iio: dummy: Add 3-axis compass (magnetometer) channels to the iio_simple_dummy
PATCH 1/1 iio: dummy: Add 3-axis compass (magnetometer) channels to the iio_simple_dummy
This patch adds support for 3-axis magnetometer data (X, Y, Z) in the iio_simple_dummy driver. It introduces three new IIO_MAGN channels and populates them with dummy values for testing and prototyping purposes.
--- drivers/iio/dummy/iio_simple_dummy.c | 71 +++++++++++++++++++++++++++- drivers/iio/dummy/iio_simple_dummy.h | 6 +++ 2 files changed, 75 insertions(+), 2 deletions(-)
drivers/iio/dummy/iio_simple_dummy.c +69 -2
@@ -222,7 +222,7 @@ static const struct iio_chan_spec iio_dummy_channels[] = {* Convenience macro for timestamps. 4 is the index in * the buffer. */ -IIO_CHAN_SOFT_TIMESTAMP (4 ), +IIO_CHAN_SOFT_TIMESTAMP (DUMMY_INDEX_SOFT_TIMESTAMP ),/* DAC channel out_voltage0_raw */ { .type = IIO_VOLTAGE,
@@ -265,6 +265,48 @@ static const struct iio_chan_spec iio_dummy_channels[] = { .num_event_specs = 1,#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */ }, + { + .type = IIO_MAGN, + .modified = 1, + .channel2 = IIO_MOD_X, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), + .scan_index = DUMMY_MAGN_X, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .shift = 0, + }, + }, + { + .type = IIO_MAGN, + .modified = 1, + .channel2 = IIO_MOD_Y, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), + .scan_index = DUMMY_MAGN_Y, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .shift = 0, + }, + }, + { + .type = IIO_MAGN, + .modified = 1, + .channel2 = IIO_MOD_Z, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), + .scan_index = DUMMY_MAGN_Z, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .shift = 0, + }, + }, }; static int __iio_dummy_read_raw(struct iio_dev *indio_dev,
@@ -294,6 +336,22 @@ static int __iio_dummy_read_raw(struct iio_dev *indio_dev,case IIO_ACCEL : *val = st->accel_val;return IIO_VAL_INT ; +case IIO_MAGN : +switch (chan->scan_index) { +case DUMMY_MAGN_X : + *val = st->buffer_compass[0 ]; +break ; +case DUMMY_MAGN_Y : + *val = st->buffer_compass[1 ]; +break ; +case DUMMY_MAGN_Z : + *val = st->buffer_compass[2 ]; +break ; +default : + *val =99 ; +break ; + } +return IIO_VAL_INT ;default :return -EINVAL ; }
@@ -378,6 +436,11 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,default :return -EINVAL ; } +case IIO_MAGN : +// Just add some dummy values + *val =0 ; + *val2 =2 ; +return IIO_VAL_INT_PLUS_MICRO ;default :return -EINVAL ; }
@@ -562,6 +625,10 @@ static int iio_dummy_init_device(struct iio_dev *indio_dev) st->activity_running =98 ; st->activity_walking =4 ; + st->buffer_compass[0 ] =78 ; + st->buffer_compass[1 ] =10 ; + st->buffer_compass[2 ] =3 ; +return 0 ; }
@@ -732,5 +799,5 @@ static struct iio_sw_device_type iio_dummy_device = {module_iio_sw_device_driver (iio_dummy_device);MODULE_AUTHOR ("Jonathan Cameron <[email protected]>" ); -MODULE_DESCRIPTION ("IIO dummy driver" ); +MODULE_DESCRIPTION ("IIO dummy driver -> IIO dummy modified by Me" );MODULE_LICENSE ("GPL v2" );
drivers/iio/dummy/iio_simple_dummy.h +6 -0
@@ -12,6 +12,7 @@struct iio_dummy_accel_calibscale ;struct iio_dummy_regs ; +#define DUMMY_AXIS_XYZ 3/** * struct iio_dummy_state - device instance specific state. * @dac_val: cache for dac value
@@ -39,6 +40,7 @@ struct iio_dummy_state {int steps_enabled;int steps;int height; +u16 buffer_compass[DUMMY_AXIS_XYZ ];#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS int event_irq;int event_val;
@@ -107,6 +109,10 @@ enum iio_simple_dummy_scan_elements {DUMMY_INDEX_DIFFVOLTAGE_1M2 ,DUMMY_INDEX_DIFFVOLTAGE_3M4 ,DUMMY_INDEX_ACCELX , +DUMMY_INDEX_SOFT_TIMESTAMP , +DUMMY_MAGN_X , +DUMMY_MAGN_Y , + DUMMY_MAGN_Z, };#ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
Signature · 1 line
2.43.0
Quoted 3 lines · Brajesh Patil
This patch adds support for 3-axis magnetometer data (X, Y, Z) in the
iio_simple_dummydriver. It introduces three newIIO_MAGNchannels and populates them with dummy values for testing and prototyping purposes.
Is this intended as a contribution for outreachy? It is not working on a staging driver.
julia
Quoted 157 lines
Signed-off-by Brajesh Patil <[email protected]>--- drivers/iio/dummy/iio_simple_dummy.c | 71 +++++++++++++++++++++++++++- drivers/iio/dummy/iio_simple_dummy.h | 6 +++ 2 files changed, 75 insertions(+), 2 deletions(-)drivers/iio/dummy/iio_simple_dummy.c +69
-2@@ -222,7 +222,7 @@ static const struct iio_chan_spec iio_dummy_channels[] = {* Convenience macro for timestamps. 4 is the index in * the buffer. */ -IIO_CHAN_SOFT_TIMESTAMP (4 ), +IIO_CHAN_SOFT_TIMESTAMP (DUMMY_INDEX_SOFT_TIMESTAMP ),/* DAC channel out_voltage0_raw */ { .type = IIO_VOLTAGE,@@ -265,6 +265,48 @@ static const struct iio_chan_spec iio_dummy_channels[] = { .num_event_specs = 1,#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */ }, + { + .type = IIO_MAGN, + .modified = 1, + .channel2 = IIO_MOD_X, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), + .scan_index = DUMMY_MAGN_X, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .shift = 0, + }, + }, + { + .type = IIO_MAGN, + .modified = 1, + .channel2 = IIO_MOD_Y, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), + .scan_index = DUMMY_MAGN_Y, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .shift = 0, + }, + }, + { + .type = IIO_MAGN, + .modified = 1, + .channel2 = IIO_MOD_Z, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), + .scan_index = DUMMY_MAGN_Z, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .shift = 0, + }, + }, }; static int __iio_dummy_read_raw(struct iio_dev *indio_dev,@@ -294,6 +336,22 @@ static int __iio_dummy_read_raw(struct iio_dev *indio_dev,case IIO_ACCEL : *val = st->accel_val;return IIO_VAL_INT ; +case IIO_MAGN : +switch (chan->scan_index) { +case DUMMY_MAGN_X : + *val = st->buffer_compass[0 ]; +break ; +case DUMMY_MAGN_Y : + *val = st->buffer_compass[1 ]; +break ; +case DUMMY_MAGN_Z : + *val = st->buffer_compass[2 ]; +break ; +default : + *val =99 ; +break ; + } +return IIO_VAL_INT ;default :return -EINVAL ; }@@ -378,6 +436,11 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,default :return -EINVAL ; } +case IIO_MAGN : +// Just add some dummy values + *val =0 ; + *val2 =2 ; +return IIO_VAL_INT_PLUS_MICRO ;default :return -EINVAL ; }@@ -562,6 +625,10 @@ static int iio_dummy_init_device(struct iio_dev *indio_dev) st->activity_running =98 ; st->activity_walking =4 ; + st->buffer_compass[0 ] =78 ; + st->buffer_compass[1 ] =10 ; + st->buffer_compass[2 ] =3 ; +return 0 ; }@@ -732,5 +799,5 @@ static struct iio_sw_device_type iio_dummy_device = {module_iio_sw_device_driver (iio_dummy_device);MODULE_AUTHOR ("Jonathan Cameron <[email protected]>" ); -MODULE_DESCRIPTION ("IIO dummy driver" ); +MODULE_DESCRIPTION ("IIO dummy driver -> IIO dummy modified by Me" );MODULE_LICENSE ("GPL v2" );drivers/iio/dummy/iio_simple_dummy.h +6
-1@@ -12,6 +12,7 @@struct iio_dummy_accel_calibscale ;struct iio_dummy_regs ; +#define DUMMY_AXIS_XYZ 3/** * struct iio_dummy_state - device instance specific state. * @dac_val: cache for dac value @@ -39,6 +40,7 @@ struct iio_dummy_state {int steps_enabled;int steps;int height; +u16 buffer_compass[DUMMY_AXIS_XYZ ];#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS int event_irq;int event_val;@@ -107,6 +109,10 @@ enum iio_simple_dummy_scan_elements {DUMMY_INDEX_DIFFVOLTAGE_1M2 ,DUMMY_INDEX_DIFFVOLTAGE_3M4 ,DUMMY_INDEX_ACCELX , +DUMMY_INDEX_SOFT_TIMESTAMP , +DUMMY_MAGN_X , +DUMMY_MAGN_Y , + DUMMY_MAGN_Z, };#ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER --2.43.0
Jonathan Cameron
maintainerQuoted 3 lines · On Sun, 6 Apr 2025 19:03:49 +0530 Brajesh Patil <[email protected]>…
This patch adds support for 3-axis magnetometer data (X, Y, Z) in the
iio_simple_dummydriver. It introduces three newIIO_MAGNchannels and populates them with dummy values for testing and prototyping purposes.
Why? This needs a description of what parts of the ABI or subsystem this exercises that were not previously covered by this driver.
I don't want to go down the path of adding examples for all channel types as that would be a huge and not bring much benefit.
Quoted 26 lines
Signed-off-by Brajesh Patil <[email protected]>--- drivers/iio/dummy/iio_simple_dummy.c | 71 +++++++++++++++++++++++++++- drivers/iio/dummy/iio_simple_dummy.h | 6 +++ 2 files changed, 75 insertions(+), 2 deletions(-)drivers/iio/dummy/iio_simple_dummy.c +3
-1@@ -222,7 +222,7 @@ static const struct iio_chan_spec iio_dummy_channels[] = {* Convenience macro for timestamps. 4 is the index in * the buffer. */ -IIO_CHAN_SOFT_TIMESTAMP (4 ), +IIO_CHAN_SOFT_TIMESTAMP (DUMMY_INDEX_SOFT_TIMESTAMP ),/* DAC channel out_voltage0_raw */ { .type = IIO_VOLTAGE,@@ -265,6 +265,48 @@ static const struct iio_chan_spec iio_dummy_channels[] = { .num_event_specs = 1,#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */ }, + { + .type = IIO_MAGN,
drivers/iio/dummy/iio_simple_dummy.c static const struct iio_chan_spec iio_dummy_channels[] = { · line 279
Quoted 10 lines
drivers/iio/dummy/iio_simple_dummy.c +10
-0+ .modified = 1, + .channel2 = IIO_MOD_X, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), + .scan_index = DUMMY_MAGN_X, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .shift = 0,
shift = 0 is considered an obvious default so generally we don't bother setting it explicitly (it is set by the requirements of the C spec anyway)/
Quoted 57 lines
drivers/iio/dummy/iio_simple_dummy.c +46
-0+ }, + }, + { + .type = IIO_MAGN, + .modified = 1, + .channel2 = IIO_MOD_Y, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), + .scan_index = DUMMY_MAGN_Y, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .shift = 0, + }, + }, + { + .type = IIO_MAGN, + .modified = 1, + .channel2 = IIO_MOD_Z, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), + .scan_index = DUMMY_MAGN_Z, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .shift = 0, + }, + }, }; static int __iio_dummy_read_raw(struct iio_dev *indio_dev,@@ -294,6 +336,22 @@ static int __iio_dummy_read_raw(struct iio_dev *indio_dev,case IIO_ACCEL : *val = st->accel_val;return IIO_VAL_INT ; +case IIO_MAGN : +switch (chan->scan_index) { +case DUMMY_MAGN_X : + *val = st->buffer_compass[0 ]; +break ; +case DUMMY_MAGN_Y : + *val = st->buffer_compass[1 ]; +break ; +case DUMMY_MAGN_Z : + *val = st->buffer_compass[2 ]; +break ; +default : + *val =99 ; +break ; + } +return IIO_VAL_INT ;default :return -EINVAL ; }
drivers/iio/dummy/iio_simple_dummy.c static int iio_dummy_read_raw(struct iio_dev *indio_dev, · line 440
Quoted 5 lines
drivers/iio/dummy/iio_simple_dummy.c +2
-0@@ -378,6 +436,11 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,default :return -EINVAL ; } +case IIO_MAGN : +// Just add some dummy values
Comment syntax is old style /* Add some dummy values */ for most kernel code (and all IIO other than SPDX tags in cases where // must be used).
drivers/iio/dummy/iio_simple_dummy.c static int iio_dummy_init_device(struct iio_dev *indio_dev) · line 626
Quoted 9 lines
drivers/iio/dummy/iio_simple_dummy.c +3
-0+ *val =0 ; + *val2 =2 ; +return IIO_VAL_INT_PLUS_MICRO ;default :return -EINVAL ; }@@ -562,6 +625,10 @@ static int iio_dummy_init_device(struct iio_dev *indio_dev) st->activity_running =98 ; st->activity_walking =4 ;
Something odd going on in email formatting here as your quoted lines are using spaces not tabs.
Quoted 9 lines
drivers/iio/dummy/iio_simple_dummy.c +4
-0+ st->buffer_compass[0 ] =78 ; + st->buffer_compass[1 ] =10 ; + st->buffer_compass[2 ] =3 ; +return 0 ; }
drivers/iio/dummy/iio_simple_dummy.c static struct iio_sw_device_type iio_dummy_device = { · line 802
Quoted 5 lines
drivers/iio/dummy/iio_simple_dummy.c +1
-1@@ -732,5 +799,5 @@ static struct iio_sw_device_type iio_dummy_device = {module_iio_sw_device_driver (iio_dummy_device);MODULE_AUTHOR ("Jonathan Cameron <[email protected]>" ); -MODULE_DESCRIPTION ("IIO dummy driver" ); +MODULE_DESCRIPTION ("IIO dummy driver -> IIO dummy modified by Me" );
Accidental send?
Quoted 22 lines
drivers/iio/dummy/iio_simple_dummy.c +0
-0MODULE_LICENSE ("GPL v2" );drivers/iio/dummy/iio_simple_dummy.h +2
-0@@ -12,6 +12,7 @@struct iio_dummy_accel_calibscale ;struct iio_dummy_regs ; +#define DUMMY_AXIS_XYZ 3/** * struct iio_dummy_state - device instance specific state. * @dac_val: cache for dac value @@ -39,6 +40,7 @@ struct iio_dummy_state {int steps_enabled;int steps;int height; +u16 buffer_compass[DUMMY_AXIS_XYZ ];#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS int event_irq;int event_val;
drivers/iio/dummy/iio_simple_dummy.h enum iio_simple_dummy_scan_elements { · line 112
Quoted 4 lines
drivers/iio/dummy/iio_simple_dummy.h +1
-0@@ -107,6 +109,10 @@ enum iio_simple_dummy_scan_elements {DUMMY_INDEX_DIFFVOLTAGE_1M2 ,DUMMY_INDEX_DIFFVOLTAGE_3M4 ,DUMMY_INDEX_ACCELX , + DUMMY_INDEX_SOFT_TIMESTAMP,
Look at why we have timestamps at the end...
(start with iio_push_to_buffers_with_timestamp)
Jonathan
Quoted 6 lines
drivers/iio/dummy/iio_simple_dummy.h +3
-0+DUMMY_MAGN_X , +DUMMY_MAGN_Y , + DUMMY_MAGN_Z, };#ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
Hi Brajesh,
Quoted 10 lines · Brajesh Patil
This patch adds support for 3-axis magnetometer data (X, Y, Z) in the
iio_simple_dummydriver. It introduces three newIIO_MAGNchannels and populates them with dummy values for testing and prototyping purposes.Signed-off-by Brajesh Patil <[email protected]>--- drivers/iio/dummy/iio_simple_dummy.c | 71 +++++++++++++++++++++++++++- drivers/iio/dummy/iio_simple_dummy.h | 6 +++ 2 files changed, 75 insertions(+), 2 deletions(-)
I'm pretty sure the changes introduced in the IIO dummy tutorial [1] were for learning purposes only and not intended for upstreaming. I don't see a reason for updating the upstream dummy driver with those. It would also make the tutorial less interesting.
[1]: https://flusp.ime.usp.br/iio/experiment-one-iio-dummy/
So NACK for this patch.
Regards,
Marcelo