2 * dwc3-exynos.c - Samsung EXYNOS DWC3 Specific Glue layer
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com
7 * Author: Anton Tikhomirov <av.tikhomirov@samsung.com>
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.
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.
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/slab.h>
22 #include <linux/platform_device.h>
23 #include <linux/clk.h>
24 #include <linux/usb/otg.h>
25 #include <linux/usb/usb_phy_generic.h>
27 #include <linux/of_platform.h>
28 #include <linux/regulator/consumer.h>
31 struct platform_device *usb2_phy;
32 struct platform_device *usb3_phy;
37 struct clk *axius_clk;
39 struct regulator *vdd33;
40 struct regulator *vdd10;
43 static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
45 struct usb_phy_generic_platform_data pdata;
46 struct platform_device *pdev;
49 memset(&pdata, 0x00, sizeof(pdata));
51 pdev = platform_device_alloc("usb_phy_generic", PLATFORM_DEVID_AUTO);
55 exynos->usb2_phy = pdev;
56 pdata.type = USB_PHY_TYPE_USB2;
57 pdata.gpio_reset = -1;
59 ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata));
63 pdev = platform_device_alloc("usb_phy_generic", PLATFORM_DEVID_AUTO);
69 exynos->usb3_phy = pdev;
70 pdata.type = USB_PHY_TYPE_USB3;
72 ret = platform_device_add_data(exynos->usb3_phy, &pdata, sizeof(pdata));
76 ret = platform_device_add(exynos->usb2_phy);
80 ret = platform_device_add(exynos->usb3_phy);
87 platform_device_del(exynos->usb2_phy);
90 platform_device_put(exynos->usb3_phy);
93 platform_device_put(exynos->usb2_phy);
98 static int dwc3_exynos_remove_child(struct device *dev, void *unused)
100 struct platform_device *pdev = to_platform_device(dev);
102 platform_device_unregister(pdev);
107 static int dwc3_exynos_probe(struct platform_device *pdev)
109 struct dwc3_exynos *exynos;
110 struct device *dev = &pdev->dev;
111 struct device_node *node = dev->of_node;
115 exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
119 platform_set_drvdata(pdev, exynos);
123 exynos->clk = devm_clk_get(dev, "usbdrd30");
124 if (IS_ERR(exynos->clk)) {
125 dev_err(dev, "couldn't get clock\n");
128 clk_prepare_enable(exynos->clk);
130 exynos->susp_clk = devm_clk_get(dev, "usbdrd30_susp_clk");
131 if (IS_ERR(exynos->susp_clk)) {
132 dev_info(dev, "no suspend clk specified\n");
133 exynos->susp_clk = NULL;
135 clk_prepare_enable(exynos->susp_clk);
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");
143 clk_prepare_enable(exynos->axius_clk);
145 exynos->axius_clk = NULL;
148 exynos->vdd33 = devm_regulator_get(dev, "vdd33");
149 if (IS_ERR(exynos->vdd33)) {
150 ret = PTR_ERR(exynos->vdd33);
153 ret = regulator_enable(exynos->vdd33);
155 dev_err(dev, "Failed to enable VDD33 supply\n");
159 exynos->vdd10 = devm_regulator_get(dev, "vdd10");
160 if (IS_ERR(exynos->vdd10)) {
161 ret = PTR_ERR(exynos->vdd10);
164 ret = regulator_enable(exynos->vdd10);
166 dev_err(dev, "Failed to enable VDD10 supply\n");
170 ret = dwc3_exynos_register_phys(exynos);
172 dev_err(dev, "couldn't register PHYs\n");
177 ret = of_platform_populate(node, NULL, NULL, dev);
179 dev_err(dev, "failed to add dwc3 core\n");
183 dev_err(dev, "no device node, failed to add dwc3 core\n");
191 platform_device_unregister(exynos->usb2_phy);
192 platform_device_unregister(exynos->usb3_phy);
194 regulator_disable(exynos->vdd10);
196 regulator_disable(exynos->vdd33);
198 clk_disable_unprepare(exynos->axius_clk);
199 clk_disable_unprepare(exynos->susp_clk);
200 clk_disable_unprepare(exynos->clk);
204 static int dwc3_exynos_remove(struct platform_device *pdev)
206 struct dwc3_exynos *exynos = platform_get_drvdata(pdev);
208 device_for_each_child(&pdev->dev, NULL, dwc3_exynos_remove_child);
209 platform_device_unregister(exynos->usb2_phy);
210 platform_device_unregister(exynos->usb3_phy);
212 clk_disable_unprepare(exynos->axius_clk);
213 clk_disable_unprepare(exynos->susp_clk);
214 clk_disable_unprepare(exynos->clk);
216 regulator_disable(exynos->vdd33);
217 regulator_disable(exynos->vdd10);
222 static const struct of_device_id exynos_dwc3_match[] = {
223 { .compatible = "samsung,exynos5250-dwusb3" },
224 { .compatible = "samsung,exynos7-dwusb3" },
227 MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
229 #ifdef CONFIG_PM_SLEEP
230 static int dwc3_exynos_suspend(struct device *dev)
232 struct dwc3_exynos *exynos = dev_get_drvdata(dev);
234 clk_disable(exynos->axius_clk);
235 clk_disable(exynos->clk);
237 regulator_disable(exynos->vdd33);
238 regulator_disable(exynos->vdd10);
243 static int dwc3_exynos_resume(struct device *dev)
245 struct dwc3_exynos *exynos = dev_get_drvdata(dev);
248 ret = regulator_enable(exynos->vdd33);
250 dev_err(dev, "Failed to enable VDD33 supply\n");
253 ret = regulator_enable(exynos->vdd10);
255 dev_err(dev, "Failed to enable VDD10 supply\n");
259 clk_enable(exynos->clk);
260 clk_enable(exynos->axius_clk);
262 /* runtime set active to reflect active state. */
263 pm_runtime_disable(dev);
264 pm_runtime_set_active(dev);
265 pm_runtime_enable(dev);
270 static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = {
271 SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume)
274 #define DEV_PM_OPS (&dwc3_exynos_dev_pm_ops)
276 #define DEV_PM_OPS NULL
277 #endif /* CONFIG_PM_SLEEP */
279 static struct platform_driver dwc3_exynos_driver = {
280 .probe = dwc3_exynos_probe,
281 .remove = dwc3_exynos_remove,
283 .name = "exynos-dwc3",
284 .of_match_table = exynos_dwc3_match,
289 module_platform_driver(dwc3_exynos_driver);
291 MODULE_ALIAS("platform:exynos-dwc3");
292 MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
293 MODULE_LICENSE("GPL v2");
294 MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");