@@ -370,7 +370,7 @@ static void hammer_unregister_leds(struct hid_device *hdev)
370370
371371#define HID_UP_GOOGLEVENDOR 0xffd10000
372372#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)
374374
375375/* HID usage for keyboard backlight (Alphanumeric display brightness) */
376376#define HID_AD_BRIGHTNESS 0x00140046
@@ -380,8 +380,7 @@ static int hammer_input_mapping(struct hid_device *hdev, struct hid_input *hi,
380380 struct hid_usage * usage ,
381381 unsigned long * * bit , int * max )
382382{
383- if (hdev -> product == USB_DEVICE_ID_GOOGLE_WHISKERS &&
384- usage -> hid == WHISKERS_KBD_FOLDED ) {
383+ if (usage -> hid == HID_USAGE_KBD_FOLDED ) {
385384 /*
386385 * We do not want to have this usage mapped as it will get
387386 * 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,
398397{
399398 unsigned long flags ;
400399
401- if (hid -> product == USB_DEVICE_ID_GOOGLE_WHISKERS &&
402- usage -> hid == WHISKERS_KBD_FOLDED ) {
400+ if (usage -> hid == HID_USAGE_KBD_FOLDED ) {
403401 spin_lock_irqsave (& cbas_ec_lock , flags );
404402
405403 /*
@@ -424,40 +422,41 @@ static int hammer_event(struct hid_device *hid, struct hid_field *field,
424422 return 0 ;
425423}
426424
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 )
428427{
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 ];
442429 struct hid_report * report ;
443430 int i , j ;
444431
445432 list_for_each_entry (report , & re -> report_list , list ) {
446- if (report -> application != HID_GD_KEYBOARD )
433+ if (report -> application != application )
447434 continue ;
448435
449436 for (i = 0 ; i < report -> maxfield ; i ++ ) {
450437 struct hid_field * field = report -> field [i ];
451438
452439 for (j = 0 ; j < field -> maxusage ; j ++ )
453- if (field -> usage [j ].hid == HID_AD_BRIGHTNESS )
440+ if (field -> usage [j ].hid == usage )
454441 return true;
455442 }
456443 }
457444
458445 return false;
459446}
460447
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+
461460static int hammer_probe (struct hid_device * hdev ,
462461 const struct hid_device_id * id )
463462{
@@ -473,12 +472,11 @@ static int hammer_probe(struct hid_device *hdev,
473472
474473 /*
475474 * 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.
479478 */
480- if (hdev -> product == USB_DEVICE_ID_GOOGLE_WHISKERS &&
481- hammer_is_keyboard_interface (hdev )) {
479+ if (hammer_has_folded_event (hdev )) {
482480 hdev -> quirks |= HID_QUIRK_ALWAYS_POLL ;
483481 error = hid_hw_open (hdev );
484482 if (error )
@@ -500,8 +498,7 @@ static void hammer_remove(struct hid_device *hdev)
500498{
501499 unsigned long flags ;
502500
503- if (hdev -> product == USB_DEVICE_ID_GOOGLE_WHISKERS &&
504- hammer_is_keyboard_interface (hdev )) {
501+ if (hammer_has_folded_event (hdev )) {
505502 hid_hw_close (hdev );
506503
507504 /*
0 commit comments