1 From ff8ec4ac39ad413b580d611dbf68e1d8a82eba56 Mon Sep 17 00:00:00 2001
2 From: Sergio Paracuellos <sergio.paracuellos@gmail.com>
3 Date: Tue, 14 Feb 2023 11:39:36 +0100
4 Subject: [PATCH 2/2] watchdog: mt7621-wdt: avoid ralink architecture dependent code
6 MT7621 SoC has a system controller node. Watchdog need to access to reset
7 status register. Ralink architecture and related driver are old and from
8 the beggining they are using some architecture dependent operations for
9 accessing this shared registers through 'asm/mach-ralink/ralink_regs.h'
10 header file. However this is not ideal from a driver perspective which can
11 just access to the system controller registers in an arch independent way
12 using regmap syscon APIs. Update Kconfig accordingly to select new added
13 dependencies and allow driver to be compile tested.
15 Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
16 Reviewed-by: Guenter Roeck <linux@roeck-us.net>
17 Link: https://lore.kernel.org/r/20230214103936.1061078-6-sergio.paracuellos@gmail.com
18 Signed-off-by: Guenter Roeck <linux@roeck-us.net>
19 Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
21 drivers/watchdog/Kconfig | 4 +++-
22 drivers/watchdog/mt7621_wdt.c | 22 +++++++++++++++++-----
23 2 files changed, 20 insertions(+), 6 deletions(-)
25 --- a/drivers/watchdog/Kconfig
26 +++ b/drivers/watchdog/Kconfig
27 @@ -1799,7 +1799,9 @@ config RALINK_WDT
29 tristate "Mediatek SoC watchdog"
31 - depends on SOC_MT7620 || SOC_MT7621
34 + depends on SOC_MT7620 || SOC_MT7621 || COMPILE_TEST
36 Hardware driver for the Mediatek/Ralink MT7621/8 SoC Watchdog Timer.
38 --- a/drivers/watchdog/mt7621_wdt.c
39 +++ b/drivers/watchdog/mt7621_wdt.c
41 #include <linux/moduleparam.h>
42 #include <linux/platform_device.h>
43 #include <linux/mod_devicetable.h>
45 -#include <asm/mach-ralink/ralink_regs.h>
46 +#include <linux/mfd/syscon.h>
47 +#include <linux/regmap.h>
49 #define SYSC_RSTSTAT 0x38
50 #define WDT_RST_CAUSE BIT(1)
52 struct mt7621_wdt_data {
54 struct reset_control *rst;
55 + struct regmap *sysc;
56 struct watchdog_device wdt;
59 @@ -104,9 +105,12 @@ static int mt7621_wdt_stop(struct watchd
63 -static int mt7621_wdt_bootcause(void)
64 +static int mt7621_wdt_bootcause(struct mt7621_wdt_data *d)
66 - if (rt_sysc_r32(SYSC_RSTSTAT) & WDT_RST_CAUSE)
69 + regmap_read(d->sysc, SYSC_RSTSTAT, &val);
70 + if (val & WDT_RST_CAUSE)
71 return WDIOF_CARDRESET;
74 @@ -134,6 +138,7 @@ static const struct watchdog_ops mt7621_
76 static int mt7621_wdt_probe(struct platform_device *pdev)
78 + struct device_node *np = pdev->dev.of_node;
79 struct device *dev = &pdev->dev;
80 struct watchdog_device *mt7621_wdt;
81 struct mt7621_wdt_data *drvdata;
82 @@ -143,6 +148,13 @@ static int mt7621_wdt_probe(struct platf
86 + drvdata->sysc = syscon_regmap_lookup_by_phandle(np, "mediatek,sysctl");
87 + if (IS_ERR(drvdata->sysc)) {
88 + drvdata->sysc = syscon_regmap_lookup_by_compatible("mediatek,mt7621-sysc");
89 + if (IS_ERR(drvdata->sysc))
90 + return PTR_ERR(drvdata->sysc);
93 drvdata->base = devm_platform_ioremap_resource(pdev, 0);
94 if (IS_ERR(drvdata->base))
95 return PTR_ERR(drvdata->base);
96 @@ -158,7 +170,7 @@ static int mt7621_wdt_probe(struct platf
97 mt7621_wdt->max_timeout = 0xfffful / 1000;
98 mt7621_wdt->parent = dev;
100 - mt7621_wdt->bootstatus = mt7621_wdt_bootcause();
101 + mt7621_wdt->bootstatus = mt7621_wdt_bootcause(drvdata);
103 watchdog_init_timeout(mt7621_wdt, mt7621_wdt->max_timeout, dev);
104 watchdog_set_nowayout(mt7621_wdt, nowayout);