ehci-au1xxx.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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_EHCCLKEN (1<<17)
  21. #define USB_MCFG_UCAM (1<<7)
  22. #define USB_MCFG_EBMEN (1<<3)
  23. #define USB_MCFG_EMEMEN (1<<2)
  24. #define USBH_ENABLE_CE (USB_MCFG_PHYPLLEN | USB_MCFG_EHCCLKEN)
  25. #ifdef CONFIG_DMA_COHERENT
  26. #define USBH_ENABLE_INIT (USBH_ENABLE_CE \
  27. | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
  28. | USB_MCFG_SSDEN | USB_MCFG_UCAM \
  29. | USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
  30. #else
  31. #define USBH_ENABLE_INIT (USBH_ENABLE_CE \
  32. | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
  33. | USB_MCFG_SSDEN \
  34. | USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
  35. #endif
  36. #define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
  37. extern int usb_disabled(void);
  38. /*-------------------------------------------------------------------------*/
  39. static void au1xxx_start_ehc(struct platform_device *dev)
  40. {
  41. pr_debug(__FILE__ ": starting Au1xxx EHCI USB Controller\n");
  42. /* write HW defaults again in case Yamon cleared them */
  43. if (au_readl(USB_HOST_CONFIG) == 0) {
  44. au_writel(0x00d02000, USB_HOST_CONFIG);
  45. au_readl(USB_HOST_CONFIG);
  46. udelay(1000);
  47. }
  48. /* enable host controller */
  49. au_writel(USBH_ENABLE_CE | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
  50. au_readl(USB_HOST_CONFIG);
  51. udelay(1000);
  52. au_writel(USBH_ENABLE_INIT | au_readl(USB_HOST_CONFIG),
  53. USB_HOST_CONFIG);
  54. au_readl(USB_HOST_CONFIG);
  55. udelay(1000);
  56. pr_debug(__FILE__ ": Clock to USB host has been enabled\n");
  57. }
  58. static void au1xxx_stop_ehc(struct platform_device *dev)
  59. {
  60. pr_debug(__FILE__ ": stopping Au1xxx EHCI USB Controller\n");
  61. /* Disable mem */
  62. au_writel(~USBH_DISABLE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
  63. udelay(1000);
  64. /* Disable clock */
  65. au_writel(~USB_MCFG_EHCCLKEN & au_readl(USB_HOST_CONFIG),
  66. USB_HOST_CONFIG);
  67. au_readl(USB_HOST_CONFIG);
  68. }
  69. /*-------------------------------------------------------------------------*/
  70. /* configure so an HC device and id are always provided */
  71. /* always called with process context; sleeping is OK */
  72. /**
  73. * usb_ehci_au1xxx_probe - initialize Au1xxx-based HCDs
  74. * Context: !in_interrupt()
  75. *
  76. * Allocates basic resources for this USB host controller, and
  77. * then invokes the start() method for the HCD associated with it
  78. * through the hotplug entry's driver_data.
  79. *
  80. */
  81. int usb_ehci_au1xxx_probe(const struct hc_driver *driver,
  82. struct usb_hcd **hcd_out, struct platform_device *dev)
  83. {
  84. int retval;
  85. struct usb_hcd *hcd;
  86. struct ehci_hcd *ehci;
  87. #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
  88. /* Au1200 AB USB does not support coherent memory */
  89. if (!(read_c0_prid() & 0xff)) {
  90. pr_info("%s: this is chip revision AB!\n", dev->name);
  91. pr_info("%s: update your board or re-configure the kernel\n",
  92. dev->name);
  93. return -ENODEV;
  94. }
  95. #endif
  96. au1xxx_start_ehc(dev);
  97. if (dev->resource[1].flags != IORESOURCE_IRQ) {
  98. pr_debug("resource[1] is not IORESOURCE_IRQ");
  99. retval = -ENOMEM;
  100. }
  101. hcd = usb_create_hcd(driver, &dev->dev, "Au1xxx");
  102. if (!hcd)
  103. return -ENOMEM;
  104. hcd->rsrc_start = dev->resource[0].start;
  105. hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
  106. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  107. pr_debug("request_mem_region failed");
  108. retval = -EBUSY;
  109. goto err1;
  110. }
  111. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  112. if (!hcd->regs) {
  113. pr_debug("ioremap failed");
  114. retval = -ENOMEM;
  115. goto err2;
  116. }
  117. ehci = hcd_to_ehci(hcd);
  118. ehci->caps = hcd->regs;
  119. ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
  120. /* cache this readonly data; minimize chip reads */
  121. ehci->hcs_params = readl(&ehci->caps->hcs_params);
  122. /* ehci_hcd_init(hcd_to_ehci(hcd)); */
  123. retval =
  124. usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED | IRQF_SHARED);
  125. if (retval == 0)
  126. return retval;
  127. au1xxx_stop_ehc(dev);
  128. iounmap(hcd->regs);
  129. err2:
  130. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  131. err1:
  132. usb_put_hcd(hcd);
  133. return retval;
  134. }
  135. /* may be called without controller electrically present */
  136. /* may be called with controller, bus, and devices active */
  137. /**
  138. * usb_ehci_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs
  139. * @dev: USB Host Controller being removed
  140. * Context: !in_interrupt()
  141. *
  142. * Reverses the effect of usb_ehci_hcd_au1xxx_probe(), first invoking
  143. * the HCD's stop() method. It is always called from a thread
  144. * context, normally "rmmod", "apmd", or something similar.
  145. *
  146. */
  147. void usb_ehci_au1xxx_remove(struct usb_hcd *hcd, struct platform_device *dev)
  148. {
  149. usb_remove_hcd(hcd);
  150. iounmap(hcd->regs);
  151. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  152. usb_put_hcd(hcd);
  153. au1xxx_stop_ehc(dev);
  154. }
  155. /*-------------------------------------------------------------------------*/
  156. static const struct hc_driver ehci_au1xxx_hc_driver = {
  157. .description = hcd_name,
  158. .product_desc = "Au1xxx EHCI",
  159. .hcd_priv_size = sizeof(struct ehci_hcd),
  160. /*
  161. * generic hardware linkage
  162. */
  163. .irq = ehci_irq,
  164. .flags = HCD_MEMORY | HCD_USB2,
  165. /*
  166. * basic lifecycle operations
  167. *
  168. * FIXME -- ehci_init() doesn't do enough here.
  169. * See ehci-ppc-soc for a complete implementation.
  170. */
  171. .reset = ehci_init,
  172. .start = ehci_run,
  173. .stop = ehci_stop,
  174. .shutdown = ehci_shutdown,
  175. /*
  176. * managing i/o requests and associated device resources
  177. */
  178. .urb_enqueue = ehci_urb_enqueue,
  179. .urb_dequeue = ehci_urb_dequeue,
  180. .endpoint_disable = ehci_endpoint_disable,
  181. /*
  182. * scheduling support
  183. */
  184. .get_frame_number = ehci_get_frame,
  185. /*
  186. * root hub support
  187. */
  188. .hub_status_data = ehci_hub_status_data,
  189. .hub_control = ehci_hub_control,
  190. .bus_suspend = ehci_bus_suspend,
  191. .bus_resume = ehci_bus_resume,
  192. };
  193. /*-------------------------------------------------------------------------*/
  194. static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
  195. {
  196. struct usb_hcd *hcd = NULL;
  197. int ret;
  198. pr_debug("In ehci_hcd_au1xxx_drv_probe\n");
  199. if (usb_disabled())
  200. return -ENODEV;
  201. ret = usb_ehci_au1xxx_probe(&ehci_au1xxx_hc_driver, &hcd, pdev);
  202. return ret;
  203. }
  204. static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
  205. {
  206. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  207. usb_ehci_au1xxx_remove(hcd, pdev);
  208. return 0;
  209. }
  210. /*TBD*/
  211. /*static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
  212. {
  213. struct platform_device *pdev = to_platform_device(dev);
  214. struct usb_hcd *hcd = dev_get_drvdata(dev);
  215. return 0;
  216. }
  217. static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
  218. {
  219. struct platform_device *pdev = to_platform_device(dev);
  220. struct usb_hcd *hcd = dev_get_drvdata(dev);
  221. return 0;
  222. }
  223. */
  224. MODULE_ALIAS("au1xxx-ehci");
  225. static struct platform_driver ehci_hcd_au1xxx_driver = {
  226. .probe = ehci_hcd_au1xxx_drv_probe,
  227. .remove = ehci_hcd_au1xxx_drv_remove,
  228. .shutdown = usb_hcd_platform_shutdown,
  229. /*.suspend = ehci_hcd_au1xxx_drv_suspend, */
  230. /*.resume = ehci_hcd_au1xxx_drv_resume, */
  231. .driver = {
  232. .name = "au1xxx-ehci",
  233. .bus = &platform_bus_type
  234. }
  235. };