Skip to contentSkip to conversation

Quaternion support

PATCH In review Srinivas Pandruvada 2 participants 9 messages Apr 15, 2014 – Apr 26, 2014

Subsystems (5)
Documentation HID IIO Driver core +1 more subsystems
lore
Share & tools
lore

Srinivas Pandruvada

author maintainer
#0 lore raw

v6 cover Quaternion support

v6:
Minor changes suggested by Peter Meerwald

v5:
Only change is for aligning function paramaters as suggested by Joe Perches

Srinivas Pandruvada (6):
devres: introduce API "devm_kmemdup
IIO: core: Introduce read_raw_multi
IIO: core: Modify scan element type
IIO: core: Add quaternion modifier
iio: hid-sensors: Added device rotation support
iio: Added ABI description for quaternion

 Documentation/ABI/testing/sysfs-bus-iio       |  12 +
 Documentation/driver-model/devres.txt         |   1 +
 drivers/base/devres.c                         |  21 ++
 drivers/iio/iio_core.h                        |   2 +-
 drivers/iio/industrialio-buffer.c             |  41 ++-
 drivers/iio/industrialio-core.c               |  66 +++--
 drivers/iio/industrialio-event.c              |   6 +-
 drivers/iio/inkern.c                          |  16 +-
 drivers/iio/orientation/Kconfig               |  12 +
 drivers/iio/orientation/Makefile              |   1 +
 drivers/iio/orientation/hid-sensor-rotation.c | 348 ++++++++++++++++++++++++++
 include/linux/device.h                        |   2 +
 include/linux/hid-sensor-ids.h                |   1 +
 include/linux/iio/iio.h                       |  24 ++
 include/linux/iio/types.h                     |   2 +
 15 files changed, 522 insertions(+), 33 deletions(-)
 create mode 100644 drivers/iio/orientation/hid-sensor-rotation.c
Signature · 1 line
1.7.11.7
author maintainer
#1 lore raw

PATCH v6 1/6 devres: introduce API "devm_kmemdup

Introduce devm_kmemdup, which uses resource managed kmalloc. There are several request from maintainers to add this instead of using kmemdup.

---
 Documentation/driver-model/devres.txt |  1 +
 drivers/base/devres.c                 | 21 +++++++++++++++++++++
 include/linux/device.h                |  2 ++
 3 files changed, 24 insertions(+)
Documentation/driver-model/devres.txt +1 -0
index 4f7897e..4999518 100644
@@ -236,6 +236,7 @@ certainly invest a bit more effort into libata core layer).
 MEM
   devm_kzalloc()
   devm_kfree()
+  devm_kmemdup()
 
 IIO
   devm_iio_device_alloc()
drivers/base/devres.c +21 -0
index db4e264..d0914cb 100644
@@ -831,3 +831,24 @@ void devm_kfree(struct device *dev, void *p)
 	WARN_ON(rc);
 }
 EXPORT_SYMBOL_GPL(devm_kfree);
+
+/**
+ * devm_kmemdup - Resource-managed kmemdup
+ * @dev: Device this memory belongs to
+ * @src: Memory region to duplicate
+ * @len: Memory region length
+ * @gfp: GFP mask to use
+ *
+ * Duplicate region of a memory using resource managed kmalloc
+ */
+void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp)
+{
+	void *p;
+
+	p = devm_kmalloc(dev, len, gfp);
+	if (p)
+		memcpy(p, src, len);
+
+	return p;
+}
+EXPORT_SYMBOL_GPL(devm_kmemdup);
include/linux/device.h +2 -0
index 233bbbe..4a37849 100644
@@ -629,6 +629,8 @@ static inline void *devm_kcalloc(struct device *dev,
 }
 extern void devm_kfree(struct device *dev, void *p);
 extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp);
+extern void *devm_kmemdup(struct device *dev, const void *src, size_t len,
+			  gfp_t gfp);
 
 void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res);
 void __iomem *devm_request_and_ioremap(struct device *dev,
Signature · 1 line
1.7.11.7
author maintainer
#3 lore raw

PATCH v6 3/6 IIO: core: Modify scan element type

In reply to Srinivas Pandruvada

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{X[repeat]}[>>shift].
Here X is specifying how may times, real/storage bits are repeating.

When X 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           |  7 +++++++
 2 files changed, 42 insertions(+), 6 deletions(-)
drivers/iio/industrialio-buffer.c +35 -6
index e108f2a..aa90c68 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[repeat]}>>%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,
@@ -474,14 +483,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;
 	}
@@ -957,7 +974,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)
@@ -969,7 +990,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)
@@ -990,7 +1015,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 +7 -0
index 5629c92..ccde917 100644
@@ -177,6 +177,12 @@ struct iio_event_spec {
  *			shift:		Shift right by this before masking out
  *					realbits.
  *			endianness:	little or big endian
+ *			repeat:		Number of times real/storage bits
+ *					repeats. When the repeat element is
+ *					more than 1, then the type element in
+ *					sysfs will show a repeat value.
+ *					Otherwise, the number of repetitions is
+ *					omitted.
  * @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 +225,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.7.11.7
author maintainer
#6 lore raw

PATCH v6 4/6 IIO: core: Add quaternion modifier

In reply to Srinivas Pandruvada

Added quaternion in the list of supported modifiers.

---
 drivers/iio/industrialio-core.c | 1 +
 include/linux/iio/types.h       | 1 +
 2 files changed, 2 insertions(+)
drivers/iio/industrialio-core.c +1 -0
index e22a984..dcc1849 100644
@@ -84,6 +84,7 @@ static const char * const iio_modifier_names[] = {
 	[IIO_MOD_LIGHT_RED] = "red",
 	[IIO_MOD_LIGHT_GREEN] = "green",
 	[IIO_MOD_LIGHT_BLUE] = "blue",
+	[IIO_MOD_QUATERNION] = "quaternion",
 };
 
 /* relies on pairs of these shared then separate */
include/linux/iio/types.h +1 -0
index a13c224..4fdab2e 100644
@@ -53,6 +53,7 @@ enum iio_modifier {
 	IIO_MOD_LIGHT_RED,
 	IIO_MOD_LIGHT_GREEN,
 	IIO_MOD_LIGHT_BLUE,
+	IIO_MOD_QUATERNION,
 };
 
 enum iio_event_type {
Signature · 1 line
1.7.11.7
author maintainer
#2 lore raw

PATCH v6 2/6 IIO: core: Introduce read_raw_multi

In reply to 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.

---
 drivers/iio/iio_core.h           |  2 +-
 drivers/iio/industrialio-core.c  | 65 ++++++++++++++++++++++++++--------------
 drivers/iio/industrialio-event.c |  6 ++--
 drivers/iio/inkern.c             | 16 ++++++++--
 include/linux/iio/iio.h          | 17 +++++++++++
 include/linux/iio/types.h        |  1 +
 6 files changed, 80 insertions(+), 27 deletions(-)
drivers/iio/iio_core.h +1 -1
index f6db6af..5f0ea77 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 size, int *vals);
 
 /* Event interface flags */
 #define IIO_BUSY_BIT_POS 1
drivers/iio/industrialio-core.c +43 -22

98 lines not on this page · raw message

drivers/iio/industrialio-event.c +4 -2
index ea6e06b..1b4f31b 100644
@@ -270,7 +270,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,
@@ -279,7 +279,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, 2, val_arr);
 }
 
 static ssize_t iio_ev_value_store(struct device *dev,
drivers/iio/inkern.c +14 -2
index 0cf5f8e..75e5386 100644
@@ -417,12 +417,24 @@ 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;
+	int val_len = 2;
 
 	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, &val_len, 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 +17 -0
index 5f2d00e..5629c92 100644
@@ -288,6 +288,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;
 
@@ -302,6 +304,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.
+ *			max_len specifies maximum number of elements
+ *			vals pointer can contain. val_len is used to return
+ *			length of valid elements in vals.
  * @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
@@ -328,6 +338,13 @@ struct iio_info {
 			int *val2,
 			long mask);
 
+	int (*read_raw_multi)(struct iio_dev *indio_dev,
+			struct iio_chan_spec const *chan,
+			int max_len,
+			int *vals,
+			int *val_len,
+			long mask);
+
 	int (*write_raw)(struct iio_dev *indio_dev,
 			 struct iio_chan_spec const *chan,
 			 int val,
include/linux/iio/types.h +1 -0
index 084d882..a13c224 100644
@@ -79,6 +79,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_INT_MULTIPLE 5
 #define IIO_VAL_FRACTIONAL 10
 #define IIO_VAL_FRACTIONAL_LOG2 11
 
Signature · 1 line
1.7.11.7
author maintainer
#7 lore raw

PATCH v6 5/6 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               |  12 +
 drivers/iio/orientation/Makefile              |   1 +
 drivers/iio/orientation/hid-sensor-rotation.c | 348 ++++++++++++++++++++++++++
 include/linux/hid-sensor-ids.h                |   1 +
 4 files changed, 362 insertions(+)
 create mode 100644 drivers/iio/orientation/hid-sensor-rotation.c
drivers/iio/orientation/Kconfig +12 -0
index 58c62c8..e3aa1e5 100644
@@ -16,4 +16,16 @@ 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. The output of a device rotation sensor
+	  is presented using quaternion format.
+
 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 +348 -0

348 lines not on this page · raw message

include/linux/hid-sensor-ids.h +1 -0
index 14ead9e..109f0e6 100644
@@ -76,6 +76,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.7.11.7
author maintainer
#8 lore raw

PATCH v6 6/6 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 | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Documentation/ABI/testing/sysfs-bus-iio +12 -0
index 6e02c50..d2c59f9 100644
@@ -784,6 +784,7 @@ What:		/sys/.../iio:deviceX/scan_elements/in_incli_x_en
 What:		/sys/.../iio:deviceX/scan_elements/in_incli_y_en
 What:		/sys/.../iio:deviceX/scan_elements/in_pressureY_en
 What:		/sys/.../iio:deviceX/scan_elements/in_pressure_en
+What:		/sys/.../iio:deviceX/scan_elements/in_rot_quaternion_en
 KernelVersion:	2.6.37
 Contact:	[email protected]
 Description:
@@ -799,6 +800,7 @@ What:		/sys/.../iio:deviceX/scan_elements/in_voltageY_supply_type
 What:		/sys/.../iio:deviceX/scan_elements/in_timestamp_type
 What:		/sys/.../iio:deviceX/scan_elements/in_pressureY_type
 What:		/sys/.../iio:deviceX/scan_elements/in_pressure_type
+What:		/sys/.../iio:deviceX/scan_elements/in_rot_quaternion_type
 KernelVersion:	2.6.37
 Contact:	[email protected]
 Description:
@@ -845,6 +847,7 @@ What:		/sys/.../iio:deviceX/scan_elements/in_incli_y_index
 What:		/sys/.../iio:deviceX/scan_elements/in_timestamp_index
 What:		/sys/.../iio:deviceX/scan_elements/in_pressureY_index
 What:		/sys/.../iio:deviceX/scan_elements/in_pressure_index
+What:		/sys/.../iio:deviceX/scan_elements/in_rot_quaternion_index
 KernelVersion:	2.6.37
 Contact:	[email protected]
 Description:
@@ -891,3 +894,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_rot_quaternion_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.7.11.7
maintainer
#4 lore raw

Re: [Patch v6 3/6] IIO: core: Modify scan element type

In reply to Srinivas Pandruvada
Quoted 11 lines · Srinivas Pandruvada

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{X[repeat]}[>>shift].

Here X is specifying how may times, real/storage bits are repeating.

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

Hi Srinivas,

I'm afraid I've been rather useless in my reviewing of earlier versions of this. What I originally meant to suggest was that we'd have descriptions along the lines of
u12/16{X4}>>2 (or u12/16X4>>2 without the brackets) rather than u12/16{4repeat}>>2

Now obviously you've gone a long way with this approach so I guess perhaps people actually like the word repeat in there?

Sorry again that I didn't pick up on this in any of the last 4 versions you have posted. Sometimes the eye sees what it expects to rather than what is there!

I don't particularly mind the version using the word 'repeat' if others like, it simply isn't what I thought we had here!

(the rest of this series are fine now btw)

J

Quoted 117 lines
---
  drivers/iio/industrialio-buffer.c | 41 +++++++++++++++++++++++++++++++++------
  include/linux/iio/iio.h           |  7 +++++++
  2 files changed, 42 insertions(+), 6 deletions(-)
drivers/iio/industrialio-buffer.c +35 -6
index e108f2a..aa90c68 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[repeat]}>>%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,
@@ -474,14 +483,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;
  	}
@@ -957,7 +974,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)
@@ -969,7 +990,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)
@@ -990,7 +1015,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 +7 -0
index 5629c92..ccde917 100644
@@ -177,6 +177,12 @@ struct iio_event_spec {
   *			shift:		Shift right by this before masking out
   *					realbits.
   *			endianness:	little or big endian
+ *			repeat:		Number of times real/storage bits
+ *					repeats. When the repeat element is
+ *					more than 1, then the type element in
+ *					sysfs will show a repeat value.
+ *					Otherwise, the number of repetitions is
+ *					omitted.
   * @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 +225,7 @@ struct iio_chan_spec {
  		u8	realbits;
  		u8	storagebits;
  		u8	shift;
+		u8	repeat;
  		enum iio_endian endianness;
  	} scan_type;
  	long			info_mask_separate;
author maintainer
#5 lore raw

Re: [Patch v6 3/6] IIO: core: Modify scan element type

Quoted 11 lines · Jonathan Cameron
Quoted 10 lines · Srinivas Pandruvada

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{X[repeat]}[>>shift].

Here X is specifying how may times, real/storage bits are repeating.

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

Quoted 7 lines
Quoted 1 line

Hi Srinivas,

I'm afraid I've been rather useless in my reviewing of earlier versions of this. What I originally meant to suggest was that we'd have descriptions along the lines of
u12/16{X4}>>2 (or u12/16X4>>2 without the brackets) rather than u12/16{4repeat}>>2

I don't mind using u12/16X4>>2, will submit series again.

Thanks,
Srinivas

Quoted 140 lines

Now obviously you've gone a long way with this approach so I guess perhaps people actually like the word repeat in there?

Sorry again that I didn't pick up on this in any of the last 4 versions you have posted. Sometimes the eye sees what it expects to rather than what is there!

I don't particularly mind the version using the word 'repeat' if others like, it simply isn't what I thought we had here!

(the rest of this series are fine now btw)

J

Quoted 125 lines
---
  drivers/iio/industrialio-buffer.c | 41 
+++++++++++++++++++++++++++++++++------
  include/linux/iio/iio.h           |  7 +++++++
  2 files changed, 42 insertions(+), 6 deletions(-)
drivers/iio/industrialio-buffer.c +10 -1
index e108f2a..aa90c68 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[repeat]}>>%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,
drivers/iio/industrialio-buffer.c +10 -2
@@ -474,14 +483,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;
      }
drivers/iio/industrialio-buffer.c +5 -1
@@ -957,7 +974,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)

drivers/iio/industrialio-buffer.c +5 -1
@@ -969,7 +990,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)

drivers/iio/industrialio-buffer.c +5 -1
@@ -990,7 +1015,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 +6 -0
index 5629c92..ccde917 100644
@@ -177,6 +177,12 @@ struct iio_event_spec {
   *            shift:        Shift right by this before masking out
   *                    realbits.
   *            endianness:    little or big endian
+ *            repeat:        Number of times real/storage bits
+ *                    repeats. When the repeat element is
+ *                    more than 1, then the type element in
+ *                    sysfs will show a repeat value.
+ *                    Otherwise, the number of repetitions is
+ *                    omitted.
   * @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

include/linux/iio/iio.h +1 -0
@@ -219,6 +225,7 @@ struct iio_chan_spec {
          u8    realbits;
          u8    storagebits;
          u8    shift;
+        u8    repeat;
          enum iio_endian endianness;
      } scan_type;
      long            info_mask_separate;