|
26 | 26 | #define LG_G510_FEATURE_BACKLIGHT_RGB 0x05 |
27 | 27 | #define LG_G510_FEATURE_POWER_ON_RGB 0x06 |
28 | 28 |
|
| 29 | +#define LG_G510_INPUT_MACRO_KEYS 0x03 |
| 30 | +#define LG_G510_INPUT_KBD_BACKLIGHT 0x04 |
| 31 | + |
29 | 32 | #define LG_G13_INPUT_REPORT 0x01 |
30 | 33 | #define LG_G13_FEATURE_M_KEYS_LEDS 0x05 |
31 | 34 | #define LG_G13_FEATURE_BACKLIGHT_RGB 0x07 |
@@ -423,6 +426,20 @@ static int lg_g510_get_initial_led_brightness(struct lg_g15_data *g15, int i) |
423 | 426 | g15->leds[i].brightness = 0; |
424 | 427 | } |
425 | 428 |
|
| 429 | + if (i) |
| 430 | + return 0; |
| 431 | + |
| 432 | + ret = hid_hw_raw_request(g15->hdev, LG_G510_INPUT_KBD_BACKLIGHT, |
| 433 | + g15->transfer_buf, 2, |
| 434 | + HID_INPUT_REPORT, HID_REQ_GET_REPORT); |
| 435 | + if (ret != 2) { |
| 436 | + /* This can happen when a KVM switch is used, so only warn. */ |
| 437 | + hid_warn(g15->hdev, "Error getting backlight state: %d\n", ret); |
| 438 | + return 0; |
| 439 | + } |
| 440 | + |
| 441 | + g15->backlight_disabled = g15->transfer_buf[1] & 0x04; |
| 442 | + |
426 | 443 | return 0; |
427 | 444 | } |
428 | 445 |
|
@@ -849,14 +866,24 @@ static int lg_g510_event(struct lg_g15_data *g15, u8 *data) |
849 | 866 |
|
850 | 867 | static int lg_g510_leds_event(struct lg_g15_data *g15, u8 *data) |
851 | 868 | { |
| 869 | + struct lg_g15_led *g15_led = &g15->leds[LG_G15_KBD_BRIGHTNESS]; |
852 | 870 | bool backlight_disabled; |
853 | 871 |
|
| 872 | + backlight_disabled = data[1] & 0x04; |
| 873 | + if (backlight_disabled == g15->backlight_disabled) |
| 874 | + return 0; |
| 875 | + |
| 876 | + led_classdev_notify_brightness_hw_changed( |
| 877 | + &g15_led->mcdev.led_cdev, |
| 878 | + backlight_disabled ? 0 : g15_led->brightness); |
| 879 | + |
| 880 | + g15->backlight_disabled = backlight_disabled; |
| 881 | + |
854 | 882 | /* |
855 | 883 | * The G510 ignores backlight updates when the backlight is turned off |
856 | 884 | * through the light toggle button on the keyboard, to work around this |
857 | 885 | * we queue a workitem to sync values when the backlight is turned on. |
858 | 886 | */ |
859 | | - backlight_disabled = data[1] & 0x04; |
860 | 887 | if (!backlight_disabled) |
861 | 888 | schedule_work(&g15->work); |
862 | 889 |
|
@@ -892,9 +919,9 @@ static int lg_g15_raw_event(struct hid_device *hdev, struct hid_report *report, |
892 | 919 | break; |
893 | 920 | case LG_G510: |
894 | 921 | case LG_G510_USB_AUDIO: |
895 | | - if (data[0] == 0x03 && size == 5) |
| 922 | + if (data[0] == LG_G510_INPUT_MACRO_KEYS && size == 5) |
896 | 923 | return lg_g510_event(g15, data); |
897 | | - if (data[0] == 0x04 && size == 2) |
| 924 | + if (data[0] == LG_G510_INPUT_KBD_BACKLIGHT && size == 2) |
898 | 925 | return lg_g510_leds_event(g15, data); |
899 | 926 | break; |
900 | 927 | } |
@@ -933,6 +960,8 @@ static void lg_g15_setup_led_rgb(struct lg_g15_data *g15, int index) |
933 | 960 | lg_g510_kbd_led_set; |
934 | 961 | gled->mcdev.led_cdev.brightness_get = |
935 | 962 | lg_g510_kbd_led_get; |
| 963 | + if (index == LG_G15_KBD_BRIGHTNESS) |
| 964 | + g15->leds[index].mcdev.led_cdev.flags = LED_BRIGHT_HW_CHANGED; |
936 | 965 | } |
937 | 966 | gled->mcdev.led_cdev.max_brightness = 255; |
938 | 967 | gled->mcdev.num_colors = 3; |
|
0 commit comments