2024-03-01 01:56:57 +00:00
|
|
|
From 137c9e08e5e542d58aa606b0bb4f0990117309a0 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Daniel Golle <daniel@makrotopia.org>
|
|
|
|
Date: Mon, 20 Nov 2023 18:22:31 +0000
|
|
|
|
Subject: [PATCH] watchdog: mediatek: mt7988: add wdt support
|
|
|
|
|
|
|
|
Add support for watchdog and reset generator unit of the MediaTek
|
|
|
|
MT7988 SoC.
|
|
|
|
|
|
|
|
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
|
|
|
|
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
|
|
|
|
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
|
|
|
|
Link: https://lore.kernel.org/r/c0cf5f701801cce60470853fa15f1d9dced78c4f.1700504385.git.daniel@makrotopia.org
|
|
|
|
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
|
|
|
|
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
|
|
|
|
---
|
|
|
|
drivers/watchdog/mtk_wdt.c | 42 ++++++++++++++++++++++++++++++++++++++
|
|
|
|
1 file changed, 42 insertions(+)
|
|
|
|
|
|
|
|
--- a/drivers/watchdog/mtk_wdt.c
|
|
|
|
+++ b/drivers/watchdog/mtk_wdt.c
|
2024-03-01 02:22:25 +00:00
|
|
|
@@ -58,9 +58,13 @@
|
2024-03-01 01:56:57 +00:00
|
|
|
#define WDT_SWSYSRST 0x18U
|
|
|
|
#define WDT_SWSYS_RST_KEY 0x88000000
|
|
|
|
|
|
|
|
+#define WDT_SWSYSRST_EN 0xfc
|
|
|
|
+
|
|
|
|
#define DRV_NAME "mtk-wdt"
|
|
|
|
#define DRV_VERSION "1.0"
|
|
|
|
|
|
|
|
+#define MT7988_TOPRGU_SW_RST_NUM 24
|
|
|
|
+
|
|
|
|
static bool nowayout = WATCHDOG_NOWAYOUT;
|
|
|
|
static unsigned int timeout;
|
|
|
|
|
2024-03-01 02:22:25 +00:00
|
|
|
@@ -71,10 +75,12 @@ struct mtk_wdt_dev {
|
2024-03-01 01:56:57 +00:00
|
|
|
struct reset_controller_dev rcdev;
|
|
|
|
bool disable_wdt_extrst;
|
2024-03-01 02:22:25 +00:00
|
|
|
bool reset_by_toprgu;
|
2024-03-01 01:56:57 +00:00
|
|
|
+ bool has_swsysrst_en;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mtk_wdt_data {
|
|
|
|
int toprgu_sw_rst_num;
|
|
|
|
+ bool has_swsysrst_en;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct mtk_wdt_data mt2712_data = {
|
2024-03-01 02:22:25 +00:00
|
|
|
@@ -89,6 +95,11 @@ static const struct mtk_wdt_data mt7986_
|
2024-03-01 01:56:57 +00:00
|
|
|
.toprgu_sw_rst_num = MT7986_TOPRGU_SW_RST_NUM,
|
|
|
|
};
|
|
|
|
|
|
|
|
+static const struct mtk_wdt_data mt7988_data = {
|
|
|
|
+ .toprgu_sw_rst_num = MT7988_TOPRGU_SW_RST_NUM,
|
|
|
|
+ .has_swsysrst_en = true,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static const struct mtk_wdt_data mt8183_data = {
|
|
|
|
.toprgu_sw_rst_num = MT8183_TOPRGU_SW_RST_NUM,
|
|
|
|
};
|
2024-03-01 02:22:25 +00:00
|
|
|
@@ -109,6 +120,28 @@ static const struct mtk_wdt_data mt8195_
|
2024-03-01 01:56:57 +00:00
|
|
|
.toprgu_sw_rst_num = MT8195_TOPRGU_SW_RST_NUM,
|
|
|
|
};
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * toprgu_reset_sw_en_unlocked() - enable/disable software control for reset bit
|
|
|
|
+ * @data: Pointer to instance of driver data.
|
|
|
|
+ * @id: Bit number identifying the reset to be enabled or disabled.
|
|
|
|
+ * @enable: If true, enable software control for that bit, disable otherwise.
|
|
|
|
+ *
|
|
|
|
+ * Context: The caller must hold lock of struct mtk_wdt_dev.
|
|
|
|
+ */
|
|
|
|
+static void toprgu_reset_sw_en_unlocked(struct mtk_wdt_dev *data,
|
|
|
|
+ unsigned long id, bool enable)
|
|
|
|
+{
|
|
|
|
+ u32 tmp;
|
|
|
|
+
|
|
|
|
+ tmp = readl(data->wdt_base + WDT_SWSYSRST_EN);
|
|
|
|
+ if (enable)
|
|
|
|
+ tmp |= BIT(id);
|
|
|
|
+ else
|
|
|
|
+ tmp &= ~BIT(id);
|
|
|
|
+
|
|
|
|
+ writel(tmp, data->wdt_base + WDT_SWSYSRST_EN);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
static int toprgu_reset_update(struct reset_controller_dev *rcdev,
|
|
|
|
unsigned long id, bool assert)
|
|
|
|
{
|
2024-03-01 02:22:25 +00:00
|
|
|
@@ -119,6 +152,9 @@ static int toprgu_reset_update(struct re
|
2024-03-01 01:56:57 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&data->lock, flags);
|
|
|
|
|
|
|
|
+ if (assert && data->has_swsysrst_en)
|
|
|
|
+ toprgu_reset_sw_en_unlocked(data, id, true);
|
|
|
|
+
|
|
|
|
tmp = readl(data->wdt_base + WDT_SWSYSRST);
|
|
|
|
if (assert)
|
|
|
|
tmp |= BIT(id);
|
2024-03-01 02:22:25 +00:00
|
|
|
@@ -127,6 +163,9 @@ static int toprgu_reset_update(struct re
|
2024-03-01 01:56:57 +00:00
|
|
|
tmp |= WDT_SWSYS_RST_KEY;
|
|
|
|
writel(tmp, data->wdt_base + WDT_SWSYSRST);
|
|
|
|
|
|
|
|
+ if (!assert && data->has_swsysrst_en)
|
|
|
|
+ toprgu_reset_sw_en_unlocked(data, id, false);
|
|
|
|
+
|
|
|
|
spin_unlock_irqrestore(&data->lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
2024-12-14 20:02:19 +00:00
|
|
|
@@ -412,6 +451,8 @@ static int mtk_wdt_probe(struct platform
|
2024-03-01 01:56:57 +00:00
|
|
|
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 =
|
2024-12-14 20:02:19 +00:00
|
|
|
@@ -450,6 +491,7 @@ static const struct of_device_id mtk_wdt
|
2024-03-01 01:56:57 +00:00
|
|
|
{ .compatible = "mediatek,mt6589-wdt" },
|
2024-03-01 02:22:25 +00:00
|
|
|
{ .compatible = "mediatek,mt6795-wdt", .data = &mt6795_data },
|
2024-03-01 01:56:57 +00:00
|
|
|
{ .compatible = "mediatek,mt7986-wdt", .data = &mt7986_data },
|
|
|
|
+ { .compatible = "mediatek,mt7988-wdt", .data = &mt7988_data },
|
|
|
|
{ .compatible = "mediatek,mt8183-wdt", .data = &mt8183_data },
|
|
|
|
{ .compatible = "mediatek,mt8186-wdt", .data = &mt8186_data },
|
2024-03-01 02:22:25 +00:00
|
|
|
{ .compatible = "mediatek,mt8188-wdt", .data = &mt8188_data },
|