Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp69988imw; Mon, 4 Jul 2022 05:28:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uhhkMgfRZKGlwh/J6INsrfYDA6w4t3KRaQb2umi6+IXoWMMMtrInuBjD4VqB3Jg3G3lLKx X-Received: by 2002:a17:907:86ac:b0:72a:a7d6:a5db with SMTP id qa44-20020a17090786ac00b0072aa7d6a5dbmr11653720ejc.173.1656937686649; Mon, 04 Jul 2022 05:28:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656937686; cv=none; d=google.com; s=arc-20160816; b=Qlz64jjmfwmPSkig8xZhxP3RcsijO+TZT1iIH7gPy7uOTpjc99GmLBLSSo6O+Ncy92 rnZMv+GqIITP6BIjH23FlMVO7ifiVmE1NpKGgAzfpxdkl5FBugfbHbtM5oFw3jE0gYrL d3g721c1cETC0KFW4QwOsjQSZYUnHyKK1c014S11vh9dal5ygt/zPPR9EXzMnRH+pFia td8tt4QsTlUa7Sx5guuTtMF3IYp2kEAPR7jiAQHUrOiujz79qP71FK3uLorp05BYj1nW bWNL6NEHUxegaDj81AEwiOKCJTqit4l8LpQGI7FDuSdsZvH9Pt4or/uzKzg8Yg28QN40 SRCg== 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=U4gdc5Ke2DI6GAPk4eWILrEGKN5i7YHQSMVjA+OPnK8=; b=cU6gyM4bSoK3j/WUNVSoTV6mbWm6XlwQlm3GfJxo6eFXl3X2ugHJJWVL1V7tZwjfYo E/EZBJm+egKDNbCG2XCQDoco6yck19fU5trxy7MKBYUa0fYpyFLPGCRDCTCigNoUBAiM nw56eO8eCsX870gbjxS0qrB2ZyP2sTIUjwM3B46M8QUo2DUBHp+qcy86jFqbVmaaupVO Kikm9MrvvMLPsv9Iunkv9heaBCUABa+fTVhd/8psRaoHUfNzGrR1rnEbd2eczWuvuhjI DudWFN19yWSLWs3zuKJDhibJmNjWe6vXdLLGbtiv/olEUg+/lhQ+DUiqr0UdCKGFk4OV Ze6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@microchip.com header.s=mchp header.b=E2W027HU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dt5-20020a170907728500b0072ac71ce749si4511422ejc.1004.2022.07.04.05.27.39; Mon, 04 Jul 2022 05:28:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@microchip.com header.s=mchp header.b=E2W027HU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229448AbiGDMQ6 (ORCPT + 99 others); Mon, 4 Jul 2022 08:16:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234177AbiGDMQp (ORCPT ); Mon, 4 Jul 2022 08:16:45 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76EE612080; Mon, 4 Jul 2022 05:16:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1656937003; x=1688473003; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Mzg8ZCgvIj+8F4A33eNTKpQ/g0iJ645P4B1jsOTxDBA=; b=E2W027HUCCd8/3PE5scyyEAhyC3lHCf4YeXD2EtczNZcqdNkFZo/GkrX EsmTN4Jt/RmCneJh1YZI0XwGrNnZi4V/2aN2Dmpg6UwR88hSyBabwsqMZ WMyzJg6Fq4jjhwiX4UEkMbbcI1yqZgqWPtpwSySyq7QG7U4MKVYcnPG33 7Buudt1GfMGitYSvOR44gZ9gQWBGvu36eCsO6s7tlcCH5Du9XMXa75A7K +l3WRBidN1oZWorbXIYpp3TlWSxvro1J6Cwft7jHanwmxio5aAv4q++IH wuD9Yff4LOby7WbFvaGUTHb+RPs2pqfJzQn494/cx3lWZd3BCPRHjHahx w==; X-IronPort-AV: E=Sophos;i="5.92,243,1650956400"; d="scan'208";a="163197495" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 04 Jul 2022 05:16:42 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 4 Jul 2022 05:16:41 -0700 Received: from wendy.microchip.com (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 4 Jul 2022 05:16:38 -0700 From: Conor Dooley To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Palmer Dabbelt , Conor Dooley , Philipp Zabel , Daire McNamara CC: Paul Walmsley , Albert Ou , , , , Subject: [PATCH v2 07/12] clk: microchip: mpfs: add MSS pll's set & round rate Date: Mon, 4 Jul 2022 13:15:54 +0100 Message-ID: <20220704121558.2088698-8-conor.dooley@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220704121558.2088698-1-conor.dooley@microchip.com> References: <20220704121558.2088698-1-conor.dooley@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The MSS pll is not a fixed frequency clock, so add set() & round_rate() support. Control is limited to a 7 bit output divider as other devices on the FPGA occupy the other three outputs of the PLL & prevent changing the multiplier. Signed-off-by: Conor Dooley --- drivers/clk/microchip/clk-mpfs.c | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/clk/microchip/clk-mpfs.c b/drivers/clk/microchip/clk-mpfs.c index c7cafd61b7f7..a23f63bcd074 100644 --- a/drivers/clk/microchip/clk-mpfs.c +++ b/drivers/clk/microchip/clk-mpfs.c @@ -131,8 +131,62 @@ static unsigned long mpfs_clk_msspll_recalc_rate(struct clk_hw *hw, unsigned lon return prate * mult / (ref_div * MSSPLL_FIXED_DIV * postdiv); } +static long mpfs_clk_msspll_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) +{ + struct mpfs_msspll_hw_clock *msspll_hw = to_mpfs_msspll_clk(hw); + void __iomem *mult_addr = msspll_hw->base + msspll_hw->reg_offset; + void __iomem *ref_div_addr = msspll_hw->base + REG_MSSPLL_REF_CR; + u32 mult, ref_div; + unsigned long rate_before_ctrl; + + mult = readl_relaxed(mult_addr) >> MSSPLL_FBDIV_SHIFT; + mult &= clk_div_mask(MSSPLL_FBDIV_WIDTH); + ref_div = readl_relaxed(ref_div_addr) >> MSSPLL_REFDIV_SHIFT; + ref_div &= clk_div_mask(MSSPLL_REFDIV_WIDTH); + + rate_before_ctrl = rate * (ref_div * MSSPLL_FIXED_DIV) / mult; + + return divider_round_rate(hw, rate_before_ctrl, prate, NULL, MSSPLL_POSTDIV_WIDTH, + msspll_hw->flags); +} + +static int mpfs_clk_msspll_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long prate) +{ + struct mpfs_msspll_hw_clock *msspll_hw = to_mpfs_msspll_clk(hw); + void __iomem *mult_addr = msspll_hw->base + msspll_hw->reg_offset; + void __iomem *ref_div_addr = msspll_hw->base + REG_MSSPLL_REF_CR; + void __iomem *postdiv_addr = msspll_hw->base + REG_MSSPLL_POSTDIV_CR; + u32 mult, ref_div, postdiv; + int divider_setting; + unsigned long rate_before_ctrl, flags; + + mult = readl_relaxed(mult_addr) >> MSSPLL_FBDIV_SHIFT; + mult &= clk_div_mask(MSSPLL_FBDIV_WIDTH); + ref_div = readl_relaxed(ref_div_addr) >> MSSPLL_REFDIV_SHIFT; + ref_div &= clk_div_mask(MSSPLL_REFDIV_WIDTH); + + rate_before_ctrl = rate * (ref_div * MSSPLL_FIXED_DIV) / mult; + divider_setting = divider_get_val(rate_before_ctrl, prate, NULL, MSSPLL_POSTDIV_WIDTH, + msspll_hw->flags); + + if (divider_setting < 0) + return divider_setting; + + spin_lock_irqsave(&mpfs_clk_lock, flags); + + postdiv = readl_relaxed(postdiv_addr); + postdiv &= ~(clk_div_mask(MSSPLL_POSTDIV_WIDTH) << MSSPLL_POSTDIV_SHIFT); + writel_relaxed(postdiv, postdiv_addr); + + spin_unlock_irqrestore(&mpfs_clk_lock, flags); + + return 0; +} + static const struct clk_ops mpfs_clk_msspll_ops = { .recalc_rate = mpfs_clk_msspll_recalc_rate, + .round_rate = mpfs_clk_msspll_round_rate, + .set_rate = mpfs_clk_msspll_set_rate, }; #define CLK_PLL(_id, _name, _parent, _shift, _width, _flags, _offset) { \ -- 2.36.1