From patchwork Thu Jul 12 07:01:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Zhao X-Patchwork-Id: 1187411 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 B2A81E0038 for ; Thu, 12 Jul 2012 07:26:48 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SpDhz-0005um-Fs; Thu, 12 Jul 2012 07:21:07 +0000 Received: from ch1ehsobe006.messaging.microsoft.com ([216.32.181.186] helo=ch1outboundpool.messaging.microsoft.com) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1SpDQS-0001m9-BV for linux-arm-kernel@lists.infradead.org; Thu, 12 Jul 2012 07:03:42 +0000 Received: from mail211-ch1-R.bigfish.com (10.43.68.228) by CH1EHSOBE013.bigfish.com (10.43.70.63) with Microsoft SMTP Server id 14.1.225.23; Thu, 12 Jul 2012 07:02:56 +0000 Received: from mail211-ch1 (localhost [127.0.0.1]) by mail211-ch1-R.bigfish.com (Postfix) with ESMTP id 2B67522060B; Thu, 12 Jul 2012 07:02:56 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bh8275dhz2dh2a8h668h839hd24he5bhf0ah107ah) Received: from mail211-ch1 (localhost.localdomain [127.0.0.1]) by mail211-ch1 (MessageSwitch) id 1342076574123832_8135; Thu, 12 Jul 2012 07:02:54 +0000 (UTC) Received: from CH1EHSMHS021.bigfish.com (snatpool1.int.messaging.microsoft.com [10.43.68.246]) by mail211-ch1.bigfish.com (Postfix) with ESMTP id 116F32E004A; Thu, 12 Jul 2012 07:02:54 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CH1EHSMHS021.bigfish.com (10.43.70.21) with Microsoft SMTP Server (TLS) id 14.1.225.23; Thu, 12 Jul 2012 07:02:51 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-003.039d.mgd.msft.net (10.84.1.16) with Microsoft SMTP Server (TLS) id 14.2.298.5; Thu, 12 Jul 2012 02:02:51 -0500 Received: from b20223-02.ap.freescale.net (b20223-02.ap.freescale.net [10.192.242.124]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id q6C71r2U016222; Thu, 12 Jul 2012 00:02:47 -0700 From: Richard Zhao To: , Subject: [PATCH 12/12] USB: chipidea: add imx usbmisc support Date: Thu, 12 Jul 2012 15:01:52 +0800 Message-ID: <1342076512-19207-13-git-send-email-richard.zhao@freescale.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1342076512-19207-1-git-send-email-richard.zhao@freescale.com> References: <1342076512-19207-1-git-send-email-richard.zhao@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [216.32.181.186 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: marex@denx.de, B20596@freescale.com, dong.aisheng@linaro.org, fabio.estevam@freescale.com, alexander.shishkin@linux.intel.com, B29397@freescale.com, balbi@ti.com, stern@rowland.harvard.edu, kernel@pengutronix.de, gregkh@linuxfoundation.org, richard.zhao@freescale.com, shawn.guo@linaro.org, mkl@pengutronix.de, linuxzsc@gmail.com 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: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org i.MX usb controllers shares non-core registers, which may include SoC specific controls. We take it as a usbmisc device and usbmisc driver export functions needed by ci13xxx_imx driver. For example, Sabrelite board has bad over-current design, we can usbmisc to disable over-current detect. Signed-off-by: Richard Zhao --- .../devicetree/bindings/usb/imx-usbmisc.txt | 15 ++ drivers/usb/chipidea/Makefile | 2 +- drivers/usb/chipidea/ci13xxx_imx.c | 4 + drivers/usb/chipidea/imx_usbmisc.c | 144 ++++++++++++++++++++ 4 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/usb/imx-usbmisc.txt create mode 100644 drivers/usb/chipidea/imx_usbmisc.c diff --git a/Documentation/devicetree/bindings/usb/imx-usbmisc.txt b/Documentation/devicetree/bindings/usb/imx-usbmisc.txt new file mode 100644 index 0000000..09f01ca --- /dev/null +++ b/Documentation/devicetree/bindings/usb/imx-usbmisc.txt @@ -0,0 +1,15 @@ +* Freescale i.MX non-core registers + +Required properties: +- compatible: Should be "fsl,imx6q-usbmisc" +- reg: Should contain registers location and length + +Optional properties: +- fsl,disable-over-current: disable over current detect + +Examples: +usbmisc@02184800 { + compatible = "fsl,imx6q-usbmisc"; + reg = <0x02184800 0x200>; + fsl,disable-over-current; +}; diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile index 3f56b76..46fc31c 100644 --- a/drivers/usb/chipidea/Makefile +++ b/drivers/usb/chipidea/Makefile @@ -17,5 +17,5 @@ ifneq ($(CONFIG_PCI),) endif ifneq ($(CONFIG_OF_DEVICE),) - obj-$(CONFIG_USB_CHIPIDEA) += ci13xxx_imx.o + obj-$(CONFIG_USB_CHIPIDEA) += ci13xxx_imx.o imx_usbmisc.o endif diff --git a/drivers/usb/chipidea/ci13xxx_imx.c b/drivers/usb/chipidea/ci13xxx_imx.c index b3173d8..dd7f3a3 100644 --- a/drivers/usb/chipidea/ci13xxx_imx.c +++ b/drivers/usb/chipidea/ci13xxx_imx.c @@ -24,6 +24,8 @@ #include "ci.h" +int imx_usbmisc_init(struct device *usbdev); + #define pdev_to_phy(pdev) \ ((struct usb_phy *)platform_get_drvdata(pdev)) #define ci_to_imx_data(ci) \ @@ -142,6 +144,8 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev) dma_set_coherent_mask(&pdev->dev, *pdev->dev.dma_mask); } + imx_usbmisc_init(&pdev->dev); + platform_set_drvdata(pdev, data); plat_ci = ci13xxx_add_device(&pdev->dev, diff --git a/drivers/usb/chipidea/imx_usbmisc.c b/drivers/usb/chipidea/imx_usbmisc.c new file mode 100644 index 0000000..33a8ec0 --- /dev/null +++ b/drivers/usb/chipidea/imx_usbmisc.c @@ -0,0 +1,144 @@ +/* + * Copyright 2012 Freescale Semiconductor, Inc. + * + * The code contained herein is licensed under the GNU General Public + * License. You may obtain a copy of the GNU General Public License + * Version 2 or later at the following locations: + * + * http://www.opensource.org/licenses/gpl-license.html + * http://www.gnu.org/copyleft/gpl.html + */ + +#include +#include +#include +#include +#include + +struct usbmisc; + +struct soc_data { + int (*init) (struct usbmisc *usbmisc, int id); + void (*exit) (struct usbmisc *usbmisc, int id); +}; + +struct usbmisc { + struct soc_data *soc_data; + void __iomem *base; + struct clk *clk; + + int dis_oc:1; +}; + +/* Since we only have one usbmisc device at runtime, we global variables */ +static struct usbmisc *usbmisc; + +static int imx6q_usbmisc_init(struct usbmisc *usbmisc, int id) +{ + u32 reg; + + if (usbmisc->dis_oc) { + reg = readl_relaxed(usbmisc->base + id * 4); + writel_relaxed(reg | (1 << 7), usbmisc->base + id * 4); + } + + return 0; +} + +static struct soc_data imx6q_data = { + .init = imx6q_usbmisc_init, +}; + + +static const struct of_device_id imx_usbmisc_dt_ids[] = { + { .compatible = "fsl,imx6q-usbmisc", .data = &imx6q_data }, + { /* sentinel */ } +}; + +static int __devinit imx_usbmisc_probe(struct platform_device *pdev) +{ + struct resource *res; + struct usbmisc *data; + const struct of_device_id *of_id = + of_match_device(imx_usbmisc_dt_ids, &pdev->dev); + + int ret; + + if (usbmisc) + return -EBUSY; + + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + data->base = devm_request_and_ioremap(&pdev->dev, res); + if (!data->base) + return -EADDRNOTAVAIL; + + data->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(data->clk)) { + dev_err(&pdev->dev, + "failed to get clock, err=%ld\n", PTR_ERR(data->clk)); + return PTR_ERR(data->clk); + } + + ret = clk_prepare_enable(data->clk); + if (!ret) { + if (of_find_property(pdev->dev.of_node, + "fsl,disable-over-current", NULL)) + data->dis_oc = 1; + data->soc_data = of_id->data; + usbmisc = data; + } + + return ret; +} + +static int __devexit imx_usbmisc_remove(struct platform_device *pdev) +{ + clk_disable_unprepare(usbmisc->clk); + return 0; +} + +static struct platform_driver imx_usbmisc_driver = { + .probe = imx_usbmisc_probe, + .remove = __devexit_p(imx_usbmisc_remove), + .driver = { + .name = "imx_usbmisc", + .owner = THIS_MODULE, + .of_match_table = imx_usbmisc_dt_ids, + }, +}; + +int imx_usbmisc_init(struct device *usbdev) +{ + struct device_node *np = usbdev->of_node; + int ret; + + if (!usbmisc) + return 0; + + ret = of_alias_get_id(np, "usb"); + if (ret < 0) { + dev_err(usbdev, "failed to get alias id, errno %d\n", ret); + return ret; + } + + return usbmisc->soc_data->init(usbmisc, ret); +} +EXPORT_SYMBOL_GPL(imx_usbmisc_init); + +static int __init imx_usbmisc_drv_init(void) +{ + return platform_driver_register(&imx_usbmisc_driver); +} +subsys_initcall(imx_usbmisc_drv_init); + +static void __exit imx_usbmisc_drv_exit(void) +{ + platform_driver_unregister(&imx_usbmisc_driver); +} +module_exit(imx_usbmisc_drv_exit); + +MODULE_LICENSE("GPL v2");