ohci-ppc-soc.c 5.1 KB

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