All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] power: max8925_power: Fix incorrect voltage and current calculation
@ 2011-08-26 20:28 Philip Rakity
  2011-08-26 23:11 ` Haojian Zhuang
  0 siblings, 1 reply; 2+ messages in thread
From: Philip Rakity @ 2011-08-26 20:28 UTC (permalink / raw)
  To: linux-kernel, Haojian Zhuang


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
*** NOT POSSIBLE TO VALIDATE THIS since my h/w does not have
current hooked up to 8925 *****

Signed-off-by: Philip Rakity <prakity@marvell.com>
---
 drivers/power/max8925_power.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/power/max8925_power.c b/drivers/power/max8925_power.c
index 29b5d2c..5e4e046 100644
--- a/drivers/power/max8925_power.c
+++ b/drivers/power/max8925_power.c
@@ -190,7 +190,7 @@ static int start_measure(struct max8925_power_info *info, int type)
 	}
 
 	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;
 }
@@ -210,7 +210,7 @@ static int max8925_ac_get_prop(struct power_supply *psy,
 		if (info->ac_online) {
 			ret = start_measure(info, MEASURE_VCHG);
 			if (ret >= 0) {
-				val->intval = ret << 1;	/* unit is mV */
+				val->intval = ret * 2000;	/* unit is uV */
 				goto out;
 			}
 		}
@@ -244,7 +244,7 @@ static int max8925_usb_get_prop(struct power_supply *psy,
 		if (info->usb_online) {
 			ret = start_measure(info, MEASURE_VCHG);
 			if (ret >= 0) {
-				val->intval = ret << 1;	/* unit is mV */
+				val->intval = ret * 2000;	/* unit is uV */
 				goto out;
 			}
 		}
@@ -268,7 +268,6 @@ static int max8925_bat_get_prop(struct power_supply *psy,
 				union power_supply_propval *val)
 {
 	struct max8925_power_info *info = dev_get_drvdata(psy->dev->parent);
-	long long int tmp = 0;
 	int ret = 0;
 
 	switch (psp) {
@@ -279,7 +278,7 @@ static int max8925_bat_get_prop(struct power_supply *psy,
 		if (info->bat_online) {
 			ret = start_measure(info, MEASURE_VMBATT);
 			if (ret >= 0) {
-				val->intval = ret << 1;	/* unit is mV */
+				val->intval = ret * 2000;	/* unit is uV */
 				ret = 0;
 				break;
 			}
@@ -290,8 +289,8 @@ static int max8925_bat_get_prop(struct power_supply *psy,
 		if (info->bat_online) {
 			ret = start_measure(info, MEASURE_ISNS);
 			if (ret >= 0) {
-				tmp = (long long int)ret * 6250 / 4096 - 3125;
-				ret = (int)tmp;
+				/* assume r_sns is 0.02 */
+				ret = ((ret * 6250) - 3125) /* uA */;
 				val->intval = 0;
 				if (ret > 0)
 					val->intval = ret; /* unit is mA */
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] power: max8925_power: Fix incorrect voltage and current calculation
  2011-08-26 20:28 [PATCH] power: max8925_power: Fix incorrect voltage and current calculation Philip Rakity
@ 2011-08-26 23:11 ` Haojian Zhuang
  0 siblings, 0 replies; 2+ messages in thread
From: Haojian Zhuang @ 2011-08-26 23:11 UTC (permalink / raw)
  To: Philip Rakity, David Woodhouse, cbou; +Cc: linux-kernel

On Sat, Aug 27, 2011 at 4:28 AM, Philip Rakity <prakity@marvell.com> wrote:
>
> 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
> *** NOT POSSIBLE TO VALIDATE THIS since my h/w does not have
> current hooked up to 8925 *****
>
> Signed-off-by: Philip Rakity <prakity@marvell.com>
> ---
>  drivers/power/max8925_power.c |   13 ++++++-------
>  1 files changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/power/max8925_power.c b/drivers/power/max8925_power.c
> index 29b5d2c..5e4e046 100644
> --- a/drivers/power/max8925_power.c
> +++ b/drivers/power/max8925_power.c
> @@ -190,7 +190,7 @@ static int start_measure(struct max8925_power_info *info, int type)
>        }
>
>        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;
>  }
> @@ -210,7 +210,7 @@ static int max8925_ac_get_prop(struct power_supply *psy,
>                if (info->ac_online) {
>                        ret = start_measure(info, MEASURE_VCHG);
>                        if (ret >= 0) {
> -                               val->intval = ret << 1; /* unit is mV */
> +                               val->intval = ret * 2000;       /* unit is uV */
>                                goto out;
>                        }
>                }
> @@ -244,7 +244,7 @@ static int max8925_usb_get_prop(struct power_supply *psy,
>                if (info->usb_online) {
>                        ret = start_measure(info, MEASURE_VCHG);
>                        if (ret >= 0) {
> -                               val->intval = ret << 1; /* unit is mV */
> +                               val->intval = ret * 2000;       /* unit is uV */
>                                goto out;
>                        }
>                }
> @@ -268,7 +268,6 @@ static int max8925_bat_get_prop(struct power_supply *psy,
>                                union power_supply_propval *val)
>  {
>        struct max8925_power_info *info = dev_get_drvdata(psy->dev->parent);
> -       long long int tmp = 0;
>        int ret = 0;
>
>        switch (psp) {
> @@ -279,7 +278,7 @@ static int max8925_bat_get_prop(struct power_supply *psy,
>                if (info->bat_online) {
>                        ret = start_measure(info, MEASURE_VMBATT);
>                        if (ret >= 0) {
> -                               val->intval = ret << 1; /* unit is mV */
> +                               val->intval = ret * 2000;       /* unit is uV */
>                                ret = 0;
>                                break;
>                        }
> @@ -290,8 +289,8 @@ static int max8925_bat_get_prop(struct power_supply *psy,
>                if (info->bat_online) {
>                        ret = start_measure(info, MEASURE_ISNS);
>                        if (ret >= 0) {
> -                               tmp = (long long int)ret * 6250 / 4096 - 3125;
> -                               ret = (int)tmp;
> +                               /* assume r_sns is 0.02 */
> +                               ret = ((ret * 6250) - 3125) /* uA */;
>                                val->intval = 0;
>                                if (ret > 0)
>                                        val->intval = ret; /* unit is mA */
> --
> 1.7.6
>

Loop maintainer

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-26 23:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-26 20:28 [PATCH] power: max8925_power: Fix incorrect voltage and current calculation Philip Rakity
2011-08-26 23:11 ` Haojian Zhuang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.