Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp12975695rwd; Fri, 23 Jun 2023 13:37:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VQP7wAM5f5bieSe9ZBjjdtUYHRMX6/f5n1CFReXqsv4RZsF/kfL55wR0Iay0AEg+WjlsU X-Received: by 2002:a17:90b:4ace:b0:259:8305:5d6e with SMTP id mh14-20020a17090b4ace00b0025983055d6emr26658963pjb.0.1687552645069; Fri, 23 Jun 2023 13:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687552645; cv=none; d=google.com; s=arc-20160816; b=rM11jJVysLQ+ko94TLTn9LEfs2e2LXRV8eUmNPKhNW+tX3JlYSUkm9jIXfWuOBHrNd Kqe1abaNI7YBZntGslcVWLiKxjIDD3f20wNrFsJojBIwrQ581ephwU9WNGZxmreYX8CJ 8FiQBDPl7GAzD5N9U7LOlaj9uUj13mpRikRr5vLscr4LpllSOu5EeFUCQ+2cFaAsV3e6 AaSEAQ+sAx608FtH6eeu8VDoYHBbQLhCpIPpwOZOPbdX1We5GNBjr8DkuchRq0mlSrlQ DNomvleaUwmLPYYAhHdv5AGvlopgx6QAyIYnCx82LmMzPLYar37QUzlgvq9ucD2Eon0p uBxw== 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=jcUM3gwx0rI2n3fxN7VeMHZfSi7qYsr2t6DtWj+onH+6/6leyFBkju0lDP6qEazGtx eyPxBUCp6eZZsWcYHctA50nERvwUc+Xr4ep4D9TGxQ1uT5YlXc8+R4M3isTXgeE5kanA k+ptc+K7GTyv+fv2HjEbxRJjaaOSqerrGIkRmS5shgEeMvMEdlMnX3SPoBl7/Di9FSsn yWk0OGf/pYPNiLHP4CuCUPg6s7ne0yx9mEV5XyAnET12DmB+f2CKJp9R/XIc9o8HOVLq 8mQNDrlE3mvXkL7WuMHH/1vkaJJ0FGIz9W3/ocW3VapVyicdx4Cv7RinSPjdHY5vXlXM zrlw== 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-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 u2-20020a17090adb4200b002473e331f90si273408pjx.46.2023.06.23.13.37.11; Fri, 23 Jun 2023 13:37:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 S232251AbjFWUhH (ORCPT + 99 others); Fri, 23 Jun 2023 16:37:07 -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 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_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-crypto@vger.kernel.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 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; -- 2.25.1