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