From patchwork Thu Mar 26 15:02:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Stefan_Riedm=C3=BCller?= X-Patchwork-Id: 11460331 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BBF526CA for ; Thu, 26 Mar 2020 15:02:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 746E3206F8 for ; Thu, 26 Mar 2020 15:02:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=temperror (0-bit key) header.d=phytec.de header.i=@phytec.de header.b="TPV+j3xY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727889AbgCZPCG (ORCPT ); Thu, 26 Mar 2020 11:02:06 -0400 Received: from mickerik.phytec.de ([195.145.39.210]:46422 "EHLO mickerik.phytec.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727444AbgCZPCF (ORCPT ); Thu, 26 Mar 2020 11:02:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; d=phytec.de; s=a1; c=relaxed/simple; q=dns/txt; i=@phytec.de; t=1585234924; x=1587826924; h=From:Sender:Reply-To:Subject:Date:Message-Id:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=z2mlDmUTVL8bamKSgP9kkGknh9FvkyYg3rvvPm37X4Q=; b=TPV+j3xYLPi/szZNWzSPvj3Qxqy6XFqbU9pzIWY+kiVsdQk7SPqydxOYrVrvc5pk 6Bg/i+jxtn1wEgqbpEwOAKfvQDyje+Ndkr1dBM7jC+FjAZeXHpIxExFOj6i+UMuG gRBT2lreLWnhDVN98uBuNizfGUCe4I3Xy+6d9ldVM2E=; X-AuditID: c39127d2-583ff70000001db9-a4-5e7cc3ecbc8d Received: from idefix.phytec.de (Unknown_Domain [172.16.0.10]) by mickerik.phytec.de (PHYTEC Mail Gateway) with SMTP id 14.1C.07609.CE3CC7E5; Thu, 26 Mar 2020 16:02:04 +0100 (CET) Received: from augenblix2.phytec.de ([172.16.0.56]) by idefix.phytec.de (IBM Domino Release 9.0.1FP7) with ESMTP id 2020032616020393-89374 ; Thu, 26 Mar 2020 16:02:03 +0100 From: Stefan Riedmueller To: Wim Van Sebroeck , Guenter Roeck , Support Opensource Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] watchdog: da9062: Use pre-configured timeout until userspace takes over Date: Thu, 26 Mar 2020 16:02:01 +0100 Message-Id: <20200326150203.371673-1-s.riedmueller@phytec.de> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-MIMETrack: Itemize by SMTP Server on Idefix/Phytec(Release 9.0.1FP7|August 17, 2016) at 26.03.2020 16:02:04, Serialize by Router on Idefix/Phytec(Release 9.0.1FP7|August 17, 2016) at 26.03.2020 16:02:04 X-TNEFEvaluated: 1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprOLMWRmVeSWpSXmKPExsWyRoCBS/fN4Zo4g9VL+C0u75rDZnFj3T52 iycLzzBZ7G29yGzx+OU/ZgdWjxWf9D1WrlnD6rHzewO7x+dNcgEsUVw2Kak5mWWpRfp2CVwZ H28ZFXTxVfzf0s3ewPiSu4uRk0NCwETi3oerjF2MXBxCAlsZJfrvNbJAOOcYJZ7/vcQGUsUm YCSxYFojE0hCRKCNUWLP0VmMIAlmAQeJx3MfgtnCAjES27ZMZgKxWQRUJZq+7GUGsXkFbCWu tLcD2RxA6+QlDh/KgggLSpyc+QRsmYTAFUaJ47d7WCBOEpI4vfgsM8R8bYllC18zT2Dkm4Wk ZxaS1AJGplWMQrmZydmpRZnZegUZlSWpyXopqZsYgYF3eKL6pR2MfXM8DjEycTAeYpTgYFYS 4X0aWRMnxJuSWFmVWpQfX1Sak1p8iFGag0VJnHcDb0mYkEB6YklqdmpqQWoRTJaJg1OqgdHl /zNTM0dh0/goGenJVzQb+/SXnt9puCx0xcaQ7ui5NxL2v5m2MLjv5c9DzMphj9KmJzid2nPI 7W/UuRczgk54ctSYFQJjjnF7ae5Rt39PQndMXffOqvV8uk9X4LZPl1db9z+z6pQ1Fvlgmzxv xoeIL+dexBZY8N9fdaDtzYa2LRMajOI+8CmxFGckGmoxFxUnAgDn9A2bKgIAAA== Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org If the watchdog is already running during probe read back its pre-configured timeout (set e.g. by the bootloader) and use it to ping the watchdog until userspace takes over. Otherwise the default timeout set before might not result in a fast enough ping. Signed-off-by: Stefan Riedmueller --- drivers/watchdog/da9062_wdt.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/watchdog/da9062_wdt.c b/drivers/watchdog/da9062_wdt.c index 0ad15d55071c..6d81b1276b87 100644 --- a/drivers/watchdog/da9062_wdt.c +++ b/drivers/watchdog/da9062_wdt.c @@ -35,6 +35,14 @@ struct da9062_watchdog { bool use_sw_pm; }; +static unsigned int da9062_wdt_read_timeout(struct da9062_watchdog *wdt) +{ + int val; + + regmap_read(wdt->hw->regmap, DA9062AA_CONTROL_D, &val); + return wdt_timeout[val & DA9062AA_TWDSCALE_MASK]; +} + static unsigned int da9062_wdt_timeout_to_sel(unsigned int secs) { unsigned int i; @@ -184,6 +192,7 @@ static int da9062_wdt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; int ret; + int timeout; struct da9062 *chip; struct da9062_watchdog *wdt; @@ -213,6 +222,13 @@ static int da9062_wdt_probe(struct platform_device *pdev) watchdog_set_drvdata(&wdt->wdtdev, wdt); dev_set_drvdata(dev, &wdt->wdtdev); + timeout = da9062_wdt_read_timeout(wdt); + if (timeout > 0) { + wdt->wdtdev.timeout = timeout; + set_bit(WDOG_HW_RUNNING, &wdt->wdtdev.status); + dev_info(wdt->hw->dev, "watchdog is running (%u s)", timeout); + } + ret = devm_watchdog_register_device(dev, &wdt->wdtdev); if (ret < 0) return ret; From patchwork Thu Mar 26 15:02:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Stefan_Riedm=C3=BCller?= X-Patchwork-Id: 11460333 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F7526CA for ; Thu, 26 Mar 2020 15:02:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 711E020B1F for ; Thu, 26 Mar 2020 15:02:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=temperror (0-bit key) header.d=phytec.de header.i=@phytec.de header.b="eznboSLS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727444AbgCZPCG (ORCPT ); Thu, 26 Mar 2020 11:02:06 -0400 Received: from mickerik.phytec.de ([195.145.39.210]:46414 "EHLO mickerik.phytec.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727851AbgCZPCG (ORCPT ); Thu, 26 Mar 2020 11:02:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; d=phytec.de; s=a1; c=relaxed/simple; q=dns/txt; i=@phytec.de; t=1585234924; x=1587826924; h=From:Sender:Reply-To:Subject:Date:Message-Id:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=2Lsi0B9PC9xzPGCjLHInYEh0CJgnpmqkv2nS4RmsyXo=; b=eznboSLSt6P9+0IlJfby1GN8SnglyDilkOYErQTlaBxWgmCz/gK/gug6wJ9Pr1c5 4QqNStoiW3SVcOEwB7ccbLvaWQZKBSEwWl9cEe5NjD/+iDQUfPVEn7+8QEhC8Cx0 Dj+vE4hBFb/CVzkyi0sx8hpg07ry/ZG5k/Y6pSdPm+Q=; X-AuditID: c39127d2-599ff70000001db9-a5-5e7cc3ecf81b Received: from idefix.phytec.de (Unknown_Domain [172.16.0.10]) by mickerik.phytec.de (PHYTEC Mail Gateway) with SMTP id 74.1C.07609.CE3CC7E5; Thu, 26 Mar 2020 16:02:04 +0100 (CET) Received: from augenblix2.phytec.de ([172.16.0.56]) by idefix.phytec.de (IBM Domino Release 9.0.1FP7) with ESMTP id 2020032616020417-89375 ; Thu, 26 Mar 2020 16:02:04 +0100 From: Stefan Riedmueller To: Wim Van Sebroeck , Guenter Roeck , Support Opensource Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] watchdog: da9063: Use pre configured timeout when watchdog is running Date: Thu, 26 Mar 2020 16:02:02 +0100 Message-Id: <20200326150203.371673-2-s.riedmueller@phytec.de> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200326150203.371673-1-s.riedmueller@phytec.de> References: <20200326150203.371673-1-s.riedmueller@phytec.de> MIME-Version: 1.0 X-MIMETrack: Itemize by SMTP Server on Idefix/Phytec(Release 9.0.1FP7|August 17, 2016) at 26.03.2020 16:02:04, Serialize by Router on Idefix/Phytec(Release 9.0.1FP7|August 17, 2016) at 26.03.2020 16:02:04 X-TNEFEvaluated: 1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrPLMWRmVeSWpSXmKPExsWyRoCBS/fN4Zo4g5vtshaXd81hs7ixbh+7 xZOFZ5gs9rZeZLZ4/PIfswOrx4pP+h4r16xh9dj5vYHd4/MmuQCWKC6blNSczLLUIn27BK6M PT++MxdMEq14eqODvYHxmWAXIyeHhICJxLKGFuYuRi4OIYGtjBJPGhczQjjnGCX+NV9kAali EzCSWDCtkQkkISLQxiix5+gsRpAEs4CDxOO5D8FsYYEoiQ1PVzKD2CwCqhLbZi8HauDg4BWw ldj6QB3ElBCQlzh8KAukglPATmLzw11g44WAKvYvbmcHsXkFBCVOznzCArJKQuAKo8Tx2z0s EJcKSZxefJYZYq22xLKFr5knMArMQtIzC0lqASPTKkah3Mzk7NSizGy9gozKktRkvZTUTYzA QD08Uf3SDsa+OR6HGJk4GA8xSnAwK4nwPo2siRPiTUmsrEotyo8vKs1JLT7EKM3BoiTOu4G3 JExIID2xJDU7NbUgtQgmy8TBKdXA2KVx0N9Rgq+gy1y47/nM5VYT9hjfsJ9Y4Lr/nvbLKdXn +ALDzsQ6NHdvNmwpZQm4tl6x0MTkAkexbZnIrGqXN9IHzNn9Sz5mmb7PSV6tb57r1ZjkYzJV fO4L7YBXv6zmTvmscVhzS7Hul/KZv1lOHZW8EnLokejxrJSn5lVcTI3T/CdXl/xTYinOSDTU Yi4qTgQA2GarKUICAAA= Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org If the watchdog is already running during probe use its pre-configured timeout instead of a default timeout to make sure the watchdog is pinged in time until userspace takes over. Signed-off-by: Stefan Riedmueller --- drivers/watchdog/da9063_wdt.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/watchdog/da9063_wdt.c b/drivers/watchdog/da9063_wdt.c index 3d65e92a4e3f..34d0c4f03814 100644 --- a/drivers/watchdog/da9063_wdt.c +++ b/drivers/watchdog/da9063_wdt.c @@ -46,15 +46,16 @@ static unsigned int da9063_wdt_timeout_to_sel(unsigned int secs) } /* - * Return 0 if watchdog is disabled, else non zero. + * Read the currently active timeout. + * Zero means the watchdog is disabled. */ -static unsigned int da9063_wdt_is_running(struct da9063 *da9063) +static unsigned int da9063_wdt_read_timeout(struct da9063 *da9063) { unsigned int val; regmap_read(da9063->regmap, DA9063_REG_CONTROL_D, &val); - return val & DA9063_TWDSCALE_MASK; + return wdt_timeout[val & DA9063_TWDSCALE_MASK]; } static int da9063_wdt_disable_timer(struct da9063 *da9063) @@ -191,6 +192,7 @@ static int da9063_wdt_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct da9063 *da9063; struct watchdog_device *wdd; + int timeout; if (!dev->parent) return -EINVAL; @@ -214,15 +216,20 @@ static int da9063_wdt_probe(struct platform_device *pdev) watchdog_set_restart_priority(wdd, 128); watchdog_set_drvdata(wdd, da9063); - /* Set default timeout, maybe override it with DT value, scale it */ - wdd->timeout = DA9063_WDG_TIMEOUT; - watchdog_init_timeout(wdd, 0, dev); - da9063_wdt_set_timeout(wdd, wdd->timeout); - - /* Change the timeout to the default value if the watchdog is running */ - if (da9063_wdt_is_running(da9063)) { - da9063_wdt_update_timeout(da9063, wdd->timeout); + /* + * Use pre-configured timeout if watchdog is already running. + * Otherwise set default timeout, maybe override it with DT value, + * scale it + */ + timeout = da9063_wdt_read_timeout(da9063); + if (timeout) { + wdd->timeout = timeout; set_bit(WDOG_HW_RUNNING, &wdd->status); + dev_info(da9063->dev, "watchdog is running (%u s)", timeout); + } else { + wdd->timeout = DA9063_WDG_TIMEOUT; + watchdog_init_timeout(wdd, 0, dev); + da9063_wdt_set_timeout(wdd, wdd->timeout); } return devm_watchdog_register_device(dev, wdd); From patchwork Thu Mar 26 15:02:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Stefan_Riedm=C3=BCller?= X-Patchwork-Id: 11460335 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E552A6CA for ; Thu, 26 Mar 2020 15:02:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C4ED3206F8 for ; Thu, 26 Mar 2020 15:02:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=temperror (0-bit key) header.d=phytec.de header.i=@phytec.de header.b="g2hoOhE/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726496AbgCZPCM (ORCPT ); Thu, 26 Mar 2020 11:02:12 -0400 Received: from mickerik.phytec.de ([195.145.39.210]:46422 "EHLO mickerik.phytec.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727851AbgCZPCH (ORCPT ); Thu, 26 Mar 2020 11:02:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; d=phytec.de; s=a1; c=relaxed/simple; q=dns/txt; i=@phytec.de; t=1585234924; x=1587826924; h=From:Sender:Reply-To:Subject:Date:Message-Id:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZtaKUFL4WFPqauqkay4ZKL991OIGk+dXJk8/oBMqrxM=; b=g2hoOhE/uF2KCdfKa2xcZv4hOkncq+ytoBl8JK7seW5JWgwrhwfEgnDo/tHacGu+ GjMGxETN0Efe1/h/QtaLdYJs2ityWdE6S1uFrClSN+OEjcIBttPY79xRCqq23NXF yPRUNnMZhTk60FqR6ilFGTofofaoAXjvkmPY1KifumA=; X-AuditID: c39127d2-583ff70000001db9-a6-5e7cc3ec7c4b Received: from idefix.phytec.de (Unknown_Domain [172.16.0.10]) by mickerik.phytec.de (PHYTEC Mail Gateway) with SMTP id D4.1C.07609.CE3CC7E5; Thu, 26 Mar 2020 16:02:04 +0100 (CET) Received: from augenblix2.phytec.de ([172.16.0.56]) by idefix.phytec.de (IBM Domino Release 9.0.1FP7) with ESMTP id 2020032616020440-89376 ; Thu, 26 Mar 2020 16:02:04 +0100 From: Stefan Riedmueller To: Wim Van Sebroeck , Guenter Roeck , Support Opensource Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] watchdog: da9062: No need to ping manually before setting timeout Date: Thu, 26 Mar 2020 16:02:03 +0100 Message-Id: <20200326150203.371673-3-s.riedmueller@phytec.de> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200326150203.371673-1-s.riedmueller@phytec.de> References: <20200326150203.371673-1-s.riedmueller@phytec.de> MIME-Version: 1.0 X-MIMETrack: Itemize by SMTP Server on Idefix/Phytec(Release 9.0.1FP7|August 17, 2016) at 26.03.2020 16:02:04, Serialize by Router on Idefix/Phytec(Release 9.0.1FP7|August 17, 2016) at 26.03.2020 16:02:04 X-TNEFEvaluated: 1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrALMWRmVeSWpSXmKPExsWyRoCBS/fN4Zo4g0fXNS0u75rDZnFj3T52 iycLzzBZ7G29yGzx+OU/ZgdWjxWf9D1WrlnD6rHzewO7x+dNcgEsUVw2Kak5mWWpRfp2CVwZ N47cZiw4yllxsP0yWwPjB/YuRk4OCQETia0/pzN1MXJxCAlsZZR4//YYC4RzjlFi4vKHrCBV bAJGEgumNYJViQi0MUrsOTqLESTBLOAg8XjuQzBbWCBMYu+kVWA2i4CqxJ7OW0wgNq+ArcTH SW1AUzmA1slLHD6UBRLmFLCT2PxwFwuILQRUsn9xOztEuaDEyZlPwI6QELjCKHH8dg8LxKlC EqcXn2WG2KstsWzha+YJjAKzkPTMQpJawMi0ilEoNzM5O7UoM1uvIKOyJDVZLyV1EyMwVA9P VL+0g7FvjschRiYOxkOMEhzMSiK8TyNr4oR4UxIrq1KL8uOLSnNSiw8xSnOwKInzbuAtCRMS SE8sSc1OTS1ILYLJMnFwSjUwrn7TzZe1d41X96Swf29qHJmjGGpasmN2+B9n3Ca1eOo1d+md ZUoi81YYXL6/8FOM0iztbP63z+ZevMjnuUb7c13tJZ0lDpeOnSho1N3umCCtF/OdWyhehdPx tcSutu9hJu/vzlp3p4/XZfW1BzvfOrwxarjnunLL2enht/m52YOv/65fzeLopMRSnJFoqMVc VJwIANV+3R9DAgAA Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org There is actually no need to ping the watchdog before disabling it during timeout change. Disabling the watchdog already takes care of resetting the counter. This fixes an issue during boot when the userspace watchdog handler takes over and the watchdog is already running. Opening the watchdog in this case leads to the first ping and directly after that without the required heartbeat delay a second ping issued by the set_timeout call. Due to the missing delay this resulted in a reset. Signed-off-by: Stefan Riedmueller Reviewed-by: Guenter Roeck Reviewed-by: Adam Thomson --- drivers/watchdog/da9062_wdt.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/watchdog/da9062_wdt.c b/drivers/watchdog/da9062_wdt.c index 6d81b1276b87..c5bd075c8b14 100644 --- a/drivers/watchdog/da9062_wdt.c +++ b/drivers/watchdog/da9062_wdt.c @@ -66,11 +66,6 @@ static int da9062_wdt_update_timeout_register(struct da9062_watchdog *wdt, unsigned int regval) { struct da9062 *chip = wdt->hw; - int ret; - - ret = da9062_reset_watchdog_timer(wdt); - if (ret) - return ret; regmap_update_bits(chip->regmap, DA9062AA_CONTROL_D,