All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] platform/x86: hp-wmi: Add HP WMI camera switch
@ 2023-04-26 15:21 Jonathan Singer
  2023-04-26 15:21 ` [PATCH v2 2/2] platform/x86: hp-wmi: Add HP Envy special key support Jonathan Singer
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Jonathan Singer @ 2023-04-26 15:21 UTC (permalink / raw)
  To: Hans de Goede, Mario Limonciello, Mark Gross
  Cc: Jorge Lopez, Rishit Bansal, platform-driver-x86, linux-kernel,
	Kai-Heng Feng, Jonathan Singer

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 <jes965@nyu.edu>
---
 drivers/platform/x86/hp/hp-wmi.c | 50 ++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-wmi.c
index 873f59c3e280..a7fb33ac49b8 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,36 @@ 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);
+
+	/* Set initial hardware state */
+	input_sync(camera_shutter_input_dev);
+
+	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 +898,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_info("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_info("Unknown camera shutter state - 0x%x\n", event_data);
+		input_sync(camera_shutter_input_dev);
+		break;
 	case HPWMI_SMART_EXPERIENCE_APP:
 		break;
 	default:
@@ -1564,9 +1610,13 @@ 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);
 	}
+
 }
 module_exit(hp_wmi_exit);
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] platform/x86: hp-wmi: Add HP Envy special key support
  2023-04-26 15:21 [PATCH v2 1/2] platform/x86: hp-wmi: Add HP WMI camera switch Jonathan Singer
@ 2023-04-26 15:21 ` Jonathan Singer
  2023-04-26 15:40   ` Mario Limonciello
  2023-04-26 15:39 ` [PATCH v2 1/2] platform/x86: hp-wmi: Add HP WMI camera switch Mario Limonciello
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Jonathan Singer @ 2023-04-26 15:21 UTC (permalink / raw)
  To: Hans de Goede, Mario Limonciello, Mark Gross
  Cc: Jorge Lopez, Rishit Bansal, platform-driver-x86, linux-kernel,
	Kai-Heng Feng, Jonathan Singer

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 <jes965@nyu.edu>
---
 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 a7fb33ac49b8..399163b4aca0 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 } },
@@ -847,11 +849,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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] platform/x86: hp-wmi: Add HP WMI camera switch
  2023-04-26 15:21 [PATCH v2 1/2] platform/x86: hp-wmi: Add HP WMI camera switch Jonathan Singer
  2023-04-26 15:21 ` [PATCH v2 2/2] platform/x86: hp-wmi: Add HP Envy special key support Jonathan Singer
@ 2023-04-26 15:39 ` Mario Limonciello
  2023-04-26 16:06 ` Hans de Goede
  2023-04-26 16:09 ` Hans de Goede
  3 siblings, 0 replies; 7+ messages in thread
From: Mario Limonciello @ 2023-04-26 15:39 UTC (permalink / raw)
  To: Jonathan Singer, Hans de Goede, Mark Gross
  Cc: Jorge Lopez, Rishit Bansal, platform-driver-x86, linux-kernel,
	Kai-Heng Feng


On 4/26/23 10:21, 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 <jes965@nyu.edu>
> ---
>   drivers/platform/x86/hp/hp-wmi.c | 50 ++++++++++++++++++++++++++++++++
>   1 file changed, 50 insertions(+)
>
> diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-wmi.c
> index 873f59c3e280..a7fb33ac49b8 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,36 @@ 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);
> +
> +	/* Set initial hardware state */
> +	input_sync(camera_shutter_input_dev);
> +
> +	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 +898,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_info("Failed to setup camera shutter input device\n");
I think this should be pr_err.
> +				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_info("Unknown camera shutter state - 0x%x\n", event_data);
I think this should be warn.
> +		input_sync(camera_shutter_input_dev);
> +		break;
>   	case HPWMI_SMART_EXPERIENCE_APP:
>   		break;
>   	default:
> @@ -1564,9 +1610,13 @@ 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);
>   	}
> +
>   }
>   module_exit(hp_wmi_exit);

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] platform/x86: hp-wmi: Add HP Envy special key support
  2023-04-26 15:21 ` [PATCH v2 2/2] platform/x86: hp-wmi: Add HP Envy special key support Jonathan Singer
@ 2023-04-26 15:40   ` Mario Limonciello
  0 siblings, 0 replies; 7+ messages in thread
From: Mario Limonciello @ 2023-04-26 15:40 UTC (permalink / raw)
  To: Jonathan Singer, Hans de Goede, Mark Gross
  Cc: Jorge Lopez, Rishit Bansal, platform-driver-x86, linux-kernel,
	Kai-Heng Feng


On 4/26/23 10:21, Jonathan Singer wrote:
> 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 <jes965@nyu.edu>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
>   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 a7fb33ac49b8..399163b4aca0 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 } },
> @@ -847,11 +849,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);

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] platform/x86: hp-wmi: Add HP WMI camera switch
  2023-04-26 15:21 [PATCH v2 1/2] platform/x86: hp-wmi: Add HP WMI camera switch Jonathan Singer
  2023-04-26 15:21 ` [PATCH v2 2/2] platform/x86: hp-wmi: Add HP Envy special key support Jonathan Singer
  2023-04-26 15:39 ` [PATCH v2 1/2] platform/x86: hp-wmi: Add HP WMI camera switch Mario Limonciello
@ 2023-04-26 16:06 ` Hans de Goede
  2023-04-26 16:09 ` Hans de Goede
  3 siblings, 0 replies; 7+ messages in thread
From: Hans de Goede @ 2023-04-26 16:06 UTC (permalink / raw)
  To: Jonathan Singer, Mario Limonciello, Mark Gross
  Cc: Jorge Lopez, Rishit Bansal, platform-driver-x86, linux-kernel,
	Kai-Heng Feng

Hi Jonathan,

On 4/26/23 17:21, 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 <jes965@nyu.edu>
> ---
>  drivers/platform/x86/hp/hp-wmi.c | 50 ++++++++++++++++++++++++++++++++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-wmi.c
> index 873f59c3e280..a7fb33ac49b8 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,36 @@ 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);
> +
> +	/* Set initial hardware state */
> +	input_sync(camera_shutter_input_dev);

This initial sync is only necessary if you have actually
read + set an initial state, which is not happening here,
so please drop this.

The caller of camera_shutter_input_setup() will set
a state + call input_sync() immediately afterwards anyways,
so there is no need to set an initial state.

Otherwise this looks good to me, thank you for working on this.

Regards,

Hans


> +
> +	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 +898,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_info("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_info("Unknown camera shutter state - 0x%x\n", event_data);
> +		input_sync(camera_shutter_input_dev);
> +		break;
>  	case HPWMI_SMART_EXPERIENCE_APP:
>  		break;
>  	default:
> @@ -1564,9 +1610,13 @@ 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);
>  	}
> +
>  }
>  module_exit(hp_wmi_exit);


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] platform/x86: hp-wmi: Add HP WMI camera switch
  2023-04-26 15:21 [PATCH v2 1/2] platform/x86: hp-wmi: Add HP WMI camera switch Jonathan Singer
                   ` (2 preceding siblings ...)
  2023-04-26 16:06 ` Hans de Goede
@ 2023-04-26 16:09 ` Hans de Goede
  2023-04-26 16:49   ` Jonathan Singer
  3 siblings, 1 reply; 7+ messages in thread
From: Hans de Goede @ 2023-04-26 16:09 UTC (permalink / raw)
  To: Jonathan Singer, Mario Limonciello, Mark Gross
  Cc: Jorge Lopez, Rishit Bansal, platform-driver-x86, linux-kernel,
	Kai-Heng Feng

Hi again,

On 4/26/23 17:21, 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 <jes965@nyu.edu>

p.s.

> +		if (event_data == 0xff)
> +			input_report_switch(camera_shutter_input_dev, SW_CAMERA_LENS_COVER, 1);

I assume that event_data = 0xff happens when disabling the camera, so
we report SW_CAMERA_LENS_COVER 1 when the camera is disabled, right ?

Regards,

Hans



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] platform/x86: hp-wmi: Add HP WMI camera switch
  2023-04-26 16:09 ` Hans de Goede
@ 2023-04-26 16:49   ` Jonathan Singer
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Singer @ 2023-04-26 16:49 UTC (permalink / raw)
  To: hdegoede
  Cc: Mario.Limonciello, jes965, jorge.lopez2, kai.heng.feng,
	linux-kernel, markgross, platform-driver-x86, rishitbansal0

Hi Hans,

On Wed, 26 Apr 2023 18:09:13 +0200, Hans de Goede <hdegoede@redhat.com> wrote
> I assume that event_data = 0xff happens when disabling the camera, so
> we report SW_CAMERA_LENS_COVER 1 when the camera is disabled, right ?

Correct, the 0xff event_data happens when the camera shutter is closed and
the 0xfe event happens when the camera shutter is opened.

Regards,
Jonathan

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-04-26 17:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-26 15:21 [PATCH v2 1/2] platform/x86: hp-wmi: Add HP WMI camera switch Jonathan Singer
2023-04-26 15:21 ` [PATCH v2 2/2] platform/x86: hp-wmi: Add HP Envy special key support Jonathan Singer
2023-04-26 15:40   ` Mario Limonciello
2023-04-26 15:39 ` [PATCH v2 1/2] platform/x86: hp-wmi: Add HP WMI camera switch Mario Limonciello
2023-04-26 16:06 ` Hans de Goede
2023-04-26 16:09 ` Hans de Goede
2023-04-26 16:49   ` Jonathan Singer

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.