@@ -1110,8 +1110,31 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
1110
1110
1111
1111
set_bit (usage -> type , input -> evbit );
1112
1112
1113
- while (usage -> code <= max && test_and_set_bit (usage -> code , bit ))
1114
- usage -> code = find_next_zero_bit (bit , max + 1 , usage -> code );
1113
+ /*
1114
+ * This part is *really* controversial:
1115
+ * - HID aims at being generic so we should do our best to export
1116
+ * all incoming events
1117
+ * - HID describes what events are, so there is no reason for ABS_X
1118
+ * to be mapped to ABS_Y
1119
+ * - HID is using *_MISC+N as a default value, but nothing prevents
1120
+ * *_MISC+N to overwrite a legitimate even, which confuses userspace
1121
+ * (for instance ABS_MISC + 7 is ABS_MT_SLOT, which has a different
1122
+ * processing)
1123
+ *
1124
+ * If devices still want to use this (at their own risk), they will
1125
+ * have to use the quirk HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE, but
1126
+ * the default should be a reliable mapping.
1127
+ */
1128
+ while (usage -> code <= max && test_and_set_bit (usage -> code , bit )) {
1129
+ if (device -> quirks & HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE ) {
1130
+ usage -> code = find_next_zero_bit (bit ,
1131
+ max + 1 ,
1132
+ usage -> code );
1133
+ } else {
1134
+ device -> status |= HID_STAT_DUP_DETECTED ;
1135
+ goto ignore ;
1136
+ }
1137
+ }
1115
1138
1116
1139
if (usage -> code > max )
1117
1140
goto ignore ;
@@ -1487,15 +1510,56 @@ static void report_features(struct hid_device *hid)
1487
1510
}
1488
1511
}
1489
1512
1490
- static struct hid_input * hidinput_allocate (struct hid_device * hid )
1513
+ static struct hid_input * hidinput_allocate (struct hid_device * hid ,
1514
+ unsigned int application )
1491
1515
{
1492
1516
struct hid_input * hidinput = kzalloc (sizeof (* hidinput ), GFP_KERNEL );
1493
1517
struct input_dev * input_dev = input_allocate_device ();
1494
- if (!hidinput || !input_dev ) {
1495
- kfree (hidinput );
1496
- input_free_device (input_dev );
1497
- hid_err (hid , "Out of memory during hid input probe\n" );
1498
- return NULL ;
1518
+ const char * suffix = NULL ;
1519
+
1520
+ if (!hidinput || !input_dev )
1521
+ goto fail ;
1522
+
1523
+ if ((hid -> quirks & HID_QUIRK_INPUT_PER_APP ) &&
1524
+ hid -> maxapplication > 1 ) {
1525
+ switch (application ) {
1526
+ case HID_GD_KEYBOARD :
1527
+ suffix = "Keyboard" ;
1528
+ break ;
1529
+ case HID_GD_KEYPAD :
1530
+ suffix = "Keypad" ;
1531
+ break ;
1532
+ case HID_GD_MOUSE :
1533
+ suffix = "Mouse" ;
1534
+ break ;
1535
+ case HID_DG_STYLUS :
1536
+ suffix = "Pen" ;
1537
+ break ;
1538
+ case HID_DG_TOUCHSCREEN :
1539
+ suffix = "Touchscreen" ;
1540
+ break ;
1541
+ case HID_DG_TOUCHPAD :
1542
+ suffix = "Touchpad" ;
1543
+ break ;
1544
+ case HID_GD_SYSTEM_CONTROL :
1545
+ suffix = "System Control" ;
1546
+ break ;
1547
+ case HID_CP_CONSUMER_CONTROL :
1548
+ suffix = "Consumer Control" ;
1549
+ break ;
1550
+ case HID_GD_WIRELESS_RADIO_CTLS :
1551
+ suffix = "Wireless Radio Control" ;
1552
+ break ;
1553
+ default :
1554
+ break ;
1555
+ }
1556
+ }
1557
+
1558
+ if (suffix ) {
1559
+ hidinput -> name = kasprintf (GFP_KERNEL , "%s %s" ,
1560
+ hid -> name , suffix );
1561
+ if (!hidinput -> name )
1562
+ goto fail ;
1499
1563
}
1500
1564
1501
1565
input_set_drvdata (input_dev , hid );
@@ -1505,18 +1569,27 @@ static struct hid_input *hidinput_allocate(struct hid_device *hid)
1505
1569
input_dev -> setkeycode = hidinput_setkeycode ;
1506
1570
input_dev -> getkeycode = hidinput_getkeycode ;
1507
1571
1508
- input_dev -> name = hid -> name ;
1572
+ input_dev -> name = hidinput -> name ? hidinput -> name : hid -> name ;
1509
1573
input_dev -> phys = hid -> phys ;
1510
1574
input_dev -> uniq = hid -> uniq ;
1511
1575
input_dev -> id .bustype = hid -> bus ;
1512
1576
input_dev -> id .vendor = hid -> vendor ;
1513
1577
input_dev -> id .product = hid -> product ;
1514
1578
input_dev -> id .version = hid -> version ;
1515
1579
input_dev -> dev .parent = & hid -> dev ;
1580
+
1516
1581
hidinput -> input = input_dev ;
1517
1582
list_add_tail (& hidinput -> list , & hid -> inputs );
1518
1583
1584
+ INIT_LIST_HEAD (& hidinput -> reports );
1585
+
1519
1586
return hidinput ;
1587
+
1588
+ fail :
1589
+ kfree (hidinput );
1590
+ input_free_device (input_dev );
1591
+ hid_err (hid , "Out of memory during hid input probe\n" );
1592
+ return NULL ;
1520
1593
}
1521
1594
1522
1595
static bool hidinput_has_been_populated (struct hid_input * hidinput )
@@ -1562,6 +1635,7 @@ static void hidinput_cleanup_hidinput(struct hid_device *hid,
1562
1635
1563
1636
list_del (& hidinput -> list );
1564
1637
input_free_device (hidinput -> input );
1638
+ kfree (hidinput -> name );
1565
1639
1566
1640
for (k = HID_INPUT_REPORT ; k <= HID_OUTPUT_REPORT ; k ++ ) {
1567
1641
if (k == HID_OUTPUT_REPORT &&
@@ -1594,6 +1668,20 @@ static struct hid_input *hidinput_match(struct hid_report *report)
1594
1668
return NULL ;
1595
1669
}
1596
1670
1671
+ static struct hid_input * hidinput_match_application (struct hid_report * report )
1672
+ {
1673
+ struct hid_device * hid = report -> device ;
1674
+ struct hid_input * hidinput ;
1675
+
1676
+ list_for_each_entry (hidinput , & hid -> inputs , list ) {
1677
+ if (hidinput -> report &&
1678
+ hidinput -> report -> application == report -> application )
1679
+ return hidinput ;
1680
+ }
1681
+
1682
+ return NULL ;
1683
+ }
1684
+
1597
1685
static inline void hidinput_configure_usages (struct hid_input * hidinput ,
1598
1686
struct hid_report * report )
1599
1687
{
@@ -1616,11 +1704,14 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
1616
1704
struct hid_driver * drv = hid -> driver ;
1617
1705
struct hid_report * report ;
1618
1706
struct hid_input * next , * hidinput = NULL ;
1707
+ unsigned int application ;
1619
1708
int i , k ;
1620
1709
1621
1710
INIT_LIST_HEAD (& hid -> inputs );
1622
1711
INIT_WORK (& hid -> led_work , hidinput_led_worker );
1623
1712
1713
+ hid -> status &= ~HID_STAT_DUP_DETECTED ;
1714
+
1624
1715
if (!force ) {
1625
1716
for (i = 0 ; i < hid -> maxcollection ; i ++ ) {
1626
1717
struct hid_collection * col = & hid -> collection [i ];
@@ -1646,15 +1737,20 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
1646
1737
if (!report -> maxfield )
1647
1738
continue ;
1648
1739
1740
+ application = report -> application ;
1741
+
1649
1742
/*
1650
1743
* Find the previous hidinput report attached
1651
1744
* to this report id.
1652
1745
*/
1653
1746
if (hid -> quirks & HID_QUIRK_MULTI_INPUT )
1654
1747
hidinput = hidinput_match (report );
1748
+ else if (hid -> maxapplication > 1 &&
1749
+ (hid -> quirks & HID_QUIRK_INPUT_PER_APP ))
1750
+ hidinput = hidinput_match_application (report );
1655
1751
1656
1752
if (!hidinput ) {
1657
- hidinput = hidinput_allocate (hid );
1753
+ hidinput = hidinput_allocate (hid , application );
1658
1754
if (!hidinput )
1659
1755
goto out_unwind ;
1660
1756
}
@@ -1663,6 +1759,9 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
1663
1759
1664
1760
if (hid -> quirks & HID_QUIRK_MULTI_INPUT )
1665
1761
hidinput -> report = report ;
1762
+
1763
+ list_add_tail (& report -> hidinput_list ,
1764
+ & hidinput -> reports );
1666
1765
}
1667
1766
}
1668
1767
@@ -1687,6 +1786,10 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
1687
1786
goto out_unwind ;
1688
1787
}
1689
1788
1789
+ if (hid -> status & HID_STAT_DUP_DETECTED )
1790
+ hid_dbg (hid ,
1791
+ "Some usages could not be mapped, please use HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE if this is legitimate.\n" );
1792
+
1690
1793
return 0 ;
1691
1794
1692
1795
out_unwind :
0 commit comments