diff options
author | Rui Miguel Silva <rui.silva@linaro.org> | 2016-08-16 22:31:55 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@google.com> | 2016-08-18 17:34:01 +0200 |
commit | c4582f9d7969019dc67234e96340e21dd3712c46 (patch) | |
tree | 09d283fe16e5dd6af4f406337e3b46d61aaec46e /drivers/staging/greybus/power_supply.c | |
parent | 6198f892fafbb3e5875c8a410eb2229a9cbac6ca (diff) | |
download | op-kernel-dev-c4582f9d7969019dc67234e96340e21dd3712c46.zip op-kernel-dev-c4582f9d7969019dc67234e96340e21dd3712c46.tar.gz |
greybus: power_supply: add callback to handle power supply changes
When checking for property changes we may need to act upon that change
besides reporting it using power_supply_changed. So, add a function that
will be call if the specific property changed.
As at it, adjust some indentation of the psy_props_changes array.
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Diffstat (limited to 'drivers/staging/greybus/power_supply.c')
-rw-r--r-- | drivers/staging/greybus/power_supply.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/drivers/staging/greybus/power_supply.c b/drivers/staging/greybus/power_supply.c index 058fd3c..aeb6a07e 100644 --- a/drivers/staging/greybus/power_supply.c +++ b/drivers/staging/greybus/power_supply.c @@ -70,17 +70,22 @@ static unsigned int update_interval_max = 30 * HZ; struct gb_power_supply_changes { enum power_supply_property prop; u32 tolerance_change; + void (*prop_changed)(struct gb_power_supply *gbpsy, + struct gb_power_supply_prop *prop); }; static const struct gb_power_supply_changes psy_props_changes[] = { - { .prop = GB_POWER_SUPPLY_PROP_STATUS, - .tolerance_change = 0, + { .prop = GB_POWER_SUPPLY_PROP_STATUS, + .tolerance_change = 0, + .prop_changed = NULL, }, - { .prop = GB_POWER_SUPPLY_PROP_TEMP, - .tolerance_change = 500, + { .prop = GB_POWER_SUPPLY_PROP_TEMP, + .tolerance_change = 500, + .prop_changed = NULL, }, - { .prop = GB_POWER_SUPPLY_PROP_ONLINE, - .tolerance_change = 0, + { .prop = GB_POWER_SUPPLY_PROP_ONLINE, + .tolerance_change = 0, + .prop_changed = NULL, }, }; @@ -349,18 +354,25 @@ static void check_changed(struct gb_power_supply *gbpsy, const struct gb_power_supply_changes *psyc; int val = prop->val; int prev_val = prop->previous_val; + bool changed = false; int i; for (i = 0; i < ARRAY_SIZE(psy_props_changes); i++) { psyc = &psy_props_changes[i]; if (prop->prop == psyc->prop) { if (!psyc->tolerance_change) - gbpsy->changed = true; + changed = true; else if (val < prev_val && prev_val - val > psyc->tolerance_change) - gbpsy->changed = true; + changed = true; else if (val > prev_val && val - prev_val > psyc->tolerance_change) + changed = true; + + if (changed && psyc->prop_changed) + psyc->prop_changed(gbpsy, prop); + + if (changed) gbpsy->changed = true; break; } |