diff mbox series

[1/3] pwm: Add upgrade path to #pwm-cells = <3> for users of of_pwm_single_xlate()

Message ID 1829c1a040c707326d9c53aee3577763e2139d58.1738777221.git.u.kleine-koenig@baylibre.com (mailing list archive)
State New
Headers show
Series pwm: pxa: Use #pwm-cells = <3> | expand

Commit Message

Uwe Kleine-König Feb. 5, 2025, 5:54 p.m. UTC
The PWM chip on PXA only has a single output. Back when the device tree
binding was defined it was considered a good idea to not pass the PWM
line index as is done for all other PWM types as it would be always zero
anyhow and so doesn't add any value.

However for consistency reasons it is nice when all PWMs use the same
binding. For that reason let of_pwm_single_xlate() (i.e. the function
that implements the PXA behaviour) behave in the same way as
of_pwm_xlate_with_flags() for 3 (or more) parameters. With that in
place, the pxa-pwm binding can be updated to #pwm-cells = <3> without
breaking old device trees that stick to #pwm-cells = <1>.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
 drivers/pwm/core.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Herve Codina Feb. 5, 2025, 6:02 p.m. UTC | #1
On Wed,  5 Feb 2025 18:54:00 +0100
Uwe Kleine-König <u.kleine-koenig@baylibre.com> wrote:

> The PWM chip on PXA only has a single output. Back when the device tree
> binding was defined it was considered a good idea to not pass the PWM
> line index as is done for all other PWM types as it would be always zero
> anyhow and so doesn't add any value.
> 
> However for consistency reasons it is nice when all PWMs use the same
> binding. For that reason let of_pwm_single_xlate() (i.e. the function
> that implements the PXA behaviour) behave in the same way as
> of_pwm_xlate_with_flags() for 3 (or more) parameters. With that in
> place, the pxa-pwm binding can be updated to #pwm-cells = <3> without
> breaking old device trees that stick to #pwm-cells = <1>.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
> ---
>  drivers/pwm/core.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)

Reviewed-by: Herve Codina <herve.codina@bootlin.com>

Best regards,
Hervé
diff mbox series

Patch

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index ccd54c089bab..bc05818fa370 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -1000,11 +1000,27 @@  of_pwm_xlate_with_flags(struct pwm_chip *chip, const struct of_phandle_args *arg
 }
 EXPORT_SYMBOL_GPL(of_pwm_xlate_with_flags);
 
+/*
+ * This callback is used for PXA PWM chips that only have a single PWM line.
+ * For such chips you could argue that passing the line number (i.e. the first
+ * parameter in the common case) is useless as it's always zero. So compared to
+ * the default xlate function of_pwm_xlate_with_flags() the first parameter is
+ * the default period and the second are flags.
+ *
+ * Note that if #pwm-cells = <3>, the semantic is the same as for
+ * of_pwm_xlate_with_flags() to allow converting the affected driver to
+ * #pwm-cells = <3> without breaking the legacy binding.
+ *
+ * Don't use for new drivers.
+ */
 struct pwm_device *
 of_pwm_single_xlate(struct pwm_chip *chip, const struct of_phandle_args *args)
 {
 	struct pwm_device *pwm;
 
+	if (args->args_count >= 3)
+		return of_pwm_xlate_with_flags(chip, args);
+
 	pwm = pwm_request_from_chip(chip, 0, NULL);
 	if (IS_ERR(pwm))
 		return pwm;