Skip to contentSkip to conversation

uniwill-laptop: Input-related improvements

PATCH Superseded Armin Wolf 1 participant 6 messages Feb 12

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Armin Wolf

author maintainer
#0 lore raw

v3 cover uniwill-laptop: Input-related improvements

This patch series contains a set of input-related improvements for the uniwill-laptop driver. The first patch renames the "fn_lock_toggle_enable" and "super_key_toggle_enable" sysfs attributes after it was discovered that the underlying hardware works differently than previously thought. This technically breaks user space applications using those sysfs attributes, but AFAIK no such users currently exist.

The next two patches fix a potential crash and an issue with the fn lock status not being updated when using a key combination. The remaining patches ensure that when the users changes the fn lock status or enables/disables the super key using a key combination, a poll notification is being issued on the appropriate sysfs attr.

Tested on a TUXEDO InfinityBook Pro 15 Gen 10 AMD (whitelist entry comes next).

Changes since v2:
- rename UNIWILL_OSD_SUPER_KEY_LOCK_CHANGED
- do no use UNIWILL_OSD_SUPER_KEY_LOCK_ENABLE and UNIWILL_OSD_SUPER_KEY_LOCK_DISABLE events for triggering the poll notification

Changes since v1:
- update admin-guide for uniwill laptops
- rename UNIWILL_OSD_SUPER_KEY_LOCK_ENABLE and UNIWILL_OSD_SUPER_KEY_LOCK_DISABLE
- fix small issue in commit description of patch 5

Armin Wolf (5):
platform/x86: uniwill-laptop: Rename FN lock and super key lock attrs platform/x86: uniwill-laptop: Fix crash on unexpected battery event platform/x86: uniwill-laptop: Mark FN lock status as being volatile platform/x86: uniwill-laptop: Handle FN lock event platform/x86: uniwill-laptop: Handle super key changed event

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

PATCH v3 1/5 platform/x86: uniwill-laptop: Rename FN lock and super key lock attrs

It turns out that both sysfs attributes actually directly control the FN lock status/super key enable status, rather than the triggering of the associated events. This behavior was first observed on a Tuxedo notebook and was belived to be a hardware quirk. However, it seems that i simply misunderstood the manual of the OEM software for Intel NUC devices. The correct behavior is:

- fn_lock_toggle_enable enables/disables FN lock mode
- super_key_toggle_enable enables/disables the super key

Rename both sysfs attributes to avoid confusing users.

Fixes d050479693bb ("platform/x86: Add Uniwill laptop driver")
---
 .../ABI/testing/sysfs-driver-uniwill-laptop   | 10 ++--
 .../admin-guide/laptops/uniwill-laptop.rst    |  2 +-
 drivers/platform/x86/uniwill/uniwill-acpi.c   | 58 ++++++++++---------
 drivers/platform/x86/uniwill/uniwill-wmi.h    |  6 +-
 4 files changed, 39 insertions(+), 37 deletions(-)
Documentation/ABI/testing/sysfs-driver-uniwill-laptop +5 -5
index eaeb659793d2..2df70792968f 100644
@@ -1,4 +1,4 @@
-What:		/sys/bus/platform/devices/INOU0000:XX/fn_lock_toggle_enable
+What:		/sys/bus/platform/devices/INOU0000:XX/fn_lock
 Date:		November 2025
 KernelVersion:	6.19
 Contact:	Armin Wolf <[email protected]>
@@ -8,15 +8,15 @@ Description:
 
 		Reading this file returns the current enable status of the FN lock functionality.
 
-What:		/sys/bus/platform/devices/INOU0000:XX/super_key_toggle_enable
+What:		/sys/bus/platform/devices/INOU0000:XX/super_key_enable
 Date:		November 2025
 KernelVersion:	6.19
 Contact:	Armin Wolf <[email protected]>
 Description:
-                Allows userspace applications to enable/disable the super key functionality
-                of the integrated keyboard by writing "1"/"0" into this file.
+		Allows userspace applications to enable/disable the super key of the integrated
+		keyboard by writing "1"/"0" into this file.
 
-		Reading this file returns the current enable status of the super key functionality.
+		Reading this file returns the current enable status of the super key.
 
 What:		/sys/bus/platform/devices/INOU0000:XX/touchpad_toggle_enable
 Date:		November 2025
Documentation/admin-guide/laptops/uniwill-laptop.rst +1 -1
index a16baf15516b..aff5f57a6bd4 100644
@@ -24,7 +24,7 @@ Keyboard settings
 
 The ``uniwill-laptop`` driver allows the user to enable/disable:
 
- - the FN and super key lock functionality of the integrated keyboard
+ - the FN lock and super key of the integrated keyboard
  - the touchpad toggle functionality of the integrated touchpad
 
 See Documentation/ABI/testing/sysfs-driver-uniwill-laptop for details.
drivers/platform/x86/uniwill/uniwill-acpi.c +30 -28

141 lines not on this page · raw message

drivers/platform/x86/uniwill/uniwill-wmi.h +3 -3
index 48783b2e9ffb..fb1910c0f741 100644
@@ -64,8 +64,8 @@
 #define UNIWILL_OSD_KB_LED_LEVEL3		0x3E
 #define UNIWILL_OSD_KB_LED_LEVEL4		0x3F
 
-#define UNIWILL_OSD_SUPER_KEY_LOCK_ENABLE	0x40
-#define UNIWILL_OSD_SUPER_KEY_LOCK_DISABLE	0x41
+#define UNIWILL_OSD_SUPER_KEY_DISABLE		0x40
+#define UNIWILL_OSD_SUPER_KEY_ENABLE		0x41
 
 #define UNIWILL_OSD_MENU_JP			0x42
 
@@ -74,7 +74,7 @@
 
 #define UNIWILL_OSD_RFKILL			0xA4
 
-#define UNIWILL_OSD_SUPER_KEY_LOCK_CHANGED	0xA5
+#define UNIWILL_OSD_SUPER_KEY_STATE_CHANGED	0xA5
 
 #define UNIWILL_OSD_LIGHTBAR_STATE_CHANGED	0xA6
 
Signature · 1 line
2.39.5
author maintainer
#2 lore raw

PATCH v3 2/5 platform/x86: uniwill-laptop: Fix crash on unexpected battery event

In reply to Armin Wolf

On devices that have not UNIWILL_FEATURE_BATTERY set, the underlying hardware might still send the UNIWILL_OSD_BATTERY_ALERT event. In such a situation, the driver will access uninitialized data structures when handling said event.

Prevent this by only handling the UNIWILL_OSD_BATTERY_ALERT event when UNIWILL_FEATURE_BATTERY is set.

Fixes d050479693bb ("platform/x86: Add Uniwill laptop driver")
---
 drivers/platform/x86/uniwill/uniwill-acpi.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/platform/x86/uniwill/uniwill-acpi.c +3 -0
index 2abae9faceb7..03694e51d0ae 100644
@@ -1359,6 +1359,9 @@ static int uniwill_notifier_call(struct notifier_block *nb, unsigned long action
 
 	switch (action) {
 	case UNIWILL_OSD_BATTERY_ALERT:
+		if (!uniwill_device_supports(data, UNIWILL_FEATURE_BATTERY))
+			return NOTIFY_DONE;
+
 		mutex_lock(&data->battery_lock);
 		list_for_each_entry(entry, &data->batteries, head) {
 			power_supply_changed(entry->battery);
Signature · 1 line
2.39.5
author maintainer
#3 lore raw

PATCH v3 3/5 platform/x86: uniwill-laptop: Mark FN lock status as being volatile

In reply to Armin Wolf

It turns out that the FN lock status can be changed by the underlying hardware when the user presses a special key combination. Mark the associated register as volatile to prevent regmap from caching said value. Also add the necessary suspend/resume handling.

Fixes d050479693bb ("platform/x86: Add Uniwill laptop driver")
---
 drivers/platform/x86/uniwill/uniwill-acpi.c | 39 ++++++++++++++++++---
 1 file changed, 35 insertions(+), 4 deletions(-)
drivers/platform/x86/uniwill/uniwill-acpi.c +35 -4
index 03694e51d0ae..29daf83c0b26 100644
@@ -330,6 +330,7 @@ struct uniwill_data {
 	struct acpi_battery_hook hook;
 	unsigned int last_charge_ctrl;
 	struct mutex battery_lock;	/* Protects the list of currently registered batteries */
+	unsigned int last_status;
 	unsigned int last_switch_status;
 	struct mutex super_key_lock;	/* Protects the toggling of the super key lock state */
 	struct list_head batteries;
@@ -580,6 +581,7 @@ static bool uniwill_volatile_reg(struct device *dev, unsigned int reg)
 	case EC_ADDR_SECOND_FAN_RPM_1:
 	case EC_ADDR_SECOND_FAN_RPM_2:
 	case EC_ADDR_BAT_ALERT:
+	case EC_ADDR_BIOS_OEM:
 	case EC_ADDR_PWM_1:
 	case EC_ADDR_PWM_2:
 	case EC_ADDR_TRIGGER:
@@ -1508,7 +1510,19 @@ static void uniwill_shutdown(struct platform_device *pdev)
 	regmap_clear_bits(data->regmap, EC_ADDR_AP_OEM, ENABLE_MANUAL_CTRL);
 }
 
-static int uniwill_suspend_keyboard(struct uniwill_data *data)
+static int uniwill_suspend_fn_lock(struct uniwill_data *data)
+{
+	if (!uniwill_device_supports(data, UNIWILL_FEATURE_FN_LOCK))
+		return 0;
+
+	/*
+	 * The EC_ADDR_BIOS_OEM is marked as volatile, so we have to restore it
+	 * ourselves.
+	 */
+	return regmap_read(data->regmap, EC_ADDR_BIOS_OEM, &data->last_status);
+}
+
+static int uniwill_suspend_super_key(struct uniwill_data *data)
 {
 	if (!uniwill_device_supports(data, UNIWILL_FEATURE_SUPER_KEY))
 		return 0;
@@ -1547,7 +1561,11 @@ static int uniwill_suspend(struct device *dev)
 	struct uniwill_data *data = dev_get_drvdata(dev);
 	int ret;
 
-	ret = uniwill_suspend_keyboard(data);
+	ret = uniwill_suspend_fn_lock(data);
+	if (ret < 0)
+		return ret;
+
+	ret = uniwill_suspend_super_key(data);
 	if (ret < 0)
 		return ret;
 
@@ -1565,7 +1583,16 @@ static int uniwill_suspend(struct device *dev)
 	return 0;
 }
 
-static int uniwill_resume_keyboard(struct uniwill_data *data)
+static int uniwill_resume_fn_lock(struct uniwill_data *data)
+{
+	if (!uniwill_device_supports(data, UNIWILL_FEATURE_FN_LOCK))
+		return 0;
+
+	return regmap_update_bits(data->regmap, EC_ADDR_BIOS_OEM, FN_LOCK_STATUS,
+				  data->last_status);
+}
+
+static int uniwill_resume_super_key(struct uniwill_data *data)
 {
 	unsigned int value;
 	int ret;
@@ -1613,7 +1640,11 @@ static int uniwill_resume(struct device *dev)
 	if (ret < 0)
 		return ret;
 
-	ret = uniwill_resume_keyboard(data);
+	ret = uniwill_resume_fn_lock(data);
+	if (ret < 0)
+		return ret;
+
+	ret = uniwill_resume_super_key(data);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
2.39.5
author maintainer
#4 lore raw

PATCH v3 4/5 platform/x86: uniwill-laptop: Handle FN lock event

In reply to Armin Wolf

On many devices, the user can toggle the Fn lock state by pressing Fn + Esc. Forward the associated event to the fn_lock sysfs attribute as a poll notification.

---
 drivers/platform/x86/uniwill/uniwill-acpi.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/platform/x86/uniwill/uniwill-acpi.c +7 -3
index 29daf83c0b26..8f214489e9ed 100644
@@ -406,9 +406,6 @@ static const struct key_entry uniwill_keymap[] = {
 	/* Reported when the user wants to toggle the mute status */
 	{ KE_IGNORE,    UNIWILL_OSD_MUTE,                       { KEY_MUTE }},
 
-	/* Reported when the user locks/unlocks the Fn key */
-	{ KE_IGNORE,    UNIWILL_OSD_FN_LOCK,                    { KEY_FN_ESC }},
-
 	/* 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 }},
@@ -1376,6 +1373,13 @@ static int uniwill_notifier_call(struct notifier_block *nb, unsigned long action
 		 * gets implemented.
 		 */
 
+		return NOTIFY_OK;
+	case UNIWILL_OSD_FN_LOCK:
+		if (!uniwill_device_supports(data, UNIWILL_FEATURE_FN_LOCK))
+			return NOTIFY_DONE;
+
+		sysfs_notify(&data->dev->kobj, NULL, "fn_lock");
+
 		return NOTIFY_OK;
 	default:
 		mutex_lock(&data->input_lock);
Signature · 1 line
2.39.5
author maintainer
#5 lore raw

PATCH v3 5/5 platform/x86: uniwill-laptop: Handle super key changed event

In reply to Armin Wolf

On many devices, the user can enable/disable the super key by pressing Fn + F9. Forward the associated event to the super_key_enable sysfs attribute as a poll notification.

---
 drivers/platform/x86/uniwill/uniwill-acpi.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/platform/x86/uniwill/uniwill-acpi.c +8 -2
index 8f214489e9ed..c1478878569b 100644
@@ -385,8 +385,6 @@ static const struct key_entry uniwill_keymap[] = {
 	 */
 	{ KE_IGNORE,    UNIWILL_OSD_SUPER_KEY_DISABLE,		{ KEY_UNKNOWN }},
 	{ KE_IGNORE,    UNIWILL_OSD_SUPER_KEY_ENABLE,		{ KEY_UNKNOWN }},
-	/* Optional, might not be reported by all devices */
-	{ KE_IGNORE,	UNIWILL_OSD_SUPER_KEY_STATE_CHANGED,	{ KEY_UNKNOWN }},
 
 	/* Reported in manual mode when toggling the airplane mode status */
 	{ KE_KEY,       UNIWILL_OSD_RFKILL,                     { KEY_RFKILL }},
@@ -1357,6 +1355,14 @@ static int uniwill_notifier_call(struct notifier_block *nb, unsigned long action
 	struct uniwill_battery_entry *entry;
 
 	switch (action) {
+	case UNIWILL_OSD_SUPER_KEY_STATE_CHANGED:
+		/* Optional, might not be reported by all devices */
+		if (!uniwill_device_supports(data, UNIWILL_FEATURE_SUPER_KEY))
+			return NOTIFY_DONE;
+
+		sysfs_notify(&data->dev->kobj, NULL, "super_key_enable");
+
+		return NOTIFY_OK;
 	case UNIWILL_OSD_BATTERY_ALERT:
 		if (!uniwill_device_supports(data, UNIWILL_FEATURE_BATTERY))
 			return NOTIFY_DONE;
Signature · 1 line
2.39.5