Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: typec: tcpm: Report right typec_pwr_opmode

At present, TCPM does not take into account the actual resistor
value presented in the CC line and therefore reports TYPEC_PWR_MODE_USB
irrespective of the power_op_mode it is in.
This patch makes TCPM consider the actual value of Rp.

Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Badhri Jagan Sridharan and committed by
Greg Kroah-Hartman
fce042f0 c79d92bd

+19 -2
+19 -2
drivers/staging/typec/tcpm.c
··· 2130 2130 } 2131 2131 } 2132 2132 2133 + enum typec_pwr_opmode tcpm_get_pwr_opmode(enum typec_cc_status cc) 2134 + { 2135 + switch (cc) { 2136 + case TYPEC_CC_RP_1_5: 2137 + return TYPEC_PWR_MODE_1_5A; 2138 + case TYPEC_CC_RP_3_0: 2139 + return TYPEC_PWR_MODE_3_0A; 2140 + case TYPEC_CC_RP_DEF: 2141 + default: 2142 + return TYPEC_PWR_MODE_USB; 2143 + } 2144 + } 2145 + 2133 2146 static void run_state_machine(struct tcpm_port *port) 2134 2147 { 2135 2148 int ret; 2149 + enum typec_pwr_opmode opmode; 2136 2150 2137 2151 port->enter_state = port->state; 2138 2152 switch (port->state) { ··· 2223 2209 ret < 0 ? 0 : PD_T_PS_SOURCE_ON); 2224 2210 break; 2225 2211 case SRC_STARTUP: 2226 - typec_set_pwr_opmode(port->typec_port, TYPEC_PWR_MODE_USB); 2212 + opmode = tcpm_get_pwr_opmode(tcpm_rp_cc(port)); 2213 + typec_set_pwr_opmode(port->typec_port, opmode); 2227 2214 port->pwr_opmode = TYPEC_PWR_MODE_USB; 2228 2215 port->caps_count = 0; 2229 2216 port->message_id = 0; ··· 2386 2371 break; 2387 2372 case SNK_STARTUP: 2388 2373 /* XXX: callback into infrastructure */ 2389 - typec_set_pwr_opmode(port->typec_port, TYPEC_PWR_MODE_USB); 2374 + opmode = tcpm_get_pwr_opmode(port->polarity ? 2375 + port->cc2 : port->cc1); 2376 + typec_set_pwr_opmode(port->typec_port, opmode); 2390 2377 port->pwr_opmode = TYPEC_PWR_MODE_USB; 2391 2378 port->message_id = 0; 2392 2379 port->rx_msgid = -1;