Skip to contentSkip to conversation

IIO: core: Introduce read_raw_multi

PATCH In review Srinivas Pandruvada 4 participants 11 messages Feb 23, 2014 – Apr 7, 2014

Subsystems (3)
lore
Share & tools
lore

Srinivas Pandruvada

author maintainer
#0 lore raw

PATCH 1/5 IIO: core: Introduce read_raw_multi

This callback is introduced to overcome some limitations of existing read_raw callback. The functionality of both existing read_raw and read_raw_multi is similar, both are used to request values from the device. The current read_raw callback allows only two return values. The new read_raw_multi allows returning multiple values. Instead of passing just address of val and val2, it passes length and pointer to values. Depending on the type and length of passed buffer, iio client drivers can return multiple values.

---
 drivers/iio/iio_core.h           |  2 +-
 drivers/iio/industrialio-core.c  | 51 +++++++++++++++++++++++-----------------
 drivers/iio/industrialio-event.c |  6 +++--
 drivers/iio/inkern.c             | 15 ++++++++++--
 include/linux/iio/iio.h          | 16 +++++++++++++
 5 files changed, 63 insertions(+), 27 deletions(-)
drivers/iio/iio_core.h +1 -1
index f6db6af..4172f22 100644
@@ -35,7 +35,7 @@ int __iio_add_chan_devattr(const char *postfix,
 			   struct list_head *attr_list);
 void iio_free_chan_devattr_list(struct list_head *attr_list);
 
-ssize_t iio_format_value(char *buf, unsigned int type, int val, int val2);
+ssize_t iio_format_value(char *buf, unsigned int type, int *val);
 
 /* Event interface flags */
 #define IIO_BUSY_BIT_POS 1
drivers/iio/industrialio-core.c +29 -22

84 lines not on this page · raw message

drivers/iio/industrialio-event.c +4 -2
index c9c1419..0f7f78e 100644
@@ -272,7 +272,7 @@ static ssize_t iio_ev_value_show(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	int val, val2;
+	int val, val2, val_arr[2];
 	int ret;
 
 	ret = indio_dev->info->read_event_value(indio_dev,
@@ -281,7 +281,9 @@ static ssize_t iio_ev_value_show(struct device *dev,
 		&val, &val2);
 	if (ret < 0)
 		return ret;
-	return iio_format_value(buf, ret, val, val2);
+	val_arr[0] = val;
+	val_arr[1] = val2;
+	return iio_format_value(buf, ret, val_arr);
 }
 
 static ssize_t iio_ev_value_store(struct device *dev,
drivers/iio/inkern.c +13 -2
index 0cf5f8e..6a93d57 100644
@@ -417,12 +417,23 @@ static int iio_channel_read(struct iio_channel *chan, int *val, int *val2,
 	enum iio_chan_info_enum info)
 {
 	int unused;
+	int vals[INDIO_MAX_RAW_ELEMENTS];
+	int ret;
 
 	if (val2 == NULL)
 		val2 = &unused;
 
-	return chan->indio_dev->info->read_raw(chan->indio_dev, chan->channel,
-						val, val2, info);
+	if (chan->indio_dev->info->read_raw_multi) {
+		ret = chan->indio_dev->info->read_raw_multi(chan->indio_dev,
+					chan->channel, INDIO_MAX_RAW_ELEMENTS,
+					vals, info);
+		*val = vals[0];
+		*val2 = vals[1];
+	} else
+		ret = chan->indio_dev->info->read_raw(chan->indio_dev,
+					chan->channel, val, val2, info);
+
+	return ret;
 }
 
 int iio_read_channel_raw(struct iio_channel *chan, int *val)
include/linux/iio/iio.h +16 -0
index 75a8a20..ddf9f60 100644
@@ -284,6 +284,8 @@ static inline s64 iio_get_time_ns(void)
 #define INDIO_ALL_BUFFER_MODES					\
 	(INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE)
 
+#define INDIO_MAX_RAW_ELEMENTS		4
+
 struct iio_trigger; /* forward declaration */
 struct iio_dev;
 
@@ -298,6 +300,14 @@ struct iio_dev;
  *			the channel in question.  Return value will specify the
  *			type of value returned by the device. val and val2 will
  *			contain the elements making up the returned value.
+ * @read_raw_multi:	function to return values from the device.
+ *			mask specifies which value. Note 0 means a reading of
+ *			the channel in question.  Return value will specify the
+ *			type of value returned by the device. vals pointer
+ *			contain the elements making up the returned value.
+ *			val_len specifies maximum number of elements
+ *			vals pointer can contain. In contrast to to read_raw
+ *			device can return multiple values not just two.
  * @write_raw:		function to write a value to the device.
  *			Parameters are the same as for read_raw.
  * @write_raw_get_fmt:	callback function to query the expected
@@ -324,6 +334,12 @@ struct iio_info {
 			int *val2,
 			long mask);
 
+	int (*read_raw_multi)(struct iio_dev *indio_dev,
+			struct iio_chan_spec const *chan,
+			int val_len,
+			int *vals,
+			long mask);
+
 	int (*write_raw)(struct iio_dev *indio_dev,
 			 struct iio_chan_spec const *chan,
 			 int val,
Signature · 1 line
1.8.3.2
author maintainer
#1 lore raw

PATCH 2/5 IIO: core: Modify scan element type

The current scan element type uses the following format:
[be|le]:[s|u]bits/storagebits[>>shift].
To specify multiple elements in this type, added a repeat value. So new format is:
[be|le]:([s|u]bits/storagebits){repeat}[>>shift].
Here repeat is specifying how may times, real/storage bits are repeating.

When repeat is value is 0 or 1, then repeat value is not used in the format, and it will be same as existing format.

---
 drivers/iio/industrialio-buffer.c | 41 +++++++++++++++++++++++++++++++++------
 include/linux/iio/iio.h           |  9 +++++++++
 2 files changed, 44 insertions(+), 6 deletions(-)
drivers/iio/industrialio-buffer.c +35 -6
index c67d83b..598eacd 100644
@@ -150,7 +150,16 @@ static ssize_t iio_show_fixed_type(struct device *dev,
 		type = IIO_BE;
 #endif
 	}
-	return sprintf(buf, "%s:%c%d/%d>>%u\n",
+	if (this_attr->c->scan_type.repeat > 1)
+		return sprintf(buf, "%s:(%c%d/%d){%d}>>%u\n",
+		       iio_endian_prefix[type],
+		       this_attr->c->scan_type.sign,
+		       this_attr->c->scan_type.realbits,
+		       this_attr->c->scan_type.storagebits,
+		       this_attr->c->scan_type.repeat,
+		       this_attr->c->scan_type.shift);
+		else
+			return sprintf(buf, "%s:%c%d/%d>>%u\n",
 		       iio_endian_prefix[type],
 		       this_attr->c->scan_type.sign,
 		       this_attr->c->scan_type.realbits,
@@ -475,14 +484,22 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev,
 	for_each_set_bit(i, mask,
 			 indio_dev->masklength) {
 		ch = iio_find_channel_from_si(indio_dev, i);
-		length = ch->scan_type.storagebits / 8;
+		if (ch->scan_type.repeat > 1)
+			length = ch->scan_type.storagebits / 8 *
+				ch->scan_type.repeat;
+		else
+			length = ch->scan_type.storagebits / 8;
 		bytes = ALIGN(bytes, length);
 		bytes += length;
 	}
 	if (timestamp) {
 		ch = iio_find_channel_from_si(indio_dev,
 					      indio_dev->scan_index_timestamp);
-		length = ch->scan_type.storagebits / 8;
+		if (ch->scan_type.repeat > 1)
+			length = ch->scan_type.storagebits / 8 *
+				ch->scan_type.repeat;
+		else
+			length = ch->scan_type.storagebits / 8;
 		bytes = ALIGN(bytes, length);
 		bytes += length;
 	}
@@ -961,7 +978,11 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
 					       indio_dev->masklength,
 					       in_ind + 1);
 			ch = iio_find_channel_from_si(indio_dev, in_ind);
-			length = ch->scan_type.storagebits/8;
+			if (ch->scan_type.repeat > 1)
+				length = ch->scan_type.storagebits / 8 *
+					ch->scan_type.repeat;
+			else
+				length = ch->scan_type.storagebits / 8;
 			/* Make sure we are aligned */
 			in_loc += length;
 			if (in_loc % length)
@@ -973,7 +994,11 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
 			goto error_clear_mux_table;
 		}
 		ch = iio_find_channel_from_si(indio_dev, in_ind);
-		length = ch->scan_type.storagebits/8;
+		if (ch->scan_type.repeat > 1)
+			length = ch->scan_type.storagebits / 8 *
+				ch->scan_type.repeat;
+		else
+			length = ch->scan_type.storagebits / 8;
 		if (out_loc % length)
 			out_loc += length - out_loc % length;
 		if (in_loc % length)
@@ -994,7 +1019,11 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
 		}
 		ch = iio_find_channel_from_si(indio_dev,
 			indio_dev->scan_index_timestamp);
-		length = ch->scan_type.storagebits/8;
+		if (ch->scan_type.repeat > 1)
+			length = ch->scan_type.storagebits / 8 *
+				ch->scan_type.repeat;
+		else
+			length = ch->scan_type.storagebits / 8;
 		if (out_loc % length)
 			out_loc += length - out_loc % length;
 		if (in_loc % length)
include/linux/iio/iio.h +9 -0
index ddf9f60..3f1a83c 100644
@@ -177,6 +177,14 @@ struct iio_event_spec {
  *			shift:		Shift right by this before masking out
  *					realbits.
  *			endianness:	little or big endian
+ *			repeat:		No. of times real/storage bits repeats.
+ *					By default, when repeat is set to 0
+ *					repeat value is treated as 1. When
+ *					repeat value is 0 or 1, then there is
+ *					no change in existing scan element
+ *					type, in sysfs. When set to more than
+ *					1, then the type element in sysfs will
+ *					show repeat value.
  * @info_mask_separate: What information is to be exported that is specific to
  *			this channel.
  * @info_mask_shared_by_type: What information is to be exported that is shared
@@ -219,6 +227,7 @@ struct iio_chan_spec {
 		u8	realbits;
 		u8	storagebits;
 		u8	shift;
+		u8	repeat;
 		enum iio_endian endianness;
 	} scan_type;
 	long			info_mask_separate;
Signature · 1 line
1.8.3.2
author maintainer
#2 lore raw

PATCH 3/5 IIO: core: Introduce Quaternion types

In reply to Srinivas Pandruvada

Introduced IIO_VAL_QUATERNION and its formatting. Format used here:
x:y:z:w
In addition IIO_QUAT_ROT is added to the channel type and name.

---
 drivers/iio/industrialio-core.c | 4 ++++
 include/linux/iio/types.h       | 2 ++
 2 files changed, 6 insertions(+)
drivers/iio/industrialio-core.c +4 -0
index b1225a4..69aaa7a 100644
@@ -70,6 +70,7 @@ static const char * const iio_chan_type_name_spec[] = {
 	[IIO_CCT] = "cct",
 	[IIO_PRESSURE] = "pressure",
 	[IIO_HUMIDITYRELATIVE] = "humidityrelative",
+	[IIO_QUAT_ROT] = "rotquaternion",
 };
 
 static const char * const iio_modifier_names[] = {
@@ -409,6 +410,9 @@ ssize_t iio_format_value(char *buf, unsigned int type, int *vals)
 		vals[1] = do_div(tmp, 1000000000LL);
 		vals[0] = tmp;
 		return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
+	case IIO_VAL_QUATERNION:
+		return sprintf(buf, "%d:%d:%d:%d\n", vals[0], vals[1], vals[2],
+							vals[3]);
 	default:
 		return 0;
 	}
include/linux/iio/types.h +2 -0
index 084d882..256ad2d 100644
@@ -30,6 +30,7 @@ enum iio_chan_type {
 	IIO_CCT,
 	IIO_PRESSURE,
 	IIO_HUMIDITYRELATIVE,
+	IIO_QUAT_ROT,
 };
 
 enum iio_modifier {
@@ -79,6 +80,7 @@ enum iio_event_direction {
 #define IIO_VAL_INT_PLUS_MICRO 2
 #define IIO_VAL_INT_PLUS_NANO 3
 #define IIO_VAL_INT_PLUS_MICRO_DB 4
+#define IIO_VAL_QUATERNION 5
 #define IIO_VAL_FRACTIONAL 10
 #define IIO_VAL_FRACTIONAL_LOG2 11
 
Signature · 1 line
1.8.3.2
author maintainer
#3 lore raw

PATCH 4/5 iio: hid-sensors: Added device rotation support

In reply to Srinivas Pandruvada

Added usage id processing for device rotation. This uses IIO interfaces for triggered buffer to present data to user mode.This uses HID sensor framework for registering callback events from the sensor hub.
Data is exported to user space in the form of quaternion rotation format.

---
 drivers/iio/orientation/Kconfig               |  11 +
 drivers/iio/orientation/Makefile              |   1 +
 drivers/iio/orientation/hid-sensor-rotation.c | 358 ++++++++++++++++++++++++++
 include/linux/hid-sensor-ids.h                |   1 +
 4 files changed, 371 insertions(+)
 create mode 100644 drivers/iio/orientation/hid-sensor-rotation.c
drivers/iio/orientation/Kconfig +11 -0
index 58c62c8..da8bd8a 100644
@@ -16,4 +16,15 @@ config HID_SENSOR_INCLINOMETER_3D
 	  Say yes here to build support for the HID SENSOR
 	  Inclinometer 3D.
 
+config HID_SENSOR_DEVICE_ROTATION
+	depends on HID_SENSOR_HUB
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	select HID_SENSOR_IIO_COMMON
+	select HID_SENSOR_IIO_TRIGGER
+	tristate "HID Device Rotation"
+	help
+	  Say yes here to build support for the HID SENSOR
+	  device rotation.
+
 endmenu
drivers/iio/orientation/Makefile +1 -0
index 2c97572..4734dab 100644
@@ -4,3 +4,4 @@
 
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_HID_SENSOR_INCLINOMETER_3D) += hid-sensor-incl-3d.o
+obj-$(CONFIG_HID_SENSOR_DEVICE_ROTATION) += hid-sensor-rotation.o
drivers/iio/orientation/hid-sensor-rotation.c new file +358 -0

358 lines not on this page · raw message

include/linux/hid-sensor-ids.h +1 -0
index beaf965..3fc44a0 100644
@@ -66,6 +66,7 @@
 #define HID_USAGE_SENSOR_ORIENT_TILT_Y				0x200480
 #define HID_USAGE_SENSOR_ORIENT_TILT_Z				0x200481
 
+#define HID_USAGE_SENSOR_DEVICE_ORIENTATION			0x20008A
 #define HID_USAGE_SENSOR_ORIENT_ROTATION_MATRIX			0x200482
 #define HID_USAGE_SENSOR_ORIENT_QUATERNION			0x200483
 #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX			0x200484
Signature · 1 line
1.8.3.2
author maintainer
#4 lore raw

PATCH 5/5 iio: Added ABI description for quaternion

In reply to Srinivas Pandruvada

Added documentation for reading quaternion components for 3D rotations.

---
 Documentation/ABI/testing/sysfs-bus-iio | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/ABI/testing/sysfs-bus-iio +9 -0
index 6e02c50..8daa91a 100644
@@ -891,3 +891,12 @@ Contact:	[email protected]
 Description:
 		This attribute is used to get/set the integration time in
 		seconds.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_rotquaternion_raw
+KernelVersion:	3.15
+Contact:	[email protected]
+Description:
+		Raw value of quaternion components using a format
+		x:y:z:w. Here x, y, and z component represents the axis about
+		which a rotation will occur and w component represents the
+		amount of rotation.
Signature · 1 line
1.8.3.2
maintainer
#5 lore raw
In reply to Srinivas Pandruvada
Quoted 10 lines · Srinivas Pandruvada

This callback is introduced to overcome some limitations of existing read_raw callback. The functionality of both existing read_raw and read_raw_multi is similar, both are used to request values from the device. The current read_raw callback allows only two return values. The new read_raw_multi allows returning multiple values. Instead of passing just address of val and val2, it passes length and pointer to values. Depending on the type and length of passed buffer, iio client drivers can return multiple values.

Hi Srinivas.

Whilst it wasn't the most in depth of discussions, I think the outcome of the 'how to handle quaternion sysfs naming' element of the thread.
[RFC] IIO: New interfaces for 'interesting' channel types.

was that we should do them as a modifier instead of a new channel type. e.g.

in_rot_quaternion_raw
etc.

Could you convert this driver over and repost?

If you disagree, then feel free to contribute to that discussion and we'll continue from there.

Sorry this took so long to sort out, I was hoping for a few more inputs but there we are...

Jonathan

Quoted 207 lines
---
  drivers/iio/iio_core.h           |  2 +-
  drivers/iio/industrialio-core.c  | 51 +++++++++++++++++++++++-----------------
  drivers/iio/industrialio-event.c |  6 +++--
  drivers/iio/inkern.c             | 15 ++++++++++--
  include/linux/iio/iio.h          | 16 +++++++++++++
  5 files changed, 63 insertions(+), 27 deletions(-)
drivers/iio/iio_core.h +1 -1
index f6db6af..4172f22 100644
@@ -35,7 +35,7 @@ int __iio_add_chan_devattr(const char *postfix,
  			   struct list_head *attr_list);
  void iio_free_chan_devattr_list(struct list_head *attr_list);
 
-ssize_t iio_format_value(char *buf, unsigned int type, int val, int val2);
+ssize_t iio_format_value(char *buf, unsigned int type, int *val);
 
  /* Event interface flags */
  #define IIO_BUSY_BIT_POS 1
drivers/iio/industrialio-core.c +29 -22
index acc911a..b1225a4 100644
@@ -373,41 +373,42 @@ EXPORT_SYMBOL_GPL(iio_enum_write);
   * @buf: The buffer to which the formated value gets written
   * @type: One of the IIO_VAL_... constants. This decides how the val and val2
   *        parameters are formatted.
- * @val: First part of the value, exact meaning depends on the type parameter.
- * @val2: Second part of the value, exact meaning depends on the type parameter.
+ * @vals: pointer to the values, exact meaning depends on the type parameter.
   */
-ssize_t iio_format_value(char *buf, unsigned int type, int val, int val2)
+ssize_t iio_format_value(char *buf, unsigned int type, int *vals)
  {
  	unsigned long long tmp;
  	bool scale_db = false;
 
  	switch (type) {
  	case IIO_VAL_INT:
-		return sprintf(buf, "%d\n", val);
+		return sprintf(buf, "%d\n", vals[0]);
  	case IIO_VAL_INT_PLUS_MICRO_DB:
  		scale_db = true;
  	case IIO_VAL_INT_PLUS_MICRO:
-		if (val2 < 0)
-			return sprintf(buf, "-%ld.%06u%s\n", abs(val), -val2,
+		if (vals[1] < 0)
+			return sprintf(buf, "-%ld.%06u%s\n", abs(vals[0]),
+					-vals[1],
  				scale_db ? " dB" : "");
  		else
-			return sprintf(buf, "%d.%06u%s\n", val, val2,
+			return sprintf(buf, "%d.%06u%s\n", vals[0], vals[1],
  				scale_db ? " dB" : "");
  	case IIO_VAL_INT_PLUS_NANO:
-		if (val2 < 0)
-			return sprintf(buf, "-%ld.%09u\n", abs(val), -val2);
+		if (vals[1] < 0)
+			return sprintf(buf, "-%ld.%09u\n", abs(vals[0]),
+					-vals[1]);
  		else
-			return sprintf(buf, "%d.%09u\n", val, val2);
+			return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
  	case IIO_VAL_FRACTIONAL:
-		tmp = div_s64((s64)val * 1000000000LL, val2);
-		val2 = do_div(tmp, 1000000000LL);
-		val = tmp;
-		return sprintf(buf, "%d.%09u\n", val, val2);
+		tmp = div_s64((s64)vals[0] * 1000000000LL, vals[1]);
+		vals[1] = do_div(tmp, 1000000000LL);
+		vals[0] = tmp;
+		return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
  	case IIO_VAL_FRACTIONAL_LOG2:
-		tmp = (s64)val * 1000000000LL >> val2;
-		val2 = do_div(tmp, 1000000000LL);
-		val = tmp;
-		return sprintf(buf, "%d.%09u\n", val, val2);
+		tmp = (s64)vals[0] * 1000000000LL >> vals[1];
+		vals[1] = do_div(tmp, 1000000000LL);
+		vals[0] = tmp;
+		return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
  	default:
  		return 0;
  	}
@@ -419,14 +420,20 @@ static ssize_t iio_read_channel_info(struct device *dev,
  {
  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
  	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	int val, val2;
-	int ret = indio_dev->info->read_raw(indio_dev, this_attr->c,
-					    &val, &val2, this_attr->address);
+	int vals[INDIO_MAX_RAW_ELEMENTS];
+	int ret;
+
+	if (indio_dev->info->read_raw_multi)
+		ret = indio_dev->info->read_raw_multi(indio_dev, this_attr->c,
+			    INDIO_MAX_RAW_ELEMENTS, vals, this_attr->address);
+	else
+		ret = indio_dev->info->read_raw(indio_dev, this_attr->c,
+				    &vals[0], &vals[1], this_attr->address);
 
  	if (ret < 0)
  		return ret;
 
-	return iio_format_value(buf, ret, val, val2);
+	return iio_format_value(buf, ret, vals);
  }
 
  /**
drivers/iio/industrialio-event.c +4 -2
index c9c1419..0f7f78e 100644
@@ -272,7 +272,7 @@ static ssize_t iio_ev_value_show(struct device *dev,
  {
  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
  	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	int val, val2;
+	int val, val2, val_arr[2];
  	int ret;
 
  	ret = indio_dev->info->read_event_value(indio_dev,
@@ -281,7 +281,9 @@ static ssize_t iio_ev_value_show(struct device *dev,
  		&val, &val2);
  	if (ret < 0)
  		return ret;
-	return iio_format_value(buf, ret, val, val2);
+	val_arr[0] = val;
+	val_arr[1] = val2;
+	return iio_format_value(buf, ret, val_arr);
  }
 
  static ssize_t iio_ev_value_store(struct device *dev,
drivers/iio/inkern.c +13 -2
index 0cf5f8e..6a93d57 100644
@@ -417,12 +417,23 @@ static int iio_channel_read(struct iio_channel *chan, int *val, int *val2,
  	enum iio_chan_info_enum info)
  {
  	int unused;
+	int vals[INDIO_MAX_RAW_ELEMENTS];
+	int ret;
 
  	if (val2 == NULL)
  		val2 = &unused;
 
-	return chan->indio_dev->info->read_raw(chan->indio_dev, chan->channel,
-						val, val2, info);
+	if (chan->indio_dev->info->read_raw_multi) {
+		ret = chan->indio_dev->info->read_raw_multi(chan->indio_dev,
+					chan->channel, INDIO_MAX_RAW_ELEMENTS,
+					vals, info);
+		*val = vals[0];
+		*val2 = vals[1];
+	} else
+		ret = chan->indio_dev->info->read_raw(chan->indio_dev,
+					chan->channel, val, val2, info);
+
+	return ret;
  }
 
  int iio_read_channel_raw(struct iio_channel *chan, int *val)
include/linux/iio/iio.h +16 -0
index 75a8a20..ddf9f60 100644
@@ -284,6 +284,8 @@ static inline s64 iio_get_time_ns(void)
  #define INDIO_ALL_BUFFER_MODES					\
  	(INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE)
 
+#define INDIO_MAX_RAW_ELEMENTS		4
+
  struct iio_trigger; /* forward declaration */
  struct iio_dev;
 
@@ -298,6 +300,14 @@ struct iio_dev;
   *			the channel in question.  Return value will specify the
   *			type of value returned by the device. val and val2 will
   *			contain the elements making up the returned value.
+ * @read_raw_multi:	function to return values from the device.
+ *			mask specifies which value. Note 0 means a reading of
+ *			the channel in question.  Return value will specify the
+ *			type of value returned by the device. vals pointer
+ *			contain the elements making up the returned value.
+ *			val_len specifies maximum number of elements
+ *			vals pointer can contain. In contrast to to read_raw
+ *			device can return multiple values not just two.
   * @write_raw:		function to write a value to the device.
   *			Parameters are the same as for read_raw.
   * @write_raw_get_fmt:	callback function to query the expected
@@ -324,6 +334,12 @@ struct iio_info {
  			int *val2,
  			long mask);
 
+	int (*read_raw_multi)(struct iio_dev *indio_dev,
+			struct iio_chan_spec const *chan,
+			int val_len,
+			int *vals,
+			long mask);
+
  	int (*write_raw)(struct iio_dev *indio_dev,
  			 struct iio_chan_spec const *chan,
  			 int val,
author maintainer
#6 lore raw
Quoted 24 lines · Jonathan Cameron
Quoted 10 lines · Srinivas Pandruvada

This callback is introduced to overcome some limitations of existing read_raw callback. The functionality of both existing read_raw and read_raw_multi is similar, both are used to request values from the device. The current read_raw callback allows only two return values. The new read_raw_multi allows returning multiple values. Instead of passing just address of val and val2, it passes length and pointer to values. Depending on the type and length of passed buffer, iio client drivers can return multiple values.

Hi Srinivas.

Whilst it wasn't the most in depth of discussions, I think the outcome of the 'how to handle quaternion sysfs naming' element of the thread.
[RFC] IIO: New interfaces for 'interesting' channel types.

was that we should do them as a modifier instead of a new channel type. e.g.

in_rot_quaternion_raw
etc.

Quoted 8 lines

Could you convert this driver over and repost?

If you disagree, then feel free to contribute to that discussion and we'll continue from there.

Sorry this took so long to sort out, I was hoping for a few more inputs but there we are...

Hi Jonathan,

I have resubmitted with the modifier for quaternion dropping this patch. I only allow buffered mode as without this patch representing in raw mode all four component is not possible. Current applications only is using buffer mode. So I can wait for core support something similar to this patch.

Thanks,
Srinivas

Quoted 220 lines

Jonathan

Quoted 217 lines
---
  drivers/iio/iio_core.h           |  2 +-
  drivers/iio/industrialio-core.c  | 51 
+++++++++++++++++++++++-----------------
  drivers/iio/industrialio-event.c |  6 +++--
  drivers/iio/inkern.c             | 15 ++++++++++--
  include/linux/iio/iio.h          | 16 +++++++++++++
  5 files changed, 63 insertions(+), 27 deletions(-)
drivers/iio/iio_core.h +1 -1
index f6db6af..4172f22 100644
@@ -35,7 +35,7 @@ int __iio_add_chan_devattr(const char *postfix,
                 struct list_head *attr_list);
  void iio_free_chan_devattr_list(struct list_head *attr_list);
 
-ssize_t iio_format_value(char *buf, unsigned int type, int val, int 
 val2);
+ssize_t iio_format_value(char *buf, unsigned int type, int *val);
 
  /* Event interface flags */
  #define IIO_BUSY_BIT_POS 1
drivers/iio/industrialio-core.c +0 -0
index acc911a..b1225a4 100644
@@ -373,41 +373,42 @@ EXPORT_SYMBOL_GPL(iio_enum_write);
   * @buf: The buffer to which the formated value gets written
   * @type: One of the IIO_VAL_... constants. This decides how the 

val and val2
* parameters are formatted.
- * @val: First part of the value, exact meaning depends on the type parameter.
- * @val2: Second part of the value, exact meaning depends on the type parameter.
+ * @vals: pointer to the values, exact meaning depends on the type parameter.
*/
-ssize_t iio_format_value(char *buf, unsigned int type, int val, int val2)

drivers/iio/industrialio-core.c +28 -19
+ssize_t iio_format_value(char *buf, unsigned int type, int *vals)
  {
      unsigned long long tmp;
      bool scale_db = false;
 
      switch (type) {
      case IIO_VAL_INT:
-        return sprintf(buf, "%d\n", val);
+        return sprintf(buf, "%d\n", vals[0]);
      case IIO_VAL_INT_PLUS_MICRO_DB:
          scale_db = true;
      case IIO_VAL_INT_PLUS_MICRO:
-        if (val2 < 0)
-            return sprintf(buf, "-%ld.%06u%s\n", abs(val), -val2,
+        if (vals[1] < 0)
+            return sprintf(buf, "-%ld.%06u%s\n", abs(vals[0]),
+                    -vals[1],
                  scale_db ? " dB" : "");
          else
-            return sprintf(buf, "%d.%06u%s\n", val, val2,
+            return sprintf(buf, "%d.%06u%s\n", vals[0], vals[1],
                  scale_db ? " dB" : "");
      case IIO_VAL_INT_PLUS_NANO:
-        if (val2 < 0)
-            return sprintf(buf, "-%ld.%09u\n", abs(val), -val2);
+        if (vals[1] < 0)
+            return sprintf(buf, "-%ld.%09u\n", abs(vals[0]),
+                    -vals[1]);
          else
-            return sprintf(buf, "%d.%09u\n", val, val2);
+            return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
      case IIO_VAL_FRACTIONAL:
-        tmp = div_s64((s64)val * 1000000000LL, val2);
-        val2 = do_div(tmp, 1000000000LL);
-        val = tmp;
-        return sprintf(buf, "%d.%09u\n", val, val2);
+        tmp = div_s64((s64)vals[0] * 1000000000LL, vals[1]);
+        vals[1] = do_div(tmp, 1000000000LL);
+        vals[0] = tmp;
+        return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
      case IIO_VAL_FRACTIONAL_LOG2:
-        tmp = (s64)val * 1000000000LL >> val2;
-        val2 = do_div(tmp, 1000000000LL);
-        val = tmp;
-        return sprintf(buf, "%d.%09u\n", val, val2);
+        tmp = (s64)vals[0] * 1000000000LL >> vals[1];
+        vals[1] = do_div(tmp, 1000000000LL);
+        vals[0] = tmp;
+        return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
      default:
          return 0;
      }
@@ -419,14 +420,20 @@ static ssize_t iio_read_channel_info(struct 
 device *dev,
  {
      struct iio_dev *indio_dev = dev_to_iio_dev(dev);
      struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-    int val, val2;
-    int ret = indio_dev->info->read_raw(indio_dev, this_attr->c,
-                        &val, &val2, this_attr->address);
+    int vals[INDIO_MAX_RAW_ELEMENTS];
+    int ret;
+
+    if (indio_dev->info->read_raw_multi)
+        ret = indio_dev->info->read_raw_multi(indio_dev, this_attr->c,
+                INDIO_MAX_RAW_ELEMENTS, vals, this_attr->address);
+    else
+        ret = indio_dev->info->read_raw(indio_dev, this_attr->c,
+                    &vals[0], &vals[1], this_attr->address);
 
      if (ret < 0)
          return ret;
 
-    return iio_format_value(buf, ret, val, val2);
+    return iio_format_value(buf, ret, vals);
  }
 

/**

drivers/iio/industrialio-event.c +4 -2
index c9c1419..0f7f78e 100644
@@ -272,7 +272,7 @@ static ssize_t iio_ev_value_show(struct device *dev,
  {
      struct iio_dev *indio_dev = dev_to_iio_dev(dev);
      struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-    int val, val2;
+    int val, val2, val_arr[2];
      int ret;
 
      ret = indio_dev->info->read_event_value(indio_dev,
@@ -281,7 +281,9 @@ static ssize_t iio_ev_value_show(struct device *dev,
          &val, &val2);
      if (ret < 0)
          return ret;
-    return iio_format_value(buf, ret, val, val2);
+    val_arr[0] = val;
+    val_arr[1] = val2;
+    return iio_format_value(buf, ret, val_arr);
  }
 
  static ssize_t iio_ev_value_store(struct device *dev,
drivers/iio/inkern.c +13 -2
index 0cf5f8e..6a93d57 100644
@@ -417,12 +417,23 @@ static int iio_channel_read(struct iio_channel 
 *chan, int *val, int *val2,
      enum iio_chan_info_enum info)
  {
      int unused;
+    int vals[INDIO_MAX_RAW_ELEMENTS];
+    int ret;
 
      if (val2 == NULL)
          val2 = &unused;
 
-    return chan->indio_dev->info->read_raw(chan->indio_dev, 
 chan->channel,
-                        val, val2, info);
+    if (chan->indio_dev->info->read_raw_multi) {
+        ret = chan->indio_dev->info->read_raw_multi(chan->indio_dev,
+                    chan->channel, INDIO_MAX_RAW_ELEMENTS,
+                    vals, info);
+        *val = vals[0];
+        *val2 = vals[1];
+    } else
+        ret = chan->indio_dev->info->read_raw(chan->indio_dev,
+                    chan->channel, val, val2, info);
+
+    return ret;
  }

int iio_read_channel_raw(struct iio_channel *chan, int *val)

include/linux/iio/iio.h +16 -0
index 75a8a20..ddf9f60 100644
@@ -284,6 +284,8 @@ static inline s64 iio_get_time_ns(void)
  #define INDIO_ALL_BUFFER_MODES                    \
      (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE)
 
+#define INDIO_MAX_RAW_ELEMENTS        4
+
  struct iio_trigger; /* forward declaration */
  struct iio_dev;
 
@@ -298,6 +300,14 @@ struct iio_dev;
   *            the channel in question.  Return value will specify the
   *            type of value returned by the device. val and val2 will
   *            contain the elements making up the returned value.
+ * @read_raw_multi:    function to return values from the device.
+ *            mask specifies which value. Note 0 means a reading of
+ *            the channel in question.  Return value will specify the
+ *            type of value returned by the device. vals pointer
+ *            contain the elements making up the returned value.
+ *            val_len specifies maximum number of elements
+ *            vals pointer can contain. In contrast to to read_raw
+ *            device can return multiple values not just two.
   * @write_raw:        function to write a value to the device.
   *            Parameters are the same as for read_raw.
   * @write_raw_get_fmt:    callback function to query the expected
@@ -324,6 +334,12 @@ struct iio_info {
              int *val2,
              long mask);
 
+    int (*read_raw_multi)(struct iio_dev *indio_dev,
+            struct iio_chan_spec const *chan,
+            int val_len,
+            int *vals,
+            long mask);
+
      int (*write_raw)(struct iio_dev *indio_dev,
               struct iio_chan_spec const *chan,
               int val,
maintainer
#7 lore raw
Quoted 35 lines · Srinivas Pandruvada
Quoted 24 lines · Jonathan Cameron
Quoted 10 lines · Srinivas Pandruvada

This callback is introduced to overcome some limitations of existing read_raw callback. The functionality of both existing read_raw and read_raw_multi is similar, both are used to request values from the device. The current read_raw callback allows only two return values. The new read_raw_multi allows returning multiple values. Instead of passing just address of val and val2, it passes length and pointer to values. Depending on the type and length of passed buffer, iio client drivers can return multiple values.

Hi Srinivas.

Whilst it wasn't the most in depth of discussions, I think the outcome of the 'how to handle quaternion sysfs naming' element of the thread.
[RFC] IIO: New interfaces for 'interesting' channel types.

was that we should do them as a modifier instead of a new channel type. e.g.

in_rot_quaternion_raw
etc.

Quoted 8 lines

Could you convert this driver over and repost?

If you disagree, then feel free to contribute to that discussion and we'll continue from there.

Sorry this took so long to sort out, I was hoping for a few more inputs but there we are...

Hi Jonathan,

Quoted 7 lines

I have resubmitted with the modifier for quaternion dropping this patch. I only allow buffered mode as without this patch representing in raw mode all four component is not possible. Current applications only is using buffer mode. So I can wait for core support something similar to this patch.

Thanks,
Srinivas

Hi Srinivas,

I'm a bit lost on this. I was quite happy with this patch and can't immediately see why the change to using a modifier requires dropping it?

It just makes for slightly different handling in the read_raw_multi call inside the driver itself...

or am I missing something...

Jonathan

Quoted 219 lines
Quoted 202 lines

Jonathan

Quoted 197 lines
---
  drivers/iio/iio_core.h           |  2 +-
  drivers/iio/industrialio-core.c  | 51 +++++++++++++++++++++++-----------------
  drivers/iio/industrialio-event.c |  6 +++--
  drivers/iio/inkern.c             | 15 ++++++++++--
  include/linux/iio/iio.h          | 16 +++++++++++++
  5 files changed, 63 insertions(+), 27 deletions(-)
drivers/iio/iio_core.h +1 -1
index f6db6af..4172f22 100644
@@ -35,7 +35,7 @@ int __iio_add_chan_devattr(const char *postfix,
                 struct list_head *attr_list);
  void iio_free_chan_devattr_list(struct list_head *attr_list);
 
-ssize_t iio_format_value(char *buf, unsigned int type, int val, int val2);
+ssize_t iio_format_value(char *buf, unsigned int type, int *val);
 
  /* Event interface flags */
  #define IIO_BUSY_BIT_POS 1
drivers/iio/industrialio-core.c +29 -22
index acc911a..b1225a4 100644
@@ -373,41 +373,42 @@ EXPORT_SYMBOL_GPL(iio_enum_write);
   * @buf: The buffer to which the formated value gets written
   * @type: One of the IIO_VAL_... constants. This decides how the val and val2
   *        parameters are formatted.
- * @val: First part of the value, exact meaning depends on the type parameter.
- * @val2: Second part of the value, exact meaning depends on the type parameter.
+ * @vals: pointer to the values, exact meaning depends on the type parameter.
   */
-ssize_t iio_format_value(char *buf, unsigned int type, int val, int val2)
+ssize_t iio_format_value(char *buf, unsigned int type, int *vals)
  {
      unsigned long long tmp;
      bool scale_db = false;
 
      switch (type) {
      case IIO_VAL_INT:
-        return sprintf(buf, "%d\n", val);
+        return sprintf(buf, "%d\n", vals[0]);
      case IIO_VAL_INT_PLUS_MICRO_DB:
          scale_db = true;
      case IIO_VAL_INT_PLUS_MICRO:
-        if (val2 < 0)
-            return sprintf(buf, "-%ld.%06u%s\n", abs(val), -val2,
+        if (vals[1] < 0)
+            return sprintf(buf, "-%ld.%06u%s\n", abs(vals[0]),
+                    -vals[1],
                  scale_db ? " dB" : "");
          else
-            return sprintf(buf, "%d.%06u%s\n", val, val2,
+            return sprintf(buf, "%d.%06u%s\n", vals[0], vals[1],
                  scale_db ? " dB" : "");
      case IIO_VAL_INT_PLUS_NANO:
-        if (val2 < 0)
-            return sprintf(buf, "-%ld.%09u\n", abs(val), -val2);
+        if (vals[1] < 0)
+            return sprintf(buf, "-%ld.%09u\n", abs(vals[0]),
+                    -vals[1]);
          else
-            return sprintf(buf, "%d.%09u\n", val, val2);
+            return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
      case IIO_VAL_FRACTIONAL:
-        tmp = div_s64((s64)val * 1000000000LL, val2);
-        val2 = do_div(tmp, 1000000000LL);
-        val = tmp;
-        return sprintf(buf, "%d.%09u\n", val, val2);
+        tmp = div_s64((s64)vals[0] * 1000000000LL, vals[1]);
+        vals[1] = do_div(tmp, 1000000000LL);
+        vals[0] = tmp;
+        return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
      case IIO_VAL_FRACTIONAL_LOG2:
-        tmp = (s64)val * 1000000000LL >> val2;
-        val2 = do_div(tmp, 1000000000LL);
-        val = tmp;
-        return sprintf(buf, "%d.%09u\n", val, val2);
+        tmp = (s64)vals[0] * 1000000000LL >> vals[1];
+        vals[1] = do_div(tmp, 1000000000LL);
+        vals[0] = tmp;
+        return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
      default:
          return 0;
      }
@@ -419,14 +420,20 @@ static ssize_t iio_read_channel_info(struct device *dev,
  {
      struct iio_dev *indio_dev = dev_to_iio_dev(dev);
      struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-    int val, val2;
-    int ret = indio_dev->info->read_raw(indio_dev, this_attr->c,
-                        &val, &val2, this_attr->address);
+    int vals[INDIO_MAX_RAW_ELEMENTS];
+    int ret;
+
+    if (indio_dev->info->read_raw_multi)
+        ret = indio_dev->info->read_raw_multi(indio_dev, this_attr->c,
+                INDIO_MAX_RAW_ELEMENTS, vals, this_attr->address);
+    else
+        ret = indio_dev->info->read_raw(indio_dev, this_attr->c,
+                    &vals[0], &vals[1], this_attr->address);
 
      if (ret < 0)
          return ret;
 
-    return iio_format_value(buf, ret, val, val2);
+    return iio_format_value(buf, ret, vals);
  }
 
  /**
drivers/iio/industrialio-event.c +4 -2
index c9c1419..0f7f78e 100644
@@ -272,7 +272,7 @@ static ssize_t iio_ev_value_show(struct device *dev,
  {
      struct iio_dev *indio_dev = dev_to_iio_dev(dev);
      struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-    int val, val2;
+    int val, val2, val_arr[2];
      int ret;
 
      ret = indio_dev->info->read_event_value(indio_dev,
@@ -281,7 +281,9 @@ static ssize_t iio_ev_value_show(struct device *dev,
          &val, &val2);
      if (ret < 0)
          return ret;
-    return iio_format_value(buf, ret, val, val2);
+    val_arr[0] = val;
+    val_arr[1] = val2;
+    return iio_format_value(buf, ret, val_arr);
  }
 
  static ssize_t iio_ev_value_store(struct device *dev,
drivers/iio/inkern.c +13 -2
index 0cf5f8e..6a93d57 100644
@@ -417,12 +417,23 @@ static int iio_channel_read(struct iio_channel *chan, int *val, int *val2,
      enum iio_chan_info_enum info)
  {
      int unused;
+    int vals[INDIO_MAX_RAW_ELEMENTS];
+    int ret;
 
      if (val2 == NULL)
          val2 = &unused;
 
-    return chan->indio_dev->info->read_raw(chan->indio_dev, chan->channel,
-                        val, val2, info);
+    if (chan->indio_dev->info->read_raw_multi) {
+        ret = chan->indio_dev->info->read_raw_multi(chan->indio_dev,
+                    chan->channel, INDIO_MAX_RAW_ELEMENTS,
+                    vals, info);
+        *val = vals[0];
+        *val2 = vals[1];
+    } else
+        ret = chan->indio_dev->info->read_raw(chan->indio_dev,
+                    chan->channel, val, val2, info);
+
+    return ret;
  }
 
  int iio_read_channel_raw(struct iio_channel *chan, int *val)
include/linux/iio/iio.h +10 -0
index 75a8a20..ddf9f60 100644
@@ -284,6 +284,8 @@ static inline s64 iio_get_time_ns(void)
  #define INDIO_ALL_BUFFER_MODES                    \
      (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE)
 
+#define INDIO_MAX_RAW_ELEMENTS        4
+
  struct iio_trigger; /* forward declaration */
  struct iio_dev;
 
@@ -298,6 +300,14 @@ struct iio_dev;
   *            the channel in question.  Return value will specify the
   *            type of value returned by the device. val and val2 will
   *            contain the elements making up the returned value.
+ * @read_raw_multi:    function to return values from the device.
+ *            mask specifies which value. Note 0 means a reading of
+ *            the channel in question.  Return value will specify the
+ *            type of value returned by the device. vals pointer
+ *            contain the elements making up the returned value.
+ *            val_len specifies maximum number of elements
+ *            vals pointer can contain. In contrast to to read_raw
+ *            device can return multiple values not just two.
   * @write_raw:        function to write a value to the device.
   *            Parameters are the same as for read_raw.
   * @write_raw_get_fmt:    callback function to query the expected
@@ -324,6 +334,12 @@ struct iio_info {
              int *val2,
              long mask);
 
Quoted 12 lines

include/linux/iio/iio.h struct iio_info { · line 345

Quoted 10 lines
include/linux/iio/iio.h +6 -0
+    int (*read_raw_multi)(struct iio_dev *indio_dev,
+            struct iio_chan_spec const *chan,
+            int val_len,
+            int *vals,
+            long mask);
+
      int (*write_raw)(struct iio_dev *indio_dev,
               struct iio_chan_spec const *chan,
               int val,

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#9 lore raw

Re: [PATCH] iio: Add Freescale MMA8452Q 3-axis accelerometer driver

Nope. I guess Peter never had a chance to get back to it. I had forgotten about it entirely...

Quoted 15 lines · On April 7, 2014 5:05:36 PM GMT+01:00, [email protected] wrote:

Hi,

I just stumbled across this [1] and was wondering if this patch made it

into some tree.

Regards,

Robert

[1] http://thread.gmane.org/gmane.linux.kernel.iio/10876
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
#10 lore raw

Re: [PATCH] iio: Add Freescale MMA8452Q 3-axis accelerometer driver

Hi,

Quoted 1 line

Nope. I guess Peter never had a chance to get back to it. I had forgotten about it entirely...

I think there were some minor comments; I'll try to clean them up and resubmit shortly

regards, p.

Quoted 15 lines
Quoted 13 lines

I just stumbled across this [1] and was wondering if this patch made it

into some tree.

Regards,

Robert

[1] http://thread.gmane.org/gmane.linux.kernel.iio/10876
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Peter Meerwald
+43-664-2444418 (mobile)