early_printk.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * arch/sh/kernel/early_printk.c
  3. *
  4. * Copyright (C) 1999, 2000 Niibe Yutaka
  5. * Copyright (C) 2002 M. R. Brown
  6. * Copyright (C) 2004 Paul Mundt
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/console.h>
  13. #include <linux/tty.h>
  14. #include <linux/init.h>
  15. #include <asm/io.h>
  16. #ifdef CONFIG_SH_STANDARD_BIOS
  17. #include <asm/sh_bios.h>
  18. /*
  19. * Print a string through the BIOS
  20. */
  21. static void sh_console_write(struct console *co, const char *s,
  22. unsigned count)
  23. {
  24. sh_bios_console_write(s, count);
  25. }
  26. /*
  27. * Setup initial baud/bits/parity. We do two things here:
  28. * - construct a cflag setting for the first rs_open()
  29. * - initialize the serial port
  30. * Return non-zero if we didn't find a serial port.
  31. */
  32. static int __init sh_console_setup(struct console *co, char *options)
  33. {
  34. int cflag = CREAD | HUPCL | CLOCAL;
  35. /*
  36. * Now construct a cflag setting.
  37. * TODO: this is a totally bogus cflag, as we have
  38. * no idea what serial settings the BIOS is using, or
  39. * even if its using the serial port at all.
  40. */
  41. cflag |= B115200 | CS8 | /*no parity*/0;
  42. co->cflag = cflag;
  43. return 0;
  44. }
  45. static struct console early_console = {
  46. .name = "bios",
  47. .write = sh_console_write,
  48. .setup = sh_console_setup,
  49. .flags = CON_PRINTBUFFER,
  50. .index = -1,
  51. };
  52. #endif
  53. #ifdef CONFIG_EARLY_SCIF_CONSOLE
  54. #define SCIF_REG 0xffe80000
  55. static void scif_sercon_putc(int c)
  56. {
  57. while (!(ctrl_inw(SCIF_REG + 0x10) & 0x20)) ;
  58. ctrl_outb(c, SCIF_REG + 12);
  59. ctrl_outw((ctrl_inw(SCIF_REG + 0x10) & 0x9f), SCIF_REG + 0x10);
  60. if (c == '\n')
  61. scif_sercon_putc('\r');
  62. }
  63. static void scif_sercon_flush(void)
  64. {
  65. ctrl_outw((ctrl_inw(SCIF_REG + 0x10) & 0xbf), SCIF_REG + 0x10);
  66. while (!(ctrl_inw(SCIF_REG + 0x10) & 0x40)) ;
  67. ctrl_outw((ctrl_inw(SCIF_REG + 0x10) & 0xbf), SCIF_REG + 0x10);
  68. }
  69. static void scif_sercon_write(struct console *con, const char *s, unsigned count)
  70. {
  71. while (count-- > 0)
  72. scif_sercon_putc(*s++);
  73. scif_sercon_flush();
  74. }
  75. static int __init scif_sercon_setup(struct console *con, char *options)
  76. {
  77. con->cflag = CREAD | HUPCL | CLOCAL | B115200 | CS8;
  78. return 0;
  79. }
  80. static struct console early_console = {
  81. .name = "sercon",
  82. .write = scif_sercon_write,
  83. .setup = scif_sercon_setup,
  84. .flags = CON_PRINTBUFFER,
  85. .index = -1,
  86. };
  87. void scif_sercon_init(int baud)
  88. {
  89. ctrl_outw(0, SCIF_REG + 8);
  90. ctrl_outw(0, SCIF_REG);
  91. /* Set baud rate */
  92. ctrl_outb((CONFIG_SH_PCLK_FREQ + 16 * baud) /
  93. (32 * baud) - 1, SCIF_REG + 4);
  94. ctrl_outw(12, SCIF_REG + 24);
  95. ctrl_outw(8, SCIF_REG + 24);
  96. ctrl_outw(0, SCIF_REG + 32);
  97. ctrl_outw(0x60, SCIF_REG + 16);
  98. ctrl_outw(0, SCIF_REG + 36);
  99. ctrl_outw(0x30, SCIF_REG + 8);
  100. }
  101. #endif
  102. void __init enable_early_printk(void)
  103. {
  104. #ifdef CONFIG_EARLY_SCIF_CONSOLE
  105. scif_sercon_init(115200);
  106. #endif
  107. register_console(&early_console);
  108. }
  109. void disable_early_printk(void)
  110. {
  111. unregister_console(&early_console);
  112. }