* [PATCH v5 0/2] thermal: imx: Add calibration offset support
@ 2026-07-13 5:51 HaoNing Cheng via B4 Relay
2026-07-13 5:51 ` [PATCH v5 1/2] dt-bindings: thermal: imx: Document calibration offset property HaoNing Cheng via B4 Relay
2026-07-13 5:51 ` [PATCH v5 2/2] thermal/drivers/imx: Add calibration offset support HaoNing Cheng via B4 Relay
0 siblings, 2 replies; 5+ messages in thread
From: HaoNing Cheng via B4 Relay @ 2026-07-13 5:51 UTC (permalink / raw)
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, devicetree, imx, linux-arm-kernel, linux-kernel,
Haoning CHENG, Krzysztof Kozlowski
Some i.MX boards need a small per-design correction to align the
reported CPU temperature with board-level measurements. This series
adds an optional DT property to specify such a calibration offset
and implements the corresponding support in the imx_thermal driver.
Patch 1 documents the new fsl,temp-calibration-offset-millicelsius
property in the i.MX thermal DT binding.
Patch 2 reads this property in the imx_thermal driver and applies
the offset to the i.MX6/6SX/7D calibration formulas. When the
property is absent, the default offset remains 0, preserving the
current behaviour.
Signed-off-by: Haoning CHENG <Haoning.CHENG@cn.bosch.com>
---
Changes in v5:
- Move calibration offset application out of c2 initialization, instead
apply it in imx_get_temp(), imx_set_alarm_temp() and imx_set_panic_temp()
for consistent style across i.MX6 and i.MX7D
- Subtract calibration offset from alarm_temp before the if-else block in
imx_set_alarm_temp(), simplifying both SoC branches (Frank's suggestion)
- Link to v4: https://patch.msgid.link/20260710-b4-symana21-11221-imx-thermal-support-upstream-6-18-v4-0-1fef97d1c750@cn.bosch.com
Changes in v4:
- dt-bindings: drop maxItems to allow minimum/maximum constraints for
temp-calibration-offset-millicelsius
- Link to v3: https://patch.msgid.link/20260710-b4-symana21-11221-imx-thermal-support-upstream-6-18-v3-0-db9fc2947c55@cn.bosch.com
Changes in v3:
- dt-bindings: add minimum/maximum (-28580/+28580) for
temp-calibration-offset-millicelsius, as suggested by Conor Dooley
- Link to v2: https://patch.msgid.link/20260709-b4-symana21-11221-imx-thermal-support-upstream-6-18-v2-0-00ff72495e24@cn.bosch.com
Changes in v2:
- dt-bindings: Removed explicit `$ref: /schemas/types.yaml#/definitions/int32`
for fsl,temp-calibration-offset-millicelsius; the `-millicelsius` suffix
already resolves to int32-array via property-units.yaml (Rob).
- dt-bindings: Fixed example indentation.
- driver: Replaced C integer division (/) with DIV_ROUND_CLOSEST() in
imx_set_alarm_temp() to prevent off-by-one alarm threshold mismatch that
could cause IRQ storms on i.MX7D.
- driver: Added clamp() bounds check for alarm_value [0, 0x1ff] to avoid
corrupting adjacent register fields (PANIC_ALARM).
- Link to v1: https://patch.msgid.link/20260709-b4-symana21-11221-imx-thermal-support-upstream-6-18-v1-0-00f88f42930b@cn.bosch.com
To: "Rafael J. Wysocki" <rafael@kernel.org>
To: Daniel Lezcano <daniel.lezcano@linaro.org>
To: Zhang Rui <rui.zhang@intel.com>
To: Lukasz Luba <lukasz.luba@arm.com>
To: Rob Herring <robh@kernel.org>
To: Krzysztof Kozlowski <krzk+dt@kernel.org>
To: Conor Dooley <conor+dt@kernel.org>
To: Shawn Guo <shawnguo@kernel.org>
To: Sascha Hauer <s.hauer@pengutronix.de>
To: Pengutronix Kernel Team <kernel@pengutronix.de>
To: Fabio Estevam <festevam@gmail.com>
Cc: linux-pm@vger.kernel.org
Cc: devicetree@vger.kernel.org
Cc: imx@lists.linux.dev
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
HaoNing Cheng (2):
dt-bindings: thermal: imx: Document calibration offset property
thermal/drivers/imx: Add calibration offset support
.../devicetree/bindings/thermal/imx-thermal.yaml | 9 +++++++++
drivers/thermal/imx_thermal.c | 16 +++++++++++++---
2 files changed, 22 insertions(+), 3 deletions(-)
---
base-commit: c50a940dcde35c647e097e89a9150003abd48329
change-id: 20260709-b4-symana21-11221-imx-thermal-support-upstream-6-18-a084984deb76
Best regards,
--
Haoning CHENG <Haoning.CHENG@cn.bosch.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v5 1/2] dt-bindings: thermal: imx: Document calibration offset property
2026-07-13 5:51 [PATCH v5 0/2] thermal: imx: Add calibration offset support HaoNing Cheng via B4 Relay
@ 2026-07-13 5:51 ` HaoNing Cheng via B4 Relay
2026-07-13 9:51 ` Krzysztof Kozlowski
2026-07-13 5:51 ` [PATCH v5 2/2] thermal/drivers/imx: Add calibration offset support HaoNing Cheng via B4 Relay
1 sibling, 1 reply; 5+ messages in thread
From: HaoNing Cheng via B4 Relay @ 2026-07-13 5:51 UTC (permalink / raw)
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, devicetree, imx, linux-arm-kernel, linux-kernel,
Haoning CHENG, Krzysztof Kozlowski
From: HaoNing Cheng <Haoning.CHENG@cn.bosch.com>
Some boards need a small per-design correction to align the reported CPU
temperature with board-level measurements.
Document the optional fsl,temp-calibration-offset-millicelsius property,
a signed offset in millicelsius that is added to the calculated sensor
temperature. The property is optional and the existing behaviour is kept
when it is omitted.
Update the binding example to show its usage.
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Signed-off-by: Haoning CHENG <Haoning.CHENG@cn.bosch.com>
---
Documentation/devicetree/bindings/thermal/imx-thermal.yaml | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/Documentation/devicetree/bindings/thermal/imx-thermal.yaml b/Documentation/devicetree/bindings/thermal/imx-thermal.yaml
index 949b154856c5..b9afffd98f84 100644
--- a/Documentation/devicetree/bindings/thermal/imx-thermal.yaml
+++ b/Documentation/devicetree/bindings/thermal/imx-thermal.yaml
@@ -59,6 +59,14 @@ properties:
clocks:
maxItems: 1
+ fsl,temp-calibration-offset-millicelsius:
+ minimum: -28580
+ maximum: 28580
+ description:
+ A signed calibration offset, in millicelsius, added to the calculated
+ sensor temperature to compensate for board-level measurement
+ differences. When absent, no offset is applied.
+
"#thermal-sensor-cells":
const: 0
@@ -109,6 +117,7 @@ examples:
nvmem-cells = <&tempmon_calib>, <&tempmon_temp_grade>;
nvmem-cell-names = "calib", "temp_grade";
clocks = <&clks IMX6SX_CLK_PLL3_USB_OTG>;
+ fsl,temp-calibration-offset-millicelsius = <(-6400)>;
#thermal-sensor-cells = <0>;
};
};
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v5 2/2] thermal/drivers/imx: Add calibration offset support
2026-07-13 5:51 [PATCH v5 0/2] thermal: imx: Add calibration offset support HaoNing Cheng via B4 Relay
2026-07-13 5:51 ` [PATCH v5 1/2] dt-bindings: thermal: imx: Document calibration offset property HaoNing Cheng via B4 Relay
@ 2026-07-13 5:51 ` HaoNing Cheng via B4 Relay
2026-07-13 6:04 ` sashiko-bot
1 sibling, 1 reply; 5+ messages in thread
From: HaoNing Cheng via B4 Relay @ 2026-07-13 5:51 UTC (permalink / raw)
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, devicetree, imx, linux-arm-kernel, linux-kernel,
Haoning CHENG
From: HaoNing Cheng <Haoning.CHENG@cn.bosch.com>
Some boards need a small per-design correction to align the reported CPU
temperature with board-level measurements.
Read the optional fsl,temp-calibration-offset-millicelsius property from
DT and apply it to the i.MX6/6SX/7D calibration formulas. When the
property is not present, the default offset remains 0, preserving the
current behaviour.
Signed-off-by: HaoNing Cheng <Haoning.CHENG@cn.bosch.com>
---
drivers/thermal/imx_thermal.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
index 38c993d1bcb3..0a443e608957 100644
--- a/drivers/thermal/imx_thermal.c
+++ b/drivers/thermal/imx_thermal.c
@@ -207,6 +207,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 +224,7 @@ static void imx_set_panic_temp(struct imx_thermal_data *data,
struct regmap *map = data->tempmon;
int critical_value;
+ panic_temp -= data->calibration_offset;
critical_value = (data->c2 - panic_temp) / data->c1;
regmap_write(map, soc_data->panic_alarm_ctrl + REG_CLR,
@@ -239,11 +241,14 @@ static void imx_set_alarm_temp(struct imx_thermal_data *data,
int alarm_value;
data->alarm_temp = alarm_temp;
+ alarm_temp -= data->calibration_offset;
- if (data->socdata->version == TEMPMON_IMX7D)
- alarm_value = alarm_temp / 1000 + data->c1 - 25;
- else
+ if (data->socdata->version == TEMPMON_IMX7D) {
+ alarm_value = DIV_ROUND_UP(alarm_temp, 1000) + data->c1 - 25;
+ alarm_value = clamp(alarm_value, 0, 0x1ff);
+ } else {
alarm_value = (data->c2 - alarm_temp) / data->c1;
+ }
regmap_write(map, soc_data->high_alarm_ctrl + REG_CLR,
soc_data->high_alarm_mask);
@@ -277,6 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
*temp = (n_meas - data->c1 + 25) * 1000;
else
*temp = data->c2 - n_meas * data->c1;
+ *temp += data->calibration_offset;
/* Update alarm value to next higher trip point for TEMPMON_IMX6Q */
if (data->socdata->version == TEMPMON_IMX6Q) {
@@ -629,6 +635,10 @@ static int imx_thermal_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, data);
+ of_property_read_s32(dev->of_node,
+ "fsl,temp-calibration-offset-millicelsius",
+ &data->calibration_offset);
+
if (of_property_present(dev->of_node, "nvmem-cells")) {
ret = imx_init_from_nvmem_cells(pdev);
if (ret)
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v5 2/2] thermal/drivers/imx: Add calibration offset support
2026-07-13 5:51 ` [PATCH v5 2/2] thermal/drivers/imx: Add calibration offset support HaoNing Cheng via B4 Relay
@ 2026-07-13 6:04 ` sashiko-bot
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-07-13 6:04 UTC (permalink / raw)
To: HaoNing Cheng; +Cc: Frank.Li, devicetree, imx, conor+dt, robh
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] Hardware register corruption due to unmasked ALARM and PANIC values
Pre-existing issues:
- [Critical] Use-After-Free of device data due to skipped thermal zone unregistration on probe error path
- [High] TOCTOU race on data->irq_enabled leads to permanent IRQ disablement
--
--- Patch [2]: [PATCH v5 2/2] thermal/drivers/imx: Add calibration offset support ---
commit 7348b3f0668ad3ef81c3864d07e94723c70b031c
Author: HaoNing Cheng <Haoning.CHENG@cn.bosch.com>
thermal/drivers/imx: Add calibration offset support
This patch reads an optional fsl,temp-calibration-offset-millicelsius
property from the device tree and applies it to the calibration formulas
for i.MX6/6SX/7D devices.
> diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
> index 5aaacbc534786..5e3cff69aced7 100644
> --- a/drivers/thermal/imx_thermal.c
> +++ b/drivers/thermal/imx_thermal.c
[ ... ]
> @@ -223,6 +224,7 @@ static void imx_set_panic_temp(struct imx_thermal_data *data,
> struct regmap *map = data->tempmon;
> int critical_value;
>
> + panic_temp -= data->calibration_offset;
> critical_value = (data->c2 - panic_temp) / data->c1;
>
> regmap_write(map, soc_data->panic_alarm_ctrl + REG_CLR,
[Severity: High]
Does this code risk corrupting the panic_alarm_ctrl register if a large
calibration offset is provided?
The calibration_offset is subtracted from panic_temp, and critical_value
is not masked before being shifted and written to the REG_SET register:
drivers/thermal/imx_thermal.c:imx_set_panic_temp() {
critical_value = (data->c2 - panic_temp) / data->c1;
...
regmap_write(map, soc_data->panic_alarm_ctrl + REG_SET,
critical_value << soc_data->panic_alarm_shift);
}
If the offset causes critical_value to exceed its bitfield width, could the
overhanging bits corrupt adjacent control bits?
> @@ -239,11 +241,14 @@ static void imx_set_alarm_temp(struct imx_thermal_data *data,
> int alarm_value;
>
> data->alarm_temp = alarm_temp;
> + alarm_temp -= data->calibration_offset;
>
> - if (data->socdata->version == TEMPMON_IMX7D)
> - alarm_value = alarm_temp / 1000 + data->c1 - 25;
> - else
> + if (data->socdata->version == TEMPMON_IMX7D) {
> + alarm_value = DIV_ROUND_UP(alarm_temp, 1000) + data->c1 - 25;
> + alarm_value = clamp(alarm_value, 0, 0x1ff);
> + } else {
> alarm_value = (data->c2 - alarm_temp) / data->c1;
> + }
>
> regmap_write(map, soc_data->high_alarm_ctrl + REG_CLR,
[Severity: High]
Can similar register corruption occur here for IMX6/IMX6SX devices?
While a clamp() was added for TEMPMON_IMX7D, the else branch for
other versions calculates alarm_value without masking or clamping:
drivers/thermal/imx_thermal.c:imx_set_alarm_temp() {
} else {
alarm_value = (data->c2 - alarm_temp) / data->c1;
}
...
regmap_write(map, soc_data->high_alarm_ctrl + REG_SET,
alarm_value << soc_data->high_alarm_shift);
}
Could an excessively large positive or negative calibration offset result
in unmasked bits corrupting the high_alarm_ctrl register?
[ ... ]
> @@ -629,6 +635,10 @@ static int imx_thermal_probe(struct platform_device *pdev)
>
> platform_set_drvdata(pdev, data);
>
> + of_property_read_s32(dev->of_node,
> + "fsl,temp-calibration-offset-millicelsius",
> + &data->calibration_offset);
> +
> if (of_property_present(dev->of_node, "nvmem-cells")) {
[Severity: Critical]
This is a pre-existing issue, but does this function leave the thermal
zone registered if pm_runtime_resume_and_get() fails later in the probe?
If pm_runtime_resume_and_get() fails near the end of probe, the error
path jumps to disable_runtime_pm:
drivers/thermal/imx_thermal.c:imx_thermal_probe() {
...
ret = pm_runtime_resume_and_get(data->dev);
if (ret < 0)
goto disable_runtime_pm;
...
thermal_zone_unregister:
thermal_zone_device_unregister(data->tz);
disable_runtime_pm:
pm_runtime_put_noidle(data->dev);
pm_runtime_disable(data->dev);
...
}
Because disable_runtime_pm is located after thermal_zone_unregister,
it skips unregistering the thermal zone. Since the device data is managed
by devm_kzalloc(), it will be freed when probe fails.
Could subsequent polling by the thermal core invoke imx_get_temp() and
dereference the freed data pointer, leading to a use-after-free?
[Severity: High]
This is a pre-existing issue, but is there a race condition that can
lead to permanent loss of thermal interrupts?
If a user-space process toggles the thermal zone mode via sysfs, it
calls imx_change_mode() which performs a non-atomic check:
drivers/thermal/imx_thermal.c:imx_change_mode() {
if (data->irq_enabled) {
disable_irq(data->irq);
data->irq_enabled = false;
}
}
If a hardware interrupt fires between the check and the call to
disable_irq(), the hardirq handler modifies the same flag and disables
the interrupt:
drivers/thermal/imx_thermal.c:imx_thermal_alarm_irq() {
...
disable_irq_nosync(irq);
data->irq_enabled = false;
...
}
Would imx_change_mode() then call disable_irq() a second time,
increasing the disable depth to 2? Since future enable attempts will only
decrement the depth to 1, could this leave the interrupt permanently
disabled and force the system to rely on slower polling?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260713-b4-symana21-11221-imx-thermal-support-upstream-6-18-v5-0-69405c306c6b@cn.bosch.com?part=2
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v5 1/2] dt-bindings: thermal: imx: Document calibration offset property
2026-07-13 5:51 ` [PATCH v5 1/2] dt-bindings: thermal: imx: Document calibration offset property HaoNing Cheng via B4 Relay
@ 2026-07-13 9:51 ` Krzysztof Kozlowski
0 siblings, 0 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2026-07-13 9:51 UTC (permalink / raw)
To: HaoNing Cheng
Cc: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Shawn Guo,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, linux-pm,
devicetree, imx, linux-arm-kernel, linux-kernel,
Krzysztof Kozlowski
On Mon, Jul 13, 2026 at 01:51:33PM +0800, HaoNing Cheng wrote:
> Some boards need a small per-design correction to align the reported CPU
> temperature with board-level measurements.
>
> Document the optional fsl,temp-calibration-offset-millicelsius property,
> a signed offset in millicelsius that is added to the calculated sensor
> temperature. The property is optional and the existing behaviour is kept
> when it is omitted.
>
> Update the binding example to show its usage.
>
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
> Signed-off-by: Haoning CHENG <Haoning.CHENG@cn.bosch.com>
Now this causes a warning as it does not match the From. Well, that's
trivial thing, but why did you change it?
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-07-13 9:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-13 5:51 [PATCH v5 0/2] thermal: imx: Add calibration offset support HaoNing Cheng via B4 Relay
2026-07-13 5:51 ` [PATCH v5 1/2] dt-bindings: thermal: imx: Document calibration offset property HaoNing Cheng via B4 Relay
2026-07-13 9:51 ` Krzysztof Kozlowski
2026-07-13 5:51 ` [PATCH v5 2/2] thermal/drivers/imx: Add calibration offset support HaoNing Cheng via B4 Relay
2026-07-13 6:04 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox