From patchwork Thu Sep 5 21:00:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jorge Ramirez-Ortiz X-Patchwork-Id: 173186 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp1241582ilq; Thu, 5 Sep 2019 14:00:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqz8FzPlZjKdPcQ/rbW98EcGhkCnpeJnjOupBBXt6QZf9sMO2wxxzr7OAO09C+jsKQP99abE X-Received: by 2002:a63:5f09:: with SMTP id t9mr5006284pgb.351.1567717250025; Thu, 05 Sep 2019 14:00:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567717250; cv=none; d=google.com; s=arc-20160816; b=x9SSzCUp/MZqmI1pLJt0rRfI8q6jEUiVZJQMF8trT6p+WzCSE2ap16WWHl4r3lbfy3 7ckPXDiX7XOz5n9w2o1kITWD6pGBw9kh0SSxEisIOU3wBR8/JAMve5ae4iS9y87XEl+i 93YvNyiRPGSNEOMPgiLTlSCvguNqdB5qewZkV0B82WiAOgm+0OFE7C59wlU1bpuQ277p Y4+QRwHoHMRUCmLzxkrYFyOVEEHF09Ef6EcLw78W0yDA1AZPlGfjpdzg6KCnBd7fv+e7 8Dzi/RK/CCLPX4Nq4bD4gm/XfbHyghdW/VPyaoQldGi/w8HLQJBv4JkyYYTZ4emEg8wu FoOw== 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=nUXv/YP7adjHV5lsiZfdyH8Xt1iSvnRzLEcLR96QP25v2uPd+uoNupb2YVMTFU0AzJ B3ckw79WX+cb/UiWNTp76eTmnt3ZGw0IwcH8K6aWqR7kqJoHzdSp8tCgY4UCqvgjiwL4 BB0bjfxjYij1JW+yCQ/sFmwzY9EWFP1Gr4Tvoc/b+sGak20QkIhCq+mtfhf60A0IYQAI my/SHLPi4kmETPPbp4uZmXZenNmU110R0bjcxZnNOV2wSH27f65S9w9aJ4WakFUjKKdf n56zR2RHFMgAfE8/3nBGmu9OJurgPS3Fp4xd7tZZWef2ZeBQPb0ug3jjC8AAK8Rtkscl cvLA== 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-watchdog-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-watchdog-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 s11si2780218pgg.200.2019.09.05.14.00.49 for ; Thu, 05 Sep 2019 14:00:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-watchdog-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-watchdog-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-watchdog-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 S2388538AbfIEVAt (ORCPT ); Thu, 5 Sep 2019 17:00:49 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:45826 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388096AbfIEVAt (ORCPT ); Thu, 5 Sep 2019 17:00:49 -0400 Received: by mail-wr1-f67.google.com with SMTP id l16so4271402wrv.12 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=hrzrEiwD276gJ3dmxYCk20UiMC4Au5bJdeopyXhGkj8R81HkMuVLyL7lX0NrrbUOxI jc5s478Fd75mtj0ceu3p4h3/EtS5JpwSBWVpBF2p6njllbtVW0Y9YGzwW8ZIMK7XJed9 GfGLUDqyZWSIv7ZbUFulGlTkRIyJC8AWxj97uABj0rPrsQXpm8pA97KvnhaSO2EA5zO5 miHXXtgMm/XZMG9gt8j18gXt6KMCNZtujrw8hepHFPmRDzwzyR3ujH82a7vVaHE7aitJ Vh89BX+8OaqhKn5W+ELQ7m8iLVvxEiLT+wJK/dP2EeUlc2n03WJv7u946j4pg5XPdFZN zxWA== X-Gm-Message-State: APjAAAXTEl7Cb8NlOjmw9oDfhKgr/69wfIC9DdeNGTZazJ0edxN8sxlv ihYTQYq5EN84LAStr4oy+SSy3Q== 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 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@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(-) -- 2.23.0 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;