[PATCH] battery: add CHARGE_FULL_DESIGN and CHARGE_NOW

Sascha Silbe sascha-pgp at silbe.org
Thu Apr 29 14:28:16 EDT 2010


These two are needed by UPower.
For CHARGE_NOW we violate the power supply class definition (as we already
do for CAPACITY though it isn't as obvious there), but this is the best
we can do without adding rather sophisticated algorithms to either the EC
or UPower.
---
 drivers/power/olpc_battery.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
index 753c170..7e78ac6 100644
--- a/drivers/power/olpc_battery.c
+++ b/drivers/power/olpc_battery.c
@@ -49,6 +49,9 @@
 
 #define BAT_ADDR_MFR_TYPE	0x5F
 
+#define CHARGE_FULL_DESIGN      3000000 /* 3Ah */
+
+
 /*********************************************************************
  *		Power
  *********************************************************************/
@@ -293,6 +296,15 @@ static int olpc_bat_get_property(struct power_supply *psy,
 		else
 			val->intval = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
 		break;
+	case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
+		val->intval = CHARGE_FULL_DESIGN;
+		break;
+	case POWER_SUPPLY_PROP_CHARGE_AVG:
+		ret = olpc_ec_cmd(EC_BAT_SOC, NULL, 0, &ec_byte, 1);
+		if (ret)
+			return ret;
+		val->intval = ec_byte * (CHARGE_FULL_DESIGN / 100);
+		break;
 	case POWER_SUPPLY_PROP_TEMP:
 		ret = olpc_ec_cmd(EC_BAT_TEMP, NULL, 0, (void *)&ec_word, 2);
 		if (ret)
@@ -342,6 +354,8 @@ static enum power_supply_property olpc_bat_props[] = {
 	POWER_SUPPLY_PROP_CURRENT_AVG,
 	POWER_SUPPLY_PROP_CAPACITY,
 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
+	POWER_SUPPLY_PROP_CHARGE_AVG,
+	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
 	POWER_SUPPLY_PROP_TEMP,
 #ifndef CONFIG_OLPC_XO_1_5
 	POWER_SUPPLY_PROP_TEMP_AMBIENT,
-- 
1.7.0




More information about the Devel mailing list