Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 1 | /* |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 2 | * Copyright (c) 2000-2001 Vojtech Pavlik |
Jiri Kosina | 7d39e84 | 2010-02-02 20:46:34 +0100 | [diff] [blame] | 3 | * Copyright (c) 2006-2010 Jiri Kosina |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 4 | * |
| 5 | * HID to Linux Input mapping |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | * |
| 23 | * Should you need to contact me, the author, you can do so either by |
| 24 | * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: |
| 25 | * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic |
| 26 | */ |
| 27 | |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/kernel.h> |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 31 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 32 | #include <linux/hid.h> |
Jiri Kosina | c080d89 | 2007-01-25 11:43:31 +0100 | [diff] [blame] | 33 | #include <linux/hid-debug.h> |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 34 | |
| 35 | #define unk KEY_UNKNOWN |
| 36 | |
| 37 | static const unsigned char hid_keyboard[256] = { |
| 38 | 0, 0, 0, 0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, |
| 39 | 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 2, 3, |
| 40 | 4, 5, 6, 7, 8, 9, 10, 11, 28, 1, 14, 15, 57, 12, 13, 26, |
| 41 | 27, 43, 43, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64, |
| 42 | 65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106, |
| 43 | 105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71, |
| 44 | 72, 73, 82, 83, 86,127,116,117,183,184,185,186,187,188,189,190, |
| 45 | 191,192,193,194,134,138,130,132,128,129,131,137,133,135,136,113, |
| 46 | 115,114,unk,unk,unk,121,unk, 89, 93,124, 92, 94, 95,unk,unk,unk, |
Jarod Wilson | 437f3b1 | 2011-04-19 15:28:30 -0400 | [diff] [blame] | 47 | 122,123, 90, 91, 85,unk,unk,unk,unk,unk,unk,unk,111,unk,unk,unk, |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 48 | unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk, |
Jiri Kosina | 1fe8736d | 2007-08-09 13:24:11 +0200 | [diff] [blame] | 49 | unk,unk,unk,unk,unk,unk,179,180,unk,unk,unk,unk,unk,unk,unk,unk, |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 50 | unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk, |
Jarod Wilson | 437f3b1 | 2011-04-19 15:28:30 -0400 | [diff] [blame] | 51 | unk,unk,unk,unk,unk,unk,unk,unk,111,unk,unk,unk,unk,unk,unk,unk, |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 52 | 29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113, |
| 53 | 150,158,159,128,136,177,178,176,142,152,173,140,unk,unk,unk,unk |
| 54 | }; |
| 55 | |
| 56 | static const struct { |
| 57 | __s32 x; |
| 58 | __s32 y; |
| 59 | } hid_hat_to_axis[] = {{ 0, 0}, { 0,-1}, { 1,-1}, { 1, 0}, { 1, 1}, { 0, 1}, {-1, 1}, {-1, 0}, {-1,-1}}; |
| 60 | |
Jiri Slaby | 022e8c4 | 2008-05-16 11:49:18 +0200 | [diff] [blame] | 61 | #define map_abs(c) hid_map_usage(hidinput, usage, &bit, &max, EV_ABS, (c)) |
| 62 | #define map_rel(c) hid_map_usage(hidinput, usage, &bit, &max, EV_REL, (c)) |
| 63 | #define map_key(c) hid_map_usage(hidinput, usage, &bit, &max, EV_KEY, (c)) |
| 64 | #define map_led(c) hid_map_usage(hidinput, usage, &bit, &max, EV_LED, (c)) |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 65 | |
Jiri Slaby | 022e8c4 | 2008-05-16 11:49:18 +0200 | [diff] [blame] | 66 | #define map_abs_clear(c) hid_map_usage_clear(hidinput, usage, &bit, \ |
| 67 | &max, EV_ABS, (c)) |
| 68 | #define map_key_clear(c) hid_map_usage_clear(hidinput, usage, &bit, \ |
| 69 | &max, EV_KEY, (c)) |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 70 | |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 71 | static bool match_scancode(struct hid_usage *usage, |
| 72 | unsigned int cur_idx, unsigned int scancode) |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 73 | { |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 74 | return (usage->hid & (HID_USAGE_PAGE | HID_USAGE)) == scancode; |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 75 | } |
| 76 | |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 77 | static bool match_keycode(struct hid_usage *usage, |
| 78 | unsigned int cur_idx, unsigned int keycode) |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 79 | { |
Dmitry Torokhov | f5854fa | 2010-09-15 19:36:56 -0700 | [diff] [blame] | 80 | /* |
| 81 | * We should exclude unmapped usages when doing lookup by keycode. |
| 82 | */ |
| 83 | return (usage->type == EV_KEY && usage->code == keycode); |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 84 | } |
| 85 | |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 86 | static bool match_index(struct hid_usage *usage, |
| 87 | unsigned int cur_idx, unsigned int idx) |
| 88 | { |
| 89 | return cur_idx == idx; |
| 90 | } |
| 91 | |
| 92 | typedef bool (*hid_usage_cmp_t)(struct hid_usage *usage, |
| 93 | unsigned int cur_idx, unsigned int val); |
| 94 | |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 95 | static struct hid_usage *hidinput_find_key(struct hid_device *hid, |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 96 | hid_usage_cmp_t match, |
| 97 | unsigned int value, |
| 98 | unsigned int *usage_idx) |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 99 | { |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 100 | unsigned int i, j, k, cur_idx = 0; |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 101 | struct hid_report *report; |
| 102 | struct hid_usage *usage; |
| 103 | |
| 104 | for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) { |
| 105 | list_for_each_entry(report, &hid->report_enum[k].report_list, list) { |
| 106 | for (i = 0; i < report->maxfield; i++) { |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 107 | for (j = 0; j < report->field[i]->maxusage; j++) { |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 108 | usage = report->field[i]->usage + j; |
Dmitry Torokhov | f5854fa | 2010-09-15 19:36:56 -0700 | [diff] [blame] | 109 | if (usage->type == EV_KEY || usage->type == 0) { |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 110 | if (match(usage, cur_idx, value)) { |
| 111 | if (usage_idx) |
| 112 | *usage_idx = cur_idx; |
| 113 | return usage; |
| 114 | } |
| 115 | cur_idx++; |
| 116 | } |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | return NULL; |
| 122 | } |
| 123 | |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 124 | static struct hid_usage *hidinput_locate_usage(struct hid_device *hid, |
| 125 | const struct input_keymap_entry *ke, |
| 126 | unsigned int *index) |
| 127 | { |
| 128 | struct hid_usage *usage; |
| 129 | unsigned int scancode; |
| 130 | |
| 131 | if (ke->flags & INPUT_KEYMAP_BY_INDEX) |
| 132 | usage = hidinput_find_key(hid, match_index, ke->index, index); |
| 133 | else if (input_scancode_to_scalar(ke, &scancode) == 0) |
| 134 | usage = hidinput_find_key(hid, match_scancode, scancode, index); |
| 135 | else |
| 136 | usage = NULL; |
| 137 | |
| 138 | return usage; |
| 139 | } |
| 140 | |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 141 | static int hidinput_getkeycode(struct input_dev *dev, |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 142 | struct input_keymap_entry *ke) |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 143 | { |
Dmitry Torokhov | f202df6 | 2007-10-31 12:33:26 +0100 | [diff] [blame] | 144 | struct hid_device *hid = input_get_drvdata(dev); |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 145 | struct hid_usage *usage; |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 146 | unsigned int scancode, index; |
Jiri Kosina | 77b2966 | 2007-08-09 14:04:56 +0200 | [diff] [blame] | 147 | |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 148 | usage = hidinput_locate_usage(hid, ke, &index); |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 149 | if (usage) { |
Dmitry Torokhov | f5854fa | 2010-09-15 19:36:56 -0700 | [diff] [blame] | 150 | ke->keycode = usage->type == EV_KEY ? |
| 151 | usage->code : KEY_RESERVED; |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 152 | ke->index = index; |
| 153 | scancode = usage->hid & (HID_USAGE_PAGE | HID_USAGE); |
| 154 | ke->len = sizeof(scancode); |
| 155 | memcpy(ke->scancode, &scancode, sizeof(scancode)); |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 156 | return 0; |
| 157 | } |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 158 | |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 159 | return -EINVAL; |
| 160 | } |
| 161 | |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 162 | static int hidinput_setkeycode(struct input_dev *dev, |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 163 | const struct input_keymap_entry *ke, |
| 164 | unsigned int *old_keycode) |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 165 | { |
Dmitry Torokhov | f202df6 | 2007-10-31 12:33:26 +0100 | [diff] [blame] | 166 | struct hid_device *hid = input_get_drvdata(dev); |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 167 | struct hid_usage *usage; |
Jiri Kosina | 77b2966 | 2007-08-09 14:04:56 +0200 | [diff] [blame] | 168 | |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 169 | usage = hidinput_locate_usage(hid, ke, NULL); |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 170 | if (usage) { |
Dmitry Torokhov | f5854fa | 2010-09-15 19:36:56 -0700 | [diff] [blame] | 171 | *old_keycode = usage->type == EV_KEY ? |
| 172 | usage->code : KEY_RESERVED; |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 173 | usage->code = ke->keycode; |
Jiri Kosina | 77b2966 | 2007-08-09 14:04:56 +0200 | [diff] [blame] | 174 | |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 175 | clear_bit(*old_keycode, dev->keybit); |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 176 | set_bit(usage->code, dev->keybit); |
Joe Perches | 587d145 | 2010-10-25 19:44:21 -0700 | [diff] [blame] | 177 | dbg_hid("Assigned keycode %d to HID usage code %x\n", |
Dmitry Torokhov | a0bf0ea | 2010-09-09 21:57:17 -0700 | [diff] [blame] | 178 | usage->code, usage->hid); |
| 179 | |
| 180 | /* |
| 181 | * Set the keybit for the old keycode if the old keycode is used |
| 182 | * by another key |
| 183 | */ |
| 184 | if (hidinput_find_key(hid, match_keycode, *old_keycode, NULL)) |
| 185 | set_bit(*old_keycode, dev->keybit); |
Jiri Kosina | 77b2966 | 2007-08-09 14:04:56 +0200 | [diff] [blame] | 186 | |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 187 | return 0; |
| 188 | } |
Jiri Kosina | 77b2966 | 2007-08-09 14:04:56 +0200 | [diff] [blame] | 189 | |
Marvin Raaijmakers | fe7ba31 | 2007-05-09 10:57:20 +0200 | [diff] [blame] | 190 | return -EINVAL; |
| 191 | } |
| 192 | |
| 193 | |
Nikolai Kondrashov | 4ea6e4f | 2010-09-15 14:51:14 +0400 | [diff] [blame] | 194 | /** |
| 195 | * hidinput_calc_abs_res - calculate an absolute axis resolution |
| 196 | * @field: the HID report field to calculate resolution for |
| 197 | * @code: axis code |
| 198 | * |
| 199 | * The formula is: |
| 200 | * (logical_maximum - logical_minimum) |
| 201 | * resolution = ---------------------------------------------------------- |
| 202 | * (physical_maximum - physical_minimum) * 10 ^ unit_exponent |
| 203 | * |
| 204 | * as seen in the HID specification v1.11 6.2.2.7 Global Items. |
| 205 | * |
Dmitry Torokhov | 83ed79c | 2010-12-02 11:49:06 +0100 | [diff] [blame] | 206 | * Only exponent 1 length units are processed. Centimeters and inches are |
| 207 | * converted to millimeters. Degrees are converted to radians. |
Nikolai Kondrashov | 4ea6e4f | 2010-09-15 14:51:14 +0400 | [diff] [blame] | 208 | */ |
| 209 | static __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code) |
| 210 | { |
| 211 | __s32 unit_exponent = field->unit_exponent; |
| 212 | __s32 logical_extents = field->logical_maximum - |
| 213 | field->logical_minimum; |
| 214 | __s32 physical_extents = field->physical_maximum - |
| 215 | field->physical_minimum; |
| 216 | __s32 prev; |
| 217 | |
| 218 | /* Check if the extents are sane */ |
| 219 | if (logical_extents <= 0 || physical_extents <= 0) |
| 220 | return 0; |
| 221 | |
| 222 | /* |
| 223 | * Verify and convert units. |
| 224 | * See HID specification v1.11 6.2.2.7 Global Items for unit decoding |
| 225 | */ |
| 226 | if (code == ABS_X || code == ABS_Y || code == ABS_Z) { |
| 227 | if (field->unit == 0x11) { /* If centimeters */ |
Dmitry Torokhov | 83ed79c | 2010-12-02 11:49:06 +0100 | [diff] [blame] | 228 | /* Convert to millimeters */ |
| 229 | unit_exponent += 1; |
| 230 | } else if (field->unit == 0x13) { /* If inches */ |
| 231 | /* Convert to millimeters */ |
| 232 | prev = physical_extents; |
| 233 | physical_extents *= 254; |
| 234 | if (physical_extents < prev) |
Nikolai Kondrashov | 4ea6e4f | 2010-09-15 14:51:14 +0400 | [diff] [blame] | 235 | return 0; |
Dmitry Torokhov | 83ed79c | 2010-12-02 11:49:06 +0100 | [diff] [blame] | 236 | unit_exponent -= 1; |
| 237 | } else { |
Nikolai Kondrashov | 4ea6e4f | 2010-09-15 14:51:14 +0400 | [diff] [blame] | 238 | return 0; |
| 239 | } |
| 240 | } else if (code == ABS_RX || code == ABS_RY || code == ABS_RZ) { |
| 241 | if (field->unit == 0x14) { /* If degrees */ |
| 242 | /* Convert to radians */ |
| 243 | prev = logical_extents; |
| 244 | logical_extents *= 573; |
| 245 | if (logical_extents < prev) |
| 246 | return 0; |
| 247 | unit_exponent += 1; |
| 248 | } else if (field->unit != 0x12) { /* If not radians */ |
| 249 | return 0; |
| 250 | } |
| 251 | } else { |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | /* Apply negative unit exponent */ |
| 256 | for (; unit_exponent < 0; unit_exponent++) { |
| 257 | prev = logical_extents; |
| 258 | logical_extents *= 10; |
| 259 | if (logical_extents < prev) |
| 260 | return 0; |
| 261 | } |
| 262 | /* Apply positive unit exponent */ |
| 263 | for (; unit_exponent > 0; unit_exponent--) { |
| 264 | prev = physical_extents; |
| 265 | physical_extents *= 10; |
| 266 | if (physical_extents < prev) |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | /* Calculate resolution */ |
| 271 | return logical_extents / physical_extents; |
| 272 | } |
| 273 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 274 | static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_field *field, |
| 275 | struct hid_usage *usage) |
| 276 | { |
| 277 | struct input_dev *input = hidinput->input; |
Dmitry Torokhov | e071298 | 2007-05-09 10:17:31 +0200 | [diff] [blame] | 278 | struct hid_device *device = input_get_drvdata(input); |
Jiri Slaby | 3715ade | 2008-07-31 11:09:37 +0200 | [diff] [blame] | 279 | int max = 0, code; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 280 | unsigned long *bit = NULL; |
| 281 | |
| 282 | field->hidinput = hidinput; |
| 283 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 284 | if (field->flags & HID_MAIN_ITEM_CONSTANT) |
| 285 | goto ignore; |
| 286 | |
Jiri Kosina | 82eb121 | 2007-08-11 23:39:42 +0200 | [diff] [blame] | 287 | /* only LED usages are supported in output fields */ |
| 288 | if (field->report_type == HID_OUTPUT_REPORT && |
| 289 | (usage->hid & HID_USAGE_PAGE) != HID_UP_LED) { |
Jiri Kosina | 82eb121 | 2007-08-11 23:39:42 +0200 | [diff] [blame] | 290 | goto ignore; |
| 291 | } |
| 292 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 293 | if (device->driver->input_mapping) { |
| 294 | int ret = device->driver->input_mapping(device, hidinput, field, |
| 295 | usage, &bit, &max); |
| 296 | if (ret > 0) |
| 297 | goto mapped; |
| 298 | if (ret < 0) |
| 299 | goto ignore; |
| 300 | } |
| 301 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 302 | switch (usage->hid & HID_USAGE_PAGE) { |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 303 | case HID_UP_UNDEFINED: |
| 304 | goto ignore; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 305 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 306 | case HID_UP_KEYBOARD: |
| 307 | set_bit(EV_REP, input->evbit); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 308 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 309 | if ((usage->hid & HID_USAGE) < 256) { |
| 310 | if (!hid_keyboard[usage->hid & HID_USAGE]) goto ignore; |
| 311 | map_key_clear(hid_keyboard[usage->hid & HID_USAGE]); |
| 312 | } else |
| 313 | map_key(KEY_UNKNOWN); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 314 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 315 | break; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 316 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 317 | case HID_UP_BUTTON: |
Jiri Kosina | 7f978b9 | 2010-02-17 09:36:35 +0100 | [diff] [blame] | 318 | code = ((usage->hid - 1) & HID_USAGE); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 319 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 320 | switch (field->application) { |
| 321 | case HID_GD_MOUSE: |
Florian Fainelli | 1874542 | 2010-12-14 11:56:56 +0100 | [diff] [blame] | 322 | case HID_GD_POINTER: code += BTN_MOUSE; break; |
Jiri Kosina | cf2f765 | 2010-01-04 12:20:56 +0100 | [diff] [blame] | 323 | case HID_GD_JOYSTICK: |
Daniel Mack | fc99f22 | 2010-07-12 19:28:26 +0200 | [diff] [blame] | 324 | if (code <= 0xf) |
| 325 | code += BTN_JOYSTICK; |
| 326 | else |
| 327 | code += BTN_TRIGGER_HAPPY; |
| 328 | break; |
Florian Fainelli | 1874542 | 2010-12-14 11:56:56 +0100 | [diff] [blame] | 329 | case HID_GD_GAMEPAD: code += BTN_GAMEPAD; break; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 330 | default: |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 331 | switch (field->physical) { |
| 332 | case HID_GD_MOUSE: |
Florian Fainelli | 1874542 | 2010-12-14 11:56:56 +0100 | [diff] [blame] | 333 | case HID_GD_POINTER: code += BTN_MOUSE; break; |
| 334 | case HID_GD_JOYSTICK: code += BTN_JOYSTICK; break; |
| 335 | case HID_GD_GAMEPAD: code += BTN_GAMEPAD; break; |
| 336 | default: code += BTN_MISC; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 337 | } |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | map_key(code); |
| 341 | break; |
| 342 | |
| 343 | case HID_UP_SIMULATION: |
| 344 | switch (usage->hid & 0xffff) { |
| 345 | case 0xba: map_abs(ABS_RUDDER); break; |
| 346 | case 0xbb: map_abs(ABS_THROTTLE); break; |
| 347 | case 0xc4: map_abs(ABS_GAS); break; |
| 348 | case 0xc5: map_abs(ABS_BRAKE); break; |
| 349 | case 0xc8: map_abs(ABS_WHEEL); break; |
| 350 | default: goto ignore; |
| 351 | } |
| 352 | break; |
| 353 | |
| 354 | case HID_UP_GENDESK: |
| 355 | if ((usage->hid & 0xf0) == 0x80) { /* SystemControl */ |
| 356 | switch (usage->hid & 0xf) { |
| 357 | case 0x1: map_key_clear(KEY_POWER); break; |
| 358 | case 0x2: map_key_clear(KEY_SLEEP); break; |
| 359 | case 0x3: map_key_clear(KEY_WAKEUP); break; |
Jarod Wilson | 437f3b1 | 2011-04-19 15:28:30 -0400 | [diff] [blame] | 360 | case 0x4: map_key_clear(KEY_CONTEXT_MENU); break; |
| 361 | case 0x5: map_key_clear(KEY_MENU); break; |
| 362 | case 0x6: map_key_clear(KEY_PROG1); break; |
| 363 | case 0x7: map_key_clear(KEY_HELP); break; |
| 364 | case 0x8: map_key_clear(KEY_EXIT); break; |
| 365 | case 0x9: map_key_clear(KEY_SELECT); break; |
| 366 | case 0xa: map_key_clear(KEY_RIGHT); break; |
| 367 | case 0xb: map_key_clear(KEY_LEFT); break; |
| 368 | case 0xc: map_key_clear(KEY_UP); break; |
| 369 | case 0xd: map_key_clear(KEY_DOWN); break; |
| 370 | case 0xe: map_key_clear(KEY_POWER2); break; |
| 371 | case 0xf: map_key_clear(KEY_RESTART); break; |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 372 | default: goto unknown; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 373 | } |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 374 | break; |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | if ((usage->hid & 0xf0) == 0x90) { /* D-pad */ |
| 378 | switch (usage->hid) { |
| 379 | case HID_GD_UP: usage->hat_dir = 1; break; |
| 380 | case HID_GD_DOWN: usage->hat_dir = 5; break; |
| 381 | case HID_GD_RIGHT: usage->hat_dir = 3; break; |
| 382 | case HID_GD_LEFT: usage->hat_dir = 7; break; |
| 383 | default: goto unknown; |
| 384 | } |
| 385 | if (field->dpad) { |
| 386 | map_abs(field->dpad); |
| 387 | goto ignore; |
| 388 | } |
| 389 | map_abs(ABS_HAT0X); |
| 390 | break; |
| 391 | } |
| 392 | |
| 393 | switch (usage->hid) { |
| 394 | /* These usage IDs map directly to the usage codes. */ |
| 395 | case HID_GD_X: case HID_GD_Y: case HID_GD_Z: |
| 396 | case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ: |
| 397 | case HID_GD_SLIDER: case HID_GD_DIAL: case HID_GD_WHEEL: |
| 398 | if (field->flags & HID_MAIN_ITEM_RELATIVE) |
| 399 | map_rel(usage->hid & 0xf); |
| 400 | else |
| 401 | map_abs(usage->hid & 0xf); |
| 402 | break; |
| 403 | |
| 404 | case HID_GD_HATSWITCH: |
| 405 | usage->hat_min = field->logical_minimum; |
| 406 | usage->hat_max = field->logical_maximum; |
| 407 | map_abs(ABS_HAT0X); |
| 408 | break; |
| 409 | |
| 410 | case HID_GD_START: map_key_clear(BTN_START); break; |
| 411 | case HID_GD_SELECT: map_key_clear(BTN_SELECT); break; |
| 412 | |
| 413 | default: goto unknown; |
| 414 | } |
| 415 | |
| 416 | break; |
| 417 | |
| 418 | case HID_UP_LED: |
| 419 | switch (usage->hid & 0xffff) { /* HID-Value: */ |
| 420 | case 0x01: map_led (LED_NUML); break; /* "Num Lock" */ |
| 421 | case 0x02: map_led (LED_CAPSL); break; /* "Caps Lock" */ |
| 422 | case 0x03: map_led (LED_SCROLLL); break; /* "Scroll Lock" */ |
| 423 | case 0x04: map_led (LED_COMPOSE); break; /* "Compose" */ |
| 424 | case 0x05: map_led (LED_KANA); break; /* "Kana" */ |
| 425 | case 0x27: map_led (LED_SLEEP); break; /* "Stand-By" */ |
| 426 | case 0x4c: map_led (LED_SUSPEND); break; /* "System Suspend" */ |
| 427 | case 0x09: map_led (LED_MUTE); break; /* "Mute" */ |
| 428 | case 0x4b: map_led (LED_MISC); break; /* "Generic Indicator" */ |
| 429 | case 0x19: map_led (LED_MAIL); break; /* "Message Waiting" */ |
| 430 | case 0x4d: map_led (LED_CHARGING); break; /* "External Power Connected" */ |
| 431 | |
| 432 | default: goto ignore; |
| 433 | } |
| 434 | break; |
| 435 | |
| 436 | case HID_UP_DIGITIZER: |
| 437 | switch (usage->hid & 0xff) { |
Forest Bond | 8c8b01c | 2010-07-13 23:50:57 +0200 | [diff] [blame] | 438 | case 0x00: /* Undefined */ |
| 439 | goto ignore; |
| 440 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 441 | case 0x30: /* TipPressure */ |
| 442 | if (!test_bit(BTN_TOUCH, input->keybit)) { |
| 443 | device->quirks |= HID_QUIRK_NOTOUCH; |
| 444 | set_bit(EV_KEY, input->evbit); |
| 445 | set_bit(BTN_TOUCH, input->keybit); |
| 446 | } |
| 447 | map_abs_clear(ABS_PRESSURE); |
| 448 | break; |
| 449 | |
| 450 | case 0x32: /* InRange */ |
| 451 | switch (field->physical & 0xff) { |
| 452 | case 0x21: map_key(BTN_TOOL_MOUSE); break; |
| 453 | case 0x22: map_key(BTN_TOOL_FINGER); break; |
| 454 | default: map_key(BTN_TOOL_PEN); break; |
| 455 | } |
| 456 | break; |
| 457 | |
| 458 | case 0x3c: /* Invert */ |
| 459 | map_key_clear(BTN_TOOL_RUBBER); |
| 460 | break; |
| 461 | |
| 462 | case 0x33: /* Touch */ |
| 463 | case 0x42: /* TipSwitch */ |
| 464 | case 0x43: /* TipSwitch2 */ |
| 465 | device->quirks &= ~HID_QUIRK_NOTOUCH; |
| 466 | map_key_clear(BTN_TOUCH); |
| 467 | break; |
| 468 | |
| 469 | case 0x44: /* BarrelSwitch */ |
| 470 | map_key_clear(BTN_STYLUS); |
| 471 | break; |
| 472 | |
Nikolai Kondrashov | 50b63697 | 2010-08-06 23:03:07 +0400 | [diff] [blame] | 473 | case 0x46: /* TabletPick */ |
| 474 | map_key_clear(BTN_STYLUS2); |
| 475 | break; |
| 476 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 477 | default: goto unknown; |
| 478 | } |
| 479 | break; |
| 480 | |
Jarod Wilson | 437f3b1 | 2011-04-19 15:28:30 -0400 | [diff] [blame] | 481 | case HID_UP_CONSUMER: /* USB HUT v1.12, pages 75-84 */ |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 482 | switch (usage->hid & HID_USAGE) { |
| 483 | case 0x000: goto ignore; |
Jarod Wilson | 437f3b1 | 2011-04-19 15:28:30 -0400 | [diff] [blame] | 484 | case 0x030: map_key_clear(KEY_POWER); break; |
| 485 | case 0x031: map_key_clear(KEY_RESTART); break; |
| 486 | case 0x032: map_key_clear(KEY_SLEEP); break; |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 487 | case 0x034: map_key_clear(KEY_SLEEP); break; |
Jarod Wilson | 437f3b1 | 2011-04-19 15:28:30 -0400 | [diff] [blame] | 488 | case 0x035: map_key_clear(KEY_KBDILLUMTOGGLE); break; |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 489 | case 0x036: map_key_clear(BTN_MISC); break; |
| 490 | |
Jarod Wilson | 437f3b1 | 2011-04-19 15:28:30 -0400 | [diff] [blame] | 491 | case 0x040: map_key_clear(KEY_MENU); break; /* Menu */ |
| 492 | case 0x041: map_key_clear(KEY_SELECT); break; /* Menu Pick */ |
| 493 | case 0x042: map_key_clear(KEY_UP); break; /* Menu Up */ |
| 494 | case 0x043: map_key_clear(KEY_DOWN); break; /* Menu Down */ |
| 495 | case 0x044: map_key_clear(KEY_LEFT); break; /* Menu Left */ |
| 496 | case 0x045: map_key_clear(KEY_RIGHT); break; /* Menu Right */ |
| 497 | case 0x046: map_key_clear(KEY_ESC); break; /* Menu Escape */ |
| 498 | case 0x047: map_key_clear(KEY_KPPLUS); break; /* Menu Value Increase */ |
| 499 | case 0x048: map_key_clear(KEY_KPMINUS); break; /* Menu Value Decrease */ |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 500 | |
Jarod Wilson | 437f3b1 | 2011-04-19 15:28:30 -0400 | [diff] [blame] | 501 | case 0x060: map_key_clear(KEY_INFO); break; /* Data On Screen */ |
| 502 | case 0x061: map_key_clear(KEY_SUBTITLE); break; /* Closed Caption */ |
| 503 | case 0x063: map_key_clear(KEY_VCR); break; /* VCR/TV */ |
| 504 | case 0x065: map_key_clear(KEY_CAMERA); break; /* Snapshot */ |
| 505 | case 0x069: map_key_clear(KEY_RED); break; |
| 506 | case 0x06a: map_key_clear(KEY_GREEN); break; |
| 507 | case 0x06b: map_key_clear(KEY_BLUE); break; |
| 508 | case 0x06c: map_key_clear(KEY_YELLOW); break; |
| 509 | case 0x06d: map_key_clear(KEY_ZOOM); break; |
| 510 | |
| 511 | case 0x082: map_key_clear(KEY_VIDEO_NEXT); break; |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 512 | case 0x083: map_key_clear(KEY_LAST); break; |
Jarod Wilson | 437f3b1 | 2011-04-19 15:28:30 -0400 | [diff] [blame] | 513 | case 0x084: map_key_clear(KEY_ENTER); break; |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 514 | case 0x088: map_key_clear(KEY_PC); break; |
| 515 | case 0x089: map_key_clear(KEY_TV); break; |
| 516 | case 0x08a: map_key_clear(KEY_WWW); break; |
| 517 | case 0x08b: map_key_clear(KEY_DVD); break; |
| 518 | case 0x08c: map_key_clear(KEY_PHONE); break; |
| 519 | case 0x08d: map_key_clear(KEY_PROGRAM); break; |
| 520 | case 0x08e: map_key_clear(KEY_VIDEOPHONE); break; |
| 521 | case 0x08f: map_key_clear(KEY_GAMES); break; |
| 522 | case 0x090: map_key_clear(KEY_MEMO); break; |
| 523 | case 0x091: map_key_clear(KEY_CD); break; |
| 524 | case 0x092: map_key_clear(KEY_VCR); break; |
| 525 | case 0x093: map_key_clear(KEY_TUNER); break; |
| 526 | case 0x094: map_key_clear(KEY_EXIT); break; |
| 527 | case 0x095: map_key_clear(KEY_HELP); break; |
| 528 | case 0x096: map_key_clear(KEY_TAPE); break; |
| 529 | case 0x097: map_key_clear(KEY_TV2); break; |
| 530 | case 0x098: map_key_clear(KEY_SAT); break; |
| 531 | case 0x09a: map_key_clear(KEY_PVR); break; |
| 532 | |
| 533 | case 0x09c: map_key_clear(KEY_CHANNELUP); break; |
| 534 | case 0x09d: map_key_clear(KEY_CHANNELDOWN); break; |
| 535 | case 0x0a0: map_key_clear(KEY_VCR2); break; |
| 536 | |
| 537 | case 0x0b0: map_key_clear(KEY_PLAY); break; |
| 538 | case 0x0b1: map_key_clear(KEY_PAUSE); break; |
| 539 | case 0x0b2: map_key_clear(KEY_RECORD); break; |
| 540 | case 0x0b3: map_key_clear(KEY_FASTFORWARD); break; |
| 541 | case 0x0b4: map_key_clear(KEY_REWIND); break; |
| 542 | case 0x0b5: map_key_clear(KEY_NEXTSONG); break; |
| 543 | case 0x0b6: map_key_clear(KEY_PREVIOUSSONG); break; |
| 544 | case 0x0b7: map_key_clear(KEY_STOPCD); break; |
| 545 | case 0x0b8: map_key_clear(KEY_EJECTCD); break; |
| 546 | case 0x0bc: map_key_clear(KEY_MEDIA_REPEAT); break; |
Jarod Wilson | 437f3b1 | 2011-04-19 15:28:30 -0400 | [diff] [blame] | 547 | case 0x0b9: map_key_clear(KEY_SHUFFLE); break; |
| 548 | case 0x0bf: map_key_clear(KEY_SLOW); break; |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 549 | |
| 550 | case 0x0cd: map_key_clear(KEY_PLAYPAUSE); break; |
| 551 | case 0x0e0: map_abs_clear(ABS_VOLUME); break; |
| 552 | case 0x0e2: map_key_clear(KEY_MUTE); break; |
| 553 | case 0x0e5: map_key_clear(KEY_BASSBOOST); break; |
| 554 | case 0x0e9: map_key_clear(KEY_VOLUMEUP); break; |
| 555 | case 0x0ea: map_key_clear(KEY_VOLUMEDOWN); break; |
Jarod Wilson | 437f3b1 | 2011-04-19 15:28:30 -0400 | [diff] [blame] | 556 | case 0x0f5: map_key_clear(KEY_SLOW); break; |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 557 | |
| 558 | case 0x182: map_key_clear(KEY_BOOKMARKS); break; |
| 559 | case 0x183: map_key_clear(KEY_CONFIG); break; |
| 560 | case 0x184: map_key_clear(KEY_WORDPROCESSOR); break; |
| 561 | case 0x185: map_key_clear(KEY_EDITOR); break; |
| 562 | case 0x186: map_key_clear(KEY_SPREADSHEET); break; |
| 563 | case 0x187: map_key_clear(KEY_GRAPHICSEDITOR); break; |
| 564 | case 0x188: map_key_clear(KEY_PRESENTATION); break; |
| 565 | case 0x189: map_key_clear(KEY_DATABASE); break; |
| 566 | case 0x18a: map_key_clear(KEY_MAIL); break; |
| 567 | case 0x18b: map_key_clear(KEY_NEWS); break; |
| 568 | case 0x18c: map_key_clear(KEY_VOICEMAIL); break; |
| 569 | case 0x18d: map_key_clear(KEY_ADDRESSBOOK); break; |
| 570 | case 0x18e: map_key_clear(KEY_CALENDAR); break; |
| 571 | case 0x191: map_key_clear(KEY_FINANCE); break; |
| 572 | case 0x192: map_key_clear(KEY_CALC); break; |
Jarod Wilson | 437f3b1 | 2011-04-19 15:28:30 -0400 | [diff] [blame] | 573 | case 0x193: map_key_clear(KEY_PLAYER); break; |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 574 | case 0x194: map_key_clear(KEY_FILE); break; |
| 575 | case 0x196: map_key_clear(KEY_WWW); break; |
Leo P White | 0690535 | 2010-02-08 13:02:05 +0000 | [diff] [blame] | 576 | case 0x199: map_key_clear(KEY_CHAT); break; |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 577 | case 0x19c: map_key_clear(KEY_LOGOFF); break; |
| 578 | case 0x19e: map_key_clear(KEY_COFFEE); break; |
| 579 | case 0x1a6: map_key_clear(KEY_HELP); break; |
| 580 | case 0x1a7: map_key_clear(KEY_DOCUMENTS); break; |
| 581 | case 0x1ab: map_key_clear(KEY_SPELLCHECK); break; |
Jarod Wilson | 437f3b1 | 2011-04-19 15:28:30 -0400 | [diff] [blame] | 582 | case 0x1ae: map_key_clear(KEY_KEYBOARD); break; |
| 583 | case 0x1b6: map_key_clear(KEY_IMAGES); break; |
| 584 | case 0x1b7: map_key_clear(KEY_AUDIO); break; |
| 585 | case 0x1b8: map_key_clear(KEY_VIDEO); break; |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 586 | case 0x1bc: map_key_clear(KEY_MESSENGER); break; |
| 587 | case 0x1bd: map_key_clear(KEY_INFO); break; |
| 588 | case 0x201: map_key_clear(KEY_NEW); break; |
| 589 | case 0x202: map_key_clear(KEY_OPEN); break; |
| 590 | case 0x203: map_key_clear(KEY_CLOSE); break; |
| 591 | case 0x204: map_key_clear(KEY_EXIT); break; |
| 592 | case 0x207: map_key_clear(KEY_SAVE); break; |
| 593 | case 0x208: map_key_clear(KEY_PRINT); break; |
| 594 | case 0x209: map_key_clear(KEY_PROPS); break; |
| 595 | case 0x21a: map_key_clear(KEY_UNDO); break; |
| 596 | case 0x21b: map_key_clear(KEY_COPY); break; |
| 597 | case 0x21c: map_key_clear(KEY_CUT); break; |
| 598 | case 0x21d: map_key_clear(KEY_PASTE); break; |
| 599 | case 0x21f: map_key_clear(KEY_FIND); break; |
| 600 | case 0x221: map_key_clear(KEY_SEARCH); break; |
| 601 | case 0x222: map_key_clear(KEY_GOTO); break; |
| 602 | case 0x223: map_key_clear(KEY_HOMEPAGE); break; |
| 603 | case 0x224: map_key_clear(KEY_BACK); break; |
| 604 | case 0x225: map_key_clear(KEY_FORWARD); break; |
| 605 | case 0x226: map_key_clear(KEY_STOP); break; |
| 606 | case 0x227: map_key_clear(KEY_REFRESH); break; |
| 607 | case 0x22a: map_key_clear(KEY_BOOKMARKS); break; |
| 608 | case 0x22d: map_key_clear(KEY_ZOOMIN); break; |
| 609 | case 0x22e: map_key_clear(KEY_ZOOMOUT); break; |
| 610 | case 0x22f: map_key_clear(KEY_ZOOMRESET); break; |
| 611 | case 0x233: map_key_clear(KEY_SCROLLUP); break; |
| 612 | case 0x234: map_key_clear(KEY_SCROLLDOWN); break; |
| 613 | case 0x238: map_rel(REL_HWHEEL); break; |
Jarod Wilson | 437f3b1 | 2011-04-19 15:28:30 -0400 | [diff] [blame] | 614 | case 0x23d: map_key_clear(KEY_EDIT); break; |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 615 | case 0x25f: map_key_clear(KEY_CANCEL); break; |
Jarod Wilson | 437f3b1 | 2011-04-19 15:28:30 -0400 | [diff] [blame] | 616 | case 0x269: map_key_clear(KEY_INSERT); break; |
| 617 | case 0x26a: map_key_clear(KEY_DELETE); break; |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 618 | case 0x279: map_key_clear(KEY_REDO); break; |
| 619 | |
| 620 | case 0x289: map_key_clear(KEY_REPLY); break; |
| 621 | case 0x28b: map_key_clear(KEY_FORWARDMAIL); break; |
| 622 | case 0x28c: map_key_clear(KEY_SEND); break; |
| 623 | |
| 624 | default: goto ignore; |
| 625 | } |
| 626 | break; |
| 627 | |
| 628 | case HID_UP_HPVENDOR: /* Reported on a Dutch layout HP5308 */ |
| 629 | set_bit(EV_REP, input->evbit); |
| 630 | switch (usage->hid & HID_USAGE) { |
| 631 | case 0x021: map_key_clear(KEY_PRINT); break; |
| 632 | case 0x070: map_key_clear(KEY_HP); break; |
| 633 | case 0x071: map_key_clear(KEY_CAMERA); break; |
| 634 | case 0x072: map_key_clear(KEY_SOUND); break; |
| 635 | case 0x073: map_key_clear(KEY_QUESTION); break; |
| 636 | case 0x080: map_key_clear(KEY_EMAIL); break; |
| 637 | case 0x081: map_key_clear(KEY_CHAT); break; |
| 638 | case 0x082: map_key_clear(KEY_SEARCH); break; |
| 639 | case 0x083: map_key_clear(KEY_CONNECT); break; |
| 640 | case 0x084: map_key_clear(KEY_FINANCE); break; |
| 641 | case 0x085: map_key_clear(KEY_SPORT); break; |
| 642 | case 0x086: map_key_clear(KEY_SHOP); break; |
| 643 | default: goto ignore; |
| 644 | } |
| 645 | break; |
| 646 | |
| 647 | case HID_UP_MSVENDOR: |
| 648 | goto ignore; |
| 649 | |
| 650 | case HID_UP_CUSTOM: /* Reported on Logitech and Apple USB keyboards */ |
| 651 | set_bit(EV_REP, input->evbit); |
| 652 | goto ignore; |
| 653 | |
| 654 | case HID_UP_LOGIVENDOR: |
| 655 | goto ignore; |
Daniel Mack | fc99f22 | 2010-07-12 19:28:26 +0200 | [diff] [blame] | 656 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 657 | case HID_UP_PID: |
| 658 | switch (usage->hid & HID_USAGE) { |
| 659 | case 0xa4: map_key_clear(BTN_DEAD); break; |
| 660 | default: goto ignore; |
| 661 | } |
| 662 | break; |
| 663 | |
| 664 | default: |
| 665 | unknown: |
| 666 | if (field->report_size == 1) { |
| 667 | if (field->report->type == HID_OUTPUT_REPORT) { |
| 668 | map_led(LED_MISC); |
| 669 | break; |
| 670 | } |
| 671 | map_key(BTN_MISC); |
| 672 | break; |
| 673 | } |
| 674 | if (field->flags & HID_MAIN_ITEM_RELATIVE) { |
| 675 | map_rel(REL_MISC); |
| 676 | break; |
| 677 | } |
| 678 | map_abs(ABS_MISC); |
| 679 | break; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 680 | } |
| 681 | |
Jiri Kosina | 10bd065 | 2007-11-22 15:18:18 +0100 | [diff] [blame] | 682 | mapped: |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 683 | if (device->driver->input_mapped && device->driver->input_mapped(device, |
| 684 | hidinput, field, usage, &bit, &max) < 0) |
| 685 | goto ignore; |
| 686 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 687 | set_bit(usage->type, input->evbit); |
| 688 | |
| 689 | while (usage->code <= max && test_and_set_bit(usage->code, bit)) |
| 690 | usage->code = find_next_zero_bit(bit, max + 1, usage->code); |
| 691 | |
| 692 | if (usage->code > max) |
| 693 | goto ignore; |
| 694 | |
| 695 | |
| 696 | if (usage->type == EV_ABS) { |
| 697 | |
| 698 | int a = field->logical_minimum; |
| 699 | int b = field->logical_maximum; |
| 700 | |
| 701 | if ((device->quirks & HID_QUIRK_BADPAD) && (usage->code == ABS_X || usage->code == ABS_Y)) { |
| 702 | a = field->logical_minimum = 0; |
| 703 | b = field->logical_maximum = 255; |
| 704 | } |
| 705 | |
| 706 | if (field->application == HID_GD_GAMEPAD || field->application == HID_GD_JOYSTICK) |
| 707 | input_set_abs_params(input, usage->code, a, b, (b - a) >> 8, (b - a) >> 4); |
| 708 | else input_set_abs_params(input, usage->code, a, b, 0, 0); |
| 709 | |
Nikolai Kondrashov | 4ea6e4f | 2010-09-15 14:51:14 +0400 | [diff] [blame] | 710 | input_abs_set_res(input, usage->code, |
| 711 | hidinput_calc_abs_res(field, usage->code)); |
| 712 | |
Henrik Rydberg | 6967b4d | 2010-06-23 09:31:37 -0700 | [diff] [blame] | 713 | /* use a larger default input buffer for MT devices */ |
| 714 | if (usage->code == ABS_MT_POSITION_X && input->hint_events_per_packet == 0) |
| 715 | input_set_events_per_packet(input, 60); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | if (usage->type == EV_ABS && |
| 719 | (usage->hat_min < usage->hat_max || usage->hat_dir)) { |
| 720 | int i; |
| 721 | for (i = usage->code; i < usage->code + 2 && i <= max; i++) { |
| 722 | input_set_abs_params(input, i, -1, 1, 0, 0); |
| 723 | set_bit(i, input->absbit); |
| 724 | } |
| 725 | if (usage->hat_dir && !field->dpad) |
| 726 | field->dpad = usage->code; |
| 727 | } |
| 728 | |
Jiri Kosina | 2c1d8ae | 2007-07-04 16:45:59 +0200 | [diff] [blame] | 729 | /* for those devices which produce Consumer volume usage as relative, |
| 730 | * we emulate pressing volumeup/volumedown appropriate number of times |
| 731 | * in hidinput_hid_event() |
| 732 | */ |
| 733 | if ((usage->type == EV_ABS) && (field->flags & HID_MAIN_ITEM_RELATIVE) && |
| 734 | (usage->code == ABS_VOLUME)) { |
| 735 | set_bit(KEY_VOLUMEUP, input->keybit); |
| 736 | set_bit(KEY_VOLUMEDOWN, input->keybit); |
| 737 | } |
| 738 | |
Jiri Kosina | c01d50d | 2007-08-20 12:13:34 +0200 | [diff] [blame] | 739 | if (usage->type == EV_KEY) { |
| 740 | set_bit(EV_MSC, input->evbit); |
| 741 | set_bit(MSC_SCAN, input->mscbit); |
| 742 | } |
| 743 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 744 | ignore: |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 745 | return; |
Jiri Kosina | a635f9d | 2009-06-12 15:20:55 +0200 | [diff] [blame] | 746 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value) |
| 750 | { |
| 751 | struct input_dev *input; |
Al Viro | b4482a4 | 2007-10-14 19:35:40 +0100 | [diff] [blame] | 752 | unsigned *quirks = &hid->quirks; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 753 | |
| 754 | if (!field->hidinput) |
| 755 | return; |
| 756 | |
| 757 | input = field->hidinput->input; |
| 758 | |
| 759 | if (!usage->type) |
| 760 | return; |
| 761 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 762 | if (usage->hat_min < usage->hat_max || usage->hat_dir) { |
| 763 | int hat_dir = usage->hat_dir; |
| 764 | if (!hat_dir) |
| 765 | hat_dir = (value - usage->hat_min) * 8 / (usage->hat_max - usage->hat_min + 1) + 1; |
| 766 | if (hat_dir < 0 || hat_dir > 8) hat_dir = 0; |
| 767 | input_event(input, usage->type, usage->code , hid_hat_to_axis[hat_dir].x); |
Daniel Mack | fc99f22 | 2010-07-12 19:28:26 +0200 | [diff] [blame] | 768 | input_event(input, usage->type, usage->code + 1, hid_hat_to_axis[hat_dir].y); |
| 769 | return; |
| 770 | } |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 771 | |
| 772 | if (usage->hid == (HID_UP_DIGITIZER | 0x003c)) { /* Invert */ |
| 773 | *quirks = value ? (*quirks | HID_QUIRK_INVERT) : (*quirks & ~HID_QUIRK_INVERT); |
| 774 | return; |
| 775 | } |
| 776 | |
| 777 | if (usage->hid == (HID_UP_DIGITIZER | 0x0032)) { /* InRange */ |
| 778 | if (value) { |
| 779 | input_event(input, usage->type, (*quirks & HID_QUIRK_INVERT) ? BTN_TOOL_RUBBER : usage->code, 1); |
| 780 | return; |
| 781 | } |
| 782 | input_event(input, usage->type, usage->code, 0); |
| 783 | input_event(input, usage->type, BTN_TOOL_RUBBER, 0); |
| 784 | return; |
| 785 | } |
| 786 | |
| 787 | if (usage->hid == (HID_UP_DIGITIZER | 0x0030) && (*quirks & HID_QUIRK_NOTOUCH)) { /* Pressure */ |
| 788 | int a = field->logical_minimum; |
| 789 | int b = field->logical_maximum; |
| 790 | input_event(input, EV_KEY, BTN_TOUCH, value > a + ((b - a) >> 3)); |
| 791 | } |
| 792 | |
| 793 | if (usage->hid == (HID_UP_PID | 0x83UL)) { /* Simultaneous Effects Max */ |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 794 | dbg_hid("Maximum Effects - %d\n",value); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 795 | return; |
| 796 | } |
| 797 | |
| 798 | if (usage->hid == (HID_UP_PID | 0x7fUL)) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 799 | dbg_hid("PID Pool Report\n"); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 800 | return; |
| 801 | } |
| 802 | |
| 803 | if ((usage->type == EV_KEY) && (usage->code == 0)) /* Key 0 is "unassigned", not KEY_UNKNOWN */ |
| 804 | return; |
| 805 | |
Jiri Kosina | 2c1d8ae | 2007-07-04 16:45:59 +0200 | [diff] [blame] | 806 | if ((usage->type == EV_ABS) && (field->flags & HID_MAIN_ITEM_RELATIVE) && |
| 807 | (usage->code == ABS_VOLUME)) { |
| 808 | int count = abs(value); |
| 809 | int direction = value > 0 ? KEY_VOLUMEUP : KEY_VOLUMEDOWN; |
| 810 | int i; |
| 811 | |
| 812 | for (i = 0; i < count; i++) { |
| 813 | input_event(input, EV_KEY, direction, 1); |
| 814 | input_sync(input); |
| 815 | input_event(input, EV_KEY, direction, 0); |
| 816 | input_sync(input); |
| 817 | } |
| 818 | return; |
| 819 | } |
| 820 | |
Jiri Kosina | c01d50d | 2007-08-20 12:13:34 +0200 | [diff] [blame] | 821 | /* report the usage code as scancode if the key status has changed */ |
| 822 | if (usage->type == EV_KEY && !!test_bit(usage->code, input->key) != value) |
| 823 | input_event(input, EV_MSC, MSC_SCAN, usage->hid); |
Jiri Kosina | 1fe8736d | 2007-08-09 13:24:11 +0200 | [diff] [blame] | 824 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 825 | input_event(input, usage->type, usage->code, value); |
| 826 | |
| 827 | if ((field->flags & HID_MAIN_ITEM_RELATIVE) && (usage->type == EV_KEY)) |
| 828 | input_event(input, usage->type, usage->code, 0); |
| 829 | } |
| 830 | |
| 831 | void hidinput_report_event(struct hid_device *hid, struct hid_report *report) |
| 832 | { |
| 833 | struct hid_input *hidinput; |
| 834 | |
Henrik Rydberg | 24750f3 | 2010-08-24 10:54:44 +0200 | [diff] [blame] | 835 | if (hid->quirks & HID_QUIRK_NO_INPUT_SYNC) |
| 836 | return; |
| 837 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 838 | list_for_each_entry(hidinput, &hid->inputs, list) |
| 839 | input_sync(hidinput->input); |
| 840 | } |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 841 | EXPORT_SYMBOL_GPL(hidinput_report_event); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 842 | |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 843 | int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int code, struct hid_field **field) |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 844 | { |
| 845 | struct hid_report *report; |
| 846 | int i, j; |
| 847 | |
| 848 | list_for_each_entry(report, &hid->report_enum[HID_OUTPUT_REPORT].report_list, list) { |
| 849 | for (i = 0; i < report->maxfield; i++) { |
| 850 | *field = report->field[i]; |
| 851 | for (j = 0; j < (*field)->maxusage; j++) |
| 852 | if ((*field)->usage[j].type == type && (*field)->usage[j].code == code) |
| 853 | return j; |
| 854 | } |
| 855 | } |
| 856 | return -1; |
| 857 | } |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 858 | EXPORT_SYMBOL_GPL(hidinput_find_field); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 859 | |
Jiri Kosina | 7c37914 | 2007-01-24 11:54:19 +0100 | [diff] [blame] | 860 | static int hidinput_open(struct input_dev *dev) |
| 861 | { |
Dmitry Torokhov | e071298 | 2007-05-09 10:17:31 +0200 | [diff] [blame] | 862 | struct hid_device *hid = input_get_drvdata(dev); |
| 863 | |
Dmitry Torokhov | 5bea766 | 2010-12-07 23:02:48 -0800 | [diff] [blame] | 864 | return hid_hw_open(hid); |
Jiri Kosina | 7c37914 | 2007-01-24 11:54:19 +0100 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | static void hidinput_close(struct input_dev *dev) |
| 868 | { |
Dmitry Torokhov | e071298 | 2007-05-09 10:17:31 +0200 | [diff] [blame] | 869 | struct hid_device *hid = input_get_drvdata(dev); |
| 870 | |
Dmitry Torokhov | 5bea766 | 2010-12-07 23:02:48 -0800 | [diff] [blame] | 871 | hid_hw_close(hid); |
Jiri Kosina | 7c37914 | 2007-01-24 11:54:19 +0100 | [diff] [blame] | 872 | } |
| 873 | |
Henrik Rydberg | f635bd1 | 2011-02-24 19:30:59 +0100 | [diff] [blame] | 874 | static void report_features(struct hid_device *hid) |
| 875 | { |
| 876 | struct hid_driver *drv = hid->driver; |
| 877 | struct hid_report_enum *rep_enum; |
| 878 | struct hid_report *rep; |
| 879 | int i, j; |
| 880 | |
| 881 | if (!drv->feature_mapping) |
| 882 | return; |
| 883 | |
| 884 | rep_enum = &hid->report_enum[HID_FEATURE_REPORT]; |
| 885 | list_for_each_entry(rep, &rep_enum->report_list, list) |
| 886 | for (i = 0; i < rep->maxfield; i++) |
| 887 | for (j = 0; j < rep->field[i]->maxusage; j++) |
| 888 | drv->feature_mapping(hid, rep->field[i], |
| 889 | rep->field[i]->usage + j); |
| 890 | } |
| 891 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 892 | /* |
| 893 | * Register the input device; print a message. |
| 894 | * Configure the input layer interface |
| 895 | * Read all reports and initialize the absolute field values. |
| 896 | */ |
| 897 | |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 898 | int hidinput_connect(struct hid_device *hid, unsigned int force) |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 899 | { |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 900 | struct hid_report *report; |
| 901 | struct hid_input *hidinput = NULL; |
| 902 | struct input_dev *input_dev; |
| 903 | int i, j, k; |
| 904 | |
| 905 | INIT_LIST_HEAD(&hid->inputs); |
| 906 | |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 907 | if (!force) { |
| 908 | for (i = 0; i < hid->maxcollection; i++) { |
| 909 | struct hid_collection *col = &hid->collection[i]; |
| 910 | if (col->type == HID_COLLECTION_APPLICATION || |
| 911 | col->type == HID_COLLECTION_PHYSICAL) |
| 912 | if (IS_INPUT_APPLICATION(col->usage)) |
| 913 | break; |
| 914 | } |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 915 | |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 916 | if (i == hid->maxcollection) |
| 917 | return -1; |
| 918 | } |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 919 | |
Henrik Rydberg | f635bd1 | 2011-02-24 19:30:59 +0100 | [diff] [blame] | 920 | report_features(hid); |
| 921 | |
| 922 | for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) { |
Benjamin Tissoires | 0d2689c | 2011-01-07 23:44:32 +0100 | [diff] [blame] | 923 | if (k == HID_OUTPUT_REPORT && |
| 924 | hid->quirks & HID_QUIRK_SKIP_OUTPUT_REPORTS) |
| 925 | continue; |
Anssi Hannula | 5556fea | 2007-01-11 16:51:17 +0200 | [diff] [blame] | 926 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 927 | list_for_each_entry(report, &hid->report_enum[k].report_list, list) { |
| 928 | |
| 929 | if (!report->maxfield) |
| 930 | continue; |
| 931 | |
| 932 | if (!hidinput) { |
| 933 | hidinput = kzalloc(sizeof(*hidinput), GFP_KERNEL); |
| 934 | input_dev = input_allocate_device(); |
| 935 | if (!hidinput || !input_dev) { |
| 936 | kfree(hidinput); |
| 937 | input_free_device(input_dev); |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 938 | hid_err(hid, "Out of memory during hid input probe\n"); |
Dirk Hohndel | 368d290 | 2007-10-30 13:02:44 +0100 | [diff] [blame] | 939 | goto out_unwind; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 940 | } |
| 941 | |
Dmitry Torokhov | e071298 | 2007-05-09 10:17:31 +0200 | [diff] [blame] | 942 | input_set_drvdata(input_dev, hid); |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 943 | input_dev->event = |
| 944 | hid->ll_driver->hidinput_input_event; |
Jiri Kosina | 7c37914 | 2007-01-24 11:54:19 +0100 | [diff] [blame] | 945 | input_dev->open = hidinput_open; |
| 946 | input_dev->close = hidinput_close; |
Dmitry Torokhov | aebd636 | 2011-01-31 21:06:39 -0800 | [diff] [blame] | 947 | input_dev->setkeycode = hidinput_setkeycode; |
| 948 | input_dev->getkeycode = hidinput_getkeycode; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 949 | |
| 950 | input_dev->name = hid->name; |
| 951 | input_dev->phys = hid->phys; |
| 952 | input_dev->uniq = hid->uniq; |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 953 | input_dev->id.bustype = hid->bus; |
| 954 | input_dev->id.vendor = hid->vendor; |
| 955 | input_dev->id.product = hid->product; |
| 956 | input_dev->id.version = hid->version; |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 957 | input_dev->dev.parent = hid->dev.parent; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 958 | hidinput->input = input_dev; |
| 959 | list_add_tail(&hidinput->list, &hid->inputs); |
| 960 | } |
| 961 | |
| 962 | for (i = 0; i < report->maxfield; i++) |
| 963 | for (j = 0; j < report->field[i]->maxusage; j++) |
| 964 | hidinput_configure_usage(hidinput, report->field[i], |
| 965 | report->field[i]->usage + j); |
| 966 | |
| 967 | if (hid->quirks & HID_QUIRK_MULTI_INPUT) { |
| 968 | /* This will leave hidinput NULL, so that it |
| 969 | * allocates another one if we have more inputs on |
| 970 | * the same interface. Some devices (e.g. Happ's |
| 971 | * UGCI) cram a lot of unrelated inputs into the |
| 972 | * same interface. */ |
| 973 | hidinput->report = report; |
Jaikumar Ganesh | 8bf44e9 | 2011-09-20 16:40:43 -0700 | [diff] [blame] | 974 | if (hid->driver->input_register && |
| 975 | hid->driver->input_register(hid, hidinput)) |
| 976 | goto out_cleanup; |
Dirk Hohndel | 368d290 | 2007-10-30 13:02:44 +0100 | [diff] [blame] | 977 | if (input_register_device(hidinput->input)) |
| 978 | goto out_cleanup; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 979 | hidinput = NULL; |
| 980 | } |
| 981 | } |
Benjamin Tissoires | 0d2689c | 2011-01-07 23:44:32 +0100 | [diff] [blame] | 982 | } |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 983 | |
Jaikumar Ganesh | 6c6f91c | 2011-09-21 17:18:56 -0700 | [diff] [blame] | 984 | if (hidinput && hid->driver->input_register && |
Jaikumar Ganesh | 8bf44e9 | 2011-09-20 16:40:43 -0700 | [diff] [blame] | 985 | hid->driver->input_register(hid, hidinput)) |
| 986 | goto out_cleanup; |
| 987 | |
Dirk Hohndel | 368d290 | 2007-10-30 13:02:44 +0100 | [diff] [blame] | 988 | if (hidinput && input_register_device(hidinput->input)) |
| 989 | goto out_cleanup; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 990 | |
| 991 | return 0; |
Dirk Hohndel | 368d290 | 2007-10-30 13:02:44 +0100 | [diff] [blame] | 992 | |
| 993 | out_cleanup: |
Benjamin Tissoires | d923630 | 2011-02-15 15:41:10 +0100 | [diff] [blame] | 994 | list_del(&hidinput->list); |
Dirk Hohndel | 368d290 | 2007-10-30 13:02:44 +0100 | [diff] [blame] | 995 | input_free_device(hidinput->input); |
| 996 | kfree(hidinput); |
| 997 | out_unwind: |
| 998 | /* unwind the ones we already registered */ |
| 999 | hidinput_disconnect(hid); |
| 1000 | |
| 1001 | return -1; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 1002 | } |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 1003 | EXPORT_SYMBOL_GPL(hidinput_connect); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 1004 | |
| 1005 | void hidinput_disconnect(struct hid_device *hid) |
| 1006 | { |
| 1007 | struct hid_input *hidinput, *next; |
| 1008 | |
| 1009 | list_for_each_entry_safe(hidinput, next, &hid->inputs, list) { |
| 1010 | list_del(&hidinput->list); |
| 1011 | input_unregister_device(hidinput->input); |
| 1012 | kfree(hidinput); |
| 1013 | } |
| 1014 | } |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 1015 | EXPORT_SYMBOL_GPL(hidinput_disconnect); |
| 1016 | |