2020-12-09 13:17:20 +01:00
|
|
|
/*!
|
|
|
|
* Copyright (c) 2018-2020 TUXEDO Computers GmbH <tux@tuxedocomputers.com>
|
|
|
|
*
|
|
|
|
* This file is part of tuxedo-keyboard.
|
|
|
|
*
|
|
|
|
* tuxedo-keyboard is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this software. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2022-07-15 14:45:51 +02:00
|
|
|
#ifndef CLEVO_KEYBOARD_H
|
|
|
|
#define CLEVO_KEYBOARD_H
|
|
|
|
|
2020-05-27 17:08:40 +02:00
|
|
|
#include "tuxedo_keyboard_common.h"
|
2020-12-03 10:15:38 +01:00
|
|
|
#include "clevo_interfaces.h"
|
2022-08-24 10:57:20 +02:00
|
|
|
#include "clevo_leds.h"
|
2020-05-27 17:08:40 +02:00
|
|
|
|
2020-12-04 15:20:55 +01:00
|
|
|
// Clevo event codes
|
2022-08-24 10:57:20 +02:00
|
|
|
#define CLEVO_EVENT_KB_LEDS_DECREASE 0x81
|
|
|
|
#define CLEVO_EVENT_KB_LEDS_INCREASE 0x82
|
|
|
|
#define CLEVO_EVENT_KB_LEDS_CYCLE_MODE 0x83
|
|
|
|
#define CLEVO_EVENT_KB_LEDS_CYCLE_BRIGHTNESS 0x8A
|
|
|
|
#define CLEVO_EVENT_KB_LEDS_TOGGLE 0x9F
|
|
|
|
|
|
|
|
#define CLEVO_EVENT_TOUCHPAD_TOGGLE 0x5D
|
|
|
|
#define CLEVO_EVENT_TOUCHPAD_OFF 0xFC
|
|
|
|
#define CLEVO_EVENT_TOUCHPAD_ON 0xFD
|
2020-05-27 17:08:40 +02:00
|
|
|
|
2022-08-24 10:57:20 +02:00
|
|
|
#define CLEVO_EVENT_RFKILL1 0x85
|
|
|
|
#define CLEVO_EVENT_RFKILL2 0x86
|
2020-05-27 17:08:40 +02:00
|
|
|
|
2022-08-24 10:57:20 +02:00
|
|
|
#define CLEVO_KB_MODE_DEFAULT 0 // "CUSTOM"/Static Color
|
2020-05-27 17:08:40 +02:00
|
|
|
|
2020-12-02 17:25:43 +01:00
|
|
|
static struct clevo_interfaces_t {
|
|
|
|
struct clevo_interface_t *wmi;
|
|
|
|
struct clevo_interface_t *acpi;
|
|
|
|
} clevo_interfaces;
|
|
|
|
|
2022-08-24 18:42:53 +02:00
|
|
|
static struct clevo_interface_t *active_clevo_interface;
|
2020-12-02 17:25:43 +01:00
|
|
|
|
2021-03-19 16:20:50 +01:00
|
|
|
static DEFINE_MUTEX(clevo_keyboard_interface_modification_lock);
|
|
|
|
|
2020-12-04 15:20:55 +01:00
|
|
|
static struct key_entry clevo_keymap[] = {
|
2020-05-27 17:08:40 +02:00
|
|
|
// Keyboard backlight (RGB versions)
|
2022-08-24 10:57:20 +02:00
|
|
|
{ KE_KEY, CLEVO_EVENT_KB_LEDS_DECREASE, { KEY_KBDILLUMDOWN } },
|
|
|
|
{ KE_KEY, CLEVO_EVENT_KB_LEDS_INCREASE, { KEY_KBDILLUMUP } },
|
|
|
|
{ KE_KEY, CLEVO_EVENT_KB_LEDS_TOGGLE, { KEY_KBDILLUMTOGGLE } },
|
|
|
|
{ KE_KEY, CLEVO_EVENT_KB_LEDS_CYCLE_MODE, { KEY_LIGHTS_TOGGLE } },
|
2020-05-27 17:08:40 +02:00
|
|
|
// Single cycle key (white only versions)
|
2022-08-25 18:21:37 +02:00
|
|
|
{ KE_KEY, CLEVO_EVENT_KB_LEDS_CYCLE_BRIGHTNESS, { KEY_KBDILLUMTOGGLE } },
|
2020-05-27 17:08:40 +02:00
|
|
|
|
|
|
|
// Touchpad
|
|
|
|
// The weirdly named touchpad toggle key that is implemented as KEY_F21 "everywhere"
|
|
|
|
// (instead of KEY_TOUCHPAD_TOGGLE or on/off)
|
|
|
|
// Most "new" devices just provide one toggle event
|
2020-12-04 15:20:55 +01:00
|
|
|
{ KE_KEY, CLEVO_EVENT_TOUCHPAD_TOGGLE, { KEY_F21 } },
|
2020-05-27 17:08:40 +02:00
|
|
|
// Some "old" devices produces on/off events
|
2020-12-04 15:20:55 +01:00
|
|
|
{ KE_KEY, CLEVO_EVENT_TOUCHPAD_OFF, { KEY_F21 } },
|
|
|
|
{ KE_KEY, CLEVO_EVENT_TOUCHPAD_ON, { KEY_F21 } },
|
2020-05-27 17:08:40 +02:00
|
|
|
// The alternative key events (currently not used)
|
2020-12-04 15:20:55 +01:00
|
|
|
// { KE_KEY, CLEVO_EVENT_TOUCHPAD_OFF, { KEY_TOUCHPAD_OFF } },
|
|
|
|
// { KE_KEY, CLEVO_EVENT_TOUCHPAD_ON, { KEY_TOUCHPAD_ON } },
|
|
|
|
// { KE_KEY, CLEVO_EVENT_TOUCHPAD_TOGGLE, { KEY_TOUCHPAD_TOGGLE } },
|
2020-05-27 17:08:40 +02:00
|
|
|
|
2020-12-04 15:20:55 +01:00
|
|
|
// Rfkill still needed by some devices
|
|
|
|
{ KE_KEY, CLEVO_EVENT_RFKILL1, { KEY_RFKILL } },
|
|
|
|
{ KE_IGNORE, CLEVO_EVENT_RFKILL2, { KEY_RFKILL } }, // Older rfkill event
|
2020-05-27 17:08:40 +02:00
|
|
|
// Note: Volume events need to be ignored as to not interfere with built-in functionality
|
2020-12-04 15:20:55 +01:00
|
|
|
{ KE_IGNORE, 0xfa, { KEY_UNKNOWN } }, // Appears by volume up/down
|
|
|
|
{ KE_IGNORE, 0xfb, { KEY_UNKNOWN } }, // Appears by mute toggle
|
2020-05-27 17:08:40 +02:00
|
|
|
|
2020-12-04 15:20:55 +01:00
|
|
|
{ KE_END, 0 }
|
2020-05-27 17:08:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Keyboard struct
|
2022-08-24 18:42:53 +02:00
|
|
|
static struct kbd_led_state_t {
|
2022-08-18 13:52:55 +02:00
|
|
|
u8 has_mode;
|
2022-08-24 10:57:20 +02:00
|
|
|
u8 mode;
|
2020-05-27 17:08:40 +02:00
|
|
|
u8 whole_kbd_color;
|
2022-08-24 18:42:53 +02:00
|
|
|
} kbd_led_state = {
|
|
|
|
.has_mode = 1,
|
|
|
|
.mode = CLEVO_KB_MODE_DEFAULT,
|
|
|
|
.whole_kbd_color = 7,
|
2020-05-27 17:08:40 +02:00
|
|
|
};
|
|
|
|
|
2022-08-24 18:42:53 +02:00
|
|
|
static struct kbd_backlight_mode_t {
|
2020-05-27 17:08:40 +02:00
|
|
|
u8 key;
|
|
|
|
u32 value;
|
|
|
|
const char *const name;
|
2022-08-24 18:42:53 +02:00
|
|
|
} kbd_backlight_modes[] = {
|
2022-08-24 10:57:20 +02:00
|
|
|
{ .key = 0, .value = 0x00000000, .name = "CUSTOM"},
|
|
|
|
{ .key = 1, .value = 0x1002a000, .name = "BREATHE"},
|
|
|
|
{ .key = 2, .value = 0x33010000, .name = "CYCLE"},
|
|
|
|
{ .key = 3, .value = 0x80000000, .name = "DANCE"},
|
|
|
|
{ .key = 4, .value = 0xA0000000, .name = "FLASH"},
|
|
|
|
{ .key = 5, .value = 0x70000000, .name = "RANDOM_COLOR"},
|
|
|
|
{ .key = 6, .value = 0x90000000, .name = "TEMPO"},
|
|
|
|
{ .key = 7, .value = 0xB0000000, .name = "WAVE"}
|
2020-05-27 17:08:40 +02:00
|
|
|
};
|
|
|
|
|
2022-07-16 17:08:15 +02:00
|
|
|
u32 clevo_evaluate_method2(u8 cmd, u32 arg, union acpi_object **result)
|
2020-12-02 17:25:43 +01:00
|
|
|
{
|
|
|
|
if (IS_ERR_OR_NULL(active_clevo_interface)) {
|
2021-09-16 00:14:39 +02:00
|
|
|
pr_err("clevo_keyboard: no active interface while attempting cmd %02x arg %08x\n", cmd, arg);
|
2020-12-02 17:25:43 +01:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
return active_clevo_interface->method_call(cmd, arg, result);
|
|
|
|
}
|
2022-07-16 17:08:15 +02:00
|
|
|
EXPORT_SYMBOL(clevo_evaluate_method2);
|
|
|
|
|
|
|
|
u32 clevo_evaluate_method(u8 cmd, u32 arg, u32 *result)
|
|
|
|
{
|
|
|
|
u32 status = 0;
|
|
|
|
union acpi_object *out_obj;
|
|
|
|
|
|
|
|
status = clevo_evaluate_method2(cmd, arg, &out_obj);
|
|
|
|
if (status) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (out_obj->type == ACPI_TYPE_INTEGER) {
|
|
|
|
if (!IS_ERR_OR_NULL(result))
|
|
|
|
*result = (u32) out_obj->integer.value;
|
|
|
|
} else {
|
|
|
|
pr_err("return type not integer, use clevo_evaluate_method2\n");
|
|
|
|
status = -ENODATA;
|
|
|
|
}
|
|
|
|
ACPI_FREE(out_obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
2020-12-07 12:19:36 +01:00
|
|
|
EXPORT_SYMBOL(clevo_evaluate_method);
|
|
|
|
|
|
|
|
u32 clevo_get_active_interface_id(char **id_str)
|
|
|
|
{
|
2020-12-08 10:25:06 +01:00
|
|
|
if (IS_ERR_OR_NULL(active_clevo_interface))
|
2020-12-07 12:19:36 +01:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (!IS_ERR_OR_NULL(id_str))
|
|
|
|
*id_str = active_clevo_interface->string_id;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(clevo_get_active_interface_id);
|
2020-12-02 17:25:43 +01:00
|
|
|
|
2020-05-27 17:08:40 +02:00
|
|
|
static int set_enabled_cmd(u8 state)
|
|
|
|
{
|
|
|
|
u32 cmd = 0xE0000000;
|
|
|
|
TUXEDO_INFO("Set keyboard enabled to: %d\n", state);
|
|
|
|
|
|
|
|
if (state == 0) {
|
|
|
|
cmd |= 0x003001;
|
|
|
|
} else {
|
|
|
|
cmd |= 0x07F001;
|
|
|
|
}
|
|
|
|
|
2022-08-24 10:57:20 +02:00
|
|
|
return clevo_evaluate_method(CLEVO_CMD_SET_KB_LEDS, cmd, NULL);
|
2020-05-27 17:08:40 +02:00
|
|
|
}
|
|
|
|
|
2022-08-24 18:55:36 +02:00
|
|
|
static void set_next_color_whole_kb(void)
|
2020-05-27 17:08:40 +02:00
|
|
|
{
|
|
|
|
/* "Calculate" new to-be color */
|
|
|
|
u32 new_color_id;
|
|
|
|
u32 new_color_code;
|
|
|
|
|
|
|
|
new_color_id = kbd_led_state.whole_kbd_color + 1;
|
|
|
|
if (new_color_id >= color_list.size) {
|
2022-08-25 19:06:16 +02:00
|
|
|
new_color_id = 1; // Skip black
|
2020-05-27 17:08:40 +02:00
|
|
|
}
|
|
|
|
new_color_code = color_list.colors[new_color_id].code;
|
|
|
|
|
|
|
|
TUXEDO_INFO("set_next_color_whole_kb(): new_color_id: %i, new_color_code %X",
|
|
|
|
new_color_id, new_color_code);
|
|
|
|
|
|
|
|
/* Set color on all four regions*/
|
2022-08-24 10:57:20 +02:00
|
|
|
clevo_leds_set_color_extern(new_color_code);
|
2020-05-27 17:08:40 +02:00
|
|
|
kbd_led_state.whole_kbd_color = new_color_id;
|
|
|
|
}
|
|
|
|
|
2022-08-24 10:57:20 +02:00
|
|
|
static void set_kbd_backlight_mode(u8 kbd_backlight_mode)
|
2020-05-27 17:08:40 +02:00
|
|
|
{
|
2022-08-24 10:57:20 +02:00
|
|
|
TUXEDO_INFO("Set keyboard backlight mode on %s", kbd_backlight_modes[kbd_backlight_mode].name);
|
2020-05-27 17:08:40 +02:00
|
|
|
|
2022-08-24 10:57:20 +02:00
|
|
|
if (!clevo_evaluate_method(CLEVO_CMD_SET_KB_LEDS, kbd_backlight_modes[kbd_backlight_mode].value, NULL)) {
|
2020-12-04 15:20:55 +01:00
|
|
|
// method was succesfull so update ur internal state struct
|
2022-08-24 10:57:20 +02:00
|
|
|
kbd_led_state.mode = kbd_backlight_mode;
|
2020-05-27 17:08:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-24 18:55:36 +02:00
|
|
|
// Sysfs Interface for the keyboard backlight mode
|
|
|
|
static ssize_t list_kbd_backlight_modes_fs(struct device *child, struct device_attribute *attr,
|
|
|
|
char *buffer)
|
|
|
|
{
|
|
|
|
return sprintf(buffer, "%d\n", kbd_led_state.mode);
|
|
|
|
}
|
|
|
|
|
2022-08-24 10:57:20 +02:00
|
|
|
static ssize_t set_kbd_backlight_mode_fs(struct device *child,
|
2020-05-27 17:08:40 +02:00
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buffer, size_t size)
|
|
|
|
{
|
2022-08-24 10:57:20 +02:00
|
|
|
unsigned int kbd_backlight_mode;
|
2020-05-27 17:08:40 +02:00
|
|
|
|
2022-08-24 10:57:20 +02:00
|
|
|
int err = kstrtouint(buffer, 0, &kbd_backlight_mode);
|
2020-05-27 17:08:40 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2022-08-24 10:57:20 +02:00
|
|
|
kbd_backlight_mode = clamp_t(u8, kbd_backlight_mode, 0, ARRAY_SIZE(kbd_backlight_modes) - 1);
|
|
|
|
set_kbd_backlight_mode(kbd_backlight_mode);
|
2020-05-27 17:08:40 +02:00
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2022-08-24 18:55:36 +02:00
|
|
|
// Sysfs attribute file permissions and method linking
|
|
|
|
static DEVICE_ATTR(kbd_backlight_mode, 0644, list_kbd_backlight_modes_fs, set_kbd_backlight_mode_fs);
|
|
|
|
|
2022-08-24 10:57:20 +02:00
|
|
|
static int kbd_backlight_mode_id_validator(const char *value,
|
|
|
|
const struct kernel_param *kbd_backlight_mode_param)
|
2020-05-27 17:08:40 +02:00
|
|
|
{
|
2022-08-24 10:57:20 +02:00
|
|
|
int kbd_backlight_mode = 0;
|
2020-05-27 17:08:40 +02:00
|
|
|
|
2022-08-24 10:57:20 +02:00
|
|
|
if (kstrtoint(value, 10, &kbd_backlight_mode) != 0
|
|
|
|
|| kbd_backlight_mode < 0
|
|
|
|
|| kbd_backlight_mode > (ARRAY_SIZE(kbd_backlight_modes) - 1)) {
|
2020-05-27 17:08:40 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-08-24 10:57:20 +02:00
|
|
|
return param_set_int(value, kbd_backlight_mode_param);
|
2020-05-27 17:08:40 +02:00
|
|
|
}
|
|
|
|
|
2022-08-24 10:57:20 +02:00
|
|
|
static const struct kernel_param_ops param_ops_mode_ops = {
|
|
|
|
.set = kbd_backlight_mode_id_validator,
|
|
|
|
.get = param_get_int,
|
|
|
|
};
|
|
|
|
|
|
|
|
static u8 param_kbd_backlight_mode = CLEVO_KB_MODE_DEFAULT;
|
|
|
|
module_param_cb(kbd_backlight_mode, ¶m_ops_mode_ops, ¶m_kbd_backlight_mode, S_IRUSR);
|
2022-08-24 18:55:36 +02:00
|
|
|
MODULE_PARM_DESC(kbd_backlight_mode, "Set the keyboard backlight mode");
|
2022-08-24 10:57:20 +02:00
|
|
|
|
|
|
|
// TODO remove
|
2020-05-27 17:08:40 +02:00
|
|
|
static int brightness_validator(const char *value,
|
|
|
|
const struct kernel_param *brightness_param)
|
|
|
|
{
|
|
|
|
int brightness = 0;
|
|
|
|
|
|
|
|
if (kstrtoint(value, 10, &brightness) != 0
|
2022-08-24 10:57:20 +02:00
|
|
|
|| brightness < 0
|
|
|
|
|| brightness > 255) {
|
2020-05-27 17:08:40 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return param_set_int(value, brightness_param);
|
|
|
|
}
|
|
|
|
|
2022-08-24 18:42:53 +02:00
|
|
|
static void clevo_keyboard_event_callb(u32 event)
|
2020-05-27 17:08:40 +02:00
|
|
|
{
|
2020-12-04 13:14:46 +01:00
|
|
|
u32 key_event = event;
|
2020-05-27 17:08:40 +02:00
|
|
|
|
2022-08-24 10:57:20 +02:00
|
|
|
TUXEDO_DEBUG("Clevo event: %0#6x\n", event);
|
2020-05-27 17:08:40 +02:00
|
|
|
|
|
|
|
switch (key_event) {
|
2022-08-24 10:57:20 +02:00
|
|
|
case CLEVO_EVENT_KB_LEDS_CYCLE_MODE:
|
|
|
|
set_next_color_whole_kb();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2020-05-27 17:08:40 +02:00
|
|
|
}
|
|
|
|
|
2020-12-02 17:25:43 +01:00
|
|
|
if (current_driver != NULL && current_driver->input_device != NULL) {
|
2022-08-24 10:57:20 +02:00
|
|
|
if (!sparse_keymap_report_known_event(current_driver->input_device, key_event, 1, true)) {
|
|
|
|
TUXEDO_DEBUG("Unknown key - %d (%0#6x)\n", key_event, key_event);
|
2020-05-29 11:41:05 +02:00
|
|
|
}
|
2020-05-27 17:08:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-02 17:25:43 +01:00
|
|
|
static void clevo_keyboard_init_device_interface(struct platform_device *dev)
|
|
|
|
{
|
2020-05-28 18:35:46 +02:00
|
|
|
// Setup sysfs
|
2022-08-24 10:57:20 +02:00
|
|
|
if (clevo_leds_get_backlight_type() == CLEVO_KB_BACKLIGHT_TYPE_3_ZONE_RGB) {
|
|
|
|
if (device_create_file(&dev->dev, &dev_attr_kbd_backlight_mode) != 0) {
|
2022-08-18 13:52:55 +02:00
|
|
|
TUXEDO_ERROR("Sysfs attribute file creation failed for blinking pattern\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
kbd_led_state.has_mode = 1;
|
|
|
|
}
|
|
|
|
}
|
2020-12-02 17:25:43 +01:00
|
|
|
}
|
|
|
|
|
2021-09-16 00:14:39 +02:00
|
|
|
/**
|
|
|
|
* strstr version of dmi_match
|
|
|
|
*/
|
|
|
|
static bool dmi_string_in(enum dmi_field f, const char *str)
|
|
|
|
{
|
|
|
|
const char *info = dmi_get_system_info(f);
|
|
|
|
|
|
|
|
if (info == NULL || str == NULL)
|
|
|
|
return info == str;
|
|
|
|
|
|
|
|
return strstr(info, str) != NULL;
|
|
|
|
}
|
|
|
|
|
2022-08-24 18:55:36 +02:00
|
|
|
static void clevo_keyboard_init(void)
|
2021-09-16 00:14:39 +02:00
|
|
|
{
|
|
|
|
bool performance_profile_set_workaround;
|
|
|
|
|
2022-08-24 10:57:20 +02:00
|
|
|
kbd_led_state.mode = param_kbd_backlight_mode;
|
|
|
|
set_kbd_backlight_mode(kbd_led_state.mode);
|
2021-09-16 00:14:39 +02:00
|
|
|
|
2022-08-24 10:57:20 +02:00
|
|
|
clevo_evaluate_method(CLEVO_CMD_SET_EVENTS_ENABLED, 0, NULL);
|
|
|
|
set_enabled_cmd(1);
|
2021-09-16 00:14:39 +02:00
|
|
|
|
|
|
|
// Workaround for firmware issue not setting selected performance profile.
|
|
|
|
// Explicitly set "performance" perf. profile on init regardless of what is chosen
|
|
|
|
// for these devices (Aura, XP14, IBS14v5)
|
|
|
|
performance_profile_set_workaround = false
|
|
|
|
|| dmi_string_in(DMI_BOARD_NAME, "AURA1501")
|
|
|
|
|| dmi_string_in(DMI_BOARD_NAME, "EDUBOOK1502")
|
|
|
|
|| dmi_string_in(DMI_BOARD_NAME, "NL5xRU")
|
|
|
|
|| dmi_string_in(DMI_BOARD_NAME, "NV4XMB,ME,MZ")
|
|
|
|
|| dmi_string_in(DMI_BOARD_NAME, "L140CU")
|
|
|
|
|| dmi_string_in(DMI_BOARD_NAME, "NS50MU")
|
2021-10-08 20:01:00 +02:00
|
|
|
|| dmi_string_in(DMI_BOARD_NAME, "NS50_70MU")
|
2021-09-16 00:14:39 +02:00
|
|
|
|| dmi_string_in(DMI_BOARD_NAME, "PCX0DX")
|
|
|
|
|| dmi_string_in(DMI_BOARD_NAME, "PCx0Dx_GN20")
|
|
|
|
|| dmi_string_in(DMI_BOARD_NAME, "L14xMU")
|
|
|
|
;
|
|
|
|
if (performance_profile_set_workaround) {
|
|
|
|
TUXEDO_INFO("Performance profile 'performance' set workaround applied\n");
|
2022-08-24 10:57:20 +02:00
|
|
|
clevo_evaluate_method(CLEVO_CMD_OPT, 0x19000002, NULL);
|
2021-09-16 00:14:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clevo_keyboard_probe(struct platform_device *dev)
|
2020-05-27 17:08:40 +02:00
|
|
|
{
|
2022-08-24 10:57:20 +02:00
|
|
|
clevo_leds_init(dev);
|
2022-08-24 17:59:37 +02:00
|
|
|
// clevo_keyboard_init_device_interface() must come after clevo_leds_init()
|
|
|
|
// to know keyboard backlight type
|
|
|
|
clevo_keyboard_init_device_interface(dev);
|
2021-09-16 00:14:39 +02:00
|
|
|
clevo_keyboard_init();
|
|
|
|
|
2020-12-02 17:25:43 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-28 18:35:46 +02:00
|
|
|
|
2020-12-02 17:25:43 +01:00
|
|
|
static void clevo_keyboard_remove_device_interface(struct platform_device *dev)
|
|
|
|
{
|
2022-08-18 13:52:55 +02:00
|
|
|
if (kbd_led_state.has_mode == 1) {
|
2022-08-24 10:57:20 +02:00
|
|
|
device_remove_file(&dev->dev, &dev_attr_kbd_backlight_mode);
|
2020-05-28 18:35:46 +02:00
|
|
|
}
|
2020-12-02 17:25:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int clevo_keyboard_remove(struct platform_device *dev)
|
|
|
|
{
|
|
|
|
clevo_keyboard_remove_device_interface(dev);
|
2022-08-24 10:57:20 +02:00
|
|
|
clevo_leds_remove(dev);
|
2020-05-27 17:08:40 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-29 11:41:05 +02:00
|
|
|
static int clevo_keyboard_suspend(struct platform_device *dev, pm_message_t state)
|
2020-05-27 17:08:40 +02:00
|
|
|
{
|
|
|
|
// turning the keyboard off prevents default colours showing on resume
|
|
|
|
set_enabled_cmd(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-29 11:41:05 +02:00
|
|
|
static int clevo_keyboard_resume(struct platform_device *dev)
|
2020-05-27 17:08:40 +02:00
|
|
|
{
|
2022-08-24 10:57:20 +02:00
|
|
|
clevo_evaluate_method(CLEVO_CMD_SET_EVENTS_ENABLED, 0, NULL);
|
|
|
|
set_enabled_cmd(1);
|
2020-05-27 17:08:40 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver platform_driver_clevo = {
|
2020-05-29 11:41:05 +02:00
|
|
|
.remove = clevo_keyboard_remove,
|
|
|
|
.suspend = clevo_keyboard_suspend,
|
|
|
|
.resume = clevo_keyboard_resume,
|
|
|
|
.driver =
|
|
|
|
{
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
2020-05-27 17:08:40 +02:00
|
|
|
};
|
|
|
|
|
2022-08-24 18:42:53 +02:00
|
|
|
static struct tuxedo_keyboard_driver clevo_keyboard_driver = {
|
2020-12-02 17:25:43 +01:00
|
|
|
.platform_driver = &platform_driver_clevo,
|
2021-09-16 00:14:39 +02:00
|
|
|
.probe = clevo_keyboard_probe,
|
2020-12-04 15:20:55 +01:00
|
|
|
.key_map = clevo_keymap,
|
2020-12-02 17:25:43 +01:00
|
|
|
};
|
2022-07-15 14:45:51 +02:00
|
|
|
|
2022-08-24 18:42:53 +02:00
|
|
|
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);
|
|
|
|
|
2022-07-15 14:45:51 +02:00
|
|
|
#endif // CLEVO_KEYBOARD_H
|