Skip to contentSkip to conversation

iio: inkern: add iio_write_channel_raw

PATCH In review Dmitry Eremin-Solenikov 4 participants 5 messages Nov 26, 2014 – Dec 12, 2014 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: inkern: add iio_write_channel_raw

Introduce API for easy in-kernel setting of DAC values.

---
 drivers/iio/inkern.c         | 29 +++++++++++++++++++++++++++++
 include/linux/iio/consumer.h | 11 +++++++++++
 2 files changed, 40 insertions(+)
drivers/iio/inkern.c +29 -0
index f084610..5b03e69 100644
@@ -608,3 +608,32 @@ 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)
+{
+	int ret;
+
+	ret = chan->indio_dev->info->write_raw(chan->indio_dev,
+			chan->channel, val, val2, info);
+
+	return ret;
+}
+
+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);
include/linux/iio/consumer.h +11 -0
index 651f9a0..06f4688 100644
@@ -151,6 +151,17 @@ 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.
  * @type:		The type of the channel.
Signature · 1 line
2.1.3
#1 lore raw
Quoted 3 lines · Dmitry Eremin-Solenikov

Introduce API for easy in-kernel setting of DAC values.

Looks good...

Quoted 13 lines
---
  drivers/iio/inkern.c         | 29 +++++++++++++++++++++++++++++
  include/linux/iio/consumer.h | 11 +++++++++++
  2 files changed, 40 insertions(+)
drivers/iio/inkern.c +0 -0
index f084610..5b03e69 100644
@@ -608,3 +608,32 @@ err_unlock:
  	return ret;
  }
  EXPORT_SYMBOL_GPL(iio_get_channel_type);

drivers/iio/inkern.c err_unlock: · line 620

Quoted 10 lines
drivers/iio/inkern.c +10 -0
+
+static int iio_channel_write(struct iio_channel *chan, int val, int val2,
+	enum iio_chan_info_enum info)
+{
+	int ret;
+
+	ret = chan->indio_dev->info->write_raw(chan->indio_dev,
+			chan->channel, val, val2, info);
+
+	return ret;

... but this is something the kbuild bot tester will complain about. There is no need for the ret variable.

Quoted 1 line
drivers/iio/inkern.c +1 -0
+}
#2 lore raw
In reply to Dmitry Eremin-Solenikov

Dmitry Eremin-Solenikov schrieb am 26.11.2014 um 23:42:

Quoted 2 lines

Introduce API for easy in-kernel setting of DAC values.

Looking good in general, but indentation of parameters could be improved to align with opening parenthesis. See inline.

Quoted 11 lines
---
 drivers/iio/inkern.c         | 29 +++++++++++++++++++++++++++++
 include/linux/iio/consumer.h | 11 +++++++++++
 2 files changed, 40 insertions(+)
drivers/iio/inkern.c +0 -0
index f084610..5b03e69 100644

drivers/iio/inkern.c err_unlock: · line 613

Quoted 6 lines
drivers/iio/inkern.c +3 -0
@@ -608,3 +608,32 @@ 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)

Here.

drivers/iio/inkern.c err_unlock: · line 618

Quoted 5 lines
drivers/iio/inkern.c +5 -0
+{
+	int ret;
+
+	ret = chan->indio_dev->info->write_raw(chan->indio_dev,
+			chan->channel, val, val2, info);

Here.

Quoted 28 lines
drivers/iio/inkern.c +21 -0
+
+	return ret;
+}
+
+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);
include/linux/iio/consumer.h +0 -0
index 651f9a0..06f4688 100644
@@ -151,6 +151,17 @@ int iio_read_channel_average_raw(struct iio_channel *chan, int *val);
 int iio_read_channel_processed(struct iio_channel *chan, int *val);
 

include/linux/iio/consumer.h int iio_read_channel_average_raw(struct iio_channel *chan, int *val); · line 162

Quoted 10 lines
include/linux/iio/consumer.h +9 -0
 /**
+ * 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);

And here, everything would easily fit in just one line.

Quoted 6 lines
include/linux/iio/consumer.h +2 -0
+
+/**
  * iio_get_channel_type() - get the type of a channel
  * @channel:		The channel being queried.
  * @type:		The type of the channel.
maintainer
#3 lore raw
Quoted 6 lines · Hartmut Knaack

Dmitry Eremin-Solenikov schrieb am 26.11.2014 um 23:42:

Quoted 2 lines

Introduce API for easy in-kernel setting of DAC values.

Looking good in general, but indentation of parameters could be improved to align with opening parenthesis. See inline.

Quoted 1 line

I've fixed up both Lars and Hartmut's comments and applied to the togreg branch of iio.git - initially pushed out as testing sometime later today. Lots to catch up with first ;)

Quoted 69 lines
Quoted 10 lines
---
 drivers/iio/inkern.c         | 29 +++++++++++++++++++++++++++++
 include/linux/iio/consumer.h | 11 +++++++++++
 2 files changed, 40 insertions(+)
drivers/iio/inkern.c +0 -0
index f084610..5b03e69 100644

drivers/iio/inkern.c err_unlock: · line 613

Quoted 6 lines
drivers/iio/inkern.c +3 -0
@@ -608,3 +608,32 @@ 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)

Here.

drivers/iio/inkern.c err_unlock: · line 618

Quoted 5 lines
drivers/iio/inkern.c +5 -0
+{
+	int ret;
+
+	ret = chan->indio_dev->info->write_raw(chan->indio_dev,
+			chan->channel, val, val2, info);

Here.

Quoted 28 lines
drivers/iio/inkern.c +21 -0
+
+	return ret;
+}
+
+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);
include/linux/iio/consumer.h +0 -0
index 651f9a0..06f4688 100644
@@ -151,6 +151,17 @@ int iio_read_channel_average_raw(struct iio_channel *chan, int *val);
 int iio_read_channel_processed(struct iio_channel *chan, int *val);
 

include/linux/iio/consumer.h int iio_read_channel_average_raw(struct iio_channel *chan, int *val); · line 162

Quoted 10 lines
include/linux/iio/consumer.h +9 -0
 /**
+ * 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);

And here, everything would easily fit in just one line.

Quoted 6 lines
include/linux/iio/consumer.h +2 -0
+
+/**
  * iio_get_channel_type() - get the type of a channel
  * @channel:		The channel being queried.
  * @type:		The type of the channel.
#4 lore raw

2014-12-12 13:17 GMT+03:00 Jonathan Cameron <[email protected]>:

Quoted 10 lines · Hartmut Knaack
Quoted 6 lines

Dmitry Eremin-Solenikov schrieb am 26.11.2014 um 23:42:

Quoted 2 lines

Introduce API for easy in-kernel setting of DAC values.

Looking good in general, but indentation of parameters could be improved to align with opening parenthesis. See inline.

Quoted 1 line

I've fixed up both Lars and Hartmut's comments and applied to the togreg branch of iio.git - initially pushed out as testing sometime later today. Lots to catch up with first ;)

Thank you. I was under the pile of other patches, so didn't have time to react to those comments.

Signature · 2 lines
With best wishes
Dmitry