Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp146674lqg; Fri, 1 Mar 2024 00:22:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXMzQ3H9wanZJo4UFf3PDbB3o5MMKUjWQAg40wR53crOP5A86XqyNswR+9/nA9lozuygc/UnTFZB/Ck+sEWataIiV+NuS3IkdSp/LCncw== X-Google-Smtp-Source: AGHT+IH+B0035AmpuBTGAFtIRwS7+Kua2QFRsaa2kylOYg2I4tng/PteiVwch3mwoshPW+PQUDsM X-Received: by 2002:a05:6214:80d:b0:68f:2de1:7251 with SMTP id df13-20020a056214080d00b0068f2de17251mr1080962qvb.41.1709281374725; Fri, 01 Mar 2024 00:22:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709281374; cv=pass; d=google.com; s=arc-20160816; b=dkj09c1DC+bdjAGnOcc5wqyeZ2YXrd+phUWCd3h28ZwNgoZVOO4f/1mU3BsFDiqTf9 11brU9lN1NocBC6bWZISkaaqaNy8+EMyFGK3jdlUUezEJVx5FvomRsEBTOMfTuw+Mu2z OrcyHVWq71ckPSDeeP8pEIqdqURqSHJbEaY14xvA+WA5yeajso2zNOlORTNqtqAbVIRn Ca5j8BeetVrRkdrU9DKGSG7fpRLOIipU1dQN4Nkh9mtXzOmzMnPbzWi9HosPjw52zTgD L80qN27IvPtmtLT2TPNtj1qgkpazraU1WuYKOrQDIEnQ9Tf3k+/ig2jr/YdW7CuFPPn4 CEaQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=6PWwkx53G5XiFcJwOhvstFdyqYxYcfUbAYAJfdswJ4o=; fh=ULOkH4cNbWy8SYo1NTJpdHa3Y5+dTFAKqrmAgsGj+0E=; b=d1699dVAgStK89JvyiwCUK/bkdMHUBgKa+n/4xKxq8pYQ27Px68d+BbdHzoiM/M5YW NJXse3yNsB3dimqI0Jw96ZU6jHqb5HfJ93Wyoo4IZTtlvWbd/5y2jV5v8XyMV3ul0pUo rrSSGSR+eMBsUUjVVifiXhGnuaQ6V3EhBuHVXlw4CJYyltgsX+8YXPIONT5EHzBkYWPs bW685NASYQM5y5yIDKzg85FXC0I3P0KC5o2EYHYHANCuscs8K/MesEMueRt+JYkGJ16W 6hGwCRkYOhf41IwPDmATPYghfmvW5RA2SG1UlRDwt4XuwSBiW+HeQWJQe/zs4qRkXNkv 9Slw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-88066-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88066-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id gm15-20020a056214268f00b0068f99d0cb5esi3232806qvb.569.2024.03.01.00.22.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 00:22:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88066-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-88066-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88066-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6973F1C23A05 for ; Fri, 1 Mar 2024 08:22:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA5DB69D38; Fri, 1 Mar 2024 08:22:26 +0000 (UTC) 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 53BEA69E0A; Fri, 1 Mar 2024 08:22:20 +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=1709281346; cv=none; b=tPAneZkb5ybP0AV9N6+/gKaMzY9igl6au9OLlSFJgPb5O5AquzUIBYlwGpUyTPc0y+1O6cRqS/n5YAZhElike7Cc86pkQLMM5gODqfRtgy6mPW6tQfeAfJmEpqMmjAKwE4TKnAj62XZ1eMYNvbA2jaOK1aJKAF8Muo0vGGx0DEc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709281346; c=relaxed/simple; bh=h6FtoEcIUz3yIkRmQPdlDZucxbkkGkvHrXaGeCM1nEs=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=k0dT4sj6uLgn36zIrqiX/bEyA0ogPU8YeEHhXTOW36d3RYfIcDbkK28lzUZUozySwevOkcwLr88lD8ZuXGQYQmATarPAXQO7f9uBEiYAF7ywkO13wgpWf88TVxuKrXdkQ31zkhtCvMz4j8gr//A3MSqm0muYYQmgawS76vNyXEg= 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: 05f06a440549480886f5d1928f357437-20240301 X-CID-O-RULE: Release_Ham X-CID-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.37,REQID:3aa1627a-5245-4c43-a2b5-b2ef66fe2ba0,IP:10, URL:0,TC:0,Content:-25,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,AC TION:release,TS:-30 X-CID-INFO: VERSION:1.1.37,REQID:3aa1627a-5245-4c43-a2b5-b2ef66fe2ba0,IP:10,UR L:0,TC:0,Content:-25,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:-30 X-CID-META: VersionHash:6f543d0,CLOUDID:c9637e84-8d4f-477b-89d2-1e3bdbef96d1,B ulkID:2403011616558IO7NRVB,BulkQuantity:0,Recheck:0,SF:66|38|24|17|19|44|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,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: 05f06a440549480886f5d1928f357437-20240301 X-User: aichao@kylinos.cn Received: from localhost.localdomain [(112.64.161.44)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 1055854772; Fri, 01 Mar 2024 16:16:55 +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 v3] platform/x86: add lenovo generic wmi driver Date: Fri, 1 Mar 2024 16:16:48 +0800 Message-Id: <20240301081648.265907-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: 8bit Add lenovo generic wmi driver to support camera button. Signed-off-by: Ai Chao --- v2: Adjust GPL v2 to GPL, adjust sprintf to sysfs_emit. v3: Remove lenovo_wmi_remove function. drivers/platform/x86/Kconfig | 10 +++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/lenovo-wmi.c | 113 ++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 drivers/platform/x86/lenovo-wmi.c diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index bdd302274b9a..fbbb8fb843d7 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -1001,6 +1001,16 @@ 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 + tristate "Lenovo Geneirc WMI driver" + depends on ACPI_WMI + depends on INPUT + help + This driver provides support for Lenovo WMI driver. + + To compile this driver as a module, choose M here: the module + will be called lenovo-wmi. + 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..d51086552192 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) += lenovo-wmi.o # Intel obj-y += intel/ diff --git a/drivers/platform/x86/lenovo-wmi.c b/drivers/platform/x86/lenovo-wmi.c new file mode 100644 index 000000000000..96c2ec9e6441 --- /dev/null +++ b/drivers/platform/x86/lenovo-wmi.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Lenovo Generic WMI Driver + * + * Copyright (C) 2024 Ai Chao + */ + +#include +#include +#include +#include +#include + +#define WMI_LENOVO_CAMERABUTTON_EVENT_GUID "50C76F1F-D8E4-D895-0A3D-62F4EA400013" + +static u8 camera_mode; + +struct lenovo_wmi_priv { + struct input_dev *idev; +}; + +static ssize_t camerabutton_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%u\n", camera_mode); +} + +DEVICE_ATTR_RO(camerabutton); + +static struct attribute *lenovo_wmi_attrs[] = { + &dev_attr_camerabutton.attr, + NULL, +}; + +static const struct attribute_group lenovo_wmi_group = { + .attrs = lenovo_wmi_attrs, +}; + +const struct attribute_group *lenovo_wmi_groups[] = { + &lenovo_wmi_group, + NULL, +}; + +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) { + camera_mode = obj->buffer.pointer[0]; + input_report_key(priv->idev, KEY_CAMERA, 1); + input_sync(priv->idev); + input_report_key(priv->idev, KEY_CAMERA, 0); + input_sync(priv->idev); + } else { + dev_dbg(&wdev->dev, "Bad response type %d\n", obj->type); + } +} + +static int lenovo_wmi_input_setup(struct wmi_device *wdev) +{ + struct lenovo_wmi_priv *priv = dev_get_drvdata(&wdev->dev); + + 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; + priv->idev->evbit[0] = BIT_MASK(EV_KEY); + priv->idev->keybit[BIT_WORD(KEY_CAMERA)] = BIT_MASK(KEY_CAMERA); + + return input_register_device(priv->idev); +} + +static int lenovo_wmi_probe(struct wmi_device *wdev, const void *context) +{ + struct lenovo_wmi_priv *priv; + int err; + + priv = devm_kzalloc(&wdev->dev, sizeof(struct lenovo_wmi_priv), + GFP_KERNEL); + if (!priv) + return -ENOMEM; + + dev_set_drvdata(&wdev->dev, priv); + + err = lenovo_wmi_input_setup(wdev); + return err; +} + +static const struct wmi_device_id lenovo_wmi_id_table[] = { + { .guid_string = WMI_LENOVO_CAMERABUTTON_EVENT_GUID }, + { } +}; + +static struct wmi_driver lenovo_wmi_driver = { + .driver = { + .name = "lenovo-wmi", + .dev_groups = lenovo_wmi_groups, + }, + .id_table = lenovo_wmi_id_table, + .probe = lenovo_wmi_probe, + .notify = lenovo_wmi_notify, +}; + +module_wmi_driver(lenovo_wmi_driver); + +MODULE_DEVICE_TABLE(wmi, lenovo_wmi_id_table); +MODULE_AUTHOR("Ai Chao "); +MODULE_DESCRIPTION("Lenovo Generic WMI Driver"); +MODULE_LICENSE("GPL"); -- 2.25.1