arm: tegra: cardhu: Register tegra based keyboard driver
[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,
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 };
78
79 int __init cardhu_kbc_init(void)
80 {
81         struct tegra_kbc_platform_data *data = &cardhu_kbc_platform_data;
82         int i;
83         struct board_info board_info;
84
85         tegra_get_board_info(&board_info);
86         if ((board_info.board_id == BOARD_E1198) ||
87                         (board_info.board_id == BOARD_E1291))
88                 return 0;
89
90         pr_info("Registering tegra-kbc\n");
91         tegra_kbc_device.dev.platform_data = &cardhu_kbc_platform_data;
92
93         for (i = 0; i < CARDHU_PM269_ROW_COUNT; i++) {
94                 data->pin_cfg[i].num = i;
95                 data->pin_cfg[i].is_row = true;
96                 data->pin_cfg[i].en = true;
97         }
98         for (i = 0; i < CARDHU_PM269_COL_COUNT; i++) {
99                 data->pin_cfg[i + KBC_PIN_GPIO_16].num = i;
100                 data->pin_cfg[i + KBC_PIN_GPIO_16].en = true;
101         }
102
103         platform_device_register(&tegra_kbc_device);
104         return 0;
105 }
106
107 int __init cardhu_scroll_init(void)
108 {
109         return 0;
110 }
111
112 #define GPIO_KEY(_id, _gpio, _iswake)           \
113         {                                       \
114                 .code = _id,                    \
115                 .gpio = TEGRA_GPIO_##_gpio,     \
116                 .active_low = 1,                \
117                 .desc = #_id,                   \
118                 .type = EV_KEY,                 \
119                 .wakeup = _iswake,              \
120                 .debounce_interval = 10,        \
121         }
122
123 static struct gpio_keys_button cardhu_keys_e1198[] = {
124         [0] = GPIO_KEY(KEY_HOME, PQ0, 0),
125         [1] = GPIO_KEY(KEY_BACK, PQ1, 0),
126         [2] = GPIO_KEY(KEY_MENU, PQ2, 0),
127         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
128         [4] = GPIO_KEY(KEY_VOLUMEUP, PR0, 0),
129         [5] = GPIO_KEY(KEY_VOLUMEDOWN, PR1, 0),
130         [6] = GPIO_KEY(KEY_POWER, PV0, 1),
131 };
132
133 static struct gpio_keys_platform_data cardhu_keys_e1198_platform_data = {
134         .buttons        = cardhu_keys_e1198,
135         .nbuttons       = ARRAY_SIZE(cardhu_keys_e1198),
136 };
137
138 static struct platform_device cardhu_keys_e1198_device = {
139         .name   = "gpio-keys",
140         .id     = 0,
141         .dev    = {
142                 .platform_data  = &cardhu_keys_e1198_platform_data,
143         },
144 };
145
146 static struct gpio_keys_button cardhu_keys_e1291[] = {
147         [0] = GPIO_KEY(KEY_MENU, PR0, 0),
148         [1] = GPIO_KEY(KEY_BACK, PR1, 0),
149         [2] = GPIO_KEY(KEY_HOME, PR2, 0),
150         [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
151         [4] = GPIO_KEY(KEY_VOLUMEUP, PQ0, 0),
152         [5] = GPIO_KEY(KEY_VOLUMEDOWN, PQ1, 0),
153 };
154
155 static struct gpio_keys_platform_data cardhu_keys_e1291_platform_data = {
156         .buttons        = cardhu_keys_e1291,
157         .nbuttons       = ARRAY_SIZE(cardhu_keys_e1291),
158 };
159
160 static struct platform_device cardhu_keys_e1291_device = {
161         .name   = "gpio-keys",
162         .id     = 0,
163         .dev    = {
164                 .platform_data  = &cardhu_keys_e1291_platform_data,
165         },
166 };
167
168 #define INT_KEY(_id, _irq, _iswake, _deb_int)   \
169         {                                       \
170                 .code = _id,                    \
171                 .irq = _irq,                    \
172                 .active_low = 1,                \
173                 .desc = #_id,                   \
174                 .type = EV_KEY,                 \
175                 .wakeup = _iswake,              \
176                 .debounce_interval = _deb_int,  \
177         }
178 static struct interrupt_keys_button cardhu_int_keys[] = {
179         [0] = INT_KEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 0, 100),
180 };
181
182 static struct interrupt_keys_button cardhu_pm298_int_keys[] = {
183         [0] = INT_KEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_FALLING, 0, 100),
184         [1] = INT_KEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_1SEC, 0, 3000),
185 };
186
187 static struct interrupt_keys_button cardhu_pm299_int_keys[] = {
188         [0] = INT_KEY(KEY_POWER, RICOH583_IRQ_BASE + RICOH583_IRQ_ONKEY, 0, 100),
189 };
190
191 static struct interrupt_keys_platform_data cardhu_int_keys_pdata = {
192         .int_buttons    = cardhu_int_keys,
193         .nbuttons       = ARRAY_SIZE(cardhu_int_keys),
194 };
195
196 static struct platform_device cardhu_int_keys_device = {
197         .name   = "interrupt-keys",
198         .id     = 0,
199         .dev    = {
200                 .platform_data  = &cardhu_int_keys_pdata,
201         },
202 };
203
204 int __init cardhu_keys_init(void)
205 {
206         int i;
207         struct board_info board_info;
208         struct board_info pmu_board_info;
209
210         tegra_get_board_info(&board_info);
211         if (!((board_info.board_id == BOARD_E1198) ||
212                 (board_info.board_id == BOARD_E1291) ||
213                 (board_info.board_id == BOARD_E1257) ||
214                 (board_info.board_id == BOARD_PM305) ||
215                 (board_info.board_id == BOARD_PM311) ||
216                 (board_info.board_id == BOARD_PM269)))
217                 return 0;
218
219         pr_info("Registering gpio keys\n");
220
221         if (board_info.board_id == BOARD_E1291) {
222                 /* Enable gpio mode for other pins */
223                 for (i = 0; i < ARRAY_SIZE(cardhu_keys_e1291); i++)
224                         tegra_gpio_enable(cardhu_keys_e1291[i].gpio);
225
226                 platform_device_register(&cardhu_keys_e1291_device);
227         } else if (board_info.board_id == BOARD_E1198) {
228                 /* For E1198 */
229                 for (i = 0; i < ARRAY_SIZE(cardhu_keys_e1198); i++)
230                         tegra_gpio_enable(cardhu_keys_e1198[i].gpio);
231
232                 platform_device_register(&cardhu_keys_e1198_device);
233         }
234
235         /* Register on-key through pmu interrupt */
236         tegra_get_pmu_board_info(&pmu_board_info);
237
238         if (pmu_board_info.board_id == BOARD_PMU_PM298) {
239                 cardhu_int_keys_pdata.int_buttons = cardhu_pm298_int_keys;
240                 cardhu_int_keys_pdata.nbuttons =
241                                         ARRAY_SIZE(cardhu_pm298_int_keys);
242         }
243
244         if (pmu_board_info.board_id == BOARD_PMU_PM299) {
245                 cardhu_int_keys_pdata.int_buttons = cardhu_pm299_int_keys;
246                 cardhu_int_keys_pdata.nbuttons =
247                                         ARRAY_SIZE(cardhu_pm299_int_keys);
248         }
249
250         if ((board_info.board_id == BOARD_E1291) ||
251                 (board_info.board_id == BOARD_E1198) ||
252                 (board_info.board_id == BOARD_E1257) ||
253                 (board_info.board_id == BOARD_PM305) ||
254                 (board_info.board_id == BOARD_PM311) ||
255                 (board_info.board_id == BOARD_PM269))
256                 platform_device_register(&cardhu_int_keys_device);
257         return 0;
258 }