iio: adc: add Nuvoton NCT7201 ADC driver
Subsystems (3)
Eason Yang
maintainerv9 cover iio: adc: add Nuvoton NCT7201 ADC driver
Change since version 9:
- Fix comments
- Change vin_mask and mask from CPU-endian to little-endian
- Fix access to restricted __le16
Change since version 8:
- dev_err_probe(), move the definition from device.h to dev_printk.h
- Use USEC_PER_MSEC rather than the hard coded value of 1000
- Use one dev for both regmap and regmap16
Change since version 7:
- Fix comments
- Derive dev from the respective regmap
- Generate the mask from the number of voltage input channels
Change since version 6:
- Fix comments
- Add use_single_read in regmap_config
- Remove unused definitions
- Do not shadow the return code by -EIO and let regmap API caller to decide
- Use simple English in all error messages
- Use a local variable for the struct device pointers. This increases code readability with shortened lines.
- Use fsleep instead of mdelay
- Use 16 bits type __le16 instead of u8 data[2]
Change since version 5:
- Fix comments
- Add NUVOTON NCT7201 IIO DRIVER section in MAINTAINERS
- Add vdd-supply and vref-supply to the DT example
- Remove mutex since the regmap should already have an internal lock
- Remove redundant assigning values
- Check errors on regmap_write
Change since version 4:
- Fix comments
- Add interrupts and reset-gpios to the DT example
- Use the FIELD_PREP and FIELD_GET
- Add use_single_write in regmap_config
- Use regmap_access_table
Change since version 3:
- Fix comments
- Don't put nct720"x" in the name, just call it nct7201
- Remove differential inputs until conversions are finished
- Add NCT7201_ prefix in all macros and avoid the tables
- Correct event threshold values in raw units
- Add with and without interrupt callback function to have the event config part and one that doesn't
- Remove print an error message if regmap_wirte failed case
Change since version 2:
- Remvoe read-vin-data-size property, default use read word vin data
- Use regmap instead of i2c smbus API
- IIO should be IIO_CHAN_INFO_RAW and _SCALE not _PROCESSED
- Use dev_xxx_probe in probe function and dev_xxx in other functions
- Use devm_iio_device_register replace of iio_device_register
- Use guard(mutex) replace of mutex_lock
- Use get_unaligned_le16 conversion API
Changes since version 1:
- Add new property in iio:adc binding document
- Add new driver for Nuvoton NCT720x driver
Eason Yang (2):
dt-bindings: iio: adc: add NCT7201 ADCs
iio: adc: add support for Nuvoton NCT7201
.../bindings/iio/adc/nuvoton,nct7201.yaml | 70 +++ MAINTAINERS | 7 + drivers/iio/adc/Kconfig | 11 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/nct7201.c | 462 ++++++++++++++++++ 5 files changed, 551 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/nuvoton,nct7201.yaml create mode 100644 drivers/iio/adc/nct7201.c
Signature · 1 line
2.34.1
Eason Yang
maintainerPATCH v9 1/2 dt-bindings: iio: adc: add NCT7201 ADCs
Add a binding specification for the Nuvoton NCT7201/NCT7202 up to 12-bit ADCs with I2C interface.
--- .../bindings/iio/adc/nuvoton,nct7201.yaml | 70 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 76 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/nuvoton,nct7201.yaml
Documentation/devicetree/bindings/iio/adc/nuvoton,nct7201.yaml new file +70 -0
@@ -0,0 +1,70 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/nuvoton,nct7201.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton nct7201 and similar ADCs + +maintainers: + - Eason Yang <[email protected]> + +description: | + The NCT7201/NCT7202 is a Nuvoton Hardware Monitor IC, contains up to 12 + voltage monitoring channels, with SMBus interface, and up to 4 sets SMBus + address selection by ADDR connection. It also provides ALERT# signal for + event notification and reset input RSTIN# to recover it from a fault + condition. + + NCT7201 contains 8 voltage monitor inputs (VIN1~VIN8). + NCT7202 contains 12 voltage monitor inputs (VIN1~VIN12). + +properties: + compatible: + enum: + - nuvoton,nct7201 + - nuvoton,nct7202 + + reg: + maxItems: 1 + + vdd-supply: + description: + A 3.3V to supply that powers the chip. + + vref-supply: + description: + The regulator supply for the ADC reference voltage. + + interrupts: + maxItems: 1 + + reset-gpios: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + #include <dt-bindings/interrupt-controller/irq.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + adc@1d { + compatible = "nuvoton,nct7202"; + reg = <0x1d>; + vdd-supply = <&vdd>; + vref-supply = <&vref>; + interrupt-parent = <&gpio3>; + interrupts = <30 IRQ_TYPE_LEVEL_LOW>; + reset-gpios = <&gpio3 28 GPIO_ACTIVE_LOW>; + }; + }; +...
MAINTAINERS +6 -0
@@ -17373,6 +17373,12 @@ F: drivers/nubus/ F: include/linux/nubus.h F: include/uapi/linux/nubus.h +NUVOTON NCT7201 IIO DRIVER +M: Eason Yang <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/iio/adc/nuvoton,nct7201.yaml + NVIDIA (rivafb and nvidiafb) FRAMEBUFFER DRIVER M: Antonino Daplas <[email protected]> L: [email protected]
Signature · 1 line
2.34.1
Eason Yang
maintainerPATCH v9 2/2 iio: adc: add support for Nuvoton NCT7201
In reply to Eason YangAdd Nuvoton NCT7201/NCT7202 system voltage monitor 12-bit ADC driver
NCT7201/NCT7202 supports up to 12 analog voltage monitor inputs and up to 4 SMBus addresses by ADDR pin. Meanwhile, ALERT# hardware event pins for independent alarm signals, and all the threshold values could be set for system protection without any timing delay. It also supports reset input RSTIN# to recover system from a fault condition.
Currently, only single-edge mode conversion and threshold events are supported.
--- MAINTAINERS | 1 + drivers/iio/adc/Kconfig | 11 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/nct7201.c | 462 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 475 insertions(+) create mode 100644 drivers/iio/adc/nct7201.c
MAINTAINERS +1 -0
@@ -17378,6 +17378,7 @@ M: Eason Yang <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/iio/adc/nuvoton,nct7201.yaml +F: drivers/iio/adc/nct7201.c NVIDIA (rivafb and nvidiafb) FRAMEBUFFER DRIVER M: Antonino Daplas <[email protected]>
drivers/iio/adc/Kconfig +11 -0
@@ -1092,6 +1092,17 @@ config NAU7802 To compile this driver as a module, choose M here: the module will be called nau7802. +config NCT7201 + tristate "Nuvoton Instruments NCT7201 and NCT7202 Power Monitor" + depends on I2C + select REGMAP_I2C + help + If you say yes here you get support for the Nuvoton NCT7201 and + NCT7202 Voltage Monitor. + + This driver can also be built as a module. If so, the module + will be called nct7201. + config NPCM_ADC tristate "Nuvoton NPCM ADC driver" depends on ARCH_NPCM || COMPILE_TEST
drivers/iio/adc/Makefile +1 -0
@@ -97,6 +97,7 @@ obj-$(CONFIG_MESON_SARADC) += meson_saradc.o obj-$(CONFIG_MP2629_ADC) += mp2629_adc.o obj-$(CONFIG_MXS_LRADC_ADC) += mxs-lradc-adc.o obj-$(CONFIG_NAU7802) += nau7802.o +obj-$(CONFIG_NCT7201) += nct7201.o obj-$(CONFIG_NPCM_ADC) += npcm_adc.o obj-$(CONFIG_PAC1921) += pac1921.o obj-$(CONFIG_PAC1934) += pac1934.o
drivers/iio/adc/nct7201.c new file +462 -0
462 lines not on this page · raw message
Signature · 1 line
2.34.1
Jonathan Cameron
maintainerRe: [PATCH v9 2/2] iio: adc: add support for Nuvoton NCT7201
Quoted 10 lines · On Mon, 5 May 2025 17:26:00 +0800 Eason Yang <[email protected]> wrote:
Add Nuvoton NCT7201/NCT7202 system voltage monitor 12-bit ADC driver
NCT7201/NCT7202 supports up to 12 analog voltage monitor inputs and up to 4 SMBus addresses by ADDR pin. Meanwhile, ALERT# hardware event pins for independent alarm signals, and all the threshold values could be set for system protection without any timing delay. It also supports reset input RSTIN# to recover system from a fault condition.
Currently, only single-edge mode conversion and threshold events are supported.
As below. Setup of threshold events seems to be here, but not the interrupt handler that would call iio_push_event() to actually notify userspace they occurred. Is the intent they are getting wired to something else?
Even if that is the intent we normally cross wire them to the host as well so as to be able to find out what happened. The use in here of client->irq implies such wiring but no sign of it being handled.
Jonathan
Quoted 65 lines
Signed-off-by Eason Yang <[email protected]>--- MAINTAINERS | 1 + drivers/iio/adc/Kconfig | 11 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/nct7201.c | 462 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 475 insertions(+) create mode 100644 drivers/iio/adc/nct7201.cMAINTAINERS +1
-0@@ -17378,6 +17378,7 @@ M: Eason Yang <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/iio/adc/nuvoton,nct7201.yaml +F: drivers/iio/adc/nct7201.c NVIDIA (rivafb and nvidiafb) FRAMEBUFFER DRIVER M: Antonino Daplas <[email protected]>drivers/iio/adc/Kconfig +11
-0@@ -1092,6 +1092,17 @@ config NAU7802 To compile this driver as a module, choose M here: the module will be called nau7802. +config NCT7201 + tristate "Nuvoton Instruments NCT7201 and NCT7202 Power Monitor" + depends on I2C + select REGMAP_I2C + help + If you say yes here you get support for the Nuvoton NCT7201 and + NCT7202 Voltage Monitor. + + This driver can also be built as a module. If so, the module + will be called nct7201. + config NPCM_ADC tristate "Nuvoton NPCM ADC driver" depends on ARCH_NPCM || COMPILE_TESTdrivers/iio/adc/Makefile +1
-0@@ -97,6 +97,7 @@ obj-$(CONFIG_MESON_SARADC) += meson_saradc.o obj-$(CONFIG_MP2629_ADC) += mp2629_adc.o obj-$(CONFIG_MXS_LRADC_ADC) += mxs-lradc-adc.o obj-$(CONFIG_NAU7802) += nau7802.o +obj-$(CONFIG_NCT7201) += nct7201.o obj-$(CONFIG_NPCM_ADC) += npcm_adc.o obj-$(CONFIG_PAC1921) += pac1921.o obj-$(CONFIG_PAC1934) += pac1934.odrivers/iio/adc/nct7201.c new file +2
-0@@ -0,0 +1,462 @@ +static const struct iio_event_spec nct7201_events[] = { + {
drivers/iio/adc/nct7201.c line 143
Quoted 10 lines
drivers/iio/adc/nct7201.c new file +10
-0+ .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_RISING, + .mask_separate = BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_ENABLE), + }, { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_FALLING, + .mask_separate =BIT (IIO_EV_INFO_VALUE ) | + BIT(IIO_EV_INFO_ENABLE), + },
I'd missed this before but you spend lots of time setting up event detectors etc which all looks good, but where are they actually signalled?
The irq handler seems to be missing.
Quoted 7 lines
drivers/iio/adc/nct7201.c new file +6
-0+}; +static int nct7201_init_chip (struct nct7201_chip_info *chip) +{ +struct device *dev =regmap_get_device (chip->regmap); +__le16 data =cpu_to_le16 (GENMASK (chip->num_vin_channels -1 ,0 )); +unsigned int value;
drivers/iio/adc/nct7201.c line 350
Quoted 10 lines
drivers/iio/adc/nct7201.c new file +10
-0+int err; + + err =regmap_write (chip->regmap,NCT7201_REG_CONFIGURATION , +NCT7201_BIT_CONFIGURATION_RESET ); +if (err) +return dev_err_probe (dev, err,"Failed to reset chip\n" ); + +/* +* After about 25 msecs, the device should be ready and then the power-up +* bit will be set to 1. If not, wait for it.
Trivial but you don't "wait for it." That's the right choice here but the comment is misleading.
Quoted 9 lines
drivers/iio/adc/nct7201.c new file +9
-0+*/ +fsleep (25 *USEC_PER_MSEC ); + + err =regmap_read (chip->regmap,NCT7201_REG_BUSY_STATUS , &value); +if (err) +return dev_err_probe (dev, err,"Failed to read busy status\n" ); +if (!(value &NCT7201_BIT_PWR_UP )) +return dev_err_probe (dev, -EIO ,"Failed to power up after reset\n" ); +
Re: [PATCH v9 2/2] iio: adc: add support for Nuvoton NCT7201
In reply to Eason YangQuoted 10 lines · Eason Yang
Add Nuvoton NCT7201/NCT7202 system voltage monitor 12-bit ADC driver
NCT7201/NCT7202 supports up to 12 analog voltage monitor inputs and up to 4 SMBus addresses by ADDR pin. Meanwhile, ALERT# hardware event pins for independent alarm signals, and all the threshold values could be set for system protection without any timing delay. It also supports reset input RSTIN# to recover system from a fault condition.
Currently, only single-edge mode conversion and threshold events are supported.
...
drivers/iio/adc/nct7201.c line 17
Quoted 10 lines
drivers/iio/adc/nct7201.c new file +10
-0+#include <linux/array_size.h> +#include <linux/bitfield.h> +#include <linux/bits.h> +#include <linux/delay.h> +#include <linux/dev_printk.h> +#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/regmap.h>
+ time.h
Quoted 2 lines
drivers/iio/adc/nct7201.c new file +2
-0+#include <linux/types.h> +#include <linux/unaligned.h>
Signature · 2 lines
With Best Regards, Andy Shevchenko