diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig index fca194f8bb4..5485919b5c5 100644 --- a/drivers/virtio/Kconfig +++ b/drivers/virtio/Kconfig @@ -95,6 +95,15 @@ config DRIVERS_VIRTIO_SERIAL_CONSOLE ---help--- This enables using first virtio serial device as console. +config DRIVERS_VIRTIO_SERIAL_NAME + string "Virtio serial driver name" + default "" + ---help--- + Using this config to custom the virtio serial registered device name, + using ";" to split the names. + For example, if DRIVERS_VIRTIO_SERIAL_NAME = "ttyBT;ttyTEL" and pass + three virtio-serial devices to the qemu, we will get three uart devices + with names: "/dev/ttyBT", "/dev/ttyTEL", "/dev/ttyV2" endif config DRIVERS_VIRTIO_SOUND diff --git a/drivers/virtio/virtio-serial.c b/drivers/virtio/virtio-serial.c index a7123ca8eeb..fa9cb6a7446 100644 --- a/drivers/virtio/virtio-serial.c +++ b/drivers/virtio/virtio-serial.c @@ -527,6 +527,61 @@ static void virtio_serial_uninit(FAR struct virtio_serial_priv_s *priv) virtio_free_buf(vdev, priv->udev.recv.buffer); } +/**************************************************************************** + * Name: virtio_serial_uart_register + ****************************************************************************/ + +static int virtio_serial_uart_register(FAR struct virtio_serial_priv_s *priv) +{ + FAR const char *name = CONFIG_DRIVERS_VIRTIO_SERIAL_NAME; + bool found = false; + int start = 0; + int ret; + int i; + int j; + + for (i = 0, j = 0; name[start] != '\0'; i++) + { + if (name[i] == ';' || name[i] == '\0') + { + if (j++ == g_virtio_serial_idx) + { + found = true; + break; + } + + start = i + 1; + } + } + + if (found) + { + snprintf(priv->name, NAME_MAX, "/dev/%.*s", i - start, &name[start]); + } + else + { + snprintf(priv->name, NAME_MAX, "/dev/ttyV%d", g_virtio_serial_idx); + } + + ret = uart_register(priv->name, &priv->udev); + if (ret < 0) + { + return ret; + } + +#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; +} + /**************************************************************************** * Name: virtio_serial_probe ****************************************************************************/ @@ -554,25 +609,13 @@ static int virtio_serial_probe(FAR struct virtio_device *vdev) /* Uart driver register */ - snprintf(priv->name, NAME_MAX, "/dev/ttyV%d", g_virtio_serial_idx); - ret = uart_register(priv->name, &priv->udev); + ret = virtio_serial_uart_register(priv); if (ret < 0) { vrterr("uart_register failed, ret=%d\n", ret); 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; err_with_init: