Skip to contentSkip to conversation

platform/x86: thinkpad-acpi: Add support for new hotkey for camera shutter switch

PATCH Superseded Nitin Joshi 2 participants 5 messages Apr 23, 2025 – Apr 29, 2025 x86 platform drivers

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 platform/x86: thinkpad-acpi: Add support for new hotkey for camera shutter switch

New Lenovo Thinkpad models, e.g. the 'X9-14 Gen 1' and 'X9-15 Gen 1' has new shortcut on F9 key i.e to switch camera shutter and it send a new 0x131b hkey event when F9 key is pressed.

This commit adds support for new hkey 0x131b.

---
Changes in v3:
* Avoid wasteful get_camera_shutter() calls and Minor changes based on review comments to make code more readable.
Changes in v2:
* Added ASL method to get camera shutter status and send it to userspace.

---
 drivers/platform/x86/thinkpad_acpi.c | 46 +++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)
drivers/platform/x86/thinkpad_acpi.c +45 -1
index 5790095c175e..0b011dcfc626 100644
@@ -182,6 +182,7 @@ enum tpacpi_hkey_event_t {
 						   * directly in the sparse-keymap.
 						   */
 	TP_HKEY_EV_AMT_TOGGLE		= 0x131a, /* Toggle AMT on/off */
+	TP_HKEY_EV_CAMERASHUTTER_TOGGLE = 0x131b, /* Toggle Camera Shutter */
 	TP_HKEY_EV_DOUBLETAP_TOGGLE	= 0x131c, /* Toggle trackpoint doubletap on/off */
 	TP_HKEY_EV_PROFILE_TOGGLE	= 0x131f, /* Toggle platform profile in 2024 systems */
 	TP_HKEY_EV_PROFILE_TOGGLE2	= 0x1401, /* Toggle platform profile in 2025 + systems */
@@ -2250,6 +2251,25 @@ static void tpacpi_input_send_tabletsw(void)
 	}
 }
 
+#define GCES_METHOD_ERR BIT(31)
+
+static int get_camera_shutter(void)
+{
+	acpi_handle gces_handle;
+	int output;
+
+	if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "GCES", &gces_handle)))
+		return -ENODEV;
+
+	if (!acpi_evalf(gces_handle, &output, NULL, "dd", 0))
+		return -EIO;
+
+	if (output & GCES_METHOD_ERR)
+		return -ENODEV;
+
+	return output;
+}
+
 static bool tpacpi_input_send_key(const u32 hkey, bool *send_acpi_ev)
 {
 	bool known_ev;
@@ -3272,6 +3292,7 @@ static const struct key_entry keymap_lenovo[] __initconst = {
 	 * after switching to sparse keymap support. The mappings above use translated
 	 * scancodes to preserve uAPI compatibility, see tpacpi_input_send_key().
 	 */
+	{ KE_KEY, TP_HKEY_EV_CAMERASHUTTER_TOGGLE, { KEY_CAMERA_ACCESS_TOGGLE } },
 	{ KE_KEY, 0x131d, { KEY_VENDOR } }, /* System debug info, similar to old ThinkPad key */
 	{ KE_KEY, 0x1320, { KEY_LINK_PHONE } },
 	{ KE_KEY, TP_HKEY_EV_TRACK_DOUBLETAP /* 0x8036 */, { KEY_PROG4 } },
@@ -3303,7 +3324,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 	const struct key_entry *keymap;
 	bool radiosw_state  = false;
 	bool tabletsw_state = false;
-	int hkeyv, res, status;
+	int hkeyv, res, status, camera_shutter_state;
 
 	vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
 			"initializing hotkey subdriver\n");
@@ -3467,6 +3488,12 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 	if (res)
 		return res;
 
+	camera_shutter_state = get_camera_shutter();
+	if (camera_shutter_state >= 0) {
+		input_set_capability(tpacpi_inputdev, EV_SW, SW_CAMERA_LENS_COVER);
+		input_report_switch(tpacpi_inputdev, SW_CAMERA_LENS_COVER, camera_shutter_state);
+	}
+
 	if (tp_features.hotkey_wlsw) {
 		input_set_capability(tpacpi_inputdev, EV_SW, SW_RFKILL_ALL);
 		input_report_switch(tpacpi_inputdev,
@@ -3633,6 +3660,8 @@ static void adaptive_keyboard_s_quickview_row(void)
 /* 0x1000-0x1FFF: key presses */
 static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
 {
+	int camera_shutter_state;
+
 	/* Never send ACPI netlink events for original hotkeys (hkey: 0x1001 - 0x1020) */
 	if (hkey >= TP_HKEY_EV_ORIG_KEY_START && hkey <= TP_HKEY_EV_ORIG_KEY_END) {
 		*send_acpi_ev = false;
@@ -3643,6 +3672,21 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
 			return true;
 	}
 
+	if (hkey == TP_HKEY_EV_CAMERASHUTTER_TOGGLE) {
+		camera_shutter_state = get_camera_shutter();
+		if (camera_shutter_state < 0) {
+			pr_err("Error retrieving camera shutter state after shutter event\n");
+			return true;
+		}
+		mutex_lock(&tpacpi_inputdev_send_mutex);
+
+		input_report_switch(tpacpi_inputdev, SW_CAMERA_LENS_COVER, camera_shutter_state);
+		input_sync(tpacpi_inputdev);
+
+		mutex_unlock(&tpacpi_inputdev_send_mutex);
+		return true;
+	}
+
 	return tpacpi_input_send_key(hkey, send_acpi_ev);
 }
 
Signature · 1 line
2.43.0
#1 lore raw

Hi,

Quoted 31 lines · Nitin Joshi

New Lenovo Thinkpad models, e.g. the 'X9-14 Gen 1' and 'X9-15 Gen 1' has new shortcut on F9 key i.e to switch camera shutter and it send a new 0x131b hkey event when F9 key is pressed.

This commit adds support for new hkey 0x131b.

---
Changes in v3:
* Avoid wasteful get_camera_shutter() calls and Minor changes based on review comments to make code more readable.
Changes in v2:
* Added ASL method to get camera shutter status and send it to userspace.

---
 drivers/platform/x86/thinkpad_acpi.c | 46 +++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)
drivers/platform/x86/thinkpad_acpi.c +1 -0
index 5790095c175e..0b011dcfc626 100644
@@ -182,6 +182,7 @@ enum tpacpi_hkey_event_t {
 						   * directly in the sparse-keymap.
 						   */
 	TP_HKEY_EV_AMT_TOGGLE		= 0x131a, /* Toggle AMT on/off */
+	TP_HKEY_EV_CAMERASHUTTER_TOGGLE = 0x131b, /* Toggle Camera Shutter */
 	TP_HKEY_EV_DOUBLETAP_TOGGLE	= 0x131c, /* Toggle trackpoint doubletap on/off */
 	TP_HKEY_EV_PROFILE_TOGGLE	= 0x131f, /* Toggle platform profile in 2024 systems */
 	TP_HKEY_EV_PROFILE_TOGGLE2	= 0x1401, /* Toggle platform profile in 2025 + systems */

drivers/platform/x86/thinkpad_acpi.c static void tpacpi_input_send_tabletsw(void) · line 2254

Quoted 4 lines
drivers/platform/x86/thinkpad_acpi.c +1 -0
@@ -2250,6 +2251,25 @@ static void tpacpi_input_send_tabletsw(void)
 	}
 }
 
+#define GCES_METHOD_ERR BIT(31)

Does this bit really indicate an error ? From other vendors this often is a device-not-present bit and the bit being set would mean in this case that there is no camera-shutter on the laptop we're running on.

This also matches with the -ENODEV return.

If this indeed is a device-not-present bit then this define should be renamed to match that.

Quoted 71 lines
drivers/platform/x86/thinkpad_acpi.c +35 -1
+static int get_camera_shutter(void)
+{
+	acpi_handle gces_handle;
+	int output;
+
+	if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "GCES", &gces_handle)))
+		return -ENODEV;
+
+	if (!acpi_evalf(gces_handle, &output, NULL, "dd", 0))
+		return -EIO;
+
+	if (output & GCES_METHOD_ERR)
+		return -ENODEV;
+
+	return output;
+}
+
 static bool tpacpi_input_send_key(const u32 hkey, bool *send_acpi_ev)
 {
 	bool known_ev;
@@ -3272,6 +3292,7 @@ static const struct key_entry keymap_lenovo[] __initconst = {
 	 * after switching to sparse keymap support. The mappings above use translated
 	 * scancodes to preserve uAPI compatibility, see tpacpi_input_send_key().
 	 */
+	{ KE_KEY, TP_HKEY_EV_CAMERASHUTTER_TOGGLE, { KEY_CAMERA_ACCESS_TOGGLE } },
 	{ KE_KEY, 0x131d, { KEY_VENDOR } }, /* System debug info, similar to old ThinkPad key */
 	{ KE_KEY, 0x1320, { KEY_LINK_PHONE } },
 	{ KE_KEY, TP_HKEY_EV_TRACK_DOUBLETAP /* 0x8036 */, { KEY_PROG4 } },
@@ -3303,7 +3324,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 	const struct key_entry *keymap;
 	bool radiosw_state  = false;
 	bool tabletsw_state = false;
-	int hkeyv, res, status;
+	int hkeyv, res, status, camera_shutter_state;
 
 	vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
 			"initializing hotkey subdriver\n");
@@ -3467,6 +3488,12 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 	if (res)
 		return res;
 
+	camera_shutter_state = get_camera_shutter();
+	if (camera_shutter_state >= 0) {
+		input_set_capability(tpacpi_inputdev, EV_SW, SW_CAMERA_LENS_COVER);
+		input_report_switch(tpacpi_inputdev, SW_CAMERA_LENS_COVER, camera_shutter_state);
+	}
+
 	if (tp_features.hotkey_wlsw) {
 		input_set_capability(tpacpi_inputdev, EV_SW, SW_RFKILL_ALL);
 		input_report_switch(tpacpi_inputdev,
@@ -3633,6 +3660,8 @@ static void adaptive_keyboard_s_quickview_row(void)
 /* 0x1000-0x1FFF: key presses */
 static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
 {
+	int camera_shutter_state;
+
 	/* Never send ACPI netlink events for original hotkeys (hkey: 0x1001 - 0x1020) */
 	if (hkey >= TP_HKEY_EV_ORIG_KEY_START && hkey <= TP_HKEY_EV_ORIG_KEY_END) {
 		*send_acpi_ev = false;
@@ -3643,6 +3672,21 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
 			return true;
 	}
 
+	if (hkey == TP_HKEY_EV_CAMERASHUTTER_TOGGLE) {
+		camera_shutter_state = get_camera_shutter();
+		if (camera_shutter_state < 0) {
+			pr_err("Error retrieving camera shutter state after shutter event\n");
+			return true;
+		}
+		mutex_lock(&tpacpi_inputdev_send_mutex);
+

drivers/platform/x86/thinkpad_acpi.c static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev) · line 3692

Quoted 10 lines
drivers/platform/x86/thinkpad_acpi.c +7 -0
+		input_report_switch(tpacpi_inputdev, SW_CAMERA_LENS_COVER, camera_shutter_state);
+		input_sync(tpacpi_inputdev);
+
+		mutex_unlock(&tpacpi_inputdev_send_mutex);
+		return true;
+	}
+
 	return tpacpi_input_send_key(hkey, send_acpi_ev);
 }
 

Otherwise this looks good to me now.

Regards,

Hans

#2 lore raw

Hello Hans,

Quoted 44 lines · Hans de Goede

Hi,

Quoted 31 lines · Nitin Joshi

New Lenovo Thinkpad models, e.g. the 'X9-14 Gen 1' and 'X9-15 Gen 1' has new shortcut on F9 key i.e to switch camera shutter and it send a new 0x131b hkey event when F9 key is pressed.

This commit adds support for new hkey 0x131b.

---
Changes in v3:
* Avoid wasteful get_camera_shutter() calls and Minor changes based on review comments to make code more readable.
Changes in v2:
* Added ASL method to get camera shutter status and send it to userspace.

---
  drivers/platform/x86/thinkpad_acpi.c | 46 +++++++++++++++++++++++++++-
  1 file changed, 45 insertions(+), 1 deletion(-)
drivers/platform/x86/thinkpad_acpi.c +1 -0
index 5790095c175e..0b011dcfc626 100644
@@ -182,6 +182,7 @@ enum tpacpi_hkey_event_t {
  						   * directly in the sparse-keymap.
  						   */
  	TP_HKEY_EV_AMT_TOGGLE		= 0x131a, /* Toggle AMT on/off */
+	TP_HKEY_EV_CAMERASHUTTER_TOGGLE = 0x131b, /* Toggle Camera Shutter */
  	TP_HKEY_EV_DOUBLETAP_TOGGLE	= 0x131c, /* Toggle trackpoint doubletap on/off */
  	TP_HKEY_EV_PROFILE_TOGGLE	= 0x131f, /* Toggle platform profile in 2024 systems */
  	TP_HKEY_EV_PROFILE_TOGGLE2	= 0x1401, /* Toggle platform profile in 2025 + systems */

drivers/platform/x86/thinkpad_acpi.c static void tpacpi_input_send_tabletsw(void) · line 2254

Quoted 4 lines
drivers/platform/x86/thinkpad_acpi.c +1 -0
@@ -2250,6 +2251,25 @@ static void tpacpi_input_send_tabletsw(void)
  	}
  }
 
+#define GCES_METHOD_ERR BIT(31)

Does this bit really indicate an error ? From other vendors this often is a device-not-present bit and the bit being set would mean in this case that there is no camera-shutter on the laptop we're running on.

Quoted 4 lines

This also matches with the -ENODEV return.

If this indeed is a device-not-present bit then this define should be renamed to match that.

Yes, my understanding is also that this is device-not-present but let me double confirm it tomorrow. In spec, Bit 31 is shown as error status that's why i had mentioned it as error.
I will reuse METHOD_ERR, after confirming that its device-not-present and send updated patch tomorrow.

Quoted 86 lines
Quoted 73 lines
drivers/platform/x86/thinkpad_acpi.c +35 -1
+static int get_camera_shutter(void)
+{
+	acpi_handle gces_handle;
+	int output;
+
+	if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "GCES", &gces_handle)))
+		return -ENODEV;
+
+	if (!acpi_evalf(gces_handle, &output, NULL, "dd", 0))
+		return -EIO;
+
+	if (output & GCES_METHOD_ERR)
+		return -ENODEV;
+
+	return output;
+}
+
  static bool tpacpi_input_send_key(const u32 hkey, bool *send_acpi_ev)
  {
  	bool known_ev;
@@ -3272,6 +3292,7 @@ static const struct key_entry keymap_lenovo[] __initconst = {
  	 * after switching to sparse keymap support. The mappings above use translated
  	 * scancodes to preserve uAPI compatibility, see tpacpi_input_send_key().
  	 */
+	{ KE_KEY, TP_HKEY_EV_CAMERASHUTTER_TOGGLE, { KEY_CAMERA_ACCESS_TOGGLE } },
  	{ KE_KEY, 0x131d, { KEY_VENDOR } }, /* System debug info, similar to old ThinkPad key */
  	{ KE_KEY, 0x1320, { KEY_LINK_PHONE } },
  	{ KE_KEY, TP_HKEY_EV_TRACK_DOUBLETAP /* 0x8036 */, { KEY_PROG4 } },
@@ -3303,7 +3324,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
  	const struct key_entry *keymap;
  	bool radiosw_state  = false;
  	bool tabletsw_state = false;
-	int hkeyv, res, status;
+	int hkeyv, res, status, camera_shutter_state;
 
  	vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
  			"initializing hotkey subdriver\n");
@@ -3467,6 +3488,12 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
  	if (res)
  		return res;
 
+	camera_shutter_state = get_camera_shutter();
+	if (camera_shutter_state >= 0) {
+		input_set_capability(tpacpi_inputdev, EV_SW, SW_CAMERA_LENS_COVER);
+		input_report_switch(tpacpi_inputdev, SW_CAMERA_LENS_COVER, camera_shutter_state);
+	}
+
  	if (tp_features.hotkey_wlsw) {
  		input_set_capability(tpacpi_inputdev, EV_SW, SW_RFKILL_ALL);
  		input_report_switch(tpacpi_inputdev,
@@ -3633,6 +3660,8 @@ static void adaptive_keyboard_s_quickview_row(void)
  /* 0x1000-0x1FFF: key presses */
  static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
  {
+	int camera_shutter_state;
+
  	/* Never send ACPI netlink events for original hotkeys (hkey: 0x1001 - 0x1020) */
  	if (hkey >= TP_HKEY_EV_ORIG_KEY_START && hkey <= TP_HKEY_EV_ORIG_KEY_END) {
  		*send_acpi_ev = false;
@@ -3643,6 +3672,21 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
  			return true;
  	}
 
+	if (hkey == TP_HKEY_EV_CAMERASHUTTER_TOGGLE) {
+		camera_shutter_state = get_camera_shutter();
+		if (camera_shutter_state < 0) {
+			pr_err("Error retrieving camera shutter state after shutter event\n");
+			return true;
+		}
+		mutex_lock(&tpacpi_inputdev_send_mutex);
+

drivers/platform/x86/thinkpad_acpi.c static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev) · line 3692

Quoted 10 lines
drivers/platform/x86/thinkpad_acpi.c +7 -0
+		input_report_switch(tpacpi_inputdev, SW_CAMERA_LENS_COVER, camera_shutter_state);
+		input_sync(tpacpi_inputdev);
+
+		mutex_unlock(&tpacpi_inputdev_send_mutex);
+		return true;
+	}
+
  	return tpacpi_input_send_key(hkey, send_acpi_ev);
  }
 

Otherwise this looks good to me now.

Quoted 3 lines

Regards,

Hans

Thanks & Regards,
Nitin Joshi

Quoted 2 lines
#3 lore raw
In reply to Hans de Goede

Hello Hans,

Quoted 44 lines · Hans de Goede

Hi,

Quoted 31 lines · Nitin Joshi

New Lenovo Thinkpad models, e.g. the 'X9-14 Gen 1' and 'X9-15 Gen 1' has new shortcut on F9 key i.e to switch camera shutter and it send a new 0x131b hkey event when F9 key is pressed.

This commit adds support for new hkey 0x131b.

---
Changes in v3:
* Avoid wasteful get_camera_shutter() calls and Minor changes based on review comments to make code more readable.
Changes in v2:
* Added ASL method to get camera shutter status and send it to userspace.

---
  drivers/platform/x86/thinkpad_acpi.c | 46 +++++++++++++++++++++++++++-
  1 file changed, 45 insertions(+), 1 deletion(-)
drivers/platform/x86/thinkpad_acpi.c +1 -0
index 5790095c175e..0b011dcfc626 100644
@@ -182,6 +182,7 @@ enum tpacpi_hkey_event_t {
  						   * directly in the sparse-keymap.
  						   */
  	TP_HKEY_EV_AMT_TOGGLE		= 0x131a, /* Toggle AMT on/off */
+	TP_HKEY_EV_CAMERASHUTTER_TOGGLE = 0x131b, /* Toggle Camera Shutter */
  	TP_HKEY_EV_DOUBLETAP_TOGGLE	= 0x131c, /* Toggle trackpoint doubletap on/off */
  	TP_HKEY_EV_PROFILE_TOGGLE	= 0x131f, /* Toggle platform profile in 2024 systems */
  	TP_HKEY_EV_PROFILE_TOGGLE2	= 0x1401, /* Toggle platform profile in 2025 + systems */

drivers/platform/x86/thinkpad_acpi.c static void tpacpi_input_send_tabletsw(void) · line 2254

Quoted 4 lines
drivers/platform/x86/thinkpad_acpi.c +1 -0
@@ -2250,6 +2251,25 @@ static void tpacpi_input_send_tabletsw(void)
  	}
  }
 
+#define GCES_METHOD_ERR BIT(31)

Does this bit really indicate an error ? From other vendors this often is a device-not-present bit and the bit being set would mean in this case that there is no camera-shutter on the laptop we're running on.

Quoted 5 lines

This also matches with the -ENODEV return.

If this indeed is a device-not-present bit then this define should be renamed to match that.

This BIT being set would mean there is no camera shutter.
So, shall i change name to "#define DEVICE_NOT_PRESENT BIT(31)"
OR
I can just replace "METHOD_ERR" with "DEVICE_NOT_PRESENT" in below enum and replace all METHOD_ERR in this file to "DEVICE_NOT_PRESENT":

enum {
	/* Error condition bit */
	METHOD_ERR = BIT(31),
};

I may have missed something but I think for consistency, its better to rename METHOD_ERR. if its OK, i can modify like this in another patch for this change.

Quoted 85 lines
Quoted 72 lines
drivers/platform/x86/thinkpad_acpi.c +35 -1
+static int get_camera_shutter(void)
+{
+	acpi_handle gces_handle;
+	int output;
+
+	if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "GCES", &gces_handle)))
+		return -ENODEV;
+
+	if (!acpi_evalf(gces_handle, &output, NULL, "dd", 0))
+		return -EIO;
+
+	if (output & GCES_METHOD_ERR)
+		return -ENODEV;
+
+	return output;
+}
+
  static bool tpacpi_input_send_key(const u32 hkey, bool *send_acpi_ev)
  {
  	bool known_ev;
@@ -3272,6 +3292,7 @@ static const struct key_entry keymap_lenovo[] __initconst = {
  	 * after switching to sparse keymap support. The mappings above use translated
  	 * scancodes to preserve uAPI compatibility, see tpacpi_input_send_key().
  	 */
+	{ KE_KEY, TP_HKEY_EV_CAMERASHUTTER_TOGGLE, { KEY_CAMERA_ACCESS_TOGGLE } },
  	{ KE_KEY, 0x131d, { KEY_VENDOR } }, /* System debug info, similar to old ThinkPad key */
  	{ KE_KEY, 0x1320, { KEY_LINK_PHONE } },
  	{ KE_KEY, TP_HKEY_EV_TRACK_DOUBLETAP /* 0x8036 */, { KEY_PROG4 } },
@@ -3303,7 +3324,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
  	const struct key_entry *keymap;
  	bool radiosw_state  = false;
  	bool tabletsw_state = false;
-	int hkeyv, res, status;
+	int hkeyv, res, status, camera_shutter_state;
 
  	vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
  			"initializing hotkey subdriver\n");
@@ -3467,6 +3488,12 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
  	if (res)
  		return res;
 
+	camera_shutter_state = get_camera_shutter();
+	if (camera_shutter_state >= 0) {
+		input_set_capability(tpacpi_inputdev, EV_SW, SW_CAMERA_LENS_COVER);
+		input_report_switch(tpacpi_inputdev, SW_CAMERA_LENS_COVER, camera_shutter_state);
+	}
+
  	if (tp_features.hotkey_wlsw) {
  		input_set_capability(tpacpi_inputdev, EV_SW, SW_RFKILL_ALL);
  		input_report_switch(tpacpi_inputdev,
@@ -3633,6 +3660,8 @@ static void adaptive_keyboard_s_quickview_row(void)
  /* 0x1000-0x1FFF: key presses */
  static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
  {
+	int camera_shutter_state;
+
  	/* Never send ACPI netlink events for original hotkeys (hkey: 0x1001 - 0x1020) */
  	if (hkey >= TP_HKEY_EV_ORIG_KEY_START && hkey <= TP_HKEY_EV_ORIG_KEY_END) {
  		*send_acpi_ev = false;
@@ -3643,6 +3672,21 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
  			return true;
  	}
 
+	if (hkey == TP_HKEY_EV_CAMERASHUTTER_TOGGLE) {
+		camera_shutter_state = get_camera_shutter();
+		if (camera_shutter_state < 0) {
+			pr_err("Error retrieving camera shutter state after shutter event\n");
+			return true;
+		}
+		mutex_lock(&tpacpi_inputdev_send_mutex);
+

drivers/platform/x86/thinkpad_acpi.c static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev) · line 3692

Quoted 10 lines
drivers/platform/x86/thinkpad_acpi.c +7 -0
+		input_report_switch(tpacpi_inputdev, SW_CAMERA_LENS_COVER, camera_shutter_state);
+		input_sync(tpacpi_inputdev);
+
+		mutex_unlock(&tpacpi_inputdev_send_mutex);
+		return true;
+	}
+
  	return tpacpi_input_send_key(hkey, send_acpi_ev);
  }
 

Otherwise this looks good to me now.

Quoted 3 lines

Regards,

Hans

Thanks & Regards,
Nitin Joshi

Quoted 2 lines
#4 lore raw

Hello Hans, Ilpo,

Quoted 61 lines · Nitin Joshi

Hello Hans,

Quoted 44 lines · Hans de Goede

Hi,

Quoted 32 lines · Nitin Joshi

New Lenovo Thinkpad models, e.g. the 'X9-14 Gen 1' and 'X9-15 Gen 1' has new shortcut on F9 key i.e to switch camera shutter and it send a new 0x131b hkey event when F9 key is pressed.

This commit adds support for new hkey 0x131b.

---
Changes in v3:
* Avoid wasteful get_camera_shutter() calls and Minor changes based on review comments to make code more readable.
Changes in v2:
* Added ASL method to get camera shutter status and send it to userspace.
---
  drivers/platform/x86/thinkpad_acpi.c | 46 +++++++++++++++++++++++++++-

  1 file changed, 45 insertions(+), 1 deletion(-)
drivers/platform/x86/thinkpad_acpi.c +0 -0
index 5790095c175e..0b011dcfc626 100644
@@ -182,6 +182,7 @@ enum tpacpi_hkey_event_t {
                              * directly in the sparse-keymap.
                              */

      TP_HKEY_EV_AMT_TOGGLE        = 0x131a, /* Toggle AMT on/off */
+    TP_HKEY_EV_CAMERASHUTTER_TOGGLE = 0x131b, /* Toggle Camera
Shutter */
      TP_HKEY_EV_DOUBLETAP_TOGGLE    = 0x131c, /* Toggle trackpoint doubletap on/off */ TP_HKEY_EV_PROFILE_TOGGLE    = 0x131f, /* Toggle platform profile in 2024 systems */ TP_HKEY_EV_PROFILE_TOGGLE2    = 0x1401, /* Toggle platform profile in 2025 + systems */

drivers/platform/x86/thinkpad_acpi.c static void tpacpi_input_send_tabletsw(void) · line 2253

Quoted 3 lines
drivers/platform/x86/thinkpad_acpi.c +1 -0
@@ -2250,6 +2251,25 @@ static void tpacpi_input_send_tabletsw(void)
       }
   }
+#define GCES_METHOD_ERR BIT(31)

Does this bit really indicate an error ? From other vendors this often is a device-not-present bit and the bit being set would mean in this case that there is no camera-shutter on the laptop we're running on.

Quoted 5 lines

This also matches with the -ENODEV return.

If this indeed is a device-not-present bit then this define should be renamed to match that.

This BIT being set would mean there is no camera shutter.
So, shall i change name to "#define DEVICE_NOT_PRESENT BIT(31)"
OR
I can just replace "METHOD_ERR" with "DEVICE_NOT_PRESENT" in below enum and replace all METHOD_ERR in this file to "DEVICE_NOT_PRESENT":
enum {
    /* Error condition bit */
    METHOD_ERR = BIT(31),
};

Quoted 2 lines

I may have missed something but I think for consistency, its better to rename METHOD_ERR. if its OK, i can modify like this in another patch for this change.

Sorry to bother you !
Please let me know your comments regarding any modification needed for this patch? Thank you !

Thanks & Regards,
Nitin Joshi

Quoted 100 lines
Quoted 92 lines
Quoted 88 lines
drivers/platform/x86/thinkpad_acpi.c +18 -0
+static int get_camera_shutter(void)
+{
+    acpi_handle gces_handle;
+    int output;
+
+    if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "GCES", 
 &gces_handle)))
+        return -ENODEV;
+
+    if (!acpi_evalf(gces_handle, &output, NULL, "dd", 0))
+        return -EIO;
+
+    if (output & GCES_METHOD_ERR)
+        return -ENODEV;
+
+    return output;
+}
+
   static bool tpacpi_input_send_key(const u32 hkey, bool *send_acpi_ev)
   {
       bool known_ev;
@@ -3272,6 +3292,7 @@ static const struct key_entry keymap_lenovo[] 
 __initconst = {
        * after switching to sparse keymap support. The mappings above use translated
        * scancodes to preserve uAPI compatibility, see tpacpi_input_send_key().
        */
+    { KE_KEY, TP_HKEY_EV_CAMERASHUTTER_TOGGLE, 
 { KEY_CAMERA_ACCESS_TOGGLE } },

      { KE_KEY, 0x131d, { KEY_VENDOR } }, /* System debug info, similar to old ThinkPad key */ { KE_KEY, 0x1320, { KEY_LINK_PHONE } },
      { KE_KEY, TP_HKEY_EV_TRACK_DOUBLETAP /* 0x8036 */, { KEY_PROG4 } },

drivers/platform/x86/thinkpad_acpi.c +7 -1
@@ -3303,7 +3324,7 @@ static int __init hotkey_init(struct 
 ibm_init_struct *iibm)
       const struct key_entry *keymap;
       bool radiosw_state  = false;
       bool tabletsw_state = false;
-    int hkeyv, res, status;
+    int hkeyv, res, status, camera_shutter_state;
       vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
               "initializing hotkey subdriver\n");
@@ -3467,6 +3488,12 @@ static int __init hotkey_init(struct 
 ibm_init_struct *iibm)
       if (res)
           return res;
+    camera_shutter_state = get_camera_shutter();
+    if (camera_shutter_state >= 0) {
+        input_set_capability(tpacpi_inputdev, EV_SW, 
 SW_CAMERA_LENS_COVER);
+        input_report_switch(tpacpi_inputdev, SW_CAMERA_LENS_COVER, 
 camera_shutter_state);
+    }
+
       if (tp_features.hotkey_wlsw) {

          input_set_capability(tpacpi_inputdev, EV_SW, SW_RFKILL_ALL); input_report_switch(tpacpi_inputdev,

drivers/platform/x86/thinkpad_acpi.c +2 -0
@@ -3633,6 +3660,8 @@ static void 
 adaptive_keyboard_s_quickview_row(void)
   /* 0x1000-0x1FFF: key presses */
   static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
   {
+    int camera_shutter_state;
+
       /* Never send ACPI netlink events for original hotkeys (hkey: 0x1001 - 0x1020) */
       if (hkey >= TP_HKEY_EV_ORIG_KEY_START && hkey <= TP_HKEY_EV_ORIG_KEY_END) {

          *send_acpi_ev = false;

drivers/platform/x86/thinkpad_acpi.c +15 -0
@@ -3643,6 +3672,21 @@ static bool hotkey_notify_hotkey(const u32 
 hkey, bool *send_acpi_ev)
               return true;
       }
+    if (hkey == TP_HKEY_EV_CAMERASHUTTER_TOGGLE) {
+        camera_shutter_state = get_camera_shutter();
+        if (camera_shutter_state < 0) {
+            pr_err("Error retrieving camera shutter state after 
 shutter event\n");
+            return true;
+        }
+        mutex_lock(&tpacpi_inputdev_send_mutex);
+
+        input_report_switch(tpacpi_inputdev, SW_CAMERA_LENS_COVER, 
 camera_shutter_state);
+        input_sync(tpacpi_inputdev);
+
+        mutex_unlock(&tpacpi_inputdev_send_mutex);
+        return true;
+    }
+
       return tpacpi_input_send_key(hkey, send_acpi_ev);
Quoted 1 line

  }

Otherwise this looks good to me now.

Quoted 3 lines

Regards,

Hans

Thanks & Regards,
Nitin Joshi

Quoted 2 lines