* [PATCH v7 1/7] thermal/drivers/exynos: Refactor clk_sec initialization inside SOC-specific case
2025-08-13 13:09 [PATCH v7 0/7] Exynos Thermal code improvement Anand Moon
@ 2025-08-13 13:09 ` Anand Moon
2025-08-13 13:09 ` [PATCH v7 2/7] thermal/drivers/exynos: Use devm_clk_get_enabled() helpers Anand Moon
` (5 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Anand Moon @ 2025-08-13 13:09 UTC (permalink / raw)
To: Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski, Rafael J. Wysocki,
Daniel Lezcano, Zhang Rui, Lukasz Luba, Alim Akhtar,
Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
open list:SAMSUNG THERMAL DRIVER,
open list:SAMSUNG THERMAL DRIVER,
moderated list:ARM/SAMSUNG S3C, S5P AND EXYNOS ARM ARCHITECTURES,
open list,
open list:CLANG/LLVM BUILD SUPPORT:Keyword:b(?i:clang|llvm)b
Cc: Anand Moon, Mateusz Majewski
Refactor the initialization of the clk_sec clock to be inside the
SOC_ARCH_EXYNOS5420_TRIMINFO case. It ensures that the clk_sec clock
is only initialized for the specified SOC and not for other SOCs,
thereby simplifying the code. The clk_sec clock is used by the TMU
for GPU on the Exynos 542x platform.
Removed redundant IS_ERR() checks for the clk_sec clock since error
handling is already managed internally by clk_unprepare() functions.
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Signed-off-by: Anand Moon <linux.amoon@gmail.com>
---
v7: None
v6: Add Rb Lukasz and try to address Daniel review coments.
v5: None
v4: Fix the aligment of code clk for clk_prepare in proper if/else block.
update the commit for clk_sec used.
checked to goto clean up all the clks are proper.
drop IS_ERR() check for clk_sec.
v3: improve the commit message.
---
drivers/thermal/samsung/exynos_tmu.c | 36 +++++++++++++---------------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
index 47a99b3c5395..04517d52afbd 100644
--- a/drivers/thermal/samsung/exynos_tmu.c
+++ b/drivers/thermal/samsung/exynos_tmu.c
@@ -1040,26 +1040,26 @@ static int exynos_tmu_probe(struct platform_device *pdev)
if (IS_ERR(data->clk))
return dev_err_probe(dev, PTR_ERR(data->clk), "Failed to get clock\n");
- data->clk_sec = devm_clk_get(dev, "tmu_triminfo_apbif");
- if (IS_ERR(data->clk_sec)) {
- if (data->soc == SOC_ARCH_EXYNOS5420_TRIMINFO)
- return dev_err_probe(dev, PTR_ERR(data->clk_sec),
- "Failed to get triminfo clock\n");
- } else {
- ret = clk_prepare(data->clk_sec);
- if (ret) {
- dev_err(dev, "Failed to get clock\n");
- return ret;
- }
- }
-
ret = clk_prepare(data->clk);
if (ret) {
dev_err(dev, "Failed to get clock\n");
- goto err_clk_sec;
+ return ret;
}
switch (data->soc) {
+ case SOC_ARCH_EXYNOS5420_TRIMINFO:
+ data->clk_sec = devm_clk_get(dev, "tmu_triminfo_apbif");
+ if (IS_ERR(data->clk_sec)) {
+ ret = dev_err_probe(dev, PTR_ERR(data->clk_sec),
+ "Failed to get clk_sec clock\n");
+ goto err_clk;
+ }
+ ret = clk_prepare(data->clk_sec);
+ if (ret) {
+ dev_err(dev, "Failed to prepare clk_sec clock\n");
+ goto err_clk_sec;
+ }
+ break;
case SOC_ARCH_EXYNOS5433:
case SOC_ARCH_EXYNOS7:
data->sclk = devm_clk_get(dev, "tmu_sclk");
@@ -1112,11 +1112,10 @@ static int exynos_tmu_probe(struct platform_device *pdev)
err_sclk:
clk_disable_unprepare(data->sclk);
+err_clk_sec:
+ clk_unprepare(data->clk_sec);
err_clk:
clk_unprepare(data->clk);
-err_clk_sec:
- if (!IS_ERR(data->clk_sec))
- clk_unprepare(data->clk_sec);
return ret;
}
@@ -1128,8 +1127,7 @@ static void exynos_tmu_remove(struct platform_device *pdev)
clk_disable_unprepare(data->sclk);
clk_unprepare(data->clk);
- if (!IS_ERR(data->clk_sec))
- clk_unprepare(data->clk_sec);
+ clk_unprepare(data->clk_sec);
}
#ifdef CONFIG_PM_SLEEP
--
2.50.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v7 2/7] thermal/drivers/exynos: Use devm_clk_get_enabled() helpers
2025-08-13 13:09 [PATCH v7 0/7] Exynos Thermal code improvement Anand Moon
2025-08-13 13:09 ` [PATCH v7 1/7] thermal/drivers/exynos: Refactor clk_sec initialization inside SOC-specific case Anand Moon
@ 2025-08-13 13:09 ` Anand Moon
2025-08-13 13:09 ` [PATCH v7 3/7] thermal/drivers/exynos: Remove redundant IS_ERR() checks for clk_sec clock Anand Moon
` (4 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Anand Moon @ 2025-08-13 13:09 UTC (permalink / raw)
To: Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski, Rafael J. Wysocki,
Daniel Lezcano, Zhang Rui, Lukasz Luba, Alim Akhtar,
Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
open list:SAMSUNG THERMAL DRIVER,
open list:SAMSUNG THERMAL DRIVER,
moderated list:ARM/SAMSUNG S3C, S5P AND EXYNOS ARM ARCHITECTURES,
open list,
open list:CLANG/LLVM BUILD SUPPORT:Keyword:b(?i:clang|llvm)b
Cc: Anand Moon, Mateusz Majewski
Use devm_clk_get_enabled() helper instead of calling devm_clk_get() and
then clk_prepare_enable(). It simplifies the error handling and makes
the code more compact.
Suggested-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Anand Moon <linux.amoon@gmail.com>
---
v7: None
v6: New patch as per Daniel request.
---
drivers/thermal/samsung/exynos_tmu.c | 77 ++++++++--------------------
1 file changed, 20 insertions(+), 57 deletions(-)
diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
index 04517d52afbd..aa0726b33c84 100644
--- a/drivers/thermal/samsung/exynos_tmu.c
+++ b/drivers/thermal/samsung/exynos_tmu.c
@@ -1036,65 +1036,41 @@ static int exynos_tmu_probe(struct platform_device *pdev)
if (ret)
return ret;
- data->clk = devm_clk_get(dev, "tmu_apbif");
+ data->clk = devm_clk_get_enabled(dev, "tmu_apbif");
if (IS_ERR(data->clk))
- return dev_err_probe(dev, PTR_ERR(data->clk), "Failed to get clock\n");
-
- ret = clk_prepare(data->clk);
- if (ret) {
- dev_err(dev, "Failed to get clock\n");
- return ret;
- }
-
- switch (data->soc) {
- case SOC_ARCH_EXYNOS5420_TRIMINFO:
- data->clk_sec = devm_clk_get(dev, "tmu_triminfo_apbif");
- if (IS_ERR(data->clk_sec)) {
- ret = dev_err_probe(dev, PTR_ERR(data->clk_sec),
- "Failed to get clk_sec clock\n");
- goto err_clk;
- }
- ret = clk_prepare(data->clk_sec);
- if (ret) {
- dev_err(dev, "Failed to prepare clk_sec clock\n");
- goto err_clk_sec;
- }
- break;
- case SOC_ARCH_EXYNOS5433:
- case SOC_ARCH_EXYNOS7:
- data->sclk = devm_clk_get(dev, "tmu_sclk");
- if (IS_ERR(data->sclk)) {
- ret = dev_err_probe(dev, PTR_ERR(data->sclk), "Failed to get sclk\n");
- goto err_clk;
- } else {
- ret = clk_prepare_enable(data->sclk);
- if (ret) {
- dev_err(dev, "Failed to enable sclk\n");
- goto err_clk;
- }
- }
- break;
- default:
- break;
+ return dev_err_probe(dev, PTR_ERR(data->clk),
+ "Failed to get clock\n");
+
+ if (data->soc == SOC_ARCH_EXYNOS5420_TRIMINFO) {
+ data->clk_sec = devm_clk_get_enabled(dev, "tmu_triminfo_apbif");
+ if (IS_ERR(data->clk_sec))
+ return dev_err_probe(dev, PTR_ERR(data->clk_sec),
+ "Failed to get clk_sec clock\n");
+ } else if (data->soc == SOC_ARCH_EXYNOS5433 ||
+ data->soc == SOC_ARCH_EXYNOS7) {
+ data->sclk = devm_clk_get_enabled(dev, "tmu_sclk");
+ if (IS_ERR(data->sclk))
+ return dev_err_probe(dev, PTR_ERR(data->sclk),
+ "Failed to get sclk\n");
}
ret = exynos_tmu_initialize(pdev);
if (ret) {
dev_err(dev, "Failed to initialize TMU\n");
- goto err_sclk;
+ return ret;
}
data->tzd = devm_thermal_of_zone_register(dev, 0, data,
&exynos_sensor_ops);
if (IS_ERR(data->tzd)) {
- ret = dev_err_probe(dev, PTR_ERR(data->tzd), "Failed to register sensor\n");
- goto err_sclk;
+ return dev_err_probe(dev, PTR_ERR(data->tzd),
+ "Failed to register sensor\n");
}
ret = exynos_thermal_zone_configure(pdev);
if (ret) {
dev_err(dev, "Failed to configure the thermal zone\n");
- goto err_sclk;
+ return ret;
}
ret = devm_request_threaded_irq(dev, data->irq, NULL,
@@ -1104,30 +1080,17 @@ static int exynos_tmu_probe(struct platform_device *pdev)
dev_name(dev), data);
if (ret) {
dev_err(dev, "Failed to request irq: %d\n", data->irq);
- goto err_sclk;
+ return ret;
}
exynos_tmu_control(pdev, true);
- return 0;
-err_sclk:
- clk_disable_unprepare(data->sclk);
-err_clk_sec:
- clk_unprepare(data->clk_sec);
-err_clk:
- clk_unprepare(data->clk);
return ret;
}
static void exynos_tmu_remove(struct platform_device *pdev)
{
- struct exynos_tmu_data *data = platform_get_drvdata(pdev);
-
exynos_tmu_control(pdev, false);
-
- clk_disable_unprepare(data->sclk);
- clk_unprepare(data->clk);
- clk_unprepare(data->clk_sec);
}
#ifdef CONFIG_PM_SLEEP
--
2.50.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v7 3/7] thermal/drivers/exynos: Remove redundant IS_ERR() checks for clk_sec clock
2025-08-13 13:09 [PATCH v7 0/7] Exynos Thermal code improvement Anand Moon
2025-08-13 13:09 ` [PATCH v7 1/7] thermal/drivers/exynos: Refactor clk_sec initialization inside SOC-specific case Anand Moon
2025-08-13 13:09 ` [PATCH v7 2/7] thermal/drivers/exynos: Use devm_clk_get_enabled() helpers Anand Moon
@ 2025-08-13 13:09 ` Anand Moon
2025-08-13 13:09 ` [PATCH v7 4/7] thermal/drivers/exynos: Fixed the efuse min max value for exynos5422 Anand Moon
` (3 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Anand Moon @ 2025-08-13 13:09 UTC (permalink / raw)
To: Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski, Rafael J. Wysocki,
Daniel Lezcano, Zhang Rui, Lukasz Luba, Alim Akhtar,
Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
open list:SAMSUNG THERMAL DRIVER,
open list:SAMSUNG THERMAL DRIVER,
moderated list:ARM/SAMSUNG S3C, S5P AND EXYNOS ARM ARCHITECTURES,
open list,
open list:CLANG/LLVM BUILD SUPPORT:Keyword:b(?i:clang|llvm)b
Cc: Anand Moon, Mateusz Majewski
Remove unnecessary IS_ERR() checks for the clk_sec clock,
the clk_enable() and clk_disable() functions can handle NULL clock
pointers, so the additional checks are redundant and have been removed
to simplify the code.
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Signed-off-by: Anand Moon <linux.amoon@gmail.com>
---
v7: None
v6: Add Rb - Lukasz and Fix the typo in the subject
v5: None
v4: drop IE_ERR() for clk_unprepare() as its handle in earlier code.
v3: improve the commit message.
---
drivers/thermal/samsung/exynos_tmu.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
index aa0726b33c84..5f017a78f437 100644
--- a/drivers/thermal/samsung/exynos_tmu.c
+++ b/drivers/thermal/samsung/exynos_tmu.c
@@ -258,8 +258,7 @@ static int exynos_tmu_initialize(struct platform_device *pdev)
mutex_lock(&data->lock);
clk_enable(data->clk);
- if (!IS_ERR(data->clk_sec))
- clk_enable(data->clk_sec);
+ clk_enable(data->clk_sec);
status = readb(data->base + EXYNOS_TMU_REG_STATUS);
if (!status) {
@@ -269,8 +268,7 @@ static int exynos_tmu_initialize(struct platform_device *pdev)
data->tmu_clear_irqs(data);
}
- if (!IS_ERR(data->clk_sec))
- clk_disable(data->clk_sec);
+ clk_disable(data->clk_sec);
clk_disable(data->clk);
mutex_unlock(&data->lock);
--
2.50.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v7 4/7] thermal/drivers/exynos: Fixed the efuse min max value for exynos5422
2025-08-13 13:09 [PATCH v7 0/7] Exynos Thermal code improvement Anand Moon
` (2 preceding siblings ...)
2025-08-13 13:09 ` [PATCH v7 3/7] thermal/drivers/exynos: Remove redundant IS_ERR() checks for clk_sec clock Anand Moon
@ 2025-08-13 13:09 ` Anand Moon
2025-08-13 13:09 ` [PATCH v7 5/7] thermal/drivers/exynos: Remove unused base_second mapping and references Anand Moon
` (2 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Anand Moon @ 2025-08-13 13:09 UTC (permalink / raw)
To: Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski, Rafael J. Wysocki,
Daniel Lezcano, Zhang Rui, Lukasz Luba, Alim Akhtar,
Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
open list:SAMSUNG THERMAL DRIVER,
open list:SAMSUNG THERMAL DRIVER,
moderated list:ARM/SAMSUNG S3C, S5P AND EXYNOS ARM ARCHITECTURES,
open list,
open list:CLANG/LLVM BUILD SUPPORT:Keyword:b(?i:clang|llvm)b
Cc: Anand Moon, Mateusz Majewski
As per Exynos5422 user manual e-Fuse range min~max range is 16~76.
if e-Fuse value is out of this range, then thermal sensor may not
sense thermal data properly. Additionally, refactors the efuse
initialization logic in exynos_map_dt_data() by replacing nested
if-else blocks with a switch statement for better readability
and maintainability. Ensures correct efuse setup based on SoC type.
Signed-off-by: Anand Moon <linux.amoon@gmail.com>
---
v7: drop the Rb Llukasz, as we dropped the nested switch to set efuse.
v6: Add Rb Lukasz and fix typo in subject
v5: None
V4: None
---
drivers/thermal/samsung/exynos_tmu.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
index 5f017a78f437..3d12e95703bf 100644
--- a/drivers/thermal/samsung/exynos_tmu.c
+++ b/drivers/thermal/samsung/exynos_tmu.c
@@ -884,6 +884,22 @@ static int exynos_map_dt_data(struct platform_device *pdev)
case SOC_ARCH_EXYNOS4412:
case SOC_ARCH_EXYNOS5250:
case SOC_ARCH_EXYNOS5260:
+ data->tmu_set_low_temp = exynos4412_tmu_set_low_temp;
+ data->tmu_set_high_temp = exynos4412_tmu_set_high_temp;
+ data->tmu_disable_low = exynos4412_tmu_disable_low;
+ data->tmu_disable_high = exynos4210_tmu_disable_high;
+ data->tmu_set_crit_temp = exynos4412_tmu_set_crit_temp;
+ data->tmu_initialize = exynos4412_tmu_initialize;
+ data->tmu_control = exynos4210_tmu_control;
+ data->tmu_read = exynos4412_tmu_read;
+ data->tmu_set_emulation = exynos4412_tmu_set_emulation;
+ data->tmu_clear_irqs = exynos4210_tmu_clear_irqs;
+ data->gain = 8;
+ data->reference_voltage = 16;
+ data->efuse_value = 55;
+ data->min_efuse_value = 0;
+ data->max_efuse_value = 100;
+ break;
case SOC_ARCH_EXYNOS5420:
case SOC_ARCH_EXYNOS5420_TRIMINFO:
data->tmu_set_low_temp = exynos4412_tmu_set_low_temp;
@@ -899,12 +915,8 @@ static int exynos_map_dt_data(struct platform_device *pdev)
data->gain = 8;
data->reference_voltage = 16;
data->efuse_value = 55;
- if (data->soc != SOC_ARCH_EXYNOS5420 &&
- data->soc != SOC_ARCH_EXYNOS5420_TRIMINFO)
- data->min_efuse_value = 40;
- else
- data->min_efuse_value = 0;
- data->max_efuse_value = 100;
+ data->min_efuse_value = 16;
+ data->max_efuse_value = 76;
break;
case SOC_ARCH_EXYNOS5433:
data->tmu_set_low_temp = exynos5433_tmu_set_low_temp;
--
2.50.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v7 5/7] thermal/drivers/exynos: Remove unused base_second mapping and references
2025-08-13 13:09 [PATCH v7 0/7] Exynos Thermal code improvement Anand Moon
` (3 preceding siblings ...)
2025-08-13 13:09 ` [PATCH v7 4/7] thermal/drivers/exynos: Fixed the efuse min max value for exynos5422 Anand Moon
@ 2025-08-13 13:09 ` Anand Moon
2025-08-13 13:09 ` [PATCH v7 6/7] thermal/drivers/exynos: Handle temperature threshold IRQs with SoC-specific mapping Anand Moon
2025-08-13 13:09 ` [PATCH v7 7/7] thermal/drivers/exynos: Refactor IRQ clear logic using SoC-specific config Anand Moon
6 siblings, 0 replies; 13+ messages in thread
From: Anand Moon @ 2025-08-13 13:09 UTC (permalink / raw)
To: Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski, Rafael J. Wysocki,
Daniel Lezcano, Zhang Rui, Lukasz Luba, Alim Akhtar,
Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
open list:SAMSUNG THERMAL DRIVER,
open list:SAMSUNG THERMAL DRIVER,
moderated list:ARM/SAMSUNG S3C, S5P AND EXYNOS ARM ARCHITECTURES,
open list,
open list:CLANG/LLVM BUILD SUPPORT:Keyword:b(?i:clang|llvm)b
Cc: Anand Moon, Mateusz Majewski
The base_second field has been removed from struct exynos_tmu_data
because it was unused. This cleanup also eliminates its mapping in
exynos_map_dt_data() and ensures that TRIMINFO access in
exynos4412_tmu_initialize() consistently uses the base field across
all SoCs. This streamlines the code and optimizes memory usage.
Signed-off-by: Anand Moon <linux.amoon@gmail.com>
---
v7: new patch in this series,
Improve the commit message
simplify the logic to TRIMINFO for all SoC.
---
drivers/thermal/samsung/exynos_tmu.c | 30 +++++++---------------------
1 file changed, 7 insertions(+), 23 deletions(-)
diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
index 3d12e95703bf..146f29fadea9 100644
--- a/drivers/thermal/samsung/exynos_tmu.c
+++ b/drivers/thermal/samsung/exynos_tmu.c
@@ -139,12 +139,11 @@ enum soc_type {
* struct exynos_tmu_data : A structure to hold the private data of the TMU
* driver
* @base: base address of the single instance of the TMU controller.
- * @base_second: base address of the common registers of the TMU controller.
* @irq: irq number of the TMU controller.
* @soc: id of the SOC type.
* @lock: lock to implement synchronization.
* @clk: pointer to the clock structure.
- * @clk_sec: pointer to the clock structure for accessing the base_second.
+ * @clk_sec: pointer to the clock structure for accessing the gpu clk.
* @sclk: pointer to the clock structure for accessing the tmu special clk.
* @cal_type: calibration type for temperature
* @efuse_value: SoC defined fuse value
@@ -172,7 +171,6 @@ enum soc_type {
*/
struct exynos_tmu_data {
void __iomem *base;
- void __iomem *base_second;
int irq;
enum soc_type soc;
struct mutex lock;
@@ -444,24 +442,17 @@ static void exynos4412_tmu_initialize(struct platform_device *pdev)
struct exynos_tmu_data *data = platform_get_drvdata(pdev);
unsigned int trim_info, ctrl;
- if (data->soc == SOC_ARCH_EXYNOS3250 ||
- data->soc == SOC_ARCH_EXYNOS4412 ||
- data->soc == SOC_ARCH_EXYNOS5250) {
- if (data->soc == SOC_ARCH_EXYNOS3250) {
- ctrl = readl(data->base + EXYNOS_TMU_TRIMINFO_CON1);
- ctrl |= EXYNOS_TRIMINFO_RELOAD_ENABLE;
- writel(ctrl, data->base + EXYNOS_TMU_TRIMINFO_CON1);
- }
+ if (data->soc == SOC_ARCH_EXYNOS3250) {
+ ctrl = readl(data->base + EXYNOS_TMU_TRIMINFO_CON1);
+ ctrl |= EXYNOS_TRIMINFO_RELOAD_ENABLE;
+ writel(ctrl, data->base + EXYNOS_TMU_TRIMINFO_CON1);
+ } else {
ctrl = readl(data->base + EXYNOS_TMU_TRIMINFO_CON2);
ctrl |= EXYNOS_TRIMINFO_RELOAD_ENABLE;
writel(ctrl, data->base + EXYNOS_TMU_TRIMINFO_CON2);
}
- /* On exynos5420 the triminfo register is in the shared space */
- if (data->soc == SOC_ARCH_EXYNOS5420_TRIMINFO)
- trim_info = readl(data->base_second + EXYNOS_TMU_REG_TRIMINFO);
- else
- trim_info = readl(data->base + EXYNOS_TMU_REG_TRIMINFO);
+ trim_info = readl(data->base + EXYNOS_TMU_REG_TRIMINFO);
sanitize_temp_error(data, trim_info);
}
@@ -974,13 +965,6 @@ static int exynos_map_dt_data(struct platform_device *pdev)
return -ENODEV;
}
- data->base_second = devm_ioremap(&pdev->dev, res.start,
- resource_size(&res));
- if (!data->base_second) {
- dev_err(&pdev->dev, "Failed to ioremap memory\n");
- return -ENOMEM;
- }
-
return 0;
}
--
2.50.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v7 6/7] thermal/drivers/exynos: Handle temperature threshold IRQs with SoC-specific mapping
2025-08-13 13:09 [PATCH v7 0/7] Exynos Thermal code improvement Anand Moon
` (4 preceding siblings ...)
2025-08-13 13:09 ` [PATCH v7 5/7] thermal/drivers/exynos: Remove unused base_second mapping and references Anand Moon
@ 2025-08-13 13:09 ` Anand Moon
[not found] ` <CGME20250819131732eucas1p26bd491e9b6b747a4857905bfd50420a9@eucas1p2.samsung.com>
2025-08-13 13:09 ` [PATCH v7 7/7] thermal/drivers/exynos: Refactor IRQ clear logic using SoC-specific config Anand Moon
6 siblings, 1 reply; 13+ messages in thread
From: Anand Moon @ 2025-08-13 13:09 UTC (permalink / raw)
To: Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski, Rafael J. Wysocki,
Daniel Lezcano, Zhang Rui, Lukasz Luba, Alim Akhtar,
Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
open list:SAMSUNG THERMAL DRIVER,
open list:SAMSUNG THERMAL DRIVER,
moderated list:ARM/SAMSUNG S3C, S5P AND EXYNOS ARM ARCHITECTURES,
open list,
open list:CLANG/LLVM BUILD SUPPORT:Keyword:b(?i:clang|llvm)b
Cc: Anand Moon, Mateusz Majewski
The Exynos TMU interrupt handling mechanism has been refined to utilize
SoC-specific mappings for interrupt clear registers, targeting rising and
falling edge events. This change introduces a tmu_irq_map structure that
defines these edge-specific interrupt bits, improving the accuracy of
thermal event handling by ensuring that only relevant interrupts are
acknowledged and cleared. The exynos4210_tmu_clear_irqs() function has
been refactored to incorporate this mapping. Notably, for Exynos4210,
a check has been added to prevent clearing unsupported falling edge
interrupt bits.
As per user manuals, specific mappings for interrupt status and clear
registers include:
Exynos4412: Falling edge bits at 20, 16, 12, and
rising edge bits at 8, 4, 0.
Exynos5422: Falling edge bits at 24, 20, 16, and
rising edge bits at 8, 4, 0.
Exynos5433: Falling edge bits at 23, 17, 16, and
rising edge bits at 7, 1, 0.
Cc: Mateusz Majewski <m.majewski2@samsung.com>
Signed-off-by: Anand Moon <linux.amoon@gmail.com>
---
v7: New patch in this series
simpilfy the logic for set and clear rising and failling
edges of the IRQ clear register.
[0] https://lore.kernel.org/all/20250624075815.132207-1-m.majewski2@samsung.com/
---
drivers/thermal/samsung/exynos_tmu.c | 70 ++++++++++++++++++++++++----
1 file changed, 60 insertions(+), 10 deletions(-)
diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
index 146f29fadea9..5e581055e3f3 100644
--- a/drivers/thermal/samsung/exynos_tmu.c
+++ b/drivers/thermal/samsung/exynos_tmu.c
@@ -197,6 +197,12 @@ struct exynos_tmu_data {
void (*tmu_clear_irqs)(struct exynos_tmu_data *data);
};
+/* Map Rise and Falling edges for IRQ Clean */
+struct tmu_irq_map {
+ u32 fall[3];
+ u32 rise[3];
+};
+
/*
* TMU treats temperature as a mapped temperature code.
* The temperature is converted differently depending on the calibration type.
@@ -765,8 +771,9 @@ static irqreturn_t exynos_tmu_threaded_irq(int irq, void *id)
static void exynos4210_tmu_clear_irqs(struct exynos_tmu_data *data)
{
- unsigned int val_irq;
+ unsigned int val_irq, clear_irq = 0;
u32 tmu_intstat, tmu_intclear;
+ struct tmu_irq_map irq_map = {0};
if (data->soc == SOC_ARCH_EXYNOS5260) {
tmu_intstat = EXYNOS5260_TMU_REG_INTSTAT;
@@ -783,15 +790,58 @@ static void exynos4210_tmu_clear_irqs(struct exynos_tmu_data *data)
}
val_irq = readl(data->base + tmu_intstat);
- /*
- * Clear the interrupts. Please note that the documentation for
- * Exynos3250, Exynos4412, Exynos5250 and Exynos5260 incorrectly
- * states that INTCLEAR register has a different placing of bits
- * responsible for FALL IRQs than INTSTAT register. Exynos5420
- * and Exynos5440 documentation is correct (Exynos4210 doesn't
- * support FALL IRQs at all).
- */
- writel(val_irq, data->base + tmu_intclear);
+
+ /* Exynos4210 doesn't support FALL interrupts */
+ if (data->soc == SOC_ARCH_EXYNOS4210) {
+ writel(val_irq, data->base + tmu_intclear);
+ return;
+ }
+
+ /* Set SoC-specific interrupt bit mappings */
+ switch (data->soc) {
+ case SOC_ARCH_EXYNOS3250:
+ case SOC_ARCH_EXYNOS4412:
+ case SOC_ARCH_EXYNOS5250:
+ case SOC_ARCH_EXYNOS5260:
+ irq_map.fall[2] = BIT(20);
+ irq_map.fall[1] = BIT(16);
+ irq_map.fall[0] = BIT(12);
+ irq_map.rise[2] = BIT(8);
+ irq_map.rise[1] = BIT(4);
+ irq_map.rise[0] = BIT(0);
+ break;
+ case SOC_ARCH_EXYNOS5420:
+ case SOC_ARCH_EXYNOS5420_TRIMINFO:
+ irq_map.fall[2] = BIT(24);
+ irq_map.fall[1] = BIT(20);
+ irq_map.fall[0] = BIT(16);
+ irq_map.rise[2] = BIT(8);
+ irq_map.rise[1] = BIT(4);
+ irq_map.rise[0] = BIT(0);
+ break;
+ case SOC_ARCH_EXYNOS5433:
+ case SOC_ARCH_EXYNOS7:
+ irq_map.fall[2] = BIT(23);
+ irq_map.fall[1] = BIT(17);
+ irq_map.fall[0] = BIT(16);
+ irq_map.rise[2] = BIT(7);
+ irq_map.rise[1] = BIT(1);
+ irq_map.rise[0] = BIT(0);
+ break;
+ default:
+ pr_warn("exynos-tmu: Unknown SoC type %d, using fallback IRQ mapping\n", soc);
+ break;
+
+ /* Map active INTSTAT bits to INTCLEAR */
+ for (int i = 0; i < 3; i++) {
+ if (val_irq & irq_map.fall[i])
+ clear_irq |= irq_map.fall[i];
+ if (val_irq & irq_map.rise[i])
+ clear_irq |= irq_map.rise[i];
+ }
+
+ if (clear_irq)
+ writel(clear_irq, data->base + tmu_intclear);
}
static const struct of_device_id exynos_tmu_match[] = {
--
2.50.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v7 7/7] thermal/drivers/exynos: Refactor IRQ clear logic using SoC-specific config
2025-08-13 13:09 [PATCH v7 0/7] Exynos Thermal code improvement Anand Moon
` (5 preceding siblings ...)
2025-08-13 13:09 ` [PATCH v7 6/7] thermal/drivers/exynos: Handle temperature threshold IRQs with SoC-specific mapping Anand Moon
@ 2025-08-13 13:09 ` Anand Moon
[not found] ` <CGME20250819131814eucas1p2c57ccc084cf6736fed01a8a5c0b35fab@eucas1p2.samsung.com>
6 siblings, 1 reply; 13+ messages in thread
From: Anand Moon @ 2025-08-13 13:09 UTC (permalink / raw)
To: Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski, Rafael J. Wysocki,
Daniel Lezcano, Zhang Rui, Lukasz Luba, Alim Akhtar,
Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
open list:SAMSUNG THERMAL DRIVER,
open list:SAMSUNG THERMAL DRIVER,
moderated list:ARM/SAMSUNG S3C, S5P AND EXYNOS ARM ARCHITECTURES,
open list,
open list:CLANG/LLVM BUILD SUPPORT:Keyword:b(?i:clang|llvm)b
Cc: Anand Moon, Mateusz Majewski
The Exynos TMU driver's IRQ clear logic has been refactored for improved
maintainability and reduced code duplication. A unified
exynos4210_tmu_clear_irqs() implementation now replaces the previous
reliance on SoC-specific functions and hardcoded register mappings.
This new implementation leverages SoC-specific configuration fields
(tmu_intstat, tmu_intclear, and IRQ bit mappings) stored within
exynos_tmu_data. These fields are populated during device setup within
exynos_map_dt_data(), thereby streamlining new SoC integration, ensuring
correct interrupt handling, and improving code clarity. This refactor
simplifies the addition of new SoC support, ensures correct interrupt
handling across platforms, and improves overall code clarity.
Cc: Mateusz Majewski <m.majewski2@samsung.com>
Signed-off-by: Anand Moon <linux.amoon@gmail.com>
---
v7: new patch in this series
split the IRQ function handler per SoC.
---
drivers/thermal/samsung/exynos_tmu.c | 150 +++++++++++++++++----------
1 file changed, 96 insertions(+), 54 deletions(-)
diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
index 5e581055e3f3..9f94c58e1e74 100644
--- a/drivers/thermal/samsung/exynos_tmu.c
+++ b/drivers/thermal/samsung/exynos_tmu.c
@@ -158,6 +158,8 @@ enum soc_type {
* 0 < reference_voltage <= 31
* @tzd: pointer to thermal_zone_device structure
* @enabled: current status of TMU device
+ * @tmu_intstat: interrupt status register
+ * @tmu_intclear: interrupt clear register
* @tmu_set_low_temp: SoC specific method to set trip (falling threshold)
* @tmu_set_high_temp: SoC specific method to set trip (rising threshold)
* @tmu_set_crit_temp: SoC specific method to set critical temperature
@@ -184,6 +186,8 @@ struct exynos_tmu_data {
u8 reference_voltage;
struct thermal_zone_device *tzd;
bool enabled;
+ u32 tmu_intstat;
+ u32 tmu_intclear;
void (*tmu_set_low_temp)(struct exynos_tmu_data *data, u8 temp);
void (*tmu_set_high_temp)(struct exynos_tmu_data *data, u8 temp);
@@ -770,67 +774,90 @@ static irqreturn_t exynos_tmu_threaded_irq(int irq, void *id)
}
static void exynos4210_tmu_clear_irqs(struct exynos_tmu_data *data)
+{
+ unsigned int val_irq;
+ u32 tmu_intstat = data->tmu_intstat;
+ u32 tmu_intclear = data->tmu_intclear;
+
+ val_irq = readl(data->base + tmu_intstat);
+
+ /* Exynos4210 doesn't support FALL interrupts */
+ writel(val_irq, data->base + tmu_intclear);
+}
+
+static void exynos4412_tmu_clear_irqs(struct exynos_tmu_data *data)
{
unsigned int val_irq, clear_irq = 0;
- u32 tmu_intstat, tmu_intclear;
+ u32 tmu_intstat = data->tmu_intstat;
+ u32 tmu_intclear = data->tmu_intclear;
struct tmu_irq_map irq_map = {0};
- if (data->soc == SOC_ARCH_EXYNOS5260) {
- tmu_intstat = EXYNOS5260_TMU_REG_INTSTAT;
- tmu_intclear = EXYNOS5260_TMU_REG_INTCLEAR;
- } else if (data->soc == SOC_ARCH_EXYNOS7) {
- tmu_intstat = EXYNOS7_TMU_REG_INTPEND;
- tmu_intclear = EXYNOS7_TMU_REG_INTPEND;
- } else if (data->soc == SOC_ARCH_EXYNOS5433) {
- tmu_intstat = EXYNOS5433_TMU_REG_INTPEND;
- tmu_intclear = EXYNOS5433_TMU_REG_INTPEND;
- } else {
- tmu_intstat = EXYNOS_TMU_REG_INTSTAT;
- tmu_intclear = EXYNOS_TMU_REG_INTCLEAR;
+ val_irq = readl(data->base + tmu_intstat);
+
+ /* Set SoC-specific interrupt bit mappings */
+ irq_map.fall[2] = BIT(20);
+ irq_map.fall[1] = BIT(16);
+ irq_map.fall[0] = BIT(12);
+ irq_map.rise[2] = BIT(8);
+ irq_map.rise[1] = BIT(4);
+ irq_map.rise[0] = BIT(0);
+
+ /* Map active INTSTAT bits to INTCLEAR */
+ for (int i = 0; i < 3; i++) {
+ if (val_irq & irq_map.fall[i])
+ clear_irq |= irq_map.fall[i];
+ if (val_irq & irq_map.rise[i])
+ clear_irq |= irq_map.rise[i];
}
+ if (clear_irq)
+ writel(clear_irq, data->base + tmu_intclear);
+}
+
+static void exynos5420_tmu_clear_irqs(struct exynos_tmu_data *data)
+{
+ unsigned int val_irq, clear_irq = 0;
+ u32 tmu_intstat = data->tmu_intstat;
+ u32 tmu_intclear = data->tmu_intclear;
+ struct tmu_irq_map irq_map = {0};
+
val_irq = readl(data->base + tmu_intstat);
- /* Exynos4210 doesn't support FALL interrupts */
- if (data->soc == SOC_ARCH_EXYNOS4210) {
- writel(val_irq, data->base + tmu_intclear);
- return;
+ /* Set SoC-specific interrupt bit mappings */
+ irq_map.fall[2] = BIT(24);
+ irq_map.fall[1] = BIT(20);
+ irq_map.fall[0] = BIT(16);
+ irq_map.rise[2] = BIT(8);
+ irq_map.rise[1] = BIT(4);
+ irq_map.rise[0] = BIT(0);
+
+ for (int i = 0; i < 3; i++) {
+ if (val_irq & irq_map.fall[i])
+ clear_irq |= irq_map.fall[i];
+ if (val_irq & irq_map.rise[i])
+ clear_irq |= irq_map.rise[i];
}
+ if (clear_irq)
+ writel(clear_irq, data->base + tmu_intclear);
+}
+
+static void exynos5433_tmu_clear_irqs(struct exynos_tmu_data *data)
+{
+ unsigned int val_irq, clear_irq = 0;
+ u32 tmu_intstat = data->tmu_intstat;
+ u32 tmu_intclear = data->tmu_intclear;
+ struct tmu_irq_map irq_map = {0};
+
+ val_irq = readl(data->base + tmu_intstat);
+
/* Set SoC-specific interrupt bit mappings */
- switch (data->soc) {
- case SOC_ARCH_EXYNOS3250:
- case SOC_ARCH_EXYNOS4412:
- case SOC_ARCH_EXYNOS5250:
- case SOC_ARCH_EXYNOS5260:
- irq_map.fall[2] = BIT(20);
- irq_map.fall[1] = BIT(16);
- irq_map.fall[0] = BIT(12);
- irq_map.rise[2] = BIT(8);
- irq_map.rise[1] = BIT(4);
- irq_map.rise[0] = BIT(0);
- break;
- case SOC_ARCH_EXYNOS5420:
- case SOC_ARCH_EXYNOS5420_TRIMINFO:
- irq_map.fall[2] = BIT(24);
- irq_map.fall[1] = BIT(20);
- irq_map.fall[0] = BIT(16);
- irq_map.rise[2] = BIT(8);
- irq_map.rise[1] = BIT(4);
- irq_map.rise[0] = BIT(0);
- break;
- case SOC_ARCH_EXYNOS5433:
- case SOC_ARCH_EXYNOS7:
- irq_map.fall[2] = BIT(23);
- irq_map.fall[1] = BIT(17);
- irq_map.fall[0] = BIT(16);
- irq_map.rise[2] = BIT(7);
- irq_map.rise[1] = BIT(1);
- irq_map.rise[0] = BIT(0);
- break;
- default:
- pr_warn("exynos-tmu: Unknown SoC type %d, using fallback IRQ mapping\n", soc);
- break;
+ irq_map.fall[2] = BIT(23);
+ irq_map.fall[1] = BIT(17);
+ irq_map.fall[0] = BIT(16);
+ irq_map.rise[2] = BIT(7);
+ irq_map.rise[1] = BIT(1);
+ irq_map.rise[0] = BIT(0);
/* Map active INTSTAT bits to INTCLEAR */
for (int i = 0; i < 3; i++) {
@@ -915,6 +942,8 @@ 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->tmu_intstat = EXYNOS_TMU_REG_INTSTAT;
+ data->tmu_intclear = EXYNOS_TMU_REG_INTCLEAR;
data->gain = 15;
data->reference_voltage = 7;
data->efuse_value = 55;
@@ -934,7 +963,14 @@ static int exynos_map_dt_data(struct platform_device *pdev)
data->tmu_control = exynos4210_tmu_control;
data->tmu_read = exynos4412_tmu_read;
data->tmu_set_emulation = exynos4412_tmu_set_emulation;
- data->tmu_clear_irqs = exynos4210_tmu_clear_irqs;
+ data->tmu_clear_irqs = exynos4412_tmu_clear_irqs;
+ if (data->soc == SOC_ARCH_EXYNOS5260) {
+ data->tmu_intstat = EXYNOS5260_TMU_REG_INTSTAT;
+ data->tmu_intclear = EXYNOS5260_TMU_REG_INTCLEAR;
+ } else {
+ data->tmu_intstat = EXYNOS_TMU_REG_INTSTAT;
+ data->tmu_intclear = EXYNOS_TMU_REG_INTCLEAR;
+ }
data->gain = 8;
data->reference_voltage = 16;
data->efuse_value = 55;
@@ -952,7 +988,9 @@ static int exynos_map_dt_data(struct platform_device *pdev)
data->tmu_control = exynos4210_tmu_control;
data->tmu_read = exynos4412_tmu_read;
data->tmu_set_emulation = exynos4412_tmu_set_emulation;
- data->tmu_clear_irqs = exynos4210_tmu_clear_irqs;
+ data->tmu_clear_irqs = exynos5420_tmu_clear_irqs;
+ data->tmu_intstat = EXYNOS_TMU_REG_INTSTAT;
+ data->tmu_intclear = EXYNOS_TMU_REG_INTCLEAR;
data->gain = 8;
data->reference_voltage = 16;
data->efuse_value = 55;
@@ -969,7 +1007,9 @@ static int exynos_map_dt_data(struct platform_device *pdev)
data->tmu_control = exynos5433_tmu_control;
data->tmu_read = exynos4412_tmu_read;
data->tmu_set_emulation = exynos4412_tmu_set_emulation;
- data->tmu_clear_irqs = exynos4210_tmu_clear_irqs;
+ data->tmu_clear_irqs = exynos5433_tmu_clear_irqs;
+ data->tmu_intstat = EXYNOS5433_TMU_REG_INTPEND;
+ data->tmu_intclear = EXYNOS5433_TMU_REG_INTPEND;
data->gain = 8;
if (res.start == EXYNOS5433_G3D_BASE)
data->reference_voltage = 23;
@@ -989,7 +1029,9 @@ static int exynos_map_dt_data(struct platform_device *pdev)
data->tmu_control = exynos7_tmu_control;
data->tmu_read = exynos7_tmu_read;
data->tmu_set_emulation = exynos4412_tmu_set_emulation;
- data->tmu_clear_irqs = exynos4210_tmu_clear_irqs;
+ data->tmu_clear_irqs = exynos5433_tmu_clear_irqs;
+ data->tmu_intstat = EXYNOS7_TMU_REG_INTPEND;
+ data->tmu_intclear = EXYNOS7_TMU_REG_INTPEND;
data->gain = 9;
data->reference_voltage = 17;
data->efuse_value = 75;
--
2.50.1
^ permalink raw reply related [flat|nested] 13+ messages in thread