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> |
Krzysztof Kozlowski | 9cb9322 | 2020-03-03 12:29:20 +0100 | [diff] [blame] | 15 | #include <linux/gpio/consumer.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> |
Dmitry Osipenko | 5bb6985 | 2020-01-06 04:34:03 +0300 | [diff] [blame] | 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/resource.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/spinlock.h> |
| 24 | |
Mikko Perttunen | f5b8c8b | 2013-07-17 10:37:49 +0300 | [diff] [blame] | 25 | #include <linux/regulator/consumer.h> |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 26 | |
Dmitry Osipenko | 5bb6985 | 2020-01-06 04:34:03 +0300 | [diff] [blame] | 27 | #include <linux/usb/ehci_def.h> |
| 28 | #include <linux/usb/of.h> |
| 29 | #include <linux/usb/tegra_usb_phy.h> |
| 30 | #include <linux/usb/ulpi.h> |
| 31 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 32 | #define ULPI_VIEWPORT 0x170 |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 33 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 34 | /* PORTSC PTS/PHCD bits, Tegra20 only */ |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 35 | #define TEGRA_USB_PORTSC1 0x184 |
| 36 | #define TEGRA_USB_PORTSC1_PTS(x) (((x) & 0x3) << 30) |
| 37 | #define TEGRA_USB_PORTSC1_PHCD BIT(23) |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 38 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 39 | /* HOSTPC1 PTS/PHCD bits, Tegra30 and above */ |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 40 | #define TEGRA_USB_HOSTPC1_DEVLC 0x1b4 |
| 41 | #define TEGRA_USB_HOSTPC1_DEVLC_PTS(x) (((x) & 0x7) << 29) |
| 42 | #define TEGRA_USB_HOSTPC1_DEVLC_PHCD BIT(22) |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 43 | |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 44 | /* Bits of PORTSC1, which will get cleared by writing 1 into them */ |
| 45 | #define TEGRA_PORTSC1_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC) |
| 46 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 47 | #define USB_SUSP_CTRL 0x400 |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 48 | #define USB_WAKE_ON_RESUME_EN BIT(2) |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 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 | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 60 | #define USB_PHY_VBUS_SENSORS 0x404 |
Dmitry Osipenko | 7917e90 | 2021-06-13 17:59:36 +0300 | [diff] [blame] | 61 | #define B_SESS_VLD_WAKEUP_EN BIT(14) |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 62 | #define A_SESS_VLD_WAKEUP_EN BIT(22) |
| 63 | #define A_VBUS_VLD_WAKEUP_EN BIT(30) |
| 64 | |
| 65 | #define USB_PHY_VBUS_WAKEUP_ID 0x408 |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 66 | #define ID_INT_EN BIT(0) |
| 67 | #define ID_CHG_DET BIT(1) |
| 68 | #define VBUS_WAKEUP_INT_EN BIT(8) |
| 69 | #define VBUS_WAKEUP_CHG_DET BIT(9) |
Dmitry Osipenko | 6f8d39a | 2021-06-13 17:59:35 +0300 | [diff] [blame] | 70 | #define VBUS_WAKEUP_STS BIT(10) |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 71 | #define VBUS_WAKEUP_WAKEUP_EN BIT(30) |
| 72 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 73 | #define USB1_LEGACY_CTRL 0x410 |
| 74 | #define USB1_NO_LEGACY_MODE BIT(0) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 75 | #define USB1_VBUS_SENSE_CTL_MASK (3 << 1) |
| 76 | #define USB1_VBUS_SENSE_CTL_VBUS_WAKEUP (0 << 1) |
| 77 | #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD_OR_VBUS_WAKEUP \ |
| 78 | (1 << 1) |
| 79 | #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD (2 << 1) |
| 80 | #define USB1_VBUS_SENSE_CTL_A_SESS_VLD (3 << 1) |
| 81 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 82 | #define ULPI_TIMING_CTRL_0 0x424 |
| 83 | #define ULPI_OUTPUT_PINMUX_BYP BIT(10) |
| 84 | #define ULPI_CLKOUT_PINMUX_BYP BIT(11) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 85 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 86 | #define ULPI_TIMING_CTRL_1 0x428 |
| 87 | #define ULPI_DATA_TRIMMER_LOAD BIT(0) |
| 88 | #define ULPI_DATA_TRIMMER_SEL(x) (((x) & 0x7) << 1) |
| 89 | #define ULPI_STPDIRNXT_TRIMMER_LOAD BIT(16) |
| 90 | #define ULPI_STPDIRNXT_TRIMMER_SEL(x) (((x) & 0x7) << 17) |
| 91 | #define ULPI_DIR_TRIMMER_LOAD BIT(24) |
| 92 | #define ULPI_DIR_TRIMMER_SEL(x) (((x) & 0x7) << 25) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 93 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 94 | #define UTMIP_PLL_CFG1 0x804 |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 95 | #define UTMIP_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0) |
| 96 | #define UTMIP_PLLU_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27) |
| 97 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 98 | #define UTMIP_XCVR_CFG0 0x808 |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 99 | #define UTMIP_XCVR_SETUP(x) (((x) & 0xf) << 0) |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 100 | #define UTMIP_XCVR_SETUP_MSB(x) ((((x) & 0x70) >> 4) << 22) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 101 | #define UTMIP_XCVR_LSRSLEW(x) (((x) & 0x3) << 8) |
| 102 | #define UTMIP_XCVR_LSFSLEW(x) (((x) & 0x3) << 10) |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 103 | #define UTMIP_FORCE_PD_POWERDOWN BIT(14) |
| 104 | #define UTMIP_FORCE_PD2_POWERDOWN BIT(16) |
| 105 | #define UTMIP_FORCE_PDZI_POWERDOWN BIT(18) |
| 106 | #define UTMIP_XCVR_LSBIAS_SEL BIT(21) |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 107 | #define UTMIP_XCVR_HSSLEW(x) (((x) & 0x3) << 4) |
| 108 | #define UTMIP_XCVR_HSSLEW_MSB(x) ((((x) & 0x1fc) >> 2) << 25) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 109 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 110 | #define UTMIP_BIAS_CFG0 0x80c |
| 111 | #define UTMIP_OTGPD BIT(11) |
| 112 | #define UTMIP_BIASPD BIT(10) |
| 113 | #define UTMIP_HSSQUELCH_LEVEL(x) (((x) & 0x3) << 0) |
| 114 | #define UTMIP_HSDISCON_LEVEL(x) (((x) & 0x3) << 2) |
| 115 | #define UTMIP_HSDISCON_LEVEL_MSB(x) ((((x) & 0x4) >> 2) << 24) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 116 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 117 | #define UTMIP_HSRX_CFG0 0x810 |
| 118 | #define UTMIP_ELASTIC_LIMIT(x) (((x) & 0x1f) << 10) |
| 119 | #define UTMIP_IDLE_WAIT(x) (((x) & 0x1f) << 15) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 120 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 121 | #define UTMIP_HSRX_CFG1 0x814 |
| 122 | #define UTMIP_HS_SYNC_START_DLY(x) (((x) & 0x1f) << 1) |
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_TX_CFG0 0x820 |
| 125 | #define UTMIP_FS_PREABMLE_J BIT(19) |
| 126 | #define UTMIP_HS_DISCON_DISABLE BIT(8) |
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_MISC_CFG0 0x824 |
| 129 | #define UTMIP_DPDM_OBSERVE BIT(26) |
| 130 | #define UTMIP_DPDM_OBSERVE_SEL(x) (((x) & 0xf) << 27) |
| 131 | #define UTMIP_DPDM_OBSERVE_SEL_FS_J UTMIP_DPDM_OBSERVE_SEL(0xf) |
| 132 | #define UTMIP_DPDM_OBSERVE_SEL_FS_K UTMIP_DPDM_OBSERVE_SEL(0xe) |
| 133 | #define UTMIP_DPDM_OBSERVE_SEL_FS_SE1 UTMIP_DPDM_OBSERVE_SEL(0xd) |
| 134 | #define UTMIP_DPDM_OBSERVE_SEL_FS_SE0 UTMIP_DPDM_OBSERVE_SEL(0xc) |
| 135 | #define UTMIP_SUSPEND_EXIT_ON_EDGE BIT(22) |
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_MISC_CFG1 0x828 |
| 138 | #define UTMIP_PLL_ACTIVE_DLY_COUNT(x) (((x) & 0x1f) << 18) |
| 139 | #define UTMIP_PLLU_STABLE_COUNT(x) (((x) & 0xfff) << 6) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 140 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 141 | #define UTMIP_DEBOUNCE_CFG0 0x82c |
| 142 | #define UTMIP_BIAS_DEBOUNCE_A(x) (((x) & 0xffff) << 0) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 143 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 144 | #define UTMIP_BAT_CHRG_CFG0 0x830 |
| 145 | #define UTMIP_PD_CHRG BIT(0) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 146 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 147 | #define UTMIP_SPARE_CFG0 0x834 |
| 148 | #define FUSE_SETUP_SEL BIT(3) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 149 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 150 | #define UTMIP_XCVR_CFG1 0x838 |
| 151 | #define UTMIP_FORCE_PDDISC_POWERDOWN BIT(0) |
| 152 | #define UTMIP_FORCE_PDCHRP_POWERDOWN BIT(2) |
| 153 | #define UTMIP_FORCE_PDDR_POWERDOWN BIT(4) |
| 154 | #define UTMIP_XCVR_TERM_RANGE_ADJ(x) (((x) & 0xf) << 18) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 155 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 156 | #define UTMIP_BIAS_CFG1 0x83c |
| 157 | #define UTMIP_BIAS_PDTRK_COUNT(x) (((x) & 0x1f) << 3) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 158 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 159 | /* For Tegra30 and above only, the address is different in Tegra20 */ |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 160 | #define USB_USBMODE 0x1f8 |
| 161 | #define USB_USBMODE_MASK (3 << 0) |
| 162 | #define USB_USBMODE_HOST (3 << 0) |
| 163 | #define USB_USBMODE_DEVICE (2 << 0) |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 164 | |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 165 | #define PMC_USB_AO 0xf0 |
| 166 | #define VBUS_WAKEUP_PD_P0 BIT(2) |
| 167 | #define ID_PD_P0 BIT(3) |
| 168 | |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 169 | static DEFINE_SPINLOCK(utmip_pad_lock); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 170 | static unsigned int utmip_pad_count; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 171 | |
| 172 | struct tegra_xtal_freq { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 173 | unsigned int freq; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 174 | u8 enable_delay; |
| 175 | u8 stable_count; |
| 176 | u8 active_delay; |
| 177 | u8 xtal_freq_count; |
| 178 | u16 debounce; |
| 179 | }; |
| 180 | |
| 181 | static const struct tegra_xtal_freq tegra_freq_table[] = { |
| 182 | { |
| 183 | .freq = 12000000, |
| 184 | .enable_delay = 0x02, |
| 185 | .stable_count = 0x2F, |
| 186 | .active_delay = 0x04, |
| 187 | .xtal_freq_count = 0x76, |
| 188 | .debounce = 0x7530, |
| 189 | }, |
| 190 | { |
| 191 | .freq = 13000000, |
| 192 | .enable_delay = 0x02, |
| 193 | .stable_count = 0x33, |
| 194 | .active_delay = 0x05, |
| 195 | .xtal_freq_count = 0x7F, |
| 196 | .debounce = 0x7EF4, |
| 197 | }, |
| 198 | { |
| 199 | .freq = 19200000, |
| 200 | .enable_delay = 0x03, |
| 201 | .stable_count = 0x4B, |
| 202 | .active_delay = 0x06, |
| 203 | .xtal_freq_count = 0xBB, |
| 204 | .debounce = 0xBB80, |
| 205 | }, |
| 206 | { |
| 207 | .freq = 26000000, |
| 208 | .enable_delay = 0x04, |
| 209 | .stable_count = 0x66, |
| 210 | .active_delay = 0x09, |
| 211 | .xtal_freq_count = 0xFE, |
| 212 | .debounce = 0xFDE8, |
| 213 | }, |
| 214 | }; |
| 215 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 216 | static inline struct tegra_usb_phy *to_tegra_usb_phy(struct usb_phy *u_phy) |
| 217 | { |
| 218 | return container_of(u_phy, struct tegra_usb_phy, u_phy); |
| 219 | } |
| 220 | |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 221 | static void set_pts(struct tegra_usb_phy *phy, u8 pts_val) |
| 222 | { |
| 223 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 01d6ea3 | 2020-01-06 04:34:08 +0300 | [diff] [blame] | 224 | u32 val; |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 225 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 226 | if (phy->soc_config->has_hostpc) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 227 | val = readl_relaxed(base + TEGRA_USB_HOSTPC1_DEVLC); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 228 | val &= ~TEGRA_USB_HOSTPC1_DEVLC_PTS(~0); |
| 229 | val |= TEGRA_USB_HOSTPC1_DEVLC_PTS(pts_val); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 230 | writel_relaxed(val, base + TEGRA_USB_HOSTPC1_DEVLC); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 231 | } else { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 232 | val = readl_relaxed(base + TEGRA_USB_PORTSC1); |
| 233 | val &= ~TEGRA_PORTSC1_RWC_BITS; |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 234 | val &= ~TEGRA_USB_PORTSC1_PTS(~0); |
| 235 | val |= TEGRA_USB_PORTSC1_PTS(pts_val); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 236 | writel_relaxed(val, base + TEGRA_USB_PORTSC1); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 237 | } |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | static void set_phcd(struct tegra_usb_phy *phy, bool enable) |
| 241 | { |
| 242 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 01d6ea3 | 2020-01-06 04:34:08 +0300 | [diff] [blame] | 243 | u32 val; |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 244 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 245 | if (phy->soc_config->has_hostpc) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 246 | val = readl_relaxed(base + TEGRA_USB_HOSTPC1_DEVLC); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 247 | if (enable) |
| 248 | val |= TEGRA_USB_HOSTPC1_DEVLC_PHCD; |
| 249 | else |
| 250 | val &= ~TEGRA_USB_HOSTPC1_DEVLC_PHCD; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 251 | writel_relaxed(val, base + TEGRA_USB_HOSTPC1_DEVLC); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 252 | } else { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 253 | val = readl_relaxed(base + TEGRA_USB_PORTSC1) & ~PORT_RWC_BITS; |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 254 | if (enable) |
| 255 | val |= TEGRA_USB_PORTSC1_PHCD; |
| 256 | else |
| 257 | val &= ~TEGRA_USB_PORTSC1_PHCD; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 258 | writel_relaxed(val, base + TEGRA_USB_PORTSC1); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 259 | } |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 260 | } |
| 261 | |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 262 | static int utmip_pad_open(struct tegra_usb_phy *phy) |
| 263 | { |
Dmitry Osipenko | 1434703 | 2018-04-10 01:02:58 +0300 | [diff] [blame] | 264 | int ret; |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 265 | |
Dmitry Osipenko | 1434703 | 2018-04-10 01:02:58 +0300 | [diff] [blame] | 266 | ret = clk_prepare_enable(phy->pad_clk); |
| 267 | if (ret) { |
| 268 | dev_err(phy->u_phy.dev, |
| 269 | "Failed to enable UTMI-pads clock: %d\n", ret); |
| 270 | return ret; |
| 271 | } |
| 272 | |
| 273 | spin_lock(&utmip_pad_lock); |
| 274 | |
| 275 | ret = reset_control_deassert(phy->pad_rst); |
| 276 | if (ret) { |
| 277 | dev_err(phy->u_phy.dev, |
| 278 | "Failed to initialize UTMI-pads reset: %d\n", ret); |
| 279 | goto unlock; |
| 280 | } |
| 281 | |
| 282 | ret = reset_control_assert(phy->pad_rst); |
| 283 | if (ret) { |
| 284 | dev_err(phy->u_phy.dev, |
| 285 | "Failed to assert UTMI-pads reset: %d\n", ret); |
| 286 | goto unlock; |
| 287 | } |
| 288 | |
| 289 | udelay(1); |
| 290 | |
| 291 | ret = reset_control_deassert(phy->pad_rst); |
| 292 | if (ret) |
| 293 | dev_err(phy->u_phy.dev, |
| 294 | "Failed to deassert UTMI-pads reset: %d\n", ret); |
| 295 | unlock: |
| 296 | spin_unlock(&utmip_pad_lock); |
| 297 | |
| 298 | clk_disable_unprepare(phy->pad_clk); |
| 299 | |
| 300 | return ret; |
| 301 | } |
| 302 | |
| 303 | static int utmip_pad_close(struct tegra_usb_phy *phy) |
| 304 | { |
| 305 | int ret; |
| 306 | |
| 307 | ret = clk_prepare_enable(phy->pad_clk); |
| 308 | if (ret) { |
| 309 | dev_err(phy->u_phy.dev, |
| 310 | "Failed to enable UTMI-pads clock: %d\n", ret); |
| 311 | return ret; |
| 312 | } |
| 313 | |
| 314 | ret = reset_control_assert(phy->pad_rst); |
| 315 | if (ret) |
| 316 | dev_err(phy->u_phy.dev, |
| 317 | "Failed to assert UTMI-pads reset: %d\n", ret); |
| 318 | |
| 319 | udelay(1); |
| 320 | |
| 321 | clk_disable_unprepare(phy->pad_clk); |
| 322 | |
| 323 | return ret; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 326 | static int utmip_pad_power_on(struct tegra_usb_phy *phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 327 | { |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 328 | struct tegra_utmip_config *config = phy->config; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 329 | void __iomem *base = phy->pad_regs; |
Dmitry Osipenko | 01d6ea3 | 2020-01-06 04:34:08 +0300 | [diff] [blame] | 330 | u32 val; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 331 | int err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 332 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 333 | err = clk_prepare_enable(phy->pad_clk); |
| 334 | if (err) |
| 335 | return err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 336 | |
Dmitry Osipenko | f1f0c75 | 2020-01-06 04:34:12 +0300 | [diff] [blame] | 337 | spin_lock(&utmip_pad_lock); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 338 | |
| 339 | if (utmip_pad_count++ == 0) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 340 | val = readl_relaxed(base + UTMIP_BIAS_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 341 | val &= ~(UTMIP_OTGPD | UTMIP_BIASPD); |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 342 | |
| 343 | if (phy->soc_config->requires_extra_tuning_parameters) { |
| 344 | val &= ~(UTMIP_HSSQUELCH_LEVEL(~0) | |
| 345 | UTMIP_HSDISCON_LEVEL(~0) | |
| 346 | UTMIP_HSDISCON_LEVEL_MSB(~0)); |
| 347 | |
| 348 | val |= UTMIP_HSSQUELCH_LEVEL(config->hssquelch_level); |
| 349 | val |= UTMIP_HSDISCON_LEVEL(config->hsdiscon_level); |
| 350 | val |= UTMIP_HSDISCON_LEVEL_MSB(config->hsdiscon_level); |
| 351 | } |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 352 | writel_relaxed(val, base + UTMIP_BIAS_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 353 | } |
| 354 | |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 355 | if (phy->pad_wakeup) { |
| 356 | phy->pad_wakeup = false; |
| 357 | utmip_pad_count--; |
| 358 | } |
| 359 | |
Dmitry Osipenko | f1f0c75 | 2020-01-06 04:34:12 +0300 | [diff] [blame] | 360 | spin_unlock(&utmip_pad_lock); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 361 | |
Prashant Gaikwad | 6a5278d | 2012-06-05 09:59:35 +0530 | [diff] [blame] | 362 | clk_disable_unprepare(phy->pad_clk); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 363 | |
| 364 | return 0; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | static int utmip_pad_power_off(struct tegra_usb_phy *phy) |
| 368 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 369 | void __iomem *base = phy->pad_regs; |
Dmitry Osipenko | 01d6ea3 | 2020-01-06 04:34:08 +0300 | [diff] [blame] | 370 | u32 val; |
Dmitry Osipenko | 92bd2ef | 2020-01-06 04:34:11 +0300 | [diff] [blame] | 371 | int ret; |
| 372 | |
| 373 | ret = clk_prepare_enable(phy->pad_clk); |
| 374 | if (ret) |
| 375 | return ret; |
| 376 | |
Dmitry Osipenko | f1f0c75 | 2020-01-06 04:34:12 +0300 | [diff] [blame] | 377 | spin_lock(&utmip_pad_lock); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 378 | |
| 379 | if (!utmip_pad_count) { |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 380 | dev_err(phy->u_phy.dev, "UTMIP pad already powered off\n"); |
Dmitry Osipenko | 92bd2ef | 2020-01-06 04:34:11 +0300 | [diff] [blame] | 381 | ret = -EINVAL; |
| 382 | goto ulock; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 383 | } |
| 384 | |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 385 | /* |
| 386 | * In accordance to TRM, OTG and Bias pad circuits could be turned off |
| 387 | * to save power if wake is enabled, but the VBUS-change detection |
| 388 | * method is board-specific and these circuits may need to be enabled |
| 389 | * to generate wakeup event, hence we will just keep them both enabled. |
| 390 | */ |
| 391 | if (phy->wakeup_enabled) { |
| 392 | phy->pad_wakeup = true; |
| 393 | utmip_pad_count++; |
| 394 | } |
| 395 | |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 396 | if (--utmip_pad_count == 0) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 397 | val = readl_relaxed(base + UTMIP_BIAS_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 398 | val |= UTMIP_OTGPD | UTMIP_BIASPD; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 399 | writel_relaxed(val, base + UTMIP_BIAS_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 400 | } |
Dmitry Osipenko | 92bd2ef | 2020-01-06 04:34:11 +0300 | [diff] [blame] | 401 | ulock: |
Dmitry Osipenko | f1f0c75 | 2020-01-06 04:34:12 +0300 | [diff] [blame] | 402 | spin_unlock(&utmip_pad_lock); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 403 | |
Prashant Gaikwad | 6a5278d | 2012-06-05 09:59:35 +0530 | [diff] [blame] | 404 | clk_disable_unprepare(phy->pad_clk); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 405 | |
Dmitry Osipenko | 92bd2ef | 2020-01-06 04:34:11 +0300 | [diff] [blame] | 406 | return ret; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | static int utmi_wait_register(void __iomem *reg, u32 mask, u32 result) |
| 410 | { |
Dmitry Osipenko | 43bcf64 | 2017-12-17 20:02:39 +0300 | [diff] [blame] | 411 | u32 tmp; |
| 412 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 413 | return readl_relaxed_poll_timeout(reg, tmp, (tmp & mask) == result, |
| 414 | 2000, 6000); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | static void utmi_phy_clk_disable(struct tegra_usb_phy *phy) |
| 418 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 419 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 01d6ea3 | 2020-01-06 04:34:08 +0300 | [diff] [blame] | 420 | u32 val; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 421 | |
Jon Hunter | 203f44c4 | 2017-10-02 12:22:53 +0100 | [diff] [blame] | 422 | /* |
| 423 | * The USB driver may have already initiated the phy clock |
| 424 | * disable so wait to see if the clock turns off and if not |
| 425 | * then proceed with gating the clock. |
| 426 | */ |
| 427 | if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) == 0) |
| 428 | return; |
| 429 | |
Venu Byravarasu | 3a55c6a | 2013-01-16 03:30:20 +0000 | [diff] [blame] | 430 | if (phy->is_legacy_phy) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 431 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 432 | val |= USB_SUSP_SET; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 433 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 434 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 435 | usleep_range(10, 100); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 436 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 437 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 438 | val &= ~USB_SUSP_SET; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 439 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 440 | } else { |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 441 | set_phcd(phy, true); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 442 | } |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 443 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 444 | 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] | 445 | dev_err(phy->u_phy.dev, |
| 446 | "Timeout waiting for PHY to stabilize on disable\n"); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | static void utmi_phy_clk_enable(struct tegra_usb_phy *phy) |
| 450 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 451 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 01d6ea3 | 2020-01-06 04:34:08 +0300 | [diff] [blame] | 452 | u32 val; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 453 | |
Jon Hunter | 203f44c4 | 2017-10-02 12:22:53 +0100 | [diff] [blame] | 454 | /* |
| 455 | * The USB driver may have already initiated the phy clock |
| 456 | * enable so wait to see if the clock turns on and if not |
| 457 | * then proceed with ungating the clock. |
| 458 | */ |
| 459 | if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, |
| 460 | USB_PHY_CLK_VALID) == 0) |
| 461 | return; |
| 462 | |
Venu Byravarasu | 3a55c6a | 2013-01-16 03:30:20 +0000 | [diff] [blame] | 463 | if (phy->is_legacy_phy) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 464 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 465 | val |= USB_SUSP_CLR; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 466 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 467 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 468 | usleep_range(10, 100); |
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 + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 471 | val &= ~USB_SUSP_CLR; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 472 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 473 | } else { |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 474 | set_phcd(phy, false); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 475 | } |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 476 | |
| 477 | if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 478 | USB_PHY_CLK_VALID)) |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 479 | dev_err(phy->u_phy.dev, |
| 480 | "Timeout waiting for PHY to stabilize on enable\n"); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | static int utmi_phy_power_on(struct tegra_usb_phy *phy) |
| 484 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 485 | struct tegra_utmip_config *config = phy->config; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 486 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 01d6ea3 | 2020-01-06 04:34:08 +0300 | [diff] [blame] | 487 | u32 val; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 488 | int err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 489 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 490 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 491 | val |= UTMIP_RESET; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 492 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 493 | |
Venu Byravarasu | 3a55c6a | 2013-01-16 03:30:20 +0000 | [diff] [blame] | 494 | if (phy->is_legacy_phy) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 495 | val = readl_relaxed(base + USB1_LEGACY_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 496 | val |= USB1_NO_LEGACY_MODE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 497 | writel_relaxed(val, base + USB1_LEGACY_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 498 | } |
| 499 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 500 | val = readl_relaxed(base + UTMIP_TX_CFG0); |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 501 | val |= UTMIP_FS_PREABMLE_J; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 502 | writel_relaxed(val, base + UTMIP_TX_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 503 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 504 | val = readl_relaxed(base + UTMIP_HSRX_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 505 | val &= ~(UTMIP_IDLE_WAIT(~0) | UTMIP_ELASTIC_LIMIT(~0)); |
| 506 | val |= UTMIP_IDLE_WAIT(config->idle_wait_delay); |
| 507 | val |= UTMIP_ELASTIC_LIMIT(config->elastic_limit); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 508 | writel_relaxed(val, base + UTMIP_HSRX_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 509 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 510 | val = readl_relaxed(base + UTMIP_HSRX_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 511 | val &= ~UTMIP_HS_SYNC_START_DLY(~0); |
| 512 | val |= UTMIP_HS_SYNC_START_DLY(config->hssync_start_delay); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 513 | writel_relaxed(val, base + UTMIP_HSRX_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 514 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 515 | val = readl_relaxed(base + UTMIP_DEBOUNCE_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 516 | val &= ~UTMIP_BIAS_DEBOUNCE_A(~0); |
| 517 | val |= UTMIP_BIAS_DEBOUNCE_A(phy->freq->debounce); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 518 | writel_relaxed(val, base + UTMIP_DEBOUNCE_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 519 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 520 | val = readl_relaxed(base + UTMIP_MISC_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 521 | val &= ~UTMIP_SUSPEND_EXIT_ON_EDGE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 522 | writel_relaxed(val, base + UTMIP_MISC_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 523 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 524 | if (!phy->soc_config->utmi_pll_config_in_car_module) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 525 | val = readl_relaxed(base + UTMIP_MISC_CFG1); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 526 | val &= ~(UTMIP_PLL_ACTIVE_DLY_COUNT(~0) | |
| 527 | UTMIP_PLLU_STABLE_COUNT(~0)); |
| 528 | val |= UTMIP_PLL_ACTIVE_DLY_COUNT(phy->freq->active_delay) | |
| 529 | UTMIP_PLLU_STABLE_COUNT(phy->freq->stable_count); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 530 | writel_relaxed(val, base + UTMIP_MISC_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 531 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 532 | val = readl_relaxed(base + UTMIP_PLL_CFG1); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 533 | val &= ~(UTMIP_XTAL_FREQ_COUNT(~0) | |
| 534 | UTMIP_PLLU_ENABLE_DLY_COUNT(~0)); |
| 535 | val |= UTMIP_XTAL_FREQ_COUNT(phy->freq->xtal_freq_count) | |
| 536 | UTMIP_PLLU_ENABLE_DLY_COUNT(phy->freq->enable_delay); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 537 | writel_relaxed(val, base + UTMIP_PLL_CFG1); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 538 | } |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 539 | |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 540 | val = readl_relaxed(base + USB_SUSP_CTRL); |
| 541 | val &= ~USB_WAKE_ON_RESUME_EN; |
| 542 | writel_relaxed(val, base + USB_SUSP_CTRL); |
| 543 | |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 544 | if (phy->mode != USB_DR_MODE_HOST) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 545 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 546 | 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] | 547 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 548 | |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 549 | val = readl_relaxed(base + USB_PHY_VBUS_WAKEUP_ID); |
| 550 | val &= ~VBUS_WAKEUP_WAKEUP_EN; |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 551 | val &= ~(ID_CHG_DET | VBUS_WAKEUP_CHG_DET); |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 552 | writel_relaxed(val, base + USB_PHY_VBUS_WAKEUP_ID); |
| 553 | |
| 554 | val = readl_relaxed(base + USB_PHY_VBUS_SENSORS); |
| 555 | val &= ~(A_VBUS_VLD_WAKEUP_EN | A_SESS_VLD_WAKEUP_EN); |
Dmitry Osipenko | 7917e90 | 2021-06-13 17:59:36 +0300 | [diff] [blame] | 556 | val &= ~(B_SESS_VLD_WAKEUP_EN); |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 557 | writel_relaxed(val, base + USB_PHY_VBUS_SENSORS); |
| 558 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 559 | val = readl_relaxed(base + UTMIP_BAT_CHRG_CFG0); |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 560 | val &= ~UTMIP_PD_CHRG; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 561 | writel_relaxed(val, base + UTMIP_BAT_CHRG_CFG0); |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 562 | } else { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 563 | val = readl_relaxed(base + UTMIP_BAT_CHRG_CFG0); |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 564 | val |= UTMIP_PD_CHRG; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 565 | writel_relaxed(val, base + UTMIP_BAT_CHRG_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 566 | } |
| 567 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 568 | err = utmip_pad_power_on(phy); |
| 569 | if (err) |
| 570 | return err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 571 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 572 | val = readl_relaxed(base + UTMIP_XCVR_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 573 | val &= ~(UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN | |
Tuomas Tynkkynen | f5833a0 | 2013-08-12 16:06:50 +0300 | [diff] [blame] | 574 | UTMIP_FORCE_PDZI_POWERDOWN | UTMIP_XCVR_LSBIAS_SEL | |
| 575 | UTMIP_XCVR_SETUP(~0) | UTMIP_XCVR_SETUP_MSB(~0) | |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 576 | UTMIP_XCVR_LSFSLEW(~0) | UTMIP_XCVR_LSRSLEW(~0)); |
| 577 | |
| 578 | if (!config->xcvr_setup_use_fuses) { |
| 579 | val |= UTMIP_XCVR_SETUP(config->xcvr_setup); |
| 580 | val |= UTMIP_XCVR_SETUP_MSB(config->xcvr_setup); |
| 581 | } |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 582 | val |= UTMIP_XCVR_LSFSLEW(config->xcvr_lsfslew); |
| 583 | val |= UTMIP_XCVR_LSRSLEW(config->xcvr_lsrslew); |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 584 | |
| 585 | if (phy->soc_config->requires_extra_tuning_parameters) { |
| 586 | val &= ~(UTMIP_XCVR_HSSLEW(~0) | UTMIP_XCVR_HSSLEW_MSB(~0)); |
| 587 | val |= UTMIP_XCVR_HSSLEW(config->xcvr_hsslew); |
| 588 | val |= UTMIP_XCVR_HSSLEW_MSB(config->xcvr_hsslew); |
| 589 | } |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 590 | writel_relaxed(val, base + UTMIP_XCVR_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 591 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 592 | val = readl_relaxed(base + UTMIP_XCVR_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 593 | val &= ~(UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN | |
| 594 | UTMIP_FORCE_PDDR_POWERDOWN | UTMIP_XCVR_TERM_RANGE_ADJ(~0)); |
| 595 | val |= UTMIP_XCVR_TERM_RANGE_ADJ(config->term_range_adj); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 596 | writel_relaxed(val, base + UTMIP_XCVR_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 597 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 598 | val = readl_relaxed(base + UTMIP_BIAS_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 599 | val &= ~UTMIP_BIAS_PDTRK_COUNT(~0); |
| 600 | val |= UTMIP_BIAS_PDTRK_COUNT(0x5); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 601 | writel_relaxed(val, base + UTMIP_BIAS_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 602 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 603 | val = readl_relaxed(base + UTMIP_SPARE_CFG0); |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 604 | if (config->xcvr_setup_use_fuses) |
| 605 | val |= FUSE_SETUP_SEL; |
| 606 | else |
| 607 | val &= ~FUSE_SETUP_SEL; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 608 | writel_relaxed(val, base + UTMIP_SPARE_CFG0); |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 609 | |
| 610 | if (!phy->is_legacy_phy) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 611 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 612 | val |= UTMIP_PHY_ENABLE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 613 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 614 | } |
| 615 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 616 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 617 | val &= ~UTMIP_RESET; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 618 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 619 | |
Venu Byravarasu | 3a55c6a | 2013-01-16 03:30:20 +0000 | [diff] [blame] | 620 | if (phy->is_legacy_phy) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 621 | val = readl_relaxed(base + USB1_LEGACY_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 622 | val &= ~USB1_VBUS_SENSE_CTL_MASK; |
| 623 | val |= USB1_VBUS_SENSE_CTL_A_SESS_VLD; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 624 | writel_relaxed(val, base + USB1_LEGACY_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 625 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 626 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 627 | val &= ~USB_SUSP_SET; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 628 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | utmi_phy_clk_enable(phy); |
| 632 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 633 | if (phy->soc_config->requires_usbmode_setup) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 634 | val = readl_relaxed(base + USB_USBMODE); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 635 | val &= ~USB_USBMODE_MASK; |
| 636 | if (phy->mode == USB_DR_MODE_HOST) |
| 637 | val |= USB_USBMODE_HOST; |
| 638 | else |
| 639 | val |= USB_USBMODE_DEVICE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 640 | writel_relaxed(val, base + USB_USBMODE); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 641 | } |
| 642 | |
Venu Byravarasu | bbdabdb | 2013-01-17 20:15:37 +0000 | [diff] [blame] | 643 | if (!phy->is_legacy_phy) |
Stephen Warren | 91a687d | 2013-06-13 11:24:11 -0600 | [diff] [blame] | 644 | set_pts(phy, 0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 645 | |
| 646 | return 0; |
| 647 | } |
| 648 | |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 649 | static int utmi_phy_power_off(struct tegra_usb_phy *phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 650 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 651 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 01d6ea3 | 2020-01-06 04:34:08 +0300 | [diff] [blame] | 652 | u32 val; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 653 | |
Dmitry Osipenko | 6f8d39a | 2021-06-13 17:59:35 +0300 | [diff] [blame] | 654 | /* |
| 655 | * Give hardware time to settle down after VBUS disconnection, |
| 656 | * otherwise PHY will immediately wake up from suspend. |
| 657 | */ |
| 658 | if (phy->wakeup_enabled && phy->mode != USB_DR_MODE_HOST) |
| 659 | readl_relaxed_poll_timeout(base + USB_PHY_VBUS_WAKEUP_ID, |
| 660 | val, !(val & VBUS_WAKEUP_STS), |
| 661 | 5000, 100000); |
| 662 | |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 663 | utmi_phy_clk_disable(phy); |
| 664 | |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 665 | /* PHY won't resume if reset is asserted */ |
| 666 | if (!phy->wakeup_enabled) { |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 667 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 668 | val |= UTMIP_RESET; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 669 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 670 | } |
| 671 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 672 | val = readl_relaxed(base + UTMIP_BAT_CHRG_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 673 | val |= UTMIP_PD_CHRG; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 674 | writel_relaxed(val, base + UTMIP_BAT_CHRG_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 675 | |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 676 | if (!phy->wakeup_enabled) { |
| 677 | val = readl_relaxed(base + UTMIP_XCVR_CFG0); |
| 678 | val |= UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN | |
| 679 | UTMIP_FORCE_PDZI_POWERDOWN; |
| 680 | writel_relaxed(val, base + UTMIP_XCVR_CFG0); |
| 681 | } |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 682 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 683 | val = readl_relaxed(base + UTMIP_XCVR_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 684 | val |= UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN | |
| 685 | UTMIP_FORCE_PDDR_POWERDOWN; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 686 | writel_relaxed(val, base + UTMIP_XCVR_CFG1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 687 | |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 688 | if (phy->wakeup_enabled) { |
| 689 | val = readl_relaxed(base + USB_SUSP_CTRL); |
| 690 | val &= ~USB_WAKEUP_DEBOUNCE_COUNT(~0); |
| 691 | val |= USB_WAKEUP_DEBOUNCE_COUNT(5); |
| 692 | val |= USB_WAKE_ON_RESUME_EN; |
| 693 | writel_relaxed(val, base + USB_SUSP_CTRL); |
| 694 | |
| 695 | /* |
| 696 | * Ask VBUS sensor to generate wake event once cable is |
| 697 | * connected. |
| 698 | */ |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 699 | if (phy->mode != USB_DR_MODE_HOST) { |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 700 | val = readl_relaxed(base + USB_PHY_VBUS_WAKEUP_ID); |
| 701 | val |= VBUS_WAKEUP_WAKEUP_EN; |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 702 | val &= ~(ID_CHG_DET | VBUS_WAKEUP_CHG_DET); |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 703 | writel_relaxed(val, base + USB_PHY_VBUS_WAKEUP_ID); |
| 704 | |
| 705 | val = readl_relaxed(base + USB_PHY_VBUS_SENSORS); |
| 706 | val |= A_VBUS_VLD_WAKEUP_EN; |
| 707 | writel_relaxed(val, base + USB_PHY_VBUS_SENSORS); |
| 708 | } |
| 709 | } |
| 710 | |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 711 | return utmip_pad_power_off(phy); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | static void utmi_phy_preresume(struct tegra_usb_phy *phy) |
| 715 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 716 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 01d6ea3 | 2020-01-06 04:34:08 +0300 | [diff] [blame] | 717 | u32 val; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 718 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 719 | val = readl_relaxed(base + UTMIP_TX_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 720 | val |= UTMIP_HS_DISCON_DISABLE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 721 | writel_relaxed(val, base + UTMIP_TX_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | static void utmi_phy_postresume(struct tegra_usb_phy *phy) |
| 725 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 726 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 01d6ea3 | 2020-01-06 04:34:08 +0300 | [diff] [blame] | 727 | u32 val; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 728 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 729 | val = readl_relaxed(base + UTMIP_TX_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 730 | val &= ~UTMIP_HS_DISCON_DISABLE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 731 | writel_relaxed(val, base + UTMIP_TX_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | static void utmi_phy_restore_start(struct tegra_usb_phy *phy, |
| 735 | enum tegra_usb_phy_port_speed port_speed) |
| 736 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 737 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 01d6ea3 | 2020-01-06 04:34:08 +0300 | [diff] [blame] | 738 | u32 val; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 739 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 740 | val = readl_relaxed(base + UTMIP_MISC_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 741 | val &= ~UTMIP_DPDM_OBSERVE_SEL(~0); |
| 742 | if (port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW) |
| 743 | val |= UTMIP_DPDM_OBSERVE_SEL_FS_K; |
| 744 | else |
| 745 | val |= UTMIP_DPDM_OBSERVE_SEL_FS_J; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 746 | writel_relaxed(val, base + UTMIP_MISC_CFG0); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 747 | usleep_range(1, 10); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 748 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 749 | val = readl_relaxed(base + UTMIP_MISC_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 750 | val |= UTMIP_DPDM_OBSERVE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 751 | writel_relaxed(val, base + UTMIP_MISC_CFG0); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 752 | usleep_range(10, 100); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | static void utmi_phy_restore_end(struct tegra_usb_phy *phy) |
| 756 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 757 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 01d6ea3 | 2020-01-06 04:34:08 +0300 | [diff] [blame] | 758 | u32 val; |
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 + UTMIP_MISC_CFG0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 761 | val &= ~UTMIP_DPDM_OBSERVE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 762 | writel_relaxed(val, base + UTMIP_MISC_CFG0); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 763 | usleep_range(10, 100); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | static int ulpi_phy_power_on(struct tegra_usb_phy *phy) |
| 767 | { |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 768 | void __iomem *base = phy->regs; |
Dmitry Osipenko | 01d6ea3 | 2020-01-06 04:34:08 +0300 | [diff] [blame] | 769 | u32 val; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 770 | int err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 771 | |
Dmitry Osipenko | 06e60e50 | 2020-01-06 04:34:09 +0300 | [diff] [blame] | 772 | gpiod_set_value_cansleep(phy->reset_gpio, 1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 773 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 774 | err = clk_prepare_enable(phy->clk); |
| 775 | if (err) |
| 776 | return err; |
| 777 | |
| 778 | usleep_range(5000, 6000); |
| 779 | |
Dmitry Osipenko | 06e60e50 | 2020-01-06 04:34:09 +0300 | [diff] [blame] | 780 | gpiod_set_value_cansleep(phy->reset_gpio, 0); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 781 | |
| 782 | usleep_range(1000, 2000); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 783 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 784 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 785 | val |= UHSIC_RESET; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 786 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 787 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 788 | val = readl_relaxed(base + ULPI_TIMING_CTRL_0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 789 | val |= ULPI_OUTPUT_PINMUX_BYP | ULPI_CLKOUT_PINMUX_BYP; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 790 | writel_relaxed(val, base + ULPI_TIMING_CTRL_0); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 791 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 792 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 793 | val |= ULPI_PHY_ENABLE; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 794 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 795 | |
| 796 | val = 0; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 797 | writel_relaxed(val, base + ULPI_TIMING_CTRL_1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 798 | |
| 799 | val |= ULPI_DATA_TRIMMER_SEL(4); |
| 800 | val |= ULPI_STPDIRNXT_TRIMMER_SEL(4); |
| 801 | val |= ULPI_DIR_TRIMMER_SEL(4); |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 802 | writel_relaxed(val, base + ULPI_TIMING_CTRL_1); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 803 | usleep_range(10, 100); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 804 | |
| 805 | val |= ULPI_DATA_TRIMMER_LOAD; |
| 806 | val |= ULPI_STPDIRNXT_TRIMMER_LOAD; |
| 807 | val |= ULPI_DIR_TRIMMER_LOAD; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 808 | writel_relaxed(val, base + ULPI_TIMING_CTRL_1); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 809 | |
| 810 | /* Fix VbusInvalid due to floating VBUS */ |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 811 | err = usb_phy_io_write(phy->ulpi, 0x40, 0x08); |
| 812 | if (err) { |
| 813 | dev_err(phy->u_phy.dev, "ULPI write failed: %d\n", err); |
| 814 | goto disable_clk; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 815 | } |
| 816 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 817 | err = usb_phy_io_write(phy->ulpi, 0x80, 0x0B); |
| 818 | if (err) { |
| 819 | dev_err(phy->u_phy.dev, "ULPI write failed: %d\n", err); |
| 820 | goto disable_clk; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 821 | } |
| 822 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 823 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 824 | val |= USB_SUSP_CLR; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 825 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 826 | usleep_range(100, 1000); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 827 | |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 828 | val = readl_relaxed(base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 829 | val &= ~USB_SUSP_CLR; |
Dmitry Osipenko | b07e5f8 | 2020-01-06 04:34:04 +0300 | [diff] [blame] | 830 | writel_relaxed(val, base + USB_SUSP_CTRL); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 831 | |
| 832 | return 0; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 833 | |
| 834 | disable_clk: |
| 835 | clk_disable_unprepare(phy->clk); |
| 836 | |
| 837 | return err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 838 | } |
| 839 | |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 840 | static int ulpi_phy_power_off(struct tegra_usb_phy *phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 841 | { |
Dmitry Osipenko | 06e60e50 | 2020-01-06 04:34:09 +0300 | [diff] [blame] | 842 | gpiod_set_value_cansleep(phy->reset_gpio, 1); |
Dmitry Osipenko | 28d190a | 2020-01-06 04:33:59 +0300 | [diff] [blame] | 843 | usleep_range(5000, 6000); |
Dmitry Osipenko | 28d190a | 2020-01-06 04:33:59 +0300 | [diff] [blame] | 844 | clk_disable_unprepare(phy->clk); |
| 845 | |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 846 | /* |
| 847 | * Wakeup currently unimplemented for ULPI, thus PHY needs to be |
| 848 | * force-resumed. |
| 849 | */ |
| 850 | if (WARN_ON_ONCE(phy->wakeup_enabled)) { |
| 851 | ulpi_phy_power_on(phy); |
| 852 | return -EOPNOTSUPP; |
| 853 | } |
| 854 | |
Dmitry Osipenko | 28d190a | 2020-01-06 04:33:59 +0300 | [diff] [blame] | 855 | return 0; |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 856 | } |
| 857 | |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 858 | static int tegra_usb_phy_power_on(struct tegra_usb_phy *phy) |
| 859 | { |
Dmitry Osipenko | 18bd8bf | 2020-01-06 04:34:00 +0300 | [diff] [blame] | 860 | int err; |
| 861 | |
| 862 | if (phy->powered_on) |
| 863 | return 0; |
| 864 | |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 865 | if (phy->is_ulpi_phy) |
Dmitry Osipenko | 18bd8bf | 2020-01-06 04:34:00 +0300 | [diff] [blame] | 866 | err = ulpi_phy_power_on(phy); |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 867 | else |
Dmitry Osipenko | 18bd8bf | 2020-01-06 04:34:00 +0300 | [diff] [blame] | 868 | err = utmi_phy_power_on(phy); |
| 869 | if (err) |
| 870 | return err; |
| 871 | |
| 872 | phy->powered_on = true; |
| 873 | |
Dmitry Osipenko | b100402 | 2020-12-18 15:02:38 +0300 | [diff] [blame] | 874 | /* Let PHY settle down */ |
| 875 | usleep_range(2000, 2500); |
| 876 | |
Dmitry Osipenko | 18bd8bf | 2020-01-06 04:34:00 +0300 | [diff] [blame] | 877 | return 0; |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | static int tegra_usb_phy_power_off(struct tegra_usb_phy *phy) |
| 881 | { |
Dmitry Osipenko | 18bd8bf | 2020-01-06 04:34:00 +0300 | [diff] [blame] | 882 | int err; |
| 883 | |
| 884 | if (!phy->powered_on) |
| 885 | return 0; |
| 886 | |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 887 | if (phy->is_ulpi_phy) |
Dmitry Osipenko | 18bd8bf | 2020-01-06 04:34:00 +0300 | [diff] [blame] | 888 | err = ulpi_phy_power_off(phy); |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 889 | else |
Dmitry Osipenko | 18bd8bf | 2020-01-06 04:34:00 +0300 | [diff] [blame] | 890 | err = utmi_phy_power_off(phy); |
| 891 | if (err) |
| 892 | return err; |
| 893 | |
| 894 | phy->powered_on = false; |
| 895 | |
| 896 | return 0; |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 897 | } |
| 898 | |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 899 | static void tegra_usb_phy_shutdown(struct usb_phy *u_phy) |
| 900 | { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 901 | struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 902 | |
| 903 | if (WARN_ON(!phy->freq)) |
| 904 | return; |
| 905 | |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 906 | usb_phy_set_wakeup(u_phy, false); |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 907 | tegra_usb_phy_power_off(phy); |
| 908 | |
| 909 | if (!phy->is_ulpi_phy) |
| 910 | utmip_pad_close(phy); |
| 911 | |
Dmitry Osipenko | 9df3adc | 2020-01-06 04:34:05 +0300 | [diff] [blame] | 912 | regulator_disable(phy->vbus); |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 913 | clk_disable_unprepare(phy->pll_u); |
| 914 | |
| 915 | phy->freq = NULL; |
| 916 | } |
| 917 | |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 918 | static irqreturn_t tegra_usb_phy_isr(int irq, void *data) |
| 919 | { |
| 920 | u32 val, int_mask = ID_CHG_DET | VBUS_WAKEUP_CHG_DET; |
| 921 | struct tegra_usb_phy *phy = data; |
| 922 | void __iomem *base = phy->regs; |
| 923 | |
| 924 | /* |
| 925 | * The PHY interrupt also wakes the USB controller driver since |
| 926 | * interrupt is shared. We don't do anything in the PHY driver, |
| 927 | * so just clear the interrupt. |
| 928 | */ |
| 929 | val = readl_relaxed(base + USB_PHY_VBUS_WAKEUP_ID); |
| 930 | writel_relaxed(val, base + USB_PHY_VBUS_WAKEUP_ID); |
| 931 | |
| 932 | return val & int_mask ? IRQ_HANDLED : IRQ_NONE; |
| 933 | } |
| 934 | |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 935 | static int tegra_usb_phy_set_wakeup(struct usb_phy *u_phy, bool enable) |
| 936 | { |
| 937 | struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 938 | void __iomem *base = phy->regs; |
| 939 | int ret = 0; |
| 940 | u32 val; |
| 941 | |
| 942 | if (phy->wakeup_enabled && phy->mode != USB_DR_MODE_HOST && |
| 943 | phy->irq > 0) { |
| 944 | disable_irq(phy->irq); |
| 945 | |
| 946 | val = readl_relaxed(base + USB_PHY_VBUS_WAKEUP_ID); |
| 947 | val &= ~(ID_INT_EN | VBUS_WAKEUP_INT_EN); |
| 948 | writel_relaxed(val, base + USB_PHY_VBUS_WAKEUP_ID); |
| 949 | |
| 950 | enable_irq(phy->irq); |
| 951 | |
| 952 | free_irq(phy->irq, phy); |
| 953 | |
| 954 | phy->wakeup_enabled = false; |
| 955 | } |
| 956 | |
| 957 | if (enable && phy->mode != USB_DR_MODE_HOST && phy->irq > 0) { |
| 958 | ret = request_irq(phy->irq, tegra_usb_phy_isr, IRQF_SHARED, |
| 959 | dev_name(phy->u_phy.dev), phy); |
| 960 | if (!ret) { |
| 961 | disable_irq(phy->irq); |
| 962 | |
| 963 | /* |
| 964 | * USB clock will be resumed once wake event will be |
| 965 | * generated. The ID-change event requires to have |
| 966 | * interrupts enabled, otherwise it won't be generated. |
| 967 | */ |
| 968 | val = readl_relaxed(base + USB_PHY_VBUS_WAKEUP_ID); |
| 969 | val |= ID_INT_EN | VBUS_WAKEUP_INT_EN; |
| 970 | writel_relaxed(val, base + USB_PHY_VBUS_WAKEUP_ID); |
| 971 | |
| 972 | enable_irq(phy->irq); |
| 973 | } else { |
| 974 | dev_err(phy->u_phy.dev, |
| 975 | "Failed to request interrupt: %d", ret); |
| 976 | enable = false; |
| 977 | } |
| 978 | } |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 979 | |
| 980 | phy->wakeup_enabled = enable; |
| 981 | |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 982 | return ret; |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 983 | } |
| 984 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 985 | 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] | 986 | { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 987 | struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 988 | int ret; |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 989 | |
| 990 | if (WARN_ON(!phy->freq)) |
| 991 | return -EINVAL; |
| 992 | |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 993 | /* |
| 994 | * PHY is sharing IRQ with the CI driver, hence here we either |
| 995 | * disable interrupt for both PHY and CI or for CI only. The |
| 996 | * interrupt needs to be disabled while hardware is reprogrammed |
| 997 | * because interrupt touches the programmed registers, and thus, |
| 998 | * there could be a race condition. |
| 999 | */ |
| 1000 | if (phy->irq > 0) |
| 1001 | disable_irq(phy->irq); |
| 1002 | |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 1003 | if (suspend) |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 1004 | ret = tegra_usb_phy_power_off(phy); |
Venu Byravarasu | 1ba8216 | 2012-09-05 18:50:23 +0530 | [diff] [blame] | 1005 | else |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 1006 | ret = tegra_usb_phy_power_on(phy); |
| 1007 | |
| 1008 | if (phy->irq > 0) |
| 1009 | enable_irq(phy->irq); |
| 1010 | |
| 1011 | return ret; |
| 1012 | } |
| 1013 | |
| 1014 | static int tegra_usb_phy_configure_pmc(struct tegra_usb_phy *phy) |
| 1015 | { |
| 1016 | int err, val = 0; |
| 1017 | |
| 1018 | /* older device-trees don't have PMC regmap */ |
| 1019 | if (!phy->pmc_regmap) |
| 1020 | return 0; |
| 1021 | |
| 1022 | /* |
| 1023 | * Tegra20 has a different layout of PMC USB register bits and AO is |
| 1024 | * enabled by default after system reset on Tegra20, so assume nothing |
| 1025 | * to do on Tegra20. |
| 1026 | */ |
| 1027 | if (!phy->soc_config->requires_pmc_ao_power_up) |
| 1028 | return 0; |
| 1029 | |
| 1030 | /* enable VBUS wake-up detector */ |
| 1031 | if (phy->mode != USB_DR_MODE_HOST) |
| 1032 | val |= VBUS_WAKEUP_PD_P0 << phy->instance * 4; |
| 1033 | |
| 1034 | /* enable ID-pin ACC detector for OTG mode switching */ |
| 1035 | if (phy->mode == USB_DR_MODE_OTG) |
| 1036 | val |= ID_PD_P0 << phy->instance * 4; |
| 1037 | |
| 1038 | /* disable detectors to reset them */ |
| 1039 | err = regmap_set_bits(phy->pmc_regmap, PMC_USB_AO, val); |
| 1040 | if (err) { |
| 1041 | dev_err(phy->u_phy.dev, "Failed to disable PMC AO: %d\n", err); |
| 1042 | return err; |
| 1043 | } |
| 1044 | |
| 1045 | usleep_range(10, 100); |
| 1046 | |
| 1047 | /* enable detectors */ |
| 1048 | err = regmap_clear_bits(phy->pmc_regmap, PMC_USB_AO, val); |
| 1049 | if (err) { |
| 1050 | dev_err(phy->u_phy.dev, "Failed to enable PMC AO: %d\n", err); |
| 1051 | return err; |
| 1052 | } |
| 1053 | |
| 1054 | /* detectors starts to work after 10ms */ |
| 1055 | usleep_range(10000, 15000); |
| 1056 | |
| 1057 | return 0; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1058 | } |
| 1059 | |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1060 | static int tegra_usb_phy_init(struct usb_phy *u_phy) |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1061 | { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1062 | struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1063 | unsigned long parent_rate; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1064 | unsigned int i; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1065 | int err; |
| 1066 | |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1067 | if (WARN_ON(phy->freq)) |
| 1068 | return 0; |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1069 | |
| 1070 | err = clk_prepare_enable(phy->pll_u); |
| 1071 | if (err) |
| 1072 | return err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1073 | |
| 1074 | parent_rate = clk_get_rate(clk_get_parent(phy->pll_u)); |
| 1075 | for (i = 0; i < ARRAY_SIZE(tegra_freq_table); i++) { |
| 1076 | if (tegra_freq_table[i].freq == parent_rate) { |
| 1077 | phy->freq = &tegra_freq_table[i]; |
| 1078 | break; |
| 1079 | } |
| 1080 | } |
| 1081 | if (!phy->freq) { |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 1082 | dev_err(phy->u_phy.dev, "Invalid pll_u parent rate %ld\n", |
| 1083 | parent_rate); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1084 | err = -EINVAL; |
Dmitry Osipenko | aecc5af | 2020-01-06 04:34:10 +0300 | [diff] [blame] | 1085 | goto disable_clk; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1086 | } |
| 1087 | |
Dmitry Osipenko | 9df3adc | 2020-01-06 04:34:05 +0300 | [diff] [blame] | 1088 | err = regulator_enable(phy->vbus); |
| 1089 | if (err) { |
| 1090 | dev_err(phy->u_phy.dev, |
| 1091 | "Failed to enable USB VBUS regulator: %d\n", err); |
Dmitry Osipenko | aecc5af | 2020-01-06 04:34:10 +0300 | [diff] [blame] | 1092 | goto disable_clk; |
Mikko Perttunen | f5b8c8b | 2013-07-17 10:37:49 +0300 | [diff] [blame] | 1093 | } |
| 1094 | |
Dmitry Osipenko | 06e60e50 | 2020-01-06 04:34:09 +0300 | [diff] [blame] | 1095 | if (!phy->is_ulpi_phy) { |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1096 | err = utmip_pad_open(phy); |
Dmitry Osipenko | 06e60e50 | 2020-01-06 04:34:09 +0300 | [diff] [blame] | 1097 | if (err) |
Dmitry Osipenko | aecc5af | 2020-01-06 04:34:10 +0300 | [diff] [blame] | 1098 | goto disable_vbus; |
Dmitry Osipenko | 06e60e50 | 2020-01-06 04:34:09 +0300 | [diff] [blame] | 1099 | } |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1100 | |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 1101 | err = tegra_usb_phy_configure_pmc(phy); |
| 1102 | if (err) |
| 1103 | goto close_phy; |
| 1104 | |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1105 | err = tegra_usb_phy_power_on(phy); |
| 1106 | if (err) |
| 1107 | goto close_phy; |
| 1108 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1109 | return 0; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1110 | |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1111 | close_phy: |
| 1112 | if (!phy->is_ulpi_phy) |
| 1113 | utmip_pad_close(phy); |
Dmitry Osipenko | aecc5af | 2020-01-06 04:34:10 +0300 | [diff] [blame] | 1114 | |
| 1115 | disable_vbus: |
| 1116 | regulator_disable(phy->vbus); |
| 1117 | |
| 1118 | disable_clk: |
Prashant Gaikwad | 6a5278d | 2012-06-05 09:59:35 +0530 | [diff] [blame] | 1119 | clk_disable_unprepare(phy->pll_u); |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1120 | |
| 1121 | phy->freq = NULL; |
| 1122 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1123 | return err; |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1124 | } |
| 1125 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1126 | void tegra_usb_phy_preresume(struct usb_phy *u_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1127 | { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1128 | struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); |
Venu Byravarasu | ab137d0 | 2013-01-24 15:57:03 +0530 | [diff] [blame] | 1129 | |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 1130 | if (!phy->is_ulpi_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1131 | utmi_phy_preresume(phy); |
| 1132 | } |
Arnd Bergmann | 4265cbf | 2012-03-02 15:58:42 -0500 | [diff] [blame] | 1133 | EXPORT_SYMBOL_GPL(tegra_usb_phy_preresume); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1134 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1135 | void tegra_usb_phy_postresume(struct usb_phy *u_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1136 | { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1137 | struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); |
Venu Byravarasu | ab137d0 | 2013-01-24 15:57:03 +0530 | [diff] [blame] | 1138 | |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 1139 | if (!phy->is_ulpi_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1140 | utmi_phy_postresume(phy); |
| 1141 | } |
Arnd Bergmann | 4265cbf | 2012-03-02 15:58:42 -0500 | [diff] [blame] | 1142 | EXPORT_SYMBOL_GPL(tegra_usb_phy_postresume); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1143 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1144 | void tegra_ehci_phy_restore_start(struct usb_phy *u_phy, |
| 1145 | enum tegra_usb_phy_port_speed port_speed) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1146 | { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1147 | struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); |
Venu Byravarasu | ab137d0 | 2013-01-24 15:57:03 +0530 | [diff] [blame] | 1148 | |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 1149 | if (!phy->is_ulpi_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1150 | utmi_phy_restore_start(phy, port_speed); |
| 1151 | } |
Arnd Bergmann | 4265cbf | 2012-03-02 15:58:42 -0500 | [diff] [blame] | 1152 | EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_start); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1153 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1154 | void tegra_ehci_phy_restore_end(struct usb_phy *u_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1155 | { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1156 | struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); |
Venu Byravarasu | ab137d0 | 2013-01-24 15:57:03 +0530 | [diff] [blame] | 1157 | |
Venu Byravarasu | 3f9db1a | 2013-01-16 03:30:21 +0000 | [diff] [blame] | 1158 | if (!phy->is_ulpi_phy) |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1159 | utmi_phy_restore_end(phy); |
| 1160 | } |
Arnd Bergmann | 4265cbf | 2012-03-02 15:58:42 -0500 | [diff] [blame] | 1161 | EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_end); |
Benoit Goby | 91525d0 | 2011-03-09 16:28:55 -0800 | [diff] [blame] | 1162 | |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1163 | static int read_utmi_param(struct platform_device *pdev, const char *param, |
| 1164 | u8 *dest) |
| 1165 | { |
| 1166 | u32 value; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1167 | int err; |
| 1168 | |
| 1169 | err = of_property_read_u32(pdev->dev.of_node, param, &value); |
| 1170 | if (err) |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 1171 | dev_err(&pdev->dev, |
| 1172 | "Failed to read USB UTMI parameter %s: %d\n", |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1173 | param, err); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1174 | else |
| 1175 | *dest = value; |
| 1176 | |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1177 | return err; |
| 1178 | } |
| 1179 | |
| 1180 | static int utmi_phy_probe(struct tegra_usb_phy *tegra_phy, |
| 1181 | struct platform_device *pdev) |
| 1182 | { |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1183 | struct tegra_utmip_config *config; |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1184 | struct resource *res; |
| 1185 | int err; |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1186 | |
| 1187 | tegra_phy->is_ulpi_phy = false; |
| 1188 | |
| 1189 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 1190 | if (!res) { |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 1191 | dev_err(&pdev->dev, "Failed to get UTMI pad regs\n"); |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1192 | return -ENXIO; |
| 1193 | } |
| 1194 | |
Dmitry Osipenko | a4a6019 | 2020-02-03 01:42:59 +0300 | [diff] [blame] | 1195 | /* |
| 1196 | * Note that UTMI pad registers are shared by all PHYs, therefore |
| 1197 | * devm_platform_ioremap_resource() can't be used here. |
| 1198 | */ |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1199 | tegra_phy->pad_regs = devm_ioremap(&pdev->dev, res->start, |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1200 | resource_size(res)); |
Chris Ruehl | 851dd02 | 2013-12-04 10:02:44 +0800 | [diff] [blame] | 1201 | if (!tegra_phy->pad_regs) { |
Dmitry Osipenko | f59cd94 | 2018-04-10 01:02:57 +0300 | [diff] [blame] | 1202 | dev_err(&pdev->dev, "Failed to remap UTMI pad regs\n"); |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1203 | return -ENOMEM; |
| 1204 | } |
| 1205 | |
Thierry Reding | 9ce9ec9 | 2014-07-21 13:37:37 +0200 | [diff] [blame] | 1206 | tegra_phy->config = devm_kzalloc(&pdev->dev, sizeof(*config), |
| 1207 | GFP_KERNEL); |
Peter Chen | 01ad32d | 2014-10-14 15:56:13 +0800 | [diff] [blame] | 1208 | if (!tegra_phy->config) |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1209 | return -ENOMEM; |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1210 | |
| 1211 | config = tegra_phy->config; |
| 1212 | |
| 1213 | err = read_utmi_param(pdev, "nvidia,hssync-start-delay", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1214 | &config->hssync_start_delay); |
| 1215 | if (err) |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1216 | return err; |
| 1217 | |
| 1218 | err = read_utmi_param(pdev, "nvidia,elastic-limit", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1219 | &config->elastic_limit); |
| 1220 | if (err) |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1221 | return err; |
| 1222 | |
| 1223 | err = read_utmi_param(pdev, "nvidia,idle-wait-delay", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1224 | &config->idle_wait_delay); |
| 1225 | if (err) |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1226 | return err; |
| 1227 | |
| 1228 | err = read_utmi_param(pdev, "nvidia,term-range-adj", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1229 | &config->term_range_adj); |
| 1230 | if (err) |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1231 | return err; |
| 1232 | |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1233 | err = read_utmi_param(pdev, "nvidia,xcvr-lsfslew", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1234 | &config->xcvr_lsfslew); |
| 1235 | if (err) |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1236 | return err; |
| 1237 | |
| 1238 | err = read_utmi_param(pdev, "nvidia,xcvr-lsrslew", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1239 | &config->xcvr_lsrslew); |
| 1240 | if (err) |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1241 | return err; |
| 1242 | |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 1243 | if (tegra_phy->soc_config->requires_extra_tuning_parameters) { |
| 1244 | err = read_utmi_param(pdev, "nvidia,xcvr-hsslew", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1245 | &config->xcvr_hsslew); |
| 1246 | if (err) |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 1247 | return err; |
| 1248 | |
| 1249 | err = read_utmi_param(pdev, "nvidia,hssquelch-level", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1250 | &config->hssquelch_level); |
| 1251 | if (err) |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 1252 | return err; |
| 1253 | |
| 1254 | err = read_utmi_param(pdev, "nvidia,hsdiscon-level", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1255 | &config->hsdiscon_level); |
| 1256 | if (err) |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 1257 | return err; |
| 1258 | } |
| 1259 | |
| 1260 | config->xcvr_setup_use_fuses = of_property_read_bool( |
| 1261 | pdev->dev.of_node, "nvidia,xcvr-setup-use-fuses"); |
| 1262 | |
| 1263 | if (!config->xcvr_setup_use_fuses) { |
| 1264 | err = read_utmi_param(pdev, "nvidia,xcvr-setup", |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1265 | &config->xcvr_setup); |
| 1266 | if (err) |
Tuomas Tynkkynen | e497a24 | 2013-08-12 16:06:53 +0300 | [diff] [blame] | 1267 | return err; |
| 1268 | } |
| 1269 | |
Mikko Perttunen | 81d5dfe | 2013-07-17 09:31:01 +0300 | [diff] [blame] | 1270 | return 0; |
| 1271 | } |
| 1272 | |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 1273 | static void tegra_usb_phy_put_pmc_device(void *dev) |
| 1274 | { |
| 1275 | put_device(dev); |
| 1276 | } |
| 1277 | |
| 1278 | static int tegra_usb_phy_parse_pmc(struct device *dev, |
| 1279 | struct tegra_usb_phy *phy) |
| 1280 | { |
| 1281 | struct platform_device *pmc_pdev; |
| 1282 | struct of_phandle_args args; |
| 1283 | int err; |
| 1284 | |
| 1285 | err = of_parse_phandle_with_fixed_args(dev->of_node, "nvidia,pmc", |
| 1286 | 1, 0, &args); |
| 1287 | if (err) { |
| 1288 | if (err != -ENOENT) |
| 1289 | return err; |
| 1290 | |
| 1291 | dev_warn_once(dev, "nvidia,pmc is missing, please update your device-tree\n"); |
| 1292 | return 0; |
| 1293 | } |
| 1294 | |
| 1295 | pmc_pdev = of_find_device_by_node(args.np); |
| 1296 | of_node_put(args.np); |
| 1297 | if (!pmc_pdev) |
| 1298 | return -ENODEV; |
| 1299 | |
| 1300 | err = devm_add_action_or_reset(dev, tegra_usb_phy_put_pmc_device, |
| 1301 | &pmc_pdev->dev); |
| 1302 | if (err) |
| 1303 | return err; |
| 1304 | |
| 1305 | if (!platform_get_drvdata(pmc_pdev)) |
| 1306 | return -EPROBE_DEFER; |
| 1307 | |
| 1308 | phy->pmc_regmap = dev_get_regmap(&pmc_pdev->dev, "usb_sleepwalk"); |
| 1309 | if (!phy->pmc_regmap) |
| 1310 | return -EINVAL; |
| 1311 | |
| 1312 | phy->instance = args.args[0]; |
| 1313 | |
| 1314 | return 0; |
| 1315 | } |
| 1316 | |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 1317 | static const struct tegra_phy_soc_config tegra20_soc_config = { |
| 1318 | .utmi_pll_config_in_car_module = false, |
| 1319 | .has_hostpc = false, |
| 1320 | .requires_usbmode_setup = false, |
| 1321 | .requires_extra_tuning_parameters = false, |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 1322 | .requires_pmc_ao_power_up = false, |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 1323 | }; |
| 1324 | |
| 1325 | static const struct tegra_phy_soc_config tegra30_soc_config = { |
| 1326 | .utmi_pll_config_in_car_module = true, |
| 1327 | .has_hostpc = true, |
| 1328 | .requires_usbmode_setup = true, |
| 1329 | .requires_extra_tuning_parameters = true, |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 1330 | .requires_pmc_ao_power_up = true, |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 1331 | }; |
| 1332 | |
Jingoo Han | 0f0520b | 2014-06-18 13:43:50 +0900 | [diff] [blame] | 1333 | static const struct of_device_id tegra_usb_phy_id_table[] = { |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 1334 | { .compatible = "nvidia,tegra30-usb-phy", .data = &tegra30_soc_config }, |
| 1335 | { .compatible = "nvidia,tegra20-usb-phy", .data = &tegra20_soc_config }, |
| 1336 | { }, |
| 1337 | }; |
| 1338 | MODULE_DEVICE_TABLE(of, tegra_usb_phy_id_table); |
| 1339 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1340 | static int tegra_usb_phy_probe(struct platform_device *pdev) |
| 1341 | { |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1342 | struct device_node *np = pdev->dev.of_node; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1343 | struct tegra_usb_phy *tegra_phy; |
Tuomas Tynkkynen | 9fdb07f | 2013-07-25 21:38:08 +0300 | [diff] [blame] | 1344 | enum usb_phy_interface phy_type; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1345 | struct reset_control *reset; |
Dmitry Osipenko | 06e60e50 | 2020-01-06 04:34:09 +0300 | [diff] [blame] | 1346 | struct gpio_desc *gpiod; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1347 | struct resource *res; |
Dmitry Osipenko | 8754174 | 2020-01-06 04:34:07 +0300 | [diff] [blame] | 1348 | struct usb_phy *phy; |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1349 | int err; |
| 1350 | |
| 1351 | tegra_phy = devm_kzalloc(&pdev->dev, sizeof(*tegra_phy), GFP_KERNEL); |
Peter Chen | 01ad32d | 2014-10-14 15:56:13 +0800 | [diff] [blame] | 1352 | if (!tegra_phy) |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1353 | return -ENOMEM; |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1354 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1355 | tegra_phy->soc_config = of_device_get_match_data(&pdev->dev); |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 1356 | tegra_phy->irq = platform_get_irq_optional(pdev, 0); |
Tuomas Tynkkynen | 3e63520 | 2013-08-12 16:06:51 +0300 | [diff] [blame] | 1357 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1358 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1359 | if (!res) { |
| 1360 | dev_err(&pdev->dev, "Failed to get I/O memory\n"); |
| 1361 | return -ENXIO; |
| 1362 | } |
| 1363 | |
Dmitry Osipenko | a4a6019 | 2020-02-03 01:42:59 +0300 | [diff] [blame] | 1364 | /* |
| 1365 | * Note that PHY and USB controller are using shared registers, |
| 1366 | * therefore devm_platform_ioremap_resource() can't be used here. |
| 1367 | */ |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1368 | tegra_phy->regs = devm_ioremap(&pdev->dev, res->start, |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1369 | resource_size(res)); |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1370 | if (!tegra_phy->regs) { |
| 1371 | dev_err(&pdev->dev, "Failed to remap I/O memory\n"); |
| 1372 | return -ENOMEM; |
| 1373 | } |
| 1374 | |
| 1375 | tegra_phy->is_legacy_phy = |
| 1376 | of_property_read_bool(np, "nvidia,has-legacy-mode"); |
| 1377 | |
Tuomas Tynkkynen | 6558d7e | 2013-07-25 21:38:09 +0300 | [diff] [blame] | 1378 | if (of_find_property(np, "dr_mode", NULL)) |
Heikki Krogerus | 06e7114 | 2015-09-21 11:14:34 +0300 | [diff] [blame] | 1379 | tegra_phy->mode = usb_get_dr_mode(&pdev->dev); |
Tuomas Tynkkynen | 6558d7e | 2013-07-25 21:38:09 +0300 | [diff] [blame] | 1380 | else |
| 1381 | tegra_phy->mode = USB_DR_MODE_HOST; |
| 1382 | |
| 1383 | if (tegra_phy->mode == USB_DR_MODE_UNKNOWN) { |
| 1384 | dev_err(&pdev->dev, "dr_mode is invalid\n"); |
| 1385 | return -EINVAL; |
| 1386 | } |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1387 | |
Mikko Perttunen | f5b8c8b | 2013-07-17 10:37:49 +0300 | [diff] [blame] | 1388 | /* On some boards, the VBUS regulator doesn't need to be controlled */ |
Dmitry Osipenko | 9df3adc | 2020-01-06 04:34:05 +0300 | [diff] [blame] | 1389 | tegra_phy->vbus = devm_regulator_get(&pdev->dev, "vbus"); |
| 1390 | if (IS_ERR(tegra_phy->vbus)) |
| 1391 | return PTR_ERR(tegra_phy->vbus); |
Mikko Perttunen | f5b8c8b | 2013-07-17 10:37:49 +0300 | [diff] [blame] | 1392 | |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1393 | tegra_phy->pll_u = devm_clk_get(&pdev->dev, "pll_u"); |
| 1394 | err = PTR_ERR_OR_ZERO(tegra_phy->pll_u); |
| 1395 | if (err) { |
| 1396 | 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] | 1397 | return err; |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1398 | } |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1399 | |
Dmitry Osipenko | c1baf6c | 2021-09-12 21:17:15 +0300 | [diff] [blame] | 1400 | err = tegra_usb_phy_parse_pmc(&pdev->dev, tegra_phy); |
| 1401 | if (err) { |
| 1402 | dev_err_probe(&pdev->dev, err, "Failed to get PMC regmap\n"); |
| 1403 | return err; |
| 1404 | } |
| 1405 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1406 | phy_type = of_usb_get_phy_mode(np); |
| 1407 | switch (phy_type) { |
| 1408 | case USBPHY_INTERFACE_MODE_UTMI: |
| 1409 | err = utmi_phy_probe(tegra_phy, pdev); |
| 1410 | if (err) |
| 1411 | return err; |
| 1412 | |
| 1413 | tegra_phy->pad_clk = devm_clk_get(&pdev->dev, "utmi-pads"); |
| 1414 | err = PTR_ERR_OR_ZERO(tegra_phy->pad_clk); |
| 1415 | if (err) { |
| 1416 | dev_err(&pdev->dev, |
| 1417 | "Failed to get UTMIP pad clock: %d\n", err); |
| 1418 | return err; |
| 1419 | } |
| 1420 | |
| 1421 | reset = devm_reset_control_get_optional_shared(&pdev->dev, |
| 1422 | "utmi-pads"); |
| 1423 | err = PTR_ERR_OR_ZERO(reset); |
| 1424 | if (err) { |
| 1425 | dev_err(&pdev->dev, |
| 1426 | "Failed to get UTMI-pads reset: %d\n", err); |
| 1427 | return err; |
| 1428 | } |
| 1429 | tegra_phy->pad_rst = reset; |
| 1430 | break; |
| 1431 | |
| 1432 | case USBPHY_INTERFACE_MODE_ULPI: |
| 1433 | tegra_phy->is_ulpi_phy = true; |
| 1434 | |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1435 | tegra_phy->clk = devm_clk_get(&pdev->dev, "ulpi-link"); |
| 1436 | err = PTR_ERR_OR_ZERO(tegra_phy->clk); |
| 1437 | if (err) { |
| 1438 | dev_err(&pdev->dev, |
| 1439 | "Failed to get ULPI clock: %d\n", err); |
| 1440 | return err; |
| 1441 | } |
| 1442 | |
Dmitry Osipenko | 06e60e50 | 2020-01-06 04:34:09 +0300 | [diff] [blame] | 1443 | gpiod = devm_gpiod_get_from_of_node(&pdev->dev, np, |
| 1444 | "nvidia,phy-reset-gpio", |
| 1445 | 0, GPIOD_OUT_HIGH, |
| 1446 | "ulpi_phy_reset_b"); |
| 1447 | err = PTR_ERR_OR_ZERO(gpiod); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1448 | if (err) { |
Dmitry Osipenko | 06e60e50 | 2020-01-06 04:34:09 +0300 | [diff] [blame] | 1449 | dev_err(&pdev->dev, |
| 1450 | "Request failed for reset GPIO: %d\n", err); |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1451 | return err; |
| 1452 | } |
Dmitry Osipenko | 06e60e50 | 2020-01-06 04:34:09 +0300 | [diff] [blame] | 1453 | tegra_phy->reset_gpio = gpiod; |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1454 | |
Dmitry Osipenko | 8754174 | 2020-01-06 04:34:07 +0300 | [diff] [blame] | 1455 | phy = devm_otg_ulpi_create(&pdev->dev, |
| 1456 | &ulpi_viewport_access_ops, 0); |
| 1457 | if (!phy) { |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1458 | dev_err(&pdev->dev, "Failed to create ULPI OTG\n"); |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1459 | return -ENOMEM; |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1460 | } |
| 1461 | |
Dmitry Osipenko | 8754174 | 2020-01-06 04:34:07 +0300 | [diff] [blame] | 1462 | tegra_phy->ulpi = phy; |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1463 | tegra_phy->ulpi->io_priv = tegra_phy->regs + ULPI_VIEWPORT; |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1464 | break; |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1465 | |
Dmitry Osipenko | 545592e | 2020-01-06 04:34:02 +0300 | [diff] [blame] | 1466 | default: |
| 1467 | dev_err(&pdev->dev, "phy_type %u is invalid or unsupported\n", |
| 1468 | phy_type); |
| 1469 | return -EINVAL; |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | tegra_phy->u_phy.dev = &pdev->dev; |
| 1473 | tegra_phy->u_phy.init = tegra_usb_phy_init; |
| 1474 | tegra_phy->u_phy.shutdown = tegra_usb_phy_shutdown; |
Dmitry Osipenko | 3519200 | 2020-12-18 15:02:39 +0300 | [diff] [blame] | 1475 | tegra_phy->u_phy.set_wakeup = tegra_usb_phy_set_wakeup; |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1476 | tegra_phy->u_phy.set_suspend = tegra_usb_phy_set_suspend; |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1477 | |
Libo Chen | 72031b5 | 2013-08-30 11:23:32 +0800 | [diff] [blame] | 1478 | platform_set_drvdata(pdev, tegra_phy); |
Tuomas Tynkkynen | 0ee5b4a | 2013-07-25 21:38:05 +0300 | [diff] [blame] | 1479 | |
Tang Bin | d410912 | 2020-05-28 19:47:17 +0800 | [diff] [blame] | 1480 | return usb_add_phy_dev(&tegra_phy->u_phy); |
Tuomas Tynkkynen | 0ee5b4a | 2013-07-25 21:38:05 +0300 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | static int tegra_usb_phy_remove(struct platform_device *pdev) |
| 1484 | { |
| 1485 | struct tegra_usb_phy *tegra_phy = platform_get_drvdata(pdev); |
| 1486 | |
| 1487 | usb_remove_phy(&tegra_phy->u_phy); |
Dmitry Osipenko | 5dcdafd | 2020-01-06 04:34:01 +0300 | [diff] [blame] | 1488 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1489 | return 0; |
| 1490 | } |
| 1491 | |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1492 | static struct platform_driver tegra_usb_phy_driver = { |
| 1493 | .probe = tegra_usb_phy_probe, |
Tuomas Tynkkynen | 0ee5b4a | 2013-07-25 21:38:05 +0300 | [diff] [blame] | 1494 | .remove = tegra_usb_phy_remove, |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1495 | .driver = { |
| 1496 | .name = "tegra-phy", |
Sachin Kamat | 78723920 | 2013-09-30 09:44:47 +0530 | [diff] [blame] | 1497 | .of_match_table = tegra_usb_phy_id_table, |
Venu Byravarasu | 2d22b42 | 2013-05-16 19:43:02 +0530 | [diff] [blame] | 1498 | }, |
| 1499 | }; |
| 1500 | module_platform_driver(tegra_usb_phy_driver); |
| 1501 | |
Stephen Warren | 587376a | 2013-06-13 11:24:08 -0600 | [diff] [blame] | 1502 | MODULE_DESCRIPTION("Tegra USB PHY driver"); |
| 1503 | MODULE_LICENSE("GPL v2"); |