diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig index dbb87a140f..2d386ad88a 100644 --- a/drivers/virtio/Kconfig +++ b/drivers/virtio/Kconfig @@ -74,6 +74,14 @@ if DRIVERS_VIRTIO_SERIAL config DRIVERS_VIRTIO_SERIAL_BUFSIZE int "Virtio serial driver buffer size" default 256 + +config DRIVERS_VIRTIO_SERIAL_CONSOLE + bool "Virtio serial console" + default n + select SERIAL_CONSOLE + ---help--- + This enables using first virtio serial device as console. + endif config DRIVERS_VIRTIO_SOUND diff --git a/drivers/virtio/virtio-serial.c b/drivers/virtio/virtio-serial.c index 3e3153016b..a7123ca8ee 100644 --- a/drivers/virtio/virtio-serial.c +++ b/drivers/virtio/virtio-serial.c @@ -132,6 +132,10 @@ static const struct uart_ops_s g_virtio_serial_ops = static int g_virtio_serial_idx = 0; +#ifdef CONFIG_DRIVERS_VIRTIO_SERIAL_CONSOLE +static struct uart_dev_s *g_virtio_console; +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -558,6 +562,16 @@ static int virtio_serial_probe(FAR struct virtio_device *vdev) goto err_with_init; } +#ifdef CONFIG_DRIVERS_VIRTIO_SERIAL_CONSOLE + if (g_virtio_console == NULL) + { + DEBUGVERIFY(uart_register("/dev/console", &priv->udev)); + g_virtio_console = &priv->udev; + g_virtio_console->isconsole = true; + } + +#endif + g_virtio_serial_idx++; return ret; @@ -595,3 +609,26 @@ int virtio_register_serial_driver(void) int ret2 = virtio_register_driver(&g_virtio_rprocserial_driver); return ret1 < 0 ? ret1 : ret2; } + +#ifdef CONFIG_DRIVERS_VIRTIO_SERIAL_CONSOLE +/**************************************************************************** + * Name: up_putc + ****************************************************************************/ + +int up_putc(int ch) +{ + if (g_virtio_console != NULL) + { + if (ch == '\n') + { + /* Add CR */ + + virtio_serial_send(g_virtio_console, '\r'); + } + + virtio_serial_send(g_virtio_console, ch); + } + + return ch; +} +#endif