diff options
author | Hakan Berg <hakan.berg@stericsson.com> | 2012-07-17 08:17:16 -0400 |
---|---|---|
committer | Lee Jones <lee.jones@linaro.org> | 2013-03-06 23:35:44 -0500 |
commit | 908fe8d6a575e2bdf349ba8635b862eeb91f7ade (patch) | |
tree | 863d1d0caffb4dfb84a118c0d885ce0c773b080a /drivers/power/ab8500_btemp.c | |
parent | d4f510f6c3f579bac0dbeaa8dc7c2dc768c31786 (diff) |
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: Hakan Berg <hakan.berg@stericsson.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Reviewed-by: Marcus COOPER <marcus.xm.cooper@stericsson.com>
Reviewed-by: Martin SJOBLOM <martin.w.sjoblom@stericsson.com>
Reviewed-by: Rabin VINCENT <rabin.vincent@stericsson.com>
Diffstat (limited to 'drivers/power/ab8500_btemp.c')
-rw-r--r-- | drivers/power/ab8500_btemp.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/drivers/power/ab8500_btemp.c b/drivers/power/ab8500_btemp.c index 07689064996e..fa60e3ac33a3 100644 --- a/drivers/power/ab8500_btemp.c +++ b/drivers/power/ab8500_btemp.c | |||
@@ -76,8 +76,8 @@ struct ab8500_btemp_ranges { | |||
76 | * @dev: Pointer to the structure device | 76 | * @dev: Pointer to the structure device |
77 | * @node: List of AB8500 BTEMPs, hence prepared for reentrance | 77 | * @node: List of AB8500 BTEMPs, hence prepared for reentrance |
78 | * @curr_source: What current source we use, in uA | 78 | * @curr_source: What current source we use, in uA |
79 | * @bat_temp: Battery temperature in degree Celcius | 79 | * @bat_temp: Dispatched battery temperature in degree Celcius |
80 | * @prev_bat_temp Last dispatched battery temperature | 80 | * @prev_bat_temp Last measured battery temperature in degree Celcius |
81 | * @parent: Pointer to the struct ab8500 | 81 | * @parent: Pointer to the struct ab8500 |
82 | * @gpadc: Pointer to the struct gpadc | 82 | * @gpadc: Pointer to the struct gpadc |
83 | * @fg: Pointer to the struct fg | 83 | * @fg: Pointer to the struct fg |
@@ -604,6 +604,7 @@ static int ab8500_btemp_id(struct ab8500_btemp *di) | |||
604 | static void ab8500_btemp_periodic_work(struct work_struct *work) | 604 | static void ab8500_btemp_periodic_work(struct work_struct *work) |
605 | { | 605 | { |
606 | int interval; | 606 | int interval; |
607 | int bat_temp; | ||
607 | struct ab8500_btemp *di = container_of(work, | 608 | struct ab8500_btemp *di = container_of(work, |
608 | struct ab8500_btemp, btemp_periodic_work.work); | 609 | struct ab8500_btemp, btemp_periodic_work.work); |
609 | 610 | ||
@@ -614,12 +615,26 @@ static void ab8500_btemp_periodic_work(struct work_struct *work) | |||
614 | dev_warn(di->dev, "failed to identify the battery\n"); | 615 | dev_warn(di->dev, "failed to identify the battery\n"); |
615 | } | 616 | } |
616 | 617 | ||
617 | di->bat_temp = ab8500_btemp_measure_temp(di); | 618 | bat_temp = ab8500_btemp_measure_temp(di); |
618 | 619 | /* | |
619 | if (di->bat_temp != di->prev_bat_temp) { | 620 | * Filter battery temperature. |
620 | di->prev_bat_temp = di->bat_temp; | 621 | * Allow direct updates on temperature only if two samples result in |
622 | * same temperature. Else only allow 1 degree change from previous | ||
623 | * reported value in the direction of the new measurement. | ||
624 | */ | ||
625 | if (bat_temp == di->prev_bat_temp || !di->initialized) { | ||
626 | if (di->bat_temp != di->prev_bat_temp || !di->initialized) { | ||
627 | di->bat_temp = bat_temp; | ||
628 | power_supply_changed(&di->btemp_psy); | ||
629 | } | ||
630 | } else if (bat_temp < di->prev_bat_temp) { | ||
631 | di->bat_temp--; | ||
632 | power_supply_changed(&di->btemp_psy); | ||
633 | } else if (bat_temp > di->prev_bat_temp) { | ||
634 | di->bat_temp++; | ||
621 | power_supply_changed(&di->btemp_psy); | 635 | power_supply_changed(&di->btemp_psy); |
622 | } | 636 | } |
637 | di->prev_bat_temp = bat_temp; | ||
623 | 638 | ||
624 | if (di->events.ac_conn || di->events.usb_conn) | 639 | if (di->events.ac_conn || di->events.usb_conn) |
625 | interval = di->bm->temp_interval_chg; | 640 | interval = di->bm->temp_interval_chg; |