ohci-au1xxx.c 9.1 KB

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