ohci-ppc-soc.c 5.5 KB

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