power_supply: Support serial number and ACR in olpc_battery
PATCH 1/4 power_supply: Support serial number and ACR in olpc_battery
From: David Woodhouse <[email protected]>
This adds serial number and accumulated current support to the OLPC battery driver.
--- drivers/power/olpc_battery.c | 23 ++++++++++++++++++++++- drivers/power/power_supply_sysfs.c | 1 + include/linux/power_supply.h | 1 + 3 files changed, 24 insertions(+), 1 deletions(-)
drivers/power/olpc_battery.c +22 -1
@@ -19,7 +19,7 @@#define EC_BAT_VOLTAGE 0x10/* uint16_t, *9.76/32, mV */ #define EC_BAT_CURRENT 0x11/* int16_t, *15.625/120, mA */ -#define EC_BAT_ACR 0x12 +#define EC_BAT_ACR 0x12/* int16_t, *416.667, µAh */ #define EC_BAT_TEMP 0x13/* uint16_t, *100/256, °C */ #define EC_AMB_TEMP 0x14/* uint16_t, *100/256, °C */ #define EC_BAT_STATUS 0x15/* uint8_t, bitmask */
@@ -84,6 +84,8 @@ static struct power_supply olpc_ac = { .get_property = olpc_ac_get_prop, }; +static char bat_serial[17 ];/* Ick */ +/********************************************************************* * Battery properties *********************************************************************/
@@ -94,6 +96,7 @@ static int olpc_bat_get_property(struct power_supply *psy,int ret =0 ;int16_t ec_word;uint8_t ec_byte; +uint64_t ser_buf; ret =olpc_ec_cmd (EC_BAT_STATUS ,NULL ,0 , &ec_byte,1 );if (ret)
@@ -241,6 +244,22 @@ static int olpc_bat_get_property(struct power_supply *psy, ec_word =be16_to_cpu (ec_word); val->intval = ec_word *100 /256 ;break ; +case POWER_SUPPLY_PROP_ACCUM_CURRENT : + ret =olpc_ec_cmd (EC_BAT_ACR ,NULL ,0 , (void *)&ec_word,2 ); +if (ret) +return ret; + + ec_word =be16_to_cpu (ec_word); + val->intval = ec_word; +break ; +case POWER_SUPPLY_PROP_SERIAL_NUMBER : + ret =olpc_ec_cmd (EC_BAT_SERIAL ,NULL ,0 , (void *)&ser_buf,8 ); +if (ret) +return ret; + +sprintf (bat_serial,"%016llx" , (long long )be64_to_cpu (ser_buf)); + val->strval = bat_serial; +break ;default : ret = -EINVAL ;break ;
@@ -259,7 +278,9 @@ static enum power_supply_property olpc_bat_props[] = {POWER_SUPPLY_PROP_CAPACITY ,POWER_SUPPLY_PROP_TEMP ,POWER_SUPPLY_PROP_TEMP_AMBIENT , +POWER_SUPPLY_PROP_ACCUM_CURRENT ,POWER_SUPPLY_PROP_MANUFACTURER , + POWER_SUPPLY_PROP_SERIAL_NUMBER, };/*********************************************************************
drivers/power/power_supply_sysfs.c +1 -0
@@ -112,6 +112,7 @@ static struct device_attribute power_supply_attrs[] = {POWER_SUPPLY_ATTR (time_to_empty_avg),POWER_SUPPLY_ATTR (time_to_full_now),POWER_SUPPLY_ATTR (time_to_full_avg), +POWER_SUPPLY_ATTR (accum_current),/* Properties of type `const char *' */ POWER_SUPPLY_ATTR (model_name), POWER_SUPPLY_ATTR(manufacturer),
include/linux/power_supply.h +1 -0
@@ -91,6 +91,7 @@ enum power_supply_property {POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG ,POWER_SUPPLY_PROP_TIME_TO_FULL_NOW ,POWER_SUPPLY_PROP_TIME_TO_FULL_AVG , +POWER_SUPPLY_PROP_ACCUM_CURRENT ,/* Properties of type `const char *' */ POWER_SUPPLY_PROP_MODEL_NAME , POWER_SUPPLY_PROP_MANUFACTURER,
Signature · 1 line
1.5.5
Quoted 44 lines · On Wed, 30 Apr 2008 16:30:02 -0400 Andres Salomon <[email protected]> wrote:
From: David Woodhouse <[email protected]>
This adds serial number and accumulated current support to the OLPC battery driver.
Signed-off-by David Woodhouse <[email protected]>Signed-off-by Andres Salomon <[email protected]>--- drivers/power/olpc_battery.c | 23 ++++++++++++++++++++++- drivers/power/power_supply_sysfs.c | 1 + include/linux/power_supply.h | 1 + 3 files changed, 24 insertions(+), 1 deletions(-)drivers/power/olpc_battery.c +4
-1@@ -19,7 +19,7 @@#define EC_BAT_VOLTAGE 0x10/* uint16_t, *9.76/32, mV */ #define EC_BAT_CURRENT 0x11/* int16_t, *15.625/120, mA */ -#define EC_BAT_ACR 0x12 +#define EC_BAT_ACR 0x12/* int16_t, *416.667, __Ah */ #define EC_BAT_TEMP 0x13/* uint16_t, *100/256, __C */ #define EC_AMB_TEMP 0x14/* uint16_t, *100/256, __C */ #define EC_BAT_STATUS 0x15/* uint8_t, bitmask */ @@ -84,6 +84,8 @@ static struct power_supply olpc_ac = { .get_property = olpc_ac_get_prop, }; +static char bat_serial[17 ];/* Ick */ +/********************************************************************* * Battery properties *********************************************************************/ @@ -94,6 +96,7 @@ static int olpc_bat_get_property(struct power_supply *psy,int ret =0 ;int16_t ec_word;uint8_t ec_byte; +uint64_t ser_buf; ret =olpc_ec_cmd (EC_BAT_STATUS ,NULL ,0 , &ec_byte,1 );if (ret)
drivers/power/olpc_battery.c static int olpc_bat_get_property(struct power_supply *psy, · line 253
Quoted 10 lines
drivers/power/olpc_battery.c +7
-0@@ -241,6 +244,22 @@ static int olpc_bat_get_property(struct power_supply *psy, ec_word =be16_to_cpu (ec_word); val->intval = ec_word *100 /256 ;break ; +case POWER_SUPPLY_PROP_ACCUM_CURRENT : + ret =olpc_ec_cmd (EC_BAT_ACR ,NULL ,0 , (void *)&ec_word,2 ); +if (ret) +return ret; + + ec_word =be16_to_cpu (ec_word); + val->intval = ec_word;
It would be cleaner to give ec_word the __be16 type and do
val->intval = be16_to_cpu(ec_word);
However I suspect that if that conversion were done fully, things would get rather involved.
It's a shame that we didn't design the endianness suypport in a way which the compiler could enforce - gcc's handling of small structs is (or was) suboptimal. sparse should do it for us, but few run it, I expect.
Quoted 4 lines · Andres Salomon
From: David Woodhouse <[email protected]>
This adds serial number and accumulated current support to the OLPC battery driver.
How PROP_ACCUM_CURRENT is different from PROP_CHARGE_NOW (uAh)?
The DS2760 is already using the later to report its ACR register...
Quoted 98 lines
Signed-off-by David Woodhouse <[email protected]>Signed-off-by Andres Salomon <[email protected]>--- drivers/power/olpc_battery.c | 23 ++++++++++++++++++++++- drivers/power/power_supply_sysfs.c | 1 + include/linux/power_supply.h | 1 + 3 files changed, 24 insertions(+), 1 deletions(-)drivers/power/olpc_battery.c +22
-1@@ -19,7 +19,7 @@#define EC_BAT_VOLTAGE 0x10/* uint16_t, *9.76/32, mV */ #define EC_BAT_CURRENT 0x11/* int16_t, *15.625/120, mA */ -#define EC_BAT_ACR 0x12 +#define EC_BAT_ACR 0x12/* int16_t, *416.667, µAh */ #define EC_BAT_TEMP 0x13/* uint16_t, *100/256, °C */ #define EC_AMB_TEMP 0x14/* uint16_t, *100/256, °C */ #define EC_BAT_STATUS 0x15/* uint8_t, bitmask */ @@ -84,6 +84,8 @@ static struct power_supply olpc_ac = { .get_property = olpc_ac_get_prop, }; +static char bat_serial[17 ];/* Ick */ +/********************************************************************* * Battery properties *********************************************************************/ @@ -94,6 +96,7 @@ static int olpc_bat_get_property(struct power_supply *psy,int ret =0 ;int16_t ec_word;uint8_t ec_byte; +uint64_t ser_buf; ret =olpc_ec_cmd (EC_BAT_STATUS ,NULL ,0 , &ec_byte,1 );if (ret)@@ -241,6 +244,22 @@ static int olpc_bat_get_property(struct power_supply *psy, ec_word =be16_to_cpu (ec_word); val->intval = ec_word *100 /256 ;break ; +case POWER_SUPPLY_PROP_ACCUM_CURRENT : + ret =olpc_ec_cmd (EC_BAT_ACR ,NULL ,0 , (void *)&ec_word,2 ); +if (ret) +return ret; + + ec_word =be16_to_cpu (ec_word); + val->intval = ec_word; +break ; +case POWER_SUPPLY_PROP_SERIAL_NUMBER : + ret =olpc_ec_cmd (EC_BAT_SERIAL ,NULL ,0 , (void *)&ser_buf,8 ); +if (ret) +return ret; + +sprintf (bat_serial,"%016llx" , (long long )be64_to_cpu (ser_buf)); + val->strval = bat_serial; +break ;default : ret = -EINVAL ;break ;@@ -259,7 +278,9 @@ static enum power_supply_property olpc_bat_props[] = {POWER_SUPPLY_PROP_CAPACITY ,POWER_SUPPLY_PROP_TEMP ,POWER_SUPPLY_PROP_TEMP_AMBIENT , +POWER_SUPPLY_PROP_ACCUM_CURRENT ,POWER_SUPPLY_PROP_MANUFACTURER , + POWER_SUPPLY_PROP_SERIAL_NUMBER, };/********************************************************************* drivers/power/power_supply_sysfs.c +1
-0@@ -112,6 +112,7 @@ static struct device_attribute power_supply_attrs[] = {POWER_SUPPLY_ATTR (time_to_empty_avg),POWER_SUPPLY_ATTR (time_to_full_now),POWER_SUPPLY_ATTR (time_to_full_avg), +POWER_SUPPLY_ATTR (accum_current),/* Properties of type `const char *' */ POWER_SUPPLY_ATTR (model_name), POWER_SUPPLY_ATTR(manufacturer),include/linux/power_supply.h +1
-0@@ -91,6 +91,7 @@ enum power_supply_property {POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG ,POWER_SUPPLY_PROP_TIME_TO_FULL_NOW ,POWER_SUPPLY_PROP_TIME_TO_FULL_AVG , +POWER_SUPPLY_PROP_ACCUM_CURRENT ,/* Properties of type `const char *' */ POWER_SUPPLY_PROP_MODEL_NAME , POWER_SUPPLY_PROP_MANUFACTURER,Signature · 1 line
1.5.5
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 10 lines · On Sat, 3 May 2008 02:58:49 +0400 Anton Vorontsov <[email protected]>…
Quoted 4 lines · Andres Salomon
From: David Woodhouse <[email protected]>
This adds serial number and accumulated current support to the OLPC battery driver.
How
PROP_ACCUM_CURRENTis different fromPROP_CHARGE_NOW(uAh)?The DS2760 is already using the later to report its ACR register...
Hm, I can change that. In the meantime, I've stripped out the ACR stuff. Can you please use the following patch instead? The change doesn't conflict with the other 3 patches.
From: David Woodhouse <[email protected]>
power_supply: Support serial number in olpc_battery
This adds serial number support to the OLPC
battery driver.
--- drivers/power/olpc_battery.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
drivers/power/olpc_battery.c +12 -0
@@ -84,6 +84,8 @@ static struct power_supply olpc_ac = { .get_property = olpc_ac_get_prop, }; +static char bat_serial[17 ];/* Ick */ +/********************************************************************* * Battery properties *********************************************************************/
@@ -94,6 +96,7 @@ static int olpc_bat_get_property(struct power_supply *psy,int ret =0 ;int16_t ec_word;uint8_t ec_byte; +uint64_t ser_buf; ret =olpc_ec_cmd (EC_BAT_STATUS ,NULL ,0 , &ec_byte,1 );if (ret)
@@ -241,6 +244,14 @@ static int olpc_bat_get_property(struct power_supply *psy, ec_word =be16_to_cpu (ec_word); val->intval = ec_word *100 /256 ;break ; +case POWER_SUPPLY_PROP_SERIAL_NUMBER : + ret =olpc_ec_cmd (EC_BAT_SERIAL ,NULL ,0 , (void *)&ser_buf,8 ); +if (ret) +return ret; + +sprintf (bat_serial,"%016llx" , (long long )be64_to_cpu (ser_buf)); + val->strval = bat_serial; +break ;default : ret = -EINVAL ;break ;
@@ -260,6 +271,7 @@ static enum power_supply_property olpc_bat_props[] = {POWER_SUPPLY_PROP_TEMP ,POWER_SUPPLY_PROP_TEMP_AMBIENT ,POWER_SUPPLY_PROP_MANUFACTURER , + POWER_SUPPLY_PROP_SERIAL_NUMBER, };/*********************************************************************
Signature · 1 line
1.5.5.1
Anton Vorontsov
AppliedQuoted 9 lines · Andres Salomon
Quoted 6 lines · On Sat, 3 May 2008 02:58:49 +0400 Anton Vorontsov <[email protected]>…
Quoted 4 lines · Andres Salomon
From: David Woodhouse <[email protected]>
This adds serial number and accumulated current support to the OLPC battery driver.
Quoted 8 lines
Quoted 4 lines
How
PROP_ACCUM_CURRENTis different fromPROP_CHARGE_NOW(uAh)?The DS2760 is already using the later to report its ACR register...
Hm, I can change that. In the meantime, I've stripped out the ACR stuff. Can you please use the following patch instead? The change doesn't conflict with the other 3 patches.
Thanks, applied to battery-2.6.git. Please see if everything is okay.
Do you want to see these patches in 2.6.26? I think it's a bit late (-rc1 is already released), but I also believe these patches are quite useful for OLPC and actually they do not touch anything but single driver...
Thanks,
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 16 lines · On Sun, 4 May 2008 13:36:27 +0400 Anton Vorontsov <[email protected]>…
Quoted 15 lines · Andres Salomon
Quoted 11 lines · On Sat, 3 May 2008 02:58:49 +0400 Anton Vorontsov <[email protected]>…
Quoted 4 lines · Andres Salomon
From: David Woodhouse <[email protected]>
This adds serial number and accumulated current support to the OLPC battery driver.
How
PROP_ACCUM_CURRENTis different fromPROP_CHARGE_NOW(uAh)?The DS2760 is already using the later to report its ACR register...
Quoted 6 lines
Quoted 3 lines
Hm, I can change that. In the meantime, I've stripped out the ACR stuff. Can you please use the following patch instead? The change doesn't conflict with the other 3 patches.
Thanks, applied to battery-2.6.git. Please see if everything is okay.
Thanks!
Quoted 5 lines
Do you want to see these patches in 2.6.26? I think it's a bit late (-rc1 is already released), but I also believe these patches are quite useful for OLPC and actually they do not touch anything but single driver...
While I certainly wouldn't complain if they found their way into 2.6.26, it's not that urgent (after all, I've been sitting on them since Feb).