From 715aaf72d40a5a68cca29a4a4e3dd242ee4fb38c Mon Sep 17 00:00:00 2001 From: Alex Hornung Date: Mon, 28 Jan 2013 18:47:48 +0000 Subject: [PATCH 1/1] power: bq27541_battery - Provide energy measurement * Since the fuel gauge chip provides energy estimates, expose those as well. Signed-off-by: Alex Hornung --- drivers/power/bq27541_battery.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/power/bq27541_battery.c b/drivers/power/bq27541_battery.c index 9ce5c2d..c433043 100755 --- a/drivers/power/bq27541_battery.c +++ b/drivers/power/bq27541_battery.c @@ -111,6 +111,7 @@ enum { REG_CAPACITY, REG_SERIAL_NUMBER, REG_CHARGE_NOW, + REG_ENERGY, REG_POWER, REG_CYCLE, @@ -142,6 +143,7 @@ static struct bq27541_device_data { [REG_CAPACITY] = BQ27541_DATA(CAPACITY, 0x2c, 0, 100), [REG_CHARGE_NOW] = BQ27541_DATA(CHARGE_NOW, 0x10, 0, 65535), + [REG_ENERGY] = BQ27541_DATA(ENERGY_NOW, 0x22, 0, 65535), [REG_POWER] = BQ27541_DATA(POWER_AVG, 0x24, 0, 65535), [REG_CYCLE] = BQ27541_DATA(CYCLE_COUNT, 0x2a, 0, 65535), @@ -156,6 +158,7 @@ static enum power_supply_property bq27541_properties[] = { POWER_SUPPLY_PROP_CAPACITY, POWER_SUPPLY_PROP_TEMP, POWER_SUPPLY_PROP_CHARGE_NOW, + POWER_SUPPLY_PROP_ENERGY_NOW, POWER_SUPPLY_PROP_CYCLE_COUNT }; @@ -505,6 +508,11 @@ static int bq27541_get_psp(int reg_offset, enum power_supply_property psp, val->intval = rt_value * 1000; BAT_NOTICE("charge_now = %u uA\n", val->intval); } + if (psp == POWER_SUPPLY_PROP_ENERGY_NOW) { + /* energy is reported in 10 mWh */ + val->intval = rt_value * 10000; + BAT_NOTICE("energy_now = %u uWh\n", val->intval); + } if (psp == POWER_SUPPLY_PROP_CYCLE_COUNT) { val->intval = rt_value; BAT_NOTICE("cycle count = %u\n", val->intval); @@ -714,6 +722,7 @@ static int bq27541_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_TEMP: case POWER_SUPPLY_PROP_SERIAL_NUMBER: case POWER_SUPPLY_PROP_CHARGE_NOW: + case POWER_SUPPLY_PROP_ENERGY_NOW: case POWER_SUPPLY_PROP_CYCLE_COUNT: for (count = 0; count < REG_MAX; count++) { if (psp == bq27541_data[count].psp) -- 1.7.10.4