Skip to contentSkip to conversation

pwm: support backward compatibility of DTB extending PWM args

PATCH Superseded Vladimir Zapolskiy 2 participants 10 messages Oct 10, 2014 – Oct 13, 2014 PWM

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover pwm: support backward compatibility of DTB extending PWM args

Please review this alternative in-house version of supporting backward compatibility of DTB files, if pwms arguments of exisitng PWM drivers are to be extended with polarity field.

Unfortunately I've firstly created the change and only after that found that Lothar Wa?mann is working on his version, so I won't insist on formal preference, but still I like to share my variant since it technically different from Lothar's one.

One visual benefit of my verison is that if this version is accepted, then of_pwm_xlate_with_flags() can be removed from all touched PWM drivers and pwm/core.c as a redundant interface and generally is looks to be a more simple change.

The particular changes in iMX PWM driver and other PWM drivers are out of this change scope.

Feel free to criticize the change.

Vladimir Zapolskiy (3):
pwm: process pwm polarity argument in of_pwm_simple_xlate()
pwm: push up dynamic printk level on errors in of_pwm_get()
pwm: set the actual number of pwms arguments defined in board dts

 drivers/pwm/core.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/3 pwm: process pwm polarity argument in of_pwm_simple_xlate()

The third optional argument of pwms is well defined as polarity and it is already used in a number of pwm drivers, so, to minimize changes in the remaining drivers which are to be updated accordingly set polarity in default of_xlate() function.

Cc Lothar Wa?mann <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Shawn Guo <[email protected]>
---
 drivers/pwm/core.c |    7 +++++++
 1 file changed, 7 insertions(+)
drivers/pwm/core.c +7 -0
index 966497d..681d154 100644
@@ -174,6 +174,13 @@ of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
 
 	pwm_set_period(pwm, args->args[1]);
 
+	if (pc->of_pwm_n_cells > 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;
 }
 
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/3 pwm: push up dynamic printk level on errors in of_pwm_get()

In reply to Vladimir Zapolskiy

The changed three user messages on fault are printed under pr_debug(), however all of them are unrecoverable and result in failed pwm device registration, report this to a user.

Cc Lothar Wa?mann <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Shawn Guo <[email protected]>
---
 drivers/pwm/core.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pwm/core.c +3 -3
index 681d154..ccf1be7 100644
@@ -532,19 +532,19 @@ struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id)
 	err = of_parse_phandle_with_args(np, "pwms", "#pwm-cells", index,
 					 &args);
 	if (err) {
-		pr_debug("%s(): can't parse \"pwms\" property\n", __func__);
+		pr_warn("%s(): can't parse \"pwms\" property\n", __func__);
 		return ERR_PTR(err);
 	}
 
 	pc = of_node_to_pwmchip(args.np);
 	if (IS_ERR(pc)) {
-		pr_debug("%s(): PWM chip not found\n", __func__);
+		pr_warn("%s(): PWM chip not found\n", __func__);
 		pwm = ERR_CAST(pc);
 		goto put;
 	}
 
 	if (args.args_count != pc->of_pwm_n_cells) {
-		pr_debug("%s: wrong #pwm-cells for %s\n", np->full_name,
+		pr_warn("%s: wrong #pwm-cells for %s\n", np->full_name,
 			 args.np->full_name);
 		pwm = ERR_PTR(-EINVAL);
 		goto put;
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 2/3 pwm: push up dynamic printk level on errors in of_pwm_get()

Hi,

Quoted 18 lines · Vladimir Zapolskiy

The changed three user messages on fault are printed under pr_debug(), however all of them are unrecoverable and result in failed pwm device registration, report this to a user.

Cc Lothar Wa?mann <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Shawn Guo <[email protected]>
---
 drivers/pwm/core.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pwm/core.c +0 -0
index 681d154..ccf1be7 100644

drivers/pwm/core.c struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id) · line 536

Quoted 6 lines
drivers/pwm/core.c +1 -1
@@ -532,19 +532,19 @@ struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id)
 	err = of_parse_phandle_with_args(np, "pwms", "#pwm-cells", index,
 					 &args);
 	if (err) {
-		pr_debug("%s(): can't parse \"pwms\" property\n", __func__);
+		pr_warn("%s(): can't parse \"pwms\" property\n", __func__);
 

As this is an error that leads to not loading the driver it should be printed with ERROR level.

drivers/pwm/core.c struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id) · line 545

Quoted 8 lines
drivers/pwm/core.c +1 -1
 		return ERR_PTR(err);
 	}
 
 	pc = of_node_to_pwmchip(args.np);
 	if (IS_ERR(pc)) {
-		pr_debug("%s(): PWM chip not found\n", __func__);
+		pr_warn("%s(): PWM chip not found\n", __func__);
 

dto.

drivers/pwm/core.c struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id)

Quoted 7 lines
drivers/pwm/core.c +1 -1
 		goto put;
 	}
 
 	if (args.args_count != pc->of_pwm_n_cells) {
-		pr_debug("%s: wrong #pwm-cells for %s\n", np->full_name,
+		pr_warn("%s: wrong #pwm-cells for %s\n", np->full_name,
 

dto.

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#4 lore raw

PATCH 3/3 pwm: set the actual number of pwms arguments defined in board dts

In reply to Vladimir Zapolskiy

For backward compatibility board device tree has to define only a minimal amount of mandatory pwms arguments, additional arguments shall be considered as optional, update pc->of_pwm_n_cells according to the actual data taken from device tree file.

Cc Lothar Wa?mann <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Shawn Guo <[email protected]>
---
 drivers/pwm/core.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pwm/core.c +2 -1
index ccf1be7..2b77322 100644
@@ -543,12 +543,13 @@ 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) {
+	if (args.args_count < pc->of_pwm_n_cells) {
 		pr_warn("%s: wrong #pwm-cells for %s\n", np->full_name,
 			 args.np->full_name);
 		pwm = ERR_PTR(-EINVAL);
 		goto put;
 	}
+	pc->of_pwm_n_cells = args.args_count;
 
 	pwm = pc->of_xlate(pc, &args);
 	if (IS_ERR(pwm))
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH v2 2/3 pwm: push up dynamic printk level on errors in of_pwm_get()

In reply to Vladimir Zapolskiy

The changed three user messages on fault are printed under pr_debug(), however all of them are unrecoverable and result in failed pwm device registration, report this to a user.

Cc Lothar Wa?mann <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Shawn Guo <[email protected]>

---
Changes from v1 to v2:
- corrected the proper kernel log level, thanks to Lothar Wa?mann.

 drivers/pwm/core.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pwm/core.c +3 -3
index 681d154..f6231c6 100644
@@ -532,19 +532,19 @@ struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id)
 	err = of_parse_phandle_with_args(np, "pwms", "#pwm-cells", index,
 					 &args);
 	if (err) {
-		pr_debug("%s(): can't parse \"pwms\" property\n", __func__);
+		pr_err("%s(): can't parse \"pwms\" property\n", __func__);
 		return ERR_PTR(err);
 	}
 
 	pc = of_node_to_pwmchip(args.np);
 	if (IS_ERR(pc)) {
-		pr_debug("%s(): PWM chip not found\n", __func__);
+		pr_err("%s(): PWM chip not found\n", __func__);
 		pwm = ERR_CAST(pc);
 		goto put;
 	}
 
 	if (args.args_count != pc->of_pwm_n_cells) {
-		pr_debug("%s: wrong #pwm-cells for %s\n", np->full_name,
+		pr_err("%s: wrong #pwm-cells for %s\n", np->full_name,
 			 args.np->full_name);
 		pwm = ERR_PTR(-EINVAL);
 		goto put;
Signature · 1 line
1.7.10.4
#6 lore raw

v2 cover pwm: support backward compatibility of DTB extending PWM args

Please review this alternative in-house version of supporting backward compatibility of DTB files, if pwms arguments of exisitng PWM drivers are to be extended with polarity field.

Unfortunately I've firstly created the change and only after that found that Lothar Wa?mann is working on his version, so I won't insist on formal preference, but still I like to share my variant since it technically different from Lothar's one.

One visual benefit of my verison is that if this version is accepted, then of_pwm_xlate_with_flags() can be removed from all touched PWM drivers and pwm/core.c as a redundant interface, chip.of_pwm_n_cells should not be updated also, and generally is looks to be a more simple change.

The particular changes in iMX PWM driver and other PWM drivers are out of this change scope.

Changes from v1 to v2:
- corrected the proper kernel log level, thanks to Lothar Wa?mann.

Vladimir Zapolskiy (3):
pwm: process pwm polarity argument in of_pwm_simple_xlate()
pwm: push up dynamic printk level on errors in of_pwm_get()
pwm: set the actual number of pwms arguments defined in board dts

 drivers/pwm/core.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.10.4
#7 lore raw

PATCH 1/3 pwm: process pwm polarity argument in of_pwm_simple_xlate()

In reply to Vladimir Zapolskiy

The third optional argument of pwms is well defined as polarity and it is already used in a number of pwm drivers, so, to minimize changes in the remaining drivers which are to be updated accordingly set polarity in default of_xlate() function.

Cc Lothar Wa?mann <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Shawn Guo <[email protected]>
---
 drivers/pwm/core.c |    7 +++++++
 1 file changed, 7 insertions(+)
drivers/pwm/core.c +7 -0
index 966497d..681d154 100644
@@ -174,6 +174,13 @@ of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
 
 	pwm_set_period(pwm, args->args[1]);
 
+	if (pc->of_pwm_n_cells > 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;
 }
 
Signature · 1 line
1.7.10.4
#8 lore raw

PATCH v2 2/3 pwm: push up dynamic printk level on errors in of_pwm_get()

In reply to Vladimir Zapolskiy

The changed three user messages on fault are printed under pr_debug(), however all of them are unrecoverable and result in failed pwm device registration, report this to a user.

Cc Lothar Wa?mann <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Shawn Guo <[email protected]>

---
Changes from v1 to v2:
- corrected the proper kernel log level, thanks to Lothar Wa?mann.

 drivers/pwm/core.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pwm/core.c +3 -3
index 681d154..f6231c6 100644
@@ -532,19 +532,19 @@ struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id)
 	err = of_parse_phandle_with_args(np, "pwms", "#pwm-cells", index,
 					 &args);
 	if (err) {
-		pr_debug("%s(): can't parse \"pwms\" property\n", __func__);
+		pr_err("%s(): can't parse \"pwms\" property\n", __func__);
 		return ERR_PTR(err);
 	}
 
 	pc = of_node_to_pwmchip(args.np);
 	if (IS_ERR(pc)) {
-		pr_debug("%s(): PWM chip not found\n", __func__);
+		pr_err("%s(): PWM chip not found\n", __func__);
 		pwm = ERR_CAST(pc);
 		goto put;
 	}
 
 	if (args.args_count != pc->of_pwm_n_cells) {
-		pr_debug("%s: wrong #pwm-cells for %s\n", np->full_name,
+		pr_err("%s: wrong #pwm-cells for %s\n", np->full_name,
 			 args.np->full_name);
 		pwm = ERR_PTR(-EINVAL);
 		goto put;
Signature · 1 line
1.7.10.4
#9 lore raw

PATCH v2 3/3 pwm: set the actual number of pwms arguments defined in board dts

In reply to Vladimir Zapolskiy

For backward compatibility board device tree has to define only a minimal amount of mandatory pwms arguments, which is specified by a driver. Additional arguments shall be considered as optional, update pc->of_pwm_n_cells according to the actual data taken from device tree file.

Cc Lothar Wa?mann <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Shawn Guo <[email protected]>

---
Changes from v1 to v2:
- rebased on top of modified patch v2 2/3

 drivers/pwm/core.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pwm/core.c +2 -1
index f6231c6..4d9fc7f 100644
@@ -543,12 +543,13 @@ 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) {
+	if (args.args_count < pc->of_pwm_n_cells) {
 		pr_err("%s: wrong #pwm-cells for %s\n", np->full_name,
 			 args.np->full_name);
 		pwm = ERR_PTR(-EINVAL);
 		goto put;
 	}
+	pc->of_pwm_n_cells = args.args_count;
 
 	pwm = pc->of_xlate(pc, &args);
 	if (IS_ERR(pwm))
Signature · 1 line
1.7.10.4