1*92c27c51SBernie Thompson /* 2*92c27c51SBernie Thompson * Keyboard matrix helper functions 3*92c27c51SBernie Thompson * 4*92c27c51SBernie Thompson * Copyright (c) 2012 The Chromium OS Authors. 5*92c27c51SBernie Thompson * See file CREDITS for list of people who contributed to this 6*92c27c51SBernie Thompson * project. 7*92c27c51SBernie Thompson * 8*92c27c51SBernie Thompson * This program is free software; you can redistribute it and/or 9*92c27c51SBernie Thompson * modify it under the terms of the GNU General Public License as 10*92c27c51SBernie Thompson * published by the Free Software Foundation; either version 2 of 11*92c27c51SBernie Thompson * the License, or (at your option) any later version. 12*92c27c51SBernie Thompson * 13*92c27c51SBernie Thompson * This program is distributed in the hope that it will be useful, 14*92c27c51SBernie Thompson * but WITHOUT ANY WARRANTY; without even the implied warranty of 15*92c27c51SBernie Thompson * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*92c27c51SBernie Thompson * GNU General Public License for more details. 17*92c27c51SBernie Thompson * 18*92c27c51SBernie Thompson * You should have received a copy of the GNU General Public License 19*92c27c51SBernie Thompson * along with this program; if not, write to the Free Software 20*92c27c51SBernie Thompson * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21*92c27c51SBernie Thompson * MA 02111-1307 USA 22*92c27c51SBernie Thompson */ 23*92c27c51SBernie Thompson 24*92c27c51SBernie Thompson #ifndef _KEY_MATRIX_H 25*92c27c51SBernie Thompson #define _KEY_MATRIX_H 26*92c27c51SBernie Thompson 27*92c27c51SBernie Thompson #include <common.h> 28*92c27c51SBernie Thompson 29*92c27c51SBernie Thompson /* Information about a matrix keyboard */ 30*92c27c51SBernie Thompson struct key_matrix { 31*92c27c51SBernie Thompson /* Dimensions of the keyboard matrix, in rows and columns */ 32*92c27c51SBernie Thompson int num_rows; 33*92c27c51SBernie Thompson int num_cols; 34*92c27c51SBernie Thompson int key_count; /* number of keys in the matrix (= rows * cols) */ 35*92c27c51SBernie Thompson 36*92c27c51SBernie Thompson /* 37*92c27c51SBernie Thompson * Information about keycode mappings. The plain_keycode array must 38*92c27c51SBernie Thompson * exist but fn may be NULL in which case it is not decoded. 39*92c27c51SBernie Thompson */ 40*92c27c51SBernie Thompson const u8 *plain_keycode; /* key code for each row / column */ 41*92c27c51SBernie Thompson const u8 *fn_keycode; /* ...when Fn held down */ 42*92c27c51SBernie Thompson int fn_pos; /* position of Fn key in key (or -1) */ 43*92c27c51SBernie Thompson }; 44*92c27c51SBernie Thompson 45*92c27c51SBernie Thompson /* Information about a particular key (row, column pair) in the matrix */ 46*92c27c51SBernie Thompson struct key_matrix_key { 47*92c27c51SBernie Thompson uint8_t row; /* row number (0 = first) */ 48*92c27c51SBernie Thompson uint8_t col; /* column number (0 = first) */ 49*92c27c51SBernie Thompson uint8_t valid; /* 1 if valid, 0 to ignore this */ 50*92c27c51SBernie Thompson }; 51*92c27c51SBernie Thompson 52*92c27c51SBernie Thompson /** 53*92c27c51SBernie Thompson * Decode a set of pressed keys into key codes 54*92c27c51SBernie Thompson * 55*92c27c51SBernie Thompson * Given a list of keys that are pressed, this converts this list into 56*92c27c51SBernie Thompson * a list of key codes. Each of the keys has a valid flag, which can be 57*92c27c51SBernie Thompson * used to mark a particular key as invalid (so that it is ignored). 58*92c27c51SBernie Thompson * 59*92c27c51SBernie Thompson * The plain keymap is used, unless the Fn key is detected along the way, 60*92c27c51SBernie Thompson * at which point we switch to the Fn key map. 61*92c27c51SBernie Thompson * 62*92c27c51SBernie Thompson * If key ghosting is detected, we simply ignore the keys and return 0. 63*92c27c51SBernie Thompson * 64*92c27c51SBernie Thompson * @param config Keyboard matrix config 65*92c27c51SBernie Thompson * @param keys List of keys to process (each is row, col) 66*92c27c51SBernie Thompson * @param num_keys Number of keys to process 67*92c27c51SBernie Thompson * @param keycode Returns a list of key codes, decoded from input 68*92c27c51SBernie Thompson * @param max_keycodes Size of key codes array (suggest 8) 69*92c27c51SBernie Thompson * 70*92c27c51SBernie Thompson */ 71*92c27c51SBernie Thompson int key_matrix_decode(struct key_matrix *config, struct key_matrix_key *keys, 72*92c27c51SBernie Thompson int num_keys, int keycode[], int max_keycodes); 73*92c27c51SBernie Thompson 74*92c27c51SBernie Thompson /** 75*92c27c51SBernie Thompson * Read the keyboard configuration out of the fdt. 76*92c27c51SBernie Thompson * 77*92c27c51SBernie Thompson * Decode properties of named "linux,<type>keymap" where <type> is either 78*92c27c51SBernie Thompson * empty, or "fn-". Then set up the plain key map (and the FN keymap if 79*92c27c51SBernie Thompson * present). 80*92c27c51SBernie Thompson * 81*92c27c51SBernie Thompson * @param config Keyboard matrix config 82*92c27c51SBernie Thompson * @param blob FDT blob 83*92c27c51SBernie Thompson * @param node Node containing compatible data 84*92c27c51SBernie Thompson * @return 0 if ok, -1 on error 85*92c27c51SBernie Thompson */ 86*92c27c51SBernie Thompson int key_matrix_decode_fdt(struct key_matrix *config, const void *blob, 87*92c27c51SBernie Thompson int node); 88*92c27c51SBernie Thompson 89*92c27c51SBernie Thompson /** 90*92c27c51SBernie Thompson * Set up a new key matrix. 91*92c27c51SBernie Thompson * 92*92c27c51SBernie Thompson * @param config Keyboard matrix config 93*92c27c51SBernie Thompson * @param rows Number of rows in key matrix 94*92c27c51SBernie Thompson * @param cols Number of columns in key matrix 95*92c27c51SBernie Thompson * @return 0 if ok, -1 on error 96*92c27c51SBernie Thompson */ 97*92c27c51SBernie Thompson int key_matrix_init(struct key_matrix *config, int rows, int cols); 98*92c27c51SBernie Thompson 99*92c27c51SBernie Thompson #endif 100