ohci-sa1111.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. * SA1111 Bus Glue
  9. *
  10. * Written by Christopher Hoover <ch@hpl.hp.com>
  11. * Based on fragments of previous driver by Russell King et al.
  12. *
  13. * This file is licenced under the GPL.
  14. */
  15. #include <mach/hardware.h>
  16. #include <asm/mach-types.h>
  17. #include <mach/assabet.h>
  18. #include <asm/hardware/sa1111.h>
  19. #ifndef CONFIG_SA1111
  20. #error "This file is SA-1111 bus glue. CONFIG_SA1111 must be defined."
  21. #endif
  22. #define USB_STATUS 0x0118
  23. #define USB_RESET 0x011c
  24. #define USB_IRQTEST 0x0120
  25. #define USB_RESET_FORCEIFRESET (1 << 0)
  26. #define USB_RESET_FORCEHCRESET (1 << 1)
  27. #define USB_RESET_CLKGENRESET (1 << 2)
  28. #define USB_RESET_SIMSCALEDOWN (1 << 3)
  29. #define USB_RESET_USBINTTEST (1 << 4)
  30. #define USB_RESET_SLEEPSTBYEN (1 << 5)
  31. #define USB_RESET_PWRSENSELOW (1 << 6)
  32. #define USB_RESET_PWRCTRLLOW (1 << 7)
  33. #define USB_STATUS_IRQHCIRMTWKUP (1 << 7)
  34. #define USB_STATUS_IRQHCIBUFFACC (1 << 8)
  35. #define USB_STATUS_NIRQHCIM (1 << 9)
  36. #define USB_STATUS_NHCIMFCLR (1 << 10)
  37. #define USB_STATUS_USBPWRSENSE (1 << 11)
  38. extern int usb_disabled(void);
  39. /*-------------------------------------------------------------------------*/
  40. static int sa1111_start_hc(struct sa1111_dev *dev)
  41. {
  42. unsigned int usb_rst = 0;
  43. int ret;
  44. printk(KERN_DEBUG "%s: starting SA-1111 OHCI USB Controller\n",
  45. __FILE__);
  46. if (machine_is_xp860() ||
  47. machine_has_neponset() ||
  48. machine_is_pfs168() ||
  49. machine_is_badge4())
  50. usb_rst = USB_RESET_PWRSENSELOW | USB_RESET_PWRCTRLLOW;
  51. /*
  52. * Configure the power sense and control lines. Place the USB
  53. * host controller in reset.
  54. */
  55. sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
  56. dev->mapbase + USB_RESET);
  57. /*
  58. * Now, carefully enable the USB clock, and take
  59. * the USB host controller out of reset.
  60. */
  61. ret = sa1111_enable_device(dev);
  62. if (ret == 0) {
  63. udelay(11);
  64. sa1111_writel(usb_rst, dev->mapbase + USB_RESET);
  65. }
  66. return ret;
  67. }
  68. static void sa1111_stop_hc(struct sa1111_dev *dev)
  69. {
  70. unsigned int usb_rst;
  71. printk(KERN_DEBUG "%s: stopping SA-1111 OHCI USB Controller\n",
  72. __FILE__);
  73. /*
  74. * Put the USB host controller into reset.
  75. */
  76. usb_rst = sa1111_readl(dev->mapbase + USB_RESET);
  77. sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
  78. dev->mapbase + USB_RESET);
  79. /*
  80. * Stop the USB clock.
  81. */
  82. sa1111_disable_device(dev);
  83. }
  84. /*-------------------------------------------------------------------------*/
  85. #if 0
  86. static void dump_hci_status(struct usb_hcd *hcd, const char *label)
  87. {
  88. unsigned long status = sa1111_readl(hcd->regs + USB_STATUS);
  89. dbg ("%s USB_STATUS = { %s%s%s%s%s}", label,
  90. ((status & USB_STATUS_IRQHCIRMTWKUP) ? "IRQHCIRMTWKUP " : ""),
  91. ((status & USB_STATUS_IRQHCIBUFFACC) ? "IRQHCIBUFFACC " : ""),
  92. ((status & USB_STATUS_NIRQHCIM) ? "" : "IRQHCIM "),
  93. ((status & USB_STATUS_NHCIMFCLR) ? "" : "HCIMFCLR "),
  94. ((status & USB_STATUS_USBPWRSENSE) ? "USBPWRSENSE " : ""));
  95. }
  96. #endif
  97. /*-------------------------------------------------------------------------*/
  98. /* configure so an HC device and id are always provided */
  99. /* always called with process context; sleeping is OK */
  100. /**
  101. * usb_hcd_sa1111_probe - initialize SA-1111-based HCDs
  102. * Context: !in_interrupt()
  103. *
  104. * Allocates basic resources for this USB host controller, and
  105. * then invokes the start() method for the HCD associated with it
  106. * through the hotplug entry's driver_data.
  107. *
  108. * Store this function in the HCD's struct pci_driver as probe().
  109. */
  110. int usb_hcd_sa1111_probe (const struct hc_driver *driver,
  111. struct sa1111_dev *dev)
  112. {
  113. struct usb_hcd *hcd;
  114. int retval;
  115. hcd = usb_create_hcd (driver, &dev->dev, "sa1111");
  116. if (!hcd)
  117. return -ENOMEM;
  118. hcd->rsrc_start = dev->res.start;
  119. hcd->rsrc_len = resource_size(&dev->res);
  120. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  121. dbg("request_mem_region failed");
  122. retval = -EBUSY;
  123. goto err1;
  124. }
  125. hcd->regs = dev->mapbase;
  126. ret = sa1111_start_hc(dev);
  127. if (ret)
  128. goto err2;
  129. ohci_hcd_init(hcd_to_ohci(hcd));
  130. retval = usb_add_hcd(hcd, dev->irq[1], 0);
  131. if (retval == 0)
  132. return retval;
  133. sa1111_stop_hc(dev);
  134. err2:
  135. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  136. err1:
  137. usb_put_hcd(hcd);
  138. return retval;
  139. }
  140. /* may be called without controller electrically present */
  141. /* may be called with controller, bus, and devices active */
  142. /**
  143. * usb_hcd_sa1111_remove - shutdown processing for SA-1111-based HCDs
  144. * @dev: USB Host Controller being removed
  145. * Context: !in_interrupt()
  146. *
  147. * Reverses the effect of usb_hcd_sa1111_probe(), first invoking
  148. * the HCD's stop() method. It is always called from a thread
  149. * context, normally "rmmod", "apmd", or something similar.
  150. *
  151. */
  152. void usb_hcd_sa1111_remove (struct usb_hcd *hcd, struct sa1111_dev *dev)
  153. {
  154. usb_remove_hcd(hcd);
  155. sa1111_stop_hc(dev);
  156. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  157. usb_put_hcd(hcd);
  158. }
  159. /*-------------------------------------------------------------------------*/
  160. static int __devinit
  161. ohci_sa1111_start (struct usb_hcd *hcd)
  162. {
  163. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  164. int ret;
  165. if ((ret = ohci_init(ohci)) < 0)
  166. return ret;
  167. if ((ret = ohci_run (ohci)) < 0) {
  168. err ("can't start %s", hcd->self.bus_name);
  169. ohci_stop (hcd);
  170. return ret;
  171. }
  172. return 0;
  173. }
  174. /*-------------------------------------------------------------------------*/
  175. static const struct hc_driver ohci_sa1111_hc_driver = {
  176. .description = hcd_name,
  177. .product_desc = "SA-1111 OHCI",
  178. .hcd_priv_size = sizeof(struct ohci_hcd),
  179. /*
  180. * generic hardware linkage
  181. */
  182. .irq = ohci_irq,
  183. .flags = HCD_USB11 | HCD_MEMORY,
  184. /*
  185. * basic lifecycle operations
  186. */
  187. .start = ohci_sa1111_start,
  188. .stop = ohci_stop,
  189. /*
  190. * managing i/o requests and associated device resources
  191. */
  192. .urb_enqueue = ohci_urb_enqueue,
  193. .urb_dequeue = ohci_urb_dequeue,
  194. .endpoint_disable = ohci_endpoint_disable,
  195. /*
  196. * scheduling support
  197. */
  198. .get_frame_number = ohci_get_frame,
  199. /*
  200. * root hub support
  201. */
  202. .hub_status_data = ohci_hub_status_data,
  203. .hub_control = ohci_hub_control,
  204. #ifdef CONFIG_PM
  205. .bus_suspend = ohci_bus_suspend,
  206. .bus_resume = ohci_bus_resume,
  207. #endif
  208. .start_port_reset = ohci_start_port_reset,
  209. };
  210. /*-------------------------------------------------------------------------*/
  211. static int ohci_hcd_sa1111_drv_probe(struct sa1111_dev *dev)
  212. {
  213. int ret;
  214. if (usb_disabled())
  215. return -ENODEV;
  216. ret = usb_hcd_sa1111_probe(&ohci_sa1111_hc_driver, dev);
  217. return ret;
  218. }
  219. static int ohci_hcd_sa1111_drv_remove(struct sa1111_dev *dev)
  220. {
  221. struct usb_hcd *hcd = sa1111_get_drvdata(dev);
  222. usb_hcd_sa1111_remove(hcd, dev);
  223. return 0;
  224. }
  225. static struct sa1111_driver ohci_hcd_sa1111_driver = {
  226. .drv = {
  227. .name = "sa1111-ohci",
  228. .owner = THIS_MODULE,
  229. },
  230. .devid = SA1111_DEVID_USB,
  231. .probe = ohci_hcd_sa1111_drv_probe,
  232. .remove = ohci_hcd_sa1111_drv_remove,
  233. };