Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

watchdog: mt7621-wdt: avoid ralink architecture dependent code

MT7621 SoC has a system controller node. Watchdog need to access to reset
status register. Ralink architecture and related driver are old and from
the beggining they are using some architecture dependent operations for
accessing this shared registers through 'asm/mach-ralink/ralink_regs.h'
header file. However this is not ideal from a driver perspective which can
just access to the system controller registers in an arch independent way
using regmap syscon APIs. Update Kconfig accordingly to select new added
dependencies and allow driver to be compile tested.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20230214103936.1061078-6-sergio.paracuellos@gmail.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>

authored by

Sergio Paracuellos and committed by
Wim Van Sebroeck
ff8ec4ac 783c7cb4

+20 -6
+3 -1
drivers/watchdog/Kconfig
··· 1872 1872 config MT7621_WDT 1873 1873 tristate "Mediatek SoC watchdog" 1874 1874 select WATCHDOG_CORE 1875 - depends on SOC_MT7620 || SOC_MT7621 1875 + select REGMAP_MMIO 1876 + select MFD_SYSCON 1877 + depends on SOC_MT7620 || SOC_MT7621 || COMPILE_TEST 1876 1878 help 1877 1879 Hardware driver for the Mediatek/Ralink MT7621/8 SoC Watchdog Timer. 1878 1880
+17 -5
drivers/watchdog/mt7621_wdt.c
··· 15 15 #include <linux/moduleparam.h> 16 16 #include <linux/platform_device.h> 17 17 #include <linux/mod_devicetable.h> 18 - 19 - #include <asm/mach-ralink/ralink_regs.h> 18 + #include <linux/mfd/syscon.h> 19 + #include <linux/regmap.h> 20 20 21 21 #define SYSC_RSTSTAT 0x38 22 22 #define WDT_RST_CAUSE BIT(1) ··· 34 34 struct mt7621_wdt_data { 35 35 void __iomem *base; 36 36 struct reset_control *rst; 37 + struct regmap *sysc; 37 38 struct watchdog_device wdt; 38 39 }; 39 40 ··· 105 104 return 0; 106 105 } 107 106 108 - static int mt7621_wdt_bootcause(void) 107 + static int mt7621_wdt_bootcause(struct mt7621_wdt_data *d) 109 108 { 110 - if (rt_sysc_r32(SYSC_RSTSTAT) & WDT_RST_CAUSE) 109 + u32 val; 110 + 111 + regmap_read(d->sysc, SYSC_RSTSTAT, &val); 112 + if (val & WDT_RST_CAUSE) 111 113 return WDIOF_CARDRESET; 112 114 113 115 return 0; ··· 138 134 139 135 static int mt7621_wdt_probe(struct platform_device *pdev) 140 136 { 137 + struct device_node *np = pdev->dev.of_node; 141 138 struct device *dev = &pdev->dev; 142 139 struct watchdog_device *mt7621_wdt; 143 140 struct mt7621_wdt_data *drvdata; ··· 147 142 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); 148 143 if (!drvdata) 149 144 return -ENOMEM; 145 + 146 + drvdata->sysc = syscon_regmap_lookup_by_phandle(np, "mediatek,sysctl"); 147 + if (IS_ERR(drvdata->sysc)) { 148 + drvdata->sysc = syscon_regmap_lookup_by_compatible("mediatek,mt7621-sysc"); 149 + if (IS_ERR(drvdata->sysc)) 150 + return PTR_ERR(drvdata->sysc); 151 + } 150 152 151 153 drvdata->base = devm_platform_ioremap_resource(pdev, 0); 152 154 if (IS_ERR(drvdata->base)) ··· 170 158 mt7621_wdt->max_timeout = 0xfffful / 1000; 171 159 mt7621_wdt->parent = dev; 172 160 173 - mt7621_wdt->bootstatus = mt7621_wdt_bootcause(); 161 + mt7621_wdt->bootstatus = mt7621_wdt_bootcause(drvdata); 174 162 175 163 watchdog_init_timeout(mt7621_wdt, mt7621_wdt->max_timeout, dev); 176 164 watchdog_set_nowayout(mt7621_wdt, nowayout);