aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim, Milo <Milo.Kim@ti.com>2012-10-18 20:12:21 -0400
committerAnton Vorontsov <anton.vorontsov@linaro.org>2012-11-17 23:42:12 -0500
commit340968de484967f931d89d20a1344d213fa86fb8 (patch)
treea5e1f1493dbb49a86d591a53938ee153213a5cab
parent968a47836c7f9dc6a3987f846bb7e095d30b86ec (diff)
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: Milo(Woogyom) Kim <milo.kim@ti.com> Reviewed-by Lars-Peter Clausen <lars@metafoo.de> Acked-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
-rw-r--r--drivers/power/lp8788-charger.c26
1 files changed, 7 insertions, 19 deletions
diff --git a/drivers/power/lp8788-charger.c b/drivers/power/lp8788-charger.c
index 614e6aafc51..1afa5f7a535 100644
--- a/drivers/power/lp8788-charger.c
+++ b/drivers/power/lp8788-charger.c
@@ -235,25 +235,14 @@ static int lp8788_get_battery_present(struct lp8788_charger *pchg,
235 return 0; 235 return 0;
236} 236}
237 237
238static int lp8788_get_vbatt_adc(struct lp8788_charger *pchg, 238static int lp8788_get_vbatt_adc(struct lp8788_charger *pchg, int *result)
239 unsigned int *result)
240{ 239{
241 struct iio_channel *channel = pchg->chan[LP8788_VBATT]; 240 struct iio_channel *channel = pchg->chan[LP8788_VBATT];
242 int scaleint;
243 int scalepart;
244 int ret;
245 241
246 if (!channel) 242 if (!channel)
247 return -EINVAL; 243 return -EINVAL;
248 244
249 ret = iio_read_channel_scale(channel, &scaleint, &scalepart); 245 return iio_read_channel_processed(channel, result);
250 if (ret != IIO_VAL_INT_PLUS_MICRO)
251 return -EINVAL;
252
253 /* unit: mV */
254 *result = (scaleint + scalepart * 1000000) / 1000;
255
256 return 0;
257} 246}
258 247
259static int lp8788_get_battery_voltage(struct lp8788_charger *pchg, 248static int lp8788_get_battery_voltage(struct lp8788_charger *pchg,
@@ -268,7 +257,7 @@ static int lp8788_get_battery_capacity(struct lp8788_charger *pchg,
268 struct lp8788 *lp = pchg->lp; 257 struct lp8788 *lp = pchg->lp;
269 struct lp8788_charger_platform_data *pdata = pchg->pdata; 258 struct lp8788_charger_platform_data *pdata = pchg->pdata;
270 unsigned int max_vbatt; 259 unsigned int max_vbatt;
271 unsigned int vbatt; 260 int vbatt;
272 enum lp8788_charging_state state; 261 enum lp8788_charging_state state;
273 u8 data; 262 u8 data;
274 int ret; 263 int ret;
@@ -304,19 +293,18 @@ static int lp8788_get_battery_temperature(struct lp8788_charger *pchg,
304 union power_supply_propval *val) 293 union power_supply_propval *val)
305{ 294{
306 struct iio_channel *channel = pchg->chan[LP8788_BATT_TEMP]; 295 struct iio_channel *channel = pchg->chan[LP8788_BATT_TEMP];
307 int scaleint; 296 int result;
308 int scalepart;
309 int ret; 297 int ret;
310 298
311 if (!channel) 299 if (!channel)
312 return -EINVAL; 300 return -EINVAL;
313 301
314 ret = iio_read_channel_scale(channel, &scaleint, &scalepart); 302 ret = iio_read_channel_processed(channel, &result);
315 if (ret != IIO_VAL_INT_PLUS_MICRO) 303 if (ret < 0)
316 return -EINVAL; 304 return -EINVAL;
317 305
318 /* unit: 0.1 'C */ 306 /* unit: 0.1 'C */
319 val->intval = (scaleint + scalepart * 1000000) / 100; 307 val->intval = result * 10;
320 308
321 return 0; 309 return 0;
322} 310}