* [PATCH next] iio: sca3000: simplify with spi_get_device_match_data()
@ 2026-02-16 9:51 Harshit Mogalapalli
2026-02-16 10:03 ` Andy Shevchenko
0 siblings, 1 reply; 4+ messages in thread
From: Harshit Mogalapalli @ 2026-02-16 9:51 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Harshit Mogalapalli, Andrew Ijano, Antoniu Miclaus, linux-iio,
linux-kernel
Cc: Andy Shevchenko
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>
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
Only compile tested.
---
drivers/iio/accel/sca3000.c | 129 +++++++++++++++++-------------------
1 file changed, 61 insertions(+), 68 deletions(-)
diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
index d4c117f54a07..9d6ee83f48ae 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},
+ .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,11 @@ 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);
+ if (!st->info)
+ return -EINVAL;
- 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 +1506,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},
{ }
};
MODULE_DEVICE_TABLE(spi, sca3000_id);
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH next] iio: sca3000: simplify with spi_get_device_match_data()
2026-02-16 9:51 [PATCH next] iio: sca3000: simplify with spi_get_device_match_data() Harshit Mogalapalli
@ 2026-02-16 10:03 ` Andy Shevchenko
2026-02-16 10:15 ` Harshit Mogalapalli
0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2026-02-16 10:03 UTC (permalink / raw)
To: Harshit Mogalapalli
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Andrew Ijano, Antoniu Miclaus, linux-iio, linux-kernel
On Mon, Feb 16, 2026 at 01:51:05AM -0800, Harshit Mogalapalli wrote:
> Refactor each sca3000 variant with it's own chip_info struct, update the
> sca3000_probe() to use spi_get_device_match_data().
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
...
> - st->info = &sca3000_spi_chip_info_tbl[spi_get_device_id(spi)
> - ->driver_data];
> + st->info = spi_get_device_match_data(spi);
> + if (!st->info)
> + return -EINVAL;
This is a dead check. Just make it a requirement and drop dead code.
The support of a new HW will be assumed not tested at all if there
is no driver_data.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH next] iio: sca3000: simplify with spi_get_device_match_data()
2026-02-16 10:03 ` Andy Shevchenko
@ 2026-02-16 10:15 ` Harshit Mogalapalli
2026-02-17 7:49 ` Andy Shevchenko
0 siblings, 1 reply; 4+ messages in thread
From: Harshit Mogalapalli @ 2026-02-16 10:15 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Andrew Ijano, Antoniu Miclaus, linux-iio, linux-kernel
Hi Andy,
On 16/02/26 15:33, Andy Shevchenko wrote:
> On Mon, Feb 16, 2026 at 01:51:05AM -0800, Harshit Mogalapalli wrote:
>> Refactor each sca3000 variant with it's own chip_info struct, update the
>> sca3000_probe() to use spi_get_device_match_data().
>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
>
Thanks for the review!
> ...
>
>> - st->info = &sca3000_spi_chip_info_tbl[spi_get_device_id(spi)
>> - ->driver_data];
>> + st->info = spi_get_device_match_data(spi);
>
>> + if (!st->info)
>> + return -EINVAL;
>
> This is a dead check. Just make it a requirement and drop dead code.
> The support of a new HW will be assumed not tested at all if there
> is no driver_data.
>
I agree, will drop the check in V2.
There are a few commits like this which added NULL checks, so I was not
fully sure.
commit: c5d8facf107a ("iio: adc: ad7192: properly check
spi_get_device_match_data()")
Thanks,
Harshit
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH next] iio: sca3000: simplify with spi_get_device_match_data()
2026-02-16 10:15 ` Harshit Mogalapalli
@ 2026-02-17 7:49 ` Andy Shevchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-02-17 7:49 UTC (permalink / raw)
To: Harshit Mogalapalli
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Andrew Ijano, Antoniu Miclaus, linux-iio, linux-kernel
On Mon, Feb 16, 2026 at 03:45:34PM +0530, Harshit Mogalapalli wrote:
> On 16/02/26 15:33, Andy Shevchenko wrote:
> > On Mon, Feb 16, 2026 at 01:51:05AM -0800, Harshit Mogalapalli wrote:
...
> > > - st->info = &sca3000_spi_chip_info_tbl[spi_get_device_id(spi)
> > > - ->driver_data];
> > > + st->info = spi_get_device_match_data(spi);
> >
> > > + if (!st->info)
> > > + return -EINVAL;
> >
> > This is a dead check. Just make it a requirement and drop dead code.
> > The support of a new HW will be assumed not tested at all if there
> > is no driver_data.
>
> I agree, will drop the check in V2.
>
> There are a few commits like this which added NULL checks, so I was not
> fully sure.
>
> commit: c5d8facf107a ("iio: adc: ad7192: properly check
> spi_get_device_match_data()")
Nice catch!
That change is unneeded churn that adds a dead code as it looks like.
Nuno, can you elaborate the motivation behind that?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-02-17 7:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-16 9:51 [PATCH next] iio: sca3000: simplify with spi_get_device_match_data() Harshit Mogalapalli
2026-02-16 10:03 ` Andy Shevchenko
2026-02-16 10:15 ` Harshit Mogalapalli
2026-02-17 7:49 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox