2018-06-08 11:56:32 +02:00
|
|
|
/*
|
|
|
|
* tuxedo_keyboard.c
|
|
|
|
*
|
2020-04-14 12:47:05 +02:00
|
|
|
* Copyright (C) 2018-2020 TUXEDO Computers GmbH <tux@tuxedocomputers.com>
|
2018-06-08 11:56:32 +02:00
|
|
|
*
|
|
|
|
* This program 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 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2019-08-04 01:28:08 +02:00
|
|
|
#define DRIVER_NAME "tuxedo_keyboard"
|
|
|
|
#define pr_fmt(fmt) DRIVER_NAME ": " fmt
|
|
|
|
|
2018-06-08 11:56:32 +02:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/acpi.h>
|
|
|
|
#include <linux/dmi.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/input.h>
|
2019-12-19 10:34:56 +01:00
|
|
|
#include <linux/input/sparse-keymap.h>
|
2020-05-27 17:08:40 +02:00
|
|
|
#include "tuxedo_keyboard_common.h"
|
|
|
|
#include "clevo_keyboard.h"
|
2020-04-14 12:47:05 +02:00
|
|
|
|
2020-05-19 15:42:50 +02:00
|
|
|
MODULE_AUTHOR("TUXEDO Computers GmbH <tux@tuxedocomputers.com>");
|
2020-05-20 13:15:05 +02:00
|
|
|
MODULE_DESCRIPTION("TUXEDO Computers keyboard & keyboard backlight Driver");
|
2018-06-08 11:56:32 +02:00
|
|
|
MODULE_LICENSE("GPL");
|
2020-05-26 14:12:47 +02:00
|
|
|
MODULE_VERSION("2.0.4");
|
2018-06-08 11:56:32 +02:00
|
|
|
|
2020-04-14 12:47:05 +02:00
|
|
|
MODULE_ALIAS("wmi:" CLEVO_EVENT_GUID);
|
|
|
|
MODULE_ALIAS("wmi:" CLEVO_GET_GUID);
|
|
|
|
|
2020-05-27 18:04:08 +02:00
|
|
|
static int __init tuxedo_input_init(const struct key_entry key_map[])
|
2019-05-31 19:39:20 +02:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
tuxedo_input_device = input_allocate_device();
|
|
|
|
if (unlikely(!tuxedo_input_device)) {
|
|
|
|
TUXEDO_ERROR("Error allocating input device\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
tuxedo_input_device->name = "TUXEDO Keyboard";
|
|
|
|
tuxedo_input_device->phys = DRIVER_NAME "/input0";
|
|
|
|
tuxedo_input_device->id.bustype = BUS_HOST;
|
|
|
|
tuxedo_input_device->dev.parent = &tuxedo_platform_device->dev;
|
|
|
|
|
2020-05-27 18:04:08 +02:00
|
|
|
if (key_map != NULL) {
|
|
|
|
err = sparse_keymap_setup(tuxedo_input_device, key_map, NULL);
|
|
|
|
if (err) {
|
|
|
|
TUXEDO_ERROR("Failed to setup sparse keymap\n");
|
|
|
|
goto err_free_input_device;
|
|
|
|
}
|
2019-12-19 10:34:56 +01:00
|
|
|
}
|
2019-05-31 19:39:20 +02:00
|
|
|
|
|
|
|
err = input_register_device(tuxedo_input_device);
|
|
|
|
if (unlikely(err)) {
|
|
|
|
TUXEDO_ERROR("Error registering input device\n");
|
|
|
|
goto err_free_input_device;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2019-06-04 19:32:30 +02:00
|
|
|
err_free_input_device:
|
2019-05-31 19:39:20 +02:00
|
|
|
input_free_device(tuxedo_input_device);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2019-06-04 19:32:30 +02:00
|
|
|
static void __exit tuxedo_input_exit(void)
|
2019-05-31 19:39:20 +02:00
|
|
|
{
|
|
|
|
if (unlikely(!tuxedo_input_device)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_unregister_device(tuxedo_input_device);
|
|
|
|
{
|
|
|
|
tuxedo_input_device = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-04 19:32:30 +02:00
|
|
|
static int __init tuxdeo_keyboard_init(void)
|
2019-05-31 19:39:20 +02:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (!wmi_has_guid(CLEVO_EVENT_GUID)) {
|
|
|
|
TUXEDO_ERROR("No known WMI event notification GUID found\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wmi_has_guid(CLEVO_GET_GUID)) {
|
|
|
|
TUXEDO_ERROR("No known WMI control method GUID found\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
TUXEDO_INFO("Model '%s' found\n",
|
2019-06-04 19:32:30 +02:00
|
|
|
dmi_get_system_info(DMI_PRODUCT_NAME));
|
2019-05-31 19:39:20 +02:00
|
|
|
|
|
|
|
tuxedo_platform_device =
|
2020-05-27 17:08:40 +02:00
|
|
|
platform_create_bundle(&platform_driver_clevo, tuxedo_wmi_probe,
|
2019-06-04 19:32:30 +02:00
|
|
|
NULL, 0, NULL, 0);
|
2019-08-04 02:58:15 +02:00
|
|
|
|
2019-05-31 19:39:20 +02:00
|
|
|
if (unlikely(IS_ERR(tuxedo_platform_device))) {
|
|
|
|
TUXEDO_ERROR("Can not init Platform driver");
|
|
|
|
return PTR_ERR(tuxedo_platform_device);
|
|
|
|
}
|
|
|
|
|
2020-05-27 18:04:08 +02:00
|
|
|
err = tuxedo_input_init(clevo_wmi_keymap);
|
2019-05-31 19:39:20 +02:00
|
|
|
if (unlikely(err)) {
|
|
|
|
TUXEDO_ERROR("Could not register input device\n");
|
|
|
|
}
|
|
|
|
|
2019-08-04 02:58:15 +02:00
|
|
|
if (device_create_file(&tuxedo_platform_device->dev, &dev_attr_state) != 0) {
|
2019-08-04 03:30:06 +02:00
|
|
|
TUXEDO_ERROR("Sysfs attribute file creation failed for state\n");
|
2019-05-31 19:39:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (device_create_file
|
|
|
|
(&tuxedo_platform_device->dev, &dev_attr_color_left) != 0) {
|
|
|
|
TUXEDO_ERROR
|
2019-08-04 03:30:06 +02:00
|
|
|
("Sysfs attribute file creation failed for color left\n");
|
2019-05-31 19:39:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (device_create_file
|
|
|
|
(&tuxedo_platform_device->dev, &dev_attr_color_center) != 0) {
|
|
|
|
TUXEDO_ERROR
|
2019-08-04 03:30:06 +02:00
|
|
|
("Sysfs attribute file creation failed for color center\n");
|
2019-05-31 19:39:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (device_create_file
|
|
|
|
(&tuxedo_platform_device->dev, &dev_attr_color_right) != 0) {
|
|
|
|
TUXEDO_ERROR
|
2019-08-04 03:30:06 +02:00
|
|
|
("Sysfs attribute file creation failed for color right\n");
|
2019-05-31 19:39:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (set_color(REGION_EXTRA, KB_COLOR_DEFAULT) != 0) {
|
|
|
|
TUXEDO_DEBUG("Keyboard does not support EXTRA Color");
|
2019-08-18 05:59:24 +02:00
|
|
|
kbd_led_state.has_extra = 0;
|
2019-05-31 19:39:20 +02:00
|
|
|
} else {
|
2019-08-18 05:59:24 +02:00
|
|
|
kbd_led_state.has_extra = 1;
|
2019-05-31 19:39:20 +02:00
|
|
|
if (device_create_file
|
|
|
|
(&tuxedo_platform_device->dev,
|
|
|
|
&dev_attr_color_extra) != 0) {
|
|
|
|
TUXEDO_ERROR
|
2019-08-04 03:30:06 +02:00
|
|
|
("Sysfs attribute file creation failed for color extra\n");
|
2019-05-31 19:39:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
set_color(REGION_EXTRA, param_color_extra);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (device_create_file(&tuxedo_platform_device->dev, &dev_attr_extra) !=
|
|
|
|
0) {
|
|
|
|
TUXEDO_ERROR
|
2019-08-04 03:30:06 +02:00
|
|
|
("Sysfs attribute file creation failed for extra information flag\n");
|
2019-05-31 19:39:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (device_create_file(&tuxedo_platform_device->dev, &dev_attr_mode) !=
|
|
|
|
0) {
|
2019-08-04 03:30:06 +02:00
|
|
|
TUXEDO_ERROR("Sysfs attribute file creation failed for blinking pattern\n");
|
2019-05-31 19:39:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (device_create_file
|
|
|
|
(&tuxedo_platform_device->dev, &dev_attr_brightness) != 0) {
|
|
|
|
TUXEDO_ERROR
|
2019-08-04 03:30:06 +02:00
|
|
|
("Sysfs attribute file creation failed for brightness\n");
|
2019-05-31 19:39:20 +02:00
|
|
|
}
|
|
|
|
|
2019-08-18 05:59:24 +02:00
|
|
|
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;
|
2019-05-31 19:39:20 +02:00
|
|
|
|
|
|
|
set_color(REGION_LEFT, param_color_left);
|
|
|
|
set_color(REGION_CENTER, param_color_center);
|
|
|
|
set_color(REGION_RIGHT, param_color_right);
|
|
|
|
|
2019-08-04 02:33:29 +02:00
|
|
|
set_blinking_pattern(param_blinking_pattern);
|
2019-05-31 19:39:20 +02:00
|
|
|
set_brightness(param_brightness);
|
2019-08-19 06:24:32 +02:00
|
|
|
set_enabled(param_state);
|
2019-05-31 19:39:20 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-04 19:32:30 +02:00
|
|
|
static void __exit tuxdeo_keyboard_exit(void)
|
2019-05-31 19:39:20 +02:00
|
|
|
{
|
|
|
|
tuxedo_input_exit();
|
|
|
|
|
|
|
|
device_remove_file(&tuxedo_platform_device->dev, &dev_attr_state);
|
|
|
|
device_remove_file(&tuxedo_platform_device->dev, &dev_attr_color_left);
|
|
|
|
device_remove_file(&tuxedo_platform_device->dev,
|
2019-06-04 19:32:30 +02:00
|
|
|
&dev_attr_color_center);
|
2019-05-31 19:39:20 +02:00
|
|
|
device_remove_file(&tuxedo_platform_device->dev, &dev_attr_color_right);
|
|
|
|
device_remove_file(&tuxedo_platform_device->dev, &dev_attr_extra);
|
|
|
|
device_remove_file(&tuxedo_platform_device->dev, &dev_attr_mode);
|
|
|
|
device_remove_file(&tuxedo_platform_device->dev, &dev_attr_brightness);
|
|
|
|
|
2019-08-18 05:59:24 +02:00
|
|
|
if (kbd_led_state.has_extra == 1) {
|
2019-05-31 19:39:20 +02:00
|
|
|
device_remove_file(&tuxedo_platform_device->dev,
|
2019-06-04 19:32:30 +02:00
|
|
|
&dev_attr_color_extra);
|
2019-05-31 19:39:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
platform_device_unregister(tuxedo_platform_device);
|
|
|
|
|
2020-05-27 17:08:40 +02:00
|
|
|
platform_driver_unregister(&platform_driver_clevo);
|
2019-05-31 19:39:20 +02:00
|
|
|
|
|
|
|
TUXEDO_DEBUG("exit");
|
|
|
|
}
|
|
|
|
|
2018-06-08 11:56:32 +02:00
|
|
|
module_init(tuxdeo_keyboard_init);
|
|
|
|
module_exit(tuxdeo_keyboard_exit);
|