From patchwork Thu Nov 22 02:05:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Xie X-Patchwork-Id: 1782851 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 9A5C0E013C for ; Thu, 22 Nov 2012 02:40:59 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TbMfx-0001LT-Eu; Thu, 22 Nov 2012 02:38:02 +0000 Received: from na3sys009aog103.obsmtp.com ([74.125.149.71]) by merlin.infradead.org with smtps (Exim 4.76 #1 (Red Hat Linux)) id 1TbMdk-0000PS-Q3 for linux-arm-kernel@lists.infradead.org; Thu, 22 Nov 2012 02:35:48 +0000 Received: from MSI-MTA.marvell.com ([65.219.4.132]) (using TLSv1) by na3sys009aob103.postini.com ([74.125.148.12]) with SMTP ID DSNKUK2Pef+i2CvIzi9HKMnq8mHBaayY64YB@postini.com; Wed, 21 Nov 2012 18:35:44 PST Received: from maili.marvell.com ([10.68.76.210]) by MSI-MTA.marvell.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 21 Nov 2012 18:05:32 -0800 Received: from localhost (unknown [10.38.36.205]) by maili.marvell.com (Postfix) with ESMTP id 2F9BB4E510; Wed, 21 Nov 2012 18:05:32 -0800 (PST) From: Chao Xie To: linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, haojian.zhuang@gmail.com Subject: [PATCH 26/29] usb: otg: mv_otg: add device tree support Date: Wed, 21 Nov 2012 21:05:07 -0500 Message-Id: <1353549910-988-26-git-send-email-xiechao.mail@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1353549910-988-1-git-send-email-xiechao.mail@gmail.com> References: <1353549910-988-1-git-send-email-xiechao.mail@gmail.com> X-OriginalArrivalTime: 22 Nov 2012 02:05:32.0410 (UTC) FILETIME=[DA508DA0:01CDC855] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121121_213545_877047_A686059A X-CRM114-Status: GOOD ( 21.48 ) X-Spam-Score: -3.3 (---) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-3.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [74.125.149.71 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (xiechao.mail[at]gmail.com) 0.0 DKIM_ADSP_CUSTOM_MED No valid author signature, adsp_override is CUSTOM_MED -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.9 NML_ADSP_CUSTOM_MED ADSP custom_med hit, and not from a mailing list X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Chao Xie Signed-off-by: Chao Xie --- drivers/usb/otg/mv_otg.c | 127 +++++++++++++++++++++++++++++++++++++-------- drivers/usb/otg/mv_otg.h | 6 +- 2 files changed, 107 insertions(+), 26 deletions(-) diff --git a/drivers/usb/otg/mv_otg.c b/drivers/usb/otg/mv_otg.c index bd6369c..887024c 100644 --- a/drivers/usb/otg/mv_otg.c +++ b/drivers/usb/otg/mv_otg.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -333,7 +334,7 @@ static void mv_otg_update_inputs(struct mv_otg *mvotg) else otg_ctrl->id = !!(otgsc & OTGSC_STS_USB_ID); - if (mvotg->pdata->otg_force_a_bus_req && !otg_ctrl->id) + if (mvotg->otg_force_a_bus_req && !otg_ctrl->id) otg_ctrl->a_bus_req = 1; otg_ctrl->a_sess_vld = !!(otgsc & OTGSC_STS_A_SESSION_VALID); @@ -690,21 +691,69 @@ int mv_otg_remove(struct platform_device *pdev) return 0; } +static int mv_otg_parse_dt(struct platform_device *pdev, + struct mv_otg *mvotg) +{ + struct device_node *np = pdev->dev.of_node; + unsigned int clks_num; + unsigned int val; + int i, ret; + const char *clk_name; + + if (!np) + return 1; + + clks_num = of_property_count_strings(np, "clocks"); + if (clks_num < 0) + return clks_num; + + mvotg->clk = devm_kzalloc(&pdev->dev, + sizeof(struct clk *) * clks_num, GFP_KERNEL); + if (mvotg->clk == NULL) + return -ENOMEM; + + for (i = 0; i < clks_num; i++) { + ret = of_property_read_string_index(np, "clocks", i, + &clk_name); + if (ret) + return ret; + mvotg->clk[i] = devm_clk_get(&pdev->dev, clk_name); + if (IS_ERR(mvotg->clk[i])) + return PTR_ERR(mvotg->clk[i]); + } + + mvotg->clknum = clks_num; + + ret = of_property_read_u32(np, "extern_attr", &mvotg->extern_attr); + if (ret) + return ret; + + ret = of_property_read_u32(np, "mode", &mvotg->mode); + if (ret) + return ret; + + ret = of_property_read_u32(np, "force_a_bus_req", &val); + if (ret) + return ret; + mvotg->otg_force_a_bus_req = !!val; + + ret = of_property_read_u32(np, "disable_clock_gating", &val); + if (ret) + return ret; + mvotg->clock_gating = !val; + + return 0; +} + static int mv_otg_probe(struct platform_device *pdev) { - struct mv_usb_platform_data *pdata = pdev->dev.platform_data; struct mv_otg *mvotg; struct usb_otg *otg; struct resource *r; - int retval = 0, clk_i, i; + int retval = 0, i; size_t size; - if (pdata == NULL) { - dev_err(&pdev->dev, "failed to get platform data\n"); - return -ENODEV; - } - - size = sizeof(*mvotg) + sizeof(struct clk *) * pdata->clknum; + size = sizeof(*mvotg); mvotg = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); if (!mvotg) { dev_err(&pdev->dev, "failed to allocate memory!\n"); @@ -718,17 +767,45 @@ static int mv_otg_probe(struct platform_device *pdev) platform_set_drvdata(pdev, mvotg); mvotg->pdev = pdev; - mvotg->extern_attr = pdata->extern_attr; - mvotg->pdata = pdata; - mvotg->clknum = pdata->clknum; - for (clk_i = 0; clk_i < mvotg->clknum; clk_i++) { - mvotg->clk[clk_i] = devm_clk_get(&pdev->dev, + retval = mv_otg_parse_dt(pdev, mvotg); + if (retval > 0) { + struct mv_usb_platform_data *pdata = pdev->dev.platform_data; + /* no CONFIG_OF */ + int clk_i = 0; + + if (pdata == NULL) { + dev_err(&pdev->dev, "missing platform_data\n"); + return -ENODEV; + } + mvotg->extern_attr = pdata->extern_attr; + mvotg->mode = pdata->mode; + mvotg->clknum = pdata->clknum; + mvotg->otg_force_a_bus_req = pdata->otg_force_a_bus_req; + if (pdata->disable_otg_clock_gating) + mvotg->clock_gating = 0; + + size = sizeof(struct clk *) * mvotg->clknum; + mvotg->clk = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); + if (mvotg->clk == NULL) { + dev_err(&pdev->dev, + "failed to allocate memory for clk\n"); + return -ENOMEM; + } + + for (clk_i = 0; clk_i < mvotg->clknum; clk_i++) { + mvotg->clk[clk_i] = devm_clk_get(&pdev->dev, pdata->clkname[clk_i]); - if (IS_ERR(mvotg->clk[clk_i])) { - retval = PTR_ERR(mvotg->clk[clk_i]); - return retval; + if (IS_ERR(mvotg->clk[clk_i])) { + dev_err(&pdev->dev, "failed to get clk %s\n", + pdata->clkname[clk_i]); + retval = PTR_ERR(mvotg->clk[clk_i]); + return retval; + } } + } else if (retval < 0) { + dev_err(&pdev->dev, "error parse dt\n"); + return retval; } mvotg->qwork = create_singlethread_workqueue("mv_otg_queue"); @@ -770,6 +847,7 @@ static int mv_otg_probe(struct platform_device *pdev) } mvotg->mvphy = mv_usb2_get_phy(); if (mvotg->mvphy == NULL) { + dev_err(&pdev->dev, "failed to get usb phy\n"); retval = -ENODEV; goto err_destroy_workqueue; } @@ -791,9 +869,6 @@ static int mv_otg_probe(struct platform_device *pdev) mv_usb2_register_notifier(mvotg->mvphy, &mvotg->notifier); } - if (pdata->disable_otg_clock_gating) - mvotg->clock_gating = 0; - mv_otg_reset(mvotg); mv_otg_init_irq(mvotg); @@ -892,13 +967,19 @@ static int mv_otg_resume(struct platform_device *pdev) } #endif +static struct of_device_id mv_otg_dt_ids[] = { + { .compatible = "mrvl,mv-otg" }, +}; +MODULE_DEVICE_TABLE(of, mv_otg_dt_ids); + static struct platform_driver mv_otg_driver = { .probe = mv_otg_probe, .remove = __exit_p(mv_otg_remove), .driver = { - .owner = THIS_MODULE, - .name = driver_name, - }, + .owner = THIS_MODULE, + .name = driver_name, + .of_match_table = mv_otg_dt_ids, + }, #ifdef CONFIG_PM .suspend = mv_otg_suspend, .resume = mv_otg_resume, diff --git a/drivers/usb/otg/mv_otg.h b/drivers/usb/otg/mv_otg.h index f5bc7dd..3b9356d 100644 --- a/drivers/usb/otg/mv_otg.h +++ b/drivers/usb/otg/mv_otg.h @@ -157,12 +157,12 @@ struct mv_otg { spinlock_t wq_lock; - struct mv_usb_platform_data *pdata; - unsigned int active; unsigned int clock_gating; + unsigned int mode; + unsigned int otg_force_a_bus_req; unsigned int clknum; - struct clk *clk[0]; + struct clk **clk; }; #endif