blob: 609a18ab8b9861c7545b3a13fdb69278873a9cfb [file] [log] [blame]
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
Duy Truongf3ac7b32013-02-13 01:07:28 -08004 * Copyright (c) 2009, The Linux Foundation. All rights reserved.
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -08005 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google, Inc. nor the names of its contributors
16 * may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <dev/keys.h>
Kinson Chikea646242011-09-01 13:53:16 -070034#include <dev/ssbi.h>
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080035#include <dev/gpio_keypad.h>
36
37#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
38
39/* don't turn this on without updating the ffa support */
40#define SCAN_FUNCTION_KEYS 0
Channagoud Kadabiedc1f5d2011-07-19 13:01:04 +053041#define LINUX_MACHTYPE_7x27_SURF 2705
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080042
43static unsigned int halibut_row_gpios[] = {
44 31, 32, 33, 34, 35, 41
45#if SCAN_FUNCTION_KEYS
46 , 42
47#endif
48};
49
50static unsigned int halibut_col_gpios[] = { 36, 37, 38, 39, 40 };
51
52#define KEYMAP_INDEX(row, col) ((row)*ARRAY_SIZE(halibut_col_gpios) + (col))
53
Channagoud Kadabiedc1f5d2011-07-19 13:01:04 +053054static const unsigned short halibut_keymap_surf[ARRAY_SIZE(halibut_col_gpios) * ARRAY_SIZE(halibut_row_gpios)] = {
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080055 [KEYMAP_INDEX(0, 0)] = KEY_5,
56 [KEYMAP_INDEX(0, 1)] = KEY_9,
57 [KEYMAP_INDEX(0, 2)] = KEY_SOFT1,
58 [KEYMAP_INDEX(0, 3)] = KEY_6,
59 [KEYMAP_INDEX(0, 4)] = KEY_LEFT,
60
61 [KEYMAP_INDEX(1, 0)] = KEY_0,
62 [KEYMAP_INDEX(1, 1)] = KEY_RIGHT,
63 [KEYMAP_INDEX(1, 2)] = KEY_1,
64 [KEYMAP_INDEX(1, 3)] = KEY_SHARP,
65 [KEYMAP_INDEX(1, 4)] = KEY_SEND,
66
67 [KEYMAP_INDEX(2, 0)] = KEY_VOLUMEUP,
68 [KEYMAP_INDEX(2, 1)] = KEY_HOME, /* FA */
69 [KEYMAP_INDEX(2, 2)] = KEY_F8, /* QCHT */
70 [KEYMAP_INDEX(2, 3)] = KEY_F6, /* R+ */
71 [KEYMAP_INDEX(2, 4)] = KEY_F7, /* R- */
72
73 [KEYMAP_INDEX(3, 0)] = KEY_UP,
74 [KEYMAP_INDEX(3, 1)] = KEY_CLEAR,
75 [KEYMAP_INDEX(3, 2)] = KEY_4,
76 [KEYMAP_INDEX(3, 3)] = KEY_MUTE, /* SPKR */
77 [KEYMAP_INDEX(3, 4)] = KEY_2,
78
79 [KEYMAP_INDEX(4, 0)] = KEY_SOFT2, /* SOFT2 */
80 [KEYMAP_INDEX(4, 1)] = KEY_CENTER, /* KEY_CENTER */
81 [KEYMAP_INDEX(4, 2)] = KEY_DOWN,
82 [KEYMAP_INDEX(4, 3)] = KEY_BACK, /* FB */
83 [KEYMAP_INDEX(4, 4)] = KEY_8,
84
85 [KEYMAP_INDEX(5, 0)] = KEY_VOLUMEDOWN,
86 [KEYMAP_INDEX(5, 1)] = KEY_STAR, /* KEY_STAR */
87 [KEYMAP_INDEX(5, 2)] = KEY_MAIL, /* MESG */
88 [KEYMAP_INDEX(5, 3)] = KEY_3,
89 [KEYMAP_INDEX(5, 4)] = KEY_7,
90
91#if SCAN_FUNCTION_KEYS
92 [KEYMAP_INDEX(6, 0)] = KEY_F5,
93 [KEYMAP_INDEX(6, 1)] = KEY_F4,
94 [KEYMAP_INDEX(6, 2)] = KEY_F3,
95 [KEYMAP_INDEX(6, 3)] = KEY_F2,
96 [KEYMAP_INDEX(6, 4)] = KEY_F1
97#endif
98};
99
Channagoud Kadabiedc1f5d2011-07-19 13:01:04 +0530100static const unsigned short halibut_keymap_ffa[ARRAY_SIZE(halibut_col_gpios) * ARRAY_SIZE(halibut_row_gpios)] = {
101 [KEYMAP_INDEX(0, 2)] = KEY_1,
102 [KEYMAP_INDEX(0, 3)] = KEY_SEND,
103 [KEYMAP_INDEX(0, 4)] = KEY_LEFT,
104
105 [KEYMAP_INDEX(1, 0)] = KEY_3,
106 [KEYMAP_INDEX(1, 1)] = KEY_RIGHT,
107 [KEYMAP_INDEX(1, 2)] = KEY_VOLUMEUP,
108 [KEYMAP_INDEX(1, 4)] = KEY_6,
109
110 [KEYMAP_INDEX(2, 0)] = KEY_HOME, /* A */
111 [KEYMAP_INDEX(2, 1)] = KEY_BACK, /* B */
112 [KEYMAP_INDEX(2, 2)] = KEY_0,
113 [KEYMAP_INDEX(2, 3)] = KEY_SHARP,
114 [KEYMAP_INDEX(2, 4)] = KEY_9,
115
116 [KEYMAP_INDEX(3, 0)] = KEY_UP,
117 [KEYMAP_INDEX(3, 1)] = KEY_CENTER,
118 [KEYMAP_INDEX(3, 2)] = KEY_4,
119 [KEYMAP_INDEX(3, 4)] = KEY_2,
120
121 [KEYMAP_INDEX(4, 0)] = KEY_VOLUMEDOWN,
122 [KEYMAP_INDEX(4, 1)] = KEY_SOUND,
123 [KEYMAP_INDEX(4, 2)] = KEY_DOWN,
124 [KEYMAP_INDEX(4, 3)] = KEY_8,
125 [KEYMAP_INDEX(4, 4)] = KEY_5,
126
127 [KEYMAP_INDEX(5, 1)] = KEY_STAR,
128 [KEYMAP_INDEX(5, 2)] = KEY_SOFT2,
129 [KEYMAP_INDEX(5, 3)] = KEY_MENU,
130 [KEYMAP_INDEX(5, 4)] = KEY_7,
131
132#if SCAN_FUNCTION_KEYS
133 [KEYMAP_INDEX(6, 0)] = KEY_F5,
134 [KEYMAP_INDEX(6, 1)] = KEY_F4,
135 [KEYMAP_INDEX(6, 2)] = KEY_F3,
136 [KEYMAP_INDEX(6, 3)] = KEY_F2,
137 [KEYMAP_INDEX(6, 4)] = KEY_F1
138#endif
139};
140
141static struct gpio_keypad_info halibut_keypad_info_surf = {
142 .keymap = halibut_keymap_surf,
143 .output_gpios = halibut_row_gpios,
144 .input_gpios = halibut_col_gpios,
145 .noutputs = ARRAY_SIZE(halibut_row_gpios),
146 .ninputs = ARRAY_SIZE(halibut_col_gpios),
147 .settle_time = 5 /* msec */,
148 .poll_time = 20 /* msec */,
149 .flags = GPIOKPF_DRIVE_INACTIVE,
150};
151
152static struct gpio_keypad_info halibut_keypad_info_ffa = {
153 .keymap = halibut_keymap_ffa,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800154 .output_gpios = halibut_row_gpios,
155 .input_gpios = halibut_col_gpios,
156 .noutputs = ARRAY_SIZE(halibut_row_gpios),
157 .ninputs = ARRAY_SIZE(halibut_col_gpios),
158 .settle_time = 5 /* msec */,
159 .poll_time = 20 /* msec */,
160 .flags = GPIOKPF_DRIVE_INACTIVE,
161};
162
163void keypad_init(void)
164{
Channagoud Kadabiedc1f5d2011-07-19 13:01:04 +0530165 unsigned int mach_id;
166 mach_id = board_machtype();
167
168 if (mach_id == LINUX_MACHTYPE_7x27_SURF)
169 gpio_keypad_init(&halibut_keypad_info_surf);
170 else
171 gpio_keypad_init(&halibut_keypad_info_ffa);
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800172}