ehci-ppc-soc.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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-au12xx.c" by David Brownell <dbrownell@users.sourceforge.net>
  10. *
  11. * This file is licenced under the GPL.
  12. */
  13. #include <linux/platform_device.h>
  14. extern int usb_disabled(void);
  15. /**
  16. * usb_ehci_ppc_soc_probe - initialize PPC-SoC-based HCDs
  17. * Context: !in_interrupt()
  18. *
  19. * Allocates basic resources for this USB host controller, and
  20. * then invokes the start() method for the HCD associated with it
  21. * through the hotplug entry's driver_data.
  22. *
  23. */
  24. int usb_ehci_ppc_soc_probe(const struct hc_driver *driver,
  25. struct usb_hcd **hcd_out,
  26. struct platform_device *dev)
  27. {
  28. int retval;
  29. struct usb_hcd *hcd;
  30. struct ehci_hcd *ehci;
  31. if (dev->resource[1].flags != IORESOURCE_IRQ) {
  32. pr_debug("resource[1] is not IORESOURCE_IRQ");
  33. retval = -ENOMEM;
  34. }
  35. hcd = usb_create_hcd(driver, &dev->dev, "PPC-SOC EHCI");
  36. if (!hcd)
  37. return -ENOMEM;
  38. hcd->rsrc_start = dev->resource[0].start;
  39. hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
  40. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  41. pr_debug("request_mem_region failed");
  42. retval = -EBUSY;
  43. goto err1;
  44. }
  45. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  46. if (!hcd->regs) {
  47. pr_debug("ioremap failed");
  48. retval = -ENOMEM;
  49. goto err2;
  50. }
  51. ehci = hcd_to_ehci(hcd);
  52. ehci->big_endian_mmio = 1;
  53. ehci->big_endian_desc = 1;
  54. ehci->caps = hcd->regs;
  55. ehci->regs = hcd->regs + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  56. /* cache this readonly data; minimize chip reads */
  57. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  58. #if defined(CONFIG_440EPX)
  59. /*
  60. * 440EPx Errata USBH_3
  61. * Fix: Enable Break Memory Transfer (BMT) in INSNREG3
  62. */
  63. out_be32((void *)((ulong)(&ehci->regs->command) + 0x8c), (1 << 0));
  64. ehci_dbg(ehci, "Break Memory Transfer (BMT) has beed enabled!\n");
  65. #endif
  66. retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED);
  67. if (retval == 0)
  68. return retval;
  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_ehci_hcd_ppc_soc_remove - shutdown processing for PPC-SoC-based HCDs
  80. * @dev: USB Host Controller being removed
  81. * Context: !in_interrupt()
  82. *
  83. * Reverses the effect of usb_ehci_hcd_ppc_soc_probe(), first invoking
  84. * the HCD's stop() method. It is always called from a thread
  85. * context, normally "rmmod", "apmd", or something similar.
  86. *
  87. */
  88. void usb_ehci_ppc_soc_remove(struct usb_hcd *hcd, struct platform_device *dev)
  89. {
  90. usb_remove_hcd(hcd);
  91. iounmap(hcd->regs);
  92. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  93. usb_put_hcd(hcd);
  94. }
  95. static const struct hc_driver ehci_ppc_soc_hc_driver = {
  96. .description = hcd_name,
  97. .product_desc = "PPC-SOC EHCI",
  98. .hcd_priv_size = sizeof(struct ehci_hcd),
  99. /*
  100. * generic hardware linkage
  101. */
  102. .irq = ehci_irq,
  103. .flags = HCD_MEMORY | HCD_USB2,
  104. /*
  105. * basic lifecycle operations
  106. */
  107. .reset = ehci_init,
  108. .start = ehci_run,
  109. .stop = ehci_stop,
  110. .shutdown = ehci_shutdown,
  111. /*
  112. * managing i/o requests and associated device resources
  113. */
  114. .urb_enqueue = ehci_urb_enqueue,
  115. .urb_dequeue = ehci_urb_dequeue,
  116. .endpoint_disable = ehci_endpoint_disable,
  117. /*
  118. * scheduling support
  119. */
  120. .get_frame_number = ehci_get_frame,
  121. /*
  122. * root hub support
  123. */
  124. .hub_status_data = ehci_hub_status_data,
  125. .hub_control = ehci_hub_control,
  126. #ifdef CONFIG_PM
  127. .hub_suspend = ehci_hub_suspend,
  128. .hub_resume = ehci_hub_resume,
  129. #endif
  130. };
  131. static int ehci_hcd_ppc_soc_drv_probe(struct platform_device *pdev)
  132. {
  133. struct usb_hcd *hcd = NULL;
  134. int ret;
  135. pr_debug("In ehci_hcd_ppc_soc_drv_probe\n");
  136. if (usb_disabled())
  137. return -ENODEV;
  138. ret = usb_ehci_ppc_soc_probe(&ehci_ppc_soc_hc_driver, &hcd, pdev);
  139. return ret;
  140. }
  141. static int ehci_hcd_ppc_soc_drv_remove(struct platform_device *pdev)
  142. {
  143. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  144. usb_ehci_ppc_soc_remove(hcd, pdev);
  145. return 0;
  146. }
  147. MODULE_ALIAS("ppc-soc-ehci");
  148. static struct platform_driver ehci_ppc_soc_driver = {
  149. .probe = ehci_hcd_ppc_soc_drv_probe,
  150. .remove = ehci_hcd_ppc_soc_drv_remove,
  151. .shutdown = usb_hcd_platform_shutdown,
  152. .driver = {
  153. .name = "ppc-soc-ehci",
  154. .bus = &platform_bus_type
  155. }
  156. };