From patchwork Fri Apr 3 13:07:26 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: 11472647 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 5CBDC15AB for ; Fri, 3 Apr 2020 13:07:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 06356207FF for ; Fri, 3 Apr 2020 13:07:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=temperror (0-bit key) header.d=phytec.de header.i=@phytec.de header.b="Q8z5Y0U8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728143AbgDCNHa (ORCPT ); Fri, 3 Apr 2020 09:07:30 -0400 Received: from mickerik.phytec.de ([195.145.39.210]:65370 "EHLO mickerik.phytec.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728117AbgDCNHa (ORCPT ); Fri, 3 Apr 2020 09:07:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; d=phytec.de; s=a1; c=relaxed/simple; q=dns/txt; i=@phytec.de; t=1585919249; x=1588511249; 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=lJci58XPLAs6Gaqe7C4KQCaN7ChYybm9aJTatTD89/A=; b=Q8z5Y0U8BXNp0xVZEafTnl5Bi4I1eFhunmLO8ffrT2HryyaDOOAojd1EMFnEhzUN KT3bG5gWUdwDoSjXgSsRRPj10fGYB26bAofibCs5s5KOc66U7IRpc18TeQsiPKQV W07/7zBIUifJQ01muxgvH7DqXqlcJrqJz7/j9/7hK3g=; X-AuditID: c39127d2-583ff70000001db9-db-5e873511793f Received: from idefix.phytec.de (Unknown_Domain [172.16.0.10]) by mickerik.phytec.de (PHYTEC Mail Gateway) with SMTP id 42.88.07609.115378E5; Fri, 3 Apr 2020 15:07:29 +0200 (CEST) Received: from augenblix2.phytec.de ([172.16.0.56]) by idefix.phytec.de (IBM Domino Release 9.0.1FP7) with ESMTP id 2020040315072879-138368 ; Fri, 3 Apr 2020 15:07:28 +0200 From: Stefan Riedmueller To: Wim Van Sebroeck , Guenter Roeck , Support Opensource Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] watchdog: da9062: Initialize timeout during probe Date: Fri, 3 Apr 2020 15:07:26 +0200 Message-Id: <20200403130728.39260-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 03.04.2020 15:07:28, Serialize by Router on Idefix/Phytec(Release 9.0.1FP7|August 17, 2016) at 03.04.2020 15:07:29 X-TNEFEvaluated: 1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprBLMWRmVeSWpSXmKPExsWyRoCBS1fQtD3O4OUFNovLu+awWdxYt4/d 4snCM0wWe1svMls8fvmP2YHVY8UnfY+Va9aweuz83sDu8XmTXABLFJdNSmpOZllqkb5dAldG 77WtTAV3xCpu/v/B2sD4U6iLkZNDQsBEYu7ym0xdjFwcQgLbGCVuNR1nhXDOMUq8PPCBFaSK TcBIYsG0RrAqEYE2Rok9R2cxgiSYBRwkHs99CGYLC3hKvFwxnxnEZhFQkbg36TIbiM0rYCMx 88BLoGYOoHXyEocPZUGEBSVOznzCAjJTQuAKo8TH32vZIU4Skji9+CwzxHxtiWULXzNPYOSb haRnFpLUAkamVYxCuZnJ2alFmdl6BRmVJanJeimpmxiBoXd4ovqlHYx9czwOMTJxMB5ilOBg VhLhdZzRGifEm5JYWZValB9fVJqTWnyIUZqDRUmcdwNvSZiQQHpiSWp2ampBahFMlomDU6qB cd9prgUWp76IrJ4jtOvbvwfuZz5uyLRQNvWUsM5xyj96SWzSjFWJCY8jIquDhV2VvB4sCw9e +/v3HP2DCm0lrger9M57zH0k8fPaH/EFZkXWW+O8+Ou276+eE8pxmT0xrPaxsuRk1Y6GgvUu Ezuy3Cqb5CvtMkWrk7o3ftHsm7R07uUn/JMslViKMxINtZiLihMBt5iq1CsCAAA= Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org During probe try to set the timeout from device tree and fall back to either the pre-configured timeout set by e.g. the bootloader in case the watchdog is already running or the default value. If the watchdog is already running make sure to update the timeout and tell the framework about the running state to make sure the watchdog is handled correctly until user space takes over. Updating the timeout also removes the need for an additional manual ping so we can remove that as well. Signed-off-by: Stefan Riedmueller Reviewed-by: Adam Thomson Reviewed-by: Guenter Roeck --- Changes in v2: - Reworked the patch to use the pre-configured timeout instead of the default value as a fallback in case no DT value is present. - To achieve the previous point watchdog_init_timeout was added to get the DT value if present. - Added a timeout update if the watchdog is running to set the desired timeout and in this instance removed the manual ping at the end. - Removed info message. --- drivers/watchdog/da9062_wdt.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/watchdog/da9062_wdt.c b/drivers/watchdog/da9062_wdt.c index 0ad15d55071c..10b37dd65bed 100644 --- a/drivers/watchdog/da9062_wdt.c +++ b/drivers/watchdog/da9062_wdt.c @@ -35,6 +35,15 @@ struct da9062_watchdog { bool use_sw_pm; }; +static unsigned int da9062_wdt_read_timeout(struct da9062_watchdog *wdt) +{ + unsigned 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; @@ -183,7 +192,7 @@ MODULE_DEVICE_TABLE(of, da9062_compatible_id_table); static int da9062_wdt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - int ret; + unsigned int timeout; struct da9062 *chip; struct da9062_watchdog *wdt; @@ -213,11 +222,19 @@ static int da9062_wdt_probe(struct platform_device *pdev) watchdog_set_drvdata(&wdt->wdtdev, wdt); dev_set_drvdata(dev, &wdt->wdtdev); - ret = devm_watchdog_register_device(dev, &wdt->wdtdev); - if (ret < 0) - return ret; + timeout = da9062_wdt_read_timeout(wdt); + if (timeout) + wdt->wdtdev.timeout = timeout; + + /* Set timeout from DT value if available */ + watchdog_init_timeout(&wdt->wdtdev, 0, dev); + + if (timeout) { + da9062_wdt_set_timeout(&wdt->wdtdev, wdt->wdtdev.timeout); + set_bit(WDOG_HW_RUNNING, &wdt->wdtdev.status); + } - return da9062_wdt_ping(&wdt->wdtdev); + return devm_watchdog_register_device(dev, &wdt->wdtdev); } static int __maybe_unused da9062_wdt_suspend(struct device *dev) From patchwork Fri Apr 3 13:07:27 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: 11472651 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 A0D1792C for ; Fri, 3 Apr 2020 13:07:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 80C352082F for ; Fri, 3 Apr 2020 13:07:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=temperror (0-bit key) header.d=phytec.de header.i=@phytec.de header.b="N52sW98Q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390855AbgDCNHc (ORCPT ); Fri, 3 Apr 2020 09:07:32 -0400 Received: from mickerik.phytec.de ([195.145.39.210]:65362 "EHLO mickerik.phytec.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390705AbgDCNHc (ORCPT ); Fri, 3 Apr 2020 09:07:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; d=phytec.de; s=a1; c=relaxed/simple; q=dns/txt; i=@phytec.de; t=1585919249; x=1588511249; 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=7PCPdXoL92mweYgm+x4Q95mtPQBQ+j+0qqnoFh5R7x4=; b=N52sW98QargAj4vl2lnNzgePvPcL0gArlb/fH0XKisEZ1Baaj6CK86xmpa0NS2dj TfAWx4Qg5LoNaBvEr7ARloGyakfT4GW3YSRWvSs7qOFuvROOlYvLfH1CRQTXBCN3 75x0CbLvF2DGc6AYO0xIEi00hITVAG4AFTgE0Im0LIw=; X-AuditID: c39127d2-599ff70000001db9-dc-5e873511cfe8 Received: from idefix.phytec.de (Unknown_Domain [172.16.0.10]) by mickerik.phytec.de (PHYTEC Mail Gateway) with SMTP id A2.88.07609.115378E5; Fri, 3 Apr 2020 15:07:29 +0200 (CEST) Received: from augenblix2.phytec.de ([172.16.0.56]) by idefix.phytec.de (IBM Domino Release 9.0.1FP7) with ESMTP id 2020040315072902-138369 ; Fri, 3 Apr 2020 15:07:29 +0200 From: Stefan Riedmueller To: Wim Van Sebroeck , Guenter Roeck , Support Opensource Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] watchdog: da9063: Make use of pre-configured timeout during probe Date: Fri, 3 Apr 2020 15:07:27 +0200 Message-Id: <20200403130728.39260-2-s.riedmueller@phytec.de> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200403130728.39260-1-s.riedmueller@phytec.de> References: <20200403130728.39260-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 03.04.2020 15:07:29, Serialize by Router on Idefix/Phytec(Release 9.0.1FP7|August 17, 2016) at 03.04.2020 15:07:29 X-TNEFEvaluated: 1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrHLMWRmVeSWpSXmKPExsWyRoCBS1fQtD3O4PAbYYvLu+awWdxYt4/d 4snCM0wWe1svMls8fvmP2YHVY8UnfY+Va9aweuz83sDu8XmTXABLFJdNSmpOZllqkb5dAlfG pMvHWAqeilT8evacpYFxtWAXIweHhICJxPeH9l2MXBxCAtsYJbqbO5m7GDmBnHOMEsuWuYHY bAJGEgumNTKBFIkItDFK7Dk6ixEkwSzgIPF47kMwW1ggUmJr7x8wm0VAReLa5bmsIDavgI3E zE/7GCGWyUscPpQFEuYUsJU48X8OO8QuG4n25ZfZIMoFJU7OfMICsktC4AqjxOPHx8CKJASE JE4vPssMsVdbYtnC18wTGAVmIemZhSS1gJFpFaNQbmZydmpRZrZeQUZlSWqyXkrqJkZgmB6e qH5pB2PfHI9DjEwcjIcYJTiYlUR4HWe0xgnxpiRWVqUW5ccXleakFh9ilOZgURLn3cBbEiYk kJ5YkpqdmlqQWgSTZeLglGpgXHAyNebe34v1y96+qt9U+2n676V9T1nYJv7Pfjb3Eq+KnVGY jNwU//uKD25ucLT4vkBEbfcfrrzJixY3G62UOWhU1ekuk/vTZ5XdNgWPD4s+bZvaf2Pv541L dVbsWrLH5cCxybN29QfN9Y+e5rIgOmUlV8ScpliNyLBPi1ZdnKXK/3VzQPUdWU8lluKMREMt 5qLiRABH7JvjQQIAAA== Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org The watchdog might already be running during boot with a timeout set by e.g. the bootloader. Make use of this pre-configured timeout instead of falling back to the default timeout if no device tree value is given. Signed-off-by: Stefan Riedmueller Reviewed-by: Adam Thomson Reviewed-by: Guenter Roeck --- Changes in v2: - Reworked patch to use the pre-configured timeout onyl as a fallback instead of the default value. - Removed info message. --- drivers/watchdog/da9063_wdt.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/watchdog/da9063_wdt.c b/drivers/watchdog/da9063_wdt.c index 3d65e92a4e3f..423584252606 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; + unsigned int timeout; if (!dev->parent) return -EINVAL; @@ -214,13 +216,19 @@ 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; + + /* Use pre-configured timeout if watchdog is already running. */ + timeout = da9063_wdt_read_timeout(da9063); + if (timeout) + wdd->timeout = timeout; + + /* Set timeout, maybe override it with DT value, scale it */ 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)) { + /* Update timeout if the watchdog is already running. */ + if (timeout) { da9063_wdt_update_timeout(da9063, wdd->timeout); set_bit(WDOG_HW_RUNNING, &wdd->status); } From patchwork Fri Apr 3 13:07:28 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: 11472649 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 98B7992C for ; Fri, 3 Apr 2020 13:07:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 771132073B for ; Fri, 3 Apr 2020 13:07:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=temperror (0-bit key) header.d=phytec.de header.i=@phytec.de header.b="AALIoyYL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403865AbgDCNHe (ORCPT ); Fri, 3 Apr 2020 09:07:34 -0400 Received: from mickerik.phytec.de ([195.145.39.210]:65370 "EHLO mickerik.phytec.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728068AbgDCNHd (ORCPT ); Fri, 3 Apr 2020 09:07:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; d=phytec.de; s=a1; c=relaxed/simple; q=dns/txt; i=@phytec.de; t=1585919249; x=1588511249; 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=wbIR5CNO6oJzqk4vJrLuH0uLlsYO4RkeTDpQrai1S9k=; b=AALIoyYLecCMygoglVwR8w7eX7Hz3EH85+HNP0DxRs+e0X4xneemIlw/ubFeUvvH 6Qyx7Sd8PDGRvkIcc4E3GhqyRXQcMDL+Y0TDaanKo98w4CKuZLjmS4SYFgbI66Rl lVE1SFyx0JJNl90hrv7vG7jtZFSPK9CQ82WDyUy21tw=; X-AuditID: c39127d2-583ff70000001db9-dd-5e87351184d5 Received: from idefix.phytec.de (Unknown_Domain [172.16.0.10]) by mickerik.phytec.de (PHYTEC Mail Gateway) with SMTP id 03.88.07609.115378E5; Fri, 3 Apr 2020 15:07:29 +0200 (CEST) Received: from augenblix2.phytec.de ([172.16.0.56]) by idefix.phytec.de (IBM Domino Release 9.0.1FP7) with ESMTP id 2020040315072926-138370 ; Fri, 3 Apr 2020 15:07:29 +0200 From: Stefan Riedmueller To: Wim Van Sebroeck , Guenter Roeck , Support Opensource Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] watchdog: da9062: No need to ping manually before setting timeout Date: Fri, 3 Apr 2020 15:07:28 +0200 Message-Id: <20200403130728.39260-3-s.riedmueller@phytec.de> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200403130728.39260-1-s.riedmueller@phytec.de> References: <20200403130728.39260-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 03.04.2020 15:07:29, Serialize by Router on Idefix/Phytec(Release 9.0.1FP7|August 17, 2016) at 03.04.2020 15:07:29 X-TNEFEvaluated: 1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrHLMWRmVeSWpSXmKPExsWyRoCBS1fQtD3OoP+aosXlXXPYLG6s28du 8WThGSaLva0XmS0ev/zH7MDqseKTvsfKNWtYPXZ+b2D3+LxJLoAlissmJTUnsyy1SN8ugSuj 6edfpoIXXBUNk6azNzD+5ehi5OSQEDCRuPljIzOILSSwjVFiwcPoLkYuIPsco8Supw/AEmwC RhILpjUygSREBNoYJfYcncUIkmAWcJB4PPchkM3BISwQKbHlqztImEVARaKpeSkbiM0rYCNx e+UBsBIJAXmJw4eyQMKcArYSJ/7PYYfYayPRvvwyVLmgxMmZT1hAVkkIXGGUePz4GDvEoUIS pxefZYZYqy2xbOFr5gmMArOQ9MxCklrAyLSKUSg3Mzk7tSgzW68go7IkNVkvJXUTIzBMD09U v7SDsW+OxyFGJg7GQ4wSHMxKIryOM1rjhHhTEiurUovy44tKc1KLDzFKc7AoifNu4C0JExJI TyxJzU5NLUgtgskycXBKNTBq/pUtusUSXL3+V8pJlgl8J1nWBfVxa1nwxb9ezsXMNNciTTZE n+u9TGf53JN5UX+9Cm4f7ir9rXV8UX5Cf+jylu9ccVYlQbMX/ipM+H3crWc3b3f0k1unagx2 qwSxmBfqc+qvqHgkcXZTaYBTwOYOLaE3BWWT071P/s6b5fRiycsZk2fl3lFiKc5INNRiLipO BACci/2VQQIAAA== 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 --- Changes in v2: - Added Reviewed-by tags. --- 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 10b37dd65bed..706fb09c2f24 100644 --- a/drivers/watchdog/da9062_wdt.c +++ b/drivers/watchdog/da9062_wdt.c @@ -67,11 +67,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,