public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] thermal: sun8i: extend H6 calibration function to support 4 sensors
@ 2023-12-17 13:36 Maksim Kiselev
  2023-12-18 11:14 ` Andre Przywara
  0 siblings, 1 reply; 3+ messages in thread
From: Maksim Kiselev @ 2023-12-17 13:36 UTC (permalink / raw)
  Cc: Maksim Kiselev, Martin Botka, Andre Przywara, Vasily Khoruzhick,
	Yangtao Li, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
	Lukasz Luba, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
	open list:ALLWINNER THERMAL DRIVER,
	moderated list:ARM/Allwinner sunXi SoC support,
	open list:ARM/Allwinner sunXi SoC support, open list

The H616 SoC resembles the H6 thermal sensor controller, with a few
changes like four sensors.

Extend sun50i_h6_ths_calibrate() function to support calibration of
these sensors.

Signed-off-by: Martin Botka <martin.botka@somainline.org>
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Maksim Kiselev <bigunclemax@gmail.com>
---
 drivers/thermal/sun8i_thermal.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c
index f989b55a8aa8..9af95b4785be 100644
--- a/drivers/thermal/sun8i_thermal.c
+++ b/drivers/thermal/sun8i_thermal.c
@@ -221,16 +221,21 @@ static int sun50i_h6_ths_calibrate(struct ths_device *tmdev,
 	struct device *dev = tmdev->dev;
 	int i, ft_temp;
 
-	if (!caldata[0] || callen < 2 + 2 * tmdev->chip->sensor_num)
+	if (!caldata[0])
 		return -EINVAL;
 
 	/*
 	 * efuse layout:
 	 *
-	 *	0   11  16	 32
-	 *	+-------+-------+-------+
-	 *	|temp|  |sensor0|sensor1|
-	 *	+-------+-------+-------+
+	 * 0      11  16     27   32     43   48    57
+	 * +----------+-----------+-----------+-----------+
+	 * |  temp |  |sensor0|   |sensor1|   |sensor2|   |
+	 * +----------+-----------+-----------+-----------+
+	 *                      ^           ^           ^
+	 *                      |           |           |
+	 *                      |           |           sensor3[11:8]
+	 *                      |           sensor3[7:4]
+	 *                      sensor3[3:0]
 	 *
 	 * The calibration data on the H6 is the ambient temperature and
 	 * sensor values that are filled during the factory test stage.
@@ -243,9 +248,16 @@ static int sun50i_h6_ths_calibrate(struct ths_device *tmdev,
 	ft_temp = (caldata[0] & FT_TEMP_MASK) * 100;
 
 	for (i = 0; i < tmdev->chip->sensor_num; i++) {
-		int sensor_reg = caldata[i + 1] & TEMP_CALIB_MASK;
-		int cdata, offset;
-		int sensor_temp = tmdev->chip->calc_temp(tmdev, i, sensor_reg);
+		int sensor_reg, sensor_temp, cdata, offset;
+
+		if (i == 3)
+			sensor_reg = (caldata[1] >> 12)
+				     | ((caldata[2] >> 12) << 4)
+				     | ((caldata[3] >> 12) << 8);
+		else
+			sensor_reg = caldata[i + 1] & TEMP_CALIB_MASK;
+
+		sensor_temp = tmdev->chip->calc_temp(tmdev, i, sensor_reg);
 
 		/*
 		 * Calibration data is CALIBRATE_DEFAULT - (calculated
-- 
2.40.1


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

* Re: [PATCH v1] thermal: sun8i: extend H6 calibration function to support 4 sensors
  2023-12-17 13:36 [PATCH v1] thermal: sun8i: extend H6 calibration function to support 4 sensors Maksim Kiselev
@ 2023-12-18 11:14 ` Andre Przywara
  2023-12-27 13:25   ` Daniel Lezcano
  0 siblings, 1 reply; 3+ messages in thread
From: Andre Przywara @ 2023-12-18 11:14 UTC (permalink / raw)
  To: Maksim Kiselev
  Cc: Martin Botka, Vasily Khoruzhick, Yangtao Li, Rafael J. Wysocki,
	Daniel Lezcano, Zhang Rui, Lukasz Luba, Chen-Yu Tsai,
	Jernej Skrabec, Samuel Holland,
	open list:ALLWINNER THERMAL DRIVER,
	moderated list:ARM/Allwinner sunXi SoC support,
	open list:ARM/Allwinner sunXi SoC support, open list

On Sun, 17 Dec 2023 16:36:36 +0300
Maksim Kiselev <bigunclemax@gmail.com> wrote:

Hi Maksim,

many thanks for sending this!

> The H616 SoC resembles the H6 thermal sensor controller, with a few
> changes like four sensors.
> 
> Extend sun50i_h6_ths_calibrate() function to support calibration of
> these sensors.

Oh wow, I didn't expect that, but it's indeed that simple: we just need to
cater for the 4th sensor's data to be cramped into the other bits, the
rest is exactly the same! Well spotted!

> Signed-off-by: Martin Botka <martin.botka@somainline.org>
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>

I don't think the Signed-off-by:s are accurate here. Please replace those
two with just:
Co-developed-by: Martin Botka <martin.botka@somainline.org>
(I didn't really do anything in those parts)

> Signed-off-by: Maksim Kiselev <bigunclemax@gmail.com>

I compared the two routines and came to the same solution as you, so:

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

I will incorporate this patch into the next submission of the H616 THS
series, so there is no need to merge this patch as is.

Cheers,
Andre

> ---
>  drivers/thermal/sun8i_thermal.c | 28 ++++++++++++++++++++--------
>  1 file changed, 20 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c
> index f989b55a8aa8..9af95b4785be 100644
> --- a/drivers/thermal/sun8i_thermal.c
> +++ b/drivers/thermal/sun8i_thermal.c
> @@ -221,16 +221,21 @@ static int sun50i_h6_ths_calibrate(struct ths_device *tmdev,
>  	struct device *dev = tmdev->dev;
>  	int i, ft_temp;
>  
> -	if (!caldata[0] || callen < 2 + 2 * tmdev->chip->sensor_num)
> +	if (!caldata[0])
>  		return -EINVAL;
>  
>  	/*
>  	 * efuse layout:
>  	 *
> -	 *	0   11  16	 32
> -	 *	+-------+-------+-------+
> -	 *	|temp|  |sensor0|sensor1|
> -	 *	+-------+-------+-------+
> +	 * 0      11  16     27   32     43   48    57
> +	 * +----------+-----------+-----------+-----------+
> +	 * |  temp |  |sensor0|   |sensor1|   |sensor2|   |
> +	 * +----------+-----------+-----------+-----------+
> +	 *                      ^           ^           ^
> +	 *                      |           |           |
> +	 *                      |           |           sensor3[11:8]
> +	 *                      |           sensor3[7:4]
> +	 *                      sensor3[3:0]
>  	 *
>  	 * The calibration data on the H6 is the ambient temperature and
>  	 * sensor values that are filled during the factory test stage.
> @@ -243,9 +248,16 @@ static int sun50i_h6_ths_calibrate(struct ths_device *tmdev,
>  	ft_temp = (caldata[0] & FT_TEMP_MASK) * 100;
>  
>  	for (i = 0; i < tmdev->chip->sensor_num; i++) {
> -		int sensor_reg = caldata[i + 1] & TEMP_CALIB_MASK;
> -		int cdata, offset;
> -		int sensor_temp = tmdev->chip->calc_temp(tmdev, i, sensor_reg);
> +		int sensor_reg, sensor_temp, cdata, offset;
> +
> +		if (i == 3)
> +			sensor_reg = (caldata[1] >> 12)
> +				     | ((caldata[2] >> 12) << 4)
> +				     | ((caldata[3] >> 12) << 8);
> +		else
> +			sensor_reg = caldata[i + 1] & TEMP_CALIB_MASK;
> +
> +		sensor_temp = tmdev->chip->calc_temp(tmdev, i, sensor_reg);
>  
>  		/*
>  		 * Calibration data is CALIBRATE_DEFAULT - (calculated


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

* Re: [PATCH v1] thermal: sun8i: extend H6 calibration function to support 4 sensors
  2023-12-18 11:14 ` Andre Przywara
@ 2023-12-27 13:25   ` Daniel Lezcano
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Lezcano @ 2023-12-27 13:25 UTC (permalink / raw)
  To: Andre Przywara
  Cc: Maksim Kiselev, Martin Botka, Vasily Khoruzhick, Yangtao Li,
	Rafael J. Wysocki, Zhang Rui, Lukasz Luba, Chen-Yu Tsai,
	Jernej Skrabec, Samuel Holland,
	open list:ALLWINNER THERMAL DRIVER,
	moderated list:ARM/Allwinner sunXi SoC support,
	open list:ARM/Allwinner sunXi SoC support, open list

On Mon, Dec 18, 2023 at 11:14:04AM +0000, Andre Przywara wrote:

[ ... ]

> I will incorporate this patch into the next submission of the H616 THS
> series, so there is no need to merge this patch as is.

Noted, thanks

  -- Daniel

[ ... ]
-- 

 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

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

end of thread, other threads:[~2023-12-27 13:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-17 13:36 [PATCH v1] thermal: sun8i: extend H6 calibration function to support 4 sensors Maksim Kiselev
2023-12-18 11:14 ` Andre Przywara
2023-12-27 13:25   ` Daniel Lezcano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox