aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/power_supply_core.c
diff options
context:
space:
mode:
authorDave Young <hidave.darkstar@gmail.com>2008-01-22 00:58:22 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2008-01-24 23:40:44 -0500
commit443cad920a1c6894da3de917ce02a194cc6d80ea (patch)
tree152e8d04111fbaabcdf4fbd16cde2ac555eec365 /drivers/power/power_supply_core.c
parent73cf60232ef16e1f8a64defa97214a1722db1e6c (diff)
power supply : use class iteration api
Convert to use the class iteration api. Signed-off-by: Dave Young <hidave.darkstar@gmail.com> Cc: Anton Vorontsov <cbou@mail.ru> Cc: David Woodhouse <dwmw2@infradead.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/power/power_supply_core.c')
-rw-r--r--drivers/power/power_supply_core.c74
1 files changed, 39 insertions, 35 deletions
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index a63b75cf75e2..03d6a38464ef 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -20,28 +20,29 @@
20 20
21struct class *power_supply_class; 21struct class *power_supply_class;
22 22
23static int __power_supply_changed_work(struct device *dev, void *data)
24{
25 struct power_supply *psy = (struct power_supply *)data;
26 struct power_supply *pst = dev_get_drvdata(dev);
27 int i;
28
29 for (i = 0; i < psy->num_supplicants; i++)
30 if (!strcmp(psy->supplied_to[i], pst->name)) {
31 if (pst->external_power_changed)
32 pst->external_power_changed(pst);
33 }
34 return 0;
35}
36
23static void power_supply_changed_work(struct work_struct *work) 37static void power_supply_changed_work(struct work_struct *work)
24{ 38{
25 struct power_supply *psy = container_of(work, struct power_supply, 39 struct power_supply *psy = container_of(work, struct power_supply,
26 changed_work); 40 changed_work);
27 int i;
28 41
29 dev_dbg(psy->dev, "%s\n", __FUNCTION__); 42 dev_dbg(psy->dev, "%s\n", __FUNCTION__);
30 43
31 for (i = 0; i < psy->num_supplicants; i++) { 44 class_for_each_device(power_supply_class, psy,
32 struct device *dev; 45 __power_supply_changed_work);
33
34 down(&power_supply_class->sem);
35 list_for_each_entry(dev, &power_supply_class->devices, node) {
36 struct power_supply *pst = dev_get_drvdata(dev);
37
38 if (!strcmp(psy->supplied_to[i], pst->name)) {
39 if (pst->external_power_changed)
40 pst->external_power_changed(pst);
41 }
42 }
43 up(&power_supply_class->sem);
44 }
45 46
46 power_supply_update_leds(psy); 47 power_supply_update_leds(psy);
47 48
@@ -55,32 +56,35 @@ void power_supply_changed(struct power_supply *psy)
55 schedule_work(&psy->changed_work); 56 schedule_work(&psy->changed_work);
56} 57}
57 58
58int power_supply_am_i_supplied(struct power_supply *psy) 59static int __power_supply_am_i_supplied(struct device *dev, void *data)
59{ 60{
60 union power_supply_propval ret = {0,}; 61 union power_supply_propval ret = {0,};
61 struct device *dev; 62 struct power_supply *psy = (struct power_supply *)data;
62 63 struct power_supply *epsy = dev_get_drvdata(dev);
63 down(&power_supply_class->sem); 64 int i;
64 list_for_each_entry(dev, &power_supply_class->devices, node) { 65
65 struct power_supply *epsy = dev_get_drvdata(dev); 66 for (i = 0; i < epsy->num_supplicants; i++) {
66 int i; 67 if (!strcmp(epsy->supplied_to[i], psy->name)) {
67 68 if (epsy->get_property(epsy,
68 for (i = 0; i < epsy->num_supplicants; i++) { 69 POWER_SUPPLY_PROP_ONLINE, &ret))
69 if (!strcmp(epsy->supplied_to[i], psy->name)) { 70 continue;
70 if (epsy->get_property(epsy, 71 if (ret.intval)
71 POWER_SUPPLY_PROP_ONLINE, &ret)) 72 return ret.intval;
72 continue;
73 if (ret.intval)
74 goto out;
75 }
76 } 73 }
77 } 74 }
78out: 75 return 0;
79 up(&power_supply_class->sem); 76}
77
78int power_supply_am_i_supplied(struct power_supply *psy)
79{
80 int error;
81
82 error = class_for_each_device(power_supply_class, psy,
83 __power_supply_am_i_supplied);
80 84
81 dev_dbg(psy->dev, "%s %d\n", __FUNCTION__, ret.intval); 85 dev_dbg(psy->dev, "%s %d\n", __FUNCTION__, error);
82 86
83 return ret.intval; 87 return error;
84} 88}
85 89
86int power_supply_register(struct device *parent, struct power_supply *psy) 90int power_supply_register(struct device *parent, struct power_supply *psy)