linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thermal: hisilicon: increase temperature resolution
@ 2015-12-30  5:13 Leo Yan
  2016-02-18  9:39 ` Leo Yan
  0 siblings, 1 reply; 2+ messages in thread
From: Leo Yan @ 2015-12-30  5:13 UTC (permalink / raw)
  To: Zhang Rui, Eduardo Valentin, linux-pm, linux-kernel, kongxinwei; +Cc: Leo Yan

When calculate temperature, old code firstly do division and then
convert to "millicelsius" unit. This will lose resolution and only can
read back temperature with "Celsius" unit.

So firstly scale step value to "millicelsius" and then do division, so
finally we can increase resolution for temperature value. Also refine
the calculation from temperature value to step value.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 drivers/thermal/hisi_thermal.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c
index 36d0729..5e820b5 100644
--- a/drivers/thermal/hisi_thermal.c
+++ b/drivers/thermal/hisi_thermal.c
@@ -68,12 +68,12 @@ static inline int _step_to_temp(int step)
 	 * Every step equals (1 * 200) / 255 celsius, and finally
 	 * need convert to millicelsius.
 	 */
-	return (HISI_TEMP_BASE + (step * 200 / 255)) * 1000;
+	return (HISI_TEMP_BASE * 1000 + (step * 200000 / 255));
 }
 
 static inline long _temp_to_step(long temp)
 {
-	return ((temp / 1000 - HISI_TEMP_BASE) * 255 / 200);
+	return ((temp - HISI_TEMP_BASE * 1000) * 255) / 200000;
 }
 
 static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data,
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] thermal: hisilicon: increase temperature resolution
  2015-12-30  5:13 [PATCH] thermal: hisilicon: increase temperature resolution Leo Yan
@ 2016-02-18  9:39 ` Leo Yan
  0 siblings, 0 replies; 2+ messages in thread
From: Leo Yan @ 2016-02-18  9:39 UTC (permalink / raw)
  To: Zhang Rui, Eduardo Valentin, linux-pm, linux-kernel, kongxinwei

Hi Rui, Eduardo,

On Wed, Dec 30, 2015 at 01:13:02PM +0800, Leo Yan wrote:
> When calculate temperature, old code firstly do division and then
> convert to "millicelsius" unit. This will lose resolution and only can
> read back temperature with "Celsius" unit.
> 
> So firstly scale step value to "millicelsius" and then do division, so
> finally we can increase resolution for temperature value. Also refine
> the calculation from temperature value to step value.
> 
> Signed-off-by: Leo Yan <leo.yan@linaro.org>

Could you help merge this patch?

Thanks,
Leo Yan

> ---
>  drivers/thermal/hisi_thermal.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c
> index 36d0729..5e820b5 100644
> --- a/drivers/thermal/hisi_thermal.c
> +++ b/drivers/thermal/hisi_thermal.c
> @@ -68,12 +68,12 @@ static inline int _step_to_temp(int step)
>  	 * Every step equals (1 * 200) / 255 celsius, and finally
>  	 * need convert to millicelsius.
>  	 */
> -	return (HISI_TEMP_BASE + (step * 200 / 255)) * 1000;
> +	return (HISI_TEMP_BASE * 1000 + (step * 200000 / 255));
>  }
>  
>  static inline long _temp_to_step(long temp)
>  {
> -	return ((temp / 1000 - HISI_TEMP_BASE) * 255 / 200);
> +	return ((temp - HISI_TEMP_BASE * 1000) * 255) / 200000;
>  }
>  
>  static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data,
> -- 
> 1.9.1
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-18  9:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-30  5:13 [PATCH] thermal: hisilicon: increase temperature resolution Leo Yan
2016-02-18  9:39 ` Leo Yan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).