blob: f3901a63c0bfde888d5eff93c6b628687e55dfe4 [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/pmic_wrap_init.h>
36#include <platform/pmic.h>
37
38void platform_early_init(void)
39{
40 uart_init_early();
41
42 /* initialize the interrupt controller */
43 arm_gic_init();
44
45 arm_generic_timer_init(ARM_GENERIC_TIMER_PHYSICAL_INT, 13000000);
46
47 /* init debugtop DRM */
48 mtk_drm_init();
49
50 /* init AP watchdog and set timeout to 10 secs */
51 mtk_wdt_init();
52
53 /* bl2 or bl33 specific platform early init */
54 platform_early_init_blx();
55
56 extern void mtk_wdt_early_init(void) __attribute__((weak));
57 if (mtk_wdt_early_init)
58 mtk_wdt_early_init();
59}
60
61void platform_init(void)
62{
63 int cache_ret, uncache_ret;
64
65 cache_ret = NO_ERROR;
66 if (CACHED_MEMPOOL_ADDR && CACHED_MEMPOOL_SIZE)
67 cache_ret = mempool_init((void *)CACHED_MEMPOOL_ADDR,
68 CACHED_MEMPOOL_SIZE, MEMPOOL_CACHE);
69
70 uncache_ret = NO_ERROR;
71 if (UNCACHED_MEMPOOL_ADDR && UNCACHED_MEMPOOL_SIZE)
72 uncache_ret = mempool_init((void *)UNCACHED_MEMPOOL_ADDR,
73 UNCACHED_MEMPOOL_SIZE, MEMPOOL_UNCACHE);
74
75 if ((cache_ret != NO_ERROR) || (uncache_ret != NO_ERROR))
76 platform_halt(HALT_ACTION_REBOOT, HALT_REASON_SW_PANIC);
77}
78
79/* Initialization context in start.S before switching from EL3 to EL1.
80 * Note data/bss segment NOT initialized, i.e. No assumption on global variable initialization.*/
81void platform_el3_init(void)
82{
83 gic_setup();
84}
85
86
87/*
88 * target_ab_set_active_bootdev() - set active boot device in ab boot flow
89 *
90 * this function is used to set the active boot device, aka slot in ab boot
91 * concept. For mt2731, the slot concept should be defined by the actual
92 * target. For targets that support ab boot concept should override this
93 * function.
94 *
95 * @slot: the slot # to be set as active boot device
96 *
97 * returns:
98 * -ENOTSUP: function not supported
99 */
100__WEAK int target_ab_set_active_bootdev(int slot)
101{
102 return -ENOTSUP;
103}
104
105/*
106 * override the common plat_ab_set_active_bootdev() impl.
107 */
108int plat_ab_set_active_bootdev(int slot)
109{
110 return target_ab_set_active_bootdev(slot);
111}