HID: lg-g15: G15 v2 contrast and game-mode LEDs
Subsystems (2)
v2 cover HID: lg-g15: G15 v2 contrast and game-mode LEDs
This series adds two LEDs for the Logitech G15 v2 to hid-lg-g15.
Patch 1 exposes the GamePanel LCD contrast as a g15::lcd_contrast LED.
Patch 2 binds the G15 v2's keyboard device (046D:C226), which is currently handled by hid-generic, and exposes the Super-key-lock ("Game Mode") state as a read-only g15::game_mode LED. Normal key input on that device is left to hid-input, with the same HID_QUIRK_INPUT_PER_APP setup hid-generic uses.
Tested on a Logitech G15 v2, together with lcdproc (g15 driver, hidraw mode) driving the LCD: the LCD output, the contrast LED and the L1-L5 keys all keep working, and the c226 input devices have the same names as under hid-generic. Also tested across a suspend/resume cycle.
Changes in v2:
- Drop the framebuffer patch; userspace (lcdproc, libg15) drives the LCD through hidraw instead.
- Drop the remove-path patch: hid-core holds driver_input_lock during remove(), so raw_event cannot reschedule the work.
- Contrast LED: clamp the brightness before indexing contrast_values[], and restore the contrast on resume under g15->mutex.
- Game-mode LED: set HID_QUIRK_INPUT_PER_APP like hid-generic, read the initial lock state before registering the LED, and guard the cached state with a spinlock so a resume-time GET_REPORT cannot overwrite a newer input report.
Torstein Eide (2):
HID: lg-g15: add LCD contrast LED
HID: lg-g15: report Super-key-lock state on G15 v2's keyboard
interface
drivers/hid/hid-ids.h | 1 + drivers/hid/hid-lg-g15.c | 347 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 343 insertions(+), 5 deletions(-)
base-commit: 2c2fe95ab19b09bef7391e3e5cdf8146d09792b6
Signature · 1 line
2.53.0
PATCH v2 1/2 HID: lg-g15: add LCD contrast LED
Wire values ({2, 32, 129, value}) match libg15's setLCDContrast() byte-for-byte.
Tested on Logitech G15v2.
Based on libg15.c.
--- drivers/hid/hid-lg-g15.c | 119 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 2 deletions(-)
drivers/hid/hid-lg-g15.c +117 -2
@@ -59,7 +59,16 @@ enum lg_g15_led_type {LG_G15_MACRO_PRESET2 ,LG_G15_MACRO_PRESET3 ,LG_G15_MACRO_RECORD , -LG_G15_LED_MAX +LG_G15_LED_MAX , +/* +* LCD contrast uses a different feature-report sub-format than the +* brightness/macro fields above (see lg_g15_contrast_set()) and has +* no hardware readback, so it lives outside [0, LG_G15_LED_MAX) to +* avoid being swept into the G13/macro loops bounded by +* LG_G15_LED_MAX. G15/G15 v2 only; registered explicitly. +*/ +LG_G15_LCD_CONTRAST =LG_G15_LED_MAX , +LG_G15_LED_ARRAY_SIZE }; struct g13_input_report {
@@ -89,9 +98,10 @@ struct lg_g15_data {struct input_dev *input_js;/* Separate joystick device for G13. */ struct hid_device *hdev;enum lg_g15_model model; -struct lg_g15_led leds[LG_G15_LED_MAX ]; +struct lg_g15_led leds[LG_G15_LED_ARRAY_SIZE ];bool game_mode_enabled;bool backlight_disabled;/* true == HW backlight toggled *OFF* */ +bool lcd_contrast_set;/* LCD contrast written at least once */ };/********* G13 LED functions ***********/
@@ -365,6 +375,69 @@ static int lg_g15_led_set(struct led_classdev *led_cdev,return ret; } +/* +* LCD contrast, report 2 field 32: {2, 32, 129, value}, value in +* {18, 22, 26} for low/medium/high. Distinct sub-format from the +* brightness/macro fields (value sits in byte 3, not byte 2, and byte 2 is +* a fixed marker rather than the field selector) and has no GET_REPORT +* readback, so brightness_get just returns the last value we set. +*/ +/* Must be called with g15->mutex held */ +static int lg_g15_contrast_write (struct lg_g15_data *g15, +enum led_brightness brightness) +{ +static const u8 contrast_values[] = {18 ,22 ,26 }; +int ret; + +/* +* The LED core does not clamp to max_brightness on every path (a +* delayed set passes the raw sysfs value), so clamp here. +*/ + brightness = min_t(enum led_brightness, brightness, +ARRAY_SIZE (contrast_values) -1 ); + + g15->transfer_buf[0 ] =LG_G15_FEATURE_REPORT ; + g15->transfer_buf[1 ] =32 ; + g15->transfer_buf[2 ] =129 ; + g15->transfer_buf[3 ] = contrast_values[brightness]; + + ret =hid_hw_raw_request (g15->hdev,LG_G15_FEATURE_REPORT , + g15->transfer_buf,4 , +HID_FEATURE_REPORT ,HID_REQ_SET_REPORT ); +if (ret !=4 ) { +hid_err (g15->hdev,"Error setting LCD contrast: %d\n" , ret); +return (ret <0 ) ? ret : -EIO ; + } + + g15->leds[LG_G15_LCD_CONTRAST ].brightness = brightness; + g15->lcd_contrast_set = true; +return 0 ; +} + +static int lg_g15_contrast_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct lg_g15_data *g15 =dev_get_drvdata (led_cdev->dev->parent); +int ret; + +if (led_cdev->flags &LED_UNREGISTERING ) +return 0 ; + +mutex_lock (&g15->mutex); + ret =lg_g15_contrast_write (g15, brightness); +mutex_unlock (&g15->mutex); + +return ret; +} + +static enum led_brightness lg_g15_contrast_get (struct led_classdev *led_cdev) +{ +struct lg_g15_led *g15_led = + container_of(led_cdev, struct lg_g15_led, cdev); + +return g15_led->brightness; +} +static void lg_g15_leds_changed_work (struct work_struct *work) { struct lg_g15_data *g15 = container_of(work, struct lg_g15_data, work);
@@ -1017,6 +1090,13 @@ static int lg_g15_register_led(struct lg_g15_data *g15, int i, const char *name)break ;case LG_G15 :case LG_G15_V2 : +if (i ==LG_G15_LCD_CONTRAST ) { + g15->leds[i].cdev.brightness_set_blocking = lg_g15_contrast_set; + g15->leds[i].cdev.brightness_get = lg_g15_contrast_get; + g15->leds[i].cdev.max_brightness =2 ; + ret =devm_led_classdev_register (&g15->hdev->dev, &g15->leds[i].cdev); +break ; + } g15->leds[i].cdev.brightness_get = lg_g15_led_get; fallthrough;case LG_Z10 :
@@ -1333,6 +1413,14 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id) goto error_hw_stop; } +/* The G11 shares the LG_G15 model but has no LCD */ +if ((g15->model ==LG_G15 && hdev->product !=USB_DEVICE_ID_LOGITECH_G11 ) || + g15->model ==LG_G15_V2 ) { + ret =lg_g15_register_led (g15,LG_G15_LCD_CONTRAST ,"g15::lcd_contrast" ); +if (ret) + goto error_hw_stop; + } +return 0 ; error_hw_stop:
@@ -1389,12 +1477,39 @@ static void lg_g15_remove(struct hid_device *hdev)hid_hw_stop (hdev); } +/* +* The LCD does not retain its contrast across a USB reset or power loss; +* re-apply the last value userspace set, if any. +*/ +static int lg_g15_resume (struct hid_device *hdev) +{ +struct lg_g15_data *g15 =hid_get_drvdata (hdev); +struct lg_g15_led *contrast; + +if (!g15) +return 0 ; + + contrast = &g15->leds[LG_G15_LCD_CONTRAST ]; +if (!contrast->cdev.dev) +return 0 ; + +/* Under the mutex, so a concurrent contrast set cannot be undone */ +mutex_lock (&g15->mutex); +if (g15->lcd_contrast_set) +lg_g15_contrast_write (g15, contrast->brightness); +mutex_unlock (&g15->mutex); + +return 0 ; +} +static struct hid_driver lg_g15_driver = { .name ="lg-g15" , .id_table = lg_g15_devices, .raw_event = lg_g15_raw_event, .probe = lg_g15_probe, .remove = lg_g15_remove, + .resume = lg_g15_resume, + .reset_resume = lg_g15_resume, };module_hid_driver (lg_g15_driver);
Signature · 1 line
2.53.0
PATCH v2 2/2 HID: lg-g15: report Super-key-lock state on G15 v2's keyboard interface
In reply to Torstein EideThe G15 v2 exposes a second USB HID interface (046D:C226) previously left to hid-generic, which reports the Super-key-lock ("Game Mode") state on report 3. Bind it as LG_G15_V2_KBD: keep default hid-input behavior for normal typing, and additionally decode report 3 to expose the lock state as a read-only g15::game_mode LED.
Tested on Logitech G15v2.
--- drivers/hid/hid-ids.h | 1 + drivers/hid/hid-lg-g15.c | 230 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 227 insertions(+), 4 deletions(-)
drivers/hid/hid-ids.h +1 -0
@@ -950,6 +950,7 @@#define USB_DEVICE_ID_LOGITECH_G13 0xc21c#define USB_DEVICE_ID_LOGITECH_G15_LCD 0xc222#define USB_DEVICE_ID_LOGITECH_G11 0xc225 +#define USB_DEVICE_ID_LOGITECH_G15_V2_KBD 0xc226#define USB_DEVICE_ID_LOGITECH_G15_V2_LCD 0xc227#define USB_DEVICE_ID_LOGITECH_G510 0xc22d#define USB_DEVICE_ID_LOGITECH_G510_USB_AUDIO 0xc22e
drivers/hid/hid-lg-g15.c +226 -4
308 lines not on this page · raw message
Signature · 1 line
2.53.0