summaryrefslogtreecommitdiff
path: root/arch/arm/mach-tegra/board-cardhu-kbc.c
blob: 2671e6cc586b986e1c58be830949dfd18b7b6e61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
 * arch/arm/mach-tegra/board-cardhu-kbc.c
 * Keys configuration for Nvidia tegra3 cardhu platform.
 *
 * Copyright (C) 2011 NVIDIA, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307, USA
 */

#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/input.h>
#include <linux/device.h>
#include <linux/gpio.h>
#include <linux/gpio_keys.h>
#include <linux/gpio_scrollwheel.h>

#include <mach/irqs.h>
#include <mach/io.h>
#include <mach/iomap.h>
#include <mach/kbc.h>

#include "gpio-names.h"

#ifdef CONFIG_KEYBOARD_TEGRA
#ifdef CONFIG_INPUT_ALPS_GPIO_SCROLLWHEEL
#define CARDHU_ROW_COUNT	3
#define CARDHU_COL_COUNT	2
#else
#define CARDHU_ROW_COUNT	4
#define CARDHU_COL_COUNT	6
#endif

#ifdef CONFIG_INPUT_ALPS_GPIO_SCROLLWHEEL
static int plain_kbd_keycode[] = {
	KEY_POWER,	KEY_RESERVED,
	KEY_HOME,	KEY_BACK,
	KEY_RESERVED,	KEY_RESERVED,
};
#else
static int plain_kbd_keycode[] = {
	KEY_POWER,	KEY_RESERVED,	KEY_RESERVED,	KEY_RESERVED,
			KEY_RESERVED,	KEY_RESERVED,	KEY_RESERVED,
	KEY_HOME,	KEY_BACK,	KEY_RESERVED,	KEY_RESERVED,
			KEY_RESERVED,	KEY_RESERVED,	KEY_RESERVED,
	KEY_CAMERA,	KEY_CAMERA,	KEY_RESERVED,	KEY_RESERVED,
			KEY_RESERVED,	KEY_RESERVED,	KEY_RESERVED,
	KEY_VOLUMEDOWN,	KEY_VOLUMEUP,	KEY_RESERVED,	KEY_RESERVED,
			KEY_RESERVED,	KEY_RESERVED,	KEY_PAUSE,
	KEY_END,	KEY_BACK,	KEY_RESERVED,	KEY_RESERVED,
			KEY_RESERVED,	KEY_PLAY,	KEY_PHONE,
};
#endif
static struct tegra_kbc_wake_key cardhu_wake_cfg[] = {
	[0] = {
		.row = 0,
		.col = 0,
	},
};

static struct tegra_kbc_platform_data cardhu_kbc_platform_data = {
	.debounce_cnt = 20,
	.repeat_cnt = 50 * 32,
	.scan_timeout_cnt = 3000 * 32,
	.plain_keycode = plain_kbd_keycode,
	.fn_keycode = NULL,
	.is_filter_keys = false,
	.is_wake_on_any_key = false,
	.wake_key_cnt = 1,
	.wake_cfg = &cardhu_wake_cfg[0],
};

static struct resource cardhu_kbc_resources[] = {
	[0] = {
		.start = TEGRA_KBC_BASE,
		.end   = TEGRA_KBC_BASE + TEGRA_KBC_SIZE - 1,
		.flags = IORESOURCE_MEM,
	},
	[1] = {
		.start = INT_KBC,
		.end   = INT_KBC,
		.flags = IORESOURCE_IRQ,
	},
};


struct platform_device cardhu_kbc_device = {
	.name = "tegra-kbc",
	.id = -1,
	.dev = {
		.platform_data = &cardhu_kbc_platform_data,
	},
	.resource = cardhu_kbc_resources,
	.num_resources = ARRAY_SIZE(cardhu_kbc_resources),
};

int __init cardhu_kbc_init(void)
{
	struct tegra_kbc_platform_data *data = &cardhu_kbc_platform_data;
	int i;

	pr_info("KBC: cardhu_kbc_init\n");

	 /* Setup the pin configuration information. */
	for (i = 0; i < KBC_MAX_GPIO; i++) {
		data->pin_cfg[i].num = 0;
		data->pin_cfg[i].pin_type = kbc_pin_unused;
	}
	for (i = 0; i < CARDHU_ROW_COUNT; i++) {
		data->pin_cfg[i].num = i;
		data->pin_cfg[i].pin_type = kbc_pin_row;
	}

	for (i = 0; i < CARDHU_COL_COUNT; i++) {
		data->pin_cfg[i + CARDHU_ROW_COUNT].num = i;
		data->pin_cfg[i + CARDHU_ROW_COUNT].pin_type = kbc_pin_col;
	}
	platform_device_register(&cardhu_kbc_device);
	return 0;
}
#else
int __init cardhu_kbc_init(void)
{
}
#endif

#ifdef CONFIG_INPUT_ALPS_GPIO_SCROLLWHEEL
#define GPIO_SCROLL(_pinaction, _gpio, _desc)		\
{							\
	.pinaction = GPIO_SCROLLWHEEL_PIN_##_pinaction,	\
	.gpio = TEGRA_GPIO_##_gpio,			\
	.desc = _desc,					\
	.active_low = 1,				\
	.debounce_interval = 2,				\
}

static struct gpio_scrollwheel_button scroll_keys[] = {
	[0] = GPIO_SCROLL(ONOFF, PR3, "sw_onoff"),
	[1] = GPIO_SCROLL(PRESS, PQ5, "sw_press"),
	[2] = GPIO_SCROLL(ROT1, PQ3, "sw_rot1"),
	[3] = GPIO_SCROLL(ROT2, PQ4, "sw_rot2"),
};

static struct gpio_scrollwheel_platform_data cardhu_scroll_platform_data = {
	.buttons = scroll_keys,
	.nbuttons = ARRAY_SIZE(scroll_keys),
};

static struct platform_device cardhu_scroll_device = {
	.name	= "alps-gpio-scrollwheel",
	.id	= 0,
	.dev	= {
		.platform_data = &cardhu_scroll_platform_data,
	},
};

int __init cardhu_scroll_init(void)
{
	int i;
	/* Setting pins to gpio mode */
	for (i = 0; i < ARRAY_SIZE(scroll_keys); i++)
		tegra_gpio_enable(scroll_keys[i].gpio);

	platform_device_register(&cardhu_scroll_device);
	return 0;
}
#else
int __init cardhu_scroll_init(void)
{
	return 0;
}
#endif

#ifdef CONFIG_KEYBOARD_GPIO
#define GPIO_KEY(_id, _gpio, _iswake)		\
	{					\
		.code = _id,			\
		.gpio = TEGRA_GPIO_##_gpio,	\
		.active_low = 1,		\
		.desc = #_id,			\
		.type = EV_KEY,			\
		.wakeup = _iswake,		\
		.debounce_interval = 10,	\
	}

static struct gpio_keys_button cardhu_keys[] = {
	[0] = GPIO_KEY(KEY_HOME, PQ0, 0),
	[1] = GPIO_KEY(KEY_MENU, PQ1, 0),
	[2] = GPIO_KEY(KEY_SEARCH, PQ2, 0),
	[3] = GPIO_KEY(KEY_BACK, PQ3, 0),
	[4] = GPIO_KEY(KEY_VOLUMEUP, PR0, 0),
	[5] = GPIO_KEY(KEY_VOLUMEDOWN, PR1, 0),
	[6] = GPIO_KEY(KEY_POWER, PV0, 1),
};

static struct gpio_keys_platform_data cardhu_keys_platform_data = {
	.buttons	= cardhu_keys,
	.nbuttons       = ARRAY_SIZE(cardhu_keys),
};

static struct platform_device cardhu_keys_device = {
	.name   = "gpio-keys",
	.id     = 0,
	.dev    = {
		.platform_data  = &cardhu_keys_platform_data,
	},
};

int __init cardhu_keys_init(void)
{
	int i;
	int ret;

	/* Set KB_ROW2 to 0 for capcitive switch to be in scan mode */
	ret = gpio_request(TEGRA_GPIO_PR2, "cap_sw_sl_scan");
	if (ret < 0) {
		pr_err("%s: gpio_request failed #%d\n",
					__func__, TEGRA_GPIO_PR2);
		return ret;
	}
	ret = gpio_direction_output(TEGRA_GPIO_PR2, 0);
	if (ret < 0) {
		pr_err("%s: gpio_direction_output failed #%d\n",
					__func__, TEGRA_GPIO_PR2);
		gpio_free(TEGRA_GPIO_PR2);
		return ret;
	}

	tegra_gpio_enable(TEGRA_GPIO_PR2);

	/* Enable gpio mode for other pins */
	for (i = 0; i < ARRAY_SIZE(cardhu_keys); i++)
		tegra_gpio_enable(cardhu_keys[i].gpio);

	platform_device_register(&cardhu_keys_device);
	return 0;
}
#else
int __init cardhu_keys_init(void)
{
	return 0;
}
#endif