blob: 60340823798ab99f19d13ab31af5e3eb1ff45369 [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 Mundta80fd212006-09-27 14:26:53 +09006 * Copyright (C) 2004 - 2006 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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#ifdef CONFIG_SH_STANDARD_BIOS
18#include <asm/sh_bios.h>
19
20/*
21 * Print a string through the BIOS
22 */
23static void sh_console_write(struct console *co, const char *s,
24 unsigned count)
25{
26 sh_bios_console_write(s, count);
27}
28
29/*
30 * Setup initial baud/bits/parity. We do two things here:
31 * - construct a cflag setting for the first rs_open()
32 * - initialize the serial port
33 * Return non-zero if we didn't find a serial port.
34 */
35static int __init sh_console_setup(struct console *co, char *options)
36{
37 int cflag = CREAD | HUPCL | CLOCAL;
38
39 /*
40 * Now construct a cflag setting.
41 * TODO: this is a totally bogus cflag, as we have
42 * no idea what serial settings the BIOS is using, or
43 * even if its using the serial port at all.
44 */
45 cflag |= B115200 | CS8 | /*no parity*/0;
46
47 co->cflag = cflag;
48
49 return 0;
50}
51
Paul Mundta80fd212006-09-27 14:26:53 +090052static struct console bios_console = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 .name = "bios",
54 .write = sh_console_write,
55 .setup = sh_console_setup,
56 .flags = CON_PRINTBUFFER,
57 .index = -1,
58};
59#endif
60
61#ifdef CONFIG_EARLY_SCIF_CONSOLE
Paul Mundta80fd212006-09-27 14:26:53 +090062#include <linux/serial_core.h>
63#include "../../../drivers/serial/sh-sci.h"
64
Paul Mundta80fd212006-09-27 14:26:53 +090065static struct uart_port scif_port = {
Paul Mundt6fc21b82006-11-27 12:10:23 +090066 .mapbase = CONFIG_EARLY_SCIF_CONSOLE_PORT,
67 .membase = (char __iomem *)CONFIG_EARLY_SCIF_CONSOLE_PORT,
Paul Mundta80fd212006-09-27 14:26:53 +090068};
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70static void scif_sercon_putc(int c)
71{
Paul Mundta80fd212006-09-27 14:26:53 +090072 while (((sci_in(&scif_port, SCFDR) & 0x1f00 >> 8) == 16))
73 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Paul Mundta80fd212006-09-27 14:26:53 +090075 sci_out(&scif_port, SCxTDR, c);
76 sci_in(&scif_port, SCxSR);
77 sci_out(&scif_port, SCxSR, 0xf3 & ~(0x20 | 0x40));
78
79 while ((sci_in(&scif_port, SCxSR) & 0x40) == 0);
80 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82 if (c == '\n')
83 scif_sercon_putc('\r');
84}
85
Paul Mundta80fd212006-09-27 14:26:53 +090086static void scif_sercon_write(struct console *con, const char *s,
87 unsigned count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
89 while (count-- > 0)
90 scif_sercon_putc(*s++);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091}
92
93static int __init scif_sercon_setup(struct console *con, char *options)
94{
95 con->cflag = CREAD | HUPCL | CLOCAL | B115200 | CS8;
96
97 return 0;
98}
99
Paul Mundta80fd212006-09-27 14:26:53 +0900100static struct console scif_console = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 .name = "sercon",
102 .write = scif_sercon_write,
103 .setup = scif_sercon_setup,
104 .flags = CON_PRINTBUFFER,
105 .index = -1,
106};
107
Paul Mundt6fc21b82006-11-27 12:10:23 +0900108#if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SH_STANDARD_BIOS)
109/*
110 * Simple SCIF init, primarily aimed at SH7750 and other similar SH-4
111 * devices that aren't using sh-ipl+g.
112 */
Paul Mundta80fd212006-09-27 14:26:53 +0900113static void scif_sercon_init(int baud)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
Paul Mundt6fc21b82006-11-27 12:10:23 +0900115 ctrl_outw(0, scif_port.mapbase + 8);
116 ctrl_outw(0, scif_port.mapbase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118 /* Set baud rate */
119 ctrl_outb((CONFIG_SH_PCLK_FREQ + 16 * baud) /
Paul Mundt6fc21b82006-11-27 12:10:23 +0900120 (32 * baud) - 1, scif_port.mapbase + 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Paul Mundt6fc21b82006-11-27 12:10:23 +0900122 ctrl_outw(12, scif_port.mapbase + 24);
123 ctrl_outw(8, scif_port.mapbase + 24);
124 ctrl_outw(0, scif_port.mapbase + 32);
125 ctrl_outw(0x60, scif_port.mapbase + 16);
126 ctrl_outw(0, scif_port.mapbase + 36);
127 ctrl_outw(0x30, scif_port.mapbase + 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
Paul Mundt6fc21b82006-11-27 12:10:23 +0900129#endif /* CONFIG_CPU_SH4 && !CONFIG_SH_STANDARD_BIOS */
130#endif /* CONFIG_EARLY_SCIF_CONSOLE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Paul Mundta80fd212006-09-27 14:26:53 +0900132/*
133 * Setup a default console, if more than one is compiled in, rely on the
134 * earlyprintk= parsing to give priority.
135 */
136static struct console *early_console =
137#ifdef CONFIG_SH_STANDARD_BIOS
138 &bios_console
139#elif defined(CONFIG_EARLY_SCIF_CONSOLE)
140 &scif_console
141#else
142 NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143#endif
Paul Mundta80fd212006-09-27 14:26:53 +0900144 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Paul Mundta80fd212006-09-27 14:26:53 +0900146static int __initdata keep_early;
147
148int __init setup_early_printk(char *opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Paul Mundta80fd212006-09-27 14:26:53 +0900150 char *space;
151 char buf[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Paul Mundta80fd212006-09-27 14:26:53 +0900153 strlcpy(buf, opt, sizeof(buf));
154 space = strchr(buf, ' ');
155 if (space)
156 *space = 0;
157
158 if (strstr(buf, "keep"))
159 keep_early = 1;
160
161#ifdef CONFIG_SH_STANDARD_BIOS
162 if (!strncmp(buf, "bios", 4))
163 early_console = &bios_console;
164#endif
165#if defined(CONFIG_EARLY_SCIF_CONSOLE)
166 if (!strncmp(buf, "serial", 6)) {
167 early_console = &scif_console;
168
Paul Mundt6fc21b82006-11-27 12:10:23 +0900169#if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SH_STANDARD_BIOS)
Paul Mundta80fd212006-09-27 14:26:53 +0900170 scif_sercon_init(115200);
171#endif
172 }
173#endif
174
175 if (likely(early_console))
176 register_console(early_console);
177
178 return 1;
179}
180__setup("earlyprintk=", setup_early_printk);
181
182void __init disable_early_printk(void)
183{
184 if (!keep_early) {
185 printk("disabling early console\n");
186 unregister_console(early_console);
187 } else
188 printk("keeping early console\n");
189}