On Thu, 7 Mar 2024, Ai Chao wrote: > Add lenovo generic wmi driver to support camera button. > The Camera button is a GPIO device. This driver receives ACPI notifyi > when the camera button is switched on/off. This driver is used in > Lenovo A70, it is a Computer integrated machine. > > Signed-off-by: Ai Chao <aichao@xxxxxxxxxx> > --- > v5: Remove camera button groups, modify KEY_CAMERA to SW_CAMERA_LENS_COVER. > v4: Remove lenovo_wmi_input_setup, move camera_mode into struct lenovo_wmi_priv. > v3: Remove lenovo_wmi_remove function. > v2: Adjust GPL v2 to GPL, adjust sprintf to sysfs_emit. > > drivers/platform/x86/Kconfig | 12 ++++ > drivers/platform/x86/Makefile | 1 + > drivers/platform/x86/lenovo-wmi-camera.c | 89 ++++++++++++++++++++++++ > 3 files changed, 102 insertions(+) > create mode 100644 drivers/platform/x86/lenovo-wmi-camera.c > > diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig > index bdd302274b9a..9506a455b547 100644 > --- a/drivers/platform/x86/Kconfig > +++ b/drivers/platform/x86/Kconfig > @@ -1001,6 +1001,18 @@ config INSPUR_PLATFORM_PROFILE > To compile this driver as a module, choose M here: the module > will be called inspur-platform-profile. > > +config LENOVO_WMI_CAMERA > + tristate "Lenovo WMI Camera Button driver" > + depends on ACPI_WMI > + depends on INPUT > + help > + This driver provides support for Lenovo camera button. The Camera > + button is a GPIO device. This driver receives ACPI notify when the > + camera button is switched on/off. > + > + To compile this driver as a module, choose M here: the module > + will be called lenovo-wmi-camera. > + > source "drivers/platform/x86/x86-android-tablets/Kconfig" > > config FW_ATTR_CLASS > diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile > index 1de432e8861e..217e94d7c877 100644 > --- a/drivers/platform/x86/Makefile > +++ b/drivers/platform/x86/Makefile > @@ -66,6 +66,7 @@ obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o > obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o > obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o > obj-$(CONFIG_YOGABOOK) += lenovo-yogabook.o > +obj-$(CONFIG_LENOVO_WMI_CAMERA) += lenovo-wmi-camera.o > > # Intel > obj-y += intel/ > diff --git a/drivers/platform/x86/lenovo-wmi-camera.c b/drivers/platform/x86/lenovo-wmi-camera.c > new file mode 100644 > index 000000000000..571d67ade8ac > --- /dev/null > +++ b/drivers/platform/x86/lenovo-wmi-camera.c > @@ -0,0 +1,89 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Lenovo WMI Camera Button Driver > + * > + * Author: Ai Chao <aichao@xxxxxxxxxx> > + * Copyright (C) 2024 KylinSoft Corporation. > + */ > + > +#include <linux/acpi.h> > +#include <linux/device.h> > +#include <linux/input.h> > +#include <linux/module.h> > +#include <linux/wmi.h> > + > +#define WMI_LENOVO_CAMERABUTTON_EVENT_GUID "50C76F1F-D8E4-D895-0A3D-62F4EA400013" > + > +struct lenovo_wmi_priv { > + struct input_dev *idev; > + struct device *dev; > +}; > + > +enum { > + SW_CAMERA_OFF = 0, > + SW_CAMERA_ON = 1, > +}; > + > +static void lenovo_wmi_notify(struct wmi_device *wdev, union acpi_object *obj) > +{ > + struct lenovo_wmi_priv *priv = dev_get_drvdata(&wdev->dev); > + > + if (obj->type == ACPI_TYPE_BUFFER && > + obj->buffer.pointer[0] <= SW_CAMERA_ON) { > + /* obj->buffer.pointer[0] is camera mode: > + * 0 camera close > + * 1 camera open > + */ > + input_report_switch(priv->idev, SW_CAMERA_LENS_COVER, > + obj->buffer.pointer[0]); > + input_sync(priv->idev); > + } else { > + dev_dbg(&wdev->dev, "Bad response type %d\n", obj->type); This message seems to assume camera mode is on the valid range. Wouldn't it be useful from debugging point of view to show also the camera mode value? -- i.