ehci-mx6.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 <asm/arch/mx6x_pins.h>
  24. #include <asm/imx-common/iomux-v3.h>
  25. #include "ehci.h"
  26. #define USB_OTGREGS_OFFSET 0x000
  27. #define USB_H1REGS_OFFSET 0x200
  28. #define USB_H2REGS_OFFSET 0x400
  29. #define USB_H3REGS_OFFSET 0x600
  30. #define USB_OTHERREGS_OFFSET 0x800
  31. #define USB_H1_CTRL_OFFSET 0x04
  32. #define USBPHY_CTRL 0x00000030
  33. #define USBPHY_CTRL_SET 0x00000034
  34. #define USBPHY_CTRL_CLR 0x00000038
  35. #define USBPHY_CTRL_TOG 0x0000003c
  36. #define USBPHY_PWD 0x00000000
  37. #define USBPHY_CTRL_SFTRST 0x80000000
  38. #define USBPHY_CTRL_CLKGATE 0x40000000
  39. #define USBPHY_CTRL_ENUTMILEVEL3 0x00008000
  40. #define USBPHY_CTRL_ENUTMILEVEL2 0x00004000
  41. #define ANADIG_USB2_CHRG_DETECT_EN_B 0x00100000
  42. #define ANADIG_USB2_CHRG_DETECT_CHK_CHRG_B 0x00080000
  43. #define ANADIG_USB2_PLL_480_CTRL_BYPASS 0x00010000
  44. #define ANADIG_USB2_PLL_480_CTRL_ENABLE 0x00002000
  45. #define ANADIG_USB2_PLL_480_CTRL_POWER 0x00001000
  46. #define ANADIG_USB2_PLL_480_CTRL_EN_USB_CLKS 0x00000040
  47. #define UCTRL_OVER_CUR_POL (1 << 8) /* OTG Polarity of Overcurrent */
  48. #define UCTRL_OVER_CUR_DIS (1 << 7) /* Disable OTG Overcurrent Detection */
  49. /* USBCMD */
  50. #define UH1_USBCMD_OFFSET 0x140
  51. #define UCMD_RUN_STOP (1 << 0) /* controller run/stop */
  52. #define UCMD_RESET (1 << 1) /* controller reset */
  53. static void usbh1_internal_phy_clock_gate(int on)
  54. {
  55. void __iomem *phy_reg = (void __iomem *)USB_PHY1_BASE_ADDR;
  56. phy_reg += on ? USBPHY_CTRL_CLR : USBPHY_CTRL_SET;
  57. __raw_writel(USBPHY_CTRL_CLKGATE, phy_reg);
  58. }
  59. static void usbh1_power_config(void)
  60. {
  61. struct anatop_regs __iomem *anatop =
  62. (struct anatop_regs __iomem *)ANATOP_BASE_ADDR;
  63. /*
  64. * Some phy and power's special controls for host1
  65. * 1. The external charger detector needs to be disabled
  66. * or the signal at DP will be poor
  67. * 2. The PLL's power and output to usb for host 1
  68. * is totally controlled by IC, so the Software only needs
  69. * to enable them at initializtion.
  70. */
  71. __raw_writel(ANADIG_USB2_CHRG_DETECT_EN_B |
  72. ANADIG_USB2_CHRG_DETECT_CHK_CHRG_B,
  73. &anatop->usb2_chrg_detect);
  74. __raw_writel(ANADIG_USB2_PLL_480_CTRL_BYPASS,
  75. &anatop->usb2_pll_480_ctrl_clr);
  76. __raw_writel(ANADIG_USB2_PLL_480_CTRL_ENABLE |
  77. ANADIG_USB2_PLL_480_CTRL_POWER |
  78. ANADIG_USB2_PLL_480_CTRL_EN_USB_CLKS,
  79. &anatop->usb2_pll_480_ctrl_set);
  80. }
  81. static int usbh1_phy_enable(void)
  82. {
  83. void __iomem *phy_reg = (void __iomem *)USB_PHY1_BASE_ADDR;
  84. void __iomem *phy_ctrl = (void __iomem *)(phy_reg + USBPHY_CTRL);
  85. void __iomem *usb_cmd = (void __iomem *)(USBOH3_USB_BASE_ADDR +
  86. USB_H1REGS_OFFSET +
  87. UH1_USBCMD_OFFSET);
  88. u32 val;
  89. /* Stop then Reset */
  90. val = __raw_readl(usb_cmd);
  91. val &= ~UCMD_RUN_STOP;
  92. __raw_writel(val, usb_cmd);
  93. while (__raw_readl(usb_cmd) & UCMD_RUN_STOP)
  94. ;
  95. val = __raw_readl(usb_cmd);
  96. val |= UCMD_RESET;
  97. __raw_writel(val, usb_cmd);
  98. while (__raw_readl(usb_cmd) & UCMD_RESET)
  99. ;
  100. /* Reset USBPHY module */
  101. val = __raw_readl(phy_ctrl);
  102. val |= USBPHY_CTRL_SFTRST;
  103. __raw_writel(val, phy_ctrl);
  104. udelay(10);
  105. /* Remove CLKGATE and SFTRST */
  106. val = __raw_readl(phy_ctrl);
  107. val &= ~(USBPHY_CTRL_CLKGATE | USBPHY_CTRL_SFTRST);
  108. __raw_writel(val, phy_ctrl);
  109. udelay(10);
  110. /* Power up the PHY */
  111. __raw_writel(0, phy_reg + USBPHY_PWD);
  112. /* enable FS/LS device */
  113. val = __raw_readl(phy_reg + USBPHY_CTRL);
  114. val |= (USBPHY_CTRL_ENUTMILEVEL2 | USBPHY_CTRL_ENUTMILEVEL3);
  115. __raw_writel(val, phy_reg + USBPHY_CTRL);
  116. return 0;
  117. }
  118. static void usbh1_oc_config(void)
  119. {
  120. void __iomem *usb_base = (void __iomem *)USBOH3_USB_BASE_ADDR;
  121. void __iomem *usbother_base = usb_base + USB_OTHERREGS_OFFSET;
  122. u32 val;
  123. val = __raw_readl(usbother_base + USB_H1_CTRL_OFFSET);
  124. #if CONFIG_MACH_TYPE == MACH_TYPE_MX6Q_ARM2
  125. /* mx6qarm2 seems to required a different setting*/
  126. val &= ~UCTRL_OVER_CUR_POL;
  127. #else
  128. val |= UCTRL_OVER_CUR_POL;
  129. #endif
  130. __raw_writel(val, usbother_base + USB_H1_CTRL_OFFSET);
  131. val = __raw_readl(usbother_base + USB_H1_CTRL_OFFSET);
  132. val |= UCTRL_OVER_CUR_DIS;
  133. __raw_writel(val, usbother_base + USB_H1_CTRL_OFFSET);
  134. }
  135. int __weak board_ehci_hcd_init(int port)
  136. {
  137. return 0;
  138. }
  139. int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  140. {
  141. struct usb_ehci *ehci;
  142. enable_usboh3_clk(1);
  143. mdelay(1);
  144. /* Do board specific initialization */
  145. board_ehci_hcd_init(CONFIG_MXC_USB_PORT);
  146. #if CONFIG_MXC_USB_PORT == 1
  147. /* USB Host 1 */
  148. usbh1_power_config();
  149. usbh1_oc_config();
  150. usbh1_internal_phy_clock_gate(1);
  151. usbh1_phy_enable();
  152. #else
  153. #error "MXC USB port not yet supported"
  154. #endif
  155. ehci = (struct usb_ehci *)(USBOH3_USB_BASE_ADDR +
  156. (0x200 * CONFIG_MXC_USB_PORT));
  157. *hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
  158. *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
  159. HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  160. setbits_le32(&ehci->usbmode, CM_HOST);
  161. __raw_writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc);
  162. setbits_le32(&ehci->portsc, USB_EN);
  163. mdelay(10);
  164. return 0;
  165. }
  166. int ehci_hcd_stop(int index)
  167. {
  168. return 0;
  169. }