Input: dlink-dir685-touchkeys - fix a typo in driver name
[linux/fpc-iii.git] / drivers / input / misc / rk805-pwrkey.c
blob921003963a53cc8a8a2f8812cad739d7a0434423
1 /*
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);
27 input_sync(pwr);
29 return IRQ_HANDLED;
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);
37 input_sync(pwr);
39 return IRQ_HANDLED;
42 static int rk805_pwrkey_probe(struct platform_device *pdev)
44 struct input_dev *pwr;
45 int fall_irq, rise_irq;
46 int err;
48 pwr = devm_input_allocate_device(&pdev->dev);
49 if (!pwr) {
50 dev_err(&pdev->dev, "Can't allocate power button\n");
51 return -ENOMEM;
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);
60 if (fall_irq < 0) {
61 dev_err(&pdev->dev, "Can't get fall irq: %d\n", fall_irq);
62 return fall_irq;
65 rise_irq = platform_get_irq(pdev, 1);
66 if (rise_irq < 0) {
67 dev_err(&pdev->dev, "Can't get rise irq: %d\n", rise_irq);
68 return rise_irq;
71 err = devm_request_any_context_irq(&pwr->dev, fall_irq,
72 pwrkey_fall_irq,
73 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
74 "rk805_pwrkey_fall", pwr);
75 if (err < 0) {
76 dev_err(&pdev->dev, "Can't register fall irq: %d\n", err);
77 return err;
80 err = devm_request_any_context_irq(&pwr->dev, rise_irq,
81 pwrkey_rise_irq,
82 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
83 "rk805_pwrkey_rise", pwr);
84 if (err < 0) {
85 dev_err(&pdev->dev, "Can't register rise irq: %d\n", err);
86 return err;
89 err = input_register_device(pwr);
90 if (err) {
91 dev_err(&pdev->dev, "Can't register power button: %d\n", err);
92 return err;
95 platform_set_drvdata(pdev, pwr);
96 device_init_wakeup(&pdev->dev, true);
98 return 0;
101 static struct platform_driver rk805_pwrkey_driver = {
102 .probe = rk805_pwrkey_probe,
103 .driver = {
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");