Skip to content

Commit

Permalink
power: supply: ab8500: Standardize capacity lookup
Browse files Browse the repository at this point in the history
The AB8500 charger only has one capacity table with
unspecified temperature, so we assume this capacity is given
for 20 degrees Celsius.

Convert this table to use the OCV (open circuit voltage)
tables in struct power_supply_battery_ocv_table.

In the process, convert the fuel gauge driver to use
microvolts and microamperes so we can use the same internals
as the power supply subsystem without having to multiply
and divide with 1000 in a few places.

Also convert high_curr_threshold and lowbat_threshold to
use microamperes and microvolts as these are closely
related to these changes.

Drop the unused overbat_threshold member in the custom
struct ab8500_fg_parameters.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
  • Loading branch information
Linus Walleij authored and Sebastian Reichel committed Nov 22, 2021
1 parent 67acb29 commit 0525f34
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 206 deletions.
30 changes: 7 additions & 23 deletions drivers/power/supply/ab8500-bm.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ enum bup_vch_sel {
#define BATT_OVV_TH_3P7 0x00
#define BATT_OVV_TH_4P75 0x01

/* A value to indicate over voltage */
#define BATT_OVV_VALUE 4750
/* A value to indicate over voltage (microvolts) */
#define BATT_OVV_VALUE 4750000

/* VBUS OVV constants */
#define VBUS_OVV_SELECT_MASK 0x78
Expand Down Expand Up @@ -284,16 +284,6 @@ struct ab8500_res_to_temp {
int resist;
};

/**
* struct ab8500_v_to_cap - Table for translating voltage to capacity
* @voltage: Voltage in mV
* @capacity: Capacity in percent
*/
struct ab8500_v_to_cap {
int voltage;
int capacity;
};

/* Forward declaration */
struct ab8500_fg;

Expand All @@ -307,10 +297,9 @@ struct ab8500_fg;
* @init_total_time: Total init time during startup
* @high_curr_time: Time current has to be high to go to recovery
* @accu_charging: FG accumulation time while charging
* @accu_high_curr: FG accumulation time in high current mode
* @high_curr_threshold: High current threshold, in mA
* @lowbat_threshold: Low battery threshold, in mV
* @overbat_threshold: Over battery threshold, in mV
* @accu_high_curr_ua: FG accumulation time in high current mode
* @high_curr_threshold_ua: High current threshold, in uA
* @lowbat_threshold_uv: Low battery threshold, in uV
* @battok_falling_th_sel0 Threshold in mV for battOk signal sel0
* Resolution in 50 mV step.
* @battok_raising_th_sel1 Threshold in mV for battOk signal sel1
Expand All @@ -335,9 +324,8 @@ struct ab8500_fg_parameters {
int high_curr_time;
int accu_charging;
int accu_high_curr;
int high_curr_threshold;
int lowbat_threshold;
int overbat_threshold;
int high_curr_threshold_ua;
int lowbat_threshold_uv;
int battok_falling_th_sel0;
int battok_raising_th_sel1;
int user_cap_limit;
Expand Down Expand Up @@ -377,8 +365,6 @@ struct ab8500_maxim_parameters {
* @low_high_vol_lvl: charger voltage in temp low/high state in mV'
* @n_r_t_tbl_elements: number of elements in r_to_t_tbl
* @r_to_t_tbl: table containing resistance to temp points
* @n_v_cap_tbl_elements: number of elements in v_to_cap_tbl
* @v_to_cap_tbl: Voltage to capacity (in %) table
*/
struct ab8500_battery_type {
int resis_high;
Expand All @@ -393,8 +379,6 @@ struct ab8500_battery_type {
int low_high_vol_lvl;
int n_temp_tbl_elements;
const struct ab8500_res_to_temp *r_to_t_tbl;
int n_v_cap_tbl_elements;
const struct ab8500_v_to_cap *v_to_cap_tbl;
};

/**
Expand Down
63 changes: 34 additions & 29 deletions drivers/power/supply/ab8500_bmdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@
/* Default: temperature hysteresis */
#define AB8500_TEMP_HYSTERESIS 3

static const struct ab8500_v_to_cap cap_tbl[] = {
{4186, 100},
{4163, 99},
{4114, 95},
{4068, 90},
{3990, 80},
{3926, 70},
{3898, 65},
{3866, 60},
{3833, 55},
{3812, 50},
{3787, 40},
{3768, 30},
{3747, 25},
{3730, 20},
{3705, 15},
{3699, 14},
{3684, 12},
{3672, 9},
{3657, 7},
{3638, 6},
{3556, 4},
{3424, 2},
{3317, 1},
{3094, 0},
static struct power_supply_battery_ocv_table ocv_cap_tbl[] = {
{ .ocv = 4186000, .capacity = 100},
{ .ocv = 4163000, .capacity = 99},
{ .ocv = 4114000, .capacity = 95},
{ .ocv = 4068000, .capacity = 90},
{ .ocv = 3990000, .capacity = 80},
{ .ocv = 3926000, .capacity = 70},
{ .ocv = 3898000, .capacity = 65},
{ .ocv = 3866000, .capacity = 60},
{ .ocv = 3833000, .capacity = 55},
{ .ocv = 3812000, .capacity = 50},
{ .ocv = 3787000, .capacity = 40},
{ .ocv = 3768000, .capacity = 30},
{ .ocv = 3747000, .capacity = 25},
{ .ocv = 3730000, .capacity = 20},
{ .ocv = 3705000, .capacity = 15},
{ .ocv = 3699000, .capacity = 14},
{ .ocv = 3684000, .capacity = 12},
{ .ocv = 3672000, .capacity = 9},
{ .ocv = 3657000, .capacity = 7},
{ .ocv = 3638000, .capacity = 6},
{ .ocv = 3556000, .capacity = 4},
{ .ocv = 3424000, .capacity = 2},
{ .ocv = 3317000, .capacity = 1},
{ .ocv = 3094000, .capacity = 0},
};

/*
Expand Down Expand Up @@ -94,8 +94,6 @@ static struct ab8500_battery_type bat_type_thermistor_unknown = {
.low_high_vol_lvl = 4000,
.n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
.r_to_t_tbl = temp_tbl,
.n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
.v_to_cap_tbl = cap_tbl,
};

static const struct ab8500_bm_capacity_levels cap_levels = {
Expand All @@ -115,8 +113,8 @@ static const struct ab8500_fg_parameters fg = {
.high_curr_time = 60,
.accu_charging = 30,
.accu_high_curr = 30,
.high_curr_threshold = 50,
.lowbat_threshold = 3100,
.high_curr_threshold_ua = 50000,
.lowbat_threshold_uv = 3100000,
.battok_falling_th_sel0 = 2860,
.battok_raising_th_sel1 = 2860,
.maint_thres = 95,
Expand Down Expand Up @@ -219,6 +217,13 @@ int ab8500_bm_of_probe(struct power_supply *psy,
bi->resist_table_size = ARRAY_SIZE(temp_to_batres_tbl_thermistor);
}

if (!bi->ocv_table[0]) {
/* Default capacity table at say 25 degrees Celsius */
bi->ocv_temp[0] = 25;
bi->ocv_table[0] = ocv_cap_tbl;
bi->ocv_table_size[0] = ARRAY_SIZE(ocv_cap_tbl);
}

if (bi->temp_min == INT_MIN)
bi->temp_min = AB8500_TEMP_UNDER;
if (bi->temp_max == INT_MAX)
Expand Down
Loading

0 comments on commit 0525f34

Please sign in to comment.