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.180.112 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795891770; b=N5KWQ6YfwlrdxPkX658enjLuZoi7m/jjSU0tcP9lOR0WaXFa+ejP5RPnBp133MGstsDm Ie1o29RdZrOicuOU4HkaFrdqi87/o1qnB81ly+WxpE0M/KkUSJCsFIWdBuBa6cMtoLFvG MhGJSm52VJ3bNKR/fSXB8Plgd/2VdyJ9STDgYUWfDhMnWUTD3wYnRHSRSfJcC6yeaygGS 3oIum5YwfYSxwOTwdElbXcmj0VlmZKnis6Nc8s4RWqDOGS8qE2A/8bxmeTbnv34HGc6dY amyxCJLq8rg419yBAcG3pLnTraRLow4VFlKOPdiQyLQjGy9DDsQx1cLyC3sW3U58xNQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795891770; 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=MZ7Dqb3EN4Xu8C1KgQ5PaReNQzvpRQAmdeBdAR6lPWo=; b=2d9/mwRIV8eYV0ArgYDwFT0pugqXM34X3T1GhN4Y1yWHGZ+vLhK77/Joznb2eFT4GDSl VQ4ithxSHKBSeL85OYyiyYw+501hXwulWW7hc1bk69nCOj58E8tiU7cFvozOh+5ha6x9v ISFueMZWJntOXVLgMx4hjQabW7H4OBwIseVuxaF3jWTrUeR2Y6zG/3QoGwdNWJ1TTAVkf x0Vzq+domNUL7pbmuO0hD2NOw6uqEPryOD37wCBEbmTirdhK/tuLt00nYdekVUqTwoIWt nE40tttIuG6KATP/gwk/iVG1NG9SVDlhs0vceIXcNmGlLC/SJCvqRTa+mU77ntp+Zhw== 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=MYOHKJG+; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.112 Received: from sender6-pp-f112.zoho.com (sender6-pp-f112.zoho.com [165.173.180.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 60FB8606A31C; Sat, 28 Nov 2026 18:49:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 60FB8606A31C 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=MYOHKJG+ ARC-Seal: i=1; a=rsa-sha256; t=1795891739; cv=none; d=zohomail.com; s=zohoarc; b=SNLmKckoubqpSPlGZn+QrroiMVxk8D3aNglB8qBripYQJwkDs3D/Wda9eIItj7BAPHFOT0AbNMJl3pnMxmRgOpruAhLZMa1J4UGoGlwML87fx0rYJGdMkqmFl0fMiSksyH3J8YgsaepJhJzt9NnFVwOxQ/A0YfRHDhhDhPFF1gs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795891739; 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=MZ7Dqb3EN4Xu8C1KgQ5PaReNQzvpRQAmdeBdAR6lPWo=; b=IJ6QXmJbIBqY/adz9W4+zzWF7m60IydlgYIBpLR25jNHH85DnmPMeF06liJib8Nt9WVrvPUGVHEnwsuUH+/XNocNIAsrCO1ccIWANX6XD+RXEmlTH5ypPuTa7Zdvj+9NGOwd6CGHJc7i0MJflspSU8LQjK7wZqqcWBVjRrxp+Oo= 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=MYOHKJG+4KjNcCi/j9fQOm1Zf0wKP6LOphMTr5sfrfddcF+JGsWGrXCCWo1NEqHwgLh1W/gjCmPWWw9RITdvR7IoWgbsdjSWPPgLTo5mQB4GW7IbGOzpzkaG83N3jvALYzsKbDGUbmfkH7jEasBPioXfpeSFbtn3NHlUptttj6WqjjAvXUPF+laiW0z2vAy6Df8puE7aNcFcx7zTRQLNQ5f/WbTAOHiaItrFyAosyhPqqiaCbe1IbAQQuhUfISUjrY8OwumrJkbuUDQVMZbgC7Uoh9i1IWa1CjXAR6P8u+BCytgCAJ0Mc6c2oYo1YT/zgNNC46H9vCuItt9UqcbJ+A==; c=relaxed/relaxed; s=zmail2048; d=rong.moe; v=1; bh=MZ7Dqb3EN4Xu8C1KgQ5PaReNQzvpRQAmdeBdAR6lPWo=; 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 1795891736799977.8490057594747; Sat, 28 Nov 2026 10:48:56 -0800 (PST) Message-ID: Subject: Re: [PATCH v3 0/2] Keyboard backlight for the Lenovo Legion Pro 7 Gen 10 From: Rong Zhang To: Marco Giunta , devnull+ciro.pedrini.gmail.com@kernel.org Cc: aer@tuxedocomputers.com, bentiss@kernel.org, ciro.pedrini@gmail.com, dcemin@nvidia.com, derekjohn.clark@gmail.com, hansg@kernel.org, ikepanhc@gmail.com, ilpo.jarvinen@linux.intel.com, jikos@kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, mpearson-lenovo@squebb.ca, platform-driver-x86@vger.kernel.org, wse@tuxedocomputers.com In-Reply-To: References: <20261127-legion-lighting-rfc-v3-0-15c55d9f15b7@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Nov 2026 02:43:48 +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 Macro, Thanks for your detailed information. On Sat, 2026-11-28 at 18:46 +0100, Marco Giunta wrote: > Hi all, >=20 > Ciro, thank you for this series. Some time ago I started working on > the exact same driver, but never really had the time to polish it and > submit it. Now that you did, I can happily and lazily skip this effort. >=20 > I have some high-level comments on the series. For reference, my laptop i= s > the Legion Pro 7 16AFR10H, which is the AMD variant of the 16IAX10H. >=20 > Apologies for not sending this earlier, I missed v1 and v2. > I see that in v3 you already fixed e.g. ignoring the spurious "brightness > up" event reported after OS/fn+up/fn+space-induced state changes or > removing the unnecessary sleep, but there are still some missing things. >=20 > 1. More WMI event codes to be ignored > -------------------------------------------------------------------------= - > (This part is for both Ciro and David, since Rong suggested moving patch = 1 > into David's series.) >=20 > On my laptop, the WMI codes emitted when pressing fn+space or fn+up/down > encode the new state, not just "state changed": there are 6 codes for the > RGB presets and 4 for the brightness levels. Here is the code I had > written in my draft series: >=20 > =09/* > =09 * Legion keyboard backlight level, Fn+Up/Down (handled by the firmwar= e, > =09 * changes reported by hid-lenovo-legion) > =09 */ > =09{ KE_IGNORE,=090x18 | IDEAPAD_WMI_KEY },=09/* off */ > =09{ KE_IGNORE,=090x19 | IDEAPAD_WMI_KEY },=09/* low */ > =09{ KE_IGNORE,=090x1a | IDEAPAD_WMI_KEY },=09/* medium */ > =09{ KE_IGNORE,=090x26 | IDEAPAD_WMI_KEY },=09/* high */ > =09/* Legion keyboard lighting preset, Fn+Space (handled by the firmware)= */ > =09{ KE_IGNORE,=090x20 | IDEAPAD_WMI_KEY },=09/* preset 1 */ > =09{ KE_IGNORE,=090x21 | IDEAPAD_WMI_KEY },=09/* preset 2 */ > =09{ KE_IGNORE,=090x22 | IDEAPAD_WMI_KEY },=09/* preset 3 */ > =09{ KE_IGNORE,=090x23 | IDEAPAD_WMI_KEY },=09/* preset 4 */ > =09{ KE_IGNORE,=090x24 | IDEAPAD_WMI_KEY },=09/* preset 5 */ > =09{ KE_IGNORE,=090x25 | IDEAPAD_WMI_KEY },=09/* preset 6 */ >=20 > Ciro: > The three codes in your patch 1 (0x21 for fn+space, 0x1a for fn+up, 0x19 > for fn+down) are exactly my "preset 2", "medium" and "low". Of course the > Intel and AMD models' firmwares may simply differ here, but it could also > be that your laptop behaves like mine and each key press you tested > happened to land on those states. > Could you check by cycling through *all* brightness levels and presets > with evtest? If so, the other seven codes still reach userspace as > KEY_UNKNOWN on your machine as well with the current patch 1. >=20 > My guess is that the two laptops behave identically, since it would be > unusual for these WMI codes not to be Lenovo-wide constants, especially o= n > two closely related models, but this is just a guess on my end. Maybe > Rong or Mark have some insight on this. >=20 > Regardless of the exact meaning on any particular model, the firmware > handles these keys and the HID driver reports the brightness changes, so > none of these WMI events are needed and all ten should be KE_IGNORE'd. > This is the only relevant (and actionable) point I'm trying to make in > this section. >=20 > Whichever version of patch 1 carries all ten codes, in this series or in > David's, will get my Reviewed-by tag. >=20 > 2. 0xd1 compatibility check on other Legion models > -------------------------------------------------------------------------= - > On my Legion, and I would assume yours as well, the KBLC ACPI method is > present in firmware but it's a stub: trying to do anything with it fails, > and ideapad-laptop says: >=20 > ideapad_acpi VPC2004:00: Unknown keyboard type: 1 >=20 > without registering any platform::kbd_backlight LED cdev. >=20 > This makes sense, given that the backlight is actually driven by the USB > keyboard controller. However, the opposite happens on the Legion Y9000P > IAX10, which is the China-exclusive version of the 16IAX10H and has the > same keyboard controller with the same USB ID. A tester of mine kindly ra= n > some tests on that laptop; here's the summary: >=20 > * The IAX10 only has a white backlight, similarly to most Yogas. > * Consistently with the above, that device uses the KBLC method: the > platform::kbd_backlight LED is already registered and functional > (tested with upower on an unpatched kernel). Regarding the hardware, > the keyboard's brightness is changed with the Yoga-like fn+space combo, > while fn+up/down does nothing. > * On the HID side, GET_BRIGHTNESS always returns 9 regardless of the > actual level, and the controller sends no report 5 on fn+space or on > brightness changes through platform::kbd_backlight. >=20 > Also note that your 16IAX10H and the tester's Y9000P report the same BIOS > version, Q7CN77WW (on top of the same 83F5 DMI), so neither the USB ID no= r > DMI/BIOS matching can tell these machines apart. For reference, Lenovo's > BIOS changelogs, e.g. the latest one: > https://download.lenovo.com/consumer/mobiles/q7cn83ww.txt > officially confirm that the same BIOS image is shared between the Legion > Pro 7 16IAX10H, the Legion Y9000P IAX10H and the Legion Y9000P IAX10. >=20 > So if the driver binds based on the USB ID alone, it will register a > second, broken kbd_backlight LED on devices that already have a > functioning one. >=20 > Fortunately, there seems to be a programmatic way of telling these cases > apart. This project: > https://github.com/LenovoLegionToolkit-Team/LenovoLegionToolkit/ > is a GPLv3 Windows app aiming to replace the proprietary Lenovo apps, and > includes a complete reverse engineering of the keyboard's HID protocol. >=20 > Here is a userspace Linux/Python port of the above targeting exclusively > the RGB functionality: > https://github.com/alstergee/legion-spectrum-control/ >=20 > One opcode reported in these repos that your driver doesn't use is 0xd1, > which is called "compatibility". I have checked that on my 16AFR10H it > returns 0, while on my tester's Y9000P it returns 1, so indeed it seems > like the right tool for the job. Could you confirm that it returns 0 > on your 16IAX10H too, before relying on it? >=20 > Overall, my suggestion would be to add a small helper, something like > legion_is_compatible(), that returns whether the response to 0xd1 is zero= ; > alternatively, something like legion_check_compatibility() that returns > -ENODEV on failure (I personally prefer the simpler version, but I'll > leave such details to Rong and Ilpo).=C2=A0 ACK. > Either way, I suggest using this > helper in probe to conditionally skip the LED registration on incompatibl= e > models, while still keeping the keyboard itself working. >=20 > 3. Legion Pro 5 Gen 10 models with ID 0xc195 > -------------------------------------------------------------------------= - > This part isn't directed at anyone in this thread specifically. > In some open issues in the second GitHub repo I linked, people report > trying these HID commands in userspace on Legion Pro 5 Gen 10 models (als= o > from 2025), whose keyboard controllers have ID 0xc195 instead of 0xc197. > Brightness and whole-keyboard colour reportedly work, while per-key > colours light up the wrong keys (which doesn't matter for this driver, > since it only handles the brightness for now). >=20 > So, if any owner of a Pro 5 Gen 10 model is reading this, please consider > testing the driver on your device with 0xc195 added to the legion_devices > table. (I wouldn't recommend adding the ID to the patch without direct > confirmation.) >=20 > 4. Some notes on patch 2 > -------------------------------------------------------------------------= - > I haven't had time to review the code in detail, but a few things stood > out while skimming through this thread and the past ones: >=20 > * I gave v3 a quick try on my 16AFR10H (on 7.3.6 + Fedora 45 KDE, with > devm_kzalloc_obj() replaced by devm_kzalloc() since the former is only > available from 7.4). Everything works as expected based on a 5-minute > test, including the short reports, suspend/resume (the level is kept > and the hotkeys still update the OSD afterwards) and reboots (the level > is kept from GRUB onwards, and KDE's slider picks it up). > Also, exposing the raw 0-9 range turns out to be a good choice: in my > draft I had limited it to the 0/3/6/9 steps used by fn+up/down, but on > my laptop the intermediate levels are all visibly different, so KDE's > slider gives finer control than the hotkeys do. I didn't know the > keyboard had these "hidden" intermediate levels, so thanks for that. > BTW, mixing software and hardware controls works as well: starting > from an intermediate level (i.e. not a multiple of 3), fn+up and > fn+down snap to the nearest multiple of 3 in that direction (e.g. > 1 + fn+up -> 3, 4 + fn+down -> 3), and KDE's OSD follows on screen. > So if this were the final revision I'd give my Tested-by, but I'll > save that for a later one. > * Separately from Rong's question about the function part of the name, > "legion::kbd_backlight" uses a vendor/product name as the devicename, > which Documentation/leds/leds-class.rst describes as deprecated; > ":kbd_backlight" is the documented form, and my suggestion going > forward. > * About Rong's suggestion to serialize legion_brightness_{set,get}() and > legion_raw_event() with kbd->lock: if I'm not mistaken, kbd->lock is > a mutex and raw_event runs in interrupt context, so it can't be taken > there. Indeed. I missed that. legion_raw_event() doesn't need to be serialized. > In my draft I kept a mutex in set/get around the whole SET/GET exchange > (with a lockdep assertion in the command helper), plus a spinlock > protecting only the cached level, which set() and raw_event both read > and write. Unlike your v1 spinlock, which only guarded the redundant > "ready" flag, this one protects the current brightness state, which is > shared with raw_event. IMO, using the additional spinlock is equivalent to: legion_brightness_set() { =09guard(mutex)(); =20 =09old =3D xchg(&cached, new); =09ret =3D legion_simple_command(); =09if (ret) =09=09cmpxchg(&cached, old, new); } =20 legion_brightness_get() { =09guard(mutex)(); =20 =09legion_simple_command(); =20 =09/* With the mutex, there is no need to update the cache brightness. *= / } =20 legion_raw_event() { =09old =3D xchg(&cached, new); =09if (old =3D=3D new) =09=09return; } Thanks, Marco > That said, most of my experience is in the sound tree, so I'm not 100% > sure this is the best (or even a correct) approach, and I'll gladly > defer to Rong on the details. >=20 > 5. In conclusion... > -------------------------------------------------------------------------= - > Ciro, I'm sure Rong, Ilpo and Mark will offer much more useful and timely > commentary on the code than I could, so please don't wait for another mai= l > from me before sending v4. And when you do, please CC me so I can provide > my Tested-by and Reviewed-by tags ASAP. Again, I'm quite busy at the > moment, so I can't give an in-depth review for now, but I'll gladly do > one later if possible. >=20 > Thanks again for working on this. >=20 > Best regards, > Marco