Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 1 | /* |
Ruari Phipps | ddc661a | 2020-09-10 09:06:14 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2020-2021, Arm Limited. All rights reserved. |
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <drivers/arm/pl011.h> |
| 8 | #include <drivers/console.h> |
Ruari Phipps | ddc661a | 2020-09-10 09:06:14 +0100 | [diff] [blame^] | 9 | #include <sp_debug.h> |
Olivier Deprez | 6967c24 | 2021-04-09 09:24:08 +0200 | [diff] [blame] | 10 | #include <spm_helpers.h> |
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 11 | |
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 12 | static int (*putc_impl)(int); |
| 13 | |
| 14 | static int putc_hypcall(int c) |
| 15 | { |
| 16 | spm_debug_log((char)c); |
| 17 | |
| 18 | return c; |
| 19 | } |
| 20 | |
| 21 | static int putc_uart(int c) |
| 22 | { |
| 23 | console_pl011_putc(c); |
| 24 | |
| 25 | return c; |
| 26 | } |
| 27 | |
| 28 | void 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 | |
| 44 | int console_putc(int c) |
| 45 | { |
| 46 | if (!putc_impl) { |
| 47 | return -1; |
| 48 | } |
| 49 | |
| 50 | return putc_impl(c); |
| 51 | } |