blob: dc33517982a45a71a2b27fc3a46088a25b7a55e1 [file] [log] [blame]
Andrew Victor39a269c2006-01-22 10:32:13 -08001/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * Copyright (C) 2004 SAN People (Pty) Ltd.
5 * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
6 *
David Brownell0365ee02006-06-19 14:27:20 -07007 * AT91 Bus Glue
Andrew Victor39a269c2006-01-22 10:32:13 -08008 *
9 * Based on fragments of 2.4 driver by Rick Bronson.
10 * Based on ohci-omap.c
11 *
12 * This file is licenced under the GPL.
13 */
14
15#include <linux/clk.h>
16#include <linux/platform_device.h>
17
Russell Kinga09e64f2008-08-05 16:14:15 +010018#include <mach/hardware.h>
David Brownell4bde4a42007-12-27 11:19:49 -080019#include <asm/gpio.h>
20
Russell Kinga09e64f2008-08-05 16:14:15 +010021#include <mach/board.h>
22#include <mach/cpu.h>
Andrew Victor39a269c2006-01-22 10:32:13 -080023
David Brownell0365ee02006-06-19 14:27:20 -070024#ifndef CONFIG_ARCH_AT91
25#error "CONFIG_ARCH_AT91 must be defined."
Andrew Victor39a269c2006-01-22 10:32:13 -080026#endif
27
Andrew Victored077bb2007-02-16 10:18:58 -080028/* interface and function clocks; sometimes also an AHB clock */
29static struct clk *iclk, *fclk, *hclk;
David Brownell0365ee02006-06-19 14:27:20 -070030static int clocked;
Andrew Victor39a269c2006-01-22 10:32:13 -080031
32extern int usb_disabled(void);
33
34/*-------------------------------------------------------------------------*/
35
Andrew Victored077bb2007-02-16 10:18:58 -080036static void at91_start_clock(void)
37{
Jean-Christophe PLAGNIOL-VILLARD0af43162011-08-30 03:29:28 +020038 clk_enable(hclk);
Andrew Victored077bb2007-02-16 10:18:58 -080039 clk_enable(iclk);
40 clk_enable(fclk);
41 clocked = 1;
42}
43
44static void at91_stop_clock(void)
45{
46 clk_disable(fclk);
47 clk_disable(iclk);
Jean-Christophe PLAGNIOL-VILLARD0af43162011-08-30 03:29:28 +020048 clk_disable(hclk);
Andrew Victored077bb2007-02-16 10:18:58 -080049 clocked = 0;
50}
51
Andrew Victor39a269c2006-01-22 10:32:13 -080052static void at91_start_hc(struct platform_device *pdev)
53{
54 struct usb_hcd *hcd = platform_get_drvdata(pdev);
55 struct ohci_regs __iomem *regs = hcd->regs;
56
David Brownell0365ee02006-06-19 14:27:20 -070057 dev_dbg(&pdev->dev, "start\n");
Andrew Victor39a269c2006-01-22 10:32:13 -080058
59 /*
60 * Start the USB clocks.
61 */
Andrew Victored077bb2007-02-16 10:18:58 -080062 at91_start_clock();
Andrew Victor39a269c2006-01-22 10:32:13 -080063
64 /*
65 * The USB host controller must remain in reset.
66 */
67 writel(0, &regs->control);
68}
69
70static void at91_stop_hc(struct platform_device *pdev)
71{
72 struct usb_hcd *hcd = platform_get_drvdata(pdev);
73 struct ohci_regs __iomem *regs = hcd->regs;
74
David Brownell0365ee02006-06-19 14:27:20 -070075 dev_dbg(&pdev->dev, "stop\n");
Andrew Victor39a269c2006-01-22 10:32:13 -080076
77 /*
78 * Put the USB host controller into reset.
79 */
80 writel(0, &regs->control);
81
82 /*
83 * Stop the USB clocks.
84 */
Andrew Victored077bb2007-02-16 10:18:58 -080085 at91_stop_clock();
Andrew Victor39a269c2006-01-22 10:32:13 -080086}
87
88
89/*-------------------------------------------------------------------------*/
90
Pete Zaitcev421b4bf2008-06-01 14:38:43 -070091static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
Andrew Victor39a269c2006-01-22 10:32:13 -080092
93/* configure so an HC device and id are always provided */
94/* always called with process context; sleeping is OK */
95
96
97/**
David Brownell0365ee02006-06-19 14:27:20 -070098 * usb_hcd_at91_probe - initialize AT91-based HCDs
Andrew Victor39a269c2006-01-22 10:32:13 -080099 * Context: !in_interrupt()
100 *
101 * Allocates basic resources for this USB host controller, and
102 * then invokes the start() method for the HCD associated with it
103 * through the hotplug entry's driver_data.
Andrew Victor39a269c2006-01-22 10:32:13 -0800104 */
David Brownell0365ee02006-06-19 14:27:20 -0700105static int usb_hcd_at91_probe(const struct hc_driver *driver,
106 struct platform_device *pdev)
Andrew Victor39a269c2006-01-22 10:32:13 -0800107{
108 int retval;
109 struct usb_hcd *hcd = NULL;
110
111 if (pdev->num_resources != 2) {
112 pr_debug("hcd probe: invalid num_resources");
113 return -ENODEV;
114 }
115
David Brownell0365ee02006-06-19 14:27:20 -0700116 if ((pdev->resource[0].flags != IORESOURCE_MEM)
117 || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
Andrew Victor39a269c2006-01-22 10:32:13 -0800118 pr_debug("hcd probe: invalid resource type\n");
119 return -ENODEV;
120 }
121
David Brownell0365ee02006-06-19 14:27:20 -0700122 hcd = usb_create_hcd(driver, &pdev->dev, "at91");
Andrew Victor39a269c2006-01-22 10:32:13 -0800123 if (!hcd)
124 return -ENOMEM;
125 hcd->rsrc_start = pdev->resource[0].start;
126 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
127
128 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
129 pr_debug("request_mem_region failed\n");
130 retval = -EBUSY;
131 goto err1;
132 }
133
134 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
135 if (!hcd->regs) {
136 pr_debug("ioremap failed\n");
137 retval = -EIO;
138 goto err2;
139 }
140
141 iclk = clk_get(&pdev->dev, "ohci_clk");
Jean-Christophe PLAGNIOL-VILLARD68134632011-12-08 16:32:00 +0100142 if (IS_ERR(iclk)) {
143 dev_err(&pdev->dev, "failed to get ohci_clk\n");
144 retval = PTR_ERR(iclk);
145 goto err3;
146 }
Andrew Victor39a269c2006-01-22 10:32:13 -0800147 fclk = clk_get(&pdev->dev, "uhpck");
Jean-Christophe PLAGNIOL-VILLARD68134632011-12-08 16:32:00 +0100148 if (IS_ERR(fclk)) {
149 dev_err(&pdev->dev, "failed to get uhpck\n");
150 retval = PTR_ERR(fclk);
151 goto err4;
152 }
Jean-Christophe PLAGNIOL-VILLARD0af43162011-08-30 03:29:28 +0200153 hclk = clk_get(&pdev->dev, "hclk");
Jean-Christophe PLAGNIOL-VILLARD68134632011-12-08 16:32:00 +0100154 if (IS_ERR(hclk)) {
155 dev_err(&pdev->dev, "failed to get hclk\n");
156 retval = PTR_ERR(hclk);
157 goto err5;
158 }
Andrew Victor39a269c2006-01-22 10:32:13 -0800159
160 at91_start_hc(pdev);
161 ohci_hcd_init(hcd_to_ohci(hcd));
162
Nicolas Ferre2f2cac32009-07-27 14:59:24 -0700163 retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
Andrew Victor39a269c2006-01-22 10:32:13 -0800164 if (retval == 0)
165 return retval;
166
167 /* Error handling */
168 at91_stop_hc(pdev);
169
Jean-Christophe PLAGNIOL-VILLARD0af43162011-08-30 03:29:28 +0200170 clk_put(hclk);
Jean-Christophe PLAGNIOL-VILLARD68134632011-12-08 16:32:00 +0100171 err5:
Andrew Victor39a269c2006-01-22 10:32:13 -0800172 clk_put(fclk);
Jean-Christophe PLAGNIOL-VILLARD68134632011-12-08 16:32:00 +0100173 err4:
Andrew Victor39a269c2006-01-22 10:32:13 -0800174 clk_put(iclk);
175
Jean-Christophe PLAGNIOL-VILLARD68134632011-12-08 16:32:00 +0100176 err3:
Andrew Victor39a269c2006-01-22 10:32:13 -0800177 iounmap(hcd->regs);
178
179 err2:
180 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
181
182 err1:
183 usb_put_hcd(hcd);
184 return retval;
185}
186
187
Andrew Victor39a269c2006-01-22 10:32:13 -0800188/* may be called with controller, bus, and devices active */
189
190/**
David Brownell0365ee02006-06-19 14:27:20 -0700191 * usb_hcd_at91_remove - shutdown processing for AT91-based HCDs
Andrew Victor39a269c2006-01-22 10:32:13 -0800192 * @dev: USB Host Controller being removed
193 * Context: !in_interrupt()
194 *
195 * Reverses the effect of usb_hcd_at91_probe(), first invoking
196 * the HCD's stop() method. It is always called from a thread
David Brownell0365ee02006-06-19 14:27:20 -0700197 * context, "rmmod" or something similar.
Andrew Victor39a269c2006-01-22 10:32:13 -0800198 *
199 */
Pete Zaitcev421b4bf2008-06-01 14:38:43 -0700200static void usb_hcd_at91_remove(struct usb_hcd *hcd,
David Brownell0365ee02006-06-19 14:27:20 -0700201 struct platform_device *pdev)
Andrew Victor39a269c2006-01-22 10:32:13 -0800202{
203 usb_remove_hcd(hcd);
204 at91_stop_hc(pdev);
205 iounmap(hcd->regs);
David Brownell68ba61b2006-04-02 20:26:21 -0800206 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
Pete Zaitcev421b4bf2008-06-01 14:38:43 -0700207 usb_put_hcd(hcd);
Andrew Victor39a269c2006-01-22 10:32:13 -0800208
Jean-Christophe PLAGNIOL-VILLARD0af43162011-08-30 03:29:28 +0200209 clk_put(hclk);
David Brownell68ba61b2006-04-02 20:26:21 -0800210 clk_put(fclk);
211 clk_put(iclk);
Andrew Victored077bb2007-02-16 10:18:58 -0800212 fclk = iclk = hclk = NULL;
Andrew Victor39a269c2006-01-22 10:32:13 -0800213
214 dev_set_drvdata(&pdev->dev, NULL);
Andrew Victor39a269c2006-01-22 10:32:13 -0800215}
216
217/*-------------------------------------------------------------------------*/
218
219static int __devinit
220ohci_at91_start (struct usb_hcd *hcd)
221{
David Brownell0365ee02006-06-19 14:27:20 -0700222 struct at91_usbh_data *board = hcd->self.controller->platform_data;
Andrew Victor39a269c2006-01-22 10:32:13 -0800223 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
224 int ret;
225
226 if ((ret = ohci_init(ohci)) < 0)
227 return ret;
228
David Brownellcd22afd2006-09-03 12:21:50 -0700229 ohci->num_ports = board->ports;
David Brownell0365ee02006-06-19 14:27:20 -0700230
Andrew Victor39a269c2006-01-22 10:32:13 -0800231 if ((ret = ohci_run(ohci)) < 0) {
232 err("can't start %s", hcd->self.bus_name);
233 ohci_stop(hcd);
234 return ret;
235 }
Andrew Victor39a269c2006-01-22 10:32:13 -0800236 return 0;
237}
238
Thomas Petazzoniaa6e52a2011-07-13 11:29:17 +0200239static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable)
240{
241 if (port < 0 || port >= 2)
242 return;
243
Jean-Christophe PLAGNIOL-VILLARD8a7a49d2011-09-19 15:32:23 +0800244 if (!gpio_is_valid(pdata->vbus_pin[port]))
Jean-Christophe PLAGNIOL-VILLARD770f0ba2011-11-12 16:46:13 +0100245 return;
246
Thomas Petazzoniaa6e52a2011-07-13 11:29:17 +0200247 gpio_set_value(pdata->vbus_pin[port], !pdata->vbus_pin_inverted ^ enable);
248}
249
250static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
251{
252 if (port < 0 || port >= 2)
253 return -EINVAL;
254
Jean-Christophe PLAGNIOL-VILLARD8a7a49d2011-09-19 15:32:23 +0800255 if (!gpio_is_valid(pdata->vbus_pin[port]))
Jean-Christophe PLAGNIOL-VILLARD770f0ba2011-11-12 16:46:13 +0100256 return -EINVAL;
257
Thomas Petazzoniaa6e52a2011-07-13 11:29:17 +0200258 return gpio_get_value(pdata->vbus_pin[port]) ^ !pdata->vbus_pin_inverted;
259}
260
261/*
262 * Update the status data from the hub with the over-current indicator change.
263 */
264static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf)
265{
266 struct at91_usbh_data *pdata = hcd->self.controller->platform_data;
267 int length = ohci_hub_status_data(hcd, buf);
268 int port;
269
270 for (port = 0; port < ARRAY_SIZE(pdata->overcurrent_pin); port++) {
271 if (pdata->overcurrent_changed[port]) {
272 if (! length)
273 length = 1;
274 buf[0] |= 1 << (port + 1);
275 }
276 }
277
278 return length;
279}
280
281/*
282 * Look at the control requests to the root hub and see if we need to override.
283 */
284static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
285 u16 wIndex, char *buf, u16 wLength)
286{
287 struct at91_usbh_data *pdata = hcd->self.controller->platform_data;
288 struct usb_hub_descriptor *desc;
289 int ret = -EINVAL;
290 u32 *data = (u32 *)buf;
291
292 dev_dbg(hcd->self.controller,
293 "ohci_at91_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n",
294 hcd, typeReq, wValue, wIndex, buf, wLength);
295
296 switch (typeReq) {
297 case SetPortFeature:
298 if (wValue == USB_PORT_FEAT_POWER) {
299 dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
300 ohci_at91_usb_set_power(pdata, wIndex - 1, 1);
301 goto out;
302 }
303 break;
304
305 case ClearPortFeature:
306 switch (wValue) {
307 case USB_PORT_FEAT_C_OVER_CURRENT:
308 dev_dbg(hcd->self.controller,
309 "ClearPortFeature: C_OVER_CURRENT\n");
310
311 if (wIndex == 1 || wIndex == 2) {
312 pdata->overcurrent_changed[wIndex-1] = 0;
313 pdata->overcurrent_status[wIndex-1] = 0;
314 }
315
316 goto out;
317
318 case USB_PORT_FEAT_OVER_CURRENT:
319 dev_dbg(hcd->self.controller,
320 "ClearPortFeature: OVER_CURRENT\n");
321
322 if (wIndex == 1 || wIndex == 2) {
323 pdata->overcurrent_status[wIndex-1] = 0;
324 }
325
326 goto out;
327
328 case USB_PORT_FEAT_POWER:
329 dev_dbg(hcd->self.controller,
330 "ClearPortFeature: POWER\n");
331
332 if (wIndex == 1 || wIndex == 2) {
333 ohci_at91_usb_set_power(pdata, wIndex - 1, 0);
334 return 0;
335 }
336 }
337 break;
338 }
339
340 ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
341 if (ret)
342 goto out;
343
344 switch (typeReq) {
345 case GetHubDescriptor:
346
347 /* update the hub's descriptor */
348
349 desc = (struct usb_hub_descriptor *)buf;
350
351 dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n",
352 desc->wHubCharacteristics);
353
354 /* remove the old configurations for power-switching, and
355 * over-current protection, and insert our new configuration
356 */
357
358 desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM);
359 desc->wHubCharacteristics |= cpu_to_le16(0x0001);
360
361 if (pdata->overcurrent_supported) {
362 desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_OCPM);
363 desc->wHubCharacteristics |= cpu_to_le16(0x0008|0x0001);
364 }
365
366 dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n",
367 desc->wHubCharacteristics);
368
369 return ret;
370
371 case GetPortStatus:
372 /* check port status */
373
374 dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex);
375
376 if (wIndex == 1 || wIndex == 2) {
377 if (! ohci_at91_usb_get_power(pdata, wIndex-1)) {
378 *data &= ~cpu_to_le32(RH_PS_PPS);
379 }
380
381 if (pdata->overcurrent_changed[wIndex-1]) {
382 *data |= cpu_to_le32(RH_PS_OCIC);
383 }
384
385 if (pdata->overcurrent_status[wIndex-1]) {
386 *data |= cpu_to_le32(RH_PS_POCI);
387 }
388 }
389 }
390
391 out:
392 return ret;
393}
394
Andrew Victor39a269c2006-01-22 10:32:13 -0800395/*-------------------------------------------------------------------------*/
396
397static const struct hc_driver ohci_at91_hc_driver = {
398 .description = hcd_name,
David Brownell0365ee02006-06-19 14:27:20 -0700399 .product_desc = "AT91 OHCI",
Andrew Victor39a269c2006-01-22 10:32:13 -0800400 .hcd_priv_size = sizeof(struct ohci_hcd),
401
402 /*
403 * generic hardware linkage
404 */
405 .irq = ohci_irq,
406 .flags = HCD_USB11 | HCD_MEMORY,
407
408 /*
409 * basic lifecycle operations
410 */
411 .start = ohci_at91_start,
412 .stop = ohci_stop,
David Brownelldd9048a2006-12-05 03:18:31 -0800413 .shutdown = ohci_shutdown,
Andrew Victor39a269c2006-01-22 10:32:13 -0800414
415 /*
416 * managing i/o requests and associated device resources
417 */
418 .urb_enqueue = ohci_urb_enqueue,
419 .urb_dequeue = ohci_urb_dequeue,
420 .endpoint_disable = ohci_endpoint_disable,
421
422 /*
423 * scheduling support
424 */
425 .get_frame_number = ohci_get_frame,
426
427 /*
428 * root hub support
429 */
Thomas Petazzoniaa6e52a2011-07-13 11:29:17 +0200430 .hub_status_data = ohci_at91_hub_status_data,
431 .hub_control = ohci_at91_hub_control,
Andrew Victor39a269c2006-01-22 10:32:13 -0800432#ifdef CONFIG_PM
David Brownell68ba61b2006-04-02 20:26:21 -0800433 .bus_suspend = ohci_bus_suspend,
434 .bus_resume = ohci_bus_resume,
Andrew Victor39a269c2006-01-22 10:32:13 -0800435#endif
436 .start_port_reset = ohci_start_port_reset,
437};
438
439/*-------------------------------------------------------------------------*/
440
Thomas Petazzoniaa6e52a2011-07-13 11:29:17 +0200441static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
442{
443 struct platform_device *pdev = data;
444 struct at91_usbh_data *pdata = pdev->dev.platform_data;
445 int val, gpio, port;
446
447 /* From the GPIO notifying the over-current situation, find
448 * out the corresponding port */
449 gpio = irq_to_gpio(irq);
450 for (port = 0; port < ARRAY_SIZE(pdata->overcurrent_pin); port++) {
451 if (pdata->overcurrent_pin[port] == gpio)
452 break;
453 }
454
455 if (port == ARRAY_SIZE(pdata->overcurrent_pin)) {
456 dev_err(& pdev->dev, "overcurrent interrupt from unknown GPIO\n");
457 return IRQ_HANDLED;
458 }
459
460 val = gpio_get_value(gpio);
461
462 /* When notified of an over-current situation, disable power
463 on the corresponding port, and mark this port in
464 over-current. */
465 if (! val) {
466 ohci_at91_usb_set_power(pdata, port, 0);
467 pdata->overcurrent_status[port] = 1;
468 pdata->overcurrent_changed[port] = 1;
469 }
470
471 dev_dbg(& pdev->dev, "overcurrent situation %s\n",
472 val ? "exited" : "notified");
473
474 return IRQ_HANDLED;
475}
476
477/*-------------------------------------------------------------------------*/
478
David Brownell0365ee02006-06-19 14:27:20 -0700479static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
Andrew Victor39a269c2006-01-22 10:32:13 -0800480{
David Brownell4bde4a42007-12-27 11:19:49 -0800481 struct at91_usbh_data *pdata = pdev->dev.platform_data;
482 int i;
483
484 if (pdata) {
Justin Waters3d6fdf72009-04-03 21:06:53 +0100485 for (i = 0; i < ARRAY_SIZE(pdata->vbus_pin); i++) {
Jean-Christophe PLAGNIOL-VILLARD8a7a49d2011-09-19 15:32:23 +0800486 if (!gpio_is_valid(pdata->vbus_pin[i]))
David Brownell4bde4a42007-12-27 11:19:49 -0800487 continue;
488 gpio_request(pdata->vbus_pin[i], "ohci_vbus");
Thomas Petazzoniaa6e52a2011-07-13 11:29:17 +0200489 ohci_at91_usb_set_power(pdata, i, 1);
490 }
491
492 for (i = 0; i < ARRAY_SIZE(pdata->overcurrent_pin); i++) {
493 int ret;
494
Jean-Christophe PLAGNIOL-VILLARD8a7a49d2011-09-19 15:32:23 +0800495 if (!gpio_is_valid(pdata->overcurrent_pin[i]))
Thomas Petazzoniaa6e52a2011-07-13 11:29:17 +0200496 continue;
497 gpio_request(pdata->overcurrent_pin[i], "ohci_overcurrent");
498
499 ret = request_irq(gpio_to_irq(pdata->overcurrent_pin[i]),
500 ohci_hcd_at91_overcurrent_irq,
501 IRQF_SHARED, "ohci_overcurrent", pdev);
502 if (ret) {
503 gpio_free(pdata->overcurrent_pin[i]);
504 dev_warn(& pdev->dev, "cannot get GPIO IRQ for overcurrent\n");
505 }
David Brownell4bde4a42007-12-27 11:19:49 -0800506 }
507 }
508
David Brownell0365ee02006-06-19 14:27:20 -0700509 device_init_wakeup(&pdev->dev, 1);
510 return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
Andrew Victor39a269c2006-01-22 10:32:13 -0800511}
512
David Brownell0365ee02006-06-19 14:27:20 -0700513static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
Andrew Victor39a269c2006-01-22 10:32:13 -0800514{
David Brownell4bde4a42007-12-27 11:19:49 -0800515 struct at91_usbh_data *pdata = pdev->dev.platform_data;
516 int i;
517
518 if (pdata) {
Justin Waters3d6fdf72009-04-03 21:06:53 +0100519 for (i = 0; i < ARRAY_SIZE(pdata->vbus_pin); i++) {
Jean-Christophe PLAGNIOL-VILLARD8a7a49d2011-09-19 15:32:23 +0800520 if (!gpio_is_valid(pdata->vbus_pin[i]))
David Brownell4bde4a42007-12-27 11:19:49 -0800521 continue;
Thomas Petazzoniaa6e52a2011-07-13 11:29:17 +0200522 ohci_at91_usb_set_power(pdata, i, 0);
David Brownell4bde4a42007-12-27 11:19:49 -0800523 gpio_free(pdata->vbus_pin[i]);
524 }
Thomas Petazzoniaa6e52a2011-07-13 11:29:17 +0200525
526 for (i = 0; i < ARRAY_SIZE(pdata->overcurrent_pin); i++) {
Jean-Christophe PLAGNIOL-VILLARD8a7a49d2011-09-19 15:32:23 +0800527 if (!gpio_is_valid(pdata->overcurrent_pin[i]))
Thomas Petazzoniaa6e52a2011-07-13 11:29:17 +0200528 continue;
529 free_irq(gpio_to_irq(pdata->overcurrent_pin[i]), pdev);
530 gpio_free(pdata->overcurrent_pin[i]);
531 }
David Brownell4bde4a42007-12-27 11:19:49 -0800532 }
533
David Brownell0365ee02006-06-19 14:27:20 -0700534 device_init_wakeup(&pdev->dev, 0);
Pete Zaitcev421b4bf2008-06-01 14:38:43 -0700535 usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev);
536 return 0;
Andrew Victor39a269c2006-01-22 10:32:13 -0800537}
538
539#ifdef CONFIG_PM
Andrew Victor39a269c2006-01-22 10:32:13 -0800540
David Brownell68ba61b2006-04-02 20:26:21 -0800541static int
David Brownell0365ee02006-06-19 14:27:20 -0700542ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg)
David Brownell68ba61b2006-04-02 20:26:21 -0800543{
David Brownell0365ee02006-06-19 14:27:20 -0700544 struct usb_hcd *hcd = platform_get_drvdata(pdev);
545 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
546
547 if (device_may_wakeup(&pdev->dev))
548 enable_irq_wake(hcd->irq);
David Brownell0365ee02006-06-19 14:27:20 -0700549
550 /*
551 * The integrated transceivers seem unable to notice disconnect,
552 * reconnect, or wakeup without the 48 MHz clock active. so for
553 * correctness, always discard connection state (using reset).
554 *
555 * REVISIT: some boards will be able to turn VBUS off...
556 */
557 if (at91_suspend_entering_slow_clock()) {
558 ohci_usb_reset (ohci);
Patrice Vilchez869aa982010-04-28 13:45:40 +0200559 /* flush the writes */
560 (void) ohci_readl (ohci, &ohci->regs->control);
Andrew Victored077bb2007-02-16 10:18:58 -0800561 at91_stop_clock();
David Brownell0365ee02006-06-19 14:27:20 -0700562 }
Andrew Victor39a269c2006-01-22 10:32:13 -0800563
564 return 0;
565}
566
David Brownell0365ee02006-06-19 14:27:20 -0700567static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
Andrew Victor39a269c2006-01-22 10:32:13 -0800568{
Marc Pignat6dde8962007-01-09 14:00:11 -0800569 struct usb_hcd *hcd = platform_get_drvdata(pdev);
570
571 if (device_may_wakeup(&pdev->dev))
572 disable_irq_wake(hcd->irq);
573
Andrew Victored077bb2007-02-16 10:18:58 -0800574 if (!clocked)
575 at91_start_clock();
Andrew Victor39a269c2006-01-22 10:32:13 -0800576
Alan Stern43bbb7e2008-04-03 18:03:17 -0400577 ohci_finish_controller_resume(hcd);
Andrew Victor39a269c2006-01-22 10:32:13 -0800578 return 0;
579}
580#else
581#define ohci_hcd_at91_drv_suspend NULL
582#define ohci_hcd_at91_drv_resume NULL
583#endif
584
Kay Sieversf4fce612008-04-10 21:29:22 -0700585MODULE_ALIAS("platform:at91_ohci");
David Brownell68ba61b2006-04-02 20:26:21 -0800586
Andrew Victor39a269c2006-01-22 10:32:13 -0800587static struct platform_driver ohci_hcd_at91_driver = {
588 .probe = ohci_hcd_at91_drv_probe,
589 .remove = ohci_hcd_at91_drv_remove,
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700590 .shutdown = usb_hcd_platform_shutdown,
Andrew Victor39a269c2006-01-22 10:32:13 -0800591 .suspend = ohci_hcd_at91_drv_suspend,
592 .resume = ohci_hcd_at91_drv_resume,
593 .driver = {
David Brownell0365ee02006-06-19 14:27:20 -0700594 .name = "at91_ohci",
Andrew Victor39a269c2006-01-22 10:32:13 -0800595 .owner = THIS_MODULE,
596 },
597};