ds2760_battery: add rated_capacity module parameter
[linux-2.6.git] / drivers / power / ds2760_battery.c
index cf07c43..ed0ea5e 100644 (file)
@@ -66,6 +66,10 @@ static unsigned int pmod_enabled;
 module_param(pmod_enabled, bool, 0644);
 MODULE_PARM_DESC(pmod_enabled, "PMOD enable bit");
 
+static unsigned int rated_capacity;
+module_param(rated_capacity, uint, 0644);
+MODULE_PARM_DESC(rated_capacity, "rated battery capacity, 10*mAh or index");
+
 /* Some batteries have their rated capacity stored a N * 10 mAh, while
  * others use an index into this table. */
 static int rated_capacities[] = {
@@ -274,6 +278,17 @@ static void ds2760_battery_write_status(struct ds2760_device_info *di,
        w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
 }
 
+static void ds2760_battery_write_rated_capacity(struct ds2760_device_info *di,
+                                               unsigned char rated_capacity)
+{
+       if (rated_capacity == di->raw[DS2760_RATED_CAPACITY])
+               return;
+
+       w1_ds2760_write(di->w1_dev, &rated_capacity, DS2760_RATED_CAPACITY, 1);
+       w1_ds2760_store_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
+       w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
+}
+
 static void ds2760_battery_work(struct work_struct *work)
 {
        struct ds2760_device_info *di = container_of(work,
@@ -337,6 +352,12 @@ static int ds2760_battery_get_property(struct power_supply *psy,
        case POWER_SUPPLY_PROP_TEMP:
                val->intval = di->temp_C;
                break;
+       case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
+               val->intval = di->life_sec;
+               break;
+       case POWER_SUPPLY_PROP_CAPACITY:
+               val->intval = di->rem_capacity;
+               break;
        default:
                return -EINVAL;
        }
@@ -353,6 +374,8 @@ static enum power_supply_property ds2760_battery_props[] = {
        POWER_SUPPLY_PROP_CHARGE_EMPTY,
        POWER_SUPPLY_PROP_CHARGE_NOW,
        POWER_SUPPLY_PROP_TEMP,
+       POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
+       POWER_SUPPLY_PROP_CAPACITY,
 };
 
 static int ds2760_battery_probe(struct platform_device *pdev)
@@ -391,6 +414,10 @@ static int ds2760_battery_probe(struct platform_device *pdev)
 
        ds2760_battery_write_status(di, status);
 
+       /* set rated capacity from module param */
+       if (rated_capacity)
+               ds2760_battery_write_rated_capacity(di, rated_capacity);
+
        retval = power_supply_register(&pdev->dev, &di->bat);
        if (retval) {
                dev_err(di->dev, "failed to register battery\n");