提交 dae7aa8d 编写于 作者: P Pramod Gurav 提交者: Dmitry Torokhov

Input: lpc32xx-keys - switch to using managed resources

This change switches to using devm_* managed resources APIs to
request the resources in probe to simplify probe error path and
module unloading.
Signed-off-by: NPramod Gurav <pramod.gurav@smartplayin.com>
Signed-off-by: NDmitry Torokhov <dmitry.torokhov@gmail.com>
上级 38c38072
...@@ -66,7 +66,6 @@ ...@@ -66,7 +66,6 @@
struct lpc32xx_kscan_drv { struct lpc32xx_kscan_drv {
struct input_dev *input; struct input_dev *input;
struct clk *clk; struct clk *clk;
struct resource *iores;
void __iomem *kscan_base; void __iomem *kscan_base;
unsigned int irq; unsigned int irq;
...@@ -188,32 +187,27 @@ static int lpc32xx_kscan_probe(struct platform_device *pdev) ...@@ -188,32 +187,27 @@ static int lpc32xx_kscan_probe(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
kscandat = kzalloc(sizeof(struct lpc32xx_kscan_drv), GFP_KERNEL); kscandat = devm_kzalloc(&pdev->dev, sizeof(*kscandat),
if (!kscandat) { GFP_KERNEL);
dev_err(&pdev->dev, "failed to allocate memory\n"); if (!kscandat)
return -ENOMEM; return -ENOMEM;
}
error = lpc32xx_parse_dt(&pdev->dev, kscandat); error = lpc32xx_parse_dt(&pdev->dev, kscandat);
if (error) { if (error) {
dev_err(&pdev->dev, "failed to parse device tree\n"); dev_err(&pdev->dev, "failed to parse device tree\n");
goto err_free_mem; return error;
} }
keymap_size = sizeof(kscandat->keymap[0]) * keymap_size = sizeof(kscandat->keymap[0]) *
(kscandat->matrix_sz << kscandat->row_shift); (kscandat->matrix_sz << kscandat->row_shift);
kscandat->keymap = kzalloc(keymap_size, GFP_KERNEL); kscandat->keymap = devm_kzalloc(&pdev->dev, keymap_size, GFP_KERNEL);
if (!kscandat->keymap) { if (!kscandat->keymap)
dev_err(&pdev->dev, "could not allocate memory for keymap\n"); return -ENOMEM;
error = -ENOMEM;
goto err_free_mem;
}
kscandat->input = input = input_allocate_device(); kscandat->input = input = devm_input_allocate_device(&pdev->dev);
if (!input) { if (!input) {
dev_err(&pdev->dev, "failed to allocate input device\n"); dev_err(&pdev->dev, "failed to allocate input device\n");
error = -ENOMEM; return -ENOMEM;
goto err_free_keymap;
} }
/* Setup key input */ /* Setup key input */
...@@ -234,39 +228,26 @@ static int lpc32xx_kscan_probe(struct platform_device *pdev) ...@@ -234,39 +228,26 @@ static int lpc32xx_kscan_probe(struct platform_device *pdev)
kscandat->keymap, kscandat->input); kscandat->keymap, kscandat->input);
if (error) { if (error) {
dev_err(&pdev->dev, "failed to build keymap\n"); dev_err(&pdev->dev, "failed to build keymap\n");
goto err_free_input; return error;
} }
input_set_drvdata(kscandat->input, kscandat); input_set_drvdata(kscandat->input, kscandat);
kscandat->iores = request_mem_region(res->start, resource_size(res), kscandat->kscan_base = devm_ioremap_resource(&pdev->dev, res);
pdev->name); if (IS_ERR(kscandat->kscan_base))
if (!kscandat->iores) { return PTR_ERR(kscandat->kscan_base);
dev_err(&pdev->dev, "failed to request I/O memory\n");
error = -EBUSY;
goto err_free_input;
}
kscandat->kscan_base = ioremap(kscandat->iores->start,
resource_size(kscandat->iores));
if (!kscandat->kscan_base) {
dev_err(&pdev->dev, "failed to remap I/O memory\n");
error = -EBUSY;
goto err_release_memregion;
}
/* Get the key scanner clock */ /* Get the key scanner clock */
kscandat->clk = clk_get(&pdev->dev, NULL); kscandat->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(kscandat->clk)) { if (IS_ERR(kscandat->clk)) {
dev_err(&pdev->dev, "failed to get clock\n"); dev_err(&pdev->dev, "failed to get clock\n");
error = PTR_ERR(kscandat->clk); return PTR_ERR(kscandat->clk);
goto err_unmap;
} }
/* Configure the key scanner */ /* Configure the key scanner */
error = clk_prepare_enable(kscandat->clk); error = clk_prepare_enable(kscandat->clk);
if (error) if (error)
goto err_clk_put; return error;
writel(kscandat->deb_clks, LPC32XX_KS_DEB(kscandat->kscan_base)); writel(kscandat->deb_clks, LPC32XX_KS_DEB(kscandat->kscan_base));
writel(kscandat->scan_delay, LPC32XX_KS_SCAN_CTL(kscandat->kscan_base)); writel(kscandat->scan_delay, LPC32XX_KS_SCAN_CTL(kscandat->kscan_base));
...@@ -277,52 +258,20 @@ static int lpc32xx_kscan_probe(struct platform_device *pdev) ...@@ -277,52 +258,20 @@ static int lpc32xx_kscan_probe(struct platform_device *pdev)
writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base)); writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
clk_disable_unprepare(kscandat->clk); clk_disable_unprepare(kscandat->clk);
error = request_irq(irq, lpc32xx_kscan_irq, 0, pdev->name, kscandat); error = devm_request_irq(&pdev->dev, irq, lpc32xx_kscan_irq, 0,
pdev->name, kscandat);
if (error) { if (error) {
dev_err(&pdev->dev, "failed to request irq\n"); dev_err(&pdev->dev, "failed to request irq\n");
goto err_clk_put; return error;
} }
error = input_register_device(kscandat->input); error = input_register_device(kscandat->input);
if (error) { if (error) {
dev_err(&pdev->dev, "failed to register input device\n"); dev_err(&pdev->dev, "failed to register input device\n");
goto err_free_irq; return error;
} }
platform_set_drvdata(pdev, kscandat); platform_set_drvdata(pdev, kscandat);
return 0;
err_free_irq:
free_irq(irq, kscandat);
err_clk_put:
clk_put(kscandat->clk);
err_unmap:
iounmap(kscandat->kscan_base);
err_release_memregion:
release_mem_region(kscandat->iores->start,
resource_size(kscandat->iores));
err_free_input:
input_free_device(kscandat->input);
err_free_keymap:
kfree(kscandat->keymap);
err_free_mem:
kfree(kscandat);
return error;
}
static int lpc32xx_kscan_remove(struct platform_device *pdev)
{
struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev);
free_irq(platform_get_irq(pdev, 0), kscandat);
clk_put(kscandat->clk);
iounmap(kscandat->kscan_base);
release_mem_region(kscandat->iores->start,
resource_size(kscandat->iores));
input_unregister_device(kscandat->input);
kfree(kscandat->keymap);
kfree(kscandat);
return 0; return 0;
} }
...@@ -378,7 +327,6 @@ MODULE_DEVICE_TABLE(of, lpc32xx_kscan_match); ...@@ -378,7 +327,6 @@ MODULE_DEVICE_TABLE(of, lpc32xx_kscan_match);
static struct platform_driver lpc32xx_kscan_driver = { static struct platform_driver lpc32xx_kscan_driver = {
.probe = lpc32xx_kscan_probe, .probe = lpc32xx_kscan_probe,
.remove = lpc32xx_kscan_remove,
.driver = { .driver = {
.name = DRV_NAME, .name = DRV_NAME,
.owner = THIS_MODULE, .owner = THIS_MODULE,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册