1 /*
2 * PROM console for Cobalt Raq2
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 1995, 1996, 1997 by Ralf Baechle
9 * Copyright (C) 2001 by Liam Davies (ldavies@agile.tv)
10 *
11 */
12
13 #include <linux/init.h>
14 #include <linux/console.h>
15 #include <linux/kdev_t.h>
16 #include <linux/major.h>
17 #include <linux/serial_reg.h>
18
19 #include <asm/delay.h>
20 #include <asm/serial.h>
21 #include <asm/io.h>
22
23 static unsigned long port = 0xc800000;
24
ns16550_cons_put_char(char ch,unsigned long ioaddr)25 static __inline__ void ns16550_cons_put_char(char ch, unsigned long ioaddr)
26 {
27 char lsr;
28
29 do {
30 lsr = inb(ioaddr + UART_LSR);
31 } while ((lsr & (UART_LSR_TEMT | UART_LSR_THRE)) != (UART_LSR_TEMT | UART_LSR_THRE));
32 outb(ch, ioaddr + UART_TX);
33 }
34
ns16550_cons_get_char(unsigned long ioaddr)35 static __inline__ char ns16550_cons_get_char(unsigned long ioaddr)
36 {
37 while ((inb(ioaddr + UART_LSR) & UART_LSR_DR) == 0)
38 udelay(1);
39 return inb(ioaddr + UART_RX);
40 }
41
ns16550_console_write(struct console * co,const char * s,unsigned count)42 void ns16550_console_write(struct console *co, const char *s, unsigned count)
43 {
44 char lsr, ier;
45 unsigned i;
46
47 ier = inb(port + UART_IER);
48 outb(0x00, port + UART_IER);
49 for (i=0; i < count; i++, s++) {
50
51 if(*s == '\n')
52 ns16550_cons_put_char('\r', port);
53 ns16550_cons_put_char(*s, port);
54 }
55
56 do {
57 lsr = inb(port + UART_LSR);
58 } while ((lsr & (UART_LSR_TEMT | UART_LSR_THRE)) != (UART_LSR_TEMT | UART_LSR_THRE));
59
60 outb(ier, port + UART_IER);
61 }
62
getDebugChar(void)63 char getDebugChar(void)
64 {
65 return ns16550_cons_get_char(port);
66 }
67
putDebugChar(char kgdb_char)68 void putDebugChar(char kgdb_char)
69 {
70 ns16550_cons_put_char(kgdb_char, port);
71 }
72
73 static kdev_t
ns16550_console_dev(struct console * c)74 ns16550_console_dev(struct console *c)
75 {
76 return MKDEV(TTY_MAJOR, 64 + c->index);
77 }
78
79 static struct console ns16550_console = {
80 .name = "prom",
81 .setup = NULL,
82 .write = ns16550_console_write,
83 .device = ns16550_console_dev,
84 .flags = CON_PRINTBUFFER,
85 .index = -1,
86 };
87
ns16550_setup_console(void)88 void __init ns16550_setup_console(void)
89 {
90 register_console(&ns16550_console);
91 }
92