2 * Early printk support for Microblaze.
4 * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
5 * Copyright (C) 2007-2009 PetaLogix
6 * Copyright (C) 2003-2006 Yasushi SHOJI <yashi@atmark-techno.com>
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
13 #include <linux/console.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/string.h>
17 #include <linux/tty.h>
19 #include <asm/processor.h>
20 #include <linux/fcntl.h>
21 #include <asm/setup.h>
24 static u32 early_console_initialized
;
27 #ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
28 static void early_printk_uartlite_putc(char c
)
31 * Limit how many times we'll spin waiting for TX FIFO status.
32 * This will prevent lockups if the base address is incorrectly
33 * set, or any other issue on the UARTLITE.
34 * This limit is pretty arbitrary, unless we are at about 10 baud
35 * we'll never timeout on a working UART.
38 unsigned retries
= 1000000;
39 /* read status bit - 0x8 offset */
40 while (--retries
&& (in_be32(base_addr
+ 8) & (1 << 3)))
43 /* Only attempt the iowrite if we didn't timeout */
44 /* write to TX_FIFO - 0x4 offset */
46 out_be32(base_addr
+ 4, c
& 0xff);
49 static void early_printk_uartlite_write(struct console
*unused
,
50 const char *s
, unsigned n
)
52 while (*s
&& n
-- > 0) {
53 early_printk_uartlite_putc(*s
);
55 early_printk_uartlite_putc('\r');
60 static struct console early_serial_uartlite_console
= {
62 .write
= early_printk_uartlite_write
,
63 .flags
= CON_PRINTBUFFER
| CON_BOOT
,
66 #endif /* CONFIG_SERIAL_UARTLITE_CONSOLE */
68 #ifdef CONFIG_SERIAL_8250_CONSOLE
69 static void early_printk_uart16550_putc(char c
)
72 * Limit how many times we'll spin waiting for TX FIFO status.
73 * This will prevent lockups if the base address is incorrectly
74 * set, or any other issue on the UARTLITE.
75 * This limit is pretty arbitrary, unless we are at about 10 baud
76 * we'll never timeout on a working UART.
79 #define UART_LSR_TEMT 0x40 /* Transmitter empty */
80 #define UART_LSR_THRE 0x20 /* Transmit-hold-register empty */
81 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
83 unsigned retries
= 10000;
86 !((in_be32(base_addr
+ 0x14) & BOTH_EMPTY
) == BOTH_EMPTY
))
90 out_be32(base_addr
, c
& 0xff);
93 static void early_printk_uart16550_write(struct console
*unused
,
94 const char *s
, unsigned n
)
96 while (*s
&& n
-- > 0) {
97 early_printk_uart16550_putc(*s
);
99 early_printk_uart16550_putc('\r');
104 static struct console early_serial_uart16550_console
= {
106 .write
= early_printk_uart16550_write
,
107 .flags
= CON_PRINTBUFFER
| CON_BOOT
,
110 #endif /* CONFIG_SERIAL_8250_CONSOLE */
112 static struct console
*early_console
;
114 void early_printk(const char *fmt
, ...)
120 if (early_console_initialized
) {
122 n
= vscnprintf(buf
, 512, fmt
, ap
);
123 early_console
->write(early_console
, buf
, n
);
128 int __init
setup_early_printk(char *opt
)
132 if (early_console_initialized
)
135 base_addr
= of_early_console(&version
);
138 early_console_reg_tlb_alloc(base_addr
);
141 #ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
143 printk(KERN_INFO
"Early console on uartlite "
144 "at 0x%08x\n", base_addr
);
145 early_console
= &early_serial_uartlite_console
;
148 #ifdef CONFIG_SERIAL_8250_CONSOLE
150 printk(KERN_INFO
"Early console on uart16650 "
151 "at 0x%08x\n", base_addr
);
152 early_console
= &early_serial_uart16550_console
;
156 printk(KERN_INFO
"Unsupported early console %d\n",
161 register_console(early_console
);
162 early_console_initialized
= 1;
168 /* Remap early console to virtual address and do not allocate one TLB
169 * only for early console because of performance degression */
170 void __init
remap_early_printk(void)
172 if (!early_console_initialized
|| !early_console
)
174 printk(KERN_INFO
"early_printk_console remaping from 0x%x to ",
176 base_addr
= (u32
) ioremap(base_addr
, PAGE_SIZE
);
177 printk(KERN_CONT
"0x%x\n", base_addr
);
180 void __init
disable_early_printk(void)
182 if (!early_console_initialized
|| !early_console
)
184 printk(KERN_WARNING
"disabling early console\n");
185 unregister_console(early_console
);
186 early_console_initialized
= 0;