From 5b770f999619d61fce014d0fffbab0fd150ebd4f Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Wed, 12 Apr 2023 19:04:12 +0200 Subject: [PATCH] Fix Clevo devices changing keyboard backlight color on resume --- src/clevo_keyboard.h | 2 ++ src/clevo_leds.h | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/clevo_keyboard.h b/src/clevo_keyboard.h index 817e50f..d069fe2 100644 --- a/src/clevo_keyboard.h +++ b/src/clevo_keyboard.h @@ -359,6 +359,8 @@ static int clevo_keyboard_suspend(struct platform_device *dev, pm_message_t stat static int clevo_keyboard_resume(struct platform_device *dev) { clevo_evaluate_method(CLEVO_CMD_SET_EVENTS_ENABLED, 0, NULL); + clevo_leds_restore_state_extern(); // Sometimes clevo devices forget their last state after + // suspend, so let the kernel ensure it. set_enabled_cmd(1); return 0; } diff --git a/src/clevo_leds.h b/src/clevo_leds.h index 18f2ab7..ebd29af 100644 --- a/src/clevo_leds.h +++ b/src/clevo_leds.h @@ -35,6 +35,7 @@ enum clevo_kb_backlight_types { int clevo_leds_init(struct platform_device *dev); int clevo_leds_remove(struct platform_device *dev); enum clevo_kb_backlight_types clevo_leds_get_backlight_type(void); +void clevo_leds_restore_state_extern(void); void clevo_leds_set_brightness_extern(enum led_brightness brightness); void clevo_leds_set_color_extern(u32 color); @@ -380,6 +381,21 @@ enum clevo_kb_backlight_types clevo_leds_get_backlight_type() { } EXPORT_SYMBOL(clevo_leds_get_backlight_type); +void clevo_leds_restore_state_extern(void) { + if (clevo_kb_backlight_type == CLEVO_KB_BACKLIGHT_TYPE_FIXED_COLOR) { + clevo_led_cdev.brightness_set(&clevo_led_cdev, clevo_led_cdev.brightness); + } + else if (clevo_kb_backlight_type == CLEVO_KB_BACKLIGHT_TYPE_1_ZONE_RGB) { + clevo_mcled_cdevs[0].led_cdev.brightness_set(&clevo_mcled_cdevs[0].led_cdev, clevo_mcled_cdevs[0].led_cdev.brightness); + } + else if (clevo_kb_backlight_type == CLEVO_KB_BACKLIGHT_TYPE_3_ZONE_RGB) { + clevo_mcled_cdevs[0].led_cdev.brightness_set(&clevo_mcled_cdevs[0].led_cdev, clevo_mcled_cdevs[0].led_cdev.brightness); + clevo_mcled_cdevs[1].led_cdev.brightness_set(&clevo_mcled_cdevs[1].led_cdev, clevo_mcled_cdevs[1].led_cdev.brightness); + clevo_mcled_cdevs[2].led_cdev.brightness_set(&clevo_mcled_cdevs[2].led_cdev, clevo_mcled_cdevs[2].led_cdev.brightness); + } +} +EXPORT_SYMBOL(clevo_leds_restore_state_extern); + void clevo_leds_set_brightness_extern(enum led_brightness brightness) { if (clevo_kb_backlight_type == CLEVO_KB_BACKLIGHT_TYPE_FIXED_COLOR) { clevo_led_cdev.brightness_set(&clevo_led_cdev, brightness);