ohci-sa1111.c 6.4 KB

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