Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / tty / serial / earlycon-riscv-sbi.c
blob0162155f0c83976e5aa9b014974fdf413f3b4a45
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * RISC-V SBI based earlycon
5 * Copyright (C) 2018 Anup Patel <anup@brainfault.org>
6 */
7 #include <linux/kernel.h>
8 #include <linux/console.h>
9 #include <linux/init.h>
10 #include <linux/serial_core.h>
11 #include <asm/sbi.h>
13 static void sbi_putc(struct uart_port *port, unsigned char c)
15 sbi_console_putchar(c);
18 static void sbi_0_1_console_write(struct console *con,
19 const char *s, unsigned int n)
21 struct earlycon_device *dev = con->data;
22 uart_console_write(&dev->port, s, n, sbi_putc);
25 static void sbi_dbcn_console_write(struct console *con,
26 const char *s, unsigned int n)
28 int ret;
30 while (n) {
31 ret = sbi_debug_console_write(s, n);
32 if (ret < 0)
33 break;
35 s += ret;
36 n -= ret;
40 static int __init early_sbi_setup(struct earlycon_device *device,
41 const char *opt)
43 if (sbi_debug_console_available)
44 device->con->write = sbi_dbcn_console_write;
45 else if (IS_ENABLED(CONFIG_RISCV_SBI_V01))
46 device->con->write = sbi_0_1_console_write;
47 else
48 return -ENODEV;
50 return 0;
52 EARLYCON_DECLARE(sbi, early_sbi_setup);