Skip to contentSkip to conversation

rpi: get rid of BCM2835_BOARD_REV_* macros

PATCH New Stephen Warren 2 participants 7 messages Dec 5, 2015 – Dec 6, 2015

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 rpi: get rid of BCM2835_BOARD_REV_* macros

There are two numbering schemes for the RPi revision values; old and new scheme. The values within each scheme overlap. Hence, it doesn't make sense to have absolute/global names for the revision IDs. Get rid of the names and just use the raw revision/type values to set up the array of per-revision data.

This change makes most sense when coupled with the next change. However, it's split out so that the mechanical cut/paste is separate from the logic changes for easier review and problem bisection.

---
 arch/arm/mach-bcm283x/include/mach/mbox.h | 28 ---------------------
 board/raspberrypi/rpi/rpi.c               | 42 +++++++++++++++++--------------
 2 files changed, 23 insertions(+), 47 deletions(-)
arch/arm/mach-bcm283x/include/mach/mbox.h +0 -28
index 9260ee2df76c..af94dff2ac63 100644
@@ -125,34 +125,6 @@ struct bcm2835_mbox_tag_hdr {
 
 #define BCM2835_MBOX_TAG_GET_BOARD_REV	0x00010002
 
-#ifdef CONFIG_BCM2836
-#define BCM2836_BOARD_REV_2_B		0x4
-#else
-/*
- * 0x2..0xf from:
- * http://raspberryalphaomega.org.uk/2013/02/06/automatic-raspberry-pi-board-revision-detection-model-a-b1-and-b2/
- * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=32733
- * http://git.drogon.net/?p=wiringPi;a=blob_plain;f=wiringPi/wiringPi.c;hb=5edd177112c99416f68ba3e8c6c4db6ed942e796
- */
-#define BCM2835_BOARD_REV_B_I2C0_2	0x2
-#define BCM2835_BOARD_REV_B_I2C0_3	0x3
-#define BCM2835_BOARD_REV_B_I2C1_4	0x4
-#define BCM2835_BOARD_REV_B_I2C1_5	0x5
-#define BCM2835_BOARD_REV_B_I2C1_6	0x6
-#define BCM2835_BOARD_REV_A_7		0x7
-#define BCM2835_BOARD_REV_A_8		0x8
-#define BCM2835_BOARD_REV_A_9		0x9
-#define BCM2835_BOARD_REV_B_REV2_d	0xd
-#define BCM2835_BOARD_REV_B_REV2_e	0xe
-#define BCM2835_BOARD_REV_B_REV2_f	0xf
-#define BCM2835_BOARD_REV_B_PLUS	0x10
-#define BCM2835_BOARD_REV_CM		0x11
-#define BCM2835_BOARD_REV_A_PLUS	0x12
-#define BCM2835_BOARD_REV_B_PLUS_13	0x13
-#define BCM2835_BOARD_REV_CM_14		0x14
-#define BCM2835_BOARD_REV_A_PLUS_15	0x15
-#endif
-
 struct bcm2835_mbox_tag_get_board_rev {
 	struct bcm2835_mbox_tag_hdr tag_hdr;
 	union {
board/raspberrypi/rpi/rpi.c +23 -19

123 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/3 rpi: fix revision scheme parsing

The RPi has two different schemes for encoding board revision values. When adding RPi 2 support, I thought that the conflicting type field values were to be interpreted based on bcm2835-vs-bcm2836. In fact, the scheme bit determines the encoding. The RPi Zero uses the bcm2835 yet uses the new encoding scheme. Fix the code to cater for this correctly.

---
 board/raspberrypi/rpi/rpi.c | 87 +++++++++++++++++++++++++++------------------
 1 file changed, 53 insertions(+), 34 deletions(-)
board/raspberrypi/rpi/rpi.c +53 -34
index 43ed60ae9811..2ad972802881 100644
@@ -77,29 +77,33 @@ struct msg_get_clock_rate {
 /*
  * http://raspberryalphaomega.org.uk/2013/02/06/automatic-raspberry-pi-board-revision-detection-model-a-b1-and-b2/
  * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=32733
- * http://git.drogon.net/?p=wiringPi;a=blob_plain;f=wiringPi/wiringPi.c;hb=5edd177112c99416f68ba3e8c6c4db6ed942e796
+ * http://git.drogon.net/?p=wiringPi;a=blob;f=wiringPi/wiringPi.c;h=503151f61014418b9c42f4476a6086f75cd4e64b;hb=refs/heads/master#l922
  */
-static const struct {
+struct rpi_model {
 	const char *name;
 	const char *fdtfile;
 	bool has_onboard_eth;
-} models[] = {
-	[0] = {
-		"Unknown model",
+};
+
+static const struct rpi_model rpi_model_unknown = {
+	"Unknown model",
 #ifdef CONFIG_BCM2836
-		"bcm2836-rpi-other.dtb",
+	"bcm2836-rpi-other.dtb",
 #else
-		"bcm2835-rpi-other.dtb",
+	"bcm2835-rpi-other.dtb",
 #endif
-		false,
-	},
-#ifdef CONFIG_BCM2836
+	false,
+};
+
+static const struct rpi_model rpi_models_new_scheme[] = {
 	[0x4] = {
 		"2 Model B",
 		"bcm2836-rpi-2-b.dtb",
 		true,
 	},
-#else
+};
+
+static const struct rpi_model rpi_models_old_scheme[] = {
 	[0x2] = {
 		"Model B (no P5)",
 		"bcm2835-rpi-b-i2c0.dtb",
@@ -185,10 +189,12 @@ static const struct {
 		"bcm2835-rpi-a-plus.dtb",
 		false,
 	},
-#endif
 };
 
-u32 rpi_board_rev = 0;
+static uint32_t revision;
+static uint32_t rev_scheme;
+static uint32_t rev_type;
+static const struct rpi_model *model;
 
 int dram_init(void)
 {
@@ -216,7 +222,7 @@ static void set_fdtfile(void)
 	if (getenv("fdtfile"))
 		return;
 
-	fdtfile = models[rpi_board_rev].fdtfile;
+	fdtfile = model->fdtfile;
 	setenv("fdtfile", fdtfile);
 }
 
@@ -225,7 +231,7 @@ static void set_usbethaddr(void)
 	ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1);
 	int ret;
 
-	if (!models[rpi_board_rev].has_onboard_eth)
+	if (!model->has_onboard_eth)
 		return;
 
 	if (getenv("usbethaddr"))
@@ -249,10 +255,16 @@ static void set_usbethaddr(void)
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 static void set_board_info(void)
 {
-	char str_rev[11];
-	sprintf(str_rev, "0x%X", rpi_board_rev);
-	setenv("board_rev", str_rev);
-	setenv("board_name", models[rpi_board_rev].name);
+	char s[11];
+
+	snprintf(s, sizeof(s), "0x%X", revision);
+	setenv("board_revision", s);
+	snprintf(s, sizeof(s), "%d", rev_scheme);
+	setenv("board_rev_scheme", s);
+	/* Can't rename this to board_rev_type since it's an ABI for scripts */
+	snprintf(s, sizeof(s), "0x%X", rev_type);
+	setenv("board_rev", s);
+	setenv("board_name", model->name);
 }
 #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
 
@@ -294,7 +306,8 @@ static void get_board_rev(void)
 {
 	ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1);
 	int ret;
-	const char *name;
+	const struct rpi_model *models;
+	uint32_t models_count;
 
 	BCM2835_MBOX_INIT_HDR(msg);
 	BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV);
@@ -317,23 +330,29 @@ static void get_board_rev(void)
 	 * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=98367&start=250
 	 * http://www.raspberrypi.org/forums/viewtopic.php?f=31&t=20594
 	 */
-	rpi_board_rev = msg->get_board_rev.body.resp.rev;
-	if (rpi_board_rev & 0x800000)
-		rpi_board_rev = (rpi_board_rev >> 4) & 0xff;
-	else
-		rpi_board_rev &= 0xff;
-	if (rpi_board_rev >= ARRAY_SIZE(models)) {
-		printf("RPI: Board rev %u outside known range\n",
-		       rpi_board_rev);
-		rpi_board_rev = 0;
+	revision = msg->get_board_rev.body.resp.rev;
+	if (revision & 0x800000) {
+		rev_scheme = 1;
+		rev_type = (revision >> 4) & 0xff;
+		models = rpi_models_new_scheme;
+		models_count = ARRAY_SIZE(rpi_models_new_scheme);
+	} else {
+		rev_scheme = 0;
+		rev_type = revision & 0xff;
+		models = rpi_models_old_scheme;
+		models_count = ARRAY_SIZE(rpi_models_old_scheme);
 	}
-	if (!models[rpi_board_rev].name) {
-		printf("RPI: Board rev %u unknown\n", rpi_board_rev);
-		rpi_board_rev = 0;
+	if (rev_type >= models_count) {
+		printf("RPI: Board rev 0x%x outside known range\n", rev_type);
+		model = &rpi_model_unknown;
+	} else if (!models[rev_type].name) {
+		printf("RPI: Board rev 0x%x unknown\n", rev_type);
+		model = &rpi_model_unknown;
+	} else {
+		model = &models[rev_type];
 	}
 
-	name = models[rpi_board_rev].name;
-	printf("RPI %s\n", name);
+	printf("RPI %s (0x%x)\n", model->name, revision);
 }
 
 int board_init(void)
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/3 rpi: fix revision scheme parsing

Quoted 7 lines · Stephen Warren

The RPi has two different schemes for encoding board revision values. When adding RPi 2 support, I thought that the conflicting type field values were to be interpreted based on bcm2835-vs-bcm2836. In fact, the scheme bit determines the encoding. The RPi Zero uses the bcm2835 yet uses the new encoding scheme. Fix the code to cater for this correctly.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151206/4f47415d/attachment.sig>
#3 lore raw

PATCH 3/3 rpi: add support for Raspberry Pi Zero

In reply to Stephen Warren

For U-Boot's purposes, at present all we care about is ensuring there's a model table entry.

---
 board/raspberrypi/rpi/rpi.c | 5 +++++
 1 file changed, 5 insertions(+)
board/raspberrypi/rpi/rpi.c +5 -0
index 2ad972802881..4b80d7b742fd 100644
@@ -101,6 +101,11 @@ static const struct rpi_model rpi_models_new_scheme[] = {
 		"bcm2836-rpi-2-b.dtb",
 		true,
 	},
+	[0x9] = {
+		"Zero",
+		"bcm2835-rpi-zero.dtb",
+		false,
+	},
 };
 
 static const struct rpi_model rpi_models_old_scheme[] = {
Signature · 1 line
1.9.1
#4 lore raw

PATCH 3/3 rpi: add support for Raspberry Pi Zero

Quoted 4 lines · Stephen Warren

For U-Boot's purposes, at present all we care about is ensuring there's a model table entry.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151206/38b35775/attachment.sig>
#5 lore raw

PATCH 1/3 rpi: get rid of BCM2835_BOARD_REV_* macros

In reply to Stephen Warren
Quoted 11 lines · Stephen Warren

There are two numbering schemes for the RPi revision values; old and new scheme. The values within each scheme overlap. Hence, it doesn't make sense to have absolute/global names for the revision IDs. Get rid of the names and just use the raw revision/type values to set up the array of per-revision data.

This change makes most sense when coupled with the next change. However, it's split out so that the mechanical cut/paste is separate from the logic changes for easier review and problem bisection.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151206/085975cf/attachment.sig>
#6 lore raw

PATCH 1/3 rpi: get rid of BCM2835_BOARD_REV_* macros

In reply to Stephen Warren
Quoted 11 lines · Stephen Warren

There are two numbering schemes for the RPi revision values; old and new scheme. The values within each scheme overlap. Hence, it doesn't make sense to have absolute/global names for the revision IDs. Get rid of the names and just use the raw revision/type values to set up the array of per-revision data.

This change makes most sense when coupled with the next change. However, it's split out so that the mechanical cut/paste is separate from the logic changes for easier review and problem bisection.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151206/342ba915/attachment.sig>