1 From 41c2b5280cd2fa3e198c422cdf223ba6e48f857a Mon Sep 17 00:00:00 2001
2 From: Felipe Balbi <balbi@ti.com>
3 Date: Wed, 18 Nov 2015 13:15:20 -0600
4 Subject: [PATCH] usb: dwc3: add generic OF glue layer
6 For simple platforms which merely enable some clocks
7 and populate its children, we can use this generic
8 glue layer to avoid boilerplate code duplication.
10 For now this supports Qcom and Xilinx, but if we
11 find a way to add generic handling of regulators and
12 optional PHYs, we can absorb exynos as well.
14 Tested-by: Subbaraya Sundeep Bhatta <subbaraya.sundeep.bhatta@xilinx.com>
15 Signed-off-by: Felipe Balbi <balbi@ti.com>
16 (cherry picked from commit 16adc674d0d68a50dfc725574738d7ae11cf5d7e)
18 Change-Id: I6fd260442997b198dc12ca726814b7a9518e6353
19 Signed-off-by: Nitheesh Sekar <nsekar@codeaurora.org>
21 drivers/usb/dwc3/Kconfig | 9 ++
22 drivers/usb/dwc3/Makefile | 1 +
23 drivers/usb/dwc3/dwc3-of-simple.c | 178 ++++++++++++++++++++++++++++++++++++++
24 3 files changed, 188 insertions(+)
25 create mode 100644 drivers/usb/dwc3/dwc3-of-simple.c
27 diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
28 index 5a42c45..070e704 100644
29 --- a/drivers/usb/dwc3/Kconfig
30 +++ b/drivers/usb/dwc3/Kconfig
31 @@ -87,6 +87,15 @@ config USB_DWC3_KEYSTONE
32 Support of USB2/3 functionality in TI Keystone2 platforms.
33 Say 'Y' or 'M' here if you have one such device
35 +config USB_DWC3_OF_SIMPLE
36 + tristate "Generic OF Simple Glue Layer"
37 + depends on OF && COMMON_CLK
40 + Support USB2/3 functionality in simple SoC integrations.
41 + Currently supports Xilinx and Qualcomm DWC USB3 IP.
42 + Say 'Y' or 'M' if you have one such device.
45 tristate "STMicroelectronics Platforms"
46 depends on ARCH_STI && OF
47 diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
48 index acc951d..6491f9b 100644
49 --- a/drivers/usb/dwc3/Makefile
50 +++ b/drivers/usb/dwc3/Makefile
51 @@ -37,5 +37,6 @@ obj-$(CONFIG_USB_DWC3_OMAP) += dwc3-omap.o
52 obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o
53 obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o
54 obj-$(CONFIG_USB_DWC3_KEYSTONE) += dwc3-keystone.o
55 +obj-$(CONFIG_USB_DWC3_OF_SIMPLE) += dwc3-of-simple.o
56 obj-$(CONFIG_USB_DWC3_QCOM) += dwc3-qcom.o
57 obj-$(CONFIG_USB_DWC3_ST) += dwc3-st.o
58 diff --git a/drivers/usb/dwc3/dwc3-of-simple.c b/drivers/usb/dwc3/dwc3-of-simple.c
60 index 0000000..60c4c5a
62 +++ b/drivers/usb/dwc3/dwc3-of-simple.c
65 + * dwc3-of-simple.c - OF glue layer for simple integrations
67 + * Copyright (c) 2015 Texas Instruments Incorporated - http://www.ti.com
69 + * Author: Felipe Balbi <balbi@ti.com>
71 + * This program is free software: you can redistribute it and/or modify
72 + * it under the terms of the GNU General Public License version 2 of
73 + * the License as published by the Free Software Foundation.
75 + * This program is distributed in the hope that it will be useful,
76 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
77 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
78 + * GNU General Public License for more details.
80 + * This is a combination of the old dwc3-qcom.c by Ivan T. Ivanov
81 + * <iivanov@mm-sol.com> and the original patch adding support for Xilinx' SoC
82 + * by Subbaraya Sundeep Bhatta <subbaraya.sundeep.bhatta@xilinx.com>
85 +#include <linux/module.h>
86 +#include <linux/kernel.h>
87 +#include <linux/slab.h>
88 +#include <linux/platform_device.h>
89 +#include <linux/dma-mapping.h>
90 +#include <linux/clk.h>
91 +#include <linux/clk-provider.h>
92 +#include <linux/of.h>
93 +#include <linux/of_platform.h>
94 +#include <linux/pm_runtime.h>
96 +struct dwc3_of_simple {
102 +static int dwc3_of_simple_probe(struct platform_device *pdev)
104 + struct dwc3_of_simple *simple;
105 + struct device *dev = &pdev->dev;
106 + struct device_node *np = dev->of_node;
111 + simple = devm_kzalloc(dev, sizeof(*simple), GFP_KERNEL);
115 + ret = of_clk_get_parent_count(np);
119 + simple->num_clocks = ret;
121 + simple->clks = devm_kcalloc(dev, simple->num_clocks,
122 + sizeof(struct clk *), GFP_KERNEL);
128 + for (i = 0; i < simple->num_clocks; i++) {
131 + clk = of_clk_get(np, i);
134 + clk_put(simple->clks[i]);
135 + return PTR_ERR(clk);
138 + ret = clk_prepare_enable(clk);
141 + clk_disable_unprepare(simple->clks[i]);
142 + clk_put(simple->clks[i]);
149 + simple->clks[i] = clk;
152 + ret = of_platform_populate(np, NULL, NULL, dev);
154 + for (i = 0; i < simple->num_clocks; i++) {
155 + clk_disable_unprepare(simple->clks[i]);
156 + clk_put(simple->clks[i]);
162 + pm_runtime_set_active(dev);
163 + pm_runtime_enable(dev);
164 + pm_runtime_get_sync(dev);
169 +static int dwc3_of_simple_remove(struct platform_device *pdev)
171 + struct dwc3_of_simple *simple = platform_get_drvdata(pdev);
172 + struct device *dev = &pdev->dev;
175 + for (i = 0; i < simple->num_clocks; i++) {
176 + clk_unprepare(simple->clks[i]);
177 + clk_put(simple->clks[i]);
180 + of_platform_depopulate(dev);
182 + pm_runtime_put_sync(dev);
183 + pm_runtime_disable(dev);
188 +static int dwc3_of_simple_runtime_suspend(struct device *dev)
190 + struct dwc3_of_simple *simple = dev_get_drvdata(dev);
193 + for (i = 0; i < simple->num_clocks; i++)
194 + clk_disable(simple->clks[i]);
199 +static int dwc3_of_simple_runtime_resume(struct device *dev)
201 + struct dwc3_of_simple *simple = dev_get_drvdata(dev);
205 + for (i = 0; i < simple->num_clocks; i++) {
206 + ret = clk_enable(simple->clks[i]);
209 + clk_disable(simple->clks[i]);
217 +static const struct dev_pm_ops dwc3_of_simple_dev_pm_ops = {
218 + SET_RUNTIME_PM_OPS(dwc3_of_simple_runtime_suspend,
219 + dwc3_of_simple_runtime_resume, NULL)
222 +static const struct of_device_id of_dwc3_simple_match[] = {
223 + { .compatible = "qcom,dwc3" },
224 + { .compatible = "xlnx,zynqmp-dwc3" },
227 +MODULE_DEVICE_TABLE(of, of_dwc3_simple_match);
229 +static struct platform_driver dwc3_of_simple_driver = {
230 + .probe = dwc3_of_simple_probe,
231 + .remove = dwc3_of_simple_remove,
233 + .name = "dwc3-of-simple",
234 + .of_match_table = of_dwc3_simple_match,
238 +module_platform_driver(dwc3_of_simple_driver);
239 +MODULE_LICENSE("GPL v2");
240 +MODULE_DESCRIPTION("DesignWare USB3 OF Simple Glue Layer");
241 +MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");