* [PATCH 1/4] power_supply: Support serial number and ACR in olpc_battery
@ 2008-04-30 20:30 Andres Salomon
2008-04-30 21:48 ` Andrew Morton
2008-05-02 22:58 ` Anton Vorontsov
0 siblings, 2 replies; 6+ messages in thread
From: Andres Salomon @ 2008-04-30 20:30 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, cbou, dwmw2
From: David Woodhouse <dwmw2@infradead.org>
This adds serial number and accumulated current support to the OLPC
battery driver.
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Andres Salomon <dilinger@debian.org>
---
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(-)
diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
index ab1e828..9d9dd09 100644
--- a/drivers/power/olpc_battery.c
+++ b/drivers/power/olpc_battery.c
@@ -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,
};
/*********************************************************************
diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
index c444d6b..756d4e1 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -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),
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 68ed19c..a699ad2 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -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,
--
1.5.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/4] power_supply: Support serial number and ACR in olpc_battery
2008-04-30 20:30 [PATCH 1/4] power_supply: Support serial number and ACR in olpc_battery Andres Salomon
@ 2008-04-30 21:48 ` Andrew Morton
2008-05-02 22:58 ` Anton Vorontsov
1 sibling, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2008-04-30 21:48 UTC (permalink / raw)
To: Andres Salomon; +Cc: linux-kernel, cbou, dwmw2
On Wed, 30 Apr 2008 16:30:02 -0400
Andres Salomon <dilinger@queued.net> wrote:
> From: David Woodhouse <dwmw2@infradead.org>
>
> This adds serial number and accumulated current support to the OLPC
> battery driver.
>
> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
> Signed-off-by: Andres Salomon <dilinger@debian.org>
> ---
> 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(-)
>
> diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
> index ab1e828..9d9dd09 100644
> --- a/drivers/power/olpc_battery.c
> +++ b/drivers/power/olpc_battery.c
> @@ -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;
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/4] power_supply: Support serial number and ACR in olpc_battery
2008-04-30 20:30 [PATCH 1/4] power_supply: Support serial number and ACR in olpc_battery Andres Salomon
2008-04-30 21:48 ` Andrew Morton
@ 2008-05-02 22:58 ` Anton Vorontsov
2008-05-04 5:31 ` Andres Salomon
1 sibling, 1 reply; 6+ messages in thread
From: Anton Vorontsov @ 2008-05-02 22:58 UTC (permalink / raw)
To: Andres Salomon; +Cc: Andrew Morton, linux-kernel, cbou, dwmw2
On Wed, Apr 30, 2008 at 04:30:02PM -0400, Andres Salomon wrote:
> From: David Woodhouse <dwmw2@infradead.org>
>
> 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...
> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
> Signed-off-by: Andres Salomon <dilinger@debian.org>
> ---
> 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(-)
>
> diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
> index ab1e828..9d9dd09 100644
> --- a/drivers/power/olpc_battery.c
> +++ b/drivers/power/olpc_battery.c
> @@ -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,
> };
>
> /*********************************************************************
> diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
> index c444d6b..756d4e1 100644
> --- a/drivers/power/power_supply_sysfs.c
> +++ b/drivers/power/power_supply_sysfs.c
> @@ -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),
> diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
> index 68ed19c..a699ad2 100644
> --- a/include/linux/power_supply.h
> +++ b/include/linux/power_supply.h
> @@ -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,
> --
> 1.5.5
>
--
Anton Vorontsov
email: cbouatmailru@gmail.com
irc://irc.freenode.net/bd2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/4] power_supply: Support serial number and ACR in olpc_battery
2008-05-02 22:58 ` Anton Vorontsov
@ 2008-05-04 5:31 ` Andres Salomon
2008-05-04 9:36 ` Anton Vorontsov
0 siblings, 1 reply; 6+ messages in thread
From: Andres Salomon @ 2008-05-04 5:31 UTC (permalink / raw)
To: cbouatmailru; +Cc: Andrew Morton, linux-kernel, cbou, dwmw2
On Sat, 3 May 2008 02:58:49 +0400
Anton Vorontsov <cbouatmailru@gmail.com> wrote:
> On Wed, Apr 30, 2008 at 04:30:02PM -0400, Andres Salomon wrote:
> > From: David Woodhouse <dwmw2@infradead.org>
> >
> > 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...
>
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 <dwmw2@infradead.org>
power_supply: Support serial number in olpc_battery
This adds serial number support to the OLPC
battery driver.
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Andres Salomon <dilinger@debian.org>
---
drivers/power/olpc_battery.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
index ab1e828..7524a63 100644
--- a/drivers/power/olpc_battery.c
+++ b/drivers/power/olpc_battery.c
@@ -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,
};
/*********************************************************************
--
1.5.5.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/4] power_supply: Support serial number and ACR in olpc_battery
2008-05-04 5:31 ` Andres Salomon
@ 2008-05-04 9:36 ` Anton Vorontsov
2008-05-04 13:55 ` Andres Salomon
0 siblings, 1 reply; 6+ messages in thread
From: Anton Vorontsov @ 2008-05-04 9:36 UTC (permalink / raw)
To: Andres Salomon; +Cc: Andrew Morton, linux-kernel, cbou, dwmw2
On Sun, May 04, 2008 at 01:31:42AM -0400, Andres Salomon wrote:
> On Sat, 3 May 2008 02:58:49 +0400
> Anton Vorontsov <cbouatmailru@gmail.com> wrote:
>
> > On Wed, Apr 30, 2008 at 04:30:02PM -0400, Andres Salomon wrote:
> > > From: David Woodhouse <dwmw2@infradead.org>
> > >
> > > 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...
> >
>
> 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,
--
Anton Vorontsov
email: cbouatmailru@gmail.com
irc://irc.freenode.net/bd2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/4] power_supply: Support serial number and ACR in olpc_battery
2008-05-04 9:36 ` Anton Vorontsov
@ 2008-05-04 13:55 ` Andres Salomon
0 siblings, 0 replies; 6+ messages in thread
From: Andres Salomon @ 2008-05-04 13:55 UTC (permalink / raw)
To: cbouatmailru; +Cc: Andrew Morton, linux-kernel, cbou, dwmw2
On Sun, 4 May 2008 13:36:27 +0400
Anton Vorontsov <cbouatmailru@gmail.com> wrote:
> On Sun, May 04, 2008 at 01:31:42AM -0400, Andres Salomon wrote:
> > On Sat, 3 May 2008 02:58:49 +0400
> > Anton Vorontsov <cbouatmailru@gmail.com> wrote:
> >
> > > On Wed, Apr 30, 2008 at 04:30:02PM -0400, Andres Salomon wrote:
> > > > From: David Woodhouse <dwmw2@infradead.org>
> > > >
> > > > 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...
> > >
> >
> > 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!
> 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).
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-05-04 13:51 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-30 20:30 [PATCH 1/4] power_supply: Support serial number and ACR in olpc_battery Andres Salomon
2008-04-30 21:48 ` Andrew Morton
2008-05-02 22:58 ` Anton Vorontsov
2008-05-04 5:31 ` Andres Salomon
2008-05-04 9:36 ` Anton Vorontsov
2008-05-04 13:55 ` Andres Salomon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox