ehci-au1xxx.c 7.9 KB

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