Re: [PATCH v3 2/4] thermal: renesas: rzg3s: Add thermal driver for the Renesas RZ/G3S SoC

From: Geert Uytterhoeven
Date: Wed Mar 26 2025 - 09:28:49 EST


Hi Claudiu,

On Mon, 24 Mar 2025 at 14:57, Claudiu <claudiu.beznea@xxxxxxxxx> wrote:
> From: Claudiu Beznea <claudiu.beznea.uj@xxxxxxxxxxxxxx>
>
> The Renesas RZ/G3S SoC features a Thermal Sensor Unit (TSU) that reports
> the junction temperature. The temperature is reported through a dedicated
> ADC channel. Add a driver for the Renesas RZ/G3S TSU.
>
> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@xxxxxxxxxxxxxx>
> ---
>
> Changes in v3:
> - drop the runtime resume/suspend from rzg3s_thermal_get_temp(); this
> is not needed as the temperature is read with ADC
> - opened the devres group id in rzg3s_thermal_probe() and rename
> previsouly rzg3s_thermal_probe() to rzg3s_thermal_probe_helper(), to
> have simpler code; this approach was suggested by Jonathan in [1];
> as there is no positive feedback for the generic solution [2] this
> looks currently the best approach

Thanks for the update!

> --- /dev/null
> +++ b/drivers/thermal/renesas/rzg3s_thermal.c

> +static int rzg3s_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
> +{
> + struct rzg3s_thermal_priv *priv = thermal_zone_device_priv(tz);
> + int ts_code_ave = 0;
> + int ret, val;
> +
> + if (priv->mode != THERMAL_DEVICE_ENABLED)
> + return -EAGAIN;
> +
> + for (u8 i = 0; i < TSU_READ_STEPS; i++) {
> + ret = iio_read_channel_raw(priv->channel, &val);
> + if (ret < 0)
> + return ret;
> +
> + ts_code_ave += val;
> + /*
> + * According to the HW manual (section 40.4.4 Procedure for Measuring the
> + * Temperature) we need to wait here at leat 3us.
> + */
> + usleep_range(5, 10);
> + }
> +
> + ret = 0;
> + ts_code_ave = DIV_ROUND_CLOSEST(MCELSIUS(ts_code_ave), TSU_READ_STEPS);
> +
> + /*
> + * According to the HW manual (section 40.4.4 Procedure for Measuring the Temperature)
> + * the computation formula is as follows:
> + *
> + * Tj = (ts_code_ave - priv->calib1) * 165 / (priv->calib0 - priv->calib1) - 40
> + *
> + * Convert everything to mili Celsius before applying the formula to avoid

milli

> + * losing precision.
> + */
> +
> + *temp = DIV_ROUND_CLOSEST((s64)(ts_code_ave - MCELSIUS(priv->calib1)) * MCELSIUS(165),
> + MCELSIUS(priv->calib0 - priv->calib1)) - MCELSIUS(40);

This is a 64-by-32 division. When compile-testing on arm32:

rzg3s_thermal.c:(.text+0x330): undefined reference to `__aeabi_ldivmod'

> +
> + /* Report it in mili degrees Celsius and round it up to 0.5 degrees Celsius. */

milli


> + *temp = roundup(*temp, 500);
> +
> + return ret;
> +}

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds