Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de> |
| 3 | * Copyright (C) 2010 Freescale Semiconductor, Inc. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <usb.h> |
| 10 | #include <errno.h> |
| 11 | #include <linux/compiler.h> |
| 12 | #include <usb/ehci-fsl.h> |
| 13 | #include <asm/io.h> |
| 14 | #include <asm/arch/imx-regs.h> |
| 15 | #include <asm/arch/clock.h> |
Troy Kisky | 2714e17 | 2012-07-19 08:18:22 +0000 | [diff] [blame] | 16 | #include <asm/imx-common/iomux-v3.h> |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 17 | |
| 18 | #include "ehci.h" |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 19 | |
| 20 | #define USB_OTGREGS_OFFSET 0x000 |
| 21 | #define USB_H1REGS_OFFSET 0x200 |
| 22 | #define USB_H2REGS_OFFSET 0x400 |
| 23 | #define USB_H3REGS_OFFSET 0x600 |
| 24 | #define USB_OTHERREGS_OFFSET 0x800 |
| 25 | |
| 26 | #define USB_H1_CTRL_OFFSET 0x04 |
| 27 | |
| 28 | #define USBPHY_CTRL 0x00000030 |
| 29 | #define USBPHY_CTRL_SET 0x00000034 |
| 30 | #define USBPHY_CTRL_CLR 0x00000038 |
| 31 | #define USBPHY_CTRL_TOG 0x0000003c |
| 32 | |
| 33 | #define USBPHY_PWD 0x00000000 |
| 34 | #define USBPHY_CTRL_SFTRST 0x80000000 |
| 35 | #define USBPHY_CTRL_CLKGATE 0x40000000 |
| 36 | #define USBPHY_CTRL_ENUTMILEVEL3 0x00008000 |
| 37 | #define USBPHY_CTRL_ENUTMILEVEL2 0x00004000 |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 38 | #define USBPHY_CTRL_OTG_ID 0x08000000 |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 39 | |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 40 | #define ANADIG_USB2_CHRG_DETECT_EN_B 0x00100000 |
| 41 | #define ANADIG_USB2_CHRG_DETECT_CHK_CHRG_B 0x00080000 |
| 42 | |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 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 | |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 48 | #define USBNC_OFFSET 0x200 |
| 49 | #define USBNC_PHYSTATUS_ID_DIG (1 << 4) /* otg_id status */ |
| 50 | #define USBNC_PHYCFG2_ACAENB (1 << 4) /* otg_id detection enable */ |
| 51 | #define UCTRL_PM (1 << 9) /* OTG Power Mask */ |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 52 | #define UCTRL_OVER_CUR_POL (1 << 8) /* OTG Polarity of Overcurrent */ |
| 53 | #define UCTRL_OVER_CUR_DIS (1 << 7) /* Disable OTG Overcurrent Detection */ |
| 54 | |
| 55 | /* USBCMD */ |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 56 | #define UCMD_RUN_STOP (1 << 0) /* controller run/stop */ |
| 57 | #define UCMD_RESET (1 << 1) /* controller reset */ |
| 58 | |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 59 | #if defined(CONFIG_MX6) |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 60 | static const unsigned phy_bases[] = { |
| 61 | USB_PHY0_BASE_ADDR, |
| 62 | USB_PHY1_BASE_ADDR, |
| 63 | }; |
| 64 | |
| 65 | static void usb_internal_phy_clock_gate(int index, int on) |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 66 | { |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 67 | void __iomem *phy_reg; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 68 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 69 | if (index >= ARRAY_SIZE(phy_bases)) |
| 70 | return; |
| 71 | |
| 72 | phy_reg = (void __iomem *)phy_bases[index]; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 73 | phy_reg += on ? USBPHY_CTRL_CLR : USBPHY_CTRL_SET; |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 74 | writel(USBPHY_CTRL_CLKGATE, phy_reg); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 77 | static void usb_power_config(int index) |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 78 | { |
Wolfgang Grandegger | 5d113ca | 2012-05-02 04:36:39 +0000 | [diff] [blame] | 79 | struct anatop_regs __iomem *anatop = |
| 80 | (struct anatop_regs __iomem *)ANATOP_BASE_ADDR; |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 81 | void __iomem *chrg_detect; |
| 82 | void __iomem *pll_480_ctrl_clr; |
| 83 | void __iomem *pll_480_ctrl_set; |
| 84 | |
| 85 | switch (index) { |
| 86 | case 0: |
| 87 | chrg_detect = &anatop->usb1_chrg_detect; |
| 88 | pll_480_ctrl_clr = &anatop->usb1_pll_480_ctrl_clr; |
| 89 | pll_480_ctrl_set = &anatop->usb1_pll_480_ctrl_set; |
| 90 | break; |
| 91 | case 1: |
| 92 | chrg_detect = &anatop->usb2_chrg_detect; |
| 93 | pll_480_ctrl_clr = &anatop->usb2_pll_480_ctrl_clr; |
| 94 | pll_480_ctrl_set = &anatop->usb2_pll_480_ctrl_set; |
| 95 | break; |
| 96 | default: |
| 97 | return; |
| 98 | } |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 99 | /* |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 100 | * Some phy and power's special controls |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 101 | * 1. The external charger detector needs to be disabled |
| 102 | * or the signal at DP will be poor |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 103 | * 2. The PLL's power and output to usb |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 104 | * is totally controlled by IC, so the Software only needs |
| 105 | * to enable them at initializtion. |
| 106 | */ |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 107 | writel(ANADIG_USB2_CHRG_DETECT_EN_B | |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 108 | ANADIG_USB2_CHRG_DETECT_CHK_CHRG_B, |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 109 | chrg_detect); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 110 | |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 111 | writel(ANADIG_USB2_PLL_480_CTRL_BYPASS, |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 112 | pll_480_ctrl_clr); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 113 | |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 114 | writel(ANADIG_USB2_PLL_480_CTRL_ENABLE | |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 115 | ANADIG_USB2_PLL_480_CTRL_POWER | |
| 116 | ANADIG_USB2_PLL_480_CTRL_EN_USB_CLKS, |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 117 | pll_480_ctrl_set); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Adrian Alonso | c52eb1c | 2015-08-06 15:46:03 -0500 | [diff] [blame] | 120 | static int wait_for_bit(u32 *reg, const u32 mask, bool set) |
| 121 | { |
| 122 | u32 val; |
| 123 | const unsigned int timeout = 10000; |
| 124 | unsigned long start = get_timer(0); |
| 125 | |
| 126 | while(1) { |
| 127 | val = readl(reg); |
| 128 | if (!set) |
| 129 | val = ~val; |
| 130 | |
| 131 | if ((val & mask) == mask) |
| 132 | return 0; |
| 133 | |
| 134 | if (get_timer(start) > timeout) |
| 135 | break; |
| 136 | |
| 137 | udelay(1); |
| 138 | } |
| 139 | |
| 140 | debug("%s: Timeout (reg=%p mask=%08x wait_set=%i)\n", |
| 141 | __func__, reg, mask, set); |
| 142 | |
| 143 | return -ETIMEDOUT; |
| 144 | } |
| 145 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 146 | /* Return 0 : host node, <>0 : device mode */ |
| 147 | static int usb_phy_enable(int index, struct usb_ehci *ehci) |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 148 | { |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 149 | void __iomem *phy_reg; |
| 150 | void __iomem *phy_ctrl; |
| 151 | void __iomem *usb_cmd; |
Adrian Alonso | c52eb1c | 2015-08-06 15:46:03 -0500 | [diff] [blame] | 152 | int ret; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 153 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 154 | if (index >= ARRAY_SIZE(phy_bases)) |
| 155 | return 0; |
| 156 | |
| 157 | phy_reg = (void __iomem *)phy_bases[index]; |
| 158 | phy_ctrl = (void __iomem *)(phy_reg + USBPHY_CTRL); |
| 159 | usb_cmd = (void __iomem *)&ehci->usbcmd; |
| 160 | |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 161 | /* Stop then Reset */ |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 162 | clrbits_le32(usb_cmd, UCMD_RUN_STOP); |
Adrian Alonso | c52eb1c | 2015-08-06 15:46:03 -0500 | [diff] [blame] | 163 | ret = wait_for_bit(usb_cmd, UCMD_RUN_STOP, 0); |
| 164 | if (ret) |
| 165 | return ret; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 166 | |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 167 | setbits_le32(usb_cmd, UCMD_RESET); |
Adrian Alonso | c52eb1c | 2015-08-06 15:46:03 -0500 | [diff] [blame] | 168 | ret = wait_for_bit(usb_cmd, UCMD_RESET, 0); |
| 169 | if (ret) |
| 170 | return ret; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 171 | |
| 172 | /* Reset USBPHY module */ |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 173 | setbits_le32(phy_ctrl, USBPHY_CTRL_SFTRST); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 174 | udelay(10); |
| 175 | |
| 176 | /* Remove CLKGATE and SFTRST */ |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 177 | clrbits_le32(phy_ctrl, USBPHY_CTRL_CLKGATE | USBPHY_CTRL_SFTRST); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 178 | udelay(10); |
| 179 | |
| 180 | /* Power up the PHY */ |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 181 | writel(0, phy_reg + USBPHY_PWD); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 182 | /* enable FS/LS device */ |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 183 | setbits_le32(phy_ctrl, USBPHY_CTRL_ENUTMILEVEL2 | |
| 184 | USBPHY_CTRL_ENUTMILEVEL3); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 185 | |
Peng Fan | 220402e | 2014-11-10 08:50:39 +0800 | [diff] [blame] | 186 | return 0; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 189 | int usb_phy_mode(int port) |
| 190 | { |
| 191 | void __iomem *phy_reg; |
| 192 | void __iomem *phy_ctrl; |
| 193 | u32 val; |
| 194 | |
| 195 | phy_reg = (void __iomem *)phy_bases[port]; |
| 196 | phy_ctrl = (void __iomem *)(phy_reg + USBPHY_CTRL); |
| 197 | |
| 198 | val = readl(phy_ctrl); |
| 199 | |
| 200 | if (val & USBPHY_CTRL_OTG_ID) |
| 201 | return USB_INIT_DEVICE; |
| 202 | else |
| 203 | return USB_INIT_HOST; |
| 204 | } |
| 205 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 206 | /* Base address for this IP block is 0x02184800 */ |
| 207 | struct usbnc_regs { |
| 208 | u32 ctrl[4]; /* otg/host1-3 */ |
| 209 | u32 uh2_hsic_ctrl; |
| 210 | u32 uh3_hsic_ctrl; |
| 211 | u32 otg_phy_ctrl_0; |
| 212 | u32 uh1_phy_ctrl_0; |
| 213 | }; |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 214 | #elif defined(CONFIG_MX7) |
| 215 | struct usbnc_regs { |
| 216 | u32 ctrl1; |
| 217 | u32 ctrl2; |
| 218 | u32 reserve1[10]; |
| 219 | u32 phy_cfg1; |
| 220 | u32 phy_cfg2; |
| 221 | u32 phy_status; |
| 222 | u32 reserve2[4]; |
| 223 | u32 adp_cfg1; |
| 224 | u32 adp_cfg2; |
| 225 | u32 adp_status; |
| 226 | }; |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 227 | |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 228 | static void usb_power_config(int index) |
| 229 | { |
| 230 | struct usbnc_regs *usbnc = (struct usbnc_regs *)(USB_BASE_ADDR + |
| 231 | (0x10000 * index) + USBNC_OFFSET); |
| 232 | void __iomem *phy_cfg2 = (void __iomem *)(&usbnc->phy_cfg2); |
| 233 | |
| 234 | /* Enable usb_otg_id detection */ |
| 235 | setbits_le32(phy_cfg2, USBNC_PHYCFG2_ACAENB); |
| 236 | } |
| 237 | |
| 238 | int usb_phy_mode(int port) |
| 239 | { |
| 240 | struct usbnc_regs *usbnc = (struct usbnc_regs *)(USB_BASE_ADDR + |
| 241 | (0x10000 * port) + USBNC_OFFSET); |
| 242 | void __iomem *status = (void __iomem *)(&usbnc->phy_status); |
| 243 | u32 val; |
| 244 | |
| 245 | val = readl(status); |
| 246 | |
| 247 | if (val & USBNC_PHYSTATUS_ID_DIG) |
| 248 | return USB_INIT_DEVICE; |
| 249 | else |
| 250 | return USB_INIT_HOST; |
| 251 | } |
| 252 | #endif |
| 253 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 254 | static void usb_oc_config(int index) |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 255 | { |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 256 | #if defined(CONFIG_MX6) |
Ye.Li | f93453a | 2014-09-15 17:23:14 +0800 | [diff] [blame] | 257 | struct usbnc_regs *usbnc = (struct usbnc_regs *)(USB_BASE_ADDR + |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 258 | USB_OTHERREGS_OFFSET); |
| 259 | void __iomem *ctrl = (void __iomem *)(&usbnc->ctrl[index]); |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 260 | #elif defined(CONFIG_MX7) |
| 261 | struct usbnc_regs *usbnc = (struct usbnc_regs *)(USB_BASE_ADDR + |
| 262 | (0x10000 * index) + USBNC_OFFSET); |
| 263 | void __iomem *ctrl = (void __iomem *)(&usbnc->ctrl1); |
| 264 | #endif |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 265 | |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 266 | #if CONFIG_MACH_TYPE == MACH_TYPE_MX6Q_ARM2 |
| 267 | /* mx6qarm2 seems to required a different setting*/ |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 268 | clrbits_le32(ctrl, UCTRL_OVER_CUR_POL); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 269 | #else |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 270 | setbits_le32(ctrl, UCTRL_OVER_CUR_POL); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 271 | #endif |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 272 | |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 273 | #if defined(CONFIG_MX6) |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 274 | setbits_le32(ctrl, UCTRL_OVER_CUR_DIS); |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 275 | #elif defined(CONFIG_MX7) |
| 276 | setbits_le32(ctrl, UCTRL_OVER_CUR_DIS | UCTRL_PM); |
| 277 | #endif |
Peng Fan | 220402e | 2014-11-10 08:50:39 +0800 | [diff] [blame] | 278 | } |
| 279 | |
Adrian Alonso | 14dfbbb | 2015-08-06 15:43:16 -0500 | [diff] [blame] | 280 | /** |
| 281 | * board_ehci_hcd_init - override usb phy mode |
| 282 | * @port: usb host/otg port |
| 283 | * |
| 284 | * Target board specific, override usb_phy_mode. |
| 285 | * When usb-otg is used as usb host port, iomux pad usb_otg_id can be |
| 286 | * left disconnected in this case usb_phy_mode will not be able to identify |
| 287 | * the phy mode that usb port is used. |
| 288 | * Machine file overrides board_usb_phy_mode. |
| 289 | * |
| 290 | * Return: USB_INIT_DEVICE or USB_INIT_HOST |
| 291 | */ |
Peng Fan | 220402e | 2014-11-10 08:50:39 +0800 | [diff] [blame] | 292 | int __weak board_usb_phy_mode(int port) |
| 293 | { |
| 294 | return usb_phy_mode(port); |
| 295 | } |
| 296 | |
Adrian Alonso | 14dfbbb | 2015-08-06 15:43:16 -0500 | [diff] [blame] | 297 | /** |
| 298 | * board_ehci_hcd_init - set usb vbus voltage |
| 299 | * @port: usb otg port |
| 300 | * |
| 301 | * Target board specific, setup iomux pad to setup supply vbus voltage |
| 302 | * for usb otg port. Machine board file overrides board_ehci_hcd_init |
| 303 | * |
| 304 | * Return: 0 Success |
| 305 | */ |
Benoît Thébaudeau | 98023c1 | 2012-11-13 09:58:35 +0000 | [diff] [blame] | 306 | int __weak board_ehci_hcd_init(int port) |
| 307 | { |
| 308 | return 0; |
| 309 | } |
| 310 | |
Adrian Alonso | 14dfbbb | 2015-08-06 15:43:16 -0500 | [diff] [blame] | 311 | /** |
| 312 | * board_ehci_power - enables/disables usb vbus voltage |
| 313 | * @port: usb otg port |
| 314 | * @on: on/off vbus voltage |
| 315 | * |
| 316 | * Enables/disables supply vbus voltage for usb otg port. |
| 317 | * Machine board file overrides board_ehci_power |
| 318 | * |
| 319 | * Return: 0 Success |
| 320 | */ |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 321 | int __weak board_ehci_power(int port, int on) |
| 322 | { |
| 323 | return 0; |
| 324 | } |
| 325 | |
Troy Kisky | 7d6bbb9 | 2013-10-10 15:27:57 -0700 | [diff] [blame] | 326 | int ehci_hcd_init(int index, enum usb_init_type init, |
| 327 | struct ehci_hccr **hccr, struct ehci_hcor **hcor) |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 328 | { |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 329 | enum usb_init_type type; |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 330 | #if defined(CONFIG_MX6) |
| 331 | u32 controller_spacing = 0x200; |
| 332 | #elif defined(CONFIG_MX7) |
| 333 | u32 controller_spacing = 0x10000; |
| 334 | #endif |
Ye.Li | f93453a | 2014-09-15 17:23:14 +0800 | [diff] [blame] | 335 | struct usb_ehci *ehci = (struct usb_ehci *)(USB_BASE_ADDR + |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 336 | (controller_spacing * index)); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 337 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 338 | if (index > 3) |
| 339 | return -EINVAL; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 340 | enable_usboh3_clk(1); |
| 341 | mdelay(1); |
| 342 | |
| 343 | /* Do board specific initialization */ |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 344 | board_ehci_hcd_init(index); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 345 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 346 | usb_power_config(index); |
| 347 | usb_oc_config(index); |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 348 | |
| 349 | #if defined(CONFIG_MX6) |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 350 | usb_internal_phy_clock_gate(index, 1); |
Peng Fan | 220402e | 2014-11-10 08:50:39 +0800 | [diff] [blame] | 351 | usb_phy_enable(index, ehci); |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 352 | #endif |
Peng Fan | 220402e | 2014-11-10 08:50:39 +0800 | [diff] [blame] | 353 | type = board_usb_phy_mode(index); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 354 | |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 355 | *hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength); |
| 356 | *hcor = (struct ehci_hcor *)((uint32_t)*hccr + |
| 357 | HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 358 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 359 | if ((type == init) || (type == USB_INIT_DEVICE)) |
| 360 | board_ehci_power(index, (type == USB_INIT_DEVICE) ? 0 : 1); |
| 361 | if (type != init) |
| 362 | return -ENODEV; |
| 363 | if (type == USB_INIT_DEVICE) |
| 364 | return 0; |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 365 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 366 | setbits_le32(&ehci->usbmode, CM_HOST); |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 367 | writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 368 | setbits_le32(&ehci->portsc, USB_EN); |
| 369 | |
| 370 | mdelay(10); |
| 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 375 | int ehci_hcd_stop(int index) |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 376 | { |
| 377 | return 0; |
| 378 | } |