From patchwork Mon Dec 12 20:58:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 32532 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2463499wrr; Mon, 12 Dec 2022 13:02:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf7WsCFXWz2r9NOKsc2Dh/ujqVdCYBBUhqWTi6JQKp5aZrYxPacVg45GlhIkIBtxE5ZK74mZ X-Received: by 2002:a17:906:a15a:b0:7ae:7c4e:195b with SMTP id bu26-20020a170906a15a00b007ae7c4e195bmr14491115ejb.22.1670878964760; Mon, 12 Dec 2022 13:02:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670878964; cv=none; d=google.com; s=arc-20160816; b=Mi1onECx+mi0qu1VrOn3rMS5eRUrfXOdoqc1MX8VLzlQBVuLqMnEE0hhlLmc7dMAXr 5cWiZZKxAqklDFltK8msUgwZ3qoeIvJoOfCpWH2fGHUywNxNSk7fHYBMDINzCYQiFUKO OtsAU4Va3yoDATwDkntsbjW8Ccrie0ewoHLZqKTVbfp/tqbC8cOWcWEBN56BMifWD2vH nd7AO2hLXmJcBWsUtZuF99RzdgsNOxfEVn3MDLhmuoHMA/6440q1foT36OLeAefNZOuT xjUpGe5VyA7OI8MSV6NOrLUe+M9aYNUolLOXCeCtR8tuoF4UOs5wBxhNttmaiGQUFpps as6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=t99/SFsMNtmGyI4mz9oW4N/Vb5nTNk7UReahhubAWF8=; b=jVht5CgWMgbJGMBxOo41wvnMj0C4tG4VXB1SaLDHKIAqItiPD5x5bCDEiac1ZSp3d+ lLENxKPtMd4IzwrU09BhgN5x488xbgPV92A/ktbtAvh8Oels/44LuA/CAdJ3TtGMXMOi XYpYSsOsDLQg+xY34TZhhMbS+OdTra07GaldEx8Aolvz8M4K1rJjLL4i/sXfM6/WuGLi JPS3RjkeyWA4uw6F5fm576uHrE3J9GCEGxmknH1V/SY3xAK83eu6UovwqdQrIoel8Ku0 cKZ5d48C3RtIrXEL2nFy7yk1P6mZt9Gw/ejZopavEbWO1+uYu55IxsW9qu/u2QzTPSPk EMLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I62rggSu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go9-20020a1709070d8900b007c16f74db39si3457917ejc.745.2022.12.12.13.02.20; Mon, 12 Dec 2022 13:02:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I62rggSu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233483AbiLLU7M (ORCPT + 99 others); Mon, 12 Dec 2022 15:59:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233344AbiLLU7B (ORCPT ); Mon, 12 Dec 2022 15:59:01 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45FB0186C0 for ; Mon, 12 Dec 2022 12:59:00 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id h8-20020a1c2108000000b003d1efd60b65so6363204wmh.0 for ; Mon, 12 Dec 2022 12:59:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t99/SFsMNtmGyI4mz9oW4N/Vb5nTNk7UReahhubAWF8=; b=I62rggSuemD4KBJ5cvSZyXPrnGSF/yT3ZcV94K/7IOcSoTjOsuhDNJ616NGUVnajQ1 kve81y916WokLOh+sCLiWK+SiFGORsF83VPdy+9p1bmkld+c09ANTJ6sBw7FD3bkscCz /iZdic03G2hiH6TweggGJWfeexk+AWvnMH2IySUeYt4AdNG9gsFFbBEQgo6lMJ2h/w5C xj5YTc4UCeJZFwqtzTXxZkHv6+zNiv8K+TTWfBHDTnXZEebQ3uPlb8w0NmX24zoMSyjU 73k7fP8yyYBq+tAQJMyF5SedcJkXII9ARE50B1hh4B6tGdIDOsvxlHnxevTJaW8FtcUq CaDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=t99/SFsMNtmGyI4mz9oW4N/Vb5nTNk7UReahhubAWF8=; b=JTat0R3treH/TFqs51+gwZRUsLckOuUL1aIDgYMOO/VCfL4wk7LI7Lm0HUpnsm0vxJ 8CiLcssirhNQf51oOKqis/qR6dPRAeGHAYMhOZHW5f0AU+/NkWFCmhRKp12UL3M9gu3B 8CczeWXIQFvHuTTRTNgIJuSMD3GtmZfusWn2ixFAxT1Y7jjlz9YnhJ4VGDVv/S4wWm1W V93H0H6suClDK2INZ1a8gOlv4IAXzLVfujqPk+ibX3u+L/kZCVCw/UVNAIMIAyqQBqMM UCk0VH3O2HkPxfNyCeXju04XzeLFudcy7Pl7FpBdKlzJtAisT/Im+x4tARtdnAUtOurc HRmw== X-Gm-Message-State: ANoB5plsnswX2hQicG4h5a4JBpNLPO9hQh1wh9tqSYtqzpNJkPwSLApp mztosWnUnq6C2jqbosIH6+2uig== X-Received: by 2002:a7b:cd8f:0:b0:3d1:baf7:ceae with SMTP id y15-20020a7bcd8f000000b003d1baf7ceaemr13759660wmj.39.1670878738656; Mon, 12 Dec 2022 12:58:58 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id t123-20020a1c4681000000b003a3170a7af9sm10537201wma.4.2022.12.12.12.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 12:58:58 -0800 (PST) From: Daniel Lezcano X-Google-Original-From: Daniel Lezcano To: rafael@kernel.org, srinivas.pandruvada@linux.intel.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] thermal/acpi: Add ACPI trip point routines Date: Mon, 12 Dec 2022 21:58:39 +0100 Message-Id: <20221212205843.3119407-2-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221212205843.3119407-1-daniel.lezcano@kernel.org> References: <20221212205843.3119407-1-daniel.lezcano@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752043581340032429?= X-GMAIL-MSGID: =?utf-8?q?1752043581340032429?= From: Daniel Lezcano The ACPI specification describes the trip points, the device tree bindings as well. The OF code uses the generic trip point structures. The ACPI has their own trip points structure and uses the get_trip_* ops to retrieve them. We can do the same as the OF code and create a set of ACPI functions to retrieve a trip point desciption. Having a common code for ACPI will help to cleanup the remaining Intel drivers and get rid of the get_trip_* functions. Signed-off-by: Daniel Lezcano --- drivers/thermal/Kconfig | 13 ++ drivers/thermal/Makefile | 1 + drivers/thermal/thermal_acpi.c | 249 +++++++++++++++++++++++++++++++++ include/linux/thermal.h | 15 ++ 4 files changed, 278 insertions(+) create mode 100644 drivers/thermal/thermal_acpi.c diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig index e052dae614eb..e57011be7009 100644 --- a/drivers/thermal/Kconfig +++ b/drivers/thermal/Kconfig @@ -76,6 +76,19 @@ config THERMAL_OF Say 'Y' here if you need to build thermal infrastructure based on device tree. +config THERMAL_ACPI + bool + prompt "APIs to parse thermal data out of the ACPI tables" + depends on ACPI + default y + help + This options provides helpers to add the support to + read and parse thermal data definitions out of the + ACPI tables blob. + + Say 'Y' here if you need to build thermal infrastructure + based on ACPI. + config THERMAL_WRITABLE_TRIPS bool "Enable writable trip points" help diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index 2506c6c8ca83..60f0dfa9aae2 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -13,6 +13,7 @@ thermal_sys-$(CONFIG_THERMAL_NETLINK) += thermal_netlink.o # interface to/from other layers providing sensors thermal_sys-$(CONFIG_THERMAL_HWMON) += thermal_hwmon.o thermal_sys-$(CONFIG_THERMAL_OF) += thermal_of.o +thermal_sys-$(CONFIG_THERMAL_ACPI) += thermal_acpi.o # governors thermal_sys-$(CONFIG_THERMAL_GOV_FAIR_SHARE) += gov_fair_share.o diff --git a/drivers/thermal/thermal_acpi.c b/drivers/thermal/thermal_acpi.c new file mode 100644 index 000000000000..7dfff3001c1c --- /dev/null +++ b/drivers/thermal/thermal_acpi.c @@ -0,0 +1,249 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2022 Linaro Limited + * + * Author: Daniel Lezcano + * + * ACPI thermal configuration + */ +#include +#include +#include +#include +#include + +#include "thermal_core.h" + +int thermal_acpi_trip_gtsh(struct acpi_device *adev) +{ + unsigned long long hyst; + acpi_status status; + + status = acpi_evaluate_integer(adev->handle, "GTSH", NULL, &hyst); + if (ACPI_FAILURE(status)) + return 0; + + return (int)(hyst * 100); +} + +int thermal_acpi_get_temp(struct acpi_device *adev, int *temperature) +{ + unsigned long long temp; + acpi_status status; + + /* + * _TMP (Temperature): This control method returns the thermal zone’s + * current operating temperature. The return value is the current + * temperature of the thermal zone in tenths of degrees Kelvin + */ + status = acpi_evaluate_integer(adev->handle, "_TMP", NULL, &temp); + if (ACPI_FAILURE(status)) + return -EIO; + + *temperature = deci_kelvin_to_millicelsius(temp); + + return 0; +} + +int thermal_acpi_trip_crit(struct acpi_device *adev, struct thermal_trip *trip) +{ + unsigned long long temp; + acpi_status status; + + /* + * _CRT (Critical temperature): This object, when defined under a thermal + * zone, returns the critical temperature at which OSPM must shutdown + * the system. If this object it present under a device, the device’s + * driver evaluates this object to determine the device’s critical cooling + * temperature trip point. This value may then be used by the device’s + * driver to program an internal device temperature sensor trip point + */ + status = acpi_evaluate_integer(adev->handle, "_CRT", NULL, &temp); + if (ACPI_FAILURE(status)) + return -EIO; + + trip->hysteresis = thermal_acpi_trip_gtsh(adev); + trip->temperature = deci_kelvin_to_millicelsius(temp); + trip->type = THERMAL_TRIP_CRITICAL; + + return 0; +} + +int thermal_acpi_trip_hot(struct acpi_device *adev, struct thermal_trip *trip) +{ + unsigned long long temp; + acpi_status status; + + /* + * _HOT (Hot Temperature): This optional object, when defined under a + * thermal zone, returns the critical temperature at which OSPM may + * choose to transition the system into the S4 sleeping state. The + * platform vendor should define _HOT to be far enough below _CRT so as + * to allow OSPM enough time to transition the system into the S4 + * sleeping state. While dependent on the amount of installed memory, + * on typical platforms OSPM implementations can transition the system + * into the S4 sleeping state in tens of seconds. If this object it + * present under a device, the device’s driver evaluates this object to + * determine the device’s hot cooling temperature trip point. This value + * may then be used by the device’s driver to program an internal device + * temperature sensor trip point. + */ + status = acpi_evaluate_integer(adev->handle, "_HOT", NULL, &temp); + if (ACPI_FAILURE(status)) + return -EIO; + + trip->hysteresis = thermal_acpi_trip_gtsh(adev); + trip->temperature = deci_kelvin_to_millicelsius(temp); + trip->type = THERMAL_TRIP_HOT; + + return 0; +} + +int thermal_acpi_trip_psl(struct acpi_device *adev, struct acpi_handle_list *devices) +{ + acpi_status status; + + /* + * _PSL (Passive List): This object is defined under a thermal zone and + * evaluates to a list of processor objects to be used for passive cooling + */ + status = acpi_evaluate_reference(adev->handle, "_PSL", NULL, devices); + if (ACPI_FAILURE(status)) + return -EIO; + + return 0; +} + +int thermal_acpi_trip_psv_tsp(struct acpi_device *adev) +{ + acpi_status status; + unsigned long long tsp; + + /* + * _TSP (Thermal Sampling Period): This object evaluates to a thermal + * sampling period (in tenths of seconds) used by OSPM to implement the + * Passive cooling equation. This value, along with _TC1 and _TC2, will + * enable OSPM to provide the proper hysteresis required by the system + * to accomplish an effective passive cooling policy. + */ + status = acpi_evaluate_integer(adev->handle, "_TSP", NULL, &tsp); + if (ACPI_FAILURE(status)) + return -EIO; + + return (int)tsp; +} + +int thermal_acpi_trip_psv_tc1(struct acpi_device *adev) +{ + acpi_status status; + unsigned long long tc1; + + /* + * _TC1 (Thermal Constant 1): This object evaluates to the constant _TC1 + * for use in the Passive cooling formula + */ + status = acpi_evaluate_integer(adev->handle, "_TC1", NULL, &tc1); + if (ACPI_FAILURE(status)) + return -EINVAL; + + return (int)tc1; +} + +int thermal_acpi_trip_psv_tc2(struct acpi_device *adev) +{ + acpi_status status; + unsigned long long tc2; + + /* + * _TC2 (Thermal Constant 1): This object evaluates to the constant _TC2 + * for use in the Passive cooling formula + */ + status = acpi_evaluate_integer(adev->handle, "_TC2", NULL, &tc2); + if (ACPI_FAILURE(status)) + return -EINVAL; + + return (int)tc2; +} + +int thermal_acpi_trip_psv(struct acpi_device *adev, struct thermal_trip *trip) +{ + unsigned long long temp; + acpi_status status; + + /* + * _PSV (Passive): This optional object, if present under a thermal zone, + * evaluates to the temperature at which OSPM must activate passive + * cooling policy + */ + status = acpi_evaluate_integer(adev->handle, "_PSV", NULL, &temp); + if (ACPI_FAILURE(status)) + return -EINVAL; + + /* + * The _PSL, _TSP, _TC1 and _TC2 are required if the _PSV object exists. + * We assume the caller will raise an error if it was able to get the _PSV + * but then fail to get the other objects. + */ + trip->hysteresis = thermal_acpi_trip_gtsh(adev); + trip->temperature = deci_kelvin_to_millicelsius(temp); + trip->type = THERMAL_TRIP_PASSIVE; + + return 0; +} + +int thermal_acpi_trip_acl(struct acpi_device *adev, + struct acpi_handle_list *devices, int id) +{ + acpi_status status; + char name[5]; + + /* + * _ALx: This object is defined under a thermal zone and evaluates to a + * list of Active cooling devices to be turned on when the corresponding + * _ACx temperature threshold is exceeded. For example, these devices + * could be fans. + */ + sprintf(name, "_AL%d", id); + + status = acpi_evaluate_reference(adev->handle, name, NULL, devices); + if (ACPI_FAILURE(status)) + return -EINVAL; + + return 0; +} + +int thermal_acpi_trip_act(struct acpi_device *adev, + struct thermal_trip *trip, int id) +{ + acpi_status status; + unsigned long long temp; + char name[5]; + + /* + * _ACx: This optional object, if present under a thermal zone, returns + * the temperature trip point at which OSPM must start or stop active + * cooling, where x is a value between 0 and 9 that designates multiple + * active cooling levels of the thermal zone. If the Active cooling + * device has one cooling level (that is, “on”) then that cooling level + * must be defined as _AC0. If the cooling device has two levels of + * capability, such as a high fan speed and a low fan speed, then they + * must be defined as _AC0 and _AC1 respectively. The smaller the value + * of x, the greater the cooling strength _ACx represents. In the above + * example, _AC0 represents the greater level of cooling (the faster fan + * speed) and _AC1 represents the lesser level of cooling (the slower + * fan speed). For every _ACx method, there must be a matching _ALx + * object or a corresponding entry in an _ART object’s active cooling + * relationship list. + */ + sprintf(name, "_AC%d", id); + + status = acpi_evaluate_integer(adev->handle, name, NULL, &temp); + if (ACPI_FAILURE(status)) + return -EINVAL; + + trip->hysteresis = thermal_acpi_trip_gtsh(adev); + trip->temperature = deci_kelvin_to_millicelsius(temp); + trip->type = THERMAL_TRIP_ACTIVE; + + return 0; +} diff --git a/include/linux/thermal.h b/include/linux/thermal.h index e2797f314d99..b8b9d9eddb3a 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -334,6 +334,21 @@ static inline void devm_thermal_of_zone_unregister(struct device *dev, } #endif +#ifdef CONFIG_ACPI +struct acpi_handle_list; +int thermal_acpi_get_temp(struct acpi_device *adev, int *temperature); +int thermal_acpi_trip_crit(struct acpi_device *adev, struct thermal_trip *trip); +int thermal_acpi_trip_hot(struct acpi_device *adev, struct thermal_trip *trip); +int thermal_acpi_trip_psv(struct acpi_device *adev, struct thermal_trip *trip); +int thermal_acpi_trip_act(struct acpi_device *adev, struct thermal_trip *trip, int id); +int thermal_acpi_trip_acl(struct acpi_device *adev, struct acpi_handle_list *devices, int id); +int thermal_acpi_trip_psv_psl(struct acpi_device *adev, struct acpi_handle_list *devices); +int thermal_acpi_trip_psv_tsp(struct acpi_device *adev); +int thermal_acpi_trip_psv_tc1(struct acpi_device *adev); +int thermal_acpi_trip_psv_tc2(struct acpi_device *adev); +int thermal_acpi_trip_gtsh(struct acpi_device *adev); +#endif + int thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, struct thermal_trip *trip); From patchwork Mon Dec 12 20:58:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 32530 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2463038wrr; Mon, 12 Dec 2022 13:01:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf4cc2lg2N4U+Z3fe3ZEQfDS82KThBOxngZg7KNLmsMyWdDqTMAVbR2wDLK1fK7HaQGtyMom X-Received: by 2002:a17:906:4905:b0:7be:fb2c:c112 with SMTP id b5-20020a170906490500b007befb2cc112mr14306062ejq.66.1670878918839; Mon, 12 Dec 2022 13:01:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670878918; cv=none; d=google.com; s=arc-20160816; b=x95h75wYo18c2USeFR5vkQeM8kxPjAJZLWn9+EdWqpCV9fZ6ukPW54HkWpD3xhEjot /aey2JoFa/5s/fhFoJQYuwUIAMkmeVzD/yxDrESyO6HTGTL5jDzI1rGzmjrT8uhq+EmZ DRclhUDcWzLiEM38lwI8ticXSMVJZpRPHFe1Tx2JyLxHhqRLT/VohVYd44lOvN5BZi4p baLPWtAgRq11c/xlgoGEEpxtY8YDOTVdWXbwR7u7n4K/RBnb+7Ai2ApGkB4p1MX5j7Vd TPAcDZeLH2IVGG0VNosySoBB+VkGDT3EYoCW4hVoA5tDhY1Yxh4rXE0gOUQ393SPcTQi RL8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NevQn9Y5RI1VimgruaO0EgtIiQx7BC1ue3AUHCaSES4=; b=TF8EYkzBIgLQFjqQiXuPDodAV7URBXMOez7b9avGMxlNBn+GL01y+c+SmTiVqOchmS KxAWGOvKqPcLRt440NGmt9pxpsc+w7dhL0v7p5zJqONfamvb/nkaz8Cv0zQAM2PZczLl zCqqPev49QvuoTJIr6CcLtKjA27nv1Aw7UB510dpog9dRUNfj4TpUvDQyiKQybs+IjKp Me2r/fm6FCEwAZImvxh/PiFymoPWeEz82ucMleKuQdQeRqykc9mMeo0Iv4PlKCf/8+32 d5trxVqKdxOnWlM42ZohCrk2xRBQ1yEqvxy8iDNyWYxKQf1pea22FAmKsVRocunh+Ho6 djtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rnkA+iLO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e12-20020a17090658cc00b007c0fa609b09si8348552ejs.771.2022.12.12.13.01.34; Mon, 12 Dec 2022 13:01:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rnkA+iLO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233020AbiLLU7R (ORCPT + 99 others); Mon, 12 Dec 2022 15:59:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233396AbiLLU7C (ORCPT ); Mon, 12 Dec 2022 15:59:02 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08556186C7 for ; Mon, 12 Dec 2022 12:59:01 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id o15so6696377wmr.4 for ; Mon, 12 Dec 2022 12:59:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NevQn9Y5RI1VimgruaO0EgtIiQx7BC1ue3AUHCaSES4=; b=rnkA+iLO6oQMzR+jyX4KPrl1mhgTNVDRrtrXuScS7PK0XH/LCNPoiZFIIhImwe4s+Q bsY0hLJF4iZdRolhjHAhrDCdy0Mqcbok1T6TxDzEoS1bzBMCdiMA8Z/CPccYTx3hKzJG 4EjXDdUMEl5S76DqwJc+kDheV0n7y44Fj2c7+2KtsHz5pLHPTHKCy9uk7nU8we0fvjYD sHtHgvDsCfoUY1+PJpdj90aA9w/Hvlx2XVZW6kLNcyTCeUd/qU4U/2TKsSXCD3A/Ob08 QW/zWPxyYXJ+XdjCQgxkTC3SG8RnXV9q+wZKIi5xq5im8EE2aG8OyItORyBxE4lG1lK2 uAtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=NevQn9Y5RI1VimgruaO0EgtIiQx7BC1ue3AUHCaSES4=; b=NltnWDCqAPQ7APbFWGNVnq1gGNVwW9Es4k95I3hz27HrfUrHoVmtHgz5Gyy3xs5+iR mX4Cv3XYMCmGGW0bqB7mF/1CY+FqOAe4TpdNgLJ3KrhzrI8yBcz2JeLTZDbZmN8rTu/a iqaafh7B5oLP8tCic7IA3BRoHvvFxfMKNn7WDi3wlG5db9XVcF9gfD4qb7VUZIBeZIV+ vlrMLV4wal8WyAX8+c1me21doqIH6Gki1+xte8OVdk6O5aktae5WKWWVFAu2G4o/3pEb jAoFLM9CIxo4zDln24uY76aRqB5q4GujLgAU6NDPWKwwutuBTt/sJdt66JJ2PADAg0wY BwTg== X-Gm-Message-State: ANoB5pm6IdB9MdnrxbGGUueuWE/cxZigYUG4gHtqxYrW1E3VnsZjZU5N wk75bz7JjXzRi+j+azTPyeiEaA== X-Received: by 2002:a05:600c:13c8:b0:3cf:69a5:3621 with SMTP id e8-20020a05600c13c800b003cf69a53621mr13743797wmg.41.1670878739531; Mon, 12 Dec 2022 12:58:59 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id t123-20020a1c4681000000b003a3170a7af9sm10537201wma.4.2022.12.12.12.58.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 12:58:59 -0800 (PST) From: Daniel Lezcano X-Google-Original-From: Daniel Lezcano To: rafael@kernel.org, srinivas.pandruvada@linux.intel.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] thermal/drivers/intel: Use generic trip points for intel_pch Date: Mon, 12 Dec 2022 21:58:40 +0100 Message-Id: <20221212205843.3119407-3-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221212205843.3119407-1-daniel.lezcano@kernel.org> References: <20221212205843.3119407-1-daniel.lezcano@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752043533058589528?= X-GMAIL-MSGID: =?utf-8?q?1752043533058589528?= From: Daniel Lezcano The thermal framework gives the possibility to register the trip points with the thermal zone. When that is done, no get_trip_* ops are needed and they can be removed. Convert ops content logic into generic trip points and register them with the thermal zone. Signed-off-by: Daniel Lezcano --- drivers/thermal/intel/intel_pch_thermal.c | 88 +++++------------------ 1 file changed, 19 insertions(+), 69 deletions(-) diff --git a/drivers/thermal/intel/intel_pch_thermal.c b/drivers/thermal/intel/intel_pch_thermal.c index dabf11a687a1..530fe9b38381 100644 --- a/drivers/thermal/intel/intel_pch_thermal.c +++ b/drivers/thermal/intel/intel_pch_thermal.c @@ -65,6 +65,8 @@ #define WPT_TEMP_OFFSET (PCH_TEMP_OFFSET * MILLIDEGREE_PER_DEGREE) #define GET_PCH_TEMP(x) (((x) / 2) + PCH_TEMP_OFFSET) +#define PCH_MAX_TRIPS 3 /* critical, hot, passive */ + /* Amount of time for each cooling delay, 100ms by default for now */ static unsigned int delay_timeout = 100; module_param(delay_timeout, int, 0644); @@ -82,12 +84,7 @@ struct pch_thermal_device { const struct pch_dev_ops *ops; struct pci_dev *pdev; struct thermal_zone_device *tzd; - int crt_trip_id; - unsigned long crt_temp; - int hot_trip_id; - unsigned long hot_temp; - int psv_trip_id; - unsigned long psv_temp; + struct thermal_trip trips[PCH_MAX_TRIPS]; bool bios_enabled; }; @@ -102,33 +99,22 @@ static void pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd, int *nr_trips) { struct acpi_device *adev; - - ptd->psv_trip_id = -1; + int ret; adev = ACPI_COMPANION(&ptd->pdev->dev); - if (adev) { - unsigned long long r; - acpi_status status; - - status = acpi_evaluate_integer(adev->handle, "_PSV", NULL, - &r); - if (ACPI_SUCCESS(status)) { - unsigned long trip_temp; - - trip_temp = deci_kelvin_to_millicelsius(r); - if (trip_temp) { - ptd->psv_temp = trip_temp; - ptd->psv_trip_id = *nr_trips; - ++(*nr_trips); - } - } - } + if (!adev) + return; + + ret = thermal_acpi_trip_psv(adev, &ptd->trips[*nr_trips]); + if (ret) + return; + + ++(*nr_trips); } #else static void pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd, int *nr_trips) { - ptd->psv_trip_id = -1; } #endif @@ -163,21 +149,19 @@ static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips) } read_trips: - ptd->crt_trip_id = -1; trip_temp = readw(ptd->hw_base + WPT_CTT); trip_temp &= 0x1FF; if (trip_temp) { - ptd->crt_temp = GET_WPT_TEMP(trip_temp); - ptd->crt_trip_id = 0; + ptd->trips[*nr_trips].temperature = GET_WPT_TEMP(trip_temp); + ptd->trips[*nr_trips].type = THERMAL_TRIP_CRITICAL; ++(*nr_trips); } - ptd->hot_trip_id = -1; trip_temp = readw(ptd->hw_base + WPT_PHL); trip_temp &= 0x1FF; if (trip_temp) { - ptd->hot_temp = GET_WPT_TEMP(trip_temp); - ptd->hot_trip_id = *nr_trips; + ptd->trips[*nr_trips].temperature = GET_WPT_TEMP(trip_temp); + ptd->trips[*nr_trips].type = THERMAL_TRIP_HOT; ++(*nr_trips); } @@ -298,39 +282,6 @@ static int pch_thermal_get_temp(struct thermal_zone_device *tzd, int *temp) return ptd->ops->get_temp(ptd, temp); } -static int pch_get_trip_type(struct thermal_zone_device *tzd, int trip, - enum thermal_trip_type *type) -{ - struct pch_thermal_device *ptd = tzd->devdata; - - if (ptd->crt_trip_id == trip) - *type = THERMAL_TRIP_CRITICAL; - else if (ptd->hot_trip_id == trip) - *type = THERMAL_TRIP_HOT; - else if (ptd->psv_trip_id == trip) - *type = THERMAL_TRIP_PASSIVE; - else - return -EINVAL; - - return 0; -} - -static int pch_get_trip_temp(struct thermal_zone_device *tzd, int trip, int *temp) -{ - struct pch_thermal_device *ptd = tzd->devdata; - - if (ptd->crt_trip_id == trip) - *temp = ptd->crt_temp; - else if (ptd->hot_trip_id == trip) - *temp = ptd->hot_temp; - else if (ptd->psv_trip_id == trip) - *temp = ptd->psv_temp; - else - return -EINVAL; - - return 0; -} - static void pch_critical(struct thermal_zone_device *tzd) { dev_dbg(&tzd->device, "%s: critical temperature reached\n", tzd->type); @@ -338,8 +289,6 @@ static void pch_critical(struct thermal_zone_device *tzd) static struct thermal_zone_device_ops tzd_ops = { .get_temp = pch_thermal_get_temp, - .get_trip_type = pch_get_trip_type, - .get_trip_temp = pch_get_trip_temp, .critical = pch_critical, }; @@ -423,8 +372,9 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev, if (err) goto error_cleanup; - ptd->tzd = thermal_zone_device_register(bi->name, nr_trips, 0, ptd, - &tzd_ops, NULL, 0, 0); + ptd->tzd = thermal_zone_device_register_with_trips(bi->name, ptd->trips, + nr_trips, 0, ptd, + &tzd_ops, NULL, 0, 0); if (IS_ERR(ptd->tzd)) { dev_err(&pdev->dev, "Failed to register thermal zone %s\n", bi->name); From patchwork Mon Dec 12 20:58:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 32531 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2463151wrr; Mon, 12 Dec 2022 13:02:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf6I69hWA5mIif4qe3gTADNEIOujz7aeTmEk6VNnEgv1zyW9k+riOTDZAY7zit1g4+QqFP32 X-Received: by 2002:a17:907:674b:b0:7ae:5473:fdb8 with SMTP id qm11-20020a170907674b00b007ae5473fdb8mr16997261ejc.22.1670878930286; Mon, 12 Dec 2022 13:02:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670878930; cv=none; d=google.com; s=arc-20160816; b=OIopWDn6KqYX5ZGRPNHVAzlsNUrm1dp0F1DnYa3BouxfhDAHyR8WFo1ZPVtSjLV4xB /Hz2019LLZRpoyseC+l6MfAvOKbvCio2FIORnAHJTpVurtSibx9X8HsMwejelKw/hoIl cFScGW4haQr/MP3Sn9jU19wlPBz6K8kdM3DpxbVfd3PVpU9L10S2MRG9aW+2KW4GgTni WG+kvycBzC9EvA9wdNHAgcxpCiLhDu2a5qnuxOabA7wge8Ef+dBz89DxTxKgV0wNCZvw nqLDHJtOWCvALIveBgFUXt0hxgFSF3h+zoZk2Id/6wMJBMdN9QoX2cAlHBDYM1/RAecf cnkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1dPwTgj60rD2ScCmM1mcgWB2TrQuz9RZ91iwzhvccN0=; b=vx6i2TK48CZH4c6qqbZlW9WYewXDr01aQLjvj2zbIOs8qLX5mhpTDsCCRjq9xdu3Is Up8n4KedN9apaq5kw0gWcPT52T7dTUQFGLSie5bK6uTMxAXHxPT1In3EcUGODMIOEaeE z2MlsnS0sFCAyeEf9z2ZmXbg1l4hWVFOpisgPxaJPkWIIgeTf+vK0Uw5fYci9nk/qW9G aDNeOdzgDRQlObp89xO1mxPiKUmX3Mr+9fOpOlH7c98ptL4c9UI2hvR7+TjSd9qEa2za VcOUzlNiCy9y1zbCON8csavHvS2QKkMvEcbrknARztjdaqK/M80GEQirPrEgyoupdG5g Xemg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qEj26m87; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v19-20020a50d593000000b0046abe52aca7si7889673edi.486.2022.12.12.13.01.46; Mon, 12 Dec 2022 13:02:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qEj26m87; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233197AbiLLU7V (ORCPT + 99 others); Mon, 12 Dec 2022 15:59:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233476AbiLLU7D (ORCPT ); Mon, 12 Dec 2022 15:59:03 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE62A17059 for ; Mon, 12 Dec 2022 12:59:01 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id c65-20020a1c3544000000b003cfffd00fc0so6345034wma.1 for ; Mon, 12 Dec 2022 12:59:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1dPwTgj60rD2ScCmM1mcgWB2TrQuz9RZ91iwzhvccN0=; b=qEj26m87uBR7HunNW7xPqy/nqdrnjjRX059UddqhJ4MsEidfxF1UoizL4n+xp7djN3 NrbhamvD4Zu8JDYJarZdwvOa5f6TScKZq55w0VpoClYGl/vDQIFa3oEB2xu74R7VcpHG xOvU4Bwos15wSAkmMawgmQOCVDfzlTlbKIrfTHifHaq4fUsRpSakwCqCIZjQeKmiV9VW XOhIJsYzdxaUAiW4xq7by98Itvv96fj19uE2J1BrGFjz6lgl7MXvLHHtD5r/+dmKpCH6 KoNruT9jfmwfJ/NpZ19zChL+T3Anfb1RwMA+x+74/1a8IMCkgk2XUT640m48IR49XBaK obdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=1dPwTgj60rD2ScCmM1mcgWB2TrQuz9RZ91iwzhvccN0=; b=HgQmpn5BcTziUc9Rqp8A7gCjseize4/Nw5uNIOXyhK3NiN6fCcsKcRLWYPlntGb0XE yKBeQbfY1TsYAyAK/p4CLmsHQjfs/jjV5r13hHWuiMpZhntjZQajl4/dicwXTAowQWxc eiFXI+0l9uiZhx49VhJcCcAoT3l2ov5m3UNMpzwgPF9BZY5t8kvAe0uXSKWxxjRa8x7b I8y2jwuDU9xrk72CBj0wbj6dF/Ve5GIsVn4qlFEUJjUj36/N2ObHE7d1a6MAYnOBRDTJ TSSpmmyuKeaUpXIZ4HjUHOdwGGjRMOKTqPDUkkMnsd5SYyogBc47Ork6j0MCWwBgxB4a 0unQ== X-Gm-Message-State: ANoB5plncNRDYpCzdo2owz2EKihLFsajNBTYxpiLr8uhwcaWHtndgHQI mZnXjtDsoaYOOZNmRQpy6cY5xw== X-Received: by 2002:a7b:c406:0:b0:3cf:a0f6:1942 with SMTP id k6-20020a7bc406000000b003cfa0f61942mr14322255wmi.34.1670878740415; Mon, 12 Dec 2022 12:59:00 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id t123-20020a1c4681000000b003a3170a7af9sm10537201wma.4.2022.12.12.12.58.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 12:59:00 -0800 (PST) From: Daniel Lezcano X-Google-Original-From: Daniel Lezcano To: rafael@kernel.org, srinivas.pandruvada@linux.intel.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] thermal/drivers/intel: Use generic trip points int340x Date: Mon, 12 Dec 2022 21:58:41 +0100 Message-Id: <20221212205843.3119407-4-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221212205843.3119407-1-daniel.lezcano@kernel.org> References: <20221212205843.3119407-1-daniel.lezcano@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752043545326505892?= X-GMAIL-MSGID: =?utf-8?q?1752043545326505892?= From: Daniel Lezcano The thermal framework gives the possibility to register the trip points with the thermal zone. When that is done, no get_trip_* ops are needed and they can be removed. Convert ops content logic into generic trip points and register them with the thermal zone. Signed-off-by: Daniel Lezcano --- .../int340x_thermal/int340x_thermal_zone.c | 175 ++++-------------- .../int340x_thermal/int340x_thermal_zone.h | 10 +- 2 files changed, 40 insertions(+), 145 deletions(-) diff --git a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c index 228f44260b27..4f2e518caf8d 100644 --- a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +++ b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c @@ -37,65 +37,6 @@ static int int340x_thermal_get_zone_temp(struct thermal_zone_device *zone, return 0; } -static int int340x_thermal_get_trip_temp(struct thermal_zone_device *zone, - int trip, int *temp) -{ - struct int34x_thermal_zone *d = zone->devdata; - int i; - - if (trip < d->aux_trip_nr) - *temp = d->aux_trips[trip]; - else if (trip == d->crt_trip_id) - *temp = d->crt_temp; - else if (trip == d->psv_trip_id) - *temp = d->psv_temp; - else if (trip == d->hot_trip_id) - *temp = d->hot_temp; - else { - for (i = 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) { - if (d->act_trips[i].valid && - d->act_trips[i].id == trip) { - *temp = d->act_trips[i].temp; - break; - } - } - if (i == INT340X_THERMAL_MAX_ACT_TRIP_COUNT) - return -EINVAL; - } - - return 0; -} - -static int int340x_thermal_get_trip_type(struct thermal_zone_device *zone, - int trip, - enum thermal_trip_type *type) -{ - struct int34x_thermal_zone *d = zone->devdata; - int i; - - if (trip < d->aux_trip_nr) - *type = THERMAL_TRIP_PASSIVE; - else if (trip == d->crt_trip_id) - *type = THERMAL_TRIP_CRITICAL; - else if (trip == d->hot_trip_id) - *type = THERMAL_TRIP_HOT; - else if (trip == d->psv_trip_id) - *type = THERMAL_TRIP_PASSIVE; - else { - for (i = 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) { - if (d->act_trips[i].valid && - d->act_trips[i].id == trip) { - *type = THERMAL_TRIP_ACTIVE; - break; - } - } - if (i == INT340X_THERMAL_MAX_ACT_TRIP_COUNT) - return -EINVAL; - } - - return 0; -} - static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone, int trip, int temp) { @@ -109,25 +50,6 @@ static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone, if (ACPI_FAILURE(status)) return -EIO; - d->aux_trips[trip] = temp; - - return 0; -} - - -static int int340x_thermal_get_trip_hyst(struct thermal_zone_device *zone, - int trip, int *temp) -{ - struct int34x_thermal_zone *d = zone->devdata; - acpi_status status; - unsigned long long hyst; - - status = acpi_evaluate_integer(d->adev->handle, "GTSH", NULL, &hyst); - if (ACPI_FAILURE(status)) - *temp = 0; - else - *temp = hyst * 100; - return 0; } @@ -138,58 +60,36 @@ static void int340x_thermal_critical(struct thermal_zone_device *zone) static struct thermal_zone_device_ops int340x_thermal_zone_ops = { .get_temp = int340x_thermal_get_zone_temp, - .get_trip_temp = int340x_thermal_get_trip_temp, - .get_trip_type = int340x_thermal_get_trip_type, .set_trip_temp = int340x_thermal_set_trip_temp, - .get_trip_hyst = int340x_thermal_get_trip_hyst, .critical = int340x_thermal_critical, }; -static int int340x_thermal_get_trip_config(acpi_handle handle, char *name, - int *temp) -{ - unsigned long long r; - acpi_status status; - - status = acpi_evaluate_integer(handle, name, NULL, &r); - if (ACPI_FAILURE(status)) - return -EIO; - - *temp = deci_kelvin_to_millicelsius(r); - - return 0; -} - int int340x_thermal_read_trips(struct int34x_thermal_zone *int34x_zone) { - int trip_cnt = int34x_zone->aux_trip_nr; - int i; + int trip_cnt; + int i, ret; - int34x_zone->crt_trip_id = -1; - if (!int340x_thermal_get_trip_config(int34x_zone->adev->handle, "_CRT", - &int34x_zone->crt_temp)) - int34x_zone->crt_trip_id = trip_cnt++; + trip_cnt = int34x_zone->aux_trip_nr; + + ret = thermal_acpi_trip_crit(int34x_zone->adev, &int34x_zone->trips[trip_cnt]); + if (!ret) + trip_cnt++; - int34x_zone->hot_trip_id = -1; - if (!int340x_thermal_get_trip_config(int34x_zone->adev->handle, "_HOT", - &int34x_zone->hot_temp)) - int34x_zone->hot_trip_id = trip_cnt++; + ret = thermal_acpi_trip_hot(int34x_zone->adev, &int34x_zone->trips[trip_cnt]); + if (!ret) + trip_cnt++; - int34x_zone->psv_trip_id = -1; - if (!int340x_thermal_get_trip_config(int34x_zone->adev->handle, "_PSV", - &int34x_zone->psv_temp)) - int34x_zone->psv_trip_id = trip_cnt++; + ret = thermal_acpi_trip_psv(int34x_zone->adev, &int34x_zone->trips[trip_cnt]); + if (!ret) + trip_cnt++; for (i = 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) { - char name[5] = { '_', 'A', 'C', '0' + i, '\0' }; - if (int340x_thermal_get_trip_config(int34x_zone->adev->handle, - name, - &int34x_zone->act_trips[i].temp)) + ret = thermal_acpi_trip_act(int34x_zone->adev, &int34x_zone->trips[trip_cnt], i); + if (ret) break; - int34x_zone->act_trips[i].id = trip_cnt++; - int34x_zone->act_trips[i].valid = true; + trip_cnt++; } return trip_cnt; @@ -208,7 +108,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev, acpi_status status; unsigned long long trip_cnt; int trip_mask = 0; - int ret; + int i, ret; int34x_thermal_zone = kzalloc(sizeof(*int34x_thermal_zone), GFP_KERNEL); @@ -228,32 +128,33 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev, int34x_thermal_zone->ops->get_temp = get_temp; status = acpi_evaluate_integer(adev->handle, "PATC", NULL, &trip_cnt); - if (ACPI_FAILURE(status)) - trip_cnt = 0; - else { - int i; - - int34x_thermal_zone->aux_trips = - kcalloc(trip_cnt, - sizeof(*int34x_thermal_zone->aux_trips), - GFP_KERNEL); - if (!int34x_thermal_zone->aux_trips) { - ret = -ENOMEM; - goto err_trip_alloc; - } - trip_mask = BIT(trip_cnt) - 1; + if (!ACPI_FAILURE(status)) { int34x_thermal_zone->aux_trip_nr = trip_cnt; - for (i = 0; i < trip_cnt; ++i) - int34x_thermal_zone->aux_trips[i] = THERMAL_TEMP_INVALID; + trip_mask = BIT(trip_cnt) - 1; } + int34x_thermal_zone->trips = kzalloc(sizeof(*int34x_thermal_zone->trips) * + (INT340X_THERMAL_MAX_TRIP_COUNT + trip_cnt), + GFP_KERNEL); + if (!int34x_thermal_zone->trips) { + ret = -ENOMEM; + goto err_trips_alloc; + } + + for (i = 0; i < trip_cnt; ++i) { + int34x_thermal_zone->trips[i].hysteresis = thermal_acpi_trip_gtsh(adev); + int34x_thermal_zone->trips[i].type = THERMAL_TRIP_PASSIVE; + int34x_thermal_zone->trips[i].temperature = THERMAL_TEMP_INVALID; + } + trip_cnt = int340x_thermal_read_trips(int34x_thermal_zone); int34x_thermal_zone->lpat_table = acpi_lpat_get_conversion_table( adev->handle); - int34x_thermal_zone->zone = thermal_zone_device_register( + int34x_thermal_zone->zone = thermal_zone_device_register_with_trips( acpi_device_bid(adev), + int34x_thermal_zone->trips, trip_cnt, trip_mask, int34x_thermal_zone, int34x_thermal_zone->ops, @@ -272,9 +173,9 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev, err_enable: thermal_zone_device_unregister(int34x_thermal_zone->zone); err_thermal_zone: + kfree(int34x_thermal_zone->trips); acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table); - kfree(int34x_thermal_zone->aux_trips); -err_trip_alloc: +err_trips_alloc: kfree(int34x_thermal_zone->ops); err_ops_alloc: kfree(int34x_thermal_zone); @@ -287,7 +188,7 @@ void int340x_thermal_zone_remove(struct int34x_thermal_zone { thermal_zone_device_unregister(int34x_thermal_zone->zone); acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table); - kfree(int34x_thermal_zone->aux_trips); + kfree(int34x_thermal_zone->trips); kfree(int34x_thermal_zone->ops); kfree(int34x_thermal_zone); } diff --git a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h index e28ab1ba5e06..0c2c8de92014 100644 --- a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h +++ b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h @@ -10,6 +10,7 @@ #include #define INT340X_THERMAL_MAX_ACT_TRIP_COUNT 10 +#define INT340X_THERMAL_MAX_TRIP_COUNT INT340X_THERMAL_MAX_ACT_TRIP_COUNT + 3 struct active_trip { int temp; @@ -19,15 +20,8 @@ struct active_trip { struct int34x_thermal_zone { struct acpi_device *adev; - struct active_trip act_trips[INT340X_THERMAL_MAX_ACT_TRIP_COUNT]; - unsigned long *aux_trips; + struct thermal_trip *trips; int aux_trip_nr; - int psv_temp; - int psv_trip_id; - int crt_temp; - int crt_trip_id; - int hot_temp; - int hot_trip_id; struct thermal_zone_device *zone; struct thermal_zone_device_ops *ops; void *priv_data; From patchwork Mon Dec 12 20:58:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 32533 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2463720wrr; Mon, 12 Dec 2022 13:03:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf71qcBP8gsr25C8wbJzeUZHDhl7rVz+S1Od+DsM+p/04Envu7F6FqnFdGoek7lu0ZrG1xll X-Received: by 2002:a17:906:11d2:b0:7c1:7c3a:ffba with SMTP id o18-20020a17090611d200b007c17c3affbamr2552837eja.35.1670878987056; Mon, 12 Dec 2022 13:03:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670878987; cv=none; d=google.com; s=arc-20160816; b=H7CVylEVv//Tw5LTfJkH52N8kOGwPcAvlBKtZwK6UM1c3C4bRoRPOEqVZZplC7bwnP CfGQHcm7Q5gaSS9totXgOlL0qxyLu5fXwSgQmP9P6U9XyKbOm+bvOm1K1gRjlAd+tX4E gf6om80ZRNdQslx8X0fXVeLXIkN7GbycJ8pHzJX6MzrXV5ALeAuXz1uAbLNvFMrsuvnD hFBf62ycuDjM9ecOGDpX5ytxGhFmkTPWfGINMqJtRJok1DLtfDuWfXplhlj6cdXSq8uY zPqpo5u9D0/sAXOettKfvpRRchsvAKjGmKaFmStKge1NVpv7IXkniUCwITusRgKJv10I vyMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OcUvjMSvUhi2ASA5ji6Vf5KA1TUeyW5xoEs+0ApDTqU=; b=p1FTEkCTYvn/f9I5/wEykZgB4u8wESZlMS8XbPF54j7G66IFuK0RY1SjrMddDS94Y0 T3/Y510HD/G/Lg2u/OvuXTDjrKWlJQI6/BxhUVK9NJLiO6X0T3F9GLq+I/p/8p2oqILF O+ApntjkYNNblmh59B12XIVVY34QJJtJXyMcWb0Ox+yts77tdx+NoChrqBW5YGtpzl1W VsIfgbCKh6eS2NCUQxAlLmpXzEucz/g+xPijDOclEY6r0cLB49kbyKpeFqbSDwdeALSo HHH4M0m4bG3/Fi1cDYxceTnO/dc8C5+IX0LBTio1Fdzx1Z6NwIqwZPlJ6KTMwePhwRpS 5bxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hjmnmQVu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id us11-20020a170906bfcb00b007824b85978asi5591596ejb.81.2022.12.12.13.02.43; Mon, 12 Dec 2022 13:03:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hjmnmQVu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233408AbiLLU73 (ORCPT + 99 others); Mon, 12 Dec 2022 15:59:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233489AbiLLU7D (ORCPT ); Mon, 12 Dec 2022 15:59:03 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCE24183A8 for ; Mon, 12 Dec 2022 12:59:02 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id k22-20020a05600c1c9600b003d1ee3a6289so6411917wms.2 for ; Mon, 12 Dec 2022 12:59:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OcUvjMSvUhi2ASA5ji6Vf5KA1TUeyW5xoEs+0ApDTqU=; b=hjmnmQVu2j6CQTfAqyqb6Jo1mrk9Xys/REZ5uB0jR0CEP20u+9VRYxr3k5edoEKI+5 /lhXTtv+14mK8tAktc/757cHS+bkTEAzb0s82p551ckqt6lwjCK3l1844M+c08koU4il zSjMOzuG9Q7ZazIjy8zBO2OJMN5a2FE6zOveiNJYxBP19tflIyQ4xSrufDr8dVX5v6MO tOQjNHyKZ+dTPswibdeMjUNm9v6bjYP3KvlLydd++mrfhjJchVxrZmdqWao4ojQ8ijvG Bouu72dz9DMjDHpzJlwTmBH5x+hnZbgK+DrYd/fHGUz0a87oXy20D3EYS7Jn/F3QZvnq P0vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=OcUvjMSvUhi2ASA5ji6Vf5KA1TUeyW5xoEs+0ApDTqU=; b=ipn/9f+wF8HdC7sALHCDcEnbx3iMlkMwt/rgwcWmMB4EJfctffwvl6Hg98mJG2WCVN YSpz0+AXcS73wWulG90ab+G17tJLbJJUpoDJT/hi2y6MGPi+pt2vzeYhuaKVeLbjcwMw i1iCtknDIk6SCTeeZujlx2loszGmTS66CWQpwc8IJcybhJqMKiWkxGjJuzz3HQ9HyVRh O1FvbUaLPam7ilNCcXGqWR+iegKZRXH+4IPuij8AJOuanGpbXtNlkEkoOQUTRED2qAii Isf2zPKoTafMy93MyC/yZjwZk74BEF4PKuwttK2TmqMJ4/g2I9/Veac82cHXoUIp/49t qyrA== X-Gm-Message-State: ANoB5pngczFzR1glKnP9qFfpIgL+TDpDZRMAPrPgP0UUfP5sLiAwU5Im gJPeiOXiz18DAmP298dJDaH4cw== X-Received: by 2002:a05:600c:354e:b0:3cf:5d41:b748 with SMTP id i14-20020a05600c354e00b003cf5d41b748mr13542381wmq.36.1670878741271; Mon, 12 Dec 2022 12:59:01 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id t123-20020a1c4681000000b003a3170a7af9sm10537201wma.4.2022.12.12.12.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 12:59:00 -0800 (PST) From: Daniel Lezcano X-Google-Original-From: Daniel Lezcano To: rafael@kernel.org, srinivas.pandruvada@linux.intel.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] thermal/drivers/intel: Use generic trip points for quark_dts Date: Mon, 12 Dec 2022 21:58:42 +0100 Message-Id: <20221212205843.3119407-5-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221212205843.3119407-1-daniel.lezcano@kernel.org> References: <20221212205843.3119407-1-daniel.lezcano@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752043604627806880?= X-GMAIL-MSGID: =?utf-8?q?1752043604627806880?= From: Daniel Lezcano The thermal framework gives the possibility to register the trip points with the thermal zone. When that is done, no get_trip_* ops are needed and they can be removed. Convert ops content logic into generic trip points and register them with the thermal zone. Signed-off-by: Daniel Lezcano --- .../thermal/intel/intel_quark_dts_thermal.c | 45 ++++++++----------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index 3eafc6b0e6c3..e1b84ba59a20 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -84,6 +84,7 @@ #define QRK_DTS_MASK_TP_THRES 0xFF #define QRK_DTS_SHIFT_TP 8 #define QRK_DTS_ID_TP_CRITICAL 0 +#define QRK_DTS_ID_TP_HOT 1 #define QRK_DTS_SAFE_TP_THRES 105 /* Thermal Sensor Register Lock */ @@ -104,6 +105,7 @@ struct soc_sensor_entry { u32 store_ptps; u32 store_dts_enable; struct thermal_zone_device *tzone; + struct thermal_trip trips[QRK_MAX_DTS_TRIPS]; }; static struct soc_sensor_entry *soc_dts; @@ -172,7 +174,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) return ret; } -static int _get_trip_temp(int trip, int *temp) +static int get_trip_temp(int trip, int *temp) { int status; u32 out; @@ -197,17 +199,6 @@ static int _get_trip_temp(int trip, int *temp) return 0; } -static inline int sys_get_trip_temp(struct thermal_zone_device *tzd, - int trip, int *temp) -{ - return _get_trip_temp(trip, temp); -} - -static inline int sys_get_crit_temp(struct thermal_zone_device *tzd, int *temp) -{ - return _get_trip_temp(QRK_DTS_ID_TP_CRITICAL, temp); -} - static int update_trip_temp(struct soc_sensor_entry *aux_entry, int trip, int temp) { @@ -262,17 +253,6 @@ static inline int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, return update_trip_temp(tzd->devdata, trip, temp); } -static int sys_get_trip_type(struct thermal_zone_device *thermal, - int trip, enum thermal_trip_type *type) -{ - if (trip) - *type = THERMAL_TRIP_HOT; - else - *type = THERMAL_TRIP_CRITICAL; - - return 0; -} - static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp) { @@ -315,10 +295,7 @@ static int sys_change_mode(struct thermal_zone_device *tzd, static struct thermal_zone_device_ops tzone_ops = { .get_temp = sys_get_curr_temp, - .get_trip_temp = sys_get_trip_temp, - .get_trip_type = sys_get_trip_type, .set_trip_temp = sys_set_trip_temp, - .get_crit_temp = sys_get_crit_temp, .change_mode = sys_change_mode, }; @@ -344,7 +321,7 @@ static void free_soc_dts(struct soc_sensor_entry *aux_entry) static struct soc_sensor_entry *alloc_soc_dts(void) { struct soc_sensor_entry *aux_entry; - int err; + int err, temperature; u32 out; int wr_mask; @@ -385,6 +362,20 @@ static struct soc_sensor_entry *alloc_soc_dts(void) goto err_ret; } + err = get_trip_temp(QRK_DTS_ID_TP_CRITICAL, &temperature); + if (err) + goto err_ret; + + aux_entry->trips[QRK_DTS_ID_TP_CRITICAL].temperature = temperature; + aux_entry->trips[QRK_DTS_ID_TP_CRITICAL].type = THERMAL_TRIP_CRITICAL; + + err = get_trip_temp(QRK_DTS_ID_TP_HOT, &temperature); + if (err) + goto err_ret; + + aux_entry->trips[QRK_DTS_ID_TP_HOT].temperature = temperature; + aux_entry->trips[QRK_DTS_ID_TP_HOT].type = THERMAL_TRIP_HOT; + aux_entry->tzone = thermal_zone_device_register("quark_dts", QRK_MAX_DTS_TRIPS, wr_mask, From patchwork Mon Dec 12 20:58:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 32534 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2464123wrr; Mon, 12 Dec 2022 13:03:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf5IpmTZ/Uq17LhEl+wWBW/qzZFu7x/LyusjkNb8pMWe64Gyw0fE5W5pg3IlZZFm2CTD5Zm/ X-Received: by 2002:a17:906:844:b0:7ad:fd3e:8fd4 with SMTP id f4-20020a170906084400b007adfd3e8fd4mr13716105ejd.69.1670879029712; Mon, 12 Dec 2022 13:03:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670879029; cv=none; d=google.com; s=arc-20160816; b=l4uzPMEk1QIYHf/gf3hfl8BMw6686a2UDtQ1mHr9QKyd+o/PWj4cw+c64dnSCT/Zmc r676v330it+EwwYTKbRuCFBPktZeZMvG5Aj0qQRYerVx+Vic226ik/W+O3mo61P4BWrt 1xms5fbRIrapOHzfdJCQ7pkJ2zC4YFHKDq7qIHqu/HGqTcOFTjKxDQLBzv+ECn/sdEBV cj6zOm8uimBFRvxYMTxbQ/lK6EhOudgx7COsoB7pds0zNUg1GNzaoxi0HPUt5dKAgw/k 6fNYbrhYm2Zr2OJuIlmogaf10xX+WB0UKBhfcbGIjdE/ATgqxdVed5oXNWWOHj85dnEx zLfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NA+3KveRrg9ruS7yhZJv26q26XB54Sa3d5JjEMDw7bg=; b=vjPTBf+1PiiHQnaF8+ImDu5jXkVqekaLqpkcZKOl0N3+znH69yspkJ8DhQkHWe0I3W jFM/w1uNzvVqUyh5E789ZI7Cs7lMdDCsBPqEdmokXoEMqxHSzxWrYAaCpiic9GgQYuT0 lUFHiEbtzUsRuGze4zEuJgcuUAkmiei/fQZwO4M3ra2pZwIpjk0KQqeeE0RuvzzAMbS3 Tfee9SBQ8+43kejxp846NAC49OP1jFojfjfCZXTa38PLKM/onaTQ40oS1ASdhtWfXqGk 2l1k9LV9VCbensACqkd5EOS6AXY7H6Tp3r3TF6IZQBcaCa1886dvCOffF8rXw6flglld ZMag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XFBEiXZK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xf10-20020a17090731ca00b007c101c9237asi6280061ejb.668.2022.12.12.13.03.26; Mon, 12 Dec 2022 13:03:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XFBEiXZK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233403AbiLLU7X (ORCPT + 99 others); Mon, 12 Dec 2022 15:59:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233461AbiLLU7D (ORCPT ); Mon, 12 Dec 2022 15:59:03 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81FC41836E for ; Mon, 12 Dec 2022 12:59:02 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id b24-20020a05600c4a9800b003d21efdd61dso4873819wmp.3 for ; Mon, 12 Dec 2022 12:59:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NA+3KveRrg9ruS7yhZJv26q26XB54Sa3d5JjEMDw7bg=; b=XFBEiXZK2DmkoL5nXZrzn5zhqUKAjPF8ofrwYAzPTkxsQGc3mNpKAXj2Tu14S2Ajvn b0vlm2LEtCZHbbbyQvYMH5nIt0cdr83jUAXWMtDLHUMx2C/ZhlO9oVk7U+3qSEQ7b4v8 t4VLGw2LXJjou8IkZU4FrUk0D4BLbFqcLytzqrd86F23hSHIZ1brdk6n5i+eWh/sR2CL fEr/CvRYQ1cWchNTvo//UhFmPFK88osBNM7eoYW9rfoOp7ZQMU0SlSr0M6JIqlt2p6od wE2CFrI0B4FxH5Ptc+u1NgN/LlmQZbSOhB/7dXPrOSvEJ0sNOj1NCjUwkvKBm6qz49O0 v+8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=NA+3KveRrg9ruS7yhZJv26q26XB54Sa3d5JjEMDw7bg=; b=Fx/5tStB7KsdTXjHN9Dq9QdXEfzkD7PGUlCyo1ENx5wuuRKAY4r9YxUaj2AMNCwhkn bOMCOkiGP4bpfgb9QvC/qW4numIQFYH0F6VOx7aPpF3r2M7xFVhA0PKdbU0DhAL6gBEj SSr0vnrHXgFhhKdNeo2W/nJpt8LIRlXrHTO1VaggDDDt+9UpyoBXDFLFR9pRY/w5wXst BNTg3vWm8tZfOGIjosE7aT/15XToXK5GbQIN/SBD+/fxjkj+l9VcfUhp31RAmlF9NM49 pRSPWaTcBdMhu9akIOZ7C7crlw0eym0s/Qm5H8YNidmszcsyTVvgwTva7X7MEmppPQKT Xngg== X-Gm-Message-State: ANoB5pmBb9qfUOmsHkypKYFOy+dmRkx2/m1LT5ZngAh6zShyeY9r1xbS 40nkcznbfb/9Mq4IIi97OnWZjQ== X-Received: by 2002:a05:600c:5112:b0:3cf:8ed7:712d with SMTP id o18-20020a05600c511200b003cf8ed7712dmr13408312wms.14.1670878742051; Mon, 12 Dec 2022 12:59:02 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id t123-20020a1c4681000000b003a3170a7af9sm10537201wma.4.2022.12.12.12.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 12:59:01 -0800 (PST) From: Daniel Lezcano X-Google-Original-From: Daniel Lezcano To: rafael@kernel.org, srinivas.pandruvada@linux.intel.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] thermal/drivers/intel: Use generic trip points for processor_thermal_device_pci Date: Mon, 12 Dec 2022 21:58:43 +0100 Message-Id: <20221212205843.3119407-6-daniel.lezcano@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221212205843.3119407-1-daniel.lezcano@kernel.org> References: <20221212205843.3119407-1-daniel.lezcano@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752043649157729907?= X-GMAIL-MSGID: =?utf-8?q?1752043649157729907?= From: Daniel Lezcano The thermal framework gives the possibility to register the trip points with the thermal zone. When that is done, no get_trip_* ops are needed and they can be removed. Convert ops content logic into generic trip points and register them with the thermal zone. Signed-off-by: Daniel Lezcano --- .../processor_thermal_device_pci.c | 53 ++++++++----------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c index bf1b1cdfade4..c7d50862bf56 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c @@ -144,34 +144,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp) return 0; } -static int sys_get_trip_temp(struct thermal_zone_device *tzd, - int trip, int *temp) -{ - struct proc_thermal_pci *pci_info = tzd->devdata; - u32 _temp; - - proc_thermal_mmio_read(pci_info, PROC_THERMAL_MMIO_THRES_0, &_temp); - if (!_temp) { - *temp = THERMAL_TEMP_INVALID; - } else { - int tjmax; - - proc_thermal_mmio_read(pci_info, PROC_THERMAL_MMIO_TJMAX, &tjmax); - _temp = tjmax - _temp; - *temp = (unsigned long)_temp * 1000; - } - - return 0; -} - -static int sys_get_trip_type(struct thermal_zone_device *tzd, int trip, - enum thermal_trip_type *type) -{ - *type = THERMAL_TRIP_PASSIVE; - - return 0; -} - static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp) { struct proc_thermal_pci *pci_info = tzd->devdata; @@ -200,10 +172,26 @@ static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp return 0; } +static int get_trip_temp(struct proc_thermal_pci *pci_info) +{ + int temp, tjmax; + + proc_thermal_mmio_read(pci_info, PROC_THERMAL_MMIO_THRES_0, &temp); + if (!temp) + return THERMAL_TEMP_INVALID; + + proc_thermal_mmio_read(pci_info, PROC_THERMAL_MMIO_TJMAX, &tjmax); + temp = (tjmax - temp) * 1000; + + return temp; +} + +static struct thermal_trip psv_trip = { + .type = THERMAL_TRIP_PASSIVE, +}; + static struct thermal_zone_device_ops tzone_ops = { .get_temp = sys_get_curr_temp, - .get_trip_temp = sys_get_trip_temp, - .get_trip_type = sys_get_trip_type, .set_trip_temp = sys_set_trip_temp, }; @@ -251,7 +239,10 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_ if (ret) goto err_ret_thermal; - pci_info->tzone = thermal_zone_device_register("TCPU_PCI", 1, 1, pci_info, + psv_trip.temperature = get_trip_temp(pci_info); + + pci_info->tzone = thermal_zone_device_register_with_trips("TCPU_PCI", &psv_trip, + 1, 1, pci_info, &tzone_ops, &tzone_params, 0, 0); if (IS_ERR(pci_info->tzone)) {