Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: adc: spear_adc: mask SPEAR_ADC_STATUS channel and avg sample before setting register

avg sample info is a bit field coded inside the following
bits: 5,6,7 and 8 of a device status register.

Channel num info the same, but over bits: 1, 2 and 3.

Mask both values in order to avoid touching other register bits,
since the first info (avg sample), came from DT.

Signed-off-by: Rodrigo Gobbi <rodrigo.gobbi.7@gmail.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20250717221559.158872-1-rodrigo.gobbi.7@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Rodrigo Gobbi and committed by
Jonathan Cameron
d75c7021 8f5ae30d

+5 -4
+5 -4
drivers/iio/adc/spear_adc.c
··· 14 14 #include <linux/kernel.h> 15 15 #include <linux/slab.h> 16 16 #include <linux/io.h> 17 + #include <linux/bitfield.h> 17 18 #include <linux/clk.h> 18 19 #include <linux/err.h> 19 20 #include <linux/completion.h> ··· 30 29 31 30 /* Bit definitions for SPEAR_ADC_STATUS */ 32 31 #define SPEAR_ADC_STATUS_START_CONVERSION BIT(0) 33 - #define SPEAR_ADC_STATUS_CHANNEL_NUM(x) ((x) << 1) 32 + #define SPEAR_ADC_STATUS_CHANNEL_NUM_MASK GENMASK(3, 1) 34 33 #define SPEAR_ADC_STATUS_ADC_ENABLE BIT(4) 35 - #define SPEAR_ADC_STATUS_AVG_SAMPLE(x) ((x) << 5) 34 + #define SPEAR_ADC_STATUS_AVG_SAMPLE_MASK GENMASK(8, 5) 36 35 #define SPEAR_ADC_STATUS_VREF_INTERNAL BIT(9) 37 36 38 37 #define SPEAR_ADC_DATA_MASK 0x03ff ··· 158 157 case IIO_CHAN_INFO_RAW: 159 158 mutex_lock(&st->lock); 160 159 161 - status = SPEAR_ADC_STATUS_CHANNEL_NUM(chan->channel) | 162 - SPEAR_ADC_STATUS_AVG_SAMPLE(st->avg_samples) | 160 + status = FIELD_PREP(SPEAR_ADC_STATUS_CHANNEL_NUM_MASK, chan->channel) | 161 + FIELD_PREP(SPEAR_ADC_STATUS_AVG_SAMPLE_MASK, st->avg_samples) | 163 162 SPEAR_ADC_STATUS_START_CONVERSION | 164 163 SPEAR_ADC_STATUS_ADC_ENABLE; 165 164 if (st->vref_external == 0)