From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.182.112 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796302785; b=33WCEIkPqg7jxEweopZUNsyCSgRp1DCa/VOa16oL8ItUZVJH6ELAbgzRGDuB9chuQWQ+ iwYXVxWyJDbC/a86PdzU5t4wsjLdtZwzdMl+kEMqU5n0PMJFvrGL5c7HqsxHbtq1DCPyU NK6JZcbgv0PASBSDDCVmg2BQB+a+73N8E4oP+UkrOner9NOmN25v8gDTMKIjehWLmZmaK 9Q9ZFHmWDZZYEUqYX+eoh8fqSaG2AM88tiQ2wKJZu9Fx9/CuLPn+xuuWapjXNdLfIkirj AYdkDemnr6ntI9EOy4ZYJXtSkux9ExwUjBrEJhyNlB9Tm0DEe1Ua1JpmI55oqMHo4GA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796302785; h=DMARC-Filter:DKIM-Signature:Received:Message-ID:Subject:From:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date: MIME-Version:User-Agent:X-ZohoMailClient; bh=3L1FvawjfMA0MIgm1aR4ni/YfmmZRpXERZlusQ9ueaU=; b=gh12NhnHCQOm//G2mZ3Y6MwyMopPpMQyJWWLqxyWQBYAoIDxjszytAZ/hBZdbAT/+dpm KbvFlFXuQjc65oASWmWl8G3Qstt6h9kW3OKtNaLwDiSvs6niX4zfTP44Lqd9vNey2uvgj 16OtMK4aS0auVZnsFku+Fu/kya3+xOZzSPYwBXAg5qtHSgYdRJbBGCbabgf732DeNPV6q SwSfzwhuijGHo+X3aAjsYTUcx0061UWVK38fcLCT/G0EQfVNAH2R762c2QDedtB85hVaN iokQbdUkvu0GrhiVEteHUops9k2u8EB24wSp02PouKx0v0P2BNOdo12AK3sL2UeH0uA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass header.d=rong.moe header.i=@rong.moe header.a=rsa-sha256 header.s=zmail2048 header.b=I1ZiZic5; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.182.112 Received: from sender5-pp-f112.zoho.com (sender5-pp-f112.zoho.com [165.173.182.112]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCD8E606A33A; Thu, 3 Dec 2026 12:59:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BCD8E606A33A 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 (2048-bit key, unprotected) header.d=rong.moe header.i=@rong.moe header.a=rsa-sha256 header.s=zmail2048 header.b=I1ZiZic5 ARC-Seal: i=1; a=rsa-sha256; t=1796302764; cv=none; d=zohomail.com; s=zohoarc; b=eq/WPG2K82oKU+e6241i3ci57zzKdOU87dHaOFVMG8pzqIWwMw8hRv+D8b1E3vrigWvwrftp5SvdNh0ZM2ywOxJiatqS2Rlb2JfrlSM+EopEwfK6KJmrYEYCYePYcYvyGiBxtflRJDJlu9xrLgCaRm4RUaq7doOY21hmGH8pfL0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1796302764; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=3L1FvawjfMA0MIgm1aR4ni/YfmmZRpXERZlusQ9ueaU=; b=hxJhqRWPvh0V82sKDa1GPqC20dfdGTqRDkSid7KArkJKA4xOfVnTYhbGT4cgX2CtJ6m5b5NzK+MX1WdwVlOMBP//LywUZZz+KniTYpB2XPqx+a8QsxxZVDKnirJVR0zKHcGjE4019RMuFxitLxjxJTEAqK0mU/EJTg4o3Esvy2A= 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: a=rsa-sha256; b=I1ZiZic5+uJvkbokRy8SshYqqtLiBtCjQCggaNH0y8b9sX7h7ESqwxBER/pmaO6IWOolb87H9tsbK9670w+qETg/oIG0j/F13OhZq47V0/vJogTcOJF6TGbVmss47Y7vs0LCdE563ljHMuZHgNWyN/Ne+QAzmk8R+397O/z456N3oHVIe0BXj3P2yJanhnhxqLxHnkt11Is81MVm8Wd44QFk2VY8vQMD3mUo6UQ7ovEd+InEsFP3zTRSAbGp3wWFevPxZnPsfIQMi02kedbY0f+bQ7yxJSLtnQu8aV8AchjtE6Kr50Z/OKVMUiC7eqi+QoZ+SJ2ATYQLBTQADMWRyQ==; c=relaxed/relaxed; s=zmail2048; d=rong.moe; v=1; bh=3L1FvawjfMA0MIgm1aR4ni/YfmmZRpXERZlusQ9ueaU=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1796302762623509.07938207406403; Thu, 3 Dec 2026 04:59:22 -0800 (PST) Message-ID: <18e4b16c0d1c80e7e72d3c1b9656e5a6753d205e.camel@rong.moe> Subject: Re: [PATCH v4] HID: lenovo-legion: Add keyboard backlight driver for Legion Gen 10 From: Rong Zhang To: Ilpo =?ISO-8859-1?Q?J=E4rvinen?= Cc: ciro.pedrini@gmail.com, Mark Pearson , "Derek J. Clark" , Ike Panhc , Hans de Goede , Jiri Kosina , Benjamin Tissoires , David Cemin , Marco Giunta , Werner Sembach , Aaron Erhardt , platform-driver-x86@vger.kernel.org, LKML , linux-input@vger.kernel.org In-Reply-To: <582b3fa9-c290-65d8-c0d0-65215f2299f5@linux.intel.com> References: <20261201-legion-lighting-rfc-v4-1-02acc82bc0b6@gmail.com> <582b3fa9-c290-65d8-c0d0-65215f2299f5@linux.intel.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 20:54:16 +0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Evolution 3.62.1-4 X-ZohoMailClient: External Hi Ilpo, On Wed, 2026-12-02 at 16:05 +0200, Ilpo J=C3=A4rvinen wrote: > On Wed, 2 Dec 2026, Rong Zhang wrote: >=20 > > Hi Ciro, > >=20 > > Thanks for working on this. > >=20 > > On Tue, 2026-12-01 at 21:53 +0000, Ciro Pedrini via B4 Relay wrote: > > > From: Ciro Pedrini > > >=20 > > > The keyboard backlight of the Lenovo Legion Pro 7 16IAX10H (2025) has= no > > > Linux support: on the test unit nothing ever lit, because the keyboar= d > > > controller's brightness was 0 from the factory and nothing exposes it= . > > >=20 > > > The ITE 8258 keyboard controller (048d:c197) is the built-in keyboard= and > > > carries a vendor protocol on feature report 0x07 (up to 960 bytes): a > > > request, answered by reading the report back. Its hardware brightness= , > > > 0..9, is stored in the controller and applies to every LED of the mac= hine > > > (keys, front strip, rear vents, lid logo). The firmware handles Fn+Up= and > > > Fn+Down itself and reports the new level on vendor input report 5; it > > > reports every other set there too, the host's and unchanged ones > > > included. > > >=20 > > > Expose the brightness as a kbd_backlight LED, :kbd_backlight, with > > > brightness_hw_changed for the hotkeys so that desktops show their OSD= . > > > Only a change of the level is reported there, so the host's own sets = and > > > Fn+Space, which come back with the level already known, are not. > > > Unregistering keeps the level (LED_RETAIN_AT_SHUTDOWN): switching it = off > > > would be stored by the controller. > > >=20 > > > The same controller ID is used by models whose white backlight is dri= ven > > > by ideapad-laptop instead (Legion Y9000P IAX10: same DMI and BIOS). T= here > > > the controller's op 0xD1 reads 1 instead of 0, and the driver registe= rs > > > no LED, leaving the keyboard as it is. > > >=20 > > > The colours stay the controller's own effects, which Fn+Space cycles.= The > > > machine's HID LampArray (048d:c193) is left to hid-generic, or to a > > > generic LampArray driver. > > >=20 > > > Tested on the 16IAX10H (83F5) with 7.3 as a module: brightness from s= ysfs > > > and KDE, the hotkeys with KDE's OSD, unbinding and rebinding. > > >=20 > > > Signed-off-by: Ciro Pedrini > > > --- > > > Hi, > > >=20 > > > This is v4 of the Legion keyboard backlight driver. Ilpo applied the > > > ideapad-laptop patch (1/2 of v3), so this is only the HID driver now. > > >=20 > > > Short background: on my laptop the keyboard backlight never turned on > > > under Linux. The keyboard controller (048d:c197) stores a brightness = from > > > 0 to 9 behind a vendor feature report (0x07), it was 0 from the facto= ry, > > > and nothing on Linux could change it. That brightness dims every LED = of > > > the machine. Fn+Up/Down/Space are handled by the firmware, which send= s > > > the new level on a vendor input report. The driver exposes the > > > brightness as a kbd_backlight LED, with brightness_hw_changed for the > > > hotkeys so the desktop OSD works. > > >=20 > > > Besides the locking changes from the v3 review, v4 checks op 0xD1 in > > > probe, as Marco suggested: the Legion Y9000P IAX10 has the same > > > controller ID, DMI and BIOS, but a white backlight driven by > > > ideapad-laptop, and reads 1 there (0 here and on Marco's 16AFR10H). O= n > > > such a machine the driver registers no LED and leaves the keyboard as > > > it is. I could only test the 0 case. > > >=20 > > > The other WMI codes Marco found (each brightness level and effect has > > > its own) will follow as a separate ideapad-laptop patch on top of > > > Ilpo's branch. > > >=20 > > > I tested it on my 16IAX10H (83F5, BIOS Q7CN77WW) with 7.3 as a module= : > > > brightness from sysfs and KDE, the hotkeys and the OSD, Fn+Space, > > > unbind and rebind. It's based on pdx86 review-ilpo-next and builds wi= th > > > W=3D1. > > >=20 > > > About how this was made: I found the protocol with usbmon captures an= d > > > by looking at Lenovo's Windows software. I wrote the code with help f= rom > > > Claude Code (Claude Opus 5.5). I went through all of it and tested it > > > myself, and the patch has a short note about it below the ---. > > >=20 > > > Thanks, > > > Ciro > > > --- > > > Changes in v4: > > > - Only the HID driver: the ideapad-laptop patch was applied by Ilpo. > > > - Locking (Rong, Marco, Sashiko): brightness set/get hold the mutex f= or > > > the whole exchange and legion_raw_command() asserts it; the level i= s an > > > atomic_t shared with raw_event (xchg, and cmpxchg to undo a failed > > > set); get no longer updates it, probe reads it once. > > > - Back to one buffer allocated in probe; no memset before the GET (Ro= ng). > > > - Op 0xD1 is read in probe; if it isn't 0, no LED is registered (Marc= o, > > > Rong). > > > - LED name ":kbd_backlight", without the vendor devicename (Marco). > > > - Link to v3: https://lore.kernel.org/r/20261127-legion-lighting-rfc-= v3-0-15c55d9f15b7@gmail.com > > >=20 > > > Changes in v3: > > > - Short reports: send only the request bytes and read only the answer > > > bytes, right after the request; no more 100 ms wait (Rong). > > > - The buffer is allocated per exchange. Not on the stack as Rong > > > suggested: usbhid hands it to the USB core for DMA. > > > - legion_raw_command() and legion_simple_command(), and the request > > > length checked against the 960-byte report with a static_assert > > > (Rong). > > > - Out-of-range values and failed reads return errors instead of being > > > clamped or replaced; dbg messages, no hex dump (Ilpo, Rong). > > > - devm for hid_hw_start()/hid_hw_open() and the LED; .remove stays, > > > empty, so hid-core doesn't stop the device twice (Ilpo, Rong). > > > - Dropped the (int) casts and the "(2025)"; comments trimmed, the one > > > about HID_QUIRK_INPUT_PER_APP now says why; Kconfig help about what > > > the driver does (Ilpo, Rong). > > > - New: only report a level change to brightness_hw_changed (see above= ). > > > - Rebased on current pdx86 for-next; Rong's Acked-by on patch 1. > > > - Link to v2: https://lore.kernel.org/r/20261110-legion-lighting-rfc-= v2-0-845726afb71c@gmail.com > > >=20 > > > Changes in v2: > > > - Only the keyboard controller (c197) now, as Rong suggested. No > > > LampArray, no colours, no lighting_mode, just a kbd_backlight LED. > > > - Ilpo's comments: struct with __le16 for the request, guard(), > > > devm_mutex_init(), no magic numbers, includes. > > > - Removed the "ready" flag, its spinlock and the work item. raw_event > > > can't run during probe/remove, so it notifies the LED directly. > > > - Keep led_cdev.brightness in sync with the hotkeys (from the Sashiko > > > review). > > > - Moved the note about the AI tool out of the changelogs, below the -= --. > > > - Link to v1: https://lore.kernel.org/r/20261109-legion-lighting-rfc-= v1-0-a87e1db8c5e3@gmail.com > > > --- > > > Prepared with Claude Code (Claude Opus 5.5) from measurements on the > > > laptop (usbmon captures) and analysis of the vendor's Windows softwar= e > > > for interoperability; I reviewed and tested it. > > > --- > > > MAINTAINERS | 1 + > > > drivers/hid/Kconfig | 12 ++ > > > drivers/hid/Makefile | 1 + > > > drivers/hid/hid-ids.h | 1 + > > > drivers/hid/hid-lenovo-legion.c | 331 ++++++++++++++++++++++++++++++= ++++++++++ > > > 5 files changed, 346 insertions(+) > > >=20 > > > diff --git a/MAINTAINERS b/MAINTAINERS > > > index ba7650cb86b0..6c622b50ac9b 100644 > > > --- a/MAINTAINERS > > > +++ b/MAINTAINERS > > > @@ -15187,6 +15187,7 @@ F:=09Documentation/ABI/testing/sysfs-driver-h= id-lenovo-go > > > F:=09Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s > > > F:=09drivers/hid/hid-lenovo-go-s.c > > > F:=09drivers/hid/hid-lenovo-go.c > > > +F:=09drivers/hid/hid-lenovo-legion.c > > > F:=09drivers/hid/hid-lenovo.c > > > =20 > > > LENOVO YOGA BOOK 9 KEYBOARD DOCK DRIVER > > > diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig > > > index 2481bc01c435..336be96dcd66 100644 > > > --- a/drivers/hid/Kconfig > > > +++ b/drivers/hid/Kconfig > > > @@ -652,6 +652,18 @@ config HID_LENOVO_GO_S > > > =09S. Say M here to compile this driver as a module. The module will= be called > > > =09hid-lenovo-go-s. > > > =20 > > > +config HID_LENOVO_LEGION > > > +=09tristate "Lenovo Legion laptop keyboard backlight" > > > +=09depends on USB_HID > > > +=09depends on LEDS_CLASS > > > +=09help > > > +=09Support for the LEDs of some Lenovo Legion laptops since 2025, wi= th > > > +=09the brightness changes initiated by predefined shortcuts (e.g., > > > +=09Fn+Up/Down) reported via brightness_hw_changed. > > > + > > > +=09Say M here to compile this driver as a module. The module will be= called > > > +=09hid-lenovo-legion. > > > + > > > config HID_LETSKETCH > > > =09tristate "Letsketch WP9620N tablets" > > > =09depends on USB_HID > > > diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile > > > index 43a8eb0f389b..713bb1c89861 100644 > > > --- a/drivers/hid/Makefile > > > +++ b/drivers/hid/Makefile > > > @@ -78,6 +78,7 @@ obj-$(CONFIG_HID_LCPOWER)=09+=3D hid-lcpower.o > > > obj-$(CONFIG_HID_LENOVO)=09+=3D hid-lenovo.o > > > obj-$(CONFIG_HID_LENOVO_GO)=09+=3D hid-lenovo-go.o > > > obj-$(CONFIG_HID_LENOVO_GO_S)=09+=3D hid-lenovo-go-s.o > > > +obj-$(CONFIG_HID_LENOVO_LEGION)=09+=3D hid-lenovo-legion.o > > > obj-$(CONFIG_HID_LETSKETCH)=09+=3D hid-letsketch.o > > > obj-$(CONFIG_HID_LOGITECH)=09+=3D hid-logitech.o > > > obj-$(CONFIG_HID_LOGITECH)=09+=3D hid-lg-g15.o > > > diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h > > > index 91319aa6516d..992b9b147e95 100644 > > > --- a/drivers/hid/hid-ids.h > > > +++ b/drivers/hid/hid-ids.h > > > @@ -773,6 +773,7 @@ > > > #define USB_DEVICE_ID_ITE_LENOVO_YOGA2 0x8350 > > > #define I2C_DEVICE_ID_ITE_LENOVO_LEGION_Y720=090x837a > > > #define USB_DEVICE_ID_ITE_LENOVO_YOGA900=090x8396 > > > +#define USB_DEVICE_ID_ITE_LENOVO_LEGION_GEN10_KBD=090xc197 > > > #define I2C_DEVICE_ID_ITE_LENOVO_YOGA_SLIM_7X_KEYBOARD=090x8987 > > > #define I2C_DEVICE_ID_ITE_LENOVO_YOGA_SLIM_7X_G11_KEYBOARD=090x83db > > > #define USB_DEVICE_ID_ITE8595=09=090x8595 > > > diff --git a/drivers/hid/hid-lenovo-legion.c b/drivers/hid/hid-lenovo= -legion.c > > > new file mode 100644 > > > index 000000000000..181fe6bc0f84 > > > --- /dev/null > > > +++ b/drivers/hid/hid-lenovo-legion.c > > > @@ -0,0 +1,331 @@ > > > +// SPDX-License-Identifier: GPL-2.0 > > > +/* > > > + * HID driver for the keyboard backlight of Lenovo Legion laptops. > > > + * > > > + * The ITE 8258 keyboard controller (048d:c197) is the built-in keyb= oard and > > > + * carries Lenovo's vendor lighting protocol on feature report 0x07 = (up to > > > + * 960 bytes): a request (struct legion_msg), answered by reading th= e report > > > + * back with a GET_FEATURE. Requests and answers may be shorter than= the > > > + * report; the answer is ready as soon as the request has been sent. > > > + * > > > + * The backlight brightness is op 0xCE (set) / 0xCD (get), 0..9, sto= red in the > > > + * controller; it applies to every LED of the machine (keys, front s= trip, rear > > > + * vents, lid logo). The firmware handles Fn+Up / Fn+Down itself and= reports > > > + * the new level on vendor input report 5 (struct legion_event). It = reports > > > + * every other set the same way, also the host's and unchanged level= s. > > > + * > > > + * Op 0xD1 reads 0 where this brightness drives the backlight. The L= egion > > > + * Y9000P IAX10 has the same controller ID, but a white backlight dr= iven by > > > + * ideapad-laptop, and reads 1: there the driver registers no LED. > > > + * > > > + * The colours are the controller's own effects. The LEDs can also b= e handed > > > + * to the HID LampArray of the "Lenovo Lighting" device (048d:c193),= which > > > + * this driver leaves to others. > > > + */ > > > + > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > + > > > +#include > > > + > > > +#include "hid-ids.h" > > > + > > > +#define LEGION_REPORT_ID=09=090x07 > > > + > > > +#define LEGION_OP_GET_BRIGHTNESS=090xcd > > > +#define LEGION_OP_SET_BRIGHTNESS=090xce > > > +#define LEGION_OP_GET_COMPATIBILITY=090xd1 > > > +#define LEGION_MAX_BRIGHTNESS=09=099 > > > + > > > +#define LEGION_EVENT_REPORT_ID=09=090x05 > > > +#define LEGION_EVENT_BRIGHTNESS=09=090x02=09/* set by the host, Fn+U= p, Fn+Space */ > > > +#define LEGION_EVENT_BRIGHTNESS_DOWN=090x03=09/* Fn+Down */ > > > + > > > +/* Request, and its answer: the value is params[0]. */ > > > +struct legion_msg { > > > +=09u8 report_id; > > > +=09u8 op; > > > +=09__le16 len;=09=09=09/* of params */ > >=20 > > You don't need the comment, but > >=20 > > > +=09u8 params[]; > >=20 > > =09u8 params[] __counted_by(len); > >=20 > > Hint: include compiler.h. This patch already depends on it because of, > > e.g., __packed. >=20 > Unfortunately that won't work because the member is __le16.=C2=A0 >=20 Ah, you're right. I overlooked the `__le16'. Sorry for the confusion. > Sadly=20 > __counted_by() cannot take expressions like __counted_by(le16_to_cpu(len)= )=20 > (AFAIK) so we cannot tell it to do the byte-swapping when hardening wants= =20 > to check length. Fortunately, __counted_by_le() and __counted_by_be() exist for exactly this reason, see commit ca7e324e8ad3 ("compiler_types: add Endianness- dependent __counted_by_{le,be}"). While they become no-op when endianness mismatches, annotating the struct with them could still increase test coverage and improve documentation. Ciro, please use __counted_by_le() here. >=20 > Another thing it cannot do is offsets like __counted_by(len + 2) which is= =20 > common in cases that include header size into the len. >=20 > Having an ability to do simple expressions like that would allow applying= =20 > __counted_by() naturally to much wider set of scenarios, with all=20 > hardening benefits it brings with it when hardening is compiled in. >=20 > I don't know if compiler people are aware of this major limitation or not= . I want these, too :-) Thanks, Rong