1  /* SPDX-License-Identifier: GPL-2.0 */
2  #ifndef _MATRIX_KEYPAD_H
3  #define _MATRIX_KEYPAD_H
4  
5  #include <linux/types.h>
6  
7  struct device;
8  struct input_dev;
9  
10  #define MATRIX_MAX_ROWS		32
11  #define MATRIX_MAX_COLS		32
12  
13  #define KEY(row, col, val)	((((row) & (MATRIX_MAX_ROWS - 1)) << 24) |\
14  				 (((col) & (MATRIX_MAX_COLS - 1)) << 16) |\
15  				 ((val) & 0xffff))
16  
17  #define KEY_ROW(k)		(((k) >> 24) & 0xff)
18  #define KEY_COL(k)		(((k) >> 16) & 0xff)
19  #define KEY_VAL(k)		((k) & 0xffff)
20  
21  #define MATRIX_SCAN_CODE(row, col, row_shift)	(((row) << (row_shift)) + (col))
22  
23  /**
24   * struct matrix_keymap_data - keymap for matrix keyboards
25   * @keymap: pointer to array of uint32 values encoded with KEY() macro
26   *	representing keymap
27   * @keymap_size: number of entries (initialized) in this keymap
28   *
29   * This structure is supposed to be used by platform code to supply
30   * keymaps to drivers that implement matrix-like keypads/keyboards.
31   */
32  struct matrix_keymap_data {
33  	const uint32_t *keymap;
34  	unsigned int	keymap_size;
35  };
36  
37  int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data,
38  			       const char *keymap_name,
39  			       unsigned int rows, unsigned int cols,
40  			       unsigned short *keymap,
41  			       struct input_dev *input_dev);
42  int matrix_keypad_parse_properties(struct device *dev,
43  				   unsigned int *rows, unsigned int *cols);
44  
45  #endif /* _MATRIX_KEYPAD_H */
46