Commit c0551abb authored by Yangtao Li's avatar Yangtao Li Committed by Dmitry Torokhov

Input: nomadik-ske-keypad - convert to use devm_* api

Use devm_* api to simplify code, this makes it unnecessary to explicitly
release resources.
Signed-off-by: default avatarYangtao Li <frank.li@vivo.com>
Link: https://lore.kernel.org/r/20230705052346.39337-8-frank.li@vivo.comSigned-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent b1c55900
...@@ -221,13 +221,20 @@ static irqreturn_t ske_keypad_irq(int irq, void *dev_id) ...@@ -221,13 +221,20 @@ static irqreturn_t ske_keypad_irq(int irq, void *dev_id)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static void ske_keypad_board_exit(void *data)
{
struct ske_keypad *keypad = data;
keypad->board->exit();
}
static int __init ske_keypad_probe(struct platform_device *pdev) static int __init ske_keypad_probe(struct platform_device *pdev)
{ {
const struct ske_keypad_platform_data *plat = const struct ske_keypad_platform_data *plat =
dev_get_platdata(&pdev->dev); dev_get_platdata(&pdev->dev);
struct device *dev = &pdev->dev;
struct ske_keypad *keypad; struct ske_keypad *keypad;
struct input_dev *input; struct input_dev *input;
struct resource *res;
int irq; int irq;
int error; int error;
...@@ -238,20 +245,14 @@ static int __init ske_keypad_probe(struct platform_device *pdev) ...@@ -238,20 +245,14 @@ static int __init ske_keypad_probe(struct platform_device *pdev)
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq < 0) if (irq < 0)
return -EINVAL; return irq;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(&pdev->dev, "missing platform resources\n");
return -EINVAL;
}
keypad = kzalloc(sizeof(struct ske_keypad), GFP_KERNEL); keypad = devm_kzalloc(dev, sizeof(struct ske_keypad),
input = input_allocate_device(); GFP_KERNEL);
input = devm_input_allocate_device(dev);
if (!keypad || !input) { if (!keypad || !input) {
dev_err(&pdev->dev, "failed to allocate keypad memory\n"); dev_err(&pdev->dev, "failed to allocate keypad memory\n");
error = -ENOMEM; return -ENOMEM;
goto err_free_mem;
} }
keypad->irq = irq; keypad->irq = irq;
...@@ -259,31 +260,20 @@ static int __init ske_keypad_probe(struct platform_device *pdev) ...@@ -259,31 +260,20 @@ static int __init ske_keypad_probe(struct platform_device *pdev)
keypad->input = input; keypad->input = input;
spin_lock_init(&keypad->ske_keypad_lock); spin_lock_init(&keypad->ske_keypad_lock);
if (!request_mem_region(res->start, resource_size(res), pdev->name)) { keypad->reg_base = devm_platform_ioremap_resource(pdev, 0);
dev_err(&pdev->dev, "failed to request I/O memory\n"); if (IS_ERR(keypad->reg_base))
error = -EBUSY; return PTR_ERR(keypad->reg_base);
goto err_free_mem;
}
keypad->reg_base = ioremap(res->start, resource_size(res));
if (!keypad->reg_base) {
dev_err(&pdev->dev, "failed to remap I/O memory\n");
error = -ENXIO;
goto err_free_mem_region;
}
keypad->pclk = clk_get(&pdev->dev, "apb_pclk"); keypad->pclk = devm_clk_get_enabled(dev, "apb_pclk");
if (IS_ERR(keypad->pclk)) { if (IS_ERR(keypad->pclk)) {
dev_err(&pdev->dev, "failed to get pclk\n"); dev_err(&pdev->dev, "failed to get pclk\n");
error = PTR_ERR(keypad->pclk); return PTR_ERR(keypad->pclk);
goto err_iounmap;
} }
keypad->clk = clk_get(&pdev->dev, NULL); keypad->clk = devm_clk_get_enabled(dev, NULL);
if (IS_ERR(keypad->clk)) { if (IS_ERR(keypad->clk)) {
dev_err(&pdev->dev, "failed to get clk\n"); dev_err(&pdev->dev, "failed to get clk\n");
error = PTR_ERR(keypad->clk); return PTR_ERR(keypad->clk);
goto err_pclk;
} }
input->id.bustype = BUS_HOST; input->id.bustype = BUS_HOST;
...@@ -295,48 +285,43 @@ static int __init ske_keypad_probe(struct platform_device *pdev) ...@@ -295,48 +285,43 @@ static int __init ske_keypad_probe(struct platform_device *pdev)
keypad->keymap, input); keypad->keymap, 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_clk; return error;
} }
input_set_capability(input, EV_MSC, MSC_SCAN); input_set_capability(input, EV_MSC, MSC_SCAN);
if (!plat->no_autorepeat) if (!plat->no_autorepeat)
__set_bit(EV_REP, input->evbit); __set_bit(EV_REP, input->evbit);
error = clk_prepare_enable(keypad->pclk);
if (error) {
dev_err(&pdev->dev, "Failed to prepare/enable pclk\n");
goto err_clk;
}
error = clk_prepare_enable(keypad->clk);
if (error) {
dev_err(&pdev->dev, "Failed to prepare/enable clk\n");
goto err_pclk_disable;
}
/* go through board initialization helpers */ /* go through board initialization helpers */
if (keypad->board->init) if (keypad->board->init)
keypad->board->init(); keypad->board->init();
if (keypad->board->exit) {
error = devm_add_action_or_reset(dev, ske_keypad_board_exit,
keypad);
if (error)
return error;
}
error = ske_keypad_chip_init(keypad); error = ske_keypad_chip_init(keypad);
if (error) { if (error) {
dev_err(&pdev->dev, "unable to init keypad hardware\n"); dev_err(&pdev->dev, "unable to init keypad hardware\n");
goto err_clk_disable; return error;
} }
error = request_threaded_irq(keypad->irq, NULL, ske_keypad_irq, error = devm_request_threaded_irq(dev, keypad->irq,
IRQF_ONESHOT, "ske-keypad", keypad); NULL, ske_keypad_irq,
IRQF_ONESHOT, "ske-keypad", keypad);
if (error) { if (error) {
dev_err(&pdev->dev, "allocate irq %d failed\n", keypad->irq); dev_err(&pdev->dev, "allocate irq %d failed\n", keypad->irq);
goto err_clk_disable; return error;
} }
error = input_register_device(input); error = input_register_device(input);
if (error) { if (error) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"unable to register input device: %d\n", error); "unable to register input device: %d\n", error);
goto err_free_irq; return error;
} }
if (plat->wakeup_enable) if (plat->wakeup_enable)
...@@ -344,47 +329,6 @@ static int __init ske_keypad_probe(struct platform_device *pdev) ...@@ -344,47 +329,6 @@ static int __init ske_keypad_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, keypad); platform_set_drvdata(pdev, keypad);
return 0;
err_free_irq:
free_irq(keypad->irq, keypad);
err_clk_disable:
clk_disable_unprepare(keypad->clk);
err_pclk_disable:
clk_disable_unprepare(keypad->pclk);
err_clk:
clk_put(keypad->clk);
err_pclk:
clk_put(keypad->pclk);
err_iounmap:
iounmap(keypad->reg_base);
err_free_mem_region:
release_mem_region(res->start, resource_size(res));
err_free_mem:
input_free_device(input);
kfree(keypad);
return error;
}
static int ske_keypad_remove(struct platform_device *pdev)
{
struct ske_keypad *keypad = platform_get_drvdata(pdev);
struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
free_irq(keypad->irq, keypad);
input_unregister_device(keypad->input);
clk_disable_unprepare(keypad->clk);
clk_put(keypad->clk);
if (keypad->board->exit)
keypad->board->exit();
iounmap(keypad->reg_base);
release_mem_region(res->start, resource_size(res));
kfree(keypad);
return 0; return 0;
} }
...@@ -424,7 +368,6 @@ static struct platform_driver ske_keypad_driver = { ...@@ -424,7 +368,6 @@ static struct platform_driver ske_keypad_driver = {
.name = "nmk-ske-keypad", .name = "nmk-ske-keypad",
.pm = pm_sleep_ptr(&ske_keypad_dev_pm_ops), .pm = pm_sleep_ptr(&ske_keypad_dev_pm_ops),
}, },
.remove = ske_keypad_remove,
}; };
module_platform_driver_probe(ske_keypad_driver, ske_keypad_probe); module_platform_driver_probe(ske_keypad_driver, ske_keypad_probe);
......
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