ohci-ppc-soc.c 5.0 KB

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