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