blob: 64ea9c582ef13039661835c5dc00dbc6918a8ba9 [file] [log] [blame]
Manish Pandey29495372020-04-09 15:19:26 +01001/*
Ruari Phippsddc661a2020-09-10 09:06:14 +01002 * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
Manish Pandey29495372020-04-09 15:19:26 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <drivers/arm/pl011.h>
8#include <drivers/console.h>
Ruari Phippsddc661a2020-09-10 09:06:14 +01009#include <sp_debug.h>
Olivier Deprez6967c242021-04-09 09:24:08 +020010#include <spm_helpers.h>
Manish Pandey29495372020-04-09 15:19:26 +010011
Manish Pandey29495372020-04-09 15:19:26 +010012static int (*putc_impl)(int);
13
14static int putc_hypcall(int c)
15{
16 spm_debug_log((char)c);
17
18 return c;
19}
20
21static int putc_uart(int c)
22{
23 console_pl011_putc(c);
24
25 return c;
26}
27
28void set_putc_impl(enum stdout_route route)
29{
30 switch (route) {
31
32 case HVC_CALL_AS_STDOUT:
33 putc_impl = putc_hypcall;
34 return;
35
36 case PL011_AS_STDOUT:
37 default:
38 break;
39 }
40
41 putc_impl = putc_uart;
42}
43
44int console_putc(int c)
45{
46 if (!putc_impl) {
47 return -1;
48 }
49
50 return putc_impl(c);
51}