Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: ab8500_fg: Convert to IIO ADC

This switches the AB8500 fuel gauge driver to using
the standard IIO ADC channel lookup and conversion routines.

Acked-by: Sebastian Reichel <sre@kernel.org>
Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Linus Walleij and committed by
Jonathan Cameron
1e82623c 97ab78ba

+15 -8
+15 -8
drivers/power/supply/ab8500_fg.c
··· 32 32 #include <linux/mfd/abx500.h> 33 33 #include <linux/mfd/abx500/ab8500.h> 34 34 #include <linux/mfd/abx500/ab8500-bm.h> 35 - #include <linux/mfd/abx500/ab8500-gpadc.h> 35 + #include <linux/iio/consumer.h> 36 36 #include <linux/kernel.h> 37 37 38 38 #define MILLI_TO_MICRO 1000 ··· 182 182 * @bat_cap: Structure for battery capacity specific parameters 183 183 * @avg_cap: Average capacity filter 184 184 * @parent: Pointer to the struct ab8500 185 - * @gpadc: Pointer to the struct gpadc 185 + * @main_bat_v: ADC channel for the main battery voltage 186 186 * @bm: Platform specific battery management information 187 187 * @fg_psy: Structure that holds the FG specific battery properties 188 188 * @fg_wq: Work queue for running the FG algorithm ··· 224 224 struct ab8500_fg_battery_capacity bat_cap; 225 225 struct ab8500_fg_avg_cap avg_cap; 226 226 struct ab8500 *parent; 227 - struct ab8500_gpadc *gpadc; 227 + struct iio_channel *main_bat_v; 228 228 struct abx500_bm_data *bm; 229 229 struct power_supply *fg_psy; 230 230 struct workqueue_struct *fg_wq; ··· 829 829 */ 830 830 static int ab8500_fg_bat_voltage(struct ab8500_fg *di) 831 831 { 832 - int vbat; 832 + int vbat, ret; 833 833 static int prev; 834 834 835 - vbat = ab8500_gpadc_convert(di->gpadc, MAIN_BAT_V); 836 - if (vbat < 0) { 835 + ret = iio_read_channel_processed(di->main_bat_v, &vbat); 836 + if (ret < 0) { 837 837 dev_err(di->dev, 838 - "%s gpadc conversion failed, using previous value\n", 838 + "%s ADC conversion failed, using previous value\n", 839 839 __func__); 840 840 return prev; 841 841 } ··· 3066 3066 /* get parent data */ 3067 3067 di->dev = &pdev->dev; 3068 3068 di->parent = dev_get_drvdata(pdev->dev.parent); 3069 - di->gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 3069 + 3070 + di->main_bat_v = devm_iio_channel_get(&pdev->dev, "main_bat_v"); 3071 + if (IS_ERR(di->main_bat_v)) { 3072 + if (PTR_ERR(di->main_bat_v) == -ENODEV) 3073 + return -EPROBE_DEFER; 3074 + dev_err(&pdev->dev, "failed to get main battery ADC channel\n"); 3075 + return PTR_ERR(di->main_bat_v); 3076 + } 3070 3077 3071 3078 psy_cfg.supplied_to = supply_interface; 3072 3079 psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface);