early_printk.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. defined(CONFIG_CPU_SUBTYPE_SH7721)
  59. #define EPK_SCSMR_VALUE 0x000
  60. #define EPK_SCBRR_VALUE 0x00C
  61. #define EPK_FIFO_SIZE 64
  62. #define EPK_FIFO_BITS (0x7f00 >> 8)
  63. #else
  64. #define EPK_FIFO_SIZE 16
  65. #define EPK_FIFO_BITS (0x1f00 >> 8)
  66. #endif
  67. static struct uart_port scif_port = {
  68. .type = PORT_SCIF,
  69. .mapbase = CONFIG_EARLY_SCIF_CONSOLE_PORT,
  70. .membase = (char __iomem *)CONFIG_EARLY_SCIF_CONSOLE_PORT,
  71. };
  72. static void scif_sercon_putc(int c)
  73. {
  74. while (((sci_in(&scif_port, SCFDR) & EPK_FIFO_BITS) >= EPK_FIFO_SIZE))
  75. ;
  76. sci_in(&scif_port, SCxSR);
  77. sci_out(&scif_port, SCxSR, 0xf3 & ~(0x20 | 0x40));
  78. sci_out(&scif_port, SCxTDR, c);
  79. while ((sci_in(&scif_port, SCxSR) & 0x40) == 0)
  80. ;
  81. if (c == '\n')
  82. scif_sercon_putc('\r');
  83. }
  84. static void scif_sercon_write(struct console *con, const char *s,
  85. unsigned count)
  86. {
  87. while (count-- > 0)
  88. scif_sercon_putc(*s++);
  89. }
  90. static int __init scif_sercon_setup(struct console *con, char *options)
  91. {
  92. con->cflag = CREAD | HUPCL | CLOCAL | B115200 | CS8;
  93. return 0;
  94. }
  95. static struct console scif_console = {
  96. .name = "sercon",
  97. .write = scif_sercon_write,
  98. .setup = scif_sercon_setup,
  99. .flags = CON_PRINTBUFFER,
  100. .index = -1,
  101. };
  102. #if !defined(CONFIG_SH_STANDARD_BIOS)
  103. #if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  104. defined(CONFIG_CPU_SUBTYPE_SH7721)
  105. static void scif_sercon_init(char *s)
  106. {
  107. sci_out(&scif_port, SCSCR, 0x0000); /* clear TE and RE */
  108. sci_out(&scif_port, SCFCR, 0x4006); /* reset */
  109. sci_out(&scif_port, SCSCR, 0x0000); /* select internal clock */
  110. sci_out(&scif_port, SCSMR, EPK_SCSMR_VALUE);
  111. sci_out(&scif_port, SCBRR, EPK_SCBRR_VALUE);
  112. mdelay(1); /* wait 1-bit time */
  113. sci_out(&scif_port, SCFCR, 0x0030); /* TTRG=b'11 */
  114. sci_out(&scif_port, SCSCR, 0x0030); /* TE, RE */
  115. }
  116. #elif defined(CONFIG_CPU_SH4)
  117. #define DEFAULT_BAUD 115200
  118. /*
  119. * Simple SCIF init, primarily aimed at SH7750 and other similar SH-4
  120. * devices that aren't using sh-ipl+g.
  121. */
  122. static void scif_sercon_init(char *s)
  123. {
  124. struct uart_port *port = &scif_port;
  125. unsigned baud = DEFAULT_BAUD;
  126. unsigned int status;
  127. char *e;
  128. if (*s == ',')
  129. ++s;
  130. if (*s) {
  131. /* ignore ioport/device name */
  132. s += strcspn(s, ",");
  133. if (*s == ',')
  134. s++;
  135. }
  136. if (*s) {
  137. baud = simple_strtoul(s, &e, 0);
  138. if (baud == 0 || s == e)
  139. baud = DEFAULT_BAUD;
  140. }
  141. do {
  142. status = sci_in(port, SCxSR);
  143. } while (!(status & SCxSR_TEND(port)));
  144. sci_out(port, SCSCR, 0); /* TE=0, RE=0 */
  145. sci_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST);
  146. sci_out(port, SCSMR, 0);
  147. /* Set baud rate */
  148. sci_out(port, SCBRR, (CONFIG_SH_PCLK_FREQ + 16 * baud) /
  149. (32 * baud) - 1);
  150. udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */
  151. sci_out(port, SCSPTR, 0);
  152. sci_out(port, SCxSR, 0x60);
  153. sci_out(port, SCLSR, 0);
  154. sci_out(port, SCFCR, 0);
  155. sci_out(port, SCSCR, 0x30); /* TE=1, RE=1 */
  156. }
  157. #endif /* defined(CONFIG_CPU_SUBTYPE_SH7720) */
  158. #endif /* !defined(CONFIG_SH_STANDARD_BIOS) */
  159. #endif /* CONFIG_EARLY_SCIF_CONSOLE */
  160. /*
  161. * Setup a default console, if more than one is compiled in, rely on the
  162. * earlyprintk= parsing to give priority.
  163. */
  164. static struct console *early_console =
  165. #ifdef CONFIG_SH_STANDARD_BIOS
  166. &bios_console
  167. #elif defined(CONFIG_EARLY_SCIF_CONSOLE)
  168. &scif_console
  169. #else
  170. NULL
  171. #endif
  172. ;
  173. static int __init setup_early_printk(char *buf)
  174. {
  175. int keep_early = 0;
  176. if (!buf)
  177. return 0;
  178. if (strstr(buf, "keep"))
  179. keep_early = 1;
  180. #ifdef CONFIG_SH_STANDARD_BIOS
  181. if (!strncmp(buf, "bios", 4))
  182. early_console = &bios_console;
  183. #endif
  184. #if defined(CONFIG_EARLY_SCIF_CONSOLE)
  185. if (!strncmp(buf, "serial", 6)) {
  186. early_console = &scif_console;
  187. #if !defined(CONFIG_SH_STANDARD_BIOS)
  188. #if defined(CONFIG_CPU_SH4) || defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  189. defined(CONFIG_CPU_SUBTYPE_SH7721)
  190. scif_sercon_init(buf + 6);
  191. #endif
  192. #endif
  193. }
  194. #endif
  195. if (likely(early_console)) {
  196. if (keep_early)
  197. early_console->flags &= ~CON_BOOT;
  198. else
  199. early_console->flags |= CON_BOOT;
  200. register_console(early_console);
  201. }
  202. return 0;
  203. }
  204. early_param("earlyprintk", setup_early_printk);