mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rodrigo Gobbi <rodrigo.gobbi.7@gmail.com>
To: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
	andy@kernel.org, conor@kernel.org
Cc: ~lkcamp/patches@lists.sr.ht, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] iio: adc: spear_adc: mask SPEAR_ADC_STATUS_AVG_SAMPLE before setting register
Date: Sat, 21 Jun 2025 15:41:44 -0300	[thread overview]
Message-ID: <20250621185301.9536-1-rodrigo.gobbi.7@gmail.com> (raw)

SPEAR_ADC_STATUS_AVG_SAMPLE info is a bit field coded inside the following
bits: 5,6,7 and 8 of a device status register. Since the value came from dt,
mask it in order to avoid touching other register bits.

Signed-off-by: Rodrigo Gobbi <rodrigo.gobbi.7@gmail.com>
---
During the submission of patches related to the yaml creation of spear_adc [1],
there was a discussion about the average-samples value/dt property. It turns out
that the dt property value is direclty written to a device status register.
Considering some defines at the .c file, we have this:

#define SPEAR_ADC_STATUS_ADC_ENABLE		BIT(4)
#define SPEAR_ADC_STATUS_AVG_SAMPLE(x)		((x) << 5)
#define SPEAR_ADC_STATUS_VREF_INTERNAL		BIT(9)

SPEAR_ADC_STATUS_AVG_SAMPLE info is a bit field coded inside the following
bits: 5,6,7 and 8. The bit 9 is a different info, vref in this case.
Currently, there is no control if the average-samples is outside of allowed
range, which is 0x15 since the driver exists. There is no documentation about
how that information is managed by the device, but I`m suggesting to add a mask
with the max value for those bits before configuring the samples bits.

@Conor, I`m considering to add the "Suggested-by:" with your name here due [1].
Are you ok with that? If you agree, I can submit a v2 with that.
Tks and regards.

[1] https://lore.kernel.org/linux-devicetree/20250506-equivocal-snooper-8a7d1ce931c8@spud/#t
---
 drivers/iio/adc/spear_adc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/spear_adc.c b/drivers/iio/adc/spear_adc.c
index e3a865c79686..cf412ece90cf 100644
--- a/drivers/iio/adc/spear_adc.c
+++ b/drivers/iio/adc/spear_adc.c
@@ -37,6 +37,8 @@
 #define SPEAR_ADC_DATA_MASK		0x03ff
 #define SPEAR_ADC_DATA_BITS		10
 
+#define SPEAR_ADC_AVG_SAMPLE_MASK 0x01E0
+
 #define SPEAR_ADC_MOD_NAME "spear-adc"
 
 #define SPEAR_ADC_CHANNEL_NUM		8
@@ -158,7 +160,7 @@ static int spear_adc_read_raw(struct iio_dev *indio_dev,
 		mutex_lock(&st->lock);
 
 		status = SPEAR_ADC_STATUS_CHANNEL_NUM(chan->channel) |
-			SPEAR_ADC_STATUS_AVG_SAMPLE(st->avg_samples) |
+			(SPEAR_ADC_STATUS_AVG_SAMPLE(st->avg_samples) & SPEAR_ADC_AVG_SAMPLE_MASK) |
 			SPEAR_ADC_STATUS_START_CONVERSION |
 			SPEAR_ADC_STATUS_ADC_ENABLE;
 		if (st->vref_external == 0)
-- 
2.49.0


             reply	other threads:[~2025-06-21 18:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-21 18:41 Rodrigo Gobbi [this message]
2025-06-21 19:18 ` David Lechner

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=20250621185301.9536-1-rodrigo.gobbi.7@gmail.com \
    --to=rodrigo.gobbi.7@gmail.com \
    --cc=andy@kernel.org \
    --cc=conor@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=~lkcamp/patches@lists.sr.ht \
    /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®