From: Jonathan Cameron <jic23@kernel.org>
To: Ryan Brue <ryanbrue.dev@gmail.com>
Cc: "David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Matthias Brugger" <matthias.bgg@gmail.com>,
"AngeloGioacchino Del Regno"
<angelogioacchino.delregno@collabora.com>,
"Lee Jones" <lee@kernel.org>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, mfd@lists.linux.dev,
"Roman Vivchar" <rva333@protonmail.com>,
"Luca Leonardo Scorcia" <l.scorcia@gmail.com>,
"Andy Shevchenko" <andriy.shevchenko@intel.com>
Subject: Re: [PATCH v4 2/3] iio: adc: mt6397-auxadc: add mt6397 PMIC AUXADC driver
Date: Mon, 19 Oct 2026 03:13:33 +0100 [thread overview]
Message-ID: <20261019031333.1010682f@jic23-hlaptop> (raw)
In-Reply-To: <20260928-rbrue-suez-upstreaming-mt6397-auxadc-v4-2-23533a0d30e3@gmail.com>
On Mon, 28 Sep 2026 15:57:20 -0500
Ryan Brue <ryanbrue.dev@gmail.com> wrote:
> The mt6397 AUXADC is a 10-bit ADC behind the SoC's PMIC wrapper. On boards
> built around this PMIC it is the only way to read the battery: the SoC's
> AUXADC is wired to board thermistors and the charger ICs these boards use
> have no ADC of their own.
>
> Add a driver exposing the battery voltage and battery temperature
> channels. Only those two are described, so a channel ID in the device tree
> indexes the driver's channel array rather than the PMIC's channel number,
> as mt6323-auxadc does. The ready bit lives in a channel's raw result
> register, but the value comes from the chip's factory-calibrated copy.
>
> The battery voltage is measured through ISENSE, because a board with a
> switching charger in the power path leaves BATSNS on the charger's system
> rail instead of on the pack. The thermistor only reads correctly with the
> PMIC's battery-detect bias and input buffer enabled, which take 20 ms to
> settle. Both are switched back off afterwards.
>
> Reads average sixteen conversions in software; the chip's sample
> accumulator makes no measurable difference at any setting, so it is left
> at one sample per conversion.
>
> Assisted-by: LLM
> Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
Hi Ryan
Sorry for the delay.
Just one thing inline. If I wasn't tired from a long day
of review I might just have made the change and asked you
to check it. So bad luck on that!
Thanks,
Jonathan
> diff --git a/drivers/iio/adc/mt6397-auxadc.c b/drivers/iio/adc/mt6397-auxadc.c
> new file mode 100644
> index 000000000000..8d1702658876
> --- /dev/null
> +++ b/drivers/iio/adc/mt6397-auxadc.c
> +static void mt6397_auxadc_release(struct mt6397_auxadc *adc,
> + const struct iio_chan_spec *chan)
> +{
> + /* Lowering START leaves the converter unarmed between reads. */
> + regmap_clear_bits(adc->regmap, MT6397_AUXADC_CON1, MT6397_AUXADC_CON1_START);
> +
> + if (chan->channel == MT6397_AUXADC_ISENSE)
> + mt6397_auxadc_isense_disable(adc);
> + else
> + mt6397_auxadc_battemp_bias_off(adc);
> +}
> +
> +static int mt6397_auxadc_read_channel(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan,
> + int *val)
> +{
> + struct mt6397_auxadc *adc = iio_priv(indio_dev);
> + int ret;
> +
> + mutex_lock(&adc->lock);
> +
> + if (chan->channel == MT6397_AUXADC_ISENSE) {
> + ret = mt6397_auxadc_isense_enable(adc);
> + if (ret)
> + goto out_release;
> +
> + fsleep(MT6397_AUXADC_ISENSE_SETTLE_US);
> + } else {
> + ret = mt6397_auxadc_battemp_bias_on(adc);
> + if (ret)
> + goto out_release;
> +
> + fsleep(MT6397_AUXADC_BATTEMP_SETTLE_US);
> + }
> +
> + ret = mt6397_auxadc_read_burst(adc, chan, val);
> +
> +out_release:
> + mt6397_auxadc_release(adc, chan);
This ends up rather confusing. Would you mind instead doing it as a pair of helpers
and a top level bit of code that does.
guard(mutex)(&adc->lock);
if (chan->channel == MT6397_AUXADC_ISENSE) {
return mt6397_auxadc_isense_read();
else
return mt6397_auxadc_battemp_read();
The only thing that get duplicated is the call to read_burst()
which seems simpler than having a pair of if / else on the channel
(one hidden in this release).
> + mutex_unlock(&adc->lock);
> +
> + return ret;
> +}
next prev parent reply other threads:[~2026-10-19 2:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 20:57 [PATCH v4 0/3] iio: adc: add mt6397 PMIC AUXADC support Ryan Brue
2026-09-28 20:57 ` [PATCH v4 1/3] dt-bindings: iio: adc: mediatek,mt6359-auxadc: add mt6397 PMIC AUXADC Ryan Brue
2026-09-28 20:57 ` [PATCH v4 2/3] iio: adc: mt6397-auxadc: add mt6397 PMIC AUXADC driver Ryan Brue
2026-09-28 21:49 ` Andy Shevchenko
2026-10-19 2:13 ` Jonathan Cameron [this message]
2026-09-28 20:57 ` [PATCH v4 3/3] mfd: mt6397-core: Add mt6397 AUXADC support Ryan Brue
2026-10-15 12:17 ` (subset) " Lee Jones
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=20261019031333.1010682f@jic23-hlaptop \
--to=jic23@kernel.org \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=l.scorcia@gmail.com \
--cc=lee@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=mfd@lists.linux.dev \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=rva333@protonmail.com \
--cc=ryanbrue.dev@gmail.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
all inboxes | Powered by JetHome®