From nobody Wed Nov 13 02:48:22 2024 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 AA60BE7D0CB for ; Fri, 22 Sep 2023 05:50:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231250AbjIVFuu (ORCPT ); Fri, 22 Sep 2023 01:50:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230504AbjIVFuk (ORCPT ); Fri, 22 Sep 2023 01:50:40 -0400 Received: from mxout1.routing.net (mxout1.routing.net [IPv6:2a03:2900:1:a::a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 030E3FB; Thu, 21 Sep 2023 22:50:29 -0700 (PDT) Received: from mxbox1.masterlogin.de (unknown [192.168.10.88]) by mxout1.routing.net (Postfix) with ESMTP id 2B12540551; Fri, 22 Sep 2023 05:50:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailerdienst.de; s=20200217; t=1695361828; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H4PGtOOvMqPAJvUztaljSdd3cxuehsc/o+gXiODesZ0=; b=obn2gtLmKsMbQ7oTfVG3YzYrZftXFejU2vWsy4x5Pd+z5Px6Sw1WnQvyLI0WNeK/d/uFs7 x+R9eFgmlu52E7Tyz8ruFx2RaVJ7YIAcPaDNfYPSSpN+yLH+jnI4w3q47q8jZeqlMCGkqz UqWyV7pLZvrJvgJpkMzoc/49xJ/BUkU= Received: from frank-G5.. (fttx-pool-217.61.149.125.bambit.de [217.61.149.125]) by mxbox1.masterlogin.de (Postfix) with ESMTPSA id 46C5B403BF; Fri, 22 Sep 2023 05:50:27 +0000 (UTC) From: Frank Wunderlich To: linux-mediatek@lists.infradead.org Cc: Frank Wunderlich , "Rafael J. Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 3/4] thermal/drivers/mediatek/lvts_thermal: make coeff configurable Date: Fri, 22 Sep 2023 07:50:19 +0200 Message-Id: <20230922055020.6436-4-linux@fw-web.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922055020.6436-1-linux@fw-web.de> References: <20230922055020.6436-1-linux@fw-web.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mail-ID: fa0f46da-b851-4668-a9a5-c9f39f15d774 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Frank Wunderlich The upcoming mt7988 has different temperature coefficients so we cannot use constants in the functions lvts_golden_temp_init, lvts_golden_temp_init and lvts_raw_to_temp anymore. Add a field in the lvts_ctrl pointing to the lvts_data which now contains the soc-specific temperature coefficents. To make the code better readable, rename static int coeff_b to golden_temp_offset, COEFF_A to temp_factor and COEFF_B to temp_offset. Signed-off-by: Frank Wunderlich Reviewed-by: AngeloGioacchino Del Regno Tested-by: Daniel Golle --- v2: - rename static int coeff_b to golden_temp_offset - rename coeff.a to temp_factor and coeff.b to temp_offset --- drivers/thermal/mediatek/lvts_thermal.c | 51 ++++++++++++++++--------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/medi= atek/lvts_thermal.c index effd9b00a424..c2669f405a94 100644 --- a/drivers/thermal/mediatek/lvts_thermal.c +++ b/drivers/thermal/mediatek/lvts_thermal.c @@ -80,8 +80,8 @@ #define LVTS_SENSOR_MAX 4 #define LVTS_GOLDEN_TEMP_MAX 62 #define LVTS_GOLDEN_TEMP_DEFAULT 50 -#define LVTS_COEFF_A -250460 -#define LVTS_COEFF_B 250460 +#define LVTS_COEFF_A_MT8195 -250460 +#define LVTS_COEFF_B_MT8195 250460 =20 #define LVTS_MSR_IMMEDIATE_MODE 0 #define LVTS_MSR_FILTERED_MODE 1 @@ -94,7 +94,7 @@ #define LVTS_MINIMUM_THRESHOLD 20000 =20 static int golden_temp =3D LVTS_GOLDEN_TEMP_DEFAULT; -static int coeff_b =3D LVTS_COEFF_B; +static int golden_temp_offset; =20 struct lvts_sensor_data { int dt_id; @@ -112,6 +112,8 @@ struct lvts_ctrl_data { struct lvts_data { const struct lvts_ctrl_data *lvts_ctrl; int num_lvts_ctrl; + int temp_factor; + int temp_offset; }; =20 struct lvts_sensor { @@ -126,6 +128,7 @@ struct lvts_sensor { =20 struct lvts_ctrl { struct lvts_sensor sensors[LVTS_SENSOR_MAX]; + const struct lvts_data *lvts_data; u32 calibration[LVTS_SENSOR_MAX]; u32 hw_tshut_raw_temp; int num_lvts_sensor; @@ -247,21 +250,21 @@ static void lvts_debugfs_exit(struct lvts_domain *lvt= s_td) { } =20 #endif =20 -static int lvts_raw_to_temp(u32 raw_temp) +static int lvts_raw_to_temp(u32 raw_temp, int temp_factor) { int temperature; =20 - temperature =3D ((s64)(raw_temp & 0xFFFF) * LVTS_COEFF_A) >> 14; - temperature +=3D coeff_b; + temperature =3D ((s64)(raw_temp & 0xFFFF) * temp_factor) >> 14; + temperature +=3D golden_temp_offset; =20 return temperature; } =20 -static u32 lvts_temp_to_raw(int temperature) +static u32 lvts_temp_to_raw(int temperature, int temp_factor) { - u32 raw_temp =3D ((s64)(coeff_b - temperature)) << 14; + u32 raw_temp =3D ((s64)(golden_temp_offset - temperature)) << 14; =20 - raw_temp =3D div_s64(raw_temp, -LVTS_COEFF_A); + raw_temp =3D div_s64(raw_temp, -temp_factor); =20 return raw_temp; } @@ -269,6 +272,9 @@ static u32 lvts_temp_to_raw(int temperature) static int lvts_get_temp(struct thermal_zone_device *tz, int *temp) { struct lvts_sensor *lvts_sensor =3D thermal_zone_device_priv(tz); + struct lvts_ctrl *lvts_ctrl =3D container_of(lvts_sensor, struct lvts_ctr= l, + sensors[lvts_sensor->id]); + const struct lvts_data *lvts_data =3D lvts_ctrl->lvts_data; void __iomem *msr =3D lvts_sensor->msr; u32 value; int rc; @@ -301,7 +307,7 @@ static int lvts_get_temp(struct thermal_zone_device *tz= , int *temp) if (rc) return -EAGAIN; =20 - *temp =3D lvts_raw_to_temp(value & 0xFFFF); + *temp =3D lvts_raw_to_temp(value & 0xFFFF, lvts_data->temp_factor); =20 return 0; } @@ -348,10 +354,13 @@ static bool lvts_should_update_thresh(struct lvts_ctr= l *lvts_ctrl, int high) static int lvts_set_trips(struct thermal_zone_device *tz, int low, int hig= h) { struct lvts_sensor *lvts_sensor =3D thermal_zone_device_priv(tz); - struct lvts_ctrl *lvts_ctrl =3D container_of(lvts_sensor, struct lvts_ctr= l, sensors[lvts_sensor->id]); + struct lvts_ctrl *lvts_ctrl =3D container_of(lvts_sensor, struct lvts_ctr= l, + sensors[lvts_sensor->id]); + const struct lvts_data *lvts_data =3D lvts_ctrl->lvts_data; void __iomem *base =3D lvts_sensor->base; - u32 raw_low =3D lvts_temp_to_raw(low !=3D -INT_MAX ? low : LVTS_MINIMUM_T= HRESHOLD); - u32 raw_high =3D lvts_temp_to_raw(high); + u32 raw_low =3D lvts_temp_to_raw(low !=3D -INT_MAX ? low : LVTS_MINIMUM_T= HRESHOLD, + lvts_data->temp_factor); + u32 raw_high =3D lvts_temp_to_raw(high, lvts_data->temp_factor); bool should_update_thresh; =20 lvts_sensor->low_thresh =3D low; @@ -692,7 +701,7 @@ static int lvts_calibration_read(struct device *dev, st= ruct lvts_domain *lvts_td return 0; } =20 -static int lvts_golden_temp_init(struct device *dev, u32 *value) +static int lvts_golden_temp_init(struct device *dev, u32 *value, int temp_= offset) { u32 gt; =20 @@ -701,7 +710,7 @@ static int lvts_golden_temp_init(struct device *dev, u3= 2 *value) if (gt && gt < LVTS_GOLDEN_TEMP_MAX) golden_temp =3D gt; =20 - coeff_b =3D golden_temp * 500 + LVTS_COEFF_B; + golden_temp_offset =3D golden_temp * 500 + temp_offset; =20 return 0; } @@ -724,7 +733,7 @@ static int lvts_ctrl_init(struct device *dev, struct lv= ts_domain *lvts_td, * The golden temp information is contained in the first chunk * of efuse data. */ - ret =3D lvts_golden_temp_init(dev, (u32 *)lvts_td->calib); + ret =3D lvts_golden_temp_init(dev, (u32 *)lvts_td->calib, lvts_data->temp= _offset); if (ret) return ret; =20 @@ -735,6 +744,7 @@ static int lvts_ctrl_init(struct device *dev, struct lv= ts_domain *lvts_td, for (i =3D 0; i < lvts_data->num_lvts_ctrl; i++) { =20 lvts_ctrl[i].base =3D lvts_td->base + lvts_data->lvts_ctrl[i].offset; + lvts_ctrl[i].lvts_data =3D lvts_data; =20 ret =3D lvts_sensor_init(dev, &lvts_ctrl[i], &lvts_data->lvts_ctrl[i]); @@ -758,7 +768,8 @@ static int lvts_ctrl_init(struct device *dev, struct lv= ts_domain *lvts_td, * after initializing the calibration. */ lvts_ctrl[i].hw_tshut_raw_temp =3D - lvts_temp_to_raw(lvts_data->lvts_ctrl[i].hw_tshut_temp); + lvts_temp_to_raw(lvts_data->lvts_ctrl[i].hw_tshut_temp, + lvts_data->temp_factor); =20 lvts_ctrl[i].low_thresh =3D INT_MIN; lvts_ctrl[i].high_thresh =3D INT_MIN; @@ -1223,6 +1234,8 @@ static int lvts_probe(struct platform_device *pdev) if (irq < 0) return irq; =20 + golden_temp_offset =3D lvts_data->temp_offset; + ret =3D lvts_domain_init(dev, lvts_td, lvts_data); if (ret) return dev_err_probe(dev, ret, "Failed to initialize the lvts domain\n"); @@ -1338,11 +1351,15 @@ static const struct lvts_ctrl_data mt8195_lvts_ap_d= ata_ctrl[] =3D { static const struct lvts_data mt8195_lvts_mcu_data =3D { .lvts_ctrl =3D mt8195_lvts_mcu_data_ctrl, .num_lvts_ctrl =3D ARRAY_SIZE(mt8195_lvts_mcu_data_ctrl), + .temp_factor =3D LVTS_COEFF_A_MT8195, + .temp_offset =3D LVTS_COEFF_B_MT8195, }; =20 static const struct lvts_data mt8195_lvts_ap_data =3D { .lvts_ctrl =3D mt8195_lvts_ap_data_ctrl, .num_lvts_ctrl =3D ARRAY_SIZE(mt8195_lvts_ap_data_ctrl), + .temp_factor =3D LVTS_COEFF_A_MT8195, + .temp_offset =3D LVTS_COEFF_B_MT8195, }; =20 static const struct of_device_id lvts_of_match[] =3D { --=20 2.34.1