ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / mips / mips-boards / generic / printf.c
1 /*
2  * Carsten Langgaard, carstenl@mips.com
3  * Copyright (C) 1999,2000 MIPS Technologies, Inc.  All rights reserved.
4  *
5  *  This program is free software; you can distribute it and/or modify it
6  *  under the terms of the GNU General Public License (Version 2) as
7  *  published by the Free Software Foundation.
8  *
9  *  This program is distributed in the hope it will be useful, but WITHOUT
10  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  *  for more details.
13  *
14  *  You should have received a copy of the GNU General Public License along
15  *  with this program; if not, write to the Free Software Foundation, Inc.,
16  *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
17  *
18  * Putting things on the screen/serial line using YAMONs facilities.
19  */
20 #include <linux/config.h>
21 #include <linux/init.h>
22 #include <linux/kernel.h>
23 #include <linux/serial_reg.h>
24 #include <linux/spinlock.h>
25 #include <asm/io.h>
26
27 #ifdef CONFIG_MIPS_ATLAS
28 #include <asm/mips-boards/atlas.h>
29
30 #ifdef CONFIG_CPU_LITTLE_ENDIAN
31 #define PORT(offset) (ATLAS_UART_REGS_BASE     + ((offset)<<3))
32 #else
33 #define PORT(offset) (ATLAS_UART_REGS_BASE + 3 + ((offset)<<3))
34 #endif
35
36 #elif defined(CONFIG_MIPS_SEAD)
37
38 #include <asm/mips-boards/sead.h>
39
40 #ifdef CONFIG_CPU_LITTLE_ENDIAN
41 #define PORT(offset) (SEAD_UART0_REGS_BASE     + ((offset)<<3))
42 #else
43 #define PORT(offset) (SEAD_UART0_REGS_BASE + 3 + ((offset)<<3))
44 #endif
45
46 #else
47
48 #define PORT(offset) (0x3f8 + (offset))
49
50 #endif
51
52 static inline unsigned int serial_in(int offset)
53 {
54         return inb(PORT(offset));
55 }
56
57 static inline void serial_out(int offset, int value)
58 {
59         outb(value, PORT(offset));
60 }
61
62 int putPromChar(char c)
63 {
64         while ((serial_in(UART_LSR) & UART_LSR_THRE) == 0)
65                 ;
66
67         serial_out(UART_TX, c);
68
69         return 1;
70 }
71
72 char getPromChar(void)
73 {
74         while (!(serial_in(UART_LSR) & UART_LSR_DR))
75                 ;
76
77         return serial_in(UART_RX);
78 }
79
80 static spinlock_t con_lock = SPIN_LOCK_UNLOCKED;
81
82 static char buf[1024];
83
84 void __init prom_printf(char *fmt, ...)
85 {
86         va_list args;
87         int l;
88         char *p, *buf_end;
89         long flags;
90
91         spin_lock_irqsave(con_lock, flags);
92
93         va_start(args, fmt);
94         l = vsprintf(buf, fmt, args); /* hopefully i < sizeof(buf) */
95         va_end(args);
96
97         buf_end = buf + l;
98
99         for (p = buf; p < buf_end; p++) {
100                 /* Crude cr/nl handling is better than none */
101                 if (*p == '\n')
102                         putPromChar('\r');
103                 putPromChar(*p);
104         }
105         /* wait for output to drain */
106         while ((serial_in(UART_LSR) & UART_LSR_TEMT) == 0)
107                 ;
108         spin_unlock_irqrestore(con_lock, flags);
109 }