[08/12] thermal: qoriq: Enable monitoring before querying temperature
diff mbox series

Message ID 20190218191141.3729-9-andrew.smirnov@gmail.com
State Changes Requested
Delegated to: Eduardo Valentin
Headers show
Series
  • QorIQ TMU multi-sensor and HWMON support
Related show

Commit Message

Andrey Smirnov Feb. 18, 2019, 7:11 p.m. UTC
Devm_thermal_zone_of_sensor_register() will call tmu_get_temp() as a
part of its execution, so we need to enable monitoring before that
happens in order to avoid returning bogus values. Change the ordering
in qoriq_tmu_probe() a bit to fix that.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/thermal/qoriq_thermal.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Patch
diff mbox series

diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index 97419ce70d83..6478d7a8168f 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -223,6 +223,10 @@  static int qoriq_tmu_probe(struct platform_device *pdev)
 	if (ret < 0)
 		return ret;
 
+	/* Enable monitoring */
+	site = 0x1 << (15 - data->sensor_id);
+	regmap_write(data->regmap, REGS_TMR, site | TMR_ME | TMR_ALPF);
+
 	data->tz = devm_thermal_zone_of_sensor_register(dev,
 							data->sensor_id,
 							data, &tmu_tz_ops);
@@ -230,20 +234,21 @@  static int qoriq_tmu_probe(struct platform_device *pdev)
 		ret = PTR_ERR(data->tz);
 		dev_err(dev, "Failed to register thermal zone device %d\n",
 			ret);
-		return ret;
+		goto disable_monitoring;
 	}
 
 	ret = devm_thermal_add_hwmon_sysfs(data->tz);
 	if (ret)
-		return ret;
+		goto disable_monitoring;
 
 	platform_set_drvdata(pdev, data);
 
-	/* Enable monitoring */
-	site = 0x1 << (15 - data->sensor_id);
-	regmap_write(data->regmap, REGS_TMR, site | TMR_ME | TMR_ALPF);
-
 	return 0;
+
+disable_monitoring:
+	/* Disable monitoring */
+	regmap_write(data->regmap, REGS_TMR, TMR_DISABLE);
+	return ret;
 }
 
 static int qoriq_tmu_remove(struct platform_device *pdev)