ohci-sa1111.c 6.2 KB

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