From patchwork Fri Jul 18 07:34:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 4581341 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 7D74F9F1D6 for ; Fri, 18 Jul 2014 07:37:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A8817201BA for ; Fri, 18 Jul 2014 07:37:29 +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 C6EA42017D for ; Fri, 18 Jul 2014 07:37:28 +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 1X82he-0008QE-7w; Fri, 18 Jul 2014 07:35:38 +0000 Received: from mail-pd0-x22c.google.com ([2607:f8b0:400e:c02::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X82hC-0006uz-CC for linux-arm-kernel@lists.infradead.org; Fri, 18 Jul 2014 07:35:11 +0000 Received: by mail-pd0-f172.google.com with SMTP id ft15so4565291pdb.31 for ; Fri, 18 Jul 2014 00:34:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=qfsE6k3pf4Aabru3X1k5Pr91r4we/HG7RKdU7hBAMgk=; b=UODltAJWQ/LCDNlp2n8TNoqTK0sSrBhfXa+mb2Na4S1OMuT3hRwyClqsXG9jZUJhkY Pvpmjmr/YmAv0ehtFlEynVvHwHSVDLKfGzxIfAflcFQmjubj4/14hqHUCxZpBef6c7xm dwrc1zgbMuWEzH4wrGNBihvkxuoxev5tb6aM6U8zyGPlJV4hqdhGTOS7RXplLNViqWAn guKsI0ikeZ8KyReSx/BZ/VOjJxkjnIaYR5EXb/VflQvvNl5LfIXpwFRcAih8hbQi3/4F RKMb/lKL5LBYaja8cv58Jcts6u+n0n9xAHRSFq4X3KiYVR7tNHw7MNXQ6Q1KcjcVax7P J2VA== X-Received: by 10.66.138.48 with SMTP id qn16mr424718pab.152.1405668889444; Fri, 18 Jul 2014 00:34:49 -0700 (PDT) Received: from localhost (108-223-40-66.lightspeed.sntcca.sbcglobal.net. [108.223.40.66]) by mx.google.com with ESMTPSA id cv2sm4664603pbc.34.2014.07.18.00.34.47 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 18 Jul 2014 00:34:48 -0700 (PDT) From: Guenter Roeck To: linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 6/7] watchdog: alim7101: Register restart handler with kernel restart handler Date: Fri, 18 Jul 2014 00:34:15 -0700 Message-Id: <1405668856-13738-7-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1405668856-13738-1-git-send-email-linux@roeck-us.net> References: <1405668856-13738-1-git-send-email-linux@roeck-us.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140718_003510_473850_908D2CA9 X-CRM114-Status: GOOD ( 17.41 ) X-Spam-Score: -0.4 (/) Cc: Ingo Molnar , Russell King , Heiko Stuebner , Arnd Bergmann , linux-doc@vger.kernel.org, Dmitry Eremin-Solenikov , Catalin Marinas , Tomasz Figa , Randy Dunlap , Will Deacon , linux-kernel@vger.kernel.org, Steven Rostedt , Jonas Jensen , Wim Van Sebroeck , Maxime Ripard , David Woodhouse , Andrew Morton , Guenter Roeck 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=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no 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 kernel core now provides an API to trigger a system restart. Register with it to restart the system instead of misusing the reboot notifier. Signed-off-by: Guenter Roeck --- v5: Function and variable renames: *notifier -> *handler v4: Set restart notifier priority to 128. v3: No change v2: No change drivers/watchdog/alim7101_wdt.c | 42 +++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/drivers/watchdog/alim7101_wdt.c b/drivers/watchdog/alim7101_wdt.c index 996b2f7..665e0e7 100644 --- a/drivers/watchdog/alim7101_wdt.c +++ b/drivers/watchdog/alim7101_wdt.c @@ -301,6 +301,28 @@ static struct miscdevice wdt_miscdev = { .fops = &wdt_fops, }; +static int wdt_restart_handle(struct notifier_block *this, unsigned long mode, + void *cmd) +{ + /* + * Cobalt devices have no way of rebooting themselves other + * than getting the watchdog to pull reset, so we restart the + * watchdog on reboot with no heartbeat. + */ + wdt_change(WDT_ENABLE); + + /* loop until the watchdog fires */ + while (true) + ; + + return NOTIFY_DONE; +} + +static struct notifier_block wdt_restart_handler = { + .notifier_call = wdt_restart_handle, + .priority = 128, +}; + /* * Notifier for system down */ @@ -311,15 +333,6 @@ static int wdt_notify_sys(struct notifier_block *this, if (code == SYS_DOWN || code == SYS_HALT) wdt_turnoff(); - if (code == SYS_RESTART) { - /* - * Cobalt devices have no way of rebooting themselves other - * than getting the watchdog to pull reset, so we restart the - * watchdog on reboot with no heartbeat - */ - wdt_change(WDT_ENABLE); - pr_info("Watchdog timer is now enabled with no heartbeat - should reboot in ~1 second\n"); - } return NOTIFY_DONE; } @@ -338,6 +351,7 @@ static void __exit alim7101_wdt_unload(void) /* Deregister */ misc_deregister(&wdt_miscdev); unregister_reboot_notifier(&wdt_notifier); + unregister_restart_handler(&wdt_restart_handler); pci_dev_put(alim7101_pmu); } @@ -390,11 +404,17 @@ static int __init alim7101_wdt_init(void) goto err_out; } + rc = register_restart_handler(&wdt_restart_handler); + if (rc) { + pr_err("cannot register restart handler (err=%d)\n", rc); + goto err_out_reboot; + } + rc = misc_register(&wdt_miscdev); if (rc) { pr_err("cannot register miscdev on minor=%d (err=%d)\n", wdt_miscdev.minor, rc); - goto err_out_reboot; + goto err_out_restart; } if (nowayout) @@ -404,6 +424,8 @@ static int __init alim7101_wdt_init(void) timeout, nowayout); return 0; +err_out_restart: + unregister_restart_handler(&wdt_restart_handler); err_out_reboot: unregister_reboot_notifier(&wdt_notifier); err_out: