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