mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: William Breathitt Gray <william.gray@linaro.org>
To: Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	William Breathitt Gray <william.gray@linaro.org>
Subject: [PATCH v3 2/2] iio: addac: stx104: Use regmap_read_poll_timeout() for conversion poll
Date: Sun, 26 Mar 2023 18:05:58 -0400	[thread overview]
Message-ID: <028dcd8d0de87699294cd2c741d5a0ebb7595bf9.1679867815.git.william.gray@linaro.org> (raw)
In-Reply-To: <cover.1679867815.git.william.gray@linaro.org>

ADC sample captures take a certain amount of time to complete after
initiated; this conversion time range can be anywhere from 5 uSec to
53.68 Seconds depending on the configuration of the Analog Input Frame
Timer register. When the conversion is in progress, the ADC Status
register CNV bit is high. Utilize regmap_read_poll_timeout() to poll
until the ADC conversion is completed (or timeout if more than 53.68
Seconds passes).

Suggested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: William Breathitt Gray <william.gray@linaro.org>
---
 drivers/iio/addac/stx104.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/addac/stx104.c b/drivers/iio/addac/stx104.c
index 17d8b8e22dc3..a804f23b5619 100644
--- a/drivers/iio/addac/stx104.c
+++ b/drivers/iio/addac/stx104.c
@@ -202,15 +202,18 @@ static int stx104_read_raw(struct iio_dev *indio_dev,
 
 		/* trigger ADC sample capture by writing to the 8-bit
 		 * Software Strobe Register and wait for completion
+		 * Range is 5 uSec to 53.68 Seconds in steps of 25 nanoseconds.
+		 * The actual Analog Input Frame Timer time interval is calculated as:
+		 * ai_time_frame_ns = ( AIFT + 1 ) * ( 25 nSec ).
+		 * Where 0 <= AIFT <= 2147483648.
 		 */
 		err = regmap_write(priv->aio_ctl_map, STX104_SOFTWARE_STROBE, 0);
 		if (err)
 			return err;
-		do {
-			err = regmap_read(priv->aio_ctl_map, STX104_ADC_STATUS, &adc_status);
-			if (err)
-				return err;
-		} while (u8_get_bits(adc_status, STX104_CNV));
+		err = regmap_read_poll_timeout(priv->aio_ctl_map, STX104_ADC_STATUS, adc_status,
+					       !u8_get_bits(adc_status, STX104_CNV), 0, 53687092);
+		if (err)
+			return err;
 
 		err = regmap_read(priv->aio_data_map, STX104_ADC_DATA, &value);
 		if (err)
-- 
2.39.2


      parent reply	other threads:[~2023-03-26 22:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-26 22:05 [PATCH v3 0/2] Migrate STX104 to the regmap API William Breathitt Gray
2023-03-26 22:05 ` [PATCH v3 1/2] iio: addac: stx104: Migrate " William Breathitt Gray
2023-03-27 11:42   ` Andy Shevchenko
2023-04-01 13:49     ` Jonathan Cameron
2023-04-01 13:51     ` Jonathan Cameron
2023-04-01 13:43       ` William Breathitt Gray
2023-04-01 14:06     ` William Breathitt Gray
2023-04-02 16:46       ` Jonathan Cameron
2023-04-02 14:51         ` William Breathitt Gray
2023-03-26 22:05 ` William Breathitt Gray [this message]

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=028dcd8d0de87699294cd2c741d5a0ebb7595bf9.1679867815.git.william.gray@linaro.org \
    --to=william.gray@linaro.org \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®