Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp1840189rwb; Fri, 5 Aug 2022 08:37:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Te96Ofm7J8eoWd4CXn93YE0M37VRs66fY/YPmtGhz/m9IR77GKz/TsmPlvF2yv7aWozSf X-Received: by 2002:a17:90b:ec7:b0:1f2:fa08:44cd with SMTP id gz7-20020a17090b0ec700b001f2fa0844cdmr8144330pjb.183.1659713868345; Fri, 05 Aug 2022 08:37:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659713868; cv=none; d=google.com; s=arc-20160816; b=d9HKwXWiXUjUwBQ5K0gvgKli7SpF+6sVlBxopaaiF7uJ0lkKr4kK0sRWjLnnGtGxof Cs22/jINknKJWFwzWprve936ig61oR9nxWzF4sEW+mVUhJNm7wlw6zeqrBGyn9Rn3XYj aKLNxgiuhdfTQl09ZEump/1KLQzzrUTpYmBoM8AJDNvyB5Q00iZd2Q6LfCaa4V6ENsh6 s/dJKFdfK5tM7RGDe041KsoEH2lCgyZvzGSqQSM0ZZoz21g8arjDaSrjBVkDUqPXOUDD Ji4FMD1rGx2NtEDwGt+B3lzQaVnx4JE4+6ubqcrGPH5GN6JQqTOOOCvbEGDIx/CnZR9e exhw== 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=+LKPhNKLGEVFzXPLROXys6y1jDgivXC9DTGdXpCbdug=; b=LXNY7F77LA6PYfkEAIwmGoM/5xbQ60bmjzotG9fhGBtOsZyTa75kxiZDoKRi7GkX/U UqEle6YojjRruQ7zPc39nRYTq2iChFgIoUzDzIZiCq+JlApurETgUTilkaq5ov2lpuVG xdnBc3OSLojX/ETfAxDkCpihoTgK6Dn77VBdb7RIKHXFl/Ukz88Dtlb5kowL4fDBqHNF VTLaJIin/OoXqdvqLAw3COUveFlfsnBpsfDf69vhQ0ghitOy3R+zKsr6h2B9XuWqDTux 3OfH44roRohjUKUSbYBVdKNF+AdAbDzVG87jDo67WI1ioGBSJ/atvtC1tesPnaeDPYkb U4CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=esaMTjnp; 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 d11-20020a170903230b00b0016d510e28d0si4961011plh.40.2022.08.05.08.37.30; Fri, 05 Aug 2022 08:37:48 -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=esaMTjnp; 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 S241023AbiHEO7r (ORCPT + 99 others); Fri, 5 Aug 2022 10:59:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241161AbiHEO6p (ORCPT ); Fri, 5 Aug 2022 10:58:45 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A1076D572 for ; Fri, 5 Aug 2022 07:58:18 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id z12so3521183wrs.9 for ; Fri, 05 Aug 2022 07:58:18 -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; bh=+LKPhNKLGEVFzXPLROXys6y1jDgivXC9DTGdXpCbdug=; b=esaMTjnp69RL3woTrdc24TQt0JCs8qISF4KHdB2djLUrswQOeXm4f1WklijtlNaS8W y/Lb4HeyDgvShVesCqKsGyd1+kO6fLVgxMcftLr+sMbS/Hifl9STEeUOE4dwtDEToE6y DZyj99tqanRhk91LPmTtpFJbq4vMT/A74niwa3YHDhIiZev8NL5wwzqccBYvBOkJ2Ruc Xgjl3H7vC5E2PTXbfzrTUP3VRiHGRElS7IaVAU0FuWAJnaKAP6Dj/mYRbOVqG8Uxt6hN esVhoie2iQtM1rAPzjDUaQ5gZocv2ffH3WclUad+iXQc/i83mMZDvv5t8KCHxMgH0zus sWfQ== 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; bh=+LKPhNKLGEVFzXPLROXys6y1jDgivXC9DTGdXpCbdug=; b=cgE23t93w4IRGIbhXWHkp5xflXa4/S4EnFoh3+hWfwTk78F8mit2pJQKoKU+7VEVmi 9jl+lzqzIFF+Cg926Nvp1LTEuZAmQmJJD1fjTccSMzkah0fz5sleD3XeZsNwGQoNQY78 8XDq58AdY8tgGlxaKtSKlGXNPp3RH4JnkXjPBtVC4lW/G9kLU9QTV3YBe2Y4BU40META lBMq7DYqY/xnX5/kkvPPDMDubn+0eBQfKVK/qW+kf5/VxUVxrnczncCqGkNuX7pocAYa vTKY2Tehs4upl1aNVnPZmC0hzSjr/eZSGQEh1BVKI+6HRi184nPCDFTX3xx0vik2v3um 1C8w== X-Gm-Message-State: ACgBeo04URMeidQajP2BXeDU0Z8gft/bAWMudb4Vw9LLUx4WYejKjG9p 5MxWQDNMFfFnVi0I+2jzuRFk2Q== X-Received: by 2002:a5d:595f:0:b0:220:619d:da07 with SMTP id e31-20020a5d595f000000b00220619dda07mr4567517wri.10.1659711496782; Fri, 05 Aug 2022 07:58:16 -0700 (PDT) Received: from mai.box.freepro.com ([2a05:6e02:1041:c10:aef0:8606:da6b:79ef]) by smtp.gmail.com with ESMTPSA id y1-20020adfd081000000b0022159d92004sm3102448wrh.82.2022.08.05.07.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 07:58:16 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: rui.zhang@intel.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Kaestle , Hans de Goede , Mark Gross , platform-driver-x86@vger.kernel.org (open list:ACER ASPIRE ONE TEMPERATURE AND FAN DRIVER) Subject: [PATCH v1 23/26] thermal/drivers/acerhdf: Use generic thermal_zone_get_trip() function Date: Fri, 5 Aug 2022 16:57:26 +0200 Message-Id: <20220805145729.2491611-24-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220805145729.2491611-1-daniel.lezcano@linaro.org> References: <20220805145729.2491611-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,T_SCC_BODY_TEXT_LINE 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 --- 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..cf757f3a1e6b 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.25.1