ohci-ppc-of.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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_platform.h>
  17. #include <asm/prom.h>
  18. static int __devinit
  19. ohci_ppc_of_start(struct usb_hcd *hcd)
  20. {
  21. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  22. int ret;
  23. if ((ret = ohci_init(ohci)) < 0)
  24. return ret;
  25. if ((ret = ohci_run(ohci)) < 0) {
  26. err("can't start %s", ohci_to_hcd(ohci)->self.bus_name);
  27. ohci_stop(hcd);
  28. return ret;
  29. }
  30. return 0;
  31. }
  32. static const struct hc_driver ohci_ppc_of_hc_driver = {
  33. .description = hcd_name,
  34. .product_desc = "OF OHCI",
  35. .hcd_priv_size = sizeof(struct ohci_hcd),
  36. /*
  37. * generic hardware linkage
  38. */
  39. .irq = ohci_irq,
  40. .flags = HCD_USB11 | HCD_MEMORY,
  41. /*
  42. * basic lifecycle operations
  43. */
  44. .start = ohci_ppc_of_start,
  45. .stop = ohci_stop,
  46. .shutdown = ohci_shutdown,
  47. /*
  48. * managing i/o requests and associated device resources
  49. */
  50. .urb_enqueue = ohci_urb_enqueue,
  51. .urb_dequeue = ohci_urb_dequeue,
  52. .endpoint_disable = ohci_endpoint_disable,
  53. /*
  54. * scheduling support
  55. */
  56. .get_frame_number = ohci_get_frame,
  57. /*
  58. * root hub support
  59. */
  60. .hub_status_data = ohci_hub_status_data,
  61. .hub_control = ohci_hub_control,
  62. #ifdef CONFIG_PM
  63. .bus_suspend = ohci_bus_suspend,
  64. .bus_resume = ohci_bus_resume,
  65. #endif
  66. .start_port_reset = ohci_start_port_reset,
  67. };
  68. static int __devinit ohci_hcd_ppc_of_probe(struct platform_device *op)
  69. {
  70. struct device_node *dn = op->dev.of_node;
  71. struct usb_hcd *hcd;
  72. struct ohci_hcd *ohci;
  73. struct resource res;
  74. int irq;
  75. int rv;
  76. int is_bigendian;
  77. struct device_node *np;
  78. if (usb_disabled())
  79. return -ENODEV;
  80. is_bigendian =
  81. of_device_is_compatible(dn, "ohci-bigendian") ||
  82. of_device_is_compatible(dn, "ohci-be");
  83. dev_dbg(&op->dev, "initializing PPC-OF USB Controller\n");
  84. rv = of_address_to_resource(dn, 0, &res);
  85. if (rv)
  86. return rv;
  87. hcd = usb_create_hcd(&ohci_ppc_of_hc_driver, &op->dev, "PPC-OF USB");
  88. if (!hcd)
  89. return -ENOMEM;
  90. hcd->rsrc_start = res.start;
  91. hcd->rsrc_len = resource_size(&res);
  92. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  93. printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
  94. rv = -EBUSY;
  95. goto err_rmr;
  96. }
  97. irq = irq_of_parse_and_map(dn, 0);
  98. if (irq == NO_IRQ) {
  99. printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
  100. rv = -EBUSY;
  101. goto err_irq;
  102. }
  103. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  104. if (!hcd->regs) {
  105. printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
  106. rv = -ENOMEM;
  107. goto err_ioremap;
  108. }
  109. ohci = hcd_to_ohci(hcd);
  110. if (is_bigendian) {
  111. ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC;
  112. if (of_device_is_compatible(dn, "fsl,mpc5200-ohci"))
  113. ohci->flags |= OHCI_QUIRK_FRAME_NO;
  114. if (of_device_is_compatible(dn, "mpc5200-ohci"))
  115. ohci->flags |= OHCI_QUIRK_FRAME_NO;
  116. }
  117. ohci_hcd_init(ohci);
  118. rv = usb_add_hcd(hcd, irq, 0);
  119. if (rv == 0)
  120. return 0;
  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. iounmap(hcd->regs);
  144. err_ioremap:
  145. irq_dispose_mapping(irq);
  146. err_irq:
  147. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  148. err_rmr:
  149. usb_put_hcd(hcd);
  150. return rv;
  151. }
  152. static int ohci_hcd_ppc_of_remove(struct platform_device *op)
  153. {
  154. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  155. dev_set_drvdata(&op->dev, NULL);
  156. dev_dbg(&op->dev, "stopping PPC-OF USB Controller\n");
  157. usb_remove_hcd(hcd);
  158. iounmap(hcd->regs);
  159. irq_dispose_mapping(hcd->irq);
  160. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  161. usb_put_hcd(hcd);
  162. return 0;
  163. }
  164. static void ohci_hcd_ppc_of_shutdown(struct platform_device *op)
  165. {
  166. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  167. if (hcd->driver->shutdown)
  168. hcd->driver->shutdown(hcd);
  169. }
  170. static const struct of_device_id ohci_hcd_ppc_of_match[] = {
  171. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF_BE
  172. {
  173. .name = "usb",
  174. .compatible = "ohci-bigendian",
  175. },
  176. {
  177. .name = "usb",
  178. .compatible = "ohci-be",
  179. },
  180. #endif
  181. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF_LE
  182. {
  183. .name = "usb",
  184. .compatible = "ohci-littledian",
  185. },
  186. {
  187. .name = "usb",
  188. .compatible = "ohci-le",
  189. },
  190. #endif
  191. {},
  192. };
  193. MODULE_DEVICE_TABLE(of, ohci_hcd_ppc_of_match);
  194. #if !defined(CONFIG_USB_OHCI_HCD_PPC_OF_BE) && \
  195. !defined(CONFIG_USB_OHCI_HCD_PPC_OF_LE)
  196. #error "No endianess selected for ppc-of-ohci"
  197. #endif
  198. static struct platform_driver ohci_hcd_ppc_of_driver = {
  199. .probe = ohci_hcd_ppc_of_probe,
  200. .remove = ohci_hcd_ppc_of_remove,
  201. .shutdown = ohci_hcd_ppc_of_shutdown,
  202. .driver = {
  203. .name = "ppc-of-ohci",
  204. .owner = THIS_MODULE,
  205. .of_match_table = ohci_hcd_ppc_of_match,
  206. },
  207. };