Browse Source

Request less power when output is disabled

Since the spec says we Shall request no more power than we actually
need, we were violating the spec whenever the output was disabled in
Setup mode.  This commit fixes that, requesting low current at 5 V when
the output is disabled.

We do play a little fast and loose with the MAX_CURRENT field, but
that's hard to avoid in a device like this.  Well, we could always set
it to 5 A in Setup mode to be safe, but that's not necessarily right
either.  At least it's still honest in Sink mode, which I consider more
important anyway.
Clara Hobbs 7 years ago
parent
commit
df43d1c5a1
1 changed files with 10 additions and 3 deletions
  1. 10
    3
      src/device_policy_manager.c

+ 10
- 3
src/device_policy_manager.c View File

@@ -74,7 +74,7 @@ bool pdb_dpm_evaluate_capability(const union pd_msg *capabilities, union pd_msg
74 74
     dpm_unconstrained_power = capabilities->obj[0] & PD_PDO_SRC_FIXED_UNCONSTRAINED;
75 75
 
76 76
     /* Make sure we have configuration */
77
-    if (cfg != NULL) {
77
+    if (cfg != NULL && pdb_dpm_output_enabled) {
78 78
         /* Look at the PDOs to see if one matches our desires */
79 79
         for (uint8_t i = 0; i < numobj; i++) {
80 80
             /* Fixed Supply PDOs come first, so when we see a PDO that isn't a
@@ -117,8 +117,14 @@ bool pdb_dpm_evaluate_capability(const union pd_msg *capabilities, union pd_msg
117 117
         PD_SPECREV_2_0 | PD_POWERROLE_SINK | PD_NUMOBJ(1);
118 118
     request->obj[0] = PD_RDO_FV_MAX_CURRENT_SET(DPM_MIN_CURRENT)
119 119
         | PD_RDO_FV_CURRENT_SET(DPM_MIN_CURRENT)
120
-        | PD_RDO_NO_USB_SUSPEND | PD_RDO_CAP_MISMATCH
120
+        | PD_RDO_NO_USB_SUSPEND
121 121
         | PD_RDO_OBJPOS_SET(1);
122
+    /* If the output is enabled and we got here, it must be a capability
123
+     * mismatch. */
124
+    if (pdb_dpm_output_enabled) {
125
+        request->obj[0] |= PD_RDO_CAP_MISMATCH;
126
+    }
127
+    /* If we can do USB communications, tell the power supply */
122 128
     if (pdb_dpm_usb_comms) {
123 129
         request->obj[0] |= PD_RDO_USB_COMMS;
124 130
     }
@@ -126,7 +132,8 @@ bool pdb_dpm_evaluate_capability(const union pd_msg *capabilities, union pd_msg
126 132
     /* Update requested voltage */
127 133
     dpm_requested_voltage = PD_MV2PDV(5000);
128 134
 
129
-    return false;
135
+    /* At this point, we have a capability match iff the output is disabled */
136
+    return !pdb_dpm_output_enabled;
130 137
 }
131 138
 
132 139
 void pdb_dpm_get_sink_capability(union pd_msg *cap)

Loading…
Cancel
Save