]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
power_supply: Add function to return system-wide power state
authorMatthew Garrett <mjg59@srcf.ucam.org>
Tue, 26 Aug 2008 20:09:59 +0000 (21:09 +0100)
committerAnton Vorontsov <cbouatmailru@gmail.com>
Sun, 31 Aug 2008 22:42:54 +0000 (02:42 +0400)
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>
drivers/power/power_supply_core.c
include/linux/power_supply.h

index cb1ccb4729210c1a3cfd8901bf7dea5c56117146..f44f5b608f6a451af9fa97f7b2ca99984cbeec15 100644 (file)
@@ -87,6 +87,30 @@ int power_supply_am_i_supplied(struct power_supply *psy)
        return error;
 }
 
+static int __power_supply_is_system_supplied(struct device *dev, void *data)
+{
+       union power_supply_propval ret = {0,};
+       struct power_supply *psy = dev_get_drvdata(dev);
+
+       if (psy->type != POWER_SUPPLY_TYPE_BATTERY) {
+               if (psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &ret))
+                       return 0;
+               if (ret.intval)
+                       return ret.intval;
+       }
+       return 0;
+}
+
+int power_supply_is_system_supplied(void)
+{
+       int error;
+
+       error = class_for_each_device(power_supply_class, NULL, NULL,
+                                     __power_supply_is_system_supplied);
+
+       return error;
+}
+
 int power_supply_register(struct device *parent, struct power_supply *psy)
 {
        int rc = 0;
@@ -148,6 +172,7 @@ static void __exit power_supply_class_exit(void)
 
 EXPORT_SYMBOL_GPL(power_supply_changed);
 EXPORT_SYMBOL_GPL(power_supply_am_i_supplied);
+EXPORT_SYMBOL_GPL(power_supply_is_system_supplied);
 EXPORT_SYMBOL_GPL(power_supply_register);
 EXPORT_SYMBOL_GPL(power_supply_unregister);
 
index ea96ead1d39daa0ac621d12ae28633e30e4c7f71..f9348cba6dc11ec32ed425e4d271ba6100de43ab 100644 (file)
@@ -165,6 +165,12 @@ struct power_supply_info {
 extern void power_supply_changed(struct power_supply *psy);
 extern int power_supply_am_i_supplied(struct power_supply *psy);
 
+#if defined(CONFIG_POWER_SUPPLY) || defined(CONFIG_POWER_SUPPLY_MODULE)
+extern int power_supply_is_system_supplied(void);
+#else
+static inline int power_supply_is_system_supplied(void) { return -ENOSYS; }
+#endif
+
 extern int power_supply_register(struct device *parent,
                                 struct power_supply *psy);
 extern void power_supply_unregister(struct power_supply *psy);