From: Jonathan Cameron <jic23@kernel.org>
To: Rodrigo Alencar <455.rodrigo.alencar@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
David Lechner <dlechner@baylibre.com>,
Andy Shevchenko <andy@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Rodrigo Alencar <rodrigo.alencar@analog.com>
Subject: Re: [PATCH v12 07/11] iio: frequency: adf41513: driver implementation
Date: Tue, 12 May 2026 12:31:59 +0100 [thread overview]
Message-ID: <20260512123159.11d7fe6f@jic23-huawei> (raw)
In-Reply-To: <svusdjojnunrgjuojwk3htqdudzesnc2owfd5wmbvp56ap22oq@7nr6p7fpozin>
> >
> > > +static int adf41513_set_frequency(struct adf41513_state *st, u64 freq_uhz, u16 sync_mask)
> > > +{
> > > + struct adf41513_pll_settings result;
> > > + int ret;
> > > +
> > > + ret = adf41513_calc_pll_settings(st, &result, freq_uhz);
> > > + if (ret < 0)
> > > + return ret;
> > > +
> > > + /* apply computed results to pll settings */
> > > + st->settings = result;
> >
> > [ ... ]
> >
> > > + if (st->settings.mode == ADF41513_MODE_INTEGER_N) {
> > > + st->regs[ADF41513_REG6] |= ADF41513_REG6_INT_MODE_MSK;
> > > + st->regs[ADF41513_REG6] &= ~ADF41513_REG6_BLEED_ENABLE_MSK;
> > > + } else {
> > > + st->regs[ADF41513_REG6] &= ~ADF41513_REG6_INT_MODE_MSK;
> > > + st->regs[ADF41513_REG6] |= ADF41513_REG6_BLEED_ENABLE_MSK;
> > > + }
> > > +
> > > + return adf41513_sync_config(st, sync_mask | ADF41513_SYNC_REG0);
> > > +}
> >
> > If the adf41513_sync_config() SPI write fails, st->settings and st->regs
> > have already been updated with the new configuration.
> >
> > Will a subsequent read of the frequency channel via adf41513_pll_get_rate()
> > return this failed frequency instead of the actual physical hardware frequency?
>
> Not seeing much problem with that. Reversing the state on every spi write failure
> would be too much effort for an error that is already reported to the user.
> Most likely another spi write attempt might fail as well, so would it be a platform
> problem?
>
Agreed. It is fair that sashikio raises it as a concern to look at but
as you say unwinding state like this on an spi error is fiddly. I think it's
only necessary if the device ends up wedged as a result. As long as we can just
try rewriting the original thing that triggered this flow, not a problem.
What to do in cases like when we get errors during buffered accesses is more
of a black art. I'm not inclined to spend much effort and greater code complexity
to harden against those - the way out can sometimes be unbind/rebind the driver.
> > [ ... ]
> >
> > > +static int adf41513_write_raw(struct iio_dev *indio_dev,
> > > + struct iio_chan_spec const *chan,
> > > + int val, int val2, long info)
> > > +{
> >
> > [ ... ]
> >
> > > + case IIO_CHAN_INFO_PHASE:
> > > + if (tmp64 >= ADF41513_MAX_PHASE_MICRORAD)
> > > + return -EINVAL;
> > > +
> > > + phase_val = DIV_U64_ROUND_CLOSEST(tmp64 << 12,
> > > + ADF41513_MAX_PHASE_MICRORAD);
> > > + phase_val = min(phase_val, ADF41513_MAX_PHASE_VAL);
> > > + st->regs[ADF41513_REG2] |= ADF41513_REG2_PHASE_ADJ_MSK;
> > > + FIELD_MODIFY(ADF41513_REG2_PHASE_VAL_MSK,
> > > + &st->regs[ADF41513_REG2], phase_val);
> > > + return adf41513_sync_config(st, ADF41513_SYNC_REG0);
> >
> > The ADF41513_REG2_PHASE_ADJ_MSK bit is set in the software shadow register,
> > but does not appear to be cleared after the shift completes.
> >
> > Because the hardware evaluates the PHASE_ADJ bit in REG2 on every REG0 write,
> > could this cause unintended phase shifts during future frequency updates?
>
> We don't need to clear that, if phase adjust is set then the phase shift is going
> to be applied. There is no phase accumulation or side effects. I think the
> datasheet could improve on that, but later on it says:
>
> The phase word in Register 2 controls the RF output phase. As this
> word is changed from 0 to 2^12, the RF output phase changes over a
> 360° range in steps of phase value × 360°/2^12.
Bit of a running theme that AI bots sometime point out unclear datasheet
text ;) I know folk were using them to scan specifications looking for this
sort of stuff where it's possible humans would also get them wrong.
>
> > [ ... ]
> >
> > > +static int adf41513_pm_resume(struct device *dev)
> > > +{
> > > + struct adf41513_state *st = dev_get_drvdata(dev);
> > > +
> > > + guard(mutex)(&st->lock);
> > > + if (st->powerdown)
> > > + return 0; /* nothing to do */
> > > +
> > > + return adf41513_resume(st);
> > > +}
> >
> > If the system cuts power to the regulators during sleep, the chip wakes up
> > in its default Power-On Reset (POR) state.
> >
> > If st->powerdown is true, this function returns early and st->regs_hw is
> > not invalidated.
> >
> > Could this leave the software state out of sync with the physical hardware,
> > causing future partial writes to leave the chip unconfigured?
>
> That is not an issue because partial writes would not power the device.
> Also the resume() function makes sure to write all registers so a power-up
> sequence is completed.
Makes sense. Thanks for addressing all these nice and clearly! Helps me
a lot. Whilst sashikio is great, dealing with everything it reports is
making reviews take a lot longer.
Jonathan
>
> > --
> > Sashiko AI review · https://sashiko.dev/#/patchset/20260510-adf41513-iio-driver-v12-0-34af2ed2779f@analog.com?part=7
>
next prev parent reply other threads:[~2026-05-12 11:32 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-10 12:42 [PATCH v12 00/11] ADF41513/ADF41510 PLL frequency synthesizers Rodrigo Alencar via B4 Relay
2026-05-10 12:42 ` [PATCH v12 01/11] dt-bindings: iio: frequency: add adf41513 Rodrigo Alencar via B4 Relay
2026-05-10 12:42 ` [PATCH v12 02/11] lib: kstrtox: add kstrtoudec64() and kstrtodec64() Rodrigo Alencar via B4 Relay
2026-05-12 11:39 ` Jonathan Cameron
2026-05-12 11:52 ` Rodrigo Alencar
2026-05-12 13:12 ` Andy Shevchenko
2026-05-12 13:21 ` Rodrigo Alencar
2026-05-12 13:48 ` Andy Shevchenko
2026-05-12 14:12 ` Rodrigo Alencar
2026-05-12 14:43 ` Andy Shevchenko
2026-05-12 15:11 ` Rodrigo Alencar
2026-05-12 15:21 ` Andy Shevchenko
2026-05-12 16:18 ` David Laight
2026-05-12 17:08 ` Andy Shevchenko
2026-05-12 16:35 ` Rodrigo Alencar
2026-05-12 17:13 ` Andy Shevchenko
2026-05-12 17:26 ` Rodrigo Alencar
2026-05-12 17:46 ` Andy Shevchenko
2026-05-12 18:15 ` Rodrigo Alencar
2026-05-12 19:08 ` Andy Shevchenko
2026-05-12 19:39 ` Rodrigo Alencar
2026-05-12 20:16 ` Andy Shevchenko
2026-05-13 7:14 ` Rodrigo Alencar
2026-05-13 10:09 ` David Laight
2026-05-13 9:41 ` Rodrigo Alencar
2026-05-10 12:42 ` [PATCH v12 03/11] lib: test-kstrtox: tests for kstrtodec64() and kstrtoudec64() Rodrigo Alencar via B4 Relay
2026-05-12 13:51 ` Andy Shevchenko
2026-05-10 12:42 ` [PATCH v12 04/11] lib: math: div64: add div64_s64_rem() Rodrigo Alencar via B4 Relay
2026-05-12 13:50 ` Andy Shevchenko
2026-05-10 12:42 ` [PATCH v12 05/11] iio: core: add decimal value formatting into 64-bit value Rodrigo Alencar via B4 Relay
2026-05-12 14:35 ` Andy Shevchenko
2026-05-12 16:09 ` Rodrigo Alencar
2026-05-12 17:49 ` Andy Shevchenko
2026-05-12 19:01 ` Rodrigo Alencar
2026-05-10 12:42 ` [PATCH v12 06/11] iio: test: iio-test-format: add test case for decimal format Rodrigo Alencar via B4 Relay
2026-05-12 14:36 ` Andy Shevchenko
2026-05-12 17:02 ` Rodrigo Alencar
2026-05-12 17:51 ` Andy Shevchenko
2026-05-10 12:42 ` [PATCH v12 07/11] iio: frequency: adf41513: driver implementation Rodrigo Alencar via B4 Relay
[not found] ` <20260511224355.6ED49C2BCB0@smtp.kernel.org>
2026-05-12 10:15 ` Rodrigo Alencar
2026-05-12 11:31 ` Jonathan Cameron [this message]
2026-05-10 12:42 ` [PATCH v12 08/11] iio: frequency: adf41513: handle LE synchronization feature Rodrigo Alencar via B4 Relay
2026-05-10 12:42 ` [PATCH v12 09/11] iio: frequency: adf41513: features on frequency change Rodrigo Alencar via B4 Relay
2026-05-10 12:42 ` [PATCH v12 10/11] docs: iio: add documentation for adf41513 driver Rodrigo Alencar via B4 Relay
2026-05-10 12:42 ` [PATCH v12 11/11] Documentation: ABI: testing: add common ABI file for iio/frequency Rodrigo Alencar via B4 Relay
2026-05-12 11:36 ` Jonathan Cameron
2026-05-12 11:48 ` [PATCH v12 00/11] ADF41513/ADF41510 PLL frequency synthesizers Jonathan Cameron
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=20260512123159.11d7fe6f@jic23-huawei \
--to=jic23@kernel.org \
--cc=455.rodrigo.alencar@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rodrigo.alencar@analog.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox