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>
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index a07fab2..76171e7 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -133,6 +133,19 @@
 	help
 	  The size of the RX buffer (needs to be power of 2)
 
+config SERIAL_PUTS
+	bool "Enable printing strings all at once"
+	depends on DM_SERIAL
+	help
+	  Some serial drivers are much more efficient when printing multiple
+	  characters at once rather than printing characters individually. This
+	  can be because they can load a fifo, or because individual print
+	  calls have a constant overhead. With this option set, the serial
+	  subsystem will try to provide serial drivers with as many characters
+	  at once as possible, instead of printing characters one by one. Most
+	  serial drivers do not need this config to print efficiently. If
+	  unsure, say N.
+
 config SERIAL_SEARCH_ALL
 	bool "Search for serial devices after default one failed"
 	depends on DM_SERIAL