From patchwork Tue Nov 3 08:28:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Gong X-Patchwork-Id: 7540771 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 8FE5F9F4F5 for ; Tue, 3 Nov 2015 08:32:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A401B201EF for ; Tue, 3 Nov 2015 08:32:19 +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 AE0B720899 for ; Tue, 3 Nov 2015 08:32:18 +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 1ZtWzR-0001fh-E9; Tue, 03 Nov 2015 08:30:49 +0000 Received: from mail-bl2on0102.outbound.protection.outlook.com ([65.55.169.102] helo=na01-bl2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZtWzG-0001H7-4K for linux-arm-kernel@lists.infradead.org; Tue, 03 Nov 2015 08:30:40 +0000 Received: from BY2PR03CA065.namprd03.prod.outlook.com (10.141.249.38) by SN2PR03MB093.namprd03.prod.outlook.com (10.255.175.157) with Microsoft SMTP Server (TLS) id 15.1.312.18; Tue, 3 Nov 2015 08:30:15 +0000 Received: from BN1AFFO11FD014.protection.gbl (2a01:111:f400:7c10::105) by BY2PR03CA065.outlook.office365.com (2a01:111:e400:2c5d::38) with Microsoft SMTP Server (TLS) id 15.1.312.18 via Frontend Transport; Tue, 3 Nov 2015 08:30:14 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) 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.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD014.mail.protection.outlook.com (10.58.52.74) with Microsoft SMTP Server (TLS) id 15.1.318.9 via Frontend Transport; Tue, 3 Nov 2015 08:30:14 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id tA38U7eA003078; Tue, 3 Nov 2015 01:30:11 -0700 From: Robin Gong To: , , Subject: [PATCH v3 2/2] watchdog: imx2_wdt: add set_pretimeout interface Date: Tue, 3 Nov 2015 16:28:14 +0800 Message-ID: <1446539294-15419-2-git-send-email-b38343@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1446539294-15419-1-git-send-email-b38343@freescale.com> References: <1446539294-15419-1-git-send-email-b38343@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD014; 1:nnxIUBUovWktjTIKfo+zR3Zn2IfSI94//JFB6+RkdralVqLjHCKbMDTSwA8O0EtHpiN26w2Oj4TgC9WZT+ZiTM/DxIIDY7l2I0JbfB9E/ql/TYZDeYYV9zV0ECBttBLma/53h2+j/S9n+yPWpGhDpQvH9KotXOdwgaFYK4VKfmPQfNVsg9jl9tPcwQoMvUS3PkJFjKILeaZS0sgKQ+8DLey5JUWCJgIzP7JaWozVbBvyR8ylt+0rbQ7TP8B/fCiDxDeF7/fQuMGh83iS4wdAO4vASG/B+DyrhvWaj8RrD7BCb7d5ZO1nTzGpmERjP/OuL0LTcOcrD+cvmtor4ElzQK7mDQQItamz+i0SqesdsPynL6HE9EHlvz9J0Qdd5T13 X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(50226001)(77096005)(33646002)(104016004)(2201001)(6806005)(47776003)(5007970100001)(97736004)(5001770100001)(19580405001)(81156007)(19580395003)(106466001)(229853001)(105606002)(87936001)(50466002)(2950100001)(36756003)(48376002)(11100500001)(5003940100001)(85426001)(5001960100002)(76176999)(5008740100001)(92566002)(189998001)(50986999)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:SN2PR03MB093; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB093; 2:8PKa8tyB2fuiAXUH9/wcjFDlk18NtuFDDGDSAT04+NxbsMxaGi1qydYNP/797tc02xDdBVJN54Fkz5FIe1Vl+Xtr+Vm2yp8RkP7I3Q5546TYEudipN9yijj+JsU50jblq5WrX/oyGtj5TiVF8RZJpVk46dVXW6mHPOSTApouIhA=; 3:tzpNk/AUME8CoIq4zjwiGPTHIgBhd4J72uMNGte+5uuAy11IZ7Vt27AAxg5TRPHY2i+OcAgK43Gtu24dcxQ3xVUle+GORyJegZgyDaZ2/lnUjBFk7T/bHZm7vFbxe5Bzl5enoyYzc35kxqGXOaHrU5++YL7UVWGSEaZuJTp6NGNYxWtPKKxfNuxug0p6fnDx/AiHXZ91+1MlqyXEVlPV+Y1phZbhKSTE98Jw3olWeZg=; 25:Zi3KmK0laX2Y0ulDe9RuhTZ2BVyInucyr8rQ4KK2gQlHVZcOtYHGamhYfnSOEnHdbgB7o2odBHgxN22oPefZD1nfvCi4GmPB/AwGUgXsWrzz4XiIsBaakx4Sj0blKbr58ummDjYUkqvkhjSmJjmNODZNp1RUT/yX+Oe9W85fardpyteyI+DX9FJraH95xYiihhCiw/7VrFcjBMcRqHKTjEyDQQNCKxf+0vvDyM48B24pRWsNFt+hKLMof2fH+1jXowWvnknzKOMcQ92kL+uh+Q== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN2PR03MB093; X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB093; 20:1ndYrcgkkaG+FJ6QFy7gyq7LMZkm2DGLHr4X8Q1zCgqi4vNX1Zu6mr212wdRTbQcCCaAjsOeNDkP1AW4236J6Hlf9B89PRlcjc8JLEONe7uIOkY9xEedEkTL3R54HdyutpIzzUgQswn4iRxHJSYpZ6EdCp8wbxbJaaS3ucbNP1o/8Usle3ZLRWUt30eYeb/t2WuUeTuLlZgjnDrKEXduCPhbyIEygfhtdWKTq8riNaseE9FMBInI2A/ICMLchF0b2je+2Gh0EO0LHuuTFTJuoXfmiOlC476tAbBUn/9SWvo0wTNSalH/H8MtCPGO8fp8R9rstxfTCSxBi0rGu449+D5w65dqVqa+RZpOhLwH7Ls=; 4:UoHjcgRXu5BZ75LOL65cG9gIOMHbvPWQndypIEUo4C1yvwa2qLhvHOh9dUOk6Rc5wyVFXu2KlZX4pgllxfxgx/95BnnZDjaZEHKjGOf4fFZTXh70Rs1bfZDNZIIdZANlVzJAgk/UmT2q3PL/ySGikzG+9DEDVxmT+OZnQenb5SWt5GGjGUdx5MD9WOmUIdRkVjVm/ljHBZ3m8q+FwfcaadJ9tod+sdq/X0QLVD+maVzWB5puwS/LJw47jvSIEJjSTdttyPwDvz/bcn1s10o3WPxcz4J7ToUShKlXxjMd8lKGzyWm3U5D+aNSd3WNROUG5CZh9fxtJLtfft4EAf79i5t4hGPP51bzossdpUhPL2NlmHe/9NV2KCZnx6aclL0M X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(520078)(5005006)(10201501046)(3002001); SRVR:SN2PR03MB093; BCL:0; PCL:0; RULEID:; SRVR:SN2PR03MB093; X-Forefront-PRVS: 0749DC2CE6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN2PR03MB093; 23:ukUA7g+yW/topWudTKfW6kGKHJFU2H6VaxybUWBNPn?= =?us-ascii?Q?g6nH6lk/LJDXeXTVf5QIePRiSNL/vKOFL3L5RcpXsdUuJ4RolNHa00wlv7xs?= =?us-ascii?Q?650QsOy3+oov9tnQqAqFuYgfWwD0fk8mIFEPE/J46nxb8tCCjdXOnQ9buq7o?= =?us-ascii?Q?ClHW90M8xRXVidiW7bnTrLnH7O3O8Lzfq5V5Podjd8fHRDX1yArMMf+F+EJ9?= =?us-ascii?Q?FY9RvEUqIOI8jESjIy6Gt4WQr90u185XnNHm363UPT+cf7Sb5M+F6w5+mEa9?= =?us-ascii?Q?YXnPVj8YA8Po2GIKszrpzy47GOMQkbDKyv8uXvxDB/cu+xto46+Flt8Q1tb0?= =?us-ascii?Q?ZdXvtJ8lzuql8qlpdq1OsAlhUsqEQjfNufo5XvJLrqDiPL1eSZ71Ts6FEmH9?= =?us-ascii?Q?zWa4rYrJL7RihSOkavIk8jxQQS3c8MGzGfdaxXyL+ZNoaklTELkAgBuWDYXq?= =?us-ascii?Q?Uv5nyMjdxzwUNG11PQcJOhilc4Ss6DgdZSt2iF9lUS0wi+QsEh5nFSNqaQnl?= =?us-ascii?Q?Ia6kiRpUdxbFE96Ii5I0VCNwreiqqcXe/xqseWpamNTiHajwDolCxHRL6/vF?= =?us-ascii?Q?Gwnccu0hkzwv6ZoEF+lR63pDz884l8m1L7OYHEwmXdMv+DabYjaYHHkG/qlF?= =?us-ascii?Q?yofJx90hXK2m8G56jybx+pmjqPO/r9PnG6onfwMHcE/mpgX0gXh+sSWMjui6?= =?us-ascii?Q?CiAJkM6UzZOtQq3EpFsj3iX2rGuk8Kx+vNxJZreaQpitIDeML9EWlocPuJt+?= =?us-ascii?Q?Zd9UdOVkKlgAzQF9KFVyck7QjKMCV5r2ucGYvPGPvVtuU3sMF/JsVg9HWwI+?= =?us-ascii?Q?oLtntCP3Qjpl6kMRAzIhzFZB47Pkp1F+Vgzo9+IUG4dS7PHobY2tWAWcjXMe?= =?us-ascii?Q?ZyvU/EgRN+Dk56lgOchukSYxrF4IgmWvx4yaDILE93DrXWorOFkqUYMAqQCj?= =?us-ascii?Q?vmaykEvpE+KQAyQvZtz9xWflCTweucg+3jYZE2RT87wc6cTcN+KdBY18Zw1Z?= =?us-ascii?Q?uiyeYiw2lkLN5myvZQARG+lgwjQygnj8z9vpNBsWRixFa5iaq9VWYiBUmTNR?= =?us-ascii?Q?yIwxE=3D?= X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB093; 5:guXt7gu881t4wV1eGLez/Svs4tjs8sW3ia5zJ9YSb/Dl/b9p+cQD3MgxNKEBlyYogHWB/paG5VgWVdD57aSwL1zXZW1yGijxSdmpQ0uIvLOJpWFB4U3rPQNSB4bCZ+mp01Vm+zhJdYvfgUhcQZ4yHA==; 24:FA9w2oZsGF3iZSr1CwnSlWaNzg7wjDjm0K0di8dKns7+NhQ4afuq0EtChYk1g1mIUis9sntStyLFypY8U+no43krTbr++RJTSqw2WQjMwN8=; 20:jlr+5JNYybSujSxxQ5AOtRCIXFzTwLhGBd3Nw6lq/hzn5rKyruDRO2kcVb7ieMU8fuYUWQvFFp3/YJvOgYWcLA== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2015 08:30:14.0298 (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.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB093 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151103_003038_607168_9B3A87D4 X-CRM114-Status: GOOD ( 22.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: linux-kernel@vger.kernel.org, linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-doc@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);