blob: 99d17552d8094adc9932c3db184355b3a3fc4084 [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 */
16#include <linux/platform_device.h>
17#include <linux/usb/ohci_pdriver.h>
18
19static int ohci_platform_reset(struct usb_hcd *hcd)
20{
21 struct platform_device *pdev = to_platform_device(hcd->self.controller);
22 struct usb_ohci_pdata *pdata = pdev->dev.platform_data;
23 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
24 int err;
25
26 if (pdata->big_endian_desc)
27 ohci->flags |= OHCI_QUIRK_BE_DESC;
28 if (pdata->big_endian_mmio)
29 ohci->flags |= OHCI_QUIRK_BE_MMIO;
30 if (pdata->no_big_frame_no)
31 ohci->flags |= OHCI_QUIRK_FRAME_NO;
32
33 ohci_hcd_init(ohci);
Florian Fainelli2b16e392012-10-08 15:11:26 +020034
35 if (pdata->num_ports)
36 ohci->num_ports = pdata->num_ports;
37
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010038 err = ohci_init(ohci);
39
40 return err;
41}
42
43static int ohci_platform_start(struct usb_hcd *hcd)
44{
45 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
46 int err;
47
48 err = ohci_run(ohci);
49 if (err < 0) {
50 ohci_err(ohci, "can't start\n");
51 ohci_stop(hcd);
52 }
53
54 return err;
55}
56
57static const struct hc_driver ohci_platform_hc_driver = {
58 .description = hcd_name,
59 .product_desc = "Generic Platform OHCI Controller",
60 .hcd_priv_size = sizeof(struct ohci_hcd),
61
62 .irq = ohci_irq,
63 .flags = HCD_MEMORY | HCD_USB11,
64
65 .reset = ohci_platform_reset,
66 .start = ohci_platform_start,
67 .stop = ohci_stop,
68 .shutdown = ohci_shutdown,
69
70 .urb_enqueue = ohci_urb_enqueue,
71 .urb_dequeue = ohci_urb_dequeue,
72 .endpoint_disable = ohci_endpoint_disable,
73
74 .get_frame_number = ohci_get_frame,
75
76 .hub_status_data = ohci_hub_status_data,
77 .hub_control = ohci_hub_control,
78#ifdef CONFIG_PM
79 .bus_suspend = ohci_bus_suspend,
80 .bus_resume = ohci_bus_resume,
81#endif
82
83 .start_port_reset = ohci_start_port_reset,
84};
85
86static int __devinit ohci_platform_probe(struct platform_device *dev)
87{
88 struct usb_hcd *hcd;
89 struct resource *res_mem;
Kuninori Morimotob6dd2452012-08-06 18:07:30 -070090 struct usb_ohci_pdata *pdata = dev->dev.platform_data;
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010091 int irq;
92 int err = -ENOMEM;
93
Kuninori Morimotob6dd2452012-08-06 18:07:30 -070094 if (!pdata) {
95 WARN_ON(1);
96 return -ENODEV;
97 }
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010098
99 if (usb_disabled())
100 return -ENODEV;
101
102 irq = platform_get_irq(dev, 0);
103 if (irq < 0) {
Masanari Iida1c1301d2012-04-19 00:04:46 +0900104 pr_err("no irq provided");
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100105 return irq;
106 }
107
108 res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
109 if (!res_mem) {
Masanari Iida1c1301d2012-04-19 00:04:46 +0900110 pr_err("no memory recourse provided");
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100111 return -ENXIO;
112 }
113
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700114 if (pdata->power_on) {
115 err = pdata->power_on(dev);
116 if (err < 0)
117 return err;
118 }
119
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100120 hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
121 dev_name(&dev->dev));
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700122 if (!hcd) {
123 err = -ENOMEM;
124 goto err_power;
125 }
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100126
127 hcd->rsrc_start = res_mem->start;
128 hcd->rsrc_len = resource_size(res_mem);
129
130 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
131 pr_err("controller already in use");
132 err = -EBUSY;
133 goto err_put_hcd;
134 }
135
136 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
Julia Lawallaece3892012-08-14 08:47:37 +0200137 if (!hcd->regs) {
138 err = -ENOMEM;
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100139 goto err_release_region;
Julia Lawallaece3892012-08-14 08:47:37 +0200140 }
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100141 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
142 if (err)
143 goto err_iounmap;
144
145 platform_set_drvdata(dev, hcd);
146
147 return err;
148
149err_iounmap:
150 iounmap(hcd->regs);
151err_release_region:
152 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
153err_put_hcd:
154 usb_put_hcd(hcd);
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700155err_power:
156 if (pdata->power_off)
157 pdata->power_off(dev);
158
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100159 return err;
160}
161
162static int __devexit ohci_platform_remove(struct platform_device *dev)
163{
164 struct usb_hcd *hcd = platform_get_drvdata(dev);
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700165 struct usb_ohci_pdata *pdata = dev->dev.platform_data;
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100166
167 usb_remove_hcd(hcd);
168 iounmap(hcd->regs);
169 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
170 usb_put_hcd(hcd);
171 platform_set_drvdata(dev, NULL);
172
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700173 if (pdata->power_off)
174 pdata->power_off(dev);
175
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100176 return 0;
177}
178
179#ifdef CONFIG_PM
180
181static int ohci_platform_suspend(struct device *dev)
182{
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700183 struct usb_ohci_pdata *pdata = dev->platform_data;
184 struct platform_device *pdev =
185 container_of(dev, struct platform_device, dev);
186
187 if (pdata->power_suspend)
188 pdata->power_suspend(pdev);
189
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100190 return 0;
191}
192
193static int ohci_platform_resume(struct device *dev)
194{
195 struct usb_hcd *hcd = dev_get_drvdata(dev);
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700196 struct usb_ohci_pdata *pdata = dev->platform_data;
197 struct platform_device *pdev =
198 container_of(dev, struct platform_device, dev);
199
200 if (pdata->power_on) {
201 int err = pdata->power_on(pdev);
202 if (err < 0)
203 return err;
204 }
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100205
Florian Fainellicfa49b42012-10-08 15:11:29 +0200206 ohci_resume(hcd, false);
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100207 return 0;
208}
209
210#else /* !CONFIG_PM */
211#define ohci_platform_suspend NULL
212#define ohci_platform_resume NULL
213#endif /* CONFIG_PM */
214
215static const struct platform_device_id ohci_platform_table[] = {
216 { "ohci-platform", 0 },
217 { }
218};
219MODULE_DEVICE_TABLE(platform, ohci_platform_table);
220
221static const struct dev_pm_ops ohci_platform_pm_ops = {
222 .suspend = ohci_platform_suspend,
223 .resume = ohci_platform_resume,
224};
225
226static struct platform_driver ohci_platform_driver = {
227 .id_table = ohci_platform_table,
228 .probe = ohci_platform_probe,
229 .remove = __devexit_p(ohci_platform_remove),
230 .shutdown = usb_hcd_platform_shutdown,
231 .driver = {
232 .owner = THIS_MODULE,
233 .name = "ohci-platform",
234 .pm = &ohci_platform_pm_ops,
235 }
236};