diff options
-rw-r--r-- | drivers/power/power_supply_core.c | 47 | ||||
-rw-r--r-- | include/linux/power_supply.h | 3 |
2 files changed, 37 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 | ||
27 | static struct device_type power_supply_dev_type; | 27 | static struct device_type power_supply_dev_type; |
28 | 28 | ||
29 | static 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 | |||
29 | static int __power_supply_changed_work(struct device *dev, void *data) | 55 | static 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 | ||
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 002a99f96331..c1cbd5e4e484 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h | |||
@@ -171,6 +171,9 @@ struct power_supply { | |||
171 | char **supplied_to; | 171 | char **supplied_to; |
172 | size_t num_supplicants; | 172 | size_t num_supplicants; |
173 | 173 | ||
174 | char **supplied_from; | ||
175 | size_t num_supplies; | ||
176 | |||
174 | int (*get_property)(struct power_supply *psy, | 177 | int (*get_property)(struct power_supply *psy, |
175 | enum power_supply_property psp, | 178 | enum power_supply_property psp, |
176 | union power_supply_propval *val); | 179 | union power_supply_propval *val); |