summaryrefslogtreecommitdiff
path: root/board/hoho/usb_pd_policy.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/hoho/usb_pd_policy.c')
-rw-r--r--board/hoho/usb_pd_policy.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/board/hoho/usb_pd_policy.c b/board/hoho/usb_pd_policy.c
index b1279d76a9..252bef6ac7 100644
--- a/board/hoho/usb_pd_policy.c
+++ b/board/hoho/usb_pd_policy.c
@@ -25,6 +25,11 @@
const uint32_t pd_src_pdo[] = {};
const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo);
+/* Define typical operating power and max power */
+#define OPERATING_POWER_MW 1000
+#define MAX_POWER_MW 1500
+#define MAX_CURRENT_MA 300
+
/* Fake PDOs : we just want our pre-defined voltages */
const uint32_t pd_snk_pdo[] = {
PDO_FIXED(5000, 500, 0),
@@ -43,6 +48,8 @@ int pd_choose_voltage(int cnt, uint32_t *src_caps, uint32_t *rdo,
int i;
int ma;
int set_mv = select_mv;
+ int max;
+ uint32_t flags;
/* Default to 5V */
if (set_mv <= 0)
@@ -58,11 +65,19 @@ int pd_choose_voltage(int cnt, uint32_t *src_caps, uint32_t *rdo,
if (i < 0)
return -EC_ERROR_UNKNOWN;
- /* request all the power ... */
+ /* build rdo for desired power */
ma = 10 * (src_caps[i] & 0x3FF);
- *rdo = RDO_FIXED(i + 1, ma, ma, 0);
- CPRINTF("Request [%d] %dV %dmA\n", i, set_mv/1000, ma);
- *curr_limit = ma;
+ max = MIN(ma, MAX_CURRENT_MA);
+ flags = (max * set_mv) < (1000 * OPERATING_POWER_MW) ?
+ RDO_CAP_MISMATCH : 0;
+ *rdo = RDO_FIXED(i + 1, max, max, 0);
+ CPRINTF("Request [%d] %dV %dmA", i, set_mv/1000, max);
+ /* Mismatch bit set if less power offered than the operating power */
+ if (flags & RDO_CAP_MISMATCH)
+ CPRINTF(" Mismatch");
+ CPRINTF("\n");
+
+ *curr_limit = max;
*supply_voltage = set_mv;
return EC_SUCCESS;
}