key_matrix.h 3.5 KB

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