From patchwork Tue Aug 6 14:56:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 13755205 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2040.outbound.protection.outlook.com [40.107.22.40]) (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 3C57218D643; Tue, 6 Aug 2024 14:47:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722955654; cv=fail; b=iiLAq+HYjmYKzV5azManTJ+cDUMEiEsVCrGPXmrCsIfEyqEzpUJsAUKgDYlBUOlMsD9y5R2ztktvAdN24g4MhfqQiXGLUMI9rr9nNw7E9zZ1/uOXTqV1JnqAsut33k0B7cxT/VNlIzwhdcsK7/okECHOQk3j43Dl8AwEZQch+mI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722955654; c=relaxed/simple; bh=Yi5Q3IFSqS+7J45FO6SgqeVphuaxGeSDNvHgNsodcsY=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=COCVeMEUyTHqiHGqS/JC8EqTXHb1B5oTp4ifj/mbRd4LHwVy1EelKbNZlDSyx1Vf4Roh8g9oKBtZ8uYGqbnDT+cedYURRZB1Y9ep8mWWsgoDxW5prw8xx3k38WjafQIkdUY+rXHWIgpr1aADIfwvwfSrRhf5qGjkFCsm3x+u4dc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b=UAps6tzG; arc=fail smtp.client-ip=40.107.22.40 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="UAps6tzG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=F9Z6G98LDjCZYJd0cj0tchDQQz+BsT06E2tHwtYey5UqYbR722JXxZF5F31zKckUgA5sYwYMxc1eoF7xKgLP16nUQFZywDqAPaewoJ/IRnUB0niDjpoP11p2Dp7d0Uka2H0D8PbxZ0Iorjxj50MVMAWs0dQh2X5uPf+RDmDxT3/qeGfIIBVlUVI4QzyMlCXILHJis+DJl/fpRTTvSAugVqbkwWyiE9CgJ9dR726egjtAH1HzYYgaCYwiGSV8KxVkRpcYeofzozYg1eMo/w6z3a7tTTTUkVAOGaay9va4LQx6wgkUSpYao8Ept2ZftEY3yMSJejFRHX8eVdI731yVeg== 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=9LuUy0YluQDfn/rdRf34ltJQ3oLxXYRAHJf15gqLOj4=; b=WOLQ6TJ4+J4rtDsN2mDHrnZAVR2JA0boq5p5RnChLJxxP+SGzT1kNuZS5ZQdlOYYNvsSGAiddrGAK5XVsyWMrBW44MuW3m71Mej138a3TYKHY9QWEOVIMx2dZ4N0t3addtM8ud+40BL8O+r3se0t2J4KIhiVg5pw6GNeZrbAqnbP3/yqB7LQprgWdZILZnusmruhw0e/gA8ikRx1UbD52FwSWj65OCWXkPKtMCilzT0uuzMScRJxMT2CKIESWd3StKfjeXWNNj8E+CTTzAS3weaq2r3DU7qv5KJ6GzfUItoMdnnPtzSE58LW2IhBjGGVbuMzgUYW/YXrSgb7Rdy4bQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9LuUy0YluQDfn/rdRf34ltJQ3oLxXYRAHJf15gqLOj4=; b=UAps6tzGoiHhgqHq6zJp2MYo1vO9SeRquEdNfc4+Z4pH5QlWNdVr7Nz3Is/rkETw+up4Z3MQljeue1sfVTfTWCtcklGFLItB09jrGuhkc6NiDu0SJ4kT/kyqo5zcSO4EcPhMWWanSabnaprG8kTNhY8F8aEo+4XmecgkZy2ESxzsMwechBWbwWRwCUpHqptjuugKktq+wIKh1/3u3dffUI3gECRRDL7wEqfDhBs8yexgWM8064MK6rMoGUbdrfg67Cbm9IH4g0PQZgeBKngMZWW5sytFdrZuC1QGB9RjW5pKm/aY7nQlrukebs17z8Zgitz0eJVK4O2goL4i1QjtYQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) by AM7PR04MB6886.eurprd04.prod.outlook.com (2603:10a6:20b:106::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.25; Tue, 6 Aug 2024 14:47:28 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%4]) with mapi id 15.20.7784.020; Tue, 6 Aug 2024 14:47:28 +0000 From: "Peng Fan (OSS)" To: sudeep.holla@arm.com, cristian.marussi@arm.com, mturquette@baylibre.com, sboyd@kernel.org, linux-clk@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, arm-scmi@vger.kernel.org, d-gole@ti.com, Peng Fan Subject: [PATCH V3] clk: scmi: add is_prepared hook Date: Tue, 6 Aug 2024 22:56:01 +0800 Message-Id: <20240806145601.1184337-1-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.37.1 X-ClientProxiedBy: SI1PR02CA0020.apcprd02.prod.outlook.com (2603:1096:4:1f4::9) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) Precedence: bulk X-Mailing-List: linux-clk@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8459:EE_|AM7PR04MB6886:EE_ X-MS-Office365-Filtering-Correlation-Id: 533676ff-2992-4f7a-7157-08dcb626b11e X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: /0hsMXPU1DL+QF0zzwA/FHq1hMdzdL02cN5hqUYkxNTZ9b5wCWm/Y99wpYj7oT/OB11BoK06JG/1vQFqPjqICa0G9aZqtl9CGtEF5Kr4mMgh4yvsARWUvk6w2JuRZbWpm6vGACz9wVMNIANb+7DadDkCHZJuZ+Xj7Eu5amkF1GZ4jGEK+DwV5vIpWoAgXCzvpiqLL77AWuCn8HXdUzUmqJPJvHFTpzjqfOwg6CJ44mMwsc6pULQzQZYBKJCjMKa7F+e0AIsMYItGGfpWKBtM1XwrDNeZg3wAMtc18K3x9/l0cifTVHptlTT/5Mtc549L2/AI5t379vjSr7LWk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RY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB8459.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(52116014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pX7mKDdT1XvmzSJvr51y6tS8DzyKnSAIJXE+4ox2uNRPoW5Lilgi40OG2wNgzHdP8iTGycg/3UYhweG2av9klZiZ2DO+L7bHpR3NxNU5Ym09OIZo2DO34KsvwwThHVRhZG8WiJnlktXybnwGP4phArG1gEyLtt2wtTUKvcg++CxlxPGlencCdkv9jE15PdTnErPhVcWSyOvFV5b7MeepbbB48rHDrd8ARZT6VWYvkhgxlmWs6UaWWcq4okMfced4V9YhxQ9tss4LqRW1utBp/k6HAGcUxiYFbZjTWpeTgKrVz+p5rMQeQVGzsCGovFCJgV9ISb913IjTwJbk+IQ9p8mrPFiwsxATHp9Ud0fBWiRDeoB4gqpd4w06cjMKtbbLkflXZSqpkJCQVsQ3wKpcMwA1UXjZA2/8B+tiR0RTxLTqCzHpmfEw+H59Z4hL3dyQxmnLDTEa/J4mqgy3QyGA3HyiYjLk/An2lhRsKmOsMKo27CR7DRSDuzKwJym4Y0yAAWkTa/GSp4wuPk867GR5ASCI14y+SM2YGuGMxdIOp1W4mApEwO1zjdw00c++utZHsBSodIys3ZTP2JGPAhWxJwT0WsqOCFTqmVurZvXsYEhmngIB0IrU5hfMXHPWhauywNvp8Fs/R6hI4Acv6XskzAZ8JMzOIOAIYtPl+4QIqdtNx3aOo1n3+5rL5u9K5WhpIfCdp89j5chDN0BGsgph37dzOtwkX3yYFls/FkvAjI1TBbjuRF36iq0jS/qTv9db1RV93aLdHwyliuY1F3VeDr7pWVh1r/koAoFUKuO1AbKY0kdiGvq7sBkvnangMGY6l2NFYSTfzZkNzd7PgIoBI0taLVZa9aHJY1gAcuaf4fPCVoqdwLTpbMBnq+UY8LGOSPC9Ypu6CZ2tjppmBo/NYdSQMw3E7+hbwTgoyFgVXl4NJ5bNiLZi0gonbs+YgM5Ca9Iyw5ivRVQU2qxThNcxmrNfVC20oX7QsmF+zcnLMMoklQri022ZGxY3ULz2x+P801yQQshdt2QCh/cXRK1we4fQXJDyc5pVY50nxUam6zgRdrN55w49vAU5lB8LBd/DAlRKkuy5yjBuq+kcOZNtzs9qtkMJlSm6u5il9XpLyu2lAJWCK5TNHvu0VxmT6c7ibVucvE/NAfkDOxqERCxqnAQobUv3/B9aMxa/HixGcRxRy/Lo6EP9M9ndn0awuLoTBdPVRxP9sM3IEET7UriUJirnlt/lEQyZabyNF2Sv+NjwOXIariJpNfVCQXUEPNga3yw9QSTJqKbDUm6nI/By9uwHFIq7CsTwf00kos0W2L4JxZCVTTA9dUFjDumXalf4lXYWzu9Afl4bHxEMl+6O6QxHUe3BwmhmRapInn9lA6bDmEb/OFYCkNpIYOPs0/XFWd7tx6C7r7ZzNPFIU06PqJMYZB8rdCNfP+caTRzpXFq1Jy0zDbqR7qzfeUUFfNmD4mVrWq8LC69hU835RFDs2uKvYnovPi8xtqEI1rWgBJVGcjLLXaSajMJLApVyXt/c5yojkVAja8la5pikCaF99uxL90NxD3JWsu+ucT15+ojMXbsoT3IOljJFZQuaqG0B X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 533676ff-2992-4f7a-7157-08dcb626b11e X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 14:47:28.0237 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Yz+x90DaBbpTocJSTQd85FKDNhkTBDOx2kFh/MsxD4V8aWEQtanCSte7TKHX4H/N/zdVDJ35qEi5Tsy4ezcltw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB6886 From: Peng Fan Some clocks maybe default enabled by hardware. For clocks that don't have users, that will be left in hardware default state, because prepare count and enable count is zero,if there is no is_prepared hook to get the hardware state. So add is_prepared hook to detect the hardware state. Then when disabling the unused clocks, they can be simply turned OFF to save power during kernel boot. Reviewed-by: Dhruva Gole Signed-off-by: Peng Fan Reviewed-by: Sudeep Holla --- V3: Update the commit log. See discussion: https://lore.kernel.org/all/20240802061234.njlviydzmjbsyteb@lcpd911/ V2: Provider helper __scmi_clk_is_enabled for atomic and non-atomic usage Move is_prepared hook out of SCMI_CLK_STATE_CTRL_SUPPORTED https://lore.kernel.org/all/20240802061234.njlviydzmjbsyteb@lcpd911/ drivers/clk/clk-scmi.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clk-scmi.c b/drivers/clk/clk-scmi.c index d86a02563f6c..15510c2ff21c 100644 --- a/drivers/clk/clk-scmi.c +++ b/drivers/clk/clk-scmi.c @@ -156,13 +156,13 @@ static void scmi_clk_atomic_disable(struct clk_hw *hw) scmi_proto_clk_ops->disable(clk->ph, clk->id, ATOMIC); } -static int scmi_clk_atomic_is_enabled(struct clk_hw *hw) +static int __scmi_clk_is_enabled(struct clk_hw *hw, bool atomic) { int ret; bool enabled = false; struct scmi_clk *clk = to_scmi_clk(hw); - ret = scmi_proto_clk_ops->state_get(clk->ph, clk->id, &enabled, ATOMIC); + ret = scmi_proto_clk_ops->state_get(clk->ph, clk->id, &enabled, atomic); if (ret) dev_warn(clk->dev, "Failed to get state for clock ID %d\n", clk->id); @@ -170,6 +170,16 @@ static int scmi_clk_atomic_is_enabled(struct clk_hw *hw) return !!enabled; } +static int scmi_clk_atomic_is_enabled(struct clk_hw *hw) +{ + return __scmi_clk_is_enabled(hw, ATOMIC); +} + +static int scmi_clk_is_enabled(struct clk_hw *hw) +{ + return __scmi_clk_is_enabled(hw, NOT_ATOMIC); +} + static int scmi_clk_get_duty_cycle(struct clk_hw *hw, struct clk_duty *duty) { int ret; @@ -285,6 +295,8 @@ scmi_clk_ops_alloc(struct device *dev, unsigned long feats_key) if (feats_key & BIT(SCMI_CLK_ATOMIC_SUPPORTED)) ops->is_enabled = scmi_clk_atomic_is_enabled; + else + ops->is_prepared = scmi_clk_is_enabled; /* Rate ops */ ops->recalc_rate = scmi_clk_recalc_rate;