From patchwork Fri Sep 14 10:13:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Izard X-Patchwork-Id: 10600603 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6F03A933 for ; Fri, 14 Sep 2018 10:15:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47D242B188 for ; Fri, 14 Sep 2018 10:15:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B1E22B1BF; Fri, 14 Sep 2018 10:15:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BC6402B188 for ; Fri, 14 Sep 2018 10:14:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=PBhwExtsrtGwoDWOYMhddLOa0e8ibrYZOxwqYpH99hc=; b=hYGo9x4pDLjs3IUSKmVDFIAN5Z y2HvhnP1JPeFFiclaCKBfD9m9jinakIuW8IOsthR/6SzBK7hdZ03CYyH1BQygIctxt3bUgnx9UpW8 nGy5b1J4c0sccPVKo+lxs2cg4A6ciBqxvftbVDwDjFIDqRpGaWATDF8p+/zlB1DDZopKRfEfLXHa7 0VH9GfNQb7tp6kYAKj4av9M9QWAPVotqmcks4SkKVnRFxPcvqgXLMNg+bi40o9lNsJbmoH4w0q/bN vYkZ/NMxG2rQF5dOezEzNjxAZoAmX8wUau+9XoFihYXG8H3LJKcTK8BVnpcYeb/as6QOUZY9s1dcU EOadBV2Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g0l7c-00077m-9t; Fri, 14 Sep 2018 10:14:44 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g0l72-0006hq-UY for linux-arm-kernel@lists.infradead.org; Fri, 14 Sep 2018 10:14:10 +0000 Received: by mail-wm1-x341.google.com with SMTP id f21-v6so1369670wmc.5 for ; Fri, 14 Sep 2018 03:13:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wQJV+ddJAv5kZKQDNvJ+wHS7DL8i4Je+cSh6xS7XWuM=; b=rircDlgBDrHWS6V0DOCcfoALp08ITkG3cQ57mUW7/dQW9MhPvpXC9MaJHZD4JFOI7h qKMb3jIRf04nxQSuFVj4cpLQJ78Cm+PNn648suHBIaqZP2UWd8b3tCgjEfSyPdSxIqjm A1loWb8zNhxtU80TYzg0Dj6lTTtHHGbgu0W1aky+Ukrdv8j2iaRljnVwl9IEiuy6noJr CoexKYHOav8Shb2F26s6rbnNSBjZfZAGDXBDZgdXJKLu22hORAr1+f0ozckapDmBpLJ3 ihAzUGDDn550klDx8+4KhI+utfVHeFKEtUc2rRK7zlvyp7MjPxBZ7ptAeDwE2IsCg1Wn hRuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wQJV+ddJAv5kZKQDNvJ+wHS7DL8i4Je+cSh6xS7XWuM=; b=MIqwnEw6mK0gJmYAiA7gpnH/oM8m5XgyQ8XfFCiUHJjx9X3+E7R9eZIhlnnxDVUrUt Awbl2U3iDPlJ0+ejDfTy0yt5yY30UxqgEOrWyX76XLXBq/cySD5fM2vyegtS2zh8nNXq 5vkhGWyvS32DASByJ19hEy1B4fTS4O9Z+nmLwk3nJFCYLf0IwjNfaqyKngQUumjDdisz csVtDBHvI2V48aq6Xgj3xCeEAfpgDAVYVLTVWCGAoO5Gmu8IiXedo9KJVckU1nVjWrCI pJA2jRSiarqXdlCWw5cSfHwh5JHiHK8Jpij//K6SiNjiodLnwkRg4vUTTC5uJkTW6OUh B81Q== X-Gm-Message-State: APzg51CzOlsV2y6/W4OYosDSKmixDvxootMkCyGsDJEZdorhHC7orAzg AaXgacoYzQrpIItfR/mthWyyhOPy X-Google-Smtp-Source: ANB0VdZY8rvGy+QS/OOWRyvjzzsgebRm2THF2oWSkUDULpGLrdu6XY0391j5GLt03LxcjIDA5ZGA7w== X-Received: by 2002:a1c:ed4:: with SMTP id 203-v6mr1576847wmo.96.1536920037259; Fri, 14 Sep 2018 03:13:57 -0700 (PDT) Received: from localhost.localdomain (static-css-cqn-143221.business.bouyguestelecom.com. [176.149.143.221]) by smtp.gmail.com with ESMTPSA id x15-v6sm5618524wrt.53.2018.09.14.03.13.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Sep 2018 03:13:56 -0700 (PDT) From: Romain Izard To: Nicolas Ferre , Alexandre Belloni , Wim Van Sebroeck , Guenter Roeck , Marcus Folkesson Subject: [PATCH 1/2] watchdog: sama5d4: fix timeout-sec usage Date: Fri, 14 Sep 2018 12:13:38 +0200 Message-Id: <20180914101339.7382-2-romain.izard.pro@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180914101339.7382-1-romain.izard.pro@gmail.com> References: <20180914101339.7382-1-romain.izard.pro@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180914_031408_988706_2F47B036 X-CRM114-Status: GOOD ( 14.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Romain Izard , linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When using watchdog_init_timeout to update the default timeout value, an error means that there is no "timeout-sec" in the relevant device tree node. This should not prevent binding of the driver to the device. Fixes: 976932e40036 ("watchdog: sama5d4: make use of timeout-secs provided in devicetree") Signed-off-by: Romain Izard Reviewed-by: Guenter Roeck Reviewed-by: Marcus Folkesson --- drivers/watchdog/sama5d4_wdt.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/watchdog/sama5d4_wdt.c b/drivers/watchdog/sama5d4_wdt.c index 255169916dbb..1e93c1b0e3cf 100644 --- a/drivers/watchdog/sama5d4_wdt.c +++ b/drivers/watchdog/sama5d4_wdt.c @@ -247,11 +247,7 @@ static int sama5d4_wdt_probe(struct platform_device *pdev) } } - ret = watchdog_init_timeout(wdd, wdt_timeout, &pdev->dev); - if (ret) { - dev_err(&pdev->dev, "unable to set timeout value\n"); - return ret; - } + watchdog_init_timeout(wdd, wdt_timeout, &pdev->dev); timeout = WDT_SEC2TICKS(wdd->timeout); From patchwork Fri Sep 14 10:13:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Izard X-Patchwork-Id: 10600605 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9BC1415A7 for ; Fri, 14 Sep 2018 10:15:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72C702B22E for ; Fri, 14 Sep 2018 10:15:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62E672B259; Fri, 14 Sep 2018 10:15:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D6A882B22E for ; Fri, 14 Sep 2018 10:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Tck85VmKsKawwmpbH+//iuYVsIXa4LWZKWK6eQCh+2Y=; b=NcIc+mk0/QhQCvNmdjZzX19dWK 4qptffr+8Feeju6Iq/5Jn4cpt3H1W2Kn1wFtkhQyENzixDVrpfM+UsLnKa5j+v/75GOMD00RlNT2C vcNXHUWiZt/n/iOSsuS023PkOAQs+tjcruOkgfVm14mcS+cFWnQ0DDJ+sui3JaKB/D1g2kvFjZqsU k5pRfJKr4pmuuerz6MTAyt6IQx3VJVue1/2/BQD/lPmwFmZatmPf58ObuZ9evJjlEl/X0gBmuvRRu mwuqXryZNIiwUDth+ZPz99en5lKxZhWxBFEJlLCVdMVfzELjUIMX4m3TTHovy0jhMY2fp5+9LUaWN Zezf5iag==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g0l8P-0008CH-P6; Fri, 14 Sep 2018 10:15:33 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g0l73-0006hs-Mh for linux-arm-kernel@lists.infradead.org; Fri, 14 Sep 2018 10:14:11 +0000 Received: by mail-wr1-x442.google.com with SMTP id g33-v6so9958574wrd.1 for ; Fri, 14 Sep 2018 03:13:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8pXDek8ZnrmjczAVnmQjU/AsOxmvJrcBH5KF6yK3Dzk=; b=dlb4nVdw5HTnxFtaAsbUYEw+BkbjDdyaJJOuo5wet0S0KlmqJ4lneuPGwg3Tweq8bg x1FyKECxMxWs8uU3Ew0K0T6YFHZWQYdUOvtYwUMsY0KLL23u3fq9WEozgENy9Gsx/QjC B5myXHWfXbXcG1POIqs6qVtphtKHBkbnG1uWOtY35LOEd6VdBm4aYu+C4dN6G8Aa1TKU UJrIE+J31f0uzVBgjWGfQi89XPSalpcwkCVrI4JOK+gXiuUYPo7Qrxt0FmOv8pNVRRW/ dc3P6+7a1V/bmlXrasW6ccNQkeFqhoWjyUw8xxySkwARDu7EBy50edHpM8unup4yVWHw j/bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8pXDek8ZnrmjczAVnmQjU/AsOxmvJrcBH5KF6yK3Dzk=; b=UTI/yGIsNb4+I16u181AHDdSdiZgDlhzqGFJ1t9fgwgQSYZbg3W/diaThICl3x9+eY 3U7ziNeOy//YW7NPp1Ctvh33oTYq6Ik3p2V/00gCkjKNsVbidsJLRNQHU/fUqZcWeRnp EfP4bj2KdgVMMQ0KwYrbVGUxH/avqwWVl8AoJeEb8StSj1fsY5TGuwvSZE15X6uFzbX0 /EoRsuW35WSAEdnOvmDrXzKO+FvYZAP2VGqFreKGEHfC01xF/bYfk1UsdFHZ8mdTt+yY Se93O4tpEhRk/rFtEOy36VRLcFRBAatERViSD3owSnpAbhbCGJlK0ViQTNuj8rY8sIQ6 M75Q== X-Gm-Message-State: APzg51AJVFChpmIt/c8bN0gAw0j4DitfKoQblHSBSf8JUBj3xDZYIUD7 a/ZF0MouYscPoi9PlK2tw/E= X-Google-Smtp-Source: ANB0Vdb+j3PuUK6bFY5ESy++Ho91fghuKNst5FC737O8vv0WGDBl04xj4qr3kf0qs26cP/9WaAXnNQ== X-Received: by 2002:adf:959a:: with SMTP id p26-v6mr8542795wrp.202.1536920038176; Fri, 14 Sep 2018 03:13:58 -0700 (PDT) Received: from localhost.localdomain (static-css-cqn-143221.business.bouyguestelecom.com. [176.149.143.221]) by smtp.gmail.com with ESMTPSA id x15-v6sm5618524wrt.53.2018.09.14.03.13.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Sep 2018 03:13:57 -0700 (PDT) From: Romain Izard To: Nicolas Ferre , Alexandre Belloni , Wim Van Sebroeck , Guenter Roeck , Marcus Folkesson Subject: [PATCH 2/2] watchdog: sama5d4: write the mode register in two steps Date: Fri, 14 Sep 2018 12:13:39 +0200 Message-Id: <20180914101339.7382-3-romain.izard.pro@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180914101339.7382-1-romain.izard.pro@gmail.com> References: <20180914101339.7382-1-romain.izard.pro@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180914_031409_743648_628890A7 X-CRM114-Status: GOOD ( 18.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Romain Izard , linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The specification for SAMA5D2 and SAMA5D4 chips, that use this IP for their watchdog timer, has the following advice regarding the Mode Register: "When setting the WDDIS bit, and while it is set, the fields WDV and WDD must not be modified." I have observed on a board based on a SAMA5D2 chip that using any other timeout duration than the default 16s in the device tree will reset the board when the watchdog device is opened; this is probably due to ignoring the aforementioned constraint. To fix this, read the content of the Mode Register before writing it, and split the access into two parts if WDV or WDD need to be changed. Signed-off-by: Romain Izard --- drivers/watchdog/sama5d4_wdt.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/watchdog/sama5d4_wdt.c b/drivers/watchdog/sama5d4_wdt.c index 1e93c1b0e3cf..1e05268ad94b 100644 --- a/drivers/watchdog/sama5d4_wdt.c +++ b/drivers/watchdog/sama5d4_wdt.c @@ -46,7 +46,10 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); -#define wdt_enabled (!(wdt->mr & AT91_WDT_WDDIS)) +#define wdt_enabled(reg) (!((reg) & AT91_WDT_WDDIS)) + +#define wdt_different_counters(reg_a, reg_b) \ + (((reg_a) ^ (reg_b)) & (AT91_WDT_WDV | AT91_WDT_WDD)) #define wdt_read(wdt, field) \ readl_relaxed((wdt)->reg_base + (field)) @@ -78,8 +81,11 @@ static void wdt_write_nosleep(struct sama5d4_wdt *wdt, u32 field, u32 val) static int sama5d4_wdt_start(struct watchdog_device *wdd) { struct sama5d4_wdt *wdt = watchdog_get_drvdata(wdd); + u32 reg = wdt_read(wdt, AT91_WDT_MR); wdt->mr &= ~AT91_WDT_WDDIS; + if (!wdt_enabled(reg) && wdt_different_counters(reg, wdt->mr)) + wdt_write(wdt, AT91_WDT_MR, reg & ~AT91_WDT_WDDIS); wdt_write(wdt, AT91_WDT_MR, wdt->mr); return 0; @@ -88,8 +94,11 @@ static int sama5d4_wdt_start(struct watchdog_device *wdd) static int sama5d4_wdt_stop(struct watchdog_device *wdd) { struct sama5d4_wdt *wdt = watchdog_get_drvdata(wdd); + u32 reg = wdt_read(wdt, AT91_WDT_MR); wdt->mr |= AT91_WDT_WDDIS; + if (wdt_enabled(reg) && wdt_different_counters(reg, wdt->mr)) + wdt_write(wdt, AT91_WDT_MR, wdt->mr & ~AT91_WDT_WDDIS); wdt_write(wdt, AT91_WDT_MR, wdt->mr); return 0; @@ -122,7 +131,7 @@ static int sama5d4_wdt_set_timeout(struct watchdog_device *wdd, * If the watchdog is enabled, then the timeout can be updated. Else, * wait that the user enables it. */ - if (wdt_enabled) + if (wdt_enabled(wdt->mr)) wdt_write(wdt, AT91_WDT_MR, wdt->mr & ~AT91_WDT_WDDIS); wdd->timeout = timeout; @@ -186,13 +195,17 @@ static int sama5d4_wdt_init(struct sama5d4_wdt *wdt) * If the watchdog is already running, we can safely update it. * Else, we have to disable it properly. */ - if (wdt_enabled) { + reg = wdt_read(wdt, AT91_WDT_MR); + if (wdt_enabled(reg)) { + if (!wdt_enabled(wdt->mr)) + wdt_write_nosleep(wdt, AT91_WDT_MR, + wdt->mr & ~AT91_WDT_WDDIS); wdt_write_nosleep(wdt, AT91_WDT_MR, wdt->mr); - } else { - reg = wdt_read(wdt, AT91_WDT_MR); - if (!(reg & AT91_WDT_WDDIS)) + } else if (wdt_enabled(wdt->mr)) { + if (wdt_different_counters(reg, wdt->mr)) wdt_write_nosleep(wdt, AT91_WDT_MR, - reg | AT91_WDT_WDDIS); + reg & ~AT91_WDT_WDDIS); + wdt_write_nosleep(wdt, AT91_WDT_MR, wdt->mr); } return 0; }