lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 18 Oct 2012 06:11:53 +0000
From:	"Kim, Milo" <Milo.Kim@...com>
To:	"cbou@...l.ru" <cbou@...l.ru>
CC:	Anton Vorontsov <anton.vorontsov@...aro.org>,
	Lars-Peter Clausen <lars@...afoo.de>,
	Jonathan Cameron <jic23@...nel.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: [PATCH 3/3] lp8788-charger: fix wrong ADC conversion

 To get the battery voltage and temperature, IIO ADC functions are used.
 LP8788 ADC driver provides RAW and SCALE channel information.
 Both RAW with SCALE values are used for the ADC calculation.
 The scale is micro unit, additional conversions are required in each case.
 This patch fixes wrong ADC result.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@...com>
---
 drivers/power/lp8788-charger.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/power/lp8788-charger.c b/drivers/power/lp8788-charger.c
index 02fc9ab..3c739e6 100644
--- a/drivers/power/lp8788-charger.c
+++ b/drivers/power/lp8788-charger.c
@@ -239,19 +239,26 @@ static int lp8788_get_vbatt_adc(struct lp8788_charger *pchg,
 				unsigned int *result)
 {
 	struct iio_channel *channel = pchg->chan[LP8788_VBATT];
+	int raw;
 	int scaleint;
 	int scalepart;
 	int ret;
+	unsigned long tmp;
 
 	if (!channel)
 		return -EINVAL;
 
+	ret = iio_read_channel_raw(channel, &raw);
+	if (ret != IIO_VAL_INT)
+		return -EINVAL;
+
 	ret = iio_read_channel_scale(channel, &scaleint, &scalepart);
 	if (ret != IIO_VAL_INT_PLUS_MICRO)
 		return -EINVAL;
 
 	/* unit: mV */
-	*result = (scaleint + scalepart * 1000000) / 1000;
+	tmp = raw * scaleint + div_u64(raw * scalepart, 1000000L);
+	*result = (unsigned int)tmp;
 
 	return 0;
 }
@@ -304,19 +311,26 @@ static int lp8788_get_battery_temperature(struct lp8788_charger *pchg,
 				union power_supply_propval *val)
 {
 	struct iio_channel *channel = pchg->chan[LP8788_BATT_TEMP];
+	int raw;
 	int scaleint;
 	int scalepart;
 	int ret;
+	unsigned long tmp;
 
 	if (!channel)
 		return -EINVAL;
 
+	ret = iio_read_channel_raw(channel, &raw);
+	if (ret != IIO_VAL_INT)
+		return -EINVAL;
+
 	ret = iio_read_channel_scale(channel, &scaleint, &scalepart);
 	if (ret != IIO_VAL_INT_PLUS_MICRO)
 		return -EINVAL;
 
 	/* unit: 0.1 'C */
-	val->intval = (scaleint + scalepart * 1000000) / 100;
+	tmp = raw * scaleint + div_u64(raw * scalepart, 1000000L);
+	val->intval = (unsigned int)tmp * 10;
 
 	return 0;
 }
-- 
1.7.9.5


Best Regards,
Milo


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ