From patchwork Mon Aug 14 17:00:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Cox X-Patchwork-Id: 1821066 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=XrCr593/; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RPghG3ly5z1yg6 for ; Tue, 15 Aug 2023 03:03:08 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qVay1-0004NH-Bc; Mon, 14 Aug 2023 17:02:57 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qVaxz-0004Mn-Ca for kernel-team@lists.ubuntu.com; Mon, 14 Aug 2023 17:02:55 +0000 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 3BB1C3F03D for ; Mon, 14 Aug 2023 17:02:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1692032575; bh=AQ461zzvhnHp0TkdlH/nNfztqeqnripOGI+djgTsvlE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XrCr593/5f19edcrSKpm1katJIlSvCC3dGrmRbexLNHD0mucZJYJBKFRuKj08+4cK be9PgrQ/LuYLJPso1yVTqYLUTxv32OPSIPptUMphdbykTqXzyFRP+awgWOHBaDXqER /FjhEJu8fVieH9fhPe6BeUmuRhc8ieQjn21X6SO8U4wZdM92qGL8BipFDgs+cvgiAe CauNZt3aXSfhKE7SVo9Bpw6jadPHXNevDfG/imA2dXwGvo1EBePUHYP/b9yzXv96Gc 217imtA5Tsg7Zjpb9/RsosJBTes/2iLJ8PCrz31N0n1pyFt1KeXFfM9hbmuSoOBls9 pCPW7BghLzUXw== Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-63ccbef84eeso44834786d6.3 for ; Mon, 14 Aug 2023 10:02:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692032572; x=1692637372; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AQ461zzvhnHp0TkdlH/nNfztqeqnripOGI+djgTsvlE=; b=QvA35jlB2tntpaB0Yi/J/QXBvv9D65yfdNPnTaWNDiR1E2I2uJi+B/GFDDPXac6sgr GrhCSyAOmEpW+iEFcWIo+fB1obkHSG/0ZbHj15I4fV7DkTiWyGl8XDMR30Wr3ZV7ACd9 UQobK+6vAUEtmy0N/UVMbSQrk7M7q/dTEb+OaaiDIN6KA+tuvY0FOGRxrP71DpacHRK5 GyXmMAtAq8vw7UrCC7TJrsOGeWUYlBQC7XvdZbt/D3B+YGOrPhvvgHvgIYSiJ6+Mz8BZ bKJcF1SQyMPW6SHzfIli88U6BY5w+M27M08xd/e/7+voI50L63uxwAxHtMgbBAwxbB/l chfg== X-Gm-Message-State: AOJu0YwnC54wTJMKJamorGddJo/UYC4651BBvoaWcxWwRBQPnJbTotiN H7Mj4lxzZFYgDoQwR7x9ka4/yK9o5V5qjqNXK+jBZzCZo8Knbr+r6+EC2qJ8xZhv3fCVpFnCxp3 MwC3lpSSRY0Gx4DAwjSOp/qrt7jVCtEIC9v4OS0PofBtOedDL4A== X-Received: by 2002:a05:6214:1647:b0:63c:f548:7788 with SMTP id f7-20020a056214164700b0063cf5487788mr10570808qvw.55.1692032572546; Mon, 14 Aug 2023 10:02:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IErvUOoCt+qUS2VsnO/p1I9u1R4JJTseRSNJqmpFWvV4CnFwiktrAS6jgH2xAfq6UaRdN/s4w== X-Received: by 2002:a05:6214:1647:b0:63c:f548:7788 with SMTP id f7-20020a056214164700b0063cf5487788mr10570785qvw.55.1692032572206; Mon, 14 Aug 2023 10:02:52 -0700 (PDT) Received: from cox.conference ([216.154.1.93]) by smtp.gmail.com with ESMTPSA id z11-20020a0cf00b000000b0063d09326fa4sm3522004qvk.31.2023.08.14.10.02.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 10:02:49 -0700 (PDT) From: Philip Cox To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/4] ACPI: fan: Separate file for attributes creation Date: Mon, 14 Aug 2023 13:00:08 -0400 Message-Id: <20230814170011.178935-2-philip.cox@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230814170011.178935-1-philip.cox@canonical.com> References: <20230814170011.178935-1-philip.cox@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Srinivas Pandruvada BugLink: https://bugs.launchpad.net/bugs/2031333 Move the functionality of creation of sysfs attributes under acpi device to a new file fan_attr.c. This cleans up the core fan code, which just use thermal sysfs interface. The original fan.c is renamed to fan_core.c. No functional changes are expected. Signed-off-by: Srinivas Pandruvada Signed-off-by: Rafael J. Wysocki (cherry picked from commit 00ae053a0533155d830da27070a931e6fa747327) Signed-off-by: Philip Cox --- drivers/acpi/Makefile | 3 + drivers/acpi/fan.h | 35 +++++++++++ drivers/acpi/fan_attr.c | 86 ++++++++++++++++++++++++++ drivers/acpi/{fan.c => fan_core.c} | 98 +++--------------------------- 4 files changed, 133 insertions(+), 89 deletions(-) create mode 100644 drivers/acpi/fan_attr.c rename drivers/acpi/{fan.c => fan_core.c} (80%) diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 3018714e87d9..d257beabe6e1 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -80,6 +80,9 @@ obj-$(CONFIG_ACPI_AC) += ac.o obj-$(CONFIG_ACPI_BUTTON) += button.o 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 + obj-$(CONFIG_ACPI_VIDEO) += video.o obj-$(CONFIG_ACPI_TAD) += acpi_tad.o obj-$(CONFIG_ACPI_PCI_SLOT) += pci_slot.o diff --git a/drivers/acpi/fan.h b/drivers/acpi/fan.h index dc9a6efa514b..e5582aff08cb 100644 --- a/drivers/acpi/fan.h +++ b/drivers/acpi/fan.h @@ -6,8 +6,43 @@ * * Add new device IDs before the generic ACPI fan one. */ + +#ifndef _ACPI_FAN_H_ +#define _ACPI_FAN_H_ + #define ACPI_FAN_DEVICE_IDS \ {"INT3404", }, /* Fan */ \ {"INTC1044", }, /* Fan for Tiger Lake generation */ \ {"INTC1048", }, /* Fan for Alder Lake generation */ \ {"PNP0C0B", } /* Generic ACPI fan */ + +#define ACPI_FPS_NAME_LEN 20 + +struct acpi_fan_fps { + u64 control; + u64 trip_point; + u64 speed; + u64 noise_level; + u64 power; + char name[ACPI_FPS_NAME_LEN]; + struct device_attribute dev_attr; +}; + +struct acpi_fan_fif { + u64 revision; + u64 fine_grain_ctrl; + u64 step_size; + u64 low_speed_notification; +}; + +struct acpi_fan { + bool acpi4; + struct acpi_fan_fif fif; + struct acpi_fan_fps *fps; + int fps_count; + struct thermal_cooling_device *cdev; +}; + +int acpi_fan_create_attributes(struct acpi_device *device); +void acpi_fan_delete_attributes(struct acpi_device *device); +#endif diff --git a/drivers/acpi/fan_attr.c b/drivers/acpi/fan_attr.c new file mode 100644 index 000000000000..7b109022108b --- /dev/null +++ b/drivers/acpi/fan_attr.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * fan_attr.c - Create extra attributes for ACPI Fan driver + * + * Copyright (C) 2001, 2002 Andy Grover + * Copyright (C) 2001, 2002 Paul Diefenbaugh + * Copyright (C) 2022 Intel Corporation. All rights reserved. + */ + +#include +#include +#include +#include + +#include "fan.h" + +MODULE_LICENSE("GPL"); + +static ssize_t show_state(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct acpi_fan_fps *fps = container_of(attr, struct acpi_fan_fps, dev_attr); + int count; + + if (fps->control == 0xFFFFFFFF || fps->control > 100) + count = scnprintf(buf, PAGE_SIZE, "not-defined:"); + else + count = scnprintf(buf, PAGE_SIZE, "%lld:", fps->control); + + if (fps->trip_point == 0xFFFFFFFF || fps->trip_point > 9) + count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:"); + else + count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->trip_point); + + if (fps->speed == 0xFFFFFFFF) + count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:"); + else + count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->speed); + + if (fps->noise_level == 0xFFFFFFFF) + count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:"); + else + count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->noise_level * 100); + + if (fps->power == 0xFFFFFFFF) + count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined\n"); + else + count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld\n", fps->power); + + return count; +} + +int acpi_fan_create_attributes(struct acpi_device *device) +{ + struct acpi_fan *fan = acpi_driver_data(device); + int i, status = 0; + + for (i = 0; i < fan->fps_count; ++i) { + struct acpi_fan_fps *fps = &fan->fps[i]; + + snprintf(fps->name, ACPI_FPS_NAME_LEN, "state%d", i); + sysfs_attr_init(&fps->dev_attr.attr); + fps->dev_attr.show = show_state; + fps->dev_attr.store = NULL; + fps->dev_attr.attr.name = fps->name; + fps->dev_attr.attr.mode = 0444; + status = sysfs_create_file(&device->dev.kobj, &fps->dev_attr.attr); + if (status) { + int j; + + for (j = 0; j < i; ++j) + sysfs_remove_file(&device->dev.kobj, &fan->fps[j].dev_attr.attr); + break; + } + } + + return status; +} + +void acpi_fan_delete_attributes(struct acpi_device *device) +{ + struct acpi_fan *fan = acpi_driver_data(device); + int i; + + for (i = 0; i < fan->fps_count; ++i) + sysfs_remove_file(&device->dev.kobj, &fan->fps[i].dev_attr.attr); +} diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan_core.c similarity index 80% rename from drivers/acpi/fan.c rename to drivers/acpi/fan_core.c index 5cd0ceb50bc8..77f427fe4409 100644 --- a/drivers/acpi/fan.c +++ b/drivers/acpi/fan_core.c @@ -1,9 +1,10 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * acpi_fan.c - ACPI Fan Driver ($Revision: 29 $) + * fan_core.c - ACPI Fan core Driver * * Copyright (C) 2001, 2002 Andy Grover * Copyright (C) 2001, 2002 Paul Diefenbaugh + * Copyright (C) 2022 Intel Corporation. All rights reserved. */ #include @@ -45,33 +46,6 @@ static const struct dev_pm_ops acpi_fan_pm = { #define FAN_PM_OPS_PTR NULL #endif -#define ACPI_FPS_NAME_LEN 20 - -struct acpi_fan_fps { - u64 control; - u64 trip_point; - u64 speed; - u64 noise_level; - u64 power; - char name[ACPI_FPS_NAME_LEN]; - struct device_attribute dev_attr; -}; - -struct acpi_fan_fif { - u64 revision; - u64 fine_grain_ctrl; - u64 step_size; - u64 low_speed_notification; -}; - -struct acpi_fan { - bool acpi4; - struct acpi_fan_fif fif; - struct acpi_fan_fps *fps; - int fps_count; - struct thermal_cooling_device *cdev; -}; - static struct platform_driver acpi_fan_driver = { .probe = acpi_fan_probe, .remove = acpi_fan_remove, @@ -270,39 +244,6 @@ static int acpi_fan_speed_cmp(const void *a, const void *b) return fps1->speed - fps2->speed; } -static ssize_t show_state(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct acpi_fan_fps *fps = container_of(attr, struct acpi_fan_fps, dev_attr); - int count; - - if (fps->control == 0xFFFFFFFF || fps->control > 100) - count = scnprintf(buf, PAGE_SIZE, "not-defined:"); - else - count = scnprintf(buf, PAGE_SIZE, "%lld:", fps->control); - - if (fps->trip_point == 0xFFFFFFFF || fps->trip_point > 9) - count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:"); - else - count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->trip_point); - - if (fps->speed == 0xFFFFFFFF) - count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:"); - else - count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->speed); - - if (fps->noise_level == 0xFFFFFFFF) - count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:"); - else - count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->noise_level * 100); - - if (fps->power == 0xFFFFFFFF) - count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined\n"); - else - count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld\n", fps->power); - - return count; -} - static int acpi_fan_get_fps(struct acpi_device *device) { struct acpi_fan *fan = acpi_driver_data(device); @@ -347,25 +288,6 @@ static int acpi_fan_get_fps(struct acpi_device *device) sort(fan->fps, fan->fps_count, sizeof(*fan->fps), acpi_fan_speed_cmp, NULL); - for (i = 0; i < fan->fps_count; ++i) { - struct acpi_fan_fps *fps = &fan->fps[i]; - - snprintf(fps->name, ACPI_FPS_NAME_LEN, "state%d", i); - sysfs_attr_init(&fps->dev_attr.attr); - fps->dev_attr.show = show_state; - fps->dev_attr.store = NULL; - fps->dev_attr.attr.name = fps->name; - fps->dev_attr.attr.mode = 0444; - status = sysfs_create_file(&device->dev.kobj, &fps->dev_attr.attr); - if (status) { - int j; - - for (j = 0; j < i; ++j) - sysfs_remove_file(&device->dev.kobj, &fan->fps[j].dev_attr.attr); - break; - } - } - err: kfree(obj); return status; @@ -396,6 +318,10 @@ static int acpi_fan_probe(struct platform_device *pdev) if (result) return result; + result = acpi_fan_create_attributes(device); + if (result) + return result; + fan->acpi4 = true; } else { result = acpi_device_update_power(device, NULL); @@ -437,12 +363,8 @@ static int acpi_fan_probe(struct platform_device *pdev) return 0; err_end: - if (fan->acpi4) { - int i; - - for (i = 0; i < fan->fps_count; ++i) - sysfs_remove_file(&device->dev.kobj, &fan->fps[i].dev_attr.attr); - } + if (fan->acpi4) + acpi_fan_delete_attributes(device); return result; } @@ -453,10 +375,8 @@ static int acpi_fan_remove(struct platform_device *pdev) if (fan->acpi4) { struct acpi_device *device = ACPI_COMPANION(&pdev->dev); - int i; - for (i = 0; i < fan->fps_count; ++i) - sysfs_remove_file(&device->dev.kobj, &fan->fps[i].dev_attr.attr); + acpi_fan_delete_attributes(device); } sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling"); sysfs_remove_link(&fan->cdev->device.kobj, "device"); From patchwork Mon Aug 14 17:00:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Cox X-Patchwork-Id: 1821064 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=IY+89lom; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RPghG35wQz1yf2 for ; Tue, 15 Aug 2023 03:03:08 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qVay3-0004Nk-HT; Mon, 14 Aug 2023 17:02:59 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qVay0-0004N9-VE for kernel-team@lists.ubuntu.com; Mon, 14 Aug 2023 17:02:56 +0000 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id B482E3F03D for ; Mon, 14 Aug 2023 17:02:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1692032576; bh=Rl7gzapdTSASkrtwKHUzhATZc/I2YnWgv8wrIc1fxOI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IY+89lommaIOXcEjz0Y+TRvyQKnwKnxHrFJ2MXKZ9O2kkhy0WB5HoqKhUplrg1seQ 79XREj67kQ/aWkyQV86FIN3tZImlUnOwxTch9ZhCyXImOEJ+7HaaG9GTlqDBD+j25P l+eBIM2pYtnjsLsI9eBNp6CoNnIXnuQbgqyKsg4IF0FDBydZcO7cvjEnIL459fcf+s 9GVbnvyDAcW26EgGoUFAvUTU4CxlwCByIgtagoOdIrsKRHSdQMx3TB5djQL2b7lKuV GUHy7dY/zRjx7bAl7w31nbwLpDqIOHVzGhg3bC78EwWfjwoEZLDzoOIDd6m9aTEzJv ldWWNZOXFxeTQ== Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-76cf1561a8dso345318285a.1 for ; Mon, 14 Aug 2023 10:02:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692032575; x=1692637375; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Rl7gzapdTSASkrtwKHUzhATZc/I2YnWgv8wrIc1fxOI=; b=LSVOEJ/UQ7d1Mu+HgtNqKv1r7RqB2tA+QbyVGRCLSWTg+daAKRTW9WRhvQLwGZYHUW SSYH0lmtnBpQTR0JVTQNxTqwTSQaV18FrAhF1M7YvxM0hSXdByExyKPSkBJTewGJ6yit CANx1PmvJ3RxS3vyT+xtPXSZjxM3AkyQxT7dxTartJw5yyQQt12j0/Czig6vMm5H+MvL ZudO9nWlawEq9Xlx4vJ/s4RDnkP7y2sR8W93eFaCK16j1mjHeNmiH4F2d65INFJ5AqGs Ne4jPOTekMjIxM2nsKaL2ZBXScSC3q+H4/WNPcPkHgCsBWyaQfao0ZSkviiKxGngdYFD ZtHg== X-Gm-Message-State: AOJu0YxsrAvgvZHsJ34uZLDYtDxRAZycK8PjjKp3YgNevv1bPbYwHWjT NpdcX5bNlJY5kU5c913WAjHuHaJNAqTA6jeeR9agOD5yyUc+2NwBVc8JZnl/sExn1ywT+DlYPdX P8sio+qwqvHuaLJE8YO1iB+5gOo4qucFhunwF0TNwCWzOr8q4zQ== X-Received: by 2002:a05:620a:450e:b0:767:f178:b571 with SMTP id t14-20020a05620a450e00b00767f178b571mr16511640qkp.10.1692032575143; Mon, 14 Aug 2023 10:02:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHOew/WtJqld7p+CoFP/XoMqzcGhQsYYb1w/E2nNoJyt+M3T81X5xIzF3eRRgsss56WEtCC/g== X-Received: by 2002:a05:620a:450e:b0:767:f178:b571 with SMTP id t14-20020a05620a450e00b00767f178b571mr16511611qkp.10.1692032574841; Mon, 14 Aug 2023 10:02:54 -0700 (PDT) Received: from cox.conference ([216.154.1.93]) by smtp.gmail.com with ESMTPSA id z11-20020a0cf00b000000b0063d09326fa4sm3522004qvk.31.2023.08.14.10.02.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 10:02:52 -0700 (PDT) From: Philip Cox To: kernel-team@lists.ubuntu.com Subject: [PATCH 2/4] ACPI: fan: Optimize struct acpi_fan_fif Date: Mon, 14 Aug 2023 13:00:09 -0400 Message-Id: <20230814170011.178935-3-philip.cox@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230814170011.178935-1-philip.cox@canonical.com> References: <20230814170011.178935-1-philip.cox@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Srinivas Pandruvada BugLink: https://bugs.launchpad.net/bugs/2031333 We don't need u64 to store the information about _FIF. There are two booleans (fine_grain_ctrl and low_speed_notification) and one field step_size which can take value from 1-9. There are no internal users of revision field. So convert all fields to u8, by not directly extracting the _FIF info the struct. Use an intermediate buffer to extract and assign. This will help to do u32 math using these fields. No functional changes are expected. Signed-off-by: Srinivas Pandruvada Signed-off-by: Rafael J. Wysocki (cherry picked from commit d445571fa369cf08148dcd9bce563d5fae14fcd7) Signed-off-by: Philip Cox --- drivers/acpi/fan.h | 8 ++++---- drivers/acpi/fan_core.c | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/fan.h b/drivers/acpi/fan.h index e5582aff08cb..ce42a6c7130e 100644 --- a/drivers/acpi/fan.h +++ b/drivers/acpi/fan.h @@ -29,10 +29,10 @@ struct acpi_fan_fps { }; struct acpi_fan_fif { - u64 revision; - u64 fine_grain_ctrl; - u64 step_size; - u64 low_speed_notification; + u8 revision; + u8 fine_grain_ctrl; + u8 step_size; + u8 low_speed_notification; }; struct acpi_fan { diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c index 77f427fe4409..ec4229fd5c4b 100644 --- a/drivers/acpi/fan_core.c +++ b/drivers/acpi/fan_core.c @@ -211,7 +211,8 @@ static int acpi_fan_get_fif(struct acpi_device *device) struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; struct acpi_fan *fan = acpi_driver_data(device); struct acpi_buffer format = { sizeof("NNNN"), "NNNN" }; - struct acpi_buffer fif = { sizeof(fan->fif), &fan->fif }; + u64 fields[4]; + struct acpi_buffer fif = { sizeof(fields), fields }; union acpi_object *obj; acpi_status status; @@ -232,6 +233,11 @@ static int acpi_fan_get_fif(struct acpi_device *device) status = -EINVAL; } + fan->fif.revision = fields[0]; + fan->fif.fine_grain_ctrl = fields[1]; + fan->fif.step_size = fields[2]; + fan->fif.low_speed_notification = fields[3]; + err: kfree(obj); return status; From patchwork Mon Aug 14 17:00:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Cox X-Patchwork-Id: 1821067 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=b06fJBMs; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RPghG3F8xz1yfg for ; Tue, 15 Aug 2023 03:03:09 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qVay6-0004QO-TC; Mon, 14 Aug 2023 17:03:02 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qVay4-0004OP-KE for kernel-team@lists.ubuntu.com; Mon, 14 Aug 2023 17:03:00 +0000 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 58F4A3F03D for ; Mon, 14 Aug 2023 17:03:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1692032580; bh=cOvLQ2jxONgv+Fac89BXQo6gYT83WjwJV5HQkABlUWM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b06fJBMs/aMxtu5dc2MVQ7bAQ013t201yd3MrPM9ggcdxrRGkcol6UEYz+batpMpR Ttq8/5U5G7tAF73WpGvsGs2yNkUwbnLIIDcD0pRP7x4Loedh7DTj8ICVQFiOrk22HI K9AyBUkYCccYo50AuZCaFGAoFUOjpxaPzISvPR5N51o24NvY5B0QNB8110GboZTOpO Mpy5IWujjvj2D3XwW+cElStcjZLukeNkLwyAyL6fXzaxqPsakoXDsG1G62+GPzy+tc gmqi7r/wooGB51OIvFEaWjSE9qNT1Q+pN69fzqRwnyuraWkEBp5heXMrc6iq1MnxfY 42GlU4M+WYtHA== Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-76d256338d3so719570085a.1 for ; Mon, 14 Aug 2023 10:03:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692032578; x=1692637378; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cOvLQ2jxONgv+Fac89BXQo6gYT83WjwJV5HQkABlUWM=; b=CGiqgdDsKBWasvBxC+sgukvYM2xIXtlfH2lryiMIKfC/4cTWM3XiU6WjoNGDozvpZG na43ADTQ5MitMxv/+1XxwyDQk4KyFhYW82AmZf09YmPc4zpyOsRWol9Ya1GTpLB6dQb9 5KYlIwZgll7J7xKjgjrG7mzHP89pQKQOq0Whs6RNaCWUlOImRW5U6kbrtbx3ssSC/7HG shzRicoWwtbLJ2MBSXLEfuEv391KFeW53JMjvqu8v+dQoL3kgREvAwm6eHLxaW96FGsE nhIRSGbIv3VJIuzcofY/K832L/oQ9bHLHyWcQnjSJhOdzqUoEpG9b5KZ7vfwTp8NHBGZ LpRg== X-Gm-Message-State: AOJu0YwinC2wswONPzuzjYPU/L0z1LNVFG0GYwrN4O7nZaWdfRhpVnbP 3C9ELBsOcGVOtZ+niAv2+btG9y5W5F1ZSCNfVcelLVsr6Hj86JUT7AZos+x0y2fwyb0OkXGUR19 UcQyvoeKXiRVvPBP3642GZh+2+pzPUBoY3gmi09VCTBJh40x9zQ== X-Received: by 2002:a0c:ca0a:0:b0:641:e7a9:274f with SMTP id c10-20020a0cca0a000000b00641e7a9274fmr11243607qvk.3.1692032577919; Mon, 14 Aug 2023 10:02:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IECwFTZra80QwEgLVNNZorb9/uJxdapZ2WU5IrIX6JHdYKTASAvrzJMMwggh/30s3kRtp3xSQ== X-Received: by 2002:a0c:ca0a:0:b0:641:e7a9:274f with SMTP id c10-20020a0cca0a000000b00641e7a9274fmr11243586qvk.3.1692032577599; Mon, 14 Aug 2023 10:02:57 -0700 (PDT) Received: from cox.conference ([216.154.1.93]) by smtp.gmail.com with ESMTPSA id z11-20020a0cf00b000000b0063d09326fa4sm3522004qvk.31.2023.08.14.10.02.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 10:02:55 -0700 (PDT) From: Philip Cox To: kernel-team@lists.ubuntu.com Subject: [PATCH 3/4] ACPI: fan: Properly handle fine grain control Date: Mon, 14 Aug 2023 13:00:10 -0400 Message-Id: <20230814170011.178935-4-philip.cox@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230814170011.178935-1-philip.cox@canonical.com> References: <20230814170011.178935-1-philip.cox@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Srinivas Pandruvada BugLink: https://bugs.launchpad.net/bugs/2031333 When _FIF object specifies support for fine grain control, then fan speed can be set from 0 to 100% with the recommended minimum "step size" via _FSL object. Here the control value doesn't need to match any value from _FPS object. Currently we have a simple solution implemented which just pick maximum control value from _FPS to display the actual state, but this is not optimal when there is a big window between two control values in _FPS. Also there is no way to set to any speed which doesn't match control values in _FPS. The system firmware can start the fan at speed which doesn't match any control value. To support fine grain control (when supported) via thermal sysfs: - cooling device max state is not _FPS state count but it will be 100 / _FIF.step_size Step size can be from 1 to 9. - cooling device current state is _FST.control / _FIF.step_size - cooling device set state will set the control value cdev.curr_state * _FIF.step_size plus any adjustment for 100%. By the spec, when control value do not sum to 100% because of _FIF.step_size, OSPM may select an appropriate ending Level increment to reach 100%. There is no rounding during calculation. For example if step size is 6: thermal sysfs cooling device max_state = 100/6 = 16 So user can set any value from 0-16. If the system boots with a _FST.control which is not multiples of step_size, the thermal sysfs cur_state will be based on the range. For example for step size = 6: _FST.control thermal sysfs cur_state ------------------------------------------------ 0-5 0 6-11 1 .. .. 90-95 15 96-100 16 While setting the _FST.control, the compensation will be at the last step for cur_state = 16, which will set the _FST.control to 100. Signed-off-by: Srinivas Pandruvada Signed-off-by: Rafael J. Wysocki (cherry picked from commit bea2d9868ef553e376480de3cd84a7a06fb03e41) Signed-off-by: Philip Cox --- drivers/acpi/fan.h | 6 +++ drivers/acpi/fan_core.c | 94 +++++++++++++++++++++++++++++------------ 2 files changed, 74 insertions(+), 26 deletions(-) diff --git a/drivers/acpi/fan.h b/drivers/acpi/fan.h index ce42a6c7130e..02799ca87343 100644 --- a/drivers/acpi/fan.h +++ b/drivers/acpi/fan.h @@ -35,6 +35,12 @@ struct acpi_fan_fif { u8 low_speed_notification; }; +struct acpi_fan_fst { + u64 revision; + u64 control; + u64 speed; +}; + struct acpi_fan { bool acpi4; struct acpi_fan_fif fif; diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c index ec4229fd5c4b..c51a1ec8b3bb 100644 --- a/drivers/acpi/fan_core.c +++ b/drivers/acpi/fan_core.c @@ -63,20 +63,24 @@ static int fan_get_max_state(struct thermal_cooling_device *cdev, unsigned long struct acpi_device *device = cdev->devdata; struct acpi_fan *fan = acpi_driver_data(device); - if (fan->acpi4) - *state = fan->fps_count - 1; - else + if (fan->acpi4) { + if (fan->fif.fine_grain_ctrl) + *state = 100 / fan->fif.step_size; + else + *state = fan->fps_count - 1; + } else { *state = 1; + } + return 0; } -static int fan_get_state_acpi4(struct acpi_device *device, unsigned long *state) +static int acpi_fan_get_fst(struct acpi_device *device, struct acpi_fan_fst *fst) { struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; - struct acpi_fan *fan = acpi_driver_data(device); union acpi_object *obj; acpi_status status; - int control, i; + int ret = 0; status = acpi_evaluate_object(device->handle, "_FST", NULL, &buffer); if (ACPI_FAILURE(status)) { @@ -89,35 +93,52 @@ static int fan_get_state_acpi4(struct acpi_device *device, unsigned long *state) obj->package.count != 3 || obj->package.elements[1].type != ACPI_TYPE_INTEGER) { dev_err(&device->dev, "Invalid _FST data\n"); - status = -EINVAL; + ret = -EINVAL; goto err; } - control = obj->package.elements[1].integer.value; + fst->revision = obj->package.elements[0].integer.value; + fst->control = obj->package.elements[1].integer.value; + fst->speed = obj->package.elements[2].integer.value; + +err: + kfree(obj); + return ret; +} + +static int fan_get_state_acpi4(struct acpi_device *device, unsigned long *state) +{ + struct acpi_fan *fan = acpi_driver_data(device); + struct acpi_fan_fst fst; + int status, i; + + status = acpi_fan_get_fst(device, &fst); + if (status) + return status; + + if (fan->fif.fine_grain_ctrl) { + /* This control should be same what we set using _FSL by spec */ + if (fst.control > 100) { + dev_dbg(&device->dev, "Invalid control value returned\n"); + goto match_fps; + } + + *state = (int) fst.control / fan->fif.step_size; + return 0; + } + +match_fps: for (i = 0; i < fan->fps_count; i++) { - /* - * When Fine Grain Control is set, return the state - * corresponding to maximum fan->fps[i].control - * value compared to the current speed. Here the - * fan->fps[] is sorted array with increasing speed. - */ - if (fan->fif.fine_grain_ctrl && control < fan->fps[i].control) { - i = (i > 0) ? i - 1 : 0; - break; - } else if (control == fan->fps[i].control) { + if (fst.control == fan->fps[i].control) break; - } } if (i == fan->fps_count) { dev_dbg(&device->dev, "Invalid control value returned\n"); - status = -EINVAL; - goto err; + return -EINVAL; } *state = i; -err: - kfree(obj); return status; } @@ -161,12 +182,27 @@ static int fan_set_state_acpi4(struct acpi_device *device, unsigned long state) { struct acpi_fan *fan = acpi_driver_data(device); acpi_status status; + u64 value = state; + int max_state; - if (state >= fan->fps_count) + if (fan->fif.fine_grain_ctrl) + max_state = 100 / fan->fif.step_size; + else + max_state = fan->fps_count - 1; + + if (state > max_state) return -EINVAL; - status = acpi_execute_simple_method(device->handle, "_FSL", - fan->fps[state].control); + if (fan->fif.fine_grain_ctrl) { + value *= fan->fif.step_size; + /* Spec allows compensate the last step only */ + if (value + fan->fif.step_size > 100) + value = 100; + } else { + value = fan->fps[state].control; + } + + status = acpi_execute_simple_method(device->handle, "_FSL", value); if (ACPI_FAILURE(status)) { dev_dbg(&device->dev, "Failed to set state by _FSL\n"); return status; @@ -238,6 +274,12 @@ static int acpi_fan_get_fif(struct acpi_device *device) fan->fif.step_size = fields[2]; fan->fif.low_speed_notification = fields[3]; + /* If there is a bug in step size and set as 0, change to 1 */ + if (!fan->fif.step_size) + fan->fif.step_size = 1; + /* If step size > 9, change to 9 (by spec valid values 1-9) */ + else if (fan->fif.step_size > 9) + fan->fif.step_size = 9; err: kfree(obj); return status; From patchwork Mon Aug 14 17:00:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Cox X-Patchwork-Id: 1821068 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=nB6Pbapa; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RPghJ1yBFz20GJ for ; Tue, 15 Aug 2023 03:03:11 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qVay9-0004U4-L2; Mon, 14 Aug 2023 17:03:05 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qVay6-0004Py-Lt for kernel-team@lists.ubuntu.com; Mon, 14 Aug 2023 17:03:02 +0000 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 633ED3F03D for ; Mon, 14 Aug 2023 17:03:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1692032582; bh=h3Bk4NdJzIRTOXXk6/00JaFRcpW1o5MqemFtC2NMooc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nB6PbapaEhJad3Z4/J5drLxFgTL3yM97jW7RGLF9+Ni3WRwM542WHgFurHMNjqhF+ 1hv0p/vV5Z7iVRW1Nb2DxCB8IOuGLVdBhl8rAGt6Z5+yTvzcIZnP9AARy/WA7WQedY 9QAre8z4MArPYqDXd8d8Sr2iA/8895Vwy7H6VKzG7B6gjjO7i2OSfflG1Odne4r4Zn bkDVn0XZQavjIeV69Z80i9dDCBFNH8Yic4L+SNyMWX2wDhc0TA5nyKBh7it0S3pTFf ASmzODMrzKRCln3pGxb3bhZetCHlW2XKl2YM2Jbrxn2LFrLqfs063H+BQDVKgn7IyX Ew8fpS/NuqR8A== Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6468e19af74so28178146d6.0 for ; Mon, 14 Aug 2023 10:03:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692032580; x=1692637380; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h3Bk4NdJzIRTOXXk6/00JaFRcpW1o5MqemFtC2NMooc=; b=EAVw+RcrAHKcKWjhiWSsvVxTrM/JySLsCxiC3BxsgoC8bR+OQi+9WcBwspFWKsndvR Qkgv0FmGw8ujEAtYfXziDMfw7m/qrhiw2Krzmx87/ZHcJZEIGn9slu1YnqqRIUQAYTyN 88+1ZsfKfNigJoKO5cDLzRCcjnEWNqkhTjn2qhlT3E6tguToMS0Yc6vgMnV2enOd91uA g3Qvy4v9vHDpOrmT8WWlATm7MAkxyZH+u8gq9kWfstDCAAz72CYOvWBerm0FxaVHYTJA VqFhnCwKW1ETqailX2yMFlJPUr1UHqJsZ56pVNXFsj3NiLOOGzsB16fKd/4ZXFBv6+Ec EoLA== X-Gm-Message-State: AOJu0Yz7oQga61N1uFWmFbMTTZ5mlKZoWsCksXcgYlnrcmaDsQEzw4dC OSxmv0t0Sj5qmHuy7p7jSe5X8BaWZZBMk1grzXuPXnxM3u1pMXWYQe8X0BaICGXfW0CAO5pZI08 4TBf7H88FAFaI5db2tDRj8Ld93g5LjaDPDEYM1c2CiG+9yTCqcQ== X-Received: by 2002:a0c:a9d8:0:b0:63d:6138:1027 with SMTP id c24-20020a0ca9d8000000b0063d61381027mr10184493qvb.42.1692032580600; Mon, 14 Aug 2023 10:03:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzxbcDEOuo0MH3Qd47vqlb9QcXLYm2BD2F9ocneDeNv8BfBNHG808vWv6GDFw4w6u4gNfy6A== X-Received: by 2002:a0c:a9d8:0:b0:63d:6138:1027 with SMTP id c24-20020a0ca9d8000000b0063d61381027mr10184474qvb.42.1692032580291; Mon, 14 Aug 2023 10:03:00 -0700 (PDT) Received: from cox.conference ([216.154.1.93]) by smtp.gmail.com with ESMTPSA id z11-20020a0cf00b000000b0063d09326fa4sm3522004qvk.31.2023.08.14.10.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 10:02:58 -0700 (PDT) From: Philip Cox To: kernel-team@lists.ubuntu.com Subject: [PATCH 4/4] ACPI: fan: Add additional attributes for fine grain control Date: Mon, 14 Aug 2023 13:00:11 -0400 Message-Id: <20230814170011.178935-5-philip.cox@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230814170011.178935-1-philip.cox@canonical.com> References: <20230814170011.178935-1-philip.cox@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Srinivas Pandruvada BugLink: https://bugs.launchpad.net/bugs/2031333 Add additional attributes, which helps in implementing algorithm in the user space to optimize fan control. These attributes are presented in the same directory as the existing performance state attributes. Additional attributes: 1. Support of fine grain control Publish support of presence of fine grain control so that fan speed can be tuned correctly. This attribute is called "fine_grain_control". 2. fan speed Publish the actual fan rpm in sysfs. Knowing fan rpm is helpful to reduce noise level and use passive control instead. Also fan performance may not be same over time, so the same control value may not be enough to run the fan at a speed. So a feedback value of speed is helpful. This sysfs attribute is called "fan_speed_rpm". Signed-off-by: Srinivas Pandruvada Signed-off-by: Rafael J. Wysocki (cherry picked from commit f1197343f07749035d74c08cf8b546c4f95614ab) Signed-off-by: Philip Cox --- drivers/acpi/fan.h | 3 +++ drivers/acpi/fan_attr.c | 55 +++++++++++++++++++++++++++++++++++++++-- drivers/acpi/fan_core.c | 2 +- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/fan.h b/drivers/acpi/fan.h index 02799ca87343..fc47ceea312a 100644 --- a/drivers/acpi/fan.h +++ b/drivers/acpi/fan.h @@ -47,8 +47,11 @@ struct acpi_fan { struct acpi_fan_fps *fps; int fps_count; struct thermal_cooling_device *cdev; + struct device_attribute fst_speed; + struct device_attribute fine_grain_control; }; +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); #endif diff --git a/drivers/acpi/fan_attr.c b/drivers/acpi/fan_attr.c index 7b109022108b..f15157d40713 100644 --- a/drivers/acpi/fan_attr.c +++ b/drivers/acpi/fan_attr.c @@ -49,10 +49,50 @@ static ssize_t show_state(struct device *dev, struct device_attribute *attr, cha return count; } +static ssize_t show_fan_speed(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct acpi_device *acpi_dev = container_of(dev, struct acpi_device, dev); + struct acpi_fan_fst fst; + int status; + + status = acpi_fan_get_fst(acpi_dev, &fst); + if (status) + return status; + + return sprintf(buf, "%lld\n", fst.speed); +} + +static ssize_t show_fine_grain_control(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct acpi_device *acpi_dev = container_of(dev, struct acpi_device, dev); + struct acpi_fan *fan = acpi_driver_data(acpi_dev); + + return sprintf(buf, "%d\n", fan->fif.fine_grain_ctrl); +} + int acpi_fan_create_attributes(struct acpi_device *device) { struct acpi_fan *fan = acpi_driver_data(device); - int i, status = 0; + int i, status; + + sysfs_attr_init(&fan->fine_grain_control.attr); + fan->fine_grain_control.show = show_fine_grain_control; + fan->fine_grain_control.store = NULL; + fan->fine_grain_control.attr.name = "fine_grain_control"; + fan->fine_grain_control.attr.mode = 0444; + status = sysfs_create_file(&device->dev.kobj, &fan->fine_grain_control.attr); + if (status) + return status; + + /* _FST is present if we are here */ + sysfs_attr_init(&fan->fst_speed.attr); + fan->fst_speed.show = show_fan_speed; + fan->fst_speed.store = NULL; + fan->fst_speed.attr.name = "fan_speed_rpm"; + fan->fst_speed.attr.mode = 0444; + status = sysfs_create_file(&device->dev.kobj, &fan->fst_speed.attr); + if (status) + goto rem_fine_grain_attr; for (i = 0; i < fan->fps_count; ++i) { struct acpi_fan_fps *fps = &fan->fps[i]; @@ -69,10 +109,18 @@ int acpi_fan_create_attributes(struct acpi_device *device) for (j = 0; j < i; ++j) sysfs_remove_file(&device->dev.kobj, &fan->fps[j].dev_attr.attr); - break; + goto rem_fst_attr; } } + return 0; + +rem_fst_attr: + sysfs_remove_file(&device->dev.kobj, &fan->fst_speed.attr); + +rem_fine_grain_attr: + sysfs_remove_file(&device->dev.kobj, &fan->fine_grain_control.attr); + return status; } @@ -83,4 +131,7 @@ void acpi_fan_delete_attributes(struct acpi_device *device) for (i = 0; i < fan->fps_count; ++i) sysfs_remove_file(&device->dev.kobj, &fan->fps[i].dev_attr.attr); + + sysfs_remove_file(&device->dev.kobj, &fan->fst_speed.attr); + sysfs_remove_file(&device->dev.kobj, &fan->fine_grain_control.attr); } diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c index c51a1ec8b3bb..f7b7d512ec9a 100644 --- a/drivers/acpi/fan_core.c +++ b/drivers/acpi/fan_core.c @@ -75,7 +75,7 @@ static int fan_get_max_state(struct thermal_cooling_device *cdev, unsigned long return 0; } -static int acpi_fan_get_fst(struct acpi_device *device, struct acpi_fan_fst *fst) +int acpi_fan_get_fst(struct acpi_device *device, struct acpi_fan_fst *fst) { struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; union acpi_object *obj;