Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1434890lqe; Mon, 8 Apr 2024 08:49:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWsaBeH4BLShBJ+Izy9fO9Gfa0IHllxHTvocGCF7tG8FySgfPdSnpxN0r1VI2keiaEhacXEY+mmGdYM99KKhkqA8xWyBvTPC8468k0NPw== X-Google-Smtp-Source: AGHT+IFgx749q1f7A/RMh8zKAo/mf3z8k7H6oW40csB2EDSki/utTJDLEOJtPjNjlcs2ymzvtI7j X-Received: by 2002:a50:cc95:0:b0:56c:2ef7:f3e6 with SMTP id q21-20020a50cc95000000b0056c2ef7f3e6mr6962168edi.0.1712591348760; Mon, 08 Apr 2024 08:49:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712591348; cv=pass; d=google.com; s=arc-20160816; b=O3fPtsc/AWrluEjW54+mGb8MDOyYcyIMoyoFu23jmRrt6RQdwQAb6X0KFE+8jS2ShK ADmhin+uGFHghnnSNOHDEL1mk4M2BUkl/HcAK0JWtH1ZTx+/QC1OpOotRwWCGyR8RK5b RLnMEHoZ0y7pdn2fj/IqpTZlz7L137ufRwMX4beijfd19o01oEmV0mPJeyvS26Z/PhIm N4YEc3SD/NFADK30d7VD2OdWgP7PzxjME6Y0Sq8lAVPx4FFHmiTMv2/JrlV3ndwpI7Jd y2EMJkpNnJCLbNshGwtMzzRElHl8T3XndTPyNLkpuwZNxsdvWZx8BYl9RozybIFoRHDz A1AA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:in-reply-to:subject:cc:to:date:from :dkim-signature; bh=CgXjADGZT4YjeucTJa6ZrnwfKPUqRBiM2oZfgP86NOs=; fh=6/znY0nXGP6WHz3CoBez6J9zBiPJq7OcLdURo5sJCwA=; b=n8SEnZMpfwVPl0uo5VpGKubiRiKnMzWM53jLH1e5NawZjWdqDd7aijJLSsCh1znDp2 ZIfIwQ52lneoGlC1f0O2BTGdEIQoNhjJGj3wp+6tTLYGVtOur6wLVZsfRIvWsgSJ3vwZ 449p/0Yu/QyIVte4QS23j/hHHIH4arUbn9KZRgwaFqI25Mj0EU1oY66C8f8bALCA200p f13Y0I1u85xgrODJK0T5ZW05L9dbKYOojLfo+X72Ph0NUitI/wMX9unpOKuWza4tloDE pUMUBYtV68Mvb3CuhGDWW7oFruGuVFKfPWjj5EWQuhDROg/XT11A7xGuawBfzP6HckvK AtVQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MHxhKh0z; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-135622-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135622-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c102-20020a509fef000000b0056e3df67505si2969820edf.507.2024.04.08.08.49.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 08:49:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135622-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MHxhKh0z; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-135622-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135622-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 54B971F2227C for ; Mon, 8 Apr 2024 15:49:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0D4021420DA; Mon, 8 Apr 2024 15:49:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MHxhKh0z" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (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 92E7E24B4A; Mon, 8 Apr 2024 15:48:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.21 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712591339; cv=none; b=ddK+070MhuFz7TnkFSnyHVawm5ZRaTqLILYariFVBXtQGc4pfAsdrEtP2hcOQ6rD2nSQqsV8klU6V4uX2iX2k3ed+W40sUI4uvVMqPRzFnTStTXxpxKrrDPTn5NKSExGEdfPiQWYhGi6bziJoWuIgKMJVcqhSbfXZ8B1EIgfrDw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712591339; c=relaxed/simple; bh=dlrWxy8aJzTsV8Kbg8Ki+bRRBgvk5NN8dk84yVKvFEM=; h=From:Date:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=LyHnNLBbeeONm8yUC2Wgunk2Q/7Qpz2lUK308V2X8A543mklazeFTtlnOFEv/ixjDui+Rcs9cuoIH+0OSOQfpAg0y1/8vyvn+rk41/4fkhB53vFRKhRkKbE2wmCTLpE7sQdmc5kDEFfIO1PN/SlQr7cQPvn4vmuHxqB1HguqgWI= 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=MHxhKh0z; arc=none smtp.client-ip=198.175.65.21 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=1712591338; x=1744127338; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=dlrWxy8aJzTsV8Kbg8Ki+bRRBgvk5NN8dk84yVKvFEM=; b=MHxhKh0zm1Ct93u78IGekqLoklszzT9SeR2Bw81mLCacwpsmUaa2pUNk qwzRqI15g6cbDRWyoPsLDFjJZpaDrIpRSgEYDMheK9wazVAmomDVEUmPB g6CWuC1kVk8vgSeGyrk5/mbxj6eL3hwCXQSoj4CVzTOxy6SyRB9AkrNGn 2Y4Yourd/wCgKXs2U9JhwUfUKo3yAPliNmsyIKa/ehFfLuHUlCUqvjW0J 0CwRGiykpfXs4gODcpJUrK3oJKIXxCmOlw6sRRb5vOsnH78gY567FVLYM UV4hcgcidB+V1F/3AAgq/5j5eC51Pfj/9MtSWDmlnHp8OhHsvdl84Fi2k g==; X-CSE-ConnectionGUID: 8OAKcLehRd+lYPzh8Cx06Q== X-CSE-MsgGUID: IeSv79j2T0avpiuiExMFdQ== X-IronPort-AV: E=McAfee;i="6600,9927,11038"; a="7784184" X-IronPort-AV: E=Sophos;i="6.07,187,1708416000"; d="scan'208";a="7784184" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 08:48:57 -0700 X-CSE-ConnectionGUID: DlHRz7zkT1yaH6fwH1SsAg== X-CSE-MsgGUID: SjTrHBcKSoSpKirqcqtjmQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,187,1708416000"; d="scan'208";a="51103101" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.28]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 08:48:53 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Mon, 8 Apr 2024 18:48:50 +0300 (EEST) To: Armin Wolf cc: mlj@danelec.com, rafael.j.wysocki@intel.com, lenb@kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: Re: [PATCH] ACPI: fan: Add hwmon support In-Reply-To: <20240408123718.15512-1-W_Armin@gmx.de> Message-ID: <63187b48-7978-3b0f-0526-79afea65c492@linux.intel.com> References: <20240408123718.15512-1-W_Armin@gmx.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII On Mon, 8 Apr 2024, Armin Wolf wrote: > Currently, the driver does only supports a custom sysfs > interface to allow userspace to read the fan speed. > Add support for the standard hwmon interface so users > can read the fan speed with standard tools like "sensors". > > Signed-off-by: Armin Wolf > --- > drivers/acpi/Makefile | 1 + > drivers/acpi/fan.h | 2 ++ > drivers/acpi/fan_core.c | 7 ++++ > drivers/acpi/fan_hwmon.c | 78 ++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 88 insertions(+) > create mode 100644 drivers/acpi/fan_hwmon.c > > diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile > index d69d5444acdb..9a2e03acc1be 100644 > --- a/drivers/acpi/Makefile > +++ b/drivers/acpi/Makefile > @@ -83,6 +83,7 @@ obj-$(CONFIG_ACPI_TINY_POWER_BUTTON) += tiny-power-button.o > obj-$(CONFIG_ACPI_FAN) += fan.o > fan-objs := fan_core.o > fan-objs += fan_attr.o > +fan-objs += fan_hwmon.o > > obj-$(CONFIG_ACPI_VIDEO) += video.o > obj-$(CONFIG_ACPI_TAD) += acpi_tad.o > diff --git a/drivers/acpi/fan.h b/drivers/acpi/fan.h > index e7b4b4e4a55e..45c2637566da 100644 > --- a/drivers/acpi/fan.h > +++ b/drivers/acpi/fan.h > @@ -56,4 +56,6 @@ struct acpi_fan { > int acpi_fan_get_fst(struct acpi_device *device, struct acpi_fan_fst *fst); > int acpi_fan_create_attributes(struct acpi_device *device); > void acpi_fan_delete_attributes(struct acpi_device *device); > + > +int devm_acpi_fan_create_hwmon(struct acpi_device *device); > #endif > diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c > index ff72e4ef8738..6bbdbb914e95 100644 > --- a/drivers/acpi/fan_core.c > +++ b/drivers/acpi/fan_core.c > @@ -7,6 +7,7 @@ > * Copyright (C) 2022 Intel Corporation. All rights reserved. > */ > > +#include > #include > #include > #include > @@ -336,6 +337,12 @@ static int acpi_fan_probe(struct platform_device *pdev) > if (result) > return result; > > + if (IS_REACHABLE(CONFIG_HWMON)) { > + result = devm_acpi_fan_create_hwmon(device); > + if (result) > + return result; > + } > + > result = acpi_fan_create_attributes(device); > if (result) > return result; > diff --git a/drivers/acpi/fan_hwmon.c b/drivers/acpi/fan_hwmon.c > new file mode 100644 > index 000000000000..4f2bec8664f4 > --- /dev/null > +++ b/drivers/acpi/fan_hwmon.c > @@ -0,0 +1,78 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * fan_hwmon.c - hwmon interface for the ACPI Fan driver > + * > + * Copyright (C) 2024 Armin Wolf > + */ > + > +#include > +#include > +#include > + > +#include "fan.h" > + > +static umode_t acpi_fan_is_visible(const void *drvdata, enum hwmon_sensor_types type, u32 attr, > + int channel) > +{ > + return 0444; > +} > + > +static int acpi_fan_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, > + long *val) > +{ > + struct acpi_device *adev = dev_get_drvdata(dev); > + struct acpi_fan_fst fst; > + int ret; > + > + switch (type) { > + case hwmon_fan: > + ret = acpi_fan_get_fst(adev, &fst); > + if (ret < 0) > + return ret; > + > + switch (attr) { > + case hwmon_fan_input: > + if (fst.speed > LONG_MAX) > + return -EOVERFLOW; > + > + *val = fst.speed; > + return 0; > + case hwmon_fan_fault: > + *val = (fst.speed == U32_MAX); > + return 0; Is it okay to return 0 in this case? > + default: > + break; > + } > + break; > + default: > + break; > + } > + > + return -EOPNOTSUPP; > +} > + > +static const struct hwmon_ops acpi_fan_ops = { > + .is_visible = acpi_fan_is_visible, > + .read = acpi_fan_read, > +}; > + > +static const struct hwmon_channel_info * const acpi_fan_info[] = { > + HWMON_CHANNEL_INFO(fan, > + HWMON_F_INPUT | HWMON_F_FAULT), One line. -- i. > + NULL > +}; > + > +static const struct hwmon_chip_info acpi_fan_chip_info = { > + .ops = &acpi_fan_ops, > + .info = acpi_fan_info, > +}; > + > +int devm_acpi_fan_create_hwmon(struct acpi_device *device) > +{ > + struct device *hdev; > + > + hdev = devm_hwmon_device_register_with_info(&device->dev, "acpi_fan", device, > + &acpi_fan_chip_info, NULL); > + > + return PTR_ERR_OR_ZERO(hdev); > +} > -- > 2.39.2 > >