blob: 6b7d166694e28fecc3f949b66cb94ae8c2e53950 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/sh/kernel/early_printk.c
3 *
4 * Copyright (C) 1999, 2000 Niibe Yutaka
5 * Copyright (C) 2002 M. R. Brown
Paul Mundt008d50f2007-10-02 16:24:50 +09006 * Copyright (C) 2004 - 2007 Paul Mundt
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
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>
Paul Mundt6fc21b82006-11-27 12:10:23 +090015#include <linux/io.h>
Markus Brunner3ea6bc32007-08-20 08:59:33 +090016#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#ifdef CONFIG_SH_STANDARD_BIOS
19#include <asm/sh_bios.h>
20
21/*
22 * Print a string through the BIOS
23 */
24static void sh_console_write(struct console *co, const char *s,
25 unsigned count)
26{
27 sh_bios_console_write(s, count);
28}
29
30/*
31 * Setup initial baud/bits/parity. We do two things here:
32 * - construct a cflag setting for the first rs_open()
33 * - initialize the serial port
34 * Return non-zero if we didn't find a serial port.
35 */
36static int __init sh_console_setup(struct console *co, char *options)
37{
38 int cflag = CREAD | HUPCL | CLOCAL;
39
40 /*
41 * Now construct a cflag setting.
42 * TODO: this is a totally bogus cflag, as we have
43 * no idea what serial settings the BIOS is using, or
44 * even if its using the serial port at all.
45 */
46 cflag |= B115200 | CS8 | /*no parity*/0;
47
48 co->cflag = cflag;
49
50 return 0;
51}
52
Paul Mundta80fd212006-09-27 14:26:53 +090053static struct console bios_console = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 .name = "bios",
55 .write = sh_console_write,
56 .setup = sh_console_setup,
57 .flags = CON_PRINTBUFFER,
58 .index = -1,
59};
60#endif
61
62#ifdef CONFIG_EARLY_SCIF_CONSOLE
Paul Mundta80fd212006-09-27 14:26:53 +090063#include <linux/serial_core.h>
64#include "../../../drivers/serial/sh-sci.h"
65
Yoshihiro Shimoda31a49c42007-12-26 11:45:06 +090066#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
67 defined(CONFIG_CPU_SUBTYPE_SH7721)
Markus Brunner3ea6bc32007-08-20 08:59:33 +090068#define EPK_SCSMR_VALUE 0x000
69#define EPK_SCBRR_VALUE 0x00C
70#define EPK_FIFO_SIZE 64
71#define EPK_FIFO_BITS (0x7f00 >> 8)
72#else
73#define EPK_FIFO_SIZE 16
74#define EPK_FIFO_BITS (0x1f00 >> 8)
75#endif
76
Paul Mundta80fd212006-09-27 14:26:53 +090077static struct uart_port scif_port = {
Paul Mundt6fc21b82006-11-27 12:10:23 +090078 .mapbase = CONFIG_EARLY_SCIF_CONSOLE_PORT,
79 .membase = (char __iomem *)CONFIG_EARLY_SCIF_CONSOLE_PORT,
Paul Mundta80fd212006-09-27 14:26:53 +090080};
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82static void scif_sercon_putc(int c)
83{
Markus Brunner3ea6bc32007-08-20 08:59:33 +090084 while (((sci_in(&scif_port, SCFDR) & EPK_FIFO_BITS) >= EPK_FIFO_SIZE))
Paul Mundta80fd212006-09-27 14:26:53 +090085 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Paul Mundta80fd212006-09-27 14:26:53 +090087 sci_out(&scif_port, SCxTDR, c);
88 sci_in(&scif_port, SCxSR);
89 sci_out(&scif_port, SCxSR, 0xf3 & ~(0x20 | 0x40));
90
Andy Whitcroft96989d92007-08-17 01:25:34 +090091 while ((sci_in(&scif_port, SCxSR) & 0x40) == 0)
Paul Mundta80fd212006-09-27 14:26:53 +090092 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94 if (c == '\n')
95 scif_sercon_putc('\r');
96}
97
Paul Mundta80fd212006-09-27 14:26:53 +090098static void scif_sercon_write(struct console *con, const char *s,
99 unsigned count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
101 while (count-- > 0)
102 scif_sercon_putc(*s++);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
105static int __init scif_sercon_setup(struct console *con, char *options)
106{
107 con->cflag = CREAD | HUPCL | CLOCAL | B115200 | CS8;
108
109 return 0;
110}
111
Paul Mundta80fd212006-09-27 14:26:53 +0900112static struct console scif_console = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 .name = "sercon",
114 .write = scif_sercon_write,
115 .setup = scif_sercon_setup,
116 .flags = CON_PRINTBUFFER,
117 .index = -1,
118};
119
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900120#if !defined(CONFIG_SH_STANDARD_BIOS)
Yoshihiro Shimoda31a49c42007-12-26 11:45:06 +0900121#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
122 defined(CONFIG_CPU_SUBTYPE_SH7721)
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900123static void scif_sercon_init(char *s)
124{
125 sci_out(&scif_port, SCSCR, 0x0000); /* clear TE and RE */
126 sci_out(&scif_port, SCFCR, 0x4006); /* reset */
127 sci_out(&scif_port, SCSCR, 0x0000); /* select internal clock */
128 sci_out(&scif_port, SCSMR, EPK_SCSMR_VALUE);
129 sci_out(&scif_port, SCBRR, EPK_SCBRR_VALUE);
130
131 mdelay(1); /* wait 1-bit time */
132
133 sci_out(&scif_port, SCFCR, 0x0030); /* TTRG=b'11 */
134 sci_out(&scif_port, SCSCR, 0x0030); /* TE, RE */
135}
136#elif defined(CONFIG_CPU_SH4)
Jamie Lenehan703404ea2006-12-19 12:16:06 +0900137#define DEFAULT_BAUD 115200
Paul Mundt6fc21b82006-11-27 12:10:23 +0900138/*
139 * Simple SCIF init, primarily aimed at SH7750 and other similar SH-4
140 * devices that aren't using sh-ipl+g.
141 */
Jamie Lenehan703404ea2006-12-19 12:16:06 +0900142static void scif_sercon_init(char *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
Magnus Damm0fba3212008-04-23 21:00:54 +0900144 struct uart_port *port = &scif_port;
Jamie Lenehan703404ea2006-12-19 12:16:06 +0900145 unsigned baud = DEFAULT_BAUD;
Magnus Damm4a65e382008-04-23 21:05:11 +0900146 unsigned int status;
Jamie Lenehan703404ea2006-12-19 12:16:06 +0900147 char *e;
148
149 if (*s == ',')
150 ++s;
151
152 if (*s) {
153 /* ignore ioport/device name */
154 s += strcspn(s, ",");
155 if (*s == ',')
156 s++;
157 }
158
159 if (*s) {
160 baud = simple_strtoul(s, &e, 0);
161 if (baud == 0 || s == e)
162 baud = DEFAULT_BAUD;
163 }
164
Magnus Damm4a65e382008-04-23 21:05:11 +0900165 do {
166 status = sci_in(port, SCxSR);
167 } while (!(status & SCxSR_TEND(port)));
168
Magnus Damm0fba3212008-04-23 21:00:54 +0900169 sci_out(port, SCSCR, 0); /* TE=0, RE=0 */
Magnus Damm191d4432008-04-23 21:16:06 +0900170 sci_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST);
Magnus Damm0fba3212008-04-23 21:00:54 +0900171 sci_out(port, SCSMR, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 /* Set baud rate */
Magnus Damm0fba3212008-04-23 21:00:54 +0900174 sci_out(port, SCBRR, (CONFIG_SH_PCLK_FREQ + 16 * baud) /
175 (32 * baud) - 1);
Magnus Damm4a65e382008-04-23 21:05:11 +0900176 udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Magnus Damm0fba3212008-04-23 21:00:54 +0900178 sci_out(port, SCSPTR, 0);
179 sci_out(port, SCxSR, 0x60);
180 sci_out(port, SCLSR, 0);
Magnus Damm191d4432008-04-23 21:16:06 +0900181
182 sci_out(port, SCFCR, 0);
Magnus Damm0fba3212008-04-23 21:00:54 +0900183 sci_out(port, SCSCR, 0x30); /* TE=1, RE=1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184}
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900185#endif /* defined(CONFIG_CPU_SUBTYPE_SH7720) */
186#endif /* !defined(CONFIG_SH_STANDARD_BIOS) */
Paul Mundt6fc21b82006-11-27 12:10:23 +0900187#endif /* CONFIG_EARLY_SCIF_CONSOLE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Paul Mundta80fd212006-09-27 14:26:53 +0900189/*
190 * Setup a default console, if more than one is compiled in, rely on the
191 * earlyprintk= parsing to give priority.
192 */
193static struct console *early_console =
194#ifdef CONFIG_SH_STANDARD_BIOS
195 &bios_console
196#elif defined(CONFIG_EARLY_SCIF_CONSOLE)
197 &scif_console
198#else
199 NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#endif
Paul Mundta80fd212006-09-27 14:26:53 +0900201 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Paul Mundt008d50f2007-10-02 16:24:50 +0900203static int __init setup_early_printk(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
Paul Mundt008d50f2007-10-02 16:24:50 +0900205 int keep_early = 0;
206
Paul Mundtb641fe02006-12-12 09:00:47 +0900207 if (!buf)
208 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Paul Mundta80fd212006-09-27 14:26:53 +0900210 if (strstr(buf, "keep"))
211 keep_early = 1;
212
213#ifdef CONFIG_SH_STANDARD_BIOS
214 if (!strncmp(buf, "bios", 4))
215 early_console = &bios_console;
216#endif
217#if defined(CONFIG_EARLY_SCIF_CONSOLE)
218 if (!strncmp(buf, "serial", 6)) {
219 early_console = &scif_console;
220
Yoshihiro Shimoda31a49c42007-12-26 11:45:06 +0900221#if !defined(CONFIG_SH_STANDARD_BIOS)
222#if defined(CONFIG_CPU_SH4) || defined(CONFIG_CPU_SUBTYPE_SH7720) || \
223 defined(CONFIG_CPU_SUBTYPE_SH7721)
Jamie Lenehan703404ea2006-12-19 12:16:06 +0900224 scif_sercon_init(buf + 6);
Paul Mundta80fd212006-09-27 14:26:53 +0900225#endif
Yoshihiro Shimoda31a49c42007-12-26 11:45:06 +0900226#endif
Paul Mundta80fd212006-09-27 14:26:53 +0900227 }
228#endif
229
Gerd Hoffmann69331af2007-05-08 00:26:49 -0700230 if (likely(early_console)) {
231 if (keep_early)
232 early_console->flags &= ~CON_BOOT;
233 else
234 early_console->flags |= CON_BOOT;
Paul Mundta80fd212006-09-27 14:26:53 +0900235 register_console(early_console);
Gerd Hoffmann69331af2007-05-08 00:26:49 -0700236 }
Paul Mundta80fd212006-09-27 14:26:53 +0900237
Paul Mundtb641fe02006-12-12 09:00:47 +0900238 return 0;
Paul Mundta80fd212006-09-27 14:26:53 +0900239}
Paul Mundtb641fe02006-12-12 09:00:47 +0900240early_param("earlyprintk", setup_early_printk);