/include/linux/input/matrix_keypad.h

https://github.com/airy09/android_kernel_sony_apq8064 · C Header · 128 lines · 64 code · 20 blank · 44 comment · 1 complexity · da2f2eeeb20799081b39c91f9d5e6a91 MD5 · raw file

  1. #ifndef _MATRIX_KEYPAD_H
  2. #define _MATRIX_KEYPAD_H
  3. #include <linux/types.h>
  4. #include <linux/input.h>
  5. #include <linux/of.h>
  6. #define MATRIX_MAX_ROWS 18
  7. #define MATRIX_MAX_COLS 18
  8. #define KEY(row, col, val) ((((row) % (MATRIX_MAX_ROWS)) << 24) |\
  9. (((col) % (MATRIX_MAX_COLS)) << 16) |\
  10. (val & 0xffff))
  11. #define KEY_ROW(k) (((k) >> 24) & 0xff)
  12. #define KEY_COL(k) (((k) >> 16) & 0xff)
  13. #define KEY_VAL(k) ((k) & 0xffff)
  14. #define MATRIX_SCAN_CODE(row, col, row_shift) (((row) << (row_shift)) + (col))
  15. /**
  16. * struct matrix_keymap_data - keymap for matrix keyboards
  17. * @keymap: pointer to array of uint32 values encoded with KEY() macro
  18. * representing keymap
  19. * @keymap_size: number of entries (initialized) in this keymap
  20. *
  21. * This structure is supposed to be used by platform code to supply
  22. * keymaps to drivers that implement matrix-like keypads/keyboards.
  23. */
  24. struct matrix_keymap_data {
  25. const uint32_t *keymap;
  26. unsigned int keymap_size;
  27. };
  28. /**
  29. * struct matrix_keypad_platform_data - platform-dependent keypad data
  30. * @keymap_data: pointer to &matrix_keymap_data
  31. * @row_gpios: pointer to array of gpio numbers representing rows
  32. * @col_gpios: pointer to array of gpio numbers reporesenting colums
  33. * @num_row_gpios: actual number of row gpios used by device
  34. * @num_col_gpios: actual number of col gpios used by device
  35. * @col_scan_delay_us: delay, measured in microseconds, that is
  36. * needed before we can keypad after activating column gpio
  37. * @debounce_ms: debounce interval in milliseconds
  38. * @clustered_irq: may be specified if interrupts of all row/column GPIOs
  39. * are bundled to one single irq
  40. * @clustered_irq_flags: flags that are needed for the clustered irq
  41. * @active_low: gpio polarity
  42. * @wakeup: controls whether the device should be set up as wakeup
  43. * source
  44. * @no_autorepeat: disable key autorepeat
  45. *
  46. * This structure represents platform-specific data that use used by
  47. * matrix_keypad driver to perform proper initialization.
  48. */
  49. struct matrix_keypad_platform_data {
  50. const struct matrix_keymap_data *keymap_data;
  51. const unsigned int *row_gpios;
  52. const unsigned int *col_gpios;
  53. unsigned int num_row_gpios;
  54. unsigned int num_col_gpios;
  55. unsigned int col_scan_delay_us;
  56. /* key debounce interval in milli-second */
  57. unsigned int debounce_ms;
  58. unsigned int clustered_irq;
  59. unsigned int clustered_irq_flags;
  60. bool active_low;
  61. bool wakeup;
  62. bool no_autorepeat;
  63. };
  64. /**
  65. * matrix_keypad_build_keymap - convert platform keymap into matrix keymap
  66. * @keymap_data: keymap supplied by the platform code
  67. * @row_shift: number of bits to shift row value by to advance to the next
  68. * line in the keymap
  69. * @keymap: expanded version of keymap that is suitable for use by
  70. * matrix keyboad driver
  71. * @keybit: pointer to bitmap of keys supported by input device
  72. *
  73. * This function converts platform keymap (encoded with KEY() macro) into
  74. * an array of keycodes that is suitable for using in a standard matrix
  75. * keyboard driver that uses row and col as indices.
  76. */
  77. static inline void
  78. matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data,
  79. unsigned int row_shift,
  80. unsigned short *keymap, unsigned long *keybit)
  81. {
  82. int i;
  83. for (i = 0; i < keymap_data->keymap_size; i++) {
  84. unsigned int key = keymap_data->keymap[i];
  85. unsigned int row = KEY_ROW(key);
  86. unsigned int col = KEY_COL(key);
  87. unsigned short code = KEY_VAL(key);
  88. keymap[MATRIX_SCAN_CODE(row, col, row_shift)] = code;
  89. __set_bit(code, keybit);
  90. }
  91. __clear_bit(KEY_RESERVED, keybit);
  92. }
  93. #ifdef CONFIG_INPUT_OF_MATRIX_KEYMAP
  94. struct matrix_keymap_data *
  95. matrix_keyboard_of_fill_keymap(struct device_node *np, const char *propname);
  96. void matrix_keyboard_of_free_keymap(const struct matrix_keymap_data *kd);
  97. #else
  98. static inline struct matrix_keymap_data *
  99. matrix_keyboard_of_fill_keymap(struct device_node *np, const char *propname)
  100. {
  101. return NULL;
  102. }
  103. static inline void
  104. matrix_keyboard_of_free_keymap(const struct matrix_keymap_data *kd)
  105. {
  106. }
  107. #endif
  108. #endif /* _MATRIX_KEYPAD_H */