Path: blob/master/arch/microblaze/kernel/early_printk.c
10817 views
/*1* Early printk support for Microblaze.2*3* Copyright (C) 2007-2009 Michal Simek <[email protected]>4* Copyright (C) 2007-2009 PetaLogix5* Copyright (C) 2003-2006 Yasushi SHOJI <[email protected]>6*7* This file is subject to the terms and conditions of the GNU General Public8* License. See the file "COPYING" in the main directory of this archive9* for more details.10*/1112#include <linux/console.h>13#include <linux/kernel.h>14#include <linux/init.h>15#include <linux/string.h>16#include <linux/tty.h>17#include <linux/io.h>18#include <asm/processor.h>19#include <linux/fcntl.h>20#include <asm/setup.h>21#include <asm/prom.h>2223static u32 early_console_initialized;24static u32 base_addr;2526#ifdef CONFIG_SERIAL_UARTLITE_CONSOLE27static void early_printk_uartlite_putc(char c)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 incorrectly32* set, or any other issue on the UARTLITE.33* This limit is pretty arbitrary, unless we are at about 10 baud34* we'll never timeout on a working UART.35*/3637unsigned retries = 10000;38/* read status bit - 0x8 offset */39while (--retries && (in_be32(base_addr + 8) & (1 << 3)))40;4142/* Only attempt the iowrite if we didn't timeout */43/* write to TX_FIFO - 0x4 offset */44if (retries)45out_be32(base_addr + 4, c & 0xff);46}4748static void early_printk_uartlite_write(struct console *unused,49const char *s, unsigned n)50{51while (*s && n-- > 0) {52early_printk_uartlite_putc(*s);53if (*s == '\n')54early_printk_uartlite_putc('\r');55s++;56}57}5859static struct console early_serial_uartlite_console = {60.name = "earlyser",61.write = early_printk_uartlite_write,62.flags = CON_PRINTBUFFER,63.index = -1,64};65#endif /* CONFIG_SERIAL_UARTLITE_CONSOLE */6667#ifdef CONFIG_SERIAL_8250_CONSOLE68static 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 incorrectly73* set, or any other issue on the UARTLITE.74* This limit is pretty arbitrary, unless we are at about 10 baud75* we'll never timeout on a working UART.76*/7778#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)8182unsigned retries = 10000;8384while (--retries &&85!((in_be32(base_addr + 0x14) & BOTH_EMPTY) == BOTH_EMPTY))86;8788if (retries)89out_be32(base_addr, c & 0xff);90}9192static void early_printk_uart16550_write(struct console *unused,93const char *s, unsigned n)94{95while (*s && n-- > 0) {96early_printk_uart16550_putc(*s);97if (*s == '\n')98early_printk_uart16550_putc('\r');99s++;100}101}102103static struct console early_serial_uart16550_console = {104.name = "earlyser",105.write = early_printk_uart16550_write,106.flags = CON_PRINTBUFFER,107.index = -1,108};109#endif /* CONFIG_SERIAL_8250_CONSOLE */110111static struct console *early_console;112113void early_printk(const char *fmt, ...)114{115char buf[512];116int n;117va_list ap;118119if (early_console_initialized) {120va_start(ap, fmt);121n = vscnprintf(buf, 512, fmt, ap);122early_console->write(early_console, buf, n);123va_end(ap);124}125}126127int __init setup_early_printk(char *opt)128{129if (early_console_initialized)130return 1;131132#ifdef CONFIG_SERIAL_UARTLITE_CONSOLE133base_addr = early_uartlite_console();134if (base_addr) {135early_console_initialized = 1;136#ifdef CONFIG_MMU137early_console_reg_tlb_alloc(base_addr);138#endif139early_console = &early_serial_uartlite_console;140early_printk("early_printk_console is enabled at 0x%08x\n",141base_addr);142143/* register_console(early_console); */144145return 0;146}147#endif /* CONFIG_SERIAL_UARTLITE_CONSOLE */148149#ifdef CONFIG_SERIAL_8250_CONSOLE150base_addr = early_uart16550_console();151base_addr &= ~3; /* clear register offset */152if (base_addr) {153early_console_initialized = 1;154#ifdef CONFIG_MMU155early_console_reg_tlb_alloc(base_addr);156#endif157early_console = &early_serial_uart16550_console;158159early_printk("early_printk_console is enabled at 0x%08x\n",160base_addr);161162/* register_console(early_console); */163164return 0;165}166#endif /* CONFIG_SERIAL_8250_CONSOLE */167168return 1;169}170171void __init disable_early_printk(void)172{173if (!early_console_initialized || !early_console)174return;175printk(KERN_WARNING "disabling early console\n");176unregister_console(early_console);177early_console_initialized = 0;178}179180181