Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp433376lqi; Thu, 7 Mar 2024 01:21:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXEz9C40xPPoeCfTu/r25Lz0vmFnFyTWS0homyzqJpgK8Z66yUMAYMXtPQU4Ujook98OS3oAdwe5ZPTtMj7lqiV0qSQZsDb2U74YxwCng== X-Google-Smtp-Source: AGHT+IGPc0h3nharuyOh2BUn43PfgDrVt2m8DdPC3HiWIySc3qFyNbTlUlaKbMUGR8hL8q03/H7s X-Received: by 2002:a05:620a:3951:b0:788:23ac:f936 with SMTP id qs17-20020a05620a395100b0078823acf936mr10329192qkn.57.1709803295574; Thu, 07 Mar 2024 01:21:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709803295; cv=pass; d=google.com; s=arc-20160816; b=nYPdLthzUXHeqdGPLkLNGaZudU6HrDUcxYDUtnLwt4AJD5XolYe52tGWeownL4sFq8 iU7OVhrAThBHklIWnDfYpwF1+h1loe6bfPjfpU9XfZW7gptTutqPVfttYKO5s5ruw2wk jgl39R2TU15PVC+clmPU3oDtqWd04v1WKsj/gUqenhuSCWH+QaJ945w9oCTHRjRHLflO u4EBUu7xEnDvRcDbMpIcUQqbFQdYuJzrq1DBMRd9625ztFRn01FVG9wpbTki2Z6pL0h9 bH7s8E+GT2YaOchDV+ZY7th2JgvM/djm0XU4bsFl/U9V9Jab2dZzD39ewT5/0t1b6Vni vuyg== 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=bcfYGATV5GoJSkOiWDV9QojUC2H2vkvgHjSxZmDt1/4=; fh=ULOkH4cNbWy8SYo1NTJpdHa3Y5+dTFAKqrmAgsGj+0E=; b=oORXZg2xxqwjmAtIghU2qDMtzuvuiHLS2hj9pkdmkUDrIbpd/Sr9/y2LhghXaTh7y+ IRSFsHf7kdi4Ghd+X8NNgaRC/+ZmpAWEgnw4+6GHxb321BXhsH7MgeMqQWPcSq156WcF UQI0V7zfqvlhcvks1ilM8kiuDBDCBaMiQc3q4u5eLGrlcHMvobaJ6vpLBlLJVKu3cudI ED6po/KsXJceWeZEdebGjrp7bBF+dt7JR7MuNDDSEJ1EsqM1f43C33xK6ADYfffxWR5N hwDc8L72ker40pWzTxJ0G5JotLRGE52CWTbsVAcnlH8fLzOS4dukORmRu7sdviG03WKV S8QA==; 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-95208-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95208-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 bj14-20020a05620a190e00b00787f3723dcesi18421142qkb.619.2024.03.07.01.21.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 01:21:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-95208-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-95208-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95208-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 ED6911C23D58 for ; Thu, 7 Mar 2024 09:21:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C3E183A06; Thu, 7 Mar 2024 09:21:05 +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 DC5BD823BF; Thu, 7 Mar 2024 09:21:00 +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=1709803264; cv=none; b=RpU/040Oj73pvxEZrTDEqrVctJaj1K8SKO9NUTqP1J/tVbLRCDFZJ7V9XBKmRtGPmjp+R+bKJDscNV7bfme/ry+mULwpGXIwnGbS/GGz++S52PRaNo1WZ0qC88hbd3hmW8qEK6egJJ7HFyFN+cgCzGD4mKjcmemdHUipob1poxc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709803264; c=relaxed/simple; bh=r3/myK4/ZpKNlUkLE94ZeTlMFLlsx33jDPOvRo6U2a8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=NDQ9JQl6QOzd09D76QXsCZi/L7petlNHcnazrtMS4H6Pb3kk+rSVtBN7PRkGXM0/IxbTeRmoykbnTRaUZfsl7VsSN6JJY9iE6GtwCNNfi4BW5Bjo/keiTVc8dbSaCCu/grLgesgqvzVN52xCK8VGrvxEI4JI65y9RtBF7i8SItM= 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: 3607b475cb7d4278aab10ffaaee8bd0e-20240307 X-CID-O-RULE: Release_Ham X-CID-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.37,REQID:e8ea706b-495e-4725-a2f2-38442837f5a6,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:e8ea706b-495e-4725-a2f2-38442837f5a6,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:d65a9eff-c16b-4159-a099-3b9d0558e447,B ulkID:240307163618P7UYFQLJ,BulkQuantity:1,Recheck:0,SF:24|17|19|44|66|38|1 02,TC:nil,Content:0,EDM:-3,IP:-2,URL:0,File:nil,RT:nil,Bulk:41,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_FSI,TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD X-UUID: 3607b475cb7d4278aab10ffaaee8bd0e-20240307 X-User: aichao@kylinos.cn Received: from localhost.localdomain [(112.64.161.44)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 1393049069; Thu, 07 Mar 2024 16:59:41 +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 wmi camera button driver Date: Thu, 7 Mar 2024 16:59:39 +0800 Message-Id: <20240307085939.668881-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. 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. +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 + * Copyright (C) 2024 KylinSoft Corporation. + */ + +#include +#include +#include +#include +#include + +#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); + } +} + +static int lenovo_wmi_probe(struct wmi_device *wdev, const void *context) +{ + struct lenovo_wmi_priv *priv; + + priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + 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_SW, SW_CAMERA_LENS_COVER); + + return input_register_device(priv->idev); +} + +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-camera", + .probe_type = PROBE_PREFER_ASYNCHRONOUS, + }, + .id_table = lenovo_wmi_id_table, + .no_singleton = true, + .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 WMI Camera Button Driver"); +MODULE_LICENSE("GPL"); -- 2.25.1