On 1/25/24 6:10 AM, Uwe Kleine-König wrote:
This prepares the greybus pwm driver to further changes of the pwm core outlined in the commit introducing devm_pwmchip_alloc(). There is no intended semantical change and the driver should behave as before. Acked-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxxxx>
I think you are changing more than you need to in this code.
--- drivers/staging/greybus/pwm.c | 75 ++++++++++------------------------- 1 file changed, 20 insertions(+), 55 deletions(-) diff --git a/drivers/staging/greybus/pwm.c b/drivers/staging/greybus/pwm.c index 75e0518791d8..a90f41c374dc 100644 --- a/drivers/staging/greybus/pwm.c +++ b/drivers/staging/greybus/pwm.c @@ -16,26 +16,11 @@struct gb_pwm_chip {struct gb_connection *connection; - u8 pwm_max; /* max pwm number */ - struct pwm_chip chip; };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);
Now I understand why you were changing the type of the argument passed to all those functions. I still don't think you need to do that though.
-} - -static int gb_pwm_count_operation(struct gb_pwm_chip *pwmc)
This function logically isolates doing the operation from the rest of the code. I'd rather you not get rid of it.
-{ - struct gb_pwm_count_response response; - int ret; - - ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_PWM_COUNT, - NULL, 0, &response, sizeof(response)); - if (ret) - return ret; - pwmc->pwm_max = response.count; - return 0; + return pwmchip_get_drvdata(chip); }static int gb_pwm_activate_operation(struct pwm_chip *chip, u8 which)@@ -45,9 +30,6 @@ static int gb_pwm_activate_operation(struct pwm_chip *chip, u8 which) struct gbphy_device *gbphy_dev; int ret;- if (which > pwmc->pwm_max)- return -EINVAL; - request.which = which;gbphy_dev = to_gbphy_dev(pwmchip_parent(chip));@@ -71,9 +53,6 @@ static int gb_pwm_deactivate_operation(struct pwm_chip *chip, struct gbphy_device *gbphy_dev; int ret;- if (which > pwmc->pwm_max)- return -EINVAL; - request.which = which;gbphy_dev = to_gbphy_dev(pwmchip_parent(chip));@@ -97,9 +76,6 @@ static int gb_pwm_config_operation(struct pwm_chip *chip, struct gbphy_device *gbphy_dev; int ret;- if (which > pwmc->pwm_max)- return -EINVAL; - request.which = which; request.duty = cpu_to_le32(duty); request.period = cpu_to_le32(period); @@ -125,9 +101,6 @@ static int gb_pwm_set_polarity_operation(struct pwm_chip *chip, struct gbphy_device *gbphy_dev; int ret;- if (which > pwmc->pwm_max)- return -EINVAL; - request.which = which; request.polarity = polarity;@@ -151,9 +124,6 @@ static int gb_pwm_enable_operation(struct pwm_chip *chip, u8 which)struct gbphy_device *gbphy_dev; int ret;- if (which > pwmc->pwm_max)- return -EINVAL; - request.which = which;gbphy_dev = to_gbphy_dev(pwmchip_parent(chip));@@ -176,9 +146,6 @@ static int gb_pwm_disable_operation(struct pwm_chip *chip, u8 which) struct gbphy_device *gbphy_dev; int ret;- if (which > pwmc->pwm_max)- return -EINVAL; - request.which = which;ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_DISABLE,@@ -263,38 +230,37 @@ static int gb_pwm_probe(struct gbphy_device *gbphy_dev, struct gb_connection *connection; struct gb_pwm_chip *pwmc; struct pwm_chip *chip; + struct gb_pwm_count_response response; int ret;- pwmc = kzalloc(sizeof(*pwmc), GFP_KERNEL);- if (!pwmc) - return -ENOMEM; - connection = gb_connection_create(gbphy_dev->bundle, le16_to_cpu(gbphy_dev->cport_desc->id), NULL); - if (IS_ERR(connection)) { - ret = PTR_ERR(connection); - goto exit_pwmc_free; + if (IS_ERR(connection)) + return PTR_ERR(connection);
This is actually a bug fix that should probably be done separately, prior to this series.
+ + ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_PWM_COUNT, + NULL, 0, &response, sizeof(response)); + if (ret) + goto exit_connection_destroy;
You didn't mention in your header that you were getting rid of gb_pwm_count_operation(), and as I said above, I don't think you should. Just keep the existing code as it was and focus only on your conversion to attaching driver data to the PWM chip structure.
+ + chip = devm_pwmchip_alloc(&gbphy_dev->dev, response.count, sizeof(*pwmc)); + if (IS_ERR(chip)) { + ret = PTR_ERR(chip); + goto exit_connection_destroy; }+ pwmc = pwm_chip_to_gb_pwm_chip(chip);pwmc->connection = connection; + gb_connection_set_data(connection, pwmc); - gb_gbphy_set_data(gbphy_dev, pwmc); + gb_gbphy_set_data(gbphy_dev, chip);
I'm pretty sure driver data should still be the Greybus structure, otherwise you're really changing the way this works (most likely in a way that's different from other Greybus drivers.
ret = gb_connection_enable(connection);if (ret) goto exit_connection_destroy;- /* Query number of pwms present */- ret = gb_pwm_count_operation(pwmc); - if (ret) - goto exit_connection_disable; - - chip = &pwmc->chip; - - chip->dev = &gbphy_dev->dev; chip->ops = &gb_pwm_ops; - chip->npwm = pwmc->pwm_max + 1;ret = pwmchip_add(chip);if (ret) { @@ -310,14 +276,13 @@ static int gb_pwm_probe(struct gbphy_device *gbphy_dev, gb_connection_disable(connection); exit_connection_destroy: gb_connection_destroy(connection); -exit_pwmc_free: - kfree(pwmc); return ret; }static void gb_pwm_remove(struct gbphy_device *gbphy_dev){ - struct gb_pwm_chip *pwmc = gb_gbphy_get_data(gbphy_dev); + struct pwm_chip *chip = gb_gbphy_get_data(gbphy_dev); + struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); struct gb_connection *connection = pwmc->connection; int ret;@@ -325,7 +290,7 @@ static void gb_pwm_remove(struct gbphy_device *gbphy_dev)if (ret) gbphy_runtime_get_noresume(gbphy_dev);- pwmchip_remove(&pwmc->chip);+ pwmchip_remove(chip); gb_connection_disable(connection); gb_connection_destroy(connection); kfree(pwmc);
_______________________________________________ greybus-dev mailing list -- greybus-dev@xxxxxxxxxxxxxxxx To unsubscribe send an email to greybus-dev-leave@xxxxxxxxxxxxxxxx