1 /*
2  * Copyright (c) 2018-2020, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 #include <assert.h>
7 
8 #include <platform_def.h>
9 
10 #include <common/debug.h>
11 #include <drivers/console.h>
12 
13 #include <plat_marvell.h>
14 
15 #ifdef PLAT_a3700
16 #include <drivers/marvell/uart/a3700_console.h>
17 #define PLAT_MARVELL_UART_CLK_IN_HZ (get_ref_clk() * 1000000)
18 #define console_marvell_register console_a3700_register
19 #else
20 #include <drivers/ti/uart/uart_16550.h>
21 #define console_marvell_register console_16550_register
22 #endif
23 
24 static console_t marvell_boot_console;
25 static console_t marvell_runtime_console;
26 
27 /*******************************************************************************
28  * Functions that set up the console
29  ******************************************************************************/
30 
31 /* Initialize the console to provide early debug support */
marvell_console_boot_init(void)32 void marvell_console_boot_init(void)
33 {
34 	int rc =
35 	console_marvell_register(PLAT_MARVELL_UART_BASE,
36 				 PLAT_MARVELL_UART_CLK_IN_HZ,
37 				 MARVELL_CONSOLE_BAUDRATE,
38 				 &marvell_boot_console);
39 	if (rc == 0) {
40 		/*
41 		 * The crash console doesn't use the multi console API, it uses
42 		 * the core console functions directly. It is safe to call panic
43 		 * and let it print debug information.
44 		 */
45 		panic();
46 	}
47 
48 	console_set_scope(&marvell_boot_console, CONSOLE_FLAG_BOOT);
49 }
50 
marvell_console_boot_end(void)51 void marvell_console_boot_end(void)
52 {
53 	console_flush();
54 
55 	(void)console_unregister(&marvell_boot_console);
56 }
57 
58 /* Initialize the runtime console */
marvell_console_runtime_init(void)59 void marvell_console_runtime_init(void)
60 {
61 	int rc =
62 	console_marvell_register(PLAT_MARVELL_UART_BASE,
63 				 PLAT_MARVELL_UART_CLK_IN_HZ,
64 				 MARVELL_CONSOLE_BAUDRATE,
65 				 &marvell_runtime_console);
66 	if (rc == 0)
67 		panic();
68 
69 	console_set_scope(&marvell_runtime_console, CONSOLE_FLAG_RUNTIME);
70 }
71 
marvell_console_runtime_end(void)72 void marvell_console_runtime_end(void)
73 {
74 	console_flush();
75 
76 	(void)console_unregister(&marvell_runtime_console);
77 }
78