ehci-au1xxx.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  136. unsigned long flags;
  137. int rc = 0;
  138. if (time_before(jiffies, ehci->next_statechange))
  139. msleep(10);
  140. /* Root hub was already suspended. Disable irq emission and
  141. * mark HW unaccessible. The PM and USB cores make sure that
  142. * the root hub is either suspended or stopped.
  143. */
  144. ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
  145. spin_lock_irqsave(&ehci->lock, flags);
  146. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  147. (void)ehci_readl(ehci, &ehci->regs->intr_enable);
  148. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  149. spin_unlock_irqrestore(&ehci->lock, flags);
  150. // could save FLADJ in case of Vaux power loss
  151. // ... we'd only use it to handle clock skew
  152. alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
  153. return rc;
  154. }
  155. static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
  156. {
  157. struct usb_hcd *hcd = dev_get_drvdata(dev);
  158. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  159. alchemy_usb_control(ALCHEMY_USB_EHCI0, 1);
  160. // maybe restore FLADJ
  161. if (time_before(jiffies, ehci->next_statechange))
  162. msleep(100);
  163. /* Mark hardware accessible again as we are out of D3 state by now */
  164. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  165. /* If CF is still set, we maintained PCI Vaux power.
  166. * Just undo the effect of ehci_pci_suspend().
  167. */
  168. if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
  169. int mask = INTR_MASK;
  170. ehci_prepare_ports_for_controller_resume(ehci);
  171. if (!hcd->self.root_hub->do_remote_wakeup)
  172. mask &= ~STS_PCD;
  173. ehci_writel(ehci, mask, &ehci->regs->intr_enable);
  174. ehci_readl(ehci, &ehci->regs->intr_enable);
  175. return 0;
  176. }
  177. ehci_dbg(ehci, "lost power, restarting\n");
  178. usb_root_hub_lost_power(hcd->self.root_hub);
  179. /* Else reset, to cope with power loss or flush-to-storage
  180. * style "resume" having let BIOS kick in during reboot.
  181. */
  182. (void) ehci_halt(ehci);
  183. (void) ehci_reset(ehci);
  184. /* emptying the schedule aborts any urbs */
  185. spin_lock_irq(&ehci->lock);
  186. if (ehci->reclaim)
  187. end_unlink_async(ehci);
  188. ehci_work(ehci);
  189. spin_unlock_irq(&ehci->lock);
  190. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  191. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  192. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  193. /* here we "know" root ports should always stay powered */
  194. ehci_port_power(ehci, 1);
  195. ehci->rh_state = EHCI_RH_SUSPENDED;
  196. return 0;
  197. }
  198. static const struct dev_pm_ops au1xxx_ehci_pmops = {
  199. .suspend = ehci_hcd_au1xxx_drv_suspend,
  200. .resume = ehci_hcd_au1xxx_drv_resume,
  201. };
  202. #define AU1XXX_EHCI_PMOPS &au1xxx_ehci_pmops
  203. #else
  204. #define AU1XXX_EHCI_PMOPS NULL
  205. #endif
  206. static struct platform_driver ehci_hcd_au1xxx_driver = {
  207. .probe = ehci_hcd_au1xxx_drv_probe,
  208. .remove = ehci_hcd_au1xxx_drv_remove,
  209. .shutdown = usb_hcd_platform_shutdown,
  210. .driver = {
  211. .name = "au1xxx-ehci",
  212. .owner = THIS_MODULE,
  213. .pm = AU1XXX_EHCI_PMOPS,
  214. }
  215. };
  216. MODULE_ALIAS("platform:au1xxx-ehci");