[PATCH v1 3/4] sysinfo: rcar3: Implement BOARD_ID and BOARD_REVISION

Detlev Casanova detlev.casanova at collabora.com
Fri Jun 16 17:21:21 CEST 2023


Expose that information to the command shell to let scripts select the
correct devicetree name.

Signed-off-by: Detlev Casanova <detlev.casanova at collabora.com>
---
 drivers/sysinfo/rcar3.c | 46 ++++++++++++++++++++++++++++++++---------
 1 file changed, 36 insertions(+), 10 deletions(-)

diff --git a/drivers/sysinfo/rcar3.c b/drivers/sysinfo/rcar3.c
index 7b127986da7..89ad46c5422 100644
--- a/drivers/sysinfo/rcar3.c
+++ b/drivers/sysinfo/rcar3.c
@@ -32,6 +32,8 @@
  */
 struct sysinfo_rcar_priv {
 	char	boardmodel[64];
+	u8	id;
+	char	revision[4];
 	u8	val;
 };
 
@@ -48,17 +50,37 @@ static int sysinfo_rcar_get_str(struct udevice *dev, int id, size_t size, char *
 
 	switch (id) {
 	case SYSINFO_ID_BOARD_MODEL:
-		strncpy(val, priv->boardmodel, size);
-		val[size - 1] = '\0';
+		strlcpy(val, priv->boardmodel, size);
+		break;
+	case SYSINFO_ID_BOARD_REVISION:
+		strlcpy(val, priv->revision, size);
+		break;
+	default:
+		return -EINVAL;
+	};
+
+	val[size - 1] = '\0';
+	return 0;
+}
+
+static int sysinfo_rcar_get_int(struct udevice *dev, int id, int *val)
+{
+	struct sysinfo_rcar_priv *priv = dev_get_priv(dev);
+
+	switch (id) {
+	case SYSINFO_ID_BOARD_ID:
+		*val = priv->id;
 		return 0;
 	default:
 		return -EINVAL;
 	};
+
 }
 
 static const struct sysinfo_ops sysinfo_rcar_ops = {
 	.detect = sysinfo_rcar_detect,
 	.get_str = sysinfo_rcar_get_str,
+	.get_int = sysinfo_rcar_get_int,
 };
 
 static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)
@@ -83,7 +105,7 @@ static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)
 		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
 			 "Renesas Salvator-X%s board rev %c.%c",
 			 salvator_xs ? "S" : "", rev_major, rev_minor);
-		return;
+		break;
 	case BOARD_STARTER_KIT:
 		if (!(board_rev & ~1)) { /* Only rev 0 and 1 is valid */
 			rev_major = (board_rev & BIT(0)) ? '3' : '1';
@@ -92,7 +114,7 @@ static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)
 		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
 			 "Renesas Starter Kit board rev %c.%c",
 			 rev_major, rev_minor);
-		return;
+		break;
 	case BOARD_STARTER_KIT_PRE:
 		if (!(board_rev & ~3)) { /* Only rev 0..3 is valid */
 			rev_major = (board_rev & BIT(1)) ? '2' : '1';
@@ -101,7 +123,7 @@ static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)
 		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
 			 "Renesas Starter Kit Premier board rev %c.%c",
 			 rev_major, rev_minor);
-		return;
+		break;
 	case BOARD_EAGLE:
 		if (!board_rev) { /* Only rev 0 is valid */
 			rev_major = '1';
@@ -110,7 +132,7 @@ static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)
 		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
 			 "Renesas Eagle board rev %c.%c",
 			 rev_major, rev_minor);
-		return;
+		break;
 	case BOARD_EBISU_4D:
 		ebisu_4d = true;
 		fallthrough;
@@ -122,7 +144,7 @@ static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)
 		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
 			 "Renesas Ebisu%s board rev %c.%c",
 			 ebisu_4d ? "-4D" : "", rev_major, rev_minor);
-		return;
+		break;
 	case BOARD_DRAAK:
 		if (!board_rev) { /* Only rev 0 is valid */
 			rev_major = '1';
@@ -131,7 +153,7 @@ static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)
 		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
 			 "Renesas Draak board rev %c.%c",
 			 rev_major, rev_minor);
-		return;
+		break;
 	case BOARD_KRIEK:
 		if (!board_rev) { /* Only rev 0 is valid */
 			rev_major = '1';
@@ -140,7 +162,7 @@ static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)
 		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
 			 "Renesas Kriek board rev %c.%c",
 			 rev_major, rev_minor);
-		return;
+		break;
 	case BOARD_CONDOR_I:
 		condor_i = true;
 		fallthrough;
@@ -152,13 +174,17 @@ static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)
 		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
 			"Renesas Condor%s board rev %c.%c",
 			condor_i ? "-I" : "", rev_major, rev_minor);
-		return;
+		break;
 	default:
 		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
 			 "Renesas -Unknown- board rev ?.?");
 		priv->val = 0xff;
 		return;
 	}
+
+	snprintf(priv->revision, sizeof(priv->revision), "%c.%c", rev_major,
+		 rev_minor);
+	priv->id = board_id;
 }
 
 static int sysinfo_rcar_probe(struct udevice *dev)
-- 
2.39.3



More information about the U-Boot mailing list