bq27x00 - don't report power-supply change so often.
authorNeilBrown <neilb@suse.de>
Fri, 30 Dec 2011 00:58:49 +0000 (11:58 +1100)
committerGrazvydas Ignotas <notasas@gmail.com>
Sat, 14 Jan 2012 22:02:38 +0000 (00:02 +0200)
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.

[notasas@gmail.com: refreshed for Pali Rohár's patches]
Signed-off-by: NeilBrown <neilb@suse.de>
drivers/power/bq27x00_battery.c

index d4b5281..45a0156 100644 (file)
@@ -60,6 +60,8 @@
 #define BQ27000_FLAG_FC                        BIT(5)
 #define BQ27000_FLAG_CHGS              BIT(7) /* Charge state flag */
 
+#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)
@@ -67,6 +69,8 @@
 #define BQ27500_FLAG_SOC1              BIT(2) /* State-of-Charge threshold 1 */
 #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;
@@ -310,6 +314,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) {
@@ -337,10 +342,14 @@ static void bq27x00_update(struct bq27x00_device_info *di)
                        di->charge_design_full = bq27x00_battery_read_ilmd(di);
        }
 
-       if (memcmp(&di->cache, &cache, sizeof(cache)) != 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;
 }