Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2479308rdb; Fri, 8 Dec 2023 09:13:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRwUeejzDO/aK8wUdEabQqOnZEDKyQP/38Ayo09WF+X6UhtjkAM9ejsv39FYhExlIL9xh+ X-Received: by 2002:a05:6a20:d385:b0:186:bd68:facc with SMTP id iq5-20020a056a20d38500b00186bd68faccmr551511pzb.28.1702055637489; Fri, 08 Dec 2023 09:13:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702055637; cv=none; d=google.com; s=arc-20160816; b=BsrD9EhfgEFjpdFp4VTlpY4rOt5HSJ6mw4mgB/hvsGh49CuCz0LVD2QgEN45gVRg9X c43DynDCCezVjsuJMB1qvNa5NWTc4783Al6JOvJ7rnBFvfhth9qezpqf6djN3tRPo6+q NKkEFASA9Mrx+naqq9IA6sZr5ad2b+hg3aczLceorwHyVckswOb81Ttno7YGFrejAnq1 3BleTKfZnrskcb3EySr2K9JDy+LBV1zmEacavdue43CLr/sjocIvqMfR8NHgMS1NzWUp 4t4taYbYLLS8uEpt3tAUzE8GBgGDxR8a71iFcjRFpT7J2CFeVEVHWobxS+v9c84Ia9P5 tf/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KVujU2NmKUEEitMUqTAGXzUhBKXz0cq8FiS3P8pHjGI=; fh=7owW42T6ZLRf2RzLwZvq8R8LNTe7zgMt8CKJpj74120=; b=eNrgtGL4Zer4jK5ZeDbFlArEiOzOZ9IvlGVVbkepxantCBR6TfCSarqbCXizN2w627 3M08FX6+/ej8fG655o5GDxlWEkMU7huqii4RuZsjkxkUGZual5/v++7E6ovSGsT2Ynxb x5nB63Y991ypTmAn1bKMXwMPu9IQPh5zYXszmfyh9coMXir0E17mdjCBdKiMNZNYzhUg CYOlbBdTvUljEBw2ZHTie4PBgPf8rjN/9Ai7SACUySXjKjhAVdDQdOoEMDrNQSE8F3iV JkJljhcwx9fVdl4hPEzyNDZXXf1G5Y6DrWBUCo/FMjR5qGOmPxs5+65BiSwPG//CRlZv jrIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KeimEb55; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id b1-20020a056a00114100b006ce702e8930si1836324pfm.215.2023.12.08.09.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 09:13:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KeimEb55; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 9F17182CC472; Fri, 8 Dec 2023 09:13:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233735AbjLHRNL (ORCPT + 99 others); Fri, 8 Dec 2023 12:13:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233790AbjLHRNF (ORCPT ); Fri, 8 Dec 2023 12:13:05 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E528A19A8 for ; Fri, 8 Dec 2023 09:13:10 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FD8DC433C7; Fri, 8 Dec 2023 17:13:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702055590; bh=wG0PAtBtH29YD+lEgHJslL6TUhE1P+xWs/z1DwA9XNA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KeimEb55QS0RBD1y0yZvPtNBR07bwY4SF9exDzMfpH+5NK86HZoaoHLOXVgnOrUBe rCkza+XSi/QYu7+pUpIpsmoPuHWt/VTtQms//XcM8NzIPfbGWtMju0rXo6LqCItzce s01EMiGQFZ+fg3eejyhFKAmAVZttDtrnRIwRPwPgz5RtQxTRrX9mkUWGubY9XlbSmd bvqceIUyj57SaOAMbzdzkTi7+/6sA8yrlm5WqabgmK1RnfgllPZx+4dzwZJmd35m/8 sE+krSDjcEEoc/iuH8hcAowq7T/YLE0nXQ/CBZom8IGc0YIkpk/H/J5SCT0tUr8fiO P7zpxZtU67OkA== From: Conor Dooley To: linux-riscv@lists.infradead.org Cc: conor@kernel.org, Conor Dooley , Daire McNamara , Wolfgang Grandegger , Marc Kleine-Budde , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Michael Turquette , Stephen Boyd , linux-can@vger.kernel.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org Subject: [PATCH RESEND v1 4/7] clk: microchip: mpfs: setup for using other mss pll outputs Date: Fri, 8 Dec 2023 17:12:26 +0000 Message-Id: <20231208-manlike-stainless-95a21ee4ee67@spud> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231208-reenter-ajar-b6223e5134b3@spud> References: <20231208-reenter-ajar-b6223e5134b3@spud> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4670; i=conor.dooley@microchip.com; h=from:subject:message-id; bh=jajlzfigpFa1OeGxZYgOSuQlL+g05VMYN2svv3ZkxAg=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDKnFfhUP76XOD+Su0/mW+uS7Z93b2N5La7d9OK/B27Krz H/ZF7+/HaUsDGIcDLJiiiyJt/tapNb/cdnh3PMWZg4rE8gQBi5OAZiI2UaG/wmfTpwOVq+Yufbu 8Xss1i/eKlU+YZGUk1+WcdxxyaNol3xGhgUfvPWz7Q7zqjmc6Y6P+tRk49B/xE0+4031X8t1qeq 7uAE= X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 08 Dec 2023 09:13:54 -0800 (PST) From: Conor Dooley Now that the MSSPLL is split, and the "postdiv" divider of the cpu/AHB/AXI bus clock is represented by its own "hw" struct, make the shifts, register offset and width a parameter of the initialisation macro, rather than using defines that only work for one of the four outputs. Configuring this at initialisaion paves the way for using the other three output clocks, where the register offset, and the bit shift within that register, will differ. Signed-off-by: Conor Dooley --- drivers/clk/microchip/clk-mpfs.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/clk/microchip/clk-mpfs.c b/drivers/clk/microchip/clk-mpfs.c index b05bdab10cdc..9edd0333e693 100644 --- a/drivers/clk/microchip/clk-mpfs.c +++ b/drivers/clk/microchip/clk-mpfs.c @@ -15,7 +15,8 @@ /* address offset of control registers */ #define REG_MSSPLL_REF_CR 0x08u -#define REG_MSSPLL_POSTDIV_CR 0x10u +#define REG_MSSPLL_POSTDIV01_CR 0x10u +#define REG_MSSPLL_POSTDIV23_CR 0x14u #define REG_MSSPLL_SSCG_2_CR 0x2Cu #define REG_CLOCK_CONFIG_CR 0x08u #define REG_RTC_CLOCK_CR 0x0Cu @@ -26,7 +27,7 @@ #define MSSPLL_FBDIV_WIDTH 0x0Cu #define MSSPLL_REFDIV_SHIFT 0x08u #define MSSPLL_REFDIV_WIDTH 0x06u -#define MSSPLL_POSTDIV_SHIFT 0x08u +#define MSSPLL_POSTDIV02_SHIFT 0x08u #define MSSPLL_POSTDIV_WIDTH 0x07u #define MSSPLL_FIXED_DIV 4u @@ -62,6 +63,9 @@ struct mpfs_msspll_out_hw_clock { struct clk_hw hw; struct clk_init_data init; unsigned int id; + u32 reg_offset; + u32 shift; + u32 width; u32 flags; }; @@ -175,11 +179,11 @@ static int mpfs_clk_register_mssplls(struct device *dev, struct mpfs_msspll_hw_c static unsigned long mpfs_clk_msspll_out_recalc_rate(struct clk_hw *hw, unsigned long prate) { struct mpfs_msspll_out_hw_clock *msspll_out_hw = to_mpfs_msspll_out_clk(hw); - void __iomem *postdiv_addr = msspll_out_hw->base + REG_MSSPLL_POSTDIV_CR; + void __iomem *postdiv_addr = msspll_out_hw->base + msspll_out_hw->reg_offset; u32 postdiv; - postdiv = readl_relaxed(postdiv_addr) >> MSSPLL_POSTDIV_SHIFT; - postdiv &= clk_div_mask(MSSPLL_POSTDIV_WIDTH); + postdiv = readl_relaxed(postdiv_addr) >> msspll_out_hw->shift; + postdiv &= clk_div_mask(msspll_out_hw->width); return prate / postdiv; } @@ -189,19 +193,19 @@ static long mpfs_clk_msspll_out_round_rate(struct clk_hw *hw, unsigned long rate { struct mpfs_msspll_out_hw_clock *msspll_out_hw = to_mpfs_msspll_out_clk(hw); - return divider_round_rate(hw, rate, prate, NULL, MSSPLL_POSTDIV_WIDTH, + return divider_round_rate(hw, rate, prate, NULL, msspll_out_hw->width, msspll_out_hw->flags); } static int mpfs_clk_msspll_out_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long prate) { struct mpfs_msspll_out_hw_clock *msspll_out_hw = to_mpfs_msspll_out_clk(hw); - void __iomem *postdiv_addr = msspll_out_hw->base + REG_MSSPLL_POSTDIV_CR; + void __iomem *postdiv_addr = msspll_out_hw->base + msspll_out_hw->reg_offset; u32 postdiv; int divider_setting; unsigned long flags; - divider_setting = divider_get_val(rate, prate, NULL, MSSPLL_POSTDIV_WIDTH, + divider_setting = divider_get_val(rate, prate, NULL, msspll_out_hw->width, msspll_out_hw->flags); if (divider_setting < 0) @@ -210,7 +214,7 @@ static int mpfs_clk_msspll_out_set_rate(struct clk_hw *hw, unsigned long rate, u spin_lock_irqsave(&mpfs_clk_lock, flags); postdiv = readl_relaxed(postdiv_addr); - postdiv &= ~(clk_div_mask(MSSPLL_POSTDIV_WIDTH) << MSSPLL_POSTDIV_SHIFT); + postdiv &= ~(clk_div_mask(msspll_out_hw->width) << msspll_out_hw->shift); writel_relaxed(postdiv, postdiv_addr); spin_unlock_irqrestore(&mpfs_clk_lock, flags); @@ -224,14 +228,18 @@ static const struct clk_ops mpfs_clk_msspll_out_ops = { .set_rate = mpfs_clk_msspll_out_set_rate, }; -#define CLK_PLL_OUT(_id, _name, _parent, _flags) { \ +#define CLK_PLL_OUT(_id, _name, _parent, _flags, _shift, _width, _offset) { \ .id = _id, \ + .shift = _shift, \ + .width = _width, \ + .reg_offset = _offset, \ .flags = _flags, \ .hw.init = CLK_HW_INIT(_name, _parent, &mpfs_clk_msspll_out_ops, 0), \ } static struct mpfs_msspll_out_hw_clock mpfs_msspll_out_clks[] = { - CLK_PLL_OUT(CLK_MSSPLL, "clk_msspll", "clk_msspll_internal", 0), + CLK_PLL_OUT(CLK_MSSPLL, "clk_msspll", "clk_msspll_internal", 0, + MSSPLL_POSTDIV02_SHIFT, MSSPLL_POSTDIV_WIDTH, REG_MSSPLL_POSTDIV01_CR), }; static int mpfs_clk_register_msspll_outs(struct device *dev, -- 2.39.2