1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _MATRIX_KEYPAD_H
3#define _MATRIX_KEYPAD_H
4
5#include <linux/types.h>
6
7struct device;
8struct 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 */
32struct matrix_keymap_data {
33 const uint32_t *keymap;
34 unsigned int keymap_size;
35};
36
37/**
38 * struct matrix_keypad_platform_data - platform-dependent keypad data
39 * @keymap_data: pointer to &matrix_keymap_data
40 * @row_gpios: pointer to array of gpio numbers representing rows
41 * @col_gpios: pointer to array of gpio numbers reporesenting colums
42 * @num_row_gpios: actual number of row gpios used by device
43 * @num_col_gpios: actual number of col gpios used by device
44 * @col_scan_delay_us: delay, measured in microseconds, that is
45 * needed before we can keypad after activating column gpio
46 * @debounce_ms: debounce interval in milliseconds
47 * @clustered_irq: may be specified if interrupts of all row/column GPIOs
48 * are bundled to one single irq
49 * @clustered_irq_flags: flags that are needed for the clustered irq
50 * @active_low: gpio polarity
51 * @wakeup: controls whether the device should be set up as wakeup
52 * source
53 * @no_autorepeat: disable key autorepeat
54 * @drive_inactive_cols: drive inactive columns during scan, rather than
55 * making them inputs.
56 *
57 * This structure represents platform-specific data that use used by
58 * matrix_keypad driver to perform proper initialization.
59 */
60struct matrix_keypad_platform_data {
61 const struct matrix_keymap_data *keymap_data;
62
63 const unsigned int *row_gpios;
64 const unsigned int *col_gpios;
65
66 unsigned int num_row_gpios;
67 unsigned int num_col_gpios;
68
69 unsigned int col_scan_delay_us;
70
71 /* key debounce interval in milli-second */
72 unsigned int debounce_ms;
73
74 unsigned int clustered_irq;
75 unsigned int clustered_irq_flags;
76
77 bool active_low;
78 bool wakeup;
79 bool no_autorepeat;
80 bool drive_inactive_cols;
81};
82
83int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data,
84 const char *keymap_name,
85 unsigned int rows, unsigned int cols,
86 unsigned short *keymap,
87 struct input_dev *input_dev);
88int matrix_keypad_parse_properties(struct device *dev,
89 unsigned int *rows, unsigned int *cols);
90
91#define matrix_keypad_parse_of_params matrix_keypad_parse_properties
92
93#endif /* _MATRIX_KEYPAD_H */
94

source code of linux/include/linux/input/matrix_keypad.h