[PATCH 1/2] thermal/drivers/mediatek/auxadc: Register per-sensor thermal zones
Daniel Lezcano
daniel.lezcano at oss.qualcomm.com
Wed Oct 7 04:51:11 PDT 2026
On 10/6/26 04:54, Nils Büchner wrote:
> The driver registers only thermal zone 0, which reports the hottest of
> all sensors. The MT8183 devicetree also describes a zone per sensor
> (soc, gpu, md1, cpu-little, cpu-big, abb as sensor ids 1-6), and
> mtk-svs looks up the "gpu-thermal" zone for its GPU banks. Without it
> SVS fails to probe on MT8183:
>
> SVSB_GPU: cannot get "gpu-thermal" thermal zone
> mtk-svs 1100bc00.svs: error -ENODEV: svs bank resource setup fail
>
> so the SoC never gets its calibrated, lower voltages.
>
> Additionally register every sensor that has a devicetree zone, using
> sensor id = sensor number + 1, read from that sensor's own measurement
> register. Sensors without a zone are skipped, so SoCs whose devicetrees
> only describe zone 0 are unaffected.
>
> Runtime-tested on an Acer Chromebook Spin 311 (MT8183, juniper) with a
> 7.0-based kernel (the hardware is not set up to boot mainline);
> build-tested on mainline with W=1. On the device: all six
> sensor zones register and read plausible values (31-34 C idle, close
> to the board sensors), and mtk-svs finds gpu-thermal.
>
> The change and this changelog were drafted with an AI coding assistant
> during a debugging session on the hardware; they were reviewed and
> tested by the submitter.
>
> Assisted-by: Claude Opus 5.5
> Signed-off-by: Nils Büchner <nils at buechner.me>
> ---
> drivers/thermal/mediatek/auxadc_thermal.c | 80 ++++++++++++++++++++++-
> 1 file changed, 79 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c
> index 9ee2e7283..59c8eaf87 100644
> --- a/drivers/thermal/mediatek/auxadc_thermal.c
> +++ b/drivers/thermal/mediatek/auxadc_thermal.c
> @@ -308,6 +308,13 @@ struct mtk_thermal_bank {
> int id;
> };
>
> +/* A single sensor, exposed as its own thermal zone (DT sensor id = sensor + 1) */
> +struct mtk_thermal_sensor {
> + struct mtk_thermal *mt;
> + int bank;
> + int index;
> +};
> +
> struct mtk_thermal_data {
> s32 num_banks;
> s32 num_sensors;
> @@ -870,6 +877,77 @@ static const struct thermal_zone_device_ops mtk_thermal_ops = {
> .get_temp = mtk_read_temp,
> };
>
> +static int mtk_read_sensor_temp(struct thermal_zone_device *tz, int *temperature)
> +{
> + struct mtk_thermal_sensor *sensor = thermal_zone_device_priv(tz);
> + struct mtk_thermal *mt = sensor->mt;
> + const struct mtk_thermal_data *conf = mt->conf;
> + struct mtk_thermal_bank *bank = &mt->banks[sensor->bank];
> + int temp;
> + u32 raw;
> +
> + mtk_thermal_get_bank(bank);
> + raw = readl(mt->thermal_base + conf->msr[sensor->index]);
> + temp = mt->raw_to_mcelsius(mt, conf->bank_data[sensor->bank].sensors[sensor->index],
> + raw);
> + mtk_thermal_put_bank(bank);
> +
> + if (!mtk_thermal_temp_is_valid(temp))
> + return -EAGAIN;
> +
> + *temperature = temp;
> +
> + return 0;
> +}
> +
> +static const struct thermal_zone_device_ops mtk_thermal_sensor_ops = {
> + .get_temp = mtk_read_sensor_temp,
> +};
> +
> +/*
> + * Zone 0 reports the hottest sensor. Also register every individual sensor
> + * the devicetree describes (sensor id = sensor number + 1): MT8183 SVS looks
> + * up its GPU bank temperature through the "gpu-thermal" zone and cannot
> + * probe without it. Sensors without a devicetree zone are skipped.
> + */
> +static int mtk_thermal_register_sensors(struct mtk_thermal *mt)
> +{
> + const struct mtk_thermal_data *conf = mt->conf;
> + struct thermal_zone_device *tzdev;
> + struct mtk_thermal_sensor *sensor;
> + int id, b, i;
> +
> + for (id = 1; id <= conf->num_sensors; id++) {
> + sensor = NULL;
> + for (b = 0; b < conf->num_banks && !sensor; b++) {
> + for (i = 0; i < conf->bank_data[b].num_sensors; i++) {
> + if (conf->bank_data[b].sensors[i] != id - 1)
> + continue;
> + sensor = devm_kzalloc(mt->dev, sizeof(*sensor), GFP_KERNEL);
> + if (!sensor)
> + return -ENOMEM;
> + sensor->mt = mt;
> + sensor->bank = b;
> + sensor->index = i;
> + break;
> + }
> + }
> + if (!sensor)
> + continue;
Please move routines into self-explanatory functions and make this
initialization function simpler to understand
> +
> + tzdev = devm_thermal_of_zone_register(mt->dev, id, sensor,
> + &mtk_thermal_sensor_ops);
> + if (IS_ERR(tzdev)) {
> + if (PTR_ERR(tzdev) == -ENODEV)
> + continue;
> + return dev_err_probe(mt->dev, PTR_ERR(tzdev),
> + "failed to register sensor %d\n", id);
> + }
> + }
> +
> + return 0;
> +}
> +
> static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num,
> u32 apmixed_phys_base, u32 auxadc_phys_base,
> int ctrl_id)
> @@ -1294,7 +1372,7 @@ static int mtk_thermal_probe(struct platform_device *pdev)
> if (ret)
> dev_warn(&pdev->dev, "error in thermal_add_hwmon_sysfs");
>
> - return 0;
> + return mtk_thermal_register_sensors(mt);
> }
>
> static struct platform_driver mtk_thermal_driver = {
More information about the Linux-mediatek
mailing list