Start rework for uniwill

This commit is contained in:
Werner Sembach 2022-08-25 18:22:48 +02:00
parent 40f46087f5
commit 60cd77e01a
3 changed files with 117 additions and 120 deletions

View file

@ -120,24 +120,4 @@ static u32 color_lookup(const struct color_list_t *color_list, const char *color
return found_color;
}
// 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,
};
// TODO remove
static ushort param_brightness = 0xffff; // Default unset value (higher than max)
module_param_cb(brightness, &param_ops_brightness_ops, &param_brightness,
S_IRUSR);
MODULE_PARM_DESC(brightness, "Set the Keyboard Brightness");
#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");
#endif

View file

@ -32,14 +32,6 @@
#include <linux/version.h>
#include "uniwill_interfaces.h"
#define UNIWILL_WMI_MGMT_GUID_BA "ABBC0F6D-8EA1-11D1-00A0-C90629100000"
#define UNIWILL_WMI_MGMT_GUID_BB "ABBC0F6E-8EA1-11D1-00A0-C90629100000"
#define UNIWILL_WMI_MGMT_GUID_BC "ABBC0F6F-8EA1-11D1-00A0-C90629100000"
#define UNIWILL_WMI_EVENT_GUID_0 "ABBC0F70-8EA1-11D1-00A0-C90629100000"
#define UNIWILL_WMI_EVENT_GUID_1 "ABBC0F71-8EA1-11D1-00A0-C90629100000"
#define UNIWILL_WMI_EVENT_GUID_2 "ABBC0F72-8EA1-11D1-00A0-C90629100000"
#define UNIWILL_OSD_RADIOON 0x01A
#define UNIWILL_OSD_RADIOOFF 0x01B
#define UNIWILL_OSD_KB_LED_LEVEL0 0x03B
@ -56,21 +48,8 @@
#define UNIWILL_OSD_TOUCHPADWORKAROUND 0xFFF
#define UNIWILL_BRIGHTNESS_MIN 0x00
#define UNIWILL_BRIGHTNESS_MAX 0xc8
#define UNIWILL_BRIGHTNESS_DEFAULT UNIWILL_BRIGHTNESS_MAX * 0.30
#define UNIWILL_COLOR_DEFAULT 0xffffff
struct tuxedo_keyboard_driver uniwill_keyboard_driver;
struct kbd_led_state_uw_t {
u32 brightness;
u32 color;
} kbd_led_state_uw = {
.brightness = UNIWILL_BRIGHTNESS_DEFAULT,
.color = UNIWILL_COLOR_DEFAULT,
};
static u8 uniwill_kbd_bl_enable_state_on_start;
static bool uniwill_kbd_bl_type_rgb_single_color = true;
@ -252,63 +231,6 @@ static void uniwill_write_kbd_bl_enable(u8 enable)
uniwill_write_ec_ram(0x078c, backlight_data);
}
/*static u32 uniwill_read_kbd_bl_br_state(u8 *brightness_state)
{
u8 backlight_data;
u32 result;
uniwill_read_ec_ram(0x078c, &backlight_data);
*brightness_state = (backlight_data & 0xf0) >> 4;
result = 0;
return result;
}*/
static u32 uniwill_read_kbd_bl_rgb(u8 *red, u8 *green, u8 *blue)
{
u32 result;
uniwill_read_ec_ram(0x1803, red);
uniwill_read_ec_ram(0x1805, green);
uniwill_read_ec_ram(0x1808, blue);
result = 0;
return result;
}
static void uniwill_write_kbd_bl_rgb(u8 red, u8 green, u8 blue)
{
if (red > 0xc8) red = 0xc8;
if (green > 0xc8) green = 0xc8;
if (blue > 0xc8) blue = 0xc8;
uniwill_write_ec_ram(0x1803, red);
uniwill_write_ec_ram(0x1805, green);
uniwill_write_ec_ram(0x1808, blue);
TUXEDO_DEBUG("Wrote kbd color [%0#4x, %0#4x, %0#4x]\n", red, green, blue);
}
static void uniwill_write_kbd_bl_state(void) {
// Get single colors from state
u32 color_red = ((kbd_led_state_uw.color >> 0x10) & 0xff);
u32 color_green = (kbd_led_state_uw.color >> 0x08) & 0xff;
u32 color_blue = (kbd_led_state_uw.color >> 0x00) & 0xff;
u32 brightness_percentage = (kbd_led_state_uw.brightness * 100) / UNIWILL_BRIGHTNESS_MAX;
// Scale color values to valid range
color_red = (color_red * 0xc8) / 0xff;
color_green = (color_green * 0xc8) / 0xff;
color_blue = (color_blue * 0xc8) / 0xff;
// Scale the respective color values with brightness
color_red = (color_red * brightness_percentage) / 100;
color_green = (color_green * brightness_percentage) / 100;
color_blue = (color_blue * brightness_percentage) / 100;
uniwill_write_kbd_bl_rgb(color_red, color_green, color_blue);
}
static void uniwill_write_kbd_bl_reset(void)
{
uniwill_write_ec_ram(0x078c, 0x10);
@ -520,28 +442,6 @@ static void uw_kbd_bl_init_ready_check(struct timer_list *t)
schedule_work(&uw_kbd_bl_init_ready_check_work);
}
static struct mc_subled cdev_kb_uw_mc_subled[3] = {
{ .color_index = LED_COLOR_ID_RED,
.brightness = UNIWILL_BRIGHTNESS_DEFAULT,
.intensity = UNIWILL_BRIGHTNESS_MAX },
{ .color_index = LED_COLOR_ID_GREEN,
.brightness = UNIWILL_BRIGHTNESS_DEFAULT,
.intensity = UNIWILL_BRIGHTNESS_MAX },
{ .color_index = LED_COLOR_ID_BLUE,
.brightness = UNIWILL_BRIGHTNESS_DEFAULT,
.intensity = UNIWILL_BRIGHTNESS_MAX }
};
static struct led_classdev_mc cdev_kb_uw_mc = {
.led_cdev.name = KBUILD_MODNAME "::kbd_backlight",
.led_cdev.max_brightness = UNIWILL_BRIGHTNESS_MAX,
.led_cdev.brightness_set_blocking = &ledcdev_set_blocking_uw_mc,
.led_cdev.brightness_get = &ledcdev_get_uw,
.led_cdev.brightness = UNIWILL_BRIGHTNESS_DEFAULT,
.num_colors = 3,
.subled_info = cdev_kb_uw_mc_subled
};
static int uw_kbd_bl_init(struct platform_device *dev)
{
int status = 0;

117
src/uniwill_leds.h Normal file
View file

@ -0,0 +1,117 @@
/*!
* 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/>.
*/
#ifndef UNIWILL_LEDS_H
#define UNIWILL_LEDS_H
#include <linux/types.h>
#include <linux/platform_device.h>
#define UNIWILL_KBD_BRIGHTNESS_MIN 0x00
#define UNIWILL_KBD_BRIGHTNESS_MAX 0xff // Uniwill devices actually operate on a range
// from 0x00 - 0xc8 (200), but because
// userspace will get it wrong we do the
// conversion in driver.
#define UNIWILL_KBD_BRIGHTNESS_DEFAULT (UNIWILL_KBD_BRIGHTNESS_MAX * 0.5)
#define UNIWILL_KB_COLOR_DEFAULT_RED 0xff // Same applies as for brightness: Actuall
#define UNIWILL_KB_COLOR_DEFAULT_GREEN 0xff // range is 0x00 - 0xc8. Conversion is done in
#define UNIWILL_KB_COLOR_DEFAULT_BLUE 0xff // this driver.
#define UNIWILL_KB_COLOR_DEFAULT ((UNIWILL_KB_COLOR_DEFAULT_RED << 16) + (UNIWILL_KB_COLOR_DEFAULT_GREEN << 8) + UNIWILL_KB_COLOR_DEFAULT_BLUE)
enum uniwill_kb_backlight_types {
UNIWILL_KB_BACKLIGHT_TYPE_NONE,
UNIWILL_KB_BACKLIGHT_TYPE_FIXED_COLOR,
UNIWILL_KB_BACKLIGHT_TYPE_1_ZONE_RGB,
UNIWILL_KB_BACKLIGHT_TYPE_PER_KEY_RGB
};
int uniwill_leds_init(struct platform_device *dev);
int uniwill_leds_remove(struct platform_device *dev);
enum uniwill_kb_backlight_types uniwill_leds_get_backlight_type(void);
void uniwill_leds_set_brightness_extern(u32 brightness);
void uniwill_leds_set_color_extern(u32 color);
// TODO The following should go into a seperate .c file, but for this to work more reworking is required in the tuxedo_keyboard structure.
#include "clevo_leds.h"
#include "clevo_interfaces.h"
#include <linux/leds.h>
#include <linux/led-class-multicolor.h>
#define FF_TO_UW_RANGE(x) (x * 0xc8 / 0xff)
#define UW_TO_FF_RANGE(x) (x * 0xff / 0xc8)
static u32 uniwill_read_kbd_bl_rgb(u8 *red, u8 *green, u8 *blue)
{
u32 result;
uniwill_read_ec_ram(0x1803, red);
uniwill_read_ec_ram(0x1805, green);
uniwill_read_ec_ram(0x1808, blue);
result = 0;
return result;
}
static void uniwill_write_kbd_bl_rgb(u8 red, u8 green, u8 blue)
{
if (red > 0xc8) red = 0xc8;
if (green > 0xc8) green = 0xc8;
if (blue > 0xc8) blue = 0xc8;
uniwill_write_ec_ram(0x1803, red);
uniwill_write_ec_ram(0x1805, green);
uniwill_write_ec_ram(0x1808, blue);
TUXEDO_DEBUG("Wrote kbd color [%0#4x, %0#4x, %0#4x]\n", red, green, blue);
}
static struct mc_subled clevo_mcled_cdev_subleds[3] = {
{
.color_index = LED_COLOR_ID_RED,
.brightness = UNIWILL_KBD_BRIGHTNESS_MAX,
.intensity = UNIWILL_KB_COLOR_DEFAULT_RED,
.channel = 0
},
{
.color_index = LED_COLOR_ID_GREEN,
.brightness = UNIWILL_KBD_BRIGHTNESS_MAX,
.intensity = UNIWILL_KB_COLOR_DEFAULT_GREEN,
.channel = 0
},
{
.color_index = LED_COLOR_ID_BLUE,
.brightness = UNIWILL_KBD_BRIGHTNESS_MAX,
.intensity = UNIWILL_KB_COLOR_DEFAULT_BLUE,
.channel = 0
}
};
static struct led_classdev_mc uniwill_mcled_cdev = {
.led_cdev.name = "rgb:" LED_FUNCTION_KBD_BACKLIGHT,
.led_cdev.max_brightness = UNIWILL_KBD_BRIGHTNESS_MAX,
.led_cdev.brightness = &uniwill_leds_set_brightness_mc,
.led_cdev.brightness = UNIWILL_KBD_BRIGHTNESS_DEFAULT,
.num_colors = 3,
.subled_info = cdev_kb_uw_mc_subled
};
#endif // UNIWILL_LEDS_H