Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
Aparna Mallavarapu | 332887b | 2012-10-11 15:51:26 +0530 | [diff] [blame] | 4 | * Copyright (c) 2009-2012, The Linux Foundation. All rights reserved. |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 5 | * |
| 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 Chik | ea64624 | 2011-09-01 13:53:16 -0700 | [diff] [blame] | 34 | #include <dev/ssbi.h> |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 35 | #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 Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 42 | static unsigned int halibut_row_gpios[] = { 31, 32, 33, 34, 35 }; |
| 43 | static unsigned int halibut_col_gpios[] = { 36, 37, 38, 39, 40 }; |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 44 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 45 | static unsigned int halibut_row_gpios_qrd[] = { 31, 32 }; |
| 46 | static unsigned int halibut_col_gpios_qrd[] = { 36, 37 }; |
Channagoud Kadabi | e8b2fd3 | 2011-10-20 15:24:25 +0530 | [diff] [blame] | 47 | |
Aparna Mallavarapu | 332887b | 2012-10-11 15:51:26 +0530 | [diff] [blame] | 48 | static unsigned int halibut_row_gpios_skud[] = { 31, 32 }; |
| 49 | static unsigned int halibut_col_gpios_skud[] = { 37 }; |
| 50 | |
Channagoud Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 51 | static unsigned int halibut_row_gpios_evb[] = { 31 }; |
| 52 | static unsigned int halibut_col_gpios_evb[] = { 36, 37 }; |
| 53 | |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 54 | #define KEYMAP_INDEX(row, col) ((row)*ARRAY_SIZE(halibut_col_gpios) + (col)) |
Channagoud Kadabi | e8b2fd3 | 2011-10-20 15:24:25 +0530 | [diff] [blame] | 55 | #define KEYMAP_INDEX_QRD(row, col) ((row)*ARRAY_SIZE(halibut_col_gpios_qrd) + (col)) |
Channagoud Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 56 | #define KEYMAP_INDEX_EVB(row, col) ((row)*ARRAY_SIZE(halibut_col_gpios_evb) + (col)) |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 57 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 58 | static const unsigned short halibut_keymap[ARRAY_SIZE(halibut_col_gpios) * |
| 59 | ARRAY_SIZE(halibut_row_gpios)] = { |
Shashank Mittal | 3976307 | 2011-04-08 17:45:50 -0700 | [diff] [blame] | 60 | [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 Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 65 | |
Shashank Mittal | 3976307 | 2011-04-08 17:45:50 -0700 | [diff] [blame] | 66 | [KEYMAP_INDEX(1, 0)] = KEY_LEFT, |
| 67 | [KEYMAP_INDEX(1, 1)] = KEY_SEND, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 68 | [KEYMAP_INDEX(1, 2)] = KEY_1, |
Shashank Mittal | 3976307 | 2011-04-08 17:45:50 -0700 | [diff] [blame] | 69 | [KEYMAP_INDEX(1, 3)] = KEY_4, |
| 70 | [KEYMAP_INDEX(1, 4)] = KEY_CLEAR, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 71 | |
Shashank Mittal | 3976307 | 2011-04-08 17:45:50 -0700 | [diff] [blame] | 72 | [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 Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 77 | |
Shashank Mittal | 3976307 | 2011-04-08 17:45:50 -0700 | [diff] [blame] | 78 | [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 Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 83 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 84 | [KEYMAP_INDEX(4, 0)] = KEY_MENU, /*R- */ |
| 85 | [KEYMAP_INDEX(4, 1)] = KEY_HOME, /*L+ */ |
| 86 | [KEYMAP_INDEX(4, 2)] = KEY_BACK, /*L- */ |
Shashank Mittal | 3976307 | 2011-04-08 17:45:50 -0700 | [diff] [blame] | 87 | [KEYMAP_INDEX(4, 3)] = KEY_VOLUMEUP, |
| 88 | [KEYMAP_INDEX(4, 4)] = KEY_VOLUMEDOWN, |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 89 | }; |
| 90 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 91 | static const unsigned short halibut_keymap_qrd[ARRAY_SIZE(halibut_col_gpios_qrd) |
| 92 | * |
| 93 | ARRAY_SIZE |
| 94 | (halibut_row_gpios_qrd)] = { |
Channagoud Kadabi | e8b2fd3 | 2011-10-20 15:24:25 +0530 | [diff] [blame] | 95 | [KEYMAP_INDEX_QRD(0, 0)] = KEY_VOLUMEUP, |
| 96 | [KEYMAP_INDEX_QRD(0, 1)] = KEY_VOLUMEDOWN, |
| 97 | }; |
| 98 | |
Channagoud Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 99 | static 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 Kadabi | e8b2fd3 | 2011-10-20 15:24:25 +0530 | [diff] [blame] | 107 | static struct gpio_keypad_info halibut_keypad_info_surf = { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 108 | .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 Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 116 | }; |
| 117 | |
Channagoud Kadabi | e8b2fd3 | 2011-10-20 15:24:25 +0530 | [diff] [blame] | 118 | static struct gpio_keypad_info halibut_keypad_info_qrd = { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 119 | .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 Kadabi | e8b2fd3 | 2011-10-20 15:24:25 +0530 | [diff] [blame] | 127 | }; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 128 | |
Aparna Mallavarapu | 332887b | 2012-10-11 15:51:26 +0530 | [diff] [blame] | 129 | static 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 Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 139 | static 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 Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 150 | void keypad_init(void) |
| 151 | { |
Aparna Mallavarapu | ac33298 | 2012-03-18 14:02:38 +0530 | [diff] [blame] | 152 | if (machine_is_qrd()) |
Channagoud Kadabi | e8b2fd3 | 2011-10-20 15:24:25 +0530 | [diff] [blame] | 153 | gpio_keypad_init(&halibut_keypad_info_qrd); |
Aparna Mallavarapu | 332887b | 2012-10-11 15:51:26 +0530 | [diff] [blame] | 154 | else if (machine_is_skud()) |
| 155 | gpio_keypad_init(&halibut_keypad_info_skud); |
Channagoud Kadabi | 3acfb74 | 2011-11-15 18:19:32 +0530 | [diff] [blame] | 156 | else if (machine_is_evb()) |
Channagoud Kadabi | d53664b | 2011-12-28 16:39:15 +0530 | [diff] [blame] | 157 | gpio_keypad_init(&halibut_keypad_info_evb); |
Channagoud Kadabi | e8b2fd3 | 2011-10-20 15:24:25 +0530 | [diff] [blame] | 158 | else |
| 159 | gpio_keypad_init(&halibut_keypad_info_surf); |
Shashank Mittal | 246f8d0 | 2011-01-21 17:12:27 -0800 | [diff] [blame] | 160 | } |