Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1393224rwb; Fri, 19 Aug 2022 02:57:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR4KMgJg8lkAe5x3jzN7fzcJGAombgtkDPP9ZFhY7facbCG6H3PDjiqLT+wuDrdM/wCfPIc4 X-Received: by 2002:a17:90b:198a:b0:1f5:2f97:12a0 with SMTP id mv10-20020a17090b198a00b001f52f9712a0mr7261561pjb.97.1660903046602; Fri, 19 Aug 2022 02:57:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660903046; cv=none; d=google.com; s=arc-20160816; b=STA9uSYSKlnnbulDFGjhb1QJgMUSBtFXcfZH3egRC6h5dGwNZhu11FSJ3rJs4VZyEM jWaNk9ZV8qXfsgh6qOh/UjIwW6VyiMNIGkTyOJK7utiO+a31G7LEbaYIeITT3CZLZzV6 GvUa+XyqQv14abuWcd69/vmk5GA6taZAibhnX2tcunNse5uZobRwWXyvX0LjCmU9bvJq TXz3kZvVtcWrc6jWYuneaDmH8A4gIAd0WZwS7AFYqTZmdKKzaeQqqpms/ke6ataGtJN1 j9CHR1w92hwJIPrESxjop10c9Vlx5qgMiQXz3PcLytTTYhmnVnL9sjEZoQ6FNe/VQzBR 9frg== 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=EWVbhfWznADVgq3AuQPbCKmU1afnHKHJkayJHmkwXZ0=; b=ygw+wgPty9X0yDieSl11EAehZciV1hHbGmMhGVGuuyTgL1/8zHNnOa6a5nvY3yb1ZP GOcs/MwZn8TwJiREPl1ltTVD1TKzjq11ZF6ZcBUR9j64epy5a9QJW63atY8JCksr6J8C PXIKUoiYhkf8KfpWv9BT+HmWUXyTst8Z5nFKh7Gkr4BWz+zNVkS4nuuIlTdxykXteXwt oQHcDjGAVzKd2TShacNQgHNFS/1uOcjowGsp7/yn15O4XR7wFJeDPjnZqrlP/SH+uN8H oHPGEGdZAkDkdlCeFMOZ2BBOAp7oKyInMbWXEW9EQPkXQHffAE5B3n93YBK1kWfpqmup leuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=lzkR20BK; 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=pass (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 d4-20020a170903230400b001708af3828fsi4397251plh.62.2022.08.19.02.57.15; Fri, 19 Aug 2022 02:57:26 -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=pass header.i=@microchip.com header.s=mchp header.b=lzkR20BK; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348090AbiHSJz0 (ORCPT + 99 others); Fri, 19 Aug 2022 05:55:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348125AbiHSJzH (ORCPT ); Fri, 19 Aug 2022 05:55:07 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CF43EEF2B; Fri, 19 Aug 2022 02:54:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1660902895; x=1692438895; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4uLFz6Q2WKjcMkrZechUyHOH9QV5mtcZ4CUpZRVa32E=; b=lzkR20BKe7v1W02AnwPfhXYfXsPxh7TNnwj/rblhlG8QZtG0Jlx3gTL3 QSIqB4YxvdMs5TKlhZbYd2NAWIQoAre+9MLu+MR4OJz7xouvif5XFvw54 esxtas36obovgxfXAhHm8B4ww+VofCIMHwXhrnuyU+b+aACthVHwWg7fg atoumGEFPhvW9gWh+NrWOx8pKGeiEHZVgx7uOA3sSl/QlnBJsZdF2rMuT wkB+P0fpEJUP1HkL+AqY5sQb+iZC6Sr1iwyE3r7IorgM7SZV1EwKjah7L xKEOn9v0of+gcgg5M8QOOETDNCy+gUhvkczJnlZfyB6zj5JfgMLNVA/op w==; X-IronPort-AV: E=Sophos;i="5.93,247,1654585200"; d="scan'208";a="170010365" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 19 Aug 2022 02:54:53 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) 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.2507.12; Fri, 19 Aug 2022 02:54:52 -0700 Received: from wendy.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Fri, 19 Aug 2022 02:54:50 -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 v3 07/13] clk: microchip: mpfs: add MSS pll's set & round rate Date: Fri, 19 Aug 2022 10:53:15 +0100 Message-ID: <20220819095320.40006-8-conor.dooley@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220819095320.40006-1-conor.dooley@microchip.com> References: <20220819095320.40006-1-conor.dooley@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-4.4 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. Reviewed-by: Daire McNamara 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 1034f7d69660..3c8cd0094143 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