Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/init.h> |
| 2 | #include <linux/errno.h> |
| 3 | #include <linux/console.h> |
| 4 | |
| 5 | #include <asm/sibyte/board.h> |
| 6 | |
Aurelien Jarno | df78b5c | 2007-09-05 08:58:26 +0200 | [diff] [blame] | 7 | #include <asm/fw/cfe/cfe_api.h> |
| 8 | #include <asm/fw/cfe/cfe_error.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 10 | extern int cfe_cons_handle; |
| 11 | |
| 12 | static void cfe_console_write(struct console *cons, const char *str, |
| 13 | unsigned int count) |
| 14 | { |
| 15 | int i, last, written; |
| 16 | |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 17 | for (i=0, last=0; i<count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | if (!str[i]) |
| 19 | /* XXXKW can/should this ever happen? */ |
| 20 | return; |
| 21 | if (str[i] == '\n') { |
| 22 | do { |
| 23 | written = cfe_write(cfe_cons_handle, &str[last], i-last); |
| 24 | if (written < 0) |
| 25 | ; |
| 26 | last += written; |
| 27 | } while (last < i); |
| 28 | while (cfe_write(cfe_cons_handle, "\r", 1) <= 0) |
| 29 | ; |
| 30 | } |
| 31 | } |
| 32 | if (last != count) { |
| 33 | do { |
| 34 | written = cfe_write(cfe_cons_handle, &str[last], count-last); |
| 35 | if (written < 0) |
| 36 | ; |
| 37 | last += written; |
| 38 | } while (last < count); |
| 39 | } |
Ralf Baechle | 42a3b4f | 2005-09-03 15:56:17 -0700 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static int cfe_console_setup(struct console *cons, char *str) |
| 44 | { |
| 45 | char consdev[32]; |
| 46 | /* XXXKW think about interaction with 'console=' cmdline arg */ |
| 47 | /* If none of the console options are configured, the build will break. */ |
| 48 | if (cfe_getenv("BOOT_CONSOLE", consdev, 32) >= 0) { |
Ralf Baechle | 477f949 | 2007-08-02 12:08:32 +0100 | [diff] [blame] | 49 | #ifdef CONFIG_SERIAL_SB1250_DUART |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | if (!strcmp(consdev, "uart0")) { |
| 51 | setleds("u0cn"); |
| 52 | } else if (!strcmp(consdev, "uart1")) { |
| 53 | setleds("u1cn"); |
Ralf Baechle | 2e25406 | 2009-06-22 16:17:52 +0100 | [diff] [blame] | 54 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #endif |
| 56 | #ifdef CONFIG_VGA_CONSOLE |
Ralf Baechle | 2e25406 | 2009-06-22 16:17:52 +0100 | [diff] [blame] | 57 | if (!strcmp(consdev, "pcconsole0")) { |
| 58 | setleds("pccn"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } else |
Ralf Baechle | 2e25406 | 2009-06-22 16:17:52 +0100 | [diff] [blame] | 60 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | return -ENODEV; |
| 62 | } |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static struct console sb1250_cfe_cons = { |
| 67 | .name = "cfe", |
| 68 | .write = cfe_console_write, |
| 69 | .setup = cfe_console_setup, |
| 70 | .flags = CON_PRINTBUFFER, |
| 71 | .index = -1, |
| 72 | }; |
| 73 | |
| 74 | static int __init sb1250_cfe_console_init(void) |
| 75 | { |
| 76 | register_console(&sb1250_cfe_cons); |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | console_initcall(sb1250_cfe_console_init); |