Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
[linux-2.6.git] / drivers / usb / dwc3 / dwc3-exynos.c
blob8ce9d7fd6cfc30051462373d3c8d1f2b681dfcb3
1 /**
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 as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/slab.h>
18 #include <linux/platform_device.h>
19 #include <linux/platform_data/dwc3-exynos.h>
20 #include <linux/dma-mapping.h>
21 #include <linux/clk.h>
22 #include <linux/usb/otg.h>
23 #include <linux/usb/nop-usb-xceiv.h>
24 #include <linux/of.h>
25 #include <linux/of_platform.h>
27 struct dwc3_exynos {
28 struct platform_device *usb2_phy;
29 struct platform_device *usb3_phy;
30 struct device *dev;
32 struct clk *clk;
35 static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
37 struct nop_usb_xceiv_platform_data pdata;
38 struct platform_device *pdev;
39 int ret;
41 memset(&pdata, 0x00, sizeof(pdata));
43 pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
44 if (!pdev)
45 return -ENOMEM;
47 exynos->usb2_phy = pdev;
48 pdata.type = USB_PHY_TYPE_USB2;
50 ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata));
51 if (ret)
52 goto err1;
54 pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
55 if (!pdev) {
56 ret = -ENOMEM;
57 goto err1;
60 exynos->usb3_phy = pdev;
61 pdata.type = USB_PHY_TYPE_USB3;
63 ret = platform_device_add_data(exynos->usb3_phy, &pdata, sizeof(pdata));
64 if (ret)
65 goto err2;
67 ret = platform_device_add(exynos->usb2_phy);
68 if (ret)
69 goto err2;
71 ret = platform_device_add(exynos->usb3_phy);
72 if (ret)
73 goto err3;
75 return 0;
77 err3:
78 platform_device_del(exynos->usb2_phy);
80 err2:
81 platform_device_put(exynos->usb3_phy);
83 err1:
84 platform_device_put(exynos->usb2_phy);
86 return ret;
89 static int dwc3_exynos_remove_child(struct device *dev, void *unused)
91 struct platform_device *pdev = to_platform_device(dev);
93 platform_device_unregister(pdev);
95 return 0;
98 static int dwc3_exynos_probe(struct platform_device *pdev)
100 struct dwc3_exynos *exynos;
101 struct clk *clk;
102 struct device *dev = &pdev->dev;
103 struct device_node *node = dev->of_node;
105 int ret = -ENOMEM;
107 exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
108 if (!exynos) {
109 dev_err(dev, "not enough memory\n");
110 goto err1;
114 * Right now device-tree probed devices don't get dma_mask set.
115 * Since shared usb code relies on it, set it here for now.
116 * Once we move to full device tree support this will vanish off.
118 if (!dev->dma_mask)
119 dev->dma_mask = &dev->coherent_dma_mask;
120 if (!dev->coherent_dma_mask)
121 dev->coherent_dma_mask = DMA_BIT_MASK(32);
123 platform_set_drvdata(pdev, exynos);
125 ret = dwc3_exynos_register_phys(exynos);
126 if (ret) {
127 dev_err(dev, "couldn't register PHYs\n");
128 goto err1;
131 clk = devm_clk_get(dev, "usbdrd30");
132 if (IS_ERR(clk)) {
133 dev_err(dev, "couldn't get clock\n");
134 ret = -EINVAL;
135 goto err1;
138 exynos->dev = dev;
139 exynos->clk = clk;
141 clk_prepare_enable(exynos->clk);
143 if (node) {
144 ret = of_platform_populate(node, NULL, NULL, dev);
145 if (ret) {
146 dev_err(dev, "failed to add dwc3 core\n");
147 goto err2;
149 } else {
150 dev_err(dev, "no device node, failed to add dwc3 core\n");
151 ret = -ENODEV;
152 goto err2;
155 return 0;
157 err2:
158 clk_disable_unprepare(clk);
159 err1:
160 return ret;
163 static int dwc3_exynos_remove(struct platform_device *pdev)
165 struct dwc3_exynos *exynos = platform_get_drvdata(pdev);
167 device_for_each_child(&pdev->dev, NULL, dwc3_exynos_remove_child);
168 platform_device_unregister(exynos->usb2_phy);
169 platform_device_unregister(exynos->usb3_phy);
171 clk_disable_unprepare(exynos->clk);
173 return 0;
176 #ifdef CONFIG_OF
177 static const struct of_device_id exynos_dwc3_match[] = {
178 { .compatible = "samsung,exynos5250-dwusb3" },
181 MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
182 #endif
184 #ifdef CONFIG_PM_SLEEP
185 static int dwc3_exynos_suspend(struct device *dev)
187 struct dwc3_exynos *exynos = dev_get_drvdata(dev);
189 clk_disable(exynos->clk);
191 return 0;
194 static int dwc3_exynos_resume(struct device *dev)
196 struct dwc3_exynos *exynos = dev_get_drvdata(dev);
198 clk_enable(exynos->clk);
200 /* runtime set active to reflect active state. */
201 pm_runtime_disable(dev);
202 pm_runtime_set_active(dev);
203 pm_runtime_enable(dev);
205 return 0;
208 static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = {
209 SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume)
212 #define DEV_PM_OPS (&dwc3_exynos_dev_pm_ops)
213 #else
214 #define DEV_PM_OPS NULL
215 #endif /* CONFIG_PM_SLEEP */
217 static struct platform_driver dwc3_exynos_driver = {
218 .probe = dwc3_exynos_probe,
219 .remove = dwc3_exynos_remove,
220 .driver = {
221 .name = "exynos-dwc3",
222 .of_match_table = of_match_ptr(exynos_dwc3_match),
223 .pm = DEV_PM_OPS,
227 module_platform_driver(dwc3_exynos_driver);
229 MODULE_ALIAS("platform:exynos-dwc3");
230 MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
231 MODULE_LICENSE("GPL");
232 MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");