ohci-au1xxx.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 <asm/mach-au1x00/au1000.h>
  21. #define USBH_ENABLE_BE (1<<0)
  22. #define USBH_ENABLE_C (1<<1)
  23. #define USBH_ENABLE_E (1<<2)
  24. #define USBH_ENABLE_CE (1<<3)
  25. #define USBH_ENABLE_RD (1<<4)
  26. #ifdef __LITTLE_ENDIAN
  27. #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C)
  28. #elif __BIG_ENDIAN
  29. #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | USBH_ENABLE_BE)
  30. #else
  31. #error not byte order defined
  32. #endif
  33. extern int usb_disabled(void);
  34. /*-------------------------------------------------------------------------*/
  35. static void au1xxx_start_hc(struct platform_device *dev)
  36. {
  37. printk(KERN_DEBUG __FILE__
  38. ": starting Au1xxx OHCI USB Controller\n");
  39. /* enable host controller */
  40. au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG);
  41. udelay(1000);
  42. au_writel(USBH_ENABLE_INIT, USB_HOST_CONFIG);
  43. udelay(1000);
  44. /* wait for reset complete (read register twice; see au1500 errata) */
  45. while (au_readl(USB_HOST_CONFIG),
  46. !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD))
  47. udelay(1000);
  48. printk(KERN_DEBUG __FILE__
  49. ": Clock to USB host has been enabled \n");
  50. }
  51. static void au1xxx_stop_hc(struct platform_device *dev)
  52. {
  53. printk(KERN_DEBUG __FILE__
  54. ": stopping Au1xxx OHCI USB Controller\n");
  55. /* Disable clock */
  56. au_writel(readl((void *)USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
  57. }
  58. /*-------------------------------------------------------------------------*/
  59. /* configure so an HC device and id are always provided */
  60. /* always called with process context; sleeping is OK */
  61. /**
  62. * usb_hcd_au1xxx_probe - initialize Au1xxx-based HCDs
  63. * Context: !in_interrupt()
  64. *
  65. * Allocates basic resources for this USB host controller, and
  66. * then invokes the start() method for the HCD associated with it
  67. * through the hotplug entry's driver_data.
  68. *
  69. */
  70. int usb_hcd_au1xxx_probe (const struct hc_driver *driver,
  71. struct platform_device *dev)
  72. {
  73. int retval;
  74. struct usb_hcd *hcd;
  75. if(dev->resource[1].flags != IORESOURCE_IRQ) {
  76. pr_debug ("resource[1] is not IORESOURCE_IRQ");
  77. return -ENOMEM;
  78. }
  79. hcd = usb_create_hcd(driver, &dev->dev, "au1xxx");
  80. if (!hcd)
  81. return -ENOMEM;
  82. hcd->rsrc_start = dev->resource[0].start;
  83. hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
  84. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  85. pr_debug("request_mem_region failed");
  86. retval = -EBUSY;
  87. goto err1;
  88. }
  89. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  90. if (!hcd->regs) {
  91. pr_debug("ioremap failed");
  92. retval = -ENOMEM;
  93. goto err2;
  94. }
  95. au1xxx_start_hc(dev);
  96. ohci_hcd_init(hcd_to_ohci(hcd));
  97. retval = usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT);
  98. if (retval == 0)
  99. return retval;
  100. au1xxx_stop_hc(dev);
  101. iounmap(hcd->regs);
  102. err2:
  103. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  104. err1:
  105. usb_put_hcd(hcd);
  106. return retval;
  107. }
  108. /* may be called without controller electrically present */
  109. /* may be called with controller, bus, and devices active */
  110. /**
  111. * usb_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs
  112. * @dev: USB Host Controller being removed
  113. * Context: !in_interrupt()
  114. *
  115. * Reverses the effect of usb_hcd_au1xxx_probe(), first invoking
  116. * the HCD's stop() method. It is always called from a thread
  117. * context, normally "rmmod", "apmd", or something similar.
  118. *
  119. */
  120. void usb_hcd_au1xxx_remove (struct usb_hcd *hcd, struct platform_device *dev)
  121. {
  122. usb_remove_hcd(hcd);
  123. au1xxx_stop_hc(dev);
  124. iounmap(hcd->regs);
  125. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  126. usb_put_hcd(hcd);
  127. }
  128. /*-------------------------------------------------------------------------*/
  129. static int __devinit
  130. ohci_au1xxx_start (struct usb_hcd *hcd)
  131. {
  132. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  133. int ret;
  134. ohci_dbg (ohci, "ohci_au1xxx_start, ohci:%p", ohci);
  135. if ((ret = ohci_init (ohci)) < 0)
  136. return ret;
  137. if ((ret = ohci_run (ohci)) < 0) {
  138. err ("can't start %s", hcd->self.bus_name);
  139. ohci_stop (hcd);
  140. return ret;
  141. }
  142. return 0;
  143. }
  144. /*-------------------------------------------------------------------------*/
  145. static const struct hc_driver ohci_au1xxx_hc_driver = {
  146. .description = hcd_name,
  147. .product_desc = "Au1xxx OHCI",
  148. .hcd_priv_size = sizeof(struct ohci_hcd),
  149. /*
  150. * generic hardware linkage
  151. */
  152. .irq = ohci_irq,
  153. .flags = HCD_USB11 | HCD_MEMORY,
  154. /*
  155. * basic lifecycle operations
  156. */
  157. .start = ohci_au1xxx_start,
  158. #ifdef CONFIG_PM
  159. /* suspend: ohci_au1xxx_suspend, -- tbd */
  160. /* resume: ohci_au1xxx_resume, -- tbd */
  161. #endif /*CONFIG_PM*/
  162. .stop = ohci_stop,
  163. /*
  164. * managing i/o requests and associated device resources
  165. */
  166. .urb_enqueue = ohci_urb_enqueue,
  167. .urb_dequeue = ohci_urb_dequeue,
  168. .endpoint_disable = ohci_endpoint_disable,
  169. /*
  170. * scheduling support
  171. */
  172. .get_frame_number = ohci_get_frame,
  173. /*
  174. * root hub support
  175. */
  176. .hub_status_data = ohci_hub_status_data,
  177. .hub_control = ohci_hub_control,
  178. };
  179. /*-------------------------------------------------------------------------*/
  180. static int ohci_hcd_au1xxx_drv_probe(struct device *dev)
  181. {
  182. struct platform_device *pdev = to_platform_device(dev);
  183. int ret;
  184. pr_debug ("In ohci_hcd_au1xxx_drv_probe");
  185. if (usb_disabled())
  186. return -ENODEV;
  187. ret = usb_hcd_au1xxx_probe(&ohci_au1xxx_hc_driver, pdev);
  188. return ret;
  189. }
  190. static int ohci_hcd_au1xxx_drv_remove(struct device *dev)
  191. {
  192. struct platform_device *pdev = to_platform_device(dev);
  193. struct usb_hcd *hcd = dev_get_drvdata(dev);
  194. usb_hcd_au1xxx_remove(hcd, pdev);
  195. return 0;
  196. }
  197. /*TBD*/
  198. /*static int ohci_hcd_au1xxx_drv_suspend(struct device *dev)
  199. {
  200. struct platform_device *pdev = to_platform_device(dev);
  201. struct usb_hcd *hcd = dev_get_drvdata(dev);
  202. return 0;
  203. }
  204. static int ohci_hcd_au1xxx_drv_resume(struct device *dev)
  205. {
  206. struct platform_device *pdev = to_platform_device(dev);
  207. struct usb_hcd *hcd = dev_get_drvdata(dev);
  208. return 0;
  209. }
  210. */
  211. static struct device_driver ohci_hcd_au1xxx_driver = {
  212. .name = "au1xxx-ohci",
  213. .bus = &platform_bus_type,
  214. .probe = ohci_hcd_au1xxx_drv_probe,
  215. .remove = ohci_hcd_au1xxx_drv_remove,
  216. /*.suspend = ohci_hcd_au1xxx_drv_suspend, */
  217. /*.resume = ohci_hcd_au1xxx_drv_resume, */
  218. };
  219. static int __init ohci_hcd_au1xxx_init (void)
  220. {
  221. pr_debug (DRIVER_INFO " (Au1xxx)");
  222. pr_debug ("block sizes: ed %d td %d\n",
  223. sizeof (struct ed), sizeof (struct td));
  224. return driver_register(&ohci_hcd_au1xxx_driver);
  225. }
  226. static void __exit ohci_hcd_au1xxx_cleanup (void)
  227. {
  228. driver_unregister(&ohci_hcd_au1xxx_driver);
  229. }
  230. module_init (ohci_hcd_au1xxx_init);
  231. module_exit (ohci_hcd_au1xxx_cleanup);