blob: c3e7287f792170028f89cd65192fda0ac5a3d915 [file] [log] [blame]
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +01001/*
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 *
7 * Derived from the OCHI-SSB driver
8 * Derived from the OHCI-PCI driver
9 * Copyright 1999 Roman Weissgaerber
10 * Copyright 2000-2002 David Brownell
11 * Copyright 1999 Linus Torvalds
12 * Copyright 1999 Gregory P. Smith
13 *
14 * Licensed under the GNU/GPL. See COPYING for details.
15 */
Thierry Reding148e1132013-01-21 11:09:22 +010016#include <linux/err.h>
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010017#include <linux/platform_device.h>
18#include <linux/usb/ohci_pdriver.h>
19
20static int ohci_platform_reset(struct usb_hcd *hcd)
21{
22 struct platform_device *pdev = to_platform_device(hcd->self.controller);
23 struct usb_ohci_pdata *pdata = pdev->dev.platform_data;
24 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
25 int err;
26
27 if (pdata->big_endian_desc)
28 ohci->flags |= OHCI_QUIRK_BE_DESC;
29 if (pdata->big_endian_mmio)
30 ohci->flags |= OHCI_QUIRK_BE_MMIO;
31 if (pdata->no_big_frame_no)
32 ohci->flags |= OHCI_QUIRK_FRAME_NO;
33
34 ohci_hcd_init(ohci);
Florian Fainelli2b16e392012-10-08 15:11:26 +020035
36 if (pdata->num_ports)
37 ohci->num_ports = pdata->num_ports;
38
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010039 err = ohci_init(ohci);
40
41 return err;
42}
43
44static int ohci_platform_start(struct usb_hcd *hcd)
45{
46 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
47 int err;
48
49 err = ohci_run(ohci);
50 if (err < 0) {
51 ohci_err(ohci, "can't start\n");
52 ohci_stop(hcd);
53 }
54
55 return err;
56}
57
58static const struct hc_driver ohci_platform_hc_driver = {
59 .description = hcd_name,
60 .product_desc = "Generic Platform OHCI Controller",
61 .hcd_priv_size = sizeof(struct ohci_hcd),
62
63 .irq = ohci_irq,
64 .flags = HCD_MEMORY | HCD_USB11,
65
66 .reset = ohci_platform_reset,
67 .start = ohci_platform_start,
68 .stop = ohci_stop,
69 .shutdown = ohci_shutdown,
70
71 .urb_enqueue = ohci_urb_enqueue,
72 .urb_dequeue = ohci_urb_dequeue,
73 .endpoint_disable = ohci_endpoint_disable,
74
75 .get_frame_number = ohci_get_frame,
76
77 .hub_status_data = ohci_hub_status_data,
78 .hub_control = ohci_hub_control,
79#ifdef CONFIG_PM
80 .bus_suspend = ohci_bus_suspend,
81 .bus_resume = ohci_bus_resume,
82#endif
83
84 .start_port_reset = ohci_start_port_reset,
85};
86
Bill Pemberton41ac7b32012-11-19 13:21:48 -050087static int ohci_platform_probe(struct platform_device *dev)
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010088{
89 struct usb_hcd *hcd;
90 struct resource *res_mem;
Kuninori Morimotob6dd2452012-08-06 18:07:30 -070091 struct usb_ohci_pdata *pdata = dev->dev.platform_data;
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010092 int irq;
93 int err = -ENOMEM;
94
Kuninori Morimotob6dd2452012-08-06 18:07:30 -070095 if (!pdata) {
96 WARN_ON(1);
97 return -ENODEV;
98 }
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010099
100 if (usb_disabled())
101 return -ENODEV;
102
103 irq = platform_get_irq(dev, 0);
104 if (irq < 0) {
Florian Fainelli976baf6e2012-10-08 15:11:42 +0200105 dev_err(&dev->dev, "no irq provided");
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100106 return irq;
107 }
108
109 res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
110 if (!res_mem) {
Florian Fainelliac0e3c02012-10-08 15:11:44 +0200111 dev_err(&dev->dev, "no memory resource provided");
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100112 return -ENXIO;
113 }
114
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700115 if (pdata->power_on) {
116 err = pdata->power_on(dev);
117 if (err < 0)
118 return err;
119 }
120
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100121 hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
122 dev_name(&dev->dev));
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700123 if (!hcd) {
124 err = -ENOMEM;
125 goto err_power;
126 }
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100127
128 hcd->rsrc_start = res_mem->start;
129 hcd->rsrc_len = resource_size(res_mem);
130
Thierry Reding148e1132013-01-21 11:09:22 +0100131 hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
132 if (IS_ERR(hcd->regs)) {
133 err = PTR_ERR(hcd->regs);
Florian Fainellibe7ac702012-10-08 15:11:46 +0200134 goto err_put_hcd;
Julia Lawallaece3892012-08-14 08:47:37 +0200135 }
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100136 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
137 if (err)
Florian Fainellibe7ac702012-10-08 15:11:46 +0200138 goto err_put_hcd;
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100139
140 platform_set_drvdata(dev, hcd);
141
142 return err;
143
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100144err_put_hcd:
145 usb_put_hcd(hcd);
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700146err_power:
147 if (pdata->power_off)
148 pdata->power_off(dev);
149
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100150 return err;
151}
152
Bill Pembertonfb4e98a2012-11-19 13:26:20 -0500153static int ohci_platform_remove(struct platform_device *dev)
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100154{
155 struct usb_hcd *hcd = platform_get_drvdata(dev);
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700156 struct usb_ohci_pdata *pdata = dev->dev.platform_data;
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100157
158 usb_remove_hcd(hcd);
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100159 usb_put_hcd(hcd);
160 platform_set_drvdata(dev, NULL);
161
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700162 if (pdata->power_off)
163 pdata->power_off(dev);
164
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100165 return 0;
166}
167
168#ifdef CONFIG_PM
169
170static int ohci_platform_suspend(struct device *dev)
171{
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700172 struct usb_ohci_pdata *pdata = dev->platform_data;
173 struct platform_device *pdev =
174 container_of(dev, struct platform_device, dev);
175
176 if (pdata->power_suspend)
177 pdata->power_suspend(pdev);
178
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100179 return 0;
180}
181
182static int ohci_platform_resume(struct device *dev)
183{
184 struct usb_hcd *hcd = dev_get_drvdata(dev);
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700185 struct usb_ohci_pdata *pdata = dev->platform_data;
186 struct platform_device *pdev =
187 container_of(dev, struct platform_device, dev);
188
189 if (pdata->power_on) {
190 int err = pdata->power_on(pdev);
191 if (err < 0)
192 return err;
193 }
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100194
Florian Fainellicfa49b42012-10-08 15:11:29 +0200195 ohci_resume(hcd, false);
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100196 return 0;
197}
198
199#else /* !CONFIG_PM */
200#define ohci_platform_suspend NULL
201#define ohci_platform_resume NULL
202#endif /* CONFIG_PM */
203
204static const struct platform_device_id ohci_platform_table[] = {
205 { "ohci-platform", 0 },
206 { }
207};
208MODULE_DEVICE_TABLE(platform, ohci_platform_table);
209
210static const struct dev_pm_ops ohci_platform_pm_ops = {
211 .suspend = ohci_platform_suspend,
212 .resume = ohci_platform_resume,
213};
214
215static struct platform_driver ohci_platform_driver = {
216 .id_table = ohci_platform_table,
217 .probe = ohci_platform_probe,
Bill Pemberton76904172012-11-19 13:21:08 -0500218 .remove = ohci_platform_remove,
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100219 .shutdown = usb_hcd_platform_shutdown,
220 .driver = {
221 .owner = THIS_MODULE,
222 .name = "ohci-platform",
223 .pm = &ohci_platform_pm_ops,
224 }
225};