Commit 557e585c authored by Stefan Popa's avatar Stefan Popa Committed by Jonathan Cameron

staging: iio: adc: ad7606: Use wait-for-completion handler

This patch replaces the use of wait_event_interruptible() with
wait_for_completion_timeout() when reading the result of a single
conversion. In this way, if the interrupt never occurs, the program will
not remain blocked.
Signed-off-by: default avatarStefan Popa <stefan.popa@analog.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 4535fa05
...@@ -119,12 +119,13 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch) ...@@ -119,12 +119,13 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch)
struct ad7606_state *st = iio_priv(indio_dev); struct ad7606_state *st = iio_priv(indio_dev);
int ret; int ret;
st->done = false;
gpiod_set_value(st->gpio_convst, 1); gpiod_set_value(st->gpio_convst, 1);
ret = wait_for_completion_timeout(&st->completion,
ret = wait_event_interruptible(st->wq_data_avail, st->done); msecs_to_jiffies(1000));
if (ret) if (!ret) {
ret = -ETIMEDOUT;
goto error_ret; goto error_ret;
}
ret = ad7606_read_samples(st); ret = ad7606_read_samples(st);
if (ret == 0) if (ret == 0)
...@@ -389,8 +390,7 @@ static irqreturn_t ad7606_interrupt(int irq, void *dev_id) ...@@ -389,8 +390,7 @@ static irqreturn_t ad7606_interrupt(int irq, void *dev_id)
if (iio_buffer_enabled(indio_dev)) { if (iio_buffer_enabled(indio_dev)) {
schedule_work(&st->poll_work); schedule_work(&st->poll_work);
} else { } else {
st->done = true; complete(&st->completion);
wake_up_interruptible(&st->wq_data_avail);
} }
return IRQ_HANDLED; return IRQ_HANDLED;
...@@ -474,7 +474,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, ...@@ -474,7 +474,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
indio_dev->channels = st->chip_info->channels; indio_dev->channels = st->chip_info->channels;
indio_dev->num_channels = st->chip_info->num_channels; indio_dev->num_channels = st->chip_info->num_channels;
init_waitqueue_head(&st->wq_data_avail); init_completion(&st->completion);
ret = ad7606_reset(st); ret = ad7606_reset(st);
if (ret) if (ret)
......
...@@ -29,11 +29,9 @@ struct ad7606_chip_info { ...@@ -29,11 +29,9 @@ struct ad7606_chip_info {
* @reg regulator info for the the power supply of the device * @reg regulator info for the the power supply of the device
* @poll_work work struct for continuously reading data from the device * @poll_work work struct for continuously reading data from the device
* into an IIO triggered buffer * into an IIO triggered buffer
* @wq_data_avail wait queue struct for buffer mode
* @bops bus operations (SPI or parallel) * @bops bus operations (SPI or parallel)
* @range voltage range selection, selects which scale to apply * @range voltage range selection, selects which scale to apply
* @oversampling oversampling selection * @oversampling oversampling selection
* @done marks whether reading data is done
* @base_address address from where to read data in parallel operation * @base_address address from where to read data in parallel operation
* @lock protect sensor state from concurrent accesses to GPIOs * @lock protect sensor state from concurrent accesses to GPIOs
* @gpio_convst GPIO descriptor for conversion start signal (CONVST) * @gpio_convst GPIO descriptor for conversion start signal (CONVST)
...@@ -44,6 +42,7 @@ struct ad7606_chip_info { ...@@ -44,6 +42,7 @@ struct ad7606_chip_info {
* @gpio_frstdata GPIO descriptor for reading from device when data * @gpio_frstdata GPIO descriptor for reading from device when data
* is being read on the first channel * is being read on the first channel
* @gpio_os GPIO descriptors to control oversampling on the device * @gpio_os GPIO descriptors to control oversampling on the device
* @complete completion to indicate end of conversion
* @data buffer for reading data from the device * @data buffer for reading data from the device
*/ */
...@@ -52,11 +51,9 @@ struct ad7606_state { ...@@ -52,11 +51,9 @@ struct ad7606_state {
const struct ad7606_chip_info *chip_info; const struct ad7606_chip_info *chip_info;
struct regulator *reg; struct regulator *reg;
struct work_struct poll_work; struct work_struct poll_work;
wait_queue_head_t wq_data_avail;
const struct ad7606_bus_ops *bops; const struct ad7606_bus_ops *bops;
unsigned int range; unsigned int range;
unsigned int oversampling; unsigned int oversampling;
bool done;
void __iomem *base_address; void __iomem *base_address;
struct mutex lock; /* protect sensor state */ struct mutex lock; /* protect sensor state */
...@@ -66,6 +63,7 @@ struct ad7606_state { ...@@ -66,6 +63,7 @@ struct ad7606_state {
struct gpio_desc *gpio_standby; struct gpio_desc *gpio_standby;
struct gpio_desc *gpio_frstdata; struct gpio_desc *gpio_frstdata;
struct gpio_descs *gpio_os; struct gpio_descs *gpio_os;
struct completion completion;
/* /*
* DMA (thus cache coherency maintenance) requires the * DMA (thus cache coherency maintenance) requires the
......
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