ohci-sa1111.c 6.4 KB

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