aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/dwc3/dwc3-exynos.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/dwc3/dwc3-exynos.c')
-rw-r--r--drivers/usb/dwc3/dwc3-exynos.c98
1 files changed, 63 insertions, 35 deletions
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c
index b082bec7343e..a8afe6e26621 100644
--- a/drivers/usb/dwc3/dwc3-exynos.c
+++ b/drivers/usb/dwc3/dwc3-exynos.c
@@ -22,9 +22,9 @@
22#include <linux/usb/otg.h> 22#include <linux/usb/otg.h>
23#include <linux/usb/nop-usb-xceiv.h> 23#include <linux/usb/nop-usb-xceiv.h>
24#include <linux/of.h> 24#include <linux/of.h>
25#include <linux/of_platform.h>
25 26
26struct dwc3_exynos { 27struct dwc3_exynos {
27 struct platform_device *dwc3;
28 struct platform_device *usb2_phy; 28 struct platform_device *usb2_phy;
29 struct platform_device *usb3_phy; 29 struct platform_device *usb3_phy;
30 struct device *dev; 30 struct device *dev;
@@ -86,21 +86,30 @@ err1:
86 return ret; 86 return ret;
87} 87}
88 88
89static int dwc3_exynos_remove_child(struct device *dev, void *unused)
90{
91 struct platform_device *pdev = to_platform_device(dev);
92
93 platform_device_unregister(pdev);
94
95 return 0;
96}
97
89static u64 dwc3_exynos_dma_mask = DMA_BIT_MASK(32); 98static u64 dwc3_exynos_dma_mask = DMA_BIT_MASK(32);
90 99
91static int dwc3_exynos_probe(struct platform_device *pdev) 100static int dwc3_exynos_probe(struct platform_device *pdev)
92{ 101{
93 struct platform_device *dwc3;
94 struct dwc3_exynos *exynos; 102 struct dwc3_exynos *exynos;
95 struct clk *clk; 103 struct clk *clk;
96 struct device *dev = &pdev->dev; 104 struct device *dev = &pdev->dev;
105 struct device_node *node = dev->of_node;
97 106
98 int ret = -ENOMEM; 107 int ret = -ENOMEM;
99 108
100 exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); 109 exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
101 if (!exynos) { 110 if (!exynos) {
102 dev_err(dev, "not enough memory\n"); 111 dev_err(dev, "not enough memory\n");
103 return -ENOMEM; 112 goto err1;
104 } 113 }
105 114
106 /* 115 /*
@@ -108,21 +117,15 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
108 * Since shared usb code relies on it, set it here for now. 117 * Since shared usb code relies on it, set it here for now.
109 * Once we move to full device tree support this will vanish off. 118 * Once we move to full device tree support this will vanish off.
110 */ 119 */
111 if (!pdev->dev.dma_mask) 120 if (!dev->dma_mask)
112 pdev->dev.dma_mask = &dwc3_exynos_dma_mask; 121 dev->dma_mask = &dwc3_exynos_dma_mask;
113 122
114 platform_set_drvdata(pdev, exynos); 123 platform_set_drvdata(pdev, exynos);
115 124
116 ret = dwc3_exynos_register_phys(exynos); 125 ret = dwc3_exynos_register_phys(exynos);
117 if (ret) { 126 if (ret) {
118 dev_err(dev, "couldn't register PHYs\n"); 127 dev_err(dev, "couldn't register PHYs\n");
119 return ret; 128 goto err1;
120 }
121
122 dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
123 if (!dwc3) {
124 dev_err(dev, "couldn't allocate dwc3 device\n");
125 return -ENOMEM;
126 } 129 }
127 130
128 clk = devm_clk_get(dev, "usbdrd30"); 131 clk = devm_clk_get(dev, "usbdrd30");
@@ -132,37 +135,28 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
132 goto err1; 135 goto err1;
133 } 136 }
134 137
135 dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask);
136
137 dwc3->dev.parent = dev;
138 dwc3->dev.dma_mask = dev->dma_mask;
139 dwc3->dev.dma_parms = dev->dma_parms;
140 exynos->dwc3 = dwc3;
141 exynos->dev = dev; 138 exynos->dev = dev;
142 exynos->clk = clk; 139 exynos->clk = clk;
143 140
144 clk_enable(exynos->clk); 141 clk_prepare_enable(exynos->clk);
145 142
146 ret = platform_device_add_resources(dwc3, pdev->resource, 143 if (node) {
147 pdev->num_resources); 144 ret = of_platform_populate(node, NULL, NULL, dev);
148 if (ret) { 145 if (ret) {
149 dev_err(dev, "couldn't add resources to dwc3 device\n"); 146 dev_err(dev, "failed to add dwc3 core\n");
150 goto err2; 147 goto err2;
151 } 148 }
152 149 } else {
153 ret = platform_device_add(dwc3); 150 dev_err(dev, "no device node, failed to add dwc3 core\n");
154 if (ret) { 151 ret = -ENODEV;
155 dev_err(dev, "failed to register dwc3 device\n");
156 goto err2; 152 goto err2;
157 } 153 }
158 154
159 return 0; 155 return 0;
160 156
161err2: 157err2:
162 clk_disable(clk); 158 clk_disable_unprepare(clk);
163err1: 159err1:
164 platform_device_put(dwc3);
165
166 return ret; 160 return ret;
167} 161}
168 162
@@ -170,11 +164,11 @@ static int dwc3_exynos_remove(struct platform_device *pdev)
170{ 164{
171 struct dwc3_exynos *exynos = platform_get_drvdata(pdev); 165 struct dwc3_exynos *exynos = platform_get_drvdata(pdev);
172 166
173 platform_device_unregister(exynos->dwc3);
174 platform_device_unregister(exynos->usb2_phy); 167 platform_device_unregister(exynos->usb2_phy);
175 platform_device_unregister(exynos->usb3_phy); 168 platform_device_unregister(exynos->usb3_phy);
169 device_for_each_child(&pdev->dev, NULL, dwc3_exynos_remove_child);
176 170
177 clk_disable(exynos->clk); 171 clk_disable_unprepare(exynos->clk);
178 172
179 return 0; 173 return 0;
180} 174}
@@ -187,12 +181,46 @@ static const struct of_device_id exynos_dwc3_match[] = {
187MODULE_DEVICE_TABLE(of, exynos_dwc3_match); 181MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
188#endif 182#endif
189 183
184#ifdef CONFIG_PM_SLEEP
185static int dwc3_exynos_suspend(struct device *dev)
186{
187 struct dwc3_exynos *exynos = dev_get_drvdata(dev);
188
189 clk_disable(exynos->clk);
190
191 return 0;
192}
193
194static int dwc3_exynos_resume(struct device *dev)
195{
196 struct dwc3_exynos *exynos = dev_get_drvdata(dev);
197
198 clk_enable(exynos->clk);
199
200 /* runtime set active to reflect active state. */
201 pm_runtime_disable(dev);
202 pm_runtime_set_active(dev);
203 pm_runtime_enable(dev);
204
205 return 0;
206}
207
208static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = {
209 SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume)
210};
211
212#define DEV_PM_OPS (&dwc3_exynos_dev_pm_ops)
213#else
214#define DEV_PM_OPS NULL
215#endif /* CONFIG_PM_SLEEP */
216
190static struct platform_driver dwc3_exynos_driver = { 217static struct platform_driver dwc3_exynos_driver = {
191 .probe = dwc3_exynos_probe, 218 .probe = dwc3_exynos_probe,
192 .remove = dwc3_exynos_remove, 219 .remove = dwc3_exynos_remove,
193 .driver = { 220 .driver = {
194 .name = "exynos-dwc3", 221 .name = "exynos-dwc3",
195 .of_match_table = of_match_ptr(exynos_dwc3_match), 222 .of_match_table = of_match_ptr(exynos_dwc3_match),
223 .pm = DEV_PM_OPS,
196 }, 224 },
197}; 225};
198 226