Skip to contentSkip to conversation

Properly describe mt6589 and mt8167 toprgu resets

PATCH NAK Luca Leonardo Scorcia 5 participants 20 messages Aug 19 – Sep 8

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v4 cover Properly describe mt6589 and mt8167 toprgu resets

Currently mt8167 inherits its watchdog from the included mt8516 dtsi, which in turn falls back on mt6589-wdt, which does not support toprgu resets yet. This series adds support for mt6589 toprgu resets with bit definitions obtained from Android stock sources.

However, according to its data sheet, mt8167 has 14 sw resets instead of 12, and the reset bits are non-contiguous. This is currently unsupported by the mtk-wtd driver, and it caused confusion between reset IDs and reset bits in device tree includes.

Therefore in the first three patches we improve the description of the, resets for mt6589 using the definitions obtained from Android sources.

Then we introduce a dedicated mediatek,mt8167-wdt compatible for the watchdog driver that describes correctly this SoC's resets. Also while we're touching the bindings reset includes, we add IDs for the MMSYS resets.

In the 5th patch we add support for a watchdog reset table to accommodate the distinction between device tree reset IDs and the actual bits in the registers. Code is inspired by the reset table currently implemented in the mmsys driver. There should be no effect on existing sequential wdt resets.

In the 6th patch, we define the mmsys reset table for the SoC. According to the datasheet, there are 28 mmsys reset bits divided across two adjacent registers.

In the last patch we actually enable the watchdog driver for mt8167 by adding a node for the mt8167 watchdog referring to the new compatible in the SoC dtsi.

The series has been tested on a Sony PlayStation Classic Mini and on a Lenovo Smart Clock 2.

Changes in v4:
- Squashed the reset IDs includes together with the bindings change;
- Added support for a reset table to the mtk-wdt driver. This allows us to decouple reset IDs from device trees from reset bits and lets us describe correctly the non-contiguous reset bits of mt8167;
- Improved explanations in commit messages.

Changes in v3 [3]:
- Improved explanations in the commit messages;
- Added the #reset-cells property to mt6589 watchdog node;
- Included the mediatek,mt6589-resets.h file in mt6589.dtsi;
- Included the mediatek,mt8167-resets.h file in mt8167.dtsi;
- Moved the mmsys reset table from the mt8167-mmsys.h header file to the mmsys driver implementation.

Changes in v2 [2]:
- Sashiko pointed out correctly a missing entry in the mmsys reset table in the last patch.

Initial version: [1]

[1] https://lore.kernel.org/linux-mediatek/[email protected]/
[2] https://lore.kernel.org/linux-mediatek/[email protected]/

Luca Leonardo Scorcia (7):
dt-bindings: reset: Add mt6589 toprgu reset IDs
watchdog: mediatek: Add wdt/toprgu resets for mt6589
arm: dts: mediatek: mt6589: Enable toprgu reset controller
dt-bindings: watchdog: Add compatible for MediaTek mt8167
watchdog: mediatek: Add support for mt8167 toprgu/watchdog
soc: mediatek: mtk-mmsys: Add resets for mt8167
arm64: dts: mt8167: Properly describe the SoC watchdog and mmsys
resets

 .../bindings/watchdog/mediatek,mtk-wdt.yaml   |  1 +
 arch/arm/boot/dts/mediatek/mt6589.dtsi        |  2 +
 arch/arm64/boot/dts/mediatek/mt8167.dtsi      | 10 ++++
 drivers/soc/mediatek/mt8167-mmsys.h           |  3 ++
 drivers/soc/mediatek/mtk-mmsys.c              | 38 +++++++++++++
 drivers/watchdog/mtk_wdt.c                    | 54 +++++++++++++++++--
 .../dt-bindings/reset/mediatek,mt6589-wdt.h   | 20 +++++++
 .../dt-bindings/reset/mediatek,mt8167-mmsys.h | 35 ++++++++++++
 .../dt-bindings/reset/mediatek,mt8167-wdt.h   | 21 ++++++++
 9 files changed, 179 insertions(+), 5 deletions(-)
 create mode 100644 include/dt-bindings/reset/mediatek,mt6589-wdt.h
 create mode 100644 include/dt-bindings/reset/mediatek,mt8167-mmsys.h
 create mode 100644 include/dt-bindings/reset/mediatek,mt8167-wdt.h
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 1/7 dt-bindings: reset: Add mt6589 toprgu reset IDs

Add IDs for the 12 mt6589 toprgu resets which can be used in device trees to identify subsystem resets. The binding for the associated reset controller mt6589-wdt is already upstream.

---
 .../dt-bindings/reset/mediatek,mt6589-wdt.h   | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 include/dt-bindings/reset/mediatek,mt6589-wdt.h
include/dt-bindings/reset/mediatek,mt6589-wdt.h new file +20 -0
new file mode 100644
index 000000000000..5e39c8cdd718
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
+#ifndef _DT_BINDINGS_RESET_MEDIATEK_MT6589_WDT_H_
+#define _DT_BINDINGS_RESET_MEDIATEK_MT6589_WDT_H_
+
+/* TOPRGU reset IDs */
+#define MT6589_TOPRGU_INFRA_SW_RST		0
+#define MT6589_TOPRGU_MM_SW_RST			1
+#define MT6589_TOPRGU_MFG_SW_RST		2
+#define MT6589_TOPRGU_VENC_SW_RST		3
+#define MT6589_TOPRGU_VDEC_SW_RST		4
+#define MT6589_TOPRGU_IMG_SW_RST		5
+#define MT6589_TOPRGU_DDRPHY_SW_RST		6
+#define MT6589_TOPRGU_MD_SW_RST			7
+#define MT6589_TOPRGU_INFRA_AO_SW_RST		8
+#define MT6589_TOPRGU_MD_LITE_SW_RST		9
+#define MT6589_TOPRGU_APMIXED_SW_RST		10
+#define MT6589_TOPRGU_PWRAP_SPI_CTL_RST		11
+#define MT6589_TOPRGU_SW_RST_NUM		12
+
+#endif  /* _DT_BINDINGS_RESET_MEDIATEK_MT6589_WDT_H_ */
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v4 1/7] dt-bindings: reset: Add mt6589 toprgu reset IDs

include/dt-bindings/reset/mediatek,mt6589-wdt.h line 18

Quoted 3 lines · Luca Leonardo Scorcia
include/dt-bindings/reset/mediatek,mt6589-wdt.h new file +2 -0
+#define MT6589_TOPRGU_PWRAP_SPI_CTL_RST		11
 
+#define MT6589_TOPRGU_SW_RST_NUM		12

Not really a binding, drop

Quoted 5 lines
(quoted diff) +2 -0
+
+#endif  /* _DT_BINDINGS_RESET_MEDIATEK_MT6589_WDT_H_ */
Signature · 1 line
2.43.0
#3 lore raw

PATCH v4 2/7 watchdog: mediatek: Add wdt/toprgu resets for mt6589

In reply to Luca Leonardo Scorcia

According to Android sources, mt6589 has 12 reset bits in the WDT_SWSYSRST register. Populate toprgu_sw_rst_num to allow toprgu resets in device trees of the many compatible devices.

---
 drivers/watchdog/mtk_wdt.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/watchdog/mtk_wdt.c +6 -1
index 91d110646e16..f8208fb0f723 100644
@@ -10,6 +10,7 @@
  */
 
 #include <dt-bindings/reset/mt2712-resets.h>
+#include <dt-bindings/reset/mediatek,mt6589-wdt.h>
 #include <dt-bindings/reset/mediatek,mt6735-wdt.h>
 #include <dt-bindings/reset/mediatek,mt6795-resets.h>
 #include <dt-bindings/reset/mt7986-resets.h>
@@ -88,6 +89,10 @@ static const struct mtk_wdt_data mt2712_data = {
 	.toprgu_sw_rst_num = MT2712_TOPRGU_SW_RST_NUM,
 };
 
+static const struct mtk_wdt_data mt6589_data = {
+	.toprgu_sw_rst_num = MT6589_TOPRGU_SW_RST_NUM,
+};
+
 static const struct mtk_wdt_data mt6735_data = {
 	.toprgu_sw_rst_num = MT6735_TOPRGU_RST_NUM,
 };
@@ -493,7 +498,7 @@ static int mtk_wdt_resume(struct device *dev)
 
 static const struct of_device_id mtk_wdt_dt_ids[] = {
 	{ .compatible = "mediatek,mt2712-wdt", .data = &mt2712_data },
-	{ .compatible = "mediatek,mt6589-wdt" },
+	{ .compatible = "mediatek,mt6589-wdt", .data = &mt6589_data },
 	{ .compatible = "mediatek,mt6735-wdt", .data = &mt6735_data },
 	{ .compatible = "mediatek,mt6795-wdt", .data = &mt6795_data },
 	{ .compatible = "mediatek,mt7986-wdt", .data = &mt7986_data },
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH v4 2/7] watchdog: mediatek: Add wdt/toprgu resets for mt6589

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Watchdog device is registered before its driver data is fully initialized, allowing userspace to trigger mtk_wdt_start() with uninitialized flags.
- [High] Reset controller is registered before has_swsysrst_en is initialized, causing a race condition where reset operations use incorrect configurations. --

--- Patch [2]: [PATCH v4 2/7] watchdog: mediatek: Add wdt/toprgu resets for mt6589 --- commit 62a8c76fbad14150f6f3dabaecc0a569e1dfdcb5
Author: Luca Leonardo Scorcia <[email protected]>

watchdog: mediatek: Add wdt/toprgu resets for mt6589

According to Android sources, mt6589 has 12 reset bits in the WDT_SWSYSRST register. Populate toprgu_sw_rst_num to allow toprgu resets in device trees of the many compatible devices.

Quoted 4 lines
drivers/watchdog/mtk_wdt.c +0 -0
index 91d110646e16f..f8208fb0f7234 100644

[ ... ]

drivers/watchdog/mtk_wdt.c static int mtk_wdt_resume(struct device *dev) · line 501

Quoted 6 lines
drivers/watchdog/mtk_wdt.c +1 -1
@@ -493,7 +498,7 @@ static int mtk_wdt_resume(struct device *dev)
 
 static const struct of_device_id mtk_wdt_dt_ids[] = {
 	{ .compatible = "mediatek,mt2712-wdt", .data = &mt2712_data },
-	{ .compatible = "mediatek,mt6589-wdt" },
+	{ .compatible = "mediatek,mt6589-wdt", .data = &mt6589_data },

[Severity: High]
This isn't a bug introduced by this patch, but I noticed a potential race condition during probe that might affect all watchdog devices here.

In mtk_wdt_probe(), the watchdog device is registered before its configuration flags are read:

        err = devm_watchdog_register_device(dev, &mtk_wdt->wdt_dev);
        if (unlikely(err))
                return err;
        
        ...

        mtk_wdt->disable_wdt_extrst =
                of_property_read_bool(dev->of_node, "mediatek,disable-extrst");

        mtk_wdt->reset_by_toprgu =
                of_property_read_bool(dev->of_node, "mediatek,reset-by-toprgu");

If userspace (like systemd) opens the device immediately after registration, could mtk_wdt_start() run before these flags are initialized?

Since these flags are written to the WDT_MODE register and not re-applied later, could this permanently misconfigure the watchdog for the system uptime and cause a hang instead of a reboot upon timeout?

[Severity: High]
This is also a pre-existing issue, but while reviewing the probe path that uses the newly assigned device data, I noticed a potential race condition with the reset controller.

In mtk_wdt_probe(), the reset controller is registered before the has_swsysrst_en flag is initialized:

        wdt_data = of_device_get_match_data(dev);
        if (wdt_data) {
                err = toprgu_register_reset_controller(pdev,
                                                       wdt_data->toprgu_sw_rst_num);
                if (err)
                        return err;

                mtk_wdt->has_swsysrst_en = wdt_data->has_swsysrst_en;
        }

If a consumer device requests and asserts a reset line immediately upon registration (e.g. from a concurrent deferred probe), could toprgu_reset_update() observe has_swsysrst_en as false before it is assigned?

If so, would it skip calling toprgu_reset_sw_en_unlocked() and fail to enable software control for the reset bit in WDT_SWSYSRST_EN, leading to a probe failure for the consumer device?

Quoted 3 lines
drivers/watchdog/mtk_wdt.c +0 -0
 	{ .compatible = "mediatek,mt6735-wdt", .data = &mt6735_data },
 	{ .compatible = "mediatek,mt6795-wdt", .data = &mt6795_data },
 	{ .compatible = "mediatek,mt7986-wdt", .data = &mt7986_data },
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

Re: [PATCH v4 2/7] watchdog: mediatek: Add wdt/toprgu resets for mt6589

In reply to Luca Leonardo Scorcia
Quoted 14 lines · Luca Leonardo Scorcia

According to Android sources, mt6589 has 12 reset bits in the WDT_SWSYSRST register. Populate toprgu_sw_rst_num to allow toprgu resets in device trees of the many compatible devices.

---
 drivers/watchdog/mtk_wdt.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/watchdog/mtk_wdt.c +0 -0
index 91d110646e16..f8208fb0f723 100644

drivers/watchdog/mtk_wdt.c line 13

Quoted 4 lines
drivers/watchdog/mtk_wdt.c +1 -0
@@ -10,6 +10,7 @@
  */
 
 #include <dt-bindings/reset/mt2712-resets.h>
+#include <dt-bindings/reset/mediatek,mt6589-wdt.h>

I do not see how you use the bindings here, so my previous comments stay. You just ignored it and never replied. In such case:

NAK

Best regards,
Krzysztof

#6 lore raw

Re: [PATCH v4 2/7] watchdog: mediatek: Add wdt/toprgu resets for mt6589

Quoted 10 lines
Quoted 10 lines
 drivers/watchdog/mtk_wdt.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/watchdog/mtk_wdt.c +0 -0
index 91d110646e16..f8208fb0f723 100644
@@ -10,6 +10,7 @@
  */
 
Quoted 7 lines

drivers/watchdog/mtk_wdt.c line 13

Quoted 2 lines
drivers/watchdog/mtk_wdt.c +1 -0
 #include <dt-bindings/reset/mt2712-resets.h>
+#include <dt-bindings/reset/mediatek,mt6589-wdt.h>

I do not see how you use the bindings here, so my previous comments stay. You just ignored it and never replied. In such case:

NAK

The mtk_wdt driver requires the total number of available resets to register the reset controller. This was defined as MT6589_TOPRGU_SW_RST_NUM in the binding header, therefore the need for including it.
In your review for patch v4 1/7 [1] you mentioned that that define should be dropped as it's not really a binding, so for the next revision I'll drop that define from the binding header and move it directly inside the driver. The include won't then be necessary.

Thank you for your help!

[1] https://lists.infradead.org/pipermail/linux-mediatek/2026-August/112272.html
--
Luca Leonardo Scorcia
[email protected]

#7 lore raw

Re: [PATCH v4 2/7] watchdog: mediatek: Add wdt/toprgu resets for mt6589

Quoted 16 lines · Luca Leonardo Scorcia
Quoted 16 lines

drivers/watchdog/mtk_wdt.c line 13

Quoted 12 lines
 drivers/watchdog/mtk_wdt.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/watchdog/mtk_wdt.c +1 -0
index 91d110646e16..f8208fb0f723 100644
@@ -10,6 +10,7 @@
  */
 
 #include <dt-bindings/reset/mt2712-resets.h>
+#include <dt-bindings/reset/mediatek,mt6589-wdt.h>

I do not see how you use the bindings here, so my previous comments stay. You just ignored it and never replied. In such case:

Quoted 6 lines
Quoted 1 line

NAK

The mtk_wdt driver requires the total number of available resets to register the reset controller. This was defined as MT6589_TOPRGU_SW_RST_NUM in the binding header, therefore the need for including it.

Number of signals almost never a binding. How do you even use it in DTS?

Best regards,
Krzysztof

#8 lore raw

PATCH v4 3/7 arm: dts: mediatek: mt6589: Enable toprgu reset controller

In reply to Luca Leonardo Scorcia

Enable the toprgu reset controller feature for the mt6589 SoC. This allows generating reset signals for the 12 subsystems managed by its top reset generation unit.

---
 arch/arm/boot/dts/mediatek/mt6589.dtsi | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/boot/dts/mediatek/mt6589.dtsi +2 -0
index 46dea445742b..2ba912a356af 100644
@@ -7,6 +7,7 @@
 
 #include <dt-bindings/interrupt-controller/irq.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <dt-bindings/reset/mediatek,mt6589-wdt.h>
 
 / {
 	#address-cells = <1>;
@@ -147,6 +148,7 @@ uart3: serial@11009000 {
 		wdt: watchdog@10000000 {
 			compatible = "mediatek,mt6589-wdt";
 			reg = <0x10000000 0x44>;
+			#reset-cells = <1>;
 		};
 	};
 };
Signature · 1 line
2.43.0
#9 lore raw

Re: [PATCH v4 3/7] arm: dts: mediatek: mt6589: Enable toprgu reset controller

Hi,

I noticed that my Signed-off-by is still present on this patch in v4.

Quoted 2 lines · Luca Leonardo Scorcia

Sorry for confusing you with the v3 patch discussion. As discussed in v3, my Signed-off-by should not be included in the sign-off chain.

Please drop my Signed-off-by from this patch.

arch/arm/boot/dts/mediatek/mt6589.dtsi line 10

Quoted 7 lines
arch/arm/boot/dts/mediatek/mt6589.dtsi +1 -0
@@ -7,6 +7,7 @@
 
 #include <dt-bindings/interrupt-controller/irq.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <dt-bindings/reset/mediatek,mt6589-wdt.h>

By the way, this header is not used by any part of mt6589.dtsi, so I think this line can simply be dropped.

Best regards,
Akari

#10 lore raw

Re: [PATCH v4 3/7] arm: dts: mediatek: mt6589: Enable toprgu reset controller

Quoted 1 line

Please drop my Signed-off-by from this patch.

Of course, I'll do that in the next iteration of the series.

Quoted 2 lines

By the way, this header is not used by any part of mt6589.dtsi, so I think this line can simply be dropped.

You are right, I will remove it.

Thank you!

Signature · 2 lines
Luca Leonardo Scorcia
[email protected]
#11 lore raw

PATCH v4 4/7 dt-bindings: watchdog: Add compatible for MediaTek mt8167

In reply to Luca Leonardo Scorcia

Currently mt8167 inherits its watchdog from the included mt8516 dtsi, which in turn falls back on mt6589-wdt. However according to the data sheet mt8167 toprgu is not actually compatible with mt6589: the latter has 12 contiguous toprgu reset bits while the former has 14 non-contiguous toprgu reset bits.

Update the mtk-wdt binding to add a dedicated compatible for mt8167 and add the IDs that can be used in device trees to identify toprgu and mmsys subsystem resets.

---
 .../bindings/watchdog/mediatek,mtk-wdt.yaml   |  1 +
 .../dt-bindings/reset/mediatek,mt8167-mmsys.h | 35 +++++++++++++++++++
 .../dt-bindings/reset/mediatek,mt8167-wdt.h   | 21 +++++++++++
 3 files changed, 57 insertions(+)
 create mode 100644 include/dt-bindings/reset/mediatek,mt8167-mmsys.h
 create mode 100644 include/dt-bindings/reset/mediatek,mt8167-wdt.h
Documentation/devicetree/bindings/watchdog/mediatek,mtk-wdt.yaml +1 -0
index 953629cb9558..f514be8a5851 100644
@@ -26,6 +26,7 @@ properties:
           - mediatek,mt6795-wdt
           - mediatek,mt7986-wdt
           - mediatek,mt7988-wdt
+          - mediatek,mt8167-wdt
           - mediatek,mt8183-wdt
           - mediatek,mt8186-wdt
           - mediatek,mt8188-wdt
include/dt-bindings/reset/mediatek,mt8167-mmsys.h new file +35 -0
new file mode 100644
index 000000000000..b21f67b3b55c
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
+#ifndef _DT_BINDINGS_RESET_MEDIATEK_MT8167_MMSYS_H_
+#define _DT_BINDINGS_RESET_MEDIATEK_MT8167_MMSYS_H_
+
+/* MMSYS reset IDs */
+#define MT8167_MMSYS_SW0_RST_B_SMI_COMMON	0
+#define MT8167_MMSYS_SW0_RST_B_SMI_LARB0	1
+#define MT8167_MMSYS_SW0_RST_B_CAM_MDP		2
+#define MT8167_MMSYS_SW0_RST_B_MDP_RDMA0	3
+#define MT8167_MMSYS_SW0_RST_B_MDP_RSZ0		4
+#define MT8167_MMSYS_SW0_RST_B_MDP_RSZ1		5
+#define MT8167_MMSYS_SW0_RST_B_MDP_TDSHP0	6
+#define MT8167_MMSYS_SW0_RST_B_MDP_WDMA		7
+#define MT8167_MMSYS_SW0_RST_B_MDP_WROT0	8
+#define MT8167_MMSYS_SW0_RST_B_FAKE_ENG		9
+#define MT8167_MMSYS_SW0_RST_B_MUTEX		10
+#define MT8167_MMSYS_SW0_RST_B_DISP_OVL0	11
+#define MT8167_MMSYS_SW0_RST_B_DISP_RDMA0	12
+#define MT8167_MMSYS_SW0_RST_B_DISP_RDMA1	13
+#define MT8167_MMSYS_SW0_RST_B_DISP_WDMA0	14
+#define MT8167_MMSYS_SW0_RST_B_DISP_COLOR	15
+#define MT8167_MMSYS_SW0_RST_B_DISP_CCORR	16
+#define MT8167_MMSYS_SW0_RST_B_DISP_AAL		17
+#define MT8167_MMSYS_SW0_RST_B_DISP_GAMMA	18
+#define MT8167_MMSYS_SW0_RST_B_DISP_DITHER	19
+#define MT8167_MMSYS_SW0_RST_B_DISP_UFOE	20
+#define MT8167_MMSYS_SW0_RST_B_DISP_PWM		21
+#define MT8167_MMSYS_SW0_RST_B_DSI0		22
+#define MT8167_MMSYS_SW0_RST_B_DPI0		23
+#define MT8167_MMSYS_SW0_RST_B_MIPI_TX_CONFIG	24
+#define MT8167_MMSYS_SW1_RST_B_LVDS_ENCODER	25
+#define MT8167_MMSYS_SW1_RST_B_DPI1		26
+#define MT8167_MMSYS_SW1_RST_B_HDMI		27
+
+#endif  /* _DT_BINDINGS_RESET_MEDIATEK_MT8167_MMSYS_H_ */
include/dt-bindings/reset/mediatek,mt8167-wdt.h new file +21 -0
new file mode 100644
index 000000000000..1a24bfe079ca
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
+#ifndef _DT_BINDINGS_RESET_MEDIATEK_MT8167_WDT_H_
+#define _DT_BINDINGS_RESET_MEDIATEK_MT8167_WDT_H_
+
+/* TOPRGU reset IDs */
+#define MT8167_TOPRGU_DDRPHY_FLASH_RST		0
+#define MT8167_TOPRGU_AUD_PAD_RST		1
+#define MT8167_TOPRGU_MM_RST			2
+#define MT8167_TOPRGU_MFG_RST			3
+#define MT8167_TOPRGU_MDSYS_RST			4
+#define MT8167_TOPRGU_CONN_RST			5
+#define MT8167_TOPRGU_PAD2CAM_DIG_MIPI_RX_RST	6
+#define MT8167_TOPRGU_DIG_MIPI_TX_RST		7
+#define MT8167_TOPRGU_SPI_PAD_MACRO_RST		8
+#define MT8167_TOPRGU_APMIXED_RST		9
+#define MT8167_TOPRGU_VDEC_RST			10
+#define MT8167_TOPRGU_CONN_MCU_RST		11
+#define MT8167_TOPRGU_EFUSE_RST			12
+#define MT8167_TOPRGU_PWRAP_SPICTL_RST		13
+
+#endif  /* _DT_BINDINGS_RESET_MEDIATEK_MT8167_WDT_H_ */
Signature · 1 line
2.43.0
#12 lore raw

Re: [PATCH v4 4/7] dt-bindings: watchdog: Add compatible for MediaTek mt8167

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] Missing `#reset-cells` required property constraint for the `mediatek,mt8167-wdt` reset provider…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Missing #reset-cells required property constraint for the mediatek,mt8167-wdt reset provider capability.
- [Medium] Missing #reset-cells required property constraint for the mediatek,mt8167-mmsys reset provider capability. --

--- Patch [4]: [PATCH v4 4/7] dt-bindings: watchdog: Add compatible for MediaTek mt8167 --- commit cda604d8e57545578970aa161f863c629cec7278
Author: Luca Leonardo Scorcia <[email protected]>

dt-bindings: watchdog: Add compatible for MediaTek mt8167

This commit adds a dedicated compatible string for the MediaTek mt8167 watchdog. It also introduces two new header files defining reset IDs for the toprgu (watchdog) and mmsys subsystems.

Documentation/devicetree/bindings/watchdog/mediatek,mtk-wdt.yaml properties: · line 29

Quoted 9 lines
Documentation/devicetree/bindings/watchdog/mediatek,mtk-wdt.yaml +1 -0
index 953629cb9558b..f514be8a5851d 100644
@@ -26,6 +26,7 @@ properties:
           - mediatek,mt6795-wdt
           - mediatek,mt7986-wdt
           - mediatek,mt7988-wdt
+          - mediatek,mt8167-wdt

[Severity: Medium]
Since this compatible string is being added as a reset provider (indicated by the new mediatek,mt8167-wdt.h header), should #reset-cells be added as a required property constraint for mediatek,mt8167-wdt?

Without this constraint, device tree nodes using the mediatek,mt8167-wdt compatible string could silently pass validation even if they omit #reset-cells. This would allow incomplete configurations to escape schema verification, leading to downstream driver or probe failures when another node attempts to reference it as a reset provider.

[ ... ]

include/dt-bindings/reset/mediatek,mt8167-mmsys.h line 2

Quoted 8 lines
include/dt-bindings/reset/mediatek,mt8167-mmsys.h new file +2 -0
new file mode 100644
index 0000000000000..b21f67b3b55c7
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
+#ifndef _DT_BINDINGS_RESET_MEDIATEK_MT8167_MMSYS_H_

[Severity: Medium]
This new header introduces reset IDs for the mt8167-mmsys hardware, formally making it a reset provider.

Does the Documentation/devicetree/bindings/arm/mediatek/mediatek,mmsys.yaml schema also need to be updated in this patch to require the #reset-cells property for the mediatek,mt8167-mmsys hardware?

If the schema is not updated, a device tree author could attempt to use an mt8167 mmsys node as a reset provider but forget to specify #reset-cells, which would pass schema validation but fail to provide resets at runtime.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
maintainer Reviewed-by on v4 4/7
#13 lore raw

Re: [PATCH v4 4/7] dt-bindings: watchdog: Add compatible for MediaTek mt8167

In reply to Luca Leonardo Scorcia

include/dt-bindings/reset/mediatek,mt8167-mmsys.h

Quoted 36 lines · Luca Leonardo Scorcia

Currently mt8167 inherits its watchdog from the included mt8516 dtsi, which in turn falls back on mt6589-wdt. However according to the data sheet mt8167 toprgu is not actually compatible with mt6589: the latter has 12 contiguous toprgu reset bits while the former has 14 non-contiguous toprgu reset bits.

Update the mtk-wdt binding to add a dedicated compatible for mt8167 and add the IDs that can be used in device trees to identify toprgu and mmsys subsystem resets.

---
  .../bindings/watchdog/mediatek,mtk-wdt.yaml   |  1 +
  .../dt-bindings/reset/mediatek,mt8167-mmsys.h | 35 +++++++++++++++++++
  .../dt-bindings/reset/mediatek,mt8167-wdt.h   | 21 +++++++++++
  3 files changed, 57 insertions(+)

create mode 100644 include/dt-bindings/reset/mediatek,mt8167-mmsys.h create mode 100644 include/dt-bindings/reset/mediatek,mt8167-wdt.h

Documentation/devicetree/bindings/watchdog/mediatek,mtk-wdt.yaml +1 -0
index 953629cb9558..f514be8a5851 100644
@@ -26,6 +26,7 @@ properties:
            - mediatek,mt6795-wdt
            - mediatek,mt7986-wdt
            - mediatek,mt7988-wdt
+          - mediatek,mt8167-wdt
            - mediatek,mt8183-wdt
            - mediatek,mt8186-wdt
            - mediatek,mt8188-wdt
include/dt-bindings/reset/mediatek,mt8167-mmsys.h new file +0 -0
new file mode 100644
index 000000000000..b21f67b3b55c

The MMSYS resets don't belong to this commit: please split, after which:

Quoted 63 lines
include/dt-bindings/reset/mediatek,mt8167-mmsys.h new file +35 -0
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
+#ifndef _DT_BINDINGS_RESET_MEDIATEK_MT8167_MMSYS_H_
+#define _DT_BINDINGS_RESET_MEDIATEK_MT8167_MMSYS_H_
+
+/* MMSYS reset IDs */
+#define MT8167_MMSYS_SW0_RST_B_SMI_COMMON	0
+#define MT8167_MMSYS_SW0_RST_B_SMI_LARB0	1
+#define MT8167_MMSYS_SW0_RST_B_CAM_MDP		2
+#define MT8167_MMSYS_SW0_RST_B_MDP_RDMA0	3
+#define MT8167_MMSYS_SW0_RST_B_MDP_RSZ0		4
+#define MT8167_MMSYS_SW0_RST_B_MDP_RSZ1		5
+#define MT8167_MMSYS_SW0_RST_B_MDP_TDSHP0	6
+#define MT8167_MMSYS_SW0_RST_B_MDP_WDMA		7
+#define MT8167_MMSYS_SW0_RST_B_MDP_WROT0	8
+#define MT8167_MMSYS_SW0_RST_B_FAKE_ENG		9
+#define MT8167_MMSYS_SW0_RST_B_MUTEX		10
+#define MT8167_MMSYS_SW0_RST_B_DISP_OVL0	11
+#define MT8167_MMSYS_SW0_RST_B_DISP_RDMA0	12
+#define MT8167_MMSYS_SW0_RST_B_DISP_RDMA1	13
+#define MT8167_MMSYS_SW0_RST_B_DISP_WDMA0	14
+#define MT8167_MMSYS_SW0_RST_B_DISP_COLOR	15
+#define MT8167_MMSYS_SW0_RST_B_DISP_CCORR	16
+#define MT8167_MMSYS_SW0_RST_B_DISP_AAL		17
+#define MT8167_MMSYS_SW0_RST_B_DISP_GAMMA	18
+#define MT8167_MMSYS_SW0_RST_B_DISP_DITHER	19
+#define MT8167_MMSYS_SW0_RST_B_DISP_UFOE	20
+#define MT8167_MMSYS_SW0_RST_B_DISP_PWM		21
+#define MT8167_MMSYS_SW0_RST_B_DSI0		22
+#define MT8167_MMSYS_SW0_RST_B_DPI0		23
+#define MT8167_MMSYS_SW0_RST_B_MIPI_TX_CONFIG	24
+#define MT8167_MMSYS_SW1_RST_B_LVDS_ENCODER	25
+#define MT8167_MMSYS_SW1_RST_B_DPI1		26
+#define MT8167_MMSYS_SW1_RST_B_HDMI		27
+
+#endif  /* _DT_BINDINGS_RESET_MEDIATEK_MT8167_MMSYS_H_ */
include/dt-bindings/reset/mediatek,mt8167-wdt.h new file +21 -0
new file mode 100644
index 000000000000..1a24bfe079ca
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
+#ifndef _DT_BINDINGS_RESET_MEDIATEK_MT8167_WDT_H_
+#define _DT_BINDINGS_RESET_MEDIATEK_MT8167_WDT_H_
+
+/* TOPRGU reset IDs */
+#define MT8167_TOPRGU_DDRPHY_FLASH_RST		0
+#define MT8167_TOPRGU_AUD_PAD_RST		1
+#define MT8167_TOPRGU_MM_RST			2
+#define MT8167_TOPRGU_MFG_RST			3
+#define MT8167_TOPRGU_MDSYS_RST			4
+#define MT8167_TOPRGU_CONN_RST			5
+#define MT8167_TOPRGU_PAD2CAM_DIG_MIPI_RX_RST	6
+#define MT8167_TOPRGU_DIG_MIPI_TX_RST		7
+#define MT8167_TOPRGU_SPI_PAD_MACRO_RST		8
+#define MT8167_TOPRGU_APMIXED_RST		9
+#define MT8167_TOPRGU_VDEC_RST			10
+#define MT8167_TOPRGU_CONN_MCU_RST		11
+#define MT8167_TOPRGU_EFUSE_RST			12
+#define MT8167_TOPRGU_PWRAP_SPICTL_RST		13
+
+#endif  /* _DT_BINDINGS_RESET_MEDIATEK_MT8167_WDT_H_ */
#14 lore raw

PATCH v4 5/7 watchdog: mediatek: Add support for mt8167 toprgu/watchdog

In reply to Luca Leonardo Scorcia

Add support for the Top Reset Generation Unit/Watchdog Timer found on mt8167.

Since according to its data sheet mt8167 toprgu reset bits are not contiguous, add support for a reset table to the driver. This lets us define reset identifiers as contiguous indexes in the binding headers.

Also address a preexisting Sashiko finding that noticed that the has_swsysrst_en configuration was set after the reset controller registration.

---
 drivers/watchdog/mtk_wdt.c | 47 ++++++++++++++++++++++++++++++++++----
 1 file changed, 43 insertions(+), 4 deletions(-)
drivers/watchdog/mtk_wdt.c +43 -4
index f8208fb0f723..fa522fd80dd4 100644
@@ -13,6 +13,7 @@
 #include <dt-bindings/reset/mediatek,mt6589-wdt.h>
 #include <dt-bindings/reset/mediatek,mt6735-wdt.h>
 #include <dt-bindings/reset/mediatek,mt6795-resets.h>
+#include <dt-bindings/reset/mediatek,mt8167-wdt.h>
 #include <dt-bindings/reset/mt7986-resets.h>
 #include <dt-bindings/reset/mt8183-resets.h>
 #include <dt-bindings/reset/mt8186-resets.h>
@@ -78,11 +79,14 @@ struct mtk_wdt_dev {
 	bool disable_wdt_extrst;
 	bool reset_by_toprgu;
 	bool has_swsysrst_en;
+	const u8 *toprgu_sw_rst_tb;
+	int toprgu_sw_rst_num;
 };
 
 struct mtk_wdt_data {
-	int toprgu_sw_rst_num;
-	bool has_swsysrst_en;
+	const u8 *toprgu_sw_rst_tb;
+	const int toprgu_sw_rst_num;
+	const bool has_swsysrst_en;
 };
 
 static const struct mtk_wdt_data mt2712_data = {
@@ -130,6 +134,29 @@ static const struct mtk_wdt_data mt8195_data = {
 	.toprgu_sw_rst_num = MT8195_TOPRGU_SW_RST_NUM,
 };
 
+static const u8 mt8167_toprgu_sw_rst_tb[] = {
+	[MT8167_TOPRGU_DDRPHY_FLASH_RST]	= 0,
+	[MT8167_TOPRGU_AUD_PAD_RST]		= 1,
+	[MT8167_TOPRGU_MM_RST]			= 2,
+	[MT8167_TOPRGU_MFG_RST]			= 3,
+	[MT8167_TOPRGU_MDSYS_RST]		= 4,
+	[MT8167_TOPRGU_CONN_RST]		= 5,
+	[MT8167_TOPRGU_PAD2CAM_DIG_MIPI_RX_RST]	= 6,
+	[MT8167_TOPRGU_DIG_MIPI_TX_RST]		= 7,
+	[MT8167_TOPRGU_SPI_PAD_MACRO_RST]	= 8,
+	/* The data sheet describes bit 9 as "reserved, unused" */
+	[MT8167_TOPRGU_APMIXED_RST]		= 10,
+	[MT8167_TOPRGU_VDEC_RST]		= 11,
+	[MT8167_TOPRGU_CONN_MCU_RST]		= 12,
+	[MT8167_TOPRGU_EFUSE_RST]		= 13,
+	[MT8167_TOPRGU_PWRAP_SPICTL_RST]	= 14
+};
+
+static const struct mtk_wdt_data mt8167_data = {
+	.toprgu_sw_rst_tb = mt8167_toprgu_sw_rst_tb,
+	.toprgu_sw_rst_num = ARRAY_SIZE(mt8167_toprgu_sw_rst_tb),
+};
+
 /**
  * toprgu_reset_sw_en_unlocked() - enable/disable software control for reset bit
  * @data: Pointer to instance of driver data.
@@ -160,6 +187,15 @@ static int toprgu_reset_update(struct reset_controller_dev *rcdev,
 	struct mtk_wdt_dev *data =
 		 container_of(rcdev, struct mtk_wdt_dev, rcdev);
 
+	if (data->toprgu_sw_rst_tb) {
+		if (id >= data->toprgu_sw_rst_num) {
+			dev_err(rcdev->dev, "Invalid reset ID: %lu (>=%u)\n",
+				id, data->toprgu_sw_rst_num);
+			return -EINVAL;
+		}
+		id = data->toprgu_sw_rst_tb[id];
+	}
+
 	spin_lock_irqsave(&data->lock, flags);
 
 	if (assert && data->has_swsysrst_en)
@@ -457,12 +493,14 @@ static int mtk_wdt_probe(struct platform_device *pdev)
 
 	wdt_data = of_device_get_match_data(dev);
 	if (wdt_data) {
+		mtk_wdt->toprgu_sw_rst_num = wdt_data->toprgu_sw_rst_num;
+		mtk_wdt->toprgu_sw_rst_tb = wdt_data->toprgu_sw_rst_tb;
+		mtk_wdt->has_swsysrst_en = wdt_data->has_swsysrst_en;
+
 		err = toprgu_register_reset_controller(pdev,
 						       wdt_data->toprgu_sw_rst_num);
 		if (err)
 			return err;
-
-		mtk_wdt->has_swsysrst_en = wdt_data->has_swsysrst_en;
 	}
 
 	mtk_wdt->disable_wdt_extrst =
@@ -503,6 +541,7 @@ static const struct of_device_id mtk_wdt_dt_ids[] = {
 	{ .compatible = "mediatek,mt6795-wdt", .data = &mt6795_data },
 	{ .compatible = "mediatek,mt7986-wdt", .data = &mt7986_data },
 	{ .compatible = "mediatek,mt7988-wdt", .data = &mt7988_data },
+	{ .compatible = "mediatek,mt8167-wdt", .data = &mt8167_data },
 	{ .compatible = "mediatek,mt8183-wdt", .data = &mt8183_data },
 	{ .compatible = "mediatek,mt8186-wdt", .data = &mt8186_data },
 	{ .compatible = "mediatek,mt8188-wdt", .data = &mt8188_data },
Signature · 1 line
2.43.0
#15 lore raw

Re: [PATCH v4 5/7] watchdog: mediatek: Add support for mt8167 toprgu/watchdog

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Race condition in watchdog registration exposing uninitialized device properties. --

--- Patch [5]: [PATCH v4 5/7] watchdog: mediatek: Add support for mt8167 toprgu/watchdog --- commit 918b68ccd6f0fbc5fe13cfd642a3baccbeddc0ed
Author: Luca Leonardo Scorcia <[email protected]>

watchdog: mediatek: Add support for mt8167 toprgu/watchdog

This commit adds support for the Top Reset Generation Unit/Watchdog Timer found on the mt8167 SoC. It uses a reset table to handle non-contiguous reset bits and ensures the reset controller is registered with the correct configuration.

Quoted 4 lines
drivers/watchdog/mtk_wdt.c +0 -0
index f8208fb0f7234..fa522fd80dd45 100644

[ ... ]

Quoted 4 lines
drivers/watchdog/mtk_wdt.c +0 -0
@@ -457,12 +493,14 @@ static int mtk_wdt_probe(struct platform_device *pdev)
 
 	wdt_data = of_device_get_match_data(dev);
 	if (wdt_data) {

[ ... ]

drivers/watchdog/mtk_wdt.c static int mtk_wdt_probe(struct platform_device *pdev) · line 506

Quoted 9 lines
drivers/watchdog/mtk_wdt.c +0 -2
 		err = toprgu_register_reset_controller(pdev,
 						       wdt_data->toprgu_sw_rst_num);
 		if (err)
 			return err;
-
-		mtk_wdt->has_swsysrst_en = wdt_data->has_swsysrst_en;
 	}
 
 	mtk_wdt->disable_wdt_extrst =

[Severity: High]
This is a pre-existing issue, but does the ordering in mtk_wdt_probe() create a race condition with userspace?

Looking at the probe function, devm_watchdog_register_device() is called and exposes the device to userspace before the hardware-specific properties disable_wdt_extrst and reset_by_toprgu are populated.

If udev or another userspace process opens the watchdog device immediately upon registration, could mtk_wdt_start() execute before these properties are initialized?

If so, mtk_wdt_start() would evaluate the properties as false:

mtk_wdt_start() {
        ...
        if (mtk_wdt->disable_wdt_extrst)
                reg &= ~WDT_MODE_EXRST_EN;
        if (mtk_wdt->reset_by_toprgu)
                reg |= WDT_MODE_CNT_SEL;
        ...
}

Could this lead to incorrectly asserting external reset signals or failing to trigger the proper TOPRGU reset path? Should the watchdog registration be deferred until all device tree properties are fully parsed?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#16 lore raw

PATCH v4 6/7 soc: mediatek: mtk-mmsys: Add resets for mt8167

In reply to Luca Leonardo Scorcia

The mt8167 SoC has 28 mmsys resets, split across two contiguous 32-bits registers, MMSYS_SW0_RST_B (0x140) and MMSYS_SW1_RST_B (0x144).

---
 drivers/soc/mediatek/mt8167-mmsys.h |  3 +++
 drivers/soc/mediatek/mtk-mmsys.c    | 38 +++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
drivers/soc/mediatek/mt8167-mmsys.h +3 -0
index 001379373507..5c7cded5cfa4 100644
@@ -3,6 +3,9 @@
 #ifndef __SOC_MEDIATEK_MT8167_MMSYS_H
 #define __SOC_MEDIATEK_MT8167_MMSYS_H
 
+#define MT8167_MMSYS_SW0_RST_B				0x140
+#define MT8167_MMSYS_SW1_RST_B				0x144
+
 #define MT8167_DISP_REG_CONFIG_DISP_OVL0_MOUT_EN	0x030
 #define MT8167_DISP_REG_CONFIG_DISP_DITHER_MOUT_EN	0x038
 #define MT8167_DISP_REG_CONFIG_DISP_COLOR0_SEL_IN	0x058
drivers/soc/mediatek/mtk-mmsys.c +38 -0
index 2f3e0778bb17..015dc5b86478 100644
@@ -4,6 +4,7 @@
  * Author: James Liao <[email protected]>
  */
 
+#include <dt-bindings/reset/mediatek,mt8167-mmsys.h>
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/io.h>
@@ -53,10 +54,47 @@ static const struct mtk_mmsys_driver_data mt6797_mmsys_driver_data = {
 	.clk_driver = "clk-mt6797-mm",
 };
 
+static const u8 mmsys_mt8167_rst_tb[] = {
+	[MT8167_MMSYS_SW0_RST_B_SMI_COMMON]	= MMSYS_RST_NR(0, 0),
+	[MT8167_MMSYS_SW0_RST_B_SMI_LARB0]	= MMSYS_RST_NR(0, 1),
+	[MT8167_MMSYS_SW0_RST_B_CAM_MDP]	= MMSYS_RST_NR(0, 2),
+	[MT8167_MMSYS_SW0_RST_B_MDP_RDMA0]	= MMSYS_RST_NR(0, 3),
+	[MT8167_MMSYS_SW0_RST_B_MDP_RSZ0]	= MMSYS_RST_NR(0, 4),
+	[MT8167_MMSYS_SW0_RST_B_MDP_RSZ1]	= MMSYS_RST_NR(0, 5),
+	[MT8167_MMSYS_SW0_RST_B_MDP_TDSHP0]	= MMSYS_RST_NR(0, 6),
+	[MT8167_MMSYS_SW0_RST_B_MDP_WDMA]	= MMSYS_RST_NR(0, 7),
+	[MT8167_MMSYS_SW0_RST_B_MDP_WROT0]	= MMSYS_RST_NR(0, 8),
+	[MT8167_MMSYS_SW0_RST_B_FAKE_ENG]	= MMSYS_RST_NR(0, 9),
+	[MT8167_MMSYS_SW0_RST_B_MUTEX]		= MMSYS_RST_NR(0, 10),
+	[MT8167_MMSYS_SW0_RST_B_DISP_OVL0]	= MMSYS_RST_NR(0, 11),
+	[MT8167_MMSYS_SW0_RST_B_DISP_RDMA0]	= MMSYS_RST_NR(0, 12),
+	[MT8167_MMSYS_SW0_RST_B_DISP_RDMA1]	= MMSYS_RST_NR(0, 13),
+	[MT8167_MMSYS_SW0_RST_B_DISP_WDMA0]	= MMSYS_RST_NR(0, 14),
+	[MT8167_MMSYS_SW0_RST_B_DISP_COLOR]	= MMSYS_RST_NR(0, 15),
+	[MT8167_MMSYS_SW0_RST_B_DISP_CCORR]	= MMSYS_RST_NR(0, 16),
+	[MT8167_MMSYS_SW0_RST_B_DISP_AAL]	= MMSYS_RST_NR(0, 17),
+	[MT8167_MMSYS_SW0_RST_B_DISP_GAMMA]	= MMSYS_RST_NR(0, 18),
+	[MT8167_MMSYS_SW0_RST_B_DISP_DITHER]	= MMSYS_RST_NR(0, 19),
+	[MT8167_MMSYS_SW0_RST_B_DISP_UFOE]	= MMSYS_RST_NR(0, 20),
+	[MT8167_MMSYS_SW0_RST_B_DISP_PWM]	= MMSYS_RST_NR(0, 21),
+	[MT8167_MMSYS_SW0_RST_B_DSI0]		= MMSYS_RST_NR(0, 22),
+	[MT8167_MMSYS_SW0_RST_B_DPI0]		= MMSYS_RST_NR(0, 23),
+	/* bit 24 is SMI_COMMON again according to data sheet */
+	/* bit 25 is SMI_LARB0 again according to data sheet */
+	[MT8167_MMSYS_SW0_RST_B_MIPI_TX_CONFIG]	= MMSYS_RST_NR(0, 26),
+	/* all other bits are not described in data sheet */
+	[MT8167_MMSYS_SW1_RST_B_LVDS_ENCODER]	= MMSYS_RST_NR(1, 2),
+	[MT8167_MMSYS_SW1_RST_B_DPI1]		= MMSYS_RST_NR(1, 3),
+	[MT8167_MMSYS_SW1_RST_B_HDMI]		= MMSYS_RST_NR(1, 4),
+};
+
 static const struct mtk_mmsys_driver_data mt8167_mmsys_driver_data = {
 	.clk_driver = "clk-mt8167-mm",
 	.routes = mt8167_mmsys_routing_table,
 	.num_routes = ARRAY_SIZE(mt8167_mmsys_routing_table),
+	.sw0_rst_offset = MT8167_MMSYS_SW0_RST_B,
+	.rst_tb = mmsys_mt8167_rst_tb,
+	.num_resets = ARRAY_SIZE(mmsys_mt8167_rst_tb),
 };
 
 static const struct mtk_mmsys_driver_data mt8173_mmsys_driver_data = {
Signature · 1 line
2.43.0
#17 lore raw

PATCH v4 7/7 arm64: dts: mt8167: Properly describe the SoC watchdog and mmsys resets

In reply to Luca Leonardo Scorcia

Currently mt8167 inherits its watchdog from the included mt8516 dtsi, which in turn falls back on mt6589-wdt. However according to the data sheet mt8167 toprgu is not really compatible with mt6589 (it has 14 sw resets instead of 12, and the reset IDs are different from mt6589).

Use the dedicated mediatek,mt8167-wdt compatible for the watchdog driver, as it correctly describes the SoC resets.

Also add support for mmsys resets by declaring the reset-cells property.

---
 arch/arm64/boot/dts/mediatek/mt8167.dtsi | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/arm64/boot/dts/mediatek/mt8167.dtsi +10 -0
index 27cf32d7ae35..cccc487086a1 100644
@@ -8,6 +8,8 @@
 #include <dt-bindings/clock/mt8167-clk.h>
 #include <dt-bindings/memory/mt8167-larb-port.h>
 #include <dt-bindings/power/mt8167-power.h>
+#include <dt-bindings/reset/mediatek,mt8167-mmsys.h>
+#include <dt-bindings/reset/mediatek,mt8167-wdt.h>
 
 #include "mt8167-pinfunc.h"
 
@@ -95,6 +97,13 @@ power-domain@MT8167_POWER_DOMAIN_CONN {
 			};
 		};
 
+		watchdog: watchdog@10007000 {
+			compatible = "mediatek,mt8167-wdt";
+			reg = <0 0x10007000 0 0x1000>;
+			interrupts = <GIC_SPI 198 IRQ_TYPE_LEVEL_LOW>;
+			#reset-cells = <1>;
+		};
+
 		pio: pinctrl@1000b000 {
 			compatible = "mediatek,mt8167-pinctrl";
 			reg = <0 0x1000b000 0 0x1000>;
@@ -124,6 +133,7 @@ mmsys: syscon@14000000 {
 			compatible = "mediatek,mt8167-mmsys", "syscon";
 			reg = <0 0x14000000 0 0x1000>;
 			#clock-cells = <1>;
+			#reset-cells = <1>;
 		};
 
 		larb0: larb@14016000 {
Signature · 1 line
2.43.0
Acked-by Conor Dooley Acked-by Guenter Roeck on the v4 series
#18 lore raw
In reply to Luca Leonardo Scorcia

Hi Luca,

Quoted 10 lines · Luca Leonardo Scorcia

Currently mt8167 inherits its watchdog from the included mt8516 dtsi, which in turn falls back on mt6589-wdt, which does not support toprgu resets yet. This series adds support for mt6589 toprgu resets with bit definitions obtained from Android stock sources.

However, according to its data sheet, mt8167 has 14 sw resets instead of 12, and the reset bits are non-contiguous. This is currently unsupported by the mtk-wtd driver, and it caused confusion between reset IDs and reset bits in device tree includes.

Quoted 7 lines

Therefore in the first three patches we improve the description of the, resets for mt6589 using the definitions obtained from Android sources.

Then we introduce a dedicated mediatek,mt8167-wdt compatible for the watchdog driver that describes correctly this SoC's resets. Also while we're touching the bindings reset includes, we add IDs for the MMSYS resets.

This is somewhat outside the scope of this series, but adding TOPRGU reset support for MT6589 exposes a pre-existing problem with the mtk-wdt binding that I think should not go unnoticed.

Until now, using mediatek,mt6589-wdt as a fallback compatible for other SoCs was mostly harmless, since the driver did not expose the TOPRGU reset controller.
This series changes that by adding reset controller support for MT6589.

According to the MT6589 datasheet, its TOPRGU reset bits are:

0 infra
1 disp (same as mmsys in upstream)
2 mfg
3 venc
4 vdec
5 img
6 ddrphy
7 md
8 infra_ao
9 md_lite
10 apmixed
11 pwrap_spictl

These are the reset bits that mediatek,mt6589-wdt will provide once this series is merged.
Therefore, for another SoC to use this compatible as a fallback, its TOPRGU reset layout needs to be compatible with the above.

At commit bd5f485f3f02, mediatek,mtk-wdt.yaml contains:

- items:
- enum:
- mediatek,mt2701-wdt
- mediatek,mt6572-wdt
- mediatek,mt6582-wdt
- mediatek,mt6797-wdt
- mediatek,mt7622-wdt
- mediatek,mt7623-wdt
- mediatek,mt7629-wdt
- mediatek,mt8173-wdt
- mediatek,mt8188-wdt
- mediatek,mt8189-wdt
- mediatek,mt8365-wdt
- mediatek,mt8516-wdt
- const: mediatek,mt6589-wdt

Let's examine the evidence for each of these SoCs.

## MT2701

I could not find enough public information to determine the reset layout.

## MT6572

A downstream kernel suggests it has the same reset layout as MT6589:
https://github.com/orangepi-xunlong/OrangePi3G-iot_external/blob/b8a66e9bde91d75a8535dc6342d668efb6ab14ee/mediatek/platform/mt6572/kernel/core/include/mach/mt_wdt.h

However, a report based on actual hardware suggests it may have fewer resets than MT6589:
https://lore.kernel.org/linux-mediatek/W7fWZU3pu6akI_HMTAWPGnnErv60QtTz-LaPb6OtGvU5Bx0Iekl4SxWB6mxBPx8cBo9q9Lg7t8dDzcyfti-5fTirEACcwCLhNAh8e5xoHus=@protonmail.com/

The datasheet is missing the bitfield for WDT_SWRST.

## MT6582

According to the datasheet, the reset bits are:

0 infra
1 mm
2 mfg
4 vdec
5 venc
6 ddrphy
7 md
8 infra_ao
9 conn
10 apmixed
12 conn_mcu

This is clearly not the same reset layout as MT6589.

## MT6797

According to the downstream kernel,
it has additional resets compared to MT6589:

  #define MTK_WDT_SWSYS_RST_C2KSYS_RST    (0x10000)
  #define MTK_WDT_SWSYS_RST_C2KWDT_RST    (0x20000)
  #define MTK_WDT_SWSYS_RST_CONMCU_RST    (0x1000)

https://github.com/SHIFTPHONES/android_kernel_shift_mt6797/blob/4c594e5fa5648dd9a8b8ccc5d609bb523f4799b7/drivers/watchdog/mediatek/wdt/mt6797/mt_wdt.h

## MT7622

According to the datasheet, the reset bits are:

0 infra
1 ethdma
6 ddrphy
8 infra_ao
9 conn
10 apmixed
12 conn_mcu

This is not the MT6589 reset layout.

## MT7623

According to the datasheet, the reset bits are:

0 infra
1 mm
2 mfg
3 ethdma
4 vdec
5 venc_img
6 ddrphy
7 md
8 infra_ao
9 conn
10 apmixed
11 hifsys
12 conn_mcu
13 bdp_disp

Again, this is not the MT6589 reset layout.

## MT7629

I have no evidence either way.

## MT8173

A the downstream kernel claims that MT8173 is compatible with MT2701, MT8127 and MT8163:
https://github.com/bq/aquaris-M10/blob/ab0f5a519edaf314e9b537e448838ec9a4a9a3c8/drivers/watchdog/mediatek/wdt/common/mtk_wdt.c

I don't find this particularly convincing.

MT8163 has 15 reset bits:
https://github.com/amazon-oss/android_kernel_amazon_mt8163/blob/479f405abf2ee6c0f13688b8cf567cce135924af/include/dt-bindings/reset-controller/mt8163-resets.h

MT8127 appears to have the same reset layout as MT6589:
https://github.com/amazon-oss/android_kernel_amazon_mt8127/blob/8428ef2958b83fa51edd6de734c069455f00cd8b/arch/arm/mach-mt8127/include/mach/mt_wdt.h

However, I am not sure whether this actually reflects the hardware.

## MT8188

This is presumably a typo for MT8189, because there is no explanation for using MT8188 in the patch:

[PATCH v7 6/9] dt-bindings: watchdog: Support MediaTek MT8189 wdt

modify dt-binding for support mt8189 dts node of wdt

---
Changs in v7:
- update dt-bindings commit msg
(use "mt8189" instead of "mt8189 evb board")

---
 Documentation/devicetree/bindings/watchdog/mediatek,mtk-wdt.yaml | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/watchdog/mediatek,mtk-wdt.yaml +1 -0
index ba0bfd73ab62..a05f8155b738 100644
@@ -41,6 +41,7 @@ properties:
               - mediatek,mt7623-wdt
               - mediatek,mt7629-wdt
               - mediatek,mt8173-wdt
+              - mediatek,mt8188-wdt
               - mediatek,mt8365-wdt
               - mediatek,mt8516-wdt
           - const: mediatek,mt6589-wdt
Signature · 48 lines
2.45.2


https://lore.kernel.org/linux-arm-kernel/[email protected]/
https://github.com/torvalds/linux/commit/a742d1713c34dff992d1273f614548d214ba1550
I honestly cannot understand how this passed review.

MT8188 already had a standalone compatible entry before this patch,
and it is clearly not compatible with MT6589:
https://github.com/torvalds/linux/blob/bd5f485f3f026225b86573e559af0b7254ef4184/include/dt-bindings/reset/mt8188-resets.h


## MT8189

There is no publicly available information about its reset layout:
https://github.com/external-mirrors/chromiumos-third_party-kernel/blob/a5153266e4c8777fac687e9009a12d32d946514b/drivers/watchdog/mtk_wdt.c#L462


## MT8365

I have no evidence to establish compatibility.


## MT8516

According to the downstream kernel, its reset layout appears to be
compatible with MT6589:
https://android.googlesource.com/platform/hardware/bsp/kernel/mediatek/mt8516-v4.4/+/refs/heads/nougat-iot-release/drivers/watchdog/mediatek/wdt/common/mtk_wdt.h


Note that a downstream kernel claiming compatibility does not necessarily
mean that the SoCs are actually compatible. In my experience, MediaTek's
downstream kernels contain substantial amounts of copied code between
different SoCs, so I would not consider such compatibility claims
sufficient evidence on their own.

Overall, I don't think `mediatek,mt6589-wdt` is an appropriate fallback
compatible for most of the SoCs currently listed in the binding.
I realize that fixing all of these bindings is outside the scope of
this series, but I think this should be addressed rather than leaving
`mediatek,mt6589-wdt` as a generic fallback.


I also noticed that the v3 link is missing from the cover letter:
[3] https://lore.kernel.org/linux-arm-kernel/[email protected]/

Best regards,
Akari
#19 lore raw

Hi Akari,
thank you for the detailed report!

Quoted 8 lines

This is somewhat outside the scope of this series, but adding TOPRGU reset support for MT6589 exposes a pre-existing problem with the mtk-wdt binding that I think should not go unnoticed.

Until now, using mediatek,mt6589-wdt as a fallback compatible for other SoCs was mostly harmless, since the driver did not expose the TOPRGU reset controller.
This series changes that by adding reset controller support for MT6589.

This is the exact reason that led me to touching the MT6589 code. I have been working on improving upstream support for MT8167 and its TOPRGU reset is required for audio support, but the current fallback on MT6589 does not allow resets. If I changed MT8167 only, a reviewer might have thought that the new MT8167 resets should have been applied to MT6589 instead.
This series should cause no regressions as the addition of #reset-cells itself only registers the reset controller for mt6589-derived boards and it does not trigger any reset on its own.

I agree that fixing MT6589 should be an initial step and that upstream would greatly benefit from the cleanup you described. From a high-level standpoint it seems like all of MediaTek's WDTs include a sw reset controller, it's just that the reset table is different for each SoC. If I'm not mistaken, fixing it shouldn't have particular repercussions on existing ABI since the existing fallback could be deprecated and their compatibles relisted as independent devices, i.e. basically what I'm doing with MT8167.

Quoted 10 lines

## MT8516

According to the downstream kernel, its reset layout appears to be compatible with MT6589:
[...]
Note that a downstream kernel claiming compatibility does not necessarily mean that the SoCs are actually compatible. In my experience, MediaTek's downstream kernels contain substantial amounts of copied code between different SoCs, so I would not consider such compatibility claims sufficient evidence on their own.

Kudos for finding MT8516 sources, I have been looking for them for ages! They actually reinforce what you say above.
MT8167 hardware is currently described upstream as MT8516 + display blocks, but the MT8167 resets as described in the data sheet are quite different from MT6589. That said, I've also noticed that sometimes parts of MediaTek's data sheets are copied from other SoCs too, and sometimes contain mistakes of their own... unless it's possible to test on an actual device, some kind of guessing is probably inevitable.

Quoted 2 lines

I also noticed that the v3 link is missing from the cover letter:
[3] https://lore.kernel.org/linux-arm-kernel/[email protected]/

Thank you for spotting this, I will list it in the next iteration!

Signature · 2 lines
Luca Leonardo Scorcia
[email protected]