[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c1cbb337-9ca5-4071-b05a-a97ab451f358@wanadoo.fr>
Date: Sun, 26 Jan 2025 16:42:50 +0900
From: Vincent Mailhol <mailhol.vincent@...adoo.fr>
To: Ming Yu <a0282524688@...il.com>
Cc: tmyu0@...oton.com, lee@...nel.org, linus.walleij@...aro.org,
brgl@...ev.pl, andi.shyti@...nel.org, mkl@...gutronix.de,
andrew+netdev@...n.ch, davem@...emloft.net, edumazet@...gle.com,
kuba@...nel.org, pabeni@...hat.com, wim@...ux-watchdog.org,
linux@...ck-us.net, jdelvare@...e.com, alexandre.belloni@...tlin.com,
linux-kernel@...r.kernel.org, linux-gpio@...r.kernel.org,
linux-i2c@...r.kernel.org, linux-can@...r.kernel.org,
netdev@...r.kernel.org, linux-watchdog@...r.kernel.org,
linux-hwmon@...r.kernel.org, linux-rtc@...r.kernel.org,
linux-usb@...r.kernel.org
Subject: Re: [PATCH v6 6/7] hwmon: Add Nuvoton NCT6694 HWMON support
On 23/01/2025 at 18:11, Ming Yu wrote:
> This driver supports Hardware monitor functionality for NCT6694 MFD
> device based on USB interface.
>
> Signed-off-by: Ming Yu <a0282524688@...il.com>
> ---
(...)
> +static int nct6694_temp_write(struct device *dev, u32 attr, int channel,
> + long val)
> +{
> + struct nct6694_hwmon_data *data = dev_get_drvdata(dev);
> + struct nct6694_cmd_header cmd_hd;
> + unsigned char temp_hyst;
> + signed char temp_max;
> + int ret;
> +
> + guard(mutex)(&data->lock);
> +
> + switch (attr) {
> + case hwmon_temp_enable:
> + if (val == 0)
> + data->hwmon_en.tin_en[channel / 8] &= ~BIT(channel % 8);
> + else if (val == 1)
> + data->hwmon_en.tin_en[channel / 8] |= BIT(channel % 8);
> + else
> + return -EINVAL;
> +
> + cmd_hd = (struct nct6694_cmd_header) {
> + .mod = NCT6694_HWMON_MOD,
> + .cmd = NCT6694_HWMON_CONTROL,
> + .sel = NCT6694_HWMON_CONTROL_SEL,
> + .len = cpu_to_le16(sizeof(data->hwmon_en))
> + };
> +
> + return nct6694_write_msg(data->nct6694, &cmd_hd,
> + &data->hwmon_en);
> + case hwmon_temp_max:
> + cmd_hd = (struct nct6694_cmd_header) {
> + .mod = NCT6694_HWMON_MOD,
> + .cmd = NCT6694_HWMON_ALARM,
> + .sel = NCT6694_HWMON_ALARM_SEL,
> + .len = cpu_to_le16(sizeof(data->msg->hwmon_alarm))
> + };
> + ret = nct6694_read_msg(data->nct6694, &cmd_hd,
> + &data->msg->hwmon_alarm);
> + if (ret)
> + return ret;
> +
> + val = clamp_val(val, -127000, 127000);
> + data->msg->hwmon_alarm.tin_cfg[channel].hl = temp_to_reg(val);
> +
> + return nct6694_write_msg(data->nct6694, &cmd_hd,
> + &data->msg->hwmon_alarm);
> + case hwmon_temp_max_hyst:
> + cmd_hd = (struct nct6694_cmd_header) {
> + .mod = NCT6694_HWMON_MOD,
> + .cmd = NCT6694_HWMON_ALARM,
> + .sel = NCT6694_HWMON_ALARM_SEL,
> + .len = cpu_to_le16(sizeof(data->msg->hwmon_alarm))
> + };
> + ret = nct6694_read_msg(data->nct6694, &cmd_hd,
> + &data->msg->hwmon_alarm);
> +
> + val = clamp_val(val, -127000, 127000);
> + temp_max = data->msg->hwmon_alarm.tin_cfg[channel].hl;
> + temp_hyst = temp_max - temp_to_reg(val);
> + temp_hyst = clamp_val(temp_hyst, 0, 7);
temp_hyst is unsigned. It can not be smaller than zero. No need for
clamp(), using min here is sufficient.
> + data->msg->hwmon_alarm.tin_cfg[channel].hyst =
> + (data->msg->hwmon_alarm.tin_cfg[channel].hyst & ~NCT6694_TIN_HYST_MASK) |
> + FIELD_PREP(NCT6694_TIN_HYST_MASK, temp_hyst);
> +
> + return nct6694_write_msg(data->nct6694, &cmd_hd,
> + &data->msg->hwmon_alarm);
> + default:
> + return -EOPNOTSUPP;
> + }
> +}
(...)
Yours sincerely,
Vincent Mailhol
Powered by blists - more mailing lists