blob: 2ac788b3cb9f893df3d54ef70ef4ed0cb406b8ab [file] [log] [blame]
Shashank Mittal246f8d02011-01-21 17:12:27 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
Aparna Mallavarapu332887b2012-10-11 15:51:26 +05304 * Copyright (c) 2009-2012, The Linux Foundation. All rights reserved.
Shashank Mittal246f8d02011-01-21 17:12:27 -08005 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google, Inc. nor the names of its contributors
16 * may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <dev/keys.h>
Kinson Chikea646242011-09-01 13:53:16 -070034#include <dev/ssbi.h>
Shashank Mittal246f8d02011-01-21 17:12:27 -080035#include <dev/gpio_keypad.h>
36
37#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
38
39/* don't turn this on without updating the ffa support */
40#define SCAN_FUNCTION_KEYS 0
41
Ajay Dudanib01e5062011-12-03 23:23:42 -080042static unsigned int halibut_row_gpios[] = { 31, 32, 33, 34, 35 };
43static unsigned int halibut_col_gpios[] = { 36, 37, 38, 39, 40 };
Shashank Mittal246f8d02011-01-21 17:12:27 -080044
Ajay Dudanib01e5062011-12-03 23:23:42 -080045static unsigned int halibut_row_gpios_qrd[] = { 31, 32 };
46static unsigned int halibut_col_gpios_qrd[] = { 36, 37 };
Channagoud Kadabie8b2fd32011-10-20 15:24:25 +053047
Aparna Mallavarapu332887b2012-10-11 15:51:26 +053048static unsigned int halibut_row_gpios_skud[] = { 31, 32 };
49static unsigned int halibut_col_gpios_skud[] = { 37 };
50
Channagoud Kadabid53664b2011-12-28 16:39:15 +053051static unsigned int halibut_row_gpios_evb[] = { 31 };
52static unsigned int halibut_col_gpios_evb[] = { 36, 37 };
53
Shashank Mittal246f8d02011-01-21 17:12:27 -080054#define KEYMAP_INDEX(row, col) ((row)*ARRAY_SIZE(halibut_col_gpios) + (col))
Channagoud Kadabie8b2fd32011-10-20 15:24:25 +053055#define KEYMAP_INDEX_QRD(row, col) ((row)*ARRAY_SIZE(halibut_col_gpios_qrd) + (col))
Channagoud Kadabid53664b2011-12-28 16:39:15 +053056#define KEYMAP_INDEX_EVB(row, col) ((row)*ARRAY_SIZE(halibut_col_gpios_evb) + (col))
Shashank Mittal246f8d02011-01-21 17:12:27 -080057
Ajay Dudanib01e5062011-12-03 23:23:42 -080058static const unsigned short halibut_keymap[ARRAY_SIZE(halibut_col_gpios) *
59 ARRAY_SIZE(halibut_row_gpios)] = {
Shashank Mittal39763072011-04-08 17:45:50 -070060 [KEYMAP_INDEX(0, 0)] = KEY_7,
61 [KEYMAP_INDEX(0, 1)] = KEY_DOWN,
62 [KEYMAP_INDEX(0, 2)] = KEY_UP,
63 [KEYMAP_INDEX(0, 3)] = KEY_RIGHT,
64 [KEYMAP_INDEX(0, 4)] = KEY_CENTER,
Shashank Mittal246f8d02011-01-21 17:12:27 -080065
Shashank Mittal39763072011-04-08 17:45:50 -070066 [KEYMAP_INDEX(1, 0)] = KEY_LEFT,
67 [KEYMAP_INDEX(1, 1)] = KEY_SEND,
Shashank Mittal246f8d02011-01-21 17:12:27 -080068 [KEYMAP_INDEX(1, 2)] = KEY_1,
Shashank Mittal39763072011-04-08 17:45:50 -070069 [KEYMAP_INDEX(1, 3)] = KEY_4,
70 [KEYMAP_INDEX(1, 4)] = KEY_CLEAR,
Shashank Mittal246f8d02011-01-21 17:12:27 -080071
Shashank Mittal39763072011-04-08 17:45:50 -070072 [KEYMAP_INDEX(2, 0)] = KEY_6,
73 [KEYMAP_INDEX(2, 1)] = KEY_5,
74 [KEYMAP_INDEX(2, 2)] = KEY_8,
75 [KEYMAP_INDEX(2, 3)] = KEY_3,
76 [KEYMAP_INDEX(2, 4)] = KEY_STAR,
Shashank Mittal246f8d02011-01-21 17:12:27 -080077
Shashank Mittal39763072011-04-08 17:45:50 -070078 [KEYMAP_INDEX(3, 0)] = KEY_9,
79 [KEYMAP_INDEX(3, 1)] = KEY_SOFT1,
80 [KEYMAP_INDEX(3, 2)] = KEY_0,
81 [KEYMAP_INDEX(3, 3)] = KEY_2,
82 [KEYMAP_INDEX(3, 4)] = KEY_SOFT2,
Shashank Mittal246f8d02011-01-21 17:12:27 -080083
Ajay Dudanib01e5062011-12-03 23:23:42 -080084 [KEYMAP_INDEX(4, 0)] = KEY_MENU, /*R- */
85 [KEYMAP_INDEX(4, 1)] = KEY_HOME, /*L+ */
86 [KEYMAP_INDEX(4, 2)] = KEY_BACK, /*L- */
Shashank Mittal39763072011-04-08 17:45:50 -070087 [KEYMAP_INDEX(4, 3)] = KEY_VOLUMEUP,
88 [KEYMAP_INDEX(4, 4)] = KEY_VOLUMEDOWN,
Shashank Mittal246f8d02011-01-21 17:12:27 -080089};
90
Ajay Dudanib01e5062011-12-03 23:23:42 -080091static const unsigned short halibut_keymap_qrd[ARRAY_SIZE(halibut_col_gpios_qrd)
92 *
93 ARRAY_SIZE
94 (halibut_row_gpios_qrd)] = {
Channagoud Kadabie8b2fd32011-10-20 15:24:25 +053095 [KEYMAP_INDEX_QRD(0, 0)] = KEY_VOLUMEUP,
96 [KEYMAP_INDEX_QRD(0, 1)] = KEY_VOLUMEDOWN,
97};
98
Channagoud Kadabid53664b2011-12-28 16:39:15 +053099static const unsigned short halibut_keymap_evb[ARRAY_SIZE(halibut_col_gpios_evb)
100 *
101 ARRAY_SIZE
102 (halibut_row_gpios_evb)] = {
103 [KEYMAP_INDEX_EVB(0, 0)] = KEY_VOLUMEUP,
104 [KEYMAP_INDEX_EVB(0, 1)] = KEY_VOLUMEDOWN,
105};
106
Channagoud Kadabie8b2fd32011-10-20 15:24:25 +0530107static struct gpio_keypad_info halibut_keypad_info_surf = {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800108 .keymap = halibut_keymap,
109 .output_gpios = halibut_row_gpios,
110 .input_gpios = halibut_col_gpios,
111 .noutputs = ARRAY_SIZE(halibut_row_gpios),
112 .ninputs = ARRAY_SIZE(halibut_col_gpios),
113 .settle_time = 5 /* msec */ ,
114 .poll_time = 20 /* msec */ ,
115 .flags = GPIOKPF_DRIVE_INACTIVE,
Shashank Mittal246f8d02011-01-21 17:12:27 -0800116};
117
Channagoud Kadabie8b2fd32011-10-20 15:24:25 +0530118static struct gpio_keypad_info halibut_keypad_info_qrd = {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800119 .keymap = halibut_keymap_qrd,
120 .output_gpios = halibut_row_gpios_qrd,
121 .input_gpios = halibut_col_gpios_qrd,
122 .noutputs = ARRAY_SIZE(halibut_row_gpios_qrd),
123 .ninputs = ARRAY_SIZE(halibut_col_gpios_qrd),
124 .settle_time = 5 /* msec */ ,
125 .poll_time = 20 /* msec */ ,
126 .flags = GPIOKPF_DRIVE_INACTIVE,
Channagoud Kadabie8b2fd32011-10-20 15:24:25 +0530127};
Ajay Dudanib01e5062011-12-03 23:23:42 -0800128
Aparna Mallavarapu332887b2012-10-11 15:51:26 +0530129static struct gpio_keypad_info halibut_keypad_info_skud = {
130 .keymap = halibut_keymap_qrd,
131 .output_gpios = halibut_row_gpios_skud,
132 .input_gpios = halibut_col_gpios_skud,
133 .noutputs = ARRAY_SIZE(halibut_row_gpios_skud),
134 .ninputs = ARRAY_SIZE(halibut_col_gpios_skud),
135 .settle_time = 5 /* msec */ ,
136 .poll_time = 20 /* msec */ ,
137 .flags = GPIOKPF_DRIVE_INACTIVE,
138};
Channagoud Kadabid53664b2011-12-28 16:39:15 +0530139static struct gpio_keypad_info halibut_keypad_info_evb = {
140 .keymap = halibut_keymap_evb,
141 .output_gpios = halibut_row_gpios_evb,
142 .input_gpios = halibut_col_gpios_evb,
143 .noutputs = ARRAY_SIZE(halibut_row_gpios_evb),
144 .ninputs = ARRAY_SIZE(halibut_col_gpios_evb),
145 .settle_time = 5 /* msec */ ,
146 .poll_time = 20 /* msec */ ,
147 .flags = GPIOKPF_DRIVE_INACTIVE,
148};
149
Shashank Mittal246f8d02011-01-21 17:12:27 -0800150void keypad_init(void)
151{
Aparna Mallavarapuac332982012-03-18 14:02:38 +0530152 if (machine_is_qrd())
Channagoud Kadabie8b2fd32011-10-20 15:24:25 +0530153 gpio_keypad_init(&halibut_keypad_info_qrd);
Aparna Mallavarapu332887b2012-10-11 15:51:26 +0530154 else if (machine_is_skud())
155 gpio_keypad_init(&halibut_keypad_info_skud);
Channagoud Kadabi3acfb742011-11-15 18:19:32 +0530156 else if (machine_is_evb())
Channagoud Kadabid53664b2011-12-28 16:39:15 +0530157 gpio_keypad_init(&halibut_keypad_info_evb);
Channagoud Kadabie8b2fd32011-10-20 15:24:25 +0530158 else
159 gpio_keypad_init(&halibut_keypad_info_surf);
Shashank Mittal246f8d02011-01-21 17:12:27 -0800160}