summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Kresin <dev@kresin.me>2016-10-17 20:25:53 +0200
committerMathias Kresin <dev@kresin.me>2016-10-19 19:55:06 +0200
commit23e3314cad2afcc5ef2897c247db11218b9df042 (patch)
treeef73444ed437ceec3a09e580927bf6780c98a0f1
parenteba84bee4ce518dc509fe51f252c5307dccf3a1c (diff)
downloadmtk-20170518-23e3314cad2afcc5ef2897c247db11218b9df042.zip
mtk-20170518-23e3314cad2afcc5ef2897c247db11218b9df042.tar.gz
mtk-20170518-23e3314cad2afcc5ef2897c247db11218b9df042.tar.bz2
lantiq: fix thermal sensors driver
Read the temperature including the decimale place from the CGU_GPHY1_CR register. Decrement the temperature read from the register by 38.0 degree celsius. The temperature range of the sensor is -38.0 to +154 °C and the register value 0 is equal to -38.0 °C. This fixes the report of unrealistic temperatures as seen on all tested boards. Give the SoC a few milliseconds to get the first temperature value. On some rare occasions there is no temperature value in the register when read the first time after activation. This leads to a reported temperature of -38.0 °C on boot. Only version 1.2 of the vr9 SoC has a temperature sensor. Add a check to make sure the driver doesn't load on v1.1 vr9 SoCs. Signed-off-by: Mathias Kresin <dev@kresin.me>
-rw-r--r--target/linux/lantiq/patches-4.4/0302-xrx200-add-sensors-driver.patch26
1 files changed, 21 insertions, 5 deletions
diff --git a/target/linux/lantiq/patches-4.4/0302-xrx200-add-sensors-driver.patch b/target/linux/lantiq/patches-4.4/0302-xrx200-add-sensors-driver.patch
index 628e476..33ff535 100644
--- a/target/linux/lantiq/patches-4.4/0302-xrx200-add-sensors-driver.patch
+++ b/target/linux/lantiq/patches-4.4/0302-xrx200-add-sensors-driver.patch
@@ -27,7 +27,7 @@
depends on SPI_MASTER
--- /dev/null
+++ b/drivers/hwmon/ltq-cputemp.c
-@@ -0,0 +1,138 @@
+@@ -0,0 +1,154 @@
+/* Lantiq CPU Temperatur sensor driver for xrx200
+ *
+ * Copyright (C) 2016 Florian Eckert <feckert@tdt.de>
@@ -48,6 +48,7 @@
+
+#include <linux/module.h>
+#include <linux/init.h>
++#include <linux/delay.h>
+#include <linux/of_device.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
@@ -61,6 +62,9 @@
+static void ltq_cputemp_enable(void)
+{
+ ltq_cgu_w32(ltq_cgu_r32(CGU_GPHY1_CR) | CGU_TEMP_PD, CGU_GPHY1_CR);
++
++ /* wait a short moment to let the SoC get the first temperatur value */
++ mdelay(100);
+}
+
+static void ltq_cputemp_disable(void)
@@ -70,8 +74,16 @@
+
+static int ltq_cputemp_read(void)
+{
-+ /* Shift 9 for register alignment and 1 to divide value by 2 */
-+ return (ltq_cgu_r32(CGU_GPHY1_CR) >> 10) & 0xFF;
++ int value;
++
++ /* get the temperature including one decimal place */
++ value = (ltq_cgu_r32(CGU_GPHY1_CR) >> 9) & 0x01FF;
++ value = (value << 2 ) + value;
++
++ /* range -38 to +154 °C, register value zero is -38.0 °C */
++ value -= 380;
++
++ return value;
+}
+
+static ssize_t show_cputemp(struct device *dev,
@@ -81,7 +93,7 @@
+
+ value = ltq_cputemp_read();
+ /* scale temp to millidegree */
-+ value = value * 1000;
++ value = value * 100;
+
+ return sprintf(buf, "%d\n", value);
+}
@@ -101,6 +113,10 @@
+ int ret;
+ struct device *hwmon_dev;
+
++ /* available on vr9 v1.2 SoCs only */
++ if (ltq_soc_type() != SOC_TYPE_VR9_2)
++ return -ENODEV;
++
+ hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
+ "CPU0",
+ NULL,
@@ -114,7 +130,7 @@
+
+ ltq_cputemp_enable();
+ value = ltq_cputemp_read();
-+ dev_info(&pdev->dev, "Current CPU die temperature: %d °C", value);
++ dev_info(&pdev->dev, "Current CPU die temperature: %d.%d °C", value / 10, value % 10);
+
+ return 0;
+