iio: inkern: add iio_write_channel_raw
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Wed, 26 Nov 2014 22:42:45 +0000 (01:42 +0300)
committerJonathan Cameron <jic23@kernel.org>
Fri, 12 Dec 2014 12:28:27 +0000 (12:28 +0000)
Introduce API for easy in-kernel setting of DAC values.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/inkern.c
include/linux/iio/consumer.h

index 866fe904cba29e9f9f06d26fb0da16a9ce62b4d4..21655fd1465c48c5f7f812d35ec6f477b9e4bda7 100644 (file)
@@ -631,3 +631,28 @@ err_unlock:
        return ret;
 }
 EXPORT_SYMBOL_GPL(iio_get_channel_type);
+
+static int iio_channel_write(struct iio_channel *chan, int val, int val2,
+                            enum iio_chan_info_enum info)
+{
+       return chan->indio_dev->info->write_raw(chan->indio_dev,
+                                               chan->channel, val, val2, info);
+}
+
+int iio_write_channel_raw(struct iio_channel *chan, int val)
+{
+       int ret;
+
+       mutex_lock(&chan->indio_dev->info_exist_lock);
+       if (chan->indio_dev->info == NULL) {
+               ret = -ENODEV;
+               goto err_unlock;
+       }
+
+       ret = iio_channel_write(chan, val, 0, IIO_CHAN_INFO_RAW);
+err_unlock:
+       mutex_unlock(&chan->indio_dev->info_exist_lock);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(iio_write_channel_raw);
index 651f9a0e2765fa17a4896321478c15b9997f416e..6f64624f329b4bd59320a13b7ba7c9cf96973667 100644 (file)
@@ -150,6 +150,16 @@ int iio_read_channel_average_raw(struct iio_channel *chan, int *val);
  */
 int iio_read_channel_processed(struct iio_channel *chan, int *val);
 
+/**
+ * iio_write_channel_raw() - write to a given channel
+ * @chan:              The channel being queried.
+ * @val:               Value being written.
+ *
+ * Note raw writes to iio channels are in dac counts and hence
+ * scale will need to be applied if standard units required.
+ */
+int iio_write_channel_raw(struct iio_channel *chan, int val);
+
 /**
  * iio_get_channel_type() - get the type of a channel
  * @channel:           The channel being queried.