1 From 137c9e08e5e542d58aa606b0bb4f0990117309a0 Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Mon, 20 Nov 2023 18:22:31 +0000
4 Subject: [PATCH] watchdog: mediatek: mt7988: add wdt support
6 Add support for watchdog and reset generator unit of the MediaTek
9 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
10 Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
11 Reviewed-by: Guenter Roeck <linux@roeck-us.net>
12 Link: https://lore.kernel.org/r/c0cf5f701801cce60470853fa15f1d9dced78c4f.1700504385.git.daniel@makrotopia.org
13 Signed-off-by: Guenter Roeck <linux@roeck-us.net>
14 Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
16 drivers/watchdog/mtk_wdt.c | 42 ++++++++++++++++++++++++++++++++++++++
17 1 file changed, 42 insertions(+)
19 --- a/drivers/watchdog/mtk_wdt.c
20 +++ b/drivers/watchdog/mtk_wdt.c
22 #define WDT_SWSYSRST 0x18U
23 #define WDT_SWSYS_RST_KEY 0x88000000
25 +#define WDT_SWSYSRST_EN 0xfc
27 #define DRV_NAME "mtk-wdt"
28 #define DRV_VERSION "1.0"
30 +#define MT7988_TOPRGU_SW_RST_NUM 24
32 static bool nowayout = WATCHDOG_NOWAYOUT;
33 static unsigned int timeout;
35 @@ -68,10 +72,12 @@ struct mtk_wdt_dev {
36 spinlock_t lock; /* protects WDT_SWSYSRST reg */
37 struct reset_controller_dev rcdev;
38 bool disable_wdt_extrst;
39 + bool has_swsysrst_en;
43 int toprgu_sw_rst_num;
44 + bool has_swsysrst_en;
47 static const struct mtk_wdt_data mt2712_data = {
48 @@ -82,6 +88,11 @@ static const struct mtk_wdt_data mt7986_
49 .toprgu_sw_rst_num = MT7986_TOPRGU_SW_RST_NUM,
52 +static const struct mtk_wdt_data mt7988_data = {
53 + .toprgu_sw_rst_num = MT7988_TOPRGU_SW_RST_NUM,
54 + .has_swsysrst_en = true,
57 static const struct mtk_wdt_data mt8183_data = {
58 .toprgu_sw_rst_num = MT8183_TOPRGU_SW_RST_NUM,
60 @@ -98,6 +109,28 @@ static const struct mtk_wdt_data mt8195_
61 .toprgu_sw_rst_num = MT8195_TOPRGU_SW_RST_NUM,
65 + * toprgu_reset_sw_en_unlocked() - enable/disable software control for reset bit
66 + * @data: Pointer to instance of driver data.
67 + * @id: Bit number identifying the reset to be enabled or disabled.
68 + * @enable: If true, enable software control for that bit, disable otherwise.
70 + * Context: The caller must hold lock of struct mtk_wdt_dev.
72 +static void toprgu_reset_sw_en_unlocked(struct mtk_wdt_dev *data,
73 + unsigned long id, bool enable)
77 + tmp = readl(data->wdt_base + WDT_SWSYSRST_EN);
83 + writel(tmp, data->wdt_base + WDT_SWSYSRST_EN);
86 static int toprgu_reset_update(struct reset_controller_dev *rcdev,
87 unsigned long id, bool assert)
89 @@ -108,6 +141,9 @@ static int toprgu_reset_update(struct re
91 spin_lock_irqsave(&data->lock, flags);
93 + if (assert && data->has_swsysrst_en)
94 + toprgu_reset_sw_en_unlocked(data, id, true);
96 tmp = readl(data->wdt_base + WDT_SWSYSRST);
99 @@ -116,6 +152,9 @@ static int toprgu_reset_update(struct re
100 tmp |= WDT_SWSYS_RST_KEY;
101 writel(tmp, data->wdt_base + WDT_SWSYSRST);
103 + if (!assert && data->has_swsysrst_en)
104 + toprgu_reset_sw_en_unlocked(data, id, false);
106 spin_unlock_irqrestore(&data->lock, flags);
109 @@ -393,6 +432,8 @@ static int mtk_wdt_probe(struct platform
110 wdt_data->toprgu_sw_rst_num);
114 + mtk_wdt->has_swsysrst_en = wdt_data->has_swsysrst_en;
117 mtk_wdt->disable_wdt_extrst =
118 @@ -427,6 +468,7 @@ static const struct of_device_id mtk_wdt
119 { .compatible = "mediatek,mt2712-wdt", .data = &mt2712_data },
120 { .compatible = "mediatek,mt6589-wdt" },
121 { .compatible = "mediatek,mt7986-wdt", .data = &mt7986_data },
122 + { .compatible = "mediatek,mt7988-wdt", .data = &mt7988_data },
123 { .compatible = "mediatek,mt8183-wdt", .data = &mt8183_data },
124 { .compatible = "mediatek,mt8186-wdt", .data = &mt8186_data },
125 { .compatible = "mediatek,mt8192-wdt", .data = &mt8192_data },