Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Quentin Schulz <quentin.schulz@cherry.de>, linux-hwmon@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Farouk Bouabid <farouk.bouabid@cherry.de>
Subject: Re: [PATCH 02/10] hwmon: (amc6821) Make reading and writing fan speed limits consistent
Date: Mon, 1 Jul 2024 07:37:37 -0700	[thread overview]
Message-ID: <80a7f733-655e-4b00-a802-825d3acaafcb@roeck-us.net> (raw)
In-Reply-To: <9fce6789-edc8-4c44-89c0-ae4ca3ec3315@roeck-us.net>

On 7/1/24 07:11, Guenter Roeck wrote:
> On 7/1/24 04:05, Quentin Schulz wrote:
>> Hi Guenter,
>>
>> On 6/28/24 5:13 PM, Guenter Roeck wrote:
>>> The default value of the maximum fan speed limit register is 0,
>>> essentially translating to an unlimited fan speed. When reading
>>> the limit, a value of 0 is reported in this case. However, writing
>>> a value of 0 results in writing a value of 0xffff into the register,
>>> which is inconsistent.
>>>  > Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>>> ---
>>>   drivers/hwmon/amc6821.c | 6 +++---
>>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
>>> index 3c614a0bd192..e37257ae1a6b 100644
>>> --- a/drivers/hwmon/amc6821.c
>>> +++ b/drivers/hwmon/amc6821.c
>>> @@ -601,7 +601,7 @@ static ssize_t fan_show(struct device *dev, struct device_attribute *devattr,
>>>       struct amc6821_data *data = amc6821_update_device(dev);
>>>       int ix = to_sensor_dev_attr(devattr)->index;
>>>       if (0 == data->fan[ix])
>>> -        return sprintf(buf, "0");
>>> +        return sprintf(buf, "6000000");
>>>       return sprintf(buf, "%d\n", (int)(6000000 / data->fan[ix]));
>>>   }
>>> @@ -625,10 +625,10 @@ static ssize_t fan_store(struct device *dev, struct device_attribute *attr,
>>>       int ret = kstrtol(buf, 10, &val);
>>>       if (ret)
>>>           return ret;
>>> -    val = 1 > val ? 0xFFFF : 6000000/val;
>>> +    val = val < 1 ? 0xFFFF : 6000000 / val;
>>>       mutex_lock(&data->update_lock);
>>> -    data->fan[ix] = (u16) clamp_val(val, 1, 0xFFFF);
>>> +    data->fan[ix] = (u16)clamp_val(val, 0, 0xFFFF);
>>
>> This is an unrelated change I believe and I would therefore have this in its own commit with proper documentation in the commit log. Indeed:
>>
>> 1- Change in fan_show handles the default 0x0 register value (which can only currently be achieved via the default value of the registers)
>> 2- Allow (re-)setting unlimited fan speed by allowing the user to pass 6000001+ instead of clamping it to 6000000 RPM.
>>
> 
> Both changes are related.
> 
> The whole point of this commit is to report and permit consistent values when
> the register value is 0. But you do have a point - reading it after my changes
> returns 6000000, but writing the same value sets the register to 1. So I think
> the proper change would be to display 6000001 as speed if the register value is
> 0, and provide a more detailed explanation. Would that address your concerns ?
> 

Ah, never  mind, I'll do it differently:

- If the register value is 0, keep reporting 0.
- If the value written is 0, write 0, otherwise limit the range to 1..6000000
   and write clamp_val(6000000 / val, 1, 0xffff)

This minimizes user visibility of the changes, and also ensures that
the reported fan speed is 0 if the register value is 0 when reading the fan
speed.

Guenter


  reply	other threads:[~2024-07-01 14:37 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-28 15:13 [PATCH 00/10] hwmon: (amc6821) Various improvements Guenter Roeck
2024-06-28 15:13 ` [PATCH 01/10] hwmon: (amc6821) Stop accepting invalid pwm values Guenter Roeck
2024-07-01 10:19   ` Quentin Schulz
2024-07-01 13:50     ` Guenter Roeck
2024-06-28 15:13 ` [PATCH 02/10] hwmon: (amc6821) Make reading and writing fan speed limits consistent Guenter Roeck
2024-07-01 11:05   ` Quentin Schulz
2024-07-01 14:11     ` Guenter Roeck
2024-07-01 14:37       ` Guenter Roeck [this message]
2024-07-01 16:13         ` Quentin Schulz
2024-07-01 17:21           ` Guenter Roeck
2024-07-01 18:05             ` Quentin Schulz
2024-07-01 19:11               ` Guenter Roeck
2024-06-28 15:13 ` [PATCH 03/10] hwmon: (amc6821) Rename fan1_div to fan1_pulses Guenter Roeck
2024-07-01 11:08   ` Quentin Schulz
2024-06-28 15:13 ` [PATCH 04/10] hwmon: (amc6821) Add support for fan1_target and pwm1_enable mode 4 Guenter Roeck
2024-07-01 11:23   ` Quentin Schulz
2024-07-01 15:26     ` Guenter Roeck
2024-07-01 16:29       ` Quentin Schulz
2024-07-01 17:31         ` Guenter Roeck
2024-06-28 15:13 ` [PATCH 05/10] hwmon: (amc2821) Reorder include files, drop unnecessary ones Guenter Roeck
2024-07-01 11:24   ` Quentin Schulz
2024-06-28 15:13 ` [PATCH 06/10] hwmon: (amc6821) Use tabs for column alignment in defines Guenter Roeck
2024-07-01 11:26   ` Quentin Schulz
2024-06-28 15:13 ` [PATCH 07/10] hwmon: (amc2821) Use BIT() and GENMASK() Guenter Roeck
2024-07-01 11:31   ` Quentin Schulz
2024-07-01 14:44     ` Guenter Roeck
2024-06-28 15:13 ` [PATCH 08/10] hwmon: (amc6821) Drop unnecessary enum chips Guenter Roeck
2024-07-01 11:36   ` Quentin Schulz
2024-07-01 14:47     ` Guenter Roeck
2024-06-28 15:13 ` [PATCH 09/10] hwmon: (amc6821) Convert to use regmap Guenter Roeck
2024-07-01 13:01   ` Quentin Schulz
2024-07-01 13:47     ` Guenter Roeck
2024-07-01 16:54       ` Quentin Schulz
2024-07-01 17:30         ` Guenter Roeck
2024-06-28 15:13 ` [PATCH 10/10] hwmon: (amc6821) Convert to with_info API Guenter Roeck
2024-07-01 17:46   ` Quentin Schulz
2024-07-01 18:24     ` Guenter Roeck

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=80a7f733-655e-4b00-a802-825d3acaafcb@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=farouk.bouabid@cherry.de \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quentin.schulz@cherry.de \
    /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