ohci-sa1111.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 <asm/mach-types.h>
  16. #include <asm/hardware/sa1111.h>
  17. #ifndef CONFIG_SA1111
  18. #error "This file is SA-1111 bus glue. CONFIG_SA1111 must be defined."
  19. #endif
  20. #define USB_STATUS 0x0118
  21. #define USB_RESET 0x011c
  22. #define USB_IRQTEST 0x0120
  23. #define USB_RESET_FORCEIFRESET (1 << 0)
  24. #define USB_RESET_FORCEHCRESET (1 << 1)
  25. #define USB_RESET_CLKGENRESET (1 << 2)
  26. #define USB_RESET_SIMSCALEDOWN (1 << 3)
  27. #define USB_RESET_USBINTTEST (1 << 4)
  28. #define USB_RESET_SLEEPSTBYEN (1 << 5)
  29. #define USB_RESET_PWRSENSELOW (1 << 6)
  30. #define USB_RESET_PWRCTRLLOW (1 << 7)
  31. #define USB_STATUS_IRQHCIRMTWKUP (1 << 7)
  32. #define USB_STATUS_IRQHCIBUFFACC (1 << 8)
  33. #define USB_STATUS_NIRQHCIM (1 << 9)
  34. #define USB_STATUS_NHCIMFCLR (1 << 10)
  35. #define USB_STATUS_USBPWRSENSE (1 << 11)
  36. #if 0
  37. static void dump_hci_status(struct usb_hcd *hcd, const char *label)
  38. {
  39. unsigned long status = sa1111_readl(hcd->regs + USB_STATUS);
  40. printk(KERN_DEBUG "%s USB_STATUS = { %s%s%s%s%s}\n", label,
  41. ((status & USB_STATUS_IRQHCIRMTWKUP) ? "IRQHCIRMTWKUP " : ""),
  42. ((status & USB_STATUS_IRQHCIBUFFACC) ? "IRQHCIBUFFACC " : ""),
  43. ((status & USB_STATUS_NIRQHCIM) ? "" : "IRQHCIM "),
  44. ((status & USB_STATUS_NHCIMFCLR) ? "" : "HCIMFCLR "),
  45. ((status & USB_STATUS_USBPWRSENSE) ? "USBPWRSENSE " : ""));
  46. }
  47. #endif
  48. static int ohci_sa1111_reset(struct usb_hcd *hcd)
  49. {
  50. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  51. ohci_hcd_init(ohci);
  52. return ohci_init(ohci);
  53. }
  54. static int ohci_sa1111_start(struct usb_hcd *hcd)
  55. {
  56. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  57. int ret;
  58. ret = ohci_run(ohci);
  59. if (ret < 0) {
  60. ohci_err(ohci, "can't start\n");
  61. ohci_stop(hcd);
  62. }
  63. return ret;
  64. }
  65. static const struct hc_driver ohci_sa1111_hc_driver = {
  66. .description = hcd_name,
  67. .product_desc = "SA-1111 OHCI",
  68. .hcd_priv_size = sizeof(struct ohci_hcd),
  69. /*
  70. * generic hardware linkage
  71. */
  72. .irq = ohci_irq,
  73. .flags = HCD_USB11 | HCD_MEMORY,
  74. /*
  75. * basic lifecycle operations
  76. */
  77. .reset = ohci_sa1111_reset,
  78. .start = ohci_sa1111_start,
  79. .stop = ohci_stop,
  80. .shutdown = ohci_shutdown,
  81. /*
  82. * managing i/o requests and associated device resources
  83. */
  84. .urb_enqueue = ohci_urb_enqueue,
  85. .urb_dequeue = ohci_urb_dequeue,
  86. .endpoint_disable = ohci_endpoint_disable,
  87. /*
  88. * scheduling support
  89. */
  90. .get_frame_number = ohci_get_frame,
  91. /*
  92. * root hub support
  93. */
  94. .hub_status_data = ohci_hub_status_data,
  95. .hub_control = ohci_hub_control,
  96. #ifdef CONFIG_PM
  97. .bus_suspend = ohci_bus_suspend,
  98. .bus_resume = ohci_bus_resume,
  99. #endif
  100. .start_port_reset = ohci_start_port_reset,
  101. };
  102. static int sa1111_start_hc(struct sa1111_dev *dev)
  103. {
  104. unsigned int usb_rst = 0;
  105. int ret;
  106. dev_dbg(&dev->dev, "starting SA-1111 OHCI USB Controller\n");
  107. if (machine_is_xp860() ||
  108. machine_is_assabet() ||
  109. machine_is_pfs168() ||
  110. machine_is_badge4())
  111. usb_rst = USB_RESET_PWRSENSELOW | USB_RESET_PWRCTRLLOW;
  112. /*
  113. * Configure the power sense and control lines. Place the USB
  114. * host controller in reset.
  115. */
  116. sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
  117. dev->mapbase + USB_RESET);
  118. /*
  119. * Now, carefully enable the USB clock, and take
  120. * the USB host controller out of reset.
  121. */
  122. ret = sa1111_enable_device(dev);
  123. if (ret == 0) {
  124. udelay(11);
  125. sa1111_writel(usb_rst, dev->mapbase + USB_RESET);
  126. }
  127. return ret;
  128. }
  129. static void sa1111_stop_hc(struct sa1111_dev *dev)
  130. {
  131. unsigned int usb_rst;
  132. dev_dbg(&dev->dev, "stopping SA-1111 OHCI USB Controller\n");
  133. /*
  134. * Put the USB host controller into reset.
  135. */
  136. usb_rst = sa1111_readl(dev->mapbase + USB_RESET);
  137. sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
  138. dev->mapbase + USB_RESET);
  139. /*
  140. * Stop the USB clock.
  141. */
  142. sa1111_disable_device(dev);
  143. }
  144. /**
  145. * ohci_hcd_sa1111_probe - initialize SA-1111-based HCDs
  146. *
  147. * Allocates basic resources for this USB host controller, and
  148. * then invokes the start() method for the HCD associated with it.
  149. */
  150. static int ohci_hcd_sa1111_probe(struct sa1111_dev *dev)
  151. {
  152. struct usb_hcd *hcd;
  153. int ret;
  154. if (usb_disabled())
  155. return -ENODEV;
  156. /*
  157. * We don't call dma_set_mask_and_coherent() here because the
  158. * DMA mask has already been appropraitely setup by the core
  159. * SA-1111 bus code (which includes bug workarounds.)
  160. */
  161. hcd = usb_create_hcd(&ohci_sa1111_hc_driver, &dev->dev, "sa1111");
  162. if (!hcd)
  163. return -ENOMEM;
  164. hcd->rsrc_start = dev->res.start;
  165. hcd->rsrc_len = resource_size(&dev->res);
  166. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  167. dev_dbg(&dev->dev, "request_mem_region failed\n");
  168. ret = -EBUSY;
  169. goto err1;
  170. }
  171. hcd->regs = dev->mapbase;
  172. ret = sa1111_start_hc(dev);
  173. if (ret)
  174. goto err2;
  175. ret = usb_add_hcd(hcd, dev->irq[1], 0);
  176. if (ret == 0) {
  177. device_wakeup_enable(hcd->self.controller);
  178. return ret;
  179. }
  180. sa1111_stop_hc(dev);
  181. err2:
  182. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  183. err1:
  184. usb_put_hcd(hcd);
  185. return ret;
  186. }
  187. /**
  188. * ohci_hcd_sa1111_remove - shutdown processing for SA-1111-based HCDs
  189. * @dev: USB Host Controller being removed
  190. *
  191. * Reverses the effect of ohci_hcd_sa1111_probe(), first invoking
  192. * the HCD's stop() method.
  193. */
  194. static int ohci_hcd_sa1111_remove(struct sa1111_dev *dev)
  195. {
  196. struct usb_hcd *hcd = sa1111_get_drvdata(dev);
  197. usb_remove_hcd(hcd);
  198. sa1111_stop_hc(dev);
  199. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  200. usb_put_hcd(hcd);
  201. return 0;
  202. }
  203. static void ohci_hcd_sa1111_shutdown(struct sa1111_dev *dev)
  204. {
  205. struct usb_hcd *hcd = sa1111_get_drvdata(dev);
  206. if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
  207. hcd->driver->shutdown(hcd);
  208. sa1111_stop_hc(dev);
  209. }
  210. }
  211. static struct sa1111_driver ohci_hcd_sa1111_driver = {
  212. .drv = {
  213. .name = "sa1111-ohci",
  214. .owner = THIS_MODULE,
  215. },
  216. .devid = SA1111_DEVID_USB,
  217. .probe = ohci_hcd_sa1111_probe,
  218. .remove = ohci_hcd_sa1111_remove,
  219. .shutdown = ohci_hcd_sa1111_shutdown,
  220. };