xref: /rk3399_ARM-atf/plat/arm/common/arm_console.c (revision c948f77136c42a92d0bb660543a3600c36dcf7f1)
1 /*
2  * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <assert.h>
8 
9 #include <platform_def.h>
10 
11 #include <common/debug.h>
12 #include <drivers/arm/pl011.h>
13 #include <drivers/console.h>
14 
15 #include <plat_arm.h>
16 
17 /*******************************************************************************
18  * Functions that set up the console
19  ******************************************************************************/
20 #if MULTI_CONSOLE_API
21 static console_pl011_t arm_boot_console;
22 static console_pl011_t arm_runtime_console;
23 #endif
24 
25 /* Initialize the console to provide early debug support */
26 void __init arm_console_boot_init(void)
27 {
28 #if MULTI_CONSOLE_API
29 	int rc = console_pl011_register(PLAT_ARM_BOOT_UART_BASE,
30 					PLAT_ARM_BOOT_UART_CLK_IN_HZ,
31 					ARM_CONSOLE_BAUDRATE,
32 					&arm_boot_console);
33 	if (rc == 0) {
34 		/*
35 		 * The crash console doesn't use the multi console API, it uses
36 		 * the core console functions directly. It is safe to call panic
37 		 * and let it print debug information.
38 		 */
39 		panic();
40 	}
41 
42 	console_set_scope(&arm_boot_console.console, CONSOLE_FLAG_BOOT);
43 #else
44 	(void)console_init(PLAT_ARM_BOOT_UART_BASE,
45 			   PLAT_ARM_BOOT_UART_CLK_IN_HZ,
46 			   ARM_CONSOLE_BAUDRATE);
47 #endif /* MULTI_CONSOLE_API */
48 }
49 
50 void arm_console_boot_end(void)
51 {
52 	(void)console_flush();
53 
54 #if MULTI_CONSOLE_API
55 	(void)console_unregister(&arm_boot_console.console);
56 #else
57 	console_uninit();
58 #endif /* MULTI_CONSOLE_API */
59 }
60 
61 /* Initialize the runtime console */
62 void arm_console_runtime_init(void)
63 {
64 #if MULTI_CONSOLE_API
65 	int rc = console_pl011_register(PLAT_ARM_BL31_RUN_UART_BASE,
66 					PLAT_ARM_BL31_RUN_UART_CLK_IN_HZ,
67 					ARM_CONSOLE_BAUDRATE,
68 					&arm_runtime_console);
69 	if (rc == 0)
70 		panic();
71 
72 	console_set_scope(&arm_runtime_console.console, CONSOLE_FLAG_RUNTIME);
73 #else
74 	(void)console_init(PLAT_ARM_BL31_RUN_UART_BASE,
75 			   PLAT_ARM_BL31_RUN_UART_CLK_IN_HZ,
76 			   ARM_CONSOLE_BAUDRATE);
77 #endif /* MULTI_CONSOLE_API */
78 }
79 
80 void arm_console_runtime_end(void)
81 {
82 	(void)console_flush();
83 
84 #if MULTI_CONSOLE_API
85 	(void)console_unregister(&arm_runtime_console.console);
86 #else
87 	console_uninit();
88 #endif /* MULTI_CONSOLE_API */
89 }
90