From nobody Mon May 25 06:41:57 2026 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 251EC2F9998 for ; Sun, 17 May 2026 14:13:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779027235; cv=none; b=l3QRS1obZrfZgkpiR4IMyFJ1rEBYBwwod5jWtIGuMre5kJ+CsVghdrluqAyV9ApTPHKfpYPP7SmFIENcCMmbfuHKxjUaw4z2XgsvVLzDxXcPgAt+ExzwcW5GxnytrCDV61Qpjz2tCbDrwRdG0lbTwv3MHwO6CBv7UmEvh/jpzaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779027235; c=relaxed/simple; bh=u+JI8R2LQAVfqakJyFmBVzSMkc2Y1IF7qqSKLB57m9g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mavYpBCscjeFd3vZju2mfvWzZUMISHRt8mpr/p7AeFpRXXvQh9nDa2wczOx/3z28QlzTpowGwitTaIqNt15vmVD6heRsSkZEHijT11WkMw6diKOgHhFgqb6zV1ImFn+DmJUJRidZEepZX8bk0e2QCioDAL7zptGGQrKa3mrAZ4A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MiexOe0o; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MiexOe0o" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-836ebdeb969so532600b3a.3 for ; Sun, 17 May 2026 07:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779027232; x=1779632032; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=seaxzvl1xgZZJAa+rRq0jV+BZBh4vJTt4ZSm28H6Xmk=; b=MiexOe0o/pOACz1YfXOHwJdZSr8qFSFIU57wzR5On47PHsE9vYDS7YEYT//524tqKc BZGIJiW5Hb3gkAglrgHzm9ij52U/1FZDlN2S9y9ykE0uLlkkWtUjaE+ybIx2NiGUgIoo 06GEUbyCBM7+HG+CmF3rPr4DAsr1ibHXDuoZNA7lMB+HOAOC/Iyyj78p+FEelUgj2olC jquxTZIAJtHzzjo/fn+neS/8Fjw1pnxgGeurcWLPDhR6yq5avG1kW6isXzSSqAERGJgn BrKPSJB6qg3mfQrvbC9YP36e97j1TMX53Fu7xCom497w+PLU8zFfVxRT/ZG1XFKvl9vU JE7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779027232; x=1779632032; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=seaxzvl1xgZZJAa+rRq0jV+BZBh4vJTt4ZSm28H6Xmk=; b=MWg/U8nIbb2cWeHwFaQpqEi0JKkGkc2pT+HD7tskJZTz0+fGEG2pbHgjptwXE56DnQ udpqYr7YdMxntmDCVSnsPZLzytOPfFLd3j6cR78mF8zfpbcRu/DjTS7Hh2l9MEQLYD8B vPmDVAmIOv9EEjAjveCiX3msqbYi6FdcX/G3+MmDUVE8HAM+6cHBN1fsaDT+Qou11ByF 9uQPQQyXWSNTWN2KtU2CqoQQXr5vq/gxccKjIIYnPURAa4gLZtZ8WLcJ2r4XVHQS/d2E Pg42/m+kzOgBASrCdiAkqtlfXesODH70ZEc9qWLocl67ACUiEZFSVQjnKGw2Dy4D56uR uHEA== X-Forwarded-Encrypted: i=1; AFNElJ/pzxJL3JL9NSy3Kf1MwJUa34QiQI1TSf4lZljmATnP6+lm44+X4Zxr+ldIpgxoa/v6Mnup3pAkmS44iiA=@vger.kernel.org X-Gm-Message-State: AOJu0YyrthOGh4j41v/rrcx8mc7if6SeyAs1llepmXEba8jNZAPu8ru0 Z3zGV1ZdAqwHeq+XuY/dO/WiYSrW35E2ruG8oezCSPwasPgLhjtaIjhk X-Gm-Gg: Acq92OE8FS/AXkZgrEHmpl4hD0F9U6AOjYhSJO5BA/CSXExicZIJ1C6Kc/vfv5hluhv VmUbnazfEMb0GR9c9Au4ePor5aqJBXgHvEHVRwl9P7MwJSyJR0N3ohpaU8Da8yg09M/COV7Hh1v BzrMkhVFCmoDUvSEBdthCctTUMlZia6w4mT+405uc0KuedwXnx3FexETAOY7TwwPGNGNrLvs4AB yztzNz6iX8lgrUXcWEz5TRyi7kcavvlp8FCGy3pzGhVLYH6mevw4zH+SuAajaD5RecOZShjOflu fRxK0mjgUKoOVyru95UmX/oADk7ndPAEcffX8KYLINBusA/w68oMxLmNDSlpitDDxvWc3gtioCq wu+T8xceeptp9C5wh1vvyFDw0s7GM6Xj/llLskMfEm0pOv7YH5PCQacndGjL9r5hxcqvLTkdM2p AMD4foQASIumfk6e1J8zjn2kDKRaRi7scFvCXcsy8= X-Received: by 2002:a05:6a00:4ac2:b0:82c:66f2:1226 with SMTP id d2e1a72fcca58-83f33d5494bmr11243398b3a.38.1779027232488; Sun, 17 May 2026 07:13:52 -0700 (PDT) Received: from guoguo-lecoo.lan ([104.28.163.100]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83f19fa5489sm10252528b3a.60.2026.05.17.07.13.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2026 07:13:52 -0700 (PDT) From: Chuanhong Guo Date: Sun, 17 May 2026 22:12:55 +0800 Subject: [PATCH 1/4] riscv: add Siflower RISC-V SoC family Kconfig support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260517-sf21-topcrm-v1-1-438f2e0513ff@gmail.com> References: <20260517-sf21-topcrm-v1-0-438f2e0513ff@gmail.com> In-Reply-To: <20260517-sf21-topcrm-v1-0-438f2e0513ff@gmail.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Michael Turquette , Stephen Boyd , Brian Masney , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, Chuanhong Guo X-Mailer: b4 0.14.3 Siflower RISC-V SoCs, including SF21A6826 and SF21H8898, are RISC-V chips with T-Head C908 cores for home routers and gateways. Add a Kconfig entry named ARCH_SIFLOWER for them. Notably these chips uses ARM PL011 for UART. ARM_AMBA is selected for its driver. Signed-off-by: Chuanhong Guo --- arch/riscv/Kconfig.socs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/riscv/Kconfig.socs b/arch/riscv/Kconfig.socs index c174ac0ec46b..9996591cd9db 100644 --- a/arch/riscv/Kconfig.socs +++ b/arch/riscv/Kconfig.socs @@ -37,6 +37,13 @@ config ARCH_SIFIVE help This enables support for SiFive SoC platform hardware. =20 +config ARCH_SIFLOWER + bool "Siflower RISC-V SoCs" + select ARM_AMBA if TTY + select ERRATA_THEAD + help + This enables support for Siflower RISC-V SoC platform hardware. + config ARCH_SOPHGO bool "Sophgo SoCs" help --=20 2.54.0 From nobody Mon May 25 06:41:57 2026 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 603F830CD82 for ; Sun, 17 May 2026 14:14:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779027243; cv=none; b=n94jAvWqjfvlZnxm9DgW+dRm10W8C+0+X4sU/VuAtoResKJHOQ9uvvzZQEGdgskXnaFBtmrj+OxBPaCe6D07XMBfqwr6P3sVncoDBnlkYLkFM2lHSmkgtjYbBWG+jg4nxal/2H4HkAbFWbQinyD6792e/CIdnQcQdVuvg+fu+NY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779027243; c=relaxed/simple; bh=JzYV15mXR7ZOGE6vAiOWahnTo78b0H7QpXMPWklQKyw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=f6sLeEjWLLJcJa2Z3lGxGT8F15Q+/d7k9DGeU6/xUduxwEaKCS+8aHIf4sRdEyCB1m5z9QUHut5ySVdWS3Qu0npc9aAjCpjZVt+6UJ321EEJt89I1tbwlENkW0eglOhTa8Mj/aj+jxRKKDR3bHkkkuW680xk9EHmHUbv5x6zGoI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=j4urrvgE; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j4urrvgE" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-8379e010b01so490716b3a.1 for ; Sun, 17 May 2026 07:14:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779027242; x=1779632042; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=KxQKu0qPaPWJEtwO0UUAfVj3SWZjw97pz5Uss4p8Sr8=; b=j4urrvgEvqZ4NtrUmMZSL6MLeAAqK1dkc9Pz9Vy5MF4O6nAwKbeVu98aVNcGV4fEBv KuzuG+7Dy908g39oB8+d9cS1oQ7OmtrNWn1U/cyddO1+GxFfppuKAbuJnZa+7i268zhK H2Cv1ARr3/+WjxV5PR1j3ccDOSbGfYUAt+qnhDJHFrXuqQHjesdld90J/a0W01gbRP6I mPMl9GXf+/LoeTc3TIQKAi9Dh/jpCGvdRBCGlboZsh8EL29kJoSFftWPvpKIOf+hoZp+ Z334Y/m6A2m9A3DAbyZkLoEgqxCB8ictO8mS4hZMlHqV+5ysqpRJwpNYegTwwWGI0q6D Hs7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779027242; x=1779632042; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=KxQKu0qPaPWJEtwO0UUAfVj3SWZjw97pz5Uss4p8Sr8=; b=kW5cY1rb1gqsVwu3E0fTYrNodrKeg/MOH9aQIWnRhcolGX2eTBoYIsw35T1BE2uHIZ wzIKKUPJoPcOWMhjYgubE6qlvGzFIoJGhl/WpHMWsvKyd6T8/CQsu94TRQMK7nQ3z62d 1scYBlzeI1OQ8CHsGwg47LJLPjdNs06t8MDhugRNx0OK7hd5pBtEku84k2EYKwX37bXv AZCu6wnPBwk1dmroBGGQLNecTsK57H2tBnNLYu+a31hfiabaW0ZqPXz/MZkXQ683Mt0K QZ8r4Nn7YYkLWcOBeuR/Fyn2qCQtGGijtDI0br0LwbeErQ8hQWo2tEEGvaliIasBOhV1 sXBw== X-Forwarded-Encrypted: i=1; AFNElJ9tsr4ePRNkNqjxLnglqdk6WMKxxGfXavY2MDHapGsX+DYo3gpz1vlHMi4EsxrpZCoxCC4PIfk8R3YuPLs=@vger.kernel.org X-Gm-Message-State: AOJu0Ywwof8Fk4DvxdW9A4pjB0AinptfEJfJtxGQuKYBXvYo+xvc7BZg Grcuhb2lv33X6cpmNI8Ten/eRJsiLIsQZyGsSia8tMil42NIA8lYmuQj X-Gm-Gg: Acq92OFvpVHzBtowfEy5xZE7rX1t5riTGs7Yv3szdTjWDos6yHL7Wg4TIr8hDhEqkxg H2OtMj/bwJBmjCtbxSPXk2NT1G2szsiDe2pkJdyLKIIZ4YQ4smcLfNKEMS+aIMFP1psXUtlIbeb BPsl+Q9sMNlkNYW9bum258rTbuIccnR3MmzzfRF/79BIbAs186CEWwC9yb9ZshUxZPIjQbiINTB bGvRjSDyF1Dn5YHTewFDQ1xBOPxgDZ2D4ZmjK1IuxCPo76LWp4HGpHNjf//E9aKiDluKnr7TS3c Fpe0lvMOTOVYae/EMopBNxj1ZusF2oLpG+O0eQm6OERw8Ray+DFn6F/zW8lCkUTqg+kPeY/ndcA pqZ3zT3Ua2XRQ9og706s0GUtFsfBFd03781/18A5oDdeOJ0BhssN9e7ei5+VXiKSo4F0wZHpIus tPBLPYO4UgyuadNFK7GVzsX5PVF1Yy X-Received: by 2002:a05:6a00:4fc8:b0:82f:84c6:6510 with SMTP id d2e1a72fcca58-83f33c961c7mr11808884b3a.11.1779027241731; Sun, 17 May 2026 07:14:01 -0700 (PDT) Received: from guoguo-lecoo.lan ([104.28.163.100]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83f19fa5489sm10252528b3a.60.2026.05.17.07.13.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2026 07:14:01 -0700 (PDT) From: Chuanhong Guo Date: Sun, 17 May 2026 22:12:56 +0800 Subject: [PATCH 2/4] dt-bindings: clock: add binding header for sf21-topcrm Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260517-sf21-topcrm-v1-2-438f2e0513ff@gmail.com> References: <20260517-sf21-topcrm-v1-0-438f2e0513ff@gmail.com> In-Reply-To: <20260517-sf21-topcrm-v1-0-438f2e0513ff@gmail.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Michael Turquette , Stephen Boyd , Brian Masney , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, Chuanhong Guo X-Mailer: b4 0.14.3 Add the device tree binding header for Siflower SF21A6826/SF21H8898 toplevel clock and reset module. The header covers both clock and reset IDs provided by the block. CLK_ETH_REF_P is a clock name that exists in the vendor datasheet. This clock connects directly to CLK_PCIEPLL_FOUT2 and there's no clock gate/mux in between. An alias is created for this clock to make available clock names align with the datasheet. Signed-off-by: Chuanhong Guo --- include/dt-bindings/clock/siflower,sf21-topcrm.h | 63 ++++++++++++++++++++= ++++ 1 file changed, 63 insertions(+) diff --git a/include/dt-bindings/clock/siflower,sf21-topcrm.h b/include/dt-= bindings/clock/siflower,sf21-topcrm.h new file mode 100644 index 000000000000..3690b3452501 --- /dev/null +++ b/include/dt-bindings/clock/siflower,sf21-topcrm.h @@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR MIT) */ + +#ifndef _DT_BINDINGS_CLK_SIFLOWER_SF21_TOPCRM_H +#define _DT_BINDINGS_CLK_SIFLOWER_SF21_TOPCRM_H + +#define SF21_CLK_CMNPLL_VCO 0 +#define SF21_CLK_CMNPLL_POSTDIV 1 + +#define SF21_CLK_DDRPLL_POSTDIV 2 + +#define SF21_CLK_PCIEPLL_VCO 3 +#define SF21_CLK_PCIEPLL_FOUT0 4 +#define SF21_CLK_PCIEPLL_FOUT1 5 +#define SF21_CLK_PCIEPLL_FOUT2 6 +#define SF21_CLK_ETH_REF_P SF21_CLK_PCIEPLL_FOUT2 +#define SF21_CLK_PCIEPLL_FOUT3 7 + +#define SF21_CLK_CPU 8 +#define SF21_CLK_PIC 9 +#define SF21_CLK_AXI 10 +#define SF21_CLK_AHB 11 +#define SF21_CLK_APB 12 +#define SF21_CLK_UART 13 +#define SF21_CLK_IRAM 14 +#define SF21_CLK_NPU 15 +#define SF21_CLK_DDRPHY_REF 16 +#define SF21_CLK_DDR_BYPASS 17 +#define SF21_CLK_ETHTSU 18 +#define SF21_CLK_GMAC_BYP_REF 19 +#define SF21_CLK_USB 20 +#define SF21_CLK_USBPHY 21 +#define SF21_CLK_SERDES_CSR 22 +#define SF21_CLK_CRYPT_CSR 23 +#define SF21_CLK_CRYPT_APP 24 +#define SF21_CLK_IROM 25 +#define SF21_CLK_BOOT 26 +#define SF21_CLK_PVT 27 +#define SF21_CLK_PLL_TEST 28 +#define SF21_CLK_PCIE_REFN 29 +#define SF21_CLK_PCIE_REFP 30 +#define SF21_CLK_MAX 31 + +#define SF21_RESET_GIC 0 +#define SF21_RESET_AXI 1 +#define SF21_RESET_AHB 2 +#define SF21_RESET_APB 3 +#define SF21_RESET_IRAM 4 +#define SF21_RESET_NPU 5 +#define SF21_RESET_DDR_CTL 6 +#define SF21_RESET_DDR_PHY 7 +#define SF21_RESET_DDR_PWR_OK_IN 8 +#define SF21_RESET_DDR_CTL_APB 9 +#define SF21_RESET_DDR_PHY_APB 10 +#define SF21_RESET_USB 11 +#define SF21_RESET_PVT 12 +#define SF21_RESET_SERDES_CSR 13 +#define SF21_RESET_CRYPT_CSR 14 +#define SF21_RESET_CRYPT_APP 15 +#define SF21_RESET_NPU2DDR_ASYNCBRIDGE 16 +#define SF21_RESET_IROM 17 +#define SF21_RESET_MAX 18 + +#endif --=20 2.54.0 From nobody Mon May 25 06:41:57 2026 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9B212F8EA4 for ; Sun, 17 May 2026 14:14:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779027253; cv=none; b=gnCHX2qL9adxqLbsbKYZ+g73ZUwwf10jgjmUhB5SA3P88o4zjZW1ZiLJyZIn3CMlnnVjl5O53RBln/BGnuXt1Le/r1CJSGZYprWfsg8lK53JaIgRQgOh4Dg9tjbJTOk1ZVYjU8LmeoKIkeJQpvlch5Ywg6kNIxWFHC0MoroFUH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779027253; c=relaxed/simple; bh=J1TWtwjyathQVzLOqlPAy45y/P9JtYt8NSeJ7wfuJ1k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QgwiIj+IqX6CvW4GP9i+vE5nq+/l17B9soWtVvO23Yw4kIsq2ly8ojJTTL2l0bvnpS9NJo47KR1k8qvjv1Z7t+Jx8ZPrEj3IpmjEXIfh/n1aY/9pn+nd0sgnRN3JDBixGUA+A2O6UPM6D/IEXrtUoN5sfZjB1+QBnnNjeVGdkQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HJKpm2Zt; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HJKpm2Zt" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-838d0b7c950so977404b3a.3 for ; Sun, 17 May 2026 07:14:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779027251; x=1779632051; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=QuKxsb1CbpZOKkWQdrQrH9Ys+UuCjZlO2N+4MPQtab4=; b=HJKpm2ZtmV1pwI86ClhB00RBHacTqccJ2b9+GtobSqeuzT1tjQZQuQB+UFw/FkFusg JLSUrNg/5akI6zeuhNq+xjSk4HcPNkSR3hPOdFVCOwErRdnWJK4cxNXE3HaFo0AAf2ln eRxp1NoOmtX1fYMib3CS/Qgm2HqbfJjoXN+2mzdfoq4YOYQ1F/rLUCPwPqhN+Y1gyqQ5 MUI7loOYn9skbTOE8F3A2US2hyvM1LW0iZD3zsKdY7DRS3uhYo60a8bWMcOdpz+69jr0 ZAzlX1h5SlYfNAXm54J3OQ+zOV5Wtj6yVX3Epoq47V9CWhzXAVBlIlyXgVGEWbR4Kuu9 HcqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779027251; x=1779632051; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=QuKxsb1CbpZOKkWQdrQrH9Ys+UuCjZlO2N+4MPQtab4=; b=G5wsIiF62vMqpxhaF2g5YhJcowp/n7OYjrSU/6BBNOqQPXZAXqcunp4o57sn7021rM +a5cWSfnlL/ZVvPTEpl65NiBxK/m6OY1oULDLn3l+2e/TIB1tcKx6ha/o5nA1lFECcMX Yjg1KrS0/xFi7T946mOJHmoBTx0GebcdmnDMkadf3NvYY/fOA2BCkaRJdyaGdI99C7Gs Zxtf0C8Mbfa+H8RGh63Uu4qCudb+XKjtKFIZG374G/5TbbqUJ9KmhBMxLHVaHFCMmVMk c4XxnEe9Yv6AHDdWpD7As3vRLd/1h2EEM/HO2b6B3l2pV0bci8MuJvX24HJQmInskcYf DFxA== X-Forwarded-Encrypted: i=1; AFNElJ/HUiIBu8it53cX+drRy7WmJ8y5CeceR5lGcedAEa1f809PG8WEeMxMeRSbSfoOn2Zcp3MdbXW7KDWAhus=@vger.kernel.org X-Gm-Message-State: AOJu0YygaYVTvKGo+8y6ipWfb5j6NJTA/XiM7AE3TACxSRQTmbvA84Cu miP7zHXsdpH6BL4M0vKUBI80p6Yq1l+99oV7UmBc2edq6FhOps/O6XUm X-Gm-Gg: Acq92OEtkovB+OjDpbH8qtVRsz6cas5yLF0AojrydcQu+G06MQKB00kJGTaeLRypzYj UXLIBjGlU1lgAvi2ruHvvpTFmUWSenkUi/DyJ0FSBPhKOzwcrAEhR5EvXe60dTzgHCIZ26Ivyxk BBtkXGynFSYw0tIXNPp5jDZiwTk57gJQlIptdHa8IbcLH9eEK0UbdoB1gWnaPoPsziEoO+78tex OM+DcHMBEpEy+3S1A8bIRrAQSMgiNkAwy/rwsmuLAejcIqKp42c1RMD5kfwTjkS1ej8l6B0GRGm jG/NOjghZ3ZgqU4A0WjZYqr/bDHIMzgIPST8uc+HPoQMDg2hVKJoGhqTKy4NZ02/lvq/zocs4sJ GvglGFMe+v+L5sOL44ORy0bj8dJzgt6onbKSJ8r2pGHco6uI86R8ZyYAinqvrbbz6zHea+TsF01 Px4gYWPSi1kJohhO4Q6Ml/7tOM79tz X-Received: by 2002:a05:6a00:a221:b0:82f:776f:a78a with SMTP id d2e1a72fcca58-83f33d9dc56mr11055934b3a.30.1779027251056; Sun, 17 May 2026 07:14:11 -0700 (PDT) Received: from guoguo-lecoo.lan ([104.28.163.100]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83f19fa5489sm10252528b3a.60.2026.05.17.07.14.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2026 07:14:10 -0700 (PDT) From: Chuanhong Guo Date: Sun, 17 May 2026 22:12:57 +0800 Subject: [PATCH 3/4] dt-bindings: clock: add doc for Siflower sf21-topcrm Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260517-sf21-topcrm-v1-3-438f2e0513ff@gmail.com> References: <20260517-sf21-topcrm-v1-0-438f2e0513ff@gmail.com> In-Reply-To: <20260517-sf21-topcrm-v1-0-438f2e0513ff@gmail.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Michael Turquette , Stephen Boyd , Brian Masney , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, Chuanhong Guo X-Mailer: b4 0.14.3 Add a binding doc for the top clock and reset module found on Siflower SF21 SoCs. This block provides the main PLLs, high-level clock controls, and some reset lines. Signed-off-by: Chuanhong Guo --- .../bindings/clock/siflower,sf21-topcrm.yaml | 69 ++++++++++++++++++= ++++ 1 file changed, 69 insertions(+) diff --git a/Documentation/devicetree/bindings/clock/siflower,sf21-topcrm.y= aml b/Documentation/devicetree/bindings/clock/siflower,sf21-topcrm.yaml new file mode 100644 index 000000000000..a013d48841f4 --- /dev/null +++ b/Documentation/devicetree/bindings/clock/siflower,sf21-topcrm.yaml @@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/clock/siflower,sf21-topcrm.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Siflower SF21 toplevel clock and reset module + +maintainers: + - Chuanhong Guo + +description: | + The toplevel clock and reset module on Siflower SF21 SoCs manages + the main PLLs, high-level clock muxes/dividers/gates, and some + reset lines. + Available clocks and resets are defined in: + include/dt-bindings/clock/siflower,sf21-topcrm.h + +properties: + compatible: + const: siflower,sf21-topcrm + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-names: + const: xin25m + + "#clock-cells": + const: 1 + + "#reset-cells": + const: 1 + +required: + - compatible + - reg + - clocks + - clock-names + - "#clock-cells" + - "#reset-cells" + +additionalProperties: false + +examples: + - | + #include + / { + #address-cells =3D <1>; + #size-cells =3D <1>; + + xin25m: clock-25000000 { + compatible =3D "fixed-clock"; + #clock-cells =3D <0>; + clock-frequency =3D <25000000>; + }; + + clock-controller@ce00400 { + compatible =3D "siflower,sf21-topcrm"; + reg =3D <0x0ce00400 0x400>; + clocks =3D <&xin25m>; + clock-names =3D "xin25m"; + #clock-cells =3D <1>; + #reset-cells =3D <1>; + }; + }; --=20 2.54.0 From nobody Mon May 25 06:41:57 2026 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E07B63112AB for ; Sun, 17 May 2026 14:14:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779027263; cv=none; b=qE96fNAQ4e3TWlTk/wR+3UcXg00bOF3uUph9LS80uD+jgAlPQqS2eZpNMjITLuaRNQHgPuOxCqh0b9V7zuO8xIzy4N02m5a10QUxDPgNApREIp0pygxKH9oMFYP6oA3xZzwmf9p3deql4L2lJ6m6NnJfX20ca7IRvHvrJDWU4Cw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779027263; c=relaxed/simple; bh=EnrscEuSE8fI9Gm+MsYeXhaWnc4Rwq16JrCR4XufEh8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WIhLcp7PDV8CVb8GPpdiPwayQ2XAhYX8wF6Ki0DZ6hbdyIowY6Ix7/x3pgvVssvHVqAKpRAoy6IUhJUOy4Bx56Hn7MzbSCLgXhngQdRoH0BdVoYjgCV3klPYR6YUhlnu0lM2lejC2oXvadio1lSnJDZ9NwIUYT/mH2WP0GEpfWc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kSt24/Fp; arc=none smtp.client-ip=209.85.215.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kSt24/Fp" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-c80170db7d6so512408a12.0 for ; Sun, 17 May 2026 07:14:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779027260; x=1779632060; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=QQ0AMioN9ICp6uPC2mkgQROFQBoTgmc1faz4jD3rols=; b=kSt24/FpulBkhWFgcBU5EchKF4bELXzXwMvfH2K9v5Chcvfx6We0ovcrDQ8wpU+2hx EJwFC+lFDludzB8dsEcEiRY48nPQTRYQgkc8BtFxxOH7rfNsu5VC9q657bJwO1OyuF6Y KhY9B2WEPXLdUcKylE1E5jXiqjl+RBEOK4aJ5IhPbd7Ms3+6AV7tJCtjXMFMyfAyqMLM WAHBq1ph2apHbhgIC0aqjxjGX7oH4/ctrExDW/GagUqSurnxZUfZhR5we6UqZEsxNipG pGkTOErrLqKd1t30RoMen/SHbFGb6UEP9Elu2CmFfovgDs8sb+FEZOfygcnl8BlRS8CF Il3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779027260; x=1779632060; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=QQ0AMioN9ICp6uPC2mkgQROFQBoTgmc1faz4jD3rols=; b=kFH+Gtu5CkPTnysA1+HbP2TAgUmtjuvn3XoX+3QMfPeGOwDh/K11GPVO7uMzfgdEXT xQQqO5Y1kkc0TFRh2TVLKYMpQ0IIN61YuCdQn5gMz/vpfptHH8OJM7Bu71espt0YGbmE Btrfdqr4+ysR0dsao2f+35T5Q/RgdLOcDP8BoyQ0WO5WhtSgmK1iWf6cVNtY3ZqEAYDC O5bO44oMDpJkbyI4tO5AlMGZ4t1pKJ569CylvkI0KPvJPac+8ImW7Y9JEAc/U1alJ9c/ sRI38Mf9T55DotxV+FZfxdz17q9Go0ZuzX5UsuBAQo0ZhakIdgznr2+3GHikD5SUABdw 4TfQ== X-Forwarded-Encrypted: i=1; AFNElJ8uTUGeLD8Hgd4OFINwwc7nHb82lzJAgfwJqvODS/J0LsoyeD8RXVuWh3Tv8GpILZBtDWv4gEtQwyOZPLI=@vger.kernel.org X-Gm-Message-State: AOJu0YxthUdacYR1izqH+ic4cFpL354rffFzmiOMeuBZLqOQ+KeCaKRl bMkKes+f+Dk8SCHc4w8ZnD9mHK5XJyvliFqYrtcZBTpi2ewN1h+kCZ7R X-Gm-Gg: Acq92OFyJs7IpgZX996zla3le2apF+MgIJkV/qkRDf2/tCB9AFzVFin8SuxSbwI07uy IauVBIks/IrvWhHpInuVmZa7LD2a98mIoP+Vmf2Kf61YiaKCYi0kk17IZR5wEC6Cxbf94lrZxN8 SiOrQX+AZOmqqjrrI8hSXi2RVHOH/dXNcaFJkoIleH53ubb7fYZkc2O3Ca/DOYZWHZWu+li7te9 lavi75DsCr4O8ic5ilOrhZ7fDnjh2JyyLgsk+O4HDpLz4HOKjfckTfx24H70emEo8ZvNHnOBeU8 GYVvheMhPs+MGcO1WCHyanDXxFvpOK6HamzmbCxlHaX9YhD0Z5yrj42UOpTU9TveRaN69yjnIPO qMGfF8Si2r/GpvWFJSkhA3OfvI6yrslnrHQBGo7oWUK3YoFHOr+EPxgA7HO2mevbrmTBEMmtAba wrEd9xEQMfImthsOhxZr5VYaX1NYTJ X-Received: by 2002:a05:6a00:428e:b0:83a:3155:c5e9 with SMTP id d2e1a72fcca58-83f33c34accmr11489015b3a.6.1779027259969; Sun, 17 May 2026 07:14:19 -0700 (PDT) Received: from guoguo-lecoo.lan ([104.28.163.100]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83f19fa5489sm10252528b3a.60.2026.05.17.07.14.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2026 07:14:19 -0700 (PDT) From: Chuanhong Guo Date: Sun, 17 May 2026 22:12:58 +0800 Subject: [PATCH 4/4] clk: add support for siflower sf21-topcrm Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260517-sf21-topcrm-v1-4-438f2e0513ff@gmail.com> References: <20260517-sf21-topcrm-v1-0-438f2e0513ff@gmail.com> In-Reply-To: <20260517-sf21-topcrm-v1-0-438f2e0513ff@gmail.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Michael Turquette , Stephen Boyd , Brian Masney , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, Chuanhong Guo X-Mailer: b4 0.14.3 This commit adds a driver for the Toplevel clock and reset controller found on Siflower SF21A6826/SF21H8898 SoCs. This block contains control for 3 PLLs, several clock mux/gate/divider blocks, and a reset register for on-chip peripherals. There are also two registers for enabling PCIE clock output in this block. They aren't covered by this patch because I can't test those without a PCIE driver. These will be added with the PCIE driver patchset later after I get that working. Signed-off-by: Chuanhong Guo --- drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/siflower/Kconfig | 22 + drivers/clk/siflower/Makefile | 1 + drivers/clk/siflower/clk-sf21-topcrm.c | 1053 ++++++++++++++++++++++++++++= ++++ 5 files changed, 1078 insertions(+) diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig index b2efbe9f6acb..8098e38d5f59 100644 --- a/drivers/clk/Kconfig +++ b/drivers/clk/Kconfig @@ -523,6 +523,7 @@ source "drivers/clk/renesas/Kconfig" source "drivers/clk/rockchip/Kconfig" source "drivers/clk/samsung/Kconfig" source "drivers/clk/sifive/Kconfig" +source "drivers/clk/siflower/Kconfig" source "drivers/clk/socfpga/Kconfig" source "drivers/clk/sophgo/Kconfig" source "drivers/clk/spacemit/Kconfig" diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index a3e2862ebd7e..7492942b7fad 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -144,6 +144,7 @@ obj-y +=3D renesas/ obj-$(CONFIG_ARCH_ROCKCHIP) +=3D rockchip/ obj-$(CONFIG_COMMON_CLK_SAMSUNG) +=3D samsung/ obj-$(CONFIG_CLK_SIFIVE) +=3D sifive/ +obj-$(CONFIG_CLK_SIFLOWER) +=3D siflower/ obj-y +=3D socfpga/ obj-y +=3D sophgo/ obj-y +=3D spacemit/ diff --git a/drivers/clk/siflower/Kconfig b/drivers/clk/siflower/Kconfig new file mode 100644 index 000000000000..03cbfbdbdb8d --- /dev/null +++ b/drivers/clk/siflower/Kconfig @@ -0,0 +1,22 @@ +# SPDX-License-Identifier: GPL-2.0 + +menuconfig CLK_SIFLOWER + bool "Clock driver for Siflower SoCs" + depends on ARCH_SIFLOWER || COMPILE_TEST + default ARCH_SIFLOWER + help + Clock drivers for Siflower Linux-capable SoCs. + +if CLK_SIFLOWER + +config CLK_SF21_TOPCRM + tristate "Clock driver for Siflower SF21 toplevel clock & reset module" + depends on ARCH_SIFLOWER || COMPILE_TEST + default ARCH_SIFLOWER + select RESET_CONTROLLER + help + Supports the toplevel clock and reset module in Siflower SF21 SoCs. + If this kernel is meant to run on Siflower SF21A6826 or SF21H8898, + enable this driver. + +endif diff --git a/drivers/clk/siflower/Makefile b/drivers/clk/siflower/Makefile new file mode 100644 index 000000000000..952a470a4308 --- /dev/null +++ b/drivers/clk/siflower/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_CLK_SF21_TOPCRM) +=3D clk-sf21-topcrm.o diff --git a/drivers/clk/siflower/clk-sf21-topcrm.c b/drivers/clk/siflower/= clk-sf21-topcrm.c new file mode 100644 index 000000000000..7d4c5e370d6d --- /dev/null +++ b/drivers/clk/siflower/clk-sf21-topcrm.c @@ -0,0 +1,1053 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct sf_clk_common { + void __iomem *base; + /* Serializes register RMW sequences shared by clocks and resets. */ + spinlock_t *lock; + struct clk_hw hw; +}; + +static inline struct sf_clk_common *hw_to_sf_clk_common(struct clk_hw *hw) +{ + return container_of(hw, struct sf_clk_common, hw); +} + +static inline u32 sf_readl(struct sf_clk_common *priv, u32 reg) +{ + return readl(priv->base + reg); +} + +static inline void sf_writel(struct sf_clk_common *priv, u32 reg, u32 val) +{ + return writel(val, priv->base + reg); +} + +static inline void sf_rmw(struct sf_clk_common *priv, u32 reg, u32 clr, u3= 2 set) +{ + u32 val; + + val =3D sf_readl(priv, reg); + val &=3D ~clr; + val |=3D set; + sf_writel(priv, reg, val); +} + +#define PLL_CMN_CFG1 0x0 +#define PLL_CMN_BYPASS BIT(27) +#define PLL_CMN_PD BIT(26) +#define PLL_CMN_FBDIV GENMASK(25, 14) +#define PLL_CMN_FBDIV_BITS (25 - 14 + 1) +#define PLL_CMN_POSTDIV_PD BIT(13) +#define PLL_CMN_VCO_PD BIT(12) +#define PLL_CMN_POSTDIV1 GENMASK(11, 9) +#define PLL_CMN_POSTDIV2 GENMASK(8, 6) +#define PLL_CMN_REFDIV GENMASK(5, 0) +#define PLL_CMN_REFDIV_BITS 6 + +#define PLL_CMN_LOCK 0xc8 +#define PLL_DDR_LOCK 0xcc +#define PLL_PCIE_LOCK 0xd4 + +#define CFG_LOAD 0x100 +#define CFG_LOAD_PCIE_PLL BIT(4) +#define CFG_LOAD_DDR_PLL BIT(2) +#define CFG_LOAD_CMN_PLL BIT(1) +#define CFG_LOAD_DIV BIT(0) + +#define PLL_LOCK_TIMEOUT_US 1000 + +static unsigned long sf21_cmnpll_vco_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct sf_clk_common *priv =3D hw_to_sf_clk_common(hw); + u32 cfg =3D sf_readl(priv, PLL_CMN_CFG1); + unsigned long refdiv =3D FIELD_GET(PLL_CMN_REFDIV, cfg); + unsigned long fbdiv =3D FIELD_GET(PLL_CMN_FBDIV, cfg); + + if (!refdiv || !fbdiv) + return 0; + + return (parent_rate / refdiv) * fbdiv; +} + +static int sf21_cmnpll_vco_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + unsigned long fbdiv, refdiv; + + rational_best_approximation(req->rate, req->best_parent_rate, + BIT(PLL_CMN_FBDIV_BITS) - 1, + BIT(PLL_CMN_REFDIV_BITS) - 1, &fbdiv, + &refdiv); + if (!refdiv || !fbdiv) + return -EINVAL; + + req->rate =3D (req->best_parent_rate / refdiv) * fbdiv; + + return 0; +} + +static int sf21_cmnpll_vco_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct sf_clk_common *priv =3D hw_to_sf_clk_common(hw); + unsigned long flags; + unsigned long fbdiv, refdiv; + u32 val; + int ret; + + rational_best_approximation(rate, parent_rate, + BIT(PLL_CMN_FBDIV_BITS) - 1, + BIT(PLL_CMN_REFDIV_BITS) - 1, &fbdiv, + &refdiv); + if (!refdiv || !fbdiv) + return -EINVAL; + + spin_lock_irqsave(priv->lock, flags); + + sf_rmw(priv, PLL_CMN_CFG1, PLL_CMN_REFDIV | PLL_CMN_FBDIV | PLL_CMN_PD, + FIELD_PREP(PLL_CMN_REFDIV, refdiv) | + FIELD_PREP(PLL_CMN_FBDIV, fbdiv)); + sf_writel(priv, CFG_LOAD, CFG_LOAD_CMN_PLL); + sf_writel(priv, CFG_LOAD, 0); + + ret =3D readl_poll_timeout_atomic(priv->base + PLL_CMN_LOCK, val, val & 1, + 0, PLL_LOCK_TIMEOUT_US); + if (ret) + goto out_unlock; + +out_unlock: + spin_unlock_irqrestore(priv->lock, flags); + return ret; +} + +static const struct clk_ops sf21_cmnpll_vco_ops =3D { + .recalc_rate =3D sf21_cmnpll_vco_recalc_rate, + .determine_rate =3D sf21_cmnpll_vco_determine_rate, + .set_rate =3D sf21_cmnpll_vco_set_rate, +}; + +static struct sf_clk_common cmnpll_vco =3D { + .hw.init =3D CLK_HW_INIT_FW_NAME("cmnpll_vco", "xin25m", + &sf21_cmnpll_vco_ops, 0), +}; + +static unsigned long sf21_dualdiv_round_rate(unsigned long rate, + unsigned long parent_rate, + unsigned int range, + unsigned int *diva, + unsigned int *divb) +{ + unsigned int div =3D DIV_ROUND_CLOSEST(parent_rate, rate); + unsigned int best_diff, da, db, cur_div, cur_diff; + + if (div <=3D 1) { + *diva =3D 1; + *divb =3D 1; + return parent_rate; + } + + best_diff =3D div - 1; + *diva =3D 1; + *divb =3D 1; + + for (da =3D 1; da <=3D range; da++) { + db =3D DIV_ROUND_CLOSEST(div, da); + if (db > da) + db =3D da; + + cur_div =3D da * db; + if (div > cur_div) + cur_diff =3D div - cur_div; + else + cur_diff =3D cur_div - div; + + if (cur_diff < best_diff) { + best_diff =3D cur_diff; + *diva =3D da; + *divb =3D db; + } + if (cur_diff =3D=3D 0) + break; + } + + return parent_rate / *diva / *divb; +} + +static int sf21_cmnpll_postdiv_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + unsigned int diva, divb; + + if (!req->rate) + return -EINVAL; + + req->rate =3D sf21_dualdiv_round_rate(req->rate, req->best_parent_rate, + 7, &diva, &divb); + + return 0; +} + +static int sf21_cmnpll_postdiv_set_rate(struct clk_hw *hw, + unsigned long rate, + unsigned long parent_rate) +{ + struct sf_clk_common *priv =3D hw_to_sf_clk_common(hw); + unsigned int diva, divb; + unsigned long flags; + + if (!rate) + return -EINVAL; + + sf21_dualdiv_round_rate(rate, parent_rate, 7, &diva, &divb); + + spin_lock_irqsave(priv->lock, flags); + sf_rmw(priv, PLL_CMN_CFG1, PLL_CMN_POSTDIV1 | PLL_CMN_POSTDIV2, + FIELD_PREP(PLL_CMN_POSTDIV1, diva) | + FIELD_PREP(PLL_CMN_POSTDIV2, divb)); + sf_writel(priv, CFG_LOAD, CFG_LOAD_CMN_PLL); + sf_writel(priv, CFG_LOAD, 0); + spin_unlock_irqrestore(priv->lock, flags); + return 0; +} + +static unsigned long +sf21_cmnpll_postdiv_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct sf_clk_common *priv =3D hw_to_sf_clk_common(hw); + u32 cfg =3D sf_readl(priv, PLL_CMN_CFG1); + unsigned long div1 =3D FIELD_GET(PLL_CMN_POSTDIV1, cfg); + unsigned long div2 =3D FIELD_GET(PLL_CMN_POSTDIV2, cfg); + + if (!div1 || !div2) + return 0; + + return parent_rate / div1 / div2; +} + +static const struct clk_ops sf21_cmnpll_postdiv_ops =3D { + .recalc_rate =3D sf21_cmnpll_postdiv_recalc_rate, + .determine_rate =3D sf21_cmnpll_postdiv_determine_rate, + .set_rate =3D sf21_cmnpll_postdiv_set_rate, +}; + +static struct sf_clk_common cmnpll_postdiv =3D { + .hw.init =3D CLK_HW_INIT_HW("cmnpll_postdiv", &cmnpll_vco.hw, + &sf21_cmnpll_postdiv_ops, 0), +}; + +#define PLL_DDR_CFG1 0x18 +#define PLL_DDR_BYPASS BIT(23) +#define PLL_DDR_PLLEN BIT(22) +#define PLL_DDR_4PHASEEN BIT(21) +#define PLL_DDR_POSTDIVEN BIT(20) +#define PLL_DDR_DSMEN BIT(19) +#define PLL_DDR_DACEN BIT(18) +#define PLL_DDR_DSKEWCALBYP BIT(17) +#define PLL_DDR_DSKEWCALCNT GENMASK(16, 14) +#define PLL_DDR_DSKEWCALEN BIT(13) +#define PLL_DDR_DSKEWCALIN GENMASK(12, 1) +#define PLL_DDR_DSKEWFASTCAL BIT(0) + +#define PLL_DDR_CFG2 0x1c +#define PLL_DDR_POSTDIV1 GENMASK(29, 27) +#define PLL_DDR_POSTDIV2 GENMASK(26, 24) +#define PLL_DDR_FRAC GENMASK(23, 0) + +#define PLL_DDR_CFG3 0x20 +#define PLL_DDR_FBDIV GENMASK(17, 6) +#define PLL_DDR_REFDIV GENMASK(5, 0) + +static unsigned long +sf21_ddrpll_postdiv_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct sf_clk_common *priv =3D hw_to_sf_clk_common(hw); + u32 cfg2 =3D sf_readl(priv, PLL_DDR_CFG2); + u32 postdiv1 =3D FIELD_GET(PLL_DDR_POSTDIV1, cfg2); + u32 postdiv2 =3D FIELD_GET(PLL_DDR_POSTDIV2, cfg2); + u32 cfg3 =3D sf_readl(priv, PLL_DDR_CFG3); + u32 fbdiv =3D FIELD_GET(PLL_DDR_FBDIV, cfg3); + u32 refdiv =3D FIELD_GET(PLL_DDR_REFDIV, cfg3); + + if (!refdiv || !fbdiv || !postdiv1 || !postdiv2) + return 0; + + return (parent_rate / refdiv) * fbdiv / postdiv1 / postdiv2; +} + +static const struct clk_ops sf21_ddrpll_postdiv_ops =3D { + .recalc_rate =3D sf21_ddrpll_postdiv_recalc_rate, +}; + +static struct sf_clk_common ddrpll_postdiv =3D { + .hw.init =3D CLK_HW_INIT_FW_NAME("ddrpll_postdiv", "xin25m", + &sf21_ddrpll_postdiv_ops, 0), +}; + +#define PLL_PCIE_CFG1 0x4c +#define PLL_PCIE_PLLEN BIT(31) +#define PLL_PCIE_POSTDIV0PRE BIT(30) +#define PLL_PCIE_REFDIV GENMASK(29, 24) +#define PLL_PCIE_FRAC GENMASK(23, 0) + +#define PLL_PCIE_CFG2 0x50 +#define PLL_PCIE_FOUTEN(i) BIT(28 + (i)) +#define PLL_PCIE_BYPASS(i) BIT(24 + (i)) +#define PLL_PCIE_PDIVA_OFFS(i) (21 - 6 * (i)) +#define PLL_PCIE_PDIVB_OFFS(i) (18 - 6 * (i)) +#define PLL_PCIE_PDIV_MASK GENMASK(2, 0) + +#define PLL_PCIE_CFG3 0x54 +#define PLL_PCIE_DSKEWFASTCAL BIT(31) +#define PLL_PCIE_DACEN BIT(30) +#define PLL_PCIE_DSMEN BIT(29) +#define PLL_PCIE_DSKEWCALEN BIT(28) +#define PLL_PCIE_DSKEWCALBYP BIT(27) +#define PLL_PCIE_DSKEWCALCNT GENMASK(26, 24) +#define PLL_PCIE_DSKEWCALIN GENMASK(23, 12) +#define PLL_PCIE_FBDIV GENMASK(11, 0) + +static unsigned long +sf21_pciepll_vco_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) +{ + struct sf_clk_common *priv =3D hw_to_sf_clk_common(hw); + u32 cfg1 =3D sf_readl(priv, PLL_PCIE_CFG1); + unsigned long refdiv =3D FIELD_GET(PLL_PCIE_REFDIV, cfg1); + u32 cfg3 =3D sf_readl(priv, PLL_PCIE_CFG3); + unsigned long fbdiv =3D FIELD_GET(PLL_PCIE_FBDIV, cfg3); + + if (!refdiv || !fbdiv) + return 0; + + return (parent_rate / refdiv) * fbdiv / 4; +} + +static int sf21_pciepll_vco_enable(struct clk_hw *hw) +{ + struct sf_clk_common *priv =3D hw_to_sf_clk_common(hw); + unsigned long flags; + u32 val; + int ret; + + spin_lock_irqsave(priv->lock, flags); + sf_rmw(priv, PLL_PCIE_CFG1, 0, PLL_PCIE_PLLEN); + sf_writel(priv, CFG_LOAD, CFG_LOAD_PCIE_PLL); + sf_writel(priv, CFG_LOAD, 0); + ret =3D readl_poll_timeout_atomic(priv->base + PLL_PCIE_LOCK, val, val & = 1, + 0, PLL_LOCK_TIMEOUT_US); + spin_unlock_irqrestore(priv->lock, flags); + return ret; +} + +static void sf21_pciepll_vco_disable(struct clk_hw *hw) +{ + struct sf_clk_common *priv =3D hw_to_sf_clk_common(hw); + unsigned long flags; + + spin_lock_irqsave(priv->lock, flags); + sf_rmw(priv, PLL_PCIE_CFG1, PLL_PCIE_PLLEN, 0); + sf_writel(priv, CFG_LOAD, CFG_LOAD_PCIE_PLL); + sf_writel(priv, CFG_LOAD, 0); + spin_unlock_irqrestore(priv->lock, flags); +} + +static int sf21_pciepll_vco_is_enabled(struct clk_hw *hw) +{ + struct sf_clk_common *priv =3D hw_to_sf_clk_common(hw); + + return !!(sf_readl(priv, PLL_PCIE_CFG1) & PLL_PCIE_PLLEN); +} + +static const struct clk_ops sf21_pciepll_vco_ops =3D { + .enable =3D sf21_pciepll_vco_enable, + .disable =3D sf21_pciepll_vco_disable, + .is_enabled =3D sf21_pciepll_vco_is_enabled, + .recalc_rate =3D sf21_pciepll_vco_recalc_rate, +}; + +static struct sf_clk_common pciepll_vco =3D { + .hw.init =3D CLK_HW_INIT_FW_NAME("pciepll_vco", "xin25m", + &sf21_pciepll_vco_ops, + CLK_SET_RATE_GATE), +}; + +struct sf21_pciepll_fout { + struct sf_clk_common common; + u8 index; +}; + +static int sf21_pciepll_fout_enable(struct clk_hw *hw) +{ + struct sf_clk_common *cmn_priv =3D hw_to_sf_clk_common(hw); + struct sf21_pciepll_fout *priv =3D + container_of(cmn_priv, struct sf21_pciepll_fout, common); + unsigned long flags; + + spin_lock_irqsave(cmn_priv->lock, flags); + sf_rmw(cmn_priv, PLL_PCIE_CFG2, 0, PLL_PCIE_FOUTEN(priv->index)); + sf_writel(cmn_priv, CFG_LOAD, CFG_LOAD_PCIE_PLL); + sf_writel(cmn_priv, CFG_LOAD, 0); + spin_unlock_irqrestore(cmn_priv->lock, flags); + return 0; +} + +static void sf21_pciepll_fout_disable(struct clk_hw *hw) +{ + struct sf_clk_common *cmn_priv =3D hw_to_sf_clk_common(hw); + struct sf21_pciepll_fout *priv =3D + container_of(cmn_priv, struct sf21_pciepll_fout, common); + unsigned long flags; + + spin_lock_irqsave(cmn_priv->lock, flags); + sf_rmw(cmn_priv, PLL_PCIE_CFG2, PLL_PCIE_FOUTEN(priv->index), 0); + sf_writel(cmn_priv, CFG_LOAD, CFG_LOAD_PCIE_PLL); + sf_writel(cmn_priv, CFG_LOAD, 0); + spin_unlock_irqrestore(cmn_priv->lock, flags); +} + +static int sf21_pciepll_fout_is_enabled(struct clk_hw *hw) +{ + struct sf_clk_common *cmn_priv =3D hw_to_sf_clk_common(hw); + struct sf21_pciepll_fout *priv =3D + container_of(cmn_priv, struct sf21_pciepll_fout, common); + + return !!(sf_readl(cmn_priv, PLL_PCIE_CFG2) & + PLL_PCIE_FOUTEN(priv->index)); +} + +static int sf21_pciepll_fout_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + unsigned int diva, divb; + + if (!req->rate) + return -EINVAL; + + req->rate =3D sf21_dualdiv_round_rate(req->rate, req->best_parent_rate, + 8, &diva, &divb); + + return 0; +} + +static int sf21_pciepll_fout_set_rate(struct clk_hw *hw, + unsigned long rate, + unsigned long parent_rate) +{ + struct sf_clk_common *cmn_priv =3D hw_to_sf_clk_common(hw); + struct sf21_pciepll_fout *priv =3D + container_of(cmn_priv, struct sf21_pciepll_fout, common); + unsigned int diva, divb; + unsigned long flags; + + if (!rate) + return -EINVAL; + + sf21_dualdiv_round_rate(rate, parent_rate, 8, &diva, &divb); + + spin_lock_irqsave(cmn_priv->lock, flags); + sf_rmw(cmn_priv, PLL_PCIE_CFG2, + (PLL_PCIE_PDIV_MASK << PLL_PCIE_PDIVA_OFFS(priv->index)) | + (PLL_PCIE_PDIV_MASK << PLL_PCIE_PDIVB_OFFS(priv->index)), + ((diva - 1) << PLL_PCIE_PDIVA_OFFS(priv->index)) | + ((divb - 1) << PLL_PCIE_PDIVB_OFFS(priv->index))); + sf_writel(cmn_priv, CFG_LOAD, CFG_LOAD_PCIE_PLL); + sf_writel(cmn_priv, CFG_LOAD, 0); + spin_unlock_irqrestore(cmn_priv->lock, flags); + return 0; +} + +static unsigned long +sf21_pciepll_fout_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) +{ + struct sf_clk_common *cmn_priv =3D hw_to_sf_clk_common(hw); + struct sf21_pciepll_fout *priv =3D + container_of(cmn_priv, struct sf21_pciepll_fout, common); + int idx =3D priv->index; + u32 cfg2 =3D sf_readl(cmn_priv, PLL_PCIE_CFG2); + ulong pdiva =3D (cfg2 >> PLL_PCIE_PDIVA_OFFS(idx)) & PLL_PCIE_PDIV_MASK; + ulong pdivb =3D (cfg2 >> PLL_PCIE_PDIVB_OFFS(idx)) & PLL_PCIE_PDIV_MASK; + + return parent_rate / (pdiva + 1) / (pdivb + 1); +} + +static const struct clk_ops sf21_pciepll_fout_ops =3D { + .enable =3D sf21_pciepll_fout_enable, + .disable =3D sf21_pciepll_fout_disable, + .is_enabled =3D sf21_pciepll_fout_is_enabled, + .recalc_rate =3D sf21_pciepll_fout_recalc_rate, + .determine_rate =3D sf21_pciepll_fout_determine_rate, + .set_rate =3D sf21_pciepll_fout_set_rate, +}; + +#define SF21_PCIEPLL_FOUT(_name, _idx, _flags) \ + struct sf21_pciepll_fout _name =3D { \ + .common.hw.init =3D CLK_HW_INIT_HW(#_name, \ + &pciepll_vco.hw, \ + &sf21_pciepll_fout_ops,\ + _flags), \ + .index =3D _idx, \ + } + +static SF21_PCIEPLL_FOUT(pciepll_fout0, 0, 0); +static SF21_PCIEPLL_FOUT(pciepll_fout1, 1, 0); +static SF21_PCIEPLL_FOUT(pciepll_fout2, 2, 0); +static SF21_PCIEPLL_FOUT(pciepll_fout3, 3, 0); + +struct sf21_clk_muxdiv { + struct sf_clk_common common; + u16 en; + u8 mux_reg; + u8 mux_offs; + u8 div_reg; + u8 div_offs; +}; + +#define CRM_CLK_SEL(_x) ((_x) * 4 + 0x80) +#define CLK_SEL1_PLL_TEST GENMASK(6, 4) +#define CRM_CLK_EN 0x8c +#define CRM_CLK_DIV(_x) ((_x) * 4 + 0x94) +#define CRM_CLK_DIV_MASK GENMASK(7, 0) + +static unsigned long sf21_muxdiv_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct sf_clk_common *cmn_priv =3D hw_to_sf_clk_common(hw); + struct sf21_clk_muxdiv *priv =3D + container_of(cmn_priv, struct sf21_clk_muxdiv, common); + ulong div_reg =3D CRM_CLK_DIV(priv->div_reg); + u16 div_offs =3D priv->div_offs; + u16 div_val =3D (sf_readl(cmn_priv, div_reg) >> div_offs) & + CRM_CLK_DIV_MASK; + div_val +=3D 1; + return parent_rate / div_val; +} + +static int sf21_muxdiv_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + unsigned int div; + + if (!req->rate) + return -EINVAL; + + div =3D DIV_ROUND_CLOSEST(req->best_parent_rate, req->rate); + if (!div) + div =3D 1; + else if (div > CRM_CLK_DIV_MASK + 1) + div =3D CRM_CLK_DIV_MASK + 1; + + req->rate =3D req->best_parent_rate / div; + return 0; +} + +static int sf21_muxdiv_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct sf_clk_common *cmn_priv =3D hw_to_sf_clk_common(hw); + struct sf21_clk_muxdiv *priv =3D + container_of(cmn_priv, struct sf21_clk_muxdiv, common); + ulong div_reg =3D CRM_CLK_DIV(priv->div_reg); + u16 div_offs =3D priv->div_offs; + unsigned long flags; + unsigned int div; + + if (!rate) + return -EINVAL; + + div =3D DIV_ROUND_CLOSEST(parent_rate, rate); + if (div < 1) + div =3D 1; + else if (div > CRM_CLK_DIV_MASK + 1) + div =3D CRM_CLK_DIV_MASK + 1; + div -=3D 1; + + spin_lock_irqsave(cmn_priv->lock, flags); + sf_rmw(cmn_priv, div_reg, CRM_CLK_DIV_MASK << div_offs, + div << div_offs); + sf_writel(cmn_priv, CFG_LOAD, CFG_LOAD_DIV); + sf_writel(cmn_priv, CFG_LOAD, 0); + spin_unlock_irqrestore(cmn_priv->lock, flags); + return 0; +} + +static int sf21_muxdiv_enable(struct clk_hw *hw) +{ + struct sf_clk_common *cmn_priv =3D hw_to_sf_clk_common(hw); + struct sf21_clk_muxdiv *priv =3D + container_of(cmn_priv, struct sf21_clk_muxdiv, common); + unsigned long flags; + + spin_lock_irqsave(cmn_priv->lock, flags); + sf_rmw(cmn_priv, CRM_CLK_EN, 0, BIT(priv->en)); + /* + * Clock divider value load only happens when the clock is running. + * Pulse the CFG_LOAD_DIV so that set_rate() which happened + * before enable() is applied. + */ + sf_writel(cmn_priv, CFG_LOAD, CFG_LOAD_DIV); + sf_writel(cmn_priv, CFG_LOAD, 0); + spin_unlock_irqrestore(cmn_priv->lock, flags); + return 0; +} + +static void sf21_muxdiv_disable(struct clk_hw *hw) +{ + struct sf_clk_common *cmn_priv =3D hw_to_sf_clk_common(hw); + struct sf21_clk_muxdiv *priv =3D + container_of(cmn_priv, struct sf21_clk_muxdiv, common); + unsigned long flags; + + spin_lock_irqsave(cmn_priv->lock, flags); + sf_rmw(cmn_priv, CRM_CLK_EN, BIT(priv->en), 0); + spin_unlock_irqrestore(cmn_priv->lock, flags); +} + +static int sf21_muxdiv_is_enabled(struct clk_hw *hw) +{ + struct sf_clk_common *cmn_priv =3D hw_to_sf_clk_common(hw); + struct sf21_clk_muxdiv *priv =3D + container_of(cmn_priv, struct sf21_clk_muxdiv, common); + u32 reg_val =3D sf_readl(cmn_priv, CRM_CLK_EN); + + return reg_val & (BIT(priv->en)) ? 1 : 0; +} + +static u8 sf21_muxdiv_get_parent(struct clk_hw *hw) +{ + struct sf_clk_common *cmn_priv =3D hw_to_sf_clk_common(hw); + struct sf21_clk_muxdiv *priv =3D + container_of(cmn_priv, struct sf21_clk_muxdiv, common); + ulong mux_reg =3D CRM_CLK_SEL(priv->mux_reg); + u16 mux_offs =3D priv->mux_offs; + u32 reg_val =3D sf_readl(cmn_priv, mux_reg); + + return reg_val & BIT(mux_offs) ? 1 : 0; +} + +static int sf21_muxdiv_set_parent(struct clk_hw *hw, u8 index) +{ + struct sf_clk_common *cmn_priv =3D hw_to_sf_clk_common(hw); + struct sf21_clk_muxdiv *priv =3D + container_of(cmn_priv, struct sf21_clk_muxdiv, common); + ulong mux_reg =3D CRM_CLK_SEL(priv->mux_reg); + u16 mux_offs =3D priv->mux_offs; + unsigned long flags; + + spin_lock_irqsave(cmn_priv->lock, flags); + if (index) + sf_rmw(cmn_priv, mux_reg, 0, BIT(mux_offs)); + else + sf_rmw(cmn_priv, mux_reg, BIT(mux_offs), 0); + + spin_unlock_irqrestore(cmn_priv->lock, flags); + return 0; +} + +static const struct clk_ops sf21_clk_muxdiv_ops =3D { + .enable =3D sf21_muxdiv_enable, + .disable =3D sf21_muxdiv_disable, + .is_enabled =3D sf21_muxdiv_is_enabled, + .recalc_rate =3D sf21_muxdiv_recalc_rate, + .determine_rate =3D sf21_muxdiv_determine_rate, + .set_rate =3D sf21_muxdiv_set_rate, + .get_parent =3D sf21_muxdiv_get_parent, + .set_parent =3D sf21_muxdiv_set_parent, +}; + +#define SF21_MUXDIV(_name, _parents, _mux_reg, _mux_offs, _div_reg, \ + _div_offs, _en, _flags) \ + struct sf21_clk_muxdiv _name =3D { \ + .common.hw.init =3D CLK_HW_INIT_PARENTS_HW( \ + #_name, _parents, &sf21_clk_muxdiv_ops, _flags), \ + .en =3D _en, \ + .mux_reg =3D _mux_reg, \ + .mux_offs =3D _mux_offs, \ + .div_reg =3D _div_reg, \ + .div_offs =3D _div_offs, \ + } + +static const struct clk_hw *clk_periph_parents[] =3D { + &cmnpll_postdiv.hw, + &ddrpll_postdiv.hw, +}; + +static const struct clk_hw *clk_ddr_parents[] =3D { + &ddrpll_postdiv.hw, + &cmnpll_postdiv.hw, +}; + +static const struct clk_hw *clk_gmac_usb_parents[] =3D { + &cmnpll_vco.hw, + &ddrpll_postdiv.hw, +}; + +static SF21_MUXDIV(muxdiv_cpu, clk_periph_parents, 0, 1, 0, 0, 0, + CLK_IGNORE_UNUSED); +static SF21_MUXDIV(muxdiv_pic, clk_periph_parents, 0, 3, 3, 16, 1, + CLK_IGNORE_UNUSED); +static SF21_MUXDIV(muxdiv_axi, clk_periph_parents, 0, 5, 0, 8, 2, + CLK_IS_CRITICAL); +static SF21_MUXDIV(muxdiv_ahb, clk_periph_parents, 0, 7, 0, 16, 3, + CLK_IS_CRITICAL); +static SF21_MUXDIV(muxdiv_apb, clk_periph_parents, 0, 9, 0, 24, 4, + CLK_IS_CRITICAL); +static SF21_MUXDIV(muxdiv_uart, clk_periph_parents, 0, 11, 1, 0, 5, 0); +static SF21_MUXDIV(muxdiv_iram, clk_periph_parents, 0, 13, 1, 8, 6, 0); +static SF21_MUXDIV(muxdiv_npu, clk_periph_parents, 0, 17, 1, 24, 8, 0); +static SF21_MUXDIV(muxdiv_ddrphy, clk_ddr_parents, 0, 19, 2, 0, 9, + CLK_IS_CRITICAL); +static SF21_MUXDIV(muxdiv_ddr_bypass, clk_ddr_parents, 0, 21, 3, 0, 10, + CLK_IS_CRITICAL); +static SF21_MUXDIV(muxdiv_ethtsu, clk_periph_parents, 0, 25, 2, 16, 12, + 0); +static SF21_MUXDIV(muxdiv_gmac_byp_ref, clk_gmac_usb_parents, 0, 27, 2, + 24, 13, 0); +static SF21_MUXDIV(muxdiv_usb, clk_gmac_usb_parents, 1, 1, 1, 16, 24, 0); +static SF21_MUXDIV(muxdiv_usbphy, clk_gmac_usb_parents, 1, 3, 2, 8, 25, + 0); +static SF21_MUXDIV(muxdiv_serdes_csr, clk_periph_parents, 1, 15, 5, 0, + 20, 0); +static SF21_MUXDIV(muxdiv_crypt_csr, clk_periph_parents, 1, 17, 5, 8, + 21, 0); +static SF21_MUXDIV(muxdiv_crypt_app, clk_periph_parents, 1, 19, 5, 16, + 22, 0); +static SF21_MUXDIV(muxdiv_irom, clk_periph_parents, 1, 21, 5, 24, 23, + CLK_IS_CRITICAL); + +static int sf21_mux_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + req->rate =3D req->best_parent_rate; + return 0; +} + +static const struct clk_ops sf21_clk_mux_ops =3D { + .get_parent =3D sf21_muxdiv_get_parent, + .set_parent =3D sf21_muxdiv_set_parent, + .determine_rate =3D sf21_mux_determine_rate, +}; + +#define SF21_MUX(_name, _parents, _mux_reg, _mux_offs, _flags) \ + struct sf21_clk_muxdiv _name =3D { \ + .common.hw.init =3D CLK_HW_INIT_PARENTS_DATA( \ + #_name, _parents, &sf21_clk_mux_ops, _flags), \ + .en =3D 0, \ + .mux_reg =3D _mux_reg, \ + .mux_offs =3D _mux_offs, \ + .div_reg =3D 0, \ + .div_offs =3D 0, \ + } + +static const struct clk_parent_data clk_boot_parents[] =3D { + { .hw =3D &muxdiv_irom.common.hw }, + { .fw_name =3D "xin25m" }, +}; + +static SF21_MUX(mux_boot, clk_boot_parents, 0, 30, CLK_IS_CRITICAL); + +static const struct clk_ops sf21_clk_div_ops =3D { + .recalc_rate =3D sf21_muxdiv_recalc_rate, + .determine_rate =3D sf21_muxdiv_determine_rate, + .set_rate =3D sf21_muxdiv_set_rate, +}; + +#define SF21_DIV(_name, _parent, _div_reg, _div_offs, _flags) \ + struct sf21_clk_muxdiv _name =3D { \ + .common.hw.init =3D CLK_HW_INIT_FW_NAME( \ + #_name, _parent, &sf21_clk_div_ops, _flags), \ + .en =3D 0, \ + .mux_reg =3D 0, \ + .mux_offs =3D 0, \ + .div_reg =3D _div_reg, \ + .div_offs =3D _div_offs, \ + } + +static SF21_DIV(div_pvt, "xin25m", 3, 8, 0); + +static const struct clk_hw *clk_pll_test_parents[] =3D { + &cmnpll_postdiv.hw, + &ddrpll_postdiv.hw, + &pciepll_fout3.common.hw, +}; + +static u8 sf21_pll_test_get_parent(struct clk_hw *hw) +{ + struct sf_clk_common *cmn_priv =3D hw_to_sf_clk_common(hw); + u32 reg_val =3D sf_readl(cmn_priv, CRM_CLK_SEL(1)); + u8 parent =3D FIELD_GET(CLK_SEL1_PLL_TEST, reg_val); + + if (parent >=3D ARRAY_SIZE(clk_pll_test_parents)) + return 0; + + return parent; +} + +static int sf21_pll_test_set_parent(struct clk_hw *hw, u8 index) +{ + struct sf_clk_common *cmn_priv =3D hw_to_sf_clk_common(hw); + unsigned long flags; + + if (index >=3D ARRAY_SIZE(clk_pll_test_parents)) + return -EINVAL; + + spin_lock_irqsave(cmn_priv->lock, flags); + sf_rmw(cmn_priv, CRM_CLK_SEL(1), CLK_SEL1_PLL_TEST, + FIELD_PREP(CLK_SEL1_PLL_TEST, index)); + spin_unlock_irqrestore(cmn_priv->lock, flags); + return 0; +} + +static const struct clk_ops sf21_clk_pll_test_ops =3D { + .recalc_rate =3D sf21_muxdiv_recalc_rate, + .determine_rate =3D sf21_muxdiv_determine_rate, + .set_rate =3D sf21_muxdiv_set_rate, + .get_parent =3D sf21_pll_test_get_parent, + .set_parent =3D sf21_pll_test_set_parent, +}; + +static struct sf21_clk_muxdiv muxdiv_pll_test =3D { + .common.hw.init =3D CLK_HW_INIT_PARENTS_HW("muxdiv_pll_test", + clk_pll_test_parents, + &sf21_clk_pll_test_ops, 0), + .en =3D 0, + .mux_reg =3D 0, + .mux_offs =3D 0, + .div_reg =3D 3, + .div_offs =3D 24, +}; + +static const struct clk_ops sf21_clk_gate_ops =3D { + .enable =3D sf21_muxdiv_enable, + .disable =3D sf21_muxdiv_disable, + .is_enabled =3D sf21_muxdiv_is_enabled, +}; + +#define SF21_GATE(_name, _parents, _en, _flags) \ + struct sf21_clk_muxdiv _name =3D { \ + .common.hw.init =3D CLK_HW_INIT_PARENTS_HW( \ + #_name, _parents, &sf21_clk_gate_ops, _flags), \ + .en =3D _en, \ + .mux_reg =3D 0, \ + .mux_offs =3D 0, \ + .div_reg =3D 0, \ + .div_offs =3D 0, \ + } + +static const struct clk_hw *clk_pcie_parents[] =3D { + &pciepll_fout1.common.hw, +}; + +static SF21_GATE(pcie_refclk_n, clk_pcie_parents, 15, 0); +static SF21_GATE(pcie_refclk_p, clk_pcie_parents, 16, 0); + +static struct clk_hw_onecell_data sf21_hw_clks =3D { + .num =3D SF21_CLK_MAX, + .hws =3D { + [SF21_CLK_CMNPLL_VCO] =3D &cmnpll_vco.hw, + [SF21_CLK_CMNPLL_POSTDIV] =3D &cmnpll_postdiv.hw, + [SF21_CLK_DDRPLL_POSTDIV] =3D &ddrpll_postdiv.hw, + [SF21_CLK_PCIEPLL_VCO] =3D &pciepll_vco.hw, + [SF21_CLK_PCIEPLL_FOUT0] =3D &pciepll_fout0.common.hw, + [SF21_CLK_PCIEPLL_FOUT1] =3D &pciepll_fout1.common.hw, + [SF21_CLK_PCIEPLL_FOUT2] =3D &pciepll_fout2.common.hw, + [SF21_CLK_PCIEPLL_FOUT3] =3D &pciepll_fout3.common.hw, + [SF21_CLK_CPU] =3D &muxdiv_cpu.common.hw, + [SF21_CLK_PIC] =3D &muxdiv_pic.common.hw, + [SF21_CLK_AXI] =3D &muxdiv_axi.common.hw, + [SF21_CLK_AHB] =3D &muxdiv_ahb.common.hw, + [SF21_CLK_APB] =3D &muxdiv_apb.common.hw, + [SF21_CLK_UART] =3D &muxdiv_uart.common.hw, + [SF21_CLK_IRAM] =3D &muxdiv_iram.common.hw, + [SF21_CLK_NPU] =3D &muxdiv_npu.common.hw, + [SF21_CLK_DDRPHY_REF] =3D &muxdiv_ddrphy.common.hw, + [SF21_CLK_DDR_BYPASS] =3D &muxdiv_ddr_bypass.common.hw, + [SF21_CLK_ETHTSU] =3D &muxdiv_ethtsu.common.hw, + [SF21_CLK_GMAC_BYP_REF] =3D &muxdiv_gmac_byp_ref.common.hw, + [SF21_CLK_USB] =3D &muxdiv_usb.common.hw, + [SF21_CLK_USBPHY] =3D &muxdiv_usbphy.common.hw, + [SF21_CLK_SERDES_CSR] =3D &muxdiv_serdes_csr.common.hw, + [SF21_CLK_CRYPT_CSR] =3D &muxdiv_crypt_csr.common.hw, + [SF21_CLK_CRYPT_APP] =3D &muxdiv_crypt_app.common.hw, + [SF21_CLK_IROM] =3D &muxdiv_irom.common.hw, + [SF21_CLK_BOOT] =3D &mux_boot.common.hw, + [SF21_CLK_PVT] =3D &div_pvt.common.hw, + [SF21_CLK_PLL_TEST] =3D &muxdiv_pll_test.common.hw, + [SF21_CLK_PCIE_REFN] =3D &pcie_refclk_n.common.hw, + [SF21_CLK_PCIE_REFP] =3D &pcie_refclk_p.common.hw, + } +}; + +struct sf21_clk_ctrl { + void __iomem *base; + /* Serializes register RMW sequences shared by clocks and resets. */ + spinlock_t lock; + struct reset_controller_dev rcdev; + const u32 *reset_bits; + unsigned int nr_resets; +}; + +#define SF21_SOFT_RESET 0xc0 + +static const u32 sf21_topcrm_reset_bits[] =3D { + [SF21_RESET_GIC] =3D BIT(1), + [SF21_RESET_AXI] =3D BIT(2), + [SF21_RESET_AHB] =3D BIT(3), + [SF21_RESET_APB] =3D BIT(4), + [SF21_RESET_IRAM] =3D BIT(5), + [SF21_RESET_NPU] =3D BIT(7), + [SF21_RESET_DDR_CTL] =3D BIT(8), + [SF21_RESET_DDR_PHY] =3D BIT(9), + [SF21_RESET_DDR_PWR_OK_IN] =3D BIT(10), + [SF21_RESET_DDR_CTL_APB] =3D BIT(11), + [SF21_RESET_DDR_PHY_APB] =3D BIT(12), + [SF21_RESET_USB] =3D BIT(19), + [SF21_RESET_PVT] =3D BIT(23), + [SF21_RESET_SERDES_CSR] =3D BIT(24), + [SF21_RESET_CRYPT_CSR] =3D BIT(28), + [SF21_RESET_CRYPT_APP] =3D BIT(29), + [SF21_RESET_NPU2DDR_ASYNCBRIDGE] =3D BIT(30), + [SF21_RESET_IROM] =3D BIT(31), +}; + +static inline struct sf21_clk_ctrl * +rcdev_to_sf21_topcrm(struct reset_controller_dev *rcdev) +{ + return container_of(rcdev, struct sf21_clk_ctrl, rcdev); +} + +static int sf21_topcrm_reset_update(struct reset_controller_dev *rcdev, + unsigned long id, bool assert) +{ + struct sf21_clk_ctrl *ctrl =3D rcdev_to_sf21_topcrm(rcdev); + u32 bit =3D ctrl->reset_bits[id]; + unsigned long flags; + u32 reg; + + spin_lock_irqsave(&ctrl->lock, flags); + reg =3D readl(ctrl->base + SF21_SOFT_RESET); + if (assert) + reg &=3D ~bit; + else + reg |=3D bit; + writel(reg, ctrl->base + SF21_SOFT_RESET); + spin_unlock_irqrestore(&ctrl->lock, flags); + + return 0; +} + +static int sf21_topcrm_reset_assert(struct reset_controller_dev *rcdev, + unsigned long id) +{ + return sf21_topcrm_reset_update(rcdev, id, true); +} + +static int sf21_topcrm_reset_deassert(struct reset_controller_dev *rcdev, + unsigned long id) +{ + return sf21_topcrm_reset_update(rcdev, id, false); +} + +static int sf21_topcrm_reset_status(struct reset_controller_dev *rcdev, + unsigned long id) +{ + struct sf21_clk_ctrl *ctrl =3D rcdev_to_sf21_topcrm(rcdev); + u32 bit =3D ctrl->reset_bits[id]; + + return !(readl(ctrl->base + SF21_SOFT_RESET) & bit); +} + +static const struct reset_control_ops sf21_topcrm_reset_ops =3D { + .assert =3D sf21_topcrm_reset_assert, + .deassert =3D sf21_topcrm_reset_deassert, + .status =3D sf21_topcrm_reset_status, +}; + +static int sf21_topcrm_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct sf21_clk_ctrl *ctrl; + int i, ret; + + ctrl =3D devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); + if (!ctrl) + return -ENOMEM; + + ctrl->base =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(ctrl->base)) + return dev_err_probe(dev, PTR_ERR(ctrl->base), + "failed to map resources\n"); + + spin_lock_init(&ctrl->lock); + + for (i =3D 0; i < sf21_hw_clks.num; i++) { + struct clk_hw *hw =3D sf21_hw_clks.hws[i]; + struct sf_clk_common *common; + + if (!hw) + continue; + common =3D hw_to_sf_clk_common(hw); + common->base =3D ctrl->base; + common->lock =3D &ctrl->lock; + ret =3D devm_clk_hw_register(dev, hw); + if (ret) + return dev_err_probe(dev, ret, + "failed to register clock %d\n", + i); + } + + ret =3D devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, + &sf21_hw_clks); + if (ret) + return dev_err_probe(dev, ret, "failed to add hw provider\n"); + + ctrl->reset_bits =3D sf21_topcrm_reset_bits; + ctrl->nr_resets =3D ARRAY_SIZE(sf21_topcrm_reset_bits); + ctrl->rcdev.owner =3D THIS_MODULE; + ctrl->rcdev.nr_resets =3D ctrl->nr_resets; + ctrl->rcdev.ops =3D &sf21_topcrm_reset_ops; + ctrl->rcdev.of_node =3D dev->of_node; + ctrl->rcdev.of_reset_n_cells =3D 1; + + ret =3D devm_reset_controller_register(dev, &ctrl->rcdev); + if (ret) + return dev_err_probe(dev, ret, + "failed to register reset controller\n"); + + return 0; +} + +static const struct of_device_id sf21_topcrm_dt_ids[] =3D { + { .compatible =3D "siflower,sf21-topcrm" }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, sf21_topcrm_dt_ids); + +static struct platform_driver sf21_topcrm_driver =3D { + .probe =3D sf21_topcrm_probe, + .driver =3D { + .name =3D "sf21-topcrm", + .suppress_bind_attrs =3D true, + .of_match_table =3D sf21_topcrm_dt_ids, + }, +}; +module_platform_driver(sf21_topcrm_driver); + +MODULE_AUTHOR("Chuanhong Guo "); +MODULE_DESCRIPTION("driver for Siflower SF21 top clock and reset module"); +MODULE_LICENSE("GPL"); --=20 2.54.0