HID: lg-g15: Add support for the Logitech Z-10 speakers
Subsystems (2)
cover HID: lg-g15: Add support for the Logitech Z-10 speakers
Hi All,
Here is a patch series adding support for the LCD menu keys + LCD brightness control on the Logitech Z-10 speakers (with LCD) which use the same protocol as the G15 keyboards.
The first patch is an unrelated cleanup, patches 2-4 move some code into helper functions to allow re-use in the Z-10 case, patch 5 adds the actual Z-10 support and patch 6 is a bonus patch adding missing MODULE_AUTHOR tags to 2 HID drivers which I maintain.
Regards,
Hans
Hans de Goede (6):
HID: lg-g15: Remove unused size argument from lg_*_event() functions
HID: lg-g15: Add a lg_g15_handle_lcd_menu_keys() helper function
HID: lg-g15: Add a lg_g15_init_input_dev() helper function
HID: lg-g15: Make the LED-name used by lg_g15_register_led() a
parameter
HID: lg-g15: Add support for the Logitech Z-10 speakers
HID: lg-g15 + ite: Add MODULE_AUTHOR
drivers/hid/hid-ids.h | 1 + drivers/hid/hid-lg-g15.c | 140 ++++++++++++++++++++++++++------------- 2 files changed, 96 insertions(+), 45 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/6 HID: lg-g15: Remove unused size argument from lg_*_event() functions
The report-size is already checked in lg_g15_raw_event() before calling the lg_*_event() functions and these functions don't use the passed in size at all, drop the unused parameter.
--- drivers/hid/hid-lg-g15.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/hid/hid-lg-g15.c +8 -8
@@ -464,7 +464,7 @@ static int lg_g15_get_initial_led_brightness(struct lg_g15_data *g15)/******** Input functions ********/ /* On the G15 Mark I Logitech has been quite creative with which bit is what */ -static int lg_g15_event (struct lg_g15_data *g15,u8 *data,int size) +static int lg_g15_event (struct lg_g15_data *g15,u8 *data) {int i, val;
@@ -510,7 +510,7 @@ static int lg_g15_event(struct lg_g15_data *g15, u8 *data, int size)return 0 ; } -static int lg_g15_v2_event (struct lg_g15_data *g15,u8 *data,int size) +static int lg_g15_v2_event (struct lg_g15_data *g15,u8 *data) {int i, val;
@@ -542,7 +542,7 @@ static int lg_g15_v2_event(struct lg_g15_data *g15, u8 *data, int size)return 0 ; } -static int lg_g510_event (struct lg_g15_data *g15,u8 *data,int size) +static int lg_g510_event (struct lg_g15_data *g15,u8 *data) {bool game_mode_enabled;int i, val;
@@ -586,7 +586,7 @@ static int lg_g510_event(struct lg_g15_data *g15, u8 *data, int size)return 0 ; } -static int lg_g510_leds_event (struct lg_g15_data *g15,u8 *data,int size) +static int lg_g510_leds_event (struct lg_g15_data *g15,u8 *data) {bool backlight_disabled;
@@ -613,18 +613,18 @@ static int lg_g15_raw_event(struct hid_device *hdev, struct hid_report *report,switch (g15->model) {case LG_G15 :if (data[0 ] ==0x02 && size ==9 ) -return lg_g15_event (g15, data, size); +return lg_g15_event (g15, data);break ;case LG_G15_V2 :if (data[0 ] ==0x02 && size ==5 ) -return lg_g15_v2_event (g15, data, size); +return lg_g15_v2_event (g15, data);break ;case LG_G510 :case LG_G510_USB_AUDIO :if (data[0 ] ==0x03 && size ==5 ) -return lg_g510_event (g15, data, size); +return lg_g510_event (g15, data);if (data[0 ] ==0x04 && size ==2 ) -return lg_g510_leds_event (g15, data, size); +return lg_g510_leds_event (g15, data);break ; }
Signature · 1 line
2.31.1
PATCH 2/6 HID: lg-g15: Add a lg_g15_handle_lcd_menu_keys() helper function
In reply to Hans de GoedeFactor out the handling of the G15 LCD menu keys out of lg_g15_event() into a new lg_g15_handle_lcd_menu_keys() helper function.
This is a preparation patch for adding support for the LCD menu keys on the Logitech Z-10 speakers (with LCD) which use the same funky HID report format.
--- drivers/hid/hid-lg-g15.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/hid/hid-lg-g15.c +14 -7
@@ -464,6 +464,19 @@ static int lg_g15_get_initial_led_brightness(struct lg_g15_data *g15)/******** Input functions ********/ /* On the G15 Mark I Logitech has been quite creative with which bit is what */ +static void lg_g15_handle_lcd_menu_keys (struct lg_g15_data *g15,u8 *data) +{ +int i, val; + +/* Most left (round/display) button below the LCD */ +input_report_key (g15->input,KEY_KBD_LCD_MENU1 , data[8 ] &0x80 ); +/* 4 other buttons below the LCD */ +for (i =0 ; i <4 ; i++) { + val = data[i +2 ] &0x80 ; +input_report_key (g15->input,KEY_KBD_LCD_MENU2 + i, val); + } +} +static int lg_g15_event (struct lg_g15_data *g15,u8 *data) {int i, val;
@@ -494,13 +507,7 @@ static int lg_g15_event(struct lg_g15_data *g15, u8 *data)/* MR */ input_report_key (g15->input,KEY_MACRO_RECORD_START , data[7 ] &0x40 ); -/* Most left (round) button below the LCD */ -input_report_key (g15->input,KEY_KBD_LCD_MENU1 , data[8 ] &0x80 ); -/* 4 other buttons below the LCD */ -for (i =0 ; i <4 ; i++) { - val = data[i +2 ] &0x80 ; -input_report_key (g15->input,KEY_KBD_LCD_MENU2 + i, val); - } +lg_g15_handle_lcd_menu_keys (g15, data);/* Backlight cycle button pressed? */ if (data[1 ] &0x80 )
Signature · 1 line
2.31.1
PATCH 3/6 HID: lg-g15: Add a lg_g15_init_input_dev() helper function
In reply to Hans de GoedeFactor the input-device setup + KEY_KBD_LCD_MENU capability setting out of lg_g15_probe() into a new lg_g15_init_input_dev() helper function.
This is a preparation patch for adding support for the LCD menu keys + LCD brightness control on the Logitech Z-10 speakers (with LCD) which use the same protocol as the G15 keyboards.
--- drivers/hid/hid-lg-g15.c | 42 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 17 deletions(-)
drivers/hid/hid-lg-g15.c +25 -17
@@ -709,6 +709,28 @@ static int lg_g15_register_led(struct lg_g15_data *g15, int i)return devm_led_classdev_register (&g15->hdev->dev, &g15->leds[i].cdev); } +/* Common input device init code shared between keyboards and Z-10 speaker handling */ +static void lg_g15_init_input_dev (struct hid_device *hdev,struct input_dev *input, +const char *name) +{ +int i; + + input->name = name; + input->phys = hdev->phys; + input->uniq = hdev->uniq; + input->id.bustype = hdev->bus; + input->id.vendor = hdev->vendor; + input->id.product = hdev->product; + input->id.version = hdev->version; + input->dev.parent = &hdev->dev; + input->open = lg_g15_input_open; + input->close = lg_g15_input_close; + +/* Keys below the LCD, intended for controlling a menu on the LCD */ +for (i =0 ; i <5 ; i++) +input_set_capability (input,EV_KEY ,KEY_KBD_LCD_MENU1 + i); +} +static int lg_g15_probe (struct hid_device *hdev,const struct hid_device_id *id) {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) g15->hdev = hdev; g15->model = id->driver_data; + g15->input = input; +input_set_drvdata (input, hdev);hid_set_drvdata (hdev, (void *)g15);switch (g15->model) {
@@ -822,16 +846,7 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id) goto error_hw_stop;/* Setup and register input device */ - input->name ="Logitech Gaming Keyboard Gaming Keys" ; - input->phys = hdev->phys; - input->uniq = hdev->uniq; - input->id.bustype = hdev->bus; - input->id.vendor = hdev->vendor; - input->id.product = hdev->product; - input->id.version = hdev->version; - input->dev.parent = &hdev->dev; - input->open = lg_g15_input_open; - input->close = lg_g15_input_close; +lg_g15_init_input_dev (hdev, input,"Logitech Gaming Keyboard Gaming Keys" );/* G-keys */ 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)input_set_capability (input,EV_KEY ,KEY_MACRO_PRESET1 + i);input_set_capability (input,EV_KEY ,KEY_MACRO_RECORD_START ); -/* Keys below the LCD, intended for controlling a menu on the LCD */ -for (i =0 ; i <5 ; i++) -input_set_capability (input,EV_KEY ,KEY_KBD_LCD_MENU1 + i); -/* * On the G510 only report headphone and mic mute keys when *not* using * 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)input_set_capability (input,EV_KEY ,KEY_F20 ); } - g15->input = input; -input_set_drvdata (input, hdev); - ret =input_register_device (input);if (ret) goto error_hw_stop;
Signature · 1 line
2.31.1
PATCH 4/6 HID: lg-g15: Make the LED-name used by lg_g15_register_led() a parameter
In reply to Hans de GoedeMake the LED-name used by lg_g15_register_led() a parameter.
This is a preparation patch for adding support for the LCD menu keys + LCD brightness control on the Logitech Z-10 speakers (with LCD) which use the same protocol as the G15 keyboards.
--- drivers/hid/hid-lg-g15.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
drivers/hid/hid-lg-g15.c +11 -12
@@ -652,19 +652,10 @@ static void lg_g15_input_close(struct input_dev *dev)hid_hw_close (hdev); } -static int lg_g15_register_led (struct lg_g15_data *g15,int i) +static int lg_g15_register_led (struct lg_g15_data *g15,int i,const char *name) { -static const char *const led_names[] = { -"g15::kbd_backlight" , -"g15::lcd_backlight" , -"g15::macro_preset1" , -"g15::macro_preset2" , -"g15::macro_preset3" , -"g15::macro_record" , - }; - g15->leds[i].led = i; - g15->leds[i].cdev.name = led_names[i]; + g15->leds[i].cdev.name = name;switch (g15->model) {case LG_G15 :
@@ -733,6 +724,14 @@ static void lg_g15_init_input_dev(struct hid_device *hdev, struct input_dev *inpstatic int lg_g15_probe (struct hid_device *hdev,const struct hid_device_id *id) { +static const char *const led_names[] = { +"g15::kbd_backlight" , +"g15::lcd_backlight" , +"g15::macro_preset1" , +"g15::macro_preset2" , +"g15::macro_preset3" , +"g15::macro_record" , + };u8 gkeys_settings_output_report =0 ;u8 gkeys_settings_feature_report =0 ;struct hid_report_enum *rep_enum;
@@ -874,7 +873,7 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id)/* Register LED devices */ for (i =0 ; i <LG_G15_LED_MAX ; i++) { - ret =lg_g15_register_led (g15, i); + ret =lg_g15_register_led (g15, i, led_names[i]);if (ret) goto error_hw_stop; }
Signature · 1 line
2.31.1
PATCH 5/6 HID: lg-g15: Add support for the Logitech Z-10 speakers
In reply to Hans de GoedeAdd support to hid-lg-g15 for the Logitech Z-10 speakers. This adds support for the LCD menu keys found on these speakers, as well as support for controlling the LCD's brightness through a LED classdev.
--- drivers/hid/hid-ids.h | 1 + drivers/hid/hid-lg-g15.c | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-)
drivers/hid/hid-ids.h +1 -0
@@ -759,6 +759,7 @@#define I2C_DEVICE_ID_LG_7010 0x7010#define USB_VENDOR_ID_LOGITECH 0x046d +#define USB_DEVICE_ID_LOGITECH_Z_10_SPK 0x0a07#define USB_DEVICE_ID_LOGITECH_AUDIOHUB 0x0a0e#define USB_DEVICE_ID_LOGITECH_T651 0xb00c#define USB_DEVICE_ID_LOGITECH_DINOVO_EDGE_KBD 0xb309
drivers/hid/hid-lg-g15.c +37 -1
@@ -28,6 +28,7 @@ enum lg_g15_model {LG_G15_V2 ,LG_G510 ,LG_G510_USB_AUDIO , + LG_Z10, }; enum lg_g15_led_type {
@@ -457,6 +458,13 @@ static int lg_g15_get_initial_led_brightness(struct lg_g15_data *g15)return ret;return lg_g510_update_mkey_led_brightness (g15); +case LG_Z10 : +/* +* Getting the LCD backlight brightness is not supported. +* Reading Feature(2) fails with -EPIPE and this crashes +* the LCD and touch keys part of the speakers. +*/ +return 0 ; }return -EINVAL ;/* Never reached */ }
@@ -626,6 +634,12 @@ static int lg_g15_raw_event(struct hid_device *hdev, struct hid_report *report,if (data[0 ] ==0x02 && size ==5 )return lg_g15_v2_event (g15, data);break ; +case LG_Z10 : +if (data[0 ] ==0x02 && size ==9 ) { +lg_g15_handle_lcd_menu_keys (g15, data); +input_sync (g15->input); + } +break ;case LG_G510 :case LG_G510_USB_AUDIO :if (data[0 ] ==0x03 && size ==5 )
@@ -660,8 +674,10 @@ static int lg_g15_register_led(struct lg_g15_data *g15, int i, const char *name)switch (g15->model) {case LG_G15 :case LG_G15_V2 : - g15->leds[i].cdev.brightness_set_blocking = lg_g15_led_set; g15->leds[i].cdev.brightness_get = lg_g15_led_get; + fallthrough; +case LG_Z10 : + g15->leds[i].cdev.brightness_set_blocking = lg_g15_led_set;if (i <LG_G15_BRIGHTNESS_MAX ) { g15->leds[i].cdev.flags =LED_BRIGHT_HW_CHANGED ; g15->leds[i].cdev.max_brightness =2 ;
@@ -802,6 +818,9 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id) gkeys_settings_feature_report =0x01 ; gkeys =18 ;break ; +case LG_Z10 : + connect_mask =HID_CONNECT_HIDRAW ; +break ; } ret =hid_hw_start (hdev, connect_mask);
@@ -844,6 +863,19 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id)if (ret) goto error_hw_stop; +if (g15->model ==LG_Z10 ) { +lg_g15_init_input_dev (hdev, g15->input,"Logitech Z-10 LCD Menu Keys" ); + ret =input_register_device (g15->input); +if (ret) + goto error_hw_stop; + + ret =lg_g15_register_led (g15,1 ,"z-10::lcd_backlight" ); +if (ret) + goto error_hw_stop; + +return 0 ;/* All done */ + } +/* Setup and register input device */ lg_g15_init_input_dev (hdev, input,"Logitech Gaming Keyboard Gaming Keys" );
@@ -904,6 +936,10 @@ static const struct hid_device_id lg_g15_devices[] = { {HID_USB_DEVICE (USB_VENDOR_ID_LOGITECH , USB_DEVICE_ID_LOGITECH_G510_USB_AUDIO), .driver_data = LG_G510_USB_AUDIO }, + /* Z-10 speakers */ + { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, + USB_DEVICE_ID_LOGITECH_Z_10_SPK), + .driver_data = LG_Z10 }, { } };MODULE_DEVICE_TABLE (hid, lg_g15_devices);
Signature · 1 line
2.31.1
PATCH 6/6 HID: lg-g15 + ite: Add MODULE_AUTHOR
In reply to Hans de GoedeI noticed that the 2 HID drivers which I've written and maintain were missing a MODULE_AUTHOR tag, add this so that people can easily figure out who to email with questions.
--- drivers/hid/hid-ite.c | 1 + drivers/hid/hid-lg-g15.c | 1 + 2 files changed, 2 insertions(+)
drivers/hid/hid-ite.c +1 -0
@@ -135,4 +135,5 @@ static struct hid_driver ite_driver = { };module_hid_driver (ite_driver); +MODULE_AUTHOR ("Hans de Goede <[email protected]>" );MODULE_LICENSE ("GPL" );
drivers/hid/hid-lg-g15.c +1 -0
@@ -952,4 +952,5 @@ static struct hid_driver lg_g15_driver = { };module_hid_driver (lg_g15_driver); +MODULE_AUTHOR ("Hans de Goede <[email protected]>" );MODULE_LICENSE ("GPL" );
Signature · 1 line
2.31.1
Jiri Kosina
maintainerQuoted 10 lines · Hans de Goede
Hi All,
Here is a patch series adding support for the LCD menu keys + LCD brightness control on the Logitech Z-10 speakers (with LCD) which use the same protocol as the G15 keyboards.
The first patch is an unrelated cleanup, patches 2-4 move some code into helper functions to allow re-use in the Z-10 case, patch 5 adds the actual Z-10 support and patch 6 is a bonus patch adding missing
MODULE_AUTHORtags to 2 HID drivers which I maintain.
Series now in for-5.14/logitech. Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs