Commit 340968de authored by Kim, Milo's avatar Kim, Milo Committed by Anton Vorontsov

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. This patch
fixes wrong ADC result.
Signed-off-by: default avatarMilo(Woogyom) Kim <milo.kim@ti.com>
Reviewed-by Lars-Peter Clausen <lars@metafoo.de>
Acked-by: default avatarJonathan Cameron <jic23@kernel.org>
Signed-off-by: default avatarAnton Vorontsov <anton.vorontsov@linaro.org>
parent 968a4783
...@@ -235,25 +235,14 @@ static int lp8788_get_battery_present(struct lp8788_charger *pchg, ...@@ -235,25 +235,14 @@ static int lp8788_get_battery_present(struct lp8788_charger *pchg,
return 0; return 0;
} }
static int lp8788_get_vbatt_adc(struct lp8788_charger *pchg, static int lp8788_get_vbatt_adc(struct lp8788_charger *pchg, int *result)
unsigned int *result)
{ {
struct iio_channel *channel = pchg->chan[LP8788_VBATT]; struct iio_channel *channel = pchg->chan[LP8788_VBATT];
int scaleint;
int scalepart;
int ret;
if (!channel) if (!channel)
return -EINVAL; return -EINVAL;
ret = iio_read_channel_scale(channel, &scaleint, &scalepart); return iio_read_channel_processed(channel, result);
if (ret != IIO_VAL_INT_PLUS_MICRO)
return -EINVAL;
/* unit: mV */
*result = (scaleint + scalepart * 1000000) / 1000;
return 0;
} }
static int lp8788_get_battery_voltage(struct lp8788_charger *pchg, static int lp8788_get_battery_voltage(struct lp8788_charger *pchg,
...@@ -268,7 +257,7 @@ static int lp8788_get_battery_capacity(struct lp8788_charger *pchg, ...@@ -268,7 +257,7 @@ static int lp8788_get_battery_capacity(struct lp8788_charger *pchg,
struct lp8788 *lp = pchg->lp; struct lp8788 *lp = pchg->lp;
struct lp8788_charger_platform_data *pdata = pchg->pdata; struct lp8788_charger_platform_data *pdata = pchg->pdata;
unsigned int max_vbatt; unsigned int max_vbatt;
unsigned int vbatt; int vbatt;
enum lp8788_charging_state state; enum lp8788_charging_state state;
u8 data; u8 data;
int ret; int ret;
...@@ -304,19 +293,18 @@ static int lp8788_get_battery_temperature(struct lp8788_charger *pchg, ...@@ -304,19 +293,18 @@ static int lp8788_get_battery_temperature(struct lp8788_charger *pchg,
union power_supply_propval *val) union power_supply_propval *val)
{ {
struct iio_channel *channel = pchg->chan[LP8788_BATT_TEMP]; struct iio_channel *channel = pchg->chan[LP8788_BATT_TEMP];
int scaleint; int result;
int scalepart;
int ret; int ret;
if (!channel) if (!channel)
return -EINVAL; return -EINVAL;
ret = iio_read_channel_scale(channel, &scaleint, &scalepart); ret = iio_read_channel_processed(channel, &result);
if (ret != IIO_VAL_INT_PLUS_MICRO) if (ret < 0)
return -EINVAL; return -EINVAL;
/* unit: 0.1 'C */ /* unit: 0.1 'C */
val->intval = (scaleint + scalepart * 1000000) / 100; val->intval = result * 10;
return 0; return 0;
} }
......
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