From nobody Sun Feb 8 15:08:32 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C57A839EC; Thu, 7 Mar 2024 09:19:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709803157; cv=none; b=fFdOyacq/lzOo5xEJJGHfKIVFnIuP93lUWu7ZHmqrXZJbDNgiOmh9D0JQS2gJBP/0lo5hJtcvgmwC4wnCyepegz4/RSpksZMmjMIZsikZqxVj3iHPJUVQTkIo7rT0aQdvMtG+MPUWwfUavGxoucy8vqicskGDYX3kR3F92RNtMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709803157; c=relaxed/simple; bh=r3/myK4/ZpKNlUkLE94ZeTlMFLlsx33jDPOvRo6U2a8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=MV7VwV5cJdbGT/HGrNUt+EQiDzik/EYm9z4jO9YSb1Uuv9/yqi8sia1axDFSeXv8lglrPgURDbrZjVu1AjBLeKQ2s8xROW0vrSK7m+uPL7rAIXjbbJHQqpoxC/Zs/SS2rpRkbTdZ/azrhir40OKqQaLqJ1nGDBwyyxHZcLkP12c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: eefd94a9bf34490995e7655ab0e53b93-20240307 X-CID-O-RULE: Release_Ham X-CID-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.37,REQID:4ca8a327-a5bd-4c4d-a334-cb7f32cbdad5,IP:20, URL:0,TC:0,Content:-25,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,AC TION:release,TS:-20 X-CID-INFO: VERSION:1.1.37,REQID:4ca8a327-a5bd-4c4d-a334-cb7f32cbdad5,IP:20,UR L:0,TC:0,Content:-25,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:-20 X-CID-META: VersionHash:6f543d0,CLOUDID:6e342090-e2c0-40b0-a8fe-7c7e47299109,B ulkID:240307163618P7UYFQLJ,BulkQuantity:0,Recheck:0,SF:17|19|44|66|38|24|1 02,TC:nil,Content:0,EDM:-3,IP:-2,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC :nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: eefd94a9bf34490995e7655ab0e53b93-20240307 X-User: aichao@kylinos.cn Received: from localhost.localdomain [(112.64.161.44)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 672017009; Thu, 07 Mar 2024 16:36:17 +0800 From: Ai Chao To: hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: Ai Chao Subject: [PATCH v5] platform/x86: add lenovo generic wmi driver Date: Wed, 28 Feb 2024 17:01:53 +0800 Message-Id: <20240228090153.572284-1-aichao@kylinos.cn> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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. =20 +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" =20 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) +=3D hdaps.o obj-$(CONFIG_THINKPAD_ACPI) +=3D thinkpad_acpi.o obj-$(CONFIG_THINKPAD_LMI) +=3D think-lmi.o obj-$(CONFIG_YOGABOOK) +=3D lenovo-yogabook.o +obj-$(CONFIG_LENOVO_WMI_CAMERA) +=3D lenovo-wmi-camera.o =20 # Intel obj-y +=3D intel/ diff --git a/drivers/platform/x86/lenovo-wmi-camera.c b/drivers/platform/x8= 6/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 + * Copyright (C) 2024 KylinSoft Corporation. + */ + +#include +#include +#include +#include +#include + +#define WMI_LENOVO_CAMERABUTTON_EVENT_GUID "50C76F1F-D8E4-D895-0A3D-62F4EA= 400013" + +struct lenovo_wmi_priv { + struct input_dev *idev; + struct device *dev; +}; + +enum { + SW_CAMERA_OFF =3D 0, + SW_CAMERA_ON =3D 1, +}; + +static void lenovo_wmi_notify(struct wmi_device *wdev, union acpi_object *= obj) +{ + struct lenovo_wmi_priv *priv =3D dev_get_drvdata(&wdev->dev); + + if (obj->type =3D=3D ACPI_TYPE_BUFFER && + obj->buffer.pointer[0] <=3D 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); + } +} + +static int lenovo_wmi_probe(struct wmi_device *wdev, const void *context) +{ + struct lenovo_wmi_priv *priv; + + priv =3D devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + dev_set_drvdata(&wdev->dev, priv); + + priv->idev =3D devm_input_allocate_device(&wdev->dev); + if (!priv->idev) + return -ENOMEM; + + priv->idev->name =3D "Lenovo WMI Camera Button"; + priv->idev->phys =3D "wmi/input0"; + priv->idev->id.bustype =3D BUS_HOST; + priv->idev->dev.parent =3D &wdev->dev; + input_set_capability(priv->idev, EV_SW, SW_CAMERA_LENS_COVER); + + return input_register_device(priv->idev); +} + +static const struct wmi_device_id lenovo_wmi_id_table[] =3D { + { .guid_string =3D WMI_LENOVO_CAMERABUTTON_EVENT_GUID }, + { } +}; + +static struct wmi_driver lenovo_wmi_driver =3D { + .driver =3D { + .name =3D "lenovo-wmi-camera", + .probe_type =3D PROBE_PREFER_ASYNCHRONOUS, + }, + .id_table =3D lenovo_wmi_id_table, + .no_singleton =3D true, + .probe =3D lenovo_wmi_probe, + .notify =3D lenovo_wmi_notify, +}; + +module_wmi_driver(lenovo_wmi_driver); + +MODULE_DEVICE_TABLE(wmi, lenovo_wmi_id_table); +MODULE_AUTHOR("Ai Chao "); +MODULE_DESCRIPTION("Lenovo WMI Camera Button Driver"); +MODULE_LICENSE("GPL"); --=20 2.25.1