@@ -370,7 +370,7 @@ static void hammer_unregister_leds(struct hid_device *hdev)
370
370
371
371
#define HID_UP_GOOGLEVENDOR 0xffd10000
372
372
#define HID_VD_KBD_FOLDED 0x00000019
373
- #define WHISKERS_KBD_FOLDED (HID_UP_GOOGLEVENDOR | HID_VD_KBD_FOLDED)
373
+ #define HID_USAGE_KBD_FOLDED (HID_UP_GOOGLEVENDOR | HID_VD_KBD_FOLDED)
374
374
375
375
/* HID usage for keyboard backlight (Alphanumeric display brightness) */
376
376
#define HID_AD_BRIGHTNESS 0x00140046
@@ -380,8 +380,7 @@ static int hammer_input_mapping(struct hid_device *hdev, struct hid_input *hi,
380
380
struct hid_usage * usage ,
381
381
unsigned long * * bit , int * max )
382
382
{
383
- if (hdev -> product == USB_DEVICE_ID_GOOGLE_WHISKERS &&
384
- usage -> hid == WHISKERS_KBD_FOLDED ) {
383
+ if (usage -> hid == HID_USAGE_KBD_FOLDED ) {
385
384
/*
386
385
* We do not want to have this usage mapped as it will get
387
386
* mixed in with "base attached" signal and delivered over
@@ -398,8 +397,7 @@ static int hammer_event(struct hid_device *hid, struct hid_field *field,
398
397
{
399
398
unsigned long flags ;
400
399
401
- if (hid -> product == USB_DEVICE_ID_GOOGLE_WHISKERS &&
402
- usage -> hid == WHISKERS_KBD_FOLDED ) {
400
+ if (usage -> hid == HID_USAGE_KBD_FOLDED ) {
403
401
spin_lock_irqsave (& cbas_ec_lock , flags );
404
402
405
403
/*
@@ -424,40 +422,41 @@ static int hammer_event(struct hid_device *hid, struct hid_field *field,
424
422
return 0 ;
425
423
}
426
424
427
- static bool hammer_is_keyboard_interface (struct hid_device * hdev )
425
+ static bool hammer_has_usage (struct hid_device * hdev , unsigned int report_type ,
426
+ unsigned application , unsigned usage )
428
427
{
429
- struct hid_report_enum * re = & hdev -> report_enum [HID_INPUT_REPORT ];
430
- struct hid_report * report ;
431
-
432
- list_for_each_entry (report , & re -> report_list , list )
433
- if (report -> application == HID_GD_KEYBOARD )
434
- return true;
435
-
436
- return false;
437
- }
438
-
439
- static bool hammer_has_backlight_control (struct hid_device * hdev )
440
- {
441
- struct hid_report_enum * re = & hdev -> report_enum [HID_OUTPUT_REPORT ];
428
+ struct hid_report_enum * re = & hdev -> report_enum [report_type ];
442
429
struct hid_report * report ;
443
430
int i , j ;
444
431
445
432
list_for_each_entry (report , & re -> report_list , list ) {
446
- if (report -> application != HID_GD_KEYBOARD )
433
+ if (report -> application != application )
447
434
continue ;
448
435
449
436
for (i = 0 ; i < report -> maxfield ; i ++ ) {
450
437
struct hid_field * field = report -> field [i ];
451
438
452
439
for (j = 0 ; j < field -> maxusage ; j ++ )
453
- if (field -> usage [j ].hid == HID_AD_BRIGHTNESS )
440
+ if (field -> usage [j ].hid == usage )
454
441
return true;
455
442
}
456
443
}
457
444
458
445
return false;
459
446
}
460
447
448
+ static bool hammer_has_folded_event (struct hid_device * hdev )
449
+ {
450
+ return hammer_has_usage (hdev , HID_INPUT_REPORT ,
451
+ HID_GD_KEYBOARD , HID_USAGE_KBD_FOLDED );
452
+ }
453
+
454
+ static bool hammer_has_backlight_control (struct hid_device * hdev )
455
+ {
456
+ return hammer_has_usage (hdev , HID_OUTPUT_REPORT ,
457
+ HID_GD_KEYBOARD , HID_AD_BRIGHTNESS );
458
+ }
459
+
461
460
static int hammer_probe (struct hid_device * hdev ,
462
461
const struct hid_device_id * id )
463
462
{
@@ -473,12 +472,11 @@ static int hammer_probe(struct hid_device *hdev,
473
472
474
473
/*
475
474
* We always want to poll for, and handle tablet mode events from
476
- * Whiskers , even when nobody has opened the input device. This also
477
- * prevents the hid core from dropping early tablet mode events from
478
- * the device.
475
+ * devices that have folded usage , even when nobody has opened the input
476
+ * device. This also prevents the hid core from dropping early tablet
477
+ * mode events from the device.
479
478
*/
480
- if (hdev -> product == USB_DEVICE_ID_GOOGLE_WHISKERS &&
481
- hammer_is_keyboard_interface (hdev )) {
479
+ if (hammer_has_folded_event (hdev )) {
482
480
hdev -> quirks |= HID_QUIRK_ALWAYS_POLL ;
483
481
error = hid_hw_open (hdev );
484
482
if (error )
@@ -500,8 +498,7 @@ static void hammer_remove(struct hid_device *hdev)
500
498
{
501
499
unsigned long flags ;
502
500
503
- if (hdev -> product == USB_DEVICE_ID_GOOGLE_WHISKERS &&
504
- hammer_is_keyboard_interface (hdev )) {
501
+ if (hammer_has_folded_event (hdev )) {
505
502
hid_hw_close (hdev );
506
503
507
504
/*
0 commit comments