Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Bernie Thompson | 92c27c5 | 2012-04-17 09:01:31 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Keyboard matrix helper functions |
| 4 | * |
| 5 | * Copyright (c) 2012 The Chromium OS Authors. |
Bernie Thompson | 92c27c5 | 2012-04-17 09:01:31 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _KEY_MATRIX_H |
| 9 | #define _KEY_MATRIX_H |
| 10 | |
Bernie Thompson | 92c27c5 | 2012-04-17 09:01:31 +0000 | [diff] [blame] | 11 | /* Information about a matrix keyboard */ |
| 12 | struct key_matrix { |
| 13 | /* Dimensions of the keyboard matrix, in rows and columns */ |
| 14 | int num_rows; |
| 15 | int num_cols; |
| 16 | int key_count; /* number of keys in the matrix (= rows * cols) */ |
| 17 | |
| 18 | /* |
| 19 | * Information about keycode mappings. The plain_keycode array must |
| 20 | * exist but fn may be NULL in which case it is not decoded. |
| 21 | */ |
| 22 | const u8 *plain_keycode; /* key code for each row / column */ |
| 23 | const u8 *fn_keycode; /* ...when Fn held down */ |
| 24 | int fn_pos; /* position of Fn key in key (or -1) */ |
Simon Glass | 71dc6bc | 2012-09-27 15:18:42 +0000 | [diff] [blame] | 25 | int ghost_filter; /* non-zero to enable ghost filter */ |
Bernie Thompson | 92c27c5 | 2012-04-17 09:01:31 +0000 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | /* Information about a particular key (row, column pair) in the matrix */ |
| 29 | struct key_matrix_key { |
| 30 | uint8_t row; /* row number (0 = first) */ |
| 31 | uint8_t col; /* column number (0 = first) */ |
| 32 | uint8_t valid; /* 1 if valid, 0 to ignore this */ |
| 33 | }; |
| 34 | |
| 35 | /** |
| 36 | * Decode a set of pressed keys into key codes |
| 37 | * |
| 38 | * Given a list of keys that are pressed, this converts this list into |
| 39 | * a list of key codes. Each of the keys has a valid flag, which can be |
| 40 | * used to mark a particular key as invalid (so that it is ignored). |
| 41 | * |
| 42 | * The plain keymap is used, unless the Fn key is detected along the way, |
| 43 | * at which point we switch to the Fn key map. |
| 44 | * |
| 45 | * If key ghosting is detected, we simply ignore the keys and return 0. |
| 46 | * |
| 47 | * @param config Keyboard matrix config |
| 48 | * @param keys List of keys to process (each is row, col) |
| 49 | * @param num_keys Number of keys to process |
| 50 | * @param keycode Returns a list of key codes, decoded from input |
| 51 | * @param max_keycodes Size of key codes array (suggest 8) |
| 52 | * |
| 53 | */ |
| 54 | int key_matrix_decode(struct key_matrix *config, struct key_matrix_key *keys, |
| 55 | int num_keys, int keycode[], int max_keycodes); |
| 56 | |
| 57 | /** |
| 58 | * Read the keyboard configuration out of the fdt. |
| 59 | * |
| 60 | * Decode properties of named "linux,<type>keymap" where <type> is either |
| 61 | * empty, or "fn-". Then set up the plain key map (and the FN keymap if |
| 62 | * present). |
| 63 | * |
| 64 | * @param config Keyboard matrix config |
| 65 | * @param blob FDT blob |
| 66 | * @param node Node containing compatible data |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 67 | * Return: 0 if ok, -1 on error |
Bernie Thompson | 92c27c5 | 2012-04-17 09:01:31 +0000 | [diff] [blame] | 68 | */ |
Simon Glass | 8327d41 | 2017-05-18 20:09:53 -0600 | [diff] [blame] | 69 | int key_matrix_decode_fdt(struct udevice *dev, struct key_matrix *config); |
Bernie Thompson | 92c27c5 | 2012-04-17 09:01:31 +0000 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Set up a new key matrix. |
| 73 | * |
| 74 | * @param config Keyboard matrix config |
| 75 | * @param rows Number of rows in key matrix |
| 76 | * @param cols Number of columns in key matrix |
Simon Glass | 71dc6bc | 2012-09-27 15:18:42 +0000 | [diff] [blame] | 77 | * @param ghost_filter Non-zero to enable ghost filtering |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 78 | * Return: 0 if ok, -1 on error |
Bernie Thompson | 92c27c5 | 2012-04-17 09:01:31 +0000 | [diff] [blame] | 79 | */ |
Simon Glass | 71dc6bc | 2012-09-27 15:18:42 +0000 | [diff] [blame] | 80 | int key_matrix_init(struct key_matrix *config, int rows, int cols, |
| 81 | int ghost_filter); |
Bernie Thompson | 92c27c5 | 2012-04-17 09:01:31 +0000 | [diff] [blame] | 82 | |
| 83 | #endif |