blob: 0299d0686de9f8676cec7e1dd444e502fa53d9d7 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* arch/arm/mach-msm/board-trout-keypad.c
2 *
3 * Copyright (C) 2008 Google, Inc.
4 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */
15
16#include <linux/platform_device.h>
17#include <linux/input.h>
18#include <linux/interrupt.h>
19#include <linux/gpio_event.h>
20#include <asm/mach-types.h>
21
22#include "board-trout.h"
23
24static char *keycaps = "--qwerty";
25#undef MODULE_PARAM_PREFIX
26#define MODULE_PARAM_PREFIX "board_trout."
27module_param_named(keycaps, keycaps, charp, 0);
28
29
30static unsigned int trout_col_gpios[] = { 35, 34, 33, 32, 31, 23, 30, 78 };
31static unsigned int trout_row_gpios[] = { 42, 41, 40, 39, 38, 37, 36 };
32
33#define KEYMAP_INDEX(col, row) ((col)*ARRAY_SIZE(trout_row_gpios) + (row))
34
35static const unsigned short trout_keymap[ARRAY_SIZE(trout_col_gpios) * ARRAY_SIZE(trout_row_gpios)] = {
36 [KEYMAP_INDEX(0, 0)] = KEY_BACK,
37 [KEYMAP_INDEX(0, 1)] = KEY_HOME,
38// [KEYMAP_INDEX(0, 2)] = KEY_,
39 [KEYMAP_INDEX(0, 3)] = KEY_BACKSPACE,
40 [KEYMAP_INDEX(0, 4)] = KEY_ENTER,
41 [KEYMAP_INDEX(0, 5)] = KEY_RIGHTALT,
42 [KEYMAP_INDEX(0, 6)] = KEY_P,
43
44 [KEYMAP_INDEX(1, 0)] = KEY_MENU,
45// [KEYMAP_INDEX(1, 0)] = 229, // SOFT1
46 [KEYMAP_INDEX(1, 1)] = KEY_SEND,
47 [KEYMAP_INDEX(1, 2)] = KEY_END,
48 [KEYMAP_INDEX(1, 3)] = KEY_LEFTALT,
49 [KEYMAP_INDEX(1, 4)] = KEY_A,
50 [KEYMAP_INDEX(1, 5)] = KEY_LEFTSHIFT,
51 [KEYMAP_INDEX(1, 6)] = KEY_Q,
52
53 [KEYMAP_INDEX(2, 0)] = KEY_U,
54 [KEYMAP_INDEX(2, 1)] = KEY_7,
55 [KEYMAP_INDEX(2, 2)] = KEY_K,
56 [KEYMAP_INDEX(2, 3)] = KEY_J,
57 [KEYMAP_INDEX(2, 4)] = KEY_M,
58 [KEYMAP_INDEX(2, 5)] = KEY_SLASH,
59 [KEYMAP_INDEX(2, 6)] = KEY_8,
60
61 [KEYMAP_INDEX(3, 0)] = KEY_5,
62 [KEYMAP_INDEX(3, 1)] = KEY_6,
63 [KEYMAP_INDEX(3, 2)] = KEY_B,
64 [KEYMAP_INDEX(3, 3)] = KEY_H,
65 [KEYMAP_INDEX(3, 4)] = KEY_N,
66 [KEYMAP_INDEX(3, 5)] = KEY_SPACE,
67 [KEYMAP_INDEX(3, 6)] = KEY_Y,
68
69 [KEYMAP_INDEX(4, 0)] = KEY_4,
70 [KEYMAP_INDEX(4, 1)] = KEY_R,
71 [KEYMAP_INDEX(4, 2)] = KEY_V,
72 [KEYMAP_INDEX(4, 3)] = KEY_G,
73 [KEYMAP_INDEX(4, 4)] = KEY_C,
74 //[KEYMAP_INDEX(4, 5)] = KEY_,
75 [KEYMAP_INDEX(4, 6)] = KEY_T,
76
77 [KEYMAP_INDEX(5, 0)] = KEY_2,
78 [KEYMAP_INDEX(5, 1)] = KEY_W,
79 [KEYMAP_INDEX(5, 2)] = KEY_COMPOSE,
80 [KEYMAP_INDEX(5, 3)] = KEY_VOLUMEUP,
81 [KEYMAP_INDEX(5, 4)] = KEY_S,
82 [KEYMAP_INDEX(5, 5)] = KEY_Z,
83 [KEYMAP_INDEX(5, 6)] = KEY_1,
84
85 [KEYMAP_INDEX(6, 0)] = KEY_I,
86 [KEYMAP_INDEX(6, 1)] = KEY_0,
87 [KEYMAP_INDEX(6, 2)] = KEY_O,
88 [KEYMAP_INDEX(6, 3)] = KEY_L,
89 [KEYMAP_INDEX(6, 4)] = KEY_DOT,
90 [KEYMAP_INDEX(6, 5)] = KEY_COMMA,
91 [KEYMAP_INDEX(6, 6)] = KEY_9,
92
93 [KEYMAP_INDEX(7, 0)] = KEY_3,
94 [KEYMAP_INDEX(7, 1)] = KEY_E,
95 [KEYMAP_INDEX(7, 2)] = KEY_EMAIL, // @
96 [KEYMAP_INDEX(7, 3)] = KEY_VOLUMEDOWN,
97 [KEYMAP_INDEX(7, 4)] = KEY_X,
98 [KEYMAP_INDEX(7, 5)] = KEY_F,
99 [KEYMAP_INDEX(7, 6)] = KEY_D
100};
101
102static unsigned int trout_col_gpios_evt2[] = { 35, 34, 33, 32, 31, 23, 30, 109 };
103static unsigned int trout_row_gpios_evt2[] = { 42, 41, 40, 39, 38, 37, 36 };
104
105static const unsigned short trout_keymap_evt2_1[ARRAY_SIZE(trout_col_gpios) * ARRAY_SIZE(trout_row_gpios)] = {
106 [KEYMAP_INDEX(0, 0)] = KEY_BACK,
107 [KEYMAP_INDEX(0, 1)] = KEY_HOME,
108// [KEYMAP_INDEX(0, 2)] = KEY_,
109 [KEYMAP_INDEX(0, 3)] = KEY_BACKSPACE,
110 [KEYMAP_INDEX(0, 4)] = KEY_ENTER,
111 [KEYMAP_INDEX(0, 5)] = KEY_RIGHTSHIFT,
112 [KEYMAP_INDEX(0, 6)] = KEY_P,
113
114 [KEYMAP_INDEX(1, 0)] = KEY_MENU,
115 [KEYMAP_INDEX(1, 1)] = KEY_SEND,
116// [KEYMAP_INDEX(1, 2)] = KEY_,
117 [KEYMAP_INDEX(1, 3)] = KEY_LEFTSHIFT,
118 [KEYMAP_INDEX(1, 4)] = KEY_A,
119 [KEYMAP_INDEX(1, 5)] = KEY_COMPOSE,
120 [KEYMAP_INDEX(1, 6)] = KEY_Q,
121
122 [KEYMAP_INDEX(2, 0)] = KEY_U,
123 [KEYMAP_INDEX(2, 1)] = KEY_7,
124 [KEYMAP_INDEX(2, 2)] = KEY_K,
125 [KEYMAP_INDEX(2, 3)] = KEY_J,
126 [KEYMAP_INDEX(2, 4)] = KEY_M,
127 [KEYMAP_INDEX(2, 5)] = KEY_SLASH,
128 [KEYMAP_INDEX(2, 6)] = KEY_8,
129
130 [KEYMAP_INDEX(3, 0)] = KEY_5,
131 [KEYMAP_INDEX(3, 1)] = KEY_6,
132 [KEYMAP_INDEX(3, 2)] = KEY_B,
133 [KEYMAP_INDEX(3, 3)] = KEY_H,
134 [KEYMAP_INDEX(3, 4)] = KEY_N,
135 [KEYMAP_INDEX(3, 5)] = KEY_SPACE,
136 [KEYMAP_INDEX(3, 6)] = KEY_Y,
137
138 [KEYMAP_INDEX(4, 0)] = KEY_4,
139 [KEYMAP_INDEX(4, 1)] = KEY_R,
140 [KEYMAP_INDEX(4, 2)] = KEY_V,
141 [KEYMAP_INDEX(4, 3)] = KEY_G,
142 [KEYMAP_INDEX(4, 4)] = KEY_C,
143// [KEYMAP_INDEX(4, 5)] = KEY_,
144 [KEYMAP_INDEX(4, 6)] = KEY_T,
145
146 [KEYMAP_INDEX(5, 0)] = KEY_2,
147 [KEYMAP_INDEX(5, 1)] = KEY_W,
148 [KEYMAP_INDEX(5, 2)] = KEY_LEFTALT,
149 [KEYMAP_INDEX(5, 3)] = KEY_VOLUMEUP,
150 [KEYMAP_INDEX(5, 4)] = KEY_S,
151 [KEYMAP_INDEX(5, 5)] = KEY_Z,
152 [KEYMAP_INDEX(5, 6)] = KEY_1,
153
154 [KEYMAP_INDEX(6, 0)] = KEY_I,
155 [KEYMAP_INDEX(6, 1)] = KEY_0,
156 [KEYMAP_INDEX(6, 2)] = KEY_O,
157 [KEYMAP_INDEX(6, 3)] = KEY_L,
158 [KEYMAP_INDEX(6, 4)] = KEY_COMMA,
159 [KEYMAP_INDEX(6, 5)] = KEY_DOT,
160 [KEYMAP_INDEX(6, 6)] = KEY_9,
161
162 [KEYMAP_INDEX(7, 0)] = KEY_3,
163 [KEYMAP_INDEX(7, 1)] = KEY_E,
164 [KEYMAP_INDEX(7, 2)] = KEY_EMAIL, // @
165 [KEYMAP_INDEX(7, 3)] = KEY_VOLUMEDOWN,
166 [KEYMAP_INDEX(7, 4)] = KEY_X,
167 [KEYMAP_INDEX(7, 5)] = KEY_F,
168 [KEYMAP_INDEX(7, 6)] = KEY_D
169};
170
171static const unsigned short trout_keymap_evt2_2[ARRAY_SIZE(trout_col_gpios) * ARRAY_SIZE(trout_row_gpios)] = {
172 [KEYMAP_INDEX(0, 0)] = KEY_BACK,
173 [KEYMAP_INDEX(0, 1)] = KEY_HOME,
174// [KEYMAP_INDEX(0, 2)] = KEY_,
175 [KEYMAP_INDEX(0, 3)] = KEY_BACKSPACE,
176 [KEYMAP_INDEX(0, 4)] = KEY_ENTER,
177 [KEYMAP_INDEX(0, 5)] = KEY_RIGHTSHIFT,
178 [KEYMAP_INDEX(0, 6)] = KEY_P,
179
180 [KEYMAP_INDEX(1, 0)] = KEY_MENU, /* external menu key */
181 [KEYMAP_INDEX(1, 1)] = KEY_SEND,
182// [KEYMAP_INDEX(1, 2)] = KEY_,
183 [KEYMAP_INDEX(1, 3)] = KEY_LEFTSHIFT,
184 [KEYMAP_INDEX(1, 4)] = KEY_A,
185 [KEYMAP_INDEX(1, 5)] = KEY_F1, /* qwerty menu key */
186 [KEYMAP_INDEX(1, 6)] = KEY_Q,
187
188 [KEYMAP_INDEX(2, 0)] = KEY_U,
189 [KEYMAP_INDEX(2, 1)] = KEY_7,
190 [KEYMAP_INDEX(2, 2)] = KEY_K,
191 [KEYMAP_INDEX(2, 3)] = KEY_J,
192 [KEYMAP_INDEX(2, 4)] = KEY_M,
193 [KEYMAP_INDEX(2, 5)] = KEY_DOT,
194 [KEYMAP_INDEX(2, 6)] = KEY_8,
195
196 [KEYMAP_INDEX(3, 0)] = KEY_5,
197 [KEYMAP_INDEX(3, 1)] = KEY_6,
198 [KEYMAP_INDEX(3, 2)] = KEY_B,
199 [KEYMAP_INDEX(3, 3)] = KEY_H,
200 [KEYMAP_INDEX(3, 4)] = KEY_N,
201 [KEYMAP_INDEX(3, 5)] = KEY_SPACE,
202 [KEYMAP_INDEX(3, 6)] = KEY_Y,
203
204 [KEYMAP_INDEX(4, 0)] = KEY_4,
205 [KEYMAP_INDEX(4, 1)] = KEY_R,
206 [KEYMAP_INDEX(4, 2)] = KEY_V,
207 [KEYMAP_INDEX(4, 3)] = KEY_G,
208 [KEYMAP_INDEX(4, 4)] = KEY_C,
209 [KEYMAP_INDEX(4, 5)] = KEY_EMAIL, // @
210 [KEYMAP_INDEX(4, 6)] = KEY_T,
211
212 [KEYMAP_INDEX(5, 0)] = KEY_2,
213 [KEYMAP_INDEX(5, 1)] = KEY_W,
214 [KEYMAP_INDEX(5, 2)] = KEY_LEFTALT,
215 [KEYMAP_INDEX(5, 3)] = KEY_VOLUMEUP,
216 [KEYMAP_INDEX(5, 4)] = KEY_S,
217 [KEYMAP_INDEX(5, 5)] = KEY_Z,
218 [KEYMAP_INDEX(5, 6)] = KEY_1,
219
220 [KEYMAP_INDEX(6, 0)] = KEY_I,
221 [KEYMAP_INDEX(6, 1)] = KEY_0,
222 [KEYMAP_INDEX(6, 2)] = KEY_O,
223 [KEYMAP_INDEX(6, 3)] = KEY_L,
224 [KEYMAP_INDEX(6, 4)] = KEY_COMMA,
225 [KEYMAP_INDEX(6, 5)] = KEY_RIGHTALT,
226 [KEYMAP_INDEX(6, 6)] = KEY_9,
227
228 [KEYMAP_INDEX(7, 0)] = KEY_3,
229 [KEYMAP_INDEX(7, 1)] = KEY_E,
230 [KEYMAP_INDEX(7, 2)] = KEY_COMPOSE,
231 [KEYMAP_INDEX(7, 3)] = KEY_VOLUMEDOWN,
232 [KEYMAP_INDEX(7, 4)] = KEY_X,
233 [KEYMAP_INDEX(7, 5)] = KEY_F,
234 [KEYMAP_INDEX(7, 6)] = KEY_D
235};
236
237static struct gpio_event_matrix_info trout_keypad_matrix_info = {
238 .info.func = gpio_event_matrix_func,
239 .keymap = trout_keymap,
240 .output_gpios = trout_col_gpios,
241 .input_gpios = trout_row_gpios,
242 .noutputs = ARRAY_SIZE(trout_col_gpios),
243 .ninputs = ARRAY_SIZE(trout_row_gpios),
244 .settle_time.tv.nsec = 40 * NSEC_PER_USEC,
245 .poll_time.tv.nsec = 20 * NSEC_PER_MSEC,
246 .flags = GPIOKPF_LEVEL_TRIGGERED_IRQ | GPIOKPF_REMOVE_PHANTOM_KEYS |GPIOKPF_PRINT_UNMAPPED_KEYS /*| GPIOKPF_PRINT_MAPPED_KEYS*/
247};
248
249static struct gpio_event_direct_entry trout_keypad_nav_map[] = {
250 { TROUT_POWER_KEY, KEY_POWER },
251 { TROUT_GPIO_CAM_BTN_STEP1_N, KEY_CAMERA-1 }, //steal KEY_HP
252 { TROUT_GPIO_CAM_BTN_STEP2_N, KEY_CAMERA },
253};
254
255static struct gpio_event_direct_entry trout_keypad_nav_map_evt2[] = {
256 { TROUT_POWER_KEY, KEY_END },
257 { TROUT_GPIO_CAM_BTN_STEP1_N, KEY_CAMERA-1 }, //steal KEY_HP
258 { TROUT_GPIO_CAM_BTN_STEP2_N, KEY_CAMERA },
259};
260
261static struct gpio_event_input_info trout_keypad_nav_info = {
262 .info.func = gpio_event_input_func,
263 .flags = 0,
264 .type = EV_KEY,
265 .keymap = trout_keypad_nav_map,
266 .keymap_size = ARRAY_SIZE(trout_keypad_nav_map)
267};
268
269static struct gpio_event_direct_entry trout_keypad_switch_map[] = {
270 { TROUT_GPIO_SLIDING_DET, SW_LID }
271};
272
273static struct gpio_event_input_info trout_keypad_switch_info = {
274 .info.func = gpio_event_input_func,
275 .flags = 0,
276 .type = EV_SW,
277 .keymap = trout_keypad_switch_map,
278 .keymap_size = ARRAY_SIZE(trout_keypad_switch_map)
279};
280
281static struct gpio_event_info *trout_keypad_info[] = {
282 &trout_keypad_matrix_info.info,
283 &trout_keypad_nav_info.info,
284 &trout_keypad_switch_info.info,
285};
286
287static struct gpio_event_platform_data trout_keypad_data = {
288 .name = "trout-keypad",
289 .info = trout_keypad_info,
290 .info_count = ARRAY_SIZE(trout_keypad_info)
291};
292
293static struct platform_device trout_keypad_device = {
294 .name = GPIO_EVENT_DEV_NAME,
295 .id = 0,
296 .dev = {
297 .platform_data = &trout_keypad_data,
298 },
299};
300
301static int __init trout_init_keypad(void)
302{
303 if (!machine_is_trout())
304 return 0;
305
306 switch (system_rev) {
307 case 0:
308 /* legacy default keylayout */
309 break;
310 case 1:
311 /* v1 has a new keyboard layout */
312 trout_keypad_matrix_info.keymap = trout_keymap_evt2_1;
313 trout_keypad_matrix_info.output_gpios = trout_col_gpios_evt2;
314 trout_keypad_matrix_info.input_gpios = trout_row_gpios_evt2;
315
316 /* v1 has new direct keys */
317 trout_keypad_nav_info.keymap = trout_keypad_nav_map_evt2;
318 trout_keypad_nav_info.keymap_size = ARRAY_SIZE(trout_keypad_nav_map_evt2);
319
320 /* userspace needs to know about these changes as well */
321 trout_keypad_data.name = "trout-keypad-v2";
322 break;
323 default: /* 2, 3, 4 currently */
324 /* v2 has a new keyboard layout */
325 trout_keypad_matrix_info.keymap = trout_keymap_evt2_2;
326 trout_keypad_matrix_info.output_gpios = trout_col_gpios_evt2;
327 trout_keypad_matrix_info.input_gpios = trout_row_gpios_evt2;
328
329 /* v2 has new direct keys */
330 trout_keypad_nav_info.keymap = trout_keypad_nav_map_evt2;
331 trout_keypad_nav_info.keymap_size = ARRAY_SIZE(trout_keypad_nav_map_evt2);
332
333 /* userspace needs to know about these changes as well */
334 if (!strcmp(keycaps, "qwertz")) {
335 trout_keypad_data.name = "trout-keypad-qwertz";
336 } else {
337 trout_keypad_data.name = "trout-keypad-v3";
338 }
339 break;
340 }
341 return platform_device_register(&trout_keypad_device);
342}
343
344device_initcall(trout_init_keypad);
345