]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - arch/arm/mach-tegra/board-cardhu-kbc.c
arm: tegra: cardhu: enable wakeup through interrupt keys
[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/interrupt_keys.h>
31 #include <linux/gpio_scrollwheel.h>
32
33 #include <mach/irqs.h>
34 #include <mach/io.h>
35 #include <mach/iomap.h>
36 #include <mach/kbc.h>
37 #include "board.h"
38 #include "board-cardhu.h"
39
40 #include "gpio-names.h"
41 #include "devices.h"
42
43 #define CARDHU_PM269_ROW_COUNT  2
44 #define CARDHU_PM269_COL_COUNT  4
45
46 static const u32 kbd_keymap[] = {
47         KEY(0, 0, KEY_POWER),
48         KEY(0, 1, KEY_RESERVED),
49         KEY(0, 2, KEY_VOLUMEUP),
50         KEY(0, 3, KEY_VOLUMEDOWN),
51
52         KEY(1, 0, KEY_HOME),
53         KEY(1, 1, KEY_MENU),
54         KEY(1, 2, KEY_BACK),
55         KEY(1, 3, KEY_SEARCH),
56 };
57 static const struct matrix_keymap_data keymap_data = {
58         .keymap  = kbd_keymap,
59         .keymap_size    = ARRAY_SIZE(kbd_keymap),
60 };
61
62 static struct tegra_kbc_wake_key cardhu_wake_cfg[] = {
63         [0] = {
64                 .row = 0,
65                 .col = 0,
66         },
67 };
68
69 static struct tegra_kbc_platform_data cardhu_kbc_platform_data = {
70         .debounce_cnt = 20 * 32, /* 20ms debounce time */
71         .repeat_cnt = 1,
72         .scan_count = 30,
73         .wakeup = true,
74         .keymap_data = &keymap_data,
75         .wake_cnt = 1,
76         .wake_cfg = &cardhu_wake_cfg[0],
77 #ifdef CONFIG_ANDROID
78         .disable_ev_rep = true,
79 #endif
80 };
81
82 int __init cardhu_kbc_init(void)
83 {
84         struct tegra_kbc_platform_data *data = &cardhu_kbc_platform_data;
85         int i;
86         struct board_info board_info;
87
88         tegra_get_board_info(&board_info);
89         if ((board_info.board_id == BOARD_E1198) ||
90                         (board_info.board_id == BOARD_E1291))
91                 return 0;
92
93         pr_info("Registering tegra-kbc\n");
94         tegra_kbc_device.dev.platform_data = &cardhu_kbc_platform_data;
95
96         for (i = 0; i < CARDHU_PM269_ROW_COUNT; i++) {
97                 data->pin_cfg[i].num = i;
98                 data->pin_cfg[i].is_row = true;
99                 data->pin_cfg[i].en = true;
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].en = true;
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 static struct gpio_keys_button cardhu_keys_e1198[] = {
127         [0] = GPIO_KEY(KEY_HOME, PQ0, 0),
128         [1] = GPIO_KEY(KEY_BACK, PQ1, 0),
129         [2] = GPIO_KEY(KEY_MENU, PQ2, 0),
130         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
131         [4] = GPIO_KEY(KEY_VOLUMEUP, PR0, 0),
132         [5] = GPIO_KEY(KEY_VOLUMEDOWN, PR1, 0),
133         [6] = GPIO_KEY(KEY_POWER, PV0, 1),
134 };
135
136 static struct gpio_keys_platform_data cardhu_keys_e1198_platform_data = {
137         .buttons        = cardhu_keys_e1198,
138         .nbuttons       = ARRAY_SIZE(cardhu_keys_e1198),
139 };
140
141 static struct platform_device cardhu_keys_e1198_device = {
142         .name   = "gpio-keys",
143         .id     = 0,
144         .dev    = {
145                 .platform_data  = &cardhu_keys_e1198_platform_data,
146         },
147 };
148
149 static struct gpio_keys_button cardhu_keys_e1291[] = {
150         [0] = GPIO_KEY(KEY_MENU, PR0, 0),
151         [1] = GPIO_KEY(KEY_BACK, PR1, 0),
152         [2] = GPIO_KEY(KEY_HOME, PR2, 0),
153         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
154         [4] = GPIO_KEY(KEY_VOLUMEUP, PQ0, 0),
155         [5] = GPIO_KEY(KEY_VOLUMEDOWN, PQ1, 0),
156 };
157
158 static struct gpio_keys_button cardhu_keys_e1291_a04[] = {
159         [0] = GPIO_KEY(KEY_MENU, PR0, 0),
160         [1] = GPIO_KEY(KEY_BACK, PR1, 0),
161         [2] = GPIO_KEY(KEY_HOME, PQ2, 0),
162         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
163         [4] = GPIO_KEY(KEY_VOLUMEUP, PQ0, 0),
164         [5] = GPIO_KEY(KEY_VOLUMEDOWN, PQ1, 0),
165 };
166
167 static struct gpio_keys_platform_data cardhu_keys_e1291_platform_data = {
168         .buttons        = cardhu_keys_e1291,
169         .nbuttons       = ARRAY_SIZE(cardhu_keys_e1291),
170 };
171
172 static struct platform_device cardhu_keys_e1291_device = {
173         .name   = "gpio-keys",
174         .id     = 0,
175         .dev    = {
176                 .platform_data  = &cardhu_keys_e1291_platform_data,
177         },
178 };
179
180 #define INT_KEY(_id, _irq, _iswake, _deb_int)   \
181         {                                       \
182                 .code = _id,                    \
183                 .irq = _irq,                    \
184                 .active_low = 1,                \
185                 .desc = #_id,                   \
186                 .type = EV_KEY,                 \
187                 .wakeup = _iswake,              \
188                 .debounce_interval = _deb_int,  \
189         }
190 static struct interrupt_keys_button cardhu_int_keys[] = {
191         [0] = INT_KEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
192 };
193
194 static struct interrupt_keys_button cardhu_pm298_int_keys[] = {
195         [0] = INT_KEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_FALLING, 1, 100),
196         [1] = INT_KEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_1SEC, 1, 3000),
197 };
198
199 static struct interrupt_keys_button cardhu_pm299_int_keys[] = {
200         [0] = INT_KEY(KEY_POWER, RICOH583_IRQ_BASE + RICOH583_IRQ_ONKEY, 1, 100),
201 };
202
203 static struct interrupt_keys_platform_data cardhu_int_keys_pdata = {
204         .int_buttons    = cardhu_int_keys,
205         .nbuttons       = ARRAY_SIZE(cardhu_int_keys),
206 };
207
208 static struct platform_device cardhu_int_keys_device = {
209         .name   = "interrupt-keys",
210         .id     = 0,
211         .dev    = {
212                 .platform_data  = &cardhu_int_keys_pdata,
213         },
214 };
215
216 int __init cardhu_keys_init(void)
217 {
218         int i;
219         struct board_info board_info;
220         struct board_info pmu_board_info;
221
222         tegra_get_board_info(&board_info);
223         if (!((board_info.board_id == BOARD_E1198) ||
224                 (board_info.board_id == BOARD_E1291) ||
225                 (board_info.board_id == BOARD_E1186) ||
226                 (board_info.board_id == BOARD_E1257) ||
227                 (board_info.board_id == BOARD_PM305) ||
228                 (board_info.board_id == BOARD_PM311) ||
229                 (board_info.board_id == BOARD_PM269)))
230                 return 0;
231
232         pr_info("Registering gpio keys\n");
233
234         if (board_info.board_id == BOARD_E1291) {
235                 if (board_info.fab >= BOARD_FAB_A04) {
236                         cardhu_keys_e1291_platform_data.buttons =
237                                         cardhu_keys_e1291_a04;
238                         cardhu_keys_e1291_platform_data.nbuttons =
239                                         ARRAY_SIZE(cardhu_keys_e1291_a04);
240                 }
241
242                 /* Enable gpio mode for other pins */
243                 for (i = 0; i < cardhu_keys_e1291_platform_data.nbuttons; i++)
244                         tegra_gpio_enable(cardhu_keys_e1291_platform_data.
245                                                 buttons[i].gpio);
246
247                 platform_device_register(&cardhu_keys_e1291_device);
248         } else if (board_info.board_id == BOARD_E1198) {
249                 /* For E1198 */
250                 for (i = 0; i < ARRAY_SIZE(cardhu_keys_e1198); i++)
251                         tegra_gpio_enable(cardhu_keys_e1198[i].gpio);
252
253                 platform_device_register(&cardhu_keys_e1198_device);
254         }
255
256         /* Register on-key through pmu interrupt */
257         tegra_get_pmu_board_info(&pmu_board_info);
258
259         if (pmu_board_info.board_id == BOARD_PMU_PM298) {
260                 cardhu_int_keys_pdata.int_buttons = cardhu_pm298_int_keys;
261                 cardhu_int_keys_pdata.nbuttons =
262                                         ARRAY_SIZE(cardhu_pm298_int_keys);
263         }
264
265         if (pmu_board_info.board_id == BOARD_PMU_PM299) {
266                 cardhu_int_keys_pdata.int_buttons = cardhu_pm299_int_keys;
267                 cardhu_int_keys_pdata.nbuttons =
268                                         ARRAY_SIZE(cardhu_pm299_int_keys);
269         }
270
271         if ((board_info.board_id == BOARD_E1291) ||
272                 (board_info.board_id == BOARD_E1198) ||
273                 (board_info.board_id == BOARD_E1257) ||
274                 (board_info.board_id == BOARD_E1186) ||
275                 (board_info.board_id == BOARD_PM305) ||
276                 (board_info.board_id == BOARD_PM311) ||
277                 (board_info.board_id == BOARD_PM269))
278                 platform_device_register(&cardhu_int_keys_device);
279         return 0;
280 }