linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwmon: pwm-fan: set usage_power on PWM state
@ 2023-03-09  1:10 Lorenz Brun
  2023-03-16  2:26 ` Guenter Roeck
  2023-03-21 15:03 ` Guenter Roeck
  0 siblings, 2 replies; 4+ messages in thread
From: Lorenz Brun @ 2023-03-09  1:10 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck; +Cc: linux-hwmon, linux-kernel

PWM fans are controlled solely by the duty cycle of the PWM signal, they
do not care about the exact timing. Thus set usage_power to true to
allow less flexible hardware to work as a PWM source for fan control.

Signed-off-by: Lorenz Brun <lorenz@brun.one>
---
 drivers/hwmon/pwm-fan.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index 83a347ca35da..aa746c2bde39 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -507,6 +507,14 @@ static int pwm_fan_probe(struct platform_device *pdev)
 
 	pwm_init_state(ctx->pwm, &ctx->pwm_state);
 
+	/*
+	 * PWM fans are controlled solely by the duty cycle of the PWM signal,
+	 * they do not care about the exact timing. Thus set usage_power to true
+	 * to allow less flexible hardware to work as a PWM source for fan
+	 * control.
+	 */
+	ctx->pwm_state.usage_power = true;
+
 	/*
 	 * set_pwm assumes that MAX_PWM * (period - 1) fits into an unsigned
 	 * long. Check this here to prevent the fan running at a too low
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] hwmon: pwm-fan: set usage_power on PWM state
  2023-03-09  1:10 [PATCH] hwmon: pwm-fan: set usage_power on PWM state Lorenz Brun
@ 2023-03-16  2:26 ` Guenter Roeck
  2023-03-17 11:33   ` Lorenz Brun
  2023-03-21 15:03 ` Guenter Roeck
  1 sibling, 1 reply; 4+ messages in thread
From: Guenter Roeck @ 2023-03-16  2:26 UTC (permalink / raw)
  To: Lorenz Brun; +Cc: Jean Delvare, linux-hwmon, linux-kernel

On Thu, Mar 09, 2023 at 02:10:08AM +0100, Lorenz Brun wrote:
> PWM fans are controlled solely by the duty cycle of the PWM signal, they
> do not care about the exact timing. Thus set usage_power to true to
> allow less flexible hardware to work as a PWM source for fan control.
> 

This doesn't seem to be used anywhere else. I do not understand the
rationale, and I do not understand the practical impact of this change.
This needs to be confirmed by someone who understands what the flag is
supposed to be used for, its impact, and if it is indeed appropriate
in this context.

Also, since in practice there is no such "less flexible hardware"
in the upstream kernel, please describe the use case in more detail.
The only pwm driver that supports usage_power is pwm-pca9685,
and that driver uses the flag for EMI reasons, not because it is
"less flexible hardware". I am not inclined to accept such a change
without specific use case or need.

Thanks,
Guenter

> Signed-off-by: Lorenz Brun <lorenz@brun.one>
> ---
>  drivers/hwmon/pwm-fan.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
> index 83a347ca35da..aa746c2bde39 100644
> --- a/drivers/hwmon/pwm-fan.c
> +++ b/drivers/hwmon/pwm-fan.c
> @@ -507,6 +507,14 @@ static int pwm_fan_probe(struct platform_device *pdev)
>  
>  	pwm_init_state(ctx->pwm, &ctx->pwm_state);
>  
> +	/*
> +	 * PWM fans are controlled solely by the duty cycle of the PWM signal,
> +	 * they do not care about the exact timing. Thus set usage_power to true
> +	 * to allow less flexible hardware to work as a PWM source for fan
> +	 * control.
> +	 */
> +	ctx->pwm_state.usage_power = true;
> +
>  	/*
>  	 * set_pwm assumes that MAX_PWM * (period - 1) fits into an unsigned
>  	 * long. Check this here to prevent the fan running at a too low

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hwmon: pwm-fan: set usage_power on PWM state
  2023-03-16  2:26 ` Guenter Roeck
@ 2023-03-17 11:33   ` Lorenz Brun
  0 siblings, 0 replies; 4+ messages in thread
From: Lorenz Brun @ 2023-03-17 11:33 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Jean Delvare, linux-hwmon, linux-kernel

Am Mi, 15. Mär 2023 um 19:26:26 -07:00:00 schrieb Guenter Roeck 
<linux@roeck-us.net>:
> This doesn't seem to be used anywhere else. I do not understand the
> rationale, and I do not understand the practical impact of this 
> change.
> This needs to be confirmed by someone who understands what the flag is
> supposed to be used for, its impact, and if it is indeed appropriate
> in this context.
> 
> Also, since in practice there is no such "less flexible hardware"
> in the upstream kernel, please describe the use case in more detail.
> The only pwm driver that supports usage_power is pwm-pca9685,
> and that driver uses the flag for EMI reasons, not because it is
> "less flexible hardware". I am not inclined to accept such a change
> without specific use case or need.

The reason for this is that I have a PWM-driven fan on a Mediatek 
MT7986a whose PWM signal is inverted by a MOSFET.
The PWM peripheral of the MT7986a however doesn't support inverted 
output, at least not in a strict sense (i.e. if inverted mathematically 
it is out of phase). The maintainer of the PWM subsystem recommended 
that I only mathematically invert if usage_power is set as this means 
that phase doesn't matter.

See 
https://lore.kernel.org/linux-pwm/20230309010410.2106525-1-lorenz@brun.one/ 
for the PWM-side patch.

Regards,
Lorenz



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hwmon: pwm-fan: set usage_power on PWM state
  2023-03-09  1:10 [PATCH] hwmon: pwm-fan: set usage_power on PWM state Lorenz Brun
  2023-03-16  2:26 ` Guenter Roeck
@ 2023-03-21 15:03 ` Guenter Roeck
  1 sibling, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2023-03-21 15:03 UTC (permalink / raw)
  To: Lorenz Brun; +Cc: Jean Delvare, linux-hwmon, linux-kernel

On Thu, Mar 09, 2023 at 02:10:08AM +0100, Lorenz Brun wrote:
> PWM fans are controlled solely by the duty cycle of the PWM signal, they
> do not care about the exact timing. Thus set usage_power to true to
> allow less flexible hardware to work as a PWM source for fan control.
> 
> Signed-off-by: Lorenz Brun <lorenz@brun.one>

Applied to hwmon-next.

Thanks,
Guenter

> ---
>  drivers/hwmon/pwm-fan.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
> index 83a347ca35da..aa746c2bde39 100644
> --- a/drivers/hwmon/pwm-fan.c
> +++ b/drivers/hwmon/pwm-fan.c
> @@ -507,6 +507,14 @@ static int pwm_fan_probe(struct platform_device *pdev)
>  
>  	pwm_init_state(ctx->pwm, &ctx->pwm_state);
>  
> +	/*
> +	 * PWM fans are controlled solely by the duty cycle of the PWM signal,
> +	 * they do not care about the exact timing. Thus set usage_power to true
> +	 * to allow less flexible hardware to work as a PWM source for fan
> +	 * control.
> +	 */
> +	ctx->pwm_state.usage_power = true;
> +
>  	/*
>  	 * set_pwm assumes that MAX_PWM * (period - 1) fits into an unsigned
>  	 * long. Check this here to prevent the fan running at a too low

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-21 15:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-09  1:10 [PATCH] hwmon: pwm-fan: set usage_power on PWM state Lorenz Brun
2023-03-16  2:26 ` Guenter Roeck
2023-03-17 11:33   ` Lorenz Brun
2023-03-21 15:03 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).