aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorRhyland Klein <rklein@nvidia.com>2013-04-01 17:45:54 -0400
committerAnton Vorontsov <anton@enomsg.org>2013-04-16 21:35:31 -0400
commit5e0848c6026ab98f47e0e179f5c76875cd509d58 (patch)
tree332ee36d2d55cdc610e81d8d9549b8bc989bf5ca /drivers/power
parentda1233364d51947d8c84a33e200fcfb177ee9f20 (diff)
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.c47
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);
26 26
27static struct device_type power_supply_dev_type; 27static struct device_type power_supply_dev_type;
28 28
29static bool __power_supply_is_supplied_by(struct power_supply *supplier,
30 struct power_supply *supply)
31{
32 int i;
33
34 if (!supply->supplied_from && !supplier->supplied_to)
35 return false;
36
37 /* Support both supplied_to and supplied_from modes */
38 if (supply->supplied_from) {
39 if (!supplier->name)
40 return false;
41 for (i = 0; i < supply->num_supplies; i++)
42 if (!strcmp(supplier->name, supply->supplied_from[i]))
43 return true;
44 } else {
45 if (!supply->name)
46 return false;
47 for (i = 0; i < supplier->num_supplicants; i++)
48 if (!strcmp(supplier->supplied_to[i], supply->name))
49 return true;
50 }
51
52 return false;
53}
54
29static int __power_supply_changed_work(struct device *dev, void *data) 55static int __power_supply_changed_work(struct device *dev, void *data)
30{ 56{
31 struct power_supply *psy = (struct power_supply *)data; 57 struct power_supply *psy = (struct power_supply *)data;
32 struct power_supply *pst = dev_get_drvdata(dev); 58 struct power_supply *pst = dev_get_drvdata(dev);
33 int i;
34 59
35 for (i = 0; i < psy->num_supplicants; i++) 60 if (__power_supply_is_supplied_by(psy, pst)) {
36 if (!strcmp(psy->supplied_to[i], pst->name)) { 61 if (pst->external_power_changed)
37 if (pst->external_power_changed) 62 pst->external_power_changed(pst);
38 pst->external_power_changed(pst); 63 }
39 } 64
40 return 0; 65 return 0;
41} 66}
42 67
@@ -68,17 +93,13 @@ static int __power_supply_am_i_supplied(struct device *dev, void *data)
68 union power_supply_propval ret = {0,}; 93 union power_supply_propval ret = {0,};
69 struct power_supply *psy = (struct power_supply *)data; 94 struct power_supply *psy = (struct power_supply *)data;
70 struct power_supply *epsy = dev_get_drvdata(dev); 95 struct power_supply *epsy = dev_get_drvdata(dev);
71 int i;
72 96
73 for (i = 0; i < epsy->num_supplicants; i++) { 97 if (__power_supply_is_supplied_by(epsy, psy))
74 if (!strcmp(epsy->supplied_to[i], psy->name)) { 98 if (!epsy->get_property(epsy, POWER_SUPPLY_PROP_ONLINE, &ret)) {
75 if (epsy->get_property(epsy,
76 POWER_SUPPLY_PROP_ONLINE, &ret))
77 continue;
78 if (ret.intval) 99 if (ret.intval)
79 return ret.intval; 100 return ret.intval;
80 } 101 }
81 } 102
82 return 0; 103 return 0;
83} 104}
84 105