From patchwork Fri Jul 26 11:01:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Majewski X-Patchwork-Id: 13742594 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E5FB9C3DA49 for ; Fri, 26 Jul 2024 11:03:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:References:Content-Type: Content-Transfer-Encoding:MIME-Version:In-Reply-To:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pPk3cJw9Upb64u9gbv/wgoHU4phpR3fMcYIsKwH4ySA=; b=UZllquJcevqd8fBArGNMFzCw83 ilninMTBlUTklStarmaOFBOSJMcZd14BJCyOJK19AJ2IhyLeP2Z1hdHMaIWfaDA2L+5YAO/9eWn9h woOUju30LxJqHygzOsdNU8zGhqtBQR1Je0N3gzzw/v2oe9GsPyAPvHLiMgorB9V+QReIkeyo35cfZ WATBeE6NvG2ELDRDB1cLxktmMH+MkAo1xL8lSjnTM8eUD1A+3QGiXaCvh+0m8vVbTOvI1XcMQq5JJ hmZmdvQ4KM/0Lji55bmCzeP0ATPoKct2iBtj+4K7ded9yDhhU36KwDFgfSDoXN+59iR8aCy/j2W/j Oa0theLg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXIjY-00000003dDd-03rc; Fri, 26 Jul 2024 11:03:36 +0000 Received: from mailout1.w1.samsung.com ([210.118.77.11]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXIhi-00000003ccs-2ZiN for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 11:01:44 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240726110139euoutp01a3a3695280ca18ddf77cece04b53227b~lvlO5QzMv0353403534euoutp01g for ; Fri, 26 Jul 2024 11:01:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240726110139euoutp01a3a3695280ca18ddf77cece04b53227b~lvlO5QzMv0353403534euoutp01g DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1721991699; bh=pPk3cJw9Upb64u9gbv/wgoHU4phpR3fMcYIsKwH4ySA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kLb5vKlierHg17rFQjMbD1hEvpX0GPesLrqRTJRYhv8pfBG4mOBwN0ZMmQ7nog3HC mGu+lsA3uZOaK+kXdaCyVoOQzwzxjNqWZginifGLHfR/oxw5S246yxRwXjNfRleD53 PoyCXMh+V9UZVhRr7GXhw12e/2GeHu9g4njK7+hc= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20240726110138eucas1p16d34d9cacaf57c5bb4d9f06f3271ea49~lvlOharvv1888618886eucas1p1I; Fri, 26 Jul 2024 11:01:38 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id A2.72.09620.21283A66; Fri, 26 Jul 2024 12:01:38 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240726110138eucas1p27f33fb42af84ba7938703796c3f80727~lvlOAWaEE2810128101eucas1p2A; Fri, 26 Jul 2024 11:01:38 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240726110138eusmtrp23ea3e0d8abe81a2cfdd0a5fb0fec5998~lvlN-nDji1722517225eusmtrp2T; Fri, 26 Jul 2024 11:01:38 +0000 (GMT) X-AuditID: cbfec7f5-d1bff70000002594-d4-66a38212571a Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 82.27.08810.21283A66; Fri, 26 Jul 2024 12:01:38 +0100 (BST) Received: from AMDC4515.eu.corp.samsungelectronics.net (unknown [106.120.51.28]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240726110137eusmtip20d1f2f32995ec671fa09edbd2e7c3c49~lvlNED4v92391923919eusmtip2g; Fri, 26 Jul 2024 11:01:37 +0000 (GMT) From: Mateusz Majewski To: linux-pm@vger.kernel.org, linux-samsung-soc@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Mateusz Majewski , Bartlomiej Zolnierkiewicz , Krzysztof Kozlowski , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Conor Dooley , Alim Akhtar , Sam Protsenko , Anand Moon Subject: [PATCH v2 3/6] drivers/thermal/exynos: improve sanitize_temp_error Date: Fri, 26 Jul 2024 13:01:07 +0200 Message-ID: <20240726110114.1509733-4-m.majewski2@samsung.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240726110114.1509733-1-m.majewski2@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrLKsWRmVeSWpSXmKPExsWy7djP87pCTYvTDD7OM7R4MG8bm8X3LdeZ LNbsPcdkMe+zrMX8I+dYLc6f38BusenxNVaLy7vmsFl87j3CaDHj/D4mi3Ubb7FbLGxqYbeY e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7vzBnvw3KuPT4sVpV38LLz2yc15mrxJL cUaioRZzUXEiAJ+QUVpRAwAA X-CMS-MailID: 20240726110138eucas1p27f33fb42af84ba7938703796c3f80727 X-Msg-Generator: CA X-RootMTR: 20240726110138eucas1p27f33fb42af84ba7938703796c3f80727 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240726110138eucas1p27f33fb42af84ba7938703796c3f80727 References: <20240726110114.1509733-1-m.majewski2@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_040142_962991_7FDB3826 X-CRM114-Status: GOOD ( 21.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There are two minor issues regarding this function. One is that it attempts to calculate the second calibration value even if 1-point trimming is being used; in this case, the calculated value is probably not useful and is never used anyway. Changing this also requires a minor reordering in Exynos5433 initialization function, so that we know which type of trimming is used before we call sanitize_temp_error. The second issue is that the function is not very consistent when it comes to the use of Exynos7-specific parameters. This seems to not be an issue in practice, in part because some of these issues are related to the mentioned calculation of the second calibration value. However, fixing this makes the code a bit less confusing, and will be required for Exynos850 which has 9-bit temperature values and uses 2-point trimming. Signed-off-by: Mateusz Majewski Reviewed-by: Sam Protsenko --- v1 -> v2: reworked to change shift instead of only mask and to also fix the 2-point trimming issue. drivers/thermal/samsung/exynos_tmu.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c index b68e9755c933..087a09628e23 100644 --- a/drivers/thermal/samsung/exynos_tmu.c +++ b/drivers/thermal/samsung/exynos_tmu.c @@ -111,6 +111,7 @@ #define EXYNOS7_TMU_REG_EMUL_CON 0x160 #define EXYNOS7_TMU_TEMP_MASK 0x1ff +#define EXYNOS7_TMU_TEMP_SHIFT 9 #define EXYNOS7_PD_DET_EN_SHIFT 23 #define EXYNOS7_TMU_INTEN_RISE0_SHIFT 0 #define EXYNOS7_EMUL_DATA_SHIFT 7 @@ -234,20 +235,23 @@ static void sanitize_temp_error(struct exynos_tmu_data *data, u32 trim_info) u16 tmu_temp_mask = (data->soc == SOC_ARCH_EXYNOS7) ? EXYNOS7_TMU_TEMP_MASK : EXYNOS_TMU_TEMP_MASK; + int tmu_85_shift = + (data->soc == SOC_ARCH_EXYNOS7) ? EXYNOS7_TMU_TEMP_SHIFT + : EXYNOS_TRIMINFO_85_SHIFT; data->temp_error1 = trim_info & tmu_temp_mask; - data->temp_error2 = ((trim_info >> EXYNOS_TRIMINFO_85_SHIFT) & - EXYNOS_TMU_TEMP_MASK); - if (!data->temp_error1 || (data->min_efuse_value > data->temp_error1) || (data->temp_error1 > data->max_efuse_value)) - data->temp_error1 = data->efuse_value & EXYNOS_TMU_TEMP_MASK; + data->temp_error1 = data->efuse_value & tmu_temp_mask; - if (!data->temp_error2) - data->temp_error2 = - (data->efuse_value >> EXYNOS_TRIMINFO_85_SHIFT) & - EXYNOS_TMU_TEMP_MASK; + if (data->cal_type == TYPE_TWO_POINT_TRIMMING) { + data->temp_error2 = (trim_info >> tmu_85_shift) & tmu_temp_mask; + if (!data->temp_error2) + data->temp_error2 = + (data->efuse_value >> tmu_85_shift) & + tmu_temp_mask; + } } static int exynos_tmu_initialize(struct platform_device *pdev) @@ -510,7 +514,6 @@ static void exynos5433_tmu_initialize(struct platform_device *pdev) int sensor_id, cal_type; trim_info = readl(data->base + EXYNOS_TMU_REG_TRIMINFO); - sanitize_temp_error(data, trim_info); /* Read the temperature sensor id */ sensor_id = (trim_info & EXYNOS5433_TRIMINFO_SENSOR_ID_MASK) @@ -532,6 +535,8 @@ static void exynos5433_tmu_initialize(struct platform_device *pdev) break; } + sanitize_temp_error(data, trim_info); + dev_info(&pdev->dev, "Calibration type is %d-point calibration\n", cal_type ? 2 : 1); }