85db24080726846d35db0d250d55e9b63a154c61
[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/gpio_scrollwheel.h>
29
30 #include <mach/irqs.h>
31 #include <mach/io.h>
32 #include <mach/iomap.h>
33 #include <mach/kbc.h>
34 #include "board.h"
35
36 #include "gpio-names.h"
37
38 #define BOARD_E1187   0x0B57
39 #define BOARD_E1186   0x0B56
40 #define BOARD_E1198   0x0B62
41 #define BOARD_E1291   0x0C5B
42
43
44 #ifdef CONFIG_KEYBOARD_TEGRA
45 #ifdef CONFIG_INPUT_ALPS_GPIO_SCROLLWHEEL
46 #define CARDHU_ROW_COUNT        3
47 #define CARDHU_COL_COUNT        2
48 #else
49 #define CARDHU_ROW_COUNT        4
50 #define CARDHU_COL_COUNT        6
51 #endif
52
53 #ifdef CONFIG_INPUT_ALPS_GPIO_SCROLLWHEEL
54 static int plain_kbd_keycode[] = {
55         KEY_POWER,      KEY_RESERVED,
56         KEY_HOME,       KEY_BACK,
57         KEY_RESERVED,   KEY_RESERVED,
58 };
59 #else
60 static int plain_kbd_keycode[] = {
61         KEY_POWER,      KEY_RESERVED,   KEY_RESERVED,   KEY_RESERVED,
62                         KEY_RESERVED,   KEY_RESERVED,   KEY_RESERVED,
63         KEY_HOME,       KEY_BACK,       KEY_RESERVED,   KEY_RESERVED,
64                         KEY_RESERVED,   KEY_RESERVED,   KEY_RESERVED,
65         KEY_CAMERA,     KEY_CAMERA,     KEY_RESERVED,   KEY_RESERVED,
66                         KEY_RESERVED,   KEY_RESERVED,   KEY_RESERVED,
67         KEY_VOLUMEDOWN, KEY_VOLUMEUP,   KEY_RESERVED,   KEY_RESERVED,
68                         KEY_RESERVED,   KEY_RESERVED,   KEY_PAUSE,
69         KEY_END,        KEY_BACK,       KEY_RESERVED,   KEY_RESERVED,
70                         KEY_RESERVED,   KEY_PLAY,       KEY_PHONE,
71 };
72 #endif
73 static struct tegra_kbc_wake_key cardhu_wake_cfg[] = {
74         [0] = {
75                 .row = 0,
76                 .col = 0,
77         },
78 };
79
80 static struct tegra_kbc_platform_data cardhu_kbc_platform_data = {
81         .debounce_cnt = 20,
82         .repeat_cnt = 50 * 32,
83         .scan_timeout_cnt = 3000 * 32,
84         .plain_keycode = plain_kbd_keycode,
85         .fn_keycode = NULL,
86         .is_filter_keys = false,
87         .is_wake_on_any_key = false,
88         .wake_key_cnt = 1,
89         .wake_cfg = &cardhu_wake_cfg[0],
90 };
91
92 static struct resource cardhu_kbc_resources[] = {
93         [0] = {
94                 .start = TEGRA_KBC_BASE,
95                 .end   = TEGRA_KBC_BASE + TEGRA_KBC_SIZE - 1,
96                 .flags = IORESOURCE_MEM,
97         },
98         [1] = {
99                 .start = INT_KBC,
100                 .end   = INT_KBC,
101                 .flags = IORESOURCE_IRQ,
102         },
103 };
104
105
106 struct platform_device cardhu_kbc_device = {
107         .name = "tegra-kbc",
108         .id = -1,
109         .dev = {
110                 .platform_data = &cardhu_kbc_platform_data,
111         },
112         .resource = cardhu_kbc_resources,
113         .num_resources = ARRAY_SIZE(cardhu_kbc_resources),
114 };
115
116 int __init cardhu_kbc_init(void)
117 {
118         struct tegra_kbc_platform_data *data = &cardhu_kbc_platform_data;
119         int i;
120         struct board_info board_info;
121
122         tegra_get_board_info(&board_info);
123         if ((board_info.board_id == BOARD_E1198) ||
124                         (board_info.board_id == BOARD_E1291))
125                 return 0;
126
127         pr_info("Registering tegra-kbc\n");
128          /* Setup the pin configuration information. */
129         for (i = 0; i < KBC_MAX_GPIO; i++) {
130                 data->pin_cfg[i].num = 0;
131                 data->pin_cfg[i].pin_type = kbc_pin_unused;
132         }
133         for (i = 0; i < CARDHU_ROW_COUNT; i++) {
134                 data->pin_cfg[i].num = i;
135                 data->pin_cfg[i].pin_type = kbc_pin_row;
136         }
137
138         for (i = 0; i < CARDHU_COL_COUNT; i++) {
139                 data->pin_cfg[i + CARDHU_ROW_COUNT].num = i;
140                 data->pin_cfg[i + CARDHU_ROW_COUNT].pin_type = kbc_pin_col;
141         }
142         platform_device_register(&cardhu_kbc_device);
143         return 0;
144 }
145 #else
146 int __init cardhu_kbc_init(void)
147 {
148 }
149 #endif
150
151 #ifdef CONFIG_INPUT_ALPS_GPIO_SCROLLWHEEL
152 #define GPIO_SCROLL(_pinaction, _gpio, _desc)           \
153 {                                                       \
154         .pinaction = GPIO_SCROLLWHEEL_PIN_##_pinaction, \
155         .gpio = TEGRA_GPIO_##_gpio,                     \
156         .desc = _desc,                                  \
157         .active_low = 1,                                \
158         .debounce_interval = 2,                         \
159 }
160
161 static struct gpio_scrollwheel_button scroll_keys[] = {
162         [0] = GPIO_SCROLL(ONOFF, PR3, "sw_onoff"),
163         [1] = GPIO_SCROLL(PRESS, PQ5, "sw_press"),
164         [2] = GPIO_SCROLL(ROT1, PQ3, "sw_rot1"),
165         [3] = GPIO_SCROLL(ROT2, PQ4, "sw_rot2"),
166 };
167
168 static struct gpio_scrollwheel_platform_data cardhu_scroll_platform_data = {
169         .buttons = scroll_keys,
170         .nbuttons = ARRAY_SIZE(scroll_keys),
171 };
172
173 static struct platform_device cardhu_scroll_device = {
174         .name   = "alps-gpio-scrollwheel",
175         .id     = 0,
176         .dev    = {
177                 .platform_data = &cardhu_scroll_platform_data,
178         },
179 };
180
181 int __init cardhu_scroll_init(void)
182 {
183         int i;
184         struct board_info board_info;
185
186         tegra_get_board_info(&board_info);
187         if ((board_info.board_id == BOARD_E1198) ||
188                 (board_info.board_id == BOARD_E1291))
189                 return 0;
190
191         pr_info("Registering alps scroll wheel\n");
192
193         /* Setting pins to gpio mode */
194         for (i = 0; i < ARRAY_SIZE(scroll_keys); i++)
195                 tegra_gpio_enable(scroll_keys[i].gpio);
196
197         platform_device_register(&cardhu_scroll_device);
198         return 0;
199 }
200 #else
201 int __init cardhu_scroll_init(void)
202 {
203         return 0;
204 }
205 #endif
206
207 #ifdef CONFIG_KEYBOARD_GPIO
208 #define GPIO_KEY(_id, _gpio, _iswake)           \
209         {                                       \
210                 .code = _id,                    \
211                 .gpio = TEGRA_GPIO_##_gpio,     \
212                 .active_low = 1,                \
213                 .desc = #_id,                   \
214                 .type = EV_KEY,                 \
215                 .wakeup = _iswake,              \
216                 .debounce_interval = 10,        \
217         }
218
219 static struct gpio_keys_button cardhu_keys[] = {
220         [0] = GPIO_KEY(KEY_HOME, PQ0, 0),
221         [1] = GPIO_KEY(KEY_BACK, PQ1, 0),
222         [2] = GPIO_KEY(KEY_MENU, PQ2, 0),
223         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
224         [4] = GPIO_KEY(KEY_VOLUMEUP, PR0, 0),
225         [5] = GPIO_KEY(KEY_VOLUMEDOWN, PR1, 0),
226         [6] = GPIO_KEY(KEY_POWER, PV0, 1),
227 };
228
229 static struct gpio_keys_platform_data cardhu_keys_platform_data = {
230         .buttons        = cardhu_keys,
231         .nbuttons       = ARRAY_SIZE(cardhu_keys),
232 };
233
234 static struct platform_device cardhu_keys_device = {
235         .name   = "gpio-keys",
236         .id     = 0,
237         .dev    = {
238                 .platform_data  = &cardhu_keys_platform_data,
239         },
240 };
241
242 int __init cardhu_keys_init(void)
243 {
244         int i;
245         int ret;
246         struct board_info board_info;
247
248         tegra_get_board_info(&board_info);
249         if (!((board_info.board_id == BOARD_E1198) ||
250                 (board_info.board_id == BOARD_E1291)))
251                 return 0;
252
253         pr_info("Registering gpio keys\n");
254
255         /* Set KB_ROW2 to 0 for capcitive switch to be in scan mode */
256         if (board_info.board_id == BOARD_E1291) {
257                 ret = gpio_request(TEGRA_GPIO_PR2, "cap_sw_sl_scan");
258                 if (ret < 0) {
259                         pr_err("%s: gpio_request failed #%d\n",
260                                         __func__, TEGRA_GPIO_PR2);
261                         return ret;
262                 }
263                 ret = gpio_direction_output(TEGRA_GPIO_PR2, 0);
264                 if (ret < 0) {
265                         pr_err("%s: gpio_direction_output failed #%d\n",
266                                         __func__, TEGRA_GPIO_PR2);
267                         gpio_free(TEGRA_GPIO_PR2);
268                         return ret;
269                 }
270
271                 tegra_gpio_enable(TEGRA_GPIO_PR2);
272         }
273
274         /* Enable gpio mode for other pins */
275         for (i = 0; i < ARRAY_SIZE(cardhu_keys); i++)
276                 tegra_gpio_enable(cardhu_keys[i].gpio);
277
278         platform_device_register(&cardhu_keys_device);
279         return 0;
280 }
281 #else
282 int __init cardhu_keys_init(void)
283 {
284         return 0;
285 }
286 #endif