ehci-ppc-of.c 6.1 KB

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