ramips: revert faulty 4.4 config change from 9c242270907
[oweals/openwrt.git] / target / linux / ipq806x / patches-4.4 / 097-1-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 --- a/drivers/usb/dwc3/Kconfig
28 +++ b/drivers/usb/dwc3/Kconfig
29 @@ -87,6 +87,15 @@ config USB_DWC3_KEYSTONE
30           Support of USB2/3 functionality in TI Keystone2 platforms.
31           Say 'Y' or 'M' here if you have one such device
32  
33 +config USB_DWC3_OF_SIMPLE
34 +       tristate "Generic OF Simple Glue Layer"
35 +       depends on OF && COMMON_CLK
36 +       default USB_DWC3
37 +       help
38 +         Support USB2/3 functionality in simple SoC integrations.
39 +        Currently supports Xilinx and Qualcomm DWC USB3 IP.
40 +        Say 'Y' or 'M' if you have one such device.
41 +
42  config USB_DWC3_ST
43         tristate "STMicroelectronics Platforms"
44         depends on ARCH_STI && OF
45 --- a/drivers/usb/dwc3/Makefile
46 +++ b/drivers/usb/dwc3/Makefile
47 @@ -37,5 +37,6 @@ obj-$(CONFIG_USB_DWC3_OMAP)           += dwc3-oma
48  obj-$(CONFIG_USB_DWC3_EXYNOS)          += dwc3-exynos.o
49  obj-$(CONFIG_USB_DWC3_PCI)             += dwc3-pci.o
50  obj-$(CONFIG_USB_DWC3_KEYSTONE)                += dwc3-keystone.o
51 +obj-$(CONFIG_USB_DWC3_OF_SIMPLE)       += dwc3-of-simple.o
52  obj-$(CONFIG_USB_DWC3_QCOM)            += dwc3-qcom.o
53  obj-$(CONFIG_USB_DWC3_ST)              += dwc3-st.o
54 --- /dev/null
55 +++ b/drivers/usb/dwc3/dwc3-of-simple.c
56 @@ -0,0 +1,178 @@
57 +/**
58 + * dwc3-of-simple.c - OF glue layer for simple integrations
59 + *
60 + * Copyright (c) 2015 Texas Instruments Incorporated - http://www.ti.com
61 + *
62 + * Author: Felipe Balbi <balbi@ti.com>
63 + *
64 + * This program is free software: you can redistribute it and/or modify
65 + * it under the terms of the GNU General Public License version 2  of
66 + * the License as published by the Free Software Foundation.
67 + *
68 + * This program is distributed in the hope that it will be useful,
69 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
70 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
71 + * GNU General Public License for more details.
72 + *
73 + * This is a combination of the old dwc3-qcom.c by Ivan T. Ivanov
74 + * <iivanov@mm-sol.com> and the original patch adding support for Xilinx' SoC
75 + * by Subbaraya Sundeep Bhatta <subbaraya.sundeep.bhatta@xilinx.com>
76 + */
77 +
78 +#include <linux/module.h>
79 +#include <linux/kernel.h>
80 +#include <linux/slab.h>
81 +#include <linux/platform_device.h>
82 +#include <linux/dma-mapping.h>
83 +#include <linux/clk.h>
84 +#include <linux/clk-provider.h>
85 +#include <linux/of.h>
86 +#include <linux/of_platform.h>
87 +#include <linux/pm_runtime.h>
88 +
89 +struct dwc3_of_simple {
90 +       struct device           *dev;
91 +       struct clk              **clks;
92 +       int                     num_clocks;
93 +};
94 +
95 +static int dwc3_of_simple_probe(struct platform_device *pdev)
96 +{
97 +       struct dwc3_of_simple   *simple;
98 +       struct device           *dev = &pdev->dev;
99 +       struct device_node      *np = dev->of_node;
100 +
101 +       int                     ret;
102 +       int                     i;
103 +
104 +       simple = devm_kzalloc(dev, sizeof(*simple), GFP_KERNEL);
105 +       if (!simple)
106 +               return -ENOMEM;
107 +
108 +       ret = of_clk_get_parent_count(np);
109 +       if (ret < 0)
110 +               return ret;
111 +
112 +       simple->num_clocks = ret;
113 +
114 +       simple->clks = devm_kcalloc(dev, simple->num_clocks,
115 +                       sizeof(struct clk *), GFP_KERNEL);
116 +       if (!simple->clks)
117 +               return -ENOMEM;
118 +
119 +       simple->dev = dev;
120 +
121 +       for (i = 0; i < simple->num_clocks; i++) {
122 +               struct clk      *clk;
123 +
124 +               clk = of_clk_get(np, i);
125 +               if (IS_ERR(clk)) {
126 +                       while (--i >= 0)
127 +                               clk_put(simple->clks[i]);
128 +                       return PTR_ERR(clk);
129 +               }
130 +
131 +               ret = clk_prepare_enable(clk);
132 +               if (ret < 0) {
133 +                       while (--i >= 0) {
134 +                               clk_disable_unprepare(simple->clks[i]);
135 +                               clk_put(simple->clks[i]);
136 +                       }
137 +                       clk_put(clk);
138 +
139 +                       return ret;
140 +               }
141 +
142 +               simple->clks[i] = clk;
143 +       }
144 +
145 +       ret = of_platform_populate(np, NULL, NULL, dev);
146 +       if (ret) {
147 +               for (i = 0; i < simple->num_clocks; i++) {
148 +                       clk_disable_unprepare(simple->clks[i]);
149 +                       clk_put(simple->clks[i]);
150 +               }
151 +
152 +               return ret;
153 +       }
154 +
155 +       pm_runtime_set_active(dev);
156 +       pm_runtime_enable(dev);
157 +       pm_runtime_get_sync(dev);
158 +
159 +       return 0;
160 +}
161 +
162 +static int dwc3_of_simple_remove(struct platform_device *pdev)
163 +{
164 +       struct dwc3_of_simple   *simple = platform_get_drvdata(pdev);
165 +       struct device           *dev = &pdev->dev;
166 +       int                     i;
167 +
168 +       for (i = 0; i < simple->num_clocks; i++) {
169 +               clk_unprepare(simple->clks[i]);
170 +               clk_put(simple->clks[i]);
171 +       }
172 +
173 +       of_platform_depopulate(dev);
174 +
175 +       pm_runtime_put_sync(dev);
176 +       pm_runtime_disable(dev);
177 +
178 +       return 0;
179 +}
180 +
181 +static int dwc3_of_simple_runtime_suspend(struct device *dev)
182 +{
183 +       struct dwc3_of_simple   *simple = dev_get_drvdata(dev);
184 +       int                     i;
185 +
186 +       for (i = 0; i < simple->num_clocks; i++)
187 +               clk_disable(simple->clks[i]);
188 +
189 +       return 0;
190 +}
191 +
192 +static int dwc3_of_simple_runtime_resume(struct device *dev)
193 +{
194 +       struct dwc3_of_simple   *simple = dev_get_drvdata(dev);
195 +       int                     ret;
196 +       int                     i;
197 +
198 +       for (i = 0; i < simple->num_clocks; i++) {
199 +               ret = clk_enable(simple->clks[i]);
200 +               if (ret < 0) {
201 +                       while (--i >= 0)
202 +                               clk_disable(simple->clks[i]);
203 +                       return ret;
204 +               }
205 +       }
206 +
207 +       return 0;
208 +}
209 +
210 +static const struct dev_pm_ops dwc3_of_simple_dev_pm_ops = {
211 +       SET_RUNTIME_PM_OPS(dwc3_of_simple_runtime_suspend,
212 +                       dwc3_of_simple_runtime_resume, NULL)
213 +};
214 +
215 +static const struct of_device_id of_dwc3_simple_match[] = {
216 +       { .compatible = "qcom,dwc3" },
217 +       { .compatible = "xlnx,zynqmp-dwc3" },
218 +       { /* Sentinel */ }
219 +};
220 +MODULE_DEVICE_TABLE(of, of_dwc3_simple_match);
221 +
222 +static struct platform_driver dwc3_of_simple_driver = {
223 +       .probe          = dwc3_of_simple_probe,
224 +       .remove         = dwc3_of_simple_remove,
225 +       .driver         = {
226 +               .name   = "dwc3-of-simple",
227 +               .of_match_table = of_dwc3_simple_match,
228 +       },
229 +};
230 +
231 +module_platform_driver(dwc3_of_simple_driver);
232 +MODULE_LICENSE("GPL v2");
233 +MODULE_DESCRIPTION("DesignWare USB3 OF Simple Glue Layer");
234 +MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");