From nobody Thu Sep 18 01:29:06 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F1CCC4332F for ; Mon, 12 Dec 2022 20:59:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233530AbiLLU7N (ORCPT ); Mon, 12 Dec 2022 15:59:13 -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-Google-Smtp-Source: AA0mqf4mWPGMOANgJMv+aAiyaKdO+h48WiDvKrWNIQgl0yFdbapiYOOfOY92WFHsq9Y1ir7YE/7n/Q== 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. =20 +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) +=3D thermal_netli= nk.o # interface to/from other layers providing sensors thermal_sys-$(CONFIG_THERMAL_HWMON) +=3D thermal_hwmon.o thermal_sys-$(CONFIG_THERMAL_OF) +=3D thermal_of.o +thermal_sys-$(CONFIG_THERMAL_ACPI) +=3D thermal_acpi.o =20 # governors thermal_sys-$(CONFIG_THERMAL_GOV_FAIR_SHARE) +=3D 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 + *=20 + * 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 =3D 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=E2=80= =99s + * current operating temperature. The return value is the current + * temperature of the thermal zone in tenths of degrees Kelvin + */ + status =3D acpi_evaluate_integer(adev->handle, "_TMP", NULL, &temp); + if (ACPI_FAILURE(status)) + return -EIO; + + *temperature =3D deci_kelvin_to_millicelsius(temp); +=09 + 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=E2=80= =99s + * driver evaluates this object to determine the device=E2=80=99s critica= l cooling + * temperature trip point. This value may then be used by the device=E2= =80=99s + * driver to program an internal device temperature sensor trip point + */ + status =3D acpi_evaluate_integer(adev->handle, "_CRT", NULL, &temp); + if (ACPI_FAILURE(status)) + return -EIO; + + trip->hysteresis =3D thermal_acpi_trip_gtsh(adev); + trip->temperature =3D deci_kelvin_to_millicelsius(temp); + trip->type =3D THERMAL_TRIP_CRITICAL; + + return 0; +} + +int thermal_acpi_trip_hot(struct acpi_device *adev, struct thermal_trip *t= rip) +{ + 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=20 + * present under a device, the device=E2=80=99s driver evaluates this obj= ect to + * determine the device=E2=80=99s hot cooling temperature trip point. Thi= s value + * may then be used by the device=E2=80=99s driver to program an internal= device + * temperature sensor trip point. + */ + status =3D acpi_evaluate_integer(adev->handle, "_HOT", NULL, &temp); + if (ACPI_FAILURE(status)) + return -EIO; + + trip->hysteresis =3D thermal_acpi_trip_gtsh(adev); + trip->temperature =3D deci_kelvin_to_millicelsius(temp); + trip->type =3D THERMAL_TRIP_HOT; + + return 0; +} + +int thermal_acpi_trip_psl(struct acpi_device *adev, struct acpi_handle_lis= t *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 cooli= ng + */ + status =3D 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; +=09 + /* + * _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 =3D 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 =3D 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; +=09 + /* + * _TC2 (Thermal Constant 1): This object evaluates to the constant _TC2 + * for use in the Passive cooling formula + */ + status =3D 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 *t= rip) +{ + 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 =3D 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 =3D thermal_acpi_trip_gtsh(adev); + trip->temperature =3D deci_kelvin_to_millicelsius(temp); + trip->type =3D 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];=09 + + /* + * _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 =3D 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];=09 + + /* + * _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, =E2=80=9Con=E2=80=9D) 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=E2=80=99s active coo= ling + * relationship list. + */ + sprintf(name, "_AC%d", id); + + status =3D acpi_evaluate_integer(adev->handle, name, NULL, &temp); + if (ACPI_FAILURE(status)) + return -EINVAL; + + trip->hysteresis =3D thermal_acpi_trip_gtsh(adev); + trip->temperature =3D deci_kelvin_to_millicelsius(temp); + trip->type =3D 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(str= uct device *dev, } #endif =20 +#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 *t= rip); +int thermal_acpi_trip_psv(struct acpi_device *adev, struct thermal_trip *t= rip); +int thermal_acpi_trip_act(struct acpi_device *adev, struct thermal_trip *t= rip, int id); +int thermal_acpi_trip_acl(struct acpi_device *adev, struct acpi_handle_lis= t *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); =20 --=20 2.34.1 From nobody Thu Sep 18 01:29:06 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D0D5C4332F for ; Mon, 12 Dec 2022 20:59:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232815AbiLLU7S (ORCPT ); Mon, 12 Dec 2022 15:59:18 -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-Google-Smtp-Source: AA0mqf6M+3z4aOSxMec5JcF2s7JYiGIZ/kzBrGS+ekFQ8yz6aU8PvIcszv1GRPXS9JF9GHFLf1qY+w== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 t= he 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/in= tel/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) =20 +#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 =3D 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; }; =20 @@ -102,33 +99,22 @@ static void pch_wpt_add_acpi_psv_trip(struct pch_therm= al_device *ptd, int *nr_trips) { struct acpi_device *adev; - - ptd->psv_trip_id =3D -1; + int ret; =20 adev =3D ACPI_COMPANION(&ptd->pdev->dev); - if (adev) { - unsigned long long r; - acpi_status status; - - status =3D acpi_evaluate_integer(adev->handle, "_PSV", NULL, - &r); - if (ACPI_SUCCESS(status)) { - unsigned long trip_temp; - - trip_temp =3D deci_kelvin_to_millicelsius(r); - if (trip_temp) { - ptd->psv_temp =3D trip_temp; - ptd->psv_trip_id =3D *nr_trips; - ++(*nr_trips); - } - } - } + if (!adev) + return; + =09 + ret =3D 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 =3D -1; =20 } #endif @@ -163,21 +149,19 @@ static int pch_wpt_init(struct pch_thermal_device *pt= d, int *nr_trips) } =20 read_trips: - ptd->crt_trip_id =3D -1; trip_temp =3D readw(ptd->hw_base + WPT_CTT); trip_temp &=3D 0x1FF; if (trip_temp) { - ptd->crt_temp =3D GET_WPT_TEMP(trip_temp); - ptd->crt_trip_id =3D 0; + ptd->trips[*nr_trips].temperature =3D GET_WPT_TEMP(trip_temp); + ptd->trips[*nr_trips].type =3D THERMAL_TRIP_CRITICAL; ++(*nr_trips); } =20 - ptd->hot_trip_id =3D -1; trip_temp =3D readw(ptd->hw_base + WPT_PHL); trip_temp &=3D 0x1FF; if (trip_temp) { - ptd->hot_temp =3D GET_WPT_TEMP(trip_temp); - ptd->hot_trip_id =3D *nr_trips; + ptd->trips[*nr_trips].temperature =3D GET_WPT_TEMP(trip_temp); + ptd->trips[*nr_trips].type =3D THERMAL_TRIP_HOT; ++(*nr_trips); } =20 @@ -298,39 +282,6 @@ static int pch_thermal_get_temp(struct thermal_zone_de= vice *tzd, int *temp) return ptd->ops->get_temp(ptd, temp); } =20 -static int pch_get_trip_type(struct thermal_zone_device *tzd, int trip, - enum thermal_trip_type *type) -{ - struct pch_thermal_device *ptd =3D tzd->devdata; - - if (ptd->crt_trip_id =3D=3D trip) - *type =3D THERMAL_TRIP_CRITICAL; - else if (ptd->hot_trip_id =3D=3D trip) - *type =3D THERMAL_TRIP_HOT; - else if (ptd->psv_trip_id =3D=3D trip) - *type =3D THERMAL_TRIP_PASSIVE; - else - return -EINVAL; - - return 0; -} - -static int pch_get_trip_temp(struct thermal_zone_device *tzd, int trip, in= t *temp) -{ - struct pch_thermal_device *ptd =3D tzd->devdata; - - if (ptd->crt_trip_id =3D=3D trip) - *temp =3D ptd->crt_temp; - else if (ptd->hot_trip_id =3D=3D trip) - *temp =3D ptd->hot_temp; - else if (ptd->psv_trip_id =3D=3D trip) - *temp =3D 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 *tz= d) =20 static struct thermal_zone_device_ops tzd_ops =3D { .get_temp =3D pch_thermal_get_temp, - .get_trip_type =3D pch_get_trip_type, - .get_trip_temp =3D pch_get_trip_temp, .critical =3D pch_critical, }; =20 @@ -423,8 +372,9 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev, if (err) goto error_cleanup; =20 - ptd->tzd =3D thermal_zone_device_register(bi->name, nr_trips, 0, ptd, - &tzd_ops, NULL, 0, 0); + ptd->tzd =3D 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); --=20 2.34.1 From nobody Thu Sep 18 01:29:06 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B669C4332F for ; Mon, 12 Dec 2022 20:59:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232478AbiLLU7W (ORCPT ); Mon, 12 Dec 2022 15:59:22 -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-Google-Smtp-Source: AA0mqf6H9JvOqLzvNzLNx4/Gr0yRURerDP93sdiLL0OHVviHRtKjYoJVlLgCr2BdIRZYZtP2M8s3JA== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 t= he 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; } =20 -static int int340x_thermal_get_trip_temp(struct thermal_zone_device *zone, - int trip, int *temp) -{ - struct int34x_thermal_zone *d =3D zone->devdata; - int i; - - if (trip < d->aux_trip_nr) - *temp =3D d->aux_trips[trip]; - else if (trip =3D=3D d->crt_trip_id) - *temp =3D d->crt_temp; - else if (trip =3D=3D d->psv_trip_id) - *temp =3D d->psv_temp; - else if (trip =3D=3D d->hot_trip_id) - *temp =3D d->hot_temp; - else { - for (i =3D 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) { - if (d->act_trips[i].valid && - d->act_trips[i].id =3D=3D trip) { - *temp =3D d->act_trips[i].temp; - break; - } - } - if (i =3D=3D 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 =3D zone->devdata; - int i; - - if (trip < d->aux_trip_nr) - *type =3D THERMAL_TRIP_PASSIVE; - else if (trip =3D=3D d->crt_trip_id) - *type =3D THERMAL_TRIP_CRITICAL; - else if (trip =3D=3D d->hot_trip_id) - *type =3D THERMAL_TRIP_HOT; - else if (trip =3D=3D d->psv_trip_id) - *type =3D THERMAL_TRIP_PASSIVE; - else { - for (i =3D 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) { - if (d->act_trips[i].valid && - d->act_trips[i].id =3D=3D trip) { - *type =3D THERMAL_TRIP_ACTIVE; - break; - } - } - if (i =3D=3D 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; =20 - d->aux_trips[trip] =3D temp; - - return 0; -} - - -static int int340x_thermal_get_trip_hyst(struct thermal_zone_device *zone, - int trip, int *temp) -{ - struct int34x_thermal_zone *d =3D zone->devdata; - acpi_status status; - unsigned long long hyst; - - status =3D acpi_evaluate_integer(d->adev->handle, "GTSH", NULL, &hyst); - if (ACPI_FAILURE(status)) - *temp =3D 0; - else - *temp =3D hyst * 100; - return 0; } =20 @@ -138,58 +60,36 @@ static void int340x_thermal_critical(struct thermal_zo= ne_device *zone) =20 static struct thermal_zone_device_ops int340x_thermal_zone_ops =3D { .get_temp =3D int340x_thermal_get_zone_temp, - .get_trip_temp =3D int340x_thermal_get_trip_temp, - .get_trip_type =3D int340x_thermal_get_trip_type, .set_trip_temp =3D int340x_thermal_set_trip_temp, - .get_trip_hyst =3D int340x_thermal_get_trip_hyst, .critical =3D int340x_thermal_critical, }; =20 -static int int340x_thermal_get_trip_config(acpi_handle handle, char *name, - int *temp) -{ - unsigned long long r; - acpi_status status; - - status =3D acpi_evaluate_integer(handle, name, NULL, &r); - if (ACPI_FAILURE(status)) - return -EIO; - - *temp =3D deci_kelvin_to_millicelsius(r); - - return 0; -} - int int340x_thermal_read_trips(struct int34x_thermal_zone *int34x_zone) { - int trip_cnt =3D int34x_zone->aux_trip_nr; - int i; + int trip_cnt; + int i, ret; =20 - int34x_zone->crt_trip_id =3D -1; - if (!int340x_thermal_get_trip_config(int34x_zone->adev->handle, "_CRT", - &int34x_zone->crt_temp)) - int34x_zone->crt_trip_id =3D trip_cnt++; + trip_cnt =3D int34x_zone->aux_trip_nr; +=09 + ret =3D thermal_acpi_trip_crit(int34x_zone->adev, &int34x_zone->trips[tri= p_cnt]); + if (!ret) + trip_cnt++; =20 - int34x_zone->hot_trip_id =3D -1; - if (!int340x_thermal_get_trip_config(int34x_zone->adev->handle, "_HOT", - &int34x_zone->hot_temp)) - int34x_zone->hot_trip_id =3D trip_cnt++; + ret =3D thermal_acpi_trip_hot(int34x_zone->adev, &int34x_zone->trips[trip= _cnt]); + if (!ret) + trip_cnt++; =20 - int34x_zone->psv_trip_id =3D -1; - if (!int340x_thermal_get_trip_config(int34x_zone->adev->handle, "_PSV", - &int34x_zone->psv_temp)) - int34x_zone->psv_trip_id =3D trip_cnt++; + ret =3D thermal_acpi_trip_psv(int34x_zone->adev, &int34x_zone->trips[trip= _cnt]); + if (!ret) + trip_cnt++; =20 for (i =3D 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) { - char name[5] =3D { '_', 'A', 'C', '0' + i, '\0' }; =20 - if (int340x_thermal_get_trip_config(int34x_zone->adev->handle, - name, - &int34x_zone->act_trips[i].temp)) + ret =3D thermal_acpi_trip_act(int34x_zone->adev, &int34x_zone->trips[tri= p_cnt], i); + if (ret) break; =20 - int34x_zone->act_trips[i].id =3D trip_cnt++; - int34x_zone->act_trips[i].valid =3D true; + trip_cnt++; } =20 return trip_cnt; @@ -208,7 +108,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(st= ruct acpi_device *adev, acpi_status status; unsigned long long trip_cnt; int trip_mask =3D 0; - int ret; + int i, ret; =20 int34x_thermal_zone =3D 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 =3D get_temp; =20 status =3D acpi_evaluate_integer(adev->handle, "PATC", NULL, &trip_cnt); - if (ACPI_FAILURE(status)) - trip_cnt =3D 0; - else { - int i; - - int34x_thermal_zone->aux_trips =3D - kcalloc(trip_cnt, - sizeof(*int34x_thermal_zone->aux_trips), - GFP_KERNEL); - if (!int34x_thermal_zone->aux_trips) { - ret =3D -ENOMEM; - goto err_trip_alloc; - } - trip_mask =3D BIT(trip_cnt) - 1; + if (!ACPI_FAILURE(status)) { int34x_thermal_zone->aux_trip_nr =3D trip_cnt; - for (i =3D 0; i < trip_cnt; ++i) - int34x_thermal_zone->aux_trips[i] =3D THERMAL_TEMP_INVALID; + trip_mask =3D BIT(trip_cnt) - 1; } =20 + int34x_thermal_zone->trips =3D kzalloc(sizeof(*int34x_thermal_zone->trips= ) * + (INT340X_THERMAL_MAX_TRIP_COUNT + trip_cnt), + GFP_KERNEL); + if (!int34x_thermal_zone->trips) { + ret =3D -ENOMEM; + goto err_trips_alloc; + } + + for (i =3D 0; i < trip_cnt; ++i) { + int34x_thermal_zone->trips[i].hysteresis =3D thermal_acpi_trip_gtsh(adev= ); + int34x_thermal_zone->trips[i].type =3D THERMAL_TRIP_PASSIVE; + int34x_thermal_zone->trips[i].temperature =3D THERMAL_TEMP_INVALID; + } +=09 trip_cnt =3D int340x_thermal_read_trips(int34x_thermal_zone); =20 int34x_thermal_zone->lpat_table =3D acpi_lpat_get_conversion_table( adev->handle); =20 - int34x_thermal_zone->zone =3D thermal_zone_device_register( + int34x_thermal_zone->zone =3D 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(st= ruct 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 =20 #define INT340X_THERMAL_MAX_ACT_TRIP_COUNT 10 +#define INT340X_THERMAL_MAX_TRIP_COUNT INT340X_THERMAL_MAX_ACT_TRIP_COUNT = + 3 =20 struct active_trip { int temp; @@ -19,15 +20,8 @@ struct active_trip { =20 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; --=20 2.34.1 From nobody Thu Sep 18 01:29:06 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB71BC4332F for ; Mon, 12 Dec 2022 20:59:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233351AbiLLU7a (ORCPT ); Mon, 12 Dec 2022 15:59:30 -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-Google-Smtp-Source: AA0mqf5VBYPgm0onB+SyQgvrccbh2wKHUADfGhuH0e6Su9I2j8upq5c61XbPXTj5dyZ31EUxz4/k4Q== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 t= he 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/ther= mal/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 =20 /* 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]; }; =20 static struct soc_sensor_entry *soc_dts; @@ -172,7 +174,7 @@ static int soc_dts_disable(struct thermal_zone_device *= tzd) return ret; } =20 -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; } =20 -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_zon= e_device *tzd, int trip, return update_trip_temp(tzd->devdata, trip, temp); } =20 -static int sys_get_trip_type(struct thermal_zone_device *thermal, - int trip, enum thermal_trip_type *type) -{ - if (trip) - *type =3D THERMAL_TRIP_HOT; - else - *type =3D 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, =20 static struct thermal_zone_device_ops tzone_ops =3D { .get_temp =3D sys_get_curr_temp, - .get_trip_temp =3D sys_get_trip_temp, - .get_trip_type =3D sys_get_trip_type, .set_trip_temp =3D sys_set_trip_temp, - .get_crit_temp =3D sys_get_crit_temp, .change_mode =3D sys_change_mode, }; =20 @@ -344,7 +321,7 @@ static void free_soc_dts(struct soc_sensor_entry *aux_e= ntry) 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; =20 @@ -385,6 +362,20 @@ static struct soc_sensor_entry *alloc_soc_dts(void) goto err_ret; } =20 + err =3D get_trip_temp(QRK_DTS_ID_TP_CRITICAL, &temperature); + if (err) + goto err_ret; + + aux_entry->trips[QRK_DTS_ID_TP_CRITICAL].temperature =3D temperature; + aux_entry->trips[QRK_DTS_ID_TP_CRITICAL].type =3D THERMAL_TRIP_CRITICAL; + + err =3D get_trip_temp(QRK_DTS_ID_TP_HOT, &temperature); + if (err) + goto err_ret; + + aux_entry->trips[QRK_DTS_ID_TP_HOT].temperature =3D temperature; + aux_entry->trips[QRK_DTS_ID_TP_HOT].type =3D THERMAL_TRIP_HOT; + aux_entry->tzone =3D thermal_zone_device_register("quark_dts", QRK_MAX_DTS_TRIPS, wr_mask, --=20 2.34.1 From nobody Thu Sep 18 01:29:06 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D60C0C4332F for ; Mon, 12 Dec 2022 20:59:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233051AbiLLU7Z (ORCPT ); Mon, 12 Dec 2022 15:59:25 -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-Google-Smtp-Source: AA0mqf77gK6MBlHNY2R1SfZaRZScpv+zMDwVIbji4lzVE6w/F0nq/SOFmWhu9J+nCBYY3vUtqothJw== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 t= he 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_devic= e *tzd, int *temp) return 0; } =20 -static int sys_get_trip_temp(struct thermal_zone_device *tzd, - int trip, int *temp) -{ - struct proc_thermal_pci *pci_info =3D tzd->devdata; - u32 _temp; - - proc_thermal_mmio_read(pci_info, PROC_THERMAL_MMIO_THRES_0, &_temp); - if (!_temp) { - *temp =3D THERMAL_TEMP_INVALID; - } else { - int tjmax; - - proc_thermal_mmio_read(pci_info, PROC_THERMAL_MMIO_TJMAX, &tjmax); - _temp =3D tjmax - _temp; - *temp =3D (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 =3D THERMAL_TRIP_PASSIVE; - - return 0; -} - static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, in= t temp) { struct proc_thermal_pci *pci_info =3D tzd->devdata; @@ -200,10 +172,26 @@ static int sys_set_trip_temp(struct thermal_zone_devi= ce *tzd, int trip, int temp return 0; } =20 +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 =3D (tjmax - temp) * 1000; + + return temp; +} + +static struct thermal_trip psv_trip =3D { + .type =3D THERMAL_TRIP_PASSIVE, +}; + static struct thermal_zone_device_ops tzone_ops =3D { .get_temp =3D sys_get_curr_temp, - .get_trip_temp =3D sys_get_trip_temp, - .get_trip_type =3D sys_get_trip_type, .set_trip_temp =3D sys_set_trip_temp, }; =20 @@ -251,7 +239,10 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev= , const struct pci_device_ if (ret) goto err_ret_thermal; =20 - pci_info->tzone =3D thermal_zone_device_register("TCPU_PCI", 1, 1, pci_in= fo, + psv_trip.temperature =3D get_trip_temp(pci_info); +=09 + pci_info->tzone =3D 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)) { --=20 2.34.1