Skip to content

Commit

Permalink
power_supply: Assume mains power by default
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jean Delvare authored and Anton Vorontsov committed Jan 6, 2012
1 parent 62df393 commit 2530daa
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion drivers/power/power_supply_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ 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);
unsigned int *count = data;

(*count)++;
if (psy->type != POWER_SUPPLY_TYPE_BATTERY) {
if (psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &ret))
return 0;
Expand All @@ -111,10 +113,18 @@ static int __power_supply_is_system_supplied(struct device *dev, void *data)
int power_supply_is_system_supplied(void)
{
int error;
unsigned int count = 0;

error = class_for_each_device(power_supply_class, NULL, NULL,
error = class_for_each_device(power_supply_class, NULL, &count,
__power_supply_is_system_supplied);

/*
* If no power class device was found at all, most probably we are
* running on a desktop system, so assume we are on mains power.
*/
if (count == 0)
return 1;

return error;
}
EXPORT_SYMBOL_GPL(power_supply_is_system_supplied);
Expand Down

0 comments on commit 2530daa

Please sign in to comment.