ohci-ppc-of.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. * (C) Copyright 2006 Sylvain Munaut <tnt@246tNt.com>
  9. *
  10. * Bus glue for OHCI HC on the of_platform bus
  11. *
  12. * Modified for of_platform bus from ohci-sa1111.c
  13. *
  14. * This file is licenced under the GPL.
  15. */
  16. #include <linux/signal.h>
  17. #include <linux/of_address.h>
  18. #include <linux/of_irq.h>
  19. #include <linux/of_platform.h>
  20. #include <asm/prom.h>
  21. static int
  22. ohci_ppc_of_start(struct usb_hcd *hcd)
  23. {
  24. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  25. int ret;
  26. if ((ret = ohci_init(ohci)) < 0)
  27. return ret;
  28. if ((ret = ohci_run(ohci)) < 0) {
  29. dev_err(hcd->self.controller, "can't start %s\n",
  30. hcd->self.bus_name);
  31. ohci_stop(hcd);
  32. return ret;
  33. }
  34. return 0;
  35. }
  36. static const struct hc_driver ohci_ppc_of_hc_driver = {
  37. .description = hcd_name,
  38. .product_desc = "OF OHCI",
  39. .hcd_priv_size = sizeof(struct ohci_hcd),
  40. /*
  41. * generic hardware linkage
  42. */
  43. .irq = ohci_irq,
  44. .flags = HCD_USB11 | HCD_MEMORY,
  45. /*
  46. * basic lifecycle operations
  47. */
  48. .start = ohci_ppc_of_start,
  49. .stop = ohci_stop,
  50. .shutdown = ohci_shutdown,
  51. /*
  52. * managing i/o requests and associated device resources
  53. */
  54. .urb_enqueue = ohci_urb_enqueue,
  55. .urb_dequeue = ohci_urb_dequeue,
  56. .endpoint_disable = ohci_endpoint_disable,
  57. /*
  58. * scheduling support
  59. */
  60. .get_frame_number = ohci_get_frame,
  61. /*
  62. * root hub support
  63. */
  64. .hub_status_data = ohci_hub_status_data,
  65. .hub_control = ohci_hub_control,
  66. #ifdef CONFIG_PM
  67. .bus_suspend = ohci_bus_suspend,
  68. .bus_resume = ohci_bus_resume,
  69. #endif
  70. .start_port_reset = ohci_start_port_reset,
  71. };
  72. static int ohci_hcd_ppc_of_probe(struct platform_device *op)
  73. {
  74. struct device_node *dn = op->dev.of_node;
  75. struct usb_hcd *hcd;
  76. struct ohci_hcd *ohci;
  77. struct resource res;
  78. int irq;
  79. int rv;
  80. int is_bigendian;
  81. struct device_node *np;
  82. if (usb_disabled())
  83. return -ENODEV;
  84. is_bigendian =
  85. of_device_is_compatible(dn, "ohci-bigendian") ||
  86. of_device_is_compatible(dn, "ohci-be");
  87. dev_dbg(&op->dev, "initializing PPC-OF USB Controller\n");
  88. rv = of_address_to_resource(dn, 0, &res);
  89. if (rv)
  90. return rv;
  91. hcd = usb_create_hcd(&ohci_ppc_of_hc_driver, &op->dev, "PPC-OF USB");
  92. if (!hcd)
  93. return -ENOMEM;
  94. hcd->rsrc_start = res.start;
  95. hcd->rsrc_len = resource_size(&res);
  96. hcd->regs = devm_ioremap_resource(&op->dev, &res);
  97. if (IS_ERR(hcd->regs)) {
  98. rv = PTR_ERR(hcd->regs);
  99. goto err_rmr;
  100. }
  101. irq = irq_of_parse_and_map(dn, 0);
  102. if (irq == NO_IRQ) {
  103. dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
  104. __FILE__);
  105. rv = -EBUSY;
  106. goto err_rmr;
  107. }
  108. ohci = hcd_to_ohci(hcd);
  109. if (is_bigendian) {
  110. ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC;
  111. if (of_device_is_compatible(dn, "fsl,mpc5200-ohci"))
  112. ohci->flags |= OHCI_QUIRK_FRAME_NO;
  113. if (of_device_is_compatible(dn, "mpc5200-ohci"))
  114. ohci->flags |= OHCI_QUIRK_FRAME_NO;
  115. }
  116. ohci_hcd_init(ohci);
  117. rv = usb_add_hcd(hcd, irq, 0);
  118. if (rv == 0) {
  119. device_wakeup_enable(hcd->self.controller);
  120. return 0;
  121. }
  122. /* by now, 440epx is known to show usb_23 erratum */
  123. np = of_find_compatible_node(NULL, NULL, "ibm,usb-ehci-440epx");
  124. /* Work around - At this point ohci_run has executed, the
  125. * controller is running, everything, the root ports, etc., is
  126. * set up. If the ehci driver is loaded, put the ohci core in
  127. * the suspended state. The ehci driver will bring it out of
  128. * suspended state when / if a non-high speed USB device is
  129. * attached to the USB Host port. If the ehci driver is not
  130. * loaded, do nothing. request_mem_region is used to test if
  131. * the ehci driver is loaded.
  132. */
  133. if (np != NULL) {
  134. if (!of_address_to_resource(np, 0, &res)) {
  135. if (!request_mem_region(res.start, 0x4, hcd_name)) {
  136. writel_be((readl_be(&ohci->regs->control) |
  137. OHCI_USB_SUSPEND), &ohci->regs->control);
  138. (void) readl_be(&ohci->regs->control);
  139. } else
  140. release_mem_region(res.start, 0x4);
  141. } else
  142. pr_debug("%s: cannot get ehci offset from fdt\n", __FILE__);
  143. }
  144. irq_dispose_mapping(irq);
  145. err_rmr:
  146. usb_put_hcd(hcd);
  147. return rv;
  148. }
  149. static int ohci_hcd_ppc_of_remove(struct platform_device *op)
  150. {
  151. struct usb_hcd *hcd = platform_get_drvdata(op);
  152. dev_dbg(&op->dev, "stopping PPC-OF USB Controller\n");
  153. usb_remove_hcd(hcd);
  154. irq_dispose_mapping(hcd->irq);
  155. usb_put_hcd(hcd);
  156. return 0;
  157. }
  158. static const struct of_device_id ohci_hcd_ppc_of_match[] = {
  159. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF_BE
  160. {
  161. .name = "usb",
  162. .compatible = "ohci-bigendian",
  163. },
  164. {
  165. .name = "usb",
  166. .compatible = "ohci-be",
  167. },
  168. #endif
  169. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF_LE
  170. {
  171. .name = "usb",
  172. .compatible = "ohci-littledian",
  173. },
  174. {
  175. .name = "usb",
  176. .compatible = "ohci-le",
  177. },
  178. #endif
  179. {},
  180. };
  181. MODULE_DEVICE_TABLE(of, ohci_hcd_ppc_of_match);
  182. #if !defined(CONFIG_USB_OHCI_HCD_PPC_OF_BE) && \
  183. !defined(CONFIG_USB_OHCI_HCD_PPC_OF_LE)
  184. #error "No endianness selected for ppc-of-ohci"
  185. #endif
  186. static struct platform_driver ohci_hcd_ppc_of_driver = {
  187. .probe = ohci_hcd_ppc_of_probe,
  188. .remove = ohci_hcd_ppc_of_remove,
  189. .shutdown = usb_hcd_platform_shutdown,
  190. .driver = {
  191. .name = "ppc-of-ohci",
  192. .of_match_table = ohci_hcd_ppc_of_match,
  193. },
  194. };