Re: [PATCH 5/5] bq27x00 - don't report power-supply change so often.

From: Grazvydas Ignotas
Date: Fri Dec 30 2011 - 06:13:46 EST


CCing Lars who added this. I vaguely recall something about generating
events to make some battery monitors update but I forget the details
now, maybe it was about something else. Also CCing Anton (the
maintainer).

On Fri, Dec 30, 2011 at 2:58 AM, NeilBrown <neilb@xxxxxxx> wrote:
> A power_supply_changed should only be reported on significant changes
> such as transition between charging and not. ÂIncremental changes
> such as charge increasing should not be reported - that can easily
> be polled for.
>
> Signed-off-by: NeilBrown <neilb@xxxxxxx>
> ---
>
> Âdrivers/power/bq27x00_battery.c | Â 15 ++++++++++++---
> Â1 files changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
> index bb16f5b..7993a17 100644
> --- a/drivers/power/bq27x00_battery.c
> +++ b/drivers/power/bq27x00_battery.c
> @@ -57,11 +57,15 @@
> Â#define BQ27000_FLAG_CHGS Â Â Â Â Â Â ÂBIT(7)
> Â#define BQ27000_FLAG_FC Â Â Â Â Â Â Â Â Â Â Â ÂBIT(5)
>
> +#define BQ27000_FLAGS_IMPORTANT Â Â Â Â Â Â Â Â(BQ27000_FLAG_FC|BQ27000_FLAG_CHGS|BIT(31))
> +
> Â#define BQ27500_REG_SOC Â Â Â Â Â Â Â Â Â Â Â Â0x2C
> Â#define BQ27500_REG_DCAP Â Â Â Â Â Â Â 0x3C /* Design capacity */
> Â#define BQ27500_FLAG_DSC Â Â Â Â Â Â Â BIT(0)
> Â#define BQ27500_FLAG_FC Â Â Â Â Â Â Â Â Â Â Â ÂBIT(9)
>
> +#define BQ27500_FLAGS_IMPORTANT Â Â Â Â Â Â Â Â(BQ27500_FLAG_FC|BQ27500_FLAG_DSC|BIT(31))
> +
> Â#define BQ27000_RS Â Â Â Â Â Â Â Â Â Â 20 /* Resistor sense */
>
> Âstruct bq27x00_device_info;
> @@ -259,6 +263,7 @@ static void bq27x00_update(struct bq27x00_device_info *di)
> Â{
> Â Â Â Âstruct bq27x00_reg_cache cache = {0, };
> Â Â Â Âbool is_bq27500 = di->chip == BQ27500;
> + Â Â Â int flags_changed;
>
> Â Â Â Âcache.flags = bq27x00_read(di, BQ27x00_REG_FLAGS, is_bq27500);
> Â Â Â Âif (cache.flags >= 0) {
> @@ -280,10 +285,14 @@ static void bq27x00_update(struct bq27x00_device_info *di)
>
> Â Â Â Â/* Ignore current_now which is a snapshot of the current battery state
> Â Â Â Â * and is likely to be different even between two consecutive reads */
> - Â Â Â if (memcmp(&di->cache, &cache, sizeof(cache) - sizeof(int)) != 0) {
> - Â Â Â Â Â Â Â di->cache = cache;
> + Â Â Â flags_changed = di->cache.flags ^ cache.flags;
> + Â Â Â di->cache = cache;
> + Â Â Â if (is_bq27500)
> + Â Â Â Â Â Â Â flags_changed &= BQ27500_FLAGS_IMPORTANT;
> + Â Â Â else
> + Â Â Â Â Â Â Â flags_changed &= BQ27000_FLAGS_IMPORTANT;
> + Â Â Â if (flags_changed)
> Â Â Â Â Â Â Â Âpower_supply_changed(&di->bat);
> - Â Â Â }
>
> Â Â Â Âdi->last_update = jiffies;
> Â}
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html


--
GraÅvydas
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/