From nobody Sat Jul 25 00:14:49 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4220363083; Wed, 22 Jul 2026 02:39:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784687945; cv=none; b=paElcX9W8NuZXPUCemRaMEZ9MoI4Mflrk2X5UoqEuQ6MlNYIRNVS65nJq16EWSEC77TF7TPiOgpnDV6MLy/47hd2ltRF2lxL5VpTpk+KzlIs8OwZFzJD+afGak2Iy7iZLiFQZGSRBp+tNNeRytOhGx/40O6zdeiZXljj3BdQWfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784687945; c=relaxed/simple; bh=noP7SLtTy6bRV7+vDOu0XXWL530DjmB63o88p0NEPPI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JyPEQbzD2IMY7vUHMxe5NEccu5A4jY76AXmhxqqRKQwJ/Jpo9vcY3Vu4YVFNkZ+mMCAWPdVjG7Pch2Az+l9nvm/9Pah82/17LID3qwYW0zOvk+pt0XGELUmSsOiLU1KYtVf55I9/XnybhfwtQ5eFjPQMyPbgH0pwDFr93DipN5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vChfd3TQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="vChfd3TQ" Received: by smtp.kernel.org (Postfix) with ESMTPS id 6260CC2BCB8; Wed, 22 Jul 2026 02:39:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1784687945; bh=noP7SLtTy6bRV7+vDOu0XXWL530DjmB63o88p0NEPPI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=vChfd3TQJdklUQPqg0W0Kz4uVFSoFU/HwVH2NtfPponDBh6pzPhwgn7moELJFigZE MhUBbTgUrV2CWOEhFM3SZd25D7aarp0jcXfuSLRd80yvbVna7O1rD41gsqBxoat/T2 LQGlGJTVB7kbKwvucOBGPJhGNFr6/uKw3108CsKlGp15sDAp2L521lqs3EdMTY2eg/ XqbFXtcR/C5G1kEvhAvGAuhnTrDA9KtV+HR/9mzEdVlWtRiL7jRvW/SkT3N+jT3m9F SMyT8Gjp8ZvLOUIP1omt8hKBCfON768znuprxLAkyg3PGJT03+tCKco10zb917daaO 2PeM7JXEO42ww== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F0BBC4452D; Wed, 22 Jul 2026 02:39:05 +0000 (UTC) From: Haoning CHENG via B4 Relay Date: Wed, 22 Jul 2026 10:11:41 +0800 Subject: [PATCH v11 1/3] dt-bindings: thermal: imx: Document calibration offset property Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260722-b4-symana21-11221-imx-thermal-support-upstream-6-18-v11-1-90e4e46c0a13@cn.bosch.com> References: <20260722-b4-symana21-11221-imx-thermal-support-upstream-6-18-v11-0-90e4e46c0a13@cn.bosch.com> In-Reply-To: <20260722-b4-symana21-11221-imx-thermal-support-upstream-6-18-v11-0-90e4e46c0a13@cn.bosch.com> To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Haoning CHENG , Krzysztof Kozlowski X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784687940; l=2030; i=Haoning.CHENG@cn.bosch.com; s=20260709; h=from:subject:message-id; bh=Ue37UPF1teuZxiSxC/xhzQKQfZyk1Yq+nuequgJPOG4=; b=ABwbGlbH3nVJiQM3RU0KiJXtVhO5x9aUjwRw7+Wwy9UUumZfzoR8s6zJYVAQ21SP7ibyoWgQr YBxqBfD5SDiDKow5vBJUINNZbcQMtV7XTAus2mhOixYRfral2GmYQAg X-Developer-Key: i=Haoning.CHENG@cn.bosch.com; a=ed25519; pk=glQGwad/fosRS5gZUJYbLDPPLGe7rFTrTV2VxY/ySdc= X-Endpoint-Received: by B4 Relay for Haoning.CHENG@cn.bosch.com/20260709 with auth_id=860 X-Original-From: Haoning CHENG Reply-To: Haoning.CHENG@cn.bosch.com From: Haoning CHENG The TEMPMON sensor reading may deviate from the theoretical SoC junction temperature. Document the optional fsl,temp-calibration-offset-millicelsius property, a signed offset in millicelsius applied to correct the sensor reading toward the theoretical junction temperature. The offset is determined through thermal characterization by comparing the sensor output against the calculated junction temperature. When absent, the offset is zero. Reviewed-by: Krzysztof Kozlowski Reviewed-by: Lukasz Luba Signed-off-by: Haoning CHENG --- Documentation/devicetree/bindings/thermal/imx-thermal.yaml | 12 ++++++++++= ++ 1 file changed, 12 insertions(+) diff --git a/Documentation/devicetree/bindings/thermal/imx-thermal.yaml b/D= ocumentation/devicetree/bindings/thermal/imx-thermal.yaml index 949b154856c5..503a6e7a2c68 100644 --- a/Documentation/devicetree/bindings/thermal/imx-thermal.yaml +++ b/Documentation/devicetree/bindings/thermal/imx-thermal.yaml @@ -59,6 +59,17 @@ properties: clocks: maxItems: 1 =20 + fsl,temp-calibration-offset-millicelsius: + minimum: -20000 + maximum: 20000 + description: + A signed offset, in millicelsius, applied to the TEMPMON + sensor reading to correct it toward the theoretical SoC + junction temperature. The offset is determined through + thermal characterization by comparing the sensor output + against the calculated junction temperature. The range is + limited to =C2=B120 =C2=B0C. When absent, no offset is applied. + "#thermal-sensor-cells": const: 0 =20 @@ -109,6 +120,7 @@ examples: nvmem-cells =3D <&tempmon_calib>, <&tempmon_temp_grade>; nvmem-cell-names =3D "calib", "temp_grade"; clocks =3D <&clks IMX6SX_CLK_PLL3_USB_OTG>; + fsl,temp-calibration-offset-millicelsius =3D <(-6400)>; #thermal-sensor-cells =3D <0>; }; }; --=20 2.43.0 From nobody Sat Jul 25 00:14:49 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A504938F95E; Wed, 22 Jul 2026 02:39:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784687945; cv=none; b=rrq/obR+TOiRIsWyxSa+hMT9tdLp5MDFqrBCPd2cbinSyNEpL5lu1N/eM+Geok3Pn89AUDArLaVQO5sQKpMl3xMBTmuWbtUzzQ51NHYwH3utBtOHL3+75HylKS4vHpP1qoQbWoTC1CigTIJzagfDkszi8Li04A110kFwF2oEhhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784687945; c=relaxed/simple; bh=mhJJOiGSAySJ9mUo6G70qcgxDi+mETTMgMGHEkSRrZQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mWB94PNxWWGHc6gkTc77JpoLN//FQhiF4ORhNVlr87J8j8SC83WmxbdIP45gkpXys12O2zPBKxRrvrnWEdB8CGJoHi59EkjG4+seOeEkhxyr3A5EhJKNumC4+/JCJ6Ktl5lkVMhVmGICzh13MSjbBKaRW0vmTJPDq2sqnYW+4ZU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LbmKITDZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LbmKITDZ" Received: by smtp.kernel.org (Postfix) with ESMTPS id 6E9A4C2BD00; Wed, 22 Jul 2026 02:39:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1784687945; bh=mhJJOiGSAySJ9mUo6G70qcgxDi+mETTMgMGHEkSRrZQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=LbmKITDZEXXBQ/8IH4zFGCagaFgNSujRWX5VLt+adrB/x57qVc4itup7K6wnkjMyb rFuYm6STR9yWOyn4nuAXr524KG/rhk6l40a5tP7p1c3l3YV/zaLfRpAXYTsY2bHDr+ 4bleXFu0MJRVMTPmZMZvMI5iRVJfxRXEddBFI8xosozlWusSBSRkJfgeLiAStOKCua VdnzYJKEwaBLOemWPnSI3OJ7e+OFZBIMExKNFEa10XGkVfMMdYPmwhHoOPVw2zJndj 972uAFe6Y99MMzhXWCmkk59a6xm8gbeE9lg2U/vtzGhIndZYC4DZeaBg5CMH/L2Vww h08ZM2CuCdmgA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5057FC4452B; Wed, 22 Jul 2026 02:39:05 +0000 (UTC) From: Haoning CHENG via B4 Relay Date: Wed, 22 Jul 2026 10:11:42 +0800 Subject: [PATCH v11 2/3] thermal/drivers/imx: Fix rounding and clamp for i.MX7D alarm Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260722-b4-symana21-11221-imx-thermal-support-upstream-6-18-v11-2-90e4e46c0a13@cn.bosch.com> References: <20260722-b4-symana21-11221-imx-thermal-support-upstream-6-18-v11-0-90e4e46c0a13@cn.bosch.com> In-Reply-To: <20260722-b4-symana21-11221-imx-thermal-support-upstream-6-18-v11-0-90e4e46c0a13@cn.bosch.com> To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Haoning CHENG , Frank Li X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784687940; l=1704; i=Haoning.CHENG@cn.bosch.com; s=20260709; h=from:subject:message-id; bh=9D7qX15817iSb+CvnZ+YgaTi5ivABKiNn7DaNl6d+D8=; b=dSw6FYxkkFm4fLIdK3ERIvfsuKpJ5CRCHad0nEFRulApxe/Ltr4d82vb9DxLAVNZPjv4gN7WY pEdrAkUTcVzA+8+TdoZVcNESzLrRQIHS+THTN+DIwlqbfGg2Z1ICtLv X-Developer-Key: i=Haoning.CHENG@cn.bosch.com; a=ed25519; pk=glQGwad/fosRS5gZUJYbLDPPLGe7rFTrTV2VxY/ySdc= X-Endpoint-Received: by B4 Relay for Haoning.CHENG@cn.bosch.com/20260709 with auth_id=860 X-Original-From: Haoning CHENG Reply-To: Haoning.CHENG@cn.bosch.com From: Haoning CHENG Convert the alarm temperature from millicelsius to degrees for i.MX7D using ceiling division instead of integer division, ensuring rounding errors do not cause the alarm to trigger below the intended threshold. Use DIV_ROUND_UP() for non-negative values and plain integer division for negative values, since C rounds toward zero which is equivalent to ceiling when the divisor is positive. Add clamp() to ensure the hardware register value stays within the 9-bit range (0..0x1ff) of the i.MX7D alarm field, preventing silent truncation if an out-of-range value is written. Reviewed-by: Frank Li Reviewed-by: Lukasz Luba Signed-off-by: Haoning Cheng --- drivers/thermal/imx_thermal.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 38c993d1bcb3..7f7d1116b9d6 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -240,10 +240,16 @@ static void imx_set_alarm_temp(struct imx_thermal_dat= a *data, =20 data->alarm_temp =3D alarm_temp; =20 - if (data->socdata->version =3D=3D TEMPMON_IMX7D) - alarm_value =3D alarm_temp / 1000 + data->c1 - 25; - else + if (data->socdata->version =3D=3D TEMPMON_IMX7D) { + if (alarm_temp >=3D 0) + alarm_temp =3D DIV_ROUND_UP(alarm_temp, 1000); + else + alarm_temp /=3D 1000; + alarm_value =3D alarm_temp + data->c1 - 25; + alarm_value =3D clamp(alarm_value, 0, 0x1ff); + } else { alarm_value =3D (data->c2 - alarm_temp) / data->c1; + } =20 regmap_write(map, soc_data->high_alarm_ctrl + REG_CLR, soc_data->high_alarm_mask); --=20 2.43.0 From nobody Sat Jul 25 00:14:49 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6636390200; Wed, 22 Jul 2026 02:39:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784687945; cv=none; b=Hz7A+SqljfjC/ndUM+rZcdJvISRehKZnuHNyQPZySYXLMo+w1rehLLPOlPUPH4qtBmNMdR6c/Ip//dghAE+CIceXSiiq+YrNHVdMG+pkpEJ58R6nlwRiNmrFPmHC+PXoDlAD3DSNUOzJlPgSbqD6cMZwfmAmiY8arw2FZ+8VpDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784687945; c=relaxed/simple; bh=ITBBTNbrJy4rjiCqecHeGN6oMKu87IH6xqyjgbYmK7M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ApmKy5MVuN2YIZAk7GYWkhjNdF6dnjMWd3ZV7yJO/q23vFo/cAakwkRNruJSOIDc5IDsDIfIBvdvo2ARHUJ6qW2pjvUqmIjhfW5jOjR56hPo/5pKBIJL5JEdXfYYQn2Dwc3rIzDVu8fnUEr/tncNuEbMgnDUaDYbEN7oRwYxl8M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qvbs5xJ4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qvbs5xJ4" Received: by smtp.kernel.org (Postfix) with ESMTPS id 761B7C2BCFD; Wed, 22 Jul 2026 02:39:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1784687945; bh=ITBBTNbrJy4rjiCqecHeGN6oMKu87IH6xqyjgbYmK7M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=qvbs5xJ49l1YYYdxqfvC2nyRb3NI6X0EgIGQe8gsbvbQvGn7nwSFJGNm7D+zbAQxY MXcGFGjdKgb0Mos8f8KJmNszH8HP6QRaFl4vFG9WsdcgV9x8gF7BZaVFalX1fSsd6e BOSPNGnV5bKoQnGX5exXWqOY6ysCqzSnG1Mj/CZeACFjAed2xRdKPD/cSgWu3O0m/m e2g5scDr5Lfd6T9cDXR/8i9qCSV4w2fRitRO8rVyjEye+qic6bShzRegJAZoNhqhq9 KURhBMPJp6eOhGvOsuIP3I0+rYaoW2SrcwCuAQbJi8xtZKZ0il2aNN+nvFdL44dJlV 9dJCxFbeUKz3g== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FA6DC44537; Wed, 22 Jul 2026 02:39:05 +0000 (UTC) From: Haoning CHENG via B4 Relay Date: Wed, 22 Jul 2026 10:11:43 +0800 Subject: [PATCH v11 3/3] thermal/drivers/imx: Add calibration offset support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260722-b4-symana21-11221-imx-thermal-support-upstream-6-18-v11-3-90e4e46c0a13@cn.bosch.com> References: <20260722-b4-symana21-11221-imx-thermal-support-upstream-6-18-v11-0-90e4e46c0a13@cn.bosch.com> In-Reply-To: <20260722-b4-symana21-11221-imx-thermal-support-upstream-6-18-v11-0-90e4e46c0a13@cn.bosch.com> To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Haoning CHENG , Frank Li X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784687940; l=4319; i=Haoning.CHENG@cn.bosch.com; s=20260709; h=from:subject:message-id; bh=iGtMCQeZJKH4z5VifCeuyUN93+QX4fy7skn49vUYhis=; b=SlhPV5ho3FNmNN6iMqbaR1vdUUAKNRWYpWNGh38K7fKyLTjQTT4qe81iPBIRFeHTKSQykqfz3 0uqlVina7AgBZUnytKjIfmg5VPF6m2OLX+FDB/vcaE7njHeEu5iHkF7 X-Developer-Key: i=Haoning.CHENG@cn.bosch.com; a=ed25519; pk=glQGwad/fosRS5gZUJYbLDPPLGe7rFTrTV2VxY/ySdc= X-Endpoint-Received: by B4 Relay for Haoning.CHENG@cn.bosch.com/20260709 with auth_id=860 X-Original-From: Haoning CHENG Reply-To: Haoning.CHENG@cn.bosch.com From: Haoning CHENG The TEMPMON sensor reading may deviate from the theoretical SoC junction temperature. Hardware characterization shows a measurable offset between the sensor output and the calculated junction temperature. Read the optional fsl,temp-calibration-offset-millicelsius property from DT and apply it uniformly to the i.MX6/6SX/7D formulas. The offset is applied symmetrically at two points to keep trip point semantics consistent: 1. In imx_set_alarm_temp() and imx_set_panic_temp(): the temperature threshold is *subtracted* by the offset before being converted to a hardware register value. This keeps the hardware IRQ trigger aligned with the physical sensor reading that corresponds to the intended temperature threshold. 2. In imx_get_temp(): after computing the temperature from the hardware register, the offset is *added* to produce the calibrated value. The thermal framework always sees the corrected temperature. For example, if DT sets offset =3D +3000 m=C2=B0C and the passive trip is 9= 5=C2=B0C: imx_set_alarm_temp(95000): alarm_temp =3D 95000 - 3000 =3D 92000 =E2=86=92 hardware register programmed for 92=C2=B0C sensor reading Hardware IRQ fires when sensor reads 92=C2=B0C imx_get_temp(): reads hardware, computes 92=C2=B0C *temp =3D 92000 + 3000 =3D 95000 =E2=86=92 thermal framework sees 95=C2=B0C =E2=86=92 correct trip When the property is not present, the offset defaults to 0, preserving the current behavior. Reviewed-by: Frank Li Reviewed-by: Lukasz Luba Signed-off-by: Haoning Cheng --- drivers/thermal/imx_thermal.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 7f7d1116b9d6..d471acc16bce 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -85,6 +85,10 @@ enum imx_thermal_trip { #define TEMPMON_IMX6SX 2 #define TEMPMON_IMX7D 3 =20 +/* Calibration offset limits (=C2=B120 =C2=B0C in millicelsius) */ +#define IMX_TEMP_CALIB_OFFSET_MIN (-20000) +#define IMX_TEMP_CALIB_OFFSET_MAX 20000 + struct thermal_soc_data { u32 version; =20 @@ -207,6 +211,7 @@ struct imx_thermal_data { struct regmap *tempmon; u32 c1, c2; /* See formula in imx_init_calib() */ int temp_max; + s32 calibration_offset; int alarm_temp; int last_temp; bool irq_enabled; @@ -223,6 +228,7 @@ static void imx_set_panic_temp(struct imx_thermal_data = *data, struct regmap *map =3D data->tempmon; int critical_value; =20 + panic_temp -=3D data->calibration_offset; critical_value =3D (data->c2 - panic_temp) / data->c1; =20 regmap_write(map, soc_data->panic_alarm_ctrl + REG_CLR, @@ -239,6 +245,7 @@ static void imx_set_alarm_temp(struct imx_thermal_data = *data, int alarm_value; =20 data->alarm_temp =3D alarm_temp; + alarm_temp -=3D data->calibration_offset; =20 if (data->socdata->version =3D=3D TEMPMON_IMX7D) { if (alarm_temp >=3D 0) @@ -283,6 +290,7 @@ static int imx_get_temp(struct thermal_zone_device *tz,= int *temp) *temp =3D (n_meas - data->c1 + 25) * 1000; else *temp =3D data->c2 - n_meas * data->c1; + *temp +=3D data->calibration_offset; =20 /* Update alarm value to next higher trip point for TEMPMON_IMX6Q */ if (data->socdata->version =3D=3D TEMPMON_IMX6Q) { @@ -635,6 +643,25 @@ static int imx_thermal_probe(struct platform_device *p= dev) =20 platform_set_drvdata(pdev, data); =20 + if (of_property_present(dev->of_node, + "fsl,temp-calibration-offset-millicelsius")) { + ret =3D of_property_read_s32(dev->of_node, + "fsl,temp-calibration-offset-millicelsius", + &data->calibration_offset); + if (ret) + return dev_err_probe(dev, ret, + "failed to read calibration offset\n"); + + if (data->calibration_offset < IMX_TEMP_CALIB_OFFSET_MIN || + data->calibration_offset > IMX_TEMP_CALIB_OFFSET_MAX) + return dev_err_probe(dev, -EINVAL, + "calibration offset %d millicelsius out of range\n", + data->calibration_offset); + + dev_dbg(dev, "calibration offset: %d millicelsius\n", + data->calibration_offset); + } + if (of_property_present(dev->of_node, "nvmem-cells")) { ret =3D imx_init_from_nvmem_cells(pdev); if (ret) --=20 2.43.0