gta01_battery: add charge_{now,full} properties
authorPaul Fertser <fercerpav@gmail.com>
Thu, 30 Jul 2009 20:47:41 +0000 (00:47 +0400)
committerPaul Fertser <fercerpav@gmail.com>
Sun, 2 Aug 2009 07:24:50 +0000 (11:24 +0400)
Some userspace (notably Enlightment's batget) ignores "capacity"
completely if there're no other properties. Expose a fake value
(850mAh, typical for BL-5C) to make them happy.

Signed-off-by: Paul Fertser <fercerpav@gmail.com>
drivers/power/gta01_battery.c

index 3c7c497..2078b07 100644 (file)
@@ -24,8 +24,13 @@ static enum power_supply_property gta01_bat_props[] = {
        POWER_SUPPLY_PROP_VOLTAGE_NOW,
        POWER_SUPPLY_PROP_CURRENT_NOW,
        POWER_SUPPLY_PROP_CAPACITY,
+       POWER_SUPPLY_PROP_CHARGE_FULL,
+       POWER_SUPPLY_PROP_CHARGE_NOW,
 };
 
+/* Capacity of typical BL-5C dumb battery */
+#define GTA01_BAT_CHARGE_FULL  850000
+
 static int gta01_bat_voltscale(int volt)
 {
        /* This table is suggested by SpeedEvil based on analysis of
@@ -83,6 +88,14 @@ static int gta01_bat_get_property(struct power_supply *psy,
        case POWER_SUPPLY_PROP_PRESENT:
                val->intval = 1; /* You must never run GTA01 without battery. */
                break;
+       case POWER_SUPPLY_PROP_CHARGE_NOW:
+               if (bat->pdata->get_voltage) {
+                       int perc = gta01_bat_voltscale(
+                                       bat->pdata->get_voltage()/1000);
+                       val->intval = perc * GTA01_BAT_CHARGE_FULL / 100;
+               } else
+                       val->intval = 0;
+               break;
        case POWER_SUPPLY_PROP_CAPACITY:
                if (bat->pdata->get_voltage)
                        val->intval = gta01_bat_voltscale(
@@ -90,6 +103,9 @@ static int gta01_bat_get_property(struct power_supply *psy,
                else
                        val->intval = 0;
                break;
+       case POWER_SUPPLY_PROP_CHARGE_FULL:
+               val->intval = GTA01_BAT_CHARGE_FULL;
+               break;
 
        default:
                return -EINVAL;