提交 7f93e1fa 编写于 作者: P Paul Kocialkowski 提交者: Sebastian Reichel

power: supply: sbs-battery: Correct supply status with current draw

The status reported directly by the battery controller is not always
reliable and should be corrected based on the current draw information.

This implements such a correction with a dedicated function, called
where the supply status is retrieved.
Signed-off-by: NPaul Kocialkowski <contact@paulk.fr>
Signed-off-by: NSebastian Reichel <sebastian.reichel@collabora.co.uk>
上级 4df2cce4
...@@ -295,6 +295,31 @@ static int sbs_write_word_data(struct i2c_client *client, u8 address, ...@@ -295,6 +295,31 @@ static int sbs_write_word_data(struct i2c_client *client, u8 address,
return 0; return 0;
} }
static int sbs_status_correct(struct i2c_client *client, int *intval)
{
int ret;
ret = sbs_read_word_data(client, sbs_data[REG_CURRENT].addr);
if (ret < 0)
return ret;
ret = (s16)ret;
/* Not drawing current means full (cannot be not charging) */
if (ret == 0)
*intval = POWER_SUPPLY_STATUS_FULL;
if (*intval == POWER_SUPPLY_STATUS_FULL) {
/* Drawing or providing current when full */
if (ret > 0)
*intval = POWER_SUPPLY_STATUS_CHARGING;
else if (ret < 0)
*intval = POWER_SUPPLY_STATUS_DISCHARGING;
}
return 0;
}
static int sbs_get_battery_presence_and_health( static int sbs_get_battery_presence_and_health(
struct i2c_client *client, enum power_supply_property psp, struct i2c_client *client, enum power_supply_property psp,
union power_supply_propval *val) union power_supply_propval *val)
...@@ -401,6 +426,8 @@ static int sbs_get_battery_property(struct i2c_client *client, ...@@ -401,6 +426,8 @@ static int sbs_get_battery_property(struct i2c_client *client,
else else
val->intval = POWER_SUPPLY_STATUS_CHARGING; val->intval = POWER_SUPPLY_STATUS_CHARGING;
sbs_status_correct(client, &val->intval);
if (chip->poll_time == 0) if (chip->poll_time == 0)
chip->last_state = val->intval; chip->last_state = val->intval;
else if (chip->last_state != val->intval) { else if (chip->last_state != val->intval) {
...@@ -721,6 +748,8 @@ static void sbs_delayed_work(struct work_struct *work) ...@@ -721,6 +748,8 @@ static void sbs_delayed_work(struct work_struct *work)
else else
ret = POWER_SUPPLY_STATUS_CHARGING; ret = POWER_SUPPLY_STATUS_CHARGING;
sbs_status_correct(chip->client, &ret);
if (chip->last_state != ret) { if (chip->last_state != ret) {
chip->poll_time = 0; chip->poll_time = 0;
power_supply_changed(chip->power_supply); power_supply_changed(chip->power_supply);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册