From patchwork Mon Oct 9 08:42:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacky Bai X-Patchwork-Id: 13413080 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 7FF39E95A8E for ; Mon, 9 Oct 2023 08:38:18 +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: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:In-Reply-To:References: List-Owner; bh=eb8uuacUPKmIm5PUKfpX4E11bBlMJukUtgDhaXPtLRs=; b=NPQuREpIpVA6ab AsJgk37J3/5SgnevDCrjUyBmsfznbDeiiqdupnalHT+nrdtr/EXbUogfXRouKOliIDPro9T2PUHqY EAc6pmTxl4xGMuw2LZHo630OoL6OzKq6++nyuaJ/sR6VCpYDt/qjdcbCPgbdzi3l5TZuPrzhfdXoL d4Tm30X/rC6elqjJVrgrv+Yw08DSNAg8lsIytCPE/0EQXwTJvgr2qhy0SEbrYVEsRoE4kDEbR+9LA RAyKE5BjAs6fnZ2RH6KmcLWv+d5fKDKqJzsL7i09ielYrA314eGEqfaLUl5VWsEIc8FWYukDpQH/L 7PdKX/dPe7UKl60QTBLQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qpllx-009zTT-1x; Mon, 09 Oct 2023 08:37:53 +0000 Received: from mail-dbaeur03on20630.outbound.protection.outlook.com ([2a01:111:f400:fe1a::630] helo=EUR03-DBA-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qpllu-009zQj-23 for linux-arm-kernel@lists.infradead.org; Mon, 09 Oct 2023 08:37:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gKc5UPXsps8k07pZwTLbrGlLgBDwplJAKptrzcaUUj44Cn++3uaY7UKZiB8D2CF524EANN3IsRVuTJaZ2CsU+kXcI9504k/lJK126U96n8ksjdGhDuBk0oJPvQdvSLSb3huu0xg5p6ZCIjY9MEdGU4QGFwWS0Esz6EbnDTZiNtcs/dqRmxXYl7tEr0213ufwn/kjhFbH/8DxDW+WW1RtKv/pvnbhMyIi6dH6I2lKvbLRkuWMA66XzTSl/F1p6VlL3+IAxMaMaYv+gJdePP7Ba68JzQNdw3zMLMoa0RDCSBAn9I2nmqtMuWAFcGH2+7SCUu3H4JmLEj+ylnJllNCMyg== 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=Cscca7jZLxyeIqr8tIsso93/AVDzoFbpup35yfyFjQo=; b=F4RqxbYMWVJoBxkhwGz1mQcfC/nBAtWvmwRE2pQYJ7iccf8v7ltrSIRaHnF6/Icw8CLkP43aNwW1JKmfqOP6RpVgO5fuaIST9UWRDwWhHmx8BpDZ2zyXFdhxRcmtKnp9Nhjtp05YKV0yFSoWtHPJQC/WovJtm2MajJKX97lrrg8pgYJ9Igl7CEawO9z73pnQcb/0GapGZFGgGV0A448fhgOK+RDJJlDJvwGExoiqR1UdTxFMAlA0v85zHS/S29aT1dvGYC0a4xawpwH8uJ9VSgtDBQ6Tqa48vaFQMYCgzISUUTiifUuLEaFE9cLx12jqcfsqsP1rEv54A8RH9XcrTA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Cscca7jZLxyeIqr8tIsso93/AVDzoFbpup35yfyFjQo=; b=XNztLca59uQvDudCY7UVfnibPs/mY2+mjxABJg908gVXm66d9rLM7qMsBJ+fg2gqLa3Mxy2G4SMDD8HpL2FkRQ7REHd6G8hd+7CFPHsnwYdM8KJj4ZZt+lU5mFOtjKKfRI+7DWzkwFUwue+NZub+wWnBB4kw0b92se42ultSgtQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8642.eurprd04.prod.outlook.com (2603:10a6:20b:429::24) by AM9PR04MB7585.eurprd04.prod.outlook.com (2603:10a6:20b:280::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.37; Mon, 9 Oct 2023 08:37:39 +0000 Received: from AS8PR04MB8642.eurprd04.prod.outlook.com ([fe80::258e:61b0:da64:d168]) by AS8PR04MB8642.eurprd04.prod.outlook.com ([fe80::258e:61b0:da64:d168%5]) with mapi id 15.20.6863.032; Mon, 9 Oct 2023 08:37:39 +0000 From: Jacky Bai To: daniel.lezcano@linaro.org, tglx@linutronix.de, shawnguo@kernel.org Cc: kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH] clocksource: imx-tpm: Wait for CnV write to take effect Date: Mon, 9 Oct 2023 16:42:35 +0800 Message-Id: <20231009084235.1944917-1-ping.bai@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI2PR02CA0047.apcprd02.prod.outlook.com (2603:1096:4:196::14) To AS8PR04MB8642.eurprd04.prod.outlook.com (2603:10a6:20b:429::24) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8642:EE_|AM9PR04MB7585:EE_ X-MS-Office365-Filtering-Correlation-Id: e04e93a8-5783-40f4-e70c-08dbc8a2feec X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EuoIev8RgYUxJtMSI5Q2+9HKK/N2Z8d/9szcm6bOR3Nes1OfqhqSFsLZ0RrEgbYvgB9QLQHxxuZ/CY9aAOLOP9PVNGY6IyiEAq5ocz2bafCzUfN52LodDPskDjLqSnrcUs96xlkNkhxWCKUdH69jfdouUNNc23ljzXj2bekLdeSs6vpqbkvcHTt/GPm/j5Drxo7SSXzn1qrIQQlioIwaGOJmC3wlulJiY/BEIqLIVstOaieCmf1gaWfoFlgmrfroC517JxpruwgXFInMSIoE2h9ixKvpjqwgfTWYH0jmU1lfCzvRgUtrseobR0zXVbBEvrmIzYh3poM7C047hSrQBqqTsB00xU2kyCzN9wDJt23Yix6xpbjCYfAH/W1bgEqt++UtNAggLcpMKkDD37pMrSmIahCYTfOrJmeXNxlB8e4iAoNketVdaCo5BaL9/6XnGCOVgvquH5TUYV/qOfBAn6ihriArAgaGw9noN64PtGDqSODBeQTJveziN3roOLhE/1BsktcpEu/mjBFwbsX3hbTxRH7s/52ULkdc1+0FKhJIzTmFKnp5Hv5oCE5q+SrWYla2SMVqJIPGuquDJ+p0Vcbs2CjMXM50DFAHopXnSMTVOprJgBcHtM6XfuI02fUU X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR04MB8642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(64100799003)(451199024)(1800799009)(186009)(38350700002)(38100700002)(86362001)(36756003)(2906002)(6512007)(6486002)(478600001)(41300700001)(8936002)(5660300002)(4326008)(8676002)(6666004)(6506007)(52116002)(83380400001)(1076003)(2616005)(66556008)(66476007)(316002)(66946007)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XRuvFysb8HakDb9r+26e1elhYTXRjR1NGYVs03WEuVUvUnpceDWyDsdh9b2i/knfaXf/pz8QOhqTJPMzGlTn7cukg29HB6IUZDmjMm0S7UreqBVPHn2sZ660J5eLv6cfjavIyD0A0fwN9OJc322ejgZm14/BooZp3XKNPIIlyyAuLthsyJXiE7JI4IUF6DKpa+UxWNaRqOqIY8P33T4yBu1BZ8cVqE9iwxWf9DqBpOK0A8f5i69E0cMTSlyEh0SFwufkyLo3fTvkUPXnsXancfzhttFFP+/S0LK2/H0TX/4GUEe0uemjC8MfURqolShvjlrxc/M1ZAuP+zDq2LF4RDMEDqRHy/Sap9MpN18uz9HdpRZsV6hDgJUGfAoH9FN63nQ/HKjPstuq7XXNURRrCRZ6q5KHXM16A71dS2GRnr+i5LTMQdY0uYg44275CubX7SwpSv5O05a/A5IfnH1qUrzS82WLxbv0TuefNKqCQqoNK688eNOBnoPZZeqII/1RggKmCB5qyGG6uFnZvj4jhP5TPSML3X4WI4Qwcqr1mkBV3vKIwBZQugVGSYfqIlQyR9tlJT19688F9D+rXbpQbrmfyrlqZGFNC8GF2tbft9sxBLmchafzXL5iJBlWRSzBGLEDjfSgbapHK3Rm5dhyH6OHHDnCzUSxUdPer0OM9ogtnoEbK8FLcZYhsjV68JdOCWUvWWzC+0LMdBNZetPOCo1fr9yDF+kgTiM1FardFcSPIN76eedUtpYOTIxIK2DKs8HObQU+EQiyaAPfX3ONr7Xs7CqJWMTbOnCY7ppAeE0T8PpCsTx2hDIJFShPggt4jQR8NMeZQaj8hPM02LR/o/vVZ5VLsjEW7DNCY+v1OuqpLnaK59SjZJBQ/DYu+AWBwcJi1uL4rlNemoexVfpoPSY+oM5nT+5GJRlhxT/3PWIksfL6qPmsJ1TdngDyCKjfwUDE9zPyHyDtUkDiyB/1xgGDmcS79z3JS87EG6zK2jXV2QYubAO4I3uInsU/uUePRUPlvpx8eSwv+GE3WwHnF24ZcMRt9knI+GL+uE/Pu2lTtbrxsR+QxQrj9UirEk7SWolPecCxFVkmJDFeutwK+65jksDtM3DakVZZmZOEJNE6Rd9L5XCKEiWnsQNcZuEz0q/n9WUQZkRiq42KvgMqbJyEGsspuWqMSIjbCVwxj4SHMm3ws9969LAa+eUghAFIM2Xg2X+H5Fq425ABb/iHjFvLfNuKViRDsl30FmI/nLTmAwtnpomoNmZRI6Ms5etKvdgap+2J6gSGv1yqPKXzWO1KIVCwJGr0C7n0+vYFUuoS5oMW58JPp4sKubR322gHpJhNmVhq/P6f0XnpJgHzJPE/Rr1jQlMi04+198VabsQOg6UGTbVDQ+FHiSAqU1db63izH2xTQgUF07w0qe5g5iU92mVUdS2Rb6HLK2fGjViQqagDzcrIkVL2l1j6+pDcmh0sTgqBgZFKN2WPMEwdLLV4xbp/EeMzHdWbuQjPFOKCQ5Rz2WU4PWzy9rswh8PkC7xeBW4RQ8rp8C6Hov3LNP7RQglbiOIfnWck7mpg4tmymxGpslxskYKbIOSzeqUE X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e04e93a8-5783-40f4-e70c-08dbc8a2feec X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2023 08:37:39.4249 (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: V4Prb/Kfb8Y8dQPm/SJ9C1qVD9cx7/wcN2WUavoq9O3V9rgiCRD8ypjHHc3Ncqg0YA8+AUAfVKxXUUvNWBUMNw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB7585 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231009_013750_674907_5CEF6ABF X-CRM114-Status: GOOD ( 17.13 ) 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 The value write into the TPM CnV can only be updated into the HW when CNT increase. Additional writes to the CnV write buffer are ignored until the register has been updated. So we need to check if the CnV has been updated before continue. Wait for 1 CNT cycle in worst case. Additionally, current return check is not correct, if a max_delta need be set, it will return '-ETIME' wrongly due to the 'int' type cast, so refine the check logic to fix it. Signed-off-by: Jacky Bai --- drivers/clocksource/timer-imx-tpm.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/clocksource/timer-imx-tpm.c b/drivers/clocksource/timer-imx-tpm.c index bd64a8a8427f..92c025b70eb6 100644 --- a/drivers/clocksource/timer-imx-tpm.c +++ b/drivers/clocksource/timer-imx-tpm.c @@ -83,20 +83,28 @@ static u64 notrace tpm_read_sched_clock(void) static int tpm_set_next_event(unsigned long delta, struct clock_event_device *evt) { - unsigned long next, now; + unsigned long next, prev, now; - next = tpm_read_counter(); - next += delta; + prev = tpm_read_counter(); + next = prev + delta; writel(next, timer_base + TPM_C0V); now = tpm_read_counter(); + /* + * Need to wait CNT increase at least 1 cycle to make sure + * the C0V has been updated into HW. + */ + if ((next & 0xffffffff) != readl(timer_base + TPM_C0V)) + while (now == tpm_read_counter()) + ; + /* * NOTE: We observed in a very small probability, the bus fabric * contention between GPU and A7 may results a few cycles delay * of writing CNT registers which may cause the min_delta event got * missed, so we need add a ETIME check here in case it happened. */ - return (int)(next - now) <= 0 ? -ETIME : 0; + return (now - prev) >= delta ? -ETIME : 0; } static int tpm_set_state_oneshot(struct clock_event_device *evt)