ehci-mx5.c 7.3 KB

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