From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
andy@kernel.org, robh@kernel.org, conor+dt@kernel.org,
krzk+dt@kernel.org, linux-iio@vger.kernel.org, s32@nxp.com,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
chester62515@gmail.com, mbrugger@suse.com,
ghennadi.procopciuc@oss.nxp.com
Subject: Re: [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms
Date: Thu, 4 Sep 2025 10:33:14 +0300 [thread overview]
Message-ID: <aLlAugdr-hwMNIje@smile.fi.intel.com> (raw)
In-Reply-To: <a34efc36-0100-4a7f-b131-566413ab88ae@linaro.org>
On Wed, Sep 03, 2025 at 05:28:09PM +0200, Daniel Lezcano wrote:
> On 03/09/2025 13:48, Andy Shevchenko wrote:
> > On Wed, Sep 03, 2025 at 12:27:56PM +0200, Daniel Lezcano wrote:
...
> > > +#include <linux/circ_buf.h>
> >
> > Why not kfifo?
>
> Are you suggesting to use kfifo instead of the circular buffer in the code ?
Asking, due to relatively recent move in the whole serial subsystem.
...
> > > +#define NXP_SAR_ADC_CAL_TIMEOUT_US 100000
> >
> > (100 * USEC_PER_MSEC)
> >
> > > +#define NXP_SAR_ADC_WAIT_US 2000
> >
> > (2 * USEC_PER_MSEC)
>
> Why is this more understandable than the raw value ?
Because instead of counting 0:s and checking the suffix, I can immediately read
from the value like:
"This is 2 milliseconds in microseconds units."
It's more understandable and robust against possible typos.
...
> > > +#define NXP_SAR_ADC_DMA_BUFF_SZ (PAGE_SIZE * NXP_SAR_ADC_DMA_SAMPLE_SZ)
> >
> > Oh, PAGE_SIZE is not good to use. I believe this HW is not tolerant to any page size.
> > (Note, we made similar mistake in Intel IPU3 camera driver, which is now fixed)
>
> Is it acceptable to put a hardcoded 4096 value ?
Sure, define it like HW page size
/* This ADC relies on the page size to be 4kB */
NXP_SAR_PAGE_SIZE 0x1000 // or SZ_4K, or ...
...
> > > + ret = read_poll_timeout(readl, msr, !(msr & REG_ADC_MSR_CALBUSY),
> >
> > Why not readl_poll_timeout()?
> >
> > > + NXP_SAR_ADC_WAIT_US,
> > > + NXP_SAR_ADC_CAL_TIMEOUT_US,
> > > + true, REG_ADC_MSR(base));
> > > + if (ret)
> > > + return ret;
> >
> > > + if (!(msr & REG_ADC_MSR_CALFAIL))
> > > + return 0;
> >
> > I would expect standard pattern — "errors first", but here either works.
>
> Does it mean this chunk of code can be preserved or do you prefer an error
> block followed with a return 0 ?
Up to you. Only the question above (readl_poll_timeout() use) stays unanswered
so far.
...
> > > + /*
> > > + * On disable, we have to wait for the transaction to finish.
> > > + * ADC does not abort the transaction if a chain conversion
> > > + * is in progress.
> > > + * Wait for the worst case scenario - 80 ADC clk cycles.
> > > + */
> > > + ndelay(div64_u64(NSEC_PER_SEC, clk_get_rate(info->clk)) * 80U);
> >
> > Could it possible go wrong and with low rate clocks (kHz:ish) this will go into
> > lo-o-o-o-ng *atomic* delay?
>
> It is the ADC clock where we need to wait for 80 cycles. The lowest clock
> rate is 40MHz, but on this platform it is 80MHz IIRC. This routine is called
> only when the capture finishes. Except I'm missing something, this scenario
> should not happen.
So, you guarantee that clk_get_rate() never returns, let's say 1000, right?
(Personally I don't see how it's possible to guarantee...)
...
> > > + nxp_sar_adc_channels_enable(info, 1 >> chan->channel);
> >
> > 1 >> ?!? Did you want BIT(channel)? Or simply channel != 0?
>
> Yeah, BIT(chan->channel) is better
But is the above a bug in the original proposal or not? I mean one wanted left
instead of right shift.
...
> > > + dmaengine_tx_status(info->dma_chan,
> > > + info->cookie, &state);
> >
> > Perfectly one line. No return check?
>
> Ok, will see if the IIO DMA API has an impact on this portion of code before
> checking the return code. However, the status is often ignored in the other
> drivers.
...which doesn't mean it's a good example to follow.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2025-09-04 7:33 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-03 10:27 [PATCH v1 0/2] NXP SAR ADC IIO driver for s32g2/3 platforms Daniel Lezcano
2025-09-03 10:27 ` [PATCH v1 1/2] dt-bindings: iio: adc: Add the NXP SAR ADC " Daniel Lezcano
2025-09-03 21:52 ` Rob Herring (Arm)
2025-09-04 19:47 ` David Lechner
2025-09-06 7:29 ` Krzysztof Kozlowski
2025-09-03 10:27 ` [PATCH v1 2/2] iio: adc: Add the NXP SAR ADC support for the " Daniel Lezcano
2025-09-03 11:20 ` Nuno Sá
2025-09-03 14:53 ` Daniel Lezcano
2025-09-03 15:41 ` Jonathan Cameron
2025-09-04 17:40 ` Daniel Lezcano
2025-09-04 17:49 ` David Lechner
2025-09-05 9:44 ` Daniel Lezcano
2025-09-05 15:25 ` David Lechner
2025-09-05 20:58 ` Daniel Lezcano
2025-09-05 21:54 ` David Lechner
2025-09-08 12:16 ` Daniel Lezcano
2025-09-08 13:58 ` David Lechner
2025-09-09 9:29 ` Nuno Sá
2025-09-09 16:22 ` Daniel Lezcano
2025-09-10 11:57 ` Nuno Sá
2025-09-10 16:21 ` Jonathan Cameron
2025-09-03 11:48 ` Andy Shevchenko
2025-09-03 15:28 ` Daniel Lezcano
2025-09-04 7:33 ` Andy Shevchenko [this message]
2025-09-04 16:52 ` Daniel Lezcano
2025-09-09 9:04 ` Daniel Lezcano
2025-09-06 7:34 ` Krzysztof Kozlowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aLlAugdr-hwMNIje@smile.fi.intel.com \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=chester62515@gmail.com \
--cc=conor+dt@kernel.org \
--cc=daniel.lezcano@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=ghennadi.procopciuc@oss.nxp.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mbrugger@suse.com \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=s32@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.