u-boot-brain/board/raspberrypi/rpi/rpi.c
Stephen Warren f031f501ef rpi: BCM2837 and Raspberry Pi 3 32-bit support
The Raspberry Pi 3 contains a BCM2837 SoC. The BCM2837 is a BCM2836 with
the CPU complex swapped out for a quad-core ARMv8. This can operate in 32-
or 64-bit mode. 32-bit mode is the current default selected by the
VideoCore firmware on the Raspberry Pi 3. This patch adds a 32-bit port of
U-Boot for the Raspberry Pi 3.

>From U-Boot's perspective, the only delta between the RPi 2 and RPi 3 is a
change in usage of the SoC UARTs. On all previous Pis, the PL011 was the
only UART in use. The Raspberry Pi 3 adds a Bluetooth module which uses a
UART to connect to the SoC. By default, the PL011 is used for this purpose
since it has larger FIFOs than the other "mini" UART. However, this can
be configured via the VideoCore firmware's config.txt file. This patch
hard-codes use of the mini UART in the RPi 3 port. If your system uses the
PL011 UART for the console even on the RPi 3, please use the RPi 2 U-Boot
port instead. A future change might determine which UART to use at
run-time, thus allowing the RPi 2 and RPi 3 (32-bit) ports to be squashed
together.

The mini UART has some limitations. One externally visible issue in the
BCM2837 integration is that the UART divides the SoC's "core clock" to
generate the baud rate. The core clock is typically variable, and under
control of the VideoCore firmware for thermal management reasons. If the
VC FW does modify the core clock rate, UART communication will be
corrupted since the baud rate will vary from the expected value. This was
not an issue for the PL011 UART, since it is fed by a fixed 3MHz clock. To
work around this, the VideoCore firmware can be told not to modify the SoC
core clock. However, the only way this can happen and be thermally safe is
to limit the core clock to a low/minimum frequency. This leaves
performance on the table for use-cases that don't care about a UART
console. Consequently, use of the mini UART console must be explicitly
requested by entering the following line into config.txt:

    enable_uart=1

A recent version of the VC firmware is required to ensure that the mini
UART is fully and correctly initialized by the VC FW; at least
firmware.git 046effa13ebc "firmware: arm_loader: emmc clock depends on
core clock See: https://github.com/raspberrypi/firmware/issues/572".

Signed-off-by: Stephen Warren <swarren@wwwdotorg.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
2016-04-01 17:17:42 -04:00

460 lines
9.8 KiB
C

/*
* (C) Copyright 2012-2016 Stephen Warren
*
* SPDX-License-Identifier: GPL-2.0
*/
#include <common.h>
#include <inttypes.h>
#include <config.h>
#include <dm.h>
#include <fdt_support.h>
#include <fdt_simplefb.h>
#include <lcd.h>
#include <memalign.h>
#include <mmc.h>
#include <asm/gpio.h>
#include <asm/arch/mbox.h>
#include <asm/arch/sdhci.h>
#include <asm/global_data.h>
#include <dm/platform_data/serial_pl01x.h>
#include <dm/platform_data/serial_bcm283x_mu.h>
DECLARE_GLOBAL_DATA_PTR;
static const struct bcm2835_gpio_platdata gpio_platdata = {
.base = BCM2835_GPIO_BASE,
};
U_BOOT_DEVICE(bcm2835_gpios) = {
.name = "gpio_bcm2835",
.platdata = &gpio_platdata,
};
#ifdef CONFIG_PL01X_SERIAL
static const struct pl01x_serial_platdata serial_platdata = {
#ifndef CONFIG_BCM2835
.base = 0x3f201000,
#else
.base = 0x20201000,
#endif
.type = TYPE_PL011,
.skip_init = true,
};
U_BOOT_DEVICE(bcm2835_serials) = {
.name = "serial_pl01x",
.platdata = &serial_platdata,
};
#else
static const struct bcm283x_mu_serial_platdata serial_platdata = {
.base = 0x3f215040,
.clock = 250000000,
.skip_init = true,
};
U_BOOT_DEVICE(bcm2837_serials) = {
.name = "serial_bcm283x_mu",
.platdata = &serial_platdata,
};
#endif
struct msg_get_arm_mem {
struct bcm2835_mbox_hdr hdr;
struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
u32 end_tag;
};
struct msg_get_board_rev {
struct bcm2835_mbox_hdr hdr;
struct bcm2835_mbox_tag_get_board_rev get_board_rev;
u32 end_tag;
};
struct msg_get_board_serial {
struct bcm2835_mbox_hdr hdr;
struct bcm2835_mbox_tag_get_board_serial get_board_serial;
u32 end_tag;
};
struct msg_get_mac_address {
struct bcm2835_mbox_hdr hdr;
struct bcm2835_mbox_tag_get_mac_address get_mac_address;
u32 end_tag;
};
struct msg_set_power_state {
struct bcm2835_mbox_hdr hdr;
struct bcm2835_mbox_tag_set_power_state set_power_state;
u32 end_tag;
};
struct msg_get_clock_rate {
struct bcm2835_mbox_hdr hdr;
struct bcm2835_mbox_tag_get_clock_rate get_clock_rate;
u32 end_tag;
};
/*
* 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;f=wiringPi/wiringPi.c;h=503151f61014418b9c42f4476a6086f75cd4e64b;hb=refs/heads/master#l922
*
* In http://lists.denx.de/pipermail/u-boot/2016-January/243752.html
* ("[U-Boot] [PATCH] rpi: fix up Model B entries") Dom Cobley at the RPi
* Foundation stated that the following source was accurate:
* https://github.com/AndrewFromMelbourne/raspberry_pi_revision
*/
struct rpi_model {
const char *name;
const char *fdtfile;
bool has_onboard_eth;
};
static const struct rpi_model rpi_model_unknown = {
"Unknown model",
"bcm283x-rpi-other.dtb",
false,
};
static const struct rpi_model rpi_models_new_scheme[] = {
[0x4] = {
"2 Model B",
"bcm2836-rpi-2-b.dtb",
true,
},
[0x8] = {
"3 Model B",
"bcm2837-rpi-3-b.dtb",
true,
},
[0x9] = {
"Zero",
"bcm2835-rpi-zero.dtb",
false,
},
};
static const struct rpi_model rpi_models_old_scheme[] = {
[0x2] = {
"Model B",
"bcm2835-rpi-b.dtb",
true,
},
[0x3] = {
"Model B",
"bcm2835-rpi-b.dtb",
true,
},
[0x4] = {
"Model B rev2",
"bcm2835-rpi-b-rev2.dtb",
true,
},
[0x5] = {
"Model B rev2",
"bcm2835-rpi-b-rev2.dtb",
true,
},
[0x6] = {
"Model B rev2",
"bcm2835-rpi-b-rev2.dtb",
true,
},
[0x7] = {
"Model A",
"bcm2835-rpi-a.dtb",
false,
},
[0x8] = {
"Model A",
"bcm2835-rpi-a.dtb",
false,
},
[0x9] = {
"Model A",
"bcm2835-rpi-a.dtb",
false,
},
[0xd] = {
"Model B rev2",
"bcm2835-rpi-b-rev2.dtb",
true,
},
[0xe] = {
"Model B rev2",
"bcm2835-rpi-b-rev2.dtb",
true,
},
[0xf] = {
"Model B rev2",
"bcm2835-rpi-b-rev2.dtb",
true,
},
[0x10] = {
"Model B+",
"bcm2835-rpi-b-plus.dtb",
true,
},
[0x11] = {
"Compute Module",
"bcm2835-rpi-cm.dtb",
false,
},
[0x12] = {
"Model A+",
"bcm2835-rpi-a-plus.dtb",
false,
},
[0x13] = {
"Model B+",
"bcm2835-rpi-b-plus.dtb",
true,
},
[0x14] = {
"Compute Module",
"bcm2835-rpi-cm.dtb",
false,
},
[0x15] = {
"Model A+",
"bcm2835-rpi-a-plus.dtb",
false,
},
};
static uint32_t revision;
static uint32_t rev_scheme;
static uint32_t rev_type;
static const struct rpi_model *model;
int dram_init(void)
{
ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1);
int ret;
BCM2835_MBOX_INIT_HDR(msg);
BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY);
ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
if (ret) {
printf("bcm2835: Could not query ARM memory size\n");
return -1;
}
gd->ram_size = msg->get_arm_mem.body.resp.mem_size;
return 0;
}
static void set_fdtfile(void)
{
const char *fdtfile;
if (getenv("fdtfile"))
return;
fdtfile = model->fdtfile;
setenv("fdtfile", fdtfile);
}
static void set_usbethaddr(void)
{
ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1);
int ret;
if (!model->has_onboard_eth)
return;
if (getenv("usbethaddr"))
return;
BCM2835_MBOX_INIT_HDR(msg);
BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS);
ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
if (ret) {
printf("bcm2835: Could not query MAC address\n");
/* Ignore error; not critical */
return;
}
eth_setenv_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac);
if (!getenv("ethaddr"))
setenv("ethaddr", getenv("usbethaddr"));
return;
}
#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
static void set_board_info(void)
{
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 */
static void set_serial_number(void)
{
ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_serial, msg, 1);
int ret;
char serial_string[17] = { 0 };
if (getenv("serial#"))
return;
BCM2835_MBOX_INIT_HDR(msg);
BCM2835_MBOX_INIT_TAG_NO_REQ(&msg->get_board_serial, GET_BOARD_SERIAL);
ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
if (ret) {
printf("bcm2835: Could not query board serial\n");
/* Ignore error; not critical */
return;
}
snprintf(serial_string, sizeof(serial_string), "%016" PRIx64,
msg->get_board_serial.body.resp.serial);
setenv("serial#", serial_string);
}
int misc_init_r(void)
{
set_fdtfile();
set_usbethaddr();
#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
set_board_info();
#endif
set_serial_number();
return 0;
}
static int power_on_module(u32 module)
{
ALLOC_CACHE_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1);
int ret;
BCM2835_MBOX_INIT_HDR(msg_pwr);
BCM2835_MBOX_INIT_TAG(&msg_pwr->set_power_state,
SET_POWER_STATE);
msg_pwr->set_power_state.body.req.device_id = module;
msg_pwr->set_power_state.body.req.state =
BCM2835_MBOX_SET_POWER_STATE_REQ_ON |
BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT;
ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN,
&msg_pwr->hdr);
if (ret) {
printf("bcm2835: Could not set module %u power state\n",
module);
return -1;
}
return 0;
}
static void get_board_rev(void)
{
ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1);
int ret;
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);
ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
if (ret) {
printf("bcm2835: Could not query board revision\n");
/* Ignore error; not critical */
return;
}
/*
* For details of old-vs-new scheme, see:
* https://github.com/pimoroni/RPi.version/blob/master/RPi/version.py
* http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=99293&p=690282
* (a few posts down)
*
* For the RPi 1, bit 24 is the "warranty bit", so we mask off just the
* lower byte to use as the board rev:
* http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=98367&start=250
* http://www.raspberrypi.org/forums/viewtopic.php?f=31&t=20594
*/
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 (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];
}
printf("RPI %s (0x%x)\n", model->name, revision);
}
int board_init(void)
{
get_board_rev();
gd->bd->bi_boot_params = 0x100;
return power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD);
}
int board_mmc_init(bd_t *bis)
{
ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1);
int ret;
power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI);
BCM2835_MBOX_INIT_HDR(msg_clk);
BCM2835_MBOX_INIT_TAG(&msg_clk->get_clock_rate, GET_CLOCK_RATE);
msg_clk->get_clock_rate.body.req.clock_id = BCM2835_MBOX_CLOCK_ID_EMMC;
ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_clk->hdr);
if (ret) {
printf("bcm2835: Could not query eMMC clock rate\n");
return -1;
}
return bcm2835_sdhci_init(BCM2835_SDHCI_BASE,
msg_clk->get_clock_rate.body.resp.rate_hz);
}
int ft_board_setup(void *blob, bd_t *bd)
{
/*
* For now, we simply always add the simplefb DT node. Later, we
* should be more intelligent, and e.g. only do this if no enabled DT
* node exists for the "real" graphics driver.
*/
lcd_dt_simplefb_add_node(blob);
return 0;
}