usb: typec: tcpm: Address incorrect values of tcpm psy for fixed supply

commit f3dedafb8263ca4791a92a23f5230068f5bde008 upstream.

tcpm_pd_build_request overwrites current_limit and supply_voltage
even before port partner accepts the requests. This leaves stale
values in current_limit and supply_voltage that get exported by
"tcpm-source-psy-". Solving this problem by caching the request
values of current limit/supply voltage in req_current_limit
and req_supply_voltage. current_limit/supply_voltage gets updated
once the port partner accepts the request.

Fixes: f2a8aa053c ("typec: tcpm: Represent source supply through power_supply")
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
Cc: stable <stable@vger.kernel.org>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20210407200723.1914388-1-badhri@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Badhri Jagan Sridharan 2021-04-07 13:07:18 -07:00 committed by Greg Kroah-Hartman
parent 0dace269aa
commit 79cae796db

View File

@ -326,7 +326,10 @@ struct tcpm_port {
unsigned int operating_snk_mw;
bool update_sink_caps;
/* Requested current / voltage */
/* Requested current / voltage to the port partner */
u32 req_current_limit;
u32 req_supply_voltage;
/* Actual current / voltage limit of the local port */
u32 current_limit;
u32 supply_voltage;
@ -1873,8 +1876,8 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,
case SNK_TRANSITION_SINK:
if (port->vbus_present) {
tcpm_set_current_limit(port,
port->current_limit,
port->supply_voltage);
port->req_current_limit,
port->req_supply_voltage);
port->explicit_contract = true;
tcpm_set_state(port, SNK_READY, 0);
} else {
@ -1956,8 +1959,8 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,
break;
case SNK_NEGOTIATE_PPS_CAPABILITIES:
port->pps_data.active = true;
port->supply_voltage = port->pps_data.out_volt;
port->current_limit = port->pps_data.op_curr;
port->req_supply_voltage = port->pps_data.out_volt;
port->req_current_limit = port->pps_data.op_curr;
tcpm_set_state(port, SNK_TRANSITION_SINK, 0);
break;
case SOFT_RESET_SEND:
@ -2564,8 +2567,8 @@ static int tcpm_pd_build_request(struct tcpm_port *port, u32 *rdo)
flags & RDO_CAP_MISMATCH ? " [mismatch]" : "");
}
port->current_limit = ma;
port->supply_voltage = mv;
port->req_current_limit = ma;
port->req_supply_voltage = mv;
return 0;
}