Commit 9c9cf9e2 authored by Philip Rakity's avatar Philip Rakity Committed by Anton Vorontsov

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: default avatarPhilip Rakity <prakity@marvell.com>
Signed-off-by: default avatarAnton Vorontsov <cbouatmailru@gmail.com>
parent 44abd774
...@@ -188,7 +188,7 @@ static int start_measure(struct max8925_power_info *info, int type) ...@@ -188,7 +188,7 @@ static int start_measure(struct max8925_power_info *info, int type)
} }
max8925_bulk_read(info->adc, meas_reg, 2, buf); max8925_bulk_read(info->adc, meas_reg, 2, buf);
ret = (buf[0] << 4) | (buf[1] >> 4); ret = ((buf[0]<<8) | buf[1]) >> 4;
return ret; return ret;
} }
...@@ -208,7 +208,7 @@ static int max8925_ac_get_prop(struct power_supply *psy, ...@@ -208,7 +208,7 @@ static int max8925_ac_get_prop(struct power_supply *psy,
if (info->ac_online) { if (info->ac_online) {
ret = start_measure(info, MEASURE_VCHG); ret = start_measure(info, MEASURE_VCHG);
if (ret >= 0) { if (ret >= 0) {
val->intval = ret << 1; /* unit is mV */ val->intval = ret * 2000; /* unit is uV */
goto out; goto out;
} }
} }
...@@ -242,7 +242,7 @@ static int max8925_usb_get_prop(struct power_supply *psy, ...@@ -242,7 +242,7 @@ static int max8925_usb_get_prop(struct power_supply *psy,
if (info->usb_online) { if (info->usb_online) {
ret = start_measure(info, MEASURE_VCHG); ret = start_measure(info, MEASURE_VCHG);
if (ret >= 0) { if (ret >= 0) {
val->intval = ret << 1; /* unit is mV */ val->intval = ret * 2000; /* unit is uV */
goto out; goto out;
} }
} }
...@@ -266,7 +266,6 @@ static int max8925_bat_get_prop(struct power_supply *psy, ...@@ -266,7 +266,6 @@ static int max8925_bat_get_prop(struct power_supply *psy,
union power_supply_propval *val) union power_supply_propval *val)
{ {
struct max8925_power_info *info = dev_get_drvdata(psy->dev->parent); struct max8925_power_info *info = dev_get_drvdata(psy->dev->parent);
long long int tmp = 0;
int ret = 0; int ret = 0;
switch (psp) { switch (psp) {
...@@ -277,7 +276,7 @@ static int max8925_bat_get_prop(struct power_supply *psy, ...@@ -277,7 +276,7 @@ static int max8925_bat_get_prop(struct power_supply *psy,
if (info->bat_online) { if (info->bat_online) {
ret = start_measure(info, MEASURE_VMBATT); ret = start_measure(info, MEASURE_VMBATT);
if (ret >= 0) { if (ret >= 0) {
val->intval = ret << 1; /* unit is mV */ val->intval = ret * 2000; /* unit is uV */
ret = 0; ret = 0;
break; break;
} }
...@@ -288,8 +287,8 @@ static int max8925_bat_get_prop(struct power_supply *psy, ...@@ -288,8 +287,8 @@ static int max8925_bat_get_prop(struct power_supply *psy,
if (info->bat_online) { if (info->bat_online) {
ret = start_measure(info, MEASURE_ISNS); ret = start_measure(info, MEASURE_ISNS);
if (ret >= 0) { if (ret >= 0) {
tmp = (long long int)ret * 6250 / 4096 - 3125; /* assume r_sns is 0.02 */
ret = (int)tmp; ret = ((ret * 6250) - 3125) /* uA */;
val->intval = 0; val->intval = 0;
if (ret > 0) if (ret > 0)
val->intval = ret; /* unit is mA */ val->intval = ret; /* unit is mA */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment