From: Hans de Goede <hdegoede@redhat.com>
To: Ai Chao <aichao@kylinos.cn>,
ilpo.jarvinen@linux.intel.com,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6] platform/x86: lenovo-wmi-camera: Use SW_CAMERA_LENS_COVER instead of KEY_CAMERA_ACESS
Date: Tue, 14 Jan 2025 10:51:30 +0100 [thread overview]
Message-ID: <789984c3-42c9-451e-857d-815d53dedd0b@redhat.com> (raw)
In-Reply-To: <20250114063934.3116444-1-aichao@kylinos.cn>
Hi,
On 14-Jan-25 7:39 AM, Ai Chao wrote:
> Use SW_CAMERA_LENS_COVER instead of KEY_CAMERA_ACESS_ENABLE and
> KEY_CAMERA_ACESS_DISABLE. When the camera toggle switch was hit,
> the lenovo-wmi-camera driver would report an event code.
>
> Signed-off-by: Ai Chao <aichao@kylinos.cn>
> ---
> change for v6
> -Change mutex() to guard().
Thank you for the new version, I see that as part of this change
you have also moved the mutex out of struct lenovo_wmi_priv making
it a global variable.
Making the mutex global is not necessary for the use of guard()
and is undesirable.
Please submit a new version where the mutex is kept as part of
struct lenovo_wmi_priv.
Regards,
Hans
> change for v5
> -Add input_report_switch before input_register_device.
> change for v4
> -Add mutex_unlock and report a switch state of 0 if SW_CAMERA_ON.
> change for v3
> -Used input_register_device and input_allocate_device.
> change for v2
> -Only delays the input-device registration and switches to reporting SW_CAMERA_LENS_COVER.
>
> drivers/platform/x86/lenovo-wmi-camera.c | 75 +++++++++++++++---------
> 1 file changed, 46 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo-wmi-camera.c b/drivers/platform/x86/lenovo-wmi-camera.c
> index 0c0bedaf7407..36835cd64758 100644
> --- a/drivers/platform/x86/lenovo-wmi-camera.c
> +++ b/drivers/platform/x86/lenovo-wmi-camera.c
> @@ -13,12 +13,15 @@
> #include <linux/module.h>
> #include <linux/mutex.h>
> #include <linux/wmi.h>
> +#include <linux/cleanup.h>
>
> #define WMI_LENOVO_CAMERABUTTON_EVENT_GUID "50C76F1F-D8E4-D895-0A3D-62F4EA400013"
>
> +/* Lenovo WMI camera button notify lock */
> +static DEFINE_MUTEX(notify_lock);
> +
> struct lenovo_wmi_priv {
> struct input_dev *idev;
> - struct mutex notify_lock; /* lenovo WMI camera button notify lock */
> };
>
> enum {
> @@ -26,10 +29,38 @@ enum {
> SW_CAMERA_ON = 1,
> };
>
> +static int camera_shutter_input_setup(struct wmi_device *wdev, u8 camera_mode)
> +{
> + struct lenovo_wmi_priv *priv = dev_get_drvdata(&wdev->dev);
> + int err;
> +
> + priv->idev = input_allocate_device();
> + if (!priv->idev)
> + return -ENOMEM;
> +
> + priv->idev->name = "Lenovo WMI Camera Button";
> + priv->idev->phys = "wmi/input0";
> + priv->idev->id.bustype = BUS_HOST;
> + priv->idev->dev.parent = &wdev->dev;
> +
> + input_set_capability(priv->idev, EV_SW, SW_CAMERA_LENS_COVER);
> +
> + input_report_switch(priv->idev, SW_CAMERA_LENS_COVER,
> + camera_mode == SW_CAMERA_ON ? 0 : 1);
> + input_sync(priv->idev);
> +
> + err = input_register_device(priv->idev);
> + if (err) {
> + input_free_device(priv->idev);
> + priv->idev = NULL;
> + }
> +
> + return err;
> +}
> +
> static void lenovo_wmi_notify(struct wmi_device *wdev, union acpi_object *obj)
> {
> struct lenovo_wmi_priv *priv = dev_get_drvdata(&wdev->dev);
> - unsigned int keycode;
> u8 camera_mode;
>
> if (obj->type != ACPI_TYPE_BUFFER) {
> @@ -53,22 +84,24 @@ static void lenovo_wmi_notify(struct wmi_device *wdev, union acpi_object *obj)
> return;
> }
>
> - mutex_lock(&priv->notify_lock);
> + guard(mutex)(¬ify_lock);
>
> - keycode = camera_mode == SW_CAMERA_ON ?
> - KEY_CAMERA_ACCESS_ENABLE : KEY_CAMERA_ACCESS_DISABLE;
> - input_report_key(priv->idev, keycode, 1);
> - input_sync(priv->idev);
> - input_report_key(priv->idev, keycode, 0);
> - input_sync(priv->idev);
> + if (!priv->idev) {
> + if (camera_shutter_input_setup(wdev, camera_mode))
> + dev_warn(&wdev->dev, "Failed to register input device\n");
> + return;
> + }
>
> - mutex_unlock(&priv->notify_lock);
> + if (camera_mode == SW_CAMERA_ON)
> + input_report_switch(priv->idev, SW_CAMERA_LENS_COVER, 0);
> + else
> + input_report_switch(priv->idev, SW_CAMERA_LENS_COVER, 1);
> + input_sync(priv->idev);
> }
>
> static int lenovo_wmi_probe(struct wmi_device *wdev, const void *context)
> {
> struct lenovo_wmi_priv *priv;
> - int ret;
>
> priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL);
> if (!priv)
> @@ -76,23 +109,6 @@ static int lenovo_wmi_probe(struct wmi_device *wdev, const void *context)
>
> dev_set_drvdata(&wdev->dev, priv);
>
> - priv->idev = devm_input_allocate_device(&wdev->dev);
> - if (!priv->idev)
> - return -ENOMEM;
> -
> - priv->idev->name = "Lenovo WMI Camera Button";
> - priv->idev->phys = "wmi/input0";
> - priv->idev->id.bustype = BUS_HOST;
> - priv->idev->dev.parent = &wdev->dev;
> - input_set_capability(priv->idev, EV_KEY, KEY_CAMERA_ACCESS_ENABLE);
> - input_set_capability(priv->idev, EV_KEY, KEY_CAMERA_ACCESS_DISABLE);
> -
> - ret = input_register_device(priv->idev);
> - if (ret)
> - return ret;
> -
> - mutex_init(&priv->notify_lock);
> -
> return 0;
> }
>
> @@ -100,7 +116,8 @@ static void lenovo_wmi_remove(struct wmi_device *wdev)
> {
> struct lenovo_wmi_priv *priv = dev_get_drvdata(&wdev->dev);
>
> - mutex_destroy(&priv->notify_lock);
> + if (priv->idev)
> + input_unregister_device(priv->idev);
> }
>
> static const struct wmi_device_id lenovo_wmi_id_table[] = {
prev parent reply other threads:[~2025-01-14 9:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-14 6:39 Ai Chao
2025-01-14 9:51 ` Hans de Goede [this message]
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=789984c3-42c9-451e-857d-815d53dedd0b@redhat.com \
--to=hdegoede@redhat.com \
--cc=aichao@kylinos.cn \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
/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®