ARM: tegra: cardhu: Power button to unlock screen
[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/interrupt_keys.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 "board.h"
37 #include "board-cardhu.h"
38
39 #include "gpio-names.h"
40
41 #define CARDHU_ROW_COUNT        4
42 #define CARDHU_COL_COUNT        2
43 static int plain_kbd_keycode[] = {
44         KEY_POWER,      KEY_RESERVED,
45         KEY_HOME,       KEY_BACK,
46         KEY_CAMERA,     KEY_CAMERA,
47         KEY_VOLUMEDOWN, KEY_VOLUMEUP
48 };
49
50 static struct tegra_kbc_wake_key cardhu_wake_cfg[] = {
51         [0] = {
52                 .row = 0,
53                 .col = 0,
54         },
55 };
56
57 static struct tegra_kbc_platform_data cardhu_kbc_platform_data = {
58         .debounce_cnt = 20,
59         .repeat_cnt = 50 * 32,
60         .scan_timeout_cnt = 3000 * 32,
61         .plain_keycode = plain_kbd_keycode,
62         .fn_keycode = NULL,
63         .is_filter_keys = false,
64         .is_wake_on_any_key = false,
65         .wake_key_cnt = 1,
66         .wake_cfg = &cardhu_wake_cfg[0],
67 };
68
69 static struct resource cardhu_kbc_resources[] = {
70         [0] = {
71                 .start = TEGRA_KBC_BASE,
72                 .end   = TEGRA_KBC_BASE + TEGRA_KBC_SIZE - 1,
73                 .flags = IORESOURCE_MEM,
74         },
75         [1] = {
76                 .start = INT_KBC,
77                 .end   = INT_KBC,
78                 .flags = IORESOURCE_IRQ,
79         },
80 };
81
82
83 struct platform_device cardhu_kbc_device = {
84         .name = "tegra-kbc",
85         .id = -1,
86         .dev = {
87                 .platform_data = &cardhu_kbc_platform_data,
88         },
89         .resource = cardhu_kbc_resources,
90         .num_resources = ARRAY_SIZE(cardhu_kbc_resources),
91 };
92
93 int __init cardhu_kbc_init(void)
94 {
95         struct tegra_kbc_platform_data *data = &cardhu_kbc_platform_data;
96         int i;
97         struct board_info board_info;
98
99         tegra_get_board_info(&board_info);
100         if ((board_info.board_id == BOARD_E1198) ||
101                         (board_info.board_id == BOARD_E1291))
102                 return 0;
103
104         pr_info("Registering tegra-kbc\n");
105          /* Setup the pin configuration information. */
106         for (i = 0; i < KBC_MAX_GPIO; i++) {
107                 data->pin_cfg[i].num = 0;
108                 data->pin_cfg[i].pin_type = kbc_pin_unused;
109         }
110         for (i = 0; i < CARDHU_ROW_COUNT; i++) {
111                 data->pin_cfg[i].num = i;
112                 data->pin_cfg[i].pin_type = kbc_pin_row;
113         }
114
115         for (i = 0; i < CARDHU_COL_COUNT; i++) {
116                 data->pin_cfg[i + CARDHU_ROW_COUNT].num = i;
117                 data->pin_cfg[i + CARDHU_ROW_COUNT].pin_type = kbc_pin_col;
118         }
119         platform_device_register(&cardhu_kbc_device);
120         return 0;
121 }
122
123 int __init cardhu_scroll_init(void)
124 {
125         return 0;
126 }
127
128 #define GPIO_KEY(_id, _gpio, _iswake)           \
129         {                                       \
130                 .code = _id,                    \
131                 .gpio = TEGRA_GPIO_##_gpio,     \
132                 .active_low = 1,                \
133                 .desc = #_id,                   \
134                 .type = EV_KEY,                 \
135                 .wakeup = _iswake,              \
136                 .debounce_interval = 10,        \
137         }
138
139 static struct gpio_keys_button cardhu_keys_pm269[] = {
140         [0] = GPIO_KEY(KEY_POWER, PV0, 1),
141 };
142
143 static struct gpio_keys_platform_data cardhu_keys_pm269_platform_data = {
144         .buttons        = cardhu_keys_pm269,
145         .nbuttons       = ARRAY_SIZE(cardhu_keys_pm269),
146 };
147
148 static struct platform_device cardhu_keys_pm269_device = {
149         .name   = "gpio-keys",
150         .id     = 0,
151         .dev    = {
152                 .platform_data  = &cardhu_keys_pm269_platform_data,
153         },
154 };
155
156 static struct gpio_keys_button cardhu_keys_e1198[] = {
157         [0] = GPIO_KEY(KEY_HOME, PQ0, 0),
158         [1] = GPIO_KEY(KEY_BACK, PQ1, 0),
159         [2] = GPIO_KEY(KEY_MENU, PQ2, 0),
160         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
161         [4] = GPIO_KEY(KEY_VOLUMEUP, PR0, 0),
162         [5] = GPIO_KEY(KEY_VOLUMEDOWN, PR1, 0),
163         [6] = GPIO_KEY(KEY_POWER, PV0, 1),
164 };
165
166 static struct gpio_keys_platform_data cardhu_keys_e1198_platform_data = {
167         .buttons        = cardhu_keys_e1198,
168         .nbuttons       = ARRAY_SIZE(cardhu_keys_e1198),
169 };
170
171 static struct platform_device cardhu_keys_e1198_device = {
172         .name   = "gpio-keys",
173         .id     = 0,
174         .dev    = {
175                 .platform_data  = &cardhu_keys_e1198_platform_data,
176         },
177 };
178
179 static struct gpio_keys_button cardhu_keys_e1291[] = {
180         [0] = GPIO_KEY(KEY_POWER, PR0, 0),
181         [1] = GPIO_KEY(KEY_BACK, PR1, 0),
182         [2] = GPIO_KEY(KEY_HOME, PR2, 0),
183         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
184         [4] = GPIO_KEY(KEY_VOLUMEUP, PQ0, 0),
185         [5] = GPIO_KEY(KEY_VOLUMEDOWN, PQ1, 0),
186 };
187
188 static struct gpio_keys_platform_data cardhu_keys_e1291_platform_data = {
189         .buttons        = cardhu_keys_e1291,
190         .nbuttons       = ARRAY_SIZE(cardhu_keys_e1291),
191 };
192
193 static struct platform_device cardhu_keys_e1291_device = {
194         .name   = "gpio-keys",
195         .id     = 0,
196         .dev    = {
197                 .platform_data  = &cardhu_keys_e1291_platform_data,
198         },
199 };
200
201 #define INT_KEY(_id, _irq, _iswake, _deb_int)   \
202         {                                       \
203                 .code = _id,                    \
204                 .irq = _irq,                    \
205                 .active_low = 1,                \
206                 .desc = #_id,                   \
207                 .type = EV_KEY,                 \
208                 .wakeup = _iswake,              \
209                 .debounce_interval = _deb_int,  \
210         }
211 static struct interrupt_keys_button cardhu_int_keys_e1291[] = {
212         [0] = INT_KEY(KEY_MENU, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 0, 100),
213         [1] = INT_KEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON_LP, 0, 8000),
214 };
215
216 static struct interrupt_keys_platform_data cardhu_int_keys_e1291_pdata = {
217         .int_buttons    = cardhu_int_keys_e1291,
218         .nbuttons       = ARRAY_SIZE(cardhu_int_keys_e1291),
219 };
220
221 static struct platform_device cardhu_int_keys_e1291_device = {
222         .name   = "interrupt-keys",
223         .id     = 0,
224         .dev    = {
225                 .platform_data  = &cardhu_int_keys_e1291_pdata,
226         },
227 };
228
229 int __init cardhu_keys_init(void)
230 {
231         int i;
232         struct board_info board_info;
233
234         tegra_get_board_info(&board_info);
235         if (!((board_info.board_id == BOARD_E1198) ||
236                 (board_info.board_id == BOARD_E1291) ||
237                 (board_info.board_id == BOARD_PM269)))
238                 return 0;
239
240         pr_info("Registering gpio keys\n");
241
242         if (board_info.board_id == BOARD_E1291) {
243                 /* Enable gpio mode for other pins */
244                 for (i = 0; i < ARRAY_SIZE(cardhu_keys_e1291); i++)
245                         tegra_gpio_enable(cardhu_keys_e1291[i].gpio);
246
247                 platform_device_register(&cardhu_keys_e1291_device);
248                 platform_device_register(&cardhu_int_keys_e1291_device);
249         } else if (board_info.board_id == BOARD_PM269) {
250                 for (i = 0; i < ARRAY_SIZE(cardhu_keys_pm269); i++)
251                         tegra_gpio_enable(cardhu_keys_pm269[i].gpio);
252
253                 platform_device_register(&cardhu_keys_pm269_device);
254         } else {
255                 /* For E1198 */
256                 for (i = 0; i < ARRAY_SIZE(cardhu_keys_e1198); i++)
257                         tegra_gpio_enable(cardhu_keys_e1198[i].gpio);
258
259                 platform_device_register(&cardhu_keys_e1198_device);
260         }
261         return 0;
262 }