mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mario Limonciello <mario.limonciello@amd.com>
To: Jonathan Singer <jes965@nyu.edu>,
	Hans de Goede <hdegoede@redhat.com>,
	Mark Gross <markgross@kernel.org>
Cc: Jorge Lopez <jorge.lopez2@hp.com>,
	Rishit Bansal <rishitbansal0@gmail.com>,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Kai-Heng Feng <kai.heng.feng@canonical.com>
Subject: Re: [PATCH v2 1/2] platform/x86: hp-wmi: Add HP WMI camera switch
Date: Wed, 26 Apr 2023 10:39:57 -0500	[thread overview]
Message-ID: <7b869715-dd1c-d35d-f075-ec866f0b00ae@amd.com> (raw)
In-Reply-To: <20230426152139.1692-1-jes965@nyu.edu>


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);

  parent reply	other threads:[~2023-04-26 15:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
2023-04-26 15:40   ` Mario Limonciello
2023-04-26 15:39 ` Mario Limonciello [this message]
2023-04-26 16:06 ` [PATCH v2 1/2] platform/x86: hp-wmi: Add HP WMI camera switch Hans de Goede
2023-04-26 16:09 ` Hans de Goede
2023-04-26 16:49   ` Jonathan Singer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7b869715-dd1c-d35d-f075-ec866f0b00ae@amd.com \
    --to=mario.limonciello@amd.com \
    --cc=hdegoede@redhat.com \
    --cc=jes965@nyu.edu \
    --cc=jorge.lopez2@hp.com \
    --cc=kai.heng.feng@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markgross@kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rishitbansal0@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®