linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: at91-sama5d2_adc: fix iio_triggered_buffer_{predisable,postenable} positions
@ 2019-10-23  8:25 Alexandru Ardelean
  2019-11-25 15:03 ` Ardelean, Alexandru
  0 siblings, 1 reply; 13+ messages in thread
From: Alexandru Ardelean @ 2019-10-23  8:25 UTC (permalink / raw)
  To: linux-iio, linux-arm-kernel, linux-kernel
  Cc: ludovic.desroches, jic23, nicolas.ferre, alexandre.belloni,
	knaack.h, lars, pmeerw, Alexandru Ardelean

The iio_triggered_buffer_{predisable,postenable} functions attach/detach
poll functions.

The iio_triggered_buffer_postenable() should be called first to attach the
poll function, and then the driver can init the data to be triggered.

Similarly, iio_triggered_buffer_predisable() should be called last to first
disable the data (to be triggered) and then the poll function should be
detached.

For this driver, the predisable & postenable hooks are also need to take
into consideration the touchscreen, so the hooks need to be put in places
that avoid the code for that cares about it.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/adc/at91-sama5d2_adc.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
index e1850f3d5cf3..ac3e5c4c9840 100644
--- a/drivers/iio/adc/at91-sama5d2_adc.c
+++ b/drivers/iio/adc/at91-sama5d2_adc.c
@@ -889,20 +889,24 @@ static int at91_adc_buffer_postenable(struct iio_dev *indio_dev)
 	if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES))
 		return -EINVAL;
 
+	ret = iio_triggered_buffer_postenable(indio_dev);
+	if (ret)
+		return ret;
+
 	/* we continue with the triggered buffer */
 	ret = at91_adc_dma_start(indio_dev);
 	if (ret) {
 		dev_err(&indio_dev->dev, "buffer postenable failed\n");
+		iio_triggered_buffer_predisable(indio_dev);
 		return ret;
 	}
 
-	return iio_triggered_buffer_postenable(indio_dev);
+	return 0;
 }
 
 static int at91_adc_buffer_predisable(struct iio_dev *indio_dev)
 {
 	struct at91_adc_state *st = iio_priv(indio_dev);
-	int ret;
 	u8 bit;
 
 	/* check if we are disabling triggered buffer or the touchscreen */
@@ -916,13 +920,8 @@ static int at91_adc_buffer_predisable(struct iio_dev *indio_dev)
 	if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES))
 		return -EINVAL;
 
-	/* continue with the triggered buffer */
-	ret = iio_triggered_buffer_predisable(indio_dev);
-	if (ret < 0)
-		dev_err(&indio_dev->dev, "buffer predisable failed\n");
-
 	if (!st->dma_st.dma_chan)
-		return ret;
+		goto out;
 
 	/* if we are using DMA we must clear registers and end DMA */
 	dmaengine_terminate_sync(st->dma_st.dma_chan);
@@ -949,7 +948,9 @@ static int at91_adc_buffer_predisable(struct iio_dev *indio_dev)
 
 	/* read overflow register to clear possible overflow status */
 	at91_adc_readl(st, AT91_SAMA5D2_OVER);
-	return ret;
+
+out:
+	return iio_triggered_buffer_predisable(indio_dev);
 }
 
 static const struct iio_buffer_setup_ops at91_buffer_setup_ops = {
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2019-12-06 17:02 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-23  8:25 [PATCH] iio: at91-sama5d2_adc: fix iio_triggered_buffer_{predisable,postenable} positions Alexandru Ardelean
2019-11-25 15:03 ` Ardelean, Alexandru
2019-11-28  8:36   ` Eugen.Hristev
2019-11-28 15:19     ` Eugen.Hristev
2019-11-29  7:02       ` Ardelean, Alexandru
2019-12-03  9:49         ` Eugen.Hristev
2019-12-03 12:04           ` Ardelean, Alexandru
2019-12-03 12:17             ` Eugen.Hristev
2019-12-03 13:40               ` Ardelean, Alexandru
2019-12-04  8:45                 ` Ludovic Desroches
2019-12-04  9:06                   ` Ardelean, Alexandru
2019-12-06 17:02                     ` Jonathan Cameron
2019-12-04  7:52           ` Ludovic Desroches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).