ehci-au1xxx.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  101. };
  102. static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
  103. {
  104. struct usb_hcd *hcd;
  105. struct ehci_hcd *ehci;
  106. int ret;
  107. if (usb_disabled())
  108. return -ENODEV;
  109. #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
  110. /* Au1200 AB USB does not support coherent memory */
  111. if (!(read_c0_prid() & 0xff)) {
  112. printk(KERN_INFO "%s: this is chip revision AB!\n", pdev->name);
  113. printk(KERN_INFO "%s: update your board or re-configure"
  114. " the kernel\n", pdev->name);
  115. return -ENODEV;
  116. }
  117. #endif
  118. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  119. pr_debug("resource[1] is not IORESOURCE_IRQ");
  120. return -ENOMEM;
  121. }
  122. hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx");
  123. if (!hcd)
  124. return -ENOMEM;
  125. hcd->rsrc_start = pdev->resource[0].start;
  126. hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
  127. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  128. pr_debug("request_mem_region failed");
  129. ret = -EBUSY;
  130. goto err1;
  131. }
  132. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  133. if (!hcd->regs) {
  134. pr_debug("ioremap failed");
  135. ret = -ENOMEM;
  136. goto err2;
  137. }
  138. au1xxx_start_ehc();
  139. ehci = hcd_to_ehci(hcd);
  140. ehci->caps = hcd->regs;
  141. ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
  142. /* cache this readonly data; minimize chip reads */
  143. ehci->hcs_params = readl(&ehci->caps->hcs_params);
  144. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  145. IRQF_DISABLED | IRQF_SHARED);
  146. if (ret == 0) {
  147. platform_set_drvdata(pdev, hcd);
  148. return ret;
  149. }
  150. au1xxx_stop_ehc();
  151. iounmap(hcd->regs);
  152. err2:
  153. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  154. err1:
  155. usb_put_hcd(hcd);
  156. return ret;
  157. }
  158. static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
  159. {
  160. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  161. usb_remove_hcd(hcd);
  162. iounmap(hcd->regs);
  163. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  164. usb_put_hcd(hcd);
  165. au1xxx_stop_ehc();
  166. platform_set_drvdata(pdev, NULL);
  167. return 0;
  168. }
  169. #ifdef CONFIG_PM
  170. static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
  171. {
  172. struct usb_hcd *hcd = dev_get_drvdata(dev);
  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. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  196. au1xxx_stop_ehc();
  197. bail:
  198. spin_unlock_irqrestore(&ehci->lock, flags);
  199. // could save FLADJ in case of Vaux power loss
  200. // ... we'd only use it to handle clock skew
  201. return rc;
  202. }
  203. static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
  204. {
  205. struct usb_hcd *hcd = dev_get_drvdata(dev);
  206. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  207. au1xxx_start_ehc();
  208. // maybe restore FLADJ
  209. if (time_before(jiffies, ehci->next_statechange))
  210. msleep(100);
  211. /* Mark hardware accessible again as we are out of D3 state by now */
  212. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  213. /* If CF is still set, we maintained PCI Vaux power.
  214. * Just undo the effect of ehci_pci_suspend().
  215. */
  216. if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
  217. int mask = INTR_MASK;
  218. if (!hcd->self.root_hub->do_remote_wakeup)
  219. mask &= ~STS_PCD;
  220. ehci_writel(ehci, mask, &ehci->regs->intr_enable);
  221. ehci_readl(ehci, &ehci->regs->intr_enable);
  222. return 0;
  223. }
  224. ehci_dbg(ehci, "lost power, restarting\n");
  225. usb_root_hub_lost_power(hcd->self.root_hub);
  226. /* Else reset, to cope with power loss or flush-to-storage
  227. * style "resume" having let BIOS kick in during reboot.
  228. */
  229. (void) ehci_halt(ehci);
  230. (void) ehci_reset(ehci);
  231. /* emptying the schedule aborts any urbs */
  232. spin_lock_irq(&ehci->lock);
  233. if (ehci->reclaim)
  234. end_unlink_async(ehci);
  235. ehci_work(ehci);
  236. spin_unlock_irq(&ehci->lock);
  237. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  238. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  239. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  240. /* here we "know" root ports should always stay powered */
  241. ehci_port_power(ehci, 1);
  242. hcd->state = HC_STATE_SUSPENDED;
  243. return 0;
  244. }
  245. static const struct dev_pm_ops au1xxx_ehci_pmops = {
  246. .suspend = ehci_hcd_au1xxx_drv_suspend,
  247. .resume = ehci_hcd_au1xxx_drv_resume,
  248. };
  249. #define AU1XXX_EHCI_PMOPS &au1xxx_ehci_pmops
  250. #else
  251. #define AU1XXX_EHCI_PMOPS NULL
  252. #endif
  253. static struct platform_driver ehci_hcd_au1xxx_driver = {
  254. .probe = ehci_hcd_au1xxx_drv_probe,
  255. .remove = ehci_hcd_au1xxx_drv_remove,
  256. .shutdown = usb_hcd_platform_shutdown,
  257. .driver = {
  258. .name = "au1xxx-ehci",
  259. .owner = THIS_MODULE,
  260. .pm = AU1XXX_EHCI_PMOPS,
  261. }
  262. };
  263. MODULE_ALIAS("platform:au1xxx-ehci");