ehci-au1xxx.c 7.3 KB

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