From nobody Mon May 25 04:33:49 2026 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EF881C5F1B for ; Tue, 19 May 2026 00:33:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779150827; cv=none; b=O66BsPw4GwedC9sg9B1jYCaua6o/meOq8V95bB7sIIuWaW3eLmYJTYYzSew1ksjQH/dLN1pQW/Z+Sk4m3QiOsvc9cDm6tZFQbg/xNF5o36JgE+kCyYwoe6dcX4ZPq+t0plzog7mnwzUI7wX8Ubx+GtxV47YFTThAnA3iNr5FC3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779150827; c=relaxed/simple; bh=lrJ282NK9fi8qqGMccNAIXekUuVRnEMIpVboAyy/jk4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=p54CQ2t+iPE9Fu0GHeVdpbbkIQsOSE2MJ6J+Ph8cNqcvTrTPpg7VU+1L65aEczxeDBho7IxVzKFAg17PZSMUmfVFxmU7GWtGn0uHK2g6o8dV5A+2Gr/IdLDsfnpRDVzRNEqzOX0xxbY3iP92Xpt5C/e/BFUpD0kSN1w2Y1GV9nc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nNqDeZLe; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nNqDeZLe" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2bd266f6fc0so13855445ad.2 for ; Mon, 18 May 2026 17:33:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779150825; x=1779755625; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=PNs2kxwC7/9yf6VBEm5tsn713iTGlZ3XWuPjzBHMItI=; b=nNqDeZLeiapyaHkPHgp7s4nEdKSJZ0smNzD/CX7J3YaRtrQwoXMBiPAacy1ljdKU13 KAPfIdfun75JHpKMorb/otgOJcUAXGAaP07Yu423k1IIhboFCOyiiqr9kyD3d+ywmTn/ VtJyVPbPjPLrA0oEVhXnm/YwRmp6J9aWxZd5nzSg6BHl5B+NFqYkcXeyAKmOeshlz1N6 MtuOGXe5/080tdKW+vtOF3SmJ1KvXwAZioaaBjwfGml403zGMfnLu2ruSA6TFjA3EKml Pwr14zmG3+5vYvzIaSSvUudWnEorybtezZqXx5cmYIDaukszTLV5uy9P3lv6tE9Fkiw4 +aMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779150825; x=1779755625; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=PNs2kxwC7/9yf6VBEm5tsn713iTGlZ3XWuPjzBHMItI=; b=KUNErbvWzWVHcVXFfUvn2JCwSc8DFuCpUIgsXlvYru8NPD1X8O1O0Ub/k1U0+LgeSi WVR8IH/Sf1CMCExvGUS77sA+M+YSuljOM1fzVxu4/BZlpznzq1o3M+XlY4ZzH5waTock Ib1hDMWm4HyDVZkwgocmsXEc+pcycp214oSd/B59seE1somlGluWFS6xhFmH2ocmfrPJ IShDpedS+CuL0ltDiyMbLfJB5dVxiixlvqq5RsffixaKvAEWLMpxNork/S6DUQfOzl6r 0h/IdlALmGmd14Lljqck/D4/emKIGj4qkmUSDCkegt0gO8rKWlTcVCojvodoTCWkxv1O hJJA== X-Forwarded-Encrypted: i=1; AFNElJ8M665K6IeRQe0tFGxe5XfzZzmhB9rGA18JQQsoxBuLd99DIrdIjkDFpwiTAAkwtK5I5CmD/nbYAp7onU4=@vger.kernel.org X-Gm-Message-State: AOJu0YyHX5OySTH2aeHIxVBjH7x1i7LzVoTvq8SqGwJW+aw3yP/aR7U3 di8L+7LLpbfATjBXJFguDabwV5VfKpAF3oTTDgnd6x2l0EfZtZekNYoQ X-Gm-Gg: Acq92OEFtjOen81IgbPCSOKiBTr7MSd3rFYEaJYVyLiPWyIEhrCvr6AjDnp5smPKVF5 sH2czO8Bzwzn7f+val2D6aT/9E5s8UGo3f4oP5hAQLO2SjyN62t1aqlePk9Zf5SlRidFfmu7brR juRxBV7zRzwPNp1MSx5ri82lDiTRyG1gVd35PzvNitKAak29iAwO67tRJTp2WkSCw5SJp5YopeT jm0VCTRgX5QFtPCNNi3xnKICCm2Nlw9t2VuBpTpZGPCupijek0Nnv05mmwyPoeu0aRscMScjK2o eoiTE/wtUYhy6qan1V2EwZNsKbfiIr7S8fiqrUPqDV9b8wsDK/pBD+HJZeFz1OIug+cu0gJ+A9o 40mtVV7W0/01QCMFPUHcAGpzRdYZ4/wI4l0RaXWMMRGNZlsBvIdTddwReLt9ohlGBRn3xQxsKG5 t3oLttpLouuDH5PUC1Q3cm1rAHYwsFs97qAuChc0YMq/cAyliuHShZs5qkCStSucQE7iPfR7Bpi u+1YJw+N3OBx9BkHtntgZgIYxc31fh2cEQ= X-Received: by 2002:a17:902:ea03:b0:2bd:9c0a:32c with SMTP id d9443c01a7336-2bd9c0a065cmr131763175ad.19.1779150824706; Mon, 18 May 2026 17:33:44 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d:7285:c2ff:fe45:8a32]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2bd5cfe6b8fsm170572785ad.46.2026.05.18.17.33.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 17:33:44 -0700 (PDT) From: Rosen Penev To: linux-watchdog@vger.kernel.org Cc: Wim Van Sebroeck , Guenter Roeck , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] watchdog: ath79: convert to watchdog_device Date: Mon, 18 May 2026 17:33:26 -0700 Message-ID: <20260519003326.625858-1-rosenp@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Converts from the legacy miscdevice/file_operations interface to the watchdog_device framework, simplifying the driver and properly handling EPROBE_DEFER. Use wdd->timeout in all callbacks instead of a global, fix get_timeleft() to return seconds instead of raw clock ticks, store max_timeout in the watchdog_device struct, wire up nowayout via watchdog_set_nowayout(), pass the module parameter to watchdog_init_timeout(), add .owner to watchdog_ops, and remove the leftover file-ops state (wdt_flags and the busy/expect-close bits). Tested on an Archer C7v2. sysupgrade watchdog handoff works fine. Assisted-by: Claude:Sonnet-4.6 Signed-off-by: Rosen Penev --- drivers/watchdog/ath79_wdt.c | 244 +++++++++++------------------------ 1 file changed, 73 insertions(+), 171 deletions(-) diff --git a/drivers/watchdog/ath79_wdt.c b/drivers/watchdog/ath79_wdt.c index 409a40b14901..d83957712c02 100644 --- a/drivers/watchdog/ath79_wdt.c +++ b/drivers/watchdog/ath79_wdt.c @@ -15,13 +15,10 @@ =20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 -#include #include #include -#include #include #include -#include #include #include #include @@ -31,7 +28,6 @@ #include #include #include -#include =20 #define DRIVER_NAME "ath79-wdt" =20 @@ -57,37 +53,32 @@ module_param(timeout, int, 0); MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds " "(default=3D" __MODULE_STRING(WDT_TIMEOUT) "s)"); =20 -static unsigned long wdt_flags; - -#define WDT_FLAGS_BUSY 0 -#define WDT_FLAGS_EXPECT_CLOSE 1 - -static struct clk *wdt_clk; -static unsigned long wdt_freq; -static int boot_status; -static int max_timeout; -static void __iomem *wdt_base; +struct ath79_wdt { + void __iomem *base; + unsigned long freq; + struct watchdog_device wdd; +}; =20 -static inline void ath79_wdt_wr(unsigned reg, u32 val) +static inline void ath79_wdt_wr(struct ath79_wdt *wdt, unsigned reg, u32 v= al) { - iowrite32(val, wdt_base + reg); + iowrite32(val, wdt->base + reg); } =20 -static inline u32 ath79_wdt_rr(unsigned reg) +static inline u32 ath79_wdt_rr(struct ath79_wdt *wdt, unsigned reg) { - return ioread32(wdt_base + reg); + return ioread32(wdt->base + reg); } =20 -static inline void ath79_wdt_keepalive(void) +static inline void ath79_wdt_keepalive(struct ath79_wdt *wdt) { - ath79_wdt_wr(WDOG_REG_TIMER, wdt_freq * timeout); + ath79_wdt_wr(wdt, WDOG_REG_TIMER, wdt->freq * wdt->wdd.timeout); /* flush write */ - ath79_wdt_rr(WDOG_REG_TIMER); + ath79_wdt_rr(wdt, WDOG_REG_TIMER); } =20 -static inline void ath79_wdt_enable(void) +static inline void ath79_wdt_enable(struct ath79_wdt *wdt) { - ath79_wdt_keepalive(); + ath79_wdt_keepalive(wdt); =20 /* * Updating the TIMER register requires a few microseconds @@ -97,202 +88,115 @@ static inline void ath79_wdt_enable(void) */ udelay(2); =20 - ath79_wdt_wr(WDOG_REG_CTRL, WDOG_CTRL_ACTION_FCR); + ath79_wdt_wr(wdt, WDOG_REG_CTRL, WDOG_CTRL_ACTION_FCR); /* flush write */ - ath79_wdt_rr(WDOG_REG_CTRL); + ath79_wdt_rr(wdt, WDOG_REG_CTRL); } =20 -static inline void ath79_wdt_disable(void) +static inline void ath79_wdt_disable(struct ath79_wdt *wdt) { - ath79_wdt_wr(WDOG_REG_CTRL, WDOG_CTRL_ACTION_NONE); + ath79_wdt_wr(wdt, WDOG_REG_CTRL, WDOG_CTRL_ACTION_NONE); /* flush write */ - ath79_wdt_rr(WDOG_REG_CTRL); + ath79_wdt_rr(wdt, WDOG_REG_CTRL); } =20 -static int ath79_wdt_set_timeout(int val) +static int ath79_wdt_ping(struct watchdog_device *wdd) { - if (val < 1 || val > max_timeout) - return -EINVAL; + struct ath79_wdt *wdt =3D watchdog_get_drvdata(wdd); =20 - timeout =3D val; - ath79_wdt_keepalive(); + ath79_wdt_keepalive(wdt); =20 return 0; } =20 -static int ath79_wdt_open(struct inode *inode, struct file *file) +static int ath79_wdt_set_timeout(struct watchdog_device *wdd, unsigned int= val) { - if (test_and_set_bit(WDT_FLAGS_BUSY, &wdt_flags)) - return -EBUSY; + struct ath79_wdt *wdt =3D watchdog_get_drvdata(wdd); =20 - clear_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags); - ath79_wdt_enable(); + wdd->timeout =3D val; + ath79_wdt_keepalive(wdt); =20 - return stream_open(inode, file); + return 0; } =20 -static int ath79_wdt_release(struct inode *inode, struct file *file) +static int ath79_wdt_start(struct watchdog_device *wdd) { - if (test_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags)) - ath79_wdt_disable(); - else { - pr_crit("device closed unexpectedly, watchdog timer will not stop!\n"); - ath79_wdt_keepalive(); - } + struct ath79_wdt *wdt =3D watchdog_get_drvdata(wdd); =20 - clear_bit(WDT_FLAGS_BUSY, &wdt_flags); - clear_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags); + ath79_wdt_enable(wdt); =20 return 0; } =20 -static ssize_t ath79_wdt_write(struct file *file, const char *data, - size_t len, loff_t *ppos) +static unsigned int ath79_wdt_get_timeleft(struct watchdog_device *wdd) { - if (len) { - if (!nowayout) { - size_t i; - - clear_bit(WDT_FLAGS_EXPECT_CLOSE, &wdt_flags); + struct ath79_wdt *wdt =3D watchdog_get_drvdata(wdd); =20 - for (i =3D 0; i !=3D len; i++) { - char c; - - if (get_user(c, data + i)) - return -EFAULT; + return ath79_wdt_rr(wdt, WDOG_REG_TIMER) / wdt->freq; +} =20 - if (c =3D=3D 'V') - set_bit(WDT_FLAGS_EXPECT_CLOSE, - &wdt_flags); - } - } +static int ath79_wdt_stop(struct watchdog_device *wdd) +{ + struct ath79_wdt *wdt =3D watchdog_get_drvdata(wdd); =20 - ath79_wdt_keepalive(); - } + ath79_wdt_disable(wdt); =20 - return len; + return 0; } =20 static const struct watchdog_info ath79_wdt_info =3D { - .options =3D WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | - WDIOF_MAGICCLOSE | WDIOF_CARDRESET, - .firmware_version =3D 0, - .identity =3D "ATH79 watchdog", + .options =3D WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_CARDRESET, + .firmware_version =3D 0, + .identity =3D "ATH79 watchdog", }; =20 -static long ath79_wdt_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) -{ - void __user *argp =3D (void __user *)arg; - int __user *p =3D argp; - int err; - int t; - - switch (cmd) { - case WDIOC_GETSUPPORT: - err =3D copy_to_user(argp, &ath79_wdt_info, - sizeof(ath79_wdt_info)) ? -EFAULT : 0; - break; - - case WDIOC_GETSTATUS: - err =3D put_user(0, p); - break; - - case WDIOC_GETBOOTSTATUS: - err =3D put_user(boot_status, p); - break; - - case WDIOC_KEEPALIVE: - ath79_wdt_keepalive(); - err =3D 0; - break; - - case WDIOC_SETTIMEOUT: - err =3D get_user(t, p); - if (err) - break; - - err =3D ath79_wdt_set_timeout(t); - if (err) - break; - fallthrough; - - case WDIOC_GETTIMEOUT: - err =3D put_user(timeout, p); - break; - - default: - err =3D -ENOTTY; - break; - } - - return err; -} - -static const struct file_operations ath79_wdt_fops =3D { - .owner =3D THIS_MODULE, - .write =3D ath79_wdt_write, - .unlocked_ioctl =3D ath79_wdt_ioctl, - .compat_ioctl =3D compat_ptr_ioctl, - .open =3D ath79_wdt_open, - .release =3D ath79_wdt_release, -}; - -static struct miscdevice ath79_wdt_miscdev =3D { - .minor =3D WATCHDOG_MINOR, - .name =3D "watchdog", - .fops =3D &ath79_wdt_fops, +static const struct watchdog_ops ath79_wdt_ops =3D { + .owner =3D THIS_MODULE, + .start =3D ath79_wdt_start, + .stop =3D ath79_wdt_stop, + .ping =3D ath79_wdt_ping, + .set_timeout =3D ath79_wdt_set_timeout, + .get_timeleft =3D ath79_wdt_get_timeleft, }; =20 static int ath79_wdt_probe(struct platform_device *pdev) { + struct ath79_wdt *wdt; + struct clk *wdt_clk; u32 ctrl; - int err; =20 - if (wdt_base) - return -EBUSY; + wdt =3D devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL); + if (!wdt) + return -ENOMEM; =20 - wdt_base =3D devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(wdt_base)) - return PTR_ERR(wdt_base); + wdt->base =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(wdt->base)) + return PTR_ERR(wdt->base); =20 wdt_clk =3D devm_clk_get_enabled(&pdev->dev, "wdt"); if (IS_ERR(wdt_clk)) return PTR_ERR(wdt_clk); =20 - wdt_freq =3D clk_get_rate(wdt_clk); - if (!wdt_freq) + wdt->freq =3D clk_get_rate(wdt_clk); + if (!wdt->freq) return -EINVAL; =20 - max_timeout =3D (0xfffffffful / wdt_freq); - if (timeout < 1 || timeout > max_timeout) { - timeout =3D max_timeout; - dev_info(&pdev->dev, - "timeout value must be 0 < timeout < %d, using %d\n", - max_timeout, timeout); - } - - ctrl =3D ath79_wdt_rr(WDOG_REG_CTRL); - boot_status =3D (ctrl & WDOG_CTRL_LAST_RESET) ? WDIOF_CARDRESET : 0; + wdt->wdd.max_timeout =3D U32_MAX / wdt->freq; =20 - err =3D misc_register(&ath79_wdt_miscdev); - if (err) { - dev_err(&pdev->dev, - "unable to register misc device, err=3D%d\n", err); - return err; - } + ctrl =3D ath79_wdt_rr(wdt, WDOG_REG_CTRL); + wdt->wdd.bootstatus =3D (ctrl & WDOG_CTRL_LAST_RESET) ? WDIOF_CARDRESET := 0; =20 - return 0; -} + wdt->wdd.info =3D &ath79_wdt_info; + wdt->wdd.ops =3D &ath79_wdt_ops; + wdt->wdd.min_timeout =3D 1; + wdt->wdd.timeout =3D WDT_TIMEOUT; + watchdog_init_timeout(&wdt->wdd, timeout, &pdev->dev); + watchdog_set_nowayout(&wdt->wdd, nowayout); + watchdog_stop_on_reboot(&wdt->wdd); =20 -static void ath79_wdt_remove(struct platform_device *pdev) -{ - misc_deregister(&ath79_wdt_miscdev); -} + watchdog_set_drvdata(&wdt->wdd, wdt); =20 -static void ath79_wdt_shutdown(struct platform_device *pdev) -{ - ath79_wdt_disable(); + return devm_watchdog_register_device(&pdev->dev, &wdt->wdd); } =20 static const struct of_device_id ath79_wdt_match[] =3D { @@ -303,8 +207,6 @@ MODULE_DEVICE_TABLE(of, ath79_wdt_match); =20 static struct platform_driver ath79_wdt_driver =3D { .probe =3D ath79_wdt_probe, - .remove =3D ath79_wdt_remove, - .shutdown =3D ath79_wdt_shutdown, .driver =3D { .name =3D DRIVER_NAME, .of_match_table =3D ath79_wdt_match, @@ -314,7 +216,7 @@ static struct platform_driver ath79_wdt_driver =3D { module_platform_driver(ath79_wdt_driver); =20 MODULE_DESCRIPTION("Atheros AR71XX/AR724X/AR913X hardware watchdog driver"= ); -MODULE_AUTHOR("Gabor Juhos "); +MODULE_AUTHOR("Imre Kaloz "); MODULE_LICENSE("GPL v2"); MODULE_ALIAS("platform:" DRIVER_NAME); --=20 2.54.0