Skip to contentSkip to conversation

platform/x86: uniwill-laptop: Support additional features

PATCH In review Armin Wolf 3 participants 25 messages May 30 – Jul 9

Subsystems (3)
lore
Share & tools
lore

Armin Wolf

author maintainer
#0 lore raw

cover platform/x86: uniwill-laptop: Support additional features

This patch series adds support for various new features to the uniwill-laptop driver. The first patch adds support for the keyboard backlight available on some models, while the next three patches add support for additional WMI events, USB powershare and AC auto boot. The last four patches finally add support for additional devices.

The patch series depends on commit b1a9b7a904af ("leds: Introduce the multi_max_intensity sysfs attribute") currently sitting inside the for-leds-next branch of the LED subsystem
tree. Without said commit the first patch will apply but not build.

All patches have been tested on my Tuxedo InfinityBook Pro 15 Gen 10 AMD and most work flawlessly, only the AC auto boot feature seems to be broken on my device. I decided to still include the patch because it works on other devices.

Armin Wolf (7):
platform/x86: uniwill-laptop: Add keyboard backlight support platform/x86: uniwill-laptop: Handle screen-related events platform/x86: uniwill-laptop: Add AC auto boot support platform/x86: uniwill-laptop: Add support for USB powershare platform/x86: uniwill-laptop: Add support for the MACHENIKE L16 Pro platform/x86: uniwill-laptop: Add support for the AiStone X4SP4NAL platform/x86: uniwill-laptop: Add lightbar support for LAPQC71A/B

 .../ABI/testing/sysfs-driver-uniwill-laptop   |  25 +
 .../admin-guide/laptops/uniwill-laptop.rst    |  27 +
 drivers/platform/x86/uniwill/uniwill-acpi.c   | 609 +++++++++++++++++-
 drivers/platform/x86/uniwill/uniwill-wmi.h    |   2 +
 4 files changed, 650 insertions(+), 13 deletions(-)
Signature · 1 line
2.39.5
author maintainer
#1 lore raw

PATCH 1/7 platform/x86: uniwill-laptop: Add keyboard backlight support

Many Uniwill-based devices support either a white-only or fully features RGB keyboard backlight. Add support for this feature and handle the associated WMI events.

---
 .../admin-guide/laptops/uniwill-laptop.rst    |  13 +
 drivers/platform/x86/uniwill/uniwill-acpi.c   | 392 +++++++++++++++++-
 2 files changed, 397 insertions(+), 8 deletions(-)
Documentation/admin-guide/laptops/uniwill-laptop.rst +13 -0
index 24b41dbab886..2b1e5da703a5 100644
@@ -77,6 +77,19 @@ LED class device. The default name of this LED class device is ``uniwill:multico
 See Documentation/ABI/testing/sysfs-driver-uniwill-laptop for details on how to control the various
 animation modes of the lightbar.
 
+Keyboard Backlight
+------------------
+
+The ``uniwill-laptop`` driver supports controlling the keyboard backlight using the standard
+LED class interface. The default name of this LED class device is ``uniwill:white:kbd_backlight``
+when the keyboard backlight supports only a single color, or ``uniwill:multicolor:kbd_backlight``
+when the keyboard backlight supports RGB colors. The maximum intensity for each color channel
+in RGB mode is 50.
+
+Keep in mind that due to hardware design choices, the driver does not support the RGB value
+``0x000000`` (black), instead it will fall back to ``0x010101`` (faint white). In order to
+disable the keyboard backlight, the standard LED brightness setting has to be used instead.
+
 Configurable TGP
 ----------------
 
drivers/platform/x86/uniwill/uniwill-acpi.c +384 -8

538 lines not on this page · raw message

Signature · 1 line
2.39.5
#2 lore raw

Re: [PATCH 1/7] platform/x86: uniwill-laptop: Add keyboard backlight support

Hi,

Am 30.05.26 um 19:08 schrieb Armin Wolf:

Quoted 440 lines

Many Uniwill-based devices support either a white-only or fully features RGB keyboard backlight. Add support for this feature and handle the associated WMI events.

---
  .../admin-guide/laptops/uniwill-laptop.rst    |  13 +
  drivers/platform/x86/uniwill/uniwill-acpi.c   | 392 +++++++++++++++++-
  2 files changed, 397 insertions(+), 8 deletions(-)
Documentation/admin-guide/laptops/uniwill-laptop.rst +13 -0
index 24b41dbab886..2b1e5da703a5 100644
@@ -77,6 +77,19 @@ LED class device. The default name of this LED class device is ``uniwill:multico
  See Documentation/ABI/testing/sysfs-driver-uniwill-laptop for details on how to control the various
  animation modes of the lightbar.
 
+Keyboard Backlight
+------------------
+
+The ``uniwill-laptop`` driver supports controlling the keyboard backlight using the standard
+LED class interface. The default name of this LED class device is ``uniwill:white:kbd_backlight``
+when the keyboard backlight supports only a single color, or ``uniwill:multicolor:kbd_backlight``
+when the keyboard backlight supports RGB colors. The maximum intensity for each color channel
+in RGB mode is 50.
+
+Keep in mind that due to hardware design choices, the driver does not support the RGB value
+``0x000000`` (black), instead it will fall back to ``0x010101`` (faint white). In order to
+disable the keyboard backlight, the standard LED brightness setting has to be used instead.
+
  Configurable TGP
  ----------------
 
drivers/platform/x86/uniwill/uniwill-acpi.c +291 -8
index ab063ead45b9..fd040197b189 100644
@@ -110,8 +110,31 @@
  #define EC_ADDR_BAT_CYCLE_COUNT_2	0x04A7
 
  #define EC_ADDR_PROJECT_ID		0x0740
+#define PROJECT_ID_NONE			0x00
+#define PROJECT_ID_GI			0x01
+#define PROJECT_ID_GJ			0x02
+#define PROJECT_ID_GK			0x03
+#define PROJECT_ID_GICN			0x04
+#define PROJECT_ID_GJCN			0x05
+#define PROJECT_ID_GK5CN_X		0x06
+#define PROJECT_ID_GK7CN_S		0x07
+#define PROJECT_ID_GK7CPCS_GK5CQ7Z	0x08
+#define PROJECT_ID_PF			0x09
+#define PROJECT_ID_GK5CP_4X_5X_6X	0x0A
+#define PROJECT_ID_IDP			0x0B
+#define PROJECT_ID_IDY_6Y		0x0C
+#define PROJECT_ID_IDY_7Y		0x0D
+#define PROJECT_ID_PF4MU_PF4MN_PF5MU	0x0E
+#define PROJECT_ID_CML_GAMING		0x0F
+#define PROJECT_ID_GK7NXXR		0x10
+#define PROJECT_ID_GM5MU1Y		0x11
  #define PROJECT_ID_PH4TRX1		0x12
+#define PROJECT_ID_PH4TUX1		0x13
+#define PROJECT_ID_PH4TQX1		0x14
  #define PROJECT_ID_PH6TRX1		0x15
+#define PROJECT_ID_PH6TQXX		0x16
+#define PROJECT_ID_PHXAXXX		0x17
+#define PROJECT_ID_PHXPXXX		0x18
 
  #define EC_ADDR_AP_OEM			0x0741
  #define	ENABLE_MANUAL_CTRL		BIT(0)
@@ -214,6 +237,7 @@
  #define FAN_TABLE_OFFICE_MODE		BIT(2)
  #define FAN_V3				BIT(3)
  #define DEFAULT_MODE			BIT(4)
+#define ENABLE_CHINA_MODE		BIT(6)
 
  #define EC_ADDR_PL1_SETTING		0x0783
 
@@ -225,11 +249,11 @@
  #define FAN_CURVE_LENGTH		5
 
  #define EC_ADDR_KBD_STATUS		0x078C
-#define KBD_WHITE_ONLY			BIT(0)	// ~single color
-#define KBD_SINGLE_COLOR_OFF		BIT(1)
+#define KBD_WHITE_ONLY			BIT(0)
+#define KBD_POWER_OFF			BIT(1)
  #define KBD_TURBO_LEVEL_MASK		GENMASK(3, 2)
  #define KBD_APPLY			BIT(4)
-#define KBD_BRIGHTNESS			GENMASK(7, 5)
+#define KBD_BRIGHTNESS_MASK		GENMASK(7, 5)
 
  #define EC_ADDR_FAN_CTRL		0x078E
  #define FAN3P5				BIT(1)
@@ -320,6 +344,9 @@
  #define LED_CHANNELS		3
  #define LED_MAX_BRIGHTNESS	200
 
+#define KBD_LED_CHANNELS	3
+#define KBD_LED_MAX_INTENSITY	50
+
  #define UNIWILL_FEATURE_FN_LOCK			BIT(0)
  #define UNIWILL_FEATURE_SUPER_KEY		BIT(1)
  #define UNIWILL_FEATURE_TOUCHPAD_TOGGLE		BIT(2)
@@ -333,6 +360,7 @@
  #define UNIWILL_FEATURE_SECONDARY_FAN		BIT(9)
  #define UNIWILL_FEATURE_NVIDIA_CTGP_CONTROL	BIT(10)
  #define UNIWILL_FEATURE_USB_C_POWER_PRIORITY	BIT(11)
+#define UNIWILL_FEATURE_KEYBOARD_BACKLIGHT	BIT(12)
 
  enum usb_c_power_priority_options {
  	USB_C_POWER_PRIORITY_CHARGING = 0,
@@ -344,6 +372,7 @@ struct uniwill_data {
  	acpi_handle handle;
  	struct regmap *regmap;
  	unsigned int features;
+	u8 project_id;
  	struct acpi_battery_hook hook;
  	struct mutex battery_lock;	/* Protects the list of currently registered batteries */
  	union {
@@ -362,6 +391,18 @@ struct uniwill_data {
  	struct mutex led_lock;		/* Protects writes to the lightbar registers */
  	struct led_classdev_mc led_mc_cdev;
  	struct mc_subled led_mc_subled_info[LED_CHANNELS];
+	bool single_color_kbd;
+	u8 kbd_led_max_brightness;
+	unsigned int last_kbd_status;
+	union {
+		struct {
+			/* Protects writes to the RGB keyboard backlight registers */
+			struct mutex kbd_rgb_led_lock;
+			struct led_classdev_mc kbd_led_mc_cdev;
+			struct mc_subled kbd_led_mc_subled_info[KBD_LED_CHANNELS];
+		};
+		struct led_classdev kbd_led_cdev;
+	};
  	struct mutex input_lock;	/* Protects input sequence during notify */
  	struct input_dev *input_device;
  	struct notifier_block nb;
@@ -376,6 +417,7 @@ struct uniwill_battery_entry {
 
  struct uniwill_device_descriptor {
  	unsigned int features;
+	u8 kbd_led_max_brightness;
  	/* Executed during driver probing */
  	int (*probe)(struct uniwill_data *data);
  };
@@ -427,6 +469,9 @@ static const struct key_entry uniwill_keymap[] = {
  	{ KE_KEY,       UNIWILL_OSD_KBDILLUMDOWN,               { KEY_KBDILLUMDOWN }},
  	{ KE_KEY,       UNIWILL_OSD_KBDILLUMUP,                 { KEY_KBDILLUMUP }},
 
+	/* Reported when the EC changed the keyboard backlight brightness */
+	{ KE_IGNORE,	UNIWILL_OSD_BACKLIGHT_LEVEL_CHANGE,	{ KEY_UNKNOWN }},
+
  	/* Reported when the user wants to toggle the microphone mute status */
  	{ KE_KEY,       UNIWILL_OSD_MIC_MUTE,                   { KEY_MICMUTE }},
 
@@ -435,11 +480,6 @@ static const struct key_entry uniwill_keymap[] = {
 
  	/* Reported when the user wants to toggle the brightness of the keyboard */
  	{ KE_KEY,       UNIWILL_OSD_KBDILLUMTOGGLE,             { KEY_KBDILLUMTOGGLE }},
-	{ KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL0,              { KEY_KBDILLUMTOGGLE }},
-	{ KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL1,              { KEY_KBDILLUMTOGGLE }},
-	{ KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL2,              { KEY_KBDILLUMTOGGLE }},
-	{ KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL3,              { KEY_KBDILLUMTOGGLE }},
-	{ KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL4,              { KEY_KBDILLUMTOGGLE }},
 
  	/* FIXME: find out the exact meaning of those events */
  	{ KE_IGNORE,    UNIWILL_OSD_BAT_CHARGE_FULL_24_H,       { KEY_UNKNOWN }},
@@ -547,6 +587,11 @@ static bool uniwill_writeable_reg(struct device *dev, unsigned int reg)
  	case EC_ADDR_LIGHTBAR_AC_BLUE:
  	case EC_ADDR_BIOS_OEM:
  	case EC_ADDR_TRIGGER:
+	case EC_ADDR_RGB_RED:
+	case EC_ADDR_RGB_GREEN:
+	case EC_ADDR_RGB_BLUE:
+	case EC_ADDR_BIOS_OEM_2:
+	case EC_ADDR_KBD_STATUS:
  	case EC_ADDR_OEM_4:
  	case EC_ADDR_CHARGE_CTRL:
  	case EC_ADDR_LIGHTBAR_BAT_CTRL:
@@ -583,8 +628,14 @@ static bool uniwill_readable_reg(struct device *dev, unsigned int reg)
  	case EC_ADDR_BIOS_OEM:
  	case EC_ADDR_PWM_1:
  	case EC_ADDR_PWM_2:
+	case EC_ADDR_SUPPORT_2:
  	case EC_ADDR_TRIGGER:
  	case EC_ADDR_SWITCH_STATUS:
+	case EC_ADDR_RGB_RED:
+	case EC_ADDR_RGB_GREEN:
+	case EC_ADDR_RGB_BLUE:
+	case EC_ADDR_BIOS_OEM_2:
+	case EC_ADDR_KBD_STATUS:
  	case EC_ADDR_OEM_4:
  	case EC_ADDR_CHARGE_CTRL:
  	case EC_ADDR_LIGHTBAR_BAT_CTRL:
@@ -616,8 +667,10 @@ static bool uniwill_volatile_reg(struct device *dev, unsigned int reg)
  	case EC_ADDR_BIOS_OEM:
  	case EC_ADDR_PWM_1:
  	case EC_ADDR_PWM_2:
+	case EC_ADDR_SUPPORT_2:
  	case EC_ADDR_TRIGGER:
  	case EC_ADDR_SWITCH_STATUS:
+	case EC_ADDR_KBD_STATUS:
  	case EC_ADDR_OEM_4:
  	case EC_ADDR_CHARGE_CTRL:
  	case EC_ADDR_USB_C_POWER_PRIORITY:
@@ -1441,6 +1494,246 @@ static int uniwill_led_init(struct uniwill_data *data)
  							 &init_data);
  }
 
+static int uniwill_notify_kbd_led(struct uniwill_data *data, int brightness)
+{
+	struct led_classdev *led_cdev;
+	int ret;
+
+	if (data->single_color_kbd)
+		led_cdev = &data->kbd_led_cdev;
+	else
+		led_cdev = &data->kbd_led_mc_cdev.led_cdev;
+
+	guard(mutex)(&led_cdev->led_access);
+
+	/* Sync the LED brightness with the actual hardware state */
+	ret = led_update_brightness(led_cdev);
+	if (ret < 0)
+		return ret;
+
+	led_classdev_notify_brightness_hw_changed(led_cdev, brightness);
+
+	return 0;
+}
+
+#define KBD_LED_MASK	(KBD_BRIGHTNESS_MASK | KBD_APPLY | KBD_POWER_OFF)
+
+static int uniwill_kbd_led_write_brightness(struct uniwill_data *data, int brightness)
+{
+	/* KBD_POWER_OFF is always implicitly cleared */
+	unsigned int regval = FIELD_PREP(KBD_BRIGHTNESS_MASK, brightness) | KBD_APPLY;
+
+	/* We must ensure that the "apply" bit is always written */
+	return regmap_write_bits(data->regmap, EC_ADDR_KBD_STATUS, KBD_LED_MASK, regval);
+}
+
+static int uniwill_kbd_led_read_brightness(struct uniwill_data *data)
+{
+	unsigned int regval;
+	int ret;
+
+	ret = regmap_read(data->regmap, EC_ADDR_KBD_STATUS, &regval);
+	if (ret < 0)
+		return ret;
+
+	return min(FIELD_GET(KBD_BRIGHTNESS_MASK, regval), data->kbd_led_max_brightness);
+}
+
+static int uniwill_kbd_led_brightness_set(struct led_classdev *led_cdev,
+					  enum led_brightness brightness)
+{
+	struct uniwill_data *data = container_of(led_cdev, struct uniwill_data, kbd_led_cdev);
+
+	return uniwill_kbd_led_write_brightness(data, brightness);
+}
+
+static enum led_brightness uniwill_kbd_led_brightness_get(struct led_classdev *led_cdev)
+{
+	struct uniwill_data *data = container_of(led_cdev, struct uniwill_data, kbd_led_cdev);
+
+	return uniwill_kbd_led_read_brightness(data);
+}
+
+static const unsigned int uniwill_kbd_led_channel_to_reg[KBD_LED_CHANNELS] = {
+	EC_ADDR_RGB_RED,
+	EC_ADDR_RGB_GREEN,
+	EC_ADDR_RGB_BLUE,
+};
+
+static int uniwill_kbd_led_mc_brightness_set(struct led_classdev *led_cdev,
+					     enum led_brightness brightness)
+{
+	struct led_classdev_mc *led_mc_cdev = lcdev_to_mccdev(led_cdev);
+	struct uniwill_data *data = container_of(led_mc_cdev, struct uniwill_data, kbd_led_mc_cdev);
+	unsigned int min_intensity = 0;
+	unsigned int regval;
+	int ret;
+
+	guard(mutex)(&data->kbd_rgb_led_lock);
+
+	/*
+	 * The EC interprets a RGB value of 0x000000 as a command to restore
+	 * the device-specfic default RGB value. Work around this by writing
+	 * a RGB value of 0x010101 (faint white) instead.
+	 */
+	if (data->kbd_led_mc_subled_info[0].intensity == 0 &&
+	    data->kbd_led_mc_subled_info[1].intensity == 0 &&
+	    data->kbd_led_mc_subled_info[2].intensity == 0)
+		min_intensity = 1;
+
+	for (int i = 0; i < KBD_LED_CHANNELS; i++) {
+		regval = max(data->kbd_led_mc_subled_info[i].intensity, min_intensity);
+		ret = regmap_write(data->regmap, uniwill_kbd_led_channel_to_reg[i], regval);
+		if (ret < 0)
+			return ret;
+	}
+
+	ret = regmap_write_bits(data->regmap, EC_ADDR_TRIGGER, RGB_APPLY_COLOR, RGB_APPLY_COLOR);
+	if (ret < 0)
+		return ret;
+
+	return uniwill_kbd_led_write_brightness(data, brightness);
+}
+
+static enum led_brightness uniwill_kbd_led_mc_brightness_get(struct led_classdev *led_cdev)
+{
+	struct led_classdev_mc *led_mc_cdev = lcdev_to_mccdev(led_cdev);
+	struct uniwill_data *data = container_of(led_mc_cdev, struct uniwill_data, kbd_led_mc_cdev);
+
+	return uniwill_kbd_led_read_brightness(data);
+}
+
+static int uniwill_kbd_led_init(struct uniwill_data *data)
+{
+	unsigned int color_indices[KBD_LED_CHANNELS] = {
+		LED_COLOR_ID_RED,
+		LED_COLOR_ID_GREEN,
+		LED_COLOR_ID_BLUE,
+	};
+	struct led_init_data init_data = {
+		.devicename = DRIVER_NAME,
+		.devname_mandatory = true,
+	};
+	bool intensity_all_zeros = true;
+	bool needs_trigger = false;
+	unsigned int regval;
+	int ret;
+
+	if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+		return 0;
+
+	ret = regmap_read(data->regmap, EC_ADDR_SUPPORT_2, &regval);
+	if (ret < 0)
+		return ret;
+
+	if (!(regval & CHINA_MODE)) {
+		ret = regmap_set_bits(data->regmap, EC_ADDR_BIOS_OEM_2, ENABLE_CHINA_MODE);
+		if (ret < 0)
+			return ret;
+	}
+
+	ret = regmap_read(data->regmap, EC_ADDR_KBD_STATUS, &regval);
+	if (ret < 0)
+		return ret;
+
+	regval |= KBD_APPLY;
+	regval &= ~KBD_POWER_OFF;
+	ret = regmap_write(data->regmap, EC_ADDR_KBD_STATUS, regval);
+	if (ret < 0)
+		return ret;
+
+	switch (data->project_id) {
+	case PROJECT_ID_PF:
+	case PROJECT_ID_PF4MU_PF4MN_PF5MU:
+	case PROJECT_ID_PH4TRX1:
+	case PROJECT_ID_PH4TUX1:
+	case PROJECT_ID_PH4TQX1:
+	case PROJECT_ID_PH6TRX1:
+	case PROJECT_ID_PH6TQXX:
+	case PROJECT_ID_PHXAXXX:
+	case PROJECT_ID_PHXPXXX:
+		data->single_color_kbd = true;
+		break;
+	default:
+		data->single_color_kbd = regval & KBD_WHITE_ONLY;
+		break;
+	}
+
+	if (data->single_color_kbd) {
+		init_data.default_label = "white:" LED_FUNCTION_KBD_BACKLIGHT;
+		data->kbd_led_cdev.max_brightness = data->kbd_led_max_brightness;
+		data->kbd_led_cdev.color = LED_COLOR_ID_WHITE;
+		data->kbd_led_cdev.flags = LED_BRIGHT_HW_CHANGED | LED_REJECT_NAME_CONFLICT;
+		data->kbd_led_cdev.brightness_set_blocking = uniwill_kbd_led_brightness_set;
+		data->kbd_led_cdev.brightness_get = uniwill_kbd_led_brightness_get;
+
+		return devm_led_classdev_register_ext(data->dev, &data->kbd_led_cdev, &init_data);
+	}
+
+	for (int i = 0; i < KBD_LED_CHANNELS; i++) {
+		data->kbd_led_mc_subled_info[i].color_index = color_indices[i];
+
+		ret = regmap_read(data->regmap, uniwill_kbd_led_channel_to_reg[i], &regval);
+		if (ret < 0)
+			return ret;
+
+		/*
+		 * Make sure that the initial intensity value is not greater than
+		 * the maximum intensity.
+		 */
+		if (regval > KBD_LED_MAX_INTENSITY) {
+			regval = KBD_LED_MAX_INTENSITY;
+			ret = regmap_write(data->regmap, uniwill_kbd_led_channel_to_reg[i], regval);
+			if (ret < 0)
+				return ret;
+
+			needs_trigger = true;
+		}
+
+		if (regval)
+			intensity_all_zeros = false;
+
+		data->kbd_led_mc_subled_info[i].intensity = regval;
+		data->kbd_led_mc_subled_info[i].max_intensity = KBD_LED_MAX_INTENSITY;
+		data->kbd_led_mc_subled_info[i].channel = i;
+	}
+
+	/* See uniwill_kbd_led_mc_brightness_set() for an explaination. */
+	if (intensity_all_zeros) {
+		for (int i = 0; i < KBD_LED_CHANNELS; i++) {
+			data->kbd_led_mc_subled_info[i].intensity = 1;
+			ret = regmap_write(data->regmap, uniwill_kbd_led_channel_to_reg[i], 1);
+			if (ret < 0)
+				return ret;
+		}
+
+		needs_trigger = true;
+	}
+
+	if (needs_trigger) {
+		ret = regmap_write_bits(data->regmap, EC_ADDR_TRIGGER, RGB_APPLY_COLOR,
+					RGB_APPLY_COLOR);
+		if (ret < 0)
+			return ret;
+	}
+
+	ret = devm_mutex_init(data->dev, &data->kbd_rgb_led_lock);
+	if (ret < 0)
+		return ret;
+
+	init_data.default_label = "multicolor:" LED_FUNCTION_KBD_BACKLIGHT;
+	data->kbd_led_mc_cdev.led_cdev.max_brightness = data->kbd_led_max_brightness;
+	data->kbd_led_mc_cdev.led_cdev.color = LED_COLOR_ID_MULTI;

drivers/platform/x86/uniwill/uniwill-acpi.c static int uniwill_led_init(struct uniwill_data *data) · line 1736

Quoted 10 lines
drivers/platform/x86/uniwill/uniwill-acpi.c +10 -0
+	data->kbd_led_mc_cdev.led_cdev.flags = LED_BRIGHT_HW_CHANGED | LED_REJECT_NAME_CONFLICT;
+	data->kbd_led_mc_cdev.led_cdev.brightness_set_blocking = uniwill_kbd_led_mc_brightness_set;
+	data->kbd_led_mc_cdev.led_cdev.brightness_get = uniwill_kbd_led_mc_brightness_get;
+	data->kbd_led_mc_cdev.subled_info = data->kbd_led_mc_subled_info;
+	data->kbd_led_mc_cdev.num_colors = KBD_LED_CHANNELS;
+
+	return devm_led_classdev_multicolor_register_ext(data->dev, &data->kbd_led_mc_cdev,
+							 &init_data);
+}
+

Sorry I know I'm way to late with my comment, but I'm not at all a fan of how complex this whole function is:

- When we have to set max brightness on a per device basis anyway, we can also set rgb or white only there and can skip this whole detection mechanism with the supported bits that are unreliable anyway

- we have a 2nd "supported devices/features list" inside this function which is abstracting away from the actual supported feature list

Should i try to spin up something much simpler, but that requires explicit setting in the device descriptor?

Best regards

Werner

Quoted 149 lines
drivers/platform/x86/uniwill/uniwill-acpi.c +83 -0
  static unsigned int uniwill_sanitize_battery_threshold(unsigned int value)
  {
  	/* 0 means "charging threshold not active" */
@@ -1789,6 +2082,31 @@ static int uniwill_notifier_call(struct notifier_block *nb, unsigned long action
  		sysfs_notify(&data->dev->kobj, NULL, "fn_lock");
 
  		return NOTIFY_OK;
+	case UNIWILL_OSD_KB_LED_LEVEL0:
+		if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+			return NOTIFY_DONE;
+
+		return notifier_from_errno(uniwill_notify_kbd_led(data, 0));
+	case UNIWILL_OSD_KB_LED_LEVEL1:
+		if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+			return NOTIFY_DONE;
+
+		return notifier_from_errno(uniwill_notify_kbd_led(data, 1));
+	case UNIWILL_OSD_KB_LED_LEVEL2:
+		if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+			return NOTIFY_DONE;
+
+		return notifier_from_errno(uniwill_notify_kbd_led(data, 2));
+	case UNIWILL_OSD_KB_LED_LEVEL3:
+		if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+			return NOTIFY_DONE;
+
+		return notifier_from_errno(uniwill_notify_kbd_led(data, 3));
+	case UNIWILL_OSD_KB_LED_LEVEL4:
+		if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+			return NOTIFY_DONE;
+
+		return notifier_from_errno(uniwill_notify_kbd_led(data, 4));
  	default:
  		mutex_lock(&data->input_lock);
  		sparse_keymap_report_event(data->input_device, action, 1, true);
@@ -1842,6 +2160,7 @@ static int uniwill_ec_init(struct uniwill_data *data)
  	if (ret < 0)
  		return ret;
 
+	data->project_id = value;
  	dev_dbg(data->dev, "Project ID: %u\n", value);
 
  	ret = regmap_set_bits(data->regmap, EC_ADDR_AP_OEM, ENABLE_MANUAL_CTRL);
@@ -1885,6 +2204,7 @@ static int uniwill_probe(struct platform_device *pdev)
  		return ret;
 
  	data->features = device_descriptor.features;
+	data->kbd_led_max_brightness = device_descriptor.kbd_led_max_brightness;
 
  	/*
  	 * Some devices might need to perform some device-specific initialization steps
@@ -1905,6 +2225,10 @@ static int uniwill_probe(struct platform_device *pdev)
  	if (ret < 0)
  		return ret;
 
+	ret = uniwill_kbd_led_init(data);
+	if (ret < 0)
+		return ret;
+
  	ret = uniwill_hwmon_init(data);
  	if (ret < 0)
  		return ret;
@@ -1976,6 +2300,31 @@ static int uniwill_suspend_battery(struct uniwill_data *data)
  	return regmap_read(data->regmap, EC_ADDR_CHARGE_CTRL, &data->last_charge_ctrl);
  }
 
+static int uniwill_suspend_kbd_led(struct uniwill_data *data)
+{
+	unsigned int regval;
+	int ret;
+
+	if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+		return 0;
+
+	ret = regmap_read(data->regmap, EC_ADDR_KBD_STATUS, &regval);
+	if (ret < 0)
+		return ret;
+
+	/*
+	 * Save the current keyboard backlight settings in order to restore them
+	 * during resume. We cannot use the regmap code for that since this register
+	 * needs to be declared as volatile because the brightness can be changed
+	 * by the EC.
+	 */
+	data->last_kbd_status = regval;
+	FIELD_MODIFY(KBD_BRIGHTNESS_MASK, &regval, 0);
+	regval |= KBD_APPLY | KBD_POWER_OFF;
+
+	return regmap_write(data->regmap, EC_ADDR_KBD_STATUS, regval);
+}
+
  static int uniwill_suspend_nvidia_ctgp(struct uniwill_data *data)
  {
  	if (!uniwill_device_supports(data, UNIWILL_FEATURE_NVIDIA_CTGP_CONTROL))
@@ -2006,6 +2355,10 @@ static int uniwill_suspend(struct device *dev)
  	if (ret < 0)
  		return ret;
 
+	ret = uniwill_suspend_kbd_led(data);
+	if (ret < 0)
+		return ret;
+
  	ret = uniwill_suspend_nvidia_ctgp(data);
  	if (ret < 0)
  		return ret;
@@ -2052,6 +2405,23 @@ static int uniwill_resume_battery(struct uniwill_data *data)
  	return 0;
  }
 
+static int uniwill_resume_kbd_led(struct uniwill_data *data)
+{
+	int ret;
+
+	if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+		return 0;
+
+	ret = regmap_write(data->regmap, EC_ADDR_KBD_STATUS, data->last_kbd_status | KBD_APPLY);
+	if (ret < 0)
+		return ret;
+
+	if (data->single_color_kbd)
+		return 0;
+
+	return regmap_write_bits(data->regmap, EC_ADDR_TRIGGER, RGB_APPLY_COLOR, RGB_APPLY_COLOR);
+}
+
  static int uniwill_resume_nvidia_ctgp(struct uniwill_data *data)
  {
  	if (!uniwill_device_supports(data, UNIWILL_FEATURE_NVIDIA_CTGP_CONTROL))
@@ -2096,6 +2466,10 @@ static int uniwill_resume(struct device *dev)
  	if (ret < 0)
  		return ret;
 
+	ret = uniwill_resume_kbd_led(data);
+	if (ret < 0)
+		return ret;
+
  	ret = uniwill_resume_nvidia_ctgp(data);
  	if (ret < 0)
  		return ret;
@@ -2745,6 +3119,8 @@ static int __init uniwill_init(void)
  	if (force) {
  		/* Assume that the device supports all features except the charge limit */
  		device_descriptor.features = UINT_MAX & ~UNIWILL_FEATURE_BATTERY_CHARGE_LIMIT;
+		/* Some models only support 3 brightness levels */
+		device_descriptor.kbd_led_max_brightness = 4;
  		pr_warn("Enabling potentially unsupported features\n");
  	}
 
author maintainer
#3 lore raw

Re: [PATCH 1/7] platform/x86: uniwill-laptop: Add keyboard backlight support

Am 08.07.26 um 21:11 schrieb Werner Sembach:

Quoted 499 lines

Hi,

Am 30.05.26 um 19:08 schrieb Armin Wolf:

Quoted 488 lines

Many Uniwill-based devices support either a white-only or fully features RGB keyboard backlight. Add support for this feature and handle the associated WMI events.

---
  .../admin-guide/laptops/uniwill-laptop.rst    |  13 + drivers/platform/x86/uniwill/uniwill-acpi.c   | 392 +++++++++++++++++-

  2 files changed, 397 insertions(+), 8 deletions(-)
Documentation/admin-guide/laptops/uniwill-laptop.rst +0 -0
index 24b41dbab886..2b1e5da703a5 100644
@@ -77,6 +77,19 @@ LED class device. The default name of this LED 

class device is ``uniwill:multico
  See Documentation/ABI/testing/sysfs-driver-uniwill-laptop for details on how to control the various animation modes of the lightbar.
  +Keyboard Backlight
+------------------

Documentation/admin-guide/laptops/uniwill-laptop.rst +2 -0
+
+The ``uniwill-laptop`` driver supports controlling the keyboard 

backlight using the standard
+LED class interface. The default name of this LED class device is ``uniwill:white:kbd_backlight``
+when the keyboard backlight supports only a single color, or ``uniwill:multicolor:kbd_backlight``
+when the keyboard backlight supports RGB colors. The maximum intensity for each color channel

Documentation/admin-guide/laptops/uniwill-laptop.rst +3 -0
+in RGB mode is 50.
+
+Keep in mind that due to hardware design choices, the driver does 

not support the RGB value
+``0x000000`` (black), instead it will fall back to ``0x010101``
(faint white). In order to
+disable the keyboard backlight, the standard LED brightness setting
has to be used instead.
+
  Configurable TGP
  ----------------
  diff --git a/drivers/platform/x86/uniwill/uniwill-acpi.c b/drivers/platform/x86/uniwill/uniwill-acpi.c index ab063ead45b9..fd040197b189 100644

drivers/platform/x86/uniwill/uniwill-acpi.c +24 -0
@@ -110,8 +110,31 @@
   #define EC_ADDR_BAT_CYCLE_COUNT_2    0x04A7
     #define EC_ADDR_PROJECT_ID        0x0740
+#define PROJECT_ID_NONE            0x00
+#define PROJECT_ID_GI            0x01
+#define PROJECT_ID_GJ            0x02
+#define PROJECT_ID_GK            0x03
+#define PROJECT_ID_GICN            0x04
+#define PROJECT_ID_GJCN            0x05
+#define PROJECT_ID_GK5CN_X        0x06
+#define PROJECT_ID_GK7CN_S        0x07
+#define PROJECT_ID_GK7CPCS_GK5CQ7Z    0x08
+#define PROJECT_ID_PF            0x09
+#define PROJECT_ID_GK5CP_4X_5X_6X    0x0A
+#define PROJECT_ID_IDP            0x0B
+#define PROJECT_ID_IDY_6Y        0x0C
+#define PROJECT_ID_IDY_7Y        0x0D
+#define PROJECT_ID_PF4MU_PF4MN_PF5MU    0x0E
+#define PROJECT_ID_CML_GAMING        0x0F
+#define PROJECT_ID_GK7NXXR        0x10
+#define PROJECT_ID_GM5MU1Y        0x11
   #define PROJECT_ID_PH4TRX1        0x12
+#define PROJECT_ID_PH4TUX1        0x13
+#define PROJECT_ID_PH4TQX1        0x14
   #define PROJECT_ID_PH6TRX1        0x15
+#define PROJECT_ID_PH6TQXX        0x16
+#define PROJECT_ID_PHXAXXX        0x17
+#define PROJECT_ID_PHXPXXX        0x18
     #define EC_ADDR_AP_OEM            0x0741
   #define    ENABLE_MANUAL_CTRL        BIT(0)
@@ -214,6 +237,7 @@
   #define FAN_TABLE_OFFICE_MODE        BIT(2)
   #define FAN_V3                BIT(3)
   #define DEFAULT_MODE            BIT(4)
+#define ENABLE_CHINA_MODE        BIT(6)
     #define EC_ADDR_PL1_SETTING        0x0783

  @@ -225,11 +249,11 @@
  #define FAN_CURVE_LENGTH        5
    #define EC_ADDR_KBD_STATUS        0x078C

drivers/platform/x86/uniwill/uniwill-acpi.c +2 -2
-#define KBD_WHITE_ONLY            BIT(0)    // ~single color
-#define KBD_SINGLE_COLOR_OFF        BIT(1)
+#define KBD_WHITE_ONLY            BIT(0)
+#define KBD_POWER_OFF            BIT(1)

  #define KBD_TURBO_LEVEL_MASK        GENMASK(3, 2) #define KBD_APPLY            BIT(4)

drivers/platform/x86/uniwill/uniwill-acpi.c +1 -1
-#define KBD_BRIGHTNESS            GENMASK(7, 5)
+#define KBD_BRIGHTNESS_MASK        GENMASK(7, 5)

    #define EC_ADDR_FAN_CTRL        0x078E
  #define FAN3P5                BIT(1)

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -320,6 +344,9 @@
   #define LED_CHANNELS        3
   #define LED_MAX_BRIGHTNESS    200

  +#define KBD_LED_CHANNELS    3

drivers/platform/x86/uniwill/uniwill-acpi.c +2 -0
+#define KBD_LED_MAX_INTENSITY    50
+

  #define UNIWILL_FEATURE_FN_LOCK            BIT(0) #define UNIWILL_FEATURE_SUPER_KEY        BIT(1) #define UNIWILL_FEATURE_TOUCHPAD_TOGGLE        BIT(2)

drivers/platform/x86/uniwill/uniwill-acpi.c +2 -0
@@ -333,6 +360,7 @@
   #define UNIWILL_FEATURE_SECONDARY_FAN        BIT(9)
   #define UNIWILL_FEATURE_NVIDIA_CTGP_CONTROL    BIT(10)
   #define UNIWILL_FEATURE_USB_C_POWER_PRIORITY    BIT(11)
+#define UNIWILL_FEATURE_KEYBOARD_BACKLIGHT    BIT(12)
     enum usb_c_power_priority_options {
       USB_C_POWER_PRIORITY_CHARGING = 0,
@@ -344,6 +372,7 @@ struct uniwill_data {
       acpi_handle handle;
       struct regmap *regmap;
       unsigned int features;
+    u8 project_id;
       struct acpi_battery_hook hook;

      struct mutex battery_lock;    /* Protects the list of currently registered batteries */ union {

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -362,6 +391,18 @@ struct uniwill_data {

      struct mutex led_lock;        /* Protects writes to the lightbar registers */ struct led_classdev_mc led_mc_cdev;
      struct mc_subled led_mc_subled_info[LED_CHANNELS];
+    bool single_color_kbd;
+    u8 kbd_led_max_brightness;
+    unsigned int last_kbd_status;
+    union {
+        struct {
+            /* Protects writes to the RGB keyboard backlight registers */
+            struct mutex kbd_rgb_led_lock;
+            struct led_classdev_mc kbd_led_mc_cdev;
+            struct mc_subled kbd_led_mc_subled_info[KBD_LED_CHANNELS]; +        };
+        struct led_classdev kbd_led_cdev;
+    };
      struct mutex input_lock;    /* Protects input sequence during notify */ struct input_dev *input_device;
      struct notifier_block nb;

drivers/platform/x86/uniwill/uniwill-acpi.c +1 -0
@@ -376,6 +417,7 @@ struct uniwill_battery_entry {
     struct uniwill_device_descriptor {
       unsigned int features;
+    u8 kbd_led_max_brightness;
       /* Executed during driver probing */
       int (*probe)(struct uniwill_data *data);
   };
@@ -427,6 +469,9 @@ static const struct key_entry uniwill_keymap[] = {
       { KE_KEY,       UNIWILL_OSD_KBDILLUMDOWN,               { KEY_KBDILLUMDOWN }},
       { KE_KEY,       UNIWILL_OSD_KBDILLUMUP,                 { KEY_KBDILLUMUP }},

  +    /* Reported when the EC changed the keyboard backlight brightness */ +    { KE_IGNORE,    UNIWILL_OSD_BACKLIGHT_LEVEL_CHANGE,    { KEY_UNKNOWN }},
+
      /* Reported when the user wants to toggle the microphone mute status */ { KE_KEY,       UNIWILL_OSD_MIC_MUTE,                   { KEY_MICMUTE }}, @@ -435,11 +480,6 @@ static const struct key_entry uniwill_keymap[] = { /* Reported when the user wants to toggle the brightness of the keyboard */ { KE_KEY,       UNIWILL_OSD_KBDILLUMTOGGLE,             { KEY_KBDILLUMTOGGLE }}, -    { KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL0,              { KEY_KBDILLUMTOGGLE }},
-    { KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL1,              { KEY_KBDILLUMTOGGLE }},
-    { KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL2,              { KEY_KBDILLUMTOGGLE }},
-    { KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL3,              { KEY_KBDILLUMTOGGLE }},
-    { KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL4,              { KEY_KBDILLUMTOGGLE }},
        /* FIXME: find out the exact meaning of those events */
      { KE_IGNORE,    UNIWILL_OSD_BAT_CHARGE_FULL_24_H,       { KEY_UNKNOWN }},

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -547,6 +587,11 @@ static bool uniwill_writeable_reg(struct device 
 *dev, unsigned int reg)

      case EC_ADDR_LIGHTBAR_AC_BLUE:
      case EC_ADDR_BIOS_OEM:
      case EC_ADDR_TRIGGER:
+    case EC_ADDR_RGB_RED:
+    case EC_ADDR_RGB_GREEN:
+    case EC_ADDR_RGB_BLUE:
+    case EC_ADDR_BIOS_OEM_2:
+    case EC_ADDR_KBD_STATUS:
      case EC_ADDR_OEM_4:
      case EC_ADDR_CHARGE_CTRL:
      case EC_ADDR_LIGHTBAR_BAT_CTRL:

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -583,8 +628,14 @@ static bool uniwill_readable_reg(struct device 
 *dev, unsigned int reg)

      case EC_ADDR_BIOS_OEM:
      case EC_ADDR_PWM_1:
      case EC_ADDR_PWM_2:
+    case EC_ADDR_SUPPORT_2:
      case EC_ADDR_TRIGGER:
      case EC_ADDR_SWITCH_STATUS:
+    case EC_ADDR_RGB_RED:
+    case EC_ADDR_RGB_GREEN:
+    case EC_ADDR_RGB_BLUE:
+    case EC_ADDR_BIOS_OEM_2:
+    case EC_ADDR_KBD_STATUS:
      case EC_ADDR_OEM_4:
      case EC_ADDR_CHARGE_CTRL:
      case EC_ADDR_LIGHTBAR_BAT_CTRL:

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -616,8 +667,10 @@ static bool uniwill_volatile_reg(struct device 
 *dev, unsigned int reg)

      case EC_ADDR_BIOS_OEM:
      case EC_ADDR_PWM_1:
      case EC_ADDR_PWM_2:
+    case EC_ADDR_SUPPORT_2:
      case EC_ADDR_TRIGGER:
      case EC_ADDR_SWITCH_STATUS:
+    case EC_ADDR_KBD_STATUS:
      case EC_ADDR_OEM_4:
      case EC_ADDR_CHARGE_CTRL:
      case EC_ADDR_USB_C_POWER_PRIORITY:

drivers/platform/x86/uniwill/uniwill-acpi.c +27 -0
@@ -1441,6 +1494,246 @@ static int uniwill_led_init(struct 
 uniwill_data *data)
                                &init_data);
   }
   +static int uniwill_notify_kbd_led(struct uniwill_data *data, int brightness)
+{
+    struct led_classdev *led_cdev;
+    int ret;
+
+    if (data->single_color_kbd)
+        led_cdev = &data->kbd_led_cdev;
+    else
+        led_cdev = &data->kbd_led_mc_cdev.led_cdev;
+
+    guard(mutex)(&led_cdev->led_access);
+
+    /* Sync the LED brightness with the actual hardware state */
+    ret = led_update_brightness(led_cdev);
+    if (ret < 0)
+        return ret;
+
+    led_classdev_notify_brightness_hw_changed(led_cdev, brightness);
+
+    return 0;
+}
+
+#define KBD_LED_MASK    (KBD_BRIGHTNESS_MASK | KBD_APPLY | 
 KBD_POWER_OFF)
+
+static int uniwill_kbd_led_write_brightness(struct uniwill_data 
 *data, int brightness)
+{
+    /* KBD_POWER_OFF is always implicitly cleared */
+    unsigned int regval = FIELD_PREP(KBD_BRIGHTNESS_MASK, 

brightness) | KBD_APPLY;
+
+    /* We must ensure that the "apply" bit is always written */ +    return regmap_write_bits(data->regmap, EC_ADDR_KBD_STATUS, KBD_LED_MASK, regval);

drivers/platform/x86/uniwill/uniwill-acpi.c +12 -0
+}
+
+static int uniwill_kbd_led_read_brightness(struct uniwill_data *data)
+{
+    unsigned int regval;
+    int ret;
+
+    ret = regmap_read(data->regmap, EC_ADDR_KBD_STATUS, &regval);
+    if (ret < 0)
+        return ret;
+
+    return min(FIELD_GET(KBD_BRIGHTNESS_MASK, regval), 

data->kbd_led_max_brightness);

drivers/platform/x86/uniwill/uniwill-acpi.c +3 -0
+}
+
+static int uniwill_kbd_led_brightness_set(struct led_classdev 

*led_cdev,
+                      enum led_brightness brightness) +{
+    struct uniwill_data *data = container_of(led_cdev, struct uniwill_data, kbd_led_cdev);

drivers/platform/x86/uniwill/uniwill-acpi.c +5 -0
+
+    return uniwill_kbd_led_write_brightness(data, brightness);
+}
+
+static enum led_brightness uniwill_kbd_led_brightness_get(struct 

led_classdev *led_cdev)
+{
+    struct uniwill_data *data = container_of(led_cdev, struct uniwill_data, kbd_led_cdev);

drivers/platform/x86/uniwill/uniwill-acpi.c +5 -0
+
+    return uniwill_kbd_led_read_brightness(data);
+}
+
+static const unsigned int 

uniwill_kbd_led_channel_to_reg[KBD_LED_CHANNELS] = { +    EC_ADDR_RGB_RED,
+    EC_ADDR_RGB_GREEN,
+    EC_ADDR_RGB_BLUE,

drivers/platform/x86/uniwill/uniwill-acpi.c +3 -0
+};
+
+static int uniwill_kbd_led_mc_brightness_set(struct led_classdev 

*led_cdev,
+                         enum led_brightness brightness) +{
+    struct led_classdev_mc *led_mc_cdev = lcdev_to_mccdev(led_cdev); +    struct uniwill_data *data = container_of(led_mc_cdev, struct uniwill_data, kbd_led_mc_cdev);
+    unsigned int min_intensity = 0;
+    unsigned int regval;
+    int ret;

drivers/platform/x86/uniwill/uniwill-acpi.c +5 -0
+
+    guard(mutex)(&data->kbd_rgb_led_lock);
+
+    /*
+     * The EC interprets a RGB value of 0x000000 as a command to 

restore
+     * the device-specfic default RGB value. Work around this by writing
+     * a RGB value of 0x010101 (faint white) instead. +     */
+    if (data->kbd_led_mc_subled_info[0].intensity == 0 && +        data->kbd_led_mc_subled_info[1].intensity == 0 && +        data->kbd_led_mc_subled_info[2].intensity == 0) +        min_intensity = 1;
+
+    for (int i = 0; i < KBD_LED_CHANNELS; i++) {
+        regval = max(data->kbd_led_mc_subled_info[i].intensity, min_intensity);
+        ret = regmap_write(data->regmap, uniwill_kbd_led_channel_to_reg[i], regval);
+        if (ret < 0)
+            return ret;
+    }
+
+    ret = regmap_write_bits(data->regmap, EC_ADDR_TRIGGER, RGB_APPLY_COLOR, RGB_APPLY_COLOR);
+    if (ret < 0)
+        return ret;

drivers/platform/x86/uniwill/uniwill-acpi.c +5 -0
+
+    return uniwill_kbd_led_write_brightness(data, brightness);
+}
+
+static enum led_brightness uniwill_kbd_led_mc_brightness_get(struct 

led_classdev *led_cdev)
+{
+    struct led_classdev_mc *led_mc_cdev = lcdev_to_mccdev(led_cdev); +    struct uniwill_data *data = container_of(led_mc_cdev, struct uniwill_data, kbd_led_mc_cdev);

drivers/platform/x86/uniwill/uniwill-acpi.c +21 -0
+
+    return uniwill_kbd_led_read_brightness(data);
+}
+
+static int uniwill_kbd_led_init(struct uniwill_data *data)
+{
+    unsigned int color_indices[KBD_LED_CHANNELS] = {
+        LED_COLOR_ID_RED,
+        LED_COLOR_ID_GREEN,
+        LED_COLOR_ID_BLUE,
+    };
+    struct led_init_data init_data = {
+        .devicename = DRIVER_NAME,
+        .devname_mandatory = true,
+    };
+    bool intensity_all_zeros = true;
+    bool needs_trigger = false;
+    unsigned int regval;
+    int ret;
+
+    if (!uniwill_device_supports(data, 

UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+        return 0;

drivers/platform/x86/uniwill/uniwill-acpi.c +7 -0
+
+    ret = regmap_read(data->regmap, EC_ADDR_SUPPORT_2, &regval);
+    if (ret < 0)
+        return ret;
+
+    if (!(regval & CHINA_MODE)) {
+        ret = regmap_set_bits(data->regmap, EC_ADDR_BIOS_OEM_2, 

ENABLE_CHINA_MODE);
+        if (ret < 0)
+            return ret;
+    }

drivers/platform/x86/uniwill/uniwill-acpi.c +31 -0
+
+    ret = regmap_read(data->regmap, EC_ADDR_KBD_STATUS, &regval);
+    if (ret < 0)
+        return ret;
+
+    regval |= KBD_APPLY;
+    regval &= ~KBD_POWER_OFF;
+    ret = regmap_write(data->regmap, EC_ADDR_KBD_STATUS, regval);
+    if (ret < 0)
+        return ret;
+
+    switch (data->project_id) {
+    case PROJECT_ID_PF:
+    case PROJECT_ID_PF4MU_PF4MN_PF5MU:
+    case PROJECT_ID_PH4TRX1:
+    case PROJECT_ID_PH4TUX1:
+    case PROJECT_ID_PH4TQX1:
+    case PROJECT_ID_PH6TRX1:
+    case PROJECT_ID_PH6TQXX:
+    case PROJECT_ID_PHXAXXX:
+    case PROJECT_ID_PHXPXXX:
+        data->single_color_kbd = true;
+        break;
+    default:
+        data->single_color_kbd = regval & KBD_WHITE_ONLY;
+        break;
+    }
+
+    if (data->single_color_kbd) {
+        init_data.default_label = "white:" LED_FUNCTION_KBD_BACKLIGHT;
+        data->kbd_led_cdev.max_brightness = 

data->kbd_led_max_brightness;
+        data->kbd_led_cdev.color = LED_COLOR_ID_WHITE; +        data->kbd_led_cdev.flags = LED_BRIGHT_HW_CHANGED | LED_REJECT_NAME_CONFLICT;
+        data->kbd_led_cdev.brightness_set_blocking = uniwill_kbd_led_brightness_set;
+        data->kbd_led_cdev.brightness_get = uniwill_kbd_led_brightness_get;
+
+        return devm_led_classdev_register_ext(data->dev, &data->kbd_led_cdev, &init_data);
+    }

drivers/platform/x86/uniwill/uniwill-acpi.c +5 -0
+
+    for (int i = 0; i < KBD_LED_CHANNELS; i++) {
+        data->kbd_led_mc_subled_info[i].color_index = color_indices[i];
+
+        ret = regmap_read(data->regmap, 

uniwill_kbd_led_channel_to_reg[i], &regval);
+        if (ret < 0)
+            return ret;
+
+        /*
+         * Make sure that the initial intensity value is not greater than
+         * the maximum intensity.
+         */
+        if (regval > KBD_LED_MAX_INTENSITY) {
+            regval = KBD_LED_MAX_INTENSITY;
+            ret = regmap_write(data->regmap, uniwill_kbd_led_channel_to_reg[i], regval);
+            if (ret < 0)
+                return ret;

drivers/platform/x86/uniwill/uniwill-acpi.c +9 -0
+
+            needs_trigger = true;
+        }
+
+        if (regval)
+            intensity_all_zeros = false;
+
+        data->kbd_led_mc_subled_info[i].intensity = regval;
+        data->kbd_led_mc_subled_info[i].max_intensity = 

KBD_LED_MAX_INTENSITY;
+        data->kbd_led_mc_subled_info[i].channel = i;
+    }
+
+    /* See uniwill_kbd_led_mc_brightness_set() for an explaination. */ +    if (intensity_all_zeros) {
+        for (int i = 0; i < KBD_LED_CHANNELS; i++) {
+            data->kbd_led_mc_subled_info[i].intensity = 1; +            ret = regmap_write(data->regmap, uniwill_kbd_led_channel_to_reg[i], 1);
+            if (ret < 0)
+                return ret;
+        }

drivers/platform/x86/uniwill/uniwill-acpi.c +6 -0
+
+        needs_trigger = true;
+    }
+
+    if (needs_trigger) {
+        ret = regmap_write_bits(data->regmap, EC_ADDR_TRIGGER, 

RGB_APPLY_COLOR,
+                    RGB_APPLY_COLOR);
+        if (ret < 0)
+            return ret;
+    }

drivers/platform/x86/uniwill/uniwill-acpi.c +7 -0
+
+    ret = devm_mutex_init(data->dev, &data->kbd_rgb_led_lock);
+    if (ret < 0)
+        return ret;
+
+    init_data.default_label = "multicolor:" LED_FUNCTION_KBD_BACKLIGHT;
+    data->kbd_led_mc_cdev.led_cdev.max_brightness = 

data->kbd_led_max_brightness;
+    data->kbd_led_mc_cdev.led_cdev.color = LED_COLOR_ID_MULTI; +    data->kbd_led_mc_cdev.led_cdev.flags = LED_BRIGHT_HW_CHANGED | LED_REJECT_NAME_CONFLICT;
+    data->kbd_led_mc_cdev.led_cdev.brightness_set_blocking = uniwill_kbd_led_mc_brightness_set;
+    data->kbd_led_mc_cdev.led_cdev.brightness_get = uniwill_kbd_led_mc_brightness_get;
+    data->kbd_led_mc_cdev.subled_info = data->kbd_led_mc_subled_info; +    data->kbd_led_mc_cdev.num_colors = KBD_LED_CHANNELS;
+
+    return devm_led_classdev_multicolor_register_ext(data->dev, &data->kbd_led_mc_cdev,
+                             &init_data);

drivers/platform/x86/uniwill/uniwill-acpi.c

Quoted 2 lines
drivers/platform/x86/uniwill/uniwill-acpi.c +2 -0
+}
+

Sorry I know I'm way to late with my comment, but I'm not at all a fan of how complex this whole function is:

- When we have to set max brightness on a per device basis anyway, we
can also set rgb or white only there and can skip this whole detection mechanism with the supported bits that are unreliable anyway

Quoted 9 lines

- we have a 2nd "supported devices/features list" inside this function which is abstracting away from the actual supported feature list

Should i try to spin up something much simpler, but that requires explicit setting in the device descriptor?

Best regards

Werner

Good point, but in this case i think having this small device list is OK, because the original control center does something similar. If we encounter a device that does not work with this strategy then we can indeed move the code into the device descriptor.

Thanks,
Armin Wolf

Quoted 158 lines
Quoted 157 lines

  static unsigned int uniwill_sanitize_battery_threshold(unsigned int value) {
      /* 0 means "charging threshold not active" */

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -1789,6 +2082,31 @@ static int uniwill_notifier_call(struct 

notifier_block *nb, unsigned long action sysfs_notify(&data->dev->kobj, NULL, "fn_lock"); return NOTIFY_OK;
+    case UNIWILL_OSD_KB_LED_LEVEL0:
+        if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+            return NOTIFY_DONE;
+
+        return notifier_from_errno(uniwill_notify_kbd_led(data, 0)); +    case UNIWILL_OSD_KB_LED_LEVEL1:
+        if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+            return NOTIFY_DONE;
+
+        return notifier_from_errno(uniwill_notify_kbd_led(data, 1)); +    case UNIWILL_OSD_KB_LED_LEVEL2:
+        if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+            return NOTIFY_DONE;
+
+        return notifier_from_errno(uniwill_notify_kbd_led(data, 2)); +    case UNIWILL_OSD_KB_LED_LEVEL3:
+        if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+            return NOTIFY_DONE;
+
+        return notifier_from_errno(uniwill_notify_kbd_led(data, 3)); +    case UNIWILL_OSD_KB_LED_LEVEL4:
+        if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+            return NOTIFY_DONE;
+
+        return notifier_from_errno(uniwill_notify_kbd_led(data, 4)); default:
          mutex_lock(&data->input_lock); sparse_keymap_report_event(data->input_device, action, 1, true);

drivers/platform/x86/uniwill/uniwill-acpi.c +4 -0
@@ -1842,6 +2160,7 @@ static int uniwill_ec_init(struct uniwill_data 
 *data)
       if (ret < 0)
           return ret;
   +    data->project_id = value;
       dev_dbg(data->dev, "Project ID: %u\n", value);
         ret = regmap_set_bits(data->regmap, EC_ADDR_AP_OEM, ENABLE_MANUAL_CTRL);
@@ -1885,6 +2204,7 @@ static int uniwill_probe(struct platform_device 
 *pdev)
           return ret;
         data->features = device_descriptor.features;
+    data->kbd_led_max_brightness = 
 device_descriptor.kbd_led_max_brightness;
         /*
        * Some devices might need to perform some device-specific initialization steps
@@ -1905,6 +2225,10 @@ static int uniwill_probe(struct 
 platform_device *pdev)
       if (ret < 0)
           return ret;
   +    ret = uniwill_kbd_led_init(data);
+    if (ret < 0)
+        return ret;
+
       ret = uniwill_hwmon_init(data);
       if (ret < 0)

          return ret;

drivers/platform/x86/uniwill/uniwill-acpi.c +13 -0
@@ -1976,6 +2300,31 @@ static int uniwill_suspend_battery(struct 
 uniwill_data *data)
       return regmap_read(data->regmap, EC_ADDR_CHARGE_CTRL, &data->last_charge_ctrl);
   }
   +static int uniwill_suspend_kbd_led(struct uniwill_data *data)
+{
+    unsigned int regval;
+    int ret;
+
+    if (!uniwill_device_supports(data, 
 UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+        return 0;
+
+    ret = regmap_read(data->regmap, EC_ADDR_KBD_STATUS, &regval);
+    if (ret < 0)
+        return ret;
+
+    /*
+     * Save the current keyboard backlight settings in order to 

restore them
+     * during resume. We cannot use the regmap code for that since this register
+     * needs to be declared as volatile because the brightness can be changed
+     * by the EC.
+     */
+    data->last_kbd_status = regval;
+    FIELD_MODIFY(KBD_BRIGHTNESS_MASK, &regval, 0);
+    regval |= KBD_APPLY | KBD_POWER_OFF;

drivers/platform/x86/uniwill/uniwill-acpi.c +4 -0
+
+    return regmap_write(data->regmap, EC_ADDR_KBD_STATUS, regval);
+}
+

  static int uniwill_suspend_nvidia_ctgp(struct uniwill_data *data) {
      if (!uniwill_device_supports(data, UNIWILL_FEATURE_NVIDIA_CTGP_CONTROL))

drivers/platform/x86/uniwill/uniwill-acpi.c +17 -0
@@ -2006,6 +2355,10 @@ static int uniwill_suspend(struct device *dev)
       if (ret < 0)
           return ret;
   +    ret = uniwill_suspend_kbd_led(data);
+    if (ret < 0)
+        return ret;
+
       ret = uniwill_suspend_nvidia_ctgp(data);
       if (ret < 0)
           return ret;
@@ -2052,6 +2405,23 @@ static int uniwill_resume_battery(struct 
 uniwill_data *data)
       return 0;
   }
   +static int uniwill_resume_kbd_led(struct uniwill_data *data)
+{
+    int ret;
+
+    if (!uniwill_device_supports(data, 
 UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+        return 0;
+
+    ret = regmap_write(data->regmap, EC_ADDR_KBD_STATUS, 
 data->last_kbd_status | KBD_APPLY);
+    if (ret < 0)
+        return ret;
+
+    if (data->single_color_kbd)
+        return 0;
+
+    return regmap_write_bits(data->regmap, EC_ADDR_TRIGGER, 

RGB_APPLY_COLOR, RGB_APPLY_COLOR);

drivers/platform/x86/uniwill/uniwill-acpi.c +2 -0
+}
+

  static int uniwill_resume_nvidia_ctgp(struct uniwill_data *data) {
      if (!uniwill_device_supports(data, UNIWILL_FEATURE_NVIDIA_CTGP_CONTROL))

drivers/platform/x86/uniwill/uniwill-acpi.c +5 -0
@@ -2096,6 +2466,10 @@ static int uniwill_resume(struct device *dev)
       if (ret < 0)
           return ret;
   +    ret = uniwill_resume_kbd_led(data);
+    if (ret < 0)
+        return ret;
+
       ret = uniwill_resume_nvidia_ctgp(data);
       if (ret < 0)
           return ret;
@@ -2745,6 +3119,8 @@ static int __init uniwill_init(void)
       if (force) {
           /* Assume that the device supports all features except the charge limit */
           device_descriptor.features = UINT_MAX & ~UNIWILL_FEATURE_BATTERY_CHARGE_LIMIT;
+        /* Some models only support 3 brightness levels */
+        device_descriptor.kbd_led_max_brightness = 4;
           pr_warn("Enabling potentially unsupported features\n");
       }
#4 lore raw

Re: [PATCH 1/7] platform/x86: uniwill-laptop: Add keyboard backlight support

Am 08.07.26 um 22:08 schrieb Armin Wolf:

Quoted 490 lines

Am 08.07.26 um 21:11 schrieb Werner Sembach:

Quoted 488 lines

Hi,

Am 30.05.26 um 19:08 schrieb Armin Wolf:

Quoted 474 lines

Many Uniwill-based devices support either a white-only or fully features RGB keyboard backlight. Add support for this feature and handle the associated WMI events.

---
  .../admin-guide/laptops/uniwill-laptop.rst    |  13 + drivers/platform/x86/uniwill/uniwill-acpi.c   | 392 +++++++++++++++++-

  2 files changed, 397 insertions(+), 8 deletions(-)
Documentation/admin-guide/laptops/uniwill-laptop.rst +0 -0
index 24b41dbab886..2b1e5da703a5 100644
@@ -77,6 +77,19 @@ LED class device. The default name of this LED class 

device is ``uniwill:multico
  See Documentation/ABI/testing/sysfs-driver-uniwill-laptop for details on how to control the various animation modes of the lightbar.
  +Keyboard Backlight
+------------------

Documentation/admin-guide/laptops/uniwill-laptop.rst +2 -0
+
+The ``uniwill-laptop`` driver supports controlling the keyboard backlight 

using the standard
+LED class interface. The default name of this LED class device is ``uniwill:white:kbd_backlight``
+when the keyboard backlight supports only a single color, or ``uniwill:multicolor:kbd_backlight``
+when the keyboard backlight supports RGB colors. The maximum intensity for each color channel

Documentation/admin-guide/laptops/uniwill-laptop.rst +3 -0
+in RGB mode is 50.
+
+Keep in mind that due to hardware design choices, the driver does not 

support the RGB value
+``0x000000`` (black), instead it will fall back to ``0x010101`` (faint
white). In order to
+disable the keyboard backlight, the standard LED brightness setting has to
be used instead.
+
  Configurable TGP
  ----------------
  diff --git a/drivers/platform/x86/uniwill/uniwill-acpi.c b/drivers/platform/x86/uniwill/uniwill-acpi.c index ab063ead45b9..fd040197b189 100644

drivers/platform/x86/uniwill/uniwill-acpi.c +24 -0
@@ -110,8 +110,31 @@
   #define EC_ADDR_BAT_CYCLE_COUNT_2    0x04A7
     #define EC_ADDR_PROJECT_ID        0x0740
+#define PROJECT_ID_NONE            0x00
+#define PROJECT_ID_GI            0x01
+#define PROJECT_ID_GJ            0x02
+#define PROJECT_ID_GK            0x03
+#define PROJECT_ID_GICN            0x04
+#define PROJECT_ID_GJCN            0x05
+#define PROJECT_ID_GK5CN_X        0x06
+#define PROJECT_ID_GK7CN_S        0x07
+#define PROJECT_ID_GK7CPCS_GK5CQ7Z    0x08
+#define PROJECT_ID_PF            0x09
+#define PROJECT_ID_GK5CP_4X_5X_6X    0x0A
+#define PROJECT_ID_IDP            0x0B
+#define PROJECT_ID_IDY_6Y        0x0C
+#define PROJECT_ID_IDY_7Y        0x0D
+#define PROJECT_ID_PF4MU_PF4MN_PF5MU    0x0E
+#define PROJECT_ID_CML_GAMING        0x0F
+#define PROJECT_ID_GK7NXXR        0x10
+#define PROJECT_ID_GM5MU1Y        0x11
   #define PROJECT_ID_PH4TRX1        0x12
+#define PROJECT_ID_PH4TUX1        0x13
+#define PROJECT_ID_PH4TQX1        0x14
   #define PROJECT_ID_PH6TRX1        0x15
+#define PROJECT_ID_PH6TQXX        0x16
+#define PROJECT_ID_PHXAXXX        0x17
+#define PROJECT_ID_PHXPXXX        0x18
     #define EC_ADDR_AP_OEM            0x0741
   #define    ENABLE_MANUAL_CTRL        BIT(0)
@@ -214,6 +237,7 @@
   #define FAN_TABLE_OFFICE_MODE        BIT(2)
   #define FAN_V3                BIT(3)
   #define DEFAULT_MODE            BIT(4)
+#define ENABLE_CHINA_MODE        BIT(6)
     #define EC_ADDR_PL1_SETTING        0x0783

  @@ -225,11 +249,11 @@
  #define FAN_CURVE_LENGTH        5
    #define EC_ADDR_KBD_STATUS        0x078C

drivers/platform/x86/uniwill/uniwill-acpi.c +2 -2
-#define KBD_WHITE_ONLY            BIT(0)    // ~single color
-#define KBD_SINGLE_COLOR_OFF        BIT(1)
+#define KBD_WHITE_ONLY            BIT(0)
+#define KBD_POWER_OFF            BIT(1)

  #define KBD_TURBO_LEVEL_MASK        GENMASK(3, 2) #define KBD_APPLY            BIT(4)

drivers/platform/x86/uniwill/uniwill-acpi.c +1 -1
-#define KBD_BRIGHTNESS            GENMASK(7, 5)
+#define KBD_BRIGHTNESS_MASK        GENMASK(7, 5)

    #define EC_ADDR_FAN_CTRL        0x078E
  #define FAN3P5                BIT(1)

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -320,6 +344,9 @@
   #define LED_CHANNELS        3
   #define LED_MAX_BRIGHTNESS    200

  +#define KBD_LED_CHANNELS    3

drivers/platform/x86/uniwill/uniwill-acpi.c +2 -0
+#define KBD_LED_MAX_INTENSITY    50
+

  #define UNIWILL_FEATURE_FN_LOCK            BIT(0) #define UNIWILL_FEATURE_SUPER_KEY        BIT(1) #define UNIWILL_FEATURE_TOUCHPAD_TOGGLE        BIT(2)

drivers/platform/x86/uniwill/uniwill-acpi.c +2 -0
@@ -333,6 +360,7 @@
   #define UNIWILL_FEATURE_SECONDARY_FAN        BIT(9)
   #define UNIWILL_FEATURE_NVIDIA_CTGP_CONTROL    BIT(10)
   #define UNIWILL_FEATURE_USB_C_POWER_PRIORITY    BIT(11)
+#define UNIWILL_FEATURE_KEYBOARD_BACKLIGHT    BIT(12)
     enum usb_c_power_priority_options {
       USB_C_POWER_PRIORITY_CHARGING = 0,
@@ -344,6 +372,7 @@ struct uniwill_data {
       acpi_handle handle;
       struct regmap *regmap;
       unsigned int features;
+    u8 project_id;
       struct acpi_battery_hook hook;

      struct mutex battery_lock;    /* Protects the list of currently registered batteries */ union {

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -362,6 +391,18 @@ struct uniwill_data {

      struct mutex led_lock;        /* Protects writes to the lightbar registers */ struct led_classdev_mc led_mc_cdev;
      struct mc_subled led_mc_subled_info[LED_CHANNELS];
+    bool single_color_kbd;
+    u8 kbd_led_max_brightness;
+    unsigned int last_kbd_status;
+    union {
+        struct {
+            /* Protects writes to the RGB keyboard backlight registers */ +            struct mutex kbd_rgb_led_lock;
+            struct led_classdev_mc kbd_led_mc_cdev;
+            struct mc_subled kbd_led_mc_subled_info[KBD_LED_CHANNELS]; +        };
+        struct led_classdev kbd_led_cdev;
+    };
      struct mutex input_lock;    /* Protects input sequence during notify */ struct input_dev *input_device;
      struct notifier_block nb;

drivers/platform/x86/uniwill/uniwill-acpi.c +1 -0
@@ -376,6 +417,7 @@ struct uniwill_battery_entry {
     struct uniwill_device_descriptor {
       unsigned int features;
+    u8 kbd_led_max_brightness;
       /* Executed during driver probing */
       int (*probe)(struct uniwill_data *data);
   };
@@ -427,6 +469,9 @@ static const struct key_entry uniwill_keymap[] = {
       { KE_KEY,       UNIWILL_OSD_KBDILLUMDOWN, { KEY_KBDILLUMDOWN }},
       { KE_KEY,       UNIWILL_OSD_KBDILLUMUP, { KEY_KBDILLUMUP }},

  +    /* Reported when the EC changed the keyboard backlight brightness */ +    { KE_IGNORE,    UNIWILL_OSD_BACKLIGHT_LEVEL_CHANGE,    { KEY_UNKNOWN }}, +
      /* Reported when the user wants to toggle the microphone mute status */ { KE_KEY,       UNIWILL_OSD_MIC_MUTE, { KEY_MICMUTE }},
  @@ -435,11 +480,6 @@ static const struct key_entry uniwill_keymap[] = { /* Reported when the user wants to toggle the brightness of the keyboard */ { KE_KEY,       UNIWILL_OSD_KBDILLUMTOGGLE, { KEY_KBDILLUMTOGGLE }}, -    { KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL0,              { KEY_KBDILLUMTOGGLE }},
-    { KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL1,              { KEY_KBDILLUMTOGGLE }},
-    { KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL2,              { KEY_KBDILLUMTOGGLE }},
-    { KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL3,              { KEY_KBDILLUMTOGGLE }},
-    { KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL4,              { KEY_KBDILLUMTOGGLE }},
        /* FIXME: find out the exact meaning of those events */
      { KE_IGNORE,    UNIWILL_OSD_BAT_CHARGE_FULL_24_H, { KEY_UNKNOWN }},

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -547,6 +587,11 @@ static bool uniwill_writeable_reg(struct device *dev, 
 unsigned int reg)

      case EC_ADDR_LIGHTBAR_AC_BLUE:
      case EC_ADDR_BIOS_OEM:
      case EC_ADDR_TRIGGER:
+    case EC_ADDR_RGB_RED:
+    case EC_ADDR_RGB_GREEN:
+    case EC_ADDR_RGB_BLUE:
+    case EC_ADDR_BIOS_OEM_2:
+    case EC_ADDR_KBD_STATUS:
      case EC_ADDR_OEM_4:
      case EC_ADDR_CHARGE_CTRL:
      case EC_ADDR_LIGHTBAR_BAT_CTRL:

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -583,8 +628,14 @@ static bool uniwill_readable_reg(struct device *dev, 
 unsigned int reg)

      case EC_ADDR_BIOS_OEM:
      case EC_ADDR_PWM_1:
      case EC_ADDR_PWM_2:
+    case EC_ADDR_SUPPORT_2:
      case EC_ADDR_TRIGGER:
      case EC_ADDR_SWITCH_STATUS:
+    case EC_ADDR_RGB_RED:
+    case EC_ADDR_RGB_GREEN:
+    case EC_ADDR_RGB_BLUE:
+    case EC_ADDR_BIOS_OEM_2:
+    case EC_ADDR_KBD_STATUS:
      case EC_ADDR_OEM_4:
      case EC_ADDR_CHARGE_CTRL:
      case EC_ADDR_LIGHTBAR_BAT_CTRL:

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -616,8 +667,10 @@ static bool uniwill_volatile_reg(struct device *dev, 
 unsigned int reg)

      case EC_ADDR_BIOS_OEM:
      case EC_ADDR_PWM_1:
      case EC_ADDR_PWM_2:
+    case EC_ADDR_SUPPORT_2:
      case EC_ADDR_TRIGGER:
      case EC_ADDR_SWITCH_STATUS:
+    case EC_ADDR_KBD_STATUS:
      case EC_ADDR_OEM_4:
      case EC_ADDR_CHARGE_CTRL:
      case EC_ADDR_USB_C_POWER_PRIORITY:

drivers/platform/x86/uniwill/uniwill-acpi.c +42 -0
@@ -1441,6 +1494,246 @@ static int uniwill_led_init(struct uniwill_data *data)
                                &init_data);
   }
   +static int uniwill_notify_kbd_led(struct uniwill_data *data, int brightness)
+{
+    struct led_classdev *led_cdev;
+    int ret;
+
+    if (data->single_color_kbd)
+        led_cdev = &data->kbd_led_cdev;
+    else
+        led_cdev = &data->kbd_led_mc_cdev.led_cdev;
+
+    guard(mutex)(&led_cdev->led_access);
+
+    /* Sync the LED brightness with the actual hardware state */
+    ret = led_update_brightness(led_cdev);
+    if (ret < 0)
+        return ret;
+
+    led_classdev_notify_brightness_hw_changed(led_cdev, brightness);
+
+    return 0;
+}
+
+#define KBD_LED_MASK    (KBD_BRIGHTNESS_MASK | KBD_APPLY | KBD_POWER_OFF)
+
+static int uniwill_kbd_led_write_brightness(struct uniwill_data *data, int 
 brightness)
+{
+    /* KBD_POWER_OFF is always implicitly cleared */
+    unsigned int regval = FIELD_PREP(KBD_BRIGHTNESS_MASK, brightness) | 
 KBD_APPLY;
+
+    /* We must ensure that the "apply" bit is always written */
+    return regmap_write_bits(data->regmap, EC_ADDR_KBD_STATUS, 
 KBD_LED_MASK, regval);
+}
+
+static int uniwill_kbd_led_read_brightness(struct uniwill_data *data)
+{
+    unsigned int regval;
+    int ret;
+
+    ret = regmap_read(data->regmap, EC_ADDR_KBD_STATUS, &regval);
+    if (ret < 0)
+        return ret;
+
+    return min(FIELD_GET(KBD_BRIGHTNESS_MASK, regval), 

data->kbd_led_max_brightness);

drivers/platform/x86/uniwill/uniwill-acpi.c +6 -0
+}
+
+static int uniwill_kbd_led_brightness_set(struct led_classdev *led_cdev,
+                      enum led_brightness brightness)
+{
+    struct uniwill_data *data = container_of(led_cdev, struct uniwill_data, 

kbd_led_cdev);

drivers/platform/x86/uniwill/uniwill-acpi.c +5 -0
+
+    return uniwill_kbd_led_write_brightness(data, brightness);
+}
+
+static enum led_brightness uniwill_kbd_led_brightness_get(struct 

led_classdev *led_cdev)
+{
+    struct uniwill_data *data = container_of(led_cdev, struct uniwill_data, kbd_led_cdev);

drivers/platform/x86/uniwill/uniwill-acpi.c +15 -0
+
+    return uniwill_kbd_led_read_brightness(data);
+}
+
+static const unsigned int uniwill_kbd_led_channel_to_reg[KBD_LED_CHANNELS] = {
+    EC_ADDR_RGB_RED,
+    EC_ADDR_RGB_GREEN,
+    EC_ADDR_RGB_BLUE,
+};
+
+static int uniwill_kbd_led_mc_brightness_set(struct led_classdev *led_cdev,
+                         enum led_brightness brightness)
+{
+    struct led_classdev_mc *led_mc_cdev = lcdev_to_mccdev(led_cdev);
+    struct uniwill_data *data = container_of(led_mc_cdev, struct 

uniwill_data, kbd_led_mc_cdev);
+    unsigned int min_intensity = 0;
+    unsigned int regval;
+    int ret;

drivers/platform/x86/uniwill/uniwill-acpi.c +15 -0
+
+    guard(mutex)(&data->kbd_rgb_led_lock);
+
+    /*
+     * The EC interprets a RGB value of 0x000000 as a command to restore
+     * the device-specfic default RGB value. Work around this by writing
+     * a RGB value of 0x010101 (faint white) instead.
+     */
+    if (data->kbd_led_mc_subled_info[0].intensity == 0 &&
+        data->kbd_led_mc_subled_info[1].intensity == 0 &&
+        data->kbd_led_mc_subled_info[2].intensity == 0)
+        min_intensity = 1;
+
+    for (int i = 0; i < KBD_LED_CHANNELS; i++) {
+        regval = max(data->kbd_led_mc_subled_info[i].intensity, 

min_intensity);
+        ret = regmap_write(data->regmap, uniwill_kbd_led_channel_to_reg[i], regval);
+        if (ret < 0)
+            return ret;
+    }
+
+    ret = regmap_write_bits(data->regmap, EC_ADDR_TRIGGER, RGB_APPLY_COLOR, RGB_APPLY_COLOR);
+    if (ret < 0)
+        return ret;

drivers/platform/x86/uniwill/uniwill-acpi.c +5 -0
+
+    return uniwill_kbd_led_write_brightness(data, brightness);
+}
+
+static enum led_brightness uniwill_kbd_led_mc_brightness_get(struct 

led_classdev *led_cdev)
+{
+    struct led_classdev_mc *led_mc_cdev = lcdev_to_mccdev(led_cdev); +    struct uniwill_data *data = container_of(led_mc_cdev, struct uniwill_data, kbd_led_mc_cdev);

drivers/platform/x86/uniwill/uniwill-acpi.c +29 -0
+
+    return uniwill_kbd_led_read_brightness(data);
+}
+
+static int uniwill_kbd_led_init(struct uniwill_data *data)
+{
+    unsigned int color_indices[KBD_LED_CHANNELS] = {
+        LED_COLOR_ID_RED,
+        LED_COLOR_ID_GREEN,
+        LED_COLOR_ID_BLUE,
+    };
+    struct led_init_data init_data = {
+        .devicename = DRIVER_NAME,
+        .devname_mandatory = true,
+    };
+    bool intensity_all_zeros = true;
+    bool needs_trigger = false;
+    unsigned int regval;
+    int ret;
+
+    if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+        return 0;
+
+    ret = regmap_read(data->regmap, EC_ADDR_SUPPORT_2, &regval);
+    if (ret < 0)
+        return ret;
+
+    if (!(regval & CHINA_MODE)) {
+        ret = regmap_set_bits(data->regmap, EC_ADDR_BIOS_OEM_2, 

ENABLE_CHINA_MODE);
+        if (ret < 0)
+            return ret;
+    }

drivers/platform/x86/uniwill/uniwill-acpi.c +33 -0
+
+    ret = regmap_read(data->regmap, EC_ADDR_KBD_STATUS, &regval);
+    if (ret < 0)
+        return ret;
+
+    regval |= KBD_APPLY;
+    regval &= ~KBD_POWER_OFF;
+    ret = regmap_write(data->regmap, EC_ADDR_KBD_STATUS, regval);
+    if (ret < 0)
+        return ret;
+
+    switch (data->project_id) {
+    case PROJECT_ID_PF:
+    case PROJECT_ID_PF4MU_PF4MN_PF5MU:
+    case PROJECT_ID_PH4TRX1:
+    case PROJECT_ID_PH4TUX1:
+    case PROJECT_ID_PH4TQX1:
+    case PROJECT_ID_PH6TRX1:
+    case PROJECT_ID_PH6TQXX:
+    case PROJECT_ID_PHXAXXX:
+    case PROJECT_ID_PHXPXXX:
+        data->single_color_kbd = true;
+        break;
+    default:
+        data->single_color_kbd = regval & KBD_WHITE_ONLY;
+        break;
+    }
+
+    if (data->single_color_kbd) {
+        init_data.default_label = "white:" LED_FUNCTION_KBD_BACKLIGHT;
+        data->kbd_led_cdev.max_brightness = data->kbd_led_max_brightness;
+        data->kbd_led_cdev.color = LED_COLOR_ID_WHITE;
+        data->kbd_led_cdev.flags = LED_BRIGHT_HW_CHANGED | 

LED_REJECT_NAME_CONFLICT;
+        data->kbd_led_cdev.brightness_set_blocking = uniwill_kbd_led_brightness_set;
+        data->kbd_led_cdev.brightness_get = uniwill_kbd_led_brightness_get; +
+        return devm_led_classdev_register_ext(data->dev, &data->kbd_led_cdev, &init_data);
+    }

drivers/platform/x86/uniwill/uniwill-acpi.c +5 -0
+
+    for (int i = 0; i < KBD_LED_CHANNELS; i++) {
+        data->kbd_led_mc_subled_info[i].color_index = color_indices[i];
+
+        ret = regmap_read(data->regmap, uniwill_kbd_led_channel_to_reg[i], 

&regval);
+        if (ret < 0)
+            return ret;
+
+        /*
+         * Make sure that the initial intensity value is not greater than +         * the maximum intensity.
+         */
+        if (regval > KBD_LED_MAX_INTENSITY) {
+            regval = KBD_LED_MAX_INTENSITY;
+            ret = regmap_write(data->regmap, uniwill_kbd_led_channel_to_reg[i], regval);
+            if (ret < 0)
+                return ret;

drivers/platform/x86/uniwill/uniwill-acpi.c +17 -0
+
+            needs_trigger = true;
+        }
+
+        if (regval)
+            intensity_all_zeros = false;
+
+        data->kbd_led_mc_subled_info[i].intensity = regval;
+        data->kbd_led_mc_subled_info[i].max_intensity = KBD_LED_MAX_INTENSITY;
+        data->kbd_led_mc_subled_info[i].channel = i;
+    }
+
+    /* See uniwill_kbd_led_mc_brightness_set() for an explaination. */
+    if (intensity_all_zeros) {
+        for (int i = 0; i < KBD_LED_CHANNELS; i++) {
+            data->kbd_led_mc_subled_info[i].intensity = 1;
+            ret = regmap_write(data->regmap, 

uniwill_kbd_led_channel_to_reg[i], 1);
+            if (ret < 0)
+                return ret;
+        }

drivers/platform/x86/uniwill/uniwill-acpi.c +6 -0
+
+        needs_trigger = true;
+    }
+
+    if (needs_trigger) {
+        ret = regmap_write_bits(data->regmap, EC_ADDR_TRIGGER, 

RGB_APPLY_COLOR,
+                    RGB_APPLY_COLOR);
+        if (ret < 0)
+            return ret;
+    }

drivers/platform/x86/uniwill/uniwill-acpi.c +7 -0
+
+    ret = devm_mutex_init(data->dev, &data->kbd_rgb_led_lock);
+    if (ret < 0)
+        return ret;
+
+    init_data.default_label = "multicolor:" LED_FUNCTION_KBD_BACKLIGHT;
+    data->kbd_led_mc_cdev.led_cdev.max_brightness = 

data->kbd_led_max_brightness;
+    data->kbd_led_mc_cdev.led_cdev.color = LED_COLOR_ID_MULTI; +    data->kbd_led_mc_cdev.led_cdev.flags = LED_BRIGHT_HW_CHANGED | LED_REJECT_NAME_CONFLICT;
+    data->kbd_led_mc_cdev.led_cdev.brightness_set_blocking = uniwill_kbd_led_mc_brightness_set;
+    data->kbd_led_mc_cdev.led_cdev.brightness_get = uniwill_kbd_led_mc_brightness_get;
+    data->kbd_led_mc_cdev.subled_info = data->kbd_led_mc_subled_info; +    data->kbd_led_mc_cdev.num_colors = KBD_LED_CHANNELS;
+
+    return devm_led_classdev_multicolor_register_ext(data->dev, &data->kbd_led_mc_cdev,
+                             &init_data);

drivers/platform/x86/uniwill/uniwill-acpi.c

Quoted 2 lines
drivers/platform/x86/uniwill/uniwill-acpi.c +2 -0
+}
+

Sorry I know I'm way to late with my comment, but I'm not at all a fan of how complex this whole function is:

- When we have to set max brightness on a per device basis anyway, we can
also set rgb or white only there and can skip this whole detection mechanism with the supported bits that are unreliable anyway

- we have a 2nd "supported devices/features list" inside this function which is abstracting away from the actual supported feature list

Quoted 8 lines
Quoted 6 lines

Should i try to spin up something much simpler, but that requires explicit setting in the device descriptor?

Best regards

Werner

Good point, but in this case i think having this small device list is OK, because the original control center does something similar.

yeah the original cc and tuxedo-drivers has these small lists all over the place ... also don't like it there

Quoted 2 lines

If we encounter a device that does not work with this strategy then we can indeed move the code into the device descriptor.

later we might not be able to get the information anymore which devices are rgb and which are white only when the supported devices lists grows, then we are stuck to reading the feature bits.

best regards,

Werner

Quoted 154 lines

Thanks,
Armin Wolf

Quoted 150 lines
Quoted 149 lines

  static unsigned int uniwill_sanitize_battery_threshold(unsigned int value) {
      /* 0 means "charging threshold not active" */

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -1789,6 +2082,31 @@ static int uniwill_notifier_call(struct 

notifier_block *nb, unsigned long action sysfs_notify(&data->dev->kobj, NULL, "fn_lock"); return NOTIFY_OK;
+    case UNIWILL_OSD_KB_LED_LEVEL0:
+        if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+            return NOTIFY_DONE;
+
+        return notifier_from_errno(uniwill_notify_kbd_led(data, 0)); +    case UNIWILL_OSD_KB_LED_LEVEL1:
+        if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+            return NOTIFY_DONE;
+
+        return notifier_from_errno(uniwill_notify_kbd_led(data, 1)); +    case UNIWILL_OSD_KB_LED_LEVEL2:
+        if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+            return NOTIFY_DONE;
+
+        return notifier_from_errno(uniwill_notify_kbd_led(data, 2)); +    case UNIWILL_OSD_KB_LED_LEVEL3:
+        if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+            return NOTIFY_DONE;
+
+        return notifier_from_errno(uniwill_notify_kbd_led(data, 3)); +    case UNIWILL_OSD_KB_LED_LEVEL4:
+        if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+            return NOTIFY_DONE;
+
+        return notifier_from_errno(uniwill_notify_kbd_led(data, 4)); default:
          mutex_lock(&data->input_lock); sparse_keymap_report_event(data->input_device, action, 1, true);

drivers/platform/x86/uniwill/uniwill-acpi.c +18 -0
@@ -1842,6 +2160,7 @@ static int uniwill_ec_init(struct uniwill_data *data)
       if (ret < 0)
           return ret;
   +    data->project_id = value;
       dev_dbg(data->dev, "Project ID: %u\n", value);
         ret = regmap_set_bits(data->regmap, EC_ADDR_AP_OEM, ENABLE_MANUAL_CTRL);
@@ -1885,6 +2204,7 @@ static int uniwill_probe(struct platform_device *pdev)
           return ret;
         data->features = device_descriptor.features;
+    data->kbd_led_max_brightness = device_descriptor.kbd_led_max_brightness;
         /*
        * Some devices might need to perform some device-specific initialization steps
@@ -1905,6 +2225,10 @@ static int uniwill_probe(struct platform_device *pdev)
       if (ret < 0)
           return ret;
   +    ret = uniwill_kbd_led_init(data);
+    if (ret < 0)
+        return ret;
+
       ret = uniwill_hwmon_init(data);
       if (ret < 0)
           return ret;
@@ -1976,6 +2300,31 @@ static int uniwill_suspend_battery(struct 
 uniwill_data *data)
       return regmap_read(data->regmap, EC_ADDR_CHARGE_CTRL, &data->last_charge_ctrl);
   }
   +static int uniwill_suspend_kbd_led(struct uniwill_data *data)
+{
+    unsigned int regval;
+    int ret;
+
+    if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+        return 0;
+
+    ret = regmap_read(data->regmap, EC_ADDR_KBD_STATUS, &regval);
+    if (ret < 0)
+        return ret;
+
+    /*
+     * Save the current keyboard backlight settings in order to restore them
+     * during resume. We cannot use the regmap code for that since this 

register
+     * needs to be declared as volatile because the brightness can be changed +     * by the EC.
+     */
+    data->last_kbd_status = regval;
+    FIELD_MODIFY(KBD_BRIGHTNESS_MASK, &regval, 0);
+    regval |= KBD_APPLY | KBD_POWER_OFF;

drivers/platform/x86/uniwill/uniwill-acpi.c +4 -0
+
+    return regmap_write(data->regmap, EC_ADDR_KBD_STATUS, regval);
+}
+

  static int uniwill_suspend_nvidia_ctgp(struct uniwill_data *data) {
      if (!uniwill_device_supports(data, UNIWILL_FEATURE_NVIDIA_CTGP_CONTROL))

drivers/platform/x86/uniwill/uniwill-acpi.c +19 -0
@@ -2006,6 +2355,10 @@ static int uniwill_suspend(struct device *dev)
       if (ret < 0)
           return ret;
   +    ret = uniwill_suspend_kbd_led(data);
+    if (ret < 0)
+        return ret;
+
       ret = uniwill_suspend_nvidia_ctgp(data);
       if (ret < 0)
           return ret;
@@ -2052,6 +2405,23 @@ static int uniwill_resume_battery(struct uniwill_data 
 *data)
       return 0;
   }
   +static int uniwill_resume_kbd_led(struct uniwill_data *data)
+{
+    int ret;
+
+    if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+        return 0;
+
+    ret = regmap_write(data->regmap, EC_ADDR_KBD_STATUS, 
 data->last_kbd_status | KBD_APPLY);
+    if (ret < 0)
+        return ret;
+
+    if (data->single_color_kbd)
+        return 0;
+
+    return regmap_write_bits(data->regmap, EC_ADDR_TRIGGER, 
 RGB_APPLY_COLOR, RGB_APPLY_COLOR);
+}
+

  static int uniwill_resume_nvidia_ctgp(struct uniwill_data *data) {
      if (!uniwill_device_supports(data, UNIWILL_FEATURE_NVIDIA_CTGP_CONTROL))

drivers/platform/x86/uniwill/uniwill-acpi.c +5 -0
@@ -2096,6 +2466,10 @@ static int uniwill_resume(struct device *dev)
       if (ret < 0)
           return ret;
   +    ret = uniwill_resume_kbd_led(data);
+    if (ret < 0)
+        return ret;
+
       ret = uniwill_resume_nvidia_ctgp(data);
       if (ret < 0)
           return ret;
@@ -2745,6 +3119,8 @@ static int __init uniwill_init(void)
       if (force) {
           /* Assume that the device supports all features except the charge limit */
           device_descriptor.features = UINT_MAX & ~UNIWILL_FEATURE_BATTERY_CHARGE_LIMIT;
+        /* Some models only support 3 brightness levels */
+        device_descriptor.kbd_led_max_brightness = 4;
           pr_warn("Enabling potentially unsupported features\n");
       }
author maintainer
#5 lore raw

Re: [PATCH 1/7] platform/x86: uniwill-laptop: Add keyboard backlight support

Am 08.07.26 um 22:15 schrieb Werner Sembach:

Quoted 521 lines

Am 08.07.26 um 22:08 schrieb Armin Wolf:

Quoted 510 lines

Am 08.07.26 um 21:11 schrieb Werner Sembach:

Quoted 508 lines

Hi,

Am 30.05.26 um 19:08 schrieb Armin Wolf:

Quoted 494 lines

Many Uniwill-based devices support either a white-only or fully features RGB keyboard backlight. Add support for this feature and handle the associated WMI events.

---
  .../admin-guide/laptops/uniwill-laptop.rst    |  13 + drivers/platform/x86/uniwill/uniwill-acpi.c   | 392
+++++++++++++++++-

  2 files changed, 397 insertions(+), 8 deletions(-)
Documentation/admin-guide/laptops/uniwill-laptop.rst +0 -0
index 24b41dbab886..2b1e5da703a5 100644
@@ -77,6 +77,19 @@ LED class device. The default name of this LED 

class device is ``uniwill:multico
  See Documentation/ABI/testing/sysfs-driver-uniwill-laptop for details on how to control the various animation modes of the lightbar.
  +Keyboard Backlight
+------------------

Documentation/admin-guide/laptops/uniwill-laptop.rst +2 -0
+
+The ``uniwill-laptop`` driver supports controlling the keyboard 

backlight using the standard
+LED class interface. The default name of this LED class device is ``uniwill:white:kbd_backlight``
+when the keyboard backlight supports only a single color, or ``uniwill:multicolor:kbd_backlight``
+when the keyboard backlight supports RGB colors. The maximum intensity for each color channel

Documentation/admin-guide/laptops/uniwill-laptop.rst +3 -0
+in RGB mode is 50.
+
+Keep in mind that due to hardware design choices, the driver does 

not support the RGB value
+``0x000000`` (black), instead it will fall back to ``0x010101``
(faint white). In order to
+disable the keyboard backlight, the standard LED brightness
setting has to be used instead.
+
  Configurable TGP
  ----------------
  diff --git a/drivers/platform/x86/uniwill/uniwill-acpi.c b/drivers/platform/x86/uniwill/uniwill-acpi.c index ab063ead45b9..fd040197b189 100644

drivers/platform/x86/uniwill/uniwill-acpi.c +24 -0
@@ -110,8 +110,31 @@
   #define EC_ADDR_BAT_CYCLE_COUNT_2    0x04A7
     #define EC_ADDR_PROJECT_ID        0x0740
+#define PROJECT_ID_NONE            0x00
+#define PROJECT_ID_GI            0x01
+#define PROJECT_ID_GJ            0x02
+#define PROJECT_ID_GK            0x03
+#define PROJECT_ID_GICN            0x04
+#define PROJECT_ID_GJCN            0x05
+#define PROJECT_ID_GK5CN_X        0x06
+#define PROJECT_ID_GK7CN_S        0x07
+#define PROJECT_ID_GK7CPCS_GK5CQ7Z    0x08
+#define PROJECT_ID_PF            0x09
+#define PROJECT_ID_GK5CP_4X_5X_6X    0x0A
+#define PROJECT_ID_IDP            0x0B
+#define PROJECT_ID_IDY_6Y        0x0C
+#define PROJECT_ID_IDY_7Y        0x0D
+#define PROJECT_ID_PF4MU_PF4MN_PF5MU    0x0E
+#define PROJECT_ID_CML_GAMING        0x0F
+#define PROJECT_ID_GK7NXXR        0x10
+#define PROJECT_ID_GM5MU1Y        0x11
   #define PROJECT_ID_PH4TRX1        0x12
+#define PROJECT_ID_PH4TUX1        0x13
+#define PROJECT_ID_PH4TQX1        0x14
   #define PROJECT_ID_PH6TRX1        0x15
+#define PROJECT_ID_PH6TQXX        0x16
+#define PROJECT_ID_PHXAXXX        0x17
+#define PROJECT_ID_PHXPXXX        0x18
     #define EC_ADDR_AP_OEM            0x0741
   #define    ENABLE_MANUAL_CTRL        BIT(0)
@@ -214,6 +237,7 @@
   #define FAN_TABLE_OFFICE_MODE        BIT(2)
   #define FAN_V3                BIT(3)
   #define DEFAULT_MODE            BIT(4)
+#define ENABLE_CHINA_MODE        BIT(6)
     #define EC_ADDR_PL1_SETTING        0x0783

  @@ -225,11 +249,11 @@
  #define FAN_CURVE_LENGTH        5
    #define EC_ADDR_KBD_STATUS        0x078C

drivers/platform/x86/uniwill/uniwill-acpi.c +2 -2
-#define KBD_WHITE_ONLY            BIT(0)    // ~single color
-#define KBD_SINGLE_COLOR_OFF        BIT(1)
+#define KBD_WHITE_ONLY            BIT(0)
+#define KBD_POWER_OFF            BIT(1)

  #define KBD_TURBO_LEVEL_MASK        GENMASK(3, 2) #define KBD_APPLY            BIT(4)

drivers/platform/x86/uniwill/uniwill-acpi.c +1 -1
-#define KBD_BRIGHTNESS            GENMASK(7, 5)
+#define KBD_BRIGHTNESS_MASK        GENMASK(7, 5)

    #define EC_ADDR_FAN_CTRL        0x078E
  #define FAN3P5                BIT(1)

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -320,6 +344,9 @@
   #define LED_CHANNELS        3
   #define LED_MAX_BRIGHTNESS    200

  +#define KBD_LED_CHANNELS    3

drivers/platform/x86/uniwill/uniwill-acpi.c +2 -0
+#define KBD_LED_MAX_INTENSITY    50
+

  #define UNIWILL_FEATURE_FN_LOCK            BIT(0) #define UNIWILL_FEATURE_SUPER_KEY        BIT(1) #define UNIWILL_FEATURE_TOUCHPAD_TOGGLE        BIT(2)

drivers/platform/x86/uniwill/uniwill-acpi.c +2 -0
@@ -333,6 +360,7 @@
   #define UNIWILL_FEATURE_SECONDARY_FAN        BIT(9)
   #define UNIWILL_FEATURE_NVIDIA_CTGP_CONTROL    BIT(10)
   #define UNIWILL_FEATURE_USB_C_POWER_PRIORITY    BIT(11)
+#define UNIWILL_FEATURE_KEYBOARD_BACKLIGHT    BIT(12)
     enum usb_c_power_priority_options {
       USB_C_POWER_PRIORITY_CHARGING = 0,
@@ -344,6 +372,7 @@ struct uniwill_data {
       acpi_handle handle;
       struct regmap *regmap;
       unsigned int features;
+    u8 project_id;
       struct acpi_battery_hook hook;

      struct mutex battery_lock;    /* Protects the list of currently registered batteries */ union {

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -362,6 +391,18 @@ struct uniwill_data {

      struct mutex led_lock;        /* Protects writes to the lightbar registers */ struct led_classdev_mc led_mc_cdev;
      struct mc_subled led_mc_subled_info[LED_CHANNELS];
+    bool single_color_kbd;
+    u8 kbd_led_max_brightness;
+    unsigned int last_kbd_status;
+    union {
+        struct {
+            /* Protects writes to the RGB keyboard backlight registers */
+            struct mutex kbd_rgb_led_lock;
+            struct led_classdev_mc kbd_led_mc_cdev;
+            struct mc_subled kbd_led_mc_subled_info[KBD_LED_CHANNELS];
+        };
+        struct led_classdev kbd_led_cdev;
+    };
      struct mutex input_lock;    /* Protects input sequence during notify */ struct input_dev *input_device;
      struct notifier_block nb;

drivers/platform/x86/uniwill/uniwill-acpi.c +1 -0
@@ -376,6 +417,7 @@ struct uniwill_battery_entry {
     struct uniwill_device_descriptor {
       unsigned int features;
+    u8 kbd_led_max_brightness;
       /* Executed during driver probing */
       int (*probe)(struct uniwill_data *data);
   };
@@ -427,6 +469,9 @@ static const struct key_entry uniwill_keymap[] = {
       { KE_KEY,       UNIWILL_OSD_KBDILLUMDOWN, { KEY_KBDILLUMDOWN }},
       { KE_KEY,       UNIWILL_OSD_KBDILLUMUP, { KEY_KBDILLUMUP }},

  +    /* Reported when the EC changed the keyboard backlight brightness */ +    { KE_IGNORE,    UNIWILL_OSD_BACKLIGHT_LEVEL_CHANGE, {
KEY_UNKNOWN }},
+
      /* Reported when the user wants to toggle the microphone mute status */ { KE_KEY,       UNIWILL_OSD_MIC_MUTE, { KEY_MICMUTE }},
  @@ -435,11 +480,6 @@ static const struct key_entry uniwill_keymap[] = { /* Reported when the user wants to toggle the brightness of the keyboard */ { KE_KEY,       UNIWILL_OSD_KBDILLUMTOGGLE, { KEY_KBDILLUMTOGGLE }}, -    { KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL0, {
KEY_KBDILLUMTOGGLE }},
-    { KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL1, {
KEY_KBDILLUMTOGGLE }},
-    { KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL2, {
KEY_KBDILLUMTOGGLE }},
-    { KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL3, {
KEY_KBDILLUMTOGGLE }},
-    { KE_KEY,       UNIWILL_OSD_KB_LED_LEVEL4, {
KEY_KBDILLUMTOGGLE }},
        /* FIXME: find out the exact meaning of those events */
      { KE_IGNORE,    UNIWILL_OSD_BAT_CHARGE_FULL_24_H, { KEY_UNKNOWN }},

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -547,6 +587,11 @@ static bool uniwill_writeable_reg(struct 
 device *dev, unsigned int reg)

      case EC_ADDR_LIGHTBAR_AC_BLUE:
      case EC_ADDR_BIOS_OEM:
      case EC_ADDR_TRIGGER:
+    case EC_ADDR_RGB_RED:
+    case EC_ADDR_RGB_GREEN:
+    case EC_ADDR_RGB_BLUE:
+    case EC_ADDR_BIOS_OEM_2:
+    case EC_ADDR_KBD_STATUS:
      case EC_ADDR_OEM_4:
      case EC_ADDR_CHARGE_CTRL:
      case EC_ADDR_LIGHTBAR_BAT_CTRL:

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -583,8 +628,14 @@ static bool uniwill_readable_reg(struct device 
 *dev, unsigned int reg)

      case EC_ADDR_BIOS_OEM:
      case EC_ADDR_PWM_1:
      case EC_ADDR_PWM_2:
+    case EC_ADDR_SUPPORT_2:
      case EC_ADDR_TRIGGER:
      case EC_ADDR_SWITCH_STATUS:
+    case EC_ADDR_RGB_RED:
+    case EC_ADDR_RGB_GREEN:
+    case EC_ADDR_RGB_BLUE:
+    case EC_ADDR_BIOS_OEM_2:
+    case EC_ADDR_KBD_STATUS:
      case EC_ADDR_OEM_4:
      case EC_ADDR_CHARGE_CTRL:
      case EC_ADDR_LIGHTBAR_BAT_CTRL:

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -616,8 +667,10 @@ static bool uniwill_volatile_reg(struct device 
 *dev, unsigned int reg)

      case EC_ADDR_BIOS_OEM:
      case EC_ADDR_PWM_1:
      case EC_ADDR_PWM_2:
+    case EC_ADDR_SUPPORT_2:
      case EC_ADDR_TRIGGER:
      case EC_ADDR_SWITCH_STATUS:
+    case EC_ADDR_KBD_STATUS:
      case EC_ADDR_OEM_4:
      case EC_ADDR_CHARGE_CTRL:
      case EC_ADDR_USB_C_POWER_PRIORITY:

drivers/platform/x86/uniwill/uniwill-acpi.c +27 -0
@@ -1441,6 +1494,246 @@ static int uniwill_led_init(struct 
 uniwill_data *data)
                                &init_data);
   }
   +static int uniwill_notify_kbd_led(struct uniwill_data *data, int brightness)
+{
+    struct led_classdev *led_cdev;
+    int ret;
+
+    if (data->single_color_kbd)
+        led_cdev = &data->kbd_led_cdev;
+    else
+        led_cdev = &data->kbd_led_mc_cdev.led_cdev;
+
+    guard(mutex)(&led_cdev->led_access);
+
+    /* Sync the LED brightness with the actual hardware state */
+    ret = led_update_brightness(led_cdev);
+    if (ret < 0)
+        return ret;
+
+    led_classdev_notify_brightness_hw_changed(led_cdev, brightness);
+
+    return 0;
+}
+
+#define KBD_LED_MASK    (KBD_BRIGHTNESS_MASK | KBD_APPLY | 
 KBD_POWER_OFF)
+
+static int uniwill_kbd_led_write_brightness(struct uniwill_data 
 *data, int brightness)
+{
+    /* KBD_POWER_OFF is always implicitly cleared */
+    unsigned int regval = FIELD_PREP(KBD_BRIGHTNESS_MASK, 

brightness) | KBD_APPLY;
+
+    /* We must ensure that the "apply" bit is always written */ +    return regmap_write_bits(data->regmap, EC_ADDR_KBD_STATUS, KBD_LED_MASK, regval);

drivers/platform/x86/uniwill/uniwill-acpi.c +12 -0
+}
+
+static int uniwill_kbd_led_read_brightness(struct uniwill_data *data)
+{
+    unsigned int regval;
+    int ret;
+
+    ret = regmap_read(data->regmap, EC_ADDR_KBD_STATUS, &regval);
+    if (ret < 0)
+        return ret;
+
+    return min(FIELD_GET(KBD_BRIGHTNESS_MASK, regval), 

data->kbd_led_max_brightness);

drivers/platform/x86/uniwill/uniwill-acpi.c +3 -0
+}
+
+static int uniwill_kbd_led_brightness_set(struct led_classdev 

*led_cdev,
+                      enum led_brightness brightness) +{
+    struct uniwill_data *data = container_of(led_cdev, struct uniwill_data, kbd_led_cdev);

drivers/platform/x86/uniwill/uniwill-acpi.c +5 -0
+
+    return uniwill_kbd_led_write_brightness(data, brightness);
+}
+
+static enum led_brightness uniwill_kbd_led_brightness_get(struct 

led_classdev *led_cdev)
+{
+    struct uniwill_data *data = container_of(led_cdev, struct uniwill_data, kbd_led_cdev);

drivers/platform/x86/uniwill/uniwill-acpi.c +5 -0
+
+    return uniwill_kbd_led_read_brightness(data);
+}
+
+static const unsigned int 

uniwill_kbd_led_channel_to_reg[KBD_LED_CHANNELS] = { +    EC_ADDR_RGB_RED,
+    EC_ADDR_RGB_GREEN,
+    EC_ADDR_RGB_BLUE,

drivers/platform/x86/uniwill/uniwill-acpi.c +3 -0
+};
+
+static int uniwill_kbd_led_mc_brightness_set(struct led_classdev 

*led_cdev,
+                         enum led_brightness brightness) +{
+    struct led_classdev_mc *led_mc_cdev = lcdev_to_mccdev(led_cdev); +    struct uniwill_data *data = container_of(led_mc_cdev, struct uniwill_data, kbd_led_mc_cdev);
+    unsigned int min_intensity = 0;
+    unsigned int regval;
+    int ret;

drivers/platform/x86/uniwill/uniwill-acpi.c +5 -0
+
+    guard(mutex)(&data->kbd_rgb_led_lock);
+
+    /*
+     * The EC interprets a RGB value of 0x000000 as a command to 

restore
+     * the device-specfic default RGB value. Work around this by writing
+     * a RGB value of 0x010101 (faint white) instead. +     */
+    if (data->kbd_led_mc_subled_info[0].intensity == 0 && +        data->kbd_led_mc_subled_info[1].intensity == 0 && +        data->kbd_led_mc_subled_info[2].intensity == 0) +        min_intensity = 1;
+
+    for (int i = 0; i < KBD_LED_CHANNELS; i++) {
+        regval = max(data->kbd_led_mc_subled_info[i].intensity, min_intensity);
+        ret = regmap_write(data->regmap, uniwill_kbd_led_channel_to_reg[i], regval);
+        if (ret < 0)
+            return ret;
+    }
+
+    ret = regmap_write_bits(data->regmap, EC_ADDR_TRIGGER, RGB_APPLY_COLOR, RGB_APPLY_COLOR);
+    if (ret < 0)
+        return ret;

drivers/platform/x86/uniwill/uniwill-acpi.c +5 -0
+
+    return uniwill_kbd_led_write_brightness(data, brightness);
+}
+
+static enum led_brightness 

uniwill_kbd_led_mc_brightness_get(struct led_classdev *led_cdev) +{
+    struct led_classdev_mc *led_mc_cdev = lcdev_to_mccdev(led_cdev); +    struct uniwill_data *data = container_of(led_mc_cdev, struct uniwill_data, kbd_led_mc_cdev);

drivers/platform/x86/uniwill/uniwill-acpi.c +21 -0
+
+    return uniwill_kbd_led_read_brightness(data);
+}
+
+static int uniwill_kbd_led_init(struct uniwill_data *data)
+{
+    unsigned int color_indices[KBD_LED_CHANNELS] = {
+        LED_COLOR_ID_RED,
+        LED_COLOR_ID_GREEN,
+        LED_COLOR_ID_BLUE,
+    };
+    struct led_init_data init_data = {
+        .devicename = DRIVER_NAME,
+        .devname_mandatory = true,
+    };
+    bool intensity_all_zeros = true;
+    bool needs_trigger = false;
+    unsigned int regval;
+    int ret;
+
+    if (!uniwill_device_supports(data, 

UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+        return 0;

drivers/platform/x86/uniwill/uniwill-acpi.c +7 -0
+
+    ret = regmap_read(data->regmap, EC_ADDR_SUPPORT_2, &regval);
+    if (ret < 0)
+        return ret;
+
+    if (!(regval & CHINA_MODE)) {
+        ret = regmap_set_bits(data->regmap, EC_ADDR_BIOS_OEM_2, 

ENABLE_CHINA_MODE);
+        if (ret < 0)
+            return ret;
+    }

drivers/platform/x86/uniwill/uniwill-acpi.c +30 -0
+
+    ret = regmap_read(data->regmap, EC_ADDR_KBD_STATUS, &regval);
+    if (ret < 0)
+        return ret;
+
+    regval |= KBD_APPLY;
+    regval &= ~KBD_POWER_OFF;
+    ret = regmap_write(data->regmap, EC_ADDR_KBD_STATUS, regval);
+    if (ret < 0)
+        return ret;
+
+    switch (data->project_id) {
+    case PROJECT_ID_PF:
+    case PROJECT_ID_PF4MU_PF4MN_PF5MU:
+    case PROJECT_ID_PH4TRX1:
+    case PROJECT_ID_PH4TUX1:
+    case PROJECT_ID_PH4TQX1:
+    case PROJECT_ID_PH6TRX1:
+    case PROJECT_ID_PH6TQXX:
+    case PROJECT_ID_PHXAXXX:
+    case PROJECT_ID_PHXPXXX:
+        data->single_color_kbd = true;
+        break;
+    default:
+        data->single_color_kbd = regval & KBD_WHITE_ONLY;
+        break;
+    }
+
+    if (data->single_color_kbd) {
+        init_data.default_label = "white:" 

LED_FUNCTION_KBD_BACKLIGHT;
+        data->kbd_led_cdev.max_brightness = data->kbd_led_max_brightness;
+        data->kbd_led_cdev.color = LED_COLOR_ID_WHITE; +        data->kbd_led_cdev.flags = LED_BRIGHT_HW_CHANGED | LED_REJECT_NAME_CONFLICT;
+        data->kbd_led_cdev.brightness_set_blocking = uniwill_kbd_led_brightness_set;
+        data->kbd_led_cdev.brightness_get = uniwill_kbd_led_brightness_get;
+
+        return devm_led_classdev_register_ext(data->dev, &data->kbd_led_cdev, &init_data);
+    }
+
+    for (int i = 0; i < KBD_LED_CHANNELS; i++) {
+        data->kbd_led_mc_subled_info[i].color_index = color_indices[i];
+
+        ret = regmap_read(data->regmap, uniwill_kbd_led_channel_to_reg[i], &regval);
+        if (ret < 0)
+            return ret;
+
+        /*
+         * Make sure that the initial intensity value is not greater than
+         * the maximum intensity.
+         */
+        if (regval > KBD_LED_MAX_INTENSITY) {
+            regval = KBD_LED_MAX_INTENSITY;
+            ret = regmap_write(data->regmap, uniwill_kbd_led_channel_to_reg[i], regval);
+            if (ret < 0)
+                return ret;

drivers/platform/x86/uniwill/uniwill-acpi.c +9 -0
+
+            needs_trigger = true;
+        }
+
+        if (regval)
+            intensity_all_zeros = false;
+
+        data->kbd_led_mc_subled_info[i].intensity = regval;
+        data->kbd_led_mc_subled_info[i].max_intensity = 

KBD_LED_MAX_INTENSITY;
+        data->kbd_led_mc_subled_info[i].channel = i; +    }
+
+    /* See uniwill_kbd_led_mc_brightness_set() for an explaination. */
+    if (intensity_all_zeros) {
+        for (int i = 0; i < KBD_LED_CHANNELS; i++) { +            data->kbd_led_mc_subled_info[i].intensity = 1; +            ret = regmap_write(data->regmap, uniwill_kbd_led_channel_to_reg[i], 1);
+            if (ret < 0)
+                return ret;
+        }

drivers/platform/x86/uniwill/uniwill-acpi.c +6 -0
+
+        needs_trigger = true;
+    }
+
+    if (needs_trigger) {
+        ret = regmap_write_bits(data->regmap, EC_ADDR_TRIGGER, 

RGB_APPLY_COLOR,
+                    RGB_APPLY_COLOR);
+        if (ret < 0)
+            return ret;
+    }

drivers/platform/x86/uniwill/uniwill-acpi.c +6 -0
+
+    ret = devm_mutex_init(data->dev, &data->kbd_rgb_led_lock);
+    if (ret < 0)
+        return ret;
+
+    init_data.default_label = "multicolor:" 

LED_FUNCTION_KBD_BACKLIGHT;
+    data->kbd_led_mc_cdev.led_cdev.max_brightness = data->kbd_led_max_brightness;
+    data->kbd_led_mc_cdev.led_cdev.color = LED_COLOR_ID_MULTI; +    data->kbd_led_mc_cdev.led_cdev.flags = LED_BRIGHT_HW_CHANGED | LED_REJECT_NAME_CONFLICT;
+ data->kbd_led_mc_cdev.led_cdev.brightness_set_blocking = uniwill_kbd_led_mc_brightness_set;
+    data->kbd_led_mc_cdev.led_cdev.brightness_get = uniwill_kbd_led_mc_brightness_get;
+    data->kbd_led_mc_cdev.subled_info = data->kbd_led_mc_subled_info; +    data->kbd_led_mc_cdev.num_colors = KBD_LED_CHANNELS;
+
+    return devm_led_classdev_multicolor_register_ext(data->dev, &data->kbd_led_mc_cdev,
+                             &init_data);

drivers/platform/x86/uniwill/uniwill-acpi.c

Quoted 2 lines
drivers/platform/x86/uniwill/uniwill-acpi.c +2 -0
+}
+

Sorry I know I'm way to late with my comment, but I'm not at all a fan of how complex this whole function is:

- When we have to set max brightness on a per device basis anyway,
we can also set rgb or white only there and can skip this whole detection mechanism with the supported bits that are unreliable anyway

- we have a 2nd "supported devices/features list" inside this function which is abstracting away from the actual supported feature list

Quoted 8 lines
Quoted 6 lines

Should i try to spin up something much simpler, but that requires explicit setting in the device descriptor?

Best regards

Werner

Good point, but in this case i think having this small device list is OK, because the original control center does something similar.

yeah the original cc and tuxedo-drivers has these small lists all over the place ... also don't like it there

Quoted 9 lines
Quoted 2 lines

If we encounter a device that does not work with this strategy then we can indeed move the code into the device descriptor.

later we might not be able to get the information anymore which devices are rgb and which are white only when the supported devices lists grows, then we are stuck to reading the feature bits.

best regards,

Werner

Good point, in this case using the device descriptor for this feature detection might indeed be better in the long term.

Do you want to send the patches or should i do it?

Thanks,
Armin Wolf

Quoted 163 lines
Quoted 162 lines

Thanks,
Armin Wolf

Quoted 158 lines
Quoted 157 lines

  static unsigned int uniwill_sanitize_battery_threshold(unsigned int value) {
      /* 0 means "charging threshold not active" */

drivers/platform/x86/uniwill/uniwill-acpi.c +0 -0
@@ -1789,6 +2082,31 @@ static int uniwill_notifier_call(struct 

notifier_block *nb, unsigned long action sysfs_notify(&data->dev->kobj, NULL, "fn_lock"); return NOTIFY_OK;
+    case UNIWILL_OSD_KB_LED_LEVEL0:
+        if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+            return NOTIFY_DONE;
+
+        return notifier_from_errno(uniwill_notify_kbd_led(data, 0)); +    case UNIWILL_OSD_KB_LED_LEVEL1:
+        if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+            return NOTIFY_DONE;
+
+        return notifier_from_errno(uniwill_notify_kbd_led(data, 1)); +    case UNIWILL_OSD_KB_LED_LEVEL2:
+        if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+            return NOTIFY_DONE;
+
+        return notifier_from_errno(uniwill_notify_kbd_led(data, 2)); +    case UNIWILL_OSD_KB_LED_LEVEL3:
+        if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+            return NOTIFY_DONE;
+
+        return notifier_from_errno(uniwill_notify_kbd_led(data, 3)); +    case UNIWILL_OSD_KB_LED_LEVEL4:
+        if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+            return NOTIFY_DONE;
+
+        return notifier_from_errno(uniwill_notify_kbd_led(data, 4)); default:
          mutex_lock(&data->input_lock); sparse_keymap_report_event(data->input_device, action, 1, true);

drivers/platform/x86/uniwill/uniwill-acpi.c +4 -0
@@ -1842,6 +2160,7 @@ static int uniwill_ec_init(struct 
 uniwill_data *data)
       if (ret < 0)
           return ret;
   +    data->project_id = value;
       dev_dbg(data->dev, "Project ID: %u\n", value);
         ret = regmap_set_bits(data->regmap, EC_ADDR_AP_OEM, ENABLE_MANUAL_CTRL);
@@ -1885,6 +2204,7 @@ static int uniwill_probe(struct 
 platform_device *pdev)
           return ret;
         data->features = device_descriptor.features;
+    data->kbd_led_max_brightness = 
 device_descriptor.kbd_led_max_brightness;
         /*
        * Some devices might need to perform some device-specific initialization steps
@@ -1905,6 +2225,10 @@ static int uniwill_probe(struct 
 platform_device *pdev)
       if (ret < 0)
           return ret;
   +    ret = uniwill_kbd_led_init(data);
+    if (ret < 0)
+        return ret;
+
       ret = uniwill_hwmon_init(data);
       if (ret < 0)

          return ret;

drivers/platform/x86/uniwill/uniwill-acpi.c +13 -0
@@ -1976,6 +2300,31 @@ static int uniwill_suspend_battery(struct 
 uniwill_data *data)
       return regmap_read(data->regmap, EC_ADDR_CHARGE_CTRL, &data->last_charge_ctrl);
   }
   +static int uniwill_suspend_kbd_led(struct uniwill_data *data)
+{
+    unsigned int regval;
+    int ret;
+
+    if (!uniwill_device_supports(data, 
 UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+        return 0;
+
+    ret = regmap_read(data->regmap, EC_ADDR_KBD_STATUS, &regval);
+    if (ret < 0)
+        return ret;
+
+    /*
+     * Save the current keyboard backlight settings in order to 

restore them
+     * during resume. We cannot use the regmap code for that since this register
+     * needs to be declared as volatile because the brightness can be changed
+     * by the EC.
+     */
+    data->last_kbd_status = regval;
+    FIELD_MODIFY(KBD_BRIGHTNESS_MASK, &regval, 0);
+    regval |= KBD_APPLY | KBD_POWER_OFF;

drivers/platform/x86/uniwill/uniwill-acpi.c +4 -0
+
+    return regmap_write(data->regmap, EC_ADDR_KBD_STATUS, regval);
+}
+

  static int uniwill_suspend_nvidia_ctgp(struct uniwill_data *data) {
      if (!uniwill_device_supports(data, UNIWILL_FEATURE_NVIDIA_CTGP_CONTROL))

drivers/platform/x86/uniwill/uniwill-acpi.c +17 -0
@@ -2006,6 +2355,10 @@ static int uniwill_suspend(struct device *dev)
       if (ret < 0)
           return ret;
   +    ret = uniwill_suspend_kbd_led(data);
+    if (ret < 0)
+        return ret;
+
       ret = uniwill_suspend_nvidia_ctgp(data);
       if (ret < 0)
           return ret;
@@ -2052,6 +2405,23 @@ static int uniwill_resume_battery(struct 
 uniwill_data *data)
       return 0;
   }
   +static int uniwill_resume_kbd_led(struct uniwill_data *data)
+{
+    int ret;
+
+    if (!uniwill_device_supports(data, 
 UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+        return 0;
+
+    ret = regmap_write(data->regmap, EC_ADDR_KBD_STATUS, 
 data->last_kbd_status | KBD_APPLY);
+    if (ret < 0)
+        return ret;
+
+    if (data->single_color_kbd)
+        return 0;
+
+    return regmap_write_bits(data->regmap, EC_ADDR_TRIGGER, 

RGB_APPLY_COLOR, RGB_APPLY_COLOR);

drivers/platform/x86/uniwill/uniwill-acpi.c +2 -0
+}
+

  static int uniwill_resume_nvidia_ctgp(struct uniwill_data *data) {
      if (!uniwill_device_supports(data, UNIWILL_FEATURE_NVIDIA_CTGP_CONTROL))

drivers/platform/x86/uniwill/uniwill-acpi.c +5 -0
@@ -2096,6 +2466,10 @@ static int uniwill_resume(struct device *dev)
       if (ret < 0)
           return ret;
   +    ret = uniwill_resume_kbd_led(data);
+    if (ret < 0)
+        return ret;
+
       ret = uniwill_resume_nvidia_ctgp(data);
       if (ret < 0)
           return ret;
@@ -2745,6 +3119,8 @@ static int __init uniwill_init(void)
       if (force) {
           /* Assume that the device supports all features except the charge limit */
           device_descriptor.features = UINT_MAX & ~UNIWILL_FEATURE_BATTERY_CHARGE_LIMIT;
+        /* Some models only support 3 brightness levels */
+        device_descriptor.kbd_led_max_brightness = 4;
           pr_warn("Enabling potentially unsupported features\n");
       }
#6 lore raw

Re: [PATCH 1/7] platform/x86: uniwill-laptop: Add keyboard backlight support

[...]

Quoted 169 lines
Quoted 169 lines
Quoted 155 lines
Quoted 155 lines
Quoted 144 lines
drivers/platform/x86/uniwill/uniwill-acpi.c +26 -0
+
+static int uniwill_kbd_led_init(struct uniwill_data *data)
+{
+    unsigned int color_indices[KBD_LED_CHANNELS] = {
+        LED_COLOR_ID_RED,
+        LED_COLOR_ID_GREEN,
+        LED_COLOR_ID_BLUE,
+    };
+    struct led_init_data init_data = {
+        .devicename = DRIVER_NAME,
+        .devname_mandatory = true,
+    };
+    bool intensity_all_zeros = true;
+    bool needs_trigger = false;
+    unsigned int regval;
+    int ret;
+
+    if (!uniwill_device_supports(data, UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+        return 0;
+
+    ret = regmap_read(data->regmap, EC_ADDR_SUPPORT_2, &regval);
+    if (ret < 0)
+        return ret;
+
+    if (!(regval & CHINA_MODE)) {
+        ret = regmap_set_bits(data->regmap, EC_ADDR_BIOS_OEM_2, 

ENABLE_CHINA_MODE);
+        if (ret < 0)
+            return ret;
+    }

drivers/platform/x86/uniwill/uniwill-acpi.c +33 -0
+
+    ret = regmap_read(data->regmap, EC_ADDR_KBD_STATUS, &regval);
+    if (ret < 0)
+        return ret;
+
+    regval |= KBD_APPLY;
+    regval &= ~KBD_POWER_OFF;
+    ret = regmap_write(data->regmap, EC_ADDR_KBD_STATUS, regval);
+    if (ret < 0)
+        return ret;
+
+    switch (data->project_id) {
+    case PROJECT_ID_PF:
+    case PROJECT_ID_PF4MU_PF4MN_PF5MU:
+    case PROJECT_ID_PH4TRX1:
+    case PROJECT_ID_PH4TUX1:
+    case PROJECT_ID_PH4TQX1:
+    case PROJECT_ID_PH6TRX1:
+    case PROJECT_ID_PH6TQXX:
+    case PROJECT_ID_PHXAXXX:
+    case PROJECT_ID_PHXPXXX:
+        data->single_color_kbd = true;
+        break;
+    default:
+        data->single_color_kbd = regval & KBD_WHITE_ONLY;
+        break;
+    }
+
+    if (data->single_color_kbd) {
+        init_data.default_label = "white:" LED_FUNCTION_KBD_BACKLIGHT;
+        data->kbd_led_cdev.max_brightness = data->kbd_led_max_brightness;
+        data->kbd_led_cdev.color = LED_COLOR_ID_WHITE;
+        data->kbd_led_cdev.flags = LED_BRIGHT_HW_CHANGED | 

LED_REJECT_NAME_CONFLICT;
+        data->kbd_led_cdev.brightness_set_blocking = uniwill_kbd_led_brightness_set;
+        data->kbd_led_cdev.brightness_get = uniwill_kbd_led_brightness_get; +
+        return devm_led_classdev_register_ext(data->dev, &data->kbd_led_cdev, &init_data);
+    }

drivers/platform/x86/uniwill/uniwill-acpi.c +5 -0
+
+    for (int i = 0; i < KBD_LED_CHANNELS; i++) {
+        data->kbd_led_mc_subled_info[i].color_index = color_indices[i];
+
+        ret = regmap_read(data->regmap, 

uniwill_kbd_led_channel_to_reg[i], &regval);
+        if (ret < 0)
+            return ret;
+
+        /*
+         * Make sure that the initial intensity value is not greater than +         * the maximum intensity.
+         */
+        if (regval > KBD_LED_MAX_INTENSITY) {
+            regval = KBD_LED_MAX_INTENSITY;
+            ret = regmap_write(data->regmap, uniwill_kbd_led_channel_to_reg[i], regval);
+            if (ret < 0)
+                return ret;

drivers/platform/x86/uniwill/uniwill-acpi.c +9 -0
+
+            needs_trigger = true;
+        }
+
+        if (regval)
+            intensity_all_zeros = false;
+
+        data->kbd_led_mc_subled_info[i].intensity = regval;
+        data->kbd_led_mc_subled_info[i].max_intensity = 

KBD_LED_MAX_INTENSITY;
+        data->kbd_led_mc_subled_info[i].channel = i;
+    }
+
+    /* See uniwill_kbd_led_mc_brightness_set() for an explaination. */ +    if (intensity_all_zeros) {
+        for (int i = 0; i < KBD_LED_CHANNELS; i++) {
+            data->kbd_led_mc_subled_info[i].intensity = 1; +            ret = regmap_write(data->regmap, uniwill_kbd_led_channel_to_reg[i], 1);
+            if (ret < 0)
+                return ret;
+        }

drivers/platform/x86/uniwill/uniwill-acpi.c +6 -0
+
+        needs_trigger = true;
+    }
+
+    if (needs_trigger) {
+        ret = regmap_write_bits(data->regmap, EC_ADDR_TRIGGER, 

RGB_APPLY_COLOR,
+                    RGB_APPLY_COLOR);
+        if (ret < 0)
+            return ret;
+    }

drivers/platform/x86/uniwill/uniwill-acpi.c +7 -0
+
+    ret = devm_mutex_init(data->dev, &data->kbd_rgb_led_lock);
+    if (ret < 0)
+        return ret;
+
+    init_data.default_label = "multicolor:" LED_FUNCTION_KBD_BACKLIGHT;
+    data->kbd_led_mc_cdev.led_cdev.max_brightness = 

data->kbd_led_max_brightness;
+    data->kbd_led_mc_cdev.led_cdev.color = LED_COLOR_ID_MULTI; +    data->kbd_led_mc_cdev.led_cdev.flags = LED_BRIGHT_HW_CHANGED | LED_REJECT_NAME_CONFLICT;
+ data->kbd_led_mc_cdev.led_cdev.brightness_set_blocking = uniwill_kbd_led_mc_brightness_set;
+    data->kbd_led_mc_cdev.led_cdev.brightness_get = uniwill_kbd_led_mc_brightness_get;
+    data->kbd_led_mc_cdev.subled_info = data->kbd_led_mc_subled_info; +    data->kbd_led_mc_cdev.num_colors = KBD_LED_CHANNELS;
+
+    return devm_led_classdev_multicolor_register_ext(data->dev, &data->kbd_led_mc_cdev,
+                             &init_data);

Review

Quoted 2 lines
(quoted diff) +2 -0
+}
+

Sorry I know I'm way to late with my comment, but I'm not at all a fan of how complex this whole function is:

- When we have to set max brightness on a per device basis anyway, we can
also set rgb or white only there and can skip this whole detection mechanism with the supported bits that are unreliable anyway

- we have a 2nd "supported devices/features list" inside this function which is abstracting away from the actual supported feature list

Quoted 8 lines
Quoted 6 lines

Should i try to spin up something much simpler, but that requires explicit setting in the device descriptor?

Best regards

Werner

Good point, but in this case i think having this small device list is OK, because the original control center does something similar.

yeah the original cc and tuxedo-drivers has these small lists all over the place ... also don't like it there

Quoted 2 lines

If we encounter a device that does not work with this strategy then we can indeed move the code into the device descriptor.

later we might not be able to get the information anymore which devices are rgb and which are white only when the supported devices lists grows, then we are stuck to reading the feature bits.

Quoted 8 lines
Quoted 4 lines

best regards,

Werner

Good point, in this case using the device descriptor for this feature detection might indeed be better in the long term.

Do you want to send the patches or should i do it?

I will not stop you if you have time to do it ^^

you are probably quicker in working on your own code

i would do a

UNIWILL_FEATURE_KBL_WHITE_ONLY and a

UNIWILL_FEATURE_KBL_ONE_ZONE_RGB (there are also Uniwill devices with per-key RGB, but that is controlled via a usb device)

also required is a way to set max intensity via the device descriptor, most tuxedo devices have 200 as max value there and not 50

best regards,

Werner

Quoted 3 lines

Thanks,
Armin Wolf

[...]

author maintainer
#7 lore raw

Re: [PATCH 1/7] platform/x86: uniwill-laptop: Add keyboard backlight support

Am 09.07.26 um 15:23 schrieb Werner Sembach:

Quoted 196 lines

[...]

Quoted 178 lines
Quoted 178 lines
Quoted 164 lines
Quoted 164 lines
Quoted 153 lines
drivers/platform/x86/uniwill/uniwill-acpi.c +18 -0
+
+static int uniwill_kbd_led_init(struct uniwill_data *data)
+{
+    unsigned int color_indices[KBD_LED_CHANNELS] = {
+        LED_COLOR_ID_RED,
+        LED_COLOR_ID_GREEN,
+        LED_COLOR_ID_BLUE,
+    };
+    struct led_init_data init_data = {
+        .devicename = DRIVER_NAME,
+        .devname_mandatory = true,
+    };
+    bool intensity_all_zeros = true;
+    bool needs_trigger = false;
+    unsigned int regval;
+    int ret;
+
+    if (!uniwill_device_supports(data, 

UNIWILL_FEATURE_KEYBOARD_BACKLIGHT))
+        return 0;

drivers/platform/x86/uniwill/uniwill-acpi.c +7 -0
+
+    ret = regmap_read(data->regmap, EC_ADDR_SUPPORT_2, &regval);
+    if (ret < 0)
+        return ret;
+
+    if (!(regval & CHINA_MODE)) {
+        ret = regmap_set_bits(data->regmap, EC_ADDR_BIOS_OEM_2, 

ENABLE_CHINA_MODE);
+        if (ret < 0)
+            return ret;
+    }

drivers/platform/x86/uniwill/uniwill-acpi.c +30 -0
+
+    ret = regmap_read(data->regmap, EC_ADDR_KBD_STATUS, &regval);
+    if (ret < 0)
+        return ret;
+
+    regval |= KBD_APPLY;
+    regval &= ~KBD_POWER_OFF;
+    ret = regmap_write(data->regmap, EC_ADDR_KBD_STATUS, regval);
+    if (ret < 0)
+        return ret;
+
+    switch (data->project_id) {
+    case PROJECT_ID_PF:
+    case PROJECT_ID_PF4MU_PF4MN_PF5MU:
+    case PROJECT_ID_PH4TRX1:
+    case PROJECT_ID_PH4TUX1:
+    case PROJECT_ID_PH4TQX1:
+    case PROJECT_ID_PH6TRX1:
+    case PROJECT_ID_PH6TQXX:
+    case PROJECT_ID_PHXAXXX:
+    case PROJECT_ID_PHXPXXX:
+        data->single_color_kbd = true;
+        break;
+    default:
+        data->single_color_kbd = regval & KBD_WHITE_ONLY;
+        break;
+    }
+
+    if (data->single_color_kbd) {
+        init_data.default_label = "white:" 

LED_FUNCTION_KBD_BACKLIGHT;
+        data->kbd_led_cdev.max_brightness = data->kbd_led_max_brightness;
+        data->kbd_led_cdev.color = LED_COLOR_ID_WHITE; +        data->kbd_led_cdev.flags = LED_BRIGHT_HW_CHANGED | LED_REJECT_NAME_CONFLICT;
+        data->kbd_led_cdev.brightness_set_blocking = uniwill_kbd_led_brightness_set;
+        data->kbd_led_cdev.brightness_get = uniwill_kbd_led_brightness_get;
+
+        return devm_led_classdev_register_ext(data->dev, &data->kbd_led_cdev, &init_data);
+    }
+
+    for (int i = 0; i < KBD_LED_CHANNELS; i++) {
+        data->kbd_led_mc_subled_info[i].color_index = color_indices[i];
+
+        ret = regmap_read(data->regmap, uniwill_kbd_led_channel_to_reg[i], &regval);
+        if (ret < 0)
+            return ret;
+
+        /*
+         * Make sure that the initial intensity value is not greater than
+         * the maximum intensity.
+         */
+        if (regval > KBD_LED_MAX_INTENSITY) {
+            regval = KBD_LED_MAX_INTENSITY;
+            ret = regmap_write(data->regmap, uniwill_kbd_led_channel_to_reg[i], regval);
+            if (ret < 0)
+                return ret;

drivers/platform/x86/uniwill/uniwill-acpi.c +9 -0
+
+            needs_trigger = true;
+        }
+
+        if (regval)
+            intensity_all_zeros = false;
+
+        data->kbd_led_mc_subled_info[i].intensity = regval;
+ data->kbd_led_mc_subled_info[i].max_intensity = 

KBD_LED_MAX_INTENSITY;
+        data->kbd_led_mc_subled_info[i].channel = i; +    }
+
+    /* See uniwill_kbd_led_mc_brightness_set() for an explaination. */
+    if (intensity_all_zeros) {
+        for (int i = 0; i < KBD_LED_CHANNELS; i++) {
+ data->kbd_led_mc_subled_info[i].intensity = 1; +            ret = regmap_write(data->regmap, uniwill_kbd_led_channel_to_reg[i], 1);
+            if (ret < 0)
+                return ret;
+        }

drivers/platform/x86/uniwill/uniwill-acpi.c +6 -0
+
+        needs_trigger = true;
+    }
+
+    if (needs_trigger) {
+        ret = regmap_write_bits(data->regmap, EC_ADDR_TRIGGER, 

RGB_APPLY_COLOR,
+                    RGB_APPLY_COLOR);
+        if (ret < 0)
+            return ret;
+    }

drivers/platform/x86/uniwill/uniwill-acpi.c +6 -0
+
+    ret = devm_mutex_init(data->dev, &data->kbd_rgb_led_lock);
+    if (ret < 0)
+        return ret;
+
+    init_data.default_label = "multicolor:" 

LED_FUNCTION_KBD_BACKLIGHT;
+    data->kbd_led_mc_cdev.led_cdev.max_brightness = data->kbd_led_max_brightness;
+    data->kbd_led_mc_cdev.led_cdev.color = LED_COLOR_ID_MULTI; +    data->kbd_led_mc_cdev.led_cdev.flags = LED_BRIGHT_HW_CHANGED | LED_REJECT_NAME_CONFLICT;
+ data->kbd_led_mc_cdev.led_cdev.brightness_set_blocking = uniwill_kbd_led_mc_brightness_set;
+    data->kbd_led_mc_cdev.led_cdev.brightness_get = uniwill_kbd_led_mc_brightness_get;
+    data->kbd_led_mc_cdev.subled_info = data->kbd_led_mc_subled_info;
+    data->kbd_led_mc_cdev.num_colors = KBD_LED_CHANNELS; +
+    return devm_led_classdev_multicolor_register_ext(data->dev, &data->kbd_led_mc_cdev,
+                             &init_data);

Review

Quoted 2 lines
(quoted diff) +2 -0
+}
+

Sorry I know I'm way to late with my comment, but I'm not at all a fan of how complex this whole function is:

- When we have to set max brightness on a per device basis anyway,
we can also set rgb or white only there and can skip this whole detection mechanism with the supported bits that are unreliable anyway

- we have a 2nd "supported devices/features list" inside this function which is abstracting away from the actual supported feature list

Quoted 8 lines
Quoted 6 lines

Should i try to spin up something much simpler, but that requires explicit setting in the device descriptor?

Best regards

Werner

Good point, but in this case i think having this small device list is OK, because the original control center does something similar.

yeah the original cc and tuxedo-drivers has these small lists all over the place ... also don't like it there

Quoted 2 lines

If we encounter a device that does not work with this strategy then we can indeed move the code into the device descriptor.

later we might not be able to get the information anymore which devices are rgb and which are white only when the supported devices lists grows, then we are stuck to reading the feature bits.

Quoted 8 lines
Quoted 4 lines

best regards,

Werner

Good point, in this case using the device descriptor for this feature detection might indeed be better in the long term.

Do you want to send the patches or should i do it?

I will not stop you if you have time to do it ^^

you are probably quicker in working on your own code

i would do a

UNIWILL_FEATURE_KBL_WHITE_ONLY and a

Quoted 8 lines

UNIWILL_FEATURE_KBL_ONE_ZONE_RGB (there are also Uniwill devices with per-key RGB, but that is controlled via a usb device)

also required is a way to set max intensity via the device descriptor, most tuxedo devices have 200 as max value there and not 50

best regards,

Werner

Alright, i will send the necessary patches soon.

Thanks,
Armin Wolf

Quoted 5 lines
Quoted 3 lines

Thanks,
Armin Wolf

[...]

author maintainer
#8 lore raw

PATCH 2/7 platform/x86: uniwill-laptop: Handle screen-related events

In reply to Armin Wolf

The EC will report event 0xCC on some devices when the screen has been enabled/disabled during resume/suspend. Ignore this event because it is currently unused by the driver.

---
 drivers/platform/x86/uniwill/uniwill-acpi.c | 6 ++++++
 drivers/platform/x86/uniwill/uniwill-wmi.h  | 2 ++
 2 files changed, 8 insertions(+)
drivers/platform/x86/uniwill/uniwill-acpi.c +6 -0
index fd040197b189..b3be2f2dbdd8 100644
@@ -95,6 +95,9 @@
 
 #define EC_ADDR_MAIN_FAN_RPM_2		0x0465
 
+#define EC_ADDR_SCREEN_STATUS		0x0466
+#define SCREEN_SUSPENDED		BIT(6)
+
 #define EC_ADDR_SECOND_FAN_RPM_1	0x046C
 
 #define EC_ADDR_SECOND_FAN_RPM_2	0x046D
@@ -488,6 +491,9 @@ static const struct key_entry uniwill_keymap[] = {
 	/* Reported when the user wants to toggle the benchmark mode status */
 	{ KE_IGNORE,    UNIWILL_OSD_BENCHMARK_MODE_TOGGLE,      { KEY_UNKNOWN }},
 
+	/* Reported when the screen is enabled/disabled during resume/suspend */
+	{ KE_IGNORE,	UNIWILL_OSD_SCREEN_STATE_CHANGED,	{ KEY_UNKNOWN }},
+
 	/* Reported when the user wants to toggle the webcam */
 	{ KE_IGNORE,    UNIWILL_OSD_WEBCAM_TOGGLE,              { KEY_UNKNOWN }},
 
drivers/platform/x86/uniwill/uniwill-wmi.h +2 -0
index fb1910c0f741..b25b2f31211c 100644
@@ -113,6 +113,8 @@
 
 #define UNIWILL_OSD_BENCHMARK_MODE_TOGGLE	0xC0
 
+#define UNIWILL_OSD_SCREEN_STATE_CHANGED	0xCC
+
 #define UNIWILL_OSD_WEBCAM_TOGGLE		0xCF
 
 #define UNIWILL_OSD_KBD_BACKLIGHT_CHANGED	0xF0
Signature · 1 line
2.39.5
author maintainer
#9 lore raw

PATCH 3/7 platform/x86: uniwill-laptop: Add AC auto boot support

In reply to Armin Wolf

Some devices support a "AC auto boot" feature where the system will automatically boot when being connected to a power source.

Add support for this feature.

---
 .../ABI/testing/sysfs-driver-uniwill-laptop   | 11 ++++
 .../admin-guide/laptops/uniwill-laptop.rst    |  7 +++
 drivers/platform/x86/uniwill/uniwill-acpi.c   | 51 +++++++++++++++++++
 3 files changed, 69 insertions(+)
Documentation/ABI/testing/sysfs-driver-uniwill-laptop +11 -0
index 2397c65c969a..57272f906184 100644
@@ -78,3 +78,14 @@ Description:
 
 		Reading this file returns the profile names with the currently active one in
 		brackets.
+
+What:		/sys/bus/platform/devices/INOU0000:XX/ac_auto_boot
+Date:		March 2026
+KernelVersion:	7.1
+Contact:	Armin Wolf <[email protected]>
+Description:
+		Allows userspace applications to configure if the device should boot automatically
+		when being connected to a power source. Writing "1"/"0" into this file
+		enables/disables this functionality.
+
+		Reading this file returns the current status of the AC auto boot functionality.
Documentation/admin-guide/laptops/uniwill-laptop.rst +7 -0
index 2b1e5da703a5..b6213fb1d3e0 100644
@@ -98,6 +98,13 @@ allow it.
 
 See Documentation/ABI/testing/sysfs-driver-uniwill-laptop for details.
 
+AC Auto Boot
+------------
+
+The ``uniwill-laptop`` driver allows the user to configure if the system should automatically
+boot when being connected to a power source, see
+Documentation/ABI/testing/sysfs-driver-uniwill-laptop for details.
+
 References
 ==========
 
drivers/platform/x86/uniwill/uniwill-acpi.c +51 -0

93 lines not on this page · raw message

Signature · 1 line
2.39.5
author maintainer
#10 lore raw

PATCH 4/7 platform/x86: uniwill-laptop: Add support for USB powershare

In reply to Armin Wolf

Some devices support a "USB powershare" feature where the system will continue to provide power via the USB ports when hibernating or powered off.

Add support for this feaure.

---
 .../ABI/testing/sysfs-driver-uniwill-laptop   |  16 ++-
 .../admin-guide/laptops/uniwill-laptop.rst    |   7 ++
 drivers/platform/x86/uniwill/uniwill-acpi.c   | 100 ++++++++++++++++++
 3 files changed, 122 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-driver-uniwill-laptop +15 -1
index 57272f906184..943f92c6b561 100644
@@ -86,6 +86,20 @@ Contact:	Armin Wolf <[email protected]>
 Description:
 		Allows userspace applications to configure if the device should boot automatically
 		when being connected to a power source. Writing "1"/"0" into this file
-		enables/disables this functionality.
+		enables/disables this functionality. Enabling both AC auto boot and USB powershare
+		at the same time is not supported.
 
 		Reading this file returns the current status of the AC auto boot functionality.
+
+What:		/sys/bus/platform/devices/INOU0000:XX/usb_powershare_high
+Date:		March 2026
+KernelVersion:	7.1
+Contact:	Armin Wolf <[email protected]>
+Description:
+		Allows userspace applications to configure if the device should continue to provide
+		power via the USB ports when hibernating or powered off. Might also increase the
+		power budget available to USB ports on some devices. Writing "1"/"0" into this
+		file enables/disables this functionality. Enabling both USB powershare and AC auto
+		boot at the same time is not supported.
+
+		Reading this file returns the current status of the USB powershare functionality.
Documentation/admin-guide/laptops/uniwill-laptop.rst +7 -0
index b6213fb1d3e0..be50b45b82ef 100644
@@ -105,6 +105,13 @@ The ``uniwill-laptop`` driver allows the user to configure if the system should
 boot when being connected to a power source, see
 Documentation/ABI/testing/sysfs-driver-uniwill-laptop for details.
 
+USB Powershare
+--------------
+
+The ``uniwill-laptop`` driver allows the user to configure if the system should continue to
+provide power via the USB ports when hibernating or powered off, see
+Documentation/ABI/testing/sysfs-driver-uniwill-laptop for details.
+
 References
 ==========
 
drivers/platform/x86/uniwill/uniwill-acpi.c +100 -0

154 lines not on this page · raw message

Signature · 1 line
2.39.5
author maintainer
#11 lore raw

PATCH 5/7 platform/x86: uniwill-laptop: Add support for the MACHENIKE L16 Pro

In reply to Armin Wolf

A user has reported that the driver works on the MACHENIKE L16 Pro. Add the necessary device descriptor and DMI entry to allow the driver to automatically load on this device.

---
 drivers/platform/x86/uniwill/uniwill-acpi.c | 22 +++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/platform/x86/uniwill/uniwill-acpi.c +22 -0
index 00140c0a67a0..0011c553c2cb 100644
@@ -2657,6 +2657,20 @@ static struct platform_driver uniwill_driver = {
 	.shutdown = uniwill_shutdown,
 };
 
+static struct uniwill_device_descriptor machenike_l16p_descriptor __initdata = {
+	.features = UNIWILL_FEATURE_FN_LOCK |
+		    UNIWILL_FEATURE_SUPER_KEY |
+		    UNIWILL_FEATURE_CPU_TEMP |
+		    UNIWILL_FEATURE_GPU_TEMP |
+		    UNIWILL_FEATURE_PRIMARY_FAN |
+		    UNIWILL_FEATURE_SECONDARY_FAN |
+		    UNIWILL_FEATURE_NVIDIA_CTGP_CONTROL |
+		    UNIWILL_FEATURE_KEYBOARD_BACKLIGHT |
+		    UNIWILL_FEATURE_AC_AUTO_BOOT |
+		    UNIWILL_FEATURE_USB_POWERSHARE,
+	.kbd_led_max_brightness = 4,
+};
+
 static struct uniwill_device_descriptor lapqc71a_lapqc71b_descriptor __initdata = {
 	.features = UNIWILL_FEATURE_SUPER_KEY |
 		    UNIWILL_FEATURE_BATTERY_CHARGE_LIMIT |
@@ -2809,6 +2823,14 @@ static struct uniwill_device_descriptor pf5pu1g_descriptor __initdata = {
 };
 
 static const struct dmi_system_id uniwill_dmi_table[] __initconst = {
+	{
+		.ident = "MACHENIKE L16 Pro",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "MACHENIKE"),
+			DMI_EXACT_MATCH(DMI_BOARD_NAME, "L16P"),
+		},
+		.driver_data = &machenike_l16p_descriptor,
+	},
 	{
 		.ident = "XMG FUSION 15 (L19)",
 		.matches = {
Signature · 1 line
2.39.5
author maintainer
#12 lore raw

PATCH 6/7 platform/x86: uniwill-laptop: Add support for the AiStone X4SP4NAL

In reply to Armin Wolf

A user has reported that the driver works on the AiStone X4SP4NAL. Add the necessary device descriptor and DMI entry to allow the driver to automatically load on this device.

---
 drivers/platform/x86/uniwill/uniwill-acpi.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/platform/x86/uniwill/uniwill-acpi.c +21 -0
index 0011c553c2cb..d688ffca3b5e 100644
@@ -2822,7 +2822,28 @@ static struct uniwill_device_descriptor pf5pu1g_descriptor __initdata = {
 		    UNIWILL_FEATURE_PRIMARY_FAN,
 };
 
+static struct uniwill_device_descriptor x4sp4nal_descriptor __initdata = {
+	.features = UNIWILL_FEATURE_FN_LOCK |
+		    UNIWILL_FEATURE_SUPER_KEY |
+		    UNIWILL_FEATURE_BATTERY_CHARGE_MODES |
+		    UNIWILL_FEATURE_CPU_TEMP |
+		    UNIWILL_FEATURE_PRIMARY_FAN |
+		    UNIWILL_FEATURE_SECONDARY_FAN |
+		    UNIWILL_FEATURE_KEYBOARD_BACKLIGHT |
+		    UNIWILL_FEATURE_AC_AUTO_BOOT |
+		    UNIWILL_FEATURE_USB_POWERSHARE,
+	.kbd_led_max_brightness = 2,
+};
+
 static const struct dmi_system_id uniwill_dmi_table[] __initconst = {
+	{
+		.ident = "AiStone X4SP4NAL",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "AiStone"),
+			DMI_EXACT_MATCH(DMI_BOARD_NAME, "X4SP4NAL"),
+		},
+		.driver_data = &x4sp4nal_descriptor,
+	},
 	{
 		.ident = "MACHENIKE L16 Pro",
 		.matches = {
Signature · 1 line
2.39.5
author maintainer
#13 lore raw

PATCH 7/7 platform/x86: uniwill-laptop: Add lightbar support for LAPQC71A/B

In reply to Armin Wolf

The LAPQC71A and LAPQC71B both feature a RGB lightbar with 36 brightness levels per color component. Extend the device descriptor to supply the maximum brightness of the lightbar and whitelist both models for UNIWILL_FEATURE_LIGHTBAR.

---
 drivers/platform/x86/uniwill/uniwill-acpi.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/platform/x86/uniwill/uniwill-acpi.c +12 -5
index d688ffca3b5e..f55b239bd4d1 100644
@@ -348,7 +348,6 @@
 #define FAN_TABLE_LENGTH	16
 
 #define LED_CHANNELS		3
-#define LED_MAX_BRIGHTNESS	200
 
 #define KBD_LED_CHANNELS	3
 #define KBD_LED_MAX_INTENSITY	50
@@ -398,6 +397,7 @@ struct uniwill_data {
 	struct mutex super_key_lock;	/* Protects the toggling of the super key lock state */
 	struct list_head batteries;
 	struct mutex led_lock;		/* Protects writes to the lightbar registers */
+	u8 lightbar_max_brightness;
 	struct led_classdev_mc led_mc_cdev;
 	struct mc_subled led_mc_subled_info[LED_CHANNELS];
 	bool single_color_kbd;
@@ -427,6 +427,7 @@ struct uniwill_battery_entry {
 struct uniwill_device_descriptor {
 	unsigned int features;
 	u8 kbd_led_max_brightness;
+	u8 lightbar_max_brightness;
 	/* Executed during driver probing */
 	int (*probe)(struct uniwill_data *data);
 };
@@ -1514,7 +1515,7 @@ static int uniwill_led_brightness_set(struct led_classdev *led_cdev, enum led_br
 
 	for (int i = 0; i < LED_CHANNELS; i++) {
 		/* Prevent the brightness values from overflowing */
-		value = min(LED_MAX_BRIGHTNESS, data->led_mc_subled_info[i].brightness);
+		value = min(data->lightbar_max_brightness, data->led_mc_subled_info[i].brightness);
 		ret = regmap_write(data->regmap, uniwill_led_channel_to_ac_reg[i], value);
 		if (ret < 0)
 			return ret;
@@ -1583,14 +1584,14 @@ static int uniwill_led_init(struct uniwill_data *data)
 		return ret;
 
 	data->led_mc_cdev.led_cdev.color = LED_COLOR_ID_MULTI;
-	data->led_mc_cdev.led_cdev.max_brightness = LED_MAX_BRIGHTNESS;
+	data->led_mc_cdev.led_cdev.max_brightness = data->lightbar_max_brightness;
 	data->led_mc_cdev.led_cdev.flags = LED_REJECT_NAME_CONFLICT;
 	data->led_mc_cdev.led_cdev.brightness_set_blocking = uniwill_led_brightness_set;
 
 	if (value & LIGHTBAR_S0_OFF)
 		data->led_mc_cdev.led_cdev.brightness = 0;
 	else
-		data->led_mc_cdev.led_cdev.brightness = LED_MAX_BRIGHTNESS;
+		data->led_mc_cdev.led_cdev.brightness = data->lightbar_max_brightness;
 
 	for (int i = 0; i < LED_CHANNELS; i++) {
 		data->led_mc_subled_info[i].color_index = color_indices[i];
@@ -1603,7 +1604,7 @@ static int uniwill_led_init(struct uniwill_data *data)
 		 * Make sure that the initial intensity value is not greater than
 		 * the maximum brightness.
 		 */
-		value = min(LED_MAX_BRIGHTNESS, value);
+		value = min(data->lightbar_max_brightness, value);
 		ret = regmap_write(data->regmap, uniwill_led_channel_to_ac_reg[i], value);
 		if (ret < 0)
 			return ret;
@@ -2334,6 +2335,7 @@ static int uniwill_probe(struct platform_device *pdev)
 
 	data->features = device_descriptor.features;
 	data->kbd_led_max_brightness = device_descriptor.kbd_led_max_brightness;
+	data->lightbar_max_brightness = device_descriptor.lightbar_max_brightness;
 
 	/*
 	 * Some devices might need to perform some device-specific initialization steps
@@ -2673,11 +2675,13 @@ static struct uniwill_device_descriptor machenike_l16p_descriptor __initdata = {
 
 static struct uniwill_device_descriptor lapqc71a_lapqc71b_descriptor __initdata = {
 	.features = UNIWILL_FEATURE_SUPER_KEY |
+		    UNIWILL_FEATURE_LIGHTBAR |
 		    UNIWILL_FEATURE_BATTERY_CHARGE_LIMIT |
 		    UNIWILL_FEATURE_CPU_TEMP |
 		    UNIWILL_FEATURE_GPU_TEMP |
 		    UNIWILL_FEATURE_PRIMARY_FAN |
 		    UNIWILL_FEATURE_SECONDARY_FAN,
+	.lightbar_max_brightness = 36,
 };
 
 static struct uniwill_device_descriptor lapac71h_descriptor __initdata = {
@@ -2701,6 +2705,7 @@ static struct uniwill_device_descriptor lapkc71f_descriptor __initdata = {
 		    UNIWILL_FEATURE_GPU_TEMP |
 		    UNIWILL_FEATURE_PRIMARY_FAN |
 		    UNIWILL_FEATURE_SECONDARY_FAN,
+	.lightbar_max_brightness = 200,
 };
 
 /*
@@ -3321,6 +3326,8 @@ static int __init uniwill_init(void)
 		device_descriptor.features = UINT_MAX & ~UNIWILL_FEATURE_BATTERY_CHARGE_LIMIT;
 		/* Some models only support 3 brightness levels */
 		device_descriptor.kbd_led_max_brightness = 4;
+		/* Some models only support 36 brightness levels per color component */
+		device_descriptor.lightbar_max_brightness = 200;
 		pr_warn("Enabling potentially unsupported features\n");
 	}
 
Signature · 1 line
2.39.5
#14 lore raw

Re: [PATCH 7/7] platform/x86: uniwill-laptop: Add lightbar support for LAPQC71A/B

Hi Ilpo,

Am 30.05.26 um 19:08 schrieb Armin Wolf:

Quoted 6 lines

The LAPQC71A and LAPQC71B both feature a RGB lightbar with 36 brightness levels per color component. Extend the device descriptor to supply the maximum brightness of the lightbar and whitelist both models for UNIWILL_FEATURE_LIGHTBAR.

This patch lost its original attribution by accident (it originally came from this RFC from me https://lore.kernel.org/all/[email protected]/)

Since the patch currently is only in for-next can this still be fixed?

Obligatory:

Best regards,

Werner

Quoted 106 lines
---
  drivers/platform/x86/uniwill/uniwill-acpi.c | 17 ++++++++++++-----
  1 file changed, 12 insertions(+), 5 deletions(-)
drivers/platform/x86/uniwill/uniwill-acpi.c +12 -5
index d688ffca3b5e..f55b239bd4d1 100644
@@ -348,7 +348,6 @@
  #define FAN_TABLE_LENGTH	16
 
  #define LED_CHANNELS		3
-#define LED_MAX_BRIGHTNESS	200
 
  #define KBD_LED_CHANNELS	3
  #define KBD_LED_MAX_INTENSITY	50
@@ -398,6 +397,7 @@ struct uniwill_data {
  	struct mutex super_key_lock;	/* Protects the toggling of the super key lock state */
  	struct list_head batteries;
  	struct mutex led_lock;		/* Protects writes to the lightbar registers */
+	u8 lightbar_max_brightness;
  	struct led_classdev_mc led_mc_cdev;
  	struct mc_subled led_mc_subled_info[LED_CHANNELS];
  	bool single_color_kbd;
@@ -427,6 +427,7 @@ struct uniwill_battery_entry {
  struct uniwill_device_descriptor {
  	unsigned int features;
  	u8 kbd_led_max_brightness;
+	u8 lightbar_max_brightness;
  	/* Executed during driver probing */
  	int (*probe)(struct uniwill_data *data);
  };
@@ -1514,7 +1515,7 @@ static int uniwill_led_brightness_set(struct led_classdev *led_cdev, enum led_br
 
  	for (int i = 0; i < LED_CHANNELS; i++) {
  		/* Prevent the brightness values from overflowing */
-		value = min(LED_MAX_BRIGHTNESS, data->led_mc_subled_info[i].brightness);
+		value = min(data->lightbar_max_brightness, data->led_mc_subled_info[i].brightness);
  		ret = regmap_write(data->regmap, uniwill_led_channel_to_ac_reg[i], value);
  		if (ret < 0)
  			return ret;
@@ -1583,14 +1584,14 @@ static int uniwill_led_init(struct uniwill_data *data)
  		return ret;
 
  	data->led_mc_cdev.led_cdev.color = LED_COLOR_ID_MULTI;
-	data->led_mc_cdev.led_cdev.max_brightness = LED_MAX_BRIGHTNESS;
+	data->led_mc_cdev.led_cdev.max_brightness = data->lightbar_max_brightness;
  	data->led_mc_cdev.led_cdev.flags = LED_REJECT_NAME_CONFLICT;
  	data->led_mc_cdev.led_cdev.brightness_set_blocking = uniwill_led_brightness_set;
 
  	if (value & LIGHTBAR_S0_OFF)
  		data->led_mc_cdev.led_cdev.brightness = 0;
  	else
-		data->led_mc_cdev.led_cdev.brightness = LED_MAX_BRIGHTNESS;
+		data->led_mc_cdev.led_cdev.brightness = data->lightbar_max_brightness;
 
  	for (int i = 0; i < LED_CHANNELS; i++) {
  		data->led_mc_subled_info[i].color_index = color_indices[i];
@@ -1603,7 +1604,7 @@ static int uniwill_led_init(struct uniwill_data *data)
  		 * Make sure that the initial intensity value is not greater than
  		 * the maximum brightness.
  		 */
-		value = min(LED_MAX_BRIGHTNESS, value);
+		value = min(data->lightbar_max_brightness, value);
  		ret = regmap_write(data->regmap, uniwill_led_channel_to_ac_reg[i], value);
  		if (ret < 0)
  			return ret;
@@ -2334,6 +2335,7 @@ static int uniwill_probe(struct platform_device *pdev)
 
  	data->features = device_descriptor.features;
  	data->kbd_led_max_brightness = device_descriptor.kbd_led_max_brightness;
+	data->lightbar_max_brightness = device_descriptor.lightbar_max_brightness;
 
  	/*
  	 * Some devices might need to perform some device-specific initialization steps
@@ -2673,11 +2675,13 @@ static struct uniwill_device_descriptor machenike_l16p_descriptor __initdata = {
 
  static struct uniwill_device_descriptor lapqc71a_lapqc71b_descriptor __initdata = {
  	.features = UNIWILL_FEATURE_SUPER_KEY |
+		    UNIWILL_FEATURE_LIGHTBAR |
  		    UNIWILL_FEATURE_BATTERY_CHARGE_LIMIT |
  		    UNIWILL_FEATURE_CPU_TEMP |
  		    UNIWILL_FEATURE_GPU_TEMP |
  		    UNIWILL_FEATURE_PRIMARY_FAN |
  		    UNIWILL_FEATURE_SECONDARY_FAN,
+	.lightbar_max_brightness = 36,
  };
 
  static struct uniwill_device_descriptor lapac71h_descriptor __initdata = {
@@ -2701,6 +2705,7 @@ static struct uniwill_device_descriptor lapkc71f_descriptor __initdata = {
  		    UNIWILL_FEATURE_GPU_TEMP |
  		    UNIWILL_FEATURE_PRIMARY_FAN |
  		    UNIWILL_FEATURE_SECONDARY_FAN,
+	.lightbar_max_brightness = 200,
  };
 
  /*
@@ -3321,6 +3326,8 @@ static int __init uniwill_init(void)
  		device_descriptor.features = UINT_MAX & ~UNIWILL_FEATURE_BATTERY_CHARGE_LIMIT;
  		/* Some models only support 3 brightness levels */
  		device_descriptor.kbd_led_max_brightness = 4;
+		/* Some models only support 36 brightness levels per color component */
+		device_descriptor.lightbar_max_brightness = 200;
  		pr_warn("Enabling potentially unsupported features\n");
  	}
 
maintainer
#15 lore raw

Re: [PATCH 7/7] platform/x86: uniwill-laptop: Add lightbar support for LAPQC71A/B

Quoted 14 lines · Werner Sembach

Hi Ilpo,

Am 30.05.26 um 19:08 schrieb Armin Wolf:

Quoted 6 lines

The LAPQC71A and LAPQC71B both feature a RGB lightbar with 36 brightness levels per color component. Extend the device descriptor to supply the maximum brightness of the lightbar and whitelist both models for UNIWILL_FEATURE_LIGHTBAR.

This patch lost its original attribution by accident (it originally came from this RFC from me
https://lore.kernel.org/all/[email protected]/)

Quoted 5 lines

Since the patch currently is only in for-next can this still be fixed?

Obligatory:

Hi Werner,

Your Signed-off-by has now been added into the commit.

Signature · 1 line
 i.
#16 lore raw

Re: [PATCH 7/7] platform/x86: uniwill-laptop: Add lightbar support for LAPQC71A/B

Am 09.07.26 um 10:57 schrieb Ilpo Järvinen:

Quoted 15 lines · Werner Sembach
Quoted 14 lines

Hi Ilpo,

Am 30.05.26 um 19:08 schrieb Armin Wolf:

Quoted 6 lines

The LAPQC71A and LAPQC71B both feature a RGB lightbar with 36 brightness levels per color component. Extend the device descriptor to supply the maximum brightness of the lightbar and whitelist both models for UNIWILL_FEATURE_LIGHTBAR.

This patch lost its original attribution by accident (it originally came from this RFC from me
https://lore.kernel.org/all/[email protected]/)

Quoted 8 lines
Quoted 5 lines

Since the patch currently is only in for-next can this still be fixed?

Obligatory:

Hi Werner,

Your Signed-off-by has now been added into the commit.

can you also fix the author?

Quoted 1 line
maintainer
#17 lore raw

Re: [PATCH 7/7] platform/x86: uniwill-laptop: Add lightbar support for LAPQC71A/B

Quoted 19 lines · Werner Sembach

Am 09.07.26 um 10:57 schrieb Ilpo Järvinen:

Quoted 18 lines · Werner Sembach
Quoted 17 lines

Hi Ilpo,

Am 30.05.26 um 19:08 schrieb Armin Wolf:

Quoted 6 lines

The LAPQC71A and LAPQC71B both feature a RGB lightbar with 36 brightness levels per color component. Extend the device descriptor to supply the maximum brightness of the lightbar and whitelist both models for UNIWILL_FEATURE_LIGHTBAR.

This patch lost its original attribution by accident (it originally came from
this RFC from me
https://lore.kernel.org/all/[email protected]/)

Since the patch currently is only in for-next can this still be fixed?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Obligatory:

Hi Werner,

Your Signed-off-by has now been added into the commit.

can you also fix the author?

Also the author field is now changed in the review-ilpo-next branch (it will eventually propagate from there to for-next).

Signature · 1 line
 i.
#18 lore raw

Re: [PATCH 7/7] platform/x86: uniwill-laptop: Add lightbar support for LAPQC71A/B

Am 09.07.26 um 15:45 schrieb Ilpo Järvinen:

Quoted 22 lines · Werner Sembach
Quoted 21 lines

Am 09.07.26 um 10:57 schrieb Ilpo Järvinen:

Quoted 20 lines · Werner Sembach
Quoted 19 lines

Hi Ilpo,

Am 30.05.26 um 19:08 schrieb Armin Wolf:

Quoted 6 lines

The LAPQC71A and LAPQC71B both feature a RGB lightbar with 36 brightness levels per color component. Extend the device descriptor to supply the maximum brightness of the lightbar and whitelist both models for UNIWILL_FEATURE_LIGHTBAR.

This patch lost its original attribution by accident (it originally came from
this RFC from me
https://lore.kernel.org/all/[email protected]/)

Since the patch currently is only in for-next can this still be fixed?

Obligatory:

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

Hi Werner,

Your Signed-off-by has now been added into the commit.

can you also fix the author?

Also the author field is now changed in the review-ilpo-next branch (it will eventually propagate from there to for-next).

thx

Quoted 1 line
maintainer
#19 lore raw
In reply to Armin Wolf
Quoted 24 lines · Armin Wolf

This patch series adds support for various new features to the uniwill-laptop driver. The first patch adds support for the keyboard backlight available on some models, while the next three patches add support for additional WMI events, USB powershare and AC auto boot. The last four patches finally add support for additional devices.

The patch series depends on commit b1a9b7a904af ("leds: Introduce the multi_max_intensity sysfs attribute") currently sitting inside the for-leds-next branch of the LED subsystem
tree. Without said commit the first patch will apply but not build.

All patches have been tested on my Tuxedo InfinityBook Pro 15 Gen 10 AMD and most work flawlessly, only the AC auto boot feature seems to be broken on my device. I decided to still include the patch because it works on other devices.

Armin Wolf (7):
platform/x86: uniwill-laptop: Add keyboard backlight support platform/x86: uniwill-laptop: Handle screen-related events platform/x86: uniwill-laptop: Add AC auto boot support platform/x86: uniwill-laptop: Add support for USB powershare platform/x86: uniwill-laptop: Add support for the MACHENIKE L16 Pro platform/x86: uniwill-laptop: Add support for the AiStone X4SP4NAL platform/x86: uniwill-laptop: Add lightbar support for LAPQC71A/B

Quoted 5 lines
 .../ABI/testing/sysfs-driver-uniwill-laptop   |  25 +
 .../admin-guide/laptops/uniwill-laptop.rst    |  27 +
 drivers/platform/x86/uniwill/uniwill-acpi.c   | 609 +++++++++++++++++-
 drivers/platform/x86/uniwill/uniwill-wmi.h    |   2 +
 4 files changed, 650 insertions(+), 13 deletions(-)

Unfortunately, I got this error after applying this series on top of review-ilpo-next:

drivers/platform/x86/uniwill/uniwill-acpi.c: In function ‘uniwill_kbd_led_init’:
drivers/platform/x86/uniwill/uniwill-acpi.c:1827:49: error: ‘struct mc_subled’ has no member named ‘max_intensity’; did you mean ‘intensity’?
1827 | data->kbd_led_mc_subled_info[i].max_intensity = KBD_LED_MAX_INTENSITY;

Signature · 1 line
 i.
author maintainer
#20 lore raw

Am 10.06.26 um 12:50 schrieb Ilpo Järvinen:

Quoted 32 lines · Armin Wolf
Quoted 25 lines

This patch series adds support for various new features to the uniwill-laptop driver. The first patch adds support for the keyboard backlight available on some models, while the next three patches add support for additional WMI events, USB powershare and AC auto boot. The last four patches finally add support for additional devices.

The patch series depends on commit b1a9b7a904af ("leds: Introduce the multi_max_intensity sysfs attribute") currently sitting inside the for-leds-next branch of the LED subsystem
tree. Without said commit the first patch will apply but not build.

All patches have been tested on my Tuxedo InfinityBook Pro 15 Gen 10 AMD and most work flawlessly, only the AC auto boot feature seems to be broken on my device. I decided to still include the patch because it works on other devices.

Armin Wolf (7):
platform/x86: uniwill-laptop: Add keyboard backlight support platform/x86: uniwill-laptop: Handle screen-related events platform/x86: uniwill-laptop: Add AC auto boot support platform/x86: uniwill-laptop: Add support for USB powershare platform/x86: uniwill-laptop: Add support for the MACHENIKE L16 Pro platform/x86: uniwill-laptop: Add support for the AiStone X4SP4NAL platform/x86: uniwill-laptop: Add lightbar support for LAPQC71A/B

Quoted 5 lines
  .../ABI/testing/sysfs-driver-uniwill-laptop   |  25 +
  .../admin-guide/laptops/uniwill-laptop.rst    |  27 +
  drivers/platform/x86/uniwill/uniwill-acpi.c   | 609 +++++++++++++++++-
  drivers/platform/x86/uniwill/uniwill-wmi.h    |   2 +
  4 files changed, 650 insertions(+), 13 deletions(-)
Quoted 8 lines

Unfortunately, I got this error after applying this series on top of review-ilpo-next:

drivers/platform/x86/uniwill/uniwill-acpi.c: In function ‘uniwill_kbd_led_init’:
drivers/platform/x86/uniwill/uniwill-acpi.c:1827:49: error: ‘struct mc_subled’ has no member named ‘max_intensity’; did you mean ‘intensity’?
1827 | data->kbd_led_mc_subled_info[i].max_intensity = KBD_LED_MAX_INTENSITY;

The patch series depends on commit b1a9b7a904af ("leds: Introduce the multi_max_intensity sysfs attribute") currently sitting inside the for-leds-next branch of the LED subsystem
tree.

Thanks,
Armin Wolf

maintainer
#21 lore raw
Quoted 45 lines · Armin Wolf

Am 10.06.26 um 12:50 schrieb Ilpo Järvinen:

Quoted 36 lines · Armin Wolf
Quoted 26 lines

This patch series adds support for various new features to the uniwill-laptop driver. The first patch adds support for the keyboard backlight available on some models, while the next three patches add support for additional WMI events, USB powershare and AC auto boot. The last four patches finally add support for additional devices.

The patch series depends on commit b1a9b7a904af ("leds: Introduce the multi_max_intensity sysfs attribute")
currently sitting inside the for-leds-next branch of the LED subsystem tree. Without said commit the first patch will apply but not build.

All patches have been tested on my Tuxedo InfinityBook Pro 15 Gen 10 AMD and most work flawlessly, only the AC auto boot feature seems to be broken on my device. I decided to still include the patch because it works on other devices.

Armin Wolf (7):
platform/x86: uniwill-laptop: Add keyboard backlight support platform/x86: uniwill-laptop: Handle screen-related events platform/x86: uniwill-laptop: Add AC auto boot support platform/x86: uniwill-laptop: Add support for USB powershare platform/x86: uniwill-laptop: Add support for the MACHENIKE L16 Pro platform/x86: uniwill-laptop: Add support for the AiStone X4SP4NAL platform/x86: uniwill-laptop: Add lightbar support for LAPQC71A/B

Quoted 5 lines
  .../ABI/testing/sysfs-driver-uniwill-laptop   |  25 +
  .../admin-guide/laptops/uniwill-laptop.rst    |  27 +
  drivers/platform/x86/uniwill/uniwill-acpi.c   | 609 +++++++++++++++++-
  drivers/platform/x86/uniwill/uniwill-wmi.h    |   2 +
  4 files changed, 650 insertions(+), 13 deletions(-)

Unfortunately, I got this error after applying this series on top of review-ilpo-next:

Quoted 8 lines

drivers/platform/x86/uniwill/uniwill-acpi.c: In function ‘uniwill_kbd_led_init’:
drivers/platform/x86/uniwill/uniwill-acpi.c:1827:49: error: ‘struct mc_subled’ has no member named ‘max_intensity’; did you mean ‘intensity’?
1827 | data->kbd_led_mc_subled_info[i].max_intensity =
KBD_LED_MAX_INTENSITY;

Quoted 4 lines

The patch series depends on commit b1a9b7a904af ("leds: Introduce the multi_max_intensity sysfs attribute")
currently sitting inside the for-leds-next branch of the LED subsystem tree.

Ah, I missed that note.

This will have to wait to the next version then. I've summoned the series back to patchwork queue so I won't forget it.

Signature · 1 line
 i.
author maintainer
#22 lore raw

Am 11.06.26 um 15:21 schrieb Ilpo Järvinen:

Quoted 52 lines · Armin Wolf
Quoted 46 lines

Am 10.06.26 um 12:50 schrieb Ilpo Järvinen:

Quoted 36 lines · Armin Wolf
Quoted 26 lines

This patch series adds support for various new features to the uniwill-laptop driver. The first patch adds support for the keyboard backlight available on some models, while the next three patches add support for additional WMI events, USB powershare and AC auto boot. The last four patches finally add support for additional devices.

The patch series depends on commit b1a9b7a904af ("leds: Introduce the multi_max_intensity sysfs attribute")
currently sitting inside the for-leds-next branch of the LED subsystem tree. Without said commit the first patch will apply but not build.

All patches have been tested on my Tuxedo InfinityBook Pro 15 Gen 10 AMD and most work flawlessly, only the AC auto boot feature seems to be broken on my device. I decided to still include the patch because it works on other devices.

Armin Wolf (7):
platform/x86: uniwill-laptop: Add keyboard backlight support platform/x86: uniwill-laptop: Handle screen-related events platform/x86: uniwill-laptop: Add AC auto boot support platform/x86: uniwill-laptop: Add support for USB powershare platform/x86: uniwill-laptop: Add support for the MACHENIKE L16 Pro platform/x86: uniwill-laptop: Add support for the AiStone X4SP4NAL platform/x86: uniwill-laptop: Add lightbar support for LAPQC71A/B

Quoted 5 lines
   .../ABI/testing/sysfs-driver-uniwill-laptop   |  25 +
   .../admin-guide/laptops/uniwill-laptop.rst    |  27 +
   drivers/platform/x86/uniwill/uniwill-acpi.c   | 609 +++++++++++++++++-
   drivers/platform/x86/uniwill/uniwill-wmi.h    |   2 +
   4 files changed, 650 insertions(+), 13 deletions(-)

Unfortunately, I got this error after applying this series on top of review-ilpo-next:

Quoted 8 lines

drivers/platform/x86/uniwill/uniwill-acpi.c: In function ‘uniwill_kbd_led_init’:
drivers/platform/x86/uniwill/uniwill-acpi.c:1827:49: error: ‘struct mc_subled’ has no member named ‘max_intensity’; did you mean ‘intensity’?
1827 | data->kbd_led_mc_subled_info[i].max_intensity =
KBD_LED_MAX_INTENSITY;

Quoted 4 lines

The patch series depends on commit b1a9b7a904af ("leds: Introduce the multi_max_intensity sysfs attribute")
currently sitting inside the for-leds-next branch of the LED subsystem tree.

Quoted 5 lines

Ah, I missed that note.

This will have to wait to the next version then. I've summoned the series back to patchwork queue so I won't forget it.

That is totally fine. Since you are ready to merge this series as-is, i will start developing patches based on this series that will be send after the development for 7.2 has started.

Thanks,
Armin Wolf

maintainer
#23 lore raw
In reply to Armin Wolf
Quoted 11 lines · Armin Wolf

This patch series adds support for various new features to the uniwill-laptop driver. The first patch adds support for the keyboard backlight available on some models, while the next three patches add support for additional WMI events, USB powershare and AC auto boot. The last four patches finally add support for additional devices.

The patch series depends on commit b1a9b7a904af ("leds: Introduce the multi_max_intensity sysfs attribute") currently sitting inside the for-leds-next branch of the LED subsystem
tree. Without said commit the first patch will apply but not build.

[...]

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

FYI [if applicable to your patch], as per Linus' policy change, also fixes are mostly routed through for-next unless the fix is for a commit introduced in the most recent or clearly a regression fix.

The list of commits applied:
[1/7] platform/x86: uniwill-laptop: Add keyboard backlight support

      commit: 2d79283eec8dbdca246ca22154d84cebcb2780c4
[2/7] platform/x86: uniwill-laptop: Handle screen-related events
      commit: c7f3d21c8f50d64202e191f0ced40190ca1f45f7
[3/7] platform/x86: uniwill-laptop: Add AC auto boot support
      commit: e8a41051b95bc8a2dfda3a32b23528d098a7e907
[4/7] platform/x86: uniwill-laptop: Add support for USB powershare
      commit: 58d88f08ab1ff8da359b78e3421566669f0d1dcd
[5/7] platform/x86: uniwill-laptop: Add support for the MACHENIKE L16 Pro
      commit: c1c6633e3f1f9e38b5b9a26137f87a997445d306
[6/7] platform/x86: uniwill-laptop: Add support for the AiStone X4SP4NAL
      commit: 62f334005d59723bcef864b82e95f6da6bbca41d
[7/7] platform/x86: uniwill-laptop: Add lightbar support for LAPQC71A/B
      commit: e451ae739a2c6fa4e9cc1be44678f6ff9223430d

--
i.

author maintainer
#24 lore raw

Am 01.07.26 um 13:30 schrieb Ilpo Järvinen:

Quoted 13 lines · Armin Wolf
Quoted 7 lines

This patch series adds support for various new features to the uniwill-laptop driver. The first patch adds support for the keyboard backlight available on some models, while the next three patches add support for additional WMI events, USB powershare and AC auto boot. The last four patches finally add support for additional devices.

Quoted 5 lines

The patch series depends on commit b1a9b7a904af ("leds: Introduce the multi_max_intensity sysfs attribute") currently sitting inside the for-leds-next branch of the LED subsystem
tree. Without said commit the first patch will apply but not build.

[...]

Quoted 8 lines

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

FYI [if applicable to your patch], as per Linus' policy change, also fixes are mostly routed through for-next unless the fix is for a commit introduced in the most recent or clearly a regression fix.

Alright, thanks for the info.

Armin Wolf

Quoted 21 lines

The list of commits applied:
[1/7] platform/x86: uniwill-laptop: Add keyboard backlight support

       commit: 2d79283eec8dbdca246ca22154d84cebcb2780c4
[2/7] platform/x86: uniwill-laptop: Handle screen-related events
       commit: c7f3d21c8f50d64202e191f0ced40190ca1f45f7
[3/7] platform/x86: uniwill-laptop: Add AC auto boot support
       commit: e8a41051b95bc8a2dfda3a32b23528d098a7e907
[4/7] platform/x86: uniwill-laptop: Add support for USB powershare
       commit: 58d88f08ab1ff8da359b78e3421566669f0d1dcd
[5/7] platform/x86: uniwill-laptop: Add support for the MACHENIKE L16 Pro
       commit: c1c6633e3f1f9e38b5b9a26137f87a997445d306
[6/7] platform/x86: uniwill-laptop: Add support for the AiStone X4SP4NAL
       commit: 62f334005d59723bcef864b82e95f6da6bbca41d
[7/7] platform/x86: uniwill-laptop: Add lightbar support for LAPQC71A/B
       commit: e451ae739a2c6fa4e9cc1be44678f6ff9223430d

--
i.