drivers/iio/accel/sca3000.c | 127 +++++++++++++++++------------------- 1 file changed, 59 insertions(+), 68 deletions(-)
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>
---
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},
+ .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},
{ }
};
MODULE_DEVICE_TABLE(spi, sca3000_id);
--
2.50.1
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);
Hi Jonathan,
On 20/02/26 16:21, Jonathan Cameron wrote:
> 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.
>
Oh, sorry for that. Maybe because these patches:
https://lore.kernel.org/all/20260205195845.4e108117@jic23-huawei/ were
not present ?
I don't see them here:
https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/log/drivers/iio/accel/sca3000.c?h=testing
, so asking.
This patch might have applied cleaner with the above series applied.
> 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 {
>>
...
>>
>> 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.
>
I didn't add the space mostly because there were not there before. Will
check for other similar drivers next time, thanks a lot for dealing with
them by yourself.
Thanks,
Harshit
>> { }
>> };
>> MODULE_DEVICE_TABLE(spi, sca3000_id);
>
Hi Jonathan, On 20/02/26 17:15, Harshit Mogalapalli wrote: >> >> Applied to the testing branch of iio.git. There was quite >> a bit of fuzz (line changes) but was all straight forward. >> > > Oh, sorry for that. Maybe because these patches: https:// > lore.kernel.org/all/20260205195845.4e108117@jic23-huawei/ were not > present ? > > I don't see them here: https://git.kernel.org/pub/scm/linux/kernel/git/ > jic23/iio.git/log/drivers/iio/accel/sca3000.c?h=testing , so asking. > > This patch might have applied cleaner with the above series applied. ping on this. Sorry if this is being tracked. the possible reason for line changes is that https://lore.kernel.org/all/20260205195845.4e108117@jic23-huawei/ patches are not part of the branch here: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/log/?h=testing While working on new patches is the testing branch right branch to use ? Thanks, Harshit
© 2016 - 2026 Red Hat, Inc.