1 --- a/drivers/power/twl4030_bci_battery.c 2010-01-16 13:48:46.745838675 -0800
2 +++ b/drivers/power/twl4030_bci_battery.c 2010-01-16 13:41:47.317595764 -0800
4 static int twl4030battery_voltage(void)
6 int volt = read_bci_val(T2_BATTERY_VOLT);
8 return (volt * VOLT_STEP_SIZE) / VOLT_PSR_R;
12 + * Get latest battery voltage (using MADC)
14 + * When the BCI is not charging, the BCI voltage registers are not
15 + * updated and are 'frozen' but the data can be read through the
18 +static int twl4030battery_voltage_madc(void)
20 + struct twl4030_madc_request req;
22 + req.channels = (1 << 12);
24 + req.method = TWL4030_MADC_SW1;
27 + twl4030_madc_conversion(&req);
29 + return (((int) req.rbuf[12]) * VOLT_STEP_SIZE) / VOLT_PSR_R;
33 * Return the battery current
38 static void twl4030_bci_battery_read_status(struct twl4030_bci_device_info *di)
40 - di->temp_C = twl4030battery_temperature(di);
41 - di->voltage_uV = twl4030battery_voltage();
42 - di->current_uA = twl4030battery_current();
43 + if(di->charge_status != POWER_SUPPLY_STATUS_DISCHARGING) {
44 + di->temp_C = twl4030battery_temperature(di);
45 + di->voltage_uV = twl4030battery_voltage();
46 + di->current_uA = twl4030battery_current();
51 twl4030_bci_battery_update_status(struct twl4030_bci_device_info *di)
53 - twl4030_bci_battery_read_status(di);
54 - di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
56 if (power_supply_am_i_supplied(&di->bat))
57 di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
59 di->charge_status = POWER_SUPPLY_STATUS_DISCHARGING;
60 + twl4030_bci_battery_read_status(di);
63 static void twl4030_bci_battery_work(struct work_struct *work)
70 +show_voltage(struct device *dev, struct device_attribute *attr, char *buf)
72 + return sprintf(buf, "%d\n", twl4030battery_voltage_madc());
75 static DEVICE_ATTR(charge_current, S_IRUGO | S_IWUGO, show_charge_current, set_charge_current);
76 +static DEVICE_ATTR(voltage_now_madc, S_IRUGO, show_voltage, NULL);
78 static int twl4030_bk_bci_battery_get_property(struct power_supply *psy,
79 enum power_supply_property psp,
80 @@ -998,10 +1026,23 @@
83 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
84 - val->intval = di->voltage_uV;
86 + /* Get latest data from MADC -- not done periodically by
87 + worker as this is more expensive, so only do it when we
88 + are actually asked for the data... */
89 + if(di->charge_status == POWER_SUPPLY_STATUS_DISCHARGING)
90 + val->intval = twl4030battery_voltage_madc();
92 + val->intval = di->voltage_uV;
96 case POWER_SUPPLY_PROP_CURRENT_NOW:
97 - val->intval = di->current_uA;
98 + /* FIXME: Get from MADC */
99 + if(di->charge_status == POWER_SUPPLY_STATUS_DISCHARGING)
102 + val->intval = di->current_uA;
104 case POWER_SUPPLY_PROP_TEMP:
105 val->intval = di->temp_C;
106 @@ -1016,6 +1057,12 @@
109 case POWER_SUPPLY_PROP_CAPACITY:
110 + /* Get latest data from MADC -- not done periodically by
111 + worker as this is more expensive, so only do it when we
112 + are actually asked for the data... */
113 + if(di->charge_status == POWER_SUPPLY_STATUS_DISCHARGING)
114 + di->voltage_uV = twl4030battery_voltage_madc();
117 * need to get the correct percentage value per the
118 * battery characteristics. Approx values for now.
119 @@ -1145,6 +1192,7 @@
123 + ret = device_create_file(di->bat.dev, &dev_attr_voltage_now_madc);
124 ret = device_create_file(di->bat.dev, &dev_attr_charge_current);
126 dev_err(&pdev->dev, "failed to create sysfs entries\n");