ohci-au1xxx.c 7.0 KB

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