treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / input / misc / rk805-pwrkey.c
blob3fb64dbda1a2189117a8ef6605b9602195feff57
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Rockchip RK805 PMIC Power Key driver
5 * Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd
7 * Author: Joseph Chen <chenjh@rock-chips.com>
8 */
10 #include <linux/errno.h>
11 #include <linux/init.h>
12 #include <linux/input.h>
13 #include <linux/interrupt.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/platform_device.h>
18 static irqreturn_t pwrkey_fall_irq(int irq, void *_pwr)
20 struct input_dev *pwr = _pwr;
22 input_report_key(pwr, KEY_POWER, 1);
23 input_sync(pwr);
25 return IRQ_HANDLED;
28 static irqreturn_t pwrkey_rise_irq(int irq, void *_pwr)
30 struct input_dev *pwr = _pwr;
32 input_report_key(pwr, KEY_POWER, 0);
33 input_sync(pwr);
35 return IRQ_HANDLED;
38 static int rk805_pwrkey_probe(struct platform_device *pdev)
40 struct input_dev *pwr;
41 int fall_irq, rise_irq;
42 int err;
44 pwr = devm_input_allocate_device(&pdev->dev);
45 if (!pwr) {
46 dev_err(&pdev->dev, "Can't allocate power button\n");
47 return -ENOMEM;
50 pwr->name = "rk805 pwrkey";
51 pwr->phys = "rk805_pwrkey/input0";
52 pwr->id.bustype = BUS_HOST;
53 input_set_capability(pwr, EV_KEY, KEY_POWER);
55 fall_irq = platform_get_irq(pdev, 0);
56 if (fall_irq < 0)
57 return fall_irq;
59 rise_irq = platform_get_irq(pdev, 1);
60 if (rise_irq < 0)
61 return rise_irq;
63 err = devm_request_any_context_irq(&pwr->dev, fall_irq,
64 pwrkey_fall_irq,
65 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
66 "rk805_pwrkey_fall", pwr);
67 if (err < 0) {
68 dev_err(&pdev->dev, "Can't register fall irq: %d\n", err);
69 return err;
72 err = devm_request_any_context_irq(&pwr->dev, rise_irq,
73 pwrkey_rise_irq,
74 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
75 "rk805_pwrkey_rise", pwr);
76 if (err < 0) {
77 dev_err(&pdev->dev, "Can't register rise irq: %d\n", err);
78 return err;
81 err = input_register_device(pwr);
82 if (err) {
83 dev_err(&pdev->dev, "Can't register power button: %d\n", err);
84 return err;
87 platform_set_drvdata(pdev, pwr);
88 device_init_wakeup(&pdev->dev, true);
90 return 0;
93 static struct platform_driver rk805_pwrkey_driver = {
94 .probe = rk805_pwrkey_probe,
95 .driver = {
96 .name = "rk805-pwrkey",
99 module_platform_driver(rk805_pwrkey_driver);
101 MODULE_AUTHOR("Joseph Chen <chenjh@rock-chips.com>");
102 MODULE_DESCRIPTION("RK805 PMIC Power Key driver");
103 MODULE_LICENSE("GPL");