From eb2c8a032f9226b83103d5a953c9cfce595f0170 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Sun, 14 Jun 2020 02:04:50 +0300 Subject: [PATCH] power: Enable charger unconditionally --- bootloader/power/bq24193.c | 10 ++++++++++ bootloader/power/bq24193.h | 2 ++ bootloader/soc/hw_init.c | 3 +++ nyx/nyx_gui/power/bq24193.c | 10 ++++++++++ nyx/nyx_gui/power/bq24193.h | 2 ++ nyx/nyx_gui/soc/hw_init.c | 3 +++ 6 files changed, 30 insertions(+) diff --git a/bootloader/power/bq24193.c b/bootloader/power/bq24193.c index 36401f4..0ade8da 100644 --- a/bootloader/power/bq24193.c +++ b/bootloader/power/bq24193.c @@ -154,6 +154,16 @@ int bq24193_get_property(enum BQ24193_reg_prop prop, int *value) return 0; } +void bq24193_enable_charger() +{ + u8 reg = bq24193_get_reg(BQ24193_PORConfig); + + reg &= ~BQ24193_PORCONFIG_CHGCONFIG_MASK; + reg |= BQ24193_PORCONFIG_CHGCONFIG_CHARGER_EN; + + i2c_send_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_PORConfig, reg); +} + void bq24193_fake_battery_removal() { // Disable watchdog to keep BATFET disabled. diff --git a/bootloader/power/bq24193.h b/bootloader/power/bq24193.h index 34e9fbf..1b6e717 100644 --- a/bootloader/power/bq24193.h +++ b/bootloader/power/bq24193.h @@ -30,6 +30,7 @@ #define BQ24193_PORCONFIG_BOOST_MASK (1<<0) #define BQ24193_PORCONFIG_SYSMIN_MASK (7<<1) #define BQ24193_PORCONFIG_CHGCONFIG_MASK (3<<4) +#define BQ24193_PORCONFIG_CHGCONFIG_CHARGER_EN (1<<4) #define BQ24193_PORCONFIG_I2CWATCHDOG_MASK (1<<6) #define BQ24193_PORCONFIG_RESET_MASK (1<<7) @@ -114,6 +115,7 @@ enum BQ24193_reg_prop { }; int bq24193_get_property(enum BQ24193_reg_prop prop, int *value); +void bq24193_enable_charger(); void bq24193_fake_battery_removal(); #endif /* __BQ24193_H_ */ diff --git a/bootloader/soc/hw_init.c b/bootloader/soc/hw_init.c index 6e85760..53f8c08 100644 --- a/bootloader/soc/hw_init.c +++ b/bootloader/soc/hw_init.c @@ -315,6 +315,9 @@ void config_hw() i2c_init(I2C_1); i2c_init(I2C_5); + // Enable charger in case it's disabled. + bq24193_enable_charger(); + _config_regulators(); _config_pmc_scratch(); // Missing from 4.x+ diff --git a/nyx/nyx_gui/power/bq24193.c b/nyx/nyx_gui/power/bq24193.c index 36401f4..0ade8da 100644 --- a/nyx/nyx_gui/power/bq24193.c +++ b/nyx/nyx_gui/power/bq24193.c @@ -154,6 +154,16 @@ int bq24193_get_property(enum BQ24193_reg_prop prop, int *value) return 0; } +void bq24193_enable_charger() +{ + u8 reg = bq24193_get_reg(BQ24193_PORConfig); + + reg &= ~BQ24193_PORCONFIG_CHGCONFIG_MASK; + reg |= BQ24193_PORCONFIG_CHGCONFIG_CHARGER_EN; + + i2c_send_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_PORConfig, reg); +} + void bq24193_fake_battery_removal() { // Disable watchdog to keep BATFET disabled. diff --git a/nyx/nyx_gui/power/bq24193.h b/nyx/nyx_gui/power/bq24193.h index 34e9fbf..1b6e717 100644 --- a/nyx/nyx_gui/power/bq24193.h +++ b/nyx/nyx_gui/power/bq24193.h @@ -30,6 +30,7 @@ #define BQ24193_PORCONFIG_BOOST_MASK (1<<0) #define BQ24193_PORCONFIG_SYSMIN_MASK (7<<1) #define BQ24193_PORCONFIG_CHGCONFIG_MASK (3<<4) +#define BQ24193_PORCONFIG_CHGCONFIG_CHARGER_EN (1<<4) #define BQ24193_PORCONFIG_I2CWATCHDOG_MASK (1<<6) #define BQ24193_PORCONFIG_RESET_MASK (1<<7) @@ -114,6 +115,7 @@ enum BQ24193_reg_prop { }; int bq24193_get_property(enum BQ24193_reg_prop prop, int *value); +void bq24193_enable_charger(); void bq24193_fake_battery_removal(); #endif /* __BQ24193_H_ */ diff --git a/nyx/nyx_gui/soc/hw_init.c b/nyx/nyx_gui/soc/hw_init.c index ffdb0fc..9dc0ca6 100644 --- a/nyx/nyx_gui/soc/hw_init.c +++ b/nyx/nyx_gui/soc/hw_init.c @@ -323,6 +323,9 @@ void config_hw() i2c_init(I2C_1); i2c_init(I2C_5); + // Enable charger in case it's disabled. + bq24193_enable_charger(); + _config_regulators(); _config_pmc_scratch(); // Missing from 4.x+