AUXADC driver for the MediaTek mt6323 PMIC
Subsystems (5)
Roman Vivchar
maintainerv2 cover AUXADC driver for the MediaTek mt6323 PMIC
This series adds support for the 15-bit AUXADC hardware block found on the MediaTek mt6323 PMIC.
The previous version of the series for all AUXADC, EFUSE and thermal drivers was split after Krzysztof's comment [1].
Tested on the MediaTek mt6572 and mt8163 SoCs (Ben), both paired with a mt6323.
The other parts (EFUSE and thermal) will probably be sent this week.
---
Changes in v2:
- AUXADC driver:
- Drop channel type from the MTK_PMIC_IIO_CHAN macro (Nuno)
- Drop kerneldoc for the mt6323_auxadc struct (Nuno)
- Add channel release to save power (Sashiko, Jonathan)
- Drop 'reg' variable in the mt6323_auxadc_read (Jonathan)
- Sort variables in the mt6323_auxadc_probe (Jonathan)
- Maintainers:
- Drop linux-mediatek list (Andy)
- Split between dt-bindings and driver to avoid missing file (Nuno)
- Link to v1: https://patch.msgid.link/[email protected]
Changes after split:
- dt-bindings: Change 'MT63xx' to 'MT6350 series and similar' (Jonathan)
- AUXADC driver:
- Add missing headers (Andy)
- Fix AUXADC_TRIM_CH* values (Andy)
- Rename masks to include their register name (Jonathan)
- Fix formatting (Andy, Jonathan)
- Replace channel address with actual register value (Jonathan), align the table
- Replace IIO_TEMP with IIO_VOLTAGE, since the actual output is still mV, not mC
- Rename constants to match their registers (Jonathan)
- Remove 'if/else if/else' in the mt6323_auxadc_read_raw (Andy)
- Add comments for fsleep, ADC range and resolution (Andy, Jonathan)
- Remove useless error messages (Andy)
- Maintainers:
- Explicitly include mt6323 in the name (Jonathan)
- Squash with AUXADC driver commit (Krzysztof)
- Set status back to 'Maintained'
- Link to a previous series: https://patch.msgid.link/[email protected]
---
Roman Vivchar (4):
dt-bindings: iio: adc: mediatek,mt6359-auxadc: add mt6323 PMIC AUXADC
iio: adc: mt6323-auxadc: add mt6323 PMIC AUXADC driver
mfd: mt6397-core: add mt6323 AUXADC support
ARM: dts: mediatek: mt6323: add AUXADC support
.../bindings/iio/adc/mediatek,mt6359-auxadc.yaml | 3 +- MAINTAINERS | 7 + arch/arm/boot/dts/mediatek/mt6323.dtsi | 5 + drivers/iio/adc/Kconfig | 11 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/mt6323-auxadc.c | 305 +++++++++++++++++++++ drivers/mfd/mt6397-core.c | 3 + .../dt-bindings/iio/adc/mediatek,mt6323-auxadc.h | 24 ++ 8 files changed, 358 insertions(+), 1 deletion(-)
---
base-commit: 028ef9c96e96197026887c0f092424679298aae8
change-id: 20260525-mt6323-adc-3befce36cbf2
Best regards,
Signature · 1 line
Roman Vivchar <[email protected]>
Roman Vivchar
maintainerPATCH v2 1/4 dt-bindings: iio: adc: mediatek,mt6359-auxadc: add mt6323 PMIC AUXADC
The MediaTek mt6323 PMIC includes an AUXADC used for battery voltage, temperature, and other internal measurements.
Add the devicetree binding documentation and the associated header file defining the ADC channel constants.
Also change the description to 'MT6350 series and similar' because the binding already includes more than mt635x series PMICs.
Finally, add the MAINTAINERS entry for the header with ADC constants.
--- .../bindings/iio/adc/mediatek,mt6359-auxadc.yaml | 3 ++- MAINTAINERS | 6 ++++++ .../dt-bindings/iio/adc/mediatek,mt6323-auxadc.h | 24 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/iio/adc/mediatek,mt6359-auxadc.yaml +2 -1
@@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/iio/adc/mediatek,mt6359-auxadc.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: MediaTek MT6350 series PMIC AUXADC +title: MediaTek MT6350 series and similar PMIC AUXADC maintainers: - AngeloGioacchino Del Regno <[email protected]>
@@ -19,6 +19,7 @@ description: properties: compatible: enum: + - mediatek,mt6323-auxadc - mediatek,mt6357-auxadc - mediatek,mt6358-auxadc - mediatek,mt6359-auxadc
MAINTAINERS +6 -0
@@ -16256,6 +16256,12 @@ S: Maintained F: Documentation/devicetree/bindings/mmc/mtk-sd.yaml F: drivers/mmc/host/mtk-sd.c +MEDIATEK MT6323 PMIC AUXADC DRIVER +M: Roman Vivchar <[email protected]> +L: [email protected] +S: Maintained +F: include/dt-bindings/iio/adc/mediatek,mt6323-auxadc.h + MEDIATEK MT6735 CLOCK & RESET DRIVERS M: Yassine Oudjana <[email protected]> L: [email protected]
include/dt-bindings/iio/adc/mediatek,mt6323-auxadc.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ + +#ifndef _DT_BINDINGS_MEDIATEK_MT6323_AUXADC_H +#define _DT_BINDINGS_MEDIATEK_MT6323_AUXADC_H + +#define MT6323_AUXADC_BATON2 0 +#define MT6323_AUXADC_CH6 1 +#define MT6323_AUXADC_BAT_TEMP 2 +#define MT6323_AUXADC_CHIP_TEMP 3 +#define MT6323_AUXADC_VCDT 4 +#define MT6323_AUXADC_BATON1 5 +#define MT6323_AUXADC_ISENSE 6 +#define MT6323_AUXADC_BATSNS 7 +#define MT6323_AUXADC_ACCDET 8 +#define MT6323_AUXADC_AUDIO0 9 +#define MT6323_AUXADC_AUDIO1 10 +#define MT6323_AUXADC_AUDIO2 11 +#define MT6323_AUXADC_AUDIO3 12 +#define MT6323_AUXADC_AUDIO4 13 +#define MT6323_AUXADC_AUDIO5 14 +#define MT6323_AUXADC_AUDIO6 15 +#define MT6323_AUXADC_AUDIO7 16 + +#endif
Signature · 1 line
2.54.0
Re: [PATCH v2 1/4] dt-bindings: iio: adc: mediatek,mt6359-auxadc: add mt6323 PMIC AUXADC
Quoted 34 lines · On Tue, Jun 09, 2026 at 04:31:58PM +0300, Roman Vivchar via B4 Relay wrote:
From: Roman Vivchar <[email protected]>
The MediaTek mt6323 PMIC includes an AUXADC used for battery voltage, temperature, and other internal measurements.
Add the devicetree binding documentation and the associated header file defining the ADC channel constants.
Also change the description to 'MT6350 series and similar' because the binding already includes more than mt635x series PMICs.
Finally, add the
MAINTAINERSentry for the header with ADC constants.Signed-off-by Roman Vivchar <[email protected]>--- .../bindings/iio/adc/mediatek,mt6359-auxadc.yaml | 3 ++- MAINTAINERS | 6 ++++++ .../dt-bindings/iio/adc/mediatek,mt6323-auxadc.h | 24 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/iio/adc/mediatek,mt6359-auxadc.yaml +1
-1@@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/iio/adc/mediatek,mt6359-auxadc.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: MediaTek MT6350 series PMIC AUXADC +title: MediaTek MT6350 series and similar PMIC AUXADC maintainers: - AngeloGioacchino Del Regno <[email protected]>
Documentation/devicetree/bindings/iio/adc/mediatek,mt6359-auxadc.yaml description: · line 22
Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/mediatek,mt6359-auxadc.yaml +1
-0@@ -19,6 +19,7 @@ description: properties: compatible: enum: + - mediatek,mt6323-auxadc
Commit message needs to explain why a fallback is not suitable.
pw-bot: changes-requested
Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/mediatek,mt6359-auxadc.yaml +0
-0- mediatek,mt6357-auxadc - mediatek,mt6358-auxadc - mediatek,mt6359-auxadcMAINTAINERS +0
-0
MAINTAINERS S: Maintained · line 16263
Quoted 8 lines
MAINTAINERS +5
-0@@ -16256,6 +16256,12 @@ S: Maintained F: Documentation/devicetree/bindings/mmc/mtk-sd.yaml F: drivers/mmc/host/mtk-sd.c +MEDIATEK MT6323 PMIC AUXADC DRIVER +M: Roman Vivchar <[email protected]> +L: [email protected] +S: Maintained +F: include/dt-bindings/iio/adc/mediatek,mt6323-auxadc.h
Why is the binding not being included here?
Cheers,
Conor.
Quoted 39 lines
MAINTAINERS +1
-0+ MEDIATEK MT6735 CLOCK & RESET DRIVERS M: Yassine Oudjana <[email protected]> L: [email protected]include/dt-bindings/iio/adc/mediatek,mt6323-auxadc.h new file +24
-0@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ + +#ifndef _DT_BINDINGS_MEDIATEK_MT6323_AUXADC_H +#define _DT_BINDINGS_MEDIATEK_MT6323_AUXADC_H + +#define MT6323_AUXADC_BATON2 0 +#define MT6323_AUXADC_CH6 1 +#define MT6323_AUXADC_BAT_TEMP 2 +#define MT6323_AUXADC_CHIP_TEMP 3 +#define MT6323_AUXADC_VCDT 4 +#define MT6323_AUXADC_BATON1 5 +#define MT6323_AUXADC_ISENSE 6 +#define MT6323_AUXADC_BATSNS 7 +#define MT6323_AUXADC_ACCDET 8 +#define MT6323_AUXADC_AUDIO0 9 +#define MT6323_AUXADC_AUDIO1 10 +#define MT6323_AUXADC_AUDIO2 11 +#define MT6323_AUXADC_AUDIO3 12 +#define MT6323_AUXADC_AUDIO4 13 +#define MT6323_AUXADC_AUDIO5 14 +#define MT6323_AUXADC_AUDIO6 15 +#define MT6323_AUXADC_AUDIO7 16 + +#endif Signature · 2 lines
-- 2.54.0
Roman Vivchar
maintainerRe: [PATCH v2 1/4] dt-bindings: iio: adc: mediatek,mt6359-auxadc: add mt6323 PMIC AUXADC
Hi Conor,
Quoted 8 lines · Conor Dooley
Quoted 4 lines · On Tue, Jun 09, 2026 at 04:31:58PM +0300, Roman Vivchar via B4 Relay wrote:
properties:
compatible:
enum:
+ - mediatek,mt6323-auxadcCommit message needs to explain why a fallback is not suitable.
pw-bot: changes-requested
Ack.
Quoted 12 lines
Quoted 12 lines
- mediatek,mt6357-auxadc
- mediatek,mt6358-auxadc
- mediatek,mt6359-auxadcMAINTAINERS +0
-0@@ -16256,6 +16256,12 @@ S: Maintained F: Documentation/devicetree/bindings/mmc/mtk-sd.yaml F: drivers/mmc/host/mtk-sd.c
Quoted 8 lines
MAINTAINERS S: Maintained · line 16263
Quoted 5 lines
MAINTAINERS +5
-0+MEDIATEK MT6323 PMIC AUXADC DRIVER +M: Roman Vivchar <[email protected]> +L: [email protected] +S: Maintained +F: include/dt-bindings/iio/adc/mediatek,mt6323-auxadc.hWhy is the binding not being included here?
The binding is shared across multiple PMIC ADCs and maintained by Angelo. Since I'm only familiar with mt6323 and not others like mt6358, I decided to not include it in the mt6323 entry.
Best regards,
Roman
Roman Vivchar
maintainerPATCH v2 2/4 iio: adc: mt6323-auxadc: add mt6323 PMIC AUXADC driver
In reply to Roman VivcharThe mt6323 AUXADC is a 15-bit ADC used for system monitoring. This driver provides support for reading various channels including battery and charger voltages, battery and chip temperature, current sensing and accessory detection.
Add a driver for the AUXADC found in the MediaTek mt6323 PMIC.
--- MAINTAINERS | 1 + drivers/iio/adc/Kconfig | 11 ++ drivers/iio/adc/Makefile | 1 + drivers/iio/adc/mt6323-auxadc.c | 305 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 318 insertions(+)
MAINTAINERS +1 -0
@@ -16260,6 +16260,7 @@ MEDIATEK MT6323 PMIC AUXADC DRIVER M: Roman Vivchar <[email protected]> L: [email protected] S: Maintained +F: drivers/iio/adc/mt6323-auxadc.c F: include/dt-bindings/iio/adc/mediatek,mt6323-auxadc.h MEDIATEK MT6735 CLOCK & RESET DRIVERS
drivers/iio/adc/Kconfig +11 -0
@@ -1137,6 +1137,17 @@ config MCP3911 This driver can also be built as a module. If so, the module will be called mcp3911. +config MEDIATEK_MT6323_AUXADC + tristate "MediaTek MT6323 PMIC AUXADC driver" + depends on MFD_MT6397 + help + Say yes here to enable support for MediaTek MT6323 PMIC Auxiliary ADC. + This driver provides multiple channels for system monitoring, + such as battery voltage, PMIC temperature, and others. + + This driver can also be built as a module. If so, the module will be + called mt6323-auxadc. + config MEDIATEK_MT6359_AUXADC tristate "MediaTek MT6359 PMIC AUXADC driver" depends on MFD_MT6397
drivers/iio/adc/Makefile +1 -0
@@ -99,6 +99,7 @@ obj-$(CONFIG_MCP320X) += mcp320x.o obj-$(CONFIG_MCP3422) += mcp3422.o obj-$(CONFIG_MCP3564) += mcp3564.o obj-$(CONFIG_MCP3911) += mcp3911.o +obj-$(CONFIG_MEDIATEK_MT6323_AUXADC) += mt6323-auxadc.o obj-$(CONFIG_MEDIATEK_MT6359_AUXADC) += mt6359-auxadc.o obj-$(CONFIG_MEDIATEK_MT6360_ADC) += mt6360-adc.o obj-$(CONFIG_MEDIATEK_MT6370_ADC) += mt6370-adc.o
drivers/iio/adc/mt6323-auxadc.c new file +305 -0
305 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v2 2/4] iio: adc: mt6323-auxadc: add mt6323 PMIC AUXADC driver
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] The probe function unconditionally dereferences `dev->parent` and `dev->parent->parent`, which…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] The probe function unconditionally dereferences dev->parent and dev->parent->parent, which will cause a kernel panic if the parent device is NULL.
- [High] The driver incorrectly uses the logical device tree channel index instead of the physical ADC channel index when setting the hardware request bitmask.
- [Medium] The AUXADC voltage buffer (VBUF) is left permanently enabled on error paths, leading to a resource/power leak.
- [Medium] Incorrect IIO channel types are hardcoded as IIO_VOLTAGE for temperature and current channels, violating IIO ABI.
--
commit 5d793b85b8942cff4538a9fd7c909fd225402286
Author: Roman Vivchar <[email protected]>
iio: adc: mt6323-auxadc: add mt6323 PMIC AUXADC driver
The mt6323 AUXADC is a 15-bit ADC used for system monitoring. This driver provides support for reading various channels including battery and charger voltages, battery and chip temperature, current sensing and accessory detection.
[ ... ]
Quoted 5 lines
drivers/iio/adc/mt6323-auxadc.c new file +0
-0
[ ... ]
drivers/iio/adc/mt6323-auxadc.c line 57
Quoted 5 lines
drivers/iio/adc/mt6323-auxadc.c new file +5
-0+#define AUXADC_DEFAULT_OSR 3 + +#define MTK_PMIC_IIO_CHAN (_name, _chan, _addr) \ +{ \ + .type = IIO_VOLTAGE, \
[Severity: Medium]
Does hardcoding IIO_VOLTAGE here break the IIO ABI for temperature and current channels?
It looks like bat_temp, chip_temp, and isense will be exported as in_voltage_*_raw instead of IIO_TEMP and IIO_CURRENT.
Quoted 2 lines
drivers/iio/adc/mt6323-auxadc.c new file +2
-0+ .indexed = 1, \ + .channel = _chan, \
[ ... ]
drivers/iio/adc/mt6323-auxadc.c line 123
Quoted 11 lines
drivers/iio/adc/mt6323-auxadc.c new file +11
-0+static int mt6323_auxadc_request (struct mt6323_auxadc *auxadc, +unsigned long channel) +{ +struct regmap *map = auxadc->regmap; +int ret; + + ret =regmap_set_bits (map,MT6323_AUXADC_CON11 ,AUXADC_CON11_VBUF_EN ); +if (ret) +return ret; + +return regmap_set_bits (map,MT6323_AUXADC_CON22 ,BIT (channel));
[Severity: High]
Does BIT(channel) request the correct physical hardware channel here?
The channel parameter receives chan->channel, which is a logical sequential index (e.g., MT6323_AUXADC_BATON2 = 0), but the hardware request register appears to expect bits corresponding to the physical ADC channels. For instance, setting BIT(0) for BATON2 would request ADC0 from the hardware, but the driver will later poll the ADC6 data register.
[Severity: Medium]
If regmap_set_bits() fails to set MT6323_AUXADC_CON22, does this leave the AUXADC voltage buffer (VBUF) permanently enabled?
Since the caller aborts on error without calling mt6323_auxadc_release(), the AUXADC_CON11_VBUF_EN bit is never cleared.
drivers/iio/adc/mt6323-auxadc.c line 134
Quoted 11 lines
drivers/iio/adc/mt6323-auxadc.c new file +11
-0+} + +static int mt6323_auxadc_release (struct mt6323_auxadc *auxadc, +unsigned long channel) +{ +struct regmap *map = auxadc->regmap; +int ret; + + ret =regmap_clear_bits (map,MT6323_AUXADC_CON22 ,BIT (channel)); +if (ret) +return ret;
[Severity: Medium]
If clearing MT6323_AUXADC_CON22 fails here, does it skip disabling the voltage buffer?
Returning early would leave AUXADC_CON11_VBUF_EN enabled.
Quoted 3 lines
drivers/iio/adc/mt6323-auxadc.c new file +3
-0+ +return regmap_clear_bits (map,MT6323_AUXADC_CON11 ,AUXADC_CON11_VBUF_EN ); +}
[ ... ]
drivers/iio/adc/mt6323-auxadc.c line 261
Quoted 9 lines
drivers/iio/adc/mt6323-auxadc.c new file +9
-0+static int mt6323_auxadc_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct mt6323_auxadc *auxadc; +struct regmap *regmap; +struct iio_dev *iio; +int ret; + + regmap =dev_get_regmap (dev->parent->parent,NULL );
[Severity: High]
Can this cause a null pointer dereference if the driver is probed directly from a device tree node without an MFD parent?
Because the driver defines an of_match_table, it could be instantiated where dev->parent is null. Even if dev->parent is valid but dev->parent->parent is null, passing null to dev_get_regmap() will cause a kernel panic when it attempts to lock devres.
Quoted 3 lines
drivers/iio/adc/mt6323-auxadc.c new file +3
-0+if (!regmap) +return dev_err_probe (dev, -ENODEV ,"failed to get regmap\n" ); +
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v2 2/4] iio: adc: mt6323-auxadc: add mt6323 PMIC AUXADC driver
In reply to Roman VivcharQuoted 6 lines · On Tue, Jun 09, 2026 at 04:31:59PM +0300, Roman Vivchar via B4 Relay wrote:
The mt6323 AUXADC is a 15-bit ADC used for system monitoring. This driver provides support for reading various channels including battery and charger voltages, battery and chip temperature, current sensing and accessory detection.
Add a driver for the AUXADC found in the MediaTek mt6323 PMIC.
A few nit-picks, most important from which is the scoped_guard() versus guard()() use.
...
Quoted 7 lines
drivers/iio/adc/mt6323-auxadc.c new file +7
-0+static int mt6323_auxadc_prepare_channel (struct mt6323_auxadc *auxadc) +{ +struct regmap *map = auxadc->regmap; +u32 val; +int ret; + + ret =regmap_read (map,MT6323_AUXADC_CON19 , &val);
drivers/iio/adc/mt6323-auxadc.c line 105
Quoted 10 lines
drivers/iio/adc/mt6323-auxadc.c new file +9
-0+if (ret) +return ret; + +/* The ADC is idle. */ +if (!(val &AUXADC_CON19_DECI_GDLY_MASK )) +return 0 ; + ret =regmap_read_poll_timeout (map,MT6323_AUXADC_ADC19 , val, + !(val &AUXADC_ADC19_BUSY_MASK ), +10 ,500 );
It's better to split on logical boundaries:
ret = regmap_read_poll_timeout(map, MT6323_AUXADC_ADC19, val, !(val & AUXADC_ADC19_BUSY_MASK), 10, 500);
Quoted 6 lines
drivers/iio/adc/mt6323-auxadc.c new file +6
-0+if (ret) +return ret; + +return regmap_clear_bits (map,MT6323_AUXADC_CON19 , +AUXADC_CON19_DECI_GDLY_MASK ); +}
...
drivers/iio/adc/mt6323-auxadc.c line 147
Quoted 9 lines
drivers/iio/adc/mt6323-auxadc.c new file +9
-0+static int mt6323_auxadc_read (struct mt6323_auxadc *auxadc, +const struct iio_chan_spec *chan,int *out) +{ +struct regmap *map = auxadc->regmap; +u32 val; +int ret; + + ret =regmap_read_poll_timeout (map, chan->address, val, (val &AUXADC_READY_MASK ), +1 *USEC_PER_MSEC ,100 *USEC_PER_MSEC );
Perhaps
ret = regmap_read_poll_timeout(map, chan->address, val, (val & AUXADC_READY_MASK), 1 * USEC_PER_MSEC, 100 * USEC_PER_MSEC);
(see above why).
Quoted 7 lines
drivers/iio/adc/mt6323-auxadc.c new file +7
-0+if (ret) +return ret; + + *out =FIELD_GET (AUXADC_DATA_MASK , val); + +return 0 ; +}
...
drivers/iio/adc/mt6323-auxadc.c line 177
Quoted 2 lines
drivers/iio/adc/mt6323-auxadc.c new file +2
-0+case IIO_CHAN_INFO_RAW : + scoped_guard(mutex, &auxadc->lock) {
I'm wondering why we haven't moved to guard()() here
case IIO_CHAN_INFO_RAW: {
guard(mutex)(&auxadc->lock);Quoted 21 lines
drivers/iio/adc/mt6323-auxadc.c new file +21
-0+ ret =mt6323_auxadc_prepare_channel (auxadc); +if (ret) +return ret; + + ret =mt6323_auxadc_request (auxadc, chan->channel); +if (ret) +return ret; + +/* Hardware limitation: the AUXADC needs a delay to become ready. */ +fsleep (300 ); + + ret =mt6323_auxadc_read (auxadc, chan, val); + +if (mt6323_auxadc_release (auxadc, chan->channel)) +dev_err (&indio_dev->dev, +"failed to release channel %d\n" , chan->channel); + +if (ret) +return ret; + } +return IIO_VAL_INT ;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Roman Vivchar
maintainerRe: [PATCH v2 2/4] iio: adc: mt6323-auxadc: add mt6323 PMIC AUXADC driver
Hi Andy,
Quoted 2 lines · Andy Shevchenko
On Tue, Jun 09, 2026 at 04:31:59PM +0300, Roman Vivchar via B4 Relay wrote:
...
Quoted 11 lines
drivers/iio/adc/mt6323-auxadc.c line 105
Quoted 4 lines
drivers/iio/adc/mt6323-auxadc.c new file +3
-0+ ret =regmap_read_poll_timeout (map,MT6323_AUXADC_ADC19 , val, + !(val &AUXADC_ADC19_BUSY_MASK ), +10 ,500 );It's better to split on logical boundaries:
ret = regmap_read_poll_timeout(map, MT6323_AUXADC_ADC19, val, !(val & AUXADC_ADC19_BUSY_MASK), 10, 500);
Agreed.
...
Quoted 5 lines
drivers/iio/adc/mt6323-auxadc.c line 177
Quoted 3 lines
drivers/iio/adc/mt6323-auxadc.c new file +2
-0+case IIO_CHAN_INFO_RAW : + scoped_guard(mutex, &auxadc->lock) {I'm wondering why we haven't moved to guard()() here
The compiler would complain about 'cannot jump from switch statement' due to default case.
Best regards,
Roman
Re: [PATCH v2 2/4] iio: adc: mt6323-auxadc: add mt6323 PMIC AUXADC driver
Quoted 2 lines · Roman Vivchar
Quoted 1 line · Andy Shevchenko
On Tue, Jun 09, 2026 at 04:31:59PM +0300, Roman Vivchar via B4 Relay wrote:
...
Quoted 7 lines
Quoted 4 lines
drivers/iio/adc/mt6323-auxadc.c line 177
Quoted 2 lines
drivers/iio/adc/mt6323-auxadc.c new file +2
-0+case IIO_CHAN_INFO_RAW : + scoped_guard(mutex, &auxadc->lock) {I'm wondering why we haven't moved to guard()() here
The compiler would complain about 'cannot jump from switch statement' due to default case.
I am not sure I follow. See the examples in the existing drivers. They are warning clean in that sense.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH v2 2/4] iio: adc: mt6323-auxadc: add mt6323 PMIC AUXADC driver
Quoted 6 lines · On Tue, 9 Jun 2026 21:33:12 +0200 Andy Shevchenko…
Quoted 2 lines · Roman Vivchar
Quoted 1 line · Andy Shevchenko
On Tue, Jun 09, 2026 at 04:31:59PM +0300, Roman Vivchar via B4 Relay wrote:
...
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
drivers/iio/adc/mt6323-auxadc.c line 177
Quoted 2 lines
drivers/iio/adc/mt6323-auxadc.c new file +2
-0+case IIO_CHAN_INFO_RAW : + scoped_guard(mutex, &auxadc->lock) {I'm wondering why we haven't moved to guard()() here
The compiler would complain about 'cannot jump from switch statement' due to default case.
See the brackets Andy suggested. That error is what you get without specifically defining the scope.
Quoted 4 lines
I am not sure I follow. See the examples in the existing drivers. They are warning clean in that sense.
Jonathan Cameron
maintainerRe: [PATCH v2 2/4] iio: adc: mt6323-auxadc: add mt6323 PMIC AUXADC driver
In reply to Roman VivcharQuoted 11 lines · On Tue, 09 Jun 2026 16:31:59 +0300 Roman Vivchar via B4 Relay…
From: Roman Vivchar <[email protected]>
The mt6323 AUXADC is a 15-bit ADC used for system monitoring. This driver provides support for reading various channels including battery and charger voltages, battery and chip temperature, current sensing and accessory detection.
Add a driver for the AUXADC found in the MediaTek mt6323 PMIC.
Make sure to take a look at:
https://sashiko.dev/#/patchset/20260609-mt6323-adc-v2-0-aa93a22309f9%40protonmail.com
A few minor other comments inline.
Quoted 12 lines
drivers/iio/adc/mt6323-auxadc.c new file +6
-0+ +#define MTK_PMIC_IIO_CHAN (_name, _chan, _addr) \ +{ \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = _chan, \
drivers/iio/adc/mt6323-auxadc.c line 69
Quoted 10 lines
drivers/iio/adc/mt6323-auxadc.c new file +10
-0+ .address = _addr, \ + .datasheet_name = __stringify(_name), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ +} + +static const struct iio_chan_spec mt6323_auxadc_channels[] = { +MTK_PMIC_IIO_CHAN (baton2,MT6323_AUXADC_BATON2 ,MT6323_AUXADC_ADC6 ), +MTK_PMIC_IIO_CHAN (ch6,MT6323_AUXADC_CH6 ,MT6323_AUXADC_ADC11 ), +MTK_PMIC_IIO_CHAN (bat_temp,MT6323_AUXADC_BAT_TEMP ,MT6323_AUXADC_ADC5 ),
Reasonable query from Sashiko on why temperature channels are presented as voltages. If for some reason that is the right choice, then maybe a comment here.
Quoted 7 lines
drivers/iio/adc/mt6323-auxadc.c new file +7
-0+MTK_PMIC_IIO_CHAN (chip_temp,MT6323_AUXADC_CHIP_TEMP ,MT6323_AUXADC_ADC4 ), +MTK_PMIC_IIO_CHAN (vcdt,MT6323_AUXADC_VCDT ,MT6323_AUXADC_ADC2 ), +MTK_PMIC_IIO_CHAN (baton1,MT6323_AUXADC_BATON1 ,MT6323_AUXADC_ADC3 ), +MTK_PMIC_IIO_CHAN (isense,MT6323_AUXADC_ISENSE ,MT6323_AUXADC_ADC1 ), +MTK_PMIC_IIO_CHAN (batsns,MT6323_AUXADC_BATSNS ,MT6323_AUXADC_ADC0 ), + MTK_PMIC_IIO_CHAN(accdet, MT6323_AUXADC_ACCDET, MT6323_AUXADC_ADC7), +};
drivers/iio/adc/mt6323-auxadc.c line 86
Quoted 10 lines
drivers/iio/adc/mt6323-auxadc.c new file +10
-0+ +/* +* The MediaTek MT6323 (as well as a lot of other PMICs) has the following hierarchy: +* PMIC AUXADC <- PMIC MFD <- SoC PWRAP (wrapper for PWRAP FSM) +* +* Therefore, PWRAP regmap should be obtained using dev->parent->parent. +*/ +struct mt6323_auxadc { +struct regmap *regmap; +struct mutex lock;
Locks should always have a comment on what data they are protecting. I think this one is about protecting the state of a device during a channel read by serializing those reads.
Quoted 4 lines
drivers/iio/adc/mt6323-auxadc.c new file +3
-0+}; + +static int mt6323_auxadc_request(struct mt6323_auxadc *auxadc,
drivers/iio/adc/mt6323-auxadc.c line 123
Quoted 10 lines
drivers/iio/adc/mt6323-auxadc.c new file +10
-0+ unsigned long channel) +{ +struct regmap *map = auxadc->regmap; +int ret; + + ret =regmap_set_bits (map,MT6323_AUXADC_CON11 ,AUXADC_CON11_VBUF_EN ); +if (ret) +return ret; + +return regmap_set_bits (map,MT6323_AUXADC_CON22 ,BIT (channel));
I'm not sure whether the sashiko question on this is valid or not. Make sure to take a look.
https://sashiko.dev/#/patchset/20260609-mt6323-adc-v2-0-aa93a22309f9%40protonmail.com
You may have carefully selected the numbering so the channel numbering matches the bits in this register. If so, it is probably worth a comment in the header to provide a cross reference. No idea if Sashiko will notice that, but at least humans should!
Quoted 15 lines
drivers/iio/adc/mt6323-auxadc.c new file +14
-0+} + + +static int mt6323_auxadc_read_raw (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan, +int *val,int *val2,long mask) +{ +struct mt6323_auxadc *auxadc =iio_priv (indio_dev); +int ret, mult; + +switch (mask) { +case IIO_CHAN_INFO_SCALE : +if (chan->channel ==MT6323_AUXADC_ISENSE || + chan->channel ==MT6323_AUXADC_BATSNS )
drivers/iio/adc/mt6323-auxadc.c line 176
Quoted 10 lines
drivers/iio/adc/mt6323-auxadc.c new file +10
-0+ mult =4 ; + else + mult =1 ; + +/* 1800mV full range with 15-bit resolution. */ + *val = mult *1800 ; + *val2 =15 ; + +return IIO_VAL_FRACTIONAL_LOG2 ; +case IIO_CHAN_INFO_RAW :
What Andy suggested here is the preferred path in IIO at least. Mainly because it reduced indent without hurting readability. Just be careful to define the scope with { }
Quoted 26 lines
drivers/iio/adc/mt6323-auxadc.c new file +26
-0+ scoped_guard(mutex, &auxadc->lock) { + ret =mt6323_auxadc_prepare_channel (auxadc); +if (ret) +return ret; + + ret =mt6323_auxadc_request (auxadc, chan->channel); +if (ret) +return ret; + +/* Hardware limitation: the AUXADC needs a delay to become ready. */ +fsleep (300 ); + + ret =mt6323_auxadc_read (auxadc, chan, val); + +if (mt6323_auxadc_release (auxadc, chan->channel)) +dev_err (&indio_dev->dev, +"failed to release channel %d\n" , chan->channel); + +if (ret) +return ret; + } +return IIO_VAL_INT ; +default : +return -EINVAL ; + } +}
Roman Vivchar
maintainerRe: [PATCH v2 2/4] iio: adc: mt6323-auxadc: add mt6323 PMIC AUXADC driver
Hi Jonathan,
Quoted 2 lines · Jonathan Cameron
On Tue, 09 Jun 2026 16:31:59 +0300
Roman Vivchar via B4 Relay <[email protected]> wrote:
...
Quoted 11 lines
Quoted 11 lines
drivers/iio/adc/mt6323-auxadc.c new file +11
-0+ +#define MTK_PMIC_IIO_CHAN (_name, _chan, _addr) \ +{ \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = _chan, \ + .address = _addr, \ + .datasheet_name = __stringify(_name), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ +}
Quoted 8 lines
drivers/iio/adc/mt6323-auxadc.c line 69
Quoted 5 lines
drivers/iio/adc/mt6323-auxadc.c new file +5
-0+ +static const struct iio_chan_spec mt6323_auxadc_channels[] = { +MTK_PMIC_IIO_CHAN (baton2,MT6323_AUXADC_BATON2 ,MT6323_AUXADC_ADC6 ), +MTK_PMIC_IIO_CHAN (ch6,MT6323_AUXADC_CH6 ,MT6323_AUXADC_ADC11 ), +MTK_PMIC_IIO_CHAN (bat_temp,MT6323_AUXADC_BAT_TEMP ,MT6323_AUXADC_ADC5 ),Reasonable query from Sashiko on why temperature channels are presented as voltages. If for some reason that is the right choice, then maybe a comment here.
mt6323 ADC always returns voltage. The thermal driver (which was in the previous series and will be sent later) is required to map these to the actual temperature. Ack.
...
Quoted 4 lines
Quoted 4 lines
+/*
+ * The MediaTek MT6323 (as well as a lot of other PMICs) has the following hierarchy:
+ * PMIC AUXADC <- PMIC MFD <- SoC PWRAP (wrapper for PWRAP FSM)
+ *
Quoted 8 lines
drivers/iio/adc/mt6323-auxadc.c line 86
Quoted 5 lines
+ * Therefore, PWRAP regmap should be obtained using
dev->parent->parent.
+ */drivers/iio/adc/mt6323-auxadc.c new file +3
-0+struct mt6323_auxadc { +struct regmap *regmap; +struct mutex lock;Locks should always have a comment on what data they are protecting. I think this one is about protecting the state of a device during a channel read by serializing those reads.
Nuno said kerneldoc looks unnecessary on v1 [1]. How the comment should look?
...
Quoted 15 lines
drivers/iio/adc/mt6323-auxadc.c line 123
Quoted 11 lines
drivers/iio/adc/mt6323-auxadc.c new file +11
-0+static int mt6323_auxadc_request (struct mt6323_auxadc *auxadc, +unsigned long channel) +{ +struct regmap *map = auxadc->regmap; +int ret; + + ret =regmap_set_bits (map,MT6323_AUXADC_CON11 ,AUXADC_CON11_VBUF_EN ); +if (ret) +return ret; + +return regmap_set_bits (map,MT6323_AUXADC_CON22 ,BIT (channel));I'm not sure whether the sashiko question on this is valid or not. Make sure to take a look.
Quoted 5 lines
https://sashiko.dev/#/patchset/20260609-mt6323-adc-v2-0-aa93a22309f9%40protonmail.com
You may have carefully selected the numbering so the channel numbering matches the bits in this register. If so, it is probably worth a comment in the header to provide a cross reference. No idea if Sashiko will notice that, but at least humans should!
The hardware is pretty weird, but dt-bindings have correct numbers. I have double checked with the vendor driver and the logic is the same.
'If regmap_set_bits() fails to set MT6323_AUXADC_CON22, does this leave the AUXADC voltage buffer (VBUF) permanently enabled?' - if this happens, then there's something really wrong with PWRAP and disabling VBUF may not be possible. Same about the 'mt6323_auxadc_release' comment.
...
Quoted 5 lines
drivers/iio/adc/mt6323-auxadc.c line 176
Quoted 1 line
drivers/iio/adc/mt6323-auxadc.c new file +1
-0+case IIO_CHAN_INFO_RAW :What Andy suggested here is the preferred path in IIO at least. Mainly because it reduced indent without hurting readability. Just be careful to define the scope with { }
Ack.
Quoted 20 lines
Quoted 20 lines
drivers/iio/adc/mt6323-auxadc.c new file +18
-0+ scoped_guard(mutex, &auxadc->lock) { + ret =mt6323_auxadc_prepare_channel (auxadc); +if (ret) +return ret; + + ret =mt6323_auxadc_request (auxadc, chan->channel); +if (ret) +return ret; + +/* Hardware limitation: the AUXADC needs a delay to become ready. */ +fsleep (300 ); + + ret =mt6323_auxadc_read (auxadc, chan, val); + +if (mt6323_auxadc_release (auxadc, chan->channel)) +dev_err (&indio_dev->dev, +"failed to release channel %d\n" , chan->channel); +
Quoted 10 lines
drivers/iio/adc/mt6323-auxadc.c line 202
Quoted 8 lines
drivers/iio/adc/mt6323-auxadc.c new file +8
-0+if (ret) +return ret; + } +return IIO_VAL_INT ; +default : +return -EINVAL ; + } +}
After these changes, should I keep or drop Andy's Reviewed-by?
[1]: https://lore.kernel.org/linux-iio/[email protected]/
Best regards,
Roman
Re: [PATCH v2 2/4] iio: adc: mt6323-auxadc: add mt6323 PMIC AUXADC driver
Quoted 3 lines · Roman Vivchar
Quoted 2 lines · Jonathan Cameron
On Tue, 09 Jun 2026 16:31:59 +0300
Roman Vivchar via B4 Relay <[email protected]> wrote:
...
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
+/*
+ * The MediaTek MT6323 (as well as a lot of other PMICs) has the following hierarchy:
+ * PMIC AUXADC <- PMIC MFD <- SoC PWRAP (wrapper for PWRAP FSM)
+ *Quoted 8 lines
drivers/iio/adc/mt6323-auxadc.c line 86
Quoted 5 lines
+ * Therefore, PWRAP regmap should be obtained using
dev->parent->parent.
+ */drivers/iio/adc/mt6323-auxadc.c new file +3
-0+struct mt6323_auxadc { +struct regmap *regmap; +struct mutex lock;Locks should always have a comment on what data they are protecting. I think this one is about protecting the state of a device during a channel read by serializing those reads.
Quoted 2 lines
Nuno said kerneldoc looks unnecessary on v1 [1]. How the comment should look?
The comment near to the member:
/* Why this lock? */ struct mutex lock;
...
Quoted 1 line
After these changes, should I keep or drop Andy's Reviewed-by?
Keep it, the above mentioned changes does not affect on that.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Roman Vivchar
maintainerPATCH v2 3/4 mfd: mt6397-core: add mt6323 AUXADC support
In reply to Roman VivcharThe mt6323 PMIC includes an AUXADC. Register the AUXADC in the mt6323 devices array to allow the corresponding driver to probe using compatible string.
--- drivers/mfd/mt6397-core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mfd/mt6397-core.c +3 -0
@@ -125,6 +125,9 @@ static const struct resource mt6323_pwrc_resources[] = {static const struct mfd_cell mt6323_devs[] = { { + .name ="mt6323-auxadc" , + .of_compatible ="mediatek,mt6323-auxadc" , + }, { .name ="mt6323-rtc" , .num_resources =ARRAY_SIZE (mt6323_rtc_resources), .resources = mt6323_rtc_resources,
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v2 3/4] mfd: mt6397-core: add mt6323 AUXADC support
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Setting the clock power down bit disables the AUXADC clock instead of enabling it. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Setting the clock power down bit disables the AUXADC clock instead of enabling it. --
commit bab9fefa6ba4c56ff9360f203a97d192c15f6cd1
Author: Roman Vivchar <[email protected]>
mfd: mt6397-core: add mt6323 AUXADC support
The mt6323 PMIC includes an AUXADC. Register the AUXADC in the mt6323 devices array to allow the corresponding driver to probe using compatible string.
drivers/mfd/mt6397-core.c static const struct resource mt6323_pwrc_resources[] = { · line 129
Quoted 10 lines
drivers/mfd/mt6397-core.c +2
-0@@ -125,6 +125,9 @@ static const struct resource mt6323_pwrc_resources[] = {static const struct mfd_cell mt6323_devs[] = { { + .name ="mt6323-auxadc" , + .of_compatible ="mediatek,mt6323-auxadc" ,
[Severity: High]
Does enabling this device expose an issue in the mt6323-auxadc driver's clock initialization?
Looking at mt6323_auxadc_init() in drivers/iio/adc/mt6323-auxadc.c, it writes a 1 to the power down register bit:
ret = regmap_set_bits(map, MT6323_TOP_CKPDN2, AUXADC_TOP_CKPDN2_CTL_CK); if (ret) return ret;
Since CKPDN registers in MediaTek PMICs are Clock Power Down registers, setting a bit to 1 explicitly disables the clock, while clearing it to 0 powers it up.
Because the AUXADC clock is explicitly disabled here and never turned back on, will ADC read requests in mt6323_auxadc_read_raw() fail or time out waiting for AUXADC_READY_MASK?
If the entire driver is functionally broken due to this, could it subsequently break dependent features like battery management and thermal protection?
Quoted 4 lines
drivers/mfd/mt6397-core.c +1
-0+ }, { .name = "mt6323-rtc", .num_resources = ARRAY_SIZE(mt6323_rtc_resources), .resources = mt6323_rtc_resources,
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Roman Vivchar
maintainerPATCH v2 4/4 ARM: dts: mediatek: mt6323: add AUXADC support
In reply to Roman VivcharAdd the devicetree node for the mt6323 AUXADC.
--- arch/arm/boot/dts/mediatek/mt6323.dtsi | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm/boot/dts/mediatek/mt6323.dtsi +5 -0
@@ -14,6 +14,11 @@ pmic: mt6323 { interrupt-controller; #interrupt-cells = <2>; + mt6323_adc: adc { + compatible = "mediatek,mt6323-auxadc"; + #io-channel-cells = <1>; + }; + mt6323_leds: leds { compatible = "mediatek,mt6323-led"; #address-cells = <1>;
Signature · 1 line
2.54.0