diff options
Diffstat (limited to 'drivers/power/lp8788-charger.c')
-rw-r--r-- | drivers/power/lp8788-charger.c | 81 |
1 files changed, 19 insertions, 62 deletions
diff --git a/drivers/power/lp8788-charger.c b/drivers/power/lp8788-charger.c index e852d12cd077..22b6407c9ca9 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, return 0; } -static int lp8788_get_vbatt_adc(struct lp8788_charger *pchg, - unsigned int *result) +static int lp8788_get_vbatt_adc(struct lp8788_charger *pchg, int *result) { struct iio_channel *channel = pchg->chan[LP8788_VBATT]; - int scaleint; - int scalepart; - int ret; if (!channel) 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; - - return 0; + return iio_read_channel_processed(channel, result); } static int lp8788_get_battery_voltage(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_charger_platform_data *pdata = pchg->pdata; unsigned int max_vbatt; - unsigned int vbatt; + int vbatt; enum lp8788_charging_state state; u8 data; int ret; @@ -304,19 +293,18 @@ 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 scaleint; - int scalepart; + int result; int ret; if (!channel) return -EINVAL; - ret = iio_read_channel_scale(channel, &scaleint, &scalepart); - if (ret != IIO_VAL_INT_PLUS_MICRO) + ret = iio_read_channel_processed(channel, &result); + if (ret < 0) return -EINVAL; /* unit: 0.1 'C */ - val->intval = (scaleint + scalepart * 1000000) / 100; + val->intval = result * 10; return 0; } @@ -592,53 +580,22 @@ static void lp8788_irq_unregister(struct platform_device *pdev, } } -static void lp8788_setup_adc_channel(struct lp8788_charger *pchg) +static void lp8788_setup_adc_channel(const char *consumer_name, + struct lp8788_charger *pchg) { struct lp8788_charger_platform_data *pdata = pchg->pdata; - struct device *dev = pchg->lp->dev; struct iio_channel *chan; - enum lp8788_adc_id id; - const char *chan_name[LPADC_MAX] = { - [LPADC_VBATT_5P5] = "vbatt-5p5", - [LPADC_VBATT_6P0] = "vbatt-6p0", - [LPADC_VBATT_5P0] = "vbatt-5p0", - [LPADC_ADC1] = "adc1", - [LPADC_ADC2] = "adc2", - [LPADC_ADC3] = "adc3", - [LPADC_ADC4] = "adc4", - }; if (!pdata) return; - id = pdata->vbatt_adc; - switch (id) { - case LPADC_VBATT_5P5: - case LPADC_VBATT_6P0: - case LPADC_VBATT_5P0: - chan = iio_channel_get(NULL, chan_name[id]); - pchg->chan[LP8788_VBATT] = IS_ERR(chan) ? NULL : chan; - break; - default: - dev_err(dev, "invalid ADC id for VBATT: %d\n", id); - pchg->chan[LP8788_VBATT] = NULL; - break; - } + /* ADC channel for battery voltage */ + chan = iio_channel_get(consumer_name, pdata->adc_vbatt); + pchg->chan[LP8788_VBATT] = IS_ERR(chan) ? NULL : chan; - id = pdata->batt_temp_adc; - switch (id) { - case LPADC_ADC1: - case LPADC_ADC2: - case LPADC_ADC3: - case LPADC_ADC4: - chan = iio_channel_get(NULL, chan_name[id]); - pchg->chan[LP8788_BATT_TEMP] = IS_ERR(chan) ? NULL : chan; - break; - default: - dev_err(dev, "invalid ADC id for BATT_TEMP : %d\n", id); - pchg->chan[LP8788_BATT_TEMP] = NULL; - break; - } + /* ADC channel for battery temperature */ + chan = iio_channel_get(consumer_name, pdata->adc_batt_temp); + pchg->chan[LP8788_BATT_TEMP] = IS_ERR(chan) ? NULL : chan; } static void lp8788_release_adc_channel(struct lp8788_charger *pchg) @@ -729,7 +686,7 @@ static const struct attribute_group lp8788_attr_group = { .attrs = lp8788_charger_attr, }; -static __devinit int lp8788_charger_probe(struct platform_device *pdev) +static int lp8788_charger_probe(struct platform_device *pdev) { struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent); struct lp8788_charger *pchg; @@ -747,7 +704,7 @@ static __devinit int lp8788_charger_probe(struct platform_device *pdev) if (ret) return ret; - lp8788_setup_adc_channel(pchg); + lp8788_setup_adc_channel(pdev->name, pchg); ret = lp8788_psy_register(pdev, pchg); if (ret) @@ -766,7 +723,7 @@ static __devinit int lp8788_charger_probe(struct platform_device *pdev) return 0; } -static int __devexit lp8788_charger_remove(struct platform_device *pdev) +static int lp8788_charger_remove(struct platform_device *pdev) { struct lp8788_charger *pchg = platform_get_drvdata(pdev); @@ -781,7 +738,7 @@ static int __devexit lp8788_charger_remove(struct platform_device *pdev) static struct platform_driver lp8788_charger_driver = { .probe = lp8788_charger_probe, - .remove = __devexit_p(lp8788_charger_remove), + .remove = lp8788_charger_remove, .driver = { .name = LP8788_DEV_CHARGER, .owner = THIS_MODULE, |