ipq806x: sync with latest patches sent by QCA
[openwrt/openwrt.git] / target / linux / ipq806x / patches-4.4 / 097-usb-dwc3-add-generic-OF-glue-layer.patch
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
5
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.
9
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.
13
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)
17
18 Change-Id: I6fd260442997b198dc12ca726814b7a9518e6353
19 Signed-off-by: Nitheesh Sekar <nsekar@codeaurora.org>
20 ---
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
26
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
34
35 +config USB_DWC3_OF_SIMPLE
36 + tristate "Generic OF Simple Glue Layer"
37 + depends on OF && COMMON_CLK
38 + default USB_DWC3
39 + help
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.
43 +
44 config USB_DWC3_ST
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
59 new file mode 100644
60 index 0000000..60c4c5a
61 --- /dev/null
62 +++ b/drivers/usb/dwc3/dwc3-of-simple.c
63 @@ -0,0 +1,178 @@
64 +/**
65 + * dwc3-of-simple.c - OF glue layer for simple integrations
66 + *
67 + * Copyright (c) 2015 Texas Instruments Incorporated - http://www.ti.com
68 + *
69 + * Author: Felipe Balbi <balbi@ti.com>
70 + *
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.
74 + *
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.
79 + *
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>
83 + */
84 +
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>
95 +
96 +struct dwc3_of_simple {
97 + struct device *dev;
98 + struct clk **clks;
99 + int num_clocks;
100 +};
101 +
102 +static int dwc3_of_simple_probe(struct platform_device *pdev)
103 +{
104 + struct dwc3_of_simple *simple;
105 + struct device *dev = &pdev->dev;
106 + struct device_node *np = dev->of_node;
107 +
108 + int ret;
109 + int i;
110 +
111 + simple = devm_kzalloc(dev, sizeof(*simple), GFP_KERNEL);
112 + if (!simple)
113 + return -ENOMEM;
114 +
115 + ret = of_clk_get_parent_count(np);
116 + if (ret < 0)
117 + return ret;
118 +
119 + simple->num_clocks = ret;
120 +
121 + simple->clks = devm_kcalloc(dev, simple->num_clocks,
122 + sizeof(struct clk *), GFP_KERNEL);
123 + if (!simple->clks)
124 + return -ENOMEM;
125 +
126 + simple->dev = dev;
127 +
128 + for (i = 0; i < simple->num_clocks; i++) {
129 + struct clk *clk;
130 +
131 + clk = of_clk_get(np, i);
132 + if (IS_ERR(clk)) {
133 + while (--i >= 0)
134 + clk_put(simple->clks[i]);
135 + return PTR_ERR(clk);
136 + }
137 +
138 + ret = clk_prepare_enable(clk);
139 + if (ret < 0) {
140 + while (--i >= 0) {
141 + clk_disable_unprepare(simple->clks[i]);
142 + clk_put(simple->clks[i]);
143 + }
144 + clk_put(clk);
145 +
146 + return ret;
147 + }
148 +
149 + simple->clks[i] = clk;
150 + }
151 +
152 + ret = of_platform_populate(np, NULL, NULL, dev);
153 + if (ret) {
154 + for (i = 0; i < simple->num_clocks; i++) {
155 + clk_disable_unprepare(simple->clks[i]);
156 + clk_put(simple->clks[i]);
157 + }
158 +
159 + return ret;
160 + }
161 +
162 + pm_runtime_set_active(dev);
163 + pm_runtime_enable(dev);
164 + pm_runtime_get_sync(dev);
165 +
166 + return 0;
167 +}
168 +
169 +static int dwc3_of_simple_remove(struct platform_device *pdev)
170 +{
171 + struct dwc3_of_simple *simple = platform_get_drvdata(pdev);
172 + struct device *dev = &pdev->dev;
173 + int i;
174 +
175 + for (i = 0; i < simple->num_clocks; i++) {
176 + clk_unprepare(simple->clks[i]);
177 + clk_put(simple->clks[i]);
178 + }
179 +
180 + of_platform_depopulate(dev);
181 +
182 + pm_runtime_put_sync(dev);
183 + pm_runtime_disable(dev);
184 +
185 + return 0;
186 +}
187 +
188 +static int dwc3_of_simple_runtime_suspend(struct device *dev)
189 +{
190 + struct dwc3_of_simple *simple = dev_get_drvdata(dev);
191 + int i;
192 +
193 + for (i = 0; i < simple->num_clocks; i++)
194 + clk_disable(simple->clks[i]);
195 +
196 + return 0;
197 +}
198 +
199 +static int dwc3_of_simple_runtime_resume(struct device *dev)
200 +{
201 + struct dwc3_of_simple *simple = dev_get_drvdata(dev);
202 + int ret;
203 + int i;
204 +
205 + for (i = 0; i < simple->num_clocks; i++) {
206 + ret = clk_enable(simple->clks[i]);
207 + if (ret < 0) {
208 + while (--i >= 0)
209 + clk_disable(simple->clks[i]);
210 + return ret;
211 + }
212 + }
213 +
214 + return 0;
215 +}
216 +
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)
220 +};
221 +
222 +static const struct of_device_id of_dwc3_simple_match[] = {
223 + { .compatible = "qcom,dwc3" },
224 + { .compatible = "xlnx,zynqmp-dwc3" },
225 + { /* Sentinel */ }
226 +};
227 +MODULE_DEVICE_TABLE(of, of_dwc3_simple_match);
228 +
229 +static struct platform_driver dwc3_of_simple_driver = {
230 + .probe = dwc3_of_simple_probe,
231 + .remove = dwc3_of_simple_remove,
232 + .driver = {
233 + .name = "dwc3-of-simple",
234 + .of_match_table = of_dwc3_simple_match,
235 + },
236 +};
237 +
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>");
242 --
243 2.7.2
244