Greg Kroah-Hartman | 5fd54ac | 2017-11-03 11:28:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 2 | /* |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 3 | * Copyright (C) 2010 Google, Inc. |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 4 | * Copyright (C) 2013 NVIDIA Corporation |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 5 | * |
| 6 | * Author: |
| 7 | * Erik Gilling <konkers@google.com> |
| 8 | * Benoit Goby <benoit@android.com> |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 9 | * Venu Byravarasu <vbyravarasu@nvidia.com> |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 10 | */ |
| 11 | |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 12 | #include <linux/delay.h> |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 13 | #include <linux/err.h> |
Arnd Bergmann | 4265cbf | 2012-03-02 15:58:42 -0500 | [diff] [blame] | 14 | #include <linux/export.h> |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 15 | #include <linux/gpio.h> |
Dmitry Osipenko | 5bb6985 | 2020-01-06 04:34:03 +0300 | [diff] [blame] | 16 | #include <linux/iopoll.h> |
| 17 | #include <linux/module.h> |
Venu Byravarasu | 3a55c6a | 2013-01-16 03:30:20 +0000 | [diff] [blame] | 18 | #include <linux/of.h> |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 19 | #include <linux/of_device.h> |
Stephen Warren | aa607eb | 2012-04-12 15:46:49 -0600 | [diff] [blame] | 20 | #include <linux/of_gpio.h> |
Dmitry Osipenko | 5bb6985 | 2020-01-06 04:34:03 +0300 | [diff] [blame] | 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/resource.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/spinlock.h> |
| 25 | |
Mikko Perttunen | f5b8c8b | 2013-07-17 10:37:49 +0300 | [diff] [blame] | 26 | #include <linux/regulator/consumer.h> |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 27 | |
Dmitry Osipenko | 5bb6985 | 2020-01-06 04:34:03 +0300 | [diff] [blame] | 28 | #include <linux/usb/ehci_def.h> |
| 29 | #include <linux/usb/of.h> |
| 30 | #include <linux/usb/tegra_usb_phy.h> |
| 31 | #include <linux/usb/ulpi.h> |
| 32 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 33 | #define ULPI_VIEWPORT 0x170 |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 34 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 35 | /* PORTSC PTS/PHCD bits, Tegra20 only */ |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 36 | #define TEGRA_USB_PORTSC1 0x184 |
| 37 | #define TEGRA_USB_PORTSC1_PTS(x) (((x) & 0x3) << 30) |
| 38 | #define TEGRA_USB_PORTSC1_PHCD BIT(23) |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 39 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 40 | /* HOSTPC1 PTS/PHCD bits, Tegra30 and above */ |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 41 | #define TEGRA_USB_HOSTPC1_DEVLC 0x1b4 |
| 42 | #define TEGRA_USB_HOSTPC1_DEVLC_PTS(x) (((x) & 0x7) << 29) |
| 43 | #define TEGRA_USB_HOSTPC1_DEVLC_PHCD BIT(22) |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 44 | |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 45 | /* Bits of PORTSC1, which will get cleared by writing 1 into them */ |
| 46 | #define TEGRA_PORTSC1_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC) |
| 47 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 48 | #define USB_SUSP_CTRL 0x400 |
| 49 | #define USB_WAKE_ON_CNNT_EN_DEV BIT(3) |
| 50 | #define USB_WAKE_ON_DISCON_EN_DEV BIT(4) |
| 51 | #define USB_SUSP_CLR BIT(5) |
| 52 | #define USB_PHY_CLK_VALID BIT(7) |
| 53 | #define UTMIP_RESET BIT(11) |
| 54 | #define UHSIC_RESET BIT(11) |
| 55 | #define UTMIP_PHY_ENABLE BIT(12) |
| 56 | #define ULPI_PHY_ENABLE BIT(13) |
| 57 | #define USB_SUSP_SET BIT(14) |
| 58 | #define USB_WAKEUP_DEBOUNCE_COUNT(x) (((x) & 0x7) << 16) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 59 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 60 | #define USB1_LEGACY_CTRL 0x410 |
| 61 | #define USB1_NO_LEGACY_MODE BIT(0) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 62 | #define USB1_VBUS_SENSE_CTL_MASK (3 << 1) |
| 63 | #define USB1_VBUS_SENSE_CTL_VBUS_WAKEUP (0 << 1) |
| 64 | #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD_OR_VBUS_WAKEUP \ |
| 65 | (1 << 1) |
| 66 | #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD (2 << 1) |
| 67 | #define USB1_VBUS_SENSE_CTL_A_SESS_VLD (3 << 1) |
| 68 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 69 | #define ULPI_TIMING_CTRL_0 0x424 |
| 70 | #define ULPI_OUTPUT_PINMUX_BYP BIT(10) |
| 71 | #define ULPI_CLKOUT_PINMUX_BYP BIT(11) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 72 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 73 | #define ULPI_TIMING_CTRL_1 0x428 |
| 74 | #define ULPI_DATA_TRIMMER_LOAD BIT(0) |
| 75 | #define ULPI_DATA_TRIMMER_SEL(x) (((x) & 0x7) << 1) |
| 76 | #define ULPI_STPDIRNXT_TRIMMER_LOAD BIT(16) |
| 77 | #define ULPI_STPDIRNXT_TRIMMER_SEL(x) (((x) & 0x7) << 17) |
| 78 | #define ULPI_DIR_TRIMMER_LOAD BIT(24) |
| 79 | #define ULPI_DIR_TRIMMER_SEL(x) (((x) & 0x7) << 25) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 80 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 81 | #define UTMIP_PLL_CFG1 0x804 |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 82 | #define UTMIP_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0) |
| 83 | #define UTMIP_PLLU_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27) |
| 84 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 85 | #define UTMIP_XCVR_CFG0 0x808 |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 86 | #define UTMIP_XCVR_SETUP(x) (((x) & 0xf) << 0) |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 87 | #define UTMIP_XCVR_SETUP_MSB(x) ((((x) & 0x70) >> 4) << 22) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 88 | #define UTMIP_XCVR_LSRSLEW(x) (((x) & 0x3) << 8) |
| 89 | #define UTMIP_XCVR_LSFSLEW(x) (((x) & 0x3) << 10) |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 90 | #define UTMIP_FORCE_PD_POWERDOWN BIT(14) |
| 91 | #define UTMIP_FORCE_PD2_POWERDOWN BIT(16) |
| 92 | #define UTMIP_FORCE_PDZI_POWERDOWN BIT(18) |
| 93 | #define UTMIP_XCVR_LSBIAS_SEL BIT(21) |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 94 | #define UTMIP_XCVR_HSSLEW(x) (((x) & 0x3) << 4) |
| 95 | #define UTMIP_XCVR_HSSLEW_MSB(x) ((((x) & 0x1fc) >> 2) << 25) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 96 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 97 | #define UTMIP_BIAS_CFG0 0x80c |
| 98 | #define UTMIP_OTGPD BIT(11) |
| 99 | #define UTMIP_BIASPD BIT(10) |
| 100 | #define UTMIP_HSSQUELCH_LEVEL(x) (((x) & 0x3) << 0) |
| 101 | #define UTMIP_HSDISCON_LEVEL(x) (((x) & 0x3) << 2) |
| 102 | #define UTMIP_HSDISCON_LEVEL_MSB(x) ((((x) & 0x4) >> 2) << 24) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 103 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 104 | #define UTMIP_HSRX_CFG0 0x810 |
| 105 | #define UTMIP_ELASTIC_LIMIT(x) (((x) & 0x1f) << 10) |
| 106 | #define UTMIP_IDLE_WAIT(x) (((x) & 0x1f) << 15) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 107 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 108 | #define UTMIP_HSRX_CFG1 0x814 |
| 109 | #define UTMIP_HS_SYNC_START_DLY(x) (((x) & 0x1f) << 1) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 110 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 111 | #define UTMIP_TX_CFG0 0x820 |
| 112 | #define UTMIP_FS_PREABMLE_J BIT(19) |
| 113 | #define UTMIP_HS_DISCON_DISABLE BIT(8) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 114 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 115 | #define UTMIP_MISC_CFG0 0x824 |
| 116 | #define UTMIP_DPDM_OBSERVE BIT(26) |
| 117 | #define UTMIP_DPDM_OBSERVE_SEL(x) (((x) & 0xf) << 27) |
| 118 | #define UTMIP_DPDM_OBSERVE_SEL_FS_J UTMIP_DPDM_OBSERVE_SEL(0xf) |
| 119 | #define UTMIP_DPDM_OBSERVE_SEL_FS_K UTMIP_DPDM_OBSERVE_SEL(0xe) |
| 120 | #define UTMIP_DPDM_OBSERVE_SEL_FS_SE1 UTMIP_DPDM_OBSERVE_SEL(0xd) |
| 121 | #define UTMIP_DPDM_OBSERVE_SEL_FS_SE0 UTMIP_DPDM_OBSERVE_SEL(0xc) |
| 122 | #define UTMIP_SUSPEND_EXIT_ON_EDGE BIT(22) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 123 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 124 | #define UTMIP_MISC_CFG1 0x828 |
| 125 | #define UTMIP_PLL_ACTIVE_DLY_COUNT(x) (((x) & 0x1f) << 18) |
| 126 | #define UTMIP_PLLU_STABLE_COUNT(x) (((x) & 0xfff) << 6) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 127 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 128 | #define UTMIP_DEBOUNCE_CFG0 0x82c |
| 129 | #define UTMIP_BIAS_DEBOUNCE_A(x) (((x) & 0xffff) << 0) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 130 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 131 | #define UTMIP_BAT_CHRG_CFG0 0x830 |
| 132 | #define UTMIP_PD_CHRG BIT(0) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 133 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 134 | #define UTMIP_SPARE_CFG0 0x834 |
| 135 | #define FUSE_SETUP_SEL BIT(3) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 136 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 137 | #define UTMIP_XCVR_CFG1 0x838 |
| 138 | #define UTMIP_FORCE_PDDISC_POWERDOWN BIT(0) |
| 139 | #define UTMIP_FORCE_PDCHRP_POWERDOWN BIT(2) |
| 140 | #define UTMIP_FORCE_PDDR_POWERDOWN BIT(4) |
| 141 | #define UTMIP_XCVR_TERM_RANGE_ADJ(x) (((x) & 0xf) << 18) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 142 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 143 | #define UTMIP_BIAS_CFG1 0x83c |
| 144 | #define UTMIP_BIAS_PDTRK_COUNT(x) (((x) & 0x1f) << 3) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 145 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 146 | /* For Tegra30 and above only, the address is different in Tegra20 */ |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 147 | #define USB_USBMODE 0x1f8 |
| 148 | #define USB_USBMODE_MASK (3 << 0) |
| 149 | #define USB_USBMODE_HOST (3 << 0) |
| 150 | #define USB_USBMODE_DEVICE (2 << 0) |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 151 | |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 152 | static DEFINE_SPINLOCK(utmip_pad_lock); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 153 | static unsigned int utmip_pad_count; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 154 | |
| 155 | struct tegra_xtal_freq { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 156 | unsigned int freq; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 157 | u8 enable_delay; |
| 158 | u8 stable_count; |
| 159 | u8 active_delay; |
| 160 | u8 xtal_freq_count; |
| 161 | u16 debounce; |
| 162 | }; |
| 163 | |
| 164 | static const struct tegra_xtal_freq tegra_freq_table[] = { |
| 165 | { |
| 166 | .freq = 12000000, |
| 167 | .enable_delay = 0x02, |
| 168 | .stable_count = 0x2F, |
| 169 | .active_delay = 0x04, |
| 170 | .xtal_freq_count = 0x76, |
| 171 | .debounce = 0x7530, |
| 172 | }, |
| 173 | { |
| 174 | .freq = 13000000, |
| 175 | .enable_delay = 0x02, |
| 176 | .stable_count = 0x33, |
| 177 | .active_delay = 0x05, |
| 178 | .xtal_freq_count = 0x7F, |
| 179 | .debounce = 0x7EF4, |
| 180 | }, |
| 181 | { |
| 182 | .freq = 19200000, |
| 183 | .enable_delay = 0x03, |
| 184 | .stable_count = 0x4B, |
| 185 | .active_delay = 0x06, |
| 186 | .xtal_freq_count = 0xBB, |
| 187 | .debounce = 0xBB80, |
| 188 | }, |
| 189 | { |
| 190 | .freq = 26000000, |
| 191 | .enable_delay = 0x04, |
| 192 | .stable_count = 0x66, |
| 193 | .active_delay = 0x09, |
| 194 | .xtal_freq_count = 0xFE, |
| 195 | .debounce = 0xFDE8, |
| 196 | }, |
| 197 | }; |
| 198 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 199 | static inline struct tegra_usb_phy *to_tegra_usb_phy(struct usb_phy *u_phy) |
| 200 | { |
| 201 | return container_of(u_phy, struct tegra_usb_phy, u_phy); |
| 202 | } |
| 203 | |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 204 | static void set_pts(struct tegra_usb_phy *phy, u8 pts_val) |
| 205 | { |
| 206 | void __iomem *base = phy->regs; |
| 207 | unsigned long val; |
| 208 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 209 | if (phy->soc_config->has_hostpc) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 210 | val = readl_relaxed(base + TEGRA_USB_HOSTPC1_DEVLC); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 211 | val &= ~TEGRA_USB_HOSTPC1_DEVLC_PTS(~0); |
| 212 | val |= TEGRA_USB_HOSTPC1_DEVLC_PTS(pts_val); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 213 | writel_relaxed(val, base + TEGRA_USB_HOSTPC1_DEVLC); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 214 | } else { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 215 | val = readl_relaxed(base + TEGRA_USB_PORTSC1); |
| 216 | val &= ~TEGRA_PORTSC1_RWC_BITS; |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 217 | val &= ~TEGRA_USB_PORTSC1_PTS(~0); |
| 218 | val |= TEGRA_USB_PORTSC1_PTS(pts_val); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 219 | writel_relaxed(val, base + TEGRA_USB_PORTSC1); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 220 | } |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | static void set_phcd(struct tegra_usb_phy *phy, bool enable) |
| 224 | { |
| 225 | void __iomem *base = phy->regs; |
| 226 | unsigned long val; |
| 227 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 228 | if (phy->soc_config->has_hostpc) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 229 | val = readl_relaxed(base + TEGRA_USB_HOSTPC1_DEVLC); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 230 | if (enable) |
| 231 | val |= TEGRA_USB_HOSTPC1_DEVLC_PHCD; |
| 232 | else |
| 233 | val &= ~TEGRA_USB_HOSTPC1_DEVLC_PHCD; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 234 | writel_relaxed(val, base + TEGRA_USB_HOSTPC1_DEVLC); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 235 | } else { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 236 | val = readl_relaxed(base + TEGRA_USB_PORTSC1) & ~PORT_RWC_BITS; |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 237 | if (enable) |
| 238 | val |= TEGRA_USB_PORTSC1_PHCD; |
| 239 | else |
| 240 | val &= ~TEGRA_USB_PORTSC1_PHCD; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 241 | writel_relaxed(val, base + TEGRA_USB_PORTSC1); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 242 | } |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 243 | } |
| 244 | |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 245 | static int utmip_pad_open(struct tegra_usb_phy *phy) |
| 246 | { |
Dmitry Osipenko | 1434703 | 2018-04-10 01:02:58 +0300 | [diff] [blame] | 247 | int ret; |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 248 | |
Dmitry Osipenko | 1434703 | 2018-04-10 01:02:58 +0300 | [diff] [blame] | 249 | ret = clk_prepare_enable(phy->pad_clk); |
| 250 | if (ret) { |
| 251 | dev_err(phy->u_phy.dev, |
| 252 | "Failed to enable UTMI-pads clock: %d\n", ret); |
| 253 | return ret; |
| 254 | } |
| 255 | |
| 256 | spin_lock(&utmip_pad_lock); |
| 257 | |
| 258 | ret = reset_control_deassert(phy->pad_rst); |
| 259 | if (ret) { |
| 260 | dev_err(phy->u_phy.dev, |
| 261 | "Failed to initialize UTMI-pads reset: %d\n", ret); |
| 262 | goto unlock; |
| 263 | } |
| 264 | |
| 265 | ret = reset_control_assert(phy->pad_rst); |
| 266 | if (ret) { |
| 267 | dev_err(phy->u_phy.dev, |
| 268 | "Failed to assert UTMI-pads reset: %d\n", ret); |
| 269 | goto unlock; |
| 270 | } |
| 271 | |
| 272 | udelay(1); |
| 273 | |
| 274 | ret = reset_control_deassert(phy->pad_rst); |
| 275 | if (ret) |
| 276 | dev_err(phy->u_phy.dev, |
| 277 | "Failed to deassert UTMI-pads reset: %d\n", ret); |
| 278 | unlock: |
| 279 | spin_unlock(&utmip_pad_lock); |
| 280 | |
| 281 | clk_disable_unprepare(phy->pad_clk); |
| 282 | |
| 283 | return ret; |
| 284 | } |
| 285 | |
| 286 | static int utmip_pad_close(struct tegra_usb_phy *phy) |
| 287 | { |
| 288 | int ret; |
| 289 | |
| 290 | ret = clk_prepare_enable(phy->pad_clk); |
| 291 | if (ret) { |
| 292 | dev_err(phy->u_phy.dev, |
| 293 | "Failed to enable UTMI-pads clock: %d\n", ret); |
| 294 | return ret; |
| 295 | } |
| 296 | |
| 297 | ret = reset_control_assert(phy->pad_rst); |
| 298 | if (ret) |
| 299 | dev_err(phy->u_phy.dev, |
| 300 | "Failed to assert UTMI-pads reset: %d\n", ret); |
| 301 | |
| 302 | udelay(1); |
| 303 | |
| 304 | clk_disable_unprepare(phy->pad_clk); |
| 305 | |
| 306 | return ret; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 307 | } |
| 308 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 309 | static int utmip_pad_power_on(struct tegra_usb_phy *phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 310 | { |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 311 | struct tegra_utmip_config *config = phy->config; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 312 | void __iomem *base = phy->pad_regs; |
| 313 | unsigned long val, flags; |
| 314 | int err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 315 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 316 | err = clk_prepare_enable(phy->pad_clk); |
| 317 | if (err) |
| 318 | return err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 319 | |
| 320 | spin_lock_irqsave(&utmip_pad_lock, flags); |
| 321 | |
| 322 | if (utmip_pad_count++ == 0) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 323 | val = readl_relaxed(base + UTMIP_BIAS_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 324 | val &= ~(UTMIP_OTGPD | UTMIP_BIASPD); |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 325 | |
| 326 | if (phy->soc_config->requires_extra_tuning_parameters) { |
| 327 | val &= ~(UTMIP_HSSQUELCH_LEVEL(~0) | |
| 328 | UTMIP_HSDISCON_LEVEL(~0) | |
| 329 | UTMIP_HSDISCON_LEVEL_MSB(~0)); |
| 330 | |
| 331 | val |= UTMIP_HSSQUELCH_LEVEL(config->hssquelch_level); |
| 332 | val |= UTMIP_HSDISCON_LEVEL(config->hsdiscon_level); |
| 333 | val |= UTMIP_HSDISCON_LEVEL_MSB(config->hsdiscon_level); |
| 334 | } |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 335 | writel_relaxed(val, base + UTMIP_BIAS_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | spin_unlock_irqrestore(&utmip_pad_lock, flags); |
| 339 | |
Prashant Gaikwad | 6a5278d | 2012-06-05 09:59:35 +0530 | [diff] [blame] | 340 | clk_disable_unprepare(phy->pad_clk); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 341 | |
| 342 | return 0; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | static int utmip_pad_power_off(struct tegra_usb_phy *phy) |
| 346 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 347 | void __iomem *base = phy->pad_regs; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 348 | unsigned long val, flags; |
| 349 | int err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 350 | |
| 351 | if (!utmip_pad_count) { |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 352 | dev_err(phy->u_phy.dev, "UTMIP pad already powered off\n"); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 353 | return -EINVAL; |
| 354 | } |
| 355 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 356 | err = clk_prepare_enable(phy->pad_clk); |
| 357 | if (err) |
| 358 | return err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 359 | |
| 360 | spin_lock_irqsave(&utmip_pad_lock, flags); |
| 361 | |
| 362 | if (--utmip_pad_count == 0) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 363 | val = readl_relaxed(base + UTMIP_BIAS_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 364 | val |= UTMIP_OTGPD | UTMIP_BIASPD; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 365 | writel_relaxed(val, base + UTMIP_BIAS_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | spin_unlock_irqrestore(&utmip_pad_lock, flags); |
| 369 | |
Prashant Gaikwad | 6a5278d | 2012-06-05 09:59:35 +0530 | [diff] [blame] | 370 | clk_disable_unprepare(phy->pad_clk); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | static int utmi_wait_register(void __iomem *reg, u32 mask, u32 result) |
| 376 | { |
Dmitry Osipenko | 43bcf64 | 2017-12-17 20:02:39 +0300 | [diff] [blame] | 377 | u32 tmp; |
| 378 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 379 | return readl_relaxed_poll_timeout(reg, tmp, (tmp & mask) == result, |
| 380 | 2000, 6000); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | static void utmi_phy_clk_disable(struct tegra_usb_phy *phy) |
| 384 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 385 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 386 | unsigned long val; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 387 | |
Jon Hunter | 203f44c4 | 2017-10-02 12:22:53 +0100 | [diff] [blame] | 388 | /* |
| 389 | * The USB driver may have already initiated the phy clock |
| 390 | * disable so wait to see if the clock turns off and if not |
| 391 | * then proceed with gating the clock. |
| 392 | */ |
| 393 | if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) == 0) |
| 394 | return; |
| 395 | |
Venu Byravarasu | 3a55c6a | 2013-01-16 03:30:20 +0000 | [diff] [blame] | 396 | if (phy->is_legacy_phy) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 397 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 398 | val |= USB_SUSP_SET; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 399 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 400 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 401 | usleep_range(10, 100); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 402 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 403 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 404 | val &= ~USB_SUSP_SET; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 405 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 406 | } else { |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 407 | set_phcd(phy, true); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 408 | } |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 409 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 410 | if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0)) |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 411 | dev_err(phy->u_phy.dev, |
| 412 | "Timeout waiting for PHY to stabilize on disable\n"); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | static void utmi_phy_clk_enable(struct tegra_usb_phy *phy) |
| 416 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 417 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 418 | unsigned long val; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 419 | |
Jon Hunter | 203f44c4 | 2017-10-02 12:22:53 +0100 | [diff] [blame] | 420 | /* |
| 421 | * The USB driver may have already initiated the phy clock |
| 422 | * enable so wait to see if the clock turns on and if not |
| 423 | * then proceed with ungating the clock. |
| 424 | */ |
| 425 | if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, |
| 426 | USB_PHY_CLK_VALID) == 0) |
| 427 | return; |
| 428 | |
Venu Byravarasu | 3a55c6a | 2013-01-16 03:30:20 +0000 | [diff] [blame] | 429 | if (phy->is_legacy_phy) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 430 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 431 | val |= USB_SUSP_CLR; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 432 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 433 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 434 | usleep_range(10, 100); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 435 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 436 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 437 | val &= ~USB_SUSP_CLR; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 438 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 439 | } else { |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 440 | set_phcd(phy, false); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 441 | } |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 442 | |
| 443 | if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 444 | USB_PHY_CLK_VALID)) |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 445 | dev_err(phy->u_phy.dev, |
| 446 | "Timeout waiting for PHY to stabilize on enable\n"); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | static int utmi_phy_power_on(struct tegra_usb_phy *phy) |
| 450 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 451 | struct tegra_utmip_config *config = phy->config; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 452 | void __iomem *base = phy->regs; |
| 453 | unsigned long val; |
| 454 | int err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 455 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 456 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 457 | val |= UTMIP_RESET; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 458 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 459 | |
Venu Byravarasu | 3a55c6a | 2013-01-16 03:30:20 +0000 | [diff] [blame] | 460 | if (phy->is_legacy_phy) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 461 | val = readl_relaxed(base + USB1_LEGACY_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 462 | val |= USB1_NO_LEGACY_MODE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 463 | writel_relaxed(val, base + USB1_LEGACY_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 464 | } |
| 465 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 466 | val = readl_relaxed(base + UTMIP_TX_CFG0); |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 467 | val |= UTMIP_FS_PREABMLE_J; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 468 | writel_relaxed(val, base + UTMIP_TX_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 469 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 470 | val = readl_relaxed(base + UTMIP_HSRX_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 471 | val &= ~(UTMIP_IDLE_WAIT(~0) | UTMIP_ELASTIC_LIMIT(~0)); |
| 472 | val |= UTMIP_IDLE_WAIT(config->idle_wait_delay); |
| 473 | val |= UTMIP_ELASTIC_LIMIT(config->elastic_limit); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 474 | writel_relaxed(val, base + UTMIP_HSRX_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 475 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 476 | val = readl_relaxed(base + UTMIP_HSRX_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 477 | val &= ~UTMIP_HS_SYNC_START_DLY(~0); |
| 478 | val |= UTMIP_HS_SYNC_START_DLY(config->hssync_start_delay); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 479 | writel_relaxed(val, base + UTMIP_HSRX_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 480 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 481 | val = readl_relaxed(base + UTMIP_DEBOUNCE_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 482 | val &= ~UTMIP_BIAS_DEBOUNCE_A(~0); |
| 483 | val |= UTMIP_BIAS_DEBOUNCE_A(phy->freq->debounce); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 484 | writel_relaxed(val, base + UTMIP_DEBOUNCE_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 485 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 486 | val = readl_relaxed(base + UTMIP_MISC_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 487 | val &= ~UTMIP_SUSPEND_EXIT_ON_EDGE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 488 | writel_relaxed(val, base + UTMIP_MISC_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 489 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 490 | if (!phy->soc_config->utmi_pll_config_in_car_module) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 491 | val = readl_relaxed(base + UTMIP_MISC_CFG1); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 492 | val &= ~(UTMIP_PLL_ACTIVE_DLY_COUNT(~0) | |
| 493 | UTMIP_PLLU_STABLE_COUNT(~0)); |
| 494 | val |= UTMIP_PLL_ACTIVE_DLY_COUNT(phy->freq->active_delay) | |
| 495 | UTMIP_PLLU_STABLE_COUNT(phy->freq->stable_count); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 496 | writel_relaxed(val, base + UTMIP_MISC_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 497 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 498 | val = readl_relaxed(base + UTMIP_PLL_CFG1); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 499 | val &= ~(UTMIP_XTAL_FREQ_COUNT(~0) | |
| 500 | UTMIP_PLLU_ENABLE_DLY_COUNT(~0)); |
| 501 | val |= UTMIP_XTAL_FREQ_COUNT(phy->freq->xtal_freq_count) | |
| 502 | UTMIP_PLLU_ENABLE_DLY_COUNT(phy->freq->enable_delay); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 503 | writel_relaxed(val, base + UTMIP_PLL_CFG1); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 504 | } |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 505 | |
Tuomas Tynkkynen | 6558d7e | 2013-07-25 21:38:09 +0300 | [diff] [blame] | 506 | if (phy->mode == USB_DR_MODE_PERIPHERAL) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 507 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 508 | val &= ~(USB_WAKE_ON_CNNT_EN_DEV | USB_WAKE_ON_DISCON_EN_DEV); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 509 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 510 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 511 | val = readl_relaxed(base + UTMIP_BAT_CHRG_CFG0); |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 512 | val &= ~UTMIP_PD_CHRG; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 513 | writel_relaxed(val, base + UTMIP_BAT_CHRG_CFG0); |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 514 | } else { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 515 | val = readl_relaxed(base + UTMIP_BAT_CHRG_CFG0); |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 516 | val |= UTMIP_PD_CHRG; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 517 | writel_relaxed(val, base + UTMIP_BAT_CHRG_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 518 | } |
| 519 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 520 | err = utmip_pad_power_on(phy); |
| 521 | if (err) |
| 522 | return err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 523 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 524 | val = readl_relaxed(base + UTMIP_XCVR_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 525 | val &= ~(UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN | |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 526 | UTMIP_FORCE_PDZI_POWERDOWN | UTMIP_XCVR_LSBIAS_SEL | |
| 527 | UTMIP_XCVR_SETUP(~0) | UTMIP_XCVR_SETUP_MSB(~0) | |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 528 | UTMIP_XCVR_LSFSLEW(~0) | UTMIP_XCVR_LSRSLEW(~0)); |
| 529 | |
| 530 | if (!config->xcvr_setup_use_fuses) { |
| 531 | val |= UTMIP_XCVR_SETUP(config->xcvr_setup); |
| 532 | val |= UTMIP_XCVR_SETUP_MSB(config->xcvr_setup); |
| 533 | } |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 534 | val |= UTMIP_XCVR_LSFSLEW(config->xcvr_lsfslew); |
| 535 | val |= UTMIP_XCVR_LSRSLEW(config->xcvr_lsrslew); |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 536 | |
| 537 | if (phy->soc_config->requires_extra_tuning_parameters) { |
| 538 | val &= ~(UTMIP_XCVR_HSSLEW(~0) | UTMIP_XCVR_HSSLEW_MSB(~0)); |
| 539 | val |= UTMIP_XCVR_HSSLEW(config->xcvr_hsslew); |
| 540 | val |= UTMIP_XCVR_HSSLEW_MSB(config->xcvr_hsslew); |
| 541 | } |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 542 | writel_relaxed(val, base + UTMIP_XCVR_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 543 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 544 | val = readl_relaxed(base + UTMIP_XCVR_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 545 | val &= ~(UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN | |
| 546 | UTMIP_FORCE_PDDR_POWERDOWN | UTMIP_XCVR_TERM_RANGE_ADJ(~0)); |
| 547 | val |= UTMIP_XCVR_TERM_RANGE_ADJ(config->term_range_adj); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 548 | writel_relaxed(val, base + UTMIP_XCVR_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 549 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 550 | val = readl_relaxed(base + UTMIP_BIAS_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 551 | val &= ~UTMIP_BIAS_PDTRK_COUNT(~0); |
| 552 | val |= UTMIP_BIAS_PDTRK_COUNT(0x5); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 553 | writel_relaxed(val, base + UTMIP_BIAS_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 554 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 555 | val = readl_relaxed(base + UTMIP_SPARE_CFG0); |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 556 | if (config->xcvr_setup_use_fuses) |
| 557 | val |= FUSE_SETUP_SEL; |
| 558 | else |
| 559 | val &= ~FUSE_SETUP_SEL; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 560 | writel_relaxed(val, base + UTMIP_SPARE_CFG0); |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 561 | |
| 562 | if (!phy->is_legacy_phy) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 563 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 564 | val |= UTMIP_PHY_ENABLE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 565 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 566 | } |
| 567 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 568 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 569 | val &= ~UTMIP_RESET; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 570 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 571 | |
Venu Byravarasu | 3a55c6a | 2013-01-16 03:30:20 +0000 | [diff] [blame] | 572 | if (phy->is_legacy_phy) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 573 | val = readl_relaxed(base + USB1_LEGACY_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 574 | val &= ~USB1_VBUS_SENSE_CTL_MASK; |
| 575 | val |= USB1_VBUS_SENSE_CTL_A_SESS_VLD; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 576 | writel_relaxed(val, base + USB1_LEGACY_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 577 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 578 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 579 | val &= ~USB_SUSP_SET; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 580 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | utmi_phy_clk_enable(phy); |
| 584 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 585 | if (phy->soc_config->requires_usbmode_setup) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 586 | val = readl_relaxed(base + USB_USBMODE); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 587 | val &= ~USB_USBMODE_MASK; |
| 588 | if (phy->mode == USB_DR_MODE_HOST) |
| 589 | val |= USB_USBMODE_HOST; |
| 590 | else |
| 591 | val |= USB_USBMODE_DEVICE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 592 | writel_relaxed(val, base + USB_USBMODE); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 593 | } |
| 594 | |
Venu Byravarasu | bbdabdb | 2013-01-17 20:15:37 +0000 | [diff] [blame] | 595 | if (!phy->is_legacy_phy) |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 596 | set_pts(phy, 0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 597 | |
| 598 | return 0; |
| 599 | } |
| 600 | |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 601 | static int utmi_phy_power_off(struct tegra_usb_phy *phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 602 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 603 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 604 | unsigned long val; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 605 | |
| 606 | utmi_phy_clk_disable(phy); |
| 607 | |
Tuomas Tynkkynen | 6558d7e | 2013-07-25 21:38:09 +0300 | [diff] [blame] | 608 | if (phy->mode == USB_DR_MODE_PERIPHERAL) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 609 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 610 | val &= ~USB_WAKEUP_DEBOUNCE_COUNT(~0); |
| 611 | val |= USB_WAKE_ON_CNNT_EN_DEV | USB_WAKEUP_DEBOUNCE_COUNT(5); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 612 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 613 | } |
| 614 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 615 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 616 | val |= UTMIP_RESET; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 617 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 618 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 619 | val = readl_relaxed(base + UTMIP_BAT_CHRG_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 620 | val |= UTMIP_PD_CHRG; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 621 | writel_relaxed(val, base + UTMIP_BAT_CHRG_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 622 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 623 | val = readl_relaxed(base + UTMIP_XCVR_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 624 | val |= UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN | |
| 625 | UTMIP_FORCE_PDZI_POWERDOWN; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 626 | writel_relaxed(val, base + UTMIP_XCVR_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 627 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 628 | val = readl_relaxed(base + UTMIP_XCVR_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 629 | val |= UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN | |
| 630 | UTMIP_FORCE_PDDR_POWERDOWN; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 631 | writel_relaxed(val, base + UTMIP_XCVR_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 632 | |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 633 | return utmip_pad_power_off(phy); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | static void utmi_phy_preresume(struct tegra_usb_phy *phy) |
| 637 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 638 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 639 | unsigned long val; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 640 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 641 | val = readl_relaxed(base + UTMIP_TX_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 642 | val |= UTMIP_HS_DISCON_DISABLE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 643 | writel_relaxed(val, base + UTMIP_TX_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | static void utmi_phy_postresume(struct tegra_usb_phy *phy) |
| 647 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 648 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 649 | unsigned long val; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 650 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 651 | val = readl_relaxed(base + UTMIP_TX_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 652 | val &= ~UTMIP_HS_DISCON_DISABLE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 653 | writel_relaxed(val, base + UTMIP_TX_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | static void utmi_phy_restore_start(struct tegra_usb_phy *phy, |
| 657 | enum tegra_usb_phy_port_speed port_speed) |
| 658 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 659 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 660 | unsigned long val; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 661 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 662 | val = readl_relaxed(base + UTMIP_MISC_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 663 | val &= ~UTMIP_DPDM_OBSERVE_SEL(~0); |
| 664 | if (port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW) |
| 665 | val |= UTMIP_DPDM_OBSERVE_SEL_FS_K; |
| 666 | else |
| 667 | val |= UTMIP_DPDM_OBSERVE_SEL_FS_J; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 668 | writel_relaxed(val, base + UTMIP_MISC_CFG0); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 669 | usleep_range(1, 10); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 670 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 671 | val = readl_relaxed(base + UTMIP_MISC_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 672 | val |= UTMIP_DPDM_OBSERVE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 673 | writel_relaxed(val, base + UTMIP_MISC_CFG0); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 674 | usleep_range(10, 100); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | static void utmi_phy_restore_end(struct tegra_usb_phy *phy) |
| 678 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 679 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 680 | unsigned long val; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 681 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 682 | val = readl_relaxed(base + UTMIP_MISC_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 683 | val &= ~UTMIP_DPDM_OBSERVE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 684 | writel_relaxed(val, base + UTMIP_MISC_CFG0); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 685 | usleep_range(10, 100); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | static int ulpi_phy_power_on(struct tegra_usb_phy *phy) |
| 689 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 690 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 691 | unsigned long val; |
| 692 | int err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 693 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 694 | err = gpio_direction_output(phy->reset_gpio, 0); |
| 695 | if (err) { |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 696 | dev_err(phy->u_phy.dev, "GPIO %d not set to 0: %d\n", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 697 | phy->reset_gpio, err); |
| 698 | return err; |
Venu Byravarasu | 6829f92 | 2013-05-16 19:43:01 +0530 | [diff] [blame] | 699 | } |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 700 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 701 | err = clk_prepare_enable(phy->clk); |
| 702 | if (err) |
| 703 | return err; |
| 704 | |
| 705 | usleep_range(5000, 6000); |
| 706 | |
| 707 | err = gpio_direction_output(phy->reset_gpio, 1); |
| 708 | if (err) { |
| 709 | dev_err(phy->u_phy.dev, "GPIO %d not set to 1: %d\n", |
| 710 | phy->reset_gpio, err); |
| 711 | goto disable_clk; |
| 712 | } |
| 713 | |
| 714 | usleep_range(1000, 2000); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 715 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 716 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 717 | val |= UHSIC_RESET; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 718 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 719 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 720 | val = readl_relaxed(base + ULPI_TIMING_CTRL_0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 721 | val |= ULPI_OUTPUT_PINMUX_BYP | ULPI_CLKOUT_PINMUX_BYP; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 722 | writel_relaxed(val, base + ULPI_TIMING_CTRL_0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 723 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 724 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 725 | val |= ULPI_PHY_ENABLE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 726 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 727 | |
| 728 | val = 0; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 729 | writel_relaxed(val, base + ULPI_TIMING_CTRL_1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 730 | |
| 731 | val |= ULPI_DATA_TRIMMER_SEL(4); |
| 732 | val |= ULPI_STPDIRNXT_TRIMMER_SEL(4); |
| 733 | val |= ULPI_DIR_TRIMMER_SEL(4); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 734 | writel_relaxed(val, base + ULPI_TIMING_CTRL_1); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 735 | usleep_range(10, 100); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 736 | |
| 737 | val |= ULPI_DATA_TRIMMER_LOAD; |
| 738 | val |= ULPI_STPDIRNXT_TRIMMER_LOAD; |
| 739 | val |= ULPI_DIR_TRIMMER_LOAD; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 740 | writel_relaxed(val, base + ULPI_TIMING_CTRL_1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 741 | |
| 742 | /* Fix VbusInvalid due to floating VBUS */ |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 743 | err = usb_phy_io_write(phy->ulpi, 0x40, 0x08); |
| 744 | if (err) { |
| 745 | dev_err(phy->u_phy.dev, "ULPI write failed: %d\n", err); |
| 746 | goto disable_clk; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 747 | } |
| 748 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 749 | err = usb_phy_io_write(phy->ulpi, 0x80, 0x0B); |
| 750 | if (err) { |
| 751 | dev_err(phy->u_phy.dev, "ULPI write failed: %d\n", err); |
| 752 | goto disable_clk; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 753 | } |
| 754 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 755 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 756 | val |= USB_SUSP_CLR; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 757 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 758 | usleep_range(100, 1000); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 759 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 760 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 761 | val &= ~USB_SUSP_CLR; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 762 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 763 | |
| 764 | return 0; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 765 | |
| 766 | disable_clk: |
| 767 | clk_disable_unprepare(phy->clk); |
| 768 | |
| 769 | return err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 770 | } |
| 771 | |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 772 | static int ulpi_phy_power_off(struct tegra_usb_phy *phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 773 | { |
Dmitry Osipenko | 28d190a | 2020-01-06 04:33:59 +0300 | [diff] [blame] | 774 | int err; |
| 775 | |
| 776 | err = gpio_direction_output(phy->reset_gpio, 0); |
| 777 | if (err) { |
| 778 | dev_err(phy->u_phy.dev, "reset GPIO not asserted: %d\n", err); |
| 779 | return err; |
| 780 | } |
| 781 | |
| 782 | usleep_range(5000, 6000); |
| 783 | |
| 784 | clk_disable_unprepare(phy->clk); |
| 785 | |
| 786 | return 0; |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 787 | } |
| 788 | |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 789 | static int tegra_usb_phy_power_on(struct tegra_usb_phy *phy) |
| 790 | { |
Dmitry Osipenko | 18bd8bf | 2020-01-06 04:34:00 +0300 | [diff] [blame] | 791 | int err; |
| 792 | |
| 793 | if (phy->powered_on) |
| 794 | return 0; |
| 795 | |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 796 | if (phy->is_ulpi_phy) |
Dmitry Osipenko | 18bd8bf | 2020-01-06 04:34:00 +0300 | [diff] [blame] | 797 | err = ulpi_phy_power_on(phy); |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 798 | else |
Dmitry Osipenko | 18bd8bf | 2020-01-06 04:34:00 +0300 | [diff] [blame] | 799 | err = utmi_phy_power_on(phy); |
| 800 | if (err) |
| 801 | return err; |
| 802 | |
| 803 | phy->powered_on = true; |
| 804 | |
| 805 | return 0; |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | static int tegra_usb_phy_power_off(struct tegra_usb_phy *phy) |
| 809 | { |
Dmitry Osipenko | 18bd8bf | 2020-01-06 04:34:00 +0300 | [diff] [blame] | 810 | int err; |
| 811 | |
| 812 | if (!phy->powered_on) |
| 813 | return 0; |
| 814 | |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 815 | if (phy->is_ulpi_phy) |
Dmitry Osipenko | 18bd8bf | 2020-01-06 04:34:00 +0300 | [diff] [blame] | 816 | err = ulpi_phy_power_off(phy); |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 817 | else |
Dmitry Osipenko | 18bd8bf | 2020-01-06 04:34:00 +0300 | [diff] [blame] | 818 | err = utmi_phy_power_off(phy); |
| 819 | if (err) |
| 820 | return err; |
| 821 | |
| 822 | phy->powered_on = false; |
| 823 | |
| 824 | return 0; |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 825 | } |
| 826 | |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 827 | static void tegra_usb_phy_shutdown(struct usb_phy *u_phy) |
| 828 | { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 829 | struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 830 | |
| 831 | if (WARN_ON(!phy->freq)) |
| 832 | return; |
| 833 | |
| 834 | tegra_usb_phy_power_off(phy); |
| 835 | |
| 836 | if (!phy->is_ulpi_phy) |
| 837 | utmip_pad_close(phy); |
| 838 | |
Dmitry Osipenko | 9df3adc | 2020-01-06 04:34:05 +0300 | [diff] [blame] | 839 | regulator_disable(phy->vbus); |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 840 | clk_disable_unprepare(phy->pll_u); |
| 841 | |
| 842 | phy->freq = NULL; |
| 843 | } |
| 844 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 845 | static int tegra_usb_phy_set_suspend(struct usb_phy *u_phy, int suspend) |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 846 | { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 847 | struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 848 | |
| 849 | if (WARN_ON(!phy->freq)) |
| 850 | return -EINVAL; |
| 851 | |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 852 | if (suspend) |
| 853 | return tegra_usb_phy_power_off(phy); |
| 854 | else |
| 855 | return tegra_usb_phy_power_on(phy); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 856 | } |
| 857 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 858 | static int ulpi_open(struct tegra_usb_phy *phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 859 | { |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 860 | int err; |
| 861 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 862 | err = gpio_direction_output(phy->reset_gpio, 0); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 863 | if (err) { |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 864 | dev_err(phy->u_phy.dev, |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 865 | "ULPI reset GPIO %d direction not asserted: %d\n", |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 866 | phy->reset_gpio, err); |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 867 | return err; |
| 868 | } |
| 869 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 870 | return 0; |
| 871 | } |
| 872 | |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 873 | static int tegra_usb_phy_init(struct usb_phy *u_phy) |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 874 | { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 875 | struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 876 | unsigned long parent_rate; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 877 | unsigned int i; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 878 | int err; |
| 879 | |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 880 | if (WARN_ON(phy->freq)) |
| 881 | return 0; |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 882 | |
| 883 | err = clk_prepare_enable(phy->pll_u); |
| 884 | if (err) |
| 885 | return err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 886 | |
| 887 | parent_rate = clk_get_rate(clk_get_parent(phy->pll_u)); |
| 888 | for (i = 0; i < ARRAY_SIZE(tegra_freq_table); i++) { |
| 889 | if (tegra_freq_table[i].freq == parent_rate) { |
| 890 | phy->freq = &tegra_freq_table[i]; |
| 891 | break; |
| 892 | } |
| 893 | } |
| 894 | if (!phy->freq) { |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 895 | dev_err(phy->u_phy.dev, "Invalid pll_u parent rate %ld\n", |
| 896 | parent_rate); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 897 | err = -EINVAL; |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 898 | goto fail; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 899 | } |
| 900 | |
Dmitry Osipenko | 9df3adc | 2020-01-06 04:34:05 +0300 | [diff] [blame] | 901 | err = regulator_enable(phy->vbus); |
| 902 | if (err) { |
| 903 | dev_err(phy->u_phy.dev, |
| 904 | "Failed to enable USB VBUS regulator: %d\n", err); |
| 905 | goto fail; |
Mikko Perttunen | f5b8c8b | 2013-07-17 10:37:49 +0300 | [diff] [blame] | 906 | } |
| 907 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 908 | if (phy->is_ulpi_phy) |
| 909 | err = ulpi_open(phy); |
| 910 | else |
| 911 | err = utmip_pad_open(phy); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 912 | if (err) |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 913 | goto fail; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 914 | |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 915 | err = tegra_usb_phy_power_on(phy); |
| 916 | if (err) |
| 917 | goto close_phy; |
| 918 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 919 | return 0; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 920 | |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 921 | close_phy: |
| 922 | if (!phy->is_ulpi_phy) |
| 923 | utmip_pad_close(phy); |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 924 | fail: |
Prashant Gaikwad | 6a5278d | 2012-06-05 09:59:35 +0530 | [diff] [blame] | 925 | clk_disable_unprepare(phy->pll_u); |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 926 | |
| 927 | phy->freq = NULL; |
| 928 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 929 | return err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 930 | } |
| 931 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 932 | void tegra_usb_phy_preresume(struct usb_phy *u_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 933 | { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 934 | struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); |
Venu Byravarasu | ab137d0 | 2013-01-24 15:57:03 +0530 | [diff] [blame] | 935 | |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 936 | if (!phy->is_ulpi_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 937 | utmi_phy_preresume(phy); |
| 938 | } |
Arnd Bergmann | 4265cbf | 2012-03-02 15:58:42 -0500 | [diff] [blame] | 939 | EXPORT_SYMBOL_GPL(tegra_usb_phy_preresume); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 940 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 941 | void tegra_usb_phy_postresume(struct usb_phy *u_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 942 | { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 943 | struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); |
Venu Byravarasu | ab137d0 | 2013-01-24 15:57:03 +0530 | [diff] [blame] | 944 | |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 945 | if (!phy->is_ulpi_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 946 | utmi_phy_postresume(phy); |
| 947 | } |
Arnd Bergmann | 4265cbf | 2012-03-02 15:58:42 -0500 | [diff] [blame] | 948 | EXPORT_SYMBOL_GPL(tegra_usb_phy_postresume); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 949 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 950 | void tegra_ehci_phy_restore_start(struct usb_phy *u_phy, |
| 951 | enum tegra_usb_phy_port_speed port_speed) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 952 | { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 953 | struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); |
Venu Byravarasu | ab137d0 | 2013-01-24 15:57:03 +0530 | [diff] [blame] | 954 | |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 955 | if (!phy->is_ulpi_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 956 | utmi_phy_restore_start(phy, port_speed); |
| 957 | } |
Arnd Bergmann | 4265cbf | 2012-03-02 15:58:42 -0500 | [diff] [blame] | 958 | EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_start); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 959 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 960 | void tegra_ehci_phy_restore_end(struct usb_phy *u_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 961 | { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 962 | struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); |
Venu Byravarasu | ab137d0 | 2013-01-24 15:57:03 +0530 | [diff] [blame] | 963 | |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 964 | if (!phy->is_ulpi_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 965 | utmi_phy_restore_end(phy); |
| 966 | } |
Arnd Bergmann | 4265cbf | 2012-03-02 15:58:42 -0500 | [diff] [blame] | 967 | EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_end); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 968 | |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 969 | static int read_utmi_param(struct platform_device *pdev, const char *param, |
| 970 | u8 *dest) |
| 971 | { |
| 972 | u32 value; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 973 | int err; |
| 974 | |
| 975 | err = of_property_read_u32(pdev->dev.of_node, param, &value); |
| 976 | if (err) |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 977 | dev_err(&pdev->dev, |
| 978 | "Failed to read USB UTMI parameter %s: %d\n", |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 979 | param, err); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 980 | else |
| 981 | *dest = value; |
| 982 | |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 983 | return err; |
| 984 | } |
| 985 | |
| 986 | static int utmi_phy_probe(struct tegra_usb_phy *tegra_phy, |
| 987 | struct platform_device *pdev) |
| 988 | { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 989 | struct tegra_utmip_config *config; |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 990 | struct resource *res; |
| 991 | int err; |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 992 | |
| 993 | tegra_phy->is_ulpi_phy = false; |
| 994 | |
| 995 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 996 | if (!res) { |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 997 | dev_err(&pdev->dev, "Failed to get UTMI pad regs\n"); |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 998 | return -ENXIO; |
| 999 | } |
| 1000 | |
| 1001 | tegra_phy->pad_regs = devm_ioremap(&pdev->dev, res->start, |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1002 | resource_size(res)); |
Chris Ruehl | 851dd02 | 2013-12-04 10:02:44 +0800 | [diff] [blame] | 1003 | if (!tegra_phy->pad_regs) { |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 1004 | dev_err(&pdev->dev, "Failed to remap UTMI pad regs\n"); |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1005 | return -ENOMEM; |
| 1006 | } |
| 1007 | |
Thierry Reding | 9ce9ec9 | 2014-07-21 13:37:37 +0200 | [diff] [blame] | 1008 | tegra_phy->config = devm_kzalloc(&pdev->dev, sizeof(*config), |
| 1009 | GFP_KERNEL); |
Peter Chen | 01ad32d | 2014-10-14 15:56:13 +0800 | [diff] [blame] | 1010 | if (!tegra_phy->config) |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1011 | return -ENOMEM; |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1012 | |
| 1013 | config = tegra_phy->config; |
| 1014 | |
| 1015 | err = read_utmi_param(pdev, "nvidia,hssync-start-delay", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1016 | &config->hssync_start_delay); |
| 1017 | if (err) |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1018 | return err; |
| 1019 | |
| 1020 | err = read_utmi_param(pdev, "nvidia,elastic-limit", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1021 | &config->elastic_limit); |
| 1022 | if (err) |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1023 | return err; |
| 1024 | |
| 1025 | err = read_utmi_param(pdev, "nvidia,idle-wait-delay", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1026 | &config->idle_wait_delay); |
| 1027 | if (err) |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1028 | return err; |
| 1029 | |
| 1030 | err = read_utmi_param(pdev, "nvidia,term-range-adj", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1031 | &config->term_range_adj); |
| 1032 | if (err) |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1033 | return err; |
| 1034 | |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1035 | err = read_utmi_param(pdev, "nvidia,xcvr-lsfslew", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1036 | &config->xcvr_lsfslew); |
| 1037 | if (err) |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1038 | return err; |
| 1039 | |
| 1040 | err = read_utmi_param(pdev, "nvidia,xcvr-lsrslew", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1041 | &config->xcvr_lsrslew); |
| 1042 | if (err) |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1043 | return err; |
| 1044 | |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 1045 | if (tegra_phy->soc_config->requires_extra_tuning_parameters) { |
| 1046 | err = read_utmi_param(pdev, "nvidia,xcvr-hsslew", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1047 | &config->xcvr_hsslew); |
| 1048 | if (err) |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 1049 | return err; |
| 1050 | |
| 1051 | err = read_utmi_param(pdev, "nvidia,hssquelch-level", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1052 | &config->hssquelch_level); |
| 1053 | if (err) |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 1054 | return err; |
| 1055 | |
| 1056 | err = read_utmi_param(pdev, "nvidia,hsdiscon-level", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1057 | &config->hsdiscon_level); |
| 1058 | if (err) |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 1059 | return err; |
| 1060 | } |
| 1061 | |
| 1062 | config->xcvr_setup_use_fuses = of_property_read_bool( |
| 1063 | pdev->dev.of_node, "nvidia,xcvr-setup-use-fuses"); |
| 1064 | |
| 1065 | if (!config->xcvr_setup_use_fuses) { |
| 1066 | err = read_utmi_param(pdev, "nvidia,xcvr-setup", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1067 | &config->xcvr_setup); |
| 1068 | if (err) |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 1069 | return err; |
| 1070 | } |
| 1071 | |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1072 | return 0; |
| 1073 | } |
| 1074 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 1075 | static const struct tegra_phy_soc_config tegra20_soc_config = { |
| 1076 | .utmi_pll_config_in_car_module = false, |
| 1077 | .has_hostpc = false, |
| 1078 | .requires_usbmode_setup = false, |
| 1079 | .requires_extra_tuning_parameters = false, |
| 1080 | }; |
| 1081 | |
| 1082 | static const struct tegra_phy_soc_config tegra30_soc_config = { |
| 1083 | .utmi_pll_config_in_car_module = true, |
| 1084 | .has_hostpc = true, |
| 1085 | .requires_usbmode_setup = true, |
| 1086 | .requires_extra_tuning_parameters = true, |
| 1087 | }; |
| 1088 | |
Jingoo Han | 0f0520b | 2014-06-18 13:43:50 +0900 | [diff] [blame] | 1089 | static const struct of_device_id tegra_usb_phy_id_table[] = { |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 1090 | { .compatible = "nvidia,tegra30-usb-phy", .data = &tegra30_soc_config }, |
| 1091 | { .compatible = "nvidia,tegra20-usb-phy", .data = &tegra20_soc_config }, |
| 1092 | { }, |
| 1093 | }; |
| 1094 | MODULE_DEVICE_TABLE(of, tegra_usb_phy_id_table); |
| 1095 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1096 | static int tegra_usb_phy_probe(struct platform_device *pdev) |
| 1097 | { |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1098 | struct device_node *np = pdev->dev.of_node; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1099 | struct tegra_usb_phy *tegra_phy; |
Tuomas Tynkkynen | 9fdb07f | 2013-07-25 21:38:08 +0300 | [diff] [blame] | 1100 | enum usb_phy_interface phy_type; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1101 | struct reset_control *reset; |
| 1102 | struct resource *res; |
Dmitry Osipenko | 8754174 | 2020-01-06 04:34:07 +0300 | [diff] [blame^] | 1103 | struct usb_phy *phy; |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1104 | int err; |
| 1105 | |
| 1106 | tegra_phy = devm_kzalloc(&pdev->dev, sizeof(*tegra_phy), GFP_KERNEL); |
Peter Chen | 01ad32d | 2014-10-14 15:56:13 +0800 | [diff] [blame] | 1107 | if (!tegra_phy) |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1108 | return -ENOMEM; |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1109 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1110 | tegra_phy->soc_config = of_device_get_match_data(&pdev->dev); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 1111 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1112 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1113 | if (!res) { |
| 1114 | dev_err(&pdev->dev, "Failed to get I/O memory\n"); |
| 1115 | return -ENXIO; |
| 1116 | } |
| 1117 | |
| 1118 | tegra_phy->regs = devm_ioremap(&pdev->dev, res->start, |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1119 | resource_size(res)); |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1120 | if (!tegra_phy->regs) { |
| 1121 | dev_err(&pdev->dev, "Failed to remap I/O memory\n"); |
| 1122 | return -ENOMEM; |
| 1123 | } |
| 1124 | |
| 1125 | tegra_phy->is_legacy_phy = |
| 1126 | of_property_read_bool(np, "nvidia,has-legacy-mode"); |
| 1127 | |
Tuomas Tynkkynen | 6558d7e | 2013-07-25 21:38:09 +0300 | [diff] [blame] | 1128 | if (of_find_property(np, "dr_mode", NULL)) |
Heikki Krogerus | 06e7114 | 2015-09-21 11:14:34 +0300 | [diff] [blame] | 1129 | tegra_phy->mode = usb_get_dr_mode(&pdev->dev); |
Tuomas Tynkkynen | 6558d7e | 2013-07-25 21:38:09 +0300 | [diff] [blame] | 1130 | else |
| 1131 | tegra_phy->mode = USB_DR_MODE_HOST; |
| 1132 | |
| 1133 | if (tegra_phy->mode == USB_DR_MODE_UNKNOWN) { |
| 1134 | dev_err(&pdev->dev, "dr_mode is invalid\n"); |
| 1135 | return -EINVAL; |
| 1136 | } |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1137 | |
Mikko Perttunen | f5b8c8b | 2013-07-17 10:37:49 +0300 | [diff] [blame] | 1138 | /* On some boards, the VBUS regulator doesn't need to be controlled */ |
Dmitry Osipenko | 9df3adc | 2020-01-06 04:34:05 +0300 | [diff] [blame] | 1139 | tegra_phy->vbus = devm_regulator_get(&pdev->dev, "vbus"); |
| 1140 | if (IS_ERR(tegra_phy->vbus)) |
| 1141 | return PTR_ERR(tegra_phy->vbus); |
Mikko Perttunen | f5b8c8b | 2013-07-17 10:37:49 +0300 | [diff] [blame] | 1142 | |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1143 | tegra_phy->pll_u = devm_clk_get(&pdev->dev, "pll_u"); |
| 1144 | err = PTR_ERR_OR_ZERO(tegra_phy->pll_u); |
| 1145 | if (err) { |
| 1146 | dev_err(&pdev->dev, "Failed to get pll_u clock: %d\n", err); |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1147 | return err; |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1148 | } |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1149 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1150 | phy_type = of_usb_get_phy_mode(np); |
| 1151 | switch (phy_type) { |
| 1152 | case USBPHY_INTERFACE_MODE_UTMI: |
| 1153 | err = utmi_phy_probe(tegra_phy, pdev); |
| 1154 | if (err) |
| 1155 | return err; |
| 1156 | |
| 1157 | tegra_phy->pad_clk = devm_clk_get(&pdev->dev, "utmi-pads"); |
| 1158 | err = PTR_ERR_OR_ZERO(tegra_phy->pad_clk); |
| 1159 | if (err) { |
| 1160 | dev_err(&pdev->dev, |
| 1161 | "Failed to get UTMIP pad clock: %d\n", err); |
| 1162 | return err; |
| 1163 | } |
| 1164 | |
| 1165 | reset = devm_reset_control_get_optional_shared(&pdev->dev, |
| 1166 | "utmi-pads"); |
| 1167 | err = PTR_ERR_OR_ZERO(reset); |
| 1168 | if (err) { |
| 1169 | dev_err(&pdev->dev, |
| 1170 | "Failed to get UTMI-pads reset: %d\n", err); |
| 1171 | return err; |
| 1172 | } |
| 1173 | tegra_phy->pad_rst = reset; |
| 1174 | break; |
| 1175 | |
| 1176 | case USBPHY_INTERFACE_MODE_ULPI: |
| 1177 | tegra_phy->is_ulpi_phy = true; |
| 1178 | |
| 1179 | tegra_phy->reset_gpio = |
| 1180 | of_get_named_gpio(np, "nvidia,phy-reset-gpio", 0); |
| 1181 | |
| 1182 | if (!gpio_is_valid(tegra_phy->reset_gpio)) { |
| 1183 | dev_err(&pdev->dev, |
| 1184 | "Invalid GPIO: %d\n", tegra_phy->reset_gpio); |
| 1185 | return tegra_phy->reset_gpio; |
| 1186 | } |
| 1187 | |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1188 | tegra_phy->clk = devm_clk_get(&pdev->dev, "ulpi-link"); |
| 1189 | err = PTR_ERR_OR_ZERO(tegra_phy->clk); |
| 1190 | if (err) { |
| 1191 | dev_err(&pdev->dev, |
| 1192 | "Failed to get ULPI clock: %d\n", err); |
| 1193 | return err; |
| 1194 | } |
| 1195 | |
| 1196 | err = devm_gpio_request(&pdev->dev, tegra_phy->reset_gpio, |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1197 | "ulpi_phy_reset_b"); |
| 1198 | if (err) { |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1199 | dev_err(&pdev->dev, "Request failed for GPIO %d: %d\n", |
| 1200 | tegra_phy->reset_gpio, err); |
| 1201 | return err; |
| 1202 | } |
| 1203 | |
Dmitry Osipenko | 8754174 | 2020-01-06 04:34:07 +0300 | [diff] [blame^] | 1204 | phy = devm_otg_ulpi_create(&pdev->dev, |
| 1205 | &ulpi_viewport_access_ops, 0); |
| 1206 | if (!phy) { |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1207 | dev_err(&pdev->dev, "Failed to create ULPI OTG\n"); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1208 | return -ENOMEM; |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1209 | } |
| 1210 | |
Dmitry Osipenko | 8754174 | 2020-01-06 04:34:07 +0300 | [diff] [blame^] | 1211 | tegra_phy->ulpi = phy; |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1212 | tegra_phy->ulpi->io_priv = tegra_phy->regs + ULPI_VIEWPORT; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1213 | break; |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1214 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1215 | default: |
| 1216 | dev_err(&pdev->dev, "phy_type %u is invalid or unsupported\n", |
| 1217 | phy_type); |
| 1218 | return -EINVAL; |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | tegra_phy->u_phy.dev = &pdev->dev; |
| 1222 | tegra_phy->u_phy.init = tegra_usb_phy_init; |
| 1223 | tegra_phy->u_phy.shutdown = tegra_usb_phy_shutdown; |
| 1224 | tegra_phy->u_phy.set_suspend = tegra_usb_phy_set_suspend; |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1225 | |
Libo Chen | 72031b5 | 2013-08-30 11:23:32 +0800 | [diff] [blame] | 1226 | platform_set_drvdata(pdev, tegra_phy); |
Tuomas Tynkkynen | 0ee5b4a | 2013-07-25 21:38:05 +0300 | [diff] [blame] | 1227 | |
| 1228 | err = usb_add_phy_dev(&tegra_phy->u_phy); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1229 | if (err) |
Dmitry Osipenko | 8754174 | 2020-01-06 04:34:07 +0300 | [diff] [blame^] | 1230 | return err; |
Tuomas Tynkkynen | 0ee5b4a | 2013-07-25 21:38:05 +0300 | [diff] [blame] | 1231 | |
| 1232 | return 0; |
| 1233 | } |
| 1234 | |
| 1235 | static int tegra_usb_phy_remove(struct platform_device *pdev) |
| 1236 | { |
| 1237 | struct tegra_usb_phy *tegra_phy = platform_get_drvdata(pdev); |
| 1238 | |
| 1239 | usb_remove_phy(&tegra_phy->u_phy); |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1240 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1241 | return 0; |
| 1242 | } |
| 1243 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1244 | static struct platform_driver tegra_usb_phy_driver = { |
| 1245 | .probe = tegra_usb_phy_probe, |
Tuomas Tynkkynen | 0ee5b4a | 2013-07-25 21:38:05 +0300 | [diff] [blame] | 1246 | .remove = tegra_usb_phy_remove, |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1247 | .driver = { |
| 1248 | .name = "tegra-phy", |
Sachin Kamat | 78723920 | 2013-09-30 09:44:47 +0530 | [diff] [blame] | 1249 | .of_match_table = tegra_usb_phy_id_table, |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1250 | }, |
| 1251 | }; |
| 1252 | module_platform_driver(tegra_usb_phy_driver); |
| 1253 | |
Stephen Warren | 587376a | 2013-06-13 11:24:08 -0600 | [diff] [blame] | 1254 | MODULE_DESCRIPTION("Tegra USB PHY driver"); |
| 1255 | MODULE_LICENSE("GPL v2"); |