ehci-orion.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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 <linux/mbus.h>
  14. #include <plat/ehci-orion.h>
  15. #define rdl(off) __raw_readl(hcd->regs + (off))
  16. #define wrl(off, val) __raw_writel((val), hcd->regs + (off))
  17. #define USB_CMD 0x140
  18. #define USB_MODE 0x1a8
  19. #define USB_CAUSE 0x310
  20. #define USB_MASK 0x314
  21. #define USB_WINDOW_CTRL(i) (0x320 + ((i) << 4))
  22. #define USB_WINDOW_BASE(i) (0x324 + ((i) << 4))
  23. #define USB_IPG 0x360
  24. #define USB_PHY_PWR_CTRL 0x400
  25. #define USB_PHY_TX_CTRL 0x420
  26. #define USB_PHY_RX_CTRL 0x430
  27. #define USB_PHY_IVREF_CTRL 0x440
  28. #define USB_PHY_TST_GRP_CTRL 0x450
  29. /*
  30. * Implement Orion USB controller specification guidelines
  31. */
  32. static void orion_usb_phy_v1_setup(struct usb_hcd *hcd)
  33. {
  34. /* The below GLs are according to the Orion Errata document */
  35. /*
  36. * Clear interrupt cause and mask
  37. */
  38. wrl(USB_CAUSE, 0);
  39. wrl(USB_MASK, 0);
  40. /*
  41. * Reset controller
  42. */
  43. wrl(USB_CMD, rdl(USB_CMD) | 0x2);
  44. while (rdl(USB_CMD) & 0x2);
  45. /*
  46. * GL# USB-10: Set IPG for non start of frame packets
  47. * Bits[14:8]=0xc
  48. */
  49. wrl(USB_IPG, (rdl(USB_IPG) & ~0x7f00) | 0xc00);
  50. /*
  51. * GL# USB-9: USB 2.0 Power Control
  52. * BG_VSEL[7:6]=0x1
  53. */
  54. wrl(USB_PHY_PWR_CTRL, (rdl(USB_PHY_PWR_CTRL) & ~0xc0)| 0x40);
  55. /*
  56. * GL# USB-1: USB PHY Tx Control - force calibration to '8'
  57. * TXDATA_BLOCK_EN[21]=0x1, EXT_RCAL_EN[13]=0x1, IMP_CAL[6:3]=0x8
  58. */
  59. wrl(USB_PHY_TX_CTRL, (rdl(USB_PHY_TX_CTRL) & ~0x78) | 0x202040);
  60. /*
  61. * GL# USB-3 GL# USB-9: USB PHY Rx Control
  62. * RXDATA_BLOCK_LENGHT[31:30]=0x3, EDGE_DET_SEL[27:26]=0,
  63. * CDR_FASTLOCK_EN[21]=0, DISCON_THRESHOLD[9:8]=0, SQ_THRESH[7:4]=0x1
  64. */
  65. wrl(USB_PHY_RX_CTRL, (rdl(USB_PHY_RX_CTRL) & ~0xc2003f0) | 0xc0000010);
  66. /*
  67. * GL# USB-3 GL# USB-9: USB PHY IVREF Control
  68. * PLLVDD12[1:0]=0x2, RXVDD[5:4]=0x3, Reserved[19]=0
  69. */
  70. wrl(USB_PHY_IVREF_CTRL, (rdl(USB_PHY_IVREF_CTRL) & ~0x80003 ) | 0x32);
  71. /*
  72. * GL# USB-3 GL# USB-9: USB PHY Test Group Control
  73. * REG_FIFO_SQ_RST[15]=0
  74. */
  75. wrl(USB_PHY_TST_GRP_CTRL, rdl(USB_PHY_TST_GRP_CTRL) & ~0x8000);
  76. /*
  77. * Stop and reset controller
  78. */
  79. wrl(USB_CMD, rdl(USB_CMD) & ~0x1);
  80. wrl(USB_CMD, rdl(USB_CMD) | 0x2);
  81. while (rdl(USB_CMD) & 0x2);
  82. /*
  83. * GL# USB-5 Streaming disable REG_USB_MODE[4]=1
  84. * TBD: This need to be done after each reset!
  85. * GL# USB-4 Setup USB Host mode
  86. */
  87. wrl(USB_MODE, 0x13);
  88. }
  89. static int ehci_orion_setup(struct usb_hcd *hcd)
  90. {
  91. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  92. int retval;
  93. retval = ehci_halt(ehci);
  94. if (retval)
  95. return retval;
  96. /*
  97. * data structure init
  98. */
  99. retval = ehci_init(hcd);
  100. if (retval)
  101. return retval;
  102. hcd->has_tt = 1;
  103. ehci_reset(ehci);
  104. ehci_port_power(ehci, 0);
  105. return retval;
  106. }
  107. static const struct hc_driver ehci_orion_hc_driver = {
  108. .description = hcd_name,
  109. .product_desc = "Marvell Orion EHCI",
  110. .hcd_priv_size = sizeof(struct ehci_hcd),
  111. /*
  112. * generic hardware linkage
  113. */
  114. .irq = ehci_irq,
  115. .flags = HCD_MEMORY | HCD_USB2,
  116. /*
  117. * basic lifecycle operations
  118. */
  119. .reset = ehci_orion_setup,
  120. .start = ehci_run,
  121. .stop = ehci_stop,
  122. .shutdown = ehci_shutdown,
  123. /*
  124. * managing i/o requests and associated device resources
  125. */
  126. .urb_enqueue = ehci_urb_enqueue,
  127. .urb_dequeue = ehci_urb_dequeue,
  128. .endpoint_disable = ehci_endpoint_disable,
  129. .endpoint_reset = ehci_endpoint_reset,
  130. /*
  131. * scheduling support
  132. */
  133. .get_frame_number = ehci_get_frame,
  134. /*
  135. * root hub support
  136. */
  137. .hub_status_data = ehci_hub_status_data,
  138. .hub_control = ehci_hub_control,
  139. .bus_suspend = ehci_bus_suspend,
  140. .bus_resume = ehci_bus_resume,
  141. .relinquish_port = ehci_relinquish_port,
  142. .port_handed_over = ehci_port_handed_over,
  143. };
  144. static void __init
  145. ehci_orion_conf_mbus_windows(struct usb_hcd *hcd,
  146. struct mbus_dram_target_info *dram)
  147. {
  148. int i;
  149. for (i = 0; i < 4; i++) {
  150. wrl(USB_WINDOW_CTRL(i), 0);
  151. wrl(USB_WINDOW_BASE(i), 0);
  152. }
  153. for (i = 0; i < dram->num_cs; i++) {
  154. struct mbus_dram_window *cs = dram->cs + i;
  155. wrl(USB_WINDOW_CTRL(i), ((cs->size - 1) & 0xffff0000) |
  156. (cs->mbus_attr << 8) |
  157. (dram->mbus_dram_target_id << 4) | 1);
  158. wrl(USB_WINDOW_BASE(i), cs->base);
  159. }
  160. }
  161. static int __devinit ehci_orion_drv_probe(struct platform_device *pdev)
  162. {
  163. struct orion_ehci_data *pd = pdev->dev.platform_data;
  164. struct resource *res;
  165. struct usb_hcd *hcd;
  166. struct ehci_hcd *ehci;
  167. void __iomem *regs;
  168. int irq, err;
  169. if (usb_disabled())
  170. return -ENODEV;
  171. pr_debug("Initializing Orion-SoC USB Host Controller\n");
  172. irq = platform_get_irq(pdev, 0);
  173. if (irq <= 0) {
  174. dev_err(&pdev->dev,
  175. "Found HC with no IRQ. Check %s setup!\n",
  176. dev_name(&pdev->dev));
  177. err = -ENODEV;
  178. goto err1;
  179. }
  180. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  181. if (!res) {
  182. dev_err(&pdev->dev,
  183. "Found HC with no register addr. Check %s setup!\n",
  184. dev_name(&pdev->dev));
  185. err = -ENODEV;
  186. goto err1;
  187. }
  188. if (!request_mem_region(res->start, res->end - res->start + 1,
  189. ehci_orion_hc_driver.description)) {
  190. dev_dbg(&pdev->dev, "controller already in use\n");
  191. err = -EBUSY;
  192. goto err1;
  193. }
  194. regs = ioremap(res->start, res->end - res->start + 1);
  195. if (regs == NULL) {
  196. dev_dbg(&pdev->dev, "error mapping memory\n");
  197. err = -EFAULT;
  198. goto err2;
  199. }
  200. hcd = usb_create_hcd(&ehci_orion_hc_driver,
  201. &pdev->dev, dev_name(&pdev->dev));
  202. if (!hcd) {
  203. err = -ENOMEM;
  204. goto err3;
  205. }
  206. hcd->rsrc_start = res->start;
  207. hcd->rsrc_len = res->end - res->start + 1;
  208. hcd->regs = regs;
  209. ehci = hcd_to_ehci(hcd);
  210. ehci->caps = hcd->regs + 0x100;
  211. ehci->regs = hcd->regs + 0x100 +
  212. HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  213. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  214. hcd->has_tt = 1;
  215. ehci->sbrn = 0x20;
  216. /*
  217. * (Re-)program MBUS remapping windows if we are asked to.
  218. */
  219. if (pd != NULL && pd->dram != NULL)
  220. ehci_orion_conf_mbus_windows(hcd, pd->dram);
  221. /*
  222. * setup Orion USB controller.
  223. */
  224. switch (pd->phy_version) {
  225. case EHCI_PHY_NA: /* dont change USB phy settings */
  226. break;
  227. case EHCI_PHY_ORION:
  228. orion_usb_phy_v1_setup(hcd);
  229. break;
  230. case EHCI_PHY_DD:
  231. case EHCI_PHY_KW:
  232. default:
  233. printk(KERN_WARNING "Orion ehci -USB phy version isn't supported.\n");
  234. }
  235. err = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_DISABLED);
  236. if (err)
  237. goto err4;
  238. return 0;
  239. err4:
  240. usb_put_hcd(hcd);
  241. err3:
  242. iounmap(regs);
  243. err2:
  244. release_mem_region(res->start, res->end - res->start + 1);
  245. err1:
  246. dev_err(&pdev->dev, "init %s fail, %d\n",
  247. dev_name(&pdev->dev), err);
  248. return err;
  249. }
  250. static int __exit ehci_orion_drv_remove(struct platform_device *pdev)
  251. {
  252. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  253. usb_remove_hcd(hcd);
  254. iounmap(hcd->regs);
  255. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  256. usb_put_hcd(hcd);
  257. return 0;
  258. }
  259. MODULE_ALIAS("platform:orion-ehci");
  260. static struct platform_driver ehci_orion_driver = {
  261. .probe = ehci_orion_drv_probe,
  262. .remove = __exit_p(ehci_orion_drv_remove),
  263. .shutdown = usb_hcd_platform_shutdown,
  264. .driver.name = "orion-ehci",
  265. };