ohci-ppc-soc.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 2003-2005 MontaVista Software Inc.
  8. *
  9. * Bus Glue for PPC On-Chip OHCI driver
  10. * Tested on Freescale MPC5200 and IBM STB04xxx
  11. *
  12. * Modified by Dale Farnsworth <dale@farnsworth.org> from ohci-sa1111.c
  13. *
  14. * This file is licenced under the GPL.
  15. */
  16. #include <linux/platform_device.h>
  17. /* configure so an HC device and id are always provided */
  18. /* always called with process context; sleeping is OK */
  19. /**
  20. * usb_hcd_ppc_soc_probe - initialize On-Chip HCDs
  21. * Context: !in_interrupt()
  22. *
  23. * Allocates basic resources for this USB host controller.
  24. *
  25. * Store this function in the HCD's struct pci_driver as probe().
  26. */
  27. static int usb_hcd_ppc_soc_probe(const struct hc_driver *driver,
  28. struct platform_device *pdev)
  29. {
  30. int retval;
  31. struct usb_hcd *hcd;
  32. struct ohci_hcd *ohci;
  33. struct resource *res;
  34. int irq;
  35. pr_debug("initializing PPC-SOC USB Controller\n");
  36. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  37. if (!res) {
  38. pr_debug(__FILE__ ": no irq\n");
  39. return -ENODEV;
  40. }
  41. irq = res->start;
  42. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  43. if (!res) {
  44. pr_debug(__FILE__ ": no reg addr\n");
  45. return -ENODEV;
  46. }
  47. hcd = usb_create_hcd(driver, &pdev->dev, "PPC-SOC USB");
  48. if (!hcd)
  49. return -ENOMEM;
  50. hcd->rsrc_start = res->start;
  51. hcd->rsrc_len = res->end - res->start + 1;
  52. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  53. pr_debug(__FILE__ ": request_mem_region failed\n");
  54. retval = -EBUSY;
  55. goto err1;
  56. }
  57. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  58. if (!hcd->regs) {
  59. pr_debug(__FILE__ ": ioremap failed\n");
  60. retval = -ENOMEM;
  61. goto err2;
  62. }
  63. ohci = hcd_to_ohci(hcd);
  64. ohci->flags |= OHCI_BIG_ENDIAN;
  65. ohci_hcd_init(ohci);
  66. retval = usb_add_hcd(hcd, irq, SA_INTERRUPT);
  67. if (retval == 0)
  68. return retval;
  69. pr_debug("Removing PPC-SOC USB Controller\n");
  70. iounmap(hcd->regs);
  71. err2:
  72. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  73. err1:
  74. usb_put_hcd(hcd);
  75. return retval;
  76. }
  77. /* may be called without controller electrically present */
  78. /* may be called with controller, bus, and devices active */
  79. /**
  80. * usb_hcd_ppc_soc_remove - shutdown processing for On-Chip HCDs
  81. * @pdev: USB Host Controller being removed
  82. * Context: !in_interrupt()
  83. *
  84. * Reverses the effect of usb_hcd_ppc_soc_probe().
  85. * It is always called from a thread
  86. * context, normally "rmmod", "apmd", or something similar.
  87. *
  88. */
  89. static void usb_hcd_ppc_soc_remove(struct usb_hcd *hcd,
  90. struct platform_device *pdev)
  91. {
  92. usb_remove_hcd(hcd);
  93. pr_debug("stopping PPC-SOC USB Controller\n");
  94. iounmap(hcd->regs);
  95. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  96. usb_put_hcd(hcd);
  97. }
  98. static int __devinit
  99. ohci_ppc_soc_start(struct usb_hcd *hcd)
  100. {
  101. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  102. int ret;
  103. if ((ret = ohci_init(ohci)) < 0)
  104. return ret;
  105. if ((ret = ohci_run(ohci)) < 0) {
  106. err("can't start %s", ohci_to_hcd(ohci)->self.bus_name);
  107. ohci_stop(hcd);
  108. return ret;
  109. }
  110. return 0;
  111. }
  112. static const struct hc_driver ohci_ppc_soc_hc_driver = {
  113. .description = hcd_name,
  114. .hcd_priv_size = sizeof(struct ohci_hcd),
  115. /*
  116. * generic hardware linkage
  117. */
  118. .irq = ohci_irq,
  119. .flags = HCD_USB11 | HCD_MEMORY,
  120. /*
  121. * basic lifecycle operations
  122. */
  123. .start = ohci_ppc_soc_start,
  124. .stop = ohci_stop,
  125. /*
  126. * managing i/o requests and associated device resources
  127. */
  128. .urb_enqueue = ohci_urb_enqueue,
  129. .urb_dequeue = ohci_urb_dequeue,
  130. .endpoint_disable = ohci_endpoint_disable,
  131. /*
  132. * scheduling support
  133. */
  134. .get_frame_number = ohci_get_frame,
  135. /*
  136. * root hub support
  137. */
  138. .hub_status_data = ohci_hub_status_data,
  139. .hub_control = ohci_hub_control,
  140. #ifdef CONFIG_PM
  141. .bus_suspend = ohci_bus_suspend,
  142. .bus_resume = ohci_bus_resume,
  143. #endif
  144. .start_port_reset = ohci_start_port_reset,
  145. };
  146. static int ohci_hcd_ppc_soc_drv_probe(struct platform_device *pdev)
  147. {
  148. int ret;
  149. if (usb_disabled())
  150. return -ENODEV;
  151. ret = usb_hcd_ppc_soc_probe(&ohci_ppc_soc_hc_driver, pdev);
  152. return ret;
  153. }
  154. static int ohci_hcd_ppc_soc_drv_remove(struct platform_device *pdev)
  155. {
  156. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  157. usb_hcd_ppc_soc_remove(hcd, pdev);
  158. return 0;
  159. }
  160. static struct platform_driver ohci_hcd_ppc_soc_driver = {
  161. .probe = ohci_hcd_ppc_soc_drv_probe,
  162. .remove = ohci_hcd_ppc_soc_drv_remove,
  163. #ifdef CONFIG_PM
  164. /*.suspend = ohci_hcd_ppc_soc_drv_suspend,*/
  165. /*.resume = ohci_hcd_ppc_soc_drv_resume,*/
  166. #endif
  167. .driver = {
  168. .name = "ppc-soc-ohci",
  169. .owner = THIS_MODULE,
  170. },
  171. };
  172. static int __init ohci_hcd_ppc_soc_init(void)
  173. {
  174. pr_debug(DRIVER_INFO " (PPC SOC)\n");
  175. pr_debug("block sizes: ed %d td %d\n", sizeof(struct ed),
  176. sizeof(struct td));
  177. return platform_driver_register(&ohci_hcd_ppc_soc_driver);
  178. }
  179. static void __exit ohci_hcd_ppc_soc_cleanup(void)
  180. {
  181. platform_driver_unregister(&ohci_hcd_ppc_soc_driver);
  182. }
  183. module_init(ohci_hcd_ppc_soc_init);
  184. module_exit(ohci_hcd_ppc_soc_cleanup);