All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dimitri Fedrau <dima.fedrau@gmail.com>
To: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
Cc: linux-pwm@vger.kernel.org
Subject: Re: [PATCH] pwm: Assume a disabled PWM to emit a constant inactive output
Date: Wed, 6 Nov 2024 10:46:18 +0100	[thread overview]
Message-ID: <20241106094618.GA306258@debian> (raw)
In-Reply-To: <20241105153521.1001864-2-u.kleine-koenig@baylibre.com>

Am Tue, Nov 05, 2024 at 04:35:22PM +0100 schrieb Uwe Kleine-König:
> Some PWM hardwares (e.g. MC33XS2410) cannot implement a zero duty cycle
> but can instead disable the hardware which also results in a constant
> inactive output.
> 
> There are some checks (enabled with CONFIG_PWM_DEBUG) to help
> implementing a driver without violating the normal rounding rules. Make
> them less strict to let above described hardware pass without warning.
> 
> Reported-by: Dimitri Fedrau <dima.fedrau@gmail.com>
> Link: https://lore.kernel.org/r/20241103205215.GA509903@debian
> Fixes: 3ad1f3a33286 ("pwm: Implement some checks for lowlevel drivers")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
> ---
> Hello,
> 
> in the context of discussing the implementation of an MC33XS2410 driver
> Dimitri reported this (unjustified) warning. With this patch the
> reported warning should go away when applying the optimisation I
> suggested.
> 
> Best regards
> Uwe
> 
>  drivers/pwm/core.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index 6e752e148b98..210368099a06 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -75,7 +75,7 @@ static void pwm_apply_debug(struct pwm_device *pwm,
>  	    state->duty_cycle < state->period)
>  		dev_warn(pwmchip_parent(chip), ".apply ignored .polarity\n");
>  
> -	if (state->enabled &&
> +	if (state->enabled && s2.enabled &&
>  	    last->polarity == state->polarity &&
>  	    last->period > s2.period &&
>  	    last->period <= state->period)
> @@ -83,7 +83,11 @@ static void pwm_apply_debug(struct pwm_device *pwm,
>  			 ".apply didn't pick the best available period (requested: %llu, applied: %llu, possible: %llu)\n",
>  			 state->period, s2.period, last->period);
>  
> -	if (state->enabled && state->period < s2.period)
> +	/*
> +	 * Rounding period up is fine only if duty_cycle is 0 then, because a
> +	 * flat line doesn't have a characteristic period.
> +	 */
> +	if (state->enabled && s2.enabled && state->period < s2.period && s2.duty_cycle)
>  		dev_warn(pwmchip_parent(chip),
>  			 ".apply is supposed to round down period (requested: %llu, applied: %llu)\n",
>  			 state->period, s2.period);
> @@ -99,7 +103,7 @@ static void pwm_apply_debug(struct pwm_device *pwm,
>  			 s2.duty_cycle, s2.period,
>  			 last->duty_cycle, last->period);
>  
> -	if (state->enabled && state->duty_cycle < s2.duty_cycle)
> +	if (state->enabled && s2.enabled && state->duty_cycle < s2.duty_cycle)
>  		dev_warn(pwmchip_parent(chip),
>  			 ".apply is supposed to round down duty_cycle (requested: %llu/%llu, applied: %llu/%llu)\n",
>  			 state->duty_cycle, state->period,
> 
> base-commit: 9852d85ec9d492ebef56dc5f229416c925758edc
> -- 
> 2.45.2
> 
Hello Uwe,

works for me. Unjustified reported warnings are gone.
Thanks for the patch.

Reviewed-by: Dimitri Fedrau <dima.fedrau@gmail.com>
Tested-by: Dimitri Fedrau <dima.fedrau@gmail.com>

Best regards,
Dimitri

  reply	other threads:[~2024-11-06  9:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-05 15:35 [PATCH] pwm: Assume a disabled PWM to emit a constant inactive output Uwe Kleine-König
2024-11-06  9:46 ` Dimitri Fedrau [this message]
2024-11-07 11:05 ` 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=20241106094618.GA306258@debian \
    --to=dima.fedrau@gmail.com \
    --cc=linux-pwm@vger.kernel.org \
    --cc=u.kleine-koenig@baylibre.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.