From nobody Fri Sep 25 09:22:49 2026 Received: from TYVP286CU001.outbound.protection.outlook.com (mail-japaneastazon11011010.outbound.protection.outlook.com [52.101.125.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC022496D56; Mon, 14 Sep 2026 20:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.125.10 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418239; cv=fail; b=gXupRSJs24ONERT9pIMx1v+rZeUuzTfVclTpVk+yK4gERFQPlVwfbFjjHwlUXjJ3FlQ6eInXr++bgGJ2NO3TGGkv/ZTPCaacyjyZv/APuzXZC08zl7ZVYuPx4oFw2bxVHDwRl4cY+MS2Dw9yhkxJzMVT3Oct+H6mNLCKtKBDb9M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418239; c=relaxed/simple; bh=FZsFxb3YpRJY0NTWRXqsoEn+YdaJp1SBy+9HNyFJ8G0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Jmx4lC0mkh6xYwlUMGCABLGj9KGaExHA1wxwaug2dkCC1hfJ49j2h8BoHRZohJI34K5IZv1ZnPonZZjE4v/8Y74CgQMPaNAA1do4O5SldvAbKao6uEEOt1Owjci1gpD22X4G5pM10awrWYJ0/3k8LKHRDERIUgMClnJ0Z1q6Olk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=HukmCVxc; arc=fail smtp.client-ip=52.101.125.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="HukmCVxc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tBAbbdzXGtGTIcDGW/s6edYy4S1fxHCQGiVvu+yTf5I+h/ji/CB/sdWeL2mzbdR5/k9/5oW67vPlcWhm8aunFcOuV/J3xuzgRCPHQdD8RnEPTb+llLdu4DHBv+ihIfgRQ9LZTReUQDUyBXIwKsi//0PfirXAnlEBz6B5jcny9OUx87AL9NX5XmRrAp60rxL7sgJE8rhuc5OZKzns2eMzHliD+G66s50tRO6cpzvFNGY3l9Rf6Q+WFg60Yl50pqOVMcv3yej5pTbe8ipopXE9e1DjWtMIiWZT+/L72ZnkdNocljt9qu7eA0BDUWPcoJulrwn0MVj6LHl1dl02lTDmcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=MjRd2/KFe+ZoMMAx1xG/bWi9V9epDXIfK7DIKCJEePk=; b=RKYqzHUAdkrSWlOf9rxBBSXO+zrDclRmOGJ8O+dfI5T75LOCjdMZDTEOUpx6XURlE5BCzqTxL96iqqk/ji2jA1uZQA8ZRoNGBRikHuJnw1+HdKAZo2Ed1HaaMf7enucBmZ4GgrBwrDMOSiZ86BDfZgRzXdAMhSZ+TeLHXExRZ/kJ5aNam1kNIDAMOO5/G1u8u7wlSNUdVMYvPluuJYpTHwjSE/H/bilfZaX+RPi3897DwvstdsPb3bNz/8xVRyoWtTQwCmQBzsyByjv589tJylV/DYwxbdY/YOTs9HQ0dHkiFl59Vvcf830qngQ1V+7jzOsDck2EH6oVjC9fUrldjg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 8.62.32.50) smtp.rcpttodomain=bp.renesas.com smtp.mailfrom=renesas.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=renesas.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MjRd2/KFe+ZoMMAx1xG/bWi9V9epDXIfK7DIKCJEePk=; b=HukmCVxcdFCYVLIXwftwhd5Gu7MsXpRIxteNuoAVC6RC9LB1YgE7whogv3V1DowyeKi3QO4owB7FtGnb5OO8Om8Sv5GCHZh1XaQPheiYf1LVgohNnlUDcgehwCvNO+hiPpCkrpS8GUeGZwHvY7sc+MdqIN5It+1igsHnuTUh59M= Received: from OSTP286CA0112.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:225::12) by TY7PR01MB15390.jpnprd01.prod.outlook.com (2603:1096:405:246::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Mon, 14 Sep 2026 20:37:15 +0000 Received: from OS1PEPF0000D215.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:225:cafe::a1) by OSTP286CA0112.outlook.office365.com (2603:1096:604:225::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.12 via Frontend Transport; Mon, 14 Sep 2026 20:37:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 8.62.32.50) smtp.mailfrom=renesas.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=renesas.com; Received-SPF: Pass (protection.outlook.com: domain of renesas.com designates 8.62.32.50 as permitted sender) receiver=protection.outlook.com; client-ip=8.62.32.50; helo=ejcrelay004p.adwin.renesas.com; pr=E Received: from ejcrelay004p.adwin.renesas.com (8.62.32.50) by OS1PEPF0000D215.mail.protection.outlook.com (10.167.240.22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Mon, 14 Sep 2026 20:37:14 +0000 Received: from demon-pc.localdomain (unknown [10.226.93.156]) by ejcrelay004p.adwin.renesas.com (Postfix) with ESMTP id 067913000437; Tue, 15 Sep 2026 05:37:11 +0900 (JST) From: Cosmin Tanislav To: Biju Das , William Breathitt Gray , Lee Jones Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav , stable@vger.kernel.org Subject: [PATCH 01/15] counter: rz-mtu3-cnt: put runtime PM on initialization error path Date: Mon, 14 Sep 2026 23:36:00 +0300 Message-ID: <20260914203614.2035277-2-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS1PEPF0000D215:EE_|TY7PR01MB15390:EE_ X-MS-Office365-Filtering-Correlation-Id: 9dfe3be7-01a5-4ad3-2942-08df129ff62c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|23010399003|376014|36860700016|10067099003|18002099003|22082099003|56012099006|11063799006; X-Microsoft-Antispam-Message-Info: bSiXjP80Y45vDOHjIMmjiU/QLjxrxkvLIjWoAnRx5fokZeYV+SFWFyAq3L2ZwNlK5yf3j2a8yZ9059xxxiycWgEbI5u6bFn11Mdep3thHHsCUe0Jvm/Pyqy3Yhc548NaFiAvlGd4lnF770hQieyyNDLyCGhvS65aHYn0EcEwzmTUAPgToXrfXSD/4Id9jQVSw7z5ZEwAgoAIbcLl+mvOdo9YEhAmmYh9bEXKjtpYsOOX6WRD5Ai4bddPKX3UZwjrfufL64W0EYw3B33tPESklAgWSGnKEEjPtTuOIYpkHfU5PIumNmqbjcvNGfkeR7CXpLtWRWUp+FJI8RA8APdK/PTNE1fdKQr35dKz5YTQlAGVacTH6Et/fzzr7/kixG0oOQjMOR5tMkUk4AuW8VXhm+/Bo78rHEueEejUJK0YAldn1+eorOKg/84ybVEE/1R4EaPrt8/Yu6vUW18gtsvgILjEr+Vy+pZbp8cfzTxZvNbAQhWSAU8eWazlFW82TTW+JxqmAjbNPVCsDye8fQJBgsN+FG/J73c/vKBHN4IFPD2SdHv+63+dW3AIzqmtATsfZWF+M4NmxbvjnyOtBC8C7KsVungn4SDTTFnahXI588BVwa8kLMnZKoVleIsM5JLPcL9p7ah4K8n+F+VpEILfjMYoJWSloZrXAzQW+FxHAoavXH9ekiuxfM+D0Eex/SM+k8kGGYEn2NQ921Bdx28q2Q== X-Forefront-Antispam-Report: CIP:8.62.32.50;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ejcrelay004p.adwin.renesas.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(23010399003)(376014)(36860700016)(10067099003)(18002099003)(22082099003)(56012099006)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9Olz+J4pgR7UAHC2FCc56/UWjvvV/6yq9dQlVBK6Tzs4XoneFrHEIDIgQVK+u3d8B8LJYrUBvyjaq2ShUUggkImLpqDfTj6FNjgC52JL6zmnPda3gdmnu5i0InU/CJUtGhmV4FMlDV/t8DVkORIcki7fBVJd2gKUAFDIyvHWlIWr34zicbt7pn4LKmlITrMWOIMOD9gOwdp1N03G7mC9IiHPnlImyyPFcbU5Ufbc43JLG2HBTpK42xOrsX4vdKNiMdmXomEBSIKn8yU4rpuxYWPg35bv1P8/wCM/A2Fx48zxDeoMOQJWPdb0GI7LdJs141vUNwkTPKfF0Sp8+AEQDd0fkM7uIGUNMfxmtmvBDDdqy9LjGMmQK24CHudDpaAHL677zVaRVM1Kf5FufwcUMWammg1kvnAceCLz0YNWxBbPe0v34cuyChvbGG9ency+ X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2026 20:37:14.8455 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9dfe3be7-01a5-4ad3-2942-08df129ff62c X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=53d82571-da19-47e4-9cb4-625a166a4a2a;Ip=[8.62.32.50];Helo=[ejcrelay004p.adwin.renesas.com] X-MS-Exchange-CrossTenant-AuthSource: OS1PEPF0000D215.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY7PR01MB15390 Content-Type: text/plain; charset="utf-8" If rz_mtu3_initialize_counter() fails, the runtime PM usage count is not decremented. rz_mtu3_initialize_counter() will fail if the requested channel is busy. Call pm_runtime_put() in the error path to decrement the usage count, and flip the check to keep the success path straightforward. Cc: stable@vger.kernel.org Fixes: 0be8907359df ("counter: Add Renesas RZ/G2L MTU3a counter driver") Signed-off-by: Cosmin Tanislav --- drivers/counter/rz-mtu3-cnt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index 7bfb6979193c..48f183f0b54f 100644 --- a/drivers/counter/rz-mtu3-cnt.c +++ b/drivers/counter/rz-mtu3-cnt.c @@ -506,8 +506,12 @@ static int rz_mtu3_count_enable_write(struct counter_d= evice *counter, if (enable) { pm_runtime_get_sync(counter->parent); ret =3D rz_mtu3_initialize_counter(counter, count->id); - if (ret =3D=3D 0) - priv->count_is_enabled[count->id] =3D true; + if (ret) { + pm_runtime_put(counter->parent); + goto exit; + } + + priv->count_is_enabled[count->id] =3D true; } else { rz_mtu3_terminate_counter(counter, count->id); priv->count_is_enabled[count->id] =3D false; --=20 2.55.0 From nobody Fri Sep 25 09:22:49 2026 Received: from TYVP286CU001.outbound.protection.outlook.com (mail-japaneastazon11011064.outbound.protection.outlook.com [52.101.125.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98ACA496D56; Mon, 14 Sep 2026 20:37:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.125.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418244; cv=fail; b=W9j9b5ND+ZA7yEiI8io9JKt9OaeBqnpuHVG0ePMst9V9jys6bqRDAVtVPYLYYcRdSWVf0MTdzMRs1S3disLoejcPkky9NPAqRFeq4UDouQ2CTl3+SRC84XGbwvvvBZmWxWhTCsPP8T5uVdCnW9RF+/AgiyoavjtAw6L7zRxvvQY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418244; c=relaxed/simple; bh=szhwdIqwdhjxK1i93afHCTzNimI4pvXleIOqYNVVjkg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ecEGwGhp66aizVDB0DDlvjjB+58844WXH4nFlNrq6qev7J/pmU/yXH+Vc0FcRlmYtg7a3gALASND+s00OzxLP8Ek2SBhYWUAFhkL9hgDMRvOcdgjZD+NnwbYRbh56WZJklXO607wqvyW+eOYHXLH+pnUcz4HGIZkkUhTzqiKky4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=lodGP4a+; arc=fail smtp.client-ip=52.101.125.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="lodGP4a+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PYxIw961j+PW8LeBTilX5OCY+508ZCstpl8+spQMgpvLP0zpWlKEMpXOsJz9vDi5f69EWgYM/iW0b+HHDi8DOVqO7tPeNRd7NleybtiQx6KfFHc+dyf32ZkZXeDu9791MKUrlXeqSTASST5ZOh3em0oKa+a6lcrOLYO7AG2OsUg9HyhaxW/wy86ABNFxv71L5ZiMiQF1r7E6P1ig9hZ7TIrpDdIODHzkt/NpwTTpPRe4PjdzYvtjIZ5MD1ChROEFKUQ3mX5wDqViTsC0dyQlsWxtzy7EJO1RmZuFgWT89tJ6Egv7POdh1ByG56k1vUdKfSXWfWC5W+ClKLnCZNC3dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=z9pmOfM89QuSpb8Q2w6OV8BkczUt1oXm4J3mTjhANnU=; b=I0kL9cLwMmQxed0vhlPkccLfwLrYrm8zXLXuHnfO6dvjbX/YFWIGoPhz+kQN3DA3QvJHEHa0icd5ywAkEylpWNNAH2JnWzf8+J8AWdC3721yv+8WU4Lhy1WYnuY0ZxiQh+MUMwxB+RNxRW0EXJfzKupW1cGcKxlzCpdcay4AF54sDhhpcHbvWZckzrgiQwDbI7l+FeVDUMAxxLuOIaC2PM9XT7O66hDefDDYRFzS4Biv63eVIZCE9O6JBffdqggIMO01VPuO6yQZ0IVMbdQoSHe3jXvwX0nTh+ohpBQjtNRl6OthJ0Z1M5ncf5lUKi7lslElQVDEsgUs/rBm0PaFqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 8.62.32.50) smtp.rcpttodomain=bp.renesas.com smtp.mailfrom=renesas.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=renesas.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=z9pmOfM89QuSpb8Q2w6OV8BkczUt1oXm4J3mTjhANnU=; b=lodGP4a+YEnPoFwrcL4GP13/gVjhoRavGLtTshfTwwC7EobWa8kLPNZ8F8KnC77V3tDun+Irpj75KjJMFlSEnIasJ0bkafGjaUYN6tratqfA0Ovh3V77vFFr2NGlTk1yusTOViulSnnWgONSM2pILsnTBzhE5hS/vgJurbZOpCQ= Received: from TY4P301CA0060.JPNP301.PROD.OUTLOOK.COM (2603:1096:405:36a::10) by TYCPR01MB11752.jpnprd01.prod.outlook.com (2603:1096:400:38c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Mon, 14 Sep 2026 20:37:18 +0000 Received: from TYO1EPF00005024.JPNP286.PROD.OUTLOOK.COM (2603:1096:405:36a:cafe::66) by TY4P301CA0060.outlook.office365.com (2603:1096:405:36a::10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.13 via Frontend Transport; Mon, 14 Sep 2026 20:37:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 8.62.32.50) smtp.mailfrom=renesas.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=renesas.com; Received-SPF: Pass (protection.outlook.com: domain of renesas.com designates 8.62.32.50 as permitted sender) receiver=protection.outlook.com; client-ip=8.62.32.50; helo=ejcrelay004p.adwin.renesas.com; pr=E Received: from ejcrelay004p.adwin.renesas.com (8.62.32.50) by TYO1EPF00005024.mail.protection.outlook.com (10.167.240.21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Mon, 14 Sep 2026 20:37:18 +0000 Received: from demon-pc.localdomain (unknown [10.226.93.156]) by ejcrelay004p.adwin.renesas.com (Postfix) with ESMTP id C35493000368; Tue, 15 Sep 2026 05:37:15 +0900 (JST) From: Cosmin Tanislav To: Biju Das , William Breathitt Gray , Lee Jones Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH 02/15] counter: rz-mtu3-cnt: do not assign struct rz_mtu3_channel::dev Date: Mon, 14 Sep 2026 23:36:01 +0300 Message-ID: <20260914203614.2035277-3-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYO1EPF00005024:EE_|TYCPR01MB11752:EE_ X-MS-Office365-Filtering-Correlation-Id: 1231dfac-9d2b-483a-0ef3-08df129ff840 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|23010399003|376014|36860700016|10067099003|7136999003|18002099003|22082099003|56012099006|11063799006; X-Microsoft-Antispam-Message-Info: o5tqGRPsAX4ukLDt7qQWFoEBKoBEEfUVYEzLlAcQqu5C/T6MfFSXK5MVULWKuXvIPDAd6256DvMLDmfg/q3gNdXm8u8uHm0ltUSX8fL+aQfyKoYoDANhxH02m5THkqSBaU8bTbSy+fFLh61Akn+3dfk1us4hZOrolAKmgseRW5mmKyla8WQioiPJZ2qVokf1SWqPUH2sdQGQuZFbv7Y+9pIARgEwfXpDbbpNChcp/Zl5uNsYdjjnCYhjdZyKVEikxkyWbgUMLcZyearqY33tnQHRrrgbGUxdF9w1Ouxo/lL8Ssh4wXZoC5QkwwHJjvXOOC0/pUJ+aGv1LSOoMLqMg0CLDroKuWe718nV3WWwTc+p14ZERWO8Jk2GqbSBPSlqOBunKpo2pchbFjPG4w18ucGtloyB7S9+f25IexK1+3zDckGaQvtOXyvJIh4tCX73+k5YNup9/rFqZeOu4+gbzn/G74lKdLkNiuDs9BWubpFYVeoqHvYEr5TN5fd5uDrzsN1FGeU23OzP9C3fmYL91ERcniIngThI9fPAt/qPbCo9GsvjuDUHLtZujPD9c84eIp0AnzLZQzLxcELg4A+ZSVkMrpmPlMh9h47ES79IPpvG9ahqo7XBS65TwIKY677e9tJtV0RgiTF9fqushEBBoP8JuwppmhhcmUOr6CpmVSZ26LB67ZuIUlhUAca3vzV0SJbigi7DkqDh511rFRLaMg== X-Forefront-Antispam-Report: CIP:8.62.32.50;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ejcrelay004p.adwin.renesas.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(23010399003)(376014)(36860700016)(10067099003)(7136999003)(18002099003)(22082099003)(56012099006)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OAnNXZUfOzMJqKNUOue2F42eJOTJQ4/A7KBfsRg2J8f1xAtyyarTvJgA1vYAbAT5jvLcpeHDIS07YmmjJrN3jQ5VcN5gF/AMrmxrbCgTYnu+f0/V4djaZbCoIHmakX6P+85hk3cXGMxAM7HZ5cZl2I2vMwU3CcdKlnYhgmaZ+oMfKOmITLutwjQLF23m3rGm6SrY33aMNvi9bDe34XHT/B5RnR5Rn/VWP4l56yjN/NIQwq5pK8ffnXDCIZF1NiLepvxGNWzCEI2gICSF2uRbixGjPsjm3PPPP8VUNCgXpDUNUlspVPxfKpROIe6J8DeNwZjhk6MIyAnB1P5tYH0bzLRSQTgY0mWdBSw37JqbL6b3LS8WD3WQTHiZ186wgbi893kbYd2JiOrTR8gpDKOLJlohDxlvlpIIqsrgBQtveWh68zqRGnmLlTF10l4TwLoU X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2026 20:37:18.3445 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1231dfac-9d2b-483a-0ef3-08df129ff840 X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=53d82571-da19-47e4-9cb4-625a166a4a2a;Ip=[8.62.32.50];Helo=[ejcrelay004p.adwin.renesas.com] X-MS-Exchange-CrossTenant-AuthSource: TYO1EPF00005024.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYCPR01MB11752 Content-Type: text/plain; charset="utf-8" struct rz_mtu3_channel::dev is now unused. Remove the assignment to prepare for removing it entirely. Signed-off-by: Cosmin Tanislav --- drivers/counter/rz-mtu3-cnt.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index 48f183f0b54f..4ad71ed3d1e1 100644 --- a/drivers/counter/rz-mtu3-cnt.c +++ b/drivers/counter/rz-mtu3-cnt.c @@ -843,7 +843,6 @@ static int rz_mtu3_cnt_probe(struct platform_device *pd= ev) struct rz_mtu3 *ddata =3D dev_get_drvdata(pdev->dev.parent); struct device *dev =3D &pdev->dev; struct counter_device *counter; - struct rz_mtu3_channel *ch; struct rz_mtu3_cnt *priv; unsigned int i; int ret; @@ -856,12 +855,8 @@ static int rz_mtu3_cnt_probe(struct platform_device *p= dev) priv->clk =3D ddata->clk; priv->mtu_32bit_max =3D U32_MAX; priv->ch =3D &ddata->channels[RZ_MTU3_CHAN_1]; - ch =3D &priv->ch[0]; - for (i =3D 0; i < RZ_MTU3_MAX_HW_CNTR_CHANNELS; i++) { - ch->dev =3D dev; + for (i =3D 0; i < RZ_MTU3_MAX_HW_CNTR_CHANNELS; i++) priv->mtu_16bit_max[i] =3D U16_MAX; - ch++; - } =20 mutex_init(&priv->lock); platform_set_drvdata(pdev, priv->clk); --=20 2.55.0 From nobody Fri Sep 25 09:22:49 2026 Received: from TY3P286CU002.outbound.protection.outlook.com (mail-japaneastazon11010005.outbound.protection.outlook.com [52.101.229.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 811D549F12B; Mon, 14 Sep 2026 20:37:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.229.5 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418247; cv=fail; b=DMV37Hg5TZlL8g7coMF62Q3KCXAGlAmUSoJpm38bmyHdDqSweHWGfpjO2Gc99EbE7FmCKJ+cs+PEjWBA8djZaMOUz0ELbnMoCf9pXs1xUPdAtNyCX9rKtCuwX4SnkyGOpeMH73kqpOBwXUkF2TWa3uFpDvMIAEWN3UahWlrRNi4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418247; c=relaxed/simple; bh=AD+zywaqsFMKbiM6GT112mLj0cZM0PDU7j3SenrG+S8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BebppgWlsJpMY/tM70p1Fred3csVYuhJfz+5PhrvPf7DnN+d33Om6Pbe8D6Osh8VSBQx3hPaVRoj2Mcx/c9yHdRU2vXAtLD78ByfI61+PFyetdHlcxDvTAkT6F6kka31sLUevIayl/wYM4ir1F4rbCfzvmhJPLc4QwQniZ6NFQU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=V7yaN6Cu; arc=fail smtp.client-ip=52.101.229.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="V7yaN6Cu" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WxrT5v4Laa/CfD7b8Ghoxnxk6frEym30+b+NTpZJJP0FHu0nNK46g+5INHMJwLR5QHq/fIrdAhjeON1lIaYMJU7MOQdJx8PTLGqbNC8X+OqJvYfqkUxCrCTyNx1a8DFbAI56i79mcXg5JQgSSHPGlw8KoiIi/1fq4KEpPsYIbLKFsoeRzXLiVuemhaTbQ0kxlSTOqr/HxAs4kWecV8F0sOaDk1CGvf0utlZXtNHgGHS2qbLkDmzbgqlMgcmWoaCnxjg4b9NeK3Hl/xw8VWem0PK8ka5mAXZe/d5LR/W3YrxhykCYA6aaVaz7DbjtdVIRPKZ9iZupgAJruSh8x8uSiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=GauizuleMuTHo/B2xCiTqWoAUunM8m8JYatwz+NiyaY=; b=KFhbsZ5LEeAJFMeEqzQdZaLn9yCQ5AoNSKuSTJMozfnEwrzMp3v1xpxaDaH0+JcXRDWfSYs/Ltpm8ynhYRx4FuUxnV9LlmxT1oSEjzZn+EuVS3Wf1OZioANj1oviJymjgpnDkV2nLk1ZoEYgKcEN8rE/p4h4mlOXM5rHfX+zJGQs3KBVZGmX91kLikKNV+2Gw7cN7kCvX4qSU6YyfAtSa7srHa5hFP3nSzL3DEwgfmzoqeuOQlJBeqJaYTcMLxY8pmcknlAjSQZRi6Qm4PQ8eegqTLXphEizjtZhUZ1u62qD8hLJWrT13bhkKKrhcne9Md6GXEpuQPu8eX8wuF1M9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 8.62.32.50) smtp.rcpttodomain=bp.renesas.com smtp.mailfrom=renesas.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=renesas.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GauizuleMuTHo/B2xCiTqWoAUunM8m8JYatwz+NiyaY=; b=V7yaN6CukhG8GNdAFur5omvxcYbupa/3v3g1tm0GqYWAWP5gWmjokNclxvlUwhT2UJFqXx0hfpe2X3/Lk4TbCgp5J+SAnkzqkXmWYoF1tF0wrmPDOK6yt5/XKehsBDN3Vv7U86AgDOfbk2usy9/XnpXjWTVtVQhukS0n6FDOdCo= Received: from TYCP286CA0275.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:3c9::17) by OSOPR01MB12345.jpnprd01.prod.outlook.com (2603:1096:604:2de::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Mon, 14 Sep 2026 20:37:22 +0000 Received: from TY1PEPF0000BAD8.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:3c9:cafe::7) by TYCP286CA0275.outlook.office365.com (2603:1096:400:3c9::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.12 via Frontend Transport; Mon, 14 Sep 2026 20:37:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 8.62.32.50) smtp.mailfrom=renesas.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=renesas.com; Received-SPF: Pass (protection.outlook.com: domain of renesas.com designates 8.62.32.50 as permitted sender) receiver=protection.outlook.com; client-ip=8.62.32.50; helo=ejcrelay004p.adwin.renesas.com; pr=E Received: from ejcrelay004p.adwin.renesas.com (8.62.32.50) by TY1PEPF0000BAD8.mail.protection.outlook.com (10.167.240.37) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Mon, 14 Sep 2026 20:37:21 +0000 Received: from demon-pc.localdomain (unknown [10.226.93.156]) by ejcrelay004p.adwin.renesas.com (Postfix) with ESMTP id 70F173000368; Tue, 15 Sep 2026 05:37:19 +0900 (JST) From: Cosmin Tanislav To: Biju Das , William Breathitt Gray , Lee Jones Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH 03/15] counter: rz-mtu3-cnt: remove manual runtime PM handling Date: Mon, 14 Sep 2026 23:36:02 +0300 Message-ID: <20260914203614.2035277-4-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TY1PEPF0000BAD8:EE_|OSOPR01MB12345:EE_ X-MS-Office365-Filtering-Correlation-Id: b1ab49a4-0033-4e4c-8e8b-08df129ffa5e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700016|23010399003|82310400026|1800799024|10067099003|56012099006|11063799006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: ZVHCoyDB9LWYDwUUSxGVfrAJnNqz1Bgf4X5oRwhEbyIjsVBjR2Klnulz5tqmkJIA0KCQYceX/V5dZK24zPTX7CzqpAtxSTD/S0BPtLqV/AWm117ivx3avr+AtKWtLwSqEkUYHrjVnG5XCWm9FFix1C5hL9IYrvhBeUyJv44JJHx778LXpvCcYXhLfewJyGZ3AhXe2EExLiirxrIVpZguVu+/1QuO1+GnOLwu4DikuzdVw3AezK9oQLlI6O67W+7t61C2kO4o+CQ8J/yeMW76Nf2uFJuU9Ob5sTqfu7velx5Ry+kfCjT8RPX04gGthEfh1UTK9MX29P9wuEQ+V1P13cgy8+G8lGiryEWy4M5vdQGnaPWCjMpBzKIxgvKG4F48L836jvZ5UokEdSwl6+AhUgsi48rlqaosr1NNXvp+HofIneyzs8GiUluMsFvblRZg38rGXAP+JfhyEVFZIKWYjtg22g5QODrBrjrUF+Rb4DR9DA7m27qvGP3LUIOOsQjJHqnxbhNIWyl4U2R8CKsJ0jiJo74ystpNo4OY0fwrd55qyNMRmchHSXYVbHSelepLdx78PN8jAxlxIjC9ZimmCkPqbFYrIHqtkpYCw2755gaWilkT7q09B7dBjNz1eYOLntWRh6VZ2yqYJWLZdqYeXVo4sHCm4kEjdQ8oBWkXItZ9Gebhbf6twLQ8MbJwNIZ+6O+4uHf3jkXTZdIIrw86Tw== X-Forefront-Antispam-Report: CIP:8.62.32.50;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ejcrelay004p.adwin.renesas.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(36860700016)(23010399003)(82310400026)(1800799024)(10067099003)(56012099006)(11063799006)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SkOm1o2KIc9TjV+kM8O0sz7c9DWpscOqd1tId1YR4jLzRHaKdEPWis7/U0aagNsa2iZaivi9TwJNxSi67vN2lvT8qoZkaT5L5VCmWQjYESZ/Ool9FO223dOaCovZxQw37lO6Ye7gdI/RT/uOlQogD2WDublEQjdDgGYy0Vs4m/4DZkZbe1gZhVTwhqLE5qNC7Ui4btbIsxutS2QQnEjd8RQoGbDf/OgVTK45Ix9+5q/IDfcX++Ilavu3bUULVY+19q2vckPpLyyvxZWEfdvhNIh5eMxPbQ36amjdVFWkNL5MTc26OY9lJVUbaAv5TkBvJT8yNgwTZqbblinqm5MgZM8wNiomqRxnlsSTsIsUoYKMT3GZA6MOmKEZFud9wDi9OjyS9X4xTTt7B+7Ii9uXzfmyZJvlVb1uZnLB2uXmmMGTpuCKj95DL6oiWte2YG4H X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2026 20:37:21.8984 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b1ab49a4-0033-4e4c-8e8b-08df129ffa5e X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=53d82571-da19-47e4-9cb4-625a166a4a2a;Ip=[8.62.32.50];Helo=[ejcrelay004p.adwin.renesas.com] X-MS-Exchange-CrossTenant-AuthSource: TY1PEPF0000BAD8.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: OSOPR01MB12345 Content-Type: text/plain; charset="utf-8" The clock is already managed by the CPG power domain attached to the parent device for all supported SoCs. When runtime PM is enabled on the parent device, __device_attach() temporarily resumes the parent for the duration of the child's probe and drops the runtime PM reference afterwards. Runtime PM usage by the child device also keeps the parent device active. As a result, explicit runtime PM handling in the counter driver is not necessary. Remove it. Signed-off-by: Cosmin Tanislav --- drivers/counter/rz-mtu3-cnt.c | 42 +++-------------------------------- 1 file changed, 3 insertions(+), 39 deletions(-) diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index 4ad71ed3d1e1..6c171a741cc3 100644 --- a/drivers/counter/rz-mtu3-cnt.c +++ b/drivers/counter/rz-mtu3-cnt.c @@ -73,7 +73,6 @@ * @mtu_32bit_max: Cache for 32-bit counters */ struct rz_mtu3_cnt { - struct clk *clk; struct mutex lock; struct rz_mtu3_channel *ch; bool count_is_enabled[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; @@ -808,34 +807,11 @@ static struct counter_comp rz_mtu3_device_ext[] =3D { rz_mtu3_ext_input_phase_clock_select_enum), }; =20 -static int rz_mtu3_cnt_pm_runtime_suspend(struct device *dev) -{ - struct clk *const clk =3D dev_get_drvdata(dev); - - clk_disable_unprepare(clk); - - return 0; -} - -static int rz_mtu3_cnt_pm_runtime_resume(struct device *dev) -{ - struct clk *const clk =3D dev_get_drvdata(dev); - - clk_prepare_enable(clk); - - return 0; -} - -static DEFINE_RUNTIME_DEV_PM_OPS(rz_mtu3_cnt_pm_ops, - rz_mtu3_cnt_pm_runtime_suspend, - rz_mtu3_cnt_pm_runtime_resume, NULL); - static void rz_mtu3_cnt_pm_disable(void *data) { struct device *dev =3D data; =20 pm_runtime_disable(dev); - pm_runtime_set_suspended(dev); } =20 static int rz_mtu3_cnt_probe(struct platform_device *pdev) @@ -852,20 +828,16 @@ static int rz_mtu3_cnt_probe(struct platform_device *= pdev) return -ENOMEM; =20 priv =3D counter_priv(counter); - priv->clk =3D ddata->clk; priv->mtu_32bit_max =3D U32_MAX; priv->ch =3D &ddata->channels[RZ_MTU3_CHAN_1]; for (i =3D 0; i < RZ_MTU3_MAX_HW_CNTR_CHANNELS; i++) priv->mtu_16bit_max[i] =3D U16_MAX; =20 mutex_init(&priv->lock); - platform_set_drvdata(pdev, priv->clk); - clk_prepare_enable(priv->clk); - pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); ret =3D devm_add_action_or_reset(&pdev->dev, rz_mtu3_cnt_pm_disable, dev); if (ret < 0) - goto disable_clock; + return ret; =20 counter->name =3D dev_name(dev); counter->parent =3D dev; @@ -879,24 +851,16 @@ static int rz_mtu3_cnt_probe(struct platform_device *= pdev) =20 /* Register Counter device */ ret =3D devm_counter_add(dev, counter); - if (ret < 0) { - dev_err_probe(dev, ret, "Failed to add counter\n"); - goto disable_clock; - } + if (ret < 0) + return dev_err_probe(dev, ret, "Failed to add counter\n"); =20 return 0; - -disable_clock: - clk_disable_unprepare(priv->clk); - - return ret; } =20 static struct platform_driver rz_mtu3_cnt_driver =3D { .probe =3D rz_mtu3_cnt_probe, .driver =3D { .name =3D "rz-mtu3-counter", - .pm =3D pm_ptr(&rz_mtu3_cnt_pm_ops), }, }; module_platform_driver(rz_mtu3_cnt_driver); --=20 2.55.0 From nobody Fri Sep 25 09:22:49 2026 Received: from OS0P286CU010.outbound.protection.outlook.com (mail-japanwestazon11011065.outbound.protection.outlook.com [40.107.74.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 201554A0919; Mon, 14 Sep 2026 20:37:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.74.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418251; cv=fail; b=A5l7MX3Q7rVjzsSz1amHDwJaFN0PVr75Q5g4febeYKDtAf08aB0e4wbDxuHz0A5JpKMBtqJzdNlzbKLNjA25LC9qBcVCJHCn9hAD8HMHfvSM/buNJtnP5w775jSczxYIkRMP6OvxKM868wbs6lDOw0xFzVyuwwjggBbLA0rfm7o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418251; c=relaxed/simple; bh=jVUzCfKKGgG9GtWIiro3Zfmgb48o8D1y9Afp2lV68Ng=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ovwsqKnKiJBkOSHa8CZHK0VtwNvl0E1bV1ZV+oURQ/y0XZCvDk/h8FxLfrVR9vrfjdhZ45pf0hB3+sISpPzCRhqUinaDnKNKH+GfayqcOnj7l6d+N8Gz1ZfmIu99hEAyGuuJ5St/AQ5Ytd/PXJYF6LuTTEBmcXJSmmYMKD/y2Hw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=a27SRdkZ; arc=fail smtp.client-ip=40.107.74.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="a27SRdkZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=D4Q4nxAqlyAUu3V0KPYJA0dwSO3olCd/pgxqA1WImBGzt1Zay0RMvqFI4vparpXb81UGBeHkGyste+12BXbr0hVGlbxDx5TAxyXRm3D0J/h4MAMLasCgpBHypxO5fA/uhOMGCsxpGAv4gMhx052+bRSzCsv+Bc3QDkXYEScAVEAb6DwySQOsAAQ4rCxErCfU8R/qLVm6qNxDTniltNZAlZ0HZQ9wps3Ws8sUiW+ACgqIchOo3kRWFv+NeeYcOirqtoJCj4VBrpK0HpAmGZm4glMjVYnSROUrUidBlV/OxKjKFQQ/pYdAa4ezulTtkX4QUQy9+CKVkzCUQIRbstW6Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=FJO3DfoVEoXriQB/9K3Mx4V4EmKgVkoWBr65P7c8tHE=; b=dk6afWAJLSj6V1xiCPQOjOel3r83z+8taRJyVNSWrQVQbqzr4zl2eGEZBeJQz6/0MCoENMQcSJ+xBegxfaAjuXdgEHhyNAf0WuUFBC0cgT4c6UckK7hckO4wQFqgKAMFM0XSifjLeas6Hy7F8+283hUyzNH4Xo1ptgCbwO/mONMOxm9KtZWNIi0hjLscJLZ+tGaC3uMss2jYjSuRSPZ4Fe4cOZ5QG8LQCjNukwvrH/UPMTW+idGwFpZWPknRWXkNDCkiDSoBalKKmJQS8N1RDASGEcmdOa3i+etpbQVQCOCYxh+vqivhuwlkFoJ/R6VDLCd/n56pmCqKN+h9i6SqYw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 8.62.32.50) smtp.rcpttodomain=bp.renesas.com smtp.mailfrom=renesas.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=renesas.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FJO3DfoVEoXriQB/9K3Mx4V4EmKgVkoWBr65P7c8tHE=; b=a27SRdkZBI/MfVGlzf64WdYS3eXvR56R9HNOnyBMqygtMfdduEz0Xdgaz28WyokbptUonchP/CpX5HzPL1YYWFQZSQmKJxbd1m4PkNJEyIWicVlCO9cnTn3qeaKh8BYTglIWWGz/YUeKee0LGcgU+FlP9ywxxY5TMXHnPbCSCFM= Received: from OS7PR01CA0278.jpnprd01.prod.outlook.com (2603:1096:604:259::6) by OSOPR01MB12185.jpnprd01.prod.outlook.com (2603:1096:604:2db::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Mon, 14 Sep 2026 20:37:26 +0000 Received: from OS3PEPF0000003D.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:259:cafe::48) by OS7PR01CA0278.outlook.office365.com (2603:1096:604:259::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.12 via Frontend Transport; Mon, 14 Sep 2026 20:37:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 8.62.32.50) smtp.mailfrom=renesas.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=renesas.com; Received-SPF: Pass (protection.outlook.com: domain of renesas.com designates 8.62.32.50 as permitted sender) receiver=protection.outlook.com; client-ip=8.62.32.50; helo=ejcrelay004p.adwin.renesas.com; pr=E Received: from ejcrelay004p.adwin.renesas.com (8.62.32.50) by OS3PEPF0000003D.mail.protection.outlook.com (10.167.240.6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Mon, 14 Sep 2026 20:37:26 +0000 Received: from demon-pc.localdomain (unknown [10.226.93.156]) by ejcrelay004p.adwin.renesas.com (Postfix) with ESMTP id 33D2E3000437; Tue, 15 Sep 2026 05:37:23 +0900 (JST) From: Cosmin Tanislav To: Biju Das , William Breathitt Gray , Lee Jones Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH 04/15] counter: rz-mtu3-cnt: use device-managed pm_runtime_enable() Date: Mon, 14 Sep 2026 23:36:03 +0300 Message-ID: <20260914203614.2035277-5-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS3PEPF0000003D:EE_|OSOPR01MB12185:EE_ X-MS-Office365-Filtering-Correlation-Id: 24c55f2f-c104-41bd-27ba-08df129ffd2f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700016|376014|23010399003|1800799024|10067099003|56012099006|11063799006|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: /RVLbpUkz5Ax+dB4CxTM7wKkCJHen0oLVy/HZxtLwe/DZ6FB9GWSNHh7258NvVYAcFDO5CjdAeEPxAIQhea6P3ohHHxj1A5lwQcVWfzfwCtl8vVdhZGd3/paFXNyte9P55VpwqWTsnRNx9RpAiJoJmmK+Sv4/h02RvHz/kdCh4EyKRRqPlUGkE3/tHNZ6QGiHiBdVmfFye0gyY1ybPWsDaWEQ6ZiEhP5h4RHd7bLdP/Tet2QwnIOnSNKfTheFPQgv/Zq3QDTQcsBGrfXQoYyvC1R2IDFASlc3M+FEk4SGbjLfUTsEZ22QdCQoN/jExNZYmlSyAtlFAe1F54xYdKvotN7ls6lS4eYLmgqHsUGdQxOPNpI9O03nF9IanafnVEfqgScvdjbxDySt8LNaRMmDv9v8eIwM4Oqs60sjspJVjQnC/jLmzuEDN5GayydqYk/zWOici2qAOWPuMWYewYMGbesjNOTHG7tF41R1ovqcyDo+J3CYIZ/8oXkJRtrJTMg7eZBHS+oPCS7+vOxfeggKJcGYEvQFLxlrdA68OoIxmqBlQxlIER4vRk2FuyQxBfcRo6gqJrNp817KJ5+y3rtMb5i7dJGr6qvURGTHQ9F1S4nUh+DvwtCFHEHKjFtMP16zyoJELDEuaoTv3g4RdJ5wTnZNYnGTEoh4ngFNfAwDQHoMPBtvCLPJ01FnZx4qOYbDhwcWjb+mDRh0WF8F5xQbA== X-Forefront-Antispam-Report: CIP:8.62.32.50;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ejcrelay004p.adwin.renesas.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700016)(376014)(23010399003)(1800799024)(10067099003)(56012099006)(11063799006)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: R7nlCo6OBo7lmsDJQPPVsFH6Sh6uc+5WOh8ClR7D+ArCoNY4C53yvQopgkm4/xxhm0AtHI1RqO6qSOhBxQhgthLmPyCeYyySPlY8WTXZ/Mq+SYN+/Kqg5nL7fwYIcMlFPInthddo6MuX9jNOBjXKyhDS52Qo7oQ17UiJfUx6s6Zkbkf4lSct9b3RGNl8yYP6dnLomdTe86aZPmdAVqd0L+sa2y/4SGr1783bcR3H7acMnfeHuRgHlYfBJ1b2tCkfpe6uR9xwu87yMFmtQAqlITR1Foo6Ge84cypA2lpIgidVoxs4NUAWtjsofxFR7RbSkW1Pnq/N5eRk9PxQvV7dHL1ihB6PnE4YgYdQUTF82YBJISBpYc4GgdvguMrUh52r/9GFJec26SsMzcQmYArt7h1rI9mUdd/m4MHP13fIm2I+bn8JNCbNxfSzuiDvwWB+ X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2026 20:37:26.6083 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 24c55f2f-c104-41bd-27ba-08df129ffd2f X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=53d82571-da19-47e4-9cb4-625a166a4a2a;Ip=[8.62.32.50];Helo=[ejcrelay004p.adwin.renesas.com] X-MS-Exchange-CrossTenant-AuthSource: OS3PEPF0000003D.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: OSOPR01MB12185 Content-Type: text/plain; charset="utf-8" devm_pm_runtime_enable() has the same semantics as the current logic, use it. Signed-off-by: Cosmin Tanislav --- drivers/counter/rz-mtu3-cnt.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index 6c171a741cc3..b99dd67703df 100644 --- a/drivers/counter/rz-mtu3-cnt.c +++ b/drivers/counter/rz-mtu3-cnt.c @@ -807,13 +807,6 @@ static struct counter_comp rz_mtu3_device_ext[] =3D { rz_mtu3_ext_input_phase_clock_select_enum), }; =20 -static void rz_mtu3_cnt_pm_disable(void *data) -{ - struct device *dev =3D data; - - pm_runtime_disable(dev); -} - static int rz_mtu3_cnt_probe(struct platform_device *pdev) { struct rz_mtu3 *ddata =3D dev_get_drvdata(pdev->dev.parent); @@ -834,9 +827,9 @@ static int rz_mtu3_cnt_probe(struct platform_device *pd= ev) priv->mtu_16bit_max[i] =3D U16_MAX; =20 mutex_init(&priv->lock); - pm_runtime_enable(&pdev->dev); - ret =3D devm_add_action_or_reset(&pdev->dev, rz_mtu3_cnt_pm_disable, dev); - if (ret < 0) + + ret =3D devm_pm_runtime_enable(dev); + if (ret) return ret; =20 counter->name =3D dev_name(dev); --=20 2.55.0 From nobody Fri Sep 25 09:22:49 2026 Received: from OS0P286CU010.outbound.protection.outlook.com (mail-japanwestazon11011048.outbound.protection.outlook.com [40.107.74.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BB6E3A1CEA; Mon, 14 Sep 2026 20:37:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.74.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418263; cv=fail; b=T+7aJ36fII/VfSCEOGQbq4hz0KnB7WBRgrmE4USYa/YJV2TTS/J0LSU/09uKyFj+rfcU1pkwqMDNkdHhhtcad7eat8IHwiHD5176IDL0XNk6atHVyhQ/J5EewQG1zrZq2Hhvsxnwvge1ZpgFzmkNf6wPt+6owRhKRuHcqH/Mwys= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418263; c=relaxed/simple; bh=dlJ/mExUJj4LM9bvLDELRiwn3YXhkz2Cjrnz6G/Xs+c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=up/9j3r6CjZGJbbXsn7sv+yqluRfNL/5t5Y9/o8ENbJp1cFr8V6zJGRMdAFebujQLC0tdI/qGeWGQzDw8d93Qc3k4K8EebFqGSK+5Z4lVAlaudEDbqaeNUGbDlWMA7sWx6zJEst3nWULGqaF0hFP6ZPDqUjYFQ717K48GVvkuWs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=Qtf0D8W0; arc=fail smtp.client-ip=40.107.74.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="Qtf0D8W0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SLNszU1wA1tp85bJqDbXzHPiOlmSckyWWqm51aHe1WUdGFEMX0vuspnqcnnvoH6JWFhETBgAX39Oh/TyU1EcRU3lRkJZJ4ZM83P1e9hUsTGW6cCU8JzHS9RU4DIlLfVbY1jsg/6dLL3H9jhClaMribghR+g4PDetGR+vua4A/lRftfm0tL4ywXg/1OS0K4H2dIDt3osFZWVn07SKmXlU5neKiVZHN4KPdKBYpPp7aRMGi4qR6Xtw8ZVhCPYICRHbf2PCU1kxSzwtmOtskmlYbLzFkJQknXZMpF6z1SIW+uQQKpuXLWe9h9BKxXDgc8k+IlA/46q8Tv8qmrkJWUYOiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=kPrZplhIVevFmiVTHq6dGBV6/XXyPf2//UpBtOElU8E=; b=zNtH2bAxStoMHvf3aSWCA81lLYFodCMSn4qmKpOjK6TNvS6yujLnr1OxBNfI0PY0mX9sooJ3Wl3agBfsAw8OY1MiGaNg86qcYzfJoHx0ICjCktWz7u/WDj67BwjeGu8wf8x2XtBIPrrhBf1ydflHcvxWz/9zew5OY7QFqyUBh8JvLZyTMfjPGSuEQsWnMUxdBGg4rlTzo2eV0HmyycrTP5Mdek7T8hlPPH/3GyTpexDYddZ9PfXkHbhIYRDqbLBcx7AINjJs0AuL7SDweiEf0QCLBOv4ZCYDMXtCKivyA827jOUN4sKnram2RMT02obFd+q9ImqBwrnZf+La2v53og== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 8.62.32.50) smtp.rcpttodomain=bp.renesas.com smtp.mailfrom=renesas.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=renesas.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kPrZplhIVevFmiVTHq6dGBV6/XXyPf2//UpBtOElU8E=; b=Qtf0D8W0LolqLtjB+eNzp2/bKtIK0xyqdSRlP6A2ps4/gqy/jlvsuAQ86hxHs/0AGmTh1dbkuV0E9PioElBP1A6Fxwmonq57o8E6tkPOVu9S7yFdYeJSpAuzW3sIJMPQdw0k4K6hKRYQAFHNg5cj2cofepoH2z62U+bZPDRpoZ0= Received: from OS7PR01CA0274.jpnprd01.prod.outlook.com (2603:1096:604:259::18) by TYWPR01MB10259.jpnprd01.prod.outlook.com (2603:1096:400:1d4::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Mon, 14 Sep 2026 20:37:36 +0000 Received: from OS3PEPF0000003D.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:259:cafe::a7) by OS7PR01CA0274.outlook.office365.com (2603:1096:604:259::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.12 via Frontend Transport; Mon, 14 Sep 2026 20:37:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 8.62.32.50) smtp.mailfrom=renesas.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=renesas.com; Received-SPF: Pass (protection.outlook.com: domain of renesas.com designates 8.62.32.50 as permitted sender) receiver=protection.outlook.com; client-ip=8.62.32.50; helo=ejcrelay004p.adwin.renesas.com; pr=E Received: from ejcrelay004p.adwin.renesas.com (8.62.32.50) by OS3PEPF0000003D.mail.protection.outlook.com (10.167.240.6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Mon, 14 Sep 2026 20:37:36 +0000 Received: from demon-pc.localdomain (unknown [10.226.93.156]) by ejcrelay004p.adwin.renesas.com (Postfix) with ESMTP id 0B70F3000368; Tue, 15 Sep 2026 05:37:33 +0900 (JST) From: Cosmin Tanislav To: Biju Das , William Breathitt Gray , Lee Jones Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH 05/15] counter: rz-mtu3-cnt: read enable value from cache Date: Mon, 14 Sep 2026 23:36:04 +0300 Message-ID: <20260914203614.2035277-6-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS3PEPF0000003D:EE_|TYWPR01MB10259:EE_ X-MS-Office365-Filtering-Correlation-Id: 225a665d-64f7-41c6-4b72-08df12a0031d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|23010399003|376014|36860700016|10067099003|18002099003|22082099003|56012099006|11063799006; X-Microsoft-Antispam-Message-Info: rW19W/hqvfnPIJsRaKx+3deTjuPtochGkQZSaA6VQ9Xpifx244d8iS4/Fyti7YHkUCzvzaJkBLbG80f2QfDunaEuY9AkpxvzAfbVEqxMh9rikIkl36pwcUqv4o1BFFmBFJP0U45QQLmrQtgINJBGkKuHoo3W/h6ayhZTB3YI46lhMr5HFEjZxhKmEi+gcoLdB9C41qlA+sUtGGBcDTGEmXUFPtitFIlKW+o/vPyvTxnMSitm5rKytrqyg/ro96nMWdSaIQRsmIT4zx2bJjMdarzs6X7gCoQBoiwUU7V1vFc0A1ZksH+5UPmd6IIL1/1jhArroQhp6KJ7L9Vl8FOwCkLkxuuieWpsR/gqml6xwn1PKhHVmS61z5WEirpZlnIQa4LAHeD3u4nFmAeN3QBz/8JvoWmEIpRxLvqEa0RcerA/75zqDqE3o7TiCrdpmU05Yb8W9jHm74N3b0kO6TL3GS7VEeJEi5w2KmT7rpAk51qktjnFsoG+5j3cL3apUpb4uplEC+v8EnKp158X97BTQsJn6HAfK7Iq11yOIkguijuKo0qVSEUtDOffi/QL7zWLQV2J8dgJYMHlH82lRjvm8dhfhSPlPfQzmocLtv54KT3uVNAFeRUij/FhhYtuMasY1vnsN8uuiBOsqjXp33t8ykD81kksLJMLI1UmsIlF5+0uGRZ+PXyxzv+iO6J+wjnFf77ZcpIwLhzQee40BieM3Q== X-Forefront-Antispam-Report: CIP:8.62.32.50;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ejcrelay004p.adwin.renesas.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(23010399003)(376014)(36860700016)(10067099003)(18002099003)(22082099003)(56012099006)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9thXiCyw2nTUWY3WV3KIO8FOFFzIeOtGoBLvC/JnOxO0++OJwllfhWBgeTz/4bS3kXeFL14AkP5d5pus9yaVCas7CODuRPHY40huD2JSYq/SmQAbeP/GkTZeuDV/NU/rXzBARcbd3XeOpPIlF3xUkLKLr0gHGJXdVAvH8WUOgZnnzBcmKSmFiZuXHkGS4lVXJWuQ8z4pYM34TH4qijy8+cE95OqCX8U8xxFg6Z+N2PWyx0qyIqegTvXfpHc2EEOdmGK5+Jvph2ORy8sGBdVScKad++vCUvS96BBu/h8OMNx42RKtpr0Xc6IzSmAD1iIv8VEaMiKVIds14zfvelR774FHlfXtUvNhOVJA/ObyN2qmFOQu9W9JPt259N2dpFcTdHsNtQEbkx2cbmuryOFM004UdROXblN6gKT6HK31EvrzHjUARiLRRoNfl5YPy5Qh X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2026 20:37:36.5594 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 225a665d-64f7-41c6-4b72-08df12a0031d X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=53d82571-da19-47e4-9cb4-625a166a4a2a;Ip=[8.62.32.50];Helo=[ejcrelay004p.adwin.renesas.com] X-MS-Exchange-CrossTenant-AuthSource: OS3PEPF0000003D.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYWPR01MB10259 Content-Type: text/plain; charset="utf-8" Reading the enable value when PWM is in use returns -EINVAL because of the checks inside rz_mtu3_lock_if_count_is_enabled(). Reading the enable value should not be an issue even if PWM on that specific MTU channel is enabled. There is no need to check whether the underlying MTU3 channel is enabled when determining whether a count is enabled, as we have a local count_is_enabled array containing exactly that information, which cannot be wrong. Use the information in the local count_is_enabled array and allow reading it even if PWM is in use. Signed-off-by: Cosmin Tanislav --- drivers/counter/rz-mtu3-cnt.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index b99dd67703df..d3daf258a3b8 100644 --- a/drivers/counter/rz-mtu3-cnt.c +++ b/drivers/counter/rz-mtu3-cnt.c @@ -471,21 +471,10 @@ static void rz_mtu3_terminate_counter(struct counter_= device *counter, int id) static int rz_mtu3_count_enable_read(struct counter_device *counter, struct counter_count *count, u8 *enable) { - struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, count->id); - struct rz_mtu3_channel *const ch1 =3D rz_mtu3_get_ch(counter, 0); - struct rz_mtu3_channel *const ch2 =3D rz_mtu3_get_ch(counter, 1); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); - int ret; - - ret =3D rz_mtu3_lock_if_count_is_enabled(ch, priv, count->id); - if (ret) - return ret; - - if (count->id =3D=3D RZ_MTU3_32_BIT_CH) - *enable =3D rz_mtu3_is_enabled(ch1) && rz_mtu3_is_enabled(ch2); - else - *enable =3D rz_mtu3_is_enabled(ch); =20 + mutex_lock(&priv->lock); + *enable =3D priv->count_is_enabled[count->id]; mutex_unlock(&priv->lock); =20 return 0; --=20 2.55.0 From nobody Fri Sep 25 09:22:49 2026 Received: from OS0P286CU010.outbound.protection.outlook.com (mail-japanwestazon11011019.outbound.protection.outlook.com [40.107.74.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5C5E49EC79; Mon, 14 Sep 2026 20:37:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.74.19 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418265; cv=fail; b=KsKkVodHJbqHUInqeUJWB7QJFX3rzz0ozP65dh/bq50xkx7L1bFqoI25YsvXhHB92nPyIfDAivjBszEpuP+OMLZJxIWjNOCkAIPUhdO/Pkzj7WpLl2yQOZHVFefPBQVsn9GOzFa4gO+/+724oSvqkQLwjgLHRfWb6sZ10H5fR3o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418265; c=relaxed/simple; bh=OOwOwl6QQF/qFCpvlGXN8G/hxkpA2HZW67uEdphKlNU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Rq0mq3hW2Rg7wf88+OqSqiy3bBLgIVtCcn/J+yDGMb4CO+zf99RPDwcW9mwOFFIBltKwcrj5Q/g8GkD1zEXMKApwQWIptev9Lv2Otavm/HAXHnXCcAliJvoTjqto+tTvn5ABCGFLhcLmX8R2NyleAY1kyPdVG3MHdIj0/1bAVsQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=WoTce4ys; arc=fail smtp.client-ip=40.107.74.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="WoTce4ys" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=K4lYk6usb1hv6BQVxrjxGcVVuFa1dk4FUG9lrIJ/WfRWWyEr4uODlJnqhxd0TFp8Ca6e6ibH0s2RXXO8VE+rYxBbKQkGcM/i9Rrbbd+tqxANkY/HqeqcTevDdvMkJur8JMRvc+2Rbx3x8VC28MVD7qmSMpixLVtLlD/lIGlVR30X0Sxl0Ce22kBbjT1NiQHCO3DeDK/R1VWNqvBGEc6dC+Qppp9is4gH8m+xaVjFmebdRoY5RVwJTknBJQG+KTwMQpw+YHCFUZKLvt2DdXmbynJW0tVpfqIul/kAmBrOkXvXrEBQAfbKMJYusonEOZSvMDL73hqGC3xWuieDF/bnsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=hnVScNJPNbtGO4dm6G0+S7f31DLrAYpcVtVdXeMbXcE=; b=XRNV2J6haFa7rkU0tvNVB8qqFcZ/AB5y2SDSPKdzeyOwayfabL/XA7RDnfy0eie8HSwCMq4eG5nIfkmiYl4r7Cko+qJ2KddtySxFcQqeSqcTnzJD6ermVrfrTSFu51VQKoPF6T4YNma5eRoDJMHsey+KYbO5M5P5EGKRY/lD7S8q/aW/H3dufjVv9j5yIQ228L58Ukfhkjg4fTwz/GPPRgJYb3RFBjxSy7fd+ft+Nv8K2h2VAZ/edaJ5WlTqZqffhi3m2wJzyIp3mGALATH79uYOs6lV8o8XA/GIR/0GuzaxNS2Ocfg0BpUqjI6PA9qKY3ge4BqHn6LPCz6/Vmo9Ig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 8.62.32.50) smtp.rcpttodomain=bp.renesas.com smtp.mailfrom=renesas.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=renesas.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hnVScNJPNbtGO4dm6G0+S7f31DLrAYpcVtVdXeMbXcE=; b=WoTce4yseN5JdOa62OLmuRTB3Cgeekk0eADTly3KYsV6IFCeEeDHf1DJvhpTt6v+A9nEwk8p/8aGYssy7XL6lVHfwEbV6A75XQWPeJCOY1ZM11IruGSuGD0pHlDNAKTl7DIeZOHiE1iaaCKAEFzulubi3VliRnYWnCQS0n61WFQ= Received: from TY4P286CA0117.JPNP286.PROD.OUTLOOK.COM (2603:1096:405:37c::17) by TYRPR01MB13769.jpnprd01.prod.outlook.com (2603:1096:405:219::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Mon, 14 Sep 2026 20:37:40 +0000 Received: from TY2PEPF00005623.JPNP286.PROD.OUTLOOK.COM (2603:1096:405:37c:cafe::5f) by TY4P286CA0117.outlook.office365.com (2603:1096:405:37c::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.12 via Frontend Transport; Mon, 14 Sep 2026 20:37:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 8.62.32.50) smtp.mailfrom=renesas.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=renesas.com; Received-SPF: Pass (protection.outlook.com: domain of renesas.com designates 8.62.32.50 as permitted sender) receiver=protection.outlook.com; client-ip=8.62.32.50; helo=ejcrelay004p.adwin.renesas.com; pr=E Received: from ejcrelay004p.adwin.renesas.com (8.62.32.50) by TY2PEPF00005623.mail.protection.outlook.com (10.167.240.54) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Mon, 14 Sep 2026 20:37:40 +0000 Received: from demon-pc.localdomain (unknown [10.226.93.156]) by ejcrelay004p.adwin.renesas.com (Postfix) with ESMTP id 98EDF3000437; Tue, 15 Sep 2026 05:37:37 +0900 (JST) From: Cosmin Tanislav To: Biju Das , William Breathitt Gray , Lee Jones Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH 06/15] counter: rz-mtu3-cnt: disable channel before releasing Date: Mon, 14 Sep 2026 23:36:05 +0300 Message-ID: <20260914203614.2035277-7-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TY2PEPF00005623:EE_|TYRPR01MB13769:EE_ X-MS-Office365-Filtering-Correlation-Id: 612ec0e0-dd2f-4582-3722-08df12a00540 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700016|376014|23010399003|1800799024|10067099003|56012099006|11063799006|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: vz9/KLegaA1Ke3WqO953PPx70wUJFD+CsSAldLuVsmput2UgUvN6zWKVXs6t9ozA0Kk7cvXeBWuhE0ZYzkrChbIzvuU/hD+5jPvdhbqFPfJnLuMyK9APKLA/GxZY+d7c5RpcfnZ4ATMvNBRHS674u9EzmzWRqGPv4nQVk4e3Z/Q7XByAOMNI3gMQTkfY9SbDcXInO67CJT3ERup/Mh14UQuna8uiSqwOA9qgjfggP8/fv7UwVMyeF8PrF3EcYAqcZOLTBdwkYQPPzBC77Xnanpo/P4BKnrCvxPRrekwx0WM2iINUlgTtyTxVAhmq1ix5GWJ6GLgpFJRilAoU1YMzm2v7O5+djGe/QU8bDO8Iqc8SHEDW4ZN6vPzYInVfzb7o4o7PUL08TaBDY/5ZsZ6oA7pNlC5MjbMFMpVLhlSpF/ZxnXq9eSRy8RCJrZRpdAvq9po+53/HZYEx3am9Glu4+dwIg3yphLOtp3WlWCYSI0PVwjL0RKiwPQ1vmmiOxKSD1cuhQq0ue5ZbLdyHaZ8iZJAZ4IBofWnI6XT66F57S4VOhQ/KPfHRjqGFIlEzM2/Z2iRKvaIbS+dP45bBufMr8lCIRFLuuhQkQ6P/TNZgcurkxONcnDhleURpjm16MiWE+8Tp6hkKJVfjzilAWhDUpZmP7i1bHwvJ2dz9kPWuGXiL1vLujKbzVw6ZU2eLdkr4+hex9uYQHzuwUtFQ6P4G6A== X-Forefront-Antispam-Report: CIP:8.62.32.50;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ejcrelay004p.adwin.renesas.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700016)(376014)(23010399003)(1800799024)(10067099003)(56012099006)(11063799006)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2l9GBfTVkyTZeTZZ5jbRcKw60lPVRYGbi2B7FwtmQ88hWMzvrEpEowOjXOFbdp7OG+mmAlsIzBjSnPiWL11OnO9xQBDQm//2Yf4JjOHdezV+oKWZlgVsv521rN8WKn7Y3zezSr75h7pOhPZRe/RhKayM7zIj8vhL5Mc0Ku7ph2eCOdc2KuX5WnEUazP85kSu2KPqF4caXWnQx/ayqDmKB4l3oS9wlsMwNo5MyyR51ehwejURcAcku8tk2l3j6Xz0B0c9elb7Ggl09MR4e52pCwx16jchevTooOk2IXVYcw1MQRYM9g5xcZZpimDtFN9AzMF2+v0QX0uWbI9yUZtN4wMAI7+leXp3864hQjckl7mT4YsesbKSGP4f9tLFE5HaxMo1Aj8zlEFP5OTKBXg7or3ORzEZ6GyqqmCo4oJ/6C7Mm2kiewVQ9S7lUW4v46af X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2026 20:37:40.1570 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 612ec0e0-dd2f-4582-3722-08df12a00540 X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=53d82571-da19-47e4-9cb4-625a166a4a2a;Ip=[8.62.32.50];Helo=[ejcrelay004p.adwin.renesas.com] X-MS-Exchange-CrossTenant-AuthSource: TY2PEPF00005623.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYRPR01MB13769 Content-Type: text/plain; charset="utf-8" Releasing a channel marks it as not busy, allowing other threads to claim it. With the current logic, it is possible for another thread to claim the channel before disable is called, since we release the channel before we disable it, causing the channel to possibly remain disabled while it should have been enabled. Disable the channel before releasing it. Fixes: 0be8907359df ("counter: Add Renesas RZ/G2L MTU3a counter driver") Signed-off-by: Cosmin Tanislav --- drivers/counter/rz-mtu3-cnt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index d3daf258a3b8..e200a6548dfe 100644 --- a/drivers/counter/rz-mtu3-cnt.c +++ b/drivers/counter/rz-mtu3-cnt.c @@ -458,13 +458,13 @@ static void rz_mtu3_terminate_counter(struct counter_= device *counter, int id) struct rz_mtu3_channel *const ch2 =3D rz_mtu3_get_ch(counter, 1); =20 if (id =3D=3D RZ_MTU3_32_BIT_CH) { - rz_mtu3_release_channel(ch2); - rz_mtu3_release_channel(ch1); rz_mtu3_disable(ch2); rz_mtu3_disable(ch1); + rz_mtu3_release_channel(ch2); + rz_mtu3_release_channel(ch1); } else { - rz_mtu3_release_channel(ch); rz_mtu3_disable(ch); + rz_mtu3_release_channel(ch); } } =20 --=20 2.55.0 From nobody Fri Sep 25 09:22:49 2026 Received: from OS0P286CU010.outbound.protection.outlook.com (mail-japanwestazon11011049.outbound.protection.outlook.com [40.107.74.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 519EB4A0130; Mon, 14 Sep 2026 20:37:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.74.49 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418268; cv=fail; b=Mn6qGtffKneQ3Tyj7yNKpDb8WCaBW5aTVIWsd9vK88NADCDXSeqZa3JU98q3K5vTCU/GdNFItFJUo2cL916IopFoqQR3/9LM9WlSFzX9YLqthPz22Vqt6A3xgt1Qg3I8KzGQOHgLHX1zeigMr7ct9T6DS758O6XP4ilbQc6g0ng= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418268; c=relaxed/simple; bh=DLBB8sLQXuqNjFqbIHFyfPckVop8RoOTUhfMT1wnmVo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FTFhKyIKaoXWBYVx4SHm8f3kYysLqAhF7mDHc4GUMMGSdUub0mwePljLwwODU0V35x3TMkkd8eSTvF5pAGim1KjLplVcx4oG0qxYRmk4NjDtaIaqSNatAGVdjOo0/Fe+szF9x88tscokh5RUYz59vvw7XvcJVyS4NVKpJOK0Wkw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=JuSngejo; arc=fail smtp.client-ip=40.107.74.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="JuSngejo" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KrHD/IuBDdE0Vpyo1Kel27Jeh3RLrJCpVZ1zD36HOE2/1fHepLL76VISap8mhrSd54nmDeRN5eY7J2exbmF8gXbu8A9t4bMPO5jiyfF0wvOzQ4/x7x2nxxd3YuD6DCW98moV/ftmCg84szfceMQCpsFhqHaasMLK+CoGVjn0HTbdAPAwbtRiOOrmLLFmY42dC8MmRaWrUrvDv0EUp/ycOawmcyw32GXSE5JnONYOTgMPZ9vF0nJzALW0vLP9I5ku20npAeXOXwiXARbViLrRoXFmqQ4LkDnvirApC26ag5bQgYJ6AU0fmNNrzRoFuo645Iui05q+DiXX87tHui/7zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=l7wTed163jXea4r0UCgqkOu+cX8+FUV7CGy/W2MRTzU=; b=NVK2A8a9vX3TdDKofTSb9pvdkJIq+01eE51n6zFW1m8f4tfL1OGiOkbBnfrzAR+Ng97kYREDiXidoz7GkbbrfwLOzdwzr3sVm5nHiblSSHJa2a7LqeGQUjPOA8JaBEwPy+YtW3rj2I5BxcuyPhKSroFDj40xCgnDSfxPpr6YHKTHnI4MOvRUCXp8zqjFuONxRVskMZlg8i45LDwEB6JiNlM4quCzjSZFZpvlwxGVPgjDWbMdw4zj14E0FHvlABgyX4btkmswwRd4ocByBhMRwDSSqUa+BOC0ctwhqa+/BwnrCF37o9g52kyIgReQ0dYvOXkpyhVcf85Hr42C+EP61w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 8.62.32.50) smtp.rcpttodomain=bp.renesas.com smtp.mailfrom=renesas.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=renesas.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=l7wTed163jXea4r0UCgqkOu+cX8+FUV7CGy/W2MRTzU=; b=JuSngejooi+GgafGPjwp0qHO/qm0Wi8BvhqokqodLAWGwVWQSZptX6AZKMeoYmM8D4vjjF3yelSbdtNegVYMcR/dwsvWaVtfVecpj7yUViKiM09obfm9Yn2mNXMNiZY/+Ph9VGDknrP8ILYHTz2GCdi40n7YM7W+1QaQh4NNqvc= Received: from TY4P301CA0060.JPNP301.PROD.OUTLOOK.COM (2603:1096:405:36a::10) by OS7PR01MB18397.jpnprd01.prod.outlook.com (2603:1096:604:4be::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Mon, 14 Sep 2026 20:37:44 +0000 Received: from TYO1EPF00005024.JPNP286.PROD.OUTLOOK.COM (2603:1096:405:36a:cafe::a2) by TY4P301CA0060.outlook.office365.com (2603:1096:405:36a::10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.13 via Frontend Transport; Mon, 14 Sep 2026 20:37:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 8.62.32.50) smtp.mailfrom=renesas.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=renesas.com; Received-SPF: Pass (protection.outlook.com: domain of renesas.com designates 8.62.32.50 as permitted sender) receiver=protection.outlook.com; client-ip=8.62.32.50; helo=ejcrelay004p.adwin.renesas.com; pr=E Received: from ejcrelay004p.adwin.renesas.com (8.62.32.50) by TYO1EPF00005024.mail.protection.outlook.com (10.167.240.21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Mon, 14 Sep 2026 20:37:44 +0000 Received: from demon-pc.localdomain (unknown [10.226.93.156]) by ejcrelay004p.adwin.renesas.com (Postfix) with ESMTP id 0CC1D3000368; Tue, 15 Sep 2026 05:37:40 +0900 (JST) From: Cosmin Tanislav To: Biju Das , William Breathitt Gray , Lee Jones Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH 07/15] counter: rz-mtu3-cnt: unify ceiling values Date: Mon, 14 Sep 2026 23:36:06 +0300 Message-ID: <20260914203614.2035277-8-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYO1EPF00005024:EE_|OS7PR01MB18397:EE_ X-MS-Office365-Filtering-Correlation-Id: 510ef4c0-b326-415d-2648-08df12a0079f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|376014|23010399003|82310400026|1800799024|6133799003|10067099003|56012099006|11063799006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: rPaxIXcLhpSpxKMYOLycg+GQ0GqA0AxaIoiszXhWN08IS5mUVhhI6qPfilsQEuCf4L62OkAsr5uaP8zLuIMN0wX8Wqh1UD71g9/3zqZEpnzO4KyIfeL+ragRbWyhuLFiCAl9Jvp2CYwlO0TAzVZhoOHxvad0mUkAGdWCuc4a6zHqMKq9EA3+vuDmLwikfrPKl14rz8Hz/Ov7/3g4uGYMeONWv1x8t79JJkc5MA6w9WQYItg91INAWilosT4hEVqWdRxIQqIatlpDXPx0xgiheyEygqkUrsM7x0OND2b3wOrruJYuNVm6b78k/CqHq286i8wrX5+N6Fsh2+WDhGh9/nAIBxdg8DjG04V/g+zhMYrZBrs9LE32xLJkaEcR+N7gylc3NefiAUGjIoLEwFgTIu83HFQZt4cDfRnH6WVzKZejIWcVJ4oDYyTROBqPV54BDsd3zIsJw2vIVToWDQbI2SwJ1/6jRrJ5q4cc1nsLKO8Xm2eIFWmxR/YsEwCunPUsWp1Izw4H0OhkO2M6eDyxD4GGEpDvtEbWZ4YmJ+O5GVqndj0OOiXL0NxXXDi38MFOhOrVP0nyqMbT055F2/Tnim9Fvfgl1Lx/veZ2z94jEafKK20waoG3tva2QYuSP9KCiakQyyjBYhHUBlowHzA4CzQyTxiox8jXnSJv5wrKupaGE5nJiLQ7y9kufqtuErmd0Za6xRst28s9CAOSYZrYpA== X-Forefront-Antispam-Report: CIP:8.62.32.50;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ejcrelay004p.adwin.renesas.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(376014)(23010399003)(82310400026)(1800799024)(6133799003)(10067099003)(56012099006)(11063799006)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: n0b1lIjKqVlssC44k6lFkAMqnsrcHugVTZvqHvXJYaeyVl5Q7aoeo9G+297Xuh0CCMCC8sW5+7spwo3dedkz3ygHZQO6osMFcDBsCXhPJQTQdx0jAmBTt9bcf8fPmYvUaxGNDElIXSvPpBEt6VtZuVa8Ynzpcf5xEgDkzmmTV7lVvPnHzA9c3xjsKyiQAYPwp1Z2CI7+nCN4b9VcvFgN/BfdgCv3MYzoWjR8ObHupr1Py0ICgCN2gdMgE5CZFuq/ss7tIVZQxKUWuq36IRoi72BYDMfiFmc0x9gF/CghNflQoeyuSI6z3kKbet1c7ig0BLyAeKFWtf1RktZ/vSipnfVoVsL3gaIRTMpbg7FrIfW7rQv9OhKqjcBFK1ErOkW0k0jROOqOvrAiJNGSPWS0INCu//MHwUU0l3op7AnNe7Xtzse3DuxCuvplwH5um6Fk X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2026 20:37:44.1326 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 510ef4c0-b326-415d-2648-08df12a0079f X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=53d82571-da19-47e4-9cb4-625a166a4a2a;Ip=[8.62.32.50];Helo=[ejcrelay004p.adwin.renesas.com] X-MS-Exchange-CrossTenant-AuthSource: TYO1EPF00005024.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS7PR01MB18397 Content-Type: text/plain; charset="utf-8" Writing to the 32-bit ceiling value clobbers the 16-bit ceiling values as both are stored in a union. This was probably done to save a few bytes of memory, but that memory is then wasted on code to handle the two separate variables. Move them out of the union and use a single u32 array to hold ceiling values for all channels to simplify the code. Signed-off-by: Cosmin Tanislav --- drivers/counter/rz-mtu3-cnt.c | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index e200a6548dfe..f9bdfaf7bd42 100644 --- a/drivers/counter/rz-mtu3-cnt.c +++ b/drivers/counter/rz-mtu3-cnt.c @@ -75,11 +75,8 @@ struct rz_mtu3_cnt { struct mutex lock; struct rz_mtu3_channel *ch; + u32 ceiling[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; bool count_is_enabled[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; - union { - u16 mtu_16bit_max[RZ_MTU3_MAX_HW_CNTR_CHANNELS]; - u32 mtu_32bit_max; - }; }; =20 static const enum counter_function rz_mtu3_count_functions[] =3D { @@ -316,27 +313,13 @@ static int rz_mtu3_count_ceiling_read(struct counter_= device *counter, { struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, count->id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); - const size_t ch_id =3D rz_mtu3_get_hw_ch(count->id); int ret; =20 ret =3D rz_mtu3_lock_if_counter_is_valid(counter, ch, priv, count->id); if (ret) return ret; =20 - switch (count->id) { - case RZ_MTU3_16_BIT_MTU1_CH: - case RZ_MTU3_16_BIT_MTU2_CH: - *ceiling =3D priv->mtu_16bit_max[ch_id]; - break; - case RZ_MTU3_32_BIT_CH: - *ceiling =3D priv->mtu_32bit_max; - break; - default: - /* should never reach this path */ - mutex_unlock(&priv->lock); - return -EINVAL; - } - + *ceiling =3D priv->ceiling[count->id]; mutex_unlock(&priv->lock); return 0; } @@ -347,7 +330,6 @@ static int rz_mtu3_count_ceiling_write(struct counter_d= evice *counter, { struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, count->id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); - const size_t ch_id =3D rz_mtu3_get_hw_ch(count->id); int ret; =20 ret =3D rz_mtu3_lock_if_counter_is_valid(counter, ch, priv, count->id); @@ -361,14 +343,12 @@ static int rz_mtu3_count_ceiling_write(struct counter= _device *counter, mutex_unlock(&priv->lock); return -ERANGE; } - priv->mtu_16bit_max[ch_id] =3D ceiling; break; case RZ_MTU3_32_BIT_CH: if (ceiling > U32_MAX) { mutex_unlock(&priv->lock); return -ERANGE; } - priv->mtu_32bit_max =3D ceiling; break; default: /* should never reach this path */ @@ -383,6 +363,7 @@ static int rz_mtu3_count_ceiling_write(struct counter_d= evice *counter, rz_mtu3_16bit_ch_write(ch, RZ_MTU3_TGRA, ceiling); =20 rz_mtu3_8bit_ch_write(ch, RZ_MTU3_TCR, RZ_MTU3_TCR_CCLR_TGRA); + priv->ceiling[count->id] =3D ceiling; pm_runtime_put(counter->parent); mutex_unlock(&priv->lock); =20 @@ -802,7 +783,6 @@ static int rz_mtu3_cnt_probe(struct platform_device *pd= ev) struct device *dev =3D &pdev->dev; struct counter_device *counter; struct rz_mtu3_cnt *priv; - unsigned int i; int ret; =20 counter =3D devm_counter_alloc(dev, sizeof(*priv)); @@ -810,10 +790,10 @@ static int rz_mtu3_cnt_probe(struct platform_device *= pdev) return -ENOMEM; =20 priv =3D counter_priv(counter); - priv->mtu_32bit_max =3D U32_MAX; + priv->ceiling[RZ_MTU3_16_BIT_MTU1_CH] =3D U16_MAX; + priv->ceiling[RZ_MTU3_16_BIT_MTU2_CH] =3D U16_MAX; + priv->ceiling[RZ_MTU3_32_BIT_CH] =3D U32_MAX; priv->ch =3D &ddata->channels[RZ_MTU3_CHAN_1]; - for (i =3D 0; i < RZ_MTU3_MAX_HW_CNTR_CHANNELS; i++) - priv->mtu_16bit_max[i] =3D U16_MAX; =20 mutex_init(&priv->lock); =20 --=20 2.55.0 From nobody Fri Sep 25 09:22:49 2026 Received: from OS0P286CU011.outbound.protection.outlook.com (mail-japanwestazon11010054.outbound.protection.outlook.com [52.101.228.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DD164A0138; Mon, 14 Sep 2026 20:37:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.228.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418281; cv=fail; b=sHzYnn9b+G+sVoir/1gyAWuXeA3D6A7tD4IiFEWe8ZGAQKE0yllgnpN52c/4HfmBlpQknlz2CLGHvyGv5ez/6B8BQSffP5umzZaAPmKwONcdROX3DBINAcV/IKppaT/vQZnYVUyuG/xbVgvVOJTGnCEgm7kPTafMU7p5veoZNSU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418281; c=relaxed/simple; bh=5hi8CkfOJr/VGqk7a0Ynj+lqJH5d5+j3Do+JwYXpmSU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QzctZpBDM+NC0g+zlFM1d8cZjrmDa1xqcJPPUeVN1NbDSaWR0Tqe/QLlHZO7RthnaZin0cRpWpnDOnIMQjeDOQdeWsgsq0cUKTUjHQsi5649TsQMBidzNCHrboxN9FpftEibdAxakkq6cmDIl+9elrUNjtRgxbBmZsFKF9DpRmw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=jCxft2oL; arc=fail smtp.client-ip=52.101.228.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="jCxft2oL" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fXFwlANCAr3Pw4DLVQQNIcIWkc9pQLLDSIpiej0vrdPFBQUf/+amQmeGUwcA96cTKs9g6wFM8+MkKUKaWK2wJ4NP+XEM5TsJuDHH/NppK28ehZr2JGRdCSXZT3k7D++79n7pIQPa8j7ISzFMnGtZAA/ViiIVckIiwLFE0eVDC7YG5q6VrWSD9YCMG0YN2Fq0P0npRgy/HHrrbMWwuINSme619vrcsvgDz65nJ5PCfhpu9+dVYuzXxuFm8nndq9Ui0qrNRg2oTU9sod93E4FWFann+XklQOYFVygCRlkGwJg0/CLh723PHtrnx1p6FOQrMylOmEIHD4RxFykAzD/jPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=XoUOCwiJcToWV6RKqAwDia+2vrctF/v+XnHK0UXLf0U=; b=s3tcSdXapUXJfx6K/2kCiMc2B6wU+GkGyq1C5vgBaH6A5uLOZWFWOfTHMu8pAH7h8YQV/9BOeqAm1IRNM6Rk7sX2pqT1YO4U2a7HlOlyeGvRFLOGDw8q6YEoDvw3ECgweeFRvYVyrMKkVtYpX60rcdIXYnjCaC5mwS5WvMhOzACejX9O4xR8i8YFotKGqDG1f7zfhLrVbomYKsIxTp0SynoWufMNBCtdCpOr0RDTZoVgJFateWbf1p81mv07n8LQd/da/Zpq3Vss6yKEntrvVmh3iYW4yy4PJJLTXDKgqJb644vk2Jq3HlKEN+80roTo72fAURWJ4cOGRg0TLVDrMw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 8.62.32.50) smtp.rcpttodomain=bp.renesas.com smtp.mailfrom=renesas.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=renesas.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XoUOCwiJcToWV6RKqAwDia+2vrctF/v+XnHK0UXLf0U=; b=jCxft2oLqDo+upNHoS1XtSPxDhdjLjF3P2wcx/iUw46mUAquu6P+W7JEtJTVNF+BnmW8SYOLyKAyewG946EpX8/U1umpkfuXLK0zoS/W2SPg1EmUD5trzsYD5qOXgitg1zw+9h801cjZZEQtYhktDhIhc4zNHwcwIZ5t+sjZxl8= Received: from OS7PR01CA0289.jpnprd01.prod.outlook.com (2603:1096:604:25a::12) by OSZPR01MB8105.jpnprd01.prod.outlook.com (2603:1096:604:1b0::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Mon, 14 Sep 2026 20:37:48 +0000 Received: from OS1PEPF0000D216.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:25a:cafe::83) by OS7PR01CA0289.outlook.office365.com (2603:1096:604:25a::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.12 via Frontend Transport; Mon, 14 Sep 2026 20:37:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 8.62.32.50) smtp.mailfrom=renesas.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=renesas.com; Received-SPF: Pass (protection.outlook.com: domain of renesas.com designates 8.62.32.50 as permitted sender) receiver=protection.outlook.com; client-ip=8.62.32.50; helo=ejcrelay004p.adwin.renesas.com; pr=E Received: from ejcrelay004p.adwin.renesas.com (8.62.32.50) by OS1PEPF0000D216.mail.protection.outlook.com (10.167.240.23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Mon, 14 Sep 2026 20:37:48 +0000 Received: from demon-pc.localdomain (unknown [10.226.93.156]) by ejcrelay004p.adwin.renesas.com (Postfix) with ESMTP id C24673000257; Tue, 15 Sep 2026 05:37:45 +0900 (JST) From: Cosmin Tanislav To: Biju Das , William Breathitt Gray , Lee Jones Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH 08/15] counter: rz-mtu3-cnt: cache ceiling values Date: Mon, 14 Sep 2026 23:36:07 +0300 Message-ID: <20260914203614.2035277-9-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS1PEPF0000D216:EE_|OSZPR01MB8105:EE_ X-MS-Office365-Filtering-Correlation-Id: 63523c45-1b9a-4c15-1d23-08df12a00a39 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|23010399003|1800799024|82310400026|36860700016|6133799003|18002099003|22082099003|3023799007|10067099003|56012099006|11063799006; X-Microsoft-Antispam-Message-Info: DdaBqanBV6JW+aUF3k0+/OhcQemY/PyXIasiwdCXTA4dB/BPpdYRTWXlmn/mxm/6MrWSuwYRHQwkLEf0h2/gwblXy6RgyxykboOAsj52bu59cSJTMJNw7b1xVhymjYWEDWsph8xMbhe6U/bqEObbZyJTpwmPj1MXb0sOnqYk0/+KV19/WqjnlXxuigU6Exjdpas3qlOp+GUOEqXVkaWume3Y53kD2a9LnE7AS+bPDCKt6oclY7ULmz20aoBYXW6RO3No4YsDqwv8r/Pup26L7SrXpX18f6QvS7vnXkg2NPI3wgt9BebqDTqChe2m3PjTGkTQw7X6G6Oh0ZnkktPowXK7EzYeeuiYcLB9H4yl9AFE+pAN6wpUtFhZlcDfmzMJm0u7ALQ9mPfHE4s4MBrahcwcX+U695BvXu9eNjz//zaaz7hzXXpOHIjoN69gC4cwa1sVY3cE45O76LYm0QdaovkmFpfWkEw+NjU3/ezyOEuqroXDlOXhp4bIIeSu77uo7r9w8kutvFpj2v2vSTSpQ+ZBJBZWVSu3pJQhdrX2dA3M8bmkK4gWq4Dy8fd+c82peu0CRcN7HG8Ef4IDYlVdIz+KEihs9XHwcY7BJRZSq/x8m1fFQE4BXQA8GnQjFDKdBOzU/3kSATZw0TlrzOE06ZAZ4kNTkcGSZ6PdfDS8ko0QsqCh3DsnkpJ9OOWcaW+SFPRBlWRWnO5rBzznFou10w== X-Forefront-Antispam-Report: CIP:8.62.32.50;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ejcrelay004p.adwin.renesas.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(23010399003)(1800799024)(82310400026)(36860700016)(6133799003)(18002099003)(22082099003)(3023799007)(10067099003)(56012099006)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ji0NBv2hN/aGcjo7+hDWcmFjovF5N5KnPVXkUUTdSt3RDtlb1O+hIx/QOCkF2CzogBV9ZJhjvio7TqPlrcior2J0jTB5fOHb8crboN8LXjU2niHUg04ufJe4jaGWbOLwm31GMb9csAfsDrAzYjNYReuVg5ujOIbRQL0ao9Sx0CPJwBtlFseqiIOXNAHjbsPJ9RWhaYDja+EawnEPFyWIJyN7CnD0Vo4zUJyS0dyb7Gkqcw9qaRWUXsc9E+YmlDyozP/vDNS3hUDSWTnQMVvpV2dGaPLLriYWbmIno86ywuxuspGvG6T2SpipzJrUwF7jRgvqJeOnnh3OVKvx0p6q4D3BELW322OnSvpQUCmMkd/Vgt0/zjv4mm9NoLut5uaTa+ALLwVnF/JuTKDH+gibGXFiFyVAI9U/cV9NCtpR9GwtUZrAvsNJQV/OMWG/9sP7 X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2026 20:37:48.4803 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 63523c45-1b9a-4c15-1d23-08df12a00a39 X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=53d82571-da19-47e4-9cb4-625a166a4a2a;Ip=[8.62.32.50];Helo=[ejcrelay004p.adwin.renesas.com] X-MS-Exchange-CrossTenant-AuthSource: OS1PEPF0000D216.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: OSZPR01MB8105 Content-Type: text/plain; charset="utf-8" If an MTU3 channel is used in phase counting mode, and then in PWM mode, when returning to counting mode the ceiling value is lost because PWM mode clobbers the TGRA registers used to store the ceiling values. Restore the ceiling value in the count initialization functions for both 16-bit and 32-bit channels. To avoid writing the ceiling register when the count is disabled, and to prepare for the removal of the rz_mtu3_lock_if_counter_is_valid() function which is susceptible to TOCTOU races because of the ch->is_busy check, only write ceiling if the count is enabled. Since runtime PM is ensured to be resumed if the count is enabled, drop the pm_runtime_get_sync() and pm_runtime_put() when writing the ceiling. Signed-off-by: Cosmin Tanislav --- drivers/counter/rz-mtu3-cnt.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index f9bdfaf7bd42..b76ad6cb8b6d 100644 --- a/drivers/counter/rz-mtu3-cnt.c +++ b/drivers/counter/rz-mtu3-cnt.c @@ -150,6 +150,17 @@ static int rz_mtu3_lock_if_count_is_enabled(struct rz_= mtu3_channel *const ch, return 0; } =20 +static void rz_mtu3_set_ceiling(struct rz_mtu3_channel *const ch, int id, + u64 ceiling) +{ + if (id =3D=3D RZ_MTU3_32_BIT_CH) + rz_mtu3_32bit_ch_write(ch, RZ_MTU3_TGRALW, ceiling); + else + rz_mtu3_16bit_ch_write(ch, RZ_MTU3_TGRA, ceiling); + + rz_mtu3_8bit_ch_write(ch, RZ_MTU3_TCR, RZ_MTU3_TCR_CCLR_TGRA); +} + static int rz_mtu3_count_read(struct counter_device *counter, struct counter_count *count, u64 *val) { @@ -356,15 +367,9 @@ static int rz_mtu3_count_ceiling_write(struct counter_= device *counter, return -EINVAL; } =20 - pm_runtime_get_sync(counter->parent); - if (count->id =3D=3D RZ_MTU3_32_BIT_CH) - rz_mtu3_32bit_ch_write(ch, RZ_MTU3_TGRALW, ceiling); - else - rz_mtu3_16bit_ch_write(ch, RZ_MTU3_TGRA, ceiling); - - rz_mtu3_8bit_ch_write(ch, RZ_MTU3_TCR, RZ_MTU3_TCR_CCLR_TGRA); + if (priv->count_is_enabled[count->id]) + rz_mtu3_set_ceiling(ch, count->id, ceiling); priv->ceiling[count->id] =3D ceiling; - pm_runtime_put(counter->parent); mutex_unlock(&priv->lock); =20 return 0; @@ -374,11 +379,14 @@ static void rz_mtu3_32bit_cnt_setting(struct counter_= device *counter) { struct rz_mtu3_channel *const ch1 =3D rz_mtu3_get_ch(counter, 0); struct rz_mtu3_channel *const ch2 =3D rz_mtu3_get_ch(counter, 1); + struct rz_mtu3_cnt *const priv =3D counter_priv(counter); =20 /* Phase counting mode 1 is used as default in initialization. */ rz_mtu3_8bit_ch_write(ch1, RZ_MTU3_TMDR1, RZ_MTU3_TMDR1_PH_CNT_MODE_1); =20 - rz_mtu3_8bit_ch_write(ch1, RZ_MTU3_TCR, RZ_MTU3_TCR_CCLR_TGRA); + rz_mtu3_set_ceiling(ch1, RZ_MTU3_32_BIT_CH, + priv->ceiling[RZ_MTU3_32_BIT_CH]); + rz_mtu3_8bit_ch_write(ch1, RZ_MTU3_TIOR, RZ_MTU3_TIOR_IC_BOTH); =20 rz_mtu3_enable(ch1); @@ -388,11 +396,13 @@ static void rz_mtu3_32bit_cnt_setting(struct counter_= device *counter) static void rz_mtu3_16bit_cnt_setting(struct counter_device *counter, int = id) { struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, id); + struct rz_mtu3_cnt *const priv =3D counter_priv(counter); =20 /* Phase counting mode 1 is used as default in initialization. */ rz_mtu3_8bit_ch_write(ch, RZ_MTU3_TMDR1, RZ_MTU3_TMDR1_PH_CNT_MODE_1); =20 - rz_mtu3_8bit_ch_write(ch, RZ_MTU3_TCR, RZ_MTU3_TCR_CCLR_TGRA); + rz_mtu3_set_ceiling(ch, id, priv->ceiling[id]); + rz_mtu3_8bit_ch_write(ch, RZ_MTU3_TIOR, RZ_MTU3_TIOR_NO_OUTPUT); rz_mtu3_enable(ch); } --=20 2.55.0 From nobody Fri Sep 25 09:22:49 2026 Received: from TYVP286CU001.outbound.protection.outlook.com (mail-japaneastazon11011021.outbound.protection.outlook.com [52.101.125.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 650D249F125; Mon, 14 Sep 2026 20:37:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.125.21 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418278; cv=fail; b=LCyFyzwoNrlGD9wX9t1I6+RVq6Ns3QmzGwIU3ullUTgOXDSMUfV1q8DyeZ2j6Pts+EaoTG+UxD2rRPdy+JWkuFUG8rSMTYlZgET2abN49Rn5dtRGkJeXGUWbzj/1i6+B8gqNeXFNLmKefEqKeWNfSbyCL2TqLQrfRbBfmyc5aMA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418278; c=relaxed/simple; bh=gHtU3lsHSje9A5/MO3GWx1QA8MbRUOnabIKfzt4XwuQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UvUFEB+OZ0IXBntC3T5XSLR2HOTZRz34HrbDkmg4jCcq/5C0Bl5OHmCwGMryPYkhewPC6Y98EmoEaaFK5zLyjgYh878mLOvncqvIoEjf2Dr/eY+5f6jy/95iaitkSjvYQlK93PnNl6luuEQpZ4SFegfozvohThfAaKPzyv1EQ6Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=DFpz+zRp; arc=fail smtp.client-ip=52.101.125.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="DFpz+zRp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ywDV1mHYMFWAHlqXei8DH4qOJWJCkzLzNKlHiXkFMNLHNv2lNCFaJT2oe6Xdsux6kYcy6AoS4kBOCpfdaF7Ls2x+3xQuOv2PFxbLgR1zom/XyQSkhaaUpAHmR+P4yAiY3c4YLPVFUlhev5Dwq7jP7USDYntaaqImLxXx9N+/uwht4CdLBgbEsoiPbMfEDwXnI6cpkWACgQGQsWX12jfX5Kl2OYwNEuCH9e+a9Q16Fxac4jQxDyofV7yNkKeYXWHf9C+0Rix2jC2Ry54PGSJkaF1gQnFMb9TlkGCUiqkuG3GIswbnRh5F/imbOVa5aA0SIPEV3Yn2xcmTfqyQicZwzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=AAWN1tx+ynjw4xNkWP75QtutSb8CS4HMM5Rn1FyfGgk=; b=M89dqCMo7FVFu4iQ+DFMwaJdw0QnDiR0qkcv/k7EGfhWc86Dqc6zFZVCIE5z5oHdaC5LcCMzx60K+dNfHWxpeo7J1QhYqr1iXgp15dBlAYBlCkvVJZcw+4JHZgHiArvEzlcSpdfwtbDJ5S7VzY0WgaJ847EpR3yW6Q0NYbtXdNLO/4n+mDUIlig65SyE9LcguVOWQwiWVjNVmLm161bfvb6sJW3y/Y+N+nKt6yNCj01oUUb+471ZtssbeAf18yGdUWSVDMBnCwbJ7B9ny+28kCLYnKa82mTzAnUdDTf+rLq3yiHMDUMq6WT9Ag30NRh6hcgHKgiL/bY3CWdOnY6H1w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 8.62.32.50) smtp.rcpttodomain=bp.renesas.com smtp.mailfrom=renesas.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=renesas.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AAWN1tx+ynjw4xNkWP75QtutSb8CS4HMM5Rn1FyfGgk=; b=DFpz+zRpo/6Q6U+Qib8e6xcO8yL0rtZL70J11TIKAuos2kboBZHa/s1ww+aPw/41Qi7xGklNS2P3LS9QnmgdzXIPOnUgPA2npFQFrt19GSglextbf+m60ncqIapprZ/Q4+G/lkA1rasXM+GvWrvyIQTsJeWPXd8T1k8XqKzuvvg= Received: from TYCP301CA0051.JPNP301.PROD.OUTLOOK.COM (2603:1096:400:384::16) by OSCPR01MB13257.jpnprd01.prod.outlook.com (2603:1096:604:350::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Mon, 14 Sep 2026 20:37:51 +0000 Received: from TY2PEPF00005621.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:384:cafe::5) by TYCP301CA0051.outlook.office365.com (2603:1096:400:384::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.12 via Frontend Transport; Mon, 14 Sep 2026 20:37:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 8.62.32.50) smtp.mailfrom=renesas.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=renesas.com; Received-SPF: Pass (protection.outlook.com: domain of renesas.com designates 8.62.32.50 as permitted sender) receiver=protection.outlook.com; client-ip=8.62.32.50; helo=ejcrelay004p.adwin.renesas.com; pr=E Received: from ejcrelay004p.adwin.renesas.com (8.62.32.50) by TY2PEPF00005621.mail.protection.outlook.com (10.167.240.52) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Mon, 14 Sep 2026 20:37:51 +0000 Received: from demon-pc.localdomain (unknown [10.226.93.156]) by ejcrelay004p.adwin.renesas.com (Postfix) with ESMTP id 4E7343000368; Tue, 15 Sep 2026 05:37:49 +0900 (JST) From: Cosmin Tanislav To: Biju Das , William Breathitt Gray , Lee Jones Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH 09/15] counter: rz-mtu3-cnt: cache count values Date: Mon, 14 Sep 2026 23:36:08 +0300 Message-ID: <20260914203614.2035277-10-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TY2PEPF00005621:EE_|OSCPR01MB13257:EE_ X-MS-Office365-Filtering-Correlation-Id: 7fc2701b-6ce0-4d7c-2bfc-08df12a00c2c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|376014|23010399003|82310400026|1800799024|3023799007|10067099003|56012099006|11063799006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: ph3rcp88aLeRREiSfNooZerPYglqDLvRvDmQI9gF/AZltkDexqsWpp0VKqAUNikIVDgJC6joHnZzPQxN4ySkff3LrBrs2z4/uCD+djzrJ+sdObqZnqKfMx0XLg70noaU5ZzAk6CBBYlG/aFDFEqRwOTGOgOnOFaEH+1Ejbje14Aoo2qrTXZJGacHanQ9F1sSIi0mPGRjBHteh0z7BqlhV3cbkM7ltJfuC5BuCjuyaaHk1rNNvQQq1BfV4wZKFvUntBxhfHYP43PJBn1oL5DWm5MiS27CuJUr1E4Pr/emmMa/7MgeucBgvOdjwWhJDNrd5NQrm1oIRxz9sfl8lx/ENHjhYrfS1lmDkwv2FeHkclWLWxjU5+zyfy+Lntq0tHPNajWKDqH1sMjmbX04VHkm/rIjz5ZuZQUSKvF4fnexE3K8gDC14eO7WSbuWMFTHA1u1UGfrUzimQeogGtrJUR2hjhV0eBPOV5hBfegO5nYn2l6wGAG0j8o9PLOBpqFaf5plXtmHyuq9zKm7wKP2dcpb2CxVzqUufXIWWxKLxj1WnnBVUnwYfrPz2xtF821lyf816IXtT8hvmqqVc2IskI+4IJd0NNSxnVpWJKmDRhmFp0knnu0kYjK1mVil/xSWBsFxYTFN84nSjUulkI/RGeHeo/m2qUAfIMLq213dlLLJUP1SYAXC9N614Cl+gOB3h5wLBfI8Uk4LS8edG/VAG3m/w== X-Forefront-Antispam-Report: CIP:8.62.32.50;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ejcrelay004p.adwin.renesas.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(376014)(23010399003)(82310400026)(1800799024)(3023799007)(10067099003)(56012099006)(11063799006)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Q70LBAklrL4ZjjQwL0d+I5zvcUOVdEB+twpn+qRFY5t56cA5Jr3/cOPKUncY5ZpxMJv03zhUHuhwlL0+dgYVazC7O/TNUfYq7w9EUhYuKPWeuDkam2JE914BPbHAhGo36q/6SaVylNqUZjTy1mTAbewiUFCaFM7HbyZh1irzKD+fWeelR6iRz2nZdGYGKIy4ZgkeDZh8iU/DpUnr/NcJYMpq6aUs3i0F2nwH8OHDFdPZG/fqqm8FBVozXKlPy6ldD5cRYCrw1rKl3el6f558oAnnPhinfp3W9kRSKimihCTNuCi/dPJ8eDU6gqEPN5OqfCoKowk+9YujYmNF+V0baCOcQAoss+4lA1HZsJ+x+YzeAC41/BxmaCasgx4qq8ih8+mJKi/AIwrLXOE1l3mcjjnIFh9DDethnl85cTtCTnMYi/CahWJwUVSwXQlPfuwD X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2026 20:37:51.7636 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7fc2701b-6ce0-4d7c-2bfc-08df12a00c2c X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=53d82571-da19-47e4-9cb4-625a166a4a2a;Ip=[8.62.32.50];Helo=[ejcrelay004p.adwin.renesas.com] X-MS-Exchange-CrossTenant-AuthSource: TY2PEPF00005621.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: OSCPR01MB13257 Content-Type: text/plain; charset="utf-8" If an MTU3 channel is used in counting mode, and then in PWM mode, when returning to counting mode the count value is lost because the TCNT register is overwritten by PWM mode. To handle this issue, save the count value on disable and restore it on enable, and also save it inside rz_mtu3_count_write(). To avoid writing the count value register when the count is disabled, and to prepare for the removal of the rz_mtu3_lock_if_counter_is_valid() function which is susceptible to TOCTOU races because of the ch->is_busy check, only read or write the count value if the count is enabled. Since runtime PM is ensured to be resumed if the count is enabled, drop the pm_runtime_get_sync() and pm_runtime_put() calls. Signed-off-by: Cosmin Tanislav --- drivers/counter/rz-mtu3-cnt.c | 42 +++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index b76ad6cb8b6d..68025c6ed409 100644 --- a/drivers/counter/rz-mtu3-cnt.c +++ b/drivers/counter/rz-mtu3-cnt.c @@ -76,6 +76,7 @@ struct rz_mtu3_cnt { struct mutex lock; struct rz_mtu3_channel *ch; u32 ceiling[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; + u32 count[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; bool count_is_enabled[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; }; =20 @@ -161,6 +162,23 @@ static void rz_mtu3_set_ceiling(struct rz_mtu3_channel= *const ch, int id, rz_mtu3_8bit_ch_write(ch, RZ_MTU3_TCR, RZ_MTU3_TCR_CCLR_TGRA); } =20 +static u32 rz_mtu3_get_count(struct rz_mtu3_channel *const ch, int id) +{ + if (id =3D=3D RZ_MTU3_32_BIT_CH) + return rz_mtu3_32bit_ch_read(ch, RZ_MTU3_TCNTLW); + else + return rz_mtu3_16bit_ch_read(ch, RZ_MTU3_TCNT); +} + +static void rz_mtu3_set_count(struct rz_mtu3_channel *const ch, int id, + u32 count) +{ + if (id =3D=3D RZ_MTU3_32_BIT_CH) + rz_mtu3_32bit_ch_write(ch, RZ_MTU3_TCNTLW, count); + else + rz_mtu3_16bit_ch_write(ch, RZ_MTU3_TCNT, count); +} + static int rz_mtu3_count_read(struct counter_device *counter, struct counter_count *count, u64 *val) { @@ -172,12 +190,9 @@ static int rz_mtu3_count_read(struct counter_device *c= ounter, if (ret) return ret; =20 - pm_runtime_get_sync(counter->parent); - if (count->id =3D=3D RZ_MTU3_32_BIT_CH) - *val =3D rz_mtu3_32bit_ch_read(ch, RZ_MTU3_TCNTLW); - else - *val =3D rz_mtu3_16bit_ch_read(ch, RZ_MTU3_TCNT); - pm_runtime_put(counter->parent); + if (priv->count_is_enabled[count->id]) + priv->count[count->id] =3D rz_mtu3_get_count(ch, count->id); + *val =3D priv->count[count->id]; mutex_unlock(&priv->lock); =20 return 0; @@ -194,12 +209,9 @@ static int rz_mtu3_count_write(struct counter_device *= counter, if (ret) return ret; =20 - pm_runtime_get_sync(counter->parent); - if (count->id =3D=3D RZ_MTU3_32_BIT_CH) - rz_mtu3_32bit_ch_write(ch, RZ_MTU3_TCNTLW, val); - else - rz_mtu3_16bit_ch_write(ch, RZ_MTU3_TCNT, val); - pm_runtime_put(counter->parent); + if (priv->count_is_enabled[count->id]) + rz_mtu3_set_count(ch, count->id, val); + priv->count[count->id] =3D val; mutex_unlock(&priv->lock); =20 return 0; @@ -386,6 +398,8 @@ static void rz_mtu3_32bit_cnt_setting(struct counter_de= vice *counter) =20 rz_mtu3_set_ceiling(ch1, RZ_MTU3_32_BIT_CH, priv->ceiling[RZ_MTU3_32_BIT_CH]); + rz_mtu3_set_count(ch1, RZ_MTU3_32_BIT_CH, + priv->count[RZ_MTU3_32_BIT_CH]); =20 rz_mtu3_8bit_ch_write(ch1, RZ_MTU3_TIOR, RZ_MTU3_TIOR_IC_BOTH); =20 @@ -402,6 +416,7 @@ static void rz_mtu3_16bit_cnt_setting(struct counter_de= vice *counter, int id) rz_mtu3_8bit_ch_write(ch, RZ_MTU3_TMDR1, RZ_MTU3_TMDR1_PH_CNT_MODE_1); =20 rz_mtu3_set_ceiling(ch, id, priv->ceiling[id]); + rz_mtu3_set_count(ch, id, priv->count[id]); =20 rz_mtu3_8bit_ch_write(ch, RZ_MTU3_TIOR, RZ_MTU3_TIOR_NO_OUTPUT); rz_mtu3_enable(ch); @@ -447,6 +462,9 @@ static void rz_mtu3_terminate_counter(struct counter_de= vice *counter, int id) struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, id); struct rz_mtu3_channel *const ch1 =3D rz_mtu3_get_ch(counter, 0); struct rz_mtu3_channel *const ch2 =3D rz_mtu3_get_ch(counter, 1); + struct rz_mtu3_cnt *const priv =3D counter_priv(counter); + + priv->count[id] =3D rz_mtu3_get_count(ch, id); =20 if (id =3D=3D RZ_MTU3_32_BIT_CH) { rz_mtu3_disable(ch2); --=20 2.55.0 From nobody Fri Sep 25 09:22:49 2026 Received: from OS0P286CU010.outbound.protection.outlook.com (mail-japanwestazon11011005.outbound.protection.outlook.com [40.107.74.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3696F429000; Mon, 14 Sep 2026 20:37:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.74.5 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418282; cv=fail; b=GyVAprK58F4bFGtKyaxDkL1ef2Fw/ewIn+FalPE4IpffKp4rw1agiHteb3NtWMB/C8KByKsIs2tsmBm0+GIQz4gM/uefUNAUF7ytnXbB4EKFB4IhlRr89V9N7FyK4B4fvyTn5U0X3/DVKrBXYj8E+Ha9smkRbbZBQd6gGOmDY0U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418282; c=relaxed/simple; bh=QuCa27XwwZO3xiL2nCpf3COaMT8sSLYHJultcJfkAtI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YaepKQ3yhZdGroaE7tZGZlGm4MBdV3+IC7eHBsDmiAJCEdOmdLMYS7BNcO5Ms0KvKOP8V8Bx1O/Smg4+72yn6wJE89bEHkzu7+PyqIlUBPPvIrJmzJesaujcBurVuac/UWbLKytcRNnnDUcq+tyBBbL85u5slEIcrq7b8gKsEoA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=Apd0BAU8; arc=fail smtp.client-ip=40.107.74.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="Apd0BAU8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=m2BZQvKDb1RBm3kgOPuHh5AEZzWvqophaYqKdHNOfceuQglwEpPu24hHCwcb/eqCOYTVgrPcsU1xJd8nNJi1b9kLdOGUDrEH7YwzxrTV5tZnpyqg1CZqxCco9udlqeFwLkxKiOkMUBqQxu7S2lSoIz64nSMUiRlvTZOIHUYnF0XYKeNAhLDJWbWXRHVGdhu/KETcz4TXFUQ91szJiMvH670jP9XQC6iGBSvXGBTfBkZtZL6IEqWoeaIijJoZb/qtIFwwQxggX/e57Zuo++tWT52SuoHw7WA/Vgzgdl/4Wpq0dTcmNA4qq6S+R1TaJS8dBYIUNVNFSsod5C3W0HGSSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=3EDYNwMAtGYOpr6G676HE3okbnqXkKujSCKU9gbG+5k=; b=mUoUCOKlHyNPdTRcaC6/ah81exoQNuc2+/ErjGKXw2yzi1AmCwcJkVfBT6g6dJc79DgIfU2s1A0V9h0oqFgTsP29MZRsqMffFavJGhwWBCZKuQj3iXZpvaY6QCon3eLCp9/fMsq0lzNXHOqaeZ039xoTs2AlE+8exouGx0NivHD+S0/LSmGy6M2NjBDcjyGM3QIQKeBWe47tAsAKtbZgeGq/mMbnuhCW8Qr3CKvovnfngJ/xyb5+pf04wqa5MedYcnRjSGHgryWtsF+WBjfYi7720yrJEUg0GtaoM4svfKEOxemMUgTihQyMsxBye2Bq6q/MaBsJl5sPlCfYhNT5fA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 8.62.32.50) smtp.rcpttodomain=bp.renesas.com smtp.mailfrom=renesas.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=renesas.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3EDYNwMAtGYOpr6G676HE3okbnqXkKujSCKU9gbG+5k=; b=Apd0BAU8bNaGUjt0Mj9dXXwrwY9mhyzurTCPoTQzahURiBS3FbgErVp+L1YBtEAc+wmW3FWR/4Y1ipPXrxF+0Vsa9yKBnjTf/Ra0/d5QI7qsCYRhX18mEK1KvMECkP4RK6hZz4Cp9z0CbDtfCbuZ4W1VbCodyisdXzi12660mQo= Received: from OS7PR01CA0300.jpnprd01.prod.outlook.com (2603:1096:604:25a::6) by OS9PR01MB17415.jpnprd01.prod.outlook.com (2603:1096:604:44e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Mon, 14 Sep 2026 20:37:55 +0000 Received: from OS1PEPF0000D20D.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:25a:cafe::5f) by OS7PR01CA0300.outlook.office365.com (2603:1096:604:25a::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.12 via Frontend Transport; Mon, 14 Sep 2026 20:37:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 8.62.32.50) smtp.mailfrom=renesas.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=renesas.com; Received-SPF: Pass (protection.outlook.com: domain of renesas.com designates 8.62.32.50 as permitted sender) receiver=protection.outlook.com; client-ip=8.62.32.50; helo=ejcrelay004p.adwin.renesas.com; pr=E Received: from ejcrelay004p.adwin.renesas.com (8.62.32.50) by OS1PEPF0000D20D.mail.protection.outlook.com (10.167.240.36) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Mon, 14 Sep 2026 20:37:55 +0000 Received: from demon-pc.localdomain (unknown [10.226.93.156]) by ejcrelay004p.adwin.renesas.com (Postfix) with ESMTP id B5D6D3000368; Tue, 15 Sep 2026 05:37:52 +0900 (JST) From: Cosmin Tanislav To: Biju Das , William Breathitt Gray , Lee Jones Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH 10/15] counter: rz-mtu3-cnt: cache function values Date: Mon, 14 Sep 2026 23:36:09 +0300 Message-ID: <20260914203614.2035277-11-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS1PEPF0000D20D:EE_|OS9PR01MB17415:EE_ X-MS-Office365-Filtering-Correlation-Id: 0879bb06-4df9-4bd6-0340-08df12a00e3f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700016|23010399003|82310400026|1800799024|6133799003|10067099003|56012099006|11063799006|22082099003|18002099003|18092099006; X-Microsoft-Antispam-Message-Info: VN2EmY76UbNr+wh7z8obml2eTZm5FIH279TUZFttPnhYK/rQCWmu69/TKF4WcgdNxD+MEHw8m80RaFuvUynYdU3V5ffMizYYLxdwoopE6f5gUjNyXijPgKolLOpLoTlKBtzbpSMPExWoHPk10FJPNDImmy1PMyEngbGi/RKp9DF5DNQEsffCl7SbHRRy3xIvbHdiqR2pYE64WtHUc1izpkaZGzl2vYNo3+chX9/iFrOBWVLH1pyAHI7wrBuHezB7ow8MYdXXORaowdBHEjfRX+vuZJI0GF7kswuqyl44X7J1ou40VavznBEfqkKYs2rdZ37qVG+bb2te2Wsd7i+NOWhDL+7H8rKBylQmmh93NfMxKmuzssIsqZ15/8yfBsZxfgDo24ziQTOS+kWmT46SnVqtZb9VCRQIrNl7s3q1oJOxF+Xhd2SMQhWuzO5vNJfs/q/rAEwY7n6Abe+h8OD9I6aXYYHwt+RNxqOpmfGRRVojlJvVkxqwH0TpYq3dSI0PIg9NLh01qXt3uPOywd2AAxVYFxuNYSJr6gc4+BpODNQp7fsvw6m5INqA6vmhgHsmcHXdjtKDqatPco/IJp1xtmBfAEa1SEvf6NOTzxwaPZA0hGt/wqgX15A6oLZlOEokozr0NrgtfOBdf5oY10tfAGkYaMU+yQT9yXcensgRLAb4HPWabfVEpI1LvdIE3oiDwYVZl8Haluqg9dwlCpp0PA== X-Forefront-Antispam-Report: CIP:8.62.32.50;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ejcrelay004p.adwin.renesas.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(36860700016)(23010399003)(82310400026)(1800799024)(6133799003)(10067099003)(56012099006)(11063799006)(22082099003)(18002099003)(18092099006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3PJBgQWEvbM3iATP1BW8zr2fZk0GmJu1E6rG0Z1Bb8yl4joCMEGZgusua0hvDHuc7fHtTZdZndTjQ46Pk9804TWJiHPrbRzk59DnPmZahubIB4U37PY+/Dli9woWHxer3PGjMKOOTHu6k0a9jh2ti7gUW9G1TKoGuCbmyegzK1aRG3gpA03H+hwd5ttFKrPOY53qTThdLmI4QMPbWPtZt+7015pDgw2LW3wbkXawKazzkk/YyfAvh5TtRUri5XEOacHT1GQJjKgGC6N26DUIbfA0y0DMVNjSyqCVo7XMlPnN7Yp/gV23H1TZ12ACGzyJimYVLiYzEuNyjL2cCzeDj+frCFzhAMEggWlDKqUh2cMpr4s0Iqzou0KTtIo0XJajUQUVsf+6/u85Iw/xBVxp5VpSEKx/csEyazfS8NfgC9RmQbMncoVFA68YJ3Hhsga4 X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2026 20:37:55.2338 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0879bb06-4df9-4bd6-0340-08df12a00e3f X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=53d82571-da19-47e4-9cb4-625a166a4a2a;Ip=[8.62.32.50];Helo=[ejcrelay004p.adwin.renesas.com] X-MS-Exchange-CrossTenant-AuthSource: OS1PEPF0000D20D.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS9PR01MB17415 Content-Type: text/plain; charset="utf-8" If an MTU3 channel is used in a specific phase counting mode, when disabling it and enabling it again, the user set mode is lost because the timer mode register (TMDR1) is initialized to the default value. Save the timer mode after setting it and restore it on enable. Use the cached value to determine the function in rz_mtu3_count_function_read_helper(). Avoid writing the TMDR1 register when the count is disabled to prevent writing registers without actually owning the channel, as the busy check inside ch->is_busy can race with PWM operations. Since runtime PM is ensured to be resumed if the count is enabled, drop the pm_runtime_get_sync() and pm_runtime_put() calls. Signed-off-by: Cosmin Tanislav --- drivers/counter/rz-mtu3-cnt.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index 68025c6ed409..3e380f69cb45 100644 --- a/drivers/counter/rz-mtu3-cnt.c +++ b/drivers/counter/rz-mtu3-cnt.c @@ -77,6 +77,7 @@ struct rz_mtu3_cnt { struct rz_mtu3_channel *ch; u32 ceiling[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; u32 count[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; + u8 timer_mode[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; bool count_is_enabled[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; }; =20 @@ -217,17 +218,11 @@ static int rz_mtu3_count_write(struct counter_device = *counter, return 0; } =20 -static int rz_mtu3_count_function_read_helper(struct rz_mtu3_channel *cons= t ch, - struct counter_device *const counter, +static int rz_mtu3_count_function_read_helper(struct rz_mtu3_cnt *const pr= iv, + int id, enum counter_function *function) { - u8 timer_mode; - - pm_runtime_get_sync(counter->parent); - timer_mode =3D rz_mtu3_8bit_ch_read(ch, RZ_MTU3_TMDR1); - pm_runtime_put(counter->parent); - - switch (timer_mode & RZ_MTU3_TMDR1_PH_CNT_MODE_MASK) { + switch (priv->timer_mode[id]) { case RZ_MTU3_TMDR1_PH_CNT_MODE_1: *function =3D COUNTER_FUNCTION_QUADRATURE_X4; return 0; @@ -259,7 +254,7 @@ static int rz_mtu3_count_function_read(struct counter_d= evice *counter, if (ret) return ret; =20 - ret =3D rz_mtu3_count_function_read_helper(ch, counter, function); + ret =3D rz_mtu3_count_function_read_helper(priv, count->id, function); mutex_unlock(&priv->lock); =20 return ret; @@ -298,9 +293,9 @@ static int rz_mtu3_count_function_write(struct counter_= device *counter, return -EINVAL; } =20 - pm_runtime_get_sync(counter->parent); - rz_mtu3_8bit_ch_write(ch, RZ_MTU3_TMDR1, timer_mode); - pm_runtime_put(counter->parent); + if (priv->count_is_enabled[count->id]) + rz_mtu3_8bit_ch_write(ch, RZ_MTU3_TMDR1, timer_mode); + priv->timer_mode[count->id] =3D timer_mode; mutex_unlock(&priv->lock); =20 return 0; @@ -393,8 +388,8 @@ static void rz_mtu3_32bit_cnt_setting(struct counter_de= vice *counter) struct rz_mtu3_channel *const ch2 =3D rz_mtu3_get_ch(counter, 1); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); =20 - /* Phase counting mode 1 is used as default in initialization. */ - rz_mtu3_8bit_ch_write(ch1, RZ_MTU3_TMDR1, RZ_MTU3_TMDR1_PH_CNT_MODE_1); + rz_mtu3_8bit_ch_write(ch1, RZ_MTU3_TMDR1, + priv->timer_mode[RZ_MTU3_32_BIT_CH]); =20 rz_mtu3_set_ceiling(ch1, RZ_MTU3_32_BIT_CH, priv->ceiling[RZ_MTU3_32_BIT_CH]); @@ -412,9 +407,7 @@ static void rz_mtu3_16bit_cnt_setting(struct counter_de= vice *counter, int id) struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); =20 - /* Phase counting mode 1 is used as default in initialization. */ - rz_mtu3_8bit_ch_write(ch, RZ_MTU3_TMDR1, RZ_MTU3_TMDR1_PH_CNT_MODE_1); - + rz_mtu3_8bit_ch_write(ch, RZ_MTU3_TMDR1, priv->timer_mode[id]); rz_mtu3_set_ceiling(ch, id, priv->ceiling[id]); rz_mtu3_set_count(ch, id, priv->count[id]); =20 @@ -644,7 +637,7 @@ static int rz_mtu3_action_read(struct counter_device *c= ounter, if (ret) return ret; =20 - ret =3D rz_mtu3_count_function_read_helper(ch, counter, &function); + ret =3D rz_mtu3_count_function_read_helper(priv, count->id, &function); if (ret) { mutex_unlock(&priv->lock); return ret; @@ -811,6 +804,7 @@ static int rz_mtu3_cnt_probe(struct platform_device *pd= ev) struct device *dev =3D &pdev->dev; struct counter_device *counter; struct rz_mtu3_cnt *priv; + unsigned int i; int ret; =20 counter =3D devm_counter_alloc(dev, sizeof(*priv)); @@ -822,6 +816,8 @@ static int rz_mtu3_cnt_probe(struct platform_device *pd= ev) priv->ceiling[RZ_MTU3_16_BIT_MTU2_CH] =3D U16_MAX; priv->ceiling[RZ_MTU3_32_BIT_CH] =3D U32_MAX; priv->ch =3D &ddata->channels[RZ_MTU3_CHAN_1]; + for (i =3D 0; i < RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS; i++) + priv->timer_mode[i] =3D RZ_MTU3_TMDR1_PH_CNT_MODE_1; =20 mutex_init(&priv->lock); =20 --=20 2.55.0 From nobody Fri Sep 25 09:22:49 2026 Received: from OS0P286CU010.outbound.protection.outlook.com (mail-japanwestazon11011046.outbound.protection.outlook.com [40.107.74.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B89554A0925; Mon, 14 Sep 2026 20:38:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.74.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418286; cv=fail; b=dMEhGysBCJTupw4pd36lf0C9h33EgBQz7GJX0xC7/k6Hxb+xadDbHvr3VCH1O9yUiEzlRbIZNUG1idMM4khgtZ22YZLrxrsbnHlawZCUYKqHiePyoC2X65Vi2RlWiNQV2cf99+pEeoeHODb0vC7b7YK65p3f7lkmMruaXqxQtAg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418286; c=relaxed/simple; bh=xc5HNsC1DG5zLbgQ/JcawpnekmMUxkTeUlExKisBmp0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fA3WYwiXsyLrXtQkx92EeRW1jVGdw0AbVTaOJtjiPZhqLajzYV7EtP/z0g4dMGFCoBPbZnOYWcy4fB0mVjwjxfFtxd0R9/VvhO1WwmYBSGGrGqaoSVNc2g7BaBPgjYfyj8ZHmSgjjW2tDmgA3gSV2pQ8UYimf3yckB4wDBhIjkc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=Cc+CeLJT; arc=fail smtp.client-ip=40.107.74.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="Cc+CeLJT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mVAp0Y0M7X60RAtQ3kMkFLcuz7XhvRHGMz20pIvJQDpktoaLYO4P6bKnSLb7L7BvLipTFMpNoZcy5Z2u4Ud1tPgiZQ7XW+7TPNY2T3rAHpPFvLHV0BHn4NgUGW1wLyW1yT+cnZb7gq4NVfq45HA8DpNoEvnSP9GvhxpfI36SyZtsb9CTMpTBPkBYBGH25WNSFupgXEhff8xdp9PvFT3/TNhsQKGLWEGgrE3Ey6LKKG/16JA1LIbRb/R6S5egPOjT+uHdRMSZ6tYiwYZF82PzSvQ2zx6npZ/MME9qYYW/rX2Zvqx8W+NYPMufdseRsRi6a2NjHKPxwPDvuNqHo0zAwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=MT2COeaNeCzkcZzV1LlRqeYTXHBHh1MkBlw7jqn06f8=; b=SF3cEf83RTPvTyPGsVBAzLLo1F+nhmjjGEM7l9jSYjMMirpJX+/Rgp8muoaacUstjHrE0rlLEiTwEKioVXdUmoKJh1Kp0I1zdVl0hnFdsJpwgXEE7D3skRRreX6qVMFHVdQlC07tif5MeSIBmbsJTg3niU4IgwTNHL5g/lT0ti/OCl5fCoBiMwgCVh5yjxI+sAQyQL0TBh/9tW465wP1XSukZPYeVV/LEFMrzRFlu8s/Z6uzxty77WIwEvl/hl2yunJAFLcnsmxF7QxcNQ5xYvfo3DU5sg4bthUyBB0CagbcjmWhbw857v2c2ApuZouZEQP7ulZhUgral0MXXwFFaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 8.62.32.50) smtp.rcpttodomain=bp.renesas.com smtp.mailfrom=renesas.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=renesas.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MT2COeaNeCzkcZzV1LlRqeYTXHBHh1MkBlw7jqn06f8=; b=Cc+CeLJTp4lB8hnHwF/9hjBC2/F4LPBUM52aGi+5phskDk6WfPKo/8lHQ38AlfES9t3rSexLn+4Nm9AZ+oCMKVEhRpPYhWp1Y3ftpT2/FWgEt7Gg73DHFhZ0urnG8uHj41/3iaBFXDwxSyApemuCSmB5t5EQlCwS0ZZ/Jd/5tUw= Received: from TY4P286CA0072.JPNP286.PROD.OUTLOOK.COM (2603:1096:405:36d::11) by OSCPR01MB15595.jpnprd01.prod.outlook.com (2603:1096:604:3c1::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Mon, 14 Sep 2026 20:37:58 +0000 Received: from TY1PEPF0000BAD7.JPNP286.PROD.OUTLOOK.COM (2603:1096:405:36d:cafe::50) by TY4P286CA0072.outlook.office365.com (2603:1096:405:36d::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.13 via Frontend Transport; Mon, 14 Sep 2026 20:37:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 8.62.32.50) smtp.mailfrom=renesas.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=renesas.com; Received-SPF: Pass (protection.outlook.com: domain of renesas.com designates 8.62.32.50 as permitted sender) receiver=protection.outlook.com; client-ip=8.62.32.50; helo=ejcrelay004p.adwin.renesas.com; pr=E Received: from ejcrelay004p.adwin.renesas.com (8.62.32.50) by TY1PEPF0000BAD7.mail.protection.outlook.com (10.167.240.36) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Mon, 14 Sep 2026 20:37:58 +0000 Received: from demon-pc.localdomain (unknown [10.226.93.156]) by ejcrelay004p.adwin.renesas.com (Postfix) with ESMTP id 4ADE63000368; Tue, 15 Sep 2026 05:37:56 +0900 (JST) From: Cosmin Tanislav To: Biju Das , William Breathitt Gray , Lee Jones Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH 11/15] counter: rz-mtu3-cnt: cache external input phase clock value Date: Mon, 14 Sep 2026 23:36:10 +0300 Message-ID: <20260914203614.2035277-12-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TY1PEPF0000BAD7:EE_|OSCPR01MB15595:EE_ X-MS-Office365-Filtering-Correlation-Id: 9f00e145-32b1-412f-6d64-08df12a0105c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|376014|1800799024|82310400026|36860700016|6133799003|18002099003|22082099003|10067099003|56012099006|11063799006; X-Microsoft-Antispam-Message-Info: Ax4gG09j//aYxSmNgQU918vB8RQrVQ/G5aQHXnzbYmwH6A7Ggyf/cHjhcOD4yaclRUKmDMZwRc4JGoCmJmo4C1g+KBDmdqRhNj5dq6PmJ770RHmzJnPoL5NU4+uvhHaFYyVfhIejCOcMR5WbOJvmx/eVCXrOUEY9P6q7zaeEzZVAmEh54qOfxa/15oMQcraYaYW0vXOZGSvK6FcSgPK2TGm2J8uz6qLwWM8l23PJfp52/qtf1G51dnlgAsuRYtJqu93GBXGaSvUAA9pAfs/j1bzRyJpRYbDoobStejkcYV6dyeEplb+WTffdlFLuYhjXRuuWEARoyeAOoZ19ebWv9Qaql67qf5y/6kMMynouX3rndA0KKstyPuvHArYcL5YgkPhQTL1dGHxR24SC+2T4FbApRqD4rEv13h9CdQ3CbanxepBfqfTLptBpT+DX+/Gp7XViaABFLFCBZquD74lPhZdFMFSPRJthfC0wIbZbR1ZQ/UN9a4y9Xy+xvu3r2yt3rbJ1p3No2gW7Fatyde9ehQY9TyHM1FXgf3O8bAR14nY8MK4SioT7ApyrnA+kIpMeMY1BD84veuvg2L8mq8+Ki8APfp/ImEj0gTLQWJIIkd2hT72NO/SNuUoW0/0ZWhBLxbVvXmDxvBunvC24og+xAZL0LVhuFMXPXvqKyDV2MEr/+4SkBV2no4M+gWPoPo8sAiM9ek/jhJCCVDGdBt9UTQ== X-Forefront-Antispam-Report: CIP:8.62.32.50;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ejcrelay004p.adwin.renesas.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(23010399003)(376014)(1800799024)(82310400026)(36860700016)(6133799003)(18002099003)(22082099003)(10067099003)(56012099006)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xCtMf/Vg8BG7Jvz7M9qefHPNyaxAnZUkKsUQP5wnh7WGYZwU85xQHUk96q8Cu19cGrl7OkRr4JnsIfXe1SGRMJZwFFhB9G0YtIyn5ZUxSoTukaG9Xi+O6Dxsu61ZkYgh0S1JBvUsFIMUZdc3BvhG/EM85w9tekfCrFTIBs4b9F0wQstGf+/fxvN+HmWcc/j0CwuBJOblX78SIAOxC86CWH8dfLrE2Y4C/CbVob1+owVBER1bGIL2SSHt3OLYh9nt3xDPD1C/qOtlzA3a95mdfE4SrMK7tFFJYd5KqNqJQh5o+163dHZCrd3sP+8BlnAAiQmpnu9X32wmaMpvlnHeU0v44IS30hlrfLaMaGtfBWeu8Rb1i2tJpXhp1enkrHO5LgjLO+4jVR9kR5G6mUgRdsgoImFBhiBbYu5VZ8D7Rgv1dGQvQIzgNRsm56e90HTB X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2026 20:37:58.7960 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9f00e145-32b1-412f-6d64-08df12a0105c X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=53d82571-da19-47e4-9cb4-625a166a4a2a;Ip=[8.62.32.50];Helo=[ejcrelay004p.adwin.renesas.com] X-MS-Exchange-CrossTenant-AuthSource: TY1PEPF0000BAD7.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: OSCPR01MB15595 Content-Type: text/plain; charset="utf-8" PHCKSEL selects between MTCLKA-MTCLKB and MTCLKC-MTCLKD pins for the external input phase clock. PHCKSEL only affects the 16-bit count backed by MTU2 and the 32-bit count. Cache the value written to external_input_phase_clock_select and restore it on enable to bring the external_input_phase_clock_select sysfs entry in line with the other entries. Initialize the cached value to true, matching PHCKSEL's reset value so behavior is unchanged for a count that gets enabled without external_input_phase_clock_select being written explicitly. Always use the cached PHCKSEL value to remove the need to access registers while counts might not be enabled. Only restore it for the count backed by MTU2 as changing PHCKSEL for MTU1 does not affect the pins used for the external input phase clock. Check if any of these counts are enabled before writing the new PHCKSEL value. This prevents writing registers without actually owning the channel, as the busy check inside ch->is_busy can race with PWM operations. Since runtime PM is ensured to be resumed if the count is enabled, drop the pm_runtime_get_sync() and pm_runtime_put() calls. Signed-off-by: Cosmin Tanislav --- drivers/counter/rz-mtu3-cnt.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index 3e380f69cb45..a26b8b71c9a6 100644 --- a/drivers/counter/rz-mtu3-cnt.c +++ b/drivers/counter/rz-mtu3-cnt.c @@ -79,6 +79,7 @@ struct rz_mtu3_cnt { u32 count[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; u8 timer_mode[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; bool count_is_enabled[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; + bool mtclkc_mtclkd; }; =20 static const enum counter_function rz_mtu3_count_functions[] =3D { @@ -180,6 +181,12 @@ static void rz_mtu3_set_count(struct rz_mtu3_channel *= const ch, int id, rz_mtu3_16bit_ch_write(ch, RZ_MTU3_TCNT, count); } =20 +static void rz_mtu3_set_phcksel(struct rz_mtu3_channel *const ch, bool ena= ble) +{ + rz_mtu3_shared_reg_update_bit(ch, RZ_MTU3_TMDR3, RZ_MTU3_TMDR3_PHCKSEL, + enable); +} + static int rz_mtu3_count_read(struct counter_device *counter, struct counter_count *count, u64 *val) { @@ -388,6 +395,8 @@ static void rz_mtu3_32bit_cnt_setting(struct counter_de= vice *counter) struct rz_mtu3_channel *const ch2 =3D rz_mtu3_get_ch(counter, 1); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); =20 + rz_mtu3_set_phcksel(priv->ch, priv->mtclkc_mtclkd); + rz_mtu3_8bit_ch_write(ch1, RZ_MTU3_TMDR1, priv->timer_mode[RZ_MTU3_32_BIT_CH]); =20 @@ -407,6 +416,8 @@ static void rz_mtu3_16bit_cnt_setting(struct counter_de= vice *counter, int id) struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); =20 + if (id =3D=3D RZ_MTU3_16_BIT_MTU2_CH) + rz_mtu3_set_phcksel(priv->ch, priv->mtclkc_mtclkd); rz_mtu3_8bit_ch_write(ch, RZ_MTU3_TMDR1, priv->timer_mode[id]); rz_mtu3_set_ceiling(ch, id, priv->ceiling[id]); rz_mtu3_set_count(ch, id, priv->count[id]); @@ -569,17 +580,13 @@ static int rz_mtu3_ext_input_phase_clock_select_get(s= truct counter_device *count u32 *ext_input_phase_clock_select) { struct rz_mtu3_cnt *const priv =3D counter_priv(counter); - unsigned long tmdr; int ret; =20 ret =3D rz_mtu3_lock_if_ch0_is_enabled(priv); if (ret) return ret; =20 - pm_runtime_get_sync(counter->parent); - tmdr =3D rz_mtu3_shared_reg_read(priv->ch, RZ_MTU3_TMDR3); - pm_runtime_put(counter->parent); - *ext_input_phase_clock_select =3D test_bit(RZ_MTU3_TMDR3_PHCKSEL, &tmdr); + *ext_input_phase_clock_select =3D priv->mtclkc_mtclkd; mutex_unlock(&priv->lock); =20 return 0; @@ -595,11 +602,10 @@ static int rz_mtu3_ext_input_phase_clock_select_set(s= truct counter_device *count if (ret) return ret; =20 - pm_runtime_get_sync(counter->parent); - rz_mtu3_shared_reg_update_bit(priv->ch, RZ_MTU3_TMDR3, - RZ_MTU3_TMDR3_PHCKSEL, - ext_input_phase_clock_select); - pm_runtime_put(counter->parent); + if (priv->count_is_enabled[RZ_MTU3_16_BIT_MTU2_CH] || + priv->count_is_enabled[RZ_MTU3_32_BIT_CH]) + rz_mtu3_set_phcksel(priv->ch, ext_input_phase_clock_select); + priv->mtclkc_mtclkd =3D ext_input_phase_clock_select; mutex_unlock(&priv->lock); =20 return 0; @@ -629,8 +635,6 @@ static int rz_mtu3_action_read(struct counter_device *c= ounter, struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, count->id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); enum counter_function function; - bool mtclkc_mtclkd; - unsigned long tmdr; int ret; =20 ret =3D rz_mtu3_lock_if_count_is_enabled(ch, priv, count->id); @@ -647,10 +651,8 @@ static int rz_mtu3_action_read(struct counter_device *= counter, *action =3D COUNTER_SYNAPSE_ACTION_NONE; =20 if (count->id !=3D RZ_MTU3_16_BIT_MTU1_CH) { - tmdr =3D rz_mtu3_shared_reg_read(priv->ch, RZ_MTU3_TMDR3); - mtclkc_mtclkd =3D test_bit(RZ_MTU3_TMDR3_PHCKSEL, &tmdr); - if ((mtclkc_mtclkd && is_signal_ab) || - (!mtclkc_mtclkd && !is_signal_ab)) { + if ((priv->mtclkc_mtclkd && is_signal_ab) || + (!priv->mtclkc_mtclkd && !is_signal_ab)) { mutex_unlock(&priv->lock); return 0; } @@ -812,6 +814,7 @@ static int rz_mtu3_cnt_probe(struct platform_device *pd= ev) return -ENOMEM; =20 priv =3D counter_priv(counter); + priv->mtclkc_mtclkd =3D true; priv->ceiling[RZ_MTU3_16_BIT_MTU1_CH] =3D U16_MAX; priv->ceiling[RZ_MTU3_16_BIT_MTU2_CH] =3D U16_MAX; priv->ceiling[RZ_MTU3_32_BIT_CH] =3D U32_MAX; --=20 2.55.0 From nobody Fri Sep 25 09:22:49 2026 Received: from TY3P286CU002.outbound.protection.outlook.com (mail-japaneastazon11010008.outbound.protection.outlook.com [52.101.229.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1F904A0EFF; Mon, 14 Sep 2026 20:38:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.229.8 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418289; cv=fail; b=KnbKIS0iADqHziUO6ZGPi+8l+3/+I+IYzMfga3WZDIB20p59F3yj9btubIw7dSY+ARhrfqJ++f0XBFDzkNDu4U43ljzUhbaHC6pAOHmAP1JhagYFyxfWuFInDG+Q++BAwZcz1W8GMZD5dicdxvrEVLnKaIWgyEG0znqlDTwYQpk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418289; c=relaxed/simple; bh=v/ugR+pLVNXBj4P8Ao3JGpwG+MABQ+eoJrz+4UbrD9E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=p0n+5+c7XSyR0P82uHl9MHXnpEuDPhugkkYFgnLy4MG+R8esg8PLQkt4gRvGLOwJqr6+PKZ9otBW4dKixOU/e3WywKQ4zlgix/Onz6Yk5QVEJHq7DQ317EpWuqtKZ+BAgizw7Uou0zgMDimFmlBBbcTMXrbJF/YTGL0/+8KxaAc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=kjM9yFul; arc=fail smtp.client-ip=52.101.229.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="kjM9yFul" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=e4739iSnBii68W4KYtaBG7KDF7gJRAok3M/q8oSGXcLd8Cdfn0+tunW4kyuJDph5vCs4LChoGPCKtK64q34qcQCnaBO92xkBKC02TDs+icSPfQoYcp+2+d4UP6iRkOoRREJ8OOn53/JJu6LIuFBlWGrsMeihrYrThrJsZgfDVwP9bh1MXPAmosyk8osdc8ofsP/DuunS37khdn8M/UqI35CeNItBTxYBbU+7fkJP0N+aasqLYn4W5RXDbht096lb4hqR6BbpgBMtjIyEHFIoQr+MHW1hYfSyeoIqqTKdfoJ1tu1ctRfWKv/EDNHaSS1xfyh7ZY7BTpOv56zZheF9Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=JueEWBFVCj1ty0G5NFmocceViYfMGgByRrrUdGo3OAM=; b=KYjelrl88XghZl+5oMvgHF4rbwzVEZso+tqZkKv2d6PNtDTcSbEbctOdXcRDTGJ/PhAhvV5b+aquNpk6cRwsvbkVAU8NiXAPyR2vBWQpxUemIjm/ZfvucvroDqdGnZ5yVaZxUVaqotoruvndzIlSBO0W6rMLRcoZNmC5zjcGRIQGK+CUxBWSo2WiPj8FkW4cLKPHjgMVUrB0D8gZfucfxgcqz78yWqiz3sydqN03ffClsAUl65nMjnpc0cp5pAUZ7Gowt6J3a5arWjUvfZvs+iAZSZSbAyJUFkqVBntGXTwZNC/lfZKdPxiOmGga59UX//Dox0IALJWRkTvbeQkZcA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 8.62.32.50) smtp.rcpttodomain=bp.renesas.com smtp.mailfrom=renesas.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=renesas.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JueEWBFVCj1ty0G5NFmocceViYfMGgByRrrUdGo3OAM=; b=kjM9yFulIMxdbM4VKeVDmDrdcoalBQEwbZBd88QSh9KbAQqVLHzdWHYRb0wXa30+anMEwFwFFT+u9Irn+HqwmhBF+i7gZdj8UaHN7wYXPU15lt4z2T1QT2ou4a5baB6m56c9O1p6ZDwKbGV8tqtHJIPHfEaoap/tC1roKnGMyMQ= Received: from OSTP286CA0023.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:216::14) by TY4PR01MB17802.jpnprd01.prod.outlook.com (2603:1096:405:34d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Mon, 14 Sep 2026 20:38:02 +0000 Received: from OS1PEPF0000D210.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:216:cafe::90) by OSTP286CA0023.outlook.office365.com (2603:1096:604:216::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.13 via Frontend Transport; Mon, 14 Sep 2026 20:38:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 8.62.32.50) smtp.mailfrom=renesas.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=renesas.com; Received-SPF: Pass (protection.outlook.com: domain of renesas.com designates 8.62.32.50 as permitted sender) receiver=protection.outlook.com; client-ip=8.62.32.50; helo=ejcrelay004p.adwin.renesas.com; pr=E Received: from ejcrelay004p.adwin.renesas.com (8.62.32.50) by OS1PEPF0000D210.mail.protection.outlook.com (10.167.240.39) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Mon, 14 Sep 2026 20:38:02 +0000 Received: from demon-pc.localdomain (unknown [10.226.93.156]) by ejcrelay004p.adwin.renesas.com (Postfix) with ESMTP id C1D1B3000257; Tue, 15 Sep 2026 05:37:59 +0900 (JST) From: Cosmin Tanislav To: Biju Das , William Breathitt Gray , Lee Jones Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH 12/15] counter: rz-mtu3-cnt: cache direction values Date: Mon, 14 Sep 2026 23:36:11 +0300 Message-ID: <20260914203614.2035277-13-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS1PEPF0000D210:EE_|TY4PR01MB17802:EE_ X-MS-Office365-Filtering-Correlation-Id: dc1badd7-2e84-41af-1405-08df12a0129b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700016|376014|23010399003|1800799024|10067099003|56012099006|11063799006|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: wE6Sc1iqUlQZpnKsIPd65dNUFC8P0E+rJKs8mtOP2VrTYu1aEG+HF3uID9378Ou9gnhnVOvkRGeiY+9CwF3rzb9pSUyJVJgTZk8GEsEI95GPaupazmBkIgHGV/eZADyDezTeZHclAMj5EG2bUpuhoZ6RsENca+o/ThZezdbqpEwr1xgmbiERn8IocfUOgfcpOFAzyBdnnTtzQbuKhy9WADEVl0vFhIZGB638UJ9zCK576xRasak2M84Z72YBtSvQA6gsxRYqft5yc8AcfPeSS3ELMVk8/b/KLv4ygOikSm4IuO8og45YzOL1q/E7fq6d9KKi65G60h58GHsmFso5D+OqxWdA5Rv9XjPF31tQJr14tXYLDWIW8Q6eWNX0T5BbsecaCyGI9njCFRbam2qLgSNf4thkhPKD+Rf8yyj8t9FRyfoYmzRGBUyFcf5ADXHSCUbHlPL8bZDrUj9oRJ6MWp9h/hECtvSn+OwNflSu6R83leLWjjZ3GHWCvhJAelhBqAWknSST7J+1ZsuVnjVl0bqPAb2DSgToIWF/8btk66KuwNuWL4rHsr5X8m4Q22K8dO4iB2mEOxXKF8tehQkMar4Rje+gSryqzsMZfa7Fnl/a0KjiS5S7KK/Wf99h724Q14lf9x+ZU9OhkvQWNhSnRGVdGnqa/ir57vpG7wGZUBOQI7TsOXMH5MWOzg31n6UOu/2KVarOzH9WbEFx2UBN1w== X-Forefront-Antispam-Report: CIP:8.62.32.50;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ejcrelay004p.adwin.renesas.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700016)(376014)(23010399003)(1800799024)(10067099003)(56012099006)(11063799006)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 56gLi+PUmkbcv9T/tAJYuP3ExkgY5X7fzG1VlFBkPGpv/x4hWPhtXr0RUXt6BVBuKmxVLB7VLBG5ZN0DtBB1l+VJJ4+AqPIYMS/MZcR6CpKLp28dDymt+sxPFeOevu1kKDJ5uFOzyp9UqtwySObSFjWStgulzZRkElGo1vfvN0598Q+Bl9r69ugChZBkyI6e+FTBTaTVJ7NumPTOS0dCw9QZd+tug5RUxxXxr3Q+wDWw4OxdvEFO8wUAZWOr+bbGGPQL/GRioDgUfnQomVFDjHuhteln3ps1e7CED4dGyPwKC3zc7fG7W04BLEg+dPiBJtUuaj6GpUzBoEvZD8p4B2SA5G9iQLAz7dFeohtb7QweT2ztLbL8mozB4uEHqy3s3HX/ZEa2164RNL5E2YAbWx74E3c7tLIFFRwsAuH+a5Iyzg6/hAAOYFCdS2COUvPm X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2026 20:38:02.5481 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dc1badd7-2e84-41af-1405-08df12a0129b X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=53d82571-da19-47e4-9cb4-625a166a4a2a;Ip=[8.62.32.50];Helo=[ejcrelay004p.adwin.renesas.com] X-MS-Exchange-CrossTenant-AuthSource: OS1PEPF0000D210.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY4PR01MB17802 Content-Type: text/plain; charset="utf-8" Reading registers without the count being enabled is an issue as the ch->is_busy check inside rz_mtu3_lock_if_count_is_enabled() can race with PWM operations. Cache the direction value on every read and on disable, and return the cached value if the count is disabled. Since runtime PM is ensured to be resumed if the count is enabled, drop the pm_runtime_get_sync() and pm_runtime_put() calls. Signed-off-by: Cosmin Tanislav --- drivers/counter/rz-mtu3-cnt.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index a26b8b71c9a6..5fd12941df4c 100644 --- a/drivers/counter/rz-mtu3-cnt.c +++ b/drivers/counter/rz-mtu3-cnt.c @@ -79,6 +79,7 @@ struct rz_mtu3_cnt { u32 count[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; u8 timer_mode[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; bool count_is_enabled[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; + bool direction[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; bool mtclkc_mtclkd; }; =20 @@ -187,6 +188,13 @@ static void rz_mtu3_set_phcksel(struct rz_mtu3_channel= *const ch, bool enable) enable); } =20 +static bool rz_mtu3_get_direction(struct rz_mtu3_channel *const ch) +{ + u8 tsr =3D rz_mtu3_8bit_ch_read(ch, RZ_MTU3_TSR); + + return !!(tsr & RZ_MTU3_TSR_TCFD); +} + static int rz_mtu3_count_read(struct counter_device *counter, struct counter_count *count, u64 *val) { @@ -315,18 +323,17 @@ static int rz_mtu3_count_direction_read(struct counte= r_device *counter, struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, count->id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); int ret; - u8 tsr; =20 ret =3D rz_mtu3_lock_if_count_is_enabled(ch, priv, count->id); if (ret) return ret; =20 - pm_runtime_get_sync(counter->parent); - tsr =3D rz_mtu3_8bit_ch_read(ch, RZ_MTU3_TSR); - pm_runtime_put(counter->parent); + if (priv->count_is_enabled[count->id]) + priv->direction[count->id] =3D rz_mtu3_get_direction(ch); =20 - *direction =3D (tsr & RZ_MTU3_TSR_TCFD) ? + *direction =3D priv->direction[count->id] ? COUNTER_COUNT_DIRECTION_FORWARD : COUNTER_COUNT_DIRECTION_BACKWARD; + mutex_unlock(&priv->lock); =20 return 0; @@ -469,6 +476,7 @@ static void rz_mtu3_terminate_counter(struct counter_de= vice *counter, int id) struct rz_mtu3_cnt *const priv =3D counter_priv(counter); =20 priv->count[id] =3D rz_mtu3_get_count(ch, id); + priv->direction[id] =3D rz_mtu3_get_direction(ch); =20 if (id =3D=3D RZ_MTU3_32_BIT_CH) { rz_mtu3_disable(ch2); --=20 2.55.0 From nobody Fri Sep 25 09:22:49 2026 Received: from TY3P286CU002.outbound.protection.outlook.com (mail-japaneastazon11010067.outbound.protection.outlook.com [52.101.229.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CEB04A091B; Mon, 14 Sep 2026 20:38:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.229.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418294; cv=fail; b=Z7LvRcdHxS/FvMe2A+ZCASzOvrGQsB6U0WR8C7rZQxSlt9+G+F46sYef3dBK9G+9kHrzYKkr4YtHscRdLVKvKgNQ6EJEZs3RkpxEdSPFrDOAXOFDswAY53AmnWyHwFFPg6kHMrOOJkxi4P26e/fngpsJr4zXHZbYw7IWkqWMSXM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418294; c=relaxed/simple; bh=Riiw9jg7Nes+cJGTim5Do3shbLmqCCdrxW9KDla95xY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AjJCL615iDT/2XhR1y0MYeKDA2w9AJWjjMkd250wGS90H2T7Da0PmQ3XIJo9XzFtDXlaIWy+uHZlLoecInOixzzNPK9uxSBXvu9twEovp+ULVnzNddxWoOTFzJJv6TEckLZHHivKtVoT75Oibu/CdxGPKwsPAnLE5GHUe5rjfZI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=anxh9xg9; arc=fail smtp.client-ip=52.101.229.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="anxh9xg9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=c4PoEu8EtTr5y0GQWuxVmA8um23a97Dl/QSxYKQhFyH14ccGXs6T9/Vyjt/8rtF1lw/0N6JMtGq+EDwZtcg2QSAdxFFeUAtYVHtGwUMyP6TPm/H3iur1yxVF5ERPKIS33NWIYCePp4vUdOT4ps6DEwaA1pZe5SgjP8/Vg2q4Dufa5u97hcsBSODFrmkdwW2kR21urorZehjLfj6PLxwuk5tx80ijdU6/ffxJdZXfprIfbH4mgmItMDOwjb4b+r9d6KjMrpiAFmpowkXfiM5Lyo6V1SaCPgyAOWddLjHsKRllq+n1uh4NQIZy6W1SO1ecKOrGZAU66VcIneMG4xytkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=m9Ae2rIZbL70OsnZKz8mxni2punQpG9eHARa4f6SbZA=; b=LGwjx+eAQ47Hgymi8CwFEgK4ud0bYhLvqIkFJkMn//5+bLM0AMdQquFJjy22pTnUbKdC7/jfsX9Jqh/jt3XxoYMV5mbHLQvXFHR04Yvoqf9DqMllQE+HE8OOzsxAZ7q6cwRE8lLZfH6kOzA9XYLh9DgBIhVI4dypDqAby76DAkRh+3PqsUtMbYfXtPuin1vPyfjYrctRrYrpiGg3D8aHbTE1/mgV0I70LaAmL6zEtIs7vvnzEYMmt/B9OOlGro+FBumYffOmuFT8E1WqWkG/kxEnY2s6H3nHvzxyCNHEMuqxVocjYhGyJ+vDfQnMTiN4/fmVEkG1GEBzhokNape4Ew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 8.62.32.50) smtp.rcpttodomain=bp.renesas.com smtp.mailfrom=renesas.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=renesas.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=m9Ae2rIZbL70OsnZKz8mxni2punQpG9eHARa4f6SbZA=; b=anxh9xg9W3a0ryCbgXGqb9DmFdXVHJzlJi1z3oclROAs3Xung/WmT5IeWKSqnFTJYMp/yxk816SC+XX3ZtnR/QtBmnsd2IJOKOEkcYKFnS0Cea0+QWyEM64GrNCkBFxY2pPgSTRPMMUfA+UN88BbG4k7K7MvL0oj8DdfCLWEhNQ= Received: from TYWP286CA0003.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:178::22) by OS9PR01MB17219.jpnprd01.prod.outlook.com (2603:1096:604:40d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Mon, 14 Sep 2026 20:38:06 +0000 Received: from TYO1EPF00005025.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:178:cafe::9b) by TYWP286CA0003.outlook.office365.com (2603:1096:400:178::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.12 via Frontend Transport; Mon, 14 Sep 2026 20:38:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 8.62.32.50) smtp.mailfrom=renesas.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=renesas.com; Received-SPF: Pass (protection.outlook.com: domain of renesas.com designates 8.62.32.50 as permitted sender) receiver=protection.outlook.com; client-ip=8.62.32.50; helo=ejcrelay004p.adwin.renesas.com; pr=E Received: from ejcrelay004p.adwin.renesas.com (8.62.32.50) by TYO1EPF00005025.mail.protection.outlook.com (10.167.240.22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Mon, 14 Sep 2026 20:38:06 +0000 Received: from demon-pc.localdomain (unknown [10.226.93.156]) by ejcrelay004p.adwin.renesas.com (Postfix) with ESMTP id 24EE13000257; Tue, 15 Sep 2026 05:38:03 +0900 (JST) From: Cosmin Tanislav To: Biju Das , William Breathitt Gray , Lee Jones Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH 13/15] counter: rz-mtu3-cnt: keep cascade_counts_enable in sync with usage Date: Mon, 14 Sep 2026 23:36:12 +0300 Message-ID: <20260914203614.2035277-14-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYO1EPF00005025:EE_|OS9PR01MB17219:EE_ X-MS-Office365-Filtering-Correlation-Id: 522b1287-6671-416c-b956-08df12a01511 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|376014|1800799024|82310400026|36860700016|6133799003|22082099003|18002099003|10067099003|11063799006|56012099006; X-Microsoft-Antispam-Message-Info: BtDyk5pxcMe+Lrb/JoJUMctRuQw/gZnd0LmA9f1GQNzS1/cpO1vVFa3IzGZhEnBj59D0gOZBWiJfvWOj7LwJfw4DnWO9VrBbWG0ghoa2fTI2L0psDSx7T4xz/P/8cYXMGY7INCH9UccIpWJL2qiV3h2ZN1bQqBlhpv6332eFXszhk7sVTqTwznk7wPNpZm9HSWuwQtKbWK2+zHSMaKvDqD+7mDvv0Tz80KjTgmgNH1ypmkko2kEsYmHc2B3DdAXzNSuSHESCE+LeaO+J441SJILhgr4Vas1ss983Y/BHInbNV4G1FGx5G0JBeH2CMk+swFSLRoupVOakgRdAoFNC4WcnGcQkOB/4hNzOqxIzKi4UfGrChWIP0OALc6Smbbw0gTJqbZJBJPNwqHYv/sYhyjCl+aG7+veCYEvXW1jeHsSduW8JtxNkU6M/GzoXZpLthA/ze/myZkBNI3q7H7Cggw564ZzNRbg6NXLHPtHf+J4EsTufIC4IK5+4eKDHsN/atR5UJ0uZVMuX5WTpj3vznkOP66zQYUcoyqlEBgTHVUNcv+9cj6wc8cgQNE2nSdl4WS9z6bbV7iiefc93UGz2VDlU2p+WK4V6lvxFqLo3Vr4qGHADtaVYqrarLpYC9eS/lTgOAsRE8vIklaN0Vg83iHs60HpbPsstYUiE+MATvZUxmq98nnmg+Dt+kd9oG7p2 X-Forefront-Antispam-Report: CIP:8.62.32.50;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ejcrelay004p.adwin.renesas.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(23010399003)(376014)(1800799024)(82310400026)(36860700016)(6133799003)(22082099003)(18002099003)(10067099003)(11063799006)(56012099006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0/J+j0V7KiGzxvYDXbjTXdhSqkRw1SfI31+noEz0KZJVlyhzN3lSYtnL54tiL4k2KDnV887L7IlXD8zt57gxBS+aB4bBaq+cvIpJjcwkh+oXod146/Z8trfdMmaAaB/MZKOfISzkvbDZiLbWfgYVU5I8J6DWidmD4CDcsiS7LQH/FAwadpLGYvqHRLjVIIQ6UrjrBFYYpfE5fmpcnLdATOhG0I7RJjP+CPu6g+lr8cVhDjeQkK0helQRJfTEnqkW2ONMNPT65xX1AIlkCg9uP8+O1BJeLDva0IRMznAGp353lENWuX2Lt8Lhb+5AuOR3yP2J4bp09sKMdxkC2K46vWMicj8wHRNMKDkBGxopeLNUv0uXwkeKlAkwEUGWPLTyneazQMcovDTEIgJsN/S1zOzhA5oN1WOB96O4kMTsCxsOPBJjD6hqVSaVqNtr844g X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2026 20:38:06.6952 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 522b1287-6671-416c-b956-08df12a01511 X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=53d82571-da19-47e4-9cb4-625a166a4a2a;Ip=[8.62.32.50];Helo=[ejcrelay004p.adwin.renesas.com] X-MS-Exchange-CrossTenant-AuthSource: TYO1EPF00005025.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS9PR01MB17219 Content-Type: text/plain; charset="utf-8" LWA is enabled/disabled by writing 1/0 to the cascade_counts_enable sysfs entry. The 32-bit channel cannot function without LWA being enabled, and the 16-bit channels cannot function with LWA enabled. PWM mode cannot function with LWA enabled. It is possible to accidentally leave LWA enabled while trying to use PWM mode, leading to unintended access to the TGRA or TGRB registers of MTU1 and MTU2, which should not be accessed while LWA is enabled. It is also possible to toggle LWA while PWM is enabled on MTU2, as the checks inside rz_mtu3_lock_if_ch0_is_enabled() do not check if MTU2 is busy, even if this setting affects MTU2. To handle this, write 1 to the LWA bit when enabling the 32-bit channel, and automatically write 0 to it when disabling the 32-bit channel, to ensure that LWA is always in the correct state for any possible usage. Remove rz_mtu3_is_counter_invalid() checks as it is now guaranteed that LWA has the proper value if a count is enabled. Keep the cascade_counts_enable sysfs entry for ABI compatibility. Signed-off-by: Cosmin Tanislav --- drivers/counter/rz-mtu3-cnt.c | 94 +++++++---------------------------- 1 file changed, 17 insertions(+), 77 deletions(-) diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index 5fd12941df4c..d519e6ab56ee 100644 --- a/drivers/counter/rz-mtu3-cnt.c +++ b/drivers/counter/rz-mtu3-cnt.c @@ -81,6 +81,7 @@ struct rz_mtu3_cnt { bool count_is_enabled[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; bool direction[RZ_MTU3_MAX_LOGICAL_CNTR_CHANNELS]; bool mtclkc_mtclkd; + bool cascade_enable; }; =20 static const enum counter_function rz_mtu3_count_functions[] =3D { @@ -102,44 +103,6 @@ static inline struct rz_mtu3_channel *rz_mtu3_get_ch(s= truct counter_device *coun return &priv->ch[ch_id]; } =20 -static bool rz_mtu3_is_counter_invalid(struct counter_device *counter, int= id) -{ - struct rz_mtu3_cnt *const priv =3D counter_priv(counter); - unsigned long tmdr; - - pm_runtime_get_sync(counter->parent); - tmdr =3D rz_mtu3_shared_reg_read(priv->ch, RZ_MTU3_TMDR3); - pm_runtime_put(counter->parent); - - if (id =3D=3D RZ_MTU3_32_BIT_CH && test_bit(RZ_MTU3_TMDR3_LWA, &tmdr)) - return false; - - if (id !=3D RZ_MTU3_32_BIT_CH && !test_bit(RZ_MTU3_TMDR3_LWA, &tmdr)) - return false; - - return true; -} - -static int rz_mtu3_lock_if_counter_is_valid(struct counter_device *counter, - struct rz_mtu3_channel *const ch, - struct rz_mtu3_cnt *const priv, - int id) -{ - mutex_lock(&priv->lock); - - if (ch->is_busy && !priv->count_is_enabled[id]) { - mutex_unlock(&priv->lock); - return -EINVAL; - } - - if (rz_mtu3_is_counter_invalid(counter, id)) { - mutex_unlock(&priv->lock); - return -EBUSY; - } - - return 0; -} - static int rz_mtu3_lock_if_count_is_enabled(struct rz_mtu3_channel *const = ch, struct rz_mtu3_cnt *const priv, int id) @@ -195,17 +158,19 @@ static bool rz_mtu3_get_direction(struct rz_mtu3_chan= nel *const ch) return !!(tsr & RZ_MTU3_TSR_TCFD); } =20 +static void rz_mtu3_set_lwa(struct rz_mtu3_channel *const ch, bool enable) +{ + rz_mtu3_shared_reg_update_bit(ch, RZ_MTU3_TMDR3, RZ_MTU3_TMDR3_LWA, + enable); +} + static int rz_mtu3_count_read(struct counter_device *counter, struct counter_count *count, u64 *val) { struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, count->id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); - int ret; - - ret =3D rz_mtu3_lock_if_counter_is_valid(counter, ch, priv, count->id); - if (ret) - return ret; =20 + mutex_lock(&priv->lock); if (priv->count_is_enabled[count->id]) priv->count[count->id] =3D rz_mtu3_get_count(ch, count->id); *val =3D priv->count[count->id]; @@ -219,12 +184,8 @@ static int rz_mtu3_count_write(struct counter_device *= counter, { struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, count->id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); - int ret; - - ret =3D rz_mtu3_lock_if_counter_is_valid(counter, ch, priv, count->id); - if (ret) - return ret; =20 + mutex_lock(&priv->lock); if (priv->count_is_enabled[count->id]) rz_mtu3_set_count(ch, count->id, val); priv->count[count->id] =3D val; @@ -343,14 +304,9 @@ static int rz_mtu3_count_ceiling_read(struct counter_d= evice *counter, struct counter_count *count, u64 *ceiling) { - struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, count->id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); - int ret; - - ret =3D rz_mtu3_lock_if_counter_is_valid(counter, ch, priv, count->id); - if (ret) - return ret; =20 + mutex_lock(&priv->lock); *ceiling =3D priv->ceiling[count->id]; mutex_unlock(&priv->lock); return 0; @@ -362,11 +318,8 @@ static int rz_mtu3_count_ceiling_write(struct counter_= device *counter, { struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, count->id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); - int ret; =20 - ret =3D rz_mtu3_lock_if_counter_is_valid(counter, ch, priv, count->id); - if (ret) - return ret; + mutex_lock(&priv->lock); =20 switch (count->id) { case RZ_MTU3_16_BIT_MTU1_CH: @@ -403,6 +356,7 @@ static void rz_mtu3_32bit_cnt_setting(struct counter_de= vice *counter) struct rz_mtu3_cnt *const priv =3D counter_priv(counter); =20 rz_mtu3_set_phcksel(priv->ch, priv->mtclkc_mtclkd); + rz_mtu3_set_lwa(ch1, true); =20 rz_mtu3_8bit_ch_write(ch1, RZ_MTU3_TMDR1, priv->timer_mode[RZ_MTU3_32_BIT_CH]); @@ -479,6 +433,7 @@ static void rz_mtu3_terminate_counter(struct counter_de= vice *counter, int id) priv->direction[id] =3D rz_mtu3_get_direction(ch); =20 if (id =3D=3D RZ_MTU3_32_BIT_CH) { + rz_mtu3_set_lwa(ch1, false); rz_mtu3_disable(ch2); rz_mtu3_disable(ch1); rz_mtu3_release_channel(ch2); @@ -549,17 +504,9 @@ static int rz_mtu3_cascade_counts_enable_get(struct co= unter_device *counter, u8 *cascade_enable) { struct rz_mtu3_cnt *const priv =3D counter_priv(counter); - unsigned long tmdr; - int ret; =20 - ret =3D rz_mtu3_lock_if_ch0_is_enabled(priv); - if (ret) - return ret; - - pm_runtime_get_sync(counter->parent); - tmdr =3D rz_mtu3_shared_reg_read(priv->ch, RZ_MTU3_TMDR3); - pm_runtime_put(counter->parent); - *cascade_enable =3D test_bit(RZ_MTU3_TMDR3_LWA, &tmdr); + mutex_lock(&priv->lock); + *cascade_enable =3D priv->cascade_enable; mutex_unlock(&priv->lock); =20 return 0; @@ -569,16 +516,9 @@ static int rz_mtu3_cascade_counts_enable_set(struct co= unter_device *counter, u8 cascade_enable) { struct rz_mtu3_cnt *const priv =3D counter_priv(counter); - int ret; =20 - ret =3D rz_mtu3_lock_if_ch0_is_enabled(priv); - if (ret) - return ret; - - pm_runtime_get_sync(counter->parent); - rz_mtu3_shared_reg_update_bit(priv->ch, RZ_MTU3_TMDR3, - RZ_MTU3_TMDR3_LWA, cascade_enable); - pm_runtime_put(counter->parent); + mutex_lock(&priv->lock); + priv->cascade_enable =3D cascade_enable; mutex_unlock(&priv->lock); =20 return 0; --=20 2.55.0 From nobody Fri Sep 25 09:22:49 2026 Received: from TYVP286CU001.outbound.protection.outlook.com (mail-japaneastazon11011011.outbound.protection.outlook.com [52.101.125.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2C144A0148; Mon, 14 Sep 2026 20:38:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.125.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418298; cv=fail; b=drzDIXRZQRv5+IPIpmh1Tojn5+4tJFVI8/bWuUVJspYLdnseH5tYYjZRMavpucQwk4lHLq7iwD66C8kA++jkgedDu2HBieu6kSaIWA8A8l+COL0xVDR/n5aOKbQi0JL+5tAPhbYmyENGd6iztCBCtydhCroXol94VSb1aO+zm9s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418298; c=relaxed/simple; bh=TAa68+yZZ0yBtDZW1vjvdGpAsW8JtOwCn7ydzJqpiCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iHWGhuJSL+zvtSS4EAF8cH1mbH07SiXGFqNBnLeMsoU5iKhePmvlFTsyGjwdJiwdZmCexJmSSwFUWqFdsxWTt7pe8DQBPkwd/ksbqVP0UeX45+M0p9P9bmdoNPhOZ9RW19OEq67eemD4jnopPCf+88XChoupCfi9xFqd/XkcOac= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=Cp9sShxX; arc=fail smtp.client-ip=52.101.125.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="Cp9sShxX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VQ+MTqUy6YJBG6Y/NGYrYOK6cX/ULnPwPCEHFWUt8eZBFFf3GkwlzR4kwQ9IdrO+Ehjlt0bsXSfw0/c3wVk9fmqtP0bs9wPkOi9NBhL9LF+0kw9D7/h7mIBSD7rMve67NlVIyDoEmSfxv8M/fkD9/D9NmNtYoz04bjeh0wqHgSVNpeF3VcBJ3troshSP4q4c81bLf82dgGMDynSsgN/qvuwlrJHgCra4tNO1FLqSYJ039zGIbgPlgwujiFVzYhVrnQs37wk4SAlmfDA2gp2kpe0ygQzjqC21mf9ULfzkzGVQDBDKSUZNk11DPxnGtLSOLZJO06pQO/SQLm6vnUIFqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=RKPDZfcDX6Mg1nyNIFBtM18dkeRDl8mTVlQD2BJBTUs=; b=X77cl/BGJ2D4kMmPcvh/mVk+ni6TUWB78nbK2MXccTb7lhwPCtDq87TbQiLQWejvC8hhvogmeAlwEkBoUdyf3dXY5dclp5kjuwWRPbTpYXC9/tmfMKV0v3Mk487w4fjVx7oktOk6SQuHJoudBSI0WZEu3EzzHTerIdOXHu0VbF48wH5tllqoLYoXrogTlAwd93AbjlcZchmc/yy3KqAsRjaf2JX/77/5flPMA8yCmtTywFKkZUhzghGbpWDRkiu68sjWJy5ZUJB6Pi/b3VvIqegrAlgqmv368yhx9aQWwNGqiTFNZuca5k9Qsnlj8cyxPAkxLKl992m5WCed7gY10w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 8.62.32.50) smtp.rcpttodomain=bp.renesas.com smtp.mailfrom=renesas.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=renesas.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RKPDZfcDX6Mg1nyNIFBtM18dkeRDl8mTVlQD2BJBTUs=; b=Cp9sShxX8iEo9o7UDAI9pTumYKt12Ju3CrraZFHVCXs2ra0Ipy1uFnDLM3XE0NhtnBVUWW2FyiHmmWLlS322MxtWkZ9dStENjDLPRIlEI4OvnzMJR6urGybzL+YjkrQuBca/TV26sT30CXvx+IeOTU6H8YMp+3vbwkpGpRoq3Pc= Received: from TYWP286CA0007.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:178::15) by TYYPR01MB14100.jpnprd01.prod.outlook.com (2603:1096:405:213::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Mon, 14 Sep 2026 20:38:10 +0000 Received: from TYO1EPF00005025.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:178:cafe::6c) by TYWP286CA0007.outlook.office365.com (2603:1096:400:178::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.12 via Frontend Transport; Mon, 14 Sep 2026 20:38:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 8.62.32.50) smtp.mailfrom=renesas.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=renesas.com; Received-SPF: Pass (protection.outlook.com: domain of renesas.com designates 8.62.32.50 as permitted sender) receiver=protection.outlook.com; client-ip=8.62.32.50; helo=ejcrelay004p.adwin.renesas.com; pr=E Received: from ejcrelay004p.adwin.renesas.com (8.62.32.50) by TYO1EPF00005025.mail.protection.outlook.com (10.167.240.22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Mon, 14 Sep 2026 20:38:10 +0000 Received: from demon-pc.localdomain (unknown [10.226.93.156]) by ejcrelay004p.adwin.renesas.com (Postfix) with ESMTP id 3C3453000476; Tue, 15 Sep 2026 05:38:07 +0900 (JST) From: Cosmin Tanislav To: Biju Das , William Breathitt Gray , Lee Jones Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH 14/15] counter: rz-mtu3-cnt: drop conditional locks Date: Mon, 14 Sep 2026 23:36:13 +0300 Message-ID: <20260914203614.2035277-15-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYO1EPF00005025:EE_|TYYPR01MB14100:EE_ X-MS-Office365-Filtering-Correlation-Id: 032d031a-264d-4e40-c5b5-08df12a01787 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|23010399003|376014|36860700016|10067099003|6133799003|18002099003|22082099003|56012099006|11063799006; X-Microsoft-Antispam-Message-Info: 2tqHJOwwG+oIxrU5dKR/snOFiFrnHCCa1VBgtDuxfRnw8bDadO2GMn6HJMW04n5NMG3nZTbhaat0qjvzu+NPai1zkmh/ldkvweyQe1e/EahSrwzlFDTt57oZRPmQSOjAj6V3LIo1m7wtmSbMlBSlLc3mokbNzjDGHTnd/KKnudLDcvuZAqWh07FApwkWLEhTTBH/6JkNz5BbtOLoKh4geebmv5jbNO/8mRZ8Kbj+kaZ5Lt2enG2Dse3gPbZ2Y2ErkVawV5V+MQOvet7G6mTYDL4f3QojKHP3ajZ1JkdAe+8mQ5zZwgjcm0mA0REYN6YryrHInr1+4pM64HSzbLIWJ+RbxuIfjonLfMz8eKwehZZGQ5t5eKg/EyIEweKkqwTWqt2w1yRXGFqKp/W7B2l5HNsC2xlr/Ji0VzFSRJb5TMOtKTDH92bY1ZnU9KqtVR74LZU8hkeULqIRmp3W+EvMj8h4afsfea6SfTm/Eku6eAfjWwcHAyESFRiafgMGlwuz9hdSOMfOVdiR1y4HXdA8SXSJxDgX72amgQrtS5mty+0CwtsLyudB9KuUbj2Swg5EPOBmYS1+R4wdMOOLYHzGD0rKafsq646gkoqW5spbvmt0Kq5SIKivUrDoX/ts0OnjWXYzWTGiM5fCZNp2fO4s5xXWOsoyiz92XntTxIJXdytw0QFJ3QIuKaX/wE08c3kNLuqGZU3OemEUO/2BmVE94w== X-Forefront-Antispam-Report: CIP:8.62.32.50;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ejcrelay004p.adwin.renesas.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(23010399003)(376014)(36860700016)(10067099003)(6133799003)(18002099003)(22082099003)(56012099006)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: oltx1MbNKPhVkhoEAcjnYDJmgOjjfkZuLFweA6Qu4Pa9GPyUKEV6Og6/Ek4c8CKuTwjgf197mYFIk6S4NvYbgi/2nrndvzAhnV7z91WzFt2IFeg6GlEAVrF3K2qjOVbDPwThkqXnpsgpsiZ5SMFySK4erm4M3Hyh/fbElc2sgM2g80p6Fryu6mCqkuM2EcB422jENl85Yk9xwQ9h4m7FjW76bijCC8QNLb1qwMH/E1eOH3K1BeyeHc4QQvDo4uoAbvCWiMT72RJqY/2k3vEMYyxt6j3C5ILtZ0MdJ3w/c3PbXns6m45GoeedMCl37DpM22QIICIj8Ug9fqrMf2O+AHx78+5Rs181veF2ufoHvUJ2TXuRbl4XhLgAB8+bPyhO01XeFpttPwIklEnTlcJTaUk6qQLQJsi8493F0AuWUoMzo3gPbh+Qy1Hge0OhZwp4 X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2026 20:38:10.8234 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 032d031a-264d-4e40-c5b5-08df12a01787 X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=53d82571-da19-47e4-9cb4-625a166a4a2a;Ip=[8.62.32.50];Helo=[ejcrelay004p.adwin.renesas.com] X-MS-Exchange-CrossTenant-AuthSource: TYO1EPF00005025.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYYPR01MB14100 Content-Type: text/plain; charset="utf-8" All read and write operations now only access the hardware if the respective count is enabled. As a count cannot be enabled without the underlying MTU channel(s) being claimed as busy by the count driver, drop conditional locks and replace them with simple locks. Use guard() where possible. Remove the conditional locking functions as there are no users left. Signed-off-by: Cosmin Tanislav --- drivers/counter/rz-mtu3-cnt.c | 120 ++++++++-------------------------- 1 file changed, 26 insertions(+), 94 deletions(-) diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index d519e6ab56ee..f3e8fe5cb818 100644 --- a/drivers/counter/rz-mtu3-cnt.c +++ b/drivers/counter/rz-mtu3-cnt.c @@ -103,20 +103,6 @@ static inline struct rz_mtu3_channel *rz_mtu3_get_ch(s= truct counter_device *coun return &priv->ch[ch_id]; } =20 -static int rz_mtu3_lock_if_count_is_enabled(struct rz_mtu3_channel *const = ch, - struct rz_mtu3_cnt *const priv, - int id) -{ - mutex_lock(&priv->lock); - - if (ch->is_busy && !priv->count_is_enabled[id]) { - mutex_unlock(&priv->lock); - return -EINVAL; - } - - return 0; -} - static void rz_mtu3_set_ceiling(struct rz_mtu3_channel *const ch, int id, u64 ceiling) { @@ -170,11 +156,11 @@ static int rz_mtu3_count_read(struct counter_device *= counter, struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, count->id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); =20 - mutex_lock(&priv->lock); + guard(mutex)(&priv->lock); + if (priv->count_is_enabled[count->id]) priv->count[count->id] =3D rz_mtu3_get_count(ch, count->id); *val =3D priv->count[count->id]; - mutex_unlock(&priv->lock); =20 return 0; } @@ -185,11 +171,11 @@ static int rz_mtu3_count_write(struct counter_device = *counter, struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, count->id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); =20 - mutex_lock(&priv->lock); + guard(mutex)(&priv->lock); + if (priv->count_is_enabled[count->id]) rz_mtu3_set_count(ch, count->id, val); priv->count[count->id] =3D val; - mutex_unlock(&priv->lock); =20 return 0; } @@ -222,18 +208,11 @@ static int rz_mtu3_count_function_read(struct counter= _device *counter, struct counter_count *count, enum counter_function *function) { - struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, count->id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); - int ret; =20 - ret =3D rz_mtu3_lock_if_count_is_enabled(ch, priv, count->id); - if (ret) - return ret; + guard(mutex)(&priv->lock); =20 - ret =3D rz_mtu3_count_function_read_helper(priv, count->id, function); - mutex_unlock(&priv->lock); - - return ret; + return rz_mtu3_count_function_read_helper(priv, count->id, function); } =20 static int rz_mtu3_count_function_write(struct counter_device *counter, @@ -243,11 +222,6 @@ static int rz_mtu3_count_function_write(struct counter= _device *counter, struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, count->id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); u8 timer_mode; - int ret; - - ret =3D rz_mtu3_lock_if_count_is_enabled(ch, priv, count->id); - if (ret) - return ret; =20 switch (function) { case COUNTER_FUNCTION_QUADRATURE_X4: @@ -265,14 +239,14 @@ static int rz_mtu3_count_function_write(struct counte= r_device *counter, * - need to add RZ_MTU3_TMDR1_PH_CNT_MODE_3 * - need to add RZ_MTU3_TMDR1_PH_CNT_MODE_5 */ - mutex_unlock(&priv->lock); return -EINVAL; } =20 + guard(mutex)(&priv->lock); + if (priv->count_is_enabled[count->id]) rz_mtu3_8bit_ch_write(ch, RZ_MTU3_TMDR1, timer_mode); priv->timer_mode[count->id] =3D timer_mode; - mutex_unlock(&priv->lock); =20 return 0; } @@ -283,11 +257,8 @@ static int rz_mtu3_count_direction_read(struct counter= _device *counter, { struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, count->id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); - int ret; =20 - ret =3D rz_mtu3_lock_if_count_is_enabled(ch, priv, count->id); - if (ret) - return ret; + guard(mutex)(&priv->lock); =20 if (priv->count_is_enabled[count->id]) priv->direction[count->id] =3D rz_mtu3_get_direction(ch); @@ -295,8 +266,6 @@ static int rz_mtu3_count_direction_read(struct counter_= device *counter, *direction =3D priv->direction[count->id] ? COUNTER_COUNT_DIRECTION_FORWARD : COUNTER_COUNT_DIRECTION_BACKWARD; =20 - mutex_unlock(&priv->lock); - return 0; } =20 @@ -306,9 +275,9 @@ static int rz_mtu3_count_ceiling_read(struct counter_de= vice *counter, { struct rz_mtu3_cnt *const priv =3D counter_priv(counter); =20 - mutex_lock(&priv->lock); + guard(mutex)(&priv->lock); *ceiling =3D priv->ceiling[count->id]; - mutex_unlock(&priv->lock); + return 0; } =20 @@ -319,32 +288,26 @@ static int rz_mtu3_count_ceiling_write(struct counter= _device *counter, struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, count->id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); =20 - mutex_lock(&priv->lock); - switch (count->id) { case RZ_MTU3_16_BIT_MTU1_CH: case RZ_MTU3_16_BIT_MTU2_CH: - if (ceiling > U16_MAX) { - mutex_unlock(&priv->lock); + if (ceiling > U16_MAX) return -ERANGE; - } break; case RZ_MTU3_32_BIT_CH: - if (ceiling > U32_MAX) { - mutex_unlock(&priv->lock); + if (ceiling > U32_MAX) return -ERANGE; - } break; default: /* should never reach this path */ - mutex_unlock(&priv->lock); return -EINVAL; } =20 + guard(mutex)(&priv->lock); + if (priv->count_is_enabled[count->id]) rz_mtu3_set_ceiling(ch, count->id, ceiling); priv->ceiling[count->id] =3D ceiling; - mutex_unlock(&priv->lock); =20 return 0; } @@ -449,9 +412,8 @@ static int rz_mtu3_count_enable_read(struct counter_dev= ice *counter, { struct rz_mtu3_cnt *const priv =3D counter_priv(counter); =20 - mutex_lock(&priv->lock); + guard(mutex)(&priv->lock); *enable =3D priv->count_is_enabled[count->id]; - mutex_unlock(&priv->lock); =20 return 0; } @@ -462,17 +424,17 @@ static int rz_mtu3_count_enable_write(struct counter_= device *counter, struct rz_mtu3_cnt *const priv =3D counter_priv(counter); int ret =3D 0; =20 - mutex_lock(&priv->lock); + guard(mutex)(&priv->lock); =20 if (priv->count_is_enabled[count->id] =3D=3D enable) - goto exit; + return 0; =20 if (enable) { pm_runtime_get_sync(counter->parent); ret =3D rz_mtu3_initialize_counter(counter, count->id); if (ret) { pm_runtime_put(counter->parent); - goto exit; + return ret; } =20 priv->count_is_enabled[count->id] =3D true; @@ -482,32 +444,16 @@ static int rz_mtu3_count_enable_write(struct counter_= device *counter, pm_runtime_put(counter->parent); } =20 -exit: - mutex_unlock(&priv->lock); - return ret; } =20 -static int rz_mtu3_lock_if_ch0_is_enabled(struct rz_mtu3_cnt *const priv) -{ - mutex_lock(&priv->lock); - if (priv->ch->is_busy && !(priv->count_is_enabled[RZ_MTU3_16_BIT_MTU1_CH]= || - priv->count_is_enabled[RZ_MTU3_32_BIT_CH])) { - mutex_unlock(&priv->lock); - return -EINVAL; - } - - return 0; -} - static int rz_mtu3_cascade_counts_enable_get(struct counter_device *counte= r, u8 *cascade_enable) { struct rz_mtu3_cnt *const priv =3D counter_priv(counter); =20 - mutex_lock(&priv->lock); + guard(mutex)(&priv->lock); *cascade_enable =3D priv->cascade_enable; - mutex_unlock(&priv->lock); =20 return 0; } @@ -517,9 +463,8 @@ static int rz_mtu3_cascade_counts_enable_set(struct cou= nter_device *counter, { struct rz_mtu3_cnt *const priv =3D counter_priv(counter); =20 - mutex_lock(&priv->lock); + guard(mutex)(&priv->lock); priv->cascade_enable =3D cascade_enable; - mutex_unlock(&priv->lock); =20 return 0; } @@ -528,14 +473,9 @@ static int rz_mtu3_ext_input_phase_clock_select_get(st= ruct counter_device *count u32 *ext_input_phase_clock_select) { struct rz_mtu3_cnt *const priv =3D counter_priv(counter); - int ret; - - ret =3D rz_mtu3_lock_if_ch0_is_enabled(priv); - if (ret) - return ret; =20 + guard(mutex)(&priv->lock); *ext_input_phase_clock_select =3D priv->mtclkc_mtclkd; - mutex_unlock(&priv->lock); =20 return 0; } @@ -544,17 +484,13 @@ static int rz_mtu3_ext_input_phase_clock_select_set(s= truct counter_device *count u32 ext_input_phase_clock_select) { struct rz_mtu3_cnt *const priv =3D counter_priv(counter); - int ret; =20 - ret =3D rz_mtu3_lock_if_ch0_is_enabled(priv); - if (ret) - return ret; + guard(mutex)(&priv->lock); =20 if (priv->count_is_enabled[RZ_MTU3_16_BIT_MTU2_CH] || priv->count_is_enabled[RZ_MTU3_32_BIT_CH]) rz_mtu3_set_phcksel(priv->ch, ext_input_phase_clock_select); priv->mtclkc_mtclkd =3D ext_input_phase_clock_select; - mutex_unlock(&priv->lock); =20 return 0; } @@ -580,14 +516,11 @@ static int rz_mtu3_action_read(struct counter_device = *counter, { const bool is_signal_ab =3D (synapse->signal->id =3D=3D SIGNAL_A_ID) || (synapse->signal->id =3D=3D SIGNAL_B_ID); - struct rz_mtu3_channel *const ch =3D rz_mtu3_get_ch(counter, count->id); struct rz_mtu3_cnt *const priv =3D counter_priv(counter); enum counter_function function; int ret; =20 - ret =3D rz_mtu3_lock_if_count_is_enabled(ch, priv, count->id); - if (ret) - return ret; + mutex_lock(&priv->lock); =20 ret =3D rz_mtu3_count_function_read_helper(priv, count->id, &function); if (ret) { @@ -606,6 +539,8 @@ static int rz_mtu3_action_read(struct counter_device *c= ounter, } } =20 + mutex_unlock(&priv->lock); + switch (function) { case COUNTER_FUNCTION_PULSE_DIRECTION: /* @@ -632,12 +567,9 @@ static int rz_mtu3_action_read(struct counter_device *= counter, break; default: /* should never reach this path */ - mutex_unlock(&priv->lock); return -EINVAL; } =20 - mutex_unlock(&priv->lock); - return 0; } =20 --=20 2.55.0 From nobody Fri Sep 25 09:22:49 2026 Received: from TYVP286CU001.outbound.protection.outlook.com (mail-japaneastazon11011036.outbound.protection.outlook.com [52.101.125.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46A944A0907; Mon, 14 Sep 2026 20:38:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.125.36 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418301; cv=fail; b=cKOl4YyVFt1KxXHEdXCC23v2fnhBAXSQkcyTpTMgTha8cNev5bBYuuH9ym/uzimhNYcZHrUwvR86rJC8wSohphuuWjTUVmg/dcAtJAFYkCZcQ1XRZKerBbfeT27QfCCbnbb58gzllEn/1zZ1X0hxqKfyX9JZhRKyE2uY8vyWi/Y= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789418301; c=relaxed/simple; bh=OH4GzFenZk20CNwn7D//X59P0s98zUHC+Id0xYL2cV8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FxfhxVQ59+G7JCE1y6JPvVBeoiTBND8vo7DjQITUaxjUreJ/2YATeFVRtaJZ4JrQWPfIw5InKa8i4259L5nAV4wbmgfJJknKwwntsTP/aqMqB1C3XPezI+mwGXL/00t1eeyCioOmP9LeIh+SJQ7WgnnEg/oCEn0zHby7tQf3/k4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=g2lRp19s; arc=fail smtp.client-ip=52.101.125.36 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="g2lRp19s" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=R0Hv7t1Lcm/5jMaNd3jC+ZXVPmMa6h7+asQAsbRocpP2D9G6V0O8Xxc5Do8fnTbWUCvCTDWWMb30XxBx6dN0uFkFaQni2IaBIqL1XESj8zoYm4Z+aDC3/Rs8KYCyQv2zGmevQWjoZbwFnK/TJK74KJKGJEYIgS4B0JW0BhNTNCMHLF5PAearQZGCqpGa6O8xLI7gTyEFpdD9oD3u8MjAByylU5ktwpPgF8/8q3ATvUBPm9YqfxfhyZnlZBXtFyeFpxFgdkt+MXGdD/Nx4vdiG7HoSMk4bebsWoLrSHflxEZHNjgFHmrgT1VCVgxQN/9jnGYyPmKoloxG9bU9JOPZdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=cbrHNcKwJnH819dmwPOhYHLkU2FtSPBvC6rXJIWixeQ=; b=Deg4QnHlnCZSk3+quNnn+MUm3cXRVSy6Jr/P2+WkZ6ypfND4+9ckDfT04JtVQIW/ZoiRusSpIP/zoIDlHr9ls1rT8LD6ZtI0M1mdtmKI6NaseDsJBL7IIdLP8Hlr5laC8+Zgs2qSHALZoDhKoY0d6Rtulw/ZMqYWYNq4yuy+nno6wfz3wYaDJLEG00Wzz5vrBnnAnoDS2IORtnq3WE4xgJJ1QrCUAB+O8DEh9wr08MIZBw93nt7khcadFZRxkPyKbnpjGyidPinaVJqDYISXv7fT3/PQVOTWBfbwA+pwOId6oqtcbe4VI3Htfe0x4gHHsiomfpGpAtB2O/z4FyROmw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 8.62.32.50) smtp.rcpttodomain=bp.renesas.com smtp.mailfrom=renesas.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=renesas.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cbrHNcKwJnH819dmwPOhYHLkU2FtSPBvC6rXJIWixeQ=; b=g2lRp19sBaCPDZrL0S7kChIYjKYxPU3QdkGQZhNOYoDV4Eq9VGbZdwUo3M4pfHv680w/UYGG+Y0d0yxTx+T1QeybOJrFWQid/vFk79YEhLjxciTn21IU3RG7QmbnVKxYS9dmrAicX96CAtWDZLprrHu6G1++Ju9BDFe69rcc/GU= Received: from OS7PR01CA0276.jpnprd01.prod.outlook.com (2603:1096:604:259::10) by TYRPR01MB16382.jpnprd01.prod.outlook.com (2603:1096:405:139::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Mon, 14 Sep 2026 20:38:14 +0000 Received: from OS3PEPF0000003D.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:259:cafe::8e) by OS7PR01CA0276.outlook.office365.com (2603:1096:604:259::10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.12 via Frontend Transport; Mon, 14 Sep 2026 20:38:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 8.62.32.50) smtp.mailfrom=renesas.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=renesas.com; Received-SPF: Pass (protection.outlook.com: domain of renesas.com designates 8.62.32.50 as permitted sender) receiver=protection.outlook.com; client-ip=8.62.32.50; helo=ejcrelay004p.adwin.renesas.com; pr=E Received: from ejcrelay004p.adwin.renesas.com (8.62.32.50) by OS3PEPF0000003D.mail.protection.outlook.com (10.167.240.6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Mon, 14 Sep 2026 20:38:14 +0000 Received: from demon-pc.localdomain (unknown [10.226.93.156]) by ejcrelay004p.adwin.renesas.com (Postfix) with ESMTP id D9EE53000368; Tue, 15 Sep 2026 05:38:11 +0900 (JST) From: Cosmin Tanislav To: Biju Das , William Breathitt Gray , Lee Jones Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH 15/15] counter: rz-mtu3-cnt: use pm_runtime_resume_and_get() Date: Mon, 14 Sep 2026 23:36:14 +0300 Message-ID: <20260914203614.2035277-16-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260914203614.2035277-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS3PEPF0000003D:EE_|TYRPR01MB16382:EE_ X-MS-Office365-Filtering-Correlation-Id: dd487cbe-6032-4c1a-9151-08df12a019c2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|376014|23010399003|82310400026|1800799024|10067099003|56012099006|11063799006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: Dst0ZmmVAsgNOCM2J+xceUW7UDL5v6r2mBsE3blWz27p8MmHFqH7UiI+uEJgaqe7jwNG/EmBCRc7eX4nQCVUJcape+7dd6BAtTQnKbd59XoLj7chwTwCen6bReEtQ0MzPRGskWe0W8Bzn0lczrbkC0fuSITfhJpAd4HPDMNkZPbwFEpaVnXw9zja7+VUOjgQ0z1pmTMxezm6NAHQXCO9fqgFKLumrinhqUZ5AD//ZkjSWRweDnSYFdV34nfdmQK8nMxh+FcDUYTx6oWwmSv5C4t0OGGfK7B2xJAzQIOWlWlxw9i1LtmkDxh4ikxvz1uLZBV4zbfCHkK622UebLgydZfxNKbydS8f5qyZ6rlqNVtfL8N9srU5C3x3P7ZqtsQD5hVD6Zez5EFTAt2orbvQy7Goz1h+rudo5lQTz++tMVS3z0/U5N/s9RaVQfzPMfPoXA9B1HposDpRYUMXRFEbLTM3Q8nbXFYgHIV2izGM3To+PUXbGc9FZE6ONssdpieVmRxmUVeuBH2rvaY7cVa+O5NRRKd1al5Dmr/KaVHmrf6DdXj+/2AbhktpitlIJPq+GYgqoVoCr9dZ4Lb9CEi7XcA6Zzqy+PZmBbB+GZGd5nzFZb7GMNz3O24IXenoxRUB/YGwXoQbggAhyko4aoNTVm7qwVhjMTgZC//LkxYc2v9pt3AnCAEHlRX0X26R+2vnSsx2WKolVPzFCFB4uJ5awQ== X-Forefront-Antispam-Report: CIP:8.62.32.50;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ejcrelay004p.adwin.renesas.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(376014)(23010399003)(82310400026)(1800799024)(10067099003)(56012099006)(11063799006)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: InWXoa8aKj013xTLcokUOFk9fMsBdaggS3jkJARTNVrajsO2zP0BdqDnGpphgk7uo3miYHX++MIaorA+NYzFyVbKp9WTC+tCc5HTqyEwwsGcGC/WUOlcJ3IPK4UcXyptgk+uWvS0leQCOy+FevVGPTKAQnVlUD8MHbgNOeC1wYsOGpUL/ZCNN2exaQ1bGJHKryjjmUugz08kk4t/x16nomCm2thvYrGgzU1MMisv+likiCuRjsZ+uPF+H0DDVIvX7BQq9MF4zqkIAdoFKDVciR1TZNrNhmG3NVfKlBtsyrxb/WbZWAv9BZQQ4VgjTreWEBTqF7BreRVMGgmnHxxO+Fgbjw+M/VG7phZ/f6g7VzgiASHyja9//oF8UAS1eA9n/eswheQmdJQmGgxdl2bRVFeupztZC7FGEcW3E61AXgqPBNCWZ32Mvj8+NPeJvXhz X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2026 20:38:14.5518 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd487cbe-6032-4c1a-9151-08df12a019c2 X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=53d82571-da19-47e4-9cb4-625a166a4a2a;Ip=[8.62.32.50];Helo=[ejcrelay004p.adwin.renesas.com] X-MS-Exchange-CrossTenant-AuthSource: OS3PEPF0000003D.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYRPR01MB16382 Content-Type: text/plain; charset="utf-8" pm_runtime_get_sync() may increment the runtime PM usage count even if the resume fails, which requires an explicit pm_runtime_put_noidle() to balance it. This driver ignores the return value of pm_runtime_get_sync(), risking accessing device registers even if resume failed. Replace it with pm_runtime_resume_and_get() and handle errors properly. Signed-off-by: Cosmin Tanislav --- drivers/counter/rz-mtu3-cnt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index f3e8fe5cb818..c6877f988b8b 100644 --- a/drivers/counter/rz-mtu3-cnt.c +++ b/drivers/counter/rz-mtu3-cnt.c @@ -430,7 +430,10 @@ static int rz_mtu3_count_enable_write(struct counter_d= evice *counter, return 0; =20 if (enable) { - pm_runtime_get_sync(counter->parent); + ret =3D pm_runtime_resume_and_get(counter->parent); + if (ret) + return ret; + ret =3D rz_mtu3_initialize_counter(counter, count->id); if (ret) { pm_runtime_put(counter->parent); --=20 2.55.0