ehci-orion.c 8.1 KB

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