Load socinfo only once (#838)

Remove code duplication and make sure to load socinfo only once. Also
set board_rev before MAC address to make sure board_rev is set even if
loading MAC address from efuses fails.
This commit is contained in:
Stefan Agner 2020-09-01 19:07:07 +02:00 committed by GitHub
parent 1c991c229d
commit b8cf3face0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 145 additions and 97 deletions

View File

@ -0,0 +1,63 @@
From fb41bcaf0e61e78bc40addb1312040a2bc6a69b7 Mon Sep 17 00:00:00 2001
Message-Id: <fb41bcaf0e61e78bc40addb1312040a2bc6a69b7.1598875349.git.stefan@agner.ch>
In-Reply-To: <c12338d22649e46aed12ebe60d897112f045fda9.1598875349.git.stefan@agner.ch>
References: <c12338d22649e46aed12ebe60d897112f045fda9.1598875349.git.stefan@agner.ch>
From: Stefan Agner <stefan@agner.ch>
Date: Mon, 31 Aug 2020 13:40:18 +0200
Subject: [PATCH 2/4] ARM: meson: isolate loading of socinfo
Move loading of socinfo into a separate function so the value can be
reused later.
Signed-off-by: Stefan Agner <stefan@agner.ch>
---
arch/arm/mach-meson/board-info.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/arch/arm/mach-meson/board-info.c b/arch/arm/mach-meson/board-info.c
index 0d3b40a249..e305d60dca 100644
--- a/arch/arm/mach-meson/board-info.c
+++ b/arch/arm/mach-meson/board-info.c
@@ -123,12 +123,16 @@ static void print_board_model(void)
printf("Model: %s\n", model ? model : "Unknown");
}
-int show_board_info(void)
+static unsigned int get_socinfo(void)
{
struct regmap *regmap;
int nodeoffset, ret;
ofnode node;
- unsigned int socinfo;
+ static unsigned int socinfo = 0;
+
+ /* Empty socinfo is invalid, so !socinfo is successfully initialized */
+ if (socinfo)
+ return socinfo;
/* find the offset of compatible node */
nodeoffset = fdt_node_offset_by_compatible(gd->fdt_blob, -1,
@@ -155,8 +159,20 @@ int show_board_info(void)
return 0;
}
+ return socinfo;
+}
+
+int show_board_info(void)
+{
+ unsigned int socinfo;
+
/* print board information */
print_board_model();
+
+ socinfo = get_socinfo();
+ if (!socinfo)
+ return 0;
+
printf("SoC: Amlogic Meson %s (%s) Revision %x:%x (%x:%x)\n",
socinfo_to_soc_id(socinfo),
socinfo_to_package_id(socinfo),
--
2.28.0

View File

@ -1,97 +0,0 @@
From 2efc005b8eb2738ac66f59d0a3af2b6540cbcc8f Mon Sep 17 00:00:00 2001
Message-Id: <2efc005b8eb2738ac66f59d0a3af2b6540cbcc8f.1596577295.git.stefan@agner.ch>
In-Reply-To: <34605fd3e035ce85265a8f308b8540b83c2ba67f.1596577295.git.stefan@agner.ch>
References: <34605fd3e035ce85265a8f308b8540b83c2ba67f.1596577295.git.stefan@agner.ch>
From: Pascal Vizeli <pvizeli@syshack.ch>
Date: Tue, 4 Aug 2020 13:50:57 +0000
Subject: [PATCH 2/2] meson: Add board_rev to env
Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch>
---
arch/arm/include/asm/arch-meson/boot.h | 2 ++
arch/arm/mach-meson/board-info.c | 38 ++++++++++++++++++++++++++
board/amlogic/w400/w400.c | 5 ++++
3 files changed, 45 insertions(+)
diff --git a/arch/arm/include/asm/arch-meson/boot.h b/arch/arm/include/asm/arch-meson/boot.h
index a90fe55081..d344258ea1 100644
--- a/arch/arm/include/asm/arch-meson/boot.h
+++ b/arch/arm/include/asm/arch-meson/boot.h
@@ -17,4 +17,6 @@
int meson_get_boot_device(void);
+int meson_get_soc_rev(char *buff);
+
#endif /* __MESON_BOOT_H__ */
diff --git a/arch/arm/mach-meson/board-info.c b/arch/arm/mach-meson/board-info.c
index 0d3b40a249..dddcb85981 100644
--- a/arch/arm/mach-meson/board-info.c
+++ b/arch/arm/mach-meson/board-info.c
@@ -167,3 +167,41 @@ int show_board_info(void)
return 0;
}
+
+int meson_get_soc_rev(char *buff)
+{
+ struct regmap *regmap;
+ int nodeoffset, ret;
+ ofnode node;
+ unsigned int socinfo;
+
+ /* find the offset of compatible node */
+ nodeoffset = fdt_node_offset_by_compatible(gd->fdt_blob, -1,
+ "amlogic,meson-gx-ao-secure");
+ if (nodeoffset < 0)
+ return 0;
+
+ /* check if chip-id is available */
+ if (!fdt_getprop(gd->fdt_blob, nodeoffset, "amlogic,has-chip-id", NULL))
+ return 0;
+
+ /* get regmap from the syscon node */
+ node = offset_to_ofnode(nodeoffset);
+ regmap = syscon_node_to_regmap(node);
+ if (IS_ERR(regmap)) {
+ printf("%s: failed to get regmap\n", __func__);
+ return 0;
+ }
+
+ /* read soc info */
+ ret = regmap_read(regmap, AO_SEC_SOCINFO_OFFSET, &socinfo);
+ if (ret && !socinfo) {
+ printf("%s: invalid chipid value\n", __func__);
+ return 0;
+ }
+
+ /* Write SoC info */
+ sprintf(buff, "%x", socinfo_to_minor(socinfo));
+
+ return 1;
+}
diff --git a/board/amlogic/w400/w400.c b/board/amlogic/w400/w400.c
index d74aab899a..55fae6b67a 100644
--- a/board/amlogic/w400/w400.c
+++ b/board/amlogic/w400/w400.c
@@ -10,6 +10,7 @@
#include <asm/io.h>
#include <asm/arch/sm.h>
#include <asm/arch/eth.h>
+#include <asm/arch/boot.h>
#define EFUSE_MAC_OFFSET 20
#define EFUSE_MAC_SIZE 12
@@ -37,5 +38,9 @@ int misc_init_r(void)
eth_env_set_enetaddr("ethaddr", mac_addr);
}
+ if (meson_get_soc_rev(buff)) {
+ env_set("board_rev", buff);
+ }
+
return 0;
}
--
2.27.0

View File

@ -0,0 +1,82 @@
From 15ce807d420324bc209772b843d4004619e0cdaf Mon Sep 17 00:00:00 2001
Message-Id: <15ce807d420324bc209772b843d4004619e0cdaf.1598875349.git.stefan@agner.ch>
In-Reply-To: <c12338d22649e46aed12ebe60d897112f045fda9.1598875349.git.stefan@agner.ch>
References: <c12338d22649e46aed12ebe60d897112f045fda9.1598875349.git.stefan@agner.ch>
From: Pascal Vizeli <pvizeli@syshack.ch>
Date: Tue, 4 Aug 2020 13:50:57 +0000
Subject: [PATCH 3/4] meson: Add board_rev to env
Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch>
Signed-off-by: Stefan Agner <stefan@agner.ch>
---
arch/arm/include/asm/arch-meson/boot.h | 4 ++++
arch/arm/mach-meson/board-info.c | 12 ++++++++++++
board/amlogic/w400/w400.c | 5 +++++
3 files changed, 21 insertions(+)
diff --git a/arch/arm/include/asm/arch-meson/boot.h b/arch/arm/include/asm/arch-meson/boot.h
index a90fe55081..c67d12d06c 100644
--- a/arch/arm/include/asm/arch-meson/boot.h
+++ b/arch/arm/include/asm/arch-meson/boot.h
@@ -7,6 +7,8 @@
#ifndef __MESON_BOOT_H__
#define __MESON_BOOT_H__
+#include <linux/types.h>
+
/* Boot device */
#define BOOT_DEVICE_RESERVED 0
#define BOOT_DEVICE_EMMC 1
@@ -17,4 +19,6 @@
int meson_get_boot_device(void);
+int meson_get_soc_rev(char *buff, size_t buff_len);
+
#endif /* __MESON_BOOT_H__ */
diff --git a/arch/arm/mach-meson/board-info.c b/arch/arm/mach-meson/board-info.c
index e305d60dca..3c40d6cd27 100644
--- a/arch/arm/mach-meson/board-info.c
+++ b/arch/arm/mach-meson/board-info.c
@@ -183,3 +183,15 @@ int show_board_info(void)
return 0;
}
+
+int meson_get_soc_rev(char *buff, size_t buff_len)
+{
+ unsigned int socinfo;
+
+ socinfo = get_socinfo();
+ if (!socinfo)
+ return -1;
+
+ /* Write SoC info */
+ return snprintf(buff, buff_len, "%x", socinfo_to_minor(socinfo));
+}
diff --git a/board/amlogic/w400/w400.c b/board/amlogic/w400/w400.c
index d74aab899a..cb2e5edf5e 100644
--- a/board/amlogic/w400/w400.c
+++ b/board/amlogic/w400/w400.c
@@ -10,6 +10,7 @@
#include <asm/io.h>
#include <asm/arch/sm.h>
#include <asm/arch/eth.h>
+#include <asm/arch/boot.h>
#define EFUSE_MAC_OFFSET 20
#define EFUSE_MAC_SIZE 12
@@ -20,6 +21,10 @@ int misc_init_r(void)
char efuse_mac_addr[EFUSE_MAC_SIZE], buff[3];
ssize_t len;
+ if (meson_get_soc_rev(buff, sizeof(buff))) {
+ env_set("board_rev", buff);
+ }
+
meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);
if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
--
2.28.0