ehci-ppc-of.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. .endpoint_reset = ehci_endpoint_reset,
  54. /*
  55. * scheduling support
  56. */
  57. .get_frame_number = ehci_get_frame,
  58. /*
  59. * root hub support
  60. */
  61. .hub_status_data = ehci_hub_status_data,
  62. .hub_control = ehci_hub_control,
  63. #ifdef CONFIG_PM
  64. .bus_suspend = ehci_bus_suspend,
  65. .bus_resume = ehci_bus_resume,
  66. #endif
  67. .relinquish_port = ehci_relinquish_port,
  68. .port_handed_over = ehci_port_handed_over,
  69. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  70. };
  71. /*
  72. * 440EPx Errata USBH_3
  73. * Fix: Enable Break Memory Transfer (BMT) in INSNREG3
  74. */
  75. #define PPC440EPX_EHCI0_INSREG_BMT (0x1 << 0)
  76. static int __devinit
  77. ppc44x_enable_bmt(struct device_node *dn)
  78. {
  79. __iomem u32 *insreg_virt;
  80. insreg_virt = of_iomap(dn, 1);
  81. if (!insreg_virt)
  82. return -EINVAL;
  83. out_be32(insreg_virt + 3, PPC440EPX_EHCI0_INSREG_BMT);
  84. iounmap(insreg_virt);
  85. return 0;
  86. }
  87. static int __devinit
  88. ehci_hcd_ppc_of_probe(struct platform_device *op, const struct of_device_id *match)
  89. {
  90. struct device_node *dn = op->dev.of_node;
  91. struct usb_hcd *hcd;
  92. struct ehci_hcd *ehci = NULL;
  93. struct resource res;
  94. int irq;
  95. int rv;
  96. struct device_node *np;
  97. if (usb_disabled())
  98. return -ENODEV;
  99. dev_dbg(&op->dev, "initializing PPC-OF USB Controller\n");
  100. rv = of_address_to_resource(dn, 0, &res);
  101. if (rv)
  102. return rv;
  103. hcd = usb_create_hcd(&ehci_ppc_of_hc_driver, &op->dev, "PPC-OF USB");
  104. if (!hcd)
  105. return -ENOMEM;
  106. hcd->rsrc_start = res.start;
  107. hcd->rsrc_len = res.end - res.start + 1;
  108. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  109. printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
  110. rv = -EBUSY;
  111. goto err_rmr;
  112. }
  113. irq = irq_of_parse_and_map(dn, 0);
  114. if (irq == NO_IRQ) {
  115. printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
  116. rv = -EBUSY;
  117. goto err_irq;
  118. }
  119. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  120. if (!hcd->regs) {
  121. printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
  122. rv = -ENOMEM;
  123. goto err_ioremap;
  124. }
  125. ehci = hcd_to_ehci(hcd);
  126. np = of_find_compatible_node(NULL, NULL, "ibm,usb-ohci-440epx");
  127. if (np != NULL) {
  128. /* claim we really affected by usb23 erratum */
  129. if (!of_address_to_resource(np, 0, &res))
  130. ehci->ohci_hcctrl_reg = ioremap(res.start +
  131. OHCI_HCCTRL_OFFSET, OHCI_HCCTRL_LEN);
  132. else
  133. pr_debug("%s: no ohci offset in fdt\n", __FILE__);
  134. if (!ehci->ohci_hcctrl_reg) {
  135. pr_debug("%s: ioremap for ohci hcctrl failed\n", __FILE__);
  136. } else {
  137. ehci->has_amcc_usb23 = 1;
  138. }
  139. }
  140. if (of_get_property(dn, "big-endian", NULL)) {
  141. ehci->big_endian_mmio = 1;
  142. ehci->big_endian_desc = 1;
  143. }
  144. if (of_get_property(dn, "big-endian-regs", NULL))
  145. ehci->big_endian_mmio = 1;
  146. if (of_get_property(dn, "big-endian-desc", NULL))
  147. ehci->big_endian_desc = 1;
  148. ehci->caps = hcd->regs;
  149. ehci->regs = hcd->regs +
  150. HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  151. /* cache this readonly data; minimize chip reads */
  152. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  153. if (of_device_is_compatible(dn, "ibm,usb-ehci-440epx")) {
  154. rv = ppc44x_enable_bmt(dn);
  155. ehci_dbg(ehci, "Break Memory Transfer (BMT) is %senabled!\n",
  156. rv ? "NOT ": "");
  157. }
  158. rv = usb_add_hcd(hcd, irq, 0);
  159. if (rv)
  160. goto err_ehci;
  161. return 0;
  162. err_ehci:
  163. if (ehci->has_amcc_usb23)
  164. iounmap(ehci->ohci_hcctrl_reg);
  165. iounmap(hcd->regs);
  166. err_ioremap:
  167. irq_dispose_mapping(irq);
  168. err_irq:
  169. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  170. err_rmr:
  171. usb_put_hcd(hcd);
  172. return rv;
  173. }
  174. static int ehci_hcd_ppc_of_remove(struct platform_device *op)
  175. {
  176. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  177. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  178. struct device_node *np;
  179. struct resource res;
  180. dev_set_drvdata(&op->dev, NULL);
  181. dev_dbg(&op->dev, "stopping PPC-OF USB Controller\n");
  182. usb_remove_hcd(hcd);
  183. iounmap(hcd->regs);
  184. irq_dispose_mapping(hcd->irq);
  185. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  186. /* use request_mem_region to test if the ohci driver is loaded. if so
  187. * ensure the ohci core is operational.
  188. */
  189. if (ehci->has_amcc_usb23) {
  190. np = of_find_compatible_node(NULL, NULL, "ibm,usb-ohci-440epx");
  191. if (np != NULL) {
  192. if (!of_address_to_resource(np, 0, &res))
  193. if (!request_mem_region(res.start,
  194. 0x4, hcd_name))
  195. set_ohci_hcfs(ehci, 1);
  196. else
  197. release_mem_region(res.start, 0x4);
  198. else
  199. pr_debug("%s: no ohci offset in fdt\n", __FILE__);
  200. of_node_put(np);
  201. }
  202. iounmap(ehci->ohci_hcctrl_reg);
  203. }
  204. usb_put_hcd(hcd);
  205. return 0;
  206. }
  207. static int ehci_hcd_ppc_of_shutdown(struct platform_device *op)
  208. {
  209. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  210. if (hcd->driver->shutdown)
  211. hcd->driver->shutdown(hcd);
  212. return 0;
  213. }
  214. static const struct of_device_id ehci_hcd_ppc_of_match[] = {
  215. {
  216. .compatible = "usb-ehci",
  217. },
  218. {},
  219. };
  220. MODULE_DEVICE_TABLE(of, ehci_hcd_ppc_of_match);
  221. static struct of_platform_driver ehci_hcd_ppc_of_driver = {
  222. .probe = ehci_hcd_ppc_of_probe,
  223. .remove = ehci_hcd_ppc_of_remove,
  224. .shutdown = ehci_hcd_ppc_of_shutdown,
  225. .driver = {
  226. .name = "ppc-of-ehci",
  227. .owner = THIS_MODULE,
  228. .of_match_table = ehci_hcd_ppc_of_match,
  229. },
  230. };