iio: adc: nxp-sar-adc: Fix the delay calculation in nxp_sar_adc_wait_for()
PATCH 1/1 iio: adc: nxp-sar-adc: Fix the delay calculation in nxp_sar_adc_wait_for()
The original code was using ndelay() twice. In one case the delay is calculated as 1/3 of ADC clock and in the other as 80 ADC clocks. But according to the comments in all cases it should be a multiplier of the ADC clock, and not a fraction of it. Inadvertently nxp_sar_adc_wait_for() takes the wrong case and spread it over the code make it wrong in all places. Fix this by modifying a helper to correctly use the multiplier.
--- drivers/iio/adc/nxp-sar-adc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/nxp-sar-adc.c +2 -2
@@ -198,13 +198,13 @@ static void nxp_sar_adc_irq_cfg(struct nxp_sar_adc *info, bool enable)writel (0 ,NXP_SAR_ADC_IMR (info->regs)); } -static void nxp_sar_adc_wait_for (struct nxp_sar_adc *info,unsigned int cycles) +static void nxp_sar_adc_wait_for (struct nxp_sar_adc *info,u64 cycles) {u64 rate; rate =clk_get_rate (info->clk);if (rate) -ndelay (div64_u64 (NSEC_PER_SEC , rate * cycles)); +ndelay (div64_u64 (NSEC_PER_SEC * cycles, rate)); }static bool nxp_sar_adc_set_enabled (struct nxp_sar_adc *info,bool enable)
Signature · 1 line
2.50.1
Jonathan Cameron
maintainerQuoted 8 lines · On Tue, 19 May 2026 23:56:06 +0200 Andy Shevchenko…
The original code was using
ndelay()twice. In one case the delay is calculated as 1/3 of ADC clock and in the other as 80 ADC clocks. But according to the comments in all cases it should be a multiplier of the ADC clock, and not a fraction of it. Inadvertentlynxp_sar_adc_wait_for()takes the wrong case and spread it over the code make it wrong in all places. Fix this by modifying a helper to correctly use the multiplier.
Quoted 5 lines
Fixes 7e5c0f97c66a ("iio: adc: nxp-sar-adc: Avoid division by zero")Fixes 4434072a893e ("iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms")Reported-by Sashiko <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Daniel, could you take a look at this one.
Explanation seems fine but original patch was yours so I'd like some 'aware' eyes on it!
Quoted 24 lines
--- drivers/iio/adc/nxp-sar-adc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/iio/adc/nxp-sar-adc.c +2
-2@@ -198,13 +198,13 @@ static void nxp_sar_adc_irq_cfg(struct nxp_sar_adc *info, bool enable)writel (0 ,NXP_SAR_ADC_IMR (info->regs)); } -static void nxp_sar_adc_wait_for (struct nxp_sar_adc *info,unsigned int cycles) +static void nxp_sar_adc_wait_for (struct nxp_sar_adc *info,u64 cycles) {u64 rate; rate =clk_get_rate (info->clk);if (rate) -ndelay (div64_u64 (NSEC_PER_SEC , rate * cycles)); +ndelay (div64_u64 (NSEC_PER_SEC * cycles, rate)); }static bool nxp_sar_adc_set_enabled (struct nxp_sar_adc *info,bool enable)
Quoted 17 lines · Jonathan Cameron
Quoted 8 lines · On Tue, 19 May 2026 23:56:06 +0200 Andy Shevchenko…
The original code was using
ndelay()twice. In one case the delay is calculated as 1/3 of ADC clock and in the other as 80 ADC clocks. But according to the comments in all cases it should be a multiplier of the ADC clock, and not a fraction of it. Inadvertentlynxp_sar_adc_wait_for()takes the wrong case and spread it over the code make it wrong in all places. Fix this by modifying a helper to correctly use the multiplier.Quoted 5 lines
Fixes 7e5c0f97c66a ("iio: adc: nxp-sar-adc: Avoid division by zero")Fixes 4434072a893e ("iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms")Reported-by Sashiko <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Quoted 4 lines
Daniel, could you take a look at this one.
Explanation seems fine but original patch was yours so I'd like some 'aware' eyes on it!
Sounds like correct but let me loop in Ghenadi as I don't have the platform anymore to check the change
Jonathan Cameron
maintainerQuoted 18 lines · On Tue, 26 May 2026 14:48:44 +0200 Daniel Lezcano…
Quoted 17 lines · Jonathan Cameron
Quoted 13 lines · On Tue, 19 May 2026 23:56:06 +0200 Andy Shevchenko…
The original code was using
ndelay()twice. In one case the delay is calculated as 1/3 of ADC clock and in the other as 80 ADC clocks. But according to the comments in all cases it should be a multiplier of the ADC clock, and not a fraction of it. Inadvertentlynxp_sar_adc_wait_for()takes the wrong case and spread it over the code make it wrong in all places. Fix this by modifying a helper to correctly use the multiplier.Fixes 7e5c0f97c66a ("iio: adc: nxp-sar-adc: Avoid division by zero")Fixes 4434072a893e ("iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms")Reported-by Sashiko <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Quoted 8 lines
Quoted 4 lines
Daniel, could you take a look at this one.
Explanation seems fine but original patch was yours so I'd like some 'aware' eyes on it!
Sounds like correct but let me loop in Ghenadi as I don't have the platform anymore to check the change
Hi
This one is still outstanding if anyone has a chance to look at it. If not I'll gamble and apply it :)
Thanks,
Jonathan
Quoted 1 line
Daniel Lezcano
Acked-byQuoted 26 lines · Jonathan Cameron
Quoted 23 lines · On Tue, 26 May 2026 14:48:44 +0200 Daniel Lezcano…
Quoted 21 lines · Jonathan Cameron
Quoted 8 lines · On Tue, 19 May 2026 23:56:06 +0200 Andy Shevchenko…
The original code was using
ndelay()twice. In one case the delay is calculated as 1/3 of ADC clock and in the other as 80 ADC clocks. But according to the comments in all cases it should be a multiplier of the ADC clock, and not a fraction of it. Inadvertentlynxp_sar_adc_wait_for()takes the wrong case and spread it over the code make it wrong in all places. Fix this by modifying a helper to correctly use the multiplier.Quoted 5 lines
Fixes 7e5c0f97c66a ("iio: adc: nxp-sar-adc: Avoid division by zero")Fixes 4434072a893e ("iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms")Reported-by Sashiko <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>Daniel, could you take a look at this one.
Explanation seems fine but original patch was yours so I'd like some 'aware' eyes on it!
Quoted 7 lines
Quoted 3 lines
Sounds like correct but let me loop in Ghenadi as I don't have the platform anymore to check the change
Hi
This one is still outstanding if anyone has a chance to look at it. If not I'll gamble and apply it :)
Yes sure, go ahead
Jonathan Cameron
maintainerQuoted 30 lines · On Fri, 3 Jul 2026 22:42:21 +0200 Daniel Lezcano…
Quoted 29 lines · Jonathan Cameron
Quoted 26 lines · On Tue, 26 May 2026 14:48:44 +0200 Daniel Lezcano…
Quoted 17 lines · Jonathan Cameron
Quoted 8 lines · On Tue, 19 May 2026 23:56:06 +0200 Andy Shevchenko…
The original code was using
ndelay()twice. In one case the delay is calculated as 1/3 of ADC clock and in the other as 80 ADC clocks. But according to the comments in all cases it should be a multiplier of the ADC clock, and not a fraction of it. Inadvertentlynxp_sar_adc_wait_for()takes the wrong case and spread it over the code make it wrong in all places. Fix this by modifying a helper to correctly use the multiplier.Quoted 5 lines
Fixes 7e5c0f97c66a ("iio: adc: nxp-sar-adc: Avoid division by zero")Fixes 4434072a893e ("iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms")Reported-by Sashiko <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>Quoted 4 lines
Daniel, could you take a look at this one.
Explanation seems fine but original patch was yours so I'd like some 'aware' eyes on it!
Sounds like correct but let me loop in Ghenadi as I don't have the platform anymore to check the change
Quoted 8 lines
Quoted 4 lines
Hi
This one is still outstanding if anyone has a chance to look at it. If not I'll gamble and apply it :)
Yes sure, go ahead
Acked-by Daniel Lezcano <[email protected]>
Applied and marked for stable
Thanks,
Jonathan