diff options
author | Fabio Estevam <fabio.estevam@freescale.com> | 2013-03-31 03:38:21 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2013-03-31 03:48:18 -0400 |
commit | da5bce199fa9209c462259125f9a0144adf6885c (patch) | |
tree | b4e897bb967473c659d1c45bd94fe2356d5355bb /drivers/input | |
parent | 2c0a4f8b870dbeb48e3351899bd0e0cc886d4985 (diff) |
Input: imx_keypad - switch to using managed resources
Using devm_ functions can make the code cleaner and simpler.
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/keyboard/imx_keypad.c | 77 |
1 files changed, 14 insertions, 63 deletions
diff --git a/drivers/input/keyboard/imx_keypad.c b/drivers/input/keyboard/imx_keypad.c index 98f9113251d2..03c8cc5cb6c1 100644 --- a/drivers/input/keyboard/imx_keypad.c +++ b/drivers/input/keyboard/imx_keypad.c | |||
@@ -448,24 +448,17 @@ static int imx_keypad_probe(struct platform_device *pdev) | |||
448 | return -EINVAL; | 448 | return -EINVAL; |
449 | } | 449 | } |
450 | 450 | ||
451 | res = request_mem_region(res->start, resource_size(res), pdev->name); | 451 | input_dev = devm_input_allocate_device(&pdev->dev); |
452 | if (res == NULL) { | ||
453 | dev_err(&pdev->dev, "failed to request I/O memory\n"); | ||
454 | return -EBUSY; | ||
455 | } | ||
456 | |||
457 | input_dev = input_allocate_device(); | ||
458 | if (!input_dev) { | 452 | if (!input_dev) { |
459 | dev_err(&pdev->dev, "failed to allocate the input device\n"); | 453 | dev_err(&pdev->dev, "failed to allocate the input device\n"); |
460 | error = -ENOMEM; | 454 | return -ENOMEM; |
461 | goto failed_rel_mem; | ||
462 | } | 455 | } |
463 | 456 | ||
464 | keypad = kzalloc(sizeof(struct imx_keypad), GFP_KERNEL); | 457 | keypad = devm_kzalloc(&pdev->dev, sizeof(struct imx_keypad), |
458 | GFP_KERNEL); | ||
465 | if (!keypad) { | 459 | if (!keypad) { |
466 | dev_err(&pdev->dev, "not enough memory for driver data\n"); | 460 | dev_err(&pdev->dev, "not enough memory for driver data\n"); |
467 | error = -ENOMEM; | 461 | return -ENOMEM; |
468 | goto failed_free_input; | ||
469 | } | 462 | } |
470 | 463 | ||
471 | keypad->input_dev = input_dev; | 464 | keypad->input_dev = input_dev; |
@@ -475,18 +468,14 @@ static int imx_keypad_probe(struct platform_device *pdev) | |||
475 | setup_timer(&keypad->check_matrix_timer, | 468 | setup_timer(&keypad->check_matrix_timer, |
476 | imx_keypad_check_for_events, (unsigned long) keypad); | 469 | imx_keypad_check_for_events, (unsigned long) keypad); |
477 | 470 | ||
478 | keypad->mmio_base = ioremap(res->start, resource_size(res)); | 471 | keypad->mmio_base = devm_ioremap_resource(&pdev->dev, res); |
479 | if (keypad->mmio_base == NULL) { | 472 | if (IS_ERR(keypad->mmio_base)) |
480 | dev_err(&pdev->dev, "failed to remap I/O memory\n"); | 473 | return PTR_ERR(keypad->mmio_base); |
481 | error = -ENOMEM; | ||
482 | goto failed_free_priv; | ||
483 | } | ||
484 | 474 | ||
485 | keypad->clk = clk_get(&pdev->dev, NULL); | 475 | keypad->clk = devm_clk_get(&pdev->dev, NULL); |
486 | if (IS_ERR(keypad->clk)) { | 476 | if (IS_ERR(keypad->clk)) { |
487 | dev_err(&pdev->dev, "failed to get keypad clock\n"); | 477 | dev_err(&pdev->dev, "failed to get keypad clock\n"); |
488 | error = PTR_ERR(keypad->clk); | 478 | return PTR_ERR(keypad->clk); |
489 | goto failed_unmap; | ||
490 | } | 479 | } |
491 | 480 | ||
492 | /* Init the Input device */ | 481 | /* Init the Input device */ |
@@ -502,7 +491,7 @@ static int imx_keypad_probe(struct platform_device *pdev) | |||
502 | keypad->keycodes, input_dev); | 491 | keypad->keycodes, input_dev); |
503 | if (error) { | 492 | if (error) { |
504 | dev_err(&pdev->dev, "failed to build keymap\n"); | 493 | dev_err(&pdev->dev, "failed to build keymap\n"); |
505 | goto failed_clock_put; | 494 | return error; |
506 | } | 495 | } |
507 | 496 | ||
508 | /* Search for rows and cols enabled */ | 497 | /* Search for rows and cols enabled */ |
@@ -527,61 +516,24 @@ static int imx_keypad_probe(struct platform_device *pdev) | |||
527 | imx_keypad_inhibit(keypad); | 516 | imx_keypad_inhibit(keypad); |
528 | clk_disable_unprepare(keypad->clk); | 517 | clk_disable_unprepare(keypad->clk); |
529 | 518 | ||
530 | error = request_irq(irq, imx_keypad_irq_handler, 0, | 519 | error = devm_request_irq(&pdev->dev, irq, imx_keypad_irq_handler, 0, |
531 | pdev->name, keypad); | 520 | pdev->name, keypad); |
532 | if (error) { | 521 | if (error) { |
533 | dev_err(&pdev->dev, "failed to request IRQ\n"); | 522 | dev_err(&pdev->dev, "failed to request IRQ\n"); |
534 | goto failed_clock_put; | 523 | return error; |
535 | } | 524 | } |
536 | 525 | ||
537 | /* Register the input device */ | 526 | /* Register the input device */ |
538 | error = input_register_device(input_dev); | 527 | error = input_register_device(input_dev); |
539 | if (error) { | 528 | if (error) { |
540 | dev_err(&pdev->dev, "failed to register input device\n"); | 529 | dev_err(&pdev->dev, "failed to register input device\n"); |
541 | goto failed_free_irq; | 530 | return error; |
542 | } | 531 | } |
543 | 532 | ||
544 | platform_set_drvdata(pdev, keypad); | 533 | platform_set_drvdata(pdev, keypad); |
545 | device_init_wakeup(&pdev->dev, 1); | 534 | device_init_wakeup(&pdev->dev, 1); |
546 | 535 | ||
547 | return 0; | 536 | return 0; |
548 | |||
549 | failed_free_irq: | ||
550 | free_irq(irq, pdev); | ||
551 | failed_clock_put: | ||
552 | clk_put(keypad->clk); | ||
553 | failed_unmap: | ||
554 | iounmap(keypad->mmio_base); | ||
555 | failed_free_priv: | ||
556 | kfree(keypad); | ||
557 | failed_free_input: | ||
558 | input_free_device(input_dev); | ||
559 | failed_rel_mem: | ||
560 | release_mem_region(res->start, resource_size(res)); | ||
561 | return error; | ||
562 | } | ||
563 | |||
564 | static int imx_keypad_remove(struct platform_device *pdev) | ||
565 | { | ||
566 | struct imx_keypad *keypad = platform_get_drvdata(pdev); | ||
567 | struct resource *res; | ||
568 | |||
569 | dev_dbg(&pdev->dev, ">%s\n", __func__); | ||
570 | |||
571 | platform_set_drvdata(pdev, NULL); | ||
572 | |||
573 | input_unregister_device(keypad->input_dev); | ||
574 | |||
575 | free_irq(keypad->irq, keypad); | ||
576 | clk_put(keypad->clk); | ||
577 | |||
578 | iounmap(keypad->mmio_base); | ||
579 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
580 | release_mem_region(res->start, resource_size(res)); | ||
581 | |||
582 | kfree(keypad); | ||
583 | |||
584 | return 0; | ||
585 | } | 537 | } |
586 | 538 | ||
587 | #ifdef CONFIG_PM_SLEEP | 539 | #ifdef CONFIG_PM_SLEEP |
@@ -640,7 +592,6 @@ static struct platform_driver imx_keypad_driver = { | |||
640 | .of_match_table = of_match_ptr(imx_keypad_of_match), | 592 | .of_match_table = of_match_ptr(imx_keypad_of_match), |
641 | }, | 593 | }, |
642 | .probe = imx_keypad_probe, | 594 | .probe = imx_keypad_probe, |
643 | .remove = imx_keypad_remove, | ||
644 | }; | 595 | }; |
645 | module_platform_driver(imx_keypad_driver); | 596 | module_platform_driver(imx_keypad_driver); |
646 | 597 | ||