arm: tegra: cardhu: add support for PM315
[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                         (board_info.board_id == BOARD_PM315))
93                 return 0;
94
95         pr_info("Registering tegra-kbc\n");
96         tegra_kbc_device.dev.platform_data = &cardhu_kbc_platform_data;
97
98         for (i = 0; i < CARDHU_PM269_ROW_COUNT; i++) {
99                 data->pin_cfg[i].num = i;
100                 data->pin_cfg[i].type = PIN_CFG_ROW;
101         }
102         for (i = 0; i < CARDHU_PM269_COL_COUNT; i++) {
103                 data->pin_cfg[i + KBC_PIN_GPIO_16].num = i;
104                 data->pin_cfg[i + KBC_PIN_GPIO_16].type = PIN_CFG_COL;
105         }
106
107         platform_device_register(&tegra_kbc_device);
108         return 0;
109 }
110
111 int __init cardhu_scroll_init(void)
112 {
113         return 0;
114 }
115
116 #define GPIO_KEY(_id, _gpio, _iswake)           \
117         {                                       \
118                 .code = _id,                    \
119                 .gpio = TEGRA_GPIO_##_gpio,     \
120                 .active_low = 1,                \
121                 .desc = #_id,                   \
122                 .type = EV_KEY,                 \
123                 .wakeup = _iswake,              \
124                 .debounce_interval = 10,        \
125         }
126
127 #define GPIO_SW_KEY(_id, _gpio, _iswake)        \
128         {                                       \
129                 .code = _id,                    \
130                 .gpio = _gpio,                  \
131                 .active_low = 1,                \
132                 .desc = #_id,                   \
133                 .type = EV_SW,                  \
134                 .wakeup = _iswake,              \
135                 .debounce_interval = 1,         \
136         }
137
138 #define GPIO_IKEY(_id, _irq, _iswake, _deb)     \
139         {                                       \
140                 .code = _id,                    \
141                 .gpio = -1,                     \
142                 .irq = _irq,                    \
143                 .desc = #_id,                   \
144                 .type = EV_KEY,                 \
145                 .wakeup = _iswake,              \
146                 .debounce_interval = _deb,      \
147         }
148
149 static struct gpio_keys_button cardhu_keys_e1198[] = {
150         [0] = GPIO_KEY(KEY_HOME, PQ0, 0),
151         [1] = GPIO_KEY(KEY_BACK, PQ1, 0),
152         [2] = GPIO_KEY(KEY_MENU, PQ2, 0),
153         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
154         [4] = GPIO_KEY(KEY_VOLUMEUP, PR0, 0),
155         [5] = GPIO_KEY(KEY_VOLUMEDOWN, PR1, 0),
156         [6] = GPIO_KEY(KEY_POWER, PV0, 1),
157         [7] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
158 };
159
160 static struct gpio_keys_platform_data cardhu_keys_e1198_pdata = {
161         .buttons        = cardhu_keys_e1198,
162         .nbuttons       = ARRAY_SIZE(cardhu_keys_e1198),
163 };
164
165 static struct platform_device cardhu_keys_e1198_device = {
166         .name   = "gpio-keys",
167         .id     = 0,
168         .dev    = {
169                 .platform_data  = &cardhu_keys_e1198_pdata,
170         },
171 };
172
173 static struct gpio_keys_button cardhu_keys_e1291[] = {
174         [0] = GPIO_KEY(KEY_VOLUMEDOWN, PR0, 0),
175         [1] = GPIO_KEY(KEY_VOLUMEUP, PR1, 0),
176         [2] = GPIO_KEY(KEY_HOME, PR2, 0),
177         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
178         [4] = GPIO_KEY(KEY_BACK, PQ0, 0),
179         [5] = GPIO_KEY(KEY_MENU, PQ1, 0),
180         [6] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
181         [7] = GPIO_SW_KEY(SW_LID, TPS6591X_GPIO_5, 0),
182 };
183
184 static struct gpio_keys_button cardhu_keys_e1291_a04[] = {
185         [0] = GPIO_KEY(KEY_VOLUMEDOWN, PR0, 0),
186         [1] = GPIO_KEY(KEY_VOLUMEUP, PR1, 0),
187         [2] = GPIO_KEY(KEY_HOME, PQ2, 0),
188         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
189         [4] = GPIO_KEY(KEY_BACK, PQ0, 0),
190         [5] = GPIO_KEY(KEY_MENU, PQ1, 0),
191         [6] = GPIO_KEY(KEY_RESERVED, PV0, 1),
192         [7] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
193         [8] = GPIO_SW_KEY(SW_LID, TPS6591X_GPIO_5, 0),
194 };
195
196 static struct gpio_keys_platform_data cardhu_keys_e1291_pdata = {
197         .buttons        = cardhu_keys_e1291,
198         .nbuttons       = ARRAY_SIZE(cardhu_keys_e1291),
199 };
200
201 static struct platform_device cardhu_keys_e1291_device = {
202         .name   = "gpio-keys",
203         .id     = 0,
204         .dev    = {
205                 .platform_data  = &cardhu_keys_e1291_pdata,
206         },
207 };
208
209 static struct gpio_keys_button cardhu_int_keys[] = {
210         [0] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
211 };
212
213 static struct gpio_keys_button cardhu_pm298_int_keys[] = {
214         [0] = GPIO_IKEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_FALLING, 0, 100),
215         [1] = GPIO_IKEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_1SEC, 0, 3000),
216 };
217
218 static struct gpio_keys_button cardhu_pm299_int_keys[] = {
219         [0] = GPIO_KEY(KEY_POWER, PV0, 1),
220 };
221
222 static struct gpio_keys_platform_data cardhu_int_keys_pdata = {
223         .buttons        = cardhu_int_keys,
224         .nbuttons       = ARRAY_SIZE(cardhu_int_keys),
225 };
226
227 static struct platform_device cardhu_int_keys_device = {
228         .name   = "gpio-keys",
229         .id     = 0,
230         .dev    = {
231                 .platform_data  = &cardhu_int_keys_pdata,
232         },
233 };
234
235 int __init cardhu_keys_init(void)
236 {
237         int i;
238         struct board_info board_info;
239         struct board_info pmu_board_info;
240         int gpio_nr;
241
242         tegra_get_board_info(&board_info);
243         if (!((board_info.board_id == BOARD_E1198) ||
244                 (board_info.board_id == BOARD_E1291) ||
245                 (board_info.board_id == BOARD_E1186) ||
246                 (board_info.board_id == BOARD_E1257) ||
247                 (board_info.board_id == BOARD_PM305) ||
248                 (board_info.board_id == BOARD_PM311) ||
249                 (board_info.board_id == BOARD_PM267) ||
250                 (board_info.board_id == BOARD_PM269)))
251                 return 0;
252
253         pr_info("Registering gpio keys\n");
254
255         if (board_info.board_id == BOARD_E1291) {
256                 if (board_info.fab >= BOARD_FAB_A04) {
257                         cardhu_keys_e1291_pdata.buttons =
258                                         cardhu_keys_e1291_a04;
259                         cardhu_keys_e1291_pdata.nbuttons =
260                                         ARRAY_SIZE(cardhu_keys_e1291_a04);
261                 }
262
263                 /* Enable gpio mode for other pins */
264                 for (i = 0; i < cardhu_keys_e1291_pdata.nbuttons; i++) {
265                         gpio_nr = cardhu_keys_e1291_pdata.buttons[i].gpio;
266                         if (gpio_nr < 0) {
267                                 if (get_tegra_image_type() == rck_image)
268                                         cardhu_keys_e1291_pdata.buttons[i].code
269                                                         = KEY_ENTER;
270                         }
271                 }
272
273                 platform_device_register(&cardhu_keys_e1291_device);
274         } else if (board_info.board_id == BOARD_E1198) {
275                 /* For E1198 */
276                 for (i = 0; i < ARRAY_SIZE(cardhu_keys_e1198); i++) {
277                         gpio_nr = cardhu_keys_e1198[i].gpio;
278                         if (gpio_nr < 0) {
279                                 if (get_tegra_image_type() == rck_image)
280                                         cardhu_keys_e1198[i].code = KEY_ENTER;
281                         }
282                 }
283
284                 platform_device_register(&cardhu_keys_e1198_device);
285         }
286
287         /* Register on-key through pmu interrupt */
288         tegra_get_pmu_board_info(&pmu_board_info);
289
290         if (pmu_board_info.board_id == BOARD_PMU_PM298) {
291                 cardhu_int_keys_pdata.buttons = cardhu_pm298_int_keys;
292                 cardhu_int_keys_pdata.nbuttons =
293                                         ARRAY_SIZE(cardhu_pm298_int_keys);
294         }
295
296         if (pmu_board_info.board_id == BOARD_PMU_PM299) {
297                 cardhu_int_keys_pdata.buttons = cardhu_pm299_int_keys;
298                 cardhu_int_keys_pdata.nbuttons =
299                                         ARRAY_SIZE(cardhu_pm299_int_keys);
300         }
301
302         if ((board_info.board_id == BOARD_E1257) ||
303                 (board_info.board_id == BOARD_E1186) ||
304                 (board_info.board_id == BOARD_PM305) ||
305                 (board_info.board_id == BOARD_PM311) ||
306                 (board_info.board_id == BOARD_PM267) ||
307                 (board_info.board_id == BOARD_PM269)) {
308                 if (get_tegra_image_type() == rck_image)
309                         cardhu_int_keys[0].code = KEY_ENTER;
310                 platform_device_register(&cardhu_int_keys_device);
311         }
312         return 0;
313 }