Commit bc6e0287 authored by Linus Walleij's avatar Linus Walleij Committed by Sebastian Reichel

power: supply: ab8500: Standardize CV voltage

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: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent 83e5aa77
...@@ -367,7 +367,6 @@ struct ab8500_maxim_parameters { ...@@ -367,7 +367,6 @@ struct ab8500_maxim_parameters {
* struct ab8500_battery_type - different batteries supported * struct ab8500_battery_type - different batteries supported
* @resis_high: battery upper resistance limit * @resis_high: battery upper resistance limit
* @resis_low: battery lower 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_cur_lvl: charger current in maintenance A state in mA
* @maint_a_vol_lvl: charger voltage in maintenance A state in mV * @maint_a_vol_lvl: charger voltage in maintenance A state in mV
* @maint_a_chg_timer_h: charge time in maintenance A state * @maint_a_chg_timer_h: charge time in maintenance A state
...@@ -386,7 +385,6 @@ struct ab8500_maxim_parameters { ...@@ -386,7 +385,6 @@ struct ab8500_maxim_parameters {
struct ab8500_battery_type { struct ab8500_battery_type {
int resis_high; int resis_high;
int resis_low; int resis_low;
int normal_vol_lvl;
int maint_a_cur_lvl; int maint_a_cur_lvl;
int maint_a_vol_lvl; int maint_a_vol_lvl;
int maint_a_chg_timer_h; int maint_a_chg_timer_h;
...@@ -421,15 +419,15 @@ struct ab8500_bm_capacity_levels { ...@@ -421,15 +419,15 @@ struct ab8500_bm_capacity_levels {
/** /**
* struct ab8500_bm_charger_parameters - Charger specific parameters * 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 * @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 * @ac_curr_max_ua: maximum allowed AC charger current in uA
*/ */
struct ab8500_bm_charger_parameters { struct ab8500_bm_charger_parameters {
int usb_volt_max; int usb_volt_max_uv;
int usb_curr_max_ua; int usb_curr_max_ua;
int ac_volt_max; int ac_volt_max_uv;
int ac_curr_max_ua; int ac_curr_max_ua;
}; };
......
...@@ -31,7 +31,7 @@ struct ux500_charger_ops { ...@@ -31,7 +31,7 @@ struct ux500_charger_ops {
* struct ux500_charger - power supply ux500 charger sub class * struct ux500_charger - power supply ux500 charger sub class
* @psy power supply base class * @psy power supply base class
* @ops ux500 charger operations * @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 * @max_out_curr_ua maximum output charger current in uA
* @enabled indicates if this charger is used or not * @enabled indicates if this charger is used or not
* @external external charger unit (pm2xxx) * @external external charger unit (pm2xxx)
...@@ -39,7 +39,7 @@ struct ux500_charger_ops { ...@@ -39,7 +39,7 @@ struct ux500_charger_ops {
struct ux500_charger { struct ux500_charger {
struct power_supply *psy; struct power_supply *psy;
struct ux500_charger_ops ops; struct ux500_charger_ops ops;
int max_out_volt; int max_out_volt_uv;
int max_out_curr_ua; int max_out_curr_ua;
int wdt_refresh; int wdt_refresh;
bool enabled; bool enabled;
......
...@@ -83,7 +83,6 @@ static const struct batres_vs_temp temp_to_batres_tbl_thermistor[] = { ...@@ -83,7 +83,6 @@ static const struct batres_vs_temp temp_to_batres_tbl_thermistor[] = {
static struct ab8500_battery_type bat_type_thermistor_unknown = { static struct ab8500_battery_type bat_type_thermistor_unknown = {
.resis_high = 0, .resis_high = 0,
.resis_low = 0, .resis_low = 0,
.normal_vol_lvl = 4100,
.maint_a_cur_lvl = 400, .maint_a_cur_lvl = 400,
.maint_a_vol_lvl = 4050, .maint_a_vol_lvl = 4050,
.maint_a_chg_timer_h = 60, .maint_a_chg_timer_h = 60,
...@@ -138,9 +137,9 @@ static const struct ab8500_maxim_parameters ab8500_maxi_params = { ...@@ -138,9 +137,9 @@ static const struct ab8500_maxim_parameters ab8500_maxi_params = {
}; };
static const struct ab8500_bm_charger_parameters chg = { static const struct ab8500_bm_charger_parameters chg = {
.usb_volt_max = 5500, .usb_volt_max_uv = 5500000,
.usb_curr_max_ua = 1500000, .usb_curr_max_ua = 1500000,
.ac_volt_max = 7500, .ac_volt_max_uv = 7500000,
.ac_curr_max_ua = 1500000, .ac_curr_max_ua = 1500000,
}; };
...@@ -203,6 +202,9 @@ int ab8500_bm_of_probe(struct power_supply *psy, ...@@ -203,6 +202,9 @@ int ab8500_bm_of_probe(struct power_supply *psy,
if (bi->constant_charge_current_max_ua < 0) if (bi->constant_charge_current_max_ua < 0)
bi->constant_charge_current_max_ua = 400000; 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) if (bi->charge_term_current_ua)
/* Charging stops when we drop below this current */ /* Charging stops when we drop below this current */
bi->charge_term_current_ua = 200000; bi->charge_term_current_ua = 200000;
......
...@@ -70,13 +70,13 @@ struct ab8500_chargalg_charger_info { ...@@ -70,13 +70,13 @@ struct ab8500_chargalg_charger_info {
enum ab8500_chargers charger_type; enum ab8500_chargers charger_type;
bool usb_chg_ok; bool usb_chg_ok;
bool ac_chg_ok; bool ac_chg_ok;
int usb_volt; int usb_volt_uv;
int usb_curr_ua; int usb_curr_ua;
int ac_volt; int ac_volt_uv;
int ac_curr_ua; int ac_curr_ua;
int usb_vset; int usb_vset_uv;
int usb_iset_ua; int usb_iset_ua;
int ac_vset; int ac_vset_uv;
int ac_iset_ua; int ac_iset_ua;
}; };
...@@ -365,12 +365,12 @@ static int ab8500_chargalg_check_charger_enable(struct ab8500_chargalg *di) ...@@ -365,12 +365,12 @@ static int ab8500_chargalg_check_charger_enable(struct ab8500_chargalg *di)
if (di->chg_info.charger_type & USB_CHG) { if (di->chg_info.charger_type & USB_CHG) {
return di->usb_chg->ops.check_enable(di->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); bi->constant_charge_current_max_ua);
} else if ((di->chg_info.charger_type & AC_CHG) && } else if ((di->chg_info.charger_type & AC_CHG) &&
!(di->ac_chg->external)) { !(di->ac_chg->external)) {
return di->ac_chg->ops.check_enable(di->ac_chg, 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); bi->constant_charge_current_max_ua);
} }
return 0; return 0;
...@@ -546,14 +546,14 @@ static int ab8500_chargalg_kick_watchdog(struct ab8500_chargalg *di) ...@@ -546,14 +546,14 @@ static int ab8500_chargalg_kick_watchdog(struct ab8500_chargalg *di)
* ab8500_chargalg_ac_en() - Turn on/off the AC charger * ab8500_chargalg_ac_en() - Turn on/off the AC charger
* @di: pointer to the ab8500_chargalg structure * @di: pointer to the ab8500_chargalg structure
* @enable: charger on/off * @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 * @iset_ua: requested charger output current in microampere
* *
* The AC charger will be turned on/off with the requested charge voltage and * The AC charger will be turned on/off with the requested charge voltage and
* current * current
*/ */
static int ab8500_chargalg_ac_en(struct ab8500_chargalg *di, int enable, 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; static int ab8500_chargalg_ex_ac_enable_toggle;
...@@ -561,13 +561,13 @@ static int ab8500_chargalg_ac_en(struct ab8500_chargalg *di, int enable, ...@@ -561,13 +561,13 @@ static int ab8500_chargalg_ac_en(struct ab8500_chargalg *di, int enable,
return -ENXIO; return -ENXIO;
/* Select maximum of what both the charger and the battery supports */ /* Select maximum of what both the charger and the battery supports */
if (di->ac_chg->max_out_volt) if (di->ac_chg->max_out_volt_uv)
vset = min(vset, di->ac_chg->max_out_volt); vset_uv = min(vset_uv, di->ac_chg->max_out_volt_uv);
if (di->ac_chg->max_out_curr_ua) if (di->ac_chg->max_out_curr_ua)
iset_ua = min(iset_ua, 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_iset_ua = iset_ua;
di->chg_info.ac_vset = vset; di->chg_info.ac_vset_uv = vset_uv;
/* Enable external charger */ /* Enable external charger */
if (enable && di->ac_chg->external && if (enable && di->ac_chg->external &&
...@@ -577,35 +577,35 @@ static int ab8500_chargalg_ac_en(struct ab8500_chargalg *di, int enable, ...@@ -577,35 +577,35 @@ static int ab8500_chargalg_ac_en(struct ab8500_chargalg *di, int enable,
ab8500_chargalg_ex_ac_enable_toggle++; 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 * ab8500_chargalg_usb_en() - Turn on/off the USB charger
* @di: pointer to the ab8500_chargalg structure * @di: pointer to the ab8500_chargalg structure
* @enable: charger on/off * @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 * @iset_ua: requested charger output current in microampere
* *
* The USB charger will be turned on/off with the requested charge voltage and * The USB charger will be turned on/off with the requested charge voltage and
* current * current
*/ */
static int ab8500_chargalg_usb_en(struct ab8500_chargalg *di, int enable, 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) if (!di->usb_chg || !di->usb_chg->ops.enable)
return -ENXIO; return -ENXIO;
/* Select maximum of what both the charger and the battery supports */ /* Select maximum of what both the charger and the battery supports */
if (di->usb_chg->max_out_volt) if (di->usb_chg->max_out_volt_uv)
vset = min(vset, di->usb_chg->max_out_volt); vset_uv = min(vset_uv, di->usb_chg->max_out_volt_uv);
if (di->usb_chg->max_out_curr_ua) if (di->usb_chg->max_out_curr_ua)
iset_ua = min(iset_ua, 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_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);
} }
/** /**
...@@ -692,28 +692,28 @@ static void ab8500_chargalg_hold_charging(struct ab8500_chargalg *di) ...@@ -692,28 +692,28 @@ static void ab8500_chargalg_hold_charging(struct ab8500_chargalg *di)
/** /**
* ab8500_chargalg_start_charging() - Start the charger * ab8500_chargalg_start_charging() - Start the charger
* @di: pointer to the ab8500_chargalg structure * @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 * @iset_ua: requested charger output current in microampere
* *
* A charger will be enabled depending on the requested charger type that was * A charger will be enabled depending on the requested charger type that was
* detected previously. * detected previously.
*/ */
static void ab8500_chargalg_start_charging(struct ab8500_chargalg *di, 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) { switch (di->chg_info.charger_type) {
case AC_CHG: case AC_CHG:
dev_dbg(di->dev, 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_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; break;
case USB_CHG: case USB_CHG:
dev_dbg(di->dev, 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_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; break;
default: default:
...@@ -777,12 +777,12 @@ static void ab8500_chargalg_check_temp(struct ab8500_chargalg *di) ...@@ -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) 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; di->chg_info.usb_chg_ok = false;
else else
di->chg_info.usb_chg_ok = true; 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; di->chg_info.ac_chg_ok = false;
else else
di->chg_info.ac_chg_ok = true; di->chg_info.ac_chg_ok = true;
...@@ -1173,10 +1173,10 @@ static int ab8500_chargalg_get_ext_psy_data(struct device *dev, void *data) ...@@ -1173,10 +1173,10 @@ static int ab8500_chargalg_get_ext_psy_data(struct device *dev, void *data)
di->batt_data.volt_uv = ret.intval; di->batt_data.volt_uv = ret.intval;
break; break;
case POWER_SUPPLY_TYPE_MAINS: case POWER_SUPPLY_TYPE_MAINS:
di->chg_info.ac_volt = ret.intval / 1000; di->chg_info.ac_volt_uv = ret.intval;
break; break;
case POWER_SUPPLY_TYPE_USB: case POWER_SUPPLY_TYPE_USB:
di->chg_info.usb_volt = ret.intval / 1000; di->chg_info.usb_volt_uv = ret.intval;
break; break;
default: default:
break; break;
...@@ -1423,9 +1423,9 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di) ...@@ -1423,9 +1423,9 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di)
di->events.usb_cv_active, di->events.usb_cv_active,
di->chg_info.ac_curr_ua, di->chg_info.ac_curr_ua,
di->chg_info.usb_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.ac_iset_ua,
di->chg_info.usb_vset, di->chg_info.usb_vset_uv,
di->chg_info.usb_iset_ua); di->chg_info.usb_iset_ua);
switch (di->charge_state) { switch (di->charge_state) {
...@@ -1518,7 +1518,7 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di) ...@@ -1518,7 +1518,7 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di)
* di->curr_status.curr_step_ua * di->curr_status.curr_step_ua
/ CHARGALG_CURR_STEP_HIGH_UA; / CHARGALG_CURR_STEP_HIGH_UA;
ab8500_chargalg_start_charging(di, ab8500_chargalg_start_charging(di,
di->bm->bat_type->normal_vol_lvl, bi->constant_charge_voltage_max_uv,
curr_step_lvl_ua); curr_step_lvl_ua);
} }
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment