Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2897031rdh; Wed, 27 Sep 2023 16:58:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG+yOD7hMRY4LI8n0dn4enWHE71U2pDvvmxJ89AX55LGyPfZq+w8eetLZGfQLbm6a7wssYf X-Received: by 2002:a05:620a:24d1:b0:774:33ce:cfb6 with SMTP id m17-20020a05620a24d100b0077433cecfb6mr4392778qkn.30.1695859122853; Wed, 27 Sep 2023 16:58:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695859122; cv=none; d=google.com; s=arc-20160816; b=O4BORQQy7f3OfdCK+63TVFIfdfSTkICNc4od6L2m+KFDAEkNmCVkDF2/L6gbkbRFD4 FzfiqGFIhBzfEg9Ng8PUnZp87oEMm+r/VbhbQDPg5WyM8PgEK6E7vmKyRDOfVWU6W5aU rd/gGuC2vZGUpSkLhTsh+IHY/SMUYCpiyUqAWfnFLm5Qg9oGUWpnsbpFAKWUKpV42iaX MwgLyqsq5yXVU8q0rvIBuzk0EI+UfTD1tkw0qMZmswUM3jHumVrwULmwcqYbF/HZCy6S kRSbXsP8i/+kLitbVoVG+OVfCf0EndA33QaNLJ0o7SdnfPnBoq03uvp2QrGha9eTHP97 GAsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=2Oa9PhK2HCjBmslfzXLy5vObhdyE6uzbu1UDnb+QV7M=; fh=RUzbxWHvSVmG9f5NGnFIwatA5HtYoryXZbFjtHfJ8t0=; b=bKUB6oQriNrTLIoAFWQG8KEP+kql6+9x2oFym3zSEbkkiFaddqd70LKhXj8kJbW732 D/UkEruZF8USh76I3ZJ+Ia19F8ZNfjDRHPKJL01jNjWRODkzvMR9awdloQBsXS1WJXMo xEkT6XFwA2qLv4sNJMI/TSZYiXgBDYzqMwx5yu5phX4CbjxEJC89m/2V31dA/hHFaERL v//7xWckgidXgQ+C0U4LskuWLx/KrMp1cJ0oy5zx5zEZ6gr8aXtK0RauFNunvkwrdcJG W258malwcWnC5z0EvQ2nT3mK3bF3Nbw6j59pXiexCt6cxxdKzk4OE2JiYOMrVC1vHGkw bXKQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id s16-20020a656450000000b0057759a5b7dasi17071164pgv.827.2023.09.27.16.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 16:58:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 72AB7826EC1A; Wed, 27 Sep 2023 16:58:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229539AbjI0X6L (ORCPT + 99 others); Wed, 27 Sep 2023 19:58:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbjI0X6K (ORCPT ); Wed, 27 Sep 2023 19:58:10 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC8CCF4; Wed, 27 Sep 2023 16:58:08 -0700 (PDT) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1qlePg-00049j-38; Wed, 27 Sep 2023 23:57:53 +0000 Date: Thu, 28 Sep 2023 00:55:33 +0100 From: Daniel Golle To: Frank Wunderlich Cc: linux-mediatek@lists.infradead.org, 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: Re: [PATCH v3 3/4] thermal/drivers/mediatek/lvts_thermal: make coeff configurable Message-ID: References: <20230922055020.6436-1-linux@fw-web.de> <20230922055020.6436-4-linux@fw-web.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230922055020.6436-4-linux@fw-web.de> X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 27 Sep 2023 16:58:25 -0700 (PDT) On Fri, Sep 22, 2023 at 07:50:19AM +0200, Frank Wunderlich wrote: > 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/mediatek/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 > > #define LVTS_MSR_IMMEDIATE_MODE 0 > #define LVTS_MSR_FILTERED_MODE 1 > @@ -94,7 +94,7 @@ > #define LVTS_MINIMUM_THRESHOLD 20000 > > static int golden_temp = LVTS_GOLDEN_TEMP_DEFAULT; > -static int coeff_b = LVTS_COEFF_B; > +static int golden_temp_offset; > > 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; > }; > > struct lvts_sensor { > @@ -126,6 +128,7 @@ struct lvts_sensor { > > 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 *lvts_td) { } > > #endif > > -static int lvts_raw_to_temp(u32 raw_temp) > +static int lvts_raw_to_temp(u32 raw_temp, int temp_factor) > { > int temperature; > > - temperature = ((s64)(raw_temp & 0xFFFF) * LVTS_COEFF_A) >> 14; > - temperature += coeff_b; > + temperature = ((s64)(raw_temp & 0xFFFF) * temp_factor) >> 14; > + temperature += golden_temp_offset; > > return temperature; > } > > -static u32 lvts_temp_to_raw(int temperature) > +static u32 lvts_temp_to_raw(int temperature, int temp_factor) > { > - u32 raw_temp = ((s64)(coeff_b - temperature)) << 14; > + u32 raw_temp = ((s64)(golden_temp_offset - temperature)) << 14; > > - raw_temp = div_s64(raw_temp, -LVTS_COEFF_A); > + raw_temp = div_s64(raw_temp, -temp_factor); > > 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 = thermal_zone_device_priv(tz); > + struct lvts_ctrl *lvts_ctrl = container_of(lvts_sensor, struct lvts_ctrl, > + sensors[lvts_sensor->id]); > + const struct lvts_data *lvts_data = lvts_ctrl->lvts_data; > void __iomem *msr = 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; > > - *temp = lvts_raw_to_temp(value & 0xFFFF); > + *temp = lvts_raw_to_temp(value & 0xFFFF, lvts_data->temp_factor); > > return 0; > } > @@ -348,10 +354,13 @@ static bool lvts_should_update_thresh(struct lvts_ctrl *lvts_ctrl, int high) > static int lvts_set_trips(struct thermal_zone_device *tz, int low, int high) > { > struct lvts_sensor *lvts_sensor = thermal_zone_device_priv(tz); > - struct lvts_ctrl *lvts_ctrl = container_of(lvts_sensor, struct lvts_ctrl, sensors[lvts_sensor->id]); > + struct lvts_ctrl *lvts_ctrl = container_of(lvts_sensor, struct lvts_ctrl, > + sensors[lvts_sensor->id]); > + const struct lvts_data *lvts_data = lvts_ctrl->lvts_data; > void __iomem *base = lvts_sensor->base; > - u32 raw_low = lvts_temp_to_raw(low != -INT_MAX ? low : LVTS_MINIMUM_THRESHOLD); > - u32 raw_high = lvts_temp_to_raw(high); > + u32 raw_low = lvts_temp_to_raw(low != -INT_MAX ? low : LVTS_MINIMUM_THRESHOLD, > + lvts_data->temp_factor); > + u32 raw_high = lvts_temp_to_raw(high, lvts_data->temp_factor); > bool should_update_thresh; > > lvts_sensor->low_thresh = low; > @@ -692,7 +701,7 @@ static int lvts_calibration_read(struct device *dev, struct lvts_domain *lvts_td > return 0; > } > > -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; > > @@ -701,7 +710,7 @@ static int lvts_golden_temp_init(struct device *dev, u32 *value) > if (gt && gt < LVTS_GOLDEN_TEMP_MAX) > golden_temp = gt; > > - coeff_b = golden_temp * 500 + LVTS_COEFF_B; > + golden_temp_offset = golden_temp * 500 + temp_offset; > > return 0; > } > @@ -724,7 +733,7 @@ static int lvts_ctrl_init(struct device *dev, struct lvts_domain *lvts_td, > * The golden temp information is contained in the first chunk > * of efuse data. > */ > - ret = lvts_golden_temp_init(dev, (u32 *)lvts_td->calib); > + ret = lvts_golden_temp_init(dev, (u32 *)lvts_td->calib, lvts_data->temp_offset); > if (ret) > return ret; > > @@ -735,6 +744,7 @@ static int lvts_ctrl_init(struct device *dev, struct lvts_domain *lvts_td, > for (i = 0; i < lvts_data->num_lvts_ctrl; i++) { > > lvts_ctrl[i].base = lvts_td->base + lvts_data->lvts_ctrl[i].offset; > + lvts_ctrl[i].lvts_data = lvts_data; > > ret = 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 lvts_domain *lvts_td, > * after initializing the calibration. > */ > lvts_ctrl[i].hw_tshut_raw_temp = > - 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); > > lvts_ctrl[i].low_thresh = INT_MIN; > lvts_ctrl[i].high_thresh = INT_MIN; > @@ -1223,6 +1234,8 @@ static int lvts_probe(struct platform_device *pdev) > if (irq < 0) > return irq; > > + golden_temp_offset = lvts_data->temp_offset; > + > ret = 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_data_ctrl[] = { > static const struct lvts_data mt8195_lvts_mcu_data = { > .lvts_ctrl = mt8195_lvts_mcu_data_ctrl, > .num_lvts_ctrl = ARRAY_SIZE(mt8195_lvts_mcu_data_ctrl), > + .temp_factor = LVTS_COEFF_A_MT8195, > + .temp_offset = LVTS_COEFF_B_MT8195, > }; > > static const struct lvts_data mt8195_lvts_ap_data = { > .lvts_ctrl = mt8195_lvts_ap_data_ctrl, > .num_lvts_ctrl = ARRAY_SIZE(mt8195_lvts_ap_data_ctrl), > + .temp_factor = LVTS_COEFF_A_MT8195, > + .temp_offset = LVTS_COEFF_B_MT8195, > }; > > static const struct of_device_id lvts_of_match[] = { > -- > 2.34.1 >