1ef2ee5d0SMichal Meloun /*- 2ef2ee5d0SMichal Meloun * Copyright (c) 2016 Michal Meloun <mmel@FreeBSD.org> 3ef2ee5d0SMichal Meloun * All rights reserved. 4ef2ee5d0SMichal Meloun * 5ef2ee5d0SMichal Meloun * Redistribution and use in source and binary forms, with or without 6ef2ee5d0SMichal Meloun * modification, are permitted provided that the following conditions 7ef2ee5d0SMichal Meloun * are met: 8ef2ee5d0SMichal Meloun * 1. Redistributions of source code must retain the above copyright 9ef2ee5d0SMichal Meloun * notice, this list of conditions and the following disclaimer. 10ef2ee5d0SMichal Meloun * 2. Redistributions in binary form must reproduce the above copyright 11ef2ee5d0SMichal Meloun * notice, this list of conditions and the following disclaimer in the 12ef2ee5d0SMichal Meloun * documentation and/or other materials provided with the distribution. 13ef2ee5d0SMichal Meloun * 14ef2ee5d0SMichal Meloun * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15ef2ee5d0SMichal Meloun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16ef2ee5d0SMichal Meloun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17ef2ee5d0SMichal Meloun * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18ef2ee5d0SMichal Meloun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19ef2ee5d0SMichal Meloun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20ef2ee5d0SMichal Meloun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21ef2ee5d0SMichal Meloun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22ef2ee5d0SMichal Meloun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23ef2ee5d0SMichal Meloun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24ef2ee5d0SMichal Meloun * SUCH DAMAGE. 25ef2ee5d0SMichal Meloun */ 26ef2ee5d0SMichal Meloun 27ef2ee5d0SMichal Meloun #include <sys/cdefs.h> 28ef2ee5d0SMichal Meloun __FBSDID("$FreeBSD$"); 29ef2ee5d0SMichal Meloun 30ef2ee5d0SMichal Meloun /* 31ef2ee5d0SMichal Meloun * USB phy driver for Tegra SoCs. 32ef2ee5d0SMichal Meloun */ 33ef2ee5d0SMichal Meloun #include <sys/param.h> 34ef2ee5d0SMichal Meloun #include <sys/systm.h> 35ef2ee5d0SMichal Meloun #include <sys/bus.h> 36ef2ee5d0SMichal Meloun #include <sys/kernel.h> 37ef2ee5d0SMichal Meloun #include <sys/module.h> 38ef2ee5d0SMichal Meloun #include <sys/malloc.h> 39ef2ee5d0SMichal Meloun #include <sys/rman.h> 40ef2ee5d0SMichal Meloun 41ef2ee5d0SMichal Meloun #include <machine/bus.h> 42ef2ee5d0SMichal Meloun 43ef2ee5d0SMichal Meloun #include <dev/extres/clk/clk.h> 44ef2ee5d0SMichal Meloun #include <dev/extres/hwreset/hwreset.h> 45ef2ee5d0SMichal Meloun #include <dev/extres/phy/phy.h> 46ef2ee5d0SMichal Meloun #include <dev/extres/regulator/regulator.h> 47ef2ee5d0SMichal Meloun #include <dev/fdt/fdt_pinctrl.h> 48ef2ee5d0SMichal Meloun #include <dev/ofw/openfirm.h> 49ef2ee5d0SMichal Meloun #include <dev/ofw/ofw_bus.h> 50ef2ee5d0SMichal Meloun #include <dev/ofw/ofw_bus_subr.h> 51ef2ee5d0SMichal Meloun 52f8759facSMichal Meloun #include "phynode_if.h" 53ef2ee5d0SMichal Meloun 54ef2ee5d0SMichal Meloun #define CTRL_ICUSB_CTRL 0x15c 55ef2ee5d0SMichal Meloun #define ICUSB_CTR_IC_ENB1 (1 << 3) 56ef2ee5d0SMichal Meloun 57ef2ee5d0SMichal Meloun #define CTRL_USB_USBMODE 0x1f8 58ef2ee5d0SMichal Meloun #define USB_USBMODE_MASK (3 << 0) 59ef2ee5d0SMichal Meloun #define USB_USBMODE_HOST (3 << 0) 60ef2ee5d0SMichal Meloun #define USB_USBMODE_DEVICE (2 << 0) 61ef2ee5d0SMichal Meloun 62ef2ee5d0SMichal Meloun #define CTRL_USB_HOSTPC1_DEVLC 0x1b4 63ef2ee5d0SMichal Meloun #define USB_HOSTPC1_DEVLC_PTS(x) (((x) & 0x7) << 29) 64ef2ee5d0SMichal Meloun #define USB_HOSTPC1_DEVLC_STS (1 << 28) 65ef2ee5d0SMichal Meloun #define USB_HOSTPC1_DEVLC_PHCD (1 << 22) 66ef2ee5d0SMichal Meloun 67ef2ee5d0SMichal Meloun #define IF_USB_SUSP_CTRL 0x400 68ef2ee5d0SMichal Meloun #define FAST_WAKEUP_RESP (1 << 26) 69ef2ee5d0SMichal Meloun #define UTMIP_SUSPL1_SET (1 << 25) 70ef2ee5d0SMichal Meloun #define USB_WAKEUP_DEBOUNCE_COUNT(x) (((x) & 0x7) << 16) 71ef2ee5d0SMichal Meloun #define USB_SUSP_SET (1 << 14) 72ef2ee5d0SMichal Meloun #define UTMIP_PHY_ENB (1 << 12) 73ef2ee5d0SMichal Meloun #define UTMIP_RESET (1 << 11) 74ef2ee5d0SMichal Meloun #define USB_SUSP_POL (1 << 10) 75ef2ee5d0SMichal Meloun #define USB_PHY_CLK_VALID_INT_ENB (1 << 9) 76ef2ee5d0SMichal Meloun #define USB_PHY_CLK_VALID_INT_STS (1 << 8) 77ef2ee5d0SMichal Meloun #define USB_PHY_CLK_VALID (1 << 7) 78ef2ee5d0SMichal Meloun #define USB_CLKEN (1 << 6) 79ef2ee5d0SMichal Meloun #define USB_SUSP_CLR (1 << 5) 80ef2ee5d0SMichal Meloun #define USB_WAKE_ON_DISCON_EN_DEV (1 << 4) 81ef2ee5d0SMichal Meloun #define USB_WAKE_ON_CNNT_EN_DEV (1 << 3) 82ef2ee5d0SMichal Meloun #define USB_WAKE_ON_RESUME_EN (1 << 2) 83ef2ee5d0SMichal Meloun #define USB_WAKEUP_INT_ENB (1 << 1) 84ef2ee5d0SMichal Meloun #define USB_WAKEUP_INT_STS (1 << 0) 85ef2ee5d0SMichal Meloun 86ef2ee5d0SMichal Meloun #define IF_USB_PHY_VBUS_SENSORS 0x404 87ef2ee5d0SMichal Meloun #define B_SESS_END_SW_VALUE (1 << 4) 88ef2ee5d0SMichal Meloun #define B_SESS_END_SW_EN (1 << 3) 89ef2ee5d0SMichal Meloun 90ef2ee5d0SMichal Meloun #define UTMIP_XCVR_CFG0 0x808 91ef2ee5d0SMichal Meloun #define UTMIP_XCVR_HSSLEW_MSB(x) ((((x) & 0x1fc) >> 2) << 25) 92ef2ee5d0SMichal Meloun #define UTMIP_XCVR_SETUP_MSB(x) ((((x) & 0x70) >> 4) << 22) 93ef2ee5d0SMichal Meloun #define UTMIP_XCVR_LSBIAS_SEL (1 << 21) 94ef2ee5d0SMichal Meloun #define UTMIP_XCVR_DISCON_METHOD (1 << 20) 95ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PDZI_POWERUP (1 << 19) 96ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PDZI_POWERDOWN (1 << 18) 97ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PD2_POWERUP (1 << 17) 98ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PD2_POWERDOWN (1 << 16) 99ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PD_POWERUP (1 << 15) 100ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PD_POWERDOWN (1 << 14) 101ef2ee5d0SMichal Meloun #define UTMIP_XCVR_TERMEN (1 << 13) 102ef2ee5d0SMichal Meloun #define UTMIP_XCVR_HSLOOPBACK (1 << 12) 103ef2ee5d0SMichal Meloun #define UTMIP_XCVR_LSFSLEW(x) (((x) & 0x3) << 10) 104ef2ee5d0SMichal Meloun #define UTMIP_XCVR_LSRSLEW(x) (((x) & 0x3) << 8) 105ef2ee5d0SMichal Meloun #define UTMIP_XCVR_FSSLEW(x) (((x) & 0x3) << 6) 106ef2ee5d0SMichal Meloun #define UTMIP_XCVR_HSSLEW(x) (((x) & 0x3) << 4) 107ef2ee5d0SMichal Meloun #define UTMIP_XCVR_SETUP(x) (((x) & 0xf) << 0) 108ef2ee5d0SMichal Meloun 109ef2ee5d0SMichal Meloun #define UTMIP_BIAS_CFG0 0x80C 110ef2ee5d0SMichal Meloun #define UTMIP_IDDIG_C_VAL (1 << 30) 111ef2ee5d0SMichal Meloun #define UTMIP_IDDIG_C_SEL (1 << 29) 112ef2ee5d0SMichal Meloun #define UTMIP_IDDIG_B_VAL (1 << 28) 113ef2ee5d0SMichal Meloun #define UTMIP_IDDIG_B_SEL (1 << 27) 114ef2ee5d0SMichal Meloun #define UTMIP_IDDIG_A_VAL (1 << 26) 115ef2ee5d0SMichal Meloun #define UTMIP_IDDIG_A_SEL (1 << 25) 116ef2ee5d0SMichal Meloun #define UTMIP_HSDISCON_LEVEL_MSB(x) ((((x) & 0x4) >> 2) << 24) 117ef2ee5d0SMichal Meloun #define UTMIP_IDPD_VAL (1 << 23) 118ef2ee5d0SMichal Meloun #define UTMIP_IDPD_SEL (1 << 22) 119ef2ee5d0SMichal Meloun #define UTMIP_IDDIG_VAL (1 << 21) 120ef2ee5d0SMichal Meloun #define UTMIP_IDDIG_SEL (1 << 20) 121ef2ee5d0SMichal Meloun #define UTMIP_GPI_VAL (1 << 19) 122ef2ee5d0SMichal Meloun #define UTMIP_GPI_SEL (1 << 18) 123ef2ee5d0SMichal Meloun #define UTMIP_ACTIVE_TERM_OFFSET(x) (((x) & 0x7) << 15) 124ef2ee5d0SMichal Meloun #define UTMIP_ACTIVE_PULLUP_OFFSET(x) (((x) & 0x7) << 12) 125ef2ee5d0SMichal Meloun #define UTMIP_OTGPD (1 << 11) 126ef2ee5d0SMichal Meloun #define UTMIP_BIASPD (1 << 10) 127ef2ee5d0SMichal Meloun #define UTMIP_VBUS_LEVEL_LEVEL(x) (((x) & 0x3) << 8) 128ef2ee5d0SMichal Meloun #define UTMIP_SESS_LEVEL_LEVEL(x) (((x) & 0x3) << 6) 129ef2ee5d0SMichal Meloun #define UTMIP_HSCHIRP_LEVEL(x) (((x) & 0x3) << 4) 130ef2ee5d0SMichal Meloun #define UTMIP_HSDISCON_LEVEL(x) (((x) & 0x3) << 2) 131ef2ee5d0SMichal Meloun #define UTMIP_HSSQUELCH_LEVEL(x) (((x) & 0x3) << 0) 132ef2ee5d0SMichal Meloun 133ef2ee5d0SMichal Meloun #define UTMIP_HSRX_CFG0 0x810 134ef2ee5d0SMichal Meloun #define UTMIP_KEEP_PATT_ON_ACTIVE(x) (((x) & 0x3) << 30) 135ef2ee5d0SMichal Meloun #define UTMIP_ALLOW_CONSEC_UPDN (1 << 29) 136ef2ee5d0SMichal Meloun #define UTMIP_REALIGN_ON_NEW_PKT (1 << 28) 137ef2ee5d0SMichal Meloun #define UTMIP_PCOUNT_UPDN_DIV(x) (((x) & 0xf) << 24) 138ef2ee5d0SMichal Meloun #define UTMIP_SQUELCH_EOP_DLY(x) (((x) & 0x7) << 21) 139ef2ee5d0SMichal Meloun #define UTMIP_NO_STRIPPING (1 << 20) 140ef2ee5d0SMichal Meloun #define UTMIP_IDLE_WAIT(x) (((x) & 0x1f) << 15) 141ef2ee5d0SMichal Meloun #define UTMIP_ELASTIC_LIMIT(x) (((x) & 0x1f) << 10) 142ef2ee5d0SMichal Meloun #define UTMIP_ELASTIC_OVERRUN_DISABLE (1 << 9) 143ef2ee5d0SMichal Meloun #define UTMIP_ELASTIC_UNDERRUN_DISABLE (1 << 8) 144ef2ee5d0SMichal Meloun #define UTMIP_PASS_CHIRP (1 << 7) 145ef2ee5d0SMichal Meloun #define UTMIP_PASS_FEEDBACK (1 << 6) 146ef2ee5d0SMichal Meloun #define UTMIP_PCOUNT_INERTIA(x) (((x) & 0x3) << 4) 147ef2ee5d0SMichal Meloun #define UTMIP_PHASE_ADJUST(x) (((x) & 0x3) << 2) 148ef2ee5d0SMichal Meloun #define UTMIP_THREE_SYNCBITS (1 << 1) 149ef2ee5d0SMichal Meloun #define UTMIP_USE4SYNC_TRAN (1 << 0) 150ef2ee5d0SMichal Meloun 151ef2ee5d0SMichal Meloun #define UTMIP_HSRX_CFG1 0x814 152ef2ee5d0SMichal Meloun #define UTMIP_HS_SYNC_START_DLY(x) (((x) & 0x1F) << 1) 153ef2ee5d0SMichal Meloun #define UTMIP_HS_ALLOW_KEEP_ALIVE (1 << 0) 154ef2ee5d0SMichal Meloun 155ef2ee5d0SMichal Meloun #define UTMIP_TX_CFG0 0x820 156ef2ee5d0SMichal Meloun #define UTMIP_FS_PREAMBLE_J (1 << 19) 157ef2ee5d0SMichal Meloun #define UTMIP_FS_POSTAMBLE_OUTPUT_ENABLE (1 << 18) 158ef2ee5d0SMichal Meloun #define UTMIP_FS_PREAMBLE_OUTPUT_ENABLE (1 << 17) 159ef2ee5d0SMichal Meloun #define UTMIP_FSLS_ALLOW_SOP_TX_STUFF_ERR (1 << 16) 160ef2ee5d0SMichal Meloun #define UTMIP_HS_READY_WAIT_FOR_VALID (1 << 15) 161ef2ee5d0SMichal Meloun #define UTMIP_HS_TX_IPG_DLY(x) (((x) & 0x1f) << 10) 162ef2ee5d0SMichal Meloun #define UTMIP_HS_DISCON_EOP_ONLY (1 << 9) 163ef2ee5d0SMichal Meloun #define UTMIP_HS_DISCON_DISABLE (1 << 8) 164ef2ee5d0SMichal Meloun #define UTMIP_HS_POSTAMBLE_OUTPUT_ENABLE (1 << 7) 165ef2ee5d0SMichal Meloun #define UTMIP_HS_PREAMBLE_OUTPUT_ENABLE (1 << 6) 166ef2ee5d0SMichal Meloun #define UTMIP_SIE_RESUME_ON_LINESTATE (1 << 5) 167ef2ee5d0SMichal Meloun #define UTMIP_SOF_ON_NO_STUFF (1 << 4) 168ef2ee5d0SMichal Meloun #define UTMIP_SOF_ON_NO_ENCODE (1 << 3) 169ef2ee5d0SMichal Meloun #define UTMIP_NO_STUFFING (1 << 2) 170ef2ee5d0SMichal Meloun #define UTMIP_NO_ENCODING (1 << 1) 171ef2ee5d0SMichal Meloun #define UTMIP_NO_SYNC_NO_EOP (1 << 0) 172ef2ee5d0SMichal Meloun 173ef2ee5d0SMichal Meloun #define UTMIP_MISC_CFG0 0x824 174ef2ee5d0SMichal Meloun #define UTMIP_DPDM_OBSERVE_SEL(x) (((x) & 0xf) << 27) 175ef2ee5d0SMichal Meloun #define UTMIP_DPDM_OBSERVE (1 << 26) 176ef2ee5d0SMichal Meloun #define UTMIP_KEEP_XCVR_PD_ON_SOFT_DISCON (1 << 25) 177ef2ee5d0SMichal Meloun #define UTMIP_ALLOW_LS_ON_SOFT_DISCON (1 << 24) 178ef2ee5d0SMichal Meloun #define UTMIP_FORCE_FS_DISABLE_ON_DEV_CHIRP (1 << 23) 179ef2ee5d0SMichal Meloun #define UTMIP_SUSPEND_EXIT_ON_EDGE (1 << 22) 180ef2ee5d0SMichal Meloun #define UTMIP_LS_TO_FS_SKIP_4MS (1 << 21) 181ef2ee5d0SMichal Meloun #define UTMIP_INJECT_ERROR_TYPE(x) (((x) & 0x3) << 19) 182ef2ee5d0SMichal Meloun #define UTMIP_FORCE_HS_CLOCK_ON (1 << 18) 183ef2ee5d0SMichal Meloun #define UTMIP_DISABLE_HS_TERM (1 << 17) 184ef2ee5d0SMichal Meloun #define UTMIP_FORCE_HS_TERM (1 << 16) 185ef2ee5d0SMichal Meloun #define UTMIP_DISABLE_PULLUP_DP (1 << 15) 186ef2ee5d0SMichal Meloun #define UTMIP_DISABLE_PULLUP_DM (1 << 14) 187ef2ee5d0SMichal Meloun #define UTMIP_DISABLE_PULLDN_DP (1 << 13) 188ef2ee5d0SMichal Meloun #define UTMIP_DISABLE_PULLDN_DM (1 << 12) 189ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PULLUP_DP (1 << 11) 190ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PULLUP_DM (1 << 10) 191ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PULLDN_DP (1 << 9) 192ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PULLDN_DM (1 << 8) 193ef2ee5d0SMichal Meloun #define UTMIP_STABLE_COUNT(x) (((x) & 0x7) << 5) 194ef2ee5d0SMichal Meloun #define UTMIP_STABLE_ALL (1 << 4) 195ef2ee5d0SMichal Meloun #define UTMIP_NO_FREE_ON_SUSPEND (1 << 3) 196ef2ee5d0SMichal Meloun #define UTMIP_NEVER_FREE_RUNNING_TERMS (1 << 2) 197ef2ee5d0SMichal Meloun #define UTMIP_ALWAYS_FREE_RUNNING_TERMS (1 << 1) 198ef2ee5d0SMichal Meloun #define UTMIP_COMB_TERMS (1 << 0) 199ef2ee5d0SMichal Meloun 200ef2ee5d0SMichal Meloun #define UTMIP_MISC_CFG1 0x828 201ef2ee5d0SMichal Meloun #define UTMIP_PHY_XTAL_CLOCKEN (1 << 30) 202ef2ee5d0SMichal Meloun 203ef2ee5d0SMichal Meloun #define UTMIP_DEBOUNCE_CFG0 0x82C 204ef2ee5d0SMichal Meloun #define UTMIP_BIAS_DEBOUNCE_B(x) (((x) & 0xffff) << 16) 205ef2ee5d0SMichal Meloun #define UTMIP_BIAS_DEBOUNCE_A(x) (((x) & 0xffff) << 0) 206ef2ee5d0SMichal Meloun 207ef2ee5d0SMichal Meloun #define UTMIP_BAT_CHRG_CFG0 0x830 208ef2ee5d0SMichal Meloun #define UTMIP_CHRG_DEBOUNCE_TIMESCALE(x) (((x) & 0x1f) << 8) 209ef2ee5d0SMichal Meloun #define UTMIP_OP_I_SRC_ENG (1 << 5) 210ef2ee5d0SMichal Meloun #define UTMIP_ON_SRC_ENG (1 << 4) 211ef2ee5d0SMichal Meloun #define UTMIP_OP_SRC_ENG (1 << 3) 212ef2ee5d0SMichal Meloun #define UTMIP_ON_SINK_ENG (1 << 2) 213ef2ee5d0SMichal Meloun #define UTMIP_OP_SINK_ENG (1 << 1) 214ef2ee5d0SMichal Meloun #define UTMIP_PD_CHRG (1 << 0) 215ef2ee5d0SMichal Meloun 216ef2ee5d0SMichal Meloun #define UTMIP_SPARE_CFG0 0x834 217ef2ee5d0SMichal Meloun #define FUSE_HS_IREF_CAP_CFG (1 << 7) 218ef2ee5d0SMichal Meloun #define FUSE_HS_SQUELCH_LEVEL (1 << 6) 219ef2ee5d0SMichal Meloun #define FUSE_SPARE (1 << 5) 220ef2ee5d0SMichal Meloun #define FUSE_TERM_RANGE_ADJ_SEL (1 << 4) 221ef2ee5d0SMichal Meloun #define FUSE_SETUP_SEL (1 << 3) 222ef2ee5d0SMichal Meloun #define HS_RX_LATE_SQUELCH (1 << 2) 223ef2ee5d0SMichal Meloun #define HS_RX_FLUSH_ALAP (1 << 1) 224ef2ee5d0SMichal Meloun #define HS_RX_IPG_ERROR_ENABLE (1 << 0) 225ef2ee5d0SMichal Meloun 226ef2ee5d0SMichal Meloun #define UTMIP_XCVR_CFG1 0x838 227ef2ee5d0SMichal Meloun #define UTMIP_XCVR_RPU_RANGE_ADJ(x) (((x) & 0x3) << 26) 228ef2ee5d0SMichal Meloun #define UTMIP_XCVR_HS_IREF_CAP(x) (((x) & 0x3) << 24) 229ef2ee5d0SMichal Meloun #define UTMIP_XCVR_SPARE(x) (((x) & 0x3) << 22) 230ef2ee5d0SMichal Meloun #define UTMIP_XCVR_TERM_RANGE_ADJ(x) (((x) & 0xf) << 18) 231ef2ee5d0SMichal Meloun #define UTMIP_RCTRL_SW_SET (1 << 17) 232ef2ee5d0SMichal Meloun #define UTMIP_RCTRL_SW_VAL(x) (((x) & 0x1f) << 12) 233ef2ee5d0SMichal Meloun #define UTMIP_TCTRL_SW_SET (1 << 11) 234ef2ee5d0SMichal Meloun #define UTMIP_TCTRL_SW_VAL(x) (((x) & 0x1f) << 6) 235ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PDDR_POWERUP (1 << 5) 236ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PDDR_POWERDOWN (1 << 4) 237ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PDCHRP_POWERUP (1 << 3) 238ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PDCHRP_POWERDOWN (1 << 2) 239ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PDDISC_POWERUP (1 << 1) 240ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PDDISC_POWERDOWN (1 << 0) 241ef2ee5d0SMichal Meloun 242ef2ee5d0SMichal Meloun #define UTMIP_BIAS_CFG1 0x83c 243ef2ee5d0SMichal Meloun #define UTMIP_BIAS_DEBOUNCE_TIMESCALE(x) (((x) & 0x3f) << 8) 244ef2ee5d0SMichal Meloun #define UTMIP_BIAS_PDTRK_COUNT(x) (((x) & 0x1f) << 3) 245ef2ee5d0SMichal Meloun #define UTMIP_VBUS_WAKEUP_POWERDOWN (1 << 2) 246ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PDTRK_POWERUP (1 << 1) 247ef2ee5d0SMichal Meloun #define UTMIP_FORCE_PDTRK_POWERDOWN (1 << 0) 248ef2ee5d0SMichal Meloun 249ef2ee5d0SMichal Meloun static int usbpby_enable_cnt; 250ef2ee5d0SMichal Meloun 251ef2ee5d0SMichal Meloun enum usb_ifc_type { 252ef2ee5d0SMichal Meloun USB_IFC_TYPE_UNKNOWN = 0, 253ef2ee5d0SMichal Meloun USB_IFC_TYPE_UTMI, 254ef2ee5d0SMichal Meloun USB_IFC_TYPE_ULPI 255ef2ee5d0SMichal Meloun }; 256ef2ee5d0SMichal Meloun 257ef2ee5d0SMichal Meloun enum usb_dr_mode { 258ef2ee5d0SMichal Meloun USB_DR_MODE_UNKNOWN = 0, 259ef2ee5d0SMichal Meloun USB_DR_MODE_DEVICE, 260ef2ee5d0SMichal Meloun USB_DR_MODE_HOST, 261ef2ee5d0SMichal Meloun USB_DR_MODE_OTG 262ef2ee5d0SMichal Meloun }; 263ef2ee5d0SMichal Meloun 264ef2ee5d0SMichal Meloun struct usbphy_softc { 265ef2ee5d0SMichal Meloun device_t dev; 266ef2ee5d0SMichal Meloun struct resource *mem_res; 267ef2ee5d0SMichal Meloun struct resource *pads_res; 268ef2ee5d0SMichal Meloun clk_t clk_reg; 269ef2ee5d0SMichal Meloun clk_t clk_pads; 270ef2ee5d0SMichal Meloun clk_t clk_pllu; 271ef2ee5d0SMichal Meloun regulator_t supply_vbus; 272ef2ee5d0SMichal Meloun hwreset_t reset_usb; 273ef2ee5d0SMichal Meloun hwreset_t reset_pads; 274ef2ee5d0SMichal Meloun enum usb_ifc_type ifc_type; 275ef2ee5d0SMichal Meloun enum usb_dr_mode dr_mode; 276ef2ee5d0SMichal Meloun bool have_utmi_regs; 277ef2ee5d0SMichal Meloun 278ef2ee5d0SMichal Meloun /* UTMI params */ 279ef2ee5d0SMichal Meloun int hssync_start_delay; 280ef2ee5d0SMichal Meloun int elastic_limit; 281ef2ee5d0SMichal Meloun int idle_wait_delay; 282ef2ee5d0SMichal Meloun int term_range_adj; 283ef2ee5d0SMichal Meloun int xcvr_lsfslew; 284ef2ee5d0SMichal Meloun int xcvr_lsrslew; 285ef2ee5d0SMichal Meloun int xcvr_hsslew; 286ef2ee5d0SMichal Meloun int hssquelch_level; 287ef2ee5d0SMichal Meloun int hsdiscon_level; 288ef2ee5d0SMichal Meloun int xcvr_setup; 289ef2ee5d0SMichal Meloun int xcvr_setup_use_fuses; 290ef2ee5d0SMichal Meloun }; 291ef2ee5d0SMichal Meloun 292ef2ee5d0SMichal Meloun static struct ofw_compat_data compat_data[] = { 293b9cbd68dSMichal Meloun {"nvidia,tegra210-usb-phy", 1}, 294ef2ee5d0SMichal Meloun {"nvidia,tegra30-usb-phy", 1}, 295ef2ee5d0SMichal Meloun {NULL, 0}, 296ef2ee5d0SMichal Meloun }; 297ef2ee5d0SMichal Meloun 298f8759facSMichal Meloun /* Phy controller class and methods. */ 299f8759facSMichal Meloun static int usbphy_phy_enable(struct phynode *phy, bool enable); 300f8759facSMichal Meloun static phynode_method_t usbphy_phynode_methods[] = { 301f8759facSMichal Meloun PHYNODEMETHOD(phynode_enable, usbphy_phy_enable), 302f8759facSMichal Meloun 303f8759facSMichal Meloun PHYNODEMETHOD_END 304f8759facSMichal Meloun }; 305f8759facSMichal Meloun DEFINE_CLASS_1(usbphy_phynode, usbphy_phynode_class, usbphy_phynode_methods, 306f8759facSMichal Meloun 0, phynode_class); 307f8759facSMichal Meloun 308ef2ee5d0SMichal Meloun #define RD4(sc, offs) \ 309ef2ee5d0SMichal Meloun bus_read_4(sc->mem_res, offs) 310ef2ee5d0SMichal Meloun 311ef2ee5d0SMichal Meloun #define WR4(sc, offs, val) \ 312ef2ee5d0SMichal Meloun bus_write_4(sc->mem_res, offs, val) 313ef2ee5d0SMichal Meloun 314ef2ee5d0SMichal Meloun static int 315ef2ee5d0SMichal Meloun reg_wait(struct usbphy_softc *sc, uint32_t reg, uint32_t mask, uint32_t val) 316ef2ee5d0SMichal Meloun { 317ef2ee5d0SMichal Meloun int i; 318ef2ee5d0SMichal Meloun 319ef2ee5d0SMichal Meloun for (i = 0; i < 1000; i++) { 320ef2ee5d0SMichal Meloun if ((RD4(sc, reg) & mask) == val) 321ef2ee5d0SMichal Meloun return (0); 322ef2ee5d0SMichal Meloun DELAY(10); 323ef2ee5d0SMichal Meloun } 324ef2ee5d0SMichal Meloun return (ETIMEDOUT); 325ef2ee5d0SMichal Meloun } 326ef2ee5d0SMichal Meloun 327ef2ee5d0SMichal Meloun static int 328ef2ee5d0SMichal Meloun usbphy_utmi_phy_clk(struct usbphy_softc *sc, bool enable) 329ef2ee5d0SMichal Meloun { 330ef2ee5d0SMichal Meloun uint32_t val; 331ef2ee5d0SMichal Meloun int rv; 332ef2ee5d0SMichal Meloun 333ef2ee5d0SMichal Meloun val = RD4(sc, CTRL_USB_HOSTPC1_DEVLC); 334ef2ee5d0SMichal Meloun if (enable) 335ef2ee5d0SMichal Meloun val &= ~USB_HOSTPC1_DEVLC_PHCD; 336ef2ee5d0SMichal Meloun else 337ef2ee5d0SMichal Meloun val |= USB_HOSTPC1_DEVLC_PHCD; 338ef2ee5d0SMichal Meloun WR4(sc, CTRL_USB_HOSTPC1_DEVLC, val); 339ef2ee5d0SMichal Meloun 340ef2ee5d0SMichal Meloun rv = reg_wait(sc, IF_USB_SUSP_CTRL, USB_PHY_CLK_VALID, 341ef2ee5d0SMichal Meloun enable ? USB_PHY_CLK_VALID: 0); 342ef2ee5d0SMichal Meloun if (rv != 0) { 343ef2ee5d0SMichal Meloun device_printf(sc->dev, "USB phy clock timeout.\n"); 344ef2ee5d0SMichal Meloun return (ETIMEDOUT); 345ef2ee5d0SMichal Meloun } 346ef2ee5d0SMichal Meloun return (0); 347ef2ee5d0SMichal Meloun } 348ef2ee5d0SMichal Meloun 349ef2ee5d0SMichal Meloun static int 350ef2ee5d0SMichal Meloun usbphy_utmi_enable(struct usbphy_softc *sc) 351ef2ee5d0SMichal Meloun { 352ef2ee5d0SMichal Meloun int rv; 353ef2ee5d0SMichal Meloun uint32_t val; 354ef2ee5d0SMichal Meloun 355ef2ee5d0SMichal Meloun /* Reset phy */ 356ef2ee5d0SMichal Meloun val = RD4(sc, IF_USB_SUSP_CTRL); 357ef2ee5d0SMichal Meloun val |= UTMIP_RESET; 358ef2ee5d0SMichal Meloun WR4(sc, IF_USB_SUSP_CTRL, val); 359ef2ee5d0SMichal Meloun 360ef2ee5d0SMichal Meloun val = RD4(sc, UTMIP_TX_CFG0); 361ef2ee5d0SMichal Meloun val |= UTMIP_FS_PREAMBLE_J; 362ef2ee5d0SMichal Meloun WR4(sc, UTMIP_TX_CFG0, val); 363ef2ee5d0SMichal Meloun 364ef2ee5d0SMichal Meloun val = RD4(sc, UTMIP_HSRX_CFG0); 365ef2ee5d0SMichal Meloun val &= ~UTMIP_IDLE_WAIT(~0); 366ef2ee5d0SMichal Meloun val &= ~UTMIP_ELASTIC_LIMIT(~0); 367ef2ee5d0SMichal Meloun val |= UTMIP_IDLE_WAIT(sc->idle_wait_delay); 368ef2ee5d0SMichal Meloun val |= UTMIP_ELASTIC_LIMIT(sc->elastic_limit); 369ef2ee5d0SMichal Meloun WR4(sc, UTMIP_HSRX_CFG0, val); 370ef2ee5d0SMichal Meloun 371ef2ee5d0SMichal Meloun val = RD4(sc, UTMIP_HSRX_CFG1); 372ef2ee5d0SMichal Meloun val &= ~UTMIP_HS_SYNC_START_DLY(~0); 373ef2ee5d0SMichal Meloun val |= UTMIP_HS_SYNC_START_DLY(sc->hssync_start_delay); 374ef2ee5d0SMichal Meloun WR4(sc, UTMIP_HSRX_CFG1, val); 375ef2ee5d0SMichal Meloun 376ef2ee5d0SMichal Meloun val = RD4(sc, UTMIP_DEBOUNCE_CFG0); 377ef2ee5d0SMichal Meloun val &= ~UTMIP_BIAS_DEBOUNCE_A(~0); 378ef2ee5d0SMichal Meloun val |= UTMIP_BIAS_DEBOUNCE_A(0x7530); /* For 12MHz */ 379ef2ee5d0SMichal Meloun WR4(sc, UTMIP_DEBOUNCE_CFG0, val); 380ef2ee5d0SMichal Meloun 381ef2ee5d0SMichal Meloun val = RD4(sc, UTMIP_MISC_CFG0); 382ef2ee5d0SMichal Meloun val &= ~UTMIP_SUSPEND_EXIT_ON_EDGE; 383ef2ee5d0SMichal Meloun WR4(sc, UTMIP_MISC_CFG0, val); 384ef2ee5d0SMichal Meloun 385ef2ee5d0SMichal Meloun if (sc->dr_mode == USB_DR_MODE_DEVICE) { 386ef2ee5d0SMichal Meloun val = RD4(sc,IF_USB_SUSP_CTRL); 387ef2ee5d0SMichal Meloun val &= ~USB_WAKE_ON_CNNT_EN_DEV; 388ef2ee5d0SMichal Meloun val &= ~USB_WAKE_ON_DISCON_EN_DEV; 389ef2ee5d0SMichal Meloun WR4(sc, IF_USB_SUSP_CTRL, val); 390ef2ee5d0SMichal Meloun 391ef2ee5d0SMichal Meloun val = RD4(sc, UTMIP_BAT_CHRG_CFG0); 392ef2ee5d0SMichal Meloun val &= ~UTMIP_PD_CHRG; 393ef2ee5d0SMichal Meloun WR4(sc, UTMIP_BAT_CHRG_CFG0, val); 394ef2ee5d0SMichal Meloun } else { 395ef2ee5d0SMichal Meloun val = RD4(sc, UTMIP_BAT_CHRG_CFG0); 396ef2ee5d0SMichal Meloun val |= UTMIP_PD_CHRG; 397ef2ee5d0SMichal Meloun WR4(sc, UTMIP_BAT_CHRG_CFG0, val); 398ef2ee5d0SMichal Meloun } 399ef2ee5d0SMichal Meloun 400ef2ee5d0SMichal Meloun usbpby_enable_cnt++; 401ef2ee5d0SMichal Meloun if (usbpby_enable_cnt == 1) { 402ef2ee5d0SMichal Meloun rv = hwreset_deassert(sc->reset_pads); 403ef2ee5d0SMichal Meloun if (rv != 0) { 404ef2ee5d0SMichal Meloun device_printf(sc->dev, 405ef2ee5d0SMichal Meloun "Cannot unreset 'utmi-pads' reset\n"); 406ef2ee5d0SMichal Meloun return (rv); 407ef2ee5d0SMichal Meloun } 408ef2ee5d0SMichal Meloun rv = clk_enable(sc->clk_pads); 409ef2ee5d0SMichal Meloun if (rv != 0) { 410ef2ee5d0SMichal Meloun device_printf(sc->dev, 411ef2ee5d0SMichal Meloun "Cannot enable 'utmi-pads' clock\n"); 412ef2ee5d0SMichal Meloun return (rv); 413ef2ee5d0SMichal Meloun } 414ef2ee5d0SMichal Meloun 415ef2ee5d0SMichal Meloun val = bus_read_4(sc->pads_res, UTMIP_BIAS_CFG0); 416ef2ee5d0SMichal Meloun val &= ~UTMIP_OTGPD; 417ef2ee5d0SMichal Meloun val &= ~UTMIP_BIASPD; 418ef2ee5d0SMichal Meloun val &= ~UTMIP_HSSQUELCH_LEVEL(~0); 419ef2ee5d0SMichal Meloun val &= ~UTMIP_HSDISCON_LEVEL(~0); 420ef2ee5d0SMichal Meloun val &= ~UTMIP_HSDISCON_LEVEL_MSB(~0); 421ef2ee5d0SMichal Meloun val |= UTMIP_HSSQUELCH_LEVEL(sc->hssquelch_level); 422ef2ee5d0SMichal Meloun val |= UTMIP_HSDISCON_LEVEL(sc->hsdiscon_level); 423ef2ee5d0SMichal Meloun val |= UTMIP_HSDISCON_LEVEL_MSB(sc->hsdiscon_level); 424ef2ee5d0SMichal Meloun bus_write_4(sc->pads_res, UTMIP_BIAS_CFG0, val); 425ef2ee5d0SMichal Meloun 426ef2ee5d0SMichal Meloun rv = clk_disable(sc->clk_pads); 427ef2ee5d0SMichal Meloun if (rv != 0) { 428ef2ee5d0SMichal Meloun device_printf(sc->dev, 429ef2ee5d0SMichal Meloun "Cannot disable 'utmi-pads' clock\n"); 430ef2ee5d0SMichal Meloun return (rv); 431ef2ee5d0SMichal Meloun } 432ef2ee5d0SMichal Meloun } 433ef2ee5d0SMichal Meloun 434ef2ee5d0SMichal Meloun val = RD4(sc, UTMIP_XCVR_CFG0); 435ef2ee5d0SMichal Meloun val &= ~UTMIP_FORCE_PD_POWERDOWN; 436ef2ee5d0SMichal Meloun val &= ~UTMIP_FORCE_PD2_POWERDOWN ; 437ef2ee5d0SMichal Meloun val &= ~UTMIP_FORCE_PDZI_POWERDOWN; 438ef2ee5d0SMichal Meloun val &= ~UTMIP_XCVR_LSBIAS_SEL; 439ef2ee5d0SMichal Meloun val &= ~UTMIP_XCVR_LSFSLEW(~0); 440ef2ee5d0SMichal Meloun val &= ~UTMIP_XCVR_LSRSLEW(~0); 441ef2ee5d0SMichal Meloun val &= ~UTMIP_XCVR_HSSLEW(~0); 442ef2ee5d0SMichal Meloun val &= ~UTMIP_XCVR_HSSLEW_MSB(~0); 443ef2ee5d0SMichal Meloun val |= UTMIP_XCVR_LSFSLEW(sc->xcvr_lsfslew); 444ef2ee5d0SMichal Meloun val |= UTMIP_XCVR_LSRSLEW(sc->xcvr_lsrslew); 445ef2ee5d0SMichal Meloun val |= UTMIP_XCVR_HSSLEW(sc->xcvr_hsslew); 446ef2ee5d0SMichal Meloun val |= UTMIP_XCVR_HSSLEW_MSB(sc->xcvr_hsslew); 447ef2ee5d0SMichal Meloun if (!sc->xcvr_setup_use_fuses) { 448ef2ee5d0SMichal Meloun val &= ~UTMIP_XCVR_SETUP(~0); 449ef2ee5d0SMichal Meloun val &= ~UTMIP_XCVR_SETUP_MSB(~0); 450ef2ee5d0SMichal Meloun val |= UTMIP_XCVR_SETUP(sc->xcvr_setup); 451ef2ee5d0SMichal Meloun val |= UTMIP_XCVR_SETUP_MSB(sc->xcvr_setup); 452ef2ee5d0SMichal Meloun } 453ef2ee5d0SMichal Meloun WR4(sc, UTMIP_XCVR_CFG0, val); 454ef2ee5d0SMichal Meloun 455ef2ee5d0SMichal Meloun val = RD4(sc, UTMIP_XCVR_CFG1); 456ef2ee5d0SMichal Meloun val &= ~UTMIP_FORCE_PDDISC_POWERDOWN; 457ef2ee5d0SMichal Meloun val &= ~UTMIP_FORCE_PDCHRP_POWERDOWN; 458ef2ee5d0SMichal Meloun val &= ~UTMIP_FORCE_PDDR_POWERDOWN; 459ef2ee5d0SMichal Meloun val &= ~UTMIP_XCVR_TERM_RANGE_ADJ(~0); 460ef2ee5d0SMichal Meloun val |= UTMIP_XCVR_TERM_RANGE_ADJ(sc->term_range_adj); 461ef2ee5d0SMichal Meloun WR4(sc, UTMIP_XCVR_CFG1, val); 462ef2ee5d0SMichal Meloun 463ef2ee5d0SMichal Meloun val = RD4(sc, UTMIP_BIAS_CFG1); 464ef2ee5d0SMichal Meloun val &= ~UTMIP_BIAS_PDTRK_COUNT(~0); 465ef2ee5d0SMichal Meloun val |= UTMIP_BIAS_PDTRK_COUNT(0x5); 466ef2ee5d0SMichal Meloun WR4(sc, UTMIP_BIAS_CFG1, val); 467ef2ee5d0SMichal Meloun 468ef2ee5d0SMichal Meloun val = RD4(sc, UTMIP_SPARE_CFG0); 469ef2ee5d0SMichal Meloun if (sc->xcvr_setup_use_fuses) 470ef2ee5d0SMichal Meloun val |= FUSE_SETUP_SEL; 471ef2ee5d0SMichal Meloun else 472ef2ee5d0SMichal Meloun val &= ~FUSE_SETUP_SEL; 473ef2ee5d0SMichal Meloun WR4(sc, UTMIP_SPARE_CFG0, val); 474ef2ee5d0SMichal Meloun 475ef2ee5d0SMichal Meloun val = RD4(sc, IF_USB_SUSP_CTRL); 476ef2ee5d0SMichal Meloun val |= UTMIP_PHY_ENB; 477ef2ee5d0SMichal Meloun WR4(sc, IF_USB_SUSP_CTRL, val); 478ef2ee5d0SMichal Meloun 479ef2ee5d0SMichal Meloun val = RD4(sc, IF_USB_SUSP_CTRL); 480ef2ee5d0SMichal Meloun val &= ~UTMIP_RESET; 481ef2ee5d0SMichal Meloun WR4(sc, IF_USB_SUSP_CTRL, val); 482ef2ee5d0SMichal Meloun 483ef2ee5d0SMichal Meloun usbphy_utmi_phy_clk(sc, true); 484ef2ee5d0SMichal Meloun 485ef2ee5d0SMichal Meloun val = RD4(sc, CTRL_USB_USBMODE); 486ef2ee5d0SMichal Meloun val &= ~USB_USBMODE_MASK; 487ef2ee5d0SMichal Meloun if (sc->dr_mode == USB_DR_MODE_HOST) 488ef2ee5d0SMichal Meloun val |= USB_USBMODE_HOST; 489ef2ee5d0SMichal Meloun else 490ef2ee5d0SMichal Meloun val |= USB_USBMODE_DEVICE; 491ef2ee5d0SMichal Meloun WR4(sc, CTRL_USB_USBMODE, val); 492ef2ee5d0SMichal Meloun 493ef2ee5d0SMichal Meloun val = RD4(sc, CTRL_USB_HOSTPC1_DEVLC); 494ef2ee5d0SMichal Meloun val &= ~USB_HOSTPC1_DEVLC_PTS(~0); 495ef2ee5d0SMichal Meloun val |= USB_HOSTPC1_DEVLC_PTS(0); 496ef2ee5d0SMichal Meloun WR4(sc, CTRL_USB_HOSTPC1_DEVLC, val); 497ef2ee5d0SMichal Meloun 498ef2ee5d0SMichal Meloun return (0); 499ef2ee5d0SMichal Meloun } 500ef2ee5d0SMichal Meloun 501ef2ee5d0SMichal Meloun static int 502ef2ee5d0SMichal Meloun usbphy_utmi_disable(struct usbphy_softc *sc) 503ef2ee5d0SMichal Meloun { 504ef2ee5d0SMichal Meloun int rv; 505ef2ee5d0SMichal Meloun uint32_t val; 506ef2ee5d0SMichal Meloun 507ef2ee5d0SMichal Meloun usbphy_utmi_phy_clk(sc, false); 508ef2ee5d0SMichal Meloun 509ef2ee5d0SMichal Meloun if (sc->dr_mode == USB_DR_MODE_DEVICE) { 510ef2ee5d0SMichal Meloun val = RD4(sc, IF_USB_SUSP_CTRL); 511ef2ee5d0SMichal Meloun val &= ~USB_WAKEUP_DEBOUNCE_COUNT(~0); 512ef2ee5d0SMichal Meloun val |= USB_WAKE_ON_CNNT_EN_DEV; 513ef2ee5d0SMichal Meloun val |= USB_WAKEUP_DEBOUNCE_COUNT(5); 514ef2ee5d0SMichal Meloun WR4(sc, IF_USB_SUSP_CTRL, val); 515ef2ee5d0SMichal Meloun } 516ef2ee5d0SMichal Meloun 517ef2ee5d0SMichal Meloun val = RD4(sc, IF_USB_SUSP_CTRL); 518ef2ee5d0SMichal Meloun val |= UTMIP_RESET; 519ef2ee5d0SMichal Meloun WR4(sc, IF_USB_SUSP_CTRL, val); 520ef2ee5d0SMichal Meloun 521ef2ee5d0SMichal Meloun val = RD4(sc, UTMIP_BAT_CHRG_CFG0); 522ef2ee5d0SMichal Meloun val |= UTMIP_PD_CHRG; 523ef2ee5d0SMichal Meloun WR4(sc, UTMIP_BAT_CHRG_CFG0, val); 524ef2ee5d0SMichal Meloun 525ef2ee5d0SMichal Meloun val = RD4(sc, UTMIP_XCVR_CFG0); 526ef2ee5d0SMichal Meloun val |= UTMIP_FORCE_PD_POWERDOWN; 527ef2ee5d0SMichal Meloun val |= UTMIP_FORCE_PD2_POWERDOWN; 528ef2ee5d0SMichal Meloun val |= UTMIP_FORCE_PDZI_POWERDOWN; 529ef2ee5d0SMichal Meloun WR4(sc, UTMIP_XCVR_CFG0, val); 530ef2ee5d0SMichal Meloun 531ef2ee5d0SMichal Meloun val = RD4(sc, UTMIP_XCVR_CFG1); 532ef2ee5d0SMichal Meloun val |= UTMIP_FORCE_PDDISC_POWERDOWN; 533ef2ee5d0SMichal Meloun val |= UTMIP_FORCE_PDCHRP_POWERDOWN; 534ef2ee5d0SMichal Meloun val |= UTMIP_FORCE_PDDR_POWERDOWN; 535ef2ee5d0SMichal Meloun WR4(sc, UTMIP_XCVR_CFG1, val); 536ef2ee5d0SMichal Meloun 537ef2ee5d0SMichal Meloun usbpby_enable_cnt--; 538ef2ee5d0SMichal Meloun if (usbpby_enable_cnt <= 0) { 539ef2ee5d0SMichal Meloun rv = clk_enable(sc->clk_pads); 540ef2ee5d0SMichal Meloun if (rv != 0) { 541ef2ee5d0SMichal Meloun device_printf(sc->dev, 542ef2ee5d0SMichal Meloun "Cannot enable 'utmi-pads' clock\n"); 543ef2ee5d0SMichal Meloun return (rv); 544ef2ee5d0SMichal Meloun } 545ef2ee5d0SMichal Meloun val =bus_read_4(sc->pads_res, UTMIP_BIAS_CFG0); 546ef2ee5d0SMichal Meloun val |= UTMIP_OTGPD; 547ef2ee5d0SMichal Meloun val |= UTMIP_BIASPD; 548ef2ee5d0SMichal Meloun bus_write_4(sc->pads_res, UTMIP_BIAS_CFG0, val); 549ef2ee5d0SMichal Meloun 550ef2ee5d0SMichal Meloun rv = clk_disable(sc->clk_pads); 551ef2ee5d0SMichal Meloun if (rv != 0) { 552ef2ee5d0SMichal Meloun device_printf(sc->dev, 553ef2ee5d0SMichal Meloun "Cannot disable 'utmi-pads' clock\n"); 554ef2ee5d0SMichal Meloun return (rv); 555ef2ee5d0SMichal Meloun } 556ef2ee5d0SMichal Meloun } 557ef2ee5d0SMichal Meloun return (0); 558ef2ee5d0SMichal Meloun } 559ef2ee5d0SMichal Meloun 560ef2ee5d0SMichal Meloun static int 561f8759facSMichal Meloun usbphy_phy_enable(struct phynode *phy, bool enable) 562ef2ee5d0SMichal Meloun { 563f8759facSMichal Meloun device_t dev; 564ef2ee5d0SMichal Meloun struct usbphy_softc *sc; 565ef2ee5d0SMichal Meloun int rv = 0; 566ef2ee5d0SMichal Meloun 567f8759facSMichal Meloun dev = phynode_get_device(phy); 568ef2ee5d0SMichal Meloun sc = device_get_softc(dev); 569ef2ee5d0SMichal Meloun 570ef2ee5d0SMichal Meloun if (sc->ifc_type != USB_IFC_TYPE_UTMI) { 571ef2ee5d0SMichal Meloun device_printf(sc->dev, 572ef2ee5d0SMichal Meloun "Only UTMI interface is supported.\n"); 573ef2ee5d0SMichal Meloun return (ENXIO); 574ef2ee5d0SMichal Meloun } 575ef2ee5d0SMichal Meloun if (enable) 576ef2ee5d0SMichal Meloun rv = usbphy_utmi_enable(sc); 577ef2ee5d0SMichal Meloun else 578ef2ee5d0SMichal Meloun rv = usbphy_utmi_disable(sc); 579ef2ee5d0SMichal Meloun 580ef2ee5d0SMichal Meloun return (rv); 581ef2ee5d0SMichal Meloun } 582ef2ee5d0SMichal Meloun 583ef2ee5d0SMichal Meloun static enum usb_ifc_type 584ef2ee5d0SMichal Meloun usb_get_ifc_mode(device_t dev, phandle_t node, char *name) 585ef2ee5d0SMichal Meloun { 586ef2ee5d0SMichal Meloun char *tmpstr; 587ef2ee5d0SMichal Meloun int rv; 588ef2ee5d0SMichal Meloun enum usb_ifc_type ret; 589ef2ee5d0SMichal Meloun 590217d17bcSOleksandr Tymoshenko rv = OF_getprop_alloc(node, name, (void **)&tmpstr); 591ef2ee5d0SMichal Meloun if (rv <= 0) 592ef2ee5d0SMichal Meloun return (USB_IFC_TYPE_UNKNOWN); 593ef2ee5d0SMichal Meloun 594ef2ee5d0SMichal Meloun ret = USB_IFC_TYPE_UNKNOWN; 595ef2ee5d0SMichal Meloun if (strcmp(tmpstr, "utmi") == 0) 596ef2ee5d0SMichal Meloun ret = USB_IFC_TYPE_UTMI; 597ef2ee5d0SMichal Meloun else if (strcmp(tmpstr, "ulpi") == 0) 598ef2ee5d0SMichal Meloun ret = USB_IFC_TYPE_ULPI; 599ef2ee5d0SMichal Meloun else 600ef2ee5d0SMichal Meloun device_printf(dev, "Unsupported phy type: %s\n", tmpstr); 601bebd5269SOleksandr Tymoshenko OF_prop_free(tmpstr); 602ef2ee5d0SMichal Meloun return (ret); 603ef2ee5d0SMichal Meloun } 604ef2ee5d0SMichal Meloun 605ef2ee5d0SMichal Meloun static enum usb_dr_mode 606ef2ee5d0SMichal Meloun usb_get_dr_mode(device_t dev, phandle_t node, char *name) 607ef2ee5d0SMichal Meloun { 608ef2ee5d0SMichal Meloun char *tmpstr; 609ef2ee5d0SMichal Meloun int rv; 610ef2ee5d0SMichal Meloun enum usb_dr_mode ret; 611ef2ee5d0SMichal Meloun 612217d17bcSOleksandr Tymoshenko rv = OF_getprop_alloc(node, name, (void **)&tmpstr); 613ef2ee5d0SMichal Meloun if (rv <= 0) 614ef2ee5d0SMichal Meloun return (USB_DR_MODE_UNKNOWN); 615ef2ee5d0SMichal Meloun 616ef2ee5d0SMichal Meloun ret = USB_DR_MODE_UNKNOWN; 617ef2ee5d0SMichal Meloun if (strcmp(tmpstr, "device") == 0) 618ef2ee5d0SMichal Meloun ret = USB_DR_MODE_DEVICE; 619ef2ee5d0SMichal Meloun else if (strcmp(tmpstr, "host") == 0) 620ef2ee5d0SMichal Meloun ret = USB_DR_MODE_HOST; 621ef2ee5d0SMichal Meloun else if (strcmp(tmpstr, "otg") == 0) 622ef2ee5d0SMichal Meloun ret = USB_DR_MODE_OTG; 623ef2ee5d0SMichal Meloun else 624ef2ee5d0SMichal Meloun device_printf(dev, "Unknown dr mode: %s\n", tmpstr); 625bebd5269SOleksandr Tymoshenko OF_prop_free(tmpstr); 626ef2ee5d0SMichal Meloun return (ret); 627ef2ee5d0SMichal Meloun } 628ef2ee5d0SMichal Meloun 629ef2ee5d0SMichal Meloun static int 630ef2ee5d0SMichal Meloun usbphy_utmi_read_params(struct usbphy_softc *sc, phandle_t node) 631ef2ee5d0SMichal Meloun { 632ef2ee5d0SMichal Meloun int rv; 633ef2ee5d0SMichal Meloun 634ef2ee5d0SMichal Meloun rv = OF_getencprop(node, "nvidia,hssync-start-delay", 635ef2ee5d0SMichal Meloun &sc->hssync_start_delay, sizeof (sc->hssync_start_delay)); 636ef2ee5d0SMichal Meloun if (rv <= 0) 637ef2ee5d0SMichal Meloun return (ENXIO); 638ef2ee5d0SMichal Meloun 639ef2ee5d0SMichal Meloun rv = OF_getencprop(node, "nvidia,elastic-limit", 640ef2ee5d0SMichal Meloun &sc->elastic_limit, sizeof (sc->elastic_limit)); 641ef2ee5d0SMichal Meloun if (rv <= 0) 642ef2ee5d0SMichal Meloun return (ENXIO); 643ef2ee5d0SMichal Meloun 644ef2ee5d0SMichal Meloun rv = OF_getencprop(node, "nvidia,idle-wait-delay", 645ef2ee5d0SMichal Meloun &sc->idle_wait_delay, sizeof (sc->idle_wait_delay)); 646ef2ee5d0SMichal Meloun if (rv <= 0) 647ef2ee5d0SMichal Meloun return (ENXIO); 648ef2ee5d0SMichal Meloun 649ef2ee5d0SMichal Meloun rv = OF_getencprop(node, "nvidia,term-range-adj", 650ef2ee5d0SMichal Meloun &sc->term_range_adj, sizeof (sc->term_range_adj)); 651ef2ee5d0SMichal Meloun if (rv <= 0) 652ef2ee5d0SMichal Meloun return (ENXIO); 653ef2ee5d0SMichal Meloun 654ef2ee5d0SMichal Meloun rv = OF_getencprop(node, "nvidia,xcvr-lsfslew", 655ef2ee5d0SMichal Meloun &sc->xcvr_lsfslew, sizeof (sc->xcvr_lsfslew)); 656ef2ee5d0SMichal Meloun if (rv <= 0) 657ef2ee5d0SMichal Meloun return (ENXIO); 658ef2ee5d0SMichal Meloun 659ef2ee5d0SMichal Meloun rv = OF_getencprop(node, "nvidia,xcvr-lsrslew", 660ef2ee5d0SMichal Meloun &sc->xcvr_lsrslew, sizeof (sc->xcvr_lsrslew)); 661ef2ee5d0SMichal Meloun if (rv <= 0) 662ef2ee5d0SMichal Meloun return (ENXIO); 663ef2ee5d0SMichal Meloun 664ef2ee5d0SMichal Meloun rv = OF_getencprop(node, "nvidia,xcvr-hsslew", 665ef2ee5d0SMichal Meloun &sc->xcvr_hsslew, sizeof (sc->xcvr_hsslew)); 666ef2ee5d0SMichal Meloun if (rv <= 0) 667ef2ee5d0SMichal Meloun return (ENXIO); 668ef2ee5d0SMichal Meloun 669ef2ee5d0SMichal Meloun rv = OF_getencprop(node, "nvidia,hssquelch-level", 670ef2ee5d0SMichal Meloun &sc->hssquelch_level, sizeof (sc->hssquelch_level)); 671ef2ee5d0SMichal Meloun if (rv <= 0) 672ef2ee5d0SMichal Meloun return (ENXIO); 673ef2ee5d0SMichal Meloun 674ef2ee5d0SMichal Meloun rv = OF_getencprop(node, "nvidia,hsdiscon-level", 675ef2ee5d0SMichal Meloun &sc->hsdiscon_level, sizeof (sc->hsdiscon_level)); 676ef2ee5d0SMichal Meloun if (rv <= 0) 677ef2ee5d0SMichal Meloun return (ENXIO); 678ef2ee5d0SMichal Meloun 679ef2ee5d0SMichal Meloun rv = OF_getproplen(node, "nvidia,xcvr-setup-use-fuses"); 680ef2ee5d0SMichal Meloun if (rv >= 1) { 681ef2ee5d0SMichal Meloun sc->xcvr_setup_use_fuses = 1; 682ef2ee5d0SMichal Meloun } else { 683ef2ee5d0SMichal Meloun rv = OF_getencprop(node, "nvidia,xcvr-setup", 684ef2ee5d0SMichal Meloun &sc->xcvr_setup, sizeof (sc->xcvr_setup)); 685ef2ee5d0SMichal Meloun if (rv <= 0) 686ef2ee5d0SMichal Meloun return (ENXIO); 687ef2ee5d0SMichal Meloun } 688ef2ee5d0SMichal Meloun 689ef2ee5d0SMichal Meloun return (0); 690ef2ee5d0SMichal Meloun } 691ef2ee5d0SMichal Meloun 692ef2ee5d0SMichal Meloun static int 693ef2ee5d0SMichal Meloun usbphy_probe(device_t dev) 694ef2ee5d0SMichal Meloun { 695ef2ee5d0SMichal Meloun 696ef2ee5d0SMichal Meloun if (!ofw_bus_status_okay(dev)) 697ef2ee5d0SMichal Meloun return (ENXIO); 698ef2ee5d0SMichal Meloun 699ef2ee5d0SMichal Meloun if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data) 700ef2ee5d0SMichal Meloun return (ENXIO); 701ef2ee5d0SMichal Meloun 702ef2ee5d0SMichal Meloun device_set_desc(dev, "Tegra USB phy"); 703ef2ee5d0SMichal Meloun return (BUS_PROBE_DEFAULT); 704ef2ee5d0SMichal Meloun } 705ef2ee5d0SMichal Meloun 706ef2ee5d0SMichal Meloun static int 707ef2ee5d0SMichal Meloun usbphy_attach(device_t dev) 708ef2ee5d0SMichal Meloun { 709ef2ee5d0SMichal Meloun struct usbphy_softc *sc; 710ef2ee5d0SMichal Meloun int rid, rv; 711ef2ee5d0SMichal Meloun phandle_t node; 712f8759facSMichal Meloun struct phynode *phynode; 713f8759facSMichal Meloun struct phynode_init_def phy_init; 714ef2ee5d0SMichal Meloun 715ef2ee5d0SMichal Meloun sc = device_get_softc(dev); 716ef2ee5d0SMichal Meloun sc->dev = dev; 717ef2ee5d0SMichal Meloun 718ef2ee5d0SMichal Meloun rid = 0; 719ef2ee5d0SMichal Meloun sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 720ef2ee5d0SMichal Meloun RF_ACTIVE | RF_SHAREABLE); 721ef2ee5d0SMichal Meloun if (sc->mem_res == NULL) { 722ef2ee5d0SMichal Meloun device_printf(dev, "Cannot allocate memory resources\n"); 723ef2ee5d0SMichal Meloun return (ENXIO); 724ef2ee5d0SMichal Meloun } 725ef2ee5d0SMichal Meloun 726ef2ee5d0SMichal Meloun rid = 1; 727ef2ee5d0SMichal Meloun sc->pads_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 728ef2ee5d0SMichal Meloun RF_ACTIVE | RF_SHAREABLE); 729ef2ee5d0SMichal Meloun if (sc->mem_res == NULL) { 730ef2ee5d0SMichal Meloun device_printf(dev, "Cannot allocate memory resources\n"); 731ef2ee5d0SMichal Meloun return (ENXIO); 732ef2ee5d0SMichal Meloun } 733ef2ee5d0SMichal Meloun 734ef2ee5d0SMichal Meloun node = ofw_bus_get_node(dev); 735ef2ee5d0SMichal Meloun 736dac93553SMichal Meloun rv = hwreset_get_by_ofw_name(sc->dev, 0, "usb", &sc->reset_usb); 737ef2ee5d0SMichal Meloun if (rv != 0) { 738ef2ee5d0SMichal Meloun device_printf(dev, "Cannot get 'usb' reset\n"); 739ef2ee5d0SMichal Meloun return (ENXIO); 740ef2ee5d0SMichal Meloun } 741dac93553SMichal Meloun rv = hwreset_get_by_ofw_name(sc->dev, 0, "utmi-pads", &sc->reset_pads); 742ef2ee5d0SMichal Meloun if (rv != 0) { 743ef2ee5d0SMichal Meloun device_printf(dev, "Cannot get 'utmi-pads' reset\n"); 744ef2ee5d0SMichal Meloun return (ENXIO); 745ef2ee5d0SMichal Meloun } 746ef2ee5d0SMichal Meloun 747dac93553SMichal Meloun rv = clk_get_by_ofw_name(sc->dev, 0, "reg", &sc->clk_reg); 748ef2ee5d0SMichal Meloun if (rv != 0) { 749ef2ee5d0SMichal Meloun device_printf(sc->dev, "Cannot get 'reg' clock\n"); 750ef2ee5d0SMichal Meloun return (ENXIO); 751ef2ee5d0SMichal Meloun } 752dac93553SMichal Meloun rv = clk_get_by_ofw_name(sc->dev, 0, "pll_u", &sc->clk_pllu); 753ef2ee5d0SMichal Meloun if (rv != 0) { 754ef2ee5d0SMichal Meloun device_printf(sc->dev, "Cannot get 'pll_u' clock\n"); 755ef2ee5d0SMichal Meloun return (ENXIO); 756ef2ee5d0SMichal Meloun } 757dac93553SMichal Meloun rv = clk_get_by_ofw_name(sc->dev, 0, "utmi-pads", &sc->clk_pads); 758ef2ee5d0SMichal Meloun if (rv != 0) { 759ef2ee5d0SMichal Meloun device_printf(sc->dev, "Cannot get 'utmi-pads' clock\n"); 760ef2ee5d0SMichal Meloun return (ENXIO); 761ef2ee5d0SMichal Meloun } 762ef2ee5d0SMichal Meloun 763ef2ee5d0SMichal Meloun rv = hwreset_deassert(sc->reset_usb); 764ef2ee5d0SMichal Meloun if (rv != 0) { 765ef2ee5d0SMichal Meloun device_printf(dev, "Cannot unreset 'usb' reset\n"); 766ef2ee5d0SMichal Meloun return (ENXIO); 767ef2ee5d0SMichal Meloun } 768ef2ee5d0SMichal Meloun 769ef2ee5d0SMichal Meloun rv = clk_enable(sc->clk_pllu); 770ef2ee5d0SMichal Meloun if (rv != 0) { 771ef2ee5d0SMichal Meloun device_printf(sc->dev, "Cannot enable 'pllu' clock\n"); 772ef2ee5d0SMichal Meloun return (ENXIO); 773ef2ee5d0SMichal Meloun } 774ef2ee5d0SMichal Meloun rv = clk_enable(sc->clk_reg); 775ef2ee5d0SMichal Meloun if (rv != 0) { 776ef2ee5d0SMichal Meloun device_printf(sc->dev, "Cannot enable 'reg' clock\n"); 777ef2ee5d0SMichal Meloun return (ENXIO); 778ef2ee5d0SMichal Meloun } 779ef2ee5d0SMichal Meloun if (OF_hasprop(node, "nvidia,has-utmi-pad-registers")) 780ef2ee5d0SMichal Meloun sc->have_utmi_regs = true; 781ef2ee5d0SMichal Meloun 782ef2ee5d0SMichal Meloun sc->dr_mode = usb_get_dr_mode(dev, node, "dr_mode"); 783ef2ee5d0SMichal Meloun if (sc->dr_mode == USB_DR_MODE_UNKNOWN) 784ef2ee5d0SMichal Meloun sc->dr_mode = USB_DR_MODE_HOST; 785ef2ee5d0SMichal Meloun 786ef2ee5d0SMichal Meloun sc->ifc_type = usb_get_ifc_mode(dev, node, "phy_type"); 787ef2ee5d0SMichal Meloun 788ef2ee5d0SMichal Meloun /* We supports only utmi phy mode for now .... */ 789ef2ee5d0SMichal Meloun if (sc->ifc_type != USB_IFC_TYPE_UTMI) { 790ef2ee5d0SMichal Meloun device_printf(dev, "Unsupported phy type\n"); 791ef2ee5d0SMichal Meloun return (ENXIO); 792ef2ee5d0SMichal Meloun } 793ef2ee5d0SMichal Meloun rv = usbphy_utmi_read_params(sc, node); 794ef2ee5d0SMichal Meloun if (rv < 0) 795ef2ee5d0SMichal Meloun return rv; 796ef2ee5d0SMichal Meloun 797ef2ee5d0SMichal Meloun if (OF_hasprop(node, "vbus-supply")) { 798dac93553SMichal Meloun rv = regulator_get_by_ofw_property(sc->dev, 0, "vbus-supply", 799ef2ee5d0SMichal Meloun &sc->supply_vbus); 800ef2ee5d0SMichal Meloun if (rv != 0) { 801ef2ee5d0SMichal Meloun device_printf(sc->dev, 802ef2ee5d0SMichal Meloun "Cannot get \"vbus\" regulator\n"); 803ef2ee5d0SMichal Meloun return (ENXIO); 804ef2ee5d0SMichal Meloun } 805ef2ee5d0SMichal Meloun rv = regulator_enable(sc->supply_vbus); 806ef2ee5d0SMichal Meloun if (rv != 0) { 807ef2ee5d0SMichal Meloun device_printf(sc->dev, 808ef2ee5d0SMichal Meloun "Cannot enable \"vbus\" regulator\n"); 809ef2ee5d0SMichal Meloun return (rv); 810ef2ee5d0SMichal Meloun } 811ef2ee5d0SMichal Meloun } 812ef2ee5d0SMichal Meloun 813f8759facSMichal Meloun /* Create and register phy. */ 814f8759facSMichal Meloun bzero(&phy_init, sizeof(phy_init)); 815f8759facSMichal Meloun phy_init.id = 1; 816f8759facSMichal Meloun phy_init.ofw_node = node; 817f8759facSMichal Meloun phynode = phynode_create(dev, &usbphy_phynode_class, &phy_init); 818f8759facSMichal Meloun if (phynode == NULL) { 819f8759facSMichal Meloun device_printf(sc->dev, "Cannot create phy\n"); 820f8759facSMichal Meloun return (ENXIO); 821f8759facSMichal Meloun } 822f8759facSMichal Meloun if (phynode_register(phynode) == NULL) { 823f8759facSMichal Meloun device_printf(sc->dev, "Cannot create phy\n"); 824f8759facSMichal Meloun return (ENXIO); 825f8759facSMichal Meloun } 826f8759facSMichal Meloun 827ef2ee5d0SMichal Meloun return (0); 828ef2ee5d0SMichal Meloun } 829ef2ee5d0SMichal Meloun 830ef2ee5d0SMichal Meloun static int 831ef2ee5d0SMichal Meloun usbphy_detach(device_t dev) 832ef2ee5d0SMichal Meloun { 833ef2ee5d0SMichal Meloun 834ef2ee5d0SMichal Meloun /* This device is always present. */ 835ef2ee5d0SMichal Meloun return (EBUSY); 836ef2ee5d0SMichal Meloun } 837ef2ee5d0SMichal Meloun 838ef2ee5d0SMichal Meloun static device_method_t tegra_usbphy_methods[] = { 839ef2ee5d0SMichal Meloun /* Device interface */ 840ef2ee5d0SMichal Meloun DEVMETHOD(device_probe, usbphy_probe), 841ef2ee5d0SMichal Meloun DEVMETHOD(device_attach, usbphy_attach), 842ef2ee5d0SMichal Meloun DEVMETHOD(device_detach, usbphy_detach), 843ef2ee5d0SMichal Meloun 844ef2ee5d0SMichal Meloun DEVMETHOD_END 845ef2ee5d0SMichal Meloun }; 846ef2ee5d0SMichal Meloun 8474bda238aSMichal Meloun static DEFINE_CLASS_0(usbphy, tegra_usbphy_driver, tegra_usbphy_methods, 8484bda238aSMichal Meloun sizeof(struct usbphy_softc)); 849*289f133bSJohn Baldwin EARLY_DRIVER_MODULE(tegra_usbphy, simplebus, tegra_usbphy_driver, NULL, NULL, 850*289f133bSJohn Baldwin 79); 851