mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Chris Packham <chris.packham@alliedtelesis.co.nz>,
	jdelvare@suse.com, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, ukleinek@kernel.org
Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org
Subject: Re: [PATCH v6 3/3] hwmon: (adt7475) Add support for configuring initial PWM state
Date: Sun, 21 Jul 2024 21:27:53 -0700	[thread overview]
Message-ID: <ed179848-2c8c-41ef-acca-a53d958a30b6@roeck-us.net> (raw)
In-Reply-To: <c261c74f-6829-4888-9836-6f27ba87dc25@alliedtelesis.co.nz>

On 7/21/24 21:09, Chris Packham wrote:
> 
> On 22/07/24 15:53, Guenter Roeck wrote:
>> On 7/21/24 17:58, Chris Packham wrote:
>>> By default the PWM duty cycle in hardware is 100%. On some systems this
>>> can cause unwanted fan noise. Add the ability to specify the fan
>>> connections and initial state of the PWMs via device properties.
>>>
>>> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
>>> ---
>>>
>>> Notes:
>>>      Changes in v6:
>>>      - Use do_div() instead of plain /
>>>      - Use a helper function to avoid repetition between the of and non-of
>>>        code paths.
>>>      Changes in v5:
>>>      - Deal with PWM frequency and duty cycle being specified in nanoseconds
>>>      Changes in v4:
>>>      - Support DT and ACPI fwnodes
>>>      - Put PWM into manual mode
>>>      Changes in v3:
>>>      - Use the pwm provider/consumer bindings
>>>      Changes in v2:
>>>      - Use correct device property string for frequency
>>>      - Allow -EINVAL and only warn on error
>>>      - Use a frequency of 0 to indicate that the hardware should be left as-is
>>>
>>>   drivers/hwmon/adt7475.c | 130 ++++++++++++++++++++++++++++++++++++++++
>>>   1 file changed, 130 insertions(+)
>>>
>>> diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
>>> index 4224ffb30483..fc5605d34f36 100644
>>> --- a/drivers/hwmon/adt7475.c
>>> +++ b/drivers/hwmon/adt7475.c
>>> @@ -21,6 +21,8 @@
>>>   #include <linux/of.h>
>>>   #include <linux/util_macros.h>
>>>   +#include <dt-bindings/pwm/pwm.h>
>>> +
>>>   /* Indexes for the sysfs hooks */
>>>     #define INPUT        0
>>> @@ -1662,6 +1664,130 @@ static int adt7475_set_pwm_polarity(struct i2c_client *client)
>>>       return 0;
>>>   }
>>>   +struct adt7475_pwm_config {
>>> +    int index;
>>> +    int freq;
>>> +    int flags;
>>> +    int duty;
>>> +};
>>> +
>>> +static int _adt7475_pwm_properties_parse_args(u32 args[4], struct adt7475_pwm_config *cfg)
>>> +{
>>> +    unsigned long freq_hz;
>>> +    unsigned long duty;
>>> +
>>> +    if (args[1] == 0)
>>> +        return -EINVAL;
>>> +
>>> +    freq_hz = 1000000000UL;
>>> +    do_div(freq_hz, args[1]);
>>> +    duty = 255 * args[3];
>>> +    do_div(duty, args[1]);
>>> +
>>
>> Gues I am a bit at loss here, just as 0-day. Why use do_div ? It is only needed
>> for 64-bit divide operations.
> 
> Mainly because of Uwe's comment on v5. I think I've avoided the original u64 issue now that I'm converting fwnode_reference_args::args to a u32 array. I can probably get away with plain division, although 255 * args[3] / args[1] might overflow in theory but shouldn't in practice.
> 
> I'll let the earth turn and send out a v7 that uses plain division unless someone has a strong opinion that I should sprinkle some more u64s around.
> 

You lost me, sorry. Neither duty nor freq_hz are u64. What u64 variables
are you talking about ? Using so_div doesn't make those variables u64.

Guenter

>>
>> Thanks,
>> Guenter
>>


  reply	other threads:[~2024-07-22  4:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-22  0:58 [PATCH v6 0/3] hwmon: (adt7475) duty cycle configuration Chris Packham
2024-07-22  0:58 ` [PATCH v6 1/3] dt-bindings: hwmon: Add adt7475 fan/pwm properties Chris Packham
2024-07-22  0:58 ` [PATCH v6 2/3] dt-bindings: hwmon: adt7475: Deprecate adi,pwm-active-state Chris Packham
2024-07-22  0:58 ` [PATCH v6 3/3] hwmon: (adt7475) Add support for configuring initial PWM state Chris Packham
2024-07-22  3:35   ` kernel test robot
2024-07-22  3:53   ` Guenter Roeck
2024-07-22  4:09     ` Chris Packham
2024-07-22  4:27       ` Guenter Roeck [this message]
2024-07-22  4:36         ` Chris Packham
2024-07-22  5:27           ` Guenter Roeck
2024-07-22  7:51       ` Uwe Kleine-König

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=ed179848-2c8c-41ef-acca-a53d958a30b6@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=chris.packham@alliedtelesis.co.nz \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jdelvare@suse.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=ukleinek@kernel.org \
    /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

all inboxes | Powered by JetHome®