Commit | Line | Data |
---|---|---|
fa3364b5 HM |
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 | * | |
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 | ||
19 | static 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); | |
2b16e39e FF |
34 | |
35 | if (pdata->num_ports) | |
36 | ohci->num_ports = pdata->num_ports; | |
37 | ||
fa3364b5 HM |
38 | err = ohci_init(ohci); |
39 | ||
40 | return err; | |
41 | } | |
42 | ||
43 | static 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 | ||
57 | static 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 | ||
86 | static int __devinit ohci_platform_probe(struct platform_device *dev) | |
87 | { | |
88 | struct usb_hcd *hcd; | |
89 | struct resource *res_mem; | |
b6dd245c | 90 | struct usb_ohci_pdata *pdata = dev->dev.platform_data; |
fa3364b5 HM |
91 | int irq; |
92 | int err = -ENOMEM; | |
93 | ||
b6dd245c KM |
94 | if (!pdata) { |
95 | WARN_ON(1); | |
96 | return -ENODEV; | |
97 | } | |
fa3364b5 HM |
98 | |
99 | if (usb_disabled()) | |
100 | return -ENODEV; | |
101 | ||
102 | irq = platform_get_irq(dev, 0); | |
103 | if (irq < 0) { | |
976baf6e | 104 | dev_err(&dev->dev, "no irq provided"); |
fa3364b5 HM |
105 | return irq; |
106 | } | |
107 | ||
108 | res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); | |
109 | if (!res_mem) { | |
976baf6e | 110 | dev_err(&dev->dev, "no memory recourse provided"); |
fa3364b5 HM |
111 | return -ENXIO; |
112 | } | |
113 | ||
e4d37aeb KM |
114 | if (pdata->power_on) { |
115 | err = pdata->power_on(dev); | |
116 | if (err < 0) | |
117 | return err; | |
118 | } | |
119 | ||
fa3364b5 HM |
120 | hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev, |
121 | dev_name(&dev->dev)); | |
e4d37aeb KM |
122 | if (!hcd) { |
123 | err = -ENOMEM; | |
124 | goto err_power; | |
125 | } | |
fa3364b5 HM |
126 | |
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)) { | |
976baf6e | 131 | dev_err(&dev->dev, "controller already in use"); |
fa3364b5 HM |
132 | err = -EBUSY; |
133 | goto err_put_hcd; | |
134 | } | |
135 | ||
136 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); | |
aece389e JL |
137 | if (!hcd->regs) { |
138 | err = -ENOMEM; | |
fa3364b5 | 139 | goto err_release_region; |
aece389e | 140 | } |
fa3364b5 HM |
141 | 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 | ||
149 | err_iounmap: | |
150 | iounmap(hcd->regs); | |
151 | err_release_region: | |
152 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | |
153 | err_put_hcd: | |
154 | usb_put_hcd(hcd); | |
e4d37aeb KM |
155 | err_power: |
156 | if (pdata->power_off) | |
157 | pdata->power_off(dev); | |
158 | ||
fa3364b5 HM |
159 | return err; |
160 | } | |
161 | ||
162 | static int __devexit ohci_platform_remove(struct platform_device *dev) | |
163 | { | |
164 | struct usb_hcd *hcd = platform_get_drvdata(dev); | |
e4d37aeb | 165 | struct usb_ohci_pdata *pdata = dev->dev.platform_data; |
fa3364b5 HM |
166 | |
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 | ||
e4d37aeb KM |
173 | if (pdata->power_off) |
174 | pdata->power_off(dev); | |
175 | ||
fa3364b5 HM |
176 | return 0; |
177 | } | |
178 | ||
179 | #ifdef CONFIG_PM | |
180 | ||
181 | static int ohci_platform_suspend(struct device *dev) | |
182 | { | |
e4d37aeb KM |
183 | 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 | ||
fa3364b5 HM |
190 | return 0; |
191 | } | |
192 | ||
193 | static int ohci_platform_resume(struct device *dev) | |
194 | { | |
195 | struct usb_hcd *hcd = dev_get_drvdata(dev); | |
e4d37aeb KM |
196 | 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 | } | |
fa3364b5 | 205 | |
cfa49b4b | 206 | ohci_resume(hcd, false); |
fa3364b5 HM |
207 | 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 | ||
215 | static const struct platform_device_id ohci_platform_table[] = { | |
216 | { "ohci-platform", 0 }, | |
217 | { } | |
218 | }; | |
219 | MODULE_DEVICE_TABLE(platform, ohci_platform_table); | |
220 | ||
221 | static const struct dev_pm_ops ohci_platform_pm_ops = { | |
222 | .suspend = ohci_platform_suspend, | |
223 | .resume = ohci_platform_resume, | |
224 | }; | |
225 | ||
226 | static 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 | }; |