Commit 1e82623c authored by Linus Walleij's avatar Linus Walleij Committed by Jonathan Cameron

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: default avatarSebastian Reichel <sre@kernel.org>
Acked-by: default avatarJonathan Cameron <jic23@kernel.org>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 97ab78ba
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include <linux/mfd/abx500.h> #include <linux/mfd/abx500.h>
#include <linux/mfd/abx500/ab8500.h> #include <linux/mfd/abx500/ab8500.h>
#include <linux/mfd/abx500/ab8500-bm.h> #include <linux/mfd/abx500/ab8500-bm.h>
#include <linux/mfd/abx500/ab8500-gpadc.h> #include <linux/iio/consumer.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#define MILLI_TO_MICRO 1000 #define MILLI_TO_MICRO 1000
...@@ -182,7 +182,7 @@ struct inst_curr_result_list { ...@@ -182,7 +182,7 @@ struct inst_curr_result_list {
* @bat_cap: Structure for battery capacity specific parameters * @bat_cap: Structure for battery capacity specific parameters
* @avg_cap: Average capacity filter * @avg_cap: Average capacity filter
* @parent: Pointer to the struct ab8500 * @parent: Pointer to the struct ab8500
* @gpadc: Pointer to the struct gpadc * @main_bat_v: ADC channel for the main battery voltage
* @bm: Platform specific battery management information * @bm: Platform specific battery management information
* @fg_psy: Structure that holds the FG specific battery properties * @fg_psy: Structure that holds the FG specific battery properties
* @fg_wq: Work queue for running the FG algorithm * @fg_wq: Work queue for running the FG algorithm
...@@ -224,7 +224,7 @@ struct ab8500_fg { ...@@ -224,7 +224,7 @@ struct ab8500_fg {
struct ab8500_fg_battery_capacity bat_cap; struct ab8500_fg_battery_capacity bat_cap;
struct ab8500_fg_avg_cap avg_cap; struct ab8500_fg_avg_cap avg_cap;
struct ab8500 *parent; struct ab8500 *parent;
struct ab8500_gpadc *gpadc; struct iio_channel *main_bat_v;
struct abx500_bm_data *bm; struct abx500_bm_data *bm;
struct power_supply *fg_psy; struct power_supply *fg_psy;
struct workqueue_struct *fg_wq; struct workqueue_struct *fg_wq;
...@@ -829,13 +829,13 @@ static void ab8500_fg_acc_cur_work(struct work_struct *work) ...@@ -829,13 +829,13 @@ static void ab8500_fg_acc_cur_work(struct work_struct *work)
*/ */
static int ab8500_fg_bat_voltage(struct ab8500_fg *di) static int ab8500_fg_bat_voltage(struct ab8500_fg *di)
{ {
int vbat; int vbat, ret;
static int prev; static int prev;
vbat = ab8500_gpadc_convert(di->gpadc, MAIN_BAT_V); ret = iio_read_channel_processed(di->main_bat_v, &vbat);
if (vbat < 0) { if (ret < 0) {
dev_err(di->dev, dev_err(di->dev,
"%s gpadc conversion failed, using previous value\n", "%s ADC conversion failed, using previous value\n",
__func__); __func__);
return prev; return prev;
} }
...@@ -3066,7 +3066,14 @@ static int ab8500_fg_probe(struct platform_device *pdev) ...@@ -3066,7 +3066,14 @@ static int ab8500_fg_probe(struct platform_device *pdev)
/* get parent data */ /* get parent data */
di->dev = &pdev->dev; di->dev = &pdev->dev;
di->parent = dev_get_drvdata(pdev->dev.parent); di->parent = dev_get_drvdata(pdev->dev.parent);
di->gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
di->main_bat_v = devm_iio_channel_get(&pdev->dev, "main_bat_v");
if (IS_ERR(di->main_bat_v)) {
if (PTR_ERR(di->main_bat_v) == -ENODEV)
return -EPROBE_DEFER;
dev_err(&pdev->dev, "failed to get main battery ADC channel\n");
return PTR_ERR(di->main_bat_v);
}
psy_cfg.supplied_to = supply_interface; psy_cfg.supplied_to = supply_interface;
psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface); psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface);
......
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