Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp440325ybe; Fri, 6 Sep 2019 01:51:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwKgiZdzhLCbSzu686aswMax0uObf7sLx7CLWES1O0C1ELqJzGVBhRMpw1JwXPZLmDKErRy X-Received: by 2002:a63:6eca:: with SMTP id j193mr6863126pgc.74.1567759868037; Fri, 06 Sep 2019 01:51:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567759868; cv=none; d=google.com; s=arc-20160816; b=Cdr53Bi9xlqIOkOwfjYZA3Hxwt2EYDrcKJ1q2twGDC1MzcUtOHeHSVXWmHONBdrjEf QCcfz/tICzvTiHF+BASsdY0Z235iu1AjatDOGj5mmoN5WwyOdsD3KTJzZBaaKqvLdfnO SyOhcag8VP23sOzC4QBeQAsncn+kqbcNxyjOx/NT6VdhSHdbbMsm2pUCwA9e0D9GPzPt bV/t4bBGOl78Wh0OMa98J+J8DzfWMj8ZoUD1tk1rXCh7baz/bZurawMfDSoGSIDECqTZ qzlrGltn9Y0ZE5N/ZHo5ZHRfk/SiR+hXJJdnAqdzeyvqCRb6g/d36JTTgrBmB4wEoth+ KXUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3nnDoHPMMqk2BqcrsZAHoETbkS1IHUKarK3YqBqfkWc=; b=pZVeMOvBHaTkGasD3gq2IJ2sinS1/ehBIBjWsimJyIKOYXfdjCGIuYWtPyobleXDDo KwoPSrBaNf0E5cioxVhTENc3daN0AfY4HRoS0Th4HS1a27ICgcekJjaNFlx4bE2/PAKs cmJQH1DcJwiwVUBYboU+LJNI6F3p6/v1sq4a7i9wI2KoZdwkLXTrLKbmAwpozT++9D1O S5+ezRQ2P3TDmuyxFuwRUKKKNP+iHZFXllMV2eo74lJpQzQvfzsMRbonIx3swl5lw82u gS+WkLCYaNNbD0UGLu/z5AcxUDmYZ2WM4mH2DcfxHa8z5xJzWvOdSXDBF2dMxI+1VVcj jGEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mp29bxwu; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 190si4472464pfc.39.2019.09.06.01.50.52; Fri, 06 Sep 2019 01:51:07 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b=mp29bxwu; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390239AbfIEVAt (ORCPT + 99 others); Thu, 5 Sep 2019 17:00:49 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:38659 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387545AbfIEVAt (ORCPT ); Thu, 5 Sep 2019 17:00:49 -0400 Received: by mail-wr1-f66.google.com with SMTP id l11so4315579wrx.5 for ; Thu, 05 Sep 2019 14:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3nnDoHPMMqk2BqcrsZAHoETbkS1IHUKarK3YqBqfkWc=; b=mp29bxwuxcKXa6CxuC8MdfDEU8Gl4WV38Qt61LUV3pUO/YxqUzHCCTtc008aej+JV6 sj7iYZPRDelw8H+IZyeHB+VauqP9Kocl+OkOev/6253abQrjeBNVEha4KY2wXEijrX3/ S8XBP2UOiY5oDVvjxSbIWcarF/y09xQYt2lAYoHe+mRBfivPVg/8xp/Ehtp6dAE+UXX9 N3MU6Z2XWLzKw5zV+wpLqV+kcg0dY0dOwax3tUQPzdVX9CTdOAEw+W9Y/gXA8KalIN9k 3+ygLZt3+3BDnKg7kehRWL7u6060dTQ+Czfi9RupEVQ0lcfC0x7ulGSBmFO8A3Ezz7Yp FHuA== 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:mime-version :content-transfer-encoding; bh=3nnDoHPMMqk2BqcrsZAHoETbkS1IHUKarK3YqBqfkWc=; b=OcGF4x7ZeqQGjh0c95+qY0NBkifmzpsTe0UN++4VhtVGrf3h+xt3pd11b4JWCuOs8R pWfO1dRW9x34YWUzJq39UqXxAGobhe2MgWMW3VfkAiGUCG0exngjyKoXwQh6BO25Tf+l LzxvLucLzc24YLX8NVgTotMvYu5OV0tdPe3YQhwX7sl5Q5KoicV9Sw+G6aOTT8mhfA+e AO44ym4UoP2ZZ9yJQy6eXGFhP10LW+kdahAR+0tPs7LzNRndi9g1OxXcQuMD8fwAQ2Te 7UlHOvh+2bqlR+rmjFYhSc2pZMM9QijAVPLyZ0jURBde0zS+h8Lvu9Dr0PanejWaQ+J8 iyng== X-Gm-Message-State: APjAAAXl8loS15jlg2LsuWXmXBqm8k2yqL4H1a7JlhYgfJS/fl30mdbM SgIwJVpOAOb0Y9DeQ2UgB+sgkg== X-Received: by 2002:a5d:680e:: with SMTP id w14mr258331wru.3.1567717246455; Thu, 05 Sep 2019 14:00:46 -0700 (PDT) Received: from localhost.localdomain (124.red-83-36-179.dynamicip.rima-tde.net. [83.36.179.124]) by smtp.gmail.com with ESMTPSA id q25sm2484253wmj.22.2019.09.05.14.00.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Sep 2019 14:00:45 -0700 (PDT) From: Jorge Ramirez-Ortiz To: jorge.ramirez-ortiz@linaro.org, agross@kernel.org, linux@roeck-us.net, wim@linux-watchdog.org, bjorn.andersson@linaro.org Cc: linux-arm-msm@vger.kernel.org, linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4] watchdog: qcom: support pre-timeout when the bark irq is available Date: Thu, 5 Sep 2019 23:00:35 +0200 Message-Id: <20190905210035.9985-1-jorge.ramirez-ortiz@linaro.org> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the bark interrupt as the pre-timeout notifier whenever this interrupt is available. By default, the pretimeout notification shall occur one second earlier than the timeout. Signed-off-by: Jorge Ramirez-Ortiz --- v4: address Guenter Roeck comments as follows: remove unnecessary include and private variable provide macro for WDT EN register values use pretimeout as per its API intent handle EPROBE_DEFER on get_irq also: handle the irq registration as done in pm8916_wdt.c v3: remove unnecesary variable added to private. v2: register the pre-timeout notifier instead. v1: drivers/watchdog/qcom-wdt.c | 64 ++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/drivers/watchdog/qcom-wdt.c b/drivers/watchdog/qcom-wdt.c index 7be7f87be28f..0f1d29eeb81d 100644 --- a/drivers/watchdog/qcom-wdt.c +++ b/drivers/watchdog/qcom-wdt.c @@ -10,6 +10,7 @@ #include #include #include +#include enum wdt_reg { WDT_RST, @@ -19,6 +20,9 @@ enum wdt_reg { WDT_BITE_TIME, }; +#define QCOM_WDT_ENABLE BIT(0) +#define QCOM_WDT_ENABLE_IRQ BIT(1) + static const u32 reg_offset_data_apcs_tmr[] = { [WDT_RST] = 0x38, [WDT_EN] = 0x40, @@ -54,15 +58,38 @@ struct qcom_wdt *to_qcom_wdt(struct watchdog_device *wdd) return container_of(wdd, struct qcom_wdt, wdd); } +static inline int qcom_get_enable(struct watchdog_device *wdd) +{ + int enable = QCOM_WDT_ENABLE; + + if (wdd->info->options & WDIOF_PRETIMEOUT) + enable |= QCOM_WDT_ENABLE_IRQ; + + return enable; +} + +static irqreturn_t qcom_wdt_isr(int irq, void *arg) +{ + struct watchdog_device *wdd = arg; + + watchdog_notify_pretimeout(wdd); + + return IRQ_HANDLED; +} + static int qcom_wdt_start(struct watchdog_device *wdd) { struct qcom_wdt *wdt = to_qcom_wdt(wdd); + unsigned int bark = wdd->timeout; + + if (wdd->pretimeout) + bark = bark - wdd->pretimeout; writel(0, wdt_addr(wdt, WDT_EN)); writel(1, wdt_addr(wdt, WDT_RST)); - writel(wdd->timeout * wdt->rate, wdt_addr(wdt, WDT_BARK_TIME)); + writel(bark * wdt->rate, wdt_addr(wdt, WDT_BARK_TIME)); writel(wdd->timeout * wdt->rate, wdt_addr(wdt, WDT_BITE_TIME)); - writel(1, wdt_addr(wdt, WDT_EN)); + writel(qcom_get_enable(wdd), wdt_addr(wdt, WDT_EN)); return 0; } @@ -89,6 +116,13 @@ static int qcom_wdt_set_timeout(struct watchdog_device *wdd, return qcom_wdt_start(wdd); } +static int qcom_wdt_set_pretimeout(struct watchdog_device *wdd, + unsigned int timeout) +{ + wdd->pretimeout = timeout; + return qcom_wdt_start(wdd); +} + static int qcom_wdt_restart(struct watchdog_device *wdd, unsigned long action, void *data) { @@ -105,7 +139,7 @@ static int qcom_wdt_restart(struct watchdog_device *wdd, unsigned long action, writel(1, wdt_addr(wdt, WDT_RST)); writel(timeout, wdt_addr(wdt, WDT_BARK_TIME)); writel(timeout, wdt_addr(wdt, WDT_BITE_TIME)); - writel(1, wdt_addr(wdt, WDT_EN)); + writel(qcom_get_enable(wdd), wdt_addr(wdt, WDT_EN)); /* * Actually make sure the above sequence hits hardware before sleeping. @@ -121,6 +155,7 @@ static const struct watchdog_ops qcom_wdt_ops = { .stop = qcom_wdt_stop, .ping = qcom_wdt_ping, .set_timeout = qcom_wdt_set_timeout, + .set_pretimeout = qcom_wdt_set_pretimeout, .restart = qcom_wdt_restart, .owner = THIS_MODULE, }; @@ -133,6 +168,15 @@ static const struct watchdog_info qcom_wdt_info = { .identity = KBUILD_MODNAME, }; +static const struct watchdog_info qcom_wdt_pt_info = { + .options = WDIOF_KEEPALIVEPING + | WDIOF_MAGICCLOSE + | WDIOF_SETTIMEOUT + | WDIOF_PRETIMEOUT + | WDIOF_CARDRESET, + .identity = KBUILD_MODNAME, +}; + static void qcom_clk_disable_unprepare(void *data) { clk_disable_unprepare(data); @@ -146,7 +190,7 @@ static int qcom_wdt_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; const u32 *regs; u32 percpu_offset; - int ret; + int irq, ret; regs = of_device_get_match_data(dev); if (!regs) { @@ -204,7 +248,17 @@ static int qcom_wdt_probe(struct platform_device *pdev) return -EINVAL; } - wdt->wdd.info = &qcom_wdt_info; + irq = platform_get_irq(pdev, 0); + if (irq > 0) { + if (devm_request_irq(dev, irq, qcom_wdt_isr, + IRQF_TRIGGER_RISING, "wdt_bark", + &wdt->wdd)) + irq = 0; + } else if (irq == -EPROBE_DEFER) + return -EPROBE_DEFER; + + wdt->wdd.info = irq > 0 ? &qcom_wdt_pt_info : &qcom_wdt_info; + wdt->wdd.pretimeout = irq > 0 ? 1 : 0; wdt->wdd.ops = &qcom_wdt_ops; wdt->wdd.min_timeout = 1; wdt->wdd.max_timeout = 0x10000000U / wdt->rate; -- 2.23.0