History

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid

Pull HID updates from Jiri Kosina: - support for U2F Zero device, from Andrej Shadura - logitech-dj has historically been treating devices behind non-unifying receivers as generic devices, using the HID emulation in the receiver. That had several shortcomings (special keys handling, battery level monitoring, etc). The driver has been reworked to enumarate (and directly communicate with) the devices behind the receiver, to avoid the (too) generic HID implementation in the receiver itself. All the work done by Benjamin Tissoires and Hans de Goede. - restructuring of intel-ish driver in order to allow for multiple clients of the ISH implementation, from Srinivas Pandruvada - several other smaller fixes and assorted device ID additions * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid: (68 commits) HID: logitech-dj: fix spelling in printk HID: input: fix assignment of .value HID: input: make sure the wheel high resolution multiplier is set HID: logitech-dj: add usbhid dependency in Kconfig HID: logitech-hidpp: add support for HID++ 1.0 consumer keys reports HID: logitech-hidpp: add support for HID++ 1.0 extra mouse buttons reports HID: logitech-hidpp: add support for HID++ 1.0 wheel reports HID: logitech-hidpp: make hidpp10_set_register_bit a bit more generic HID: logitech-hidpp: add input_device ptr to struct hidpp_device HID: logitech-hidpp: do not hardcode very long report length HID: logitech-hidpp: handle devices attached to 27MHz wireless receivers HID: logitech-hidpp: use RAP instead of FAP to get the protocol version HID: logitech-hidpp: remove unused origin_is_hid_core function parameter HID: logitech-hidpp: remove double assignment from __hidpp_send_report HID: logitech-hidpp: do not make failure to get the name fatal HID: logitech-hidpp: ignore very-short or empty names HID: logitech-hidpp: make .probe usbhid capable HID: logitech-hidpp: allow non HID++ devices to be handled by this module HID: logitech-dj: add support for Logitech Bluetooth Mini-Receiver HID: logitech-dj: make appending of the HID++ descriptors conditional ...

Linus Torvalds committed 7 years ago

Commit b4dd05d2 parents 80104bb 63b6f0b29 files · +3518 −690Browse files

Unified · Split

29 files
  1. drivers/hid/Kconfig +27 −0
  2. drivers/hid/Makefile +3 −0
  3. drivers/hid/hid-core.c +39 −14
  4. drivers/hid/hid-ids.h +6 −1
  5. drivers/hid/hid-input.c +50 −31
  6. drivers/hid/hid-lg.c +0 −2
  7. drivers/hid/hid-logitech-dj.c +920 −222
  8. drivers/hid/hid-logitech-hidpp.c +537 −199
  9. drivers/hid/hid-macally.c +45 −0
  10. drivers/hid/hid-picolcd_core.c +6 −12
  11. drivers/hid/hid-quirks.c +0 −6
  12. drivers/hid/hid-sensor-custom.c +4 −8
  13. drivers/hid/hid-u2fzero.c +374 −0
  14. drivers/hid/i2c-hid/i2c-hid-core.c +0 −2
  15. drivers/hid/intel-ish-hid/Kconfig +15 −0
  16. drivers/hid/intel-ish-hid/Makefile +3 −0
  17. drivers/hid/intel-ish-hid/ipc/hw-ish.h +1 −0
  18. drivers/hid/intel-ish-hid/ipc/pci-ish.c +1 −0
  19. drivers/hid/intel-ish-hid/ishtp-fw-loader.c +1085 −0
  20. drivers/hid/intel-ish-hid/ishtp-hid-client.c +92 −76
  21. drivers/hid/intel-ish-hid/ishtp-hid.c +43 −6
  22. drivers/hid/intel-ish-hid/ishtp-hid.h +11 −3
  23. drivers/hid/intel-ish-hid/ishtp/bus.c +92 −4
  24. drivers/hid/intel-ish-hid/ishtp/bus.h +1 −36
  25. drivers/hid/intel-ish-hid/ishtp/client.c +48 −12
  26. drivers/hid/intel-ish-hid/ishtp/client.h +0 −24
  27. drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h +0 −31
  28. include/linux/hid.h +3 −1
  29. include/linux/intel-ish-client-if.h +112 −0
drivers/hid/Kconfig+27−0
@@ -231,6 +231,16 @@ config HID_COUGAR · 230 unmodified lines
231 Supported devices:231 Supported devices:
232 - Cougar 500k Gaming Keyboard232 - Cougar 500k Gaming Keyboard
233 233
234config HID_MACALLY
235 tristate "Macally devices"
236 depends on HID
237 help
238 Support for Macally devices that are not fully compliant with the
239 HID standard.
240
241 supported devices:
242 - Macally ikey keyboard
243
234config HID_PRODIKEYS244config HID_PRODIKEYS
235 tristate "Prodikeys PC-MIDI Keyboard support"245 tristate "Prodikeys PC-MIDI Keyboard support"
236 depends on HID && SND246 depends on HID && SND
@@ -511,6 +521,7 @@ config HID_LOGITECH · 274 unmodified lines
511 521
512config HID_LOGITECH_DJ522config HID_LOGITECH_DJ
513 tristate "Logitech Unifying receivers full support"523 tristate "Logitech Unifying receivers full support"
524 depends on USB_HID
514 depends on HIDRAW525 depends on HIDRAW
515 depends on HID_LOGITECH526 depends on HID_LOGITECH
516 select HID_LOGITECH_HIDPP527 select HID_LOGITECH_HIDPP
@@ -1003,6 +1014,22 @@ config HID_UDRAW_PS3 · 486 unmodified lines
1003 Say Y here if you want to use the THQ uDraw gaming tablet for1014 Say Y here if you want to use the THQ uDraw gaming tablet for
1004 the PS3.1015 the PS3.
1005 1016
1017config HID_U2FZERO
1018 tristate "U2F Zero LED and RNG support"
1019 depends on USB_HID
1020 depends on LEDS_CLASS
1021 depends on HW_RANDOM
1022 help
1023 Support for the LED of the U2F Zero device.
1024
1025 U2F Zero supports custom commands for blinking the LED
1026 and getting data from the internal hardware RNG.
1027 The internal hardware can be used to feed the enthropy pool.
1028
1029 U2F Zero only supports blinking its LED, so this driver doesn't
1030 allow setting the brightness to anything but 1, which will
1031 trigger a single blink and immediately reset to back 0.
1032
1006config HID_WACOM1033config HID_WACOM
1007 tristate "Wacom Intuos/Graphire tablet support (USB)"1034 tristate "Wacom Intuos/Graphire tablet support (USB)"
1008 depends on USB_HID1035 depends on USB_HID
drivers/hid/Makefile+3−0
@@ -65,6 +65,7 @@ obj-$(CONFIG_HID_LENOVO) += hid-lenovo.o · 64 unmodified lines
65obj-$(CONFIG_HID_LOGITECH) += hid-logitech.o65obj-$(CONFIG_HID_LOGITECH) += hid-logitech.o
66obj-$(CONFIG_HID_LOGITECH_DJ) += hid-logitech-dj.o66obj-$(CONFIG_HID_LOGITECH_DJ) += hid-logitech-dj.o
67obj-$(CONFIG_HID_LOGITECH_HIDPP) += hid-logitech-hidpp.o67obj-$(CONFIG_HID_LOGITECH_HIDPP) += hid-logitech-hidpp.o
68obj-$(CONFIG_HID_MACALLY) += hid-macally.o
68obj-$(CONFIG_HID_MAGICMOUSE) += hid-magicmouse.o69obj-$(CONFIG_HID_MAGICMOUSE) += hid-magicmouse.o
69obj-$(CONFIG_HID_MALTRON) += hid-maltron.o70obj-$(CONFIG_HID_MALTRON) += hid-maltron.o
70obj-$(CONFIG_HID_MAYFLASH) += hid-mf.o71obj-$(CONFIG_HID_MAYFLASH) += hid-mf.o
@@ -109,6 +110,7 @@ obj-$(CONFIG_HID_THRUSTMASTER) += hid-tmff.o · 38 unmodified lines
109obj-$(CONFIG_HID_TIVO) += hid-tivo.o110obj-$(CONFIG_HID_TIVO) += hid-tivo.o
110obj-$(CONFIG_HID_TOPSEED) += hid-topseed.o111obj-$(CONFIG_HID_TOPSEED) += hid-topseed.o
111obj-$(CONFIG_HID_TWINHAN) += hid-twinhan.o112obj-$(CONFIG_HID_TWINHAN) += hid-twinhan.o
113obj-$(CONFIG_HID_U2FZERO) += hid-u2fzero.o
112hid-uclogic-objs := hid-uclogic-core.o \114hid-uclogic-objs := hid-uclogic-core.o \
113 hid-uclogic-rdesc.o \115 hid-uclogic-rdesc.o \
114 hid-uclogic-params.o116 hid-uclogic-params.o
@@ -134,3 +136,4 @@ obj-$(CONFIG_USB_KBD) += usbhid/ · 19 unmodified lines
134obj-$(CONFIG_I2C_HID) += i2c-hid/136obj-$(CONFIG_I2C_HID) += i2c-hid/
135 137
136obj-$(CONFIG_INTEL_ISH_HID) += intel-ish-hid/138obj-$(CONFIG_INTEL_ISH_HID) += intel-ish-hid/
139obj-$(INTEL_ISH_FIRMWARE_DOWNLOADER) += intel-ish-hid/
drivers/hid/hid-core.c+39−14
@@ -30,6 +30,7 @@ · 29 unmodified lines
30#include <linux/vmalloc.h>30#include <linux/vmalloc.h>
31#include <linux/sched.h>31#include <linux/sched.h>
32#include <linux/semaphore.h>32#include <linux/semaphore.h>
33#include <linux/async.h>
33 34
34#include <linux/hid.h>35#include <linux/hid.h>
35#include <linux/hiddev.h>36#include <linux/hiddev.h>
@@ -218,13 +219,14 @@ static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type) · 182 unmodified lines
218 * Add a usage to the temporary parser table.219 * Add a usage to the temporary parser table.
219 */220 */
220 221
221static int hid_add_usage(struct hid_parser *parser, unsigned usage)222static int hid_add_usage(struct hid_parser *parser, unsigned usage, u8 size)
222{223{
223 if (parser->local.usage_index >= HID_MAX_USAGES) {224 if (parser->local.usage_index >= HID_MAX_USAGES) {
224 hid_err(parser->device, "usage index exceeded\n");225 hid_err(parser->device, "usage index exceeded\n");
225 return -1;226 return -1;
226 }227 }
227 parser->local.usage[parser->local.usage_index] = usage;228 parser->local.usage[parser->local.usage_index] = usage;
229 parser->local.usage_size[parser->local.usage_index] = size;
228 parser->local.collection_index[parser->local.usage_index] =230 parser->local.collection_index[parser->local.usage_index] =
229 parser->collection_stack_ptr ?231 parser->collection_stack_ptr ?
230 parser->collection_stack[parser->collection_stack_ptr - 1] : 0;232 parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
@@ -486,10 +488,7 @@ static int hid_parser_local(struct hid_parser *parser, struct hid_item *item) · 255 unmodified lines
486 return 0;488 return 0;
487 }489 }
488 490
489 if (item->size <= 2)491 return hid_add_usage(parser, data, item->size);
490 data = (parser->global.usage_page << 16) + data;
491
492 return hid_add_usage(parser, data);
493 492
494 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:493 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
495 494
@@ -498,9 +497,6 @@ static int hid_parser_local(struct hid_parser *parser, struct hid_item *item) · 2 unmodified lines
498 return 0;497 return 0;
499 }498 }
500 499
501 if (item->size <= 2)
502 data = (parser->global.usage_page << 16) + data;
503
504 parser->local.usage_minimum = data;500 parser->local.usage_minimum = data;
505 return 0;501 return 0;
506 502
@@ -511,9 +507,6 @@ static int hid_parser_local(struct hid_parser *parser, struct hid_item *item) · 4 unmodified lines
511 return 0;507 return 0;
512 }508 }
513 509
514 if (item->size <= 2)
515 data = (parser->global.usage_page << 16) + data;
516
517 count = data - parser->local.usage_minimum;510 count = data - parser->local.usage_minimum;
518 if (count + parser->local.usage_index >= HID_MAX_USAGES) {511 if (count + parser->local.usage_index >= HID_MAX_USAGES) {
519 /*512 /*
@@ -533,7 +526,7 @@ static int hid_parser_local(struct hid_parser *parser, struct hid_item *item) · 13 unmodified lines
533 }526 }
534 527
535 for (n = parser->local.usage_minimum; n <= data; n++)528 for (n = parser->local.usage_minimum; n <= data; n++)
536 if (hid_add_usage(parser, n)) {529 if (hid_add_usage(parser, n, item->size)) {
537 dbg_hid("hid_add_usage failed\n");530 dbg_hid("hid_add_usage failed\n");
538 return -1;531 return -1;
539 }532 }
@@ -547,6 +540,22 @@ static int hid_parser_local(struct hid_parser *parser, struct hid_item *item) · 7 unmodified lines
547 return 0;540 return 0;
548}541}
549 542
543/*
544 * Concatenate Usage Pages into Usages where relevant:
545 * As per specification, 6.2.2.8: "When the parser encounters a main item it
546 * concatenates the last declared Usage Page with a Usage to form a complete
547 * usage value."
548 */
549
550static void hid_concatenate_usage_page(struct hid_parser *parser)
551{
552 int i;
553
554 for (i = 0; i < parser->local.usage_index; i++)
555 if (parser->local.usage_size[i] <= 2)
556 parser->local.usage[i] += parser->global.usage_page << 16;
557}
558
550/*559/*
551 * Process a main item.560 * Process a main item.
552 */561 */
@@ -556,6 +565,8 @@ static int hid_parser_main(struct hid_parser *parser, struct hid_item *item) · 3 unmodified lines
556 __u32 data;565 __u32 data;
557 int ret;566 int ret;
558 567
568 hid_concatenate_usage_page(parser);
569
559 data = item_udata(item);570 data = item_udata(item);
560 571
561 switch (item->tag) {572 switch (item->tag) {
@@ -765,6 +776,8 @@ static int hid_scan_main(struct hid_parser *parser, struct hid_item *item) · 203 unmodified lines
765 __u32 data;776 __u32 data;
766 int i;777 int i;
767 778
779 hid_concatenate_usage_page(parser);
780
768 data = item_udata(item);781 data = item_udata(item);
769 782
770 switch (item->tag) {783 switch (item->tag) {
@@ -1624,7 +1637,7 @@ static struct hid_report *hid_get_report(struct hid_report_enum *report_enum, · 853 unmodified lines
1624 * Implement a generic .request() callback, using .raw_request()1637 * Implement a generic .request() callback, using .raw_request()
1625 * DO NOT USE in hid drivers directly, but through hid_hw_request instead.1638 * DO NOT USE in hid drivers directly, but through hid_hw_request instead.
1626 */1639 */
1627void __hid_request(struct hid_device *hid, struct hid_report *report,1640int __hid_request(struct hid_device *hid, struct hid_report *report,
1628 int reqtype)1641 int reqtype)
1629{1642{
1630 char *buf;1643 char *buf;
@@ -1633,7 +1646,7 @@ void __hid_request(struct hid_device *hid, struct hid_report *report, · 2 unmodified lines
1633 1646
1634 buf = hid_alloc_report_buf(report, GFP_KERNEL);1647 buf = hid_alloc_report_buf(report, GFP_KERNEL);
1635 if (!buf)1648 if (!buf)
1636 return;1649 return -ENOMEM;
1637 1650
1638 len = hid_report_len(report);1651 len = hid_report_len(report);
1639 1652
@@ -1650,8 +1663,11 @@ void __hid_request(struct hid_device *hid, struct hid_report *report, · 10 unmodified lines
1650 if (reqtype == HID_REQ_GET_REPORT)1663 if (reqtype == HID_REQ_GET_REPORT)
1651 hid_input_report(hid, report->type, buf, ret, 0);1664 hid_input_report(hid, report->type, buf, ret, 0);
1652 1665
1666 ret = 0;
1667
1653out:1668out:
1654 kfree(buf);1669 kfree(buf);
1670 return ret;
1655}1671}
1656EXPORT_SYMBOL_GPL(__hid_request);1672EXPORT_SYMBOL_GPL(__hid_request);
1657 1673
@@ -2349,6 +2365,15 @@ int hid_add_device(struct hid_device *hdev) · 691 unmodified lines
2349 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,2365 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
2350 hdev->vendor, hdev->product, atomic_inc_return(&id));2366 hdev->vendor, hdev->product, atomic_inc_return(&id));
2351 2367
2368 /*
2369 * Try loading the module for the device before the add, so that we do
2370 * not first have hid-generic binding only to have it replaced
2371 * immediately afterwards with a specialized driver.
2372 */
2373 if (!current_is_async())
2374 request_module("hid:b%04Xg%04Xv%08Xp%08X", hdev->bus,
2375 hdev->group, hdev->vendor, hdev->product);
2376
2352 hid_debug_register(hdev, dev_name(&hdev->dev));2377 hid_debug_register(hdev, dev_name(&hdev->dev));
2353 ret = device_add(&hdev->dev);2378 ret = device_add(&hdev->dev);
2354 if (!ret)2379 if (!ret)
drivers/hid/hid-ids.h+6−1
@@ -323,6 +323,7 @@ · 322 unmodified lines
323#define USB_DEVICE_ID_CYGNAL_RADIO_SI470X 0x818a323#define USB_DEVICE_ID_CYGNAL_RADIO_SI470X 0x818a
324#define USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH 0x81b9324#define USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH 0x81b9
325#define USB_DEVICE_ID_CYGNAL_CP2112 0xea90325#define USB_DEVICE_ID_CYGNAL_CP2112 0xea90
326#define USB_DEVICE_ID_U2F_ZERO 0x8acf
326 327
327#define USB_DEVICE_ID_CYGNAL_RADIO_SI4713 0x8244328#define USB_DEVICE_ID_CYGNAL_RADIO_SI4713 0x8244
328 329
@@ -762,8 +763,12 @@ · 433 unmodified lines
762#define USB_DEVICE_ID_S510_RECEIVER_2 0xc517763#define USB_DEVICE_ID_S510_RECEIVER_2 0xc517
763#define USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500 0xc512764#define USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500 0xc512
764#define USB_DEVICE_ID_MX3000_RECEIVER 0xc513765#define USB_DEVICE_ID_MX3000_RECEIVER 0xc513
766#define USB_DEVICE_ID_LOGITECH_27MHZ_MOUSE_RECEIVER 0xc51b
765#define USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER 0xc52b767#define USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER 0xc52b
768#define USB_DEVICE_ID_LOGITECH_NANO_RECEIVER 0xc52f
766#define USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2 0xc532769#define USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2 0xc532
770#define USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_2 0xc534
771#define USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_GAMING 0xc539
767#define USB_DEVICE_ID_SPACETRAVELLER 0xc623772#define USB_DEVICE_ID_SPACETRAVELLER 0xc623
768#define USB_DEVICE_ID_SPACENAVIGATOR 0xc626773#define USB_DEVICE_ID_SPACENAVIGATOR 0xc626
769#define USB_DEVICE_ID_DINOVO_DESKTOP 0xc704774#define USB_DEVICE_ID_DINOVO_DESKTOP 0xc704
@@ -1034,6 +1039,7 @@ · 264 unmodified lines
1034#define USB_DEVICE_ID_SINO_LITE_CONTROLLER 0x30081039#define USB_DEVICE_ID_SINO_LITE_CONTROLLER 0x3008
1035 1040
1036#define USB_VENDOR_ID_SOLID_YEAR 0x060b1041#define USB_VENDOR_ID_SOLID_YEAR 0x060b
1042#define USB_DEVICE_ID_MACALLY_IKEY_KEYBOARD 0x0001
1037#define USB_DEVICE_ID_COUGAR_500K_GAMING_KEYBOARD 0x500a1043#define USB_DEVICE_ID_COUGAR_500K_GAMING_KEYBOARD 0x500a
1038#define USB_DEVICE_ID_COUGAR_700K_GAMING_KEYBOARD 0x700a1044#define USB_DEVICE_ID_COUGAR_700K_GAMING_KEYBOARD 0x700a
1039 1045
@@ -1083,7 +1089,6 @@ · 43 unmodified lines
1083#define USB_DEVICE_ID_SYNAPTICS_HD 0x0ac31089#define USB_DEVICE_ID_SYNAPTICS_HD 0x0ac3
1084#define USB_DEVICE_ID_SYNAPTICS_QUAD_HD 0x1ac31090#define USB_DEVICE_ID_SYNAPTICS_QUAD_HD 0x1ac3
1085#define USB_DEVICE_ID_SYNAPTICS_TP_V103 0x57101091#define USB_DEVICE_ID_SYNAPTICS_TP_V103 0x5710
1086#define I2C_DEVICE_ID_SYNAPTICS_7E7E 0x7e7e
1087 1092
1088#define USB_VENDOR_ID_TEXAS_INSTRUMENTS 0x20471093#define USB_VENDOR_ID_TEXAS_INSTRUMENTS 0x2047
1089#define USB_DEVICE_ID_TEXAS_INSTRUMENTS_LENOVO_YOGA 0x08551094#define USB_DEVICE_ID_TEXAS_INSTRUMENTS_LENOVO_YOGA 0x0855
drivers/hid/hid-input.c+50−31
@@ -1557,52 +1557,71 @@ static void hidinput_close(struct input_dev *dev) · 1556 unmodified lines
1557 hid_hw_close(hid);1557 hid_hw_close(hid);
1558}1558}
1559 1559
1560static void hidinput_change_resolution_multipliers(struct hid_device *hid)1560static bool __hidinput_change_resolution_multipliers(struct hid_device *hid,
1561 struct hid_report *report, bool use_logical_max)
1561{1562{
1562 struct hid_report_enum *rep_enum;
1563 struct hid_report *rep;
1564 struct hid_usage *usage;1563 struct hid_usage *usage;
1564 bool update_needed = false;
1565 int i, j;1565 int i, j;
1566 1566
1567 rep_enum = &hid->report_enum[HID_FEATURE_REPORT];1567 if (report->maxfield == 0)
1568 list_for_each_entry(rep, &rep_enum->report_list, list) {1568 return false;
1569 bool update_needed = false;
1570 1569
1571 if (rep->maxfield == 0)1570 /*
1572 continue;1571 * If we have more than one feature within this report we
1572 * need to fill in the bits from the others before we can
1573 * overwrite the ones for the Resolution Multiplier.
1574 */
1575 if (report->maxfield > 1) {
1576 hid_hw_request(hid, report, HID_REQ_GET_REPORT);
1577 hid_hw_wait(hid);
1578 }
1573 1579
1574 /*1580 for (i = 0; i < report->maxfield; i++) {
1575 * If we have more than one feature within this report we1581 __s32 value = use_logical_max ?
1576 * need to fill in the bits from the others before we can1582 report->field[i]->logical_maximum :
1577 * overwrite the ones for the Resolution Multiplier.1583 report->field[i]->logical_minimum;
1584
1585 /* There is no good reason for a Resolution
1586 * Multiplier to have a count other than 1.
1587 * Ignore that case.
1578 */1588 */
1579 if (rep->maxfield > 1) {1589 if (report->field[i]->report_count != 1)
1580 hid_hw_request(hid, rep, HID_REQ_GET_REPORT);1590 continue;
1581 hid_hw_wait(hid);
1582 }
1583 1591
1584 for (i = 0; i < rep->maxfield; i++) {1592 for (j = 0; j < report->field[i]->maxusage; j++) {
1585 __s32 logical_max = rep->field[i]->logical_maximum;1593 usage = &report->field[i]->usage[j];
1586 1594
1587 /* There is no good reason for a Resolution1595 if (usage->hid != HID_GD_RESOLUTION_MULTIPLIER)
1588 * Multiplier to have a count other than 1.
1589 * Ignore that case.
1590 */
1591 if (rep->field[i]->report_count != 1)
1592 continue;1596 continue;
1593 1597
1594 for (j = 0; j < rep->field[i]->maxusage; j++) {1598 report->field[i]->value[j] = value;
1595 usage = &rep->field[i]->usage[j];1599 update_needed = true;
1600 }
1601 }
1602
1603 return update_needed;
1604}
1596 1605
1597 if (usage->hid != HID_GD_RESOLUTION_MULTIPLIER)1606static void hidinput_change_resolution_multipliers(struct hid_device *hid)
1598 continue;1607{
1608 struct hid_report_enum *rep_enum;
1609 struct hid_report *rep;
1610 int ret;
1599 1611
1600 *rep->field[i]->value = logical_max;1612 rep_enum = &hid->report_enum[HID_FEATURE_REPORT];
1601 update_needed = true;1613 list_for_each_entry(rep, &rep_enum->report_list, list) {
1614 bool update_needed = __hidinput_change_resolution_multipliers(hid,
1615 rep, true);
1616
1617 if (update_needed) {
1618 ret = __hid_request(hid, rep, HID_REQ_SET_REPORT);
1619 if (ret) {
1620 __hidinput_change_resolution_multipliers(hid,
1621 rep, false);
1622 return;
1602 }1623 }
1603 }1624 }
1604 if (update_needed)
1605 hid_hw_request(hid, rep, HID_REQ_SET_REPORT);
1606 }1625 }
1607 1626
1608 /* refresh our structs */1627 /* refresh our structs */
drivers/hid/hid-lg.c+0−2
@@ -876,8 +876,6 @@ static const struct hid_device_id lg_devices[] = { · 875 unmodified lines
876 .driver_data = LG_RDESC | LG_WIRELESS },876 .driver_data = LG_RDESC | LG_WIRELESS },
877 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER),877 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER),
878 .driver_data = LG_RDESC | LG_WIRELESS },878 .driver_data = LG_RDESC | LG_WIRELESS },
879 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2),
880 .driver_data = LG_RDESC | LG_WIRELESS },
881 879
882 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER),880 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER),
883 .driver_data = LG_BAD_RELATIVE_KEYS },881 .driver_data = LG_BAD_RELATIVE_KEYS },
drivers/hid/hid-logitech-dj.c+920−222
@@ -25,13 +25,14 @@ · 24 unmodified lines
25#include <linux/device.h>25#include <linux/device.h>
26#include <linux/hid.h>26#include <linux/hid.h>
27#include <linux/module.h>27#include <linux/module.h>
28#include <linux/usb.h>
29#include <linux/kfifo.h>28#include <linux/kfifo.h>
29#include <linux/delay.h>
30#include <linux/usb.h> /* For to_usb_interface for kvm extra intf check */
30#include <asm/unaligned.h>31#include <asm/unaligned.h>
31#include "hid-ids.h"32#include "hid-ids.h"
32 33
33#define DJ_MAX_PAIRED_DEVICES 634#define DJ_MAX_PAIRED_DEVICES 6
34#define DJ_MAX_NUMBER_NOTIFICATIONS 835#define DJ_MAX_NUMBER_NOTIFS 8
35#define DJ_RECEIVER_INDEX 036#define DJ_RECEIVER_INDEX 0
36#define DJ_DEVICE_INDEX_MIN 137#define DJ_DEVICE_INDEX_MIN 1
37#define DJ_DEVICE_INDEX_MAX 638#define DJ_DEVICE_INDEX_MAX 6
@@ -74,7 +75,6 @@ · 36 unmodified lines
74/* Device Un-Paired Notification */75/* Device Un-Paired Notification */
75#define REPORT_TYPE_NOTIF_DEVICE_UNPAIRED 0x4076#define REPORT_TYPE_NOTIF_DEVICE_UNPAIRED 0x40
76 77
77
78/* Connection Status Notification */78/* Connection Status Notification */
79#define REPORT_TYPE_NOTIF_CONNECTION_STATUS 0x4279#define REPORT_TYPE_NOTIF_CONNECTION_STATUS 0x42
80#define CONNECTION_STATUS_PARAM_STATUS 0x0080#define CONNECTION_STATUS_PARAM_STATUS 0x00
@@ -94,12 +94,43 @@ · 13 unmodified lines
94#define REPORT_TYPE_LEDS 0x0E94#define REPORT_TYPE_LEDS 0x0E
95 95
96/* RF Report types bitfield */96/* RF Report types bitfield */
97#define STD_KEYBOARD 0x0000000297#define STD_KEYBOARD BIT(1)
98#define STD_MOUSE 0x0000000498#define STD_MOUSE BIT(2)
99#define MULTIMEDIA 0x0000000899#define MULTIMEDIA BIT(3)
100#define POWER_KEYS 0x00000010100#define POWER_KEYS BIT(4)
101#define MEDIA_CENTER 0x00000100101#define MEDIA_CENTER BIT(8)
102#define KBD_LEDS 0x00004000102#define KBD_LEDS BIT(14)
103/* Fake (bitnr > NUMBER_OF_HID_REPORTS) bit to track HID++ capability */
104#define HIDPP BIT_ULL(63)
105
106/* HID++ Device Connected Notification */
107#define REPORT_TYPE_NOTIF_DEVICE_CONNECTED 0x41
108#define HIDPP_PARAM_PROTO_TYPE 0x00
109#define HIDPP_PARAM_DEVICE_INFO 0x01
110#define HIDPP_PARAM_EQUAD_LSB 0x02
111#define HIDPP_PARAM_EQUAD_MSB 0x03
112#define HIDPP_PARAM_27MHZ_DEVID 0x03
113#define HIDPP_DEVICE_TYPE_MASK GENMASK(3, 0)
114#define HIDPP_LINK_STATUS_MASK BIT(6)
115#define HIDPP_MANUFACTURER_MASK BIT(7)
116
117#define HIDPP_DEVICE_TYPE_KEYBOARD 1
118#define HIDPP_DEVICE_TYPE_MOUSE 2
119
120#define HIDPP_SET_REGISTER 0x80
121#define HIDPP_GET_LONG_REGISTER 0x83
122#define HIDPP_REG_CONNECTION_STATE 0x02
123#define HIDPP_REG_PAIRING_INFORMATION 0xB5
124#define HIDPP_PAIRING_INFORMATION 0x20
125#define HIDPP_FAKE_DEVICE_ARRIVAL 0x02
126
127enum recvr_type {
128 recvr_type_dj,
129 recvr_type_hidpp,
130 recvr_type_gaming_hidpp,
131 recvr_type_27mhz,
132 recvr_type_bluetooth,
133};
103 134
104struct dj_report {135struct dj_report {
105 u8 report_id;136 u8 report_id;
@@ -108,23 +139,51 @@ struct dj_report { · 2 unmodified lines
108 u8 report_params[DJREPORT_SHORT_LENGTH - 3];139 u8 report_params[DJREPORT_SHORT_LENGTH - 3];
109};140};
110 141
142struct hidpp_event {
143 u8 report_id;
144 u8 device_index;
145 u8 sub_id;
146 u8 params[HIDPP_REPORT_LONG_LENGTH - 3U];
147} __packed;
148
111struct dj_receiver_dev {149struct dj_receiver_dev {
112 struct hid_device *hdev;150 struct hid_device *mouse;
151 struct hid_device *keyboard;
152 struct hid_device *hidpp;
113 struct dj_device *paired_dj_devices[DJ_MAX_PAIRED_DEVICES +153 struct dj_device *paired_dj_devices[DJ_MAX_PAIRED_DEVICES +
114 DJ_DEVICE_INDEX_MIN];154 DJ_DEVICE_INDEX_MIN];
155 struct list_head list;
156 struct kref kref;
115 struct work_struct work;157 struct work_struct work;
116 struct kfifo notif_fifo;158 struct kfifo notif_fifo;
159 unsigned long last_query; /* in jiffies */
160 bool ready;
161 enum recvr_type type;
162 unsigned int unnumbered_application;
117 spinlock_t lock;163 spinlock_t lock;
118 bool querying_devices;
119};164};
120 165
121struct dj_device {166struct dj_device {
122 struct hid_device *hdev;167 struct hid_device *hdev;
123 struct dj_receiver_dev *dj_receiver_dev;168 struct dj_receiver_dev *dj_receiver_dev;
124 u32 reports_supported;169 u64 reports_supported;
125 u8 device_index;170 u8 device_index;
126};171};
127 172
173#define WORKITEM_TYPE_EMPTY 0
174#define WORKITEM_TYPE_PAIRED 1
175#define WORKITEM_TYPE_UNPAIRED 2
176#define WORKITEM_TYPE_UNKNOWN 255
177
178struct dj_workitem {
179 u8 type; /* WORKITEM_TYPE_* */
180 u8 device_index;
181 u8 device_type;
182 u8 quad_id_msb;
183 u8 quad_id_lsb;
184 u64 reports_supported;
185};
186
128/* Keyboard descriptor (1) */187/* Keyboard descriptor (1) */
129static const char kbd_descriptor[] = {188static const char kbd_descriptor[] = {
130 0x05, 0x01, /* USAGE_PAGE (generic Desktop) */189 0x05, 0x01, /* USAGE_PAGE (generic Desktop) */
@@ -200,6 +259,131 @@ static const char mse_descriptor[] = { · 69 unmodified lines
200 0xC0, /* END_COLLECTION */259 0xC0, /* END_COLLECTION */
201};260};
202 261
262/* Mouse descriptor (2) for 27 MHz receiver, only 8 buttons */
263static const char mse_27mhz_descriptor[] = {
264 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
265 0x09, 0x02, /* USAGE (Mouse) */
266 0xA1, 0x01, /* COLLECTION (Application) */
267 0x85, 0x02, /* REPORT_ID = 2 */
268 0x09, 0x01, /* USAGE (pointer) */
269 0xA1, 0x00, /* COLLECTION (physical) */
270 0x05, 0x09, /* USAGE_PAGE (buttons) */
271 0x19, 0x01, /* USAGE_MIN (1) */
272 0x29, 0x08, /* USAGE_MAX (8) */
273 0x15, 0x00, /* LOGICAL_MIN (0) */
274 0x25, 0x01, /* LOGICAL_MAX (1) */
275 0x95, 0x08, /* REPORT_COUNT (8) */
276 0x75, 0x01, /* REPORT_SIZE (1) */
277 0x81, 0x02, /* INPUT (data var abs) */
278 0x05, 0x01, /* USAGE_PAGE (generic desktop) */
279 0x16, 0x01, 0xF8, /* LOGICAL_MIN (-2047) */
280 0x26, 0xFF, 0x07, /* LOGICAL_MAX (2047) */
281 0x75, 0x0C, /* REPORT_SIZE (12) */
282 0x95, 0x02, /* REPORT_COUNT (2) */
283 0x09, 0x30, /* USAGE (X) */
284 0x09, 0x31, /* USAGE (Y) */
285 0x81, 0x06, /* INPUT */
286 0x15, 0x81, /* LOGICAL_MIN (-127) */
287 0x25, 0x7F, /* LOGICAL_MAX (127) */
288 0x75, 0x08, /* REPORT_SIZE (8) */
289 0x95, 0x01, /* REPORT_COUNT (1) */
290 0x09, 0x38, /* USAGE (wheel) */
291 0x81, 0x06, /* INPUT */
292 0x05, 0x0C, /* USAGE_PAGE(consumer) */
293 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */
294 0x95, 0x01, /* REPORT_COUNT (1) */
295 0x81, 0x06, /* INPUT */
296 0xC0, /* END_COLLECTION */
297 0xC0, /* END_COLLECTION */
298};
299
300/* Mouse descriptor (2) for Bluetooth receiver, low-res hwheel, 12 buttons */
301static const char mse_bluetooth_descriptor[] = {
302 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
303 0x09, 0x02, /* USAGE (Mouse) */
304 0xA1, 0x01, /* COLLECTION (Application) */
305 0x85, 0x02, /* REPORT_ID = 2 */
306 0x09, 0x01, /* USAGE (pointer) */
307 0xA1, 0x00, /* COLLECTION (physical) */
308 0x05, 0x09, /* USAGE_PAGE (buttons) */
309 0x19, 0x01, /* USAGE_MIN (1) */
310 0x29, 0x08, /* USAGE_MAX (8) */
311 0x15, 0x00, /* LOGICAL_MIN (0) */
312 0x25, 0x01, /* LOGICAL_MAX (1) */
313 0x95, 0x08, /* REPORT_COUNT (8) */
314 0x75, 0x01, /* REPORT_SIZE (1) */
315 0x81, 0x02, /* INPUT (data var abs) */
316 0x05, 0x01, /* USAGE_PAGE (generic desktop) */
317 0x16, 0x01, 0xF8, /* LOGICAL_MIN (-2047) */
318 0x26, 0xFF, 0x07, /* LOGICAL_MAX (2047) */
319 0x75, 0x0C, /* REPORT_SIZE (12) */
320 0x95, 0x02, /* REPORT_COUNT (2) */
321 0x09, 0x30, /* USAGE (X) */
322 0x09, 0x31, /* USAGE (Y) */
323 0x81, 0x06, /* INPUT */
324 0x15, 0x81, /* LOGICAL_MIN (-127) */
325 0x25, 0x7F, /* LOGICAL_MAX (127) */
326 0x75, 0x08, /* REPORT_SIZE (8) */
327 0x95, 0x01, /* REPORT_COUNT (1) */
328 0x09, 0x38, /* USAGE (wheel) */
329 0x81, 0x06, /* INPUT */
330 0x05, 0x0C, /* USAGE_PAGE(consumer) */
331 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */
332 0x15, 0xF9, /* LOGICAL_MIN (-7) */
333 0x25, 0x07, /* LOGICAL_MAX (7) */
334 0x75, 0x04, /* REPORT_SIZE (4) */
335 0x95, 0x01, /* REPORT_COUNT (1) */
336 0x81, 0x06, /* INPUT */
337 0x05, 0x09, /* USAGE_PAGE (buttons) */
338 0x19, 0x09, /* USAGE_MIN (9) */
339 0x29, 0x0C, /* USAGE_MAX (12) */
340 0x15, 0x00, /* LOGICAL_MIN (0) */
341 0x25, 0x01, /* LOGICAL_MAX (1) */
342 0x75, 0x01, /* REPORT_SIZE (1) */
343 0x95, 0x04, /* REPORT_COUNT (4) */
344 0x81, 0x06, /* INPUT */
345 0xC0, /* END_COLLECTION */
346 0xC0, /* END_COLLECTION */
347};
348
349/* Gaming Mouse descriptor (2) */
350static const char mse_high_res_descriptor[] = {
351 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
352 0x09, 0x02, /* USAGE (Mouse) */
353 0xA1, 0x01, /* COLLECTION (Application) */
354 0x85, 0x02, /* REPORT_ID = 2 */
355 0x09, 0x01, /* USAGE (pointer) */
356 0xA1, 0x00, /* COLLECTION (physical) */
357 0x05, 0x09, /* USAGE_PAGE (buttons) */
358 0x19, 0x01, /* USAGE_MIN (1) */
359 0x29, 0x10, /* USAGE_MAX (16) */
360 0x15, 0x00, /* LOGICAL_MIN (0) */
361 0x25, 0x01, /* LOGICAL_MAX (1) */
362 0x95, 0x10, /* REPORT_COUNT (16) */
363 0x75, 0x01, /* REPORT_SIZE (1) */
364 0x81, 0x02, /* INPUT (data var abs) */
365 0x05, 0x01, /* USAGE_PAGE (generic desktop) */
366 0x16, 0x01, 0x80, /* LOGICAL_MIN (-32767) */
367 0x26, 0xFF, 0x7F, /* LOGICAL_MAX (32767) */
368 0x75, 0x10, /* REPORT_SIZE (16) */
369 0x95, 0x02, /* REPORT_COUNT (2) */
370 0x09, 0x30, /* USAGE (X) */
371 0x09, 0x31, /* USAGE (Y) */
372 0x81, 0x06, /* INPUT */
373 0x15, 0x81, /* LOGICAL_MIN (-127) */
374 0x25, 0x7F, /* LOGICAL_MAX (127) */
375 0x75, 0x08, /* REPORT_SIZE (8) */
376 0x95, 0x01, /* REPORT_COUNT (1) */
377 0x09, 0x38, /* USAGE (wheel) */
378 0x81, 0x06, /* INPUT */
379 0x05, 0x0C, /* USAGE_PAGE(consumer) */
380 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */
381 0x95, 0x01, /* REPORT_COUNT (1) */
382 0x81, 0x06, /* INPUT */
383 0xC0, /* END_COLLECTION */
384 0xC0, /* END_COLLECTION */
385};
386
203/* Consumer Control descriptor (3) */387/* Consumer Control descriptor (3) */
204static const char consumer_descriptor[] = {388static const char consumer_descriptor[] = {
205 0x05, 0x0C, /* USAGE_PAGE (Consumer Devices) */389 0x05, 0x0C, /* USAGE_PAGE (Consumer Devices) */
@@ -308,7 +492,7 @@ static const char hidpp_descriptor[] = { · 102 unmodified lines
308/* Make sure all descriptors are present here */492/* Make sure all descriptors are present here */
309#define MAX_RDESC_SIZE \493#define MAX_RDESC_SIZE \
310 (sizeof(kbd_descriptor) + \494 (sizeof(kbd_descriptor) + \
311 sizeof(mse_descriptor) + \495 sizeof(mse_bluetooth_descriptor) + \
312 sizeof(consumer_descriptor) + \496 sizeof(consumer_descriptor) + \
313 sizeof(syscontrol_descriptor) + \497 sizeof(syscontrol_descriptor) + \
314 sizeof(media_descriptor) + \498 sizeof(media_descriptor) + \
@@ -341,51 +525,160 @@ static const u8 hid_reportid_size_map[NUMBER_OF_HID_REPORTS] = { · 26 unmodified lines
341static struct hid_ll_driver logi_dj_ll_driver;525static struct hid_ll_driver logi_dj_ll_driver;
342 526
343static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev);527static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev);
528static void delayedwork_callback(struct work_struct *work);
529
530static LIST_HEAD(dj_hdev_list);
531static DEFINE_MUTEX(dj_hdev_list_lock);
532
533/*
534 * dj/HID++ receivers are really a single logical entity, but for BIOS/Windows
535 * compatibility they have multiple USB interfaces. On HID++ receivers we need
536 * to listen for input reports on both interfaces. The functions below are used
537 * to create a single struct dj_receiver_dev for all interfaces belonging to
538 * a single USB-device / receiver.
539 */
540static struct dj_receiver_dev *dj_find_receiver_dev(struct hid_device *hdev,
541 enum recvr_type type)
542{
543 struct dj_receiver_dev *djrcv_dev;
544 char sep;
545
546 /*
547 * The bluetooth receiver contains a built-in hub and has separate
548 * USB-devices for the keyboard and mouse interfaces.
549 */
550 sep = (type == recvr_type_bluetooth) ? '.' : '/';
551
552 /* Try to find an already-probed interface from the same device */
553 list_for_each_entry(djrcv_dev, &dj_hdev_list, list) {
554 if (djrcv_dev->mouse &&
555 hid_compare_device_paths(hdev, djrcv_dev->mouse, sep)) {
556 kref_get(&djrcv_dev->kref);
557 return djrcv_dev;
558 }
559 if (djrcv_dev->keyboard &&
560 hid_compare_device_paths(hdev, djrcv_dev->keyboard, sep)) {
561 kref_get(&djrcv_dev->kref);
562 return djrcv_dev;
563 }
564 if (djrcv_dev->hidpp &&
565 hid_compare_device_paths(hdev, djrcv_dev->hidpp, sep)) {
566 kref_get(&djrcv_dev->kref);
567 return djrcv_dev;
568 }
569 }
570
571 return NULL;
572}
573
574static void dj_release_receiver_dev(struct kref *kref)
575{
576 struct dj_receiver_dev *djrcv_dev = container_of(kref, struct dj_receiver_dev, kref);
577
578 list_del(&djrcv_dev->list);
579 kfifo_free(&djrcv_dev->notif_fifo);
580 kfree(djrcv_dev);
581}
582
583static void dj_put_receiver_dev(struct hid_device *hdev)
584{
585 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
586
587 mutex_lock(&dj_hdev_list_lock);
588
589 if (djrcv_dev->mouse == hdev)
590 djrcv_dev->mouse = NULL;
591 if (djrcv_dev->keyboard == hdev)
592 djrcv_dev->keyboard = NULL;
593 if (djrcv_dev->hidpp == hdev)
594 djrcv_dev->hidpp = NULL;
595
596 kref_put(&djrcv_dev->kref, dj_release_receiver_dev);
597
598 mutex_unlock(&dj_hdev_list_lock);
599}
600
601static struct dj_receiver_dev *dj_get_receiver_dev(struct hid_device *hdev,
602 enum recvr_type type,
603 unsigned int application,
604 bool is_hidpp)
605{
606 struct dj_receiver_dev *djrcv_dev;
607
608 mutex_lock(&dj_hdev_list_lock);
609
610 djrcv_dev = dj_find_receiver_dev(hdev, type);
611 if (!djrcv_dev) {
612 djrcv_dev = kzalloc(sizeof(*djrcv_dev), GFP_KERNEL);
613 if (!djrcv_dev)
614 goto out;
615
616 INIT_WORK(&djrcv_dev->work, delayedwork_callback);
617 spin_lock_init(&djrcv_dev->lock);
618 if (kfifo_alloc(&djrcv_dev->notif_fifo,
619 DJ_MAX_NUMBER_NOTIFS * sizeof(struct dj_workitem),
620 GFP_KERNEL)) {
621 kfree(djrcv_dev);
622 djrcv_dev = NULL;
623 goto out;
624 }
625 kref_init(&djrcv_dev->kref);
626 list_add_tail(&djrcv_dev->list, &dj_hdev_list);
627 djrcv_dev->last_query = jiffies;
628 djrcv_dev->type = type;
629 }
630
631 if (application == HID_GD_KEYBOARD)
632 djrcv_dev->keyboard = hdev;
633 if (application == HID_GD_MOUSE)
634 djrcv_dev->mouse = hdev;
635 if (is_hidpp)
636 djrcv_dev->hidpp = hdev;
637
638 hid_set_drvdata(hdev, djrcv_dev);
639out:
640 mutex_unlock(&dj_hdev_list_lock);
641 return djrcv_dev;
642}
344 643
345static void logi_dj_recv_destroy_djhid_device(struct dj_receiver_dev *djrcv_dev,644static void logi_dj_recv_destroy_djhid_device(struct dj_receiver_dev *djrcv_dev,
346 struct dj_report *dj_report)645 struct dj_workitem *workitem)
347{646{
348 /* Called in delayed work context */647 /* Called in delayed work context */
349 struct dj_device *dj_dev;648 struct dj_device *dj_dev;
350 unsigned long flags;649 unsigned long flags;
351 650
352 spin_lock_irqsave(&djrcv_dev->lock, flags);651 spin_lock_irqsave(&djrcv_dev->lock, flags);
353 dj_dev = djrcv_dev->paired_dj_devices[dj_report->device_index];652 dj_dev = djrcv_dev->paired_dj_devices[workitem->device_index];
354 djrcv_dev->paired_dj_devices[dj_report->device_index] = NULL;653 djrcv_dev->paired_dj_devices[workitem->device_index] = NULL;
355 spin_unlock_irqrestore(&djrcv_dev->lock, flags);654 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
356 655
357 if (dj_dev != NULL) {656 if (dj_dev != NULL) {
358 hid_destroy_device(dj_dev->hdev);657 hid_destroy_device(dj_dev->hdev);
359 kfree(dj_dev);658 kfree(dj_dev);
360 } else {659 } else {
361 dev_err(&djrcv_dev->hdev->dev, "%s: can't destroy a NULL device\n",660 hid_err(djrcv_dev->hidpp, "%s: can't destroy a NULL device\n",
362 __func__);661 __func__);
363 }662 }
364}663}
365 664
366static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev,665static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev,
367 struct dj_report *dj_report)666 struct dj_workitem *workitem)
368{667{
369 /* Called in delayed work context */668 /* Called in delayed work context */
370 struct hid_device *djrcv_hdev = djrcv_dev->hdev;669 struct hid_device *djrcv_hdev = djrcv_dev->hidpp;
371 struct usb_interface *intf = to_usb_interface(djrcv_hdev->dev.parent);
372 struct usb_device *usbdev = interface_to_usbdev(intf);
373 struct hid_device *dj_hiddev;670 struct hid_device *dj_hiddev;
374 struct dj_device *dj_dev;671 struct dj_device *dj_dev;
672 u8 device_index = workitem->device_index;
673 unsigned long flags;
375 674
376 /* Device index goes from 1 to 6, we need 3 bytes to store the675 /* Device index goes from 1 to 6, we need 3 bytes to store the
377 * semicolon, the index, and a null terminator676 * semicolon, the index, and a null terminator
378 */677 */
379 unsigned char tmpstr[3];678 unsigned char tmpstr[3];
380 679
381 if (dj_report->report_params[DEVICE_PAIRED_PARAM_SPFUNCTION] &680 /* We are the only one ever adding a device, no need to lock */
382 SPFUNCTION_DEVICE_LIST_EMPTY) {681 if (djrcv_dev->paired_dj_devices[device_index]) {
383 dbg_hid("%s: device list is empty\n", __func__);
384 djrcv_dev->querying_devices = false;
385 return;
386 }
387
388 if (djrcv_dev->paired_dj_devices[dj_report->device_index]) {
389 /* The device is already known. No need to reallocate it. */682 /* The device is already known. No need to reallocate it. */
390 dbg_hid("%s: device is already known\n", __func__);683 dbg_hid("%s: device is already known\n", __func__);
391 return;684 return;
@@ -393,8 +686,7 @@ static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev, · 1 unmodified line
393 686
394 dj_hiddev = hid_allocate_device();687 dj_hiddev = hid_allocate_device();
395 if (IS_ERR(dj_hiddev)) {688 if (IS_ERR(dj_hiddev)) {
396 dev_err(&djrcv_hdev->dev, "%s: hid_allocate_device failed\n",689 hid_err(djrcv_hdev, "%s: hid_allocate_dev failed\n", __func__);
397 __func__);
398 return;690 return;
399 }691 }
400 692
@@ -402,48 +694,67 @@ static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev, · 1 unmodified line
402 694
403 dj_hiddev->dev.parent = &djrcv_hdev->dev;695 dj_hiddev->dev.parent = &djrcv_hdev->dev;
404 dj_hiddev->bus = BUS_USB;696 dj_hiddev->bus = BUS_USB;
405 dj_hiddev->vendor = le16_to_cpu(usbdev->descriptor.idVendor);697 dj_hiddev->vendor = djrcv_hdev->vendor;
406 dj_hiddev->product =698 dj_hiddev->product = (workitem->quad_id_msb << 8) |
407 (dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_MSB]699 workitem->quad_id_lsb;
408 << 8) |700 if (workitem->device_type) {
409 dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_LSB];701 const char *type_str = "Device";
410 snprintf(dj_hiddev->name, sizeof(dj_hiddev->name),702
411 "Logitech Unifying Device. Wireless PID:%04x",703 switch (workitem->device_type) {
412 dj_hiddev->product);704 case 0x01: type_str = "Keyboard"; break;
413 705 case 0x02: type_str = "Mouse"; break;
414 dj_hiddev->group = HID_GROUP_LOGITECH_DJ_DEVICE;706 case 0x03: type_str = "Numpad"; break;
415 707 case 0x04: type_str = "Presenter"; break;
416 usb_make_path(usbdev, dj_hiddev->phys, sizeof(dj_hiddev->phys));708 case 0x07: type_str = "Remote Control"; break;
417 snprintf(tmpstr, sizeof(tmpstr), ":%d", dj_report->device_index);709 case 0x08: type_str = "Trackball"; break;
710 case 0x09: type_str = "Touchpad"; break;
711 }
712 snprintf(dj_hiddev->name, sizeof(dj_hiddev->name),
713 "Logitech Wireless %s PID:%04x",
714 type_str, dj_hiddev->product);
715 } else {
716 snprintf(dj_hiddev->name, sizeof(dj_hiddev->name),
717 "Logitech Unifying Device. Wireless PID:%04x",
718 dj_hiddev->product);
719 }
720
721 if (djrcv_dev->type == recvr_type_27mhz)
722 dj_hiddev->group = HID_GROUP_LOGITECH_27MHZ_DEVICE;
723 else
724 dj_hiddev->group = HID_GROUP_LOGITECH_DJ_DEVICE;
725
726 memcpy(dj_hiddev->phys, djrcv_hdev->phys, sizeof(djrcv_hdev->phys));
727 snprintf(tmpstr, sizeof(tmpstr), ":%d", device_index);
418 strlcat(dj_hiddev->phys, tmpstr, sizeof(dj_hiddev->phys));728 strlcat(dj_hiddev->phys, tmpstr, sizeof(dj_hiddev->phys));
419 729
420 dj_dev = kzalloc(sizeof(struct dj_device), GFP_KERNEL);730 dj_dev = kzalloc(sizeof(struct dj_device), GFP_KERNEL);
421 731
422 if (!dj_dev) {732 if (!dj_dev) {
423 dev_err(&djrcv_hdev->dev, "%s: failed allocating dj_device\n",733 hid_err(djrcv_hdev, "%s: failed allocating dj_dev\n", __func__);
424 __func__);
425 goto dj_device_allocate_fail;734 goto dj_device_allocate_fail;
426 }735 }
427 736
428 dj_dev->reports_supported = get_unaligned_le32(737 dj_dev->reports_supported = workitem->reports_supported;
429 dj_report->report_params + DEVICE_PAIRED_RF_REPORT_TYPE);
430 dj_dev->hdev = dj_hiddev;738 dj_dev->hdev = dj_hiddev;
431 dj_dev->dj_receiver_dev = djrcv_dev;739 dj_dev->dj_receiver_dev = djrcv_dev;
432 dj_dev->device_index = dj_report->device_index;740 dj_dev->device_index = device_index;
433 dj_hiddev->driver_data = dj_dev;741 dj_hiddev->driver_data = dj_dev;
434 742
435 djrcv_dev->paired_dj_devices[dj_report->device_index] = dj_dev;743 spin_lock_irqsave(&djrcv_dev->lock, flags);
744 djrcv_dev->paired_dj_devices[device_index] = dj_dev;
745 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
436 746
437 if (hid_add_device(dj_hiddev)) {747 if (hid_add_device(dj_hiddev)) {
438 dev_err(&djrcv_hdev->dev, "%s: failed adding dj_device\n",748 hid_err(djrcv_hdev, "%s: failed adding dj_device\n", __func__);
439 __func__);
440 goto hid_add_device_fail;749 goto hid_add_device_fail;
441 }750 }
442 751
443 return;752 return;
444 753
445hid_add_device_fail:754hid_add_device_fail:
446 djrcv_dev->paired_dj_devices[dj_report->device_index] = NULL;755 spin_lock_irqsave(&djrcv_dev->lock, flags);
756 djrcv_dev->paired_dj_devices[device_index] = NULL;
757 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
447 kfree(dj_dev);758 kfree(dj_dev);
448dj_device_allocate_fail:759dj_device_allocate_fail:
449 hid_destroy_device(dj_hiddev);760 hid_destroy_device(dj_hiddev);
@@ -454,7 +765,7 @@ static void delayedwork_callback(struct work_struct *work) · 4 unmodified lines
454 struct dj_receiver_dev *djrcv_dev =765 struct dj_receiver_dev *djrcv_dev =
455 container_of(work, struct dj_receiver_dev, work);766 container_of(work, struct dj_receiver_dev, work);
456 767
457 struct dj_report dj_report;768 struct dj_workitem workitem;
458 unsigned long flags;769 unsigned long flags;
459 int count;770 int count;
460 int retval;771 int retval;
@@ -463,69 +774,231 @@ static void delayedwork_callback(struct work_struct *work) · 2 unmodified lines
463 774
464 spin_lock_irqsave(&djrcv_dev->lock, flags);775 spin_lock_irqsave(&djrcv_dev->lock, flags);
465 776
466 count = kfifo_out(&djrcv_dev->notif_fifo, &dj_report,777 /*
467 sizeof(struct dj_report));778 * Since we attach to multiple interfaces, we may get scheduled before
468 779 * we are bound to the HID++ interface, catch this.
469 if (count != sizeof(struct dj_report)) {780 */
470 dev_err(&djrcv_dev->hdev->dev, "%s: workitem triggered without "781 if (!djrcv_dev->ready) {
471 "notifications available\n", __func__);782 pr_warn("%s: delayedwork queued before hidpp interface was enumerated\n",
783 __func__);
472 spin_unlock_irqrestore(&djrcv_dev->lock, flags);784 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
473 return;785 return;
474 }786 }
475 787
476 if (!kfifo_is_empty(&djrcv_dev->notif_fifo)) {788 count = kfifo_out(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
477 if (schedule_work(&djrcv_dev->work) == 0) {789
478 dbg_hid("%s: did not schedule the work item, was "790 if (count != sizeof(workitem)) {
479 "already queued\n", __func__);791 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
480 }792 return;
481 }793 }
482 794
795 if (!kfifo_is_empty(&djrcv_dev->notif_fifo))
796 schedule_work(&djrcv_dev->work);
797
483 spin_unlock_irqrestore(&djrcv_dev->lock, flags);798 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
484 799
485 switch (dj_report.report_type) {800 switch (workitem.type) {
486 case REPORT_TYPE_NOTIF_DEVICE_PAIRED:801 case WORKITEM_TYPE_PAIRED:
487 logi_dj_recv_add_djhid_device(djrcv_dev, &dj_report);802 logi_dj_recv_add_djhid_device(djrcv_dev, &workitem);
488 break;803 break;
489 case REPORT_TYPE_NOTIF_DEVICE_UNPAIRED:804 case WORKITEM_TYPE_UNPAIRED:
490 logi_dj_recv_destroy_djhid_device(djrcv_dev, &dj_report);805 logi_dj_recv_destroy_djhid_device(djrcv_dev, &workitem);
491 break;806 break;
492 default:807 case WORKITEM_TYPE_UNKNOWN:
493 /* A normal report (i. e. not belonging to a pair/unpair notification)
494 * arriving here, means that the report arrived but we did not have a
495 * paired dj_device associated to the report's device_index, this
496 * means that the original "device paired" notification corresponding
497 * to this dj_device never arrived to this driver. The reason is that
498 * hid-core discards all packets coming from a device while probe() is
499 * executing. */
500 if (!djrcv_dev->paired_dj_devices[dj_report.device_index]) {
501 /* ok, we don't know the device, just re-ask the
502 * receiver for the list of connected devices. */
503 retval = logi_dj_recv_query_paired_devices(djrcv_dev);808 retval = logi_dj_recv_query_paired_devices(djrcv_dev);
504 if (!retval) {809 if (retval) {
505 /* everything went fine, so just leave */810 hid_err(djrcv_dev->hidpp, "%s: logi_dj_recv_query_paired_devices error: %d\n",
506 break;811 __func__, retval);
507 }
508 dev_err(&djrcv_dev->hdev->dev,
509 "%s:logi_dj_recv_query_paired_devices "
510 "error:%d\n", __func__, retval);
511 }812 }
512 dbg_hid("%s: unexpected report type\n", __func__);813 break;
814 case WORKITEM_TYPE_EMPTY:
815 dbg_hid("%s: device list is empty\n", __func__);
816 break;
513 }817 }
514}818}
515 819
820/*
821 * Sometimes we receive reports for which we do not have a paired dj_device
822 * associated with the device_index or report-type to forward the report to.
823 * This means that the original "device paired" notification corresponding
824 * to the dj_device never arrived to this driver. Possible reasons for this are:
825 * 1) hid-core discards all packets coming from a device during probe().
826 * 2) if the receiver is plugged into a KVM switch then the pairing reports
827 * are only forwarded to it if the focus is on this PC.
828 * This function deals with this by re-asking the receiver for the list of
829 * connected devices in the delayed work callback.
830 * This function MUST be called with djrcv->lock held.
831 */
832static void logi_dj_recv_queue_unknown_work(struct dj_receiver_dev *djrcv_dev)
833{
834 struct dj_workitem workitem = { .type = WORKITEM_TYPE_UNKNOWN };
835
836 /* Rate limit queries done because of unhandeled reports to 2/sec */
837 if (time_before(jiffies, djrcv_dev->last_query + HZ / 2))
838 return;
839
840 kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
841 schedule_work(&djrcv_dev->work);
842}
843
516static void logi_dj_recv_queue_notification(struct dj_receiver_dev *djrcv_dev,844static void logi_dj_recv_queue_notification(struct dj_receiver_dev *djrcv_dev,
517 struct dj_report *dj_report)845 struct dj_report *dj_report)
518{846{
519 /* We are called from atomic context (tasklet && djrcv->lock held) */847 /* We are called from atomic context (tasklet && djrcv->lock held) */
848 struct dj_workitem workitem = {
849 .device_index = dj_report->device_index,
850 };
851
852 switch (dj_report->report_type) {
853 case REPORT_TYPE_NOTIF_DEVICE_PAIRED:
854 workitem.type = WORKITEM_TYPE_PAIRED;
855 if (dj_report->report_params[DEVICE_PAIRED_PARAM_SPFUNCTION] &
856 SPFUNCTION_DEVICE_LIST_EMPTY) {
857 workitem.type = WORKITEM_TYPE_EMPTY;
858 break;
859 }
860 /* fall-through */
861 case REPORT_TYPE_NOTIF_DEVICE_UNPAIRED:
862 workitem.quad_id_msb =
863 dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_MSB];
864 workitem.quad_id_lsb =
865 dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_LSB];
866 workitem.reports_supported = get_unaligned_le32(
867 dj_report->report_params +
868 DEVICE_PAIRED_RF_REPORT_TYPE);
869 workitem.reports_supported |= HIDPP;
870 if (dj_report->report_type == REPORT_TYPE_NOTIF_DEVICE_UNPAIRED)
871 workitem.type = WORKITEM_TYPE_UNPAIRED;
872 break;
873 default:
874 logi_dj_recv_queue_unknown_work(djrcv_dev);
875 return;
876 }
520 877
521 kfifo_in(&djrcv_dev->notif_fifo, dj_report, sizeof(struct dj_report));878 kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
879 schedule_work(&djrcv_dev->work);
880}
522 881
523 if (schedule_work(&djrcv_dev->work) == 0) {882static void logi_hidpp_dev_conn_notif_equad(struct hidpp_event *hidpp_report,
524 dbg_hid("%s: did not schedule the work item, was already "883 struct dj_workitem *workitem)
525 "queued\n", __func__);884{
885 workitem->type = WORKITEM_TYPE_PAIRED;
886 workitem->device_type = hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] &
887 HIDPP_DEVICE_TYPE_MASK;
888 workitem->quad_id_msb = hidpp_report->params[HIDPP_PARAM_EQUAD_MSB];
889 workitem->quad_id_lsb = hidpp_report->params[HIDPP_PARAM_EQUAD_LSB];
890 switch (workitem->device_type) {
891 case REPORT_TYPE_KEYBOARD:
892 workitem->reports_supported |= STD_KEYBOARD | MULTIMEDIA |
893 POWER_KEYS | MEDIA_CENTER |
894 HIDPP;
895 break;
896 case REPORT_TYPE_MOUSE:
897 workitem->reports_supported |= STD_MOUSE | HIDPP;
898 break;
899 }
900}
901
902static void logi_hidpp_dev_conn_notif_27mhz(struct hid_device *hdev,
903 struct hidpp_event *hidpp_report,
904 struct dj_workitem *workitem)
905{
906 workitem->type = WORKITEM_TYPE_PAIRED;
907 workitem->quad_id_lsb = hidpp_report->params[HIDPP_PARAM_27MHZ_DEVID];
908 switch (hidpp_report->device_index) {
909 case 1: /* Index 1 is always a mouse */
910 case 2: /* Index 2 is always a mouse */
911 workitem->device_type = HIDPP_DEVICE_TYPE_MOUSE;
912 workitem->reports_supported |= STD_MOUSE | HIDPP;
913 break;
914 case 3: /* Index 3 is always the keyboard */
915 case 4: /* Index 4 is used for an optional separate numpad */
916 workitem->device_type = HIDPP_DEVICE_TYPE_KEYBOARD;
917 workitem->reports_supported |= STD_KEYBOARD | MULTIMEDIA |
918 POWER_KEYS | HIDPP;
919 break;
920 default:
921 hid_warn(hdev, "%s: unexpected device-index %d", __func__,
922 hidpp_report->device_index);
526 }923 }
527}924}
528 925
926static void logi_hidpp_recv_queue_notif(struct hid_device *hdev,
927 struct hidpp_event *hidpp_report)
928{
929 /* We are called from atomic context (tasklet && djrcv->lock held) */
930 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
931 const char *device_type = "UNKNOWN";
932 struct dj_workitem workitem = {
933 .type = WORKITEM_TYPE_EMPTY,
934 .device_index = hidpp_report->device_index,
935 };
936
937 switch (hidpp_report->params[HIDPP_PARAM_PROTO_TYPE]) {
938 case 0x01:
939 device_type = "Bluetooth";
940 /* Bluetooth connect packet contents is the same as (e)QUAD */
941 logi_hidpp_dev_conn_notif_equad(hidpp_report, &workitem);
942 if (!(hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] &
943 HIDPP_MANUFACTURER_MASK)) {
944 hid_info(hdev, "Non Logitech device connected on slot %d\n",
945 hidpp_report->device_index);
946 workitem.reports_supported &= ~HIDPP;
947 }
948 break;
949 case 0x02:
950 device_type = "27 Mhz";
951 logi_hidpp_dev_conn_notif_27mhz(hdev, hidpp_report, &workitem);
952 break;
953 case 0x03:
954 device_type = "QUAD or eQUAD";
955 logi_hidpp_dev_conn_notif_equad(hidpp_report, &workitem);
956 break;
957 case 0x04:
958 device_type = "eQUAD step 4 DJ";
959 logi_hidpp_dev_conn_notif_equad(hidpp_report, &workitem);
960 break;
961 case 0x05:
962 device_type = "DFU Lite";
963 break;
964 case 0x06:
965 device_type = "eQUAD step 4 Lite";
966 logi_hidpp_dev_conn_notif_equad(hidpp_report, &workitem);
967 break;
968 case 0x07:
969 device_type = "eQUAD step 4 Gaming";
970 break;
971 case 0x08:
972 device_type = "eQUAD step 4 for gamepads";
973 break;
974 case 0x0a:
975 device_type = "eQUAD nano Lite";
976 logi_hidpp_dev_conn_notif_equad(hidpp_report, &workitem);
977 break;
978 case 0x0c:
979 device_type = "eQUAD Lightspeed";
980 logi_hidpp_dev_conn_notif_equad(hidpp_report, &workitem);
981 workitem.reports_supported |= STD_KEYBOARD;
982 break;
983 }
984
985 if (workitem.type == WORKITEM_TYPE_EMPTY) {
986 hid_warn(hdev,
987 "unusable device of type %s (0x%02x) connected on slot %d",
988 device_type,
989 hidpp_report->params[HIDPP_PARAM_PROTO_TYPE],
990 hidpp_report->device_index);
991 return;
992 }
993
994 hid_info(hdev, "device of type %s (0x%02x) connected on slot %d",
995 device_type, hidpp_report->params[HIDPP_PARAM_PROTO_TYPE],
996 hidpp_report->device_index);
997
998 kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
999 schedule_work(&djrcv_dev->work);
1000}
1001
529static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev,1002static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev,
530 struct dj_report *dj_report)1003 struct dj_report *dj_report)
531{1004{
@@ -552,8 +1025,8 @@ static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev, · 20 unmodified lines
552 }1025 }
553}1026}
554 1027
555static void logi_dj_recv_forward_report(struct dj_receiver_dev *djrcv_dev,1028static void logi_dj_recv_forward_dj(struct dj_receiver_dev *djrcv_dev,
556 struct dj_report *dj_report)1029 struct dj_report *dj_report)
557{1030{
558 /* We are called from atomic context (tasklet && djrcv->lock held) */1031 /* We are called from atomic context (tasklet && djrcv->lock held) */
559 struct dj_device *dj_device;1032 struct dj_device *dj_device;
@@ -573,18 +1046,48 @@ static void logi_dj_recv_forward_report(struct dj_receiver_dev *djrcv_dev, · 13 unmodified lines
573 }1046 }
574}1047}
575 1048
576static void logi_dj_recv_forward_hidpp(struct dj_device *dj_dev, u8 *data,1049static void logi_dj_recv_forward_report(struct dj_device *dj_dev, u8 *data,
577 int size)1050 int size)
578{1051{
579 /* We are called from atomic context (tasklet && djrcv->lock held) */1052 /* We are called from atomic context (tasklet && djrcv->lock held) */
580 if (hid_input_report(dj_dev->hdev, HID_INPUT_REPORT, data, size, 1))1053 if (hid_input_report(dj_dev->hdev, HID_INPUT_REPORT, data, size, 1))
581 dbg_hid("hid_input_report error\n");1054 dbg_hid("hid_input_report error\n");
582}1055}
583 1056
1057static void logi_dj_recv_forward_input_report(struct hid_device *hdev,
1058 u8 *data, int size)
1059{
1060 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1061 struct dj_device *dj_dev;
1062 unsigned long flags;
1063 u8 report = data[0];
1064 int i;
1065
1066 if (report > REPORT_TYPE_RFREPORT_LAST) {
1067 hid_err(hdev, "Unexpected input report number %d\n", report);
1068 return;
1069 }
1070
1071 spin_lock_irqsave(&djrcv_dev->lock, flags);
1072 for (i = 0; i < (DJ_MAX_PAIRED_DEVICES + DJ_DEVICE_INDEX_MIN); i++) {
1073 dj_dev = djrcv_dev->paired_dj_devices[i];
1074 if (dj_dev && (dj_dev->reports_supported & BIT(report))) {
1075 logi_dj_recv_forward_report(dj_dev, data, size);
1076 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1077 return;
1078 }
1079 }
1080
1081 logi_dj_recv_queue_unknown_work(djrcv_dev);
1082 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1083
1084 dbg_hid("No dj-devs handling input report number %d\n", report);
1085}
1086
584static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,1087static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
585 struct dj_report *dj_report)1088 struct dj_report *dj_report)
586{1089{
587 struct hid_device *hdev = djrcv_dev->hdev;1090 struct hid_device *hdev = djrcv_dev->hidpp;
588 struct hid_report *report;1091 struct hid_report *report;
589 struct hid_report_enum *output_report_enum;1092 struct hid_report_enum *output_report_enum;
590 u8 *data = (u8 *)(&dj_report->device_index);1093 u8 *data = (u8 *)(&dj_report->device_index);
@@ -594,7 +1097,7 @@ static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev, · 3 unmodified lines
594 report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT];1097 report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT];
595 1098
596 if (!report) {1099 if (!report) {
597 dev_err(&hdev->dev, "%s: unable to find dj report\n", __func__);1100 hid_err(hdev, "%s: unable to find dj report\n", __func__);
598 return -ENODEV;1101 return -ENODEV;
599 }1102 }
600 1103
@@ -606,14 +1109,40 @@ static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev, · 5 unmodified lines
606 return 0;1109 return 0;
607}1110}
608 1111
1112static int logi_dj_recv_query_hidpp_devices(struct dj_receiver_dev *djrcv_dev)
1113{
1114 const u8 template[] = {REPORT_ID_HIDPP_SHORT,
1115 HIDPP_RECEIVER_INDEX,
1116 HIDPP_SET_REGISTER,
1117 HIDPP_REG_CONNECTION_STATE,
1118 HIDPP_FAKE_DEVICE_ARRIVAL,
1119 0x00, 0x00};
1120 u8 *hidpp_report;
1121 int retval;
1122
1123 hidpp_report = kmemdup(template, sizeof(template), GFP_KERNEL);
1124 if (!hidpp_report)
1125 return -ENOMEM;
1126
1127 retval = hid_hw_raw_request(djrcv_dev->hidpp,
1128 REPORT_ID_HIDPP_SHORT,
1129 hidpp_report, sizeof(template),
1130 HID_OUTPUT_REPORT,
1131 HID_REQ_SET_REPORT);
1132
1133 kfree(hidpp_report);
1134 return 0;
1135}
1136
609static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev)1137static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev)
610{1138{
611 struct dj_report *dj_report;1139 struct dj_report *dj_report;
612 int retval;1140 int retval;
613 1141
614 /* no need to protect djrcv_dev->querying_devices */1142 djrcv_dev->last_query = jiffies;
615 if (djrcv_dev->querying_devices)1143
616 return 0;1144 if (djrcv_dev->type != recvr_type_dj)
1145 return logi_dj_recv_query_hidpp_devices(djrcv_dev);
617 1146
618 dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL);1147 dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL);
619 if (!dj_report)1148 if (!dj_report)
@@ -630,27 +1159,33 @@ static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev) · 10 unmodified lines
630static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev,1159static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev,
631 unsigned timeout)1160 unsigned timeout)
632{1161{
633 struct hid_device *hdev = djrcv_dev->hdev;1162 struct hid_device *hdev = djrcv_dev->hidpp;
634 struct dj_report *dj_report;1163 struct dj_report *dj_report;
635 u8 *buf;1164 u8 *buf;
636 int retval;1165 int retval = 0;
637 1166
638 dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL);1167 dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL);
639 if (!dj_report)1168 if (!dj_report)
640 return -ENOMEM;1169 return -ENOMEM;
641 dj_report->report_id = REPORT_ID_DJ_SHORT;
642 dj_report->device_index = 0xFF;
643 dj_report->report_type = REPORT_TYPE_CMD_SWITCH;
644 dj_report->report_params[CMD_SWITCH_PARAM_DEVBITFIELD] = 0x3F;
645 dj_report->report_params[CMD_SWITCH_PARAM_TIMEOUT_SECONDS] = (u8)timeout;
646 retval = logi_dj_recv_send_report(djrcv_dev, dj_report);
647 1170
648 /*1171 if (djrcv_dev->type == recvr_type_dj) {
649 * Ugly sleep to work around a USB 3.0 bug when the receiver is still1172 dj_report->report_id = REPORT_ID_DJ_SHORT;
650 * processing the "switch-to-dj" command while we send an other command.1173 dj_report->device_index = 0xFF;
651 * 50 msec should gives enough time to the receiver to be ready.1174 dj_report->report_type = REPORT_TYPE_CMD_SWITCH;
652 */1175 dj_report->report_params[CMD_SWITCH_PARAM_DEVBITFIELD] = 0x3F;
653 msleep(50);1176 dj_report->report_params[CMD_SWITCH_PARAM_TIMEOUT_SECONDS] =
1177 (u8)timeout;
1178
1179 retval = logi_dj_recv_send_report(djrcv_dev, dj_report);
1180
1181 /*
1182 * Ugly sleep to work around a USB 3.0 bug when the receiver is
1183 * still processing the "switch-to-dj" command while we send an
1184 * other command.
1185 * 50 msec should gives enough time to the receiver to be ready.
1186 */
1187 msleep(50);
1188 }
654 1189
655 /*1190 /*
656 * Magical bits to set up hidpp notifications when the dj devices1191 * Magical bits to set up hidpp notifications when the dj devices
@@ -682,22 +1217,28 @@ static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev, · 25 unmodified lines
682 1217
683static int logi_dj_ll_open(struct hid_device *hid)1218static int logi_dj_ll_open(struct hid_device *hid)
684{1219{
685 dbg_hid("%s:%s\n", __func__, hid->phys);1220 dbg_hid("%s: %s\n", __func__, hid->phys);
686 return 0;1221 return 0;
687 1222
688}1223}
689 1224
690static void logi_dj_ll_close(struct hid_device *hid)1225static void logi_dj_ll_close(struct hid_device *hid)
691{1226{
692 dbg_hid("%s:%s\n", __func__, hid->phys);1227 dbg_hid("%s: %s\n", __func__, hid->phys);
693}1228}
694 1229
695/*1230/*
696 * Register 0xB5 is "pairing information". It is solely intended for the1231 * Register 0xB5 is "pairing information". It is solely intended for the
697 * receiver, so do not overwrite the device index.1232 * receiver, so do not overwrite the device index.
698 */1233 */
699static u8 unifying_pairing_query[] = {0x10, 0xff, 0x83, 0xb5};1234static u8 unifying_pairing_query[] = { REPORT_ID_HIDPP_SHORT,
700static u8 unifying_pairing_answer[] = {0x11, 0xff, 0x83, 0xb5};1235 HIDPP_RECEIVER_INDEX,
1236 HIDPP_GET_LONG_REGISTER,
1237 HIDPP_REG_PAIRING_INFORMATION };
1238static u8 unifying_pairing_answer[] = { REPORT_ID_HIDPP_LONG,
1239 HIDPP_RECEIVER_INDEX,
1240 HIDPP_GET_LONG_REGISTER,
1241 HIDPP_REG_PAIRING_INFORMATION };
701 1242
702static int logi_dj_ll_raw_request(struct hid_device *hid,1243static int logi_dj_ll_raw_request(struct hid_device *hid,
703 unsigned char reportnum, __u8 *buf,1244 unsigned char reportnum, __u8 *buf,
@@ -721,13 +1262,23 @@ static int logi_dj_ll_raw_request(struct hid_device *hid, · 17 unmodified lines
721 buf[4] = (buf[4] & 0xf0) | (djdev->device_index - 1);1262 buf[4] = (buf[4] & 0xf0) | (djdev->device_index - 1);
722 else1263 else
723 buf[1] = djdev->device_index;1264 buf[1] = djdev->device_index;
724 return hid_hw_raw_request(djrcv_dev->hdev, reportnum, buf,1265 return hid_hw_raw_request(djrcv_dev->hidpp, reportnum, buf,
725 count, report_type, reqtype);1266 count, report_type, reqtype);
726 }1267 }
727 1268
728 if (buf[0] != REPORT_TYPE_LEDS)1269 if (buf[0] != REPORT_TYPE_LEDS)
729 return -EINVAL;1270 return -EINVAL;
730 1271
1272 if (djrcv_dev->type != recvr_type_dj && count >= 2) {
1273 if (!djrcv_dev->keyboard) {
1274 hid_warn(hid, "Received REPORT_TYPE_LEDS request before the keyboard interface was enumerated\n");
1275 return 0;
1276 }
1277 /* usbhid overrides the report ID and ignores the first byte */
1278 return hid_hw_raw_request(djrcv_dev->keyboard, 0, buf, count,
1279 report_type, reqtype);
1280 }
1281
731 out_buf = kzalloc(DJREPORT_SHORT_LENGTH, GFP_ATOMIC);1282 out_buf = kzalloc(DJREPORT_SHORT_LENGTH, GFP_ATOMIC);
732 if (!out_buf)1283 if (!out_buf)
733 return -ENOMEM;1284 return -ENOMEM;
@@ -739,7 +1290,7 @@ static int logi_dj_ll_raw_request(struct hid_device *hid, · 5 unmodified lines
739 out_buf[1] = djdev->device_index;1290 out_buf[1] = djdev->device_index;
740 memcpy(out_buf + 2, buf, count);1291 memcpy(out_buf + 2, buf, count);
741 1292
742 ret = hid_hw_raw_request(djrcv_dev->hdev, out_buf[0], out_buf,1293 ret = hid_hw_raw_request(djrcv_dev->hidpp, out_buf[0], out_buf,
743 DJREPORT_SHORT_LENGTH, report_type, reqtype);1294 DJREPORT_SHORT_LENGTH, report_type, reqtype);
744 1295
745 kfree(out_buf);1296 kfree(out_buf);
@@ -769,41 +1320,55 @@ static int logi_dj_ll_parse(struct hid_device *hid) · 23 unmodified lines
769 return -ENOMEM;1320 return -ENOMEM;
770 1321
771 if (djdev->reports_supported & STD_KEYBOARD) {1322 if (djdev->reports_supported & STD_KEYBOARD) {
772 dbg_hid("%s: sending a kbd descriptor, reports_supported: %x\n",1323 dbg_hid("%s: sending a kbd descriptor, reports_supported: %llx\n",
773 __func__, djdev->reports_supported);1324 __func__, djdev->reports_supported);
774 rdcat(rdesc, &rsize, kbd_descriptor, sizeof(kbd_descriptor));1325 rdcat(rdesc, &rsize, kbd_descriptor, sizeof(kbd_descriptor));
775 }1326 }
776 1327
777 if (djdev->reports_supported & STD_MOUSE) {1328 if (djdev->reports_supported & STD_MOUSE) {
778 dbg_hid("%s: sending a mouse descriptor, reports_supported: "1329 dbg_hid("%s: sending a mouse descriptor, reports_supported: %llx\n",
779 "%x\n", __func__, djdev->reports_supported);1330 __func__, djdev->reports_supported);
780 rdcat(rdesc, &rsize, mse_descriptor, sizeof(mse_descriptor));1331 if (djdev->dj_receiver_dev->type == recvr_type_gaming_hidpp)
1332 rdcat(rdesc, &rsize, mse_high_res_descriptor,
1333 sizeof(mse_high_res_descriptor));
1334 else if (djdev->dj_receiver_dev->type == recvr_type_27mhz)
1335 rdcat(rdesc, &rsize, mse_27mhz_descriptor,
1336 sizeof(mse_27mhz_descriptor));
1337 else if (djdev->dj_receiver_dev->type == recvr_type_bluetooth)
1338 rdcat(rdesc, &rsize, mse_bluetooth_descriptor,
1339 sizeof(mse_bluetooth_descriptor));
1340 else
1341 rdcat(rdesc, &rsize, mse_descriptor,
1342 sizeof(mse_descriptor));
781 }1343 }
782 1344
783 if (djdev->reports_supported & MULTIMEDIA) {1345 if (djdev->reports_supported & MULTIMEDIA) {
784 dbg_hid("%s: sending a multimedia report descriptor: %x\n",1346 dbg_hid("%s: sending a multimedia report descriptor: %llx\n",
785 __func__, djdev->reports_supported);1347 __func__, djdev->reports_supported);
786 rdcat(rdesc, &rsize, consumer_descriptor, sizeof(consumer_descriptor));1348 rdcat(rdesc, &rsize, consumer_descriptor, sizeof(consumer_descriptor));
787 }1349 }
788 1350
789 if (djdev->reports_supported & POWER_KEYS) {1351 if (djdev->reports_supported & POWER_KEYS) {
790 dbg_hid("%s: sending a power keys report descriptor: %x\n",1352 dbg_hid("%s: sending a power keys report descriptor: %llx\n",
791 __func__, djdev->reports_supported);1353 __func__, djdev->reports_supported);
792 rdcat(rdesc, &rsize, syscontrol_descriptor, sizeof(syscontrol_descriptor));1354 rdcat(rdesc, &rsize, syscontrol_descriptor, sizeof(syscontrol_descriptor));
793 }1355 }
794 1356
795 if (djdev->reports_supported & MEDIA_CENTER) {1357 if (djdev->reports_supported & MEDIA_CENTER) {
796 dbg_hid("%s: sending a media center report descriptor: %x\n",1358 dbg_hid("%s: sending a media center report descriptor: %llx\n",
797 __func__, djdev->reports_supported);1359 __func__, djdev->reports_supported);
798 rdcat(rdesc, &rsize, media_descriptor, sizeof(media_descriptor));1360 rdcat(rdesc, &rsize, media_descriptor, sizeof(media_descriptor));
799 }1361 }
800 1362
801 if (djdev->reports_supported & KBD_LEDS) {1363 if (djdev->reports_supported & KBD_LEDS) {
802 dbg_hid("%s: need to send kbd leds report descriptor: %x\n",1364 dbg_hid("%s: need to send kbd leds report descriptor: %llx\n",
803 __func__, djdev->reports_supported);1365 __func__, djdev->reports_supported);
804 }1366 }
805 1367
806 rdcat(rdesc, &rsize, hidpp_descriptor, sizeof(hidpp_descriptor));1368 if (djdev->reports_supported & HIDPP) {
1369 rdcat(rdesc, &rsize, hidpp_descriptor,
1370 sizeof(hidpp_descriptor));
1371 }
807 1372
808 retval = hid_parse_report(hid, rdesc, rsize);1373 retval = hid_parse_report(hid, rdesc, rsize);
809 kfree(rdesc);1374 kfree(rdesc);
@@ -866,7 +1431,7 @@ static int logi_dj_dj_event(struct hid_device *hdev, · 56 unmodified lines
866 * so ignore those reports too.1431 * so ignore those reports too.
867 */1432 */
868 if (dj_report->device_index != DJ_RECEIVER_INDEX)1433 if (dj_report->device_index != DJ_RECEIVER_INDEX)
869 dev_err(&hdev->dev, "%s: invalid device index:%d\n",1434 hid_err(hdev, "%s: invalid device index:%d\n",
870 __func__, dj_report->device_index);1435 __func__, dj_report->device_index);
871 return false;1436 return false;
872 }1437 }
@@ -893,7 +1458,7 @@ static int logi_dj_dj_event(struct hid_device *hdev, · 20 unmodified lines
893 }1458 }
894 break;1459 break;
895 default:1460 default:
896 logi_dj_recv_forward_report(djrcv_dev, dj_report);1461 logi_dj_recv_forward_dj(djrcv_dev, dj_report);
897 }1462 }
898 1463
899out:1464out:
@@ -907,9 +1472,10 @@ static int logi_dj_hidpp_event(struct hid_device *hdev, · 7 unmodified lines
907 int size)1472 int size)
908{1473{
909 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);1474 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
910 struct dj_report *dj_report = (struct dj_report *) data;1475 struct hidpp_event *hidpp_report = (struct hidpp_event *) data;
1476 struct dj_device *dj_dev;
911 unsigned long flags;1477 unsigned long flags;
912 u8 device_index = dj_report->device_index;1478 u8 device_index = hidpp_report->device_index;
913 1479
914 if (device_index == HIDPP_RECEIVER_INDEX) {1480 if (device_index == HIDPP_RECEIVER_INDEX) {
915 /* special case were the device wants to know its unifying1481 /* special case were the device wants to know its unifying
@@ -937,21 +1503,42 @@ static int logi_dj_hidpp_event(struct hid_device *hdev, · 21 unmodified lines
937 * This driver can ignore safely the receiver notifications,1503 * This driver can ignore safely the receiver notifications,
938 * so ignore those reports too.1504 * so ignore those reports too.
939 */1505 */
940 dev_err(&hdev->dev, "%s: invalid device index:%d\n",1506 hid_err(hdev, "%s: invalid device index:%d\n", __func__,
941 __func__, dj_report->device_index);1507 hidpp_report->device_index);
942 return false;1508 return false;
943 }1509 }
944 1510
945 spin_lock_irqsave(&djrcv_dev->lock, flags);1511 spin_lock_irqsave(&djrcv_dev->lock, flags);
946 1512
947 if (!djrcv_dev->paired_dj_devices[device_index])1513 dj_dev = djrcv_dev->paired_dj_devices[device_index];
948 /* received an event for an unknown device, bail out */1514
949 goto out;1515 /*
1516 * With 27 MHz receivers, we do not get an explicit unpair event,
1517 * remove the old device if the user has paired a *different* device.
1518 */
1519 if (djrcv_dev->type == recvr_type_27mhz && dj_dev &&
1520 hidpp_report->sub_id == REPORT_TYPE_NOTIF_DEVICE_CONNECTED &&
1521 hidpp_report->params[HIDPP_PARAM_PROTO_TYPE] == 0x02 &&
1522 hidpp_report->params[HIDPP_PARAM_27MHZ_DEVID] !=
1523 dj_dev->hdev->product) {
1524 struct dj_workitem workitem = {
1525 .device_index = hidpp_report->device_index,
1526 .type = WORKITEM_TYPE_UNPAIRED,
1527 };
1528 kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
1529 /* logi_hidpp_recv_queue_notif will queue the work */
1530 dj_dev = NULL;
1531 }
950 1532
951 logi_dj_recv_forward_hidpp(djrcv_dev->paired_dj_devices[device_index],1533 if (dj_dev) {
952 data, size);1534 logi_dj_recv_forward_report(dj_dev, data, size);
1535 } else {
1536 if (hidpp_report->sub_id == REPORT_TYPE_NOTIF_DEVICE_CONNECTED)
1537 logi_hidpp_recv_queue_notif(hdev, hidpp_report);
1538 else
1539 logi_dj_recv_queue_unknown_work(djrcv_dev);
1540 }
953 1541
954out:
955 spin_unlock_irqrestore(&djrcv_dev->lock, flags);1542 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
956 1543
957 return false;1544 return false;
@@ -961,112 +1548,176 @@ static int logi_dj_raw_event(struct hid_device *hdev, · 3 unmodified lines
961 struct hid_report *report, u8 *data,1548 struct hid_report *report, u8 *data,
962 int size)1549 int size)
963{1550{
1551 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
964 dbg_hid("%s, size:%d\n", __func__, size);1552 dbg_hid("%s, size:%d\n", __func__, size);
965 1553
1554 if (!djrcv_dev)
1555 return 0;
1556
1557 if (!hdev->report_enum[HID_INPUT_REPORT].numbered) {
1558
1559 if (djrcv_dev->unnumbered_application == HID_GD_KEYBOARD) {
1560 /*
1561 * For the keyboard, we can reuse the same report by
1562 * using the second byte which is constant in the USB
1563 * HID report descriptor.
1564 */
1565 data[1] = data[0];
1566 data[0] = REPORT_TYPE_KEYBOARD;
1567
1568 logi_dj_recv_forward_input_report(hdev, data, size);
1569
1570 /* restore previous state */
1571 data[0] = data[1];
1572 data[1] = 0;
1573 }
1574 /* The 27 MHz mouse-only receiver sends unnumbered mouse data */
1575 if (djrcv_dev->unnumbered_application == HID_GD_MOUSE &&
1576 size == 6) {
1577 u8 mouse_report[7];
1578
1579 /* Prepend report id */
1580 mouse_report[0] = REPORT_TYPE_MOUSE;
1581 memcpy(mouse_report + 1, data, 6);
1582 logi_dj_recv_forward_input_report(hdev, mouse_report, 7);
1583 }
1584
1585 return false;
1586 }
1587
966 switch (data[0]) {1588 switch (data[0]) {
967 case REPORT_ID_DJ_SHORT:1589 case REPORT_ID_DJ_SHORT:
968 if (size != DJREPORT_SHORT_LENGTH) {1590 if (size != DJREPORT_SHORT_LENGTH) {
969 dev_err(&hdev->dev, "DJ report of bad size (%d)", size);1591 hid_err(hdev, "Short DJ report bad size (%d)", size);
1592 return false;
1593 }
1594 return logi_dj_dj_event(hdev, report, data, size);
1595 case REPORT_ID_DJ_LONG:
1596 if (size != DJREPORT_LONG_LENGTH) {
1597 hid_err(hdev, "Long DJ report bad size (%d)", size);
970 return false;1598 return false;
971 }1599 }
972 return logi_dj_dj_event(hdev, report, data, size);1600 return logi_dj_dj_event(hdev, report, data, size);
973 case REPORT_ID_HIDPP_SHORT:1601 case REPORT_ID_HIDPP_SHORT:
974 if (size != HIDPP_REPORT_SHORT_LENGTH) {1602 if (size != HIDPP_REPORT_SHORT_LENGTH) {
975 dev_err(&hdev->dev,1603 hid_err(hdev, "Short HID++ report bad size (%d)", size);
976 "Short HID++ report of bad size (%d)", size);
977 return false;1604 return false;
978 }1605 }
979 return logi_dj_hidpp_event(hdev, report, data, size);1606 return logi_dj_hidpp_event(hdev, report, data, size);
980 case REPORT_ID_HIDPP_LONG:1607 case REPORT_ID_HIDPP_LONG:
981 if (size != HIDPP_REPORT_LONG_LENGTH) {1608 if (size != HIDPP_REPORT_LONG_LENGTH) {
982 dev_err(&hdev->dev,1609 hid_err(hdev, "Long HID++ report bad size (%d)", size);
983 "Long HID++ report of bad size (%d)", size);
984 return false;1610 return false;
985 }1611 }
986 return logi_dj_hidpp_event(hdev, report, data, size);1612 return logi_dj_hidpp_event(hdev, report, data, size);
987 }1613 }
988 1614
1615 logi_dj_recv_forward_input_report(hdev, data, size);
1616
989 return false;1617 return false;
990}1618}
991 1619
992static int logi_dj_probe(struct hid_device *hdev,1620static int logi_dj_probe(struct hid_device *hdev,
993 const struct hid_device_id *id)1621 const struct hid_device_id *id)
994{1622{
995 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);1623 struct hid_report_enum *rep_enum;
1624 struct hid_report *rep;
996 struct dj_receiver_dev *djrcv_dev;1625 struct dj_receiver_dev *djrcv_dev;
1626 struct usb_interface *intf;
1627 unsigned int no_dj_interfaces = 0;
1628 bool has_hidpp = false;
1629 unsigned long flags;
997 int retval;1630 int retval;
998 1631
999 dbg_hid("%s called for ifnum %d\n", __func__,1632 /*
1000 intf->cur_altsetting->desc.bInterfaceNumber);1633 * Call to usbhid to fetch the HID descriptors of the current
1634 * interface subsequently call to the hid/hid-core to parse the
1635 * fetched descriptors.
1636 */
1637 retval = hid_parse(hdev);
1638 if (retval) {
1639 hid_err(hdev, "%s: parse failed\n", __func__);
1640 return retval;
1641 }
1001 1642
1002 /* Ignore interfaces 0 and 1, they will not carry any data, dont create1643 /*
1003 * any hid_device for them */1644 * Some KVMs add an extra interface for e.g. mouse emulation. If we
1004 if (intf->cur_altsetting->desc.bInterfaceNumber !=1645 * treat these as logitech-dj interfaces then this causes input events
1005 LOGITECH_DJ_INTERFACE_NUMBER) {1646 * reported through this extra interface to not be reported correctly.
1006 dbg_hid("%s: ignoring ifnum %d\n", __func__,1647 * To avoid this, we treat these as generic-hid devices.
1007 intf->cur_altsetting->desc.bInterfaceNumber);1648 */
1649 switch (id->driver_data) {
1650 case recvr_type_dj: no_dj_interfaces = 3; break;
1651 case recvr_type_hidpp: no_dj_interfaces = 2; break;
1652 case recvr_type_gaming_hidpp: no_dj_interfaces = 3; break;
1653 case recvr_type_27mhz: no_dj_interfaces = 2; break;
1654 case recvr_type_bluetooth: no_dj_interfaces = 2; break;
1655 }
1656 if (hid_is_using_ll_driver(hdev, &usb_hid_driver)) {
1657 intf = to_usb_interface(hdev->dev.parent);
1658 if (intf && intf->altsetting->desc.bInterfaceNumber >=
1659 no_dj_interfaces) {
1660 hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
1661 return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1662 }
1663 }
1664
1665 rep_enum = &hdev->report_enum[HID_INPUT_REPORT];
1666
1667 /* no input reports, bail out */
1668 if (list_empty(&rep_enum->report_list))
1008 return -ENODEV;1669 return -ENODEV;
1670
1671 /*
1672 * Check for the HID++ application.
1673 * Note: we should theoretically check for HID++ and DJ
1674 * collections, but this will do.
1675 */
1676 list_for_each_entry(rep, &rep_enum->report_list, list) {
1677 if (rep->application == 0xff000001)
1678 has_hidpp = true;
1009 }1679 }
1010 1680
1011 /* Treat interface 2 */1681 /*
1682 * Ignore interfaces without DJ/HID++ collection, they will not carry
1683 * any data, dont create any hid_device for them.
1684 */
1685 if (!has_hidpp && id->driver_data == recvr_type_dj)
1686 return -ENODEV;
1012 1687
1013 djrcv_dev = kzalloc(sizeof(struct dj_receiver_dev), GFP_KERNEL);1688 /* get the current application attached to the node */
1689 rep = list_first_entry(&rep_enum->report_list, struct hid_report, list);
1690 djrcv_dev = dj_get_receiver_dev(hdev, id->driver_data,
1691 rep->application, has_hidpp);
1014 if (!djrcv_dev) {1692 if (!djrcv_dev) {
1015 dev_err(&hdev->dev,1693 hid_err(hdev, "%s: dj_get_receiver_dev failed\n", __func__);
1016 "%s:failed allocating dj_receiver_dev\n", __func__);
1017 return -ENOMEM;1694 return -ENOMEM;
1018 }1695 }
1019 djrcv_dev->hdev = hdev;
1020 INIT_WORK(&djrcv_dev->work, delayedwork_callback);
1021 spin_lock_init(&djrcv_dev->lock);
1022 if (kfifo_alloc(&djrcv_dev->notif_fifo,
1023 DJ_MAX_NUMBER_NOTIFICATIONS * sizeof(struct dj_report),
1024 GFP_KERNEL)) {
1025 dev_err(&hdev->dev,
1026 "%s:failed allocating notif_fifo\n", __func__);
1027 kfree(djrcv_dev);
1028 return -ENOMEM;
1029 }
1030 hid_set_drvdata(hdev, djrcv_dev);
1031 1696
1032 /* Call to usbhid to fetch the HID descriptors of interface 2 and1697 if (!rep_enum->numbered)
1033 * subsequently call to the hid/hid-core to parse the fetched1698 djrcv_dev->unnumbered_application = rep->application;
1034 * descriptors, this will in turn create the hidraw and hiddev nodes
1035 * for interface 2 of the receiver */
1036 retval = hid_parse(hdev);
1037 if (retval) {
1038 dev_err(&hdev->dev,
1039 "%s:parse of interface 2 failed\n", __func__);
1040 goto hid_parse_fail;
1041 }
1042
1043 if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, REPORT_ID_DJ_SHORT,
1044 0, DJREPORT_SHORT_LENGTH - 1)) {
1045 retval = -ENODEV;
1046 goto hid_parse_fail;
1047 }
1048 1699
1049 /* Starts the usb device and connects to upper interfaces hiddev and1700 /* Starts the usb device and connects to upper interfaces hiddev and
1050 * hidraw */1701 * hidraw */
1051 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);1702 retval = hid_hw_start(hdev, HID_CONNECT_HIDRAW|HID_CONNECT_HIDDEV);
1052 if (retval) {1703 if (retval) {
1053 dev_err(&hdev->dev,1704 hid_err(hdev, "%s: hid_hw_start returned error\n", __func__);
1054 "%s:hid_hw_start returned error\n", __func__);
1055 goto hid_hw_start_fail;1705 goto hid_hw_start_fail;
1056 }1706 }
1057 1707
1058 retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0);1708 if (has_hidpp) {
1059 if (retval < 0) {1709 retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0);
1060 dev_err(&hdev->dev,1710 if (retval < 0) {
1061 "%s:logi_dj_recv_switch_to_dj_mode returned error:%d\n",1711 hid_err(hdev, "%s: logi_dj_recv_switch_to_dj_mode returned error:%d\n",
1062 __func__, retval);1712 __func__, retval);
1063 goto switch_to_dj_mode_fail;1713 goto switch_to_dj_mode_fail;
1714 }
1064 }1715 }
1065 1716
1066 /* This is enabling the polling urb on the IN endpoint */1717 /* This is enabling the polling urb on the IN endpoint */
1067 retval = hid_hw_open(hdev);1718 retval = hid_hw_open(hdev);
1068 if (retval < 0) {1719 if (retval < 0) {
1069 dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n",1720 hid_err(hdev, "%s: hid_hw_open returned error:%d\n",
1070 __func__, retval);1721 __func__, retval);
1071 goto llopen_failed;1722 goto llopen_failed;
1072 }1723 }
@@ -1074,11 +1725,16 @@ static int logi_dj_probe(struct hid_device *hdev, · 1 unmodified line
1074 /* Allow incoming packets to arrive: */1725 /* Allow incoming packets to arrive: */
1075 hid_device_io_start(hdev);1726 hid_device_io_start(hdev);
1076 1727
1077 retval = logi_dj_recv_query_paired_devices(djrcv_dev);1728 if (has_hidpp) {
1078 if (retval < 0) {1729 spin_lock_irqsave(&djrcv_dev->lock, flags);
1079 dev_err(&hdev->dev, "%s:logi_dj_recv_query_paired_devices "1730 djrcv_dev->ready = true;
1080 "error:%d\n", __func__, retval);1731 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1081 goto logi_dj_recv_query_paired_devices_failed;1732 retval = logi_dj_recv_query_paired_devices(djrcv_dev);
1733 if (retval < 0) {
1734 hid_err(hdev, "%s: logi_dj_recv_query_paired_devices error:%d\n",
1735 __func__, retval);
1736 goto logi_dj_recv_query_paired_devices_failed;
1737 }
1082 }1738 }
1083 1739
1084 return retval;1740 return retval;
@@ -1091,12 +1747,8 @@ switch_to_dj_mode_fail: · 6 unmodified lines
1091 hid_hw_stop(hdev);1747 hid_hw_stop(hdev);
1092 1748
1093hid_hw_start_fail:1749hid_hw_start_fail:
1094hid_parse_fail:1750 dj_put_receiver_dev(hdev);
1095 kfifo_free(&djrcv_dev->notif_fifo);
1096 kfree(djrcv_dev);
1097 hid_set_drvdata(hdev, NULL);
1098 return retval;1751 return retval;
1099
1100}1752}
1101 1753
1102#ifdef CONFIG_PM1754#ifdef CONFIG_PM
@@ -1105,10 +1757,12 @@ static int logi_dj_reset_resume(struct hid_device *hdev) · 2 unmodified lines
1105 int retval;1757 int retval;
1106 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);1758 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1107 1759
1760 if (!djrcv_dev || djrcv_dev->hidpp != hdev)
1761 return 0;
1762
1108 retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0);1763 retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0);
1109 if (retval < 0) {1764 if (retval < 0) {
1110 dev_err(&hdev->dev,1765 hid_err(hdev, "%s: logi_dj_recv_switch_to_dj_mode returned error:%d\n",
1111 "%s:logi_dj_recv_switch_to_dj_mode returned error:%d\n",
1112 __func__, retval);1766 __func__, retval);
1113 }1767 }
1114 1768
@@ -1120,39 +1774,83 @@ static void logi_dj_remove(struct hid_device *hdev) · 5 unmodified lines
1120{1774{
1121 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);1775 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1122 struct dj_device *dj_dev;1776 struct dj_device *dj_dev;
1777 unsigned long flags;
1123 int i;1778 int i;
1124 1779
1125 dbg_hid("%s\n", __func__);1780 dbg_hid("%s\n", __func__);
1126 1781
1782 if (!djrcv_dev)
1783 return hid_hw_stop(hdev);
1784
1785 /*
1786 * This ensures that if the work gets requeued from another
1787 * interface of the same receiver it will be a no-op.
1788 */
1789 spin_lock_irqsave(&djrcv_dev->lock, flags);
1790 djrcv_dev->ready = false;
1791 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1792
1127 cancel_work_sync(&djrcv_dev->work);1793 cancel_work_sync(&djrcv_dev->work);
1128 1794
1129 hid_hw_close(hdev);1795 hid_hw_close(hdev);
1130 hid_hw_stop(hdev);1796 hid_hw_stop(hdev);
1131 1797
1132 /* I suppose that at this point the only context that can access1798 /*
1133 * the djrecv_data is this thread as the work item is guaranteed to1799 * For proper operation we need access to all interfaces, so we destroy
1134 * have finished and no more raw_event callbacks should arrive after1800 * the paired devices when we're unbound from any interface.
1135 * the remove callback was triggered so no locks are put around the1801 *
1136 * code below */1802 * Note we may still be bound to other interfaces, sharing the same
1803 * djrcv_dev, so we need locking here.
1804 */
1137 for (i = 0; i < (DJ_MAX_PAIRED_DEVICES + DJ_DEVICE_INDEX_MIN); i++) {1805 for (i = 0; i < (DJ_MAX_PAIRED_DEVICES + DJ_DEVICE_INDEX_MIN); i++) {
1806 spin_lock_irqsave(&djrcv_dev->lock, flags);
1138 dj_dev = djrcv_dev->paired_dj_devices[i];1807 dj_dev = djrcv_dev->paired_dj_devices[i];
1808 djrcv_dev->paired_dj_devices[i] = NULL;
1809 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1139 if (dj_dev != NULL) {1810 if (dj_dev != NULL) {
1140 hid_destroy_device(dj_dev->hdev);1811 hid_destroy_device(dj_dev->hdev);
1141 kfree(dj_dev);1812 kfree(dj_dev);
1142 djrcv_dev->paired_dj_devices[i] = NULL;
1143 }1813 }
1144 }1814 }
1145 1815
1146 kfifo_free(&djrcv_dev->notif_fifo);1816 dj_put_receiver_dev(hdev);
1147 kfree(djrcv_dev);
1148 hid_set_drvdata(hdev, NULL);
1149}1817}
1150 1818
1151static const struct hid_device_id logi_dj_receivers[] = {1819static const struct hid_device_id logi_dj_receivers[] = {
1152 {HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,1820 {HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1153 USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER)},1821 USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER),
1822 .driver_data = recvr_type_dj},
1154 {HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,1823 {HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1155 USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2)},1824 USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2),
1825 .driver_data = recvr_type_dj},
1826 { /* Logitech Nano (non DJ) receiver */
1827 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1828 USB_DEVICE_ID_LOGITECH_NANO_RECEIVER),
1829 .driver_data = recvr_type_hidpp},
1830 { /* Logitech Nano (non DJ) receiver */
1831 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1832 USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_2),
1833 .driver_data = recvr_type_hidpp},
1834 { /* Logitech gaming receiver (0xc539) */
1835 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1836 USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_GAMING),
1837 .driver_data = recvr_type_gaming_hidpp},
1838 { /* Logitech 27 MHz HID++ 1.0 receiver (0xc517) */
1839 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1840 USB_DEVICE_ID_S510_RECEIVER_2),
1841 .driver_data = recvr_type_27mhz},
1842 { /* Logitech 27 MHz HID++ 1.0 mouse-only receiver (0xc51b) */
1843 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1844 USB_DEVICE_ID_LOGITECH_27MHZ_MOUSE_RECEIVER),
1845 .driver_data = recvr_type_27mhz},
1846 { /* Logitech MX5000 HID++ / bluetooth receiver keyboard intf. */
1847 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1848 0xc70e),
1849 .driver_data = recvr_type_bluetooth},
1850 { /* Logitech MX5000 HID++ / bluetooth receiver mouse intf. */
1851 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1852 0xc70a),
1853 .driver_data = recvr_type_bluetooth},
1156 {}1854 {}
1157};1855};
1158 1856
drivers/hid/hid-logitech-hidpp.c+537−199
@@ -51,7 +51,11 @@ MODULE_PARM_DESC(disable_tap_to_click, · 50 unmodified lines
51 51
52#define HIDPP_REPORT_SHORT_LENGTH 752#define HIDPP_REPORT_SHORT_LENGTH 7
53#define HIDPP_REPORT_LONG_LENGTH 2053#define HIDPP_REPORT_LONG_LENGTH 20
54#define HIDPP_REPORT_VERY_LONG_LENGTH 6454#define HIDPP_REPORT_VERY_LONG_MAX_LENGTH 64
55
56#define HIDPP_SUB_ID_CONSUMER_VENDOR_KEYS 0x03
57#define HIDPP_SUB_ID_ROLLER 0x05
58#define HIDPP_SUB_ID_MOUSE_EXTRA_BTNS 0x06
55 59
56#define HIDPP_QUIRK_CLASS_WTP BIT(0)60#define HIDPP_QUIRK_CLASS_WTP BIT(0)
57#define HIDPP_QUIRK_CLASS_M560 BIT(1)61#define HIDPP_QUIRK_CLASS_M560 BIT(1)
@@ -68,6 +72,13 @@ MODULE_PARM_DESC(disable_tap_to_click, · 10 unmodified lines
68#define HIDPP_QUIRK_HI_RES_SCROLL_1P0 BIT(26)72#define HIDPP_QUIRK_HI_RES_SCROLL_1P0 BIT(26)
69#define HIDPP_QUIRK_HI_RES_SCROLL_X2120 BIT(27)73#define HIDPP_QUIRK_HI_RES_SCROLL_X2120 BIT(27)
70#define HIDPP_QUIRK_HI_RES_SCROLL_X2121 BIT(28)74#define HIDPP_QUIRK_HI_RES_SCROLL_X2121 BIT(28)
75#define HIDPP_QUIRK_HIDPP_WHEELS BIT(29)
76#define HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS BIT(30)
77#define HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS BIT(31)
78
79/* These are just aliases for now */
80#define HIDPP_QUIRK_KBD_SCROLL_WHEEL HIDPP_QUIRK_HIDPP_WHEELS
81#define HIDPP_QUIRK_KBD_ZOOM_WHEEL HIDPP_QUIRK_HIDPP_WHEELS
71 82
72/* Convenience constant to check for any high-res support. */83/* Convenience constant to check for any high-res support. */
73#define HIDPP_QUIRK_HI_RES_SCROLL (HIDPP_QUIRK_HI_RES_SCROLL_1P0 | \84#define HIDPP_QUIRK_HI_RES_SCROLL (HIDPP_QUIRK_HI_RES_SCROLL_1P0 | \
@@ -106,13 +117,13 @@ MODULE_PARM_DESC(disable_tap_to_click, · 32 unmodified lines
106struct fap {117struct fap {
107 u8 feature_index;118 u8 feature_index;
108 u8 funcindex_clientid;119 u8 funcindex_clientid;
109 u8 params[HIDPP_REPORT_VERY_LONG_LENGTH - 4U];120 u8 params[HIDPP_REPORT_VERY_LONG_MAX_LENGTH - 4U];
110};121};
111 122
112struct rap {123struct rap {
113 u8 sub_id;124 u8 sub_id;
114 u8 reg_address;125 u8 reg_address;
115 u8 params[HIDPP_REPORT_VERY_LONG_LENGTH - 4U];126 u8 params[HIDPP_REPORT_VERY_LONG_MAX_LENGTH - 4U];
116};127};
117 128
118struct hidpp_report {129struct hidpp_report {
@@ -149,7 +160,6 @@ struct hidpp_battery { · 30 unmodified lines
149 * @last_time: last event time, used to reset remainder after inactivity160 * @last_time: last event time, used to reset remainder after inactivity
150 */161 */
151struct hidpp_scroll_counter {162struct hidpp_scroll_counter {
152 struct input_dev *dev;
153 int wheel_multiplier;163 int wheel_multiplier;
154 int remainder;164 int remainder;
155 int direction;165 int direction;
@@ -158,10 +168,12 @@ struct hidpp_scroll_counter { · 2 unmodified lines
158 168
159struct hidpp_device {169struct hidpp_device {
160 struct hid_device *hid_dev;170 struct hid_device *hid_dev;
171 struct input_dev *input;
161 struct mutex send_mutex;172 struct mutex send_mutex;
162 void *send_receive_buf;173 void *send_receive_buf;
163 char *name; /* will never be NULL and should not be freed */174 char *name; /* will never be NULL and should not be freed */
164 wait_queue_head_t wait;175 wait_queue_head_t wait;
176 int very_long_report_length;
165 bool answer_available;177 bool answer_available;
166 u8 protocol_major;178 u8 protocol_major;
167 u8 protocol_minor;179 u8 protocol_minor;
@@ -206,8 +218,6 @@ static int __hidpp_send_report(struct hid_device *hdev, · 38 unmodified lines
206 struct hidpp_device *hidpp = hid_get_drvdata(hdev);218 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
207 int fields_count, ret;219 int fields_count, ret;
208 220
209 hidpp = hid_get_drvdata(hdev);
210
211 switch (hidpp_report->report_id) {221 switch (hidpp_report->report_id) {
212 case REPORT_ID_HIDPP_SHORT:222 case REPORT_ID_HIDPP_SHORT:
213 fields_count = HIDPP_REPORT_SHORT_LENGTH;223 fields_count = HIDPP_REPORT_SHORT_LENGTH;
@@ -216,7 +226,7 @@ static int __hidpp_send_report(struct hid_device *hdev, · 2 unmodified lines
216 fields_count = HIDPP_REPORT_LONG_LENGTH;226 fields_count = HIDPP_REPORT_LONG_LENGTH;
217 break;227 break;
218 case REPORT_ID_HIDPP_VERY_LONG:228 case REPORT_ID_HIDPP_VERY_LONG:
219 fields_count = HIDPP_REPORT_VERY_LONG_LENGTH;229 fields_count = hidpp->very_long_report_length;
220 break;230 break;
221 default:231 default:
222 return -ENODEV;232 return -ENODEV;
@@ -342,7 +352,7 @@ static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev, · 119 unmodified lines
342 max_count = HIDPP_REPORT_LONG_LENGTH - 4;352 max_count = HIDPP_REPORT_LONG_LENGTH - 4;
343 break;353 break;
344 case REPORT_ID_HIDPP_VERY_LONG:354 case REPORT_ID_HIDPP_VERY_LONG:
345 max_count = HIDPP_REPORT_VERY_LONG_LENGTH - 4;355 max_count = hidpp_dev->very_long_report_length - 4;
346 break;356 break;
347 default:357 default:
348 return -EINVAL;358 return -EINVAL;
@@ -434,14 +444,15 @@ static void hidpp_prefix_name(char **name, int name_length) · 85 unmodified lines
434 * emit low-resolution scroll events when appropriate for444 * emit low-resolution scroll events when appropriate for
435 * backwards-compatibility with userspace input libraries.445 * backwards-compatibility with userspace input libraries.
436 */446 */
437static void hidpp_scroll_counter_handle_scroll(struct hidpp_scroll_counter *counter,447static void hidpp_scroll_counter_handle_scroll(struct input_dev *input_dev,
448 struct hidpp_scroll_counter *counter,
438 int hi_res_value)449 int hi_res_value)
439{450{
440 int low_res_value, remainder, direction;451 int low_res_value, remainder, direction;
441 unsigned long long now, previous;452 unsigned long long now, previous;
442 453
443 hi_res_value = hi_res_value * 120/counter->wheel_multiplier;454 hi_res_value = hi_res_value * 120/counter->wheel_multiplier;
444 input_report_rel(counter->dev, REL_WHEEL_HI_RES, hi_res_value);455 input_report_rel(input_dev, REL_WHEEL_HI_RES, hi_res_value);
445 456
446 remainder = counter->remainder;457 remainder = counter->remainder;
447 direction = hi_res_value > 0 ? 1 : -1;458 direction = hi_res_value > 0 ? 1 : -1;
@@ -475,7 +486,7 @@ static void hidpp_scroll_counter_handle_scroll(struct hidpp_scroll_counter *coun · 27 unmodified lines
475 low_res_value = remainder / 120;486 low_res_value = remainder / 120;
476 if (low_res_value == 0)487 if (low_res_value == 0)
477 low_res_value = (hi_res_value > 0 ? 1 : -1);488 low_res_value = (hi_res_value > 0 ? 1 : -1);
478 input_report_rel(counter->dev, REL_WHEEL, low_res_value);489 input_report_rel(input_dev, REL_WHEEL, low_res_value);
479 remainder -= low_res_value * 120;490 remainder -= low_res_value * 120;
480 }491 }
481 counter->remainder = remainder;492 counter->remainder = remainder;
@@ -491,14 +502,16 @@ static void hidpp_scroll_counter_handle_scroll(struct hidpp_scroll_counter *coun · 9 unmodified lines
491#define HIDPP_GET_LONG_REGISTER 0x83502#define HIDPP_GET_LONG_REGISTER 0x83
492 503
493/**504/**
494 * hidpp10_set_register_bit() - Sets a single bit in a HID++ 1.0 register.505 * hidpp10_set_register - Modify a HID++ 1.0 register.
495 * @hidpp_dev: the device to set the register on.506 * @hidpp_dev: the device to set the register on.
496 * @register_address: the address of the register to modify.507 * @register_address: the address of the register to modify.
497 * @byte: the byte of the register to modify. Should be less than 3.508 * @byte: the byte of the register to modify. Should be less than 3.
509 * @mask: mask of the bits to modify
510 * @value: new values for the bits in mask
498 * Return: 0 if successful, otherwise a negative error code.511 * Return: 0 if successful, otherwise a negative error code.
499 */512 */
500static int hidpp10_set_register_bit(struct hidpp_device *hidpp_dev,513static int hidpp10_set_register(struct hidpp_device *hidpp_dev,
501 u8 register_address, u8 byte, u8 bit)514 u8 register_address, u8 byte, u8 mask, u8 value)
502{515{
503 struct hidpp_report response;516 struct hidpp_report response;
504 int ret;517 int ret;
@@ -514,7 +527,8 @@ static int hidpp10_set_register_bit(struct hidpp_device *hidpp_dev, · 9 unmodified lines
514 527
515 memcpy(params, response.rap.params, 3);528 memcpy(params, response.rap.params, 3);
516 529
517 params[byte] |= BIT(bit);530 params[byte] &= ~mask;
531 params[byte] |= value & mask;
518 532
519 return hidpp_send_rap_command_sync(hidpp_dev,533 return hidpp_send_rap_command_sync(hidpp_dev,
520 REPORT_ID_HIDPP_SHORT,534 REPORT_ID_HIDPP_SHORT,
@@ -523,20 +537,28 @@ static int hidpp10_set_register_bit(struct hidpp_device *hidpp_dev, · 2 unmodified lines
523 params, 3, &response);537 params, 3, &response);
524}538}
525 539
526 540#define HIDPP_REG_ENABLE_REPORTS 0x00
527#define HIDPP_REG_GENERAL 0x00541#define HIDPP_ENABLE_CONSUMER_REPORT BIT(0)
542#define HIDPP_ENABLE_WHEEL_REPORT BIT(2)
543#define HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT BIT(3)
544#define HIDPP_ENABLE_BAT_REPORT BIT(4)
545#define HIDPP_ENABLE_HWHEEL_REPORT BIT(5)
528 546
529static int hidpp10_enable_battery_reporting(struct hidpp_device *hidpp_dev)547static int hidpp10_enable_battery_reporting(struct hidpp_device *hidpp_dev)
530{548{
531 return hidpp10_set_register_bit(hidpp_dev, HIDPP_REG_GENERAL, 0, 4);549 return hidpp10_set_register(hidpp_dev, HIDPP_REG_ENABLE_REPORTS, 0,
550 HIDPP_ENABLE_BAT_REPORT, HIDPP_ENABLE_BAT_REPORT);
532}551}
533 552
534#define HIDPP_REG_FEATURES 0x01553#define HIDPP_REG_FEATURES 0x01
554#define HIDPP_ENABLE_SPECIAL_BUTTON_FUNC BIT(1)
555#define HIDPP_ENABLE_FAST_SCROLL BIT(6)
535 556
536/* On HID++ 1.0 devices, high-res scroll was called "scrolling acceleration". */557/* On HID++ 1.0 devices, high-res scroll was called "scrolling acceleration". */
537static int hidpp10_enable_scrolling_acceleration(struct hidpp_device *hidpp_dev)558static int hidpp10_enable_scrolling_acceleration(struct hidpp_device *hidpp_dev)
538{559{
539 return hidpp10_set_register_bit(hidpp_dev, HIDPP_REG_FEATURES, 0, 6);560 return hidpp10_set_register(hidpp_dev, HIDPP_REG_FEATURES, 0,
561 HIDPP_ENABLE_FAST_SCROLL, HIDPP_ENABLE_FAST_SCROLL);
540}562}
541 563
542#define HIDPP_REG_BATTERY_STATUS 0x07564#define HIDPP_REG_BATTERY_STATUS 0x07
@@ -741,6 +763,9 @@ static char *hidpp_unifying_get_name(struct hidpp_device *hidpp_dev) · 198 unmodified lines
741 if (2 + len > sizeof(response.rap.params))763 if (2 + len > sizeof(response.rap.params))
742 return NULL;764 return NULL;
743 765
766 if (len < 4) /* logitech devices are usually at least Xddd */
767 return NULL;
768
744 name = kzalloc(len + 1, GFP_KERNEL);769 name = kzalloc(len + 1, GFP_KERNEL);
745 if (!name)770 if (!name)
746 return NULL;771 return NULL;
@@ -836,18 +861,21 @@ static int hidpp_root_get_feature(struct hidpp_device *hidpp, u16 feature, · 89 unmodified lines
836 861
837static int hidpp_root_get_protocol_version(struct hidpp_device *hidpp)862static int hidpp_root_get_protocol_version(struct hidpp_device *hidpp)
838{863{
864 const u8 ping_byte = 0x5a;
865 u8 ping_data[3] = { 0, 0, ping_byte };
839 struct hidpp_report response;866 struct hidpp_report response;
840 int ret;867 int ret;
841 868
842 ret = hidpp_send_fap_command_sync(hidpp,869 ret = hidpp_send_rap_command_sync(hidpp,
870 REPORT_ID_HIDPP_SHORT,
843 HIDPP_PAGE_ROOT_IDX,871 HIDPP_PAGE_ROOT_IDX,
844 CMD_ROOT_GET_PROTOCOL_VERSION,872 CMD_ROOT_GET_PROTOCOL_VERSION,
845 NULL, 0, &response);873 ping_data, sizeof(ping_data), &response);
846 874
847 if (ret == HIDPP_ERROR_INVALID_SUBID) {875 if (ret == HIDPP_ERROR_INVALID_SUBID) {
848 hidpp->protocol_major = 1;876 hidpp->protocol_major = 1;
849 hidpp->protocol_minor = 0;877 hidpp->protocol_minor = 0;
850 return 0;878 goto print_version;
851 }879 }
852 880
853 /* the device might not be connected */881 /* the device might not be connected */
@@ -862,21 +890,19 @@ static int hidpp_root_get_protocol_version(struct hidpp_device *hidpp) · 8 unmodified lines
862 if (ret)890 if (ret)
863 return ret;891 return ret;
864 892
865 hidpp->protocol_major = response.fap.params[0];893 if (response.rap.params[2] != ping_byte) {
866 hidpp->protocol_minor = response.fap.params[1];894 hid_err(hidpp->hid_dev, "%s: ping mismatch 0x%02x != 0x%02x\n",
895 __func__, response.rap.params[2], ping_byte);
896 return -EPROTO;
897 }
867 898
868 return ret;899 hidpp->protocol_major = response.rap.params[0];
869}900 hidpp->protocol_minor = response.rap.params[1];
870 901
871static bool hidpp_is_connected(struct hidpp_device *hidpp)902print_version:
872{903 hid_info(hidpp->hid_dev, "HID++ %u.%u device connected.\n",
873 int ret;904 hidpp->protocol_major, hidpp->protocol_minor);
874 905 return 0;
875 ret = hidpp_root_get_protocol_version(hidpp);
876 if (!ret)
877 hid_dbg(hidpp->hid_dev, "HID++ %u.%u device connected.\n",
878 hidpp->protocol_major, hidpp->protocol_minor);
879 return ret == 0;
880}906}
881 907
882/* -------------------------------------------------------------------------- */908/* -------------------------------------------------------------------------- */
@@ -932,7 +958,7 @@ static int hidpp_devicenametype_get_device_name(struct hidpp_device *hidpp, · 49 unmodified lines
932 958
933 switch (response.report_id) {959 switch (response.report_id) {
934 case REPORT_ID_HIDPP_VERY_LONG:960 case REPORT_ID_HIDPP_VERY_LONG:
935 count = HIDPP_REPORT_VERY_LONG_LENGTH - 4;961 count = hidpp->very_long_report_length - 4;
936 break;962 break;
937 case REPORT_ID_HIDPP_LONG:963 case REPORT_ID_HIDPP_LONG:
938 count = HIDPP_REPORT_LONG_LENGTH - 4;964 count = HIDPP_REPORT_LONG_LENGTH - 4;
@@ -1012,7 +1038,11 @@ static int hidpp_map_battery_level(int capacity) · 73 unmodified lines
1012{1038{
1013 if (capacity < 11)1039 if (capacity < 11)
1014 return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;1040 return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
1015 else if (capacity < 31)1041 /*
1042 * The spec says this should be < 31 but some devices report 30
1043 * with brand new batteries and Windows reports 30 as "Good".
1044 */
1045 else if (capacity < 30)
1016 return POWER_SUPPLY_CAPACITY_LEVEL_LOW;1046 return POWER_SUPPLY_CAPACITY_LEVEL_LOW;
1017 else if (capacity < 81)1047 else if (capacity < 81)
1018 return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;1048 return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
@@ -2211,7 +2241,6 @@ static int hidpp_ff_deinit(struct hid_device *hid) · 1192 unmodified lines
2211#define WTP_MANUAL_RESOLUTION 392241#define WTP_MANUAL_RESOLUTION 39
2212 2242
2213struct wtp_data {2243struct wtp_data {
2214 struct input_dev *input;
2215 u16 x_size, y_size;2244 u16 x_size, y_size;
2216 u8 finger_count;2245 u8 finger_count;
2217 u8 mt_feature_index;2246 u8 mt_feature_index;
@@ -2229,7 +2258,7 @@ static int wtp_input_mapping(struct hid_device *hdev, struct hid_input *hi, · 11 unmodified lines
2229}2258}
2230 2259
2231static void wtp_populate_input(struct hidpp_device *hidpp,2260static void wtp_populate_input(struct hidpp_device *hidpp,
2232 struct input_dev *input_dev, bool origin_is_hid_core)2261 struct input_dev *input_dev)
2233{2262{
2234 struct wtp_data *wd = hidpp->private_data;2263 struct wtp_data *wd = hidpp->private_data;
2235 2264
@@ -2255,31 +2284,30 @@ static void wtp_populate_input(struct hidpp_device *hidpp, · 19 unmodified lines
2255 2284
2256 input_mt_init_slots(input_dev, wd->maxcontacts, INPUT_MT_POINTER |2285 input_mt_init_slots(input_dev, wd->maxcontacts, INPUT_MT_POINTER |
2257 INPUT_MT_DROP_UNUSED);2286 INPUT_MT_DROP_UNUSED);
2258
2259 wd->input = input_dev;
2260}2287}
2261 2288
2262static void wtp_touch_event(struct wtp_data *wd,2289static void wtp_touch_event(struct hidpp_device *hidpp,
2263 struct hidpp_touchpad_raw_xy_finger *touch_report)2290 struct hidpp_touchpad_raw_xy_finger *touch_report)
2264{2291{
2292 struct wtp_data *wd = hidpp->private_data;
2265 int slot;2293 int slot;
2266 2294
2267 if (!touch_report->finger_id || touch_report->contact_type)2295 if (!touch_report->finger_id || touch_report->contact_type)
2268 /* no actual data */2296 /* no actual data */
2269 return;2297 return;
2270 2298
2271 slot = input_mt_get_slot_by_key(wd->input, touch_report->finger_id);2299 slot = input_mt_get_slot_by_key(hidpp->input, touch_report->finger_id);
2272 2300
2273 input_mt_slot(wd->input, slot);2301 input_mt_slot(hidpp->input, slot);
2274 input_mt_report_slot_state(wd->input, MT_TOOL_FINGER,2302 input_mt_report_slot_state(hidpp->input, MT_TOOL_FINGER,
2275 touch_report->contact_status);2303 touch_report->contact_status);
2276 if (touch_report->contact_status) {2304 if (touch_report->contact_status) {
2277 input_event(wd->input, EV_ABS, ABS_MT_POSITION_X,2305 input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_X,
2278 touch_report->x);2306 touch_report->x);
2279 input_event(wd->input, EV_ABS, ABS_MT_POSITION_Y,2307 input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_Y,
2280 wd->flip_y ? wd->y_size - touch_report->y :2308 wd->flip_y ? wd->y_size - touch_report->y :
2281 touch_report->y);2309 touch_report->y);
2282 input_event(wd->input, EV_ABS, ABS_MT_PRESSURE,2310 input_event(hidpp->input, EV_ABS, ABS_MT_PRESSURE,
2283 touch_report->area);2311 touch_report->area);
2284 }2312 }
2285}2313}
@@ -2287,19 +2315,18 @@ static void wtp_touch_event(struct wtp_data *wd, · 1 unmodified line
2287static void wtp_send_raw_xy_event(struct hidpp_device *hidpp,2315static void wtp_send_raw_xy_event(struct hidpp_device *hidpp,
2288 struct hidpp_touchpad_raw_xy *raw)2316 struct hidpp_touchpad_raw_xy *raw)
2289{2317{
2290 struct wtp_data *wd = hidpp->private_data;
2291 int i;2318 int i;
2292 2319
2293 for (i = 0; i < 2; i++)2320 for (i = 0; i < 2; i++)
2294 wtp_touch_event(wd, &(raw->fingers[i]));2321 wtp_touch_event(hidpp, &(raw->fingers[i]));
2295 2322
2296 if (raw->end_of_frame &&2323 if (raw->end_of_frame &&
2297 !(hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS))2324 !(hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS))
2298 input_event(wd->input, EV_KEY, BTN_LEFT, raw->button);2325 input_event(hidpp->input, EV_KEY, BTN_LEFT, raw->button);
2299 2326
2300 if (raw->end_of_frame || raw->finger_count <= 2) {2327 if (raw->end_of_frame || raw->finger_count <= 2) {
2301 input_mt_sync_frame(wd->input);2328 input_mt_sync_frame(hidpp->input);
2302 input_sync(wd->input);2329 input_sync(hidpp->input);
2303 }2330 }
2304}2331}
2305 2332
@@ -2349,7 +2376,7 @@ static int wtp_raw_event(struct hid_device *hdev, u8 *data, int size) · 43 unmodified lines
2349 struct hidpp_report *report = (struct hidpp_report *)data;2376 struct hidpp_report *report = (struct hidpp_report *)data;
2350 struct hidpp_touchpad_raw_xy raw;2377 struct hidpp_touchpad_raw_xy raw;
2351 2378
2352 if (!wd || !wd->input)2379 if (!wd || !hidpp->input)
2353 return 1;2380 return 1;
2354 2381
2355 switch (data[0]) {2382 switch (data[0]) {
@@ -2360,11 +2387,11 @@ static int wtp_raw_event(struct hid_device *hdev, u8 *data, int size) · 4 unmodified lines
2360 return 1;2387 return 1;
2361 }2388 }
2362 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) {2389 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) {
2363 input_event(wd->input, EV_KEY, BTN_LEFT,2390 input_event(hidpp->input, EV_KEY, BTN_LEFT,
2364 !!(data[1] & 0x01));2391 !!(data[1] & 0x01));
2365 input_event(wd->input, EV_KEY, BTN_RIGHT,2392 input_event(hidpp->input, EV_KEY, BTN_RIGHT,
2366 !!(data[1] & 0x02));2393 !!(data[1] & 0x02));
2367 input_sync(wd->input);2394 input_sync(hidpp->input);
2368 return 0;2395 return 0;
2369 } else {2396 } else {
2370 if (size < 21)2397 if (size < 21)
@@ -2482,10 +2509,6 @@ static int wtp_connect(struct hid_device *hdev, bool connected) · 111 unmodified lines
2482 2509
2483static const u8 m560_config_parameter[] = {0x00, 0xaf, 0x03};2510static const u8 m560_config_parameter[] = {0x00, 0xaf, 0x03};
2484 2511
2485struct m560_private_data {
2486 struct input_dev *input;
2487};
2488
2489/* how buttons are mapped in the report */2512/* how buttons are mapped in the report */
2490#define M560_MOUSE_BTN_LEFT 0x012513#define M560_MOUSE_BTN_LEFT 0x01
2491#define M560_MOUSE_BTN_RIGHT 0x022514#define M560_MOUSE_BTN_RIGHT 0x02
@@ -2513,28 +2536,12 @@ static int m560_send_config_command(struct hid_device *hdev, bool connected) · 21 unmodified lines
2513 );2536 );
2514}2537}
2515 2538
2516static int m560_allocate(struct hid_device *hdev)
2517{
2518 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2519 struct m560_private_data *d;
2520
2521 d = devm_kzalloc(&hdev->dev, sizeof(struct m560_private_data),
2522 GFP_KERNEL);
2523 if (!d)
2524 return -ENOMEM;
2525
2526 hidpp->private_data = d;
2527
2528 return 0;
2529};
2530
2531static int m560_raw_event(struct hid_device *hdev, u8 *data, int size)2539static int m560_raw_event(struct hid_device *hdev, u8 *data, int size)
2532{2540{
2533 struct hidpp_device *hidpp = hid_get_drvdata(hdev);2541 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2534 struct m560_private_data *mydata = hidpp->private_data;
2535 2542
2536 /* sanity check */2543 /* sanity check */
2537 if (!mydata || !mydata->input) {2544 if (!hidpp->input) {
2538 hid_err(hdev, "error in parameter\n");2545 hid_err(hdev, "error in parameter\n");
2539 return -EINVAL;2546 return -EINVAL;
2540 }2547 }
@@ -2561,24 +2568,24 @@ static int m560_raw_event(struct hid_device *hdev, u8 *data, int size) · 20 unmodified lines
2561 2568
2562 switch (data[5]) {2569 switch (data[5]) {
2563 case 0xaf:2570 case 0xaf:
2564 input_report_key(mydata->input, BTN_MIDDLE, 1);2571 input_report_key(hidpp->input, BTN_MIDDLE, 1);
2565 break;2572 break;
2566 case 0xb0:2573 case 0xb0:
2567 input_report_key(mydata->input, BTN_FORWARD, 1);2574 input_report_key(hidpp->input, BTN_FORWARD, 1);
2568 break;2575 break;
2569 case 0xae:2576 case 0xae:
2570 input_report_key(mydata->input, BTN_BACK, 1);2577 input_report_key(hidpp->input, BTN_BACK, 1);
2571 break;2578 break;
2572 case 0x00:2579 case 0x00:
2573 input_report_key(mydata->input, BTN_BACK, 0);2580 input_report_key(hidpp->input, BTN_BACK, 0);
2574 input_report_key(mydata->input, BTN_FORWARD, 0);2581 input_report_key(hidpp->input, BTN_FORWARD, 0);
2575 input_report_key(mydata->input, BTN_MIDDLE, 0);2582 input_report_key(hidpp->input, BTN_MIDDLE, 0);
2576 break;2583 break;
2577 default:2584 default:
2578 hid_err(hdev, "error in report\n");2585 hid_err(hdev, "error in report\n");
2579 return 0;2586 return 0;
2580 }2587 }
2581 input_sync(mydata->input);2588 input_sync(hidpp->input);
2582 2589
2583 } else if (data[0] == 0x02) {2590 } else if (data[0] == 0x02) {
2584 /*2591 /*
@@ -2592,59 +2599,55 @@ static int m560_raw_event(struct hid_device *hdev, u8 *data, int size) · 7 unmodified lines
2592 2599
2593 int v;2600 int v;
2594 2601
2595 input_report_key(mydata->input, BTN_LEFT,2602 input_report_key(hidpp->input, BTN_LEFT,
2596 !!(data[1] & M560_MOUSE_BTN_LEFT));2603 !!(data[1] & M560_MOUSE_BTN_LEFT));
2597 input_report_key(mydata->input, BTN_RIGHT,2604 input_report_key(hidpp->input, BTN_RIGHT,
2598 !!(data[1] & M560_MOUSE_BTN_RIGHT));2605 !!(data[1] & M560_MOUSE_BTN_RIGHT));
2599 2606
2600 if (data[1] & M560_MOUSE_BTN_WHEEL_LEFT) {2607 if (data[1] & M560_MOUSE_BTN_WHEEL_LEFT) {
2601 input_report_rel(mydata->input, REL_HWHEEL, -1);2608 input_report_rel(hidpp->input, REL_HWHEEL, -1);
2602 input_report_rel(mydata->input, REL_HWHEEL_HI_RES,2609 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES,
2603 -120);2610 -120);
2604 } else if (data[1] & M560_MOUSE_BTN_WHEEL_RIGHT) {2611 } else if (data[1] & M560_MOUSE_BTN_WHEEL_RIGHT) {
2605 input_report_rel(mydata->input, REL_HWHEEL, 1);2612 input_report_rel(hidpp->input, REL_HWHEEL, 1);
2606 input_report_rel(mydata->input, REL_HWHEEL_HI_RES,2613 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES,
2607 120);2614 120);
2608 }2615 }
2609 2616
2610 v = hid_snto32(hid_field_extract(hdev, data+3, 0, 12), 12);2617 v = hid_snto32(hid_field_extract(hdev, data+3, 0, 12), 12);
2611 input_report_rel(mydata->input, REL_X, v);2618 input_report_rel(hidpp->input, REL_X, v);
2612 2619
2613 v = hid_snto32(hid_field_extract(hdev, data+3, 12, 12), 12);2620 v = hid_snto32(hid_field_extract(hdev, data+3, 12, 12), 12);
2614 input_report_rel(mydata->input, REL_Y, v);2621 input_report_rel(hidpp->input, REL_Y, v);
2615 2622
2616 v = hid_snto32(data[6], 8);2623 v = hid_snto32(data[6], 8);
2617 if (v != 0)2624 if (v != 0)
2618 hidpp_scroll_counter_handle_scroll(2625 hidpp_scroll_counter_handle_scroll(hidpp->input,
2619 &hidpp->vertical_wheel_counter, v);2626 &hidpp->vertical_wheel_counter, v);
2620 2627
2621 input_sync(mydata->input);2628 input_sync(hidpp->input);
2622 }2629 }
2623 2630
2624 return 1;2631 return 1;
2625}2632}
2626 2633
2627static void m560_populate_input(struct hidpp_device *hidpp,2634static void m560_populate_input(struct hidpp_device *hidpp,
2628 struct input_dev *input_dev, bool origin_is_hid_core)2635 struct input_dev *input_dev)
2629{2636{
2630 struct m560_private_data *mydata = hidpp->private_data;2637 __set_bit(EV_KEY, input_dev->evbit);
2631 2638 __set_bit(BTN_MIDDLE, input_dev->keybit);
2632 mydata->input = input_dev;2639 __set_bit(BTN_RIGHT, input_dev->keybit);
2633 2640 __set_bit(BTN_LEFT, input_dev->keybit);
2634 __set_bit(EV_KEY, mydata->input->evbit);2641 __set_bit(BTN_BACK, input_dev->keybit);
2635 __set_bit(BTN_MIDDLE, mydata->input->keybit);2642 __set_bit(BTN_FORWARD, input_dev->keybit);
2636 __set_bit(BTN_RIGHT, mydata->input->keybit);
2637 __set_bit(BTN_LEFT, mydata->input->keybit);
2638 __set_bit(BTN_BACK, mydata->input->keybit);
2639 __set_bit(BTN_FORWARD, mydata->input->keybit);
2640 2643
2641 __set_bit(EV_REL, mydata->input->evbit);2644 __set_bit(EV_REL, input_dev->evbit);
2642 __set_bit(REL_X, mydata->input->relbit);2645 __set_bit(REL_X, input_dev->relbit);
2643 __set_bit(REL_Y, mydata->input->relbit);2646 __set_bit(REL_Y, input_dev->relbit);
2644 __set_bit(REL_WHEEL, mydata->input->relbit);2647 __set_bit(REL_WHEEL, input_dev->relbit);
2645 __set_bit(REL_HWHEEL, mydata->input->relbit);2648 __set_bit(REL_HWHEEL, input_dev->relbit);
2646 __set_bit(REL_WHEEL_HI_RES, mydata->input->relbit);2649 __set_bit(REL_WHEEL_HI_RES, input_dev->relbit);
2647 __set_bit(REL_HWHEEL_HI_RES, mydata->input->relbit);2650 __set_bit(REL_HWHEEL_HI_RES, input_dev->relbit);
2648}2651}
2649 2652
2650static int m560_input_mapping(struct hid_device *hdev, struct hid_input *hi,2653static int m560_input_mapping(struct hid_device *hdev, struct hid_input *hi,
@@ -2746,6 +2749,175 @@ static int g920_get_config(struct hidpp_device *hidpp) · 95 unmodified lines
2746 return 0;2749 return 0;
2747}2750}
2748 2751
2752/* -------------------------------------------------------------------------- */
2753/* HID++1.0 devices which use HID++ reports for their wheels */
2754/* -------------------------------------------------------------------------- */
2755static int hidpp10_wheel_connect(struct hidpp_device *hidpp)
2756{
2757 return hidpp10_set_register(hidpp, HIDPP_REG_ENABLE_REPORTS, 0,
2758 HIDPP_ENABLE_WHEEL_REPORT | HIDPP_ENABLE_HWHEEL_REPORT,
2759 HIDPP_ENABLE_WHEEL_REPORT | HIDPP_ENABLE_HWHEEL_REPORT);
2760}
2761
2762static int hidpp10_wheel_raw_event(struct hidpp_device *hidpp,
2763 u8 *data, int size)
2764{
2765 s8 value, hvalue;
2766
2767 if (!hidpp->input)
2768 return -EINVAL;
2769
2770 if (size < 7)
2771 return 0;
2772
2773 if (data[0] != REPORT_ID_HIDPP_SHORT || data[2] != HIDPP_SUB_ID_ROLLER)
2774 return 0;
2775
2776 value = data[3];
2777 hvalue = data[4];
2778
2779 input_report_rel(hidpp->input, REL_WHEEL, value);
2780 input_report_rel(hidpp->input, REL_WHEEL_HI_RES, value * 120);
2781 input_report_rel(hidpp->input, REL_HWHEEL, hvalue);
2782 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES, hvalue * 120);
2783 input_sync(hidpp->input);
2784
2785 return 1;
2786}
2787
2788static void hidpp10_wheel_populate_input(struct hidpp_device *hidpp,
2789 struct input_dev *input_dev)
2790{
2791 __set_bit(EV_REL, input_dev->evbit);
2792 __set_bit(REL_WHEEL, input_dev->relbit);
2793 __set_bit(REL_WHEEL_HI_RES, input_dev->relbit);
2794 __set_bit(REL_HWHEEL, input_dev->relbit);
2795 __set_bit(REL_HWHEEL_HI_RES, input_dev->relbit);
2796}
2797
2798/* -------------------------------------------------------------------------- */
2799/* HID++1.0 mice which use HID++ reports for extra mouse buttons */
2800/* -------------------------------------------------------------------------- */
2801static int hidpp10_extra_mouse_buttons_connect(struct hidpp_device *hidpp)
2802{
2803 return hidpp10_set_register(hidpp, HIDPP_REG_ENABLE_REPORTS, 0,
2804 HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT,
2805 HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT);
2806}
2807
2808static int hidpp10_extra_mouse_buttons_raw_event(struct hidpp_device *hidpp,
2809 u8 *data, int size)
2810{
2811 int i;
2812
2813 if (!hidpp->input)
2814 return -EINVAL;
2815
2816 if (size < 7)
2817 return 0;
2818
2819 if (data[0] != REPORT_ID_HIDPP_SHORT ||
2820 data[2] != HIDPP_SUB_ID_MOUSE_EXTRA_BTNS)
2821 return 0;
2822
2823 /*
2824 * Buttons are either delivered through the regular mouse report *or*
2825 * through the extra buttons report. At least for button 6 how it is
2826 * delivered differs per receiver firmware version. Even receivers with
2827 * the same usb-id show different behavior, so we handle both cases.
2828 */
2829 for (i = 0; i < 8; i++)
2830 input_report_key(hidpp->input, BTN_MOUSE + i,
2831 (data[3] & (1 << i)));
2832
2833 /* Some mice report events on button 9+, use BTN_MISC */
2834 for (i = 0; i < 8; i++)
2835 input_report_key(hidpp->input, BTN_MISC + i,
2836 (data[4] & (1 << i)));
2837
2838 input_sync(hidpp->input);
2839 return 1;
2840}
2841
2842static void hidpp10_extra_mouse_buttons_populate_input(
2843 struct hidpp_device *hidpp, struct input_dev *input_dev)
2844{
2845 /* BTN_MOUSE - BTN_MOUSE+7 are set already by the descriptor */
2846 __set_bit(BTN_0, input_dev->keybit);
2847 __set_bit(BTN_1, input_dev->keybit);
2848 __set_bit(BTN_2, input_dev->keybit);
2849 __set_bit(BTN_3, input_dev->keybit);
2850 __set_bit(BTN_4, input_dev->keybit);
2851 __set_bit(BTN_5, input_dev->keybit);
2852 __set_bit(BTN_6, input_dev->keybit);
2853 __set_bit(BTN_7, input_dev->keybit);
2854}
2855
2856/* -------------------------------------------------------------------------- */
2857/* HID++1.0 kbds which only report 0x10xx consumer usages through sub-id 0x03 */
2858/* -------------------------------------------------------------------------- */
2859
2860/* Find the consumer-page input report desc and change Maximums to 0x107f */
2861static u8 *hidpp10_consumer_keys_report_fixup(struct hidpp_device *hidpp,
2862 u8 *_rdesc, unsigned int *rsize)
2863{
2864 /* Note 0 terminated so we can use strnstr to search for this. */
2865 const char consumer_rdesc_start[] = {
2866 0x05, 0x0C, /* USAGE_PAGE (Consumer Devices) */
2867 0x09, 0x01, /* USAGE (Consumer Control) */
2868 0xA1, 0x01, /* COLLECTION (Application) */
2869 0x85, 0x03, /* REPORT_ID = 3 */
2870 0x75, 0x10, /* REPORT_SIZE (16) */
2871 0x95, 0x02, /* REPORT_COUNT (2) */
2872 0x15, 0x01, /* LOGICAL_MIN (1) */
2873 0x26, 0x00 /* LOGICAL_MAX (... */
2874 };
2875 char *consumer_rdesc, *rdesc = (char *)_rdesc;
2876 unsigned int size;
2877
2878 consumer_rdesc = strnstr(rdesc, consumer_rdesc_start, *rsize);
2879 size = *rsize - (consumer_rdesc - rdesc);
2880 if (consumer_rdesc && size >= 25) {
2881 consumer_rdesc[15] = 0x7f;
2882 consumer_rdesc[16] = 0x10;
2883 consumer_rdesc[20] = 0x7f;
2884 consumer_rdesc[21] = 0x10;
2885 }
2886 return _rdesc;
2887}
2888
2889static int hidpp10_consumer_keys_connect(struct hidpp_device *hidpp)
2890{
2891 return hidpp10_set_register(hidpp, HIDPP_REG_ENABLE_REPORTS, 0,
2892 HIDPP_ENABLE_CONSUMER_REPORT,
2893 HIDPP_ENABLE_CONSUMER_REPORT);
2894}
2895
2896static int hidpp10_consumer_keys_raw_event(struct hidpp_device *hidpp,
2897 u8 *data, int size)
2898{
2899 u8 consumer_report[5];
2900
2901 if (size < 7)
2902 return 0;
2903
2904 if (data[0] != REPORT_ID_HIDPP_SHORT ||
2905 data[2] != HIDPP_SUB_ID_CONSUMER_VENDOR_KEYS)
2906 return 0;
2907
2908 /*
2909 * Build a normal consumer report (3) out of the data, this detour
2910 * is necessary to get some keyboards to report their 0x10xx usages.
2911 */
2912 consumer_report[0] = 0x03;
2913 memcpy(&consumer_report[1], &data[3], 4);
2914 /* We are called from atomic context */
2915 hid_report_raw_event(hidpp->hid_dev, HID_INPUT_REPORT,
2916 consumer_report, 5, 1);
2917
2918 return 1;
2919}
2920
2749/* -------------------------------------------------------------------------- */2921/* -------------------------------------------------------------------------- */
2750/* High-resolution scroll wheels */2922/* High-resolution scroll wheels */
2751/* -------------------------------------------------------------------------- */2923/* -------------------------------------------------------------------------- */
@@ -2781,12 +2953,31 @@ static int hi_res_scroll_enable(struct hidpp_device *hidpp) · 29 unmodified lines
2781/* Generic HID++ devices */2953/* Generic HID++ devices */
2782/* -------------------------------------------------------------------------- */2954/* -------------------------------------------------------------------------- */
2783 2955
2956static u8 *hidpp_report_fixup(struct hid_device *hdev, u8 *rdesc,
2957 unsigned int *rsize)
2958{
2959 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2960
2961 if (!hidpp)
2962 return rdesc;
2963
2964 /* For 27 MHz keyboards the quirk gets set after hid_parse. */
2965 if (hdev->group == HID_GROUP_LOGITECH_27MHZ_DEVICE ||
2966 (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS))
2967 rdesc = hidpp10_consumer_keys_report_fixup(hidpp, rdesc, rsize);
2968
2969 return rdesc;
2970}
2971
2784static int hidpp_input_mapping(struct hid_device *hdev, struct hid_input *hi,2972static int hidpp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
2785 struct hid_field *field, struct hid_usage *usage,2973 struct hid_field *field, struct hid_usage *usage,
2786 unsigned long **bit, int *max)2974 unsigned long **bit, int *max)
2787{2975{
2788 struct hidpp_device *hidpp = hid_get_drvdata(hdev);2976 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2789 2977
2978 if (!hidpp)
2979 return 0;
2980
2790 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)2981 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
2791 return wtp_input_mapping(hdev, hi, field, usage, bit, max);2982 return wtp_input_mapping(hdev, hi, field, usage, bit, max);
2792 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560 &&2983 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560 &&
@@ -2802,6 +2993,9 @@ static int hidpp_input_mapped(struct hid_device *hdev, struct hid_input *hi, · 9 unmodified lines
2802{2993{
2803 struct hidpp_device *hidpp = hid_get_drvdata(hdev);2994 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2804 2995
2996 if (!hidpp)
2997 return 0;
2998
2805 /* Ensure that Logitech G920 is not given a default fuzz/flat value */2999 /* Ensure that Logitech G920 is not given a default fuzz/flat value */
2806 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) {3000 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) {
2807 if (usage->type == EV_ABS && (usage->code == ABS_X ||3001 if (usage->type == EV_ABS && (usage->code == ABS_X ||
@@ -2816,15 +3010,20 @@ static int hidpp_input_mapped(struct hid_device *hdev, struct hid_input *hi, · 8 unmodified lines
2816 3010
2817 3011
2818static void hidpp_populate_input(struct hidpp_device *hidpp,3012static void hidpp_populate_input(struct hidpp_device *hidpp,
2819 struct input_dev *input, bool origin_is_hid_core)3013 struct input_dev *input)
2820{3014{
3015 hidpp->input = input;
3016
2821 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)3017 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
2822 wtp_populate_input(hidpp, input, origin_is_hid_core);3018 wtp_populate_input(hidpp, input);
2823 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560)3019 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560)
2824 m560_populate_input(hidpp, input, origin_is_hid_core);3020 m560_populate_input(hidpp, input);
2825 3021
2826 if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL)3022 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS)
2827 hidpp->vertical_wheel_counter.dev = input;3023 hidpp10_wheel_populate_input(hidpp, input);
3024
3025 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS)
3026 hidpp10_extra_mouse_buttons_populate_input(hidpp, input);
2828}3027}
2829 3028
2830static int hidpp_input_configured(struct hid_device *hdev,3029static int hidpp_input_configured(struct hid_device *hdev,
@@ -2833,7 +3032,10 @@ static int hidpp_input_configured(struct hid_device *hdev, · 2 unmodified lines
2833 struct hidpp_device *hidpp = hid_get_drvdata(hdev);3032 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2834 struct input_dev *input = hidinput->input;3033 struct input_dev *input = hidinput->input;
2835 3034
2836 hidpp_populate_input(hidpp, input, true);3035 if (!hidpp)
3036 return 0;
3037
3038 hidpp_populate_input(hidpp, input);
2837 3039
2838 return 0;3040 return 0;
2839}3041}
@@ -2893,6 +3095,24 @@ static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data, · 53 unmodified lines
2893 return ret;3095 return ret;
2894 }3096 }
2895 3097
3098 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) {
3099 ret = hidpp10_wheel_raw_event(hidpp, data, size);
3100 if (ret != 0)
3101 return ret;
3102 }
3103
3104 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) {
3105 ret = hidpp10_extra_mouse_buttons_raw_event(hidpp, data, size);
3106 if (ret != 0)
3107 return ret;
3108 }
3109
3110 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS) {
3111 ret = hidpp10_consumer_keys_raw_event(hidpp, data, size);
3112 if (ret != 0)
3113 return ret;
3114 }
3115
2896 return 0;3116 return 0;
2897}3117}
2898 3118
@@ -2902,10 +3122,13 @@ static int hidpp_raw_event(struct hid_device *hdev, struct hid_report *report, · 3 unmodified lines
2902 struct hidpp_device *hidpp = hid_get_drvdata(hdev);3122 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2903 int ret = 0;3123 int ret = 0;
2904 3124
3125 if (!hidpp)
3126 return 0;
3127
2905 /* Generic HID++ processing. */3128 /* Generic HID++ processing. */
2906 switch (data[0]) {3129 switch (data[0]) {
2907 case REPORT_ID_HIDPP_VERY_LONG:3130 case REPORT_ID_HIDPP_VERY_LONG:
2908 if (size != HIDPP_REPORT_VERY_LONG_LENGTH) {3131 if (size != hidpp->very_long_report_length) {
2909 hid_err(hdev, "received hid++ report of bad size (%d)",3132 hid_err(hdev, "received hid++ report of bad size (%d)",
2910 size);3133 size);
2911 return 1;3134 return 1;
@@ -2950,17 +3173,22 @@ static int hidpp_event(struct hid_device *hdev, struct hid_field *field, · 38 unmodified lines
2950 * restriction imposed in hidpp_usages.3173 * restriction imposed in hidpp_usages.
2951 */3174 */
2952 struct hidpp_device *hidpp = hid_get_drvdata(hdev);3175 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2953 struct hidpp_scroll_counter *counter = &hidpp->vertical_wheel_counter;3176 struct hidpp_scroll_counter *counter;
3177
3178 if (!hidpp)
3179 return 0;
3180
3181 counter = &hidpp->vertical_wheel_counter;
2954 /* A scroll event may occur before the multiplier has been retrieved or3182 /* A scroll event may occur before the multiplier has been retrieved or
2955 * the input device set, or high-res scroll enabling may fail. In such3183 * the input device set, or high-res scroll enabling may fail. In such
2956 * cases we must return early (falling back to default behaviour) to3184 * cases we must return early (falling back to default behaviour) to
2957 * avoid a crash in hidpp_scroll_counter_handle_scroll.3185 * avoid a crash in hidpp_scroll_counter_handle_scroll.
2958 */3186 */
2959 if (!(hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL) || value == 03187 if (!(hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL) || value == 0
2960 || counter->dev == NULL || counter->wheel_multiplier == 0)3188 || hidpp->input == NULL || counter->wheel_multiplier == 0)
2961 return 0;3189 return 0;
2962 3190
2963 hidpp_scroll_counter_handle_scroll(counter, value);3191 hidpp_scroll_counter_handle_scroll(hidpp->input, counter, value);
2964 return 1;3192 return 1;
2965}3193}
2966 3194
@@ -3132,32 +3360,45 @@ static void hidpp_connect_event(struct hidpp_device *hidpp) · 165 unmodified lines
3132 return;3360 return;
3133 }3361 }
3134 3362
3363 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) {
3364 ret = hidpp10_wheel_connect(hidpp);
3365 if (ret)
3366 return;
3367 }
3368
3369 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) {
3370 ret = hidpp10_extra_mouse_buttons_connect(hidpp);
3371 if (ret)
3372 return;
3373 }
3374
3375 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS) {
3376 ret = hidpp10_consumer_keys_connect(hidpp);
3377 if (ret)
3378 return;
3379 }
3380
3135 /* the device is already connected, we can ask for its name and3381 /* the device is already connected, we can ask for its name and
3136 * protocol */3382 * protocol */
3137 if (!hidpp->protocol_major) {3383 if (!hidpp->protocol_major) {
3138 ret = !hidpp_is_connected(hidpp);3384 ret = hidpp_root_get_protocol_version(hidpp);
3139 if (ret) {3385 if (ret) {
3140 hid_err(hdev, "Can not get the protocol version.\n");3386 hid_err(hdev, "Can not get the protocol version.\n");
3141 return;3387 return;
3142 }3388 }
3143 hid_info(hdev, "HID++ %u.%u device connected.\n",
3144 hidpp->protocol_major, hidpp->protocol_minor);
3145 }3389 }
3146 3390
3147 if (hidpp->name == hdev->name && hidpp->protocol_major >= 2) {3391 if (hidpp->name == hdev->name && hidpp->protocol_major >= 2) {
3148 name = hidpp_get_device_name(hidpp);3392 name = hidpp_get_device_name(hidpp);
3149 if (!name) {3393 if (name) {
3150 hid_err(hdev,3394 devm_name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
3151 "unable to retrieve the name of the device");3395 "%s", name);
3152 return;3396 kfree(name);
3153 }3397 if (!devm_name)
3154 3398 return;
3155 devm_name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "%s", name);
3156 kfree(name);
3157 if (!devm_name)
3158 return;
3159 3399
3160 hidpp->name = devm_name;3400 hidpp->name = devm_name;
3401 }
3161 }3402 }
3162 3403
3163 hidpp_initialize_battery(hidpp);3404 hidpp_initialize_battery(hidpp);
@@ -3188,7 +3429,7 @@ static void hidpp_connect_event(struct hidpp_device *hidpp) · 24 unmodified lines
3188 return;3429 return;
3189 }3430 }
3190 3431
3191 hidpp_populate_input(hidpp, input, false);3432 hidpp_populate_input(hidpp, input);
3192 3433
3193 ret = input_register_device(input);3434 ret = input_register_device(input);
3194 if (ret)3435 if (ret)
@@ -3208,6 +3449,60 @@ static const struct attribute_group ps_attribute_group = { · 13 unmodified lines
3208 .attrs = sysfs_attrs3449 .attrs = sysfs_attrs
3209};3450};
3210 3451
3452static int hidpp_get_report_length(struct hid_device *hdev, int id)
3453{
3454 struct hid_report_enum *re;
3455 struct hid_report *report;
3456
3457 re = &(hdev->report_enum[HID_OUTPUT_REPORT]);
3458 report = re->report_id_hash[id];
3459 if (!report)
3460 return 0;
3461
3462 return report->field[0]->report_count + 1;
3463}
3464
3465static bool hidpp_validate_report(struct hid_device *hdev, int id,
3466 int expected_length, bool optional)
3467{
3468 int report_length;
3469
3470 if (id >= HID_MAX_IDS || id < 0) {
3471 hid_err(hdev, "invalid HID report id %u\n", id);
3472 return false;
3473 }
3474
3475 report_length = hidpp_get_report_length(hdev, id);
3476 if (!report_length)
3477 return optional;
3478
3479 if (report_length < expected_length) {
3480 hid_warn(hdev, "not enough values in hidpp report %d\n", id);
3481 return false;
3482 }
3483
3484 return true;
3485}
3486
3487static bool hidpp_validate_device(struct hid_device *hdev)
3488{
3489 return hidpp_validate_report(hdev, REPORT_ID_HIDPP_SHORT,
3490 HIDPP_REPORT_SHORT_LENGTH, false) &&
3491 hidpp_validate_report(hdev, REPORT_ID_HIDPP_LONG,
3492 HIDPP_REPORT_LONG_LENGTH, true);
3493}
3494
3495static bool hidpp_application_equals(struct hid_device *hdev,
3496 unsigned int application)
3497{
3498 struct list_head *report_list;
3499 struct hid_report *report;
3500
3501 report_list = &hdev->report_enum[HID_INPUT_REPORT].report_list;
3502 report = list_first_entry_or_null(report_list, struct hid_report, list);
3503 return report && report->application == application;
3504}
3505
3211static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)3506static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
3212{3507{
3213 struct hidpp_device *hidpp;3508 struct hidpp_device *hidpp;
@@ -3215,20 +3510,48 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) · 1 unmodified line
3215 bool connected;3510 bool connected;
3216 unsigned int connect_mask = HID_CONNECT_DEFAULT;3511 unsigned int connect_mask = HID_CONNECT_DEFAULT;
3217 3512
3218 hidpp = devm_kzalloc(&hdev->dev, sizeof(struct hidpp_device),3513 /* report_fixup needs drvdata to be set before we call hid_parse */
3219 GFP_KERNEL);3514 hidpp = devm_kzalloc(&hdev->dev, sizeof(*hidpp), GFP_KERNEL);
3220 if (!hidpp)3515 if (!hidpp)
3221 return -ENOMEM;3516 return -ENOMEM;
3222 3517
3223 hidpp->hid_dev = hdev;3518 hidpp->hid_dev = hdev;
3224 hidpp->name = hdev->name;3519 hidpp->name = hdev->name;
3520 hidpp->quirks = id->driver_data;
3225 hid_set_drvdata(hdev, hidpp);3521 hid_set_drvdata(hdev, hidpp);
3226 3522
3227 hidpp->quirks = id->driver_data;3523 ret = hid_parse(hdev);
3524 if (ret) {
3525 hid_err(hdev, "%s:parse failed\n", __func__);
3526 return ret;
3527 }
3528
3529 /*
3530 * Make sure the device is HID++ capable, otherwise treat as generic HID
3531 */
3532 if (!hidpp_validate_device(hdev)) {
3533 hid_set_drvdata(hdev, NULL);
3534 devm_kfree(&hdev->dev, hidpp);
3535 return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
3536 }
3537
3538 hidpp->very_long_report_length =
3539 hidpp_get_report_length(hdev, REPORT_ID_HIDPP_VERY_LONG);
3540 if (hidpp->very_long_report_length > HIDPP_REPORT_VERY_LONG_MAX_LENGTH)
3541 hidpp->very_long_report_length = HIDPP_REPORT_VERY_LONG_MAX_LENGTH;
3228 3542
3229 if (id->group == HID_GROUP_LOGITECH_DJ_DEVICE)3543 if (id->group == HID_GROUP_LOGITECH_DJ_DEVICE)
3230 hidpp->quirks |= HIDPP_QUIRK_UNIFYING;3544 hidpp->quirks |= HIDPP_QUIRK_UNIFYING;
3231 3545
3546 if (id->group == HID_GROUP_LOGITECH_27MHZ_DEVICE &&
3547 hidpp_application_equals(hdev, HID_GD_MOUSE))
3548 hidpp->quirks |= HIDPP_QUIRK_HIDPP_WHEELS |
3549 HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS;
3550
3551 if (id->group == HID_GROUP_LOGITECH_27MHZ_DEVICE &&
3552 hidpp_application_equals(hdev, HID_GD_KEYBOARD))
3553 hidpp->quirks |= HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS;
3554
3232 if (disable_raw_mode) {3555 if (disable_raw_mode) {
3233 hidpp->quirks &= ~HIDPP_QUIRK_CLASS_WTP;3556 hidpp->quirks &= ~HIDPP_QUIRK_CLASS_WTP;
3234 hidpp->quirks &= ~HIDPP_QUIRK_NO_HIDINPUT;3557 hidpp->quirks &= ~HIDPP_QUIRK_NO_HIDINPUT;
@@ -3237,15 +3560,11 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) · 2 unmodified lines
3237 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) {3560 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) {
3238 ret = wtp_allocate(hdev, id);3561 ret = wtp_allocate(hdev, id);
3239 if (ret)3562 if (ret)
3240 goto allocate_fail;3563 return ret;
3241 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) {
3242 ret = m560_allocate(hdev);
3243 if (ret)
3244 goto allocate_fail;
3245 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) {3564 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) {
3246 ret = k400_allocate(hdev);3565 ret = k400_allocate(hdev);
3247 if (ret)3566 if (ret)
3248 goto allocate_fail;3567 return ret;
3249 }3568 }
3250 3569
3251 INIT_WORK(&hidpp->work, delayed_work_cb);3570 INIT_WORK(&hidpp->work, delayed_work_cb);
@@ -3258,93 +3577,79 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) · 6 unmodified lines
3258 hid_warn(hdev, "Cannot allocate sysfs group for %s\n",3577 hid_warn(hdev, "Cannot allocate sysfs group for %s\n",
3259 hdev->name);3578 hdev->name);
3260 3579
3261 ret = hid_parse(hdev);3580 /*
3581 * Plain USB connections need to actually call start and open
3582 * on the transport driver to allow incoming data.
3583 */
3584 ret = hid_hw_start(hdev, 0);
3262 if (ret) {3585 if (ret) {
3263 hid_err(hdev, "%s:parse failed\n", __func__);3586 hid_err(hdev, "hw start failed\n");
3264 goto hid_parse_fail;3587 goto hid_hw_start_fail;
3265 }3588 }
3266 3589
3267 if (hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT)3590 ret = hid_hw_open(hdev);
3268 connect_mask &= ~HID_CONNECT_HIDINPUT;3591 if (ret < 0) {
3269 3592 dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n",
3270 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) {3593 __func__, ret);
3271 ret = hid_hw_start(hdev, connect_mask);3594 hid_hw_stop(hdev);
3272 if (ret) {3595 goto hid_hw_open_fail;
3273 hid_err(hdev, "hw start failed\n");
3274 goto hid_hw_start_fail;
3275 }
3276 ret = hid_hw_open(hdev);
3277 if (ret < 0) {
3278 dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n",
3279 __func__, ret);
3280 hid_hw_stop(hdev);
3281 goto hid_hw_start_fail;
3282 }
3283 }3596 }
3284 3597
3285
3286 /* Allow incoming packets */3598 /* Allow incoming packets */
3287 hid_device_io_start(hdev);3599 hid_device_io_start(hdev);
3288 3600
3289 if (hidpp->quirks & HIDPP_QUIRK_UNIFYING)3601 if (hidpp->quirks & HIDPP_QUIRK_UNIFYING)
3290 hidpp_unifying_init(hidpp);3602 hidpp_unifying_init(hidpp);
3291 3603
3292 connected = hidpp_is_connected(hidpp);3604 connected = hidpp_root_get_protocol_version(hidpp) == 0;
3293 atomic_set(&hidpp->connected, connected);3605 atomic_set(&hidpp->connected, connected);
3294 if (!(hidpp->quirks & HIDPP_QUIRK_UNIFYING)) {3606 if (!(hidpp->quirks & HIDPP_QUIRK_UNIFYING)) {
3295 if (!connected) {3607 if (!connected) {
3296 ret = -ENODEV;3608 ret = -ENODEV;
3297 hid_err(hdev, "Device not connected");3609 hid_err(hdev, "Device not connected");
3298 goto hid_hw_open_failed;3610 goto hid_hw_init_fail;
3299 }3611 }
3300 3612
3301 hid_info(hdev, "HID++ %u.%u device connected.\n",
3302 hidpp->protocol_major, hidpp->protocol_minor);
3303
3304 hidpp_overwrite_name(hdev);3613 hidpp_overwrite_name(hdev);
3305 }3614 }
3306 3615
3307 if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) {3616 if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) {
3308 ret = wtp_get_config(hidpp);3617 ret = wtp_get_config(hidpp);
3309 if (ret)3618 if (ret)
3310 goto hid_hw_open_failed;3619 goto hid_hw_init_fail;
3311 } else if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) {3620 } else if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) {
3312 ret = g920_get_config(hidpp);3621 ret = g920_get_config(hidpp);
3313 if (ret)3622 if (ret)
3314 goto hid_hw_open_failed;3623 goto hid_hw_init_fail;
3315 }3624 }
3316 3625
3317 /* Block incoming packets */3626 hidpp_connect_event(hidpp);
3318 hid_device_io_stop(hdev);
3319 3627
3320 if (!(hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) {3628 /* Reset the HID node state */
3321 ret = hid_hw_start(hdev, connect_mask);3629 hid_device_io_stop(hdev);
3322 if (ret) {3630 hid_hw_close(hdev);
3323 hid_err(hdev, "%s:hid_hw_start returned error\n", __func__);3631 hid_hw_stop(hdev);
3324 goto hid_hw_start_fail;
3325 }
3326 }
3327 3632
3328 /* Allow incoming packets */3633 if (hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT)
3329 hid_device_io_start(hdev);3634 connect_mask &= ~HID_CONNECT_HIDINPUT;
3330 3635
3331 hidpp_connect_event(hidpp);3636 /* Now export the actual inputs and hidraw nodes to the world */
3637 ret = hid_hw_start(hdev, connect_mask);
3638 if (ret) {
3639 hid_err(hdev, "%s:hid_hw_start returned error\n", __func__);
3640 goto hid_hw_start_fail;
3641 }
3332 3642
3333 return ret;3643 return ret;
3334 3644
3335hid_hw_open_failed:3645hid_hw_init_fail:
3336 hid_device_io_stop(hdev);3646 hid_hw_close(hdev);
3337 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) {3647hid_hw_open_fail:
3338 hid_hw_close(hdev);3648 hid_hw_stop(hdev);
3339 hid_hw_stop(hdev);
3340 }
3341hid_hw_start_fail:3649hid_hw_start_fail:
3342hid_parse_fail:
3343 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);3650 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);
3344 cancel_work_sync(&hidpp->work);3651 cancel_work_sync(&hidpp->work);
3345 mutex_destroy(&hidpp->send_mutex);3652 mutex_destroy(&hidpp->send_mutex);
3346allocate_fail:
3347 hid_set_drvdata(hdev, NULL);
3348 return ret;3653 return ret;
3349}3654}
3350 3655
@@ -3352,12 +3657,14 @@ static void hidpp_remove(struct hid_device *hdev) · 1 unmodified line
3352{3657{
3353 struct hidpp_device *hidpp = hid_get_drvdata(hdev);3658 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3354 3659
3660 if (!hidpp)
3661 return hid_hw_stop(hdev);
3662
3355 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);3663 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);
3356 3664
3357 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) {3665 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)
3358 hidpp_ff_deinit(hdev);3666 hidpp_ff_deinit(hdev);
3359 hid_hw_close(hdev);3667
3360 }
3361 hid_hw_stop(hdev);3668 hid_hw_stop(hdev);
3362 cancel_work_sync(&hidpp->work);3669 cancel_work_sync(&hidpp->work);
3363 mutex_destroy(&hidpp->send_mutex);3670 mutex_destroy(&hidpp->send_mutex);
@@ -3367,6 +3674,10 @@ static void hidpp_remove(struct hid_device *hdev) · 3 unmodified lines
3367 HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE, \3674 HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE, \
3368 USB_VENDOR_ID_LOGITECH, (product))3675 USB_VENDOR_ID_LOGITECH, (product))
3369 3676
3677#define L27MHZ_DEVICE(product) \
3678 HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_27MHZ_DEVICE, \
3679 USB_VENDOR_ID_LOGITECH, (product))
3680
3370static const struct hid_device_id hidpp_devices[] = {3681static const struct hid_device_id hidpp_devices[] = {
3371 { /* wireless touchpad */3682 { /* wireless touchpad */
3372 LDJ_DEVICE(0x4011),3683 LDJ_DEVICE(0x4011),
@@ -3418,11 +3729,37 @@ static const struct hid_device_id hidpp_devices[] = { · 45 unmodified lines
3418 { /* Solar Keyboard Logitech K750 */3729 { /* Solar Keyboard Logitech K750 */
3419 LDJ_DEVICE(0x4002),3730 LDJ_DEVICE(0x4002),
3420 .driver_data = HIDPP_QUIRK_CLASS_K750 },3731 .driver_data = HIDPP_QUIRK_CLASS_K750 },
3732 { /* Keyboard MX5000 (Bluetooth-receiver in HID proxy mode) */
3733 LDJ_DEVICE(0xb305),
3734 .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
3421 3735
3422 { LDJ_DEVICE(HID_ANY_ID) },3736 { LDJ_DEVICE(HID_ANY_ID) },
3423 3737
3424 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G920_WHEEL),3738 { /* Keyboard LX501 (Y-RR53) */
3739 L27MHZ_DEVICE(0x0049),
3740 .driver_data = HIDPP_QUIRK_KBD_ZOOM_WHEEL },
3741 { /* Keyboard MX3000 (Y-RAM74) */
3742 L27MHZ_DEVICE(0x0057),
3743 .driver_data = HIDPP_QUIRK_KBD_SCROLL_WHEEL },
3744 { /* Keyboard MX3200 (Y-RAV80) */
3745 L27MHZ_DEVICE(0x005c),
3746 .driver_data = HIDPP_QUIRK_KBD_ZOOM_WHEEL },
3747
3748 { L27MHZ_DEVICE(HID_ANY_ID) },
3749
3750 { /* Logitech G403 Gaming Mouse over USB */
3751 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC082) },
3752 { /* Logitech G700 Gaming Mouse over USB */
3753 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC06B) },
3754 { /* Logitech G900 Gaming Mouse over USB */
3755 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC081) },
3756 { /* Logitech G920 Wheel over USB */
3757 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G920_WHEEL),
3425 .driver_data = HIDPP_QUIRK_CLASS_G920 | HIDPP_QUIRK_FORCE_OUTPUT_REPORTS},3758 .driver_data = HIDPP_QUIRK_CLASS_G920 | HIDPP_QUIRK_FORCE_OUTPUT_REPORTS},
3759
3760 { /* MX5000 keyboard over Bluetooth */
3761 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb305),
3762 .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
3426 {}3763 {}
3427};3764};
3428 3765
@@ -3436,6 +3773,7 @@ static const struct hid_usage_id hidpp_usages[] = { · 7 unmodified lines
3436static struct hid_driver hidpp_driver = {3773static struct hid_driver hidpp_driver = {
3437 .name = "logitech-hidpp-device",3774 .name = "logitech-hidpp-device",
3438 .id_table = hidpp_devices,3775 .id_table = hidpp_devices,
3776 .report_fixup = hidpp_report_fixup,
3439 .probe = hidpp_probe,3777 .probe = hidpp_probe,
3440 .remove = hidpp_remove,3778 .remove = hidpp_remove,
3441 .raw_event = hidpp_raw_event,3779 .raw_event = hidpp_raw_event,
drivers/hid/hid-macally.c+45−0
@@ -0,0 +1,45 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * HID driver for quirky Macally devices
4 *
5 * Copyright (c) 2019 Alex Henrie <alexhenrie24@gmail.com>
6 */
7
8#include <linux/hid.h>
9#include <linux/module.h>
10
11#include "hid-ids.h"
12
13MODULE_AUTHOR("Alex Henrie <alexhenrie24@gmail.com>");
14MODULE_DESCRIPTION("Macally devices");
15MODULE_LICENSE("GPL");
16
17/*
18 * The Macally ikey keyboard says that its logical and usage maximums are both
19 * 101, but the power key is 102 and the equals key is 103
20 */
21static __u8 *macally_report_fixup(struct hid_device *hdev, __u8 *rdesc,
22 unsigned int *rsize)
23{
24 if (*rsize >= 60 && rdesc[53] == 0x65 && rdesc[59] == 0x65) {
25 hid_info(hdev,
26 "fixing up Macally ikey keyboard report descriptor\n");
27 rdesc[53] = rdesc[59] = 0x67;
28 }
29 return rdesc;
30}
31
32static struct hid_device_id macally_id_table[] = {
33 { HID_USB_DEVICE(USB_VENDOR_ID_SOLID_YEAR,
34 USB_DEVICE_ID_MACALLY_IKEY_KEYBOARD) },
35 { }
36};
37MODULE_DEVICE_TABLE(hid, macally_id_table);
38
39static struct hid_driver macally_driver = {
40 .name = "macally",
41 .id_table = macally_id_table,
42 .report_fixup = macally_report_fixup,
43};
44
45module_hid_driver(macally_driver);
drivers/hid/hid-picolcd_core.c+6−12
@@ -28,6 +28,7 @@ · 27 unmodified lines
28#include <linux/completion.h>28#include <linux/completion.h>
29#include <linux/uaccess.h>29#include <linux/uaccess.h>
30#include <linux/module.h>30#include <linux/module.h>
31#include <linux/string.h>
31 32
32#include "hid-picolcd.h"33#include "hid-picolcd.h"
33 34
@@ -275,27 +276,20 @@ static ssize_t picolcd_operation_mode_store(struct device *dev, · 241 unmodified lines
275{276{
276 struct picolcd_data *data = dev_get_drvdata(dev);277 struct picolcd_data *data = dev_get_drvdata(dev);
277 struct hid_report *report = NULL;278 struct hid_report *report = NULL;
278 size_t cnt = count;
279 int timeout = data->opmode_delay;279 int timeout = data->opmode_delay;
280 unsigned long flags;280 unsigned long flags;
281 281
282 if (cnt >= 3 && strncmp("lcd", buf, 3) == 0) {282 if (sysfs_streq(buf, "lcd")) {
283 if (data->status & PICOLCD_BOOTLOADER)283 if (data->status & PICOLCD_BOOTLOADER)
284 report = picolcd_out_report(REPORT_EXIT_FLASHER, data->hdev);284 report = picolcd_out_report(REPORT_EXIT_FLASHER, data->hdev);
285 buf += 3;285 } else if (sysfs_streq(buf, "bootloader")) {
286 cnt -= 3;
287 } else if (cnt >= 10 && strncmp("bootloader", buf, 10) == 0) {
288 if (!(data->status & PICOLCD_BOOTLOADER))286 if (!(data->status & PICOLCD_BOOTLOADER))
289 report = picolcd_out_report(REPORT_EXIT_KEYBOARD, data->hdev);287 report = picolcd_out_report(REPORT_EXIT_KEYBOARD, data->hdev);
290 buf += 10;288 } else {
291 cnt -= 10;
292 }
293 if (!report || report->maxfield != 1)
294 return -EINVAL;289 return -EINVAL;
290 }
295 291
296 while (cnt > 0 && (buf[cnt-1] == '\n' || buf[cnt-1] == '\r'))292 if (!report || report->maxfield != 1)
297 cnt--;
298 if (cnt != 0)
299 return -EINVAL;293 return -EINVAL;
300 294
301 spin_lock_irqsave(&data->lock, flags);295 spin_lock_irqsave(&data->lock, flags);
drivers/hid/hid-quirks.c+0−6
@@ -432,7 +432,6 @@ static const struct hid_device_id hid_have_special_driver[] = { · 431 unmodified lines
432#if IS_ENABLED(CONFIG_HID_LOGITECH)432#if IS_ENABLED(CONFIG_HID_LOGITECH)
433 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },433 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
434 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },434 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
435 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
436 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },435 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
437 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },436 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
438 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },437 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
@@ -464,13 +463,8 @@ static const struct hid_device_id hid_have_special_driver[] = { · 25 unmodified lines
464 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },463 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
465#endif464#endif
466#if IS_ENABLED(CONFIG_HID_LOGITECH_HIDPP)465#if IS_ENABLED(CONFIG_HID_LOGITECH_HIDPP)
467 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_T651) },
468 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G920_WHEEL) },466 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G920_WHEEL) },
469#endif467#endif
470#if IS_ENABLED(CONFIG_HID_LOGITECH_DJ)
471 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER) },
472 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2) },
473#endif
474#if IS_ENABLED(CONFIG_HID_MAGICMOUSE)468#if IS_ENABLED(CONFIG_HID_MAGICMOUSE)
475 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },469 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
476 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },470 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
drivers/hid/hid-sensor-custom.c+4−8
@@ -157,8 +157,7 @@ static int usage_id_cmp(const void *p1, const void *p2) · 156 unmodified lines
157static ssize_t enable_sensor_show(struct device *dev,157static ssize_t enable_sensor_show(struct device *dev,
158 struct device_attribute *attr, char *buf)158 struct device_attribute *attr, char *buf)
159{159{
160 struct platform_device *pdev = to_platform_device(dev);160 struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev);
161 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev);
162 161
163 return sprintf(buf, "%d\n", sensor_inst->enable);162 return sprintf(buf, "%d\n", sensor_inst->enable);
164}163}
@@ -237,8 +236,7 @@ static ssize_t enable_sensor_store(struct device *dev, · 72 unmodified lines
237 struct device_attribute *attr,236 struct device_attribute *attr,
238 const char *buf, size_t count)237 const char *buf, size_t count)
239{238{
240 struct platform_device *pdev = to_platform_device(dev);239 struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev);
241 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev);
242 int value;240 int value;
243 int ret = -EINVAL;241 int ret = -EINVAL;
244 242
@@ -283,8 +281,7 @@ static const struct attribute_group enable_sensor_attr_group = { · 38 unmodified lines
283static ssize_t show_value(struct device *dev, struct device_attribute *attr,281static ssize_t show_value(struct device *dev, struct device_attribute *attr,
284 char *buf)282 char *buf)
285{283{
286 struct platform_device *pdev = to_platform_device(dev);284 struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev);
287 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev);
288 struct hid_sensor_hub_attribute_info *attribute;285 struct hid_sensor_hub_attribute_info *attribute;
289 int index, usage, field_index;286 int index, usage, field_index;
290 char name[HID_CUSTOM_NAME_LENGTH];287 char name[HID_CUSTOM_NAME_LENGTH];
@@ -392,8 +389,7 @@ static ssize_t show_value(struct device *dev, struct device_attribute *attr, · 101 unmodified lines
392static ssize_t store_value(struct device *dev, struct device_attribute *attr,389static ssize_t store_value(struct device *dev, struct device_attribute *attr,
393 const char *buf, size_t count)390 const char *buf, size_t count)
394{391{
395 struct platform_device *pdev = to_platform_device(dev);392 struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev);
396 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev);
397 int index, field_index, usage;393 int index, field_index, usage;
398 char name[HID_CUSTOM_NAME_LENGTH];394 char name[HID_CUSTOM_NAME_LENGTH];
399 int value;395 int value;
drivers/hid/hid-u2fzero.c+374−0
@@ -0,0 +1,374 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * U2F Zero LED and RNG driver
4 *
5 * Copyright 2018 Andrej Shadura <andrew@shadura.me>
6 * Loosely based on drivers/hid/hid-led.c
7 * and drivers/usb/misc/chaoskey.c
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation, version 2.
12 */
13
14#include <linux/hid.h>
15#include <linux/hidraw.h>
16#include <linux/hw_random.h>
17#include <linux/leds.h>
18#include <linux/module.h>
19#include <linux/mutex.h>
20#include <linux/usb.h>
21
22#include "usbhid/usbhid.h"
23#include "hid-ids.h"
24
25#define DRIVER_SHORT "u2fzero"
26
27#define HID_REPORT_SIZE 64
28
29/* We only use broadcast (CID-less) messages */
30#define CID_BROADCAST 0xffffffff
31
32struct u2f_hid_msg {
33 u32 cid;
34 union {
35 struct {
36 u8 cmd;
37 u8 bcnth;
38 u8 bcntl;
39 u8 data[HID_REPORT_SIZE - 7];
40 } init;
41 struct {
42 u8 seq;
43 u8 data[HID_REPORT_SIZE - 5];
44 } cont;
45 };
46} __packed;
47
48struct u2f_hid_report {
49 u8 report_type;
50 struct u2f_hid_msg msg;
51} __packed;
52
53#define U2F_HID_MSG_LEN(f) (size_t)(((f).init.bcnth << 8) + (f).init.bcntl)
54
55/* Custom extensions to the U2FHID protocol */
56#define U2F_CUSTOM_GET_RNG 0x21
57#define U2F_CUSTOM_WINK 0x24
58
59struct u2fzero_device {
60 struct hid_device *hdev;
61 struct urb *urb; /* URB for the RNG data */
62 struct led_classdev ldev; /* Embedded struct for led */
63 struct hwrng hwrng; /* Embedded struct for hwrng */
64 char *led_name;
65 char *rng_name;
66 u8 *buf_out;
67 u8 *buf_in;
68 struct mutex lock;
69 bool present;
70};
71
72static int u2fzero_send(struct u2fzero_device *dev, struct u2f_hid_report *req)
73{
74 int ret;
75
76 mutex_lock(&dev->lock);
77
78 memcpy(dev->buf_out, req, sizeof(struct u2f_hid_report));
79
80 ret = hid_hw_output_report(dev->hdev, dev->buf_out,
81 sizeof(struct u2f_hid_msg));
82
83 mutex_unlock(&dev->lock);
84
85 if (ret < 0)
86 return ret;
87
88 return ret == sizeof(struct u2f_hid_msg) ? 0 : -EMSGSIZE;
89}
90
91struct u2fzero_transfer_context {
92 struct completion done;
93 int status;
94};
95
96static void u2fzero_read_callback(struct urb *urb)
97{
98 struct u2fzero_transfer_context *ctx = urb->context;
99
100 ctx->status = urb->status;
101 complete(&ctx->done);
102}
103
104static int u2fzero_recv(struct u2fzero_device *dev,
105 struct u2f_hid_report *req,
106 struct u2f_hid_msg *resp)
107{
108 int ret;
109 struct hid_device *hdev = dev->hdev;
110 struct u2fzero_transfer_context ctx;
111
112 mutex_lock(&dev->lock);
113
114 memcpy(dev->buf_out, req, sizeof(struct u2f_hid_report));
115
116 dev->urb->context = &ctx;
117 init_completion(&ctx.done);
118
119 ret = usb_submit_urb(dev->urb, GFP_NOIO);
120 if (unlikely(ret)) {
121 hid_err(hdev, "usb_submit_urb failed: %d", ret);
122 goto err;
123 }
124
125 ret = hid_hw_output_report(dev->hdev, dev->buf_out,
126 sizeof(struct u2f_hid_msg));
127
128 if (ret < 0) {
129 hid_err(hdev, "hid_hw_output_report failed: %d", ret);
130 goto err;
131 }
132
133 ret = (wait_for_completion_timeout(
134 &ctx.done, msecs_to_jiffies(USB_CTRL_SET_TIMEOUT)));
135 if (ret < 0) {
136 usb_kill_urb(dev->urb);
137 hid_err(hdev, "urb submission timed out");
138 } else {
139 ret = dev->urb->actual_length;
140 memcpy(resp, dev->buf_in, ret);
141 }
142
143err:
144 mutex_unlock(&dev->lock);
145
146 return ret;
147}
148
149static int u2fzero_blink(struct led_classdev *ldev)
150{
151 struct u2fzero_device *dev = container_of(ldev,
152 struct u2fzero_device, ldev);
153 struct u2f_hid_report req = {
154 .report_type = 0,
155 .msg.cid = CID_BROADCAST,
156 .msg.init = {
157 .cmd = U2F_CUSTOM_WINK,
158 .bcnth = 0,
159 .bcntl = 0,
160 .data = {0},
161 }
162 };
163 return u2fzero_send(dev, &req);
164}
165
166static int u2fzero_brightness_set(struct led_classdev *ldev,
167 enum led_brightness brightness)
168{
169 ldev->brightness = LED_OFF;
170 if (brightness)
171 return u2fzero_blink(ldev);
172 else
173 return 0;
174}
175
176static int u2fzero_rng_read(struct hwrng *rng, void *data,
177 size_t max, bool wait)
178{
179 struct u2fzero_device *dev = container_of(rng,
180 struct u2fzero_device, hwrng);
181 struct u2f_hid_report req = {
182 .report_type = 0,
183 .msg.cid = CID_BROADCAST,
184 .msg.init = {
185 .cmd = U2F_CUSTOM_GET_RNG,
186 .bcnth = 0,
187 .bcntl = 0,
188 .data = {0},
189 }
190 };
191 struct u2f_hid_msg resp;
192 int ret;
193 size_t actual_length;
194
195 if (!dev->present) {
196 hid_dbg(dev->hdev, "device not present");
197 return 0;
198 }
199
200 ret = u2fzero_recv(dev, &req, &resp);
201 if (ret < 0)
202 return 0;
203
204 /* only take the minimum amount of data it is safe to take */
205 actual_length = min3((size_t)ret - offsetof(struct u2f_hid_msg,
206 init.data), U2F_HID_MSG_LEN(resp), max);
207
208 memcpy(data, resp.init.data, actual_length);
209
210 return actual_length;
211}
212
213static int u2fzero_init_led(struct u2fzero_device *dev,
214 unsigned int minor)
215{
216 dev->led_name = devm_kasprintf(&dev->hdev->dev, GFP_KERNEL,
217 "%s%u", DRIVER_SHORT, minor);
218 if (dev->led_name == NULL)
219 return -ENOMEM;
220
221 dev->ldev.name = dev->led_name;
222 dev->ldev.max_brightness = LED_ON;
223 dev->ldev.flags = LED_HW_PLUGGABLE;
224 dev->ldev.brightness_set_blocking = u2fzero_brightness_set;
225
226 return devm_led_classdev_register(&dev->hdev->dev, &dev->ldev);
227}
228
229static int u2fzero_init_hwrng(struct u2fzero_device *dev,
230 unsigned int minor)
231{
232 dev->rng_name = devm_kasprintf(&dev->hdev->dev, GFP_KERNEL,
233 "%s-rng%u", DRIVER_SHORT, minor);
234 if (dev->rng_name == NULL)
235 return -ENOMEM;
236
237 dev->hwrng.name = dev->rng_name;
238 dev->hwrng.read = u2fzero_rng_read;
239 dev->hwrng.quality = 1;
240
241 return devm_hwrng_register(&dev->hdev->dev, &dev->hwrng);
242}
243
244static int u2fzero_fill_in_urb(struct u2fzero_device *dev)
245{
246 struct hid_device *hdev = dev->hdev;
247 struct usb_device *udev;
248 struct usbhid_device *usbhid = hdev->driver_data;
249 unsigned int pipe_in;
250 struct usb_host_endpoint *ep;
251
252 if (dev->hdev->bus != BUS_USB)
253 return -EINVAL;
254
255 udev = hid_to_usb_dev(hdev);
256
257 if (!usbhid->urbout || !usbhid->urbin)
258 return -ENODEV;
259
260 ep = usb_pipe_endpoint(udev, usbhid->urbin->pipe);
261 if (!ep)
262 return -ENODEV;
263
264 dev->urb = usb_alloc_urb(0, GFP_KERNEL);
265 if (!dev->urb)
266 return -ENOMEM;
267
268 pipe_in = (usbhid->urbin->pipe & ~(3 << 30)) | (PIPE_INTERRUPT << 30);
269
270 usb_fill_int_urb(dev->urb,
271 udev,
272 pipe_in,
273 dev->buf_in,
274 HID_REPORT_SIZE,
275 u2fzero_read_callback,
276 NULL,
277 ep->desc.bInterval);
278
279 return 0;
280}
281
282static int u2fzero_probe(struct hid_device *hdev,
283 const struct hid_device_id *id)
284{
285 struct u2fzero_device *dev;
286 unsigned int minor;
287 int ret;
288
289 if (!hid_is_using_ll_driver(hdev, &usb_hid_driver))
290 return -EINVAL;
291
292 dev = devm_kzalloc(&hdev->dev, sizeof(*dev), GFP_KERNEL);
293 if (dev == NULL)
294 return -ENOMEM;
295
296 dev->buf_out = devm_kmalloc(&hdev->dev,
297 sizeof(struct u2f_hid_report), GFP_KERNEL);
298 if (dev->buf_out == NULL)
299 return -ENOMEM;
300
301 dev->buf_in = devm_kmalloc(&hdev->dev,
302 sizeof(struct u2f_hid_msg), GFP_KERNEL);
303 if (dev->buf_in == NULL)
304 return -ENOMEM;
305
306 ret = hid_parse(hdev);
307 if (ret)
308 return ret;
309
310 dev->hdev = hdev;
311 hid_set_drvdata(hdev, dev);
312 mutex_init(&dev->lock);
313
314 ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW);
315 if (ret)
316 return ret;
317
318 u2fzero_fill_in_urb(dev);
319
320 dev->present = true;
321
322 minor = ((struct hidraw *) hdev->hidraw)->minor;
323
324 ret = u2fzero_init_led(dev, minor);
325 if (ret) {
326 hid_hw_stop(hdev);
327 return ret;
328 }
329
330 hid_info(hdev, "U2F Zero LED initialised\n");
331
332 ret = u2fzero_init_hwrng(dev, minor);
333 if (ret) {
334 hid_hw_stop(hdev);
335 return ret;
336 }
337
338 hid_info(hdev, "U2F Zero RNG initialised\n");
339
340 return 0;
341}
342
343static void u2fzero_remove(struct hid_device *hdev)
344{
345 struct u2fzero_device *dev = hid_get_drvdata(hdev);
346
347 mutex_lock(&dev->lock);
348 dev->present = false;
349 mutex_unlock(&dev->lock);
350
351 hid_hw_stop(hdev);
352 usb_poison_urb(dev->urb);
353 usb_free_urb(dev->urb);
354}
355
356static const struct hid_device_id u2fzero_table[] = {
357 { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL,
358 USB_DEVICE_ID_U2F_ZERO) },
359 { }
360};
361MODULE_DEVICE_TABLE(hid, u2fzero_table);
362
363static struct hid_driver u2fzero_driver = {
364 .name = "hid-" DRIVER_SHORT,
365 .probe = u2fzero_probe,
366 .remove = u2fzero_remove,
367 .id_table = u2fzero_table,
368};
369
370module_hid_driver(u2fzero_driver);
371
372MODULE_LICENSE("GPL");
373MODULE_AUTHOR("Andrej Shadura <andrew@shadura.me>");
374MODULE_DESCRIPTION("U2F Zero LED and RNG driver");
drivers/hid/i2c-hid/i2c-hid-core.c+0−2
@@ -184,8 +184,6 @@ static const struct i2c_hid_quirks { · 183 unmodified lines
184 I2C_HID_QUIRK_NO_RUNTIME_PM },184 I2C_HID_QUIRK_NO_RUNTIME_PM },
185 { USB_VENDOR_ID_ELAN, HID_ANY_ID,185 { USB_VENDOR_ID_ELAN, HID_ANY_ID,
186 I2C_HID_QUIRK_BOGUS_IRQ },186 I2C_HID_QUIRK_BOGUS_IRQ },
187 { USB_VENDOR_ID_SYNAPTICS, I2C_DEVICE_ID_SYNAPTICS_7E7E,
188 I2C_HID_QUIRK_NO_RUNTIME_PM },
189 { 0, 0 }187 { 0, 0 }
190};188};
191 189
drivers/hid/intel-ish-hid/Kconfig+15−0
@@ -14,4 +14,19 @@ config INTEL_ISH_HID · 13 unmodified lines
14 Broxton and Kaby Lake.14 Broxton and Kaby Lake.
15 15
16 Say Y here if you want to support Intel ISH. If unsure, say N.16 Say Y here if you want to support Intel ISH. If unsure, say N.
17
18config INTEL_ISH_FIRMWARE_DOWNLOADER
19 tristate "Host Firmware Load feature for Intel ISH"
20 depends on INTEL_ISH_HID
21 depends on X86
22 help
23 The Integrated Sensor Hub (ISH) enables the kernel to offload
24 sensor polling and algorithm processing to a dedicated low power
25 processor in the chipset.
26
27 The Host Firmware Load feature adds support to load the ISH
28 firmware from host file system at boot.
29
30 Say M here if you want to support Host Firmware Loading feature
31 for Intel ISH. If unsure, say N.
17endmenu32endmenu
drivers/hid/intel-ish-hid/Makefile+3−0
@@ -20,4 +20,7 @@ obj-$(CONFIG_INTEL_ISH_HID) += intel-ishtp-hid.o · 19 unmodified lines
20intel-ishtp-hid-objs := ishtp-hid.o20intel-ishtp-hid-objs := ishtp-hid.o
21intel-ishtp-hid-objs += ishtp-hid-client.o21intel-ishtp-hid-objs += ishtp-hid-client.o
22 22
23obj-$(CONFIG_INTEL_ISH_FIRMWARE_DOWNLOADER) += intel-ishtp-loader.o
24intel-ishtp-loader-objs += ishtp-fw-loader.o
25
23ccflags-y += -Idrivers/hid/intel-ish-hid/ishtp26ccflags-y += -Idrivers/hid/intel-ish-hid/ishtp
drivers/hid/intel-ish-hid/ipc/hw-ish.h+1−0
@@ -31,6 +31,7 @@ · 30 unmodified lines
31#define CNL_H_DEVICE_ID 0xA37C31#define CNL_H_DEVICE_ID 0xA37C
32#define ICL_MOBILE_DEVICE_ID 0x34FC32#define ICL_MOBILE_DEVICE_ID 0x34FC
33#define SPT_H_DEVICE_ID 0xA13533#define SPT_H_DEVICE_ID 0xA135
34#define CML_LP_DEVICE_ID 0x02FC
34 35
35#define REVISION_ID_CHT_A0 0x636#define REVISION_ID_CHT_A0 0x6
36#define REVISION_ID_CHT_Ax_SI 0x037#define REVISION_ID_CHT_Ax_SI 0x0
drivers/hid/intel-ish-hid/ipc/pci-ish.c+1−0
@@ -40,6 +40,7 @@ static const struct pci_device_id ish_pci_tbl[] = { · 39 unmodified lines
40 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, CNL_H_DEVICE_ID)},40 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, CNL_H_DEVICE_ID)},
41 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, ICL_MOBILE_DEVICE_ID)},41 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, ICL_MOBILE_DEVICE_ID)},
42 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, SPT_H_DEVICE_ID)},42 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, SPT_H_DEVICE_ID)},
43 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, CML_LP_DEVICE_ID)},
43 {0, }44 {0, }
44};45};
45MODULE_DEVICE_TABLE(pci, ish_pci_tbl);46MODULE_DEVICE_TABLE(pci, ish_pci_tbl);
drivers/hid/intel-ish-hid/ishtp-fw-loader.c+1085−0
@@ -0,0 +1,1085 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * ISH-TP client driver for ISH firmware loading
4 *
5 * Copyright (c) 2019, Intel Corporation.
6 */
7
8#include <linux/firmware.h>
9#include <linux/module.h>
10#include <linux/pci.h>
11#include <linux/intel-ish-client-if.h>
12#include <linux/property.h>
13#include <asm/cacheflush.h>
14
15/* Number of times we attempt to load the firmware before giving up */
16#define MAX_LOAD_ATTEMPTS 3
17
18/* ISH TX/RX ring buffer pool size */
19#define LOADER_CL_RX_RING_SIZE 1
20#define LOADER_CL_TX_RING_SIZE 1
21
22/*
23 * ISH Shim firmware loader reserves 4 Kb buffer in SRAM. The buffer is
24 * used to temporarily hold the data transferred from host to Shim
25 * firmware loader. Reason for the odd size of 3968 bytes? Each IPC
26 * transfer is 128 bytes (= 4 bytes header + 124 bytes payload). So the
27 * 4 Kb buffer can hold maximum of 32 IPC transfers, which means we can
28 * have a max payload of 3968 bytes (= 32 x 124 payload).
29 */
30#define LOADER_SHIM_IPC_BUF_SIZE 3968
31
32/**
33 * enum ish_loader_commands - ISH loader host commands.
34 * LOADER_CMD_XFER_QUERY Query the Shim firmware loader for
35 * capabilities
36 * LOADER_CMD_XFER_FRAGMENT Transfer one firmware image fragment at a
37 * time. The command may be executed
38 * multiple times until the entire firmware
39 * image is downloaded to SRAM.
40 * LOADER_CMD_START Start executing the main firmware.
41 */
42enum ish_loader_commands {
43 LOADER_CMD_XFER_QUERY = 0,
44 LOADER_CMD_XFER_FRAGMENT,
45 LOADER_CMD_START,
46};
47
48/* Command bit mask */
49#define CMD_MASK GENMASK(6, 0)
50#define IS_RESPONSE BIT(7)
51
52/*
53 * ISH firmware max delay for one transmit failure is 1 Hz,
54 * and firmware will retry 2 times, so 3 Hz is used for timeout.
55 */
56#define ISHTP_SEND_TIMEOUT (3 * HZ)
57
58/*
59 * Loader transfer modes:
60 *
61 * LOADER_XFER_MODE_ISHTP mode uses the existing ISH-TP mechanism to
62 * transfer data. This may use IPC or DMA if supported in firmware.
63 * The buffer size is limited to 4 Kb by the IPC/ISH-TP protocol for
64 * both IPC & DMA (legacy).
65 *
66 * LOADER_XFER_MODE_DIRECT_DMA - firmware loading is a bit different
67 * from the sensor data streaming. Here we download a large (300+ Kb)
68 * image directly to ISH SRAM memory. There is limited benefit of
69 * DMA'ing 300 Kb image in 4 Kb chucks limit. Hence, we introduce
70 * this "direct dma" mode, where we do not use ISH-TP for DMA, but
71 * instead manage the DMA directly in kernel driver and Shim firmware
72 * loader (allocate buffer, break in chucks and transfer). This allows
73 * to overcome 4 Kb limit, and optimize the data flow path in firmware.
74 */
75#define LOADER_XFER_MODE_DIRECT_DMA BIT(0)
76#define LOADER_XFER_MODE_ISHTP BIT(1)
77
78/* ISH Transport Loader client unique GUID */
79static const guid_t loader_ishtp_guid =
80 GUID_INIT(0xc804d06a, 0x55bd, 0x4ea7,
81 0xad, 0xed, 0x1e, 0x31, 0x22, 0x8c, 0x76, 0xdc);
82
83#define FILENAME_SIZE 256
84
85/*
86 * The firmware loading latency will be minimum if we can DMA the
87 * entire ISH firmware image in one go. This requires that we allocate
88 * a large DMA buffer in kernel, which could be problematic on some
89 * platforms. So here we limit the DMA buffer size via a module_param.
90 * We default to 4 pages, but a customer can set it to higher limit if
91 * deemed appropriate for his platform.
92 */
93static int dma_buf_size_limit = 4 * PAGE_SIZE;
94
95/**
96 * struct loader_msg_hdr - Header for ISH Loader commands.
97 * @command: LOADER_CMD* commands. Bit 7 is the response.
98 * @status: Command response status. Non 0, is error
99 * condition.
100 *
101 * This structure is used as header for every command/data sent/received
102 * between Host driver and ISH Shim firmware loader.
103 */
104struct loader_msg_hdr {
105 u8 command;
106 u8 reserved[2];
107 u8 status;
108} __packed;
109
110struct loader_xfer_query {
111 struct loader_msg_hdr hdr;
112 u32 image_size;
113} __packed;
114
115struct ish_fw_version {
116 u16 major;
117 u16 minor;
118 u16 hotfix;
119 u16 build;
120} __packed;
121
122union loader_version {
123 u32 value;
124 struct {
125 u8 major;
126 u8 minor;
127 u8 hotfix;
128 u8 build;
129 };
130} __packed;
131
132struct loader_capability {
133 u32 max_fw_image_size;
134 u32 xfer_mode;
135 u32 max_dma_buf_size; /* only for dma mode, multiples of cacheline */
136} __packed;
137
138struct shim_fw_info {
139 struct ish_fw_version ish_fw_version;
140 u32 protocol_version;
141 union loader_version ldr_version;
142 struct loader_capability ldr_capability;
143} __packed;
144
145struct loader_xfer_query_response {
146 struct loader_msg_hdr hdr;
147 struct shim_fw_info fw_info;
148} __packed;
149
150struct loader_xfer_fragment {
151 struct loader_msg_hdr hdr;
152 u32 xfer_mode;
153 u32 offset;
154 u32 size;
155 u32 is_last;
156} __packed;
157
158struct loader_xfer_ipc_fragment {
159 struct loader_xfer_fragment fragment;
160 u8 data[] ____cacheline_aligned; /* variable length payload here */
161} __packed;
162
163struct loader_xfer_dma_fragment {
164 struct loader_xfer_fragment fragment;
165 u64 ddr_phys_addr;
166} __packed;
167
168struct loader_start {
169 struct loader_msg_hdr hdr;
170} __packed;
171
172/**
173 * struct response_info - Encapsulate firmware response related
174 * information for passing between function
175 * loader_cl_send() and process_recv() callback.
176 * @data Copy the data received from firmware here.
177 * @max_size Max size allocated for the @data buffer. If the
178 * received data exceeds this value, we log an
179 * error.
180 * @size Actual size of data received from firmware.
181 * @error Returns 0 for success, negative error code for a
182 * failure in function process_recv().
183 * @received Set to true on receiving a valid firmware
184 * response to host command
185 * @wait_queue Wait queue for Host firmware loading where the
186 * client sends message to ISH firmware and waits
187 * for response
188 */
189struct response_info {
190 void *data;
191 size_t max_size;
192 size_t size;
193 int error;
194 bool received;
195 wait_queue_head_t wait_queue;
196};
197
198/**
199 * struct ishtp_cl_data - Encapsulate per ISH-TP Client Data.
200 * @work_ishtp_reset: Work queue for reset handling.
201 * @work_fw_load: Work queue for host firmware loading.
202 * @flag_retry Flag for indicating host firmware loading should
203 * be retried.
204 * @retry_count Count the number of retries.
205 *
206 * This structure is used to store data per client.
207 */
208struct ishtp_cl_data {
209 struct ishtp_cl *loader_ishtp_cl;
210 struct ishtp_cl_device *cl_device;
211
212 /*
213 * Used for passing firmware response information between
214 * loader_cl_send() and process_recv() callback.
215 */
216 struct response_info response;
217
218 struct work_struct work_ishtp_reset;
219 struct work_struct work_fw_load;
220
221 /*
222 * In certain failure scenrios, it makes sense to reset the ISH
223 * subsystem and retry Host firmware loading (e.g. bad message
224 * packet, ENOMEM, etc.). On the other hand, failures due to
225 * protocol mismatch, etc., are not recoverable. We do not
226 * retry them.
227 *
228 * If set, the flag indicates that we should re-try the
229 * particular failure.
230 */
231 bool flag_retry;
232 int retry_count;
233};
234
235#define IPC_FRAGMENT_DATA_PREAMBLE \
236 offsetof(struct loader_xfer_ipc_fragment, data)
237
238#define cl_data_to_dev(client_data) ishtp_device((client_data)->cl_device)
239
240/**
241 * get_firmware_variant() - Gets the filename of firmware image to be
242 * loaded based on platform variant.
243 * @client_data Client data instance.
244 * @filename Returns firmware filename.
245 *
246 * Queries the firmware-name device property string.
247 *
248 * Return: 0 for success, negative error code for failure.
249 */
250static int get_firmware_variant(struct ishtp_cl_data *client_data,
251 char *filename)
252{
253 int rv;
254 const char *val;
255 struct device *devc = ishtp_get_pci_device(client_data->cl_device);
256
257 rv = device_property_read_string(devc, "firmware-name", &val);
258 if (rv < 0) {
259 dev_err(devc,
260 "Error: ISH firmware-name device property required\n");
261 return rv;
262 }
263 return snprintf(filename, FILENAME_SIZE, "intel/%s", val);
264}
265
266/**
267 * loader_cl_send() Send message from host to firmware
268 * @client_data: Client data instance
269 * @out_msg Message buffer to be sent to firmware
270 * @out_size Size of out going message
271 * @in_msg Message buffer where the incoming data copied.
272 * This buffer is allocated by calling
273 * @in_size Max size of incoming message
274 *
275 * Return: Number of bytes copied in the in_msg on success, negative
276 * error code on failure.
277 */
278static int loader_cl_send(struct ishtp_cl_data *client_data,
279 u8 *out_msg, size_t out_size,
280 u8 *in_msg, size_t in_size)
281{
282 int rv;
283 struct loader_msg_hdr *out_hdr = (struct loader_msg_hdr *)out_msg;
284 struct ishtp_cl *loader_ishtp_cl = client_data->loader_ishtp_cl;
285
286 dev_dbg(cl_data_to_dev(client_data),
287 "%s: command=%02lx is_response=%u status=%02x\n",
288 __func__,
289 out_hdr->command & CMD_MASK,
290 out_hdr->command & IS_RESPONSE ? 1 : 0,
291 out_hdr->status);
292
293 /* Setup in coming buffer & size */
294 client_data->response.data = in_msg;
295 client_data->response.max_size = in_size;
296 client_data->response.error = 0;
297 client_data->response.received = false;
298
299 rv = ishtp_cl_send(loader_ishtp_cl, out_msg, out_size);
300 if (rv < 0) {
301 dev_err(cl_data_to_dev(client_data),
302 "ishtp_cl_send error %d\n", rv);
303 return rv;
304 }
305
306 wait_event_interruptible_timeout(client_data->response.wait_queue,
307 client_data->response.received,
308 ISHTP_SEND_TIMEOUT);
309 if (!client_data->response.received) {
310 dev_err(cl_data_to_dev(client_data),
311 "Timed out for response to command=%02lx",
312 out_hdr->command & CMD_MASK);
313 return -ETIMEDOUT;
314 }
315
316 if (client_data->response.error < 0)
317 return client_data->response.error;
318
319 return client_data->response.size;
320}
321
322/**
323 * process_recv() - Receive and parse incoming packet
324 * @loader_ishtp_cl: Client instance to get stats
325 * @rb_in_proc: ISH received message buffer
326 *
327 * Parse the incoming packet. If it is a response packet then it will
328 * update received and wake up the caller waiting to for the response.
329 */
330static void process_recv(struct ishtp_cl *loader_ishtp_cl,
331 struct ishtp_cl_rb *rb_in_proc)
332{
333 struct loader_msg_hdr *hdr;
334 size_t data_len = rb_in_proc->buf_idx;
335 struct ishtp_cl_data *client_data =
336 ishtp_get_client_data(loader_ishtp_cl);
337
338 /* Sanity check */
339 if (!client_data->response.data) {
340 dev_err(cl_data_to_dev(client_data),
341 "Receiving buffer is null. Should be allocated by calling function\n");
342 client_data->response.error = -EINVAL;
343 goto end;
344 }
345
346 if (client_data->response.received) {
347 dev_err(cl_data_to_dev(client_data),
348 "Previous firmware message not yet processed\n");
349 client_data->response.error = -EINVAL;
350 goto end;
351 }
352 /*
353 * All firmware messages have a header. Check buffer size
354 * before accessing elements inside.
355 */
356 if (!rb_in_proc->buffer.data) {
357 dev_warn(cl_data_to_dev(client_data),
358 "rb_in_proc->buffer.data returned null");
359 client_data->response.error = -EBADMSG;
360 goto end;
361 }
362
363 if (data_len < sizeof(struct loader_msg_hdr)) {
364 dev_err(cl_data_to_dev(client_data),
365 "data size %zu is less than header %zu\n",
366 data_len, sizeof(struct loader_msg_hdr));
367 client_data->response.error = -EMSGSIZE;
368 goto end;
369 }
370
371 hdr = (struct loader_msg_hdr *)rb_in_proc->buffer.data;
372
373 dev_dbg(cl_data_to_dev(client_data),
374 "%s: command=%02lx is_response=%u status=%02x\n",
375 __func__,
376 hdr->command & CMD_MASK,
377 hdr->command & IS_RESPONSE ? 1 : 0,
378 hdr->status);
379
380 if (((hdr->command & CMD_MASK) != LOADER_CMD_XFER_QUERY) &&
381 ((hdr->command & CMD_MASK) != LOADER_CMD_XFER_FRAGMENT) &&
382 ((hdr->command & CMD_MASK) != LOADER_CMD_START)) {
383 dev_err(cl_data_to_dev(client_data),
384 "Invalid command=%02lx\n",
385 hdr->command & CMD_MASK);
386 client_data->response.error = -EPROTO;
387 goto end;
388 }
389
390 if (data_len > client_data->response.max_size) {
391 dev_err(cl_data_to_dev(client_data),
392 "Received buffer size %zu is larger than allocated buffer %zu\n",
393 data_len, client_data->response.max_size);
394 client_data->response.error = -EMSGSIZE;
395 goto end;
396 }
397
398 /* We expect only "response" messages from firmware */
399 if (!(hdr->command & IS_RESPONSE)) {
400 dev_err(cl_data_to_dev(client_data),
401 "Invalid response to command\n");
402 client_data->response.error = -EIO;
403 goto end;
404 }
405
406 if (hdr->status) {
407 dev_err(cl_data_to_dev(client_data),
408 "Loader returned status %d\n",
409 hdr->status);
410 client_data->response.error = -EIO;
411 goto end;
412 }
413
414 /* Update the actual received buffer size */
415 client_data->response.size = data_len;
416
417 /*
418 * Copy the buffer received in firmware response for the
419 * calling thread.
420 */
421 memcpy(client_data->response.data,
422 rb_in_proc->buffer.data, data_len);
423
424 /* Set flag before waking up the caller */
425 client_data->response.received = true;
426
427end:
428 /* Free the buffer */
429 ishtp_cl_io_rb_recycle(rb_in_proc);
430 rb_in_proc = NULL;
431
432 /* Wake the calling thread */
433 wake_up_interruptible(&client_data->response.wait_queue);
434}
435
436/**
437 * loader_cl_event_cb() - bus driver callback for incoming message
438 * @device: Pointer to the ishtp client device for which this
439 * message is targeted
440 *
441 * Remove the packet from the list and process the message by calling
442 * process_recv
443 */
444static void loader_cl_event_cb(struct ishtp_cl_device *cl_device)
445{
446 struct ishtp_cl_rb *rb_in_proc;
447 struct ishtp_cl *loader_ishtp_cl = ishtp_get_drvdata(cl_device);
448
449 while ((rb_in_proc = ishtp_cl_rx_get_rb(loader_ishtp_cl)) != NULL) {
450 /* Process the data packet from firmware */
451 process_recv(loader_ishtp_cl, rb_in_proc);
452 }
453}
454
455/**
456 * ish_query_loader_prop() - Query ISH Shim firmware loader
457 * @client_data: Client data instance
458 * @fw: Poiner to firmware data struct in host memory
459 * @fw_info: Loader firmware properties
460 *
461 * This function queries the ISH Shim firmware loader for capabilities.
462 *
463 * Return: 0 for success, negative error code for failure.
464 */
465static int ish_query_loader_prop(struct ishtp_cl_data *client_data,
466 const struct firmware *fw,
467 struct shim_fw_info *fw_info)
468{
469 int rv;
470 struct loader_xfer_query ldr_xfer_query;
471 struct loader_xfer_query_response ldr_xfer_query_resp;
472
473 memset(&ldr_xfer_query, 0, sizeof(ldr_xfer_query));
474 ldr_xfer_query.hdr.command = LOADER_CMD_XFER_QUERY;
475 ldr_xfer_query.image_size = fw->size;
476 rv = loader_cl_send(client_data,
477 (u8 *)&ldr_xfer_query,
478 sizeof(ldr_xfer_query),
479 (u8 *)&ldr_xfer_query_resp,
480 sizeof(ldr_xfer_query_resp));
481 if (rv < 0) {
482 client_data->flag_retry = true;
483 return rv;
484 }
485
486 /* On success, the return value is the received buffer size */
487 if (rv != sizeof(struct loader_xfer_query_response)) {
488 dev_err(cl_data_to_dev(client_data),
489 "data size %d is not equal to size of loader_xfer_query_response %zu\n",
490 rv, sizeof(struct loader_xfer_query_response));
491 client_data->flag_retry = true;
492 return -EMSGSIZE;
493 }
494
495 /* Save fw_info for use outside this function */
496 *fw_info = ldr_xfer_query_resp.fw_info;
497
498 /* Loader firmware properties */
499 dev_dbg(cl_data_to_dev(client_data),
500 "ish_fw_version: major=%d minor=%d hotfix=%d build=%d protocol_version=0x%x loader_version=%d\n",
501 fw_info->ish_fw_version.major,
502 fw_info->ish_fw_version.minor,
503 fw_info->ish_fw_version.hotfix,
504 fw_info->ish_fw_version.build,
505 fw_info->protocol_version,
506 fw_info->ldr_version.value);
507
508 dev_dbg(cl_data_to_dev(client_data),
509 "loader_capability: max_fw_image_size=0x%x xfer_mode=%d max_dma_buf_size=0x%x dma_buf_size_limit=0x%x\n",
510 fw_info->ldr_capability.max_fw_image_size,
511 fw_info->ldr_capability.xfer_mode,
512 fw_info->ldr_capability.max_dma_buf_size,
513 dma_buf_size_limit);
514
515 /* Sanity checks */
516 if (fw_info->ldr_capability.max_fw_image_size < fw->size) {
517 dev_err(cl_data_to_dev(client_data),
518 "ISH firmware size %zu is greater than Shim firmware loader max supported %d\n",
519 fw->size,
520 fw_info->ldr_capability.max_fw_image_size);
521 return -ENOSPC;
522 }
523
524 /* For DMA the buffer size should be multiple of cacheline size */
525 if ((fw_info->ldr_capability.xfer_mode & LOADER_XFER_MODE_DIRECT_DMA) &&
526 (fw_info->ldr_capability.max_dma_buf_size % L1_CACHE_BYTES)) {
527 dev_err(cl_data_to_dev(client_data),
528 "Shim firmware loader buffer size %d should be multiple of cacheline\n",
529 fw_info->ldr_capability.max_dma_buf_size);
530 return -EINVAL;
531 }
532
533 return 0;
534}
535
536/**
537 * ish_fw_xfer_ishtp() Loads ISH firmware using ishtp interface
538 * @client_data: Client data instance
539 * @fw: Pointer to firmware data struct in host memory
540 *
541 * This function uses ISH-TP to transfer ISH firmware from host to
542 * ISH SRAM. Lower layers may use IPC or DMA depending on firmware
543 * support.
544 *
545 * Return: 0 for success, negative error code for failure.
546 */
547static int ish_fw_xfer_ishtp(struct ishtp_cl_data *client_data,
548 const struct firmware *fw)
549{
550 int rv;
551 u32 fragment_offset, fragment_size, payload_max_size;
552 struct loader_xfer_ipc_fragment *ldr_xfer_ipc_frag;
553 struct loader_msg_hdr ldr_xfer_ipc_ack;
554
555 payload_max_size =
556 LOADER_SHIM_IPC_BUF_SIZE - IPC_FRAGMENT_DATA_PREAMBLE;
557
558 ldr_xfer_ipc_frag = kzalloc(LOADER_SHIM_IPC_BUF_SIZE, GFP_KERNEL);
559 if (!ldr_xfer_ipc_frag) {
560 client_data->flag_retry = true;
561 return -ENOMEM;
562 }
563
564 ldr_xfer_ipc_frag->fragment.hdr.command = LOADER_CMD_XFER_FRAGMENT;
565 ldr_xfer_ipc_frag->fragment.xfer_mode = LOADER_XFER_MODE_ISHTP;
566
567 /* Break the firmware image into fragments and send as ISH-TP payload */
568 fragment_offset = 0;
569 while (fragment_offset < fw->size) {
570 if (fragment_offset + payload_max_size < fw->size) {
571 fragment_size = payload_max_size;
572 ldr_xfer_ipc_frag->fragment.is_last = 0;
573 } else {
574 fragment_size = fw->size - fragment_offset;
575 ldr_xfer_ipc_frag->fragment.is_last = 1;
576 }
577
578 ldr_xfer_ipc_frag->fragment.offset = fragment_offset;
579 ldr_xfer_ipc_frag->fragment.size = fragment_size;
580 memcpy(ldr_xfer_ipc_frag->data,
581 &fw->data[fragment_offset],
582 fragment_size);
583
584 dev_dbg(cl_data_to_dev(client_data),
585 "xfer_mode=ipc offset=0x%08x size=0x%08x is_last=%d\n",
586 ldr_xfer_ipc_frag->fragment.offset,
587 ldr_xfer_ipc_frag->fragment.size,
588 ldr_xfer_ipc_frag->fragment.is_last);
589
590 rv = loader_cl_send(client_data,
591 (u8 *)ldr_xfer_ipc_frag,
592 IPC_FRAGMENT_DATA_PREAMBLE + fragment_size,
593 (u8 *)&ldr_xfer_ipc_ack,
594 sizeof(ldr_xfer_ipc_ack));
595 if (rv < 0) {
596 client_data->flag_retry = true;
597 goto end_err_resp_buf_release;
598 }
599
600 fragment_offset += fragment_size;
601 }
602
603 kfree(ldr_xfer_ipc_frag);
604 return 0;
605
606end_err_resp_buf_release:
607 /* Free ISH buffer if not done already, in error case */
608 kfree(ldr_xfer_ipc_frag);
609 return rv;
610}
611
612/**
613 * ish_fw_xfer_direct_dma() - Loads ISH firmware using direct dma
614 * @client_data: Client data instance
615 * @fw: Pointer to firmware data struct in host memory
616 * @fw_info: Loader firmware properties
617 *
618 * Host firmware load is a unique case where we need to download
619 * a large firmware image (200+ Kb). This function implements
620 * direct DMA transfer in kernel and ISH firmware. This allows
621 * us to overcome the ISH-TP 4 Kb limit, and allows us to DMA
622 * directly to ISH UMA at location of choice.
623 * Function depends on corresponding support in ISH firmware.
624 *
625 * Return: 0 for success, negative error code for failure.
626 */
627static int ish_fw_xfer_direct_dma(struct ishtp_cl_data *client_data,
628 const struct firmware *fw,
629 const struct shim_fw_info fw_info)
630{
631 int rv;
632 void *dma_buf;
633 dma_addr_t dma_buf_phy;
634 u32 fragment_offset, fragment_size, payload_max_size;
635 struct loader_msg_hdr ldr_xfer_dma_frag_ack;
636 struct loader_xfer_dma_fragment ldr_xfer_dma_frag;
637 struct device *devc = ishtp_get_pci_device(client_data->cl_device);
638 u32 shim_fw_buf_size =
639 fw_info.ldr_capability.max_dma_buf_size;
640
641 /*
642 * payload_max_size should be set to minimum of
643 * (1) Size of firmware to be loaded,
644 * (2) Max DMA buffer size supported by Shim firmware,
645 * (3) DMA buffer size limit set by boot_param dma_buf_size_limit.
646 */
647 payload_max_size = min3(fw->size,
648 (size_t)shim_fw_buf_size,
649 (size_t)dma_buf_size_limit);
650
651 /*
652 * Buffer size should be multiple of cacheline size
653 * if it's not, select the previous cacheline boundary.
654 */
655 payload_max_size &= ~(L1_CACHE_BYTES - 1);
656
657 dma_buf = kmalloc(payload_max_size, GFP_KERNEL | GFP_DMA32);
658 if (!dma_buf) {
659 client_data->flag_retry = true;
660 return -ENOMEM;
661 }
662
663 dma_buf_phy = dma_map_single(devc, dma_buf, payload_max_size,
664 DMA_TO_DEVICE);
665 if (dma_mapping_error(devc, dma_buf_phy)) {
666 dev_err(cl_data_to_dev(client_data), "DMA map failed\n");
667 client_data->flag_retry = true;
668 rv = -ENOMEM;
669 goto end_err_dma_buf_release;
670 }
671
672 ldr_xfer_dma_frag.fragment.hdr.command = LOADER_CMD_XFER_FRAGMENT;
673 ldr_xfer_dma_frag.fragment.xfer_mode = LOADER_XFER_MODE_DIRECT_DMA;
674 ldr_xfer_dma_frag.ddr_phys_addr = (u64)dma_buf_phy;
675
676 /* Send the firmware image in chucks of payload_max_size */
677 fragment_offset = 0;
678 while (fragment_offset < fw->size) {
679 if (fragment_offset + payload_max_size < fw->size) {
680 fragment_size = payload_max_size;
681 ldr_xfer_dma_frag.fragment.is_last = 0;
682 } else {
683 fragment_size = fw->size - fragment_offset;
684 ldr_xfer_dma_frag.fragment.is_last = 1;
685 }
686
687 ldr_xfer_dma_frag.fragment.offset = fragment_offset;
688 ldr_xfer_dma_frag.fragment.size = fragment_size;
689 memcpy(dma_buf, &fw->data[fragment_offset], fragment_size);
690
691 dma_sync_single_for_device(devc, dma_buf_phy,
692 payload_max_size,
693 DMA_TO_DEVICE);
694
695 /*
696 * Flush cache here because the dma_sync_single_for_device()
697 * does not do for x86.
698 */
699 clflush_cache_range(dma_buf, payload_max_size);
700
701 dev_dbg(cl_data_to_dev(client_data),
702 "xfer_mode=dma offset=0x%08x size=0x%x is_last=%d ddr_phys_addr=0x%016llx\n",
703 ldr_xfer_dma_frag.fragment.offset,
704 ldr_xfer_dma_frag.fragment.size,
705 ldr_xfer_dma_frag.fragment.is_last,
706 ldr_xfer_dma_frag.ddr_phys_addr);
707
708 rv = loader_cl_send(client_data,
709 (u8 *)&ldr_xfer_dma_frag,
710 sizeof(ldr_xfer_dma_frag),
711 (u8 *)&ldr_xfer_dma_frag_ack,
712 sizeof(ldr_xfer_dma_frag_ack));
713 if (rv < 0) {
714 client_data->flag_retry = true;
715 goto end_err_resp_buf_release;
716 }
717
718 fragment_offset += fragment_size;
719 }
720
721 dma_unmap_single(devc, dma_buf_phy, payload_max_size, DMA_TO_DEVICE);
722 kfree(dma_buf);
723 return 0;
724
725end_err_resp_buf_release:
726 /* Free ISH buffer if not done already, in error case */
727 dma_unmap_single(devc, dma_buf_phy, payload_max_size, DMA_TO_DEVICE);
728end_err_dma_buf_release:
729 kfree(dma_buf);
730 return rv;
731}
732
733/**
734 * ish_fw_start() Start executing ISH main firmware
735 * @client_data: client data instance
736 *
737 * This function sends message to Shim firmware loader to start
738 * the execution of ISH main firmware.
739 *
740 * Return: 0 for success, negative error code for failure.
741 */
742static int ish_fw_start(struct ishtp_cl_data *client_data)
743{
744 struct loader_start ldr_start;
745 struct loader_msg_hdr ldr_start_ack;
746
747 memset(&ldr_start, 0, sizeof(ldr_start));
748 ldr_start.hdr.command = LOADER_CMD_START;
749 return loader_cl_send(client_data,
750 (u8 *)&ldr_start,
751 sizeof(ldr_start),
752 (u8 *)&ldr_start_ack,
753 sizeof(ldr_start_ack));
754}
755
756/**
757 * load_fw_from_host() Loads ISH firmware from host
758 * @client_data: Client data instance
759 *
760 * This function loads the ISH firmware to ISH SRAM and starts execution
761 *
762 * Return: 0 for success, negative error code for failure.
763 */
764static int load_fw_from_host(struct ishtp_cl_data *client_data)
765{
766 int rv;
767 u32 xfer_mode;
768 char *filename;
769 const struct firmware *fw;
770 struct shim_fw_info fw_info;
771 struct ishtp_cl *loader_ishtp_cl = client_data->loader_ishtp_cl;
772
773 client_data->flag_retry = false;
774
775 filename = kzalloc(FILENAME_SIZE, GFP_KERNEL);
776 if (!filename) {
777 client_data->flag_retry = true;
778 rv = -ENOMEM;
779 goto end_error;
780 }
781
782 /* Get filename of the ISH firmware to be loaded */
783 rv = get_firmware_variant(client_data, filename);
784 if (rv < 0)
785 goto end_err_filename_buf_release;
786
787 rv = request_firmware(&fw, filename, cl_data_to_dev(client_data));
788 if (rv < 0)
789 goto end_err_filename_buf_release;
790
791 /* Step 1: Query Shim firmware loader properties */
792
793 rv = ish_query_loader_prop(client_data, fw, &fw_info);
794 if (rv < 0)
795 goto end_err_fw_release;
796
797 /* Step 2: Send the main firmware image to be loaded, to ISH SRAM */
798
799 xfer_mode = fw_info.ldr_capability.xfer_mode;
800 if (xfer_mode & LOADER_XFER_MODE_DIRECT_DMA) {
801 rv = ish_fw_xfer_direct_dma(client_data, fw, fw_info);
802 } else if (xfer_mode & LOADER_XFER_MODE_ISHTP) {
803 rv = ish_fw_xfer_ishtp(client_data, fw);
804 } else {
805 dev_err(cl_data_to_dev(client_data),
806 "No transfer mode selected in firmware\n");
807 rv = -EINVAL;
808 }
809 if (rv < 0)
810 goto end_err_fw_release;
811
812 /* Step 3: Start ISH main firmware exeuction */
813
814 rv = ish_fw_start(client_data);
815 if (rv < 0)
816 goto end_err_fw_release;
817
818 release_firmware(fw);
819 kfree(filename);
820 dev_info(cl_data_to_dev(client_data), "ISH firmware %s loaded\n",
821 filename);
822 return 0;
823
824end_err_fw_release:
825 release_firmware(fw);
826end_err_filename_buf_release:
827 kfree(filename);
828end_error:
829 /* Keep a count of retries, and give up after 3 attempts */
830 if (client_data->flag_retry &&
831 client_data->retry_count++ < MAX_LOAD_ATTEMPTS) {
832 dev_warn(cl_data_to_dev(client_data),
833 "ISH host firmware load failed %d. Resetting ISH, and trying again..\n",
834 rv);
835 ish_hw_reset(ishtp_get_ishtp_device(loader_ishtp_cl));
836 } else {
837 dev_err(cl_data_to_dev(client_data),
838 "ISH host firmware load failed %d\n", rv);
839 }
840 return rv;
841}
842
843static void load_fw_from_host_handler(struct work_struct *work)
844{
845 struct ishtp_cl_data *client_data;
846
847 client_data = container_of(work, struct ishtp_cl_data,
848 work_fw_load);
849 load_fw_from_host(client_data);
850}
851
852/**
853 * loader_init() - Init function for ISH-TP client
854 * @loader_ishtp_cl: ISH-TP client instance
855 * @reset: true if called for init after reset
856 *
857 * Return: 0 for success, negative error code for failure
858 */
859static int loader_init(struct ishtp_cl *loader_ishtp_cl, int reset)
860{
861 int rv;
862 struct ishtp_fw_client *fw_client;
863 struct ishtp_cl_data *client_data =
864 ishtp_get_client_data(loader_ishtp_cl);
865
866 dev_dbg(cl_data_to_dev(client_data), "reset flag: %d\n", reset);
867
868 rv = ishtp_cl_link(loader_ishtp_cl);
869 if (rv < 0) {
870 dev_err(cl_data_to_dev(client_data), "ishtp_cl_link failed\n");
871 return rv;
872 }
873
874 /* Connect to firmware client */
875 ishtp_set_tx_ring_size(loader_ishtp_cl, LOADER_CL_TX_RING_SIZE);
876 ishtp_set_rx_ring_size(loader_ishtp_cl, LOADER_CL_RX_RING_SIZE);
877
878 fw_client =
879 ishtp_fw_cl_get_client(ishtp_get_ishtp_device(loader_ishtp_cl),
880 &loader_ishtp_guid);
881 if (!fw_client) {
882 dev_err(cl_data_to_dev(client_data),
883 "ISH client uuid not found\n");
884 rv = -ENOENT;
885 goto err_cl_unlink;
886 }
887
888 ishtp_cl_set_fw_client_id(loader_ishtp_cl,
889 ishtp_get_fw_client_id(fw_client));
890 ishtp_set_connection_state(loader_ishtp_cl, ISHTP_CL_CONNECTING);
891
892 rv = ishtp_cl_connect(loader_ishtp_cl);
893 if (rv < 0) {
894 dev_err(cl_data_to_dev(client_data), "Client connect fail\n");
895 goto err_cl_unlink;
896 }
897
898 dev_dbg(cl_data_to_dev(client_data), "Client connected\n");
899
900 ishtp_register_event_cb(client_data->cl_device, loader_cl_event_cb);
901
902 return 0;
903
904err_cl_unlink:
905 ishtp_cl_unlink(loader_ishtp_cl);
906 return rv;
907}
908
909static void loader_deinit(struct ishtp_cl *loader_ishtp_cl)
910{
911 ishtp_set_connection_state(loader_ishtp_cl, ISHTP_CL_DISCONNECTING);
912 ishtp_cl_disconnect(loader_ishtp_cl);
913 ishtp_cl_unlink(loader_ishtp_cl);
914 ishtp_cl_flush_queues(loader_ishtp_cl);
915
916 /* Disband and free all Tx and Rx client-level rings */
917 ishtp_cl_free(loader_ishtp_cl);
918}
919
920static void reset_handler(struct work_struct *work)
921{
922 int rv;
923 struct ishtp_cl_data *client_data;
924 struct ishtp_cl *loader_ishtp_cl;
925 struct ishtp_cl_device *cl_device;
926
927 client_data = container_of(work, struct ishtp_cl_data,
928 work_ishtp_reset);
929
930 loader_ishtp_cl = client_data->loader_ishtp_cl;
931 cl_device = client_data->cl_device;
932
933 /* Unlink, flush queues & start again */
934 ishtp_cl_unlink(loader_ishtp_cl);
935 ishtp_cl_flush_queues(loader_ishtp_cl);
936 ishtp_cl_free(loader_ishtp_cl);
937
938 loader_ishtp_cl = ishtp_cl_allocate(cl_device);
939 if (!loader_ishtp_cl)
940 return;
941
942 ishtp_set_drvdata(cl_device, loader_ishtp_cl);
943 ishtp_set_client_data(loader_ishtp_cl, client_data);
944 client_data->loader_ishtp_cl = loader_ishtp_cl;
945 client_data->cl_device = cl_device;
946
947 rv = loader_init(loader_ishtp_cl, 1);
948 if (rv < 0) {
949 dev_err(ishtp_device(cl_device), "Reset Failed\n");
950 return;
951 }
952
953 /* ISH firmware loading from host */
954 load_fw_from_host(client_data);
955}
956
957/**
958 * loader_ishtp_cl_probe() - ISH-TP client driver probe
959 * @cl_device: ISH-TP client device instance
960 *
961 * This function gets called on device create on ISH-TP bus
962 *
963 * Return: 0 for success, negative error code for failure
964 */
965static int loader_ishtp_cl_probe(struct ishtp_cl_device *cl_device)
966{
967 struct ishtp_cl *loader_ishtp_cl;
968 struct ishtp_cl_data *client_data;
969 int rv;
970
971 client_data = devm_kzalloc(ishtp_device(cl_device),
972 sizeof(*client_data),
973 GFP_KERNEL);
974 if (!client_data)
975 return -ENOMEM;
976
977 loader_ishtp_cl = ishtp_cl_allocate(cl_device);
978 if (!loader_ishtp_cl)
979 return -ENOMEM;
980
981 ishtp_set_drvdata(cl_device, loader_ishtp_cl);
982 ishtp_set_client_data(loader_ishtp_cl, client_data);
983 client_data->loader_ishtp_cl = loader_ishtp_cl;
984 client_data->cl_device = cl_device;
985
986 init_waitqueue_head(&client_data->response.wait_queue);
987
988 INIT_WORK(&client_data->work_ishtp_reset,
989 reset_handler);
990 INIT_WORK(&client_data->work_fw_load,
991 load_fw_from_host_handler);
992
993 rv = loader_init(loader_ishtp_cl, 0);
994 if (rv < 0) {
995 ishtp_cl_free(loader_ishtp_cl);
996 return rv;
997 }
998 ishtp_get_device(cl_device);
999
1000 client_data->retry_count = 0;
1001
1002 /* ISH firmware loading from host */
1003 schedule_work(&client_data->work_fw_load);
1004
1005 return 0;
1006}
1007
1008/**
1009 * loader_ishtp_cl_remove() - ISH-TP client driver remove
1010 * @cl_device: ISH-TP client device instance
1011 *
1012 * This function gets called on device remove on ISH-TP bus
1013 *
1014 * Return: 0
1015 */
1016static int loader_ishtp_cl_remove(struct ishtp_cl_device *cl_device)
1017{
1018 struct ishtp_cl_data *client_data;
1019 struct ishtp_cl *loader_ishtp_cl = ishtp_get_drvdata(cl_device);
1020
1021 client_data = ishtp_get_client_data(loader_ishtp_cl);
1022
1023 /*
1024 * The sequence of the following two cancel_work_sync() is
1025 * important. The work_fw_load can in turn schedue
1026 * work_ishtp_reset, so first cancel work_fw_load then
1027 * cancel work_ishtp_reset.
1028 */
1029 cancel_work_sync(&client_data->work_fw_load);
1030 cancel_work_sync(&client_data->work_ishtp_reset);
1031 loader_deinit(loader_ishtp_cl);
1032 ishtp_put_device(cl_device);
1033
1034 return 0;
1035}
1036
1037/**
1038 * loader_ishtp_cl_reset() - ISH-TP client driver reset
1039 * @cl_device: ISH-TP client device instance
1040 *
1041 * This function gets called on device reset on ISH-TP bus
1042 *
1043 * Return: 0
1044 */
1045static int loader_ishtp_cl_reset(struct ishtp_cl_device *cl_device)
1046{
1047 struct ishtp_cl_data *client_data;
1048 struct ishtp_cl *loader_ishtp_cl = ishtp_get_drvdata(cl_device);
1049
1050 client_data = ishtp_get_client_data(loader_ishtp_cl);
1051
1052 schedule_work(&client_data->work_ishtp_reset);
1053
1054 return 0;
1055}
1056
1057static struct ishtp_cl_driver loader_ishtp_cl_driver = {
1058 .name = "ish-loader",
1059 .guid = &loader_ishtp_guid,
1060 .probe = loader_ishtp_cl_probe,
1061 .remove = loader_ishtp_cl_remove,
1062 .reset = loader_ishtp_cl_reset,
1063};
1064
1065static int __init ish_loader_init(void)
1066{
1067 return ishtp_cl_driver_register(&loader_ishtp_cl_driver, THIS_MODULE);
1068}
1069
1070static void __exit ish_loader_exit(void)
1071{
1072 ishtp_cl_driver_unregister(&loader_ishtp_cl_driver);
1073}
1074
1075late_initcall(ish_loader_init);
1076module_exit(ish_loader_exit);
1077
1078module_param(dma_buf_size_limit, int, 0644);
1079MODULE_PARM_DESC(dma_buf_size_limit, "Limit the DMA buf size to this value in bytes");
1080
1081MODULE_DESCRIPTION("ISH ISH-TP Host firmware Loader Client Driver");
1082MODULE_AUTHOR("Rushikesh S Kadam <rushikesh.s.kadam@intel.com>");
1083
1084MODULE_LICENSE("GPL v2");
1085MODULE_ALIAS("ishtp:*");
drivers/hid/intel-ish-hid/ishtp-hid-client.c+92−76
@@ -15,15 +15,16 @@ · 14 unmodified lines
15 15
16#include <linux/module.h>16#include <linux/module.h>
17#include <linux/hid.h>17#include <linux/hid.h>
18#include <linux/intel-ish-client-if.h>
18#include <linux/sched.h>19#include <linux/sched.h>
19#include "ishtp/ishtp-dev.h"
20#include "ishtp/client.h"
21#include "ishtp-hid.h"20#include "ishtp-hid.h"
22 21
23/* Rx ring buffer pool size */22/* Rx ring buffer pool size */
24#define HID_CL_RX_RING_SIZE 3223#define HID_CL_RX_RING_SIZE 32
25#define HID_CL_TX_RING_SIZE 1624#define HID_CL_TX_RING_SIZE 16
26 25
26#define cl_data_to_dev(client_data) ishtp_device(client_data->cl_device)
27
27/**28/**
28 * report_bad_packets() - Report bad packets29 * report_bad_packets() - Report bad packets
29 * @hid_ishtp_cl: Client instance to get stats30 * @hid_ishtp_cl: Client instance to get stats
@@ -37,9 +38,9 @@ static void report_bad_packet(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, · 7 unmodified lines
37 size_t cur_pos, size_t payload_len)38 size_t cur_pos, size_t payload_len)
38{39{
39 struct hostif_msg *recv_msg = recv_buf;40 struct hostif_msg *recv_msg = recv_buf;
40 struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;41 struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl);
41 42
42 dev_err(&client_data->cl_device->dev, "[hid-ish]: BAD packet %02X\n"43 dev_err(cl_data_to_dev(client_data), "[hid-ish]: BAD packet %02X\n"
43 "total_bad=%u cur_pos=%u\n"44 "total_bad=%u cur_pos=%u\n"
44 "[%02X %02X %02X %02X]\n"45 "[%02X %02X %02X %02X]\n"
45 "payload_len=%u\n"46 "payload_len=%u\n"
@@ -69,13 +70,15 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, · 23 unmodified lines
69 unsigned char *payload;70 unsigned char *payload;
70 struct device_info *dev_info;71 struct device_info *dev_info;
71 int i, j;72 int i, j;
72 size_t payload_len, total_len, cur_pos;73 size_t payload_len, total_len, cur_pos, raw_len;
73 int report_type;74 int report_type;
74 struct report_list *reports_list;75 struct report_list *reports_list;
75 char *reports;76 char *reports;
76 size_t report_len;77 size_t report_len;
77 struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;78 struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl);
78 int curr_hid_dev = client_data->cur_hid_dev;79 int curr_hid_dev = client_data->cur_hid_dev;
80 struct ishtp_hid_data *hid_data = NULL;
81 struct hid_device *hid = NULL;
79 82
80 payload = recv_buf + sizeof(struct hostif_msg_hdr);83 payload = recv_buf + sizeof(struct hostif_msg_hdr);
81 total_len = data_len;84 total_len = data_len;
@@ -83,12 +86,12 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, · 1 unmodified line
83 86
84 do {87 do {
85 if (cur_pos + sizeof(struct hostif_msg) > total_len) {88 if (cur_pos + sizeof(struct hostif_msg) > total_len) {
86 dev_err(&client_data->cl_device->dev,89 dev_err(cl_data_to_dev(client_data),
87 "[hid-ish]: error, received %u which is less than data header %u\n",90 "[hid-ish]: error, received %u which is less than data header %u\n",
88 (unsigned int)data_len,91 (unsigned int)data_len,
89 (unsigned int)sizeof(struct hostif_msg_hdr));92 (unsigned int)sizeof(struct hostif_msg_hdr));
90 ++client_data->bad_recv_cnt;93 ++client_data->bad_recv_cnt;
91 ish_hw_reset(hid_ishtp_cl->dev);94 ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl));
92 break;95 break;
93 }96 }
94 97
@@ -101,7 +104,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, · 6 unmodified lines
101 ++client_data->bad_recv_cnt;104 ++client_data->bad_recv_cnt;
102 report_bad_packet(hid_ishtp_cl, recv_msg, cur_pos,105 report_bad_packet(hid_ishtp_cl, recv_msg, cur_pos,
103 payload_len);106 payload_len);
104 ish_hw_reset(hid_ishtp_cl->dev);107 ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl));
105 break;108 break;
106 }109 }
107 110
@@ -116,18 +119,18 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, · 8 unmodified lines
116 report_bad_packet(hid_ishtp_cl, recv_msg,119 report_bad_packet(hid_ishtp_cl, recv_msg,
117 cur_pos,120 cur_pos,
118 payload_len);121 payload_len);
119 ish_hw_reset(hid_ishtp_cl->dev);122 ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl));
120 break;123 break;
121 }124 }
122 client_data->hid_dev_count = (unsigned int)*payload;125 client_data->hid_dev_count = (unsigned int)*payload;
123 if (!client_data->hid_devices)126 if (!client_data->hid_devices)
124 client_data->hid_devices = devm_kcalloc(127 client_data->hid_devices = devm_kcalloc(
125 &client_data->cl_device->dev,128 cl_data_to_dev(client_data),
126 client_data->hid_dev_count,129 client_data->hid_dev_count,
127 sizeof(struct device_info),130 sizeof(struct device_info),
128 GFP_KERNEL);131 GFP_KERNEL);
129 if (!client_data->hid_devices) {132 if (!client_data->hid_devices) {
130 dev_err(&client_data->cl_device->dev,133 dev_err(cl_data_to_dev(client_data),
131 "Mem alloc failed for hid device info\n");134 "Mem alloc failed for hid device info\n");
132 wake_up_interruptible(&client_data->init_wait);135 wake_up_interruptible(&client_data->init_wait);
133 break;136 break;
@@ -135,7 +138,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, · 1 unmodified line
135 for (i = 0; i < client_data->hid_dev_count; ++i) {138 for (i = 0; i < client_data->hid_dev_count; ++i) {
136 if (1 + sizeof(struct device_info) * i >=139 if (1 + sizeof(struct device_info) * i >=
137 payload_len) {140 payload_len) {
138 dev_err(&client_data->cl_device->dev,141 dev_err(cl_data_to_dev(client_data),
139 "[hid-ish]: [ENUM_DEVICES]: content size %zu is bigger than payload_len %zu\n",142 "[hid-ish]: [ENUM_DEVICES]: content size %zu is bigger than payload_len %zu\n",
140 1 + sizeof(struct device_info)143 1 + sizeof(struct device_info)
141 * i, payload_len);144 * i, payload_len);
@@ -165,12 +168,12 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, · 23 unmodified lines
165 report_bad_packet(hid_ishtp_cl, recv_msg,168 report_bad_packet(hid_ishtp_cl, recv_msg,
166 cur_pos,169 cur_pos,
167 payload_len);170 payload_len);
168 ish_hw_reset(hid_ishtp_cl->dev);171 ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl));
169 break;172 break;
170 }173 }
171 if (!client_data->hid_descr[curr_hid_dev])174 if (!client_data->hid_descr[curr_hid_dev])
172 client_data->hid_descr[curr_hid_dev] =175 client_data->hid_descr[curr_hid_dev] =
173 devm_kmalloc(&client_data->cl_device->dev,176 devm_kmalloc(cl_data_to_dev(client_data),
174 payload_len, GFP_KERNEL);177 payload_len, GFP_KERNEL);
175 if (client_data->hid_descr[curr_hid_dev]) {178 if (client_data->hid_descr[curr_hid_dev]) {
176 memcpy(client_data->hid_descr[curr_hid_dev],179 memcpy(client_data->hid_descr[curr_hid_dev],
@@ -190,12 +193,12 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, · 13 unmodified lines
190 report_bad_packet(hid_ishtp_cl, recv_msg,193 report_bad_packet(hid_ishtp_cl, recv_msg,
191 cur_pos,194 cur_pos,
192 payload_len);195 payload_len);
193 ish_hw_reset(hid_ishtp_cl->dev);196 ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl));
194 break;197 break;
195 }198 }
196 if (!client_data->report_descr[curr_hid_dev])199 if (!client_data->report_descr[curr_hid_dev])
197 client_data->report_descr[curr_hid_dev] =200 client_data->report_descr[curr_hid_dev] =
198 devm_kmalloc(&client_data->cl_device->dev,201 devm_kmalloc(cl_data_to_dev(client_data),
199 payload_len, GFP_KERNEL);202 payload_len, GFP_KERNEL);
200 if (client_data->report_descr[curr_hid_dev]) {203 if (client_data->report_descr[curr_hid_dev]) {
201 memcpy(client_data->report_descr[curr_hid_dev],204 memcpy(client_data->report_descr[curr_hid_dev],
@@ -219,18 +222,31 @@ do_get_report: · 17 unmodified lines
219 /* Get index of device that matches this id */222 /* Get index of device that matches this id */
220 for (i = 0; i < client_data->num_hid_devices; ++i) {223 for (i = 0; i < client_data->num_hid_devices; ++i) {
221 if (recv_msg->hdr.device_id ==224 if (recv_msg->hdr.device_id ==
222 client_data->hid_devices[i].dev_id)225 client_data->hid_devices[i].dev_id) {
223 if (client_data->hid_sensor_hubs[i]) {226 hid = client_data->hid_sensor_hubs[i];
224 hid_input_report(227 if (!hid)
225 client_data->hid_sensor_hubs[
226 i],
227 report_type, payload,
228 payload_len, 0);
229 ishtp_hid_wakeup(
230 client_data->hid_sensor_hubs[
231 i]);
232 break;228 break;
229
230 hid_data = hid->driver_data;
231 if (hid_data->raw_get_req) {
232 raw_len =
233 (hid_data->raw_buf_size <
234 payload_len) ?
235 hid_data->raw_buf_size :
236 payload_len;
237
238 memcpy(hid_data->raw_buf,
239 payload, raw_len);
240 } else {
241 hid_input_report
242 (hid, report_type,
243 payload, payload_len,
244 0);
233 }245 }
246
247 ishtp_hid_wakeup(hid);
248 break;
249 }
234 }250 }
235 break;251 break;
236 252
@@ -295,7 +311,7 @@ do_get_report: · 58 unmodified lines
295 ++client_data->bad_recv_cnt;311 ++client_data->bad_recv_cnt;
296 report_bad_packet(hid_ishtp_cl, recv_msg, cur_pos,312 report_bad_packet(hid_ishtp_cl, recv_msg, cur_pos,
297 payload_len);313 payload_len);
298 ish_hw_reset(hid_ishtp_cl->dev);314 ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl));
299 break;315 break;
300 316
301 }317 }
@@ -475,7 +491,7 @@ int ishtp_hid_link_ready_wait(struct ishtp_cl_data *client_data) · 173 unmodified lines
475static int ishtp_enum_enum_devices(struct ishtp_cl *hid_ishtp_cl)491static int ishtp_enum_enum_devices(struct ishtp_cl *hid_ishtp_cl)
476{492{
477 struct hostif_msg msg;493 struct hostif_msg msg;
478 struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;494 struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl);
479 int retry_count;495 int retry_count;
480 int rv;496 int rv;
481 497
@@ -501,18 +517,18 @@ static int ishtp_enum_enum_devices(struct ishtp_cl *hid_ishtp_cl) · 19 unmodified lines
501 sizeof(struct hostif_msg));517 sizeof(struct hostif_msg));
502 }518 }
503 if (!client_data->enum_devices_done) {519 if (!client_data->enum_devices_done) {
504 dev_err(&client_data->cl_device->dev,520 dev_err(cl_data_to_dev(client_data),
505 "[hid-ish]: timed out waiting for enum_devices\n");521 "[hid-ish]: timed out waiting for enum_devices\n");
506 return -ETIMEDOUT;522 return -ETIMEDOUT;
507 }523 }
508 if (!client_data->hid_devices) {524 if (!client_data->hid_devices) {
509 dev_err(&client_data->cl_device->dev,525 dev_err(cl_data_to_dev(client_data),
510 "[hid-ish]: failed to allocate HID dev structures\n");526 "[hid-ish]: failed to allocate HID dev structures\n");
511 return -ENOMEM;527 return -ENOMEM;
512 }528 }
513 529
514 client_data->num_hid_devices = client_data->hid_dev_count;530 client_data->num_hid_devices = client_data->hid_dev_count;
515 dev_info(&hid_ishtp_cl->device->dev,531 dev_info(ishtp_device(client_data->cl_device),
516 "[hid-ish]: enum_devices_done OK, num_hid_devices=%d\n",532 "[hid-ish]: enum_devices_done OK, num_hid_devices=%d\n",
517 client_data->num_hid_devices);533 client_data->num_hid_devices);
518 534
@@ -531,7 +547,7 @@ static int ishtp_enum_enum_devices(struct ishtp_cl *hid_ishtp_cl) · 12 unmodified lines
531static int ishtp_get_hid_descriptor(struct ishtp_cl *hid_ishtp_cl, int index)547static int ishtp_get_hid_descriptor(struct ishtp_cl *hid_ishtp_cl, int index)
532{548{
533 struct hostif_msg msg;549 struct hostif_msg msg;
534 struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;550 struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl);
535 int rv;551 int rv;
536 552
537 /* Get HID descriptor */553 /* Get HID descriptor */
@@ -549,13 +565,13 @@ static int ishtp_get_hid_descriptor(struct ishtp_cl *hid_ishtp_cl, int index) · 11 unmodified lines
549 client_data->hid_descr_done,565 client_data->hid_descr_done,
550 3 * HZ);566 3 * HZ);
551 if (!client_data->hid_descr_done) {567 if (!client_data->hid_descr_done) {
552 dev_err(&client_data->cl_device->dev,568 dev_err(cl_data_to_dev(client_data),
553 "[hid-ish]: timed out for hid_descr_done\n");569 "[hid-ish]: timed out for hid_descr_done\n");
554 return -EIO;570 return -EIO;
555 }571 }
556 572
557 if (!client_data->hid_descr[index]) {573 if (!client_data->hid_descr[index]) {
558 dev_err(&client_data->cl_device->dev,574 dev_err(cl_data_to_dev(client_data),
559 "[hid-ish]: allocation HID desc fail\n");575 "[hid-ish]: allocation HID desc fail\n");
560 return -ENOMEM;576 return -ENOMEM;
561 }577 }
@@ -578,7 +594,7 @@ static int ishtp_get_report_descriptor(struct ishtp_cl *hid_ishtp_cl, · 16 unmodified lines
578 int index)594 int index)
579{595{
580 struct hostif_msg msg;596 struct hostif_msg msg;
581 struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;597 struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl);
582 int rv;598 int rv;
583 599
584 /* Get report descriptor */600 /* Get report descriptor */
@@ -596,12 +612,12 @@ static int ishtp_get_report_descriptor(struct ishtp_cl *hid_ishtp_cl, · 11 unmodified lines
596 client_data->report_descr_done,612 client_data->report_descr_done,
597 3 * HZ);613 3 * HZ);
598 if (!client_data->report_descr_done) {614 if (!client_data->report_descr_done) {
599 dev_err(&client_data->cl_device->dev,615 dev_err(cl_data_to_dev(client_data),
600 "[hid-ish]: timed out for report descr\n");616 "[hid-ish]: timed out for report descr\n");
601 return -EIO;617 return -EIO;
602 }618 }
603 if (!client_data->report_descr[index]) {619 if (!client_data->report_descr[index]) {
604 dev_err(&client_data->cl_device->dev,620 dev_err(cl_data_to_dev(client_data),
605 "[hid-ish]: failed to alloc report descr\n");621 "[hid-ish]: failed to alloc report descr\n");
606 return -ENOMEM;622 return -ENOMEM;
607 }623 }
@@ -626,42 +642,42 @@ static int ishtp_get_report_descriptor(struct ishtp_cl *hid_ishtp_cl, · 18 unmodified lines
626static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset)642static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset)
627{643{
628 struct ishtp_device *dev;644 struct ishtp_device *dev;
629 struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;645 struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl);
630 struct ishtp_fw_client *fw_client;646 struct ishtp_fw_client *fw_client;
631 int i;647 int i;
632 int rv;648 int rv;
633 649
634 dev_dbg(&client_data->cl_device->dev, "%s\n", __func__);650 dev_dbg(cl_data_to_dev(client_data), "%s\n", __func__);
635 hid_ishtp_trace(client_data, "%s reset flag: %d\n", __func__, reset);651 hid_ishtp_trace(client_data, "%s reset flag: %d\n", __func__, reset);
636 652
637 rv = ishtp_cl_link(hid_ishtp_cl, ISHTP_HOST_CLIENT_ID_ANY);653 rv = ishtp_cl_link(hid_ishtp_cl);
638 if (rv) {654 if (rv) {
639 dev_err(&client_data->cl_device->dev,655 dev_err(cl_data_to_dev(client_data),
640 "ishtp_cl_link failed\n");656 "ishtp_cl_link failed\n");
641 return -ENOMEM;657 return -ENOMEM;
642 }658 }
643 659
644 client_data->init_done = 0;660 client_data->init_done = 0;
645 661
646 dev = hid_ishtp_cl->dev;662 dev = ishtp_get_ishtp_device(hid_ishtp_cl);
647 663
648 /* Connect to FW client */664 /* Connect to FW client */
649 hid_ishtp_cl->rx_ring_size = HID_CL_RX_RING_SIZE;665 ishtp_set_tx_ring_size(hid_ishtp_cl, HID_CL_TX_RING_SIZE);
650 hid_ishtp_cl->tx_ring_size = HID_CL_TX_RING_SIZE;666 ishtp_set_rx_ring_size(hid_ishtp_cl, HID_CL_RX_RING_SIZE);
651 667
652 fw_client = ishtp_fw_cl_get_client(dev, &hid_ishtp_guid);668 fw_client = ishtp_fw_cl_get_client(dev, &hid_ishtp_guid);
653 if (!fw_client) {669 if (!fw_client) {
654 dev_err(&client_data->cl_device->dev,670 dev_err(cl_data_to_dev(client_data),
655 "ish client uuid not found\n");671 "ish client uuid not found\n");
656 return -ENOENT;672 return -ENOENT;
657 }673 }
658 674 ishtp_cl_set_fw_client_id(hid_ishtp_cl,
659 hid_ishtp_cl->fw_client_id = fw_client->client_id;675 ishtp_get_fw_client_id(fw_client));
660 hid_ishtp_cl->state = ISHTP_CL_CONNECTING;676 ishtp_set_connection_state(hid_ishtp_cl, ISHTP_CL_CONNECTING);
661 677
662 rv = ishtp_cl_connect(hid_ishtp_cl);678 rv = ishtp_cl_connect(hid_ishtp_cl);
663 if (rv) {679 if (rv) {
664 dev_err(&client_data->cl_device->dev,680 dev_err(cl_data_to_dev(client_data),
665 "client connect fail\n");681 "client connect fail\n");
666 goto err_cl_unlink;682 goto err_cl_unlink;
667 }683 }
@@ -669,7 +685,7 @@ static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset) · 1 unmodified line
669 hid_ishtp_trace(client_data, "%s client connected\n", __func__);685 hid_ishtp_trace(client_data, "%s client connected\n", __func__);
670 686
671 /* Register read callback */687 /* Register read callback */
672 ishtp_register_event_cb(hid_ishtp_cl->device, ish_cl_event_cb);688 ishtp_register_event_cb(client_data->cl_device, ish_cl_event_cb);
673 689
674 rv = ishtp_enum_enum_devices(hid_ishtp_cl);690 rv = ishtp_enum_enum_devices(hid_ishtp_cl);
675 if (rv)691 if (rv)
@@ -692,7 +708,7 @@ static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset) · 16 unmodified lines
692 if (!reset) {708 if (!reset) {
693 rv = ishtp_hid_probe(i, client_data);709 rv = ishtp_hid_probe(i, client_data);
694 if (rv) {710 if (rv) {
695 dev_err(&client_data->cl_device->dev,711 dev_err(cl_data_to_dev(client_data),
696 "[hid-ish]: HID probe for #%u failed: %d\n",712 "[hid-ish]: HID probe for #%u failed: %d\n",
697 i, rv);713 i, rv);
698 goto err_cl_disconnect;714 goto err_cl_disconnect;
@@ -707,7 +723,7 @@ static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset) · 8 unmodified lines
707 return 0;723 return 0;
708 724
709err_cl_disconnect:725err_cl_disconnect:
710 hid_ishtp_cl->state = ISHTP_CL_DISCONNECTING;726 ishtp_set_connection_state(hid_ishtp_cl, ISHTP_CL_DISCONNECTING);
711 ishtp_cl_disconnect(hid_ishtp_cl);727 ishtp_cl_disconnect(hid_ishtp_cl);
712err_cl_unlink:728err_cl_unlink:
713 ishtp_cl_unlink(hid_ishtp_cl);729 ishtp_cl_unlink(hid_ishtp_cl);
@@ -744,16 +760,16 @@ static void hid_ishtp_cl_reset_handler(struct work_struct *work) · 30 unmodified lines
744 760
745 hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__,761 hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__,
746 hid_ishtp_cl);762 hid_ishtp_cl);
747 dev_dbg(&cl_device->dev, "%s\n", __func__);763 dev_dbg(ishtp_device(client_data->cl_device), "%s\n", __func__);
748 764
749 hid_ishtp_cl_deinit(hid_ishtp_cl);765 hid_ishtp_cl_deinit(hid_ishtp_cl);
750 766
751 hid_ishtp_cl = ishtp_cl_allocate(cl_device->ishtp_dev);767 hid_ishtp_cl = ishtp_cl_allocate(cl_device);
752 if (!hid_ishtp_cl)768 if (!hid_ishtp_cl)
753 return;769 return;
754 770
755 ishtp_set_drvdata(cl_device, hid_ishtp_cl);771 ishtp_set_drvdata(cl_device, hid_ishtp_cl);
756 hid_ishtp_cl->client_data = client_data;772 ishtp_set_client_data(hid_ishtp_cl, client_data);
757 client_data->hid_ishtp_cl = hid_ishtp_cl;773 client_data->hid_ishtp_cl = hid_ishtp_cl;
758 774
759 client_data->num_hid_devices = 0;775 client_data->num_hid_devices = 0;
@@ -762,15 +778,17 @@ static void hid_ishtp_cl_reset_handler(struct work_struct *work) · 2 unmodified lines
762 rv = hid_ishtp_cl_init(hid_ishtp_cl, 1);778 rv = hid_ishtp_cl_init(hid_ishtp_cl, 1);
763 if (!rv)779 if (!rv)
764 break;780 break;
765 dev_err(&client_data->cl_device->dev, "Retry reset init\n");781 dev_err(cl_data_to_dev(client_data), "Retry reset init\n");
766 }782 }
767 if (rv) {783 if (rv) {
768 dev_err(&client_data->cl_device->dev, "Reset Failed\n");784 dev_err(cl_data_to_dev(client_data), "Reset Failed\n");
769 hid_ishtp_trace(client_data, "%s Failed hid_ishtp_cl %p\n",785 hid_ishtp_trace(client_data, "%s Failed hid_ishtp_cl %p\n",
770 __func__, hid_ishtp_cl);786 __func__, hid_ishtp_cl);
771 }787 }
772}788}
773 789
790void (*hid_print_trace)(void *unused, const char *format, ...);
791
774/**792/**
775 * hid_ishtp_cl_probe() - ISHTP client driver probe793 * hid_ishtp_cl_probe() - ISHTP client driver probe
776 * @cl_device: ISHTP client device instance794 * @cl_device: ISHTP client device instance
@@ -788,21 +806,18 @@ static int hid_ishtp_cl_probe(struct ishtp_cl_device *cl_device) · 11 unmodified lines
788 if (!cl_device)806 if (!cl_device)
789 return -ENODEV;807 return -ENODEV;
790 808
791 if (!guid_equal(&hid_ishtp_guid,809 client_data = devm_kzalloc(ishtp_device(cl_device),
792 &cl_device->fw_client->props.protocol_name))810 sizeof(*client_data),
793 return -ENODEV;
794
795 client_data = devm_kzalloc(&cl_device->dev, sizeof(*client_data),
796 GFP_KERNEL);811 GFP_KERNEL);
797 if (!client_data)812 if (!client_data)
798 return -ENOMEM;813 return -ENOMEM;
799 814
800 hid_ishtp_cl = ishtp_cl_allocate(cl_device->ishtp_dev);815 hid_ishtp_cl = ishtp_cl_allocate(cl_device);
801 if (!hid_ishtp_cl)816 if (!hid_ishtp_cl)
802 return -ENOMEM;817 return -ENOMEM;
803 818
804 ishtp_set_drvdata(cl_device, hid_ishtp_cl);819 ishtp_set_drvdata(cl_device, hid_ishtp_cl);
805 hid_ishtp_cl->client_data = client_data;820 ishtp_set_client_data(hid_ishtp_cl, client_data);
806 client_data->hid_ishtp_cl = hid_ishtp_cl;821 client_data->hid_ishtp_cl = hid_ishtp_cl;
807 client_data->cl_device = cl_device;822 client_data->cl_device = cl_device;
808 823
@@ -811,6 +826,8 @@ static int hid_ishtp_cl_probe(struct ishtp_cl_device *cl_device) · 2 unmodified lines
811 826
812 INIT_WORK(&client_data->work, hid_ishtp_cl_reset_handler);827 INIT_WORK(&client_data->work, hid_ishtp_cl_reset_handler);
813 828
829 hid_print_trace = ishtp_trace_callback(cl_device);
830
814 rv = hid_ishtp_cl_init(hid_ishtp_cl, 0);831 rv = hid_ishtp_cl_init(hid_ishtp_cl, 0);
815 if (rv) {832 if (rv) {
816 ishtp_cl_free(hid_ishtp_cl);833 ishtp_cl_free(hid_ishtp_cl);
@@ -832,13 +849,13 @@ static int hid_ishtp_cl_probe(struct ishtp_cl_device *cl_device) · 15 unmodified lines
832static int hid_ishtp_cl_remove(struct ishtp_cl_device *cl_device)849static int hid_ishtp_cl_remove(struct ishtp_cl_device *cl_device)
833{850{
834 struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device);851 struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device);
835 struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;852 struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl);
836 853
837 hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__,854 hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__,
838 hid_ishtp_cl);855 hid_ishtp_cl);
839 856
840 dev_dbg(&cl_device->dev, "%s\n", __func__);857 dev_dbg(ishtp_device(cl_device), "%s\n", __func__);
841 hid_ishtp_cl->state = ISHTP_CL_DISCONNECTING;858 ishtp_set_connection_state(hid_ishtp_cl, ISHTP_CL_DISCONNECTING);
842 ishtp_cl_disconnect(hid_ishtp_cl);859 ishtp_cl_disconnect(hid_ishtp_cl);
843 ishtp_put_device(cl_device);860 ishtp_put_device(cl_device);
844 ishtp_hid_remove(client_data);861 ishtp_hid_remove(client_data);
@@ -862,7 +879,7 @@ static int hid_ishtp_cl_remove(struct ishtp_cl_device *cl_device) · 17 unmodified lines
862static int hid_ishtp_cl_reset(struct ishtp_cl_device *cl_device)879static int hid_ishtp_cl_reset(struct ishtp_cl_device *cl_device)
863{880{
864 struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device);881 struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device);
865 struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;882 struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl);
866 883
867 hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__,884 hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__,
868 hid_ishtp_cl);885 hid_ishtp_cl);
@@ -872,8 +889,6 @@ static int hid_ishtp_cl_reset(struct ishtp_cl_device *cl_device) · 3 unmodified lines
872 return 0;889 return 0;
873}890}
874 891
875#define to_ishtp_cl_device(d) container_of(d, struct ishtp_cl_device, dev)
876
877/**892/**
878 * hid_ishtp_cl_suspend() - ISHTP client driver suspend893 * hid_ishtp_cl_suspend() - ISHTP client driver suspend
879 * @device: device instance894 * @device: device instance
@@ -884,9 +899,9 @@ static int hid_ishtp_cl_reset(struct ishtp_cl_device *cl_device) · 4 unmodified lines
884 */899 */
885static int hid_ishtp_cl_suspend(struct device *device)900static int hid_ishtp_cl_suspend(struct device *device)
886{901{
887 struct ishtp_cl_device *cl_device = to_ishtp_cl_device(device);902 struct ishtp_cl_device *cl_device = dev_get_drvdata(device);
888 struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device);903 struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device);
889 struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;904 struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl);
890 905
891 hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__,906 hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__,
892 hid_ishtp_cl);907 hid_ishtp_cl);
@@ -905,9 +920,9 @@ static int hid_ishtp_cl_suspend(struct device *device) · 12 unmodified lines
905 */920 */
906static int hid_ishtp_cl_resume(struct device *device)921static int hid_ishtp_cl_resume(struct device *device)
907{922{
908 struct ishtp_cl_device *cl_device = to_ishtp_cl_device(device);923 struct ishtp_cl_device *cl_device = dev_get_drvdata(device);
909 struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device);924 struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device);
910 struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;925 struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl);
911 926
912 hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__,927 hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__,
913 hid_ishtp_cl);928 hid_ishtp_cl);
@@ -922,6 +937,7 @@ static const struct dev_pm_ops hid_ishtp_pm_ops = { · 8 unmodified lines
922 937
923static struct ishtp_cl_driver hid_ishtp_cl_driver = {938static struct ishtp_cl_driver hid_ishtp_cl_driver = {
924 .name = "ish-hid",939 .name = "ish-hid",
940 .guid = &hid_ishtp_guid,
925 .probe = hid_ishtp_cl_probe,941 .probe = hid_ishtp_cl_probe,
926 .remove = hid_ishtp_cl_remove,942 .remove = hid_ishtp_cl_remove,
927 .reset = hid_ishtp_cl_reset,943 .reset = hid_ishtp_cl_reset,
@@ -933,7 +949,7 @@ static int __init ish_hid_init(void) · 5 unmodified lines
933 int rv;949 int rv;
934 950
935 /* Register ISHTP client device driver with ISHTP Bus */951 /* Register ISHTP client device driver with ISHTP Bus */
936 rv = ishtp_cl_driver_register(&hid_ishtp_cl_driver);952 rv = ishtp_cl_driver_register(&hid_ishtp_cl_driver, THIS_MODULE);
937 953
938 return rv;954 return rv;
939 955
drivers/hid/intel-ish-hid/ishtp-hid.c+43−6
@@ -14,8 +14,8 @@ · 13 unmodified lines
14 */14 */
15 15
16#include <linux/hid.h>16#include <linux/hid.h>
17#include <linux/intel-ish-client-if.h>
17#include <uapi/linux/input.h>18#include <uapi/linux/input.h>
18#include "ishtp/client.h"
19#include "ishtp-hid.h"19#include "ishtp-hid.h"
20 20
21/**21/**
@@ -59,10 +59,46 @@ static void ishtp_hid_close(struct hid_device *hid) · 37 unmodified lines
59{59{
60}60}
61 61
62static int ishtp_raw_request(struct hid_device *hdev, unsigned char reportnum,62static int ishtp_raw_request(struct hid_device *hid, unsigned char reportnum,
63 __u8 *buf, size_t len, unsigned char rtype, int reqtype)63 __u8 *buf, size_t len, unsigned char rtype,
64 int reqtype)
64{65{
65 return 0;66 struct ishtp_hid_data *hid_data = hid->driver_data;
67 char *ishtp_buf = NULL;
68 size_t ishtp_buf_len;
69 unsigned int header_size = sizeof(struct hostif_msg);
70
71 if (rtype == HID_OUTPUT_REPORT)
72 return -EINVAL;
73
74 hid_data->request_done = false;
75 switch (reqtype) {
76 case HID_REQ_GET_REPORT:
77 hid_data->raw_buf = buf;
78 hid_data->raw_buf_size = len;
79 hid_data->raw_get_req = true;
80
81 hid_ishtp_get_report(hid, reportnum, rtype);
82 break;
83 case HID_REQ_SET_REPORT:
84 /*
85 * Spare 7 bytes for 64b accesses through
86 * get/put_unaligned_le64()
87 */
88 ishtp_buf_len = len + header_size;
89 ishtp_buf = kzalloc(ishtp_buf_len + 7, GFP_KERNEL);
90 if (!ishtp_buf)
91 return -ENOMEM;
92
93 memcpy(ishtp_buf + header_size, buf, len);
94 hid_ishtp_set_feature(hid, ishtp_buf, ishtp_buf_len, reportnum);
95 kfree(ishtp_buf);
96 break;
97 }
98
99 hid_hw_wait(hid);
100
101 return len;
66}102}
67 103
68/**104/**
@@ -87,6 +123,7 @@ static void ishtp_hid_request(struct hid_device *hid, struct hid_report *rep, · 18 unmodified lines
87 hid_data->request_done = false;123 hid_data->request_done = false;
88 switch (reqtype) {124 switch (reqtype) {
89 case HID_REQ_GET_REPORT:125 case HID_REQ_GET_REPORT:
126 hid_data->raw_get_req = false;
90 hid_ishtp_get_report(hid, rep->id, rep->type);127 hid_ishtp_get_report(hid, rep->id, rep->type);
91 break;128 break;
92 case HID_REQ_SET_REPORT:129 case HID_REQ_SET_REPORT:
@@ -116,7 +153,6 @@ static void ishtp_hid_request(struct hid_device *hid, struct hid_report *rep, · 23 unmodified lines
116static int ishtp_wait_for_response(struct hid_device *hid)153static int ishtp_wait_for_response(struct hid_device *hid)
117{154{
118 struct ishtp_hid_data *hid_data = hid->driver_data;155 struct ishtp_hid_data *hid_data = hid->driver_data;
119 struct ishtp_cl_data *client_data = hid_data->client_data;
120 int rv;156 int rv;
121 157
122 hid_ishtp_trace(client_data, "%s hid %p\n", __func__, hid);158 hid_ishtp_trace(client_data, "%s hid %p\n", __func__, hid);
@@ -204,7 +240,8 @@ int ishtp_hid_probe(unsigned int cur_hid_dev, · 81 unmodified lines
204 240
205 hid->ll_driver = &ishtp_hid_ll_driver;241 hid->ll_driver = &ishtp_hid_ll_driver;
206 hid->bus = BUS_INTEL_ISHTP;242 hid->bus = BUS_INTEL_ISHTP;
207 hid->dev.parent = &client_data->cl_device->dev;243 hid->dev.parent = ishtp_device(client_data->cl_device);
244
208 hid->version = le16_to_cpu(ISH_HID_VERSION);245 hid->version = le16_to_cpu(ISH_HID_VERSION);
209 hid->vendor = le16_to_cpu(client_data->hid_devices[cur_hid_dev].vid);246 hid->vendor = le16_to_cpu(client_data->hid_devices[cur_hid_dev].vid);
210 hid->product = le16_to_cpu(client_data->hid_devices[cur_hid_dev].pid);247 hid->product = le16_to_cpu(client_data->hid_devices[cur_hid_dev].pid);
drivers/hid/intel-ish-hid/ishtp-hid.h+11−3
@@ -24,9 +24,9 @@ · 23 unmodified lines
24#define IS_RESPONSE 0x8024#define IS_RESPONSE 0x80
25 25
26/* Used to dump to Linux trace buffer, if enabled */26/* Used to dump to Linux trace buffer, if enabled */
27#define hid_ishtp_trace(client, ...) \27extern void (*hid_print_trace)(void *unused, const char *format, ...);
28 client->cl_device->ishtp_dev->print_log(\28#define hid_ishtp_trace(client, ...) \
29 client->cl_device->ishtp_dev, __VA_ARGS__)29 (hid_print_trace)(NULL, __VA_ARGS__)
30 30
31/* ISH Transport protocol (ISHTP in short) GUID */31/* ISH Transport protocol (ISHTP in short) GUID */
32static const guid_t hid_ishtp_guid =32static const guid_t hid_ishtp_guid =
@@ -159,6 +159,9 @@ struct ishtp_cl_data { · 126 unmodified lines
159 * @client_data: Link to the client instance159 * @client_data: Link to the client instance
160 * @hid_wait: Completion waitq160 * @hid_wait: Completion waitq
161 *161 *
162 * @raw_get_req: Flag indicating raw get request ongoing
163 * @raw_buf: raw request buffer filled on receiving get report
164 * @raw_buf_size: raw request buffer size
162 * Used to tie hid hid->driver data to driver client instance165 * Used to tie hid hid->driver data to driver client instance
163 */166 */
164struct ishtp_hid_data {167struct ishtp_hid_data {
@@ -166,6 +169,11 @@ struct ishtp_hid_data { · 1 unmodified line
166 bool request_done;169 bool request_done;
167 struct ishtp_cl_data *client_data;170 struct ishtp_cl_data *client_data;
168 wait_queue_head_t hid_wait;171 wait_queue_head_t hid_wait;
172
173 /* raw request */
174 bool raw_get_req;
175 u8 *raw_buf;
176 size_t raw_buf_size;
169};177};
170 178
171/* Interface functions between HID LL driver and ISH TP client */179/* Interface functions between HID LL driver and ISH TP client */
drivers/hid/intel-ish-hid/ishtp/bus.c+92−4
@@ -170,6 +170,19 @@ struct ishtp_fw_client *ishtp_fw_cl_get_client(struct ishtp_device *dev, · 169 unmodified lines
170}170}
171EXPORT_SYMBOL(ishtp_fw_cl_get_client);171EXPORT_SYMBOL(ishtp_fw_cl_get_client);
172 172
173/**
174 * ishtp_get_fw_client_id() - Get fw client id
175 *
176 * This interface is used to reset HW get FW client id.
177 *
178 * Return: firmware client id.
179 */
180int ishtp_get_fw_client_id(struct ishtp_fw_client *fw_client)
181{
182 return fw_client->client_id;
183}
184EXPORT_SYMBOL(ishtp_get_fw_client_id);
185
173/**186/**
174 * ishtp_fw_cl_by_id() - return index to fw_clients for client_id187 * ishtp_fw_cl_by_id() - return index to fw_clients for client_id
175 * @dev: the ishtp device structure188 * @dev: the ishtp device structure
@@ -219,6 +232,26 @@ static int ishtp_cl_device_probe(struct device *dev) · 43 unmodified lines
219 return driver->probe(device);232 return driver->probe(device);
220}233}
221 234
235/**
236 * ishtp_cl_bus_match() - Bus match() callback
237 * @dev: the device structure
238 * @drv: the driver structure
239 *
240 * This is a bus match callback, called when a new ishtp_cl_device is
241 * registered during ishtp bus client enumeration. Use the guid_t in
242 * drv and dev to decide whether they match or not.
243 *
244 * Return: 1 if dev & drv matches, 0 otherwise.
245 */
246static int ishtp_cl_bus_match(struct device *dev, struct device_driver *drv)
247{
248 struct ishtp_cl_device *device = to_ishtp_cl_device(dev);
249 struct ishtp_cl_driver *driver = to_ishtp_cl_driver(drv);
250
251 return guid_equal(driver->guid,
252 &device->fw_client->props.protocol_name);
253}
254
222/**255/**
223 * ishtp_cl_device_remove() - Bus remove() callback256 * ishtp_cl_device_remove() - Bus remove() callback
224 * @dev: the device structure257 * @dev: the device structure
@@ -372,6 +405,7 @@ static struct bus_type ishtp_cl_bus_type = { · 147 unmodified lines
372 .name = "ishtp",405 .name = "ishtp",
373 .dev_groups = ishtp_cl_dev_groups,406 .dev_groups = ishtp_cl_dev_groups,
374 .probe = ishtp_cl_device_probe,407 .probe = ishtp_cl_device_probe,
408 .match = ishtp_cl_bus_match,
375 .remove = ishtp_cl_device_remove,409 .remove = ishtp_cl_device_remove,
376 .pm = &ishtp_cl_bus_dev_pm_ops,410 .pm = &ishtp_cl_bus_dev_pm_ops,
377 .uevent = ishtp_cl_uevent,411 .uevent = ishtp_cl_uevent,
@@ -445,6 +479,7 @@ static struct ishtp_cl_device *ishtp_bus_add_device(struct ishtp_device *dev, · 67 unmodified lines
445 }479 }
446 480
447 ishtp_device_ready = true;481 ishtp_device_ready = true;
482 dev_set_drvdata(&device->dev, device);
448 483
449 return device;484 return device;
450}485}
@@ -464,7 +499,7 @@ static void ishtp_bus_remove_device(struct ishtp_cl_device *device) · 13 unmodified lines
464}499}
465 500
466/**501/**
467 * __ishtp_cl_driver_register() - Client driver register502 * ishtp_cl_driver_register() - Client driver register
468 * @driver: the client driver instance503 * @driver: the client driver instance
469 * @owner: Owner of this driver module504 * @owner: Owner of this driver module
470 *505 *
@@ -473,8 +508,8 @@ static void ishtp_bus_remove_device(struct ishtp_cl_device *device) · 2 unmodified lines
473 *508 *
474 * Return: Return value of driver_register or -ENODEV if not ready509 * Return: Return value of driver_register or -ENODEV if not ready
475 */510 */
476int __ishtp_cl_driver_register(struct ishtp_cl_driver *driver,511int ishtp_cl_driver_register(struct ishtp_cl_driver *driver,
477 struct module *owner)512 struct module *owner)
478{513{
479 int err;514 int err;
480 515
@@ -491,7 +526,7 @@ int __ishtp_cl_driver_register(struct ishtp_cl_driver *driver, · 10 unmodified lines
491 526
492 return 0;527 return 0;
493}528}
494EXPORT_SYMBOL(__ishtp_cl_driver_register);529EXPORT_SYMBOL(ishtp_cl_driver_register);
495 530
496/**531/**
497 * ishtp_cl_driver_unregister() - Client driver unregister532 * ishtp_cl_driver_unregister() - Client driver unregister
@@ -806,6 +841,59 @@ int ishtp_use_dma_transfer(void) · 308 unmodified lines
806 return ishtp_use_dma;841 return ishtp_use_dma;
807}842}
808 843
844/**
845 * ishtp_device() - Return device pointer
846 *
847 * This interface is used to return device pointer from ishtp_cl_device
848 * instance.
849 *
850 * Return: device *.
851 */
852struct device *ishtp_device(struct ishtp_cl_device *device)
853{
854 return &device->dev;
855}
856EXPORT_SYMBOL(ishtp_device);
857
858/**
859 * ishtp_get_pci_device() - Return PCI device dev pointer
860 * This interface is used to return PCI device pointer
861 * from ishtp_cl_device instance.
862 *
863 * Return: device *.
864 */
865struct device *ishtp_get_pci_device(struct ishtp_cl_device *device)
866{
867 return device->ishtp_dev->devc;
868}
869EXPORT_SYMBOL(ishtp_get_pci_device);
870
871/**
872 * ishtp_trace_callback() - Return trace callback
873 *
874 * This interface is used to return trace callback function pointer.
875 *
876 * Return: void *.
877 */
878void *ishtp_trace_callback(struct ishtp_cl_device *cl_device)
879{
880 return cl_device->ishtp_dev->print_log;
881}
882EXPORT_SYMBOL(ishtp_trace_callback);
883
884/**
885 * ish_hw_reset() - Call HW reset IPC callback
886 *
887 * This interface is used to reset HW in case of error.
888 *
889 * Return: value from IPC hw_reset callback
890 */
891int ish_hw_reset(struct ishtp_device *dev)
892{
893 return dev->ops->hw_reset(dev);
894}
895EXPORT_SYMBOL(ish_hw_reset);
896
809/**897/**
810 * ishtp_bus_register() - Function to register bus898 * ishtp_bus_register() - Function to register bus
811 *899 *
drivers/hid/intel-ish-hid/ishtp/bus.h+1−36
@@ -17,6 +17,7 @@ · 16 unmodified lines
17 17
18#include <linux/device.h>18#include <linux/device.h>
19#include <linux/mod_devicetable.h>19#include <linux/mod_devicetable.h>
20#include <linux/intel-ish-client-if.h>
20 21
21struct ishtp_cl;22struct ishtp_cl;
22struct ishtp_cl_device;23struct ishtp_cl_device;
@@ -52,25 +53,6 @@ struct ishtp_cl_device { · 29 unmodified lines
52 void (*event_cb)(struct ishtp_cl_device *device);53 void (*event_cb)(struct ishtp_cl_device *device);
53};54};
54 55
55/**
56 * struct ishtp_cl_device - ISHTP device handle
57 * @driver: driver instance on a bus
58 * @name: Name of the device for probe
59 * @probe: driver callback for device probe
60 * @remove: driver callback on device removal
61 *
62 * Client drivers defines to get probed/removed for ISHTP client device.
63 */
64struct ishtp_cl_driver {
65 struct device_driver driver;
66 const char *name;
67 int (*probe)(struct ishtp_cl_device *dev);
68 int (*remove)(struct ishtp_cl_device *dev);
69 int (*reset)(struct ishtp_cl_device *dev);
70 const struct dev_pm_ops *pm;
71};
72
73
74int ishtp_bus_new_client(struct ishtp_device *dev);56int ishtp_bus_new_client(struct ishtp_device *dev);
75void ishtp_remove_all_clients(struct ishtp_device *dev);57void ishtp_remove_all_clients(struct ishtp_device *dev);
76int ishtp_cl_device_bind(struct ishtp_cl *cl);58int ishtp_cl_device_bind(struct ishtp_cl *cl);
@@ -98,22 +80,5 @@ void ishtp_recv(struct ishtp_device *dev); · 21 unmodified lines
98void ishtp_reset_handler(struct ishtp_device *dev);80void ishtp_reset_handler(struct ishtp_device *dev);
99void ishtp_reset_compl_handler(struct ishtp_device *dev);81void ishtp_reset_compl_handler(struct ishtp_device *dev);
100 82
101void ishtp_put_device(struct ishtp_cl_device *);
102void ishtp_get_device(struct ishtp_cl_device *);
103
104void ishtp_set_drvdata(struct ishtp_cl_device *cl_device, void *data);
105void *ishtp_get_drvdata(struct ishtp_cl_device *cl_device);
106
107int __ishtp_cl_driver_register(struct ishtp_cl_driver *driver,
108 struct module *owner);
109#define ishtp_cl_driver_register(driver) \
110 __ishtp_cl_driver_register(driver, THIS_MODULE)
111void ishtp_cl_driver_unregister(struct ishtp_cl_driver *driver);
112
113int ishtp_register_event_cb(struct ishtp_cl_device *device,
114 void (*read_cb)(struct ishtp_cl_device *));
115int ishtp_fw_cl_by_uuid(struct ishtp_device *dev, const guid_t *cuuid);83int ishtp_fw_cl_by_uuid(struct ishtp_device *dev, const guid_t *cuuid);
116struct ishtp_fw_client *ishtp_fw_cl_get_client(struct ishtp_device *dev,
117 const guid_t *uuid);
118
119#endif /* _LINUX_ISHTP_CL_BUS_H */84#endif /* _LINUX_ISHTP_CL_BUS_H */
drivers/hid/intel-ish-hid/ishtp/client.c+48−12
@@ -126,7 +126,7 @@ static void ishtp_cl_init(struct ishtp_cl *cl, struct ishtp_device *dev) · 125 unmodified lines
126 *126 *
127 * Return: The allocated client instance or NULL on failure127 * Return: The allocated client instance or NULL on failure
128 */128 */
129struct ishtp_cl *ishtp_cl_allocate(struct ishtp_device *dev)129struct ishtp_cl *ishtp_cl_allocate(struct ishtp_cl_device *cl_device)
130{130{
131 struct ishtp_cl *cl;131 struct ishtp_cl *cl;
132 132
@@ -134,7 +134,7 @@ struct ishtp_cl *ishtp_cl_allocate(struct ishtp_device *dev) · 1 unmodified line
134 if (!cl)134 if (!cl)
135 return NULL;135 return NULL;
136 136
137 ishtp_cl_init(cl, dev);137 ishtp_cl_init(cl, cl_device->ishtp_dev);
138 return cl;138 return cl;
139}139}
140EXPORT_SYMBOL(ishtp_cl_allocate);140EXPORT_SYMBOL(ishtp_cl_allocate);
@@ -168,9 +168,6 @@ EXPORT_SYMBOL(ishtp_cl_free); · 27 unmodified lines
168/**168/**
169 * ishtp_cl_link() - Reserve a host id and link the client instance169 * ishtp_cl_link() - Reserve a host id and link the client instance
170 * @cl: client device instance170 * @cl: client device instance
171 * @id: host client id to use. It can be ISHTP_HOST_CLIENT_ID_ANY if any
172 * id from the available can be used
173 *
174 *171 *
175 * This allocates a single bit in the hostmap. This function will make sure172 * This allocates a single bit in the hostmap. This function will make sure
176 * that not many client sessions are opened at the same time. Once allocated173 * that not many client sessions are opened at the same time. Once allocated
@@ -179,11 +176,11 @@ EXPORT_SYMBOL(ishtp_cl_free); · 2 unmodified lines
179 *176 *
180 * Return: 0 or error code on failure177 * Return: 0 or error code on failure
181 */178 */
182int ishtp_cl_link(struct ishtp_cl *cl, int id)179int ishtp_cl_link(struct ishtp_cl *cl)
183{180{
184 struct ishtp_device *dev;181 struct ishtp_device *dev;
185 unsigned long flags, flags_cl;182 unsigned long flags, flags_cl;
186 int ret = 0;183 int id, ret = 0;
187 184
188 if (WARN_ON(!cl || !cl->dev))185 if (WARN_ON(!cl || !cl->dev))
189 return -EINVAL;186 return -EINVAL;
@@ -197,10 +194,7 @@ int ishtp_cl_link(struct ishtp_cl *cl, int id) · 7 unmodified lines
197 goto unlock_dev;194 goto unlock_dev;
198 }195 }
199 196
200 /* If Id is not assigned get one*/197 id = find_first_zero_bit(dev->host_clients_map, ISHTP_CLIENTS_MAX);
201 if (id == ISHTP_HOST_CLIENT_ID_ANY)
202 id = find_first_zero_bit(dev->host_clients_map,
203 ISHTP_CLIENTS_MAX);
204 198
205 if (id >= ISHTP_CLIENTS_MAX) {199 if (id >= ISHTP_CLIENTS_MAX) {
206 spin_unlock_irqrestore(&dev->device_lock, flags);200 spin_unlock_irqrestore(&dev->device_lock, flags);
@@ -1069,3 +1063,45 @@ void recv_ishtp_cl_msg_dma(struct ishtp_device *dev, void *msg, · 862 unmodified lines
1069eoi:1063eoi:
1070 return;1064 return;
1071}1065}
1066
1067void *ishtp_get_client_data(struct ishtp_cl *cl)
1068{
1069 return cl->client_data;
1070}
1071EXPORT_SYMBOL(ishtp_get_client_data);
1072
1073void ishtp_set_client_data(struct ishtp_cl *cl, void *data)
1074{
1075 cl->client_data = data;
1076}
1077EXPORT_SYMBOL(ishtp_set_client_data);
1078
1079struct ishtp_device *ishtp_get_ishtp_device(struct ishtp_cl *cl)
1080{
1081 return cl->dev;
1082}
1083EXPORT_SYMBOL(ishtp_get_ishtp_device);
1084
1085void ishtp_set_tx_ring_size(struct ishtp_cl *cl, int size)
1086{
1087 cl->tx_ring_size = size;
1088}
1089EXPORT_SYMBOL(ishtp_set_tx_ring_size);
1090
1091void ishtp_set_rx_ring_size(struct ishtp_cl *cl, int size)
1092{
1093 cl->rx_ring_size = size;
1094}
1095EXPORT_SYMBOL(ishtp_set_rx_ring_size);
1096
1097void ishtp_set_connection_state(struct ishtp_cl *cl, int state)
1098{
1099 cl->state = state;
1100}
1101EXPORT_SYMBOL(ishtp_set_connection_state);
1102
1103void ishtp_cl_set_fw_client_id(struct ishtp_cl *cl, int fw_client_id)
1104{
1105 cl->fw_client_id = fw_client_id;
1106}
1107EXPORT_SYMBOL(ishtp_cl_set_fw_client_id);
drivers/hid/intel-ish-hid/ishtp/client.h+0−24
@@ -19,15 +19,6 @@ · 18 unmodified lines
19#include <linux/types.h>19#include <linux/types.h>
20#include "ishtp-dev.h"20#include "ishtp-dev.h"
21 21
22/* Client state */
23enum cl_state {
24 ISHTP_CL_INITIALIZING = 0,
25 ISHTP_CL_CONNECTING,
26 ISHTP_CL_CONNECTED,
27 ISHTP_CL_DISCONNECTING,
28 ISHTP_CL_DISCONNECTED
29};
30
31/* Tx and Rx ring size */22/* Tx and Rx ring size */
32#define CL_DEF_RX_RING_SIZE 223#define CL_DEF_RX_RING_SIZE 2
33#define CL_DEF_TX_RING_SIZE 224#define CL_DEF_TX_RING_SIZE 2
@@ -169,19 +160,4 @@ static inline bool ishtp_cl_cmp_id(const struct ishtp_cl *cl1, · 135 unmodified lines
169 (cl1->fw_client_id == cl2->fw_client_id);160 (cl1->fw_client_id == cl2->fw_client_id);
170}161}
171 162
172/* exported functions from ISHTP under client management scope */
173struct ishtp_cl *ishtp_cl_allocate(struct ishtp_device *dev);
174void ishtp_cl_free(struct ishtp_cl *cl);
175int ishtp_cl_link(struct ishtp_cl *cl, int id);
176void ishtp_cl_unlink(struct ishtp_cl *cl);
177int ishtp_cl_disconnect(struct ishtp_cl *cl);
178int ishtp_cl_connect(struct ishtp_cl *cl);
179int ishtp_cl_send(struct ishtp_cl *cl, uint8_t *buf, size_t length);
180int ishtp_cl_flush_queues(struct ishtp_cl *cl);
181
182/* exported functions from ISHTP client buffer management scope */
183int ishtp_cl_io_rb_recycle(struct ishtp_cl_rb *rb);
184bool ishtp_cl_tx_empty(struct ishtp_cl *cl);
185struct ishtp_cl_rb *ishtp_cl_rx_get_rb(struct ishtp_cl *cl);
186
187#endif /* _ISHTP_CLIENT_H_ */163#endif /* _ISHTP_CLIENT_H_ */
drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h+0−31
@@ -79,32 +79,6 @@ struct ishtp_fw_client { · 78 unmodified lines
79 uint8_t client_id;79 uint8_t client_id;
80};80};
81 81
82/**
83 * struct ishtp_msg_data - ISHTP message data struct
84 * @size: Size of data in the *data
85 * @data: Pointer to data
86 */
87struct ishtp_msg_data {
88 uint32_t size;
89 unsigned char *data;
90};
91
92/*
93 * struct ishtp_cl_rb - request block structure
94 * @list: Link to list members
95 * @cl: ISHTP client instance
96 * @buffer: message header
97 * @buf_idx: Index into buffer
98 * @read_time: unused at this time
99 */
100struct ishtp_cl_rb {
101 struct list_head list;
102 struct ishtp_cl *cl;
103 struct ishtp_msg_data buffer;
104 unsigned long buf_idx;
105 unsigned long read_time;
106};
107
108/*82/*
109 * Control info for IPC messages ISHTP/IPC sending FIFO -83 * Control info for IPC messages ISHTP/IPC sending FIFO -
110 * list with inline data buffer84 * list with inline data buffer
@@ -264,11 +238,6 @@ static inline int ish_ipc_reset(struct ishtp_device *dev) · 153 unmodified lines
264 return dev->ops->ipc_reset(dev);238 return dev->ops->ipc_reset(dev);
265}239}
266 240
267static inline int ish_hw_reset(struct ishtp_device *dev)
268{
269 return dev->ops->hw_reset(dev);
270}
271
272/* Exported function */241/* Exported function */
273void ishtp_device_init(struct ishtp_device *dev);242void ishtp_device_init(struct ishtp_device *dev);
274int ishtp_start(struct ishtp_device *dev);243int ishtp_start(struct ishtp_device *dev);
include/linux/hid.h+3−1
@@ -382,6 +382,7 @@ struct hid_item { · 381 unmodified lines
382#define HID_GROUP_WACOM 0x0101382#define HID_GROUP_WACOM 0x0101
383#define HID_GROUP_LOGITECH_DJ_DEVICE 0x0102383#define HID_GROUP_LOGITECH_DJ_DEVICE 0x0102
384#define HID_GROUP_STEAM 0x0103384#define HID_GROUP_STEAM 0x0103
385#define HID_GROUP_LOGITECH_27MHZ_DEVICE 0x0104
385 386
386/*387/*
387 * HID protocol status388 * HID protocol status
@@ -417,6 +418,7 @@ struct hid_global { · 29 unmodified lines
417 418
418struct hid_local {419struct hid_local {
419 unsigned usage[HID_MAX_USAGES]; /* usage array */420 unsigned usage[HID_MAX_USAGES]; /* usage array */
421 u8 usage_size[HID_MAX_USAGES]; /* usage size array */
420 unsigned collection_index[HID_MAX_USAGES]; /* collection index array */422 unsigned collection_index[HID_MAX_USAGES]; /* collection index array */
421 unsigned usage_index;423 unsigned usage_index;
422 unsigned usage_minimum;424 unsigned usage_minimum;
@@ -893,7 +895,7 @@ struct hid_field *hidinput_get_led_field(struct hid_device *hid); · 470 unmodified lines
893unsigned int hidinput_count_leds(struct hid_device *hid);895unsigned int hidinput_count_leds(struct hid_device *hid);
894__s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code);896__s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code);
895void hid_output_report(struct hid_report *report, __u8 *data);897void hid_output_report(struct hid_report *report, __u8 *data);
896void __hid_request(struct hid_device *hid, struct hid_report *rep, int reqtype);898int __hid_request(struct hid_device *hid, struct hid_report *rep, int reqtype);
897u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags);899u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags);
898struct hid_device *hid_allocate_device(void);900struct hid_device *hid_allocate_device(void);
899struct hid_report *hid_register_report(struct hid_device *device,901struct hid_report *hid_register_report(struct hid_device *device,
include/linux/intel-ish-client-if.h+112−0
@@ -0,0 +1,112 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Intel ISH client Interface definitions
4 *
5 * Copyright (c) 2019, Intel Corporation.
6 */
7
8#ifndef _INTEL_ISH_CLIENT_IF_H_
9#define _INTEL_ISH_CLIENT_IF_H_
10
11struct ishtp_cl_device;
12struct ishtp_device;
13struct ishtp_cl;
14struct ishtp_fw_client;
15
16/* Client state */
17enum cl_state {
18 ISHTP_CL_INITIALIZING = 0,
19 ISHTP_CL_CONNECTING,
20 ISHTP_CL_CONNECTED,
21 ISHTP_CL_DISCONNECTING,
22 ISHTP_CL_DISCONNECTED
23};
24
25/**
26 * struct ishtp_cl_device - ISHTP device handle
27 * @driver: driver instance on a bus
28 * @name: Name of the device for probe
29 * @probe: driver callback for device probe
30 * @remove: driver callback on device removal
31 *
32 * Client drivers defines to get probed/removed for ISHTP client device.
33 */
34struct ishtp_cl_driver {
35 struct device_driver driver;
36 const char *name;
37 const guid_t *guid;
38 int (*probe)(struct ishtp_cl_device *dev);
39 int (*remove)(struct ishtp_cl_device *dev);
40 int (*reset)(struct ishtp_cl_device *dev);
41 const struct dev_pm_ops *pm;
42};
43
44/**
45 * struct ishtp_msg_data - ISHTP message data struct
46 * @size: Size of data in the *data
47 * @data: Pointer to data
48 */
49struct ishtp_msg_data {
50 uint32_t size;
51 unsigned char *data;
52};
53
54/*
55 * struct ishtp_cl_rb - request block structure
56 * @list: Link to list members
57 * @cl: ISHTP client instance
58 * @buffer: message header
59 * @buf_idx: Index into buffer
60 * @read_time: unused at this time
61 */
62struct ishtp_cl_rb {
63 struct list_head list;
64 struct ishtp_cl *cl;
65 struct ishtp_msg_data buffer;
66 unsigned long buf_idx;
67 unsigned long read_time;
68};
69
70int ishtp_cl_driver_register(struct ishtp_cl_driver *driver,
71 struct module *owner);
72void ishtp_cl_driver_unregister(struct ishtp_cl_driver *driver);
73int ishtp_register_event_cb(struct ishtp_cl_device *device,
74 void (*read_cb)(struct ishtp_cl_device *));
75
76/* Get the device * from ishtp device instance */
77struct device *ishtp_device(struct ishtp_cl_device *cl_device);
78/* Trace interface for clients */
79void *ishtp_trace_callback(struct ishtp_cl_device *cl_device);
80/* Get device pointer of PCI device for DMA acces */
81struct device *ishtp_get_pci_device(struct ishtp_cl_device *cl_device);
82
83struct ishtp_cl *ishtp_cl_allocate(struct ishtp_cl_device *cl_device);
84void ishtp_cl_free(struct ishtp_cl *cl);
85int ishtp_cl_link(struct ishtp_cl *cl);
86void ishtp_cl_unlink(struct ishtp_cl *cl);
87int ishtp_cl_disconnect(struct ishtp_cl *cl);
88int ishtp_cl_connect(struct ishtp_cl *cl);
89int ishtp_cl_send(struct ishtp_cl *cl, uint8_t *buf, size_t length);
90int ishtp_cl_flush_queues(struct ishtp_cl *cl);
91int ishtp_cl_io_rb_recycle(struct ishtp_cl_rb *rb);
92bool ishtp_cl_tx_empty(struct ishtp_cl *cl);
93struct ishtp_cl_rb *ishtp_cl_rx_get_rb(struct ishtp_cl *cl);
94void *ishtp_get_client_data(struct ishtp_cl *cl);
95void ishtp_set_client_data(struct ishtp_cl *cl, void *data);
96struct ishtp_device *ishtp_get_ishtp_device(struct ishtp_cl *cl);
97void ishtp_set_tx_ring_size(struct ishtp_cl *cl, int size);
98void ishtp_set_rx_ring_size(struct ishtp_cl *cl, int size);
99void ishtp_set_connection_state(struct ishtp_cl *cl, int state);
100void ishtp_cl_set_fw_client_id(struct ishtp_cl *cl, int fw_client_id);
101
102void ishtp_put_device(struct ishtp_cl_device *cl_dev);
103void ishtp_get_device(struct ishtp_cl_device *cl_dev);
104void ishtp_set_drvdata(struct ishtp_cl_device *cl_device, void *data);
105void *ishtp_get_drvdata(struct ishtp_cl_device *cl_device);
106int ishtp_register_event_cb(struct ishtp_cl_device *device,
107 void (*read_cb)(struct ishtp_cl_device *));
108struct ishtp_fw_client *ishtp_fw_cl_get_client(struct ishtp_device *dev,
109 const guid_t *uuid);
110int ishtp_get_fw_client_id(struct ishtp_fw_client *fw_client);
111int ish_hw_reset(struct ishtp_device *dev);
112#endif /* _INTEL_ISH_CLIENT_IF_H_ */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t