2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-02-18 18:46:38 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2015 Google, Inc
|
|
|
|
*/
|
|
|
|
|
2017-03-20 11:40:33 +00:00
|
|
|
#include <clk.h>
|
2017-02-18 18:46:38 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <debug_uart.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <fdtdec.h>
|
|
|
|
#include <led.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <ram.h>
|
|
|
|
#include <spl.h>
|
2019-01-21 21:53:31 +00:00
|
|
|
#include <syscon.h>
|
2017-02-18 18:46:38 +00:00
|
|
|
#include <asm/gpio.h>
|
|
|
|
#include <asm/io.h>
|
2019-03-28 03:01:23 +00:00
|
|
|
#include <asm/arch-rockchip/bootrom.h>
|
|
|
|
#include <asm/arch-rockchip/clock.h>
|
|
|
|
#include <asm/arch-rockchip/grf_rk3188.h>
|
|
|
|
#include <asm/arch-rockchip/hardware.h>
|
|
|
|
#include <asm/arch-rockchip/periph.h>
|
|
|
|
#include <asm/arch-rockchip/pmu_rk3188.h>
|
|
|
|
#include <asm/arch-rockchip/sdram.h>
|
|
|
|
#include <asm/arch-rockchip/timer.h>
|
2017-02-18 18:46:38 +00:00
|
|
|
#include <dm/pinctrl.h>
|
|
|
|
#include <dm/root.h>
|
|
|
|
#include <dm/test.h>
|
|
|
|
#include <dm/util.h>
|
|
|
|
#include <power/regulator.h>
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
u32 spl_boot_device(void)
|
|
|
|
{
|
|
|
|
#if !CONFIG_IS_ENABLED(OF_PLATDATA)
|
|
|
|
const void *blob = gd->fdt_blob;
|
|
|
|
struct udevice *dev;
|
|
|
|
const char *bootdev;
|
|
|
|
int node;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
bootdev = fdtdec_get_config_string(blob, "u-boot,boot0");
|
|
|
|
debug("Boot device %s\n", bootdev);
|
|
|
|
if (!bootdev)
|
|
|
|
goto fallback;
|
|
|
|
|
|
|
|
node = fdt_path_offset(blob, bootdev);
|
|
|
|
if (node < 0) {
|
|
|
|
debug("node=%d\n", node);
|
|
|
|
goto fallback;
|
|
|
|
}
|
2018-08-09 14:17:44 +00:00
|
|
|
ret = device_get_global_by_ofnode(offset_to_ofnode(node), &dev);
|
2017-02-18 18:46:38 +00:00
|
|
|
if (ret) {
|
|
|
|
debug("device at node %s/%d not found: %d\n", bootdev, node,
|
|
|
|
ret);
|
|
|
|
goto fallback;
|
|
|
|
}
|
|
|
|
debug("Found device %s\n", dev->name);
|
|
|
|
switch (device_get_uclass_id(dev)) {
|
|
|
|
case UCLASS_SPI_FLASH:
|
|
|
|
return BOOT_DEVICE_SPI;
|
|
|
|
case UCLASS_MMC:
|
|
|
|
return BOOT_DEVICE_MMC1;
|
|
|
|
default:
|
|
|
|
debug("Booting from device uclass '%s' not supported\n",
|
|
|
|
dev_get_uclass_name(dev));
|
|
|
|
}
|
|
|
|
|
|
|
|
fallback:
|
|
|
|
#endif
|
|
|
|
return BOOT_DEVICE_MMC1;
|
|
|
|
}
|
|
|
|
|
2017-03-20 11:40:33 +00:00
|
|
|
static int setup_arm_clock(void)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
struct clk clk;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = rockchip_get_clk(&dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
clk.id = CLK_ARM;
|
|
|
|
ret = clk_request(dev, &clk);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = clk_set_rate(&clk, 600000000);
|
|
|
|
|
|
|
|
clk_free(&clk);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-11-29 02:07:38 +00:00
|
|
|
void board_init_f(ulong dummy)
|
|
|
|
{
|
2019-01-02 12:50:58 +00:00
|
|
|
struct udevice *dev;
|
2018-11-29 02:07:38 +00:00
|
|
|
int ret;
|
|
|
|
|
2019-03-29 01:09:01 +00:00
|
|
|
#ifdef CONFIG_DEBUG_UART
|
2017-02-18 18:46:38 +00:00
|
|
|
/*
|
|
|
|
* Debug UART can be used from here if required:
|
|
|
|
*
|
|
|
|
* debug_uart_init();
|
|
|
|
* printch('a');
|
|
|
|
* printhex8(0x1234);
|
|
|
|
* printascii("string");
|
|
|
|
*/
|
|
|
|
debug_uart_init();
|
2019-01-02 12:50:58 +00:00
|
|
|
printascii("U-Boot SPL board init");
|
2017-02-18 18:46:38 +00:00
|
|
|
#endif
|
|
|
|
|
2018-10-08 11:01:56 +00:00
|
|
|
#ifdef CONFIG_ROCKCHIP_USB_UART
|
|
|
|
rk_clrsetreg(&grf->uoc0_con[0],
|
|
|
|
SIDDQ_MASK | UOC_DISABLE_MASK | COMMON_ON_N_MASK,
|
|
|
|
1 << SIDDQ_SHIFT | 1 << UOC_DISABLE_SHIFT |
|
|
|
|
1 << COMMON_ON_N_SHIFT);
|
|
|
|
rk_clrsetreg(&grf->uoc0_con[2],
|
|
|
|
SOFT_CON_SEL_MASK, 1 << SOFT_CON_SEL_SHIFT);
|
|
|
|
rk_clrsetreg(&grf->uoc0_con[3],
|
|
|
|
OPMODE_MASK | XCVRSELECT_MASK |
|
|
|
|
TERMSEL_FULLSPEED_MASK | SUSPENDN_MASK,
|
|
|
|
OPMODE_NODRIVING << OPMODE_SHIFT |
|
|
|
|
XCVRSELECT_FSTRANSC << XCVRSELECT_SHIFT |
|
|
|
|
1 << TERMSEL_FULLSPEED_SHIFT |
|
|
|
|
1 << SUSPENDN_SHIFT);
|
|
|
|
rk_clrsetreg(&grf->uoc0_con[0],
|
|
|
|
BYPASSSEL_MASK | BYPASSDMEN_MASK,
|
|
|
|
1 << BYPASSSEL_SHIFT | 1 << BYPASSDMEN_SHIFT);
|
|
|
|
#endif
|
|
|
|
|
2017-03-20 06:47:16 +00:00
|
|
|
ret = spl_early_init();
|
2017-02-18 18:46:38 +00:00
|
|
|
if (ret) {
|
2017-03-20 06:47:16 +00:00
|
|
|
debug("spl_early_init() failed: %d\n", ret);
|
2017-02-18 18:46:38 +00:00
|
|
|
hang();
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = rockchip_get_clk(&dev);
|
|
|
|
if (ret) {
|
|
|
|
debug("CLK init failed: %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = uclass_get_device(UCLASS_RAM, 0, &dev);
|
|
|
|
if (ret) {
|
|
|
|
debug("DRAM init failed: %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-20 11:40:33 +00:00
|
|
|
setup_arm_clock();
|
2017-06-29 09:21:15 +00:00
|
|
|
#if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT)
|
2017-10-10 14:21:16 +00:00
|
|
|
back_to_bootrom(BROM_BOOT_NEXTSTAGE);
|
2017-02-18 18:46:38 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int setup_led(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SPL_LED
|
|
|
|
struct udevice *dev;
|
|
|
|
char *led_name;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
|
|
|
|
if (!led_name)
|
|
|
|
return 0;
|
|
|
|
ret = led_get_by_label(led_name, &dev);
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: get=%d\n", __func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = led_set_on(dev, 1);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void spl_board_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = setup_led();
|
|
|
|
if (ret) {
|
|
|
|
debug("LED ret=%d\n", ret);
|
|
|
|
hang();
|
|
|
|
}
|
|
|
|
|
|
|
|
preloader_console_init();
|
2017-06-29 09:21:15 +00:00
|
|
|
#if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
|
2017-10-10 14:21:16 +00:00
|
|
|
back_to_bootrom(BROM_BOOT_NEXTSTAGE);
|
2017-02-18 18:46:38 +00:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|