matrix_keypad.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _MATRIX_KEYPAD_H
  3. #define _MATRIX_KEYPAD_H
  4. #include <linux/types.h>
  5. #include <linux/input.h>
  6. #include <linux/of.h>
  7. #define MATRIX_MAX_ROWS 32
  8. #define MATRIX_MAX_COLS 32
  9. #define KEY(row, col, val) ((((row) & (MATRIX_MAX_ROWS - 1)) << 24) |\
  10. (((col) & (MATRIX_MAX_COLS - 1)) << 16) |\
  11. ((val) & 0xffff))
  12. #define KEY_ROW(k) (((k) >> 24) & 0xff)
  13. #define KEY_COL(k) (((k) >> 16) & 0xff)
  14. #define KEY_VAL(k) ((k) & 0xffff)
  15. #define MATRIX_SCAN_CODE(row, col, row_shift) (((row) << (row_shift)) + (col))
  16. /**
  17. * struct matrix_keymap_data - keymap for matrix keyboards
  18. * @keymap: pointer to array of uint32 values encoded with KEY() macro
  19. * representing keymap
  20. * @keymap_size: number of entries (initialized) in this keymap
  21. *
  22. * This structure is supposed to be used by platform code to supply
  23. * keymaps to drivers that implement matrix-like keypads/keyboards.
  24. */
  25. struct matrix_keymap_data {
  26. const uint32_t *keymap;
  27. unsigned int keymap_size;
  28. };
  29. /**
  30. * struct matrix_keypad_platform_data - platform-dependent keypad data
  31. * @keymap_data: pointer to &matrix_keymap_data
  32. * @row_gpios: pointer to array of gpio numbers representing rows
  33. * @col_gpios: pointer to array of gpio numbers reporesenting colums
  34. * @num_row_gpios: actual number of row gpios used by device
  35. * @num_col_gpios: actual number of col gpios used by device
  36. * @col_scan_delay_us: delay, measured in microseconds, that is
  37. * needed before we can keypad after activating column gpio
  38. * @debounce_ms: debounce interval in milliseconds
  39. * @clustered_irq: may be specified if interrupts of all row/column GPIOs
  40. * are bundled to one single irq
  41. * @clustered_irq_flags: flags that are needed for the clustered irq
  42. * @active_low: gpio polarity
  43. * @wakeup: controls whether the device should be set up as wakeup
  44. * source
  45. * @no_autorepeat: disable key autorepeat
  46. * @drive_inactive_cols: drive inactive columns during scan, rather than
  47. * making them inputs.
  48. *
  49. * This structure represents platform-specific data that use used by
  50. * matrix_keypad driver to perform proper initialization.
  51. */
  52. struct matrix_keypad_platform_data {
  53. const struct matrix_keymap_data *keymap_data;
  54. const unsigned int *row_gpios;
  55. const unsigned int *col_gpios;
  56. unsigned int num_row_gpios;
  57. unsigned int num_col_gpios;
  58. unsigned int col_scan_delay_us;
  59. /* key debounce interval in milli-second */
  60. unsigned int debounce_ms;
  61. unsigned int clustered_irq;
  62. unsigned int clustered_irq_flags;
  63. bool active_low;
  64. bool wakeup;
  65. bool no_autorepeat;
  66. bool drive_inactive_cols;
  67. };
  68. int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data,
  69. const char *keymap_name,
  70. unsigned int rows, unsigned int cols,
  71. unsigned short *keymap,
  72. struct input_dev *input_dev);
  73. int matrix_keypad_parse_properties(struct device *dev,
  74. unsigned int *rows, unsigned int *cols);
  75. #define matrix_keypad_parse_of_params matrix_keypad_parse_properties
  76. #endif /* _MATRIX_KEYPAD_H */