ehci-ppc-of.c 6.2 KB

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