Merge tag 'fbdev-4.6' of git://git.kernel.org/pub/scm/linux/kernel/git/tomba/linux
[deliverable/linux.git] / arch / microblaze / kernel / early_printk.c
CommitLineData
89272a51
MS
1/*
2 * Early printk support for Microblaze.
3 *
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>
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
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>
18#include <linux/io.h>
19#include <asm/processor.h>
20#include <linux/fcntl.h>
21#include <asm/setup.h>
22#include <asm/prom.h>
23
89272a51
MS
24static u32 base_addr;
25
51f5fa50 26#ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
2af9ebe9 27static void early_printk_uartlite_putc(char c)
89272a51
MS
28{
29 /*
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.
35 */
36
ca12adc8 37 unsigned retries = 1000000;
89272a51 38 /* read status bit - 0x8 offset */
6e60c148 39 while (--retries && (in_be32(base_addr + 8) & (1 << 3)))
89272a51
MS
40 ;
41
42 /* Only attempt the iowrite if we didn't timeout */
43 /* write to TX_FIFO - 0x4 offset */
44 if (retries)
45 out_be32(base_addr + 4, c & 0xff);
46}
47
2af9ebe9 48static void early_printk_uartlite_write(struct console *unused,
89272a51
MS
49 const char *s, unsigned n)
50{
51 while (*s && n-- > 0) {
89272a51 52 if (*s == '\n')
2af9ebe9 53 early_printk_uartlite_putc('\r');
a8c2e555 54 early_printk_uartlite_putc(*s);
89272a51
MS
55 s++;
56 }
57}
58
2af9ebe9 59static struct console early_serial_uartlite_console = {
89272a51 60 .name = "earlyser",
2af9ebe9 61 .write = early_printk_uartlite_write,
e721a45f 62 .flags = CON_PRINTBUFFER | CON_BOOT,
89272a51
MS
63 .index = -1,
64};
51f5fa50 65#endif /* CONFIG_SERIAL_UARTLITE_CONSOLE */
89272a51 66
67f4aaa2
MS
67#ifdef CONFIG_SERIAL_8250_CONSOLE
68static void early_printk_uart16550_putc(char c)
69{
70 /*
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.
76 */
77
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)
81
82 unsigned retries = 10000;
83
84 while (--retries &&
85 !((in_be32(base_addr + 0x14) & BOTH_EMPTY) == BOTH_EMPTY))
86 ;
87
88 if (retries)
89 out_be32(base_addr, c & 0xff);
90}
91
92static void early_printk_uart16550_write(struct console *unused,
93 const char *s, unsigned n)
94{
95 while (*s && n-- > 0) {
67f4aaa2
MS
96 if (*s == '\n')
97 early_printk_uart16550_putc('\r');
a8c2e555 98 early_printk_uart16550_putc(*s);
67f4aaa2
MS
99 s++;
100 }
101}
102
103static struct console early_serial_uart16550_console = {
104 .name = "earlyser",
105 .write = early_printk_uart16550_write,
e721a45f 106 .flags = CON_PRINTBUFFER | CON_BOOT,
67f4aaa2
MS
107 .index = -1,
108};
109#endif /* CONFIG_SERIAL_8250_CONSOLE */
110
89272a51
MS
111int __init setup_early_printk(char *opt)
112{
2aa8e375
MS
113 int version = 0;
114
d0380e6c 115 if (early_console)
89272a51
MS
116 return 1;
117
2aa8e375 118 base_addr = of_early_console(&version);
89272a51 119 if (base_addr) {
a43acfbb
MS
120#ifdef CONFIG_MMU
121 early_console_reg_tlb_alloc(base_addr);
122#endif
2aa8e375
MS
123 switch (version) {
124#ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
125 case UARTLITE:
6bd55f0b
MS
126 pr_info("Early console on uartlite at 0x%08x\n",
127 base_addr);
2aa8e375
MS
128 early_console = &early_serial_uartlite_console;
129 break;
130#endif
67f4aaa2 131#ifdef CONFIG_SERIAL_8250_CONSOLE
2aa8e375 132 case UART16550:
6bd55f0b
MS
133 pr_info("Early console on uart16650 at 0x%08x\n",
134 base_addr);
2aa8e375
MS
135 early_console = &early_serial_uart16550_console;
136 break;
67f4aaa2 137#endif
2aa8e375 138 default:
6bd55f0b 139 pr_info("Unsupported early console %d\n",
2aa8e375
MS
140 version);
141 return 1;
142 }
67f4aaa2 143
e721a45f 144 register_console(early_console);
67f4aaa2
MS
145 return 0;
146 }
51f5fa50 147 return 1;
89272a51
MS
148}
149
e721a45f
MS
150/* Remap early console to virtual address and do not allocate one TLB
151 * only for early console because of performance degression */
152void __init remap_early_printk(void)
153{
d0380e6c 154 if (!early_console)
e721a45f 155 return;
6bd55f0b 156 pr_info("early_printk_console remapping from 0x%x to ", base_addr);
e721a45f 157 base_addr = (u32) ioremap(base_addr, PAGE_SIZE);
6bd55f0b 158 pr_cont("0x%x\n", base_addr);
e02db0aa 159
0fc7374b 160#ifdef CONFIG_MMU
e02db0aa
MS
161 /*
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)
168 * nop
169 * mfs rX, rtlblo
170 * nop
171 * cmp rX, orig_base_addr
172 */
173 tlb_skip -= 1;
0fc7374b 174#endif
e721a45f
MS
175}
176
89272a51
MS
177void __init disable_early_printk(void)
178{
d0380e6c 179 if (!early_console)
89272a51 180 return;
6bd55f0b 181 pr_warn("disabling early console\n");
89272a51 182 unregister_console(early_console);
d0380e6c 183 early_console = NULL;
89272a51 184}
This page took 0.36558 seconds and 5 git commands to generate.