From patchwork Thu Sep 5 18:07:05 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: 173173 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp1059410ilq; Thu, 5 Sep 2019 11:07:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqy0yZxYwjYVowD8oU7nr7truys1ixj7VfFbtZm/KI44EXoOfhdkuH5Na4ek3rIXTOycNsCb X-Received: by 2002:a17:90a:7783:: with SMTP id v3mr5112514pjk.109.1567706831497; Thu, 05 Sep 2019 11:07:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567706831; cv=none; d=google.com; s=arc-20160816; b=t7ve0jrO7RbTuUsgg4+dZBLCIBFPGfadZ/eDvfc0830mChQb1Q5261eaCHTbMfEj37 8p3m2cSWhKcvF/A/L9imQzjeuH+PnYYvqOeZqkGzidCW5N2ybDO1gTd0zbfbRFa33jVf N2Fge0vdwXz7j7DrNC6SoB0vQ1P6raEEYAIwmhPH5IyuonwZqT3Qv2krPlNiSyUpZyXb 8JwAXFGEvu14dXn1KULr6cAEEwsIUkUMhYTiioX+ZGXZ775b7sU3FrhFu0kkTAQiGJsZ Fbj2wJY0vDTf7cjOsJ4oO/0S7oiuo+P3HGQfXgRUFvj5IGvHF9yFc5GubfnFpsx6X2A2 urgQ== 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=eQx8LFwZEFLFHsOp6JVQ136wPiDCvxTvsHmYT44VyoI=; b=uXSyD99uAOBLPPTW0YIHNmPmD/3XR2HUQg8ThLMtM7Kjvip7XScFc3SH0VBaiE39R/ RrcFnuB0OJSypWdu5lc6ZNXZg5oLGzzZOZZkh4ERuT1QgiE3uIFymPTZsSqR+mxLtxgY AS8eOLmjB1bUj2DYklL0hmoDPkJLGRe62yBc2QqeuMtebdqQbJLY2LC163jFWdf1HSvA yMydwChB5UWpyI39hqOhhHhifjt6KF9CwSE2IN/FBP/LKvVDhHAh0+KLz0MOuRTj2R24 IOzk3caGXtd6bIZwsI0FBToLW8hZxJG6mDOGGgosr4w7p4JWJirXym/o2dON/OlYUkgm KXyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZJv5I+4J; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 o2si3021590pfg.136.2019.09.05.11.07.11; Thu, 05 Sep 2019 11:07:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-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=ZJv5I+4J; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S2391214AbfIESHK (ORCPT + 15 others); Thu, 5 Sep 2019 14:07:10 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:33940 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391213AbfIESHK (ORCPT ); Thu, 5 Sep 2019 14:07:10 -0400 Received: by mail-wm1-f65.google.com with SMTP id y135so5567333wmc.1 for ; Thu, 05 Sep 2019 11:07:09 -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=eQx8LFwZEFLFHsOp6JVQ136wPiDCvxTvsHmYT44VyoI=; b=ZJv5I+4JMEy7c+i65ipPMvQ3ao0PJLdsjSW4Z4AWhUpYsQn1x9l2q+DA2kgvlqskbs xLjtUbzbvYq++1MekuMRihek+riXpl52V1TWEUQHNWw5fcyJbg3mau2uczjDdozYuSv2 L5RcmY7Q0Ebn1f25EOGmJoKJAs62svd2/xDJ5vcFAj/ymSlfZkFlSabdaw/vZotgq7Fp G2/o1GHwx09jjoQ09hfMEkWRaUHmGwWR9TBsMOLF5Nwzvk2iwbZztrISJUjBGQwNyC8Q M9dW8HVPRMRmdYQW+D0ynq6IF4SuuLsWm8ZhAcRKVF5FUb8gaJqmaQKr/JNUiwQFOuXJ wFxQ== 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=eQx8LFwZEFLFHsOp6JVQ136wPiDCvxTvsHmYT44VyoI=; b=cJfpKng30KpE7Q+Nd7YbQC+464+oKOaSOFUaDHAkIE2TtzujB1Q5lnPigHrRp000gB bgEGFjW0P/f8xmjtyfUyhI6ULdZPKzVDsqPTd0Qt7ypN5U5OnVb6V7GIvWqGCmLrEzx9 iqsjltZ165r6Xcw1Gsg10LVRkv7ONBcAiw6Zwj6WlrnLW0Xo2OT6y7Tx5MhDY5t0SVEu P/GIp9ZJrEZXlI3nP4UxCoYTnF0jiFIwprGovemcVJx7nblTgrkTs2Bety9iHlmawV1r pewFHJcrMP2VtIyeoHfgWgX/4X4O+zPSYXjTtaShv6yQ6eoNSBVJJyDJhJumRH8I1BtL fj4Q== X-Gm-Message-State: APjAAAV/mtlOxWsiidQuBPgwLkHNsnQ3EvyhHk6C6UX3gEGoAnDB3Qin sP2lIVtkyVE+0jodejeabcwtJw== X-Received: by 2002:a05:600c:214c:: with SMTP id v12mr4002689wml.28.1567706828344; Thu, 05 Sep 2019 11:07:08 -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 h12sm3238489wrp.51.2019.09.05.11.07.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Sep 2019 11:07:07 -0700 (PDT) From: Jorge Ramirez-Ortiz To: jorge.ramirez-ortiz@linaro.org, agross@kernel.org, wim@linux-watchdog.org, linux@roeck-us.net, bjorn.andersson@linaro.org Cc: linux-arm-msm@vger.kernel.org, linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Date: Thu, 5 Sep 2019 20:07:05 +0200 Message-Id: <20190905180705.30910-1-jorge.ramirez-ortiz@linaro.org> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@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 --- drivers/watchdog/qcom-wdt.c | 63 ++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 5 deletions(-) -- 2.23.0 diff --git a/drivers/watchdog/qcom-wdt.c b/drivers/watchdog/qcom-wdt.c index 7be7f87be28f..2dd36914aa82 100644 --- a/drivers/watchdog/qcom-wdt.c +++ b/drivers/watchdog/qcom-wdt.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include enum wdt_reg { WDT_RST, @@ -41,6 +43,7 @@ struct qcom_wdt { unsigned long rate; void __iomem *base; const u32 *layout; + const struct device *dev; }; static void __iomem *wdt_addr(struct qcom_wdt *wdt, enum wdt_reg reg) @@ -54,15 +57,37 @@ struct qcom_wdt *to_qcom_wdt(struct watchdog_device *wdd) return container_of(wdd, struct qcom_wdt, wdd); } +static inline int qcom_wdt_enable(struct qcom_wdt *wdt) +{ + /* enable the bark interrupt */ + if (wdt->wdd.info->options & WDIOF_PRETIMEOUT) + return 3; + + return 1; +} + +static irqreturn_t qcom_wdt_irq(int irq, void *cookie) +{ + struct watchdog_device *wdd = (struct watchdog_device *) cookie; + + 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->pretimeout; + + if (!(wdd->info->options & WDIOF_PRETIMEOUT)) + bark = wdd->timeout; 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_wdt_enable(wdt), wdt_addr(wdt, WDT_EN)); return 0; } @@ -86,9 +111,18 @@ static int qcom_wdt_set_timeout(struct watchdog_device *wdd, unsigned int timeout) { wdd->timeout = timeout; + return qcom_wdt_start(wdd); } +static int qcom_wdt_set_pretimeout(struct watchdog_device *wdd, + unsigned int timeout) +{ + wdd->pretimeout = timeout; + + return 0; +} + 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_wdt_enable(wdt), wdt_addr(wdt, WDT_EN)); /* * Actually make sure the above sequence hits hardware before sleeping. @@ -121,11 +155,12 @@ 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, }; -static const struct watchdog_info qcom_wdt_info = { +static struct watchdog_info qcom_wdt_info = { .options = WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE | WDIOF_SETTIMEOUT @@ -146,7 +181,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) { @@ -210,6 +245,7 @@ static int qcom_wdt_probe(struct platform_device *pdev) wdt->wdd.max_timeout = 0x10000000U / wdt->rate; wdt->wdd.parent = dev; wdt->layout = regs; + wdt->dev = &pdev->dev; if (readl(wdt_addr(wdt, WDT_STS)) & 1) wdt->wdd.bootstatus = WDIOF_CARDRESET; @@ -222,6 +258,23 @@ static int qcom_wdt_probe(struct platform_device *pdev) wdt->wdd.timeout = min(wdt->wdd.max_timeout, 30U); watchdog_init_timeout(&wdt->wdd, 0, dev); + irq = platform_get_irq(pdev, 0); + if (irq >= 0) { + /* enable the pre-timeout notification */ + qcom_wdt_info.options |= WDIOF_PRETIMEOUT; + + ret = devm_request_irq(&pdev->dev, irq, qcom_wdt_irq, + IRQF_TRIGGER_RISING, "wdog_bark", + &wdt->wdd); + if (ret) { + dev_err(&pdev->dev, "failed to request irq\n"); + return ret; + } + } + + if (qcom_wdt_info.options & WDIOF_PRETIMEOUT) + wdt->wdd.pretimeout = wdt->wdd.timeout - 1; + ret = devm_watchdog_register_device(dev, &wdt->wdd); if (ret) return ret;