diff options
| -rw-r--r-- | drivers/hid/Kconfig | 16 | ||||
| -rw-r--r-- | drivers/hid/Makefile | 2 | ||||
| -rw-r--r-- | drivers/hid/hid-alps.c | 30 | ||||
| -rw-r--r-- | drivers/hid/hid-core.c | 21 | ||||
| -rw-r--r-- | drivers/hid/hid-generic.c | 15 | ||||
| -rw-r--r-- | drivers/hid/hid-gfrm.c | 2 | ||||
| -rw-r--r-- | drivers/hid/hid-ids.h | 5 | ||||
| -rw-r--r-- | drivers/hid/hid-input.c | 123 | ||||
| -rw-r--r-- | drivers/hid/hid-magicmouse.c | 6 | ||||
| -rw-r--r-- | drivers/hid/hid-multitouch.c | 232 | ||||
| -rw-r--r-- | drivers/hid/hid-plantronics.c | 6 | ||||
| -rw-r--r-- | drivers/hid/hid-quirks.c | 1 | ||||
| -rw-r--r-- | drivers/hid/hid-redragon.c | 86 | ||||
| -rw-r--r-- | drivers/hid/hid-rmi.c | 20 | ||||
| -rw-r--r-- | drivers/hid/hid-steam.c | 1115 | ||||
| -rw-r--r-- | drivers/hid/i2c-hid/i2c-hid.c | 33 | ||||
| -rw-r--r-- | drivers/hid/wacom_wac.c | 74 | ||||
| -rw-r--r-- | include/linux/hid.h | 19 |
18 files changed, 1621 insertions, 185 deletions
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 0000434a1fbd..a49a10437c40 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig | |||
| @@ -575,6 +575,13 @@ config HID_MAYFLASH | |||
| 575 | Say Y here if you have HJZ Mayflash PS3 game controller adapters | 575 | Say Y here if you have HJZ Mayflash PS3 game controller adapters |
| 576 | and want to enable force feedback support. | 576 | and want to enable force feedback support. |
| 577 | 577 | ||
| 578 | config HID_REDRAGON | ||
| 579 | tristate "Redragon keyboards" | ||
| 580 | depends on HID | ||
| 581 | default !EXPERT | ||
| 582 | ---help--- | ||
| 583 | Support for Redragon keyboards that need fix-ups to work properly. | ||
| 584 | |||
| 578 | config HID_MICROSOFT | 585 | config HID_MICROSOFT |
| 579 | tristate "Microsoft non-fully HID-compliant devices" | 586 | tristate "Microsoft non-fully HID-compliant devices" |
| 580 | depends on HID | 587 | depends on HID |
| @@ -838,6 +845,15 @@ config HID_SPEEDLINK | |||
| 838 | ---help--- | 845 | ---help--- |
| 839 | Support for Speedlink Vicious and Divine Cezanne mouse. | 846 | Support for Speedlink Vicious and Divine Cezanne mouse. |
| 840 | 847 | ||
| 848 | config HID_STEAM | ||
| 849 | tristate "Steam Controller support" | ||
| 850 | depends on HID | ||
| 851 | select POWER_SUPPLY | ||
| 852 | ---help--- | ||
| 853 | Say Y here if you have a Steam Controller if you want to use it | ||
| 854 | without running the Steam Client. It supports both the wired and | ||
| 855 | the wireless adaptor. | ||
| 856 | |||
| 841 | config HID_STEELSERIES | 857 | config HID_STEELSERIES |
| 842 | tristate "Steelseries SRW-S1 steering wheel support" | 858 | tristate "Steelseries SRW-S1 steering wheel support" |
| 843 | depends on HID | 859 | depends on HID |
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 17a8bd97da9d..511e1cbff768 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile | |||
| @@ -86,6 +86,7 @@ hid-picolcd-$(CONFIG_DEBUG_FS) += hid-picolcd_debugfs.o | |||
| 86 | 86 | ||
| 87 | obj-$(CONFIG_HID_PLANTRONICS) += hid-plantronics.o | 87 | obj-$(CONFIG_HID_PLANTRONICS) += hid-plantronics.o |
| 88 | obj-$(CONFIG_HID_PRIMAX) += hid-primax.o | 88 | obj-$(CONFIG_HID_PRIMAX) += hid-primax.o |
| 89 | obj-$(CONFIG_HID_REDRAGON) += hid-redragon.o | ||
| 89 | obj-$(CONFIG_HID_RETRODE) += hid-retrode.o | 90 | obj-$(CONFIG_HID_RETRODE) += hid-retrode.o |
| 90 | obj-$(CONFIG_HID_ROCCAT) += hid-roccat.o hid-roccat-common.o \ | 91 | obj-$(CONFIG_HID_ROCCAT) += hid-roccat.o hid-roccat-common.o \ |
| 91 | hid-roccat-arvo.o hid-roccat-isku.o hid-roccat-kone.o \ | 92 | hid-roccat-arvo.o hid-roccat-isku.o hid-roccat-kone.o \ |
| @@ -97,6 +98,7 @@ obj-$(CONFIG_HID_SAMSUNG) += hid-samsung.o | |||
| 97 | obj-$(CONFIG_HID_SMARTJOYPLUS) += hid-sjoy.o | 98 | obj-$(CONFIG_HID_SMARTJOYPLUS) += hid-sjoy.o |
| 98 | obj-$(CONFIG_HID_SONY) += hid-sony.o | 99 | obj-$(CONFIG_HID_SONY) += hid-sony.o |
| 99 | obj-$(CONFIG_HID_SPEEDLINK) += hid-speedlink.o | 100 | obj-$(CONFIG_HID_SPEEDLINK) += hid-speedlink.o |
| 101 | obj-$(CONFIG_HID_STEAM) += hid-steam.o | ||
| 100 | obj-$(CONFIG_HID_STEELSERIES) += hid-steelseries.o | 102 | obj-$(CONFIG_HID_STEELSERIES) += hid-steelseries.o |
| 101 | obj-$(CONFIG_HID_SUNPLUS) += hid-sunplus.o | 103 | obj-$(CONFIG_HID_SUNPLUS) += hid-sunplus.o |
| 102 | obj-$(CONFIG_HID_GREENASIA) += hid-gaff.o | 104 | obj-$(CONFIG_HID_GREENASIA) += hid-gaff.o |
diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c index b1eeb4839bfc..aec253b44156 100644 --- a/drivers/hid/hid-alps.c +++ b/drivers/hid/hid-alps.c | |||
| @@ -171,7 +171,7 @@ static int t4_read_write_register(struct hid_device *hdev, u32 address, | |||
| 171 | int ret; | 171 | int ret; |
| 172 | u16 check_sum; | 172 | u16 check_sum; |
| 173 | u8 *input; | 173 | u8 *input; |
| 174 | u8 *readbuf; | 174 | u8 *readbuf = NULL; |
| 175 | 175 | ||
| 176 | input = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL); | 176 | input = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL); |
| 177 | if (!input) | 177 | if (!input) |
| @@ -204,8 +204,8 @@ static int t4_read_write_register(struct hid_device *hdev, u32 address, | |||
| 204 | goto exit; | 204 | goto exit; |
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | readbuf = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL); | ||
| 208 | if (read_flag) { | 207 | if (read_flag) { |
| 208 | readbuf = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL); | ||
| 209 | if (!readbuf) { | 209 | if (!readbuf) { |
| 210 | ret = -ENOMEM; | 210 | ret = -ENOMEM; |
| 211 | goto exit; | 211 | goto exit; |
| @@ -219,22 +219,24 @@ static int t4_read_write_register(struct hid_device *hdev, u32 address, | |||
| 219 | goto exit_readbuf; | 219 | goto exit_readbuf; |
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | ret = -EINVAL; | ||
| 223 | |||
| 222 | if (*(u32 *)&readbuf[6] != address) { | 224 | if (*(u32 *)&readbuf[6] != address) { |
| 223 | dev_err(&hdev->dev, "read register address error (%x,%x)\n", | 225 | dev_err(&hdev->dev, "read register address error (%x,%x)\n", |
| 224 | *(u32 *)&readbuf[6], address); | 226 | *(u32 *)&readbuf[6], address); |
| 225 | goto exit_readbuf; | 227 | goto exit_readbuf; |
| 226 | } | 228 | } |
| 227 | 229 | ||
| 228 | if (*(u16 *)&readbuf[10] != 1) { | 230 | if (*(u16 *)&readbuf[10] != 1) { |
| 229 | dev_err(&hdev->dev, "read register size error (%x)\n", | 231 | dev_err(&hdev->dev, "read register size error (%x)\n", |
| 230 | *(u16 *)&readbuf[10]); | 232 | *(u16 *)&readbuf[10]); |
| 231 | goto exit_readbuf; | 233 | goto exit_readbuf; |
| 232 | } | 234 | } |
| 233 | 235 | ||
| 234 | check_sum = t4_calc_check_sum(readbuf, 6, 7); | 236 | check_sum = t4_calc_check_sum(readbuf, 6, 7); |
| 235 | if (*(u16 *)&readbuf[13] != check_sum) { | 237 | if (*(u16 *)&readbuf[13] != check_sum) { |
| 236 | dev_err(&hdev->dev, "read register checksum error (%x,%x)\n", | 238 | dev_err(&hdev->dev, "read register checksum error (%x,%x)\n", |
| 237 | *(u16 *)&readbuf[13], check_sum); | 239 | *(u16 *)&readbuf[13], check_sum); |
| 238 | goto exit_readbuf; | 240 | goto exit_readbuf; |
| 239 | } | 241 | } |
| 240 | 242 | ||
| @@ -458,17 +460,35 @@ static int __maybe_unused alps_post_reset(struct hid_device *hdev) | |||
| 458 | case T4: | 460 | case T4: |
| 459 | ret = t4_read_write_register(hdev, T4_PRM_FEED_CONFIG_1, | 461 | ret = t4_read_write_register(hdev, T4_PRM_FEED_CONFIG_1, |
| 460 | NULL, T4_I2C_ABS, false); | 462 | NULL, T4_I2C_ABS, false); |
| 463 | if (ret < 0) { | ||
| 464 | dev_err(&hdev->dev, "failed T4_PRM_FEED_CONFIG_1 (%d)\n", | ||
| 465 | ret); | ||
| 466 | goto exit; | ||
| 467 | } | ||
| 468 | |||
| 461 | ret = t4_read_write_register(hdev, T4_PRM_FEED_CONFIG_4, | 469 | ret = t4_read_write_register(hdev, T4_PRM_FEED_CONFIG_4, |
| 462 | NULL, T4_FEEDCFG4_ADVANCED_ABS_ENABLE, false); | 470 | NULL, T4_FEEDCFG4_ADVANCED_ABS_ENABLE, false); |
| 471 | if (ret < 0) { | ||
| 472 | dev_err(&hdev->dev, "failed T4_PRM_FEED_CONFIG_4 (%d)\n", | ||
| 473 | ret); | ||
| 474 | goto exit; | ||
| 475 | } | ||
| 463 | break; | 476 | break; |
| 464 | case U1: | 477 | case U1: |
| 465 | ret = u1_read_write_register(hdev, | 478 | ret = u1_read_write_register(hdev, |
| 466 | ADDRESS_U1_DEV_CTRL_1, NULL, | 479 | ADDRESS_U1_DEV_CTRL_1, NULL, |
| 467 | U1_TP_ABS_MODE | U1_SP_ABS_MODE, false); | 480 | U1_TP_ABS_MODE | U1_SP_ABS_MODE, false); |
| 481 | if (ret < 0) { | ||
| 482 | dev_err(&hdev->dev, "failed to change TP mode (%d)\n", | ||
| 483 | ret); | ||
| 484 | goto exit; | ||
| 485 | } | ||
| 468 | break; | 486 | break; |
| 469 | default: | 487 | default: |
| 470 | break; | 488 | break; |
| 471 | } | 489 | } |
| 490 | |||
| 491 | exit: | ||
| 472 | return ret; | 492 | return ret; |
| 473 | } | 493 | } |
| 474 | 494 | ||
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 5d7cc6bbbac6..355dc7e49562 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c | |||
| @@ -57,7 +57,9 @@ MODULE_PARM_DESC(ignore_special_drivers, "Ignore any special drivers and handle | |||
| 57 | * Register a new report for a device. | 57 | * Register a new report for a device. |
| 58 | */ | 58 | */ |
| 59 | 59 | ||
| 60 | struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id) | 60 | struct hid_report *hid_register_report(struct hid_device *device, |
| 61 | unsigned int type, unsigned int id, | ||
| 62 | unsigned int application) | ||
| 61 | { | 63 | { |
| 62 | struct hid_report_enum *report_enum = device->report_enum + type; | 64 | struct hid_report_enum *report_enum = device->report_enum + type; |
| 63 | struct hid_report *report; | 65 | struct hid_report *report; |
| @@ -78,6 +80,7 @@ struct hid_report *hid_register_report(struct hid_device *device, unsigned type, | |||
| 78 | report->type = type; | 80 | report->type = type; |
| 79 | report->size = 0; | 81 | report->size = 0; |
| 80 | report->device = device; | 82 | report->device = device; |
| 83 | report->application = application; | ||
| 81 | report_enum->report_id_hash[id] = report; | 84 | report_enum->report_id_hash[id] = report; |
| 82 | 85 | ||
| 83 | list_add_tail(&report->list, &report_enum->report_list); | 86 | list_add_tail(&report->list, &report_enum->report_list); |
| @@ -221,11 +224,15 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign | |||
| 221 | { | 224 | { |
| 222 | struct hid_report *report; | 225 | struct hid_report *report; |
| 223 | struct hid_field *field; | 226 | struct hid_field *field; |
| 224 | unsigned usages; | 227 | unsigned int usages; |
| 225 | unsigned offset; | 228 | unsigned int offset; |
| 226 | unsigned i; | 229 | unsigned int i; |
| 230 | unsigned int application; | ||
| 231 | |||
| 232 | application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION); | ||
| 227 | 233 | ||
| 228 | report = hid_register_report(parser->device, report_type, parser->global.report_id); | 234 | report = hid_register_report(parser->device, report_type, |
| 235 | parser->global.report_id, application); | ||
| 229 | if (!report) { | 236 | if (!report) { |
| 230 | hid_err(parser->device, "hid_register_report failed\n"); | 237 | hid_err(parser->device, "hid_register_report failed\n"); |
| 231 | return -1; | 238 | return -1; |
| @@ -259,7 +266,7 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign | |||
| 259 | 266 | ||
| 260 | field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL); | 267 | field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL); |
| 261 | field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL); | 268 | field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL); |
| 262 | field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION); | 269 | field->application = application; |
| 263 | 270 | ||
| 264 | for (i = 0; i < usages; i++) { | 271 | for (i = 0; i < usages; i++) { |
| 265 | unsigned j = i; | 272 | unsigned j = i; |
| @@ -1798,7 +1805,7 @@ EXPORT_SYMBOL_GPL(hid_hw_stop); | |||
| 1798 | * | 1805 | * |
| 1799 | * Tell underlying HW to start delivering events from the device. | 1806 | * Tell underlying HW to start delivering events from the device. |
| 1800 | * This function should be called sometime after successful call | 1807 | * This function should be called sometime after successful call |
| 1801 | * to hid_hiw_start(). | 1808 | * to hid_hw_start(). |
| 1802 | */ | 1809 | */ |
| 1803 | int hid_hw_open(struct hid_device *hdev) | 1810 | int hid_hw_open(struct hid_device *hdev) |
| 1804 | { | 1811 | { |
diff --git a/drivers/hid/hid-generic.c b/drivers/hid/hid-generic.c index c25b4718de44..3b6eccbc2519 100644 --- a/drivers/hid/hid-generic.c +++ b/drivers/hid/hid-generic.c | |||
| @@ -56,6 +56,20 @@ static bool hid_generic_match(struct hid_device *hdev, | |||
| 56 | return true; | 56 | return true; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | static int hid_generic_probe(struct hid_device *hdev, | ||
| 60 | const struct hid_device_id *id) | ||
| 61 | { | ||
| 62 | int ret; | ||
| 63 | |||
| 64 | hdev->quirks |= HID_QUIRK_INPUT_PER_APP; | ||
| 65 | |||
| 66 | ret = hid_parse(hdev); | ||
| 67 | if (ret) | ||
| 68 | return ret; | ||
| 69 | |||
| 70 | return hid_hw_start(hdev, HID_CONNECT_DEFAULT); | ||
| 71 | } | ||
| 72 | |||
| 59 | static const struct hid_device_id hid_table[] = { | 73 | static const struct hid_device_id hid_table[] = { |
| 60 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, HID_ANY_ID, HID_ANY_ID) }, | 74 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, HID_ANY_ID, HID_ANY_ID) }, |
| 61 | { } | 75 | { } |
| @@ -66,6 +80,7 @@ static struct hid_driver hid_generic = { | |||
| 66 | .name = "hid-generic", | 80 | .name = "hid-generic", |
| 67 | .id_table = hid_table, | 81 | .id_table = hid_table, |
| 68 | .match = hid_generic_match, | 82 | .match = hid_generic_match, |
| 83 | .probe = hid_generic_probe, | ||
| 69 | }; | 84 | }; |
| 70 | module_hid_driver(hid_generic); | 85 | module_hid_driver(hid_generic); |
| 71 | 86 | ||
diff --git a/drivers/hid/hid-gfrm.c b/drivers/hid/hid-gfrm.c index 075b1c020846..cf477f8c8f4c 100644 --- a/drivers/hid/hid-gfrm.c +++ b/drivers/hid/hid-gfrm.c | |||
| @@ -116,7 +116,7 @@ static int gfrm_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 116 | * those reports reach gfrm_raw_event() from hid_input_report(). | 116 | * those reports reach gfrm_raw_event() from hid_input_report(). |
| 117 | */ | 117 | */ |
| 118 | if (!hid_register_report(hdev, HID_INPUT_REPORT, | 118 | if (!hid_register_report(hdev, HID_INPUT_REPORT, |
| 119 | GFRM100_SEARCH_KEY_REPORT_ID)) { | 119 | GFRM100_SEARCH_KEY_REPORT_ID, 0)) { |
| 120 | ret = -ENOMEM; | 120 | ret = -ENOMEM; |
| 121 | goto done; | 121 | goto done; |
| 122 | } | 122 | } |
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index 46f5ecd11bf7..a85634fe033f 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h | |||
| @@ -615,6 +615,7 @@ | |||
| 615 | #define USB_VENDOR_ID_JESS 0x0c45 | 615 | #define USB_VENDOR_ID_JESS 0x0c45 |
| 616 | #define USB_DEVICE_ID_JESS_YUREX 0x1010 | 616 | #define USB_DEVICE_ID_JESS_YUREX 0x1010 |
| 617 | #define USB_DEVICE_ID_ASUS_MD_5112 0x5112 | 617 | #define USB_DEVICE_ID_ASUS_MD_5112 0x5112 |
| 618 | #define USB_DEVICE_ID_REDRAGON_ASURA 0x760b | ||
| 618 | 619 | ||
| 619 | #define USB_VENDOR_ID_JESS2 0x0f30 | 620 | #define USB_VENDOR_ID_JESS2 0x0f30 |
| 620 | #define USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD 0x0111 | 621 | #define USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD 0x0111 |
| @@ -1012,6 +1013,10 @@ | |||
| 1012 | #define USB_VENDOR_ID_STANTUM_SITRONIX 0x1403 | 1013 | #define USB_VENDOR_ID_STANTUM_SITRONIX 0x1403 |
| 1013 | #define USB_DEVICE_ID_MTP_SITRONIX 0x5001 | 1014 | #define USB_DEVICE_ID_MTP_SITRONIX 0x5001 |
| 1014 | 1015 | ||
| 1016 | #define USB_VENDOR_ID_VALVE 0x28de | ||
| 1017 | #define USB_DEVICE_ID_STEAM_CONTROLLER 0x1102 | ||
| 1018 | #define USB_DEVICE_ID_STEAM_CONTROLLER_WIRELESS 0x1142 | ||
| 1019 | |||
| 1015 | #define USB_VENDOR_ID_STEELSERIES 0x1038 | 1020 | #define USB_VENDOR_ID_STEELSERIES 0x1038 |
| 1016 | #define USB_DEVICE_ID_STEELSERIES_SRWS1 0x1410 | 1021 | #define USB_DEVICE_ID_STEELSERIES_SRWS1 0x1410 |
| 1017 | 1022 | ||
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 930652c25120..ab93dd5927c3 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c | |||
| @@ -1110,8 +1110,31 @@ mapped: | |||
| 1110 | 1110 | ||
| 1111 | set_bit(usage->type, input->evbit); | 1111 | set_bit(usage->type, input->evbit); |
| 1112 | 1112 | ||
| 1113 | while (usage->code <= max && test_and_set_bit(usage->code, bit)) | 1113 | /* |
| 1114 | usage->code = find_next_zero_bit(bit, max + 1, usage->code); | 1114 | * This part is *really* controversial: |
| 1115 | * - HID aims at being generic so we should do our best to export | ||
| 1116 | * all incoming events | ||
| 1117 | * - HID describes what events are, so there is no reason for ABS_X | ||
| 1118 | * to be mapped to ABS_Y | ||
| 1119 | * - HID is using *_MISC+N as a default value, but nothing prevents | ||
| 1120 | * *_MISC+N to overwrite a legitimate even, which confuses userspace | ||
| 1121 | * (for instance ABS_MISC + 7 is ABS_MT_SLOT, which has a different | ||
| 1122 | * processing) | ||
| 1123 | * | ||
| 1124 | * If devices still want to use this (at their own risk), they will | ||
| 1125 | * have to use the quirk HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE, but | ||
| 1126 | * the default should be a reliable mapping. | ||
| 1127 | */ | ||
| 1128 | while (usage->code <= max && test_and_set_bit(usage->code, bit)) { | ||
| 1129 | if (device->quirks & HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE) { | ||
| 1130 | usage->code = find_next_zero_bit(bit, | ||
| 1131 | max + 1, | ||
| 1132 | usage->code); | ||
| 1133 | } else { | ||
| 1134 | device->status |= HID_STAT_DUP_DETECTED; | ||
| 1135 | goto ignore; | ||
| 1136 | } | ||
| 1137 | } | ||
| 1115 | 1138 | ||
| 1116 | if (usage->code > max) | 1139 | if (usage->code > max) |
| 1117 | goto ignore; | 1140 | goto ignore; |
| @@ -1487,15 +1510,56 @@ static void report_features(struct hid_device *hid) | |||
| 1487 | } | 1510 | } |
| 1488 | } | 1511 | } |
| 1489 | 1512 | ||
| 1490 | static struct hid_input *hidinput_allocate(struct hid_device *hid) | 1513 | static struct hid_input *hidinput_allocate(struct hid_device *hid, |
| 1514 | unsigned int application) | ||
| 1491 | { | 1515 | { |
| 1492 | struct hid_input *hidinput = kzalloc(sizeof(*hidinput), GFP_KERNEL); | 1516 | struct hid_input *hidinput = kzalloc(sizeof(*hidinput), GFP_KERNEL); |
| 1493 | struct input_dev *input_dev = input_allocate_device(); | 1517 | struct input_dev *input_dev = input_allocate_device(); |
| 1494 | if (!hidinput || !input_dev) { | 1518 | const char *suffix = NULL; |
| 1495 | kfree(hidinput); | 1519 | |
| 1496 | input_free_device(input_dev); | 1520 | if (!hidinput || !input_dev) |
| 1497 | hid_err(hid, "Out of memory during hid input probe\n"); | 1521 | goto fail; |
| 1498 | return NULL; | 1522 | |
| 1523 | if ((hid->quirks & HID_QUIRK_INPUT_PER_APP) && | ||
| 1524 | hid->maxapplication > 1) { | ||
| 1525 | switch (application) { | ||
| 1526 | case HID_GD_KEYBOARD: | ||
| 1527 | suffix = "Keyboard"; | ||
| 1528 | break; | ||
| 1529 | case HID_GD_KEYPAD: | ||
| 1530 | suffix = "Keypad"; | ||
| 1531 | break; | ||
| 1532 | case HID_GD_MOUSE: | ||
| 1533 | suffix = "Mouse"; | ||
| 1534 | break; | ||
| 1535 | case HID_DG_STYLUS: | ||
| 1536 | suffix = "Pen"; | ||
| 1537 | break; | ||
| 1538 | case HID_DG_TOUCHSCREEN: | ||
| 1539 | suffix = "Touchscreen"; | ||
| 1540 | break; | ||
| 1541 | case HID_DG_TOUCHPAD: | ||
| 1542 | suffix = "Touchpad"; | ||
| 1543 | break; | ||
| 1544 | case HID_GD_SYSTEM_CONTROL: | ||
| 1545 | suffix = "System Control"; | ||
| 1546 | break; | ||
| 1547 | case HID_CP_CONSUMER_CONTROL: | ||
| 1548 | suffix = "Consumer Control"; | ||
| 1549 | break; | ||
| 1550 | case HID_GD_WIRELESS_RADIO_CTLS: | ||
| 1551 | suffix = "Wireless Radio Control"; | ||
| 1552 | break; | ||
| 1553 | default: | ||
| 1554 | break; | ||
| 1555 | } | ||
| 1556 | } | ||
| 1557 | |||
| 1558 | if (suffix) { | ||
| 1559 | hidinput->name = kasprintf(GFP_KERNEL, "%s %s", | ||
| 1560 | hid->name, suffix); | ||
| 1561 | if (!hidinput->name) | ||
| 1562 | goto fail; | ||
| 1499 | } | 1563 | } |
| 1500 | 1564 | ||
| 1501 | input_set_drvdata(input_dev, hid); | 1565 | input_set_drvdata(input_dev, hid); |
| @@ -1505,7 +1569,7 @@ static struct hid_input *hidinput_allocate(struct hid_device *hid) | |||
| 1505 | input_dev->setkeycode = hidinput_setkeycode; | 1569 | input_dev->setkeycode = hidinput_setkeycode; |
| 1506 | input_dev->getkeycode = hidinput_getkeycode; | 1570 | input_dev->getkeycode = hidinput_getkeycode; |
| 1507 | 1571 | ||
| 1508 | input_dev->name = hid->name; | 1572 | input_dev->name = hidinput->name ? hidinput->name : hid->name; |
| 1509 | input_dev->phys = hid->phys; | 1573 | input_dev->phys = hid->phys; |
| 1510 | input_dev->uniq = hid->uniq; | 1574 | input_dev->uniq = hid->uniq; |
| 1511 | input_dev->id.bustype = hid->bus; | 1575 | input_dev->id.bustype = hid->bus; |
| @@ -1513,10 +1577,19 @@ static struct hid_input *hidinput_allocate(struct hid_device *hid) | |||
| 1513 | input_dev->id.product = hid->product; | 1577 | input_dev->id.product = hid->product; |
| 1514 | input_dev->id.version = hid->version; | 1578 | input_dev->id.version = hid->version; |
| 1515 | input_dev->dev.parent = &hid->dev; | 1579 | input_dev->dev.parent = &hid->dev; |
| 1580 | |||
| 1516 | hidinput->input = input_dev; | 1581 | hidinput->input = input_dev; |
| 1517 | list_add_tail(&hidinput->list, &hid->inputs); | 1582 | list_add_tail(&hidinput->list, &hid->inputs); |
| 1518 | 1583 | ||
| 1584 | INIT_LIST_HEAD(&hidinput->reports); | ||
| 1585 | |||
| 1519 | return hidinput; | 1586 | return hidinput; |
| 1587 | |||
| 1588 | fail: | ||
| 1589 | kfree(hidinput); | ||
| 1590 | input_free_device(input_dev); | ||
| 1591 | hid_err(hid, "Out of memory during hid input probe\n"); | ||
| 1592 | return NULL; | ||
| 1520 | } | 1593 | } |
| 1521 | 1594 | ||
| 1522 | static bool hidinput_has_been_populated(struct hid_input *hidinput) | 1595 | static bool hidinput_has_been_populated(struct hid_input *hidinput) |
| @@ -1562,6 +1635,7 @@ static void hidinput_cleanup_hidinput(struct hid_device *hid, | |||
| 1562 | 1635 | ||
| 1563 | list_del(&hidinput->list); | 1636 | list_del(&hidinput->list); |
| 1564 | input_free_device(hidinput->input); | 1637 | input_free_device(hidinput->input); |
| 1638 | kfree(hidinput->name); | ||
| 1565 | 1639 | ||
| 1566 | for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) { | 1640 | for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) { |
| 1567 | if (k == HID_OUTPUT_REPORT && | 1641 | if (k == HID_OUTPUT_REPORT && |
| @@ -1594,6 +1668,20 @@ static struct hid_input *hidinput_match(struct hid_report *report) | |||
| 1594 | return NULL; | 1668 | return NULL; |
| 1595 | } | 1669 | } |
| 1596 | 1670 | ||
| 1671 | static struct hid_input *hidinput_match_application(struct hid_report *report) | ||
| 1672 | { | ||
| 1673 | struct hid_device *hid = report->device; | ||
| 1674 | struct hid_input *hidinput; | ||
| 1675 | |||
| 1676 | list_for_each_entry(hidinput, &hid->inputs, list) { | ||
| 1677 | if (hidinput->report && | ||
| 1678 | hidinput->report->application == report->application) | ||
| 1679 | return hidinput; | ||
| 1680 | } | ||
| 1681 | |||
| 1682 | return NULL; | ||
| 1683 | } | ||
| 1684 | |||
| 1597 | static inline void hidinput_configure_usages(struct hid_input *hidinput, | 1685 | static inline void hidinput_configure_usages(struct hid_input *hidinput, |
| 1598 | struct hid_report *report) | 1686 | struct hid_report *report) |
| 1599 | { | 1687 | { |
| @@ -1616,11 +1704,14 @@ int hidinput_connect(struct hid_device *hid, unsigned int force) | |||
| 1616 | struct hid_driver *drv = hid->driver; | 1704 | struct hid_driver *drv = hid->driver; |
| 1617 | struct hid_report *report; | 1705 | struct hid_report *report; |
| 1618 | struct hid_input *next, *hidinput = NULL; | 1706 | struct hid_input *next, *hidinput = NULL; |
| 1707 | unsigned int application; | ||
| 1619 | int i, k; | 1708 | int i, k; |
| 1620 | 1709 | ||
| 1621 | INIT_LIST_HEAD(&hid->inputs); | 1710 | INIT_LIST_HEAD(&hid->inputs); |
| 1622 | INIT_WORK(&hid->led_work, hidinput_led_worker); | 1711 | INIT_WORK(&hid->led_work, hidinput_led_worker); |
| 1623 | 1712 | ||
| 1713 | hid->status &= ~HID_STAT_DUP_DETECTED; | ||
| 1714 | |||
| 1624 | if (!force) { | 1715 | if (!force) { |
| 1625 | for (i = 0; i < hid->maxcollection; i++) { | 1716 | for (i = 0; i < hid->maxcollection; i++) { |
| 1626 | struct hid_collection *col = &hid->collection[i]; | 1717 | struct hid_collection *col = &hid->collection[i]; |
| @@ -1646,15 +1737,20 @@ int hidinput_connect(struct hid_device *hid, unsigned int force) | |||
| 1646 | if (!report->maxfield) | 1737 | if (!report->maxfield) |
| 1647 | continue; | 1738 | continue; |
| 1648 | 1739 | ||
| 1740 | application = report->application; | ||
| 1741 | |||
| 1649 | /* | 1742 | /* |
| 1650 | * Find the previous hidinput report attached | 1743 | * Find the previous hidinput report attached |
| 1651 | * to this report id. | 1744 | * to this report id. |
| 1652 | */ | 1745 | */ |
| 1653 | if (hid->quirks & HID_QUIRK_MULTI_INPUT) | 1746 | if (hid->quirks & HID_QUIRK_MULTI_INPUT) |
| 1654 | hidinput = hidinput_match(report); | 1747 | hidinput = hidinput_match(report); |
| 1748 | else if (hid->maxapplication > 1 && | ||
| 1749 | (hid->quirks & HID_QUIRK_INPUT_PER_APP)) | ||
| 1750 | hidinput = hidinput_match_application(report); | ||
| 1655 | 1751 | ||
| 1656 | if (!hidinput) { | 1752 | if (!hidinput) { |
| 1657 | hidinput = hidinput_allocate(hid); | 1753 | hidinput = hidinput_allocate(hid, application); |
| 1658 | if (!hidinput) | 1754 | if (!hidinput) |
| 1659 | goto out_unwind; | 1755 | goto out_unwind; |
| 1660 | } | 1756 | } |
| @@ -1663,6 +1759,9 @@ int hidinput_connect(struct hid_device *hid, unsigned int force) | |||
| 1663 | 1759 | ||
| 1664 | if (hid->quirks & HID_QUIRK_MULTI_INPUT) | 1760 | if (hid->quirks & HID_QUIRK_MULTI_INPUT) |
| 1665 | hidinput->report = report; | 1761 | hidinput->report = report; |
| 1762 | |||
| 1763 | list_add_tail(&report->hidinput_list, | ||
| 1764 | &hidinput->reports); | ||
| 1666 | } | 1765 | } |
| 1667 | } | 1766 | } |
| 1668 | 1767 | ||
| @@ -1687,6 +1786,10 @@ int hidinput_connect(struct hid_device *hid, unsigned int force) | |||
| 1687 | goto out_unwind; | 1786 | goto out_unwind; |
| 1688 | } | 1787 | } |
| 1689 | 1788 | ||
| 1789 | if (hid->status & HID_STAT_DUP_DETECTED) | ||
| 1790 | hid_dbg(hid, | ||
| 1791 | "Some usages could not be mapped, please use HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE if this is legitimate.\n"); | ||
| 1792 | |||
| 1690 | return 0; | 1793 | return 0; |
| 1691 | 1794 | ||
| 1692 | out_unwind: | 1795 | out_unwind: |
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c index 42ed887ba0be..b454c4386157 100644 --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c | |||
| @@ -531,12 +531,12 @@ static int magicmouse_probe(struct hid_device *hdev, | |||
| 531 | 531 | ||
| 532 | if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE) | 532 | if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE) |
| 533 | report = hid_register_report(hdev, HID_INPUT_REPORT, | 533 | report = hid_register_report(hdev, HID_INPUT_REPORT, |
| 534 | MOUSE_REPORT_ID); | 534 | MOUSE_REPORT_ID, 0); |
| 535 | else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */ | 535 | else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */ |
| 536 | report = hid_register_report(hdev, HID_INPUT_REPORT, | 536 | report = hid_register_report(hdev, HID_INPUT_REPORT, |
| 537 | TRACKPAD_REPORT_ID); | 537 | TRACKPAD_REPORT_ID, 0); |
| 538 | report = hid_register_report(hdev, HID_INPUT_REPORT, | 538 | report = hid_register_report(hdev, HID_INPUT_REPORT, |
| 539 | DOUBLE_REPORT_ID); | 539 | DOUBLE_REPORT_ID, 0); |
| 540 | } | 540 | } |
| 541 | 541 | ||
| 542 | if (!report) { | 542 | if (!report) { |
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index dad2fbb0e3f8..45968f7970f8 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c | |||
| @@ -81,6 +81,11 @@ MODULE_LICENSE("GPL"); | |||
| 81 | 81 | ||
| 82 | #define MT_BUTTONTYPE_CLICKPAD 0 | 82 | #define MT_BUTTONTYPE_CLICKPAD 0 |
| 83 | 83 | ||
| 84 | enum latency_mode { | ||
| 85 | HID_LATENCY_NORMAL = 0, | ||
| 86 | HID_LATENCY_HIGH = 1, | ||
| 87 | }; | ||
| 88 | |||
| 84 | #define MT_IO_FLAGS_RUNNING 0 | 89 | #define MT_IO_FLAGS_RUNNING 0 |
| 85 | #define MT_IO_FLAGS_ACTIVE_SLOTS 1 | 90 | #define MT_IO_FLAGS_ACTIVE_SLOTS 1 |
| 86 | #define MT_IO_FLAGS_PENDING_SLOTS 2 | 91 | #define MT_IO_FLAGS_PENDING_SLOTS 2 |
| @@ -127,11 +132,7 @@ struct mt_device { | |||
| 127 | int left_button_state; /* left button state */ | 132 | int left_button_state; /* left button state */ |
| 128 | unsigned last_slot_field; /* the last field of a slot */ | 133 | unsigned last_slot_field; /* the last field of a slot */ |
| 129 | unsigned mt_report_id; /* the report ID of the multitouch device */ | 134 | unsigned mt_report_id; /* the report ID of the multitouch device */ |
| 130 | __s16 inputmode; /* InputMode HID feature, -1 if non-existent */ | 135 | __u8 inputmode_value; /* InputMode HID feature value */ |
| 131 | __s16 inputmode_index; /* InputMode HID feature index in the report */ | ||
| 132 | __s16 maxcontact_report_id; /* Maximum Contact Number HID feature, | ||
| 133 | -1 if non-existent */ | ||
| 134 | __u8 inputmode_value; /* InputMode HID feature value */ | ||
| 135 | __u8 num_received; /* how many contacts we received */ | 136 | __u8 num_received; /* how many contacts we received */ |
| 136 | __u8 num_expected; /* expected last contact index */ | 137 | __u8 num_expected; /* expected last contact index */ |
| 137 | __u8 maxcontacts; | 138 | __u8 maxcontacts; |
| @@ -415,32 +416,9 @@ static void mt_feature_mapping(struct hid_device *hdev, | |||
| 415 | struct mt_device *td = hid_get_drvdata(hdev); | 416 | struct mt_device *td = hid_get_drvdata(hdev); |
| 416 | 417 | ||
| 417 | switch (usage->hid) { | 418 | switch (usage->hid) { |
| 418 | case HID_DG_INPUTMODE: | ||
| 419 | /* Ignore if value index is out of bounds. */ | ||
| 420 | if (usage->usage_index >= field->report_count) { | ||
| 421 | dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n"); | ||
| 422 | break; | ||
| 423 | } | ||
| 424 | |||
| 425 | if (td->inputmode < 0) { | ||
| 426 | td->inputmode = field->report->id; | ||
| 427 | td->inputmode_index = usage->usage_index; | ||
| 428 | } else { | ||
| 429 | /* | ||
| 430 | * Some elan panels wrongly declare 2 input mode | ||
| 431 | * features, and silently ignore when we set the | ||
| 432 | * value in the second field. Skip the second feature | ||
| 433 | * and hope for the best. | ||
| 434 | */ | ||
| 435 | dev_info(&hdev->dev, | ||
| 436 | "Ignoring the extra HID_DG_INPUTMODE\n"); | ||
| 437 | } | ||
| 438 | |||
| 439 | break; | ||
| 440 | case HID_DG_CONTACTMAX: | 419 | case HID_DG_CONTACTMAX: |
| 441 | mt_get_feature(hdev, field->report); | 420 | mt_get_feature(hdev, field->report); |
| 442 | 421 | ||
| 443 | td->maxcontact_report_id = field->report->id; | ||
| 444 | td->maxcontacts = field->value[0]; | 422 | td->maxcontacts = field->value[0]; |
| 445 | if (!td->maxcontacts && | 423 | if (!td->maxcontacts && |
| 446 | field->logical_maximum <= MT_MAX_MAXCONTACT) | 424 | field->logical_maximum <= MT_MAX_MAXCONTACT) |
| @@ -620,13 +598,16 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 620 | hid_map_usage(hi, usage, bit, max, | 598 | hid_map_usage(hi, usage, bit, max, |
| 621 | EV_MSC, MSC_TIMESTAMP); | 599 | EV_MSC, MSC_TIMESTAMP); |
| 622 | input_set_capability(hi->input, EV_MSC, MSC_TIMESTAMP); | 600 | input_set_capability(hi->input, EV_MSC, MSC_TIMESTAMP); |
| 623 | mt_store_field(usage, td, hi); | ||
| 624 | /* Ignore if indexes are out of bounds. */ | 601 | /* Ignore if indexes are out of bounds. */ |
| 625 | if (field->index >= field->report->maxfield || | 602 | if (field->index >= field->report->maxfield || |
| 626 | usage->usage_index >= field->report_count) | 603 | usage->usage_index >= field->report_count) |
| 627 | return 1; | 604 | return 1; |
| 628 | td->scantime_index = field->index; | 605 | td->scantime_index = field->index; |
| 629 | td->scantime_val_index = usage->usage_index; | 606 | td->scantime_val_index = usage->usage_index; |
| 607 | /* | ||
| 608 | * We don't set td->last_slot_field as scan time is | ||
| 609 | * global to the report. | ||
| 610 | */ | ||
| 630 | return 1; | 611 | return 1; |
| 631 | case HID_DG_CONTACTCOUNT: | 612 | case HID_DG_CONTACTCOUNT: |
| 632 | /* Ignore if indexes are out of bounds. */ | 613 | /* Ignore if indexes are out of bounds. */ |
| @@ -1181,61 +1162,100 @@ static void mt_report(struct hid_device *hid, struct hid_report *report) | |||
| 1181 | input_sync(field->hidinput->input); | 1162 | input_sync(field->hidinput->input); |
| 1182 | } | 1163 | } |
| 1183 | 1164 | ||
| 1184 | static void mt_set_input_mode(struct hid_device *hdev) | 1165 | static bool mt_need_to_apply_feature(struct hid_device *hdev, |
| 1166 | struct hid_field *field, | ||
| 1167 | struct hid_usage *usage, | ||
| 1168 | enum latency_mode latency, | ||
| 1169 | bool surface_switch, | ||
| 1170 | bool button_switch) | ||
| 1185 | { | 1171 | { |
| 1186 | struct mt_device *td = hid_get_drvdata(hdev); | 1172 | struct mt_device *td = hid_get_drvdata(hdev); |
| 1187 | struct hid_report *r; | ||
| 1188 | struct hid_report_enum *re; | ||
| 1189 | struct mt_class *cls = &td->mtclass; | 1173 | struct mt_class *cls = &td->mtclass; |
| 1174 | struct hid_report *report = field->report; | ||
| 1175 | unsigned int index = usage->usage_index; | ||
| 1190 | char *buf; | 1176 | char *buf; |
| 1191 | u32 report_len; | 1177 | u32 report_len; |
| 1178 | int max; | ||
| 1192 | 1179 | ||
| 1193 | if (td->inputmode < 0) | 1180 | switch (usage->hid) { |
| 1194 | return; | 1181 | case HID_DG_INPUTMODE: |
| 1195 | |||
| 1196 | re = &(hdev->report_enum[HID_FEATURE_REPORT]); | ||
| 1197 | r = re->report_id_hash[td->inputmode]; | ||
| 1198 | if (r) { | ||
| 1199 | if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) { | 1182 | if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) { |
| 1200 | report_len = hid_report_len(r); | 1183 | report_len = hid_report_len(report); |
| 1201 | buf = hid_alloc_report_buf(r, GFP_KERNEL); | 1184 | buf = hid_alloc_report_buf(report, GFP_KERNEL); |
| 1202 | if (!buf) { | 1185 | if (!buf) { |
| 1203 | hid_err(hdev, "failed to allocate buffer for report\n"); | 1186 | hid_err(hdev, |
| 1204 | return; | 1187 | "failed to allocate buffer for report\n"); |
| 1188 | return false; | ||
| 1205 | } | 1189 | } |
| 1206 | hid_hw_raw_request(hdev, r->id, buf, report_len, | 1190 | hid_hw_raw_request(hdev, report->id, buf, report_len, |
| 1207 | HID_FEATURE_REPORT, | 1191 | HID_FEATURE_REPORT, |
| 1208 | HID_REQ_GET_REPORT); | 1192 | HID_REQ_GET_REPORT); |
| 1209 | kfree(buf); | 1193 | kfree(buf); |
| 1210 | } | 1194 | } |
| 1211 | r->field[0]->value[td->inputmode_index] = td->inputmode_value; | ||
| 1212 | hid_hw_request(hdev, r, HID_REQ_SET_REPORT); | ||
| 1213 | } | ||
| 1214 | } | ||
| 1215 | 1195 | ||
| 1216 | static void mt_set_maxcontacts(struct hid_device *hdev) | 1196 | field->value[index] = td->inputmode_value; |
| 1217 | { | 1197 | return true; |
| 1218 | struct mt_device *td = hid_get_drvdata(hdev); | ||
| 1219 | struct hid_report *r; | ||
| 1220 | struct hid_report_enum *re; | ||
| 1221 | int fieldmax, max; | ||
| 1222 | 1198 | ||
| 1223 | if (td->maxcontact_report_id < 0) | 1199 | case HID_DG_CONTACTMAX: |
| 1224 | return; | 1200 | if (td->mtclass.maxcontacts) { |
| 1201 | max = min_t(int, field->logical_maximum, | ||
| 1202 | td->mtclass.maxcontacts); | ||
| 1203 | if (field->value[index] != max) { | ||
| 1204 | field->value[index] = max; | ||
| 1205 | return true; | ||
| 1206 | } | ||
| 1207 | } | ||
| 1208 | break; | ||
| 1225 | 1209 | ||
| 1226 | if (!td->mtclass.maxcontacts) | 1210 | case HID_DG_LATENCYMODE: |
| 1227 | return; | 1211 | field->value[index] = latency; |
| 1212 | return true; | ||
| 1213 | |||
| 1214 | case HID_DG_SURFACESWITCH: | ||
| 1215 | field->value[index] = surface_switch; | ||
| 1216 | return true; | ||
| 1217 | |||
| 1218 | case HID_DG_BUTTONSWITCH: | ||
| 1219 | field->value[index] = button_switch; | ||
| 1220 | return true; | ||
| 1221 | } | ||
| 1228 | 1222 | ||
| 1229 | re = &hdev->report_enum[HID_FEATURE_REPORT]; | 1223 | return false; /* no need to update the report */ |
| 1230 | r = re->report_id_hash[td->maxcontact_report_id]; | 1224 | } |
| 1231 | if (r) { | 1225 | |
| 1232 | max = td->mtclass.maxcontacts; | 1226 | static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency, |
| 1233 | fieldmax = r->field[0]->logical_maximum; | 1227 | bool surface_switch, bool button_switch) |
| 1234 | max = min(fieldmax, max); | 1228 | { |
| 1235 | if (r->field[0]->value[0] != max) { | 1229 | struct hid_report_enum *rep_enum; |
| 1236 | r->field[0]->value[0] = max; | 1230 | struct hid_report *rep; |
| 1237 | hid_hw_request(hdev, r, HID_REQ_SET_REPORT); | 1231 | struct hid_usage *usage; |
| 1232 | int i, j; | ||
| 1233 | bool update_report; | ||
| 1234 | |||
| 1235 | rep_enum = &hdev->report_enum[HID_FEATURE_REPORT]; | ||
| 1236 | list_for_each_entry(rep, &rep_enum->report_list, list) { | ||
| 1237 | update_report = false; | ||
| 1238 | |||
| 1239 | for (i = 0; i < rep->maxfield; i++) { | ||
| 1240 | /* Ignore if report count is out of bounds. */ | ||
| 1241 | if (rep->field[i]->report_count < 1) | ||
| 1242 | continue; | ||
| 1243 | |||
| 1244 | for (j = 0; j < rep->field[i]->maxusage; j++) { | ||
| 1245 | usage = &rep->field[i]->usage[j]; | ||
| 1246 | |||
| 1247 | if (mt_need_to_apply_feature(hdev, | ||
| 1248 | rep->field[i], | ||
| 1249 | usage, | ||
| 1250 | latency, | ||
| 1251 | surface_switch, | ||
| 1252 | button_switch)) | ||
| 1253 | update_report = true; | ||
| 1254 | } | ||
| 1238 | } | 1255 | } |
| 1256 | |||
| 1257 | if (update_report) | ||
| 1258 | hid_hw_request(hdev, rep, HID_REQ_SET_REPORT); | ||
| 1239 | } | 1259 | } |
| 1240 | } | 1260 | } |
| 1241 | 1261 | ||
| @@ -1274,54 +1294,48 @@ static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi) | |||
| 1274 | struct mt_device *td = hid_get_drvdata(hdev); | 1294 | struct mt_device *td = hid_get_drvdata(hdev); |
| 1275 | char *name; | 1295 | char *name; |
| 1276 | const char *suffix = NULL; | 1296 | const char *suffix = NULL; |
| 1277 | struct hid_field *field = hi->report->field[0]; | 1297 | unsigned int application = 0; |
| 1298 | struct hid_report *report; | ||
| 1278 | int ret; | 1299 | int ret; |
| 1279 | 1300 | ||
| 1280 | if (hi->report->id == td->mt_report_id) { | 1301 | list_for_each_entry(report, &hi->reports, hidinput_list) { |
| 1281 | ret = mt_touch_input_configured(hdev, hi); | 1302 | application = report->application; |
| 1282 | if (ret) | 1303 | if (report->id == td->mt_report_id) { |
| 1283 | return ret; | 1304 | ret = mt_touch_input_configured(hdev, hi); |
| 1305 | if (ret) | ||
| 1306 | return ret; | ||
| 1307 | } | ||
| 1308 | |||
| 1309 | /* | ||
| 1310 | * some egalax touchscreens have "application == DG_TOUCHSCREEN" | ||
| 1311 | * for the stylus. Check this first, and then rely on | ||
| 1312 | * the application field. | ||
| 1313 | */ | ||
| 1314 | if (report->field[0]->physical == HID_DG_STYLUS) { | ||
| 1315 | suffix = "Pen"; | ||
| 1316 | /* force BTN_STYLUS to allow tablet matching in udev */ | ||
| 1317 | __set_bit(BTN_STYLUS, hi->input->keybit); | ||
| 1318 | } | ||
| 1284 | } | 1319 | } |
| 1285 | 1320 | ||
| 1286 | /* | 1321 | if (!suffix) { |
| 1287 | * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN" | 1322 | switch (application) { |
| 1288 | * for the stylus. Check this first, and then rely on the application | ||
| 1289 | * field. | ||
| 1290 | */ | ||
| 1291 | if (hi->report->field[0]->physical == HID_DG_STYLUS) { | ||
| 1292 | suffix = "Pen"; | ||
| 1293 | /* force BTN_STYLUS to allow tablet matching in udev */ | ||
| 1294 | __set_bit(BTN_STYLUS, hi->input->keybit); | ||
| 1295 | } else { | ||
| 1296 | switch (field->application) { | ||
| 1297 | case HID_GD_KEYBOARD: | 1323 | case HID_GD_KEYBOARD: |
| 1298 | suffix = "Keyboard"; | ||
| 1299 | break; | ||
| 1300 | case HID_GD_KEYPAD: | 1324 | case HID_GD_KEYPAD: |
| 1301 | suffix = "Keypad"; | ||
| 1302 | break; | ||
| 1303 | case HID_GD_MOUSE: | 1325 | case HID_GD_MOUSE: |
| 1304 | suffix = "Mouse"; | ||
| 1305 | break; | ||
| 1306 | case HID_DG_STYLUS: | ||
| 1307 | suffix = "Pen"; | ||
| 1308 | /* force BTN_STYLUS to allow tablet matching in udev */ | ||
| 1309 | __set_bit(BTN_STYLUS, hi->input->keybit); | ||
| 1310 | break; | ||
| 1311 | case HID_DG_TOUCHSCREEN: | ||
| 1312 | /* we do not set suffix = "Touchscreen" */ | ||
| 1313 | break; | ||
| 1314 | case HID_DG_TOUCHPAD: | 1326 | case HID_DG_TOUCHPAD: |
| 1315 | suffix = "Touchpad"; | ||
| 1316 | break; | ||
| 1317 | case HID_GD_SYSTEM_CONTROL: | 1327 | case HID_GD_SYSTEM_CONTROL: |
| 1318 | suffix = "System Control"; | ||
| 1319 | break; | ||
| 1320 | case HID_CP_CONSUMER_CONTROL: | 1328 | case HID_CP_CONSUMER_CONTROL: |
| 1321 | suffix = "Consumer Control"; | ||
| 1322 | break; | ||
| 1323 | case HID_GD_WIRELESS_RADIO_CTLS: | 1329 | case HID_GD_WIRELESS_RADIO_CTLS: |
| 1324 | suffix = "Wireless Radio Control"; | 1330 | /* already handled by hid core */ |
| 1331 | break; | ||
| 1332 | case HID_DG_TOUCHSCREEN: | ||
| 1333 | /* we do not set suffix = "Touchscreen" */ | ||
| 1334 | hi->input->name = hdev->name; | ||
| 1335 | break; | ||
| 1336 | case HID_DG_STYLUS: | ||
| 1337 | /* force BTN_STYLUS to allow tablet matching in udev */ | ||
| 1338 | __set_bit(BTN_STYLUS, hi->input->keybit); | ||
| 1325 | break; | 1339 | break; |
| 1326 | case HID_VD_ASUS_CUSTOM_MEDIA_KEYS: | 1340 | case HID_VD_ASUS_CUSTOM_MEDIA_KEYS: |
| 1327 | suffix = "Custom Media Keys"; | 1341 | suffix = "Custom Media Keys"; |
| @@ -1434,8 +1448,6 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 1434 | } | 1448 | } |
| 1435 | td->hdev = hdev; | 1449 | td->hdev = hdev; |
| 1436 | td->mtclass = *mtclass; | 1450 | td->mtclass = *mtclass; |
| 1437 | td->inputmode = -1; | ||
| 1438 | td->maxcontact_report_id = -1; | ||
| 1439 | td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN; | 1451 | td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN; |
| 1440 | td->cc_index = -1; | 1452 | td->cc_index = -1; |
| 1441 | td->scantime_index = -1; | 1453 | td->scantime_index = -1; |
| @@ -1459,10 +1471,10 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 1459 | 1471 | ||
| 1460 | /* | 1472 | /* |
| 1461 | * This allows the driver to handle different input sensors | 1473 | * This allows the driver to handle different input sensors |
| 1462 | * that emits events through different reports on the same HID | 1474 | * that emits events through different applications on the same HID |
| 1463 | * device. | 1475 | * device. |
| 1464 | */ | 1476 | */ |
| 1465 | hdev->quirks |= HID_QUIRK_MULTI_INPUT; | 1477 | hdev->quirks |= HID_QUIRK_INPUT_PER_APP; |
| 1466 | 1478 | ||
| 1467 | timer_setup(&td->release_timer, mt_expired_timeout, 0); | 1479 | timer_setup(&td->release_timer, mt_expired_timeout, 0); |
| 1468 | 1480 | ||
| @@ -1482,8 +1494,7 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 1482 | dev_warn(&hdev->dev, "Cannot allocate sysfs group for %s\n", | 1494 | dev_warn(&hdev->dev, "Cannot allocate sysfs group for %s\n", |
| 1483 | hdev->name); | 1495 | hdev->name); |
| 1484 | 1496 | ||
| 1485 | mt_set_maxcontacts(hdev); | 1497 | mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true); |
| 1486 | mt_set_input_mode(hdev); | ||
| 1487 | 1498 | ||
| 1488 | /* release .fields memory as it is not used anymore */ | 1499 | /* release .fields memory as it is not used anymore */ |
| 1489 | devm_kfree(&hdev->dev, td->fields); | 1500 | devm_kfree(&hdev->dev, td->fields); |
| @@ -1496,8 +1507,7 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 1496 | static int mt_reset_resume(struct hid_device *hdev) | 1507 | static int mt_reset_resume(struct hid_device *hdev) |
| 1497 | { | 1508 | { |
| 1498 | mt_release_contacts(hdev); | 1509 | mt_release_contacts(hdev); |
| 1499 | mt_set_maxcontacts(hdev); | 1510 | mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true); |
| 1500 | mt_set_input_mode(hdev); | ||
| 1501 | return 0; | 1511 | return 0; |
| 1502 | } | 1512 | } |
| 1503 | 1513 | ||
diff --git a/drivers/hid/hid-plantronics.c b/drivers/hid/hid-plantronics.c index febb21ee190e..584b10d3fc3d 100644 --- a/drivers/hid/hid-plantronics.c +++ b/drivers/hid/hid-plantronics.c | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | * Plantronics USB HID Driver | 2 | * Plantronics USB HID Driver |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 2014 JD Cole <jd.cole@plantronics.com> | 4 | * Copyright (c) 2014 JD Cole <jd.cole@plantronics.com> |
| 5 | * Copyright (c) 2015 Terry Junge <terry.junge@plantronics.com> | 5 | * Copyright (c) 2015-2018 Terry Junge <terry.junge@plantronics.com> |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | /* | 8 | /* |
| @@ -48,6 +48,10 @@ static int plantronics_input_mapping(struct hid_device *hdev, | |||
| 48 | unsigned short mapped_key; | 48 | unsigned short mapped_key; |
| 49 | unsigned long plt_type = (unsigned long)hid_get_drvdata(hdev); | 49 | unsigned long plt_type = (unsigned long)hid_get_drvdata(hdev); |
| 50 | 50 | ||
| 51 | /* special case for PTT products */ | ||
| 52 | if (field->application == HID_GD_JOYSTICK) | ||
| 53 | goto defaulted; | ||
| 54 | |||
| 51 | /* handle volume up/down mapping */ | 55 | /* handle volume up/down mapping */ |
| 52 | /* non-standard types or multi-HID interfaces - plt_type is PID */ | 56 | /* non-standard types or multi-HID interfaces - plt_type is PID */ |
| 53 | if (!(plt_type & HID_USAGE_PAGE)) { | 57 | if (!(plt_type & HID_USAGE_PAGE)) { |
diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c index 587e2681a53f..249d49b6b16c 100644 --- a/drivers/hid/hid-quirks.c +++ b/drivers/hid/hid-quirks.c | |||
| @@ -416,7 +416,6 @@ static const struct hid_device_id hid_have_special_driver[] = { | |||
| 416 | { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000) }, | 416 | { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000) }, |
| 417 | #endif | 417 | #endif |
| 418 | #if IS_ENABLED(CONFIG_HID_LED) | 418 | #if IS_ENABLED(CONFIG_HID_LED) |
| 419 | { HID_USB_DEVICE(USB_VENDOR_ID_DELCOM, USB_DEVICE_ID_DELCOM_VISUAL_IND) }, | ||
| 420 | { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, USB_DEVICE_ID_DREAM_CHEEKY_WN) }, | 419 | { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, USB_DEVICE_ID_DREAM_CHEEKY_WN) }, |
| 421 | { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, USB_DEVICE_ID_DREAM_CHEEKY_FA) }, | 420 | { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, USB_DEVICE_ID_DREAM_CHEEKY_FA) }, |
| 422 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_LUXAFOR) }, | 421 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_LUXAFOR) }, |
diff --git a/drivers/hid/hid-redragon.c b/drivers/hid/hid-redragon.c new file mode 100644 index 000000000000..daf59578bf93 --- /dev/null +++ b/drivers/hid/hid-redragon.c | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | /* | ||
| 2 | * HID driver for Redragon keyboards | ||
| 3 | * | ||
| 4 | * Copyright (c) 2017 Robert Munteanu | ||
| 5 | * SPDX-License-Identifier: GPL-2.0+ | ||
| 6 | */ | ||
| 7 | |||
| 8 | /* | ||
| 9 | * This program is free software; you can redistribute it and/or modify it | ||
| 10 | * under the terms of the GNU General Public License as published by the Free | ||
| 11 | * Software Foundation; either version 2 of the License, or (at your option) | ||
| 12 | * any later version. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #include <linux/device.h> | ||
| 16 | #include <linux/hid.h> | ||
| 17 | #include <linux/module.h> | ||
| 18 | |||
| 19 | #include "hid-ids.h" | ||
| 20 | |||
| 21 | |||
| 22 | /* | ||
| 23 | * The Redragon Asura keyboard sends an incorrect HID descriptor. | ||
| 24 | * At byte 100 it contains | ||
| 25 | * | ||
| 26 | * 0x81, 0x00 | ||
| 27 | * | ||
| 28 | * which is Input (Data, Arr, Abs), but it should be | ||
| 29 | * | ||
| 30 | * 0x81, 0x02 | ||
| 31 | * | ||
| 32 | * which is Input (Data, Var, Abs), which is consistent with the way | ||
| 33 | * key codes are generated. | ||
| 34 | */ | ||
| 35 | |||
| 36 | static __u8 *redragon_report_fixup(struct hid_device *hdev, __u8 *rdesc, | ||
| 37 | unsigned int *rsize) | ||
| 38 | { | ||
| 39 | if (*rsize >= 102 && rdesc[100] == 0x81 && rdesc[101] == 0x00) { | ||
| 40 | dev_info(&hdev->dev, "Fixing Redragon ASURA report descriptor.\n"); | ||
| 41 | rdesc[101] = 0x02; | ||
| 42 | } | ||
| 43 | |||
| 44 | return rdesc; | ||
| 45 | } | ||
| 46 | |||
| 47 | static int redragon_probe(struct hid_device *dev, | ||
| 48 | const struct hid_device_id *id) | ||
| 49 | { | ||
| 50 | int ret; | ||
| 51 | |||
| 52 | ret = hid_parse(dev); | ||
| 53 | if (ret) { | ||
| 54 | hid_err(dev, "parse failed\n"); | ||
| 55 | return ret; | ||
| 56 | } | ||
| 57 | |||
| 58 | /* do not register unused input device */ | ||
| 59 | if (dev->maxapplication == 1) | ||
| 60 | return 0; | ||
| 61 | |||
| 62 | ret = hid_hw_start(dev, HID_CONNECT_DEFAULT); | ||
| 63 | if (ret) { | ||
| 64 | hid_err(dev, "hw start failed\n"); | ||
| 65 | return ret; | ||
| 66 | } | ||
| 67 | |||
| 68 | return 0; | ||
| 69 | } | ||
| 70 | static const struct hid_device_id redragon_devices[] = { | ||
| 71 | {HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_REDRAGON_ASURA)}, | ||
| 72 | {} | ||
| 73 | }; | ||
| 74 | |||
| 75 | MODULE_DEVICE_TABLE(hid, redragon_devices); | ||
| 76 | |||
| 77 | static struct hid_driver redragon_driver = { | ||
| 78 | .name = "redragon", | ||
| 79 | .id_table = redragon_devices, | ||
| 80 | .report_fixup = redragon_report_fixup, | ||
| 81 | .probe = redragon_probe | ||
| 82 | }; | ||
| 83 | |||
| 84 | module_hid_driver(redragon_driver); | ||
| 85 | |||
| 86 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c index 9c9362149641..9e33165250a3 100644 --- a/drivers/hid/hid-rmi.c +++ b/drivers/hid/hid-rmi.c | |||
| @@ -413,6 +413,24 @@ static int rmi_event(struct hid_device *hdev, struct hid_field *field, | |||
| 413 | return 0; | 413 | return 0; |
| 414 | } | 414 | } |
| 415 | 415 | ||
| 416 | static void rmi_report(struct hid_device *hid, struct hid_report *report) | ||
| 417 | { | ||
| 418 | struct hid_field *field = report->field[0]; | ||
| 419 | |||
| 420 | if (!(hid->claimed & HID_CLAIMED_INPUT)) | ||
| 421 | return; | ||
| 422 | |||
| 423 | switch (report->id) { | ||
| 424 | case RMI_READ_DATA_REPORT_ID: | ||
| 425 | /* fall-through */ | ||
| 426 | case RMI_ATTN_REPORT_ID: | ||
| 427 | return; | ||
| 428 | } | ||
| 429 | |||
| 430 | if (field && field->hidinput && field->hidinput->input) | ||
| 431 | input_sync(field->hidinput->input); | ||
| 432 | } | ||
| 433 | |||
| 416 | #ifdef CONFIG_PM | 434 | #ifdef CONFIG_PM |
| 417 | static int rmi_suspend(struct hid_device *hdev, pm_message_t message) | 435 | static int rmi_suspend(struct hid_device *hdev, pm_message_t message) |
| 418 | { | 436 | { |
| @@ -637,6 +655,7 @@ static int rmi_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 637 | hid_set_drvdata(hdev, data); | 655 | hid_set_drvdata(hdev, data); |
| 638 | 656 | ||
| 639 | hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; | 657 | hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; |
| 658 | hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC; | ||
| 640 | 659 | ||
| 641 | ret = hid_parse(hdev); | 660 | ret = hid_parse(hdev); |
| 642 | if (ret) { | 661 | if (ret) { |
| @@ -744,6 +763,7 @@ static struct hid_driver rmi_driver = { | |||
| 744 | .remove = rmi_remove, | 763 | .remove = rmi_remove, |
| 745 | .event = rmi_event, | 764 | .event = rmi_event, |
| 746 | .raw_event = rmi_raw_event, | 765 | .raw_event = rmi_raw_event, |
| 766 | .report = rmi_report, | ||
| 747 | .input_mapping = rmi_input_mapping, | 767 | .input_mapping = rmi_input_mapping, |
| 748 | .input_configured = rmi_input_configured, | 768 | .input_configured = rmi_input_configured, |
| 749 | #ifdef CONFIG_PM | 769 | #ifdef CONFIG_PM |
diff --git a/drivers/hid/hid-steam.c b/drivers/hid/hid-steam.c new file mode 100644 index 000000000000..cb86cc834201 --- /dev/null +++ b/drivers/hid/hid-steam.c | |||
| @@ -0,0 +1,1115 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0+ | ||
| 2 | /* | ||
| 3 | * HID driver for Valve Steam Controller | ||
| 4 | * | ||
| 5 | * Copyright (c) 2018 Rodrigo Rivas Costa <rodrigorivascosta@gmail.com> | ||
| 6 | * | ||
| 7 | * Supports both the wired and wireless interfaces. | ||
| 8 | * | ||
| 9 | * This controller has a builtin emulation of mouse and keyboard: the right pad | ||
| 10 | * can be used as a mouse, the shoulder buttons are mouse buttons, A and B | ||
| 11 | * buttons are ENTER and ESCAPE, and so on. This is implemented as additional | ||
| 12 | * HID interfaces. | ||
| 13 | * | ||
| 14 | * This is known as the "lizard mode", because apparently lizards like to use | ||
| 15 | * the computer from the coach, without a proper mouse and keyboard. | ||
| 16 | * | ||
| 17 | * This driver will disable the lizard mode when the input device is opened | ||
| 18 | * and re-enable it when the input device is closed, so as not to break user | ||
| 19 | * mode behaviour. The lizard_mode parameter can be used to change that. | ||
| 20 | * | ||
| 21 | * There are a few user space applications (notably Steam Client) that use | ||
| 22 | * the hidraw interface directly to create input devices (XTest, uinput...). | ||
| 23 | * In order to avoid breaking them this driver creates a layered hidraw device, | ||
| 24 | * so it can detect when the client is running and then: | ||
| 25 | * - it will not send any command to the controller. | ||
| 26 | * - this input device will be disabled, to avoid double input of the same | ||
| 27 | * user action. | ||
| 28 | * | ||
| 29 | * For additional functions, such as changing the right-pad margin or switching | ||
| 30 | * the led, you can use the user-space tool at: | ||
| 31 | * | ||
| 32 | * https://github.com/rodrigorc/steamctrl | ||
| 33 | */ | ||
| 34 | |||
| 35 | #include <linux/device.h> | ||
| 36 | #include <linux/input.h> | ||
| 37 | #include <linux/hid.h> | ||
| 38 | #include <linux/module.h> | ||
| 39 | #include <linux/workqueue.h> | ||
| 40 | #include <linux/mutex.h> | ||
| 41 | #include <linux/rcupdate.h> | ||
| 42 | #include <linux/delay.h> | ||
| 43 | #include <linux/power_supply.h> | ||
| 44 | #include "hid-ids.h" | ||
| 45 | |||
| 46 | MODULE_LICENSE("GPL"); | ||
| 47 | MODULE_AUTHOR("Rodrigo Rivas Costa <rodrigorivascosta@gmail.com>"); | ||
| 48 | |||
| 49 | static bool lizard_mode = true; | ||
| 50 | |||
| 51 | static DEFINE_MUTEX(steam_devices_lock); | ||
| 52 | static LIST_HEAD(steam_devices); | ||
| 53 | |||
| 54 | #define STEAM_QUIRK_WIRELESS BIT(0) | ||
| 55 | |||
| 56 | /* Touch pads are 40 mm in diameter and 65535 units */ | ||
| 57 | #define STEAM_PAD_RESOLUTION 1638 | ||
| 58 | /* Trigger runs are about 5 mm and 256 units */ | ||
| 59 | #define STEAM_TRIGGER_RESOLUTION 51 | ||
| 60 | /* Joystick runs are about 5 mm and 256 units */ | ||
| 61 | #define STEAM_JOYSTICK_RESOLUTION 51 | ||
| 62 | |||
| 63 | #define STEAM_PAD_FUZZ 256 | ||
| 64 | |||
| 65 | /* | ||
| 66 | * Commands that can be sent in a feature report. | ||
| 67 | * Thanks to Valve for some valuable hints. | ||
| 68 | */ | ||
| 69 | #define STEAM_CMD_SET_MAPPINGS 0x80 | ||
| 70 | #define STEAM_CMD_CLEAR_MAPPINGS 0x81 | ||
| 71 | #define STEAM_CMD_GET_MAPPINGS 0x82 | ||
| 72 | #define STEAM_CMD_GET_ATTRIB 0x83 | ||
| 73 | #define STEAM_CMD_GET_ATTRIB_LABEL 0x84 | ||
| 74 | #define STEAM_CMD_DEFAULT_MAPPINGS 0x85 | ||
| 75 | #define STEAM_CMD_FACTORY_RESET 0x86 | ||
| 76 | #define STEAM_CMD_WRITE_REGISTER 0x87 | ||
| 77 | #define STEAM_CMD_CLEAR_REGISTER 0x88 | ||
| 78 | #define STEAM_CMD_READ_REGISTER 0x89 | ||
| 79 | #define STEAM_CMD_GET_REGISTER_LABEL 0x8a | ||
| 80 | #define STEAM_CMD_GET_REGISTER_MAX 0x8b | ||
| 81 | #define STEAM_CMD_GET_REGISTER_DEFAULT 0x8c | ||
| 82 | #define STEAM_CMD_SET_MODE 0x8d | ||
| 83 | #define STEAM_CMD_DEFAULT_MOUSE 0x8e | ||
| 84 | #define STEAM_CMD_FORCEFEEDBAK 0x8f | ||
| 85 | #define STEAM_CMD_REQUEST_COMM_STATUS 0xb4 | ||
| 86 | #define STEAM_CMD_GET_SERIAL 0xae | ||
| 87 | |||
| 88 | /* Some useful register ids */ | ||
| 89 | #define STEAM_REG_LPAD_MODE 0x07 | ||
| 90 | #define STEAM_REG_RPAD_MODE 0x08 | ||
| 91 | #define STEAM_REG_RPAD_MARGIN 0x18 | ||
| 92 | #define STEAM_REG_LED 0x2d | ||
| 93 | #define STEAM_REG_GYRO_MODE 0x30 | ||
| 94 | |||
| 95 | /* Raw event identifiers */ | ||
| 96 | #define STEAM_EV_INPUT_DATA 0x01 | ||
| 97 | #define STEAM_EV_CONNECT 0x03 | ||
| 98 | #define STEAM_EV_BATTERY 0x04 | ||
| 99 | |||
| 100 | /* Values for GYRO_MODE (bitmask) */ | ||
| 101 | #define STEAM_GYRO_MODE_OFF 0x0000 | ||
| 102 | #define STEAM_GYRO_MODE_STEERING 0x0001 | ||
| 103 | #define STEAM_GYRO_MODE_TILT 0x0002 | ||
| 104 | #define STEAM_GYRO_MODE_SEND_ORIENTATION 0x0004 | ||
| 105 | #define STEAM_GYRO_MODE_SEND_RAW_ACCEL 0x0008 | ||
| 106 | #define STEAM_GYRO_MODE_SEND_RAW_GYRO 0x0010 | ||
| 107 | |||
| 108 | /* Other random constants */ | ||
| 109 | #define STEAM_SERIAL_LEN 10 | ||
| 110 | |||
| 111 | struct steam_device { | ||
| 112 | struct list_head list; | ||
| 113 | spinlock_t lock; | ||
| 114 | struct hid_device *hdev, *client_hdev; | ||
| 115 | struct mutex mutex; | ||
| 116 | bool client_opened, input_opened; | ||
| 117 | struct input_dev __rcu *input; | ||
| 118 | unsigned long quirks; | ||
| 119 | struct work_struct work_connect; | ||
| 120 | bool connected; | ||
| 121 | char serial_no[STEAM_SERIAL_LEN + 1]; | ||
| 122 | struct power_supply_desc battery_desc; | ||
| 123 | struct power_supply __rcu *battery; | ||
| 124 | u8 battery_charge; | ||
| 125 | u16 voltage; | ||
| 126 | }; | ||
| 127 | |||
| 128 | static int steam_recv_report(struct steam_device *steam, | ||
| 129 | u8 *data, int size) | ||
| 130 | { | ||
| 131 | struct hid_report *r; | ||
| 132 | u8 *buf; | ||
| 133 | int ret; | ||
| 134 | |||
| 135 | r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0]; | ||
| 136 | if (hid_report_len(r) < 64) | ||
| 137 | return -EINVAL; | ||
| 138 | |||
| 139 | buf = hid_alloc_report_buf(r, GFP_KERNEL); | ||
| 140 | if (!buf) | ||
| 141 | return -ENOMEM; | ||
| 142 | |||
| 143 | /* | ||
| 144 | * The report ID is always 0, so strip the first byte from the output. | ||
| 145 | * hid_report_len() is not counting the report ID, so +1 to the length | ||
| 146 | * or else we get a EOVERFLOW. We are safe from a buffer overflow | ||
| 147 | * because hid_alloc_report_buf() allocates +7 bytes. | ||
| 148 | */ | ||
| 149 | ret = hid_hw_raw_request(steam->hdev, 0x00, | ||
| 150 | buf, hid_report_len(r) + 1, | ||
| 151 | HID_FEATURE_REPORT, HID_REQ_GET_REPORT); | ||
| 152 | if (ret > 0) | ||
| 153 | memcpy(data, buf + 1, min(size, ret - 1)); | ||
| 154 | kfree(buf); | ||
| 155 | return ret; | ||
| 156 | } | ||
| 157 | |||
| 158 | static int steam_send_report(struct steam_device *steam, | ||
| 159 | u8 *cmd, int size) | ||
| 160 | { | ||
| 161 | struct hid_report *r; | ||
| 162 | u8 *buf; | ||
| 163 | unsigned int retries = 50; | ||
| 164 | int ret; | ||
| 165 | |||
| 166 | r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0]; | ||
| 167 | if (hid_report_len(r) < 64) | ||
| 168 | return -EINVAL; | ||
| 169 | |||
| 170 | buf = hid_alloc_report_buf(r, GFP_KERNEL); | ||
| 171 | if (!buf) | ||
| 172 | return -ENOMEM; | ||
| 173 | |||
| 174 | /* The report ID is always 0 */ | ||
| 175 | memcpy(buf + 1, cmd, size); | ||
| 176 | |||
| 177 | /* | ||
| 178 | * Sometimes the wireless controller fails with EPIPE | ||
| 179 | * when sending a feature report. | ||
| 180 | * Doing a HID_REQ_GET_REPORT and waiting for a while | ||
| 181 | * seems to fix that. | ||
| 182 | */ | ||
| 183 | do { | ||
| 184 | ret = hid_hw_raw_request(steam->hdev, 0, | ||
| 185 | buf, size + 1, | ||
| 186 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); | ||
| 187 | if (ret != -EPIPE) | ||
| 188 | break; | ||
| 189 | msleep(20); | ||
| 190 | } while (--retries); | ||
| 191 | |||
| 192 | kfree(buf); | ||
| 193 | if (ret < 0) | ||
| 194 | hid_err(steam->hdev, "%s: error %d (%*ph)\n", __func__, | ||
| 195 | ret, size, cmd); | ||
| 196 | return ret; | ||
| 197 | } | ||
| 198 | |||
| 199 | static inline int steam_send_report_byte(struct steam_device *steam, u8 cmd) | ||
| 200 | { | ||
| 201 | return steam_send_report(steam, &cmd, 1); | ||
| 202 | } | ||
| 203 | |||
| 204 | static int steam_write_registers(struct steam_device *steam, | ||
| 205 | /* u8 reg, u16 val */...) | ||
| 206 | { | ||
| 207 | /* Send: 0x87 len (reg valLo valHi)* */ | ||
| 208 | u8 reg; | ||
| 209 | u16 val; | ||
| 210 | u8 cmd[64] = {STEAM_CMD_WRITE_REGISTER, 0x00}; | ||
| 211 | va_list args; | ||
| 212 | |||
| 213 | va_start(args, steam); | ||
| 214 | for (;;) { | ||
| 215 | reg = va_arg(args, int); | ||
| 216 | if (reg == 0) | ||
| 217 | break; | ||
| 218 | val = va_arg(args, int); | ||
| 219 | cmd[cmd[1] + 2] = reg; | ||
| 220 | cmd[cmd[1] + 3] = val & 0xff; | ||
| 221 | cmd[cmd[1] + 4] = val >> 8; | ||
| 222 | cmd[1] += 3; | ||
| 223 | } | ||
| 224 | va_end(args); | ||
| 225 | |||
| 226 | return steam_send_report(steam, cmd, 2 + cmd[1]); | ||
| 227 | } | ||
| 228 | |||
| 229 | static int steam_get_serial(struct steam_device *steam) | ||
| 230 | { | ||
| 231 | /* | ||
| 232 | * Send: 0xae 0x15 0x01 | ||
| 233 | * Recv: 0xae 0x15 0x01 serialnumber (10 chars) | ||
| 234 | */ | ||
| 235 | int ret; | ||
| 236 | u8 cmd[] = {STEAM_CMD_GET_SERIAL, 0x15, 0x01}; | ||
| 237 | u8 reply[3 + STEAM_SERIAL_LEN + 1]; | ||
| 238 | |||
| 239 | ret = steam_send_report(steam, cmd, sizeof(cmd)); | ||
| 240 | if (ret < 0) | ||
| 241 | return ret; | ||
| 242 | ret = steam_recv_report(steam, reply, sizeof(reply)); | ||
| 243 | if (ret < 0) | ||
| 244 | return ret; | ||
| 245 | if (reply[0] != 0xae || reply[1] != 0x15 || reply[2] != 0x01) | ||
| 246 | return -EIO; | ||
| 247 | reply[3 + STEAM_SERIAL_LEN] = 0; | ||
| 248 | strlcpy(steam->serial_no, reply + 3, sizeof(steam->serial_no)); | ||
| 249 | return 0; | ||
| 250 | } | ||
| 251 | |||
| 252 | /* | ||
| 253 | * This command requests the wireless adaptor to post an event | ||
| 254 | * with the connection status. Useful if this driver is loaded when | ||
| 255 | * the controller is already connected. | ||
| 256 | */ | ||
| 257 | static inline int steam_request_conn_status(struct steam_device *steam) | ||
| 258 | { | ||
| 259 | return steam_send_report_byte(steam, STEAM_CMD_REQUEST_COMM_STATUS); | ||
| 260 | } | ||
| 261 | |||
| 262 | static void steam_set_lizard_mode(struct steam_device *steam, bool enable) | ||
| 263 | { | ||
| 264 | if (enable) { | ||
| 265 | /* enable esc, enter, cursors */ | ||
| 266 | steam_send_report_byte(steam, STEAM_CMD_DEFAULT_MAPPINGS); | ||
| 267 | /* enable mouse */ | ||
| 268 | steam_send_report_byte(steam, STEAM_CMD_DEFAULT_MOUSE); | ||
| 269 | steam_write_registers(steam, | ||
| 270 | STEAM_REG_RPAD_MARGIN, 0x01, /* enable margin */ | ||
| 271 | 0); | ||
| 272 | } else { | ||
| 273 | /* disable esc, enter, cursor */ | ||
| 274 | steam_send_report_byte(steam, STEAM_CMD_CLEAR_MAPPINGS); | ||
| 275 | steam_write_registers(steam, | ||
| 276 | STEAM_REG_RPAD_MODE, 0x07, /* disable mouse */ | ||
| 277 | STEAM_REG_RPAD_MARGIN, 0x00, /* disable margin */ | ||
| 278 | 0); | ||
| 279 | } | ||
| 280 | } | ||
| 281 | |||
| 282 | static void steam_update_lizard_mode(struct steam_device *steam) | ||
| 283 | { | ||
| 284 | mutex_lock(&steam->mutex); | ||
| 285 | if (!steam->client_opened) { | ||
| 286 | if (steam->input_opened) | ||
| 287 | steam_set_lizard_mode(steam, false); | ||
| 288 | else | ||
| 289 | steam_set_lizard_mode(steam, lizard_mode); | ||
| 290 | } | ||
| 291 | mutex_unlock(&steam->mutex); | ||
| 292 | } | ||
| 293 | |||
| 294 | static int steam_input_open(struct input_dev *dev) | ||
| 295 | { | ||
| 296 | struct steam_device *steam = input_get_drvdata(dev); | ||
| 297 | int ret; | ||
| 298 | |||
| 299 | ret = hid_hw_open(steam->hdev); | ||
| 300 | if (ret) | ||
| 301 | return ret; | ||
| 302 | |||
| 303 | mutex_lock(&steam->mutex); | ||
| 304 | steam->input_opened = true; | ||
| 305 | if (!steam->client_opened && lizard_mode) | ||
| 306 | steam_set_lizard_mode(steam, false); | ||
| 307 | mutex_unlock(&steam->mutex); | ||
| 308 | return 0; | ||
| 309 | } | ||
| 310 | |||
| 311 | static void steam_input_close(struct input_dev *dev) | ||
| 312 | { | ||
| 313 | struct steam_device *steam = input_get_drvdata(dev); | ||
| 314 | |||
| 315 | mutex_lock(&steam->mutex); | ||
| 316 | steam->input_opened = false; | ||
| 317 | if (!steam->client_opened && lizard_mode) | ||
| 318 | steam_set_lizard_mode(steam, true); | ||
| 319 | mutex_unlock(&steam->mutex); | ||
| 320 | |||
| 321 | hid_hw_close(steam->hdev); | ||
| 322 | } | ||
| 323 | |||
| 324 | static enum power_supply_property steam_battery_props[] = { | ||
| 325 | POWER_SUPPLY_PROP_PRESENT, | ||
| 326 | POWER_SUPPLY_PROP_SCOPE, | ||
| 327 | POWER_SUPPLY_PROP_VOLTAGE_NOW, | ||
| 328 | POWER_SUPPLY_PROP_CAPACITY, | ||
| 329 | }; | ||
| 330 | |||
| 331 | static int steam_battery_get_property(struct power_supply *psy, | ||
| 332 | enum power_supply_property psp, | ||
| 333 | union power_supply_propval *val) | ||
| 334 | { | ||
| 335 | struct steam_device *steam = power_supply_get_drvdata(psy); | ||
| 336 | unsigned long flags; | ||
| 337 | s16 volts; | ||
| 338 | u8 batt; | ||
| 339 | int ret = 0; | ||
| 340 | |||
| 341 | spin_lock_irqsave(&steam->lock, flags); | ||
| 342 | volts = steam->voltage; | ||
| 343 | batt = steam->battery_charge; | ||
| 344 | spin_unlock_irqrestore(&steam->lock, flags); | ||
| 345 | |||
| 346 | switch (psp) { | ||
| 347 | case POWER_SUPPLY_PROP_PRESENT: | ||
| 348 | val->intval = 1; | ||
| 349 | break; | ||
| 350 | case POWER_SUPPLY_PROP_SCOPE: | ||
| 351 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; | ||
| 352 | break; | ||
| 353 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: | ||
| 354 | val->intval = volts * 1000; /* mV -> uV */ | ||
| 355 | break; | ||
| 356 | case POWER_SUPPLY_PROP_CAPACITY: | ||
| 357 | val->intval = batt; | ||
| 358 | break; | ||
| 359 | default: | ||
| 360 | ret = -EINVAL; | ||
| 361 | break; | ||
| 362 | } | ||
| 363 | return ret; | ||
| 364 | } | ||
| 365 | |||
| 366 | static int steam_battery_register(struct steam_device *steam) | ||
| 367 | { | ||
| 368 | struct power_supply *battery; | ||
| 369 | struct power_supply_config battery_cfg = { .drv_data = steam, }; | ||
| 370 | unsigned long flags; | ||
| 371 | int ret; | ||
| 372 | |||
| 373 | steam->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; | ||
| 374 | steam->battery_desc.properties = steam_battery_props; | ||
| 375 | steam->battery_desc.num_properties = ARRAY_SIZE(steam_battery_props); | ||
| 376 | steam->battery_desc.get_property = steam_battery_get_property; | ||
| 377 | steam->battery_desc.name = devm_kasprintf(&steam->hdev->dev, | ||
| 378 | GFP_KERNEL, "steam-controller-%s-battery", | ||
| 379 | steam->serial_no); | ||
| 380 | if (!steam->battery_desc.name) | ||
| 381 | return -ENOMEM; | ||
| 382 | |||
| 383 | /* avoid the warning of 0% battery while waiting for the first info */ | ||
| 384 | spin_lock_irqsave(&steam->lock, flags); | ||
| 385 | steam->voltage = 3000; | ||
| 386 | steam->battery_charge = 100; | ||
| 387 | spin_unlock_irqrestore(&steam->lock, flags); | ||
| 388 | |||
| 389 | battery = power_supply_register(&steam->hdev->dev, | ||
| 390 | &steam->battery_desc, &battery_cfg); | ||
| 391 | if (IS_ERR(battery)) { | ||
| 392 | ret = PTR_ERR(battery); | ||
| 393 | hid_err(steam->hdev, | ||
| 394 | "%s:power_supply_register failed with error %d\n", | ||
| 395 | __func__, ret); | ||
| 396 | return ret; | ||
| 397 | } | ||
| 398 | rcu_assign_pointer(steam->battery, battery); | ||
| 399 | power_supply_powers(battery, &steam->hdev->dev); | ||
| 400 | return 0; | ||
| 401 | } | ||
| 402 | |||
| 403 | static int steam_register(struct steam_device *steam) | ||
| 404 | { | ||
| 405 | struct hid_device *hdev = steam->hdev; | ||
| 406 | struct input_dev *input; | ||
| 407 | int ret; | ||
| 408 | |||
| 409 | rcu_read_lock(); | ||
| 410 | input = rcu_dereference(steam->input); | ||
| 411 | rcu_read_unlock(); | ||
| 412 | if (input) { | ||
| 413 | dbg_hid("%s: already connected\n", __func__); | ||
| 414 | return 0; | ||
| 415 | } | ||
| 416 | |||
| 417 | /* | ||
| 418 | * Unlikely, but getting the serial could fail, and it is not so | ||
| 419 | * important, so make up a serial number and go on. | ||
| 420 | */ | ||
| 421 | if (steam_get_serial(steam) < 0) | ||
| 422 | strlcpy(steam->serial_no, "XXXXXXXXXX", | ||
| 423 | sizeof(steam->serial_no)); | ||
| 424 | |||
| 425 | hid_info(hdev, "Steam Controller '%s' connected", | ||
| 426 | steam->serial_no); | ||
| 427 | |||
| 428 | input = input_allocate_device(); | ||
| 429 | if (!input) | ||
| 430 | return -ENOMEM; | ||
| 431 | |||
| 432 | input_set_drvdata(input, steam); | ||
| 433 | input->dev.parent = &hdev->dev; | ||
| 434 | input->open = steam_input_open; | ||
| 435 | input->close = steam_input_close; | ||
| 436 | |||
| 437 | input->name = (steam->quirks & STEAM_QUIRK_WIRELESS) ? | ||
| 438 | "Wireless Steam Controller" : | ||
| 439 | "Steam Controller"; | ||
| 440 | input->phys = hdev->phys; | ||
| 441 | input->uniq = steam->serial_no; | ||
| 442 | input->id.bustype = hdev->bus; | ||
| 443 | input->id.vendor = hdev->vendor; | ||
| 444 | input->id.product = hdev->product; | ||
| 445 | input->id.version = hdev->version; | ||
| 446 | |||
| 447 | input_set_capability(input, EV_KEY, BTN_TR2); | ||
| 448 | input_set_capability(input, EV_KEY, BTN_TL2); | ||
| 449 | input_set_capability(input, EV_KEY, BTN_TR); | ||
| 450 | input_set_capability(input, EV_KEY, BTN_TL); | ||
| 451 | input_set_capability(input, EV_KEY, BTN_Y); | ||
| 452 | input_set_capability(input, EV_KEY, BTN_B); | ||
| 453 | input_set_capability(input, EV_KEY, BTN_X); | ||
| 454 | input_set_capability(input, EV_KEY, BTN_A); | ||
| 455 | input_set_capability(input, EV_KEY, BTN_DPAD_UP); | ||
| 456 | input_set_capability(input, EV_KEY, BTN_DPAD_RIGHT); | ||
| 457 | input_set_capability(input, EV_KEY, BTN_DPAD_LEFT); | ||
| 458 | input_set_capability(input, EV_KEY, BTN_DPAD_DOWN); | ||
| 459 | input_set_capability(input, EV_KEY, BTN_SELECT); | ||
| 460 | input_set_capability(input, EV_KEY, BTN_MODE); | ||
| 461 | input_set_capability(input, EV_KEY, BTN_START); | ||
| 462 | input_set_capability(input, EV_KEY, BTN_GEAR_DOWN); | ||
| 463 | input_set_capability(input, EV_KEY, BTN_GEAR_UP); | ||
| 464 | input_set_capability(input, EV_KEY, BTN_THUMBR); | ||
| 465 | input_set_capability(input, EV_KEY, BTN_THUMBL); | ||
| 466 | input_set_capability(input, EV_KEY, BTN_THUMB); | ||
| 467 | input_set_capability(input, EV_KEY, BTN_THUMB2); | ||
| 468 | |||
| 469 | input_set_abs_params(input, ABS_HAT2Y, 0, 255, 0, 0); | ||
| 470 | input_set_abs_params(input, ABS_HAT2X, 0, 255, 0, 0); | ||
| 471 | input_set_abs_params(input, ABS_X, -32767, 32767, 0, 0); | ||
| 472 | input_set_abs_params(input, ABS_Y, -32767, 32767, 0, 0); | ||
| 473 | input_set_abs_params(input, ABS_RX, -32767, 32767, | ||
| 474 | STEAM_PAD_FUZZ, 0); | ||
| 475 | input_set_abs_params(input, ABS_RY, -32767, 32767, | ||
| 476 | STEAM_PAD_FUZZ, 0); | ||
| 477 | input_set_abs_params(input, ABS_HAT0X, -32767, 32767, | ||
| 478 | STEAM_PAD_FUZZ, 0); | ||
| 479 | input_set_abs_params(input, ABS_HAT0Y, -32767, 32767, | ||
| 480 | STEAM_PAD_FUZZ, 0); | ||
| 481 | input_abs_set_res(input, ABS_X, STEAM_JOYSTICK_RESOLUTION); | ||
| 482 | input_abs_set_res(input, ABS_Y, STEAM_JOYSTICK_RESOLUTION); | ||
| 483 | input_abs_set_res(input, ABS_RX, STEAM_PAD_RESOLUTION); | ||
| 484 | input_abs_set_res(input, ABS_RY, STEAM_PAD_RESOLUTION); | ||
| 485 | input_abs_set_res(input, ABS_HAT0X, STEAM_PAD_RESOLUTION); | ||
| 486 | input_abs_set_res(input, ABS_HAT0Y, STEAM_PAD_RESOLUTION); | ||
| 487 | input_abs_set_res(input, ABS_HAT2Y, STEAM_TRIGGER_RESOLUTION); | ||
| 488 | input_abs_set_res(input, ABS_HAT2X, STEAM_TRIGGER_RESOLUTION); | ||
| 489 | |||
| 490 | ret = input_register_device(input); | ||
| 491 | if (ret) | ||
| 492 | goto input_register_fail; | ||
| 493 | |||
| 494 | rcu_assign_pointer(steam->input, input); | ||
| 495 | |||
| 496 | /* ignore battery errors, we can live without it */ | ||
| 497 | if (steam->quirks & STEAM_QUIRK_WIRELESS) | ||
| 498 | steam_battery_register(steam); | ||
| 499 | |||
| 500 | return 0; | ||
| 501 | |||
| 502 | input_register_fail: | ||
| 503 | input_free_device(input); | ||
| 504 | return ret; | ||
| 505 | } | ||
| 506 | |||
| 507 | static void steam_unregister(struct steam_device *steam) | ||
| 508 | { | ||
| 509 | struct input_dev *input; | ||
| 510 | struct power_supply *battery; | ||
| 511 | |||
| 512 | rcu_read_lock(); | ||
| 513 | input = rcu_dereference(steam->input); | ||
| 514 | battery = rcu_dereference(steam->battery); | ||
| 515 | rcu_read_unlock(); | ||
| 516 | |||
| 517 | if (battery) { | ||
| 518 | RCU_INIT_POINTER(steam->battery, NULL); | ||
| 519 | synchronize_rcu(); | ||
| 520 | power_supply_unregister(battery); | ||
| 521 | } | ||
| 522 | if (input) { | ||
| 523 | RCU_INIT_POINTER(steam->input, NULL); | ||
| 524 | synchronize_rcu(); | ||
| 525 | hid_info(steam->hdev, "Steam Controller '%s' disconnected", | ||
| 526 | steam->serial_no); | ||
| 527 | input_unregister_device(input); | ||
| 528 | } | ||
| 529 | } | ||
| 530 | |||
| 531 | static void steam_work_connect_cb(struct work_struct *work) | ||
| 532 | { | ||
| 533 | struct steam_device *steam = container_of(work, struct steam_device, | ||
| 534 | work_connect); | ||
| 535 | unsigned long flags; | ||
| 536 | bool connected; | ||
| 537 | int ret; | ||
| 538 | |||
| 539 | spin_lock_irqsave(&steam->lock, flags); | ||
| 540 | connected = steam->connected; | ||
| 541 | spin_unlock_irqrestore(&steam->lock, flags); | ||
| 542 | |||
| 543 | if (connected) { | ||
| 544 | ret = steam_register(steam); | ||
| 545 | if (ret) { | ||
| 546 | hid_err(steam->hdev, | ||
| 547 | "%s:steam_register failed with error %d\n", | ||
| 548 | __func__, ret); | ||
| 549 | } | ||
| 550 | } else { | ||
| 551 | steam_unregister(steam); | ||
| 552 | } | ||
| 553 | } | ||
| 554 | |||
| 555 | static bool steam_is_valve_interface(struct hid_device *hdev) | ||
| 556 | { | ||
| 557 | struct hid_report_enum *rep_enum; | ||
| 558 | |||
| 559 | /* | ||
| 560 | * The wired device creates 3 interfaces: | ||
| 561 | * 0: emulated mouse. | ||
| 562 | * 1: emulated keyboard. | ||
| 563 | * 2: the real game pad. | ||
| 564 | * The wireless device creates 5 interfaces: | ||
| 565 | * 0: emulated keyboard. | ||
| 566 | * 1-4: slots where up to 4 real game pads will be connected to. | ||
| 567 | * We know which one is the real gamepad interface because they are the | ||
| 568 | * only ones with a feature report. | ||
| 569 | */ | ||
| 570 | rep_enum = &hdev->report_enum[HID_FEATURE_REPORT]; | ||
| 571 | return !list_empty(&rep_enum->report_list); | ||
| 572 | } | ||
| 573 | |||
| 574 | static int steam_client_ll_parse(struct hid_device *hdev) | ||
| 575 | { | ||
| 576 | struct steam_device *steam = hid_get_drvdata(hdev); | ||
| 577 | |||
| 578 | return hid_parse_report(hdev, steam->hdev->dev_rdesc, | ||
| 579 | steam->hdev->dev_rsize); | ||
| 580 | } | ||
| 581 | |||
| 582 | static int steam_client_ll_start(struct hid_device *hdev) | ||
| 583 | { | ||
| 584 | return 0; | ||
| 585 | } | ||
| 586 | |||
| 587 | static void steam_client_ll_stop(struct hid_device *hdev) | ||
| 588 | { | ||
| 589 | } | ||
| 590 | |||
| 591 | static int steam_client_ll_open(struct hid_device *hdev) | ||
| 592 | { | ||
| 593 | struct steam_device *steam = hid_get_drvdata(hdev); | ||
| 594 | int ret; | ||
| 595 | |||
| 596 | ret = hid_hw_open(steam->hdev); | ||
| 597 | if (ret) | ||
| 598 | return ret; | ||
| 599 | |||
| 600 | mutex_lock(&steam->mutex); | ||
| 601 | steam->client_opened = true; | ||
| 602 | mutex_unlock(&steam->mutex); | ||
| 603 | return ret; | ||
| 604 | } | ||
| 605 | |||
| 606 | static void steam_client_ll_close(struct hid_device *hdev) | ||
| 607 | { | ||
| 608 | struct steam_device *steam = hid_get_drvdata(hdev); | ||
| 609 | |||
| 610 | mutex_lock(&steam->mutex); | ||
| 611 | steam->client_opened = false; | ||
| 612 | if (steam->input_opened) | ||
| 613 | steam_set_lizard_mode(steam, false); | ||
| 614 | else | ||
| 615 | steam_set_lizard_mode(steam, lizard_mode); | ||
| 616 | mutex_unlock(&steam->mutex); | ||
| 617 | |||
| 618 | hid_hw_close(steam->hdev); | ||
| 619 | } | ||
| 620 | |||
| 621 | static int steam_client_ll_raw_request(struct hid_device *hdev, | ||
| 622 | unsigned char reportnum, u8 *buf, | ||
| 623 | size_t count, unsigned char report_type, | ||
| 624 | int reqtype) | ||
| 625 | { | ||
| 626 | struct steam_device *steam = hid_get_drvdata(hdev); | ||
| 627 | |||
| 628 | return hid_hw_raw_request(steam->hdev, reportnum, buf, count, | ||
| 629 | report_type, reqtype); | ||
| 630 | } | ||
| 631 | |||
| 632 | static struct hid_ll_driver steam_client_ll_driver = { | ||
| 633 | .parse = steam_client_ll_parse, | ||
| 634 | .start = steam_client_ll_start, | ||
| 635 | .stop = steam_client_ll_stop, | ||
| 636 | .open = steam_client_ll_open, | ||
| 637 | .close = steam_client_ll_close, | ||
| 638 | .raw_request = steam_client_ll_raw_request, | ||
| 639 | }; | ||
| 640 | |||
| 641 | static struct hid_device *steam_create_client_hid(struct hid_device *hdev) | ||
| 642 | { | ||
| 643 | struct hid_device *client_hdev; | ||
| 644 | |||
| 645 | client_hdev = hid_allocate_device(); | ||
| 646 | if (IS_ERR(client_hdev)) | ||
| 647 | return client_hdev; | ||
| 648 | |||
| 649 | client_hdev->ll_driver = &steam_client_ll_driver; | ||
| 650 | client_hdev->dev.parent = hdev->dev.parent; | ||
| 651 | client_hdev->bus = hdev->bus; | ||
| 652 | client_hdev->vendor = hdev->vendor; | ||
| 653 | client_hdev->product = hdev->product; | ||
| 654 | client_hdev->version = hdev->version; | ||
| 655 | client_hdev->type = hdev->type; | ||
| 656 | client_hdev->country = hdev->country; | ||
| 657 | strlcpy(client_hdev->name, hdev->name, | ||
| 658 | sizeof(client_hdev->name)); | ||
| 659 | strlcpy(client_hdev->phys, hdev->phys, | ||
| 660 | sizeof(client_hdev->phys)); | ||
| 661 | /* | ||
| 662 | * Since we use the same device info than the real interface to | ||
| 663 | * trick userspace, we will be calling steam_probe recursively. | ||
| 664 | * We need to recognize the client interface somehow. | ||
| 665 | */ | ||
| 666 | client_hdev->group = HID_GROUP_STEAM; | ||
| 667 | return client_hdev; | ||
| 668 | } | ||
| 669 | |||
| 670 | static int steam_probe(struct hid_device *hdev, | ||
| 671 | const struct hid_device_id *id) | ||
| 672 | { | ||
| 673 | struct steam_device *steam; | ||
| 674 | int ret; | ||
| 675 | |||
| 676 | ret = hid_parse(hdev); | ||
| 677 | if (ret) { | ||
| 678 | hid_err(hdev, | ||
| 679 | "%s:parse of hid interface failed\n", __func__); | ||
| 680 | return ret; | ||
| 681 | } | ||
| 682 | |||
| 683 | /* | ||
| 684 | * The virtual client_dev is only used for hidraw. | ||
| 685 | * Also avoid the recursive probe. | ||
| 686 | */ | ||
| 687 | if (hdev->group == HID_GROUP_STEAM) | ||
| 688 | return hid_hw_start(hdev, HID_CONNECT_HIDRAW); | ||
| 689 | /* | ||
| 690 | * The non-valve interfaces (mouse and keyboard emulation) are | ||
| 691 | * connected without changes. | ||
| 692 | */ | ||
| 693 | if (!steam_is_valve_interface(hdev)) | ||
| 694 | return hid_hw_start(hdev, HID_CONNECT_DEFAULT); | ||
| 695 | |||
| 696 | steam = devm_kzalloc(&hdev->dev, sizeof(*steam), GFP_KERNEL); | ||
| 697 | if (!steam) { | ||
| 698 | ret = -ENOMEM; | ||
| 699 | goto steam_alloc_fail; | ||
| 700 | } | ||
| 701 | steam->hdev = hdev; | ||
| 702 | hid_set_drvdata(hdev, steam); | ||
| 703 | spin_lock_init(&steam->lock); | ||
| 704 | mutex_init(&steam->mutex); | ||
| 705 | steam->quirks = id->driver_data; | ||
| 706 | INIT_WORK(&steam->work_connect, steam_work_connect_cb); | ||
| 707 | |||
| 708 | steam->client_hdev = steam_create_client_hid(hdev); | ||
| 709 | if (IS_ERR(steam->client_hdev)) { | ||
| 710 | ret = PTR_ERR(steam->client_hdev); | ||
| 711 | goto client_hdev_fail; | ||
| 712 | } | ||
| 713 | hid_set_drvdata(steam->client_hdev, steam); | ||
| 714 | |||
| 715 | /* | ||
| 716 | * With the real steam controller interface, do not connect hidraw. | ||
| 717 | * Instead, create the client_hid and connect that. | ||
| 718 | */ | ||
| 719 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_HIDRAW); | ||
| 720 | if (ret) | ||
| 721 | goto hid_hw_start_fail; | ||
| 722 | |||
| 723 | ret = hid_add_device(steam->client_hdev); | ||
| 724 | if (ret) | ||
| 725 | goto client_hdev_add_fail; | ||
| 726 | |||
| 727 | if (steam->quirks & STEAM_QUIRK_WIRELESS) { | ||
| 728 | ret = hid_hw_open(hdev); | ||
| 729 | if (ret) { | ||
| 730 | hid_err(hdev, | ||
| 731 | "%s:hid_hw_open for wireless\n", | ||
| 732 | __func__); | ||
| 733 | goto hid_hw_open_fail; | ||
| 734 | } | ||
| 735 | hid_info(hdev, "Steam wireless receiver connected"); | ||
| 736 | steam_request_conn_status(steam); | ||
| 737 | } else { | ||
| 738 | ret = steam_register(steam); | ||
| 739 | if (ret) { | ||
| 740 | hid_err(hdev, | ||
| 741 | "%s:steam_register failed with error %d\n", | ||
| 742 | __func__, ret); | ||
| 743 | goto input_register_fail; | ||
| 744 | } | ||
| 745 | } | ||
| 746 | |||
| 747 | mutex_lock(&steam_devices_lock); | ||
| 748 | steam_update_lizard_mode(steam); | ||
| 749 | list_add(&steam->list, &steam_devices); | ||
| 750 | mutex_unlock(&steam_devices_lock); | ||
| 751 | |||
| 752 | return 0; | ||
| 753 | |||
| 754 | hid_hw_open_fail: | ||
| 755 | input_register_fail: | ||
| 756 | client_hdev_add_fail: | ||
| 757 | hid_hw_stop(hdev); | ||
| 758 | hid_hw_start_fail: | ||
| 759 | hid_destroy_device(steam->client_hdev); | ||
| 760 | client_hdev_fail: | ||
| 761 | cancel_work_sync(&steam->work_connect); | ||
| 762 | steam_alloc_fail: | ||
| 763 | hid_err(hdev, "%s: failed with error %d\n", | ||
| 764 | __func__, ret); | ||
| 765 | return ret; | ||
| 766 | } | ||
| 767 | |||
| 768 | static void steam_remove(struct hid_device *hdev) | ||
| 769 | { | ||
| 770 | struct steam_device *steam = hid_get_drvdata(hdev); | ||
| 771 | |||
| 772 | if (!steam || hdev->group == HID_GROUP_STEAM) { | ||
| 773 | hid_hw_stop(hdev); | ||
| 774 | return; | ||
| 775 | } | ||
| 776 | |||
| 777 | mutex_lock(&steam_devices_lock); | ||
| 778 | list_del(&steam->list); | ||
| 779 | mutex_unlock(&steam_devices_lock); | ||
| 780 | |||
| 781 | hid_destroy_device(steam->client_hdev); | ||
| 782 | steam->client_opened = false; | ||
| 783 | cancel_work_sync(&steam->work_connect); | ||
| 784 | if (steam->quirks & STEAM_QUIRK_WIRELESS) { | ||
| 785 | hid_info(hdev, "Steam wireless receiver disconnected"); | ||
| 786 | hid_hw_close(hdev); | ||
| 787 | } | ||
| 788 | hid_hw_stop(hdev); | ||
| 789 | steam_unregister(steam); | ||
| 790 | } | ||
| 791 | |||
| 792 | static void steam_do_connect_event(struct steam_device *steam, bool connected) | ||
| 793 | { | ||
| 794 | unsigned long flags; | ||
| 795 | |||
| 796 | spin_lock_irqsave(&steam->lock, flags); | ||
| 797 | steam->connected = connected; | ||
| 798 | spin_unlock_irqrestore(&steam->lock, flags); | ||
| 799 | |||
| 800 | if (schedule_work(&steam->work_connect) == 0) | ||
| 801 | dbg_hid("%s: connected=%d event already queued\n", | ||
| 802 | __func__, connected); | ||
| 803 | } | ||
| 804 | |||
| 805 | /* | ||
| 806 | * Some input data in the protocol has the opposite sign. | ||
| 807 | * Clamp the values to 32767..-32767 so that the range is | ||
| 808 | * symmetrical and can be negated safely. | ||
| 809 | */ | ||
| 810 | static inline s16 steam_le16(u8 *data) | ||
| 811 | { | ||
| 812 | s16 x = (s16) le16_to_cpup((__le16 *)data); | ||
| 813 | |||
| 814 | return x == -32768 ? -32767 : x; | ||
| 815 | } | ||
| 816 | |||
| 817 | /* | ||
| 818 | * The size for this message payload is 60. | ||
| 819 | * The known values are: | ||
| 820 | * (* values are not sent through wireless) | ||
| 821 | * (* accelerator/gyro is disabled by default) | ||
| 822 | * Offset| Type | Mapped to |Meaning | ||
| 823 | * -------+-------+-----------+-------------------------- | ||
| 824 | * 4-7 | u32 | -- | sequence number | ||
| 825 | * 8-10 | 24bit | see below | buttons | ||
| 826 | * 11 | u8 | ABS_HAT2Y | left trigger | ||
| 827 | * 12 | u8 | ABS_HAT2X | right trigger | ||
| 828 | * 13-15 | -- | -- | always 0 | ||
| 829 | * 16-17 | s16 | ABS_X/ABS_HAT0X | X value | ||
| 830 | * 18-19 | s16 | ABS_Y/ABS_HAT0Y | Y value | ||
| 831 | * 20-21 | s16 | ABS_RX | right-pad X value | ||
| 832 | * 22-23 | s16 | ABS_RY | right-pad Y value | ||
| 833 | * 24-25 | s16 | -- | * left trigger | ||
| 834 | * 26-27 | s16 | -- | * right trigger | ||
| 835 | * 28-29 | s16 | -- | * accelerometer X value | ||
| 836 | * 30-31 | s16 | -- | * accelerometer Y value | ||
| 837 | * 32-33 | s16 | -- | * accelerometer Z value | ||
| 838 | * 34-35 | s16 | -- | gyro X value | ||
| 839 | * 36-36 | s16 | -- | gyro Y value | ||
| 840 | * 38-39 | s16 | -- | gyro Z value | ||
| 841 | * 40-41 | s16 | -- | quaternion W value | ||
| 842 | * 42-43 | s16 | -- | quaternion X value | ||
| 843 | * 44-45 | s16 | -- | quaternion Y value | ||
| 844 | * 46-47 | s16 | -- | quaternion Z value | ||
| 845 | * 48-49 | -- | -- | always 0 | ||
| 846 | * 50-51 | s16 | -- | * left trigger (uncalibrated) | ||
| 847 | * 52-53 | s16 | -- | * right trigger (uncalibrated) | ||
| 848 | * 54-55 | s16 | -- | * joystick X value (uncalibrated) | ||
| 849 | * 56-57 | s16 | -- | * joystick Y value (uncalibrated) | ||
| 850 | * 58-59 | s16 | -- | * left-pad X value | ||
| 851 | * 60-61 | s16 | -- | * left-pad Y value | ||
| 852 | * 62-63 | u16 | -- | * battery voltage | ||
| 853 | * | ||
| 854 | * The buttons are: | ||
| 855 | * Bit | Mapped to | Description | ||
| 856 | * ------+------------+-------------------------------- | ||
| 857 | * 8.0 | BTN_TR2 | right trigger fully pressed | ||
| 858 | * 8.1 | BTN_TL2 | left trigger fully pressed | ||
| 859 | * 8.2 | BTN_TR | right shoulder | ||
| 860 | * 8.3 | BTN_TL | left shoulder | ||
| 861 | * 8.4 | BTN_Y | button Y | ||
| 862 | * 8.5 | BTN_B | button B | ||
| 863 | * 8.6 | BTN_X | button X | ||
| 864 | * 8.7 | BTN_A | button A | ||
| 865 | * 9.0 | BTN_DPAD_UP | lef-pad up | ||
| 866 | * 9.1 | BTN_DPAD_RIGHT | lef-pad right | ||
| 867 | * 9.2 | BTN_DPAD_LEFT | lef-pad left | ||
| 868 | * 9.3 | BTN_DPAD_DOWN | lef-pad down | ||
| 869 | * 9.4 | BTN_SELECT | menu left | ||
| 870 | * 9.5 | BTN_MODE | steam logo | ||
| 871 | * 9.6 | BTN_START | menu right | ||
| 872 | * 9.7 | BTN_GEAR_DOWN | left back lever | ||
| 873 | * 10.0 | BTN_GEAR_UP | right back lever | ||
| 874 | * 10.1 | -- | left-pad clicked | ||
| 875 | * 10.2 | BTN_THUMBR | right-pad clicked | ||
| 876 | * 10.3 | BTN_THUMB | left-pad touched (but see explanation below) | ||
| 877 | * 10.4 | BTN_THUMB2 | right-pad touched | ||
| 878 | * 10.5 | -- | unknown | ||
| 879 | * 10.6 | BTN_THUMBL | joystick clicked | ||
| 880 | * 10.7 | -- | lpad_and_joy | ||
| 881 | */ | ||
| 882 | |||
| 883 | static void steam_do_input_event(struct steam_device *steam, | ||
| 884 | struct input_dev *input, u8 *data) | ||
| 885 | { | ||
| 886 | /* 24 bits of buttons */ | ||
| 887 | u8 b8, b9, b10; | ||
| 888 | s16 x, y; | ||
| 889 | bool lpad_touched, lpad_and_joy; | ||
| 890 | |||
| 891 | b8 = data[8]; | ||
| 892 | b9 = data[9]; | ||
| 893 | b10 = data[10]; | ||
| 894 | |||
| 895 | input_report_abs(input, ABS_HAT2Y, data[11]); | ||
| 896 | input_report_abs(input, ABS_HAT2X, data[12]); | ||
| 897 | |||
| 898 | /* | ||
| 899 | * These two bits tells how to interpret the values X and Y. | ||
| 900 | * lpad_and_joy tells that the joystick and the lpad are used at the | ||
| 901 | * same time. | ||
| 902 | * lpad_touched tells whether X/Y are to be read as lpad coord or | ||
| 903 | * joystick values. | ||
| 904 | * (lpad_touched || lpad_and_joy) tells if the lpad is really touched. | ||
| 905 | */ | ||
| 906 | lpad_touched = b10 & BIT(3); | ||
| 907 | lpad_and_joy = b10 & BIT(7); | ||
| 908 | x = steam_le16(data + 16); | ||
| 909 | y = -steam_le16(data + 18); | ||
| 910 | |||
| 911 | input_report_abs(input, lpad_touched ? ABS_HAT0X : ABS_X, x); | ||
| 912 | input_report_abs(input, lpad_touched ? ABS_HAT0Y : ABS_Y, y); | ||
| 913 | /* Check if joystick is centered */ | ||
| 914 | if (lpad_touched && !lpad_and_joy) { | ||
| 915 | input_report_abs(input, ABS_X, 0); | ||
| 916 | input_report_abs(input, ABS_Y, 0); | ||
| 917 | } | ||
| 918 | /* Check if lpad is untouched */ | ||
| 919 | if (!(lpad_touched || lpad_and_joy)) { | ||
| 920 | input_report_abs(input, ABS_HAT0X, 0); | ||
| 921 | input_report_abs(input, ABS_HAT0Y, 0); | ||
| 922 | } | ||
| 923 | |||
| 924 | input_report_abs(input, ABS_RX, steam_le16(data + 20)); | ||
| 925 | input_report_abs(input, ABS_RY, -steam_le16(data + 22)); | ||
| 926 | |||
| 927 | input_event(input, EV_KEY, BTN_TR2, !!(b8 & BIT(0))); | ||
| 928 | input_event(input, EV_KEY, BTN_TL2, !!(b8 & BIT(1))); | ||
| 929 | input_event(input, EV_KEY, BTN_TR, !!(b8 & BIT(2))); | ||
| 930 | input_event(input, EV_KEY, BTN_TL, !!(b8 & BIT(3))); | ||
| 931 | input_event(input, EV_KEY, BTN_Y, !!(b8 & BIT(4))); | ||
| 932 | input_event(input, EV_KEY, BTN_B, !!(b8 & BIT(5))); | ||
| 933 | input_event(input, EV_KEY, BTN_X, !!(b8 & BIT(6))); | ||
| 934 | input_event(input, EV_KEY, BTN_A, !!(b8 & BIT(7))); | ||
| 935 | input_event(input, EV_KEY, BTN_SELECT, !!(b9 & BIT(4))); | ||
| 936 | input_event(input, EV_KEY, BTN_MODE, !!(b9 & BIT(5))); | ||
| 937 | input_event(input, EV_KEY, BTN_START, !!(b9 & BIT(6))); | ||
| 938 | input_event(input, EV_KEY, BTN_GEAR_DOWN, !!(b9 & BIT(7))); | ||
| 939 | input_event(input, EV_KEY, BTN_GEAR_UP, !!(b10 & BIT(0))); | ||
| 940 | input_event(input, EV_KEY, BTN_THUMBR, !!(b10 & BIT(2))); | ||
| 941 | input_event(input, EV_KEY, BTN_THUMBL, !!(b10 & BIT(6))); | ||
| 942 | input_event(input, EV_KEY, BTN_THUMB, lpad_touched || lpad_and_joy); | ||
| 943 | input_event(input, EV_KEY, BTN_THUMB2, !!(b10 & BIT(4))); | ||
| 944 | input_event(input, EV_KEY, BTN_DPAD_UP, !!(b9 & BIT(0))); | ||
| 945 | input_event(input, EV_KEY, BTN_DPAD_RIGHT, !!(b9 & BIT(1))); | ||
| 946 | input_event(input, EV_KEY, BTN_DPAD_LEFT, !!(b9 & BIT(2))); | ||
| 947 | input_event(input, EV_KEY, BTN_DPAD_DOWN, !!(b9 & BIT(3))); | ||
| 948 | |||
| 949 | input_sync(input); | ||
| 950 | } | ||
| 951 | |||
| 952 | /* | ||
| 953 | * The size for this message payload is 11. | ||
| 954 | * The known values are: | ||
| 955 | * Offset| Type | Meaning | ||
| 956 | * -------+-------+--------------------------- | ||
| 957 | * 4-7 | u32 | sequence number | ||
| 958 | * 8-11 | -- | always 0 | ||
| 959 | * 12-13 | u16 | voltage (mV) | ||
| 960 | * 14 | u8 | battery percent | ||
| 961 | */ | ||
| 962 | static void steam_do_battery_event(struct steam_device *steam, | ||
| 963 | struct power_supply *battery, u8 *data) | ||
| 964 | { | ||
| 965 | unsigned long flags; | ||
| 966 | |||
| 967 | s16 volts = steam_le16(data + 12); | ||
| 968 | u8 batt = data[14]; | ||
| 969 | |||
| 970 | /* Creating the battery may have failed */ | ||
| 971 | rcu_read_lock(); | ||
| 972 | battery = rcu_dereference(steam->battery); | ||
| 973 | if (likely(battery)) { | ||
| 974 | spin_lock_irqsave(&steam->lock, flags); | ||
| 975 | steam->voltage = volts; | ||
| 976 | steam->battery_charge = batt; | ||
| 977 | spin_unlock_irqrestore(&steam->lock, flags); | ||
| 978 | power_supply_changed(battery); | ||
| 979 | } | ||
| 980 | rcu_read_unlock(); | ||
| 981 | } | ||
| 982 | |||
| 983 | static int steam_raw_event(struct hid_device *hdev, | ||
| 984 | struct hid_report *report, u8 *data, | ||
| 985 | int size) | ||
| 986 | { | ||
| 987 | struct steam_device *steam = hid_get_drvdata(hdev); | ||
| 988 | struct input_dev *input; | ||
| 989 | struct power_supply *battery; | ||
| 990 | |||
| 991 | if (!steam) | ||
| 992 | return 0; | ||
| 993 | |||
| 994 | if (steam->client_opened) | ||
| 995 | hid_input_report(steam->client_hdev, HID_FEATURE_REPORT, | ||
| 996 | data, size, 0); | ||
| 997 | /* | ||
| 998 | * All messages are size=64, all values little-endian. | ||
| 999 | * The format is: | ||
| 1000 | * Offset| Meaning | ||
| 1001 | * -------+-------------------------------------------- | ||
| 1002 | * 0-1 | always 0x01, 0x00, maybe protocol version? | ||
| 1003 | * 2 | type of message | ||
| 1004 | * 3 | length of the real payload (not checked) | ||
| 1005 | * 4-n | payload data, depends on the type | ||
| 1006 | * | ||
| 1007 | * There are these known types of message: | ||
| 1008 | * 0x01: input data (60 bytes) | ||
| 1009 | * 0x03: wireless connect/disconnect (1 byte) | ||
| 1010 | * 0x04: battery status (11 bytes) | ||
| 1011 | */ | ||
| 1012 | |||
| 1013 | if (size != 64 || data[0] != 1 || data[1] != 0) | ||
| 1014 | return 0; | ||
| 1015 | |||
| 1016 | switch (data[2]) { | ||
| 1017 | case STEAM_EV_INPUT_DATA: | ||
| 1018 | if (steam->client_opened) | ||
| 1019 | return 0; | ||
| 1020 | rcu_read_lock(); | ||
| 1021 | input = rcu_dereference(steam->input); | ||
| 1022 | if (likely(input)) { | ||
| 1023 | steam_do_input_event(steam, input, data); | ||
| 1024 | } else { | ||
| 1025 | dbg_hid("%s: input data without connect event\n", | ||
| 1026 | __func__); | ||
| 1027 | steam_do_connect_event(steam, true); | ||
| 1028 | } | ||
| 1029 | rcu_read_unlock(); | ||
| 1030 | break; | ||
| 1031 | case STEAM_EV_CONNECT: | ||
| 1032 | /* | ||
| 1033 | * The payload of this event is a single byte: | ||
| 1034 | * 0x01: disconnected. | ||
| 1035 | * 0x02: connected. | ||
| 1036 | */ | ||
| 1037 | switch (data[4]) { | ||
| 1038 | case 0x01: | ||
| 1039 | steam_do_connect_event(steam, false); | ||
| 1040 | break; | ||
| 1041 | case 0x02: | ||
| 1042 | steam_do_connect_event(steam, true); | ||
| 1043 | break; | ||
| 1044 | } | ||
| 1045 | break; | ||
| 1046 | case STEAM_EV_BATTERY: | ||
| 1047 | if (steam->quirks & STEAM_QUIRK_WIRELESS) { | ||
| 1048 | rcu_read_lock(); | ||
| 1049 | battery = rcu_dereference(steam->battery); | ||
| 1050 | if (likely(battery)) { | ||
| 1051 | steam_do_battery_event(steam, battery, data); | ||
| 1052 | } else { | ||
| 1053 | dbg_hid( | ||
| 1054 | "%s: battery data without connect event\n", | ||
| 1055 | __func__); | ||
| 1056 | steam_do_connect_event(steam, true); | ||
| 1057 | } | ||
| 1058 | rcu_read_unlock(); | ||
| 1059 | } | ||
| 1060 | break; | ||
| 1061 | } | ||
| 1062 | return 0; | ||
| 1063 | } | ||
| 1064 | |||
| 1065 | static int steam_param_set_lizard_mode(const char *val, | ||
| 1066 | const struct kernel_param *kp) | ||
| 1067 | { | ||
| 1068 | struct steam_device *steam; | ||
| 1069 | int ret; | ||
| 1070 | |||
| 1071 | ret = param_set_bool(val, kp); | ||
| 1072 | if (ret) | ||
| 1073 | return ret; | ||
| 1074 | |||
| 1075 | mutex_lock(&steam_devices_lock); | ||
| 1076 | list_for_each_entry(steam, &steam_devices, list) { | ||
| 1077 | steam_update_lizard_mode(steam); | ||
| 1078 | } | ||
| 1079 | mutex_unlock(&steam_devices_lock); | ||
| 1080 | return 0; | ||
| 1081 | } | ||
| 1082 | |||
| 1083 | static const struct kernel_param_ops steam_lizard_mode_ops = { | ||
| 1084 | .set = steam_param_set_lizard_mode, | ||
| 1085 | .get = param_get_bool, | ||
| 1086 | }; | ||
| 1087 | |||
| 1088 | module_param_cb(lizard_mode, &steam_lizard_mode_ops, &lizard_mode, 0644); | ||
| 1089 | MODULE_PARM_DESC(lizard_mode, | ||
| 1090 | "Enable mouse and keyboard emulation (lizard mode) when the gamepad is not in use"); | ||
| 1091 | |||
| 1092 | static const struct hid_device_id steam_controllers[] = { | ||
| 1093 | { /* Wired Steam Controller */ | ||
| 1094 | HID_USB_DEVICE(USB_VENDOR_ID_VALVE, | ||
| 1095 | USB_DEVICE_ID_STEAM_CONTROLLER) | ||
| 1096 | }, | ||
| 1097 | { /* Wireless Steam Controller */ | ||
| 1098 | HID_USB_DEVICE(USB_VENDOR_ID_VALVE, | ||
| 1099 | USB_DEVICE_ID_STEAM_CONTROLLER_WIRELESS), | ||
| 1100 | .driver_data = STEAM_QUIRK_WIRELESS | ||
| 1101 | }, | ||
| 1102 | {} | ||
| 1103 | }; | ||
| 1104 | |||
| 1105 | MODULE_DEVICE_TABLE(hid, steam_controllers); | ||
| 1106 | |||
| 1107 | static struct hid_driver steam_controller_driver = { | ||
| 1108 | .name = "hid-steam", | ||
| 1109 | .id_table = steam_controllers, | ||
| 1110 | .probe = steam_probe, | ||
| 1111 | .remove = steam_remove, | ||
| 1112 | .raw_event = steam_raw_event, | ||
| 1113 | }; | ||
| 1114 | |||
| 1115 | module_hid_driver(steam_controller_driver); | ||
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index cc33622253aa..c1652bb7bd15 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c | |||
| @@ -131,8 +131,6 @@ static const struct i2c_hid_cmd hid_no_cmd = { .length = 0 }; | |||
| 131 | * static const struct i2c_hid_cmd hid_set_protocol_cmd = { I2C_HID_CMD(0x07) }; | 131 | * static const struct i2c_hid_cmd hid_set_protocol_cmd = { I2C_HID_CMD(0x07) }; |
| 132 | */ | 132 | */ |
| 133 | 133 | ||
| 134 | static DEFINE_MUTEX(i2c_hid_open_mut); | ||
| 135 | |||
| 136 | /* The main device structure */ | 134 | /* The main device structure */ |
| 137 | struct i2c_hid { | 135 | struct i2c_hid { |
| 138 | struct i2c_client *client; /* i2c client */ | 136 | struct i2c_client *client; /* i2c client */ |
| @@ -868,6 +866,15 @@ static int i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) | |||
| 868 | } | 866 | } |
| 869 | 867 | ||
| 870 | #ifdef CONFIG_ACPI | 868 | #ifdef CONFIG_ACPI |
| 869 | static const struct acpi_device_id i2c_hid_acpi_blacklist[] = { | ||
| 870 | /* | ||
| 871 | * The CHPN0001 ACPI device, which is used to describe the Chipone | ||
| 872 | * ICN8505 controller, has a _CID of PNP0C50 but is not HID compatible. | ||
| 873 | */ | ||
| 874 | {"CHPN0001", 0 }, | ||
| 875 | { }, | ||
| 876 | }; | ||
| 877 | |||
| 871 | static int i2c_hid_acpi_pdata(struct i2c_client *client, | 878 | static int i2c_hid_acpi_pdata(struct i2c_client *client, |
| 872 | struct i2c_hid_platform_data *pdata) | 879 | struct i2c_hid_platform_data *pdata) |
| 873 | { | 880 | { |
| @@ -879,13 +886,18 @@ static int i2c_hid_acpi_pdata(struct i2c_client *client, | |||
| 879 | acpi_handle handle; | 886 | acpi_handle handle; |
| 880 | 887 | ||
| 881 | handle = ACPI_HANDLE(&client->dev); | 888 | handle = ACPI_HANDLE(&client->dev); |
| 882 | if (!handle || acpi_bus_get_device(handle, &adev)) | 889 | if (!handle || acpi_bus_get_device(handle, &adev)) { |
| 890 | dev_err(&client->dev, "Error could not get ACPI device\n"); | ||
| 891 | return -ENODEV; | ||
| 892 | } | ||
| 893 | |||
| 894 | if (acpi_match_device_ids(adev, i2c_hid_acpi_blacklist) == 0) | ||
| 883 | return -ENODEV; | 895 | return -ENODEV; |
| 884 | 896 | ||
| 885 | obj = acpi_evaluate_dsm_typed(handle, &i2c_hid_guid, 1, 1, NULL, | 897 | obj = acpi_evaluate_dsm_typed(handle, &i2c_hid_guid, 1, 1, NULL, |
| 886 | ACPI_TYPE_INTEGER); | 898 | ACPI_TYPE_INTEGER); |
| 887 | if (!obj) { | 899 | if (!obj) { |
| 888 | dev_err(&client->dev, "device _DSM execution failed\n"); | 900 | dev_err(&client->dev, "Error _DSM call to get HID descriptor address failed\n"); |
| 889 | return -ENODEV; | 901 | return -ENODEV; |
| 890 | } | 902 | } |
| 891 | 903 | ||
| @@ -1000,11 +1012,8 @@ static int i2c_hid_probe(struct i2c_client *client, | |||
| 1000 | goto err; | 1012 | goto err; |
| 1001 | } else if (!platform_data) { | 1013 | } else if (!platform_data) { |
| 1002 | ret = i2c_hid_acpi_pdata(client, &ihid->pdata); | 1014 | ret = i2c_hid_acpi_pdata(client, &ihid->pdata); |
| 1003 | if (ret) { | 1015 | if (ret) |
| 1004 | dev_err(&client->dev, | ||
| 1005 | "HID register address not provided\n"); | ||
| 1006 | goto err; | 1016 | goto err; |
| 1007 | } | ||
| 1008 | } else { | 1017 | } else { |
| 1009 | ihid->pdata = *platform_data; | 1018 | ihid->pdata = *platform_data; |
| 1010 | } | 1019 | } |
| @@ -1054,6 +1063,14 @@ static int i2c_hid_probe(struct i2c_client *client, | |||
| 1054 | pm_runtime_enable(&client->dev); | 1063 | pm_runtime_enable(&client->dev); |
| 1055 | device_enable_async_suspend(&client->dev); | 1064 | device_enable_async_suspend(&client->dev); |
| 1056 | 1065 | ||
| 1066 | /* Make sure there is something at this address */ | ||
| 1067 | ret = i2c_smbus_read_byte(client); | ||
| 1068 | if (ret < 0) { | ||
| 1069 | dev_dbg(&client->dev, "nothing at this address: %d\n", ret); | ||
| 1070 | ret = -ENXIO; | ||
| 1071 | goto err_pm; | ||
| 1072 | } | ||
| 1073 | |||
| 1057 | ret = i2c_hid_fetch_hid_descriptor(ihid); | 1074 | ret = i2c_hid_fetch_hid_descriptor(ihid); |
| 1058 | if (ret < 0) | 1075 | if (ret < 0) |
| 1059 | goto err_pm; | 1076 | goto err_pm; |
diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 5f947ec20dcb..0bb44d0088ed 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c | |||
| @@ -2894,24 +2894,31 @@ static int wacom_bpt_pen(struct wacom_wac *wacom) | |||
| 2894 | struct wacom_features *features = &wacom->features; | 2894 | struct wacom_features *features = &wacom->features; |
| 2895 | struct input_dev *input = wacom->pen_input; | 2895 | struct input_dev *input = wacom->pen_input; |
| 2896 | unsigned char *data = wacom->data; | 2896 | unsigned char *data = wacom->data; |
| 2897 | int prox = 0, x = 0, y = 0, p = 0, d = 0, pen = 0, btn1 = 0, btn2 = 0; | 2897 | int x = 0, y = 0, p = 0, d = 0; |
| 2898 | bool pen = false, btn1 = false, btn2 = false; | ||
| 2899 | bool range, prox, rdy; | ||
| 2898 | 2900 | ||
| 2899 | if (data[0] != WACOM_REPORT_PENABLED) | 2901 | if (data[0] != WACOM_REPORT_PENABLED) |
| 2900 | return 0; | 2902 | return 0; |
| 2901 | 2903 | ||
| 2902 | prox = (data[1] & 0x20) == 0x20; | 2904 | range = (data[1] & 0x80) == 0x80; |
| 2905 | prox = (data[1] & 0x40) == 0x40; | ||
| 2906 | rdy = (data[1] & 0x20) == 0x20; | ||
| 2907 | |||
| 2908 | wacom->shared->stylus_in_proximity = range; | ||
| 2909 | if (delay_pen_events(wacom)) | ||
| 2910 | return 0; | ||
| 2911 | |||
| 2912 | if (rdy) { | ||
| 2913 | p = le16_to_cpup((__le16 *)&data[6]); | ||
| 2914 | pen = data[1] & 0x01; | ||
| 2915 | btn1 = data[1] & 0x02; | ||
| 2916 | btn2 = data[1] & 0x04; | ||
| 2917 | } | ||
| 2918 | if (prox) { | ||
| 2919 | x = le16_to_cpup((__le16 *)&data[2]); | ||
| 2920 | y = le16_to_cpup((__le16 *)&data[4]); | ||
| 2903 | 2921 | ||
| 2904 | /* | ||
| 2905 | * All reports shared between PEN and RUBBER tool must be | ||
| 2906 | * forced to a known starting value (zero) when transitioning to | ||
| 2907 | * out-of-prox. | ||
| 2908 | * | ||
| 2909 | * If not reset then, to userspace, it will look like lost events | ||
| 2910 | * if new tool comes in-prox with same values as previous tool sent. | ||
| 2911 | * | ||
| 2912 | * Hardware does report zero in most out-of-prox cases but not all. | ||
| 2913 | */ | ||
| 2914 | if (!wacom->shared->stylus_in_proximity) { | ||
| 2915 | if (data[1] & 0x08) { | 2922 | if (data[1] & 0x08) { |
| 2916 | wacom->tool[0] = BTN_TOOL_RUBBER; | 2923 | wacom->tool[0] = BTN_TOOL_RUBBER; |
| 2917 | wacom->id[0] = ERASER_DEVICE_ID; | 2924 | wacom->id[0] = ERASER_DEVICE_ID; |
| @@ -2919,16 +2926,9 @@ static int wacom_bpt_pen(struct wacom_wac *wacom) | |||
| 2919 | wacom->tool[0] = BTN_TOOL_PEN; | 2926 | wacom->tool[0] = BTN_TOOL_PEN; |
| 2920 | wacom->id[0] = STYLUS_DEVICE_ID; | 2927 | wacom->id[0] = STYLUS_DEVICE_ID; |
| 2921 | } | 2928 | } |
| 2929 | wacom->reporting_data = true; | ||
| 2922 | } | 2930 | } |
| 2923 | 2931 | if (range) { | |
| 2924 | wacom->shared->stylus_in_proximity = prox; | ||
| 2925 | if (delay_pen_events(wacom)) | ||
| 2926 | return 0; | ||
| 2927 | |||
| 2928 | if (prox) { | ||
| 2929 | x = le16_to_cpup((__le16 *)&data[2]); | ||
| 2930 | y = le16_to_cpup((__le16 *)&data[4]); | ||
| 2931 | p = le16_to_cpup((__le16 *)&data[6]); | ||
| 2932 | /* | 2932 | /* |
| 2933 | * Convert distance from out prox to distance from tablet. | 2933 | * Convert distance from out prox to distance from tablet. |
| 2934 | * distance will be greater than distance_max once | 2934 | * distance will be greater than distance_max once |
| @@ -2937,25 +2937,29 @@ static int wacom_bpt_pen(struct wacom_wac *wacom) | |||
| 2937 | */ | 2937 | */ |
| 2938 | if (data[8] <= features->distance_max) | 2938 | if (data[8] <= features->distance_max) |
| 2939 | d = features->distance_max - data[8]; | 2939 | d = features->distance_max - data[8]; |
| 2940 | |||
| 2941 | pen = data[1] & 0x01; | ||
| 2942 | btn1 = data[1] & 0x02; | ||
| 2943 | btn2 = data[1] & 0x04; | ||
| 2944 | } else { | 2940 | } else { |
| 2945 | wacom->id[0] = 0; | 2941 | wacom->id[0] = 0; |
| 2946 | } | 2942 | } |
| 2947 | 2943 | ||
| 2948 | input_report_key(input, BTN_TOUCH, pen); | 2944 | if (wacom->reporting_data) { |
| 2949 | input_report_key(input, BTN_STYLUS, btn1); | 2945 | input_report_key(input, BTN_TOUCH, pen); |
| 2950 | input_report_key(input, BTN_STYLUS2, btn2); | 2946 | input_report_key(input, BTN_STYLUS, btn1); |
| 2947 | input_report_key(input, BTN_STYLUS2, btn2); | ||
| 2951 | 2948 | ||
| 2952 | input_report_abs(input, ABS_X, x); | 2949 | if (prox || !range) { |
| 2953 | input_report_abs(input, ABS_Y, y); | 2950 | input_report_abs(input, ABS_X, x); |
| 2954 | input_report_abs(input, ABS_PRESSURE, p); | 2951 | input_report_abs(input, ABS_Y, y); |
| 2955 | input_report_abs(input, ABS_DISTANCE, d); | 2952 | } |
| 2953 | input_report_abs(input, ABS_PRESSURE, p); | ||
| 2954 | input_report_abs(input, ABS_DISTANCE, d); | ||
| 2956 | 2955 | ||
| 2957 | input_report_key(input, wacom->tool[0], prox); /* PEN or RUBBER */ | 2956 | input_report_key(input, wacom->tool[0], range); /* PEN or RUBBER */ |
| 2958 | input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */ | 2957 | input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */ |
| 2958 | } | ||
| 2959 | |||
| 2960 | if (!range) { | ||
| 2961 | wacom->reporting_data = false; | ||
| 2962 | } | ||
| 2959 | 2963 | ||
| 2960 | return 1; | 2964 | return 1; |
| 2961 | } | 2965 | } |
diff --git a/include/linux/hid.h b/include/linux/hid.h index 26240a22978a..41a3d5775394 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h | |||
| @@ -292,9 +292,12 @@ struct hid_item { | |||
| 292 | #define HID_DG_CONTACTCOUNT 0x000d0054 | 292 | #define HID_DG_CONTACTCOUNT 0x000d0054 |
| 293 | #define HID_DG_CONTACTMAX 0x000d0055 | 293 | #define HID_DG_CONTACTMAX 0x000d0055 |
| 294 | #define HID_DG_SCANTIME 0x000d0056 | 294 | #define HID_DG_SCANTIME 0x000d0056 |
| 295 | #define HID_DG_SURFACESWITCH 0x000d0057 | ||
| 296 | #define HID_DG_BUTTONSWITCH 0x000d0058 | ||
| 295 | #define HID_DG_BUTTONTYPE 0x000d0059 | 297 | #define HID_DG_BUTTONTYPE 0x000d0059 |
| 296 | #define HID_DG_BARRELSWITCH2 0x000d005a | 298 | #define HID_DG_BARRELSWITCH2 0x000d005a |
| 297 | #define HID_DG_TOOLSERIALNUMBER 0x000d005b | 299 | #define HID_DG_TOOLSERIALNUMBER 0x000d005b |
| 300 | #define HID_DG_LATENCYMODE 0x000d0060 | ||
| 298 | 301 | ||
| 299 | #define HID_VD_ASUS_CUSTOM_MEDIA_KEYS 0xff310076 | 302 | #define HID_VD_ASUS_CUSTOM_MEDIA_KEYS 0xff310076 |
| 300 | /* | 303 | /* |
| @@ -341,10 +344,12 @@ struct hid_item { | |||
| 341 | /* BIT(8) reserved for backward compatibility, was HID_QUIRK_NO_EMPTY_INPUT */ | 344 | /* BIT(8) reserved for backward compatibility, was HID_QUIRK_NO_EMPTY_INPUT */ |
| 342 | /* BIT(9) reserved for backward compatibility, was NO_INIT_INPUT_REPORTS */ | 345 | /* BIT(9) reserved for backward compatibility, was NO_INIT_INPUT_REPORTS */ |
| 343 | #define HID_QUIRK_ALWAYS_POLL BIT(10) | 346 | #define HID_QUIRK_ALWAYS_POLL BIT(10) |
| 347 | #define HID_QUIRK_INPUT_PER_APP BIT(11) | ||
| 344 | #define HID_QUIRK_SKIP_OUTPUT_REPORTS BIT(16) | 348 | #define HID_QUIRK_SKIP_OUTPUT_REPORTS BIT(16) |
| 345 | #define HID_QUIRK_SKIP_OUTPUT_REPORT_ID BIT(17) | 349 | #define HID_QUIRK_SKIP_OUTPUT_REPORT_ID BIT(17) |
| 346 | #define HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP BIT(18) | 350 | #define HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP BIT(18) |
| 347 | #define HID_QUIRK_HAVE_SPECIAL_DRIVER BIT(19) | 351 | #define HID_QUIRK_HAVE_SPECIAL_DRIVER BIT(19) |
| 352 | #define HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE BIT(20) | ||
| 348 | #define HID_QUIRK_FULLSPEED_INTERVAL BIT(28) | 353 | #define HID_QUIRK_FULLSPEED_INTERVAL BIT(28) |
| 349 | #define HID_QUIRK_NO_INIT_REPORTS BIT(29) | 354 | #define HID_QUIRK_NO_INIT_REPORTS BIT(29) |
| 350 | #define HID_QUIRK_NO_IGNORE BIT(30) | 355 | #define HID_QUIRK_NO_IGNORE BIT(30) |
| @@ -367,6 +372,7 @@ struct hid_item { | |||
| 367 | #define HID_GROUP_RMI 0x0100 | 372 | #define HID_GROUP_RMI 0x0100 |
| 368 | #define HID_GROUP_WACOM 0x0101 | 373 | #define HID_GROUP_WACOM 0x0101 |
| 369 | #define HID_GROUP_LOGITECH_DJ_DEVICE 0x0102 | 374 | #define HID_GROUP_LOGITECH_DJ_DEVICE 0x0102 |
| 375 | #define HID_GROUP_STEAM 0x0103 | ||
| 370 | 376 | ||
| 371 | /* | 377 | /* |
| 372 | * HID protocol status | 378 | * HID protocol status |
| @@ -463,8 +469,10 @@ struct hid_field { | |||
| 463 | 469 | ||
| 464 | struct hid_report { | 470 | struct hid_report { |
| 465 | struct list_head list; | 471 | struct list_head list; |
| 466 | unsigned id; /* id of this report */ | 472 | struct list_head hidinput_list; |
| 467 | unsigned type; /* report type */ | 473 | unsigned int id; /* id of this report */ |
| 474 | unsigned int type; /* report type */ | ||
| 475 | unsigned int application; /* application usage for this report */ | ||
| 468 | struct hid_field *field[HID_MAX_FIELDS]; /* fields of the report */ | 476 | struct hid_field *field[HID_MAX_FIELDS]; /* fields of the report */ |
| 469 | unsigned maxfield; /* maximum valid field index */ | 477 | unsigned maxfield; /* maximum valid field index */ |
| 470 | unsigned size; /* size of the report (bits) */ | 478 | unsigned size; /* size of the report (bits) */ |
| @@ -502,12 +510,15 @@ struct hid_output_fifo { | |||
| 502 | 510 | ||
| 503 | #define HID_STAT_ADDED BIT(0) | 511 | #define HID_STAT_ADDED BIT(0) |
| 504 | #define HID_STAT_PARSED BIT(1) | 512 | #define HID_STAT_PARSED BIT(1) |
| 513 | #define HID_STAT_DUP_DETECTED BIT(2) | ||
| 505 | 514 | ||
| 506 | struct hid_input { | 515 | struct hid_input { |
| 507 | struct list_head list; | 516 | struct list_head list; |
| 508 | struct hid_report *report; | 517 | struct hid_report *report; |
| 509 | struct input_dev *input; | 518 | struct input_dev *input; |
| 519 | const char *name; | ||
| 510 | bool registered; | 520 | bool registered; |
| 521 | struct list_head reports; /* the list of reports */ | ||
| 511 | }; | 522 | }; |
| 512 | 523 | ||
| 513 | enum hid_type { | 524 | enum hid_type { |
| @@ -864,7 +875,9 @@ void hid_output_report(struct hid_report *report, __u8 *data); | |||
| 864 | void __hid_request(struct hid_device *hid, struct hid_report *rep, int reqtype); | 875 | void __hid_request(struct hid_device *hid, struct hid_report *rep, int reqtype); |
| 865 | u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags); | 876 | u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags); |
| 866 | struct hid_device *hid_allocate_device(void); | 877 | struct hid_device *hid_allocate_device(void); |
| 867 | struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id); | 878 | struct hid_report *hid_register_report(struct hid_device *device, |
| 879 | unsigned int type, unsigned int id, | ||
| 880 | unsigned int application); | ||
| 868 | int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size); | 881 | int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size); |
| 869 | struct hid_report *hid_validate_values(struct hid_device *hid, | 882 | struct hid_report *hid_validate_values(struct hid_device *hid, |
| 870 | unsigned int type, unsigned int id, | 883 | unsigned int type, unsigned int id, |
