Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp25582rwb; Mon, 26 Sep 2022 08:51:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4eKf+DGM/JVLIZs/wJrtdhOXlvRFKiU+rhbl4X22hWSg+werM6QH4iBms4atN4wcSExMS1 X-Received: by 2002:a63:6bc9:0:b0:43a:9316:84df with SMTP id g192-20020a636bc9000000b0043a931684dfmr21156233pgc.118.1664207517021; Mon, 26 Sep 2022 08:51:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664207517; cv=none; d=google.com; s=arc-20160816; b=vO9HQfe6DUq2zOA+NixOnjDaY/5uqkhikrZcAmZxAiLga+FnCq20LyNQ2Ze7+vJNMH 9y2tBhVsgPd1x5hMgTzdtWPpVFKq+tLYsndAvA5zSPnRYv/2gr4DDGw1+N3XdEwMkuxk jLhIHW3Kdr8wcOR625MgqriPVm+iDbkFB/LGlWRPEzuyic0yV/woJ8hVsXtqScwNSaFp sc2rWWyVbTRAA6EdeNUmWiut4d4Q2bLCUcGLSgQxByeGYLFnbFTOWm/drlClx3VZhm4M YZtH5OqsrA2k5igP1TMDdLVoLZpqu7MVHcfDd6wkli13tGAinMSHOyGyh9rBtq/cqEqQ dn2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Bvo7EJO01qiFSqaGbT4JiAGDEh8uk0vvz3ltgjeJ4xY=; b=uIulrizsFXkx217wPqILjM5tVs02w+xeJ58clbN73zKODqYAHbMmGu9eRjbq9V/FJZ iLg7va36tv7M9fg0Snt/zm8Rw690I1sONd9MT+oWcBtjCEReEcwxwsqcA6Qs9kENQO8s lAmgpAB5gf9OrltW6vbjLcN57otpfZAUDn42bDcSMoQ+1S/gsyBIHdLxdkNNCdEJo7jD XihB/I19VM11ZtI3nl++2Tv14AYMJtHqZecL2B9lUc7YKRLh5yMEmLHnlA21zuYVBdrk WG6+dasXBhu7+/5mViEmYV0SwydvQIn/u+zAmRsVxuL+BVU4PWh+TDgQI9rDTDJiwG9Z NnpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FAE2j0go; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z6-20020a1709027e8600b0016eef21566dsi10941444pla.198.2022.09.26.08.51.42; Mon, 26 Sep 2022 08:51:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FAE2j0go; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236413AbiIZPVo (ORCPT + 99 others); Mon, 26 Sep 2022 11:21:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236202AbiIZPUQ (ORCPT ); Mon, 26 Sep 2022 11:20:16 -0400 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 56E85832EF for ; Mon, 26 Sep 2022 07:06:59 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id fn7-20020a05600c688700b003b4fb113b86so3818278wmb.0 for ; Mon, 26 Sep 2022 07:06:59 -0700 (PDT) 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; bh=Bvo7EJO01qiFSqaGbT4JiAGDEh8uk0vvz3ltgjeJ4xY=; b=FAE2j0go+IJoVbSOEoS/wABZka52n31gX/OBRtsHZ8JZMRuxdBmePkjjo6z/BlAixW Pdm00JdDcaKRRkjyQ8WHjxQagb6jLtuqz6exeGmeI7a9YSv7ASu9hvageY7giMSIICna sHbrYljjkAeh/kKUtshKIdkadD5fQjyoqCgOtqo6JScf6eAapxVquUYwhwLuHzWWzWpM Re/KHDXfteQtRlnZd3g6lCsjAMxhC4Hm0dl/qhDjsOSJHgH11828dCx/MrjxpBD1PviK 8Fjd/AVPS+3o0SUvr8X2DXR30b6iSdptr1EHIxIoRoASaUS0mLopFtXLAv834cXxkgmJ EPvA== 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; bh=Bvo7EJO01qiFSqaGbT4JiAGDEh8uk0vvz3ltgjeJ4xY=; b=AVUq7sZo/XtsGJVLqFjDYYwFympXGP4xRilEwgVk9cRD0LDPwpf0i0GL9woGSUf6uh ReJKK/2/7YK1NqQKz3kx0vMfD6YUnwHRGINwHwW/A+KVsfik19Mpo8zNeg+b3FxkrHDd pwZRMIMXmH5OKUfALqbsfs2ZOs7umiqx+aoxY+j+/YPota97iJbdKzTxCgM1JLIGyEU3 ylHiurPKYXFs52keHnsffM/NGLynYIVDMBEBYkB+KbQSAfdFMX+2G4iTX2lZqjvPrNxM 2sFSM53hb5PJOxoafqcatdTds8WGfOiQtEWaUawMUpWDb75hw3wVrBai3PPvtil8CGsQ qBVw== X-Gm-Message-State: ACrzQf1MquSI4I6jEEVJYyommhrE6pIIVpEZpb6PLG+0rAbWeZVaoRso tp9uFxxCtzSVjo2AZAb2Ey3RFw== X-Received: by 2002:a05:600c:3b1f:b0:3b4:b1fc:4797 with SMTP id m31-20020a05600c3b1f00b003b4b1fc4797mr22405991wms.129.1664201217638; Mon, 26 Sep 2022 07:06:57 -0700 (PDT) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id v3-20020adfebc3000000b0022adf321d22sm14310731wrn.92.2022.09.26.07.06.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 07:06:57 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rui.zhang@intel.com, Hans de Goede , =?UTF-8?q?Peter=20K=C3=A4stle?= , Mark Gross , platform-driver-x86@vger.kernel.org (open list:ACER ASPIRE ONE TEMPERATURE AND FAN DRIVER) Subject: [PATCH v5 27/30] thermal/drivers/acerhdf: Use generic thermal_zone_get_trip() function Date: Mon, 26 Sep 2022 16:06:01 +0200 Message-Id: <20220926140604.4173723-28-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220926140604.4173723-1-daniel.lezcano@linaro.org> References: <20220926140604.4173723-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Hans de Goede Acked-by: Peter Kästle --- drivers/platform/x86/acerhdf.c | 73 ++++++++++++---------------------- 1 file changed, 26 insertions(+), 47 deletions(-) diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 3463629f8764..a7407aa032ba 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -46,6 +46,8 @@ * measured by the on-die thermal monitor are within 0 <= Tj <= 90. So, * assume 89°C is critical temperature. */ +#define ACERHDF_DEFAULT_TEMP_FANON 60000 +#define ACERHDF_DEFAULT_TEMP_FANOFF 53000 #define ACERHDF_TEMP_CRIT 89000 #define ACERHDF_FAN_OFF 0 #define ACERHDF_FAN_AUTO 1 @@ -70,8 +72,8 @@ static int kernelmode; #endif static unsigned int interval = 10; -static unsigned int fanon = 60000; -static unsigned int fanoff = 53000; +static unsigned int fanon = ACERHDF_DEFAULT_TEMP_FANON; +static unsigned int fanoff = ACERHDF_DEFAULT_TEMP_FANOFF; static unsigned int verbose; static unsigned int list_supported; static unsigned int fanstate = ACERHDF_FAN_AUTO; @@ -137,6 +139,15 @@ struct ctrl_settings { int mcmd_enable; }; +static struct thermal_trip trips[] = { + [0] = { .temperature = ACERHDF_DEFAULT_TEMP_FANON, + .hysteresis = ACERHDF_DEFAULT_TEMP_FANON - ACERHDF_DEFAULT_TEMP_FANOFF, + .type = THERMAL_TRIP_ACTIVE }, + + [1] = { .temperature = ACERHDF_TEMP_CRIT, + .type = THERMAL_TRIP_CRITICAL } +}; + static struct ctrl_settings ctrl_cfg __read_mostly; /* Register addresses and values for different BIOS versions */ @@ -326,6 +337,15 @@ static void acerhdf_check_param(struct thermal_zone_device *thermal) fanon = ACERHDF_MAX_FANON; } + if (fanon < fanoff) { + pr_err("fanoff temperature (%d) is above fanon temperature (%d), clamping to %d\n", + fanoff, fanon, fanon); + fanoff = fanon; + }; + + trips[0].temperature = fanon; + trips[0].hysteresis = fanon - fanoff; + if (kernelmode && prev_interval != interval) { if (interval > ACERHDF_MAX_INTERVAL) { pr_err("interval too high, set to %d\n", @@ -424,43 +444,6 @@ static int acerhdf_change_mode(struct thermal_zone_device *thermal, return 0; } -static int acerhdf_get_trip_type(struct thermal_zone_device *thermal, int trip, - enum thermal_trip_type *type) -{ - if (trip == 0) - *type = THERMAL_TRIP_ACTIVE; - else if (trip == 1) - *type = THERMAL_TRIP_CRITICAL; - else - return -EINVAL; - - return 0; -} - -static int acerhdf_get_trip_hyst(struct thermal_zone_device *thermal, int trip, - int *temp) -{ - if (trip != 0) - return -EINVAL; - - *temp = fanon - fanoff; - - return 0; -} - -static int acerhdf_get_trip_temp(struct thermal_zone_device *thermal, int trip, - int *temp) -{ - if (trip == 0) - *temp = fanon; - else if (trip == 1) - *temp = ACERHDF_TEMP_CRIT; - else - return -EINVAL; - - return 0; -} - static int acerhdf_get_crit_temp(struct thermal_zone_device *thermal, int *temperature) { @@ -474,13 +457,9 @@ static struct thermal_zone_device_ops acerhdf_dev_ops = { .unbind = acerhdf_unbind, .get_temp = acerhdf_get_ec_temp, .change_mode = acerhdf_change_mode, - .get_trip_type = acerhdf_get_trip_type, - .get_trip_hyst = acerhdf_get_trip_hyst, - .get_trip_temp = acerhdf_get_trip_temp, .get_crit_temp = acerhdf_get_crit_temp, }; - /* * cooling device callback functions * get maximal fan cooling state @@ -710,10 +689,10 @@ static int __init acerhdf_register_thermal(void) if (IS_ERR(cl_dev)) return -EINVAL; - thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, - &acerhdf_dev_ops, - &acerhdf_zone_params, 0, - (kernelmode) ? interval*1000 : 0); + thz_dev = thermal_zone_device_register_with_trips("acerhdf", trips, ARRAY_SIZE(trips), + 0, NULL, &acerhdf_dev_ops, + &acerhdf_zone_params, 0, + (kernelmode) ? interval*1000 : 0); if (IS_ERR(thz_dev)) return -EINVAL; -- 2.34.1