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