From patchwork Fri Jun 23 20:30:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varshini Rajendran X-Patchwork-Id: 112276 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6031364vqr; Fri, 23 Jun 2023 13:46:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4YtmaeAwgkfOdEAcL21vDOPsSmAn2UsvKSKm6x70fwJclx8y+hCkd1Ro2127gAkqOM2n8p X-Received: by 2002:a05:6830:1d4b:b0:6b4:642b:ae81 with SMTP id p11-20020a0568301d4b00b006b4642bae81mr19755575oth.5.1687553206153; Fri, 23 Jun 2023 13:46:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687553206; cv=none; d=google.com; s=arc-20160816; b=qxoHHJjPzENZ3xBlWH1J3L0MmhtZGql2Ct9jn9XLV6jVxKa2ks+odkbIP0pnpltOhe TUrpElOP0IEhH7B+iPzuchm1vqTcEHEIt3FgikGtsbVAVrh3B+HEvzVIjJGj6AIzD0XV MX5I8Emk8m5u757yQrJcaa6z5La45S47rBOON+IR9ZEjfmLVvfpFmZy1hFRodekW9vvg CWMPR5yO1ZUh3kZC74Sg1O74AIT3JxTh8DzguL2CLyfXP9MLlMPuHm25+frd2UxqKsM3 K7cYOlGfyMV0gOXg80XLoacdsr/1Z6i34dGNBlQd4U6/qpJAiIe1zCQlH1RoKzDpdbIC L60A== 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=7pO+ubjGvIv9gOj5NxYSW+ytGj1N/7xlAoea9TM23MU=; fh=gvF0Lmh3we7l1N050eW0NXEfX6fwK1w/g3y1gvYPqdE=; b=dOMh64ZVbZpSj0YlZK6eBL61Qit5V+2YvVeIce/Ob2mpeMfJxiOBXVLz/7beljsCn4 KfEPHxQhYrYG8y95OiHrXGOXuv3RUanoZk5AWd8EgOghwr1pdVvj30dPtoy5Dc2zLj3a zy4PiSAOO+QtYSRQUuSNzjmProoNog44s/bV69M28yISkLjJoJG13mkb4gCxQGE+MB+M s4XdAAuoEBKGtg7vj+LR41o5xW2VBpq54GWKyLEYX4crurEtkuKsjP2rlo/vlFfqEg8h PQTInESyx4GYQC0QcASyn6NhcYnrF47D6iz5LNtgupWj+XkzNyIrCpVa1kTTbe/kZHv4 kTDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b="sw3K/ej6"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s2-20020a6550c2000000b00553d5cc2c8bsi191294pgp.508.2023.06.23.13.46.33; Fri, 23 Jun 2023 13:46:46 -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="sw3K/ej6"; 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 S232276AbjFWUhJ (ORCPT + 99 others); Fri, 23 Jun 2023 16:37:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232083AbjFWUhB (ORCPT ); Fri, 23 Jun 2023 16:37:01 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DF47273A; Fri, 23 Jun 2023 13:36:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1687552590; x=1719088590; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=H6+qeb5lhbTKb0rFTMW89wX0Vd03nImzkY3g4+gHCu0=; b=sw3K/ej633I0E4UwoLLQQw5Up94xZGy9pdLuwUaBLcqDyG2IrICbuPtp VNla8kxzEhXbpukRaz8OpVp+ToKM/hd9m81y5Q6l4JXnOSXg3ZFqENgKG 8pUVSflTDmFtvMIqTvy4UlQKb3VOcMZiTwbEIs88+XrpdTgA2ZUgdZfFu 7CFf85etT22yI82QY5fcATHNWFf7KZQcH+TtJsKop4C4dN42eT/yDI5dH KRbKLQkqQS1/Bg1b0aRvg6/yT4XAipdK8WnGWGQv9qNMz+rqnlf7CCcPa Egb1LShkhigzx9t8nCwrGOCYzerN3j9hYPbM4Y+6lqtibjj+twKylruwL w==; X-IronPort-AV: E=Sophos;i="6.01,153,1684825200"; d="scan'208";a="219550360" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 23 Jun 2023 13:36:01 -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.21; Fri, 23 Jun 2023 13:35:53 -0700 Received: from che-lt-i67070.amer.actel.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.21 via Frontend Transport; Fri, 23 Jun 2023 13:35:25 -0700 From: Varshini Rajendran To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , Subject: [PATCH v2 09/45] clk: at91: sam9x7: add support for HW PLL freq dividers Date: Sat, 24 Jun 2023 02:00:20 +0530 Message-ID: <20230623203056.689705-10-varshini.rajendran@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230623203056.689705-1-varshini.rajendran@microchip.com> References: <20230623203056.689705-1-varshini.rajendran@microchip.com> MIME-Version: 1.0 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_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769527790370322877?= X-GMAIL-MSGID: =?utf-8?q?1769527790370322877?= 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 b3012641214c..76273ea74f8b 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, @@ -718,10 +740,16 @@ sam9x60_clk_register_div_pll(struct regmap *regmap, spinlock_t *lock, init.name = name; 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 3e36dcc464c1..1dd01f30bdee 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;