This commit is contained in:
Werner Sembach 2022-08-24 18:42:53 +02:00
parent 2766237dd0
commit 6f9ee3fd6f

View file

@ -39,83 +39,15 @@
#define CLEVO_KB_MODE_DEFAULT 0 // "CUSTOM"/Static Color #define CLEVO_KB_MODE_DEFAULT 0 // "CUSTOM"/Static Color
struct tuxedo_keyboard_driver clevo_keyboard_driver;
static struct clevo_interfaces_t { static struct clevo_interfaces_t {
struct clevo_interface_t *wmi; struct clevo_interface_t *wmi;
struct clevo_interface_t *acpi; struct clevo_interface_t *acpi;
} clevo_interfaces; } clevo_interfaces;
struct clevo_interface_t *active_clevo_interface; static struct clevo_interface_t *active_clevo_interface;
void clevo_keyboard_event_callb(u32 event); // TODO Reorder to not require forward declaration?
static DEFINE_MUTEX(clevo_keyboard_interface_modification_lock); static DEFINE_MUTEX(clevo_keyboard_interface_modification_lock);
u32 clevo_keyboard_add_interface(struct clevo_interface_t *new_interface)
{
mutex_lock(&clevo_keyboard_interface_modification_lock);
if (strcmp(new_interface->string_id, CLEVO_INTERFACE_WMI_STRID) == 0) {
clevo_interfaces.wmi = new_interface;
clevo_interfaces.wmi->event_callb = clevo_keyboard_event_callb;
// Only use wmi if there is no other current interface
if (ZERO_OR_NULL_PTR(active_clevo_interface)) {
pr_debug("enable wmi events\n");
clevo_interfaces.wmi->method_call(CLEVO_CMD_SET_EVENTS_ENABLED, 0, NULL);
active_clevo_interface = clevo_interfaces.wmi;
}
} else if (strcmp(new_interface->string_id, CLEVO_INTERFACE_ACPI_STRID) == 0) {
clevo_interfaces.acpi = new_interface;
clevo_interfaces.acpi->event_callb = clevo_keyboard_event_callb;
pr_debug("enable acpi events (takes priority)\n");
clevo_interfaces.acpi->method_call(CLEVO_CMD_SET_EVENTS_ENABLED, 0, NULL);
active_clevo_interface = clevo_interfaces.acpi;
} else {
// Not recognized interface
pr_err("unrecognized interface\n");
mutex_unlock(&clevo_keyboard_interface_modification_lock);
return -EINVAL;
}
mutex_unlock(&clevo_keyboard_interface_modification_lock);
if (active_clevo_interface != NULL)
tuxedo_keyboard_init_driver(&clevo_keyboard_driver);
return 0;
}
EXPORT_SYMBOL(clevo_keyboard_add_interface);
u32 clevo_keyboard_remove_interface(struct clevo_interface_t *interface)
{
mutex_lock(&clevo_keyboard_interface_modification_lock);
if (strcmp(interface->string_id, CLEVO_INTERFACE_WMI_STRID) == 0) {
clevo_interfaces.wmi = NULL;
} else if (strcmp(interface->string_id, CLEVO_INTERFACE_ACPI_STRID) == 0) {
clevo_interfaces.acpi = NULL;
} else {
mutex_unlock(&clevo_keyboard_interface_modification_lock);
return -EINVAL;
}
if (active_clevo_interface == interface) {
tuxedo_keyboard_remove_driver(&clevo_keyboard_driver);
active_clevo_interface = NULL;
}
mutex_unlock(&clevo_keyboard_interface_modification_lock);
return 0;
}
EXPORT_SYMBOL(clevo_keyboard_remove_interface);
static struct key_entry clevo_keymap[] = { static struct key_entry clevo_keymap[] = {
// Keyboard backlight (RGB versions) // Keyboard backlight (RGB versions)
{ KE_KEY, CLEVO_EVENT_KB_LEDS_DECREASE, { KEY_KBDILLUMDOWN } }, { KE_KEY, CLEVO_EVENT_KB_LEDS_DECREASE, { KEY_KBDILLUMDOWN } },
@ -148,22 +80,22 @@ static struct key_entry clevo_keymap[] = {
{ KE_END, 0 } { KE_END, 0 }
}; };
#define BRIGHTNESS_STEP 32
// Keyboard struct // Keyboard struct
struct kbd_led_state_t { static struct kbd_led_state_t {
u8 has_mode; u8 has_mode;
u8 mode; u8 mode;
u8 whole_kbd_color; u8 whole_kbd_color;
} kbd_led_state = {
.has_mode = 1,
.mode = CLEVO_KB_MODE_DEFAULT,
.whole_kbd_color = 7,
}; };
struct blinking_pattern_t { static struct kbd_backlight_mode_t {
u8 key; u8 key;
u32 value; u32 value;
const char *const name; const char *const name;
}; } kbd_backlight_modes[] = {
static struct blinking_pattern_t kbd_backlight_modes[] = {
{ .key = 0, .value = 0x00000000, .name = "CUSTOM"}, { .key = 0, .value = 0x00000000, .name = "CUSTOM"},
{ .key = 1, .value = 0x1002a000, .name = "BREATHE"}, { .key = 1, .value = 0x1002a000, .name = "BREATHE"},
{ .key = 2, .value = 0x33010000, .name = "CYCLE"}, { .key = 2, .value = 0x33010000, .name = "CYCLE"},
@ -174,12 +106,6 @@ static struct blinking_pattern_t kbd_backlight_modes[] = {
{ .key = 7, .value = 0xB0000000, .name = "WAVE"} { .key = 7, .value = 0xB0000000, .name = "WAVE"}
}; };
static struct kbd_led_state_t kbd_led_state = {
.has_mode = 1,
.mode = CLEVO_KB_MODE_DEFAULT,
.whole_kbd_color = 7,
};
// Sysfs Interface for the backlight blinking pattern // Sysfs Interface for the backlight blinking pattern
static ssize_t show_kbd_backlight_modes_fs(struct device *child, struct device_attribute *attr, static ssize_t show_kbd_backlight_modes_fs(struct device *child, struct device_attribute *attr,
char *buffer) char *buffer)
@ -334,7 +260,7 @@ static int brightness_validator(const char *value,
return param_set_int(value, brightness_param); return param_set_int(value, brightness_param);
} }
void clevo_keyboard_event_callb(u32 event) static void clevo_keyboard_event_callb(u32 event)
{ {
u32 key_event = event; u32 key_event = event;
@ -384,7 +310,7 @@ static bool dmi_string_in(enum dmi_field f, const char *str)
return strstr(info, str) != NULL; return strstr(info, str) != NULL;
} }
int clevo_keyboard_init(void) static int clevo_keyboard_init(void)
{ {
bool performance_profile_set_workaround; bool performance_profile_set_workaround;
@ -467,10 +393,73 @@ static struct platform_driver platform_driver_clevo = {
}, },
}; };
struct tuxedo_keyboard_driver clevo_keyboard_driver = { static struct tuxedo_keyboard_driver clevo_keyboard_driver = {
.platform_driver = &platform_driver_clevo, .platform_driver = &platform_driver_clevo,
.probe = clevo_keyboard_probe, .probe = clevo_keyboard_probe,
.key_map = clevo_keymap, .key_map = clevo_keymap,
}; };
u32 clevo_keyboard_add_interface(struct clevo_interface_t *new_interface)
{
mutex_lock(&clevo_keyboard_interface_modification_lock);
if (strcmp(new_interface->string_id, CLEVO_INTERFACE_WMI_STRID) == 0) {
clevo_interfaces.wmi = new_interface;
clevo_interfaces.wmi->event_callb = clevo_keyboard_event_callb;
// Only use wmi if there is no other current interface
if (ZERO_OR_NULL_PTR(active_clevo_interface)) {
pr_debug("enable wmi events\n");
clevo_interfaces.wmi->method_call(CLEVO_CMD_SET_EVENTS_ENABLED, 0, NULL);
active_clevo_interface = clevo_interfaces.wmi;
}
} else if (strcmp(new_interface->string_id, CLEVO_INTERFACE_ACPI_STRID) == 0) {
clevo_interfaces.acpi = new_interface;
clevo_interfaces.acpi->event_callb = clevo_keyboard_event_callb;
pr_debug("enable acpi events (takes priority)\n");
clevo_interfaces.acpi->method_call(CLEVO_CMD_SET_EVENTS_ENABLED, 0, NULL);
active_clevo_interface = clevo_interfaces.acpi;
} else {
// Not recognized interface
pr_err("unrecognized interface\n");
mutex_unlock(&clevo_keyboard_interface_modification_lock);
return -EINVAL;
}
mutex_unlock(&clevo_keyboard_interface_modification_lock);
if (active_clevo_interface != NULL)
tuxedo_keyboard_init_driver(&clevo_keyboard_driver);
return 0;
}
EXPORT_SYMBOL(clevo_keyboard_add_interface);
u32 clevo_keyboard_remove_interface(struct clevo_interface_t *interface)
{
mutex_lock(&clevo_keyboard_interface_modification_lock);
if (strcmp(interface->string_id, CLEVO_INTERFACE_WMI_STRID) == 0) {
clevo_interfaces.wmi = NULL;
} else if (strcmp(interface->string_id, CLEVO_INTERFACE_ACPI_STRID) == 0) {
clevo_interfaces.acpi = NULL;
} else {
mutex_unlock(&clevo_keyboard_interface_modification_lock);
return -EINVAL;
}
if (active_clevo_interface == interface) {
tuxedo_keyboard_remove_driver(&clevo_keyboard_driver);
active_clevo_interface = NULL;
}
mutex_unlock(&clevo_keyboard_interface_modification_lock);
return 0;
}
EXPORT_SYMBOL(clevo_keyboard_remove_interface);
#endif // CLEVO_KEYBOARD_H #endif // CLEVO_KEYBOARD_H