@@ -709,6 +709,28 @@ static int lg_g15_register_led(struct lg_g15_data *g15, int i)
709709 return devm_led_classdev_register (& g15 -> hdev -> dev , & g15 -> leds [i ].cdev );
710710}
711711
712+ /* Common input device init code shared between keyboards and Z-10 speaker handling */
713+ static void lg_g15_init_input_dev (struct hid_device * hdev , struct input_dev * input ,
714+ const char * name )
715+ {
716+ int i ;
717+
718+ input -> name = name ;
719+ input -> phys = hdev -> phys ;
720+ input -> uniq = hdev -> uniq ;
721+ input -> id .bustype = hdev -> bus ;
722+ input -> id .vendor = hdev -> vendor ;
723+ input -> id .product = hdev -> product ;
724+ input -> id .version = hdev -> version ;
725+ input -> dev .parent = & hdev -> dev ;
726+ input -> open = lg_g15_input_open ;
727+ input -> close = lg_g15_input_close ;
728+
729+ /* Keys below the LCD, intended for controlling a menu on the LCD */
730+ for (i = 0 ; i < 5 ; i ++ )
731+ input_set_capability (input , EV_KEY , KEY_KBD_LCD_MENU1 + i );
732+ }
733+
712734static int lg_g15_probe (struct hid_device * hdev , const struct hid_device_id * id )
713735{
714736 u8 gkeys_settings_output_report = 0 ;
@@ -751,6 +773,8 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id)
751773
752774 g15 -> hdev = hdev ;
753775 g15 -> model = id -> driver_data ;
776+ g15 -> input = input ;
777+ input_set_drvdata (input , hdev );
754778 hid_set_drvdata (hdev , (void * )g15 );
755779
756780 switch (g15 -> model ) {
@@ -822,16 +846,7 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id)
822846 goto error_hw_stop ;
823847
824848 /* Setup and register input device */
825- input -> name = "Logitech Gaming Keyboard Gaming Keys" ;
826- input -> phys = hdev -> phys ;
827- input -> uniq = hdev -> uniq ;
828- input -> id .bustype = hdev -> bus ;
829- input -> id .vendor = hdev -> vendor ;
830- input -> id .product = hdev -> product ;
831- input -> id .version = hdev -> version ;
832- input -> dev .parent = & hdev -> dev ;
833- input -> open = lg_g15_input_open ;
834- input -> close = lg_g15_input_close ;
849+ lg_g15_init_input_dev (hdev , input , "Logitech Gaming Keyboard Gaming Keys" );
835850
836851 /* G-keys */
837852 for (i = 0 ; i < gkeys ; i ++ )
@@ -842,10 +857,6 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id)
842857 input_set_capability (input , EV_KEY , KEY_MACRO_PRESET1 + i );
843858 input_set_capability (input , EV_KEY , KEY_MACRO_RECORD_START );
844859
845- /* Keys below the LCD, intended for controlling a menu on the LCD */
846- for (i = 0 ; i < 5 ; i ++ )
847- input_set_capability (input , EV_KEY , KEY_KBD_LCD_MENU1 + i );
848-
849860 /*
850861 * On the G510 only report headphone and mic mute keys when *not* using
851862 * the builtin USB audio device. When the builtin audio is used these
@@ -857,9 +868,6 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id)
857868 input_set_capability (input , EV_KEY , KEY_F20 );
858869 }
859870
860- g15 -> input = input ;
861- input_set_drvdata (input , hdev );
862-
863871 ret = input_register_device (input );
864872 if (ret )
865873 goto error_hw_stop ;
0 commit comments