Skip to contentSkip to conversation

Add support for mt8167 toprgu and mmsys resets

PATCH Applied Luca Leonardo Scorcia 5 participants 18 messages Sep 8 – Sep 17

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

v5 cover Add support for mt8167 toprgu and mmsys 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. In the first two patches we add support for the 12 mt6589 toprgu resets.

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

Therefore we introduce a dedicated mediatek,mt8167-wdt compatible for the watchdog driver that describes correctly this SoC's resets. Since its reset bits are non-contiguous, 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 last three patches we describe the mmsys reset table for the SoC. According to the datasheet there are 28 mmsys reset bits divided across two adjacent registers.

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

Changes in v5:
- Dropped the binding header for mt6589 reset IDs;
- Moved the definition of the number of resets for mt6589 inside mtk-wdt driver;
- Separated the mmsys related changes to the last three commits.

Changes in v4 [4]:
- 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]/
[3] https://lore.kernel.org/linux-mediatek/[email protected]/
[4] https://lore.kernel.org/linux-mediatek/[email protected]/

Luca Leonardo Scorcia (8):
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
arm64: dts: mt8167: Properly describe the SoC watchdog resets
dt-bindings: reset: Add mmsys reset ids for mt8167
soc: mediatek: mtk-mmsys: Add resets for mt8167
arm64: dts: mt8167: Add support for mmsys resets

 .../bindings/watchdog/mediatek,mtk-wdt.yaml   |  1 +
 arch/arm/boot/dts/mediatek/mt6589.dtsi        |  1 +
 arch/arm64/boot/dts/mediatek/mt8167.dtsi      |  9 ++++
 drivers/soc/mediatek/mt8167-mmsys.h           |  3 ++
 drivers/soc/mediatek/mtk-mmsys.c              | 38 +++++++++++++
 drivers/watchdog/mtk_wdt.c                    | 54 +++++++++++++++++--
 .../dt-bindings/reset/mediatek,mt8167-mmsys.h | 35 ++++++++++++
 .../dt-bindings/reset/mediatek,mt8167-wdt.h   | 21 ++++++++
 8 files changed, 157 insertions(+), 5 deletions(-)
 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 v5 1/8 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.

---
 drivers/watchdog/mtk_wdt.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/watchdog/mtk_wdt.c +6 -1
index d9c30e4c80e3..d609f0fa35e3 100644
@@ -64,6 +64,7 @@
 #define DRV_NAME		"mtk-wdt"
 #define DRV_VERSION		"1.0"
 
+#define MT6589_TOPRGU_SW_RST_NUM	12
 #define MT7988_TOPRGU_SW_RST_NUM	24
 
 static bool nowayout = WATCHDOG_NOWAYOUT;
@@ -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
#3 lore raw

PATCH v5 2/8 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 | 1 +
 1 file changed, 1 insertion(+)
arch/arm/boot/dts/mediatek/mt6589.dtsi +1 -0
index 46dea445742b..2645054a4a61 100644
@@ -147,6 +147,7 @@ uart3: serial@11009000 {
 		wdt: watchdog@10000000 {
 			compatible = "mediatek,mt6589-wdt";
 			reg = <0x10000000 0x44>;
+			#reset-cells = <1>;
 		};
 	};
 };
Signature · 1 line
2.43.0
#4 lore raw

PATCH v5 3/8 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 (it has 14 sw resets instead of 12, and its reset bit map table is different from mt6589).

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 subsystem resets.

---
 .../bindings/watchdog/mediatek,mtk-wdt.yaml   |  1 +
 .../dt-bindings/reset/mediatek,mt8167-wdt.h   | 21 +++++++++++++++++++
 2 files changed, 22 insertions(+)
 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-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
#8 lore raw

PATCH v5 4/8 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 d609f0fa35e3..abe58ed6a504 100644
@@ -12,6 +12,7 @@
 #include <dt-bindings/reset/mt2712-resets.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
#11 lore raw

PATCH v5 5/8 arm64: dts: mt8167: Properly describe the SoC watchdog 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.

---
 arch/arm64/boot/dts/mediatek/mt8167.dtsi | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm64/boot/dts/mediatek/mt8167.dtsi +8 -0
index 27cf32d7ae35..be215390730b 100644
@@ -8,6 +8,7 @@
 #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-wdt.h>
 
 #include "mt8167-pinfunc.h"
 
@@ -95,6 +96,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>;
Signature · 1 line
2.43.0
#12 lore raw

PATCH v5 6/8 dt-bindings: reset: Add mmsys reset ids for mt8167

In reply to Luca Leonardo Scorcia

According to the SoC data sheet mt8167 has 28 mmsys resets. Add the IDs that can be used in device trees to identify subsystem resets.

---
 .../dt-bindings/reset/mediatek,mt8167-mmsys.h | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 include/dt-bindings/reset/mediatek,mt8167-mmsys.h
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_ */
Signature · 1 line
2.43.0
#15 lore raw

PATCH v5 7/8 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
#16 lore raw

PATCH v5 8/8 arm64: dts: mt8167: Add support for mmsys resets

In reply to Luca Leonardo Scorcia

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

---
 arch/arm64/boot/dts/mediatek/mt8167.dtsi | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/mediatek/mt8167.dtsi +1 -0
index be215390730b..9eb24dc8715f 100644
@@ -132,6 +132,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
#5 lore raw

Re: [PATCH v5 3/8] dt-bindings: watchdog: Add compatible for MediaTek mt8167

In reply to Luca Leonardo Scorcia
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Missing required property constraint for new provider capabilities --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing required property constraint for new provider capabilities --

commit 1623803f044eb5bb4bdac92465a186ae36fe6a1a
Author: Luca Leonardo Scorcia <[email protected]>

dt-bindings: watchdog: Add compatible for MediaTek mt8167

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 (it has 14 sw resets instead of 12, and its reset bit map table is different from mt6589).

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 subsystem resets.

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]
Should #reset-cells be added as a conditionally required property for this new compatible?

Since this patch adds reset provider capabilities to the hardware (defining reset IDs in include/dt-bindings/reset/mediatek,mt8167-wdt.h), the schema needs to ensure #reset-cells is conditionally required for this variant.

Without adding #reset-cells to a required list for mediatek,mt8167-wdt under properties:compatible:oneOf or via an allOf block, a device tree node omitting it will silently pass dt_binding_check validation. This allows incomplete configurations that will fail at runtime when dependent nodes try to consume the resets.

Quoted 3 lines
Documentation/devicetree/bindings/watchdog/mediatek,mtk-wdt.yaml +0 -0
           - mediatek,mt8183-wdt
           - mediatek,mt8186-wdt
           - mediatek,mt8188-wdt
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#9 lore raw

Re: [PATCH v5 4/8] watchdog: mediatek: Add support for mt8167 toprgu/watchdog

In reply to Luca Leonardo Scorcia
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] The watchdog character device is registered and exposed to userspace before its configuration properties are parsed from the Device Tree, creating a time-of-check to time-of-use race condition. This problem wasn't introduced by this patch, but it remains unfixed. --

commit 636d28c87d7152b3a57c046cb13f6a93c3f5aaef
Author: Luca Leonardo Scorcia <[email protected]>

watchdog: mediatek: Add support for mt8167 toprgu/watchdog

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. Also address a preexisting Sashiko finding regarding has_swsysrst_en configuration.

Quoted 4 lines
drivers/watchdog/mtk_wdt.c +0 -0
index d609f0fa35e32..abe58ed6a5045 100644

[ ... ]

Quoted 7 lines
drivers/watchdog/mtk_wdt.c +3 -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) {
+		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;

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

Quoted 10 lines
drivers/watchdog/mtk_wdt.c +1 -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 it looks like the watchdog device is exposed to userspace before its configuration properties are fully parsed from the Device Tree.

In mtk_wdt_probe() in drivers/watchdog/mtk_wdt.c, the device is registered earlier:

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

This registration immediately fires a KOBJ_ADD uevent. If a process opens /dev/watchdog during boot while the probe thread is blocked (for example, if there is mutex contention in toprgu_register_reset_controller()), watchdog_open() will call mtk_wdt_start().

However, mtk_wdt_start() relies on properties that are parsed after the registration:

	if (mtk_wdt->disable_wdt_extrst)
		reg &= ~WDT_MODE_EXRST_EN;
	else
		reg |= WDT_MODE_EXRST_EN;

	if (mtk_wdt->reset_by_toprgu)
		reg |= WDT_MODE_CNT_SEL;
	else
		reg &= ~WDT_MODE_CNT_SEL;

Since mtk_wdt->disable_wdt_extrst and mtk_wdt->reset_by_toprgu are still uninitialized (false) when this race occurs, could mtk_wdt_start() configure the hardware incorrectly, potentially causing a system hang instead of a reboot when a watchdog timeout triggers?

Would it be safer to move the property parsing before the call to devm_watchdog_register_device()?

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

Re: [PATCH v5 6/8] dt-bindings: reset: Add mmsys reset ids for mt8167

In reply to Luca Leonardo Scorcia
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The mt8167-mmsys reset provider capability is introduced without updating the YAML binding to…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The mt8167-mmsys reset provider capability is introduced without updating the YAML binding to require #reset-cells. --

commit 58d3f60477024bb27299c071d1ec1f38c92deeac
Author: Luca Leonardo Scorcia <[email protected]>
Subject: dt-bindings: reset: Add mmsys reset ids for mt8167

According to the SoC data sheet, the mt8167 has 28 mmsys resets. This commit adds the corresponding IDs that can be used in device trees to identify subsystem resets.

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

Quoted 12 lines
include/dt-bindings/reset/mediatek,mt8167-mmsys.h new file +6 -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_
+#define _DT_BINDINGS_RESET_MEDIATEK_MT8167_MMSYS_H_
+
+/* MMSYS reset IDs */
+#define MT8167_MMSYS_SW0_RST_B_SMI_COMMON	0

[Severity: Medium]
This commit introduces a new reset provider capability by adding reset IDs for mt8167-mmsys, but should the corresponding YAML binding be updated as well?

Looking at Documentation/devicetree/bindings/arm/mediatek/mediatek,mmsys.yaml, when hardware gains new provider capabilities like resets, the standard properties such as #reset-cells must be added to the required list or a compatible string-specific conditional block.

Without this update, a device tree node using mediatek,mt8167-mmsys could omit the #reset-cells property and still pass dtbs_check schema validation.

This allows incomplete device trees to slip through, potentially causing runtime failures for reset consumers.

Should the mediatek,mmsys.yaml binding be updated to enforce #reset-cells for this compatible string?

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
maintainer Reviewed-by on the v5 series
#17 lore raw
In reply to Luca Leonardo Scorcia
Quoted 18 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. In the first two patches we add support for the 12 mt6589 toprgu resets.

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

Therefore we introduce a dedicated mediatek,mt8167-wdt compatible for the watchdog driver that describes correctly this SoC's resets. Since its reset bits are non-contiguous, 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.

Quoted 7 lines

In the last three patches we describe the mmsys reset table for the SoC. According to the datasheet there are 28 mmsys reset bits divided across two adjacent registers.

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

Whole series is

Quoted 54 lines

Changes in v5:
- Dropped the binding header for mt6589 reset IDs;
- Moved the definition of the number of resets for mt6589 inside mtk-wdt driver;
- Separated the mmsys related changes to the last three commits.

Changes in v4 [4]:
- 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]/
[3] https://lore.kernel.org/linux-mediatek/[email protected]/
[4] https://lore.kernel.org/linux-mediatek/[email protected]/

Luca Leonardo Scorcia (8):
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
arm64: dts: mt8167: Properly describe the SoC watchdog resets
dt-bindings: reset: Add mmsys reset ids for mt8167
soc: mediatek: mtk-mmsys: Add resets for mt8167
arm64: dts: mt8167: Add support for mmsys resets

  .../bindings/watchdog/mediatek,mtk-wdt.yaml   |  1 +
  arch/arm/boot/dts/mediatek/mt6589.dtsi        |  1 +
  arch/arm64/boot/dts/mediatek/mt8167.dtsi      |  9 ++++
  drivers/soc/mediatek/mt8167-mmsys.h           |  3 ++
  drivers/soc/mediatek/mtk-mmsys.c              | 38 +++++++++++++
  drivers/watchdog/mtk_wdt.c                    | 54 +++++++++++++++++--
  .../dt-bindings/reset/mediatek,mt8167-mmsys.h | 35 ++++++++++++
  .../dt-bindings/reset/mediatek,mt8167-wdt.h   | 21 ++++++++
  8 files changed, 157 insertions(+), 5 deletions(-)

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

Acked-by on v5 3/8
#6 lore raw

Re: [PATCH v5 3/8] dt-bindings: watchdog: Add compatible for MediaTek mt8167

In reply to Luca Leonardo Scorcia
Quoted 9 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 (it has 14 sw resets instead of 12, and its reset bit map table is different from mt6589).

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 subsystem resets.

Quoted 7 lines
---
 .../bindings/watchdog/mediatek,mtk-wdt.yaml   |  1 +
 .../dt-bindings/reset/mediatek,mt8167-wdt.h   | 21 +++++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 include/dt-bindings/reset/mediatek,mt8167-wdt.h

Best regards,
Krzysztof

Acked-by on v5 6/8
#14 lore raw

Re: [PATCH v5 6/8] dt-bindings: reset: Add mmsys reset ids for mt8167

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

According to the SoC data sheet mt8167 has 28 mmsys resets. Add the IDs that can be used in device trees to identify subsystem resets.

---
 .../dt-bindings/reset/mediatek,mt8167-mmsys.h | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 include/dt-bindings/reset/mediatek,mt8167-mmsys.h

Best regards,
Krzysztof

maintainer Applied
#7 lore raw

Re: [PATCH v5 3/8] dt-bindings: watchdog: Add compatible for MediaTek mt8167

In reply to Luca Leonardo Scorcia
Quoted 6 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 (it has 14 sw resets instead of 12, and its reset bit map table is different from mt6589).

Quoted 6 lines

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 subsystem resets.

Applied.

Thanks,
Guenter

maintainer Applied
#10 lore raw

Re: [PATCH v5 4/8] watchdog: mediatek: Add support for mt8167 toprgu/watchdog

In reply to Luca Leonardo Scorcia
Quoted 7 lines · 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.

Quoted 5 lines

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

Applied.

Thanks,
Guenter