[U-Boot] [PATCH] serial: nulldev: Add nulldev serial driver
Bin Meng
bmeng.cn at gmail.com
Wed Aug 23 12:50:16 UTC 2017
Hi Wilson,
On Wed, Aug 23, 2017 at 12:51 PM, Wilson Lee <wilson.lee at ni.com> wrote:
> From: Keng Soon Cheah <keng.soon.cheah at ni.com>
>
> Some device the serial console's initialization cannot run early during
> the boot process. Hence, nulldev serial device is helpful on that
> situation.
>
> This commit is to adding nulldev serial driver. This will allows the
> default console to be specified as a nulldev.
Can you elaborate more on what issue this patch is going to resolve?
>
> Signed-off-by: Joe Hershberger <joe.hershberger at ni.com>
> Signed-off-by: Keng Soon Cheah <keng.soon.cheah at ni.com>
> Cc: Chen Yee Chew <chen.yee.chew at ni.com>
> Signed-off-by: Wilson Lee <wilson.lee at ni.com>
> ---
>
> drivers/serial/Kconfig | 7 +++
> drivers/serial/Makefile | 1 +
> drivers/serial/serial.c | 2 +
> drivers/serial/serial_nulldev.c | 103 ++++++++++++++++++++++++++++++++++++++++
> include/serial.h | 2 +
> 5 files changed, 115 insertions(+)
> create mode 100644 drivers/serial/serial_nulldev.c
>
> diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
> index a8e9978..5064edf 100644
> --- a/drivers/serial/Kconfig
> +++ b/drivers/serial/Kconfig
> @@ -409,6 +409,13 @@ config MXC_UART
> If you have a machine based on a Motorola IMX CPU you
> can enable its onboard serial port by enabling this option.
>
> +config NULLDEV_SERIAL
> + bool "Null serial device"
> + help
> + Select this to enable null serial device support. A null serial
> + device merely acts as a placeholder for a serial device and does
> + nothing for all it's operation.
> +
> config PIC32_SERIAL
> bool "Support for Microchip PIC32 on-chip UART"
> depends on DM_SERIAL && MACH_PIC32
> diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
> index 72a6996..7adcee3 100644
> --- a/drivers/serial/Makefile
> +++ b/drivers/serial/Makefile
> @@ -49,6 +49,7 @@ obj-$(CONFIG_BCM283X_MU_SERIAL) += serial_bcm283x_mu.o
> obj-$(CONFIG_MSM_SERIAL) += serial_msm.o
> obj-$(CONFIG_MVEBU_A3700_UART) += serial_mvebu_a3700.o
> obj-$(CONFIG_MPC8XX_CONS) += serial_mpc8xx.o
> +obj-$(CONFIG_NULLDEV_SERIAL) += serial_nulldev.o
>
> ifndef CONFIG_SPL_BUILD
> obj-$(CONFIG_USB_TTY) += usbtty.o
> diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c
> index cc4bdcb..b902162 100644
> --- a/drivers/serial/serial.c
> +++ b/drivers/serial/serial.c
> @@ -138,6 +138,7 @@ serial_initfunc(mpc8xx_serial_initialize);
> serial_initfunc(mxc_serial_initialize);
> serial_initfunc(mxs_auart_initialize);
> serial_initfunc(ns16550_serial_initialize);
> +serial_initfunc(nulldev_serial_initialize);
> serial_initfunc(oc_serial_initialize);
> serial_initfunc(p3mx_serial_initialize);
> serial_initfunc(pl01x_serial_initialize);
> @@ -225,6 +226,7 @@ void serial_initialize(void)
> mxc_serial_initialize();
> mxs_auart_initialize();
> ns16550_serial_initialize();
> + nulldev_serial_initialize();
Please stop adding non-DM driver.
> oc_serial_initialize();
> p3mx_serial_initialize();
> pl01x_serial_initialize();
> diff --git a/drivers/serial/serial_nulldev.c b/drivers/serial/serial_nulldev.c
> new file mode 100644
> index 0000000..0545a74
> --- /dev/null
> +++ b/drivers/serial/serial_nulldev.c
> @@ -0,0 +1,103 @@
> +/*
> + * Copyright (c) 2015 National Instruments
> + *
> + * SPDX-License-Identifier: GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <serial.h>
> +
> +
> +#ifndef CONFIG_DM_SERIAL
> +
> +static int nulldev_init(void)
> +{
> + /* nulldev is empty! */
> + return 0;
> +}
> +
> +static void nulldev_setbrg(void)
> +{
> + /* nulldev is empty! */
> +}
> +
> +static void nulldev_putc(const char c)
> +{
> + /* nulldev is empty! */
> +}
> +
> +static void nulldev_puts(const char *s)
> +{
> + /* nulldev is empty! */
> +}
> +
> +static int nulldev_input(void)
> +{
> + /* nulldev is empty! */
> + return 0;
> +}
> +
> +struct serial_device nulldev_serial_device = {
> + "nulldev",
> + nulldev_init,
> + NULL,
> + nulldev_setbrg,
> + nulldev_input,
> + nulldev_input,
> + nulldev_putc,
> + nulldev_puts,
> +};
> +
> +void nulldev_serial_initialize(void)
> +{
> + serial_register(&nulldev_serial_device);
> +}
> +
> +__weak struct serial_device *default_serial_console(void)
> +{
> + return &nulldev_serial_device;
> +}
> +
> +#else /* CONFIG_DM_SERIAL */
> +
> +static int nulldev_serial_setbrg(struct udevice *dev, int baudrate)
> +{
> + return 0;
> +}
> +
> +static int nulldev_serial_getc(struct udevice *dev)
> +{
> + return -EAGAIN;
> +}
> +
> +static int nulldev_serial_input(struct udevice *dev)
> +{
> + return 0;
> +}
> +
> +static int nulldev_serial_putc(struct udevice *dev, const char ch)
> +{
> + return 0;
> +}
> +
> +static const struct udevice_id nulldev_serial_ids[] = {
> + { .compatible = "nulldev-serial" },
> + { }
> +};
> +
> +
> +const struct dm_serial_ops nulldev_serial_ops = {
> + .putc = nulldev_serial_putc,
> + .getc = nulldev_serial_getc,
> + .setbrg = nulldev_serial_setbrg,
> +};
> +
> +U_BOOT_DRIVER(serial_nulldev) = {
> + .name = "serial_nulldev",
> + .id = UCLASS_SERIAL,
> + .of_match = nulldev_serial_ids,
> + .ops = &nulldev_serial_ops,
> +};
> +
> +#endif /* CONFIG_DM_SERIAL */
> diff --git a/include/serial.h b/include/serial.h
> index f417196..087cabe 100644
> --- a/include/serial.h
> +++ b/include/serial.h
> @@ -40,6 +40,7 @@ extern struct serial_device eserial3_device;
> extern struct serial_device eserial4_device;
> extern struct serial_device eserial5_device;
> extern struct serial_device eserial6_device;
> +extern struct serial_device nulldev_serial_device;
>
> extern void serial_register(struct serial_device *);
> extern void serial_initialize(void);
> @@ -186,6 +187,7 @@ void mpc8xx_serial_initialize(void);
> void mxc_serial_initialize(void);
> void mxs_auart_initialize(void);
> void ns16550_serial_initialize(void);
> +void nulldev_serial_initialize(void);
> void oc_serial_initialize(void);
> void p3mx_serial_initialize(void);
> void pl01x_serial_initialize(void);
> --
Regards,
Bin
More information about the U-Boot
mailing list