Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: ef67f16e365c ("iio: adc: ad7606: Introduce num_adc_channels")
Signed-off-by: Guillaume Stols <gstols@baylibre.com>
Link: https://patch.msgid.link/20241210-ad7606_add_iio_backend_software_mode-v2-1-6619c3e50d81@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Guillaume Stols and committed by
Jonathan Cameron
954c06dd e16ebd9d

+29 -21
+28 -20
drivers/iio/adc/ad7606.c
··· 175 175 AD7606_CHANNEL(15, 16), 176 176 }; 177 177 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, 179 179 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, 181 181 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, 183 183 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, 185 185 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, 187 187 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, 189 189 struct iio_chan_spec *chan, int ch); 190 190 191 191 const struct ad7606_chip_info ad7605_4_info = { ··· 323 323 } 324 324 EXPORT_SYMBOL_NS_GPL(ad7606_reset, "IIO_AD7606"); 325 325 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, 327 327 struct iio_chan_spec *chan, int ch) 328 328 { 329 + struct ad7606_state *st = iio_priv(indio_dev); 329 330 struct ad7606_chan_scale *cs = &st->chan_scales[ch]; 330 331 331 332 if (!st->sw_mode_en) { ··· 346 345 return 0; 347 346 } 348 347 349 - static int ad7606_get_chan_config(struct ad7606_state *st, int ch, 348 + static int ad7606_get_chan_config(struct iio_dev *indio_dev, int ch, 350 349 bool *bipolar, bool *differential) 351 350 { 352 - unsigned int num_channels = st->chip_info->num_channels - 1; 351 + struct ad7606_state *st = iio_priv(indio_dev); 352 + unsigned int num_channels = st->chip_info->num_adc_channels; 353 + unsigned int offset = indio_dev->num_channels - st->chip_info->num_adc_channels; 353 354 struct device *dev = st->dev; 354 355 int ret; 355 356 ··· 367 364 continue; 368 365 369 366 /* channel number (here) is from 1 to num_channels */ 370 - if (reg == 0 || reg > num_channels) { 367 + if (reg < offset || reg > num_channels) { 371 368 dev_warn(dev, 372 369 "Invalid channel number (ignoring): %d\n", reg); 373 370 continue; ··· 402 399 return 0; 403 400 } 404 401 405 - static int ad7606c_18bit_chan_scale_setup(struct ad7606_state *st, 402 + static int ad7606c_18bit_chan_scale_setup(struct iio_dev *indio_dev, 406 403 struct iio_chan_spec *chan, int ch) 407 404 { 405 + struct ad7606_state *st = iio_priv(indio_dev); 408 406 struct ad7606_chan_scale *cs = &st->chan_scales[ch]; 409 407 bool bipolar, differential; 410 408 int ret; ··· 417 413 return 0; 418 414 } 419 415 420 - ret = ad7606_get_chan_config(st, ch, &bipolar, &differential); 416 + ret = ad7606_get_chan_config(indio_dev, ch, &bipolar, &differential); 421 417 if (ret) 422 418 return ret; 423 419 ··· 459 455 return 0; 460 456 } 461 457 462 - static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st, 458 + static int ad7606c_16bit_chan_scale_setup(struct iio_dev *indio_dev, 463 459 struct iio_chan_spec *chan, int ch) 464 460 { 461 + struct ad7606_state *st = iio_priv(indio_dev); 465 462 struct ad7606_chan_scale *cs = &st->chan_scales[ch]; 466 463 bool bipolar, differential; 467 464 int ret; ··· 474 469 return 0; 475 470 } 476 471 477 - ret = ad7606_get_chan_config(st, ch, &bipolar, &differential); 472 + ret = ad7606_get_chan_config(indio_dev, ch, &bipolar, &differential); 478 473 if (ret) 479 474 return ret; 480 475 ··· 517 512 return 0; 518 513 } 519 514 520 - static int ad7607_chan_scale_setup(struct ad7606_state *st, 515 + static int ad7607_chan_scale_setup(struct iio_dev *indio_dev, 521 516 struct iio_chan_spec *chan, int ch) 522 517 { 518 + struct ad7606_state *st = iio_priv(indio_dev); 523 519 struct ad7606_chan_scale *cs = &st->chan_scales[ch]; 524 520 525 521 cs->range = 0; ··· 529 523 return 0; 530 524 } 531 525 532 - static int ad7608_chan_scale_setup(struct ad7606_state *st, 526 + static int ad7608_chan_scale_setup(struct iio_dev *indio_dev, 533 527 struct iio_chan_spec *chan, int ch) 534 528 { 529 + struct ad7606_state *st = iio_priv(indio_dev); 535 530 struct ad7606_chan_scale *cs = &st->chan_scales[ch]; 536 531 537 532 cs->range = 0; ··· 541 534 return 0; 542 535 } 543 536 544 - static int ad7609_chan_scale_setup(struct ad7606_state *st, 537 + static int ad7609_chan_scale_setup(struct iio_dev *indio_dev, 545 538 struct iio_chan_spec *chan, int ch) 546 539 { 540 + struct ad7606_state *st = iio_priv(indio_dev); 547 541 struct ad7606_chan_scale *cs = &st->chan_scales[ch]; 548 542 549 543 cs->range = 0; ··· 1154 1146 1155 1147 static int ad7606_chan_scales_setup(struct iio_dev *indio_dev) 1156 1148 { 1157 - unsigned int num_channels = indio_dev->num_channels - 1; 1158 1149 struct ad7606_state *st = iio_priv(indio_dev); 1150 + unsigned int offset = indio_dev->num_channels - st->chip_info->num_adc_channels; 1159 1151 struct iio_chan_spec *chans; 1160 1152 size_t size; 1161 1153 int ch, ret; ··· 1169 1161 memcpy(chans, indio_dev->channels, size); 1170 1162 indio_dev->channels = chans; 1171 1163 1172 - for (ch = 0; ch < num_channels; ch++) { 1173 - ret = st->chip_info->scale_setup_cb(st, &chans[ch + 1], ch); 1164 + for (ch = 0; ch < st->chip_info->num_adc_channels; ch++) { 1165 + ret = st->chip_info->scale_setup_cb(indio_dev, &chans[ch + offset], ch); 1174 1166 if (ret) 1175 1167 return ret; 1176 1168 }
+1 -1
drivers/iio/adc/ad7606.h
··· 69 69 70 70 struct ad7606_state; 71 71 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, 73 73 struct iio_chan_spec *chan, int ch); 74 74 75 75 /**