Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1513141

[PATCH v3 09/11] pwm: core: make the PWM_POLARITY flag in DTB optional

From Lukasz Majewski <l.majewski@majess.pl>
Newsgroups linux.kernel
Subject [PATCH v3 09/11] pwm: core: make the PWM_POLARITY flag in DTB optional
Date 2016-11-01 08:30 +0100
Message-ID <syBGa-5AA-13@gated-at.bofh.it> (permalink)
References <syBwt-5xk-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Lothar Wassmann <LW@KARO-electronics.de>

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.

Signed-off-by: Lothar Wassmann <LW@KARO-electronics.de>
Signed-off-by: Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>
Suggested-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
---
Changes for v3:
- None

Changes for v2:
- None
---
 drivers/pwm/core.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index ec7179f..d80e5c5 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -137,9 +137,14 @@ 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)
 		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,11 +153,10 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
 		return pwm;
 
 	pwm->args.period = args->args[1];
+	pwm->args.polarity = PWM_POLARITY_NORMAL;
 
-	if (args->args[2] & PWM_POLARITY_INVERTED)
+	if (args->args_count > 2 && args->args[2] & PWM_POLARITY_INVERTED)
 		pwm->args.polarity = PWM_POLARITY_INVERSED;
-	else
-		pwm->args.polarity = PWM_POLARITY_NORMAL;
 
 	return pwm;
 }
@@ -163,9 +167,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);
 
@@ -674,13 +683,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;
-- 
2.1.4

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v3 00/11] pwm: imx: Provide atomic operation for IMX PWM driver Lukasz Majewski <l.majewski@majess.pl> - 2016-11-01 08:20 +0100
  [PATCH v3 08/11] pwm: imx: Remove redundant i.MX PWMv2 code Lukasz Majewski <l.majewski@majess.pl> - 2016-11-01 08:20 +0100
  [PATCH v3 05/11] pwm: imx: Move PWMv2 software reset code to a separate function Lukasz Majewski <l.majewski@majess.pl> - 2016-11-01 08:20 +0100
  [PATCH v3 03/11] pwm: imx: Add separate set of pwm ops for PWMv1 and PWMv2 Lukasz Majewski <l.majewski@majess.pl> - 2016-11-01 08:20 +0100
  [PATCH v3 04/11] pwm: imx: Rewrite imx_pwm_*_v1 code to facilitate switch to atomic pwm operation Lukasz Majewski <l.majewski@majess.pl> - 2016-11-01 08:20 +0100
  [PATCH v3 02/11] pwm: imx: remove ipg clock Lukasz Majewski <l.majewski@majess.pl> - 2016-11-01 08:20 +0100
    Re: [PATCH v3 02/11] pwm: imx: remove ipg clock Philipp Zabel <p.zabel@pengutronix.de> - 2016-11-01 10:30 +0100
  [PATCH v3 10/11] pwm: imx: doc: Update imx-pwm.txt documentation entry Lukasz Majewski <l.majewski@majess.pl> - 2016-11-01 08:20 +0100
  [PATCH v3 01/11] pwm: print error messages with pr_err() instead of pr_debug() Lukasz Majewski <l.majewski@majess.pl> - 2016-11-01 08:20 +0100
  [PATCH v3 11/11] pwm: imx: Add polarity inversion support to i.MX's PWMv2 Lukasz Majewski <l.majewski@majess.pl> - 2016-11-01 08:30 +0100
  [PATCH v3 09/11] pwm: core: make the PWM_POLARITY flag in DTB optional Lukasz Majewski <l.majewski@majess.pl> - 2016-11-01 08:30 +0100
  [PATCH v3 07/11] pwm: imx: Provide atomic PWM support for i.MX PWMv2 Lukasz Majewski <l.majewski@majess.pl> - 2016-11-01 08:40 +0100
  [PATCH v3 06/11] pwm: imx: Move PWMv2 wait for fifo slot code to a separate function Lukasz Majewski <l.majewski@majess.pl> - 2016-11-01 08:40 +0100
  Re: [PATCH v3 00/11] pwm: imx: Provide atomic operation for IMX PWM  driver Lukasz Majewski <l.majewski@majess.pl> - 2016-11-08 23:30 +0100

csiph-web