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

watchdog: npcm: Enable clock if provided

On the Nuvoton WPCM450 SoC, with its upcoming clock driver, peripheral
clocks are individually gated and ungated. Therefore, the watchdog
driver must be able to ungate the watchdog clock.

Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20220610072141.347795-3-j.neuschaefer@gmx.net
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>

authored by

Jonathan Neuschäfer and committed by
Wim Van Sebroeck
af084fdc 6adbfbab

+16
+16
drivers/watchdog/npcm_wdt.c
··· 3 3 // Copyright (c) 2018 IBM Corp. 4 4 5 5 #include <linux/bitops.h> 6 + #include <linux/clk.h> 6 7 #include <linux/delay.h> 7 8 #include <linux/interrupt.h> 8 9 #include <linux/kernel.h> ··· 44 43 struct npcm_wdt { 45 44 struct watchdog_device wdd; 46 45 void __iomem *reg; 46 + struct clk *clk; 47 47 }; 48 48 49 49 static inline struct npcm_wdt *to_npcm_wdt(struct watchdog_device *wdd) ··· 67 65 { 68 66 struct npcm_wdt *wdt = to_npcm_wdt(wdd); 69 67 u32 val; 68 + 69 + if (wdt->clk) 70 + clk_prepare_enable(wdt->clk); 70 71 71 72 if (wdd->timeout < 2) 72 73 val = 0x800; ··· 104 99 struct npcm_wdt *wdt = to_npcm_wdt(wdd); 105 100 106 101 writel(0, wdt->reg); 102 + 103 + if (wdt->clk) 104 + clk_disable_unprepare(wdt->clk); 107 105 108 106 return 0; 109 107 } ··· 155 147 { 156 148 struct npcm_wdt *wdt = to_npcm_wdt(wdd); 157 149 150 + /* For reset, we start the WDT clock and leave it running. */ 151 + if (wdt->clk) 152 + clk_prepare_enable(wdt->clk); 153 + 158 154 writel(NPCM_WTR | NPCM_WTRE | NPCM_WTE, wdt->reg); 159 155 udelay(1000); 160 156 ··· 202 190 wdt->reg = devm_platform_ioremap_resource(pdev, 0); 203 191 if (IS_ERR(wdt->reg)) 204 192 return PTR_ERR(wdt->reg); 193 + 194 + wdt->clk = devm_clk_get_optional(&pdev->dev, NULL); 195 + if (IS_ERR(wdt->clk)) 196 + return PTR_ERR(wdt->clk); 205 197 206 198 irq = platform_get_irq(pdev, 0); 207 199 if (irq < 0)