ohci-ppc-of.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. 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 = res.end - res.start + 1;
  92. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  93. printk(KERN_ERR __FILE__ ": request_mem_region failed\n");
  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 __FILE__ ": irq_of_parse_and_map failed\n");
  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 __FILE__ ": ioremap failed\n");
  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, IRQF_DISABLED);
  119. if (rv == 0)
  120. return 0;
  121. iounmap(hcd->regs);
  122. err_ioremap:
  123. irq_dispose_mapping(irq);
  124. err_irq:
  125. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  126. err_rmr:
  127. usb_put_hcd(hcd);
  128. return rv;
  129. }
  130. static int ohci_hcd_ppc_of_remove(struct of_device *op)
  131. {
  132. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  133. dev_set_drvdata(&op->dev, NULL);
  134. dev_dbg(&op->dev, "stopping PPC-OF USB Controller\n");
  135. usb_remove_hcd(hcd);
  136. iounmap(hcd->regs);
  137. irq_dispose_mapping(hcd->irq);
  138. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  139. usb_put_hcd(hcd);
  140. return 0;
  141. }
  142. static int ohci_hcd_ppc_of_shutdown(struct of_device *op)
  143. {
  144. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  145. if (hcd->driver->shutdown)
  146. hcd->driver->shutdown(hcd);
  147. return 0;
  148. }
  149. static struct of_device_id ohci_hcd_ppc_of_match[] = {
  150. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF_BE
  151. {
  152. .name = "usb",
  153. .compatible = "ohci-bigendian",
  154. },
  155. {
  156. .name = "usb",
  157. .compatible = "ohci-be",
  158. },
  159. #endif
  160. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF_LE
  161. {
  162. .name = "usb",
  163. .compatible = "ohci-littledian",
  164. },
  165. {
  166. .name = "usb",
  167. .compatible = "ohci-le",
  168. },
  169. #endif
  170. {},
  171. };
  172. MODULE_DEVICE_TABLE(of, ohci_hcd_ppc_of_match);
  173. #if !defined(CONFIG_USB_OHCI_HCD_PPC_OF_BE) && \
  174. !defined(CONFIG_USB_OHCI_HCD_PPC_OF_LE)
  175. #error "No endianess selected for ppc-of-ohci"
  176. #endif
  177. static struct of_platform_driver ohci_hcd_ppc_of_driver = {
  178. .name = "ppc-of-ohci",
  179. .match_table = ohci_hcd_ppc_of_match,
  180. .probe = ohci_hcd_ppc_of_probe,
  181. .remove = ohci_hcd_ppc_of_remove,
  182. .shutdown = ohci_hcd_ppc_of_shutdown,
  183. #ifdef CONFIG_PM
  184. /*.suspend = ohci_hcd_ppc_soc_drv_suspend,*/
  185. /*.resume = ohci_hcd_ppc_soc_drv_resume,*/
  186. #endif
  187. .driver = {
  188. .name = "ppc-of-ohci",
  189. .owner = THIS_MODULE,
  190. },
  191. };