ohci-ppc-of.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. .hub_irq_enable = ohci_rhsc_enable,
  63. #ifdef CONFIG_PM
  64. .bus_suspend = ohci_bus_suspend,
  65. .bus_resume = ohci_bus_resume,
  66. #endif
  67. .start_port_reset = ohci_start_port_reset,
  68. };
  69. static int __devinit
  70. ohci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match)
  71. {
  72. struct device_node *dn = op->node;
  73. struct usb_hcd *hcd;
  74. struct ohci_hcd *ohci;
  75. struct resource res;
  76. int irq;
  77. int rv;
  78. int is_bigendian;
  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. iounmap(hcd->regs);
  123. err_ioremap:
  124. irq_dispose_mapping(irq);
  125. err_irq:
  126. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  127. err_rmr:
  128. usb_put_hcd(hcd);
  129. return rv;
  130. }
  131. static int ohci_hcd_ppc_of_remove(struct of_device *op)
  132. {
  133. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  134. dev_set_drvdata(&op->dev, NULL);
  135. dev_dbg(&op->dev, "stopping PPC-OF USB Controller\n");
  136. usb_remove_hcd(hcd);
  137. iounmap(hcd->regs);
  138. irq_dispose_mapping(hcd->irq);
  139. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  140. usb_put_hcd(hcd);
  141. return 0;
  142. }
  143. static int ohci_hcd_ppc_of_shutdown(struct of_device *op)
  144. {
  145. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  146. if (hcd->driver->shutdown)
  147. hcd->driver->shutdown(hcd);
  148. return 0;
  149. }
  150. static struct of_device_id ohci_hcd_ppc_of_match[] = {
  151. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF_BE
  152. {
  153. .name = "usb",
  154. .compatible = "ohci-bigendian",
  155. },
  156. {
  157. .name = "usb",
  158. .compatible = "ohci-be",
  159. },
  160. #endif
  161. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF_LE
  162. {
  163. .name = "usb",
  164. .compatible = "ohci-littledian",
  165. },
  166. {
  167. .name = "usb",
  168. .compatible = "ohci-le",
  169. },
  170. #endif
  171. {},
  172. };
  173. MODULE_DEVICE_TABLE(of, ohci_hcd_ppc_of_match);
  174. #if !defined(CONFIG_USB_OHCI_HCD_PPC_OF_BE) && \
  175. !defined(CONFIG_USB_OHCI_HCD_PPC_OF_LE)
  176. #error "No endianess selected for ppc-of-ohci"
  177. #endif
  178. static struct of_platform_driver ohci_hcd_ppc_of_driver = {
  179. .name = "ppc-of-ohci",
  180. .match_table = ohci_hcd_ppc_of_match,
  181. .probe = ohci_hcd_ppc_of_probe,
  182. .remove = ohci_hcd_ppc_of_remove,
  183. .shutdown = ohci_hcd_ppc_of_shutdown,
  184. #ifdef CONFIG_PM
  185. /*.suspend = ohci_hcd_ppc_soc_drv_suspend,*/
  186. /*.resume = ohci_hcd_ppc_soc_drv_resume,*/
  187. #endif
  188. .driver = {
  189. .name = "ppc-of-ohci",
  190. .owner = THIS_MODULE,
  191. },
  192. };