From patchwork Tue Aug 16 04:36:43 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: 12944274 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 57CE0C25B0F for ; Tue, 16 Aug 2022 04:43:58 +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=qsUl+RcVmaYrccx79t+W1623PUDE/Hboi1excBl6aTk=; b=xhMxVqtT3i9cme x3G1eVtAL98xaDE/gQXBuvVRKgC48zMBUv4H4V9kYy2Iu9Vb3rA0aWE8AYIJTMZggxIuWrMnbSToM tZl7SAHfGrs0dTukG3jM/P9x0pmb6NE0vC7w8aMAv9PQMr1BkvJ2FYus98eiEf5wMh0b+IIN5qHwx O6wvzf8gE0vncvG+tEyjqnIvl849vpLCyIJPaIwT0LjzcgFAzAlHw1CcnVih3UpVEyx+fMSKS9//q mZdbmmKaU5eDeQzrAjPDYsme5wwUECH7m1ywGNZyFgWkysWPkZZ2ev17luIb/MqctnGlLx0VzwEGA zeO1k92mYpqdLUyKSlKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNoOy-00AtjE-KS; Tue, 16 Aug 2022 04:42:13 +0000 Received: from mail-vi1eur05on2052.outbound.protection.outlook.com ([40.107.21.52] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNoLn-00AqAv-34 for linux-arm-kernel@lists.infradead.org; Tue, 16 Aug 2022 04:38:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gZoCCQJ7yiIdc4SzaWQ8+lraF51DmkbNfv2qwoca5ZtIEP5HXRJZvLmzhjEndDfNyCrgZNISMxGYWcIJQONDZij+G05Ffyad8MFtElIaVY2U8FPFSBbLIAMr6wCwSiJhbbKKmGlPLUBXO9LFDlwsaHNqK5dqY3C0b6Oi5jGeSh3MB/SOYvGX8Eo1d7lbUANN4prNCbn3Ztk34pKNmOiRFCxwFNd/weFsm+DRz6J6bhhyy64M9HmhDU8UtY8hDsXHNYHlCMS81SqELT7MCBG+QO2hYv+igCv6jc3DroNHok7LwX2My57MPfHCmR2NRiM2mMGJkp+qfIJvx5fbhiv9zg== 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=6bwa+IDV+1k34kBc/2efKKAgqy3sBdoQjBKkNiHtb3k=; b=BDr0Rr5wU4xoD/z7ABs4NMaXkY+gCo4oYzh/SOG0MahD+qjycwj3N+TYC041gfxnzbUk7TXHWurR563n6p011B0X/MI+1Ce3VBavyz0o1CT16A9+s7F+iD4ihwTWvQvCVR0o1FyYEx7zM1V53kBTo1o3ilwEX8wgx7KWRe8QMAOGUTqWx3/utdxiM530L0e1ZYB5LFuFTu1IcDNRBvTjtAqsskxOcHWjzycSNYMKCyrqZPrV1nX8DBYHOeHrsGxaqBkTYVEtSXqxAPkd3PjReOAFMVvxXIwQkSjiCmy2GOiklBe6xnB9Ttf4KzKY8qP/mFfKUKZg5DPLsxTr1vtzLQ== 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=6bwa+IDV+1k34kBc/2efKKAgqy3sBdoQjBKkNiHtb3k=; b=W5htE8H3x3p8dHE9CoguMSbIELk3EXfkiMMQusJlTfvbhXurmo0LU7GfOBOC4n3dd6pu/5hcI04ouAwt9oXJcAn1aK8x8ThHeBAjDwE5HL0Kn4AXn+rFTudhCRBoIWXG0yKoC1kftScXBiXy+2YO7GSKUSSDV+xWFIcnbaAAypA= 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 DB8PR04MB7036.eurprd04.prod.outlook.com (2603:10a6:10:12f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.28; Tue, 16 Aug 2022 04:38:43 +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.5525.011; Tue, 16 Aug 2022 04:38:43 +0000 From: "Alice Guo (OSS)" To: wim@linux-watchdog.org, linux@roeck-us.net, 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 7/7] watchdog: imx93: add watchdog timer on imx93 Date: Tue, 16 Aug 2022 12:36:43 +0800 Message-Id: <20220816043643.26569-8-alice.guo@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220816043643.26569-1-alice.guo@oss.nxp.com> References: <20220816043643.26569-1-alice.guo@oss.nxp.com> X-ClientProxiedBy: SG2PR02CA0015.apcprd02.prod.outlook.com (2603:1096:3:17::27) 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: 4de274ab-0357-4cef-6cbb-08da7f413350 X-MS-TrafficTypeDiagnostic: DB8PR04MB7036: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: BlAubPDZ8ukH47IiNKMkSi2Cm2I3Ndi0gmRoZdaUcnquRM6YePTXXUfR1CwcRf038Ya6iSQ/RX45nuxKLYqrppqbwWjm7b7zJfbictgJF79tfa3BOWUXmOEEmiEzKAQBJvhHcagBSx1twL+0ieqkplmI5uwoBA3/Q0CdG5bT8Pw5t0wJjcJeolbO0Moqapx6QZU2WsiXesZV8PY+gri7Kym6iHGx8sOmpt0L+38vFwkofnS4EZ1g/XSbhNApp9In3fL9fvmhq6Cm1iaOyjqixLfcmQLIQP+PPuRqIqLOGBirIbq8+cRV4bQMGvwql95uLjLaogfJGmCcYCF1iBnQgGd5nYv956rDWLeBlnNbO5EspYWa3UMqLfNLam//1pWPByGYbr4nwcSLFLXaDa/CAysUCYrO1bMIZH3wqhYeNKSAOzygTZHBvyCBC8io0PcwOQyeLQZXozUHTYdVM4LkHlrpZnzdmp0QUIK+RjV46WUbFmkn/6fW298SY0s92rlM/Q6bKLQ2CxB1RDJJLMj2UP6i7A9CrqzHU7h/08sOBp3ThtIPFTjwfcYnQqzyxjSEmuSHY2JRZdRe6AaR5leLiDOc5aALRI7aNProtgaVT4vzVsiZfzsqnl//0546YhtiwwqFQeYnu8zvZ47Wzq4OIbjXWO4WtgSytpROZs5uJR2qGX2QXdPkK9T1qgQBBZjC0UTKAoAMVUCMAgtHyxPNRi3tGiJSxiTNfRthWwHhX81lwbVYjl/dQ51Iuc54AD6kYQ2nfjbBGyRY7zh4jfxg05RctzGeZ8Nr0uNyHACniNM= 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)(346002)(366004)(396003)(39860400002)(376002)(136003)(83380400001)(38350700002)(86362001)(38100700002)(4326008)(8676002)(66556008)(66946007)(66476007)(316002)(2906002)(8936002)(5660300002)(6512007)(6506007)(26005)(1076003)(41300700001)(2616005)(186003)(52116002)(6486002)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: g1WZ8/oFu5ClsEDGmYXW9EpL+xz+lXH1qgzTtE0+mOs9a+y4EKBU+ldwIj6TXkxHuWaQJbP28QY65dfHw6e2LDu9TCRowg4vkRtQOtqrwE+1uIHZaz6PafChkE2lkt6f/5hJVa329Tnmf1u1E9ydCGBQAJ324HCa1fKFw+wRIOI/1A7FNNsujwBpIP7dI2VqpDVSS48V5vsENq77uOPtLdrO1QAbGjyrO+cksPqNiqE8gBjXRN46JNYrFheaXI7ngtTepVSK3HTunfj5Ya94vS3XvtxuDmIdo3ufuS+g15tlQ5J7TcXOWexRKiP5dWZQ5jHiBTS/dMscGbFfVToVC2A2uPf1koLv7bTVrN9hxgNJIy2TSKCPNzSgfkqogHRyBkMu4v8mJalM80AWvjAit82BL6ywudx5IQRJZ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qOQO6Yt+r1VDHT+V3MmBvUucTz+Nz92h/xS0IYzg48xBG2s4Z2UkWsUzFMULY1uIQ2lJEK+PPyCdIBg9d+iPCNCY2uYA1ilcRZJSTN5Vz X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4de274ab-0357-4cef-6cbb-08da7f413350 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6053.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2022 04:38:43.8106 (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: IYmG6bZed++TSUnF70LDAIU3+FENLk/bMLzDR1ueH8GVPol/WnYqunSJtoUTDA3lVvSVhxRLTyWOzdcup1KlzQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR04MB7036 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220815_213847_180365_96820956 X-CRM114-Status: GOOD ( 15.85 ) 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 --- 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 58508f69d933..4694aa4b8cfb 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);