Linux 4.18.10
[linux/fpc-iii.git] / drivers / tty / hvc / hvc_riscv_sbi.c
blob75155bde2b8810306dc19f97e47f334c26a3979d
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (C) 2008 David Gibson, IBM Corporation
4 * Copyright (C) 2012 Regents of the University of California
5 * Copyright (C) 2017 SiFive
6 */
8 #include <linux/console.h>
9 #include <linux/err.h>
10 #include <linux/init.h>
11 #include <linux/moduleparam.h>
12 #include <linux/types.h>
14 #include <asm/sbi.h>
16 #include "hvc_console.h"
18 static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, int count)
20 int i;
22 for (i = 0; i < count; i++)
23 sbi_console_putchar(buf[i]);
25 return i;
28 static int hvc_sbi_tty_get(uint32_t vtermno, char *buf, int count)
30 int i, c;
32 for (i = 0; i < count; i++) {
33 c = sbi_console_getchar();
34 if (c < 0)
35 break;
36 buf[i] = c;
39 return i;
42 static const struct hv_ops hvc_sbi_ops = {
43 .get_chars = hvc_sbi_tty_get,
44 .put_chars = hvc_sbi_tty_put,
47 static int __init hvc_sbi_init(void)
49 return PTR_ERR_OR_ZERO(hvc_alloc(0, 0, &hvc_sbi_ops, 16));
51 device_initcall(hvc_sbi_init);
53 static int __init hvc_sbi_console_init(void)
55 hvc_instantiate(0, 0, &hvc_sbi_ops);
56 add_preferred_console("hvc", 0, NULL);
58 return 0;
60 console_initcall(hvc_sbi_console_init);