aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorJean Delvare <jdelvare@suse.de>2011-12-10 16:53:36 -0500
committerAnton Vorontsov <cbouatmailru@gmail.com>2012-01-05 20:50:32 -0500
commit2530daa187be3adef2d7cb41bd51f1384e478f2b (patch)
treef4210ee87310b4e8e2dbbd45ebb98f25d80c0249 /drivers/power
parent62df3935a7ef842ad0af6025d2fc59d353de2e1d (diff)
power_supply: Assume mains power by default
If no power class device is found in power_supply_is_system_supplied(), the function currently returns 0, which basically means that the system is supposed to be running on battery. In practice, mobile devices tend to always implement at least one power class device and more often two (battery and AC adapter). Systems with no registered power class devices are more likely to be desktop systems, where the system is always powered by mains. So, change the default return value of power_supply_is_system_supplied() from 0 (running on battery) to 1 (running on mains.) Signed-off-by: Jean Delvare <jdelvare@suse.de> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Matthew Garrett <mjg59@srcf.ucam.org> Cc: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/power_supply_core.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index b10c121244e5..bc82f9589a0d 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -98,7 +98,9 @@ static int __power_supply_is_system_supplied(struct device *dev, void *data)
98{ 98{
99 union power_supply_propval ret = {0,}; 99 union power_supply_propval ret = {0,};
100 struct power_supply *psy = dev_get_drvdata(dev); 100 struct power_supply *psy = dev_get_drvdata(dev);
101 unsigned int *count = data;
101 102
103 (*count)++;
102 if (psy->type != POWER_SUPPLY_TYPE_BATTERY) { 104 if (psy->type != POWER_SUPPLY_TYPE_BATTERY) {
103 if (psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &ret)) 105 if (psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &ret))
104 return 0; 106 return 0;
@@ -111,10 +113,18 @@ static int __power_supply_is_system_supplied(struct device *dev, void *data)
111int power_supply_is_system_supplied(void) 113int power_supply_is_system_supplied(void)
112{ 114{
113 int error; 115 int error;
116 unsigned int count = 0;
114 117
115 error = class_for_each_device(power_supply_class, NULL, NULL, 118 error = class_for_each_device(power_supply_class, NULL, &count,
116 __power_supply_is_system_supplied); 119 __power_supply_is_system_supplied);
117 120
121 /*
122 * If no power class device was found at all, most probably we are
123 * running on a desktop system, so assume we are on mains power.
124 */
125 if (count == 0)
126 return 1;
127
118 return error; 128 return error;
119} 129}
120EXPORT_SYMBOL_GPL(power_supply_is_system_supplied); 130EXPORT_SYMBOL_GPL(power_supply_is_system_supplied);