summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaud Pouliquen <arnaud.pouliquen@st.com>2018-01-10 05:13:06 -0500
committerMark Brown <broonie@kernel.org>2018-01-10 05:30:08 -0500
commit34739a213dbb85c8d775de42d52358255059c257 (patch)
treea12a6cb37562cf92480e9b45e18c1f3257135e51
parentb688c18d30060e8a840d8af72790339c72acdac4 (diff)
IIO: inkern: API for manipulating channel attributes
Extend the inkern API with functions for reading and writing attribute of iio channels. Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@st.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/iio/inkern.c17
-rw-r--r--include/linux/iio/consumer.h26
-rw-r--r--include/linux/iio/iio.h28
-rw-r--r--include/linux/iio/types.h28
4 files changed, 66 insertions, 33 deletions
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index 069defcc6d9b..ec98790e2a28 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -664,9 +664,8 @@ err_unlock:
664} 664}
665EXPORT_SYMBOL_GPL(iio_convert_raw_to_processed); 665EXPORT_SYMBOL_GPL(iio_convert_raw_to_processed);
666 666
667static int iio_read_channel_attribute(struct iio_channel *chan, 667int iio_read_channel_attribute(struct iio_channel *chan, int *val, int *val2,
668 int *val, int *val2, 668 enum iio_chan_info_enum attribute)
669 enum iio_chan_info_enum attribute)
670{ 669{
671 int ret; 670 int ret;
672 671
@@ -682,6 +681,7 @@ err_unlock:
682 681
683 return ret; 682 return ret;
684} 683}
684EXPORT_SYMBOL_GPL(iio_read_channel_attribute);
685 685
686int iio_read_channel_offset(struct iio_channel *chan, int *val, int *val2) 686int iio_read_channel_offset(struct iio_channel *chan, int *val, int *val2)
687{ 687{
@@ -850,7 +850,8 @@ static int iio_channel_write(struct iio_channel *chan, int val, int val2,
850 chan->channel, val, val2, info); 850 chan->channel, val, val2, info);
851} 851}
852 852
853int iio_write_channel_raw(struct iio_channel *chan, int val) 853int iio_write_channel_attribute(struct iio_channel *chan, int val, int val2,
854 enum iio_chan_info_enum attribute)
854{ 855{
855 int ret; 856 int ret;
856 857
@@ -860,12 +861,18 @@ int iio_write_channel_raw(struct iio_channel *chan, int val)
860 goto err_unlock; 861 goto err_unlock;
861 } 862 }
862 863
863 ret = iio_channel_write(chan, val, 0, IIO_CHAN_INFO_RAW); 864 ret = iio_channel_write(chan, val, val2, attribute);
864err_unlock: 865err_unlock:
865 mutex_unlock(&chan->indio_dev->info_exist_lock); 866 mutex_unlock(&chan->indio_dev->info_exist_lock);
866 867
867 return ret; 868 return ret;
868} 869}
870EXPORT_SYMBOL_GPL(iio_write_channel_attribute);
871
872int iio_write_channel_raw(struct iio_channel *chan, int val)
873{
874 return iio_write_channel_attribute(chan, val, 0, IIO_CHAN_INFO_RAW);
875}
869EXPORT_SYMBOL_GPL(iio_write_channel_raw); 876EXPORT_SYMBOL_GPL(iio_write_channel_raw);
870 877
871unsigned int iio_get_channel_ext_info_count(struct iio_channel *chan) 878unsigned int iio_get_channel_ext_info_count(struct iio_channel *chan)
diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h
index 5e347a9805fd..2017f35db17c 100644
--- a/include/linux/iio/consumer.h
+++ b/include/linux/iio/consumer.h
@@ -216,6 +216,32 @@ int iio_read_channel_average_raw(struct iio_channel *chan, int *val);
216int iio_read_channel_processed(struct iio_channel *chan, int *val); 216int iio_read_channel_processed(struct iio_channel *chan, int *val);
217 217
218/** 218/**
219 * iio_write_channel_attribute() - Write values to the device attribute.
220 * @chan: The channel being queried.
221 * @val: Value being written.
222 * @val2: Value being written.val2 use depends on attribute type.
223 * @attribute: info attribute to be read.
224 *
225 * Returns an error code or 0.
226 */
227int iio_write_channel_attribute(struct iio_channel *chan, int val,
228 int val2, enum iio_chan_info_enum attribute);
229
230/**
231 * iio_read_channel_attribute() - Read values from the device attribute.
232 * @chan: The channel being queried.
233 * @val: Value being written.
234 * @val2: Value being written.Val2 use depends on attribute type.
235 * @attribute: info attribute to be written.
236 *
237 * Returns an error code if failed. Else returns a description of what is in val
238 * and val2, such as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val
239 * + val2/1e6
240 */
241int iio_read_channel_attribute(struct iio_channel *chan, int *val,
242 int *val2, enum iio_chan_info_enum attribute);
243
244/**
219 * iio_write_channel_raw() - write to a given channel 245 * iio_write_channel_raw() - write to a given channel
220 * @chan: The channel being queried. 246 * @chan: The channel being queried.
221 * @val: Value being written. 247 * @val: Value being written.
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 20b61347ea58..f12a61be1ede 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -20,34 +20,6 @@
20 * Currently assumes nano seconds. 20 * Currently assumes nano seconds.
21 */ 21 */
22 22
23enum iio_chan_info_enum {
24 IIO_CHAN_INFO_RAW = 0,
25 IIO_CHAN_INFO_PROCESSED,
26 IIO_CHAN_INFO_SCALE,
27 IIO_CHAN_INFO_OFFSET,
28 IIO_CHAN_INFO_CALIBSCALE,
29 IIO_CHAN_INFO_CALIBBIAS,
30 IIO_CHAN_INFO_PEAK,
31 IIO_CHAN_INFO_PEAK_SCALE,
32 IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW,
33 IIO_CHAN_INFO_AVERAGE_RAW,
34 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY,
35 IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY,
36 IIO_CHAN_INFO_SAMP_FREQ,
37 IIO_CHAN_INFO_FREQUENCY,
38 IIO_CHAN_INFO_PHASE,
39 IIO_CHAN_INFO_HARDWAREGAIN,
40 IIO_CHAN_INFO_HYSTERESIS,
41 IIO_CHAN_INFO_INT_TIME,
42 IIO_CHAN_INFO_ENABLE,
43 IIO_CHAN_INFO_CALIBHEIGHT,
44 IIO_CHAN_INFO_CALIBWEIGHT,
45 IIO_CHAN_INFO_DEBOUNCE_COUNT,
46 IIO_CHAN_INFO_DEBOUNCE_TIME,
47 IIO_CHAN_INFO_CALIBEMISSIVITY,
48 IIO_CHAN_INFO_OVERSAMPLING_RATIO,
49};
50
51enum iio_shared_by { 23enum iio_shared_by {
52 IIO_SEPARATE, 24 IIO_SEPARATE,
53 IIO_SHARED_BY_TYPE, 25 IIO_SHARED_BY_TYPE,
diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
index 2aa7b6384d64..6eb3d683ef62 100644
--- a/include/linux/iio/types.h
+++ b/include/linux/iio/types.h
@@ -34,4 +34,32 @@ enum iio_available_type {
34 IIO_AVAIL_RANGE, 34 IIO_AVAIL_RANGE,
35}; 35};
36 36
37enum iio_chan_info_enum {
38 IIO_CHAN_INFO_RAW = 0,
39 IIO_CHAN_INFO_PROCESSED,
40 IIO_CHAN_INFO_SCALE,
41 IIO_CHAN_INFO_OFFSET,
42 IIO_CHAN_INFO_CALIBSCALE,
43 IIO_CHAN_INFO_CALIBBIAS,
44 IIO_CHAN_INFO_PEAK,
45 IIO_CHAN_INFO_PEAK_SCALE,
46 IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW,
47 IIO_CHAN_INFO_AVERAGE_RAW,
48 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY,
49 IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY,
50 IIO_CHAN_INFO_SAMP_FREQ,
51 IIO_CHAN_INFO_FREQUENCY,
52 IIO_CHAN_INFO_PHASE,
53 IIO_CHAN_INFO_HARDWAREGAIN,
54 IIO_CHAN_INFO_HYSTERESIS,
55 IIO_CHAN_INFO_INT_TIME,
56 IIO_CHAN_INFO_ENABLE,
57 IIO_CHAN_INFO_CALIBHEIGHT,
58 IIO_CHAN_INFO_CALIBWEIGHT,
59 IIO_CHAN_INFO_DEBOUNCE_COUNT,
60 IIO_CHAN_INFO_DEBOUNCE_TIME,
61 IIO_CHAN_INFO_CALIBEMISSIVITY,
62 IIO_CHAN_INFO_OVERSAMPLING_RATIO,
63};
64
37#endif /* _IIO_TYPES_H_ */ 65#endif /* _IIO_TYPES_H_ */