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: 633847 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 19B02C4167B for ; Mon, 12 Dec 2022 20:59:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233445AbiLLU7D (ORCPT ); Mon, 12 Dec 2022 15:59:03 -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 S233360AbiLLU7B (ORCPT ); Mon, 12 Dec 2022 15:59:01 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 441D7183BB for ; Mon, 12 Dec 2022 12:59:00 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id b24-20020a05600c4a9800b003d21efdd61dso4873582wmp.3 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=10cZ7SncpfgEoQtQ83gooOODejPEMNmPwj0OUizvDIk2kPiNGke70rtdpAoxTRE852 lhZT8lbTIPigWWpDXGQcs+Np6ZVnsBMncJDSinkeyyqf6/Hk337eI3RIUF8ZRoh9Pnaf 7eLoNeuK7kIZ96WfgWJU0/FioUjfVf5VIJlGpKA345x8BXUIJejQF9eRE1+5BCcyMayo 0jMaDKzTjOA8POP1BTdChJFsnhuFB9lUHDSoO7ErmO4G5bX8xlQ7plyr2EtQ+j4obLVQ c/EmqwHKV3XnlsJQbMJdtlN0Lwn1AYOXaf71aAaV68DBcJQpxAxPaVljEFug4PRNzBbV KAqg== X-Gm-Message-State: ANoB5pldQAZatJtv1WPPwBxace73DAbRoKiIt6vk/BE349cKGtOBxCB4 MzX1rO0ygI/3IDIPi00tefke4A== 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 Precedence: bulk List-ID: X-Mailing-List: linux-pm@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. +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: 633444 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 9D3FCC00145 for ; Mon, 12 Dec 2022 20:59:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233502AbiLLU7E (ORCPT ); Mon, 12 Dec 2022 15:59:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233384AbiLLU7C (ORCPT ); Mon, 12 Dec 2022 15:59:02 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07A3D183B2 for ; Mon, 12 Dec 2022 12:59:01 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id ay2-20020a05600c1e0200b003d22e3e796dso669932wmb.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=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=5JNB/wUqrhrRiYxnynKMAo1CgB2UxH8rvMnkATE+Oo0tdLpznQe5ueOmmV9aHXGPtV /BhqF1p31hZvZhA/azM34+bMm6j5xe4RnX3KwyJKgymIDt59oWegE9PjInA21bkljw8Q GCC1qfnlvIvEGSfHT3vQVqrvDK2SIXjkcZzbk+so0AqVMPdKSsrHwS1yEh4hPeSLu0an gtOqMwmLvUXZYgLmZ7E9K23Nb3dpZLLgRbZfZHbe1RXrPtGcfnF0NBOAdiqYw8FHlBnM xuzkkxuOcnZRa7IluXKH7Q2WDMUcbIF0OPGfc6uvN4XXAxLR2jTJxK9Iq8hdSqAT76dY iXNQ== X-Gm-Message-State: ANoB5pkXeGWA5g8qurRRo8MitrYc4LAaootPbySh8HpP6RY2JaRStzsP P086UzLkq1v3G40KLNu4BYuEXA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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: 633846 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 E8C91C4708E for ; Mon, 12 Dec 2022 20:59:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232724AbiLLU7F (ORCPT ); Mon, 12 Dec 2022 15:59:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233320AbiLLU7D (ORCPT ); Mon, 12 Dec 2022 15:59:03 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECBC0164BE for ; Mon, 12 Dec 2022 12:59:01 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id n9-20020a05600c3b8900b003d0944dba41so6391266wms.4 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=XJ0NIKI9drmQQ9SymGgTnD6B3Aaa/CbtNLlAYvFpe6pSErATgBtFIjNnxwK2JMrPmS Uc5gtOKLUIUIBmCHqKVX3hmMUbpzfh9eu8VdRYbJrUaqzXvUOWR/XPiOc6oIh2opO2/H /ssLv9VD7zhuW0lDMlPEvskcB0SGlG0jSFtwRmJySNpC0RrnUiPx8VjxWfhqe8EyFX42 wzhtnH6FdzVnfxTqNZAMT+KRxJ9Tg22wCB54EtMghye24aLM32Ak4Yde3iSFtRAfVOBz KpzcBz3n65HXFMZofhzH1UGrb0LMl9qKwfUUsbxIxFRZMb8zWEWZfhf5qJGuY0jE4EVE WxbA== X-Gm-Message-State: ANoB5plOQCRNzR5mVpmvQVnStx2DnAQm1HOH/dzSb4OUANqLOuK3rtd5 s6m5mHny3FewHODFeozRO1mal+NYP9xxphn4 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 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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: 633845 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 EFD21C4167B for ; Mon, 12 Dec 2022 20:59:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233320AbiLLU7G (ORCPT ); Mon, 12 Dec 2022 15:59:06 -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 S233486AbiLLU7D (ORCPT ); Mon, 12 Dec 2022 15:59:03 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAB9B183A6 for ; Mon, 12 Dec 2022 12:59:02 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id ay14-20020a05600c1e0e00b003cf6ab34b61so6336385wmb.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=GGuAN0i5E48IIV2/v9jvrqtVwsTA1YObQnmG8ogqsyJCoE6PRJauYXQ/9aAGPXSkF8 1MFNo6rlQRQm9u52pWlF8i9ErxUhrPs7rKIid9VYwLfrbTMD+tdZw6vAZFaAWPc9/6xY wDsyg0+SlOv+tdOIsr412+JelBJQZ5FlsOXGfkil4koouO0iESlSea2N9m27A/sUnsF4 z7jciEaGUM1g1t/Wg7BvkuFKCY3VIAhrplcPBQ31CMpSmhXsFB5MNltnMXQqey3ZHuJo zx1fXV5SNClj4chAU/Vz35A1tG1RKEjxI0EAbKYUPRwfiokF2wAZZk7TwPEia9moZifY ErkA== X-Gm-Message-State: ANoB5pk+QjbAYwiHs3KCGpFaWvlRsHZDJmGCh3TVAouHWHNbDUycBZ9t WgnA097EqoxXwdt626KxTuF1d6Oi8O6v2PBe 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 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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: 633443 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 2856EC4332F for ; Mon, 12 Dec 2022 20:59:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232939AbiLLU7G (ORCPT ); Mon, 12 Dec 2022 15:59:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233483AbiLLU7D (ORCPT ); Mon, 12 Dec 2022 15:59:03 -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 83C3818385 for ; Mon, 12 Dec 2022 12:59:02 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id h8-20020a1c2108000000b003d1efd60b65so6363310wmh.0 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=mQcmYzU9kYDPZ7B1dlR7DwU8IQRKrViMbeDjOtBEqR0AGLhFEgrdZdRb4NOumfVvec weoVidsRUcSZdthns3hb5yI1d6lWEIevnOnWQRU4qDu0vP/wnO+0hLSHEKHTDwO4qCIi JUCeZ0RWcEnF9FitCOx36bwLfUIA6IR+LhF7Qw6Wxe7hgKHg0Pa0oDxS+XSYtgrCfLwJ DTGgJbLHpR1hw1sw7cP1ftXIxTK9KNeRw52wY6A2zrwfR5T0ku2rl+Duxjbf3YnhWHfI jNfehNaOajBnhjPyGOQCjsE3yOdCzjDuuSA5V9gWnwUpkIkZ/gmMsFHHawCah6w7I9iV IZmg== X-Gm-Message-State: ANoB5pnFSVeWYMsL91iSyHsOtjSaVAioPoxc1X0WHd/twyA4RNamh6fV QCnfJw3/sVz+4tRPUMMwH/TLMQ== 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 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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)) {