OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [i960/] [kernel/] [mon960_console.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1623 jcastillo
/*
2
 *   FILE: mon960_console.c
3
 * AUTHOR: kma
4
 *  DESCR: serial console for TI's 16552 serial controller
5
 */
6
 
7
#ident "$Id: mon960_console.c,v 1.1 2005-12-20 09:42:38 jcastillo Exp $"
8
 
9
#include <linux/tty.h>
10
#include <linux/tty_driver.h>
11
#include <linux/major.h>
12
#include <linux/interrupt.h>
13
#include <asm/system.h>
14
#include <asm/delay.h>
15
 
16
#define SER16552_LSR    ((volatile unsigned char*)0xe0000014)   /* line status */
17
#define SER16552_THR    ((volatile unsigned char*)0xe0000000)   /* send fifo */
18
#define SER16552_RBR    ((volatile unsigned char*)0xe0000000)   /* rcv fifo */
19
#define SER16552_IER    ((volatile unsigned char*)0xe0000004)   /* int enable */
20
 
21
#define LSR_READY               1
22
#define LSR_SEND_READY          0x20
23
#define LSR_RECEIVE_READY       0x1
24
#define LSR_BREAK               (1 << 4)
25
 
26
#define IER_RCV_ENABLE  1
27
#define IER_SEND_ENABLE 2
28
 
29
static int console_refcount;
30
static struct tty_struct *console_table[1];
31
static struct termios   *console_termios[1];
32
static struct termios   *console_termios_locked[1];
33
static struct tty_driver console_driver;
34
 
35
/*
36
 * The interrupt for the 16552; should only happen for reads
37
 */
38
void do_16552_intr(void)
39
{
40
        unsigned char           buf[16];
41
        int                     ii;
42
        struct tty_struct       *tty = console_table[0];
43
        unsigned long           lsr;
44
 
45
        /* Drain the fifo into the tty */
46
        for (ii=0; (lsr = *SER16552_LSR) & LSR_RECEIVE_READY; ii++) {
47
                /* If there was a break, enter the debugger */
48
#ifdef CONFIG_MON960
49
                char    garbage;
50
                if (lsr & LSR_BREAK) {
51
                        extern void system_break(void);
52
                        system_break();
53
                        garbage = *SER16552_RBR;
54
                        ii--;
55
                }
56
                else
57
#endif
58
                        buf[ii] = *SER16552_RBR;
59
        }
60
 
61
 
62
        if (ii)
63
                tty->ldisc.receive_buf(tty, buf, 0, ii);
64
}
65
 
66
#if 0
67
static void do_16552_bh(void)
68
{
69
        printk("in 16552 bottom half!\n");
70
        printk("umm... yeah.\n");
71
}
72
#endif
73
 
74
static inline void putc_16552(char c, int blocking)
75
{
76
        unsigned long   flags;
77
 
78
        save_flags(flags);
79
        cli();
80
top:
81
        while (!(*SER16552_LSR & LSR_SEND_READY)) {
82
                udelay(1000);
83
        }
84
 
85
        *SER16552_THR = c;
86
 
87
        if (c == '\n') {
88
                c = '\r';
89
                goto top;
90
        }
91
        restore_flags(flags);
92
}
93
 
94
void console_print_mon960(const char* msg)
95
{
96
        long flags;
97
        char c;
98
 
99
        save_flags(flags);
100
        cli();
101
        while (c = *msg++)
102
                putc_16552(c, 0);
103
 
104
        restore_flags(flags);
105
}
106
 
107
/*
108
 * XXX: make this interrupt driven if it's coming from the user
109
 */
110
static int con_write(struct tty_struct* tty, int from_user,
111
                     const unsigned char* buf, int count)
112
{
113
        int ii = count;
114
 
115
        while (ii--)
116
                putc_16552(*buf++, from_user);
117
        return count;
118
}
119
 
120
static int con_chars_in_buffer(struct tty_struct *tty)
121
{
122
        return 0;                /* we're not buffering */
123
}
124
 
125
static int con_writeroom(struct tty_struct *tty)
126
{
127
        return  8192;           /* could return anything */
128
}
129
 
130
static void con_putchar(struct tty_struct* tty, unsigned char c)
131
{
132
        putc_16552(c, 0);
133
}
134
 
135
static int con_open(struct tty_struct* tty, struct file* filp)
136
{
137
        return 0;
138
}
139
 
140
/*
141
 * register our tty driver
142
 */
143
 
144
void mon960_console_init(void)
145
{
146
        memset(&console_driver, 0, sizeof(console_driver));
147
        console_driver.magic = TTY_DRIVER_MAGIC;
148
        console_driver.name = "tty";
149
        console_driver.name_base = 1;
150
        console_driver.major = TTY_MAJOR;
151
        console_driver.minor_start = 1;
152
        console_driver.num = 1;
153
        console_driver.type = TTY_DRIVER_TYPE_SERIAL;
154
        console_driver.init_termios = tty_std_termios;
155
        console_driver.init_termios.c_lflag |= ISIG | ICANON | ECHO
156
                 | ECHOE | ECHOK ;
157
        console_driver.init_termios.c_iflag |= ICRNL;
158
        console_driver.init_termios.c_cflag = CS8 | CREAD | CLOCAL;
159
        console_driver.flags = TTY_DRIVER_REAL_RAW;
160
        console_driver.refcount = &console_refcount;
161
 
162
        console_driver.table = console_table;
163
        console_driver.termios = console_termios;
164
        console_driver.termios_locked = console_termios_locked;
165
 
166
        console_driver.open = con_open;
167
        console_driver.write = con_write;
168
        console_driver.put_char = con_putchar;
169
        console_driver.write_room = con_writeroom;
170
        console_driver.chars_in_buffer = con_chars_in_buffer;
171
 
172
        if (tty_register_driver(&console_driver)) {
173
                printk("Couldn't register console driver\n");
174
        }
175
 
176
        /*
177
         * Enable receive interrupts
178
         */
179
        *SER16552_IER = IER_RCV_ENABLE;
180
 
181
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.