提交 6c7dd64a 编写于 作者: H H Hartley Sweeten 提交者: Greg Kroah-Hartman

misc/ep93xx_pwm: use managed device resources

Use managed device resources to clean up the probe/remove.
Signed-off-by: NH Hartley Sweeten <hsweeten@visionengravers.com>
Acked-by: NArnd Bergmann <arnd@arndb.de>
Reviewed-by: NRyan Mallon <rmallon@gmail.com>
Cc: Matthieu Crapet <mcrapet@gmail.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 01fe7b43
......@@ -273,50 +273,33 @@ static int __init ep93xx_pwm_probe(struct platform_device *pdev)
{
struct ep93xx_pwm *pwm;
struct resource *res;
int err;
int ret;
err = ep93xx_pwm_acquire_gpio(pdev);
if (err)
return err;
pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
if (!pwm)
return -ENOMEM;
pwm = kzalloc(sizeof(struct ep93xx_pwm), GFP_KERNEL);
if (!pwm) {
err = -ENOMEM;
goto fail_no_mem;
}
pwm->clk = devm_clk_get(&pdev->dev, "pwm_clk");
if (IS_ERR(pwm->clk))
return PTR_ERR(pwm->clk);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) {
err = -ENXIO;
goto fail_no_mem_resource;
}
res = request_mem_region(res->start, resource_size(res), pdev->name);
if (res == NULL) {
err = -EBUSY;
goto fail_no_mem_resource;
}
pwm->mmio_base = ioremap(res->start, resource_size(res));
if (pwm->mmio_base == NULL) {
err = -ENXIO;
goto fail_no_ioremap;
}
err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_pwm_sysfs_files);
if (err)
goto fail_no_sysfs;
pwm->clk = clk_get(&pdev->dev, "pwm_clk");
if (IS_ERR(pwm->clk)) {
err = PTR_ERR(pwm->clk);
goto fail_no_clk;
pwm->mmio_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(pwm->mmio_base))
return PTR_ERR(pwm->mmio_base);
ret = ep93xx_pwm_acquire_gpio(pdev);
if (ret)
return ret;
ret = sysfs_create_group(&pdev->dev.kobj, &ep93xx_pwm_sysfs_files);
if (ret) {
ep93xx_pwm_release_gpio(pdev);
return ret;
}
pwm->duty_percent = 50;
platform_set_drvdata(pdev, pwm);
/* disable pwm at startup. Avoids zero value. */
ep93xx_pwm_disable(pwm);
ep93xx_pwm_write_tc(pwm, EP93XX_PWM_MAX_COUNT);
......@@ -324,33 +307,17 @@ static int __init ep93xx_pwm_probe(struct platform_device *pdev)
clk_enable(pwm->clk);
platform_set_drvdata(pdev, pwm);
return 0;
fail_no_clk:
sysfs_remove_group(&pdev->dev.kobj, &ep93xx_pwm_sysfs_files);
fail_no_sysfs:
iounmap(pwm->mmio_base);
fail_no_ioremap:
release_mem_region(res->start, resource_size(res));
fail_no_mem_resource:
kfree(pwm);
fail_no_mem:
ep93xx_pwm_release_gpio(pdev);
return err;
}
static int __exit ep93xx_pwm_remove(struct platform_device *pdev)
{
struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
ep93xx_pwm_disable(pwm);
clk_disable(pwm->clk);
clk_put(pwm->clk);
sysfs_remove_group(&pdev->dev.kobj, &ep93xx_pwm_sysfs_files);
iounmap(pwm->mmio_base);
release_mem_region(res->start, resource_size(res));
kfree(pwm);
ep93xx_pwm_release_gpio(pdev);
return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册