ehci-mx5.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
  3. * Copyright (C) 2010 Freescale Semiconductor, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * for more details.
  14. */
  15. #include <common.h>
  16. #include <usb.h>
  17. #include <errno.h>
  18. #include <linux/compiler.h>
  19. #include <usb/ehci-fsl.h>
  20. #include <asm/io.h>
  21. #include <asm/arch/imx-regs.h>
  22. #include <asm/arch/clock.h>
  23. #include "ehci.h"
  24. #define MX5_USBOTHER_REGS_OFFSET 0x800
  25. #define MXC_OTG_OFFSET 0
  26. #define MXC_H1_OFFSET 0x200
  27. #define MXC_H2_OFFSET 0x400
  28. #define MXC_H3_OFFSET 0x600
  29. #define MXC_USBCTRL_OFFSET 0
  30. #define MXC_USB_PHY_CTR_FUNC_OFFSET 0x8
  31. #define MXC_USB_PHY_CTR_FUNC2_OFFSET 0xc
  32. #define MXC_USB_CTRL_1_OFFSET 0x10
  33. #define MXC_USBH2CTRL_OFFSET 0x14
  34. #define MXC_USBH3CTRL_OFFSET 0x18
  35. /* USB_CTRL */
  36. /* OTG wakeup intr enable */
  37. #define MXC_OTG_UCTRL_OWIE_BIT (1 << 27)
  38. /* OTG power mask */
  39. #define MXC_OTG_UCTRL_OPM_BIT (1 << 24)
  40. /* OTG power pin polarity */
  41. #define MXC_OTG_UCTRL_O_PWR_POL_BIT (1 << 24)
  42. /* Host1 ULPI interrupt enable */
  43. #define MXC_H1_UCTRL_H1UIE_BIT (1 << 12)
  44. /* HOST1 wakeup intr enable */
  45. #define MXC_H1_UCTRL_H1WIE_BIT (1 << 11)
  46. /* HOST1 power mask */
  47. #define MXC_H1_UCTRL_H1PM_BIT (1 << 8)
  48. /* HOST1 power pin polarity */
  49. #define MXC_H1_UCTRL_H1_PWR_POL_BIT (1 << 8)
  50. /* USB_PHY_CTRL_FUNC */
  51. /* OTG Polarity of Overcurrent */
  52. #define MXC_OTG_PHYCTRL_OC_POL_BIT (1 << 9)
  53. /* OTG Disable Overcurrent Event */
  54. #define MXC_OTG_PHYCTRL_OC_DIS_BIT (1 << 8)
  55. /* UH1 Polarity of Overcurrent */
  56. #define MXC_H1_OC_POL_BIT (1 << 6)
  57. /* UH1 Disable Overcurrent Event */
  58. #define MXC_H1_OC_DIS_BIT (1 << 5)
  59. /* OTG Power Pin Polarity */
  60. #define MXC_OTG_PHYCTRL_PWR_POL_BIT (1 << 3)
  61. /* USBH2CTRL */
  62. #define MXC_H2_UCTRL_H2_OC_POL_BIT (1 << 31)
  63. #define MXC_H2_UCTRL_H2_OC_DIS_BIT (1 << 30)
  64. #define MXC_H2_UCTRL_H2UIE_BIT (1 << 8)
  65. #define MXC_H2_UCTRL_H2WIE_BIT (1 << 7)
  66. #define MXC_H2_UCTRL_H2PM_BIT (1 << 4)
  67. #define MXC_H2_UCTRL_H2_PWR_POL_BIT (1 << 4)
  68. /* USBH3CTRL */
  69. #define MXC_H3_UCTRL_H3_OC_POL_BIT (1 << 31)
  70. #define MXC_H3_UCTRL_H3_OC_DIS_BIT (1 << 30)
  71. #define MXC_H3_UCTRL_H3UIE_BIT (1 << 8)
  72. #define MXC_H3_UCTRL_H3WIE_BIT (1 << 7)
  73. #define MXC_H3_UCTRL_H3_PWR_POL_BIT (1 << 4)
  74. /* USB_CTRL_1 */
  75. #define MXC_USB_CTRL_UH1_EXT_CLK_EN (1 << 25)
  76. int mxc_set_usbcontrol(int port, unsigned int flags)
  77. {
  78. unsigned int v;
  79. void __iomem *usb_base = (void __iomem *)OTG_BASE_ADDR;
  80. void __iomem *usbother_base;
  81. int ret = 0;
  82. usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
  83. switch (port) {
  84. case 0: /* OTG port */
  85. if (flags & MXC_EHCI_INTERNAL_PHY) {
  86. v = __raw_readl(usbother_base +
  87. MXC_USB_PHY_CTR_FUNC_OFFSET);
  88. if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW)
  89. v |= MXC_OTG_PHYCTRL_OC_POL_BIT;
  90. else
  91. v &= ~MXC_OTG_PHYCTRL_OC_POL_BIT;
  92. if (flags & MXC_EHCI_POWER_PINS_ENABLED)
  93. /* OC/USBPWR is used */
  94. v &= ~MXC_OTG_PHYCTRL_OC_DIS_BIT;
  95. else
  96. /* OC/USBPWR is not used */
  97. v |= MXC_OTG_PHYCTRL_OC_DIS_BIT;
  98. #ifdef CONFIG_MX51
  99. if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
  100. v |= MXC_OTG_PHYCTRL_PWR_POL_BIT;
  101. else
  102. v &= ~MXC_OTG_PHYCTRL_PWR_POL_BIT;
  103. #endif
  104. __raw_writel(v, usbother_base +
  105. MXC_USB_PHY_CTR_FUNC_OFFSET);
  106. v = __raw_readl(usbother_base + MXC_USBCTRL_OFFSET);
  107. #ifdef CONFIG_MX51
  108. if (flags & MXC_EHCI_POWER_PINS_ENABLED)
  109. v &= ~MXC_OTG_UCTRL_OPM_BIT;
  110. else
  111. v |= MXC_OTG_UCTRL_OPM_BIT;
  112. #endif
  113. #ifdef CONFIG_MX53
  114. if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
  115. v |= MXC_OTG_UCTRL_O_PWR_POL_BIT;
  116. else
  117. v &= ~MXC_OTG_UCTRL_O_PWR_POL_BIT;
  118. #endif
  119. __raw_writel(v, usbother_base + MXC_USBCTRL_OFFSET);
  120. }
  121. break;
  122. case 1: /* Host 1 ULPI */
  123. #ifdef CONFIG_MX51
  124. /* The clock for the USBH1 ULPI port will come externally
  125. from the PHY. */
  126. v = __raw_readl(usbother_base + MXC_USB_CTRL_1_OFFSET);
  127. __raw_writel(v | MXC_USB_CTRL_UH1_EXT_CLK_EN, usbother_base +
  128. MXC_USB_CTRL_1_OFFSET);
  129. #endif
  130. v = __raw_readl(usbother_base + MXC_USBCTRL_OFFSET);
  131. #ifdef CONFIG_MX51
  132. if (flags & MXC_EHCI_POWER_PINS_ENABLED)
  133. v &= ~MXC_H1_UCTRL_H1PM_BIT; /* H1 power mask unused */
  134. else
  135. v |= MXC_H1_UCTRL_H1PM_BIT; /* H1 power mask used */
  136. #endif
  137. #ifdef CONFIG_MX53
  138. if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
  139. v |= MXC_H1_UCTRL_H1_PWR_POL_BIT;
  140. else
  141. v &= ~MXC_H1_UCTRL_H1_PWR_POL_BIT;
  142. #endif
  143. __raw_writel(v, usbother_base + MXC_USBCTRL_OFFSET);
  144. v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC_OFFSET);
  145. if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW)
  146. v |= MXC_H1_OC_POL_BIT;
  147. else
  148. v &= ~MXC_H1_OC_POL_BIT;
  149. if (flags & MXC_EHCI_POWER_PINS_ENABLED)
  150. v &= ~MXC_H1_OC_DIS_BIT; /* OC is used */
  151. else
  152. v |= MXC_H1_OC_DIS_BIT; /* OC is not used */
  153. __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC_OFFSET);
  154. break;
  155. case 2: /* Host 2 ULPI */
  156. v = __raw_readl(usbother_base + MXC_USBH2CTRL_OFFSET);
  157. #ifdef CONFIG_MX51
  158. if (flags & MXC_EHCI_POWER_PINS_ENABLED)
  159. v &= ~MXC_H2_UCTRL_H2PM_BIT; /* H2 power mask unused */
  160. else
  161. v |= MXC_H2_UCTRL_H2PM_BIT; /* H2 power mask used */
  162. #endif
  163. #ifdef CONFIG_MX53
  164. if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW)
  165. v |= MXC_H2_UCTRL_H2_OC_POL_BIT;
  166. else
  167. v &= ~MXC_H2_UCTRL_H2_OC_POL_BIT;
  168. if (flags & MXC_EHCI_POWER_PINS_ENABLED)
  169. v &= ~MXC_H2_UCTRL_H2_OC_DIS_BIT; /* OC is used */
  170. else
  171. v |= MXC_H2_UCTRL_H2_OC_DIS_BIT; /* OC is not used */
  172. if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
  173. v |= MXC_H2_UCTRL_H2_PWR_POL_BIT;
  174. else
  175. v &= ~MXC_H2_UCTRL_H2_PWR_POL_BIT;
  176. #endif
  177. __raw_writel(v, usbother_base + MXC_USBH2CTRL_OFFSET);
  178. break;
  179. #ifdef CONFIG_MX53
  180. case 3: /* Host 3 ULPI */
  181. v = __raw_readl(usbother_base + MXC_USBH3CTRL_OFFSET);
  182. if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW)
  183. v |= MXC_H3_UCTRL_H3_OC_POL_BIT;
  184. else
  185. v &= ~MXC_H3_UCTRL_H3_OC_POL_BIT;
  186. if (flags & MXC_EHCI_POWER_PINS_ENABLED)
  187. v &= ~MXC_H3_UCTRL_H3_OC_DIS_BIT; /* OC is used */
  188. else
  189. v |= MXC_H3_UCTRL_H3_OC_DIS_BIT; /* OC is not used */
  190. if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
  191. v |= MXC_H3_UCTRL_H3_PWR_POL_BIT;
  192. else
  193. v &= ~MXC_H3_UCTRL_H3_PWR_POL_BIT;
  194. __raw_writel(v, usbother_base + MXC_USBH3CTRL_OFFSET);
  195. break;
  196. #endif
  197. }
  198. return ret;
  199. }
  200. int __weak board_ehci_hcd_init(int port)
  201. {
  202. return 0;
  203. }
  204. void __weak board_ehci_hcd_postinit(struct usb_ehci *ehci, int port)
  205. {
  206. }
  207. int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  208. {
  209. struct usb_ehci *ehci;
  210. #ifdef CONFIG_MX53
  211. struct clkctl *sc_regs = (struct clkctl *)CCM_BASE_ADDR;
  212. u32 reg;
  213. reg = __raw_readl(&sc_regs->cscmr1) & ~(1 << 26);
  214. /* derive USB PHY clock multiplexer from PLL3 */
  215. reg |= 1 << 26;
  216. __raw_writel(reg, &sc_regs->cscmr1);
  217. #endif
  218. set_usboh3_clk();
  219. enable_usboh3_clk(1);
  220. set_usb_phy_clk();
  221. enable_usb_phy1_clk(1);
  222. enable_usb_phy2_clk(1);
  223. mdelay(1);
  224. /* Do board specific initialization */
  225. board_ehci_hcd_init(CONFIG_MXC_USB_PORT);
  226. ehci = (struct usb_ehci *)(OTG_BASE_ADDR +
  227. (0x200 * CONFIG_MXC_USB_PORT));
  228. *hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
  229. *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
  230. HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  231. setbits_le32(&ehci->usbmode, CM_HOST);
  232. __raw_writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc);
  233. setbits_le32(&ehci->portsc, USB_EN);
  234. mxc_set_usbcontrol(CONFIG_MXC_USB_PORT, CONFIG_MXC_USB_FLAGS);
  235. mdelay(10);
  236. /* Do board specific post-initialization */
  237. board_ehci_hcd_postinit(ehci, CONFIG_MXC_USB_PORT);
  238. return 0;
  239. }
  240. int ehci_hcd_stop(int index)
  241. {
  242. return 0;
  243. }