Commit d045b9d2 authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Greg Kroah-Hartman

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: default avatarLars-Peter Clausen <lars@metafoo.de>
Acked-by: default avatarJonathan Cameron <jic23@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a648232d
...@@ -13,7 +13,7 @@ config AD7291 ...@@ -13,7 +13,7 @@ config AD7291
config AD7298 config AD7298
tristate "Analog Devices AD7298 ADC driver" tristate "Analog Devices AD7298 ADC driver"
depends on SPI depends on SPI
select IIO_KFIFO_BUF if IIO_BUFFER select IIO_TRIGGERED_BUFFER if IIO_BUFFER
help help
Say yes here to build support for Analog Devices AD7298 Say yes here to build support for Analog Devices AD7298
8 Channel ADC with temperature sensor. 8 Channel ADC with temperature sensor.
......
...@@ -55,6 +55,8 @@ struct ad7298_state { ...@@ -55,6 +55,8 @@ struct ad7298_state {
#ifdef CONFIG_IIO_BUFFER #ifdef CONFIG_IIO_BUFFER
int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev); int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev);
void ad7298_ring_cleanup(struct iio_dev *indio_dev); void ad7298_ring_cleanup(struct iio_dev *indio_dev);
int ad7298_update_scan_mode(struct iio_dev *indio_dev,
const unsigned long *active_scan_mask);
#else /* CONFIG_IIO_BUFFER */ #else /* CONFIG_IIO_BUFFER */
static inline int static inline int
...@@ -66,5 +68,8 @@ ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev) ...@@ -66,5 +68,8 @@ ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
static inline void ad7298_ring_cleanup(struct iio_dev *indio_dev) static inline void ad7298_ring_cleanup(struct iio_dev *indio_dev)
{ {
} }
#define ad7298_update_scan_mode NULL
#endif /* CONFIG_IIO_BUFFER */ #endif /* CONFIG_IIO_BUFFER */
#endif /* IIO_ADC_AD7298_H_ */ #endif /* IIO_ADC_AD7298_H_ */
...@@ -45,8 +45,8 @@ static struct iio_chan_spec ad7298_channels[] = { ...@@ -45,8 +45,8 @@ static struct iio_chan_spec ad7298_channels[] = {
.channel = 0, .channel = 0,
.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
IIO_CHAN_INFO_SCALE_SEPARATE_BIT, IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
.address = 9, .address = AD7298_CH_TEMP,
.scan_index = AD7298_CH_TEMP, .scan_index = -1,
.scan_type = { .scan_type = {
.sign = 's', .sign = 's',
.realbits = 32, .realbits = 32,
...@@ -171,6 +171,7 @@ static int ad7298_read_raw(struct iio_dev *indio_dev, ...@@ -171,6 +171,7 @@ static int ad7298_read_raw(struct iio_dev *indio_dev,
static const struct iio_info ad7298_info = { static const struct iio_info ad7298_info = {
.read_raw = &ad7298_read_raw, .read_raw = &ad7298_read_raw,
.update_scan_mode = ad7298_update_scan_mode,
.driver_module = THIS_MODULE, .driver_module = THIS_MODULE,
}; };
...@@ -231,19 +232,12 @@ static int __devinit ad7298_probe(struct spi_device *spi) ...@@ -231,19 +232,12 @@ static int __devinit ad7298_probe(struct spi_device *spi)
if (ret) if (ret)
goto error_disable_reg; goto error_disable_reg;
ret = iio_buffer_register(indio_dev,
&ad7298_channels[1], /* skip temp0 */
ARRAY_SIZE(ad7298_channels) - 1);
if (ret)
goto error_cleanup_ring;
ret = iio_device_register(indio_dev); ret = iio_device_register(indio_dev);
if (ret) if (ret)
goto error_unregister_ring; goto error_cleanup_ring;
return 0; return 0;
error_unregister_ring:
iio_buffer_unregister(indio_dev);
error_cleanup_ring: error_cleanup_ring:
ad7298_ring_cleanup(indio_dev); ad7298_ring_cleanup(indio_dev);
error_disable_reg: error_disable_reg:
...@@ -263,7 +257,6 @@ static int __devexit ad7298_remove(struct spi_device *spi) ...@@ -263,7 +257,6 @@ static int __devexit ad7298_remove(struct spi_device *spi)
struct ad7298_state *st = iio_priv(indio_dev); struct ad7298_state *st = iio_priv(indio_dev);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
iio_buffer_unregister(indio_dev);
ad7298_ring_cleanup(indio_dev); ad7298_ring_cleanup(indio_dev);
if (!IS_ERR(st->reg)) { if (!IS_ERR(st->reg)) {
regulator_disable(st->reg); regulator_disable(st->reg);
......
...@@ -13,37 +13,29 @@ ...@@ -13,37 +13,29 @@
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/iio/buffer.h> #include <linux/iio/buffer.h>
#include <linux/iio/kfifo_buf.h>
#include <linux/iio/trigger_consumer.h> #include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
#include "ad7298.h" #include "ad7298.h"
/** /**
* ad7298_ring_preenable() setup the parameters of the ring before enabling * ad7298_update_scan_mode() setup the spi transfer buffer for the new scan mask
*
* The complex nature of the setting of the number of bytes per datum is due
* to this driver currently ensuring that the timestamp is stored at an 8
* byte boundary.
**/ **/
static int ad7298_ring_preenable(struct iio_dev *indio_dev) int ad7298_update_scan_mode(struct iio_dev *indio_dev,
const unsigned long *active_scan_mask)
{ {
struct ad7298_state *st = iio_priv(indio_dev); struct ad7298_state *st = iio_priv(indio_dev);
int i, m; int i, m;
unsigned short command; unsigned short command;
int scan_count, ret; int scan_count;
ret = iio_sw_buffer_preenable(indio_dev);
if (ret < 0)
return ret;
/* Now compute overall size */ /* Now compute overall size */
scan_count = bitmap_weight(indio_dev->active_scan_mask, scan_count = bitmap_weight(active_scan_mask, indio_dev->masklength);
indio_dev->masklength);
command = AD7298_WRITE | st->ext_ref; command = AD7298_WRITE | st->ext_ref;
for (i = 0, m = AD7298_CH(0); i < AD7298_MAX_CHAN; i++, m >>= 1) for (i = 0, m = AD7298_CH(0); i < AD7298_MAX_CHAN; i++, m >>= 1)
if (test_bit(i, indio_dev->active_scan_mask)) if (test_bit(i, active_scan_mask))
command |= m; command |= m;
st->tx_buf[0] = cpu_to_be16(command); st->tx_buf[0] = cpu_to_be16(command);
...@@ -108,49 +100,13 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p) ...@@ -108,49 +100,13 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static const struct iio_buffer_setup_ops ad7298_ring_setup_ops = {
.preenable = &ad7298_ring_preenable,
.postenable = &iio_triggered_buffer_postenable,
.predisable = &iio_triggered_buffer_predisable,
};
int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev) int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
{ {
int ret; return iio_triggered_buffer_setup(indio_dev, NULL,
&ad7298_trigger_handler, NULL);
indio_dev->buffer = iio_kfifo_allocate(indio_dev);
if (!indio_dev->buffer) {
ret = -ENOMEM;
goto error_ret;
}
indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
&ad7298_trigger_handler,
IRQF_ONESHOT,
indio_dev,
"ad7298_consumer%d",
indio_dev->id);
if (indio_dev->pollfunc == NULL) {
ret = -ENOMEM;
goto error_deallocate_kfifo;
}
/* Ring buffer functions - here trigger setup related */
indio_dev->setup_ops = &ad7298_ring_setup_ops;
indio_dev->buffer->scan_timestamp = true;
/* Flag that polled ring buffering is possible */
indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
return 0;
error_deallocate_kfifo:
iio_kfifo_free(indio_dev->buffer);
error_ret:
return ret;
} }
void ad7298_ring_cleanup(struct iio_dev *indio_dev) void ad7298_ring_cleanup(struct iio_dev *indio_dev)
{ {
iio_dealloc_pollfunc(indio_dev->pollfunc); iio_triggered_buffer_cleanup(indio_dev);
iio_kfifo_free(indio_dev->buffer);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment