1*66e56efcSFrank Li /* SPDX-License-Identifier: GPL-2.0 */ 2*66e56efcSFrank Li 3*66e56efcSFrank Li /* PORTSC - Port Status and Control Register - port_status_base bitmasks */ 4*66e56efcSFrank Li /* true: device connected */ 5*66e56efcSFrank Li #define PORT_CONNECT (1 << 0) 6*66e56efcSFrank Li /* true: port enabled */ 7*66e56efcSFrank Li #define PORT_PE (1 << 1) 8*66e56efcSFrank Li /* bit 2 reserved and zeroed */ 9*66e56efcSFrank Li /* true: port has an over-current condition */ 10*66e56efcSFrank Li #define PORT_OC (1 << 3) 11*66e56efcSFrank Li /* true: port reset signaling asserted */ 12*66e56efcSFrank Li #define PORT_RESET (1 << 4) 13*66e56efcSFrank Li /* Port Link State - bits 5:8 14*66e56efcSFrank Li * A read gives the current link PM state of the port, 15*66e56efcSFrank Li * a write with Link State Write Strobe set sets the link state. 16*66e56efcSFrank Li */ 17*66e56efcSFrank Li #define PORT_PLS_MASK (0xf << 5) 18*66e56efcSFrank Li #define XDEV_U0 (0x0 << 5) 19*66e56efcSFrank Li #define XDEV_U1 (0x1 << 5) 20*66e56efcSFrank Li #define XDEV_U2 (0x2 << 5) 21*66e56efcSFrank Li #define XDEV_U3 (0x3 << 5) 22*66e56efcSFrank Li #define XDEV_DISABLED (0x4 << 5) 23*66e56efcSFrank Li #define XDEV_RXDETECT (0x5 << 5) 24*66e56efcSFrank Li #define XDEV_INACTIVE (0x6 << 5) 25*66e56efcSFrank Li #define XDEV_POLLING (0x7 << 5) 26*66e56efcSFrank Li #define XDEV_RECOVERY (0x8 << 5) 27*66e56efcSFrank Li #define XDEV_HOT_RESET (0x9 << 5) 28*66e56efcSFrank Li #define XDEV_COMP_MODE (0xa << 5) 29*66e56efcSFrank Li #define XDEV_TEST_MODE (0xb << 5) 30*66e56efcSFrank Li #define XDEV_RESUME (0xf << 5) 31*66e56efcSFrank Li 32*66e56efcSFrank Li /* true: port has power (see HCC_PPC) */ 33*66e56efcSFrank Li #define PORT_POWER (1 << 9) 34*66e56efcSFrank Li /* bits 10:13 indicate device speed: 35*66e56efcSFrank Li * 0 - undefined speed - port hasn't be initialized by a reset yet 36*66e56efcSFrank Li * 1 - full speed 37*66e56efcSFrank Li * 2 - low speed 38*66e56efcSFrank Li * 3 - high speed 39*66e56efcSFrank Li * 4 - super speed 40*66e56efcSFrank Li * 5-15 reserved 41*66e56efcSFrank Li */ 42*66e56efcSFrank Li #define DEV_SPEED_MASK (0xf << 10) 43*66e56efcSFrank Li #define XDEV_FS (0x1 << 10) 44*66e56efcSFrank Li #define XDEV_LS (0x2 << 10) 45*66e56efcSFrank Li #define XDEV_HS (0x3 << 10) 46*66e56efcSFrank Li #define XDEV_SS (0x4 << 10) 47*66e56efcSFrank Li #define XDEV_SSP (0x5 << 10) 48*66e56efcSFrank Li #define DEV_UNDEFSPEED(p) (((p) & DEV_SPEED_MASK) == (0x0<<10)) 49*66e56efcSFrank Li #define DEV_FULLSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_FS) 50*66e56efcSFrank Li #define DEV_LOWSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_LS) 51*66e56efcSFrank Li #define DEV_HIGHSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_HS) 52*66e56efcSFrank Li #define DEV_SUPERSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_SS) 53*66e56efcSFrank Li #define DEV_SUPERSPEEDPLUS(p) (((p) & DEV_SPEED_MASK) == XDEV_SSP) 54*66e56efcSFrank Li #define DEV_SUPERSPEED_ANY(p) (((p) & DEV_SPEED_MASK) >= XDEV_SS) 55*66e56efcSFrank Li #define DEV_PORT_SPEED(p) (((p) >> 10) & 0x0f) 56*66e56efcSFrank Li 57*66e56efcSFrank Li /* Bits 20:23 in the Slot Context are the speed for the device */ 58*66e56efcSFrank Li #define SLOT_SPEED_FS (XDEV_FS << 10) 59*66e56efcSFrank Li #define SLOT_SPEED_LS (XDEV_LS << 10) 60*66e56efcSFrank Li #define SLOT_SPEED_HS (XDEV_HS << 10) 61*66e56efcSFrank Li #define SLOT_SPEED_SS (XDEV_SS << 10) 62*66e56efcSFrank Li #define SLOT_SPEED_SSP (XDEV_SSP << 10) 63*66e56efcSFrank Li /* Port Indicator Control */ 64*66e56efcSFrank Li #define PORT_LED_OFF (0 << 14) 65*66e56efcSFrank Li #define PORT_LED_AMBER (1 << 14) 66*66e56efcSFrank Li #define PORT_LED_GREEN (2 << 14) 67*66e56efcSFrank Li #define PORT_LED_MASK (3 << 14) 68*66e56efcSFrank Li /* Port Link State Write Strobe - set this when changing link state */ 69*66e56efcSFrank Li #define PORT_LINK_STROBE (1 << 16) 70*66e56efcSFrank Li /* true: connect status change */ 71*66e56efcSFrank Li #define PORT_CSC (1 << 17) 72*66e56efcSFrank Li /* true: port enable change */ 73*66e56efcSFrank Li #define PORT_PEC (1 << 18) 74*66e56efcSFrank Li /* true: warm reset for a USB 3.0 device is done. A "hot" reset puts the port 75*66e56efcSFrank Li * into an enabled state, and the device into the default state. A "warm" reset 76*66e56efcSFrank Li * also resets the link, forcing the device through the link training sequence. 77*66e56efcSFrank Li * SW can also look at the Port Reset register to see when warm reset is done. 78*66e56efcSFrank Li */ 79*66e56efcSFrank Li #define PORT_WRC (1 << 19) 80*66e56efcSFrank Li /* true: over-current change */ 81*66e56efcSFrank Li #define PORT_OCC (1 << 20) 82*66e56efcSFrank Li /* true: reset change - 1 to 0 transition of PORT_RESET */ 83*66e56efcSFrank Li #define PORT_RC (1 << 21) 84*66e56efcSFrank Li /* port link status change - set on some port link state transitions: 85*66e56efcSFrank Li * Transition Reason 86*66e56efcSFrank Li * ------------------------------------------------------------------------------ 87*66e56efcSFrank Li * - U3 to Resume Wakeup signaling from a device 88*66e56efcSFrank Li * - Resume to Recovery to U0 USB 3.0 device resume 89*66e56efcSFrank Li * - Resume to U0 USB 2.0 device resume 90*66e56efcSFrank Li * - U3 to Recovery to U0 Software resume of USB 3.0 device complete 91*66e56efcSFrank Li * - U3 to U0 Software resume of USB 2.0 device complete 92*66e56efcSFrank Li * - U2 to U0 L1 resume of USB 2.1 device complete 93*66e56efcSFrank Li * - U0 to U0 (???) L1 entry rejection by USB 2.1 device 94*66e56efcSFrank Li * - U0 to disabled L1 entry error with USB 2.1 device 95*66e56efcSFrank Li * - Any state to inactive Error on USB 3.0 port 96*66e56efcSFrank Li */ 97*66e56efcSFrank Li #define PORT_PLC (1 << 22) 98*66e56efcSFrank Li /* port configure error change - port failed to configure its link partner */ 99*66e56efcSFrank Li #define PORT_CEC (1 << 23) 100*66e56efcSFrank Li #define PORT_CHANGE_MASK (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \ 101*66e56efcSFrank Li PORT_RC | PORT_PLC | PORT_CEC) 102*66e56efcSFrank Li 103*66e56efcSFrank Li 104*66e56efcSFrank Li /* Cold Attach Status - xHC can set this bit to report device attached during 105*66e56efcSFrank Li * Sx state. Warm port reset should be perfomed to clear this bit and move port 106*66e56efcSFrank Li * to connected state. 107*66e56efcSFrank Li */ 108*66e56efcSFrank Li #define PORT_CAS (1 << 24) 109*66e56efcSFrank Li /* wake on connect (enable) */ 110*66e56efcSFrank Li #define PORT_WKCONN_E (1 << 25) 111*66e56efcSFrank Li /* wake on disconnect (enable) */ 112*66e56efcSFrank Li #define PORT_WKDISC_E (1 << 26) 113*66e56efcSFrank Li /* wake on over-current (enable) */ 114*66e56efcSFrank Li #define PORT_WKOC_E (1 << 27) 115*66e56efcSFrank Li /* bits 28:29 reserved */ 116*66e56efcSFrank Li /* true: device is non-removable - for USB 3.0 roothub emulation */ 117*66e56efcSFrank Li #define PORT_DEV_REMOVE (1 << 30) 118*66e56efcSFrank Li /* Initiate a warm port reset - complete when PORT_WRC is '1' */ 119*66e56efcSFrank Li #define PORT_WR (1 << 31) 120*66e56efcSFrank Li 121*66e56efcSFrank Li /* We mark duplicate entries with -1 */ 122*66e56efcSFrank Li #define DUPLICATE_ENTRY ((u8)(-1)) 123*66e56efcSFrank Li 124*66e56efcSFrank Li /* Port Power Management Status and Control - port_power_base bitmasks */ 125*66e56efcSFrank Li /* Inactivity timer value for transitions into U1, in microseconds. 126*66e56efcSFrank Li * Timeout can be up to 127us. 0xFF means an infinite timeout. 127*66e56efcSFrank Li */ 128*66e56efcSFrank Li #define PORT_U1_TIMEOUT(p) ((p) & 0xff) 129*66e56efcSFrank Li #define PORT_U1_TIMEOUT_MASK 0xff 130*66e56efcSFrank Li /* Inactivity timer value for transitions into U2 */ 131*66e56efcSFrank Li #define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8) 132*66e56efcSFrank Li #define PORT_U2_TIMEOUT_MASK (0xff << 8) 133*66e56efcSFrank Li /* Bits 24:31 for port testing */ 134*66e56efcSFrank Li 135*66e56efcSFrank Li /* USB2 Protocol PORTSPMSC */ 136*66e56efcSFrank Li #define PORT_L1S_MASK 7 137*66e56efcSFrank Li #define PORT_L1S_SUCCESS 1 138*66e56efcSFrank Li #define PORT_RWE (1 << 3) 139*66e56efcSFrank Li #define PORT_HIRD(p) (((p) & 0xf) << 4) 140*66e56efcSFrank Li #define PORT_HIRD_MASK (0xf << 4) 141*66e56efcSFrank Li #define PORT_L1DS_MASK (0xff << 8) 142*66e56efcSFrank Li #define PORT_L1DS(p) (((p) & 0xff) << 8) 143*66e56efcSFrank Li #define PORT_HLE (1 << 16) 144*66e56efcSFrank Li #define PORT_TEST_MODE_SHIFT 28 145*66e56efcSFrank Li 146*66e56efcSFrank Li /* USB3 Protocol PORTLI Port Link Information */ 147*66e56efcSFrank Li #define PORT_RX_LANES(p) (((p) >> 16) & 0xf) 148*66e56efcSFrank Li #define PORT_TX_LANES(p) (((p) >> 20) & 0xf) 149*66e56efcSFrank Li 150*66e56efcSFrank Li /* USB2 Protocol PORTHLPMC */ 151*66e56efcSFrank Li #define PORT_HIRDM(p)((p) & 3) 152*66e56efcSFrank Li #define PORT_L1_TIMEOUT(p)(((p) & 0xff) << 2) 153*66e56efcSFrank Li #define PORT_BESLD(p)(((p) & 0xf) << 10) 154*66e56efcSFrank Li 155*66e56efcSFrank Li /* use 512 microseconds as USB2 LPM L1 default timeout. */ 156*66e56efcSFrank Li #define XHCI_L1_TIMEOUT 512 157*66e56efcSFrank Li 158*66e56efcSFrank Li /* Set default HIRD/BESL value to 4 (350/400us) for USB2 L1 LPM resume latency. 159*66e56efcSFrank Li * Safe to use with mixed HIRD and BESL systems (host and device) and is used 160*66e56efcSFrank Li * by other operating systems. 161*66e56efcSFrank Li * 162*66e56efcSFrank Li * XHCI 1.0 errata 8/14/12 Table 13 notes: 163*66e56efcSFrank Li * "Software should choose xHC BESL/BESLD field values that do not violate a 164*66e56efcSFrank Li * device's resume latency requirements, 165*66e56efcSFrank Li * e.g. not program values > '4' if BLC = '1' and a HIRD device is attached, 166*66e56efcSFrank Li * or not program values < '4' if BLC = '0' and a BESL device is attached. 167*66e56efcSFrank Li */ 168*66e56efcSFrank Li #define XHCI_DEFAULT_BESL 4 169*66e56efcSFrank Li 170*66e56efcSFrank Li /* 171*66e56efcSFrank Li * USB3 specification define a 360ms tPollingLFPSTiemout for USB3 ports 172*66e56efcSFrank Li * to complete link training. usually link trainig completes much faster 173*66e56efcSFrank Li * so check status 10 times with 36ms sleep in places we need to wait for 174*66e56efcSFrank Li * polling to complete. 175*66e56efcSFrank Li */ 176*66e56efcSFrank Li #define XHCI_PORT_POLLING_LFPS_TIME 36 177