7e4e45df13fe826320671448f2ec6baac92c9661
[openwrt/staging/stintel.git] / target / linux / ramips / patches-6.1 / 009-v6.3-02-watchdog-mt7621-wdt-avoid-ralink-architecture-depend.patch
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
5
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.
14
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>
20 ---
21 drivers/watchdog/Kconfig | 4 +++-
22 drivers/watchdog/mt7621_wdt.c | 22 +++++++++++++++++-----
23 2 files changed, 20 insertions(+), 6 deletions(-)
24
25 --- a/drivers/watchdog/Kconfig
26 +++ b/drivers/watchdog/Kconfig
27 @@ -1865,7 +1865,9 @@ config GXP_WATCHDOG
28 config MT7621_WDT
29 tristate "Mediatek SoC watchdog"
30 select WATCHDOG_CORE
31 - depends on SOC_MT7620 || SOC_MT7621
32 + select REGMAP_MMIO
33 + select MFD_SYSCON
34 + depends on SOC_MT7620 || SOC_MT7621 || COMPILE_TEST
35 help
36 Hardware driver for the Mediatek/Ralink MT7621/8 SoC Watchdog Timer.
37
38 --- a/drivers/watchdog/mt7621_wdt.c
39 +++ b/drivers/watchdog/mt7621_wdt.c
40 @@ -15,8 +15,8 @@
41 #include <linux/moduleparam.h>
42 #include <linux/platform_device.h>
43 #include <linux/mod_devicetable.h>
44 -
45 -#include <asm/mach-ralink/ralink_regs.h>
46 +#include <linux/mfd/syscon.h>
47 +#include <linux/regmap.h>
48
49 #define SYSC_RSTSTAT 0x38
50 #define WDT_RST_CAUSE BIT(1)
51 @@ -34,6 +34,7 @@
52 struct mt7621_wdt_data {
53 void __iomem *base;
54 struct reset_control *rst;
55 + struct regmap *sysc;
56 struct watchdog_device wdt;
57 };
58
59 @@ -104,9 +105,12 @@ static int mt7621_wdt_stop(struct watchd
60 return 0;
61 }
62
63 -static int mt7621_wdt_bootcause(void)
64 +static int mt7621_wdt_bootcause(struct mt7621_wdt_data *d)
65 {
66 - if (rt_sysc_r32(SYSC_RSTSTAT) & WDT_RST_CAUSE)
67 + u32 val;
68 +
69 + regmap_read(d->sysc, SYSC_RSTSTAT, &val);
70 + if (val & WDT_RST_CAUSE)
71 return WDIOF_CARDRESET;
72
73 return 0;
74 @@ -134,6 +138,7 @@ static const struct watchdog_ops mt7621_
75
76 static int mt7621_wdt_probe(struct platform_device *pdev)
77 {
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
83 if (!drvdata)
84 return -ENOMEM;
85
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);
91 + }
92 +
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;
99
100 - mt7621_wdt->bootstatus = mt7621_wdt_bootcause();
101 + mt7621_wdt->bootstatus = mt7621_wdt_bootcause(drvdata);
102
103 watchdog_init_timeout(mt7621_wdt, mt7621_wdt->max_timeout, dev);
104 watchdog_set_nowayout(mt7621_wdt, nowayout);