ohci-ppc-of.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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
  69. ohci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match)
  70. {
  71. struct device_node *dn = op->node;
  72. struct usb_hcd *hcd;
  73. struct ohci_hcd *ohci;
  74. struct resource res;
  75. int irq;
  76. int rv;
  77. int is_bigendian;
  78. struct device_node *np;
  79. if (usb_disabled())
  80. return -ENODEV;
  81. is_bigendian =
  82. of_device_is_compatible(dn, "ohci-bigendian") ||
  83. of_device_is_compatible(dn, "ohci-be");
  84. dev_dbg(&op->dev, "initializing PPC-OF USB Controller\n");
  85. rv = of_address_to_resource(dn, 0, &res);
  86. if (rv)
  87. return rv;
  88. hcd = usb_create_hcd(&ohci_ppc_of_hc_driver, &op->dev, "PPC-OF USB");
  89. if (!hcd)
  90. return -ENOMEM;
  91. hcd->rsrc_start = res.start;
  92. hcd->rsrc_len = res.end - res.start + 1;
  93. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  94. printk(KERN_ERR __FILE__ ": request_mem_region failed\n");
  95. rv = -EBUSY;
  96. goto err_rmr;
  97. }
  98. irq = irq_of_parse_and_map(dn, 0);
  99. if (irq == NO_IRQ) {
  100. printk(KERN_ERR __FILE__ ": irq_of_parse_and_map failed\n");
  101. rv = -EBUSY;
  102. goto err_irq;
  103. }
  104. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  105. if (!hcd->regs) {
  106. printk(KERN_ERR __FILE__ ": ioremap failed\n");
  107. rv = -ENOMEM;
  108. goto err_ioremap;
  109. }
  110. ohci = hcd_to_ohci(hcd);
  111. if (is_bigendian) {
  112. ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC;
  113. if (of_device_is_compatible(dn, "fsl,mpc5200-ohci"))
  114. ohci->flags |= OHCI_QUIRK_FRAME_NO;
  115. if (of_device_is_compatible(dn, "mpc5200-ohci"))
  116. ohci->flags |= OHCI_QUIRK_FRAME_NO;
  117. }
  118. ohci_hcd_init(ohci);
  119. rv = usb_add_hcd(hcd, irq, IRQF_DISABLED);
  120. if (rv == 0)
  121. return 0;
  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(__FILE__ ": cannot get ehci offset from fdt\n");
  143. }
  144. iounmap(hcd->regs);
  145. err_ioremap:
  146. irq_dispose_mapping(irq);
  147. err_irq:
  148. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  149. err_rmr:
  150. usb_put_hcd(hcd);
  151. return rv;
  152. }
  153. static int ohci_hcd_ppc_of_remove(struct of_device *op)
  154. {
  155. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  156. dev_set_drvdata(&op->dev, NULL);
  157. dev_dbg(&op->dev, "stopping PPC-OF USB Controller\n");
  158. usb_remove_hcd(hcd);
  159. iounmap(hcd->regs);
  160. irq_dispose_mapping(hcd->irq);
  161. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  162. usb_put_hcd(hcd);
  163. return 0;
  164. }
  165. static int ohci_hcd_ppc_of_shutdown(struct of_device *op)
  166. {
  167. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  168. if (hcd->driver->shutdown)
  169. hcd->driver->shutdown(hcd);
  170. return 0;
  171. }
  172. static struct of_device_id ohci_hcd_ppc_of_match[] = {
  173. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF_BE
  174. {
  175. .name = "usb",
  176. .compatible = "ohci-bigendian",
  177. },
  178. {
  179. .name = "usb",
  180. .compatible = "ohci-be",
  181. },
  182. #endif
  183. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF_LE
  184. {
  185. .name = "usb",
  186. .compatible = "ohci-littledian",
  187. },
  188. {
  189. .name = "usb",
  190. .compatible = "ohci-le",
  191. },
  192. #endif
  193. {},
  194. };
  195. MODULE_DEVICE_TABLE(of, ohci_hcd_ppc_of_match);
  196. #if !defined(CONFIG_USB_OHCI_HCD_PPC_OF_BE) && \
  197. !defined(CONFIG_USB_OHCI_HCD_PPC_OF_LE)
  198. #error "No endianess selected for ppc-of-ohci"
  199. #endif
  200. static struct of_platform_driver ohci_hcd_ppc_of_driver = {
  201. .name = "ppc-of-ohci",
  202. .match_table = ohci_hcd_ppc_of_match,
  203. .probe = ohci_hcd_ppc_of_probe,
  204. .remove = ohci_hcd_ppc_of_remove,
  205. .shutdown = ohci_hcd_ppc_of_shutdown,
  206. #ifdef CONFIG_PM
  207. /*.suspend = ohci_hcd_ppc_soc_drv_suspend,*/
  208. /*.resume = ohci_hcd_ppc_soc_drv_resume,*/
  209. #endif
  210. .driver = {
  211. .name = "ppc-of-ohci",
  212. .owner = THIS_MODULE,
  213. },
  214. };