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>
26 #ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
27 static void early_printk_uartlite_putc(char c
)
30 * Limit how many times we'll spin waiting for TX FIFO status.
31 * This will prevent lockups if the base address is incorrectly
32 * set, or any other issue on the UARTLITE.
33 * This limit is pretty arbitrary, unless we are at about 10 baud
34 * we'll never timeout on a working UART.
37 unsigned retries
= 1000000;
38 /* read status bit - 0x8 offset */
39 while (--retries
&& (in_be32(base_addr
+ 8) & (1 << 3)))
42 /* Only attempt the iowrite if we didn't timeout */
43 /* write to TX_FIFO - 0x4 offset */
45 out_be32(base_addr
+ 4, c
& 0xff);
48 static void early_printk_uartlite_write(struct console
*unused
,
49 const char *s
, unsigned n
)
51 while (*s
&& n
-- > 0) {
53 early_printk_uartlite_putc('\r');
54 early_printk_uartlite_putc(*s
);
59 static struct console early_serial_uartlite_console
= {
61 .write
= early_printk_uartlite_write
,
62 .flags
= CON_PRINTBUFFER
| CON_BOOT
,
65 #endif /* CONFIG_SERIAL_UARTLITE_CONSOLE */
67 #ifdef CONFIG_SERIAL_8250_CONSOLE
68 static void early_printk_uart16550_putc(char c
)
71 * Limit how many times we'll spin waiting for TX FIFO status.
72 * This will prevent lockups if the base address is incorrectly
73 * set, or any other issue on the UARTLITE.
74 * This limit is pretty arbitrary, unless we are at about 10 baud
75 * we'll never timeout on a working UART.
78 #define UART_LSR_TEMT 0x40 /* Transmitter empty */
79 #define UART_LSR_THRE 0x20 /* Transmit-hold-register empty */
80 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
82 unsigned retries
= 10000;
85 !((in_be32(base_addr
+ 0x14) & BOTH_EMPTY
) == BOTH_EMPTY
))
89 out_be32(base_addr
, c
& 0xff);
92 static void early_printk_uart16550_write(struct console
*unused
,
93 const char *s
, unsigned n
)
95 while (*s
&& n
-- > 0) {
97 early_printk_uart16550_putc('\r');
98 early_printk_uart16550_putc(*s
);
103 static struct console early_serial_uart16550_console
= {
105 .write
= early_printk_uart16550_write
,
106 .flags
= CON_PRINTBUFFER
| CON_BOOT
,
109 #endif /* CONFIG_SERIAL_8250_CONSOLE */
111 int __init
setup_early_printk(char *opt
)
118 base_addr
= of_early_console(&version
);
121 early_console_reg_tlb_alloc(base_addr
);
124 #ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
126 pr_info("Early console on uartlite at 0x%08x\n",
128 early_console
= &early_serial_uartlite_console
;
131 #ifdef CONFIG_SERIAL_8250_CONSOLE
133 pr_info("Early console on uart16650 at 0x%08x\n",
135 early_console
= &early_serial_uart16550_console
;
139 pr_info("Unsupported early console %d\n",
144 register_console(early_console
);
150 /* Remap early console to virtual address and do not allocate one TLB
151 * only for early console because of performance degression */
152 void __init
remap_early_printk(void)
156 pr_info("early_printk_console remapping from 0x%x to ", base_addr
);
157 base_addr
= (u32
) ioremap(base_addr
, PAGE_SIZE
);
158 pr_cont("0x%x\n", base_addr
);
162 * Early console is on the top of skipped TLB entries
163 * decrease tlb_skip size ensure that hardcoded TLB entry will be
164 * used by generic algorithm
165 * FIXME check if early console mapping is on the top by rereading
166 * TLB entry and compare baseaddr
167 * mts rtlbx, (tlb_skip - 1)
171 * cmp rX, orig_base_addr
177 void __init
disable_early_printk(void)
181 pr_warn("disabling early console\n");
182 unregister_console(early_console
);
183 early_console
= NULL
;