From: Jonathan Cameron <jic23@kernel.org>
To: Eason Yang <j2anfernee@gmail.com>
Cc: lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org,
conor+dt@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
javier.carrasco.cruz@gmail.com, gstols@baylibre.com,
alisadariana@gmail.com, tgamblin@baylibre.com,
olivier.moysan@foss.st.com, antoniu.miclaus@analog.com,
eblanc@baylibre.com, andriy.shevchenko@linux.intel.com,
joao.goncalves@toradex.com, tobias.sperling@softing.com,
marcelo.schmitt@analog.com,
angelogioacchino.delregno@collabora.com,
thomas.bonnefille@bootlin.com, herve.codina@bootlin.com,
chanh@os.amperecomputing.com, KWLIU@nuvoton.com,
yhyang2@nuvoton.com, linux-iio@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 2/2] iio: adc: add support for Nuvoton NCT7201
Date: Fri, 18 Apr 2025 17:13:26 +0100 [thread overview]
Message-ID: <20250418171326.07634113@jic23-huawei> (raw)
In-Reply-To: <20250416081734.563111-3-j2anfernee@gmail.com>
On Wed, 16 Apr 2025 16:17:34 +0800
Eason Yang <j2anfernee@gmail.com> 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.
>
> Signed-off-by: Eason Yang <j2anfernee@gmail.com>
Hi Eason,
A few trivial things from another glance through.
Thanks,
Jonathan
> +
> +static const struct nct7201_adc_model_data nct7201_model_data = {
> + .model_name = "nct7201",
> + .channels = nct7201_channels,
> + .num_channels = ARRAY_SIZE(nct7201_channels),
> + .num_vin_channels = 8,
> +};
> +
> +static const struct nct7201_adc_model_data nct7202_model_data = {
> + .model_name = "nct7202",
> + .channels = nct7202_channels,
> + .num_channels = ARRAY_SIZE(nct7202_channels),
> + .num_vin_channels = 12,
> +};
> +
> +static int nct7201_init_chip(struct nct7201_chip_info *chip)
> +{
> + struct device *dev = chip->dev;
> + __le16 data = cpu_to_le16(NCT7201_REG_CHANNEL_ENABLE_MASK);
Assign this value down near where it is used. That will generally help
readability.
> + unsigned int value;
> + 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.
I'd hyphenate power-up perhaps.
> + */
> + fsleep(25000);
> + 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");
> +
> + /* Enable Channel */
> + if (chip->num_vin_channels <= 8)
> + err = regmap_write(chip->regmap, NCT7201_REG_CHANNEL_ENABLE_1,
> + NCT7201_REG_CHANNEL_ENABLE_MASK);
This is a little odd as I think you are writing an 8 bit register with a 12 bit mask.
Sure it works, but confusing thing to see. If some future 6 channel device comes
along this <= 8 will seem odd too. Maybe generate the mask from teh number
of channels?
> + else
> + err = regmap_bulk_write(chip->regmap, NCT7201_REG_CHANNEL_ENABLE_1,
> + &data, sizeof(data));
> + if (err)
> + return dev_err_probe(dev, err, "Failed to enable channel\n");
> +
> + err = regmap_bulk_read(chip->regmap, NCT7201_REG_CHANNEL_ENABLE_1,
> + &chip->vin_mask, sizeof(chip->vin_mask));
> + if (err)
> + return dev_err_probe(dev, err,
> + "Failed to read channel enable register\n");
> +
> + /* Start monitoring if needed */
> + err = regmap_set_bits(chip->regmap, NCT7201_REG_CONFIGURATION,
> + NCT7201_BIT_CONFIGURATION_START);
> + if (err)
> + return dev_err_probe(dev, err, "Failed to start monitoring\n");
> +
> + return 0;
> +}
next prev parent reply other threads:[~2025-04-18 16:13 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-16 8:17 [PATCH v6 0/2] iio: adc: add Nuvoton NCT7201 ADC driver Eason Yang
2025-04-16 8:17 ` [PATCH v6 1/2] dt-bindings: iio: adc: add NCT7201 ADCs Eason Yang
2025-04-17 6:20 ` Krzysztof Kozlowski
2025-04-16 8:17 ` [PATCH v6 2/2] iio: adc: add support for Nuvoton NCT7201 Eason Yang
2025-04-16 9:34 ` Andy Shevchenko
2025-04-20 13:03 ` Yu-Hsian Yang
2025-04-20 19:45 ` Andy Shevchenko
2025-04-18 16:13 ` Jonathan Cameron [this message]
2025-04-19 15:23 ` Andy Shevchenko
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=20250418171326.07634113@jic23-huawei \
--to=jic23@kernel.org \
--cc=KWLIU@nuvoton.com \
--cc=alisadariana@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=antoniu.miclaus@analog.com \
--cc=chanh@os.amperecomputing.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=eblanc@baylibre.com \
--cc=gstols@baylibre.com \
--cc=herve.codina@bootlin.com \
--cc=j2anfernee@gmail.com \
--cc=javier.carrasco.cruz@gmail.com \
--cc=joao.goncalves@toradex.com \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.schmitt@analog.com \
--cc=nuno.sa@analog.com \
--cc=olivier.moysan@foss.st.com \
--cc=robh@kernel.org \
--cc=tgamblin@baylibre.com \
--cc=thomas.bonnefille@bootlin.com \
--cc=tobias.sperling@softing.com \
--cc=yhyang2@nuvoton.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