Commit 908fe8d6 authored by Hakan Berg's avatar Hakan Berg Committed by Lee Jones

ab8500-btemp: Filter btemp readings

Battery tempreature readings sometimes fail and results in
a value far from recent values. This patch adds a software
filter that disposes such readings, by allowing direct
updates on temperature only if two samples result in the
same temperature. Else only allow 1 degree change from previous
reported value in the direction of the new measurement.
Signed-off-by: default avatarHakan Berg <hakan.berg@stericsson.com>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
Reviewed-by: default avatarMarcus COOPER <marcus.xm.cooper@stericsson.com>
Reviewed-by: default avatarMartin SJOBLOM <martin.w.sjoblom@stericsson.com>
Reviewed-by: default avatarRabin VINCENT <rabin.vincent@stericsson.com>
parent d4f510f6
...@@ -76,8 +76,8 @@ struct ab8500_btemp_ranges { ...@@ -76,8 +76,8 @@ struct ab8500_btemp_ranges {
* @dev: Pointer to the structure device * @dev: Pointer to the structure device
* @node: List of AB8500 BTEMPs, hence prepared for reentrance * @node: List of AB8500 BTEMPs, hence prepared for reentrance
* @curr_source: What current source we use, in uA * @curr_source: What current source we use, in uA
* @bat_temp: Battery temperature in degree Celcius * @bat_temp: Dispatched battery temperature in degree Celcius
* @prev_bat_temp Last dispatched battery temperature * @prev_bat_temp Last measured battery temperature in degree Celcius
* @parent: Pointer to the struct ab8500 * @parent: Pointer to the struct ab8500
* @gpadc: Pointer to the struct gpadc * @gpadc: Pointer to the struct gpadc
* @fg: Pointer to the struct fg * @fg: Pointer to the struct fg
...@@ -604,6 +604,7 @@ static int ab8500_btemp_id(struct ab8500_btemp *di) ...@@ -604,6 +604,7 @@ static int ab8500_btemp_id(struct ab8500_btemp *di)
static void ab8500_btemp_periodic_work(struct work_struct *work) static void ab8500_btemp_periodic_work(struct work_struct *work)
{ {
int interval; int interval;
int bat_temp;
struct ab8500_btemp *di = container_of(work, struct ab8500_btemp *di = container_of(work,
struct ab8500_btemp, btemp_periodic_work.work); struct ab8500_btemp, btemp_periodic_work.work);
...@@ -614,12 +615,26 @@ static void ab8500_btemp_periodic_work(struct work_struct *work) ...@@ -614,12 +615,26 @@ static void ab8500_btemp_periodic_work(struct work_struct *work)
dev_warn(di->dev, "failed to identify the battery\n"); dev_warn(di->dev, "failed to identify the battery\n");
} }
di->bat_temp = ab8500_btemp_measure_temp(di); bat_temp = ab8500_btemp_measure_temp(di);
/*
if (di->bat_temp != di->prev_bat_temp) { * Filter battery temperature.
di->prev_bat_temp = di->bat_temp; * Allow direct updates on temperature only if two samples result in
* same temperature. Else only allow 1 degree change from previous
* reported value in the direction of the new measurement.
*/
if (bat_temp == di->prev_bat_temp || !di->initialized) {
if (di->bat_temp != di->prev_bat_temp || !di->initialized) {
di->bat_temp = bat_temp;
power_supply_changed(&di->btemp_psy);
}
} else if (bat_temp < di->prev_bat_temp) {
di->bat_temp--;
power_supply_changed(&di->btemp_psy);
} else if (bat_temp > di->prev_bat_temp) {
di->bat_temp++;
power_supply_changed(&di->btemp_psy); power_supply_changed(&di->btemp_psy);
} }
di->prev_bat_temp = bat_temp;
if (di->events.ac_conn || di->events.usb_conn) if (di->events.ac_conn || di->events.usb_conn)
interval = di->bm->temp_interval_chg; interval = di->bm->temp_interval_chg;
......
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