early_printk.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 - 2007 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. #include <linux/delay.h>
  17. #ifdef CONFIG_SH_STANDARD_BIOS
  18. #include <asm/sh_bios.h>
  19. /*
  20. * Print a string through the BIOS
  21. */
  22. static void sh_console_write(struct console *co, const char *s,
  23. unsigned count)
  24. {
  25. sh_bios_console_write(s, count);
  26. }
  27. /*
  28. * Setup initial baud/bits/parity. We do two things here:
  29. * - construct a cflag setting for the first rs_open()
  30. * - initialize the serial port
  31. * Return non-zero if we didn't find a serial port.
  32. */
  33. static int __init sh_console_setup(struct console *co, char *options)
  34. {
  35. int cflag = CREAD | HUPCL | CLOCAL;
  36. /*
  37. * Now construct a cflag setting.
  38. * TODO: this is a totally bogus cflag, as we have
  39. * no idea what serial settings the BIOS is using, or
  40. * even if its using the serial port at all.
  41. */
  42. cflag |= B115200 | CS8 | /*no parity*/0;
  43. co->cflag = cflag;
  44. return 0;
  45. }
  46. static struct console bios_console = {
  47. .name = "bios",
  48. .write = sh_console_write,
  49. .setup = sh_console_setup,
  50. .flags = CON_PRINTBUFFER,
  51. .index = -1,
  52. };
  53. #endif
  54. #ifdef CONFIG_EARLY_SCIF_CONSOLE
  55. #include <linux/serial_core.h>
  56. #include "../../../drivers/serial/sh-sci.h"
  57. #if defined(CONFIG_CPU_SUBTYPE_SH7720)
  58. #define EPK_SCSMR_VALUE 0x000
  59. #define EPK_SCBRR_VALUE 0x00C
  60. #define EPK_FIFO_SIZE 64
  61. #define EPK_FIFO_BITS (0x7f00 >> 8)
  62. #else
  63. #define EPK_FIFO_SIZE 16
  64. #define EPK_FIFO_BITS (0x1f00 >> 8)
  65. #endif
  66. static struct uart_port scif_port = {
  67. .mapbase = CONFIG_EARLY_SCIF_CONSOLE_PORT,
  68. .membase = (char __iomem *)CONFIG_EARLY_SCIF_CONSOLE_PORT,
  69. };
  70. static void scif_sercon_putc(int c)
  71. {
  72. while (((sci_in(&scif_port, SCFDR) & EPK_FIFO_BITS) >= EPK_FIFO_SIZE))
  73. ;
  74. sci_out(&scif_port, SCxTDR, c);
  75. sci_in(&scif_port, SCxSR);
  76. sci_out(&scif_port, SCxSR, 0xf3 & ~(0x20 | 0x40));
  77. while ((sci_in(&scif_port, SCxSR) & 0x40) == 0)
  78. ;
  79. if (c == '\n')
  80. scif_sercon_putc('\r');
  81. }
  82. static void scif_sercon_write(struct console *con, const char *s,
  83. unsigned count)
  84. {
  85. while (count-- > 0)
  86. scif_sercon_putc(*s++);
  87. }
  88. static int __init scif_sercon_setup(struct console *con, char *options)
  89. {
  90. con->cflag = CREAD | HUPCL | CLOCAL | B115200 | CS8;
  91. return 0;
  92. }
  93. static struct console scif_console = {
  94. .name = "sercon",
  95. .write = scif_sercon_write,
  96. .setup = scif_sercon_setup,
  97. .flags = CON_PRINTBUFFER,
  98. .index = -1,
  99. };
  100. #if !defined(CONFIG_SH_STANDARD_BIOS)
  101. #if defined(CONFIG_CPU_SUBTYPE_SH7720)
  102. static void scif_sercon_init(char *s)
  103. {
  104. sci_out(&scif_port, SCSCR, 0x0000); /* clear TE and RE */
  105. sci_out(&scif_port, SCFCR, 0x4006); /* reset */
  106. sci_out(&scif_port, SCSCR, 0x0000); /* select internal clock */
  107. sci_out(&scif_port, SCSMR, EPK_SCSMR_VALUE);
  108. sci_out(&scif_port, SCBRR, EPK_SCBRR_VALUE);
  109. mdelay(1); /* wait 1-bit time */
  110. sci_out(&scif_port, SCFCR, 0x0030); /* TTRG=b'11 */
  111. sci_out(&scif_port, SCSCR, 0x0030); /* TE, RE */
  112. }
  113. #elif defined(CONFIG_CPU_SH4)
  114. #define DEFAULT_BAUD 115200
  115. /*
  116. * Simple SCIF init, primarily aimed at SH7750 and other similar SH-4
  117. * devices that aren't using sh-ipl+g.
  118. */
  119. static void scif_sercon_init(char *s)
  120. {
  121. unsigned baud = DEFAULT_BAUD;
  122. char *e;
  123. if (*s == ',')
  124. ++s;
  125. if (*s) {
  126. /* ignore ioport/device name */
  127. s += strcspn(s, ",");
  128. if (*s == ',')
  129. s++;
  130. }
  131. if (*s) {
  132. baud = simple_strtoul(s, &e, 0);
  133. if (baud == 0 || s == e)
  134. baud = DEFAULT_BAUD;
  135. }
  136. ctrl_outw(0, scif_port.mapbase + 8);
  137. ctrl_outw(0, scif_port.mapbase);
  138. /* Set baud rate */
  139. ctrl_outb((CONFIG_SH_PCLK_FREQ + 16 * baud) /
  140. (32 * baud) - 1, scif_port.mapbase + 4);
  141. ctrl_outw(12, scif_port.mapbase + 24);
  142. ctrl_outw(8, scif_port.mapbase + 24);
  143. ctrl_outw(0, scif_port.mapbase + 32);
  144. ctrl_outw(0x60, scif_port.mapbase + 16);
  145. ctrl_outw(0, scif_port.mapbase + 36);
  146. ctrl_outw(0x30, scif_port.mapbase + 8);
  147. }
  148. #endif /* defined(CONFIG_CPU_SUBTYPE_SH7720) */
  149. #endif /* !defined(CONFIG_SH_STANDARD_BIOS) */
  150. #endif /* CONFIG_EARLY_SCIF_CONSOLE */
  151. /*
  152. * Setup a default console, if more than one is compiled in, rely on the
  153. * earlyprintk= parsing to give priority.
  154. */
  155. static struct console *early_console =
  156. #ifdef CONFIG_SH_STANDARD_BIOS
  157. &bios_console
  158. #elif defined(CONFIG_EARLY_SCIF_CONSOLE)
  159. &scif_console
  160. #else
  161. NULL
  162. #endif
  163. ;
  164. static int __init setup_early_printk(char *buf)
  165. {
  166. int keep_early = 0;
  167. if (!buf)
  168. return 0;
  169. if (strstr(buf, "keep"))
  170. keep_early = 1;
  171. #ifdef CONFIG_SH_STANDARD_BIOS
  172. if (!strncmp(buf, "bios", 4))
  173. early_console = &bios_console;
  174. #endif
  175. #if defined(CONFIG_EARLY_SCIF_CONSOLE)
  176. if (!strncmp(buf, "serial", 6)) {
  177. early_console = &scif_console;
  178. #if (defined(CONFIG_CPU_SH4) || defined(CONFIG_CPU_SUBTYPE_SH7720)) && \
  179. !defined(CONFIG_SH_STANDARD_BIOS)
  180. scif_sercon_init(buf + 6);
  181. #endif
  182. }
  183. #endif
  184. if (likely(early_console)) {
  185. if (keep_early)
  186. early_console->flags &= ~CON_BOOT;
  187. else
  188. early_console->flags |= CON_BOOT;
  189. register_console(early_console);
  190. }
  191. return 0;
  192. }
  193. early_param("earlyprintk", setup_early_printk);