Skip to content

Commit

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

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

Drop some duplicate unused defines in a header.

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 1091ed7 commit 83e5aa7
Show file tree
Hide file tree
Showing 5 changed files with 270 additions and 266 deletions.
25 changes: 8 additions & 17 deletions drivers/power/supply/ab8500-bm.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,6 @@
#define BTEMP_HIGH_TH_57_1 0x02
#define BTEMP_HIGH_TH_62 0x03

/* current is mA */
#define USB_0P1A 100
#define USB_0P2A 200
#define USB_0P3A 300
#define USB_0P4A 400
#define USB_0P5A 500

#define LOW_BAT_3P1V 0x20
#define LOW_BAT_2P3V 0x00
#define LOW_BAT_RESET 0x01
Expand Down Expand Up @@ -359,22 +352,21 @@ struct ab8500_fg_parameters {
/**
* struct ab8500_charger_maximization - struct used by the board config.
* @use_maxi: Enable maximization for this battery type
* @maxi_chg_curr: Maximum charger current allowed
* @maxi_chg_curr_ua: Maximum charger current allowed in microampere
* @maxi_wait_cycles: cycles to wait before setting charger current
* @charger_curr_step delta between two charger current settings (mA)
* @charger_curr_step_ua: delta between two charger current settings (uA)
*/
struct ab8500_maxim_parameters {
bool ena_maxi;
int chg_curr;
int chg_curr_ua;
int wait_cycles;
int charger_curr_step;
int charger_curr_step_ua;
};

/**
* struct ab8500_battery_type - different batteries supported
* @resis_high: battery upper resistance limit
* @resis_low: battery lower resistance limit
* @normal_cur_lvl: charger current in normal state in mA
* @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
Expand All @@ -394,7 +386,6 @@ struct ab8500_maxim_parameters {
struct ab8500_battery_type {
int resis_high;
int resis_low;
int normal_cur_lvl;
int normal_vol_lvl;
int maint_a_cur_lvl;
int maint_a_vol_lvl;
Expand Down Expand Up @@ -431,15 +422,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_curr_max: maximum allowed USB charger current in mA
* @usb_curr_max_ua: maximum allowed USB charger current in uA
* @ac_volt_max: maximum allowed AC charger voltage in mV
* @ac_curr_max: maximum allowed AC charger current in mA
* @ac_curr_max_ua: maximum allowed AC charger current in uA
*/
struct ab8500_bm_charger_parameters {
int usb_volt_max;
int usb_curr_max;
int usb_curr_max_ua;
int ac_volt_max;
int ac_curr_max;
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 @@ -32,15 +32,15 @@ struct ux500_charger_ops {
* @psy power supply base class
* @ops ux500 charger operations
* @max_out_volt maximum output charger voltage in mV
* @max_out_curr maximum output charger current in mA
* @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_curr;
int max_out_curr_ua;
int wdt_refresh;
bool enabled;
bool external;
Expand Down
12 changes: 7 additions & 5 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_cur_lvl = 400,
.normal_vol_lvl = 4100,
.maint_a_cur_lvl = 400,
.maint_a_vol_lvl = 4050,
Expand Down Expand Up @@ -133,16 +132,16 @@ static const struct ab8500_fg_parameters fg = {

static const struct ab8500_maxim_parameters ab8500_maxi_params = {
.ena_maxi = true,
.chg_curr = 910,
.chg_curr_ua = 910000,
.wait_cycles = 10,
.charger_curr_step = 100,
.charger_curr_step_ua = 100000,
};

static const struct ab8500_bm_charger_parameters chg = {
.usb_volt_max = 5500,
.usb_curr_max = 1500,
.usb_curr_max_ua = 1500000,
.ac_volt_max = 7500,
.ac_curr_max = 1500,
.ac_curr_max_ua = 1500000,
};

/* This is referenced directly in the charger code */
Expand Down Expand Up @@ -201,6 +200,9 @@ int ab8500_bm_of_probe(struct power_supply *psy,
bi->overvoltage_limit_uv = 4050000;
}

if (bi->constant_charge_current_max_ua < 0)
bi->constant_charge_current_max_ua = 400000;

if (bi->charge_term_current_ua)
/* Charging stops when we drop below this current */
bi->charge_term_current_ua = 200000;
Expand Down
Loading

0 comments on commit 83e5aa7

Please sign in to comment.