875b0302996786eb5958cbf5c06059a39c876d25
[linux-2.6.git] / arch / arm / mach-tegra / board-cardhu-kbc.c
1 /*
2  * arch/arm/mach-tegra/board-cardhu-kbc.c
3  * Keys configuration for Nvidia tegra3 cardhu platform.
4  *
5  * Copyright (C) 2011 NVIDIA, Inc.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19  * 02111-1307, USA
20  */
21
22 #include <linux/kernel.h>
23 #include <linux/platform_device.h>
24 #include <linux/input.h>
25 #include <linux/device.h>
26 #include <linux/gpio.h>
27 #include <linux/gpio_keys.h>
28 #include <linux/mfd/tps6591x.h>
29 #include <linux/mfd/max77663-core.h>
30 #include <linux/gpio_scrollwheel.h>
31
32 #include <mach/irqs.h>
33 #include <mach/io.h>
34 #include <mach/iomap.h>
35 #include <mach/kbc.h>
36 #include <mach/gpio-tegra.h>
37
38 #include "board.h"
39 #include "board-cardhu.h"
40
41 #include "gpio-names.h"
42 #include "devices.h"
43
44 #define CARDHU_PM269_ROW_COUNT  2
45 #define CARDHU_PM269_COL_COUNT  4
46
47 static const u32 kbd_keymap[] = {
48         KEY(0, 0, KEY_POWER),
49         KEY(0, 1, KEY_RESERVED),
50         KEY(0, 2, KEY_VOLUMEUP),
51         KEY(0, 3, KEY_VOLUMEDOWN),
52
53         KEY(1, 0, KEY_HOME),
54         KEY(1, 1, KEY_MENU),
55         KEY(1, 2, KEY_BACK),
56         KEY(1, 3, KEY_SEARCH),
57 };
58 static const struct matrix_keymap_data keymap_data = {
59         .keymap  = kbd_keymap,
60         .keymap_size    = ARRAY_SIZE(kbd_keymap),
61 };
62
63 static struct tegra_kbc_wake_key cardhu_wake_cfg[] = {
64         [0] = {
65                 .row = 0,
66                 .col = 0,
67         },
68 };
69
70 static struct tegra_kbc_platform_data cardhu_kbc_platform_data = {
71         .debounce_cnt = 20 * 32, /* 20ms debounce time */
72         .repeat_cnt = 1,
73         .scan_count = 30,
74         .wakeup = true,
75         .keymap_data = &keymap_data,
76         .wake_cnt = 1,
77         .wake_cfg = &cardhu_wake_cfg[0],
78 #ifdef CONFIG_ANDROID
79         .disable_ev_rep = true,
80 #endif
81 };
82
83 int __init cardhu_kbc_init(void)
84 {
85         struct tegra_kbc_platform_data *data = &cardhu_kbc_platform_data;
86         int i;
87         struct board_info board_info;
88
89         tegra_get_board_info(&board_info);
90         if ((board_info.board_id == BOARD_E1198) ||
91                         (board_info.board_id == BOARD_E1291))
92                 return 0;
93
94         pr_info("Registering tegra-kbc\n");
95         tegra_kbc_device.dev.platform_data = &cardhu_kbc_platform_data;
96
97         for (i = 0; i < CARDHU_PM269_ROW_COUNT; i++) {
98                 data->pin_cfg[i].num = i;
99                 data->pin_cfg[i].type = PIN_CFG_ROW;
100         }
101         for (i = 0; i < CARDHU_PM269_COL_COUNT; i++) {
102                 data->pin_cfg[i + KBC_PIN_GPIO_16].num = i;
103                 data->pin_cfg[i + KBC_PIN_GPIO_16].type = PIN_CFG_COL;
104         }
105
106         platform_device_register(&tegra_kbc_device);
107         return 0;
108 }
109
110 int __init cardhu_scroll_init(void)
111 {
112         return 0;
113 }
114
115 #define GPIO_KEY(_id, _gpio, _iswake)           \
116         {                                       \
117                 .code = _id,                    \
118                 .gpio = TEGRA_GPIO_##_gpio,     \
119                 .active_low = 1,                \
120                 .desc = #_id,                   \
121                 .type = EV_KEY,                 \
122                 .wakeup = _iswake,              \
123                 .debounce_interval = 10,        \
124         }
125
126 #define GPIO_SW_KEY(_id, _gpio, _iswake)        \
127         {                                       \
128                 .code = _id,                    \
129                 .gpio = _gpio,                  \
130                 .active_low = 1,                \
131                 .desc = #_id,                   \
132                 .type = EV_SW,                  \
133                 .wakeup = _iswake,              \
134                 .debounce_interval = 1,         \
135         }
136
137 #define GPIO_IKEY(_id, _irq, _iswake, _deb)     \
138         {                                       \
139                 .code = _id,                    \
140                 .gpio = -1,                     \
141                 .irq = _irq,                    \
142                 .desc = #_id,                   \
143                 .type = EV_KEY,                 \
144                 .wakeup = _iswake,              \
145                 .debounce_interval = _deb,      \
146         }
147
148 static struct gpio_keys_button cardhu_keys_e1198[] = {
149         [0] = GPIO_KEY(KEY_HOME, PQ0, 0),
150         [1] = GPIO_KEY(KEY_BACK, PQ1, 0),
151         [2] = GPIO_KEY(KEY_MENU, PQ2, 0),
152         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
153         [4] = GPIO_KEY(KEY_VOLUMEUP, PR0, 0),
154         [5] = GPIO_KEY(KEY_VOLUMEDOWN, PR1, 0),
155         [6] = GPIO_KEY(KEY_POWER, PV0, 1),
156         [7] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
157 };
158
159 static struct gpio_keys_platform_data cardhu_keys_e1198_pdata = {
160         .buttons        = cardhu_keys_e1198,
161         .nbuttons       = ARRAY_SIZE(cardhu_keys_e1198),
162 };
163
164 static struct platform_device cardhu_keys_e1198_device = {
165         .name   = "gpio-keys",
166         .id     = 0,
167         .dev    = {
168                 .platform_data  = &cardhu_keys_e1198_pdata,
169         },
170 };
171
172 static struct gpio_keys_button cardhu_keys_e1291[] = {
173         [0] = GPIO_KEY(KEY_VOLUMEDOWN, PR0, 0),
174         [1] = GPIO_KEY(KEY_VOLUMEUP, PR1, 0),
175         [2] = GPIO_KEY(KEY_HOME, PR2, 0),
176         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
177         [4] = GPIO_KEY(KEY_BACK, PQ0, 0),
178         [5] = GPIO_KEY(KEY_MENU, PQ1, 0),
179         [6] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
180         [7] = GPIO_SW_KEY(SW_LID, TPS6591X_GPIO_5, 0),
181 };
182
183 static struct gpio_keys_button cardhu_keys_e1291_a04[] = {
184         [0] = GPIO_KEY(KEY_VOLUMEDOWN, PR0, 0),
185         [1] = GPIO_KEY(KEY_VOLUMEUP, PR1, 0),
186         [2] = GPIO_KEY(KEY_HOME, PQ2, 0),
187         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
188         [4] = GPIO_KEY(KEY_BACK, PQ0, 0),
189         [5] = GPIO_KEY(KEY_MENU, PQ1, 0),
190         [6] = GPIO_KEY(KEY_RESERVED, PV0, 1),
191         [7] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
192         [8] = GPIO_SW_KEY(SW_LID, TPS6591X_GPIO_5, 0),
193 };
194
195 static struct gpio_keys_platform_data cardhu_keys_e1291_pdata = {
196         .buttons        = cardhu_keys_e1291,
197         .nbuttons       = ARRAY_SIZE(cardhu_keys_e1291),
198 };
199
200 static struct platform_device cardhu_keys_e1291_device = {
201         .name   = "gpio-keys",
202         .id     = 0,
203         .dev    = {
204                 .platform_data  = &cardhu_keys_e1291_pdata,
205         },
206 };
207
208 static struct gpio_keys_button cardhu_int_keys[] = {
209         [0] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
210 };
211
212 static struct gpio_keys_button cardhu_pm298_int_keys[] = {
213         [0] = GPIO_IKEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_FALLING, 0, 100),
214         [1] = GPIO_IKEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_1SEC, 0, 3000),
215 };
216
217 static struct gpio_keys_button cardhu_pm299_int_keys[] = {
218         [0] = GPIO_KEY(KEY_POWER, PV0, 1),
219 };
220
221 static struct gpio_keys_platform_data cardhu_int_keys_pdata = {
222         .buttons        = cardhu_int_keys,
223         .nbuttons       = ARRAY_SIZE(cardhu_int_keys),
224 };
225
226 static struct platform_device cardhu_int_keys_device = {
227         .name   = "gpio-keys",
228         .id     = 0,
229         .dev    = {
230                 .platform_data  = &cardhu_int_keys_pdata,
231         },
232 };
233
234 int __init cardhu_keys_init(void)
235 {
236         int i;
237         struct board_info board_info;
238         struct board_info pmu_board_info;
239         int gpio_nr;
240
241         tegra_get_board_info(&board_info);
242         if (!((board_info.board_id == BOARD_E1198) ||
243                 (board_info.board_id == BOARD_E1291) ||
244                 (board_info.board_id == BOARD_E1186) ||
245                 (board_info.board_id == BOARD_E1257) ||
246                 (board_info.board_id == BOARD_PM305) ||
247                 (board_info.board_id == BOARD_PM311) ||
248                 (board_info.board_id == BOARD_PM267) ||
249                 (board_info.board_id == BOARD_PM269)))
250                 return 0;
251
252         pr_info("Registering gpio keys\n");
253
254         if (board_info.board_id == BOARD_E1291) {
255                 if (board_info.fab >= BOARD_FAB_A04) {
256                         cardhu_keys_e1291_pdata.buttons =
257                                         cardhu_keys_e1291_a04;
258                         cardhu_keys_e1291_pdata.nbuttons =
259                                         ARRAY_SIZE(cardhu_keys_e1291_a04);
260                 }
261
262                 /* Enable gpio mode for other pins */
263                 for (i = 0; i < cardhu_keys_e1291_pdata.nbuttons; i++) {
264                         gpio_nr = cardhu_keys_e1291_pdata.buttons[i].gpio;
265                         if (gpio_nr < 0) {
266                                 if (get_tegra_image_type() == rck_image)
267                                         cardhu_keys_e1291_pdata.buttons[i].code
268                                                         = KEY_ENTER;
269                         }
270                 }
271
272                 platform_device_register(&cardhu_keys_e1291_device);
273         } else if (board_info.board_id == BOARD_E1198) {
274                 /* For E1198 */
275                 for (i = 0; i < ARRAY_SIZE(cardhu_keys_e1198); i++) {
276                         gpio_nr = cardhu_keys_e1198[i].gpio;
277                         if (gpio_nr < 0) {
278                                 if (get_tegra_image_type() == rck_image)
279                                         cardhu_keys_e1198[i].code = KEY_ENTER;
280                         }
281                 }
282
283                 platform_device_register(&cardhu_keys_e1198_device);
284         }
285
286         /* Register on-key through pmu interrupt */
287         tegra_get_pmu_board_info(&pmu_board_info);
288
289         if (pmu_board_info.board_id == BOARD_PMU_PM298) {
290                 cardhu_int_keys_pdata.buttons = cardhu_pm298_int_keys;
291                 cardhu_int_keys_pdata.nbuttons =
292                                         ARRAY_SIZE(cardhu_pm298_int_keys);
293         }
294
295         if (pmu_board_info.board_id == BOARD_PMU_PM299) {
296                 cardhu_int_keys_pdata.buttons = cardhu_pm299_int_keys;
297                 cardhu_int_keys_pdata.nbuttons =
298                                         ARRAY_SIZE(cardhu_pm299_int_keys);
299         }
300
301         if ((board_info.board_id == BOARD_E1257) ||
302                 (board_info.board_id == BOARD_E1186) ||
303                 (board_info.board_id == BOARD_PM305) ||
304                 (board_info.board_id == BOARD_PM311) ||
305                 (board_info.board_id == BOARD_PM267) ||
306                 (board_info.board_id == BOARD_PM269)) {
307                 if (get_tegra_image_type() == rck_image)
308                         cardhu_int_keys[0].code = KEY_ENTER;
309                 platform_device_register(&cardhu_int_keys_device);
310         }
311         return 0;
312 }