diff options
author | Rhyland Klein <rklein@nvidia.com> | 2013-04-01 17:45:54 -0400 |
---|---|---|
committer | Anton Vorontsov <anton@enomsg.org> | 2013-04-16 18:35:31 -0700 |
commit | 5e0848c6026ab98f47e0e179f5c76875cd509d58 (patch) | |
tree | 332ee36d2d55cdc610e81d8d9549b8bc989bf5ca /drivers/power | |
parent | da1233364d51947d8c84a33e200fcfb177ee9f20 (diff) | |
download | blackbird-op-linux-5e0848c6026ab98f47e0e179f5c76875cd509d58.tar.gz blackbird-op-linux-5e0848c6026ab98f47e0e179f5c76875cd509d58.zip |
power_supply: Add core support for supplied_from
This patch adds support for supplies to register a list of char *'s which
represent the list of supplies which supply them. This is the opposite as
the supplied_to list.
This change maintains support for supplied_to until all drivers which make
use of it already are converted.
Signed-off-by: Rhyland Klein <rklein@nvidia.com>
Reviewed-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Anton Vorontsov <anton@enomsg.org>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/power_supply_core.c | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c index 5deac432e2ae..d843cc9df030 100644 --- a/drivers/power/power_supply_core.c +++ b/drivers/power/power_supply_core.c @@ -26,17 +26,42 @@ EXPORT_SYMBOL_GPL(power_supply_class); static struct device_type power_supply_dev_type; +static bool __power_supply_is_supplied_by(struct power_supply *supplier, + struct power_supply *supply) +{ + int i; + + if (!supply->supplied_from && !supplier->supplied_to) + return false; + + /* Support both supplied_to and supplied_from modes */ + if (supply->supplied_from) { + if (!supplier->name) + return false; + for (i = 0; i < supply->num_supplies; i++) + if (!strcmp(supplier->name, supply->supplied_from[i])) + return true; + } else { + if (!supply->name) + return false; + for (i = 0; i < supplier->num_supplicants; i++) + if (!strcmp(supplier->supplied_to[i], supply->name)) + return true; + } + + return false; +} + static int __power_supply_changed_work(struct device *dev, void *data) { struct power_supply *psy = (struct power_supply *)data; struct power_supply *pst = dev_get_drvdata(dev); - int i; - for (i = 0; i < psy->num_supplicants; i++) - if (!strcmp(psy->supplied_to[i], pst->name)) { - if (pst->external_power_changed) - pst->external_power_changed(pst); - } + if (__power_supply_is_supplied_by(psy, pst)) { + if (pst->external_power_changed) + pst->external_power_changed(pst); + } + return 0; } @@ -68,17 +93,13 @@ static int __power_supply_am_i_supplied(struct device *dev, void *data) union power_supply_propval ret = {0,}; struct power_supply *psy = (struct power_supply *)data; struct power_supply *epsy = dev_get_drvdata(dev); - int i; - for (i = 0; i < epsy->num_supplicants; i++) { - if (!strcmp(epsy->supplied_to[i], psy->name)) { - if (epsy->get_property(epsy, - POWER_SUPPLY_PROP_ONLINE, &ret)) - continue; + if (__power_supply_is_supplied_by(epsy, psy)) + if (!epsy->get_property(epsy, POWER_SUPPLY_PROP_ONLINE, &ret)) { if (ret.intval) return ret.intval; } - } + return 0; } |