Linux kernel staging patches
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: linux-pwm@vger.kernel.org, Johan Hovold <johan@kernel.org>,
	Alex Elder <elder@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev,
	kernel@pengutronix.de
Subject: [PATCH v6 159/164] staging: greybus: pwm: Rework how the number of PWM lines is determined
Date: Wed, 14 Feb 2024 10:33:26 +0100	[thread overview]
Message-ID: <3efd84ac03e7dc288f20b0de20b142b6404cb1fa.1707900770.git.u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <cover.1707900770.git.u.kleine-koenig@pengutronix.de>

With a later patch it becomes necessary to already now the number of PWM
lines when pwmc is allocated. So make the function not use pwmc but a
plain connection and return the number of lines instead of storing it in
pwmc. This allows to get rid of the pwm_max member.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/staging/greybus/pwm.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/greybus/pwm.c b/drivers/staging/greybus/pwm.c
index c7a2e874a62b..35e98e7c00c1 100644
--- a/drivers/staging/greybus/pwm.c
+++ b/drivers/staging/greybus/pwm.c
@@ -16,8 +16,6 @@
 
 struct gb_pwm_chip {
 	struct gb_connection	*connection;
-	u8			pwm_max;	/* max pwm number */
-
 	struct pwm_chip		chip;
 };
 
@@ -26,17 +24,21 @@ static inline struct gb_pwm_chip *pwm_chip_to_gb_pwm_chip(struct pwm_chip *chip)
 	return container_of(chip, struct gb_pwm_chip, chip);
 }
 
-static int gb_pwm_count_operation(struct gb_pwm_chip *pwmc)
+static int gb_pwm_get_npwm(struct gb_connection *connection)
 {
 	struct gb_pwm_count_response response;
 	int ret;
 
-	ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_PWM_COUNT,
+	ret = gb_operation_sync(connection, GB_PWM_TYPE_PWM_COUNT,
 				NULL, 0, &response, sizeof(response));
 	if (ret)
 		return ret;
-	pwmc->pwm_max = response.count;
-	return 0;
+
+	/*
+	 * The request returns the highest allowed PWM id parameter. So add one
+	 * to get the number of PWMs.
+	 */
+	return response.count + 1;
 }
 
 static int gb_pwm_activate_operation(struct pwm_chip *chip, u8 which)
@@ -245,7 +247,7 @@ static int gb_pwm_probe(struct gbphy_device *gbphy_dev,
 	struct gb_connection *connection;
 	struct gb_pwm_chip *pwmc;
 	struct pwm_chip *chip;
-	int ret;
+	int ret, npwm;
 
 	pwmc = kzalloc(sizeof(*pwmc), GFP_KERNEL);
 	if (!pwmc)
@@ -267,15 +269,16 @@ static int gb_pwm_probe(struct gbphy_device *gbphy_dev,
 		goto exit_connection_destroy;
 
 	/* Query number of pwms present */
-	ret = gb_pwm_count_operation(pwmc);
-	if (ret)
+	ret = gb_pwm_get_npwm(connection);
+	if (ret < 0)
 		goto exit_connection_disable;
+	npwm = ret;
 
 	chip = &pwmc->chip;
 
 	chip->dev = &gbphy_dev->dev;
 	chip->ops = &gb_pwm_ops;
-	chip->npwm = pwmc->pwm_max + 1;
+	chip->npwm = npwm;
 
 	ret = pwmchip_add(chip);
 	if (ret) {
-- 
2.43.0


  parent reply	other threads:[~2024-02-14  9:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-14  9:30 [PATCH v6 000/164] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
2024-02-14  9:30 ` [PATCH v6 001/164] pwm: Provide an inline function to get the parent device of a given chip Uwe Kleine-König
2024-02-14 10:39   ` Greg Kroah-Hartman
2024-02-14  9:33 ` [PATCH v6 155/164] staging: greybus: pwm: Change prototype of helpers to prepare further changes Uwe Kleine-König
2024-02-14 10:40   ` Greg Kroah-Hartman
2024-02-14  9:33 ` [PATCH v6 156/164] staging: greybus: pwm: Make use of pwmchip_parent() accessor Uwe Kleine-König
2024-02-14 10:40   ` Greg Kroah-Hartman
2024-02-14  9:33 ` [PATCH v6 157/164] staging: greybus: pwm: Rely on pwm framework to pass a valid hwpwm Uwe Kleine-König
2024-02-14 10:40   ` Greg Kroah-Hartman
2024-02-14  9:33 ` [PATCH v6 158/164] staging: greybus: pwm: Drop unused gb_connection_set_data() Uwe Kleine-König
2024-02-14 10:40   ` Greg Kroah-Hartman
2024-02-14  9:33 ` Uwe Kleine-König [this message]
2024-02-14 10:40   ` [PATCH v6 159/164] staging: greybus: pwm: Rework how the number of PWM lines is determined Greg Kroah-Hartman
2024-02-14  9:33 ` [PATCH v6 160/164] staging: greybus: pwm: Make use of devm_pwmchip_alloc() function Uwe Kleine-König
2024-02-14 10:41   ` Greg Kroah-Hartman
2024-02-15 11:46 ` [PATCH v6 000/164] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
2024-03-25  1:54 ` patchwork-bot+chrome-platform
2024-03-25  2:13 ` patchwork-bot+chrome-platform

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=3efd84ac03e7dc288f20b0de20b142b6404cb1fa.1707900770.git.u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=elder@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=greybus-dev@lists.linaro.org \
    --cc=johan@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).