From patchwork Fri Jan 26 07:09:19 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: 13532149 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 96B20C47422 for ; Fri, 26 Jan 2024 07:05:49 +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=W9v7uVxDrhX1Xfeo+Eq/4dQBtG2MQ+MTwcLNq2xUJ78=; b=xlVBFttnNv2Qt7+ut7z4BrZX0h R9cOuM+u+IuDaw97Y0O8K24m/rxy80OtEMqhUv3t9I4i2pdvHi8/4z1s82Qnp00FBwl2be20cK8jv 2RqZ7G67A8JD8z0hHJXTsJZZToYual2IeNu415tPnUZcHdYVtkn3c8R4SFmZaKdAKMYgV3h04DjQ7 DwLDgw9cPnQyxfynyFf2yw0D9eO/Juuy1QBdY1az66Z7Fdbb4L4PjEuECEgq64jkX1SSaksKC2eKk HQLP1p3ui1Qiq6i+rZXYKEpdBw8pmWKECKsP/bF7Fpp2bVjF/EnDD76Fc8w9j9RSaVRXLbpSBx4Qa BVvckLNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTGHN-00000003J2C-2RBZ; Fri, 26 Jan 2024 07:05:33 +0000 Received: from mail-am6eur05on20601.outbound.protection.outlook.com ([2a01:111:f403:2612::601] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTGHC-00000003Iwj-0Hlu for linux-arm-kernel@lists.infradead.org; Fri, 26 Jan 2024 07:05:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ChrQlUShimnV2UfAasZXjH2JrW2LkTVIUbtfJA144ulg3Lzbyr5alHijW8XC2dJq2lAHOvChkiSXA3gFz6ih7BoxLV7MESz26rYR6rV7OQN1IqOClWJLA0m/h2Ehb/b3FH3p+Wuyu8Q2rlI1Im+RCt+l83TPySO7hXgVY3hnqYuxmTYSzh3hZ0hdIQ+Zu1o8PXyOTJmxjy7nmyezVKtHkgipvmDnQQpRZL2m2y0KfE6sM0hNBSWONF7IvN+LbaZhB+VdNvAvfaNW01Wp+lkpeH4y7zp7IdZ12s7q6Xxy+mhJpCNQlbrN9N8oJr3TSexRpLlmeL1V6bkmB4q+5D/XTg== 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=GWwGLQogleAHAp03QiCYcNmz77yayBGa4AxJXmlI5Q0=; b=ImYLJUf2BwLRzTncw6BimsuvJYEvFJ9ylcpEKMKdAr+elUe8MbiWU48jSKnWEYwkroeFH05lRHuJVXneVwjHWnm9Zma+0wyq2R6UdOmEUyzBEr8F0pHRD+9/VFfhOeBEo5OqDiYTnMGJ7tsXfK8qWWvro5+TYKw594Yaj6UmR6UXELXp4hG5PWvX8xf/KZU1fwZ4s99O9W6OYrHzG1yl/zl5xHk81q9K/MEqkPvZbBclAhQVXIEJ3nVC83wiAXnwYv781azHDVZ0gycWjXo6cazxDJidet2DupxJYs3qW5nce841McFbzIIa8Dj797Ebi8KLOu4frfMhSi91ebYmWg== 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=GWwGLQogleAHAp03QiCYcNmz77yayBGa4AxJXmlI5Q0=; b=TCoWZz5RTxPcnkNv7ZpJcFu55LRky3lUzo5vTCAMN3ZEJ7wJwDpfbVYcgxTI4WYcfOTpjwi7snVAuo4CAx2NL7VB6YyoBTz862ez1Q6T9HWxz50/gqUtTCfsAkCx5GDeRx0UMQQBxhGrfDZxQHplYMrhWwZFOtSuN7xqNVywNZI= 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 DBBPR04MB7515.eurprd04.prod.outlook.com (2603:10a6:10:202::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.27; Fri, 26 Jan 2024 07:05:09 +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.7228.022; Fri, 26 Jan 2024 07:05:09 +0000 From: "Peng Fan (OSS)" Date: Fri, 26 Jan 2024 15:09:19 +0800 Subject: [PATCH v3 2/3] clocksource/drivers/imx-sysctr: drop use global variables Message-Id: <20240126-imx-sysctr-v3-2-33fe801d5f31@nxp.com> References: <20240126-imx-sysctr-v3-0-33fe801d5f31@nxp.com> In-Reply-To: <20240126-imx-sysctr-v3-0-33fe801d5f31@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=1706252968; l=4759; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=GNd7nn9IlMWOE6EtgMoRLuOvy3mCu2EVYjx6qUvMpbo=; b=t0YAXFpShJ+kyGL9+aJ76dTajHOu6B/NgIS6JNiyyk9CXMG97W8VWOXltP2q4yuQwxZ3NJcaY ntUjmwCV0g7AB2AdBsIsEyOS07qnyAE9jJ8HoaknPyS/Pbh+WM71P2J X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI2PR04CA0002.apcprd04.prod.outlook.com (2603:1096:4:197::17) 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_|DBBPR04MB7515:EE_ X-MS-Office365-Filtering-Correlation-Id: 5d483ba1-f61e-4dbd-f76e-08dc1e3d2240 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: AOj5PFPHUuMTpYjAH4jb8MlJwdxXjcOrbATAS2eTR/+UP33CYraRDOZ8Gs2myOos1UMAlM0wZsVRz1faQGeFPwsxpXZ81OvuY0TG7VRKp44yWd657nzOfrvoSgXp9s86EfIbZOMG+YiNr3BxlzAaBTzDsdBxzexyTQtz/45w++i6S0x3FVKVf8p02XkFhY6Ts8Pf1jxoMdVnjdiigWbuINoQ8ioRBmmfG9xosO2K0iVi6DTHPzmHqs4VnlLugbV5hoj1Be21Ykg1b/L4cnz7ILDCofzplTu3o+vUgFchLm2PFpWAdpZZg5rB0JxWfrCfMMoaADbOcUwOmsVTokEhqrZSDTVaGC8osMVVKnKYUulDIbVeeQ9YaYfaHf2qzVO6BdLFCPueAMjK4rttLwOq/3PA8JYDYhX6RWUVuA2uuYR59mQE1cImaSKJWrh1Dp1h1wWZNQL+W9tvA+lzzJQDy9qffD5dlQZEbak+iHTbuCWg0Eawq+rZDrn67SQT5V0tsv0hKL2dFNd4LFW14ygLip8PMZhN3UvGGEPmwHxLjYzIQOXfimXJGqOI9f7Yw7pwDT2UqKl1B+0OxiQ7UBJMdj+at53wtloMDoSFt2SA13Z2LHtkrbAygRefsSWiO93gDUxX/pf/Ky29H1AfVyBqfg== 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)(376002)(366004)(39860400002)(346002)(136003)(396003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(7416002)(2906002)(478600001)(5660300002)(4326008)(921011)(38350700005)(8936002)(66946007)(66556008)(316002)(36756003)(66476007)(8676002)(41300700001)(6486002)(110136005)(52116002)(6506007)(6512007)(26005)(9686003)(86362001)(6666004)(83380400001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?syM4gGfGX37qvAauTPkkxc8NLwfv?= =?utf-8?q?u9hPAWdA9sUCM7r3oY4jPqZDEA6q+ASQ+f+si5KYWoxL4fonJuiy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1Ez642LAtB6R1zvSgVv4EQZbF?= =?utf-8?q?1tkOD3gaQKrdOGBnFOUffZu1aJ/lLdRJu2OyypwnmnJNLwkF+/mPN3RzCbeVaqEo2?= =?utf-8?q?wWkqgmc9Ccg7PUXojGb3H8wNhBYX/387yw2mSz+w8j8ByCGQLqdjMtMtS+tkVXARW?= =?utf-8?q?47R2JuRFZ7CA9bBkmBDm/9w+eHn682V4GmFrtGDXmEwO3MwlzdAESROx0t2mgmqKh?= =?utf-8?q?ly8SPUSEvmeyH/Qgw63F1IizmZ8Z2QoDs5PzJddLSlXyNPN8Z/E6NYtswJdD9DDXE?= =?utf-8?q?D4pGlZlh018Cm7CZ0L4JEfpoyHAVUc1sBwSI6BsnA8C7LOjExR15DINOT7o6CYDx8?= =?utf-8?q?KXtYAiQdnzGgqnI8E/xy/dENPr7nSKgLyCZk/kQmkgrZvph+sgJ8kKitDgI1ercll?= =?utf-8?q?LQj1Mevplg5NUqbvlvEf2rurRRnXjYFkI9m6IRJjLnCdIc8mJv1/dpVO58e+3VeZW?= =?utf-8?q?6Le9/AspSbi+zzJrdATKvqOfSf7I/rkcw712BsIr64nAJUkh6LpU0iGIp96r92CL8?= =?utf-8?q?02HzT4xOS/usGPD9+I2gTJ+2jyNp060eAUmB/fzNARdTKntPdmnV0nc/u4643C+K7?= =?utf-8?q?TrfDAkecMIet?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d483ba1-f61e-4dbd-f76e-08dc1e3d2240 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 07:05:09.7168 (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: lwFzY5Y6pLvOM7EmbOReEsFqj+sf3gxXtapxJcFSakT618mOSnw/XhiyGReBB43+3BoF6GOVvdEC41evKS1+SQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7515 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240125_230523_790975_721B3B85 X-CRM114-Status: GOOD ( 18.04 ) 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 | 75 +++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/drivers/clocksource/timer-imx-sysctr.c b/drivers/clocksource/timer-imx-sysctr.c index 5a7a951c4efc..8d5bfb8470fb 100644 --- a/drivers/clocksource/timer-imx-sysctr.c +++ b/drivers/clocksource/timer-imx-sysctr.c @@ -20,32 +20,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 +61,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 +90,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 +99,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 +126,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);