ehci-au1xxx.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. #define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG)
  16. #define USB_MCFG_PFEN (1<<31)
  17. #define USB_MCFG_RDCOMB (1<<30)
  18. #define USB_MCFG_SSDEN (1<<23)
  19. #define USB_MCFG_PHYPLLEN (1<<19)
  20. #define USB_MCFG_UCECLKEN (1<<18)
  21. #define USB_MCFG_EHCCLKEN (1<<17)
  22. #ifdef CONFIG_DMA_COHERENT
  23. #define USB_MCFG_UCAM (1<<7)
  24. #else
  25. #define USB_MCFG_UCAM (0)
  26. #endif
  27. #define USB_MCFG_EBMEN (1<<3)
  28. #define USB_MCFG_EMEMEN (1<<2)
  29. #define USBH_ENABLE_CE (USB_MCFG_PHYPLLEN | USB_MCFG_EHCCLKEN)
  30. #define USBH_ENABLE_INIT (USB_MCFG_PFEN | USB_MCFG_RDCOMB | \
  31. USBH_ENABLE_CE | USB_MCFG_SSDEN | \
  32. USB_MCFG_UCAM | USB_MCFG_EBMEN | \
  33. USB_MCFG_EMEMEN)
  34. #define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
  35. extern int usb_disabled(void);
  36. static void au1xxx_start_ehc(void)
  37. {
  38. /* enable clock to EHCI block and HS PHY PLL*/
  39. au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG);
  40. au_sync();
  41. udelay(1000);
  42. /* enable EHCI mmio */
  43. au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
  44. au_sync();
  45. udelay(1000);
  46. }
  47. static void au1xxx_stop_ehc(void)
  48. {
  49. unsigned long c;
  50. /* Disable mem */
  51. au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG);
  52. au_sync();
  53. udelay(1000);
  54. /* Disable EHC clock. If the HS PHY is unused disable it too. */
  55. c = au_readl(USB_HOST_CONFIG) & ~USB_MCFG_EHCCLKEN;
  56. if (!(c & USB_MCFG_UCECLKEN)) /* UDC disabled? */
  57. c &= ~USB_MCFG_PHYPLLEN; /* yes: disable HS PHY PLL */
  58. au_writel(c, USB_HOST_CONFIG);
  59. au_sync();
  60. }
  61. static const struct hc_driver ehci_au1xxx_hc_driver = {
  62. .description = hcd_name,
  63. .product_desc = "Au1xxx EHCI",
  64. .hcd_priv_size = sizeof(struct ehci_hcd),
  65. /*
  66. * generic hardware linkage
  67. */
  68. .irq = ehci_irq,
  69. .flags = HCD_MEMORY | HCD_USB2,
  70. /*
  71. * basic lifecycle operations
  72. *
  73. * FIXME -- ehci_init() doesn't do enough here.
  74. * See ehci-ppc-soc for a complete implementation.
  75. */
  76. .reset = ehci_init,
  77. .start = ehci_run,
  78. .stop = ehci_stop,
  79. .shutdown = ehci_shutdown,
  80. /*
  81. * managing i/o requests and associated device resources
  82. */
  83. .urb_enqueue = ehci_urb_enqueue,
  84. .urb_dequeue = ehci_urb_dequeue,
  85. .endpoint_disable = ehci_endpoint_disable,
  86. .endpoint_reset = ehci_endpoint_reset,
  87. /*
  88. * scheduling support
  89. */
  90. .get_frame_number = ehci_get_frame,
  91. /*
  92. * root hub support
  93. */
  94. .hub_status_data = ehci_hub_status_data,
  95. .hub_control = ehci_hub_control,
  96. .bus_suspend = ehci_bus_suspend,
  97. .bus_resume = ehci_bus_resume,
  98. .relinquish_port = ehci_relinquish_port,
  99. .port_handed_over = ehci_port_handed_over,
  100. };
  101. static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
  102. {
  103. struct usb_hcd *hcd;
  104. struct ehci_hcd *ehci;
  105. int ret;
  106. if (usb_disabled())
  107. return -ENODEV;
  108. #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
  109. /* Au1200 AB USB does not support coherent memory */
  110. if (!(read_c0_prid() & 0xff)) {
  111. printk(KERN_INFO "%s: this is chip revision AB!\n", pdev->name);
  112. printk(KERN_INFO "%s: update your board or re-configure"
  113. " the kernel\n", pdev->name);
  114. return -ENODEV;
  115. }
  116. #endif
  117. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  118. pr_debug("resource[1] is not IORESOURCE_IRQ");
  119. return -ENOMEM;
  120. }
  121. hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx");
  122. if (!hcd)
  123. return -ENOMEM;
  124. hcd->rsrc_start = pdev->resource[0].start;
  125. hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
  126. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  127. pr_debug("request_mem_region failed");
  128. ret = -EBUSY;
  129. goto err1;
  130. }
  131. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  132. if (!hcd->regs) {
  133. pr_debug("ioremap failed");
  134. ret = -ENOMEM;
  135. goto err2;
  136. }
  137. au1xxx_start_ehc();
  138. ehci = hcd_to_ehci(hcd);
  139. ehci->caps = hcd->regs;
  140. ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
  141. /* cache this readonly data; minimize chip reads */
  142. ehci->hcs_params = readl(&ehci->caps->hcs_params);
  143. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  144. IRQF_DISABLED | IRQF_SHARED);
  145. if (ret == 0) {
  146. platform_set_drvdata(pdev, hcd);
  147. return ret;
  148. }
  149. au1xxx_stop_ehc();
  150. iounmap(hcd->regs);
  151. err2:
  152. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  153. err1:
  154. usb_put_hcd(hcd);
  155. return ret;
  156. }
  157. static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
  158. {
  159. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  160. usb_remove_hcd(hcd);
  161. iounmap(hcd->regs);
  162. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  163. usb_put_hcd(hcd);
  164. au1xxx_stop_ehc();
  165. platform_set_drvdata(pdev, NULL);
  166. return 0;
  167. }
  168. #ifdef CONFIG_PM
  169. static int ehci_hcd_au1xxx_drv_suspend(struct platform_device *pdev,
  170. pm_message_t message)
  171. {
  172. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  173. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  174. unsigned long flags;
  175. int rc;
  176. return 0;
  177. rc = 0;
  178. if (time_before(jiffies, ehci->next_statechange))
  179. msleep(10);
  180. /* Root hub was already suspended. Disable irq emission and
  181. * mark HW unaccessible, bail out if RH has been resumed. Use
  182. * the spinlock to properly synchronize with possible pending
  183. * RH suspend or resume activity.
  184. *
  185. * This is still racy as hcd->state is manipulated outside of
  186. * any locks =P But that will be a different fix.
  187. */
  188. spin_lock_irqsave(&ehci->lock, flags);
  189. if (hcd->state != HC_STATE_SUSPENDED) {
  190. rc = -EINVAL;
  191. goto bail;
  192. }
  193. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  194. (void)ehci_readl(ehci, &ehci->regs->intr_enable);
  195. /* make sure snapshot being resumed re-enumerates everything */
  196. if (message.event == PM_EVENT_PRETHAW) {
  197. ehci_halt(ehci);
  198. ehci_reset(ehci);
  199. }
  200. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  201. au1xxx_stop_ehc();
  202. bail:
  203. spin_unlock_irqrestore(&ehci->lock, flags);
  204. // could save FLADJ in case of Vaux power loss
  205. // ... we'd only use it to handle clock skew
  206. return rc;
  207. }
  208. static int ehci_hcd_au1xxx_drv_resume(struct platform_device *pdev)
  209. {
  210. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  211. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  212. au1xxx_start_ehc();
  213. // maybe restore FLADJ
  214. if (time_before(jiffies, ehci->next_statechange))
  215. msleep(100);
  216. /* Mark hardware accessible again as we are out of D3 state by now */
  217. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  218. /* If CF is still set, we maintained PCI Vaux power.
  219. * Just undo the effect of ehci_pci_suspend().
  220. */
  221. if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
  222. int mask = INTR_MASK;
  223. if (!hcd->self.root_hub->do_remote_wakeup)
  224. mask &= ~STS_PCD;
  225. ehci_writel(ehci, mask, &ehci->regs->intr_enable);
  226. ehci_readl(ehci, &ehci->regs->intr_enable);
  227. return 0;
  228. }
  229. ehci_dbg(ehci, "lost power, restarting\n");
  230. usb_root_hub_lost_power(hcd->self.root_hub);
  231. /* Else reset, to cope with power loss or flush-to-storage
  232. * style "resume" having let BIOS kick in during reboot.
  233. */
  234. (void) ehci_halt(ehci);
  235. (void) ehci_reset(ehci);
  236. /* emptying the schedule aborts any urbs */
  237. spin_lock_irq(&ehci->lock);
  238. if (ehci->reclaim)
  239. end_unlink_async(ehci);
  240. ehci_work(ehci);
  241. spin_unlock_irq(&ehci->lock);
  242. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  243. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  244. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  245. /* here we "know" root ports should always stay powered */
  246. ehci_port_power(ehci, 1);
  247. hcd->state = HC_STATE_SUSPENDED;
  248. return 0;
  249. }
  250. #else
  251. #define ehci_hcd_au1xxx_drv_suspend NULL
  252. #define ehci_hcd_au1xxx_drv_resume NULL
  253. #endif
  254. static struct platform_driver ehci_hcd_au1xxx_driver = {
  255. .probe = ehci_hcd_au1xxx_drv_probe,
  256. .remove = ehci_hcd_au1xxx_drv_remove,
  257. .shutdown = usb_hcd_platform_shutdown,
  258. .suspend = ehci_hcd_au1xxx_drv_suspend,
  259. .resume = ehci_hcd_au1xxx_drv_resume,
  260. .driver = {
  261. .name = "au1xxx-ehci",
  262. .owner = THIS_MODULE,
  263. }
  264. };
  265. MODULE_ALIAS("platform:au1xxx-ehci");