All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@kaod.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5 13/13] aspeed: ast2500: fix D2-PLL clock setting in RGMII mode
Date: Mon, 29 Oct 2018 07:06:41 +0100	[thread overview]
Message-ID: <20181029060641.13824-14-clg@kaod.org> (raw)
In-Reply-To: <20181029060641.13824-1-clg@kaod.org>

The algorithm in the ast2500_calc_clock_config() routine suffers from
integer rounding and the requested rate does not get the appropriate
set of Numerator, Denumerator, Post Divider parameters.

This is the case for the D2-PLL clock used by the MAC controllers in
RGMII mode. The requested rated is 250MHz but a 251MHz is assigned.

The easiest way to fix this problem is to introduce an array of clock
settings defining the N, M, P parameters for well known frequencies
used by the Aspeed SoC.

Signed-off-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
---
 drivers/clk/aspeed/clk_ast2500.c | 38 ++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/drivers/clk/aspeed/clk_ast2500.c b/drivers/clk/aspeed/clk_ast2500.c
index 2182320f607f..dbee13a18297 100644
--- a/drivers/clk/aspeed/clk_ast2500.c
+++ b/drivers/clk/aspeed/clk_ast2500.c
@@ -165,6 +165,35 @@ static ulong ast2500_clk_get_rate(struct clk *clk)
 	return rate;
 }
 
+struct ast2500_clock_config {
+	ulong input_rate;
+	ulong rate;
+	struct ast2500_div_config cfg;
+};
+
+static const struct ast2500_clock_config ast2500_clock_config_defaults[] = {
+	{ 24000000, 250000000, { .num = 124, .denum = 1, .post_div = 5 } },
+};
+
+static bool ast2500_get_clock_config_default(ulong input_rate,
+					     ulong requested_rate,
+					     struct ast2500_div_config *cfg)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(ast2500_clock_config_defaults); i++) {
+		const struct ast2500_clock_config *default_cfg =
+			&ast2500_clock_config_defaults[i];
+		if (default_cfg->input_rate == input_rate &&
+		    default_cfg->rate == requested_rate) {
+			*cfg = default_cfg->cfg;
+			return true;
+		}
+	}
+
+	return false;
+}
+
 /*
  * @input_rate - the rate of input clock in Hz
  * @requested_rate - desired output rate in Hz
@@ -189,6 +218,12 @@ static ulong ast2500_calc_clock_config(ulong input_rate, ulong requested_rate,
 	ulong delta = rate_khz;
 	ulong new_rate_khz = 0;
 
+	/*
+	 * Look for a well known frequency first.
+	 */
+	if (ast2500_get_clock_config_default(input_rate, requested_rate, cfg))
+		return requested_rate;
+
 	for (; it.denum <= max_vals.denum; ++it.denum) {
 		for (it.post_div = 0; it.post_div <= max_vals.post_div;
 		     ++it.post_div) {
@@ -318,6 +353,9 @@ static ulong ast2500_configure_d2pll(struct ast2500_scu *scu, ulong rate)
 	/*
 	 * The values and the meaning of the next three
 	 * parameters are undocumented. Taken from Aspeed SDK.
+	 *
+	 * TODO(clg@kaod.org): the SIP and SIC values depend on the
+	 * Numerator value
 	 */
 	const u32 d2_pll_ext_param = 0x2c;
 	const u32 d2_pll_sip = 0x11;
-- 
2.17.2

  parent reply	other threads:[~2018-10-29  6:06 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-29  6:06 [U-Boot] [PATCH v5 00/13] Support for the Faraday ftgmac100 controller Cédric Le Goater
2018-10-29  6:06 ` [U-Boot] [PATCH v5 01/13] net: ftgmac100: use the BIT() macro Cédric Le Goater
2018-11-05 17:53   ` [U-Boot] " Joe Hershberger
2018-10-29  6:06 ` [U-Boot] [PATCH v5 02/13] net: ftgmac100: use the aligned() macro Cédric Le Goater
2018-11-05 17:53   ` [U-Boot] " Joe Hershberger
2018-10-29  6:06 ` [U-Boot] [PATCH v5 03/13] net: ftgmac100: convert to driver model Cédric Le Goater
2018-11-05 17:53   ` [U-Boot] " Joe Hershberger
2018-10-29  6:06 ` [U-Boot] [PATCH v5 04/13] net: ftgmac100: use setbits_le32() in the reset method Cédric Le Goater
2018-11-05 17:53   ` [U-Boot] " Joe Hershberger
2018-10-29  6:06 ` [U-Boot] [PATCH v5 05/13] net: ftgmac100: add MDIO bus and phylib support Cédric Le Goater
2018-11-05 17:53   ` [U-Boot] " Joe Hershberger
2018-10-29  6:06 ` [U-Boot] [PATCH v5 06/13] net: ftgmac100: convert the RX/TX descriptor arrays Cédric Le Goater
2018-11-05 17:53   ` [U-Boot] " Joe Hershberger
2018-10-29  6:06 ` [U-Boot] [PATCH v5 07/13] net: ftgmac100: handle timeouts when transmitting Cédric Le Goater
2018-10-29 19:23   ` Joe Hershberger
2018-11-05 17:53   ` [U-Boot] " Joe Hershberger
2018-10-29  6:06 ` [U-Boot] [PATCH v5 08/13] net: ftgmac100: add clock support Cédric Le Goater
2018-11-05 17:53   ` [U-Boot] " Joe Hershberger
2018-10-29  6:06 ` [U-Boot] [PATCH v5 09/13] aspeed: ast2500: fix missing break in D2PLL clock enablement Cédric Le Goater
2018-11-05 17:53   ` [U-Boot] " Joe Hershberger
2018-10-29  6:06 ` [U-Boot] [PATCH v5 10/13] net: ftgmac100: Add support for the Aspeed SoC Cédric Le Goater
2018-11-05 17:54   ` [U-Boot] " Joe Hershberger
2018-10-29  6:06 ` [U-Boot] [PATCH v5 11/13] aspeed: Update ast2500 SoC DTS file to Linux v4.17-rc6 level Cédric Le Goater
2018-11-05 17:54   ` [U-Boot] " Joe Hershberger
2018-10-29  6:06 ` [U-Boot] [PATCH v5 12/13] aspeed: Activate ethernet devices on the ast2500 Eval Board Cédric Le Goater
2018-11-05 17:54   ` [U-Boot] " Joe Hershberger
2018-10-29  6:06 ` Cédric Le Goater [this message]
2018-11-05 17:54   ` [U-Boot] aspeed: ast2500: fix D2-PLL clock setting in RGMII mode Joe Hershberger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181029060641.13824-14-clg@kaod.org \
    --to=clg@kaod.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.