[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <c0e9a395-41d1-4edc-a759-f958ea10387a@linaro.org>
Date: Wed, 7 May 2025 09:29:26 +0200
From: Daniel Lezcano <daniel.lezcano@...aro.org>
To: Christian Marangi <ansuelsmth@...il.com>
Cc: "Rafael J. Wysocki" <rafael@...nel.org>, Zhang Rui <rui.zhang@...el.com>,
Lukasz Luba <lukasz.luba@....com>, Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>, Conor Dooley
<conor+dt@...nel.org>, linux-pm@...r.kernel.org, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v5 2/2] thermal: Add support for Airoha EN7581 thermal
sensor
On 02/05/2025 17:00, Christian Marangi wrote:
> On Fri, May 02, 2025 at 03:30:56PM +0200, Daniel Lezcano wrote:
[ ... ]
>>> +static int airoha_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
>>> +{
>>> + struct airoha_thermal_priv *priv = thermal_zone_device_priv(tz);
>>> + int min, max, avg_temp, temp_adc;
>>> + int i;
>>> +
>>> + /* Get the starting temp */
>>> + temp_adc = airoha_get_thermal_ADC(priv);
>>> + min = temp_adc;
>>> + max = temp_adc;
>>> + avg_temp = temp_adc;
>>> +
>>> + /* Make 5 more measurement and average the temp ADC difference */
>>> + for (i = 0; i < 5; i++) {
>>> + temp_adc = airoha_get_thermal_ADC(priv);
>>> + avg_temp += temp_adc;
>>> + if (temp_adc > max)
>>> + max = temp_adc;
>>> + if (temp_adc < min)
>>> + min = temp_adc;
>>> + }
>>> + avg_temp = avg_temp - max - min;
>>> + avg_temp /= 4;
Why 4 ? There is 5 samples no ? one before the loop and 4 with the loop
>>> + *temp = RAW_TO_TEMP(priv, avg_temp);
Does RAW_TO_TEMP() on a average raw adc value report the same value as
an average of the temperature after their conversion ?
>>> + return 0;
>>> +}
The routine is a bit confusing because of the initial adc read.
avg_value = 0;
min_value = INT_MAX;
max_value = INT_MIN;
for (i = 0; i < AIROHA_MAX_SAMPLES; i++) {
value = airoha_get_thermal_ADC(priv);
min_value = min(value, min_value);
max_value = max(value, max_value);
avg_value += value;
}
avg_value -= (min_value + max_value);
avg_value /= AIROHA_MAX_SAMPLES;
>> Does this chip support the averaging with the filtered mode which prevent to
>> do this expensive calls when getting the temperature ?
>>
>
> If you notice in this function we read directly from the ADC sensor to
> have a more precise and realtime temperature.
>
> Yes the thermal module support averaging (and this is what is set for
> the critical temperature monitor) but since we base everything on
> interrupt the expensive call is called only when the user poll the
> temperature with sysfs.
When the temperature reaches the threshold, the interrupt is fired which
in turn calls thermal_zone_device_update(). This lead to a polling from
the kernel at a higher rate with the governor taking cooling decision.
> Do you prefer to use the thermal module entirely?
It is up to you. I would say if the sensor has a hardware assistance to
compute the averaging while the CPU does something else it is better.
But if the filtered mode has the same issues than the LVTS, then it is
probably not worth it.
[ ... ]
--
<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
Powered by blists - more mailing lists