Skip to content

Commit 3c415b1

Browse files
nitinexclusivelyij-intel
authored andcommitted
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. Reviewed-by: Mark Pearson <[email protected]> Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Nitin Joshi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent 9950f94 commit 3c415b1

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

drivers/platform/x86/thinkpad_acpi.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ enum tpacpi_hkey_event_t {
182182
* directly in the sparse-keymap.
183183
*/
184184
TP_HKEY_EV_AMT_TOGGLE = 0x131a, /* Toggle AMT on/off */
185+
TP_HKEY_EV_CAMERASHUTTER_TOGGLE = 0x131b, /* Toggle Camera Shutter */
185186
TP_HKEY_EV_DOUBLETAP_TOGGLE = 0x131c, /* Toggle trackpoint doubletap on/off */
186187
TP_HKEY_EV_PROFILE_TOGGLE = 0x131f, /* Toggle platform profile in 2024 systems */
187188
TP_HKEY_EV_PROFILE_TOGGLE2 = 0x1401, /* Toggle platform profile in 2025 + systems */
@@ -2250,6 +2251,25 @@ static void tpacpi_input_send_tabletsw(void)
22502251
}
22512252
}
22522253

2254+
#define GCES_NO_SHUTTER_DEVICE BIT(31)
2255+
2256+
static int get_camera_shutter(void)
2257+
{
2258+
acpi_handle gces_handle;
2259+
int output;
2260+
2261+
if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "GCES", &gces_handle)))
2262+
return -ENODEV;
2263+
2264+
if (!acpi_evalf(gces_handle, &output, NULL, "dd", 0))
2265+
return -EIO;
2266+
2267+
if (output & GCES_NO_SHUTTER_DEVICE)
2268+
return -ENODEV;
2269+
2270+
return output;
2271+
}
2272+
22532273
static bool tpacpi_input_send_key(const u32 hkey, bool *send_acpi_ev)
22542274
{
22552275
bool known_ev;
@@ -3303,7 +3323,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
33033323
const struct key_entry *keymap;
33043324
bool radiosw_state = false;
33053325
bool tabletsw_state = false;
3306-
int hkeyv, res, status;
3326+
int hkeyv, res, status, camera_shutter_state;
33073327

33083328
vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
33093329
"initializing hotkey subdriver\n");
@@ -3467,6 +3487,12 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
34673487
if (res)
34683488
return res;
34693489

3490+
camera_shutter_state = get_camera_shutter();
3491+
if (camera_shutter_state >= 0) {
3492+
input_set_capability(tpacpi_inputdev, EV_SW, SW_CAMERA_LENS_COVER);
3493+
input_report_switch(tpacpi_inputdev, SW_CAMERA_LENS_COVER, camera_shutter_state);
3494+
}
3495+
34703496
if (tp_features.hotkey_wlsw) {
34713497
input_set_capability(tpacpi_inputdev, EV_SW, SW_RFKILL_ALL);
34723498
input_report_switch(tpacpi_inputdev,
@@ -11161,6 +11187,8 @@ static struct platform_driver tpacpi_hwmon_pdriver = {
1116111187
*/
1116211188
static bool tpacpi_driver_event(const unsigned int hkey_event)
1116311189
{
11190+
int camera_shutter_state;
11191+
1116411192
switch (hkey_event) {
1116511193
case TP_HKEY_EV_BRGHT_UP:
1116611194
case TP_HKEY_EV_BRGHT_DOWN:
@@ -11236,6 +11264,19 @@ static bool tpacpi_driver_event(const unsigned int hkey_event)
1123611264
else
1123711265
dytc_control_amt(!dytc_amt_active);
1123811266

11267+
return true;
11268+
case TP_HKEY_EV_CAMERASHUTTER_TOGGLE:
11269+
camera_shutter_state = get_camera_shutter();
11270+
if (camera_shutter_state < 0) {
11271+
pr_err("Error retrieving camera shutter state after shutter event\n");
11272+
return true;
11273+
}
11274+
mutex_lock(&tpacpi_inputdev_send_mutex);
11275+
11276+
input_report_switch(tpacpi_inputdev, SW_CAMERA_LENS_COVER, camera_shutter_state);
11277+
input_sync(tpacpi_inputdev);
11278+
11279+
mutex_unlock(&tpacpi_inputdev_send_mutex);
1123911280
return true;
1124011281
case TP_HKEY_EV_DOUBLETAP_TOGGLE:
1124111282
tp_features.trackpoint_doubletap = !tp_features.trackpoint_doubletap;

0 commit comments

Comments
 (0)