Received: by 2002:a05:7208:13ce:b0:7f:395a:35b6 with SMTP id r14csp296977rbe; Wed, 28 Feb 2024 22:47:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVQbGzGLsYKYL51FAUOsKbReBi5s9GlVxAiTn+eMq1JKRk+0AWvWZs0jXr7847q+9pkOWgX9cw/IezYU3bZpMska6Gp1FcVzeVq0CQ5oA== X-Google-Smtp-Source: AGHT+IFvKBOj8s/Z+mgrafweDACW9PNm3yfjLjBMcTJrg9MXB1aUbEoWyOyTP0QVZsYDoNsuZFdH X-Received: by 2002:a05:6a20:7b24:b0:19e:9c5e:ad80 with SMTP id s36-20020a056a207b2400b0019e9c5ead80mr1222901pzh.62.1709189252476; Wed, 28 Feb 2024 22:47:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709189252; cv=pass; d=google.com; s=arc-20160816; b=w/Se9O2Dto5l0Z5+ztMTN/g3WWlC3tqrSCzXFSi82xKWlbOJ7Vt3nOEx6jcU8f66Et TktbWzWS1Ciin3zNKR0hNX1Z5DJQ8fq+1KE4SlcpcMDZNZBcMn2By2ab4IRiy2nx+eQi jUtSH/3ojfpSDO8UleHyTqoZMefHIyY1GiBkldmC6mH+cuI25F0T5MUnK4tuOo/ihgha KQoubYWdCotlAenfoqMtQAQybSJ83sMDzuBWgG9EgUSlqQ/MP9WgsS8BK+xanobfjjB9 VDijp9j5EF/j9wi6eGf3tAfSUHKv9ZUO8qb894W0r113/CpONwaaW/x4rXpInZsObox0 jmvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=3mP6yul9Z5X7rw+fsj9FO7rl8rYfKgs1VoP7KdOF0zc=; fh=cw5BG+JiafwTHCR6tk0R5//5dIlYqWsmn/fIQe0yVfE=; b=r6d/3sSYeoqocjqy5eu3dpjFUN+1x6VyfK8z3l2vjVnN97DJKOn8elLsV6wPhkVLVo 3xtTfKDD47lsIiegEbkZDyAaTuPme0YkEOuqtV4FyFKBBVaFxHdP7sRWANeEadgTTgr8 fmdqPS50s9TIS4LRr+aBD+DspnQ7DG8oyA73OH73AvjXGt/uqc2e4PQmj2ujSlDKgyw5 PLupGdIh57GpsLRiyvY0y3RHSqjAM/JuqCsSu9fnIbvlaFkM+uR6OqAVktobjzgw9cCu /LNNBizLcRfh5h8Wu8PUQxdejDK3738HSfBZBDuIpmPySilTHkO0NVSFPB4MflpHQllH lkJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ijlTkJMd; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-86192-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86192-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m12-20020a170902f20c00b001d9607d5cc5si686351plc.244.2024.02.28.22.47.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 22:47:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86192-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ijlTkJMd; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-86192-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86192-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2C705282602 for ; Thu, 29 Feb 2024 06:47:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 21F5D3DB86; Thu, 29 Feb 2024 06:46:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ijlTkJMd" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 64E3F4438E; Thu, 29 Feb 2024 06:46:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709189192; cv=none; b=HCe7e9LAlJPRzhH9e1HhXej36ZH+2/hNR5x2zupAS+WfLaFbC/ELRBZdMW1ApmnXDGt4ORvjDDLlqzdqnLrT7QAzqGjmiEIJcQ9QU+7arAJRIznQMevtiv88zJnTGcaBNSmoeYmvyxKnImLQRWyxkThrvfBh1Md0o27yLyvo0B4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709189192; c=relaxed/simple; bh=wLx74cxDos7PYxlETX7eEY2HrA5tgmRwY2rfBPbGBKY=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=JoNvCL+ODPuPBFcjOovMMpGt7YeDbacerCKZuBHR8i5Ntq14jo25147vgvzgIm2AlGSXM2hIHvEtiV35kpNWPt5eLwKGTEUcVQmn5AfiqwHYFNT2v6PemT7yVuV94IRey4AVN5UFCTH/XJMSZfDTSpRY3wmwuWbC52U5CZf6o/o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ijlTkJMd; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709189191; x=1740725191; h=message-id:date:mime-version:subject:to:references:from: in-reply-to:content-transfer-encoding; bh=wLx74cxDos7PYxlETX7eEY2HrA5tgmRwY2rfBPbGBKY=; b=ijlTkJMdCXXDTweWCRLMWaulA24FhzPsV2AfZ4JIO4DIKTKhZ4OGQvcH 2SxllLDZXuwzmU7qlPa+mdCu/wVntVy5eqzGo8wY4F4kmmWHStxMCNMVK wq39TTM7KAY9CRNQ6aJCmZi8J16sMEqnG+BXJWQld8fNbcpA5AWgLxQbg fiEnUFLYdmLkh+6mdqQAZGTsNTknHdslCSfy6dUzYtiu06nh9cGLAAO9g 3fYkMarkWnkWjSRW4DKlD3FJvV2SegxNPtq1ZwWhpciSTd3jskTHb5BX5 2HMsmwafnBePzq2810KLUAEr8lvC8xyB7OTA391GEDfgoC/VpEfpfryqZ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="3486504" X-IronPort-AV: E=Sophos;i="6.06,192,1705392000"; d="scan'208";a="3486504" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 22:46:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,192,1705392000"; d="scan'208";a="12373836" Received: from smitpat1-mobl.amr.corp.intel.com (HELO [10.209.30.182]) ([10.209.30.182]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 22:46:30 -0800 Message-ID: Date: Wed, 28 Feb 2024 22:46:29 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] platform/x86: add lenovo generic wmi driver Content-Language: en-US To: Ai Chao , hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org References: <20240229051621.12341-1-aichao@kylinos.cn> From: Kuppuswamy Sathyanarayanan In-Reply-To: <20240229051621.12341-1-aichao@kylinos.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2/28/24 9:16 PM, Ai Chao wrote: > Add lenovo generic wmi driver to support camera button. > > Signed-off-by: Ai Chao > --- > drivers/platform/x86/Kconfig | 10 +++ > drivers/platform/x86/Makefile | 1 + > drivers/platform/x86/lenovo-wmi.c | 121 ++++++++++++++++++++++++++++++ > 3 files changed, 132 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..e8b1c401b53e > --- /dev/null > +++ b/drivers/platform/x86/lenovo-wmi.c > @@ -0,0 +1,121 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Lenovo Generic WMI Driver > + * > + * Copyright (C) 2018 Ai Chao 2024 ? > + */ > + > +#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 sprintf(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_info(&wdev->dev, "Bad response type %d\n", obj->type); Does it needs to be dev_info? I don't think this affects the driver functionality, right? May be dev_dbg() is better here? > + } > +} > + > +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 void lenovo_wmi_remove(struct wmi_device *wdev) > +{ > + struct lenovo_wmi_priv *priv = dev_get_drvdata(&wdev->dev); > + > + input_unregister_device(priv->idev); Since you use devm_input_allocate_device() for allocation, you don't need to explicitly unregister the device. > +} > + > +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, > + .remove = lenovo_wmi_remove, > +}; > + > +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 v2"); -- Sathyanarayanan Kuppuswamy Linux Kernel Developer