power: Assume mains power by default
PATCH 1/1 power: 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.)
---
If anyone thinks that returning 1 in this case could cause problems on some systems, I would be fine returning an error code instead. Callers would then have to be adjusted accordingly.
Alex, with this change the "auto" power profile of the radeon driver should finally work fine on all desktop systems (which could then become the default?)
drivers/power/power_supply_core.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/power/power_supply_core.c +11 -1
@@ -98,7 +98,9 @@ static int __power_supply_is_system_supp {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 ;
@@ -111,10 +113,18 @@ static int __power_supply_is_system_suppint 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);
Signature · 2 lines
Jean Delvare Suse L3
Anton Vorontsov
AppliedQuoted 12 lines · Jean Delvare
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.)
Quoted 6 lines
Signed-off-by Jean Delvare <[email protected]>Cc Anton Vorontsov <[email protected]>Cc David Woodhouse <[email protected]>Cc Matthew Garrett <[email protected]>Cc Alex Deucher <[email protected]>---
Applied, thanks!
Signature · 2 lines
Anton Vorontsov Email: [email protected]