Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[pandora-kernel.git] / drivers / power / olpc_battery.c
index 58e4192..baefcf1 100644 (file)
@@ -10,7 +10,9 @@
 
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/types.h>
 #include <linux/err.h>
+#include <linux/device.h>
 #include <linux/platform_device.h>
 #include <linux/power_supply.h>
 #include <linux/jiffies.h>
@@ -231,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));
@@ -276,6 +286,14 @@ static int olpc_bat_get_property(struct power_supply *psy,
                        return ret;
                val->intval = ec_byte;
                break;
+       case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
+               if (ec_byte & BAT_STAT_FULL)
+                       val->intval = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
+               else if (ec_byte & BAT_STAT_LOW)
+                       val->intval = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
+               else
+                       val->intval = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
+               break;
        case POWER_SUPPLY_PROP_TEMP:
                ret = olpc_ec_cmd(EC_BAT_TEMP, NULL, 0, (void *)&ec_word, 2);
                if (ret)
@@ -315,12 +333,14 @@ 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,
        POWER_SUPPLY_PROP_VOLTAGE_AVG,
        POWER_SUPPLY_PROP_CURRENT_AVG,
        POWER_SUPPLY_PROP_CAPACITY,
+       POWER_SUPPLY_PROP_CAPACITY_LEVEL,
        POWER_SUPPLY_PROP_TEMP,
        POWER_SUPPLY_PROP_TEMP_AMBIENT,
        POWER_SUPPLY_PROP_MANUFACTURER,
@@ -334,7 +354,7 @@ static enum power_supply_property olpc_bat_props[] = {
 #define EEPROM_END     0x80
 #define EEPROM_SIZE    (EEPROM_END - EEPROM_START)
 
-static ssize_t olpc_bat_eeprom_read(struct kobject *kobj,
+static ssize_t olpc_bat_eeprom_read(struct file *filp, struct kobject *kobj,
                struct bin_attribute *attr, char *buf, loff_t off, size_t count)
 {
        uint8_t ec_byte;
@@ -370,6 +390,29 @@ static struct bin_attribute olpc_bat_eeprom = {
        .read = olpc_bat_eeprom_read,
 };
 
+/* Allow userspace to see the specific error value pulled from the EC */
+
+static ssize_t olpc_bat_error_read(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       uint8_t ec_byte;
+       ssize_t ret;
+
+       ret = olpc_ec_cmd(EC_BAT_ERRCODE, NULL, 0, &ec_byte, 1);
+       if (ret < 0)
+               return ret;
+
+       return sprintf(buf, "%d\n", ec_byte);
+}
+
+static struct device_attribute olpc_bat_error = {
+       .attr = {
+               .name = "error",
+               .mode = S_IRUGO,
+       },
+       .show = olpc_bat_error_read,
+};
+
 /*********************************************************************
  *             Initialisation
  *********************************************************************/
@@ -433,8 +476,14 @@ static int __init olpc_bat_init(void)
        if (ret)
                goto eeprom_failed;
 
+       ret = device_create_file(olpc_bat.dev, &olpc_bat_error);
+       if (ret)
+               goto error_failed;
+
        goto success;
 
+error_failed:
+       device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom);
 eeprom_failed:
        power_supply_unregister(&olpc_bat);
 battery_failed:
@@ -447,6 +496,7 @@ success:
 
 static void __exit olpc_bat_exit(void)
 {
+       device_remove_file(olpc_bat.dev, &olpc_bat_error);
        device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom);
        power_supply_unregister(&olpc_bat);
        power_supply_unregister(&olpc_ac);