ehci-orion.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. hcd->has_tt = 1;
  95. retval = ehci_halt(ehci);
  96. if (retval)
  97. return retval;
  98. /*
  99. * data structure init
  100. */
  101. retval = ehci_init(hcd);
  102. if (retval)
  103. return retval;
  104. ehci_reset(ehci);
  105. ehci_port_power(ehci, 0);
  106. return retval;
  107. }
  108. static const struct hc_driver ehci_orion_hc_driver = {
  109. .description = hcd_name,
  110. .product_desc = "Marvell Orion EHCI",
  111. .hcd_priv_size = sizeof(struct ehci_hcd),
  112. /*
  113. * generic hardware linkage
  114. */
  115. .irq = ehci_irq,
  116. .flags = HCD_MEMORY | HCD_USB2,
  117. /*
  118. * basic lifecycle operations
  119. */
  120. .reset = ehci_orion_setup,
  121. .start = ehci_run,
  122. .stop = ehci_stop,
  123. .shutdown = ehci_shutdown,
  124. /*
  125. * managing i/o requests and associated device resources
  126. */
  127. .urb_enqueue = ehci_urb_enqueue,
  128. .urb_dequeue = ehci_urb_dequeue,
  129. .endpoint_disable = ehci_endpoint_disable,
  130. .endpoint_reset = ehci_endpoint_reset,
  131. /*
  132. * scheduling support
  133. */
  134. .get_frame_number = ehci_get_frame,
  135. /*
  136. * root hub support
  137. */
  138. .hub_status_data = ehci_hub_status_data,
  139. .hub_control = ehci_hub_control,
  140. .bus_suspend = ehci_bus_suspend,
  141. .bus_resume = ehci_bus_resume,
  142. .relinquish_port = ehci_relinquish_port,
  143. .port_handed_over = ehci_port_handed_over,
  144. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  145. };
  146. static void __init
  147. ehci_orion_conf_mbus_windows(struct usb_hcd *hcd,
  148. const struct mbus_dram_target_info *dram)
  149. {
  150. int i;
  151. for (i = 0; i < 4; i++) {
  152. wrl(USB_WINDOW_CTRL(i), 0);
  153. wrl(USB_WINDOW_BASE(i), 0);
  154. }
  155. for (i = 0; i < dram->num_cs; i++) {
  156. const struct mbus_dram_window *cs = dram->cs + i;
  157. wrl(USB_WINDOW_CTRL(i), ((cs->size - 1) & 0xffff0000) |
  158. (cs->mbus_attr << 8) |
  159. (dram->mbus_dram_target_id << 4) | 1);
  160. wrl(USB_WINDOW_BASE(i), cs->base);
  161. }
  162. }
  163. static int __devinit ehci_orion_drv_probe(struct platform_device *pdev)
  164. {
  165. struct orion_ehci_data *pd = pdev->dev.platform_data;
  166. const struct mbus_dram_target_info *dram;
  167. struct resource *res;
  168. struct usb_hcd *hcd;
  169. struct ehci_hcd *ehci;
  170. struct clk *clk;
  171. void __iomem *regs;
  172. int irq, err;
  173. if (usb_disabled())
  174. return -ENODEV;
  175. pr_debug("Initializing Orion-SoC USB Host Controller\n");
  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. if (!request_mem_region(res->start, resource_size(res),
  193. ehci_orion_hc_driver.description)) {
  194. dev_dbg(&pdev->dev, "controller already in use\n");
  195. err = -EBUSY;
  196. goto err1;
  197. }
  198. regs = ioremap(res->start, resource_size(res));
  199. if (regs == NULL) {
  200. dev_dbg(&pdev->dev, "error mapping memory\n");
  201. err = -EFAULT;
  202. goto err2;
  203. }
  204. /* Not all platforms can gate the clock, so it is not
  205. an error if the clock does not exists. */
  206. clk = clk_get(&pdev->dev, NULL);
  207. if (!IS_ERR(clk)) {
  208. clk_prepare_enable(clk);
  209. clk_put(clk);
  210. }
  211. hcd = usb_create_hcd(&ehci_orion_hc_driver,
  212. &pdev->dev, dev_name(&pdev->dev));
  213. if (!hcd) {
  214. err = -ENOMEM;
  215. goto err3;
  216. }
  217. hcd->rsrc_start = res->start;
  218. hcd->rsrc_len = resource_size(res);
  219. hcd->regs = regs;
  220. ehci = hcd_to_ehci(hcd);
  221. ehci->caps = hcd->regs + 0x100;
  222. ehci->regs = hcd->regs + 0x100 +
  223. HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  224. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  225. hcd->has_tt = 1;
  226. ehci->sbrn = 0x20;
  227. /*
  228. * (Re-)program MBUS remapping windows if we are asked to.
  229. */
  230. dram = mv_mbus_dram_info();
  231. if (dram)
  232. ehci_orion_conf_mbus_windows(hcd, dram);
  233. /*
  234. * setup Orion USB controller.
  235. */
  236. switch (pd->phy_version) {
  237. case EHCI_PHY_NA: /* dont change USB phy settings */
  238. break;
  239. case EHCI_PHY_ORION:
  240. orion_usb_phy_v1_setup(hcd);
  241. break;
  242. case EHCI_PHY_DD:
  243. case EHCI_PHY_KW:
  244. default:
  245. printk(KERN_WARNING "Orion ehci -USB phy version isn't supported.\n");
  246. }
  247. err = usb_add_hcd(hcd, irq, IRQF_SHARED);
  248. if (err)
  249. goto err4;
  250. return 0;
  251. err4:
  252. usb_put_hcd(hcd);
  253. err3:
  254. iounmap(regs);
  255. err2:
  256. release_mem_region(res->start, resource_size(res));
  257. err1:
  258. dev_err(&pdev->dev, "init %s fail, %d\n",
  259. dev_name(&pdev->dev), err);
  260. return err;
  261. }
  262. static int __exit ehci_orion_drv_remove(struct platform_device *pdev)
  263. {
  264. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  265. struct clk *clk;
  266. usb_remove_hcd(hcd);
  267. iounmap(hcd->regs);
  268. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  269. usb_put_hcd(hcd);
  270. clk = clk_get(&pdev->dev, NULL);
  271. if (!IS_ERR(clk)) {
  272. clk_disable_unprepare(clk);
  273. clk_put(clk);
  274. }
  275. return 0;
  276. }
  277. MODULE_ALIAS("platform:orion-ehci");
  278. static struct platform_driver ehci_orion_driver = {
  279. .probe = ehci_orion_drv_probe,
  280. .remove = __exit_p(ehci_orion_drv_remove),
  281. .shutdown = usb_hcd_platform_shutdown,
  282. .driver.name = "orion-ehci",
  283. };