From patchwork Tue Nov 3 08:26:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Gong X-Patchwork-Id: 7540731 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 022519F4F5 for ; Tue, 3 Nov 2015 08:31:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1F89020762 for ; Tue, 3 Nov 2015 08:31:17 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 18D702075A for ; Tue, 3 Nov 2015 08:31:16 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZtWy8-00082V-Fy; Tue, 03 Nov 2015 08:29:28 +0000 Received: from mail-bl2on0138.outbound.protection.outlook.com ([65.55.169.138] helo=na01-bl2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZtWy0-0007uZ-1r for linux-arm-kernel@lists.infradead.org; Tue, 03 Nov 2015 08:29:21 +0000 Received: from BLUPR0301CA0011.namprd03.prod.outlook.com (10.162.113.149) by BY1PR0301MB0886.namprd03.prod.outlook.com (10.160.194.144) with Microsoft SMTP Server (TLS) id 15.1.312.18; Tue, 3 Nov 2015 08:28:57 +0000 Received: from BN1BFFO11FD029.protection.gbl (2a01:111:f400:7c10::1:194) by BLUPR0301CA0011.outlook.office365.com (2a01:111:e400:5259::21) with Microsoft SMTP Server (TLS) id 15.1.318.15 via Frontend Transport; Tue, 3 Nov 2015 08:28:56 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; lists.infradead.org; dkim=none (message not signed) header.d=none;lists.infradead.org; dmarc=none action=none header.from=freescale.com; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BN1BFFO11FD029.mail.protection.outlook.com (10.58.144.92) with Microsoft SMTP Server (TLS) id 15.1.318.9 via Frontend Transport; Tue, 3 Nov 2015 08:28:56 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id tA38Sljw020608; Tue, 3 Nov 2015 01:28:53 -0700 From: Robin Gong To: , , Subject: [PATCH v3 2/2] watchdog: imx2_wdt: add set_pretimeout interface Date: Tue, 3 Nov 2015 16:26:46 +0800 Message-ID: <1446539206-8213-2-git-send-email-b38343@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1446539206-8213-1-git-send-email-b38343@freescale.com> References: <1446539206-8213-1-git-send-email-b38343@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD029; 1:iavYIkhr7hl1GBQiBykMHTI6/SeDiJiLM6mYnCJcRF7KFQEBMFWS/cY1AOBccMV1m/JUCTROTO4aJRuGHaGQ9h3MTAjJfKiyApH2cao0aNPp5YLRi0Tjg8Er14n5Ye/VcPnU61K/S54xSQkaF3XbQwHZvc8aS+SUzHA0Dde5jig1UII1SHiPm7YtGchsU2Gl58cRhp55yLOg643Gz162L4SV4TezvI5Y+S0Vejxc6gPdPfQJmEy4QuweVhzdudsrxVpDOUX+xT4vYh//mUVZ8t5FRhnlcElHkzjgV8DPv+GyhPK11jJIgcI/3XuHHciq3QKDzUt44EIC3q4feFPlJ3/ouebhdO0O0okzRqwvo9XZnESl9x8lCjGaxPtQ7ydQ X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(50466002)(36756003)(47776003)(105606002)(106466001)(48376002)(19580395003)(85426001)(76176999)(69596002)(229853001)(50986999)(87936001)(19580405001)(5008740100001)(77096005)(97736004)(81156007)(189998001)(2201001)(5001770100001)(2950100001)(5007970100001)(33646002)(5001960100002)(50226001)(92566002)(11100500001)(6806005)(5003940100001)(104016004)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:BY1PR0301MB0886; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BY1PR0301MB0886; 2:0VMdkaUVh7+2Fr5tqfIq74tK+2RHL1NzyoiMN/s1ysCAPyVoTBKQ8CcCslJ9VRD3+iHZI8++bFE90RanIQL3GogIv1RZSu7PZQ0a+Zv5RkqNbMnUoHE108i+gJ9+c110kdaQjp7xKvnwPuLKSwu1EY5mZ5T5pyVoxgUROvfCAuc=; 3:sSx/QCLjBJ9D0NAXw91wy8XCKQ+YZgLdYXSFTsZ0IiJfzb2XLyIO5DbT3n/nUyRmU+H6h6Fdt6x2wr2Kf4H2axTX4spGzuT9j6iKQ0zccOGo3yYDNhQY6oC291UNHkcF2/ORHhlVVylo+oGXpq5HUWFGJgOZidQJ6M842v5kFny7d4F9Igt0cp9leiXYGtXlOLgooI9xTtUCXtAm4oW4mQyaXLHw2gDGyIBhSBzI94A=; 25:itgwKQWc78EjdUnOtRCFYZMwIP5n0GgFAy0gcPpWiqSjIpwEbOPXXcYm3pTbzYk8rtMESOFAoffZwSIr3aOkgIjGw75LcY5JgwrxoV5Sd8MbRUNxpLUxHJNT5+S92x1EMeMZmAErYflZjynKdbahD0B0kGqlkur+PY92K9R5qLVXObS4Gkw6DkihNkD9qYuLD6uVi+UOa7aaeq2rPsURNScrD5i6SIbI45nsrYhrByurqkPQj3ciQp5t637Qq9ImgiJJCg164/+tZafSHDb6Ew== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0301MB0886; X-Microsoft-Exchange-Diagnostics: 1; BY1PR0301MB0886; 20:5b57J8BiXkBITldNG1CgEO2JEUnKvA4++6h3HR/xBX8fuCtsysdD+oQzpnkueXAbFRUISKFvsQxY8lLB3bu9wyIOn7Xk8bhZ3HUar1Cet70YFBf57HUPZeUilfWD8QXCigzfI3E0okdVXtA09EtI4haNNINElRBocZ8Dc+nAhn+jKkV9EqZTdl7Fby8S+0UDSRtD31CW8QnFtmLZqKjQs+RDMoDdTlsjy3B7rWvjoTJIvBtB1xqIxMLY0lVyyRzkYyvsMXxhdlYbGmiGNwK/8eNCkkZH+7zjegWbrG6Cnm6GYZ8eNz213vZwsoMuW9DsRGykyNYu332PWxwAL9kp9bNiNUDOgdtpF8uym4ZEJdw=; 4:0236OEnYcdT2OrBrikrGBx1XscdGhixCVogCqmiTaMkZSu4wejGJV06zsYm7XfQ0DXreG6DvOZt0Sz/9LVk5X1v6xV7p8bXXzrJQlD+YIv1G2M6EMXIcC9VeLXbFvmYn1NkAbjFLo/fS9+ctjQpHFinnPfjPtePBu85/LxYiwdmxexzz6B9FfGyyQFs0vRpe7p4triJiucyONVkb0wMSwO+KmZ2c/ZPUED5jSjCfONO7fnFwDnaUsqPO3WsKQjC5feqp2Xq8mlQf65THRpZupCQcIWDjEdmMQJ38JVacZJSJCf3nInzd65J6RQWmA4B7nvum2jQVI9TberiUO3+wOujK0mAtwbN/mLLydzkroAOzwxgAT/3UiU8RfLEOG5cq X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(520078)(3002001)(10201501046); SRVR:BY1PR0301MB0886; BCL:0; PCL:0; RULEID:; SRVR:BY1PR0301MB0886; X-Forefront-PRVS: 0749DC2CE6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY1PR0301MB0886; 23:Bg2rT11jgooy/rmYLYpzkWSc3sxJokPWov/JDtm?= =?us-ascii?Q?/7FGLNluOvfVS+i4LsVZgv8CKs1281dJy2JhTswzCRvE6m7PiuiyUtYHMADO?= =?us-ascii?Q?pohSh1qkTEl82vyfRNi8RLOgzR82xn2ooeUz2QYB62k29kTbOo2/lqGOuBu8?= =?us-ascii?Q?rNWIwFdMVZV2IcKtHTuPUxbWQAHnJWeqhb46ELqFXclp7131t21Hw4RQVr++?= =?us-ascii?Q?eZ4jbWtVHMHN3QA3RScnAlNDp1EPnRDTq3Bu1aOljLogF6Mp3Im23jAvt+sj?= =?us-ascii?Q?jTaWtDV5s7/yN4tUO/sihM1IWfHXaMZnsq+F+2vOjAgt/LItOvaQfxnUvdDh?= =?us-ascii?Q?Zz5DunOZ20H0LoydCabcvyqnIiI9IPhv3L/Ye9ISyNl5rCuoHK/LbYpn/OJC?= =?us-ascii?Q?sahWwU2nNdAoNmK+fMUnu0VmehGUuUFVV2SIA17F630AbbK44qq6MQYVHB4z?= =?us-ascii?Q?gfCm8x4h3fw1yfpFb6bJMvhLKmjfdvzhSQHCmrws6P2o50/WbvIAdr5J8Tdm?= =?us-ascii?Q?GdGltse81m8LnW28CovG8Uw1GK8mr1MBGTh91bV0PGFO+0h7EKbubxrT+U5J?= =?us-ascii?Q?ZNvIcz6Fa401Ilg5igBpJitXLNUcK9xOX9ObOQ4A7OyQu20lapqaQaV89nVf?= =?us-ascii?Q?XRgrzPN41BdbcIrKbqxBm07rJnV0NLIXs9uQk8JC6McvoSU7n8bYzSDqIqJ0?= =?us-ascii?Q?Wrnqvd4rXmPEeC0lmxWI/cTyVaNOfrp+Z3ezWctlFXd+tsuHZAd98GCoCSQY?= =?us-ascii?Q?meNtcAoWUPBUyd7XLj7a65+nqQ06KbVDQgGhP+grw96uG0rc1WUsn7aOOWvK?= =?us-ascii?Q?Zyv/JVMchdW1VjJIZxDv6uW/KqVtka3xvjW3HnP/hJwBjnkhhr7f5wW/GYvP?= =?us-ascii?Q?XZDeQhl9C0G6tXlVEPsQ/o3xu1OpJAAyWZr1WSnqwHMet4icUV47kfAtSsu6?= =?us-ascii?Q?Uu79zI3g+vmBaGnYVyzzirWXCgLb3+h7SwsKiMmkObE8t0WI8uNfTiKOrorS?= =?us-ascii?Q?BevFh6DqFOl6mXFNIk+l4H3qsykk/zJgEk5TbzoBb2sEUJPlhOUMK3kmipDW?= =?us-ascii?Q?hSLIKfgDi3w7/CEnPNgiyQn/V0TQl?= X-Microsoft-Exchange-Diagnostics: 1; BY1PR0301MB0886; 5:pWgohclVnVym9aHY52ppvSTVIfAuvaX+WmoUrWliCYW2OND8JMGIW3zyNHUzny9Ks+lK608hax/hqDUK62KV2Qzm56RiN39NIUOw7zFzeTcG8O6vg4YaA+sVg+Ux+7TF4XWniRbNff5+mWMP9/3Uig==; 24:DyYWFTE2g4ylHIP3bf3oQixtFC4O2qs4vm7l/FdSpCpDzmHJ7IwfF5I/NFbAZa54OMxF5cPyITbmpLwFbHIoAKowzpSzaWT2VyKtu1SOIDc=; 20:wCG+gLBUwpKAw95JCbamK1D1Tdu5ZuwUMWTIK5Wh5Ri/HXe3F2mYsronUJuTLRH+oEXT1afXQdtym0oKnfO7lw== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2015 08:28:56.1422 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0301MB0886 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151103_002920_415682_BC845C60 X-CRM114-Status: GOOD ( 18.66 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: inux-doc@vger.kernel.org, linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Enable set_pretimeout interface and trigger the pretimeout interrupt before watchdog timeout event happen. Signed-off-by: Robin Gong --- drivers/watchdog/imx2_wdt.c | 58 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c index 0bb1a1d..06631cf 100644 --- a/drivers/watchdog/imx2_wdt.c +++ b/drivers/watchdog/imx2_wdt.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -52,12 +53,18 @@ #define IMX2_WDT_WRSR 0x04 /* Reset Status Register */ #define IMX2_WDT_WRSR_TOUT (1 << 1) /* -> Reset due to Timeout */ +#define IMX2_WDT_WICR 0x06 /*Interrupt Control Register*/ +#define IMX2_WDT_WICR_WIE (1 << 15) /* -> Interrupt Enable */ +#define IMX2_WDT_WICR_WTIS (1 << 14) /* -> Interrupt Status */ +#define IMX2_WDT_WICR_WICT 0xFF /* Watchdog Interrupt Timeout */ + #define IMX2_WDT_WMCR 0x08 /* Misc Register */ #define IMX2_WDT_MAX_TIME 128 #define IMX2_WDT_DEFAULT_TIME 60 /* in seconds */ #define WDOG_SEC_TO_COUNT(s) ((s * 2 - 1) << 8) +#define WDOG_SEC_TO_PRECOUNT(s) ((s) * 2) /* set WDOG pre timeout count*/ struct imx2_wdt_device { struct clk *clk; @@ -80,7 +87,8 @@ MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (default=" static const struct watchdog_info imx2_wdt_info = { .identity = "imx2+ watchdog", - .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, + .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE + | WDIOF_PRETIMEOUT, }; static int imx2_restart_handler(struct notifier_block *this, unsigned long mode, @@ -207,12 +215,49 @@ static inline void imx2_wdt_ping_if_active(struct watchdog_device *wdog) } } +static int imx2_wdt_set_pretimeout(struct watchdog_device *wdog, + unsigned int new_timeout) +{ + struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog); + u32 val; + + regmap_read(wdev->regmap, IMX2_WDT_WICR, &val); + /* set the new pre-timeout value in the WSR */ + val &= ~IMX2_WDT_WICR_WICT; + val |= WDOG_SEC_TO_PRECOUNT(new_timeout); + + regmap_write(wdev->regmap, IMX2_WDT_WICR, val | IMX2_WDT_WICR_WIE); + + wdog->pretimeout = new_timeout; + + return 0; +} + +static irqreturn_t imx2_wdt_isr(int irq, void *dev_id) +{ + struct platform_device *pdev = dev_id; + struct watchdog_device *wdog = platform_get_drvdata(pdev); + struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog); + u32 val; + + regmap_read(wdev->regmap, IMX2_WDT_WICR, &val); + if (val & IMX2_WDT_WICR_WTIS) { + /*clear interrupt status bit*/ + regmap_write(wdev->regmap, IMX2_WDT_WICR, val); + panic("pre-timeout:%d, %d seconds remained\n", wdog->pretimeout, + wdog->timeout - wdog->pretimeout); + } + + return IRQ_HANDLED; +} + static const struct watchdog_ops imx2_wdt_ops = { .owner = THIS_MODULE, .start = imx2_wdt_start, .stop = imx2_wdt_stop, .ping = imx2_wdt_ping, .set_timeout = imx2_wdt_set_timeout, + .set_pretimeout = imx2_wdt_set_pretimeout, }; static const struct regmap_config imx2_wdt_regmap_config = { @@ -229,6 +274,7 @@ static int __init imx2_wdt_probe(struct platform_device *pdev) struct resource *res; void __iomem *base; int ret; + int irq; u32 val; wdev = devm_kzalloc(&pdev->dev, sizeof(*wdev), GFP_KERNEL); @@ -294,6 +340,16 @@ static int __init imx2_wdt_probe(struct platform_device *pdev) goto disable_clk; } + irq = platform_get_irq(pdev, 0); + if (irq > 0) { + ret = devm_request_irq(&pdev->dev, irq, imx2_wdt_isr, 0, + dev_name(&pdev->dev), pdev); + if (ret) { + dev_err(&pdev->dev, "can't get irq %d\n", irq); + goto disable_clk; + } + } + wdev->restart_handler.notifier_call = imx2_restart_handler; wdev->restart_handler.priority = 128; ret = register_restart_handler(&wdev->restart_handler);