Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/sh/kernel/early_printk.c |
| 3 | * |
| 4 | * Copyright (C) 1999, 2000 Niibe Yutaka |
| 5 | * Copyright (C) 2002 M. R. Brown |
Paul Mundt | 008d50f | 2007-10-02 16:24:50 +0900 | [diff] [blame^] | 6 | * Copyright (C) 2004 - 2007 Paul Mundt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Paul Mundt | 6fc21b8 | 2006-11-27 12:10:23 +0900 | [diff] [blame] | 15 | #include <linux/io.h> |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 16 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 53 | static struct console bios_console = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 63 | #include <linux/serial_core.h> |
| 64 | #include "../../../drivers/serial/sh-sci.h" |
| 65 | |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 66 | #if defined(CONFIG_CPU_SUBTYPE_SH7720) |
| 67 | #define EPK_SCSMR_VALUE 0x000 |
| 68 | #define EPK_SCBRR_VALUE 0x00C |
| 69 | #define EPK_FIFO_SIZE 64 |
| 70 | #define EPK_FIFO_BITS (0x7f00 >> 8) |
| 71 | #else |
| 72 | #define EPK_FIFO_SIZE 16 |
| 73 | #define EPK_FIFO_BITS (0x1f00 >> 8) |
| 74 | #endif |
| 75 | |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 76 | static struct uart_port scif_port = { |
Paul Mundt | 6fc21b8 | 2006-11-27 12:10:23 +0900 | [diff] [blame] | 77 | .mapbase = CONFIG_EARLY_SCIF_CONSOLE_PORT, |
| 78 | .membase = (char __iomem *)CONFIG_EARLY_SCIF_CONSOLE_PORT, |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 79 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | static void scif_sercon_putc(int c) |
| 82 | { |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 83 | while (((sci_in(&scif_port, SCFDR) & EPK_FIFO_BITS) >= EPK_FIFO_SIZE)) |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 84 | ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 86 | sci_out(&scif_port, SCxTDR, c); |
| 87 | sci_in(&scif_port, SCxSR); |
| 88 | sci_out(&scif_port, SCxSR, 0xf3 & ~(0x20 | 0x40)); |
| 89 | |
Andy Whitcroft | 96989d9 | 2007-08-17 01:25:34 +0900 | [diff] [blame] | 90 | while ((sci_in(&scif_port, SCxSR) & 0x40) == 0) |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 91 | ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | if (c == '\n') |
| 94 | scif_sercon_putc('\r'); |
| 95 | } |
| 96 | |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 97 | static void scif_sercon_write(struct console *con, const char *s, |
| 98 | unsigned count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
| 100 | while (count-- > 0) |
| 101 | scif_sercon_putc(*s++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static int __init scif_sercon_setup(struct console *con, char *options) |
| 105 | { |
| 106 | con->cflag = CREAD | HUPCL | CLOCAL | B115200 | CS8; |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 111 | static struct console scif_console = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | .name = "sercon", |
| 113 | .write = scif_sercon_write, |
| 114 | .setup = scif_sercon_setup, |
| 115 | .flags = CON_PRINTBUFFER, |
| 116 | .index = -1, |
| 117 | }; |
| 118 | |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 119 | #if !defined(CONFIG_SH_STANDARD_BIOS) |
| 120 | #if defined(CONFIG_CPU_SUBTYPE_SH7720) |
| 121 | static void scif_sercon_init(char *s) |
| 122 | { |
| 123 | sci_out(&scif_port, SCSCR, 0x0000); /* clear TE and RE */ |
| 124 | sci_out(&scif_port, SCFCR, 0x4006); /* reset */ |
| 125 | sci_out(&scif_port, SCSCR, 0x0000); /* select internal clock */ |
| 126 | sci_out(&scif_port, SCSMR, EPK_SCSMR_VALUE); |
| 127 | sci_out(&scif_port, SCBRR, EPK_SCBRR_VALUE); |
| 128 | |
| 129 | mdelay(1); /* wait 1-bit time */ |
| 130 | |
| 131 | sci_out(&scif_port, SCFCR, 0x0030); /* TTRG=b'11 */ |
| 132 | sci_out(&scif_port, SCSCR, 0x0030); /* TE, RE */ |
| 133 | } |
| 134 | #elif defined(CONFIG_CPU_SH4) |
Jamie Lenehan | 703404ea | 2006-12-19 12:16:06 +0900 | [diff] [blame] | 135 | #define DEFAULT_BAUD 115200 |
Paul Mundt | 6fc21b8 | 2006-11-27 12:10:23 +0900 | [diff] [blame] | 136 | /* |
| 137 | * Simple SCIF init, primarily aimed at SH7750 and other similar SH-4 |
| 138 | * devices that aren't using sh-ipl+g. |
| 139 | */ |
Jamie Lenehan | 703404ea | 2006-12-19 12:16:06 +0900 | [diff] [blame] | 140 | static void scif_sercon_init(char *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | { |
Jamie Lenehan | 703404ea | 2006-12-19 12:16:06 +0900 | [diff] [blame] | 142 | unsigned baud = DEFAULT_BAUD; |
| 143 | char *e; |
| 144 | |
| 145 | if (*s == ',') |
| 146 | ++s; |
| 147 | |
| 148 | if (*s) { |
| 149 | /* ignore ioport/device name */ |
| 150 | s += strcspn(s, ","); |
| 151 | if (*s == ',') |
| 152 | s++; |
| 153 | } |
| 154 | |
| 155 | if (*s) { |
| 156 | baud = simple_strtoul(s, &e, 0); |
| 157 | if (baud == 0 || s == e) |
| 158 | baud = DEFAULT_BAUD; |
| 159 | } |
| 160 | |
Paul Mundt | 6fc21b8 | 2006-11-27 12:10:23 +0900 | [diff] [blame] | 161 | ctrl_outw(0, scif_port.mapbase + 8); |
| 162 | ctrl_outw(0, scif_port.mapbase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
| 164 | /* Set baud rate */ |
| 165 | ctrl_outb((CONFIG_SH_PCLK_FREQ + 16 * baud) / |
Paul Mundt | 6fc21b8 | 2006-11-27 12:10:23 +0900 | [diff] [blame] | 166 | (32 * baud) - 1, scif_port.mapbase + 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Paul Mundt | 6fc21b8 | 2006-11-27 12:10:23 +0900 | [diff] [blame] | 168 | ctrl_outw(12, scif_port.mapbase + 24); |
| 169 | ctrl_outw(8, scif_port.mapbase + 24); |
| 170 | ctrl_outw(0, scif_port.mapbase + 32); |
| 171 | ctrl_outw(0x60, scif_port.mapbase + 16); |
| 172 | ctrl_outw(0, scif_port.mapbase + 36); |
| 173 | ctrl_outw(0x30, scif_port.mapbase + 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 175 | #endif /* defined(CONFIG_CPU_SUBTYPE_SH7720) */ |
| 176 | #endif /* !defined(CONFIG_SH_STANDARD_BIOS) */ |
Paul Mundt | 6fc21b8 | 2006-11-27 12:10:23 +0900 | [diff] [blame] | 177 | #endif /* CONFIG_EARLY_SCIF_CONSOLE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 179 | /* |
| 180 | * Setup a default console, if more than one is compiled in, rely on the |
| 181 | * earlyprintk= parsing to give priority. |
| 182 | */ |
| 183 | static struct console *early_console = |
| 184 | #ifdef CONFIG_SH_STANDARD_BIOS |
| 185 | &bios_console |
| 186 | #elif defined(CONFIG_EARLY_SCIF_CONSOLE) |
| 187 | &scif_console |
| 188 | #else |
| 189 | NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | #endif |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 191 | ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
Paul Mundt | 008d50f | 2007-10-02 16:24:50 +0900 | [diff] [blame^] | 193 | static int __init setup_early_printk(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { |
Paul Mundt | 008d50f | 2007-10-02 16:24:50 +0900 | [diff] [blame^] | 195 | int keep_early = 0; |
| 196 | |
Paul Mundt | b641fe0 | 2006-12-12 09:00:47 +0900 | [diff] [blame] | 197 | if (!buf) |
| 198 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 200 | if (strstr(buf, "keep")) |
| 201 | keep_early = 1; |
| 202 | |
| 203 | #ifdef CONFIG_SH_STANDARD_BIOS |
| 204 | if (!strncmp(buf, "bios", 4)) |
| 205 | early_console = &bios_console; |
| 206 | #endif |
| 207 | #if defined(CONFIG_EARLY_SCIF_CONSOLE) |
| 208 | if (!strncmp(buf, "serial", 6)) { |
| 209 | early_console = &scif_console; |
| 210 | |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 211 | #if (defined(CONFIG_CPU_SH4) || defined(CONFIG_CPU_SUBTYPE_SH7720)) && \ |
| 212 | !defined(CONFIG_SH_STANDARD_BIOS) |
Jamie Lenehan | 703404ea | 2006-12-19 12:16:06 +0900 | [diff] [blame] | 213 | scif_sercon_init(buf + 6); |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 214 | #endif |
| 215 | } |
| 216 | #endif |
| 217 | |
Gerd Hoffmann | 69331af | 2007-05-08 00:26:49 -0700 | [diff] [blame] | 218 | if (likely(early_console)) { |
| 219 | if (keep_early) |
| 220 | early_console->flags &= ~CON_BOOT; |
| 221 | else |
| 222 | early_console->flags |= CON_BOOT; |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 223 | register_console(early_console); |
Gerd Hoffmann | 69331af | 2007-05-08 00:26:49 -0700 | [diff] [blame] | 224 | } |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 225 | |
Paul Mundt | b641fe0 | 2006-12-12 09:00:47 +0900 | [diff] [blame] | 226 | return 0; |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 227 | } |
Paul Mundt | b641fe0 | 2006-12-12 09:00:47 +0900 | [diff] [blame] | 228 | early_param("earlyprintk", setup_early_printk); |