This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / sh64 / kernel / early_printk.c
1 /*
2  * arch/sh64/kernel/early_printk.c
3  *
4  * SH-5 Early SCIF console (cloned and hacked from sh implementation)
5  *
6  * Copyright (C) 2003, 2004  Paul Mundt <lethal@linux-sh.org>
7  * Copyright (C) 2002  M. R. Brown <mrbrown@0xd6.org>
8  *
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
11  * for more details.
12  */
13 #include <linux/console.h>
14 #include <linux/tty.h>
15 #include <linux/init.h>
16 #include <asm/io.h>
17 #include <asm/hardware.h>
18
19 extern void cpu_relax(void);
20
21 #define SCIF_BASE_ADDR  0x01030000
22 #define SCIF_ADDR_SH5   PHYS_PERIPHERAL_BLOCK+SCIF_BASE_ADDR
23
24 /*
25  * Fixed virtual address where SCIF is mapped (should already be done
26  * in arch/sh64/kernel/head.S!).
27  */
28 #define SCIF_REG        0xfa030000
29
30 enum {
31         SCIF_SCSMR2     = SCIF_REG + 0x00,
32         SCIF_SCBRR2     = SCIF_REG + 0x04,
33         SCIF_SCSCR2     = SCIF_REG + 0x08,
34         SCIF_SCFTDR2    = SCIF_REG + 0x0c,
35         SCIF_SCFSR2     = SCIF_REG + 0x10,
36         SCIF_SCFRDR2    = SCIF_REG + 0x14,
37         SCIF_SCFCR2     = SCIF_REG + 0x18,
38         SCIF_SCFDR2     = SCIF_REG + 0x1c,
39         SCIF_SCSPTR2    = SCIF_REG + 0x20,
40         SCIF_SCLSR2     = SCIF_REG + 0x24,
41 };
42
43 static void sh_console_putc(int c)
44 {
45         while (!(ctrl_inw(SCIF_SCFSR2) & 0x20))
46                 cpu_relax();
47
48         ctrl_outb(c, SCIF_SCFTDR2);
49         ctrl_outw((ctrl_inw(SCIF_SCFSR2) & 0x9f), SCIF_SCFSR2);
50
51         if (c == '\n')
52                 sh_console_putc('\r');
53 }
54
55 static void sh_console_flush(void)
56 {
57         ctrl_outw((ctrl_inw(SCIF_SCFSR2) & 0xbf), SCIF_SCFSR2);
58
59         while (!(ctrl_inw(SCIF_SCFSR2) & 0x40))
60                 cpu_relax();
61
62         ctrl_outw((ctrl_inw(SCIF_SCFSR2) & 0xbf), SCIF_SCFSR2);
63 }
64
65 static void sh_console_write(struct console *con, const char *s, unsigned count)
66 {
67         while (count-- > 0)
68                 sh_console_putc(*s++);
69
70         sh_console_flush();
71 }
72
73 static int __init sh_console_setup(struct console *con, char *options)
74 {
75         con->cflag = CREAD | HUPCL | CLOCAL | B19200 | CS8;
76
77         return 0;
78 }
79
80 static struct console sh_console = {
81         .name           = "scifcon",
82         .write          = sh_console_write,
83         .setup          = sh_console_setup,
84         .flags          = CON_PRINTBUFFER,
85         .index          = -1,
86 };
87
88 void __init enable_early_printk(void)
89 {
90         ctrl_outb(0x2a, SCIF_SCBRR2);   /* 19200bps */
91
92         ctrl_outw(0x04, SCIF_SCFCR2);   /* Reset TFRST */
93         ctrl_outw(0x10, SCIF_SCFCR2);   /* TTRG0=1 */
94
95         ctrl_outw(0, SCIF_SCSPTR2);
96         ctrl_outw(0x60, SCIF_SCFSR2);
97         ctrl_outw(0, SCIF_SCLSR2);
98         ctrl_outw(0x30, SCIF_SCSCR2);
99
100         register_console(&sh_console);
101 }
102
103 void disable_early_printk(void)
104 {
105         unregister_console(&sh_console);
106 }
107