All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Lee Jones <lee.jones@linaro.org>,
	linux-pwm@vger.kernel.org, kernel@pengutronix.de
Subject: Re: [PATCH 1/4] pwm: Make of_pwm_xlate_with_flags() work with #pwm-cells = <2>
Date: Fri, 9 Apr 2021 15:36:40 +0200	[thread overview]
Message-ID: <YHBYaCWUrEH6Lz27@orome.fritz.box> (raw)
In-Reply-To: <20210315111124.2475274-2-u.kleine-koenig@pengutronix.de>

[-- Attachment #1: Type: text/plain, Size: 2185 bytes --]

On Mon, Mar 15, 2021 at 12:11:21PM +0100, Uwe Kleine-König wrote:
> The two functions of_pwm_simple_xlate() and of_pwm_xlate_with_flags() are
> quite similar. of_pwm_simple_xlate() only supports two pwm-cells while
> of_pwm_xlate_with_flags() only support >= 3 pwm-cells. The latter can
> easily be modified to behave identically to of_pwm_simple_xlate for two
> pwm-cells. This is implemented here and allows to drop
> of_pwm_simple_xlate() in the next commit.
> 
> There is a small detail that is different now between of_pwm_simple_xlate()
> and of_pwm_xlate_with_flags() with pwm-cells = <2>: pwm->args.polarity is
> unconditionally initialized to PWM_POLARITY_NORMAL in the latter. I didn't
> find a case where this matters and doing that explicitly is the more
> robust approach.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/pwm/core.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index b1adf3bb8508..39b0ad506bdd 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -126,8 +126,7 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
>  {
>  	struct pwm_device *pwm;
>  
> -	/* check, whether the driver supports a third cell for flags */
> -	if (pc->of_pwm_n_cells < 3)
> +	if (pc->of_pwm_n_cells < 2)
>  		return ERR_PTR(-EINVAL);
>  
>  	/* flags in the third cell are optional */
> @@ -144,7 +143,8 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
>  	pwm->args.period = args->args[1];
>  	pwm->args.polarity = PWM_POLARITY_NORMAL;
>  
> -	if (args->args_count > 2 && args->args[2] & PWM_POLARITY_INVERTED)
> +	if (pc->of_pwm_n_cells >= 3 && args->args_count > 2 &&
> +	    args->args[2] & PWM_POLARITY_INVERTED)

This might more clearly look like a superset of of_pwm_xlate_simple() if
you split up the conditional this way:

	if (pc->of_pwm_n_cells >= 3) {
		if (args->args_count > 2 && args->args[2] & PWM_POLARITY_INVERTED)
			...
	}

That'd also help if we ever end up extending the list of supported
flags.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2021-04-09 13:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15 11:11 [PATCH 0/4] pwm: Simplify drivers with of_pwm_n_cells = 3 Uwe Kleine-König
2021-03-15 11:11 ` [PATCH 1/4] pwm: Make of_pwm_xlate_with_flags() work with #pwm-cells = <2> Uwe Kleine-König
2021-03-19 12:58   ` Marco Felsch
2021-03-19 14:00     ` Uwe Kleine-König
2021-04-09 13:36   ` Thierry Reding [this message]
2021-04-24 11:29     ` Uwe Kleine-König
2021-04-26  7:10       ` Thierry Reding
2021-03-15 11:11 ` [PATCH 2/4] pwm: Drop of_pwm_simple_xlate() in favour of of_pwm_xlate_with_flags() Uwe Kleine-König
2021-03-15 11:11 ` [PATCH 3/4] pwm: Autodetect default value for of_pwm_n_cells from device tree Uwe Kleine-König
2021-03-15 11:11 ` [PATCH 4/4] pwm: Simplify all drivers with explicit of_pwm_n_cells = 3 Uwe Kleine-König
2021-04-09 13:38 ` [PATCH 0/4] pwm: Simplify drivers with " Thierry Reding

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=YHBYaCWUrEH6Lz27@orome.fritz.box \
    --to=thierry.reding@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=lee.jones@linaro.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=u.kleine-koenig@pengutronix.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 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.