From patchwork Fri Jan 24 14:25:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 13949374 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 71A7DC02181 for ; Fri, 24 Jan 2025 13:23:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To: In-Reply-To:References:Message-Id:Content-Transfer-Encoding:Content-Type: Subject:Date:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+ePnyDdKyIs8yCcON+kQ6iffv5+zA00+HvqYWQRtRm0=; b=CxvpyxD+zY2W2EqRLMcv//ikNq XY3ID7tpNNXy6fspR+ZeZOOImylW3CcRZUDx7V3VxGC0oKmnKdmO/iOmzj8brBw3uWZT1AFWP4o2r KsEoLOxx/zeB0CFClSBZvkCnVfBwjBv6elp9rhFR3RPcF6bN/CS6M1dDR5l5Bv67RQs1r9KsNPsl9 NZgFI6V69Q4dvt+VIChp4Mb2Vb81YpFIflUG9mZIcOPFY09DpOm2jmy6z6KAPxmvPk6Iycla9wsF1 6StD6u9YW65APT4x2ygUdPU+8d5litLYb8Fu+FiMuVjJ3uSoj8fEYo+5oPChFWRUq4/Cm0qEDFZ31 aPIZ72GA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tbJeT-0000000EjWF-26yL; Fri, 24 Jan 2025 13:23:13 +0000 Received: from mail-am6eur05on20611.outbound.protection.outlook.com ([2a01:111:f403:2612::611] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tbJad-0000000Ej8G-2IU5 for linux-arm-kernel@lists.infradead.org; Fri, 24 Jan 2025 13:19:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UNRgKmrmYlGR8QGKa9EMdUciYWOIOcaEGw3xh+WkKRHtKkes3oH2VmlyU/yjneaodWhBU1EZ997hc6BfSxqB0hAqJBnPBfTf65JRHQTY26robFFDRs9i6lgzBnlV1wIWZh0txCkA5ALyS3qfeqJQgtZG3H5zawLpGX8da3TMsnovPI/5ECYnBod0EKBup+qTer9/BNvwCsaVCKjVPHyyNGhJxi88mZ5T+jlEjlzaGmNwYNdb2HwCnvF6HAKwc2ABmJsFTdmKdmXijVTIb3ODF1D/hVduJOv5XbVggL1GicF1rjsI9L8W2vfxZPPzykP2JeqNF3g9+qdgL0g+tfM15g== 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=+ePnyDdKyIs8yCcON+kQ6iffv5+zA00+HvqYWQRtRm0=; b=OsfMaURFSLJstSWbg9enHS5gMzGCc80nKNNpVKjFbMPK2a1b7XGsfn4olgrrv6vk3Svttflha9k8RRJfi7/7Z58jUu0PgMfX/M0aBI0J3EQq8Zh6Wcm6ZLSscJN6igyIzomoCfLO7uedeCvbp+blEkaej6WtfZVAqMppgggYkQn0K+/7jmiuaUWWVSr5xAOhFqHbxiQkqy8SsJmIO6NUQKz7Afb7el/H3zQT5DKn1UCXi8/OIXt3qDWmxeO/pBBTTjhkqfYTQu1x1BZchVXiVHmpywQI2raBqI0VIO3Y+8gU9Mv7mGAXHIE7qxgB0tJk7RMlsYaLzTRWEOuRIwaLrQ== 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=+ePnyDdKyIs8yCcON+kQ6iffv5+zA00+HvqYWQRtRm0=; b=Qk9+kpvMsGQEL57+357I8Eh0JFKf4GA/gVPDNF3nJhzRlWZKWd00xlbd8jXAAtj8i+Y37i82/A7nmFFiD30HKsyEH2P8vrO87ZS+uO4c+13sTuYnhSYE4FlfVmXz3wzxyYbEuV7E3rtpWPoiJZ3deDS+bM33HFYiceZ5/n924SdeY1OQYcnA4nEpxg8E8WUWVfR/Vw2h2wFluvxyLSBeXPZblJ3zAPSENZj+MK3pspQ9EEmR+51/wNEolpH5BHPSY+O4uSxpNPJxbbYdHd+ohQWxQyyQpxZM1240grg8pFLfeXC1teIvOy/CE8PsTypqIcyaI/xdxwaSy4EmgLPmhA== 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 PAWPR04MB10007.eurprd04.prod.outlook.com (2603:10a6:102:387::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.18; Fri, 24 Jan 2025 13:19:13 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%5]) with mapi id 15.20.8377.009; Fri, 24 Jan 2025 13:19:13 +0000 From: "Peng Fan (OSS)" Date: Fri, 24 Jan 2025 22:25:18 +0800 Subject: [PATCH 2/3] clk: conf: Support assigned-clock-sscs Message-Id: <20250124-clk-ssc-v1-2-2d39f6baf2af@nxp.com> References: <20250124-clk-ssc-v1-0-2d39f6baf2af@nxp.com> In-Reply-To: <20250124-clk-ssc-v1-0-2d39f6baf2af@nxp.com> To: Michael Turquette , Stephen Boyd , Russell King , Sudeep Holla , Cristian Marussi Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, arm-scmi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Rob Herring , Krzysztof Kozlowski , Dario Binacchi , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , imx@lists.linux.dev, Peng Fan X-Mailer: b4 0.14.2 X-ClientProxiedBy: SG2PR02CA0127.apcprd02.prod.outlook.com (2603:1096:4:188::7) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8459:EE_|PAWPR04MB10007:EE_ X-MS-Office365-Filtering-Correlation-Id: 31680041-489c-41b5-7699-08dd3c79b240 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|376014|7416014|366016|52116014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?szUD+TxTMEhoESoYUKgpNM/f7vj68Ae?= =?utf-8?q?ODGvDzONAvlD47icdX3HbqUJrC3XuO5V0z1QXkb/Ap3Jj3WAxtHnCbBu4BlkAGaZj?= =?utf-8?q?tPOSIYF169J66oP5eiYOJXRcAcBiAREoP4zIloLGIrH18GJLNXyYQ3UVOeUj/dYaf?= =?utf-8?q?XkhzPls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zUKt/vkQn2VM9lJ54/dbuNmDtqKxKCDrQy9cxbC1f5ok2s2+cabbcvwSZNq?= =?utf-8?q?oAc2CCbQ0HXzFgCB7KzDzwGH5OR/yRir+EzlOC1IZSYLWuuIMke9rXifiOLf/xtKG?= =?utf-8?q?qwmRWvBHN2qCANhJPursV1EGU5aXG4IohPi6w6ernVdaRHG+ijTEGTqJHtbtbLjj3?= =?utf-8?q?VhhEd2Cy3YJ0L2iQPslmxFj3JPFQ9s8OyVcSwH1s0R6Apugkdu8rA2IJ+Tc3Yq/FY?= =?utf-8?q?b/pxmTzzIBOhV09FlV5hU9eNPX7GETtDRw4OxHGedcRFBwBVuO3n8Yie3g+u/G/ik?= =?utf-8?q?Zw3HnVG+aOvucYBd+yM1SqqoACCKR+ZbKe7YKkXp9rvIOLtkxLa9ERsrydEG8oDTU?= =?utf-8?q?LORL0iYfFf2?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB8459.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(366016)(52116014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?3jYX7PAbHcEIkW416BZrIBu3Fyrr?= =?utf-8?q?/OgUO2DY0HYZjbLMbDocXmNurY8sO6TPnG6udunbR/48m1WVtKtLx1TohXkNIsXZA?= =?utf-8?q?zY5onmE73j3kBBHzkloNtJGHpgzlzFzb0MfeVlSA3XRqbgI5WZkhUiJ6eSQw0VYuW?= =?utf-8?q?RGZqAKISA5nwrdRSX/9OYEgQMhKhPTl9+z/bZKbtnGJsWNzqqcJOxCcpYQ9PVWiTd?= =?utf-8?q?2D7sY9TD/xwXQRMSKOK9thIaA364q2x2LPtZ+NC92BQ2odpp84kdEzYwDjz4I2Jq3?= =?utf-8?q?sXr2xxYtcoFh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?q?V6qXXSfNfB53Xqu8ZPAxgQjS7yGMNbolQ6GtoE4kSaTnzqum3kujDqAC7kus1sLP/?= =?utf-8?q?HQA7Ir3rF29N9rOE2lCqKWWWTYrjHqdJE5hBEgKgrxiB2F4mdT15h7G9uIrtxTR56?= =?utf-8?q?BKeJlg+zkxx9qd0aCgwg8NSUx203ZwHr9wgAwOBg7ZsxmUuozUx4JD66O8DkX5kKD?= =?utf-8?q?IBPtnZ0A+zHRPt17AgmQdLyLMqG5Qvz1TSbDNuY+mpiArDAWgDsANZs2hTnNGm/jF?= =?utf-8?q?6wATC7fssqIMwRfugrwmtC5vjdGZrIgqyZOIM7znUsE0+t5Ty6N/8glM1XBkOK3UD?= =?utf-8?q?hN4kpUTgIUoaUAIW+B99jccyUmNdlkN1Zgb4tCa1GKgT63vOajY1Pw/EyOCNKWbNW?= =?utf-8?q?R9ckTi/DuGC5?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 31680041-489c-41b5-7699-08dd3c79b240 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2025 13:19:13.6902 (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: dE3GiPDH7+/OQJWbpvJ2dvW5KPlZP2m78Mk83T82QbQXbwEaFRnOmHHyHae8luvDBI1GzEqP0rDrzVG1szU1Ew== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR04MB10007 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250124_051915_595382_03AEDA0A X-CRM114-Status: GOOD ( 16.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Peng Fan Parse the Spread Spectrum Configuration(SSC) from device tree and configure them before using the clock. Each SSC is three u32 elements which means '', so assigned-clock-sscs is an array of multiple three u32 elements. Signed-off-by: Peng Fan --- drivers/clk/clk-conf.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/drivers/clk/clk-conf.c b/drivers/clk/clk-conf.c index 303a0bb26e54a95655ce094a35b989c97ebc6fd8..1ca4222caa829223d65dd37c7a776d43dc421944 100644 --- a/drivers/clk/clk-conf.c +++ b/drivers/clk/clk-conf.c @@ -155,6 +155,70 @@ static int __set_clk_rates(struct device_node *node, bool clk_supplier) return 0; } +static int __set_clk_spread_spectrum(struct device_node *node, bool clk_supplier) +{ + u32 *sscs __free(kfree) = NULL; + u32 elem_size = sizeof(u32) * 3; + struct of_phandle_args clkspec; + int rc, count, index; + struct clk *clk; + + /* modfreq, spreadPercent, modmethod */ + count = of_property_count_elems_of_size(node, "assigned-clock-sscs", elem_size); + if (count > 0) { + sscs = kcalloc(count, elem_size, GFP_KERNEL); + if (!sscs) + return -ENOMEM; + rc = of_property_read_u32_array(node, + "assigned-clock-sscs", + sscs, count * 3); + } else { + return 0; + } + + if (rc) + return rc; + + for (index = 0; index < count; index++) { + u32 modfreq = sscs[index * 3], spreadpercent = sscs[index * 3 + 1]; + u32 method = sscs[index * 3 + 2]; + + if (modfreq || spreadpercent || method) { + rc = of_parse_phandle_with_args(node, "assigned-clocks", + "#clock-cells", index, &clkspec); + if (rc < 0) { + /* skip empty (null) phandles */ + if (rc == -ENOENT) + continue; + else + return rc; + } + + if (clkspec.np == node && !clk_supplier) { + of_node_put(clkspec.np); + return 0; + } + + clk = of_clk_get_from_provider(&clkspec); + of_node_put(clkspec.np); + if (IS_ERR(clk)) { + if (PTR_ERR(clk) != -EPROBE_DEFER) + pr_warn("clk: couldn't get clock %d for %pOF\n", + index, node); + return PTR_ERR(clk); + } + + rc = clk_set_spread_spectrum(clk, modfreq, spreadpercent, method, true); + if (rc < 0) + pr_err("clk: couldn't set %s clk spread spectrum %u %u %u: %d\n", + __clk_get_name(clk), modfreq, spreadpercent, method, rc); + clk_put(clk); + } + } + + return 0; +} + /** * of_clk_set_defaults() - parse and set assigned clocks configuration * @node: device node to apply clock settings for @@ -174,6 +238,10 @@ int of_clk_set_defaults(struct device_node *node, bool clk_supplier) if (!node) return 0; + rc = __set_clk_spread_spectrum(node, clk_supplier); + if (rc < 0) + return rc; + rc = __set_clk_parents(node, clk_supplier); if (rc < 0) return rc;