summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2022-07-06 11:44:24 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-07-06 18:54:56 +0000
commit9dda866745dc265965a656cf79862016f1cb2870 (patch)
tree559c5454697ce67721f0bdca1540f369a0a61b94 /driver
parent2b8e6c8a813f0e5314da1dd940f06078e9850b05 (diff)
downloadchrome-ec-9dda866745dc265965a656cf79862016f1cb2870.tar.gz
driver/charger/sm5803.c: Format with clang-format
BUG=b:236386294 BRANCH=none TEST=none Tricium: disable Change-Id: I2987ecff1d3df11f7cb8655ce6a4404f82730d6d Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729968 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/charger/sm5803.c257
1 files changed, 116 insertions, 141 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c
index e65bb67e75..d90294b8c9 100644
--- a/driver/charger/sm5803.c
+++ b/driver/charger/sm5803.c
@@ -29,22 +29,22 @@
#endif
/* Console output macros */
-#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ##args)
#define UNKNOWN_DEV_ID -1
static int dev_id = UNKNOWN_DEV_ID;
static const struct charger_info sm5803_charger_info = {
- .name = CHARGER_NAME,
- .voltage_max = CHARGE_V_MAX,
- .voltage_min = CHARGE_V_MIN,
+ .name = CHARGER_NAME,
+ .voltage_max = CHARGE_V_MAX,
+ .voltage_min = CHARGE_V_MIN,
.voltage_step = CHARGE_V_STEP,
- .current_max = CHARGE_I_MAX,
- .current_min = CHARGE_I_MIN,
+ .current_max = CHARGE_I_MAX,
+ .current_min = CHARGE_I_MIN,
.current_step = CHARGE_I_STEP,
- .input_current_max = INPUT_I_MAX,
- .input_current_min = INPUT_I_MIN,
+ .input_current_max = INPUT_I_MAX,
+ .input_current_min = INPUT_I_MIN,
.input_current_step = INPUT_I_STEP,
};
@@ -77,9 +77,8 @@ static int attempt_bfet_enable;
*/
static bool fast_charge_disabled;
-
-#define CHARGING_FAILURE_MAX_COUNT 5
-#define CHARGING_FAILURE_INTERVAL MINUTE
+#define CHARGING_FAILURE_MAX_COUNT 5
+#define CHARGING_FAILURE_INTERVAL MINUTE
static int sm5803_is_sourcing_otg_power(int chgnum, int port);
static enum ec_error_list sm5803_get_dev_id(int chgnum, int *id);
@@ -88,58 +87,51 @@ static enum ec_error_list sm5803_set_current(int chgnum, int current);
static inline enum ec_error_list chg_read8(int chgnum, int offset, int *value)
{
return i2c_read8(chg_chips[chgnum].i2c_port,
- chg_chips[chgnum].i2c_addr_flags,
- offset, value);
+ chg_chips[chgnum].i2c_addr_flags, offset, value);
}
static inline enum ec_error_list chg_write8(int chgnum, int offset, int value)
{
return i2c_write8(chg_chips[chgnum].i2c_port,
- chg_chips[chgnum].i2c_addr_flags,
- offset, value);
+ chg_chips[chgnum].i2c_addr_flags, offset, value);
}
static inline enum ec_error_list meas_read8(int chgnum, int offset, int *value)
{
- return i2c_read8(chg_chips[chgnum].i2c_port,
- SM5803_ADDR_MEAS_FLAGS,
+ return i2c_read8(chg_chips[chgnum].i2c_port, SM5803_ADDR_MEAS_FLAGS,
offset, value);
}
static inline enum ec_error_list meas_write8(int chgnum, int offset, int value)
{
- return i2c_write8(chg_chips[chgnum].i2c_port,
- SM5803_ADDR_MEAS_FLAGS,
- offset, value);
+ return i2c_write8(chg_chips[chgnum].i2c_port, SM5803_ADDR_MEAS_FLAGS,
+ offset, value);
}
static inline enum ec_error_list main_read8(int chgnum, int offset, int *value)
{
- return i2c_read8(chg_chips[chgnum].i2c_port,
- SM5803_ADDR_MAIN_FLAGS,
+ return i2c_read8(chg_chips[chgnum].i2c_port, SM5803_ADDR_MAIN_FLAGS,
offset, value);
}
static inline enum ec_error_list main_write8(int chgnum, int offset, int value)
{
- return i2c_write8(chg_chips[chgnum].i2c_port,
- SM5803_ADDR_MAIN_FLAGS,
- offset, value);
+ return i2c_write8(chg_chips[chgnum].i2c_port, SM5803_ADDR_MAIN_FLAGS,
+ offset, value);
}
static inline enum ec_error_list test_write8(int chgnum, int offset, int value)
{
- return i2c_write8(chg_chips[chgnum].i2c_port,
- SM5803_ADDR_TEST_FLAGS,
- offset, value);
+ return i2c_write8(chg_chips[chgnum].i2c_port, SM5803_ADDR_TEST_FLAGS,
+ offset, value);
}
-static inline enum ec_error_list test_update8(int chgnum, const int offset,
- const uint8_t mask,
- const enum mask_update_action action)
+static inline enum ec_error_list
+test_update8(int chgnum, const int offset, const uint8_t mask,
+ const enum mask_update_action action)
{
- return i2c_update8(chg_chips[chgnum].i2c_port,
- SM5803_ADDR_TEST_FLAGS, offset, mask, action);
+ return i2c_update8(chg_chips[chgnum].i2c_port, SM5803_ADDR_TEST_FLAGS,
+ offset, mask, action);
}
/*
@@ -166,7 +158,7 @@ static int sm5803_set_full_clock_speed(int chgnum)
}
if (val & SM5803_CLOCK_SEL_LOW) {
rv = main_write8(chgnum, SM5803_REG_CLOCK_SEL,
- val & ~SM5803_CLOCK_SEL_LOW);
+ val & ~SM5803_CLOCK_SEL_LOW);
}
out:
@@ -177,8 +169,9 @@ out:
return rv;
}
-static enum ec_error_list sm5803_flow1_update(int chgnum, const uint8_t mask,
- const enum mask_update_action action)
+static enum ec_error_list
+sm5803_flow1_update(int chgnum, const uint8_t mask,
+ const enum mask_update_action action)
{
int rv;
@@ -186,8 +179,7 @@ static enum ec_error_list sm5803_flow1_update(int chgnum, const uint8_t mask,
mutex_lock(&flow1_access_lock[chgnum]);
rv = i2c_update8(chg_chips[chgnum].i2c_port,
- chg_chips[chgnum].i2c_addr_flags,
- SM5803_REG_FLOW1,
+ chg_chips[chgnum].i2c_addr_flags, SM5803_REG_FLOW1,
mask, action);
mutex_unlock(&flow1_access_lock[chgnum]);
@@ -195,16 +187,16 @@ static enum ec_error_list sm5803_flow1_update(int chgnum, const uint8_t mask,
return rv;
}
-static enum ec_error_list sm5803_flow2_update(int chgnum, const uint8_t mask,
- const enum mask_update_action action)
+static enum ec_error_list
+sm5803_flow2_update(int chgnum, const uint8_t mask,
+ const enum mask_update_action action)
{
int rv;
mutex_lock(&flow2_access_lock[chgnum]);
rv = i2c_update8(chg_chips[chgnum].i2c_port,
- chg_chips[chgnum].i2c_addr_flags,
- SM5803_REG_FLOW2,
+ chg_chips[chgnum].i2c_addr_flags, SM5803_REG_FLOW2,
mask, action);
mutex_unlock(&flow2_access_lock[chgnum]);
@@ -345,15 +337,16 @@ enum ec_error_list sm5803_vbus_sink_enable(int chgnum, int enable)
*/
if (battery_get_disconnect_state() ==
BATTERY_NOT_DISCONNECTED) {
- rv = sm5803_flow2_update(chgnum,
- SM5803_FLOW2_AUTO_ENABLED,
- MASK_SET);
+ rv = sm5803_flow2_update(
+ chgnum, SM5803_FLOW2_AUTO_ENABLED,
+ MASK_SET);
fast_charge_disabled = false;
} else {
- rv = sm5803_flow2_update(chgnum,
- SM5803_FLOW2_AUTO_TRKL_EN |
+ rv = sm5803_flow2_update(
+ chgnum,
+ SM5803_FLOW2_AUTO_TRKL_EN |
SM5803_FLOW2_AUTO_PRECHG_EN,
- MASK_SET);
+ MASK_SET);
fast_charge_disabled = true;
}
} else {
@@ -380,9 +373,8 @@ enum ec_error_list sm5803_vbus_sink_enable(int chgnum, int enable)
rv |= sm5803_flow1_update(chgnum, CHARGER_MODE_SINK, MASK_SET);
} else {
if (chgnum == CHARGER_PRIMARY)
- rv |= sm5803_flow2_update(chgnum,
- SM5803_FLOW2_AUTO_ENABLED,
- MASK_CLR);
+ rv |= sm5803_flow2_update(
+ chgnum, SM5803_FLOW2_AUTO_ENABLED, MASK_CLR);
if (chgnum == CHARGER_SECONDARY) {
rv |= sm5803_flow1_update(CHARGER_PRIMARY,
@@ -396,7 +388,6 @@ enum ec_error_list sm5803_vbus_sink_enable(int chgnum, int enable)
regval);
}
-
/* Disable sink mode, unless currently sourcing out */
if (!sm5803_is_sourcing_otg_power(chgnum, chgnum))
rv |= sm5803_flow1_update(chgnum, CHARGER_MODE_SINK,
@@ -404,7 +395,6 @@ enum ec_error_list sm5803_vbus_sink_enable(int chgnum, int enable)
}
return rv;
-
}
/*
@@ -412,8 +402,8 @@ enum ec_error_list sm5803_vbus_sink_enable(int chgnum, int enable)
* boot. This should prevent us from re-running inits after sysjumps.
*/
static bool chip_inited[CHARGER_NUM];
-#define SM5803_SYSJUMP_TAG 0x534D /* SM */
-#define SM5803_HOOK_VERSION 1
+#define SM5803_SYSJUMP_TAG 0x534D /* SM */
+#define SM5803_HOOK_VERSION 1
static void init_status_preserve(void)
{
@@ -427,10 +417,9 @@ static void init_status_retrieve(void)
const uint8_t *tag_contents;
int version, size;
- tag_contents = system_get_jump_tag(SM5803_SYSJUMP_TAG,
- &version, &size);
+ tag_contents = system_get_jump_tag(SM5803_SYSJUMP_TAG, &version, &size);
if (tag_contents && (version == SM5803_HOOK_VERSION) &&
- (size == sizeof(chip_inited)))
+ (size == sizeof(chip_inited)))
/* Valid init status found, restore before charger chip init */
memcpy(&chip_inited, tag_contents, size);
}
@@ -548,7 +537,7 @@ static void sm5803_init(int chgnum)
rv = main_read8(chgnum, SM5803_REG_PLATFORM, &platform_id);
if (rv) {
CPRINTS("%s %d: Failed to read platform during init",
- CHARGER_NAME, chgnum);
+ CHARGER_NAME, chgnum);
return;
}
platform_id &= SM5803_PLATFORM_ID;
@@ -557,10 +546,10 @@ static void sm5803_init(int chgnum)
/* 3S Battery inits */
/* set 13.3V VBAT_SNSP TH GPADC THRESHOLD*/
rv |= meas_write8(chgnum, 0x26,
- SM5803_VBAT_SNSP_MAXTH_3S_LEVEL);
+ SM5803_VBAT_SNSP_MAXTH_3S_LEVEL);
/* OV_VBAT HW second level (14.1V) */
rv |= chg_write8(chgnum, 0x21,
- SM5803_VBAT_PWR_MINTH_3S_LEVEL);
+ SM5803_VBAT_PWR_MINTH_3S_LEVEL);
rv |= main_write8(chgnum, 0x30, 0xC0);
rv |= main_write8(chgnum, 0x80, 0x01);
rv |= main_write8(chgnum, 0x1A, 0x08);
@@ -606,11 +595,11 @@ static void sm5803_init(int chgnum)
* threshold for interrupt generation.
*/
rv |= meas_write8(chgnum, 0x26,
- SM5803_VBAT_SNSP_MAXTH_2S_LEVEL);
+ SM5803_VBAT_SNSP_MAXTH_2S_LEVEL);
/* Set OV_VBAT HW second level threshold as 9.4V */
rv |= chg_write8(chgnum, 0x21,
- SM5803_VBAT_PWR_MINTH_2S_LEVEL);
+ SM5803_VBAT_PWR_MINTH_2S_LEVEL);
rv |= main_write8(chgnum, 0x30, 0xC0);
rv |= main_write8(chgnum, 0x80, 0x01);
@@ -676,12 +665,9 @@ static void sm5803_init(int chgnum)
* Turn on GPADCs to default. Enable the IBAT_CHG ADC in order to
* measure battery current and calculate system resistance.
*/
- reg = SM5803_GPADCC1_TINT_EN |
- SM5803_GPADCC1_VSYS_EN |
- SM5803_GPADCC1_VCHGPWR_EN |
- SM5803_GPADCC1_VBUS_EN |
- SM5803_GPADCC1_IBAT_CHG_EN |
- SM5803_GPADCC1_IBAT_DIS_EN |
+ reg = SM5803_GPADCC1_TINT_EN | SM5803_GPADCC1_VSYS_EN |
+ SM5803_GPADCC1_VCHGPWR_EN | SM5803_GPADCC1_VBUS_EN |
+ SM5803_GPADCC1_IBAT_CHG_EN | SM5803_GPADCC1_IBAT_DIS_EN |
SM5803_GPADCC1_VBATSNSP_EN;
rv |= meas_write8(chgnum, SM5803_REG_GPADC_CONFIG1, reg);
@@ -707,26 +693,26 @@ static void sm5803_init(int chgnum)
rv |= chg_write8(chgnum, SM5803_REG_DPM_VL_SET_LSB, (reg & 0x7));
/* Set default input current */
- reg = SM5803_CURRENT_TO_REG(CONFIG_CHARGER_INPUT_CURRENT)
- & SM5803_CHG_ILIM_RAW;
+ reg = SM5803_CURRENT_TO_REG(CONFIG_CHARGER_INPUT_CURRENT) &
+ SM5803_CHG_ILIM_RAW;
rv |= chg_write8(chgnum, SM5803_REG_CHG_ILIM, reg);
/* Configure charger insertion interrupts */
rv |= main_write8(chgnum, SM5803_REG_INT1_EN, SM5803_INT1_CHG);
/* Enable end of charge interrupts for logging */
- rv |= main_write8(chgnum, SM5803_REG_INT4_EN, SM5803_INT4_CHG_FAIL |
- SM5803_INT4_CHG_DONE |
- SM5803_INT4_OTG_FAIL);
+ rv |= main_write8(chgnum, SM5803_REG_INT4_EN,
+ SM5803_INT4_CHG_FAIL | SM5803_INT4_CHG_DONE |
+ SM5803_INT4_OTG_FAIL);
/* Set TINT interrupts for higher threshold 360 K */
rv |= meas_write8(chgnum, SM5803_REG_TINT_HIGH_TH,
- SM5803_TINT_HIGH_LEVEL);
+ SM5803_TINT_HIGH_LEVEL);
/*
* Set TINT interrupts for lower threshold to 0 when not
* throttled to prevent trigger interrupts continually
*/
rv |= meas_write8(chgnum, SM5803_REG_TINT_LOW_TH,
- SM5803_TINT_MIN_LEVEL);
+ SM5803_TINT_MIN_LEVEL);
/*
* Configure VBAT_SNSP high interrupt to fire after thresholds are set.
@@ -735,7 +721,6 @@ static void sm5803_init(int chgnum)
reg |= SM5803_INT2_VBATSNSP;
rv |= main_write8(chgnum, SM5803_REG_INT2_EN, reg);
-
/* Configure TINT interrupts to fire after thresholds are set */
rv |= main_write8(chgnum, SM5803_REG_INT2_EN, SM5803_INT2_TINT);
@@ -792,7 +777,7 @@ static void sm5803_init(int chgnum)
rv |= meas_write8(chgnum, SM5803_REG_BFET_PWR_MAX_TH, reg);
reg = (6000 * 10) / 292;
rv |= meas_write8(chgnum, SM5803_REG_BFET_PWR_HWSAFE_MAX_TH,
- reg);
+ reg);
rv |= main_read8(chgnum, SM5803_REG_INT3_EN, &reg);
reg |= SM5803_INT3_BFET_PWR_LIMIT |
SM5803_INT3_BFET_PWR_HWSAFE_LIMIT;
@@ -892,9 +877,8 @@ static void sm5803_disable_runtime_low_power_mode(void)
CPRINTS("%s %d: Failed to set in disable runtime LPM",
CHARGER_NAME, chgnum);
}
-DECLARE_HOOK(HOOK_USB_PD_CONNECT,
- sm5803_disable_runtime_low_power_mode,
- HOOK_PRIO_FIRST);
+DECLARE_HOOK(HOOK_USB_PD_CONNECT, sm5803_disable_runtime_low_power_mode,
+ HOOK_PRIO_FIRST);
static enum ec_error_list sm5803_enable_linear_charge(int chgnum, bool enable)
{
@@ -923,18 +907,15 @@ static enum ec_error_list sm5803_enable_linear_charge(int chgnum, bool enable)
batt_info->precharge_current);
/* Enable linear charge mode. */
- rv |= sm5803_flow1_update(chgnum,
- SM5803_FLOW1_LINEAR_CHARGE_EN,
- MASK_SET);
+ rv |= sm5803_flow1_update(chgnum, SM5803_FLOW1_LINEAR_CHARGE_EN,
+ MASK_SET);
rv |= chg_read8(chgnum, SM5803_REG_FLOW3, &regval);
regval |= BIT(6) | BIT(5) | BIT(4);
rv |= chg_write8(chgnum, SM5803_REG_FLOW3, regval);
} else {
- rv = sm5803_flow1_update(chgnum,
- SM5803_FLOW1_LINEAR_CHARGE_EN,
+ rv = sm5803_flow1_update(chgnum, SM5803_FLOW1_LINEAR_CHARGE_EN,
MASK_CLR);
- rv |= sm5803_flow2_update(chgnum,
- SM5803_FLOW2_AUTO_ENABLED,
+ rv |= sm5803_flow2_update(chgnum, SM5803_FLOW2_AUTO_ENABLED,
MASK_CLR);
rv |= chg_read8(chgnum, SM5803_REG_FLOW3, &regval);
regval &= ~(BIT(6) | BIT(5) | BIT(4) |
@@ -983,9 +964,8 @@ static void sm5803_enable_runtime_low_power_mode(void)
CPRINTS("%s %d: Failed to set in enable runtime LPM",
CHARGER_NAME, chgnum);
}
-DECLARE_HOOK(HOOK_USB_PD_DISCONNECT,
- sm5803_enable_runtime_low_power_mode,
- HOOK_PRIO_LAST);
+DECLARE_HOOK(HOOK_USB_PD_DISCONNECT, sm5803_enable_runtime_low_power_mode,
+ HOOK_PRIO_LAST);
void sm5803_disable_low_power_mode(int chgnum)
{
@@ -1044,7 +1024,6 @@ void sm5803_enable_low_power_mode(int chgnum)
reg |= SM5803_PHOT1_VBUS_MON_EN;
rv |= chg_write8(chgnum, SM5803_REG_PHOT1, reg);
-
if (rv)
CPRINTS("%s %d: Failed to set in enable low power mode",
CHARGER_NAME, chgnum);
@@ -1065,8 +1044,8 @@ void sm5803_restart_charging(void)
* Enough time has passed since our last failure,
* restart the timing and count from now.
*/
- failure_tracker[act_chg].time.val = now.val +
- CHARGING_FAILURE_INTERVAL;
+ failure_tracker[act_chg].time.val =
+ now.val + CHARGING_FAILURE_INTERVAL;
failure_tracker[act_chg].count = 1;
sm5803_vbus_sink_enable(act_chg, 1);
@@ -1129,27 +1108,27 @@ void sm5803_handle_interrupt(int chgnum)
if ((meas_reg <= SM5803_TINT_LOW_LEVEL) && throttled) {
throttled = false;
throttle_ap(THROTTLE_OFF, THROTTLE_HARD,
- THROTTLE_SRC_THERMAL);
+ THROTTLE_SRC_THERMAL);
/*
* Set back higher threshold to 360 K and set lower
* threshold to 0.
*/
rv |= meas_write8(chgnum, SM5803_REG_TINT_LOW_TH,
- SM5803_TINT_MIN_LEVEL);
+ SM5803_TINT_MIN_LEVEL);
rv |= meas_write8(chgnum, SM5803_REG_TINT_HIGH_TH,
- SM5803_TINT_HIGH_LEVEL);
+ SM5803_TINT_HIGH_LEVEL);
} else if (meas_reg >= SM5803_TINT_HIGH_LEVEL) {
throttled = true;
throttle_ap(THROTTLE_ON, THROTTLE_HARD,
- THROTTLE_SRC_THERMAL);
+ THROTTLE_SRC_THERMAL);
/*
* Set back lower threshold to 330 K and set higher
* threshold to maximum.
*/
rv |= meas_write8(chgnum, SM5803_REG_TINT_HIGH_TH,
- SM5803_TINT_MAX_LEVEL);
+ SM5803_TINT_MAX_LEVEL);
rv |= meas_write8(chgnum, SM5803_REG_TINT_LOW_TH,
- SM5803_TINT_LOW_LEVEL);
+ SM5803_TINT_LOW_LEVEL);
}
/*
* If the interrupt came in and we're not currently throttling
@@ -1165,25 +1144,23 @@ void sm5803_handle_interrupt(int chgnum)
rv = main_read8(chgnum, SM5803_REG_PLATFORM, &platform_id);
if (rv) {
CPRINTS("%s %d: Failed to read platform in interrupt",
- CHARGER_NAME, chgnum);
+ CHARGER_NAME, chgnum);
return;
}
platform_id &= SM5803_PLATFORM_ID;
act_chg = charge_manager_get_active_charge_port();
- rv = meas_read8(CHARGER_PRIMARY,
- SM5803_REG_VBATSNSP_MEAS_MSB,
- &meas_reg);
+ rv = meas_read8(CHARGER_PRIMARY, SM5803_REG_VBATSNSP_MEAS_MSB,
+ &meas_reg);
if (rv)
return;
meas_volt = meas_reg << 2;
- rv = meas_read8(CHARGER_PRIMARY,
- SM5803_REG_VBATSNSP_MEAS_LSB,
- &meas_reg);
+ rv = meas_read8(CHARGER_PRIMARY, SM5803_REG_VBATSNSP_MEAS_LSB,
+ &meas_reg);
if (rv)
return;
meas_volt |= meas_reg & 0x03;
- rv = meas_read8(CHARGER_PRIMARY,
- SM5803_REG_VBATSNSP_MAX_TH, &meas_reg);
+ rv = meas_read8(CHARGER_PRIMARY, SM5803_REG_VBATSNSP_MAX_TH,
+ &meas_reg);
if (rv)
return;
@@ -1192,8 +1169,7 @@ void sm5803_handle_interrupt(int chgnum)
CPRINTS("%s %d : VBAT_SNSP_HIGH_TH: %d mV ! - "
"VBAT %d mV",
CHARGER_NAME, CHARGER_PRIMARY,
- meas_reg * 408/10,
- meas_volt * 102/10);
+ meas_reg * 408 / 10, meas_volt * 102 / 10);
}
if (is_platform_id_3s(platform_id)) {
@@ -1201,28 +1177,27 @@ void sm5803_handle_interrupt(int chgnum)
CPRINTS("%s %d : VBAT_SNSP_HIGH_TH: %d mV ! "
"- VBAT %d mV",
CHARGER_NAME, CHARGER_PRIMARY,
- meas_reg * 616/10,
- meas_volt * 154/10);
+ meas_reg * 616 / 10, meas_volt * 154 / 10);
}
/* Set Vbat Threshold to Max value to re-arm the interrupt */
- rv = meas_write8(CHARGER_PRIMARY,
- SM5803_REG_VBATSNSP_MAX_TH, 0xFF);
+ rv = meas_write8(CHARGER_PRIMARY, SM5803_REG_VBATSNSP_MAX_TH,
+ 0xFF);
/* Disable battery charge */
rv |= sm5803_flow1_update(chgnum, CHARGER_MODE_DISABLED,
- MASK_CLR);
+ MASK_CLR);
if (is_platform_id_2s(platform_id)) {
/* 2S battery: set VBAT_SENSP TH 9V */
rv |= meas_write8(CHARGER_PRIMARY,
- SM5803_REG_VBATSNSP_MAX_TH,
- SM5803_VBAT_SNSP_MAXTH_2S_LEVEL);
+ SM5803_REG_VBATSNSP_MAX_TH,
+ SM5803_VBAT_SNSP_MAXTH_2S_LEVEL);
}
if (is_platform_id_3s(platform_id)) {
/* 3S battery: set VBAT_SENSP TH 13.3V */
rv |= meas_write8(CHARGER_PRIMARY,
- SM5803_REG_VBATSNSP_MAX_TH,
- SM5803_VBAT_SNSP_MAXTH_3S_LEVEL);
+ SM5803_REG_VBATSNSP_MAX_TH,
+ SM5803_VBAT_SNSP_MAXTH_3S_LEVEL);
}
active_restart_port = act_chg;
@@ -1243,7 +1218,7 @@ void sm5803_handle_interrupt(int chgnum)
act_chg = charge_manager_get_active_charge_port();
CPRINTS("%s BFET power limit reached! (%s)", CHARGER_NAME,
(int_reg & SM5803_INT3_BFET_PWR_LIMIT) ? "warn" :
- "FATAL");
+ "FATAL");
CPRINTS("\tVbat: %dmV", bp.voltage);
CPRINTS("\tIbat: %dmA", bp.current);
charger_get_voltage(act_chg, &val);
@@ -1280,7 +1255,7 @@ void sm5803_handle_interrupt(int chgnum)
hook_call_deferred(&sm5803_restart_charging_data,
30 * SECOND);
} else if ((status_reg & SM5803_STATUS_CHG_OV_VBAT) &&
- act_chg == CHARGER_PRIMARY) {
+ act_chg == CHARGER_PRIMARY) {
active_restart_port = act_chg;
hook_call_deferred(&sm5803_restart_charging_data,
1 * SECOND);
@@ -1312,11 +1287,12 @@ void sm5803_handle_interrupt(int chgnum)
* will detect us as sinking in this failure case.
*/
if (status_reg == 0)
- rv = sm5803_flow1_update(chgnum, CHARGER_MODE_SOURCE |
- SM5803_FLOW1_DIRECTCHG_SRC_EN,
- MASK_CLR);
+ rv = sm5803_flow1_update(
+ chgnum,
+ CHARGER_MODE_SOURCE |
+ SM5803_FLOW1_DIRECTCHG_SRC_EN,
+ MASK_CLR);
}
-
}
static void sm5803_irq_deferred(void)
@@ -1347,7 +1323,6 @@ static enum ec_error_list sm5803_get_dev_id(int chgnum, int *id)
*id = dev_id;
return rv;
-
}
static const struct charger_info *sm5803_get_info(int chgnum)
@@ -1367,7 +1342,6 @@ static enum ec_error_list sm5803_get_status(int chgnum, int *status)
if (rv)
return rv;
-
if ((reg & SM5803_FLOW1_MODE) == CHARGER_MODE_DISABLED &&
!(reg & SM5803_FLOW1_LINEAR_CHARGE_EN))
*status |= CHARGER_CHARGE_INHIBITED;
@@ -1500,8 +1474,7 @@ static enum ec_error_list sm5803_set_voltage(int chgnum, int voltage)
/* Once battery is connected, set up fast charge enable */
if (fast_charge_disabled && chgnum == CHARGER_PRIMARY &&
battery_get_disconnect_state() == BATTERY_NOT_DISCONNECTED) {
- rv = sm5803_flow2_update(chgnum,
- SM5803_FLOW2_AUTO_ENABLED,
+ rv = sm5803_flow2_update(chgnum, SM5803_FLOW2_AUTO_ENABLED,
MASK_SET);
fast_charge_disabled = false;
}
@@ -1549,7 +1522,7 @@ static enum ec_error_list sm5803_discharge_on_ac(int chgnum, int enable)
}
static enum ec_error_list sm5803_get_vbus_voltage(int chgnum, int port,
- int *voltage)
+ int *voltage)
{
enum ec_error_list rv;
int reg;
@@ -1718,13 +1691,13 @@ static enum ec_error_list sm5803_set_otg_current_voltage(int chgnum,
reg &= ~SM5803_DISCH_CONF5_CLS_LIMIT;
reg |= MIN((output_current / SM5803_CLS_CURRENT_STEP),
- SM5803_DISCH_CONF5_CLS_LIMIT);
+ SM5803_DISCH_CONF5_CLS_LIMIT);
rv |= chg_write8(chgnum, SM5803_REG_DISCH_CONF5, reg);
reg = SM5803_VOLTAGE_TO_REG(output_voltage);
rv = chg_write8(chgnum, SM5803_REG_VPWR_MSB, (reg >> 3));
rv |= chg_write8(chgnum, SM5803_REG_DISCH_CONF2,
- reg & SM5803_DISCH_CONF5_VPWR_LSB);
+ reg & SM5803_DISCH_CONF5_VPWR_LSB);
return rv;
}
@@ -1765,7 +1738,7 @@ static enum ec_error_list sm5803_enable_otg_power(int chgnum, int enabled)
return rv;
selected_current = (reg & SM5803_DISCH_CONF5_CLS_LIMIT) *
- SM5803_CLS_CURRENT_STEP;
+ SM5803_CLS_CURRENT_STEP;
sm5803_set_otg_current_voltage(chgnum, selected_current, 4800);
/*
@@ -1773,8 +1746,9 @@ static enum ec_error_list sm5803_enable_otg_power(int chgnum, int enabled)
* DIRECTCHG_SOURCE_EN - enable current loop
* (for designs with no external Vbus FET)
*/
- rv = sm5803_flow1_update(chgnum, CHARGER_MODE_SOURCE |
- SM5803_FLOW1_DIRECTCHG_SRC_EN,
+ rv = sm5803_flow1_update(chgnum,
+ CHARGER_MODE_SOURCE |
+ SM5803_FLOW1_DIRECTCHG_SRC_EN,
MASK_SET);
usleep(4000);
@@ -1810,9 +1784,11 @@ static enum ec_error_list sm5803_enable_otg_power(int chgnum, int enabled)
return rv;
if ((reg & SM5803_FLOW1_MODE) != CHARGER_MODE_SINK || status)
- rv = sm5803_flow1_update(chgnum, CHARGER_MODE_SOURCE |
- SM5803_FLOW1_DIRECTCHG_SRC_EN,
- MASK_CLR);
+ rv = sm5803_flow1_update(
+ chgnum,
+ CHARGER_MODE_SOURCE |
+ SM5803_FLOW1_DIRECTCHG_SRC_EN,
+ MASK_CLR);
}
return rv;
@@ -1839,7 +1815,6 @@ static enum ec_error_list sm5803_set_vsys_compensation(int chgnum,
int current_ma,
int voltage_mv)
{
-
int rv;
int regval;
int r;