20 #include <mach/hardware.h>
23 #include <mach/board.h>
26 #ifndef CONFIG_ARCH_AT91
27 #error "CONFIG_ARCH_AT91 must be defined."
30 #define valid_port(index) ((index) >= 0 && (index) < AT91_MAX_USBH_PORTS)
31 #define at91_for_each_port(index) \
32 for ((index) = 0; (index) < AT91_MAX_USBH_PORTS; (index)++)
42 static void at91_start_clock(
void)
50 static void at91_stop_clock(
void)
60 struct usb_hcd *hcd = platform_get_drvdata(pdev);
78 struct usb_hcd *hcd = platform_get_drvdata(pdev);
111 static int __devinit usb_hcd_at91_probe(
const struct hc_driver *
driver,
115 struct usb_hcd *hcd =
NULL;
118 pr_debug(
"hcd probe: invalid num_resources");
124 pr_debug(
"hcd probe: invalid resource type\n");
131 hcd->rsrc_start = pdev->
resource[0].start;
132 hcd->rsrc_len = resource_size(&pdev->
resource[0]);
135 pr_debug(
"request_mem_region failed\n");
140 hcd->regs =
ioremap(hcd->rsrc_start, hcd->rsrc_len);
149 dev_err(&pdev->
dev,
"failed to get ohci_clk\n");
150 retval = PTR_ERR(iclk);
156 retval = PTR_ERR(fclk);
162 retval = PTR_ERR(hclk);
167 ohci_hcd_init(hcd_to_ohci(hcd));
206 static void __devexit usb_hcd_at91_remove(
struct usb_hcd *hcd,
218 fclk = iclk = hclk =
NULL;
226 ohci_at91_reset (
struct usb_hcd *hcd)
232 if ((ret = ohci_init(ohci)) < 0)
240 ohci_at91_start (
struct usb_hcd *hcd)
242 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
245 if ((ret = ohci_run(ohci)) < 0) {
246 dev_err(hcd->self.controller,
"can't start %s\n",
259 if (!gpio_is_valid(pdata->
vbus_pin[port]))
266 static int ohci_at91_usb_get_power(
struct at91_usbh_data *pdata,
int port)
271 if (!gpio_is_valid(pdata->
vbus_pin[port]))
281 static int ohci_at91_hub_status_data(
struct usb_hcd *hcd,
char *
buf)
283 struct at91_usbh_data *pdata = hcd->self.controller->platform_data;
284 int length = ohci_hub_status_data(hcd, buf);
291 buf[0] |= 1 << (port + 1);
301 static int ohci_at91_hub_control(
struct usb_hcd *hcd,
u16 typeReq,
u16 wValue,
304 struct at91_usbh_data *pdata = hcd->self.controller->platform_data;
310 "ohci_at91_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n",
311 hcd, typeReq, wValue, wIndex, buf, wLength);
318 dev_dbg(hcd->self.controller,
"SetPortFeat: POWER\n");
320 ohci_at91_usb_set_power(pdata, wIndex, 1);
328 case ClearPortFeature:
332 "ClearPortFeature: C_OVER_CURRENT\n");
343 "ClearPortFeature: OVER_CURRENT\n");
352 "ClearPortFeature: POWER\n");
355 ohci_at91_usb_set_power(pdata, wIndex, 0);
362 ret = ohci_hub_control(hcd, typeReq, wValue, wIndex + 1, buf, wLength);
367 case GetHubDescriptor:
373 dev_dbg(hcd->self.controller,
"wHubCharacteristics 0x%04x\n",
388 dev_dbg(hcd->self.controller,
"wHubCharacteristics after 0x%04x\n",
396 dev_dbg(hcd->self.controller,
"GetPortStatus(%d)\n", wIndex);
399 if (!ohci_at91_usb_get_power(pdata, wIndex))
416 static const struct hc_driver ohci_at91_hc_driver = {
417 .description = hcd_name,
418 .product_desc =
"AT91 OHCI",
419 .hcd_priv_size =
sizeof(
struct ohci_hcd),
425 .flags = HCD_USB11 | HCD_MEMORY,
430 .reset = ohci_at91_reset,
431 .start = ohci_at91_start,
433 .shutdown = ohci_shutdown,
438 .urb_enqueue = ohci_urb_enqueue,
439 .urb_dequeue = ohci_urb_dequeue,
440 .endpoint_disable = ohci_endpoint_disable,
445 .get_frame_number = ohci_get_frame,
450 .hub_status_data = ohci_at91_hub_status_data,
451 .hub_control = ohci_at91_hub_control,
453 .bus_suspend = ohci_bus_suspend,
454 .bus_resume = ohci_bus_resume,
461 static irqreturn_t ohci_hcd_at91_overcurrent_irq(
int irq,
void *data)
478 dev_err(& pdev->
dev,
"overcurrent interrupt from unknown GPIO\n");
488 ohci_at91_usb_set_power(pdata, port, 0);
493 dev_dbg(& pdev->
dev,
"overcurrent situation %s\n",
494 val ?
"exited" :
"notified");
524 if (!pdev->
dev.dma_mask)
525 pdev->
dev.dma_mask = &at91_ohci_dma_mask;
531 if (!of_property_read_u32(np,
"num-ports", &ports))
537 if (!gpio_is_valid(gpio))
566 ret = ohci_at91_of_init(pdev);
570 pdata = pdev->
dev.platform_data;
578 if (i >= pdata->
ports) {
584 if (!gpio_is_valid(pdata->
vbus_pin[i]))
591 "can't request vbus gpio %d\n", gpio);
598 "can't put vbus gpio %d as output %d\n",
604 ohci_at91_usb_set_power(pdata, i, 1);
615 "can't request overcurrent gpio %d\n",
623 "can't configure overcurrent gpio %d as input\n",
630 ohci_hcd_at91_overcurrent_irq,
635 "can't get gpio IRQ for overcurrent\n");
641 return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
651 if (!gpio_is_valid(pdata->
vbus_pin[i]))
653 ohci_at91_usb_set_power(pdata, i, 0);
666 usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev);
675 struct usb_hcd *hcd = platform_get_drvdata(pdev);
676 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
678 if (device_may_wakeup(&pdev->
dev))
679 enable_irq_wake(hcd->irq);
689 ohci_usb_reset (ohci);
700 struct usb_hcd *hcd = platform_get_drvdata(pdev);
702 if (device_may_wakeup(&pdev->
dev))
703 disable_irq_wake(hcd->irq);
708 ohci_finish_controller_resume(hcd);
712 #define ohci_hcd_at91_drv_suspend NULL
713 #define ohci_hcd_at91_drv_resume NULL
719 .probe = ohci_hcd_at91_drv_probe,