mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Alexander Shiyan <eagle.alexander923@gmail.com>
To: barebox@lists.infradead.org
Cc: Alexander Shiyan <eagle.alexander923@gmail.com>
Subject: [RFC 8/8] ARM: OMAP: Move am33xx_sdram_size() into EMIF module and make it generic
Date: Fri,  3 Jun 2022 14:25:40 +0300	[thread overview]
Message-ID: <20220603112540.51644-8-eagle.alexander923@gmail.com> (raw)
In-Reply-To: <20220603112540.51644-1-eagle.alexander923@gmail.com>

Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
 arch/arm/mach-omap/Makefile                   |  2 +-
 arch/arm/mach-omap/am33xx_generic.c           | 53 +------------------
 arch/arm/mach-omap/am33xx_scrm.c              |  4 +-
 arch/arm/mach-omap/emif4.c                    | 50 +++++++++++++++++
 .../mach-omap/include/mach/am33xx-silicon.h   |  1 -
 arch/arm/mach-omap/include/mach/emif4.h       |  2 +
 6 files changed, 58 insertions(+), 54 deletions(-)

diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
index 2c7f577856..88c6b1d594 100644
--- a/arch/arm/mach-omap/Makefile
+++ b/arch/arm/mach-omap/Makefile
@@ -21,7 +21,7 @@ obj-$(CONFIG_ARCH_OMAP3) += omap3_generic.o auxcr.o
 pbl-$(CONFIG_ARCH_OMAP3) += omap3_generic.o auxcr.o
 obj-$(CONFIG_ARCH_OMAP4) += omap4_generic.o omap4_clock.o
 pbl-$(CONFIG_ARCH_OMAP4) += omap4_generic.o omap4_clock.o
-obj-pbl-$(CONFIG_ARCH_AM33XX) += am33xx_generic.o am33xx_clock.o am33xx_mux.o am3xxx.o
+obj-pbl-$(CONFIG_ARCH_AM33XX) += am33xx_generic.o am33xx_clock.o am33xx_mux.o am3xxx.o emif4.o
 obj-pbl-$(CONFIG_ARCH_AM35XX) += am3xxx.o emif4.o
 obj-$(CONFIG_ARCH_AM33XX) += am33xx_scrm.o
 obj-$(CONFIG_ARCH_OMAP3) += omap3_clock.o
diff --git a/arch/arm/mach-omap/am33xx_generic.c b/arch/arm/mach-omap/am33xx_generic.c
index 2727ebdf7f..bfe5b3dc73 100644
--- a/arch/arm/mach-omap/am33xx_generic.c
+++ b/arch/arm/mach-omap/am33xx_generic.c
@@ -342,59 +342,10 @@ void am33xx_config_sdram(const struct am33xx_emif_regs *regs)
 	writel(regs->sdram_config, emif4 + EMIF4_SDRAM_CONFIG);
 }
 
-/**
- * am335x_sdram_size - read back SDRAM size from sdram_config register
- *
- * @return: The SDRAM size
- */
-unsigned long am335x_sdram_size(void)
-{
-	uint32_t sdram_config = readl(IOMEM(AM33XX_EMIF4_BASE + EMIF4_SDRAM_CONFIG));
-	int rows, cols, width, banks;
-	unsigned long size;
-
-	rows = ((sdram_config >> 7) & 0x7) + 9;
-	cols = (sdram_config & 0x7) + 8;
-
-	switch ((sdram_config >> 14) & 0x3) {
-	case 0:
-		width = 4;
-		break;
-	case 1:
-		width = 2;
-		break;
-	default:
-		return 0;
-	}
-
-	switch ((sdram_config >> 4) & 0x7) {
-	case 0:
-		banks = 1;
-		break;
-	case 1:
-		banks = 2;
-		break;
-	case 2:
-		banks = 4;
-		break;
-	case 3:
-		banks = 8;
-		break;
-	default:
-		return 0;
-	}
-
-	size = (1 << rows) * (1 << cols) * banks * width;
-
-	debug("%s: sdram_config: 0x%08x cols: %2d rows: %2d width: %2d banks: %2d size: 0x%08lx\n",
-			__func__, sdram_config, cols, rows, width, banks, size);
-
-	return size;
-}
-
 void __noreturn am335x_barebox_entry(void *boarddata)
 {
-	barebox_arm_entry(0x80000000, am335x_sdram_size(), boarddata);
+	barebox_arm_entry(0x80000000,
+			  emif4_sdram_size(IOMEM(AM33XX_EMIF4_BASE)), boarddata);
 }
 
 void am33xx_config_io_ctrl(int ioctrl)
diff --git a/arch/arm/mach-omap/am33xx_scrm.c b/arch/arm/mach-omap/am33xx_scrm.c
index 0f13a9deb6..e10e80ce31 100644
--- a/arch/arm/mach-omap/am33xx_scrm.c
+++ b/arch/arm/mach-omap/am33xx_scrm.c
@@ -21,10 +21,12 @@
 #include <asm/barebox-arm.h>
 #include <asm/memory.h>
 #include <mach/am33xx-silicon.h>
+#include <mach/emif4.h>
 
 static int am33xx_scrm_probe(struct device_d *dev)
 {
-	return arm_add_mem_device("ram0", 0x80000000, am335x_sdram_size());
+	return arm_add_mem_device("ram0", 0x80000000,
+				  emif4_sdram_size(IOMEM(AM33XX_EMIF4_BASE)));
 }
 
 static __maybe_unused struct of_device_id am33xx_scrm_dt_ids[] = {
diff --git a/arch/arm/mach-omap/emif4.c b/arch/arm/mach-omap/emif4.c
index e61cf00c57..b5a53e8c63 100644
--- a/arch/arm/mach-omap/emif4.c
+++ b/arch/arm/mach-omap/emif4.c
@@ -65,6 +65,56 @@
 #define EMIF4_DDR1_PWRDN_EN	(0x1 << 6)
 #define EMIF4_DDR1_READ_LAT	(0x6 << 0)
 
+/**
+ * emif4_sdram_size - read back SDRAM size from sdram_config register
+ *
+ * @return: The SDRAM size
+ */
+unsigned long emif4_sdram_size(const void __iomem *emif4)
+{
+	uint32_t sdram_config = readl(emif4 + EMIF4_SDRAM_CONFIG);
+	int rows, cols, width, banks;
+	unsigned long size;
+
+	rows = ((sdram_config >> 7) & 0x7) + 9;
+	cols = (sdram_config & 0x7) + 8;
+
+	switch ((sdram_config >> 14) & 0x3) {
+	case 0:
+		width = 4;
+		break;
+	case 1:
+		width = 2;
+		break;
+	default:
+		return 0;
+	}
+
+	switch ((sdram_config >> 4) & 0x7) {
+	case 0:
+		banks = 1;
+		break;
+	case 1:
+		banks = 2;
+		break;
+	case 2:
+		banks = 4;
+		break;
+	case 3:
+		banks = 8;
+		break;
+	default:
+		return 0;
+	}
+
+	size = (1 << rows) * (1 << cols) * banks * width;
+
+	debug("SDRAM_CONFIG: 0x%08x, cols: %2d, rows: %2d, width: %2d, banks: %2d, size: 0x%08lx\n",
+	      sdram_config, cols, rows, width, banks, size);
+
+	return size;
+}
+
 /*
  *  - Init the emif4 module for DDR access
  *  - Early init routines, called from flash or SRAM.
diff --git a/arch/arm/mach-omap/include/mach/am33xx-silicon.h b/arch/arm/mach-omap/include/mach/am33xx-silicon.h
index 671706ff49..74b0b7638e 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-silicon.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-silicon.h
@@ -220,7 +220,6 @@ void am33xx_config_ddr_data(const struct am33xx_ddr_data *data, int macronr);
 void am335x_sdram_init(int ioctrl, const struct am33xx_cmd_control *cmd_ctrl,
 			const struct am33xx_emif_regs *emif_regs,
 			const struct am33xx_ddr_data *ddr_data);
-unsigned long am335x_sdram_size(void);
 void am335x_barebox_entry(void *boarddata);
 
 #endif
diff --git a/arch/arm/mach-omap/include/mach/emif4.h b/arch/arm/mach-omap/include/mach/emif4.h
index 10ecfe6c6b..00702e60e8 100644
--- a/arch/arm/mach-omap/include/mach/emif4.h
+++ b/arch/arm/mach-omap/include/mach/emif4.h
@@ -45,6 +45,8 @@
 #define EMIF4_DDR_PHY_CTRL_2					0xec
 #define EMIF4_IODFT_TLGC					0x60
 
+unsigned long emif4_sdram_size(const void __iomem *emif4);
+
 void am35xx_emif4_init(const void __iomem *emif4);
 
 #endif /* endif _EMIF_H_ */
-- 
2.32.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2022-06-03 11:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-03 11:25 [RFC 1/8] ARM: OMAP: Rearranging EMIF4 definitions Alexander Shiyan
2022-06-03 11:25 ` [RFC 2/8] ARM: OMAP: Move EMIF4 definitions to appropriate header Alexander Shiyan
2022-06-03 11:25 ` [RFC 3/8] ARM: OMAP: Adopt am35xx_emif4_init() to use fixed offset definitions Alexander Shiyan
2022-06-03 11:25 ` [RFC 4/8] ARM: OMAP: Move locally used definitions from emif4 header to am35xx_emif4 Alexander Shiyan
2022-06-03 11:25 ` [RFC 5/8] ARM: OMAP: emif: Abstract am35xx_emif4 from any CPU-specific includes Alexander Shiyan
2022-06-03 11:25 ` [RFC 6/8] ARM: OMAP: emif: Rename am35xx_emif4 unit Alexander Shiyan
2022-06-03 11:25 ` [RFC 7/8] ARM: OMAP: Use EMIF4 registers for get SDRAM size Alexander Shiyan
2022-06-03 11:25 ` Alexander Shiyan [this message]
2022-06-07  7:38 ` [RFC 1/8] ARM: OMAP: Rearranging EMIF4 definitions Sascha Hauer
2022-06-07  7:47   ` Alexander Shiyan

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=20220603112540.51644-8-eagle.alexander923@gmail.com \
    --to=eagle.alexander923@gmail.com \
    --cc=barebox@lists.infradead.org \
    /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