[PATCH v3 3/6] serial: Implement flush callback
Pali Rohár
pali at kernel.org
Mon Sep 5 19:28:38 CEST 2022
On Monday 05 September 2022 19:24:17 Michael Nazzareno Trimarchi wrote:
> Hi
>
> Il lun 5 set 2022, 11:32 Pali Rohár <pali at kernel.org> ha scritto:
>
> > UART drivers have putc/puts functions which just put characters into HW
> > transmit queue and do not wait until all data are transmitted.
> >
> > Implement flush callback via serial driver's pending(false) callback which
> > waits until HW transmit all characters from the queue.
> >
>
> This is a drain if you want to wait. Is not the right terminology?
Yes, for tty devices it is drain. But for C stdio.h it is (f)flush.
Hence I used more generic name flush() as it is not only for serial
devices, but for any U-Boot stdio device. E.g. sandbox os use real
fflush function.
But feel free to choose any other name of function. I do not care a much
about it.
> Michael
>
>
> > Signed-off-by: Pali Rohár <pali at kernel.org>
> > ---
> > drivers/serial/serial-uclass.c | 20 ++++++++++++++++++++
> > 1 file changed, 20 insertions(+)
> >
> > diff --git a/drivers/serial/serial-uclass.c
> > b/drivers/serial/serial-uclass.c
> > index 30650e37b0d7..be6502f3d24c 100644
> > --- a/drivers/serial/serial-uclass.c
> > +++ b/drivers/serial/serial-uclass.c
> > @@ -238,6 +238,18 @@ static void _serial_puts(struct udevice *dev, const
> > char *str)
> > } while (*str);
> > }
> >
> > +#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
> > +static void _serial_flush(struct udevice *dev)
> > +{
> > + struct dm_serial_ops *ops = serial_get_ops(dev);
> > +
> > + if (!ops->pending)
> > + return;
> > + while (ops->pending(dev, false) > 0)
> > + ;
> > +}
> > +#endif
> > +
> > static int __serial_getc(struct udevice *dev)
> > {
> > struct dm_serial_ops *ops = serial_get_ops(dev);
> > @@ -398,6 +410,13 @@ static void serial_stub_puts(struct stdio_dev *sdev,
> > const char *str)
> > _serial_puts(sdev->priv, str);
> > }
> >
> > +#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
> > +static void serial_stub_flush(struct stdio_dev *sdev)
> > +{
> > + _serial_flush(sdev->priv);
> > +}
> > +#endif
> > +
> > static int serial_stub_getc(struct stdio_dev *sdev)
> > {
> > return _serial_getc(sdev->priv);
> > @@ -520,6 +539,7 @@ static int serial_post_probe(struct udevice *dev)
> > sdev.priv = dev;
> > sdev.putc = serial_stub_putc;
> > sdev.puts = serial_stub_puts;
> > + STDIO_DEV_ASSIGN_FLUSH(&sdev, serial_stub_flush);
> > sdev.getc = serial_stub_getc;
> > sdev.tstc = serial_stub_tstc;
> >
> > --
> > 2.20.1
> >
> >
More information about the U-Boot
mailing list