ohci-au1xxx.c 7.0 KB

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