key_matrix.h 2.7 KB

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