]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/usb/dwc3/dwc3-exynos.c
Merge tag 'spi-v4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
[mirror_ubuntu-artful-kernel.git] / drivers / usb / dwc3 / dwc3-exynos.c
CommitLineData
d28a9689
AT
1/**
2 * dwc3-exynos.c - Samsung EXYNOS DWC3 Specific Glue layer
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com
6 *
7 * Author: Anton Tikhomirov <av.tikhomirov@samsung.com>
8 *
5945f789
FB
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 of
11 * the License as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
d28a9689
AT
17 */
18
19#include <linux/module.h>
20#include <linux/kernel.h>
21#include <linux/slab.h>
22#include <linux/platform_device.h>
d28a9689 23#include <linux/clk.h>
d720f057 24#include <linux/usb/otg.h>
d7078df6 25#include <linux/usb/usb_phy_generic.h>
accefdd4 26#include <linux/of.h>
adcf20dc 27#include <linux/of_platform.h>
bd8ce544 28#include <linux/regulator/consumer.h>
d28a9689 29
d28a9689 30struct dwc3_exynos {
d720f057
FB
31 struct platform_device *usb2_phy;
32 struct platform_device *usb3_phy;
d28a9689
AT
33 struct device *dev;
34
35 struct clk *clk;
72d996fc 36 struct clk *susp_clk;
ed692a99 37 struct clk *axius_clk;
72d996fc 38
bd8ce544
VG
39 struct regulator *vdd33;
40 struct regulator *vdd10;
d28a9689
AT
41};
42
41ac7b3a 43static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
d720f057 44{
4525beeb 45 struct usb_phy_generic_platform_data pdata;
d720f057
FB
46 struct platform_device *pdev;
47 int ret;
48
49 memset(&pdata, 0x00, sizeof(pdata));
50
4525beeb 51 pdev = platform_device_alloc("usb_phy_generic", PLATFORM_DEVID_AUTO);
d720f057
FB
52 if (!pdev)
53 return -ENOMEM;
54
55 exynos->usb2_phy = pdev;
56 pdata.type = USB_PHY_TYPE_USB2;
13518673 57 pdata.gpio_reset = -1;
d720f057
FB
58
59 ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata));
60 if (ret)
61 goto err1;
62
4525beeb 63 pdev = platform_device_alloc("usb_phy_generic", PLATFORM_DEVID_AUTO);
d720f057
FB
64 if (!pdev) {
65 ret = -ENOMEM;
66 goto err1;
67 }
68
69 exynos->usb3_phy = pdev;
70 pdata.type = USB_PHY_TYPE_USB3;
71
72 ret = platform_device_add_data(exynos->usb3_phy, &pdata, sizeof(pdata));
73 if (ret)
74 goto err2;
75
76 ret = platform_device_add(exynos->usb2_phy);
77 if (ret)
78 goto err2;
79
80 ret = platform_device_add(exynos->usb3_phy);
81 if (ret)
82 goto err3;
83
84 return 0;
85
86err3:
87 platform_device_del(exynos->usb2_phy);
88
89err2:
90 platform_device_put(exynos->usb3_phy);
91
92err1:
93 platform_device_put(exynos->usb2_phy);
94
95 return ret;
96}
97
adcf20dc
VG
98static int dwc3_exynos_remove_child(struct device *dev, void *unused)
99{
100 struct platform_device *pdev = to_platform_device(dev);
101
102 platform_device_unregister(pdev);
103
104 return 0;
105}
106
41ac7b3a 107static int dwc3_exynos_probe(struct platform_device *pdev)
d28a9689 108{
d28a9689 109 struct dwc3_exynos *exynos;
20b97dc1 110 struct device *dev = &pdev->dev;
adcf20dc 111 struct device_node *node = dev->of_node;
d28a9689 112
b09e99ee 113 int ret;
d28a9689 114
20b97dc1 115 exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
734d5a53 116 if (!exynos)
b09e99ee 117 return -ENOMEM;
d28a9689
AT
118
119 platform_set_drvdata(pdev, exynos);
120
c1a3acaa
VG
121 exynos->dev = dev;
122
123 exynos->clk = devm_clk_get(dev, "usbdrd30");
124 if (IS_ERR(exynos->clk)) {
20b97dc1 125 dev_err(dev, "couldn't get clock\n");
b09e99ee 126 return -EINVAL;
d28a9689 127 }
ddb5147c 128 clk_prepare_enable(exynos->clk);
d28a9689 129
72d996fc
VG
130 exynos->susp_clk = devm_clk_get(dev, "usbdrd30_susp_clk");
131 if (IS_ERR(exynos->susp_clk)) {
42f69a02 132 dev_info(dev, "no suspend clk specified\n");
72d996fc
VG
133 exynos->susp_clk = NULL;
134 }
135 clk_prepare_enable(exynos->susp_clk);
136
ed692a99
VG
137 if (of_device_is_compatible(node, "samsung,exynos7-dwusb3")) {
138 exynos->axius_clk = devm_clk_get(dev, "usbdrd30_axius_clk");
139 if (IS_ERR(exynos->axius_clk)) {
140 dev_err(dev, "no AXI UpScaler clk specified\n");
8ae584d1
SK
141 ret = -ENODEV;
142 goto axius_clk_err;
ed692a99
VG
143 }
144 clk_prepare_enable(exynos->axius_clk);
145 } else {
146 exynos->axius_clk = NULL;
147 }
148
bd8ce544
VG
149 exynos->vdd33 = devm_regulator_get(dev, "vdd33");
150 if (IS_ERR(exynos->vdd33)) {
151 ret = PTR_ERR(exynos->vdd33);
152 goto err2;
153 }
154 ret = regulator_enable(exynos->vdd33);
155 if (ret) {
156 dev_err(dev, "Failed to enable VDD33 supply\n");
157 goto err2;
158 }
159
160 exynos->vdd10 = devm_regulator_get(dev, "vdd10");
161 if (IS_ERR(exynos->vdd10)) {
162 ret = PTR_ERR(exynos->vdd10);
163 goto err3;
164 }
165 ret = regulator_enable(exynos->vdd10);
166 if (ret) {
167 dev_err(dev, "Failed to enable VDD10 supply\n");
168 goto err3;
169 }
170
4879efb3
SG
171 ret = dwc3_exynos_register_phys(exynos);
172 if (ret) {
173 dev_err(dev, "couldn't register PHYs\n");
174 goto err4;
175 }
176
adcf20dc
VG
177 if (node) {
178 ret = of_platform_populate(node, NULL, NULL, dev);
179 if (ret) {
180 dev_err(dev, "failed to add dwc3 core\n");
4879efb3 181 goto err5;
adcf20dc
VG
182 }
183 } else {
184 dev_err(dev, "no device node, failed to add dwc3 core\n");
185 ret = -ENODEV;
4879efb3 186 goto err5;
d28a9689
AT
187 }
188
189 return 0;
190
4879efb3
SG
191err5:
192 platform_device_unregister(exynos->usb2_phy);
193 platform_device_unregister(exynos->usb3_phy);
bd8ce544
VG
194err4:
195 regulator_disable(exynos->vdd10);
196err3:
197 regulator_disable(exynos->vdd33);
20b97dc1 198err2:
ed692a99 199 clk_disable_unprepare(exynos->axius_clk);
8ae584d1 200axius_clk_err:
72d996fc 201 clk_disable_unprepare(exynos->susp_clk);
c1a3acaa 202 clk_disable_unprepare(exynos->clk);
d28a9689
AT
203 return ret;
204}
205
fb4e98ab 206static int dwc3_exynos_remove(struct platform_device *pdev)
d28a9689
AT
207{
208 struct dwc3_exynos *exynos = platform_get_drvdata(pdev);
d28a9689 209
022d0547 210 device_for_each_child(&pdev->dev, NULL, dwc3_exynos_remove_child);
d720f057
FB
211 platform_device_unregister(exynos->usb2_phy);
212 platform_device_unregister(exynos->usb3_phy);
d28a9689 213
ed692a99 214 clk_disable_unprepare(exynos->axius_clk);
72d996fc 215 clk_disable_unprepare(exynos->susp_clk);
ddb5147c 216 clk_disable_unprepare(exynos->clk);
d28a9689 217
bd8ce544
VG
218 regulator_disable(exynos->vdd33);
219 regulator_disable(exynos->vdd10);
220
d28a9689
AT
221 return 0;
222}
223
accefdd4 224static const struct of_device_id exynos_dwc3_match[] = {
fe29db8f 225 { .compatible = "samsung,exynos5250-dwusb3" },
ed692a99 226 { .compatible = "samsung,exynos7-dwusb3" },
accefdd4
VG
227 {},
228};
229MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
accefdd4 230
19fda7cd 231#ifdef CONFIG_PM_SLEEP
0646caf7
VS
232static int dwc3_exynos_suspend(struct device *dev)
233{
234 struct dwc3_exynos *exynos = dev_get_drvdata(dev);
235
ed692a99 236 clk_disable(exynos->axius_clk);
0646caf7
VS
237 clk_disable(exynos->clk);
238
bd8ce544
VG
239 regulator_disable(exynos->vdd33);
240 regulator_disable(exynos->vdd10);
241
0646caf7
VS
242 return 0;
243}
244
245static int dwc3_exynos_resume(struct device *dev)
246{
247 struct dwc3_exynos *exynos = dev_get_drvdata(dev);
bd8ce544
VG
248 int ret;
249
250 ret = regulator_enable(exynos->vdd33);
251 if (ret) {
252 dev_err(dev, "Failed to enable VDD33 supply\n");
253 return ret;
254 }
255 ret = regulator_enable(exynos->vdd10);
256 if (ret) {
257 dev_err(dev, "Failed to enable VDD10 supply\n");
258 return ret;
259 }
0646caf7
VS
260
261 clk_enable(exynos->clk);
ed692a99 262 clk_enable(exynos->axius_clk);
0646caf7
VS
263
264 /* runtime set active to reflect active state. */
265 pm_runtime_disable(dev);
266 pm_runtime_set_active(dev);
267 pm_runtime_enable(dev);
268
269 return 0;
270}
271
272static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = {
273 SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume)
274};
275
276#define DEV_PM_OPS (&dwc3_exynos_dev_pm_ops)
277#else
278#define DEV_PM_OPS NULL
19fda7cd 279#endif /* CONFIG_PM_SLEEP */
0646caf7 280
d28a9689
AT
281static struct platform_driver dwc3_exynos_driver = {
282 .probe = dwc3_exynos_probe,
7690417d 283 .remove = dwc3_exynos_remove,
d28a9689
AT
284 .driver = {
285 .name = "exynos-dwc3",
b4c9f578 286 .of_match_table = exynos_dwc3_match,
0646caf7 287 .pm = DEV_PM_OPS,
d28a9689
AT
288 },
289};
290
291module_platform_driver(dwc3_exynos_driver);
292
293MODULE_ALIAS("platform:exynos-dwc3");
294MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
5945f789 295MODULE_LICENSE("GPL v2");
d28a9689 296MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");