From patchwork Thu Apr 25 01:14:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anson Huang X-Patchwork-Id: 10915931 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EC379922 for ; Thu, 25 Apr 2019 01:14:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4FF028AE0 for ; Thu, 25 Apr 2019 01:14:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7FB428B83; Thu, 25 Apr 2019 01:14:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D41328AE0 for ; Thu, 25 Apr 2019 01:14:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728742AbfDYBO3 (ORCPT ); Wed, 24 Apr 2019 21:14:29 -0400 Received: from mail-eopbgr50055.outbound.protection.outlook.com ([40.107.5.55]:39075 "EHLO EUR03-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728694AbfDYBO3 (ORCPT ); Wed, 24 Apr 2019 21:14:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fQmTqUEQ4Se4l3OkB66vvOLpPWden9Z0y2j/2fcbKp4=; b=t1E8NWpu4lVHvc6mifi6lcsGdIh6SrgNtfJPv1HdeaYWtINV3xOZzzokNPpYXmxAVubnt///RvM1AKsghXalf9r2Jv4b6DE88mjJ4pjdceYulT5yn4wZW0SF0BMeZQGlb2nNzn7zel20n1t7SoOgB3ZLZkbwTGisNkV+S+lof/k= Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com (52.134.72.18) by DB3PR0402MB3788.eurprd04.prod.outlook.com (52.134.72.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1813.18; Thu, 25 Apr 2019 01:14:23 +0000 Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::e8ca:4f6b:e43:c170]) by DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::e8ca:4f6b:e43:c170%3]) with mapi id 15.20.1835.010; Thu, 25 Apr 2019 01:14:23 +0000 From: Anson Huang To: "shawnguo@kernel.org" , "s.hauer@pengutronix.de" , "kernel@pengutronix.de" , "festevam@gmail.com" , "wim@linux-watchdog.org" , "linux@roeck-us.net" , Aisheng Dong , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "linux-watchdog@vger.kernel.org" CC: dl-linux-imx Subject: [PATCH 1/2] firmware: imx: SCU irq should ONLY be enabled after SCU IPC is ready Thread-Topic: [PATCH 1/2] firmware: imx: SCU irq should ONLY be enabled after SCU IPC is ready Thread-Index: AQHU+wQ3bxGkLXDjYkSt99sp4EdO4Q== Date: Thu, 25 Apr 2019 01:14:23 +0000 Message-ID: <1556154581-31890-1-git-send-email-Anson.Huang@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: HK0PR03CA0058.apcprd03.prod.outlook.com (2603:1096:203:52::22) To DB3PR0402MB3916.eurprd04.prod.outlook.com (2603:10a6:8:10::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=anson.huang@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.66] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b5121134-f1c0-44c5-af66-08d6c91b59e5 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020);SRVR:DB3PR0402MB3788; x-ms-traffictypediagnostic: DB3PR0402MB3788: x-microsoft-antispam-prvs: x-forefront-prvs: 0018A2705B x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(136003)(366004)(346002)(376002)(396003)(39850400004)(199004)(189003)(68736007)(36756003)(256004)(478600001)(8936002)(50226002)(2201001)(5024004)(14454004)(97736004)(86362001)(316002)(6486002)(110136005)(66476007)(66446008)(64756008)(66556008)(73956011)(476003)(53936002)(6506007)(8676002)(2616005)(186003)(66946007)(66066001)(305945005)(102836004)(26005)(7736002)(6116002)(486006)(25786009)(2501003)(4326008)(386003)(52116002)(99286004)(81166006)(6436002)(81156014)(6512007)(3846002)(71190400001)(5660300002)(2906002)(71200400001)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DB3PR0402MB3788;H:DB3PR0402MB3916.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: xCJMX4DWnl6hcTcn/2+GY235Mlki70ZUezzcT2h8MSYni9fqcifawRnb5/u15gNUAYyDeBg4ti8mnfcKb6TJ6O51Nvd7NHUDsiX5CR6yFhr4lyOS6i5i06SzCqrD6bC/j9SpUD1CQZDA8e4RPSzEgU5gxNc/rW+NZBRqnGDhO0ke6EZDqTBy0aIdM/ZEjszxI6lMkaSNAcIJg8Cc7PfBGFNu1PTbNZ6lOR03KAmrhijj2Wd43DllcL1c9tL4EHhsmX5BW0aU2ymlNvtp+e3TOexS/S3NaZ+HCMlPyO1pni1KnI6VjGOtZOekqjaBquV2BepWDuuSrvkwoJl3ZEL076HKeBm5u6ndsxnYW67h/s44rTOmk7YG3aKyV/8v5Br9ITKH1NPKTWlwGkL7LHO0luG3XlmTo//moG7Owx2+Dto= MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b5121134-f1c0-44c5-af66-08d6c91b59e5 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Apr 2019 01:14:23.7794 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0402MB3788 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The imx_scu_irq_group_enable() is normally called during module driver probe phase to enable SCU group irq, e.g., i.MX system controller watchdog driver will call it during its driver probe phase, as i.MX system controller watchdog driver does NOT need SCU IPC handle for operations, so it could be probed before i.MX SCU IPC is ready, and below dump will show out: [ 0.933001] Hardware name: Freescale i.MX8QXP MEK (DT) [ 0.938129] pstate: 60000005 (nZCv daif -PAN -UAO) [ 0.942907] pc : imx_scu_call_rpc+0x114/0x158 [ 0.947251] lr : imx_scu_irq_group_enable+0x74/0xc4 [ 0.952113] sp : ffff00001005bae0 [ 0.955415] x29: ffff00001005bae0 x28: ffff0000111bb0a0 [ 0.960712] x27: ffff00001140b000 x26: ffff00001111068c [ 0.966011] x25: ffff0000111bb100 x24: 0000000000000000 [ 0.971311] x23: ffff0000113d9cd8 x22: 0000000000000001 [ 0.976610] x21: 0000000000000001 x20: ffff80083b51a410 [ 0.981909] x19: ffff000011259000 x18: 0000000000000480 [ 0.987209] x17: 000000000023ffb8 x16: 0000000000000010 [ 0.992508] x15: 000000000000023f x14: ffffffffffffffff [ 0.997807] x13: 0000000000000018 x12: 0000000000000030 [ 1.003107] x11: 0000000000000003 x10: 0101010101010101 [ 1.008406] x9 : ffffffffffffffff x8 : 7f7f7f7f7f7f7f7f [ 1.013706] x7 : fefefeff646c606d x6 : 0000000000000000 [ 1.019005] x5 : ffff0000112596c8 x4 : 0000000000000008 [ 1.024304] x3 : 0000000000000003 x2 : 0000000000000001 [ 1.029604] x1 : ffff00001005bb58 x0 : 0000000000000000 [ 1.034905] Call trace: [ 1.037341] imx_scu_call_rpc+0x114/0x158 [ 1.041334] imx_scu_irq_group_enable+0x74/0xc4 [ 1.045856] imx_sc_wdt_probe+0x24/0x150 [ 1.049766] platform_drv_probe+0x4c/0xb0 [ 1.053762] really_probe+0x1f8/0x2c8 [ 1.057407] driver_probe_device+0x58/0xfc [ 1.061490] device_driver_attach+0x68/0x70 [ 1.065660] __driver_attach+0x94/0xdc [ 1.069397] bus_for_each_dev+0x64/0xc0 [ 1.073220] driver_attach+0x20/0x28 [ 1.076782] bus_add_driver+0x148/0x1fc [ 1.080601] driver_register+0x68/0x120 [ 1.084424] __platform_driver_register+0x4c/0x54 [ 1.089120] imx_sc_wdt_driver_init+0x18/0x20 [ 1.093463] do_one_initcall+0x58/0x1b8 [ 1.097287] kernel_init_freeable+0x1cc/0x288 [ 1.101630] kernel_init+0x10/0x100 [ 1.105101] ret_from_fork+0x10/0x18 [ 1.108669] ---[ end trace 9e03302114457de9 ]--- [ 1.113296] enable irq failed, group 1, mask 1, ret -22 To avoid such scenario, return -EPROBE_DEFER in imx_scu_irq_group_enable() API if SCU IPC is NOT ready, then module driver which calls this API in probe phase will defer probe after SCU IPC ready. Fixes: 851826c7566e ("firmware: imx: enable imx scu general irq function") Signed-off-by: Anson Huang --- drivers/firmware/imx/imx-scu-irq.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/firmware/imx/imx-scu-irq.c b/drivers/firmware/imx/imx-scu-irq.c index 043833a..687121f 100644 --- a/drivers/firmware/imx/imx-scu-irq.c +++ b/drivers/firmware/imx/imx-scu-irq.c @@ -100,6 +100,9 @@ int imx_scu_irq_group_enable(u8 group, u32 mask, u8 enable) struct imx_sc_rpc_msg *hdr = &msg.hdr; int ret; + if (!imx_sc_irq_ipc_handle) + return -EPROBE_DEFER; + hdr->ver = IMX_SC_RPC_VERSION; hdr->svc = IMX_SC_RPC_SVC_IRQ; hdr->func = IMX_SC_IRQ_FUNC_ENABLE; From patchwork Thu Apr 25 01:14:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anson Huang X-Patchwork-Id: 10915933 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7181F922 for ; Thu, 25 Apr 2019 01:14:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6567C28AE0 for ; Thu, 25 Apr 2019 01:14:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5895B28BE4; Thu, 25 Apr 2019 01:14:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B91EE28AE0 for ; Thu, 25 Apr 2019 01:14:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387410AbfDYBOd (ORCPT ); Wed, 24 Apr 2019 21:14:33 -0400 Received: from mail-eopbgr50055.outbound.protection.outlook.com ([40.107.5.55]:39075 "EHLO EUR03-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728712AbfDYBOd (ORCPT ); Wed, 24 Apr 2019 21:14:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GMrGsHFSr84jVLmd4m/2/B64dNSw1UWjdhzur/Lzdgg=; b=FbTCRrC9gUtB8P4v5gq/b3ayg6tehB9JFaht5HuVsq0jTeZqyb9i74bI7vJA9sqFIcGZqP1nqin0MU9HNi1HcgDrx9aP+qq/NFg+iGC4Mz8oDnY09kbLEbRLwrdZr39XQ6Pz/Kzz3FafY8SmM1KsMOs5pUxpgyhUcKTnPRwCxkQ= Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com (52.134.72.18) by DB3PR0402MB3788.eurprd04.prod.outlook.com (52.134.72.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1813.18; Thu, 25 Apr 2019 01:14:27 +0000 Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::e8ca:4f6b:e43:c170]) by DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::e8ca:4f6b:e43:c170%3]) with mapi id 15.20.1835.010; Thu, 25 Apr 2019 01:14:27 +0000 From: Anson Huang To: "shawnguo@kernel.org" , "s.hauer@pengutronix.de" , "kernel@pengutronix.de" , "festevam@gmail.com" , "wim@linux-watchdog.org" , "linux@roeck-us.net" , Aisheng Dong , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "linux-watchdog@vger.kernel.org" CC: dl-linux-imx Subject: [PATCH 2/2] watchdog: imx_sc: Add pretimeout support Thread-Topic: [PATCH 2/2] watchdog: imx_sc: Add pretimeout support Thread-Index: AQHU+wQ67HfMfWtsaUW0yczuADoMLQ== Date: Thu, 25 Apr 2019 01:14:27 +0000 Message-ID: <1556154581-31890-2-git-send-email-Anson.Huang@nxp.com> References: <1556154581-31890-1-git-send-email-Anson.Huang@nxp.com> In-Reply-To: <1556154581-31890-1-git-send-email-Anson.Huang@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: HK0PR03CA0058.apcprd03.prod.outlook.com (2603:1096:203:52::22) To DB3PR0402MB3916.eurprd04.prod.outlook.com (2603:10a6:8:10::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=anson.huang@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.66] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 84f21954-e104-42af-7ab9-08d6c91b5c79 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020);SRVR:DB3PR0402MB3788; x-ms-traffictypediagnostic: DB3PR0402MB3788: x-microsoft-antispam-prvs: x-forefront-prvs: 0018A2705B x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(136003)(366004)(346002)(376002)(396003)(39850400004)(199004)(189003)(68736007)(36756003)(256004)(478600001)(8936002)(50226002)(76176011)(2201001)(14444005)(14454004)(97736004)(86362001)(316002)(6486002)(110136005)(66476007)(66446008)(64756008)(66556008)(73956011)(476003)(53936002)(6506007)(8676002)(2616005)(186003)(66946007)(66066001)(305945005)(446003)(11346002)(102836004)(26005)(7736002)(6116002)(486006)(25786009)(2501003)(4326008)(386003)(52116002)(99286004)(81166006)(6436002)(81156014)(6512007)(3846002)(71190400001)(5660300002)(2906002)(71200400001)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:DB3PR0402MB3788;H:DB3PR0402MB3916.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 6p2124/KYgVXesqg3JxYO51SMfxkMLzo65nl+90aSsTRjw+eeUUEe5W1pJdWscAUKN/ZIS+FJXfswnMEZ5NwcdzVH10D9PAdi/yu3Y4asTJMOFvmw29/olJPBeWZj4kC+0w4yLaFt9iJcCwO+ysCSSHBOuUEsoecLcxcLi8KMgrhcdTcZzqL8MRf0jVHHHu0mfU9K0QVLIy+d+1uqNcTgvampbaq7nUiP0XbPMGt76MYrsDlM/kqrIg8zj8FWZ0FKfNJMUI37wU+orHB92jQYeSAaPm0afTlr0qJwrNG7dCdM6cAJvIKIZta9O2SwCxL7xKTCHbfNUIsoy2BdvDfvN+AnVasU0WXrjAsYWoD/um5ifK/o+iKudMq5BgWBnxCjG1lZLzTSovaRvSYHbiKp+bfz8haUVRwT43Zkn5pGh0= MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 84f21954-e104-42af-7ab9-08d6c91b5c79 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Apr 2019 01:14:27.7712 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0402MB3788 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP i.MX system controller watchdog can support pretimeout IRQ via general SCU MU IRQ, it depends on IMX_SCU and driver MUST be probed after SCU IPC ready, then enable corresponding SCU IRQ group and register SCU IRQ notifier, when watchdog pretimeout IRQ fires, SCU MU IRQ will be handled and watchdog pretimeout notifier will be called to handle the event. Signed-off-by: Anson Huang --- drivers/watchdog/Kconfig | 1 + drivers/watchdog/imx_sc_wdt.c | 65 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 44a3158..f2c2c1a 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -644,6 +644,7 @@ config IMX2_WDT config IMX_SC_WDT tristate "IMX SC Watchdog" depends on HAVE_ARM_SMCCC + depends on IMX_SCU select WATCHDOG_CORE help This is the driver for the system controller watchdog diff --git a/drivers/watchdog/imx_sc_wdt.c b/drivers/watchdog/imx_sc_wdt.c index 49848b6..f45ed10 100644 --- a/drivers/watchdog/imx_sc_wdt.c +++ b/drivers/watchdog/imx_sc_wdt.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -33,11 +34,16 @@ #define SC_TIMER_WDOG_ACTION_PARTITION 0 +#define SC_IRQ_WDOG 1 +#define SC_IRQ_GROUP_WDOG 1 + static bool nowayout = WATCHDOG_NOWAYOUT; module_param(nowayout, bool, 0000); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); +struct watchdog_device *imx_sc_wdd; + static int imx_sc_wdt_ping(struct watchdog_device *wdog) { struct arm_smccc_res res; @@ -85,12 +91,42 @@ static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog, return res.a0 ? -EACCES : 0; } +static int imx_sc_wdt_set_pretimeout(struct watchdog_device *wdog, + unsigned int pretimeout) +{ + struct arm_smccc_res res; + + wdog->pretimeout = pretimeout; + arm_smccc_smc(IMX_SIP_TIMER, IMX_SIP_TIMER_SET_PRETIME_WDOG, + pretimeout * 1000, 0, 0, 0, 0, 0, &res); + + return res.a0 ? -EACCES : 0; +} + +static int imx_sc_wdt_notify(struct notifier_block *nb, + unsigned long event, void *group) +{ + /* ignore other irqs */ + if (!(event & SC_IRQ_WDOG && + (*(u8 *)group == SC_IRQ_GROUP_WDOG))) + return 0; + + watchdog_notify_pretimeout(imx_sc_wdd); + + return 0; +} + +static struct notifier_block imx_sc_wdt_notifier = { + .notifier_call = imx_sc_wdt_notify, +}; + static const struct watchdog_ops imx_sc_wdt_ops = { .owner = THIS_MODULE, .start = imx_sc_wdt_start, .stop = imx_sc_wdt_stop, .ping = imx_sc_wdt_ping, .set_timeout = imx_sc_wdt_set_timeout, + .set_pretimeout = imx_sc_wdt_set_pretimeout, }; static const struct watchdog_info imx_sc_wdt_info = { @@ -102,9 +138,15 @@ static const struct watchdog_info imx_sc_wdt_info = { static int imx_sc_wdt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct watchdog_device *imx_sc_wdd; int ret; + /* wait until i.MX SCU IPC ready */ + ret = imx_scu_irq_group_enable(SC_IRQ_GROUP_WDOG, + SC_IRQ_WDOG, + true); + if (ret == -EPROBE_DEFER) + return ret; + imx_sc_wdd = devm_kzalloc(dev, sizeof(*imx_sc_wdd), GFP_KERNEL); if (!imx_sc_wdd) return -ENOMEM; @@ -117,6 +159,7 @@ static int imx_sc_wdt_probe(struct platform_device *pdev) imx_sc_wdd->max_timeout = MAX_TIMEOUT; imx_sc_wdd->parent = dev; imx_sc_wdd->timeout = DEFAULT_TIMEOUT; + imx_sc_wdd->pretimeout = 0; watchdog_init_timeout(imx_sc_wdd, 0, dev); watchdog_stop_on_reboot(imx_sc_wdd); @@ -128,13 +171,26 @@ static int imx_sc_wdt_probe(struct platform_device *pdev) return ret; } + ret = imx_scu_irq_register_notifier(&imx_sc_wdt_notifier); + if (ret) + dev_warn(&pdev->dev, + "Failed to register watchdog irq notifier\n"); + return 0; } -static int __maybe_unused imx_sc_wdt_suspend(struct device *dev) +static int imx_sc_wdt_remove(struct platform_device *pdev) { - struct watchdog_device *imx_sc_wdd = dev_get_drvdata(dev); + imx_scu_irq_unregister_notifier(&imx_sc_wdt_notifier); + imx_scu_irq_group_enable(SC_IRQ_GROUP_WDOG, + SC_IRQ_WDOG, + false); + return 0; +} + +static int __maybe_unused imx_sc_wdt_suspend(struct device *dev) +{ if (watchdog_active(imx_sc_wdd)) imx_sc_wdt_stop(imx_sc_wdd); @@ -143,8 +199,6 @@ static int __maybe_unused imx_sc_wdt_suspend(struct device *dev) static int __maybe_unused imx_sc_wdt_resume(struct device *dev) { - struct watchdog_device *imx_sc_wdd = dev_get_drvdata(dev); - if (watchdog_active(imx_sc_wdd)) imx_sc_wdt_start(imx_sc_wdd); @@ -162,6 +216,7 @@ MODULE_DEVICE_TABLE(of, imx_sc_wdt_dt_ids); static struct platform_driver imx_sc_wdt_driver = { .probe = imx_sc_wdt_probe, + .remove = imx_sc_wdt_remove, .driver = { .name = "imx-sc-wdt", .of_match_table = imx_sc_wdt_dt_ids,