Re: [PATCH v2 6/7] hwmon: Add Nuvoton NCT6694 HWMON support

Ming Yu
2024-11-22T08:15:37Z

Dear Guenter,

Thank you for your comments,

Guenter Roeck <linux@roeck-us.net> 於 2024年11月21日 週四 下午10:22寫道：
>
...
> > +static int nct6694_in_read(struct device *dev, u32 attr, int channel,
> > + long *val)
> > +{
> > + struct nct6694_hwmon_data *data = dev_get_drvdata(dev);
> > + unsigned char vin_en;
> > + int ret;
> > +
> > + guard(mutex)(&data->lock);
> > +
> > + switch (attr) {
> > + case hwmon_in_enable:
> > + vin_en = data->hwmon_en[NCT6694_VIN_EN(channel / 8)];
> > + *val = vin_en & BIT(channel % 8) ? 1 : 0;
>
> Nit: !!(vin_en & BIT(channel % 8))
>
> Not even worth mentioning, but !! is used below, so it would make sense
> to use it here as well for consistency.
>

Understood. I will make the modifications in v3.

> > +
> > + return 0;
...
> > +static int nct6694_temp_write(struct device *dev, u32 attr, int channel,
> > + long val)
> > +{
> > + struct nct6694_hwmon_data *data = dev_get_drvdata(dev);
> > + signed char temp_max, temp_hyst;
> > + int ret;
> > +
> > + guard(mutex)(&data->lock);
> > +
> > + switch (attr) {
> > + case hwmon_temp_enable:
> > + return nct6694_enable_channel(dev, NCT6694_TIN_EN(channel / 8),
> > + channel, val);
> > + case hwmon_temp_max:
> > + ret = nct6694_read_msg(data->nct6694, NCT6694_HWMON_MOD,
> > + NCT6694_HWMON_CMD2_OFFSET,
> > + NCT6694_HWMON_CMD2_LEN,
> > + data->xmit_buf);
> > + if (ret)
> > + return ret;
> > +
> > + val = clamp_val(val, -127000, 127000);
> > + data->xmit_buf[NCT6694_TIN_HL(channel)] = temp_to_reg(val);
> > +
> > + return nct6694_write_msg(data->nct6694, NCT6694_HWMON_MOD,
> > + NCT6694_HWMON_CMD2_OFFSET,
> > + NCT6694_HWMON_CMD2_LEN,
> > + data->xmit_buf);
> > + case hwmon_temp_max_hyst:
> > + ret = nct6694_read_msg(data->nct6694, NCT6694_HWMON_MOD,
> > + NCT6694_HWMON_CMD2_OFFSET,
> > + NCT6694_HWMON_CMD2_LEN,
> > + data->xmit_buf);
> > +
> > + val = clamp_val(val, -127000, 127000);
> > + temp_max = (signed char)data->xmit_buf[NCT6694_TIN_HL(channel)];
> > + temp_hyst = (temp_max < 0) ? (temp_max + val / 1000) :
> > + (temp_max - val / 1000);
> > + if (temp_hyst < 0 || temp_hyst > 7)
> > + return -EINVAL;
> > +
>
> Just use clamp_val() again. Otherwise it is difficult for the user to determine
> valid ranges.
>

Understood. I will make the modifications in v3.

> > + data->xmit_buf[NCT6694_TIN_HYST(channel)] =
> > + (data->xmit_buf[NCT6694_TIN_HYST(channel)] & ~NCT6694_TIN_HYST_MASK) |
> > + FIELD_PREP(NCT6694_TIN_HYST_MASK, temp_hyst);
> > +
> > + return nct6694_write_msg(data->nct6694, NCT6694_HWMON_MOD,
> > + NCT6694_HWMON_CMD2_OFFSET,
> > + NCT6694_HWMON_CMD2_LEN,
> > + data->xmit_buf);
> > + default:
> > + return -EOPNOTSUPP;
> > + }
> > +}
> > +
> > +static int nct6694_fan_write(struct device *dev, u32 attr, int channel,
> > + long val)
> > +{
> > + struct nct6694_hwmon_data *data = dev_get_drvdata(dev);
> > + int ret;
> > +
> > + guard(mutex)(&data->lock);
> > +
> > + switch (attr) {
> > + case hwmon_fan_enable:
> > + return nct6694_enable_channel(dev, NCT6694_FIN_EN(channel / 8),
> > + channel, val);
> > + case hwmon_fan_min:
> > + if (val <= 0)
> > + return -EINVAL;
> > +
> I'd suggest to just use clamp_val() and drop this check.
>

Understood. I will make the modifications in v3.

Best regards,
Ming