ehci-ppc-of.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * EHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * Bus Glue for PPC On-Chip EHCI driver on the of_platform bus
  5. * Tested on AMCC PPC 440EPx
  6. *
  7. * Valentine Barshak <vbarshak@ru.mvista.com>
  8. *
  9. * Based on "ehci-ppc-soc.c" by Stefan Roese <sr@denx.de>
  10. * and "ohci-ppc-of.c" by Sylvain Munaut <tnt@246tNt.com>
  11. *
  12. * This file is licenced under the GPL.
  13. */
  14. #include <linux/signal.h>
  15. #include <linux/of.h>
  16. #include <linux/of_platform.h>
  17. /* called during probe() after chip reset completes */
  18. static int ehci_ppc_of_setup(struct usb_hcd *hcd)
  19. {
  20. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  21. int retval;
  22. retval = ehci_halt(ehci);
  23. if (retval)
  24. return retval;
  25. retval = ehci_init(hcd);
  26. if (retval)
  27. return retval;
  28. ehci->sbrn = 0x20;
  29. return ehci_reset(ehci);
  30. }
  31. static const struct hc_driver ehci_ppc_of_hc_driver = {
  32. .description = hcd_name,
  33. .product_desc = "OF EHCI",
  34. .hcd_priv_size = sizeof(struct ehci_hcd),
  35. /*
  36. * generic hardware linkage
  37. */
  38. .irq = ehci_irq,
  39. .flags = HCD_MEMORY | HCD_USB2,
  40. /*
  41. * basic lifecycle operations
  42. */
  43. .reset = ehci_ppc_of_setup,
  44. .start = ehci_run,
  45. .stop = ehci_stop,
  46. .shutdown = ehci_shutdown,
  47. /*
  48. * managing i/o requests and associated device resources
  49. */
  50. .urb_enqueue = ehci_urb_enqueue,
  51. .urb_dequeue = ehci_urb_dequeue,
  52. .endpoint_disable = ehci_endpoint_disable,
  53. /*
  54. * scheduling support
  55. */
  56. .get_frame_number = ehci_get_frame,
  57. /*
  58. * root hub support
  59. */
  60. .hub_status_data = ehci_hub_status_data,
  61. .hub_control = ehci_hub_control,
  62. #ifdef CONFIG_PM
  63. .bus_suspend = ehci_bus_suspend,
  64. .bus_resume = ehci_bus_resume,
  65. #endif
  66. };
  67. /*
  68. * 440EPx Errata USBH_3
  69. * Fix: Enable Break Memory Transfer (BMT) in INSNREG3
  70. */
  71. #define PPC440EPX_EHCI0_INSREG_BMT (0x1 << 0)
  72. static int __devinit
  73. ppc44x_enable_bmt(struct device_node *dn)
  74. {
  75. __iomem u32 *insreg_virt;
  76. insreg_virt = of_iomap(dn, 1);
  77. if (!insreg_virt)
  78. return -EINVAL;
  79. out_be32(insreg_virt + 3, PPC440EPX_EHCI0_INSREG_BMT);
  80. iounmap(insreg_virt);
  81. return 0;
  82. }
  83. static int __devinit
  84. ehci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match)
  85. {
  86. struct device_node *dn = op->node;
  87. struct usb_hcd *hcd;
  88. struct ehci_hcd *ehci;
  89. struct resource res;
  90. int irq;
  91. int rv;
  92. if (usb_disabled())
  93. return -ENODEV;
  94. dev_dbg(&op->dev, "initializing PPC-OF USB Controller\n");
  95. rv = of_address_to_resource(dn, 0, &res);
  96. if (rv)
  97. return rv;
  98. hcd = usb_create_hcd(&ehci_ppc_of_hc_driver, &op->dev, "PPC-OF USB");
  99. if (!hcd)
  100. return -ENOMEM;
  101. hcd->rsrc_start = res.start;
  102. hcd->rsrc_len = res.end - res.start + 1;
  103. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  104. printk(KERN_ERR __FILE__ ": request_mem_region failed\n");
  105. rv = -EBUSY;
  106. goto err_rmr;
  107. }
  108. irq = irq_of_parse_and_map(dn, 0);
  109. if (irq == NO_IRQ) {
  110. printk(KERN_ERR __FILE__ ": irq_of_parse_and_map failed\n");
  111. rv = -EBUSY;
  112. goto err_irq;
  113. }
  114. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  115. if (!hcd->regs) {
  116. printk(KERN_ERR __FILE__ ": ioremap failed\n");
  117. rv = -ENOMEM;
  118. goto err_ioremap;
  119. }
  120. ehci = hcd_to_ehci(hcd);
  121. if (of_get_property(dn, "big-endian", NULL)) {
  122. ehci->big_endian_mmio = 1;
  123. ehci->big_endian_desc = 1;
  124. }
  125. if (of_get_property(dn, "big-endian-regs", NULL))
  126. ehci->big_endian_mmio = 1;
  127. if (of_get_property(dn, "big-endian-desc", NULL))
  128. ehci->big_endian_desc = 1;
  129. ehci->caps = hcd->regs;
  130. ehci->regs = hcd->regs +
  131. HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  132. /* cache this readonly data; minimize chip reads */
  133. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  134. if (of_device_is_compatible(dn, "ibm,usb-ehci-440epx")) {
  135. rv = ppc44x_enable_bmt(dn);
  136. ehci_dbg(ehci, "Break Memory Transfer (BMT) is %senabled!\n",
  137. rv ? "NOT ": "");
  138. }
  139. rv = usb_add_hcd(hcd, irq, 0);
  140. if (rv == 0)
  141. return 0;
  142. iounmap(hcd->regs);
  143. err_ioremap:
  144. irq_dispose_mapping(irq);
  145. err_irq:
  146. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  147. err_rmr:
  148. usb_put_hcd(hcd);
  149. return rv;
  150. }
  151. static int ehci_hcd_ppc_of_remove(struct of_device *op)
  152. {
  153. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  154. dev_set_drvdata(&op->dev, NULL);
  155. dev_dbg(&op->dev, "stopping PPC-OF USB Controller\n");
  156. usb_remove_hcd(hcd);
  157. iounmap(hcd->regs);
  158. irq_dispose_mapping(hcd->irq);
  159. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  160. usb_put_hcd(hcd);
  161. return 0;
  162. }
  163. static int ehci_hcd_ppc_of_shutdown(struct of_device *op)
  164. {
  165. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  166. if (hcd->driver->shutdown)
  167. hcd->driver->shutdown(hcd);
  168. return 0;
  169. }
  170. static struct of_device_id ehci_hcd_ppc_of_match[] = {
  171. {
  172. .compatible = "usb-ehci",
  173. },
  174. {},
  175. };
  176. MODULE_DEVICE_TABLE(of, ehci_hcd_ppc_of_match);
  177. static struct of_platform_driver ehci_hcd_ppc_of_driver = {
  178. .name = "ppc-of-ehci",
  179. .match_table = ehci_hcd_ppc_of_match,
  180. .probe = ehci_hcd_ppc_of_probe,
  181. .remove = ehci_hcd_ppc_of_remove,
  182. .shutdown = ehci_hcd_ppc_of_shutdown,
  183. .driver = {
  184. .name = "ppc-of-ehci",
  185. .owner = THIS_MODULE,
  186. },
  187. };