xref: /rk3399_ARM-atf/plat/rockchip/rk3588/drivers/soc/soc.c (revision e3ec6ff4b24c7daa4dfa82709c23a22829947160)
1 /*
2  * Copyright (c) 2024, Rockchip, Inc. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <assert.h>
8 #include <errno.h>
9 
10 #include <arch_helpers.h>
11 #include <bl31/bl31.h>
12 #include <common/debug.h>
13 #include <drivers/console.h>
14 #include <drivers/delay_timer.h>
15 #include <lib/mmio.h>
16 #include <lib/xlat_tables/xlat_tables_compat.h>
17 #include <platform.h>
18 #include <platform_def.h>
19 #include <pmu.h>
20 
21 #include <plat_private.h>
22 #include <secure.h>
23 #include <soc.h>
24 
25 #define RK3588_DEV_RNG0_BASE	0xf0000000
26 #define RK3588_DEV_RNG0_SIZE	0x0ffff000
27 
28 const mmap_region_t plat_rk_mmap[] = {
29 	MAP_REGION_FLAT(RK3588_DEV_RNG0_BASE, RK3588_DEV_RNG0_SIZE,
30 			MT_DEVICE | MT_RW | MT_SECURE),
31 	MAP_REGION_FLAT(DDR_SHARE_MEM, DDR_SHARE_SIZE,
32 			MT_DEVICE | MT_RW | MT_NS),
33 	{ 0 }
34 };
35 
36 /* The RockChip power domain tree descriptor */
37 const unsigned char rockchip_power_domain_tree_desc[] = {
38 	/* No of root nodes */
39 	PLATFORM_SYSTEM_COUNT,
40 	/* No of children for the root node */
41 	PLATFORM_CLUSTER_COUNT,
42 	/* No of children for the first cluster node */
43 	PLATFORM_CLUSTER0_CORE_COUNT,
44 	/* No of children for the second cluster node */
45 	PLATFORM_CLUSTER1_CORE_COUNT
46 };
47 
48 void timer_hp_init(void)
49 {
50 	if ((mmio_read_32(TIMER_HP_BASE + TIMER_HP_CTRL) & 0x1) != 0)
51 		return;
52 
53 	mmio_write_32(TIMER_HP_BASE + TIMER_HP_CTRL, 0x0);
54 	dsb();
55 	mmio_write_32(TIMER_HP_BASE + TIMER_HP_LOAD_COUNT0, 0xffffffff);
56 	mmio_write_32(TIMER_HP_BASE + TIMER_HP_LOAD_COUNT1, 0xffffffff);
57 	mmio_write_32(TIMER_HP_BASE + TIMER_HP_INT_EN, 0);
58 	dsb();
59 	mmio_write_32(TIMER_HP_BASE + TIMER_HP_CTRL, 0x1);
60 }
61 
62 static void system_reset_init(void)
63 {
64 	/* enable wdt_ns0~4 trigger global reset and select first reset.
65 	 * enable tsadc trigger global reset and select first reset.
66 	 * enable global reset and wdt trigger pmu reset.
67 	 * select first reset trigger pmu reset.s
68 	 */
69 	mmio_write_32(CRU_BASE + CRU_GLB_RST_CON, 0xffdf);
70 
71 	/* enable wdt_s, wdt_ns reset */
72 	mmio_write_32(BUSSGRF_BASE + SGRF_SOC_CON(2), 0x0c000c00);
73 
74 	/* reset width = 0xffff */
75 	mmio_write_32(PMU1GRF_BASE + PMU1GRF_SOC_CON(1), 0xffffffff);
76 
77 	/* enable first/tsadc/wdt reset output */
78 	mmio_write_32(PMU1SGRF_BASE + PMU1SGRF_SOC_CON(0), 0x00070007);
79 
80 	/* pmu1_grf pmu1_ioc hold */
81 	mmio_write_32(PMU1GRF_BASE + PMU1GRF_SOC_CON(7), 0x30003000);
82 
83 	/* pmu1sgrf hold */
84 	mmio_write_32(PMU1SGRF_BASE + PMU1SGRF_SOC_CON(14), 0x00200020);
85 
86 	/* select tsadc_shut_m0 ionmux*/
87 	mmio_write_32(PMU0IOC_BASE + 0x0, 0x00f00020);
88 }
89 
90 void plat_rockchip_soc_init(void)
91 {
92 	secure_timer_init();
93 	timer_hp_init();
94 	system_reset_init();
95 	sgrf_init();
96 }
97