From patchwork Wed Jun 7 10:47:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Gerhold X-Patchwork-Id: 104408 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp166536vqr; Wed, 7 Jun 2023 03:59:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7KHKTPrGabswi0LqaEmu/pMYwSTO0CGGbLlD0haZdMFVLi+ubFW+j0xlH+9BH08Mv34jET X-Received: by 2002:a05:6870:c356:b0:1a2:aaf7:434d with SMTP id e22-20020a056870c35600b001a2aaf7434dmr4580494oak.17.1686135560898; Wed, 07 Jun 2023 03:59:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686135560; cv=none; d=google.com; s=arc-20160816; b=pMfNGNmJEY7H0a085NOB++tzM0Q8ezeKcmFkuQyKFLl8OPXSFFiQfrDw/rRCPjS2lm rp+gyRmi/t3FC59fE86bjk/F7GTJ4DdoKX6X8QjQDzfK6gYp/WHIUi8G9AG9yNMvCsN9 ZvDvoSh1rMPyZzGoE6ysVHKOijws7hhFEwalcmrWFNgXEjiScloyEqIdcQnoiCJLF+LT kaLQx4Vu4BGBH0NBvSI9fGOaKLBHxg0WT8biy+DENimZKvnZysaglepsyOaA+Q7LOvO+ tJj2yZqDkTN5fzHGcxXw4DvJepT2pD+Dzvz2qbYjK8PzOHmUFexQJYhn/HtAWt+98DBl MPTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=kO6sjhQBSRSoH1BkSxRydzvO3qYJnTGlIeFcyYdMhD0=; b=eZs8/7MPKJB3zy9G7KdoUnykwxlh/uKYJvgdn/ETJLUSKbQWvrhWPrhNMu2hceola7 155eSCWMU6cEk12VUOyUJdXI9u5TgiEie22nVh9lrCa/fPdc14y3NO1dazyNbfL1fVSj RPzV6RLMhOJtD3G9OHk/+nRl3WEKll90zugMlUpbdjDaPCXGo1syFEO3HpyPUyUa4Eul 71Eww1gfJOPLdNV+WPVoHIImLi25yoe/jwTfIQy4aHQsPFI2yXT/ypOaE2avvx3zThvg nahQtVvnwNRJlIcgrHSt88wWbGpmE0k/2ZIQuJ9C7DacWVn4WGVkIefSc5mreZX0Bb3b L08g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernkonzept.com header.s=mx1 header.b=hd7mtU+u; 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=kernkonzept.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u3-20020a637903000000b0053f23ffad17si8685591pgc.420.2023.06.07.03.59.08; Wed, 07 Jun 2023 03:59:20 -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=@kernkonzept.com header.s=mx1 header.b=hd7mtU+u; 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=kernkonzept.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239533AbjFGKs2 (ORCPT + 99 others); Wed, 7 Jun 2023 06:48:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237833AbjFGKsP (ORCPT ); Wed, 7 Jun 2023 06:48:15 -0400 Received: from mx.kernkonzept.com (serv1.kernkonzept.com [IPv6:2a01:4f8:1c1c:b490::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C6FFAA; Wed, 7 Jun 2023 03:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kernkonzept.com; s=mx1; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From: Reply-To:Content-ID:Content-Description; bh=kO6sjhQBSRSoH1BkSxRydzvO3qYJnTGlIeFcyYdMhD0=; b=hd7mtU+u2uDSLCRGtpYOlVAqge h9gesXqkwvb/toekdgyfbwXbQQ54Z05Oxcz1a9PZH+4DXwLcY8j0YO6gwcqkFE0UYtSDOyAJRFSAJ qOM36zM8KyDx7oLURgDOoQO/DP2Urnp0tLqZ5kfEwNPoFYJG0OjCmjKIK/vTExomsAEoz2fFoffiX rt42gNnb6ylsFaI0kguCRJr2PZvwv/VD33kRIdjljQQRgcUIK4m1zgHvuCA8hJpItXeUJQ4/cZn1a IAPQTbxCNijBb7XbJ15Qur3kwfpVftBZbYINmXHqd6H3A5vp/u+RLzqFIlNAiwGzYW+1Bh4VWFGqX 2s2vzHbQ==; Received: from [10.22.3.24] (helo=serv1.dd1.int.kernkonzept.com) by mx.kernkonzept.com with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) id 1q6qhu-0069NL-Or; Wed, 07 Jun 2023 12:48:02 +0200 From: Stephan Gerhold Date: Wed, 07 Jun 2023 12:47:46 +0200 Subject: [PATCH v5 3/6] thermal: qcom: tsens-v0_1: Add mdm9607 correction offsets MIME-Version: 1.0 Message-Id: <20230508-msm8909-tsens-v5-3-5eb632235ba7@kernkonzept.com> References: <20230508-msm8909-tsens-v5-0-5eb632235ba7@kernkonzept.com> In-Reply-To: <20230508-msm8909-tsens-v5-0-5eb632235ba7@kernkonzept.com> To: Daniel Lezcano Cc: Amit Kucheria , Thara Gopinath , Andy Gross , Bjorn Andersson , Konrad Dybcio , "Rafael J. Wysocki" , Zhang Rui , Dmitry Baryshkov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Stephan Gerhold , Stephan Gerhold X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768041281884275999?= X-GMAIL-MSGID: =?utf-8?q?1768041281884275999?= According to the msm-3.18 vendor kernel from Qualcomm, mdm9607 needs "correction factors" to adjust for additional offsets observed after the factory calibration values in the fuses [1, 2]. The fixed offsets should be applied unless there is a special calibration mode value that indicates that no offsets are needed [3]. Note that the new calibration mode values are called differently in this patch compared to the vendor kernel: - TSENS_TWO_POINT_CALIB_N_WA -> ONE_PT_CALIB2_NO_OFFSET - TSENS_TWO_POINT_CALIB_N_OFFSET_WA -> TWO_PT_CALIB_NO_OFFSET This is because close inspection of the calibration function [3] reveals that TSENS_TWO_POINT_CALIB_N_WA is actually a "one point" calibration because the if statements skip all "point2" related code for it. [1]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/commit/d9d2db1b82bf3f72f5de0803d55e6849eb5b671e [2]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/commit/d75aef53a760e8ff7bac54049d00c8b2ee1b193e [3]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LE.UM.4.3.2.r1-04200-9x07/drivers/thermal/msm-tsens.c#L2987-3136 Fixes: a2149ab815fc ("thermal/drivers/qcom/tsens-v0_1: Add support for MDM9607") Reviewed-by: Konrad Dybcio Reviewed-by: Dmitry Baryshkov Signed-off-by: Stephan Gerhold --- drivers/thermal/qcom/tsens-v0_1.c | 11 +++++++++++ drivers/thermal/qcom/tsens.c | 16 +++++++++++++++- drivers/thermal/qcom/tsens.h | 4 ++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c index 9802ae1d4fcf..4a55a8ea0043 100644 --- a/drivers/thermal/qcom/tsens-v0_1.c +++ b/drivers/thermal/qcom/tsens-v0_1.c @@ -241,6 +241,17 @@ static int __init init_9607(struct tsens_priv *priv) for (i = 0; i < priv->num_sensors; ++i) priv->sensor[i].slope = 3000; + priv->sensor[0].p1_calib_offset = 1; + priv->sensor[0].p2_calib_offset = 1; + priv->sensor[1].p1_calib_offset = -4; + priv->sensor[1].p2_calib_offset = -2; + priv->sensor[2].p1_calib_offset = 4; + priv->sensor[2].p2_calib_offset = 8; + priv->sensor[3].p1_calib_offset = -3; + priv->sensor[3].p2_calib_offset = -5; + priv->sensor[4].p1_calib_offset = -4; + priv->sensor[4].p2_calib_offset = -4; + return init_common(priv); } diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index 1c457b55efb3..9dd5e4b70911 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -134,10 +134,12 @@ int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2, p1[i] = p1[i] + (base1 << shift); break; case TWO_PT_CALIB: + case TWO_PT_CALIB_NO_OFFSET: for (i = 0; i < priv->num_sensors; i++) p2[i] = (p2[i] + base2) << shift; fallthrough; case ONE_PT_CALIB2: + case ONE_PT_CALIB2_NO_OFFSET: for (i = 0; i < priv->num_sensors; i++) p1[i] = (p1[i] + base1) << shift; break; @@ -149,6 +151,18 @@ int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2, } } + /* Apply calibration offset workaround except for _NO_OFFSET modes */ + switch (mode) { + case TWO_PT_CALIB: + for (i = 0; i < priv->num_sensors; i++) + p2[i] += priv->sensor[i].p2_calib_offset; + fallthrough; + case ONE_PT_CALIB2: + for (i = 0; i < priv->num_sensors; i++) + p1[i] += priv->sensor[i].p1_calib_offset; + break; + } + return mode; } @@ -254,7 +268,7 @@ void compute_intercept_slope(struct tsens_priv *priv, u32 *p1, if (!priv->sensor[i].slope) priv->sensor[i].slope = SLOPE_DEFAULT; - if (mode == TWO_PT_CALIB) { + if (mode == TWO_PT_CALIB || mode == TWO_PT_CALIB_NO_OFFSET) { /* * slope (m) = adc_code2 - adc_code1 (y2 - y1)/ * temp_120_degc - temp_30_degc (x2 - x1) diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h index 433eba370998..1cd8f4fe0971 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -10,6 +10,8 @@ #define ONE_PT_CALIB 0x1 #define ONE_PT_CALIB2 0x2 #define TWO_PT_CALIB 0x3 +#define ONE_PT_CALIB2_NO_OFFSET 0x6 +#define TWO_PT_CALIB_NO_OFFSET 0x7 #define CAL_DEGC_PT1 30 #define CAL_DEGC_PT2 120 #define SLOPE_FACTOR 1000 @@ -57,6 +59,8 @@ struct tsens_sensor { unsigned int hw_id; int slope; u32 status; + int p1_calib_offset; + int p2_calib_offset; }; /**