This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / mips / pmc-sierra / yosemite / py-console.c
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 2001, 2002, 2004 Ralf Baechle
7  */
8 #include <linux/init.h>
9 #include <linux/console.h>
10 #include <linux/kdev_t.h>
11 #include <linux/major.h>
12 #include <linux/termios.h>
13 #include <linux/sched.h>
14 #include <linux/tty.h>
15
16 #include <linux/serial.h>
17 #include <linux/serial_core.h>
18 #include <asm/serial.h>
19 #include <asm/io.h>
20
21 /* SUPERIO uart register map */
22 struct yo_uartregs {
23         union {
24                 volatile u8     rbr;    /* read only, DLAB == 0 */
25                 volatile u8     thr;    /* write only, DLAB == 0 */
26                 volatile u8     dll;    /* DLAB == 1 */
27         } u1;
28         union {
29                 volatile u8     ier;    /* DLAB == 0 */
30                 volatile u8     dlm;    /* DLAB == 1 */
31         } u2;
32         union {
33                 volatile u8     iir;    /* read only */
34                 volatile u8     fcr;    /* write only */
35         } u3;
36         volatile u8     iu_lcr;
37         volatile u8     iu_mcr;
38         volatile u8     iu_lsr;
39         volatile u8     iu_msr;
40         volatile u8     iu_scr;
41 } yo_uregs_t;
42
43 #define iu_rbr u1.rbr
44 #define iu_thr u1.thr
45 #define iu_dll u1.dll
46 #define iu_ier u2.ier
47 #define iu_dlm u2.dlm
48 #define iu_iir u3.iir
49 #define iu_fcr u3.fcr
50
51 extern unsigned long uart_base;
52
53 #define IO_BASE_64      0x9000000000000000ULL
54
55 static unsigned char readb_outer_space(unsigned long phys)
56 {
57         unsigned long long vaddr = IO_BASE_64 | phys;
58         unsigned char res;
59         unsigned int sr;
60
61         sr = read_c0_status();
62         write_c0_status((sr | ST0_KX) & ~ ST0_IE);
63         __asm__("sll    $0, $0, 2\n");
64         __asm__("sll    $0, $0, 2\n");
65         __asm__("sll    $0, $0, 2\n");
66         __asm__("sll    $0, $0, 2\n");
67
68         __asm__ __volatile__ (
69         "       .set    mips3           \n"
70         "       ld      %0, (%0)        \n"
71         "       lbu     %0, (%0)        \n"
72         "       .set    mips0           \n"
73         : "=r" (res)
74         : "0" (&vaddr));
75
76         write_c0_status(sr);
77         __asm__("sll    $0, $0, 2\n");
78         __asm__("sll    $0, $0, 2\n");
79         __asm__("sll    $0, $0, 2\n");
80         __asm__("sll    $0, $0, 2\n");
81
82         return res;
83 }
84
85 static void writeb_outer_space(unsigned long phys, unsigned char c)
86 {
87         unsigned long long vaddr = IO_BASE_64 | phys;
88         unsigned long tmp;
89         unsigned int sr;
90
91         sr = read_c0_status();
92         write_c0_status((sr | ST0_KX) & ~ ST0_IE);
93         __asm__("sll    $0, $0, 2\n");
94         __asm__("sll    $0, $0, 2\n");
95         __asm__("sll    $0, $0, 2\n");
96         __asm__("sll    $0, $0, 2\n");
97
98         __asm__ __volatile__ (
99         "       .set    mips3           \n"
100         "       ld      %0, (%1)        \n"
101         "       sb      %2, (%0)        \n"
102         "       .set    mips0           \n"
103         : "=r" (tmp)
104         : "r" (&vaddr), "r" (c));
105
106         write_c0_status(sr);
107         __asm__("sll    $0, $0, 2\n");
108         __asm__("sll    $0, $0, 2\n");
109         __asm__("sll    $0, $0, 2\n");
110         __asm__("sll    $0, $0, 2\n");
111 }
112
113 static inline struct yo_uartregs *console_uart(void)
114 {
115         return (struct yo_uartregs *) (uart_base + 8);
116 }
117
118 void prom_putchar(char c)
119 {
120         unsigned long lsr = 0xfd000008UL + offsetof(struct yo_uartregs, iu_lsr);
121         unsigned long thr = 0xfd000008UL + offsetof(struct yo_uartregs, iu_thr);
122
123         while ((readb_outer_space(lsr) & 0x20) == 0);
124         writeb_outer_space(thr, c);
125 }
126
127 char __init prom_getchar(void)
128 {
129         return 0;
130 }