Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: add RAVE SP Powerbutton driver

Add driver that properly handles input event emitted by RAVE SP
devices.

Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Andrey Smirnov and committed by
Dmitry Torokhov
62f0f079 c6380ecd

+126
+22
Documentation/devicetree/bindings/input/zii,rave-sp-pwrbutton.txt
··· 1 + Zodiac Inflight Innovations RAVE Supervisory Processor Power Button Bindings 2 + 3 + RAVE SP input device is a "MFD cell" device corresponding to power 4 + button functionality of RAVE Supervisory Processor. It is expected 5 + that its Device Tree node is specified as a child of the node 6 + corresponding to the parent RAVE SP device (as documented in 7 + Documentation/devicetree/bindings/mfd/zii,rave-sp.txt) 8 + 9 + Required properties: 10 + 11 + - compatible: Should be "zii,rave-sp-pwrbutton" 12 + 13 + Example: 14 + 15 + rave-sp { 16 + compatible = "zii,rave-sp-rdu1"; 17 + current-speed = <38400>; 18 + 19 + pwrbutton { 20 + compatible = "zii,rave-sp-pwrbutton"; 21 + }; 22 + }
+9
drivers/input/misc/Kconfig
··· 841 841 To compile this driver as a module, choose M here: the 842 842 module will be called hisi_powerkey. 843 843 844 + config INPUT_RAVE_SP_PWRBUTTON 845 + tristate "RAVE SP Power button Driver" 846 + depends on RAVE_SP_CORE 847 + help 848 + Say Y here if you want to enable power key reporting from RAVE SP 849 + 850 + To compile this driver as a module, choose M here: the 851 + module will be called rave-sp-pwrbutton. 852 + 844 853 endif
+1
drivers/input/misc/Makefile
··· 60 60 obj-$(CONFIG_INPUT_POWERMATE) += powermate.o 61 61 obj-$(CONFIG_INPUT_PWM_BEEPER) += pwm-beeper.o 62 62 obj-$(CONFIG_INPUT_PWM_VIBRA) += pwm-vibra.o 63 + obj-$(CONFIG_INPUT_RAVE_SP_PWRBUTTON) += rave-sp-pwrbutton.o 63 64 obj-$(CONFIG_INPUT_RB532_BUTTON) += rb532_button.o 64 65 obj-$(CONFIG_INPUT_REGULATOR_HAPTIC) += regulator-haptic.o 65 66 obj-$(CONFIG_INPUT_RETU_PWRBUTTON) += retu-pwrbutton.o
+94
drivers/input/misc/rave-sp-pwrbutton.c
··· 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 + // 8 + 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> 14 + 15 + #define RAVE_SP_EVNT_BUTTON_PRESS (RAVE_SP_EVNT_BASE + 0x00) 16 + 17 + struct rave_sp_power_button { 18 + struct input_dev *idev; 19 + struct notifier_block nb; 20 + }; 21 + 22 + static int rave_sp_power_button_event(struct notifier_block *nb, 23 + unsigned long action, void *data) 24 + { 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; 30 + 31 + if (event == RAVE_SP_EVNT_BUTTON_PRESS) { 32 + input_report_key(idev, KEY_POWER, value); 33 + input_sync(idev); 34 + 35 + return NOTIFY_STOP; 36 + } 37 + 38 + return NOTIFY_DONE; 39 + } 40 + 41 + static int rave_sp_pwrbutton_probe(struct platform_device *pdev) 42 + { 43 + struct device *dev = &pdev->dev; 44 + struct rave_sp_power_button *pb; 45 + struct input_dev *idev; 46 + int error; 47 + 48 + pb = devm_kzalloc(dev, sizeof(*pb), GFP_KERNEL); 49 + if (!pb) 50 + return -ENOMEM; 51 + 52 + idev = devm_input_allocate_device(dev); 53 + if (!idev) 54 + return -ENOMEM; 55 + 56 + idev->name = pdev->name; 57 + 58 + input_set_capability(idev, EV_KEY, KEY_POWER); 59 + 60 + error = input_register_device(idev); 61 + if (error) 62 + return error; 63 + 64 + pb->idev = idev; 65 + pb->nb.notifier_call = rave_sp_power_button_event; 66 + pb->nb.priority = 128; 67 + 68 + error = devm_rave_sp_register_event_notifier(dev, &pb->nb); 69 + if (error) 70 + return error; 71 + 72 + return 0; 73 + } 74 + 75 + static const struct of_device_id rave_sp_pwrbutton_of_match[] = { 76 + { .compatible = "zii,rave-sp-pwrbutton" }, 77 + {} 78 + }; 79 + 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, 85 + }, 86 + }; 87 + module_platform_driver(rave_sp_pwrbutton_driver); 88 + 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");