From c393505bab5b1fa25aa702c04a25b3bae0a570ee Mon Sep 17 00:00:00 2001 From: Armin Wolf Date: Sat, 30 May 2026 19:08:09 +0200 Subject: [PATCH] platform/x86: uniwill-laptop: Add AC auto boot support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Signed-off-by: Armin Wolf Link: https://patch.msgid.link/20260530170813.10166-4-W_Armin@gmx.de Reviewed-by: Ilpo Järvinen Signed-off-by: Ilpo Järvinen --- .../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(+) diff --git a/Documentation/ABI/testing/sysfs-driver-uniwill-laptop b/Documentation/ABI/testing/sysfs-driver-uniwill-laptop index 2397c65c969a..57272f906184 100644 --- a/Documentation/ABI/testing/sysfs-driver-uniwill-laptop +++ b/Documentation/ABI/testing/sysfs-driver-uniwill-laptop @@ -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 +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. diff --git a/Documentation/admin-guide/laptops/uniwill-laptop.rst b/Documentation/admin-guide/laptops/uniwill-laptop.rst index 2b1e5da703a5..b6213fb1d3e0 100644 --- a/Documentation/admin-guide/laptops/uniwill-laptop.rst +++ b/Documentation/admin-guide/laptops/uniwill-laptop.rst @@ -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 ========== diff --git a/drivers/platform/x86/uniwill/uniwill-acpi.c b/drivers/platform/x86/uniwill/uniwill-acpi.c index b3be2f2dbdd8..897c6163de53 100644 --- a/drivers/platform/x86/uniwill/uniwill-acpi.c +++ b/drivers/platform/x86/uniwill/uniwill-acpi.c @@ -112,6 +112,9 @@ #define EC_ADDR_BAT_CYCLE_COUNT_2 0x04A7 +#define EC_ADDR_OEM_9 0x0726 +#define AC_AUTO_BOOT_ENABLE BIT(3) + #define EC_ADDR_PROJECT_ID 0x0740 #define PROJECT_ID_NONE 0x00 #define PROJECT_ID_GI 0x01 @@ -364,6 +367,7 @@ #define UNIWILL_FEATURE_NVIDIA_CTGP_CONTROL BIT(10) #define UNIWILL_FEATURE_USB_C_POWER_PRIORITY BIT(11) #define UNIWILL_FEATURE_KEYBOARD_BACKLIGHT BIT(12) +#define UNIWILL_FEATURE_AC_AUTO_BOOT BIT(13) enum usb_c_power_priority_options { USB_C_POWER_PRIORITY_CHARGING = 0, @@ -586,6 +590,7 @@ static const struct regmap_bus uniwill_ec_bus = { static bool uniwill_writeable_reg(struct device *dev, unsigned int reg) { switch (reg) { + case EC_ADDR_OEM_9: case EC_ADDR_AP_OEM: case EC_ADDR_LIGHTBAR_AC_CTRL: case EC_ADDR_LIGHTBAR_AC_RED: @@ -625,6 +630,7 @@ static bool uniwill_readable_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_OEM_9: case EC_ADDR_PROJECT_ID: case EC_ADDR_AP_OEM: case EC_ADDR_LIGHTBAR_AC_CTRL: @@ -1136,6 +1142,45 @@ static int usb_c_power_priority_init(struct uniwill_data *data) return 0; } +static ssize_t ac_auto_boot_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct uniwill_data *data = dev_get_drvdata(dev); + unsigned int regval; + bool enable; + int ret; + + ret = kstrtobool(buf, &enable); + if (ret < 0) + return ret; + + if (enable) + regval = AC_AUTO_BOOT_ENABLE; + else + regval = 0; + + ret = regmap_update_bits(data->regmap, EC_ADDR_OEM_9, AC_AUTO_BOOT_ENABLE, regval); + if (ret < 0) + return ret; + + return count; +} + +static ssize_t ac_auto_boot_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct uniwill_data *data = dev_get_drvdata(dev); + unsigned int regval; + int ret; + + ret = regmap_read(data->regmap, EC_ADDR_OEM_9, ®val); + if (ret < 0) + return ret; + + return sysfs_emit(buf, "%d\n", !!(regval & AC_AUTO_BOOT_ENABLE)); +} + +static DEVICE_ATTR_RW(ac_auto_boot); + static struct attribute *uniwill_attrs[] = { /* Keyboard-related */ &dev_attr_fn_lock.attr, @@ -1147,6 +1192,7 @@ static struct attribute *uniwill_attrs[] = { /* Power-management-related */ &dev_attr_ctgp_offset.attr, &dev_attr_usb_c_power_priority.attr, + &dev_attr_ac_auto_boot.attr, NULL }; @@ -1186,6 +1232,11 @@ static umode_t uniwill_attr_is_visible(struct kobject *kobj, struct attribute *a return attr->mode; } + if (attr == &dev_attr_ac_auto_boot.attr) { + if (uniwill_device_supports(data, UNIWILL_FEATURE_AC_AUTO_BOOT)) + return attr->mode; + } + return 0; }