diff options
author | Jinyoung Park <jinyoungp@nvidia.com> | 2013-09-12 15:45:34 +0900 |
---|---|---|
committer | Dan Willemsen <dwillemsen@nvidia.com> | 2013-09-16 17:42:42 -0700 |
commit | e84979c2bbe78c9a51c1009ad1e4d9ad07411744 (patch) | |
tree | 6be10ad65344046b59bf45f6a86a7e922acc47ac /drivers/iio | |
parent | 595d6e3fc2cd52088a2e6edd61036bf45f425854 (diff) |
iio: inkern: Add functions to read channel with dual mode
Added functions to read channel with dual mode.
The functions check a channel info attribute and the channel supports
dual mode then read channel.
If the channel doesn't support dual mode, return error value.
Bug 1287901
Bug 1356128
Change-Id: Ia2ffdf8eb6d05f95f763939dc413be5b06b7c605
Signed-off-by: Jinyoung Park <jinyoungp@nvidia.com>
Reviewed-on: http://git-master/r/273636
GVS: Gerrit_Virtual_Submit
Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/industrialio-core.c | 2 | ||||
-rw-r--r-- | drivers/iio/inkern.c | 54 |
2 files changed, 56 insertions, 0 deletions
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index e145931ef1b8..cf9252c91acf 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -86,6 +86,8 @@ static const char * const iio_modifier_names[] = { static const char * const iio_chan_info_postfix[] = { [IIO_CHAN_INFO_RAW] = "raw", [IIO_CHAN_INFO_PROCESSED] = "input", + [IIO_CHAN_INFO_RAW_DUAL] = "raw_dual", + [IIO_CHAN_INFO_PROCESSED_DUAL] = "input_dual", [IIO_CHAN_INFO_SCALE] = "scale", [IIO_CHAN_INFO_OFFSET] = "offset", [IIO_CHAN_INFO_CALIBSCALE] = "calibscale", diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 0cf5f8e06cfc..8b3be9223bcb 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -540,6 +540,60 @@ err_unlock: } EXPORT_SYMBOL_GPL(iio_read_channel_processed); +int iio_read_channel_raw_dual(struct iio_channel *chan, int *val, int *val2) +{ + int ret; + + mutex_lock(&chan->indio_dev->info_exist_lock); + if (chan->indio_dev->info == NULL) { + ret = -ENODEV; + goto err_unlock; + } + + if (iio_channel_has_info(chan->channel, IIO_CHAN_INFO_RAW_DUAL)) + ret = iio_channel_read(chan, val, val2, IIO_CHAN_INFO_RAW_DUAL); + else + ret = -ENXIO; + +err_unlock: + mutex_unlock(&chan->indio_dev->info_exist_lock); + + return ret; +} +EXPORT_SYMBOL_GPL(iio_read_channel_raw_dual); + +int iio_read_channel_processed_dual(struct iio_channel *chan, int *val, + int *val2) +{ + int ret; + + mutex_lock(&chan->indio_dev->info_exist_lock); + if (chan->indio_dev->info == NULL) { + ret = -ENODEV; + goto err_unlock; + } + + if (iio_channel_has_info(chan->channel, IIO_CHAN_INFO_PROCESSED_DUAL)) { + ret = iio_channel_read(chan, val, val2, + IIO_CHAN_INFO_PROCESSED_DUAL); + } else { + ret = iio_channel_read(chan, val, val2, IIO_CHAN_INFO_RAW_DUAL); + if (ret < 0) + goto err_unlock; + ret = iio_convert_raw_to_processed_unlocked(chan, *val, val, 1); + if (ret < 0) + goto err_unlock; + ret = iio_convert_raw_to_processed_unlocked(chan, *val2, val2, + 1); + } + +err_unlock: + mutex_unlock(&chan->indio_dev->info_exist_lock); + + return ret; +} +EXPORT_SYMBOL_GPL(iio_read_channel_processed_dual); + int iio_read_channel_scale(struct iio_channel *chan, int *val, int *val2) { int ret; |