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: ad7476: Drop convstart chan_spec

The ad7476 driver defines separate chan_spec structures for operation
with and without convstart GPIO. At quick glance this may seem as if the
driver did provide more than 1 data-channel to users - one for the
regular data, other for the data obtained with the convstart GPIO.

The only difference between the 'convstart' and 'non convstart'
-channels is presence / absence of the BIT(IIO_CHAN_INFO_RAW) in
channel's flags.

We can drop the convstart channel spec, and related convstart macro, by
allocating a mutable per driver instance channel spec and adding the flag
in probe if needed. This will simplify the driver with the cost of added
memory consumption.

Assuming there aren't systems with very many ADCs and very few
resources, this tradeoff seems worth making.

Simplify the driver by dropping the 'convstart' channel spec and
allocating the channel spec for each driver instance.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Link: https://patch.msgid.link/cd7c72e3ee00f279d3381873f54e0c5b75b5ad11.1754901948.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Matti Vaittinen and committed by
Jonathan Cameron
84977a7a 0be6a47e

+19 -12
+19 -12
drivers/iio/adc/ad7476.c
··· 6 6 * Copyright 2010 Analog Devices Inc. 7 7 */ 8 8 9 + #include <linux/bitops.h> 9 10 #include <linux/device.h> 10 11 #include <linux/kernel.h> 11 12 #include <linux/slab.h> ··· 30 29 struct ad7476_chip_info { 31 30 unsigned int int_vref_mv; 32 31 struct iio_chan_spec channel[2]; 33 - /* channels used when convst gpio is defined */ 34 - struct iio_chan_spec convst_channel[2]; 35 32 void (*reset)(struct ad7476_state *); 36 33 bool has_vref; 37 34 bool has_vdrive; ··· 41 42 struct gpio_desc *convst_gpio; 42 43 struct spi_transfer xfer; 43 44 struct spi_message msg; 45 + struct iio_chan_spec channel[2]; 44 46 int scale_mv; 45 47 /* 46 48 * DMA (thus cache coherency maintenance) may require the ··· 154 154 #define AD7940_CHAN(bits) _AD7476_CHAN((bits), 15 - (bits), \ 155 155 BIT(IIO_CHAN_INFO_RAW)) 156 156 #define AD7091R_CHAN(bits) _AD7476_CHAN((bits), 16 - (bits), 0) 157 - #define AD7091R_CONVST_CHAN(bits) _AD7476_CHAN((bits), 16 - (bits), \ 158 - BIT(IIO_CHAN_INFO_RAW)) 159 157 #define ADS786X_CHAN(bits) _AD7476_CHAN((bits), 12 - (bits), \ 160 158 BIT(IIO_CHAN_INFO_RAW)) 161 159 162 160 static const struct ad7476_chip_info ad7091_chip_info = { 163 161 .channel[0] = AD7091R_CHAN(12), 164 162 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 165 - .convst_channel[0] = AD7091R_CONVST_CHAN(12), 166 - .convst_channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 167 163 .reset = ad7091_reset, 168 164 }; 169 165 170 166 static const struct ad7476_chip_info ad7091r_chip_info = { 171 167 .channel[0] = AD7091R_CHAN(12), 172 168 .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 173 - .convst_channel[0] = AD7091R_CONVST_CHAN(12), 174 - .convst_channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), 175 169 .int_vref_mv = 2500, 176 170 .has_vref = true, 177 171 .reset = ad7091_reset, ··· 276 282 { 277 283 struct ad7476_state *st; 278 284 struct iio_dev *indio_dev; 285 + unsigned int i; 279 286 int ret; 280 287 281 288 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); ··· 327 332 if (IS_ERR(st->convst_gpio)) 328 333 return PTR_ERR(st->convst_gpio); 329 334 335 + /* 336 + * This will never happen. Unless someone changes the channel specs 337 + * in this driver. And if someone does, without changing the loop 338 + * below, then we'd better immediately produce a big fat error, before 339 + * the change proceeds from that developer's table. 340 + */ 341 + static_assert(ARRAY_SIZE(st->channel) == ARRAY_SIZE(st->chip_info->channel)); 342 + for (i = 0; i < ARRAY_SIZE(st->channel); i++) { 343 + st->channel[i] = st->chip_info->channel[i]; 344 + if (st->convst_gpio) 345 + __set_bit(IIO_CHAN_INFO_RAW, 346 + &st->channel[i].info_mask_separate); 347 + } 348 + 330 349 st->spi = spi; 331 350 332 351 indio_dev->name = spi_get_device_id(spi)->name; 333 352 indio_dev->modes = INDIO_DIRECT_MODE; 334 - indio_dev->channels = st->chip_info->channel; 335 - indio_dev->num_channels = 2; 353 + indio_dev->channels = st->channel; 354 + indio_dev->num_channels = ARRAY_SIZE(st->channel); 336 355 indio_dev->info = &ad7476_info; 337 356 338 - if (st->convst_gpio) 339 - indio_dev->channels = st->chip_info->convst_channel; 340 357 /* Setup default message */ 341 358 342 359 st->xfer.rx_buf = &st->data;