From patchwork Mon Feb 5 03:17:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 13544948 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 79A69C48286 for ; Mon, 5 Feb 2024 03:14:08 +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:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=3NgqO5huLfK51MrRBa6AVDVISFF+HGV22nFORNf5GgU=; b=o/25jKw+FDPHDjv81dr4L72RCC ERJpKF1un53Fd1H6KzHVfu4JWh8eDjSj76OpfbD8gHK7Np+SVnAtCVhdhNFC0tEJ5SXqtLnZry74D AU7P8aminODvMJOLsr4e2WyWdf3/CyAzHxF6EibwrvwupmgptGocGC2NklnrVGUVINsWqTdvAU+xu s1vPonfhXXKXxycNkL8hHq4mOGK3gT8SRv/cn2O9Of3B40BC4rh8ZX1FHhtpIV0KtHJpUZkJGmcGk EzKRov47Dy8gRsLactUOvJ877vWvZp8jdVUZ6ycgJesHXsB0ZnxNcSYWit5q9c71RrV3Keu9To63H Wu7UV4Hg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWpQg-00000001tcO-3ogC; Mon, 05 Feb 2024 03:13:54 +0000 Received: from mail-vi1eur05on20600.outbound.protection.outlook.com ([2a01:111:f403:2613::600] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWpQe-00000001tak-2DK5 for linux-arm-kernel@lists.infradead.org; Mon, 05 Feb 2024 03:13:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UQ1Op5R36Xp6WN1weBGNdP2oZgTj8DrqaYrlcuBcqeefDw1EqDko4f/0SmAoQIT5HrX9jEQ4dU1MOgqqwc11OHsPuP1Pvd9+fPJfonJy+hgEIqFo/PyxwiWU6T9vgEGQ/ZYQzdRWgTkoIVV16OJPDj7jI5SQ1gIAVaYPkQNS2o6HP2vYMFaZ6VwvH+HX81XjSAuBm2JFhVVpP9BnjWFdOUjWzqVsQVq+lDLFh0RPtFwVFRBIXjqOUv/4/O3V3w6NuZxQqZzHD3PJ6W7SapR7mw/4OuVwQ9Iv0VFRFxIwqZQFjWFrVNFnVCsJQm9N5EoCJl8hH50sFkdK7RKMO+ANPQ== 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=ojj9JFqx7/SKG+NtV4R+WN6A0aMY/vM2Wbiw0lOFvc8=; b=SWW6SCzpcPpivoYU5TLbOK1tf0kdI62m0JliiL4LH+ImKc2KyDGCNLtlMepK/gW0dsd1GNoYvujnUrPuGnzOuoS4vbGu+1bAKOQsjz2XLu0scpRnuu0RxRkkrlgx8fSWT/GqaJ5IWzbLucFfMucGiRUurO6exJjQRK8e6H5kUur4Zo0tAoIhD/Wq4/TDnrH6TKzsLhEkBuD8jR8zBrHV2cIIxH/0YSAdlNgW4gyWEuZ40ChM1/PRxakNV6vv3Wx4hmdNWI7j67B51Lh53B4q9TGIfoiG2J+tgb3/Ib7erBBfauRcmkeF+6LUx1FiqyNYuM9fRlaHf6iLaV7+A1dZgQ== 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=ojj9JFqx7/SKG+NtV4R+WN6A0aMY/vM2Wbiw0lOFvc8=; b=FZ6OYFdSs/pzePz5AWs1G9e7AGJ+qgmmxV4fouDcYo/AIoe7bMx7sN1u4kCLa5ZbgzBLlVmGAnEmk0aP6kl2WeZJZkJz/5vWengG18d+BPchU/Tk02Qxw1+wm491RzPHZaSI1MYbxjnU2IKth95CPfaBjktevoWuWxdtTIu9sMM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by PA4PR04MB7775.eurprd04.prod.outlook.com (2603:10a6:102:c3::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.34; Mon, 5 Feb 2024 03:13:50 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::c499:8cef:9bb1:ced6]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::c499:8cef:9bb1:ced6%3]) with mapi id 15.20.7249.032; Mon, 5 Feb 2024 03:13:50 +0000 From: "Peng Fan (OSS)" Date: Mon, 05 Feb 2024 11:17:58 +0800 Subject: [PATCH v4 2/3] clocksource/drivers/imx-sysctr: drop use global variables Message-Id: <20240205-imx-sysctr-v4-2-ca5a6e1552e7@nxp.com> References: <20240205-imx-sysctr-v4-0-ca5a6e1552e7@nxp.com> In-Reply-To: <20240205-imx-sysctr-v4-0-ca5a6e1552e7@nxp.com> To: Daniel Lezcano , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bai Ping , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Marco Felsch Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Peng Fan X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707103086; l=4899; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=S7w4NqGjFN883vSC1fzkHyfccuvNVL7NR4MRBDh8Qms=; b=bD9PSR8u6DgMlZb1CM7VZyCiBI8l5A6qOl3CSEuPxz8QpI3az80lzl3T1cdRbTKP3WyPKbXh/ XB+QHefLv2hDPFbQdNVR7SsApbvIJMxpZrNyw3iDWwxaM6WNrs3CkVj X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR02CA0124.apcprd02.prod.outlook.com (2603:1096:4:188::9) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|PA4PR04MB7775:EE_ X-MS-Office365-Filtering-Correlation-Id: 4c2844ee-13e6-4f55-aa0c-08dc25f87972 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: EqToun86n84hAFq31qRQA5jgCxHqTVzEoRNZfAyfDdiqpI0Oq8gymhvLuG32HejILzihv1rVxpvPiDrtyEU0tpGCVDndIjYCSp3isP2Q1kn6FTwfa6DDepS5nxW0JHDH8dQOlPEkbM0rS/N8eVV2WJmwXi0/7aA6r+T/M+JZPoQ7vUSI4SNYDGJDBJfEoK/p8xd+LeqsdeWMOf+n2vECeNdwTQVTkR/GLa0pBXBC5nOOst9ekk/yBOLL+g1AXDtr+UxwPVvahPL9b1vmRonfiox7qlq2lp2QkxT9FAEbCh9vurKXuE1Y084lPh+vQe+GjVZnzGRSJG9qsHaYPXir+Iy+hGUfwcJWq26Mu7R/ED00dMUitkV4r16TUGvTHjmZuH5Xu7U1fV/8X+odu61hNANcND9sZH3k9LaDqyjpbnnpMYeSRcb9wjfV2PX1J7kU5IdLzMtbzPznGBbYtulHhNOJC9cld2G2/+pMLNAvB1D4jTXF4PwonAjRrbwgaDrfjgZI8DaXl/25luTiBC9/XiynZWBW6h1Kjzt81penHg7KwHWpxAeRFgs2bh/CcGRWU3XHuq6F2yA+rwNtkZup2uGp9hp1/BUcDuKGukE7QtdDNGBVFgbKmx/MSnaJqn1efzL7Tg8Pdb4Wy2PaPGiOGw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU0PR04MB9417.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(136003)(346002)(366004)(396003)(376002)(230922051799003)(186009)(64100799003)(1800799012)(451199024)(52116002)(6506007)(83380400001)(38100700002)(26005)(86362001)(41300700001)(4326008)(36756003)(8936002)(8676002)(9686003)(6512007)(921011)(478600001)(2906002)(6486002)(7416002)(5660300002)(66476007)(316002)(66946007)(66556008)(38350700005)(110136005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?oPhJkuKAV9j0H6mgRpgMgomOkXF8?= =?utf-8?q?kP3Ahkhoho67UU47LqXVVeEbAlnnxyKmel4I90xFS4I/Q3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7I9rGxHK9qY0nLj5gs2jTX?= =?utf-8?q?LqNkWO0xEhJYlOJKD5STOsyzFu6uqFjnIOYOaQqapp2pytko51aRJaOLOjuRbZPHP?= =?utf-8?q?QuL1xutlJW4/EwMALsMmDdy8lZyKS9jT+wsrXubVaOVZRWGhDhz+o7zrXk3ekz0pp?= =?utf-8?q?whqcItyB7T7ECzp5MgMnADxv0d1yEggqu2OtjfuPoLgWihMVOZECsiewrbYd0UL1P?= =?utf-8?q?nu2se+hyUsTs4wGl/DfYHd0c6M844y9eVViOT8/5OZn1REzLT6isDVWIc8MpdF9xr?= =?utf-8?q?fVPHNAAGuE91+UJlrK0VsTW27UGFVdIcSyiO7YFFcMVRPhCfTsZd+n7R7HOKDL647?= =?utf-8?q?UIkbDHkvzvJhJ9ni1FE4kbtBA6jy0BAYZP4EeDoksu8q/JBLbozTCWtj6wWHcxv1c?= =?utf-8?q?7/lUPb6JV5qs15dKAqyog1GmRcBtsVDEfFS0cuP01zMxNRmMgCLTqShHJiU8qWmt1?= =?utf-8?q?fP9Q9FL+w0lsP8ZIWQQT+Vb7id+t3dJ+O32+RlGQGvNrpbeONGOgPDcger2ka+lYD?= =?utf-8?q?DQP9L+Et1XkXaYE/pTxzwbzwUWCtgyNJrRud5dxNOvPZuKgdPbOJX7QKoS8F7I3JE?= =?utf-8?q?CerNauzNn/LN?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4c2844ee-13e6-4f55-aa0c-08dc25f87972 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2024 03:13:50.0253 (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: EYGeEci0ei1IChQHyk6jVqdLMhHVoT+KjakphIEZm7mMsZmW9xDKdfD+M+bvSCLo4ph+n7C9jrapnzrY60utDg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7775 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240204_191352_636351_67D33E84 X-CRM114-Status: GOOD ( 18.69 ) 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: Peng Fan Clean up code to not use global variables and introduce sysctr_private structure to prepare the support for i.MX95. Signed-off-by: Peng Fan --- drivers/clocksource/timer-imx-sysctr.c | 76 ++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/drivers/clocksource/timer-imx-sysctr.c b/drivers/clocksource/timer-imx-sysctr.c index 5a7a951c4efc..c075ea89a214 100644 --- a/drivers/clocksource/timer-imx-sysctr.c +++ b/drivers/clocksource/timer-imx-sysctr.c @@ -4,6 +4,7 @@ #include #include +#include #include "timer-of.h" @@ -20,32 +21,39 @@ #define SYS_CTR_CLK_DIV 0x3 -static void __iomem *sys_ctr_base __ro_after_init; -static u32 cmpcr __ro_after_init; +struct sysctr_private { + u32 cmpcr; +}; -static void sysctr_timer_enable(bool enable) +static void sysctr_timer_enable(struct clock_event_device *evt, bool enable) { - writel(enable ? cmpcr | SYS_CTR_EN : cmpcr, sys_ctr_base + CMPCR); + struct timer_of *to = to_timer_of(evt); + struct sysctr_private *priv = to->private_data; + void __iomem *base = timer_of_base(to); + + writel(enable ? priv->cmpcr | SYS_CTR_EN : priv->cmpcr, base + CMPCR); } -static void sysctr_irq_acknowledge(void) +static void sysctr_irq_acknowledge(struct clock_event_device *evt) { /* * clear the enable bit(EN =0) will clear * the status bit(ISTAT = 0), then the interrupt * signal will be negated(acknowledged). */ - sysctr_timer_enable(false); + sysctr_timer_enable(evt, false); } -static inline u64 sysctr_read_counter(void) +static inline u64 sysctr_read_counter(struct clock_event_device *evt) { + struct timer_of *to = to_timer_of(evt); + void __iomem *base = timer_of_base(to); u32 cnt_hi, tmp_hi, cnt_lo; do { - cnt_hi = readl_relaxed(sys_ctr_base + CNTCV_HI); - cnt_lo = readl_relaxed(sys_ctr_base + CNTCV_LO); - tmp_hi = readl_relaxed(sys_ctr_base + CNTCV_HI); + cnt_hi = readl_relaxed(base + CNTCV_HI); + cnt_lo = readl_relaxed(base + CNTCV_LO); + tmp_hi = readl_relaxed(base + CNTCV_HI); } while (tmp_hi != cnt_hi); return ((u64) cnt_hi << 32) | cnt_lo; @@ -54,22 +62,24 @@ static inline u64 sysctr_read_counter(void) static int sysctr_set_next_event(unsigned long delta, struct clock_event_device *evt) { + struct timer_of *to = to_timer_of(evt); + void __iomem *base = timer_of_base(to); u32 cmp_hi, cmp_lo; u64 next; - sysctr_timer_enable(false); + sysctr_timer_enable(evt, false); - next = sysctr_read_counter(); + next = sysctr_read_counter(evt); next += delta; cmp_hi = (next >> 32) & 0x00fffff; cmp_lo = next & 0xffffffff; - writel_relaxed(cmp_hi, sys_ctr_base + CMPCV_HI); - writel_relaxed(cmp_lo, sys_ctr_base + CMPCV_LO); + writel_relaxed(cmp_hi, base + CMPCV_HI); + writel_relaxed(cmp_lo, base + CMPCV_LO); - sysctr_timer_enable(true); + sysctr_timer_enable(evt, true); return 0; } @@ -81,7 +91,7 @@ static int sysctr_set_state_oneshot(struct clock_event_device *evt) static int sysctr_set_state_shutdown(struct clock_event_device *evt) { - sysctr_timer_enable(false); + sysctr_timer_enable(evt, false); return 0; } @@ -90,7 +100,7 @@ static irqreturn_t sysctr_timer_interrupt(int irq, void *dev_id) { struct clock_event_device *evt = dev_id; - sysctr_irq_acknowledge(); + sysctr_irq_acknowledge(evt); evt->event_handler(evt); @@ -117,34 +127,36 @@ static struct timer_of to_sysctr = { }, }; -static void __init sysctr_clockevent_init(void) -{ - to_sysctr.clkevt.cpumask = cpu_possible_mask; - - clockevents_config_and_register(&to_sysctr.clkevt, - timer_of_rate(&to_sysctr), - 0xff, 0x7fffffff); -} - static int __init sysctr_timer_init(struct device_node *np) { - int ret = 0; + struct sysctr_private *priv; + void __iomem *base; + int ret; + + priv = kzalloc(sizeof(struct sysctr_private), GFP_KERNEL); + if (!priv) + return -ENOMEM; ret = timer_of_init(np, &to_sysctr); - if (ret) + if (ret) { + kfree(priv); return ret; + } if (!of_property_read_bool(np, "nxp,no-divider")) { /* system counter clock is divided by 3 internally */ to_sysctr.of_clk.rate /= SYS_CTR_CLK_DIV; } - sys_ctr_base = timer_of_base(&to_sysctr); - cmpcr = readl(sys_ctr_base + CMPCR); - cmpcr &= ~SYS_CTR_EN; + to_sysctr.clkevt.cpumask = cpu_possible_mask; + to_sysctr.private_data = priv; - sysctr_clockevent_init(); + base = timer_of_base(&to_sysctr); + priv->cmpcr = readl(base + CMPCR) & ~SYS_CTR_EN; + clockevents_config_and_register(&to_sysctr.clkevt, + timer_of_rate(&to_sysctr), + 0xff, 0x7fffffff); return 0; } TIMER_OF_DECLARE(sysctr_timer, "nxp,sysctr-timer", sysctr_timer_init);