2 * Early printk for Nios2.
4 * Copyright (C) 2015, Altera Corporation
5 * Copyright (C) 2010, Tobias Klauser <tklauser@distanz.ch>
6 * Copyright (C) 2009, Wind River Systems Inc
7 * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
14 #include <linux/console.h>
15 #include <linux/init.h>
16 #include <linux/kernel.h>
21 static unsigned long base_addr
;
23 #if defined(CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE)
25 #define ALTERA_JTAGUART_DATA_REG 0
26 #define ALTERA_JTAGUART_CONTROL_REG 4
27 #define ALTERA_JTAGUART_CONTROL_WSPACE_MSK 0xFFFF0000
28 #define ALTERA_JTAGUART_CONTROL_AC_MSK 0x00000400
30 #define JUART_GET_CR() \
31 __builtin_ldwio((void *)(base_addr + ALTERA_JTAGUART_CONTROL_REG))
32 #define JUART_SET_CR(v) \
33 __builtin_stwio((void *)(base_addr + ALTERA_JTAGUART_CONTROL_REG), v)
34 #define JUART_SET_TX(v) \
35 __builtin_stwio((void *)(base_addr + ALTERA_JTAGUART_DATA_REG), v)
37 static void early_console_write(struct console
*con
, const char *s
, unsigned n
)
42 while (((status
= JUART_GET_CR())
43 & ALTERA_JTAGUART_CONTROL_WSPACE_MSK
) == 0) {
44 #if defined(CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE_BYPASS)
45 if ((status
& ALTERA_JTAGUART_CONTROL_AC_MSK
) == 0)
46 return; /* no connection activity */
54 #elif defined(CONFIG_SERIAL_ALTERA_UART_CONSOLE)
56 #define ALTERA_UART_TXDATA_REG 4
57 #define ALTERA_UART_STATUS_REG 8
58 #define ALTERA_UART_STATUS_TRDY 0x0040
60 #define UART_GET_SR() \
61 __builtin_ldwio((void *)(base_addr + ALTERA_UART_STATUS_REG))
62 #define UART_SET_TX(v) \
63 __builtin_stwio((void *)(base_addr + ALTERA_UART_TXDATA_REG), v)
65 static void early_console_putc(char c
)
67 while (!(UART_GET_SR() & ALTERA_UART_STATUS_TRDY
))
73 static void early_console_write(struct console
*con
, const char *s
, unsigned n
)
76 early_console_putc(*s
);
78 early_console_putc('\r');
84 # error Neither SERIAL_ALTERA_JTAGUART_CONSOLE nor SERIAL_ALTERA_UART_CONSOLE \
88 static struct console early_console_prom
= {
90 .write
= early_console_write
,
91 .flags
= CON_PRINTBUFFER
| CON_BOOT
,
95 void __init
setup_early_printk(void)
97 #if defined(CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE) || \
98 defined(CONFIG_SERIAL_ALTERA_UART_CONSOLE)
99 base_addr
= of_early_console();
107 #if defined(CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE_BYPASS)
108 /* Clear activity bit so BYPASS doesn't stall if we've used JTAG for
109 * downloading the kernel. This might cause early data to be lost even
110 * if the JTAG terminal is running.
112 JUART_SET_CR(JUART_GET_CR() | ALTERA_JTAGUART_CONTROL_AC_MSK
);
115 early_console
= &early_console_prom
;
116 register_console(early_console
);
117 pr_info("early_console initialized at 0x%08lx\n", base_addr
);