* [PATCH v1 1/1] iio: dummy: Add 3-axis compass (magnetometer) channels to the iio_simple_dummy
@ 2025-04-06 13:33 Brajesh Patil
2025-04-06 13:41 ` Julia Lawall
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Brajesh Patil @ 2025-04-06 13:33 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, lars, linux-kernel, outreachy, Brajesh Patil
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.
Signed-off-by: Brajesh Patil <brajeshpatil11@gmail.com>
---
drivers/iio/dummy/iio_simple_dummy.c | 71 +++++++++++++++++++++++++++-
drivers/iio/dummy/iio_simple_dummy.h | 6 +++
2 files changed, 75 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/dummy/iio_simple_dummy.c b/drivers/iio/dummy/iio_simple_dummy.c
index 8575d4a08..713b764c9 100644
--- a/drivers/iio/dummy/iio_simple_dummy.c
+++ b/drivers/iio/dummy/iio_simple_dummy.c
@@ -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 <jic23@kernel.org>");
-MODULE_DESCRIPTION("IIO dummy driver");
+MODULE_DESCRIPTION("IIO dummy driver -> IIO dummy modified by Me");
MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/dummy/iio_simple_dummy.h b/drivers/iio/dummy/iio_simple_dummy.h
index 8246f25db..e05d8b5cc 100644
--- a/drivers/iio/dummy/iio_simple_dummy.h
+++ b/drivers/iio/dummy/iio_simple_dummy.h
@@ -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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v1 1/1] iio: dummy: Add 3-axis compass (magnetometer) channels to the iio_simple_dummy
2025-04-06 13:33 [PATCH v1 1/1] iio: dummy: Add 3-axis compass (magnetometer) channels to the iio_simple_dummy Brajesh Patil
@ 2025-04-06 13:41 ` Julia Lawall
2025-04-06 15:39 ` Jonathan Cameron
2025-04-06 17:42 ` Marcelo Schmitt
2 siblings, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2025-04-06 13:41 UTC (permalink / raw)
To: Brajesh Patil; +Cc: linux-iio, jic23, lars, linux-kernel, outreachy
On Sun, 6 Apr 2025, Brajesh Patil wrote:
> 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.
Is this intended as a contribution for outreachy? It is not working on a
staging driver.
julia
>
> Signed-off-by: Brajesh Patil <brajeshpatil11@gmail.com>
> ---
> drivers/iio/dummy/iio_simple_dummy.c | 71 +++++++++++++++++++++++++++-
> drivers/iio/dummy/iio_simple_dummy.h | 6 +++
> 2 files changed, 75 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/dummy/iio_simple_dummy.c b/drivers/iio/dummy/iio_simple_dummy.c
> index 8575d4a08..713b764c9 100644
> --- a/drivers/iio/dummy/iio_simple_dummy.c
> +++ b/drivers/iio/dummy/iio_simple_dummy.c
> @@ -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 <jic23@kernel.org>");
> -MODULE_DESCRIPTION("IIO dummy driver");
> +MODULE_DESCRIPTION("IIO dummy driver -> IIO dummy modified by Me");
> MODULE_LICENSE("GPL v2");
> diff --git a/drivers/iio/dummy/iio_simple_dummy.h b/drivers/iio/dummy/iio_simple_dummy.h
> index 8246f25db..e05d8b5cc 100644
> --- a/drivers/iio/dummy/iio_simple_dummy.h
> +++ b/drivers/iio/dummy/iio_simple_dummy.h
> @@ -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
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1 1/1] iio: dummy: Add 3-axis compass (magnetometer) channels to the iio_simple_dummy
2025-04-06 13:33 [PATCH v1 1/1] iio: dummy: Add 3-axis compass (magnetometer) channels to the iio_simple_dummy Brajesh Patil
2025-04-06 13:41 ` Julia Lawall
@ 2025-04-06 15:39 ` Jonathan Cameron
2025-04-06 17:42 ` Marcelo Schmitt
2 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2025-04-06 15:39 UTC (permalink / raw)
To: Brajesh Patil; +Cc: linux-iio, lars, linux-kernel, outreachy
On Sun, 6 Apr 2025 19:03:49 +0530
Brajesh Patil <brajeshpatil11@gmail.com> wrote:
> 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.
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.
>
> Signed-off-by: Brajesh Patil <brajeshpatil11@gmail.com>
> ---
> drivers/iio/dummy/iio_simple_dummy.c | 71 +++++++++++++++++++++++++++-
> drivers/iio/dummy/iio_simple_dummy.h | 6 +++
> 2 files changed, 75 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/dummy/iio_simple_dummy.c b/drivers/iio/dummy/iio_simple_dummy.c
> index 8575d4a08..713b764c9 100644
> --- a/drivers/iio/dummy/iio_simple_dummy.c
> +++ b/drivers/iio/dummy/iio_simple_dummy.c
> @@ -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,
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)/
> + },
> + },
> + {
> + .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
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).
> + *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.
>
> + 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 <jic23@kernel.org>");
> -MODULE_DESCRIPTION("IIO dummy driver");
> +MODULE_DESCRIPTION("IIO dummy driver -> IIO dummy modified by Me");
Accidental send?
> MODULE_LICENSE("GPL v2");
> diff --git a/drivers/iio/dummy/iio_simple_dummy.h b/drivers/iio/dummy/iio_simple_dummy.h
> index 8246f25db..e05d8b5cc 100644
> --- a/drivers/iio/dummy/iio_simple_dummy.h
> +++ b/drivers/iio/dummy/iio_simple_dummy.h
> @@ -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,
Look at why we have timestamps at the end...
(start with iio_push_to_buffers_with_timestamp)
Jonathan
> + DUMMY_MAGN_X,
> + DUMMY_MAGN_Y,
> + DUMMY_MAGN_Z,
> };
>
> #ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1 1/1] iio: dummy: Add 3-axis compass (magnetometer) channels to the iio_simple_dummy
2025-04-06 13:33 [PATCH v1 1/1] iio: dummy: Add 3-axis compass (magnetometer) channels to the iio_simple_dummy Brajesh Patil
2025-04-06 13:41 ` Julia Lawall
2025-04-06 15:39 ` Jonathan Cameron
@ 2025-04-06 17:42 ` Marcelo Schmitt
2 siblings, 0 replies; 4+ messages in thread
From: Marcelo Schmitt @ 2025-04-06 17:42 UTC (permalink / raw)
To: Brajesh Patil; +Cc: linux-iio, jic23, lars, linux-kernel, outreachy
Hi Brajesh,
On 04/06, Brajesh Patil wrote:
> 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.
>
> Signed-off-by: Brajesh Patil <brajeshpatil11@gmail.com>
> ---
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-06 17:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-06 13:33 [PATCH v1 1/1] iio: dummy: Add 3-axis compass (magnetometer) channels to the iio_simple_dummy Brajesh Patil
2025-04-06 13:41 ` Julia Lawall
2025-04-06 15:39 ` Jonathan Cameron
2025-04-06 17:42 ` Marcelo Schmitt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox