ehci-au1xxx.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * EHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
  5. *
  6. * Bus Glue for AMD Alchemy Au1xxx
  7. *
  8. * Based on "ohci-au1xxx.c" by Matt Porter <mporter@kernel.crashing.org>
  9. *
  10. * Modified for AMD Alchemy Au1200 EHC
  11. * by K.Boge <karsten.boge@amd.com>
  12. *
  13. * This file is licenced under the GPL.
  14. */
  15. #include <linux/platform_device.h>
  16. #include <asm/mach-au1x00/au1000.h>
  17. #ifndef CONFIG_SOC_AU1200
  18. #error "this Alchemy chip doesn't have EHCI"
  19. #else /* Au1200 */
  20. #define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG)
  21. #define USB_MCFG_PFEN (1<<31)
  22. #define USB_MCFG_RDCOMB (1<<30)
  23. #define USB_MCFG_SSDEN (1<<23)
  24. #define USB_MCFG_PHYPLLEN (1<<19)
  25. #define USB_MCFG_EHCCLKEN (1<<17)
  26. #define USB_MCFG_UCAM (1<<7)
  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. #ifdef CONFIG_DMA_COHERENT
  31. #define USBH_ENABLE_INIT (USBH_ENABLE_CE \
  32. | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
  33. | USB_MCFG_SSDEN | USB_MCFG_UCAM \
  34. | USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
  35. #else
  36. #define USBH_ENABLE_INIT (USBH_ENABLE_CE \
  37. | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
  38. | USB_MCFG_SSDEN \
  39. | USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
  40. #endif
  41. #define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
  42. #endif /* Au1200 */
  43. extern int usb_disabled(void);
  44. /*-------------------------------------------------------------------------*/
  45. static void au1xxx_start_ehc(struct platform_device *dev)
  46. {
  47. pr_debug(__FILE__ ": starting Au1xxx EHCI USB Controller\n");
  48. /* write HW defaults again in case Yamon cleared them */
  49. if (au_readl(USB_HOST_CONFIG) == 0) {
  50. au_writel(0x00d02000, USB_HOST_CONFIG);
  51. au_readl(USB_HOST_CONFIG);
  52. udelay(1000);
  53. }
  54. /* enable host controller */
  55. au_writel(USBH_ENABLE_CE | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
  56. au_readl(USB_HOST_CONFIG);
  57. udelay(1000);
  58. au_writel(USBH_ENABLE_INIT | au_readl(USB_HOST_CONFIG),
  59. USB_HOST_CONFIG);
  60. au_readl(USB_HOST_CONFIG);
  61. udelay(1000);
  62. pr_debug(__FILE__ ": Clock to USB host has been enabled\n");
  63. }
  64. static void au1xxx_stop_ehc(struct platform_device *dev)
  65. {
  66. pr_debug(__FILE__ ": stopping Au1xxx EHCI USB Controller\n");
  67. /* Disable mem */
  68. au_writel(~USBH_DISABLE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
  69. udelay(1000);
  70. /* Disable clock */
  71. au_writel(~USB_MCFG_EHCCLKEN & au_readl(USB_HOST_CONFIG),
  72. USB_HOST_CONFIG);
  73. au_readl(USB_HOST_CONFIG);
  74. }
  75. /*-------------------------------------------------------------------------*/
  76. /* configure so an HC device and id are always provided */
  77. /* always called with process context; sleeping is OK */
  78. /**
  79. * usb_ehci_au1xxx_probe - initialize Au1xxx-based HCDs
  80. * Context: !in_interrupt()
  81. *
  82. * Allocates basic resources for this USB host controller, and
  83. * then invokes the start() method for the HCD associated with it
  84. * through the hotplug entry's driver_data.
  85. *
  86. */
  87. int usb_ehci_au1xxx_probe(const struct hc_driver *driver,
  88. struct usb_hcd **hcd_out, struct platform_device *dev)
  89. {
  90. int retval;
  91. struct usb_hcd *hcd;
  92. struct ehci_hcd *ehci;
  93. #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
  94. /* Au1200 AB USB does not support coherent memory */
  95. if (!(read_c0_prid() & 0xff)) {
  96. pr_info("%s: this is chip revision AB!\n", dev->dev.name);
  97. pr_info("%s: update your board or re-configure the kernel\n",
  98. dev->dev.name);
  99. return -ENODEV;
  100. }
  101. #endif
  102. au1xxx_start_ehc(dev);
  103. if (dev->resource[1].flags != IORESOURCE_IRQ) {
  104. pr_debug("resource[1] is not IORESOURCE_IRQ");
  105. retval = -ENOMEM;
  106. }
  107. hcd = usb_create_hcd(driver, &dev->dev, "Au1xxx");
  108. if (!hcd)
  109. return -ENOMEM;
  110. hcd->rsrc_start = dev->resource[0].start;
  111. hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
  112. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  113. pr_debug("request_mem_region failed");
  114. retval = -EBUSY;
  115. goto err1;
  116. }
  117. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  118. if (!hcd->regs) {
  119. pr_debug("ioremap failed");
  120. retval = -ENOMEM;
  121. goto err2;
  122. }
  123. ehci = hcd_to_ehci(hcd);
  124. ehci->caps = hcd->regs;
  125. ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
  126. /* cache this readonly data; minimize chip reads */
  127. ehci->hcs_params = readl(&ehci->caps->hcs_params);
  128. /* ehci_hcd_init(hcd_to_ehci(hcd)); */
  129. retval =
  130. usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT | SA_SHIRQ);
  131. if (retval == 0)
  132. return retval;
  133. au1xxx_stop_ehc(dev);
  134. iounmap(hcd->regs);
  135. err2:
  136. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  137. err1:
  138. usb_put_hcd(hcd);
  139. return retval;
  140. }
  141. /* may be called without controller electrically present */
  142. /* may be called with controller, bus, and devices active */
  143. /**
  144. * usb_ehci_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs
  145. * @dev: USB Host Controller being removed
  146. * Context: !in_interrupt()
  147. *
  148. * Reverses the effect of usb_ehci_hcd_au1xxx_probe(), first invoking
  149. * the HCD's stop() method. It is always called from a thread
  150. * context, normally "rmmod", "apmd", or something similar.
  151. *
  152. */
  153. void usb_ehci_au1xxx_remove(struct usb_hcd *hcd, struct platform_device *dev)
  154. {
  155. usb_remove_hcd(hcd);
  156. iounmap(hcd->regs);
  157. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  158. usb_put_hcd(hcd);
  159. au1xxx_stop_ehc(dev);
  160. }
  161. /*-------------------------------------------------------------------------*/
  162. static const struct hc_driver ehci_au1xxx_hc_driver = {
  163. .description = hcd_name,
  164. .product_desc = "Au1xxx EHCI",
  165. .hcd_priv_size = sizeof(struct ehci_hcd),
  166. /*
  167. * generic hardware linkage
  168. */
  169. .irq = ehci_irq,
  170. .flags = HCD_MEMORY | HCD_USB2,
  171. /*
  172. * basic lifecycle operations
  173. */
  174. .reset = ehci_init,
  175. .start = ehci_run,
  176. .stop = ehci_stop,
  177. /*
  178. * managing i/o requests and associated device resources
  179. */
  180. .urb_enqueue = ehci_urb_enqueue,
  181. .urb_dequeue = ehci_urb_dequeue,
  182. .endpoint_disable = ehci_endpoint_disable,
  183. /*
  184. * scheduling support
  185. */
  186. .get_frame_number = ehci_get_frame,
  187. /*
  188. * root hub support
  189. */
  190. .hub_status_data = ehci_hub_status_data,
  191. .hub_control = ehci_hub_control,
  192. #ifdef CONFIG_PM
  193. .hub_suspend = ehci_hub_suspend,
  194. .hub_resume = ehci_hub_resume,
  195. #endif
  196. };
  197. /*-------------------------------------------------------------------------*/
  198. static int ehci_hcd_au1xxx_drv_probe(struct device *dev)
  199. {
  200. struct platform_device *pdev = to_platform_device(dev);
  201. struct usb_hcd *hcd = NULL;
  202. int ret;
  203. pr_debug("In ehci_hcd_au1xxx_drv_probe\n");
  204. if (usb_disabled())
  205. return -ENODEV;
  206. ret = usb_ehci_au1xxx_probe(&ehci_au1xxx_hc_driver, &hcd, pdev);
  207. return ret;
  208. }
  209. static int ehci_hcd_au1xxx_drv_remove(struct device *dev)
  210. {
  211. struct platform_device *pdev = to_platform_device(dev);
  212. struct usb_hcd *hcd = dev_get_drvdata(dev);
  213. usb_ehci_au1xxx_remove(hcd, pdev);
  214. return 0;
  215. }
  216. /*TBD*/
  217. /*static int ehci_hcd_au1xxx_drv_suspend(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. static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
  224. {
  225. struct platform_device *pdev = to_platform_device(dev);
  226. struct usb_hcd *hcd = dev_get_drvdata(dev);
  227. return 0;
  228. }
  229. */
  230. static struct device_driver ehci_hcd_au1xxx_driver = {
  231. .name = "au1xxx-ehci",
  232. .bus = &platform_bus_type,
  233. .probe = ehci_hcd_au1xxx_drv_probe,
  234. .remove = ehci_hcd_au1xxx_drv_remove,
  235. /*.suspend = ehci_hcd_au1xxx_drv_suspend, */
  236. /*.resume = ehci_hcd_au1xxx_drv_resume, */
  237. };
  238. static int __init ehci_hcd_au1xxx_init(void)
  239. {
  240. pr_debug(DRIVER_INFO " (Au1xxx)\n");
  241. return driver_register(&ehci_hcd_au1xxx_driver);
  242. }
  243. static void __exit ehci_hcd_au1xxx_cleanup(void)
  244. {
  245. driver_unregister(&ehci_hcd_au1xxx_driver);
  246. }
  247. module_init(ehci_hcd_au1xxx_init);
  248. module_exit(ehci_hcd_au1xxx_cleanup);