From patchwork Wed Aug 7 08:48:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Majewski X-Patchwork-Id: 13756030 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 CBC2CC3DA7F for ; Wed, 7 Aug 2024 08:52:03 +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=5wsELEEviwJQsFZ5DJNpJB4cw/iPr7KJRjxHSkMlBYc=; b=jzcdiLCvSHAP84UBin3yUeG2Uh BIIWL+Yc71IvPAX34n0Dqih/woEeeIcxll0gRTOOePY9epKoxLIVejoUveEMd9TwNNyoLPLE40wEO lgxPkXhESDLjcjujc/b+IuBeUYBxQIaAHFlE4JJt/xHMbtNIipY+MQlQ001ziR2gC33gzY7HNXIJK u8tgnJZO29BqzcnSAYA7BPtK/zhg3V1hvL0VyVih3YfsJmpwGIXdttfkYxw3JYpJLfdZzSEoaICcg gOnDiu+WEQ9AGHqFFJ7HS6iLEIU3+7Oa4JKuwFuj8WR3Q13/oNbM1AmKIeP1mKw1u69k2TzRSrehy wEMSUn5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbcOc-00000004RYD-2EDJ; Wed, 07 Aug 2024 08:51:50 +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 1sbcM9-00000004Qr4-1IzM for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 08:49:20 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240807084913euoutp0102196530b2cd6e7e19b375a5ddafbb40~pZhCToZjv1700017000euoutp01H for ; Wed, 7 Aug 2024 08:49:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240807084913euoutp0102196530b2cd6e7e19b375a5ddafbb40~pZhCToZjv1700017000euoutp01H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1723020553; bh=5wsELEEviwJQsFZ5DJNpJB4cw/iPr7KJRjxHSkMlBYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vRHHJDRYvh+fbcCAtR/0F+kAcuu1YzShmPtRZhEcabmesCf8plzMMgpn+KNRJUWa9 tMdb44fGss3jm0lBFKpajQXtXZLR2x46KTCleKgs7LW5lOpEdr1B28g6MgyutBtt0e oHWeEFxjSM5gisEQlAUNj3o23lMlLhSgH/3+Hd2A= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20240807084913eucas1p1e697ebbfbc4f8d624aca443af1dcf46f~pZhBzbo9E2070720707eucas1p1P; Wed, 7 Aug 2024 08:49:13 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id DB.02.09624.90533B66; Wed, 7 Aug 2024 09:49:13 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240807084912eucas1p20af043b96b6d741a0c7d7ae36efe5ac5~pZhBZLkTm2538325383eucas1p2p; Wed, 7 Aug 2024 08:49:12 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240807084912eusmtrp2364066f1788ca33e808c4e54b006ef3d~pZhBXaoDr2319723197eusmtrp2d; Wed, 7 Aug 2024 08:49:12 +0000 (GMT) X-AuditID: cbfec7f2-c11ff70000002598-29-66b33509e903 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 54.01.08810.80533B66; Wed, 7 Aug 2024 09:49:12 +0100 (BST) Received: from AMDC4515.eu.corp.samsungelectronics.net (unknown [106.120.51.28]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240807084911eusmtip235da50f51f8113a83e734e05da542ba2~pZhAdxbIX2807028070eusmtip2S; Wed, 7 Aug 2024 08:49:11 +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 v3 3/6] drivers/thermal/exynos: improve sanitize_temp_error Date: Wed, 7 Aug 2024 10:48:22 +0200 Message-ID: <20240807084829.1037303-4-m.majewski2@samsung.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240807084829.1037303-1-m.majewski2@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrHKsWRmVeSWpSXmKPExsWy7djP87qcppvTDGZf5bJ4MG8bm8X3LdeZ LNbsPcdkMe+zrMX8I+dYLc6f38BusenxNVaLy7vmsFl87j3CaDHj/D4mi3Ubb7FbL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RcVJwIAysa3+FEDAAA= X-CMS-MailID: 20240807084912eucas1p20af043b96b6d741a0c7d7ae36efe5ac5 X-Msg-Generator: CA X-RootMTR: 20240807084912eucas1p20af043b96b6d741a0c7d7ae36efe5ac5 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240807084912eucas1p20af043b96b6d741a0c7d7ae36efe5ac5 References: <20240807084829.1037303-1-m.majewski2@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_014917_645949_2516AA0F X-CRM114-Status: GOOD ( 21.95 ) 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. Reviewed-by: Sam Protsenko Signed-off-by: Mateusz Majewski --- 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); }