diff options
author | Laxman Dewangan <ldewangan@nvidia.com> | 2014-04-13 11:05:03 +0530 |
---|---|---|
committer | Laxman Dewangan <ldewangan@nvidia.com> | 2014-04-13 05:38:28 -0700 |
commit | ff66b38933844c9cd6b57abcf3073b13a35dc092 (patch) | |
tree | a9d082c41a4c4322fb6b351b96c7df28b32d7054 /drivers | |
parent | f1d0c94ee899b600173bc504565c813936f5c92f (diff) |
power: batter-charger-gauge: add API for reading battery current
Add API for reading battery current throuch IIO channels.
IIO channel information is read from battery gauge device node.
bug 1413219
Change-Id: I87094acbd15796a16acb520ba52c2351439e4bbb
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/395550
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/power/battery-charger-gauge-comm.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/power/battery-charger-gauge-comm.c b/drivers/power/battery-charger-gauge-comm.c index 511509759a6d..ee4c44116498 100644 --- a/drivers/power/battery-charger-gauge-comm.c +++ b/drivers/power/battery-charger-gauge-comm.c @@ -38,6 +38,8 @@ #include <linux/power/battery-charger-gauge-comm.h> #include <linux/power/reset/system-pmic.h> #include <linux/wakelock.h> +#include <linux/iio/consumer.h> +#include <linux/iio/iio.h> #define JETI_TEMP_COLD 0 #define JETI_TEMP_COOL 10 @@ -80,6 +82,8 @@ struct battery_gauge_dev { int battery_capacity; int battery_snapshot_voltage; int battery_snapshot_capacity; + const char *bat_curr_channel_name; + struct iio_channel *bat_current_iio_channel; }; struct battery_gauge_dev *bg_temp; @@ -516,6 +520,36 @@ int battery_gauge_get_battery_temperature(struct battery_gauge_dev *bg_dev, } EXPORT_SYMBOL_GPL(battery_gauge_get_battery_temperature); +int battery_gauge_get_battery_current(struct battery_gauge_dev *bg_dev, + int *current_ma) +{ + int ret; + + if (!bg_dev || !bg_dev->bat_curr_channel_name) + return -EINVAL; + + if (!bg_dev->bat_current_iio_channel) + bg_dev->bat_current_iio_channel = + iio_channel_get(bg_dev->parent_dev, + bg_dev->bat_curr_channel_name); + if (!bg_dev->bat_current_iio_channel || IS_ERR(bg_dev->bat_current_iio_channel)) { + dev_info(bg_dev->parent_dev, + "Battery IIO current channel %s not registered yet\n", + bg_dev->bat_curr_channel_name); + bg_dev->bat_current_iio_channel = NULL; + return -ENODEV; + } + + ret = iio_read_channel_processed(bg_dev->bat_current_iio_channel, + current_ma); + if (ret < 0) { + dev_err(bg_dev->parent_dev, " The channel read failed: %d\n", ret); + return ret; + } + return 0; +} +EXPORT_SYMBOL_GPL(battery_gauge_get_battery_current); + struct battery_gauge_dev *battery_gauge_register(struct device *dev, struct battery_gauge_info *bgi, void *drv_data) { @@ -548,6 +582,9 @@ struct battery_gauge_dev *battery_gauge_register(struct device *dev, bg_dev->drv_data = drv_data; bg_dev->tz_name = kstrdup(bgi->tz_name, GFP_KERNEL); + if (bgi->current_channel_name) + bg_dev->bat_curr_channel_name = bgi->current_channel_name; + if (bg_dev->tz_name) { bg_dev->battery_tz = thermal_zone_device_find_by_name( bg_dev->tz_name); |