ehci-au1xxx.c 7.4 KB

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