ohci-ppc-soc.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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("%s: no irq\n", __FILE__);
  40. return -ENODEV;
  41. }
  42. irq = res->start;
  43. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  44. if (!res) {
  45. pr_debug("%s: no reg addr\n", __FILE__);
  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 = resource_size(res);
  53. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  54. pr_debug("%s: request_mem_region failed\n", __FILE__);
  55. retval = -EBUSY;
  56. goto err1;
  57. }
  58. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  59. if (!hcd->regs) {
  60. pr_debug("%s: ioremap failed\n", __FILE__);
  61. retval = -ENOMEM;
  62. goto err2;
  63. }
  64. ohci = hcd_to_ohci(hcd);
  65. ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC;
  66. #ifdef CONFIG_PPC_MPC52xx
  67. /* MPC52xx doesn't need frame_no shift */
  68. ohci->flags |= OHCI_QUIRK_FRAME_NO;
  69. #endif
  70. ohci_hcd_init(ohci);
  71. retval = usb_add_hcd(hcd, irq, 0);
  72. if (retval == 0)
  73. return retval;
  74. pr_debug("Removing PPC-SOC USB Controller\n");
  75. iounmap(hcd->regs);
  76. err2:
  77. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  78. err1:
  79. usb_put_hcd(hcd);
  80. return retval;
  81. }
  82. /* may be called without controller electrically present */
  83. /* may be called with controller, bus, and devices active */
  84. /**
  85. * usb_hcd_ppc_soc_remove - shutdown processing for On-Chip HCDs
  86. * @pdev: USB Host Controller being removed
  87. * Context: !in_interrupt()
  88. *
  89. * Reverses the effect of usb_hcd_ppc_soc_probe().
  90. * It is always called from a thread
  91. * context, normally "rmmod", "apmd", or something similar.
  92. *
  93. */
  94. static void usb_hcd_ppc_soc_remove(struct usb_hcd *hcd,
  95. struct platform_device *pdev)
  96. {
  97. usb_remove_hcd(hcd);
  98. pr_debug("stopping PPC-SOC USB Controller\n");
  99. iounmap(hcd->regs);
  100. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  101. usb_put_hcd(hcd);
  102. }
  103. static int __devinit
  104. ohci_ppc_soc_start(struct usb_hcd *hcd)
  105. {
  106. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  107. int ret;
  108. if ((ret = ohci_init(ohci)) < 0)
  109. return ret;
  110. if ((ret = ohci_run(ohci)) < 0) {
  111. err("can't start %s", ohci_to_hcd(ohci)->self.bus_name);
  112. ohci_stop(hcd);
  113. return ret;
  114. }
  115. return 0;
  116. }
  117. static const struct hc_driver ohci_ppc_soc_hc_driver = {
  118. .description = hcd_name,
  119. .hcd_priv_size = sizeof(struct ohci_hcd),
  120. /*
  121. * generic hardware linkage
  122. */
  123. .irq = ohci_irq,
  124. .flags = HCD_USB11 | HCD_MEMORY,
  125. /*
  126. * basic lifecycle operations
  127. */
  128. .start = ohci_ppc_soc_start,
  129. .stop = ohci_stop,
  130. .shutdown = ohci_shutdown,
  131. /*
  132. * managing i/o requests and associated device resources
  133. */
  134. .urb_enqueue = ohci_urb_enqueue,
  135. .urb_dequeue = ohci_urb_dequeue,
  136. .endpoint_disable = ohci_endpoint_disable,
  137. /*
  138. * scheduling support
  139. */
  140. .get_frame_number = ohci_get_frame,
  141. /*
  142. * root hub support
  143. */
  144. .hub_status_data = ohci_hub_status_data,
  145. .hub_control = ohci_hub_control,
  146. #ifdef CONFIG_PM
  147. .bus_suspend = ohci_bus_suspend,
  148. .bus_resume = ohci_bus_resume,
  149. #endif
  150. .start_port_reset = ohci_start_port_reset,
  151. };
  152. static int ohci_hcd_ppc_soc_drv_probe(struct platform_device *pdev)
  153. {
  154. int ret;
  155. if (usb_disabled())
  156. return -ENODEV;
  157. ret = usb_hcd_ppc_soc_probe(&ohci_ppc_soc_hc_driver, pdev);
  158. return ret;
  159. }
  160. static int ohci_hcd_ppc_soc_drv_remove(struct platform_device *pdev)
  161. {
  162. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  163. usb_hcd_ppc_soc_remove(hcd, pdev);
  164. return 0;
  165. }
  166. static struct platform_driver ohci_hcd_ppc_soc_driver = {
  167. .probe = ohci_hcd_ppc_soc_drv_probe,
  168. .remove = ohci_hcd_ppc_soc_drv_remove,
  169. .shutdown = usb_hcd_platform_shutdown,
  170. #ifdef CONFIG_PM
  171. /*.suspend = ohci_hcd_ppc_soc_drv_suspend,*/
  172. /*.resume = ohci_hcd_ppc_soc_drv_resume,*/
  173. #endif
  174. .driver = {
  175. .name = "ppc-soc-ohci",
  176. .owner = THIS_MODULE,
  177. },
  178. };
  179. MODULE_ALIAS("platform:ppc-soc-ohci");