All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mihail Chindris <mihail.chindris@analog.com>
To: <linux-kernel@vger.kernel.org>, <linux-iio@vger.kernel.org>
Cc: <lars@metafoo.de>, <Michael.Hennerich@analog.com>,
	<jic23@kernel.org>, <nuno.sa@analog.com>,
	<dragos.bogdan@analog.com>, <alexandru.ardelean@analog.com>,
	Mihail Chindris <mihail.chindris@analog.com>
Subject: [PATCH v5 6/6] drivers:iio:dac:ad5766.c: Add trigger buffer
Date: Thu, 16 Sep 2021 18:29:14 +0000	[thread overview]
Message-ID: <20210916182914.1810-7-mihail.chindris@analog.com> (raw)
In-Reply-To: <20210916182914.1810-1-mihail.chindris@analog.com>

This chip is able to generate waveform and using an
with the output trigger buffer will be easy to generate one.

Signed-off-by: Mihail Chindris <mihail.chindris@analog.com>
---
 drivers/iio/dac/ad5766.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/drivers/iio/dac/ad5766.c b/drivers/iio/dac/ad5766.c
index dafda84fdea3..71491e6d466e 100644
--- a/drivers/iio/dac/ad5766.c
+++ b/drivers/iio/dac/ad5766.c
@@ -5,10 +5,13 @@
  * Copyright 2019-2020 Analog Devices Inc.
  */
 #include <linux/bitfield.h>
+#include <linux/bitops.h>
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/gpio/consumer.h>
 #include <linux/iio/iio.h>
+#include <linux/iio/triggered_buffer.h>
+#include <linux/iio/trigger_consumer.h>
 #include <linux/module.h>
 #include <linux/spi/spi.h>
 #include <asm/unaligned.h>
@@ -41,6 +44,7 @@
 #define AD5766_CMD_DITHER_SCALE_2		0xD0
 
 #define AD5766_FULL_RESET_CODE			0x1234
+#define AD5766_NUM_CH				16
 
 enum ad5766_type {
 	ID_AD5766,
@@ -455,6 +459,7 @@ static const struct iio_chan_spec_ext_info ad5766_ext_info[] = {
 	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),			\
 	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |		\
 		BIT(IIO_CHAN_INFO_SCALE),				\
+	.scan_index = (_chan),						\
 	.scan_type = {							\
 		.sign = 'u',						\
 		.realbits = (_bits),					\
@@ -576,6 +581,28 @@ static int ad5766_default_setup(struct ad5766_state *st)
 	return  __ad5766_spi_write(st, AD5766_CMD_SPAN_REG, st->crt_range);
 }
 
+static irqreturn_t ad5766_trigger_handler(int irq, void *p)
+{
+	struct iio_poll_func *pf = p;
+	struct iio_dev *indio_dev = pf->indio_dev;
+	struct iio_buffer *buf = indio_dev->buffer;
+	int ret, ch, i;
+	u16 data[AD5766_NUM_CH];
+
+	ret = iio_pop_from_buffer(buf, (u8 *)data);
+	if (ret)
+		goto done;
+
+	i = 0;
+	for_each_set_bit(ch, indio_dev->active_scan_mask, AD5766_NUM_CH - 1)
+		ad5766_write(indio_dev, ch, le16_to_cpu(data[i++]));
+
+done:
+	iio_trigger_notify_done(indio_dev->trig);
+
+	return IRQ_HANDLED;
+}
+
 static int ad5766_probe(struct spi_device *spi)
 {
 	enum ad5766_type type;
@@ -609,6 +636,15 @@ static int ad5766_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
+	/* Configure trigger buffer */
+	ret = devm_iio_triggered_buffer_setup_ext(&spi->dev, indio_dev, NULL,
+						  ad5766_trigger_handler,
+						  IIO_BUFFER_DIRECTION_OUT,
+						  NULL,
+						  NULL);
+	if (ret)
+		return ret;
+
 	return devm_iio_device_register(&spi->dev, indio_dev);
 }
 
-- 
2.27.0


  parent reply	other threads:[~2021-09-16 18:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-16 18:29 [PATCH v5 0/6] iio: Add output buffer support Mihail Chindris
2021-09-16 18:29 ` [PATCH v5 1/6] " Mihail Chindris
2021-09-19 17:02   ` Jonathan Cameron
2021-09-20  8:02     ` Sa, Nuno
2021-09-20 18:04       ` Jonathan Cameron
2021-09-16 18:29 ` [PATCH v5 2/6] iio: kfifo-buffer: " Mihail Chindris
2021-09-16 18:29 ` [PATCH v5 3/6] iio: triggered-buffer: extend support to configure output buffers Mihail Chindris
2021-09-19 17:05   ` Jonathan Cameron
2021-09-16 18:29 ` [PATCH v5 4/6] drivers: iio: dac: ad5766: Fix dt property name Mihail Chindris
2021-09-17  7:53   ` Alexandru Ardelean
2021-09-19 17:11     ` Jonathan Cameron
2021-09-16 18:29 ` [PATCH v5 5/6] Documentation:devicetree:bindings:iio:dac: Fix val Mihail Chindris
2021-09-17  7:53   ` Alexandru Ardelean
2021-09-19 17:12     ` Jonathan Cameron
2021-09-16 18:29 ` Mihail Chindris [this message]
2021-09-17  8:08   ` [PATCH v5 6/6] drivers:iio:dac:ad5766.c: Add trigger buffer Alexandru Ardelean
2021-09-19 17:30     ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210916182914.1810-7-mihail.chindris@analog.com \
    --to=mihail.chindris@analog.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=alexandru.ardelean@analog.com \
    --cc=dragos.bogdan@analog.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.