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