From patchwork Tue Nov 3 03:29:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Gong X-Patchwork-Id: 7539601 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 010049F327 for ; Tue, 3 Nov 2015 03:34:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1E43B2072B for ; Tue, 3 Nov 2015 03:34:50 +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 1016520729 for ; Tue, 3 Nov 2015 03:34:49 +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 1ZtSKF-0002xm-Ui; Tue, 03 Nov 2015 03:31:59 +0000 Received: from mail-bn1on0148.outbound.protection.outlook.com ([157.56.110.148] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZtSK5-0002uH-Hl for linux-arm-kernel@lists.infradead.org; Tue, 03 Nov 2015 03:31:50 +0000 Received: from BLUPR03CA009.namprd03.prod.outlook.com (10.255.124.26) by SN2PR03MB094.namprd03.prod.outlook.com (10.255.175.158) with Microsoft SMTP Server (TLS) id 15.1.318.15; Tue, 3 Nov 2015 03:31:27 +0000 Received: from BL2FFO11FD051.protection.gbl (10.255.124.4) by BLUPR03CA009.outlook.office365.com (10.255.124.26) with Microsoft SMTP Server (TLS) id 15.1.312.18 via Frontend Transport; Tue, 3 Nov 2015 03:31:27 +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 BL2FFO11FD051.mail.protection.outlook.com (10.173.161.213) with Microsoft SMTP Server (TLS) id 15.1.318.9 via Frontend Transport; Tue, 3 Nov 2015 03:31:27 +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 tA33VLrE017585; Mon, 2 Nov 2015 20:31:25 -0700 From: Robin Gong To: Subject: [PATCH v1 2/2] watchdog: imx2_wdt: add set_pretimeout interface Date: Tue, 3 Nov 2015 11:29:27 +0800 Message-ID: <1446521367-25748-2-git-send-email-b38343@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1446521367-25748-1-git-send-email-b38343@freescale.com> References: <1446521367-25748-1-git-send-email-b38343@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD051; 1:2xu+qttkELFfUkyVFbCl/FKc/NwOL2ut89pOrlEqqHpxLioobW1bEn99+fx52sAPm9VLuCGk93x3jw5fLkY3ZpPChtq91yLzzYAR2KLqF5VcW7aOJ7Vzn3QM1373Q1r1yxJ+wiHOVF6puJCITtalStm8vPA256g+Vkrqo3YBOww18jMcs1Es8rQkVzDyvSllKQtcVjigfg8CPfU1rQJESijLQembpUkJ83bHFmQt8D/6gMVQTW9EpOgAWzcSV55oovzyqlWkv6CEJlkhWmGUlbB11choeKYaOLoAMY0aCwnuKyTZofrC7HEl2RD5zhEIBxkPmtv4epiK1cTtn1Vv71vwFsY/9epMdIUV1gI7NBYSMMTCx6s/XSYj1DiWeUVt X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(11100500001)(76176999)(50226001)(85426001)(50466002)(48376002)(87936001)(106466001)(2351001)(50986999)(33646002)(229853001)(47776003)(105606002)(5007970100001)(5003940100001)(110136002)(5001960100002)(189998001)(92566002)(5001920100001)(5008740100001)(6806005)(36756003)(2950100001)(97736004)(77096005)(81156007)(19580405001)(104016004)(19580395003)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:SN2PR03MB094; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB094; 2:8h2Y1eFVfic33RBeCEvjVSnVIHhKwtP8/dQVKfoc5chSWgebuMroc6Nd8B/t0VipcDKsB56k6vVLtR6nQ9IUUjjKGt/mK5jPPDGTUIp/bYlPnCwqqVNauBw+hWXsBoLVFEXNMKHMg4bHzt1bwYxzIcwpoZ8YcyrevHNahvbotq8=; 3:OgnRJcjLd9WpAxFv8hA2WPK6Pdgm2x8uR8Ve/V/LUtsmp8d9SJn3u35S9XGRxMUPlWoaoHKJ4V9yk3cQ6yAc79BV7npj80DEm77NcK8N2Xqh+wRO0ToVDWC/hdHdnZoSDO8bly24h/z63vEyNtJXBul98dJqo7MBcxcrBY93MRX/ccCov5gGzcxhRo9SXEXaDy6ulqWMvcPa8zXjnmpW/y+8NFb2MaAECNB92HMkFgA=; 25:dD570ScHfAY7DUgxvxzJuBVAAvF6NVmSZaN03HJMi4E5O8FLVl4vBvbw+mQqmKzzwkdVlaNbyrNLihNJs5sZghAmFcso2ubUmK+td11r18aENfMRexUdWXfjCAXpsZoudr5X/mMVD0CPBO9ITANFfgQ5BxeLMP/dkDipIl6ajmjEv83zucX1hcmLkgndJPGcjt0bIOOEQHZnLYXdYbjfqavEwNBR/a7jtyzOK8H1qui/aHhXwC8V9KuCSE/sDgI/Ujhsh6M43SXh8avVgUwQjQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN2PR03MB094; X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB094; 20:TvweVhDrwiKuZfsAhinDt1BuuEMB6aBGyiqjTtIWEFxRk+LGcU2/hwg+UiMGePmKM+rFWHwIWYwuXKiu/U1RB3JTk/PyKTHP/kNH6Qb248a59Ys0U4PXLiUcQFbheJmMXo3Gb2Vg7Y6WAONK1daTZu3SYsuiQdkqgjvYJHHM3GmjHM3jj8YdvDDa5x/LyJZsEAiY/GjunqB/95ojIVlGXbIdBGVsE85ewqcgl8nK1+VpoOhuSTIlFilJ/QZQ0WhRIcX4Vwwnx5oBSBS+xSTl3C/rtm3QhtkQRIR33o3YgjsAI8RJTfGVE+39jm6UlES7XsVWRRRoFQrkGLyrv9QMUk4DretZY1euNRuB7iIVAl8=; 4:O0j4e27FVkU++ZE4bM1gliwBou1jO/6dyMYZTnYynsok9sHTS6NZ3H2si5bsbgXWbwKzwLBKDdslx7IG3DQRICHvmFqMIEYFKzx8lanxctDcPG2j19O9lCxE9Kio++HSPE4CwikkNDQPR7msBRa6oM9n0X+wc382l34oSW5YZZul0t6EdHWKDoN6/ib3B2UM/IlydkWOGoT3BuyrQiHuvEaOxYqrEEMF1HzjkGIfHk1lXZzflAR8gvJ2HNbYUdl7/0cFkFTwiQNzE1R5c4QRf7T4tycqnmTFbeP1l+UuVk4OyZ4m6eoToCDrEDiHE0sR58SfPdsdisVt1CsUJj9c10HbidO4JrqwD8FRBpk9yVFUdeEIe6wRJ9GFaEgkGQtzUzDYo7XEHicCnV8jBacWzg== 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)(520078)(8121501046)(3002001)(10201501046); SRVR:SN2PR03MB094; BCL:0; PCL:0; RULEID:; SRVR:SN2PR03MB094; X-Forefront-PRVS: 0749DC2CE6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN2PR03MB094; 23:SvTKq8abgZpvMvOA/d/IMtuyWTWPC7zl4p4lRrjDee?= =?us-ascii?Q?vghuHdXldjGB9/qCmbGjEQr7ZciNP81HCbbGLUdEs6P5tKvYniQl6FsN7grq?= =?us-ascii?Q?o5lkTcTlxfohq6l+dDdhPEduB4Fl5LbYZjYr3fQ+dAoJaCAHODt5B0BOdA92?= =?us-ascii?Q?tsgYg7TMStiSf5IR+cuQAYkBJiphSqnSC2/lR7z9PLNuEEu9E9Ti3zD5rbum?= =?us-ascii?Q?BBYvl95H1lFldf/H9ggmBjAjyS07KK0M6UO4vkE1gjbv8yxwAxhx5qjgYD6O?= =?us-ascii?Q?md/Cws2e6CfrftIWPO1+Ml1Q609cBfzuhgAcPcANdYDQTjZdF2/6/KFHNnkm?= =?us-ascii?Q?LAAVf7AIzTTiJjXUP6ZoGhp+oma8kKVcYo31IeRGkdqY8IUD+x1Ob0bD/Gdg?= =?us-ascii?Q?cAcj8b/JI7XvuyelfrebaPalL9W0outnRvCjPl6O/1/BLplMmNKwmY4P9bdG?= =?us-ascii?Q?K99ydZHDsy6+At4XD9ka/fDaKzSQtAziZ7FgZ+X64pgGxklAsOa3NgHHI0m3?= =?us-ascii?Q?q7cxnX+ZmUha5JQloNX7m3NTETi9la86OoDUmKOmFOQi4SC/3GHM6gsIEcZX?= =?us-ascii?Q?ZtNBkN6Pnty8fkQqJE32ltNAka65jYmiVDFjwH5zLNYtk5+oWwm4LDMjT3M5?= =?us-ascii?Q?YTow+xiACH8HHW/jynQ0TTyaGzGKpWfn/wTdizOVKcFHm+J8JOCsEcX+6WgF?= =?us-ascii?Q?Yw/1aL+uTlyzYkmkP4vwF/UKFp/wZnbTxxzjltwvC6q9HHFY9qvXQbqFo/hh?= =?us-ascii?Q?6mM1M0LKC/XaSc9nfzy4o0DqH/n9IJbBxO2JPWLE7y/S85mqdeQNgSY0VoYg?= =?us-ascii?Q?2/7DNmC5+OA8OYAGby5EM28tQBqI20UAsIHteWCkWo9rYfAob+AcMHEgXWNW?= =?us-ascii?Q?kt0S+Vj0slWocbiHnMOgd54iuxkjrPgU9G99d064XX3CNpUy6+11xp5rquEM?= =?us-ascii?Q?+/Af3E1z174M9KpAuakw/yQP7xnO7Jjl/UxAvGVS1tCKOKohbRivSMn25zBd?= =?us-ascii?Q?qdtXy5CRm6ErrI+pUURL0XWFuN13bYePqvZvczBRE//jMUklX+F7JflhRsym?= =?us-ascii?Q?fXiTWuzMBODlZpyW9wkG0ndd3L?= X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB094; 5:Oeig+ROSHJmU7XYn4sjUMzKhqqo9hS1wtrlEOfQ805CY8tXklbyiRUsDRmVv4/r0ccaq/3uwWOmCKvQteF1Zm1R9CXyhaxjfdgTlKnBhnbzRJAYPs2q35btG6+9xNz6pN/l5L1aKe4V1+rIAxfqaHQ==; 24:MxYiy7FD9obgL3pf1KbJEVeHqe7knNRNVRK6CTAEQ4aD3qQg9iJEzPtK0cC8dZVmStkA6P7K03Dxb3wItO7ajCiDWe2ipbs/oTc2Vk5AxU8=; 20:JPJih7HSFSg7O6pLK5nmDXwYsNrtrsJlc94GwEC1WF6wZaD+eRuSvnS1y+jxRgvO5R1kEYpTppoRdURPO9u3Jg== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2015 03:31:27.1198 (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: SN2PR03MB094 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151102_193149_942044_17BE14DB X-CRM114-Status: GOOD ( 21.13 ) 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 | 67 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c index 0bb1a1d..d3c6b07 100644 --- a/drivers/watchdog/imx2_wdt.c +++ b/drivers/watchdog/imx2_wdt.c @@ -24,7 +24,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -52,12 +54,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 << 0) /* 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 +88,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 +216,59 @@ static inline void imx2_wdt_ping_if_active(struct watchdog_device *wdog) } } +static int imx2_wdt_check_pretimeout_set(struct imx2_wdt_device *wdev) +{ + u32 val; + + regmap_read(wdev->regmap, IMX2_WDT_WICR, &val); + return (val & IMX2_WDT_WICR_WIE) ? 1 : 0; +} + +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); + + if (!imx2_wdt_check_pretimeout_set(wdev)) + val |= IMX2_WDT_WICR_WIE; /*enable*/ + + regmap_write(wdev->regmap, IMX2_WDT_WICR, val); + + 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); + dev_warn(&pdev->dev, "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 +285,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); @@ -253,6 +310,14 @@ static int __init imx2_wdt_probe(struct platform_device *pdev) return PTR_ERR(wdev->clk); } + irq = platform_get_irq(pdev, 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); + return ret; + } + wdog = &wdev->wdog; wdog->info = &imx2_wdt_info; wdog->ops = &imx2_wdt_ops;