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 int (uniwill_write_ec_ram_with_retry_t)(u16, u8, int);
typedef void (uniwill_event_callb_t)(u32); typedef void (uniwill_event_callb_t)(u32);
#define UW_EC_REG_KBD_BL_STATUS 0x078c // UW_EC_REG_* known relevant EC address exposing some information or function
#define UW_EC_REG_KBD_BL_STATUS_SUBCMD_RESET 0x10 // 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_STATUS 0x078c
#define UW_EC_REG_KBD_BL_WHITE_BRIGHTNESS 0x1802 #define UW_EC_REG_KBD_BL_STATUS_BIT_WHITE_ONLY_KB 0x01
#define UW_EC_REG_KBD_BL_RGB_RED_BRIGHTNESS 0x1803 #define UW_EC_REG_KBD_BL_STATUS_SUBCMD_RESET 0x10
#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_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 { struct uniwill_interface_t {
char *string_id; char *string_id;

View file

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