U-boot Archive mirror
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
To: Minda Chen <minda.chen@starfivetech.com>,
	Hal Feng <hal.feng@starfivetech.com>,
	Rick Chen <rick@andestech.com>, Leo <ycliang@andestech.com>
Cc: Aurelien Jarno <aurelien@aurel32.net>,
	Lukasz Tekieli <tekieli.lukasz@gmail.com>,
	Lukas Funke <lukas.funke@weidmueller.com>,
	Shiji Yang <yangshiji66@outlook.com>,
	Shengyu Qu <wiagn233@outlook.com>,
	Michal Simek <michal.simek@amd.com>,
	Seung-Woo Kim <sw0312.kim@samsung.com>,
	Mason Huo <mason.huo@starfivetech.com>,
	E Shattow <lucent@gmail.com>,
	u-boot@lists.denx.de,
	Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Subject: [PATCH v4 1/5] board: starfive: function to read eMMC size
Date: Sun, 12 May 2024 06:25:22 +0200	[thread overview]
Message-ID: <20240512042528.7766-2-heinrich.schuchardt@canonical.com> (raw)
In-Reply-To: <20240512042528.7766-1-heinrich.schuchardt@canonical.com>

The EEPROM provides information about the size of the eMMC.
Provide a new function get_mmc_size_from_eeprom() to read it.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: E. Shattow <lucent@gmail.com>
---
v5:
	no change
v4:
	no change
v3:
	no change
v2:
	fix typos in get_mmc_size_from_eeprom() description
---
 arch/riscv/include/asm/arch-jh7110/eeprom.h    |  7 +++++++
 board/starfive/visionfive2/Kconfig             |  9 +++++++++
 .../visionfive2/visionfive2-i2c-eeprom.c       | 18 ++++++++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/arch/riscv/include/asm/arch-jh7110/eeprom.h b/arch/riscv/include/asm/arch-jh7110/eeprom.h
index 62d184aeb57..45ad2a5f7bc 100644
--- a/arch/riscv/include/asm/arch-jh7110/eeprom.h
+++ b/arch/riscv/include/asm/arch-jh7110/eeprom.h
@@ -12,6 +12,13 @@
 u8 get_pcb_revision_from_eeprom(void);
 u32 get_ddr_size_from_eeprom(void);
 
+/**
+ * get_mmc_size_from_eeprom() - read eMMC size from EEPROM
+ *
+ * @return: size in GiB or 0 on error.
+ */
+u32 get_mmc_size_from_eeprom(void);
+
 /**
  * get_product_id_from_eeprom - get product ID string
  *
diff --git a/board/starfive/visionfive2/Kconfig b/board/starfive/visionfive2/Kconfig
index 2186a939646..d7e8a7a7d78 100644
--- a/board/starfive/visionfive2/Kconfig
+++ b/board/starfive/visionfive2/Kconfig
@@ -50,4 +50,13 @@ config BOARD_SPECIFIC_OPTIONS # dummy
 	imply PHY_LIB
 	imply PHY_MSCC
 
+config STARFIVE_NO_EMMC
+	bool "Report eMMC size as zero"
+	help
+	  The serial number string in the EEPROM is meant to report the
+	  size of onboard eMMC. Unfortunately some Milk-V Mars CM Lite
+	  modules without eMMC show a non-zero size here.
+
+	  Set to 'Y' if you have a Mars CM Lite module.
+
 endif
diff --git a/board/starfive/visionfive2/visionfive2-i2c-eeprom.c b/board/starfive/visionfive2/visionfive2-i2c-eeprom.c
index 5095a0e9fdb..9648a270494 100644
--- a/board/starfive/visionfive2/visionfive2-i2c-eeprom.c
+++ b/board/starfive/visionfive2/visionfive2-i2c-eeprom.c
@@ -548,6 +548,24 @@ u32 get_ddr_size_from_eeprom(void)
 	return hextoul(&pbuf.eeprom.atom1.data.pstr[14], NULL);
 }
 
+u32 get_mmc_size_from_eeprom(void)
+{
+	u32 size;
+
+	if (IS_ENABLED(CONFIG_STARFIVE_NO_EMMC))
+		return 0;
+
+	if (read_eeprom())
+		return 0;
+
+	size = dectoul(&pbuf.eeprom.atom1.data.pstr[19], NULL);
+
+	if (pbuf.eeprom.atom1.data.pstr[21] == 'T')
+		size <<= 10;
+
+	return size;
+}
+
 U_BOOT_LONGHELP(mac,
 	"\n"
 	"    - display EEPROM content\n"
-- 
2.43.0


  reply	other threads:[~2024-05-12  4:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-12  4:25 [PATCH v4 0/5] board: starfive: add Milk-V Mars CM support Heinrich Schuchardt
2024-05-12  4:25 ` Heinrich Schuchardt [this message]
2024-05-12  4:25 ` [PATCH v4 2/5] board: add support for Milk-V Mars CM Heinrich Schuchardt
2024-05-12  4:25 ` [PATCH v4 3/5] doc: Milk-V Mars CM and Milk-V Mars CM Lite Heinrich Schuchardt
2024-05-12  4:25 ` [PATCH v4 4/5] configs: visionfive2: enable SPL_YMODEM_SUPPORT Heinrich Schuchardt
2024-05-12  4:25 ` [PATCH v5 5/5] starfive: add mac vendor sub-command Heinrich Schuchardt
  -- strict thread matches above, loose matches on Subject: below --
2024-05-10  5:52 [PATCH v4 0/5] board: starfive: add Milk-V Mars CM support Heinrich Schuchardt
2024-05-10  5:52 ` [PATCH v4 1/5] board: starfive: function to read eMMC size Heinrich Schuchardt

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=20240512042528.7766-2-heinrich.schuchardt@canonical.com \
    --to=heinrich.schuchardt@canonical.com \
    --cc=aurelien@aurel32.net \
    --cc=hal.feng@starfivetech.com \
    --cc=lucent@gmail.com \
    --cc=lukas.funke@weidmueller.com \
    --cc=mason.huo@starfivetech.com \
    --cc=michal.simek@amd.com \
    --cc=minda.chen@starfivetech.com \
    --cc=rick@andestech.com \
    --cc=sw0312.kim@samsung.com \
    --cc=tekieli.lukasz@gmail.com \
    --cc=u-boot@lists.denx.de \
    --cc=wiagn233@outlook.com \
    --cc=yangshiji66@outlook.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).