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