ehci-ppc-of.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. .relinquish_port = ehci_relinquish_port,
  67. .port_handed_over = ehci_port_handed_over,
  68. };
  69. /*
  70. * 440EPx Errata USBH_3
  71. * Fix: Enable Break Memory Transfer (BMT) in INSNREG3
  72. */
  73. #define PPC440EPX_EHCI0_INSREG_BMT (0x1 << 0)
  74. static int __devinit
  75. ppc44x_enable_bmt(struct device_node *dn)
  76. {
  77. __iomem u32 *insreg_virt;
  78. insreg_virt = of_iomap(dn, 1);
  79. if (!insreg_virt)
  80. return -EINVAL;
  81. out_be32(insreg_virt + 3, PPC440EPX_EHCI0_INSREG_BMT);
  82. iounmap(insreg_virt);
  83. return 0;
  84. }
  85. static int __devinit
  86. ehci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match)
  87. {
  88. struct device_node *dn = op->node;
  89. struct usb_hcd *hcd;
  90. struct ehci_hcd *ehci;
  91. struct resource res;
  92. int irq;
  93. int rv;
  94. if (usb_disabled())
  95. return -ENODEV;
  96. dev_dbg(&op->dev, "initializing PPC-OF USB Controller\n");
  97. rv = of_address_to_resource(dn, 0, &res);
  98. if (rv)
  99. return rv;
  100. hcd = usb_create_hcd(&ehci_ppc_of_hc_driver, &op->dev, "PPC-OF USB");
  101. if (!hcd)
  102. return -ENOMEM;
  103. hcd->rsrc_start = res.start;
  104. hcd->rsrc_len = res.end - res.start + 1;
  105. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  106. printk(KERN_ERR __FILE__ ": request_mem_region failed\n");
  107. rv = -EBUSY;
  108. goto err_rmr;
  109. }
  110. irq = irq_of_parse_and_map(dn, 0);
  111. if (irq == NO_IRQ) {
  112. printk(KERN_ERR __FILE__ ": irq_of_parse_and_map failed\n");
  113. rv = -EBUSY;
  114. goto err_irq;
  115. }
  116. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  117. if (!hcd->regs) {
  118. printk(KERN_ERR __FILE__ ": ioremap failed\n");
  119. rv = -ENOMEM;
  120. goto err_ioremap;
  121. }
  122. ehci = hcd_to_ehci(hcd);
  123. if (of_get_property(dn, "big-endian", NULL)) {
  124. ehci->big_endian_mmio = 1;
  125. ehci->big_endian_desc = 1;
  126. }
  127. if (of_get_property(dn, "big-endian-regs", NULL))
  128. ehci->big_endian_mmio = 1;
  129. if (of_get_property(dn, "big-endian-desc", NULL))
  130. ehci->big_endian_desc = 1;
  131. ehci->caps = hcd->regs;
  132. ehci->regs = hcd->regs +
  133. HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  134. /* cache this readonly data; minimize chip reads */
  135. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  136. if (of_device_is_compatible(dn, "ibm,usb-ehci-440epx")) {
  137. rv = ppc44x_enable_bmt(dn);
  138. ehci_dbg(ehci, "Break Memory Transfer (BMT) is %senabled!\n",
  139. rv ? "NOT ": "");
  140. }
  141. rv = usb_add_hcd(hcd, irq, 0);
  142. if (rv == 0)
  143. return 0;
  144. iounmap(hcd->regs);
  145. err_ioremap:
  146. irq_dispose_mapping(irq);
  147. err_irq:
  148. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  149. err_rmr:
  150. usb_put_hcd(hcd);
  151. return rv;
  152. }
  153. static int ehci_hcd_ppc_of_remove(struct of_device *op)
  154. {
  155. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  156. dev_set_drvdata(&op->dev, NULL);
  157. dev_dbg(&op->dev, "stopping PPC-OF USB Controller\n");
  158. usb_remove_hcd(hcd);
  159. iounmap(hcd->regs);
  160. irq_dispose_mapping(hcd->irq);
  161. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  162. usb_put_hcd(hcd);
  163. return 0;
  164. }
  165. static int ehci_hcd_ppc_of_shutdown(struct of_device *op)
  166. {
  167. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  168. if (hcd->driver->shutdown)
  169. hcd->driver->shutdown(hcd);
  170. return 0;
  171. }
  172. static struct of_device_id ehci_hcd_ppc_of_match[] = {
  173. {
  174. .compatible = "usb-ehci",
  175. },
  176. {},
  177. };
  178. MODULE_DEVICE_TABLE(of, ehci_hcd_ppc_of_match);
  179. static struct of_platform_driver ehci_hcd_ppc_of_driver = {
  180. .name = "ppc-of-ehci",
  181. .match_table = ehci_hcd_ppc_of_match,
  182. .probe = ehci_hcd_ppc_of_probe,
  183. .remove = ehci_hcd_ppc_of_remove,
  184. .shutdown = ehci_hcd_ppc_of_shutdown,
  185. .driver = {
  186. .name = "ppc-of-ehci",
  187. .owner = THIS_MODULE,
  188. },
  189. };