matrix_keypad.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 32
  7. #define MATRIX_MAX_COLS 32
  8. #define KEY(row, col, val) ((((row) & (MATRIX_MAX_ROWS - 1)) << 24) |\
  9. (((col) & (MATRIX_MAX_COLS - 1)) << 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. int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data,
  65. const char *keymap_name,
  66. unsigned int rows, unsigned int cols,
  67. unsigned short *keymap,
  68. struct input_dev *input_dev);
  69. #ifdef CONFIG_OF
  70. /**
  71. * matrix_keypad_parse_of_params() - Read parameters from matrix-keypad node
  72. *
  73. * @dev: Device containing of_node
  74. * @rows: Returns number of matrix rows
  75. * @cols: Returns number of matrix columns
  76. * @return 0 if OK, <0 on error
  77. */
  78. int matrix_keypad_parse_of_params(struct device *dev,
  79. unsigned int *rows, unsigned int *cols);
  80. #else
  81. static inline int matrix_keypad_parse_of_params(struct device *dev,
  82. unsigned int *rows, unsigned int *cols)
  83. {
  84. return -ENOSYS;
  85. }
  86. #endif /* CONFIG_OF */
  87. #endif /* _MATRIX_KEYPAD_H */