From patchwork Wed Mar 6 08:48:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Gautam X-Patchwork-Id: 15252 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 8256123E3E for ; Wed, 6 Mar 2013 08:51:34 +0000 (UTC) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by fiordland.canonical.com (Postfix) with ESMTP id 39707A18FC9 for ; Wed, 6 Mar 2013 08:51:34 +0000 (UTC) Received: by mail-ve0-f179.google.com with SMTP id da11so6421163veb.38 for ; Wed, 06 Mar 2013 00:51:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-auditid:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-brightmail-tracker:x-brightmail-tracker :dlp-filter:x-mtr:x-cfilter-loop:x-gm-message-state; bh=IXTeCCjvCn4xe6EaFf0jdeYcWUSlW9Qv0a6dpDpBcgU=; b=ItA2dMmq/QXUeUi5HtvCpQ9DeYK1ZZ0yBINEKxPOjyZbVtekJndySa8YdazSfjzGyx +zdk6qrk1Yu5D2NnZ40IpN5eExMHZrfBrZTBaU/G7HKAAgpeQdzwvn4fs2KZxIKd+EHk nA9JPyk2vsSpM0gPWmRftu7tqe5h4wrUObXjZjJpS0HZXccERmlwA0kVwAe6g8ow7DYF 1k7Z8nBVVoEYk+FzwkTlpvAmDvT98EYpd1qlxvNi0YWD/giuzFdPrG6GlYsz2IjZEHrD 703o4yt2Aq3YnM+8vNtCuIH+VzBGrwT3kVAL7ynu1X/ouekvKcseT6l6YWWKNX+Ac4ez 5x5A== X-Received: by 10.220.214.6 with SMTP id gy6mr10808507vcb.8.1362559893687; Wed, 06 Mar 2013 00:51:33 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.127.98 with SMTP id nf2csp4156veb; Wed, 6 Mar 2013 00:51:33 -0800 (PST) X-Received: by 10.68.138.225 with SMTP id qt1mr43763286pbb.82.1362559890980; Wed, 06 Mar 2013 00:51:30 -0800 (PST) Received: from mailout2.samsung.com (mailout2.samsung.com. [203.254.224.25]) by mx.google.com with ESMTP id qf10si32152298pbc.338.2013.03.06.00.51.30; Wed, 06 Mar 2013 00:51:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of gautam.vivek@samsung.com designates 203.254.224.25 as permitted sender) client-ip=203.254.224.25; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of gautam.vivek@samsung.com designates 203.254.224.25 as permitted sender) smtp.mail=gautam.vivek@samsung.com Received: from epcpsbgr2.samsung.com (u142.gpu120.samsung.co.kr [203.254.230.142]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MJ8006MUDWTN3U0@mailout2.samsung.com> for patches@linaro.org; Wed, 06 Mar 2013 17:50:54 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.122]) by epcpsbgr2.samsung.com (EPCPMTA) with SMTP id 30.E8.25214.D6307315; Wed, 06 Mar 2013 17:50:54 +0900 (KST) X-AuditID: cbfee68e-b7fa46d00000627e-d1-5137036d6745 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id CF.B7.03880.D6307315; Wed, 06 Mar 2013 17:50:53 +0900 (KST) Received: from vivekkumarg-linuxpc.sisodomain.com ([107.108.214.169]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MJ80010MDW69F80@mmp1.samsung.com> for patches@linaro.org; Wed, 06 Mar 2013 17:50:53 +0900 (KST) From: Vivek Gautam To: u-boot@lists.denx.de Cc: patches@linaro.org, mk7.kang@samsung.com, marex@denx.de, sjg@chromium.org, rajeshwari.s@samsung.com Subject: [PATCH v4 1/2] usb: ehci: exynos: Fix multiple FDT decode Date: Wed, 06 Mar 2013 14:18:32 +0530 Message-id: <1362559713-6743-2-git-send-email-gautam.vivek@samsung.com> X-Mailer: git-send-email 1.7.6.5 In-reply-to: <1362559713-6743-1-git-send-email-gautam.vivek@samsung.com> References: <1362559713-6743-1-git-send-email-gautam.vivek@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrCLMWRmVeSWpSXmKPExsWyRsSkSjeP2TzQYOMsJosph7+wODB63Lm2 hy2AMYrLJiU1J7MstUjfLoEr4/jC++wFC2Ur9u24wd7A+Fi8i5GTQ0LAROLcz0esELaYxIV7 69m6GLk4hASWMkr8//qFHabo+L4LzBCJRYwSS2ftYoFwVjNJ3NrdzwxSxSagK9H0dhcjiC0i ICHxq/8qmM0skCnxbvMloBoODmEBJ4l1c8tAwiwCqhJz3q8E28wr4C6x/MYTFohlChJvbj8D G8kp4CFxf8UJFpBWIaCatTvdQNZKCFxmk5h0ZwYLxBwBiW+TD4HVSAjISmw6wAwxRlLi4Iob LBMYhRcwMqxiFE0tSC4oTkovMtIrTswtLs1L10vOz93ECAzB0/+e9e1gvHnA+hBjMtC4icxS osn5wBDOK4k3NDYxNzU2NTOytLQ0JU1YSZxX/pJMoJBAemJJanZqakFqUXxRaU5q8SFGJg5O qQZGmQX63xO6NilPOXL68ofqrqwJAS+OLL/qvGeyiY3ghvBXXY/P/jYWONEr+87KxVpB4PP+ I7KNascC2VuX7XC8X/K6QGvFvBq/G9tfe022lbx3IeyPuWyb3/KruvPC5E+v/2t0pW5ynJrt q5K2gmlnj1Ve6L2z3bLAVdds8/aALXve809nYGzrUWIpzkg01GIuKk4EACkPBhhXAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrIIsWRmVeSWpSXmKPExsVy+t9jAd1cZvNAg79XtC2mHP7C4sDocefa HrYAxqgGRpuM1MSU1CKF1Lzk/JTMvHRbJe/geOd4UzMDQ11DSwtzJYW8xNxUWyUXnwBdt8wc oLFKCmWJOaVAoYDE4mIlfTtME0JD3HQtYBojdH1DguB6jAzQQMIaxozjC++zFyyUrdi34wZ7 A+Nj8S5GTg4JAROJ4/suMEPYYhIX7q1n62Lk4hASWMQosXTWLhYIZzWTxK3d/WBVbAK6Ek1v dzGC2CICEhK/+q+C2cwCmRLvNl8CquHgEBZwklg3twwkzCKgKjHn/UpWEJtXwF1i+Y0nLBDL FCTe3H4GNpJTwEPi/ooTLCCtQkA1a3e6TWDkXcDIsIpRNLUguaA4KT3XSK84Mbe4NC9dLzk/ dxMjOMCfSe9gXNVgcYhRgINRiYd3gopZoBBrYllxZe4hRgkOZiURXq4zQCHelMTKqtSi/Pii 0pzU4kOMyUBHTWSWEk3OB0ZfXkm8obGJuamxqaWJhYmZJWnCSuK8jKeeBAgJpCeWpGanphak FsFsYeLglGpgjH+8a4UB54u99RfPrbxnaPde49ak3aUNq/bIZdhtrnxrt3zPpeCD+S23a813 7v3AfdInTC+O8/mvmX2Lna/1OuzOP7Y1Q0s2p7NCNONXe0lb2H03k9AJ3muXz71xrCpn80sG 9sVvezxfXg/bUMrA/0YrtWvx7GPmXVMvhJyQL1+y3dH8sf3dFiWW4oxEQy3mouJEAPzJh8i0 AgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQkSJtOt8Xv8JLdbj5QGaut/QX0f7eZ/DFDRcqtFuTkKZ6I2EEMEl5WeljDCYnovenmOsSNd With current FDT support driver tries to parse device node twice in ehci_hcd_init() and ehci_hcd_stop(), which shouldn't happen ideally. Making provision to store data in a global structure and thereby passing its pointer when needed. Signed-off-by: Vivek Gautam Acked-by: Simon Glass --- Changes from v3: - Checking for error return in exynos_usb_parse_dt() and returning there only in case of failure for DT systems. - Removed unnecesassry parentheses. Changes from v2: - Using hcd as "struct ehci_hccr *" rather than "unsigned int" to avoid unnecessary typecasting later in the code. - Further using local variable of type "fdt_addr_t" in exynos_usb_parse_dt() and modifying the code as required. Changes from v1: - Added patch to fix problem of multiple FDT decode. drivers/usb/host/ehci-exynos.c | 44 ++++++++++++++------------------------- 1 files changed, 16 insertions(+), 28 deletions(-) diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c index 3ca4c5c..c4c90be 100644 --- a/drivers/usb/host/ehci-exynos.c +++ b/drivers/usb/host/ehci-exynos.c @@ -42,11 +42,14 @@ DECLARE_GLOBAL_DATA_PTR; */ struct exynos_ehci { struct exynos_usb_phy *usb; - unsigned int *hcd; + struct ehci_hccr *hcd; }; +static struct exynos_ehci exynos; + static int exynos_usb_parse_dt(const void *blob, struct exynos_ehci *exynos) { + fdt_addr_t addr; unsigned int node; int depth; @@ -59,12 +62,14 @@ static int exynos_usb_parse_dt(const void *blob, struct exynos_ehci *exynos) /* * Get the base address for EHCI controller from the device node */ - exynos->hcd = (unsigned int *)fdtdec_get_addr(blob, node, "reg"); - if (exynos->hcd == NULL) { + addr = fdtdec_get_addr(blob, node, "reg"); + if (addr == FDT_ADDR_T_NONE) { debug("Can't get the EHCI register address\n"); return -ENXIO; } + exynos->hcd = (struct ehci_hccr *)addr; + depth = 0; node = fdtdec_next_compatible_subnode(blob, node, COMPAT_SAMSUNG_EXYNOS_USB_PHY, &depth); @@ -144,20 +149,16 @@ static void reset_usb_phy(struct exynos_usb_phy *usb) */ int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor) { - struct exynos_ehci *exynos = NULL; + struct exynos_ehci *ctx = &exynos; - exynos = (struct exynos_ehci *) - kzalloc(sizeof(struct exynos_ehci), GFP_KERNEL); - if (!exynos) { - debug("failed to allocate exynos ehci context\n"); - return -ENOMEM; + if (exynos_usb_parse_dt(gd->fdt_blob, ctx)) { + debug("Unable to parse device tree for ehci-exynos\n"); + return -ENODEV; } - exynos_usb_parse_dt(gd->fdt_blob, exynos); + setup_usb_phy(ctx->usb); - setup_usb_phy(exynos->usb); - - *hccr = (struct ehci_hccr *)(exynos->hcd); + *hccr = ctx->hcd; *hcor = (struct ehci_hcor *)((uint32_t) *hccr + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); @@ -165,8 +166,6 @@ int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor) (uint32_t)*hccr, (uint32_t)*hcor, (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); - kfree(exynos); - return 0; } @@ -176,20 +175,9 @@ int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor) */ int ehci_hcd_stop(int index) { - struct exynos_ehci *exynos = NULL; - - exynos = (struct exynos_ehci *) - kzalloc(sizeof(struct exynos_ehci), GFP_KERNEL); - if (!exynos) { - debug("failed to allocate exynos ehci context\n"); - return -ENOMEM; - } - - exynos_usb_parse_dt(gd->fdt_blob, exynos); - - reset_usb_phy(exynos->usb); + struct exynos_ehci *ctx = &exynos; - kfree(exynos); + reset_usb_phy(ctx->usb); return 0; }