ARM: tegra: cardhu: Wakup through GPIO-PV0 for E1291-A04
[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_IKEY(_id, _irq, _iswake, _deb)     \
127         {                                       \
128                 .code = _id,                    \
129                 .gpio = -1,                     \
130                 .irq = _irq,                    \
131                 .desc = #_id,                   \
132                 .type = EV_KEY,                 \
133                 .wakeup = _iswake,              \
134                 .debounce_interval = _deb,      \
135         }
136
137 static struct gpio_keys_button cardhu_keys_e1198[] = {
138         [0] = GPIO_KEY(KEY_HOME, PQ0, 0),
139         [1] = GPIO_KEY(KEY_BACK, PQ1, 0),
140         [2] = GPIO_KEY(KEY_MENU, PQ2, 0),
141         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
142         [4] = GPIO_KEY(KEY_VOLUMEUP, PR0, 0),
143         [5] = GPIO_KEY(KEY_VOLUMEDOWN, PR1, 0),
144         [6] = GPIO_KEY(KEY_POWER, PV0, 1),
145         [7] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
146 };
147
148 static struct gpio_keys_platform_data cardhu_keys_e1198_pdata = {
149         .buttons        = cardhu_keys_e1198,
150         .nbuttons       = ARRAY_SIZE(cardhu_keys_e1198),
151 };
152
153 static struct platform_device cardhu_keys_e1198_device = {
154         .name   = "gpio-keys",
155         .id     = 0,
156         .dev    = {
157                 .platform_data  = &cardhu_keys_e1198_pdata,
158         },
159 };
160
161 static struct gpio_keys_button cardhu_keys_e1291[] = {
162         [0] = GPIO_KEY(KEY_VOLUMEDOWN, PR0, 0),
163         [1] = GPIO_KEY(KEY_VOLUMEUP, PR1, 0),
164         [2] = GPIO_KEY(KEY_HOME, PR2, 0),
165         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
166         [4] = GPIO_KEY(KEY_BACK, PQ0, 0),
167         [5] = GPIO_KEY(KEY_MENU, PQ1, 0),
168         [6] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
169 };
170
171 static struct gpio_keys_button cardhu_keys_e1291_a04[] = {
172         [0] = GPIO_KEY(KEY_VOLUMEDOWN, PR0, 0),
173         [1] = GPIO_KEY(KEY_VOLUMEUP, PR1, 0),
174         [2] = GPIO_KEY(KEY_HOME, PQ2, 0),
175         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
176         [4] = GPIO_KEY(KEY_BACK, PQ0, 0),
177         [5] = GPIO_KEY(KEY_MENU, PQ1, 0),
178         [6] = GPIO_KEY(KEY_POWER, PV0, 1),
179 };
180
181 static struct gpio_keys_platform_data cardhu_keys_e1291_pdata = {
182         .buttons        = cardhu_keys_e1291,
183         .nbuttons       = ARRAY_SIZE(cardhu_keys_e1291),
184 };
185
186 static struct platform_device cardhu_keys_e1291_device = {
187         .name   = "gpio-keys",
188         .id     = 0,
189         .dev    = {
190                 .platform_data  = &cardhu_keys_e1291_pdata,
191         },
192 };
193
194 static struct gpio_keys_button cardhu_int_keys[] = {
195         [0] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
196 };
197
198 static struct gpio_keys_button cardhu_pm298_int_keys[] = {
199         [0] = GPIO_IKEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_FALLING, 1, 100),
200         [1] = GPIO_IKEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_1SEC, 1, 3000),
201 };
202
203 static struct gpio_keys_button cardhu_pm299_int_keys[] = {
204         [0] = GPIO_KEY(KEY_POWER, PV0, 1),
205 };
206
207 static struct gpio_keys_platform_data cardhu_int_keys_pdata = {
208         .buttons        = cardhu_int_keys,
209         .nbuttons       = ARRAY_SIZE(cardhu_int_keys),
210 };
211
212 static struct platform_device cardhu_int_keys_device = {
213         .name   = "gpio-keys",
214         .id     = 0,
215         .dev    = {
216                 .platform_data  = &cardhu_int_keys_pdata,
217         },
218 };
219
220 int __init cardhu_keys_init(void)
221 {
222         int i;
223         struct board_info board_info;
224         struct board_info pmu_board_info;
225         int gpio_nr;
226
227         tegra_get_board_info(&board_info);
228         if (!((board_info.board_id == BOARD_E1198) ||
229                 (board_info.board_id == BOARD_E1291) ||
230                 (board_info.board_id == BOARD_E1186) ||
231                 (board_info.board_id == BOARD_E1257) ||
232                 (board_info.board_id == BOARD_PM305) ||
233                 (board_info.board_id == BOARD_PM311) ||
234                 (board_info.board_id == BOARD_PM269)))
235                 return 0;
236
237         pr_info("Registering gpio keys\n");
238
239         if (board_info.board_id == BOARD_E1291) {
240                 if (board_info.fab >= BOARD_FAB_A04) {
241                         cardhu_keys_e1291_pdata.buttons =
242                                         cardhu_keys_e1291_a04;
243                         cardhu_keys_e1291_pdata.nbuttons =
244                                         ARRAY_SIZE(cardhu_keys_e1291_a04);
245                 }
246
247                 /* Enable gpio mode for other pins */
248                 for (i = 0; i < cardhu_keys_e1291_pdata.nbuttons; i++) {
249                         gpio_nr = cardhu_keys_e1291_pdata.buttons[i].gpio;
250                         if (gpio_nr < 0) {
251                                 if (get_tegra_image_type() == rck_image)
252                                         cardhu_keys_e1291_pdata.buttons[i].code
253                                                         = KEY_ENTER;
254                         } else {
255                                 tegra_gpio_enable(gpio_nr);
256                         }
257                 }
258
259                 platform_device_register(&cardhu_keys_e1291_device);
260         } else if (board_info.board_id == BOARD_E1198) {
261                 /* For E1198 */
262                 for (i = 0; i < ARRAY_SIZE(cardhu_keys_e1198); i++) {
263                         gpio_nr = cardhu_keys_e1198[i].gpio;
264                         if (gpio_nr < 0) {
265                                 if (get_tegra_image_type() == rck_image)
266                                         cardhu_keys_e1198[i].code = KEY_ENTER;
267                         } else {
268                                 tegra_gpio_enable(gpio_nr);
269                         }
270                 }
271
272                 platform_device_register(&cardhu_keys_e1198_device);
273         }
274
275         /* Register on-key through pmu interrupt */
276         tegra_get_pmu_board_info(&pmu_board_info);
277
278         if (pmu_board_info.board_id == BOARD_PMU_PM298) {
279                 cardhu_int_keys_pdata.buttons = cardhu_pm298_int_keys;
280                 cardhu_int_keys_pdata.nbuttons =
281                                         ARRAY_SIZE(cardhu_pm298_int_keys);
282         }
283
284         if (pmu_board_info.board_id == BOARD_PMU_PM299) {
285                 cardhu_int_keys_pdata.buttons = cardhu_pm299_int_keys;
286                 cardhu_int_keys_pdata.nbuttons =
287                                         ARRAY_SIZE(cardhu_pm299_int_keys);
288         }
289
290         if ((board_info.board_id == BOARD_E1257) ||
291                 (board_info.board_id == BOARD_E1186) ||
292                 (board_info.board_id == BOARD_PM305) ||
293                 (board_info.board_id == BOARD_PM311) ||
294                 (board_info.board_id == BOARD_PM269)) {
295                 if (get_tegra_image_type() == rck_image)
296                         cardhu_int_keys[0].code = KEY_ENTER;
297                 platform_device_register(&cardhu_int_keys_device);
298         }
299         return 0;
300 }