[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <d44a6621-49ff-41c3-a4c1-69bf2e92e012@alliedtelesis.co.nz>
Date: Fri, 12 Jul 2024 10:59:38 +1200
From: Chris Packham <chris.packham@...iedtelesis.co.nz>
To: Uwe Kleine-König <u.kleine-koenig@...libre.com>
Cc: jdelvare@...e.com, linux@...ck-us.net, robh@...nel.org,
krzk+dt@...nel.org, conor+dt@...nel.org, linux-hwmon@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-pwm@...r.kernel.org
Subject: Re: [PATCH v4 1/3] dt-bindings: hwmon: Add adt7475 fan/pwm properties
Hi Uwe,
On 5/07/24 21:09, Uwe Kleine-König wrote:
> Hello Chris,
>
> sorry for taking so long to respond. Don't take it personal, I'm way
> behind my maintainer dutys in general.
>
> On Wed, May 29, 2024 at 10:56:36AM +1200, Chris Packham wrote:
>> Add fan child nodes that allow describing the connections for the
>> ADT7475 to the fans it controls. This also allows setting some
>> initial values for the pwm duty cycle and frequency.
>>
>> Signed-off-by: Chris Packham <chris.packham@...iedtelesis.co.nz>
>> ---
>>
>> Notes:
>> I realise there is still some discussion about how to express the
>> frequency and duty cycle. I have a personal preference for using hertz
>> for the frequency and 0-255 for the duty cycle but if the consensus is
>> to express these things some other way I'm fine with doing some math.
>>
>> Changes in v4:
>> - 0 is not a valid frequency value
>> Changes in v3:
>> - Use the pwm provider/consumer bindings
>> Changes in v2:
>> - Document 0 as a valid value (leaves hardware as-is)
>>
>> .../devicetree/bindings/hwmon/adt7475.yaml | 25 ++++++++++++++++++-
>> 1 file changed, 24 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/devicetree/bindings/hwmon/adt7475.yaml b/Documentation/devicetree/bindings/hwmon/adt7475.yaml
>> index 051c976ab711..bfef4c803bf7 100644
>> --- a/Documentation/devicetree/bindings/hwmon/adt7475.yaml
>> +++ b/Documentation/devicetree/bindings/hwmon/adt7475.yaml
>> @@ -51,6 +51,15 @@ properties:
>> enum: [0, 1]
>> default: 1
>>
>> + "#pwm-cells":
>> + const: 4
>> + description: |
>> + Number of cells in a PWM specifier.
>> + - 0: The pwm channel
>> + - 1: The pwm frequency in hertz - 11, 14, 22, 29, 35, 44, 58, 88, 22500
> Nack, don't deviate from how PWMs are usually referenced. So specify the
> period in nanoseconds, not Hertz.
OK no problem. The math is easy enough. I might end up over documenting
things for the acceptable PWM period so someone can weigh in on that.
>> + - 2: PWM flags 0 or PWM_POLARITY_INVERTED
>> + - 3: The default pwm duty cycle - 0-255
> I'd be ok with that, however please add support for that in the pwm core
> and then just use that.
>
> You wrote that you find it irritating that the duty is specified in
> nanoseconds and not a percentage. The reason for that is historic. Also
> it gives a more precise specification (at least compared to the naive
> representation of the integer percentage as an integer type).
> For the rework of how PWM waveforms are represented I picked
> "duty_length" as variable name for this value, in the hope this is less
> confusing.
>
> untested prototype for a 4th member in pwm specifiers:
Right now the adt7475 is not a pwm_chip and I'm not really planning on
making it one. My goal with this was just to make it possible for the
kernel to keep the fans running quietly before userland can take over
and start doing proper configuration/monitoring. The best I can do is
make sure that the devicetree binding is done in such a way that it
could grow pwm_chip capabilities in the future.
>
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index 5c1d20985148..f732235df12d 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -251,7 +251,7 @@ int pwm_adjust_config(struct pwm_device *pwm)
> * duty cycle of 0.
> */
> if (!state.period) {
> - state.duty_cycle = 0;
> + state.duty_cycle = pargs.duty_length;
> state.period = pargs.period;
> state.polarity = pargs.polarity;
>
> @@ -437,6 +437,10 @@ of_pwm_xlate_with_flags(struct pwm_chip *chip, const struct of_phandle_args *arg
> if (args->args_count > 2 && args->args[2] & PWM_POLARITY_INVERTED)
> pwm->args.polarity = PWM_POLARITY_INVERSED;
>
> + pwm->args.duty_length = 0;
> + if (args->args_count > 3)
> + pwm->args.duty_length = args->args[3];
> +
> return pwm;
> }
> EXPORT_SYMBOL_GPL(of_pwm_xlate_with_flags);
> @@ -457,6 +461,10 @@ of_pwm_single_xlate(struct pwm_chip *chip, const struct of_phandle_args *args)
> if (args->args_count > 1 && args->args[1] & PWM_POLARITY_INVERTED)
> pwm->args.polarity = PWM_POLARITY_INVERSED;
>
> + pwm->args.duty_length = 0;
> + if (args->args_count > 2)
> + pwm->args.duty_length = args->args[2];
> +
> return pwm;
> }
> EXPORT_SYMBOL_GPL(of_pwm_single_xlate);
> @@ -1353,6 +1361,9 @@ static struct pwm_device *acpi_pwm_get(const struct fwnode_handle *fwnode)
> if (args.nargs > 2 && args.args[2] & PWM_POLARITY_INVERTED)
> pwm->args.polarity = PWM_POLARITY_INVERSED;
>
> + /* Maybe extend this to apply args.args[3] if args.nargs > 3? */
> + pwm->args.duty_cycle = 0;
> +
> return pwm;
> }
>
> @@ -1514,6 +1525,7 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
>
> pwm->args.period = chosen->period;
> pwm->args.polarity = chosen->polarity;
> + pwm->args.duty_length = 0;
>
> return pwm;
> }
> diff --git a/include/linux/pwm.h b/include/linux/pwm.h
> index f8c2dc12dbd3..678a97706eac 100644
> --- a/include/linux/pwm.h
> +++ b/include/linux/pwm.h
> @@ -41,6 +41,7 @@ enum pwm_polarity {
> */
> struct pwm_args {
> u64 period;
> + u32 duty_length;
> enum pwm_polarity polarity;
> };
>
> (I think it doesn't make sense to use a u64 here. At least the oftree
> values are only 32 bit wide. I didn't check the ACPI part, if that is
> only 32 bit wide, too, it would make sense to make period use a 32 bit
> type, too.)
>
> Best regards
> Uwe
Powered by blists - more mailing lists