Previously, when the camera toggle switch was hit, the hp-wmi driver
would report an invalid event code. By adding a case for that in the
event handling switch statement we can eliminate that error code and
enable a framework for potential further kernel handling of that key.
This change was tested on my HP Envy x360 15-ey0023dx laptop, but it
would likely work for any HP laptop with a camera toggle button. Now
we emit an SW_CAMERA_LENS_COVER event, on a device that gets created
on the first such event so as to not report incorrectly the state of
the camera shutter before we can know its state.
Signed-off-by: Jonathan Singer <[email protected]>
---
V2 changes: Added SW_CAMERA_LENS_COVER switch event
V3 changes: removed input dev sync, changed pr_info to pr_err/pr_warn
drivers/platform/x86/hp/hp-wmi.c | 46 ++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-wmi.c
index 873f59c3e280..18d40270aa0d 100644
--- a/drivers/platform/x86/hp/hp-wmi.c
+++ b/drivers/platform/x86/hp/hp-wmi.c
@@ -90,6 +90,7 @@ enum hp_wmi_event_ids {
HPWMI_PEAKSHIFT_PERIOD = 0x0F,
HPWMI_BATTERY_CHARGE_PERIOD = 0x10,
HPWMI_SANITIZATION_MODE = 0x17,
+ HPWMI_CAMERA_TOGGLE = 0x1A,
HPWMI_OMEN_KEY = 0x1D,
HPWMI_SMART_EXPERIENCE_APP = 0x21,
};
@@ -228,6 +229,7 @@ static const struct key_entry hp_wmi_keymap[] = {
};
static struct input_dev *hp_wmi_input_dev;
+static struct input_dev *camera_shutter_input_dev;
static struct platform_device *hp_wmi_platform_dev;
static struct platform_profile_handler platform_profile_handler;
static bool platform_profile_support;
@@ -739,6 +741,33 @@ static ssize_t postcode_store(struct device *dev, struct device_attribute *attr,
return count;
}
+static int camera_shutter_input_setup(void)
+{
+ int err;
+
+ camera_shutter_input_dev = input_allocate_device();
+ if (!camera_shutter_input_dev)
+ return -ENOMEM;
+
+ camera_shutter_input_dev->name = "HP WMI camera shutter";
+ camera_shutter_input_dev->phys = "wmi/input1";
+ camera_shutter_input_dev->id.bustype = BUS_HOST;
+
+ __set_bit(EV_SW, camera_shutter_input_dev->evbit);
+ __set_bit(SW_CAMERA_LENS_COVER, camera_shutter_input_dev->swbit);
+
+ err = input_register_device(camera_shutter_input_dev);
+ if (err)
+ goto err_free_dev;
+
+ return 0;
+
+ err_free_dev:
+ input_free_device(camera_shutter_input_dev);
+ camera_shutter_input_dev = NULL;
+ return err;
+}
+
static DEVICE_ATTR_RO(display);
static DEVICE_ATTR_RO(hddtemp);
static DEVICE_ATTR_RW(als);
@@ -866,6 +895,20 @@ static void hp_wmi_notify(u32 value, void *context)
break;
case HPWMI_SANITIZATION_MODE:
break;
+ case HPWMI_CAMERA_TOGGLE:
+ if (!camera_shutter_input_dev)
+ if (camera_shutter_input_setup()) {
+ pr_err("Failed to setup camera shutter input device\n");
+ break;
+ }
+ if (event_data == 0xff)
+ input_report_switch(camera_shutter_input_dev, SW_CAMERA_LENS_COVER, 1);
+ else if (event_data == 0xfe)
+ input_report_switch(camera_shutter_input_dev, SW_CAMERA_LENS_COVER, 0);
+ else
+ pr_warn("Unknown camera shutter state - 0x%x\n", event_data);
+ input_sync(camera_shutter_input_dev);
+ break;
case HPWMI_SMART_EXPERIENCE_APP:
break;
default:
@@ -1564,6 +1607,9 @@ static void __exit hp_wmi_exit(void)
if (wmi_has_guid(HPWMI_EVENT_GUID))
hp_wmi_input_destroy();
+ if (camera_shutter_input_dev)
+ input_unregister_device(camera_shutter_input_dev);
+
if (hp_wmi_platform_dev) {
platform_device_unregister(hp_wmi_platform_dev);
platform_driver_unregister(&hp_wmi_driver);
--
2.40.0
Previously, some support for certain keys on the HP keyboard has been
added already in commit 3ee5447b2048 ("platform/x86: hp-wmi: Handle Omen
Key event"), however this as tested did not allow even the fn+esc key on
my HP Envy which uses the same keycode on my HP Envy x360 laptop to work
--the keycode rather than being passed in as a separate int from WMI, was
being passed in as the event_data for the HPWMI_OMEN_KEY event.
This patch, as tested was able to properly get the keycode for fn+esc,
and for fn+f12 which is supposed to be a programmable key according to
HP's keyboard diagram and is thus mapped to KEY_PROG2. The fn+f8 key
combination (mute microphone) was a standard HPWMI_BEZEL_BUTTON key,
however it did not previously have an entry in the sparse keymap. This
patch preserves the original HPWMI_OMEN_KEY behavior for laptops that
use it by only taking the keycode from the event_data only when the
event_data is nonzero.
Signed-off-by: Jonathan Singer <[email protected]>
Reviewed-by: Mario Limonciello <[email protected]>
---
V2 changes: Removed confusing comment
drivers/platform/x86/hp/hp-wmi.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-wmi.c
index 18d40270aa0d..2749433b713f 100644
--- a/drivers/platform/x86/hp/hp-wmi.c
+++ b/drivers/platform/x86/hp/hp-wmi.c
@@ -212,6 +212,7 @@ struct bios_rfkill2_state {
static const struct key_entry hp_wmi_keymap[] = {
{ KE_KEY, 0x02, { KEY_BRIGHTNESSUP } },
{ KE_KEY, 0x03, { KEY_BRIGHTNESSDOWN } },
+ { KE_KEY, 0x270, { KEY_MICMUTE } },
{ KE_KEY, 0x20e6, { KEY_PROG1 } },
{ KE_KEY, 0x20e8, { KEY_MEDIA } },
{ KE_KEY, 0x2142, { KEY_MEDIA } },
@@ -222,6 +223,7 @@ static const struct key_entry hp_wmi_keymap[] = {
{ KE_IGNORE, 0x121a4, }, /* Win Lock Off */
{ KE_KEY, 0x21a5, { KEY_PROG2 } }, /* HP Omen Key */
{ KE_KEY, 0x21a7, { KEY_FN_ESC } },
+ { KE_KEY, 0x21a8, { KEY_PROG2 } }, /* HP Envy x360 programmable key */
{ KE_KEY, 0x21a9, { KEY_TOUCHPAD_OFF } },
{ KE_KEY, 0x121a9, { KEY_TOUCHPAD_ON } },
{ KE_KEY, 0x231b, { KEY_HELP } },
@@ -844,11 +846,20 @@ static void hp_wmi_notify(u32 value, void *context)
case HPWMI_SMART_ADAPTER:
break;
case HPWMI_BEZEL_BUTTON:
- case HPWMI_OMEN_KEY:
key_code = hp_wmi_read_int(HPWMI_HOTKEY_QUERY);
if (key_code < 0)
break;
+ if (!sparse_keymap_report_event(hp_wmi_input_dev,
+ key_code, 1, true))
+ pr_info("Unknown key code - 0x%x\n", key_code);
+ break;
+ case HPWMI_OMEN_KEY:
+ if (event_data) /* Only should be true for HP Omen */
+ key_code = event_data;
+ else
+ key_code = hp_wmi_read_int(HPWMI_HOTKEY_QUERY);
+
if (!sparse_keymap_report_event(hp_wmi_input_dev,
key_code, 1, true))
pr_info("Unknown key code - 0x%x\n", key_code);
--
2.40.0
[Public]
> Previously, when the camera toggle switch was hit, the hp-wmi driver
> would report an invalid event code. By adding a case for that in the
> event handling switch statement we can eliminate that error code and
> enable a framework for potential further kernel handling of that key.
> This change was tested on my HP Envy x360 15-ey0023dx laptop, but it
> would likely work for any HP laptop with a camera toggle button. Now
> we emit an SW_CAMERA_LENS_COVER event, on a device that gets created
> on the first such event so as to not report incorrectly the state of
> the camera shutter before we can know its state.
>
> Signed-off-by: Jonathan Singer <[email protected]>
Reviewed-by: Mario Limonciello <[email protected]>
> ---
> V2 changes: Added SW_CAMERA_LENS_COVER switch event
> V3 changes: removed input dev sync, changed pr_info to pr_err/pr_warn
>
> drivers/platform/x86/hp/hp-wmi.c | 46
> ++++++++++++++++++++++++++++++++
> 1 file changed, 46 insertions(+)
>
> diff --git a/drivers/platform/x86/hp/hp-wmi.c
> b/drivers/platform/x86/hp/hp-wmi.c
> index 873f59c3e280..18d40270aa0d 100644
> --- a/drivers/platform/x86/hp/hp-wmi.c
> +++ b/drivers/platform/x86/hp/hp-wmi.c
> @@ -90,6 +90,7 @@ enum hp_wmi_event_ids {
> HPWMI_PEAKSHIFT_PERIOD = 0x0F,
> HPWMI_BATTERY_CHARGE_PERIOD = 0x10,
> HPWMI_SANITIZATION_MODE = 0x17,
> + HPWMI_CAMERA_TOGGLE = 0x1A,
> HPWMI_OMEN_KEY = 0x1D,
> HPWMI_SMART_EXPERIENCE_APP = 0x21,
> };
> @@ -228,6 +229,7 @@ static const struct key_entry hp_wmi_keymap[] = {
> };
>
> static struct input_dev *hp_wmi_input_dev;
> +static struct input_dev *camera_shutter_input_dev;
> static struct platform_device *hp_wmi_platform_dev;
> static struct platform_profile_handler platform_profile_handler;
> static bool platform_profile_support;
> @@ -739,6 +741,33 @@ static ssize_t postcode_store(struct device *dev,
> struct device_attribute *attr,
> return count;
> }
>
> +static int camera_shutter_input_setup(void)
> +{
> + int err;
> +
> + camera_shutter_input_dev = input_allocate_device();
> + if (!camera_shutter_input_dev)
> + return -ENOMEM;
> +
> + camera_shutter_input_dev->name = "HP WMI camera shutter";
> + camera_shutter_input_dev->phys = "wmi/input1";
> + camera_shutter_input_dev->id.bustype = BUS_HOST;
> +
> + __set_bit(EV_SW, camera_shutter_input_dev->evbit);
> + __set_bit(SW_CAMERA_LENS_COVER, camera_shutter_input_dev-
> >swbit);
> +
> + err = input_register_device(camera_shutter_input_dev);
> + if (err)
> + goto err_free_dev;
> +
> + return 0;
> +
> + err_free_dev:
> + input_free_device(camera_shutter_input_dev);
> + camera_shutter_input_dev = NULL;
> + return err;
> +}
> +
> static DEVICE_ATTR_RO(display);
> static DEVICE_ATTR_RO(hddtemp);
> static DEVICE_ATTR_RW(als);
> @@ -866,6 +895,20 @@ static void hp_wmi_notify(u32 value, void *context)
> break;
> case HPWMI_SANITIZATION_MODE:
> break;
> + case HPWMI_CAMERA_TOGGLE:
> + if (!camera_shutter_input_dev)
> + if (camera_shutter_input_setup()) {
> + pr_err("Failed to setup camera shutter input
> device\n");
> + break;
> + }
> + if (event_data == 0xff)
> + input_report_switch(camera_shutter_input_dev,
> SW_CAMERA_LENS_COVER, 1);
> + else if (event_data == 0xfe)
> + input_report_switch(camera_shutter_input_dev,
> SW_CAMERA_LENS_COVER, 0);
> + else
> + pr_warn("Unknown camera shutter state - 0x%x\n",
> event_data);
> + input_sync(camera_shutter_input_dev);
> + break;
> case HPWMI_SMART_EXPERIENCE_APP:
> break;
> default:
> @@ -1564,6 +1607,9 @@ static void __exit hp_wmi_exit(void)
> if (wmi_has_guid(HPWMI_EVENT_GUID))
> hp_wmi_input_destroy();
>
> + if (camera_shutter_input_dev)
> + input_unregister_device(camera_shutter_input_dev);
> +
> if (hp_wmi_platform_dev) {
> platform_device_unregister(hp_wmi_platform_dev);
> platform_driver_unregister(&hp_wmi_driver);
> --
> 2.40.0
Hi,
On 4/26/23 20:48, Jonathan Singer wrote:
> Previously, when the camera toggle switch was hit, the hp-wmi driver
> would report an invalid event code. By adding a case for that in the
> event handling switch statement we can eliminate that error code and
> enable a framework for potential further kernel handling of that key.
> This change was tested on my HP Envy x360 15-ey0023dx laptop, but it
> would likely work for any HP laptop with a camera toggle button. Now
> we emit an SW_CAMERA_LENS_COVER event, on a device that gets created
> on the first such event so as to not report incorrectly the state of
> the camera shutter before we can know its state.
>
> Signed-off-by: Jonathan Singer <[email protected]>
Thank you for your patch-series, I've applied the series to my
review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans
Note it will show up in my review-hans branch once I've pushed my
local branch there, which might take a while.
Once I've run some tests on this branch the patches there will be
added to the platform-drivers-x86/for-next branch and eventually
will be included in the pdx86 pull-request to Linus for the next
merge-window.
Regards,
Hans
> ---
> V2 changes: Added SW_CAMERA_LENS_COVER switch event
> V3 changes: removed input dev sync, changed pr_info to pr_err/pr_warn
>
> drivers/platform/x86/hp/hp-wmi.c | 46 ++++++++++++++++++++++++++++++++
> 1 file changed, 46 insertions(+)
>
> diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-wmi.c
> index 873f59c3e280..18d40270aa0d 100644
> --- a/drivers/platform/x86/hp/hp-wmi.c
> +++ b/drivers/platform/x86/hp/hp-wmi.c
> @@ -90,6 +90,7 @@ enum hp_wmi_event_ids {
> HPWMI_PEAKSHIFT_PERIOD = 0x0F,
> HPWMI_BATTERY_CHARGE_PERIOD = 0x10,
> HPWMI_SANITIZATION_MODE = 0x17,
> + HPWMI_CAMERA_TOGGLE = 0x1A,
> HPWMI_OMEN_KEY = 0x1D,
> HPWMI_SMART_EXPERIENCE_APP = 0x21,
> };
> @@ -228,6 +229,7 @@ static const struct key_entry hp_wmi_keymap[] = {
> };
>
> static struct input_dev *hp_wmi_input_dev;
> +static struct input_dev *camera_shutter_input_dev;
> static struct platform_device *hp_wmi_platform_dev;
> static struct platform_profile_handler platform_profile_handler;
> static bool platform_profile_support;
> @@ -739,6 +741,33 @@ static ssize_t postcode_store(struct device *dev, struct device_attribute *attr,
> return count;
> }
>
> +static int camera_shutter_input_setup(void)
> +{
> + int err;
> +
> + camera_shutter_input_dev = input_allocate_device();
> + if (!camera_shutter_input_dev)
> + return -ENOMEM;
> +
> + camera_shutter_input_dev->name = "HP WMI camera shutter";
> + camera_shutter_input_dev->phys = "wmi/input1";
> + camera_shutter_input_dev->id.bustype = BUS_HOST;
> +
> + __set_bit(EV_SW, camera_shutter_input_dev->evbit);
> + __set_bit(SW_CAMERA_LENS_COVER, camera_shutter_input_dev->swbit);
> +
> + err = input_register_device(camera_shutter_input_dev);
> + if (err)
> + goto err_free_dev;
> +
> + return 0;
> +
> + err_free_dev:
> + input_free_device(camera_shutter_input_dev);
> + camera_shutter_input_dev = NULL;
> + return err;
> +}
> +
> static DEVICE_ATTR_RO(display);
> static DEVICE_ATTR_RO(hddtemp);
> static DEVICE_ATTR_RW(als);
> @@ -866,6 +895,20 @@ static void hp_wmi_notify(u32 value, void *context)
> break;
> case HPWMI_SANITIZATION_MODE:
> break;
> + case HPWMI_CAMERA_TOGGLE:
> + if (!camera_shutter_input_dev)
> + if (camera_shutter_input_setup()) {
> + pr_err("Failed to setup camera shutter input device\n");
> + break;
> + }
> + if (event_data == 0xff)
> + input_report_switch(camera_shutter_input_dev, SW_CAMERA_LENS_COVER, 1);
> + else if (event_data == 0xfe)
> + input_report_switch(camera_shutter_input_dev, SW_CAMERA_LENS_COVER, 0);
> + else
> + pr_warn("Unknown camera shutter state - 0x%x\n", event_data);
> + input_sync(camera_shutter_input_dev);
> + break;
> case HPWMI_SMART_EXPERIENCE_APP:
> break;
> default:
> @@ -1564,6 +1607,9 @@ static void __exit hp_wmi_exit(void)
> if (wmi_has_guid(HPWMI_EVENT_GUID))
> hp_wmi_input_destroy();
>
> + if (camera_shutter_input_dev)
> + input_unregister_device(camera_shutter_input_dev);
> +
> if (hp_wmi_platform_dev) {
> platform_device_unregister(hp_wmi_platform_dev);
> platform_driver_unregister(&hp_wmi_driver);