Skip to content

Commit

Permalink
power: supply: ab8500: Standardize CV voltage
Browse files Browse the repository at this point in the history
The voltage used in the constant voltage phase of the charging
exist in struct power_supply_battery_info as
constant_charge_voltage_max_uv.

Switch the custom property normal_vol_lvl to this and
consequentially change everything that relates to this value
over to using microvolts rather than millivolts so
we align internal representation of current with the
power core. Prefix every variable we change with *_uv
to indicate the unit everywhere but also to make sure
we do not miss any outlier.

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 83e5aa7 commit bc6e028
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 150 deletions.
10 changes: 4 additions & 6 deletions drivers/power/supply/ab8500-bm.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ struct ab8500_maxim_parameters {
* struct ab8500_battery_type - different batteries supported
* @resis_high: battery upper resistance limit
* @resis_low: battery lower resistance limit
* @normal_vol_lvl: charger voltage in normal state in mV
* @maint_a_cur_lvl: charger current in maintenance A state in mA
* @maint_a_vol_lvl: charger voltage in maintenance A state in mV
* @maint_a_chg_timer_h: charge time in maintenance A state
Expand All @@ -386,7 +385,6 @@ struct ab8500_maxim_parameters {
struct ab8500_battery_type {
int resis_high;
int resis_low;
int normal_vol_lvl;
int maint_a_cur_lvl;
int maint_a_vol_lvl;
int maint_a_chg_timer_h;
Expand Down Expand Up @@ -421,15 +419,15 @@ struct ab8500_bm_capacity_levels {

/**
* struct ab8500_bm_charger_parameters - Charger specific parameters
* @usb_volt_max: maximum allowed USB charger voltage in mV
* @usb_volt_max_uv: maximum allowed USB charger voltage in uV
* @usb_curr_max_ua: maximum allowed USB charger current in uA
* @ac_volt_max: maximum allowed AC charger voltage in mV
* @ac_volt_max_uv: maximum allowed AC charger voltage in uV
* @ac_curr_max_ua: maximum allowed AC charger current in uA
*/
struct ab8500_bm_charger_parameters {
int usb_volt_max;
int usb_volt_max_uv;
int usb_curr_max_ua;
int ac_volt_max;
int ac_volt_max_uv;
int ac_curr_max_ua;
};

Expand Down
4 changes: 2 additions & 2 deletions drivers/power/supply/ab8500-chargalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ struct ux500_charger_ops {
* struct ux500_charger - power supply ux500 charger sub class
* @psy power supply base class
* @ops ux500 charger operations
* @max_out_volt maximum output charger voltage in mV
* @max_out_volt_uv maximum output charger voltage in uV
* @max_out_curr_ua maximum output charger current in uA
* @enabled indicates if this charger is used or not
* @external external charger unit (pm2xxx)
*/
struct ux500_charger {
struct power_supply *psy;
struct ux500_charger_ops ops;
int max_out_volt;
int max_out_volt_uv;
int max_out_curr_ua;
int wdt_refresh;
bool enabled;
Expand Down
8 changes: 5 additions & 3 deletions drivers/power/supply/ab8500_bmdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ static const struct batres_vs_temp temp_to_batres_tbl_thermistor[] = {
static struct ab8500_battery_type bat_type_thermistor_unknown = {
.resis_high = 0,
.resis_low = 0,
.normal_vol_lvl = 4100,
.maint_a_cur_lvl = 400,
.maint_a_vol_lvl = 4050,
.maint_a_chg_timer_h = 60,
Expand Down Expand Up @@ -138,9 +137,9 @@ static const struct ab8500_maxim_parameters ab8500_maxi_params = {
};

static const struct ab8500_bm_charger_parameters chg = {
.usb_volt_max = 5500,
.usb_volt_max_uv = 5500000,
.usb_curr_max_ua = 1500000,
.ac_volt_max = 7500,
.ac_volt_max_uv = 7500000,
.ac_curr_max_ua = 1500000,
};

Expand Down Expand Up @@ -203,6 +202,9 @@ int ab8500_bm_of_probe(struct power_supply *psy,
if (bi->constant_charge_current_max_ua < 0)
bi->constant_charge_current_max_ua = 400000;

if (bi->constant_charge_voltage_max_uv < 0)
bi->constant_charge_voltage_max_uv = 4100000;

if (bi->charge_term_current_ua)
/* Charging stops when we drop below this current */
bi->charge_term_current_ua = 200000;
Expand Down
62 changes: 31 additions & 31 deletions drivers/power/supply/ab8500_chargalg.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ struct ab8500_chargalg_charger_info {
enum ab8500_chargers charger_type;
bool usb_chg_ok;
bool ac_chg_ok;
int usb_volt;
int usb_volt_uv;
int usb_curr_ua;
int ac_volt;
int ac_volt_uv;
int ac_curr_ua;
int usb_vset;
int usb_vset_uv;
int usb_iset_ua;
int ac_vset;
int ac_vset_uv;
int ac_iset_ua;
};

Expand Down Expand Up @@ -365,12 +365,12 @@ static int ab8500_chargalg_check_charger_enable(struct ab8500_chargalg *di)

if (di->chg_info.charger_type & USB_CHG) {
return di->usb_chg->ops.check_enable(di->usb_chg,
di->bm->bat_type->normal_vol_lvl,
bi->constant_charge_voltage_max_uv,
bi->constant_charge_current_max_ua);
} else if ((di->chg_info.charger_type & AC_CHG) &&
!(di->ac_chg->external)) {
return di->ac_chg->ops.check_enable(di->ac_chg,
di->bm->bat_type->normal_vol_lvl,
bi->constant_charge_voltage_max_uv,
bi->constant_charge_current_max_ua);
}
return 0;
Expand Down Expand Up @@ -546,28 +546,28 @@ static int ab8500_chargalg_kick_watchdog(struct ab8500_chargalg *di)
* ab8500_chargalg_ac_en() - Turn on/off the AC charger
* @di: pointer to the ab8500_chargalg structure
* @enable: charger on/off
* @vset: requested charger output voltage
* @vset_uv: requested charger output voltage in microvolt
* @iset_ua: requested charger output current in microampere
*
* The AC charger will be turned on/off with the requested charge voltage and
* current
*/
static int ab8500_chargalg_ac_en(struct ab8500_chargalg *di, int enable,
int vset, int iset_ua)
int vset_uv, int iset_ua)
{
static int ab8500_chargalg_ex_ac_enable_toggle;

if (!di->ac_chg || !di->ac_chg->ops.enable)
return -ENXIO;

/* Select maximum of what both the charger and the battery supports */
if (di->ac_chg->max_out_volt)
vset = min(vset, di->ac_chg->max_out_volt);
if (di->ac_chg->max_out_volt_uv)
vset_uv = min(vset_uv, di->ac_chg->max_out_volt_uv);
if (di->ac_chg->max_out_curr_ua)
iset_ua = min(iset_ua, di->ac_chg->max_out_curr_ua);

di->chg_info.ac_iset_ua = iset_ua;
di->chg_info.ac_vset = vset;
di->chg_info.ac_vset_uv = vset_uv;

/* Enable external charger */
if (enable && di->ac_chg->external &&
Expand All @@ -577,35 +577,35 @@ static int ab8500_chargalg_ac_en(struct ab8500_chargalg *di, int enable,
ab8500_chargalg_ex_ac_enable_toggle++;
}

return di->ac_chg->ops.enable(di->ac_chg, enable, vset, iset_ua);
return di->ac_chg->ops.enable(di->ac_chg, enable, vset_uv, iset_ua);
}

/**
* ab8500_chargalg_usb_en() - Turn on/off the USB charger
* @di: pointer to the ab8500_chargalg structure
* @enable: charger on/off
* @vset: requested charger output voltage
* @vset_uv: requested charger output voltage in microvolt
* @iset_ua: requested charger output current in microampere
*
* The USB charger will be turned on/off with the requested charge voltage and
* current
*/
static int ab8500_chargalg_usb_en(struct ab8500_chargalg *di, int enable,
int vset, int iset_ua)
int vset_uv, int iset_ua)
{
if (!di->usb_chg || !di->usb_chg->ops.enable)
return -ENXIO;

/* Select maximum of what both the charger and the battery supports */
if (di->usb_chg->max_out_volt)
vset = min(vset, di->usb_chg->max_out_volt);
if (di->usb_chg->max_out_volt_uv)
vset_uv = min(vset_uv, di->usb_chg->max_out_volt_uv);
if (di->usb_chg->max_out_curr_ua)
iset_ua = min(iset_ua, di->usb_chg->max_out_curr_ua);

di->chg_info.usb_iset_ua = iset_ua;
di->chg_info.usb_vset = vset;
di->chg_info.usb_vset_uv = vset_uv;

return di->usb_chg->ops.enable(di->usb_chg, enable, vset, iset_ua);
return di->usb_chg->ops.enable(di->usb_chg, enable, vset_uv, iset_ua);
}

/**
Expand Down Expand Up @@ -692,28 +692,28 @@ static void ab8500_chargalg_hold_charging(struct ab8500_chargalg *di)
/**
* ab8500_chargalg_start_charging() - Start the charger
* @di: pointer to the ab8500_chargalg structure
* @vset: requested charger output voltage
* @vset_uv: requested charger output voltage in microvolt
* @iset_ua: requested charger output current in microampere
*
* A charger will be enabled depending on the requested charger type that was
* detected previously.
*/
static void ab8500_chargalg_start_charging(struct ab8500_chargalg *di,
int vset, int iset_ua)
int vset_uv, int iset_ua)
{
switch (di->chg_info.charger_type) {
case AC_CHG:
dev_dbg(di->dev,
"AC parameters: Vset %d, Ich %d\n", vset, iset_ua);
"AC parameters: Vset %d, Ich %d\n", vset_uv, iset_ua);
ab8500_chargalg_usb_en(di, false, 0, 0);
ab8500_chargalg_ac_en(di, true, vset, iset_ua);
ab8500_chargalg_ac_en(di, true, vset_uv, iset_ua);
break;

case USB_CHG:
dev_dbg(di->dev,
"USB parameters: Vset %d, Ich %d\n", vset, iset_ua);
"USB parameters: Vset %d, Ich %d\n", vset_uv, iset_ua);
ab8500_chargalg_ac_en(di, false, 0, 0);
ab8500_chargalg_usb_en(di, true, vset, iset_ua);
ab8500_chargalg_usb_en(di, true, vset_uv, iset_ua);
break;

default:
Expand Down Expand Up @@ -777,12 +777,12 @@ static void ab8500_chargalg_check_temp(struct ab8500_chargalg *di)
*/
static void ab8500_chargalg_check_charger_voltage(struct ab8500_chargalg *di)
{
if (di->chg_info.usb_volt > di->bm->chg_params->usb_volt_max)
if (di->chg_info.usb_volt_uv > di->bm->chg_params->usb_volt_max_uv)
di->chg_info.usb_chg_ok = false;
else
di->chg_info.usb_chg_ok = true;

if (di->chg_info.ac_volt > di->bm->chg_params->ac_volt_max)
if (di->chg_info.ac_volt_uv > di->bm->chg_params->ac_volt_max_uv)
di->chg_info.ac_chg_ok = false;
else
di->chg_info.ac_chg_ok = true;
Expand Down Expand Up @@ -1173,10 +1173,10 @@ static int ab8500_chargalg_get_ext_psy_data(struct device *dev, void *data)
di->batt_data.volt_uv = ret.intval;
break;
case POWER_SUPPLY_TYPE_MAINS:
di->chg_info.ac_volt = ret.intval / 1000;
di->chg_info.ac_volt_uv = ret.intval;
break;
case POWER_SUPPLY_TYPE_USB:
di->chg_info.usb_volt = ret.intval / 1000;
di->chg_info.usb_volt_uv = ret.intval;
break;
default:
break;
Expand Down Expand Up @@ -1423,9 +1423,9 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di)
di->events.usb_cv_active,
di->chg_info.ac_curr_ua,
di->chg_info.usb_curr_ua,
di->chg_info.ac_vset,
di->chg_info.ac_vset_uv,
di->chg_info.ac_iset_ua,
di->chg_info.usb_vset,
di->chg_info.usb_vset_uv,
di->chg_info.usb_iset_ua);

switch (di->charge_state) {
Expand Down Expand Up @@ -1518,7 +1518,7 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di)
* di->curr_status.curr_step_ua
/ CHARGALG_CURR_STEP_HIGH_UA;
ab8500_chargalg_start_charging(di,
di->bm->bat_type->normal_vol_lvl,
bi->constant_charge_voltage_max_uv,
curr_step_lvl_ua);
}

Expand Down
Loading

0 comments on commit bc6e028

Please sign in to comment.