From patchwork Thu Aug 25 08:32:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alice Guo (OSS)" X-Patchwork-Id: 12954382 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 05971C04AA5 for ; Thu, 25 Aug 2022 08:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NhNxPsgvSUziYLab51RfYU9WUOnBrctiBiMTVJnr6Uk=; b=AY+SwglOkEoOtS Ud7ancKBioinJ84XEUARm1k/OeifF8faWLR5PZtCdwss6HbHvWAeRaN3xaqfwK7zeYLXe2k1quh5d 2cveSKRzf2+haSFMII6h7j0P64gqnF7PRsKMVd/qNYb0j58qsxLufbNvmmOTY99W4kiq5oZMtjQa+ JrC5D7v0ZMiRo/PMaegUAF+rlRRqvB9xN1k2Wyt3/Jph6TXfDgX5m5Kn0NhUEkzobEOtFS1KTA7qe 3QtYUs5hWyRH6C2j1vAnDaE4xlGq4dyp9B8xL5eQac+PYT1ZIORqbz8picChuTK6+GqkFWSMMRNH+ UyRJoTxW3BKQ4QBFPusQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oR8N6-00A8Y4-1K; Thu, 25 Aug 2022 08:37:53 +0000 Received: from mail-eopbgr50062.outbound.protection.outlook.com ([40.107.5.62] helo=EUR03-VE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oR8Im-00A5s1-2q for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2022 08:33:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m6a3lMv+34TAqTqUnQkcZaA6px6hRhDhHImEHqDez8t//eKbnTxluLwlWsyN849DwNvj1VzApg0pgYJrIl+z9yeWFk5PPV2U6uR63G9g2UfKYL4qJc3zd5N8Moe22zM2DSYMzoQNg/YiiK/UE+Gjvdz0Ne6Gol8c3mkoLD23voeasJrAHqkuigKXuQ9pG9uksU/e0drckdrzdoeqKWtFoFj3uKqmb3eEaC2uODTdG8AahsGkVo3istya5taoHzOYZe5VvtAxUOOV+m+7Kd0vOTqgfaQyov1L+4cRM1a5erg142z4JGoEohw2u6zfqAyjblcIdv7A0k3C4eKSWXvY+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QklsSL7Q/a1bjgg5pmMLTYcBv4jx4AqzDyYnHrZv47k=; b=BZPX1vszgbtRtUPHJMJDBrPbgjmT/UpNGyXxlILCha+IDsi858GiekfQdL0m1cZ3D66vp0u4aNPNrnyW/NEev/p9ABC/qMpkad3F5EI8RZNOlONvfurIUMoZkSbkgjcOnIRTylnhiIzRMrM+gzgLP5/ilbNJ/9DYu4IGBCJVrH8bvSMdIRXMJfv7PTV7dR0u7gMyY3VgdKejAfbSyKCD8t/KcFmB5DQUidhitwDv+OxUHCQLrgdL7vL0NFU622HV77AJROaQ/SuGs5+lo4SIj9tfHvZRX094jLzG9uyvXXgjgLML3FnJgfcrxcTUxKcucnggzKJ/YakgjW0lH8RQUg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QklsSL7Q/a1bjgg5pmMLTYcBv4jx4AqzDyYnHrZv47k=; b=FCoxUuSGCoyE9LxHwKSfTzM3Cw5wjOkdmU6gzIiXQfpld4ESlVbIAg+U/DsYF9oSXh3yvtb3MdnrKndAKgug6O0WBWcNYZwH9sATFMMdaIQ+mLxVHW5udX/DpCmeKn4cxovACJHWwnzSMTVi/Rj6u1Pi3dg6AWGkZgPQcv429Ik= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM6PR04MB6053.eurprd04.prod.outlook.com (2603:10a6:20b:b9::10) by AM6PR04MB4901.eurprd04.prod.outlook.com (2603:10a6:20b:1::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.15; Thu, 25 Aug 2022 08:33:19 +0000 Received: from AM6PR04MB6053.eurprd04.prod.outlook.com ([fe80::6cd5:f11c:4e5c:d79c]) by AM6PR04MB6053.eurprd04.prod.outlook.com ([fe80::6cd5:f11c:4e5c:d79c%3]) with mapi id 15.20.5566.015; Thu, 25 Aug 2022 08:33:19 +0000 From: "Alice Guo (OSS)" To: m.felsch@pengutronix.de, linux@roeck-us.net, wim@linux-watchdog.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com Cc: kernel@pengutronix.de, linux-imx@nxp.com, linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] watchdog: imx93: add watchdog timer on imx93 Date: Thu, 25 Aug 2022 16:32:56 +0800 Message-Id: <20220825083256.14565-8-alice.guo@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220825083256.14565-1-alice.guo@oss.nxp.com> References: <20220825083256.14565-1-alice.guo@oss.nxp.com> X-ClientProxiedBy: SG2PR06CA0225.apcprd06.prod.outlook.com (2603:1096:4:68::33) To AM6PR04MB6053.eurprd04.prod.outlook.com (2603:10a6:20b:b9::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9e9b47b1-f15c-4331-21cc-08da8674768d X-MS-TrafficTypeDiagnostic: AM6PR04MB4901:EE_ X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WRj5g0uYW1I7KAYimzjp+lxSQt19GRRky5Aq5i0UXP+nZeBR755twcnVGHA8lQgXnHV0WK+J1Ty4MF71H0mi186C3FlW/Gdec3gjqnEWtFzr8pS3kvpYT6+TMOZUUaVqkUEs1VDTUOiFikZAsU7Umr+RVNc3Wr+C5i9XVT6Is1Qs6NjyyBkxV6HKPb+Jd9OqAtb1ORUv6Ua2iyXb+iFAc9ef36Sby4PXTR3SSEjShng4VLBjSP1WHiFRxSe0rlbJvAbE0Hp8D/4ixnWr40p7mDariDnpWcnlACZMoxchLNzjkniggjU2LBFFgRqg272RVQbvqCPI77zWvJRxZyuA0q0M5MPOCKUemibdC63pTJDWFhP0zbSSlBvzGxVCHjnSjzO7lAW02d8VM/B06NSY5EemMZPou9ZnvaIAgUWpbVucjhynRvYrIJjnCGGU3ZiGKXhaWxfUkN3EtuPSQ15UdmY8slwB8iqDYnqqvB6YgykBJMMUNBrF1BceTejPXnbrlnzjY07+J79Sm8Q5+R0B6Xp2Sen+1WK3TobzTwwwOFiOMhfauB8giWI/dmJ0dzwr5hQYxO7YSi8LNHOly+nO8E2MXkxOvtmwR6bmqYTxtwd9N5O9U/ssfdAvPc/WaksALOB7RNM4N/fwOTq6hibKU1WH+DMbKWEIrYfDZV6LTgy9TtfU87n2iGtr+6NUd05OuoUkwS9V7oeFp1a2+Xt9+fh4LDhegtx+SgxFdWTrPvrsKI0h9KWhvLivQ+2Uy1VEJ+h8TR0NaATP8fPKQvre9g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB6053.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(366004)(376002)(136003)(346002)(39860400002)(396003)(8936002)(5660300002)(7416002)(38100700002)(38350700002)(4326008)(66946007)(66556008)(66476007)(478600001)(8676002)(6486002)(6666004)(41300700001)(316002)(2616005)(186003)(1076003)(26005)(6512007)(83380400001)(2906002)(52116002)(6506007)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HjYAKLRaBOWB1TzhANf6IrpXrtQl2/6+/6KY7XzHH87RKN6bpDfZ4DtkOfqhuVrbADr87B/DhCeDIJqof0pPhIr7hkN7JgmETTk5n7NVTlLinIzvmTIqVaF+713QKs/bc40dCZ6MIOkC1InXtIfy5Cqe2hNvRpMeMAg0mB7VfYYPRb+p6bDsCG4nyOdY6JNOA2Fhn8eQtF07yNjBsp2jgqVQ8Wm6a0b5wikBFIey4O4faDjA5bXzwtj6fP7HgZvabWJASFjgJ7DDw0vaelSubgigZl7wajki+kdH9lBasZ+MToEQDC4Bbyp/6vZlQaIkfh8eu3c1eBoM6+Ee6KkiE87RgXSAy/ZYtctdMXCTUNPW+7/xyHAjCJUMtEoG+Jg3jU1eLQydE9WRdBAwPU9HU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Q7FriRACb9XgfEF2w3KtBtzZgiZR7Ye9/Urcty0nAC79ZQkb2B/fn3JbYLYFOMMnPdeitGH8RZT7P1Q+gIC3bHphgFBkA7xrn0iUL5IesWOEV0i3Md1NxnQhnbsg X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9e9b47b1-f15c-4331-21cc-08da8674768d X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6053.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2022 08:33:19.1197 (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-CrossTenant-UserPrincipalName: SpKNS1Ka8ywxzME9UqKXavvybaZwRmt4h4BYhRKq+vs8OS/A80eVXtPc5SsnUeqax1e/6HEHmEWhP9RP99+5Ww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4901 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220825_013324_187260_3A869B1C X-CRM114-Status: GOOD ( 16.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Alice Guo The WDOG clocks are sourced from lpo_clk, and lpo_clk is the fixed 32KHz. TOVAL contains the 16-bit value used to set the timeout period of the watchdog. When the timeout period exceeds 2 seconds, the value written to the TOVAL register is larger than 16-bit can represent. Enabling watchdog prescaler can solve this problem. Two points need to be aware of: 1. watchdog prescaler enables a fixed 256 pre-scaling of watchdog counter reference clock 2. reconfiguration takes about 55ms on imx93 Reviewed-by: Jacky Bai Signed-off-by: Alice Guo Reviewed-by: Guenter Roeck --- Changes for v2: - none drivers/watchdog/imx7ulp_wdt.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/drivers/watchdog/imx7ulp_wdt.c b/drivers/watchdog/imx7ulp_wdt.c index dee02c2a52c9..2897902090b3 100644 --- a/drivers/watchdog/imx7ulp_wdt.c +++ b/drivers/watchdog/imx7ulp_wdt.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -52,11 +53,17 @@ module_param(nowayout, bool, 0000); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); +struct imx_wdt_hw_feature { + bool prescaler_enable; + u32 wdog_clock_rate; +}; + struct imx7ulp_wdt_device { struct watchdog_device wdd; void __iomem *base; struct clk *clk; bool post_rcs_wait; + const struct imx_wdt_hw_feature *hw; }; static int imx7ulp_wdt_wait_ulk(void __iomem *base) @@ -179,7 +186,7 @@ static int imx7ulp_wdt_set_timeout(struct watchdog_device *wdog, unsigned int timeout) { struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog); - u32 toval = WDOG_CLOCK_RATE * timeout; + u32 toval = wdt->hw->wdog_clock_rate * timeout; u32 val; int ret; u32 loop = RETRY_MAX; @@ -276,6 +283,9 @@ static int imx7ulp_wdt_init(struct imx7ulp_wdt_device *wdt, unsigned int timeout int ret; u32 loop = RETRY_MAX; + if (wdt->hw->prescaler_enable) + val |= WDOG_CS_PRES; + do { ret = _imx7ulp_wdt_init(wdt, timeout, val); toval = readl(wdt->base + WDOG_TOVAL); @@ -346,7 +356,9 @@ static int imx7ulp_wdt_probe(struct platform_device *pdev) watchdog_stop_on_reboot(wdog); watchdog_stop_on_unregister(wdog); watchdog_set_drvdata(wdog, imx7ulp_wdt); - ret = imx7ulp_wdt_init(imx7ulp_wdt, wdog->timeout * WDOG_CLOCK_RATE); + + imx7ulp_wdt->hw = of_device_get_match_data(dev); + ret = imx7ulp_wdt_init(imx7ulp_wdt, wdog->timeout * imx7ulp_wdt->hw->wdog_clock_rate); if (ret) return ret; @@ -368,7 +380,7 @@ static int __maybe_unused imx7ulp_wdt_suspend_noirq(struct device *dev) static int __maybe_unused imx7ulp_wdt_resume_noirq(struct device *dev) { struct imx7ulp_wdt_device *imx7ulp_wdt = dev_get_drvdata(dev); - u32 timeout = imx7ulp_wdt->wdd.timeout * WDOG_CLOCK_RATE; + u32 timeout = imx7ulp_wdt->wdd.timeout * imx7ulp_wdt->hw->wdog_clock_rate; int ret; ret = clk_prepare_enable(imx7ulp_wdt->clk); @@ -389,9 +401,20 @@ static const struct dev_pm_ops imx7ulp_wdt_pm_ops = { imx7ulp_wdt_resume_noirq) }; +static const struct imx_wdt_hw_feature imx7ulp_wdt_hw = { + .prescaler_enable = false, + .wdog_clock_rate = 1000, +}; + +static const struct imx_wdt_hw_feature imx93_wdt_hw = { + .prescaler_enable = true, + .wdog_clock_rate = 125, +}; + static const struct of_device_id imx7ulp_wdt_dt_ids[] = { - { .compatible = "fsl,imx8ulp-wdt", }, - { .compatible = "fsl,imx7ulp-wdt", }, + { .compatible = "fsl,imx8ulp-wdt", .data = &imx7ulp_wdt_hw, }, + { .compatible = "fsl,imx7ulp-wdt", .data = &imx7ulp_wdt_hw, }, + { .compatible = "fsl,imx93-wdt", .data = &imx93_wdt_hw, }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, imx7ulp_wdt_dt_ids);