aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Garrett <mjg59@srcf.ucam.org>2008-08-26 16:09:59 -0400
committerAnton Vorontsov <cbouatmailru@gmail.com>2008-08-31 18:42:54 -0400
commit942ed161944b3476639916cf544e6975b29c985a (patch)
treea05e3bd0d6b59de318f3bfc5557502c13dde1bc4
parente82374fd1a804e197fc2a54c3930e70c5d300abc (diff)
power_supply: Add function to return system-wide power state
Certain drivers benefit from knowing whether the system is on ac or battery, for instance when determining which backlight registers to read. This adds a simple call to determine whether there's an online power supply other than any batteries. Signed-off-by: Matthew Garrett <mjg@redhat.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
-rw-r--r--drivers/power/power_supply_core.c25
-rw-r--r--include/linux/power_supply.h6
2 files changed, 31 insertions, 0 deletions
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index cb1ccb472921..f44f5b608f6a 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -87,6 +87,30 @@ int power_supply_am_i_supplied(struct power_supply *psy)
87 return error; 87 return error;
88} 88}
89 89
90static int __power_supply_is_system_supplied(struct device *dev, void *data)
91{
92 union power_supply_propval ret = {0,};
93 struct power_supply *psy = dev_get_drvdata(dev);
94
95 if (psy->type != POWER_SUPPLY_TYPE_BATTERY) {
96 if (psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &ret))
97 return 0;
98 if (ret.intval)
99 return ret.intval;
100 }
101 return 0;
102}
103
104int power_supply_is_system_supplied(void)
105{
106 int error;
107
108 error = class_for_each_device(power_supply_class, NULL, NULL,
109 __power_supply_is_system_supplied);
110
111 return error;
112}
113
90int power_supply_register(struct device *parent, struct power_supply *psy) 114int power_supply_register(struct device *parent, struct power_supply *psy)
91{ 115{
92 int rc = 0; 116 int rc = 0;
@@ -148,6 +172,7 @@ static void __exit power_supply_class_exit(void)
148 172
149EXPORT_SYMBOL_GPL(power_supply_changed); 173EXPORT_SYMBOL_GPL(power_supply_changed);
150EXPORT_SYMBOL_GPL(power_supply_am_i_supplied); 174EXPORT_SYMBOL_GPL(power_supply_am_i_supplied);
175EXPORT_SYMBOL_GPL(power_supply_is_system_supplied);
151EXPORT_SYMBOL_GPL(power_supply_register); 176EXPORT_SYMBOL_GPL(power_supply_register);
152EXPORT_SYMBOL_GPL(power_supply_unregister); 177EXPORT_SYMBOL_GPL(power_supply_unregister);
153 178
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index ea96ead1d39d..f9348cba6dc1 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -165,6 +165,12 @@ struct power_supply_info {
165extern void power_supply_changed(struct power_supply *psy); 165extern void power_supply_changed(struct power_supply *psy);
166extern int power_supply_am_i_supplied(struct power_supply *psy); 166extern int power_supply_am_i_supplied(struct power_supply *psy);
167 167
168#if defined(CONFIG_POWER_SUPPLY) || defined(CONFIG_POWER_SUPPLY_MODULE)
169extern int power_supply_is_system_supplied(void);
170#else
171static inline int power_supply_is_system_supplied(void) { return -ENOSYS; }
172#endif
173
168extern int power_supply_register(struct device *parent, 174extern int power_supply_register(struct device *parent,
169 struct power_supply *psy); 175 struct power_supply *psy);
170extern void power_supply_unregister(struct power_supply *psy); 176extern void power_supply_unregister(struct power_supply *psy);