Skip to content

Commit 4d18905

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
Pull HID updates from Jiri Kosina: - suspend/resume handling fix for Raydium I2C-connected touchscreen from Aaron Ma - protocol fixup for certain BT-connected Wacoms from Aaron Armstrong Skomra - battery level reporting fix on BT-connected mice from Dmitry Torokhov - hidraw race condition fix from Rodrigo Rivas Costa * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid: HID: i2c-hid: fix inverted return value from i2c_hid_command() HID: i2c-hid: Fix resume issue on Raydium touchscreen device HID: wacom: bluetooth: send exit report for recent Bluetooth devices HID: hidraw: Fix crash on HIDIOCGFEATURE with a destroyed device HID: input: fix battery level reporting on BT mice
2 parents 41e3bef + b658912 commit 4d18905

6 files changed

Lines changed: 92 additions & 38 deletions

File tree

‎drivers/hid/hid-ids.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@
525525
#define I2C_VENDOR_ID_HANTICK 0x0911
526526
#define I2C_PRODUCT_ID_HANTICK_5288 0x5288
527527

528+
#define I2C_VENDOR_ID_RAYD 0x2386
529+
#define I2C_PRODUCT_ID_RAYD_3118 0x3118
530+
528531
#define USB_VENDOR_ID_HANWANG 0x0b57
529532
#define USB_DEVICE_ID_HANWANG_TABLET_FIRST 0x5000
530533
#define USB_DEVICE_ID_HANWANG_TABLET_LAST 0x8fff

‎drivers/hid/hid-input.c‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ static int hidinput_get_battery_property(struct power_supply *psy,
387387
break;
388388

389389
case POWER_SUPPLY_PROP_CAPACITY:
390-
if (dev->battery_report_type == HID_FEATURE_REPORT) {
390+
if (dev->battery_status != HID_BATTERY_REPORTED &&
391+
!dev->battery_avoid_query) {
391392
value = hidinput_query_battery_capacity(dev);
392393
if (value < 0)
393394
return value;
@@ -403,17 +404,17 @@ static int hidinput_get_battery_property(struct power_supply *psy,
403404
break;
404405

405406
case POWER_SUPPLY_PROP_STATUS:
406-
if (!dev->battery_reported &&
407-
dev->battery_report_type == HID_FEATURE_REPORT) {
407+
if (dev->battery_status != HID_BATTERY_REPORTED &&
408+
!dev->battery_avoid_query) {
408409
value = hidinput_query_battery_capacity(dev);
409410
if (value < 0)
410411
return value;
411412

412413
dev->battery_capacity = value;
413-
dev->battery_reported = true;
414+
dev->battery_status = HID_BATTERY_QUERIED;
414415
}
415416

416-
if (!dev->battery_reported)
417+
if (dev->battery_status == HID_BATTERY_UNKNOWN)
417418
val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
418419
else if (dev->battery_capacity == 100)
419420
val->intval = POWER_SUPPLY_STATUS_FULL;
@@ -486,6 +487,14 @@ static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
486487
dev->battery_report_type = report_type;
487488
dev->battery_report_id = field->report->id;
488489

490+
/*
491+
* Stylus is normally not connected to the device and thus we
492+
* can't query the device and get meaningful battery strength.
493+
* We have to wait for the device to report it on its own.
494+
*/
495+
dev->battery_avoid_query = report_type == HID_INPUT_REPORT &&
496+
field->physical == HID_DG_STYLUS;
497+
489498
dev->battery = power_supply_register(&dev->dev, psy_desc, &psy_cfg);
490499
if (IS_ERR(dev->battery)) {
491500
error = PTR_ERR(dev->battery);
@@ -530,9 +539,10 @@ static void hidinput_update_battery(struct hid_device *dev, int value)
530539

531540
capacity = hidinput_scale_battery_capacity(dev, value);
532541

533-
if (!dev->battery_reported || capacity != dev->battery_capacity) {
542+
if (dev->battery_status != HID_BATTERY_REPORTED ||
543+
capacity != dev->battery_capacity) {
534544
dev->battery_capacity = capacity;
535-
dev->battery_reported = true;
545+
dev->battery_status = HID_BATTERY_REPORTED;
536546
power_supply_changed(dev->battery);
537547
}
538548
}

‎drivers/hid/hidraw.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ static ssize_t hidraw_get_report(struct file *file, char __user *buffer, size_t
192192
int ret = 0, len;
193193
unsigned char report_number;
194194

195+
if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
196+
ret = -ENODEV;
197+
goto out;
198+
}
199+
195200
dev = hidraw_table[minor]->hid;
196201

197202
if (!dev->ll_driver->raw_request) {

‎drivers/hid/i2c-hid/i2c-hid.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
/* quirks to control the device */
4848
#define I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV BIT(0)
4949
#define I2C_HID_QUIRK_NO_IRQ_AFTER_RESET BIT(1)
50+
#define I2C_HID_QUIRK_RESEND_REPORT_DESCR BIT(2)
5051

5152
/* flags */
5253
#define I2C_HID_STARTED 0
@@ -171,6 +172,8 @@ static const struct i2c_hid_quirks {
171172
I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV },
172173
{ I2C_VENDOR_ID_HANTICK, I2C_PRODUCT_ID_HANTICK_5288,
173174
I2C_HID_QUIRK_NO_IRQ_AFTER_RESET },
175+
{ I2C_VENDOR_ID_RAYD, I2C_PRODUCT_ID_RAYD_3118,
176+
I2C_HID_QUIRK_RESEND_REPORT_DESCR },
174177
{ 0, 0 }
175178
};
176179

@@ -1220,6 +1223,16 @@ static int i2c_hid_resume(struct device *dev)
12201223
if (ret)
12211224
return ret;
12221225

1226+
/* RAYDIUM device (2386:3118) need to re-send report descr cmd
1227+
* after resume, after this it will be back normal.
1228+
* otherwise it issues too many incomplete reports.
1229+
*/
1230+
if (ihid->quirks & I2C_HID_QUIRK_RESEND_REPORT_DESCR) {
1231+
ret = i2c_hid_command(client, &hid_report_descr_cmd, NULL, 0);
1232+
if (ret)
1233+
return ret;
1234+
}
1235+
12231236
if (hid->driver && hid->driver->reset_resume) {
12241237
ret = hid->driver->reset_resume(hid);
12251238
return ret;

‎drivers/hid/wacom_wac.c‎

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,45 @@ static int wacom_intuos_get_tool_type(int tool_id)
689689
return tool_type;
690690
}
691691

692+
static void wacom_exit_report(struct wacom_wac *wacom)
693+
{
694+
struct input_dev *input = wacom->pen_input;
695+
struct wacom_features *features = &wacom->features;
696+
unsigned char *data = wacom->data;
697+
int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
698+
699+
/*
700+
* Reset all states otherwise we lose the initial states
701+
* when in-prox next time
702+
*/
703+
input_report_abs(input, ABS_X, 0);
704+
input_report_abs(input, ABS_Y, 0);
705+
input_report_abs(input, ABS_DISTANCE, 0);
706+
input_report_abs(input, ABS_TILT_X, 0);
707+
input_report_abs(input, ABS_TILT_Y, 0);
708+
if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
709+
input_report_key(input, BTN_LEFT, 0);
710+
input_report_key(input, BTN_MIDDLE, 0);
711+
input_report_key(input, BTN_RIGHT, 0);
712+
input_report_key(input, BTN_SIDE, 0);
713+
input_report_key(input, BTN_EXTRA, 0);
714+
input_report_abs(input, ABS_THROTTLE, 0);
715+
input_report_abs(input, ABS_RZ, 0);
716+
} else {
717+
input_report_abs(input, ABS_PRESSURE, 0);
718+
input_report_key(input, BTN_STYLUS, 0);
719+
input_report_key(input, BTN_STYLUS2, 0);
720+
input_report_key(input, BTN_TOUCH, 0);
721+
input_report_abs(input, ABS_WHEEL, 0);
722+
if (features->type >= INTUOS3S)
723+
input_report_abs(input, ABS_Z, 0);
724+
}
725+
input_report_key(input, wacom->tool[idx], 0);
726+
input_report_abs(input, ABS_MISC, 0); /* reset tool id */
727+
input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
728+
wacom->id[idx] = 0;
729+
}
730+
692731
static int wacom_intuos_inout(struct wacom_wac *wacom)
693732
{
694733
struct wacom_features *features = &wacom->features;
@@ -741,36 +780,7 @@ static int wacom_intuos_inout(struct wacom_wac *wacom)
741780
if (!wacom->id[idx])
742781
return 1;
743782

744-
/*
745-
* Reset all states otherwise we lose the initial states
746-
* when in-prox next time
747-
*/
748-
input_report_abs(input, ABS_X, 0);
749-
input_report_abs(input, ABS_Y, 0);
750-
input_report_abs(input, ABS_DISTANCE, 0);
751-
input_report_abs(input, ABS_TILT_X, 0);
752-
input_report_abs(input, ABS_TILT_Y, 0);
753-
if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
754-
input_report_key(input, BTN_LEFT, 0);
755-
input_report_key(input, BTN_MIDDLE, 0);
756-
input_report_key(input, BTN_RIGHT, 0);
757-
input_report_key(input, BTN_SIDE, 0);
758-
input_report_key(input, BTN_EXTRA, 0);
759-
input_report_abs(input, ABS_THROTTLE, 0);
760-
input_report_abs(input, ABS_RZ, 0);
761-
} else {
762-
input_report_abs(input, ABS_PRESSURE, 0);
763-
input_report_key(input, BTN_STYLUS, 0);
764-
input_report_key(input, BTN_STYLUS2, 0);
765-
input_report_key(input, BTN_TOUCH, 0);
766-
input_report_abs(input, ABS_WHEEL, 0);
767-
if (features->type >= INTUOS3S)
768-
input_report_abs(input, ABS_Z, 0);
769-
}
770-
input_report_key(input, wacom->tool[idx], 0);
771-
input_report_abs(input, ABS_MISC, 0); /* reset tool id */
772-
input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
773-
wacom->id[idx] = 0;
783+
wacom_exit_report(wacom);
774784
return 2;
775785
}
776786

@@ -1235,6 +1245,12 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
12351245
if (!valid)
12361246
continue;
12371247

1248+
if (!prox) {
1249+
wacom->shared->stylus_in_proximity = false;
1250+
wacom_exit_report(wacom);
1251+
input_sync(pen_input);
1252+
return;
1253+
}
12381254
if (range) {
12391255
input_report_abs(pen_input, ABS_X, get_unaligned_le16(&frame[1]));
12401256
input_report_abs(pen_input, ABS_Y, get_unaligned_le16(&frame[3]));

‎include/linux/hid.h‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,12 @@ enum hid_type {
516516
HID_TYPE_USBNONE
517517
};
518518

519+
enum hid_battery_status {
520+
HID_BATTERY_UNKNOWN = 0,
521+
HID_BATTERY_QUERIED, /* Kernel explicitly queried battery strength */
522+
HID_BATTERY_REPORTED, /* Device sent unsolicited battery strength report */
523+
};
524+
519525
struct hid_driver;
520526
struct hid_ll_driver;
521527

@@ -558,7 +564,8 @@ struct hid_device { /* device report descriptor */
558564
__s32 battery_max;
559565
__s32 battery_report_type;
560566
__s32 battery_report_id;
561-
bool battery_reported;
567+
enum hid_battery_status battery_status;
568+
bool battery_avoid_query;
562569
#endif
563570

564571
unsigned int status; /* see STAT flags above */

0 commit comments

Comments
 (0)