From 2db9f54300bcd98854a4ec4774516d280f749d4d Mon Sep 17 00:00:00 2001 From: Ye Zhang Date: Mon, 8 Jan 2024 16:56:44 +0800 Subject: [PATCH] thermal: rockchip: Round up code in rk_tsadcv2_temp_to_code rk_tsadcv2_temp_to_code rounds down, so the temperature that triggers the high temperature interrupt may be lower than the temperature we configured in dts. Therefore, it may not be possible to update the trip when the high temperature interrupt occurs, resulting in continuous interruptions. Signed-off-by: Ye Zhang Change-Id: I84511a612421b42a130c938b4573bddb6156dff6 --- drivers/thermal/rockchip_thermal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c index c116277fea5a..10c078ccf1b2 100644 --- a/drivers/thermal/rockchip_thermal.c +++ b/drivers/thermal/rockchip_thermal.c @@ -786,7 +786,7 @@ static u32 rk_tsadcv2_temp_to_code(const struct chip_tsadc_table *table, u32 error = table->data_mask; if (table->kNum) - return (((temp / 1000) * table->kNum) / 1000 + table->bNum); + return DIV_ROUND_UP(temp / 100 * table->kNum, 10000) + table->bNum; low = 0; high = (table->length - 1) - 1; /* ignore the last check for table */ @@ -818,9 +818,9 @@ static u32 rk_tsadcv2_temp_to_code(const struct chip_tsadc_table *table, switch (table->mode) { case ADC_DECREMENT: - return table->id[mid].code - (num / denom); + return table->id[mid].code - DIV_ROUND_UP(num, denom); case ADC_INCREMENT: - return table->id[mid].code + (num / denom); + return table->id[mid].code + DIV_ROUND_UP(num, denom); default: pr_err("%s: unknown table mode: %d\n", __func__, table->mode); return error;