Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de> |
| 4 | * Copyright (C) 2010 Freescale Semiconductor, Inc. |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 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> |
Mateusz Kulikowski | 3add69e | 2016-03-31 23:12:23 +0200 | [diff] [blame] | 13 | #include <usb/ehci-ci.h> |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <asm/arch/imx-regs.h> |
| 16 | #include <asm/arch/clock.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 17 | #include <asm/mach-imx/iomux-v3.h> |
| 18 | #include <asm/mach-imx/sys_proto.h> |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 19 | #include <dm.h> |
Simon Glass | 0ffb9d6 | 2017-05-31 19:47:48 -0600 | [diff] [blame] | 20 | #include <asm/mach-types.h> |
Peng Fan | 1335133 | 2016-12-22 17:06:43 +0800 | [diff] [blame] | 21 | #include <power/regulator.h> |
Adam Ford | 15287f0 | 2019-04-03 08:41:56 -0500 | [diff] [blame] | 22 | #include <linux/usb/otg.h> |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 23 | |
| 24 | #include "ehci.h" |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 25 | |
Peng Fan | 9e3eab3 | 2016-12-22 17:06:42 +0800 | [diff] [blame] | 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 28 | #define USB_OTGREGS_OFFSET 0x000 |
| 29 | #define USB_H1REGS_OFFSET 0x200 |
| 30 | #define USB_H2REGS_OFFSET 0x400 |
| 31 | #define USB_H3REGS_OFFSET 0x600 |
| 32 | #define USB_OTHERREGS_OFFSET 0x800 |
| 33 | |
| 34 | #define USB_H1_CTRL_OFFSET 0x04 |
| 35 | |
| 36 | #define USBPHY_CTRL 0x00000030 |
| 37 | #define USBPHY_CTRL_SET 0x00000034 |
| 38 | #define USBPHY_CTRL_CLR 0x00000038 |
| 39 | #define USBPHY_CTRL_TOG 0x0000003c |
| 40 | |
| 41 | #define USBPHY_PWD 0x00000000 |
| 42 | #define USBPHY_CTRL_SFTRST 0x80000000 |
| 43 | #define USBPHY_CTRL_CLKGATE 0x40000000 |
| 44 | #define USBPHY_CTRL_ENUTMILEVEL3 0x00008000 |
| 45 | #define USBPHY_CTRL_ENUTMILEVEL2 0x00004000 |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 46 | #define USBPHY_CTRL_OTG_ID 0x08000000 |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 47 | |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 48 | #define ANADIG_USB2_CHRG_DETECT_EN_B 0x00100000 |
| 49 | #define ANADIG_USB2_CHRG_DETECT_CHK_CHRG_B 0x00080000 |
| 50 | |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 51 | #define ANADIG_USB2_PLL_480_CTRL_BYPASS 0x00010000 |
| 52 | #define ANADIG_USB2_PLL_480_CTRL_ENABLE 0x00002000 |
| 53 | #define ANADIG_USB2_PLL_480_CTRL_POWER 0x00001000 |
| 54 | #define ANADIG_USB2_PLL_480_CTRL_EN_USB_CLKS 0x00000040 |
| 55 | |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 56 | #define USBNC_OFFSET 0x200 |
Peng Fan | 9e3eab3 | 2016-12-22 17:06:42 +0800 | [diff] [blame] | 57 | #define USBNC_PHY_STATUS_OFFSET 0x23C |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 58 | #define USBNC_PHYSTATUS_ID_DIG (1 << 4) /* otg_id status */ |
| 59 | #define USBNC_PHYCFG2_ACAENB (1 << 4) /* otg_id detection enable */ |
Stefan Agner | 475cf91 | 2016-07-13 00:25:37 -0700 | [diff] [blame] | 60 | #define UCTRL_PWR_POL (1 << 9) /* OTG Polarity of Power Pin */ |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 61 | #define UCTRL_OVER_CUR_POL (1 << 8) /* OTG Polarity of Overcurrent */ |
| 62 | #define UCTRL_OVER_CUR_DIS (1 << 7) /* Disable OTG Overcurrent Detection */ |
| 63 | |
| 64 | /* USBCMD */ |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 65 | #define UCMD_RUN_STOP (1 << 0) /* controller run/stop */ |
| 66 | #define UCMD_RESET (1 << 1) /* controller reset */ |
| 67 | |
Ye Li | 9da57ea | 2019-10-24 10:29:32 -0300 | [diff] [blame] | 68 | #if defined(CONFIG_MX6) || defined(CONFIG_MX7ULP) |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 69 | static const unsigned phy_bases[] = { |
| 70 | USB_PHY0_BASE_ADDR, |
Ye Li | 9da57ea | 2019-10-24 10:29:32 -0300 | [diff] [blame] | 71 | #if defined(USB_PHY1_BASE_ADDR) |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 72 | USB_PHY1_BASE_ADDR, |
Ye Li | 9da57ea | 2019-10-24 10:29:32 -0300 | [diff] [blame] | 73 | #endif |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | static void usb_internal_phy_clock_gate(int index, int on) |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 77 | { |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 78 | void __iomem *phy_reg; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 79 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 80 | if (index >= ARRAY_SIZE(phy_bases)) |
| 81 | return; |
| 82 | |
| 83 | phy_reg = (void __iomem *)phy_bases[index]; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 84 | phy_reg += on ? USBPHY_CTRL_CLR : USBPHY_CTRL_SET; |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 85 | writel(USBPHY_CTRL_CLKGATE, phy_reg); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 88 | static void usb_power_config(int index) |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 89 | { |
Ye Li | 9da57ea | 2019-10-24 10:29:32 -0300 | [diff] [blame] | 90 | #if defined(CONFIG_MX7ULP) |
| 91 | struct usbphy_regs __iomem *usbphy = |
| 92 | (struct usbphy_regs __iomem *)USB_PHY0_BASE_ADDR; |
| 93 | |
| 94 | if (index > 0) |
| 95 | return; |
| 96 | |
| 97 | writel(ANADIG_USB2_CHRG_DETECT_EN_B | |
| 98 | ANADIG_USB2_CHRG_DETECT_CHK_CHRG_B, |
| 99 | &usbphy->usb1_chrg_detect); |
| 100 | |
| 101 | scg_enable_usb_pll(true); |
| 102 | |
| 103 | #else |
Wolfgang Grandegger | 5d113ca | 2012-05-02 04:36:39 +0000 | [diff] [blame] | 104 | struct anatop_regs __iomem *anatop = |
| 105 | (struct anatop_regs __iomem *)ANATOP_BASE_ADDR; |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 106 | void __iomem *chrg_detect; |
| 107 | void __iomem *pll_480_ctrl_clr; |
| 108 | void __iomem *pll_480_ctrl_set; |
| 109 | |
| 110 | switch (index) { |
| 111 | case 0: |
| 112 | chrg_detect = &anatop->usb1_chrg_detect; |
| 113 | pll_480_ctrl_clr = &anatop->usb1_pll_480_ctrl_clr; |
| 114 | pll_480_ctrl_set = &anatop->usb1_pll_480_ctrl_set; |
| 115 | break; |
| 116 | case 1: |
| 117 | chrg_detect = &anatop->usb2_chrg_detect; |
| 118 | pll_480_ctrl_clr = &anatop->usb2_pll_480_ctrl_clr; |
| 119 | pll_480_ctrl_set = &anatop->usb2_pll_480_ctrl_set; |
| 120 | break; |
| 121 | default: |
| 122 | return; |
| 123 | } |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 124 | /* |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 125 | * Some phy and power's special controls |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 126 | * 1. The external charger detector needs to be disabled |
| 127 | * or the signal at DP will be poor |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 128 | * 2. The PLL's power and output to usb |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 129 | * is totally controlled by IC, so the Software only needs |
| 130 | * to enable them at initializtion. |
| 131 | */ |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 132 | writel(ANADIG_USB2_CHRG_DETECT_EN_B | |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 133 | ANADIG_USB2_CHRG_DETECT_CHK_CHRG_B, |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 134 | chrg_detect); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 135 | |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 136 | writel(ANADIG_USB2_PLL_480_CTRL_BYPASS, |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 137 | pll_480_ctrl_clr); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 138 | |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 139 | writel(ANADIG_USB2_PLL_480_CTRL_ENABLE | |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 140 | ANADIG_USB2_PLL_480_CTRL_POWER | |
| 141 | ANADIG_USB2_PLL_480_CTRL_EN_USB_CLKS, |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 142 | pll_480_ctrl_set); |
Ye Li | 9da57ea | 2019-10-24 10:29:32 -0300 | [diff] [blame] | 143 | |
| 144 | #endif |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 147 | /* Return 0 : host node, <>0 : device mode */ |
| 148 | static int usb_phy_enable(int index, struct usb_ehci *ehci) |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 149 | { |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 150 | void __iomem *phy_reg; |
| 151 | void __iomem *phy_ctrl; |
| 152 | void __iomem *usb_cmd; |
Adrian Alonso | c52eb1c | 2015-08-06 15:46:03 -0500 | [diff] [blame] | 153 | int ret; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 154 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 155 | if (index >= ARRAY_SIZE(phy_bases)) |
| 156 | return 0; |
| 157 | |
| 158 | phy_reg = (void __iomem *)phy_bases[index]; |
| 159 | phy_ctrl = (void __iomem *)(phy_reg + USBPHY_CTRL); |
| 160 | usb_cmd = (void __iomem *)&ehci->usbcmd; |
| 161 | |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 162 | /* Stop then Reset */ |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 163 | clrbits_le32(usb_cmd, UCMD_RUN_STOP); |
Álvaro Fernández Rojas | 918de03 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 164 | ret = wait_for_bit_le32(usb_cmd, UCMD_RUN_STOP, false, 10000, false); |
Adrian Alonso | c52eb1c | 2015-08-06 15:46:03 -0500 | [diff] [blame] | 165 | if (ret) |
| 166 | return ret; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 167 | |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 168 | setbits_le32(usb_cmd, UCMD_RESET); |
Álvaro Fernández Rojas | 918de03 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 169 | ret = wait_for_bit_le32(usb_cmd, UCMD_RESET, false, 10000, false); |
Adrian Alonso | c52eb1c | 2015-08-06 15:46:03 -0500 | [diff] [blame] | 170 | if (ret) |
| 171 | return ret; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 172 | |
| 173 | /* Reset USBPHY module */ |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 174 | setbits_le32(phy_ctrl, USBPHY_CTRL_SFTRST); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 175 | udelay(10); |
| 176 | |
| 177 | /* Remove CLKGATE and SFTRST */ |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 178 | clrbits_le32(phy_ctrl, USBPHY_CTRL_CLKGATE | USBPHY_CTRL_SFTRST); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 179 | udelay(10); |
| 180 | |
| 181 | /* Power up the PHY */ |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 182 | writel(0, phy_reg + USBPHY_PWD); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 183 | /* enable FS/LS device */ |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 184 | setbits_le32(phy_ctrl, USBPHY_CTRL_ENUTMILEVEL2 | |
| 185 | USBPHY_CTRL_ENUTMILEVEL3); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 186 | |
Peng Fan | 220402e | 2014-11-10 08:50:39 +0800 | [diff] [blame] | 187 | return 0; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 190 | int usb_phy_mode(int port) |
| 191 | { |
| 192 | void __iomem *phy_reg; |
| 193 | void __iomem *phy_ctrl; |
| 194 | u32 val; |
| 195 | |
| 196 | phy_reg = (void __iomem *)phy_bases[port]; |
| 197 | phy_ctrl = (void __iomem *)(phy_reg + USBPHY_CTRL); |
| 198 | |
| 199 | val = readl(phy_ctrl); |
| 200 | |
| 201 | if (val & USBPHY_CTRL_OTG_ID) |
| 202 | return USB_INIT_DEVICE; |
| 203 | else |
| 204 | return USB_INIT_HOST; |
| 205 | } |
| 206 | |
Ye Li | 9da57ea | 2019-10-24 10:29:32 -0300 | [diff] [blame] | 207 | #if defined(CONFIG_MX7ULP) |
| 208 | struct usbnc_regs { |
| 209 | u32 ctrl1; |
| 210 | u32 ctrl2; |
| 211 | u32 reserve0[2]; |
| 212 | u32 hsic_ctrl; |
| 213 | }; |
| 214 | #else |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 215 | /* Base address for this IP block is 0x02184800 */ |
| 216 | struct usbnc_regs { |
| 217 | u32 ctrl[4]; /* otg/host1-3 */ |
| 218 | u32 uh2_hsic_ctrl; |
| 219 | u32 uh3_hsic_ctrl; |
| 220 | u32 otg_phy_ctrl_0; |
| 221 | u32 uh1_phy_ctrl_0; |
| 222 | }; |
Ye Li | 9da57ea | 2019-10-24 10:29:32 -0300 | [diff] [blame] | 223 | #endif |
| 224 | |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 225 | #elif defined(CONFIG_MX7) |
| 226 | struct usbnc_regs { |
| 227 | u32 ctrl1; |
| 228 | u32 ctrl2; |
| 229 | u32 reserve1[10]; |
| 230 | u32 phy_cfg1; |
| 231 | u32 phy_cfg2; |
Peng Fan | 13186cf | 2016-06-20 09:43:08 +0800 | [diff] [blame] | 232 | u32 reserve2; |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 233 | u32 phy_status; |
Peng Fan | 13186cf | 2016-06-20 09:43:08 +0800 | [diff] [blame] | 234 | u32 reserve3[4]; |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 235 | u32 adp_cfg1; |
| 236 | u32 adp_cfg2; |
| 237 | u32 adp_status; |
| 238 | }; |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 239 | |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 240 | static void usb_power_config(int index) |
| 241 | { |
| 242 | struct usbnc_regs *usbnc = (struct usbnc_regs *)(USB_BASE_ADDR + |
| 243 | (0x10000 * index) + USBNC_OFFSET); |
| 244 | void __iomem *phy_cfg2 = (void __iomem *)(&usbnc->phy_cfg2); |
| 245 | |
Peng Fan | 928d3d0 | 2016-06-20 09:43:09 +0800 | [diff] [blame] | 246 | /* |
| 247 | * Clear the ACAENB to enable usb_otg_id detection, |
| 248 | * otherwise it is the ACA detection enabled. |
| 249 | */ |
| 250 | clrbits_le32(phy_cfg2, USBNC_PHYCFG2_ACAENB); |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | int usb_phy_mode(int port) |
| 254 | { |
| 255 | struct usbnc_regs *usbnc = (struct usbnc_regs *)(USB_BASE_ADDR + |
| 256 | (0x10000 * port) + USBNC_OFFSET); |
| 257 | void __iomem *status = (void __iomem *)(&usbnc->phy_status); |
| 258 | u32 val; |
| 259 | |
| 260 | val = readl(status); |
| 261 | |
| 262 | if (val & USBNC_PHYSTATUS_ID_DIG) |
| 263 | return USB_INIT_DEVICE; |
| 264 | else |
| 265 | return USB_INIT_HOST; |
| 266 | } |
| 267 | #endif |
| 268 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 269 | static void usb_oc_config(int index) |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 270 | { |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 271 | #if defined(CONFIG_MX6) |
Ye.Li | f93453a | 2014-09-15 17:23:14 +0800 | [diff] [blame] | 272 | struct usbnc_regs *usbnc = (struct usbnc_regs *)(USB_BASE_ADDR + |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 273 | USB_OTHERREGS_OFFSET); |
| 274 | void __iomem *ctrl = (void __iomem *)(&usbnc->ctrl[index]); |
Ye Li | 9da57ea | 2019-10-24 10:29:32 -0300 | [diff] [blame] | 275 | #elif defined(CONFIG_MX7) || defined(CONFIG_MX7ULP) |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 276 | struct usbnc_regs *usbnc = (struct usbnc_regs *)(USB_BASE_ADDR + |
| 277 | (0x10000 * index) + USBNC_OFFSET); |
| 278 | void __iomem *ctrl = (void __iomem *)(&usbnc->ctrl1); |
| 279 | #endif |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 280 | |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 281 | #if CONFIG_MACH_TYPE == MACH_TYPE_MX6Q_ARM2 |
| 282 | /* mx6qarm2 seems to required a different setting*/ |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 283 | clrbits_le32(ctrl, UCTRL_OVER_CUR_POL); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 284 | #else |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 285 | setbits_le32(ctrl, UCTRL_OVER_CUR_POL); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 286 | #endif |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 287 | |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 288 | setbits_le32(ctrl, UCTRL_OVER_CUR_DIS); |
Ye Li | 9da57ea | 2019-10-24 10:29:32 -0300 | [diff] [blame] | 289 | |
| 290 | /* Set power polarity to high active */ |
| 291 | #ifdef CONFIG_MXC_USB_OTG_HACTIVE |
| 292 | setbits_le32(ctrl, UCTRL_PWR_POL); |
| 293 | #else |
| 294 | clrbits_le32(ctrl, UCTRL_PWR_POL); |
| 295 | #endif |
Peng Fan | 220402e | 2014-11-10 08:50:39 +0800 | [diff] [blame] | 296 | } |
| 297 | |
Adrian Alonso | 14dfbbb | 2015-08-06 15:43:16 -0500 | [diff] [blame] | 298 | /** |
Stefan Agner | 3dfd3a0 | 2016-05-05 16:59:12 -0700 | [diff] [blame] | 299 | * board_usb_phy_mode - override usb phy mode |
Adrian Alonso | 14dfbbb | 2015-08-06 15:43:16 -0500 | [diff] [blame] | 300 | * @port: usb host/otg port |
| 301 | * |
| 302 | * Target board specific, override usb_phy_mode. |
| 303 | * When usb-otg is used as usb host port, iomux pad usb_otg_id can be |
| 304 | * left disconnected in this case usb_phy_mode will not be able to identify |
| 305 | * the phy mode that usb port is used. |
| 306 | * Machine file overrides board_usb_phy_mode. |
| 307 | * |
| 308 | * Return: USB_INIT_DEVICE or USB_INIT_HOST |
| 309 | */ |
Peng Fan | 220402e | 2014-11-10 08:50:39 +0800 | [diff] [blame] | 310 | int __weak board_usb_phy_mode(int port) |
| 311 | { |
| 312 | return usb_phy_mode(port); |
| 313 | } |
| 314 | |
Adrian Alonso | 14dfbbb | 2015-08-06 15:43:16 -0500 | [diff] [blame] | 315 | /** |
| 316 | * board_ehci_hcd_init - set usb vbus voltage |
| 317 | * @port: usb otg port |
| 318 | * |
| 319 | * Target board specific, setup iomux pad to setup supply vbus voltage |
| 320 | * for usb otg port. Machine board file overrides board_ehci_hcd_init |
| 321 | * |
| 322 | * Return: 0 Success |
| 323 | */ |
Benoît Thébaudeau | 98023c1 | 2012-11-13 09:58:35 +0000 | [diff] [blame] | 324 | int __weak board_ehci_hcd_init(int port) |
| 325 | { |
| 326 | return 0; |
| 327 | } |
| 328 | |
Adrian Alonso | 14dfbbb | 2015-08-06 15:43:16 -0500 | [diff] [blame] | 329 | /** |
| 330 | * board_ehci_power - enables/disables usb vbus voltage |
| 331 | * @port: usb otg port |
| 332 | * @on: on/off vbus voltage |
| 333 | * |
| 334 | * Enables/disables supply vbus voltage for usb otg port. |
| 335 | * Machine board file overrides board_ehci_power |
| 336 | * |
| 337 | * Return: 0 Success |
| 338 | */ |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 339 | int __weak board_ehci_power(int port, int on) |
| 340 | { |
| 341 | return 0; |
| 342 | } |
| 343 | |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 344 | int ehci_mx6_common_init(struct usb_ehci *ehci, int index) |
| 345 | { |
| 346 | int ret; |
| 347 | |
| 348 | enable_usboh3_clk(1); |
| 349 | mdelay(1); |
| 350 | |
| 351 | /* Do board specific initialization */ |
| 352 | ret = board_ehci_hcd_init(index); |
| 353 | if (ret) |
| 354 | return ret; |
| 355 | |
| 356 | usb_power_config(index); |
| 357 | usb_oc_config(index); |
| 358 | |
Ye Li | 9da57ea | 2019-10-24 10:29:32 -0300 | [diff] [blame] | 359 | #if defined(CONFIG_MX6) || defined(CONFIG_MX7ULP) |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 360 | usb_internal_phy_clock_gate(index, 1); |
| 361 | usb_phy_enable(index, ehci); |
| 362 | #endif |
| 363 | |
| 364 | return 0; |
| 365 | } |
| 366 | |
Sven Schwermer | 8a3cb9f1 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 367 | #if !CONFIG_IS_ENABLED(DM_USB) |
Troy Kisky | 7d6bbb9 | 2013-10-10 15:27:57 -0700 | [diff] [blame] | 368 | int ehci_hcd_init(int index, enum usb_init_type init, |
| 369 | struct ehci_hccr **hccr, struct ehci_hcor **hcor) |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 370 | { |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 371 | enum usb_init_type type; |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 372 | #if defined(CONFIG_MX6) |
| 373 | u32 controller_spacing = 0x200; |
Ye Li | 9da57ea | 2019-10-24 10:29:32 -0300 | [diff] [blame] | 374 | #elif defined(CONFIG_MX7) || defined(CONFIG_MX7ULP) |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 375 | u32 controller_spacing = 0x10000; |
| 376 | #endif |
Ye.Li | f93453a | 2014-09-15 17:23:14 +0800 | [diff] [blame] | 377 | struct usb_ehci *ehci = (struct usb_ehci *)(USB_BASE_ADDR + |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 378 | (controller_spacing * index)); |
Stefan Agner | 3dfd3a0 | 2016-05-05 16:59:12 -0700 | [diff] [blame] | 379 | int ret; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 380 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 381 | if (index > 3) |
| 382 | return -EINVAL; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 383 | |
Peng Fan | f8b2719 | 2020-05-01 22:08:36 +0800 | [diff] [blame] | 384 | if (CONFIG_IS_ENABLED(IMX_MODULE_FUSE)) { |
| 385 | if (usb_fused((ulong)ehci)) { |
| 386 | printf("SoC fuse indicates USB@0x%lx is unavailable.\n", |
| 387 | (ulong)ehci); |
| 388 | return -ENODEV; |
| 389 | } |
| 390 | } |
| 391 | |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 392 | ret = ehci_mx6_common_init(ehci, index); |
Stefan Agner | 3dfd3a0 | 2016-05-05 16:59:12 -0700 | [diff] [blame] | 393 | if (ret) |
| 394 | return ret; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 395 | |
Peng Fan | 220402e | 2014-11-10 08:50:39 +0800 | [diff] [blame] | 396 | type = board_usb_phy_mode(index); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 397 | |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 398 | if (hccr && hcor) { |
| 399 | *hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength); |
| 400 | *hcor = (struct ehci_hcor *)((uint32_t)*hccr + |
| 401 | HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
| 402 | } |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 403 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 404 | if ((type == init) || (type == USB_INIT_DEVICE)) |
| 405 | board_ehci_power(index, (type == USB_INIT_DEVICE) ? 0 : 1); |
| 406 | if (type != init) |
| 407 | return -ENODEV; |
| 408 | if (type == USB_INIT_DEVICE) |
| 409 | return 0; |
Adrian Alonso | f31599f | 2015-08-06 15:43:17 -0500 | [diff] [blame] | 410 | |
Troy Kisky | ed72a9e | 2013-10-10 15:27:59 -0700 | [diff] [blame] | 411 | setbits_le32(&ehci->usbmode, CM_HOST); |
Adrian Alonso | aee79b4 | 2015-08-06 15:43:15 -0500 | [diff] [blame] | 412 | writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 413 | setbits_le32(&ehci->portsc, USB_EN); |
| 414 | |
| 415 | mdelay(10); |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 420 | int ehci_hcd_stop(int index) |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 421 | { |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 422 | return 0; |
| 423 | } |
| 424 | #else |
| 425 | struct ehci_mx6_priv_data { |
| 426 | struct ehci_ctrl ctrl; |
| 427 | struct usb_ehci *ehci; |
Peng Fan | 1335133 | 2016-12-22 17:06:43 +0800 | [diff] [blame] | 428 | struct udevice *vbus_supply; |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 429 | enum usb_init_type init_type; |
| 430 | int portnr; |
| 431 | }; |
| 432 | |
| 433 | static int mx6_init_after_reset(struct ehci_ctrl *dev) |
| 434 | { |
| 435 | struct ehci_mx6_priv_data *priv = dev->priv; |
| 436 | enum usb_init_type type = priv->init_type; |
| 437 | struct usb_ehci *ehci = priv->ehci; |
| 438 | int ret; |
| 439 | |
| 440 | ret = ehci_mx6_common_init(priv->ehci, priv->portnr); |
| 441 | if (ret) |
| 442 | return ret; |
| 443 | |
Abel Vesa | 888a946 | 2019-02-01 16:40:08 +0000 | [diff] [blame] | 444 | #if CONFIG_IS_ENABLED(DM_REGULATOR) |
Peng Fan | 1335133 | 2016-12-22 17:06:43 +0800 | [diff] [blame] | 445 | if (priv->vbus_supply) { |
| 446 | ret = regulator_set_enable(priv->vbus_supply, |
| 447 | (type == USB_INIT_DEVICE) ? |
| 448 | false : true); |
| 449 | if (ret) { |
| 450 | puts("Error enabling VBUS supply\n"); |
| 451 | return ret; |
| 452 | } |
| 453 | } |
Abel Vesa | 888a946 | 2019-02-01 16:40:08 +0000 | [diff] [blame] | 454 | #endif |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 455 | |
| 456 | if (type == USB_INIT_DEVICE) |
| 457 | return 0; |
| 458 | |
| 459 | setbits_le32(&ehci->usbmode, CM_HOST); |
| 460 | writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc); |
| 461 | setbits_le32(&ehci->portsc, USB_EN); |
| 462 | |
| 463 | mdelay(10); |
| 464 | |
| 465 | return 0; |
| 466 | } |
| 467 | |
| 468 | static const struct ehci_ops mx6_ehci_ops = { |
| 469 | .init_after_reset = mx6_init_after_reset |
| 470 | }; |
| 471 | |
Peng Fan | 9e3eab3 | 2016-12-22 17:06:42 +0800 | [diff] [blame] | 472 | static int ehci_usb_phy_mode(struct udevice *dev) |
| 473 | { |
| 474 | struct usb_platdata *plat = dev_get_platdata(dev); |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 475 | void *__iomem addr = (void *__iomem)devfdt_get_addr(dev); |
Peng Fan | 9e3eab3 | 2016-12-22 17:06:42 +0800 | [diff] [blame] | 476 | void *__iomem phy_ctrl, *__iomem phy_status; |
| 477 | const void *blob = gd->fdt_blob; |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 478 | int offset = dev_of_offset(dev), phy_off; |
Peng Fan | 9e3eab3 | 2016-12-22 17:06:42 +0800 | [diff] [blame] | 479 | u32 val; |
| 480 | |
| 481 | /* |
| 482 | * About fsl,usbphy, Refer to |
| 483 | * Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt. |
| 484 | */ |
Ye Li | 9da57ea | 2019-10-24 10:29:32 -0300 | [diff] [blame] | 485 | if (is_mx6() || is_mx7ulp()) { |
Peng Fan | 9e3eab3 | 2016-12-22 17:06:42 +0800 | [diff] [blame] | 486 | phy_off = fdtdec_lookup_phandle(blob, |
| 487 | offset, |
| 488 | "fsl,usbphy"); |
| 489 | if (phy_off < 0) |
| 490 | return -EINVAL; |
| 491 | |
| 492 | addr = (void __iomem *)fdtdec_get_addr(blob, phy_off, |
| 493 | "reg"); |
| 494 | if ((fdt_addr_t)addr == FDT_ADDR_T_NONE) |
| 495 | return -EINVAL; |
| 496 | |
| 497 | phy_ctrl = (void __iomem *)(addr + USBPHY_CTRL); |
| 498 | val = readl(phy_ctrl); |
| 499 | |
| 500 | if (val & USBPHY_CTRL_OTG_ID) |
| 501 | plat->init_type = USB_INIT_DEVICE; |
| 502 | else |
| 503 | plat->init_type = USB_INIT_HOST; |
| 504 | } else if (is_mx7()) { |
| 505 | phy_status = (void __iomem *)(addr + |
| 506 | USBNC_PHY_STATUS_OFFSET); |
| 507 | val = readl(phy_status); |
| 508 | |
| 509 | if (val & USBNC_PHYSTATUS_ID_DIG) |
| 510 | plat->init_type = USB_INIT_DEVICE; |
| 511 | else |
| 512 | plat->init_type = USB_INIT_HOST; |
| 513 | } else { |
| 514 | return -EINVAL; |
| 515 | } |
| 516 | |
| 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | static int ehci_usb_ofdata_to_platdata(struct udevice *dev) |
| 521 | { |
| 522 | struct usb_platdata *plat = dev_get_platdata(dev); |
Adam Ford | 15287f0 | 2019-04-03 08:41:56 -0500 | [diff] [blame] | 523 | enum usb_dr_mode dr_mode; |
Peng Fan | 9e3eab3 | 2016-12-22 17:06:42 +0800 | [diff] [blame] | 524 | |
Kever Yang | 1b80705 | 2020-03-04 08:59:50 +0800 | [diff] [blame] | 525 | dr_mode = usb_get_dr_mode(dev->node); |
Peng Fan | 9e3eab3 | 2016-12-22 17:06:42 +0800 | [diff] [blame] | 526 | |
Adam Ford | 15287f0 | 2019-04-03 08:41:56 -0500 | [diff] [blame] | 527 | switch (dr_mode) { |
| 528 | case USB_DR_MODE_HOST: |
| 529 | plat->init_type = USB_INIT_HOST; |
| 530 | break; |
| 531 | case USB_DR_MODE_PERIPHERAL: |
| 532 | plat->init_type = USB_INIT_DEVICE; |
| 533 | break; |
| 534 | case USB_DR_MODE_OTG: |
| 535 | case USB_DR_MODE_UNKNOWN: |
| 536 | return ehci_usb_phy_mode(dev); |
| 537 | }; |
Peng Fan | 9e3eab3 | 2016-12-22 17:06:42 +0800 | [diff] [blame] | 538 | |
Adam Ford | 15287f0 | 2019-04-03 08:41:56 -0500 | [diff] [blame] | 539 | return 0; |
Peng Fan | 9e3eab3 | 2016-12-22 17:06:42 +0800 | [diff] [blame] | 540 | } |
| 541 | |
Marek Vasut | d93dda7 | 2019-06-24 19:05:47 +0200 | [diff] [blame] | 542 | static int ehci_usb_bind(struct udevice *dev) |
| 543 | { |
| 544 | /* |
| 545 | * TODO: |
| 546 | * This driver is only partly converted to DT probing and still uses |
| 547 | * a tremendous amount of hard-coded addresses. To make things worse, |
| 548 | * the driver depends on specific sequential indexing of controllers, |
| 549 | * from which it derives offsets in the PHY and ANATOP register sets. |
| 550 | * |
| 551 | * Here we attempt to calculate these indexes from DT information as |
Igor Opaniuk | 9c24d01 | 2019-10-10 16:09:35 +0300 | [diff] [blame] | 552 | * well as we can. The USB controllers on all existing iMX6 SoCs |
| 553 | * are placed next to each other, at addresses incremented by 0x200, |
| 554 | * and iMX7 their addresses are shifted by 0x10000. |
| 555 | * Thus, the index is derived from the multiple of 0x200 (0x10000 for |
| 556 | * iMX7) offset from the first controller address. |
Marek Vasut | d93dda7 | 2019-06-24 19:05:47 +0200 | [diff] [blame] | 557 | * |
| 558 | * However, to complete conversion of this driver to DT probing, the |
| 559 | * following has to be done: |
| 560 | * - DM clock framework support for iMX must be implemented |
| 561 | * - usb_power_config() has to be converted to clock framework |
| 562 | * -> Thus, the ad-hoc "index" variable goes away. |
| 563 | * - USB PHY handling has to be factored out into separate driver |
| 564 | * -> Thus, the ad-hoc "index" variable goes away from the PHY |
| 565 | * code, the PHY driver must parse it's address from DT. This |
| 566 | * USB driver must find the PHY driver via DT phandle. |
| 567 | * -> usb_power_config() shall be moved to PHY driver |
| 568 | * With these changes in place, the ad-hoc indexing goes away and |
| 569 | * the driver is fully converted to DT probing. |
| 570 | */ |
Igor Opaniuk | 9c24d01 | 2019-10-10 16:09:35 +0300 | [diff] [blame] | 571 | u32 controller_spacing = is_mx7() ? 0x10000 : 0x200; |
| 572 | fdt_addr_t addr = devfdt_get_addr_index(dev, 0); |
Marek Vasut | d93dda7 | 2019-06-24 19:05:47 +0200 | [diff] [blame] | 573 | |
Igor Opaniuk | 9c24d01 | 2019-10-10 16:09:35 +0300 | [diff] [blame] | 574 | dev->req_seq = (addr - USB_BASE_ADDR) / controller_spacing; |
Marek Vasut | d93dda7 | 2019-06-24 19:05:47 +0200 | [diff] [blame] | 575 | |
| 576 | return 0; |
| 577 | } |
| 578 | |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 579 | static int ehci_usb_probe(struct udevice *dev) |
| 580 | { |
| 581 | struct usb_platdata *plat = dev_get_platdata(dev); |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 582 | struct usb_ehci *ehci = (struct usb_ehci *)devfdt_get_addr(dev); |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 583 | struct ehci_mx6_priv_data *priv = dev_get_priv(dev); |
Peng Fan | 1335133 | 2016-12-22 17:06:43 +0800 | [diff] [blame] | 584 | enum usb_init_type type = plat->init_type; |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 585 | struct ehci_hccr *hccr; |
| 586 | struct ehci_hcor *hcor; |
| 587 | int ret; |
| 588 | |
Peng Fan | f8b2719 | 2020-05-01 22:08:36 +0800 | [diff] [blame] | 589 | if (CONFIG_IS_ENABLED(IMX_MODULE_FUSE)) { |
| 590 | if (usb_fused((ulong)ehci)) { |
| 591 | printf("SoC fuse indicates USB@0x%lx is unavailable.\n", |
| 592 | (ulong)ehci); |
| 593 | return -ENODEV; |
| 594 | } |
| 595 | } |
| 596 | |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 597 | priv->ehci = ehci; |
| 598 | priv->portnr = dev->seq; |
Peng Fan | 1335133 | 2016-12-22 17:06:43 +0800 | [diff] [blame] | 599 | priv->init_type = type; |
| 600 | |
Abel Vesa | 888a946 | 2019-02-01 16:40:08 +0000 | [diff] [blame] | 601 | #if CONFIG_IS_ENABLED(DM_REGULATOR) |
Peng Fan | 1335133 | 2016-12-22 17:06:43 +0800 | [diff] [blame] | 602 | ret = device_get_supply_regulator(dev, "vbus-supply", |
| 603 | &priv->vbus_supply); |
| 604 | if (ret) |
| 605 | debug("%s: No vbus supply\n", dev->name); |
Abel Vesa | 888a946 | 2019-02-01 16:40:08 +0000 | [diff] [blame] | 606 | #endif |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 607 | ret = ehci_mx6_common_init(ehci, priv->portnr); |
| 608 | if (ret) |
| 609 | return ret; |
| 610 | |
Abel Vesa | 888a946 | 2019-02-01 16:40:08 +0000 | [diff] [blame] | 611 | #if CONFIG_IS_ENABLED(DM_REGULATOR) |
Peng Fan | 1335133 | 2016-12-22 17:06:43 +0800 | [diff] [blame] | 612 | if (priv->vbus_supply) { |
| 613 | ret = regulator_set_enable(priv->vbus_supply, |
| 614 | (type == USB_INIT_DEVICE) ? |
| 615 | false : true); |
| 616 | if (ret) { |
| 617 | puts("Error enabling VBUS supply\n"); |
| 618 | return ret; |
| 619 | } |
| 620 | } |
Abel Vesa | 888a946 | 2019-02-01 16:40:08 +0000 | [diff] [blame] | 621 | #endif |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 622 | |
| 623 | if (priv->init_type == USB_INIT_HOST) { |
| 624 | setbits_le32(&ehci->usbmode, CM_HOST); |
| 625 | writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc); |
| 626 | setbits_le32(&ehci->portsc, USB_EN); |
| 627 | } |
| 628 | |
| 629 | mdelay(10); |
| 630 | |
| 631 | hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength); |
| 632 | hcor = (struct ehci_hcor *)((uint32_t)hccr + |
| 633 | HC_LENGTH(ehci_readl(&(hccr)->cr_capbase))); |
| 634 | |
| 635 | return ehci_register(dev, hccr, hcor, &mx6_ehci_ops, 0, priv->init_type); |
| 636 | } |
| 637 | |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 638 | static const struct udevice_id mx6_usb_ids[] = { |
| 639 | { .compatible = "fsl,imx27-usb" }, |
| 640 | { } |
| 641 | }; |
| 642 | |
| 643 | U_BOOT_DRIVER(usb_mx6) = { |
| 644 | .name = "ehci_mx6", |
| 645 | .id = UCLASS_USB, |
| 646 | .of_match = mx6_usb_ids, |
Peng Fan | 9e3eab3 | 2016-12-22 17:06:42 +0800 | [diff] [blame] | 647 | .ofdata_to_platdata = ehci_usb_ofdata_to_platdata, |
Marek Vasut | d93dda7 | 2019-06-24 19:05:47 +0200 | [diff] [blame] | 648 | .bind = ehci_usb_bind, |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 649 | .probe = ehci_usb_probe, |
Masahiro Yamada | d41919b | 2016-09-06 22:17:34 +0900 | [diff] [blame] | 650 | .remove = ehci_deregister, |
Peng Fan | 5c363c1 | 2016-06-17 14:19:27 +0800 | [diff] [blame] | 651 | .ops = &ehci_usb_ops, |
| 652 | .platdata_auto_alloc_size = sizeof(struct usb_platdata), |
| 653 | .priv_auto_alloc_size = sizeof(struct ehci_mx6_priv_data), |
| 654 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 655 | }; |
| 656 | #endif |