| Eric Miao | bab7614 | 2009-06-29 00:20:52 -0700 | [diff] [blame] | 1 | #ifndef _MATRIX_KEYPAD_H | 
|  | 2 | #define _MATRIX_KEYPAD_H | 
|  | 3 |  | 
|  | 4 | #include <linux/types.h> | 
|  | 5 | #include <linux/input.h> | 
|  | 6 |  | 
| Trilok Soni | cfaea56 | 2011-02-11 00:44:41 -0800 | [diff] [blame] | 7 | #define MATRIX_MAX_ROWS		32 | 
|  | 8 | #define MATRIX_MAX_COLS		32 | 
| Eric Miao | bab7614 | 2009-06-29 00:20:52 -0700 | [diff] [blame] | 9 |  | 
|  | 10 | #define KEY(row, col, val)	((((row) & (MATRIX_MAX_ROWS - 1)) << 24) |\ | 
|  | 11 | (((col) & (MATRIX_MAX_COLS - 1)) << 16) |\ | 
| Janusz Krzysztofik | da1f026 | 2010-12-20 21:09:22 +0000 | [diff] [blame] | 12 | ((val) & 0xffff)) | 
| Eric Miao | bab7614 | 2009-06-29 00:20:52 -0700 | [diff] [blame] | 13 |  | 
|  | 14 | #define KEY_ROW(k)		(((k) >> 24) & 0xff) | 
|  | 15 | #define KEY_COL(k)		(((k) >> 16) & 0xff) | 
|  | 16 | #define KEY_VAL(k)		((k) & 0xffff) | 
|  | 17 |  | 
| Eric Miao | d82f1c3 | 2009-08-05 01:24:41 -0700 | [diff] [blame] | 18 | #define MATRIX_SCAN_CODE(row, col, row_shift)	(((row) << (row_shift)) + (col)) | 
|  | 19 |  | 
| Eric Miao | bab7614 | 2009-06-29 00:20:52 -0700 | [diff] [blame] | 20 | /** | 
|  | 21 | * struct matrix_keymap_data - keymap for matrix keyboards | 
|  | 22 | * @keymap: pointer to array of uint32 values encoded with KEY() macro | 
|  | 23 | *	representing keymap | 
|  | 24 | * @keymap_size: number of entries (initialized) in this keymap | 
| Eric Miao | bab7614 | 2009-06-29 00:20:52 -0700 | [diff] [blame] | 25 | * | 
|  | 26 | * This structure is supposed to be used by platform code to supply | 
|  | 27 | * keymaps to drivers that implement matrix-like keypads/keyboards. | 
|  | 28 | */ | 
|  | 29 | struct matrix_keymap_data { | 
|  | 30 | const uint32_t *keymap; | 
|  | 31 | unsigned int	keymap_size; | 
| Eric Miao | bab7614 | 2009-06-29 00:20:52 -0700 | [diff] [blame] | 32 | }; | 
|  | 33 |  | 
|  | 34 | /** | 
|  | 35 | * struct matrix_keypad_platform_data - platform-dependent keypad data | 
|  | 36 | * @keymap_data: pointer to &matrix_keymap_data | 
| Eric Miao | d82f1c3 | 2009-08-05 01:24:41 -0700 | [diff] [blame] | 37 | * @row_gpios: pointer to array of gpio numbers representing rows | 
|  | 38 | * @col_gpios: pointer to array of gpio numbers reporesenting colums | 
| Eric Miao | bab7614 | 2009-06-29 00:20:52 -0700 | [diff] [blame] | 39 | * @num_row_gpios: actual number of row 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 | 
|  | 42 | *	needed before we can keypad after activating column gpio | 
|  | 43 | * @debounce_ms: debounce interval in milliseconds | 
| Luotao Fu | fb76dd1 | 2010-06-10 12:05:23 -0700 | [diff] [blame] | 44 | * @clustered_irq: may be specified if interrupts of all row/column GPIOs | 
|  | 45 | *	are bundled to one single irq | 
|  | 46 | * @clustered_irq_flags: flags that are needed for the clustered irq | 
| Dmitry Torokhov | d69249f | 2009-11-16 22:12:20 -0800 | [diff] [blame] | 47 | * @active_low: gpio polarity | 
|  | 48 | * @wakeup: controls whether the device should be set up as wakeup | 
|  | 49 | *	source | 
| H Hartley Sweeten | 9d32c30 | 2010-04-05 22:29:09 -0700 | [diff] [blame] | 50 | * @no_autorepeat: disable key autorepeat | 
| Eric Miao | bab7614 | 2009-06-29 00:20:52 -0700 | [diff] [blame] | 51 | * | 
|  | 52 | * This structure represents platform-specific data that use used by | 
|  | 53 | * matrix_keypad driver to perform proper initialization. | 
|  | 54 | */ | 
|  | 55 | struct matrix_keypad_platform_data { | 
|  | 56 | const struct matrix_keymap_data *keymap_data; | 
|  | 57 |  | 
| Eric Miao | d82f1c3 | 2009-08-05 01:24:41 -0700 | [diff] [blame] | 58 | const unsigned int *row_gpios; | 
|  | 59 | const unsigned int *col_gpios; | 
|  | 60 |  | 
| Eric Miao | bab7614 | 2009-06-29 00:20:52 -0700 | [diff] [blame] | 61 | unsigned int	num_row_gpios; | 
|  | 62 | unsigned int	num_col_gpios; | 
|  | 63 |  | 
|  | 64 | unsigned int	col_scan_delay_us; | 
|  | 65 |  | 
|  | 66 | /* key debounce interval in milli-second */ | 
|  | 67 | unsigned int	debounce_ms; | 
|  | 68 |  | 
| Luotao Fu | fb76dd1 | 2010-06-10 12:05:23 -0700 | [diff] [blame] | 69 | unsigned int	clustered_irq; | 
|  | 70 | unsigned int	clustered_irq_flags; | 
|  | 71 |  | 
| Eric Miao | bab7614 | 2009-06-29 00:20:52 -0700 | [diff] [blame] | 72 | bool		active_low; | 
|  | 73 | bool		wakeup; | 
| H Hartley Sweeten | 9d32c30 | 2010-04-05 22:29:09 -0700 | [diff] [blame] | 74 | bool		no_autorepeat; | 
| Eric Miao | bab7614 | 2009-06-29 00:20:52 -0700 | [diff] [blame] | 75 | }; | 
|  | 76 |  | 
| Dmitry Torokhov | 77a53fd | 2009-08-25 19:24:13 -0700 | [diff] [blame] | 77 | /** | 
|  | 78 | * matrix_keypad_build_keymap - convert platform keymap into matrix keymap | 
|  | 79 | * @keymap_data: keymap supplied by the platform code | 
|  | 80 | * @row_shift: number of bits to shift row value by to advance to the next | 
|  | 81 | * line in the keymap | 
|  | 82 | * @keymap: expanded version of keymap that is suitable for use by | 
|  | 83 | * matrix keyboad driver | 
|  | 84 | * @keybit: pointer to bitmap of keys supported by input device | 
|  | 85 | * | 
|  | 86 | * This function converts platform keymap (encoded with KEY() macro) into | 
|  | 87 | * an array of keycodes that is suitable for using in a standard matrix | 
|  | 88 | * keyboard driver that uses row and col as indices. | 
|  | 89 | */ | 
|  | 90 | static inline void | 
|  | 91 | matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data, | 
|  | 92 | unsigned int row_shift, | 
|  | 93 | unsigned short *keymap, unsigned long *keybit) | 
|  | 94 | { | 
|  | 95 | int i; | 
|  | 96 |  | 
|  | 97 | for (i = 0; i < keymap_data->keymap_size; i++) { | 
|  | 98 | unsigned int key = keymap_data->keymap[i]; | 
|  | 99 | unsigned int row = KEY_ROW(key); | 
|  | 100 | unsigned int col = KEY_COL(key); | 
|  | 101 | unsigned short code = KEY_VAL(key); | 
|  | 102 |  | 
|  | 103 | keymap[MATRIX_SCAN_CODE(row, col, row_shift)] = code; | 
|  | 104 | __set_bit(code, keybit); | 
|  | 105 | } | 
|  | 106 | __clear_bit(KEY_RESERVED, keybit); | 
|  | 107 | } | 
|  | 108 |  | 
| Eric Miao | bab7614 | 2009-06-29 00:20:52 -0700 | [diff] [blame] | 109 | #endif /* _MATRIX_KEYPAD_H */ |