public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Yanhong Wang <yanhong.wang@starfivetech.com>
To: <u-boot@lists.denx.de>, Rick Chen <rick@andestech.com>,
	Leo <ycliang@andestech.com>,
	Joe Hershberger <joe.hershberger@ni.com>,
	"Ramon Fried" <rfried.dev@gmail.com>
Cc: Yanhong Wang <yanhong.wang@starfivetech.com>,
	Torsten Duwe <duwe@lst.de>,
	 Leyfoon Tan <leyfoon.tan@starfivetech.com>,
	"samin . guo" <samin.guo@starfivetech.com>,
	Walker Chen <walker.chen@starfivetech.com>
Subject: [PATCH v4 04/11] ram: starfive: Read memory size information from EEPROM
Date: Thu, 25 May 2023 17:36:30 +0800	[thread overview]
Message-ID: <20230525093637.31364-5-yanhong.wang@starfivetech.com> (raw)
In-Reply-To: <20230525093637.31364-1-yanhong.wang@starfivetech.com>

StarFive VisionFive 2 has two versions, 1.2A and 1.3B, each version of
DDR capacity includes 2G/4G/8G, a DT can not support multiple
capacities, so the capacity size information is recorded to EEPROM, when
DDR initialization required capacity size information is read from
EEPROM.

If there is no information in EEPROM, it is initialized with the default
size defined in DT.

Signed-off-by: Yanhong Wang <yanhong.wang@starfivetech.com>
---
 arch/riscv/cpu/jh7110/spl.c         | 32 ++++++++++++++++++++++++++++-
 drivers/ram/starfive/starfive_ddr.c |  2 --
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/cpu/jh7110/spl.c b/arch/riscv/cpu/jh7110/spl.c
index 104f0fe949..72adcefa0e 100644
--- a/arch/riscv/cpu/jh7110/spl.c
+++ b/arch/riscv/cpu/jh7110/spl.c
@@ -3,19 +3,49 @@
  * Copyright (C) 2022 StarFive Technology Co., Ltd.
  * Author: Yanhong Wang<yanhong.wang@starfivetech.com>
  */
-
+#include <common.h>
+#include <asm/arch/eeprom.h>
 #include <asm/csr.h>
 #include <asm/sections.h>
 #include <dm.h>
+#include <linux/sizes.h>
 #include <log.h>
+#include <init.h>
 
 #define CSR_U74_FEATURE_DISABLE	0x7c1
 #define L2_LIM_MEM_END	0x81FFFFFUL
 
+DECLARE_GLOBAL_DATA_PTR;
+
+static bool check_ddr_size(phys_size_t size)
+{
+	switch (size) {
+	case SZ_2:
+	case SZ_4:
+	case SZ_8:
+	case SZ_16:
+		return true;
+	default:
+		return false;
+	}
+}
+
 int spl_soc_init(void)
 {
 	int ret;
 	struct udevice *dev;
+	phys_size_t size;
+
+	ret = fdtdec_setup_mem_size_base();
+	if (ret)
+		return ret;
+
+	/* Read the definition of the DDR size from eeprom, and if not,
+	 * use the definition in DT
+	 */
+	size = (get_ddr_size_from_eeprom() >> 16) & 0xFF;
+	if (check_ddr_size(size))
+		gd->ram_size = size << 30;
 
 	/* DDR init */
 	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
diff --git a/drivers/ram/starfive/starfive_ddr.c b/drivers/ram/starfive/starfive_ddr.c
index 553f2ce6f4..a0a3d6b33d 100644
--- a/drivers/ram/starfive/starfive_ddr.c
+++ b/drivers/ram/starfive/starfive_ddr.c
@@ -72,8 +72,6 @@ static int starfive_ddr_probe(struct udevice *dev)
 	u64 rate;
 	int ret;
 
-	/* Read memory base and size from DT */
-	fdtdec_setup_mem_size_base();
 	priv->info.base = gd->ram_base;
 	priv->info.size = gd->ram_size;
 
-- 
2.17.1


  parent reply	other threads:[~2023-05-25  9:37 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-25  9:36 [PATCH v4 00/11] Add ethernet driver for StarFive JH7110 SoC Yanhong Wang
2023-05-25  9:36 ` [PATCH v4 01/11] net: phy: Add driver for Motorcomm yt8531 gigabit ethernet phy Yanhong Wang
2023-05-25  9:36 ` [PATCH v4 02/11] net: dwc_eth_qos: Add StarFive ethernet driver glue layer Yanhong Wang
2023-05-25  9:36 ` [PATCH v4 03/11] eeprom: starfive: Enable ID EEPROM configuration Yanhong Wang
2023-05-25  9:36 ` Yanhong Wang [this message]
2023-05-25  9:36 ` [PATCH v4 05/11] board: starfive: Dynamic configuration of DT for 1.2A and 1.3B Yanhong Wang
2023-05-25  9:36 ` [PATCH v4 06/11] riscv: dts: jh7110: Add ethernet device tree nodes Yanhong Wang
2023-05-25  9:36 ` [PATCH v4 07/11] riscv: dts: jh7110: Combine the board device tree files of 1.2A and 1.3B Yanhong Wang
2023-05-25  9:36 ` [PATCH v4 08/11] riscv: dts: starfive: Add support eeprom device tree node Yanhong Wang
2023-05-25  9:36 ` [PATCH v4 09/11] doc: board: starfive: Reword the make defconfig information Yanhong Wang
2023-05-25  9:36 ` [PATCH v4 10/11] configs: starfive: Enable ethernet configuration for StarFive VisionFive2 Yanhong Wang
2023-06-04 18:53   ` Jan Kiszka
2023-06-06  7:43     ` yanhong wang
2023-05-25  9:36 ` [PATCH v4 11/11] configs: starfive: Enable ID EEPROM configuration Yanhong Wang
2023-06-04 19:23   ` Jan Kiszka
2023-06-07  2:19     ` yanhong wang
2023-06-07 12:30       ` Jan Kiszka
2023-05-26  7:40 ` [PATCH v4 00/11] Add ethernet driver for StarFive JH7110 SoC Torsten Duwe
2023-06-01 17:44 ` Torsten Duwe
2023-06-02  3:14   ` yanhong wang

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=20230525093637.31364-5-yanhong.wang@starfivetech.com \
    --to=yanhong.wang@starfivetech.com \
    --cc=duwe@lst.de \
    --cc=joe.hershberger@ni.com \
    --cc=leyfoon.tan@starfivetech.com \
    --cc=rfried.dev@gmail.com \
    --cc=rick@andestech.com \
    --cc=samin.guo@starfivetech.com \
    --cc=u-boot@lists.denx.de \
    --cc=walker.chen@starfivetech.com \
    --cc=ycliang@andestech.com \
    /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