diff mbox series

[PATCH/RFT] thermal: rcar_thermal: update calculation formula for E3

Message ID 1551127558-28916-1-git-send-email-ykaneko0929@gmail.com (mailing list archive)
State Superseded, archived
Delegated to: Eduardo Valentin
Headers show
Series [PATCH/RFT] thermal: rcar_thermal: update calculation formula for E3 | expand

Commit Message

Yoshihiro Kaneko Feb. 25, 2019, 8:45 p.m. UTC
HW manual changes temperature calculation formula for E3:
- When CTEMP is less than 24
   T = CTEMP[5:0] * 5.5 - 72
- When CTEMP is equal to/greater than 24
   T = CTEMP[5:0] * 5 - 60

This was inspired by a patch in the BSP by Van Do <van.do.xw@renesas.com>

Signed-off-by: Yoshihiro Kaneko <ykaneko0929@gmail.com>
---

This patch is based on the master branch of Linus Torvalds's linux tree.

 drivers/thermal/rcar_thermal.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Simon Horman Feb. 26, 2019, 11:12 a.m. UTC | #1
On Tue, Feb 26, 2019 at 05:45:58AM +0900, Yoshihiro Kaneko wrote:
> HW manual changes temperature calculation formula for E3:

Thanks Kaneko-san,

I think it would be good do describe this patch not just in terms of E3.
Of the IP versions supported by the driver I believe this effects:

  R-Car V3M (r8a77970)
  R-Car E3 (r8a77990)
  R-Car D3 (r8a77995)
  RZ/G2E (r8a774c0)

> - When CTEMP is less than 24
>    T = CTEMP[5:0] * 5.5 - 72
> - When CTEMP is equal to/greater than 24
>    T = CTEMP[5:0] * 5 - 60
> 
> This was inspired by a patch in the BSP by Van Do <van.do.xw@renesas.com>
> 
> Signed-off-by: Yoshihiro Kaneko <ykaneko0929@gmail.com>
> ---
> 
> This patch is based on the master branch of Linus Torvalds's linux tree.
> 
>  drivers/thermal/rcar_thermal.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)

Using renesas-devel-20190225-v5.0-rc8 on an E3 based Ebisu board, I see:

# cat /sys/devices/virtual/thermal/thermal_zone0/temp
25000
# N=1; while [ $N -lt 1000000 ]; do N=$(($N + 1)); done & \
  N=1; while [ $N -lt 1000000 ]; do N=$(($N + 1)); done & \
  wait; \
  cat /sys/devices/virtual/thermal/thermal_zone0/temp
30000

And with this patch applied on top of renesas-devel-20190225-v5.0-rc8 I see:

# cat /sys/devices/virtual/thermal/thermal_zone0/temp
27000
# N=1; while [ $N -lt 1000000 ]; do N=$(($N + 1)); done & \
  N=1; while [ $N -lt 1000000 ]; do N=$(($N + 1)); done & \
  wait; \
  cat /sys/devices/virtual/thermal/thermal_zone0/temp
32000

I see the same, 27000/32000, result when running the test on
BSP v3.9.3-rc1, which includes Van Do's work.

The E3 has 2 cores

Tested-by: Simon Horman <horms+renesas@verge.net.au>

> diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c
> index 97462e9..11df0cc 100644
> --- a/drivers/thermal/rcar_thermal.c
> +++ b/drivers/thermal/rcar_thermal.c
> @@ -52,6 +52,7 @@ struct rcar_thermal_chip {
>  	unsigned int irq_per_ch : 1;
>  	unsigned int needs_suspend_resume : 1;
>  	unsigned int nirqs;
> +	unsigned int ctemp_bands;
>  };
>  
>  static const struct rcar_thermal_chip rcar_thermal = {
> @@ -60,6 +61,7 @@ struct rcar_thermal_chip {
>  	.irq_per_ch = 0,
>  	.needs_suspend_resume = 0,
>  	.nirqs = 1,
> +	.ctemp_bands = 1,
>  };
>  
>  static const struct rcar_thermal_chip rcar_gen2_thermal = {
> @@ -68,6 +70,7 @@ struct rcar_thermal_chip {
>  	.irq_per_ch = 0,
>  	.needs_suspend_resume = 0,
>  	.nirqs = 1,
> +	.ctemp_bands = 1,
>  };
>  
>  static const struct rcar_thermal_chip rcar_gen3_thermal = {
> @@ -80,6 +83,7 @@ struct rcar_thermal_chip {
>  	 * interrupts to detect a temperature change, rise or fall.
>  	 */
>  	.nirqs = 2,
> +	.ctemp_bands = 2,
>  };
>  
>  struct rcar_thermal_priv {
> @@ -263,7 +267,12 @@ static int rcar_thermal_get_current_temp(struct rcar_thermal_priv *priv,
>  		return ret;
>  
>  	mutex_lock(&priv->lock);
> -	tmp =  MCELSIUS((priv->ctemp * 5) - 65);
> +	if (priv->chip->ctemp_bands == 1)
> +		tmp =  MCELSIUS((priv->ctemp * 5) - 65);
> +	else if (priv->ctemp < 24)
> +		tmp = MCELSIUS(((priv->ctemp * 55) - 720) / 10);
> +	else
> +		tmp = MCELSIUS((priv->ctemp * 5) - 60);
>  	mutex_unlock(&priv->lock);
>  
>  	if ((tmp < MCELSIUS(-45)) || (tmp > MCELSIUS(125))) {
> -- 
> 1.9.1
>
Wolfram Sang March 5, 2019, 11:02 a.m. UTC | #2
On Tue, Feb 26, 2019 at 05:45:58AM +0900, Yoshihiro Kaneko wrote:
> HW manual changes temperature calculation formula for E3:
> - When CTEMP is less than 24
>    T = CTEMP[5:0] * 5.5 - 72
> - When CTEMP is equal to/greater than 24
>    T = CTEMP[5:0] * 5 - 60
> 
> This was inspired by a patch in the BSP by Van Do <van.do.xw@renesas.com>
> 
> Signed-off-by: Yoshihiro Kaneko <ykaneko0929@gmail.com>

Acked-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
diff mbox series

Patch

diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c
index 97462e9..11df0cc 100644
--- a/drivers/thermal/rcar_thermal.c
+++ b/drivers/thermal/rcar_thermal.c
@@ -52,6 +52,7 @@  struct rcar_thermal_chip {
 	unsigned int irq_per_ch : 1;
 	unsigned int needs_suspend_resume : 1;
 	unsigned int nirqs;
+	unsigned int ctemp_bands;
 };
 
 static const struct rcar_thermal_chip rcar_thermal = {
@@ -60,6 +61,7 @@  struct rcar_thermal_chip {
 	.irq_per_ch = 0,
 	.needs_suspend_resume = 0,
 	.nirqs = 1,
+	.ctemp_bands = 1,
 };
 
 static const struct rcar_thermal_chip rcar_gen2_thermal = {
@@ -68,6 +70,7 @@  struct rcar_thermal_chip {
 	.irq_per_ch = 0,
 	.needs_suspend_resume = 0,
 	.nirqs = 1,
+	.ctemp_bands = 1,
 };
 
 static const struct rcar_thermal_chip rcar_gen3_thermal = {
@@ -80,6 +83,7 @@  struct rcar_thermal_chip {
 	 * interrupts to detect a temperature change, rise or fall.
 	 */
 	.nirqs = 2,
+	.ctemp_bands = 2,
 };
 
 struct rcar_thermal_priv {
@@ -263,7 +267,12 @@  static int rcar_thermal_get_current_temp(struct rcar_thermal_priv *priv,
 		return ret;
 
 	mutex_lock(&priv->lock);
-	tmp =  MCELSIUS((priv->ctemp * 5) - 65);
+	if (priv->chip->ctemp_bands == 1)
+		tmp =  MCELSIUS((priv->ctemp * 5) - 65);
+	else if (priv->ctemp < 24)
+		tmp = MCELSIUS(((priv->ctemp * 55) - 720) / 10);
+	else
+		tmp = MCELSIUS((priv->ctemp * 5) - 60);
 	mutex_unlock(&priv->lock);
 
 	if ((tmp < MCELSIUS(-45)) || (tmp > MCELSIUS(125))) {