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