cfe_console.c 1.7 KB

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