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/>.
|
|
|
|
*/
|
2020-05-27 17:08:40 +02:00
|
|
|
#ifndef TUXEDO_KEYBOARD_COMMON_H
|
|
|
|
#define TUXEDO_KEYBOARD_COMMON_H
|
|
|
|
|
2020-05-29 16:20:02 +02:00
|
|
|
#include <linux/module.h>
|
2020-07-28 11:25:29 +02:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/acpi.h>
|
|
|
|
#include <linux/dmi.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/input.h>
|
2020-05-27 17:08:40 +02:00
|
|
|
#include <linux/input/sparse-keymap.h>
|
|
|
|
|
|
|
|
/* :::: Module specific Constants and simple Macros :::: */
|
|
|
|
#define __TUXEDO_PR(lvl, fmt, ...) do { pr_##lvl(fmt, ##__VA_ARGS__); } while (0)
|
|
|
|
#define TUXEDO_INFO(fmt, ...) __TUXEDO_PR(info, fmt, ##__VA_ARGS__)
|
|
|
|
#define TUXEDO_ERROR(fmt, ...) __TUXEDO_PR(err, fmt, ##__VA_ARGS__)
|
|
|
|
#define TUXEDO_DEBUG(fmt, ...) __TUXEDO_PR(debug, "[%s:%u] " fmt, __func__, __LINE__, ##__VA_ARGS__)
|
|
|
|
|
2020-05-29 16:20:02 +02:00
|
|
|
#ifndef DRIVER_NAME
|
|
|
|
#define DRIVER_NAME "tuxedo_keyboard"
|
|
|
|
#endif
|
|
|
|
|
2020-05-28 18:35:46 +02:00
|
|
|
struct tuxedo_keyboard_driver {
|
2020-05-29 11:41:05 +02:00
|
|
|
// Platform driver provided by driver
|
2020-05-28 18:35:46 +02:00
|
|
|
struct platform_driver *platform_driver;
|
2020-05-29 11:41:05 +02:00
|
|
|
// Probe method provided by driver
|
2020-05-28 18:35:46 +02:00
|
|
|
int (*probe)(struct platform_device *);
|
2020-05-29 11:41:05 +02:00
|
|
|
// Keymap provided by driver
|
2020-05-28 18:35:46 +02:00
|
|
|
struct key_entry *key_map;
|
2020-05-29 11:41:05 +02:00
|
|
|
// Input device reference filled in on module init after probe success
|
|
|
|
struct input_dev *input_device;
|
2020-05-28 18:35:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Global module devices
|
2020-12-02 17:25:43 +01:00
|
|
|
static struct platform_device *tuxedo_platform_device = NULL;
|
|
|
|
static struct input_dev *tuxedo_input_device = NULL;
|
2020-05-27 17:08:40 +02:00
|
|
|
|
2020-05-28 18:35:46 +02:00
|
|
|
// Currently chosen driver
|
2020-12-02 17:25:43 +01:00
|
|
|
static struct tuxedo_keyboard_driver *current_driver = NULL;
|
|
|
|
|
|
|
|
struct platform_device *tuxedo_keyboard_init_driver(struct tuxedo_keyboard_driver *tk_driver);
|
2021-09-15 17:58:06 +02:00
|
|
|
void tuxedo_keyboard_remove_driver(struct tuxedo_keyboard_driver *tk_driver);
|
2020-05-28 18:35:46 +02:00
|
|
|
|
2020-05-27 17:08:40 +02:00
|
|
|
/**
|
|
|
|
* Basically a copy of the existing report event but doesn't report unknown events
|
|
|
|
*/
|
|
|
|
bool sparse_keymap_report_known_event(struct input_dev *dev, unsigned int code,
|
|
|
|
unsigned int value, bool autorelease)
|
|
|
|
{
|
|
|
|
const struct key_entry *ke =
|
|
|
|
sparse_keymap_entry_from_scancode(dev, code);
|
|
|
|
|
|
|
|
if (ke) {
|
|
|
|
sparse_keymap_report_entry(dev, ke, value, autorelease);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-27 11:34:29 +02:00
|
|
|
struct color_t {
|
|
|
|
u32 code;
|
|
|
|
char* name;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct color_list_t {
|
|
|
|
uint size;
|
|
|
|
struct color_t colors[];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Commonly used standard colors
|
|
|
|
*/
|
|
|
|
static struct color_list_t color_list = {
|
|
|
|
.size = 8,
|
|
|
|
.colors = {
|
|
|
|
{ .name = "BLACK", .code = 0x000000 }, // 0
|
|
|
|
{ .name = "RED", .code = 0xFF0000 }, // 1
|
|
|
|
{ .name = "GREEN", .code = 0x00FF00 }, // 2
|
|
|
|
{ .name = "BLUE", .code = 0x0000FF }, // 3
|
|
|
|
{ .name = "YELLOW", .code = 0xFFFF00 }, // 4
|
|
|
|
{ .name = "MAGENTA", .code = 0xFF00FF }, // 5
|
|
|
|
{ .name = "CYAN", .code = 0x00FFFF }, // 6
|
|
|
|
{ .name = "WHITE", .code = 0xFFFFFF }, // 7
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-07-27 16:31:38 +02:00
|
|
|
/**
|
|
|
|
* Looks up a color in the color_list
|
|
|
|
*
|
2020-08-04 11:40:17 +02:00
|
|
|
* Returns found color value, or 0xffffffff if string did not match
|
2020-07-27 16:31:38 +02:00
|
|
|
*/
|
|
|
|
static u32 color_lookup(const struct color_list_t *color_list, const char *color_name)
|
|
|
|
{
|
2020-08-04 11:40:17 +02:00
|
|
|
u32 found_color = 0xffffffff;
|
2020-07-27 16:31:38 +02:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < color_list->size; ++i) {
|
|
|
|
if (strcmp(color_list->colors[i].name, color_name) == 0) {
|
|
|
|
found_color = color_list->colors[i].code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found_color;
|
|
|
|
}
|
|
|
|
|
2020-07-28 11:25:29 +02:00
|
|
|
// Common parameters
|
|
|
|
|
|
|
|
static int brightness_validator(const char *val,
|
|
|
|
const struct kernel_param *brightness_param);
|
|
|
|
static const struct kernel_param_ops param_ops_brightness_ops = {
|
|
|
|
.set = brightness_validator,
|
|
|
|
.get = param_get_int,
|
|
|
|
};
|
|
|
|
|
|
|
|
static ushort param_brightness = 0xffff; // Default unset value (higher than max)
|
|
|
|
module_param_cb(brightness, ¶m_ops_brightness_ops, ¶m_brightness,
|
|
|
|
S_IRUSR);
|
|
|
|
MODULE_PARM_DESC(brightness, "Set the Keyboard Brightness");
|
|
|
|
|
2020-07-28 13:25:08 +02:00
|
|
|
#define COLOR_STRING_LEN 20
|
|
|
|
static char param_color[COLOR_STRING_LEN];
|
|
|
|
module_param_string(color, param_color, COLOR_STRING_LEN, S_IRUSR);
|
|
|
|
MODULE_PARM_DESC(color, "Preset color for the keyboard backlight as string");
|
|
|
|
|
2020-05-27 17:08:40 +02:00
|
|
|
#endif
|