2007-12-12 19:24:17

by Andres Salomon

[permalink] [raw]
Subject: [PATCH 1/2] power: remove POWER_SUPPLY_PROP_CAPACITY_LEVEL


The CAPACITY_LEVEL stuff defines various levels of charge; however, what
is the difference between them? What differentiates between HIGH and NORMAL,
LOW and CRITICAL, etc?

As it appears that these are fairly arbitrary, we end up making such policy
decisions in the kernel (or in hardware). This is the sort of decision that
should be made in userspace, not in the kernel.

If the hardware does not support _CAPACITY and it cannot be easily calculated,
then perhaps the driver should register a custom CAPACITY_LEVEL attribute;
however, userspace should not become accustomed to looking for such a thing,
and we should certainly not encourage drivers to provide CAPACITY_LEVEL
stubs.

The following removes support for POWER_SUPPLY_PROP_CAPACITY_LEVEL. The
OLPC battery driver is the only driver making use of this, so it's
removed from there as well.

Signed-off-by: Andres Salomon <[email protected]>
---
Documentation/power_supply_class.txt | 2 --
drivers/power/olpc_battery.c | 9 ---------
drivers/power/power_supply_sysfs.c | 6 ------
include/linux/power_supply.h | 10 ----------
4 files changed, 0 insertions(+), 27 deletions(-)

diff --git a/Documentation/power_supply_class.txt b/Documentation/power_supply_class.txt
index 9758cf4..a032c31 100644
--- a/Documentation/power_supply_class.txt
+++ b/Documentation/power_supply_class.txt
@@ -100,8 +100,6 @@ age)". I.e. these attributes represents real thresholds, not design values.
ENERGY_FULL, ENERGY_EMPTY - same as above but for energy.

CAPACITY - capacity in percents.
-CAPACITY_LEVEL - capacity level. This corresponds to
-POWER_SUPPLY_CAPACITY_LEVEL_*.

TEMP - temperature of the power supply.
TEMP_AMBIENT - ambient temperature.
diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
index c998e68..af7a231 100644
--- a/drivers/power/olpc_battery.c
+++ b/drivers/power/olpc_battery.c
@@ -226,14 +226,6 @@ static int olpc_bat_get_property(struct power_supply *psy,
return ret;
val->intval = ec_byte;
break;
- case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
- if (ec_byte & BAT_STAT_FULL)
- val->intval = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
- else if (ec_byte & BAT_STAT_LOW)
- val->intval = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
- else
- val->intval = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
- break;
case POWER_SUPPLY_PROP_TEMP:
ret = olpc_ec_cmd(EC_BAT_TEMP, NULL, 0, (void *)&ec_word, 2);
if (ret)
@@ -265,7 +257,6 @@ static enum power_supply_property olpc_bat_props[] = {
POWER_SUPPLY_PROP_VOLTAGE_AVG,
POWER_SUPPLY_PROP_CURRENT_AVG,
POWER_SUPPLY_PROP_CAPACITY,
- POWER_SUPPLY_PROP_CAPACITY_LEVEL,
POWER_SUPPLY_PROP_TEMP,
POWER_SUPPLY_PROP_TEMP_AMBIENT,
POWER_SUPPLY_PROP_MANUFACTURER,
diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
index 249f61b..0331e82 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -48,9 +48,6 @@ static ssize_t power_supply_show_property(struct device *dev,
static char *technology_text[] = {
"Unknown", "NiMH", "Li-ion", "Li-poly", "LiFe", "NiCd"
};
- static char *capacity_level_text[] = {
- "Unknown", "Critical", "Low", "Normal", "High", "Full"
- };
ssize_t ret;
struct power_supply *psy = dev_get_drvdata(dev);
const ptrdiff_t off = attr - power_supply_attrs;
@@ -71,9 +68,6 @@ static ssize_t power_supply_show_property(struct device *dev,
return sprintf(buf, "%s\n", health_text[value.intval]);
else if (off == POWER_SUPPLY_PROP_TECHNOLOGY)
return sprintf(buf, "%s\n", technology_text[value.intval]);
- else if (off == POWER_SUPPLY_PROP_CAPACITY_LEVEL)
- return sprintf(buf, "%s\n",
- capacity_level_text[value.intval]);
else if (off >= POWER_SUPPLY_PROP_MODEL_NAME)
return sprintf(buf, "%s\n", value.strval);

diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 606c095..358b38d 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -56,15 +56,6 @@ enum {
POWER_SUPPLY_TECHNOLOGY_NiCd,
};

-enum {
- POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN = 0,
- POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL,
- POWER_SUPPLY_CAPACITY_LEVEL_LOW,
- POWER_SUPPLY_CAPACITY_LEVEL_NORMAL,
- POWER_SUPPLY_CAPACITY_LEVEL_HIGH,
- POWER_SUPPLY_CAPACITY_LEVEL_FULL,
-};
-
enum power_supply_property {
/* Properties of type `int' */
POWER_SUPPLY_PROP_STATUS = 0,
@@ -91,7 +82,6 @@ enum power_supply_property {
POWER_SUPPLY_PROP_ENERGY_NOW,
POWER_SUPPLY_PROP_ENERGY_AVG,
POWER_SUPPLY_PROP_CAPACITY, /* in percents! */
- POWER_SUPPLY_PROP_CAPACITY_LEVEL,
POWER_SUPPLY_PROP_TEMP,
POWER_SUPPLY_PROP_TEMP_AMBIENT,
POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
--
1.5.3.5


2007-12-12 19:48:23

by Anton Vorontsov

[permalink] [raw]
Subject: Re: [PATCH 1/2] power: remove POWER_SUPPLY_PROP_CAPACITY_LEVEL

On Wed, Dec 12, 2007 at 02:12:56PM -0500, Andres Salomon wrote:
>
> The CAPACITY_LEVEL stuff defines various levels of charge; however, what
> is the difference between them? What differentiates between HIGH and NORMAL,
> LOW and CRITICAL, etc?
>
> As it appears that these are fairly arbitrary, we end up making such policy
> decisions in the kernel (or in hardware). This is the sort of decision that
> should be made in userspace, not in the kernel.
>
> If the hardware does not support _CAPACITY and it cannot be easily calculated,
> then perhaps the driver should register a custom CAPACITY_LEVEL attribute;
> however, userspace should not become accustomed to looking for such a thing,
> and we should certainly not encourage drivers to provide CAPACITY_LEVEL
> stubs.
>
> The following removes support for POWER_SUPPLY_PROP_CAPACITY_LEVEL. The
> OLPC battery driver is the only driver making use of this, so it's
> removed from there as well.
>
> Signed-off-by: Andres Salomon <[email protected]>
> ---
> Documentation/power_supply_class.txt | 2 --
> drivers/power/olpc_battery.c | 9 ---------
> drivers/power/power_supply_sysfs.c | 6 ------
> include/linux/power_supply.h | 10 ----------
> 4 files changed, 0 insertions(+), 27 deletions(-)

^^^ This looks good. ;-) I'll apply this if David will not have any
objections.

Thanks!

> diff --git a/Documentation/power_supply_class.txt b/Documentation/power_supply_class.txt
> index 9758cf4..a032c31 100644
> --- a/Documentation/power_supply_class.txt
> +++ b/Documentation/power_supply_class.txt
> @@ -100,8 +100,6 @@ age)". I.e. these attributes represents real thresholds, not design values.
> ENERGY_FULL, ENERGY_EMPTY - same as above but for energy.
>
> CAPACITY - capacity in percents.
> -CAPACITY_LEVEL - capacity level. This corresponds to
> -POWER_SUPPLY_CAPACITY_LEVEL_*.
>
> TEMP - temperature of the power supply.
> TEMP_AMBIENT - ambient temperature.
> diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
> index c998e68..af7a231 100644
> --- a/drivers/power/olpc_battery.c
> +++ b/drivers/power/olpc_battery.c
> @@ -226,14 +226,6 @@ static int olpc_bat_get_property(struct power_supply *psy,
> return ret;
> val->intval = ec_byte;
> break;
> - case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
> - if (ec_byte & BAT_STAT_FULL)
> - val->intval = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
> - else if (ec_byte & BAT_STAT_LOW)
> - val->intval = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
> - else
> - val->intval = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
> - break;
> case POWER_SUPPLY_PROP_TEMP:
> ret = olpc_ec_cmd(EC_BAT_TEMP, NULL, 0, (void *)&ec_word, 2);
> if (ret)
> @@ -265,7 +257,6 @@ static enum power_supply_property olpc_bat_props[] = {
> POWER_SUPPLY_PROP_VOLTAGE_AVG,
> POWER_SUPPLY_PROP_CURRENT_AVG,
> POWER_SUPPLY_PROP_CAPACITY,
> - POWER_SUPPLY_PROP_CAPACITY_LEVEL,
> POWER_SUPPLY_PROP_TEMP,
> POWER_SUPPLY_PROP_TEMP_AMBIENT,
> POWER_SUPPLY_PROP_MANUFACTURER,
> diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
> index 249f61b..0331e82 100644
> --- a/drivers/power/power_supply_sysfs.c
> +++ b/drivers/power/power_supply_sysfs.c
> @@ -48,9 +48,6 @@ static ssize_t power_supply_show_property(struct device *dev,
> static char *technology_text[] = {
> "Unknown", "NiMH", "Li-ion", "Li-poly", "LiFe", "NiCd"
> };
> - static char *capacity_level_text[] = {
> - "Unknown", "Critical", "Low", "Normal", "High", "Full"
> - };
> ssize_t ret;
> struct power_supply *psy = dev_get_drvdata(dev);
> const ptrdiff_t off = attr - power_supply_attrs;
> @@ -71,9 +68,6 @@ static ssize_t power_supply_show_property(struct device *dev,
> return sprintf(buf, "%s\n", health_text[value.intval]);
> else if (off == POWER_SUPPLY_PROP_TECHNOLOGY)
> return sprintf(buf, "%s\n", technology_text[value.intval]);
> - else if (off == POWER_SUPPLY_PROP_CAPACITY_LEVEL)
> - return sprintf(buf, "%s\n",
> - capacity_level_text[value.intval]);
> else if (off >= POWER_SUPPLY_PROP_MODEL_NAME)
> return sprintf(buf, "%s\n", value.strval);
>
> diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
> index 606c095..358b38d 100644
> --- a/include/linux/power_supply.h
> +++ b/include/linux/power_supply.h
> @@ -56,15 +56,6 @@ enum {
> POWER_SUPPLY_TECHNOLOGY_NiCd,
> };
>
> -enum {
> - POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN = 0,
> - POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL,
> - POWER_SUPPLY_CAPACITY_LEVEL_LOW,
> - POWER_SUPPLY_CAPACITY_LEVEL_NORMAL,
> - POWER_SUPPLY_CAPACITY_LEVEL_HIGH,
> - POWER_SUPPLY_CAPACITY_LEVEL_FULL,
> -};
> -
> enum power_supply_property {
> /* Properties of type `int' */
> POWER_SUPPLY_PROP_STATUS = 0,
> @@ -91,7 +82,6 @@ enum power_supply_property {
> POWER_SUPPLY_PROP_ENERGY_NOW,
> POWER_SUPPLY_PROP_ENERGY_AVG,
> POWER_SUPPLY_PROP_CAPACITY, /* in percents! */
> - POWER_SUPPLY_PROP_CAPACITY_LEVEL,
> POWER_SUPPLY_PROP_TEMP,
> POWER_SUPPLY_PROP_TEMP_AMBIENT,
> POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
> --
> 1.5.3.5
>

--
Anton Vorontsov
email: [email protected]
backup email: [email protected]
irc://irc.freenode.net/bd2

2007-12-20 14:39:48

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH 1/2] power: remove POWER_SUPPLY_PROP_CAPACITY_LEVEL

On Wed 2007-12-12 14:12:56, Andres Salomon wrote:
>
> The CAPACITY_LEVEL stuff defines various levels of charge; however, what
> is the difference between them? What differentiates between HIGH and NORMAL,
> LOW and CRITICAL, etc?

On embedded hw, it is quite common that you can sense only 4-or-so
levels of battery charge, very non-linear. I suspect that's what capacity_level comes
from.

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html