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