blob: a94fb1ba8f2c48ea4d389a328de844ba7c6542b6 [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-2.0
Anton Tikhomirovd28a9682012-02-15 17:04:56 +09002/**
3 * dwc3-exynos.c - Samsung EXYNOS DWC3 Specific Glue layer
4 *
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 * http://www.samsung.com
7 *
8 * Author: Anton Tikhomirov <av.tikhomirov@samsung.com>
Anton Tikhomirovd28a9682012-02-15 17:04:56 +09009 */
10
11#include <linux/module.h>
12#include <linux/kernel.h>
13#include <linux/slab.h>
14#include <linux/platform_device.h>
Anton Tikhomirovd28a9682012-02-15 17:04:56 +090015#include <linux/clk.h>
Felipe Balbid720f052012-07-19 14:01:10 +030016#include <linux/usb/otg.h>
Felipe Balbid7078df2014-04-16 15:28:32 -050017#include <linux/usb/usb_phy_generic.h>
Vivek Gautamaccefdd2012-11-03 18:00:27 +053018#include <linux/of.h>
Vivek Gautamadcf20d2013-03-14 18:09:49 +053019#include <linux/of_platform.h>
Vivek Gautambd8ce542014-04-21 17:46:44 +053020#include <linux/regulator/consumer.h>
Anton Tikhomirovd28a9682012-02-15 17:04:56 +090021
Anton Tikhomirovd28a9682012-02-15 17:04:56 +090022struct dwc3_exynos {
Felipe Balbid720f052012-07-19 14:01:10 +030023 struct platform_device *usb2_phy;
24 struct platform_device *usb3_phy;
Anton Tikhomirovd28a9682012-02-15 17:04:56 +090025 struct device *dev;
26
27 struct clk *clk;
Vivek Gautam72d996f2014-11-21 19:05:46 +053028 struct clk *susp_clk;
Vivek Gautamed692a92014-11-21 19:05:47 +053029 struct clk *axius_clk;
Vivek Gautam72d996f2014-11-21 19:05:46 +053030
Vivek Gautambd8ce542014-04-21 17:46:44 +053031 struct regulator *vdd33;
32 struct regulator *vdd10;
Anton Tikhomirovd28a9682012-02-15 17:04:56 +090033};
34
Bill Pemberton41ac7b32012-11-19 13:21:48 -050035static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
Felipe Balbid720f052012-07-19 14:01:10 +030036{
Felipe Balbi4525bee2014-04-16 15:20:44 -050037 struct usb_phy_generic_platform_data pdata;
Felipe Balbid720f052012-07-19 14:01:10 +030038 struct platform_device *pdev;
39 int ret;
40
41 memset(&pdata, 0x00, sizeof(pdata));
42
Felipe Balbi4525bee2014-04-16 15:20:44 -050043 pdev = platform_device_alloc("usb_phy_generic", PLATFORM_DEVID_AUTO);
Felipe Balbid720f052012-07-19 14:01:10 +030044 if (!pdev)
45 return -ENOMEM;
46
47 exynos->usb2_phy = pdev;
48 pdata.type = USB_PHY_TYPE_USB2;
Heikki Krogerus13518672013-12-18 16:41:25 +020049 pdata.gpio_reset = -1;
Felipe Balbid720f052012-07-19 14:01:10 +030050
51 ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata));
52 if (ret)
53 goto err1;
54
Felipe Balbi4525bee2014-04-16 15:20:44 -050055 pdev = platform_device_alloc("usb_phy_generic", PLATFORM_DEVID_AUTO);
Felipe Balbid720f052012-07-19 14:01:10 +030056 if (!pdev) {
57 ret = -ENOMEM;
58 goto err1;
59 }
60
61 exynos->usb3_phy = pdev;
62 pdata.type = USB_PHY_TYPE_USB3;
63
64 ret = platform_device_add_data(exynos->usb3_phy, &pdata, sizeof(pdata));
65 if (ret)
66 goto err2;
67
68 ret = platform_device_add(exynos->usb2_phy);
69 if (ret)
70 goto err2;
71
72 ret = platform_device_add(exynos->usb3_phy);
73 if (ret)
74 goto err3;
75
76 return 0;
77
78err3:
79 platform_device_del(exynos->usb2_phy);
80
81err2:
82 platform_device_put(exynos->usb3_phy);
83
84err1:
85 platform_device_put(exynos->usb2_phy);
86
87 return ret;
88}
89
Vivek Gautamadcf20d2013-03-14 18:09:49 +053090static int dwc3_exynos_remove_child(struct device *dev, void *unused)
91{
92 struct platform_device *pdev = to_platform_device(dev);
93
94 platform_device_unregister(pdev);
95
96 return 0;
97}
98
Bill Pemberton41ac7b32012-11-19 13:21:48 -050099static int dwc3_exynos_probe(struct platform_device *pdev)
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900100{
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900101 struct dwc3_exynos *exynos;
Jingoo Han20b97dc2012-11-13 11:20:49 +0900102 struct device *dev = &pdev->dev;
Vivek Gautamadcf20d2013-03-14 18:09:49 +0530103 struct device_node *node = dev->of_node;
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900104
Andy Shevchenkob09e99e2014-05-15 15:53:32 +0300105 int ret;
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900106
Jingoo Han20b97dc2012-11-13 11:20:49 +0900107 exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
Jingoo Han734d5a52014-07-17 12:45:11 +0900108 if (!exynos)
Andy Shevchenkob09e99e2014-05-15 15:53:32 +0300109 return -ENOMEM;
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900110
111 platform_set_drvdata(pdev, exynos);
112
Vivek Gautamc1a3aca2014-11-21 19:05:45 +0530113 exynos->dev = dev;
114
115 exynos->clk = devm_clk_get(dev, "usbdrd30");
116 if (IS_ERR(exynos->clk)) {
Jingoo Han20b97dc2012-11-13 11:20:49 +0900117 dev_err(dev, "couldn't get clock\n");
Andy Shevchenkob09e99e2014-05-15 15:53:32 +0300118 return -EINVAL;
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900119 }
Arvind Yadavece7af52017-06-12 16:23:31 +0530120 ret = clk_prepare_enable(exynos->clk);
121 if (ret)
122 return ret;
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900123
Vivek Gautam72d996f2014-11-21 19:05:46 +0530124 exynos->susp_clk = devm_clk_get(dev, "usbdrd30_susp_clk");
Shuah Khan3e27b3f2017-01-10 14:20:59 -0700125 if (IS_ERR(exynos->susp_clk))
Vivek Gautam72d996f2014-11-21 19:05:46 +0530126 exynos->susp_clk = NULL;
Arvind Yadavece7af52017-06-12 16:23:31 +0530127 ret = clk_prepare_enable(exynos->susp_clk);
128 if (ret)
129 goto susp_clk_err;
Vivek Gautam72d996f2014-11-21 19:05:46 +0530130
Vivek Gautamed692a92014-11-21 19:05:47 +0530131 if (of_device_is_compatible(node, "samsung,exynos7-dwusb3")) {
132 exynos->axius_clk = devm_clk_get(dev, "usbdrd30_axius_clk");
133 if (IS_ERR(exynos->axius_clk)) {
134 dev_err(dev, "no AXI UpScaler clk specified\n");
Shuah Khan8ae584d2017-01-10 16:05:28 -0700135 ret = -ENODEV;
136 goto axius_clk_err;
Vivek Gautamed692a92014-11-21 19:05:47 +0530137 }
Arvind Yadavece7af52017-06-12 16:23:31 +0530138 ret = clk_prepare_enable(exynos->axius_clk);
139 if (ret)
140 goto axius_clk_err;
Vivek Gautamed692a92014-11-21 19:05:47 +0530141 } else {
142 exynos->axius_clk = NULL;
143 }
144
Vivek Gautambd8ce542014-04-21 17:46:44 +0530145 exynos->vdd33 = devm_regulator_get(dev, "vdd33");
146 if (IS_ERR(exynos->vdd33)) {
147 ret = PTR_ERR(exynos->vdd33);
Shuah Khan3a932b02017-01-30 12:25:04 -0700148 goto vdd33_err;
Vivek Gautambd8ce542014-04-21 17:46:44 +0530149 }
150 ret = regulator_enable(exynos->vdd33);
151 if (ret) {
152 dev_err(dev, "Failed to enable VDD33 supply\n");
Shuah Khan3a932b02017-01-30 12:25:04 -0700153 goto vdd33_err;
Vivek Gautambd8ce542014-04-21 17:46:44 +0530154 }
155
156 exynos->vdd10 = devm_regulator_get(dev, "vdd10");
157 if (IS_ERR(exynos->vdd10)) {
158 ret = PTR_ERR(exynos->vdd10);
Shuah Khan3a932b02017-01-30 12:25:04 -0700159 goto vdd10_err;
Vivek Gautambd8ce542014-04-21 17:46:44 +0530160 }
161 ret = regulator_enable(exynos->vdd10);
162 if (ret) {
163 dev_err(dev, "Failed to enable VDD10 supply\n");
Shuah Khan3a932b02017-01-30 12:25:04 -0700164 goto vdd10_err;
Vivek Gautambd8ce542014-04-21 17:46:44 +0530165 }
166
Steinar H. Gunderson4879efb2016-05-24 20:13:15 +0200167 ret = dwc3_exynos_register_phys(exynos);
168 if (ret) {
169 dev_err(dev, "couldn't register PHYs\n");
Shuah Khan3a932b02017-01-30 12:25:04 -0700170 goto phys_err;
Steinar H. Gunderson4879efb2016-05-24 20:13:15 +0200171 }
172
Vivek Gautamadcf20d2013-03-14 18:09:49 +0530173 if (node) {
174 ret = of_platform_populate(node, NULL, NULL, dev);
175 if (ret) {
176 dev_err(dev, "failed to add dwc3 core\n");
Shuah Khan3a932b02017-01-30 12:25:04 -0700177 goto populate_err;
Vivek Gautamadcf20d2013-03-14 18:09:49 +0530178 }
179 } else {
180 dev_err(dev, "no device node, failed to add dwc3 core\n");
181 ret = -ENODEV;
Shuah Khan3a932b02017-01-30 12:25:04 -0700182 goto populate_err;
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900183 }
184
185 return 0;
186
Shuah Khan3a932b02017-01-30 12:25:04 -0700187populate_err:
Steinar H. Gunderson4879efb2016-05-24 20:13:15 +0200188 platform_device_unregister(exynos->usb2_phy);
189 platform_device_unregister(exynos->usb3_phy);
Shuah Khan3a932b02017-01-30 12:25:04 -0700190phys_err:
Vivek Gautambd8ce542014-04-21 17:46:44 +0530191 regulator_disable(exynos->vdd10);
Shuah Khan3a932b02017-01-30 12:25:04 -0700192vdd10_err:
Vivek Gautambd8ce542014-04-21 17:46:44 +0530193 regulator_disable(exynos->vdd33);
Shuah Khan3a932b02017-01-30 12:25:04 -0700194vdd33_err:
Vivek Gautamed692a92014-11-21 19:05:47 +0530195 clk_disable_unprepare(exynos->axius_clk);
Shuah Khan8ae584d2017-01-10 16:05:28 -0700196axius_clk_err:
Vivek Gautam72d996f2014-11-21 19:05:46 +0530197 clk_disable_unprepare(exynos->susp_clk);
Arvind Yadavece7af52017-06-12 16:23:31 +0530198susp_clk_err:
Vivek Gautamc1a3aca2014-11-21 19:05:45 +0530199 clk_disable_unprepare(exynos->clk);
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900200 return ret;
201}
202
Bill Pembertonfb4e98a2012-11-19 13:26:20 -0500203static int dwc3_exynos_remove(struct platform_device *pdev)
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900204{
205 struct dwc3_exynos *exynos = platform_get_drvdata(pdev);
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900206
Peter Chen022d0542013-05-24 14:30:16 +0800207 device_for_each_child(&pdev->dev, NULL, dwc3_exynos_remove_child);
Felipe Balbid720f052012-07-19 14:01:10 +0300208 platform_device_unregister(exynos->usb2_phy);
209 platform_device_unregister(exynos->usb3_phy);
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900210
Vivek Gautamed692a92014-11-21 19:05:47 +0530211 clk_disable_unprepare(exynos->axius_clk);
Vivek Gautam72d996f2014-11-21 19:05:46 +0530212 clk_disable_unprepare(exynos->susp_clk);
Vivek Gautamddb51472013-03-14 16:14:58 +0530213 clk_disable_unprepare(exynos->clk);
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900214
Vivek Gautambd8ce542014-04-21 17:46:44 +0530215 regulator_disable(exynos->vdd33);
216 regulator_disable(exynos->vdd10);
217
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900218 return 0;
219}
220
Vivek Gautamaccefdd2012-11-03 18:00:27 +0530221static const struct of_device_id exynos_dwc3_match[] = {
Vivek Gautamfe29db82013-01-24 19:15:30 +0530222 { .compatible = "samsung,exynos5250-dwusb3" },
Vivek Gautamed692a92014-11-21 19:05:47 +0530223 { .compatible = "samsung,exynos7-dwusb3" },
Vivek Gautamaccefdd2012-11-03 18:00:27 +0530224 {},
225};
226MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
Vivek Gautamaccefdd2012-11-03 18:00:27 +0530227
Jingoo Han19fda7c2013-03-26 01:52:48 +0000228#ifdef CONFIG_PM_SLEEP
Vikas Sajjan0646caf2012-10-16 15:15:38 +0530229static int dwc3_exynos_suspend(struct device *dev)
230{
231 struct dwc3_exynos *exynos = dev_get_drvdata(dev);
232
Vivek Gautamed692a92014-11-21 19:05:47 +0530233 clk_disable(exynos->axius_clk);
Vikas Sajjan0646caf2012-10-16 15:15:38 +0530234 clk_disable(exynos->clk);
235
Vivek Gautambd8ce542014-04-21 17:46:44 +0530236 regulator_disable(exynos->vdd33);
237 regulator_disable(exynos->vdd10);
238
Vikas Sajjan0646caf2012-10-16 15:15:38 +0530239 return 0;
240}
241
242static int dwc3_exynos_resume(struct device *dev)
243{
244 struct dwc3_exynos *exynos = dev_get_drvdata(dev);
Vivek Gautambd8ce542014-04-21 17:46:44 +0530245 int ret;
246
247 ret = regulator_enable(exynos->vdd33);
248 if (ret) {
249 dev_err(dev, "Failed to enable VDD33 supply\n");
250 return ret;
251 }
252 ret = regulator_enable(exynos->vdd10);
253 if (ret) {
254 dev_err(dev, "Failed to enable VDD10 supply\n");
255 return ret;
256 }
Vikas Sajjan0646caf2012-10-16 15:15:38 +0530257
258 clk_enable(exynos->clk);
Vivek Gautamed692a92014-11-21 19:05:47 +0530259 clk_enable(exynos->axius_clk);
Vikas Sajjan0646caf2012-10-16 15:15:38 +0530260
261 /* runtime set active to reflect active state. */
262 pm_runtime_disable(dev);
263 pm_runtime_set_active(dev);
264 pm_runtime_enable(dev);
265
266 return 0;
267}
268
269static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = {
270 SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume)
271};
272
273#define DEV_PM_OPS (&dwc3_exynos_dev_pm_ops)
274#else
275#define DEV_PM_OPS NULL
Jingoo Han19fda7c2013-03-26 01:52:48 +0000276#endif /* CONFIG_PM_SLEEP */
Vikas Sajjan0646caf2012-10-16 15:15:38 +0530277
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900278static struct platform_driver dwc3_exynos_driver = {
279 .probe = dwc3_exynos_probe,
Bill Pemberton76904172012-11-19 13:21:08 -0500280 .remove = dwc3_exynos_remove,
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900281 .driver = {
282 .name = "exynos-dwc3",
Jingoo Hanb4c9f572014-11-04 11:01:47 +0900283 .of_match_table = exynos_dwc3_match,
Vikas Sajjan0646caf2012-10-16 15:15:38 +0530284 .pm = DEV_PM_OPS,
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900285 },
286};
287
288module_platform_driver(dwc3_exynos_driver);
289
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900290MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
Felipe Balbi5945f782013-06-30 14:15:11 +0300291MODULE_LICENSE("GPL v2");
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900292MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");