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

usb: typec: tcpm: Correct the PPS out_volt calculation

When Sink negotiates PPS, the voltage range of selected PPS APDO might
not cover the previous voltage (out_volt). If the previous out_volt is
lower than the new min_volt, the output voltage in RDO might be set to
an invalid value. For instance, supposed that the previous voltage is
5V, and the new voltage range in the APDO is 7V-12V. Then the output
voltage in the RDO should not be set to 5V which is lower than the
possible min_volt 7V.

Fix this by choosing the maximal value between the previous voltage and
the new min_volt first. And ensure that this value will not exceed the
new max_volt. The new out_volt will fall within the new voltage range
while being the closest value compared to the previous out_volt.

Signed-off-by: Kyle Tso <kyletso@google.com>
Reviewed-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Fixes: c710d0bb76ff0 ("usb: typec: tcpm: Extend the matching rules on PPS APDO selection")
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Kyle Tso and committed by
Greg Kroah-Hartman
a07ddce4 c7b0c3bb

+2 -1
+2 -1
drivers/usb/typec/tcpm/tcpm.c
··· 2297 2297 pdo_pps_apdo_max_voltage(snk)); 2298 2298 port->pps_data.max_curr = min_pps_apdo_current(src, snk); 2299 2299 port->pps_data.out_volt = min(port->pps_data.max_volt, 2300 - port->pps_data.out_volt); 2300 + max(port->pps_data.min_volt, 2301 + port->pps_data.out_volt)); 2301 2302 port->pps_data.op_curr = min(port->pps_data.max_curr, 2302 2303 port->pps_data.op_curr); 2303 2304 }