All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paweł Anikiel" <pan@semihalf.com>
To: marex@denx.de, simon.k.r.goldschmidt@gmail.com,
	tien.fong.chee@intel.com, michal.simek@xilinx.com
Cc: u-boot@lists.denx.de, sjg@chromium.org, festevam@denx.de,
	jagan@amarulasolutions.com, andre.przywara@arm.com,
	narmstrong@baylibre.com, pbrobinson@gmail.com,
	tharvey@gateworks.com, paul.liu@linaro.org,
	christianshewitt@gmail.com, adrian.fiergolski@fastree3d.com,
	marek.behun@nic.cz, wd@denx.de, elly.siew.chin.lim@intel.com,
	upstream@semihalf.com, amstan@chromium.org,
	"Paweł Anikiel" <pan@semihalf.com>
Subject: [PATCH v3 08/11] socfpga: arria10: Replace delays with busy waiting in cm_full_cfg
Date: Fri, 17 Jun 2022 12:47:23 +0200	[thread overview]
Message-ID: <20220617104726.158688-9-pan@semihalf.com> (raw)
In-Reply-To: <20220617104726.158688-1-pan@semihalf.com>

Using udelay while the clocks aren't fully configured causes the timer
system to save the wrong clock rate. Use sdelay and wait_on_value
instead (the values used in these functions were found experimentally).

Signed-off-by: Paweł Anikiel <pan@semihalf.com>
---
 arch/arm/mach-socfpga/clock_manager_arria10.c | 31 +++++++++++++------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/arch/arm/mach-socfpga/clock_manager_arria10.c b/arch/arm/mach-socfpga/clock_manager_arria10.c
index 58d5d3fd8a..b48a2b47bc 100644
--- a/arch/arm/mach-socfpga/clock_manager_arria10.c
+++ b/arch/arm/mach-socfpga/clock_manager_arria10.c
@@ -15,6 +15,10 @@
 
 #ifdef CONFIG_SPL_BUILD
 
+void sdelay(unsigned long loops);
+u32 wait_on_value(u32 read_bit_mask, u32 match_value, void *read_addr,
+		  u32 bound);
+
 static u32 eosc1_hz;
 static u32 cb_intosc_hz;
 static u32 f2s_free_hz;
@@ -551,13 +555,13 @@ static void cm_pll_ramp_main(struct mainpll_cfg *main_cfg,
 			CLKMGR_MAINPLL_VCO1_DENOM_LSB) |
 			cm_calc_safe_pll_numer(0, main_cfg, per_cfg, clk_hz),
 			socfpga_get_clkmgr_addr() + CLKMGR_A10_MAINPLL_VCO1);
-		mdelay(1);
+		sdelay(1000000); /* 1ms */
 		cm_wait_for_lock(LOCKED_MASK);
 	}
 	writel((main_cfg->vco1_denom << CLKMGR_MAINPLL_VCO1_DENOM_LSB) |
 		main_cfg->vco1_numer,
 		socfpga_get_clkmgr_addr() + CLKMGR_A10_MAINPLL_VCO1);
-	mdelay(1);
+	sdelay(1000000); /* 1ms */
 	cm_wait_for_lock(LOCKED_MASK);
 }
 
@@ -585,16 +589,25 @@ static void cm_pll_ramp_periph(struct mainpll_cfg *main_cfg,
 						     clk_hz),
 			      socfpga_get_clkmgr_addr() +
 			      CLKMGR_A10_PERPLL_VCO1);
-		mdelay(1);
+		sdelay(1000000); /* 1ms */
 		cm_wait_for_lock(LOCKED_MASK);
 	}
 	writel((per_cfg->vco1_denom << CLKMGR_PERPLL_VCO1_DENOM_LSB) |
 		      per_cfg->vco1_numer,
 		      socfpga_get_clkmgr_addr() + CLKMGR_A10_PERPLL_VCO1);
-	mdelay(1);
+	sdelay(1000000); /* 1ms */
 	cm_wait_for_lock(LOCKED_MASK);
 }
 
+/* function to poll in the fsm busy bit */
+static int cm_busy_wait_for_fsm(void)
+{
+	void *reg = (void *)(socfpga_get_clkmgr_addr() + CLKMGR_STAT);
+
+	/* 20s timeout */
+	return wait_on_value(CLKMGR_STAT_BUSY, 0, reg, 100000000);
+}
+
 /*
  * Setup clocks while making no assumptions of the
  * previous state of the clocks.
@@ -727,7 +740,7 @@ static int cm_full_cfg(struct mainpll_cfg *main_cfg, struct perpll_cfg *per_cfg)
 			socfpga_get_clkmgr_addr() + CLKMGR_A10_PERPLL_VCO1);
 
 	/* Wait for at least 5 us */
-	udelay(5);
+	sdelay(5000);
 
 	/* Now deassert BGPWRDN and PWRDN */
 	clrbits_le32(socfpga_get_clkmgr_addr() + CLKMGR_A10_MAINPLL_VCO0,
@@ -738,7 +751,7 @@ static int cm_full_cfg(struct mainpll_cfg *main_cfg, struct perpll_cfg *per_cfg)
 		     CLKMGR_PERPLL_VCO0_PWRDN_SET_MSK);
 
 	/* Wait for at least 7 us */
-	udelay(7);
+	sdelay(7000);
 
 	/* enable the VCO and disable the external regulator to PLL */
 	writel((readl(socfpga_get_clkmgr_addr() + CLKMGR_A10_MAINPLL_VCO0) &
@@ -878,19 +891,19 @@ static int cm_full_cfg(struct mainpll_cfg *main_cfg, struct perpll_cfg *per_cfg)
 	writel(CLKMGR_MAINPLL_BYPASS_RESET,
 	       socfpga_get_clkmgr_addr() + CLKMGR_A10_MAINPLL_BYPASSR);
 	/* wait till Clock Manager is not busy */
-	cm_wait_for_fsm();
+	cm_busy_wait_for_fsm();
 
 	/* release perpll from bypass */
 	writel(CLKMGR_PERPLL_BYPASS_RESET,
 	       socfpga_get_clkmgr_addr() + CLKMGR_A10_PERPLL_BYPASSR);
 	/* wait till Clock Manager is not busy */
-	cm_wait_for_fsm();
+	cm_busy_wait_for_fsm();
 
 	/* clear boot mode */
 	clrbits_le32(socfpga_get_clkmgr_addr() + CLKMGR_A10_CTRL,
 		     CLKMGR_CLKMGR_CTL_BOOTMOD_SET_MSK);
 	/* wait till Clock Manager is not busy */
-	cm_wait_for_fsm();
+	cm_busy_wait_for_fsm();
 
 	/* At here, we need to ramp to final value if needed */
 	if (pll_ramp_main_hz != 0)
-- 
2.36.1.476.g0c4daa206d-goog


  parent reply	other threads:[~2022-06-17 10:49 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-17 10:47 [PATCH v3 00/11] Add Chameleon v3 support Paweł Anikiel
2022-06-17 10:47 ` [PATCH v3 01/11] arm: dts: Add Mercury+ AA1 devicetrees Paweł Anikiel
2022-06-17 10:47 ` [PATCH v3 02/11] arm: dts: Add Chameleonv3 handoff headers Paweł Anikiel
2022-06-17 10:47 ` [PATCH v3 03/11] arm: dts: Add Chameleonv3 devicetrees Paweł Anikiel
2022-06-17 10:47 ` [PATCH v3 04/11] board: Add Chameleonv3 board dir Paweł Anikiel
2022-06-17 10:47 ` [PATCH v3 05/11] config: Add Chameleonv3 config Paweł Anikiel
2022-06-17 10:47 ` [PATCH v3 06/11] misc: atsha204a: Increase wake delay by tWHI Paweł Anikiel
2022-06-17 10:47 ` [PATCH v3 07/11] sysreset: socfpga: Use parent device for reading base address Paweł Anikiel
2022-06-17 10:47 ` Paweł Anikiel [this message]
2022-06-20  8:40   ` [PATCH v3 08/11] socfpga: arria10: Replace delays with busy waiting in cm_full_cfg Chee, Tien Fong
2022-06-20 12:13     ` Paweł Anikiel
2022-06-20 12:29       ` Chee, Tien Fong
2022-06-20 15:59         ` Paweł Anikiel
2022-06-23 11:53           ` Chee, Tien Fong
2022-06-17 10:47 ` [PATCH v3 09/11] socfpga: arria10: Improve bitstream loading speed Paweł Anikiel
2022-06-17 10:47 ` [PATCH v3 10/11] socfpga: arria10: Wait for fifo empty after writing bitstream Paweł Anikiel
2022-06-17 10:47 ` [PATCH v3 11/11] socfpga: arria10: Allow dcache_enable before relocation Paweł Anikiel

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=20220617104726.158688-9-pan@semihalf.com \
    --to=pan@semihalf.com \
    --cc=adrian.fiergolski@fastree3d.com \
    --cc=amstan@chromium.org \
    --cc=andre.przywara@arm.com \
    --cc=christianshewitt@gmail.com \
    --cc=elly.siew.chin.lim@intel.com \
    --cc=festevam@denx.de \
    --cc=jagan@amarulasolutions.com \
    --cc=marek.behun@nic.cz \
    --cc=marex@denx.de \
    --cc=michal.simek@xilinx.com \
    --cc=narmstrong@baylibre.com \
    --cc=paul.liu@linaro.org \
    --cc=pbrobinson@gmail.com \
    --cc=simon.k.r.goldschmidt@gmail.com \
    --cc=sjg@chromium.org \
    --cc=tharvey@gateworks.com \
    --cc=tien.fong.chee@intel.com \
    --cc=u-boot@lists.denx.de \
    --cc=upstream@semihalf.com \
    --cc=wd@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.