* [PATCH v1 1/1] iio: adc: nxp-sar-adc: Fix the delay calculation in nxp_sar_adc_wait_for()
@ 2026-05-19 21:56 Andy Shevchenko
2026-05-20 11:42 ` Stepan Ionichev
2026-05-22 17:35 ` Jonathan Cameron
0 siblings, 2 replies; 7+ messages in thread
From: Andy Shevchenko @ 2026-05-19 21:56 UTC (permalink / raw)
To: Jonathan Cameron, Daniel Lezcano, linux-iio, linux-kernel
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Andy Shevchenko,
Sashiko
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.
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 <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260416090122.758990-1-andriy.shevchenko%40linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/iio/adc/nxp-sar-adc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/nxp-sar-adc.c b/drivers/iio/adc/nxp-sar-adc.c
index 01f3da56e987..68d237ef30c2 100644
--- a/drivers/iio/adc/nxp-sar-adc.c
+++ b/drivers/iio/adc/nxp-sar-adc.c
@@ -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)
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v1 1/1] iio: adc: nxp-sar-adc: Fix the delay calculation in nxp_sar_adc_wait_for()
2026-05-19 21:56 [PATCH v1 1/1] iio: adc: nxp-sar-adc: Fix the delay calculation in nxp_sar_adc_wait_for() Andy Shevchenko
@ 2026-05-20 11:42 ` Stepan Ionichev
2026-05-22 17:35 ` Jonathan Cameron
1 sibling, 0 replies; 7+ messages in thread
From: Stepan Ionichev @ 2026-05-20 11:42 UTC (permalink / raw)
To: andriy.shevchenko
Cc: jic23, daniel.lezcano, dlechner, nuno.sa, andy, sashiko-bot,
linux-iio, linux-kernel, Stepan Ionichev
Reviewed-by: Stepan Ionichev <sozdayvek@gmail.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/1] iio: adc: nxp-sar-adc: Fix the delay calculation in nxp_sar_adc_wait_for()
2026-05-19 21:56 [PATCH v1 1/1] iio: adc: nxp-sar-adc: Fix the delay calculation in nxp_sar_adc_wait_for() Andy Shevchenko
2026-05-20 11:42 ` Stepan Ionichev
@ 2026-05-22 17:35 ` Jonathan Cameron
2026-05-26 12:48 ` Daniel Lezcano
1 sibling, 1 reply; 7+ messages in thread
From: Jonathan Cameron @ 2026-05-22 17:35 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Daniel Lezcano, linux-iio, linux-kernel, David Lechner,
Nuno Sá, Andy Shevchenko, Sashiko
On Tue, 19 May 2026 23:56:06 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 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.
>
> 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 <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/patchset/20260416090122.758990-1-andriy.shevchenko%40linux.intel.com
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
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!
> ---
> drivers/iio/adc/nxp-sar-adc.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/adc/nxp-sar-adc.c b/drivers/iio/adc/nxp-sar-adc.c
> index 01f3da56e987..68d237ef30c2 100644
> --- a/drivers/iio/adc/nxp-sar-adc.c
> +++ b/drivers/iio/adc/nxp-sar-adc.c
> @@ -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)
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v1 1/1] iio: adc: nxp-sar-adc: Fix the delay calculation in nxp_sar_adc_wait_for()
2026-05-22 17:35 ` Jonathan Cameron
@ 2026-05-26 12:48 ` Daniel Lezcano
2026-07-03 19:06 ` Jonathan Cameron
0 siblings, 1 reply; 7+ messages in thread
From: Daniel Lezcano @ 2026-05-26 12:48 UTC (permalink / raw)
To: Jonathan Cameron, Andy Shevchenko, Ghennadi Procopciuc
Cc: Daniel Lezcano, linux-iio, linux-kernel, David Lechner,
Nuno Sá, Andy Shevchenko, Sashiko
On 5/22/26 19:35, Jonathan Cameron wrote:
> On Tue, 19 May 2026 23:56:06 +0200
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
>
>> 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.
>>
>> 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 <sashiko-bot@kernel.org>
>> Closes: https://sashiko.dev/#/patchset/20260416090122.758990-1-andriy.shevchenko%40linux.intel.com
>> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v1 1/1] iio: adc: nxp-sar-adc: Fix the delay calculation in nxp_sar_adc_wait_for()
2026-05-26 12:48 ` Daniel Lezcano
@ 2026-07-03 19:06 ` Jonathan Cameron
2026-07-03 20:42 ` Daniel Lezcano
0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Cameron @ 2026-07-03 19:06 UTC (permalink / raw)
To: Daniel Lezcano
Cc: Andy Shevchenko, Ghennadi Procopciuc, Daniel Lezcano, linux-iio,
linux-kernel, David Lechner, Nuno Sá, Andy Shevchenko,
Sashiko
On Tue, 26 May 2026 14:48:44 +0200
Daniel Lezcano <daniel.lezcano@oss.qualcomm.com> wrote:
> On 5/22/26 19:35, Jonathan Cameron wrote:
> > On Tue, 19 May 2026 23:56:06 +0200
> > Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> >
> >> 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.
> >>
> >> 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 <sashiko-bot@kernel.org>
> >> Closes: https://sashiko.dev/#/patchset/20260416090122.758990-1-andriy.shevchenko%40linux.intel.com
> >> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> >
> > 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
>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v1 1/1] iio: adc: nxp-sar-adc: Fix the delay calculation in nxp_sar_adc_wait_for()
2026-07-03 19:06 ` Jonathan Cameron
@ 2026-07-03 20:42 ` Daniel Lezcano
2026-07-03 22:55 ` Jonathan Cameron
0 siblings, 1 reply; 7+ messages in thread
From: Daniel Lezcano @ 2026-07-03 20:42 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Andy Shevchenko, Ghennadi Procopciuc, Daniel Lezcano, linux-iio,
linux-kernel, David Lechner, Nuno Sá, Andy Shevchenko,
Sashiko
On 7/3/26 21:06, Jonathan Cameron wrote:
> On Tue, 26 May 2026 14:48:44 +0200
> Daniel Lezcano <daniel.lezcano@oss.qualcomm.com> wrote:
>
>> On 5/22/26 19:35, Jonathan Cameron wrote:
>>> On Tue, 19 May 2026 23:56:06 +0200
>>> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
>>>
>>>> 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.
>>>>
>>>> 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 <sashiko-bot@kernel.org>
>>>> Closes: https://sashiko.dev/#/patchset/20260416090122.758990-1-andriy.shevchenko%40linux.intel.com
>>>> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>>>
>>> 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 :)
Yes sure, go ahead
Acked-by: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v1 1/1] iio: adc: nxp-sar-adc: Fix the delay calculation in nxp_sar_adc_wait_for()
2026-07-03 20:42 ` Daniel Lezcano
@ 2026-07-03 22:55 ` Jonathan Cameron
0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2026-07-03 22:55 UTC (permalink / raw)
To: Daniel Lezcano
Cc: Andy Shevchenko, Ghennadi Procopciuc, Daniel Lezcano, linux-iio,
linux-kernel, David Lechner, Nuno Sá, Andy Shevchenko,
Sashiko
On Fri, 3 Jul 2026 22:42:21 +0200
Daniel Lezcano <daniel.lezcano@oss.qualcomm.com> wrote:
> On 7/3/26 21:06, Jonathan Cameron wrote:
> > On Tue, 26 May 2026 14:48:44 +0200
> > Daniel Lezcano <daniel.lezcano@oss.qualcomm.com> wrote:
> >
> >> On 5/22/26 19:35, Jonathan Cameron wrote:
> >>> On Tue, 19 May 2026 23:56:06 +0200
> >>> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> >>>
> >>>> 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.
> >>>>
> >>>> 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 <sashiko-bot@kernel.org>
> >>>> Closes: https://sashiko.dev/#/patchset/20260416090122.758990-1-andriy.shevchenko%40linux.intel.com
> >>>> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> >>>
> >>> 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 :)
>
> Yes sure, go ahead
>
> Acked-by: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
Applied and marked for stable
Thanks,
Jonathan
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-07-03 22:56 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-19 21:56 [PATCH v1 1/1] iio: adc: nxp-sar-adc: Fix the delay calculation in nxp_sar_adc_wait_for() Andy Shevchenko
2026-05-20 11:42 ` Stepan Ionichev
2026-05-22 17:35 ` Jonathan Cameron
2026-05-26 12:48 ` Daniel Lezcano
2026-07-03 19:06 ` Jonathan Cameron
2026-07-03 20:42 ` Daniel Lezcano
2026-07-03 22:55 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox