diff mbox series

dm: serial: introduce puts hook

Message ID 20200503130457.7080-1-peng.fan@nxp.com
State New
Headers show
Series dm: serial: introduce puts hook | expand

Commit Message

Peng Fan May 3, 2020, 1:04 p.m. UTC
Introduce puts hook for dm serial driver.

Signed-off-by: Peng Fan <peng.fan at nxp.com>
---
 drivers/serial/serial-uclass.c | 13 +++++++++++--
 include/serial.h               |  8 ++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

Comments

Simon Glass May 4, 2020, 2:17 p.m. UTC | #1
Hi Peng,

On Sun, 3 May 2020 at 06:42, Peng Fan <peng.fan at nxp.com> wrote:
>
> Introduce puts hook for dm serial driver.
>
> Signed-off-by: Peng Fan <peng.fan at nxp.com>
> ---
>  drivers/serial/serial-uclass.c | 13 +++++++++++--
>  include/serial.h               |  8 ++++++++
>  2 files changed, 19 insertions(+), 2 deletions(-)

I'm just wondering why we need this? Isn't serial_putc() enough?

Regards,
Simon
Peng Fan May 4, 2020, 2:24 p.m. UTC | #2
Hi Simon,

> Subject: Re: [PATCH] dm: serial: introduce puts hook
> 
> Hi Peng,
> 
> On Sun, 3 May 2020 at 06:42, Peng Fan <peng.fan at nxp.com> wrote:
> >
> > Introduce puts hook for dm serial driver.
> >
> > Signed-off-by: Peng Fan <peng.fan at nxp.com>
> > ---
> >  drivers/serial/serial-uclass.c | 13 +++++++++++--
> >  include/serial.h               |  8 ++++++++
> >  2 files changed, 19 insertions(+), 2 deletions(-)
> 
> I'm just wondering why we need this? Isn't serial_putc() enough?

This is to let u-boot could run in a XEN hypervisor DomU virtual machine.
It is low efficiently if each time, we use putc to let xen dom0 print uboot
log.

We could pass a string, not a char to improve performance.

Thanks,
Peng.

> 
> Regards,
> Simon
Simon Glass May 4, 2020, 3:21 p.m. UTC | #3
Hi Peng,

On Mon, 4 May 2020 at 08:24, Peng Fan <peng.fan at nxp.com> wrote:
>
> Hi Simon,
>
> > Subject: Re: [PATCH] dm: serial: introduce puts hook
> >
> > Hi Peng,
> >
> > On Sun, 3 May 2020 at 06:42, Peng Fan <peng.fan at nxp.com> wrote:
> > >
> > > Introduce puts hook for dm serial driver.
> > >
> > > Signed-off-by: Peng Fan <peng.fan at nxp.com>
> > > ---
> > >  drivers/serial/serial-uclass.c | 13 +++++++++++--
> > >  include/serial.h               |  8 ++++++++
> > >  2 files changed, 19 insertions(+), 2 deletions(-)
> >
> > I'm just wondering why we need this? Isn't serial_putc() enough?
>
> This is to let u-boot could run in a XEN hypervisor DomU virtual machine.
> It is low efficiently if each time, we use putc to let xen dom0 print uboot
> log.

OK that is the sort of thing that should be in the commit message :-)

>
> We could pass a string, not a char to improve performance.

If we are going to do that, I think it would be better to add a
write() call, with a length. It should return the number of bytes
written, since sometimes the port might be full.

The uclass itself needs a serial_write() call which would then fall
back to writing characters if the driver doesn't have the write
method.

Also should have a test.

Regards,
Simon
diff mbox series

Patch

diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index 7703c67492..b6a7502ac8 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -189,8 +189,17 @@  static void _serial_putc(struct udevice *dev, char ch)
 
 static void _serial_puts(struct udevice *dev, const char *str)
 {
-	while (*str)
-		_serial_putc(dev, *str++);
+	struct dm_serial_ops *ops = serial_get_ops(dev);
+	int err;
+
+	if (ops->puts) {
+		do {
+			err = ops->puts(dev, str);
+		} while (err == -EAGAIN);
+	} else {
+		while (*str)
+			_serial_putc(dev, *str++);
+	}
 }
 
 static int __serial_getc(struct udevice *dev)
diff --git a/include/serial.h b/include/serial.h
index 54b21a0470..0b40b27526 100644
--- a/include/serial.h
+++ b/include/serial.h
@@ -186,6 +186,14 @@  struct dm_serial_ops {
 	 * @return character (0..255), -ve on error
 	 */
 	int (*getc)(struct udevice *dev);
+	/**
+	 * puts() - puts a string
+	 *
+	 * @dev: Device pointer
+	 * @str: string to write
+	 * @return 0 if OK, -ve on error
+	 */
+	int (*puts)(struct udevice *dev, const char *str);
 	/**
 	 * putc() - Write a character
 	 *