ohci-sa1111.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. // SPDX-License-Identifier: GPL-1.0+
  2. /*
  3. * OHCI HCD (Host Controller Driver) for USB.
  4. *
  5. * (C) Copyright 1999 Roman Weissgaerber <[email protected]>
  6. * (C) Copyright 2000-2002 David Brownell <[email protected]>
  7. * (C) Copyright 2002 Hewlett-Packard Company
  8. *
  9. * SA1111 Bus Glue
  10. *
  11. * Written by Christopher Hoover <[email protected]>
  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. /*
  173. * According to the "Intel StrongARM SA-1111 Microprocessor Companion
  174. * Chip Specification Update" (June 2000), erratum #7, there is a
  175. * significant bug in the SA1111 SDRAM shared memory controller. If
  176. * an access to a region of memory above 1MB relative to the bank base,
  177. * it is important that address bit 10 _NOT_ be asserted. Depending
  178. * on the configuration of the RAM, bit 10 may correspond to one
  179. * of several different (processor-relative) address bits.
  180. *
  181. * Section 4.6 of the "Intel StrongARM SA-1111 Development Module
  182. * User's Guide" mentions that jumpers R51 and R52 control the
  183. * target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or
  184. * SDRAM bank 1 on Neponset). The default configuration selects
  185. * Assabet, so any address in bank 1 is necessarily invalid.
  186. *
  187. * As a workaround, use a bounce buffer in addressable memory
  188. * as local_mem, relying on ZONE_DMA to provide an area that
  189. * fits within the above constraints.
  190. *
  191. * SZ_64K is an estimate for what size this might need.
  192. */
  193. ret = usb_hcd_setup_local_mem(hcd, 0, 0, SZ_64K);
  194. if (ret)
  195. goto err1;
  196. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  197. dev_dbg(&dev->dev, "request_mem_region failed\n");
  198. ret = -EBUSY;
  199. goto err1;
  200. }
  201. hcd->regs = dev->mapbase;
  202. ret = sa1111_start_hc(dev);
  203. if (ret)
  204. goto err2;
  205. ret = usb_add_hcd(hcd, irq, 0);
  206. if (ret == 0) {
  207. device_wakeup_enable(hcd->self.controller);
  208. return ret;
  209. }
  210. sa1111_stop_hc(dev);
  211. err2:
  212. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  213. err1:
  214. usb_put_hcd(hcd);
  215. return ret;
  216. }
  217. /**
  218. * ohci_hcd_sa1111_remove - shutdown processing for SA-1111-based HCDs
  219. * @dev: USB Host Controller being removed
  220. *
  221. * Reverses the effect of ohci_hcd_sa1111_probe(), first invoking
  222. * the HCD's stop() method.
  223. */
  224. static void ohci_hcd_sa1111_remove(struct sa1111_dev *dev)
  225. {
  226. struct usb_hcd *hcd = sa1111_get_drvdata(dev);
  227. usb_remove_hcd(hcd);
  228. sa1111_stop_hc(dev);
  229. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  230. usb_put_hcd(hcd);
  231. }
  232. static void ohci_hcd_sa1111_shutdown(struct device *_dev)
  233. {
  234. struct sa1111_dev *dev = to_sa1111_device(_dev);
  235. struct usb_hcd *hcd = sa1111_get_drvdata(dev);
  236. if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
  237. hcd->driver->shutdown(hcd);
  238. sa1111_stop_hc(dev);
  239. }
  240. }
  241. static struct sa1111_driver ohci_hcd_sa1111_driver = {
  242. .drv = {
  243. .name = "sa1111-ohci",
  244. .owner = THIS_MODULE,
  245. .shutdown = ohci_hcd_sa1111_shutdown,
  246. },
  247. .devid = SA1111_DEVID_USB,
  248. .probe = ohci_hcd_sa1111_probe,
  249. .remove = ohci_hcd_sa1111_remove,
  250. };