diff mbox series

[v3,001/108] pwm: cros-ec: Change prototype of helper to prepare further changes

Message ID 20231121134901.208535-2-u.kleine-koenig@pengutronix.de (mailing list archive)
State Handled Elsewhere
Headers show
Series pwm: Fix lifetime issues for pwm_chips | expand

Commit Message

Uwe Kleine-König Nov. 21, 2023, 1:49 p.m. UTC
pwm_chip allocation and registration is about to change. For that the number
of PWM devices must be known earlier in cros_ec_pwm_probe(). So make
cros_ec_pwm_get_duty() independant from struct cros_ec_pwm_device which is only
available later.

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

Comments

Tzung-Bi Shih Nov. 22, 2023, 8:52 a.m. UTC | #1
On Tue, Nov 21, 2023 at 02:49:03PM +0100, Uwe Kleine-König wrote:
> @@ -233,7 +232,7 @@ static int cros_ec_num_pwms(struct cros_ec_pwm_device *ec_pwm)
>  
>  	/* The index field is only 8 bits */
>  	for (i = 0; i <= U8_MAX; i++) {
> -		ret = cros_ec_pwm_get_duty(ec_pwm, i);
> +		ret = cros_ec_pwm_get_duty(ec_pwm->ec, ec_pwm->use_pwm_type, i);

Or just pass false for `use_pwm_type` because the path:
cros_ec_pwm_probe()
-> !ec_pwm->use_pwm_type
-> cros_ec_num_pwms()

`ec_pwm->use_pwm_type` is always false here.
Uwe Kleine-König Nov. 23, 2023, 9:24 a.m. UTC | #2
On Wed, Nov 22, 2023 at 04:52:16PM +0800, Tzung-Bi Shih wrote:
> On Tue, Nov 21, 2023 at 02:49:03PM +0100, Uwe Kleine-König wrote:
> > @@ -233,7 +232,7 @@ static int cros_ec_num_pwms(struct cros_ec_pwm_device *ec_pwm)
> >  
> >  	/* The index field is only 8 bits */
> >  	for (i = 0; i <= U8_MAX; i++) {
> > -		ret = cros_ec_pwm_get_duty(ec_pwm, i);
> > +		ret = cros_ec_pwm_get_duty(ec_pwm->ec, ec_pwm->use_pwm_type, i);
> 
> Or just pass false for `use_pwm_type` because the path:
> cros_ec_pwm_probe()
> -> !ec_pwm->use_pwm_type
> -> cros_ec_num_pwms()
> 
> `ec_pwm->use_pwm_type` is always false here.

Good catch, that allows to simplify the patch that introduces
devm_pwmchip_alloc() to this driver.

Best regards
Uwe
diff mbox series

Patch

diff --git a/drivers/pwm/pwm-cros-ec.c b/drivers/pwm/pwm-cros-ec.c
index 9a8f1b6a4e13..7345ca1c60f0 100644
--- a/drivers/pwm/pwm-cros-ec.c
+++ b/drivers/pwm/pwm-cros-ec.c
@@ -94,9 +94,8 @@  static int cros_ec_pwm_set_duty(struct cros_ec_pwm_device *ec_pwm, u8 index,
 	return cros_ec_cmd_xfer_status(ec, msg);
 }
 
-static int cros_ec_pwm_get_duty(struct cros_ec_pwm_device *ec_pwm, u8 index)
+static int cros_ec_pwm_get_duty(struct cros_ec_device *ec, bool use_pwm_type, u8 index)
 {
-	struct cros_ec_device *ec = ec_pwm->ec;
 	struct {
 		struct cros_ec_command msg;
 		union {
@@ -116,7 +115,7 @@  static int cros_ec_pwm_get_duty(struct cros_ec_pwm_device *ec_pwm, u8 index)
 	msg->insize = sizeof(*resp);
 	msg->outsize = sizeof(*params);
 
-	if (ec_pwm->use_pwm_type) {
+	if (use_pwm_type) {
 		ret = cros_ec_dt_type_to_pwm_type(index, &params->pwm_type);
 		if (ret) {
 			dev_err(ec->dev, "Invalid PWM type index: %d\n", index);
@@ -172,7 +171,7 @@  static int cros_ec_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
 	struct cros_ec_pwm *channel = &ec_pwm->channel[pwm->hwpwm];
 	int ret;
 
-	ret = cros_ec_pwm_get_duty(ec_pwm, pwm->hwpwm);
+	ret = cros_ec_pwm_get_duty(ec_pwm->ec, ec_pwm->use_pwm_type, pwm->hwpwm);
 	if (ret < 0) {
 		dev_err(chip->dev, "error getting initial duty: %d\n", ret);
 		return ret;
@@ -233,7 +232,7 @@  static int cros_ec_num_pwms(struct cros_ec_pwm_device *ec_pwm)
 
 	/* The index field is only 8 bits */
 	for (i = 0; i <= U8_MAX; i++) {
-		ret = cros_ec_pwm_get_duty(ec_pwm, i);
+		ret = cros_ec_pwm_get_duty(ec_pwm->ec, ec_pwm->use_pwm_type, i);
 		/*
 		 * We look for SUCCESS, INVALID_COMMAND, or INVALID_PARAM
 		 * responses; everything else is treated as an error.