Add keyboard type detection based on EC

This commit is contained in:
Werner Sembach 2022-10-26 13:43:37 +02:00
parent 8d67160ea8
commit 099be56b62
2 changed files with 61 additions and 24 deletions

View file

@ -40,14 +40,34 @@ typedef int (uniwill_write_ec_ram_t)(u16, u8);
typedef int (uniwill_write_ec_ram_with_retry_t)(u16, u8, int);
typedef void (uniwill_event_callb_t)(u32);
#define UW_EC_REG_KBD_BL_STATUS 0x078c
#define UW_EC_REG_KBD_BL_STATUS_SUBCMD_RESET 0x10
// UW_EC_REG_* known relevant EC address exposing some information or function
// UW_EC_REG_*_BIT_* single bit from byte holding information, should be handled with bit-wise operations
// UW_EC_REG_*_VALUE_* discrete value of the whole byte with special meaning
// UW_EC_REG_*_SUBCMD_* writing this discrete value triggers special behaviour
#define UW_EC_REG_KBD_BL_MAX_BRIGHTNESS 0x1801
#define UW_EC_REG_KBD_BL_WHITE_BRIGHTNESS 0x1802
#define UW_EC_REG_KBD_BL_RGB_RED_BRIGHTNESS 0x1803
#define UW_EC_REG_KBD_BL_RGB_GREEN_BRIGHTNESS 0x1805
#define UW_EC_REG_KBD_BL_RGB_BLUE_BRIGHTNESS 0x1808
#define UW_EC_REG_KBD_BL_STATUS 0x078c
#define UW_EC_REG_KBD_BL_STATUS_BIT_WHITE_ONLY_KB 0x01
#define UW_EC_REG_KBD_BL_STATUS_SUBCMD_RESET 0x10
#define UW_EC_REG_KBD_BL_MAX_BRIGHTNESS 0x1801
#define UW_EC_REG_KBD_BL_WHITE_BRIGHTNESS 0x1802
#define UW_EC_REG_KBD_BL_RGB_RED_BRIGHTNESS 0x1803
#define UW_EC_REG_KBD_BL_RGB_GREEN_BRIGHTNESS 0x1805
#define UW_EC_REG_KBD_BL_RGB_BLUE_BRIGHTNESS 0x1808
#define UW_EC_REG_BAREBONE_ID 0x0740
#define UW_EC_REG_BAREBONE_ID_VALUE_PFxxxxx 0x09
#define UW_EC_REG_BAREBONE_ID_VALUE_PFxMxxx 0x0e
#define UW_EC_REG_BAREBONE_ID_VALUE_PH4TRX1 0x12
#define UW_EC_REG_BAREBONE_ID_VALUE_PH4TUX1 0x13
#define UW_EC_REG_BAREBONE_ID_VALUE_PH4TQx1 0x14
#define UW_EC_REG_BAREBONE_ID_VALUE_PH6TRX1 0x15
#define UW_EC_REG_BAREBONE_ID_VALUE_PH6TQxx 0x16
#define UW_EC_REG_BAREBONE_ID_VALUE_PH4Axxx 0x17
#define UW_EC_REG_FEATURES_0 0x0765
#define UW_EC_REG_FEATURES_1 0x0766
#define UW_EC_REG_FEATURES_1_BIT_1_ZONE_RGB_KB 0x04
struct uniwill_interface_t {
char *string_id;

View file

@ -56,7 +56,7 @@ void uniwill_leds_set_color_extern(u32 color);
#include <linux/led-class-multicolor.h>
static enum uniwill_kb_backlight_types uniwill_kb_backlight_type = UNIWILL_KB_BACKLIGHT_TYPE_FIXED_COLOR;
static enum uniwill_kb_backlight_types uniwill_kb_backlight_type = UNIWILL_KB_BACKLIGHT_TYPE_NONE;
static bool uw_leds_initialized = false;
//static DECLARE_COMPLETION(init_done);
@ -157,23 +157,40 @@ int uniwill_leds_init_early(struct platform_device *dev)
{
// FIXME Use mutexes
int ret;
u8 data;
if ( dmi_match(DMI_BOARD_NAME, "POLARIS1501A1650TI")
|| dmi_match(DMI_BOARD_NAME, "POLARIS1501A2060")
|| dmi_match(DMI_BOARD_NAME, "POLARIS1501I1650TI")
|| dmi_match(DMI_BOARD_NAME, "POLARIS1501I2060")
|| dmi_match(DMI_BOARD_NAME, "POLARIS1701A1650TI")
|| dmi_match(DMI_BOARD_NAME, "POLARIS1701A2060")
|| dmi_match(DMI_BOARD_NAME, "POLARIS1701I1650TI")
|| dmi_match(DMI_BOARD_NAME, "POLARIS1701I2060")
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0)
|| dmi_match(DMI_PRODUCT_SKU, "POLARIS1XA02")
|| dmi_match(DMI_PRODUCT_SKU, "POLARIS1XI02")
|| dmi_match(DMI_PRODUCT_SKU, "POLARIS1XA03")
|| dmi_match(DMI_PRODUCT_SKU, "POLARIS1XI03")
#endif
) {
uniwill_kb_backlight_type = UNIWILL_KB_BACKLIGHT_TYPE_1_ZONE_RGB;
ret = uniwill_read_ec_ram(UW_EC_REG_BAREBONE_ID, &data);
if (ret) {
pr_err("Reading barebone ID failed.\n");
return ret;
}
if (data == UW_EC_REG_BAREBONE_ID_VALUE_PFxxxxx ||
data == UW_EC_REG_BAREBONE_ID_VALUE_PFxMxxx ||
data == UW_EC_REG_BAREBONE_ID_VALUE_PH4TRX1 ||
data == UW_EC_REG_BAREBONE_ID_VALUE_PH4TUX1 ||
data == UW_EC_REG_BAREBONE_ID_VALUE_PH4TQx1 ||
data == UW_EC_REG_BAREBONE_ID_VALUE_PH6TRX1 ||
data == UW_EC_REG_BAREBONE_ID_VALUE_PH6TQxx ||
data == UW_EC_REG_BAREBONE_ID_VALUE_PH4Axxx) {
ret = uniwill_read_ec_ram(UW_EC_REG_KBD_BL_STATUS, &data);
if (ret) {
pr_err("Reading keyboard backlight status failed.\n");
return ret;
}
if (data & UW_EC_REG_KBD_BL_STATUS_BIT_WHITE_ONLY_KB) {
uniwill_kb_backlight_type = UNIWILL_KB_BACKLIGHT_TYPE_FIXED_COLOR;
}
}
else {
ret = uniwill_read_ec_ram(UW_EC_REG_FEATURES_1, &data);
if (ret) {
pr_err("Reading features 1 failed.\n");
return ret;
}
if (data & UW_EC_REG_FEATURES_1_BIT_1_ZONE_RGB_KB) {
uniwill_kb_backlight_type = UNIWILL_KB_BACKLIGHT_TYPE_1_ZONE_RGB;
}
}
pr_debug("Keyboard backlight type: 0x%02x\n", uniwill_kb_backlight_type);