]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * arch/sh/kernel/early_printk.c | |
3 | * | |
4 | * Copyright (C) 1999, 2000 Niibe Yutaka | |
5 | * Copyright (C) 2002 M. R. Brown | |
008d50fc | 6 | * Copyright (C) 2004 - 2007 Paul Mundt |
1da177e4 LT |
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> | |
6fc21b82 | 15 | #include <linux/io.h> |
3ea6bc3d | 16 | #include <linux/delay.h> |
1da177e4 LT |
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 | ||
a80fd21e | 53 | static struct console bios_console = { |
1da177e4 LT |
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 | |
a80fd21e PM |
63 | #include <linux/serial_core.h> |
64 | #include "../../../drivers/serial/sh-sci.h" | |
65 | ||
31a49c4b YS |
66 | #if defined(CONFIG_CPU_SUBTYPE_SH7720) || \ |
67 | defined(CONFIG_CPU_SUBTYPE_SH7721) | |
3ea6bc3d MB |
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 | ||
a80fd21e | 77 | static struct uart_port scif_port = { |
bfbedf78 | 78 | .type = PORT_SCIF, |
6fc21b82 PM |
79 | .mapbase = CONFIG_EARLY_SCIF_CONSOLE_PORT, |
80 | .membase = (char __iomem *)CONFIG_EARLY_SCIF_CONSOLE_PORT, | |
a80fd21e | 81 | }; |
1da177e4 LT |
82 | |
83 | static void scif_sercon_putc(int c) | |
84 | { | |
3ea6bc3d | 85 | while (((sci_in(&scif_port, SCFDR) & EPK_FIFO_BITS) >= EPK_FIFO_SIZE)) |
a80fd21e | 86 | ; |
1da177e4 | 87 | |
a80fd21e PM |
88 | sci_in(&scif_port, SCxSR); |
89 | sci_out(&scif_port, SCxSR, 0xf3 & ~(0x20 | 0x40)); | |
272966c0 | 90 | sci_out(&scif_port, SCxTDR, c); |
a80fd21e | 91 | |
96989d9d | 92 | while ((sci_in(&scif_port, SCxSR) & 0x40) == 0) |
a80fd21e | 93 | ; |
1da177e4 LT |
94 | |
95 | if (c == '\n') | |
96 | scif_sercon_putc('\r'); | |
97 | } | |
98 | ||
a80fd21e PM |
99 | static void scif_sercon_write(struct console *con, const char *s, |
100 | unsigned count) | |
1da177e4 LT |
101 | { |
102 | while (count-- > 0) | |
103 | scif_sercon_putc(*s++); | |
1da177e4 LT |
104 | } |
105 | ||
106 | static int __init scif_sercon_setup(struct console *con, char *options) | |
107 | { | |
108 | con->cflag = CREAD | HUPCL | CLOCAL | B115200 | CS8; | |
109 | ||
110 | return 0; | |
111 | } | |
112 | ||
a80fd21e | 113 | static struct console scif_console = { |
1da177e4 LT |
114 | .name = "sercon", |
115 | .write = scif_sercon_write, | |
116 | .setup = scif_sercon_setup, | |
117 | .flags = CON_PRINTBUFFER, | |
118 | .index = -1, | |
119 | }; | |
120 | ||
3ea6bc3d | 121 | #if !defined(CONFIG_SH_STANDARD_BIOS) |
31a49c4b YS |
122 | #if defined(CONFIG_CPU_SUBTYPE_SH7720) || \ |
123 | defined(CONFIG_CPU_SUBTYPE_SH7721) | |
3ea6bc3d MB |
124 | static void scif_sercon_init(char *s) |
125 | { | |
126 | sci_out(&scif_port, SCSCR, 0x0000); /* clear TE and RE */ | |
127 | sci_out(&scif_port, SCFCR, 0x4006); /* reset */ | |
128 | sci_out(&scif_port, SCSCR, 0x0000); /* select internal clock */ | |
129 | sci_out(&scif_port, SCSMR, EPK_SCSMR_VALUE); | |
130 | sci_out(&scif_port, SCBRR, EPK_SCBRR_VALUE); | |
131 | ||
132 | mdelay(1); /* wait 1-bit time */ | |
133 | ||
134 | sci_out(&scif_port, SCFCR, 0x0030); /* TTRG=b'11 */ | |
135 | sci_out(&scif_port, SCSCR, 0x0030); /* TE, RE */ | |
136 | } | |
137 | #elif defined(CONFIG_CPU_SH4) | |
703404ea | 138 | #define DEFAULT_BAUD 115200 |
6fc21b82 PM |
139 | /* |
140 | * Simple SCIF init, primarily aimed at SH7750 and other similar SH-4 | |
141 | * devices that aren't using sh-ipl+g. | |
142 | */ | |
703404ea | 143 | static void scif_sercon_init(char *s) |
1da177e4 | 144 | { |
0fba3213 | 145 | struct uart_port *port = &scif_port; |
703404ea | 146 | unsigned baud = DEFAULT_BAUD; |
4a65e382 | 147 | unsigned int status; |
703404ea JL |
148 | char *e; |
149 | ||
150 | if (*s == ',') | |
151 | ++s; | |
152 | ||
153 | if (*s) { | |
154 | /* ignore ioport/device name */ | |
155 | s += strcspn(s, ","); | |
156 | if (*s == ',') | |
157 | s++; | |
158 | } | |
159 | ||
160 | if (*s) { | |
161 | baud = simple_strtoul(s, &e, 0); | |
162 | if (baud == 0 || s == e) | |
163 | baud = DEFAULT_BAUD; | |
164 | } | |
165 | ||
4a65e382 MD |
166 | do { |
167 | status = sci_in(port, SCxSR); | |
168 | } while (!(status & SCxSR_TEND(port))); | |
169 | ||
0fba3213 | 170 | sci_out(port, SCSCR, 0); /* TE=0, RE=0 */ |
191d4437 | 171 | sci_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST); |
0fba3213 | 172 | sci_out(port, SCSMR, 0); |
1da177e4 LT |
173 | |
174 | /* Set baud rate */ | |
0fba3213 MD |
175 | sci_out(port, SCBRR, (CONFIG_SH_PCLK_FREQ + 16 * baud) / |
176 | (32 * baud) - 1); | |
4a65e382 | 177 | udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */ |
0fba3213 | 178 | |
0fba3213 MD |
179 | sci_out(port, SCSPTR, 0); |
180 | sci_out(port, SCxSR, 0x60); | |
181 | sci_out(port, SCLSR, 0); | |
191d4437 MD |
182 | |
183 | sci_out(port, SCFCR, 0); | |
0fba3213 | 184 | sci_out(port, SCSCR, 0x30); /* TE=1, RE=1 */ |
1da177e4 | 185 | } |
3ea6bc3d MB |
186 | #endif /* defined(CONFIG_CPU_SUBTYPE_SH7720) */ |
187 | #endif /* !defined(CONFIG_SH_STANDARD_BIOS) */ | |
6fc21b82 | 188 | #endif /* CONFIG_EARLY_SCIF_CONSOLE */ |
1da177e4 | 189 | |
a80fd21e PM |
190 | /* |
191 | * Setup a default console, if more than one is compiled in, rely on the | |
192 | * earlyprintk= parsing to give priority. | |
193 | */ | |
194 | static struct console *early_console = | |
195 | #ifdef CONFIG_SH_STANDARD_BIOS | |
196 | &bios_console | |
197 | #elif defined(CONFIG_EARLY_SCIF_CONSOLE) | |
198 | &scif_console | |
199 | #else | |
200 | NULL | |
201 | #endif | |
202 | ; | |
203 | ||
008d50fc | 204 | static int __init setup_early_printk(char *buf) |
1da177e4 | 205 | { |
008d50fc | 206 | int keep_early = 0; |
a80fd21e | 207 | |
008d50fc | 208 | if (!buf) |
b641fe01 | 209 | return 0; |
a80fd21e PM |
210 | |
211 | if (strstr(buf, "keep")) | |
212 | keep_early = 1; | |
213 | ||
214 | #ifdef CONFIG_SH_STANDARD_BIOS | |
215 | if (!strncmp(buf, "bios", 4)) | |
216 | early_console = &bios_console; | |
217 | #endif | |
218 | #if defined(CONFIG_EARLY_SCIF_CONSOLE) | |
219 | if (!strncmp(buf, "serial", 6)) { | |
220 | early_console = &scif_console; | |
221 | ||
31a49c4b YS |
222 | #if !defined(CONFIG_SH_STANDARD_BIOS) |
223 | #if defined(CONFIG_CPU_SH4) || defined(CONFIG_CPU_SUBTYPE_SH7720) || \ | |
224 | defined(CONFIG_CPU_SUBTYPE_SH7721) | |
703404ea | 225 | scif_sercon_init(buf + 6); |
31a49c4b | 226 | #endif |
a80fd21e PM |
227 | #endif |
228 | } | |
1da177e4 | 229 | #endif |
a80fd21e | 230 | |
69331af7 GH |
231 | if (likely(early_console)) { |
232 | if (keep_early) | |
233 | early_console->flags &= ~CON_BOOT; | |
234 | else | |
235 | early_console->flags |= CON_BOOT; | |
a80fd21e | 236 | register_console(early_console); |
69331af7 | 237 | } |
a80fd21e | 238 | |
b641fe01 | 239 | return 0; |
1da177e4 | 240 | } |
b641fe01 | 241 | early_param("earlyprintk", setup_early_printk); |