ehci-au1xxx.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * EHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * Bus Glue for AMD Alchemy Au1xxx
  5. *
  6. * Based on "ohci-au1xxx.c" by Matt Porter <mporter@kernel.crashing.org>
  7. *
  8. * Modified for AMD Alchemy Au1200 EHC
  9. * by K.Boge <karsten.boge@amd.com>
  10. *
  11. * This file is licenced under the GPL.
  12. */
  13. #include <linux/platform_device.h>
  14. #include <asm/mach-au1x00/au1000.h>
  15. extern int usb_disabled(void);
  16. static int au1xxx_ehci_setup(struct usb_hcd *hcd)
  17. {
  18. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  19. int ret = ehci_init(hcd);
  20. ehci->need_io_watchdog = 0;
  21. ehci_reset(ehci);
  22. return ret;
  23. }
  24. static const struct hc_driver ehci_au1xxx_hc_driver = {
  25. .description = hcd_name,
  26. .product_desc = "Au1xxx EHCI",
  27. .hcd_priv_size = sizeof(struct ehci_hcd),
  28. /*
  29. * generic hardware linkage
  30. */
  31. .irq = ehci_irq,
  32. .flags = HCD_MEMORY | HCD_USB2,
  33. /*
  34. * basic lifecycle operations
  35. *
  36. * FIXME -- ehci_init() doesn't do enough here.
  37. * See ehci-ppc-soc for a complete implementation.
  38. */
  39. .reset = au1xxx_ehci_setup,
  40. .start = ehci_run,
  41. .stop = ehci_stop,
  42. .shutdown = ehci_shutdown,
  43. /*
  44. * managing i/o requests and associated device resources
  45. */
  46. .urb_enqueue = ehci_urb_enqueue,
  47. .urb_dequeue = ehci_urb_dequeue,
  48. .endpoint_disable = ehci_endpoint_disable,
  49. .endpoint_reset = ehci_endpoint_reset,
  50. /*
  51. * scheduling support
  52. */
  53. .get_frame_number = ehci_get_frame,
  54. /*
  55. * root hub support
  56. */
  57. .hub_status_data = ehci_hub_status_data,
  58. .hub_control = ehci_hub_control,
  59. .bus_suspend = ehci_bus_suspend,
  60. .bus_resume = ehci_bus_resume,
  61. .relinquish_port = ehci_relinquish_port,
  62. .port_handed_over = ehci_port_handed_over,
  63. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  64. };
  65. static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
  66. {
  67. struct usb_hcd *hcd;
  68. struct ehci_hcd *ehci;
  69. struct resource *res;
  70. int ret;
  71. if (usb_disabled())
  72. return -ENODEV;
  73. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  74. pr_debug("resource[1] is not IORESOURCE_IRQ");
  75. return -ENOMEM;
  76. }
  77. hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx");
  78. if (!hcd)
  79. return -ENOMEM;
  80. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  81. hcd->rsrc_start = res->start;
  82. hcd->rsrc_len = resource_size(res);
  83. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  84. pr_debug("request_mem_region failed");
  85. ret = -EBUSY;
  86. goto err1;
  87. }
  88. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  89. if (!hcd->regs) {
  90. pr_debug("ioremap failed");
  91. ret = -ENOMEM;
  92. goto err2;
  93. }
  94. if (alchemy_usb_control(ALCHEMY_USB_EHCI0, 1)) {
  95. printk(KERN_INFO "%s: controller init failed!\n", pdev->name);
  96. ret = -ENODEV;
  97. goto err3;
  98. }
  99. ehci = hcd_to_ehci(hcd);
  100. ehci->caps = hcd->regs;
  101. ehci->regs = hcd->regs +
  102. HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
  103. /* cache this readonly data; minimize chip reads */
  104. ehci->hcs_params = readl(&ehci->caps->hcs_params);
  105. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  106. IRQF_SHARED);
  107. if (ret == 0) {
  108. platform_set_drvdata(pdev, hcd);
  109. return ret;
  110. }
  111. alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
  112. err3:
  113. iounmap(hcd->regs);
  114. err2:
  115. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  116. err1:
  117. usb_put_hcd(hcd);
  118. return ret;
  119. }
  120. static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
  121. {
  122. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  123. usb_remove_hcd(hcd);
  124. alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
  125. iounmap(hcd->regs);
  126. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  127. usb_put_hcd(hcd);
  128. platform_set_drvdata(pdev, NULL);
  129. return 0;
  130. }
  131. #ifdef CONFIG_PM
  132. static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
  133. {
  134. struct usb_hcd *hcd = dev_get_drvdata(dev);
  135. bool do_wakeup = device_may_wakeup(dev);
  136. int rc;
  137. rc = ehci_suspend(hcd, do_wakeup);
  138. alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
  139. return rc;
  140. }
  141. static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
  142. {
  143. struct usb_hcd *hcd = dev_get_drvdata(dev);
  144. alchemy_usb_control(ALCHEMY_USB_EHCI0, 1);
  145. ehci_resume(hcd, false);
  146. return 0;
  147. }
  148. static const struct dev_pm_ops au1xxx_ehci_pmops = {
  149. .suspend = ehci_hcd_au1xxx_drv_suspend,
  150. .resume = ehci_hcd_au1xxx_drv_resume,
  151. };
  152. #define AU1XXX_EHCI_PMOPS &au1xxx_ehci_pmops
  153. #else
  154. #define AU1XXX_EHCI_PMOPS NULL
  155. #endif
  156. static struct platform_driver ehci_hcd_au1xxx_driver = {
  157. .probe = ehci_hcd_au1xxx_drv_probe,
  158. .remove = ehci_hcd_au1xxx_drv_remove,
  159. .shutdown = usb_hcd_platform_shutdown,
  160. .driver = {
  161. .name = "au1xxx-ehci",
  162. .owner = THIS_MODULE,
  163. .pm = AU1XXX_EHCI_PMOPS,
  164. }
  165. };
  166. MODULE_ALIAS("platform:au1xxx-ehci");