blob: 5c8fc37649a3c3cc3b7443d54080fbb0147224cc [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* arch/arm/mach-msm/board-sapphire-keypad.c
2 * Copyright (C) 2007-2009 HTC Corporation.
3 * Author: Thomas Tsai <thomas_tsai@htc.com>
4 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13*/
14
15#include <linux/platform_device.h>
16#include <linux/input.h>
17#include <linux/interrupt.h>
18#include <linux/gpio_event.h>
19#include <asm/mach-types.h>
20#include "gpio_chip.h"
21#include "board-sapphire.h"
22static char *keycaps = "--qwerty";
23#undef MODULE_PARAM_PREFIX
24#define MODULE_PARAM_PREFIX "board_sapphire."
25module_param_named(keycaps, keycaps, charp, 0);
26
27
28static unsigned int sapphire_col_gpios[] = { 35, 34 };
29
30/* KP_MKIN2 (GPIO40) is not used? */
31static unsigned int sapphire_row_gpios[] = { 42, 41 };
32
33#define KEYMAP_INDEX(col, row) ((col)*ARRAY_SIZE(sapphire_row_gpios) + (row))
34
35/*scan matrix key*/
36/* HOME(up) MENU (up) Back Search */
37static const unsigned short sapphire_keymap2[ARRAY_SIZE(sapphire_col_gpios) * ARRAY_SIZE(sapphire_row_gpios)] = {
38 [KEYMAP_INDEX(0, 0)] = KEY_COMPOSE,
39 [KEYMAP_INDEX(0, 1)] = KEY_BACK,
40
41 [KEYMAP_INDEX(1, 0)] = KEY_MENU,
42 [KEYMAP_INDEX(1, 1)] = KEY_SEND,
43};
44
45/* HOME(up) + MENU (down)*/
46static const unsigned short sapphire_keymap1[ARRAY_SIZE(sapphire_col_gpios) *
47 ARRAY_SIZE(sapphire_row_gpios)] = {
48 [KEYMAP_INDEX(0, 0)] = KEY_BACK,
49 [KEYMAP_INDEX(0, 1)] = KEY_MENU,
50
51 [KEYMAP_INDEX(1, 0)] = KEY_HOME,
52 [KEYMAP_INDEX(1, 1)] = KEY_SEND,
53};
54
55/* MENU(up) + HOME (down)*/
56static const unsigned short sapphire_keymap0[ARRAY_SIZE(sapphire_col_gpios) *
57 ARRAY_SIZE(sapphire_row_gpios)] = {
58 [KEYMAP_INDEX(0, 0)] = KEY_BACK,
59 [KEYMAP_INDEX(0, 1)] = KEY_HOME,
60
61 [KEYMAP_INDEX(1, 0)] = KEY_MENU,
62 [KEYMAP_INDEX(1, 1)] = KEY_SEND,
63};
64
65static struct gpio_event_matrix_info sapphire_keypad_matrix_info = {
66 .info.func = gpio_event_matrix_func,
67 .keymap = sapphire_keymap2,
68 .output_gpios = sapphire_col_gpios,
69 .input_gpios = sapphire_row_gpios,
70 .noutputs = ARRAY_SIZE(sapphire_col_gpios),
71 .ninputs = ARRAY_SIZE(sapphire_row_gpios),
72 .settle_time.tv.nsec = 40 * NSEC_PER_USEC,
73 .poll_time.tv.nsec = 20 * NSEC_PER_MSEC,
74 .debounce_delay.tv.nsec = 50 * NSEC_PER_MSEC,
75 .flags = GPIOKPF_LEVEL_TRIGGERED_IRQ |
76 GPIOKPF_REMOVE_PHANTOM_KEYS |
77 GPIOKPF_PRINT_UNMAPPED_KEYS /*| GPIOKPF_PRINT_MAPPED_KEYS*/
78};
79
80static struct gpio_event_direct_entry sapphire_keypad_nav_map[] = {
81 { SAPPHIRE_POWER_KEY, KEY_END },
82 { SAPPHIRE_VOLUME_UP, KEY_VOLUMEUP },
83 { SAPPHIRE_VOLUME_DOWN, KEY_VOLUMEDOWN },
84};
85
86static struct gpio_event_input_info sapphire_keypad_nav_info = {
87 .info.func = gpio_event_input_func,
88 .flags = 0,
89 .type = EV_KEY,
90 .keymap = sapphire_keypad_nav_map,
91 .debounce_time.tv.nsec = 20 * NSEC_PER_MSEC,
92 .keymap_size = ARRAY_SIZE(sapphire_keypad_nav_map)
93};
94
95static struct gpio_event_info *sapphire_keypad_info[] = {
96 &sapphire_keypad_matrix_info.info,
97 &sapphire_keypad_nav_info.info,
98};
99
100static struct gpio_event_platform_data sapphire_keypad_data = {
101 .name = "sapphire-keypad",
102 .info = sapphire_keypad_info,
103 .info_count = ARRAY_SIZE(sapphire_keypad_info)
104};
105
106static struct platform_device sapphire_keypad_device = {
107 .name = GPIO_EVENT_DEV_NAME,
108 .id = 0,
109 .dev = {
110 .platform_data = &sapphire_keypad_data,
111 },
112};
113
114static int __init sapphire_init_keypad(void)
115{
116 if (!machine_is_sapphire())
117 return 0;
118
119 switch (sapphire_get_hwid()) {
120 case 0:
121 sapphire_keypad_matrix_info.keymap = sapphire_keymap0;
122 break;
123 default:
124 if(system_rev != 0x80)
125 sapphire_keypad_matrix_info.keymap = sapphire_keymap1;
126 break;
127 }
128 return platform_device_register(&sapphire_keypad_device);
129}
130
131device_initcall(sapphire_init_keypad);
132