2 * Rockchip RK805 PMIC Power Key driver
4 * Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd
6 * Author: Joseph Chen <chenjh@rock-chips.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
14 #include <linux/errno.h>
15 #include <linux/init.h>
16 #include <linux/input.h>
17 #include <linux/interrupt.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
22 static irqreturn_t
pwrkey_fall_irq(int irq
, void *_pwr
)
24 struct input_dev
*pwr
= _pwr
;
26 input_report_key(pwr
, KEY_POWER
, 1);
32 static irqreturn_t
pwrkey_rise_irq(int irq
, void *_pwr
)
34 struct input_dev
*pwr
= _pwr
;
36 input_report_key(pwr
, KEY_POWER
, 0);
42 static int rk805_pwrkey_probe(struct platform_device
*pdev
)
44 struct input_dev
*pwr
;
45 int fall_irq
, rise_irq
;
48 pwr
= devm_input_allocate_device(&pdev
->dev
);
50 dev_err(&pdev
->dev
, "Can't allocate power button\n");
54 pwr
->name
= "rk805 pwrkey";
55 pwr
->phys
= "rk805_pwrkey/input0";
56 pwr
->id
.bustype
= BUS_HOST
;
57 input_set_capability(pwr
, EV_KEY
, KEY_POWER
);
59 fall_irq
= platform_get_irq(pdev
, 0);
61 dev_err(&pdev
->dev
, "Can't get fall irq: %d\n", fall_irq
);
65 rise_irq
= platform_get_irq(pdev
, 1);
67 dev_err(&pdev
->dev
, "Can't get rise irq: %d\n", rise_irq
);
71 err
= devm_request_any_context_irq(&pwr
->dev
, fall_irq
,
73 IRQF_TRIGGER_FALLING
| IRQF_ONESHOT
,
74 "rk805_pwrkey_fall", pwr
);
76 dev_err(&pdev
->dev
, "Can't register fall irq: %d\n", err
);
80 err
= devm_request_any_context_irq(&pwr
->dev
, rise_irq
,
82 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
83 "rk805_pwrkey_rise", pwr
);
85 dev_err(&pdev
->dev
, "Can't register rise irq: %d\n", err
);
89 err
= input_register_device(pwr
);
91 dev_err(&pdev
->dev
, "Can't register power button: %d\n", err
);
95 platform_set_drvdata(pdev
, pwr
);
96 device_init_wakeup(&pdev
->dev
, true);
101 static struct platform_driver rk805_pwrkey_driver
= {
102 .probe
= rk805_pwrkey_probe
,
104 .name
= "rk805-pwrkey",
107 module_platform_driver(rk805_pwrkey_driver
);
109 MODULE_AUTHOR("Joseph Chen <chenjh@rock-chips.com>");
110 MODULE_DESCRIPTION("RK805 PMIC Power Key driver");
111 MODULE_LICENSE("GPL");