Commit 6d91a51a authored by Sylwester Nawrocki's avatar Sylwester Nawrocki Committed by Mauro Carvalho Chehab

[media] s5p-fimc: Convert to the device managed resources

The devm_* functions are used in the platform device probe() for data
that is freed on driver removal. The managed device layer takes care
of undoing actions taken in the probe callback() and freeing resources
on driver detach. This eliminates the need for manually releasing
resources and simplifies error handling.
Signed-off-by: default avatarSylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 2def9946
...@@ -1678,8 +1678,6 @@ static int fimc_probe(struct platform_device *pdev) ...@@ -1678,8 +1678,6 @@ static int fimc_probe(struct platform_device *pdev)
struct s5p_platform_fimc *pdata; struct s5p_platform_fimc *pdata;
int ret = 0; int ret = 0;
dev_dbg(&pdev->dev, "%s():\n", __func__);
drv_data = (struct samsung_fimc_driverdata *) drv_data = (struct samsung_fimc_driverdata *)
platform_get_device_id(pdev)->driver_data; platform_get_device_id(pdev)->driver_data;
...@@ -1689,7 +1687,7 @@ static int fimc_probe(struct platform_device *pdev) ...@@ -1689,7 +1687,7 @@ static int fimc_probe(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
fimc = kzalloc(sizeof(struct fimc_dev), GFP_KERNEL); fimc = devm_kzalloc(&pdev->dev, sizeof(*fimc), GFP_KERNEL);
if (!fimc) if (!fimc)
return -ENOMEM; return -ENOMEM;
...@@ -1700,51 +1698,35 @@ static int fimc_probe(struct platform_device *pdev) ...@@ -1700,51 +1698,35 @@ static int fimc_probe(struct platform_device *pdev)
pdata = pdev->dev.platform_data; pdata = pdev->dev.platform_data;
fimc->pdata = pdata; fimc->pdata = pdata;
init_waitqueue_head(&fimc->irq_queue); init_waitqueue_head(&fimc->irq_queue);
spin_lock_init(&fimc->slock); spin_lock_init(&fimc->slock);
mutex_init(&fimc->lock); mutex_init(&fimc->lock);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) { fimc->regs = devm_request_and_ioremap(&pdev->dev, res);
dev_err(&pdev->dev, "failed to find the registers\n"); if (fimc->regs == NULL) {
ret = -ENOENT; dev_err(&pdev->dev, "Failed to obtain io memory\n");
goto err_info; return -ENOENT;
}
fimc->regs_res = request_mem_region(res->start, resource_size(res),
dev_name(&pdev->dev));
if (!fimc->regs_res) {
dev_err(&pdev->dev, "failed to obtain register region\n");
ret = -ENOENT;
goto err_info;
}
fimc->regs = ioremap(res->start, resource_size(res));
if (!fimc->regs) {
dev_err(&pdev->dev, "failed to map registers\n");
ret = -ENXIO;
goto err_req_region;
} }
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (!res) { if (res == NULL) {
dev_err(&pdev->dev, "failed to get IRQ resource\n"); dev_err(&pdev->dev, "Failed to get IRQ resource\n");
ret = -ENXIO; return -ENXIO;
goto err_regs_unmap;
} }
fimc->irq = res->start; fimc->irq = res->start;
fimc->num_clocks = MAX_FIMC_CLOCKS; fimc->num_clocks = MAX_FIMC_CLOCKS;
ret = fimc_clk_get(fimc); ret = fimc_clk_get(fimc);
if (ret) if (ret)
goto err_regs_unmap; return ret;
clk_set_rate(fimc->clock[CLK_BUS], drv_data->lclk_frequency); clk_set_rate(fimc->clock[CLK_BUS], drv_data->lclk_frequency);
clk_enable(fimc->clock[CLK_BUS]); clk_enable(fimc->clock[CLK_BUS]);
platform_set_drvdata(pdev, fimc); platform_set_drvdata(pdev, fimc);
ret = request_irq(fimc->irq, fimc_irq_handler, 0, pdev->name, fimc); ret = devm_request_irq(&pdev->dev, fimc->irq, fimc_irq_handler,
0, pdev->name, fimc);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to install irq (%d)\n", ret); dev_err(&pdev->dev, "failed to install irq (%d)\n", ret);
goto err_clk; goto err_clk;
...@@ -1753,7 +1735,7 @@ static int fimc_probe(struct platform_device *pdev) ...@@ -1753,7 +1735,7 @@ static int fimc_probe(struct platform_device *pdev)
pm_runtime_enable(&pdev->dev); pm_runtime_enable(&pdev->dev);
ret = pm_runtime_get_sync(&pdev->dev); ret = pm_runtime_get_sync(&pdev->dev);
if (ret < 0) if (ret < 0)
goto err_irq; goto err_clk;
/* Initialize contiguous memory allocator */ /* Initialize contiguous memory allocator */
fimc->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); fimc->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
if (IS_ERR(fimc->alloc_ctx)) { if (IS_ERR(fimc->alloc_ctx)) {
...@@ -1768,17 +1750,8 @@ static int fimc_probe(struct platform_device *pdev) ...@@ -1768,17 +1750,8 @@ static int fimc_probe(struct platform_device *pdev)
err_pm: err_pm:
pm_runtime_put(&pdev->dev); pm_runtime_put(&pdev->dev);
err_irq:
free_irq(fimc->irq, fimc);
err_clk: err_clk:
fimc_clk_put(fimc); fimc_clk_put(fimc);
err_regs_unmap:
iounmap(fimc->regs);
err_req_region:
release_resource(fimc->regs_res);
kfree(fimc->regs_res);
err_info:
kfree(fimc);
return ret; return ret;
} }
...@@ -1865,11 +1838,6 @@ static int __devexit fimc_remove(struct platform_device *pdev) ...@@ -1865,11 +1838,6 @@ static int __devexit fimc_remove(struct platform_device *pdev)
clk_disable(fimc->clock[CLK_BUS]); clk_disable(fimc->clock[CLK_BUS]);
fimc_clk_put(fimc); fimc_clk_put(fimc);
free_irq(fimc->irq, fimc);
iounmap(fimc->regs);
release_resource(fimc->regs_res);
kfree(fimc->regs_res);
kfree(fimc);
dev_info(&pdev->dev, "driver unloaded\n"); dev_info(&pdev->dev, "driver unloaded\n");
return 0; return 0;
......
...@@ -434,7 +434,6 @@ struct fimc_ctx; ...@@ -434,7 +434,6 @@ struct fimc_ctx;
* @num_clocks: the number of clocks managed by this device instance * @num_clocks: the number of clocks managed by this device instance
* @clock: clocks required for FIMC operation * @clock: clocks required for FIMC operation
* @regs: the mapped hardware registers * @regs: the mapped hardware registers
* @regs_res: the resource claimed for IO registers
* @irq: FIMC interrupt number * @irq: FIMC interrupt number
* @irq_queue: interrupt handler waitqueue * @irq_queue: interrupt handler waitqueue
* @v4l2_dev: root v4l2_device * @v4l2_dev: root v4l2_device
...@@ -454,7 +453,6 @@ struct fimc_dev { ...@@ -454,7 +453,6 @@ struct fimc_dev {
u16 num_clocks; u16 num_clocks;
struct clk *clock[MAX_FIMC_CLOCKS]; struct clk *clock[MAX_FIMC_CLOCKS];
void __iomem *regs; void __iomem *regs;
struct resource *regs_res;
int irq; int irq;
wait_queue_head_t irq_queue; wait_queue_head_t irq_queue;
struct v4l2_device *v4l2_dev; struct v4l2_device *v4l2_dev;
......
...@@ -753,7 +753,7 @@ static int __devinit fimc_md_probe(struct platform_device *pdev) ...@@ -753,7 +753,7 @@ static int __devinit fimc_md_probe(struct platform_device *pdev)
struct fimc_md *fmd; struct fimc_md *fmd;
int ret; int ret;
fmd = kzalloc(sizeof(struct fimc_md), GFP_KERNEL); fmd = devm_kzalloc(&pdev->dev, sizeof(*fmd), GFP_KERNEL);
if (!fmd) if (!fmd)
return -ENOMEM; return -ENOMEM;
...@@ -774,7 +774,7 @@ static int __devinit fimc_md_probe(struct platform_device *pdev) ...@@ -774,7 +774,7 @@ static int __devinit fimc_md_probe(struct platform_device *pdev)
ret = v4l2_device_register(&pdev->dev, &fmd->v4l2_dev); ret = v4l2_device_register(&pdev->dev, &fmd->v4l2_dev);
if (ret < 0) { if (ret < 0) {
v4l2_err(v4l2_dev, "Failed to register v4l2_device: %d\n", ret); v4l2_err(v4l2_dev, "Failed to register v4l2_device: %d\n", ret);
goto err1; return ret;
} }
ret = media_device_register(&fmd->media_dev); ret = media_device_register(&fmd->media_dev);
if (ret < 0) { if (ret < 0) {
...@@ -816,8 +816,6 @@ static int __devinit fimc_md_probe(struct platform_device *pdev) ...@@ -816,8 +816,6 @@ static int __devinit fimc_md_probe(struct platform_device *pdev)
fimc_md_unregister_entities(fmd); fimc_md_unregister_entities(fmd);
err2: err2:
v4l2_device_unregister(&fmd->v4l2_dev); v4l2_device_unregister(&fmd->v4l2_dev);
err1:
kfree(fmd);
return ret; return ret;
} }
...@@ -831,7 +829,6 @@ static int __devexit fimc_md_remove(struct platform_device *pdev) ...@@ -831,7 +829,6 @@ static int __devexit fimc_md_remove(struct platform_device *pdev)
fimc_md_unregister_entities(fmd); fimc_md_unregister_entities(fmd);
media_device_unregister(&fmd->media_dev); media_device_unregister(&fmd->media_dev);
fimc_md_put_clocks(fmd); fimc_md_put_clocks(fmd);
kfree(fmd);
return 0; return 0;
} }
......
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