ehci-ppc-soc.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * EHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * (C) Copyright 2006-2007 Stefan Roese <sr@denx.de>, DENX Software Engineering
  5. *
  6. * Bus Glue for PPC On-Chip EHCI driver
  7. * Tested on AMCC 440EPx
  8. *
  9. * Based on "ehci-au1xxx.c" by K.Boge <karsten.boge@amd.com>
  10. *
  11. * This file is licenced under the GPL.
  12. */
  13. #include <linux/platform_device.h>
  14. extern int usb_disabled(void);
  15. /* called during probe() after chip reset completes */
  16. static int ehci_ppc_soc_setup(struct usb_hcd *hcd)
  17. {
  18. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  19. int retval;
  20. retval = ehci_halt(ehci);
  21. if (retval)
  22. return retval;
  23. retval = ehci_init(hcd);
  24. if (retval)
  25. return retval;
  26. ehci->sbrn = 0x20;
  27. return ehci_reset(ehci);
  28. }
  29. /**
  30. * usb_ehci_ppc_soc_probe - initialize PPC-SoC-based HCDs
  31. * Context: !in_interrupt()
  32. *
  33. * Allocates basic resources for this USB host controller, and
  34. * then invokes the start() method for the HCD associated with it
  35. * through the hotplug entry's driver_data.
  36. *
  37. */
  38. int usb_ehci_ppc_soc_probe(const struct hc_driver *driver,
  39. struct usb_hcd **hcd_out,
  40. struct platform_device *dev)
  41. {
  42. int retval;
  43. struct usb_hcd *hcd;
  44. struct ehci_hcd *ehci;
  45. if (dev->resource[1].flags != IORESOURCE_IRQ) {
  46. pr_debug("resource[1] is not IORESOURCE_IRQ");
  47. retval = -ENOMEM;
  48. }
  49. hcd = usb_create_hcd(driver, &dev->dev, "PPC-SOC EHCI");
  50. if (!hcd)
  51. return -ENOMEM;
  52. hcd->rsrc_start = dev->resource[0].start;
  53. hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
  54. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  55. pr_debug("request_mem_region failed");
  56. retval = -EBUSY;
  57. goto err1;
  58. }
  59. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  60. if (!hcd->regs) {
  61. pr_debug("ioremap failed");
  62. retval = -ENOMEM;
  63. goto err2;
  64. }
  65. ehci = hcd_to_ehci(hcd);
  66. ehci->big_endian_mmio = 1;
  67. ehci->big_endian_desc = 1;
  68. ehci->caps = hcd->regs;
  69. ehci->regs = hcd->regs + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  70. /* cache this readonly data; minimize chip reads */
  71. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  72. #if defined(CONFIG_440EPX)
  73. /*
  74. * 440EPx Errata USBH_3
  75. * Fix: Enable Break Memory Transfer (BMT) in INSNREG3
  76. */
  77. out_be32((void *)((ulong)(&ehci->regs->command) + 0x8c), (1 << 0));
  78. ehci_dbg(ehci, "Break Memory Transfer (BMT) has beed enabled!\n");
  79. #endif
  80. retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED);
  81. if (retval == 0)
  82. return retval;
  83. iounmap(hcd->regs);
  84. err2:
  85. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  86. err1:
  87. usb_put_hcd(hcd);
  88. return retval;
  89. }
  90. /* may be called without controller electrically present */
  91. /* may be called with controller, bus, and devices active */
  92. /**
  93. * usb_ehci_hcd_ppc_soc_remove - shutdown processing for PPC-SoC-based HCDs
  94. * @dev: USB Host Controller being removed
  95. * Context: !in_interrupt()
  96. *
  97. * Reverses the effect of usb_ehci_hcd_ppc_soc_probe(), first invoking
  98. * the HCD's stop() method. It is always called from a thread
  99. * context, normally "rmmod", "apmd", or something similar.
  100. *
  101. */
  102. void usb_ehci_ppc_soc_remove(struct usb_hcd *hcd, struct platform_device *dev)
  103. {
  104. usb_remove_hcd(hcd);
  105. iounmap(hcd->regs);
  106. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  107. usb_put_hcd(hcd);
  108. }
  109. static const struct hc_driver ehci_ppc_soc_hc_driver = {
  110. .description = hcd_name,
  111. .product_desc = "PPC-SOC EHCI",
  112. .hcd_priv_size = sizeof(struct ehci_hcd),
  113. /*
  114. * generic hardware linkage
  115. */
  116. .irq = ehci_irq,
  117. .flags = HCD_MEMORY | HCD_USB2,
  118. /*
  119. * basic lifecycle operations
  120. */
  121. .reset = ehci_ppc_soc_setup,
  122. .start = ehci_run,
  123. .stop = ehci_stop,
  124. .shutdown = ehci_shutdown,
  125. /*
  126. * managing i/o requests and associated device resources
  127. */
  128. .urb_enqueue = ehci_urb_enqueue,
  129. .urb_dequeue = ehci_urb_dequeue,
  130. .endpoint_disable = ehci_endpoint_disable,
  131. /*
  132. * scheduling support
  133. */
  134. .get_frame_number = ehci_get_frame,
  135. /*
  136. * root hub support
  137. */
  138. .hub_status_data = ehci_hub_status_data,
  139. .hub_control = ehci_hub_control,
  140. .bus_suspend = ehci_bus_suspend,
  141. .bus_resume = ehci_bus_resume,
  142. .relinquish_port = ehci_relinquish_port,
  143. .port_handed_over = ehci_port_handed_over,
  144. };
  145. static int ehci_hcd_ppc_soc_drv_probe(struct platform_device *pdev)
  146. {
  147. struct usb_hcd *hcd = NULL;
  148. int ret;
  149. pr_debug("In ehci_hcd_ppc_soc_drv_probe\n");
  150. if (usb_disabled())
  151. return -ENODEV;
  152. /* FIXME we only want one one probe() not two */
  153. ret = usb_ehci_ppc_soc_probe(&ehci_ppc_soc_hc_driver, &hcd, pdev);
  154. return ret;
  155. }
  156. static int ehci_hcd_ppc_soc_drv_remove(struct platform_device *pdev)
  157. {
  158. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  159. /* FIXME we only want one one remove() not two */
  160. usb_ehci_ppc_soc_remove(hcd, pdev);
  161. return 0;
  162. }
  163. MODULE_ALIAS("platform:ppc-soc-ehci");
  164. static struct platform_driver ehci_ppc_soc_driver = {
  165. .probe = ehci_hcd_ppc_soc_drv_probe,
  166. .remove = ehci_hcd_ppc_soc_drv_remove,
  167. .shutdown = usb_hcd_platform_shutdown,
  168. .driver = {
  169. .name = "ppc-soc-ehci",
  170. }
  171. };