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: linux-pwm@vger.kernel.org, Lee Jones <lee.jones@linaro.org>,
	kernel@pengutronix.de
Subject: Re: [PATCH 1/4] pwm: Make of_pwm_xlate_with_flags() work with #pwm-cells = <2>
Date: Mon, 26 Apr 2021 09:10:48 +0200	[thread overview]
Message-ID: <YIZneL9KueIddbCc@orome.fritz.box> (raw)
In-Reply-To: <20210424112957.oqblunomm64tjtm5@pengutronix.de>

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

On Sat, Apr 24, 2021 at 01:29:57PM +0200, Uwe Kleine-König wrote:
> Hello Thierry,
> 
> On Fri, Apr 09, 2021 at 03:36:40PM +0200, Thierry Reding wrote:
> > 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)
> > 			...
> > 	}
> 
> I'm not convinced here. Being (more) obviously a superset of
> of_pwm_xlate_simple has very limited impact, as of_pwm_xlate_simple is
> going away.

That's precisely the point here. Since you are replacing the existing
of_pwm_xlate_simple() with this one, it's useful to make it as clear as
possible that this is, in fact, a superset.

> Also I expect that a construct like that will attract monkey
> patchers that will change the construct back to what I initially
> suggested. (I'm surprised that there isn't a coccinelle recipe to
> simplify such a construct, but maybe I just failed to find it.)

I don't mind rejecting non-sense patches that some script suggested. If
there's indeed some script or coccinelle recipe that would suggest
merging the conditions in this case, then I would argue that it's broken
and should be fixed or removed.

Thierry

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

  reply	other threads:[~2021-04-26  7:10 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
2021-04-24 11:29     ` Uwe Kleine-König
2021-04-26  7:10       ` Thierry Reding [this message]
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=YIZneL9KueIddbCc@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.