ehci-orion.c 7.1 KB

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