From: Thierry Reding <thierry.reding@gmail.com>
To: "Lothar Waßmann" <LW@KARO-electronics.de>
Cc: linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
Shawn Guo <shawn.guo@linaro.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Tony Prisk <linux@prisktech.co.nz>
Subject: Re: [PATCHv5 2/3] pwm: make the PWM_POLARITY flag in DTB optional
Date: Thu, 9 Oct 2014 17:16:08 +0200 [thread overview]
Message-ID: <20141009151605.GA8818@ulmo.nvidia.com> (raw)
In-Reply-To: <1412690134-13712-3-git-send-email-LW@KARO-electronics.de>
[-- Attachment #1.1: Type: text/plain, Size: 1005 bytes --]
On Tue, Oct 07, 2014 at 03:55:33PM +0200, Lothar Waßmann wrote:
> Change the pwm chip driver registration, so that a chip driver that
> supports polarity inversion can still be used with DTBs that don't
> provide the 'PWM_POLARITY' flag.
>
> This is done to provide polarity inversion support for the pwm-imx
> driver without having to modify all existing DTS files.
I don't like how this throws out the window the only sanity checking we
have in place for the #pwm-cells property.
As I understand it, the problem that you're trying to solve is one of
backwards-compatibility where existing device trees have #pwm-cells =
<2>, but the driver is extended to support flags as well.
In that case, can we not simply make of_pwm_xlate_with_flags() support
that case transparently? That is, if the driver sets .of_pwm_n_cells to
3, we can still support #pwm-cells = <2> and use the default (no) flags
instead.
Something like the below should do that (compile-tested only).
Thierry
[-- Attachment #1.2: patch --]
[-- Type: text/plain, Size: 1880 bytes --]
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 966497d10c6e..89a5e309b0a3 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -136,9 +136,14 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
{
struct pwm_device *pwm;
+ /* check that the driver supports a third cell for flags */
if (pc->of_pwm_n_cells < 3)
return ERR_PTR(-EINVAL);
+ /* flags in the third cell are optional */
+ if (args->args_count < 2)
+ return ERR_PTR(-EINVAL);
+
if (args->args[0] >= pc->npwm)
return ERR_PTR(-EINVAL);
@@ -148,10 +153,12 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
pwm_set_period(pwm, args->args[1]);
- if (args->args[2] & PWM_POLARITY_INVERTED)
- pwm_set_polarity(pwm, PWM_POLARITY_INVERSED);
- else
- pwm_set_polarity(pwm, PWM_POLARITY_NORMAL);
+ if (args->args_count > 2) {
+ if (args->args[2] & PWM_POLARITY_INVERTED)
+ pwm_set_polarity(pwm, PWM_POLARITY_INVERSED);
+ else
+ pwm_set_polarity(pwm, PWM_POLARITY_NORMAL);
+ }
return pwm;
}
@@ -162,9 +169,14 @@ of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
{
struct pwm_device *pwm;
+ /* sanity check driver support */
if (pc->of_pwm_n_cells < 2)
return ERR_PTR(-EINVAL);
+ /* all cells are required */
+ if (args->args_count != pc->of_pwm_n_cells)
+ return ERR_PTR(-EINVAL);
+
if (args->args[0] >= pc->npwm)
return ERR_PTR(-EINVAL);
@@ -536,13 +548,6 @@ struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id)
goto put;
}
- if (args.args_count != pc->of_pwm_n_cells) {
- pr_debug("%s: wrong #pwm-cells for %s\n", np->full_name,
- args.np->full_name);
- pwm = ERR_PTR(-EINVAL);
- goto put;
- }
-
pwm = pc->of_xlate(pc, &args);
if (IS_ERR(pwm))
goto put;
[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]
WARNING: multiple messages have this Message-ID (diff)
From: thierry.reding@gmail.com (Thierry Reding)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCHv5 2/3] pwm: make the PWM_POLARITY flag in DTB optional
Date: Thu, 9 Oct 2014 17:16:08 +0200 [thread overview]
Message-ID: <20141009151605.GA8818@ulmo.nvidia.com> (raw)
In-Reply-To: <1412690134-13712-3-git-send-email-LW@KARO-electronics.de>
On Tue, Oct 07, 2014 at 03:55:33PM +0200, Lothar Wa?mann wrote:
> Change the pwm chip driver registration, so that a chip driver that
> supports polarity inversion can still be used with DTBs that don't
> provide the 'PWM_POLARITY' flag.
>
> This is done to provide polarity inversion support for the pwm-imx
> driver without having to modify all existing DTS files.
I don't like how this throws out the window the only sanity checking we
have in place for the #pwm-cells property.
As I understand it, the problem that you're trying to solve is one of
backwards-compatibility where existing device trees have #pwm-cells =
<2>, but the driver is extended to support flags as well.
In that case, can we not simply make of_pwm_xlate_with_flags() support
that case transparently? That is, if the driver sets .of_pwm_n_cells to
3, we can still support #pwm-cells = <2> and use the default (no) flags
instead.
Something like the below should do that (compile-tested only).
Thierry
-------------- next part --------------
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 966497d10c6e..89a5e309b0a3 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -136,9 +136,14 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
{
struct pwm_device *pwm;
+ /* check that the driver supports a third cell for flags */
if (pc->of_pwm_n_cells < 3)
return ERR_PTR(-EINVAL);
+ /* flags in the third cell are optional */
+ if (args->args_count < 2)
+ return ERR_PTR(-EINVAL);
+
if (args->args[0] >= pc->npwm)
return ERR_PTR(-EINVAL);
@@ -148,10 +153,12 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
pwm_set_period(pwm, args->args[1]);
- if (args->args[2] & PWM_POLARITY_INVERTED)
- pwm_set_polarity(pwm, PWM_POLARITY_INVERSED);
- else
- pwm_set_polarity(pwm, PWM_POLARITY_NORMAL);
+ if (args->args_count > 2) {
+ if (args->args[2] & PWM_POLARITY_INVERTED)
+ pwm_set_polarity(pwm, PWM_POLARITY_INVERSED);
+ else
+ pwm_set_polarity(pwm, PWM_POLARITY_NORMAL);
+ }
return pwm;
}
@@ -162,9 +169,14 @@ of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
{
struct pwm_device *pwm;
+ /* sanity check driver support */
if (pc->of_pwm_n_cells < 2)
return ERR_PTR(-EINVAL);
+ /* all cells are required */
+ if (args->args_count != pc->of_pwm_n_cells)
+ return ERR_PTR(-EINVAL);
+
if (args->args[0] >= pc->npwm)
return ERR_PTR(-EINVAL);
@@ -536,13 +548,6 @@ struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id)
goto put;
}
- if (args.args_count != pc->of_pwm_n_cells) {
- pr_debug("%s: wrong #pwm-cells for %s\n", np->full_name,
- args.np->full_name);
- pwm = ERR_PTR(-EINVAL);
- goto put;
- }
-
pwm = pc->of_xlate(pc, &args);
if (IS_ERR(pwm))
goto put;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141009/da3e1b34/attachment.sig>
next prev parent reply other threads:[~2014-10-09 15:16 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-07 13:55 [PATCHv4 0/3] pwm: imx: support output polarity inversion Lothar Waßmann
2014-10-07 13:55 ` Lothar Waßmann
2014-10-07 13:55 ` [PATCHv5 1/3] pwm: print error messages with pr_err() instead of pr_debug() Lothar Waßmann
2014-10-07 13:55 ` Lothar Waßmann
2014-10-07 13:55 ` [PATCHv5 2/3] pwm: make the PWM_POLARITY flag in DTB optional Lothar Waßmann
2014-10-07 13:55 ` Lothar Waßmann
2014-10-09 15:16 ` Thierry Reding [this message]
2014-10-09 15:16 ` Thierry Reding
2014-10-10 14:22 ` [PATCHv6 0/3] pwm: imx: support output polarity inversion Lothar Waßmann
2014-10-10 14:22 ` Lothar Waßmann
2014-10-10 14:22 ` [PATCHv6 1/3] pwm: print error messages with pr_err() instead of pr_debug() Lothar Waßmann
2014-10-10 14:22 ` Lothar Waßmann
2014-10-10 14:22 ` [PATCHv6 2/3] pwm: make the PWM_POLARITY flag in DTB optional Lothar Waßmann
2014-10-10 14:22 ` Lothar Waßmann
2014-10-10 14:22 ` [PATCH 3/3] pwm: imx: support output polarity inversion Lothar Waßmann
2014-10-10 14:22 ` Lothar Waßmann
2016-09-08 22:15 ` [PATCHv6 0/3] " Stefan Agner
2016-09-08 22:15 ` Stefan Agner
2016-09-09 7:18 ` Lothar Waßmann
2016-09-09 7:18 ` Lothar Waßmann
2016-09-12 12:45 ` Alexandre Belloni
2016-09-12 12:45 ` Alexandre Belloni
2016-09-12 14:04 ` Uwe Kleine-König
2016-09-12 14:04 ` Uwe Kleine-König
2016-09-12 16:51 ` Stefan Agner
2016-09-12 16:51 ` Stefan Agner
2016-09-12 20:00 ` Uwe Kleine-König
2016-09-12 20:00 ` Uwe Kleine-König
2016-09-12 21:12 ` Clemens Gruber
2016-09-12 21:12 ` Clemens Gruber
2016-09-13 6:45 ` Uwe Kleine-König
2016-09-13 6:45 ` Uwe Kleine-König
2016-09-12 13:54 ` Vladimir Zapolskiy
2016-09-12 13:54 ` Vladimir Zapolskiy
2014-10-07 13:55 ` [PATCHv5 3/3] " Lothar Waßmann
2014-10-07 13:55 ` Lothar Waßmann
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=20141009151605.GA8818@ulmo.nvidia.com \
--to=thierry.reding@gmail.com \
--cc=LW@KARO-electronics.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux@prisktech.co.nz \
--cc=s.hauer@pengutronix.de \
--cc=shawn.guo@linaro.org \
/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.