early_printk.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 - 2006 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 <linux/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 bios_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. #include <linux/serial_core.h>
  55. #include "../../../drivers/serial/sh-sci.h"
  56. static struct uart_port scif_port = {
  57. .mapbase = CONFIG_EARLY_SCIF_CONSOLE_PORT,
  58. .membase = (char __iomem *)CONFIG_EARLY_SCIF_CONSOLE_PORT,
  59. };
  60. static void scif_sercon_putc(int c)
  61. {
  62. while (((sci_in(&scif_port, SCFDR) & 0x1f00 >> 8) == 16))
  63. ;
  64. sci_out(&scif_port, SCxTDR, c);
  65. sci_in(&scif_port, SCxSR);
  66. sci_out(&scif_port, SCxSR, 0xf3 & ~(0x20 | 0x40));
  67. while ((sci_in(&scif_port, SCxSR) & 0x40) == 0);
  68. ;
  69. if (c == '\n')
  70. scif_sercon_putc('\r');
  71. }
  72. static void scif_sercon_write(struct console *con, const char *s,
  73. unsigned count)
  74. {
  75. while (count-- > 0)
  76. scif_sercon_putc(*s++);
  77. }
  78. static int __init scif_sercon_setup(struct console *con, char *options)
  79. {
  80. con->cflag = CREAD | HUPCL | CLOCAL | B115200 | CS8;
  81. return 0;
  82. }
  83. static struct console scif_console = {
  84. .name = "sercon",
  85. .write = scif_sercon_write,
  86. .setup = scif_sercon_setup,
  87. .flags = CON_PRINTBUFFER,
  88. .index = -1,
  89. };
  90. #if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SH_STANDARD_BIOS)
  91. /*
  92. * Simple SCIF init, primarily aimed at SH7750 and other similar SH-4
  93. * devices that aren't using sh-ipl+g.
  94. */
  95. static void scif_sercon_init(int baud)
  96. {
  97. ctrl_outw(0, scif_port.mapbase + 8);
  98. ctrl_outw(0, scif_port.mapbase);
  99. /* Set baud rate */
  100. ctrl_outb((CONFIG_SH_PCLK_FREQ + 16 * baud) /
  101. (32 * baud) - 1, scif_port.mapbase + 4);
  102. ctrl_outw(12, scif_port.mapbase + 24);
  103. ctrl_outw(8, scif_port.mapbase + 24);
  104. ctrl_outw(0, scif_port.mapbase + 32);
  105. ctrl_outw(0x60, scif_port.mapbase + 16);
  106. ctrl_outw(0, scif_port.mapbase + 36);
  107. ctrl_outw(0x30, scif_port.mapbase + 8);
  108. }
  109. #endif /* CONFIG_CPU_SH4 && !CONFIG_SH_STANDARD_BIOS */
  110. #endif /* CONFIG_EARLY_SCIF_CONSOLE */
  111. /*
  112. * Setup a default console, if more than one is compiled in, rely on the
  113. * earlyprintk= parsing to give priority.
  114. */
  115. static struct console *early_console =
  116. #ifdef CONFIG_SH_STANDARD_BIOS
  117. &bios_console
  118. #elif defined(CONFIG_EARLY_SCIF_CONSOLE)
  119. &scif_console
  120. #else
  121. NULL
  122. #endif
  123. ;
  124. static int __initdata keep_early;
  125. static int early_console_initialized;
  126. int __init setup_early_printk(char *buf)
  127. {
  128. if (!buf)
  129. return 0;
  130. if (early_console_initialized)
  131. return 0;
  132. early_console_initialized = 1;
  133. if (strstr(buf, "keep"))
  134. keep_early = 1;
  135. #ifdef CONFIG_SH_STANDARD_BIOS
  136. if (!strncmp(buf, "bios", 4))
  137. early_console = &bios_console;
  138. #endif
  139. #if defined(CONFIG_EARLY_SCIF_CONSOLE)
  140. if (!strncmp(buf, "serial", 6)) {
  141. early_console = &scif_console;
  142. #if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SH_STANDARD_BIOS)
  143. scif_sercon_init(115200);
  144. #endif
  145. }
  146. #endif
  147. if (likely(early_console))
  148. register_console(early_console);
  149. return 0;
  150. }
  151. early_param("earlyprintk", setup_early_printk);
  152. void __init disable_early_printk(void)
  153. {
  154. if (!early_console_initialized || !early_console)
  155. return;
  156. if (!keep_early) {
  157. printk("disabling early console\n");
  158. unregister_console(early_console);
  159. } else
  160. printk("keeping early console\n");
  161. }