20 #include <linux/device.h>
21 #include <linux/kernel.h>
22 #include <linux/types.h>
23 #include <linux/input.h>
25 #include <linux/export.h>
26 #include <linux/module.h>
29 static bool matrix_keypad_map_key(
struct input_dev *input_dev,
30 unsigned int rows,
unsigned int cols,
31 unsigned int row_shift,
unsigned int key)
33 unsigned short *keymap = input_dev->keycode;
34 unsigned int row =
KEY_ROW(key);
35 unsigned int col =
KEY_COL(key);
38 if (row >= rows || col >= cols) {
40 "%s: invalid keymap entry 0x%x (row: %d, col: %d, rows: %d, cols: %d)\n",
41 __func__, key, row, col, rows, cols);
52 static int matrix_keypad_parse_of_keymap(
const char *propname,
53 unsigned int rows,
unsigned int cols,
54 struct input_dev *input_dev)
56 struct device *
dev = input_dev->dev.parent;
58 unsigned int row_shift = get_count_order(cols);
59 unsigned int max_keys = rows << row_shift;
60 unsigned int proplen,
i,
size;
67 propname =
"linux,keymap";
71 dev_err(dev,
"OF: %s property not defined in %s\n",
76 if (proplen %
sizeof(
u32)) {
77 dev_err(dev,
"OF: Malformed keycode property %s in %s\n",
82 size = proplen /
sizeof(
u32);
83 if (size > max_keys) {
84 dev_err(dev,
"OF: %s size overflow\n", propname);
88 for (i = 0; i <
size; i++) {
91 if (!matrix_keypad_map_key(input_dev, rows, cols,
99 static int matrix_keypad_parse_of_keymap(
const char *propname,
100 unsigned int rows,
unsigned int cols,
101 struct input_dev *input_dev)
130 const char *keymap_name,
131 unsigned int rows,
unsigned int cols,
132 unsigned short *keymap,
133 struct input_dev *input_dev)
135 unsigned int row_shift = get_count_order(cols);
139 input_dev->keycode = keymap;
140 input_dev->keycodesize =
sizeof(*keymap);
141 input_dev->keycodemax = rows << row_shift;
147 unsigned int key = keymap_data->
keymap[
i];
149 if (!matrix_keypad_map_key(input_dev, rows, cols,
154 error = matrix_keypad_parse_of_keymap(keymap_name, rows, cols,