ehci-au1xxx.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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;
  20. ehci->caps = hcd->regs;
  21. ret = ehci_setup(hcd);
  22. ehci->need_io_watchdog = 0;
  23. return ret;
  24. }
  25. static const struct hc_driver ehci_au1xxx_hc_driver = {
  26. .description = hcd_name,
  27. .product_desc = "Au1xxx EHCI",
  28. .hcd_priv_size = sizeof(struct ehci_hcd),
  29. /*
  30. * generic hardware linkage
  31. */
  32. .irq = ehci_irq,
  33. .flags = HCD_MEMORY | HCD_USB2,
  34. /*
  35. * basic lifecycle operations
  36. *
  37. * FIXME -- ehci_init() doesn't do enough here.
  38. * See ehci-ppc-soc for a complete implementation.
  39. */
  40. .reset = au1xxx_ehci_setup,
  41. .start = ehci_run,
  42. .stop = ehci_stop,
  43. .shutdown = ehci_shutdown,
  44. /*
  45. * managing i/o requests and associated device resources
  46. */
  47. .urb_enqueue = ehci_urb_enqueue,
  48. .urb_dequeue = ehci_urb_dequeue,
  49. .endpoint_disable = ehci_endpoint_disable,
  50. .endpoint_reset = ehci_endpoint_reset,
  51. /*
  52. * scheduling support
  53. */
  54. .get_frame_number = ehci_get_frame,
  55. /*
  56. * root hub support
  57. */
  58. .hub_status_data = ehci_hub_status_data,
  59. .hub_control = ehci_hub_control,
  60. .bus_suspend = ehci_bus_suspend,
  61. .bus_resume = ehci_bus_resume,
  62. .relinquish_port = ehci_relinquish_port,
  63. .port_handed_over = ehci_port_handed_over,
  64. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  65. };
  66. static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
  67. {
  68. struct usb_hcd *hcd;
  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. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  100. IRQF_SHARED);
  101. if (ret == 0) {
  102. platform_set_drvdata(pdev, hcd);
  103. return ret;
  104. }
  105. alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
  106. err3:
  107. iounmap(hcd->regs);
  108. err2:
  109. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  110. err1:
  111. usb_put_hcd(hcd);
  112. return ret;
  113. }
  114. static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
  115. {
  116. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  117. usb_remove_hcd(hcd);
  118. alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
  119. iounmap(hcd->regs);
  120. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  121. usb_put_hcd(hcd);
  122. platform_set_drvdata(pdev, NULL);
  123. return 0;
  124. }
  125. #ifdef CONFIG_PM
  126. static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
  127. {
  128. struct usb_hcd *hcd = dev_get_drvdata(dev);
  129. bool do_wakeup = device_may_wakeup(dev);
  130. int rc;
  131. rc = ehci_suspend(hcd, do_wakeup);
  132. alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
  133. return rc;
  134. }
  135. static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
  136. {
  137. struct usb_hcd *hcd = dev_get_drvdata(dev);
  138. alchemy_usb_control(ALCHEMY_USB_EHCI0, 1);
  139. ehci_resume(hcd, false);
  140. return 0;
  141. }
  142. static const struct dev_pm_ops au1xxx_ehci_pmops = {
  143. .suspend = ehci_hcd_au1xxx_drv_suspend,
  144. .resume = ehci_hcd_au1xxx_drv_resume,
  145. };
  146. #define AU1XXX_EHCI_PMOPS &au1xxx_ehci_pmops
  147. #else
  148. #define AU1XXX_EHCI_PMOPS NULL
  149. #endif
  150. static struct platform_driver ehci_hcd_au1xxx_driver = {
  151. .probe = ehci_hcd_au1xxx_drv_probe,
  152. .remove = ehci_hcd_au1xxx_drv_remove,
  153. .shutdown = usb_hcd_platform_shutdown,
  154. .driver = {
  155. .name = "au1xxx-ehci",
  156. .owner = THIS_MODULE,
  157. .pm = AU1XXX_EHCI_PMOPS,
  158. }
  159. };
  160. MODULE_ALIAS("platform:au1xxx-ehci");