2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-08-12 09:58:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Rockchip Electronics Co., Ltd
|
|
|
|
*/
|
2019-07-22 12:02:10 +00:00
|
|
|
#include <common.h>
|
2020-05-10 17:40:03 +00:00
|
|
|
#include <command.h>
|
2019-07-22 12:02:13 +00:00
|
|
|
#include <dm.h>
|
2019-08-01 15:46:51 +00:00
|
|
|
#include <env.h>
|
2019-07-22 12:02:13 +00:00
|
|
|
#include <clk.h>
|
2019-11-14 19:57:46 +00:00
|
|
|
#include <init.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <malloc.h>
|
2019-07-09 13:58:44 +00:00
|
|
|
#include <asm/armv7.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2016-08-12 09:58:12 +00:00
|
|
|
#include <asm/io.h>
|
2019-07-22 11:59:30 +00:00
|
|
|
#include <asm/arch-rockchip/bootrom.h>
|
2019-07-22 12:02:13 +00:00
|
|
|
#include <asm/arch-rockchip/clock.h>
|
2020-07-21 06:46:38 +00:00
|
|
|
#include <asm/arch-rockchip/cpu_rk3288.h>
|
2020-01-09 08:52:17 +00:00
|
|
|
#include <asm/arch-rockchip/cru.h>
|
2019-03-28 03:01:23 +00:00
|
|
|
#include <asm/arch-rockchip/hardware.h>
|
2019-03-29 01:09:03 +00:00
|
|
|
#include <asm/arch-rockchip/grf_rk3288.h>
|
2019-07-22 11:59:26 +00:00
|
|
|
#include <asm/arch-rockchip/pmu_rk3288.h>
|
2019-07-22 12:02:10 +00:00
|
|
|
#include <asm/arch-rockchip/qos_rk3288.h>
|
2019-11-15 03:04:33 +00:00
|
|
|
#include <asm/arch-rockchip/sdram.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <linux/err.h>
|
2019-07-22 11:59:26 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
2016-08-12 09:58:12 +00:00
|
|
|
|
2019-03-29 01:09:03 +00:00
|
|
|
#define GRF_BASE 0xff770000
|
2016-08-12 09:58:12 +00:00
|
|
|
|
2019-07-22 11:59:30 +00:00
|
|
|
const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
|
2022-04-15 21:21:43 +00:00
|
|
|
[BROM_BOOTSOURCE_EMMC] = "/mmc@ff0f0000",
|
|
|
|
[BROM_BOOTSOURCE_SD] = "/mmc@ff0c0000",
|
2019-07-22 11:59:30 +00:00
|
|
|
};
|
|
|
|
|
2019-07-09 13:58:44 +00:00
|
|
|
#ifdef CONFIG_SPL_BUILD
|
|
|
|
static void configure_l2ctlr(void)
|
|
|
|
{
|
|
|
|
u32 l2ctlr;
|
|
|
|
|
|
|
|
l2ctlr = read_l2ctlr();
|
|
|
|
l2ctlr &= 0xfffc0000; /* clear bit0~bit17 */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Data RAM write latency: 2 cycles
|
|
|
|
* Data RAM read latency: 2 cycles
|
|
|
|
* Data RAM setup latency: 1 cycle
|
|
|
|
* Tag RAM write latency: 1 cycle
|
|
|
|
* Tag RAM read latency: 1 cycle
|
|
|
|
* Tag RAM setup latency: 1 cycle
|
|
|
|
*/
|
|
|
|
l2ctlr |= (1 << 3 | 1 << 0);
|
|
|
|
write_l2ctlr(l2ctlr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-07-22 12:02:10 +00:00
|
|
|
int rk3288_qos_init(void)
|
|
|
|
{
|
|
|
|
int val = 2 << PRIORITY_HIGH_SHIFT | 2 << PRIORITY_LOW_SHIFT;
|
|
|
|
/* set vop qos to higher priority */
|
|
|
|
writel(val, CPU_AXI_QOS_PRIORITY + VIO0_VOP_QOS);
|
|
|
|
writel(val, CPU_AXI_QOS_PRIORITY + VIO1_VOP_QOS);
|
|
|
|
|
|
|
|
if (!fdt_node_check_compatible(gd->fdt_blob, 0,
|
|
|
|
"rockchip,rk3288-tinker")) {
|
|
|
|
/* set isp qos to higher priority */
|
|
|
|
writel(val, CPU_AXI_QOS_PRIORITY + VIO1_ISP_R_QOS);
|
|
|
|
writel(val, CPU_AXI_QOS_PRIORITY + VIO1_ISP_W0_QOS);
|
|
|
|
writel(val, CPU_AXI_QOS_PRIORITY + VIO1_ISP_W1_QOS);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-12 09:58:12 +00:00
|
|
|
int arch_cpu_init(void)
|
|
|
|
{
|
2019-07-09 13:58:43 +00:00
|
|
|
#ifdef CONFIG_SPL_BUILD
|
|
|
|
configure_l2ctlr();
|
|
|
|
#else
|
2016-08-12 09:58:12 +00:00
|
|
|
/* We do some SoC one time setting here. */
|
2019-03-29 01:09:03 +00:00
|
|
|
struct rk3288_grf * const grf = (void *)GRF_BASE;
|
2016-08-12 09:58:12 +00:00
|
|
|
|
|
|
|
/* Use rkpwm by default */
|
2019-03-29 01:09:03 +00:00
|
|
|
rk_setreg(&grf->soc_con2, 1 << 0);
|
2019-07-22 12:02:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable JTAG on sdmmc0 IO. The SDMMC won't work until this bit is
|
|
|
|
* cleared
|
|
|
|
*/
|
|
|
|
rk_clrreg(&grf->soc_con0, 1 << 12);
|
|
|
|
|
|
|
|
rk3288_qos_init();
|
2019-07-09 13:58:43 +00:00
|
|
|
#endif
|
2016-08-12 09:58:12 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-03-29 01:09:04 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_UART_BOARD_INIT
|
|
|
|
void board_debug_uart_init(void)
|
|
|
|
{
|
|
|
|
/* Enable early UART on the RK3288 */
|
|
|
|
struct rk3288_grf * const grf = (void *)GRF_BASE;
|
|
|
|
|
|
|
|
rk_clrsetreg(&grf->gpio7ch_iomux, GPIO7C7_MASK << GPIO7C7_SHIFT |
|
|
|
|
GPIO7C6_MASK << GPIO7C6_SHIFT,
|
|
|
|
GPIO7C7_UART2DBG_SOUT << GPIO7C7_SHIFT |
|
|
|
|
GPIO7C6_UART2DBG_SIN << GPIO7C6_SHIFT);
|
|
|
|
}
|
|
|
|
#endif
|
2019-07-22 12:02:13 +00:00
|
|
|
|
2019-07-22 12:02:14 +00:00
|
|
|
__weak int rk3288_board_late_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rk_board_late_init(void)
|
|
|
|
{
|
|
|
|
return rk3288_board_late_init();
|
|
|
|
}
|
|
|
|
|
2020-07-21 06:46:38 +00:00
|
|
|
static int ft_rk3288w_setup(void *blob)
|
|
|
|
{
|
|
|
|
const char *path;
|
|
|
|
int offs, ret;
|
|
|
|
|
|
|
|
path = "/clock-controller@ff760000";
|
|
|
|
offs = fdt_path_offset(blob, path);
|
|
|
|
if (offs < 0) {
|
|
|
|
debug("failed to found fdt path %s\n", path);
|
|
|
|
return offs;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = fdt_setprop_string(blob, offs, "compatible", "rockchip,rk3288w-cru");
|
|
|
|
if (ret) {
|
|
|
|
printf("failed to set rk3288w-cru compatible (ret=%d)\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ft_board_setup(void *blob, struct bd_info *bd)
|
|
|
|
{
|
|
|
|
if (soc_is_rk3288w())
|
|
|
|
return ft_rk3288w_setup(blob);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_clock(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2019-07-22 12:02:13 +00:00
|
|
|
{
|
|
|
|
static const struct {
|
|
|
|
char *name;
|
|
|
|
int id;
|
|
|
|
} clks[] = {
|
|
|
|
{ "osc", CLK_OSC },
|
|
|
|
{ "apll", CLK_ARM },
|
|
|
|
{ "dpll", CLK_DDR },
|
|
|
|
{ "cpll", CLK_CODEC },
|
|
|
|
{ "gpll", CLK_GENERAL },
|
|
|
|
#ifdef CONFIG_ROCKCHIP_RK3036
|
|
|
|
{ "mpll", CLK_NEW },
|
|
|
|
#else
|
|
|
|
{ "npll", CLK_NEW },
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
int ret, i;
|
|
|
|
struct udevice *dev;
|
|
|
|
|
|
|
|
ret = rockchip_get_clk(&dev);
|
|
|
|
if (ret) {
|
|
|
|
printf("clk-uclass not found\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(clks); i++) {
|
|
|
|
struct clk clk;
|
|
|
|
ulong rate;
|
|
|
|
|
|
|
|
clk.id = clks[i].id;
|
|
|
|
ret = clk_request(dev, &clk);
|
|
|
|
if (ret < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rate = clk_get_rate(&clk);
|
|
|
|
printf("%s: %lu\n", clks[i].name, rate);
|
|
|
|
|
|
|
|
clk_free(&clk);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
clock, 2, 1, do_clock,
|
|
|
|
"display information about clocks",
|
|
|
|
""
|
|
|
|
);
|