Commit 1e9a1aea authored by Caesar Wang's avatar Caesar Wang Committed by Eduardo Valentin

thermal: rockchip: make temperature reporting much more accurate

In general, the kernel should report temperature readings exactly as
reported by the hardware. The cpu / gpu thermal driver works in 5 degree
increments,but we ought to do more accurate. The temperature will do
linear interpolation between the entries in the table.

Test= $md5sum /dev/zero &
$while true; do grep "" /sys/class/thermal/thermal_zone[1-2]/temp;
sleep .5; done

e.g. We can get the result as follows:
    /sys/class/thermal/thermal_zone1/temp:39994
    /sys/class/thermal/thermal_zone2/temp:39086
    /sys/class/thermal/thermal_zone1/temp:39994
    /sys/class/thermal/thermal_zone2/temp:39540
    /sys/class/thermal/thermal_zone1/temp:39540
    /sys/class/thermal/thermal_zone2/temp:39540
    /sys/class/thermal/thermal_zone1/temp:39540
    /sys/class/thermal/thermal_zone2/temp:39994
Reviewed-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Reviewed-by: default avatarDaniel Kurtz <djkurtz@chromium.org>
Signed-off-by: default avatarCaesar Wang <wxt@rock-chips.com>
Signed-off-by: default avatarEduardo Valentin <edubezval@gmail.com>
parent 1fd2273f
...@@ -193,19 +193,20 @@ static u32 rk_tsadcv2_temp_to_code(long temp) ...@@ -193,19 +193,20 @@ static u32 rk_tsadcv2_temp_to_code(long temp)
static long rk_tsadcv2_code_to_temp(u32 code) static long rk_tsadcv2_code_to_temp(u32 code)
{ {
int high, low, mid; unsigned int low = 0;
unsigned int high = ARRAY_SIZE(v2_code_table) - 1;
low = 0; unsigned int mid = (low + high) / 2;
high = ARRAY_SIZE(v2_code_table) - 1; unsigned int num;
mid = (high + low) / 2; unsigned long denom;
if (code > v2_code_table[low].code || code < v2_code_table[high].code) /* Invalid code, return -EAGAIN */
return 125000; /* No code available, return max temperature */ if (code > TSADCV2_DATA_MASK)
return -EAGAIN;
while (low <= high) { while (low <= high && mid) {
if (code >= v2_code_table[mid].code && code < if (code >= v2_code_table[mid].code &&
v2_code_table[mid - 1].code) code < v2_code_table[mid - 1].code)
return v2_code_table[mid].temp; break;
else if (code < v2_code_table[mid].code) else if (code < v2_code_table[mid].code)
low = mid + 1; low = mid + 1;
else else
...@@ -213,7 +214,16 @@ static long rk_tsadcv2_code_to_temp(u32 code) ...@@ -213,7 +214,16 @@ static long rk_tsadcv2_code_to_temp(u32 code)
mid = (low + high) / 2; mid = (low + high) / 2;
} }
return 125000; /*
* The 5C granularity provided by the table is too much. Let's
* assume that the relationship between sensor readings and
* temperature between 2 table entries is linear and interpolate
* to produce less granular result.
*/
num = v2_code_table[mid].temp - v2_code_table[mid - 1].temp;
num *= v2_code_table[mid - 1].code - code;
denom = v2_code_table[mid - 1].code - v2_code_table[mid].code;
return v2_code_table[mid - 1].temp + (num / denom);
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment