mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-09 12:33:18 -04:00
iio: adc: ad4030: don't store scan_type in state
Move getting the scan_type to ad4030_conversion(). Previously, we were getting the scan_type in two other places, then storing it in the state struct before using it in ad4030_conversion(). This was a bit fragile against potential future changes since it isn't obvious that anything that could potentially change the scan_type would need to also update the state struct. Also, the non-obviousness of this led to a redundant call to iio_get_current_scan_type() in ad4030_single_conversion() since it also calls ad4030_set_mode() which in turn calls ad4030_conversion(). To simplify things, just call iio_get_current_scan_type() in ad4030_conversion() where the returned struct is actually used and don't bother storing it in the state struct. Signed-off-by: David Lechner <dlechner@baylibre.com> Reviewed-by: Nuno Sá <nuno.sa@analog.com> Link: https://patch.msgid.link/20250310-iio-adc-ad4030-check-scan-type-err-v1-4-589e4ebd9711@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
committed by
Jonathan Cameron
parent
efaa981e67
commit
15ffee89c7
@@ -147,7 +147,6 @@ struct ad4030_state {
|
||||
struct spi_device *spi;
|
||||
struct regmap *regmap;
|
||||
const struct ad4030_chip_info *chip;
|
||||
const struct iio_scan_type *current_scan_type;
|
||||
struct gpio_desc *cnv_gpio;
|
||||
int vref_uv;
|
||||
int vio_uv;
|
||||
@@ -562,11 +561,6 @@ static int ad4030_set_mode(struct iio_dev *indio_dev, unsigned long mask)
|
||||
st->mode = AD4030_OUT_DATA_MD_DIFF;
|
||||
}
|
||||
|
||||
st->current_scan_type = iio_get_current_scan_type(indio_dev,
|
||||
st->chip->channels);
|
||||
if (IS_ERR(st->current_scan_type))
|
||||
return PTR_ERR(st->current_scan_type);
|
||||
|
||||
return regmap_update_bits(st->regmap, AD4030_REG_MODES,
|
||||
AD4030_REG_MODES_MASK_OUT_DATA_MODE,
|
||||
st->mode);
|
||||
@@ -614,15 +608,20 @@ static void ad4030_extract_interleaved(u8 *src, u32 *ch0, u32 *ch1)
|
||||
static int ad4030_conversion(struct iio_dev *indio_dev)
|
||||
{
|
||||
struct ad4030_state *st = iio_priv(indio_dev);
|
||||
unsigned char diff_realbytes =
|
||||
BITS_TO_BYTES(st->current_scan_type->realbits);
|
||||
unsigned char diff_storagebytes =
|
||||
BITS_TO_BYTES(st->current_scan_type->storagebits);
|
||||
const struct iio_scan_type *scan_type;
|
||||
unsigned char diff_realbytes, diff_storagebytes;
|
||||
unsigned int bytes_to_read;
|
||||
unsigned long cnv_nb = BIT(st->avg_log2);
|
||||
unsigned int i;
|
||||
int ret;
|
||||
|
||||
scan_type = iio_get_current_scan_type(indio_dev, st->chip->channels);
|
||||
if (IS_ERR(scan_type))
|
||||
return PTR_ERR(scan_type);
|
||||
|
||||
diff_realbytes = BITS_TO_BYTES(scan_type->realbits);
|
||||
diff_storagebytes = BITS_TO_BYTES(scan_type->storagebits);
|
||||
|
||||
/* Number of bytes for one differential channel */
|
||||
bytes_to_read = diff_realbytes;
|
||||
/* Add one byte if we are using a differential + common byte mode */
|
||||
@@ -673,11 +672,6 @@ static int ad4030_single_conversion(struct iio_dev *indio_dev,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
st->current_scan_type = iio_get_current_scan_type(indio_dev,
|
||||
st->chip->channels);
|
||||
if (IS_ERR(st->current_scan_type))
|
||||
return PTR_ERR(st->current_scan_type);
|
||||
|
||||
ret = ad4030_conversion(indio_dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user