mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Michael Tretter <m.tretter@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	 BAREBOX <barebox@lists.infradead.org>
Cc: Steffen Trumtrar <s.trumtrar@pengutronix.de>,
	 Michael Tretter <m.tretter@pengutronix.de>
Subject: [PATCH 5/6] arm: socfpga: mailbox_s10: add write_qspi_refclk helper
Date: Wed, 06 May 2026 11:06:11 +0200	[thread overview]
Message-ID: <20260506-socfpga-agilex5-qspi-v1-5-94def85c1b80@pengutronix.de> (raw)
In-Reply-To: <20260506-socfpga-agilex5-qspi-v1-0-94def85c1b80@pengutronix.de>

Add a helper function that hides the actually used register, field, and
format. This makes the code easier to read and allows to move it to a
better location.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
 arch/arm/mach-socfpga/mailbox_s10.c         |  9 +++------
 include/mach/socfpga/soc64-system-manager.h | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-socfpga/mailbox_s10.c b/arch/arm/mach-socfpga/mailbox_s10.c
index c6ea081165d4..417816673c3d 100644
--- a/arch/arm/mach-socfpga/mailbox_s10.c
+++ b/arch/arm/mach-socfpga/mailbox_s10.c
@@ -299,7 +299,6 @@ int socfpga_mailbox_s10_qspi_open(void)
 	int ret;
 	u32 resp_buf[1] = {};
 	u32 resp_buf_len = ARRAY_SIZE(resp_buf);
-	u32 reg;
 	u32 clk_rate;
 	int try = 0;
 
@@ -340,11 +339,9 @@ int socfpga_mailbox_s10_qspi_open(void)
 
 	pr_info("QSPI: reference clock at %d kHz\n", clk_rate / 1000);
 
-	reg = (readl(SOCFPGA_SYSMGR_ADDRESS + SYSMGR_SOC64_BOOT_SCRATCH_COLD0)) &
-			~(SYSMGR_SCRATCH_REG_0_QSPI_REFCLK_MASK);
-
-	writel(((clk_rate / 1000) & SYSMGR_SCRATCH_REG_0_QSPI_REFCLK_MASK) | reg,
-	       SOCFPGA_SYSMGR_ADDRESS + SYSMGR_SOC64_BOOT_SCRATCH_COLD0);
+	ret = socfpga_agilex5_write_qspi_refclk(clk_rate);
+	if (ret)
+		return ret;
 
 	return 0;
 
diff --git a/include/mach/socfpga/soc64-system-manager.h b/include/mach/socfpga/soc64-system-manager.h
index 862e974b1902..a5df69855a28 100644
--- a/include/mach/socfpga/soc64-system-manager.h
+++ b/include/mach/socfpga/soc64-system-manager.h
@@ -8,6 +8,8 @@
 
 #include <linux/bitops.h>
 
+#include <mach/socfpga/soc64-regs.h>
+
 #define SYSMGR_SOC64_SILICONID_1		0x00
 #define SYSMGR_SOC64_SILICONID_2		0x04
 #define SYSMGR_SOC64_WDDBG			0x08
@@ -173,4 +175,23 @@ void agilex5_security_interleaving_off(void);
 void agilex5_initialize_security_policies(void);
 void agilex5_sysmgr_pinmux_init(void);
 
+static inline int socfpga_agilex5_write_qspi_refclk(unsigned long clkrate)
+{
+	unsigned long clkrate_khz;
+	u32 reg;
+
+	/* Follow U-Boot and store clock rate in kHz */
+	clkrate_khz = clkrate / 1000;
+	if (clkrate_khz & ~SYSMGR_SCRATCH_REG_0_QSPI_REFCLK_MASK)
+		return -EINVAL;
+
+	reg = readl(SOCFPGA_SYSMGR_ADDRESS + SYSMGR_SOC64_BOOT_SCRATCH_COLD0);
+	reg &= ~SYSMGR_SCRATCH_REG_0_QSPI_REFCLK_MASK;
+	reg |= (SYSMGR_SCRATCH_REG_0_QSPI_REFCLK_MASK & clkrate_khz);
+
+	writel(reg, SOCFPGA_SYSMGR_ADDRESS + SYSMGR_SOC64_BOOT_SCRATCH_COLD0);
+
+	return 0;
+}
+
 #endif /* _SOC64_SYSTEM_MANAGER_H_ */

-- 
2.47.3




  parent reply	other threads:[~2026-05-06  9:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-06  9:06 [PATCH 0/6] arm: socfpga: agilex5: cleanup QSPI flash low level code Michael Tretter
2026-05-06  9:06 ` [PATCH 1/6] arm: socfpga: agilex5: add missing include soc64-regs.h Michael Tretter
2026-05-06  9:06 ` [PATCH 2/6] arm: socfgpa: agilex5: remove mailbox_s10 from barebox proper Michael Tretter
2026-05-06  9:06 ` [PATCH 3/6] arm: socfpga: agilex5: extract function to request qspi access Michael Tretter
2026-05-06  9:06 ` [PATCH 4/6] arm: socfpga: mailbox_s10: keep clock rate in Hz Michael Tretter
2026-05-06  9:06 ` Michael Tretter [this message]
2026-05-06  9:06 ` [PATCH 6/6] arm: socfpga: agilex5: extract write_qspi_refclk from mailbox Michael Tretter
2026-05-07 10:48 ` [PATCH 0/6] arm: socfpga: agilex5: cleanup QSPI flash low level code Sascha Hauer

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=20260506-socfpga-agilex5-qspi-v1-5-94def85c1b80@pengutronix.de \
    --to=m.tretter@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    --cc=s.trumtrar@pengutronix.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox