cb49ce1d253139763f889cbd2429460b94fec0ae
[openwrt/staging/stintel.git] / target / linux / mediatek / patches-6.6 / 251-v6.8-watchdog-mediatek-mt7988-add-wdt-support.patch
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
5
6 Add support for watchdog and reset generator unit of the MediaTek
7 MT7988 SoC.
8
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>
15 ---
16 drivers/watchdog/mtk_wdt.c | 42 ++++++++++++++++++++++++++++++++++++++
17 1 file changed, 42 insertions(+)
18
19 --- a/drivers/watchdog/mtk_wdt.c
20 +++ b/drivers/watchdog/mtk_wdt.c
21 @@ -56,9 +56,13 @@
22 #define WDT_SWSYSRST 0x18U
23 #define WDT_SWSYS_RST_KEY 0x88000000
24
25 +#define WDT_SWSYSRST_EN 0xfc
26 +
27 #define DRV_NAME "mtk-wdt"
28 #define DRV_VERSION "1.0"
29
30 +#define MT7988_TOPRGU_SW_RST_NUM 24
31 +
32 static bool nowayout = WATCHDOG_NOWAYOUT;
33 static unsigned int timeout;
34
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;
40 };
41
42 struct mtk_wdt_data {
43 int toprgu_sw_rst_num;
44 + bool has_swsysrst_en;
45 };
46
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,
50 };
51
52 +static const struct mtk_wdt_data mt7988_data = {
53 + .toprgu_sw_rst_num = MT7988_TOPRGU_SW_RST_NUM,
54 + .has_swsysrst_en = true,
55 +};
56 +
57 static const struct mtk_wdt_data mt8183_data = {
58 .toprgu_sw_rst_num = MT8183_TOPRGU_SW_RST_NUM,
59 };
60 @@ -98,6 +109,28 @@ static const struct mtk_wdt_data mt8195_
61 .toprgu_sw_rst_num = MT8195_TOPRGU_SW_RST_NUM,
62 };
63
64 +/**
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.
69 + *
70 + * Context: The caller must hold lock of struct mtk_wdt_dev.
71 + */
72 +static void toprgu_reset_sw_en_unlocked(struct mtk_wdt_dev *data,
73 + unsigned long id, bool enable)
74 +{
75 + u32 tmp;
76 +
77 + tmp = readl(data->wdt_base + WDT_SWSYSRST_EN);
78 + if (enable)
79 + tmp |= BIT(id);
80 + else
81 + tmp &= ~BIT(id);
82 +
83 + writel(tmp, data->wdt_base + WDT_SWSYSRST_EN);
84 +}
85 +
86 static int toprgu_reset_update(struct reset_controller_dev *rcdev,
87 unsigned long id, bool assert)
88 {
89 @@ -108,6 +141,9 @@ static int toprgu_reset_update(struct re
90
91 spin_lock_irqsave(&data->lock, flags);
92
93 + if (assert && data->has_swsysrst_en)
94 + toprgu_reset_sw_en_unlocked(data, id, true);
95 +
96 tmp = readl(data->wdt_base + WDT_SWSYSRST);
97 if (assert)
98 tmp |= BIT(id);
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);
102
103 + if (!assert && data->has_swsysrst_en)
104 + toprgu_reset_sw_en_unlocked(data, id, false);
105 +
106 spin_unlock_irqrestore(&data->lock, flags);
107
108 return 0;
109 @@ -393,6 +432,8 @@ static int mtk_wdt_probe(struct platform
110 wdt_data->toprgu_sw_rst_num);
111 if (err)
112 return err;
113 +
114 + mtk_wdt->has_swsysrst_en = wdt_data->has_swsysrst_en;
115 }
116
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 },