IIO: core: Introduce read_raw_multi
Subsystems (3)
Srinivas Pandruvada
maintainerPATCH 1/4 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
@@ -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
@@ -274,7 +274,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;if (indio_dev->info->read_event_value) {
@@ -290,7 +290,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); } }
drivers/iio/inkern.c +13 -2
@@ -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
@@ -286,6 +286,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 ;
@@ -300,6 +302,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
@@ -334,6 +344,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
Srinivas Pandruvada
maintainerPATCH 2/4 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
@@ -121,7 +121,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,
@@ -446,14 +455,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; }
@@ -932,7 +949,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)
@@ -944,7 +965,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)
@@ -965,7 +990,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
@@ -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
@@ -220,6 +228,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
Srinivas Pandruvada
maintainerPATCH 3/4 IIO: core: Introduce Quaternion types
In reply to Srinivas PandruvadaIntroduced 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 | 3 +++ 2 files changed, 7 insertions(+)
drivers/iio/industrialio-core.c +4 -0
@@ -69,6 +69,7 @@ static const char * const iio_chan_type_name_spec[] = { [IIO_ALTVOLTAGE] = "altvoltage", [IIO_CCT] = "cct", [IIO_PRESSURE] = "pressure", + [IIO_QUAT_ROT] = "rotquaternion", };static const char *const iio_modifier_names[] = {
@@ -403,6 +404,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 +3 -0
@@ -29,6 +29,7 @@ enum iio_chan_type {IIO_ALTVOLTAGE ,IIO_CCT ,IIO_PRESSURE , + IIO_QUAT_ROT, }; enum iio_modifier {
@@ -52,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 {
@@ -78,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
Jonathan Cameron
maintainerRe: [PATCH 3/4] IIO: core: Introduce Quaternion types
Quoted 5 lines · Srinivas Pandruvada
Introduced
IIO_VAL_QUATERNIONand its formatting. Format used here:
x:y:z:w
In additionIIO_QUAT_ROTis added to the channel type and name.Signed-off-by Srinivas Pandruvada <[email protected]>
Since reviewing the interface for the ecap driver the other day I've been wondering if a new channel is the right approach here. In that driver I pointed out that modifiers can result in different units for the output. I'm not sure we want to do that in general, but perhaps here it makes sense?
So we would have a quaternion modifier (treating it the same as an axis) giving us attributes like
in_rot_quaternion_raw
etc.
Would this be prefereable to the approach here of having new channel type to cover it? That is do we want the channel type to always specify the representation, or do we allow it to be done through the modifier? We have let in relativehumidity as a type which arguably could have been humidity and a relative modifier. Perhaps we are better just going with these compound types. They don't really restrict us, but just feel a little untidy.
Also, Srinivas - whatever we end up with needs documenting in Documentation/ABI/testing/sysfs-bus-iio
Whilst looking at this I notice we confusingly have both rot and angl channel types. Are they actually different? Conceptually devices tend to be thought of as measuring one or the other - so you'd probably never describe an inclinometer as measuring rotation. Hmm.. As it is now been in the ABI for some time we are pretty much stuck with this.
Quoted 56 lines
--- drivers/iio/industrialio-core.c | 4 ++++ include/linux/iio/types.h | 3 +++ 2 files changed, 7 insertions(+)drivers/iio/industrialio-core.c +4
-0@@ -69,6 +69,7 @@ static const char * const iio_chan_type_name_spec[] = { [IIO_ALTVOLTAGE] = "altvoltage", [IIO_CCT] = "cct", [IIO_PRESSURE] = "pressure", + [IIO_QUAT_ROT] = "rotquaternion", };static const char *const iio_modifier_names[] = {@@ -403,6 +404,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 +3
-0@@ -29,6 +29,7 @@ enum iio_chan_type {IIO_ALTVOLTAGE ,IIO_CCT ,IIO_PRESSURE , + IIO_QUAT_ROT, }; enum iio_modifier {@@ -52,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 {@@ -78,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
Srinivas Pandruvada
maintainerRe: [PATCH 3/4] IIO: core: Introduce Quaternion types
Quoted 12 lines · Jonathan Cameron
Quoted 5 lines · Srinivas Pandruvada
Introduced
IIO_VAL_QUATERNIONand its formatting. Format used here:
x:y:z:w
In additionIIO_QUAT_ROTis added to the channel type and name.Signed-off-by Srinivas Pandruvada <[email protected]>Since reviewing the interface for the ecap driver the other day I've been wondering if a new channel is the right approach here. In that driver I pointed out that modifiers can result in different units for the output. I'm not sure we want to do that in general, but perhaps here it makes sense?
Quoted 7 lines
So we would have a quaternion modifier (treating it the same as an axis) giving us attributes like
in_rot_quaternion_rawetc.
This is what it looks now, with new set of patches:
iio:deviceX/
├── buffer │ ├── enable │ └── length .. ├── in_rotquaternion_raw ├── name ├── scan_elements │ ├── in_rotquaternion_en │ ├── in_rotquaternion_index │ └── in_rotquaternion_type ├── trigger │ └── current_trigger
This is what you prefer?
Quoted 10 lines
Would this be prefereable to the approach here of having new channel type to cover it? That is do we want the channel type to always specify the representation, or do we allow it to be done through the modifier? We have let in relativehumidity as a type which arguably could have been humidity and a relative modifier. Perhaps we are better just going with these compound types. They don't really restrict us, but just feel a little untidy.
Also, Srinivas - whatever we end up with needs documenting in
Documentation/ABI/testing/sysfs-bus-iio
Submitted a new series with this patch
Thanks,
Srinivas
Quoted 70 lines
Whilst looking at this I notice we confusingly have both rot and angl channel types. Are they actually different? Conceptually devices tend to be thought of as measuring one or the other - so you'd probably never describe an inclinometer as measuring rotation. Hmm.. As it is now been
in the ABI for some time we are pretty much stuck with this.Quoted 51 lines
--- drivers/iio/industrialio-core.c | 4 ++++ include/linux/iio/types.h | 3 +++ 2 files changed, 7 insertions(+)drivers/iio/industrialio-core.c +4
-0@@ -69,6 +69,7 @@ static const char * const iio_chan_type_name_spec[] = { [IIO_ALTVOLTAGE] = "altvoltage", [IIO_CCT] = "cct", [IIO_PRESSURE] = "pressure", + [IIO_QUAT_ROT] = "rotquaternion", };static const char *const iio_modifier_names[] = {@@ -403,6 +404,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@@ -29,6 +29,7 @@ enum iio_chan_type {IIO_ALTVOLTAGE ,IIO_CCT ,IIO_PRESSURE , + IIO_QUAT_ROT, }; enum iio_modifier {@@ -52,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 {include/linux/iio/types.h enum iio_event_direction { · line 86
Quoted 7 lines
include/linux/iio/types.h +1
-0@@ -78,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--
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
Jonathan Cameron
maintainerRe: [PATCH 3/4] IIO: core: Introduce Quaternion types
Quoted 37 lines · Srinivas Pandruvada
Quoted 12 lines · Jonathan Cameron
Quoted 5 lines · Srinivas Pandruvada
Introduced
IIO_VAL_QUATERNIONand its formatting. Format used here:
x:y:z:w
In additionIIO_QUAT_ROTis added to the channel type and name.Signed-off-by Srinivas Pandruvada <[email protected]>Since reviewing the interface for the ecap driver the other day I've been wondering if a new channel is the right approach here. In that driver I pointed out that modifiers can result in different units for the output. I'm not sure we want to do that in general, but perhaps here it makes sense?
Quoted 7 lines
So we would have a quaternion modifier (treating it the same as an axis) giving us attributes like
in_rot_quaternion_rawetc.
This is what it looks now, with new set of patches:
iio:deviceX/├── buffer │ ├── enable │ └── length .. ├── in_rotquaternion_raw ├── name ├── scan_elements │ ├── in_rotquaternion_en │ ├── in_rotquaternion_index │ └── in_rotquaternion_type ├── trigger │ └── current_trigger
Quoted 1 line
This is what you prefer?
I was suggesting in this email that we consider using a modifier to specify the quaternion bit (much like x, y, z for axes). I'm still a bit in two minds about this so was hoping to start a bit more of a discussion about it!
Right now I think I slighly prefer the approach you have taken here as it avoids some confusion. Having said that I'll probably need to rethink my response to the ecap driver as the interfaces of these two are in some ways raising the same sorts of questions!
Thanks and sorry for delaying the merging of these patchs.
Good to get the Docs in there though. I should have picked up on that earlier.
Jonathan
Quoted 95 lines
Quoted 11 lines
Would this be prefereable to the approach here of having new channel type to cover it? That is do we want the channel type to always specify the representation, or do we allow it to be done through the modifier? We have let in relativehumidity as a type which arguably could have been humidity and a relative modifier. Perhaps we are better just going with these compound types. They don't really restrict us, but just feel a little untidy.
Quoted 2 lines
Also, Srinivas - whatever we end up with needs documenting in
Documentation/ABI/testing/sysfs-bus-iioSubmitted a new series with this patch
Thanks,
SrinivasQuoted 54 lines
Whilst looking at this I notice we confusingly have both rot and angl channel types. Are they actually different? Conceptually devices tend to be thought of as measuring one or the other - so you'd probably never describe an inclinometer as measuring rotation. Hmm.. As it is now been
in the ABI for some time we are pretty much stuck with this.Quoted 48 lines
--- drivers/iio/industrialio-core.c | 4 ++++ include/linux/iio/types.h | 3 +++ 2 files changed, 7 insertions(+)drivers/iio/industrialio-core.c +4
-0@@ -69,6 +69,7 @@ static const char * const iio_chan_type_name_spec[] = { [IIO_ALTVOLTAGE] = "altvoltage", [IIO_CCT] = "cct", [IIO_PRESSURE] = "pressure", + [IIO_QUAT_ROT] = "rotquaternion", };static const char *const iio_modifier_names[] = {@@ -403,6 +404,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@@ -29,6 +29,7 @@ enum iio_chan_type {IIO_ALTVOLTAGE ,IIO_CCT ,IIO_PRESSURE , + IIO_QUAT_ROT, }; enum iio_modifier {@@ -52,6 +53,7 @@ enum iio_modifier {IIO_MOD_LIGHT_RED ,IIO_MOD_LIGHT_GREEN ,IIO_MOD_LIGHT_BLUE , + IIO_MOD_QUATERNION, };Quoted 16 lines
include/linux/iio/types.h enum iio_event_direction { · line 86
Quoted 10 lines
include/linux/iio/types.h +1
-0enum iio_event_type {@@ -78,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--
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--
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
Srinivas Pandruvada
maintainerPATCH 4/4 iio: hid-sensors: Added device rotation support
In reply to Srinivas PandruvadaAdded 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 | 360 ++++++++++++++++++++++++++ include/linux/hid-sensor-ids.h | 1 + 4 files changed, 373 insertions(+) create mode 100644 drivers/iio/orientation/hid-sensor-rotation.c
drivers/iio/orientation/Kconfig +11 -0
@@ -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
@@ -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 +360 -0
360 lines not on this page · raw message
include/linux/hid-sensor-ids.h +1 -0
@@ -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
Jonathan Cameron
maintainerQuoted 10 lines · Srinivas Pandruvada
This callback is introduced to overcome some limitations of existing
read_rawcallback. The functionality of both existingread_rawandread_raw_multiis similar, both are used to request values from the device. The currentread_rawcallback allows only two return values. The newread_raw_multiallows 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.Signed-off-by Srinivas Pandruvada <[email protected]>
I am fairly happy with this set, but would like to get a few more opinions before taking this new chunk of ABI into the subsystem.
Peter made the point that there were other cases (RGB colour sensors, where perhaps such a multi component type makes sense) and as such we may have some redundancy. I agree that this is a possible issue but in the case of quaternion rotations the components have no meaning whatsoever on their own under any circumstances. As such supporting them as single components is a non starter to my mind.
The other option Peter raised was to only allow such compound types via the buffered interface. This would certainly be an option as then we could use available channel masks to ensure that all or none of hte elements are present.
I think I prefer the approach taken here as it still allows for 'what is my current orientation' type polled queries via sysfs.
Anyhow, I've cc'd everyone I could immediately think of who might have an opinion and / or has some involvement with inertial sensors that 'might' use this functionality at some point.
Jonathan
p.s You will probably want to read the whole series if you haven't seen this before.
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@@ -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 1drivers/iio/industrialio-core.c +29
-22@@ -367,41 +367,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 ; }@@ -413,14 +414,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@@ -274,7 +274,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;if (indio_dev->info->read_event_value) {@@ -290,7 +290,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); } }drivers/iio/inkern.c +13
-2@@ -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@@ -286,6 +286,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 ;@@ -300,6 +302,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 @@ -334,6 +344,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,