bq27x00: Return -ENODEV for properties if the battery is not present
authorLars-Peter Clausen <lars@metafoo.de>
Mon, 24 May 2010 19:57:33 +0000 (21:57 +0200)
committerLars-Peter Clausen <lars@metafoo.de>
Tue, 22 Feb 2011 10:02:40 +0000 (11:02 +0100)
This patch changes get_property callback of the bq27x00 battery to return
-ENODEV for properties other then the PROP_PRESENT if the battery is not
present.
The power subsystem core expects a driver to behave that way.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Rodolfo Giometti <giometti@linux.it>
Tested-by: Grazvydas Ignotas <notasas@gmail.com>
drivers/power/bq27x00_battery.c

index 1b06134e0ae883b88852af2719da59996024e39b..9f16666dc4668cb16a79e2738991fac3d943df79 100644 (file)
@@ -252,16 +252,21 @@ static int bq27x00_battery_get_property(struct power_supply *psy,
 {
        int ret = 0;
        struct bq27x00_device_info *di = to_bq27x00_device_info(psy);
+       int voltage = bq27x00_battery_voltage(di);
+
+       if (psp != POWER_SUPPLY_PROP_PRESENT && voltage <= 0)
+               return -ENODEV;
 
        switch (psp) {
        case POWER_SUPPLY_PROP_STATUS:
                ret = bq27x00_battery_status(di, val);
                break;
        case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+               val->intval = voltage;
+               break;
        case POWER_SUPPLY_PROP_PRESENT:
-               val->intval = bq27x00_battery_voltage(di);
                if (psp == POWER_SUPPLY_PROP_PRESENT)
-                       val->intval = val->intval <= 0 ? 0 : 1;
+                       val->intval = voltage <= 0 ? 0 : 1;
                break;
        case POWER_SUPPLY_PROP_CURRENT_NOW:
                val->intval = bq27x00_battery_current(di);