2 * driver/input/misc/rk8xx-pwrkey.c
3 * Power Key driver for RK8xx PMIC Power Button.
5 * Copyright (C) 2017, Rockchip Technology Co., Ltd.
6 * Author: Chen Jianhong <chenjh@rock-chips.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
13 * kind, whether express or implied; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/errno.h>
19 #include <linux/input.h>
20 #include <linux/init.h>
21 #include <linux/interrupt.h>
22 #include <linux/kernel.h>
23 #include <linux/mfd/rk808.h>
24 #include <linux/module.h>
26 #include <linux/platform_device.h>
27 #include <linux/regmap.h>
31 struct input_dev *input_dev;
35 static irqreturn_t rk8xx_pwrkey_irq_falling(int irq, void *data)
37 struct rk8xx_pwrkey *pwr = data;
39 input_report_key(pwr->input_dev, pwr->report_key, 1);
40 input_sync(pwr->input_dev);
45 static irqreturn_t rk8xx_pwrkey_irq_rising(int irq, void *data)
47 struct rk8xx_pwrkey *pwr = data;
49 input_report_key(pwr->input_dev, pwr->report_key, 0);
50 input_sync(pwr->input_dev);
55 static int rk8xx_pwrkey_probe(struct platform_device *pdev)
57 struct rk808 *rk8xx = dev_get_drvdata(pdev->dev.parent);
58 struct rk8xx_pwrkey *pwrkey;
59 int fall_irq, rise_irq, err;
60 struct device_node *np;
62 np = of_find_node_by_name(pdev->dev.parent->of_node, "pwrkey");
64 if (!of_device_is_available(np)) {
65 dev_info(&pdev->dev, "device is disabled\n");
70 pwrkey = devm_kzalloc(&pdev->dev,
71 sizeof(struct rk8xx_pwrkey), GFP_KERNEL);
75 pwrkey->input_dev = devm_input_allocate_device(&pdev->dev);
76 if (!pwrkey->input_dev) {
77 dev_err(&pdev->dev, "Can't allocate power button\n");
81 /* init struct input_dev */
82 pwrkey->rk8xx = rk8xx;
83 pwrkey->report_key = KEY_POWER;
84 pwrkey->input_dev->name = "rk8xx_pwrkey";
85 pwrkey->input_dev->phys = "rk8xx_pwrkey/input0";
86 pwrkey->input_dev->dev.parent = pdev->dev.parent;
87 pwrkey->input_dev->evbit[0] = BIT_MASK(EV_KEY);
88 pwrkey->input_dev->keybit[BIT_WORD(pwrkey->report_key)] =
89 BIT_MASK(pwrkey->report_key);
90 platform_set_drvdata(pdev, pwrkey);
92 /* requeset rise and fall irqs */
93 rise_irq = platform_get_irq(pdev, 0);
95 dev_err(&pdev->dev, "no IRQ for rise: %d\n", rise_irq);
99 fall_irq = platform_get_irq(pdev, 1);
101 dev_err(&pdev->dev, "no IRQ for fall: %d\n", fall_irq);
105 err = devm_request_threaded_irq(&pdev->dev, fall_irq,
106 NULL, rk8xx_pwrkey_irq_falling,
107 IRQF_TRIGGER_FALLING,
108 "rk8xx_pwrkey_fall", pwrkey);
110 dev_err(&pdev->dev, "Can't get fall irq for pwrkey: %d\n", err);
113 err = devm_request_threaded_irq(&pdev->dev, rise_irq,
114 NULL, rk8xx_pwrkey_irq_rising,
116 "rk8xx_pwrkey_rise", pwrkey);
118 dev_err(&pdev->dev, "Can't get rise irq for pwrkey: %d\n", err);
122 /* register input device */
123 err = input_register_device(pwrkey->input_dev);
125 dev_err(&pdev->dev, "Can't register power button: %d\n", err);
132 static struct platform_driver rk8xx_pwrkey_driver = {
133 .probe = rk8xx_pwrkey_probe,
135 .name = "rk8xx-pwrkey",
136 .owner = THIS_MODULE,
140 module_platform_driver(rk8xx_pwrkey_driver);
142 MODULE_LICENSE("GPL v2");
143 MODULE_DESCRIPTION("RK8xx Power Button");
144 MODULE_AUTHOR("Chen Jianhong <chenjh@rock-chips.com>");