Skip to contentSkip to conversation

usb: typec: tcpm: Extend the matching rules on PPS APDO selection

PATCH Superseded Kyle Tso 4 participants 8 messages Dec 17, 2018

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Kyle Tso

author
#0 lore raw

PATCH 1/1 usb: typec: tcpm: Extend the matching rules on PPS APDO selection

Current matching rules ensure that the voltage range of selected Source Capability is entirely within the range defined in one of the Sink Capabilities. This is reasonable but not practical because Sink may not support wide range of voltage when sinking power while Source could advertise its capabilities in raletively wider range. For example, a Source PDO advertising 3.3V-11V@3A (9V Prog of Fixed Nominal Voltage) will not be selected if the Sink requires 5V-12V@3A PPS power. However, the Sink could work well if the requested voltage range in RDOs is 5V-11V@3A.

Currently accepted:

		|--------- source -----|
	|----------- sink ---------------|

Currently not accepted:

			|--------- source -----|
	|----------- sink ---------------|
	|--------- source -----|
		|----------- sink ---------------|
	|--------- source -----------------|
		|------ sink -------|

To improve the usability, change the matching rules to what listed below:
a. The Source PDO is selectable if any portion of the voltage range
overlaps one of the Sink PDO's voltage range.
b. The maximum operational voltage will be the lower one between the
selected Source PDO and the matching Sink PDO.
c. The maximum power will be the maximum operational voltage times the
maximum current defined in the selected Source PDO
d. Select the Source PDO with the highest maximum power

---
Changelog since v1:
- updated the commit message as suggested by Guenter Roeck <[email protected]>

---
 drivers/usb/typec/tcpm/tcpm.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +17 -12
index 3620efee2688..3001df7bd602 100644
@@ -2213,7 +2213,8 @@ static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port)
 	unsigned int i, j, max_mw = 0, max_mv = 0;
 	unsigned int min_src_mv, max_src_mv, src_ma, src_mw;
 	unsigned int min_snk_mv, max_snk_mv;
-	u32 pdo;
+	unsigned int max_op_mv;
+	u32 pdo, src, snk;
 	unsigned int src_pdo = 0, snk_pdo = 0;
 
 	/*
@@ -2263,16 +2264,18 @@ static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port)
 					continue;
 				}
 
-				if (max_src_mv <= max_snk_mv &&
-				    min_src_mv >= min_snk_mv) {
+				if (min_src_mv <= max_snk_mv &&
+				    max_src_mv >= min_snk_mv) {
+					max_op_mv = min(max_src_mv, max_snk_mv);
+					src_mw = (max_op_mv * src_ma) / 1000;
 					/* Prefer higher voltages if available */
 					if ((src_mw == max_mw &&
-					     min_src_mv > max_mv) ||
+					     max_op_mv > max_mv) ||
 					    src_mw > max_mw) {
 						src_pdo = i;
 						snk_pdo = j;
 						max_mw = src_mw;
-						max_mv = max_src_mv;
+						max_mv = max_op_mv;
 					}
 				}
 			}
@@ -2285,14 +2288,16 @@ static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port)
 	}
 
 	if (src_pdo) {
-		pdo = port->source_caps[src_pdo];
-
-		port->pps_data.min_volt = pdo_pps_apdo_min_voltage(pdo);
-		port->pps_data.max_volt = pdo_pps_apdo_max_voltage(pdo);
-		port->pps_data.max_curr =
-			min_pps_apdo_current(pdo, port->snk_pdo[snk_pdo]);
+		src = port->source_caps[src_pdo];
+		snk = port->snk_pdo[snk_pdo];
+
+		port->pps_data.min_volt = max(pdo_pps_apdo_min_voltage(src),
+					      pdo_pps_apdo_min_voltage(snk));
+		port->pps_data.max_volt = min(pdo_pps_apdo_max_voltage(src),
+					      pdo_pps_apdo_max_voltage(snk));
+		port->pps_data.max_curr = min_pps_apdo_current(src, snk);
 		port->pps_data.out_volt =
-			min(pdo_pps_apdo_max_voltage(pdo), port->pps_data.out_volt);
+			min(port->pps_data.max_volt, port->pps_data.out_volt);
 		port->pps_data.op_curr =
 			min(port->pps_data.max_curr, port->pps_data.op_curr);
 	}
Reviewed-by on v1 1/1
#1 lore raw
Quoted 34 lines · Kyle Tso

Current matching rules ensure that the voltage range of selected Source Capability is entirely within the range defined in one of the Sink Capabilities. This is reasonable but not practical because Sink may not support wide range of voltage when sinking power while Source could advertise its capabilities in raletively wider range. For example, a Source PDO advertising 3.3V-11V@3A (9V Prog of Fixed Nominal Voltage) will not be selected if the Sink requires 5V-12V@3A PPS power. However, the Sink could work well if the requested voltage range in RDOs is 5V-11V@3A.

Currently accepted:

		|--------- source -----|
	|----------- sink ---------------|

Currently not accepted:

			|--------- source -----|
	|----------- sink ---------------|
	|--------- source -----|
		|----------- sink ---------------|
	|--------- source -----------------|
		|------ sink -------|

To improve the usability, change the matching rules to what listed below:
a. The Source PDO is selectable if any portion of the voltage range
overlaps one of the Sink PDO's voltage range.
b. The maximum operational voltage will be the lower one between the
selected Source PDO and the matching Sink PDO.
c. The maximum power will be the maximum operational voltage times the
maximum current defined in the selected Source PDO
d. Select the Source PDO with the highest maximum power

Quoted 1 line
Quoted 70 lines

---
Changelog since v1:
- updated the commit message as suggested by Guenter Roeck <[email protected]>

---
  drivers/usb/typec/tcpm/tcpm.c | 29 +++++++++++++++++------------
  1 file changed, 17 insertions(+), 12 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +17 -12
index 3620efee2688..3001df7bd602 100644
@@ -2213,7 +2213,8 @@ static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port)
  	unsigned int i, j, max_mw = 0, max_mv = 0;
  	unsigned int min_src_mv, max_src_mv, src_ma, src_mw;
  	unsigned int min_snk_mv, max_snk_mv;
-	u32 pdo;
+	unsigned int max_op_mv;
+	u32 pdo, src, snk;
  	unsigned int src_pdo = 0, snk_pdo = 0;
 
  	/*
@@ -2263,16 +2264,18 @@ static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port)
  					continue;
  				}
 
-				if (max_src_mv <= max_snk_mv &&
-				    min_src_mv >= min_snk_mv) {
+				if (min_src_mv <= max_snk_mv &&
+				    max_src_mv >= min_snk_mv) {
+					max_op_mv = min(max_src_mv, max_snk_mv);
+					src_mw = (max_op_mv * src_ma) / 1000;
  					/* Prefer higher voltages if available */
  					if ((src_mw == max_mw &&
-					     min_src_mv > max_mv) ||
+					     max_op_mv > max_mv) ||
  					    src_mw > max_mw) {
  						src_pdo = i;
  						snk_pdo = j;
  						max_mw = src_mw;
-						max_mv = max_src_mv;
+						max_mv = max_op_mv;
  					}
  				}
  			}
@@ -2285,14 +2288,16 @@ static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port)
  	}
 
  	if (src_pdo) {
-		pdo = port->source_caps[src_pdo];
-
-		port->pps_data.min_volt = pdo_pps_apdo_min_voltage(pdo);
-		port->pps_data.max_volt = pdo_pps_apdo_max_voltage(pdo);
-		port->pps_data.max_curr =
-			min_pps_apdo_current(pdo, port->snk_pdo[snk_pdo]);
+		src = port->source_caps[src_pdo];
+		snk = port->snk_pdo[snk_pdo];
+
+		port->pps_data.min_volt = max(pdo_pps_apdo_min_voltage(src),
+					      pdo_pps_apdo_min_voltage(snk));
+		port->pps_data.max_volt = min(pdo_pps_apdo_max_voltage(src),
+					      pdo_pps_apdo_max_voltage(snk));
+		port->pps_data.max_curr = min_pps_apdo_current(src, snk);
  		port->pps_data.out_volt =
-			min(pdo_pps_apdo_max_voltage(pdo), port->pps_data.out_volt);
+			min(port->pps_data.max_volt, port->pps_data.out_volt);
  		port->pps_data.op_curr =
  			min(port->pps_data.max_curr, port->pps_data.op_curr);
  	}
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Kyle Tso
Quoted 34 lines · Kyle Tso

Current matching rules ensure that the voltage range of selected Source Capability is entirely within the range defined in one of the Sink Capabilities. This is reasonable but not practical because Sink may not support wide range of voltage when sinking power while Source could advertise its capabilities in raletively wider range. For example, a Source PDO advertising 3.3V-11V@3A (9V Prog of Fixed Nominal Voltage) will not be selected if the Sink requires 5V-12V@3A PPS power. However, the Sink could work well if the requested voltage range in RDOs is 5V-11V@3A.

Currently accepted:

		|--------- source -----|
	|----------- sink ---------------|

Currently not accepted:

			|--------- source -----|
	|----------- sink ---------------|
	|--------- source -----|
		|----------- sink ---------------|
	|--------- source -----------------|
		|------ sink -------|

To improve the usability, change the matching rules to what listed below:
a. The Source PDO is selectable if any portion of the voltage range
overlaps one of the Sink PDO's voltage range.
b. The maximum operational voltage will be the lower one between the
selected Source PDO and the matching Sink PDO.
c. The maximum power will be the maximum operational voltage times the
maximum current defined in the selected Source PDO
d. Select the Source PDO with the highest maximum power

Quoted 1 line

In case you'll do one more version, I have a minor comment about the style below, but no need to resend only because of that.

Quoted 55 lines

---
Changelog since v1:
- updated the commit message as suggested by Guenter Roeck <[email protected]>

---
 drivers/usb/typec/tcpm/tcpm.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +9 -11
index 3620efee2688..3001df7bd602 100644
@@ -2213,7 +2213,8 @@ static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port)
 	unsigned int i, j, max_mw = 0, max_mv = 0;
 	unsigned int min_src_mv, max_src_mv, src_ma, src_mw;
 	unsigned int min_snk_mv, max_snk_mv;
-	u32 pdo;
+	unsigned int max_op_mv;
+	u32 pdo, src, snk;
 	unsigned int src_pdo = 0, snk_pdo = 0;
 
 	/*
@@ -2263,16 +2264,18 @@ static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port)
 					continue;
 				}
 
-				if (max_src_mv <= max_snk_mv &&
-				    min_src_mv >= min_snk_mv) {
+				if (min_src_mv <= max_snk_mv &&
+				    max_src_mv >= min_snk_mv) {
+					max_op_mv = min(max_src_mv, max_snk_mv);
+					src_mw = (max_op_mv * src_ma) / 1000;
 					/* Prefer higher voltages if available */
 					if ((src_mw == max_mw &&
-					     min_src_mv > max_mv) ||
+					     max_op_mv > max_mv) ||
 					    src_mw > max_mw) {
 						src_pdo = i;
 						snk_pdo = j;
 						max_mw = src_mw;
-						max_mv = max_src_mv;
+						max_mv = max_op_mv;
 					}
 				}
 			}
@@ -2285,14 +2288,16 @@ static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port)
 	}
 
 	if (src_pdo) {
-		pdo = port->source_caps[src_pdo];
-
-		port->pps_data.min_volt = pdo_pps_apdo_min_voltage(pdo);
-		port->pps_data.max_volt = pdo_pps_apdo_max_voltage(pdo);
-		port->pps_data.max_curr =
-			min_pps_apdo_current(pdo, port->snk_pdo[snk_pdo]);
+		src = port->source_caps[src_pdo];

drivers/usb/typec/tcpm/tcpm.c static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port) · line 2300

Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +8 -1
+		snk = port->snk_pdo[snk_pdo];
+
+		port->pps_data.min_volt = max(pdo_pps_apdo_min_voltage(src),
+					      pdo_pps_apdo_min_voltage(snk));
+		port->pps_data.max_volt = min(pdo_pps_apdo_max_voltage(src),
+					      pdo_pps_apdo_max_voltage(snk));
+		port->pps_data.max_curr = min_pps_apdo_current(src, snk);
 		port->pps_data.out_volt =
-			min(pdo_pps_apdo_max_voltage(pdo), port->pps_data.out_volt);
+			min(port->pps_data.max_volt, port->pps_data.out_volt);

While here, you could have aligned that like the above lines:

	port->pps_data.out_volt = min(pdo_pps_apdo_max_voltage(pdo),
                                      port->pps_data.out_volt);
Quoted 5 lines
drivers/usb/typec/tcpm/tcpm.c +0 -0
 		port->pps_data.op_curr =
 			min(port->pps_data.max_curr, port->pps_data.op_curr);
 	}
Signature · 1 line
2.20.0.405.gbc1bbc6f85-goog

thanks,

author
#3 lore raw
Quoted 111 lines · Heikki Krogerus
Quoted 34 lines · Kyle Tso

Current matching rules ensure that the voltage range of selected Source Capability is entirely within the range defined in one of the Sink Capabilities. This is reasonable but not practical because Sink may not support wide range of voltage when sinking power while Source could advertise its capabilities in raletively wider range. For example, a Source PDO advertising 3.3V-11V@3A (9V Prog of Fixed Nominal Voltage) will not be selected if the Sink requires 5V-12V@3A PPS power. However, the Sink could work well if the requested voltage range in RDOs is 5V-11V@3A.

Currently accepted:

              |--------- source -----|
      |----------- sink ---------------|

Currently not accepted:

                      |--------- source -----|
      |----------- sink ---------------|
      |--------- source -----|
              |----------- sink ---------------|
      |--------- source -----------------|
              |------ sink -------|

To improve the usability, change the matching rules to what listed below:
a. The Source PDO is selectable if any portion of the voltage range
overlaps one of the Sink PDO's voltage range.
b. The maximum operational voltage will be the lower one between the
selected Source PDO and the matching Sink PDO.
c. The maximum power will be the maximum operational voltage times the
maximum current defined in the selected Source PDO
d. Select the Source PDO with the highest maximum power

Quoted 1 line

In case you'll do one more version, I have a minor comment about the style below, but no need to resend only because of that.

Quoted 55 lines

---
Changelog since v1:
- updated the commit message as suggested by Guenter Roeck <[email protected]>

---
 drivers/usb/typec/tcpm/tcpm.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +9 -11
index 3620efee2688..3001df7bd602 100644
@@ -2213,7 +2213,8 @@ static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port)
      unsigned int i, j, max_mw = 0, max_mv = 0;
      unsigned int min_src_mv, max_src_mv, src_ma, src_mw;
      unsigned int min_snk_mv, max_snk_mv;
-     u32 pdo;
+     unsigned int max_op_mv;
+     u32 pdo, src, snk;
      unsigned int src_pdo = 0, snk_pdo = 0;
 
      /*
@@ -2263,16 +2264,18 @@ static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port)
                                      continue;
                              }
 
-                             if (max_src_mv <= max_snk_mv &&
-                                 min_src_mv >= min_snk_mv) {
+                             if (min_src_mv <= max_snk_mv &&
+                                 max_src_mv >= min_snk_mv) {
+                                     max_op_mv = min(max_src_mv, max_snk_mv);
+                                     src_mw = (max_op_mv * src_ma) / 1000;
                                      /* Prefer higher voltages if available */
                                      if ((src_mw == max_mw &&
-                                          min_src_mv > max_mv) ||
+                                          max_op_mv > max_mv) ||
                                          src_mw > max_mw) {
                                              src_pdo = i;
                                              snk_pdo = j;
                                              max_mw = src_mw;
-                                             max_mv = max_src_mv;
+                                             max_mv = max_op_mv;
                                      }
                              }
                      }
@@ -2285,14 +2288,16 @@ static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port)
      }
 
      if (src_pdo) {
-             pdo = port->source_caps[src_pdo];
-
-             port->pps_data.min_volt = pdo_pps_apdo_min_voltage(pdo);
-             port->pps_data.max_volt = pdo_pps_apdo_max_voltage(pdo);
-             port->pps_data.max_curr =
-                     min_pps_apdo_current(pdo, port->snk_pdo[snk_pdo]);
+             src = port->source_caps[src_pdo];

drivers/usb/typec/tcpm/tcpm.c static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port) · line 2300

Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +8 -1
+             snk = port->snk_pdo[snk_pdo];
+
+             port->pps_data.min_volt = max(pdo_pps_apdo_min_voltage(src),
+                                           pdo_pps_apdo_min_voltage(snk));
+             port->pps_data.max_volt = min(pdo_pps_apdo_max_voltage(src),
+                                           pdo_pps_apdo_max_voltage(snk));
+             port->pps_data.max_curr = min_pps_apdo_current(src, snk);
              port->pps_data.out_volt =
-                     min(pdo_pps_apdo_max_voltage(pdo), port->pps_data.out_volt);
+                     min(port->pps_data.max_volt, port->pps_data.out_volt);

While here, you could have aligned that like the above lines:

Quoted 3 lines
        port->pps_data.out_volt = min(pdo_pps_apdo_max_voltage(pdo),
                                      port->pps_data.out_volt);

Thanks Heikki Krogerus,
I will fix this (and the lines below as well) in the next (should be V3) patch.

Quoted 10 lines
Quoted 5 lines
drivers/usb/typec/tcpm/tcpm.c +0 -1
              port->pps_data.op_curr =
                      min(port->pps_data.max_curr, port->pps_data.op_curr);
      }
--

2.20.0.405.gbc1bbc6f85-goog

thanks,

--
heikki

#4 lore raw
In reply to Kyle Tso
Quoted 5 lines · Kyle Tso

Current matching rules ensure that the voltage range of selected Source Capability is entirely within the range defined in one of the Sink Capabilities. This is reasonable but not practical because Sink may not support wide range of voltage when sinking power while Source could advertise its capabilities in raletively wider range. For example, a Source PDO advertising 3.3V-11V@3A (9V

relatively

Quoted 60 lines

Prog of Fixed Nominal Voltage) will not be selected if the Sink requires 5V- 12V@3A PPS power. However, the Sink could work well if the requested voltage range in RDOs is 5V-11V@3A.

Currently accepted:

		|--------- source -----|
	|----------- sink ---------------|

Currently not accepted:

			|--------- source -----|
	|----------- sink ---------------|
	|--------- source -----|
		|----------- sink ---------------|
	|--------- source -----------------|
		|------ sink -------|

To improve the usability, change the matching rules to what listed below:
a. The Source PDO is selectable if any portion of the voltage range
overlaps one of the Sink PDO's voltage range.
b. The maximum operational voltage will be the lower one between the
selected Source PDO and the matching Sink PDO.
c. The maximum power will be the maximum operational voltage times the
maximum current defined in the selected Source PDO d. Select the Source PDO
with the highest maximum power

---
Changelog since v1:
- updated the commit message as suggested by Guenter Roeck <linux@roeck- us.net>

---
 drivers/usb/typec/tcpm/tcpm.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +2 -1
index 3620efee2688..3001df7bd602 100644
@@ -2213,7 +2213,8 @@ static unsigned int tcpm_pd_select_pps_apdo(struct
 tcpm_port *port)
 	unsigned int i, j, max_mw = 0, max_mv = 0;
 	unsigned int min_src_mv, max_src_mv, src_ma, src_mw;
 	unsigned int min_snk_mv, max_snk_mv;
-	u32 pdo;
+	unsigned int max_op_mv;
+	u32 pdo, src, snk;
 	unsigned int src_pdo = 0, snk_pdo = 0;
 
drivers/usb/typec/tcpm/tcpm.c +0 -2
 	/*
@@ -2263,16 +2264,18 @@ static unsigned int tcpm_pd_select_pps_apdo(struct
 tcpm_port *port)
 					continue;
 				}
 
-				if (max_src_mv <= max_snk_mv &&
-				    min_src_mv >= min_snk_mv) {

drivers/usb/typec/tcpm/tcpm.c static unsigned int tcpm_pd_select_pps_apdo(struct · line 2276

Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +5 -1
+				if (min_src_mv <= max_snk_mv &&
+				    max_src_mv >= min_snk_mv) {
+					max_op_mv = min(max_src_mv,
 max_snk_mv);
+					src_mw = (max_op_mv * src_ma) / 1000;
 					/* Prefer higher voltages if available */
 					if ((src_mw == max_mw &&
-					     min_src_mv > max_mv) ||
+					     max_op_mv > max_mv) ||
 					    src_mw > max_mw) {

Sorry I didn't raise this before, but came to mind this morning when I was considering your updates again. What happens if the Source validly provides two PPS APDOs, for example:

	3.3V - 11V, 3A (9V programmable)
	3.3V - 16V, 3A (15V programmable)

and the sink APDO is:

	5V - 9V, 3A

I think the code here will now select the higher range (15V programmable) as it gives a larger power output value, even if the sink can only support a voltage that's far smaller. I really don't think this is correct. *If* you are going to allow selection of PPS APDOs that provide a larger voltage range than the Sink can actually cope with, then I think you should at least select the lower of those advertised which fulfils the needs of the Sink.

Quoted 39 lines
drivers/usb/typec/tcpm/tcpm.c +1 -1
 						src_pdo = i;
 						snk_pdo = j;
 						max_mw = src_mw;
-						max_mv = max_src_mv;
+						max_mv = max_op_mv;
 					}
drivers/usb/typec/tcpm/tcpm.c +8 -7
 				}
 			}
@@ -2285,14 +2288,16 @@ static unsigned int tcpm_pd_select_pps_apdo(struct
 tcpm_port *port)
 	}
 
 	if (src_pdo) {
-		pdo = port->source_caps[src_pdo];
-
-		port->pps_data.min_volt = pdo_pps_apdo_min_voltage(pdo);
-		port->pps_data.max_volt = pdo_pps_apdo_max_voltage(pdo);
-		port->pps_data.max_curr =
-			min_pps_apdo_current(pdo, port->snk_pdo[snk_pdo]);
+		src = port->source_caps[src_pdo];
+		snk = port->snk_pdo[snk_pdo];
+
+		port->pps_data.min_volt =
 max(pdo_pps_apdo_min_voltage(src),
+					      pdo_pps_apdo_min_voltage(snk));
+		port->pps_data.max_volt =
 min(pdo_pps_apdo_max_voltage(src),
+					      pdo_pps_apdo_max_voltage(snk));
+		port->pps_data.max_curr = min_pps_apdo_current(src, snk);
 		port->pps_data.out_volt =
-			min(pdo_pps_apdo_max_voltage(pdo), port-
Quoted 1 line

pps_data.out_volt);

drivers/usb/typec/tcpm/tcpm.c +1 -0
+			min(port->pps_data.max_volt, port-
Quoted 1 line

pps_data.out_volt);

drivers/usb/typec/tcpm/tcpm.c +0 -1
 		port->pps_data.op_curr =
 			min(port->pps_data.max_curr, port->pps_data.op_curr);
 	}
--

2.20.0.405.gbc1bbc6f85-goog

author
#5 lore raw
Quoted 11 lines · Adam Thomson
Quoted 5 lines · Kyle Tso

Current matching rules ensure that the voltage range of selected Source Capability is entirely within the range defined in one of the Sink Capabilities. This is reasonable but not practical because Sink may not support wide range of voltage when sinking power while Source could advertise its capabilities in raletively wider range. For example, a Source PDO advertising 3.3V-11V@3A (9V

relatively

noted!
Thanks for the correction. I will fix this in the next patch.

Quoted 80 lines
Quoted 60 lines

Prog of Fixed Nominal Voltage) will not be selected if the Sink requires 5V- 12V@3A PPS power. However, the Sink could work well if the requested voltage range in RDOs is 5V-11V@3A.

Currently accepted:

              |--------- source -----|
      |----------- sink ---------------|

Currently not accepted:

                      |--------- source -----|
      |----------- sink ---------------|
      |--------- source -----|
              |----------- sink ---------------|
      |--------- source -----------------|
              |------ sink -------|

To improve the usability, change the matching rules to what listed below:
a. The Source PDO is selectable if any portion of the voltage range
overlaps one of the Sink PDO's voltage range.
b. The maximum operational voltage will be the lower one between the
selected Source PDO and the matching Sink PDO.
c. The maximum power will be the maximum operational voltage times the
maximum current defined in the selected Source PDO d. Select the Source PDO
with the highest maximum power

---
Changelog since v1:
- updated the commit message as suggested by Guenter Roeck <linux@roeck- us.net>

---
 drivers/usb/typec/tcpm/tcpm.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +2 -1
index 3620efee2688..3001df7bd602 100644
@@ -2213,7 +2213,8 @@ static unsigned int tcpm_pd_select_pps_apdo(struct
 tcpm_port *port)
      unsigned int i, j, max_mw = 0, max_mv = 0;
      unsigned int min_src_mv, max_src_mv, src_ma, src_mw;
      unsigned int min_snk_mv, max_snk_mv;
-     u32 pdo;
+     unsigned int max_op_mv;
+     u32 pdo, src, snk;
      unsigned int src_pdo = 0, snk_pdo = 0;
 
      /*
drivers/usb/typec/tcpm/tcpm.c +0 -2
@@ -2263,16 +2264,18 @@ static unsigned int tcpm_pd_select_pps_apdo(struct
 tcpm_port *port)
                                      continue;
                              }
 
-                             if (max_src_mv <= max_snk_mv &&
-                                 min_src_mv >= min_snk_mv) {

drivers/usb/typec/tcpm/tcpm.c static unsigned int tcpm_pd_select_pps_apdo(struct · line 2276

Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +5 -1
+                             if (min_src_mv <= max_snk_mv &&
+                                 max_src_mv >= min_snk_mv) {
+                                     max_op_mv = min(max_src_mv,
 max_snk_mv);
+                                     src_mw = (max_op_mv * src_ma) / 1000;
                                      /* Prefer higher voltages if available */
                                      if ((src_mw == max_mw &&
-                                          min_src_mv > max_mv) ||
+                                          max_op_mv > max_mv) ||
                                          src_mw > max_mw) {

Sorry I didn't raise this before, but came to mind this morning when I was considering your updates again. What happens if the Source validly provides two PPS APDOs, for example:

        3.3V - 11V, 3A (9V programmable)
        3.3V - 16V, 3A (15V programmable)

and the sink APDO is:

Quoted 8 lines
        5V - 9V, 3A

I think the code here will now select the higher range (15V programmable) as it gives a larger power output value, even if the sink can only support a voltage that's far smaller. I really don't think this is correct. *If* you are going to allow selection of PPS APDOs that provide a larger voltage range than the Sink can actually cope with, then I think you should at least select the lower of those advertised which fulfils the needs of the Sink.

Source:
3.3V - 11V, 3A (9V programmable)
3.3V - 16V, 3A (15V programmable)

Sink
5V - 9V, 3A

In this case, the Sink will select "3.3V - 11V, 3A (9V programmable)" because the
"max_op_mv" when dealing with both Source Cap will be the same.

See line#2269, "max_op_mv" will be limited by "max_snk_mv" which is 9V. And in line#2273, "max_op_mv" (of the second src_cap) fails the check because "max_mv", which is equal to the "max_op_mv" of the previous src_cap, is the same as it.

2267 if (min_src_mv <= max_snk_mv &&
2268 max_src_mv >= min_snk_mv) {
2269 max_op_mv = min(max_src_mv,
max_snk_mv);
2270 src_mw = (max_op_mv * src_ma) / 1000;
2271 /* Prefer higher voltages if
available */
2272 if ((src_mw == max_mw &&
2273 max_op_mv > max_mv) ||
2274 src_mw > max_mw) {

2275                                             src_pdo = i;
2276                                             snk_pdo = j;
2277                                             max_mw = src_mw;
2278                                             max_mv = max_op_mv;

2279 }
2280 }

Quoted 41 lines
Quoted 40 lines
drivers/usb/typec/tcpm/tcpm.c +1 -1
                                              src_pdo = i;
                                              snk_pdo = j;
                                              max_mw = src_mw;
-                                             max_mv = max_src_mv;
+                                             max_mv = max_op_mv;
                                      }
                              }
                      }
drivers/usb/typec/tcpm/tcpm.c +8 -7
@@ -2285,14 +2288,16 @@ static unsigned int tcpm_pd_select_pps_apdo(struct
 tcpm_port *port)
      }
 
      if (src_pdo) {
-             pdo = port->source_caps[src_pdo];
-
-             port->pps_data.min_volt = pdo_pps_apdo_min_voltage(pdo);
-             port->pps_data.max_volt = pdo_pps_apdo_max_voltage(pdo);
-             port->pps_data.max_curr =
-                     min_pps_apdo_current(pdo, port->snk_pdo[snk_pdo]);
+             src = port->source_caps[src_pdo];
+             snk = port->snk_pdo[snk_pdo];
+
+             port->pps_data.min_volt =
 max(pdo_pps_apdo_min_voltage(src),
+                                           pdo_pps_apdo_min_voltage(snk));
+             port->pps_data.max_volt =
 min(pdo_pps_apdo_max_voltage(src),
+                                           pdo_pps_apdo_max_voltage(snk));
+             port->pps_data.max_curr = min_pps_apdo_current(src, snk);
              port->pps_data.out_volt =
-                     min(pdo_pps_apdo_max_voltage(pdo), port-
Quoted 1 line

pps_data.out_volt);

+ min(port->pps_data.max_volt, port-

Quoted 1 line

pps_data.out_volt);

              port->pps_data.op_curr =
                      min(port->pps_data.max_curr, port->pps_data.op_curr);
      }

--
2.20.0.405.gbc1bbc6f85-goog

author
#6 lore raw
Quoted 114 lines · Kyle Tso
Quoted 11 lines · Adam Thomson
Quoted 5 lines · Kyle Tso

Current matching rules ensure that the voltage range of selected Source Capability is entirely within the range defined in one of the Sink Capabilities. This is reasonable but not practical because Sink may not support wide range of voltage when sinking power while Source could advertise its capabilities in raletively wider range. For example, a Source PDO advertising 3.3V-11V@3A (9V

relatively

noted!
Thanks for the correction. I will fix this in the next patch.

Quoted 80 lines
Quoted 60 lines

Prog of Fixed Nominal Voltage) will not be selected if the Sink requires 5V- 12V@3A PPS power. However, the Sink could work well if the requested voltage range in RDOs is 5V-11V@3A.

Currently accepted:

              |--------- source -----|
      |----------- sink ---------------|

Currently not accepted:

                      |--------- source -----|
      |----------- sink ---------------|
      |--------- source -----|
              |----------- sink ---------------|
      |--------- source -----------------|
              |------ sink -------|

To improve the usability, change the matching rules to what listed below:
a. The Source PDO is selectable if any portion of the voltage range
overlaps one of the Sink PDO's voltage range.
b. The maximum operational voltage will be the lower one between the
selected Source PDO and the matching Sink PDO.
c. The maximum power will be the maximum operational voltage times the
maximum current defined in the selected Source PDO d. Select the Source PDO
with the highest maximum power

---
Changelog since v1:
- updated the commit message as suggested by Guenter Roeck <linux@roeck- us.net>

---
 drivers/usb/typec/tcpm/tcpm.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +2 -1
index 3620efee2688..3001df7bd602 100644
@@ -2213,7 +2213,8 @@ static unsigned int tcpm_pd_select_pps_apdo(struct
 tcpm_port *port)
      unsigned int i, j, max_mw = 0, max_mv = 0;
      unsigned int min_src_mv, max_src_mv, src_ma, src_mw;
      unsigned int min_snk_mv, max_snk_mv;
-     u32 pdo;
+     unsigned int max_op_mv;
+     u32 pdo, src, snk;
      unsigned int src_pdo = 0, snk_pdo = 0;
 
      /*
drivers/usb/typec/tcpm/tcpm.c +0 -2
@@ -2263,16 +2264,18 @@ static unsigned int tcpm_pd_select_pps_apdo(struct
 tcpm_port *port)
                                      continue;
                              }
 
-                             if (max_src_mv <= max_snk_mv &&
-                                 min_src_mv >= min_snk_mv) {

drivers/usb/typec/tcpm/tcpm.c static unsigned int tcpm_pd_select_pps_apdo(struct · line 2276

Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +5 -1
+                             if (min_src_mv <= max_snk_mv &&
+                                 max_src_mv >= min_snk_mv) {
+                                     max_op_mv = min(max_src_mv,
 max_snk_mv);
+                                     src_mw = (max_op_mv * src_ma) / 1000;
                                      /* Prefer higher voltages if available */
                                      if ((src_mw == max_mw &&
-                                          min_src_mv > max_mv) ||
+                                          max_op_mv > max_mv) ||
                                          src_mw > max_mw) {

Sorry I didn't raise this before, but came to mind this morning when I was considering your updates again. What happens if the Source validly provides two PPS APDOs, for example:

        3.3V - 11V, 3A (9V programmable)
        3.3V - 16V, 3A (15V programmable)

and the sink APDO is:

Quoted 8 lines
        5V - 9V, 3A

I think the code here will now select the higher range (15V programmable) as it gives a larger power output value, even if the sink can only support a voltage that's far smaller. I really don't think this is correct. *If* you are going to allow selection of PPS APDOs that provide a larger voltage range than the Sink can actually cope with, then I think you should at least select the lower of those advertised which fulfils the needs of the Sink.

Source:
3.3V - 11V, 3A (9V programmable)
3.3V - 16V, 3A (15V programmable)

Sink
5V - 9V, 3A

Quoted 9 lines

In this case, the Sink will select "3.3V - 11V, 3A (9V programmable)" because the
"max_op_mv" when dealing with both Source Cap will be the same.

See line#2269, "max_op_mv" will be limited by "max_snk_mv" which is 9V. And in line#2273, "max_op_mv" (of the second src_cap) fails the check because "max_mv", which is equal to the "max_op_mv" of the previous src_cap, is the same as it.

Sorry, I should have explained more clearer here.
"max_op_mv" and "src_mw" are both limited to "max_snk_mv" (9V) in this case. Therefore in the following "if" statement (line#2272 to line#2274), both "src_mw" and "max_op_mv" remain the same as those regarding to the previous src_cap. So the "if" statement will be "false".
==> select the previous src_cap

Quoted 58 lines

2267 if (min_src_mv <= max_snk_mv &&
2268 max_src_mv >= min_snk_mv) {
2269 max_op_mv = min(max_src_mv,
max_snk_mv);
2270 src_mw = (max_op_mv * src_ma) / 1000;
2271 /* Prefer higher voltages if
available */
2272 if ((src_mw == max_mw &&
2273 max_op_mv > max_mv) ||
2274 src_mw > max_mw) {

2275                                             src_pdo = i;
2276                                             snk_pdo = j;
2277                                             max_mw = src_mw;
2278                                             max_mv = max_op_mv;

2279 }
2280 }

Quoted 41 lines
Quoted 40 lines
drivers/usb/typec/tcpm/tcpm.c +1 -1
                                              src_pdo = i;
                                              snk_pdo = j;
                                              max_mw = src_mw;
-                                             max_mv = max_src_mv;
+                                             max_mv = max_op_mv;
                                      }
                              }
                      }
drivers/usb/typec/tcpm/tcpm.c +8 -7
@@ -2285,14 +2288,16 @@ static unsigned int tcpm_pd_select_pps_apdo(struct
 tcpm_port *port)
      }
 
      if (src_pdo) {
-             pdo = port->source_caps[src_pdo];
-
-             port->pps_data.min_volt = pdo_pps_apdo_min_voltage(pdo);
-             port->pps_data.max_volt = pdo_pps_apdo_max_voltage(pdo);
-             port->pps_data.max_curr =
-                     min_pps_apdo_current(pdo, port->snk_pdo[snk_pdo]);
+             src = port->source_caps[src_pdo];
+             snk = port->snk_pdo[snk_pdo];
+
+             port->pps_data.min_volt =
 max(pdo_pps_apdo_min_voltage(src),
+                                           pdo_pps_apdo_min_voltage(snk));
+             port->pps_data.max_volt =
 min(pdo_pps_apdo_max_voltage(src),
+                                           pdo_pps_apdo_max_voltage(snk));
+             port->pps_data.max_curr = min_pps_apdo_current(src, snk);
              port->pps_data.out_volt =
-                     min(pdo_pps_apdo_max_voltage(pdo), port-
Quoted 1 line

pps_data.out_volt);

+ min(port->pps_data.max_volt, port-

Quoted 1 line

pps_data.out_volt);

              port->pps_data.op_curr =
                      min(port->pps_data.max_curr, port->pps_data.op_curr);
      }

--
2.20.0.405.gbc1bbc6f85-goog

#7 lore raw
In reply to Kyle Tso
Quoted 117 lines · Kyle Tso
Quoted 12 lines · Adam Thomson
Quoted 6 lines · Kyle Tso

Current matching rules ensure that the voltage range of selected Source Capability is entirely within the range defined in one of the Sink Capabilities. This is reasonable but not practical because Sink may not support wide range of voltage when sinking power while Source could advertise its capabilities in raletively wider range. For example, a Source PDO advertising 3.3V-11V@3A (9V

relatively

noted!
Thanks for the correction. I will fix this in the next patch.

Quoted 82 lines
Quoted 62 lines

Prog of Fixed Nominal Voltage) will not be selected if the Sink requires 5V- 12V@3A PPS power. However, the Sink could work well if the requested voltage range in RDOs is 5V-11V@3A.

Currently accepted:

              |--------- source -----|
      |----------- sink ---------------|

Currently not accepted:

                      |--------- source -----|
      |----------- sink ---------------|
      |--------- source -----|
              |----------- sink ---------------|
      |--------- source -----------------|
              |------ sink -------|

To improve the usability, change the matching rules to what listed below:
a. The Source PDO is selectable if any portion of the voltage range
overlaps one of the Sink PDO's voltage range.
b. The maximum operational voltage will be the lower one between the
selected Source PDO and the matching Sink PDO.
c. The maximum power will be the maximum operational voltage times the
maximum current defined in the selected Source PDO d. Select the
Source PDO with the highest maximum power

---
Changelog since v1:
- updated the commit message as suggested by Guenter Roeck <linux@roeck- us.net>

---
 drivers/usb/typec/tcpm/tcpm.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/drivers/usb/typec/tcpm/tcpm.c index 3620efee2688..3001df7bd602 100644

drivers/usb/typec/tcpm/tcpm.c +2 -1
@@ -2213,7 +2213,8 @@ static unsigned int
 tcpm_pd_select_pps_apdo(struct tcpm_port *port)
      unsigned int i, j, max_mw = 0, max_mv = 0;
      unsigned int min_src_mv, max_src_mv, src_ma, src_mw;
      unsigned int min_snk_mv, max_snk_mv;
-     u32 pdo;
+     unsigned int max_op_mv;
+     u32 pdo, src, snk;
      unsigned int src_pdo = 0, snk_pdo = 0;
 
      /*
drivers/usb/typec/tcpm/tcpm.c +1 -2
@@ -2263,16 +2264,18 @@ static unsigned int
 tcpm_pd_select_pps_apdo(struct tcpm_port *port)
                                      continue;
                              }
 
-                             if (max_src_mv <= max_snk_mv &&
-                                 min_src_mv >= min_snk_mv) {
+                             if (min_src_mv <= max_snk_mv &&

drivers/usb/typec/tcpm/tcpm.c static unsigned int · line 2277

Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +5 -1
+                                 max_src_mv >= min_snk_mv) {
+                                     max_op_mv = min(max_src_mv,
 max_snk_mv);
+                                     src_mw = (max_op_mv * src_ma)
+ / 1000;
                                      /* Prefer higher voltages if available */
                                      if ((src_mw == max_mw &&
-                                          min_src_mv > max_mv) ||
+                                          max_op_mv > max_mv) ||
                                          src_mw > max_mw) {

Sorry I didn't raise this before, but came to mind this morning when I was considering your updates again. What happens if the Source validly provides two PPS APDOs, for example:

        3.3V - 11V, 3A (9V programmable)
        3.3V - 16V, 3A (15V programmable)

and the sink APDO is:

Quoted 8 lines
        5V - 9V, 3A

I think the code here will now select the higher range (15V programmable) as it gives a larger power output value, even if the sink can only support a voltage that's far smaller. I really don't think this is correct. *If* you are going to allow selection of PPS APDOs that provide a larger voltage range than the Sink can actually cope with, then I think you should at least select the lower of those advertised

which fulfils the needs of the Sink.

Source:
3.3V - 11V, 3A (9V programmable)
3.3V - 16V, 3A (15V programmable)

Sink
5V - 9V, 3A

Quoted 8 lines

In this case, the Sink will select "3.3V - 11V, 3A (9V programmable)" because the
"max_op_mv" when dealing with both Source Cap will be the same.

See line#2269, "max_op_mv" will be limited by "max_snk_mv" which is 9V. And in line#2273, "max_op_mv" (of the second src_cap) fails the check because "max_mv", which is equal to the "max_op_mv" of the previous src_cap, is the same as it.

Ok, yes I missed the re-calculation of src_mw on line 2270. Apologies.

Quoted 60 lines

2267 if (min_src_mv <= max_snk_mv &&
2268 max_src_mv >= min_snk_mv) {
2269 max_op_mv = min(max_src_mv,
max_snk_mv);
2270 src_mw = (max_op_mv * src_ma) / 1000;
2271 /* Prefer higher voltages if
available */
2272 if ((src_mw == max_mw &&
2273 max_op_mv > max_mv) ||
2274 src_mw > max_mw) {

2275                                             src_pdo = i;
2276                                             snk_pdo = j;
2277                                             max_mw = src_mw;
2278                                             max_mv = max_op_mv;

2279 }
2280 }

Quoted 42 lines
Quoted 41 lines
drivers/usb/typec/tcpm/tcpm.c +10 -8
                                              src_pdo = i;
                                              snk_pdo = j;
                                              max_mw = src_mw;
-                                             max_mv = max_src_mv;
+                                             max_mv = max_op_mv;
                                      }
                              }
                      }
@@ -2285,14 +2288,16 @@ static unsigned int
 tcpm_pd_select_pps_apdo(struct tcpm_port *port)
      }
 
      if (src_pdo) {
-             pdo = port->source_caps[src_pdo];
-
-             port->pps_data.min_volt = pdo_pps_apdo_min_voltage(pdo);
-             port->pps_data.max_volt = pdo_pps_apdo_max_voltage(pdo);
-             port->pps_data.max_curr =
-                     min_pps_apdo_current(pdo, port->snk_pdo[snk_pdo]);
+             src = port->source_caps[src_pdo];
+             snk = port->snk_pdo[snk_pdo];
+
+             port->pps_data.min_volt =
 max(pdo_pps_apdo_min_voltage(src),
+                                           pdo_pps_apdo_min_voltage(snk));
+             port->pps_data.max_volt =
 min(pdo_pps_apdo_max_voltage(src),
+                                           pdo_pps_apdo_max_voltage(snk));
+             port->pps_data.max_curr = min_pps_apdo_current(src,
+ snk);
              port->pps_data.out_volt =
-                     min(pdo_pps_apdo_max_voltage(pdo), port-
Quoted 1 line

pps_data.out_volt);

+ min(port->pps_data.max_volt, port-

Quoted 1 line

pps_data.out_volt);

              port->pps_data.op_curr =
                      min(port->pps_data.max_curr, port->pps_data.op_curr);
      }

--
2.20.0.405.gbc1bbc6f85-goog