Skip to contentSkip to conversation

iio: adc: nxp-sar-adc: use field_get() for EOC bit check

PATCH Superseded Piyush Patle 3 participants 4 messages Apr 10 – Apr 11 IIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: nxp-sar-adc: use field_get() for EOC bit check

The driver uses FIELD_GET() for constant-mask fields but falls back to a raw bit test for the per-channel EOC bit, as the mask depends on the runtime channel index. A TODO notes that this should switch to field_get() when available.

Use field_get() here now that runtime-mask support exists, and drop the obsolete TODO. Since NXP_SAR_ADC_EOC_CH(c) is BIT(c), the resulting !-test is semantically identical.

No functional change.

---
 drivers/iio/adc/nxp-sar-adc.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/iio/adc/nxp-sar-adc.c +1 -5
index 58103bf16aff..d6c2a0d50bb4 100644
@@ -316,11 +316,7 @@ static int nxp_sar_adc_read_data(struct nxp_sar_adc *info, unsigned int chan)
 
 	ceocfr = readl(NXP_SAR_ADC_CEOCFR0(info->regs));
 
-	/*
-	 * FIELD_GET() can not be used here because EOC_CH is not constant.
-	 * TODO: Switch to field_get() when it will be available.
-	 */
-	if (!(NXP_SAR_ADC_EOC_CH(chan) & ceocfr))
+	if (!field_get(NXP_SAR_ADC_EOC_CH(chan), ceocfr))
 		return -EIO;
 
 	cdr = readl(NXP_SAR_ADC_CDR(info->regs, chan));
Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Piyush Patle

The driver uses FIELD_GET() for constant-mask fields but falls back to a raw bit test for the per-channel EOC bit, as the mask depends on the runtime channel index. A TODO notes that this should switch to field_get() when available.

Could drop this first paragraph, it is a bit redundant.

Quoted 2 lines

Use field_get() here now that runtime-mask support exists, and drop

We like for commit messages to start with the verb like this, so this would be ideal for the first paragraph of the commit message.

Quoted 7 lines

the obsolete TODO. Since NXP_SAR_ADC_EOC_CH(c) is BIT(c), the resulting !-test is semantically identical.

No functional change.

---

And if you are interested in doing more like this, search the IIO subsystem for __ffs. If it is used with << or >> then there is a good chance it could be replaced with field_get() or field_prep().

#2 lore raw
Quoted 6 lines · Piyush Patle
Quoted 4 lines

The driver uses FIELD_GET() for constant-mask fields but falls back to a raw bit test for the per-channel EOC bit, as the mask depends on the runtime channel index. A TODO notes that this should switch to field_get() when available.

Quoted 7 lines

Could drop this first paragraph, it is a bit redundant.

Quoted 2 lines

Use field_get() here now that runtime-mask support exists, and drop

We like for commit messages to start with the verb like this, so this would be ideal for the first paragraph of the commit message.

I have addressed all your comments.

Quoted 10 lines
Quoted 8 lines

the obsolete TODO. Since NXP_SAR_ADC_EOC_CH(c) is BIT(c), the resulting !-test is semantically identical.

No functional change.

---

Thanks for the review. Sent v2!

Quoted 5 lines

And if you are interested in doing more like this, search the IIO subsystem for __ffs. If it is used with << or >> then there is a good chance it could be replaced with field_get() or field_prep().

I'll also look for similar __ffs() patterns in IIO and convert them to field_get()/field_prep() where appropriate.

#3 lore raw
In reply to David Lechner
Quoted 19 lines · On Fri, 10 Apr 2026 16:26:05 -0500 David Lechner <[email protected]> wrote:
Quoted 4 lines · Piyush Patle

The driver uses FIELD_GET() for constant-mask fields but falls back to a raw bit test for the per-channel EOC bit, as the mask depends on the runtime channel index. A TODO notes that this should switch to field_get() when available.

Could drop this first paragraph, it is a bit redundant.

Quoted 2 lines

Use field_get() here now that runtime-mask support exists, and drop

We like for commit messages to start with the verb like this, so this would be ideal for the first paragraph of the commit message.

Quoted 5 lines

the obsolete TODO. Since NXP_SAR_ADC_EOC_CH(c) is BIT(c), the resulting !-test is semantically identical.

No functional change.

Quoted 10 lines
Quoted 2 lines

---

And if you are interested in doing more like this, search the IIO subsystem for __ffs. If it is used with << or >> then there is a good chance it could be replaced with field_get() or field_prep().

And likely make the code larger and slower :-)
At least run the bloat-o-meter.

David