Browse Source

Partially implement vrange requests

Requests for fixed voltages are now made from the voltage range.  This
isn't a terrible behavior, but I might want to be able to make requests
from programmable supplies from the range as well.  'Twould be more
complicated though, and provide comparitively little benefit.  I'll
think about it, and maybe put out a request for comments.
Clara Hobbs 4 years ago
parent
commit
ea29fd0969
1 changed files with 35 additions and 0 deletions
  1. 35
    0
      src/device_policy_manager.c

+ 35
- 0
src/device_policy_manager.c View File

@@ -117,6 +117,41 @@ bool pdbs_dpm_evaluate_capability(struct pdb_config *cfg,
117 117
                 /* Update requested voltage */
118 118
                 dpm_data->_requested_voltage = PD_PRV2MV(PD_MV2PRV(scfg->v));
119 119
 
120
+                dpm_data->_capability_match = true;
121
+                return true;
122
+            }
123
+        }
124
+        /* Look at the PDOs a second time to see if one falls in our voltage
125
+         * range. */
126
+        for (uint8_t i = 0; i < numobj; i++) {
127
+            /* If we have a fixed PDO, its V equals our desired V, and its I is
128
+             * at least our desired I */
129
+            if ((capabilities->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED
130
+                    && PD_PDO_SRC_FIXED_CURRENT_GET(capabilities, i) >= scfg->i
131
+                    && PD_PDO_SRC_FIXED_VOLTAGE_GET(capabilities, i) >= PD_MV2PDV(scfg->vmin)
132
+                    && PD_PDO_SRC_FIXED_VOLTAGE_GET(capabilities, i) <= PD_MV2PDV(scfg->vmax)) {
133
+                /* We got what we wanted, so build a request for that */
134
+                request->hdr = cfg->pe.hdr_template | PD_MSGTYPE_REQUEST
135
+                    | PD_NUMOBJ(1);
136
+                if (scfg->flags & PDBS_CONFIG_FLAGS_GIVEBACK) {
137
+                    /* GiveBack enabled */
138
+                    request->obj[0] = PD_RDO_FV_MIN_CURRENT_SET(DPM_MIN_CURRENT)
139
+                        | PD_RDO_FV_CURRENT_SET(scfg->i)
140
+                        | PD_RDO_NO_USB_SUSPEND | PD_RDO_GIVEBACK
141
+                        | PD_RDO_OBJPOS_SET(i + 1);
142
+                } else {
143
+                    /* GiveBack disabled */
144
+                    request->obj[0] = PD_RDO_FV_MAX_CURRENT_SET(scfg->i)
145
+                        | PD_RDO_FV_CURRENT_SET(scfg->i)
146
+                        | PD_RDO_NO_USB_SUSPEND | PD_RDO_OBJPOS_SET(i + 1);
147
+                }
148
+                if (dpm_data->usb_comms) {
149
+                    request->obj[0] |= PD_RDO_USB_COMMS;
150
+                }
151
+
152
+                /* Update requested voltage */
153
+                dpm_data->_requested_voltage = PD_PDV2MV(PD_PDO_SRC_FIXED_VOLTAGE_GET(capabilities, i));
154
+
120 155
                 dpm_data->_capability_match = true;
121 156
                 return true;
122 157
             }

Loading…
Cancel
Save