drivers/iio/adc/ad7173.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-)
Fix the num_slots value for most chips in the ad7173 driver. The correct
value is the number of CHANNELx registers on the chip.
In commit 4310e15b3140 ("iio: adc: ad7173: don't make copy of
ad_sigma_delta_info struct"), we refactored struct ad_sigma_delta_info
to be static const data instead of being dynamically populated during
driver probe. However, there was an existing bug in commit 76a1e6a42802
("iio: adc: ad7173: add AD7173 driver") where num_slots was incorrectly
set to the number of CONFIGx registers instead of the number of
CHANNELx registers. This bug was partially propagated to the refactored
code in that the 16-channel chips were only given 8 slots instead of
16 although we did managed to fix the 8-channel chips and one of the
4-channel chips in that commit. However, we botched two of the 4-channel
chips and ended up incorrectly giving them 8 slots during the
refactoring.
This patch fixes that mistake on the 4-channel chips and also
corrects the 16-channel chips to have 16 slots.
Fixes: 4310e15b3140 ("iio: adc: ad7173: don't make copy of ad_sigma_delta_info struct")
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
Here is the patch that actually compiles on the fixes-togreg branch.
---
Changes in v3:
- Drop supports_spi_offload field.
- Link to v2: https://lore.kernel.org/r/20250704-iio-adc-ad7173-fix-num_slots-on-most-chips-v2-1-a74941609143@baylibre.com
Changes in v2:
- Improve commit message.
- Link to v1: https://lore.kernel.org/r/20250703-iio-adc-ad7173-fix-num_slots-on-most-chips-v1-1-326c5d113e15@baylibre.com
---
drivers/iio/adc/ad7173.c | 36 ++++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c
index 1966a9bc331401af118334a7be4c1a5b8d381473..c41bc5b9ac597f57eea6a097cc3a118de7b42210 100644
--- a/drivers/iio/adc/ad7173.c
+++ b/drivers/iio/adc/ad7173.c
@@ -772,10 +772,26 @@ static const struct ad_sigma_delta_info ad7173_sigma_delta_info_8_slots = {
.num_slots = 8,
};
+static const struct ad_sigma_delta_info ad7173_sigma_delta_info_16_slots = {
+ .set_channel = ad7173_set_channel,
+ .append_status = ad7173_append_status,
+ .disable_all = ad7173_disable_all,
+ .disable_one = ad7173_disable_one,
+ .set_mode = ad7173_set_mode,
+ .has_registers = true,
+ .has_named_irqs = true,
+ .addr_shift = 0,
+ .read_mask = BIT(6),
+ .status_ch_mask = GENMASK(3, 0),
+ .data_reg = AD7173_REG_DATA,
+ .num_resetclks = 64,
+ .num_slots = 16,
+};
+
static const struct ad7173_device_info ad4111_device_info = {
.name = "ad4111",
.id = AD4111_ID,
- .sd_info = &ad7173_sigma_delta_info_8_slots,
+ .sd_info = &ad7173_sigma_delta_info_16_slots,
.num_voltage_in_div = 8,
.num_channels = 16,
.num_configs = 8,
@@ -797,7 +813,7 @@ static const struct ad7173_device_info ad4111_device_info = {
static const struct ad7173_device_info ad4112_device_info = {
.name = "ad4112",
.id = AD4112_ID,
- .sd_info = &ad7173_sigma_delta_info_8_slots,
+ .sd_info = &ad7173_sigma_delta_info_16_slots,
.num_voltage_in_div = 8,
.num_channels = 16,
.num_configs = 8,
@@ -818,7 +834,7 @@ static const struct ad7173_device_info ad4112_device_info = {
static const struct ad7173_device_info ad4113_device_info = {
.name = "ad4113",
.id = AD4113_ID,
- .sd_info = &ad7173_sigma_delta_info_8_slots,
+ .sd_info = &ad7173_sigma_delta_info_16_slots,
.num_voltage_in_div = 8,
.num_channels = 16,
.num_configs = 8,
@@ -837,7 +853,7 @@ static const struct ad7173_device_info ad4113_device_info = {
static const struct ad7173_device_info ad4114_device_info = {
.name = "ad4114",
.id = AD4114_ID,
- .sd_info = &ad7173_sigma_delta_info_8_slots,
+ .sd_info = &ad7173_sigma_delta_info_16_slots,
.num_voltage_in_div = 16,
.num_channels = 16,
.num_configs = 8,
@@ -856,7 +872,7 @@ static const struct ad7173_device_info ad4114_device_info = {
static const struct ad7173_device_info ad4115_device_info = {
.name = "ad4115",
.id = AD4115_ID,
- .sd_info = &ad7173_sigma_delta_info_8_slots,
+ .sd_info = &ad7173_sigma_delta_info_16_slots,
.num_voltage_in_div = 16,
.num_channels = 16,
.num_configs = 8,
@@ -875,7 +891,7 @@ static const struct ad7173_device_info ad4115_device_info = {
static const struct ad7173_device_info ad4116_device_info = {
.name = "ad4116",
.id = AD4116_ID,
- .sd_info = &ad7173_sigma_delta_info_8_slots,
+ .sd_info = &ad7173_sigma_delta_info_16_slots,
.num_voltage_in_div = 11,
.num_channels = 16,
.num_configs = 8,
@@ -894,7 +910,7 @@ static const struct ad7173_device_info ad4116_device_info = {
static const struct ad7173_device_info ad7172_2_device_info = {
.name = "ad7172-2",
.id = AD7172_2_ID,
- .sd_info = &ad7173_sigma_delta_info_8_slots,
+ .sd_info = &ad7173_sigma_delta_info_4_slots,
.num_voltage_in = 5,
.num_channels = 4,
.num_configs = 4,
@@ -927,7 +943,7 @@ static const struct ad7173_device_info ad7172_4_device_info = {
static const struct ad7173_device_info ad7173_8_device_info = {
.name = "ad7173-8",
.id = AD7173_ID,
- .sd_info = &ad7173_sigma_delta_info_8_slots,
+ .sd_info = &ad7173_sigma_delta_info_16_slots,
.num_voltage_in = 17,
.num_channels = 16,
.num_configs = 8,
@@ -944,7 +960,7 @@ static const struct ad7173_device_info ad7173_8_device_info = {
static const struct ad7173_device_info ad7175_2_device_info = {
.name = "ad7175-2",
.id = AD7175_2_ID,
- .sd_info = &ad7173_sigma_delta_info_8_slots,
+ .sd_info = &ad7173_sigma_delta_info_4_slots,
.num_voltage_in = 5,
.num_channels = 4,
.num_configs = 4,
@@ -961,7 +977,7 @@ static const struct ad7173_device_info ad7175_2_device_info = {
static const struct ad7173_device_info ad7175_8_device_info = {
.name = "ad7175-8",
.id = AD7175_8_ID,
- .sd_info = &ad7173_sigma_delta_info_8_slots,
+ .sd_info = &ad7173_sigma_delta_info_16_slots,
.num_voltage_in = 17,
.num_channels = 16,
.num_configs = 8,
---
base-commit: 731bfc181896a4dfd20a8c219bef1c205dd1d708
change-id: 20250703-iio-adc-ad7173-fix-num_slots-on-most-chips-b982206a20b1
Best regards,
--
David Lechner <dlechner@baylibre.com>
On Sun, 2025-07-06 at 13:53 -0500, David Lechner wrote: > Fix the num_slots value for most chips in the ad7173 driver. The correct > value is the number of CHANNELx registers on the chip. > > In commit 4310e15b3140 ("iio: adc: ad7173: don't make copy of > ad_sigma_delta_info struct"), we refactored struct ad_sigma_delta_info > to be static const data instead of being dynamically populated during > driver probe. However, there was an existing bug in commit 76a1e6a42802 > ("iio: adc: ad7173: add AD7173 driver") where num_slots was incorrectly > set to the number of CONFIGx registers instead of the number of > CHANNELx registers. This bug was partially propagated to the refactored > code in that the 16-channel chips were only given 8 slots instead of > 16 although we did managed to fix the 8-channel chips and one of the > 4-channel chips in that commit. However, we botched two of the 4-channel > chips and ended up incorrectly giving them 8 slots during the > refactoring. > > This patch fixes that mistake on the 4-channel chips and also > corrects the 16-channel chips to have 16 slots. > > Fixes: 4310e15b3140 ("iio: adc: ad7173: don't make copy of ad_sigma_delta_info > struct") > Signed-off-by: David Lechner <dlechner@baylibre.com> > --- Reviewed-by: Nuno Sá <nuno.sa@analog.com> > Here is the patch that actually compiles on the fixes-togreg branch. > --- > Changes in v3: > - Drop supports_spi_offload field. > - Link to v2: > https://lore.kernel.org/r/20250704-iio-adc-ad7173-fix-num_slots-on-most-chips-v2-1-a74941609143@baylibre.com > > Changes in v2: > - Improve commit message. > - Link to v1: > https://lore.kernel.org/r/20250703-iio-adc-ad7173-fix-num_slots-on-most-chips-v1-1-326c5d113e15@baylibre.com > --- > drivers/iio/adc/ad7173.c | 36 ++++++++++++++++++++++++++---------- > 1 file changed, 26 insertions(+), 10 deletions(-) > > diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c > index > 1966a9bc331401af118334a7be4c1a5b8d381473..c41bc5b9ac597f57eea6a097cc3a118de7b4 > 2210 100644 > --- a/drivers/iio/adc/ad7173.c > +++ b/drivers/iio/adc/ad7173.c > @@ -772,10 +772,26 @@ static const struct ad_sigma_delta_info > ad7173_sigma_delta_info_8_slots = { > .num_slots = 8, > }; > > +static const struct ad_sigma_delta_info ad7173_sigma_delta_info_16_slots = { > + .set_channel = ad7173_set_channel, > + .append_status = ad7173_append_status, > + .disable_all = ad7173_disable_all, > + .disable_one = ad7173_disable_one, > + .set_mode = ad7173_set_mode, > + .has_registers = true, > + .has_named_irqs = true, > + .addr_shift = 0, > + .read_mask = BIT(6), > + .status_ch_mask = GENMASK(3, 0), > + .data_reg = AD7173_REG_DATA, > + .num_resetclks = 64, > + .num_slots = 16, > +}; > + > static const struct ad7173_device_info ad4111_device_info = { > .name = "ad4111", > .id = AD4111_ID, > - .sd_info = &ad7173_sigma_delta_info_8_slots, > + .sd_info = &ad7173_sigma_delta_info_16_slots, > .num_voltage_in_div = 8, > .num_channels = 16, > .num_configs = 8, > @@ -797,7 +813,7 @@ static const struct ad7173_device_info ad4111_device_info > = { > static const struct ad7173_device_info ad4112_device_info = { > .name = "ad4112", > .id = AD4112_ID, > - .sd_info = &ad7173_sigma_delta_info_8_slots, > + .sd_info = &ad7173_sigma_delta_info_16_slots, > .num_voltage_in_div = 8, > .num_channels = 16, > .num_configs = 8, > @@ -818,7 +834,7 @@ static const struct ad7173_device_info ad4112_device_info > = { > static const struct ad7173_device_info ad4113_device_info = { > .name = "ad4113", > .id = AD4113_ID, > - .sd_info = &ad7173_sigma_delta_info_8_slots, > + .sd_info = &ad7173_sigma_delta_info_16_slots, > .num_voltage_in_div = 8, > .num_channels = 16, > .num_configs = 8, > @@ -837,7 +853,7 @@ static const struct ad7173_device_info ad4113_device_info > = { > static const struct ad7173_device_info ad4114_device_info = { > .name = "ad4114", > .id = AD4114_ID, > - .sd_info = &ad7173_sigma_delta_info_8_slots, > + .sd_info = &ad7173_sigma_delta_info_16_slots, > .num_voltage_in_div = 16, > .num_channels = 16, > .num_configs = 8, > @@ -856,7 +872,7 @@ static const struct ad7173_device_info ad4114_device_info > = { > static const struct ad7173_device_info ad4115_device_info = { > .name = "ad4115", > .id = AD4115_ID, > - .sd_info = &ad7173_sigma_delta_info_8_slots, > + .sd_info = &ad7173_sigma_delta_info_16_slots, > .num_voltage_in_div = 16, > .num_channels = 16, > .num_configs = 8, > @@ -875,7 +891,7 @@ static const struct ad7173_device_info ad4115_device_info > = { > static const struct ad7173_device_info ad4116_device_info = { > .name = "ad4116", > .id = AD4116_ID, > - .sd_info = &ad7173_sigma_delta_info_8_slots, > + .sd_info = &ad7173_sigma_delta_info_16_slots, > .num_voltage_in_div = 11, > .num_channels = 16, > .num_configs = 8, > @@ -894,7 +910,7 @@ static const struct ad7173_device_info ad4116_device_info > = { > static const struct ad7173_device_info ad7172_2_device_info = { > .name = "ad7172-2", > .id = AD7172_2_ID, > - .sd_info = &ad7173_sigma_delta_info_8_slots, > + .sd_info = &ad7173_sigma_delta_info_4_slots, > .num_voltage_in = 5, > .num_channels = 4, > .num_configs = 4, > @@ -927,7 +943,7 @@ static const struct ad7173_device_info > ad7172_4_device_info = { > static const struct ad7173_device_info ad7173_8_device_info = { > .name = "ad7173-8", > .id = AD7173_ID, > - .sd_info = &ad7173_sigma_delta_info_8_slots, > + .sd_info = &ad7173_sigma_delta_info_16_slots, > .num_voltage_in = 17, > .num_channels = 16, > .num_configs = 8, > @@ -944,7 +960,7 @@ static const struct ad7173_device_info > ad7173_8_device_info = { > static const struct ad7173_device_info ad7175_2_device_info = { > .name = "ad7175-2", > .id = AD7175_2_ID, > - .sd_info = &ad7173_sigma_delta_info_8_slots, > + .sd_info = &ad7173_sigma_delta_info_4_slots, > .num_voltage_in = 5, > .num_channels = 4, > .num_configs = 4, > @@ -961,7 +977,7 @@ static const struct ad7173_device_info > ad7175_2_device_info = { > static const struct ad7173_device_info ad7175_8_device_info = { > .name = "ad7175-8", > .id = AD7175_8_ID, > - .sd_info = &ad7173_sigma_delta_info_8_slots, > + .sd_info = &ad7173_sigma_delta_info_16_slots, > .num_voltage_in = 17, > .num_channels = 16, > .num_configs = 8, > > --- > base-commit: 731bfc181896a4dfd20a8c219bef1c205dd1d708 > change-id: 20250703-iio-adc-ad7173-fix-num_slots-on-most-chips-b982206a20b1 > > Best regards,
On Mon, 07 Jul 2025 09:06:16 +0100 Nuno Sá <noname.nuno@gmail.com> wrote: > On Sun, 2025-07-06 at 13:53 -0500, David Lechner wrote: > > Fix the num_slots value for most chips in the ad7173 driver. The correct > > value is the number of CHANNELx registers on the chip. > > > > In commit 4310e15b3140 ("iio: adc: ad7173: don't make copy of > > ad_sigma_delta_info struct"), we refactored struct ad_sigma_delta_info > > to be static const data instead of being dynamically populated during > > driver probe. However, there was an existing bug in commit 76a1e6a42802 > > ("iio: adc: ad7173: add AD7173 driver") where num_slots was incorrectly > > set to the number of CONFIGx registers instead of the number of > > CHANNELx registers. This bug was partially propagated to the refactored > > code in that the 16-channel chips were only given 8 slots instead of > > 16 although we did managed to fix the 8-channel chips and one of the > > 4-channel chips in that commit. However, we botched two of the 4-channel > > chips and ended up incorrectly giving them 8 slots during the > > refactoring. > > > > This patch fixes that mistake on the 4-channel chips and also > > corrects the 16-channel chips to have 16 slots. > > > > Fixes: 4310e15b3140 ("iio: adc: ad7173: don't make copy of ad_sigma_delta_info > > struct") > > Signed-off-by: David Lechner <dlechner@baylibre.com> > > --- > > Reviewed-by: Nuno Sá <nuno.sa@analog.com> As discussed. Dropped patch 12 of the other series. Applied this one to the fixes-togreg branch of iio.git. I'll let it soak a couple of days before I do a pull request. > > > Here is the patch that actually compiles on the fixes-togreg branch. > > --- > > Changes in v3: > > - Drop supports_spi_offload field. > > - Link to v2: > > https://lore.kernel.org/r/20250704-iio-adc-ad7173-fix-num_slots-on-most-chips-v2-1-a74941609143@baylibre.com > > > > Changes in v2: > > - Improve commit message. > > - Link to v1: > > https://lore.kernel.org/r/20250703-iio-adc-ad7173-fix-num_slots-on-most-chips-v1-1-326c5d113e15@baylibre.com > > --- > > drivers/iio/adc/ad7173.c | 36 ++++++++++++++++++++++++++---------- > > 1 file changed, 26 insertions(+), 10 deletions(-) > > > > diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c > > index > > 1966a9bc331401af118334a7be4c1a5b8d381473..c41bc5b9ac597f57eea6a097cc3a118de7b4 > > 2210 100644 > > --- a/drivers/iio/adc/ad7173.c > > +++ b/drivers/iio/adc/ad7173.c > > @@ -772,10 +772,26 @@ static const struct ad_sigma_delta_info > > ad7173_sigma_delta_info_8_slots = { > > .num_slots = 8, > > }; > > > > +static const struct ad_sigma_delta_info ad7173_sigma_delta_info_16_slots = { > > + .set_channel = ad7173_set_channel, > > + .append_status = ad7173_append_status, > > + .disable_all = ad7173_disable_all, > > + .disable_one = ad7173_disable_one, > > + .set_mode = ad7173_set_mode, > > + .has_registers = true, > > + .has_named_irqs = true, > > + .addr_shift = 0, > > + .read_mask = BIT(6), > > + .status_ch_mask = GENMASK(3, 0), > > + .data_reg = AD7173_REG_DATA, > > + .num_resetclks = 64, > > + .num_slots = 16, > > +}; > > + > > static const struct ad7173_device_info ad4111_device_info = { > > .name = "ad4111", > > .id = AD4111_ID, > > - .sd_info = &ad7173_sigma_delta_info_8_slots, > > + .sd_info = &ad7173_sigma_delta_info_16_slots, > > .num_voltage_in_div = 8, > > .num_channels = 16, > > .num_configs = 8, > > @@ -797,7 +813,7 @@ static const struct ad7173_device_info ad4111_device_info > > = { > > static const struct ad7173_device_info ad4112_device_info = { > > .name = "ad4112", > > .id = AD4112_ID, > > - .sd_info = &ad7173_sigma_delta_info_8_slots, > > + .sd_info = &ad7173_sigma_delta_info_16_slots, > > .num_voltage_in_div = 8, > > .num_channels = 16, > > .num_configs = 8, > > @@ -818,7 +834,7 @@ static const struct ad7173_device_info ad4112_device_info > > = { > > static const struct ad7173_device_info ad4113_device_info = { > > .name = "ad4113", > > .id = AD4113_ID, > > - .sd_info = &ad7173_sigma_delta_info_8_slots, > > + .sd_info = &ad7173_sigma_delta_info_16_slots, > > .num_voltage_in_div = 8, > > .num_channels = 16, > > .num_configs = 8, > > @@ -837,7 +853,7 @@ static const struct ad7173_device_info ad4113_device_info > > = { > > static const struct ad7173_device_info ad4114_device_info = { > > .name = "ad4114", > > .id = AD4114_ID, > > - .sd_info = &ad7173_sigma_delta_info_8_slots, > > + .sd_info = &ad7173_sigma_delta_info_16_slots, > > .num_voltage_in_div = 16, > > .num_channels = 16, > > .num_configs = 8, > > @@ -856,7 +872,7 @@ static const struct ad7173_device_info ad4114_device_info > > = { > > static const struct ad7173_device_info ad4115_device_info = { > > .name = "ad4115", > > .id = AD4115_ID, > > - .sd_info = &ad7173_sigma_delta_info_8_slots, > > + .sd_info = &ad7173_sigma_delta_info_16_slots, > > .num_voltage_in_div = 16, > > .num_channels = 16, > > .num_configs = 8, > > @@ -875,7 +891,7 @@ static const struct ad7173_device_info ad4115_device_info > > = { > > static const struct ad7173_device_info ad4116_device_info = { > > .name = "ad4116", > > .id = AD4116_ID, > > - .sd_info = &ad7173_sigma_delta_info_8_slots, > > + .sd_info = &ad7173_sigma_delta_info_16_slots, > > .num_voltage_in_div = 11, > > .num_channels = 16, > > .num_configs = 8, > > @@ -894,7 +910,7 @@ static const struct ad7173_device_info ad4116_device_info > > = { > > static const struct ad7173_device_info ad7172_2_device_info = { > > .name = "ad7172-2", > > .id = AD7172_2_ID, > > - .sd_info = &ad7173_sigma_delta_info_8_slots, > > + .sd_info = &ad7173_sigma_delta_info_4_slots, > > .num_voltage_in = 5, > > .num_channels = 4, > > .num_configs = 4, > > @@ -927,7 +943,7 @@ static const struct ad7173_device_info > > ad7172_4_device_info = { > > static const struct ad7173_device_info ad7173_8_device_info = { > > .name = "ad7173-8", > > .id = AD7173_ID, > > - .sd_info = &ad7173_sigma_delta_info_8_slots, > > + .sd_info = &ad7173_sigma_delta_info_16_slots, > > .num_voltage_in = 17, > > .num_channels = 16, > > .num_configs = 8, > > @@ -944,7 +960,7 @@ static const struct ad7173_device_info > > ad7173_8_device_info = { > > static const struct ad7173_device_info ad7175_2_device_info = { > > .name = "ad7175-2", > > .id = AD7175_2_ID, > > - .sd_info = &ad7173_sigma_delta_info_8_slots, > > + .sd_info = &ad7173_sigma_delta_info_4_slots, > > .num_voltage_in = 5, > > .num_channels = 4, > > .num_configs = 4, > > @@ -961,7 +977,7 @@ static const struct ad7173_device_info > > ad7175_2_device_info = { > > static const struct ad7173_device_info ad7175_8_device_info = { > > .name = "ad7175-8", > > .id = AD7175_8_ID, > > - .sd_info = &ad7173_sigma_delta_info_8_slots, > > + .sd_info = &ad7173_sigma_delta_info_16_slots, > > .num_voltage_in = 17, > > .num_channels = 16, > > .num_configs = 8, > > > > --- > > base-commit: 731bfc181896a4dfd20a8c219bef1c205dd1d708 > > change-id: 20250703-iio-adc-ad7173-fix-num_slots-on-most-chips-b982206a20b1 > > > > Best regards, >
© 2016 - 2025 Red Hat, Inc.