ehci-au1xxx.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. return ret;
  22. }
  23. static const struct hc_driver ehci_au1xxx_hc_driver = {
  24. .description = hcd_name,
  25. .product_desc = "Au1xxx EHCI",
  26. .hcd_priv_size = sizeof(struct ehci_hcd),
  27. /*
  28. * generic hardware linkage
  29. */
  30. .irq = ehci_irq,
  31. .flags = HCD_MEMORY | HCD_USB2,
  32. /*
  33. * basic lifecycle operations
  34. *
  35. * FIXME -- ehci_init() doesn't do enough here.
  36. * See ehci-ppc-soc for a complete implementation.
  37. */
  38. .reset = au1xxx_ehci_setup,
  39. .start = ehci_run,
  40. .stop = ehci_stop,
  41. .shutdown = ehci_shutdown,
  42. /*
  43. * managing i/o requests and associated device resources
  44. */
  45. .urb_enqueue = ehci_urb_enqueue,
  46. .urb_dequeue = ehci_urb_dequeue,
  47. .endpoint_disable = ehci_endpoint_disable,
  48. .endpoint_reset = ehci_endpoint_reset,
  49. /*
  50. * scheduling support
  51. */
  52. .get_frame_number = ehci_get_frame,
  53. /*
  54. * root hub support
  55. */
  56. .hub_status_data = ehci_hub_status_data,
  57. .hub_control = ehci_hub_control,
  58. .bus_suspend = ehci_bus_suspend,
  59. .bus_resume = ehci_bus_resume,
  60. .relinquish_port = ehci_relinquish_port,
  61. .port_handed_over = ehci_port_handed_over,
  62. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  63. };
  64. static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
  65. {
  66. struct usb_hcd *hcd;
  67. struct ehci_hcd *ehci;
  68. struct resource *res;
  69. int ret;
  70. if (usb_disabled())
  71. return -ENODEV;
  72. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  73. pr_debug("resource[1] is not IORESOURCE_IRQ");
  74. return -ENOMEM;
  75. }
  76. hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx");
  77. if (!hcd)
  78. return -ENOMEM;
  79. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  80. hcd->rsrc_start = res->start;
  81. hcd->rsrc_len = resource_size(res);
  82. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  83. pr_debug("request_mem_region failed");
  84. ret = -EBUSY;
  85. goto err1;
  86. }
  87. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  88. if (!hcd->regs) {
  89. pr_debug("ioremap failed");
  90. ret = -ENOMEM;
  91. goto err2;
  92. }
  93. if (alchemy_usb_control(ALCHEMY_USB_EHCI0, 1)) {
  94. printk(KERN_INFO "%s: controller init failed!\n", pdev->name);
  95. ret = -ENODEV;
  96. goto err3;
  97. }
  98. ehci = hcd_to_ehci(hcd);
  99. ehci->caps = hcd->regs;
  100. ehci->regs = hcd->regs +
  101. HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
  102. /* cache this readonly data; minimize chip reads */
  103. ehci->hcs_params = readl(&ehci->caps->hcs_params);
  104. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  105. IRQF_SHARED);
  106. if (ret == 0) {
  107. platform_set_drvdata(pdev, hcd);
  108. return ret;
  109. }
  110. alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
  111. err3:
  112. iounmap(hcd->regs);
  113. err2:
  114. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  115. err1:
  116. usb_put_hcd(hcd);
  117. return ret;
  118. }
  119. static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
  120. {
  121. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  122. usb_remove_hcd(hcd);
  123. alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
  124. iounmap(hcd->regs);
  125. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  126. usb_put_hcd(hcd);
  127. platform_set_drvdata(pdev, NULL);
  128. return 0;
  129. }
  130. #ifdef CONFIG_PM
  131. static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
  132. {
  133. struct usb_hcd *hcd = dev_get_drvdata(dev);
  134. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  135. unsigned long flags;
  136. int rc = 0;
  137. if (time_before(jiffies, ehci->next_statechange))
  138. msleep(10);
  139. /* Root hub was already suspended. Disable irq emission and
  140. * mark HW unaccessible. The PM and USB cores make sure that
  141. * the root hub is either suspended or stopped.
  142. */
  143. ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
  144. spin_lock_irqsave(&ehci->lock, flags);
  145. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  146. (void)ehci_readl(ehci, &ehci->regs->intr_enable);
  147. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  148. spin_unlock_irqrestore(&ehci->lock, flags);
  149. // could save FLADJ in case of Vaux power loss
  150. // ... we'd only use it to handle clock skew
  151. alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
  152. return rc;
  153. }
  154. static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
  155. {
  156. struct usb_hcd *hcd = dev_get_drvdata(dev);
  157. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  158. alchemy_usb_control(ALCHEMY_USB_EHCI0, 1);
  159. // maybe restore FLADJ
  160. if (time_before(jiffies, ehci->next_statechange))
  161. msleep(100);
  162. /* Mark hardware accessible again as we are out of D3 state by now */
  163. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  164. /* If CF is still set, we maintained PCI Vaux power.
  165. * Just undo the effect of ehci_pci_suspend().
  166. */
  167. if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
  168. int mask = INTR_MASK;
  169. ehci_prepare_ports_for_controller_resume(ehci);
  170. if (!hcd->self.root_hub->do_remote_wakeup)
  171. mask &= ~STS_PCD;
  172. ehci_writel(ehci, mask, &ehci->regs->intr_enable);
  173. ehci_readl(ehci, &ehci->regs->intr_enable);
  174. return 0;
  175. }
  176. ehci_dbg(ehci, "lost power, restarting\n");
  177. usb_root_hub_lost_power(hcd->self.root_hub);
  178. /* Else reset, to cope with power loss or flush-to-storage
  179. * style "resume" having let BIOS kick in during reboot.
  180. */
  181. (void) ehci_halt(ehci);
  182. (void) ehci_reset(ehci);
  183. /* emptying the schedule aborts any urbs */
  184. spin_lock_irq(&ehci->lock);
  185. if (ehci->reclaim)
  186. end_unlink_async(ehci);
  187. ehci_work(ehci);
  188. spin_unlock_irq(&ehci->lock);
  189. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  190. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  191. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  192. /* here we "know" root ports should always stay powered */
  193. ehci_port_power(ehci, 1);
  194. ehci->rh_state = EHCI_RH_SUSPENDED;
  195. return 0;
  196. }
  197. static const struct dev_pm_ops au1xxx_ehci_pmops = {
  198. .suspend = ehci_hcd_au1xxx_drv_suspend,
  199. .resume = ehci_hcd_au1xxx_drv_resume,
  200. };
  201. #define AU1XXX_EHCI_PMOPS &au1xxx_ehci_pmops
  202. #else
  203. #define AU1XXX_EHCI_PMOPS NULL
  204. #endif
  205. static struct platform_driver ehci_hcd_au1xxx_driver = {
  206. .probe = ehci_hcd_au1xxx_drv_probe,
  207. .remove = ehci_hcd_au1xxx_drv_remove,
  208. .shutdown = usb_hcd_platform_shutdown,
  209. .driver = {
  210. .name = "au1xxx-ehci",
  211. .owner = THIS_MODULE,
  212. .pm = AU1XXX_EHCI_PMOPS,
  213. }
  214. };
  215. MODULE_ALIAS("platform:au1xxx-ehci");