^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // Power Button driver for RAVE SP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) // Copyright (C) 2017 Zodiac Inflight Innovations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/mfd/rave-sp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define RAVE_SP_EVNT_BUTTON_PRESS (RAVE_SP_EVNT_BASE + 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct rave_sp_power_button {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct input_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct notifier_block nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static int rave_sp_power_button_event(struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) unsigned long action, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct rave_sp_power_button *pb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) container_of(nb, struct rave_sp_power_button, nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) const u8 event = rave_sp_action_unpack_event(action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) const u8 value = rave_sp_action_unpack_value(action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct input_dev *idev = pb->idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (event == RAVE_SP_EVNT_BUTTON_PRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) input_report_key(idev, KEY_POWER, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) input_sync(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return NOTIFY_STOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static int rave_sp_pwrbutton_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct rave_sp_power_button *pb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct input_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) pb = devm_kzalloc(dev, sizeof(*pb), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (!pb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) idev = devm_input_allocate_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) idev->name = pdev->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) input_set_capability(idev, EV_KEY, KEY_POWER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) error = input_register_device(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) pb->idev = idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) pb->nb.notifier_call = rave_sp_power_button_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) pb->nb.priority = 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) error = devm_rave_sp_register_event_notifier(dev, &pb->nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static const struct of_device_id rave_sp_pwrbutton_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) { .compatible = "zii,rave-sp-pwrbutton" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static struct platform_driver rave_sp_pwrbutton_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .probe = rave_sp_pwrbutton_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) .of_match_table = rave_sp_pwrbutton_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) module_platform_driver(rave_sp_pwrbutton_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) MODULE_DEVICE_TABLE(of, rave_sp_pwrbutton_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) MODULE_AUTHOR("Andrey Vostrikov <andrey.vostrikov@cogentembedded.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) MODULE_AUTHOR("Nikita Yushchenko <nikita.yoush@cogentembedded.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) MODULE_AUTHOR("Andrey Smirnov <andrew.smirnov@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) MODULE_DESCRIPTION("RAVE SP Power Button driver");