blob: dffb588ec9a7d4009eb23bb9b29507becf245815 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2018 MediaTek Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23#include <debug.h>
24#include <dev/interrupt/arm_gic.h>
25#include <dev/timer/arm_generic.h>
26#include <dev/uart.h>
27#include <err.h>
28#include <errno.h>
29#include <lib/mempool.h>
30#include <platform.h>
31#include <platform/platform_blx.h>
32#include <platform/gic.h>
33#include <platform/mtk_wdt.h>
34#include <platform/mtk_drm.h>
35#include <platform/mt_gpio.h>
36
37void platform_early_init(void)
38{
39 uart_init_early();
40
41 /* initialize the interrupt controller */
42 arm_gic_init();
43
44 arm_generic_timer_init(ARM_GENERIC_TIMER_PHYSICAL_INT, 13000000);
45
46 /* init debugtop DRM */
47 mtk_drm_init();
48
49 /* init AP watchdog and set timeout to 10 secs */
50 mtk_wdt_init();
51
52 /* init gpio */
53 mtk_gpio_init();
54
55 /* bl2 or bl33 specific platform early init */
56 platform_early_init_blx();
57
58 extern void mtk_wdt_early_init(void) __attribute__((weak));
59 if (mtk_wdt_early_init)
60 mtk_wdt_early_init();
61}
62
63void platform_init(void)
64{
65 int cache_ret, uncache_ret;
66
67 cache_ret = NO_ERROR;
68 if (CACHED_MEMPOOL_ADDR && CACHED_MEMPOOL_SIZE)
69 cache_ret = mempool_init((void *)CACHED_MEMPOOL_ADDR,
70 CACHED_MEMPOOL_SIZE, MEMPOOL_CACHE);
71
72 uncache_ret = NO_ERROR;
73 if (UNCACHED_MEMPOOL_ADDR && UNCACHED_MEMPOOL_SIZE)
74 uncache_ret = mempool_init((void *)UNCACHED_MEMPOOL_ADDR,
75 UNCACHED_MEMPOOL_SIZE, MEMPOOL_UNCACHE);
76
77 if ((cache_ret != NO_ERROR) || (uncache_ret != NO_ERROR))
78 platform_halt(HALT_ACTION_REBOOT, HALT_REASON_SW_PANIC);
79}
80
81/* Initialization context in start.S before switching from EL3 to EL1.
82 * Note data/bss segment NOT initialized, i.e. No assumption on global variable initialization.*/
83void platform_el3_init(void)
84{
85 gic_setup();
86}
87
88
89/*
90 * target_ab_set_active_bootdev() - set active boot device in ab boot flow
91 *
92 * this function is used to set the active boot device, aka slot in ab boot
93 * concept. For mt2735, the slot concept should be defined by the actual
94 * target. For targets that support ab boot concept should override this
95 * function.
96 *
97 * @slot: the slot # to be set as active boot device
98 *
99 * returns:
100 * -ENOTSUP: function not supported
101 */
102__WEAK int target_ab_set_active_bootdev(int slot)
103{
104 return 0;
105}
106
107/*
108 * override the common plat_ab_set_active_bootdev() impl.
109 */
110int plat_ab_set_active_bootdev(int slot)
111{
112 return target_ab_set_active_bootdev(slot);
113}