aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/iio
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2012-06-18 12:33:51 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-06-18 20:26:09 -0400
commitd045b9d21b9591a4605590e7fe433f92d4b54762 (patch)
tree29c9de47fd02d55c3c4567da4e00ee596516fcea /drivers/staging/iio
parenta648232dc5ed840c6dab0a949450ee4cdf5830bd (diff)
staging:iio:adc:ad7298: Use new triggered buffer setup helper function
Use the new triggered buffer setup helper function to allocate and register buffer and pollfunc. The previous code was not passing the temperature channel to iio_buffer_register since the temperature channel can not be used in buffered mode. With the new helper functions it is not possible to do this, instead the scan index for the temperature channel is set to -1 which will cause iio_buffer_register to ignore the channel. (Also While we are at it also assign the symbolic constant instead of the raw value to the channel address for the temperature channel). Also as part of the conversion drop scan_timestamp being enabled by default, since it is a left over of an earlier cleanup. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/iio')
-rw-r--r--drivers/staging/iio/adc/Kconfig2
-rw-r--r--drivers/staging/iio/adc/ad7298.h5
-rw-r--r--drivers/staging/iio/adc/ad7298_core.c15
-rw-r--r--drivers/staging/iio/adc/ad7298_ring.c64
4 files changed, 20 insertions, 66 deletions
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 7cdf421e76e..bb6fffd0d37 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -13,7 +13,7 @@ config AD7291
13config AD7298 13config AD7298
14 tristate "Analog Devices AD7298 ADC driver" 14 tristate "Analog Devices AD7298 ADC driver"
15 depends on SPI 15 depends on SPI
16 select IIO_KFIFO_BUF if IIO_BUFFER 16 select IIO_TRIGGERED_BUFFER if IIO_BUFFER
17 help 17 help
18 Say yes here to build support for Analog Devices AD7298 18 Say yes here to build support for Analog Devices AD7298
19 8 Channel ADC with temperature sensor. 19 8 Channel ADC with temperature sensor.
diff --git a/drivers/staging/iio/adc/ad7298.h b/drivers/staging/iio/adc/ad7298.h
index 5051a7e4d4f..18f27872300 100644
--- a/drivers/staging/iio/adc/ad7298.h
+++ b/drivers/staging/iio/adc/ad7298.h
@@ -55,6 +55,8 @@ struct ad7298_state {
55#ifdef CONFIG_IIO_BUFFER 55#ifdef CONFIG_IIO_BUFFER
56int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev); 56int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev);
57void ad7298_ring_cleanup(struct iio_dev *indio_dev); 57void ad7298_ring_cleanup(struct iio_dev *indio_dev);
58int ad7298_update_scan_mode(struct iio_dev *indio_dev,
59 const unsigned long *active_scan_mask);
58#else /* CONFIG_IIO_BUFFER */ 60#else /* CONFIG_IIO_BUFFER */
59 61
60static inline int 62static inline int
@@ -66,5 +68,8 @@ ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
66static inline void ad7298_ring_cleanup(struct iio_dev *indio_dev) 68static inline void ad7298_ring_cleanup(struct iio_dev *indio_dev)
67{ 69{
68} 70}
71
72#define ad7298_update_scan_mode NULL
73
69#endif /* CONFIG_IIO_BUFFER */ 74#endif /* CONFIG_IIO_BUFFER */
70#endif /* IIO_ADC_AD7298_H_ */ 75#endif /* IIO_ADC_AD7298_H_ */
diff --git a/drivers/staging/iio/adc/ad7298_core.c b/drivers/staging/iio/adc/ad7298_core.c
index c90f2b3e661..6141f4a70cf 100644
--- a/drivers/staging/iio/adc/ad7298_core.c
+++ b/drivers/staging/iio/adc/ad7298_core.c
@@ -45,8 +45,8 @@ static struct iio_chan_spec ad7298_channels[] = {
45 .channel = 0, 45 .channel = 0,
46 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | 46 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
47 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, 47 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
48 .address = 9, 48 .address = AD7298_CH_TEMP,
49 .scan_index = AD7298_CH_TEMP, 49 .scan_index = -1,
50 .scan_type = { 50 .scan_type = {
51 .sign = 's', 51 .sign = 's',
52 .realbits = 32, 52 .realbits = 32,
@@ -171,6 +171,7 @@ static int ad7298_read_raw(struct iio_dev *indio_dev,
171 171
172static const struct iio_info ad7298_info = { 172static const struct iio_info ad7298_info = {
173 .read_raw = &ad7298_read_raw, 173 .read_raw = &ad7298_read_raw,
174 .update_scan_mode = ad7298_update_scan_mode,
174 .driver_module = THIS_MODULE, 175 .driver_module = THIS_MODULE,
175}; 176};
176 177
@@ -231,19 +232,12 @@ static int __devinit ad7298_probe(struct spi_device *spi)
231 if (ret) 232 if (ret)
232 goto error_disable_reg; 233 goto error_disable_reg;
233 234
234 ret = iio_buffer_register(indio_dev,
235 &ad7298_channels[1], /* skip temp0 */
236 ARRAY_SIZE(ad7298_channels) - 1);
237 if (ret)
238 goto error_cleanup_ring;
239 ret = iio_device_register(indio_dev); 235 ret = iio_device_register(indio_dev);
240 if (ret) 236 if (ret)
241 goto error_unregister_ring; 237 goto error_cleanup_ring;
242 238
243 return 0; 239 return 0;
244 240
245error_unregister_ring:
246 iio_buffer_unregister(indio_dev);
247error_cleanup_ring: 241error_cleanup_ring:
248 ad7298_ring_cleanup(indio_dev); 242 ad7298_ring_cleanup(indio_dev);
249error_disable_reg: 243error_disable_reg:
@@ -263,7 +257,6 @@ static int __devexit ad7298_remove(struct spi_device *spi)
263 struct ad7298_state *st = iio_priv(indio_dev); 257 struct ad7298_state *st = iio_priv(indio_dev);
264 258
265 iio_device_unregister(indio_dev); 259 iio_device_unregister(indio_dev);
266 iio_buffer_unregister(indio_dev);
267 ad7298_ring_cleanup(indio_dev); 260 ad7298_ring_cleanup(indio_dev);
268 if (!IS_ERR(st->reg)) { 261 if (!IS_ERR(st->reg)) {
269 regulator_disable(st->reg); 262 regulator_disable(st->reg);
diff --git a/drivers/staging/iio/adc/ad7298_ring.c b/drivers/staging/iio/adc/ad7298_ring.c
index 908a3e5609d..cd3e9cb47a6 100644
--- a/drivers/staging/iio/adc/ad7298_ring.c
+++ b/drivers/staging/iio/adc/ad7298_ring.c
@@ -13,37 +13,29 @@
13 13
14#include <linux/iio/iio.h> 14#include <linux/iio/iio.h>
15#include <linux/iio/buffer.h> 15#include <linux/iio/buffer.h>
16#include <linux/iio/kfifo_buf.h>
17#include <linux/iio/trigger_consumer.h> 16#include <linux/iio/trigger_consumer.h>
17#include <linux/iio/triggered_buffer.h>
18 18
19#include "ad7298.h" 19#include "ad7298.h"
20 20
21/** 21/**
22 * ad7298_ring_preenable() setup the parameters of the ring before enabling 22 * ad7298_update_scan_mode() setup the spi transfer buffer for the new scan mask
23 *
24 * The complex nature of the setting of the number of bytes per datum is due
25 * to this driver currently ensuring that the timestamp is stored at an 8
26 * byte boundary.
27 **/ 23 **/
28static int ad7298_ring_preenable(struct iio_dev *indio_dev) 24int ad7298_update_scan_mode(struct iio_dev *indio_dev,
25 const unsigned long *active_scan_mask)
29{ 26{
30 struct ad7298_state *st = iio_priv(indio_dev); 27 struct ad7298_state *st = iio_priv(indio_dev);
31 int i, m; 28 int i, m;
32 unsigned short command; 29 unsigned short command;
33 int scan_count, ret; 30 int scan_count;
34
35 ret = iio_sw_buffer_preenable(indio_dev);
36 if (ret < 0)
37 return ret;
38 31
39 /* Now compute overall size */ 32 /* Now compute overall size */
40 scan_count = bitmap_weight(indio_dev->active_scan_mask, 33 scan_count = bitmap_weight(active_scan_mask, indio_dev->masklength);
41 indio_dev->masklength);
42 34
43 command = AD7298_WRITE | st->ext_ref; 35 command = AD7298_WRITE | st->ext_ref;
44 36
45 for (i = 0, m = AD7298_CH(0); i < AD7298_MAX_CHAN; i++, m >>= 1) 37 for (i = 0, m = AD7298_CH(0); i < AD7298_MAX_CHAN; i++, m >>= 1)
46 if (test_bit(i, indio_dev->active_scan_mask)) 38 if (test_bit(i, active_scan_mask))
47 command |= m; 39 command |= m;
48 40
49 st->tx_buf[0] = cpu_to_be16(command); 41 st->tx_buf[0] = cpu_to_be16(command);
@@ -108,49 +100,13 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
108 return IRQ_HANDLED; 100 return IRQ_HANDLED;
109} 101}
110 102
111static const struct iio_buffer_setup_ops ad7298_ring_setup_ops = {
112 .preenable = &ad7298_ring_preenable,
113 .postenable = &iio_triggered_buffer_postenable,
114 .predisable = &iio_triggered_buffer_predisable,
115};
116
117int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev) 103int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
118{ 104{
119 int ret; 105 return iio_triggered_buffer_setup(indio_dev, NULL,
120 106 &ad7298_trigger_handler, NULL);
121 indio_dev->buffer = iio_kfifo_allocate(indio_dev);
122 if (!indio_dev->buffer) {
123 ret = -ENOMEM;
124 goto error_ret;
125 }
126 indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
127 &ad7298_trigger_handler,
128 IRQF_ONESHOT,
129 indio_dev,
130 "ad7298_consumer%d",
131 indio_dev->id);
132
133 if (indio_dev->pollfunc == NULL) {
134 ret = -ENOMEM;
135 goto error_deallocate_kfifo;
136 }
137
138 /* Ring buffer functions - here trigger setup related */
139 indio_dev->setup_ops = &ad7298_ring_setup_ops;
140 indio_dev->buffer->scan_timestamp = true;
141
142 /* Flag that polled ring buffering is possible */
143 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
144 return 0;
145
146error_deallocate_kfifo:
147 iio_kfifo_free(indio_dev->buffer);
148error_ret:
149 return ret;
150} 107}
151 108
152void ad7298_ring_cleanup(struct iio_dev *indio_dev) 109void ad7298_ring_cleanup(struct iio_dev *indio_dev)
153{ 110{
154 iio_dealloc_pollfunc(indio_dev->pollfunc); 111 iio_triggered_buffer_cleanup(indio_dev);
155 iio_kfifo_free(indio_dev->buffer);
156} 112}