aboutsummaryrefslogtreecommitdiff
path: root/include/serial.h
diff options
context:
space:
mode:
authorSean Anderson <sean.anderson@seco.com>2022-03-22 16:59:34 -0400
committerTom Rini <trini@konsulko.com>2022-04-01 16:56:54 -0400
commit7a763471894feb58d5a1bdf78ea7014c7a952264 (patch)
treefc64ed7fef66e55214c75b98a90531645a203294 /include/serial.h
parent53b953f2ebad6263352cb1247618dc5b965863cc (diff)
downloadu-boot-7a763471894feb58d5a1bdf78ea7014c7a952264.zip
u-boot-7a763471894feb58d5a1bdf78ea7014c7a952264.tar.gz
u-boot-7a763471894feb58d5a1bdf78ea7014c7a952264.tar.bz2
serial: dm: Add support for puts
Some serial drivers can be vastly more efficient when printing multiple characters at once. Non-DM serial has had a puts option for these sorts of drivers; implement it for DM serial as well. Because we have to add carriage returns, we can't just pass the whole string directly to the serial driver. Instead, we print up to the newline, then print a carriage return, and then continue on. This is less efficient, but it is better than printing each character individually. It also avoids having to allocate memory just to add a few characters. Drivers may perform short writes (such as filling a FIFO) and return the number of characters written in len. We loop over them in the same way that _serial_putc loops over putc. This results in around sizeof(void *) growth for all boards with DM_SERIAL. The full implementation takes around 140 bytes. Signed-off-by: Sean Anderson <sean.anderson@seco.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/serial.h')
-rw-r--r--include/serial.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/include/serial.h b/include/serial.h
index 2681d26..8c2e7ad 100644
--- a/include/serial.h
+++ b/include/serial.h
@@ -196,6 +196,24 @@ struct dm_serial_ops {
*/
int (*putc)(struct udevice *dev, const char ch);
/**
+ * puts() - Write a string
+ *
+ * This writes a string. This function should be implemented only if
+ * writing multiple characters at once is more performant than just
+ * calling putc() in a loop.
+ *
+ * If the whole string cannot be written at once, then this function
+ * should return the number of characters written. Returning a negative
+ * error code implies that no characters were written. If this function
+ * returns 0, then it will be called again with the same arguments.
+ *
+ * @dev: Device pointer
+ * @s: The string to write
+ * @len: The length of the string to write.
+ * @return The number of characters written on success, or -ve on error
+ */
+ ssize_t (*puts)(struct udevice *dev, const char *s, size_t len);
+ /**
* pending() - Check if input/output characters are waiting
*
* This can be used to return an indication of the number of waiting