ohci-ppc-of.c 4.7 KB

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