From patchwork Wed Sep 11 12:11:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Majewski X-Patchwork-Id: 13800358 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 3DE43EE4998 for ; Wed, 11 Sep 2024 12:20:46 +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=NJdZThH/4rVsf6XBL7/98lsA2ZRMGdmDLTG8epuqeXs=; b=w5MPkh+4i8p9b9zedIEb/Je3D3 4hi6WiHInd1xfDCk3dYjb11dNAsMSL5ooVkh6Vxqtt6wEMf1vVF5shA6B9IL01grQL9cBtquui06/ 743MHAW9GASD7meMVNRiy0Lq2XUYkzD+niAC0G0J9FGbyNRHOwLNISHqG9VnTk2sZWq8luG5tXAG5 0LQ+IwLnNQW9U4G0HLSzpcyOQfzypcKpKU7rxYVvw9urE5g9CmaQ11ryF4qwPbB52F2m8HuvOv2Zw 4g6jPa1ky9kWFlwu6fBjfehAny7TyJVJ3HW3mwdlYSxCGqNsjdTZuY/WJr7SkfQazuVL9mu5ZtOiV tPX9fG2A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soMKo-00000009Ryb-1j2N; Wed, 11 Sep 2024 12:20:34 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soMCT-00000009Q0Q-1cZ9 for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 12:11:59 +0000 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240911121155euoutp02491c1fcd4542fff8b3094f3f5bfafc32~0L3AndB310044900449euoutp02L for ; Wed, 11 Sep 2024 12:11:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240911121155euoutp02491c1fcd4542fff8b3094f3f5bfafc32~0L3AndB310044900449euoutp02L DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1726056715; bh=NJdZThH/4rVsf6XBL7/98lsA2ZRMGdmDLTG8epuqeXs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fm0836T9VLbJbXzXgN7F87AI6oZJtGBQ022ZayU1cBU9iu8NeIN6L9Vkv2bs5TB3z u+mwoYpTwW4Le+EaZ2O6EdfNzC+R+FoB3tyqYQimj2PAty94ZxJBsWPJeYBOVxJ/p7 QmV4KRm39fLr2G5jAx9JQfn24b1vUKIGyzLKeFD0= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20240911121155eucas1p1f1fda5e90a3c7cf15e520430d0564982~0L3ADN0pR1328313283eucas1p1s; Wed, 11 Sep 2024 12:11:55 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id D2.61.09875.B0981E66; Wed, 11 Sep 2024 13:11:55 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240911121154eucas1p1a429a565c446cdd968f565df1ffae42c~0L2-fJYMn2450124501eucas1p1N; Wed, 11 Sep 2024 12:11:54 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240911121154eusmtrp28d359762649260d33f3c7f8a315fd71e~0L2-eCf6X2688526885eusmtrp2c; Wed, 11 Sep 2024 12:11:54 +0000 (GMT) X-AuditID: cbfec7f4-131ff70000002693-93-66e1890b802d Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id DC.4D.19096.A0981E66; Wed, 11 Sep 2024 13:11:54 +0100 (BST) Received: from AMDC4515.eu.corp.samsungelectronics.net (unknown [106.120.51.28]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240911121153eusmtip1f4eff36b994b8846f7538e82aadde599~0L2_jbr-E0774607746eusmtip14; Wed, 11 Sep 2024 12:11:53 +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 , Marek Szyprowski Subject: [PATCH v4 3/7] drivers/thermal/exynos: improve sanitize_temp_error Date: Wed, 11 Sep 2024 14:11:26 +0200 Message-ID: <20240911121136.1120026-4-m.majewski2@samsung.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240911121136.1120026-1-m.majewski2@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrEKsWRmVeSWpSXmKPExsWy7djP87rcnQ/TDH7eZrd4MG8bm8X3LdeZ LNbsPcdkMe+zrMX8I+dYLc6f38BusenxNVaLy7vmsFl87j3CaDH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rNdjT94O3zyg1SH+PM lir4WS3gUWIpzkg01GIuKk4EADuSQhZXAwAA X-CMS-MailID: 20240911121154eucas1p1a429a565c446cdd968f565df1ffae42c X-Msg-Generator: CA X-RootMTR: 20240911121154eucas1p1a429a565c446cdd968f565df1ffae42c X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240911121154eucas1p1a429a565c446cdd968f565df1ffae42c References: <20240911121136.1120026-1-m.majewski2@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_051157_732976_AB495E93 X-CRM114-Status: GOOD ( 23.90 ) 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 --- v3 -> v4: further reworked to avoid SoC-specific code, instead using SoC-specific parameters inside of exynos_tmu_data (probably different enough to drop R-b). 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 | 40 ++++++++++++++++++---------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c index b68e9755c933..8b1014915c31 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 @@ -152,6 +153,8 @@ enum soc_type { * @max_efuse_value: maximum valid trimming data * @temp_error1: fused value of the first point trim. * @temp_error2: fused value of the second point trim. + * @temp_mask: SoC specific temperature mask + * @temp_85_shift: SoC specific address shift * @gain: gain of amplifier in the positive-TC generator block * 0 < gain <= 15 * @reference_voltage: reference voltage of amplifier @@ -182,6 +185,8 @@ struct exynos_tmu_data { u32 min_efuse_value; u32 max_efuse_value; u16 temp_error1, temp_error2; + u16 temp_mask; + int temp_85_shift; u8 gain; u8 reference_voltage; struct thermal_zone_device *tzd; @@ -229,25 +234,26 @@ static int code_to_temp(struct exynos_tmu_data *data, u16 temp_code) EXYNOS_FIRST_POINT_TRIM; } +/* + * Sanitize sensor calibration values, according to minimum and maximum + * values defined for each SoC. + */ 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; - - data->temp_error1 = trim_info & tmu_temp_mask; - data->temp_error2 = ((trim_info >> EXYNOS_TRIMINFO_85_SHIFT) & - EXYNOS_TMU_TEMP_MASK); - + data->temp_error1 = trim_info & data->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 & data->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 >> data->temp_85_shift) & + data->temp_mask; + if (!data->temp_error2) + data->temp_error2 = + (data->efuse_value >> data->temp_85_shift) & + data->temp_mask; + } } static int exynos_tmu_initialize(struct platform_device *pdev) @@ -510,7 +516,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 +537,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); } @@ -876,6 +883,7 @@ static int exynos_map_dt_data(struct platform_device *pdev) data->tmu_control = exynos4210_tmu_control; data->tmu_read = exynos4210_tmu_read; data->tmu_clear_irqs = exynos4210_tmu_clear_irqs; + data->temp_mask = EXYNOS_TMU_TEMP_MASK; data->gain = 15; data->reference_voltage = 7; data->efuse_value = 55; @@ -898,6 +906,7 @@ static int exynos_map_dt_data(struct platform_device *pdev) data->tmu_read = exynos4412_tmu_read; data->tmu_set_emulation = exynos4412_tmu_set_emulation; data->tmu_clear_irqs = exynos4210_tmu_clear_irqs; + data->temp_mask = EXYNOS_TMU_TEMP_MASK; data->gain = 8; data->reference_voltage = 16; data->efuse_value = 55; @@ -919,6 +928,8 @@ static int exynos_map_dt_data(struct platform_device *pdev) data->tmu_read = exynos4412_tmu_read; data->tmu_set_emulation = exynos4412_tmu_set_emulation; data->tmu_clear_irqs = exynos4210_tmu_clear_irqs; + data->temp_mask = EXYNOS_TMU_TEMP_MASK; + data->temp_85_shift = EXYNOS_TRIMINFO_85_SHIFT; data->gain = 8; if (res.start == EXYNOS5433_G3D_BASE) data->reference_voltage = 23; @@ -939,6 +950,7 @@ static int exynos_map_dt_data(struct platform_device *pdev) data->tmu_read = exynos7_tmu_read; data->tmu_set_emulation = exynos4412_tmu_set_emulation; data->tmu_clear_irqs = exynos4210_tmu_clear_irqs; + data->temp_mask = EXYNOS7_TMU_TEMP_MASK; data->gain = 9; data->reference_voltage = 17; data->efuse_value = 75;