thermal: rockchip: make temperature reporting much more accurate
Subsystems (2)
v3 cover thermal: rockchip: make temperature reporting much more accurate
This patch is merged on chromiumos/third_party/kernel.
https://chromium-review.googlesource.com/#/c/239190/
Tested on veyron boards.
Changes in v3:
Suggested-by Daniel Kurtz,
the check doesn't reject "code == 0xfff"
Fixed in rk_tsadcv2_code_to_temp(u32 code)
Changes in v2:
Caesar Wang (1):
thermal: rockchip: make temperature reporting much more accurate
drivers/thermal/rockchip_thermal.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-)
Signature · 1 line
1.9.1
PATCH v3 1/1 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---
Changes in v3:
Suggested-by Daniel Kurtz,
the check doesn't reject "code == 0xfff"
Fixed in rk_tsadcv2_code_to_temp(u32 code)
Changes in v2:
drivers/thermal/rockchip_thermal.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-)
drivers/thermal/rockchip_thermal.c +22 -10
@@ -193,19 +193,22 @@ static u32 rk_tsadcv2_temp_to_code(long temp)static long rk_tsadcv2_code_to_temp (u32 code) { -int high, low, mid; - - low =0 ; - high =ARRAY_SIZE (v2_code_table) -1 ; - mid = (high + low) /2 ; +unsigned int low =0 ; +unsigned int high =ARRAY_SIZE (v2_code_table) -1 ; +unsigned int mid = (low + high) /2 ; +unsigned int num; +unsigned long denom; +/* No code available, return callback */ if (code > v2_code_table[low].code || code < v2_code_table[high].code) -return 125000 ;/* No code available, return max temperature */ +return rk_tsadcv2_code_to_temp (code);while (low <= high) { -if (code >= v2_code_table[mid].code && code < - v2_code_table[mid -1 ].code) -return v2_code_table[mid].temp; +if (code >= v2_code_table[mid].code && + code < v2_code_table[mid -1 ].code) +break ; +else if (code ==TSADCV2_DATA_MASK ) +break ;else if (code < v2_code_table[mid].code) low = mid +1 ;else
@@ -213,7 +216,16 @@ static long rk_tsadcv2_code_to_temp(u32 code) 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); }/**
Signature · 1 line
1.9.1
Quoted 48 lines · Caesar Wang
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; donee.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:39994Signed-off-by Caesar Wang <[email protected]>Reviewed-by Dmitry Torokhov <[email protected]>---
Changes in v3:
Suggested-by Daniel Kurtz,
the check doesn't reject "code ==0xfff"
Fixed inrk_tsadcv2_code_to_temp(u32 code)Changes in v2:
Reviewed-by Dmitry Torokhov <[email protected]>drivers/thermal/rockchip_thermal.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-)drivers/thermal/rockchip_thermal.c +0
-5@@ -193,19 +193,22 @@ static u32 rk_tsadcv2_temp_to_code(long temp)static long rk_tsadcv2_code_to_temp (u32 code) { -int high, low, mid; - - low =0 ; - high =ARRAY_SIZE (v2_code_table) -1 ; - mid = (high + low) /2 ;
drivers/thermal/rockchip_thermal.c static u32 rk_tsadcv2_temp_to_code(long temp) · line 204
Quoted 10 lines
drivers/thermal/rockchip_thermal.c +7
-1+unsigned int low =0 ; +unsigned int high =ARRAY_SIZE (v2_code_table) -1 ; +unsigned int mid = (low + high) /2 ; +unsigned int num; +unsigned long denom; +/* No code available, return callback */ if (code > v2_code_table[low].code || code < v2_code_table[high].code) -return 125000 ;/* No code available, return max temperature */ +return rk_tsadcv2_code_to_temp (code);
Isn't this an infinite recursion?
Quoted 35 lines
drivers/thermal/rockchip_thermal.c +15
-5while (low <= high) { -if (code >= v2_code_table[mid].code && code < - v2_code_table[mid -1 ].code) -return v2_code_table[mid].temp; +if (code >= v2_code_table[mid].code && + code < v2_code_table[mid -1 ].code) +break ; +else if (code ==TSADCV2_DATA_MASK ) +break ;else if (code < v2_code_table[mid].code) low = mid +1 ;else @@ -213,7 +216,16 @@ static long rk_tsadcv2_code_to_temp(u32 code) 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); }/** -- 1.9.1
? 2015?01?22? 12:01, Daniel Kurtz ??:
Quoted 55 lines · Caesar Wang
Quoted 54 lines
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; donee.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:39994Signed-off-by Caesar Wang <[email protected]>Reviewed-by Dmitry Torokhov <[email protected]>---
Changes in v3:
Suggested-by Daniel Kurtz,
the check doesn't reject "code ==0xfff"
Fixed inrk_tsadcv2_code_to_temp(u32 code)Changes in v2:
Reviewed-by Dmitry Torokhov <[email protected]>drivers/thermal/rockchip_thermal.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-)drivers/thermal/rockchip_thermal.c +5
-5@@ -193,19 +193,22 @@ static u32 rk_tsadcv2_temp_to_code(long temp)static long rk_tsadcv2_code_to_temp (u32 code) { -int high, low, mid; - - low =0 ; - high =ARRAY_SIZE (v2_code_table) -1 ; - mid = (high + low) /2 ; +unsigned int low =0 ; +unsigned int high =ARRAY_SIZE (v2_code_table) -1 ; +unsigned int mid = (low + high) /2 ; +unsigned int num; +unsigned long denom;
Quoted 5 lines
drivers/thermal/rockchip_thermal.c static u32 rk_tsadcv2_temp_to_code(long temp) · line 204
Quoted 4 lines
drivers/thermal/rockchip_thermal.c +2
-1+/* No code available, return callback */ if (code > v2_code_table[low].code || code < v2_code_table[high].code) -return 125000 ;/* No code available, return max temperature */ +return rk_tsadcv2_code_to_temp (code);Isn't this an infinite recursion?
No, I think we can try check if it is happened.
Maybe we can return a warning/error for it.
Quoted 36 lines
Quoted 34 lines
drivers/thermal/rockchip_thermal.c +15
-5while (low <= high) { -if (code >= v2_code_table[mid].code && code < - v2_code_table[mid -1 ].code) -return v2_code_table[mid].temp; +if (code >= v2_code_table[mid].code && + code < v2_code_table[mid -1 ].code) +break ; +else if (code ==TSADCV2_DATA_MASK ) +break ;else if (code < v2_code_table[mid].code) low = mid +1 ;else @@ -213,7 +216,16 @@ static long rk_tsadcv2_code_to_temp(u32 code) 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); }/** -- 1.9.1
Signature · 8 lines
Best regards Caesar Wang (???) ??????????? Fuzhou Rockchip Electronics Co.Ltd ?????????????89????A?18??(350003) Addr:No.18 Building, A District, No.89, software Boulevard Fuzhou, Fujian,PRC Email:wxt at rock-chips.com Tel:+86-591-83991906/07->8221
Quoted 71 lines · Caesar Wang
? 2015?01?22? 12:01, Daniel Kurtz ??:
Quoted 58 lines · Caesar Wang
Quoted 57 lines
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; donee.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:39994Signed-off-by Caesar Wang <[email protected]>Reviewed-by Dmitry Torokhov <[email protected]>---
Changes in v3:
Suggested-by Daniel Kurtz,
the check doesn't reject "code ==0xfff"
Fixed inrk_tsadcv2_code_to_temp(u32 code)Changes in v2:
Reviewed-by Dmitry Torokhov <[email protected]>drivers/thermal/rockchip_thermal.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-)drivers/thermal/rockchip_thermal.c +5
-5@@ -193,19 +193,22 @@ static u32 rk_tsadcv2_temp_to_code(long temp)static long rk_tsadcv2_code_to_temp (u32 code) { -int high, low, mid; - - low =0 ; - high =ARRAY_SIZE (v2_code_table) -1 ; - mid = (high + low) /2 ; +unsigned int low =0 ; +unsigned int high =ARRAY_SIZE (v2_code_table) -1 ; +unsigned int mid = (low + high) /2 ; +unsigned int num; +unsigned long denom;Quoted 8 lines
Quoted 6 lines
drivers/thermal/rockchip_thermal.c +1
-1+/* No code available, return callback */ if (code > v2_code_table[low].code || code < v2_code_table[high].code) -return 125000 ;/* No code available, return max temperature */
+ returnrk_tsadcv2_code_to_temp(code);Isn't this an infinite recursion?
Quoted 2 lines
No, I think we can try check if it is happened.
Maybe we can return a warning/error for it.
I mean, if the 'if' condition is true, then this will just call the same function again with the same code, and again, and again... Just return an error code here, -ENOENT maybe?
I am not sure what error code is appropriate.
Quoted 50 lines
Quoted 30 lines
Quoted 30 lines
while (low <= high) {drivers/thermal/rockchip_thermal.c +15
-4-if (code >= v2_code_table[mid].code && code < - v2_code_table[mid -1 ].code) -return v2_code_table[mid].temp; +if (code >= v2_code_table[mid].code && + code < v2_code_table[mid -1 ].code) +break ; +else if (code ==TSADCV2_DATA_MASK ) +break ;else if (code < v2_code_table[mid].code) low = mid +1 ;else @@ -213,7 +216,16 @@ static long rk_tsadcv2_code_to_temp(u32 code) 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); }Quoted 7 lines
Quoted 5 lines
drivers/thermal/rockchip_thermal.c +0
-1/** -- 1.9.1
--
Best regards
Caesar Wang (???)
???????????
Fuzhou Rockchip Electronics Co.Ltd ?????????????89????A?18??(350003)
Addr:No.18 Building, A District, No.89, software Boulevard Fuzhou, Fujian,PRC
Email:wxt at rock-chips.com Tel:+86-591-83991906/07->8221
? 2015?01?22? 12:25, Daniel Kurtz ??:
Quoted 69 lines
Quoted 67 lines · Caesar Wang
? 2015?01?22? 12:01, Daniel Kurtz ??:
Quoted 64 lines · Caesar Wang
Quoted 60 lines
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; donee.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:39994Signed-off-by Caesar Wang <[email protected]>Reviewed-by Dmitry Torokhov <[email protected]>---
Changes in v3:
Suggested-by Daniel Kurtz,
the check doesn't reject "code ==0xfff"
Fixed inrk_tsadcv2_code_to_temp(u32 code)Changes in v2:
Reviewed-by Dmitry Torokhov <[email protected]>drivers/thermal/rockchip_thermal.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-)drivers/thermal/rockchip_thermal.c +6
-6@@ -193,19 +193,22 @@ static u32 rk_tsadcv2_temp_to_code(long temp)static long rk_tsadcv2_code_to_temp (u32 code) { -int high, low, mid; - - low =0 ; - high =ARRAY_SIZE (v2_code_table) -1 ; - mid = (high + low) /2 ; +unsigned int low =0 ; +unsigned int high =ARRAY_SIZE (v2_code_table) -1 ; +unsigned int mid = (low + high) /2 ; +unsigned int num; +unsigned long denom; +/* No code available, return callback */ if (code > v2_code_table[low].code || code < v2_code_table[high].code) -return 125000 ;/* No code available, return max Quoted 2 lines
temperature */
+ returnrk_tsadcv2_code_to_temp(code);Isn't this an infinite recursion?
Quoted 6 lines
Quoted 2 lines
No, I think we can try check if it is happened.
Maybe we can return a warning/error for it.I mean, if the 'if' condition is true, then this will just call the same function again with the same code, and again, and again... Just return an error code here,
-ENOENTmaybe?
I am not sure what error code is appropriate.
Maybe "return -EAGAIN"
Quoted 52 lines
Quoted 36 lines
Quoted 30 lines
Quoted 30 lines
while (low <= high) {drivers/thermal/rockchip_thermal.c +15
-4-if (code >= v2_code_table[mid].code && code < - v2_code_table[mid -1 ].code) -return v2_code_table[mid].temp; +if (code >= v2_code_table[mid].code && + code < v2_code_table[mid -1 ].code) +break ; +else if (code ==TSADCV2_DATA_MASK ) +break ;else if (code < v2_code_table[mid].code) low = mid +1 ;else @@ -213,7 +216,16 @@ static long rk_tsadcv2_code_to_temp(u32 code) 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); }Quoted 6 lines
Quoted 5 lines
drivers/thermal/rockchip_thermal.c +0
-1/** -- 1.9.1
Quoted 12 lines
--
Best regards
Caesar Wang (???)
???????????
Fuzhou Rockchip Electronics Co.Ltd ?????????????89????A?18??(350003)
Addr:No.18 Building, A District, No.89, software Boulevard Fuzhou, Fujian,PRC
Email:wxt at rock-chips.com Tel:+86-591-83991906/07->8221_______________________________________________
Linux-rockchip mailing list
Linux-rockchip at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip