sparse-keymap.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. #ifndef _SPARSE_KEYMAP_H
  3. #define _SPARSE_KEYMAP_H
  4. /*
  5. * Copyright (c) 2009 Dmitry Torokhov
  6. */
  7. #define KE_END 0 /* Indicates end of keymap */
  8. #define KE_KEY 1 /* Ordinary key/button */
  9. #define KE_SW 2 /* Switch (predetermined value) */
  10. #define KE_VSW 3 /* Switch (value supplied at runtime) */
  11. #define KE_IGNORE 4 /* Known entry that should be ignored */
  12. #define KE_LAST KE_IGNORE
  13. /**
  14. * struct key_entry - keymap entry for use in sparse keymap
  15. * @type: Type of the key entry (KE_KEY, KE_SW, KE_VSW, KE_END);
  16. * drivers are allowed to extend the list with their own
  17. * private definitions.
  18. * @code: Device-specific data identifying the button/switch
  19. * @keycode: KEY_* code assigned to a key/button
  20. * @sw: struct with code/value used by KE_SW and KE_VSW
  21. * @sw.code: SW_* code assigned to a switch
  22. * @sw.value: Value that should be sent in an input even when KE_SW
  23. * switch is toggled. KE_VSW switches ignore this field and
  24. * expect driver to supply value for the event.
  25. *
  26. * This structure defines an entry in a sparse keymap used by some
  27. * input devices for which traditional table-based approach is not
  28. * suitable.
  29. */
  30. struct key_entry {
  31. int type; /* See KE_* above */
  32. u32 code;
  33. union {
  34. u16 keycode; /* For KE_KEY */
  35. struct { /* For KE_SW, KE_VSW */
  36. u8 code;
  37. u8 value; /* For KE_SW, ignored by KE_VSW */
  38. } sw;
  39. };
  40. };
  41. struct key_entry *sparse_keymap_entry_from_scancode(struct input_dev *dev,
  42. unsigned int code);
  43. struct key_entry *sparse_keymap_entry_from_keycode(struct input_dev *dev,
  44. unsigned int code);
  45. int sparse_keymap_setup(struct input_dev *dev,
  46. const struct key_entry *keymap,
  47. int (*setup)(struct input_dev *, struct key_entry *));
  48. void sparse_keymap_report_entry(struct input_dev *dev, const struct key_entry *ke,
  49. unsigned int value, bool autorelease);
  50. bool sparse_keymap_report_event(struct input_dev *dev, unsigned int code,
  51. unsigned int value, bool autorelease);
  52. #endif /* _SPARSE_KEYMAP_H */