Skip to content

Commit 4885800

Browse files
committed
usbpd/tps65987.c: fall back to default charger current
Fall back to the default CHARGER_INPUT_CURRENT in case usbpd communication failed and we could not determine the actual charger power. Signed-off-by: Michał Kopeć <michal.kopec@3mdeb.com>
1 parent 7986b03 commit 4885800

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

src/board/system76/common/usbpd/tps65987.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,25 @@ void usbpd_event(void) {
333333
next_input_voltage = BATTERY_CHARGER_VOLTAGE_AC;
334334
} else if (sink_ctrl_1) {
335335
while ((res = usbpd_current_limit(PORT_A_ADDRESS)) < 0 && retry--) {};
336-
next_input_current = res < CHARGER_INPUT_CURRENT ? res : CHARGER_INPUT_CURRENT;
337-
next_input_current = (uint32_t)next_input_current * 85 / 100;
338-
next_input_voltage = BATTERY_CHARGER_VOLTAGE_PD;
336+
if (res >= 0) {
337+
next_input_current = res < CHARGER_INPUT_CURRENT ? res : CHARGER_INPUT_CURRENT;
338+
next_input_current = (uint32_t)next_input_current * 85 / 100;
339+
next_input_voltage = BATTERY_CHARGER_VOLTAGE_PD;
340+
} else {
341+
next_input_current = CHARGER_INPUT_CURRENT;
342+
next_input_voltage = BATTERY_CHARGER_VOLTAGE_AC;
343+
}
339344
#ifdef USBPD_DUAL_PORT
340345
} else if (sink_ctrl_2) {
341346
while ((res = usbpd_current_limit(PORT_B_ADDRESS)) < 0 && retry--) {};
342-
next_input_current = res < CHARGER_INPUT_CURRENT ? res : CHARGER_INPUT_CURRENT;
343-
next_input_current = (uint32_t)next_input_current * 85 / 100;
344-
next_input_voltage = BATTERY_CHARGER_VOLTAGE_PD;
347+
if (res >= 0) {
348+
next_input_current = res < CHARGER_INPUT_CURRENT ? res : CHARGER_INPUT_CURRENT;
349+
next_input_current = (uint32_t)next_input_current * 85 / 100;
350+
next_input_voltage = BATTERY_CHARGER_VOLTAGE_PD;
351+
} else {
352+
next_input_current = CHARGER_INPUT_CURRENT;
353+
next_input_voltage = BATTERY_CHARGER_VOLTAGE_AC;
354+
}
345355
#endif
346356
}
347357
}

0 commit comments

Comments
 (0)