[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8963764e-0948-4f11-a907-de74b0f8ba3b@tuxon.dev>
Date: Sun, 10 Aug 2025 09:36:06 +0300
From: Claudiu Beznea <claudiu.beznea@...on.dev>
To: Geert Uytterhoeven <geert@...ux-m68k.org>
Cc: rafael@...nel.org, daniel.lezcano@...aro.org, rui.zhang@...el.com,
lukasz.luba@....com, robh@...nel.org, krzk+dt@...nel.org,
conor+dt@...nel.org, geert+renesas@...der.be, magnus.damm@...il.com,
p.zabel@...gutronix.de, linux-pm@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-renesas-soc@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
Claudiu Beznea <claudiu.beznea.uj@...renesas.com>
Subject: Re: [PATCH v3 2/4] thermal: renesas: rzg3s: Add thermal driver for
the Renesas RZ/G3S SoC
Hi, Geert,
On 26.03.2025 15:26, Geert Uytterhoeven wrote:
> Hi Claudiu,
>
> On Mon, 24 Mar 2025 at 14:57, Claudiu <claudiu.beznea@...on.dev> wrote:
>> From: Claudiu Beznea <claudiu.beznea.uj@...renesas.com>
>>
>> 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@...renesas.com>
>> ---
>>
>> 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'
Thank you for reporting this! I'll switch to div_s64().
Claudiu
>
>> +
>> + /* 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@...ux-m68k.org
>
> 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
Powered by blists - more mailing lists