aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2013-03-04 14:30:00 -0500
committerJonathan Cameron <jic23@kernel.org>2013-03-17 16:16:41 -0400
commitf2f7a449707eade5d6876d48d48ddc79dd77d75f (patch)
tree3e25d517dcd2a8652d17cb9bc23e29caac6e28c4 /drivers/iio
parentecf6ca2539bc3a36a14685b743fd7376707958ab (diff)
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>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/adc/Kconfig6
-rw-r--r--drivers/iio/adc/ad7923.c63
2 files changed, 53 insertions, 16 deletions
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 9c45c0f3f127..ab0767e6727e 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -31,13 +31,13 @@ config AD7298
31 module will be called ad7298. 31 module will be called ad7298.
32 32
33config AD7923 33config AD7923
34 tristate "Analog Devices AD7923 ADC driver" 34 tristate "Analog Devices AD7923 and similar ADCs driver"
35 depends on SPI 35 depends on SPI
36 select IIO_BUFFER 36 select IIO_BUFFER
37 select IIO_TRIGGERED_BUFFER 37 select IIO_TRIGGERED_BUFFER
38 help 38 help
39 Say yes here to build support for Analog Devices AD7923 39 Say yes here to build support for Analog Devices
40 4 Channel ADC with temperature sensor. 40 AD7904, AD7914, AD7923, AD7924 4 Channel ADCs.
41 41
42 To compile this driver as a module, choose M here: the 42 To compile this driver as a module, choose M here: the
43 module will be called ad7923. 43 module will be called ad7923.
diff --git a/drivers/iio/adc/ad7923.c b/drivers/iio/adc/ad7923.c
index 11ccc42b25a6..97fa0d3dc4aa 100644
--- a/drivers/iio/adc/ad7923.c
+++ b/drivers/iio/adc/ad7923.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * AD7923 SPI ADC driver 2 * AD7904/AD7914/AD7923/AD7924 SPI ADC driver
3 * 3 *
4 * Copyright 2011 Analog Devices Inc (from AD7923 Driver) 4 * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
5 * Copyright 2012 CS Systemes d'Information 5 * Copyright 2012 CS Systemes d'Information
@@ -70,7 +70,18 @@ struct ad7923_state {
70 __be16 tx_buf[4]; 70 __be16 tx_buf[4];
71}; 71};
72 72
73#define AD7923_V_CHAN(index) \ 73struct ad7923_chip_info {
74 const struct iio_chan_spec *channels;
75 unsigned int num_channels;
76};
77
78enum ad7923_id {
79 AD7904,
80 AD7914,
81 AD7924,
82};
83
84#define AD7923_V_CHAN(index, bits) \
74 { \ 85 { \
75 .type = IIO_VOLTAGE, \ 86 .type = IIO_VOLTAGE, \
76 .indexed = 1, \ 87 .indexed = 1, \
@@ -81,18 +92,38 @@ struct ad7923_state {
81 .scan_index = index, \ 92 .scan_index = index, \
82 .scan_type = { \ 93 .scan_type = { \
83 .sign = 'u', \ 94 .sign = 'u', \
84 .realbits = 12, \ 95 .realbits = (bits), \
85 .storagebits = 16, \ 96 .storagebits = 16, \
86 .endianness = IIO_BE, \ 97 .endianness = IIO_BE, \
87 }, \ 98 }, \
88 } 99 }
89 100
90static const struct iio_chan_spec ad7923_channels[] = { 101#define DECLARE_AD7923_CHANNELS(name, bits) \
91 AD7923_V_CHAN(0), 102const struct iio_chan_spec name ## _channels[] = { \
92 AD7923_V_CHAN(1), 103 AD7923_V_CHAN(0, bits), \
93 AD7923_V_CHAN(2), 104 AD7923_V_CHAN(1, bits), \
94 AD7923_V_CHAN(3), 105 AD7923_V_CHAN(2, bits), \
95 IIO_CHAN_SOFT_TIMESTAMP(4), 106 AD7923_V_CHAN(3, bits), \
107 IIO_CHAN_SOFT_TIMESTAMP(4), \
108}
109
110static DECLARE_AD7923_CHANNELS(ad7904, 8);
111static DECLARE_AD7923_CHANNELS(ad7914, 10);
112static DECLARE_AD7923_CHANNELS(ad7924, 12);
113
114static const struct ad7923_chip_info ad7923_chip_info[] = {
115 [AD7904] = {
116 .channels = ad7904_channels,
117 .num_channels = ARRAY_SIZE(ad7904_channels),
118 },
119 [AD7914] = {
120 .channels = ad7914_channels,
121 .num_channels = ARRAY_SIZE(ad7914_channels),
122 },
123 [AD7924] = {
124 .channels = ad7924_channels,
125 .num_channels = ARRAY_SIZE(ad7924_channels),
126 },
96}; 127};
97 128
98/** 129/**
@@ -245,6 +276,7 @@ static int ad7923_probe(struct spi_device *spi)
245{ 276{
246 struct ad7923_state *st; 277 struct ad7923_state *st;
247 struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st)); 278 struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
279 const struct ad7923_chip_info *info;
248 int ret; 280 int ret;
249 281
250 if (indio_dev == NULL) 282 if (indio_dev == NULL)
@@ -258,11 +290,13 @@ static int ad7923_probe(struct spi_device *spi)
258 st->settings = AD7923_CODING | AD7923_RANGE | 290 st->settings = AD7923_CODING | AD7923_RANGE |
259 AD7923_PM_MODE_WRITE(AD7923_PM_MODE_OPS); 291 AD7923_PM_MODE_WRITE(AD7923_PM_MODE_OPS);
260 292
293 info = &ad7923_chip_info[spi_get_device_id(spi)->driver_data];
294
261 indio_dev->name = spi_get_device_id(spi)->name; 295 indio_dev->name = spi_get_device_id(spi)->name;
262 indio_dev->dev.parent = &spi->dev; 296 indio_dev->dev.parent = &spi->dev;
263 indio_dev->modes = INDIO_DIRECT_MODE; 297 indio_dev->modes = INDIO_DIRECT_MODE;
264 indio_dev->channels = ad7923_channels; 298 indio_dev->channels = info->channels;
265 indio_dev->num_channels = ARRAY_SIZE(ad7923_channels); 299 indio_dev->num_channels = info->num_channels;
266 indio_dev->info = &ad7923_info; 300 indio_dev->info = &ad7923_info;
267 301
268 /* Setup default message */ 302 /* Setup default message */
@@ -324,7 +358,10 @@ static int ad7923_remove(struct spi_device *spi)
324} 358}
325 359
326static const struct spi_device_id ad7923_id[] = { 360static const struct spi_device_id ad7923_id[] = {
327 {"ad7923", 0}, 361 {"ad7904", AD7904},
362 {"ad7914", AD7914},
363 {"ad7923", AD7924},
364 {"ad7924", AD7924},
328 {} 365 {}
329}; 366};
330MODULE_DEVICE_TABLE(spi, ad7923_id); 367MODULE_DEVICE_TABLE(spi, ad7923_id);
@@ -342,5 +379,5 @@ module_spi_driver(ad7923_driver);
342 379
343MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 380MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
344MODULE_AUTHOR("Patrick Vasseur <patrick.vasseur@c-s.fr>"); 381MODULE_AUTHOR("Patrick Vasseur <patrick.vasseur@c-s.fr>");
345MODULE_DESCRIPTION("Analog Devices AD7923 ADC"); 382MODULE_DESCRIPTION("Analog Devices AD7904/AD7914/AD7923/AD7924 ADC");
346MODULE_LICENSE("GPL v2"); 383MODULE_LICENSE("GPL v2");