key_matrix.h 2.7 KB

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