Commit dfbf9379 authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Thierry Reding

pwm: vt8500: Simplify using devm functions

With devm_clk_get_prepared() the call to clk_unprepare() can be dropped
from the error path and the remove callback. With devm_pwmchip_add()
pwmchip_remove() can be dropped. Then the remove callback is empty and
can go away, too. With vt8500_pwm_remove() the last user of
platform_get_drvdata() is gone and so platform_set_drvdata() can be
dropped, too.

Also use dev_err_probe() for simplified (and improved) error reporting.

Link: https://lore.kernel.org/r/20230929161918.2410424-10-u.kleine-koenig@pengutronix.deSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent 21c0e1aa
...@@ -235,10 +235,8 @@ static int vt8500_pwm_probe(struct platform_device *pdev) ...@@ -235,10 +235,8 @@ static int vt8500_pwm_probe(struct platform_device *pdev)
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
int ret; int ret;
if (!np) { if (!np)
dev_err(&pdev->dev, "invalid devicetree node\n"); return dev_err_probe(&pdev->dev, -EINVAL, "invalid devicetree node\n");
return -EINVAL;
}
vt8500 = devm_kzalloc(&pdev->dev, sizeof(*vt8500), GFP_KERNEL); vt8500 = devm_kzalloc(&pdev->dev, sizeof(*vt8500), GFP_KERNEL);
if (vt8500 == NULL) if (vt8500 == NULL)
...@@ -248,45 +246,23 @@ static int vt8500_pwm_probe(struct platform_device *pdev) ...@@ -248,45 +246,23 @@ static int vt8500_pwm_probe(struct platform_device *pdev)
vt8500->chip.ops = &vt8500_pwm_ops; vt8500->chip.ops = &vt8500_pwm_ops;
vt8500->chip.npwm = VT8500_NR_PWMS; vt8500->chip.npwm = VT8500_NR_PWMS;
vt8500->clk = devm_clk_get(&pdev->dev, NULL); vt8500->clk = devm_clk_get_prepared(&pdev->dev, NULL);
if (IS_ERR(vt8500->clk)) { if (IS_ERR(vt8500->clk))
dev_err(&pdev->dev, "clock source not specified\n"); return dev_err_probe(&pdev->dev, PTR_ERR(vt8500->clk), "clock source not specified\n");
return PTR_ERR(vt8500->clk);
}
vt8500->base = devm_platform_ioremap_resource(pdev, 0); vt8500->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(vt8500->base)) if (IS_ERR(vt8500->base))
return PTR_ERR(vt8500->base); return PTR_ERR(vt8500->base);
ret = clk_prepare(vt8500->clk); ret = devm_pwmchip_add(&pdev->dev, &vt8500->chip);
if (ret < 0) { if (ret < 0)
dev_err(&pdev->dev, "failed to prepare clock\n"); return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
return ret;
}
ret = pwmchip_add(&vt8500->chip);
if (ret < 0) {
dev_err(&pdev->dev, "failed to add PWM chip\n");
clk_unprepare(vt8500->clk);
return ret;
}
platform_set_drvdata(pdev, vt8500);
return ret;
}
static void vt8500_pwm_remove(struct platform_device *pdev)
{
struct vt8500_chip *vt8500 = platform_get_drvdata(pdev);
pwmchip_remove(&vt8500->chip);
clk_unprepare(vt8500->clk); return 0;
} }
static struct platform_driver vt8500_pwm_driver = { static struct platform_driver vt8500_pwm_driver = {
.probe = vt8500_pwm_probe, .probe = vt8500_pwm_probe,
.remove_new = vt8500_pwm_remove,
.driver = { .driver = {
.name = "vt8500-pwm", .name = "vt8500-pwm",
.of_match_table = vt8500_pwm_dt_ids, .of_match_table = vt8500_pwm_dt_ids,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment