From bea182ed6d2086698dcbb66c4f63bcaf1a5ac7c7 Mon Sep 17 00:00:00 2001 From: Christoffer Sandberg Date: Mon, 19 Apr 2021 14:13:48 +0200 Subject: [PATCH] Clean-up cl driver state init - Ensure keyb bl state is initialized from params - Unify state writing (directly from state struct) - Use same state write on resume - Don't attempt to init twice if already initialized (should prevent some double writing and make debugging easier) --- src/clevo_keyboard.h | 51 +++++++++++++++++++++---------------------- src/tuxedo_keyboard.c | 8 +++++-- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/clevo_keyboard.h b/src/clevo_keyboard.h index 6588473..7e91c2c 100644 --- a/src/clevo_keyboard.h +++ b/src/clevo_keyboard.h @@ -96,8 +96,6 @@ u32 clevo_keyboard_add_interface(struct clevo_interface_t *new_interface) return -EINVAL; } - clevo_keyboard_write_state(); - mutex_unlock(&clevo_keyboard_interface_modification_lock); return 0; @@ -694,24 +692,17 @@ static void clevo_keyboard_init_device_interface(struct platform_device *dev) ("Sysfs attribute file creation failed for brightness\n"); } - // Set state variables - kbd_led_state.color.left = param_color_left; - kbd_led_state.color.center = param_color_center; - kbd_led_state.color.right = param_color_right; - kbd_led_state.color.extra = param_color_extra; } void clevo_keyboard_write_state(void) { - // Write state - set_color(REGION_LEFT, param_color_left); - set_color(REGION_CENTER, param_color_center); - set_color(REGION_RIGHT, param_color_right); - - set_blinking_pattern(param_blinking_pattern); - if (param_brightness > BRIGHTNESS_MAX) param_brightness = BRIGHTNESS_DEFAULT; - set_brightness(param_brightness); - set_enabled(param_state); + // Note: + // - set_blinking_pattern also writes colors + // - set_brightness, set_enabled, set_blinking_pattern + // still also update state + set_blinking_pattern(kbd_led_state.blinking_pattern); + set_brightness(kbd_led_state.brightness); + set_enabled(kbd_led_state.enabled); } static int clevo_keyboard_probe_only_init(struct platform_device *dev) @@ -752,15 +743,7 @@ static int clevo_keyboard_resume(struct platform_device *dev) { clevo_evaluate_method(CLEVO_METHOD_ID_GET_AP, 0, NULL); - set_color(REGION_LEFT, kbd_led_state.color.left); - set_color(REGION_CENTER, kbd_led_state.color.center); - set_color(REGION_RIGHT, kbd_led_state.color.right); - if (kbd_led_state.has_extra) - set_color(REGION_EXTRA, kbd_led_state.color.extra); - - set_blinking_pattern(kbd_led_state.blinking_pattern); - set_brightness(kbd_led_state.brightness); - set_enabled(kbd_led_state.enabled); + clevo_keyboard_write_state(); return 0; } @@ -799,7 +782,23 @@ int clevo_keyboard_init(void) { bool performance_profile_set_workaround; - tuxedo_keyboard_init_driver(&clevo_keyboard_driver_v2); + if (IS_ERR_OR_NULL(tuxedo_keyboard_init_driver(&clevo_keyboard_driver_v2))) + return -EEXIST; + + // Init state from params + kbd_led_state.color.left = param_color_left; + kbd_led_state.color.center = param_color_center; + kbd_led_state.color.right = param_color_right; + kbd_led_state.color.extra = param_color_extra; + + kbd_led_state.blinking_pattern = param_blinking_pattern; + + if (param_brightness > BRIGHTNESS_MAX) param_brightness = BRIGHTNESS_DEFAULT; + kbd_led_state.brightness = param_brightness; + + kbd_led_state.enabled = param_state; + + clevo_keyboard_write_state(); // Workaround for firmware issue not setting selected performance profile. // Explicitly set "performance" perf. profile on init regardless of what is chosen diff --git a/src/tuxedo_keyboard.c b/src/tuxedo_keyboard.c index e05b167..c5999ed 100644 --- a/src/tuxedo_keyboard.c +++ b/src/tuxedo_keyboard.c @@ -80,6 +80,8 @@ err_free_input_device: struct platform_device *tuxedo_keyboard_init_driver(struct tuxedo_keyboard_driver *tk_driver) { int err; + struct platform_device *new_platform_device = NULL; + TUXEDO_DEBUG("init driver start\n"); mutex_lock(&tuxedo_keyboard_init_driver_lock); @@ -91,9 +93,11 @@ struct platform_device *tuxedo_keyboard_init_driver(struct tuxedo_keyboard_drive } else { // Otherwise, attempt to initialize structures TUXEDO_DEBUG("create platform bundle\n"); - tuxedo_platform_device = platform_create_bundle( + new_platform_device = platform_create_bundle( tk_driver->platform_driver, tk_driver->probe, NULL, 0, NULL, 0); + tuxedo_platform_device = new_platform_device; + if (IS_ERR_OR_NULL(tuxedo_platform_device)) { // Normal case probe failed, no init goto init_driver_exit; @@ -116,7 +120,7 @@ struct platform_device *tuxedo_keyboard_init_driver(struct tuxedo_keyboard_drive init_driver_exit: mutex_unlock(&tuxedo_keyboard_init_driver_lock); - return tuxedo_platform_device; + return new_platform_device; } EXPORT_SYMBOL(tuxedo_keyboard_init_driver);