- Update to 2.6.25-rc3.
[linux-flexiantxendom0-3.2.10.git] / arch / sh / kernel / early_printk.c
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
18 #ifdef CONFIG_SH_STANDARD_BIOS
19 #include <asm/sh_bios.h>
20
21 /*
22  *      Print a string through the BIOS
23  */
24 static 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  */
36 static 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
53 static struct console bios_console = {
54         .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
63 #include <linux/serial_core.h>
64 #include "../../../drivers/serial/sh-sci.h"
65
66 #if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
67     defined(CONFIG_CPU_SUBTYPE_SH7721)
68 #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
77 static struct uart_port scif_port = {
78         .mapbase        = CONFIG_EARLY_SCIF_CONSOLE_PORT,
79         .membase        = (char __iomem *)CONFIG_EARLY_SCIF_CONSOLE_PORT,
80 };
81
82 static void scif_sercon_putc(int c)
83 {
84         while (((sci_in(&scif_port, SCFDR) & EPK_FIFO_BITS) >= EPK_FIFO_SIZE))
85                 ;
86
87         sci_out(&scif_port, SCxTDR, c);
88         sci_in(&scif_port, SCxSR);
89         sci_out(&scif_port, SCxSR, 0xf3 & ~(0x20 | 0x40));
90
91         while ((sci_in(&scif_port, SCxSR) & 0x40) == 0)
92                 ;
93
94         if (c == '\n')
95                 scif_sercon_putc('\r');
96 }
97
98 static void scif_sercon_write(struct console *con, const char *s,
99                               unsigned count)
100 {
101         while (count-- > 0)
102                 scif_sercon_putc(*s++);
103 }
104
105 static 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
112 static struct console scif_console = {
113         .name           = "sercon",
114         .write          = scif_sercon_write,
115         .setup          = scif_sercon_setup,
116         .flags          = CON_PRINTBUFFER,
117         .index          = -1,
118 };
119
120 #if !defined(CONFIG_SH_STANDARD_BIOS)
121 #if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
122     defined(CONFIG_CPU_SUBTYPE_SH7721)
123 static 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)
137 #define DEFAULT_BAUD 115200
138 /*
139  * Simple SCIF init, primarily aimed at SH7750 and other similar SH-4
140  * devices that aren't using sh-ipl+g.
141  */
142 static void scif_sercon_init(char *s)
143 {
144         unsigned baud = DEFAULT_BAUD;
145         char *e;
146
147         if (*s == ',')
148                 ++s;
149
150         if (*s) {
151                 /* ignore ioport/device name */
152                 s += strcspn(s, ",");
153                 if (*s == ',')
154                         s++;
155         }
156
157         if (*s) {
158                 baud = simple_strtoul(s, &e, 0);
159                 if (baud == 0 || s == e)
160                         baud = DEFAULT_BAUD;
161         }
162
163         ctrl_outw(0, scif_port.mapbase + 8);
164         ctrl_outw(0, scif_port.mapbase);
165
166         /* Set baud rate */
167         ctrl_outb((CONFIG_SH_PCLK_FREQ + 16 * baud) /
168                   (32 * baud) - 1, scif_port.mapbase + 4);
169
170         ctrl_outw(12, scif_port.mapbase + 24);
171         ctrl_outw(8, scif_port.mapbase + 24);
172         ctrl_outw(0, scif_port.mapbase + 32);
173         ctrl_outw(0x60, scif_port.mapbase + 16);
174         ctrl_outw(0, scif_port.mapbase + 36);
175         ctrl_outw(0x30, scif_port.mapbase + 8);
176 }
177 #endif /* defined(CONFIG_CPU_SUBTYPE_SH7720) */
178 #endif /* !defined(CONFIG_SH_STANDARD_BIOS) */
179 #endif /* CONFIG_EARLY_SCIF_CONSOLE */
180
181 /*
182  * Setup a default console, if more than one is compiled in, rely on the
183  * earlyprintk= parsing to give priority.
184  */
185 static struct console *early_console =
186 #ifdef CONFIG_SH_STANDARD_BIOS
187         &bios_console
188 #elif defined(CONFIG_EARLY_SCIF_CONSOLE)
189         &scif_console
190 #else
191         NULL
192 #endif
193         ;
194
195 static int __init setup_early_printk(char *buf)
196 {
197         int keep_early = 0;
198
199         if (!buf)
200                 return 0;
201
202         if (strstr(buf, "keep"))
203                 keep_early = 1;
204
205 #ifdef CONFIG_SH_STANDARD_BIOS
206         if (!strncmp(buf, "bios", 4))
207                 early_console = &bios_console;
208 #endif
209 #if defined(CONFIG_EARLY_SCIF_CONSOLE)
210         if (!strncmp(buf, "serial", 6)) {
211                 early_console = &scif_console;
212
213 #if !defined(CONFIG_SH_STANDARD_BIOS)
214 #if defined(CONFIG_CPU_SH4) || defined(CONFIG_CPU_SUBTYPE_SH7720) || \
215     defined(CONFIG_CPU_SUBTYPE_SH7721)
216                 scif_sercon_init(buf + 6);
217 #endif
218 #endif
219         }
220 #endif
221
222         if (likely(early_console)) {
223                 if (keep_early)
224                         early_console->flags &= ~CON_BOOT;
225                 else
226                         early_console->flags |= CON_BOOT;
227                 register_console(early_console);
228         }
229
230         return 0;
231 }
232 early_param("earlyprintk", setup_early_printk);