1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Rockchip RK805 PMIC Power Key driver
5 * Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd
7 * Author: Joseph Chen <chenjh@rock-chips.com>
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);
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);
38 static int rk805_pwrkey_probe(struct platform_device
*pdev
)
40 struct input_dev
*pwr
;
41 int fall_irq
, rise_irq
;
44 pwr
= devm_input_allocate_device(&pdev
->dev
);
46 dev_err(&pdev
->dev
, "Can't allocate power button\n");
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);
59 rise_irq
= platform_get_irq(pdev
, 1);
63 err
= devm_request_any_context_irq(&pwr
->dev
, fall_irq
,
65 IRQF_TRIGGER_FALLING
| IRQF_ONESHOT
,
66 "rk805_pwrkey_fall", pwr
);
68 dev_err(&pdev
->dev
, "Can't register fall irq: %d\n", err
);
72 err
= devm_request_any_context_irq(&pwr
->dev
, rise_irq
,
74 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
75 "rk805_pwrkey_rise", pwr
);
77 dev_err(&pdev
->dev
, "Can't register rise irq: %d\n", err
);
81 err
= input_register_device(pwr
);
83 dev_err(&pdev
->dev
, "Can't register power button: %d\n", err
);
87 platform_set_drvdata(pdev
, pwr
);
88 device_init_wakeup(&pdev
->dev
, true);
93 static struct platform_driver rk805_pwrkey_driver
= {
94 .probe
= rk805_pwrkey_probe
,
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");