summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zephyr/projects/nissa/src/nereid/usbc.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/zephyr/projects/nissa/src/nereid/usbc.c b/zephyr/projects/nissa/src/nereid/usbc.c
index e731b73a76..eeab449c32 100644
--- a/zephyr/projects/nissa/src/nereid/usbc.c
+++ b/zephyr/projects/nissa/src/nereid/usbc.c
@@ -63,22 +63,19 @@ void board_pd_vconn_ctrl(int port, enum usbpd_cc_pin cc_pin, int enabled)
__override bool pd_check_vbus_level(int port, enum vbus_level level)
{
- /*
- * While the charger can differentiate SAFE0V from REMOVED, doing so
- * requires doing a I2C read of the VBUS analog level. Because this
- * function can be polled by the USB state machines and doing the I2C
- * read is relatively costly, we only check the cached VBUS presence
- * (for which interrupts record transitions).
- */
- switch (level) {
- case VBUS_PRESENT:
- return sm5803_is_vbus_present(port);
- case VBUS_SAFE0V: /* Less than vSafe0V */
- case VBUS_REMOVED: /* Less than vSinkDisconnect */
- return !sm5803_is_vbus_present(port);
+ int vbus_voltage;
+
+ /* If we're unable to speak to the charger, best to guess false */
+ if (charger_get_vbus_voltage(port, &vbus_voltage)) {
+ return false;
}
- LOG_WRN("Unrecognized vbus_level value: %d", level);
- return false;
+
+ if (level == VBUS_SAFE0V)
+ return vbus_voltage < PD_V_SAFE0V_MAX;
+ else if (level == VBUS_PRESENT)
+ return vbus_voltage > PD_V_SAFE5V_MIN;
+ else
+ return vbus_voltage < PD_V_SINK_DISCONNECT_MAX;
}
/*