From patchwork Fri Feb 23 17:27:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varshini Rajendran X-Patchwork-Id: 13569708 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF34FC54798 for ; Fri, 23 Feb 2024 17:35:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XpiE7FpgYPGPMB+AxaBcmo6Ef/6F9CntNLsncHxsR88=; b=3FyHddO4vW8KNK REVu0WeBsoXzDj1vFR7Es8qXGVi58AI82yyBKRoIsoNTdxsw+wPlQyenqsivOGtllF0Th0q8v0cNJ gcmwBLT+Lqwtac3j3j/VsFeyvp89m0xXme6wUFZ3r0MV+ZzK6d0hcnRHHktWFMlqgSchXYSYrWDMJ ienR/fKS+dfEBuagNgIkpZQHR2+L9WmWYFiHzRo/O/4n4JaCnHDTEpiUgSF1IJyBJ3XZuHJB0fSm2 liSfziLfq0XZgxzv1kR7ZjeiMpImvS7tRP494+VyXzvCcBoCa+sxJZvgLvfuejM4wQgbGN7IICGUT iPB2satJ65QZs9+cbRFQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rdZRt-0000000AXa9-2T6W; Fri, 23 Feb 2024 17:35:01 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rdZLa-0000000AU6n-0abU for linux-arm-kernel@bombadil.infradead.org; Fri, 23 Feb 2024 17:28:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description; bh=p3kEunUpevHzeDJZ21R7H45CDuTTg1WSYKiQ2cV5aRk=; b=ZahYhXwkenlOTJZ4ADfjMfeh3u 099dX2mtUo9IX6NpnZ6M26LD4c8AXo4mgXVO9nTGmM8ceSmpO1CVNAhL5veePZDbkviQ7VoFG6+hm HQnWz18qM/yT01f4ksV/gKxFy6dAJSTEBbMKZWKR5uITYKue18iPjuc6gfYwtBPtlHOxUMIXEIIX2 pxWQKNRU2Ik/UO/pmc5TVKhi2gr06gcf2q8v1rnQc67Cpo2xRFPfE+2hgTFyxK6LRDHMKYXEF65J1 1cqTJUL1JWJTicjGUrE7LT+ut0XSmO5nZS94VvFbneyeFLj2uUJS/Tv5ditWdwBxcLhB2HfSfVPZ1 ueIJlOSg==; Received: from esa.microchip.iphmx.com ([68.232.154.123]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rdZLV-000000002HN-1IV3 for linux-arm-kernel@lists.infradead.org; Fri, 23 Feb 2024 17:28:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1708709306; x=1740245306; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=+9RuzNpYmHyqf7fIjBX42rka1JAIk57K6KkiNE8I2wU=; b=I5+/0iVPgOUizxaDH8UBlC1EkIwQVjWs9LqgtNY/7MGbbUag8YAFQx25 X525XHgPdU47iAA9GTQebIIi6pGusqbOytsRdAc8Jn5TOEBfMYTmIkThb uK2RJov2aM5J6ypHRg4XMINRJWQeT+TehnEdSU/qhWXNgDWzsrTJNiGxc 9R0K/1xaLfxLuFLyDerbpo5VkxA9OKSIRSkgMev3+/B8mTDX/3VjLnTRb 81Ec793DrxSVS1/hELJX0oORI2qmcJx5Tz6FJh9lbmdUY9cZxETY1w8nU uSE3QHxsDDbZn3rf/semGDwecJMFE0zXv3CecyNL60u7tv6KKjzXwBf77 A==; X-CSE-ConnectionGUID: cHovNnNySCWyq3qf4VhSKA== X-CSE-MsgGUID: ZbQPapPVTx6bw5cP6MVfuA== X-IronPort-AV: E=Sophos;i="6.06,180,1705388400"; d="scan'208";a="16735967" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 23 Feb 2024 10:28:24 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Fri, 23 Feb 2024 10:28:09 -0700 Received: from che-lt-i67070.microchip.com (10.10.85.11) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Fri, 23 Feb 2024 10:28:05 -0700 From: Varshini Rajendran To: , , , , , , , , , Subject: [PATCH v4 24/39] clk: at91: sam9x7: add support for HW PLL freq dividers Date: Fri, 23 Feb 2024 22:57:58 +0530 Message-ID: <20240223172758.672796-1-varshini.rajendran@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240223171342.669133-1-varshini.rajendran@microchip.com> References: <20240223171342.669133-1-varshini.rajendran@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240223_172826_792126_CD0B490D X-CRM114-Status: GOOD ( 16.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add support for hardware dividers for PLL IDs in sam9x7 SoC. The system PLL - PLLA and the system PLL divided by 2 - PLLADIV2 with PLL ID 0 and 4 respectively, both have a hardware divider /2. This has to taken into account in the software to obtain the right frequencies. Support for the same is added in the PLL driver. fcorepllack -----> HW Div = 2 -+--> fpllack | +--> HW Div = 2 ---> fplladiv2ck In this case the corepll freq is 1600 MHz. So, the plla freq is 800 MHz after the hardware divider and the plladiv2 freq is 400 MHz after the hardware divider (Given that the DIVPMC is 0). Signed-off-by: Varshini Rajendran --- drivers/clk/at91/clk-sam9x60-pll.c | 38 ++++++++++++++++++++++++++---- drivers/clk/at91/pmc.h | 1 + 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/drivers/clk/at91/clk-sam9x60-pll.c b/drivers/clk/at91/clk-sam9x60-pll.c index b0314dfd7393..1f80759309c0 100644 --- a/drivers/clk/at91/clk-sam9x60-pll.c +++ b/drivers/clk/at91/clk-sam9x60-pll.c @@ -73,9 +73,15 @@ static unsigned long sam9x60_frac_pll_recalc_rate(struct clk_hw *hw, { struct sam9x60_pll_core *core = to_sam9x60_pll_core(hw); struct sam9x60_frac *frac = to_sam9x60_frac(core); + unsigned long freq; - return parent_rate * (frac->mul + 1) + + freq = parent_rate * (frac->mul + 1) + DIV_ROUND_CLOSEST_ULL((u64)parent_rate * frac->frac, (1 << 22)); + + if (core->layout->div2) + freq >>= 1; + + return freq; } static int sam9x60_frac_pll_set(struct sam9x60_pll_core *core) @@ -432,6 +438,12 @@ static unsigned long sam9x60_div_pll_recalc_rate(struct clk_hw *hw, return DIV_ROUND_CLOSEST_ULL(parent_rate, (div->div + 1)); } +static unsigned long sam9x60_fixed_div_pll_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + return parent_rate >> 1; +} + static long sam9x60_div_pll_compute_div(struct sam9x60_pll_core *core, unsigned long *parent_rate, unsigned long rate) @@ -606,6 +618,16 @@ static const struct clk_ops sam9x60_div_pll_ops_chg = { .restore_context = sam9x60_div_pll_restore_context, }; +static const struct clk_ops sam9x60_fixed_div_pll_ops = { + .prepare = sam9x60_div_pll_prepare, + .unprepare = sam9x60_div_pll_unprepare, + .is_prepared = sam9x60_div_pll_is_prepared, + .recalc_rate = sam9x60_fixed_div_pll_recalc_rate, + .round_rate = sam9x60_div_pll_round_rate, + .save_context = sam9x60_div_pll_save_context, + .restore_context = sam9x60_div_pll_restore_context, +}; + struct clk_hw * __init sam9x60_clk_register_frac_pll(struct regmap *regmap, spinlock_t *lock, const char *name, const char *parent_name, @@ -725,10 +747,16 @@ sam9x60_clk_register_div_pll(struct regmap *regmap, spinlock_t *lock, else init.parent_names = &parent_name; init.num_parents = 1; - if (flags & CLK_SET_RATE_GATE) - init.ops = &sam9x60_div_pll_ops; - else - init.ops = &sam9x60_div_pll_ops_chg; + + if (layout->div2) { + init.ops = &sam9x60_fixed_div_pll_ops; + } else { + if (flags & CLK_SET_RATE_GATE) + init.ops = &sam9x60_div_pll_ops; + else + init.ops = &sam9x60_div_pll_ops_chg; + } + init.flags = flags; div->core.id = id; diff --git a/drivers/clk/at91/pmc.h b/drivers/clk/at91/pmc.h index bb9da35198d9..91d1c6305d95 100644 --- a/drivers/clk/at91/pmc.h +++ b/drivers/clk/at91/pmc.h @@ -64,6 +64,7 @@ struct clk_pll_layout { u8 frac_shift; u8 div_shift; u8 endiv_shift; + u8 div2; }; extern const struct clk_pll_layout at91rm9200_pll_layout;