rave-sp-pwrbutton.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #include <linux/input.h>
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/mfd/rave-sp.h>
  12. #include <linux/platform_device.h>
  13. #define RAVE_SP_EVNT_BUTTON_PRESS (RAVE_SP_EVNT_BASE + 0x00)
  14. struct rave_sp_power_button {
  15. struct input_dev *idev;
  16. struct notifier_block nb;
  17. };
  18. static int rave_sp_power_button_event(struct notifier_block *nb,
  19. unsigned long action, void *data)
  20. {
  21. struct rave_sp_power_button *pb =
  22. container_of(nb, struct rave_sp_power_button, nb);
  23. const u8 event = rave_sp_action_unpack_event(action);
  24. const u8 value = rave_sp_action_unpack_value(action);
  25. struct input_dev *idev = pb->idev;
  26. if (event == RAVE_SP_EVNT_BUTTON_PRESS) {
  27. input_report_key(idev, KEY_POWER, value);
  28. input_sync(idev);
  29. return NOTIFY_STOP;
  30. }
  31. return NOTIFY_DONE;
  32. }
  33. static int rave_sp_pwrbutton_probe(struct platform_device *pdev)
  34. {
  35. struct device *dev = &pdev->dev;
  36. struct rave_sp_power_button *pb;
  37. struct input_dev *idev;
  38. int error;
  39. pb = devm_kzalloc(dev, sizeof(*pb), GFP_KERNEL);
  40. if (!pb)
  41. return -ENOMEM;
  42. idev = devm_input_allocate_device(dev);
  43. if (!idev)
  44. return -ENOMEM;
  45. idev->name = pdev->name;
  46. input_set_capability(idev, EV_KEY, KEY_POWER);
  47. error = input_register_device(idev);
  48. if (error)
  49. return error;
  50. pb->idev = idev;
  51. pb->nb.notifier_call = rave_sp_power_button_event;
  52. pb->nb.priority = 128;
  53. error = devm_rave_sp_register_event_notifier(dev, &pb->nb);
  54. if (error)
  55. return error;
  56. return 0;
  57. }
  58. static const struct of_device_id rave_sp_pwrbutton_of_match[] = {
  59. { .compatible = "zii,rave-sp-pwrbutton" },
  60. {}
  61. };
  62. static struct platform_driver rave_sp_pwrbutton_driver = {
  63. .probe = rave_sp_pwrbutton_probe,
  64. .driver = {
  65. .name = KBUILD_MODNAME,
  66. .of_match_table = rave_sp_pwrbutton_of_match,
  67. },
  68. };
  69. module_platform_driver(rave_sp_pwrbutton_driver);
  70. MODULE_DEVICE_TABLE(of, rave_sp_pwrbutton_of_match);
  71. MODULE_LICENSE("GPL");
  72. MODULE_AUTHOR("Andrey Vostrikov <[email protected]>");
  73. MODULE_AUTHOR("Nikita Yushchenko <[email protected]>");
  74. MODULE_AUTHOR("Andrey Smirnov <[email protected]>");
  75. MODULE_DESCRIPTION("RAVE SP Power Button driver");