Skip to content

Commit 06db2af

Browse files
committed
Merge branch 'for-6.3/hid-core' into for-linus
- constify hid_ll_driver (Thomas Weißschuh) - map standard Battery System Charging to upower (José Expósito) - couple of assorted fixes and new handling of HID usages (Jingyuan Liang & Ronald Tschalär)
2 parents 0b02818 + 3f16ba1 commit 06db2af

File tree

21 files changed

+157
-56
lines changed

21 files changed

+157
-56
lines changed

drivers/hid/.kunitconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CONFIG_KUNIT=y
22
CONFIG_USB=y
33
CONFIG_USB_HID=y
4+
CONFIG_HID_BATTERY_STRENGTH=y
45
CONFIG_HID_UCLOGIC=y
56
CONFIG_HID_KUNIT_TEST=y

drivers/hid/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,7 @@ config HID_MCP2221
12641264
config HID_KUNIT_TEST
12651265
tristate "KUnit tests for HID" if !KUNIT_ALL_TESTS
12661266
depends on KUNIT=y
1267+
depends on HID_BATTERY_STRENGTH
12671268
depends on HID_UCLOGIC
12681269
default KUNIT_ALL_TESTS
12691270
help

drivers/hid/amd-sfh-hid/amd_sfh_hid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void amdtp_hid_wakeup(struct hid_device *hid)
112112
}
113113
}
114114

115-
static struct hid_ll_driver amdtp_hid_ll_driver = {
115+
static const struct hid_ll_driver amdtp_hid_ll_driver = {
116116
.parse = amdtp_hid_parse,
117117
.start = amdtp_hid_start,
118118
.stop = amdtp_hid_stop,

drivers/hid/hid-core.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@
4141

4242
#define DRIVER_DESC "HID core driver"
4343

44-
int hid_debug = 0;
45-
module_param_named(debug, hid_debug, int, 0600);
46-
MODULE_PARM_DESC(debug, "toggle HID debugging messages");
47-
EXPORT_SYMBOL_GPL(hid_debug);
48-
4944
static int hid_ignore_special_drivers = 0;
5045
module_param_named(ignore_special_drivers, hid_ignore_special_drivers, int, 0600);
5146
MODULE_PARM_DESC(ignore_special_drivers, "Ignore any special drivers and handle all devices by generic driver");
@@ -804,7 +799,8 @@ static void hid_scan_collection(struct hid_parser *parser, unsigned type)
804799
int i;
805800

806801
if (((parser->global.usage_page << 16) == HID_UP_SENSOR) &&
807-
type == HID_COLLECTION_PHYSICAL)
802+
(type == HID_COLLECTION_PHYSICAL ||
803+
type == HID_COLLECTION_APPLICATION))
808804
hid->group = HID_GROUP_SENSOR_HUB;
809805

810806
if (hid->vendor == USB_VENDOR_ID_MICROSOFT &&
@@ -2912,10 +2908,6 @@ static int __init hid_init(void)
29122908
{
29132909
int ret;
29142910

2915-
if (hid_debug)
2916-
pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
2917-
"debugfs is now used for inspecting the device (report descriptor, reports)\n");
2918-
29192911
ret = bus_register(&hid_bus_type);
29202912
if (ret) {
29212913
pr_err("can't register hid bus\n");

drivers/hid/hid-debug.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ static const char *keys[KEY_MAX + 1] = {
975975
[KEY_CAMERA_ACCESS_DISABLE] = "CameraAccessDisable",
976976
[KEY_CAMERA_ACCESS_TOGGLE] = "CameraAccessToggle",
977977
[KEY_DICTATE] = "Dictate",
978+
[KEY_MICMUTE] = "MicrophoneMute",
978979
[KEY_BRIGHTNESS_MIN] = "BrightnessMin",
979980
[KEY_BRIGHTNESS_MAX] = "BrightnessMax",
980981
[KEY_BRIGHTNESS_AUTO] = "BrightnessAuto",

drivers/hid/hid-hyperv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ static int mousevsc_hid_raw_request(struct hid_device *hid,
424424
return 0;
425425
}
426426

427-
static struct hid_ll_driver mousevsc_ll_driver = {
427+
static const struct hid_ll_driver mousevsc_ll_driver = {
428428
.parse = mousevsc_hid_parse,
429429
.open = mousevsc_hid_open,
430430
.close = mousevsc_hid_close,

drivers/hid/hid-input-test.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* HID to Linux Input mapping
4+
*
5+
* Copyright (c) 2022 José Expósito <[email protected]>
6+
*/
7+
8+
#include <kunit/test.h>
9+
10+
static void hid_test_input_set_battery_charge_status(struct kunit *test)
11+
{
12+
struct hid_device *dev;
13+
bool handled;
14+
15+
dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL);
16+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
17+
18+
handled = hidinput_set_battery_charge_status(dev, HID_DG_HEIGHT, 0);
19+
KUNIT_EXPECT_FALSE(test, handled);
20+
KUNIT_EXPECT_EQ(test, dev->battery_charge_status, POWER_SUPPLY_STATUS_UNKNOWN);
21+
22+
handled = hidinput_set_battery_charge_status(dev, HID_BAT_CHARGING, 0);
23+
KUNIT_EXPECT_TRUE(test, handled);
24+
KUNIT_EXPECT_EQ(test, dev->battery_charge_status, POWER_SUPPLY_STATUS_DISCHARGING);
25+
26+
handled = hidinput_set_battery_charge_status(dev, HID_BAT_CHARGING, 1);
27+
KUNIT_EXPECT_TRUE(test, handled);
28+
KUNIT_EXPECT_EQ(test, dev->battery_charge_status, POWER_SUPPLY_STATUS_CHARGING);
29+
}
30+
31+
static void hid_test_input_get_battery_property(struct kunit *test)
32+
{
33+
struct power_supply *psy;
34+
struct hid_device *dev;
35+
union power_supply_propval val;
36+
int ret;
37+
38+
dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL);
39+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
40+
dev->battery_avoid_query = true;
41+
42+
psy = kunit_kzalloc(test, sizeof(*psy), GFP_KERNEL);
43+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, psy);
44+
psy->drv_data = dev;
45+
46+
dev->battery_status = HID_BATTERY_UNKNOWN;
47+
dev->battery_charge_status = POWER_SUPPLY_STATUS_CHARGING;
48+
ret = hidinput_get_battery_property(psy, POWER_SUPPLY_PROP_STATUS, &val);
49+
KUNIT_EXPECT_EQ(test, ret, 0);
50+
KUNIT_EXPECT_EQ(test, val.intval, POWER_SUPPLY_STATUS_UNKNOWN);
51+
52+
dev->battery_status = HID_BATTERY_REPORTED;
53+
dev->battery_charge_status = POWER_SUPPLY_STATUS_CHARGING;
54+
ret = hidinput_get_battery_property(psy, POWER_SUPPLY_PROP_STATUS, &val);
55+
KUNIT_EXPECT_EQ(test, ret, 0);
56+
KUNIT_EXPECT_EQ(test, val.intval, POWER_SUPPLY_STATUS_CHARGING);
57+
58+
dev->battery_status = HID_BATTERY_REPORTED;
59+
dev->battery_charge_status = POWER_SUPPLY_STATUS_DISCHARGING;
60+
ret = hidinput_get_battery_property(psy, POWER_SUPPLY_PROP_STATUS, &val);
61+
KUNIT_EXPECT_EQ(test, ret, 0);
62+
KUNIT_EXPECT_EQ(test, val.intval, POWER_SUPPLY_STATUS_DISCHARGING);
63+
}
64+
65+
static struct kunit_case hid_input_tests[] = {
66+
KUNIT_CASE(hid_test_input_set_battery_charge_status),
67+
KUNIT_CASE(hid_test_input_get_battery_property),
68+
{ }
69+
};
70+
71+
static struct kunit_suite hid_input_test_suite = {
72+
.name = "hid_input",
73+
.test_cases = hid_input_tests,
74+
};
75+
76+
kunit_test_suite(hid_input_test_suite);
77+
78+
MODULE_DESCRIPTION("HID input KUnit tests");
79+
MODULE_LICENSE("GPL");
80+
MODULE_AUTHOR("José Expósito <[email protected]>");

drivers/hid/hid-input.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static int hidinput_get_battery_property(struct power_supply *psy,
486486
if (dev->battery_status == HID_BATTERY_UNKNOWN)
487487
val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
488488
else
489-
val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
489+
val->intval = dev->battery_charge_status;
490490
break;
491491

492492
case POWER_SUPPLY_PROP_SCOPE:
@@ -554,6 +554,7 @@ static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
554554
dev->battery_max = max;
555555
dev->battery_report_type = report_type;
556556
dev->battery_report_id = field->report->id;
557+
dev->battery_charge_status = POWER_SUPPLY_STATUS_DISCHARGING;
557558

558559
/*
559560
* Stylus is normally not connected to the device and thus we
@@ -620,6 +621,20 @@ static void hidinput_update_battery(struct hid_device *dev, int value)
620621
power_supply_changed(dev->battery);
621622
}
622623
}
624+
625+
static bool hidinput_set_battery_charge_status(struct hid_device *dev,
626+
unsigned int usage, int value)
627+
{
628+
switch (usage) {
629+
case HID_BAT_CHARGING:
630+
dev->battery_charge_status = value ?
631+
POWER_SUPPLY_STATUS_CHARGING :
632+
POWER_SUPPLY_STATUS_DISCHARGING;
633+
return true;
634+
}
635+
636+
return false;
637+
}
623638
#else /* !CONFIG_HID_BATTERY_STRENGTH */
624639
static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
625640
struct hid_field *field, bool is_percentage)
@@ -634,6 +649,12 @@ static void hidinput_cleanup_battery(struct hid_device *dev)
634649
static void hidinput_update_battery(struct hid_device *dev, int value)
635650
{
636651
}
652+
653+
static bool hidinput_set_battery_charge_status(struct hid_device *dev,
654+
unsigned int usage, int value)
655+
{
656+
return false;
657+
}
637658
#endif /* CONFIG_HID_BATTERY_STRENGTH */
638659

639660
static bool hidinput_field_in_collection(struct hid_device *device, struct hid_field *field,
@@ -793,6 +814,14 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
793814
break;
794815
}
795816

817+
if ((usage->hid & 0xf0) == 0xa0) { /* SystemControl */
818+
switch (usage->hid & 0xf) {
819+
case 0x9: map_key_clear(KEY_MICMUTE); break;
820+
default: goto ignore;
821+
}
822+
break;
823+
}
824+
796825
if ((usage->hid & 0xf0) == 0xb0) { /* SC - Display */
797826
switch (usage->hid & 0xf) {
798827
case 0x05: map_key_clear(KEY_SWITCHVIDEOMODE); break;
@@ -1223,6 +1252,9 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
12231252
hidinput_setup_battery(device, HID_INPUT_REPORT, field, true);
12241253
usage->type = EV_PWR;
12251254
return;
1255+
case HID_BAT_CHARGING:
1256+
usage->type = EV_PWR;
1257+
return;
12261258
}
12271259
goto unknown;
12281260

@@ -1465,7 +1497,11 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
14651497
return;
14661498

14671499
if (usage->type == EV_PWR) {
1468-
hidinput_update_battery(hid, value);
1500+
bool handled = hidinput_set_battery_charge_status(hid, usage->hid, value);
1501+
1502+
if (!handled)
1503+
hidinput_update_battery(hid, value);
1504+
14691505
return;
14701506
}
14711507

@@ -2321,3 +2357,7 @@ void hidinput_disconnect(struct hid_device *hid)
23212357
cancel_work_sync(&hid->led_work);
23222358
}
23232359
EXPORT_SYMBOL_GPL(hidinput_disconnect);
2360+
2361+
#ifdef CONFIG_HID_KUNIT_TEST
2362+
#include "hid-input-test.c"
2363+
#endif

drivers/hid/hid-letsketch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static int letsketch_probe(struct hid_device *hdev, const struct hid_device_id *
238238
char buf[256];
239239
int i, ret;
240240

241-
if (!hid_is_using_ll_driver(hdev, &usb_hid_driver))
241+
if (!hid_is_usb(hdev))
242242
return -ENODEV;
243243

244244
intf = to_usb_interface(hdev->dev.parent);

drivers/hid/hid-logitech-dj.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ static const u8 hid_reportid_size_map[NUMBER_OF_HID_REPORTS] = {
554554

555555
#define LOGITECH_DJ_INTERFACE_NUMBER 0x02
556556

557-
static struct hid_ll_driver logi_dj_ll_driver;
557+
static const struct hid_ll_driver logi_dj_ll_driver;
558558

559559
static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev);
560560
static void delayedwork_callback(struct work_struct *work);
@@ -1506,7 +1506,7 @@ static bool logi_dj_ll_may_wakeup(struct hid_device *hid)
15061506
return hid_hw_may_wakeup(djrcv_dev->hidpp);
15071507
}
15081508

1509-
static struct hid_ll_driver logi_dj_ll_driver = {
1509+
static const struct hid_ll_driver logi_dj_ll_driver = {
15101510
.parse = logi_dj_ll_parse,
15111511
.start = logi_dj_ll_start,
15121512
.stop = logi_dj_ll_stop,

0 commit comments

Comments
 (0)