44
44
#include "i2c-hid.h"
45
45
46
46
/* quirks to control the device */
47
- #define I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV BIT(0)
48
- #define I2C_HID_QUIRK_NO_IRQ_AFTER_RESET BIT(1)
49
- #define I2C_HID_QUIRK_BOGUS_IRQ BIT(4)
50
- #define I2C_HID_QUIRK_RESET_ON_RESUME BIT(5)
51
- #define I2C_HID_QUIRK_BAD_INPUT_SIZE BIT(6)
52
- #define I2C_HID_QUIRK_NO_WAKEUP_AFTER_RESET BIT(7)
47
+ #define I2C_HID_QUIRK_NO_IRQ_AFTER_RESET BIT(0)
48
+ #define I2C_HID_QUIRK_BOGUS_IRQ BIT(1)
49
+ #define I2C_HID_QUIRK_RESET_ON_RESUME BIT(2)
50
+ #define I2C_HID_QUIRK_BAD_INPUT_SIZE BIT(3)
51
+ #define I2C_HID_QUIRK_NO_WAKEUP_AFTER_RESET BIT(4)
53
52
54
53
/* Command opcodes */
55
54
#define I2C_HID_OPCODE_RESET 0x01
@@ -120,8 +119,6 @@ static const struct i2c_hid_quirks {
120
119
__u16 idProduct ;
121
120
__u32 quirks ;
122
121
} i2c_hid_quirks [] = {
123
- { USB_VENDOR_ID_WEIDA , HID_ANY_ID ,
124
- I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV },
125
122
{ I2C_VENDOR_ID_HANTICK , I2C_PRODUCT_ID_HANTICK_5288 ,
126
123
I2C_HID_QUIRK_NO_IRQ_AFTER_RESET },
127
124
{ I2C_VENDOR_ID_ITE , I2C_DEVICE_ID_ITE_VOYO_WINPAD_A15 ,
@@ -395,8 +392,7 @@ static int i2c_hid_set_power(struct i2c_hid *ihid, int power_state)
395
392
* The call will get a return value (EREMOTEIO) but device will be
396
393
* triggered and activated. After that, it goes like a normal device.
397
394
*/
398
- if (power_state == I2C_HID_PWR_ON &&
399
- ihid -> quirks & I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV ) {
395
+ if (power_state == I2C_HID_PWR_ON ) {
400
396
ret = i2c_hid_set_power_command (ihid , I2C_HID_PWR_ON );
401
397
402
398
/* Device was already activated */
@@ -426,12 +422,23 @@ static int i2c_hid_set_power(struct i2c_hid *ihid, int power_state)
426
422
return ret ;
427
423
}
428
424
429
- static int i2c_hid_execute_reset (struct i2c_hid * ihid )
425
+ static int i2c_hid_start_hwreset (struct i2c_hid * ihid )
430
426
{
431
427
size_t length = 0 ;
432
428
int ret ;
433
429
434
- i2c_hid_dbg (ihid , "resetting...\n" );
430
+ i2c_hid_dbg (ihid , "%s\n" , __func__ );
431
+
432
+ /*
433
+ * This prevents sending feature reports while the device is
434
+ * being reset. Otherwise we may lose the reset complete
435
+ * interrupt.
436
+ */
437
+ lockdep_assert_held (& ihid -> reset_lock );
438
+
439
+ ret = i2c_hid_set_power (ihid , I2C_HID_PWR_ON );
440
+ if (ret )
441
+ return ret ;
435
442
436
443
/* Prepare reset command. Command register goes first. */
437
444
* (__le16 * )ihid -> cmdbuf = ihid -> hdesc .wCommandRegister ;
@@ -444,60 +451,40 @@ static int i2c_hid_execute_reset(struct i2c_hid *ihid)
444
451
445
452
ret = i2c_hid_xfer (ihid , ihid -> cmdbuf , length , NULL , 0 );
446
453
if (ret ) {
447
- dev_err (& ihid -> client -> dev , "failed to reset device.\n" );
448
- goto out ;
449
- }
450
-
451
- if (ihid -> quirks & I2C_HID_QUIRK_NO_IRQ_AFTER_RESET ) {
452
- msleep (100 );
453
- goto out ;
454
+ dev_err (& ihid -> client -> dev ,
455
+ "failed to reset device: %d\n" , ret );
456
+ goto err_clear_reset ;
454
457
}
455
458
456
- i2c_hid_dbg (ihid , "%s: waiting...\n" , __func__ );
457
- if (!wait_event_timeout (ihid -> wait ,
458
- !test_bit (I2C_HID_RESET_PENDING , & ihid -> flags ),
459
- msecs_to_jiffies (5000 ))) {
460
- ret = - ENODATA ;
461
- goto out ;
462
- }
463
- i2c_hid_dbg (ihid , "%s: finished.\n" , __func__ );
459
+ return 0 ;
464
460
465
- out :
461
+ err_clear_reset :
466
462
clear_bit (I2C_HID_RESET_PENDING , & ihid -> flags );
463
+ i2c_hid_set_power (ihid , I2C_HID_PWR_SLEEP );
467
464
return ret ;
468
465
}
469
466
470
- static int i2c_hid_hwreset (struct i2c_hid * ihid )
467
+ static int i2c_hid_finish_hwreset (struct i2c_hid * ihid )
471
468
{
472
- int ret ;
469
+ int ret = 0 ;
473
470
474
- i2c_hid_dbg (ihid , "%s\n" , __func__ );
475
-
476
- /*
477
- * This prevents sending feature reports while the device is
478
- * being reset. Otherwise we may lose the reset complete
479
- * interrupt.
480
- */
481
- mutex_lock (& ihid -> reset_lock );
482
-
483
- ret = i2c_hid_set_power (ihid , I2C_HID_PWR_ON );
484
- if (ret )
485
- goto out_unlock ;
471
+ i2c_hid_dbg (ihid , "%s: waiting...\n" , __func__ );
486
472
487
- ret = i2c_hid_execute_reset (ihid );
488
- if (ret ) {
489
- dev_err (& ihid -> client -> dev ,
490
- "failed to reset device: %d\n" , ret );
491
- i2c_hid_set_power (ihid , I2C_HID_PWR_SLEEP );
492
- goto out_unlock ;
473
+ if (ihid -> quirks & I2C_HID_QUIRK_NO_IRQ_AFTER_RESET ) {
474
+ msleep (100 );
475
+ clear_bit (I2C_HID_RESET_PENDING , & ihid -> flags );
476
+ } else if (!wait_event_timeout (ihid -> wait ,
477
+ !test_bit (I2C_HID_RESET_PENDING , & ihid -> flags ),
478
+ msecs_to_jiffies (1000 ))) {
479
+ dev_warn (& ihid -> client -> dev , "device did not ack reset within 1000 ms\n" );
480
+ clear_bit (I2C_HID_RESET_PENDING , & ihid -> flags );
493
481
}
482
+ i2c_hid_dbg (ihid , "%s: finished.\n" , __func__ );
494
483
495
484
/* At least some SIS devices need this after reset */
496
485
if (!(ihid -> quirks & I2C_HID_QUIRK_NO_WAKEUP_AFTER_RESET ))
497
486
ret = i2c_hid_set_power (ihid , I2C_HID_PWR_ON );
498
487
499
- out_unlock :
500
- mutex_unlock (& ihid -> reset_lock );
501
488
return ret ;
502
489
}
503
490
@@ -729,11 +716,10 @@ static int i2c_hid_parse(struct hid_device *hid)
729
716
struct i2c_client * client = hid -> driver_data ;
730
717
struct i2c_hid * ihid = i2c_get_clientdata (client );
731
718
struct i2c_hid_desc * hdesc = & ihid -> hdesc ;
719
+ char * rdesc = NULL , * use_override = NULL ;
732
720
unsigned int rsize ;
733
- char * rdesc ;
734
721
int ret ;
735
722
int tries = 3 ;
736
- char * use_override ;
737
723
738
724
i2c_hid_dbg (ihid , "entering %s\n" , __func__ );
739
725
@@ -743,14 +729,15 @@ static int i2c_hid_parse(struct hid_device *hid)
743
729
return - EINVAL ;
744
730
}
745
731
732
+ mutex_lock (& ihid -> reset_lock );
746
733
do {
747
- ret = i2c_hid_hwreset (ihid );
734
+ ret = i2c_hid_start_hwreset (ihid );
748
735
if (ret )
749
736
msleep (1000 );
750
737
} while (tries -- > 0 && ret );
751
738
752
739
if (ret )
753
- return ret ;
740
+ goto abort_reset ;
754
741
755
742
use_override = i2c_hid_get_dmi_hid_report_desc_override (client -> name ,
756
743
& rsize );
@@ -762,8 +749,8 @@ static int i2c_hid_parse(struct hid_device *hid)
762
749
rdesc = kzalloc (rsize , GFP_KERNEL );
763
750
764
751
if (!rdesc ) {
765
- dbg_hid ( "couldn't allocate rdesc memory\n" ) ;
766
- return - ENOMEM ;
752
+ ret = - ENOMEM ;
753
+ goto abort_reset ;
767
754
}
768
755
769
756
i2c_hid_dbg (ihid , "asking HID report descriptor\n" );
@@ -773,23 +760,34 @@ static int i2c_hid_parse(struct hid_device *hid)
773
760
rdesc , rsize );
774
761
if (ret ) {
775
762
hid_err (hid , "reading report descriptor failed\n" );
776
- kfree (rdesc );
777
- return - EIO ;
763
+ goto abort_reset ;
778
764
}
779
765
}
780
766
767
+ /*
768
+ * Windows directly reads the report-descriptor after sending reset
769
+ * and then waits for resets completion afterwards. Some touchpads
770
+ * actually wait for the report-descriptor to be read before signalling
771
+ * reset completion.
772
+ */
773
+ ret = i2c_hid_finish_hwreset (ihid );
774
+ abort_reset :
775
+ clear_bit (I2C_HID_RESET_PENDING , & ihid -> flags );
776
+ mutex_unlock (& ihid -> reset_lock );
777
+ if (ret )
778
+ goto out ;
779
+
781
780
i2c_hid_dbg (ihid , "Report Descriptor: %*ph\n" , rsize , rdesc );
782
781
783
782
ret = hid_parse_report (hid , rdesc , rsize );
783
+ if (ret )
784
+ dbg_hid ("parsing report descriptor failed\n" );
785
+
786
+ out :
784
787
if (!use_override )
785
788
kfree (rdesc );
786
789
787
- if (ret ) {
788
- dbg_hid ("parsing report descriptor failed\n" );
789
- return ret ;
790
- }
791
-
792
- return 0 ;
790
+ return ret ;
793
791
}
794
792
795
793
static int i2c_hid_start (struct hid_device * hid )
@@ -987,10 +985,15 @@ static int i2c_hid_core_resume(struct i2c_hid *ihid)
987
985
* However some ALPS touchpads generate IRQ storm without reset, so
988
986
* let's still reset them here.
989
987
*/
990
- if (ihid -> quirks & I2C_HID_QUIRK_RESET_ON_RESUME )
991
- ret = i2c_hid_hwreset (ihid );
992
- else
988
+ if (ihid -> quirks & I2C_HID_QUIRK_RESET_ON_RESUME ) {
989
+ mutex_lock (& ihid -> reset_lock );
990
+ ret = i2c_hid_start_hwreset (ihid );
991
+ if (ret == 0 )
992
+ ret = i2c_hid_finish_hwreset (ihid );
993
+ mutex_unlock (& ihid -> reset_lock );
994
+ } else {
993
995
ret = i2c_hid_set_power (ihid , I2C_HID_PWR_ON );
996
+ }
994
997
995
998
if (ret )
996
999
return ret ;
0 commit comments