From patchwork Tue Nov 3 06:11:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Gong X-Patchwork-Id: 7540081 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 758B1BEEA4 for ; Tue, 3 Nov 2015 06:19:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7FC72207D8 for ; Tue, 3 Nov 2015 06:19:54 +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 7199F207DB for ; Tue, 3 Nov 2015 06:19:53 +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 1ZtUqx-0003HI-0A; Tue, 03 Nov 2015 06:13:55 +0000 Received: from mail-bn1bbn0106.outbound.protection.outlook.com ([157.56.111.106] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZtUqo-0002y3-Je for linux-arm-kernel@lists.infradead.org; Tue, 03 Nov 2015 06:13:48 +0000 Received: from CH1PR03CA009.namprd03.prod.outlook.com (10.255.156.154) by BY2PR0301MB0727.namprd03.prod.outlook.com (10.160.63.17) with Microsoft SMTP Server (TLS) id 15.1.312.18; Tue, 3 Nov 2015 06:13:24 +0000 Received: from BN1BFFO11FD029.protection.gbl (10.255.156.132) by CH1PR03CA009.outlook.office365.com (10.255.156.154) with Microsoft SMTP Server (TLS) id 15.1.312.18 via Frontend Transport; Tue, 3 Nov 2015 06:13:23 +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 06:13:23 +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 tA36DHRO019247; Mon, 2 Nov 2015 23:13:20 -0700 From: Robin Gong To: , Subject: [PATCH v2 2/2] watchdog: imx2_wdt: add set_pretimeout interface Date: Tue, 3 Nov 2015 14:11:24 +0800 Message-ID: <1446531084-15365-2-git-send-email-b38343@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1446531084-15365-1-git-send-email-b38343@freescale.com> References: <1446531084-15365-1-git-send-email-b38343@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD029; 1:V705ybVSqTCOAI+eXfu/63zWbfmrVCey7NFrckAXw0+5MyF3Rs0rENaoCtoQfVnBFwmk3XKY+3xGFMX3efpLYNHm5/7zioh/X76kJ/rVnW6D9CDMg5l8B6Bhl7GEwyzhyCx0htV2wQxhKFofk+TTJZCeEJCJmTspJlBwZEFZeFMteIqsWHnD7UWDMT/+k9IppHQpmRtUaU2ySqHFdCgiGj/WrOYQWByTbfoQ4upkHDZBvgF8AnAEPcyegkUOq3zrUAYTLeW0dEIaRgCwqVbxI7IO2Q0jvE92Yz2oEcCkfhL2/UlVPXaBTgQ3ReF3gsJyG1bvPVts0+QFgxfG+CoAY42pAL0cXlSImtVZIEgMiiwPAh2Xtz7fcBHol51L3mGA X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(50226001)(97736004)(5007970100001)(81156007)(2950100001)(11100500001)(5001770100001)(104016004)(5008740100001)(6806005)(5001960100002)(189998001)(5001920100001)(105606002)(50466002)(106466001)(229853001)(69596002)(48376002)(87936001)(19580405001)(85426001)(36756003)(77096005)(92566002)(5003940100001)(33646002)(50986999)(47776003)(76176999)(19580395003)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR0301MB0727; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0727; 2:y3+HvDfb8MLhCR1+Eu/0GrxtfU+D4cLSuDs8qpAGDizM839be/YZGitzCyUUgXuazvV9oNsXhByTh1eCywo7vA5mVHXLT0aH+f/kJEAQBAx6Z954NI1yAAMml2tyUU7vWG+Omtcde6nr3ilBuOzloANSPszO2ugpSiRl1J8yV+g=; 3:q6+z9dWToZ2i7DwIGnnBkpKU75Dzh8v35ikF62iBB8Y8eHdn/NRmUyVtbIevEMn+d2k6hFTix4sYeA1+ykmWYENZR8D7FaGNhi0FMfbksEGe/9uZ9ciAem+JQMQuVcxxsiBXBMoVOEWFMkFnZWfI51PGucBhIXKdxfBHwcn2cLFbe/pJk/GlCWqRRVZQTMK2MPNh4AM/7e14clZNHRLJfLg7BypAgUplWmM93fprleQ=; 25:haCtsOb4iNN/+rb9rG0CaW7Z2nVJqU6uiyFCvfqDpE1/OTmhK/zNMPbeOG7XDmpoCUqqhRg1sNjf6lIPTL46PL7LJsTr8SKBI7HPNfnakA32XbdypY7JsGzfVBGB7SfhdYZH7rf6KIBt2+dl4rpIO3o+h1SUW/JLMYX9iPiQsj5bzDRS479iUUONWcd+9Nu7cUfDJrRX9WDIdaIHaPb5A5ea4zoFVX+OCQGrfCuN01zuNjhAOeaJZQHkcPFb3/nood6PzMOFtIiGc8Xyq2N/Xg== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR0301MB0727; X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0727; 20:Wx4wzTwuhioelkeZ4mxqhNR3Z54+gNsKa8jLpCctzzmb/RLfwvxx4DvG22r7TV5HCavNYicuLDOKI41AKeE9+RwqOsvWhpY2ys8m8CY2vUtxBXVXDDKaQKzUlB3xb8/vs2hoyDTjaVaAYS3gUpICja2Yl+02scyKCrhONZnEWk2gYGAnFbPsNaxpMxKRzJOphr/5oWBes7yJ51g17Rl2pbZPH5+C9GCsq3Y/LDVjMRZMYmOV1sZKHLBHY3jil9tuEG+lMOvNFzQIanORqHCW1QJ60GnjbHVMoWY7VPqplWbk4WsZnU0I8u4lHdBRF7O2PMy/AD5GiZiaLZOm4hs0HLG+Vs5ghSJkVjyoiXFkxV8=; 4:vmnqGfu3tABfMWnMoCUqPa4mfMBJhVx2cutA59dY09fctPSmC1uxAtwKl17MX2Oy11I9yZtIQgxYOic4b4PfGCQBGYdTpjBYK8CbHHpa8FHZcirK9SY0Kif88OqVJA8k9YnI/2igs+nDgzx7eqqMI5xjm3oPCa9lU5ywc2BPFeh3ocHtn96t19rRqAEg7mjCXF47yB8sCLuxhhb3BX8nhOP5yWsMJFS3wXRfpG1aQZwfpmFI72bpDH6WjXnTIwLP37cYRFNS01d3sHFNZ3Dr0XyjnJqilp3rb642A0W9w78xdm3oJ+Gyc5cVgqFbUJ80NSW8xqEAHLb5rwgNvKlkmJAnoKb9by80QuBUlPk3mcEqdP/MVPgELyA/H7nax/tQ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(520078)(5005006)(8121501046)(10201501046)(3002001); SRVR:BY2PR0301MB0727; BCL:0; PCL:0; RULEID:; SRVR:BY2PR0301MB0727; X-Forefront-PRVS: 0749DC2CE6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR0301MB0727; 23:tyx/Kn3dMnHfiCyS/EKZMeZ1hdA7fQyUArVYWtc?= =?us-ascii?Q?eiozb+VWFMOD6P17XR+dU9TsWHHSXKZEuiNVDxHbUDTgjR/iE4E8VyQuiKq2?= =?us-ascii?Q?4Dlm36ZVq0wZ70PVxR4TSUtCDeqI+0ES3gVQAEWKMvdwfMqWJaxRDaYQ8+GV?= =?us-ascii?Q?O4VRGXTXuXzwPQgeQ3073thPTCpJHgQh+tHzw2HjUDNY3zVfxCLlMO7R1W9h?= =?us-ascii?Q?XbFheAIuLshngTU1hZ37ed0P3k6p5GkR//5JbsSSVJsiSoesECKJpYY5OeDW?= =?us-ascii?Q?1aGQ2Xzv1IfFQXPQTqZ9WopNNQtx6GcnkA8St3rZAd+Djvs1dZ9UJTLhcMR1?= =?us-ascii?Q?JIIkg0kayZThRG2y4b3YhDr0LNTLtrl7FaD5PU2HVvUfL3sPheAqSb3GnBID?= =?us-ascii?Q?FFLB3G0fnR61jmBBFA5p2EOR97j1lJCdcD7OSaLhW1fs60v8OAaRavW8afLa?= =?us-ascii?Q?zHUftmmAUhsdKc2zIP05Oy75aMLC8db84tXqGAN1BAhv/7x7cWz7vtbef3WF?= =?us-ascii?Q?ZQWngWY9S8L6ECztA8ZhvZtWsRcKYrAiuE0XcIYagTQoI1ZJhli8NLzQ03xf?= =?us-ascii?Q?929lmE0BU8HChuOc8v7W3+Xg/4NSBy/Tru+Pk8eXUfhYltis5AHV2MlBoRi4?= =?us-ascii?Q?j94GzeOOh+AElyiiubwexeeUWvebOwq9JrTRv5kkDYvQrz0NiQRb2lIPDp4U?= =?us-ascii?Q?2o1X/DyyGnmoAuIMWVZQ3QFxAvs9lDO2BZHT6BHLDiL5OlGtgcbTOfPLQEEN?= =?us-ascii?Q?gDcVQPCkGo2AL4RBqschW0TEFMujoHVePcj7JPSmfiZI8RbjtxXusljEjQte?= =?us-ascii?Q?bmBeLf+89tl3vyUyAz9VNwsnBLXhFEw/BOslEXz5zv/MWBhrhDs3buwdi+yR?= =?us-ascii?Q?YzvotTkZ2mJ6NWivk7ZPPeb65rAPYmYhL3Ew7lYHTjiVSOtLkH+mgy8PiQpR?= =?us-ascii?Q?14+ksWGrxwAMUwtWZk79S03Op725MBBi9RcoEjfrOHMGWKv0sOKVjeU8DVLx?= =?us-ascii?Q?GCzCuhagDSEiqjseLLoxacsvs1+rWRyt/ASdd21Eu0FN9X3E2TO5BhmLyXu+?= =?us-ascii?Q?CZo4P3Qg43W/TZ7MpGWZIgE7hnL7G?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0727; 5:V+4e2iLrr3MikOeInEyqz54QZrYpplMRRLvKGHwNKYNEZwgRBvaE6SqMeCi9DvFd1D+35PY8Sn27W0svyoCgas2dkOUHNXMmdakDvtuvzP25j+znAD+hCpseTH0+eMn5IFi4qCD0ht6SQdmFIKI7Pg==; 24:B0zTcbKTA34J84sHNk4FEfDUWP3Ji4TJsoYMhCw/Cmn7+trCs7obSUJgLoKt43sjcx8o6i7kZZUUytKyZ206LnTxHBfSevBn5SZa8SfMMrM=; 20:kKzInCDi2G9Ko8rY/r/Sl402QMZtSnsd8c8EAifwbpm1ailsVRsVp/l0XEYE6NEd0mZMVBYOPE+uqLc8MGaKzw== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2015 06:13:23.7609 (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: BY2PR0301MB0727 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151102_221346_962066_06F9312F X-CRM114-Status: GOOD ( 18.04 ) 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-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..bd42857 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);