mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Cc: "David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Antoniu Miclaus" <antoniu.miclaus@analog.com>,
	"Andrew Ijano" <andrew.ijano@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Andy Shevchenko" <andriy.shevchenko@intel.com>
Subject: Re: [PATCH next v2] iio: sca3000: simplify with spi_get_device_match_data()
Date: Fri, 20 Feb 2026 10:51:07 +0000	[thread overview]
Message-ID: <20260220105001.7fce6c3c@jic23-huawei> (raw)
In-Reply-To: <20260216102453.1063866-1-harshit.m.mogalapalli@oracle.com>

On Mon, 16 Feb 2026 02:24:48 -0800
Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com> wrote:

> Refactor each sca3000 variant with it's own chip_info struct, update the
> sca3000_probe() to use spi_get_device_match_data().
> 
> Suggested-by: David Lechner <dlechner@baylibre.com>
> Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>

I made a couple of white space tweaks whilst applying.

Applied to the testing branch of iio.git.  There was quite
a bit of fuzz (line changes) but was all straight forward.

thanks,

Jonathan

> ---
> Only compile tested.
> 
> v1->v2: Andy suggested we drop a NULL check on
> spi_get_device_match_data() failure. Also added Andy's RB.
> ---
>  drivers/iio/accel/sca3000.c | 127 +++++++++++++++++-------------------
>  1 file changed, 59 insertions(+), 68 deletions(-)
> 
> diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
> index d4c117f54a07..eeb313056259 100644
> --- a/drivers/iio/accel/sca3000.c
> +++ b/drivers/iio/accel/sca3000.c
> @@ -172,6 +172,7 @@ struct sca3000_state {
>  
>  /**
>   * struct sca3000_chip_info - model dependent parameters
> + * @name:			name of the chip
>   * @scale:			scale * 10^-6
>   * @temp_output:		some devices have temperature sensors.
>   * @measurement_mode_freq:	normal mode sampling frequency
> @@ -194,6 +195,7 @@ struct sca3000_state {
>   * sca3000 variant.
>   **/
>  struct sca3000_chip_info {
> +	const char		*name;
>  	unsigned int		scale;
>  	bool			temp_output;
>  	int			measurement_mode_freq;
> @@ -208,69 +210,59 @@ struct sca3000_chip_info {
>  	int			mot_det_mult_y[7];
>  };
>  
> -enum sca3000_variant {
> -	d01,
> -	e02,
> -	e04,
> -	e05,
> +static const struct sca3000_chip_info sca3000_chip_info_d01 = {
> +	.name = "sca3000_d01",
> +	.scale = 7357,
> +	.temp_output = true,
> +	.measurement_mode_freq = 250,
> +	.measurement_mode_3db_freq = 45,
> +	.option_mode_1 = SCA3000_OP_MODE_BYPASS,
> +	.option_mode_1_freq = 250,
> +	.option_mode_1_3db_freq = 70,
> +	.mot_det_mult_xz = {50, 100, 200, 350, 650, 1300},

Trivial but whilst we are here, lets add spaces after { and before }

> +	.mot_det_mult_y = {50, 100, 150, 250, 450, 850, 1750},
>  };
>  
> -/*
> - * Note where option modes are not defined, the chip simply does not
> - * support any.
> - * Other chips in the sca3000 series use i2c and are not included here.
> - *
> - * Some of these devices are only listed in the family data sheet and
> - * do not actually appear to be available.
> - */
> -static const struct sca3000_chip_info sca3000_spi_chip_info_tbl[] = {
> -	[d01] = {
> -		.scale = 7357,
> -		.temp_output = true,
> -		.measurement_mode_freq = 250,
> -		.measurement_mode_3db_freq = 45,
> -		.option_mode_1 = SCA3000_OP_MODE_BYPASS,
> -		.option_mode_1_freq = 250,
> -		.option_mode_1_3db_freq = 70,
> -		.mot_det_mult_xz = {50, 100, 200, 350, 650, 1300},
> -		.mot_det_mult_y = {50, 100, 150, 250, 450, 850, 1750},
> -	},
> -	[e02] = {
> -		.scale = 9810,
> -		.measurement_mode_freq = 125,
> -		.measurement_mode_3db_freq = 40,
> -		.option_mode_1 = SCA3000_OP_MODE_NARROW,
> -		.option_mode_1_freq = 63,
> -		.option_mode_1_3db_freq = 11,
> -		.mot_det_mult_xz = {100, 150, 300, 550, 1050, 2050},
> -		.mot_det_mult_y = {50, 100, 200, 350, 700, 1350, 2700},
> -	},
> -	[e04] = {
> -		.scale = 19620,
> -		.measurement_mode_freq = 100,
> -		.measurement_mode_3db_freq = 38,
> -		.option_mode_1 = SCA3000_OP_MODE_NARROW,
> -		.option_mode_1_freq = 50,
> -		.option_mode_1_3db_freq = 9,
> -		.option_mode_2 = SCA3000_OP_MODE_WIDE,
> -		.option_mode_2_freq = 400,
> -		.option_mode_2_3db_freq = 70,
> -		.mot_det_mult_xz = {200, 300, 600, 1100, 2100, 4100},
> -		.mot_det_mult_y = {100, 200, 400, 7000, 1400, 2700, 54000},
> -	},
> -	[e05] = {
> -		.scale = 61313,
> -		.measurement_mode_freq = 200,
> -		.measurement_mode_3db_freq = 60,
> -		.option_mode_1 = SCA3000_OP_MODE_NARROW,
> -		.option_mode_1_freq = 50,
> -		.option_mode_1_3db_freq = 9,
> -		.option_mode_2 = SCA3000_OP_MODE_WIDE,
> -		.option_mode_2_freq = 400,
> -		.option_mode_2_3db_freq = 75,
> -		.mot_det_mult_xz = {600, 900, 1700, 3200, 6100, 11900},
> -		.mot_det_mult_y = {300, 600, 1200, 2000, 4100, 7800, 15600},
> -	},
> +static const struct sca3000_chip_info sca3000_chip_info_e02 = {
> +	.name = "sca3000_e02",
> +	.scale = 9810,
> +	.measurement_mode_freq = 125,
> +	.measurement_mode_3db_freq = 40,
> +	.option_mode_1 = SCA3000_OP_MODE_NARROW,
> +	.option_mode_1_freq = 63,
> +	.option_mode_1_3db_freq = 11,
> +	.mot_det_mult_xz = {100, 150, 300, 550, 1050, 2050},
> +	.mot_det_mult_y = {50, 100, 200, 350, 700, 1350, 2700},
> +};
> +
> +static const struct sca3000_chip_info sca3000_chip_info_e04 = {
> +	.name = "sca3000_e04",
> +	.scale = 19620,
> +	.measurement_mode_freq = 100,
> +	.measurement_mode_3db_freq = 38,
> +	.option_mode_1 = SCA3000_OP_MODE_NARROW,
> +	.option_mode_1_freq = 50,
> +	.option_mode_1_3db_freq = 9,
> +	.option_mode_2 = SCA3000_OP_MODE_WIDE,
> +	.option_mode_2_freq = 400,
> +	.option_mode_2_3db_freq = 70,
> +	.mot_det_mult_xz = {200, 300, 600, 1100, 2100, 4100},
> +	.mot_det_mult_y = {100, 200, 400, 7000, 1400, 2700, 54000},
> +};
> +
> +static const struct sca3000_chip_info sca3000_chip_info_e05 = {
> +	.name = "sca3000_e05",
> +	.scale = 61313,
> +	.measurement_mode_freq = 200,
> +	.measurement_mode_3db_freq = 60,
> +	.option_mode_1 = SCA3000_OP_MODE_NARROW,
> +	.option_mode_1_freq = 50,
> +	.option_mode_1_3db_freq = 9,
> +	.option_mode_2 = SCA3000_OP_MODE_WIDE,
> +	.option_mode_2_freq = 400,
> +	.option_mode_2_3db_freq = 75,
> +	.mot_det_mult_xz = {600, 900, 1700, 3200, 6100, 11900},
> +	.mot_det_mult_y = {300, 600, 1200, 2000, 4100, 7800, 15600},
>  };
>  
>  static int sca3000_write_reg(struct sca3000_state *st, u8 address, u8 val)
> @@ -1469,10 +1461,9 @@ static int sca3000_probe(struct spi_device *spi)
>  	st = iio_priv(indio_dev);
>  	st->us = spi;
>  	mutex_init(&st->lock);
> -	st->info = &sca3000_spi_chip_info_tbl[spi_get_device_id(spi)
> -					      ->driver_data];  
> +	st->info = spi_get_device_match_data(spi);
>  
> -	indio_dev->name = spi_get_device_id(spi)->name;
> +	indio_dev->name = st->info->name;
>  	indio_dev->info = &sca3000_info;
>  	if (st->info->temp_output) {
>  		indio_dev->channels = sca3000_channels_with_temp;
> @@ -1513,10 +1504,10 @@ static int sca3000_probe(struct spi_device *spi)
>  }
>  
>  static const struct spi_device_id sca3000_id[] = {
> -	{"sca3000_d01", d01},
> -	{"sca3000_e02", e02},
> -	{"sca3000_e04", e04},
> -	{"sca3000_e05", e05},
> +	{"sca3000_d01", (kernel_ulong_t)&sca3000_chip_info_d01},
> +	{"sca3000_e02", (kernel_ulong_t)&sca3000_chip_info_e02},
> +	{"sca3000_e04", (kernel_ulong_t)&sca3000_chip_info_e04},
> +	{"sca3000_e05", (kernel_ulong_t)&sca3000_chip_info_e05},
Similarly let's add some spaces to these.

>  	{ }
>  };
>  MODULE_DEVICE_TABLE(spi, sca3000_id);


  reply	other threads:[~2026-02-20 10:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-16 10:24 Harshit Mogalapalli
2026-02-20 10:51 ` Jonathan Cameron [this message]
2026-02-20 11:45   ` Harshit Mogalapalli
2026-02-24 16:23     ` Harshit Mogalapalli

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=20260220105001.7fce6c3c@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andrew.ijano@gmail.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=antoniu.miclaus@analog.com \
    --cc=dlechner@baylibre.com \
    --cc=harshit.m.mogalapalli@oracle.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /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

all inboxes | Powered by JetHome®