ehci-au1xxx.c 8.0 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 int au1xxx_ehci_setup(struct usb_hcd *hcd)
  62. {
  63. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  64. int ret = ehci_init(hcd);
  65. ehci->need_io_watchdog = 0;
  66. return ret;
  67. }
  68. static const struct hc_driver ehci_au1xxx_hc_driver = {
  69. .description = hcd_name,
  70. .product_desc = "Au1xxx EHCI",
  71. .hcd_priv_size = sizeof(struct ehci_hcd),
  72. /*
  73. * generic hardware linkage
  74. */
  75. .irq = ehci_irq,
  76. .flags = HCD_MEMORY | HCD_USB2,
  77. /*
  78. * basic lifecycle operations
  79. *
  80. * FIXME -- ehci_init() doesn't do enough here.
  81. * See ehci-ppc-soc for a complete implementation.
  82. */
  83. .reset = au1xxx_ehci_setup,
  84. .start = ehci_run,
  85. .stop = ehci_stop,
  86. .shutdown = ehci_shutdown,
  87. /*
  88. * managing i/o requests and associated device resources
  89. */
  90. .urb_enqueue = ehci_urb_enqueue,
  91. .urb_dequeue = ehci_urb_dequeue,
  92. .endpoint_disable = ehci_endpoint_disable,
  93. .endpoint_reset = ehci_endpoint_reset,
  94. /*
  95. * scheduling support
  96. */
  97. .get_frame_number = ehci_get_frame,
  98. /*
  99. * root hub support
  100. */
  101. .hub_status_data = ehci_hub_status_data,
  102. .hub_control = ehci_hub_control,
  103. .bus_suspend = ehci_bus_suspend,
  104. .bus_resume = ehci_bus_resume,
  105. .relinquish_port = ehci_relinquish_port,
  106. .port_handed_over = ehci_port_handed_over,
  107. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  108. };
  109. static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
  110. {
  111. struct usb_hcd *hcd;
  112. struct ehci_hcd *ehci;
  113. struct resource *res;
  114. int ret;
  115. if (usb_disabled())
  116. return -ENODEV;
  117. #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
  118. /* Au1200 AB USB does not support coherent memory */
  119. if (!(read_c0_prid() & 0xff)) {
  120. printk(KERN_INFO "%s: this is chip revision AB!\n", pdev->name);
  121. printk(KERN_INFO "%s: update your board or re-configure"
  122. " the kernel\n", pdev->name);
  123. return -ENODEV;
  124. }
  125. #endif
  126. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  127. pr_debug("resource[1] is not IORESOURCE_IRQ");
  128. return -ENOMEM;
  129. }
  130. hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx");
  131. if (!hcd)
  132. return -ENOMEM;
  133. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  134. hcd->rsrc_start = res->start;
  135. hcd->rsrc_len = resource_size(res);
  136. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  137. pr_debug("request_mem_region failed");
  138. ret = -EBUSY;
  139. goto err1;
  140. }
  141. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  142. if (!hcd->regs) {
  143. pr_debug("ioremap failed");
  144. ret = -ENOMEM;
  145. goto err2;
  146. }
  147. au1xxx_start_ehc();
  148. ehci = hcd_to_ehci(hcd);
  149. ehci->caps = hcd->regs;
  150. ehci->regs = hcd->regs +
  151. HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
  152. /* cache this readonly data; minimize chip reads */
  153. ehci->hcs_params = readl(&ehci->caps->hcs_params);
  154. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  155. IRQF_DISABLED | IRQF_SHARED);
  156. if (ret == 0) {
  157. platform_set_drvdata(pdev, hcd);
  158. return ret;
  159. }
  160. au1xxx_stop_ehc();
  161. iounmap(hcd->regs);
  162. err2:
  163. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  164. err1:
  165. usb_put_hcd(hcd);
  166. return ret;
  167. }
  168. static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
  169. {
  170. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  171. usb_remove_hcd(hcd);
  172. iounmap(hcd->regs);
  173. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  174. usb_put_hcd(hcd);
  175. au1xxx_stop_ehc();
  176. platform_set_drvdata(pdev, NULL);
  177. return 0;
  178. }
  179. #ifdef CONFIG_PM
  180. static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
  181. {
  182. struct usb_hcd *hcd = dev_get_drvdata(dev);
  183. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  184. unsigned long flags;
  185. int rc = 0;
  186. if (time_before(jiffies, ehci->next_statechange))
  187. msleep(10);
  188. /* Root hub was already suspended. Disable irq emission and
  189. * mark HW unaccessible. The PM and USB cores make sure that
  190. * the root hub is either suspended or stopped.
  191. */
  192. ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
  193. spin_lock_irqsave(&ehci->lock, flags);
  194. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  195. (void)ehci_readl(ehci, &ehci->regs->intr_enable);
  196. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  197. spin_unlock_irqrestore(&ehci->lock, flags);
  198. // could save FLADJ in case of Vaux power loss
  199. // ... we'd only use it to handle clock skew
  200. au1xxx_stop_ehc();
  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. ehci_prepare_ports_for_controller_resume(ehci);
  219. if (!hcd->self.root_hub->do_remote_wakeup)
  220. mask &= ~STS_PCD;
  221. ehci_writel(ehci, mask, &ehci->regs->intr_enable);
  222. ehci_readl(ehci, &ehci->regs->intr_enable);
  223. return 0;
  224. }
  225. ehci_dbg(ehci, "lost power, restarting\n");
  226. usb_root_hub_lost_power(hcd->self.root_hub);
  227. /* Else reset, to cope with power loss or flush-to-storage
  228. * style "resume" having let BIOS kick in during reboot.
  229. */
  230. (void) ehci_halt(ehci);
  231. (void) ehci_reset(ehci);
  232. /* emptying the schedule aborts any urbs */
  233. spin_lock_irq(&ehci->lock);
  234. if (ehci->reclaim)
  235. end_unlink_async(ehci);
  236. ehci_work(ehci);
  237. spin_unlock_irq(&ehci->lock);
  238. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  239. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  240. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  241. /* here we "know" root ports should always stay powered */
  242. ehci_port_power(ehci, 1);
  243. hcd->state = HC_STATE_SUSPENDED;
  244. return 0;
  245. }
  246. static const struct dev_pm_ops au1xxx_ehci_pmops = {
  247. .suspend = ehci_hcd_au1xxx_drv_suspend,
  248. .resume = ehci_hcd_au1xxx_drv_resume,
  249. };
  250. #define AU1XXX_EHCI_PMOPS &au1xxx_ehci_pmops
  251. #else
  252. #define AU1XXX_EHCI_PMOPS 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. .driver = {
  259. .name = "au1xxx-ehci",
  260. .owner = THIS_MODULE,
  261. .pm = AU1XXX_EHCI_PMOPS,
  262. }
  263. };
  264. MODULE_ALIAS("platform:au1xxx-ehci");