Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Brajesh Patil <brajeshpatil11@gmail.com>
Cc: linux-iio@vger.kernel.org, lars@metafoo.de,
	linux-kernel@vger.kernel.org, outreachy@lists.linux.dev
Subject: Re: [PATCH v1 1/1] iio: dummy: Add 3-axis compass (magnetometer) channels to the iio_simple_dummy
Date: Sun, 6 Apr 2025 16:39:13 +0100	[thread overview]
Message-ID: <20250406163913.6a7234fb@jic23-huawei> (raw)
In-Reply-To: <20250406133349.50633-1-brajeshpatil11@gmail.com>

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


  parent reply	other threads:[~2025-04-06 15:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2025-04-06 17:42 ` Marcelo Schmitt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250406163913.6a7234fb@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=brajeshpatil11@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=outreachy@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox