Calling stm_thermal_read_factory_settings before clocking
internal peripheral causes bad register values and makes
temperature computation wrong.

Calling stm_thermal_read_factory_settings inside
stm_thermal_prepare fixes this problem as internal
peripheral is well clocked at this stage.

Signed-off-by: David Hernandez Sanchez <david.hernandezsanc...@st.com>
Fixes: 1d693155 ("thermal: add stm32 thermal driver")

diff --git a/drivers/thermal/st/stm_thermal.c b/drivers/thermal/st/stm_thermal.c
index 47623da..daa1257 100644
--- a/drivers/thermal/st/stm_thermal.c
+++ b/drivers/thermal/st/stm_thermal.c
@@ -532,6 +532,10 @@ static int stm_thermal_prepare(struct stm_thermal_sensor 
*sensor)
        if (ret)
                return ret;
 
+       ret = stm_thermal_read_factory_settings(sensor);
+       if (ret)
+               goto thermal_unprepare;
+
        ret = stm_thermal_calibration(sensor);
        if (ret)
                goto thermal_unprepare;
@@ -636,10 +640,6 @@ static int stm_thermal_probe(struct platform_device *pdev)
        /* Populate sensor */
        sensor->base = base;
 
-       ret = stm_thermal_read_factory_settings(sensor);
-       if (ret)
-               return ret;
-
        sensor->clk = devm_clk_get(&pdev->dev, "pclk");
        if (IS_ERR(sensor->clk)) {
                dev_err(&pdev->dev, "%s: failed to fetch PCLK clock\n",
-- 
2.7.4

Reply via email to