Received: by 10.223.185.116 with SMTP id b49csp2367360wrg; Thu, 15 Feb 2018 10:29:54 -0800 (PST) X-Google-Smtp-Source: AH8x227cnKgLE5CQjjrQr4+aCz4skIPqT7eMSuAv5N7qIhMHwGftzt7I4T4ANREU+6aIZRDRHztc X-Received: by 10.99.164.74 with SMTP id c10mr2912532pgp.409.1518719394442; Thu, 15 Feb 2018 10:29:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518719394; cv=none; d=google.com; s=arc-20160816; b=M/SwuajHmzhZhjE7w4H41otQpaKXFaJNNZFx/jllHc72LmcOIECNSSpGz369CgA9qo C9Z0GW2R7Dsx/Hng7JxNm9IReKj4ILzYIypDV+m1F24N4X336U6Bb0xs/REb8KdivN5C +zVN8Pg/z2FOaI8hZxbwVokUg5HPK4JXG3j9FNsJUw/rMAz1DapGJH946dAEs1VQIZkQ QFyQajfaWUkveUy0RbuoAJEMNFwIyu+fkfJjngODgKAjml17aplMUbwQNeq2cvW7xtjx 7p+2TpVJ/jd/Ezytwmomp9SYOrkMSYyTMxBergVOs41cxvHeJ0dil8O4fbWPx9FAFubP /A4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=E7l+LNZ6s9fh1Q945KSaL37nRuSQ0dsfH3iiKqipKCU=; b=0EEUPBo4Ih+vO4411hB4bGV5//rDBa4L8IdAHAt8W0MUyHGEP/6fO8BT6/HAY5Xo70 h70cD73XidCTeL/2AfDiL2Ay+xL80f7bahebjrvpiL2wlLqVJ71BNtKqA1PzzQzv3BB+ TN5QgnvYa3ErtL1sYWRA9Lh51iJ3RP7lfjoI7nCTxWISE0EkKwAa8qsWUBh3aCeZJ4yF vRYzHWGCwEa75qEq+5Eadao4pL+UkY38UzdBzfF/dWdCRlUh2r6a5nXBsODqlegi/xOu vMHSw2WhoPAoVVI4vU60xQl27T4Sx/yVfddeI4M5QR+f21gjkPNT/pvV5jsTrNSgDbuY r96w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w4si2683477pgq.199.2018.02.15.10.29.39; Thu, 15 Feb 2018 10:29:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1166447AbeBOS1o (ORCPT + 99 others); Thu, 15 Feb 2018 13:27:44 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:52336 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163208AbeBOPZj (ORCPT ); Thu, 15 Feb 2018 10:25:39 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C939E111C; Thu, 15 Feb 2018 15:25:38 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Martin Kaiser , Guenter Roeck , Wim Van Sebroeck Subject: [PATCH 4.4 088/108] watchdog: imx2_wdt: restore previous timeout after suspend+resume Date: Thu, 15 Feb 2018 16:17:25 +0100 Message-Id: <20180215151234.633840297@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151222.267507937@linuxfoundation.org> References: <20180215151222.267507937@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Martin Kaiser commit 0be267255cef64e1c58475baa7b25568355a3816 upstream. When the watchdog device is suspended, its timeout is set to the maximum value. During resume, the previously set timeout should be restored. This does not work at the moment. The suspend function calls imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME); and resume reverts this by calling imx2_wdt_set_timeout(wdog, wdog->timeout); However, imx2_wdt_set_timeout() updates wdog->timeout. Therefore, wdog->timeout is set to IMX2_WDT_MAX_TIME when we enter the resume function. Fix this by adding a new function __imx2_wdt_set_timeout() which only updates the hardware settings. imx2_wdt_set_timeout() now calls __imx2_wdt_set_timeout() and then saves the new timeout to wdog->timeout. During suspend, we call __imx2_wdt_set_timeout() directly so that wdog->timeout won't be updated and we can restore the previous value during resume. This approach makes wdog->timeout different from the actual setting in the hardware which is usually not a good thing. However, the two differ only while we're suspended and no kernel code is running, so it should be ok in this case. Signed-off-by: Martin Kaiser Reviewed-by: Guenter Roeck Signed-off-by: Guenter Roeck Signed-off-by: Wim Van Sebroeck Signed-off-by: Greg Kroah-Hartman --- drivers/watchdog/imx2_wdt.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) --- a/drivers/watchdog/imx2_wdt.c +++ b/drivers/watchdog/imx2_wdt.c @@ -161,15 +161,21 @@ static void imx2_wdt_timer_ping(unsigned mod_timer(&wdev->timer, jiffies + wdog->timeout * HZ / 2); } -static int imx2_wdt_set_timeout(struct watchdog_device *wdog, - unsigned int new_timeout) +static void __imx2_wdt_set_timeout(struct watchdog_device *wdog, + unsigned int new_timeout) { struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog); - wdog->timeout = new_timeout; - regmap_update_bits(wdev->regmap, IMX2_WDT_WCR, IMX2_WDT_WCR_WT, WDOG_SEC_TO_COUNT(new_timeout)); +} + +static int imx2_wdt_set_timeout(struct watchdog_device *wdog, + unsigned int new_timeout) +{ + __imx2_wdt_set_timeout(wdog, new_timeout); + + wdog->timeout = new_timeout; return 0; } @@ -353,7 +359,11 @@ static int imx2_wdt_suspend(struct devic /* The watchdog IP block is running */ if (imx2_wdt_is_running(wdev)) { - imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME); + /* + * Don't update wdog->timeout, we'll restore the current value + * during resume. + */ + __imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME); imx2_wdt_ping(wdog); /* The watchdog is not active */