From 0845466b0b936820dc44da65b3af4ba1175c17fe Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Tue, 20 Jun 2023 18:35:47 +0200 Subject: [PATCH] Finish implementation of notify hw changed for Clevo --- src/clevo_leds.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/clevo_leds.h b/src/clevo_leds.h index 4abe589..9dcc915 100644 --- a/src/clevo_leds.h +++ b/src/clevo_leds.h @@ -180,7 +180,8 @@ static struct led_classdev clevo_led_cdev = { .name = "white:" LED_FUNCTION_KBD_BACKLIGHT, .max_brightness = CLEVO_KBD_BRIGHTNESS_WHITE_MAX, .brightness_set = &clevo_leds_set_brightness, - .brightness = CLEVO_KBD_BRIGHTNESS_WHITE_DEFAULT + .brightness = CLEVO_KBD_BRIGHTNESS_WHITE_DEFAULT, + .flags = LED_BRIGHT_HW_CHANGED }; static struct mc_subled clevo_mcled_cdevs_subleds[3][3] = { @@ -400,6 +401,8 @@ enum clevo_kb_backlight_types clevo_leds_get_backlight_type(void) { } EXPORT_SYMBOL(clevo_leds_get_backlight_type); +// TODO Don't reuse brightness_set as it is writing back the same brightness which could lead to race conditions. +// Reimplement brightness_set instead without writing back brightness value like in uniwill_leds.h. 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); @@ -416,12 +419,20 @@ void clevo_leds_restore_state_extern(void) { EXPORT_SYMBOL(clevo_leds_restore_state_extern); void clevo_leds_notify_brightness_change_extern(void) { + int status; + u32 result; + if (clevo_kb_backlight_type == CLEVO_KB_BACKLIGHT_TYPE_FIXED_COLOR) { - // TODO + status = clevo_evaluate_method(CLEVO_CMD_GET_KB_WHITE_LEDS, 0, &result); + pr_debug("Firmware set brightness: %u\n", result); + clevo_led_cdev.brightness = result; + led_classdev_notify_brightness_hw_changed(&clevo_led_cdev, result); } } EXPORT_SYMBOL(clevo_leds_notify_brightness_change_extern); +// TODO Not used externaly, but only on init. Should not be exposed because it would require a correct +// led_classdev_notify_brightness_hw_changed implementation when used outside of init. 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); @@ -437,6 +448,8 @@ void clevo_leds_set_brightness_extern(enum led_brightness brightness) { } EXPORT_SYMBOL(clevo_leds_set_brightness_extern); +// TODO Not used externaly, but only on init. Should not be exposed because it would require a correct +// led_classdev_notify_brightness_hw_changed equivalent for color implementation when used outside of init. void clevo_leds_set_color_extern(u32 color) { if (clevo_kb_backlight_type == CLEVO_KB_BACKLIGHT_TYPE_1_ZONE_RGB) { clevo_mcled_cdevs[0].subled_info[0].intensity = (color >> 16) & 0xff;