From 241c6a017b65a88b1c23c701b32618e3ff5e8e07 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 4 Jun 2014 09:17:31 +0200 Subject: console: Add puts callback to console devices Some devices may have a much more efficient way to output strings rather than single characters. Let console devices implement a callback for this. Signed-off-by: Sascha Hauer --- common/console.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'common/console.c') diff --git a/common/console.c b/common/console.c index aa9e3ce0f5..b3198356a2 100644 --- a/common/console.c +++ b/common/console.c @@ -162,6 +162,22 @@ static void console_set_stdoutpath(struct console_device *cdev) free(str); } +static int __console_puts(struct console_device *cdev, const char *s) +{ + int n = 0; + + while (*s) { + if (*s == '\n') { + cdev->putc(cdev, '\r'); + n++; + } + cdev->putc(cdev, *s); + n++; + s++; + } + return n; +} + int console_register(struct console_device *newcdev) { struct device_d *dev = &newcdev->class_dev; @@ -182,6 +198,9 @@ int console_register(struct console_device *newcdev) NULL, &newcdev->baudrate, "%u", newcdev); } + if (newcdev->putc && !newcdev->puts) + newcdev->puts = __console_puts; + dev_add_param(dev, "active", console_std_set, NULL, 0); if (IS_ENABLED(CONFIG_CONSOLE_ACTIVATE_FIRST)) { @@ -342,9 +361,19 @@ EXPORT_SYMBOL(console_putc); int console_puts(unsigned int ch, const char *str) { + struct console_device *cdev; const char *s = str; int n = 0; + if (initialized == CONSOLE_INIT_FULL) { + for_each_console(cdev) { + if (cdev->f_active & ch) { + n = cdev->puts(cdev, str); + } + } + return n; + } + while (*s) { if (*s == '\n') { console_putc(ch, '\r'); -- cgit v1.2.3