* [PATCH v2] platform/x86: thinkpad-acpi: Add support for new hotkey for camera shutter switch
@ 2025-04-23 5:51 Nitin Joshi
2025-04-23 9:42 ` Ilpo Järvinen
2025-04-23 12:57 ` Hans de Goede
0 siblings, 2 replies; 5+ messages in thread
From: Nitin Joshi @ 2025-04-23 5:51 UTC (permalink / raw)
To: ilpo.jarvinen, hdegoede
Cc: platform-driver-x86, ibm-acpi-devel, njoshi1, Nitin Joshi,
Mark Pearson
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.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Nitin Joshi <nitjoshi@gmail.com>
---
Changes in v2:
* Added ASL method to get camera shutter status and send it to userspace.
---
drivers/platform/x86/thinkpad_acpi.c | 43 +++++++++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 5790095c175e..80b02e8538e8 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -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)
}
}
+static int get_camera_shutter(void)
+{
+ acpi_handle gces_handle;
+ int output;
+
+ if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "GCES", &gces_handle))) {
+ /* Platform doesn't support GCES */
+ return -ENODEV;
+ }
+
+ if (!acpi_evalf(gces_handle, &output, NULL, "dd", 0))
+ return -EIO;
+
+ if (output & BIT(31))
+ 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,13 @@ 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 +3661,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 +3673,17 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
return true;
}
+ camera_shutter_state = get_camera_shutter();
+ if (hkey == TP_HKEY_EV_CAMERASHUTTER_TOGGLE && (camera_shutter_state >= 0)) {
+ 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 tpacpi_input_send_key(hkey, send_acpi_ev);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2] platform/x86: thinkpad-acpi: Add support for new hotkey for camera shutter switch
2025-04-23 5:51 [PATCH v2] platform/x86: thinkpad-acpi: Add support for new hotkey for camera shutter switch Nitin Joshi
@ 2025-04-23 9:42 ` Ilpo Järvinen
2025-04-23 12:29 ` Nitin Joshi
2025-04-23 12:57 ` Hans de Goede
1 sibling, 1 reply; 5+ messages in thread
From: Ilpo Järvinen @ 2025-04-23 9:42 UTC (permalink / raw)
To: Nitin Joshi
Cc: Hans de Goede, platform-driver-x86, ibm-acpi-devel, njoshi1,
Mark Pearson
On Wed, 23 Apr 2025, Nitin Joshi wrote:
> 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.
>
> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Signed-off-by: Nitin Joshi <nitjoshi@gmail.com>
> ---
> Changes in v2:
>
> * Added ASL method to get camera shutter status and send it to userspace.
> ---
> drivers/platform/x86/thinkpad_acpi.c | 43 +++++++++++++++++++++++++++-
> 1 file changed, 42 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
> index 5790095c175e..80b02e8538e8 100644
> --- a/drivers/platform/x86/thinkpad_acpi.c
> +++ b/drivers/platform/x86/thinkpad_acpi.c
> @@ -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)
> }
> }
>
> +static int get_camera_shutter(void)
> +{
> + acpi_handle gces_handle;
> + int output;
> +
> + if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "GCES", &gces_handle))) {
> + /* Platform doesn't support GCES */
Drop this as it's unnecessary/very obvious.
> + return -ENODEV;
> + }
> +
> + if (!acpi_evalf(gces_handle, &output, NULL, "dd", 0))
> + return -EIO;
> +
> + if (output & BIT(31))
Please use a named define instead of using BIT(31) directly as it improves
code readability a lot.
> + 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,13 @@ 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);
The second parameter fits on the previous line.
> + }
> +
> if (tp_features.hotkey_wlsw) {
> input_set_capability(tpacpi_inputdev, EV_SW, SW_RFKILL_ALL);
> input_report_switch(tpacpi_inputdev,
> @@ -3633,6 +3661,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 +3673,17 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
> return true;
> }
>
> + camera_shutter_state = get_camera_shutter();
> + if (hkey == TP_HKEY_EV_CAMERASHUTTER_TOGGLE && (camera_shutter_state >= 0)) {
> + 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 tpacpi_input_send_key(hkey, send_acpi_ev);
> }
>
>
--
i.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] platform/x86: thinkpad-acpi: Add support for new hotkey for camera shutter switch
2025-04-23 9:42 ` Ilpo Järvinen
@ 2025-04-23 12:29 ` Nitin Joshi
0 siblings, 0 replies; 5+ messages in thread
From: Nitin Joshi @ 2025-04-23 12:29 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Hans de Goede, platform-driver-x86, ibm-acpi-devel, njoshi1,
Mark Pearson
Hello Ilpo,
Thanks for review.
On 4/23/25 18:42, Ilpo Järvinen wrote:
> On Wed, 23 Apr 2025, Nitin Joshi wrote:
>
>> 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.
>>
>> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> Signed-off-by: Nitin Joshi <nitjoshi@gmail.com>
>> ---
>> Changes in v2:
>>
>> * Added ASL method to get camera shutter status and send it to userspace.
>> ---
>> drivers/platform/x86/thinkpad_acpi.c | 43 +++++++++++++++++++++++++++-
>> 1 file changed, 42 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
>> index 5790095c175e..80b02e8538e8 100644
>> --- a/drivers/platform/x86/thinkpad_acpi.c
>> +++ b/drivers/platform/x86/thinkpad_acpi.c
>> @@ -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)
>> }
>> }
>>
>> +static int get_camera_shutter(void)
>> +{
>> + acpi_handle gces_handle;
>> + int output;
>> +
>> + if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "GCES", &gces_handle))) {
>> + /* Platform doesn't support GCES */
>
> Drop this as it's unnecessary/very obvious.
Ack , I will remove it.
>
>> + return -ENODEV;
>> + }
>> +
>> + if (!acpi_evalf(gces_handle, &output, NULL, "dd", 0))
>> + return -EIO;
>> +
>> + if (output & BIT(31))
>
> Please use a named define instead of using BIT(31) directly as it improves
> code readability a lot.
Ack, I will use named define GCES_METHOD_ERR instead of BIT(31).
>
>> + 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,13 @@ 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);
>
> The second parameter fits on the previous line.
Ack , I will modify it .
Thanks & Regards,
Nitin Joshi
>
>> + }
>> +
>> if (tp_features.hotkey_wlsw) {
>> input_set_capability(tpacpi_inputdev, EV_SW, SW_RFKILL_ALL);
>> input_report_switch(tpacpi_inputdev,
>> @@ -3633,6 +3661,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 +3673,17 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
>> return true;
>> }
>>
>> + camera_shutter_state = get_camera_shutter();
>> + if (hkey == TP_HKEY_EV_CAMERASHUTTER_TOGGLE && (camera_shutter_state >= 0)) {
>> + 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 tpacpi_input_send_key(hkey, send_acpi_ev);
>> }
>>
>>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] platform/x86: thinkpad-acpi: Add support for new hotkey for camera shutter switch
2025-04-23 5:51 [PATCH v2] platform/x86: thinkpad-acpi: Add support for new hotkey for camera shutter switch Nitin Joshi
2025-04-23 9:42 ` Ilpo Järvinen
@ 2025-04-23 12:57 ` Hans de Goede
2025-04-23 13:19 ` Nitin Joshi
1 sibling, 1 reply; 5+ messages in thread
From: Hans de Goede @ 2025-04-23 12:57 UTC (permalink / raw)
To: Nitin Joshi, ilpo.jarvinen
Cc: platform-driver-x86, ibm-acpi-devel, njoshi1, Mark Pearson
Hi Nitin,
On 23-Apr-25 7:51 AM, Nitin Joshi wrote:
> 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.
>
> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Signed-off-by: Nitin Joshi <nitjoshi@gmail.com>
> ---
> Changes in v2:
>
> * Added ASL method to get camera shutter status and send it to userspace.
Thank you for the new version, overall this looks good,
one small remark below.
> ---
> drivers/platform/x86/thinkpad_acpi.c | 43 +++++++++++++++++++++++++++-
> 1 file changed, 42 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
> index 5790095c175e..80b02e8538e8 100644
> --- a/drivers/platform/x86/thinkpad_acpi.c
> +++ b/drivers/platform/x86/thinkpad_acpi.c
> @@ -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)
> }
> }
>
> +static int get_camera_shutter(void)
> +{
> + acpi_handle gces_handle;
> + int output;
> +
> + if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "GCES", &gces_handle))) {
> + /* Platform doesn't support GCES */
> + return -ENODEV;
> + }
> +
> + if (!acpi_evalf(gces_handle, &output, NULL, "dd", 0))
> + return -EIO;
> +
> + if (output & BIT(31))
> + 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,13 @@ 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 +3661,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 +3673,17 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
> return true;
> }
>
> + camera_shutter_state = get_camera_shutter();
Doing this on every hotkey_notify_hotkey() seems wasteful /
inefficient. I suggest to move this inside the if, like this:
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,
...
> + if (hkey == TP_HKEY_EV_CAMERASHUTTER_TOGGLE && (camera_shutter_state >= 0)) {
> + 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);
I believe you should add a "return true" after the unlock to avoid this
code from triggering later:
if (!known_ev) {
pr_notice("unhandled HKEY event 0x%04x\n", hkey);
pr_notice("please report the conditions when this event happened to %s
TPACPI_MAIL);
}
and also to avoid needlessly going through hotkey_notify_hotkey();
> + }
> +
> return tpacpi_input_send_key(hkey, send_acpi_ev);
> }
Regards,
Hans
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] platform/x86: thinkpad-acpi: Add support for new hotkey for camera shutter switch
2025-04-23 12:57 ` Hans de Goede
@ 2025-04-23 13:19 ` Nitin Joshi
0 siblings, 0 replies; 5+ messages in thread
From: Nitin Joshi @ 2025-04-23 13:19 UTC (permalink / raw)
To: Hans de Goede, ilpo.jarvinen
Cc: platform-driver-x86, ibm-acpi-devel, njoshi1, Mark Pearson
Hello Hans,
Thank you for review.
On 4/23/25 21:57, Hans de Goede wrote:
> Hi Nitin,
>
> On 23-Apr-25 7:51 AM, Nitin Joshi wrote:
>> 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.
>>
>> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> Signed-off-by: Nitin Joshi <nitjoshi@gmail.com>
>> ---
>> Changes in v2:
>>
>> * Added ASL method to get camera shutter status and send it to userspace.
>
> Thank you for the new version, overall this looks good,
> one small remark below.
>
>
>> ---
>> drivers/platform/x86/thinkpad_acpi.c | 43 +++++++++++++++++++++++++++-
>> 1 file changed, 42 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
>> index 5790095c175e..80b02e8538e8 100644
>> --- a/drivers/platform/x86/thinkpad_acpi.c
>> +++ b/drivers/platform/x86/thinkpad_acpi.c
>> @@ -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)
>> }
>> }
>>
>> +static int get_camera_shutter(void)
>> +{
>> + acpi_handle gces_handle;
>> + int output;
>> +
>> + if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "GCES", &gces_handle))) {
>> + /* Platform doesn't support GCES */
>> + return -ENODEV;
>> + }
>> +
>> + if (!acpi_evalf(gces_handle, &output, NULL, "dd", 0))
>> + return -EIO;
>> +
>> + if (output & BIT(31))
>> + 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,13 @@ 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 +3661,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 +3673,17 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
>> return true;
>> }
>>
>> + camera_shutter_state = get_camera_shutter();
>
> Doing this on every hotkey_notify_hotkey() seems wasteful /
> inefficient. I suggest to move this inside the if, like this:
Ack , Thanks for pointing this out. I will modify it.
>
> 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,
> ...
>
>> + if (hkey == TP_HKEY_EV_CAMERASHUTTER_TOGGLE && (camera_shutter_state >= 0)) {
>> + 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);
>
>
> I believe you should add a "return true" after the unlock to avoid this
> code from triggering later:
>
> if (!known_ev) {
> pr_notice("unhandled HKEY event 0x%04x\n", hkey);
> pr_notice("please report the conditions when this event happened to %s
> TPACPI_MAIL);
> }
>
> and also to avoid needlessly going through hotkey_notify_hotkey();
>
Thanks for pointing this out. I have already modified it and will send
updated patch soon.
>> + }
>> +
>> return tpacpi_input_send_key(hkey, send_acpi_ev);
>> }
>
> Regards,
>
> Hans
Thanks & Regards,
Nitin Joshi
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-04-23 13:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-23 5:51 [PATCH v2] platform/x86: thinkpad-acpi: Add support for new hotkey for camera shutter switch Nitin Joshi
2025-04-23 9:42 ` Ilpo Järvinen
2025-04-23 12:29 ` Nitin Joshi
2025-04-23 12:57 ` Hans de Goede
2025-04-23 13:19 ` Nitin Joshi
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.