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