aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorPhilip Rakity <prakity@marvell.com>2011-11-25 12:25:23 -0500
committerAnton Vorontsov <cbouatmailru@gmail.com>2011-11-25 12:26:03 -0500
commit9c9cf9e26363d0c06d0e01d5304477be97ace5cb (patch)
tree11c5ce9267a40ec86a08cb405c6d99a6ff5ad15f /drivers/power
parent44abd774f52999125d499aed17a2f70211c34dcd (diff)
max8925_power: Fix incorrect voltage and current calculation
The datasheet indicates a 12 bit value is returned for i2c registers for voltage and current. Code was assuming 8 bits. But default for chip is 12 bit return value. Voltage is returned in 2mV units -- adjust to return as uV per linux power spec Adjust current calculation to return units in uA. Signed-off-by: Philip Rakity <prakity@marvell.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/max8925_power.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/drivers/power/max8925_power.c b/drivers/power/max8925_power.c
index a70e16d3a3dc..b16bd71f24fb 100644
--- a/drivers/power/max8925_power.c
+++ b/drivers/power/max8925_power.c
@@ -188,7 +188,7 @@ static int start_measure(struct max8925_power_info *info, int type)
188 } 188 }
189 189
190 max8925_bulk_read(info->adc, meas_reg, 2, buf); 190 max8925_bulk_read(info->adc, meas_reg, 2, buf);
191 ret = (buf[0] << 4) | (buf[1] >> 4); 191 ret = ((buf[0]<<8) | buf[1]) >> 4;
192 192
193 return ret; 193 return ret;
194} 194}
@@ -208,7 +208,7 @@ static int max8925_ac_get_prop(struct power_supply *psy,
208 if (info->ac_online) { 208 if (info->ac_online) {
209 ret = start_measure(info, MEASURE_VCHG); 209 ret = start_measure(info, MEASURE_VCHG);
210 if (ret >= 0) { 210 if (ret >= 0) {
211 val->intval = ret << 1; /* unit is mV */ 211 val->intval = ret * 2000; /* unit is uV */
212 goto out; 212 goto out;
213 } 213 }
214 } 214 }
@@ -242,7 +242,7 @@ static int max8925_usb_get_prop(struct power_supply *psy,
242 if (info->usb_online) { 242 if (info->usb_online) {
243 ret = start_measure(info, MEASURE_VCHG); 243 ret = start_measure(info, MEASURE_VCHG);
244 if (ret >= 0) { 244 if (ret >= 0) {
245 val->intval = ret << 1; /* unit is mV */ 245 val->intval = ret * 2000; /* unit is uV */
246 goto out; 246 goto out;
247 } 247 }
248 } 248 }
@@ -266,7 +266,6 @@ static int max8925_bat_get_prop(struct power_supply *psy,
266 union power_supply_propval *val) 266 union power_supply_propval *val)
267{ 267{
268 struct max8925_power_info *info = dev_get_drvdata(psy->dev->parent); 268 struct max8925_power_info *info = dev_get_drvdata(psy->dev->parent);
269 long long int tmp = 0;
270 int ret = 0; 269 int ret = 0;
271 270
272 switch (psp) { 271 switch (psp) {
@@ -277,7 +276,7 @@ static int max8925_bat_get_prop(struct power_supply *psy,
277 if (info->bat_online) { 276 if (info->bat_online) {
278 ret = start_measure(info, MEASURE_VMBATT); 277 ret = start_measure(info, MEASURE_VMBATT);
279 if (ret >= 0) { 278 if (ret >= 0) {
280 val->intval = ret << 1; /* unit is mV */ 279 val->intval = ret * 2000; /* unit is uV */
281 ret = 0; 280 ret = 0;
282 break; 281 break;
283 } 282 }
@@ -288,8 +287,8 @@ static int max8925_bat_get_prop(struct power_supply *psy,
288 if (info->bat_online) { 287 if (info->bat_online) {
289 ret = start_measure(info, MEASURE_ISNS); 288 ret = start_measure(info, MEASURE_ISNS);
290 if (ret >= 0) { 289 if (ret >= 0) {
291 tmp = (long long int)ret * 6250 / 4096 - 3125; 290 /* assume r_sns is 0.02 */
292 ret = (int)tmp; 291 ret = ((ret * 6250) - 3125) /* uA */;
293 val->intval = 0; 292 val->intval = 0;
294 if (ret > 0) 293 if (ret > 0)
295 val->intval = ret; /* unit is mA */ 294 val->intval = ret; /* unit is mA */