xref: /rk3399_rockchip-uboot/include/key_matrix.h (revision 71dc6bca4ef61d10f1327114ac1d53b6865a6030)
192c27c51SBernie Thompson /*
292c27c51SBernie Thompson  * Keyboard matrix helper functions
392c27c51SBernie Thompson  *
492c27c51SBernie Thompson  * Copyright (c) 2012 The Chromium OS Authors.
592c27c51SBernie Thompson  * See file CREDITS for list of people who contributed to this
692c27c51SBernie Thompson  * project.
792c27c51SBernie Thompson  *
892c27c51SBernie Thompson  * This program is free software; you can redistribute it and/or
992c27c51SBernie Thompson  * modify it under the terms of the GNU General Public License as
1092c27c51SBernie Thompson  * published by the Free Software Foundation; either version 2 of
1192c27c51SBernie Thompson  * the License, or (at your option) any later version.
1292c27c51SBernie Thompson  *
1392c27c51SBernie Thompson  * This program is distributed in the hope that it will be useful,
1492c27c51SBernie Thompson  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1592c27c51SBernie Thompson  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1692c27c51SBernie Thompson  * GNU General Public License for more details.
1792c27c51SBernie Thompson  *
1892c27c51SBernie Thompson  * You should have received a copy of the GNU General Public License
1992c27c51SBernie Thompson  * along with this program; if not, write to the Free Software
2092c27c51SBernie Thompson  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
2192c27c51SBernie Thompson  * MA 02111-1307 USA
2292c27c51SBernie Thompson  */
2392c27c51SBernie Thompson 
2492c27c51SBernie Thompson #ifndef _KEY_MATRIX_H
2592c27c51SBernie Thompson #define _KEY_MATRIX_H
2692c27c51SBernie Thompson 
2792c27c51SBernie Thompson #include <common.h>
2892c27c51SBernie Thompson 
2992c27c51SBernie Thompson /* Information about a matrix keyboard */
3092c27c51SBernie Thompson struct key_matrix {
3192c27c51SBernie Thompson 	/* Dimensions of the keyboard matrix, in rows and columns */
3292c27c51SBernie Thompson 	int num_rows;
3392c27c51SBernie Thompson 	int num_cols;
3492c27c51SBernie Thompson 	int key_count;	/* number of keys in the matrix (= rows * cols) */
3592c27c51SBernie Thompson 
3692c27c51SBernie Thompson 	/*
3792c27c51SBernie Thompson 	 * Information about keycode mappings. The plain_keycode array must
3892c27c51SBernie Thompson 	 * exist but fn may be NULL in which case it is not decoded.
3992c27c51SBernie Thompson 	 */
4092c27c51SBernie Thompson 	const u8 *plain_keycode;        /* key code for each row / column */
4192c27c51SBernie Thompson 	const u8 *fn_keycode;           /* ...when Fn held down */
4292c27c51SBernie Thompson 	int fn_pos;                     /* position of Fn key in key (or -1) */
43*71dc6bcaSSimon Glass 	int ghost_filter;		/* non-zero to enable ghost filter */
4492c27c51SBernie Thompson };
4592c27c51SBernie Thompson 
4692c27c51SBernie Thompson /* Information about a particular key (row, column pair) in the matrix */
4792c27c51SBernie Thompson struct key_matrix_key {
4892c27c51SBernie Thompson 	uint8_t row;	/* row number (0 = first) */
4992c27c51SBernie Thompson 	uint8_t col;	/* column number (0 = first) */
5092c27c51SBernie Thompson 	uint8_t valid;	/* 1 if valid, 0 to ignore this */
5192c27c51SBernie Thompson };
5292c27c51SBernie Thompson 
5392c27c51SBernie Thompson /**
5492c27c51SBernie Thompson  * Decode a set of pressed keys into key codes
5592c27c51SBernie Thompson  *
5692c27c51SBernie Thompson  * Given a list of keys that are pressed, this converts this list into
5792c27c51SBernie Thompson  * a list of key codes. Each of the keys has a valid flag, which can be
5892c27c51SBernie Thompson  * used to mark a particular key as invalid (so that it is ignored).
5992c27c51SBernie Thompson  *
6092c27c51SBernie Thompson  * The plain keymap is used, unless the Fn key is detected along the way,
6192c27c51SBernie Thompson  * at which point we switch to the Fn key map.
6292c27c51SBernie Thompson  *
6392c27c51SBernie Thompson  * If key ghosting is detected, we simply ignore the keys and return 0.
6492c27c51SBernie Thompson  *
6592c27c51SBernie Thompson  * @param config        Keyboard matrix config
6692c27c51SBernie Thompson  * @param keys		List of keys to process (each is row, col)
6792c27c51SBernie Thompson  * @param num_keys	Number of keys to process
6892c27c51SBernie Thompson  * @param keycode	Returns a list of key codes, decoded from input
6992c27c51SBernie Thompson  * @param max_keycodes	Size of key codes array (suggest 8)
7092c27c51SBernie Thompson  *
7192c27c51SBernie Thompson  */
7292c27c51SBernie Thompson int key_matrix_decode(struct key_matrix *config, struct key_matrix_key *keys,
7392c27c51SBernie Thompson 		      int num_keys, int keycode[], int max_keycodes);
7492c27c51SBernie Thompson 
7592c27c51SBernie Thompson /**
7692c27c51SBernie Thompson  * Read the keyboard configuration out of the fdt.
7792c27c51SBernie Thompson  *
7892c27c51SBernie Thompson  * Decode properties of named "linux,<type>keymap" where <type> is either
7992c27c51SBernie Thompson  * empty, or "fn-". Then set up the plain key map (and the FN keymap if
8092c27c51SBernie Thompson  * present).
8192c27c51SBernie Thompson  *
8292c27c51SBernie Thompson  * @param config        Keyboard matrix config
8392c27c51SBernie Thompson  * @param blob          FDT blob
8492c27c51SBernie Thompson  * @param node          Node containing compatible data
8592c27c51SBernie Thompson  * @return 0 if ok, -1 on error
8692c27c51SBernie Thompson  */
8792c27c51SBernie Thompson int key_matrix_decode_fdt(struct key_matrix *config, const void *blob,
8892c27c51SBernie Thompson 			  int node);
8992c27c51SBernie Thompson 
9092c27c51SBernie Thompson /**
9192c27c51SBernie Thompson  * Set up a new key matrix.
9292c27c51SBernie Thompson  *
9392c27c51SBernie Thompson  * @param config	Keyboard matrix config
9492c27c51SBernie Thompson  * @param rows		Number of rows in key matrix
9592c27c51SBernie Thompson  * @param cols		Number of columns in key matrix
96*71dc6bcaSSimon Glass  * @param ghost_filter	Non-zero to enable ghost filtering
9792c27c51SBernie Thompson  * @return 0 if ok, -1 on error
9892c27c51SBernie Thompson  */
99*71dc6bcaSSimon Glass int key_matrix_init(struct key_matrix *config, int rows, int cols,
100*71dc6bcaSSimon Glass 		    int ghost_filter);
10192c27c51SBernie Thompson 
10292c27c51SBernie Thompson #endif
103