power_supply: add a charge_type status to the api, and use it for olpc driver
Subsystems (2)
PATCH 5/5 power_supply: add a charge_type status to the api, and use it for olpc driver
This adds a new sysfs file called 'charge_type' which displays the type of charging (n/a, trickle charge, slow charge, or fast charging). This allows things like battery diagnostics to determine what the battery/EC is doing without resorting to changing the 'status' sysfs output.
--- Documentation/power/power_supply_class.txt | 4 ++++ drivers/power/olpc_battery.c | 9 +++++++++ drivers/power/power_supply_sysfs.c | 6 ++++++ include/linux/power_supply.h | 8 ++++++++ 4 files changed, 27 insertions(+), 0 deletions(-)
Documentation/power/power_supply_class.txt +4 -0
@@ -76,6 +76,10 @@ STATUS - this attribute represents operating status (charging, full, discharging (i.e. powering a load), etc.). This corresponds to BATTERY_STATUS_* values, as defined in battery.h. +CHARGE_TYPE - batteries can typically charge at different rates. +This defines trickle, slow, and fast charges. For batteries that +are already charged or discharging, 'n/a' can be displayed. + HEALTH - represents health of the battery, values corresponds to POWER_SUPPLY_HEALTH_*, defined in battery.h.
drivers/power/olpc_battery.c +9 -0
@@ -230,6 +230,14 @@ static int olpc_bat_get_property(struct power_supply *psy,if (ret)return ret;break ; +case POWER_SUPPLY_PROP_CHARGE_TYPE : +if (ec_byte &BAT_STAT_TRICKLE ) + val->intval =POWER_SUPPLY_CHARGE_TYPE_TRICKLE ; +else if (ec_byte &BAT_STAT_CHARGING ) + val->intval =POWER_SUPPLY_CHARGE_TYPE_FAST ; +else + val->intval =POWER_SUPPLY_CHARGE_TYPE_NONE ; +break ;case POWER_SUPPLY_PROP_PRESENT : val->intval = !!(ec_byte & (BAT_STAT_PRESENT |BAT_STAT_TRICKLE ));break ;
@@ -321,6 +329,7 @@ static int olpc_bat_get_property(struct power_supply *psy,static enum power_supply_property olpc_bat_props[] = {POWER_SUPPLY_PROP_STATUS , +POWER_SUPPLY_PROP_CHARGE_TYPE ,POWER_SUPPLY_PROP_PRESENT ,POWER_SUPPLY_PROP_HEALTH ,POWER_SUPPLY_PROP_TECHNOLOGY ,
drivers/power/power_supply_sysfs.c +6 -0
@@ -43,6 +43,9 @@ static ssize_t power_supply_show_property(struct device *dev,static char *status_text[] = {"Unknown" ,"Charging" ,"Discharging" ,"Not charging" ,"Full" }; +static char *charge_type[] = { +"N/A" ,"Trickle" ,"Slow" ,"Fast" + };static char *health_text[] = {"Unknown" ,"Good" ,"Overheat" ,"Dead" ,"Over voltage" ,"Unspecified failure" ,"Cold" ,
@@ -70,6 +73,8 @@ static ssize_t power_supply_show_property(struct device *dev,if (off ==POWER_SUPPLY_PROP_STATUS )return sprintf (buf,"%s\n" , status_text[value.intval]); +else if (off ==POWER_SUPPLY_PROP_CHARGE_TYPE ) +return sprintf (buf,"%s\n" , charge_type[value.intval]);else if (off ==POWER_SUPPLY_PROP_HEALTH )return sprintf (buf,"%s\n" , health_text[value.intval]);else if (off ==POWER_SUPPLY_PROP_TECHNOLOGY )
@@ -87,6 +92,7 @@ static ssize_t power_supply_show_property(struct device *dev,static struct device_attribute power_supply_attrs[] = {/* Properties of type `int' */ POWER_SUPPLY_ATTR (status), +POWER_SUPPLY_ATTR (charge_type),POWER_SUPPLY_ATTR (health),POWER_SUPPLY_ATTR (present),POWER_SUPPLY_ATTR (online),
include/linux/power_supply.h +8 -0
@@ -39,6 +39,13 @@ enum { };enum { +POWER_SUPPLY_CHARGE_TYPE_NONE =0 , +POWER_SUPPLY_CHARGE_TYPE_TRICKLE , +POWER_SUPPLY_CHARGE_TYPE_SLOW , +POWER_SUPPLY_CHARGE_TYPE_FAST , +}; + +enum {POWER_SUPPLY_HEALTH_UNKNOWN =0 ,POWER_SUPPLY_HEALTH_GOOD ,POWER_SUPPLY_HEALTH_OVERHEAT ,
@@ -70,6 +77,7 @@ enum {enum power_supply_property {/* Properties of type `int' */ POWER_SUPPLY_PROP_STATUS =0 , +POWER_SUPPLY_PROP_CHARGE_TYPE ,POWER_SUPPLY_PROP_HEALTH ,POWER_SUPPLY_PROP_PRESENT ,POWER_SUPPLY_PROP_ONLINE ,
Signature · 1 line
1.5.6.5
Quoted 6 lines · Andres Salomon
This adds a new sysfs file called '
charge_type' which displays the type of charging (n/a, trickle charge, slow charge, or fast charging). This allows things like battery diagnostics to determine what the battery/EC is doing without resorting to changing the 'status' sysfs output.Signed-off-by Andres Salomon <[email protected]>
This looks good to me. Could you please keep me on the CC for any future revisions of this patch, I can make use of this in the WM8350 driver.
drivers/power/power_supply_sysfs.c static ssize_t power_supply_show_property(struct device *dev, · line 48
Quoted 3 lines
drivers/power/power_supply_sysfs.c +3
-0+static char *charge_type[] = { +"N/A" ,"Trickle" ,"Slow" ,"Fast" + };
I'd be tempted to make "N/A" be "Unknown" to match the style of the rest of the attributes. I'm also not sure that we need a slow type, but equally it shouldn't do any harm.
Quoted 8 lines · On Tue, 30 Jun 2009 12:31:35 +0100 Mark Brown…
Quoted 5 lines · Andres Salomon
This adds a new sysfs file called '
charge_type' which displays the type of charging (n/a, trickle charge, slow charge, or fast charging). This allows things like battery diagnostics to determine what the battery/EC is doing without resorting to changing the 'status' sysfs output.
Quoted 5 lines
Quoted 1 line
Signed-off-by Andres Salomon <[email protected]>This looks good to me. Could you please keep me on the CC for any future revisions of this patch, I can make use of this in the WM8350 driver.
Sure.
Quoted 8 lines
drivers/power/power_supply_sysfs.c static ssize_t power_supply_show_property(struct device *dev, · line 48
Quoted 4 lines
drivers/power/power_supply_sysfs.c +3
-0+static char *charge_type[] = { +"N/A" ,"Trickle" ,"Slow" ,"Fast" + };I'd be tempted to make "N/A" be "Unknown" to match the style of the rest of the attributes. I'm also not sure that we need a slow type, but equally it shouldn't do any harm.
It's known though, right? :) It could just as easily be "None",
"Unknown", etc, but I'm not particularly picky. As far as the slow type, I don't see the need either, but I assumed Anton was aware of devices that differentiated between slow and trickle charging.
Quoted 29 lines · Andres Salomon
Quoted 8 lines · On Tue, 30 Jun 2009 12:31:35 +0100 Mark Brown…
Quoted 5 lines · Andres Salomon
This adds a new sysfs file called '
charge_type' which displays the type of charging (n/a, trickle charge, slow charge, or fast charging). This allows things like battery diagnostics to determine what the battery/EC is doing without resorting to changing the 'status' sysfs output.Quoted 5 lines
Quoted 1 line
Signed-off-by Andres Salomon <[email protected]>This looks good to me. Could you please keep me on the CC for any future revisions of this patch, I can make use of this in the WM8350 driver.
Sure.
Quoted 8 lines
drivers/power/power_supply_sysfs.c static ssize_t power_supply_show_property(struct device *dev, · line 48
Quoted 4 lines
drivers/power/power_supply_sysfs.c +3
-0+static char *charge_type[] = { +"N/A" ,"Trickle" ,"Slow" ,"Fast" + };I'd be tempted to make "N/A" be "Unknown" to match the style of the rest of the attributes. I'm also not sure that we need a slow type, but equally it shouldn't do any harm.
Quoted 2 lines
It's known though, right? :) It could just as easily be "None",
"Unknown", etc, but I'm not particularly picky.
These are quite different states, and thinking about it, we might want to introduce both. Default is "Unknown" (0), means that the driver can't report the charging mode at this very moment. And "N/A" is "not applicable", i.e. we're not charging anything right now.
Quoted 3 lines
As far as the slow type, I don't see the need either, but I assumed Anton was aware of devices that differentiated between slow and trickle charging.
Yep, there are two charging modes in Openmoko Neo FreeRunners:
- 100 mA. It's "slow" mode -- used when the Neo couldn't negotiate with USB host, so it is permitted to only draw 100 mA from VBUS.
- 500/1000 mA. It's so-called "fast" mode, can be enabled after successful negotiation with the USB host.
Well, this kind slow charging isn't official terminology, and I'm not sure if we should use it. But I'm fine with it since we can always remove "Slow" mode (i.e. report it as "Fast"), and userspace won't break.
Thanks,
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 10 lines · Anton Vorontsov
Quoted 3 lines · Andres Salomon
As far as the slow type, I don't see the need either, but I assumed Anton was aware of devices that differentiated between slow and trickle charging.
Yep, there are two charging modes in Openmoko Neo FreeRunners:
- 100 mA. It's "slow" mode -- used when the Neo couldn't negotiate with USB host, so it is permitted to only draw 100 mA from VBUS.
I strongly suspect you will find that the "slow" mode there is actually a trickle charge. It's a lot more practical to trickle charge in mobile phone sized systems since the batteries are so much smaller than laptop batteries.
Quoted 2 lines
- 500/1000 mA. It's so-called "fast" mode, can be enabled after successful negotiation with the USB host.
Even if the 500mA is available you'll not always be able to do a fast charge from a USB supply - some systems draw enough current to require that the USB supply be suppliemented from battery when they're being heavily used.
Quoted 4 lines
Well, this kind slow charging isn't official terminology, and I'm not sure if we should use it. But I'm fine with it since we can always remove "Slow" mode (i.e. report it as "Fast"), and userspace won't break.
I guess my main question was if it was distinguishable from trickle charging.
Quoted 9 lines · Mark Brown
Quoted 7 lines · Anton Vorontsov
Quoted 3 lines · Andres Salomon
As far as the slow type, I don't see the need either, but I assumed Anton was aware of devices that differentiated between slow and trickle charging.
Yep, there are two charging modes in Openmoko Neo FreeRunners:
Quoted 7 lines
Quoted 2 lines
- 100 mA. It's "slow" mode -- used when the Neo couldn't negotiate with USB host, so it is permitted to only draw 100 mA from VBUS.
I strongly suspect you will find that the "slow" mode there is actually a trickle charge. It's a lot more practical to trickle charge in mobile phone sized systems since the batteries are so much smaller than laptop batteries.
Could be.
Anyway, I was curious what terminology is used in specs, and so I took a look at pcf50633 spec.
"When a suitable adapter or USB supply is detected, the battery is
charged with a constant precharge current (CC mode). The constant current is selected via the prechgcur bits
...
For a Li-ion battery, the precharge current is typically 0.1C (C = charge rate = the charge current which will fully charge the battery in one hour)."
And then what is "fast" charge in pcf50633:
"Fast charging of a battery is only permitted within a certain
temperature window (typically between 0 and 50 °C).
...
If charging is via the adapter, the fast charge current is determined by the fstchgcur1 bit settings. If charging is via the USB connector, bits fstchgcur2 determine the fast charge current. For a Li-Ion battery, the fast-charge current is typically between 0.7 C and 1.0 C."
There is also precharge-wait and fastcharge-wait modes, FWIW. But we don't expose this information to the userspace.
Quoted 7 lines
Quoted 2 lines
- 500/1000 mA. It's so-called "fast" mode, can be enabled after successful negotiation with the USB host.
Even if the 500mA is available you'll not always be able to do a fast charge from a USB supply - some systems draw enough current to require that the USB supply be suppliemented from battery when they're being heavily used.
True. Though, for these cases there is an AC charger that can do 2A. ;-)
Quoted 7 lines
Quoted 4 lines
Well, this kind slow charging isn't official terminology, and I'm not sure if we should use it. But I'm fine with it since we can always remove "Slow" mode (i.e. report it as "Fast"), and userspace won't break.
I guess my main question was if it was distinguishable from trickle charging.
Probably not, Fast/Slow/Trickle are quite vague terms anyway. I'd prefer if we could measure this in some real units, but alas...
Thanks,
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 6 lines · Anton Vorontsov
Quoted 4 lines · Mark Brown
I strongly suspect you will find that the "slow" mode there is actually a trickle charge. It's a lot more practical to trickle charge in mobile phone sized systems since the batteries are so much smaller than laptop batteries.
...
Quoted 3 lines
For a Li-ion battery, the precharge current is typically 0.1C (C = charge rate = the charge current which will fully charge the battery in one hour)."
Yup, that sounds like a trickle charge all right.
Quoted 2 lines
There is also precharge-wait and fastcharge-wait modes, FWIW. But we don't expose this information to the userspace.
Those *probably* boil down to one of the other states - without looking at the datasheet they sound like waiting for the conditions required to do one of the other charges to be satisfied.
Quoted 2 lines
Probably not, Fast/Slow/Trickle are quite vague terms anyway. I'd prefer if we could measure this in some real units, but alas...
Fast and trickle charge are fairly well understood terms, I think. For specific numbers you'd need to look at the particular batteries involved, unfortunately, but they do tend to be fairly obvious when looking at a particular charger and/or battery.
Quoted 8 lines · Andres Salomon
This adds a new sysfs file called '
charge_type' which displays the type of charging (n/a, trickle charge, slow charge, or fast charging). This allows things like battery diagnostics to determine what the battery/EC is doing without resorting to changing the 'status' sysfs output.Signed-off-by Andres Salomon <[email protected]>---
The patch didn't apply cleanly (not sure why, maybe because of my "cosmetic" changes in the previous patches? hm.)
Can you please add "Unknown" state before "N/A", and per Mark's comments also remove "Slow" charge type, and resend the patch against battery-2.6.git tree?
Mark, since you seem to be interested in this addition, it would be great to see your ack/nak status on an updated patch, so we'll be sure that this is suitable for WM8350.
Thanks!
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 18 lines · On Wed, 1 Jul 2009 03:14:50 +0400 Anton Vorontsov <[email protected]>…
Quoted 9 lines · Andres Salomon
This adds a new sysfs file called '
charge_type' which displays the type of charging (n/a, trickle charge, slow charge, or fast charging). This allows things like battery diagnostics to determine what the battery/EC is doing without resorting to changing the 'status' sysfs output.Signed-off-by Andres Salomon <[email protected]>---
The patch didn't apply cleanly (not sure why, maybe because of my "cosmetic" changes in the previous patches? hm.)
Can you please add "Unknown" state before "N/A", and per Mark's comments also remove "Slow" charge type, and resend the patch against battery-2.6.git tree?
Quoted 6 lines
Mark, since you seem to be interested in this addition, it would be great to see your ack/nak status on an updated patch, so we'll be sure that this is suitable for WM8350.
Thanks!
An updated patch (against battery-2.6 master) is below.
This adds a new sysfs file called 'charge_type' which displays the type of charging (unknown, n/a, trickle charge, or fast charging). This allows things like battery diagnostics to determine what the battery/EC is doing without resorting to changing the 'status' sysfs output.
--- Documentation/power/power_supply_class.txt | 5 +++++ drivers/power/olpc_battery.c | 9 +++++++++ drivers/power/power_supply_sysfs.c | 6 ++++++ include/linux/power_supply.h | 8 ++++++++ 4 files changed, 28 insertions(+), 0 deletions(-)
Documentation/power/power_supply_class.txt +5 -0
@@ -76,6 +76,11 @@ STATUS - this attribute represents operating status (charging, full, discharging (i.e. powering a load), etc.). This corresponds to BATTERY_STATUS_* values, as defined in battery.h. +CHARGE_TYPE - batteries can typically charge at different rates. +This defines trickle and fast charges. For batteries that +are already charged or discharging, 'n/a' can be displayed (or +'unknown', if the status is not known). + HEALTH - represents health of the battery, values corresponds to POWER_SUPPLY_HEALTH_*, defined in battery.h.
drivers/power/olpc_battery.c +9 -0
@@ -233,6 +233,14 @@ static int olpc_bat_get_property(struct power_supply *psy,if (ret)return ret;break ; +case POWER_SUPPLY_PROP_CHARGE_TYPE : +if (ec_byte &BAT_STAT_TRICKLE ) + val->intval =POWER_SUPPLY_CHARGE_TYPE_TRICKLE ; +else if (ec_byte &BAT_STAT_CHARGING ) + val->intval =POWER_SUPPLY_CHARGE_TYPE_FAST ; +else + val->intval =POWER_SUPPLY_CHARGE_TYPE_NONE ; +break ;case POWER_SUPPLY_PROP_PRESENT : val->intval = !!(ec_byte & (BAT_STAT_PRESENT |BAT_STAT_TRICKLE ));
@@ -325,6 +333,7 @@ static int olpc_bat_get_property(struct power_supply *psy,static enum power_supply_property olpc_bat_props[] = {POWER_SUPPLY_PROP_STATUS , +POWER_SUPPLY_PROP_CHARGE_TYPE ,POWER_SUPPLY_PROP_PRESENT ,POWER_SUPPLY_PROP_HEALTH ,POWER_SUPPLY_PROP_TECHNOLOGY ,
drivers/power/power_supply_sysfs.c +6 -0
@@ -43,6 +43,9 @@ static ssize_t power_supply_show_property(struct device *dev,static char *status_text[] = {"Unknown" ,"Charging" ,"Discharging" ,"Not charging" ,"Full" }; +static char *charge_type[] = { +"Unknown" ,"N/A" ,"Trickle" ,"Fast" + };static char *health_text[] = {"Unknown" ,"Good" ,"Overheat" ,"Dead" ,"Over voltage" ,"Unspecified failure" ,"Cold" ,
@@ -70,6 +73,8 @@ static ssize_t power_supply_show_property(struct device *dev,if (off ==POWER_SUPPLY_PROP_STATUS )return sprintf (buf,"%s\n" , status_text[value.intval]); +else if (off ==POWER_SUPPLY_PROP_CHARGE_TYPE ) +return sprintf (buf,"%s\n" , charge_type[value.intval]);else if (off ==POWER_SUPPLY_PROP_HEALTH )return sprintf (buf,"%s\n" , health_text[value.intval]);else if (off ==POWER_SUPPLY_PROP_TECHNOLOGY )
@@ -86,6 +91,7 @@ static ssize_t power_supply_show_property(struct device *dev,static struct device_attribute power_supply_attrs[] = {/* Properties of type `int' */ POWER_SUPPLY_ATTR (status), +POWER_SUPPLY_ATTR (charge_type),POWER_SUPPLY_ATTR (health),POWER_SUPPLY_ATTR (present),POWER_SUPPLY_ATTR (online),
include/linux/power_supply.h +8 -0
@@ -39,6 +39,13 @@ enum { };enum { +POWER_SUPPLY_CHARGE_TYPE_UNKNOWN =0 , +POWER_SUPPLY_CHARGE_TYPE_NONE , +POWER_SUPPLY_CHARGE_TYPE_TRICKLE , +POWER_SUPPLY_CHARGE_TYPE_FAST , +}; + +enum {POWER_SUPPLY_HEALTH_UNKNOWN =0 ,POWER_SUPPLY_HEALTH_GOOD ,POWER_SUPPLY_HEALTH_OVERHEAT ,
@@ -70,6 +77,7 @@ enum {enum power_supply_property {/* Properties of type `int' */ POWER_SUPPLY_PROP_STATUS =0 , +POWER_SUPPLY_PROP_CHARGE_TYPE ,POWER_SUPPLY_PROP_HEALTH ,POWER_SUPPLY_PROP_PRESENT ,POWER_SUPPLY_PROP_ONLINE ,
Signature · 1 line
1.5.6.5
Mark Brown
Acked-byQuoted 6 lines · Andres Salomon
This adds a new sysfs file called '
charge_type' which displays the type of charging (unknown, n/a, trickle charge, or fast charging). This allows things like battery diagnostics to determine what the battery/EC is doing without resorting to changing the 'status' sysfs output.Signed-off-by Andres Salomon <[email protected]>
Quoted 10 lines · Mark Brown
Quoted 6 lines · Andres Salomon
This adds a new sysfs file called '
charge_type' which displays the type of charging (unknown, n/a, trickle charge, or fast charging). This allows things like battery diagnostics to determine what the battery/EC is doing without resorting to changing the 'status' sysfs output.Signed-off-by Andres Salomon <[email protected]>Acked-by Mark Brown <[email protected]>
Much thanks to both of you.
This is now applied to battery-2.6.git (for -next).
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2