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/signal.h>
  15. #include <linux/of.h>
  16. #include <linux/of_platform.h>
  17. static const struct hc_driver ehci_ppc_of_hc_driver = {
  18. .description = hcd_name,
  19. .product_desc = "OF EHCI",
  20. .hcd_priv_size = sizeof(struct ehci_hcd),
  21. /*
  22. * generic hardware linkage
  23. */
  24. .irq = ehci_irq,
  25. .flags = HCD_MEMORY | HCD_USB2,
  26. /*
  27. * basic lifecycle operations
  28. */
  29. .reset = ehci_setup,
  30. .start = ehci_run,
  31. .stop = ehci_stop,
  32. .shutdown = ehci_shutdown,
  33. /*
  34. * managing i/o requests and associated device resources
  35. */
  36. .urb_enqueue = ehci_urb_enqueue,
  37. .urb_dequeue = ehci_urb_dequeue,
  38. .endpoint_disable = ehci_endpoint_disable,
  39. .endpoint_reset = ehci_endpoint_reset,
  40. /*
  41. * scheduling support
  42. */
  43. .get_frame_number = ehci_get_frame,
  44. /*
  45. * root hub support
  46. */
  47. .hub_status_data = ehci_hub_status_data,
  48. .hub_control = ehci_hub_control,
  49. #ifdef CONFIG_PM
  50. .bus_suspend = ehci_bus_suspend,
  51. .bus_resume = ehci_bus_resume,
  52. #endif
  53. .relinquish_port = ehci_relinquish_port,
  54. .port_handed_over = ehci_port_handed_over,
  55. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  56. };
  57. /*
  58. * 440EPx Errata USBH_3
  59. * Fix: Enable Break Memory Transfer (BMT) in INSNREG3
  60. */
  61. #define PPC440EPX_EHCI0_INSREG_BMT (0x1 << 0)
  62. static int
  63. ppc44x_enable_bmt(struct device_node *dn)
  64. {
  65. __iomem u32 *insreg_virt;
  66. insreg_virt = of_iomap(dn, 1);
  67. if (!insreg_virt)
  68. return -EINVAL;
  69. out_be32(insreg_virt + 3, PPC440EPX_EHCI0_INSREG_BMT);
  70. iounmap(insreg_virt);
  71. return 0;
  72. }
  73. static int ehci_hcd_ppc_of_probe(struct platform_device *op)
  74. {
  75. struct device_node *dn = op->dev.of_node;
  76. struct usb_hcd *hcd;
  77. struct ehci_hcd *ehci = NULL;
  78. struct resource res;
  79. int irq;
  80. int rv;
  81. struct device_node *np;
  82. if (usb_disabled())
  83. return -ENODEV;
  84. dev_dbg(&op->dev, "initializing PPC-OF USB Controller\n");
  85. rv = of_address_to_resource(dn, 0, &res);
  86. if (rv)
  87. return rv;
  88. hcd = usb_create_hcd(&ehci_ppc_of_hc_driver, &op->dev, "PPC-OF USB");
  89. if (!hcd)
  90. return -ENOMEM;
  91. hcd->rsrc_start = res.start;
  92. hcd->rsrc_len = resource_size(&res);
  93. irq = irq_of_parse_and_map(dn, 0);
  94. if (irq == NO_IRQ) {
  95. printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
  96. rv = -EBUSY;
  97. goto err_irq;
  98. }
  99. hcd->regs = devm_request_and_ioremap(&op->dev, &res);
  100. if (!hcd->regs) {
  101. pr_err("%s: devm_request_and_ioremap failed\n", __FILE__);
  102. rv = -ENOMEM;
  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. };