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

iio:adc:ad7923: Add support for the ad7904/ad7914/ad7924

The ad7924 is software compatible with the ad7923. The ad7904 and ad7914 are the
8 and 10 bit version of the ad7924.

While we are at it also drop the "with temperature sensor" from the Kconfig
entry, since the chips do not have a temperature sensor.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Cc: Patrick Vasseur <patrick.vasseur@c-s.fr>
Cc: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Lars-Peter Clausen and committed by
Jonathan Cameron
f2f7a449 ecf6ca25

+53 -16
+3 -3
drivers/iio/adc/Kconfig
··· 31 31 module will be called ad7298. 32 32 33 33 config AD7923 34 - tristate "Analog Devices AD7923 ADC driver" 34 + tristate "Analog Devices AD7923 and similar ADCs driver" 35 35 depends on SPI 36 36 select IIO_BUFFER 37 37 select IIO_TRIGGERED_BUFFER 38 38 help 39 - Say yes here to build support for Analog Devices AD7923 40 - 4 Channel ADC with temperature sensor. 39 + Say yes here to build support for Analog Devices 40 + AD7904, AD7914, AD7923, AD7924 4 Channel ADCs. 41 41 42 42 To compile this driver as a module, choose M here: the 43 43 module will be called ad7923.
+50 -13
drivers/iio/adc/ad7923.c
··· 1 1 /* 2 - * AD7923 SPI ADC driver 2 + * AD7904/AD7914/AD7923/AD7924 SPI ADC driver 3 3 * 4 4 * Copyright 2011 Analog Devices Inc (from AD7923 Driver) 5 5 * Copyright 2012 CS Systemes d'Information ··· 70 70 __be16 tx_buf[4]; 71 71 }; 72 72 73 - #define AD7923_V_CHAN(index) \ 73 + struct ad7923_chip_info { 74 + const struct iio_chan_spec *channels; 75 + unsigned int num_channels; 76 + }; 77 + 78 + enum ad7923_id { 79 + AD7904, 80 + AD7914, 81 + AD7924, 82 + }; 83 + 84 + #define AD7923_V_CHAN(index, bits) \ 74 85 { \ 75 86 .type = IIO_VOLTAGE, \ 76 87 .indexed = 1, \ ··· 92 81 .scan_index = index, \ 93 82 .scan_type = { \ 94 83 .sign = 'u', \ 95 - .realbits = 12, \ 84 + .realbits = (bits), \ 96 85 .storagebits = 16, \ 97 86 .endianness = IIO_BE, \ 98 87 }, \ 99 88 } 100 89 101 - static const struct iio_chan_spec ad7923_channels[] = { 102 - AD7923_V_CHAN(0), 103 - AD7923_V_CHAN(1), 104 - AD7923_V_CHAN(2), 105 - AD7923_V_CHAN(3), 106 - IIO_CHAN_SOFT_TIMESTAMP(4), 90 + #define DECLARE_AD7923_CHANNELS(name, bits) \ 91 + const struct iio_chan_spec name ## _channels[] = { \ 92 + AD7923_V_CHAN(0, bits), \ 93 + AD7923_V_CHAN(1, bits), \ 94 + AD7923_V_CHAN(2, bits), \ 95 + AD7923_V_CHAN(3, bits), \ 96 + IIO_CHAN_SOFT_TIMESTAMP(4), \ 97 + } 98 + 99 + static DECLARE_AD7923_CHANNELS(ad7904, 8); 100 + static DECLARE_AD7923_CHANNELS(ad7914, 10); 101 + static DECLARE_AD7923_CHANNELS(ad7924, 12); 102 + 103 + static const struct ad7923_chip_info ad7923_chip_info[] = { 104 + [AD7904] = { 105 + .channels = ad7904_channels, 106 + .num_channels = ARRAY_SIZE(ad7904_channels), 107 + }, 108 + [AD7914] = { 109 + .channels = ad7914_channels, 110 + .num_channels = ARRAY_SIZE(ad7914_channels), 111 + }, 112 + [AD7924] = { 113 + .channels = ad7924_channels, 114 + .num_channels = ARRAY_SIZE(ad7924_channels), 115 + }, 107 116 }; 108 117 109 118 /** ··· 276 245 { 277 246 struct ad7923_state *st; 278 247 struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st)); 248 + const struct ad7923_chip_info *info; 279 249 int ret; 280 250 281 251 if (indio_dev == NULL) ··· 290 258 st->settings = AD7923_CODING | AD7923_RANGE | 291 259 AD7923_PM_MODE_WRITE(AD7923_PM_MODE_OPS); 292 260 261 + info = &ad7923_chip_info[spi_get_device_id(spi)->driver_data]; 262 + 293 263 indio_dev->name = spi_get_device_id(spi)->name; 294 264 indio_dev->dev.parent = &spi->dev; 295 265 indio_dev->modes = INDIO_DIRECT_MODE; 296 - indio_dev->channels = ad7923_channels; 297 - indio_dev->num_channels = ARRAY_SIZE(ad7923_channels); 266 + indio_dev->channels = info->channels; 267 + indio_dev->num_channels = info->num_channels; 298 268 indio_dev->info = &ad7923_info; 299 269 300 270 /* Setup default message */ ··· 358 324 } 359 325 360 326 static const struct spi_device_id ad7923_id[] = { 361 - {"ad7923", 0}, 327 + {"ad7904", AD7904}, 328 + {"ad7914", AD7914}, 329 + {"ad7923", AD7924}, 330 + {"ad7924", AD7924}, 362 331 {} 363 332 }; 364 333 MODULE_DEVICE_TABLE(spi, ad7923_id); ··· 379 342 380 343 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 381 344 MODULE_AUTHOR("Patrick Vasseur <patrick.vasseur@c-s.fr>"); 382 - MODULE_DESCRIPTION("Analog Devices AD7923 ADC"); 345 + MODULE_DESCRIPTION("Analog Devices AD7904/AD7914/AD7923/AD7924 ADC"); 383 346 MODULE_LICENSE("GPL v2");