Loading...
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Generic platform ohci driver
4 *
5 * Copyright 2007 Michael Buesch <m@bues.ch>
6 * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de>
7 * Copyright 2014 Hans de Goede <hdegoede@redhat.com>
8 *
9 * Derived from the OCHI-SSB driver
10 * Derived from the OHCI-PCI driver
11 * Copyright 1999 Roman Weissgaerber
12 * Copyright 2000-2002 David Brownell
13 * Copyright 1999 Linus Torvalds
14 * Copyright 1999 Gregory P. Smith
15 */
16
17#include <linux/clk.h>
18#include <linux/dma-mapping.h>
19#include <linux/hrtimer.h>
20#include <linux/io.h>
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/err.h>
24#include <linux/of.h>
25#include <linux/platform_device.h>
26#include <linux/pm_runtime.h>
27#include <linux/reset.h>
28#include <linux/usb/ohci_pdriver.h>
29#include <linux/usb.h>
30#include <linux/usb/hcd.h>
31#include <linux/usb/of.h>
32
33#include "ohci.h"
34
35#define DRIVER_DESC "OHCI generic platform driver"
36#define OHCI_MAX_CLKS 4
37#define hcd_to_ohci_priv(h) ((struct ohci_platform_priv *)hcd_to_ohci(h)->priv)
38
39struct ohci_platform_priv {
40 struct clk *clks[OHCI_MAX_CLKS];
41 struct reset_control *resets;
42};
43
44static int ohci_platform_power_on(struct platform_device *dev)
45{
46 struct usb_hcd *hcd = platform_get_drvdata(dev);
47 struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
48 int clk, ret;
49
50 for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++) {
51 ret = clk_prepare_enable(priv->clks[clk]);
52 if (ret)
53 goto err_disable_clks;
54 }
55
56 return 0;
57
58err_disable_clks:
59 while (--clk >= 0)
60 clk_disable_unprepare(priv->clks[clk]);
61
62 return ret;
63}
64
65static void ohci_platform_power_off(struct platform_device *dev)
66{
67 struct usb_hcd *hcd = platform_get_drvdata(dev);
68 struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
69 int clk;
70
71 for (clk = OHCI_MAX_CLKS - 1; clk >= 0; clk--)
72 if (priv->clks[clk])
73 clk_disable_unprepare(priv->clks[clk]);
74}
75
76static struct hc_driver __read_mostly ohci_platform_hc_driver;
77
78static const struct ohci_driver_overrides platform_overrides __initconst = {
79 .product_desc = "Generic Platform OHCI controller",
80 .extra_priv_size = sizeof(struct ohci_platform_priv),
81};
82
83static struct usb_ohci_pdata ohci_platform_defaults = {
84 .power_on = ohci_platform_power_on,
85 .power_suspend = ohci_platform_power_off,
86 .power_off = ohci_platform_power_off,
87};
88
89static int ohci_platform_probe(struct platform_device *dev)
90{
91 struct usb_hcd *hcd;
92 struct resource *res_mem;
93 struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
94 struct ohci_platform_priv *priv;
95 struct ohci_hcd *ohci;
96 int err, irq, clk = 0;
97
98 if (usb_disabled())
99 return -ENODEV;
100
101 /*
102 * Use reasonable defaults so platforms don't have to provide these
103 * with DT probing on ARM.
104 */
105 if (!pdata)
106 pdata = &ohci_platform_defaults;
107
108 err = dma_coerce_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32));
109 if (err)
110 return err;
111
112 irq = platform_get_irq(dev, 0);
113 if (irq < 0)
114 return irq;
115
116 hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
117 dev_name(&dev->dev));
118 if (!hcd)
119 return -ENOMEM;
120
121 platform_set_drvdata(dev, hcd);
122 dev->dev.platform_data = pdata;
123 priv = hcd_to_ohci_priv(hcd);
124 ohci = hcd_to_ohci(hcd);
125
126 if (pdata == &ohci_platform_defaults && dev->dev.of_node) {
127 if (of_property_read_bool(dev->dev.of_node, "big-endian-regs"))
128 ohci->flags |= OHCI_QUIRK_BE_MMIO;
129
130 if (of_property_read_bool(dev->dev.of_node, "big-endian-desc"))
131 ohci->flags |= OHCI_QUIRK_BE_DESC;
132
133 if (of_property_read_bool(dev->dev.of_node, "big-endian"))
134 ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC;
135
136 if (of_property_read_bool(dev->dev.of_node, "no-big-frame-no"))
137 ohci->flags |= OHCI_QUIRK_FRAME_NO;
138
139 if (of_property_read_bool(dev->dev.of_node,
140 "remote-wakeup-connected"))
141 ohci->hc_control = OHCI_CTRL_RWC;
142
143 of_property_read_u32(dev->dev.of_node, "num-ports",
144 &ohci->num_ports);
145
146 for (clk = 0; clk < OHCI_MAX_CLKS; clk++) {
147 priv->clks[clk] = of_clk_get(dev->dev.of_node, clk);
148 if (IS_ERR(priv->clks[clk])) {
149 err = PTR_ERR(priv->clks[clk]);
150 if (err == -EPROBE_DEFER)
151 goto err_put_clks;
152 priv->clks[clk] = NULL;
153 break;
154 }
155 }
156
157 priv->resets = devm_reset_control_array_get_optional_shared(
158 &dev->dev);
159 if (IS_ERR(priv->resets)) {
160 err = PTR_ERR(priv->resets);
161 goto err_put_clks;
162 }
163
164 err = reset_control_deassert(priv->resets);
165 if (err)
166 goto err_put_clks;
167 }
168
169 if (pdata->big_endian_desc)
170 ohci->flags |= OHCI_QUIRK_BE_DESC;
171 if (pdata->big_endian_mmio)
172 ohci->flags |= OHCI_QUIRK_BE_MMIO;
173 if (pdata->no_big_frame_no)
174 ohci->flags |= OHCI_QUIRK_FRAME_NO;
175 if (pdata->num_ports)
176 ohci->num_ports = pdata->num_ports;
177
178#ifndef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO
179 if (ohci->flags & OHCI_QUIRK_BE_MMIO) {
180 dev_err(&dev->dev,
181 "Error: CONFIG_USB_OHCI_BIG_ENDIAN_MMIO not set\n");
182 err = -EINVAL;
183 goto err_reset;
184 }
185#endif
186#ifndef CONFIG_USB_OHCI_BIG_ENDIAN_DESC
187 if (ohci->flags & OHCI_QUIRK_BE_DESC) {
188 dev_err(&dev->dev,
189 "Error: CONFIG_USB_OHCI_BIG_ENDIAN_DESC not set\n");
190 err = -EINVAL;
191 goto err_reset;
192 }
193#endif
194
195 pm_runtime_set_active(&dev->dev);
196 pm_runtime_enable(&dev->dev);
197 if (pdata->power_on) {
198 err = pdata->power_on(dev);
199 if (err < 0)
200 goto err_reset;
201 }
202
203 hcd->regs = devm_platform_get_and_ioremap_resource(dev, 0, &res_mem);
204 if (IS_ERR(hcd->regs)) {
205 err = PTR_ERR(hcd->regs);
206 goto err_power;
207 }
208 hcd->rsrc_start = res_mem->start;
209 hcd->rsrc_len = resource_size(res_mem);
210
211 hcd->tpl_support = of_usb_host_tpl_support(dev->dev.of_node);
212
213 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
214 if (err)
215 goto err_power;
216
217 device_wakeup_enable(hcd->self.controller);
218
219 platform_set_drvdata(dev, hcd);
220
221 return err;
222
223err_power:
224 if (pdata->power_off)
225 pdata->power_off(dev);
226err_reset:
227 pm_runtime_disable(&dev->dev);
228 reset_control_assert(priv->resets);
229err_put_clks:
230 while (--clk >= 0)
231 clk_put(priv->clks[clk]);
232
233 if (pdata == &ohci_platform_defaults)
234 dev->dev.platform_data = NULL;
235
236 usb_put_hcd(hcd);
237
238 return err;
239}
240
241static void ohci_platform_remove(struct platform_device *dev)
242{
243 struct usb_hcd *hcd = platform_get_drvdata(dev);
244 struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
245 struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
246 int clk;
247
248 pm_runtime_get_sync(&dev->dev);
249 usb_remove_hcd(hcd);
250
251 if (pdata->power_off)
252 pdata->power_off(dev);
253
254 reset_control_assert(priv->resets);
255
256 for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++)
257 clk_put(priv->clks[clk]);
258
259 usb_put_hcd(hcd);
260
261 pm_runtime_put_sync(&dev->dev);
262 pm_runtime_disable(&dev->dev);
263
264 if (pdata == &ohci_platform_defaults)
265 dev->dev.platform_data = NULL;
266}
267
268#ifdef CONFIG_PM_SLEEP
269static int ohci_platform_suspend(struct device *dev)
270{
271 struct usb_hcd *hcd = dev_get_drvdata(dev);
272 struct usb_ohci_pdata *pdata = dev->platform_data;
273 struct platform_device *pdev = to_platform_device(dev);
274 bool do_wakeup = device_may_wakeup(dev);
275 int ret;
276
277 ret = ohci_suspend(hcd, do_wakeup);
278 if (ret)
279 return ret;
280
281 if (pdata->power_suspend)
282 pdata->power_suspend(pdev);
283
284 return ret;
285}
286
287static int ohci_platform_resume_common(struct device *dev, bool hibernated)
288{
289 struct usb_hcd *hcd = dev_get_drvdata(dev);
290 struct usb_ohci_pdata *pdata = dev_get_platdata(dev);
291 struct platform_device *pdev = to_platform_device(dev);
292
293 if (pdata->power_on) {
294 int err = pdata->power_on(pdev);
295 if (err < 0)
296 return err;
297 }
298
299 ohci_resume(hcd, hibernated);
300
301 pm_runtime_disable(dev);
302 pm_runtime_set_active(dev);
303 pm_runtime_enable(dev);
304
305 return 0;
306}
307
308static int ohci_platform_resume(struct device *dev)
309{
310 return ohci_platform_resume_common(dev, false);
311}
312
313static int ohci_platform_restore(struct device *dev)
314{
315 return ohci_platform_resume_common(dev, true);
316}
317#endif /* CONFIG_PM_SLEEP */
318
319static const struct of_device_id ohci_platform_ids[] = {
320 { .compatible = "generic-ohci", },
321 { .compatible = "cavium,octeon-6335-ohci", },
322 { .compatible = "ti,ohci-omap3", },
323 { }
324};
325MODULE_DEVICE_TABLE(of, ohci_platform_ids);
326
327static const struct platform_device_id ohci_platform_table[] = {
328 { "ohci-platform", 0 },
329 { }
330};
331MODULE_DEVICE_TABLE(platform, ohci_platform_table);
332
333#ifdef CONFIG_PM_SLEEP
334static const struct dev_pm_ops ohci_platform_pm_ops = {
335 .suspend = ohci_platform_suspend,
336 .resume = ohci_platform_resume,
337 .freeze = ohci_platform_suspend,
338 .thaw = ohci_platform_resume,
339 .poweroff = ohci_platform_suspend,
340 .restore = ohci_platform_restore,
341};
342#endif
343
344static struct platform_driver ohci_platform_driver = {
345 .id_table = ohci_platform_table,
346 .probe = ohci_platform_probe,
347 .remove_new = ohci_platform_remove,
348 .shutdown = usb_hcd_platform_shutdown,
349 .driver = {
350 .name = "ohci-platform",
351#ifdef CONFIG_PM_SLEEP
352 .pm = &ohci_platform_pm_ops,
353#endif
354 .of_match_table = ohci_platform_ids,
355 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
356 }
357};
358
359static int __init ohci_platform_init(void)
360{
361 if (usb_disabled())
362 return -ENODEV;
363
364 ohci_init_driver(&ohci_platform_hc_driver, &platform_overrides);
365 return platform_driver_register(&ohci_platform_driver);
366}
367module_init(ohci_platform_init);
368
369static void __exit ohci_platform_cleanup(void)
370{
371 platform_driver_unregister(&ohci_platform_driver);
372}
373module_exit(ohci_platform_cleanup);
374
375MODULE_DESCRIPTION(DRIVER_DESC);
376MODULE_AUTHOR("Hauke Mehrtens");
377MODULE_AUTHOR("Alan Stern");
378MODULE_LICENSE("GPL");
1/*
2 * Generic platform ohci driver
3 *
4 * Copyright 2007 Michael Buesch <m@bues.ch>
5 * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de>
6 * Copyright 2014 Hans de Goede <hdegoede@redhat.com>
7 *
8 * Derived from the OCHI-SSB driver
9 * Derived from the OHCI-PCI driver
10 * Copyright 1999 Roman Weissgaerber
11 * Copyright 2000-2002 David Brownell
12 * Copyright 1999 Linus Torvalds
13 * Copyright 1999 Gregory P. Smith
14 *
15 * Licensed under the GNU/GPL. See COPYING for details.
16 */
17
18#include <linux/clk.h>
19#include <linux/dma-mapping.h>
20#include <linux/hrtimer.h>
21#include <linux/io.h>
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/err.h>
25#include <linux/phy/phy.h>
26#include <linux/platform_device.h>
27#include <linux/reset.h>
28#include <linux/usb/ohci_pdriver.h>
29#include <linux/usb.h>
30#include <linux/usb/hcd.h>
31
32#include "ohci.h"
33
34#define DRIVER_DESC "OHCI generic platform driver"
35#define OHCI_MAX_CLKS 3
36#define hcd_to_ohci_priv(h) ((struct ohci_platform_priv *)hcd_to_ohci(h)->priv)
37
38struct ohci_platform_priv {
39 struct clk *clks[OHCI_MAX_CLKS];
40 struct reset_control *rst;
41 struct phy **phys;
42 int num_phys;
43};
44
45static const char hcd_name[] = "ohci-platform";
46
47static int ohci_platform_power_on(struct platform_device *dev)
48{
49 struct usb_hcd *hcd = platform_get_drvdata(dev);
50 struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
51 int clk, ret, phy_num;
52
53 for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++) {
54 ret = clk_prepare_enable(priv->clks[clk]);
55 if (ret)
56 goto err_disable_clks;
57 }
58
59 for (phy_num = 0; phy_num < priv->num_phys; phy_num++) {
60 ret = phy_init(priv->phys[phy_num]);
61 if (ret)
62 goto err_exit_phy;
63 ret = phy_power_on(priv->phys[phy_num]);
64 if (ret) {
65 phy_exit(priv->phys[phy_num]);
66 goto err_exit_phy;
67 }
68 }
69
70 return 0;
71
72err_exit_phy:
73 while (--phy_num >= 0) {
74 phy_power_off(priv->phys[phy_num]);
75 phy_exit(priv->phys[phy_num]);
76 }
77err_disable_clks:
78 while (--clk >= 0)
79 clk_disable_unprepare(priv->clks[clk]);
80
81 return ret;
82}
83
84static void ohci_platform_power_off(struct platform_device *dev)
85{
86 struct usb_hcd *hcd = platform_get_drvdata(dev);
87 struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
88 int clk, phy_num;
89
90 for (phy_num = 0; phy_num < priv->num_phys; phy_num++) {
91 phy_power_off(priv->phys[phy_num]);
92 phy_exit(priv->phys[phy_num]);
93 }
94
95 for (clk = OHCI_MAX_CLKS - 1; clk >= 0; clk--)
96 if (priv->clks[clk])
97 clk_disable_unprepare(priv->clks[clk]);
98}
99
100static struct hc_driver __read_mostly ohci_platform_hc_driver;
101
102static const struct ohci_driver_overrides platform_overrides __initconst = {
103 .product_desc = "Generic Platform OHCI controller",
104 .extra_priv_size = sizeof(struct ohci_platform_priv),
105};
106
107static struct usb_ohci_pdata ohci_platform_defaults = {
108 .power_on = ohci_platform_power_on,
109 .power_suspend = ohci_platform_power_off,
110 .power_off = ohci_platform_power_off,
111};
112
113static int ohci_platform_probe(struct platform_device *dev)
114{
115 struct usb_hcd *hcd;
116 struct resource *res_mem;
117 struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
118 struct ohci_platform_priv *priv;
119 struct ohci_hcd *ohci;
120 int err, irq, phy_num, clk = 0;
121
122 if (usb_disabled())
123 return -ENODEV;
124
125 /*
126 * Use reasonable defaults so platforms don't have to provide these
127 * with DT probing on ARM.
128 */
129 if (!pdata)
130 pdata = &ohci_platform_defaults;
131
132 err = dma_coerce_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32));
133 if (err)
134 return err;
135
136 irq = platform_get_irq(dev, 0);
137 if (irq < 0) {
138 dev_err(&dev->dev, "no irq provided");
139 return irq;
140 }
141
142 hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
143 dev_name(&dev->dev));
144 if (!hcd)
145 return -ENOMEM;
146
147 platform_set_drvdata(dev, hcd);
148 dev->dev.platform_data = pdata;
149 priv = hcd_to_ohci_priv(hcd);
150 ohci = hcd_to_ohci(hcd);
151
152 if (pdata == &ohci_platform_defaults && dev->dev.of_node) {
153 if (of_property_read_bool(dev->dev.of_node, "big-endian-regs"))
154 ohci->flags |= OHCI_QUIRK_BE_MMIO;
155
156 if (of_property_read_bool(dev->dev.of_node, "big-endian-desc"))
157 ohci->flags |= OHCI_QUIRK_BE_DESC;
158
159 if (of_property_read_bool(dev->dev.of_node, "big-endian"))
160 ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC;
161
162 if (of_property_read_bool(dev->dev.of_node, "no-big-frame-no"))
163 ohci->flags |= OHCI_QUIRK_FRAME_NO;
164
165 of_property_read_u32(dev->dev.of_node, "num-ports",
166 &ohci->num_ports);
167
168 priv->num_phys = of_count_phandle_with_args(dev->dev.of_node,
169 "phys", "#phy-cells");
170
171 if (priv->num_phys > 0) {
172 priv->phys = devm_kcalloc(&dev->dev, priv->num_phys,
173 sizeof(struct phy *), GFP_KERNEL);
174 if (!priv->phys)
175 return -ENOMEM;
176 } else
177 priv->num_phys = 0;
178
179 for (phy_num = 0; phy_num < priv->num_phys; phy_num++) {
180 priv->phys[phy_num] = devm_of_phy_get_by_index(
181 &dev->dev, dev->dev.of_node, phy_num);
182 if (IS_ERR(priv->phys[phy_num])) {
183 err = PTR_ERR(priv->phys[phy_num]);
184 goto err_put_hcd;
185 }
186 }
187
188 for (clk = 0; clk < OHCI_MAX_CLKS; clk++) {
189 priv->clks[clk] = of_clk_get(dev->dev.of_node, clk);
190 if (IS_ERR(priv->clks[clk])) {
191 err = PTR_ERR(priv->clks[clk]);
192 if (err == -EPROBE_DEFER)
193 goto err_put_clks;
194 priv->clks[clk] = NULL;
195 break;
196 }
197 }
198
199 }
200
201 priv->rst = devm_reset_control_get_optional(&dev->dev, NULL);
202 if (IS_ERR(priv->rst)) {
203 err = PTR_ERR(priv->rst);
204 if (err == -EPROBE_DEFER)
205 goto err_put_clks;
206 priv->rst = NULL;
207 } else {
208 err = reset_control_deassert(priv->rst);
209 if (err)
210 goto err_put_clks;
211 }
212
213 if (pdata->big_endian_desc)
214 ohci->flags |= OHCI_QUIRK_BE_DESC;
215 if (pdata->big_endian_mmio)
216 ohci->flags |= OHCI_QUIRK_BE_MMIO;
217 if (pdata->no_big_frame_no)
218 ohci->flags |= OHCI_QUIRK_FRAME_NO;
219 if (pdata->num_ports)
220 ohci->num_ports = pdata->num_ports;
221
222#ifndef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO
223 if (ohci->flags & OHCI_QUIRK_BE_MMIO) {
224 dev_err(&dev->dev,
225 "Error: CONFIG_USB_OHCI_BIG_ENDIAN_MMIO not set\n");
226 err = -EINVAL;
227 goto err_reset;
228 }
229#endif
230#ifndef CONFIG_USB_OHCI_BIG_ENDIAN_DESC
231 if (ohci->flags & OHCI_QUIRK_BE_DESC) {
232 dev_err(&dev->dev,
233 "Error: CONFIG_USB_OHCI_BIG_ENDIAN_DESC not set\n");
234 err = -EINVAL;
235 goto err_reset;
236 }
237#endif
238
239 if (pdata->power_on) {
240 err = pdata->power_on(dev);
241 if (err < 0)
242 goto err_reset;
243 }
244
245 res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
246 hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
247 if (IS_ERR(hcd->regs)) {
248 err = PTR_ERR(hcd->regs);
249 goto err_power;
250 }
251 hcd->rsrc_start = res_mem->start;
252 hcd->rsrc_len = resource_size(res_mem);
253
254 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
255 if (err)
256 goto err_power;
257
258 device_wakeup_enable(hcd->self.controller);
259
260 platform_set_drvdata(dev, hcd);
261
262 return err;
263
264err_power:
265 if (pdata->power_off)
266 pdata->power_off(dev);
267err_reset:
268 if (priv->rst)
269 reset_control_assert(priv->rst);
270err_put_clks:
271 while (--clk >= 0)
272 clk_put(priv->clks[clk]);
273err_put_hcd:
274 if (pdata == &ohci_platform_defaults)
275 dev->dev.platform_data = NULL;
276
277 usb_put_hcd(hcd);
278
279 return err;
280}
281
282static int ohci_platform_remove(struct platform_device *dev)
283{
284 struct usb_hcd *hcd = platform_get_drvdata(dev);
285 struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
286 struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
287 int clk;
288
289 usb_remove_hcd(hcd);
290
291 if (pdata->power_off)
292 pdata->power_off(dev);
293
294 if (priv->rst)
295 reset_control_assert(priv->rst);
296
297 for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++)
298 clk_put(priv->clks[clk]);
299
300 usb_put_hcd(hcd);
301
302 if (pdata == &ohci_platform_defaults)
303 dev->dev.platform_data = NULL;
304
305 return 0;
306}
307
308#ifdef CONFIG_PM_SLEEP
309static int ohci_platform_suspend(struct device *dev)
310{
311 struct usb_hcd *hcd = dev_get_drvdata(dev);
312 struct usb_ohci_pdata *pdata = dev->platform_data;
313 struct platform_device *pdev = to_platform_device(dev);
314 bool do_wakeup = device_may_wakeup(dev);
315 int ret;
316
317 ret = ohci_suspend(hcd, do_wakeup);
318 if (ret)
319 return ret;
320
321 if (pdata->power_suspend)
322 pdata->power_suspend(pdev);
323
324 return ret;
325}
326
327static int ohci_platform_resume(struct device *dev)
328{
329 struct usb_hcd *hcd = dev_get_drvdata(dev);
330 struct usb_ohci_pdata *pdata = dev_get_platdata(dev);
331 struct platform_device *pdev = to_platform_device(dev);
332
333 if (pdata->power_on) {
334 int err = pdata->power_on(pdev);
335 if (err < 0)
336 return err;
337 }
338
339 ohci_resume(hcd, false);
340 return 0;
341}
342#endif /* CONFIG_PM_SLEEP */
343
344static const struct of_device_id ohci_platform_ids[] = {
345 { .compatible = "generic-ohci", },
346 { .compatible = "cavium,octeon-6335-ohci", },
347 { }
348};
349MODULE_DEVICE_TABLE(of, ohci_platform_ids);
350
351static const struct platform_device_id ohci_platform_table[] = {
352 { "ohci-platform", 0 },
353 { }
354};
355MODULE_DEVICE_TABLE(platform, ohci_platform_table);
356
357static SIMPLE_DEV_PM_OPS(ohci_platform_pm_ops, ohci_platform_suspend,
358 ohci_platform_resume);
359
360static struct platform_driver ohci_platform_driver = {
361 .id_table = ohci_platform_table,
362 .probe = ohci_platform_probe,
363 .remove = ohci_platform_remove,
364 .shutdown = usb_hcd_platform_shutdown,
365 .driver = {
366 .name = "ohci-platform",
367 .pm = &ohci_platform_pm_ops,
368 .of_match_table = ohci_platform_ids,
369 }
370};
371
372static int __init ohci_platform_init(void)
373{
374 if (usb_disabled())
375 return -ENODEV;
376
377 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
378
379 ohci_init_driver(&ohci_platform_hc_driver, &platform_overrides);
380 return platform_driver_register(&ohci_platform_driver);
381}
382module_init(ohci_platform_init);
383
384static void __exit ohci_platform_cleanup(void)
385{
386 platform_driver_unregister(&ohci_platform_driver);
387}
388module_exit(ohci_platform_cleanup);
389
390MODULE_DESCRIPTION(DRIVER_DESC);
391MODULE_AUTHOR("Hauke Mehrtens");
392MODULE_AUTHOR("Alan Stern");
393MODULE_LICENSE("GPL");