ehci-au1xxx.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. /*
  87. * scheduling support
  88. */
  89. .get_frame_number = ehci_get_frame,
  90. /*
  91. * root hub support
  92. */
  93. .hub_status_data = ehci_hub_status_data,
  94. .hub_control = ehci_hub_control,
  95. .bus_suspend = ehci_bus_suspend,
  96. .bus_resume = ehci_bus_resume,
  97. .relinquish_port = ehci_relinquish_port,
  98. .port_handed_over = ehci_port_handed_over,
  99. };
  100. static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
  101. {
  102. struct usb_hcd *hcd;
  103. struct ehci_hcd *ehci;
  104. int ret;
  105. if (usb_disabled())
  106. return -ENODEV;
  107. #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
  108. /* Au1200 AB USB does not support coherent memory */
  109. if (!(read_c0_prid() & 0xff)) {
  110. printk(KERN_INFO "%s: this is chip revision AB!\n", pdev->name);
  111. printk(KERN_INFO "%s: update your board or re-configure"
  112. " the kernel\n", pdev->name);
  113. return -ENODEV;
  114. }
  115. #endif
  116. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  117. pr_debug("resource[1] is not IORESOURCE_IRQ");
  118. return -ENOMEM;
  119. }
  120. hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx");
  121. if (!hcd)
  122. return -ENOMEM;
  123. hcd->rsrc_start = pdev->resource[0].start;
  124. hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
  125. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  126. pr_debug("request_mem_region failed");
  127. ret = -EBUSY;
  128. goto err1;
  129. }
  130. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  131. if (!hcd->regs) {
  132. pr_debug("ioremap failed");
  133. ret = -ENOMEM;
  134. goto err2;
  135. }
  136. au1xxx_start_ehc();
  137. ehci = hcd_to_ehci(hcd);
  138. ehci->caps = hcd->regs;
  139. ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
  140. /* cache this readonly data; minimize chip reads */
  141. ehci->hcs_params = readl(&ehci->caps->hcs_params);
  142. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  143. IRQF_DISABLED | IRQF_SHARED);
  144. if (ret == 0) {
  145. platform_set_drvdata(pdev, hcd);
  146. return ret;
  147. }
  148. au1xxx_stop_ehc();
  149. iounmap(hcd->regs);
  150. err2:
  151. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  152. err1:
  153. usb_put_hcd(hcd);
  154. return ret;
  155. }
  156. static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
  157. {
  158. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  159. usb_remove_hcd(hcd);
  160. iounmap(hcd->regs);
  161. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  162. usb_put_hcd(hcd);
  163. au1xxx_stop_ehc();
  164. platform_set_drvdata(pdev, NULL);
  165. return 0;
  166. }
  167. /*TBD*/
  168. /*static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
  169. {
  170. struct platform_device *pdev = to_platform_device(dev);
  171. struct usb_hcd *hcd = dev_get_drvdata(dev);
  172. return 0;
  173. }
  174. static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
  175. {
  176. struct platform_device *pdev = to_platform_device(dev);
  177. struct usb_hcd *hcd = dev_get_drvdata(dev);
  178. return 0;
  179. }
  180. */
  181. static struct platform_driver ehci_hcd_au1xxx_driver = {
  182. .probe = ehci_hcd_au1xxx_drv_probe,
  183. .remove = ehci_hcd_au1xxx_drv_remove,
  184. .shutdown = usb_hcd_platform_shutdown,
  185. /*.suspend = ehci_hcd_au1xxx_drv_suspend, */
  186. /*.resume = ehci_hcd_au1xxx_drv_resume, */
  187. .driver = {
  188. .name = "au1xxx-ehci",
  189. .owner = THIS_MODULE,
  190. }
  191. };
  192. MODULE_ALIAS("platform:au1xxx-ehci");