ohci-sa1111.c 6.5 KB

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