Re: [PATCH 1/2] olpc-battery: Add VOLTAGE_MAX_DESIGN property

2012-07-16 Thread Anton Vorontsov
On Sun, Jul 15, 2012 at 10:43:25PM +0100, Daniel Drake wrote:
> From: Richard A. Smith 
> 
> upowerd wants to compute the energy in the battery by looking at this
> property.  If it's not present then it falls back on using the reported
> voltage of the battery at time upowerd loads.  That's close but also
> means that every time you boot you get a slightly different energy
> capacity.
> 
> Adding the VOLTAGE_MAX_DESIGN property allows upowerd to compute the
> same energy every time.
> 
> Signed-off-by: Richard A. Smith 
> Signed-off-by: Daniel Drake 
> ---

Both patches applied, thank you!

[...]
> +static int olpc_bat_get_voltage_max_design(union power_supply_propval *val)
> +{
> + uint8_t ec_byte;
> + union power_supply_propval tech;
> + int ret, mfr;

ret and mfr should have been on separate lines (yes, I understand that
this comes from olpc_bat_get_charge_full_design(), but the function
is the only abuser in the file, so it would be better to fix it, not
spread it further :-)

-- 
Anton Vorontsov
Email: cbouatmai...@gmail.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] olpc-battery: Add VOLTAGE_MAX_DESIGN property

2012-07-16 Thread Anton Vorontsov
On Sun, Jul 15, 2012 at 10:43:25PM +0100, Daniel Drake wrote:
 From: Richard A. Smith rich...@laptop.org
 
 upowerd wants to compute the energy in the battery by looking at this
 property.  If it's not present then it falls back on using the reported
 voltage of the battery at time upowerd loads.  That's close but also
 means that every time you boot you get a slightly different energy
 capacity.
 
 Adding the VOLTAGE_MAX_DESIGN property allows upowerd to compute the
 same energy every time.
 
 Signed-off-by: Richard A. Smith rich...@laptop.org
 Signed-off-by: Daniel Drake d...@laptop.org
 ---

Both patches applied, thank you!

[...]
 +static int olpc_bat_get_voltage_max_design(union power_supply_propval *val)
 +{
 + uint8_t ec_byte;
 + union power_supply_propval tech;
 + int ret, mfr;

ret and mfr should have been on separate lines (yes, I understand that
this comes from olpc_bat_get_charge_full_design(), but the function
is the only abuser in the file, so it would be better to fix it, not
spread it further :-)

-- 
Anton Vorontsov
Email: cbouatmai...@gmail.com
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] olpc-battery: Add VOLTAGE_MAX_DESIGN property

2012-07-15 Thread Daniel Drake
From: Richard A. Smith 

upowerd wants to compute the energy in the battery by looking at this
property.  If it's not present then it falls back on using the reported
voltage of the battery at time upowerd loads.  That's close but also
means that every time you boot you get a slightly different energy
capacity.

Adding the VOLTAGE_MAX_DESIGN property allows upowerd to compute the
same energy every time.

Signed-off-by: Richard A. Smith 
Signed-off-by: Daniel Drake 
---
 drivers/power/olpc_battery.c |   54 ++
 1 file changed, 54 insertions(+)

diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
index 7385092..b98f531 100644
--- a/drivers/power/olpc_battery.c
+++ b/drivers/power/olpc_battery.c
@@ -267,6 +267,53 @@ static int olpc_bat_get_charge_now(union 
power_supply_propval *val)
return 0;
 }
 
+static int olpc_bat_get_voltage_max_design(union power_supply_propval *val)
+{
+   uint8_t ec_byte;
+   union power_supply_propval tech;
+   int ret, mfr;
+
+   ret = olpc_bat_get_tech();
+   if (ret)
+   return ret;
+
+   ec_byte = BAT_ADDR_MFR_TYPE;
+   ret = olpc_ec_cmd(EC_BAT_EEPROM, _byte, 1, _byte, 1);
+   if (ret)
+   return ret;
+
+   mfr = ec_byte >> 4;
+
+   switch (tech.intval) {
+   case POWER_SUPPLY_TECHNOLOGY_NiMH:
+   switch (mfr) {
+   case 1: /* Gold Peak */
+   val->intval = 600;
+   break;
+   default:
+   return -EIO;
+   }
+   break;
+
+   case POWER_SUPPLY_TECHNOLOGY_LiFe:
+   switch (mfr) {
+   case 1: /* Gold Peak */
+   val->intval = 640;
+   break;
+   case 2: /* BYD */
+   val->intval = 650;
+   break;
+   default:
+   return -EIO;
+   }
+   break;
+
+   default:
+   return -EIO;
+   }
+
+   return ret;
+}
 /*
  * Battery properties
  */
@@ -401,6 +448,11 @@ static int olpc_bat_get_property(struct power_supply *psy,
sprintf(bat_serial, "%016llx", (long long)be64_to_cpu(ser_buf));
val->strval = bat_serial;
break;
+   case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
+   ret = olpc_bat_get_voltage_max_design(val);
+   if (ret)
+   return ret;
+   break;
default:
ret = -EINVAL;
break;
@@ -428,6 +480,7 @@ static enum power_supply_property olpc_xo1_bat_props[] = {
POWER_SUPPLY_PROP_MANUFACTURER,
POWER_SUPPLY_PROP_SERIAL_NUMBER,
POWER_SUPPLY_PROP_CHARGE_COUNTER,
+   POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
 };
 
 /* XO-1.5 does not have ambient temperature property */
@@ -449,6 +502,7 @@ static enum power_supply_property olpc_xo15_bat_props[] = {
POWER_SUPPLY_PROP_MANUFACTURER,
POWER_SUPPLY_PROP_SERIAL_NUMBER,
POWER_SUPPLY_PROP_CHARGE_COUNTER,
+   POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
 };
 
 /* EEPROM reading goes completely around the power_supply API, sadly */
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] olpc-battery: Add VOLTAGE_MAX_DESIGN property

2012-07-15 Thread Daniel Drake
From: Richard A. Smith rich...@laptop.org

upowerd wants to compute the energy in the battery by looking at this
property.  If it's not present then it falls back on using the reported
voltage of the battery at time upowerd loads.  That's close but also
means that every time you boot you get a slightly different energy
capacity.

Adding the VOLTAGE_MAX_DESIGN property allows upowerd to compute the
same energy every time.

Signed-off-by: Richard A. Smith rich...@laptop.org
Signed-off-by: Daniel Drake d...@laptop.org
---
 drivers/power/olpc_battery.c |   54 ++
 1 file changed, 54 insertions(+)

diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
index 7385092..b98f531 100644
--- a/drivers/power/olpc_battery.c
+++ b/drivers/power/olpc_battery.c
@@ -267,6 +267,53 @@ static int olpc_bat_get_charge_now(union 
power_supply_propval *val)
return 0;
 }
 
+static int olpc_bat_get_voltage_max_design(union power_supply_propval *val)
+{
+   uint8_t ec_byte;
+   union power_supply_propval tech;
+   int ret, mfr;
+
+   ret = olpc_bat_get_tech(tech);
+   if (ret)
+   return ret;
+
+   ec_byte = BAT_ADDR_MFR_TYPE;
+   ret = olpc_ec_cmd(EC_BAT_EEPROM, ec_byte, 1, ec_byte, 1);
+   if (ret)
+   return ret;
+
+   mfr = ec_byte  4;
+
+   switch (tech.intval) {
+   case POWER_SUPPLY_TECHNOLOGY_NiMH:
+   switch (mfr) {
+   case 1: /* Gold Peak */
+   val-intval = 600;
+   break;
+   default:
+   return -EIO;
+   }
+   break;
+
+   case POWER_SUPPLY_TECHNOLOGY_LiFe:
+   switch (mfr) {
+   case 1: /* Gold Peak */
+   val-intval = 640;
+   break;
+   case 2: /* BYD */
+   val-intval = 650;
+   break;
+   default:
+   return -EIO;
+   }
+   break;
+
+   default:
+   return -EIO;
+   }
+
+   return ret;
+}
 /*
  * Battery properties
  */
@@ -401,6 +448,11 @@ static int olpc_bat_get_property(struct power_supply *psy,
sprintf(bat_serial, %016llx, (long long)be64_to_cpu(ser_buf));
val-strval = bat_serial;
break;
+   case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
+   ret = olpc_bat_get_voltage_max_design(val);
+   if (ret)
+   return ret;
+   break;
default:
ret = -EINVAL;
break;
@@ -428,6 +480,7 @@ static enum power_supply_property olpc_xo1_bat_props[] = {
POWER_SUPPLY_PROP_MANUFACTURER,
POWER_SUPPLY_PROP_SERIAL_NUMBER,
POWER_SUPPLY_PROP_CHARGE_COUNTER,
+   POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
 };
 
 /* XO-1.5 does not have ambient temperature property */
@@ -449,6 +502,7 @@ static enum power_supply_property olpc_xo15_bat_props[] = {
POWER_SUPPLY_PROP_MANUFACTURER,
POWER_SUPPLY_PROP_SERIAL_NUMBER,
POWER_SUPPLY_PROP_CHARGE_COUNTER,
+   POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
 };
 
 /* EEPROM reading goes completely around the power_supply API, sadly */
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/