From nobody Mon Sep 15 03:55:53 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65416C3DA78 for ; Sun, 15 Jan 2023 23:01:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231346AbjAOXBz (ORCPT ); Sun, 15 Jan 2023 18:01:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231381AbjAOXBv (ORCPT ); Sun, 15 Jan 2023 18:01:51 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 206E210428; Sun, 15 Jan 2023 15:01:50 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id d9so28564805pll.9; Sun, 15 Jan 2023 15:01:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=AWNlysJq0lnDtbSKvo7T7muCSIE9cK6qJbiITiHffwM=; b=ds0/Dsx056A9dQBoiIZArdP2boxGzDMZcKAYB5MQp1vG0Uc2I+YscriDmut/gQBUSM v6Kkvg9GmH/xejXlYOg7JCtKgq9J9Ay/C3MnHK7f06KjX4c5tntXfAwdv0KReDSdB8gc Sbt7k3TM5QH6BlSkQWkXiBFdp5gmzhPA2yEtWCRgQXNV56xYamfsjSSsAMfEnp8dyfxM IHemzc9BpULy8RAn3sgVePK+WBdLTmgsD7Zzbf52lS2fOSXdMO8tA6YCeY07z5Hdi/Oa crashmkPTsbwKLnFozkZUX6SZQkyb5lBGH8+zHZh1Xk8NdV9HLiBHFlEn1jhqE4oyucG tPVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AWNlysJq0lnDtbSKvo7T7muCSIE9cK6qJbiITiHffwM=; b=CGJw2GHiqRJAXVzmQXsgYZ67lO31O2tX8oxv4ZjwwsMmJnPSTVqluGYgEXzhu+teFS HP1ib44nsi064Wc91CaukxvW03nwuVudBNpTBKilr3yl135AqM3lOsYvGxT+vfR9xA8U lhNcq5VbfVwHPvN6iIkVlR00qWVopG/Te1GNk9WfBVQYQIuvbGH06e/7GfGiELJa3+K3 Vjt/zqj+M4jmQwTGjN9/tDTDKPU1BSfxA5oprCZ+D1m/5YS63wszyhNQzQcFUEU4hSkT 8fdC6n68TQCXNW4IA0n87+1RuU6n/UGKayN1zWrSnOR2qwGac24+ciSJYCnkQ3xO3idr VNHg== X-Gm-Message-State: AFqh2kovoGYkhFKj0XF3z2IR+3foJa3Vd+duwJ8J6s/+gjeEN4F7U1cU Hr0uig1yk2WWduDquTh1aCGgqH2kzhP54B7P X-Google-Smtp-Source: AMrXdXuO6o2CBDXDhZhy5lfSBGHQNlupsXAhE4S02tsSIHSZk/2mWziKsU8ST+nPZO1f7pPn0ACJoQ== X-Received: by 2002:a17:902:c814:b0:193:a5b:ccf6 with SMTP id u20-20020a170902c81400b001930a5bccf6mr21683890plx.0.1673823709041; Sun, 15 Jan 2023 15:01:49 -0800 (PST) Received: from rishit-OMEN-Laptop-15-en0xxx ([171.76.81.196]) by smtp.gmail.com with ESMTPSA id d17-20020a170902ced100b00168dadc7354sm17907377plg.78.2023.01.15.15.01.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Jan 2023 15:01:48 -0800 (PST) Date: Mon, 16 Jan 2023 04:31:44 +0530 From: Rishit Bansal To: Hans de Goede , Mark Gross , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] platform/x86: hp-wmi: Support omen backlight control wmi-acpi methods Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The HP Omen Command Studio application includes a Light Studio feature which can be used to control various features related to the keyboard backlight via the 0x20009 command. The command supports the following queries: - 0x1: Checks if keyboard lighting is supported - 0x2: Get the zone colors of each of the 4 zones on the keyboard - 0x3: Set the zone colors of each of the 4 zones on the keyboard - 0x4: Gets the state (on/off) of the backlight - 0x5: Sets the state (on/off) of the backlight This patch introduces a new sysfs led class called "hp_omen::kbd_backlight" which can be used to control the state of the backlight. It also includes a sysfs RW attribute called "backlight_color" which can be used to get/set the current color of each zone. The patch has been tested on an HP Omen 15-en0037AX (AMD) laptop. Signed-off-by: Rishit Bansal --- drivers/platform/x86/hp/hp-wmi.c | 110 +++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-= wmi.c index 0a99058be813..0dd6f1b6d9e1 100644 --- a/drivers/platform/x86/hp/hp-wmi.c +++ b/drivers/platform/x86/hp/hp-wmi.c @@ -27,6 +27,7 @@ #include #include #include +#include =20 MODULE_AUTHOR("Matthew Garrett "); MODULE_DESCRIPTION("HP laptop WMI hotkeys driver"); @@ -136,6 +137,7 @@ enum hp_wmi_command { HPWMI_WRITE =3D 0x02, HPWMI_ODM =3D 0x03, HPWMI_GM =3D 0x20008, + HPWMI_KB =3D 0x20009, }; =20 enum hp_wmi_hardware_mask { @@ -734,12 +736,56 @@ static ssize_t postcode_store(struct device *dev, str= uct device_attribute *attr, return count; } =20 +static ssize_t kbd_rgb_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + u8 val[128]; + + int ret =3D hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, HPWMI_KB, &val, + zero_if_sup(val), sizeof(val)); + + if (ret) + return ret; + + strncat(buf, &val[25], 12); + + return strlen(buf); +} + +static ssize_t kbd_rgb_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + u8 val[128]; + int ret; + + ret =3D hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, HPWMI_KB, &val, + zero_if_sup(val), sizeof(val)); + + if (ret) + return ret; + + if (count !=3D 12) + return -1; + + strncpy(&val[25], buf, count); + + ret =3D hp_wmi_perform_query(HPWMI_ALS_QUERY, HPWMI_KB, &val, sizeof(val), + 0); + + if (ret) + return ret; + + return count; +} + static DEVICE_ATTR_RO(display); static DEVICE_ATTR_RO(hddtemp); static DEVICE_ATTR_RW(als); static DEVICE_ATTR_RO(dock); static DEVICE_ATTR_RO(tablet); static DEVICE_ATTR_RW(postcode); +static DEVICE_ATTR_RW(kbd_rgb); =20 static struct attribute *hp_wmi_attrs[] =3D { &dev_attr_display.attr, @@ -748,6 +794,7 @@ static struct attribute *hp_wmi_attrs[] =3D { &dev_attr_dock.attr, &dev_attr_tablet.attr, &dev_attr_postcode.attr, + &dev_attr_kbd_rgb.attr, NULL, }; ATTRIBUTE_GROUPS(hp_wmi); @@ -1294,6 +1341,63 @@ static int thermal_profile_setup(void) =20 static int hp_wmi_hwmon_init(void); =20 +static struct led_classdev omen_kbd_led; + +static enum led_brightness get_omen_backlight_brightness(struct led_classd= ev *cdev) +{ + u8 val; + + int ret =3D hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, HPWMI_KB, &val, ze= ro_if_sup(val), sizeof(val)); + + if (ret) + return ret; + + return (val & 0x80) ? LED_ON : LED_OFF; +} + +static void set_omen_backlight_brightness(struct led_classdev *cdev, enum = led_brightness value) +{ + char buffer[4] =3D { (value =3D=3D LED_OFF) ? 0x64 : 0xe4, 0, 0, 0 }; + + hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, HPWMI_KB, &buffer, + sizeof(buffer), 0); +} + + +static bool is_omen_lighting_supported(void) +{ + u8 val; + + int ret =3D hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, HPWMI_KB, &val, zer= o_if_sup(val), sizeof(val)); + + if (ret) + return false; + + return (val & 1) =3D=3D 1; +} + +static int omen_backlight_init(struct device *dev) +{ + int ret; + + omen_kbd_led.name =3D "hp_omen::kbd_backlight"; + omen_kbd_led.brightness_set =3D set_omen_backlight_brightness; + omen_kbd_led.brightness_get =3D get_omen_backlight_brightness; + omen_kbd_led.max_brightness =3D 1; + + ret =3D devm_led_classdev_register(dev, &omen_kbd_led); + + if (ret < 0) + return -1; + + return 0; +} + +static void omen_backlight_exit(struct device *dev) +{ + devm_led_classdev_unregister(dev, &omen_kbd_led); +} + static int __init hp_wmi_bios_setup(struct platform_device *device) { int err; @@ -1321,6 +1425,9 @@ static int __init hp_wmi_bios_setup(struct platform_d= evice *device) =20 thermal_profile_setup(); =20 + if (is_omen_lighting_supported()) + omen_backlight_init(&device->dev); + return 0; } =20 @@ -1349,6 +1456,9 @@ static int __exit hp_wmi_bios_remove(struct platform_= device *device) if (platform_profile_support) platform_profile_remove(); =20 + if (is_omen_lighting_supported()) + omen_backlight_exit(&device->dev); + return 0; } =20 --=20 2.37.2