ehci-orion.c 7.2 KB

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