[U-Boot] [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.
Signed-off-by: Stephen Warren swarren@wwwdotorg.org --- arch/arm/mach-bcm283x/include/mach/mbox.h | 28 --------------------- board/raspberrypi/rpi/rpi.c | 42 +++++++++++++++++-------------- 2 files changed, 23 insertions(+), 47 deletions(-)
diff --git a/arch/arm/mach-bcm283x/include/mach/mbox.h b/arch/arm/mach-bcm283x/include/mach/mbox.h index 9260ee2df76c..af94dff2ac63 100644 --- a/arch/arm/mach-bcm283x/include/mach/mbox.h +++ b/arch/arm/mach-bcm283x/include/mach/mbox.h @@ -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-re... - * 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=5edd... - */ -#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 { diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c index 6451d1d916b1..43ed60ae9811 100644 --- a/board/raspberrypi/rpi/rpi.c +++ b/board/raspberrypi/rpi/rpi.c @@ -74,7 +74,11 @@ struct msg_get_clock_rate { u32 end_tag; };
-/* See comments in mbox.h for data source */ +/* + * http://raspberryalphaomega.org.uk/2013/02/06/automatic-raspberry-pi-board-re... + * 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=5edd... + */ static const struct { const char *name; const char *fdtfile; @@ -90,93 +94,93 @@ static const struct { false, }, #ifdef CONFIG_BCM2836 - [BCM2836_BOARD_REV_2_B] = { + [0x4] = { "2 Model B", "bcm2836-rpi-2-b.dtb", true, }, #else - [BCM2835_BOARD_REV_B_I2C0_2] = { + [0x2] = { "Model B (no P5)", "bcm2835-rpi-b-i2c0.dtb", true, }, - [BCM2835_BOARD_REV_B_I2C0_3] = { + [0x3] = { "Model B (no P5)", "bcm2835-rpi-b-i2c0.dtb", true, }, - [BCM2835_BOARD_REV_B_I2C1_4] = { + [0x4] = { "Model B", "bcm2835-rpi-b.dtb", true, }, - [BCM2835_BOARD_REV_B_I2C1_5] = { + [0x5] = { "Model B", "bcm2835-rpi-b.dtb", true, }, - [BCM2835_BOARD_REV_B_I2C1_6] = { + [0x6] = { "Model B", "bcm2835-rpi-b.dtb", true, }, - [BCM2835_BOARD_REV_A_7] = { + [0x7] = { "Model A", "bcm2835-rpi-a.dtb", false, }, - [BCM2835_BOARD_REV_A_8] = { + [0x8] = { "Model A", "bcm2835-rpi-a.dtb", false, }, - [BCM2835_BOARD_REV_A_9] = { + [0x9] = { "Model A", "bcm2835-rpi-a.dtb", false, }, - [BCM2835_BOARD_REV_B_REV2_d] = { + [0xd] = { "Model B rev2", "bcm2835-rpi-b-rev2.dtb", true, }, - [BCM2835_BOARD_REV_B_REV2_e] = { + [0xe] = { "Model B rev2", "bcm2835-rpi-b-rev2.dtb", true, }, - [BCM2835_BOARD_REV_B_REV2_f] = { + [0xf] = { "Model B rev2", "bcm2835-rpi-b-rev2.dtb", true, }, - [BCM2835_BOARD_REV_B_PLUS] = { + [0x10] = { "Model B+", "bcm2835-rpi-b-plus.dtb", true, }, - [BCM2835_BOARD_REV_CM] = { + [0x11] = { "Compute Module", "bcm2835-rpi-cm.dtb", false, }, - [BCM2835_BOARD_REV_A_PLUS] = { + [0x12] = { "Model A+", "bcm2835-rpi-a-plus.dtb", false, }, - [BCM2835_BOARD_REV_B_PLUS_13] = { + [0x13] = { "Model B+", "bcm2835-rpi-b-plus.dtb", true, }, - [BCM2835_BOARD_REV_CM_14] = { + [0x14] = { "Compute Module", "bcm2835-rpi-cm.dtb", false, }, - [BCM2835_BOARD_REV_A_PLUS_15] = { + [0x15] = { "Model A+", "bcm2835-rpi-a-plus.dtb", false,

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.
Signed-off-by: Stephen Warren swarren@wwwdotorg.org --- board/raspberrypi/rpi/rpi.c | 87 +++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 34 deletions(-)
diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c index 43ed60ae9811..2ad972802881 100644 --- a/board/raspberrypi/rpi/rpi.c +++ b/board/raspberrypi/rpi/rpi.c @@ -77,29 +77,33 @@ struct msg_get_clock_rate { /* * http://raspberryalphaomega.org.uk/2013/02/06/automatic-raspberry-pi-board-re... * 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=5edd... + * http://git.drogon.net/?p=wiringPi;a=blob;f=wiringPi/wiringPi.c;h=503151f6101... */ -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=2... * 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)

On Fri, Dec 04, 2015 at 10:07:45PM -0700, Stephen Warren wrote:
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.
Signed-off-by: Stephen Warren swarren@wwwdotorg.org
Applied to u-boot/master, thanks!

For U-Boot's purposes, at present all we care about is ensuring there's a model table entry.
Signed-off-by: Stephen Warren swarren@wwwdotorg.org --- board/raspberrypi/rpi/rpi.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c index 2ad972802881..4b80d7b742fd 100644 --- a/board/raspberrypi/rpi/rpi.c +++ b/board/raspberrypi/rpi/rpi.c @@ -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[] = {

On Fri, Dec 04, 2015 at 10:07:46PM -0700, Stephen Warren wrote:
For U-Boot's purposes, at present all we care about is ensuring there's a model table entry.
Signed-off-by: Stephen Warren swarren@wwwdotorg.org
Applied to u-boot/master, thanks!

On Fri, Dec 04, 2015 at 10:07:44PM -0700, Stephen Warren wrote:
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.
Signed-off-by: Stephen Warren swarren@wwwdotorg.org
Applied to u-boot/master, thanks!

On Fri, Dec 04, 2015 at 10:07:44PM -0700, Stephen Warren wrote:
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.
Signed-off-by: Stephen Warren swarren@wwwdotorg.org
Applied to u-boot/master, thanks!
participants (2)
-
Stephen Warren
-
Tom Rini