Skip to content

Commit

Permalink
power: supply: ab8500: Sink current tables into charger code
Browse files Browse the repository at this point in the history
The two tables for input and output current translation from
register values does not need to be passed around from the
battery manager data. Just push it down into the charger code
where it is used, like other tables in that code.

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 59f1b85 commit 3aca6ec
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 43 deletions.
8 changes: 0 additions & 8 deletions drivers/power/supply/ab8500-bm.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,6 @@ struct ab8500_bm_charger_parameters {
* @interval_not_charging charge alg cycle period time when not charging (sec)
* @temp_hysteresis temperature hysteresis
* @gnd_lift_resistance Battery ground to phone ground resistance (mOhm)
* @n_chg_out_curr number of elements in array chg_output_curr
* @n_chg_in_curr number of elements in array chg_input_curr
* @chg_output_curr charger output current level map
* @chg_input_curr charger input current level map
* @maxi maximization parameters
* @cap_levels capacity in percent for the different capacity levels
* @bat_type table of supported battery types
Expand Down Expand Up @@ -519,10 +515,6 @@ struct ab8500_bm_data {
int interval_not_charging;
int temp_hysteresis;
int gnd_lift_resistance;
int n_chg_out_curr;
int n_chg_in_curr;
int *chg_output_curr;
int *chg_input_curr;
const struct ab8500_maxim_parameters *maxi;
const struct ab8500_bm_capacity_levels *cap_levels;
struct ab8500_battery_type *bat_type;
Expand Down
22 changes: 0 additions & 22 deletions drivers/power/supply/ab8500_bmdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,24 +436,6 @@ static const struct ab8500_bm_charger_parameters chg = {
.ac_curr_max = 1500,
};

/*
* This array maps the raw hex value to charger output current used by the
* AB8500 values
*/
static int ab8500_charge_output_curr_map[] = {
100, 200, 300, 400, 500, 600, 700, 800,
900, 1000, 1100, 1200, 1300, 1400, 1500, 1500,
};

/*
* This array maps the raw hex value to charger input current used by the
* AB8500 values
*/
static int ab8500_charge_input_curr_map[] = {
50, 98, 193, 290, 380, 450, 500, 600,
700, 800, 900, 1000, 1100, 1300, 1400, 1500,
};

struct ab8500_bm_data ab8500_bm_data = {
.temp_under = 3,
.temp_low = 8,
Expand All @@ -479,13 +461,9 @@ struct ab8500_bm_data ab8500_bm_data = {
.interval_not_charging = 120,
.temp_hysteresis = 3,
.gnd_lift_resistance = 34,
.chg_output_curr = ab8500_charge_output_curr_map,
.n_chg_out_curr = ARRAY_SIZE(ab8500_charge_output_curr_map),
.maxi = &ab8500_maxi_params,
.chg_params = &chg,
.fg_params = &fg,
.chg_input_curr = ab8500_charge_input_curr_map,
.n_chg_in_curr = ARRAY_SIZE(ab8500_charge_input_curr_map),
};

int ab8500_bm_of_probe(struct power_supply *psy,
Expand Down
38 changes: 25 additions & 13 deletions drivers/power/supply/ab8500_charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,21 +1025,33 @@ static int ab8500_voltage_to_regval(int voltage)
return -1;
}

/* This array maps the raw register value to charger input current */
static int ab8500_charge_input_curr_map[] = {
50, 98, 193, 290, 380, 450, 500, 600,
700, 800, 900, 1000, 1100, 1300, 1400, 1500,
};

/* This array maps the raw register value to charger output current */
static int ab8500_charge_output_curr_map[] = {
100, 200, 300, 400, 500, 600, 700, 800,
900, 1000, 1100, 1200, 1300, 1400, 1500, 1500,
};

static int ab8500_current_to_regval(struct ab8500_charger *di, int curr)
{
int i;

if (curr < di->bm->chg_output_curr[0])
if (curr < ab8500_charge_output_curr_map[0])
return 0;

for (i = 0; i < di->bm->n_chg_out_curr; i++) {
if (curr < di->bm->chg_output_curr[i])
for (i = 0; i < ARRAY_SIZE(ab8500_charge_output_curr_map); i++) {
if (curr < ab8500_charge_output_curr_map[i])
return i - 1;
}

/* If not last element, return error */
i = di->bm->n_chg_out_curr - 1;
if (curr == di->bm->chg_output_curr[i])
i = ARRAY_SIZE(ab8500_charge_output_curr_map) - 1;
if (curr == ab8500_charge_output_curr_map[i])
return i;
else
return -1;
Expand All @@ -1049,17 +1061,17 @@ static int ab8500_vbus_in_curr_to_regval(struct ab8500_charger *di, int curr)
{
int i;

if (curr < di->bm->chg_input_curr[0])
if (curr < ab8500_charge_input_curr_map[0])
return 0;

for (i = 0; i < di->bm->n_chg_in_curr; i++) {
if (curr < di->bm->chg_input_curr[i])
for (i = 0; i < ARRAY_SIZE(ab8500_charge_input_curr_map); i++) {
if (curr < ab8500_charge_input_curr_map[i])
return i - 1;
}

/* If not last element, return error */
i = di->bm->n_chg_in_curr - 1;
if (curr == di->bm->chg_input_curr[i])
i = ARRAY_SIZE(ab8500_charge_input_curr_map) - 1;
if (curr == ab8500_charge_input_curr_map[i])
return i;
else
return -1;
Expand Down Expand Up @@ -2673,7 +2685,7 @@ static void ab8500_charger_vbus_drop_end_work(struct work_struct *work)
return;
}

curr = di->bm->chg_input_curr[
curr = ab8500_charge_input_curr_map[
reg_value >> AUTO_VBUS_IN_CURR_LIM_SHIFT];

if (di->max_usb_in_curr.calculated_max != curr) {
Expand Down Expand Up @@ -3503,7 +3515,7 @@ static int ab8500_charger_probe(struct platform_device *pdev)
di->ac_chg.max_out_volt = ab8500_charger_voltage_map[
ARRAY_SIZE(ab8500_charger_voltage_map) - 1];
di->ac_chg.max_out_curr =
di->bm->chg_output_curr[di->bm->n_chg_out_curr - 1];
ab8500_charge_output_curr_map[ARRAY_SIZE(ab8500_charge_output_curr_map) - 1];
di->ac_chg.wdt_refresh = CHG_WD_INTERVAL;
/*
* The AB8505 only supports USB charging. If we are not the
Expand All @@ -3524,7 +3536,7 @@ static int ab8500_charger_probe(struct platform_device *pdev)
di->usb_chg.max_out_volt = ab8500_charger_voltage_map[
ARRAY_SIZE(ab8500_charger_voltage_map) - 1];
di->usb_chg.max_out_curr =
di->bm->chg_output_curr[di->bm->n_chg_out_curr - 1];
ab8500_charge_output_curr_map[ARRAY_SIZE(ab8500_charge_output_curr_map) - 1];
di->usb_chg.wdt_refresh = CHG_WD_INTERVAL;
di->usb_chg.external = false;
di->usb_state.usb_current = -1;
Expand Down

0 comments on commit 3aca6ec

Please sign in to comment.