From patchwork Thu Mar 6 17:57:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haylen Chu X-Patchwork-Id: 14005082 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 E076DC282D1 for ; Thu, 6 Mar 2025 18:00:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=ejW+VlZ/Z9n4oGFbpTsgS7DfZ8BJvN8Of6DXNoNbjh4=; b=MWGXAqpeJ14R86 ilfOj/TEVWdlWRwUfmxhyfmfTX/H3GL2Iev616j3Spf43y1RtXZhafqYSWrE1biI9mWwrgiQdsmXN ecBnOrl8WNEdF5VfITtnQC/YgEKh3tGpxbTKv5FpXtmiKbmmiewLHYNlPkHWDE2dJ2jg6mJ35/oup OzMawoA1miDx1vx4cTNQnoLDo4z7hQs3ichdK7/ecaq+BjJxUTOAOyda+wRsqwraI78ABvH9emUZx RhDURcPQ+CgINp9fHFMG0+YNJBhOnjyV8c8k3pyKyc8nHKU/dXmQimxMPWXhB6A4J6PhChmF+Zswt YzB3HCjL2SbpqoGP/UjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tqFVj-0000000BliA-1qDZ; Thu, 06 Mar 2025 17:59:55 +0000 Received: from bayard.4d2.org ([155.254.16.17]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tqFVg-0000000Blfg-2kdd for linux-riscv@lists.infradead.org; Thu, 06 Mar 2025 17:59:54 +0000 Received: from bayard.4d2.org (bayard.4d2.org [127.0.0.1]) by bayard.4d2.org (Postfix) with ESMTP id 759D0EC59F8; Thu, 06 Mar 2025 09:59:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=4d2.org; s=mail; t=1741283989; bh=Yw1n6v5hNvDiqN1eYZkeAUubqnzwc9HWGRsVQHuzjNw=; h=From:To:Cc:Subject:Date:From; b=YBH99TsV/YpwgAqDPHCN4SeETkt7w5iU0BzPNLS+3sP8bQQmoamfRl7jFpXV6gkO5 L2SEsX+R3WBcyZdTUl6xPb9hfOd0LzK1zRg4EjNUbBrYnnCEWlT/bCDK+5ZRdp0SS8 Z00OzYQPC7vZ2nkK8L9ZjixNSQDKTtvqD2wknzmisgomtQrwSKylLF2c6aJQU31eDf vvsRHKkEQAUgQ9IjhyRqKlrKoPqJm+FrfPOAq29zMWR/pp1XMQ3mneaNd8zs5XpBzj SYqsSXaPh6qqNL9OB3WWT3z8mj/o+JjN+g6PGfHF6pdW0dwR5zdd8EHMGlDvX1vXak 6X3WL7Nrh21lQ== X-Virus-Scanned: amavisd-new at 4d2.org Authentication-Results: bayard.4d2.org (amavisd-new); dkim=pass (2048-bit key) header.d=4d2.org Received: from bayard.4d2.org ([127.0.0.1]) by bayard.4d2.org (bayard.4d2.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eabRI32M_UJV; Thu, 6 Mar 2025 09:59:47 -0800 (PST) Received: from localhost.localdomain (unknown [183.217.80.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) (Authenticated sender: heylenay@4d2.org) by bayard.4d2.org (Postfix) with ESMTPSA id E9A03EC59F2; Thu, 06 Mar 2025 09:59:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=4d2.org; s=mail; t=1741283987; bh=Yw1n6v5hNvDiqN1eYZkeAUubqnzwc9HWGRsVQHuzjNw=; h=From:To:Cc:Subject:Date:From; b=QvFlMvlPZ+Tcl72h1v31ByLCyEIpX9QnzhbdJm/2wnPrG1SF9BxPRDsoznyJbSFR/ YtlftR4FxF/oxT52tImQPoxpoNFLboXqja6m0E9NyPalj9QLIUBkAxIt1R/wLSN8uX 3zEolKr2ppHkToVmF7uA15rMl17BP3JtzsgAWpONtz3n1q7BL7QUge2AuZtc9pAztR auyVblLj7f+XNHu2zyWkcKtzUayG2+2TfZU0H5VN1sW5WwK2oLCMQYj7PR8omWt877 F2RtsjNRLDTmLZerdWZoQMVdmbiZVJLNqYCwmNUVrOJBS3qMdvLwraH+fX/sgfnCJq uUYHDoDjxL3+g== From: Haylen Chu To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Haylen Chu , Yixun Lan Cc: linux-riscv@lists.infradead.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, spacemit@lists.linux.dev, Inochi Amaoto , Chen Wang , Jisheng Zhang , Meng Zhang , Haylen Chu Subject: [PATCH v5 0/5] Add clock controller support for SpacemiT K1 Date: Thu, 6 Mar 2025 17:57:46 +0000 Message-ID: <20250306175750.22480-2-heylenay@4d2.org> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250306_095952_994464_EF7EC222 X-CRM114-Status: GOOD ( 17.16 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The clock tree of SpacemiT K1 is managed by several independent multifunction devices, some of them are - Application Power Manage Unit, APMU - Main Power Manage Unit, MPMU - APB Bus Clock Unit, APBC - APB Spare, APBS These four devices provide hardware bits for three purposes: power management, reset signals and clocks. Not every device is capable of all the three functionalities, - APMU, MPMU: power, reset, clock - APBC: clock, reset - APBS: clock (PLL clocks) This series adds support for clock hardwares in these four regions, which covers most peripherals except DDR and the realtime processor. Tested on BananaPi-F3 board. With some out-of-tree drivers, I've successfully brought up I2C, RTC, MMC and ethernet controllers. A clock tree dump could be obtained here[1]. [1]: https://gist.github.com/heylenayy/4c88630454d5ad26c9336592673eb187 Changed from v4 - bindings: - Drop CLK_*_NUM macros from binding headers - Rename spacemit,k1-ccu.yaml to spacemit,k1-pll.yaml, change to describe only the PLL in APBS region - k1-syscon.yaml - drop spacemit,k1-syscon-apbs, it should be the PLL device - drop child nodes - describe the syscons as clock, reset and power-domain controllers - drop "syscon" from the compatible list, as these syscons aren't compatible with the generic one - driver: - misc style fixes and naming improvements - drop unused fields from data structures - drop unused clock types: CCU_DDN_GATE - ddn type: - improve the comments - dynamically calculate appropriate rates - hardcode the x2 factor - mix type - drop val_{disable,enable} for gate subtype - drop unncessary polling when enabling a gate - encode subtypes directly in struct ccu_mix - generate clock names from identifiers of the data structure - rename CCU_DIV2_FC_MUX_GATE_DEFINE to CCU_DIV_SPLIT_FC_MUX_GATE - pll type: - correctly claim the parent clock - make rate tables const - drop SWCR2-related fields - combine fields of registers as a whole instead of working with each field - clock tree for k1: - removed duplicated offsets - drop the placeholder 1:1 factor, pll1_d7_351p8 - workaround the quirk of TWSI8 clocks - fix the definition of ripc_clk, wdt_bus_clk, dpu_bit_clk and timers_*_clk - drop structure spacemit_ccu_priv and spacemit_ccu_data - rework clock registration - split the PCIe clocks correctly (there're three distinct clocks for each PCIe port) - devicetree: - adapt the new binding - Link to v4: https://lore.kernel.org/all/20250103215636.19967-2-heylenay@4d2.org/ Changed from v3 - spacemit,k1-ccu binding - allow spacemit,mpmu property only for controllers requiring it (spacemit,k1-ccu-apbs) - spacemit,k1-syscon binding - drop unnecessary *-cells properties - drop unrelated nodes in the example - driver - remove unnecessary divisions during rate calucalation in ccu_ddn.c - use independent clk_ops for different ddn/mix variants, drop reg_type field in struct ccu_common - make the register containing frequency change bit a sperate field in ccu_common - unify DIV_MFC_MUX_GATE and DIV_FC_MUX_GATE - implement a correct determine_rate() for mix type - avoid reparenting in set_rate() for mix type - fix build failure when SPACEMIT_CCU and SPACEMIT_CCU_K1 are configured differently - use "osc" instead of "osc_32k" in clock input names - misc style fixes - Link to v3: https://lore.kernel.org/all/20241126143125.9980-2-heylenay@4d2.org/ Changed from v2 - dt-binding fixes - drop clocks marked as deprecated by the vendor (CLK_JPF_4KAFBC and CLK_JPF_2KAFBC) - add binding of missing bus clocks - change input clocks to use frequency-aware and more precise names - mark input clocks and their names as required - move the example to the (parent) syscon node and complete it - misc style fixes - misc improvements in code - drop unnecessary spinlock in the driver - implement missing bus clocks - Link to v2: https://lore.kernel.org/all/SEYPR01MB4221829A2CD4D4C1704BABD7D7602@SEYPR01MB4221.apcprd01.prod.exchangelabs.com/ Changed from v1 - add SoC prefix (k1) - relicense dt-binding header - misc fixes and style improvements for dt-binding - document spacemit,k1-syscon - implement all APBS, MPMU, APBC and APMU clocks - code cleanup - Link to v1: https://lore.kernel.org/all/SEYPR01MB4221B3178F5233EAB5149E41D7902@SEYPR01MB4221.apcprd01.prod.exchangelabs.com/ Haylen Chu (5): dt-bindings: soc: spacemit: Add spacemit,k1-syscon dt-bindings: clock: spacemit: Add spacemit,k1-pll clk: spacemit: Add clock support for Spacemit K1 SoC clk: spacemit: k1: Add TWSI8 bus and function clocks riscv: dts: spacemit: Add clock tree for Spacemit K1 .../bindings/clock/spacemit,k1-pll.yaml | 50 + .../soc/spacemit/spacemit,k1-syscon.yaml | 80 + arch/riscv/boot/dts/spacemit/k1.dtsi | 79 + drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/spacemit/Kconfig | 20 + drivers/clk/spacemit/Makefile | 5 + drivers/clk/spacemit/ccu-k1.c | 1720 +++++++++++++++++ drivers/clk/spacemit/ccu_common.h | 47 + drivers/clk/spacemit/ccu_ddn.c | 80 + drivers/clk/spacemit/ccu_ddn.h | 48 + drivers/clk/spacemit/ccu_mix.c | 284 +++ drivers/clk/spacemit/ccu_mix.h | 246 +++ drivers/clk/spacemit/ccu_pll.c | 146 ++ drivers/clk/spacemit/ccu_pll.h | 76 + include/dt-bindings/clock/spacemit,k1-ccu.h | 247 +++ 16 files changed, 3130 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/spacemit,k1-pll.yaml create mode 100644 Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml create mode 100644 drivers/clk/spacemit/Kconfig create mode 100644 drivers/clk/spacemit/Makefile create mode 100644 drivers/clk/spacemit/ccu-k1.c create mode 100644 drivers/clk/spacemit/ccu_common.h create mode 100644 drivers/clk/spacemit/ccu_ddn.c create mode 100644 drivers/clk/spacemit/ccu_ddn.h create mode 100644 drivers/clk/spacemit/ccu_mix.c create mode 100644 drivers/clk/spacemit/ccu_mix.h create mode 100644 drivers/clk/spacemit/ccu_pll.c create mode 100644 drivers/clk/spacemit/ccu_pll.h create mode 100644 include/dt-bindings/clock/spacemit,k1-ccu.h