blob: 685a64e93ede94bac6789f24b3a733c5e7aed1ee [file] [log] [blame]
Michal Simek89272a52009-03-27 14:25:22 +01001/*
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
24static u32 early_console_initialized;
25static u32 base_addr;
26
Michal Simek51f5fa52010-09-28 16:40:00 +100027#ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
Michal Simek2af9ebe2010-09-28 16:33:53 +100028static void early_printk_uartlite_putc(char c)
Michal Simek89272a52009-03-27 14:25:22 +010029{
30 /*
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.
36 */
37
38 unsigned retries = 10000;
39 /* read status bit - 0x8 offset */
Roel Kluin6e60c142009-04-16 22:49:17 +020040 while (--retries && (in_be32(base_addr + 8) & (1 << 3)))
Michal Simek89272a52009-03-27 14:25:22 +010041 ;
42
43 /* Only attempt the iowrite if we didn't timeout */
44 /* write to TX_FIFO - 0x4 offset */
45 if (retries)
46 out_be32(base_addr + 4, c & 0xff);
47}
48
Michal Simek2af9ebe2010-09-28 16:33:53 +100049static void early_printk_uartlite_write(struct console *unused,
Michal Simek89272a52009-03-27 14:25:22 +010050 const char *s, unsigned n)
51{
52 while (*s && n-- > 0) {
Michal Simek2af9ebe2010-09-28 16:33:53 +100053 early_printk_uartlite_putc(*s);
Michal Simek89272a52009-03-27 14:25:22 +010054 if (*s == '\n')
Michal Simek2af9ebe2010-09-28 16:33:53 +100055 early_printk_uartlite_putc('\r');
Michal Simek89272a52009-03-27 14:25:22 +010056 s++;
57 }
58}
59
Michal Simek2af9ebe2010-09-28 16:33:53 +100060static struct console early_serial_uartlite_console = {
Michal Simek89272a52009-03-27 14:25:22 +010061 .name = "earlyser",
Michal Simek2af9ebe2010-09-28 16:33:53 +100062 .write = early_printk_uartlite_write,
Michal Simek89272a52009-03-27 14:25:22 +010063 .flags = CON_PRINTBUFFER,
64 .index = -1,
65};
Michal Simek51f5fa52010-09-28 16:40:00 +100066#endif /* CONFIG_SERIAL_UARTLITE_CONSOLE */
Michal Simek89272a52009-03-27 14:25:22 +010067
Michal Simek9a7e8d82010-09-28 16:38:28 +100068static struct console *early_console;
Michal Simek89272a52009-03-27 14:25:22 +010069
70void early_printk(const char *fmt, ...)
71{
72 char buf[512];
73 int n;
74 va_list ap;
75
76 if (early_console_initialized) {
77 va_start(ap, fmt);
78 n = vscnprintf(buf, 512, fmt, ap);
79 early_console->write(early_console, buf, n);
80 va_end(ap);
81 }
82}
83
84int __init setup_early_printk(char *opt)
85{
86 if (early_console_initialized)
87 return 1;
88
Michal Simek51f5fa52010-09-28 16:40:00 +100089#ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
Michal Simek89272a52009-03-27 14:25:22 +010090 base_addr = early_uartlite_console();
91 if (base_addr) {
92 early_console_initialized = 1;
Michal Simeka43acfb2009-05-26 16:30:10 +020093#ifdef CONFIG_MMU
94 early_console_reg_tlb_alloc(base_addr);
95#endif
Michal Simek9a7e8d82010-09-28 16:38:28 +100096 early_console = &early_serial_uartlite_console;
Michal Simek89272a52009-03-27 14:25:22 +010097 early_printk("early_printk_console is enabled at 0x%08x\n",
98 base_addr);
99
100 /* register_console(early_console); */
101
102 return 0;
Michal Simek51f5fa52010-09-28 16:40:00 +1000103 }
104#endif /* CONFIG_SERIAL_UARTLITE_CONSOLE */
105
106 return 1;
Michal Simek89272a52009-03-27 14:25:22 +0100107}
108
109void __init disable_early_printk(void)
110{
111 if (!early_console_initialized || !early_console)
112 return;
113 printk(KERN_WARNING "disabling early console\n");
114 unregister_console(early_console);
115 early_console_initialized = 0;
116}