Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1 | /* |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 2 | * Copyright (C) 2010 Google, Inc. |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 3 | * Copyright (C) 2013 NVIDIA Corporation |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 4 | * |
| 5 | * Author: |
| 6 | * Erik Gilling <konkers@google.com> |
| 7 | * Benoit Goby <benoit@android.com> |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 8 | * Venu Byravarasu <vbyravarasu@nvidia.com> |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 9 | * |
| 10 | * This software is licensed under the terms of the GNU General Public |
| 11 | * License version 2, as published by the Free Software Foundation, and |
| 12 | * may be copied, distributed, and modified under those terms. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <linux/resource.h> |
| 22 | #include <linux/delay.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/err.h> |
Arnd Bergmann | 4265cbf | 2012-03-02 15:58:42 -0500 | [diff] [blame] | 25 | #include <linux/export.h> |
Stephen Warren | 587376a | 2013-06-13 11:24:08 -0600 | [diff] [blame] | 26 | #include <linux/module.h> |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 27 | #include <linux/platform_device.h> |
| 28 | #include <linux/io.h> |
| 29 | #include <linux/gpio.h> |
Venu Byravarasu | 3a55c6a | 2013-01-16 03:30:20 +0000 | [diff] [blame] | 30 | #include <linux/of.h> |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame^] | 31 | #include <linux/of_device.h> |
Stephen Warren | aa607eb | 2012-04-12 15:46:49 -0600 | [diff] [blame] | 32 | #include <linux/of_gpio.h> |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 33 | #include <linux/usb/otg.h> |
| 34 | #include <linux/usb/ulpi.h> |
Tuomas Tynkkynen | 9fdb07f | 2013-07-25 21:38:08 +0300 | [diff] [blame] | 35 | #include <linux/usb/of.h> |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 36 | #include <asm/mach-types.h> |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 37 | #include <linux/usb/ehci_def.h> |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 38 | #include <linux/usb/tegra_usb_phy.h> |
Mikko Perttunen | f5b8c8b | 2013-07-17 10:37:49 +0300 | [diff] [blame] | 39 | #include <linux/regulator/consumer.h> |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 40 | |
| 41 | #define ULPI_VIEWPORT 0x170 |
| 42 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame^] | 43 | /* PORTSC PTS/PHCD bits, Tegra20 only */ |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 44 | #define TEGRA_USB_PORTSC1 0x184 |
| 45 | #define TEGRA_USB_PORTSC1_PTS(x) (((x) & 0x3) << 30) |
| 46 | #define TEGRA_USB_PORTSC1_PHCD (1 << 23) |
| 47 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame^] | 48 | /* HOSTPC1 PTS/PHCD bits, Tegra30 and above */ |
| 49 | #define TEGRA_USB_HOSTPC1_DEVLC 0x1b4 |
| 50 | #define TEGRA_USB_HOSTPC1_DEVLC_PTS(x) (((x) & 0x7) << 29) |
| 51 | #define TEGRA_USB_HOSTPC1_DEVLC_PHCD (1 << 22) |
| 52 | |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 53 | /* Bits of PORTSC1, which will get cleared by writing 1 into them */ |
| 54 | #define TEGRA_PORTSC1_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC) |
| 55 | |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 56 | #define USB_SUSP_CTRL 0x400 |
| 57 | #define USB_WAKE_ON_CNNT_EN_DEV (1 << 3) |
| 58 | #define USB_WAKE_ON_DISCON_EN_DEV (1 << 4) |
| 59 | #define USB_SUSP_CLR (1 << 5) |
| 60 | #define USB_PHY_CLK_VALID (1 << 7) |
| 61 | #define UTMIP_RESET (1 << 11) |
| 62 | #define UHSIC_RESET (1 << 11) |
| 63 | #define UTMIP_PHY_ENABLE (1 << 12) |
| 64 | #define ULPI_PHY_ENABLE (1 << 13) |
| 65 | #define USB_SUSP_SET (1 << 14) |
| 66 | #define USB_WAKEUP_DEBOUNCE_COUNT(x) (((x) & 0x7) << 16) |
| 67 | |
| 68 | #define USB1_LEGACY_CTRL 0x410 |
| 69 | #define USB1_NO_LEGACY_MODE (1 << 0) |
| 70 | #define USB1_VBUS_SENSE_CTL_MASK (3 << 1) |
| 71 | #define USB1_VBUS_SENSE_CTL_VBUS_WAKEUP (0 << 1) |
| 72 | #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD_OR_VBUS_WAKEUP \ |
| 73 | (1 << 1) |
| 74 | #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD (2 << 1) |
| 75 | #define USB1_VBUS_SENSE_CTL_A_SESS_VLD (3 << 1) |
| 76 | |
| 77 | #define ULPI_TIMING_CTRL_0 0x424 |
| 78 | #define ULPI_OUTPUT_PINMUX_BYP (1 << 10) |
| 79 | #define ULPI_CLKOUT_PINMUX_BYP (1 << 11) |
| 80 | |
| 81 | #define ULPI_TIMING_CTRL_1 0x428 |
| 82 | #define ULPI_DATA_TRIMMER_LOAD (1 << 0) |
| 83 | #define ULPI_DATA_TRIMMER_SEL(x) (((x) & 0x7) << 1) |
| 84 | #define ULPI_STPDIRNXT_TRIMMER_LOAD (1 << 16) |
| 85 | #define ULPI_STPDIRNXT_TRIMMER_SEL(x) (((x) & 0x7) << 17) |
| 86 | #define ULPI_DIR_TRIMMER_LOAD (1 << 24) |
| 87 | #define ULPI_DIR_TRIMMER_SEL(x) (((x) & 0x7) << 25) |
| 88 | |
| 89 | #define UTMIP_PLL_CFG1 0x804 |
| 90 | #define UTMIP_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0) |
| 91 | #define UTMIP_PLLU_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27) |
| 92 | |
| 93 | #define UTMIP_XCVR_CFG0 0x808 |
| 94 | #define UTMIP_XCVR_SETUP(x) (((x) & 0xf) << 0) |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 95 | #define UTMIP_XCVR_SETUP_MSB(x) ((((x) & 0x70) >> 4) << 22) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 96 | #define UTMIP_XCVR_LSRSLEW(x) (((x) & 0x3) << 8) |
| 97 | #define UTMIP_XCVR_LSFSLEW(x) (((x) & 0x3) << 10) |
| 98 | #define UTMIP_FORCE_PD_POWERDOWN (1 << 14) |
| 99 | #define UTMIP_FORCE_PD2_POWERDOWN (1 << 16) |
| 100 | #define UTMIP_FORCE_PDZI_POWERDOWN (1 << 18) |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 101 | #define UTMIP_XCVR_LSBIAS_SEL (1 << 21) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 102 | #define UTMIP_XCVR_HSSLEW_MSB(x) (((x) & 0x7f) << 25) |
| 103 | |
| 104 | #define UTMIP_BIAS_CFG0 0x80c |
| 105 | #define UTMIP_OTGPD (1 << 11) |
| 106 | #define UTMIP_BIASPD (1 << 10) |
| 107 | |
| 108 | #define UTMIP_HSRX_CFG0 0x810 |
| 109 | #define UTMIP_ELASTIC_LIMIT(x) (((x) & 0x1f) << 10) |
| 110 | #define UTMIP_IDLE_WAIT(x) (((x) & 0x1f) << 15) |
| 111 | |
| 112 | #define UTMIP_HSRX_CFG1 0x814 |
| 113 | #define UTMIP_HS_SYNC_START_DLY(x) (((x) & 0x1f) << 1) |
| 114 | |
| 115 | #define UTMIP_TX_CFG0 0x820 |
| 116 | #define UTMIP_FS_PREABMLE_J (1 << 19) |
| 117 | #define UTMIP_HS_DISCON_DISABLE (1 << 8) |
| 118 | |
| 119 | #define UTMIP_MISC_CFG0 0x824 |
| 120 | #define UTMIP_DPDM_OBSERVE (1 << 26) |
| 121 | #define UTMIP_DPDM_OBSERVE_SEL(x) (((x) & 0xf) << 27) |
| 122 | #define UTMIP_DPDM_OBSERVE_SEL_FS_J UTMIP_DPDM_OBSERVE_SEL(0xf) |
| 123 | #define UTMIP_DPDM_OBSERVE_SEL_FS_K UTMIP_DPDM_OBSERVE_SEL(0xe) |
| 124 | #define UTMIP_DPDM_OBSERVE_SEL_FS_SE1 UTMIP_DPDM_OBSERVE_SEL(0xd) |
| 125 | #define UTMIP_DPDM_OBSERVE_SEL_FS_SE0 UTMIP_DPDM_OBSERVE_SEL(0xc) |
| 126 | #define UTMIP_SUSPEND_EXIT_ON_EDGE (1 << 22) |
| 127 | |
| 128 | #define UTMIP_MISC_CFG1 0x828 |
| 129 | #define UTMIP_PLL_ACTIVE_DLY_COUNT(x) (((x) & 0x1f) << 18) |
| 130 | #define UTMIP_PLLU_STABLE_COUNT(x) (((x) & 0xfff) << 6) |
| 131 | |
| 132 | #define UTMIP_DEBOUNCE_CFG0 0x82c |
| 133 | #define UTMIP_BIAS_DEBOUNCE_A(x) (((x) & 0xffff) << 0) |
| 134 | |
| 135 | #define UTMIP_BAT_CHRG_CFG0 0x830 |
| 136 | #define UTMIP_PD_CHRG (1 << 0) |
| 137 | |
| 138 | #define UTMIP_SPARE_CFG0 0x834 |
| 139 | #define FUSE_SETUP_SEL (1 << 3) |
| 140 | |
| 141 | #define UTMIP_XCVR_CFG1 0x838 |
| 142 | #define UTMIP_FORCE_PDDISC_POWERDOWN (1 << 0) |
| 143 | #define UTMIP_FORCE_PDCHRP_POWERDOWN (1 << 2) |
| 144 | #define UTMIP_FORCE_PDDR_POWERDOWN (1 << 4) |
| 145 | #define UTMIP_XCVR_TERM_RANGE_ADJ(x) (((x) & 0xf) << 18) |
| 146 | |
| 147 | #define UTMIP_BIAS_CFG1 0x83c |
| 148 | #define UTMIP_BIAS_PDTRK_COUNT(x) (((x) & 0x1f) << 3) |
| 149 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame^] | 150 | /* For Tegra30 and above only, the address is different in Tegra20 */ |
| 151 | #define USB_USBMODE 0x1f8 |
| 152 | #define USB_USBMODE_MASK (3 << 0) |
| 153 | #define USB_USBMODE_HOST (3 << 0) |
| 154 | #define USB_USBMODE_DEVICE (2 << 0) |
| 155 | |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 156 | static DEFINE_SPINLOCK(utmip_pad_lock); |
| 157 | static int utmip_pad_count; |
| 158 | |
| 159 | struct tegra_xtal_freq { |
| 160 | int freq; |
| 161 | u8 enable_delay; |
| 162 | u8 stable_count; |
| 163 | u8 active_delay; |
| 164 | u8 xtal_freq_count; |
| 165 | u16 debounce; |
| 166 | }; |
| 167 | |
| 168 | static const struct tegra_xtal_freq tegra_freq_table[] = { |
| 169 | { |
| 170 | .freq = 12000000, |
| 171 | .enable_delay = 0x02, |
| 172 | .stable_count = 0x2F, |
| 173 | .active_delay = 0x04, |
| 174 | .xtal_freq_count = 0x76, |
| 175 | .debounce = 0x7530, |
| 176 | }, |
| 177 | { |
| 178 | .freq = 13000000, |
| 179 | .enable_delay = 0x02, |
| 180 | .stable_count = 0x33, |
| 181 | .active_delay = 0x05, |
| 182 | .xtal_freq_count = 0x7F, |
| 183 | .debounce = 0x7EF4, |
| 184 | }, |
| 185 | { |
| 186 | .freq = 19200000, |
| 187 | .enable_delay = 0x03, |
| 188 | .stable_count = 0x4B, |
| 189 | .active_delay = 0x06, |
| 190 | .xtal_freq_count = 0xBB, |
| 191 | .debounce = 0xBB80, |
| 192 | }, |
| 193 | { |
| 194 | .freq = 26000000, |
| 195 | .enable_delay = 0x04, |
| 196 | .stable_count = 0x66, |
| 197 | .active_delay = 0x09, |
| 198 | .xtal_freq_count = 0xFE, |
| 199 | .debounce = 0xFDE8, |
| 200 | }, |
| 201 | }; |
| 202 | |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 203 | static void set_pts(struct tegra_usb_phy *phy, u8 pts_val) |
| 204 | { |
| 205 | void __iomem *base = phy->regs; |
| 206 | unsigned long val; |
| 207 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame^] | 208 | if (phy->soc_config->has_hostpc) { |
| 209 | val = readl(base + TEGRA_USB_HOSTPC1_DEVLC); |
| 210 | val &= ~TEGRA_USB_HOSTPC1_DEVLC_PTS(~0); |
| 211 | val |= TEGRA_USB_HOSTPC1_DEVLC_PTS(pts_val); |
| 212 | writel(val, base + TEGRA_USB_HOSTPC1_DEVLC); |
| 213 | } else { |
| 214 | val = readl(base + TEGRA_USB_PORTSC1) & ~TEGRA_PORTSC1_RWC_BITS; |
| 215 | val &= ~TEGRA_USB_PORTSC1_PTS(~0); |
| 216 | val |= TEGRA_USB_PORTSC1_PTS(pts_val); |
| 217 | writel(val, base + TEGRA_USB_PORTSC1); |
| 218 | } |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static void set_phcd(struct tegra_usb_phy *phy, bool enable) |
| 222 | { |
| 223 | void __iomem *base = phy->regs; |
| 224 | unsigned long val; |
| 225 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame^] | 226 | if (phy->soc_config->has_hostpc) { |
| 227 | val = readl(base + TEGRA_USB_HOSTPC1_DEVLC); |
| 228 | if (enable) |
| 229 | val |= TEGRA_USB_HOSTPC1_DEVLC_PHCD; |
| 230 | else |
| 231 | val &= ~TEGRA_USB_HOSTPC1_DEVLC_PHCD; |
| 232 | writel(val, base + TEGRA_USB_HOSTPC1_DEVLC); |
| 233 | } else { |
| 234 | val = readl(base + TEGRA_USB_PORTSC1) & ~PORT_RWC_BITS; |
| 235 | if (enable) |
| 236 | val |= TEGRA_USB_PORTSC1_PHCD; |
| 237 | else |
| 238 | val &= ~TEGRA_USB_PORTSC1_PHCD; |
| 239 | writel(val, base + TEGRA_USB_PORTSC1); |
| 240 | } |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 241 | } |
| 242 | |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 243 | static int utmip_pad_open(struct tegra_usb_phy *phy) |
| 244 | { |
Tuomas Tynkkynen | 185d0fd | 2013-07-25 21:38:01 +0300 | [diff] [blame] | 245 | phy->pad_clk = devm_clk_get(phy->u_phy.dev, "utmi-pads"); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 246 | if (IS_ERR(phy->pad_clk)) { |
| 247 | pr_err("%s: can't get utmip pad clock\n", __func__); |
| 248 | return PTR_ERR(phy->pad_clk); |
| 249 | } |
| 250 | |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 251 | return 0; |
| 252 | } |
| 253 | |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 254 | static void utmip_pad_power_on(struct tegra_usb_phy *phy) |
| 255 | { |
| 256 | unsigned long val, flags; |
| 257 | void __iomem *base = phy->pad_regs; |
| 258 | |
Prashant Gaikwad | 6a5278d | 2012-06-05 09:59:35 +0530 | [diff] [blame] | 259 | clk_prepare_enable(phy->pad_clk); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 260 | |
| 261 | spin_lock_irqsave(&utmip_pad_lock, flags); |
| 262 | |
| 263 | if (utmip_pad_count++ == 0) { |
| 264 | val = readl(base + UTMIP_BIAS_CFG0); |
| 265 | val &= ~(UTMIP_OTGPD | UTMIP_BIASPD); |
| 266 | writel(val, base + UTMIP_BIAS_CFG0); |
| 267 | } |
| 268 | |
| 269 | spin_unlock_irqrestore(&utmip_pad_lock, flags); |
| 270 | |
Prashant Gaikwad | 6a5278d | 2012-06-05 09:59:35 +0530 | [diff] [blame] | 271 | clk_disable_unprepare(phy->pad_clk); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | static int utmip_pad_power_off(struct tegra_usb_phy *phy) |
| 275 | { |
| 276 | unsigned long val, flags; |
| 277 | void __iomem *base = phy->pad_regs; |
| 278 | |
| 279 | if (!utmip_pad_count) { |
| 280 | pr_err("%s: utmip pad already powered off\n", __func__); |
| 281 | return -EINVAL; |
| 282 | } |
| 283 | |
Prashant Gaikwad | 6a5278d | 2012-06-05 09:59:35 +0530 | [diff] [blame] | 284 | clk_prepare_enable(phy->pad_clk); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 285 | |
| 286 | spin_lock_irqsave(&utmip_pad_lock, flags); |
| 287 | |
| 288 | if (--utmip_pad_count == 0) { |
| 289 | val = readl(base + UTMIP_BIAS_CFG0); |
| 290 | val |= UTMIP_OTGPD | UTMIP_BIASPD; |
| 291 | writel(val, base + UTMIP_BIAS_CFG0); |
| 292 | } |
| 293 | |
| 294 | spin_unlock_irqrestore(&utmip_pad_lock, flags); |
| 295 | |
Prashant Gaikwad | 6a5278d | 2012-06-05 09:59:35 +0530 | [diff] [blame] | 296 | clk_disable_unprepare(phy->pad_clk); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | static int utmi_wait_register(void __iomem *reg, u32 mask, u32 result) |
| 302 | { |
| 303 | unsigned long timeout = 2000; |
| 304 | do { |
| 305 | if ((readl(reg) & mask) == result) |
| 306 | return 0; |
| 307 | udelay(1); |
| 308 | timeout--; |
| 309 | } while (timeout); |
| 310 | return -1; |
| 311 | } |
| 312 | |
| 313 | static void utmi_phy_clk_disable(struct tegra_usb_phy *phy) |
| 314 | { |
| 315 | unsigned long val; |
| 316 | void __iomem *base = phy->regs; |
| 317 | |
Venu Byravarasu | 3a55c6a | 2013-01-16 03:30:20 +0000 | [diff] [blame] | 318 | if (phy->is_legacy_phy) { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 319 | val = readl(base + USB_SUSP_CTRL); |
| 320 | val |= USB_SUSP_SET; |
| 321 | writel(val, base + USB_SUSP_CTRL); |
| 322 | |
| 323 | udelay(10); |
| 324 | |
| 325 | val = readl(base + USB_SUSP_CTRL); |
| 326 | val &= ~USB_SUSP_SET; |
| 327 | writel(val, base + USB_SUSP_CTRL); |
Venu Byravarasu | bbdabdb | 2013-01-17 20:15:37 +0000 | [diff] [blame] | 328 | } else |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 329 | set_phcd(phy, true); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 330 | |
| 331 | if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) < 0) |
| 332 | pr_err("%s: timeout waiting for phy to stabilize\n", __func__); |
| 333 | } |
| 334 | |
| 335 | static void utmi_phy_clk_enable(struct tegra_usb_phy *phy) |
| 336 | { |
| 337 | unsigned long val; |
| 338 | void __iomem *base = phy->regs; |
| 339 | |
Venu Byravarasu | 3a55c6a | 2013-01-16 03:30:20 +0000 | [diff] [blame] | 340 | if (phy->is_legacy_phy) { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 341 | val = readl(base + USB_SUSP_CTRL); |
| 342 | val |= USB_SUSP_CLR; |
| 343 | writel(val, base + USB_SUSP_CTRL); |
| 344 | |
| 345 | udelay(10); |
| 346 | |
| 347 | val = readl(base + USB_SUSP_CTRL); |
| 348 | val &= ~USB_SUSP_CLR; |
| 349 | writel(val, base + USB_SUSP_CTRL); |
Venu Byravarasu | bbdabdb | 2013-01-17 20:15:37 +0000 | [diff] [blame] | 350 | } else |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 351 | set_phcd(phy, false); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 352 | |
| 353 | if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, |
| 354 | USB_PHY_CLK_VALID)) |
| 355 | pr_err("%s: timeout waiting for phy to stabilize\n", __func__); |
| 356 | } |
| 357 | |
| 358 | static int utmi_phy_power_on(struct tegra_usb_phy *phy) |
| 359 | { |
| 360 | unsigned long val; |
| 361 | void __iomem *base = phy->regs; |
| 362 | struct tegra_utmip_config *config = phy->config; |
| 363 | |
| 364 | val = readl(base + USB_SUSP_CTRL); |
| 365 | val |= UTMIP_RESET; |
| 366 | writel(val, base + USB_SUSP_CTRL); |
| 367 | |
Venu Byravarasu | 3a55c6a | 2013-01-16 03:30:20 +0000 | [diff] [blame] | 368 | if (phy->is_legacy_phy) { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 369 | val = readl(base + USB1_LEGACY_CTRL); |
| 370 | val |= USB1_NO_LEGACY_MODE; |
| 371 | writel(val, base + USB1_LEGACY_CTRL); |
| 372 | } |
| 373 | |
| 374 | val = readl(base + UTMIP_TX_CFG0); |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 375 | val |= UTMIP_FS_PREABMLE_J; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 376 | writel(val, base + UTMIP_TX_CFG0); |
| 377 | |
| 378 | val = readl(base + UTMIP_HSRX_CFG0); |
| 379 | val &= ~(UTMIP_IDLE_WAIT(~0) | UTMIP_ELASTIC_LIMIT(~0)); |
| 380 | val |= UTMIP_IDLE_WAIT(config->idle_wait_delay); |
| 381 | val |= UTMIP_ELASTIC_LIMIT(config->elastic_limit); |
| 382 | writel(val, base + UTMIP_HSRX_CFG0); |
| 383 | |
| 384 | val = readl(base + UTMIP_HSRX_CFG1); |
| 385 | val &= ~UTMIP_HS_SYNC_START_DLY(~0); |
| 386 | val |= UTMIP_HS_SYNC_START_DLY(config->hssync_start_delay); |
| 387 | writel(val, base + UTMIP_HSRX_CFG1); |
| 388 | |
| 389 | val = readl(base + UTMIP_DEBOUNCE_CFG0); |
| 390 | val &= ~UTMIP_BIAS_DEBOUNCE_A(~0); |
| 391 | val |= UTMIP_BIAS_DEBOUNCE_A(phy->freq->debounce); |
| 392 | writel(val, base + UTMIP_DEBOUNCE_CFG0); |
| 393 | |
| 394 | val = readl(base + UTMIP_MISC_CFG0); |
| 395 | val &= ~UTMIP_SUSPEND_EXIT_ON_EDGE; |
| 396 | writel(val, base + UTMIP_MISC_CFG0); |
| 397 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame^] | 398 | if (!phy->soc_config->utmi_pll_config_in_car_module) { |
| 399 | val = readl(base + UTMIP_MISC_CFG1); |
| 400 | val &= ~(UTMIP_PLL_ACTIVE_DLY_COUNT(~0) | |
| 401 | UTMIP_PLLU_STABLE_COUNT(~0)); |
| 402 | val |= UTMIP_PLL_ACTIVE_DLY_COUNT(phy->freq->active_delay) | |
| 403 | UTMIP_PLLU_STABLE_COUNT(phy->freq->stable_count); |
| 404 | writel(val, base + UTMIP_MISC_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 405 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame^] | 406 | val = readl(base + UTMIP_PLL_CFG1); |
| 407 | val &= ~(UTMIP_XTAL_FREQ_COUNT(~0) | |
| 408 | UTMIP_PLLU_ENABLE_DLY_COUNT(~0)); |
| 409 | val |= UTMIP_XTAL_FREQ_COUNT(phy->freq->xtal_freq_count) | |
| 410 | UTMIP_PLLU_ENABLE_DLY_COUNT(phy->freq->enable_delay); |
| 411 | writel(val, base + UTMIP_PLL_CFG1); |
| 412 | } |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 413 | |
Tuomas Tynkkynen | 6558d7e | 2013-07-25 21:38:09 +0300 | [diff] [blame] | 414 | if (phy->mode == USB_DR_MODE_PERIPHERAL) { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 415 | val = readl(base + USB_SUSP_CTRL); |
| 416 | val &= ~(USB_WAKE_ON_CNNT_EN_DEV | USB_WAKE_ON_DISCON_EN_DEV); |
| 417 | writel(val, base + USB_SUSP_CTRL); |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 418 | |
| 419 | val = readl(base + UTMIP_BAT_CHRG_CFG0); |
| 420 | val &= ~UTMIP_PD_CHRG; |
| 421 | writel(val, base + UTMIP_BAT_CHRG_CFG0); |
| 422 | } else { |
| 423 | val = readl(base + UTMIP_BAT_CHRG_CFG0); |
| 424 | val |= UTMIP_PD_CHRG; |
| 425 | writel(val, base + UTMIP_BAT_CHRG_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | utmip_pad_power_on(phy); |
| 429 | |
| 430 | val = readl(base + UTMIP_XCVR_CFG0); |
| 431 | val &= ~(UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN | |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 432 | UTMIP_FORCE_PDZI_POWERDOWN | UTMIP_XCVR_LSBIAS_SEL | |
| 433 | UTMIP_XCVR_SETUP(~0) | UTMIP_XCVR_SETUP_MSB(~0) | |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 434 | UTMIP_XCVR_LSFSLEW(~0) | UTMIP_XCVR_LSRSLEW(~0) | |
| 435 | UTMIP_XCVR_HSSLEW_MSB(~0)); |
| 436 | val |= UTMIP_XCVR_SETUP(config->xcvr_setup); |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 437 | val |= UTMIP_XCVR_SETUP_MSB(config->xcvr_setup); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 438 | val |= UTMIP_XCVR_LSFSLEW(config->xcvr_lsfslew); |
| 439 | val |= UTMIP_XCVR_LSRSLEW(config->xcvr_lsrslew); |
| 440 | writel(val, base + UTMIP_XCVR_CFG0); |
| 441 | |
| 442 | val = readl(base + UTMIP_XCVR_CFG1); |
| 443 | val &= ~(UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN | |
| 444 | UTMIP_FORCE_PDDR_POWERDOWN | UTMIP_XCVR_TERM_RANGE_ADJ(~0)); |
| 445 | val |= UTMIP_XCVR_TERM_RANGE_ADJ(config->term_range_adj); |
| 446 | writel(val, base + UTMIP_XCVR_CFG1); |
| 447 | |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 448 | val = readl(base + UTMIP_BIAS_CFG1); |
| 449 | val &= ~UTMIP_BIAS_PDTRK_COUNT(~0); |
| 450 | val |= UTMIP_BIAS_PDTRK_COUNT(0x5); |
| 451 | writel(val, base + UTMIP_BIAS_CFG1); |
| 452 | |
Venu Byravarasu | 3a55c6a | 2013-01-16 03:30:20 +0000 | [diff] [blame] | 453 | if (phy->is_legacy_phy) { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 454 | val = readl(base + UTMIP_SPARE_CFG0); |
Tuomas Tynkkynen | 6558d7e | 2013-07-25 21:38:09 +0300 | [diff] [blame] | 455 | if (phy->mode == USB_DR_MODE_PERIPHERAL) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 456 | val &= ~FUSE_SETUP_SEL; |
| 457 | else |
| 458 | val |= FUSE_SETUP_SEL; |
| 459 | writel(val, base + UTMIP_SPARE_CFG0); |
Venu Byravarasu | 3a55c6a | 2013-01-16 03:30:20 +0000 | [diff] [blame] | 460 | } else { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 461 | val = readl(base + USB_SUSP_CTRL); |
| 462 | val |= UTMIP_PHY_ENABLE; |
| 463 | writel(val, base + USB_SUSP_CTRL); |
| 464 | } |
| 465 | |
| 466 | val = readl(base + USB_SUSP_CTRL); |
| 467 | val &= ~UTMIP_RESET; |
| 468 | writel(val, base + USB_SUSP_CTRL); |
| 469 | |
Venu Byravarasu | 3a55c6a | 2013-01-16 03:30:20 +0000 | [diff] [blame] | 470 | if (phy->is_legacy_phy) { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 471 | val = readl(base + USB1_LEGACY_CTRL); |
| 472 | val &= ~USB1_VBUS_SENSE_CTL_MASK; |
| 473 | val |= USB1_VBUS_SENSE_CTL_A_SESS_VLD; |
| 474 | writel(val, base + USB1_LEGACY_CTRL); |
| 475 | |
| 476 | val = readl(base + USB_SUSP_CTRL); |
| 477 | val &= ~USB_SUSP_SET; |
| 478 | writel(val, base + USB_SUSP_CTRL); |
| 479 | } |
| 480 | |
| 481 | utmi_phy_clk_enable(phy); |
| 482 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame^] | 483 | if (phy->soc_config->requires_usbmode_setup) { |
| 484 | val = readl(base + USB_USBMODE); |
| 485 | val &= ~USB_USBMODE_MASK; |
| 486 | if (phy->mode == USB_DR_MODE_HOST) |
| 487 | val |= USB_USBMODE_HOST; |
| 488 | else |
| 489 | val |= USB_USBMODE_DEVICE; |
| 490 | writel(val, base + USB_USBMODE); |
| 491 | } |
| 492 | |
Venu Byravarasu | bbdabdb | 2013-01-17 20:15:37 +0000 | [diff] [blame] | 493 | if (!phy->is_legacy_phy) |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 494 | set_pts(phy, 0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 495 | |
| 496 | return 0; |
| 497 | } |
| 498 | |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 499 | static int utmi_phy_power_off(struct tegra_usb_phy *phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 500 | { |
| 501 | unsigned long val; |
| 502 | void __iomem *base = phy->regs; |
| 503 | |
| 504 | utmi_phy_clk_disable(phy); |
| 505 | |
Tuomas Tynkkynen | 6558d7e | 2013-07-25 21:38:09 +0300 | [diff] [blame] | 506 | if (phy->mode == USB_DR_MODE_PERIPHERAL) { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 507 | val = readl(base + USB_SUSP_CTRL); |
| 508 | val &= ~USB_WAKEUP_DEBOUNCE_COUNT(~0); |
| 509 | val |= USB_WAKE_ON_CNNT_EN_DEV | USB_WAKEUP_DEBOUNCE_COUNT(5); |
| 510 | writel(val, base + USB_SUSP_CTRL); |
| 511 | } |
| 512 | |
| 513 | val = readl(base + USB_SUSP_CTRL); |
| 514 | val |= UTMIP_RESET; |
| 515 | writel(val, base + USB_SUSP_CTRL); |
| 516 | |
| 517 | val = readl(base + UTMIP_BAT_CHRG_CFG0); |
| 518 | val |= UTMIP_PD_CHRG; |
| 519 | writel(val, base + UTMIP_BAT_CHRG_CFG0); |
| 520 | |
| 521 | val = readl(base + UTMIP_XCVR_CFG0); |
| 522 | val |= UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN | |
| 523 | UTMIP_FORCE_PDZI_POWERDOWN; |
| 524 | writel(val, base + UTMIP_XCVR_CFG0); |
| 525 | |
| 526 | val = readl(base + UTMIP_XCVR_CFG1); |
| 527 | val |= UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN | |
| 528 | UTMIP_FORCE_PDDR_POWERDOWN; |
| 529 | writel(val, base + UTMIP_XCVR_CFG1); |
| 530 | |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 531 | return utmip_pad_power_off(phy); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | static void utmi_phy_preresume(struct tegra_usb_phy *phy) |
| 535 | { |
| 536 | unsigned long val; |
| 537 | void __iomem *base = phy->regs; |
| 538 | |
| 539 | val = readl(base + UTMIP_TX_CFG0); |
| 540 | val |= UTMIP_HS_DISCON_DISABLE; |
| 541 | writel(val, base + UTMIP_TX_CFG0); |
| 542 | } |
| 543 | |
| 544 | static void utmi_phy_postresume(struct tegra_usb_phy *phy) |
| 545 | { |
| 546 | unsigned long val; |
| 547 | void __iomem *base = phy->regs; |
| 548 | |
| 549 | val = readl(base + UTMIP_TX_CFG0); |
| 550 | val &= ~UTMIP_HS_DISCON_DISABLE; |
| 551 | writel(val, base + UTMIP_TX_CFG0); |
| 552 | } |
| 553 | |
| 554 | static void utmi_phy_restore_start(struct tegra_usb_phy *phy, |
| 555 | enum tegra_usb_phy_port_speed port_speed) |
| 556 | { |
| 557 | unsigned long val; |
| 558 | void __iomem *base = phy->regs; |
| 559 | |
| 560 | val = readl(base + UTMIP_MISC_CFG0); |
| 561 | val &= ~UTMIP_DPDM_OBSERVE_SEL(~0); |
| 562 | if (port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW) |
| 563 | val |= UTMIP_DPDM_OBSERVE_SEL_FS_K; |
| 564 | else |
| 565 | val |= UTMIP_DPDM_OBSERVE_SEL_FS_J; |
| 566 | writel(val, base + UTMIP_MISC_CFG0); |
| 567 | udelay(1); |
| 568 | |
| 569 | val = readl(base + UTMIP_MISC_CFG0); |
| 570 | val |= UTMIP_DPDM_OBSERVE; |
| 571 | writel(val, base + UTMIP_MISC_CFG0); |
| 572 | udelay(10); |
| 573 | } |
| 574 | |
| 575 | static void utmi_phy_restore_end(struct tegra_usb_phy *phy) |
| 576 | { |
| 577 | unsigned long val; |
| 578 | void __iomem *base = phy->regs; |
| 579 | |
| 580 | val = readl(base + UTMIP_MISC_CFG0); |
| 581 | val &= ~UTMIP_DPDM_OBSERVE; |
| 582 | writel(val, base + UTMIP_MISC_CFG0); |
| 583 | udelay(10); |
| 584 | } |
| 585 | |
| 586 | static int ulpi_phy_power_on(struct tegra_usb_phy *phy) |
| 587 | { |
| 588 | int ret; |
| 589 | unsigned long val; |
| 590 | void __iomem *base = phy->regs; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 591 | |
Venu Byravarasu | 6829f92 | 2013-05-16 19:43:01 +0530 | [diff] [blame] | 592 | ret = gpio_direction_output(phy->reset_gpio, 0); |
| 593 | if (ret < 0) { |
Tuomas Tynkkynen | 185d0fd | 2013-07-25 21:38:01 +0300 | [diff] [blame] | 594 | dev_err(phy->u_phy.dev, "gpio %d not set to 0\n", |
| 595 | phy->reset_gpio); |
Venu Byravarasu | 6829f92 | 2013-05-16 19:43:01 +0530 | [diff] [blame] | 596 | return ret; |
| 597 | } |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 598 | msleep(5); |
Venu Byravarasu | 6829f92 | 2013-05-16 19:43:01 +0530 | [diff] [blame] | 599 | ret = gpio_direction_output(phy->reset_gpio, 1); |
| 600 | if (ret < 0) { |
Tuomas Tynkkynen | 185d0fd | 2013-07-25 21:38:01 +0300 | [diff] [blame] | 601 | dev_err(phy->u_phy.dev, "gpio %d not set to 1\n", |
| 602 | phy->reset_gpio); |
Venu Byravarasu | 6829f92 | 2013-05-16 19:43:01 +0530 | [diff] [blame] | 603 | return ret; |
| 604 | } |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 605 | |
Prashant Gaikwad | 6a5278d | 2012-06-05 09:59:35 +0530 | [diff] [blame] | 606 | clk_prepare_enable(phy->clk); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 607 | msleep(1); |
| 608 | |
| 609 | val = readl(base + USB_SUSP_CTRL); |
| 610 | val |= UHSIC_RESET; |
| 611 | writel(val, base + USB_SUSP_CTRL); |
| 612 | |
| 613 | val = readl(base + ULPI_TIMING_CTRL_0); |
| 614 | val |= ULPI_OUTPUT_PINMUX_BYP | ULPI_CLKOUT_PINMUX_BYP; |
| 615 | writel(val, base + ULPI_TIMING_CTRL_0); |
| 616 | |
| 617 | val = readl(base + USB_SUSP_CTRL); |
| 618 | val |= ULPI_PHY_ENABLE; |
| 619 | writel(val, base + USB_SUSP_CTRL); |
| 620 | |
| 621 | val = 0; |
| 622 | writel(val, base + ULPI_TIMING_CTRL_1); |
| 623 | |
| 624 | val |= ULPI_DATA_TRIMMER_SEL(4); |
| 625 | val |= ULPI_STPDIRNXT_TRIMMER_SEL(4); |
| 626 | val |= ULPI_DIR_TRIMMER_SEL(4); |
| 627 | writel(val, base + ULPI_TIMING_CTRL_1); |
| 628 | udelay(10); |
| 629 | |
| 630 | val |= ULPI_DATA_TRIMMER_LOAD; |
| 631 | val |= ULPI_STPDIRNXT_TRIMMER_LOAD; |
| 632 | val |= ULPI_DIR_TRIMMER_LOAD; |
| 633 | writel(val, base + ULPI_TIMING_CTRL_1); |
| 634 | |
| 635 | /* Fix VbusInvalid due to floating VBUS */ |
Heikki Krogerus | b96d3b0 | 2012-02-13 13:24:18 +0200 | [diff] [blame] | 636 | ret = usb_phy_io_write(phy->ulpi, 0x40, 0x08); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 637 | if (ret) { |
| 638 | pr_err("%s: ulpi write failed\n", __func__); |
| 639 | return ret; |
| 640 | } |
| 641 | |
Heikki Krogerus | b96d3b0 | 2012-02-13 13:24:18 +0200 | [diff] [blame] | 642 | ret = usb_phy_io_write(phy->ulpi, 0x80, 0x0B); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 643 | if (ret) { |
| 644 | pr_err("%s: ulpi write failed\n", __func__); |
| 645 | return ret; |
| 646 | } |
| 647 | |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 648 | val = readl(base + USB_SUSP_CTRL); |
| 649 | val |= USB_SUSP_CLR; |
| 650 | writel(val, base + USB_SUSP_CTRL); |
| 651 | udelay(100); |
| 652 | |
| 653 | val = readl(base + USB_SUSP_CTRL); |
| 654 | val &= ~USB_SUSP_CLR; |
| 655 | writel(val, base + USB_SUSP_CTRL); |
| 656 | |
| 657 | return 0; |
| 658 | } |
| 659 | |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 660 | static int ulpi_phy_power_off(struct tegra_usb_phy *phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 661 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 662 | clk_disable(phy->clk); |
Venu Byravarasu | 12ea18e | 2013-05-16 19:43:00 +0530 | [diff] [blame] | 663 | return gpio_direction_output(phy->reset_gpio, 0); |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 664 | } |
| 665 | |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 666 | static void tegra_usb_phy_close(struct usb_phy *x) |
| 667 | { |
| 668 | struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy); |
| 669 | |
Mikko Perttunen | f5b8c8b | 2013-07-17 10:37:49 +0300 | [diff] [blame] | 670 | if (!IS_ERR(phy->vbus)) |
| 671 | regulator_disable(phy->vbus); |
| 672 | |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 673 | clk_disable_unprepare(phy->pll_u); |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | static int tegra_usb_phy_power_on(struct tegra_usb_phy *phy) |
| 677 | { |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 678 | if (phy->is_ulpi_phy) |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 679 | return ulpi_phy_power_on(phy); |
| 680 | else |
| 681 | return utmi_phy_power_on(phy); |
| 682 | } |
| 683 | |
| 684 | static int tegra_usb_phy_power_off(struct tegra_usb_phy *phy) |
| 685 | { |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 686 | if (phy->is_ulpi_phy) |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 687 | return ulpi_phy_power_off(phy); |
| 688 | else |
| 689 | return utmi_phy_power_off(phy); |
| 690 | } |
| 691 | |
| 692 | static int tegra_usb_phy_suspend(struct usb_phy *x, int suspend) |
| 693 | { |
| 694 | struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy); |
| 695 | if (suspend) |
| 696 | return tegra_usb_phy_power_off(phy); |
| 697 | else |
| 698 | return tegra_usb_phy_power_on(phy); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 699 | } |
| 700 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 701 | static int ulpi_open(struct tegra_usb_phy *phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 702 | { |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 703 | int err; |
| 704 | |
Tuomas Tynkkynen | 185d0fd | 2013-07-25 21:38:01 +0300 | [diff] [blame] | 705 | phy->clk = devm_clk_get(phy->u_phy.dev, "ulpi-link"); |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 706 | if (IS_ERR(phy->clk)) { |
| 707 | pr_err("%s: can't get ulpi clock\n", __func__); |
| 708 | return PTR_ERR(phy->clk); |
| 709 | } |
| 710 | |
Tuomas Tynkkynen | 185d0fd | 2013-07-25 21:38:01 +0300 | [diff] [blame] | 711 | err = devm_gpio_request(phy->u_phy.dev, phy->reset_gpio, |
| 712 | "ulpi_phy_reset_b"); |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 713 | if (err < 0) { |
Tuomas Tynkkynen | 185d0fd | 2013-07-25 21:38:01 +0300 | [diff] [blame] | 714 | dev_err(phy->u_phy.dev, "request failed for gpio: %d\n", |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 715 | phy->reset_gpio); |
| 716 | return err; |
| 717 | } |
| 718 | |
| 719 | err = gpio_direction_output(phy->reset_gpio, 0); |
| 720 | if (err < 0) { |
Tuomas Tynkkynen | 185d0fd | 2013-07-25 21:38:01 +0300 | [diff] [blame] | 721 | dev_err(phy->u_phy.dev, "gpio %d direction not set to output\n", |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 722 | phy->reset_gpio); |
| 723 | return err; |
| 724 | } |
| 725 | |
| 726 | phy->ulpi = otg_ulpi_create(&ulpi_viewport_access_ops, 0); |
| 727 | if (!phy->ulpi) { |
Tuomas Tynkkynen | 185d0fd | 2013-07-25 21:38:01 +0300 | [diff] [blame] | 728 | dev_err(phy->u_phy.dev, "otg_ulpi_create returned NULL\n"); |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 729 | err = -ENOMEM; |
| 730 | return err; |
| 731 | } |
| 732 | |
| 733 | phy->ulpi->io_priv = phy->regs + ULPI_VIEWPORT; |
| 734 | return 0; |
| 735 | } |
| 736 | |
| 737 | static int tegra_usb_phy_init(struct tegra_usb_phy *phy) |
| 738 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 739 | unsigned long parent_rate; |
| 740 | int i; |
| 741 | int err; |
| 742 | |
Tuomas Tynkkynen | 185d0fd | 2013-07-25 21:38:01 +0300 | [diff] [blame] | 743 | phy->pll_u = devm_clk_get(phy->u_phy.dev, "pll_u"); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 744 | if (IS_ERR(phy->pll_u)) { |
| 745 | pr_err("Can't get pll_u clock\n"); |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 746 | return PTR_ERR(phy->pll_u); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 747 | } |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 748 | |
| 749 | err = clk_prepare_enable(phy->pll_u); |
| 750 | if (err) |
| 751 | return err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 752 | |
| 753 | parent_rate = clk_get_rate(clk_get_parent(phy->pll_u)); |
| 754 | for (i = 0; i < ARRAY_SIZE(tegra_freq_table); i++) { |
| 755 | if (tegra_freq_table[i].freq == parent_rate) { |
| 756 | phy->freq = &tegra_freq_table[i]; |
| 757 | break; |
| 758 | } |
| 759 | } |
| 760 | if (!phy->freq) { |
| 761 | pr_err("invalid pll_u parent rate %ld\n", parent_rate); |
| 762 | err = -EINVAL; |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 763 | goto fail; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 764 | } |
| 765 | |
Mikko Perttunen | f5b8c8b | 2013-07-17 10:37:49 +0300 | [diff] [blame] | 766 | if (!IS_ERR(phy->vbus)) { |
| 767 | err = regulator_enable(phy->vbus); |
| 768 | if (err) { |
Tuomas Tynkkynen | 185d0fd | 2013-07-25 21:38:01 +0300 | [diff] [blame] | 769 | dev_err(phy->u_phy.dev, |
Mikko Perttunen | f5b8c8b | 2013-07-17 10:37:49 +0300 | [diff] [blame] | 770 | "failed to enable usb vbus regulator: %d\n", |
| 771 | err); |
| 772 | goto fail; |
| 773 | } |
| 774 | } |
| 775 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 776 | if (phy->is_ulpi_phy) |
| 777 | err = ulpi_open(phy); |
| 778 | else |
| 779 | err = utmip_pad_open(phy); |
| 780 | if (err < 0) |
| 781 | goto fail; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 782 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 783 | return 0; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 784 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 785 | fail: |
Prashant Gaikwad | 6a5278d | 2012-06-05 09:59:35 +0530 | [diff] [blame] | 786 | clk_disable_unprepare(phy->pll_u); |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 787 | return err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 788 | } |
| 789 | |
Venu Byravarasu | ab137d0 | 2013-01-24 15:57:03 +0530 | [diff] [blame] | 790 | void tegra_usb_phy_preresume(struct usb_phy *x) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 791 | { |
Venu Byravarasu | ab137d0 | 2013-01-24 15:57:03 +0530 | [diff] [blame] | 792 | struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy); |
| 793 | |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 794 | if (!phy->is_ulpi_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 795 | utmi_phy_preresume(phy); |
| 796 | } |
Arnd Bergmann | 4265cbf | 2012-03-02 15:58:42 -0500 | [diff] [blame] | 797 | EXPORT_SYMBOL_GPL(tegra_usb_phy_preresume); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 798 | |
Venu Byravarasu | ab137d0 | 2013-01-24 15:57:03 +0530 | [diff] [blame] | 799 | void tegra_usb_phy_postresume(struct usb_phy *x) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 800 | { |
Venu Byravarasu | ab137d0 | 2013-01-24 15:57:03 +0530 | [diff] [blame] | 801 | struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy); |
| 802 | |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 803 | if (!phy->is_ulpi_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 804 | utmi_phy_postresume(phy); |
| 805 | } |
Arnd Bergmann | 4265cbf | 2012-03-02 15:58:42 -0500 | [diff] [blame] | 806 | EXPORT_SYMBOL_GPL(tegra_usb_phy_postresume); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 807 | |
Venu Byravarasu | ab137d0 | 2013-01-24 15:57:03 +0530 | [diff] [blame] | 808 | void tegra_ehci_phy_restore_start(struct usb_phy *x, |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 809 | enum tegra_usb_phy_port_speed port_speed) |
| 810 | { |
Venu Byravarasu | ab137d0 | 2013-01-24 15:57:03 +0530 | [diff] [blame] | 811 | struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy); |
| 812 | |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 813 | if (!phy->is_ulpi_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 814 | utmi_phy_restore_start(phy, port_speed); |
| 815 | } |
Arnd Bergmann | 4265cbf | 2012-03-02 15:58:42 -0500 | [diff] [blame] | 816 | EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_start); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 817 | |
Venu Byravarasu | ab137d0 | 2013-01-24 15:57:03 +0530 | [diff] [blame] | 818 | void tegra_ehci_phy_restore_end(struct usb_phy *x) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 819 | { |
Venu Byravarasu | ab137d0 | 2013-01-24 15:57:03 +0530 | [diff] [blame] | 820 | struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy); |
| 821 | |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 822 | if (!phy->is_ulpi_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 823 | utmi_phy_restore_end(phy); |
| 824 | } |
Arnd Bergmann | 4265cbf | 2012-03-02 15:58:42 -0500 | [diff] [blame] | 825 | EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_end); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 826 | |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 827 | static int read_utmi_param(struct platform_device *pdev, const char *param, |
| 828 | u8 *dest) |
| 829 | { |
| 830 | u32 value; |
| 831 | int err = of_property_read_u32(pdev->dev.of_node, param, &value); |
| 832 | *dest = (u8)value; |
| 833 | if (err < 0) |
| 834 | dev_err(&pdev->dev, "Failed to read USB UTMI parameter %s: %d\n", |
| 835 | param, err); |
| 836 | return err; |
| 837 | } |
| 838 | |
| 839 | static int utmi_phy_probe(struct tegra_usb_phy *tegra_phy, |
| 840 | struct platform_device *pdev) |
| 841 | { |
| 842 | struct resource *res; |
| 843 | int err; |
| 844 | struct tegra_utmip_config *config; |
| 845 | |
| 846 | tegra_phy->is_ulpi_phy = false; |
| 847 | |
| 848 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 849 | if (!res) { |
| 850 | dev_err(&pdev->dev, "Failed to get UTMI Pad regs\n"); |
| 851 | return -ENXIO; |
| 852 | } |
| 853 | |
| 854 | tegra_phy->pad_regs = devm_ioremap(&pdev->dev, res->start, |
| 855 | resource_size(res)); |
| 856 | if (!tegra_phy->regs) { |
| 857 | dev_err(&pdev->dev, "Failed to remap UTMI Pad regs\n"); |
| 858 | return -ENOMEM; |
| 859 | } |
| 860 | |
| 861 | tegra_phy->config = devm_kzalloc(&pdev->dev, |
| 862 | sizeof(*tegra_phy->config), GFP_KERNEL); |
| 863 | if (!tegra_phy->config) { |
| 864 | dev_err(&pdev->dev, |
| 865 | "unable to allocate memory for USB UTMIP config\n"); |
| 866 | return -ENOMEM; |
| 867 | } |
| 868 | |
| 869 | config = tegra_phy->config; |
| 870 | |
| 871 | err = read_utmi_param(pdev, "nvidia,hssync-start-delay", |
| 872 | &config->hssync_start_delay); |
| 873 | if (err < 0) |
| 874 | return err; |
| 875 | |
| 876 | err = read_utmi_param(pdev, "nvidia,elastic-limit", |
| 877 | &config->elastic_limit); |
| 878 | if (err < 0) |
| 879 | return err; |
| 880 | |
| 881 | err = read_utmi_param(pdev, "nvidia,idle-wait-delay", |
| 882 | &config->idle_wait_delay); |
| 883 | if (err < 0) |
| 884 | return err; |
| 885 | |
| 886 | err = read_utmi_param(pdev, "nvidia,term-range-adj", |
| 887 | &config->term_range_adj); |
| 888 | if (err < 0) |
| 889 | return err; |
| 890 | |
| 891 | err = read_utmi_param(pdev, "nvidia,xcvr-setup", |
| 892 | &config->xcvr_setup); |
| 893 | if (err < 0) |
| 894 | return err; |
| 895 | |
| 896 | err = read_utmi_param(pdev, "nvidia,xcvr-lsfslew", |
| 897 | &config->xcvr_lsfslew); |
| 898 | if (err < 0) |
| 899 | return err; |
| 900 | |
| 901 | err = read_utmi_param(pdev, "nvidia,xcvr-lsrslew", |
| 902 | &config->xcvr_lsrslew); |
| 903 | if (err < 0) |
| 904 | return err; |
| 905 | |
| 906 | return 0; |
| 907 | } |
| 908 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame^] | 909 | static const struct tegra_phy_soc_config tegra20_soc_config = { |
| 910 | .utmi_pll_config_in_car_module = false, |
| 911 | .has_hostpc = false, |
| 912 | .requires_usbmode_setup = false, |
| 913 | .requires_extra_tuning_parameters = false, |
| 914 | }; |
| 915 | |
| 916 | static const struct tegra_phy_soc_config tegra30_soc_config = { |
| 917 | .utmi_pll_config_in_car_module = true, |
| 918 | .has_hostpc = true, |
| 919 | .requires_usbmode_setup = true, |
| 920 | .requires_extra_tuning_parameters = true, |
| 921 | }; |
| 922 | |
| 923 | static struct of_device_id tegra_usb_phy_id_table[] = { |
| 924 | { .compatible = "nvidia,tegra30-usb-phy", .data = &tegra30_soc_config }, |
| 925 | { .compatible = "nvidia,tegra20-usb-phy", .data = &tegra20_soc_config }, |
| 926 | { }, |
| 927 | }; |
| 928 | MODULE_DEVICE_TABLE(of, tegra_usb_phy_id_table); |
| 929 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 930 | static int tegra_usb_phy_probe(struct platform_device *pdev) |
| 931 | { |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame^] | 932 | const struct of_device_id *match; |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 933 | struct resource *res; |
| 934 | struct tegra_usb_phy *tegra_phy = NULL; |
| 935 | struct device_node *np = pdev->dev.of_node; |
Tuomas Tynkkynen | 9fdb07f | 2013-07-25 21:38:08 +0300 | [diff] [blame] | 936 | enum usb_phy_interface phy_type; |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 937 | int err; |
| 938 | |
| 939 | tegra_phy = devm_kzalloc(&pdev->dev, sizeof(*tegra_phy), GFP_KERNEL); |
| 940 | if (!tegra_phy) { |
| 941 | dev_err(&pdev->dev, "unable to allocate memory for USB2 PHY\n"); |
| 942 | return -ENOMEM; |
| 943 | } |
| 944 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame^] | 945 | match = of_match_device(tegra_usb_phy_id_table, &pdev->dev); |
| 946 | if (!match) { |
| 947 | dev_err(&pdev->dev, "Error: No device match found\n"); |
| 948 | return -ENODEV; |
| 949 | } |
| 950 | tegra_phy->soc_config = match->data; |
| 951 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 952 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 953 | if (!res) { |
| 954 | dev_err(&pdev->dev, "Failed to get I/O memory\n"); |
| 955 | return -ENXIO; |
| 956 | } |
| 957 | |
| 958 | tegra_phy->regs = devm_ioremap(&pdev->dev, res->start, |
| 959 | resource_size(res)); |
| 960 | if (!tegra_phy->regs) { |
| 961 | dev_err(&pdev->dev, "Failed to remap I/O memory\n"); |
| 962 | return -ENOMEM; |
| 963 | } |
| 964 | |
| 965 | tegra_phy->is_legacy_phy = |
| 966 | of_property_read_bool(np, "nvidia,has-legacy-mode"); |
| 967 | |
Tuomas Tynkkynen | 9fdb07f | 2013-07-25 21:38:08 +0300 | [diff] [blame] | 968 | phy_type = of_usb_get_phy_mode(np); |
Tuomas Tynkkynen | a554aea | 2013-07-25 22:24:09 +0300 | [diff] [blame] | 969 | switch (phy_type) { |
| 970 | case USBPHY_INTERFACE_MODE_UTMI: |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 971 | err = utmi_phy_probe(tegra_phy, pdev); |
| 972 | if (err < 0) |
| 973 | return err; |
Tuomas Tynkkynen | a554aea | 2013-07-25 22:24:09 +0300 | [diff] [blame] | 974 | break; |
| 975 | |
| 976 | case USBPHY_INTERFACE_MODE_ULPI: |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 977 | tegra_phy->is_ulpi_phy = true; |
| 978 | |
| 979 | tegra_phy->reset_gpio = |
| 980 | of_get_named_gpio(np, "nvidia,phy-reset-gpio", 0); |
| 981 | if (!gpio_is_valid(tegra_phy->reset_gpio)) { |
| 982 | dev_err(&pdev->dev, "invalid gpio: %d\n", |
| 983 | tegra_phy->reset_gpio); |
| 984 | return tegra_phy->reset_gpio; |
| 985 | } |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 986 | tegra_phy->config = NULL; |
Tuomas Tynkkynen | a554aea | 2013-07-25 22:24:09 +0300 | [diff] [blame] | 987 | break; |
| 988 | |
| 989 | default: |
Tuomas Tynkkynen | 9fdb07f | 2013-07-25 21:38:08 +0300 | [diff] [blame] | 990 | dev_err(&pdev->dev, "phy_type is invalid or unsupported\n"); |
| 991 | return -EINVAL; |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 992 | } |
| 993 | |
Tuomas Tynkkynen | 6558d7e | 2013-07-25 21:38:09 +0300 | [diff] [blame] | 994 | if (of_find_property(np, "dr_mode", NULL)) |
| 995 | tegra_phy->mode = of_usb_get_dr_mode(np); |
| 996 | else |
| 997 | tegra_phy->mode = USB_DR_MODE_HOST; |
| 998 | |
| 999 | if (tegra_phy->mode == USB_DR_MODE_UNKNOWN) { |
| 1000 | dev_err(&pdev->dev, "dr_mode is invalid\n"); |
| 1001 | return -EINVAL; |
| 1002 | } |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1003 | |
Mikko Perttunen | f5b8c8b | 2013-07-17 10:37:49 +0300 | [diff] [blame] | 1004 | /* On some boards, the VBUS regulator doesn't need to be controlled */ |
| 1005 | if (of_find_property(np, "vbus-supply", NULL)) { |
| 1006 | tegra_phy->vbus = devm_regulator_get(&pdev->dev, "vbus"); |
| 1007 | if (IS_ERR(tegra_phy->vbus)) |
| 1008 | return PTR_ERR(tegra_phy->vbus); |
| 1009 | } else { |
| 1010 | dev_notice(&pdev->dev, "no vbus regulator"); |
| 1011 | tegra_phy->vbus = ERR_PTR(-ENODEV); |
| 1012 | } |
| 1013 | |
Tuomas Tynkkynen | 185d0fd | 2013-07-25 21:38:01 +0300 | [diff] [blame] | 1014 | tegra_phy->u_phy.dev = &pdev->dev; |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1015 | err = tegra_usb_phy_init(tegra_phy); |
| 1016 | if (err < 0) |
| 1017 | return err; |
| 1018 | |
| 1019 | tegra_phy->u_phy.shutdown = tegra_usb_phy_close; |
| 1020 | tegra_phy->u_phy.set_suspend = tegra_usb_phy_suspend; |
| 1021 | |
| 1022 | dev_set_drvdata(&pdev->dev, tegra_phy); |
Tuomas Tynkkynen | 0ee5b4a | 2013-07-25 21:38:05 +0300 | [diff] [blame] | 1023 | |
| 1024 | err = usb_add_phy_dev(&tegra_phy->u_phy); |
| 1025 | if (err < 0) { |
| 1026 | tegra_usb_phy_close(&tegra_phy->u_phy); |
| 1027 | return err; |
| 1028 | } |
| 1029 | |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
| 1033 | static int tegra_usb_phy_remove(struct platform_device *pdev) |
| 1034 | { |
| 1035 | struct tegra_usb_phy *tegra_phy = platform_get_drvdata(pdev); |
| 1036 | |
| 1037 | usb_remove_phy(&tegra_phy->u_phy); |
| 1038 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1039 | return 0; |
| 1040 | } |
| 1041 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1042 | static struct platform_driver tegra_usb_phy_driver = { |
| 1043 | .probe = tegra_usb_phy_probe, |
Tuomas Tynkkynen | 0ee5b4a | 2013-07-25 21:38:05 +0300 | [diff] [blame] | 1044 | .remove = tegra_usb_phy_remove, |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1045 | .driver = { |
| 1046 | .name = "tegra-phy", |
| 1047 | .owner = THIS_MODULE, |
| 1048 | .of_match_table = of_match_ptr(tegra_usb_phy_id_table), |
| 1049 | }, |
| 1050 | }; |
| 1051 | module_platform_driver(tegra_usb_phy_driver); |
| 1052 | |
Stephen Warren | 587376a | 2013-06-13 11:24:08 -0600 | [diff] [blame] | 1053 | MODULE_DESCRIPTION("Tegra USB PHY driver"); |
| 1054 | MODULE_LICENSE("GPL v2"); |