ohci-ppc-of.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  96. printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
  97. rv = -EBUSY;
  98. goto err_rmr;
  99. }
  100. irq = irq_of_parse_and_map(dn, 0);
  101. if (irq == NO_IRQ) {
  102. printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
  103. rv = -EBUSY;
  104. goto err_irq;
  105. }
  106. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  107. if (!hcd->regs) {
  108. printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
  109. rv = -ENOMEM;
  110. goto err_ioremap;
  111. }
  112. ohci = hcd_to_ohci(hcd);
  113. if (is_bigendian) {
  114. ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC;
  115. if (of_device_is_compatible(dn, "fsl,mpc5200-ohci"))
  116. ohci->flags |= OHCI_QUIRK_FRAME_NO;
  117. if (of_device_is_compatible(dn, "mpc5200-ohci"))
  118. ohci->flags |= OHCI_QUIRK_FRAME_NO;
  119. }
  120. ohci_hcd_init(ohci);
  121. rv = usb_add_hcd(hcd, irq, 0);
  122. if (rv == 0)
  123. return 0;
  124. /* by now, 440epx is known to show usb_23 erratum */
  125. np = of_find_compatible_node(NULL, NULL, "ibm,usb-ehci-440epx");
  126. /* Work around - At this point ohci_run has executed, the
  127. * controller is running, everything, the root ports, etc., is
  128. * set up. If the ehci driver is loaded, put the ohci core in
  129. * the suspended state. The ehci driver will bring it out of
  130. * suspended state when / if a non-high speed USB device is
  131. * attached to the USB Host port. If the ehci driver is not
  132. * loaded, do nothing. request_mem_region is used to test if
  133. * the ehci driver is loaded.
  134. */
  135. if (np != NULL) {
  136. if (!of_address_to_resource(np, 0, &res)) {
  137. if (!request_mem_region(res.start, 0x4, hcd_name)) {
  138. writel_be((readl_be(&ohci->regs->control) |
  139. OHCI_USB_SUSPEND), &ohci->regs->control);
  140. (void) readl_be(&ohci->regs->control);
  141. } else
  142. release_mem_region(res.start, 0x4);
  143. } else
  144. pr_debug("%s: cannot get ehci offset from fdt\n", __FILE__);
  145. }
  146. iounmap(hcd->regs);
  147. err_ioremap:
  148. irq_dispose_mapping(irq);
  149. err_irq:
  150. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  151. err_rmr:
  152. usb_put_hcd(hcd);
  153. return rv;
  154. }
  155. static int ohci_hcd_ppc_of_remove(struct platform_device *op)
  156. {
  157. struct usb_hcd *hcd = platform_get_drvdata(op);
  158. dev_dbg(&op->dev, "stopping PPC-OF USB Controller\n");
  159. usb_remove_hcd(hcd);
  160. iounmap(hcd->regs);
  161. irq_dispose_mapping(hcd->irq);
  162. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  163. usb_put_hcd(hcd);
  164. return 0;
  165. }
  166. static const struct of_device_id ohci_hcd_ppc_of_match[] = {
  167. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF_BE
  168. {
  169. .name = "usb",
  170. .compatible = "ohci-bigendian",
  171. },
  172. {
  173. .name = "usb",
  174. .compatible = "ohci-be",
  175. },
  176. #endif
  177. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF_LE
  178. {
  179. .name = "usb",
  180. .compatible = "ohci-littledian",
  181. },
  182. {
  183. .name = "usb",
  184. .compatible = "ohci-le",
  185. },
  186. #endif
  187. {},
  188. };
  189. MODULE_DEVICE_TABLE(of, ohci_hcd_ppc_of_match);
  190. #if !defined(CONFIG_USB_OHCI_HCD_PPC_OF_BE) && \
  191. !defined(CONFIG_USB_OHCI_HCD_PPC_OF_LE)
  192. #error "No endianness selected for ppc-of-ohci"
  193. #endif
  194. static struct platform_driver ohci_hcd_ppc_of_driver = {
  195. .probe = ohci_hcd_ppc_of_probe,
  196. .remove = ohci_hcd_ppc_of_remove,
  197. .shutdown = usb_hcd_platform_shutdown,
  198. .driver = {
  199. .name = "ppc-of-ohci",
  200. .owner = THIS_MODULE,
  201. .of_match_table = ohci_hcd_ppc_of_match,
  202. },
  203. };