diff options
author | Eric Miao <eric.y.miao@gmail.com> | 2009-08-05 04:24:41 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2009-08-06 01:20:14 -0400 |
commit | d82f1c35348cebe2fb2d4a4d31ce0ab0769e3d93 (patch) | |
tree | 6ff3e1d1d3aea32c86305f6fdf7bee204ad26389 | |
parent | 194934785a846e0a7b1b674b7b475a9d0125d2f8 (diff) |
Input: matrix_keypad - make matrix keymap size dynamic
Remove assumption on the shift and size of rows/columns form
matrix_keypad driver.
Signed-off-by: Eric Miao <eric.y.miao@gmail.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
-rw-r--r-- | drivers/input/keyboard/matrix_keypad.c | 18 | ||||
-rw-r--r-- | include/linux/input/matrix_keypad.h | 13 |
2 files changed, 16 insertions, 15 deletions
diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index e9b2e7cb05be..541b981ff075 100644 --- a/drivers/input/keyboard/matrix_keypad.c +++ b/drivers/input/keyboard/matrix_keypad.c | |||
@@ -27,6 +27,7 @@ struct matrix_keypad { | |||
27 | const struct matrix_keypad_platform_data *pdata; | 27 | const struct matrix_keypad_platform_data *pdata; |
28 | struct input_dev *input_dev; | 28 | struct input_dev *input_dev; |
29 | unsigned short *keycodes; | 29 | unsigned short *keycodes; |
30 | unsigned int row_shift; | ||
30 | 31 | ||
31 | uint32_t last_key_state[MATRIX_MAX_COLS]; | 32 | uint32_t last_key_state[MATRIX_MAX_COLS]; |
32 | struct delayed_work work; | 33 | struct delayed_work work; |
@@ -136,7 +137,7 @@ static void matrix_keypad_scan(struct work_struct *work) | |||
136 | if ((bits_changed & (1 << row)) == 0) | 137 | if ((bits_changed & (1 << row)) == 0) |
137 | continue; | 138 | continue; |
138 | 139 | ||
139 | code = (row << 4) + col; | 140 | code = MATRIX_SCAN_CODE(row, col, keypad->row_shift); |
140 | input_event(input_dev, EV_MSC, MSC_SCAN, code); | 141 | input_event(input_dev, EV_MSC, MSC_SCAN, code); |
141 | input_report_key(input_dev, | 142 | input_report_key(input_dev, |
142 | keypad->keycodes[code], | 143 | keypad->keycodes[code], |
@@ -317,6 +318,7 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev) | |||
317 | struct matrix_keypad *keypad; | 318 | struct matrix_keypad *keypad; |
318 | struct input_dev *input_dev; | 319 | struct input_dev *input_dev; |
319 | unsigned short *keycodes; | 320 | unsigned short *keycodes; |
321 | unsigned int row_shift; | ||
320 | int i; | 322 | int i; |
321 | int err; | 323 | int err; |
322 | 324 | ||
@@ -332,14 +334,11 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev) | |||
332 | return -EINVAL; | 334 | return -EINVAL; |
333 | } | 335 | } |
334 | 336 | ||
335 | if (!keymap_data->max_keymap_size) { | 337 | row_shift = get_count_order(pdata->num_col_gpios); |
336 | dev_err(&pdev->dev, "invalid keymap data supplied\n"); | ||
337 | return -EINVAL; | ||
338 | } | ||
339 | 338 | ||
340 | keypad = kzalloc(sizeof(struct matrix_keypad), GFP_KERNEL); | 339 | keypad = kzalloc(sizeof(struct matrix_keypad), GFP_KERNEL); |
341 | keycodes = kzalloc(keymap_data->max_keymap_size * | 340 | keycodes = kzalloc((pdata->num_row_gpios << row_shift) * |
342 | sizeof(keypad->keycodes), | 341 | sizeof(*keycodes), |
343 | GFP_KERNEL); | 342 | GFP_KERNEL); |
344 | input_dev = input_allocate_device(); | 343 | input_dev = input_allocate_device(); |
345 | if (!keypad || !keycodes || !input_dev) { | 344 | if (!keypad || !keycodes || !input_dev) { |
@@ -350,6 +349,7 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev) | |||
350 | keypad->input_dev = input_dev; | 349 | keypad->input_dev = input_dev; |
351 | keypad->pdata = pdata; | 350 | keypad->pdata = pdata; |
352 | keypad->keycodes = keycodes; | 351 | keypad->keycodes = keycodes; |
352 | keypad->row_shift = row_shift; | ||
353 | keypad->stopped = true; | 353 | keypad->stopped = true; |
354 | INIT_DELAYED_WORK(&keypad->work, matrix_keypad_scan); | 354 | INIT_DELAYED_WORK(&keypad->work, matrix_keypad_scan); |
355 | spin_lock_init(&keypad->lock); | 355 | spin_lock_init(&keypad->lock); |
@@ -363,7 +363,7 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev) | |||
363 | 363 | ||
364 | input_dev->keycode = keycodes; | 364 | input_dev->keycode = keycodes; |
365 | input_dev->keycodesize = sizeof(*keycodes); | 365 | input_dev->keycodesize = sizeof(*keycodes); |
366 | input_dev->keycodemax = keymap_data->max_keymap_size; | 366 | input_dev->keycodemax = pdata->num_row_gpios << keypad->row_shift; |
367 | 367 | ||
368 | for (i = 0; i < keymap_data->keymap_size; i++) { | 368 | for (i = 0; i < keymap_data->keymap_size; i++) { |
369 | unsigned int key = keymap_data->keymap[i]; | 369 | unsigned int key = keymap_data->keymap[i]; |
@@ -371,7 +371,7 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev) | |||
371 | unsigned int col = KEY_COL(key); | 371 | unsigned int col = KEY_COL(key); |
372 | unsigned short code = KEY_VAL(key); | 372 | unsigned short code = KEY_VAL(key); |
373 | 373 | ||
374 | keycodes[(row << 4) + col] = code; | 374 | keycodes[MATRIX_SCAN_CODE(row, col, row_shift)] = code; |
375 | __set_bit(code, input_dev->keybit); | 375 | __set_bit(code, input_dev->keybit); |
376 | } | 376 | } |
377 | __clear_bit(KEY_RESERVED, input_dev->keybit); | 377 | __clear_bit(KEY_RESERVED, input_dev->keybit); |
diff --git a/include/linux/input/matrix_keypad.h b/include/linux/input/matrix_keypad.h index 7964516c6954..15d5903af2dd 100644 --- a/include/linux/input/matrix_keypad.h +++ b/include/linux/input/matrix_keypad.h | |||
@@ -15,12 +15,13 @@ | |||
15 | #define KEY_COL(k) (((k) >> 16) & 0xff) | 15 | #define KEY_COL(k) (((k) >> 16) & 0xff) |
16 | #define KEY_VAL(k) ((k) & 0xffff) | 16 | #define KEY_VAL(k) ((k) & 0xffff) |
17 | 17 | ||
18 | #define MATRIX_SCAN_CODE(row, col, row_shift) (((row) << (row_shift)) + (col)) | ||
19 | |||
18 | /** | 20 | /** |
19 | * struct matrix_keymap_data - keymap for matrix keyboards | 21 | * struct matrix_keymap_data - keymap for matrix keyboards |
20 | * @keymap: pointer to array of uint32 values encoded with KEY() macro | 22 | * @keymap: pointer to array of uint32 values encoded with KEY() macro |
21 | * representing keymap | 23 | * representing keymap |
22 | * @keymap_size: number of entries (initialized) in this keymap | 24 | * @keymap_size: number of entries (initialized) in this keymap |
23 | * @max_keymap_size: maximum size of keymap supported by the device | ||
24 | * | 25 | * |
25 | * This structure is supposed to be used by platform code to supply | 26 | * This structure is supposed to be used by platform code to supply |
26 | * keymaps to drivers that implement matrix-like keypads/keyboards. | 27 | * keymaps to drivers that implement matrix-like keypads/keyboards. |
@@ -28,14 +29,13 @@ | |||
28 | struct matrix_keymap_data { | 29 | struct matrix_keymap_data { |
29 | const uint32_t *keymap; | 30 | const uint32_t *keymap; |
30 | unsigned int keymap_size; | 31 | unsigned int keymap_size; |
31 | unsigned int max_keymap_size; | ||
32 | }; | 32 | }; |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * struct matrix_keypad_platform_data - platform-dependent keypad data | 35 | * struct matrix_keypad_platform_data - platform-dependent keypad data |
36 | * @keymap_data: pointer to &matrix_keymap_data | 36 | * @keymap_data: pointer to &matrix_keymap_data |
37 | * @row_gpios: array of gpio numbers reporesenting rows | 37 | * @row_gpios: pointer to array of gpio numbers representing rows |
38 | * @col_gpios: array of gpio numbers reporesenting colums | 38 | * @col_gpios: pointer to array of gpio numbers reporesenting colums |
39 | * @num_row_gpios: actual number of row gpios used by device | 39 | * @num_row_gpios: actual number of row gpios used by device |
40 | * @num_col_gpios: actual number of col gpios used by device | 40 | * @num_col_gpios: actual number of col gpios used by device |
41 | * @col_scan_delay_us: delay, measured in microseconds, that is | 41 | * @col_scan_delay_us: delay, measured in microseconds, that is |
@@ -48,8 +48,9 @@ struct matrix_keymap_data { | |||
48 | struct matrix_keypad_platform_data { | 48 | struct matrix_keypad_platform_data { |
49 | const struct matrix_keymap_data *keymap_data; | 49 | const struct matrix_keymap_data *keymap_data; |
50 | 50 | ||
51 | unsigned int row_gpios[MATRIX_MAX_ROWS]; | 51 | const unsigned int *row_gpios; |
52 | unsigned int col_gpios[MATRIX_MAX_COLS]; | 52 | const unsigned int *col_gpios; |
53 | |||
53 | unsigned int num_row_gpios; | 54 | unsigned int num_row_gpios; |
54 | unsigned int num_col_gpios; | 55 | unsigned int num_col_gpios; |
55 | 56 | ||