ehci-orion.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * drivers/usb/host/ehci-orion.c
  3. *
  4. * Tzachi Perelstein <tzachi@marvell.com>
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/platform_device.h>
  13. #include <asm/arch/orion.h>
  14. #define rdl(off) __raw_readl(hcd->regs + (off))
  15. #define wrl(off, val) __raw_writel((val), hcd->regs + (off))
  16. #define USB_CAUSE 0x310
  17. #define USB_MASK 0x314
  18. #define USB_CMD 0x140
  19. #define USB_MODE 0x1a8
  20. #define USB_IPG 0x360
  21. #define USB_PHY_PWR_CTRL 0x400
  22. #define USB_PHY_TX_CTRL 0x420
  23. #define USB_PHY_RX_CTRL 0x430
  24. #define USB_PHY_IVREF_CTRL 0x440
  25. #define USB_PHY_TST_GRP_CTRL 0x450
  26. /*
  27. * Implement Orion USB controller specification guidelines
  28. */
  29. static void orion_usb_setup(struct usb_hcd *hcd)
  30. {
  31. /*
  32. * Clear interrupt cause and mask
  33. */
  34. wrl(USB_CAUSE, 0);
  35. wrl(USB_MASK, 0);
  36. /*
  37. * Reset controller
  38. */
  39. wrl(USB_CMD, rdl(USB_CMD) | 0x2);
  40. while (rdl(USB_CMD) & 0x2);
  41. /*
  42. * GL# USB-10: Set IPG for non start of frame packets
  43. * Bits[14:8]=0xc
  44. */
  45. wrl(USB_IPG, (rdl(USB_IPG) & ~0x7f00) | 0xc00);
  46. /*
  47. * GL# USB-9: USB 2.0 Power Control
  48. * BG_VSEL[7:6]=0x1
  49. */
  50. wrl(USB_PHY_PWR_CTRL, (rdl(USB_PHY_PWR_CTRL) & ~0xc0)| 0x40);
  51. /*
  52. * GL# USB-1: USB PHY Tx Control - force calibration to '8'
  53. * TXDATA_BLOCK_EN[21]=0x1, EXT_RCAL_EN[13]=0x1, IMP_CAL[6:3]=0x8
  54. */
  55. wrl(USB_PHY_TX_CTRL, (rdl(USB_PHY_TX_CTRL) & ~0x78) | 0x202040);
  56. /*
  57. * GL# USB-3 GL# USB-9: USB PHY Rx Control
  58. * RXDATA_BLOCK_LENGHT[31:30]=0x3, EDGE_DET_SEL[27:26]=0,
  59. * CDR_FASTLOCK_EN[21]=0, DISCON_THRESHOLD[9:8]=0, SQ_THRESH[7:4]=0x1
  60. */
  61. wrl(USB_PHY_RX_CTRL, (rdl(USB_PHY_RX_CTRL) & ~0xc2003f0) | 0xc0000010);
  62. /*
  63. * GL# USB-3 GL# USB-9: USB PHY IVREF Control
  64. * PLLVDD12[1:0]=0x2, RXVDD[5:4]=0x3, Reserved[19]=0
  65. */
  66. wrl(USB_PHY_IVREF_CTRL, (rdl(USB_PHY_IVREF_CTRL) & ~0x80003 ) | 0x32);
  67. /*
  68. * GL# USB-3 GL# USB-9: USB PHY Test Group Control
  69. * REG_FIFO_SQ_RST[15]=0
  70. */
  71. wrl(USB_PHY_TST_GRP_CTRL, rdl(USB_PHY_TST_GRP_CTRL) & ~0x8000);
  72. /*
  73. * Stop and reset controller
  74. */
  75. wrl(USB_CMD, rdl(USB_CMD) & ~0x1);
  76. wrl(USB_CMD, rdl(USB_CMD) | 0x2);
  77. while (rdl(USB_CMD) & 0x2);
  78. /*
  79. * GL# USB-5 Streaming disable REG_USB_MODE[4]=1
  80. * TBD: This need to be done after each reset!
  81. * GL# USB-4 Setup USB Host mode
  82. */
  83. wrl(USB_MODE, 0x13);
  84. }
  85. static int ehci_orion_setup(struct usb_hcd *hcd)
  86. {
  87. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  88. int retval;
  89. retval = ehci_halt(ehci);
  90. if (retval)
  91. return retval;
  92. /*
  93. * data structure init
  94. */
  95. retval = ehci_init(hcd);
  96. if (retval)
  97. return retval;
  98. ehci_reset(ehci);
  99. ehci_port_power(ehci, 0);
  100. return retval;
  101. }
  102. static const struct hc_driver ehci_orion_hc_driver = {
  103. .description = hcd_name,
  104. .product_desc = "Marvell Orion EHCI",
  105. .hcd_priv_size = sizeof(struct ehci_hcd),
  106. /*
  107. * generic hardware linkage
  108. */
  109. .irq = ehci_irq,
  110. .flags = HCD_MEMORY | HCD_USB2,
  111. /*
  112. * basic lifecycle operations
  113. */
  114. .reset = ehci_orion_setup,
  115. .start = ehci_run,
  116. #ifdef CONFIG_PM
  117. .suspend = ehci_bus_suspend,
  118. .resume = ehci_bus_resume,
  119. #endif
  120. .stop = ehci_stop,
  121. .shutdown = ehci_shutdown,
  122. /*
  123. * managing i/o requests and associated device resources
  124. */
  125. .urb_enqueue = ehci_urb_enqueue,
  126. .urb_dequeue = ehci_urb_dequeue,
  127. .endpoint_disable = ehci_endpoint_disable,
  128. /*
  129. * scheduling support
  130. */
  131. .get_frame_number = ehci_get_frame,
  132. /*
  133. * root hub support
  134. */
  135. .hub_status_data = ehci_hub_status_data,
  136. .hub_control = ehci_hub_control,
  137. .bus_suspend = ehci_bus_suspend,
  138. .bus_resume = ehci_bus_resume,
  139. };
  140. static int __init ehci_orion_drv_probe(struct platform_device *pdev)
  141. {
  142. struct resource *res;
  143. struct usb_hcd *hcd;
  144. struct ehci_hcd *ehci;
  145. void __iomem *regs;
  146. int irq, err;
  147. if (usb_disabled())
  148. return -ENODEV;
  149. pr_debug("Initializing Orion-SoC USB Host Controller\n");
  150. irq = platform_get_irq(pdev, 0);
  151. if (irq <= 0) {
  152. dev_err(&pdev->dev,
  153. "Found HC with no IRQ. Check %s setup!\n",
  154. pdev->dev.bus_id);
  155. err = -ENODEV;
  156. goto err1;
  157. }
  158. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  159. if (!res) {
  160. dev_err(&pdev->dev,
  161. "Found HC with no register addr. Check %s setup!\n",
  162. pdev->dev.bus_id);
  163. err = -ENODEV;
  164. goto err1;
  165. }
  166. if (!request_mem_region(res->start, res->end - res->start + 1,
  167. ehci_orion_hc_driver.description)) {
  168. dev_dbg(&pdev->dev, "controller already in use\n");
  169. err = -EBUSY;
  170. goto err1;
  171. }
  172. regs = ioremap(res->start, res->end - res->start + 1);
  173. if (regs == NULL) {
  174. dev_dbg(&pdev->dev, "error mapping memory\n");
  175. err = -EFAULT;
  176. goto err2;
  177. }
  178. hcd = usb_create_hcd(&ehci_orion_hc_driver,
  179. &pdev->dev, pdev->dev.bus_id);
  180. if (!hcd) {
  181. err = -ENOMEM;
  182. goto err3;
  183. }
  184. hcd->rsrc_start = res->start;
  185. hcd->rsrc_len = res->end - res->start + 1;
  186. hcd->regs = regs;
  187. ehci = hcd_to_ehci(hcd);
  188. ehci->caps = hcd->regs + 0x100;
  189. ehci->regs = hcd->regs + 0x100 +
  190. HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  191. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  192. ehci->is_tdi_rh_tt = 1;
  193. ehci->sbrn = 0x20;
  194. /*
  195. * setup Orion USB controller
  196. */
  197. orion_usb_setup(hcd);
  198. err = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_DISABLED);
  199. if (err)
  200. goto err4;
  201. return 0;
  202. err4:
  203. usb_put_hcd(hcd);
  204. err3:
  205. iounmap(regs);
  206. err2:
  207. release_mem_region(res->start, res->end - res->start + 1);
  208. err1:
  209. dev_err(&pdev->dev, "init %s fail, %d\n",
  210. pdev->dev.bus_id, err);
  211. return err;
  212. }
  213. static int __exit ehci_orion_drv_remove(struct platform_device *pdev)
  214. {
  215. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  216. usb_remove_hcd(hcd);
  217. iounmap(hcd->regs);
  218. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  219. usb_put_hcd(hcd);
  220. return 0;
  221. }
  222. MODULE_ALIAS("platform:orion-ehci");
  223. static struct platform_driver ehci_orion_driver = {
  224. .probe = ehci_orion_drv_probe,
  225. .remove = __exit_p(ehci_orion_drv_remove),
  226. .shutdown = usb_hcd_platform_shutdown,
  227. .driver.name = "orion-ehci",
  228. };