ohci-ppc-of.c 5.2 KB

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