[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250621185301.9536-1-rodrigo.gobbi.7@gmail.com>
Date: Sat, 21 Jun 2025 15:41:44 -0300
From: Rodrigo Gobbi <rodrigo.gobbi.7@...il.com>
To: jic23@...nel.org,
dlechner@...libre.com,
nuno.sa@...log.com,
andy@...nel.org,
conor@...nel.org
Cc: ~lkcamp/patches@...ts.sr.ht,
linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH] iio: adc: spear_adc: mask SPEAR_ADC_STATUS_AVG_SAMPLE before setting register
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@...il.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
Powered by blists - more mailing lists