aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/keyboard
diff options
context:
space:
mode:
authorStephen Boyd <sboyd@codeaurora.org>2014-03-29 15:32:43 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2014-03-30 16:25:18 -0400
commitc7f6ee264b511d8a35063e9821cf36ad18e4e4fd (patch)
treedeb987e6e9a6a57661bad451da6367f7e246af91 /drivers/input/keyboard
parentd3e6a67c7e502e8d21624c453f1d1f697e674548 (diff)
Input: pmic8xxx-keypad - migrate to devm_* APIs
Simplify the error paths and reduce the lines of code in this driver by using the devm_* APIs. Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/keyboard')
-rw-r--r--drivers/input/keyboard/pmic8xxx-keypad.c61
1 files changed, 17 insertions, 44 deletions
diff --git a/drivers/input/keyboard/pmic8xxx-keypad.c b/drivers/input/keyboard/pmic8xxx-keypad.c
index c4aa882c8fb9..bec53ebde7b2 100644
--- a/drivers/input/keyboard/pmic8xxx-keypad.c
+++ b/drivers/input/keyboard/pmic8xxx-keypad.c
@@ -543,7 +543,7 @@ static int pmic8xxx_kp_probe(struct platform_device *pdev)
543 return -EINVAL; 543 return -EINVAL;
544 } 544 }
545 545
546 kp = kzalloc(sizeof(*kp), GFP_KERNEL); 546 kp = devm_kzalloc(&pdev->dev, sizeof(*kp), GFP_KERNEL);
547 if (!kp) 547 if (!kp)
548 return -ENOMEM; 548 return -ENOMEM;
549 549
@@ -552,32 +552,27 @@ static int pmic8xxx_kp_probe(struct platform_device *pdev)
552 kp->pdata = pdata; 552 kp->pdata = pdata;
553 kp->dev = &pdev->dev; 553 kp->dev = &pdev->dev;
554 554
555 kp->input = input_allocate_device(); 555 kp->input = devm_input_allocate_device(&pdev->dev);
556 if (!kp->input) { 556 if (!kp->input) {
557 dev_err(&pdev->dev, "unable to allocate input device\n"); 557 dev_err(&pdev->dev, "unable to allocate input device\n");
558 rc = -ENOMEM; 558 return -ENOMEM;
559 goto err_alloc_device;
560 } 559 }
561 560
562 kp->key_sense_irq = platform_get_irq(pdev, 0); 561 kp->key_sense_irq = platform_get_irq(pdev, 0);
563 if (kp->key_sense_irq < 0) { 562 if (kp->key_sense_irq < 0) {
564 dev_err(&pdev->dev, "unable to get keypad sense irq\n"); 563 dev_err(&pdev->dev, "unable to get keypad sense irq\n");
565 rc = -ENXIO; 564 return kp->key_sense_irq;
566 goto err_get_irq;
567 } 565 }
568 566
569 kp->key_stuck_irq = platform_get_irq(pdev, 1); 567 kp->key_stuck_irq = platform_get_irq(pdev, 1);
570 if (kp->key_stuck_irq < 0) { 568 if (kp->key_stuck_irq < 0) {
571 dev_err(&pdev->dev, "unable to get keypad stuck irq\n"); 569 dev_err(&pdev->dev, "unable to get keypad stuck irq\n");
572 rc = -ENXIO; 570 return kp->key_stuck_irq;
573 goto err_get_irq;
574 } 571 }
575 572
576 kp->input->name = pdata->input_name ? : "PMIC8XXX keypad"; 573 kp->input->name = pdata->input_name ? : "PMIC8XXX keypad";
577 kp->input->phys = pdata->input_phys_device ? : "pmic8xxx_keypad/input0"; 574 kp->input->phys = pdata->input_phys_device ? : "pmic8xxx_keypad/input0";
578 575
579 kp->input->dev.parent = &pdev->dev;
580
581 kp->input->id.bustype = BUS_I2C; 576 kp->input->id.bustype = BUS_I2C;
582 kp->input->id.version = 0x0001; 577 kp->input->id.version = 0x0001;
583 kp->input->id.product = 0x0001; 578 kp->input->id.product = 0x0001;
@@ -591,7 +586,7 @@ static int pmic8xxx_kp_probe(struct platform_device *pdev)
591 kp->keycodes, kp->input); 586 kp->keycodes, kp->input);
592 if (rc) { 587 if (rc) {
593 dev_err(&pdev->dev, "failed to build keymap\n"); 588 dev_err(&pdev->dev, "failed to build keymap\n");
594 goto err_get_irq; 589 return rc;
595 } 590 }
596 591
597 if (pdata->rep) 592 if (pdata->rep)
@@ -607,27 +602,29 @@ static int pmic8xxx_kp_probe(struct platform_device *pdev)
607 rc = pmic8xxx_kpd_init(kp); 602 rc = pmic8xxx_kpd_init(kp);
608 if (rc < 0) { 603 if (rc < 0) {
609 dev_err(&pdev->dev, "unable to initialize keypad controller\n"); 604 dev_err(&pdev->dev, "unable to initialize keypad controller\n");
610 goto err_get_irq; 605 return rc;
611 } 606 }
612 607
613 rc = request_any_context_irq(kp->key_sense_irq, pmic8xxx_kp_irq, 608 rc = devm_request_any_context_irq(&pdev->dev, kp->key_sense_irq,
614 IRQF_TRIGGER_RISING, "pmic-keypad", kp); 609 pmic8xxx_kp_irq, IRQF_TRIGGER_RISING, "pmic-keypad",
610 kp);
615 if (rc < 0) { 611 if (rc < 0) {
616 dev_err(&pdev->dev, "failed to request keypad sense irq\n"); 612 dev_err(&pdev->dev, "failed to request keypad sense irq\n");
617 goto err_get_irq; 613 return rc;
618 } 614 }
619 615
620 rc = request_any_context_irq(kp->key_stuck_irq, pmic8xxx_kp_stuck_irq, 616 rc = devm_request_any_context_irq(&pdev->dev, kp->key_stuck_irq,
621 IRQF_TRIGGER_RISING, "pmic-keypad-stuck", kp); 617 pmic8xxx_kp_stuck_irq, IRQF_TRIGGER_RISING,
618 "pmic-keypad-stuck", kp);
622 if (rc < 0) { 619 if (rc < 0) {
623 dev_err(&pdev->dev, "failed to request keypad stuck irq\n"); 620 dev_err(&pdev->dev, "failed to request keypad stuck irq\n");
624 goto err_req_stuck_irq; 621 return rc;
625 } 622 }
626 623
627 rc = pmic8xxx_kp_read_u8(kp, &ctrl_val, KEYP_CTRL); 624 rc = pmic8xxx_kp_read_u8(kp, &ctrl_val, KEYP_CTRL);
628 if (rc < 0) { 625 if (rc < 0) {
629 dev_err(&pdev->dev, "failed to read KEYP_CTRL register\n"); 626 dev_err(&pdev->dev, "failed to read KEYP_CTRL register\n");
630 goto err_pmic_reg_read; 627 return rc;
631 } 628 }
632 629
633 kp->ctrl_reg = ctrl_val; 630 kp->ctrl_reg = ctrl_val;
@@ -635,35 +632,12 @@ static int pmic8xxx_kp_probe(struct platform_device *pdev)
635 rc = input_register_device(kp->input); 632 rc = input_register_device(kp->input);
636 if (rc < 0) { 633 if (rc < 0) {
637 dev_err(&pdev->dev, "unable to register keypad input device\n"); 634 dev_err(&pdev->dev, "unable to register keypad input device\n");
638 goto err_pmic_reg_read; 635 return rc;
639 } 636 }
640 637
641 device_init_wakeup(&pdev->dev, pdata->wakeup); 638 device_init_wakeup(&pdev->dev, pdata->wakeup);
642 639
643 return 0; 640 return 0;
644
645err_pmic_reg_read:
646 free_irq(kp->key_stuck_irq, kp);
647err_req_stuck_irq:
648 free_irq(kp->key_sense_irq, kp);
649err_get_irq:
650 input_free_device(kp->input);
651err_alloc_device:
652 kfree(kp);
653 return rc;
654}
655
656static int pmic8xxx_kp_remove(struct platform_device *pdev)
657{
658 struct pmic8xxx_kp *kp = platform_get_drvdata(pdev);
659
660 device_init_wakeup(&pdev->dev, 0);
661 free_irq(kp->key_stuck_irq, kp);
662 free_irq(kp->key_sense_irq, kp);
663 input_unregister_device(kp->input);
664 kfree(kp);
665
666 return 0;
667} 641}
668 642
669#ifdef CONFIG_PM_SLEEP 643#ifdef CONFIG_PM_SLEEP
@@ -713,7 +687,6 @@ static SIMPLE_DEV_PM_OPS(pm8xxx_kp_pm_ops,
713 687
714static struct platform_driver pmic8xxx_kp_driver = { 688static struct platform_driver pmic8xxx_kp_driver = {
715 .probe = pmic8xxx_kp_probe, 689 .probe = pmic8xxx_kp_probe,
716 .remove = pmic8xxx_kp_remove,
717 .driver = { 690 .driver = {
718 .name = PM8XXX_KEYPAD_DEV_NAME, 691 .name = PM8XXX_KEYPAD_DEV_NAME,
719 .owner = THIS_MODULE, 692 .owner = THIS_MODULE,