Skip to content

Commit e0d3277

Browse files
author
Uwe Kleine-König
committed
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 <[email protected]> Link: https://lore.kernel.org/r/3efd84ac03e7dc288f20b0de20b142b6404cb1fa.1707900770.git.u.kleine-koenig@pengutronix.de Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent 1dd173f commit e0d3277

File tree

1 file changed

+13
-10
lines changed
  • drivers/staging/greybus

1 file changed

+13
-10
lines changed

drivers/staging/greybus/pwm.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
struct gb_pwm_chip {
1818
struct gb_connection *connection;
19-
u8 pwm_max; /* max pwm number */
20-
2119
struct pwm_chip chip;
2220
};
2321

@@ -26,17 +24,21 @@ static inline struct gb_pwm_chip *pwm_chip_to_gb_pwm_chip(struct pwm_chip *chip)
2624
return container_of(chip, struct gb_pwm_chip, chip);
2725
}
2826

29-
static int gb_pwm_count_operation(struct gb_pwm_chip *pwmc)
27+
static int gb_pwm_get_npwm(struct gb_connection *connection)
3028
{
3129
struct gb_pwm_count_response response;
3230
int ret;
3331

34-
ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_PWM_COUNT,
32+
ret = gb_operation_sync(connection, GB_PWM_TYPE_PWM_COUNT,
3533
NULL, 0, &response, sizeof(response));
3634
if (ret)
3735
return ret;
38-
pwmc->pwm_max = response.count;
39-
return 0;
36+
37+
/*
38+
* The request returns the highest allowed PWM id parameter. So add one
39+
* to get the number of PWMs.
40+
*/
41+
return response.count + 1;
4042
}
4143

4244
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,
245247
struct gb_connection *connection;
246248
struct gb_pwm_chip *pwmc;
247249
struct pwm_chip *chip;
248-
int ret;
250+
int ret, npwm;
249251

250252
pwmc = kzalloc(sizeof(*pwmc), GFP_KERNEL);
251253
if (!pwmc)
@@ -267,15 +269,16 @@ static int gb_pwm_probe(struct gbphy_device *gbphy_dev,
267269
goto exit_connection_destroy;
268270

269271
/* Query number of pwms present */
270-
ret = gb_pwm_count_operation(pwmc);
271-
if (ret)
272+
ret = gb_pwm_get_npwm(connection);
273+
if (ret < 0)
272274
goto exit_connection_disable;
275+
npwm = ret;
273276

274277
chip = &pwmc->chip;
275278

276279
chip->dev = &gbphy_dev->dev;
277280
chip->ops = &gb_pwm_ops;
278-
chip->npwm = pwmc->pwm_max + 1;
281+
chip->npwm = npwm;
279282

280283
ret = pwmchip_add(chip);
281284
if (ret) {

0 commit comments

Comments
 (0)