ohci-au1xxx.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  5. * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
  6. * (C) Copyright 2002 Hewlett-Packard Company
  7. *
  8. * Bus Glue for AMD Alchemy Au1xxx
  9. *
  10. * Written by Christopher Hoover <ch@hpl.hp.com>
  11. * Based on fragments of previous driver by Rusell King et al.
  12. *
  13. * Modified for LH7A404 from ohci-sa1111.c
  14. * by Durgesh Pattamatta <pattamattad@sharpsec.com>
  15. * Modified for AMD Alchemy Au1xxx
  16. * by Matt Porter <mporter@kernel.crashing.org>
  17. *
  18. * This file is licenced under the GPL.
  19. */
  20. #include <linux/platform_device.h>
  21. #include <linux/signal.h>
  22. #include <asm/mach-au1x00/au1000.h>
  23. #ifndef CONFIG_SOC_AU1200
  24. #define USBH_ENABLE_BE (1<<0)
  25. #define USBH_ENABLE_C (1<<1)
  26. #define USBH_ENABLE_E (1<<2)
  27. #define USBH_ENABLE_CE (1<<3)
  28. #define USBH_ENABLE_RD (1<<4)
  29. #ifdef __LITTLE_ENDIAN
  30. #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C)
  31. #elif __BIG_ENDIAN
  32. #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | USBH_ENABLE_BE)
  33. #else
  34. #error not byte order defined
  35. #endif
  36. #else /* Au1200 */
  37. #define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG)
  38. #define USB_MCFG_PFEN (1<<31)
  39. #define USB_MCFG_RDCOMB (1<<30)
  40. #define USB_MCFG_SSDEN (1<<23)
  41. #define USB_MCFG_OHCCLKEN (1<<16)
  42. #define USB_MCFG_UCAM (1<<7)
  43. #define USB_MCFG_OBMEN (1<<1)
  44. #define USB_MCFG_OMEMEN (1<<0)
  45. #define USBH_ENABLE_CE USB_MCFG_OHCCLKEN
  46. #ifdef CONFIG_DMA_COHERENT
  47. #define USBH_ENABLE_INIT (USB_MCFG_OHCCLKEN \
  48. | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
  49. | USB_MCFG_SSDEN | USB_MCFG_UCAM \
  50. | USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
  51. #else
  52. #define USBH_ENABLE_INIT (USB_MCFG_OHCCLKEN \
  53. | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
  54. | USB_MCFG_SSDEN \
  55. | USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
  56. #endif
  57. #define USBH_DISABLE (USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
  58. #endif /* Au1200 */
  59. extern int usb_disabled(void);
  60. /*-------------------------------------------------------------------------*/
  61. static void au1xxx_start_ohc(struct platform_device *dev)
  62. {
  63. printk(KERN_DEBUG __FILE__
  64. ": starting Au1xxx OHCI USB Controller\n");
  65. /* enable host controller */
  66. #ifndef CONFIG_SOC_AU1200
  67. au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG);
  68. udelay(1000);
  69. au_writel(USBH_ENABLE_INIT, USB_HOST_CONFIG);
  70. udelay(1000);
  71. #else /* Au1200 */
  72. /* write HW defaults again in case Yamon cleared them */
  73. if (au_readl(USB_HOST_CONFIG) == 0) {
  74. au_writel(0x00d02000, USB_HOST_CONFIG);
  75. au_readl(USB_HOST_CONFIG);
  76. udelay(1000);
  77. }
  78. au_writel(USBH_ENABLE_CE | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
  79. au_readl(USB_HOST_CONFIG);
  80. udelay(1000);
  81. au_writel(USBH_ENABLE_INIT | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
  82. au_readl(USB_HOST_CONFIG);
  83. udelay(1000);
  84. #endif /* Au1200 */
  85. /* wait for reset complete (read register twice; see au1500 errata) */
  86. while (au_readl(USB_HOST_CONFIG),
  87. !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD))
  88. udelay(1000);
  89. printk(KERN_DEBUG __FILE__
  90. ": Clock to USB host has been enabled \n");
  91. }
  92. static void au1xxx_stop_ohc(struct platform_device *dev)
  93. {
  94. printk(KERN_DEBUG __FILE__
  95. ": stopping Au1xxx OHCI USB Controller\n");
  96. #ifndef CONFIG_SOC_AU1200
  97. /* Disable clock */
  98. au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
  99. #else /* Au1200 */
  100. /* Disable mem */
  101. au_writel(~USBH_DISABLE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
  102. udelay(1000);
  103. /* Disable clock */
  104. au_writel(~USBH_ENABLE_CE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
  105. au_readl(USB_HOST_CONFIG);
  106. #endif /* Au1200 */
  107. }
  108. /*-------------------------------------------------------------------------*/
  109. /* configure so an HC device and id are always provided */
  110. /* always called with process context; sleeping is OK */
  111. /**
  112. * usb_ohci_au1xxx_probe - initialize Au1xxx-based HCDs
  113. * Context: !in_interrupt()
  114. *
  115. * Allocates basic resources for this USB host controller, and
  116. * then invokes the start() method for the HCD associated with it
  117. * through the hotplug entry's driver_data.
  118. *
  119. */
  120. static int usb_ohci_au1xxx_probe(const struct hc_driver *driver,
  121. struct platform_device *dev)
  122. {
  123. int retval;
  124. struct usb_hcd *hcd;
  125. #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
  126. /* Au1200 AB USB does not support coherent memory */
  127. if (!(read_c0_prid() & 0xff)) {
  128. pr_info("%s: this is chip revision AB !!\n",
  129. dev->dev.name);
  130. pr_info("%s: update your board or re-configure the kernel\n",
  131. dev->dev.name);
  132. return -ENODEV;
  133. }
  134. #endif
  135. if (dev->resource[1].flags != IORESOURCE_IRQ) {
  136. pr_debug("resource[1] is not IORESOURCE_IRQ\n");
  137. return -ENOMEM;
  138. }
  139. hcd = usb_create_hcd(driver, &dev->dev, "au1xxx");
  140. if (!hcd)
  141. return -ENOMEM;
  142. hcd->rsrc_start = dev->resource[0].start;
  143. hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
  144. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  145. pr_debug("request_mem_region failed\n");
  146. retval = -EBUSY;
  147. goto err1;
  148. }
  149. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  150. if (!hcd->regs) {
  151. pr_debug("ioremap failed\n");
  152. retval = -ENOMEM;
  153. goto err2;
  154. }
  155. au1xxx_start_ohc(dev);
  156. ohci_hcd_init(hcd_to_ohci(hcd));
  157. retval = usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT | SA_SHIRQ);
  158. if (retval == 0)
  159. return retval;
  160. au1xxx_stop_ohc(dev);
  161. iounmap(hcd->regs);
  162. err2:
  163. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  164. err1:
  165. usb_put_hcd(hcd);
  166. return retval;
  167. }
  168. /* may be called without controller electrically present */
  169. /* may be called with controller, bus, and devices active */
  170. /**
  171. * usb_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs
  172. * @dev: USB Host Controller being removed
  173. * Context: !in_interrupt()
  174. *
  175. * Reverses the effect of usb_hcd_au1xxx_probe(), first invoking
  176. * the HCD's stop() method. It is always called from a thread
  177. * context, normally "rmmod", "apmd", or something similar.
  178. *
  179. */
  180. static void usb_ohci_au1xxx_remove(struct usb_hcd *hcd, struct platform_device *dev)
  181. {
  182. usb_remove_hcd(hcd);
  183. au1xxx_stop_ohc(dev);
  184. iounmap(hcd->regs);
  185. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  186. usb_put_hcd(hcd);
  187. }
  188. /*-------------------------------------------------------------------------*/
  189. static int __devinit
  190. ohci_au1xxx_start (struct usb_hcd *hcd)
  191. {
  192. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  193. int ret;
  194. ohci_dbg (ohci, "ohci_au1xxx_start, ohci:%p", ohci);
  195. if ((ret = ohci_init (ohci)) < 0)
  196. return ret;
  197. if ((ret = ohci_run (ohci)) < 0) {
  198. err ("can't start %s", hcd->self.bus_name);
  199. ohci_stop (hcd);
  200. return ret;
  201. }
  202. return 0;
  203. }
  204. /*-------------------------------------------------------------------------*/
  205. static const struct hc_driver ohci_au1xxx_hc_driver = {
  206. .description = hcd_name,
  207. .product_desc = "Au1xxx OHCI",
  208. .hcd_priv_size = sizeof(struct ohci_hcd),
  209. /*
  210. * generic hardware linkage
  211. */
  212. .irq = ohci_irq,
  213. .flags = HCD_USB11 | HCD_MEMORY,
  214. /*
  215. * basic lifecycle operations
  216. */
  217. .start = ohci_au1xxx_start,
  218. #ifdef CONFIG_PM
  219. /* suspend: ohci_au1xxx_suspend, -- tbd */
  220. /* resume: ohci_au1xxx_resume, -- tbd */
  221. #endif /*CONFIG_PM*/
  222. .stop = ohci_stop,
  223. /*
  224. * managing i/o requests and associated device resources
  225. */
  226. .urb_enqueue = ohci_urb_enqueue,
  227. .urb_dequeue = ohci_urb_dequeue,
  228. .endpoint_disable = ohci_endpoint_disable,
  229. /*
  230. * scheduling support
  231. */
  232. .get_frame_number = ohci_get_frame,
  233. /*
  234. * root hub support
  235. */
  236. .hub_status_data = ohci_hub_status_data,
  237. .hub_control = ohci_hub_control,
  238. #ifdef CONFIG_PM
  239. .bus_suspend = ohci_bus_suspend,
  240. .bus_resume = ohci_bus_resume,
  241. #endif
  242. .start_port_reset = ohci_start_port_reset,
  243. };
  244. /*-------------------------------------------------------------------------*/
  245. static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
  246. {
  247. int ret;
  248. pr_debug ("In ohci_hcd_au1xxx_drv_probe");
  249. if (usb_disabled())
  250. return -ENODEV;
  251. ret = usb_ohci_au1xxx_probe(&ohci_au1xxx_hc_driver, pdev);
  252. return ret;
  253. }
  254. static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
  255. {
  256. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  257. usb_ohci_au1xxx_remove(hcd, pdev);
  258. return 0;
  259. }
  260. /*TBD*/
  261. /*static int ohci_hcd_au1xxx_drv_suspend(struct platform_device *dev)
  262. {
  263. struct usb_hcd *hcd = platform_get_drvdata(dev);
  264. return 0;
  265. }
  266. static int ohci_hcd_au1xxx_drv_resume(struct platform_device *dev)
  267. {
  268. struct usb_hcd *hcd = platform_get_drvdata(dev);
  269. return 0;
  270. }
  271. */
  272. static struct platform_driver ohci_hcd_au1xxx_driver = {
  273. .probe = ohci_hcd_au1xxx_drv_probe,
  274. .remove = ohci_hcd_au1xxx_drv_remove,
  275. /*.suspend = ohci_hcd_au1xxx_drv_suspend, */
  276. /*.resume = ohci_hcd_au1xxx_drv_resume, */
  277. .driver = {
  278. .name = "au1xxx-ohci",
  279. .owner = THIS_MODULE,
  280. },
  281. };
  282. static int __init ohci_hcd_au1xxx_init (void)
  283. {
  284. pr_debug (DRIVER_INFO " (Au1xxx)");
  285. pr_debug ("block sizes: ed %d td %d\n",
  286. sizeof (struct ed), sizeof (struct td));
  287. return platform_driver_register(&ohci_hcd_au1xxx_driver);
  288. }
  289. static void __exit ohci_hcd_au1xxx_cleanup (void)
  290. {
  291. platform_driver_unregister(&ohci_hcd_au1xxx_driver);
  292. }
  293. module_init (ohci_hcd_au1xxx_init);
  294. module_exit (ohci_hcd_au1xxx_cleanup);