From fceb98342b8e03cfbf27c5f29974d3b593ef77f6 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 27 Nov 2019 12:16:55 -0700 Subject: [PATCH] Disable watchdog when charging --- src/board/system76/galp3-c/battery.c | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/board/system76/galp3-c/battery.c b/src/board/system76/galp3-c/battery.c index e7acf9b..8a98771 100644 --- a/src/board/system76/galp3-c/battery.c +++ b/src/board/system76/galp3-c/battery.c @@ -9,9 +9,29 @@ int smbus_write(uint8_t address, uint8_t command, uint16_t data) { return i2c_set(address, command, (uint8_t *)&data, 2); } +// ChargeOption0 flags +// Low Power Mode Enable +#define SBC_EN_LWPWR ((uint16_t)(1 << 15)) +// Watchdog Timer Adjust +#define SBC_WDTMR_ADJ_175S ((uint16_t)(0b11 << 13)) +// Switching Frequency +#define SBC_PWM_FREQ_800KHZ ((uint16_t)(0b01 << 8)) +// IDCHG Amplifier Gain +#define SBC_IDCHC_GAIN ((uint16_t)(1 << 3)) + int battery_charger_disable(void) { int res = 0; + // Set charge option 0 with 175s watchdog + res = smbus_write( + 0x09, + 0x12, + SBC_EN_LWPWR | + SBC_WDTMR_ADJ_175S | + SBC_PWM_FREQ_800KHZ | + SBC_IDCHC_GAIN + ); + // Disable charge current res = smbus_write(0x09, 0x14, 0); if (res < 0) return res; @@ -37,6 +57,15 @@ int battery_charger_enable(void) { res = smbus_write(0x09, 0x15, 0x3300); if (res < 0) return res; + // Set charge option 0 with watchdog disabled + res = smbus_write( + 0x09, + 0x12, + SBC_EN_LWPWR | + SBC_PWM_FREQ_800KHZ | + SBC_IDCHC_GAIN + ); + return 0; }