From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Nuno Sa" <Nuno.Sa@analog.com>,
"Miquel Raynal" <miquel.raynal@bootlin.com>,
"Nuno Sá" <nuno.sa@analog.com>
Subject: [PATCH v4 06/16] iio: adc: max1027: Create a helper to enable/disable the cnvst trigger
Date: Tue, 21 Sep 2021 13:53:58 +0200 [thread overview]
Message-ID: <20210921115408.66711-7-miquel.raynal@bootlin.com> (raw)
In-Reply-To: <20210921115408.66711-1-miquel.raynal@bootlin.com>
There are two ways to physically trigger a conversion:
- A falling edge on the cnvst pin
- A write operation on the conversion register
Let's create a helper for this.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
---
drivers/iio/adc/max1027.c | 41 ++++++++++++++++++++++++---------------
1 file changed, 25 insertions(+), 16 deletions(-)
diff --git a/drivers/iio/adc/max1027.c b/drivers/iio/adc/max1027.c
index e84f49f21778..d1a9ffa68c38 100644
--- a/drivers/iio/adc/max1027.c
+++ b/drivers/iio/adc/max1027.c
@@ -271,6 +271,25 @@ struct max1027_state {
u8 reg ____cacheline_aligned;
};
+static int max1027_enable_trigger(struct iio_dev *indio_dev, bool enable)
+{
+ struct max1027_state *st = iio_priv(indio_dev);
+
+ st->reg = MAX1027_SETUP_REG | MAX1027_REF_MODE2;
+
+ /*
+ * Start acquisition on:
+ * MODE0: external hardware trigger wired to the cnvst input pin
+ * MODE2: conversion register write
+ */
+ if (enable)
+ st->reg |= MAX1027_CKS_MODE0;
+ else
+ st->reg |= MAX1027_CKS_MODE2;
+
+ return spi_write(st->spi, &st->reg, 1);
+}
+
static int max1027_read_single_value(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val)
@@ -283,14 +302,9 @@ static int max1027_read_single_value(struct iio_dev *indio_dev,
return -EBUSY;
}
- /* Start acquisition on conversion register write */
- st->reg = MAX1027_SETUP_REG | MAX1027_REF_MODE2 | MAX1027_CKS_MODE2;
- ret = spi_write(st->spi, &st->reg, 1);
- if (ret < 0) {
- dev_err(&indio_dev->dev,
- "Failed to configure setup register\n");
+ ret = max1027_enable_trigger(indio_dev, false);
+ if (ret)
return ret;
- }
/* Configure conversion register with the requested chan */
st->reg = MAX1027_CONV_REG | MAX1027_CHAN(chan->channel) |
@@ -396,11 +410,8 @@ static int max1027_set_cnvst_trigger_state(struct iio_trigger *trig, bool state)
int ret;
if (state) {
- /* Start acquisition on cnvst */
- st->reg = MAX1027_SETUP_REG | MAX1027_CKS_MODE0 |
- MAX1027_REF_MODE2;
- ret = spi_write(st->spi, &st->reg, 1);
- if (ret < 0)
+ ret = max1027_enable_trigger(indio_dev, state);
+ if (ret)
return ret;
/*
@@ -417,10 +428,8 @@ static int max1027_set_cnvst_trigger_state(struct iio_trigger *trig, bool state)
return ret;
} else {
/* Start acquisition on conversion register write */
- st->reg = MAX1027_SETUP_REG | MAX1027_CKS_MODE2 |
- MAX1027_REF_MODE2;
- ret = spi_write(st->spi, &st->reg, 1);
- if (ret < 0)
+ ret = max1027_enable_trigger(indio_dev, state);
+ if (ret)
return ret;
}
--
2.27.0
next prev parent reply other threads:[~2021-09-21 11:54 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-21 11:53 [PATCH v4 00/16] Bring external triggers support to MAX1027-like ADCs Miquel Raynal
2021-09-21 11:53 ` [PATCH v4 01/16] iio: adc: max1027: Fix style Miquel Raynal
2021-09-21 11:53 ` [PATCH v4 02/16] iio: adc: max1027: Drop extra warning message Miquel Raynal
2021-09-21 11:53 ` [PATCH v4 03/16] iio: adc: max1027: Drop useless debug messages Miquel Raynal
2021-09-21 11:53 ` [PATCH v4 04/16] iio: adc: max1027: Minimize the number of converted channels Miquel Raynal
2021-09-21 11:53 ` [PATCH v4 05/16] iio: adc: max1027: Rename a helper Miquel Raynal
2021-09-21 11:53 ` Miquel Raynal [this message]
2021-09-21 11:53 ` [PATCH v4 07/16] iio: adc: max1027: Simplify the _set_trigger_state() helper Miquel Raynal
2021-09-21 11:54 ` [PATCH v4 08/16] iio: adc: max1027: Ensure a default cnvst trigger configuration Miquel Raynal
2021-09-21 11:54 ` [PATCH v4 09/16] iio: adc: max1027: Create a helper to configure the channels to scan Miquel Raynal
2021-09-21 11:54 ` [PATCH v4 10/16] iio: adc: max1027: Prevent single channel accesses during buffer reads Miquel Raynal
2021-09-21 11:54 ` [PATCH v4 11/16] iio: adc: max1027: Separate the IRQ handler from the read logic Miquel Raynal
2021-09-21 11:54 ` [PATCH v4 12/16] iio: adc: max1027: Introduce an end of conversion helper Miquel Raynal
2021-09-21 11:54 ` [PATCH v4 13/16] iio: adc: max1027: Stop requesting a threaded IRQ Miquel Raynal
2021-09-21 11:54 ` [PATCH v4 14/16] iio: adc: max1027: Use the EOC IRQ when populated for single reads Miquel Raynal
2021-09-26 14:36 ` Jonathan Cameron
2021-09-27 14:30 ` Miquel Raynal
2021-09-21 11:54 ` [PATCH v4 15/16] iio: adc: max1027: Allow all kind of triggers to be used Miquel Raynal
2021-09-21 11:54 ` [PATCH v4 16/16] iio: adc: max1027: Don't reject external triggers when there is no IRQ Miquel Raynal
2021-09-26 14:38 ` [PATCH v4 00/16] Bring external triggers support to MAX1027-like ADCs 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=20210921115408.66711-7-miquel.raynal@bootlin.com \
--to=miquel.raynal@bootlin.com \
--cc=Nuno.Sa@analog.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=thomas.petazzoni@bootlin.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 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).