]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
power_supply: Add a charge_type property, and use it for olpc driver
authorAndres Salomon <dilinger@collabora.co.uk>
Thu, 2 Jul 2009 13:45:18 +0000 (09:45 -0400)
committerAnton Vorontsov <cbouatmailru@gmail.com>
Thu, 2 Jul 2009 14:14:37 +0000 (18:14 +0400)
This adds a new sysfs file called 'charge_type' which displays the
type of charging (unknown, n/a, trickle charge, or fast charging).

This allows things like battery diagnostics to determine what the
battery/EC is doing without resorting to changing the 'status' sysfs
output.

Signed-off-by: Andres Salomon <dilinger@collabora.co.uk>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
Documentation/power/power_supply_class.txt
drivers/power/olpc_battery.c
drivers/power/power_supply_sysfs.c
include/linux/power_supply.h

index 709d95571d7bfe10dd49403e05fb093f2c8c39c1..9f16c5178b662b8f9ec67f3dd7eafd6f4c89e39a 100644 (file)
@@ -76,6 +76,11 @@ STATUS - this attribute represents operating status (charging, full,
 discharging (i.e. powering a load), etc.). This corresponds to
 BATTERY_STATUS_* values, as defined in battery.h.
 
+CHARGE_TYPE - batteries can typically charge at different rates.
+This defines trickle and fast charges.  For batteries that
+are already charged or discharging, 'n/a' can be displayed (or
+'unknown', if the status is not known).
+
 HEALTH - represents health of the battery, values corresponds to
 POWER_SUPPLY_HEALTH_*, defined in battery.h.
 
index 602bbd008f7840bbeb6ce58e3009701c64bb1cc2..8fefe5a73558895f5bb0df35b865366ea02e8618 100644 (file)
@@ -233,6 +233,14 @@ static int olpc_bat_get_property(struct power_supply *psy,
                if (ret)
                        return ret;
                break;
+       case POWER_SUPPLY_PROP_CHARGE_TYPE:
+               if (ec_byte & BAT_STAT_TRICKLE)
+                       val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
+               else if (ec_byte & BAT_STAT_CHARGING)
+                       val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST;
+               else
+                       val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
+               break;
        case POWER_SUPPLY_PROP_PRESENT:
                val->intval = !!(ec_byte & (BAT_STAT_PRESENT |
                                            BAT_STAT_TRICKLE));
@@ -325,6 +333,7 @@ static int olpc_bat_get_property(struct power_supply *psy,
 
 static enum power_supply_property olpc_bat_props[] = {
        POWER_SUPPLY_PROP_STATUS,
+       POWER_SUPPLY_PROP_CHARGE_TYPE,
        POWER_SUPPLY_PROP_PRESENT,
        POWER_SUPPLY_PROP_HEALTH,
        POWER_SUPPLY_PROP_TECHNOLOGY,
index 9deabbde6fd6e82ec4b59061c7f93e96b32b4022..08144393d64b72e7b2a54d44929a6d47cbf18036 100644 (file)
@@ -43,6 +43,9 @@ static ssize_t power_supply_show_property(struct device *dev,
        static char *status_text[] = {
                "Unknown", "Charging", "Discharging", "Not charging", "Full"
        };
+       static char *charge_type[] = {
+               "Unknown", "N/A", "Trickle", "Fast"
+       };
        static char *health_text[] = {
                "Unknown", "Good", "Overheat", "Dead", "Over voltage",
                "Unspecified failure", "Cold",
@@ -70,6 +73,8 @@ static ssize_t power_supply_show_property(struct device *dev,
 
        if (off == POWER_SUPPLY_PROP_STATUS)
                return sprintf(buf, "%s\n", status_text[value.intval]);
+       else if (off == POWER_SUPPLY_PROP_CHARGE_TYPE)
+               return sprintf(buf, "%s\n", charge_type[value.intval]);
        else if (off == POWER_SUPPLY_PROP_HEALTH)
                return sprintf(buf, "%s\n", health_text[value.intval]);
        else if (off == POWER_SUPPLY_PROP_TECHNOLOGY)
@@ -86,6 +91,7 @@ static ssize_t power_supply_show_property(struct device *dev,
 static struct device_attribute power_supply_attrs[] = {
        /* Properties of type `int' */
        POWER_SUPPLY_ATTR(status),
+       POWER_SUPPLY_ATTR(charge_type),
        POWER_SUPPLY_ATTR(health),
        POWER_SUPPLY_ATTR(present),
        POWER_SUPPLY_ATTR(online),
index 0ab6aa1712417f76932c632a713e43e507a91c37..4c7c6fc35487ed5e371d0906595ee21394977934 100644 (file)
@@ -38,6 +38,13 @@ enum {
        POWER_SUPPLY_STATUS_FULL,
 };
 
+enum {
+       POWER_SUPPLY_CHARGE_TYPE_UNKNOWN = 0,
+       POWER_SUPPLY_CHARGE_TYPE_NONE,
+       POWER_SUPPLY_CHARGE_TYPE_TRICKLE,
+       POWER_SUPPLY_CHARGE_TYPE_FAST,
+};
+
 enum {
        POWER_SUPPLY_HEALTH_UNKNOWN = 0,
        POWER_SUPPLY_HEALTH_GOOD,
@@ -70,6 +77,7 @@ enum {
 enum power_supply_property {
        /* Properties of type `int' */
        POWER_SUPPLY_PROP_STATUS = 0,
+       POWER_SUPPLY_PROP_CHARGE_TYPE,
        POWER_SUPPLY_PROP_HEALTH,
        POWER_SUPPLY_PROP_PRESENT,
        POWER_SUPPLY_PROP_ONLINE,