Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1877499rwn; Fri, 9 Sep 2022 05:33:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR5SSLTIjruVoe9jo1g2Hxe2z7ctTbDjUXWVXy9Utzq7XetVChB7T5Yy2fyRTTYutMAV1bwo X-Received: by 2002:a65:6255:0:b0:42c:87b1:485b with SMTP id q21-20020a656255000000b0042c87b1485bmr12257781pgv.491.1662726836761; Fri, 09 Sep 2022 05:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662726836; cv=none; d=google.com; s=arc-20160816; b=Whvy/bAy0kQtCdIXBaG2CI6puPpi7RvjyYWUkPjuZ6HeDfwU8saD0ehmdMYhfy3gyq CtphC7h4+apQUok31kUAUNHA6OcG4trhQe8YQGmIL5JsMu28bF6UT7VgIFwUCZ8lOGAW jxIdwaFtXLAxm3uUkPLZnxEvv4FGSOuFavcA2JFa7VaQXbpJk1/kIf3Xr8UNjyGgw22+ Fw2SOlSJt0vJm13iGEG3qhuhZzXbUcI810fVmizJ5h0BajENe42EL8eT23NBaz3+Jzmq 7qiFkaWrSIIeeOsawfLX9zDP//MaDIybQA5j0JWl8WK0AO3XgrTEc1zZfCZE/wGz3lXq 6kLQ== 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=y1GXOgXY7/VNnIukoRPRcLMdZ0kuGboKsg3GKTEGH30=; b=LtTfnLvYm/9tMHxTtikMI/Dk9SmlW/wVxuP2JjIDTQlolfYW0YQ0EC4bxjqqHL8hiw cC3T4KqcwSeunxTEyIYtwORPnBKguY/7+gJmU3vn6k7jy8PdZuewz0+W7ZErk0lOSnwx kxfHIwJfFURvKJPpogJlfwkdUsJ+S7s45ZnDnPtFdnjuzKdWFCGIGQwJs3+71av0yUAc Jwy7Nfj4d3TWmYyvcsd+I2INizxRn9H5O5X2PUyzLkqT9pF5Y4at8EpC6W2EVR5p8p0p 7F9LIhKE8f1a3TaQhY1bwqQBOqqZowMxS3HKdZQexq8SySmotgsbooH4TqUxKD92D0lk 4/ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=G3uTYS9N; 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 t11-20020a056a00138b00b0053b89017c91si477240pfg.253.2022.09.09.05.33.44; Fri, 09 Sep 2022 05:33:56 -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=G3uTYS9N; 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 S231669AbiIIMc1 (ORCPT + 99 others); Fri, 9 Sep 2022 08:32:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231631AbiIIMcP (ORCPT ); Fri, 9 Sep 2022 08:32:15 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AABF11C7CD; Fri, 9 Sep 2022 05:32:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1662726731; x=1694262731; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+IIVc307auJRgXB9wfntqv2uBJ0XjYajuLGf8lU3Pmg=; b=G3uTYS9NqWIrUGmMZGk5NRHs6itPGvV/ex0dljtsiYHAPa2OqL3erNtd f1OZb0BrJmzmZ4tDfRAyUWB3B57z2N0bYWC/PUJvf1eaqc7/qQZIbvTFK cQ15LaZ0LxFEM5pmzigjPxIetr3jJMtJd2/tcc7t7/k6UP4fuLn+KqMTH ek0wBaGez0Celi/DQFveyWI/Sx7tRL2LAhRk73GNymJfcjHz69QVoU9cs YtvrbDLY21fnbsintEToDb6GKTQmokxv18kyGFkpX8S9Hi41Wqhnbx/jB bIQcBqqfShsuXXSeBvCFY99wfkEWLCO9j//aOzpxN04afAyz3sM1wsSOh g==; X-IronPort-AV: E=Sophos;i="5.93,303,1654585200"; d="scan'208";a="112926442" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 09 Sep 2022 05:32:10 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Fri, 9 Sep 2022 05:32:09 -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, 9 Sep 2022 05:32:06 -0700 From: Conor Dooley To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Palmer Dabbelt , Conor Dooley , Daire McNamara CC: Paul Walmsley , Albert Ou , Claudiu Beznea , , , , Subject: [PATCH v5 08/14] clk: microchip: mpfs: add MSS pll's set & round rate Date: Fri, 9 Sep 2022 13:31:17 +0100 Message-ID: <20220909123123.2699583-9-conor.dooley@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220909123123.2699583-1-conor.dooley@microchip.com> References: <20220909123123.2699583-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 Reviewed-by: Claudiu Beznea --- 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 610c81ecc526..f40d22293539 100644 --- a/drivers/clk/microchip/clk-mpfs.c +++ b/drivers/clk/microchip/clk-mpfs.c @@ -129,8 +129,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