From patchwork Wed Jan 10 13:31:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JeeHeng Sia X-Patchwork-Id: 186873 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp792159dyi; Wed, 10 Jan 2024 05:34:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IH2usaQBLGMDM4Lgdgqvr6774TaSj6zPg15Fv2s6WbmoTvllB4ir4S02Y8AtOeUiwmczJJ8 X-Received: by 2002:a05:6e02:20c3:b0:360:6ba8:e85a with SMTP id 3-20020a056e0220c300b003606ba8e85amr1269401ilq.38.1704893648869; Wed, 10 Jan 2024 05:34:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704893648; cv=pass; d=google.com; s=arc-20160816; b=RAvzEohFPjXcEKbvbJhHZWOGtVE9vGoeV+QgE7equCnPQCi6GLRMSkf77O7fmVQg0W bkOzWN+WcfxTeL+9yj1RyjFoFDNylwSX1XGWX4tLp0oKsiFGIg06+ljHkiGd3aGfwD3e uc3o44cR/eHvfg/34vXE66V0CBEj6435KUnVwoeTigoMBfZCTWnzkuEd0AEVvirwZmPw wKOy57SSxHB9pihzsY26Iw3LTeKN4XSXR5zWlH+VwpbFd7JdEatdRsh8WxYVVBL5PVXM W3CTs8XMaRFvLAdP5wp5FoqLooIbGNcqB1ruvMiYyHHRahIDbPjJOFy+dTAV2jMP4Aj+ lh6w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :content-transfer-encoding:references:in-reply-to:message-id:date :subject:cc:to:from; bh=lSRkXU9BfabriSMC3ca8IBms3ZqZ3OTXIxVD5Z5+odk=; fh=RhJA/SsSH7HASJYZo/rxwkZKCpI1Kfj/3wSo2/eUkrk=; b=n29JFDOJjfp0WeS0xEzQQ293EZe4sb0ZUVMkneoLfOL2Mh/lvFnHfPdmDHy+G9Prn5 iACjKWwODLzQt9NOvzWIxD1PcXyfyldyYkCzEMMFaJvsWXcESkAhV5sFiganRk63aBYK MNbDjURkgVNuLYmpuunH4q3KxFeteTnSArVbCsT1yxok+bpmNm0God4Dg8w3geKpVQTI UjkH9L7RAiYeWexbUAD882INEtSn4ca0y1TKSy6ygvZII4U9ISlLeoKkF8TCxVMDiuQv uVWbkfJIGIZCAmSrxDkHAwL9GGgCbkK1OWSiUm0ZXvoRfaN+BLfFQP5rLoazMTROcJro hsVg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=starfivetech.com dkim=pass dkdomain=starfivetech.com dmarc=pass fromdomain=starfivetech.com); spf=pass (google.com: domain of linux-kernel+bounces-22240-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22240-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n186-20020a6327c3000000b005ce0a03ccf5si3664927pgn.536.2024.01.10.05.34.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 05:34:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22240-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=starfivetech.com dkim=pass dkdomain=starfivetech.com dmarc=pass fromdomain=starfivetech.com); spf=pass (google.com: domain of linux-kernel+bounces-22240-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22240-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 9B40F289A2E for ; Wed, 10 Jan 2024 13:34:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06BE24B5C8; Wed, 10 Jan 2024 13:32:37 +0000 (UTC) Received: from CHN02-SH0-obe.outbound.protection.partner.outlook.cn (mail-sh0chn02on2051.outbound.protection.partner.outlook.cn [139.219.146.51]) (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 117A748CD2; Wed, 10 Jan 2024 13:32:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=starfivetech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=starfivetech.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iMq5FN8ebFbr/dqY9vwLDrxD9bchv2P7Yfkj27VHbvNl58hgwNeIwCh9xhwoFPtqvbbONEku+6zumI+YQE7Dcb51c+bdlvJAU261uqcwTU0ZiCWHIocgwfv1nW7v8j7DeBRAeRYIH5M1ab7rvuNvj7Vfms3tJ1uPSB1GWx7t52TfslQwTpIC4Jqn2AJ3Ls8dYLdI0HoGGW/6oe65uJQylRB/iJQaV0klgwByUL8VulCTCA+7TdNiV2h5GG1C85jl4gbyIRPPVokKp20FoYXg1zsogIHwzaV0Pl/Tkyt9V2wBAV1aKxbY2j5ltFwovNy/ywTM/7DwQ57xGG18Xs4wGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=lSRkXU9BfabriSMC3ca8IBms3ZqZ3OTXIxVD5Z5+odk=; b=WWxUlZOvsS/jAObbtrVUNZ+XuL2xrNwCGdveheOWoMAIQOse7cDfMHQiPyIdj2e3zqKnYIrGJIDGK8zwcInCJCzYZp1yyCEXWz8BPuty0r5uggmX377m/WdHip/UTRa1ow9mLl0DKrhLv7moDfcfg2pf9gU3v9kfpE5HZ6n3RDX/FwXIChFx0LW1KWrENwqZeHW9NJv7fUdr9duRPPaf/wbnzcMMxCLsWeMrM6vJ/OBJNSqcx0W6iMEmDsFcGuAe9IxVIr1QL9WXp1jc7E6ftAssMjdHeU4dh3J7MbrFkrpgRjvTf86r4xVZq3wYX3xIRamP7/bvpZ/j+8zfSmh5pA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=starfivetech.com; dmarc=pass action=none header.from=starfivetech.com; dkim=pass header.d=starfivetech.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=starfivetech.com; Received: from BJSPR01MB0561.CHNPR01.prod.partner.outlook.cn (2406:e500:c211:f::16) by BJSPR01MB0626.CHNPR01.prod.partner.outlook.cn (2406:e500:c211:10::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.33; Wed, 10 Jan 2024 13:32:27 +0000 Received: from BJSPR01MB0561.CHNPR01.prod.partner.outlook.cn ([fe80::3862:65b4:c857:c4a6]) by BJSPR01MB0561.CHNPR01.prod.partner.outlook.cn ([fe80::3862:65b4:c857:c4a6%4]) with mapi id 15.20.7135.033; Wed, 10 Jan 2024 13:32:27 +0000 From: Sia Jee Heng To: kernel@esmil.dk, conor@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, mturquette@baylibre.com, sboyd@kernel.org, p.zabel@pengutronix.de, emil.renner.berthing@canonical.com, hal.feng@starfivetech.com, xingyu.wu@starfivetech.com Cc: linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, jeeheng.sia@starfivetech.com, leyfoon.tan@starfivetech.com Subject: [RFC v3 12/16] clk: starfive: Add JH8100 South-West clock generator driver Date: Wed, 10 Jan 2024 21:31:24 +0800 Message-Id: <20240110133128.286657-13-jeeheng.sia@starfivetech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240110133128.286657-1-jeeheng.sia@starfivetech.com> References: <20240110133128.286657-1-jeeheng.sia@starfivetech.com> X-ClientProxiedBy: BJXPR01CA0067.CHNPR01.prod.partner.outlook.cn (2406:e500:c211:12::34) To BJSPR01MB0561.CHNPR01.prod.partner.outlook.cn (2406:e500:c211:f::16) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BJSPR01MB0561:EE_|BJSPR01MB0626:EE_ X-MS-Office365-Filtering-Correlation-Id: 8433f7ae-58e4-472d-a711-08dc11e0961c X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Lm3cc2vKNR88UHi5pXXaXMagNMOczNEu8MIP7DefQIAuxRSHj6g5UBxqbwHY2KsihnojoeA15f1tqO4uY9biY2yApX10qH5y+TnJwzgdetrFm8j72HriOJ1E0BTkPZ2fmqPkFD4ZEDGRh6StYDMnmWtTodcU6H/tHX97kEiotwt/N0pm9fr0vDum2HS1y4o5lR9rMwH2w7CNyRnIOe+3oBK+rQrnRKPQRinMhfSf1uvLxaoJ5ngmmSoNtwWAm0uhhT4tczgG3ZifHU9vXNmmJr0wF67oxS3jZk8xR22ECQVckcnYSVZH3a40lncISD8gv5TKgxhHS28Xc+JirjdfKsCT3WyldXvkCeEy4tueT3rByLdrIpEsUhZuw5HsImatdg/co+ERQ5Ea62GB6Z63C16lmGsykbzInezRlwRAy3GmefDtHbgrNeD8LYbqbp6/6oAHfHejY941+mRAauiRFfiuRPJwqp2LuXI3DJ1mY4J01s2Dc1uGr5KfVQn20c18llG0t7uO6Ode0w/QKQ5wc1X6iaEYAxr0EWW8EhHgLhzRpMzxRk7q0VlfG0XkQzzQX0xagSIDSTNPmibpB7T60kk370rZPTnKbHfH3ROpIGqcb3F/ABY6QeqDQ9e8h3mb X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BJSPR01MB0561.CHNPR01.prod.partner.outlook.cn;PTR:;CAT:NONE;SFS:(13230031)(39830400003)(136003)(346002)(396003)(366004)(230273577357003)(230922051799003)(230173577357003)(186009)(64100799003)(451199024)(1800799012)(921011)(26005)(107886003)(52116002)(2616005)(41320700001)(6666004)(83380400001)(1076003)(86362001)(40160700002)(40180700001)(38100700002)(36756003)(38350700005)(5660300002)(7416002)(4326008)(55236004)(6636002)(66556008)(66476007)(66946007)(41300700001)(2906002)(8936002)(8676002)(508600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wOBBZYHV4rkJ6+aPZQWAfKDPMPz/zirmEJqdNwzuSNzAMSRWmvMmQ3pao0Dx338pZYQy8wMaTZaiRMbDRrAen4mrjvruaIbC4OaUDQdrMVK8yIM57NhzPXe1hxzvVbTqtDA54fBRsKNeVFgKhzIJ/g7zZ1cnhrWzPbo2g1xHFH/pFsqqeuavVPK+tREWs3loiOsUWafPbRgEoJtAKnY2BdgDzNpoZDIXkbbN3ytdxd2Lb5xzkKxkxMspUJM0QHKhgmIFu4judne+ojbWrz1xrHApT/9+6CboJnaMD5Loqwz6jC/zqz7Hi6lVQPbP9GRnB4tz4KQoNiXZqvnLu0sNEWdorFE7XUZTBShquCE+KzV9FqRgWk7+85zXu3okoHehvvQGNnSFhfTS35qNEHkjxfEG1JiKQ71D4S2kQo8Bzrk2UMCLXff9Mw/Fc6Z+SXuRcYeWTvTePQG+HbJcqiB1xodHj6BvHYwuCE+QKEjiwmQ+MIeQAywfrM2q1XwLarg2cR4l3Oj8AW3fQqaGAodTakm/Ei7olvaRFn3+7Yn0YXw982isbbFJqk80pYgE2KJD4APEOZFQDuI++ViLjVRS/fsSoyYvzf/0nef7GdMmUa1GzBeyMgidvtIBtg6wYwH15F4+7rYqCuE4e7DRn7j4RSDuwA/xyy88Q5VTDk0Pp5cIL7hcCRhmiMaZfbij+EiU60BoiouL1Z1om3w+M9pqCxOfSyxqSDZm/YwZIKCItkOtu0JzCYmanIXY4TzZ7ErYZo+oTUbz9eFJU8JRPy8vZO8c99EUYuwu7FXMu3JBCqDY90WxGwHRoMp23thbsxguhsGuVTfiHB2AKMtT0WLA2In2W0+za+XHeIEgfkIA18OnRQ6N80q1Ovx0PwUtViqMtTwS3l6QqR2/O6pZhhEFs2OoSV+PrUCMv7VGDMYmxiqf/pZfXtXQeGXQQLNKnRL9nYcIQwCJf/PsVMhBDnQ2aLf5UWpJv6MKyyI8/ZG6gx6zaKHCXnWNLAmYYP81cUgnpF45u1wecEnLeZWCrz2KYulEyG8bm0nPIRgC4o9nOwy7YSmQJ81r/s1wvLtovTYQRAEK8HIWA9b3Lv3t+evv1gZwL1eEdWwIIn5bVj6WrIdWNrIvC9nwlH0Ee02PRBCEjYbrQs1Gn75n030W5HMz/hs4raSiliD55V0w6NzA03oQj/sjRCi2AgcqHdd1VmkvYn4xOrAEYd635xGYmLBuaxbzSdymGKNg0UASn+WlcdWC7omucilfcD6F3Mb6ZUXog0FfM0KQphDC54HV4UeFwYAlLfSnPdJggEOz/XV+oza5sZV4FhqOKmfWCwDq9o6TKLqgq/1ivvOymLaZmX58ZDe8HOjLo/e1q+CSD6nbtQeXVlBtXNtDE5MxxiJ1wEZe4cTfMkl4f3GUMjmVYE5Q50yTG45LQgha6iEppTmXq+6mNJjIKoLUKv387glhgDwp8hruJ+6p1J2Fed6AYHPKe9IrFs1tF8JgsAqbjoq0s3tjv/o7e4RWcHU7SXLw6fLS+up584FdmfKUCZzmGONl7O14xYZZzNBFhJFsDBxy8QulHvi3Xym2IhgjHMGjJISewoVnwKM6Hocu3/nGodeDtoD/np2078bQq3DbPMinK/w= X-OriginatorOrg: starfivetech.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8433f7ae-58e4-472d-a711-08dc11e0961c X-MS-Exchange-CrossTenant-AuthSource: BJSPR01MB0561.CHNPR01.prod.partner.outlook.cn X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2024 13:32:27.0506 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 06fe3fa3-1221-43d3-861b-5a4ee687a85c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: yYRQ3ZIN5CHunGCZPXlJo1fdilGAXkkym3BunxwJoJaS/6CHmUlzhbadJT+OjSr/6C0xm/zqA8vEYnuGnd9+jlljxCtfBQ0VJKFCigJwPmY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BJSPR01MB0626 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787710562608678451 X-GMAIL-MSGID: 1787710562608678451 Add support for JH8100 South-West (SWCRG) clock generator. Signed-off-by: Sia Jee Heng Reviewed-by: Ley Foon Tan --- drivers/clk/starfive/Kconfig | 7 + drivers/clk/starfive/Makefile | 1 + drivers/clk/starfive/clk-starfive-jh8100-sw.c | 134 ++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jh8100-sw.c diff --git a/drivers/clk/starfive/Kconfig b/drivers/clk/starfive/Kconfig index 23968e97969b..23ae894fedb9 100644 --- a/drivers/clk/starfive/Kconfig +++ b/drivers/clk/starfive/Kconfig @@ -95,3 +95,10 @@ config CLK_STARFIVE_JH8100_NE default ARCH_STARFIVE help Say yes here to support the North-East clock controller on the StarFive JH8100 SoC. + +config CLK_STARFIVE_JH8100_SW + bool "StarFive JH8100 South-West clock support" + depends on CLK_STARFIVE_JH8100_SYS + default ARCH_STARFIVE + help + Say yes here to support the South-West clock controller on the StarFive JH8100 SoC. diff --git a/drivers/clk/starfive/Makefile b/drivers/clk/starfive/Makefile index cecce3655600..242e2e75dadb 100644 --- a/drivers/clk/starfive/Makefile +++ b/drivers/clk/starfive/Makefile @@ -14,3 +14,4 @@ obj-$(CONFIG_CLK_STARFIVE_JH7110_VOUT) += clk-starfive-jh7110-vout.o obj-$(CONFIG_CLK_STARFIVE_JH8100_SYS) += clk-starfive-jh8100-sys.o obj-$(CONFIG_CLK_STARFIVE_JH8100_NW) += clk-starfive-jh8100-nw.o obj-$(CONFIG_CLK_STARFIVE_JH8100_NE) += clk-starfive-jh8100-ne.o +obj-$(CONFIG_CLK_STARFIVE_JH8100_SW) += clk-starfive-jh8100-sw.o diff --git a/drivers/clk/starfive/clk-starfive-jh8100-sw.c b/drivers/clk/starfive/clk-starfive-jh8100-sw.c new file mode 100644 index 000000000000..f583f7d984ed --- /dev/null +++ b/drivers/clk/starfive/clk-starfive-jh8100-sw.c @@ -0,0 +1,134 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * StarFive JH8100 South-West Clock Driver + * + * Copyright (C) 2023 StarFive Technology Co., Ltd. + * + * Author: Jee Heng Sia + * + */ + +#include +#include +#include +#include +#include + +#include + +#include "clk-starfive-jh8100.h" + +#define JH8100_SWCLK_NUM_CLKS (JH8100_SWCLK_VDEC_ICG_EN + 1) + +/* external clocks */ +#define JH8100_SWCLK_APB_BUS (JH8100_SWCLK_NUM_CLKS + 0) +#define JH8100_SWCLK_VDEC_ROOT (JH8100_SWCLK_NUM_CLKS + 1) +#define JH8100_SWCLK_FLEXNOC1 (JH8100_SWCLK_NUM_CLKS + 2) + +static const struct starfive_clk_data jh8100_swcrg_clk_data[] = { + /* jpeg */ + STARFIVE__DIV(JH8100_SWCLK_JPEG_AXI, "jpeg_axi", 20, JH8100_SWCLK_VDEC_ROOT), + STARFIVE_GATE(JH8100_SWCLK_VC9000DJ_AXI, "vc9000dj_axi", CLK_IGNORE_UNUSED, + JH8100_SWCLK_JPEG_AXI), + STARFIVE_GDIV(JH8100_SWCLK_VC9000DJ_VDEC, "vc9000dj_vdec", CLK_IGNORE_UNUSED, 40, + JH8100_SWCLK_VDEC_ROOT), + STARFIVE_GATE(JH8100_SWCLK_VC9000DJ_APB, "vc9000dj_apb", CLK_IGNORE_UNUSED, + JH8100_SWCLK_APB_BUS), + /* video dec */ + STARFIVE__DIV(JH8100_SWCLK_VDEC_AXI, "vdec_axi", 20, JH8100_SWCLK_VDEC_ROOT), + STARFIVE_GATE(JH8100_SWCLK_VC9000D_AXI, "vc9000d_axi", CLK_IGNORE_UNUSED, + JH8100_SWCLK_VDEC_AXI), + STARFIVE_GDIV(JH8100_SWCLK_VC9000D_VDEC, "vc9000d_vdec", CLK_IGNORE_UNUSED, 40, + JH8100_SWCLK_FLEXNOC1), + STARFIVE_GATE(JH8100_SWCLK_VC9000D_APB, "vc9000d_apb", CLK_IGNORE_UNUSED, + JH8100_SWCLK_APB_BUS), + /* icg_en */ + STARFIVE_GATE(JH8100_SWCLK_JPEG_ICG_EN, "jpeg_en", 0, JH8100_SWCLK_VDEC_ROOT), + STARFIVE_GATE(JH8100_SWCLK_VDEC_ICG_EN, "vdec_en", 0, JH8100_SWCLK_VDEC_AXI), +}; + +static struct clk_hw *jh8100_swcrg_clk_get(struct of_phandle_args *clkspec, void *data) +{ + struct starfive_clk_priv *priv = data; + unsigned int idx = clkspec->args[0]; + + if (idx < JH8100_SWCLK_NUM_CLKS) + return &priv->reg[idx].hw; + + return ERR_PTR(-EINVAL); +} + +static int jh8100_swcrg_probe(struct platform_device *pdev) +{ + struct starfive_clk_priv *priv; + unsigned int idx; + int ret; + + priv = devm_kzalloc(&pdev->dev, + struct_size(priv, reg, JH8100_SWCLK_NUM_CLKS), + GFP_KERNEL); + if (!priv) + return -ENOMEM; + + spin_lock_init(&priv->rmw_lock); + priv->dev = &pdev->dev; + priv->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); + + for (idx = 0; idx < JH8100_SWCLK_NUM_CLKS; idx++) { + u32 max = jh8100_swcrg_clk_data[idx].max; + struct clk_parent_data parents[4] = {}; + struct clk_init_data init = { + .name = jh8100_swcrg_clk_data[idx].name, + .ops = starfive_clk_ops(max), + .parent_data = parents, + .num_parents = + ((max & STARFIVE_CLK_MUX_MASK) >> STARFIVE_CLK_MUX_SHIFT) + 1, + .flags = jh8100_swcrg_clk_data[idx].flags, + }; + struct starfive_clk *clk = &priv->reg[idx]; + unsigned int i; + + for (i = 0; i < init.num_parents; i++) { + unsigned int pidx = jh8100_swcrg_clk_data[idx].parents[i]; + + if (pidx < JH8100_SWCLK_NUM_CLKS) + parents[i].hw = &priv->reg[pidx].hw; + else if (pidx == JH8100_SWCLK_APB_BUS) + parents[i].fw_name = "apb_bus"; + else if (pidx == JH8100_SWCLK_VDEC_ROOT) + parents[i].fw_name = "vdec_root"; + else if (pidx == JH8100_SWCLK_FLEXNOC1) + parents[i].fw_name = "flexnoc1"; + } + + clk->hw.init = &init; + clk->idx = idx; + clk->max_div = max & STARFIVE_CLK_DIV_MASK; + + ret = devm_clk_hw_register(&pdev->dev, &clk->hw); + if (ret) + return ret; + } + + ret = devm_of_clk_add_hw_provider(&pdev->dev, jh8100_swcrg_clk_get, priv); + if (ret) + return ret; + + return jh8100_reset_controller_register(priv, "rst-sw", 3); +} + +static const struct of_device_id jh8100_swcrg_match[] = { + { .compatible = "starfive,jh8100-swcrg" }, + { /* sentinel */ } +}; + +static struct platform_driver jh8100_swcrg_driver = { + .driver = { + .name = "clk-starfive-jh8100-sw", + .of_match_table = jh8100_swcrg_match, + .suppress_bind_attrs = true, + }, +}; +builtin_platform_driver_probe(jh8100_swcrg_driver, jh8100_swcrg_probe);