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.

Signed-off-by: Stephen Warren <swarren@wwwdotorg.org>
This commit is contained in:
Stephen Warren 2015-12-04 22:07:45 -07:00 committed by Tom Rini
parent dbe6f1eb93
commit c4ea1edb70
1 changed files with 53 additions and 34 deletions

View File

@ -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://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://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 *name;
const char *fdtfile; const char *fdtfile;
bool has_onboard_eth; bool has_onboard_eth;
} models[] = { };
[0] = {
"Unknown model", static const struct rpi_model rpi_model_unknown = {
"Unknown model",
#ifdef CONFIG_BCM2836 #ifdef CONFIG_BCM2836
"bcm2836-rpi-other.dtb", "bcm2836-rpi-other.dtb",
#else #else
"bcm2835-rpi-other.dtb", "bcm2835-rpi-other.dtb",
#endif #endif
false, false,
}, };
#ifdef CONFIG_BCM2836
static const struct rpi_model rpi_models_new_scheme[] = {
[0x4] = { [0x4] = {
"2 Model B", "2 Model B",
"bcm2836-rpi-2-b.dtb", "bcm2836-rpi-2-b.dtb",
true, true,
}, },
#else };
static const struct rpi_model rpi_models_old_scheme[] = {
[0x2] = { [0x2] = {
"Model B (no P5)", "Model B (no P5)",
"bcm2835-rpi-b-i2c0.dtb", "bcm2835-rpi-b-i2c0.dtb",
@ -185,10 +189,12 @@ static const struct {
"bcm2835-rpi-a-plus.dtb", "bcm2835-rpi-a-plus.dtb",
false, 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) int dram_init(void)
{ {
@ -216,7 +222,7 @@ static void set_fdtfile(void)
if (getenv("fdtfile")) if (getenv("fdtfile"))
return; return;
fdtfile = models[rpi_board_rev].fdtfile; fdtfile = model->fdtfile;
setenv("fdtfile", fdtfile); setenv("fdtfile", fdtfile);
} }
@ -225,7 +231,7 @@ static void set_usbethaddr(void)
ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1); ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1);
int ret; int ret;
if (!models[rpi_board_rev].has_onboard_eth) if (!model->has_onboard_eth)
return; return;
if (getenv("usbethaddr")) if (getenv("usbethaddr"))
@ -249,10 +255,16 @@ static void set_usbethaddr(void)
#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
static void set_board_info(void) static void set_board_info(void)
{ {
char str_rev[11]; char s[11];
sprintf(str_rev, "0x%X", rpi_board_rev);
setenv("board_rev", str_rev); snprintf(s, sizeof(s), "0x%X", revision);
setenv("board_name", models[rpi_board_rev].name); 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 */ #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); ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1);
int ret; int ret;
const char *name; const struct rpi_model *models;
uint32_t models_count;
BCM2835_MBOX_INIT_HDR(msg); BCM2835_MBOX_INIT_HDR(msg);
BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV); 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=63&t=98367&start=250
* http://www.raspberrypi.org/forums/viewtopic.php?f=31&t=20594 * http://www.raspberrypi.org/forums/viewtopic.php?f=31&t=20594
*/ */
rpi_board_rev = msg->get_board_rev.body.resp.rev; revision = msg->get_board_rev.body.resp.rev;
if (rpi_board_rev & 0x800000) if (revision & 0x800000) {
rpi_board_rev = (rpi_board_rev >> 4) & 0xff; rev_scheme = 1;
else rev_type = (revision >> 4) & 0xff;
rpi_board_rev &= 0xff; models = rpi_models_new_scheme;
if (rpi_board_rev >= ARRAY_SIZE(models)) { models_count = ARRAY_SIZE(rpi_models_new_scheme);
printf("RPI: Board rev %u outside known range\n", } else {
rpi_board_rev); rev_scheme = 0;
rpi_board_rev = 0; rev_type = revision & 0xff;
models = rpi_models_old_scheme;
models_count = ARRAY_SIZE(rpi_models_old_scheme);
} }
if (!models[rpi_board_rev].name) { if (rev_type >= models_count) {
printf("RPI: Board rev %u unknown\n", rpi_board_rev); printf("RPI: Board rev 0x%x outside known range\n", rev_type);
rpi_board_rev = 0; 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 (0x%x)\n", model->name, revision);
printf("RPI %s\n", name);
} }
int board_init(void) int board_init(void)