Input: dlink-dir685-touchkeys - fix a typo in driver name
[linux/fpc-iii.git] / drivers / input / misc / rave-sp-pwrbutton.c
blobbcab3cdb7ebdaf48fac8feb592d312e477d250a2
1 // SPDX-License-Identifier: GPL-2.0+
2 //
3 // Power Button driver for RAVE SP
4 //
5 // Copyright (C) 2017 Zodiac Inflight Innovations
6 //
7 //
9 #include <linux/input.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/mfd/rave-sp.h>
13 #include <linux/platform_device.h>
15 #define RAVE_SP_EVNT_BUTTON_PRESS (RAVE_SP_EVNT_BASE + 0x00)
17 struct rave_sp_power_button {
18 struct input_dev *idev;
19 struct notifier_block nb;
22 static int rave_sp_power_button_event(struct notifier_block *nb,
23 unsigned long action, void *data)
25 struct rave_sp_power_button *pb =
26 container_of(nb, struct rave_sp_power_button, nb);
27 const u8 event = rave_sp_action_unpack_event(action);
28 const u8 value = rave_sp_action_unpack_value(action);
29 struct input_dev *idev = pb->idev;
31 if (event == RAVE_SP_EVNT_BUTTON_PRESS) {
32 input_report_key(idev, KEY_POWER, value);
33 input_sync(idev);
35 return NOTIFY_STOP;
38 return NOTIFY_DONE;
41 static int rave_sp_pwrbutton_probe(struct platform_device *pdev)
43 struct device *dev = &pdev->dev;
44 struct rave_sp_power_button *pb;
45 struct input_dev *idev;
46 int error;
48 pb = devm_kzalloc(dev, sizeof(*pb), GFP_KERNEL);
49 if (!pb)
50 return -ENOMEM;
52 idev = devm_input_allocate_device(dev);
53 if (!idev)
54 return -ENOMEM;
56 idev->name = pdev->name;
58 input_set_capability(idev, EV_KEY, KEY_POWER);
60 error = input_register_device(idev);
61 if (error)
62 return error;
64 pb->idev = idev;
65 pb->nb.notifier_call = rave_sp_power_button_event;
66 pb->nb.priority = 128;
68 error = devm_rave_sp_register_event_notifier(dev, &pb->nb);
69 if (error)
70 return error;
72 return 0;
75 static const struct of_device_id rave_sp_pwrbutton_of_match[] = {
76 { .compatible = "zii,rave-sp-pwrbutton" },
80 static struct platform_driver rave_sp_pwrbutton_driver = {
81 .probe = rave_sp_pwrbutton_probe,
82 .driver = {
83 .name = KBUILD_MODNAME,
84 .of_match_table = rave_sp_pwrbutton_of_match,
87 module_platform_driver(rave_sp_pwrbutton_driver);
89 MODULE_DEVICE_TABLE(of, rave_sp_pwrbutton_of_match);
90 MODULE_LICENSE("GPL");
91 MODULE_AUTHOR("Andrey Vostrikov <andrey.vostrikov@cogentembedded.com>");
92 MODULE_AUTHOR("Nikita Yushchenko <nikita.yoush@cogentembedded.com>");
93 MODULE_AUTHOR("Andrey Smirnov <andrew.smirnov@gmail.com>");
94 MODULE_DESCRIPTION("RAVE SP Power Button driver");