From patchwork Wed Nov 18 00:50:48 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Siyuan X-Patchwork-Id: 4153 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 6B4121C5E0F for ; Wed, 18 Nov 2026 01:51:24 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=163.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-27806-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-27806-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 7057B3D921 for ; Wed, 18 Nov 2026 00:51:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1794963081; b=yR9+5OW3VOaa+qij/fOsiXnjIrtquRtfzAfTjsejDujCqKJZLIvoHvSXkkDkGnrWCfT2 zTCa3DsT/osI/tE87UQ7AkWIcJw090MNV4+m4gnOhDH3PUqV2Gov+/R9/hgsQvq4dCUDT xO6Ou6AJ78rH5w8TbzUVX2G8QK/bxGKCv1gailjq0x/NYcEYjfZ81YOHLefCI6/GxoNZk R//KR0fUp5Xk932lUiKGuYI5ZzMu9xOZn50wufLudwM4+tfkhGjA1IKmJKgzQlI6PzWpR o3pfAF17NXuMclQ+rSajo0MVAbT7S/9o+u5H5y/oBYCMydiiEQ0a88sD1p1gPz9POPA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794963081; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:From:To: Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=E+RsS1tq+kLfqFUPfdWPYkZYK/Z9niwBH23LyHoXUfs=; b=dNDHbLG2LyWLhML01SilGwSvNNYQrFy/8yuowYw+MWqpl+fmKblIdXzBQLHyzX/HgIV4 5m8fFPz/aL2PGS7LrCWieYOx0DgraEE5niwJ/R4v0El7qrPCX8T8LaJjMqihhWmSJ3BkF Lkb2X7Ss4y/JySZrpQfhtw0WqBrpPNZUisT193NulrFWnuGHvRlNmzM3VosOy0yrEu0oy dJX01zBhZZD9WXH3RJxXwtBmKlI/qhH3q0iMTCzXuhcID4o//+d4dSexnLrLrPB8CZQPh yVvhFs8NjXX1y1quWWej3u+E0PLM/7rt92zW2WTnJhCq/RfU6Yq9ynKVKvvH7teyJ0Q== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b="bG+Ue8f/"; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; arc=fail smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9BC3606A32C; Wed, 18 Nov 2026 00:51:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=bG+Ue8f/ X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.3 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794963081; b=jmWnXO+IkyWGjg08IWyCVpUnW3iC5L1ckRISDUTnpBAjPZcYdUDDA4hAjusITl/DKcNu hZTOzABMU3Xny8lsr7AivRFOV7UTm7T6FK6TWBDcW7jhkCcVQVEvRugg5nTJl0QNO9lV/ ZBB0UZzKeMi8lzH4mxVZtMqpJwDuEejMWM1wZT6gnVZkzTy7Hi+IshP64F6FCy+4huAIx Mo+Gif8fI+vPReaKK1/9pwntm3M6bN4jARkLMWByo7jvZz+piBBfIgYPL+dbDSCKCS9iY fs/15pIGEP2gcRJp9cESxDH0Pq+tjHS9ji0lGPbpi8mCTR8jcYGucmaT5Z85MEr6ZTQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794963081; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-Originating-IP:X-CM-SenderInfo; bh=E+RsS1tq+kLfqFUPfdWPYkZYK/Z9niwBH23LyHoXUfs=; b=EoFJflN/daf0vIgWX34rgS3B+klzMsurjv28pK+HnFIAGP5fBgVyRW28RdROYqwA5tk9 O/w0ihQd22uya+rejdXsQ0QEQt0s/88xocdxkV1elubsAWUXhqY9MiWD5qYgLHg786Gaa fFSg1oDoSyfd/QQ5KJVSM9KxZR1Cw5OtUkwLalKi1qgAAG0ckdW2TOdxSG6jOLOx4+38A 8Ux73sIdI8XRJ+GSnoRxu+rU9MZJlWd9Qf1TBIveJ/UfvV1AePotlptJeItr2IHt2N+5N 0amFCsazW6Bwv+r8JCKclmSQvTeYeeiybZOfunKxbsvjeV01aMyfI8jbH+n1UPTjp3w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b="bG+Ue8f/"; arc=none smtp.remote-ip=220.197.31.3 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7C72606A31C for ; Wed, 18 Nov 2026 00:51:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B7C72606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=E+ RsS1tq+kLfqFUPfdWPYkZYK/Z9niwBH23LyHoXUfs=; b=bG+Ue8f/UZ5gtZAA+S Cfs1vGehNw0RAcWGiRrj0YkI3g4WPMgDuC44WvS4aFS+swNndP7XBUxl0N2m8fln CeP8a5WqncCJDI+hrMhqhK+dr0ugt0/PVQOgWmcHzzQTMXt+ETvqFzJgmfol3sxy pAtwybU1J3AVMga+Yh7MMQavU= Received: from SYPC (unknown []) by gzsmtp4 (Coremail) with SMTP id PygvCgBHsYd49vxqwTllGg--.46287S2; Wed, 18 Nov 2026 08:51:05 +0800 (CST) From: Yang Siyuan To: Wim Van Sebroeck , Guenter Roeck Cc: linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4] watchdog: sunxi_wdt: stop the watchdog across system suspend Date: Wed, 18 Nov 2026 08:50:48 +0800 Message-ID: <20261118005048.385059-1-hsyysy@163.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: References: X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-CM-TRANSID: PygvCgBHsYd49vxqwTllGg--.46287S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxCr1rury5ZF1ktF1UXF1UZFb_yoWrGr43pF 4Yya4FkrW0qr4avr4aywnrAFn5G3ZYg34UAryxG34fA3Z8Gr1rGFy0qr1UAwsxGrWrGF1r uF1Ut3yxGayq9a7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jVYLkUUUUU= X-CM-SenderInfo: 5kv152r16rljoofrz/xtbC7Rm16Wr89nkdMgAA3e X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [4.31 / 15.00]; RBL_SENDERSCORE(2.00)[172.105.105.114:from]; ARC_REJECT(1.00)[cv is fail on i=2]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; RCVD_COUNT_FIVE(0.00)[5]; R_DKIM_ALLOW(0.00)[163.com:s=s110527]; FROM_HAS_DN(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,220.197.31.3:received]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:helo,tor.lore.kernel.org:rdns]; TAGGED_FROM(0.00)[bounces-27806-noreply=patchwork.local]; FROM_NEQ_ENVFROM(0.00)[hsyysy@163.com,linux-sunxi@lists.linux.dev]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; RCVD_TLS_LAST(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114]; FREEMAIL_FROM(0.00)[163.com]; TO_DN_SOME(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_FIVE(0.00)[6]; DMARC_POLICY_ALLOW(0.00)[163.com,none]; DKIM_TRACE(0.00)[163.com:+]; MIME_TRACE(0.00)[0:+]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from] X-Rspamd-Queue-Id: 6B4121C5E0F X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX The H616 watchdog has a maximum timeout of 16 seconds. systemd keeps /dev/watchdog0 open with RuntimeWatchdogSec=16s, but during system suspend all userspace is frozen and the watchdog core does not stop the hardware. A suspend longer than the timeout therefore resets the board before it can resume. Add system sleep PM ops to stop the watchdog before suspend and restart it after resume if it was running. The driver did not store its private data in the platform device, so add platform_set_drvdata() for the PM callbacks. Use DEFINE_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr(), and use watchdog_hw_running() instead of a private flag to decide whether the hardware needs to be stopped and restarted. Tested on an Anbernic RG35XX-SP: a 30-second s2idle suspend resumes without the 16-second watchdog reset, and /dev/watchdog0 keeps working afterwards. Signed-off-by: Yang Siyuan --- Changes in v4: - Drop __maybe_unused again. The W=1 report was against v1, which used SET_SYSTEM_SLEEP_PM_OPS(); that macro expands to nothing when CONFIG_PM_SLEEP=n, so the callbacks were unused. v2 already replaced it with DEFINE_SIMPLE_DEV_PM_OPS(), whose SYSTEM_SLEEP_PM_OPS() takes the callback addresses through pm_sleep_ptr() even with CONFIG_PM_SLEEP=n, so the functions are never unused. The v3 change is reverted in v4. Changes in v3: - Mark the PM callbacks __maybe_unused, in response to a W=1 report that turned out to be against v1. Reverted in v4. Changes in v2: - Use DEFINE_SIMPLE_DEV_PM_OPS()/pm_sleep_ptr() to avoid unused-function warnings with CONFIG_PM_SLEEP=n. - Use watchdog_hw_running() instead of tracking running_at_suspend. - Drop the inaccurate ping-worker reference from the comment. drivers/watchdog/sunxi_wdt.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3 diff --git a/drivers/watchdog/sunxi_wdt.c b/drivers/watchdog/sunxi_wdt.c index a6500eb..3fdc7bf 100644 --- a/drivers/watchdog/sunxi_wdt.c +++ b/drivers/watchdog/sunxi_wdt.c @@ -225,6 +225,35 @@ static int sunxi_wdt_start(struct watchdog_device *wdt_dev) return 0; } +/* + * The hardware watchdog has a maximum timeout of 16 seconds. A system + * suspend easily lasts longer than that, and the watchdog core does not + * stop the hardware during system sleep. Stop the watchdog explicitly + * while suspended and re-arm it on resume if it was running. + */ +static int sunxi_wdt_suspend(struct device *dev) +{ + struct sunxi_wdt_dev *sunxi_wdt = dev_get_drvdata(dev); + + if (watchdog_hw_running(&sunxi_wdt->wdt_dev)) + sunxi_wdt_stop(&sunxi_wdt->wdt_dev); + + return 0; +} + +static int sunxi_wdt_resume(struct device *dev) +{ + struct sunxi_wdt_dev *sunxi_wdt = dev_get_drvdata(dev); + + if (watchdog_hw_running(&sunxi_wdt->wdt_dev)) + sunxi_wdt_start(&sunxi_wdt->wdt_dev); + + return 0; +} + +static DEFINE_SIMPLE_DEV_PM_OPS(sunxi_wdt_pm_ops, + sunxi_wdt_suspend, sunxi_wdt_resume); + static const struct watchdog_info sunxi_wdt_info = { .identity = DRV_NAME, .options = WDIOF_SETTIMEOUT | @@ -307,6 +336,8 @@ static int sunxi_wdt_probe(struct platform_device *pdev) if (IS_ERR(sunxi_wdt->wdt_base)) return PTR_ERR(sunxi_wdt->wdt_base); + platform_set_drvdata(pdev, sunxi_wdt); + sunxi_wdt->wdt_dev.info = &sunxi_wdt_info; sunxi_wdt->wdt_dev.ops = &sunxi_wdt_ops; sunxi_wdt->wdt_dev.timeout = WDT_MAX_TIMEOUT; @@ -348,6 +379,7 @@ static struct platform_driver sunxi_wdt_driver = { .driver = { .name = DRV_NAME, .of_match_table = sunxi_wdt_dt_ids, + .pm = pm_sleep_ptr(&sunxi_wdt_pm_ops), }, };