From: Mathias Kresin Date: Mon, 17 Oct 2016 18:25:53 +0000 (+0200) Subject: lantiq: fix thermal sensors driver X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=23e3314cad2afcc5ef2897c247db11218b9df042;p=openwrt%2Fstaging%2Flynxis%2Fomap.git 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 --- 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 628e476a77..33ff535881 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 @@ -48,6 +48,7 @@ + +#include +#include ++#include +#include +#include +#include @@ -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; +