Skip to content

Commit 13d02c6

Browse files
Binary-EaterJiri Kosina
authored andcommitted
HID: nvidia-shield: Add mappings for consumer HID USAGE buttons
Map Android Home, Back, Search, VolumeUp, VolumeDown, and PlayPause buttons to the appropriate input event codes. Signed-off-by: Rahul Rameshbabu <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 0930856 commit 13d02c6

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

drivers/hid/hid-nvidia-shield.c

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
#include "hid-ids.h"
1616

1717
#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+
};
1828

1929
enum {
2030
SHIELD_FW_VERSION_INITIALIZED = 0,
@@ -416,6 +426,40 @@ static struct shield_device *thunderstrike_create(struct hid_device *hdev)
416426
return shield_dev;
417427
}
418428

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+
419463
static ssize_t firmware_version_show(struct device *dev,
420464
struct device_attribute *attr, char *buf)
421465
{
@@ -571,11 +615,12 @@ static const struct hid_device_id shield_devices[] = {
571615
MODULE_DEVICE_TABLE(hid, shield_devices);
572616

573617
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,
579624
.driver = {
580625
.dev_groups = shield_device_groups,
581626
},

0 commit comments

Comments
 (0)