mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexandre Mergnat <amergnat@baylibre.com>
To: Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>,
	 Matthias Brugger <matthias.bgg@gmail.com>,
	 AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	 Nicolas Frattaroli <nicolas.frattaroli@collabora.com>,
	 Ulf Hansson <ulfh@kernel.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	 Daniel Lezcano <daniel.lezcano@kernel.org>,
	Zhang Rui <rui.zhang@intel.com>,
	 Lukasz Luba <lukasz.luba@arm.com>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org,  linux-pm@vger.kernel.org,
	Alexandre Mergnat <amergnat@baylibre.com>
Subject: [PATCH 2/3] pmdomain: mediatek: mfg: Expose GPU temperature
Date: Mon, 30 Nov 2026 14:19:32 +0000	[thread overview]
Message-ID: <20261130-mtk-mfg-thermal-v1-2-e0617e26f902@baylibre.com> (raw)
In-Reply-To: <20261130-mtk-mfg-thermal-v1-0-e0617e26f902@baylibre.com>

The GPUEB reports the GPU temperature in the shared memory that
mtk-mfg maps, but mtk-mfg does not read it, so no thermal zone can
use it.

Create an auxiliary device for a thermal driver, and export to it
a function that returns the temperature reported by the GPUEB.

Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com>
---
 drivers/pmdomain/mediatek/Kconfig            |  1 +
 drivers/pmdomain/mediatek/mtk-mfg-pmdomain.c | 29 ++++++++++++++++++++++++++++
 include/linux/soc/mediatek/mtk-mfg.h         | 13 +++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/drivers/pmdomain/mediatek/Kconfig b/drivers/pmdomain/mediatek/Kconfig
index a2eb704a773c..b7c0fa40b9cf 100644
--- a/drivers/pmdomain/mediatek/Kconfig
+++ b/drivers/pmdomain/mediatek/Kconfig
@@ -32,6 +32,7 @@ config MTK_MFG_PM_DOMAIN
 	depends on PM
 	depends on OF
 	depends on COMMON_CLK
+	select AUXILIARY_BUS
 	select MAILBOX
 	select PM_GENERIC_DOMAINS
 	imply MTK_GPUEB_MBOX
diff --git a/drivers/pmdomain/mediatek/mtk-mfg-pmdomain.c b/drivers/pmdomain/mediatek/mtk-mfg-pmdomain.c
index 1417ffc22b3e..28f6d84a2774 100644
--- a/drivers/pmdomain/mediatek/mtk-mfg-pmdomain.c
+++ b/drivers/pmdomain/mediatek/mtk-mfg-pmdomain.c
@@ -5,6 +5,7 @@
  * Copyright (C) 2025, Collabora Ltd.
  */
 
+#include <linux/auxiliary_bus.h>
 #include <linux/completion.h>
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
@@ -22,6 +23,7 @@
 #include <linux/pm_domain.h>
 #include <linux/pm_opp.h>
 #include <linux/regulator/consumer.h>
+#include <linux/soc/mediatek/mtk-mfg.h>
 #include <linux/units.h>
 
 #define GPR_LP_STATE		0x0028
@@ -908,6 +910,28 @@ static int mtk_mfg_init_nvmem_provider(struct mtk_mfg *mfg)
 	return 0;
 }
 
+/**
+ * mtk_mfg_get_temp() - Get the GPU temperature reported by the GPUEB
+ * @adev: the auxiliary device created by mtk-mfg
+ * @temp: the temperature in millidegrees Celsius
+ *
+ * Return: 0 on success, -ENODATA while the GPU is off, as the GPUEB does not
+ * update the temperature then.
+ */
+int mtk_mfg_get_temp(struct auxiliary_device *adev, int *temp)
+{
+	struct mtk_mfg *mfg = dev_get_drvdata(adev->dev.parent);
+
+	if (READ_ONCE(mfg->pd.status) != GENPD_STATE_ON)
+		return -ENODATA;
+
+	*temp = (s32)readl(mfg->shared_mem + GF_REG_TEMP_RAW) *
+		MILLIDEGREE_PER_DEGREE;
+
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(mtk_mfg_get_temp, "MTK_MFG_PM_DOMAIN");
+
 static int mtk_mfg_probe(struct platform_device *pdev)
 {
 	struct mtk_mfg *mfg;
@@ -1024,6 +1048,11 @@ static int mtk_mfg_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_power_off;
 
+	if (!devm_auxiliary_device_create(dev, "thermal", NULL)) {
+		ret = -ENODEV;
+		goto err_power_off;
+	}
+
 	ret = of_genpd_add_provider_simple(dev->of_node, &mfg->pd);
 	if (ret) {
 		dev_err_probe(dev, ret, "Failed to add pmdomain provider\n");
diff --git a/include/linux/soc/mediatek/mtk-mfg.h b/include/linux/soc/mediatek/mtk-mfg.h
new file mode 100644
index 000000000000..8ca41b7faffd
--- /dev/null
+++ b/include/linux/soc/mediatek/mtk-mfg.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2026 BayLibre, SAS
+ */
+
+#ifndef __MTK_MFG_H
+#define __MTK_MFG_H
+
+struct auxiliary_device;
+
+int mtk_mfg_get_temp(struct auxiliary_device *adev, int *temp);
+
+#endif /* __MTK_MFG_H */

-- 
2.43.0


  parent reply	other threads:[~2026-11-30 14:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 14:19 [PATCH 0/3] Add the MT8196 GPU temperature sensor Alexandre Mergnat
2026-11-30 14:19 ` [PATCH 1/3] dt-bindings: power: mt8196-gpufreq: Add #thermal-sensor-cells Alexandre Mergnat
2026-11-30 14:19 ` Alexandre Mergnat [this message]
2026-11-30 14:19 ` [PATCH 3/3] thermal/drivers/mediatek: Add GPUEB thermal driver Alexandre Mergnat
2026-11-30 15:31   ` Uwe Kleine-König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130-mtk-mfg-thermal-v1-2-e0617e26f902@baylibre.com \
    --to=amergnat@baylibre.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=conor+dt@kernel.org \
    --cc=daniel.lezcano@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=matthias.bgg@gmail.com \
    --cc=nicolas.frattaroli@collabora.com \
    --cc=rafael@kernel.org \
    --cc=robh@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=ulfh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®