|
15 | 15 | #include "hid-ids.h"
|
16 | 16 |
|
17 | 17 | #define NOT_INIT_STR "NOT INITIALIZED"
|
| 18 | +#define android_map_key(c) hid_map_usage(hi, usage, bit, max, EV_KEY, (c)) |
| 19 | + |
| 20 | +enum { |
| 21 | + HID_USAGE_ANDROID_PLAYPAUSE_BTN = 0xcd, /* Double-tap volume slider */ |
| 22 | + HID_USAGE_ANDROID_VOLUMEUP_BTN = 0xe9, |
| 23 | + HID_USAGE_ANDROID_VOLUMEDOWN_BTN = 0xea, |
| 24 | + HID_USAGE_ANDROID_SEARCH_BTN = 0x221, /* NVIDIA btn on Thunderstrike */ |
| 25 | + HID_USAGE_ANDROID_HOME_BTN = 0x223, |
| 26 | + HID_USAGE_ANDROID_BACK_BTN = 0x224, |
| 27 | +}; |
18 | 28 |
|
19 | 29 | enum {
|
20 | 30 | SHIELD_FW_VERSION_INITIALIZED = 0,
|
@@ -416,6 +426,40 @@ static struct shield_device *thunderstrike_create(struct hid_device *hdev)
|
416 | 426 | return shield_dev;
|
417 | 427 | }
|
418 | 428 |
|
| 429 | +static int android_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 430 | + struct hid_field *field, |
| 431 | + struct hid_usage *usage, unsigned long **bit, |
| 432 | + int *max) |
| 433 | +{ |
| 434 | + if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER) |
| 435 | + return 0; |
| 436 | + |
| 437 | + switch (usage->hid & HID_USAGE) { |
| 438 | + case HID_USAGE_ANDROID_PLAYPAUSE_BTN: |
| 439 | + android_map_key(KEY_PLAYPAUSE); |
| 440 | + break; |
| 441 | + case HID_USAGE_ANDROID_VOLUMEUP_BTN: |
| 442 | + android_map_key(KEY_VOLUMEUP); |
| 443 | + break; |
| 444 | + case HID_USAGE_ANDROID_VOLUMEDOWN_BTN: |
| 445 | + android_map_key(KEY_VOLUMEDOWN); |
| 446 | + break; |
| 447 | + case HID_USAGE_ANDROID_SEARCH_BTN: |
| 448 | + android_map_key(BTN_Z); |
| 449 | + break; |
| 450 | + case HID_USAGE_ANDROID_HOME_BTN: |
| 451 | + android_map_key(BTN_MODE); |
| 452 | + break; |
| 453 | + case HID_USAGE_ANDROID_BACK_BTN: |
| 454 | + android_map_key(BTN_SELECT); |
| 455 | + break; |
| 456 | + default: |
| 457 | + return 0; |
| 458 | + } |
| 459 | + |
| 460 | + return 1; |
| 461 | +} |
| 462 | + |
419 | 463 | static ssize_t firmware_version_show(struct device *dev,
|
420 | 464 | struct device_attribute *attr, char *buf)
|
421 | 465 | {
|
@@ -571,11 +615,12 @@ static const struct hid_device_id shield_devices[] = {
|
571 | 615 | MODULE_DEVICE_TABLE(hid, shield_devices);
|
572 | 616 |
|
573 | 617 | static struct hid_driver shield_driver = {
|
574 |
| - .name = "shield", |
575 |
| - .id_table = shield_devices, |
576 |
| - .probe = shield_probe, |
577 |
| - .remove = shield_remove, |
578 |
| - .raw_event = shield_raw_event, |
| 618 | + .name = "shield", |
| 619 | + .id_table = shield_devices, |
| 620 | + .input_mapping = android_input_mapping, |
| 621 | + .probe = shield_probe, |
| 622 | + .remove = shield_remove, |
| 623 | + .raw_event = shield_raw_event, |
579 | 624 | .driver = {
|
580 | 625 | .dev_groups = shield_device_groups,
|
581 | 626 | },
|
|
0 commit comments