From nobody Sun Oct 5 10:44:55 2025 Received: from sender4-op-o15.zoho.com (sender4-op-o15.zoho.com [136.143.188.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0E30277CB4; Tue, 5 Aug 2025 14:01:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754402514; cv=pass; b=cbWm6Wnw95vA3+LszhnXTxuj/SxHMJLi4mEYGq054KQT1k7kcbTHxC1AHSox5DRedAcL2CZvzZZv2KuatKCrUz8mbJB4+U3MxFQr7iV4cURXGKzOWTldSxdhT/b8Lmu0B9/urelLr+nElu3iEAiBbmzFdq6lrucEfRS6XkPKcGI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754402514; c=relaxed/simple; bh=pb5l6V6MFgw+c2S3rC/qDHjKOTeDwdBvVTPGOtWjD2s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ka0XytoRb/7iCG7TPbznCpiZVBQTVcg1/NWKvZo6mNRHAlo71GgRWx1XgBceTc0hjqOjB5NPsIsgtVAgMmgZWmlYEpr8cT+t8Y11Vq5X/eesWIKenykzcp8IxDwhegf/sJ62YL1quPnsmKXgn56Pwwp55gZ/rRHUDTTPlzvrqXA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (1024-bit key) header.d=rong.moe header.i=i@rong.moe header.b=Ov9NjMw+; arc=pass smtp.client-ip=136.143.188.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=rong.moe header.i=i@rong.moe header.b="Ov9NjMw+" ARC-Seal: i=1; a=rsa-sha256; t=1754402500; cv=none; d=zohomail.com; s=zohoarc; b=TqthBYFwMrCDJPeeiFn5g4s/vHWV8+JcqwHfrG6SwILS/xeYdDGVV3F4U2/9EjSwjRUckNPp4hKahNVQ2FPahoBiZYJQ9CV5rrYb+3/gmgA5sGEgw7Qorm4FJy+kGivYoQhqjJ5O2oLCYim5ru1Gc8YBHfdpxbnKTKNZ1+eyKNU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1754402500; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=szgFRyrHBEXhnRIBZfTrku2yCNERmg+BCSoHdLQuY5U=; b=bq5eHCstPqYk+NrAw1cr+WzMWQNF5yFxN5aCzlP3D3V/wGtkt1NmaQMl5Bg+797wV2hij+52r+VpluACRtgCohuLzRvTwJ5ziMMvb2loc4DsIaO/S7ow3l/2+7FgEfaHMotUl9SXC+kW7Ydw9XODDbD8gtrJbvRo+txATkqbYew= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1754402500; s=zmail; d=rong.moe; i=i@rong.moe; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=szgFRyrHBEXhnRIBZfTrku2yCNERmg+BCSoHdLQuY5U=; b=Ov9NjMw+UCN+g9LrWDGAP3pQU28eajQOiHx912t0jwTLYufOMmOn3NnfN7NaLlKC /pub1VH5KZIIXDBlgBE2g2M90LfIJ0cp3d20Y746uLORuLzvqLlpVXEpmTqRPRiEbh5 eeSH8EzK43q4Xzn6vexRae8dZSonlDOW5fwrM9Wg= Received: by mx.zohomail.com with SMTPS id 1754402497801370.09200921968306; Tue, 5 Aug 2025 07:01:37 -0700 (PDT) From: Rong Zhang To: Ike Panhc , "Derek J. Clark" , Mark Pearson , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Hans de Goede Cc: Rong Zhang , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] platform/x86: ideapad-laptop: Decouple HW & cdev brightness for kbd backlight Date: Tue, 5 Aug 2025 22:01:28 +0800 Message-ID: <20250805140131.284122-2-i@rong.moe> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250805140131.284122-1-i@rong.moe> References: <20250805140131.284122-1-i@rong.moe> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" Some recent models come with an ambient light sensor (ALS). On these models, their EC will automatically set the keyboard backlight to an appropriate brightness when the effective "HW brightness" is 3. The term "HW brightness" means that it cannot be perfectly mapped to an LED classdev brightness, but the EC does use this predefined brightness value to represent such a mode. Currently, the code processing keyboard backlight is coupled with LED classdev, making it hard to expose the auto brightness (ALS) mode to the userspace. As the first step toward the goal, decouple HW brightness from LED classdev brightness, and update comments about corresponding backlight modes. Signed-off-by: Rong Zhang --- drivers/platform/x86/lenovo/ideapad-laptop.c | 125 +++++++++++++------ 1 file changed, 90 insertions(+), 35 deletions(-) diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platfor= m/x86/lenovo/ideapad-laptop.c index fcebfbaf0460..5014c1d0b633 100644 --- a/drivers/platform/x86/lenovo/ideapad-laptop.c +++ b/drivers/platform/x86/lenovo/ideapad-laptop.c @@ -119,17 +119,40 @@ enum { }; =20 /* - * These correspond to the number of supported states - 1 - * Future keyboard types may need a new system, if there's a collision - * KBD_BL_TRISTATE_AUTO has no way to report or set the auto state - * so it effectively has 3 states, but needs to handle 4 + * The enumeration has two purposes: + * - as an internal identifier for all known types of keyboard backlight + * - as a mandatory parameter of the KBLC command + * + * For each type, the HW brightness values are defined as follows: + * +--------------------------+----------+-----+------+------+ + * | HW brightness | 0 | 1 | 2 | 3 | + * | Type | | | | | + * +--------------------------+----------+-----+------+------+ + * | KBD_BL_STANDARD | off | on | N/A | N/A | + * +--------------------------+----------+-----+------+------+ + * | KBD_BL_TRISTATE | off | low | high | N/A | + * +--------------------------+----------+-----+------+------+ + * | KBD_BL_TRISTATE_AUTO | off | low | high | auto | + * +--------------------------+----------+-----+------+------+ + * + * We map LED classdev brightness for KBD_BL_TRISTATE_AUTO as follows: + * +--------------------------+----------+-----+------+ + * | LED classdev brightness | 0 | 1 | 2 | + * | Operation | | | | + * +--------------------------+----------+-----+------+ + * | Read | off/auto | low | high | + * +--------------------------+----------+-----+------+ + * | Write | off | low | high | + * +--------------------------+----------+-----+------+ */ enum { - KBD_BL_STANDARD =3D 1, - KBD_BL_TRISTATE =3D 2, - KBD_BL_TRISTATE_AUTO =3D 3, + KBD_BL_STANDARD =3D 1, + KBD_BL_TRISTATE =3D 2, + KBD_BL_TRISTATE_AUTO =3D 3, }; =20 +#define KBD_BL_AUTO_MODE_HW_BRIGHTNESS 3 + #define KBD_BL_QUERY_TYPE 0x1 #define KBD_BL_TRISTATE_TYPE 0x5 #define KBD_BL_TRISTATE_AUTO_TYPE 0x7 @@ -1559,7 +1582,25 @@ static int ideapad_kbd_bl_check_tristate(int type) return (type =3D=3D KBD_BL_TRISTATE) || (type =3D=3D KBD_BL_TRISTATE_AUTO= ); } =20 -static int ideapad_kbd_bl_brightness_get(struct ideapad_private *priv) +static int ideapad_kbd_bl_brightness_parse(struct ideapad_private *priv, + unsigned int hw_brightness) +{ + /* Off, low or high */ + if (hw_brightness <=3D priv->kbd_bl.led.max_brightness) + return hw_brightness; + + /* Auto (controlled by EC according to ALS), report as off */ + if (priv->kbd_bl.type =3D=3D KBD_BL_TRISTATE_AUTO && + hw_brightness =3D=3D KBD_BL_AUTO_MODE_HW_BRIGHTNESS) + return 0; + + /* Unknown value */ + dev_warn(&priv->platform_device->dev, + "Unknown keyboard backlight value: %u", hw_brightness); + return -EINVAL; +} + +static int ideapad_kbd_bl_hw_brightness_get(struct ideapad_private *priv) { unsigned long value; int err; @@ -1573,21 +1614,7 @@ static int ideapad_kbd_bl_brightness_get(struct idea= pad_private *priv) if (err) return err; =20 - /* Convert returned value to brightness level */ - value =3D FIELD_GET(KBD_BL_GET_BRIGHTNESS, value); - - /* Off, low or high */ - if (value <=3D priv->kbd_bl.led.max_brightness) - return value; - - /* Auto, report as off */ - if (value =3D=3D priv->kbd_bl.led.max_brightness + 1) - return 0; - - /* Unknown value */ - dev_warn(&priv->platform_device->dev, - "Unknown keyboard backlight value: %lu", value); - return -EINVAL; + return FIELD_GET(KBD_BL_GET_BRIGHTNESS, value); } =20 err =3D eval_hals(priv->adev->handle, &value); @@ -1597,6 +1624,16 @@ static int ideapad_kbd_bl_brightness_get(struct idea= pad_private *priv) return !!test_bit(HALS_KBD_BL_STATE_BIT, &value); } =20 +static int ideapad_kbd_bl_brightness_get(struct ideapad_private *priv) +{ + int hw_brightness =3D ideapad_kbd_bl_hw_brightness_get(priv); + + if (hw_brightness < 0) + return hw_brightness; + + return ideapad_kbd_bl_brightness_parse(priv, hw_brightness); +} + static enum led_brightness ideapad_kbd_bl_led_cdev_brightness_get(struct l= ed_classdev *led_cdev) { struct ideapad_private *priv =3D container_of(led_cdev, struct ideapad_pr= ivate, kbd_bl.led); @@ -1604,24 +1641,37 @@ static enum led_brightness ideapad_kbd_bl_led_cdev_= brightness_get(struct led_cla return ideapad_kbd_bl_brightness_get(priv); } =20 -static int ideapad_kbd_bl_brightness_set(struct ideapad_private *priv, uns= igned int brightness) +static int ideapad_kbd_bl_hw_brightness_set(struct ideapad_private *priv, + unsigned int hw_brightness) { int err; unsigned long value; int type =3D priv->kbd_bl.type; =20 if (ideapad_kbd_bl_check_tristate(type)) { - if (brightness > priv->kbd_bl.led.max_brightness) - return -EINVAL; - - value =3D FIELD_PREP(KBD_BL_SET_BRIGHTNESS, brightness) | + value =3D FIELD_PREP(KBD_BL_SET_BRIGHTNESS, hw_brightness) | FIELD_PREP(KBD_BL_COMMAND_TYPE, type) | KBD_BL_COMMAND_SET; err =3D exec_kblc(priv->adev->handle, value); } else { - err =3D exec_sals(priv->adev->handle, brightness ? SALS_KBD_BL_ON : SALS= _KBD_BL_OFF); + err =3D exec_sals(priv->adev->handle, + hw_brightness ? SALS_KBD_BL_ON : SALS_KBD_BL_OFF); } =20 + if (err) + return err; + + return 0; +} + +static int ideapad_kbd_bl_brightness_set(struct ideapad_private *priv, uns= igned int brightness) +{ + int err; + + if (brightness > priv->kbd_bl.led.max_brightness) + return -EINVAL; + + err =3D ideapad_kbd_bl_hw_brightness_set(priv, brightness); if (err) return err; =20 @@ -1638,6 +1688,16 @@ static int ideapad_kbd_bl_led_cdev_brightness_set(st= ruct led_classdev *led_cdev, return ideapad_kbd_bl_brightness_set(priv, brightness); } =20 +static void ideapad_kbd_bl_notify_known(struct ideapad_private *priv, unsi= gned int brightness) +{ + if (brightness =3D=3D priv->kbd_bl.last_brightness) + return; + + priv->kbd_bl.last_brightness =3D brightness; + + led_classdev_notify_brightness_hw_changed(&priv->kbd_bl.led, brightness); +} + static void ideapad_kbd_bl_notify(struct ideapad_private *priv) { int brightness; @@ -1649,12 +1709,7 @@ static void ideapad_kbd_bl_notify(struct ideapad_pri= vate *priv) if (brightness < 0) return; =20 - if (brightness =3D=3D priv->kbd_bl.last_brightness) - return; - - priv->kbd_bl.last_brightness =3D brightness; - - led_classdev_notify_brightness_hw_changed(&priv->kbd_bl.led, brightness); + ideapad_kbd_bl_notify_known(priv, brightness); } =20 static int ideapad_kbd_bl_init(struct ideapad_private *priv) --=20 2.50.1 From nobody Sun Oct 5 10:44:55 2025 Received: from sender4-op-o12.zoho.com (sender4-op-o12.zoho.com [136.143.188.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5195E2798EF; Tue, 5 Aug 2025 14:01:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.12 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754402516; cv=pass; b=i/yWMfAuvmY3/pkQL5PCxNzxgSPp8cXuFwE4TjI2VLibIPxBo5fqy2fHrfrritg8hobPfYkRT3LOf0kI6o7P9igbxivTlXTLrbpB9TlltMgaElw6QQaGJQKqv11wVyBevOtRKtPdYEC1Sf0qEWxYUmklLBx0ARy6eWS1DGStQpU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754402516; c=relaxed/simple; bh=XIxQxnU0xVK+cxhZrdEdccN8S9oUSm9/ytnvIqa1W5g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uyjYM6PC1CHtKun2ZFThna8tP1NeOEc/sTmp2Qye966mxymAS5dOq+IaOs982b5y1sRVw1+B+87Hh24IAuUwk6nxqYmCBUnO1BBTuZV17mcmf9cwwbmbioVz55X6D30JzPi8dfeNmbBr2pdBeKBlqtGTeMF/ehYCJBR3LPicb6c= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (1024-bit key) header.d=rong.moe header.i=i@rong.moe header.b=iudBfvHW; arc=pass smtp.client-ip=136.143.188.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=rong.moe header.i=i@rong.moe header.b="iudBfvHW" ARC-Seal: i=1; a=rsa-sha256; t=1754402504; cv=none; d=zohomail.com; s=zohoarc; b=CPAhJ38echNu7NwuPSApJAYpsp9NQZFeP6B8agGEyv3JJrK0NPCEV/mDledoyhdyTN4R1px0fheXhKL8Gt0C3DBUf4f3XToc24utZTrrfgj80SRTmQglyG4DzFSz3zcnmfPKxg8G2Fvnyb0l/zmKalbB0JN21bXsUUiaX7XfJTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1754402504; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=KLD0agmNAMnmyf27fVCPlQIUAQ3zVBfhyAEJ7jRU07s=; b=gxcmsucE2vkOHciHnD5SE8TBOTmjdjLKlWyEF3vol7yi0MBavywe9HLBqr11lMw0DwRlFULJMq+jV17MOIgA7cXVEt9E/bWL38G8dMngspiYqiNJNG7cgnggoqDuHkSc0i8TGNiqONFyXlGLVJ5aPOWwJO0B+CFJfFNjIwU2zfg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1754402504; s=zmail; d=rong.moe; i=i@rong.moe; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=KLD0agmNAMnmyf27fVCPlQIUAQ3zVBfhyAEJ7jRU07s=; b=iudBfvHWAuxuejX+Fs8hxlwJBf4vuchRVGJ1X4BCpRSBsCxCJGw/2eid2T9KjPgN lCo+j5jYO4vehWyhPSp9yqVXhKzEDvPuJby6cB0tLdb7q17SoW0eUq8Y0cELrrNmvEc 4zSDfFrm5WKHBXZ5G7MZhvcKr7w+eIX+CBE8cXe0= Received: by mx.zohomail.com with SMTPS id 1754402502071948.9728883893175; Tue, 5 Aug 2025 07:01:42 -0700 (PDT) From: Rong Zhang To: Ike Panhc , "Derek J. Clark" , Mark Pearson , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Hans de Goede Cc: Rong Zhang , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] platform/x86: ideapad-laptop: Fully support auto kbd backlight Date: Tue, 5 Aug 2025 22:01:29 +0800 Message-ID: <20250805140131.284122-3-i@rong.moe> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250805140131.284122-1-i@rong.moe> References: <20250805140131.284122-1-i@rong.moe> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" Currently, the auto brightness mode of keyboard backlight maps to brightness=3D0 in LED classdev. The only method to switch to such a mode is by pressing the manufacturer-defined shortcut (Fn+Space). However, 0 is a multiplexed brightness value; writing 0 simply results in the backlight being turned off. With brightness processing code decoupled from LED classdev, we can now fully support the auto brightness mode. In this mode, the keyboard backlight is controlled by the EC according to the ambient light sensor (ALS). To utilize this, a sysfs node is exposed to the userspace: /sys/class/leds/platform::kbd_backlight/als_enabled. The name is chosen to align with dell-laptop, which provides a similar feature. Signed-off-by: Rong Zhang --- .../ABI/testing/sysfs-platform-ideapad-laptop | 12 ++++ drivers/platform/x86/lenovo/ideapad-laptop.c | 65 ++++++++++++++++++- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-platform-ideapad-laptop b/Docu= mentation/ABI/testing/sysfs-platform-ideapad-laptop index 5ec0dee9e707..a2b78aa60aaa 100644 --- a/Documentation/ABI/testing/sysfs-platform-ideapad-laptop +++ b/Documentation/ABI/testing/sysfs-platform-ideapad-laptop @@ -50,3 +50,15 @@ Description: Controls whether the "always on USB charging" feature is enabled or not. This feature enables charging USB devices even if the computer is not turned on. + +What: /sys/class/leds/platform::kbd_backlight/als_enabled +Date: July 2025 +KernelVersion: 6.17 +Contact: platform-driver-x86@vger.kernel.org +Description: + This file allows to control the automatic keyboard + illumination mode on some systems that have an ambient + light sensor. Write 1 to this file to enable the auto + mode, 0 to disable it. In this mode, the actual + brightness level is not available and reading the + "brightness" file always returns 0. diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platfor= m/x86/lenovo/ideapad-laptop.c index 5014c1d0b633..49f2fc68add4 100644 --- a/drivers/platform/x86/lenovo/ideapad-laptop.c +++ b/drivers/platform/x86/lenovo/ideapad-laptop.c @@ -1712,6 +1712,57 @@ static void ideapad_kbd_bl_notify(struct ideapad_pri= vate *priv) ideapad_kbd_bl_notify_known(priv, brightness); } =20 +static ssize_t als_enabled_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct led_classdev *led_cdev =3D dev_get_drvdata(dev); + struct ideapad_private *priv =3D container_of(led_cdev, struct ideapad_pr= ivate, kbd_bl.led); + int hw_brightness; + + hw_brightness =3D ideapad_kbd_bl_hw_brightness_get(priv); + if (hw_brightness < 0) + return hw_brightness; + + return sysfs_emit(buf, "%d\n", hw_brightness =3D=3D KBD_BL_AUTO_MODE_HW_B= RIGHTNESS); +} + +static ssize_t als_enabled_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct led_classdev *led_cdev =3D dev_get_drvdata(dev); + struct ideapad_private *priv =3D container_of(led_cdev, struct ideapad_pr= ivate, kbd_bl.led); + bool state; + int err; + + err =3D kstrtobool(buf, &state); + if (err) + return err; + + /* + * Auto (ALS) mode uses a predefined HW brightness value. It is + * impossible to disable it without setting another brightness value. + * Set the brightness to 0 when disabling is requested. + */ + err =3D ideapad_kbd_bl_hw_brightness_set(priv, state ? KBD_BL_AUTO_MODE_H= W_BRIGHTNESS : 0); + if (err) + return err; + + /* Both HW brightness values map to 0 in the LED classdev. */ + ideapad_kbd_bl_notify_known(priv, 0); + + return count; +} + +static DEVICE_ATTR_RW(als_enabled); + +static struct attribute *ideapad_kbd_bl_als_attrs[] =3D { + &dev_attr_als_enabled.attr, + NULL, +}; +ATTRIBUTE_GROUPS(ideapad_kbd_bl_als); + static int ideapad_kbd_bl_init(struct ideapad_private *priv) { int brightness, err; @@ -1722,10 +1773,20 @@ static int ideapad_kbd_bl_init(struct ideapad_priva= te *priv) if (WARN_ON(priv->kbd_bl.initialized)) return -EEXIST; =20 - if (ideapad_kbd_bl_check_tristate(priv->kbd_bl.type)) { + switch (priv->kbd_bl.type) { + case KBD_BL_TRISTATE_AUTO: + /* The sysfs node will be /sys/class/leds/platform::kbd_backlight/als_en= abled */ + priv->kbd_bl.led.groups =3D ideapad_kbd_bl_als_groups; + fallthrough; + case KBD_BL_TRISTATE: priv->kbd_bl.led.max_brightness =3D 2; - } else { + break; + case KBD_BL_STANDARD: priv->kbd_bl.led.max_brightness =3D 1; + break; + default: + /* This has already been validated by ideapad_check_features(). */ + unreachable(); } =20 brightness =3D ideapad_kbd_bl_brightness_get(priv); --=20 2.50.1