Skip to content

Commit 954c06d

Browse files
gstolsjic23
authored andcommitted
iio: adc: ad7606: Fix hardcoded offset in the ADC channels
When introducing num_adc_channels, I overlooked some new functions created in a meanwhile that had also the hardcoded offset. This commit adds the new logic to these functions. Fixes: ef67f16 ("iio: adc: ad7606: Introduce num_adc_channels") Signed-off-by: Guillaume Stols <[email protected]> Link: https://patch.msgid.link/20241210-ad7606_add_iio_backend_software_mode-v2-1-6619c3e50d81@baylibre.com Signed-off-by: Jonathan Cameron <[email protected]>
1 parent e16ebd9 commit 954c06d

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

drivers/iio/adc/ad7606.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,17 @@ static const struct iio_chan_spec ad7616_channels[] = {
175175
AD7606_CHANNEL(15, 16),
176176
};
177177

178-
static int ad7606c_18bit_chan_scale_setup(struct ad7606_state *st,
178+
static int ad7606c_18bit_chan_scale_setup(struct iio_dev *indio_dev,
179179
struct iio_chan_spec *chan, int ch);
180-
static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st,
180+
static int ad7606c_16bit_chan_scale_setup(struct iio_dev *indio_dev,
181181
struct iio_chan_spec *chan, int ch);
182-
static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st,
182+
static int ad7606_16bit_chan_scale_setup(struct iio_dev *indio_dev,
183183
struct iio_chan_spec *chan, int ch);
184-
static int ad7607_chan_scale_setup(struct ad7606_state *st,
184+
static int ad7607_chan_scale_setup(struct iio_dev *indio_dev,
185185
struct iio_chan_spec *chan, int ch);
186-
static int ad7608_chan_scale_setup(struct ad7606_state *st,
186+
static int ad7608_chan_scale_setup(struct iio_dev *indio_dev,
187187
struct iio_chan_spec *chan, int ch);
188-
static int ad7609_chan_scale_setup(struct ad7606_state *st,
188+
static int ad7609_chan_scale_setup(struct iio_dev *indio_dev,
189189
struct iio_chan_spec *chan, int ch);
190190

191191
const struct ad7606_chip_info ad7605_4_info = {
@@ -323,9 +323,10 @@ int ad7606_reset(struct ad7606_state *st)
323323
}
324324
EXPORT_SYMBOL_NS_GPL(ad7606_reset, "IIO_AD7606");
325325

326-
static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st,
326+
static int ad7606_16bit_chan_scale_setup(struct iio_dev *indio_dev,
327327
struct iio_chan_spec *chan, int ch)
328328
{
329+
struct ad7606_state *st = iio_priv(indio_dev);
329330
struct ad7606_chan_scale *cs = &st->chan_scales[ch];
330331

331332
if (!st->sw_mode_en) {
@@ -345,10 +346,12 @@ static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st,
345346
return 0;
346347
}
347348

348-
static int ad7606_get_chan_config(struct ad7606_state *st, int ch,
349+
static int ad7606_get_chan_config(struct iio_dev *indio_dev, int ch,
349350
bool *bipolar, bool *differential)
350351
{
351-
unsigned int num_channels = st->chip_info->num_channels - 1;
352+
struct ad7606_state *st = iio_priv(indio_dev);
353+
unsigned int num_channels = st->chip_info->num_adc_channels;
354+
unsigned int offset = indio_dev->num_channels - st->chip_info->num_adc_channels;
352355
struct device *dev = st->dev;
353356
int ret;
354357

@@ -364,7 +367,7 @@ static int ad7606_get_chan_config(struct ad7606_state *st, int ch,
364367
continue;
365368

366369
/* channel number (here) is from 1 to num_channels */
367-
if (reg == 0 || reg > num_channels) {
370+
if (reg < offset || reg > num_channels) {
368371
dev_warn(dev,
369372
"Invalid channel number (ignoring): %d\n", reg);
370373
continue;
@@ -399,9 +402,10 @@ static int ad7606_get_chan_config(struct ad7606_state *st, int ch,
399402
return 0;
400403
}
401404

402-
static int ad7606c_18bit_chan_scale_setup(struct ad7606_state *st,
405+
static int ad7606c_18bit_chan_scale_setup(struct iio_dev *indio_dev,
403406
struct iio_chan_spec *chan, int ch)
404407
{
408+
struct ad7606_state *st = iio_priv(indio_dev);
405409
struct ad7606_chan_scale *cs = &st->chan_scales[ch];
406410
bool bipolar, differential;
407411
int ret;
@@ -413,7 +417,7 @@ static int ad7606c_18bit_chan_scale_setup(struct ad7606_state *st,
413417
return 0;
414418
}
415419

416-
ret = ad7606_get_chan_config(st, ch, &bipolar, &differential);
420+
ret = ad7606_get_chan_config(indio_dev, ch, &bipolar, &differential);
417421
if (ret)
418422
return ret;
419423

@@ -455,9 +459,10 @@ static int ad7606c_18bit_chan_scale_setup(struct ad7606_state *st,
455459
return 0;
456460
}
457461

458-
static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st,
462+
static int ad7606c_16bit_chan_scale_setup(struct iio_dev *indio_dev,
459463
struct iio_chan_spec *chan, int ch)
460464
{
465+
struct ad7606_state *st = iio_priv(indio_dev);
461466
struct ad7606_chan_scale *cs = &st->chan_scales[ch];
462467
bool bipolar, differential;
463468
int ret;
@@ -469,7 +474,7 @@ static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st,
469474
return 0;
470475
}
471476

472-
ret = ad7606_get_chan_config(st, ch, &bipolar, &differential);
477+
ret = ad7606_get_chan_config(indio_dev, ch, &bipolar, &differential);
473478
if (ret)
474479
return ret;
475480

@@ -512,9 +517,10 @@ static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st,
512517
return 0;
513518
}
514519

515-
static int ad7607_chan_scale_setup(struct ad7606_state *st,
520+
static int ad7607_chan_scale_setup(struct iio_dev *indio_dev,
516521
struct iio_chan_spec *chan, int ch)
517522
{
523+
struct ad7606_state *st = iio_priv(indio_dev);
518524
struct ad7606_chan_scale *cs = &st->chan_scales[ch];
519525

520526
cs->range = 0;
@@ -523,9 +529,10 @@ static int ad7607_chan_scale_setup(struct ad7606_state *st,
523529
return 0;
524530
}
525531

526-
static int ad7608_chan_scale_setup(struct ad7606_state *st,
532+
static int ad7608_chan_scale_setup(struct iio_dev *indio_dev,
527533
struct iio_chan_spec *chan, int ch)
528534
{
535+
struct ad7606_state *st = iio_priv(indio_dev);
529536
struct ad7606_chan_scale *cs = &st->chan_scales[ch];
530537

531538
cs->range = 0;
@@ -534,9 +541,10 @@ static int ad7608_chan_scale_setup(struct ad7606_state *st,
534541
return 0;
535542
}
536543

537-
static int ad7609_chan_scale_setup(struct ad7606_state *st,
544+
static int ad7609_chan_scale_setup(struct iio_dev *indio_dev,
538545
struct iio_chan_spec *chan, int ch)
539546
{
547+
struct ad7606_state *st = iio_priv(indio_dev);
540548
struct ad7606_chan_scale *cs = &st->chan_scales[ch];
541549

542550
cs->range = 0;
@@ -1146,8 +1154,8 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio_dev)
11461154

11471155
static int ad7606_chan_scales_setup(struct iio_dev *indio_dev)
11481156
{
1149-
unsigned int num_channels = indio_dev->num_channels - 1;
11501157
struct ad7606_state *st = iio_priv(indio_dev);
1158+
unsigned int offset = indio_dev->num_channels - st->chip_info->num_adc_channels;
11511159
struct iio_chan_spec *chans;
11521160
size_t size;
11531161
int ch, ret;
@@ -1161,8 +1169,8 @@ static int ad7606_chan_scales_setup(struct iio_dev *indio_dev)
11611169
memcpy(chans, indio_dev->channels, size);
11621170
indio_dev->channels = chans;
11631171

1164-
for (ch = 0; ch < num_channels; ch++) {
1165-
ret = st->chip_info->scale_setup_cb(st, &chans[ch + 1], ch);
1172+
for (ch = 0; ch < st->chip_info->num_adc_channels; ch++) {
1173+
ret = st->chip_info->scale_setup_cb(indio_dev, &chans[ch + offset], ch);
11661174
if (ret)
11671175
return ret;
11681176
}

drivers/iio/adc/ad7606.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
struct ad7606_state;
7171

72-
typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st,
72+
typedef int (*ad7606_scale_setup_cb_t)(struct iio_dev *indio_dev,
7373
struct iio_chan_spec *chan, int ch);
7474

7575
/**

0 commit comments

Comments
 (0)