ehci-ppc-of.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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/err.h>
  15. #include <linux/signal.h>
  16. #include <linux/of.h>
  17. #include <linux/of_platform.h>
  18. static const struct hc_driver ehci_ppc_of_hc_driver = {
  19. .description = hcd_name,
  20. .product_desc = "OF EHCI",
  21. .hcd_priv_size = sizeof(struct ehci_hcd),
  22. /*
  23. * generic hardware linkage
  24. */
  25. .irq = ehci_irq,
  26. .flags = HCD_MEMORY | HCD_USB2,
  27. /*
  28. * basic lifecycle operations
  29. */
  30. .reset = ehci_setup,
  31. .start = ehci_run,
  32. .stop = ehci_stop,
  33. .shutdown = ehci_shutdown,
  34. /*
  35. * managing i/o requests and associated device resources
  36. */
  37. .urb_enqueue = ehci_urb_enqueue,
  38. .urb_dequeue = ehci_urb_dequeue,
  39. .endpoint_disable = ehci_endpoint_disable,
  40. .endpoint_reset = ehci_endpoint_reset,
  41. /*
  42. * scheduling support
  43. */
  44. .get_frame_number = ehci_get_frame,
  45. /*
  46. * root hub support
  47. */
  48. .hub_status_data = ehci_hub_status_data,
  49. .hub_control = ehci_hub_control,
  50. #ifdef CONFIG_PM
  51. .bus_suspend = ehci_bus_suspend,
  52. .bus_resume = ehci_bus_resume,
  53. #endif
  54. .relinquish_port = ehci_relinquish_port,
  55. .port_handed_over = ehci_port_handed_over,
  56. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  57. };
  58. /*
  59. * 440EPx Errata USBH_3
  60. * Fix: Enable Break Memory Transfer (BMT) in INSNREG3
  61. */
  62. #define PPC440EPX_EHCI0_INSREG_BMT (0x1 << 0)
  63. static int
  64. ppc44x_enable_bmt(struct device_node *dn)
  65. {
  66. __iomem u32 *insreg_virt;
  67. insreg_virt = of_iomap(dn, 1);
  68. if (!insreg_virt)
  69. return -EINVAL;
  70. out_be32(insreg_virt + 3, PPC440EPX_EHCI0_INSREG_BMT);
  71. iounmap(insreg_virt);
  72. return 0;
  73. }
  74. static int ehci_hcd_ppc_of_probe(struct platform_device *op)
  75. {
  76. struct device_node *dn = op->dev.of_node;
  77. struct usb_hcd *hcd;
  78. struct ehci_hcd *ehci = NULL;
  79. struct resource res;
  80. int irq;
  81. int rv;
  82. struct device_node *np;
  83. if (usb_disabled())
  84. return -ENODEV;
  85. dev_dbg(&op->dev, "initializing PPC-OF USB Controller\n");
  86. rv = of_address_to_resource(dn, 0, &res);
  87. if (rv)
  88. return rv;
  89. hcd = usb_create_hcd(&ehci_ppc_of_hc_driver, &op->dev, "PPC-OF USB");
  90. if (!hcd)
  91. return -ENOMEM;
  92. hcd->rsrc_start = res.start;
  93. hcd->rsrc_len = resource_size(&res);
  94. irq = irq_of_parse_and_map(dn, 0);
  95. if (irq == NO_IRQ) {
  96. printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
  97. rv = -EBUSY;
  98. goto err_irq;
  99. }
  100. hcd->regs = devm_ioremap_resource(&op->dev, &res);
  101. if (IS_ERR(hcd->regs)) {
  102. rv = PTR_ERR(hcd->regs);
  103. goto err_ioremap;
  104. }
  105. ehci = hcd_to_ehci(hcd);
  106. np = of_find_compatible_node(NULL, NULL, "ibm,usb-ohci-440epx");
  107. if (np != NULL) {
  108. /* claim we really affected by usb23 erratum */
  109. if (!of_address_to_resource(np, 0, &res))
  110. ehci->ohci_hcctrl_reg =
  111. devm_ioremap(&op->dev,
  112. res.start + OHCI_HCCTRL_OFFSET,
  113. OHCI_HCCTRL_LEN);
  114. else
  115. pr_debug("%s: no ohci offset in fdt\n", __FILE__);
  116. if (!ehci->ohci_hcctrl_reg) {
  117. pr_debug("%s: ioremap for ohci hcctrl failed\n", __FILE__);
  118. } else {
  119. ehci->has_amcc_usb23 = 1;
  120. }
  121. }
  122. if (of_get_property(dn, "big-endian", NULL)) {
  123. ehci->big_endian_mmio = 1;
  124. ehci->big_endian_desc = 1;
  125. }
  126. if (of_get_property(dn, "big-endian-regs", NULL))
  127. ehci->big_endian_mmio = 1;
  128. if (of_get_property(dn, "big-endian-desc", NULL))
  129. ehci->big_endian_desc = 1;
  130. ehci->caps = hcd->regs;
  131. if (of_device_is_compatible(dn, "ibm,usb-ehci-440epx")) {
  132. rv = ppc44x_enable_bmt(dn);
  133. ehci_dbg(ehci, "Break Memory Transfer (BMT) is %senabled!\n",
  134. rv ? "NOT ": "");
  135. }
  136. rv = usb_add_hcd(hcd, irq, 0);
  137. if (rv)
  138. goto err_ioremap;
  139. return 0;
  140. err_ioremap:
  141. irq_dispose_mapping(irq);
  142. err_irq:
  143. usb_put_hcd(hcd);
  144. return rv;
  145. }
  146. static int ehci_hcd_ppc_of_remove(struct platform_device *op)
  147. {
  148. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  149. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  150. struct device_node *np;
  151. struct resource res;
  152. dev_set_drvdata(&op->dev, NULL);
  153. dev_dbg(&op->dev, "stopping PPC-OF USB Controller\n");
  154. usb_remove_hcd(hcd);
  155. irq_dispose_mapping(hcd->irq);
  156. /* use request_mem_region to test if the ohci driver is loaded. if so
  157. * ensure the ohci core is operational.
  158. */
  159. if (ehci->has_amcc_usb23) {
  160. np = of_find_compatible_node(NULL, NULL, "ibm,usb-ohci-440epx");
  161. if (np != NULL) {
  162. if (!of_address_to_resource(np, 0, &res))
  163. if (!request_mem_region(res.start,
  164. 0x4, hcd_name))
  165. set_ohci_hcfs(ehci, 1);
  166. else
  167. release_mem_region(res.start, 0x4);
  168. else
  169. pr_debug("%s: no ohci offset in fdt\n", __FILE__);
  170. of_node_put(np);
  171. }
  172. }
  173. usb_put_hcd(hcd);
  174. return 0;
  175. }
  176. static void ehci_hcd_ppc_of_shutdown(struct platform_device *op)
  177. {
  178. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  179. if (hcd->driver->shutdown)
  180. hcd->driver->shutdown(hcd);
  181. }
  182. static const struct of_device_id ehci_hcd_ppc_of_match[] = {
  183. {
  184. .compatible = "usb-ehci",
  185. },
  186. {},
  187. };
  188. MODULE_DEVICE_TABLE(of, ehci_hcd_ppc_of_match);
  189. static struct platform_driver ehci_hcd_ppc_of_driver = {
  190. .probe = ehci_hcd_ppc_of_probe,
  191. .remove = ehci_hcd_ppc_of_remove,
  192. .shutdown = ehci_hcd_ppc_of_shutdown,
  193. .driver = {
  194. .name = "ppc-of-ehci",
  195. .owner = THIS_MODULE,
  196. .of_match_table = ehci_hcd_ppc_of_match,
  197. },
  198. };