ohci-au1xxx.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. #ifndef CONFIG_SOC_AU1200
  86. /* wait for reset complete (read register twice; see au1500 errata) */
  87. while (au_readl(USB_HOST_CONFIG),
  88. !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD))
  89. #endif
  90. udelay(1000);
  91. printk(KERN_DEBUG __FILE__
  92. ": Clock to USB host has been enabled \n");
  93. #endif
  94. }
  95. static void au1xxx_stop_ohc(struct platform_device *dev)
  96. {
  97. printk(KERN_DEBUG __FILE__
  98. ": stopping Au1xxx OHCI USB Controller\n");
  99. #ifndef CONFIG_SOC_AU1200
  100. /* Disable clock */
  101. au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
  102. #else /* Au1200 */
  103. /* Disable mem */
  104. au_writel(~USBH_DISABLE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
  105. udelay(1000);
  106. /* Disable clock */
  107. au_writel(~USBH_ENABLE_CE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
  108. au_readl(USB_HOST_CONFIG);
  109. #endif /* Au1200 */
  110. }
  111. /*-------------------------------------------------------------------------*/
  112. /* configure so an HC device and id are always provided */
  113. /* always called with process context; sleeping is OK */
  114. /**
  115. * usb_ohci_au1xxx_probe - initialize Au1xxx-based HCDs
  116. * Context: !in_interrupt()
  117. *
  118. * Allocates basic resources for this USB host controller, and
  119. * then invokes the start() method for the HCD associated with it
  120. * through the hotplug entry's driver_data.
  121. *
  122. */
  123. static int usb_ohci_au1xxx_probe(const struct hc_driver *driver,
  124. struct platform_device *dev)
  125. {
  126. int retval;
  127. struct usb_hcd *hcd;
  128. #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
  129. /* Au1200 AB USB does not support coherent memory */
  130. if (!(read_c0_prid() & 0xff)) {
  131. pr_info("%s: this is chip revision AB !!\n",
  132. dev->name);
  133. pr_info("%s: update your board or re-configure the kernel\n",
  134. dev->name);
  135. return -ENODEV;
  136. }
  137. #endif
  138. if (dev->resource[1].flags != IORESOURCE_IRQ) {
  139. pr_debug("resource[1] is not IORESOURCE_IRQ\n");
  140. return -ENOMEM;
  141. }
  142. hcd = usb_create_hcd(driver, &dev->dev, "au1xxx");
  143. if (!hcd)
  144. return -ENOMEM;
  145. hcd->rsrc_start = dev->resource[0].start;
  146. hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
  147. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  148. pr_debug("request_mem_region failed\n");
  149. retval = -EBUSY;
  150. goto err1;
  151. }
  152. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  153. if (!hcd->regs) {
  154. pr_debug("ioremap failed\n");
  155. retval = -ENOMEM;
  156. goto err2;
  157. }
  158. au1xxx_start_ohc(dev);
  159. ohci_hcd_init(hcd_to_ohci(hcd));
  160. retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED | IRQF_SHARED);
  161. if (retval == 0)
  162. return retval;
  163. au1xxx_stop_ohc(dev);
  164. iounmap(hcd->regs);
  165. err2:
  166. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  167. err1:
  168. usb_put_hcd(hcd);
  169. return retval;
  170. }
  171. /* may be called without controller electrically present */
  172. /* may be called with controller, bus, and devices active */
  173. /**
  174. * usb_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs
  175. * @dev: USB Host Controller being removed
  176. * Context: !in_interrupt()
  177. *
  178. * Reverses the effect of usb_hcd_au1xxx_probe(), first invoking
  179. * the HCD's stop() method. It is always called from a thread
  180. * context, normally "rmmod", "apmd", or something similar.
  181. *
  182. */
  183. static void usb_ohci_au1xxx_remove(struct usb_hcd *hcd, struct platform_device *dev)
  184. {
  185. usb_remove_hcd(hcd);
  186. au1xxx_stop_ohc(dev);
  187. iounmap(hcd->regs);
  188. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  189. usb_put_hcd(hcd);
  190. }
  191. /*-------------------------------------------------------------------------*/
  192. static int __devinit
  193. ohci_au1xxx_start (struct usb_hcd *hcd)
  194. {
  195. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  196. int ret;
  197. ohci_dbg (ohci, "ohci_au1xxx_start, ohci:%p", ohci);
  198. if ((ret = ohci_init (ohci)) < 0)
  199. return ret;
  200. if ((ret = ohci_run (ohci)) < 0) {
  201. err ("can't start %s", hcd->self.bus_name);
  202. ohci_stop (hcd);
  203. return ret;
  204. }
  205. return 0;
  206. }
  207. /*-------------------------------------------------------------------------*/
  208. static const struct hc_driver ohci_au1xxx_hc_driver = {
  209. .description = hcd_name,
  210. .product_desc = "Au1xxx OHCI",
  211. .hcd_priv_size = sizeof(struct ohci_hcd),
  212. /*
  213. * generic hardware linkage
  214. */
  215. .irq = ohci_irq,
  216. .flags = HCD_USB11 | HCD_MEMORY,
  217. /*
  218. * basic lifecycle operations
  219. */
  220. .start = ohci_au1xxx_start,
  221. #ifdef CONFIG_PM
  222. /* suspend: ohci_au1xxx_suspend, -- tbd */
  223. /* resume: ohci_au1xxx_resume, -- tbd */
  224. #endif /*CONFIG_PM*/
  225. .stop = ohci_stop,
  226. /*
  227. * managing i/o requests and associated device resources
  228. */
  229. .urb_enqueue = ohci_urb_enqueue,
  230. .urb_dequeue = ohci_urb_dequeue,
  231. .endpoint_disable = ohci_endpoint_disable,
  232. /*
  233. * scheduling support
  234. */
  235. .get_frame_number = ohci_get_frame,
  236. /*
  237. * root hub support
  238. */
  239. .hub_status_data = ohci_hub_status_data,
  240. .hub_control = ohci_hub_control,
  241. #ifdef CONFIG_PM
  242. .bus_suspend = ohci_bus_suspend,
  243. .bus_resume = ohci_bus_resume,
  244. #endif
  245. .start_port_reset = ohci_start_port_reset,
  246. };
  247. /*-------------------------------------------------------------------------*/
  248. static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
  249. {
  250. int ret;
  251. pr_debug ("In ohci_hcd_au1xxx_drv_probe");
  252. if (usb_disabled())
  253. return -ENODEV;
  254. ret = usb_ohci_au1xxx_probe(&ohci_au1xxx_hc_driver, pdev);
  255. return ret;
  256. }
  257. static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
  258. {
  259. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  260. usb_ohci_au1xxx_remove(hcd, pdev);
  261. return 0;
  262. }
  263. /*TBD*/
  264. /*static int ohci_hcd_au1xxx_drv_suspend(struct platform_device *dev)
  265. {
  266. struct usb_hcd *hcd = platform_get_drvdata(dev);
  267. return 0;
  268. }
  269. static int ohci_hcd_au1xxx_drv_resume(struct platform_device *dev)
  270. {
  271. struct usb_hcd *hcd = platform_get_drvdata(dev);
  272. return 0;
  273. }
  274. */
  275. static struct platform_driver ohci_hcd_au1xxx_driver = {
  276. .probe = ohci_hcd_au1xxx_drv_probe,
  277. .remove = ohci_hcd_au1xxx_drv_remove,
  278. /*.suspend = ohci_hcd_au1xxx_drv_suspend, */
  279. /*.resume = ohci_hcd_au1xxx_drv_resume, */
  280. .driver = {
  281. .name = "au1xxx-ohci",
  282. .owner = THIS_MODULE,
  283. },
  284. };
  285. static int __init ohci_hcd_au1xxx_init (void)
  286. {
  287. pr_debug (DRIVER_INFO " (Au1xxx)");
  288. pr_debug ("block sizes: ed %d td %d\n",
  289. sizeof (struct ed), sizeof (struct td));
  290. return platform_driver_register(&ohci_hcd_au1xxx_driver);
  291. }
  292. static void __exit ohci_hcd_au1xxx_cleanup (void)
  293. {
  294. platform_driver_unregister(&ohci_hcd_au1xxx_driver);
  295. }
  296. module_init (ohci_hcd_au1xxx_init);
  297. module_exit (ohci_hcd_au1xxx_cleanup);