[PATCH v2 06/11] iio: adc: ad7793: use spi_get_device_match_data()
From: Nuno Sá
Date: Wed Dec 02 2026 - 12:07:19 EST
The chip info is looked up by indexing the chip info table with the
driver data of the matched SPI device id, assuming spi_get_device_id()
always finds a match. That is not guaranteed, e.g. when the device is
bound through driver_override.
Store the part name in struct ad7793_chip_info, point the SPI device id
table entries to the chip info and get it with
spi_get_device_match_data(). This also prepares for the upcoming
firmware support, as the same chip info can then be provided by an OF
match table.
Signed-off-by: Nuno Sá <nuno.sa@xxxxxxxxxx>
---
drivers/iio/adc/ad7793.c | 35 +++++++++++++++++++++++------------
1 file changed, 23 insertions(+), 12 deletions(-)
diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
index 937c8b09ad45..6a8f7212b6fd 100644
--- a/drivers/iio/adc/ad7793.c
+++ b/drivers/iio/adc/ad7793.c
@@ -141,6 +141,7 @@
#define AD7793_FLAG_HAS_BUFFER BIT(5)
struct ad7793_chip_info {
+ const char *name;
unsigned int id;
const struct iio_chan_spec *channels;
unsigned int num_channels;
@@ -676,6 +677,7 @@ static DECLARE_AD7799_CHANNELS(ad7799, 24, 32);
static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
[ID_AD7785] = {
+ .name = "ad7785",
.id = AD7785_ID,
.channels = ad7785_channels,
.num_channels = ARRAY_SIZE(ad7785_channels),
@@ -689,6 +691,7 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
AD7793_FLAG_HAS_BUFFER,
},
[ID_AD7792] = {
+ .name = "ad7792",
.id = AD7792_ID,
.channels = ad7792_channels,
.num_channels = ARRAY_SIZE(ad7792_channels),
@@ -702,6 +705,7 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
AD7793_FLAG_HAS_BUFFER,
},
[ID_AD7793] = {
+ .name = "ad7793",
.id = AD7793_ID,
.channels = ad7793_channels,
.num_channels = ARRAY_SIZE(ad7793_channels),
@@ -715,6 +719,7 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
AD7793_FLAG_HAS_BUFFER,
},
[ID_AD7794] = {
+ .name = "ad7794",
.id = AD7794_ID,
.channels = ad7794_channels,
.num_channels = ARRAY_SIZE(ad7794_channels),
@@ -728,6 +733,7 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
AD7793_FLAG_HAS_BUFFER,
},
[ID_AD7795] = {
+ .name = "ad7795",
.id = AD7795_ID,
.channels = ad7795_channels,
.num_channels = ARRAY_SIZE(ad7795_channels),
@@ -741,6 +747,7 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
AD7793_FLAG_HAS_BUFFER,
},
[ID_AD7796] = {
+ .name = "ad7796",
.id = AD7796_ID,
.channels = ad7796_channels,
.num_channels = ARRAY_SIZE(ad7796_channels),
@@ -749,6 +756,7 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
.flags = AD7793_FLAG_HAS_CLKSEL,
},
[ID_AD7797] = {
+ .name = "ad7797",
.id = AD7797_ID,
.channels = ad7797_channels,
.num_channels = ARRAY_SIZE(ad7797_channels),
@@ -757,6 +765,7 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
.flags = AD7793_FLAG_HAS_CLKSEL,
},
[ID_AD7798] = {
+ .name = "ad7798",
.id = AD7798_ID,
.channels = ad7798_channels,
.num_channels = ARRAY_SIZE(ad7798_channels),
@@ -766,6 +775,7 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
AD7793_FLAG_HAS_BUFFER,
},
[ID_AD7799] = {
+ .name = "ad7799",
.id = AD7799_ID,
.channels = ad7799_channels,
.num_channels = ARRAY_SIZE(ad7799_channels),
@@ -810,10 +820,11 @@ static int ad7793_probe(struct spi_device *spi)
vref_mv = 1170; /* Built-in ref */
}
- st->chip_info =
- &ad7793_chip_info_tbl[spi_get_device_id(spi)->driver_data];
+ st->chip_info = spi_get_device_match_data(spi);
+ if (!st->chip_info)
+ return -ENODEV;
- indio_dev->name = spi_get_device_id(spi)->name;
+ indio_dev->name = st->chip_info->name;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = st->chip_info->channels;
indio_dev->num_channels = st->chip_info->num_channels;
@@ -831,15 +842,15 @@ static int ad7793_probe(struct spi_device *spi)
}
static const struct spi_device_id ad7793_id[] = {
- { .name = "ad7785", .driver_data = ID_AD7785 },
- { .name = "ad7792", .driver_data = ID_AD7792 },
- { .name = "ad7793", .driver_data = ID_AD7793 },
- { .name = "ad7794", .driver_data = ID_AD7794 },
- { .name = "ad7795", .driver_data = ID_AD7795 },
- { .name = "ad7796", .driver_data = ID_AD7796 },
- { .name = "ad7797", .driver_data = ID_AD7797 },
- { .name = "ad7798", .driver_data = ID_AD7798 },
- { .name = "ad7799", .driver_data = ID_AD7799 },
+ { .name = "ad7785", .driver_data = (kernel_ulong_t)&ad7793_chip_info_tbl[ID_AD7785] },
+ { .name = "ad7792", .driver_data = (kernel_ulong_t)&ad7793_chip_info_tbl[ID_AD7792] },
+ { .name = "ad7793", .driver_data = (kernel_ulong_t)&ad7793_chip_info_tbl[ID_AD7793] },
+ { .name = "ad7794", .driver_data = (kernel_ulong_t)&ad7793_chip_info_tbl[ID_AD7794] },
+ { .name = "ad7795", .driver_data = (kernel_ulong_t)&ad7793_chip_info_tbl[ID_AD7795] },
+ { .name = "ad7796", .driver_data = (kernel_ulong_t)&ad7793_chip_info_tbl[ID_AD7796] },
+ { .name = "ad7797", .driver_data = (kernel_ulong_t)&ad7793_chip_info_tbl[ID_AD7797] },
+ { .name = "ad7798", .driver_data = (kernel_ulong_t)&ad7793_chip_info_tbl[ID_AD7798] },
+ { .name = "ad7799", .driver_data = (kernel_ulong_t)&ad7793_chip_info_tbl[ID_AD7799] },
{ }
};
MODULE_DEVICE_TABLE(spi, ad7793_id);
--
2.56.0