Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4679020rwb; Tue, 6 Sep 2022 10:53:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR7R6H9mx9hXTFR3ANw+XofsCMHTl95T7Ge9ZSbpYEoApnnMYGwiT67wIxSyTgfG2nYC5EzZ X-Received: by 2002:a17:907:2cd4:b0:73c:9fa8:3ddc with SMTP id hg20-20020a1709072cd400b0073c9fa83ddcmr31064601ejc.40.1662486781540; Tue, 06 Sep 2022 10:53:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662486781; cv=none; d=google.com; s=arc-20160816; b=FqRUbEgocAC0SYBkBl6Gyx8Pup1FeXWVC0JZ5+ZXr34fnpaSssQdk8/TwCf6SyuW2i igKT12wGcomIbQs69/FD2u43J04g5FVe+BNzJ6P491mrzVs2JyVmOZiuIbtMdKpiENC6 B2/Pm5PjsNaX4tUpBp5lnmDGkP6evXpf4E16qW+P1ZHSuU9sMV4IozNmkO3RYyfsICRp 1BB3E0K+0M0/6b/iu5LGxQC8bjiO2Orpb8O5gvEzkoyZ4anJTuuT2eSkApPAMns9J/WY QJbBwPuS1qOw7BIVpfViVjO/3BZcWUc9AWjJXIXwaG2p10SOmX7tGCEczYvR0OdXPoAu K3jQ== 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=BFbiLufC2pQN7Jbu6EdCIWoqvW2z7pY1CtRNmqMNBtBz6s1jjMa4V576yoa70wxd3V +p6JDdAKTYkQ3fu3IN0U1/hPY2Avdz2JTL4/WKpEjJ0d+v/hFNqsc/smO/DEHThMtCWv tOKOHG6prBAC9jbMCFoJh/+r73u9NgChQjIFennPcUhshIFAFJ/fnBFn1mRXVQF6XbiU NJ/jPwQPwCdtJG/EDUVQb0fVhh5syeyomRNH+Fx3ChOpQOSufuHniYJ1bXYT2PYpuy4F /sn6tPGYba/gYExzP6LpD8/qJtpyW36YthKPDISqu6iHpJmIz2QNd0tCsvbeeQ5wtjmS FcKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PCzElyvI; 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 p26-20020a056402501a00b004437a9fcc07si10258484eda.361.2022.09.06.10.52.35; Tue, 06 Sep 2022 10:53:01 -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=PCzElyvI; 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 S239521AbiIFRDh (ORCPT + 99 others); Tue, 6 Sep 2022 13:03:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238584AbiIFRBo (ORCPT ); Tue, 6 Sep 2022 13:01:44 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88AD495E49 for ; Tue, 6 Sep 2022 09:48:13 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id b16so16355857wru.7 for ; Tue, 06 Sep 2022 09:48:12 -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=PCzElyvISj5qWfubEWFk/604t2S+HL6Am3VsTrI8JH6HFKBPnnHUuVAK3RZu5VQbnZ yZ+kKc2PVSmX98UhEMyD23ay7DopBE5dm9+J7/YOEuJDwEv8LBhEnw5491up/s8dkcsv M1hgUvo+MT9iWH8gOOwv4n2TWF/8xgK0slBLWsUXS30Pw2eGWsrz2Nly4pdHY+/htqtZ yZgUn/Dhxo+J27UkQJsZfByJHXD4kxwxYFyCIE79kjBDcynuyUUnM1+bObFVJYCNMmf9 EwquFk2g6UfDNf97PS1S/mSca1F6T62XchlkX5yja//6RgmwT2ZDuVjEC2cM4A7tlAjB kO1A== 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=NuIStoqbuZCqN9BNPxl1H3YOuU+WZtyDv5xgnQlxeUT640CYT/X+RdEFg8nbTW57wL 14aqwcIQAAlRjsKx0wzaHR9d3z1/B8v21kSP0YvDZzHuAupt2KYJwi1xQ4M4nezbDaTB O7R20OtwS7PXawaBdPXnSkGFTXdqJbBljEKdGriQGOn2lNndYBxNCfsm4UYI2SdWSOXa 0Jxb8EpgdKCw1UYL01RbBYWEf0pfBkFcAI7SEYlaBV55hpAuBdZ+bxF3lgpRCQoFjF/y xcIcCgw4GgMKbf5s6eWHYlMFkOXNTnpNNFZl0E7psmjBjwyZ68SOEb/24r+Rkw0/LPU9 Y9tg== X-Gm-Message-State: ACgBeo2IlMt08hahXsHFj0zY53R5T8TlfbZKgz3z9HrJ5eHWa5Dyj56h 3Sdjz1LTQYFLSOsNZAkdm+AmZw== X-Received: by 2002:a5d:58cb:0:b0:228:dc7f:b9b3 with SMTP id o11-20020a5d58cb000000b00228dc7fb9b3mr1427048wrf.98.1662482891357; Tue, 06 Sep 2022 09:48:11 -0700 (PDT) Received: from localhost.localdomain (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id e27-20020adf9bdb000000b0021f0ff1bc6csm7426600wrc.41.2022.09.06.09.48.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 09:48:11 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, 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 v3 27/30] thermal/drivers/acerhdf: Use generic thermal_zone_get_trip() function Date: Tue, 6 Sep 2022 18:47:17 +0200 Message-Id: <20220906164720.330701-28-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220906164720.330701-1-daniel.lezcano@linaro.org> References: <20220906164720.330701-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 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