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>
Cc: linux-pwm@vger.kernel.org, kernel@pengutronix.de
Subject: [PATCH 3/5] pwm: Let the of_xlate callbacks accept references without period
Date: Tue,  9 Jan 2024 22:34:33 +0100	[thread overview]
Message-ID: <127622315d07d9d419ae8e6373c7e5be7fab7a62.1704835845.git.u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <cover.1704835845.git.u.kleine-koenig@pengutronix.de>

With this extension of_pwm_xlate_with_flags() is suitable to replace the
custom xlate function of the pwm-clps711x driver.

While touching these very similar functions align their implementations.

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

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 31f210872a07..606d9ef0c709 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -107,8 +107,8 @@ of_pwm_xlate_with_flags(struct pwm_chip *chip, const struct of_phandle_args *arg
 {
 	struct pwm_device *pwm;
 
-	/* flags in the third cell are optional */
-	if (args->args_count < 2)
+	/* period in the second cell and flags in the third cell are optional */
+	if (args->args_count < 1)
 		return ERR_PTR(-EINVAL);
 
 	if (args->args[0] >= chip->npwm)
@@ -118,9 +118,10 @@ of_pwm_xlate_with_flags(struct pwm_chip *chip, const struct of_phandle_args *arg
 	if (IS_ERR(pwm))
 		return pwm;
 
-	pwm->args.period = args->args[1];
-	pwm->args.polarity = PWM_POLARITY_NORMAL;
+	if (args->args_count > 1)
+		pwm->args.period = args->args[1];
 
+	pwm->args.polarity = PWM_POLARITY_NORMAL;
 	if (args->args_count > 2 && args->args[2] & PWM_POLARITY_INVERTED)
 		pwm->args.polarity = PWM_POLARITY_INVERSED;
 
@@ -133,18 +134,15 @@ of_pwm_single_xlate(struct pwm_chip *chip, const struct of_phandle_args *args)
 {
 	struct pwm_device *pwm;
 
-	/* validate that one cell is specified, optionally with flags */
-	if (args->args_count != 1 && args->args_count != 2)
-		return ERR_PTR(-EINVAL);
-
 	pwm = pwm_request_from_chip(chip, 0, NULL);
 	if (IS_ERR(pwm))
 		return pwm;
 
-	pwm->args.period = args->args[0];
-	pwm->args.polarity = PWM_POLARITY_NORMAL;
+	if (args->args_count > 1)
+		pwm->args.period = args->args[0];
 
-	if (args->args_count == 2 && args->args[1] & PWM_POLARITY_INVERTED)
+	pwm->args.polarity = PWM_POLARITY_NORMAL;
+	if (args->args_count > 1 && args->args[1] & PWM_POLARITY_INVERTED)
 		pwm->args.polarity = PWM_POLARITY_INVERSED;
 
 	return pwm;
-- 
2.43.0


  parent reply	other threads:[~2024-01-09 21:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-09 21:34 [PATCH 0/5] pwm: Some improvements around .of_xlate() Uwe Kleine-König
2024-01-09 21:34 ` Uwe Kleine-König
2024-01-09 21:34 ` Uwe Kleine-König
2024-01-09 21:34 ` [PATCH 1/5] pwm: Fix out-of-bounds access in of_pwm_single_xlate() Uwe Kleine-König
2024-01-13  8:30   ` Uwe Kleine-König
2024-01-09 21:34 ` [PATCH 2/5] pwm: Drop useless member .of_pwm_n_cells of struct pwm_chip Uwe Kleine-König
2024-01-09 21:34   ` Uwe Kleine-König
2024-01-09 21:34   ` Uwe Kleine-König
2024-01-10  0:14   ` Doug Anderson
2024-01-10  0:14     ` Doug Anderson
2024-01-10  0:14     ` Doug Anderson
2024-01-09 21:34 ` Uwe Kleine-König [this message]
2024-01-09 21:34 ` [PATCH 4/5] pwm: clps711x: Drop custom .of_xlate() callback Uwe Kleine-König
2024-01-09 21:34   ` Uwe Kleine-König
2024-01-09 21:34 ` [PATCH 5/5] pwm: Drop duplicate check against chip->npwm in of_pwm_xlate_with_flags() Uwe Kleine-König
2024-01-24  8:43 ` [PATCH 0/5] pwm: Some improvements around .of_xlate() Uwe Kleine-König
2024-01-24  8:43   ` Uwe Kleine-König
2024-01-24  8:43   ` 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=127622315d07d9d419ae8e6373c7e5be7fab7a62.1704835845.git.u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=kernel@pengutronix.de \
    --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.