aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2024-02-14 10:33:26 +0100
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>2024-02-22 14:39:29 +0100
commite0d32775716508942657cc5778bd881b40659287 (patch)
treef62df74cdd370bd730c85750ce76104c157f8174 /drivers/staging
parent1dd173fc96244d4b67f642cf90c29f21aa2b49b9 (diff)
downloadlinux-e0d32775716508942657cc5778bd881b40659287.tar.gz
staging: greybus: pwm: Rework how the number of PWM lines is determined
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. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://lore.kernel.org/r/3efd84ac03e7dc288f20b0de20b142b6404cb1fa.1707900770.git.u.kleine-koenig@pengutronix.de Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Diffstat (limited to 'drivers/staging')
-rw-r--r--drivers/staging/greybus/pwm.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/drivers/staging/greybus/pwm.c b/drivers/staging/greybus/pwm.c
index c7a2e874a62be3..35e98e7c00c1a4 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) {