From patchwork Mon Sep 22 20:55:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: j.uzycki@elproma.com.pl X-Patchwork-Id: 4950381 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 066719F2BB for ; Mon, 22 Sep 2014 20:56:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3F7902024F for ; Mon, 22 Sep 2014 20:56:15 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E782E2014A for ; Mon, 22 Sep 2014 20:56:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XWAcP-0001El-OW; Mon, 22 Sep 2014 20:53:57 +0000 Received: from v032797.home.net.pl ([89.161.177.31]) by bombadil.infradead.org with smtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XWAcG-0001BJ-GZ for linux-arm-kernel@lists.infradead.org; Mon, 22 Sep 2014 20:53:49 +0000 Received: from ip-78-133-172-40.ibd.gtsenergis.pl [78.133.172.40] (HELO ip165.elproma.lan) by elproma.home.pl [89.161.177.31] with SMTP (IdeaSmtpServer v0.80) id cebe48213b89efc8; Mon, 22 Sep 2014 22:53:19 +0200 From: Janusz Uzycki To: Guenter Roeck Subject: [PATCH 5/6] watchdog: suspend/resume PM helper Date: Mon, 22 Sep 2014 22:55:49 +0200 Message-Id: <1411419350-1297-5-git-send-email-j.uzycki@elproma.com.pl> X-Mailer: git-send-email 1.7.11.3 In-Reply-To: <1411419350-1297-1-git-send-email-j.uzycki@elproma.com.pl> References: <1411419350-1297-1-git-send-email-j.uzycki@elproma.com.pl> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140922_135348_741189_E408EE98 X-CRM114-Status: UNSURE ( 7.86 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) Cc: Wim Van Sebroeck , Janusz Uzycki , linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The helper replaces watchdog_active() condition usually used in device-specific drivers for PM support. It also solves race between ping timer and driver-specific suspend function. Signed-off-by: Janusz Uzycki --- drivers/watchdog/watchdog_dev.c | 38 +++++++++++++++++++++++++++ include/linux/watchdog.h | 4 +++ 2 files changed, 42 insertions(+) diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index d289eab..2df88b7 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -311,6 +311,44 @@ static void watchdog_keepon_stop(struct watchdog_device *wdd) } /* + * watchdog_suspend: deactivate ping timer if enabled and + * stop the watchdog if active + * @wdd: the watchdog device to do the suspend on + */ +void watchdog_suspend(struct watchdog_device *wdd) +{ + if (test_bit(WDOG_UNREGISTERED, &wdd->status)) + return; + + if (test_bit(WDOG_KEEP_ON, &wdd->status) && + !test_bit(WDOG_DEV_OPEN, &wdd->status)) + del_timer_sync(&wdd->ping_timer); + + if (watchdog_active(wdd)) + wdd->ops->stop(wdd); +} +EXPORT_SYMBOL_GPL(watchdog_suspend); + +/* + * watchdog_resume: start the watchdog if it was active + * and activate ping timer if it was enabled + * @wdd: the watchdog device to do the resume on + */ +void watchdog_resume(struct watchdog_device *wdd) +{ + if (test_bit(WDOG_UNREGISTERED, &wdd->status)) + return; + + if (watchdog_active(wdd)) + wdd->ops->start(wdd); + + if (test_bit(WDOG_KEEP_ON, &wdd->status) && + !test_bit(WDOG_DEV_OPEN, &wdd->status)) + watchdog_ping_timer_cb((unsigned long)wdd); +} +EXPORT_SYMBOL_GPL(watchdog_resume); + +/* * watchdog_write: writes to the watchdog. * @file: file from VFS * @data: user address of data diff --git a/include/linux/watchdog.h b/include/linux/watchdog.h index 650e0d5..eee1b65 100644 --- a/include/linux/watchdog.h +++ b/include/linux/watchdog.h @@ -147,4 +147,8 @@ extern int watchdog_init_timeout(struct watchdog_device *wdd, extern int watchdog_register_device(struct watchdog_device *); extern void watchdog_unregister_device(struct watchdog_device *); +/* drivers/watchdog/watchdog_dev.c */ +extern void watchdog_suspend(struct watchdog_device *); +extern void watchdog_resume(struct watchdog_device *); + #endif /* ifndef _LINUX_WATCHDOG_H */