ehci-ppc-of.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 __devinit
  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 __devinit 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. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  94. printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
  95. rv = -EBUSY;
  96. goto err_rmr;
  97. }
  98. irq = irq_of_parse_and_map(dn, 0);
  99. if (irq == NO_IRQ) {
  100. printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
  101. rv = -EBUSY;
  102. goto err_irq;
  103. }
  104. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  105. if (!hcd->regs) {
  106. printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
  107. rv = -ENOMEM;
  108. goto err_ioremap;
  109. }
  110. ehci = hcd_to_ehci(hcd);
  111. np = of_find_compatible_node(NULL, NULL, "ibm,usb-ohci-440epx");
  112. if (np != NULL) {
  113. /* claim we really affected by usb23 erratum */
  114. if (!of_address_to_resource(np, 0, &res))
  115. ehci->ohci_hcctrl_reg = ioremap(res.start +
  116. OHCI_HCCTRL_OFFSET, OHCI_HCCTRL_LEN);
  117. else
  118. pr_debug("%s: no ohci offset in fdt\n", __FILE__);
  119. if (!ehci->ohci_hcctrl_reg) {
  120. pr_debug("%s: ioremap for ohci hcctrl failed\n", __FILE__);
  121. } else {
  122. ehci->has_amcc_usb23 = 1;
  123. }
  124. }
  125. if (of_get_property(dn, "big-endian", NULL)) {
  126. ehci->big_endian_mmio = 1;
  127. ehci->big_endian_desc = 1;
  128. }
  129. if (of_get_property(dn, "big-endian-regs", NULL))
  130. ehci->big_endian_mmio = 1;
  131. if (of_get_property(dn, "big-endian-desc", NULL))
  132. ehci->big_endian_desc = 1;
  133. ehci->caps = hcd->regs;
  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)
  141. goto err_ehci;
  142. return 0;
  143. err_ehci:
  144. if (ehci->has_amcc_usb23)
  145. iounmap(ehci->ohci_hcctrl_reg);
  146. iounmap(hcd->regs);
  147. err_ioremap:
  148. irq_dispose_mapping(irq);
  149. err_irq:
  150. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  151. err_rmr:
  152. usb_put_hcd(hcd);
  153. return rv;
  154. }
  155. static int ehci_hcd_ppc_of_remove(struct platform_device *op)
  156. {
  157. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  158. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  159. struct device_node *np;
  160. struct resource res;
  161. dev_set_drvdata(&op->dev, NULL);
  162. dev_dbg(&op->dev, "stopping PPC-OF USB Controller\n");
  163. usb_remove_hcd(hcd);
  164. iounmap(hcd->regs);
  165. irq_dispose_mapping(hcd->irq);
  166. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  167. /* use request_mem_region to test if the ohci driver is loaded. if so
  168. * ensure the ohci core is operational.
  169. */
  170. if (ehci->has_amcc_usb23) {
  171. np = of_find_compatible_node(NULL, NULL, "ibm,usb-ohci-440epx");
  172. if (np != NULL) {
  173. if (!of_address_to_resource(np, 0, &res))
  174. if (!request_mem_region(res.start,
  175. 0x4, hcd_name))
  176. set_ohci_hcfs(ehci, 1);
  177. else
  178. release_mem_region(res.start, 0x4);
  179. else
  180. pr_debug("%s: no ohci offset in fdt\n", __FILE__);
  181. of_node_put(np);
  182. }
  183. iounmap(ehci->ohci_hcctrl_reg);
  184. }
  185. usb_put_hcd(hcd);
  186. return 0;
  187. }
  188. static void ehci_hcd_ppc_of_shutdown(struct platform_device *op)
  189. {
  190. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  191. if (hcd->driver->shutdown)
  192. hcd->driver->shutdown(hcd);
  193. }
  194. static const struct of_device_id ehci_hcd_ppc_of_match[] = {
  195. {
  196. .compatible = "usb-ehci",
  197. },
  198. {},
  199. };
  200. MODULE_DEVICE_TABLE(of, ehci_hcd_ppc_of_match);
  201. static struct platform_driver ehci_hcd_ppc_of_driver = {
  202. .probe = ehci_hcd_ppc_of_probe,
  203. .remove = ehci_hcd_ppc_of_remove,
  204. .shutdown = ehci_hcd_ppc_of_shutdown,
  205. .driver = {
  206. .name = "ppc-of-ehci",
  207. .owner = THIS_MODULE,
  208. .of_match_table = ehci_hcd_ppc_of_match,
  209. },
  210. };