summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Lynn <andrew.lynn@stericsson.com>2011-08-18 15:08:21 +0100
committerUlf Hansson <ulf.hansson@stericsson.com>2011-09-19 16:00:10 +0200
commit735a95532cf87d3fb743e8d0a3da898b67fa48c6 (patch)
tree340a687306e0606ff4e06bdb140cc08b6ff10237
parentf76c8e15e9effc79c6ec98eacf3dcf294000f4cd (diff)
ab8500-bm: Ground lift compensation for Tbat
Measure Ibat and remove the resulting voltage between Vbat- and Gnd from Vntc readings. ST-Ericsson ID: 350661 ST-Ericsson FOSS-OUT ID: Trivial ST-Ericsson Linux next: NA Change-Id: I232b9fc7da3ea69e2062feda98776ded33d6253b Signed-off-by: Andrew Lynn <andrew.lynn@stericsson.com> Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/27869 Reviewed-by: QATOOLS Reviewed-by: QABUILD Reviewed-by: QATEST Reviewed-by: Johan PALSSON <johan.palsson@stericsson.com> Reviewed-by: Jonas ABERG <jonas.aberg@stericsson.com> Reviewed-by: Karl KOMIEROWSKI <karl.komierowski@stericsson.com>
-rw-r--r--arch/arm/mach-ux500/board-mop500-bm.c1
-rw-r--r--drivers/power/ab8500_btemp.c31
-rw-r--r--include/linux/mfd/ab8500/bm.h2
3 files changed, 27 insertions, 7 deletions
diff --git a/arch/arm/mach-ux500/board-mop500-bm.c b/arch/arm/mach-ux500/board-mop500-bm.c
index 86be12cad3b..1d8730408fa 100644
--- a/arch/arm/mach-ux500/board-mop500-bm.c
+++ b/arch/arm/mach-ux500/board-mop500-bm.c
@@ -414,6 +414,7 @@ struct ab8500_bm_data ab8500_bm_data = {
.interval_charging = 5,
.interval_not_charging = 120,
.temp_hysteresis = 3,
+ .gnd_lift_resistance = 34,
.maxi = &maxi_params,
.chg_params = &chg,
.fg_params = &fg,
diff --git a/drivers/power/ab8500_btemp.c b/drivers/power/ab8500_btemp.c
index 336384c882f..70e3a4688c9 100644
--- a/drivers/power/ab8500_btemp.c
+++ b/drivers/power/ab8500_btemp.c
@@ -74,6 +74,7 @@ struct ab8500_btemp_ranges {
* @prev_bat_temp Last dispatched battery temperature
* @parent: Pointer to the struct ab8500
* @gpadc: Pointer to the struct gpadc
+ * @fg: Pointer to the struct fg
* @pdata: Pointer to the ab8500_btemp platform data
* @bat: Pointer to the ab8500_bm platform data
* @btemp_psy: Structure for BTEMP specific battery properties
@@ -91,6 +92,7 @@ struct ab8500_btemp {
int prev_bat_temp;
struct ab8500 *parent;
struct ab8500_gpadc *gpadc;
+ struct ab8500_fg *fg;
struct ab8500_btemp_platform_data *pdata;
struct ab8500_bm_data *bat;
struct power_supply btemp_psy;
@@ -126,13 +128,14 @@ struct ab8500_btemp *ab8500_btemp_get(void)
* ab8500_btemp_batctrl_volt_to_res() - convert batctrl voltage to resistance
* @di: pointer to the ab8500_btemp structure
* @v_batctrl: measured batctrl voltage
+ * @inst_curr: measured instant current
*
* This function returns the battery resistance that is
* derived from the BATCTRL voltage.
* Returns value in Ohms.
*/
static int ab8500_btemp_batctrl_volt_to_res(struct ab8500_btemp *di,
- int v_batctrl)
+ int v_batctrl, int inst_curr)
{
int rbs;
@@ -151,7 +154,9 @@ static int ab8500_btemp_batctrl_volt_to_res(struct ab8500_btemp *di,
* If the battery has internal NTC, we use the current
* source to calculate the resistance, 7uA or 20uA
*/
- rbs = v_batctrl * 1000 / di->curr_source;
+ rbs = (v_batctrl * 1000
+ - di->bat->gnd_lift_resistance * inst_curr)
+ / di->curr_source;
} else {
/*
* BAT_CTRL is internally
@@ -342,8 +347,10 @@ disable_force_comp:
static int ab8500_btemp_get_batctrl_res(struct ab8500_btemp *di)
{
int ret;
- int batctrl;
+ int batctrl = 0;
int res;
+ int inst_curr;
+ int i = 0;
/*
* BATCTRL current sources are included on AB8500 cut2.0
@@ -355,8 +362,18 @@ static int ab8500_btemp_get_batctrl_res(struct ab8500_btemp *di)
return ret;
}
- batctrl = ab8500_btemp_read_batctrl_voltage(di);
- res = ab8500_btemp_batctrl_volt_to_res(di, batctrl);
+ if (!di->fg)
+ di->fg = ab8500_fg_get();
+ if (!di->fg || ab8500_fg_inst_curr_nonblocking(di->fg, &inst_curr))
+ inst_curr = 0;
+ do {
+ batctrl += ab8500_btemp_read_batctrl_voltage(di);
+ i++;
+ msleep(1);
+ barrier();
+ } while (inst_curr == INVALID_CURRENT);
+ batctrl /= i;
+ res = ab8500_btemp_batctrl_volt_to_res(di, batctrl, inst_curr);
ret = ab8500_btemp_curr_source_enable(di, false);
if (ret) {
@@ -364,8 +381,8 @@ static int ab8500_btemp_get_batctrl_res(struct ab8500_btemp *di)
return ret;
}
- dev_dbg(di->dev, "%s batctrl: %d res: %d ",
- __func__, batctrl, res);
+ dev_dbg(di->dev, "%s batctrl: %d res: %d inst_curr: %d\n",
+ __func__, batctrl, res, inst_curr);
return res;
}
diff --git a/include/linux/mfd/ab8500/bm.h b/include/linux/mfd/ab8500/bm.h
index cbd66dfd9ec..0bd8703b2bd 100644
--- a/include/linux/mfd/ab8500/bm.h
+++ b/include/linux/mfd/ab8500/bm.h
@@ -415,6 +415,7 @@ struct ab8500_bm_charger_parameters {
* @interval_charging charge alg cycle period time when charging (sec)
* @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)
* @maxi: maximization parameters
* @cap_levels capacity in percent for the different capacity levels
* @bat_type table of supported battery types
@@ -442,6 +443,7 @@ struct ab8500_bm_data {
int interval_charging;
int interval_not_charging;
int temp_hysteresis;
+ int gnd_lift_resistance;
const struct ab8500_maxim_parameters *maxi;
const struct ab8500_bm_capacity_levels *cap_levels;
const struct battery_type *bat_type;