All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Thierry Reding <thierry.reding@gmail.com>,
	Lee Jones <lee.jones@linaro.org>
Cc: linux-pwm@vger.kernel.org, kernel@pengutronix.de
Subject: [PATCH v2 3/4] pwm: Autodetect default value for of_pwm_n_cells from device tree
Date: Mon, 10 May 2021 16:06:39 +0200	[thread overview]
Message-ID: <20210510140640.980100-4-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20210510140640.980100-1-u.kleine-koenig@pengutronix.de>

This allows to simplify all drivers that use three pwm-cells.
The only ugly side effect is that if a driver specified of_pwm_n_cells = 2
it suddenly supports device trees that use #pwm-cells = <3>. This however
isn't a bad thing because the driver doesn't need explicit support for
three cells as the core handles all the details. Also there is no such
in-tree driver.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/pwm/core.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 9eb7ab19dbfb..33cf05a47770 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -159,8 +159,14 @@ static void of_pwmchip_add(struct pwm_chip *chip)
 		return;
 
 	if (!chip->of_xlate) {
+		u32 pwm_cells;
+
+		if (of_property_read_u32(chip->dev->of_node, "#pwm-cells",
+					 &pwm_cells))
+			pwm_cells = 2;
+
 		chip->of_xlate = of_pwm_xlate_with_flags;
-		chip->of_pwm_n_cells = 2;
+		chip->of_pwm_n_cells = pwm_cells;
 	}
 
 	of_node_get(chip->dev->of_node);
-- 
2.30.2


  parent reply	other threads:[~2021-05-10 14:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-10 14:06 [PATCH v2 0/4] pwm: Simplify drivers with of_pwm_n_cells = 3 Uwe Kleine-König
2021-05-10 14:06 ` [PATCH v2 1/4] pwm: Make of_pwm_xlate_with_flags() work with #pwm-cells = <2> Uwe Kleine-König
2021-05-10 14:06 ` [PATCH v2 2/4] pwm: Drop of_pwm_simple_xlate() in favour of of_pwm_xlate_with_flags() Uwe Kleine-König
2021-05-10 14:06 ` Uwe Kleine-König [this message]
2021-05-10 14:06 ` [PATCH v2 4/4] pwm: Simplify all drivers with explicit of_pwm_n_cells = 3 Uwe Kleine-König
2021-05-10 14:48 ` [PATCH v2 0/4] pwm: Simplify drivers with " Uwe Kleine-König
  -- strict thread matches above, loose matches on Subject: below --
2021-04-24 21:07 Uwe Kleine-König
2021-04-24 21:07 ` [PATCH v2 3/4] pwm: Autodetect default value for of_pwm_n_cells from device tree Uwe Kleine-König

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=20210510140640.980100-4-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=kernel@pengutronix.de \
    --cc=lee.jones@linaro.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=thierry.reding@gmail.com \
    /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.