Skip to contentSkip to conversation

usb: typec: tcpm: match source fixed pdo with sink variable pdo

RFC New Jun Li 1 participant 1 message Mar 13, 2018

Subsystems (2)
lore
Share & tools
lore

Jun Li

author
#0 lore raw

RFC 1/1 usb: typec: tcpm: match source fixed pdo with sink variable pdo

This patch tries to fix the problem describled on revert patch commit[1], suppose any supported voltage ranges of sink should be describled by variable pdo, so instead of revert the patch of only comparing source and sink pdo to select one source pdo, this patch adds the match between source fixed pdo and sink variable pdo.

[1] https://www.spinics.net/lists/linux-usb/msg166366.html

CC Hans de Goede <[email protected]>
CC Guenter Roeck <[email protected]>
CC Heikki Krogerus <[email protected]>
CC Adam Thomson <[email protected]>
CC Badhri Jagan Sridharan <[email protected]>
---
 drivers/usb/typec/tcpm.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/usb/typec/tcpm.c +31 -0
index ef3a60d..8a74a43 100644
@@ -1815,6 +1815,37 @@ static int tcpm_pd_select_pdo(struct tcpm_port *port, int *sink_pdo,
 					break;
 				}
 			}
+
+			/*
+			 * If the source pdo has the same voltage with one
+			 * fixed pdo, no need check variable pdo for it.
+			 */
+			if (j < port->nr_fixed)
+				continue;
+
+			for (j = port->nr_fixed +
+				 port->nr_batt;
+			     j < port->nr_fixed +
+				 port->nr_batt +
+				 port->nr_var;
+			     j++) {
+				if (pdo_fixed_voltage(pdo) >=
+				     pdo_min_voltage(port->snk_pdo[j]) &&
+				     pdo_fixed_voltage(pdo) <=
+				     pdo_max_voltage(port->snk_pdo[j])) {
+					ma = min_current(pdo, port->snk_pdo[j]);
+					mv = pdo_fixed_voltage(pdo);
+					mw = ma * mv / 1000;
+					if (mw > max_mw ||
+					    (mw == max_mw && mv > max_mv)) {
+						ret = 0;
+						*src_pdo = i;
+						*sink_pdo = j;
+						max_mw = mw;
+						max_mv = mv;
+					}
+				}
+			}
 		} else if (type == PDO_TYPE_BATT) {
 			for (j = port->nr_fixed;
 			     j < port->nr_fixed +