* [PATCH] power: Assume mains power by default
@ 2011-12-10 21:53 Jean Delvare
2012-01-06 1:52 ` Anton Vorontsov
0 siblings, 1 reply; 2+ messages in thread
From: Jean Delvare @ 2011-12-10 21:53 UTC (permalink / raw)
To: Anton Vorontsov, David Woodhouse
Cc: linux-kernel, Matthew Garrett, Alex Deucher
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: Anton Vorontsov <cbou@mail.ru>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Matthew Garrett <mjg59@srcf.ucam.org>
Cc: Alex Deucher <alexander.deucher@amd.com>
---
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(-)
--- linux-3.2-rc4.orig/drivers/power/power_supply_core.c 2011-07-22 04:17:23.000000000 +0200
+++ linux-3.2-rc4/drivers/power/power_supply_core.c 2011-12-10 10:04:52.000000000 +0100
@@ -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_supp
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);
--
Jean Delvare
Suse L3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] power: Assume mains power by default
2011-12-10 21:53 [PATCH] power: Assume mains power by default Jean Delvare
@ 2012-01-06 1:52 ` Anton Vorontsov
0 siblings, 0 replies; 2+ messages in thread
From: Anton Vorontsov @ 2012-01-06 1:52 UTC (permalink / raw)
To: Jean Delvare; +Cc: David Woodhouse, linux-kernel, Matthew Garrett, Alex Deucher
On Sat, Dec 10, 2011 at 10:53:36PM +0100, Jean Delvare wrote:
> 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: Anton Vorontsov <cbou@mail.ru>
> Cc: David Woodhouse <dwmw2@infradead.org>
> Cc: Matthew Garrett <mjg59@srcf.ucam.org>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> ---
Applied, thanks!
--
Anton Vorontsov
Email: cbouatmailru@gmail.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-01-06 1:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-10 21:53 [PATCH] power: Assume mains power by default Jean Delvare
2012-01-06 1:52 ` Anton Vorontsov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).