summaryrefslogtreecommitdiff
path: root/arch/arm/mach-msm/board-sapphire-keypad.c
blob: 14f12e5e865c416abc43ca40a1eb0aa70ac04359 (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
/* arch/arm/mach-msm/board-sapphire-keypad.c
 * Copyright (C) 2007-2009 HTC Corporation.
 * Author: Thomas Tsai <thomas_tsai@htc.com>
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * 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.
*/

#include <linux/platform_device.h>
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/gpio_event.h>
#include <asm/mach-types.h>
#include "gpio_chip.h"
#include "board-sapphire.h"
static char *keycaps = "--qwerty";
#undef MODULE_PARAM_PREFIX
#define MODULE_PARAM_PREFIX "board_sapphire."
module_param_named(keycaps, keycaps, charp, 0);


static unsigned int sapphire_col_gpios[] = { 35, 34 };

/* KP_MKIN2 (GPIO40) is not used? */
static unsigned int sapphire_row_gpios[] = { 42, 41 };

#define KEYMAP_INDEX(col, row) ((col)*ARRAY_SIZE(sapphire_row_gpios) + (row))

/*scan matrix key*/
/* HOME(up) + MENU (down)*/
static const unsigned short sapphire_keymap1[ARRAY_SIZE(sapphire_col_gpios) *
					ARRAY_SIZE(sapphire_row_gpios)] = {
	[KEYMAP_INDEX(0, 0)] = KEY_BACK,
	[KEYMAP_INDEX(0, 1)] = KEY_MENU,

	[KEYMAP_INDEX(1, 0)] = KEY_HOME,
	[KEYMAP_INDEX(1, 1)] = KEY_SEND,
};

/* MENU(up) + HOME (down)*/
static const unsigned short sapphire_keymap0[ARRAY_SIZE(sapphire_col_gpios) *
					ARRAY_SIZE(sapphire_row_gpios)] = {
	[KEYMAP_INDEX(0, 0)] = KEY_BACK,
	[KEYMAP_INDEX(0, 1)] = KEY_HOME,

	[KEYMAP_INDEX(1, 0)] = KEY_MENU,
	[KEYMAP_INDEX(1, 1)] = KEY_SEND,
};

static struct gpio_event_matrix_info sapphire_keypad_matrix_info = {
	.info.func = gpio_event_matrix_func,
	.keymap = sapphire_keymap1,
	.output_gpios = sapphire_col_gpios,
	.input_gpios = sapphire_row_gpios,
	.noutputs = ARRAY_SIZE(sapphire_col_gpios),
	.ninputs = ARRAY_SIZE(sapphire_row_gpios),
	.settle_time.tv.nsec = 40 * NSEC_PER_USEC,
	.poll_time.tv.nsec = 20 * NSEC_PER_MSEC,
	.debounce_delay.tv.nsec = 50 * NSEC_PER_MSEC,
	.flags = GPIOKPF_LEVEL_TRIGGERED_IRQ |
		 GPIOKPF_REMOVE_PHANTOM_KEYS |
		 GPIOKPF_PRINT_UNMAPPED_KEYS /*| GPIOKPF_PRINT_MAPPED_KEYS*/
};

static struct gpio_event_direct_entry sapphire_keypad_nav_map[] = {
	{ SAPPHIRE_POWER_KEY,              KEY_END        },
	{ SAPPHIRE_VOLUME_UP,              KEY_VOLUMEUP   },
	{ SAPPHIRE_VOLUME_DOWN,            KEY_VOLUMEDOWN },
};

static struct gpio_event_input_info sapphire_keypad_nav_info = {
	.info.func = gpio_event_input_func,
	.flags = 0,
	.type = EV_KEY,
	.keymap = sapphire_keypad_nav_map,
	.debounce_time.tv.nsec = 20 * NSEC_PER_MSEC,
	.keymap_size = ARRAY_SIZE(sapphire_keypad_nav_map)
};

static struct gpio_event_info *sapphire_keypad_info[] = {
	&sapphire_keypad_matrix_info.info,
	&sapphire_keypad_nav_info.info,
};

static struct gpio_event_platform_data sapphire_keypad_data = {
	.name = "sapphire-keypad",
	.info = sapphire_keypad_info,
	.info_count = ARRAY_SIZE(sapphire_keypad_info)
};

static struct platform_device sapphire_keypad_device = {
	.name = GPIO_EVENT_DEV_NAME,
	.id = 0,
	.dev		= {
		.platform_data	= &sapphire_keypad_data,
	},
};

static int __init sapphire_init_keypad(void)
{
	if (!machine_is_sapphire())
		return 0;

	switch (sapphire_get_hwid()) {
	case 0:
		sapphire_keypad_matrix_info.keymap = sapphire_keymap0;
		break;
	default:
		sapphire_keypad_matrix_info.keymap = sapphire_keymap1;
		break;
	}
	return platform_device_register(&sapphire_keypad_device);
}

device_initcall(sapphire_init_keypad);