[PATCH v3] platform/x86: ideapad-laptop: Report camera switch as SW_CAMERA_LENS_COVER

Rong Zhang posted 1 patch 20 hours ago
drivers/platform/x86/lenovo/ideapad-laptop.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
[PATCH v3] platform/x86: ideapad-laptop: Report camera switch as SW_CAMERA_LENS_COVER
Posted by Rong Zhang 20 hours ago
On certain 2025 Lenovo laptops, such as the Yoga Pro 7 14ASP10 and Legion
Pro 7 16AFR10H, a switch on the side disables the camera. This is handled
by the firmware, which also sends event 0x0d (camera disabled) or 0x0c
(camera enabled) through the WMI event GUID handled with
ideapad_wmi_context_fn_keys. These events are currently reported as
KEY_UNKNOWN.

Other Lenovo laptops expose a similar camera switch through a separate WMI
GUID, which lenovo-wmi-camera reports as SW_CAMERA_LENS_COVER since
commit d98bf6a6ed61 ("platform/x86: lenovo-wmi-camera: Use
SW_CAMERA_LENS_COVER instead of KEY_CAMERA_ACESS"). That driver does not
bind on these laptops, so map the WMI events to SW_CAMERA_LENS_COVER as
well via sparse keymap KE_SW.

Unfortunately, there is no programmatic way to determine the current
state on the mentioned devices until the next relevant WMI key event.
Therefore, no switch event is emitted on probe or resume, intentionally
leaving the default (0, i.e., no covered) or the last state unchanged,
and let the first relevant WMI key event to correct it. This should
fulfill the requirement of using the switch events to show an OSD.
AFAIK, no userspace software queries its state via EVIOCGBIT(EV_SW).

The above behavior is basically the same as lenovo-wmi-camera, except
that SW_CAMERA_LENS_COVER is always exposed even on devices with no
camera switch. It's because, again, there is no programmatic way to
determine the switch's existence on the mentioned devices. Doing so
should be harmless as long as no switch event is emitted and eliminates
the need to dynamically register an additional input device at run time
like lenovo-wmi-camera does. Even if a userspace program does query the
switch's state via EVIOCGBIT(EV_SW), the returned state will always be 0
(not covered), which is the correct state on unsupported devices.

Co-developed-by: Marco Giunta <marco_giunta@outlook.it>
Signed-off-by: Marco Giunta <marco_giunta@outlook.it>
Tested-by: Marco Giunta <marco_giunta@outlook.it>
Signed-off-by: Rong Zhang <i@rong.moe>
---
Changes in v3:
- Take over the patch from Marco Giunta as discussed in
  https://msgid.link/SN6PR19MB2303278926469783FA99824CFC842@SN6PR19MB2303.namprd19.prod.outlook.com
- Map the relevant WMI key events via the ideapad_keymap instead of
  creating a dedicated input device at run time
- Remove Reviewed-by: Huang Wei <huangwei@kylinos.cn> as the methodology
  has changed, please review again
- Link to v2: https://patch.msgid.link/SN6PR19MB2303E25270E1A460ABC76EA3FC852@SN6PR19MB2303.namprd19.prod.outlook.com

Changes in v2:
- Add lockdep_assert_held(&ideapad_shared_mutex) and a comment at the top
  of ideapad_camera_switch_report() to document and check that the WMI
  notify path is serialized through ideapad_shared_mutex (suggested by
  Huang Wei)
- Replace dev_warn() with dev_warn_once() in
  ideapad_camera_switch_report() so that a persistent registration failure
  does not log a warning on every toggle (suggested by Huang Wei)
- Link to v1: https://patch.msgid.link/SN6PR19MB23039910DD1918BEE3825BAFFC862@SN6PR19MB2303.namprd19.prod.outlook.com
---
 drivers/platform/x86/lenovo/ideapad-laptop.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platform/x86/lenovo/ideapad-laptop.c
index 8213524504ee..3e91cc1df6c2 100644
--- a/drivers/platform/x86/lenovo/ideapad-laptop.c
+++ b/drivers/platform/x86/lenovo/ideapad-laptop.c
@@ -1365,6 +1365,18 @@ static const struct key_entry ideapad_keymap[] = {
 	{ KE_KEY,   0x29 | IDEAPAD_WMI_KEY, { KEY_TOUCHPAD_TOGGLE } },
 	{ KE_KEY,   0x2a | IDEAPAD_WMI_KEY, { KEY_ROOT_MENU } },
 
+	/*
+	 * WMI switches
+	 *
+	 * Some devices come with physical switches. Whenever a switch is
+	 * toggled, an WMI event is emitted to inform the software about the
+	 * switch's latest state.
+	 */
+
+	/* Camera switch */
+	{ KE_SW,	0x0c | IDEAPAD_WMI_KEY, .sw = { SW_CAMERA_LENS_COVER, 0 } },
+	{ KE_SW,	0x0d | IDEAPAD_WMI_KEY, .sw = { SW_CAMERA_LENS_COVER, 1 } },
+
 	{ KE_END },
 };
 

---
base-commit: fe2ec83746e501645709761605c2464a44fd2929
change-id: 8511c6da-ideapad-laptop-camera-sw-948e4653b20e

Thanks,
Rong
Re: [PATCH v3] platform/x86: ideapad-laptop: Report camera switch as SW_CAMERA_LENS_COVER
Posted by Huang Wei 5 hours ago
Hi Rong,

The v3 looks good - the KE_SW mapping is the right shape for this and
the entries match everything we worked through in the thread. Putting
them under a dedicated "WMI switches" section at the end of the
keymap is a nice touch, and it's good to see Marco's Tested-by
carried along with the handover.

Reviewed-by: Huang Wei <huangwei@kylinos.cn>

Thanks,
Huang Wei