early_printk.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. #define DEFAULT_BAUD 115200
  92. /*
  93. * Simple SCIF init, primarily aimed at SH7750 and other similar SH-4
  94. * devices that aren't using sh-ipl+g.
  95. */
  96. static void scif_sercon_init(char *s)
  97. {
  98. unsigned baud = DEFAULT_BAUD;
  99. char *e;
  100. if (*s == ',')
  101. ++s;
  102. if (*s) {
  103. /* ignore ioport/device name */
  104. s += strcspn(s, ",");
  105. if (*s == ',')
  106. s++;
  107. }
  108. if (*s) {
  109. baud = simple_strtoul(s, &e, 0);
  110. if (baud == 0 || s == e)
  111. baud = DEFAULT_BAUD;
  112. }
  113. ctrl_outw(0, scif_port.mapbase + 8);
  114. ctrl_outw(0, scif_port.mapbase);
  115. /* Set baud rate */
  116. ctrl_outb((CONFIG_SH_PCLK_FREQ + 16 * baud) /
  117. (32 * baud) - 1, scif_port.mapbase + 4);
  118. ctrl_outw(12, scif_port.mapbase + 24);
  119. ctrl_outw(8, scif_port.mapbase + 24);
  120. ctrl_outw(0, scif_port.mapbase + 32);
  121. ctrl_outw(0x60, scif_port.mapbase + 16);
  122. ctrl_outw(0, scif_port.mapbase + 36);
  123. ctrl_outw(0x30, scif_port.mapbase + 8);
  124. }
  125. #endif /* CONFIG_CPU_SH4 && !CONFIG_SH_STANDARD_BIOS */
  126. #endif /* CONFIG_EARLY_SCIF_CONSOLE */
  127. /*
  128. * Setup a default console, if more than one is compiled in, rely on the
  129. * earlyprintk= parsing to give priority.
  130. */
  131. static struct console *early_console =
  132. #ifdef CONFIG_SH_STANDARD_BIOS
  133. &bios_console
  134. #elif defined(CONFIG_EARLY_SCIF_CONSOLE)
  135. &scif_console
  136. #else
  137. NULL
  138. #endif
  139. ;
  140. static int __initdata keep_early;
  141. static int early_console_initialized;
  142. int __init setup_early_printk(char *buf)
  143. {
  144. if (!buf)
  145. return 0;
  146. if (early_console_initialized)
  147. return 0;
  148. early_console_initialized = 1;
  149. if (strstr(buf, "keep"))
  150. keep_early = 1;
  151. #ifdef CONFIG_SH_STANDARD_BIOS
  152. if (!strncmp(buf, "bios", 4))
  153. early_console = &bios_console;
  154. #endif
  155. #if defined(CONFIG_EARLY_SCIF_CONSOLE)
  156. if (!strncmp(buf, "serial", 6)) {
  157. early_console = &scif_console;
  158. #if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SH_STANDARD_BIOS)
  159. scif_sercon_init(buf + 6);
  160. #endif
  161. }
  162. #endif
  163. if (likely(early_console)) {
  164. if (keep_early)
  165. early_console->flags &= ~CON_BOOT;
  166. else
  167. early_console->flags |= CON_BOOT;
  168. register_console(early_console);
  169. }
  170. return 0;
  171. }
  172. early_param("earlyprintk", setup_early_printk);