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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [char/] [serial_tx3912.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 *  drivers/char/serial_tx3912.c
3
 *
4
 *  Copyright (C) 2001 Steven J. Hill (sjhill@realitydiluted.com)
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License version 2 as
8
 * published by the Free Software Foundation.
9
 *
10
 *  Serial driver for TMPR3912/05 and PR31700 processors
11
 */
12
#include <linux/init.h>
13
#include <linux/config.h>
14
#include <linux/tty.h>
15
#include <linux/major.h>
16
#include <linux/console.h>
17
#include <linux/slab.h>
18
#include <linux/module.h>
19
#include <linux/serial.h>
20
#include <asm/io.h>
21
#include <asm/uaccess.h>
22
#include <asm/delay.h>
23
#include <asm/tx3912.h>
24
#include "serial_tx3912.h"
25
 
26
/*
27
 * Forward declarations for serial routines
28
 */
29
static void rs_disable_tx_interrupts (void * ptr);
30
static void rs_enable_tx_interrupts (void * ptr);
31
static void rs_disable_rx_interrupts (void * ptr);
32
static void rs_enable_rx_interrupts (void * ptr);
33
static int rs_get_CD (void * ptr);
34
static void rs_shutdown_port (void * ptr);
35
static int rs_set_real_termios (void *ptr);
36
static int rs_chars_in_buffer (void * ptr);
37
static void rs_hungup (void *ptr);
38
static void rs_close (void *ptr);
39
 
40
/*
41
 * Used by generic serial driver to access hardware
42
 */
43
static struct real_driver rs_real_driver = {
44
        disable_tx_interrupts: rs_disable_tx_interrupts,
45
        enable_tx_interrupts:  rs_enable_tx_interrupts,
46
        disable_rx_interrupts: rs_disable_rx_interrupts,
47
        enable_rx_interrupts:  rs_enable_rx_interrupts,
48
        get_CD:                rs_get_CD,
49
        shutdown_port:         rs_shutdown_port,
50
        set_real_termios:      rs_set_real_termios,
51
        chars_in_buffer:       rs_chars_in_buffer,
52
        close:                 rs_close,
53
        hungup:                rs_hungup,
54
};
55
 
56
/*
57
 * Structures and usage counts
58
 */
59
static struct tty_driver rs_driver, rs_callout_driver;
60
static struct tty_struct **rs_tty;
61
static struct termios **rs_termios;
62
static struct termios **rs_termios_locked;
63
static struct rs_port *rs_port;
64
static int rs_refcount;
65
static int rs_initialized;
66
 
67
 
68
/*
69
 * Receive a character
70
 */
71
static inline void receive_char_pio(struct rs_port *port)
72
{
73
        struct tty_struct *tty = port->gs.tty;
74
        unsigned char ch;
75
        int counter = 2048;
76
 
77
        /* While there are characters */
78
        while (counter > 0) {
79
                if (!(inl(TX3912_UARTA_CTRL1) & TX3912_UART_CTRL1_RXHOLDFULL))
80
                        break;
81
                ch = inb(TX3912_UARTA_DATA);
82
                if (tty->flip.count < TTY_FLIPBUF_SIZE) {
83
                        *tty->flip.char_buf_ptr++ = ch;
84
                        *tty->flip.flag_buf_ptr++ = 0;
85
                        tty->flip.count++;
86
                }
87
                udelay(1);
88
                counter--;
89
        }
90
 
91
        tty_flip_buffer_push(tty);
92
}
93
 
94
/*
95
 * Transmit a character
96
 */
97
static inline void transmit_char_pio(struct rs_port *port)
98
{
99
        /* TX while bytes available */
100
        for (;;) {
101
                if (!(inl(TX3912_UARTA_CTRL1) & TX3912_UART_CTRL1_EMPTY))
102
                        break;
103
                else if (port->x_char) {
104
                        outb(port->x_char, TX3912_UARTA_DATA);
105
                        port->icount.tx++;
106
                        port->x_char = 0;
107
                }
108
                else if (port->gs.xmit_cnt <= 0 || port->gs.tty->stopped ||
109
                    port->gs.tty->hw_stopped) {
110
                        break;
111
                }
112
                else {
113
                        outb(port->gs.xmit_buf[port->gs.xmit_tail++],
114
                                TX3912_UARTA_DATA);
115
                        port->icount.tx++;
116
                        port->gs.xmit_tail &= SERIAL_XMIT_SIZE-1;
117
                        if (--port->gs.xmit_cnt <= 0) {
118
                                break;
119
                        }
120
                }
121
                udelay(10);
122
        }
123
 
124
        if (port->gs.xmit_cnt <= 0 || port->gs.tty->stopped ||
125
             port->gs.tty->hw_stopped) {
126
                rs_disable_tx_interrupts(port);
127
        }
128
 
129
        if (port->gs.xmit_cnt <= port->gs.wakeup_chars) {
130
                if ((port->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
131
                    port->gs.tty->ldisc.write_wakeup)
132
                        (port->gs.tty->ldisc.write_wakeup)(port->gs.tty);
133
                rs_dprintk(TX3912_UART_DEBUG_TRANSMIT, "Waking up.... ldisc (%d)....\n",
134
                            port->gs.wakeup_chars);
135
                wake_up_interruptible(&port->gs.tty->write_wait);
136
        }
137
}
138
 
139
/*
140
 * We don't have MSR
141
 */
142
static inline void check_modem_status(struct rs_port *port)
143
{
144
        wake_up_interruptible(&port->gs.open_wait);
145
}
146
 
147
/*
148
 * RX interrupt handler
149
 */
150
static inline void rs_rx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
151
{
152
        unsigned long flags, status;
153
 
154
        save_and_cli(flags);
155
 
156
        rs_dprintk(TX3912_UART_DEBUG_INTERRUPTS, "rs_rx_interrupt...");
157
 
158
        /* Get the interrupts */
159
        status = inl(TX3912_INT2_STATUS);
160
 
161
        /* Clear any interrupts we might be about to handle */
162
        outl(TX3912_INT2_UARTA_RX_BITS, TX3912_INT2_CLEAR);
163
 
164
        if(!rs_port || !rs_port->gs.tty) {
165
                restore_flags(flags);
166
                return;
167
        }
168
 
169
        /* RX Receiver Holding Register Overrun */
170
        if(status & TX3912_INT2_UARTATXOVERRUNINT) {
171
                rs_dprintk(TX3912_UART_DEBUG_INTERRUPTS, "overrun");
172
                rs_port->icount.overrun++;
173
        }
174
 
175
        /* RX Frame Error */
176
        if(status & TX3912_INT2_UARTAFRAMEERRINT) {
177
                rs_dprintk(TX3912_UART_DEBUG_INTERRUPTS, "frame error");
178
                rs_port->icount.frame++;
179
        }
180
 
181
        /* Break signal received */
182
        if(status & TX3912_INT2_UARTABREAKINT) {
183
                rs_dprintk(TX3912_UART_DEBUG_INTERRUPTS, "break");
184
                rs_port->icount.brk++;
185
        }
186
 
187
        /* RX Parity Error */
188
        if(status & TX3912_INT2_UARTAPARITYINT) {
189
                rs_dprintk(TX3912_UART_DEBUG_INTERRUPTS, "parity error");
190
                rs_port->icount.parity++;
191
        }
192
 
193
        /* Byte received */
194
        if(status & TX3912_INT2_UARTARXINT) {
195
                receive_char_pio(rs_port);
196
        }
197
 
198
        restore_flags(flags);
199
 
200
        rs_dprintk(TX3912_UART_DEBUG_INTERRUPTS, "end.\n");
201
}
202
 
203
/*
204
 * TX interrupt handler
205
 */
206
static inline void rs_tx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
207
{
208
        unsigned long flags, status;
209
 
210
        save_and_cli(flags);
211
 
212
        rs_dprintk(TX3912_UART_DEBUG_INTERRUPTS, "rs_tx_interrupt...");
213
 
214
        /* Get the interrupts */
215
        status = inl(TX3912_INT2_STATUS);
216
 
217
        if(!rs_port || !rs_port->gs.tty) {
218
                restore_flags(flags);
219
                return;
220
        }
221
 
222
        /* Clear interrupts */
223
        outl(TX3912_INT2_UARTA_TX_BITS, TX3912_INT2_CLEAR);
224
 
225
        /* TX holding register empty - transmit a byte */
226
        if(status & TX3912_INT2_UARTAEMPTYINT) {
227
                transmit_char_pio(rs_port);
228
        }
229
 
230
        /* TX Transmit Holding Register Overrun (shouldn't happen) */
231
        if(status & TX3912_INT2_UARTATXOVERRUNINT) {
232
                printk( "rs_tx_interrupt: TX overrun\n");
233
        }
234
 
235
        restore_flags(flags);
236
 
237
        rs_dprintk(TX3912_UART_DEBUG_INTERRUPTS, "end.\n");
238
}
239
 
240
/*
241
 * Here are the routines that actually interface with the generic driver
242
 */
243
static void rs_disable_tx_interrupts (void * ptr)
244
{
245
        unsigned long flags;
246
 
247
        save_and_cli(flags);
248
 
249
        outl(inl(TX3912_INT2_ENABLE) & ~TX3912_INT2_UARTA_TX_BITS,
250
                TX3912_INT2_ENABLE);
251
        outl(TX3912_INT2_UARTA_TX_BITS, TX3912_INT2_CLEAR);
252
 
253
        restore_flags(flags);
254
}
255
 
256
static void rs_enable_tx_interrupts (void * ptr)
257
{
258
        unsigned long flags;
259
 
260
        save_and_cli(flags);
261
 
262
        outl(TX3912_INT2_UARTA_TX_BITS, TX3912_INT2_CLEAR);
263
        outl(inl(TX3912_INT2_ENABLE) | TX3912_INT2_UARTA_TX_BITS,
264
                TX3912_INT2_ENABLE);
265
        transmit_char_pio(rs_port);
266
 
267
        restore_flags(flags);
268
}
269
 
270
static void rs_disable_rx_interrupts (void * ptr)
271
{
272
        unsigned long flags;
273
 
274
        save_and_cli(flags);
275
 
276
        outl(inl(TX3912_INT2_ENABLE) & ~TX3912_INT2_UARTA_RX_BITS,
277
                TX3912_INT2_ENABLE);
278
        outl(TX3912_INT2_UARTA_RX_BITS, TX3912_INT2_CLEAR);
279
 
280
        restore_flags(flags);
281
}
282
 
283
static void rs_enable_rx_interrupts (void * ptr)
284
{
285
        unsigned long flags;
286
 
287
        save_and_cli(flags);
288
 
289
        outl(inl(TX3912_INT2_ENABLE) | TX3912_INT2_UARTA_RX_BITS,
290
                TX3912_INT2_ENABLE);
291
        while (inl(TX3912_UARTA_CTRL1) & TX3912_UART_CTRL1_RXHOLDFULL)
292
                inb(TX3912_UARTA_DATA);
293
        outl(TX3912_INT2_UARTA_RX_BITS, TX3912_INT2_CLEAR);
294
 
295
        restore_flags(flags);
296
}
297
 
298
/*
299
 * We have no CD
300
 */
301
static int rs_get_CD (void * ptr)
302
{
303
        return 1;
304
}
305
 
306
/*
307
 * Shut down the port
308
 */
309
static void rs_shutdown_port (void * ptr)
310
{
311
        func_enter();
312
        rs_port->gs.flags &= ~GS_ACTIVE;
313
        func_exit();
314
}
315
 
316
static int rs_set_real_termios (void *ptr)
317
{
318
        unsigned int ctrl1 = 0;
319
        unsigned int ctrl2 = 0;
320
 
321
        /* Set baud rate */
322
        switch (rs_port->gs.baud) {
323
                case 0:
324
                        goto done;
325
                case 1200:
326
                        ctrl2 = TX3912_UART_CTRL2_B1200;
327
                        break;
328
                case 2400:
329
                        ctrl2 = TX3912_UART_CTRL2_B2400;
330
                        break;
331
                case 4800:
332
                        ctrl2 = TX3912_UART_CTRL2_B4800;
333
                        break;
334
                case 9600:
335
                        ctrl2 = TX3912_UART_CTRL2_B9600;
336
                        break;
337
                case 19200:
338
                        ctrl2 = TX3912_UART_CTRL2_B19200;
339
                        break;
340
                case 38400:
341
                        ctrl2 = TX3912_UART_CTRL2_B38400;
342
                        break;
343
                case 57600:
344
                        ctrl2 = TX3912_UART_CTRL2_B57600;
345
                        break;
346
                case 115200:
347
                default:
348
                        ctrl2 = TX3912_UART_CTRL2_B115200;
349
                        break;
350
        }
351
 
352
        /* Clear current UARTA settings */
353
        ctrl1 = inl(TX3912_UARTA_CTRL1) & 0xf000000f;
354
 
355
        /* Set parity */
356
        if(C_PARENB(rs_port->gs.tty)) {
357
                if (!C_PARODD(rs_port->gs.tty))
358
                        ctrl1 |= (TX3912_UART_CTRL1_ENPARITY |
359
                                 TX3912_UART_CTRL1_EVENPARITY);
360
                else
361
                        ctrl1 |= TX3912_UART_CTRL1_ENPARITY;
362
        }
363
 
364
        /* Set data size */
365
        switch(rs_port->gs.tty->termios->c_cflag & CSIZE) {
366
                case CS7:
367
                        ctrl1 |= TX3912_UART_CTRL1_BIT_7;
368
                        break;
369
                case CS5:
370
                case CS6:
371
                        printk(KERN_ERR "Data byte size unsupported. Defaulting to CS8\n");
372
                case CS8:
373
                default:
374
                        ctrl1 &= ~TX3912_UART_CTRL1_BIT_7;
375
        }
376
 
377
        /* Set stop bits */
378
        if(C_CSTOPB(rs_port->gs.tty))
379
                ctrl1 |= TX3912_UART_CTRL1_TWOSTOP;
380
 
381
        /* Write the control registers */
382
        outl(ctrl2, TX3912_UARTA_CTRL2);
383
        outl(0, TX3912_UARTA_DMA_CTRL1);
384
        outl(0, TX3912_UARTA_DMA_CTRL2);
385
        outl(ctrl1, TX3912_UARTA_CTRL1);
386
 
387
        /* Loop until the UART is on */
388
        while(~inl(TX3912_UARTA_CTRL1) & TX3912_UART_CTRL1_UARTON);
389
 
390
done:
391
        func_exit();
392
        return 0;
393
}
394
 
395
/*
396
 * Anyone in the buffer?
397
 */
398
static int rs_chars_in_buffer (void * ptr)
399
{
400
        return ((inl(TX3912_UARTA_CTRL1) & TX3912_UART_CTRL1_EMPTY) ? 0 : 1);
401
}
402
 
403
/*
404
 * Open the serial port
405
 */
406
static int rs_open(struct tty_struct * tty, struct file * filp)
407
{
408
        int retval;
409
 
410
        func_enter();
411
 
412
        if(!rs_initialized) {
413
                return -EIO;
414
        }
415
 
416
        if(MINOR(tty->device) - tty->driver.minor_start) {
417
                return -ENODEV;
418
        }
419
 
420
        rs_dprintk(TX3912_UART_DEBUG_OPEN, "Serial opening...\n");
421
 
422
        tty->driver_data = rs_port;
423
        rs_port->gs.tty = tty;
424
        rs_port->gs.count++;
425
 
426
        /*
427
         * Start up serial port
428
         */
429
        retval = gs_init_port(&rs_port->gs);
430
        rs_dprintk(TX3912_UART_DEBUG_OPEN, "Finished gs_init...\n");
431
        if(retval) {
432
                rs_port->gs.count--;
433
                return retval;
434
        }
435
 
436
        rs_port->gs.flags |= GS_ACTIVE;
437
        if(rs_port->gs.count == 1) {
438
                MOD_INC_USE_COUNT;
439
        }
440
 
441
        rs_enable_rx_interrupts(rs_port);
442
        rs_enable_tx_interrupts(rs_port);
443
 
444
        retval = gs_block_til_ready(&rs_port->gs, filp);
445
        if(retval) {
446
                MOD_DEC_USE_COUNT;
447
                rs_port->gs.count--;
448
                return retval;
449
        }
450
 
451
        if((rs_port->gs.count == 1) &&
452
                (rs_port->gs.flags & ASYNC_SPLIT_TERMIOS)) {
453
                if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
454
                        *tty->termios = rs_port->gs.normal_termios;
455
                else
456
                        *tty->termios = rs_port->gs.callout_termios;
457
                rs_set_real_termios(rs_port);
458
        }
459
 
460
        rs_port->gs.session = current->session;
461
        rs_port->gs.pgrp = current->pgrp;
462
        func_exit();
463
 
464
        return 0;
465
}
466
 
467
/*
468
 * Close the serial port
469
 */
470
static void rs_close(void *ptr)
471
{
472
        func_enter();
473
        MOD_DEC_USE_COUNT;
474
        func_exit();
475
}
476
 
477
/*
478
 * Hang up the serial port
479
 */
480
static void rs_hungup(void *ptr)
481
{
482
        func_enter();
483
        MOD_DEC_USE_COUNT;
484
        func_exit();
485
}
486
 
487
/*
488
 * Serial ioctl call
489
 */
490
static int rs_ioctl(struct tty_struct * tty, struct file * filp,
491
                     unsigned int cmd, unsigned long arg)
492
{
493
        int ival, rc;
494
 
495
        rc = 0;
496
        switch (cmd) {
497
                case TIOCGSOFTCAR:
498
                        rc = put_user((tty->termios->c_cflag & CLOCAL) ? 1 : 0,
499
                              (unsigned int *) arg);
500
                        break;
501
                case TIOCSSOFTCAR:
502
                        if ((rc = verify_area(VERIFY_READ, (void *) arg,
503
                                sizeof(int))) == 0) {
504
                                get_user(ival, (unsigned int *) arg);
505
                                tty->termios->c_cflag =
506
                                        (tty->termios->c_cflag & ~CLOCAL) |
507
                                        (ival ? CLOCAL : 0);
508
                        }
509
                        break;
510
                case TIOCGSERIAL:
511
                        if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
512
                                sizeof(struct serial_struct))) == 0)
513
                                rc = gs_getserial(&rs_port->gs, (struct serial_struct *) arg);
514
                        break;
515
                case TIOCSSERIAL:
516
                        if ((rc = verify_area(VERIFY_READ, (void *) arg,
517
                                sizeof(struct serial_struct))) == 0)
518
                                rc = gs_setserial(&rs_port->gs, (struct serial_struct *) arg);
519
                        break;
520
                default:
521
                        rc = -ENOIOCTLCMD;
522
                        break;
523
        }
524
 
525
        return rc;
526
}
527
 
528
/*
529
 * Send xchar
530
 */
531
static void rs_send_xchar(struct tty_struct * tty, char ch)
532
{
533
        func_enter();
534
 
535
        rs_port->x_char = ch;
536
        if (ch) {
537
                rs_enable_tx_interrupts(tty);
538
        }
539
 
540
        func_exit();
541
}
542
 
543
/*
544
 * Throttle characters as directed by upper tty layer
545
 */
546
static void rs_throttle(struct tty_struct * tty)
547
{
548
#ifdef TX3912_UART_DEBUG_THROTTLE
549
        char    buf[64];
550
 
551
        printk("throttle %s: %d....\n", tty_name(tty, buf),
552
               tty->ldisc.chars_in_buffer(tty));
553
#endif
554
 
555
        func_enter();
556
 
557
        if (I_IXOFF(tty))
558
                rs_send_xchar(tty, STOP_CHAR(tty));
559
 
560
        func_exit();
561
}
562
 
563
/*
564
 * Un-throttle characters as directed by upper tty layer
565
 */
566
static void rs_unthrottle(struct tty_struct * tty)
567
{
568
#ifdef TX3912_UART_DEBUG_THROTTLE
569
        char    buf[64];
570
 
571
        printk("unthrottle %s: %d....\n", tty_name(tty, buf),
572
               tty->ldisc.chars_in_buffer(tty));
573
#endif
574
 
575
        func_enter();
576
 
577
        if (I_IXOFF(tty)) {
578
                if (rs_port->x_char)
579
                        rs_port->x_char = 0;
580
                else
581
                        rs_send_xchar(tty, START_CHAR(tty));
582
        }
583
 
584
        func_exit();
585
}
586
 
587
/*
588
 * Initialize the serial port
589
 */
590
void __init tx3912_rs_init(void)
591
{
592
        func_enter();
593
        rs_dprintk(TX3912_UART_DEBUG_INIT, "Initializing serial...\n");
594
 
595
        /* Allocate critical structures */
596
        if(!(rs_tty = kmalloc(sizeof(struct tty_struct), GFP_KERNEL))) {
597
                return;
598
        }
599
        if(!(rs_port = kmalloc(sizeof(struct rs_port), GFP_KERNEL))) {
600
                kfree(rs_tty);
601
                return;
602
        }
603
        if(!(rs_termios = kmalloc(sizeof(struct termios), GFP_KERNEL))) {
604
                kfree(rs_port);
605
                kfree(rs_tty);
606
                return;
607
        }
608
        if(!(rs_termios_locked = kmalloc(sizeof(struct termios), GFP_KERNEL))) {
609
                kfree(rs_termios);
610
                kfree(rs_port);
611
                kfree(rs_tty);
612
                return;
613
        }
614
 
615
        /* Zero out the structures */
616
        memset(rs_tty, 0, sizeof(struct tty_struct));
617
        memset(rs_port, 0, sizeof(struct rs_port));
618
        memset(rs_termios, 0, sizeof(struct termios));
619
        memset(rs_termios_locked, 0, sizeof(struct termios));
620
        memset(&rs_driver, 0, sizeof(rs_driver));
621
        memset(&rs_callout_driver, 0, sizeof(rs_callout_driver));
622
 
623
        /* Fill in hardware specific port structure */
624
        rs_port->gs.callout_termios = tty_std_termios;
625
        rs_port->gs.normal_termios      = tty_std_termios;
626
        rs_port->gs.magic = SERIAL_MAGIC;
627
        rs_port->gs.close_delay = HZ/2;
628
        rs_port->gs.closing_wait = 30 * HZ;
629
        rs_port->gs.rd = &rs_real_driver;
630
#ifdef NEW_WRITE_LOCKING
631
        rs_port->gs.port_write_sem = MUTEX;
632
#endif
633
#ifdef DECLARE_WAITQUEUE
634
        init_waitqueue_head(&rs_port->gs.open_wait);
635
        init_waitqueue_head(&rs_port->gs.close_wait);
636
#endif
637
 
638
        /* Fill in generic serial driver structures */
639
        rs_driver.magic = TTY_DRIVER_MAGIC;
640
        rs_driver.driver_name = "serial";
641
        rs_driver.name = "ttyS";
642
        rs_driver.major = TTY_MAJOR;
643
        rs_driver.minor_start = 64;
644
        rs_driver.num = 1;
645
        rs_driver.type = TTY_DRIVER_TYPE_SERIAL;
646
        rs_driver.subtype = SERIAL_TYPE_NORMAL;
647
        rs_driver.init_termios = tty_std_termios;
648
        rs_driver.init_termios.c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL;
649
        rs_driver.refcount = &rs_refcount;
650
        rs_driver.table = rs_tty;
651
        rs_driver.termios = rs_termios;
652
        rs_driver.termios_locked = rs_termios_locked;
653
        rs_driver.open  = rs_open;
654
        rs_driver.close = gs_close;
655
        rs_driver.write = gs_write;
656
        rs_driver.put_char = gs_put_char;
657
        rs_driver.flush_chars = gs_flush_chars;
658
        rs_driver.write_room = gs_write_room;
659
        rs_driver.chars_in_buffer = gs_chars_in_buffer;
660
        rs_driver.flush_buffer = gs_flush_buffer;
661
        rs_driver.ioctl = rs_ioctl;
662
        rs_driver.throttle = rs_throttle;
663
        rs_driver.unthrottle = rs_unthrottle;
664
        rs_driver.set_termios = gs_set_termios;
665
        rs_driver.stop = gs_stop;
666
        rs_driver.start = gs_start;
667
        rs_driver.hangup = gs_hangup;
668
        rs_callout_driver = rs_driver;
669
        rs_callout_driver.name = "cua";
670
        rs_callout_driver.major = TTYAUX_MAJOR;
671
        rs_callout_driver.subtype = SERIAL_TYPE_CALLOUT;
672
 
673
        /* Register serial and callout drivers */
674
        if(tty_register_driver(&rs_driver)) {
675
                printk(KERN_ERR "Unable to register serial driver\n");
676
                goto error;
677
        }
678
        if(tty_register_driver(&rs_callout_driver)) {
679
                tty_unregister_driver(&rs_driver);
680
                printk(KERN_ERR "Unable to register callout driver\n");
681
                goto error;
682
        }
683
 
684
        /* Assign IRQs */
685
        if(request_irq(2, rs_tx_interrupt, SA_SHIRQ,
686
                "uarta_tx", rs_port)) {
687
                printk(KERN_ERR "Cannot allocate IRQ for UARTA_TX.\n");
688
                goto error;
689
        }
690
 
691
        if(request_irq(3, rs_rx_interrupt, SA_SHIRQ,
692
                "uarta_rx", rs_port)) {
693
                printk(KERN_ERR "Cannot allocate IRQ for UARTA_RX.\n");
694
                goto error;
695
        }
696
 
697
        /* Enable the serial receive interrupt */
698
        rs_enable_rx_interrupts(rs_port);
699
 
700
#ifndef CONFIG_SERIAL_TX3912_CONSOLE
701
        /* Write the control registers */
702
        outl(TX3912_UART_CTRL2_B115200, TX3912_UARTA_CTRL2);
703
        outl(0x00000000, TX3912_UARTA_DMA_CTRL1);
704
        outl(0x00000000, TX3912_UARTA_DMA_CTRL2);
705
        outl(inl(TX3912_UARTA_CTRL1) | TX3912_UART_CTRL1_ENUART,
706
                TX3912_UARTA_CTRL1);
707
 
708
        /* Loop until the UART is on */
709
        while(~inl(TX3912_UARTA_CTRL1) & TX3912_UART_CTRL1_UARTON);
710
#endif
711
 
712
        rs_initialized = 1;
713
        func_exit();
714
        return;
715
 
716
error:
717
        kfree(rs_termios_locked);
718
        kfree(rs_termios);
719
        kfree(rs_port);
720
        kfree(rs_tty);
721
        func_exit();
722
}
723
 
724
/*
725
 * Begin serial console routines
726
 */
727
#ifdef CONFIG_SERIAL_TX3912_CONSOLE
728
void serial_outc(unsigned char c)
729
{
730
        int i;
731
        unsigned long int2;
732
 
733
        /* Disable UARTA_TX interrupts */
734
        int2 = inl(TX3912_INT2_ENABLE);
735
        outl(inl(TX3912_INT2_ENABLE) & ~TX3912_INT2_UARTA_TX_BITS,
736
                 TX3912_INT2_ENABLE);
737
 
738
        /* Wait for UARTA_TX register to empty */
739
        i = 10000;
740
        while(!(inl(TX3912_INT2_STATUS) & TX3912_INT2_UARTATXINT) && i--);
741
        outl(TX3912_INT2_UARTA_TX_BITS, TX3912_INT2_CLEAR);
742
 
743
        /* Send the character */
744
        outl(c, TX3912_UARTA_DATA);
745
 
746
        /* Wait for UARTA_TX register to empty */
747
        i = 10000;
748
        while(!(inl(TX3912_INT2_STATUS) & TX3912_INT2_UARTATXINT) && i--);
749
        outl(TX3912_INT2_UARTA_TX_BITS, TX3912_INT2_CLEAR);
750
 
751
        /* Enable UARTA_TX interrupts */
752
        outl(int2, TX3912_INT2_ENABLE);
753
}
754
 
755
static int serial_console_wait_key(struct console *co)
756
{
757
        unsigned int int2, res;
758
 
759
        int2 = inl(TX3912_INT2_ENABLE);
760
        outl(0, TX3912_INT2_ENABLE);
761
 
762
        while (!(inl(TX3912_UARTA_CTRL1) & TX3912_UART_CTRL1_RXHOLDFULL));
763
        res = inl(TX3912_UARTA_DATA);
764
        udelay(10);
765
 
766
        outl(int2, TX3912_INT2_ENABLE);
767
        return res;
768
}
769
 
770
static void serial_console_write(struct console *co, const char *s,
771
        unsigned count)
772
{
773
        unsigned int i;
774
 
775
        for (i = 0; i < count; i++) {
776
                if (*s == '\n')
777
                        serial_outc('\r');
778
                serial_outc(*s++);
779
        }
780
}
781
 
782
static kdev_t serial_console_device(struct console *c)
783
{
784
        return MKDEV(TTY_MAJOR, 64 + c->index);
785
}
786
 
787
static __init int serial_console_setup(struct console *co, char *options)
788
{
789
        int baud = 115200;
790
        int bits = 8;
791
        int parity = 'n';
792
        char *s;
793
        unsigned int ctrl1 = 0;
794
        unsigned int ctrl2 = 0;
795
 
796
        if (options) {
797
                baud = simple_strtoul(options, NULL, 10);
798
                s = options;
799
                while(*s >= '0' && *s <= '9')
800
                        s++;
801
                if (*s) parity = *s++;
802
                if (*s) bits   = *s++ - '0';
803
        }
804
 
805
        switch(baud) {
806
                case 1200:
807
                        ctrl2 = TX3912_UART_CTRL2_B1200;
808
                        break;
809
                case 2400:
810
                        ctrl2 = TX3912_UART_CTRL2_B2400;
811
                        break;
812
                case 4800:
813
                        ctrl2 = TX3912_UART_CTRL2_B4800;
814
                        break;
815
                case 9600:
816
                        ctrl2 = TX3912_UART_CTRL2_B9600;
817
                        break;
818
                case 19200:
819
                        ctrl2 = TX3912_UART_CTRL2_B19200;
820
                        break;
821
                case 38400:
822
                        ctrl2 = TX3912_UART_CTRL2_B38400;
823
                        break;
824
                case 57600:
825
                        ctrl2 = TX3912_UART_CTRL2_B57600;
826
                        break;
827
                case 115200:
828
                default:
829
                        ctrl2 = TX3912_UART_CTRL2_B115200;
830
                        break;
831
        }
832
 
833
        switch(bits) {
834
                case 7:
835
                        ctrl1 = TX3912_UART_CTRL1_BIT_7;
836
                        break;
837
                default:
838
                        break;
839
        }
840
 
841
        switch(parity) {
842
                case 'o': case 'O':
843
                        ctrl1 |= TX3912_UART_CTRL1_ENPARITY;
844
                        break;
845
                case 'e': case 'E':
846
                        ctrl1 |= (TX3912_UART_CTRL1_ENPARITY |
847
                                 TX3912_UART_CTRL1_EVENPARITY);
848
                        break;
849
                default:
850
                        break;
851
        }
852
 
853
        /* Write the control registers */
854
        outl(ctrl2, TX3912_UARTA_CTRL2);
855
        outl(0x00000000, TX3912_UARTA_DMA_CTRL1);
856
        outl(0x00000000, TX3912_UARTA_DMA_CTRL2);
857
        outl((ctrl1 | TX3912_UART_CTRL1_ENUART), TX3912_UARTA_CTRL1);
858
 
859
        /* Loop until the UART is on */
860
        while(~inl(TX3912_UARTA_CTRL1) & TX3912_UART_CTRL1_UARTON);
861
 
862
        return 0;
863
}
864
 
865
static struct console sercons = {
866
        name:     "ttyS",
867
        write:    serial_console_write,
868
        device:   serial_console_device,
869
        setup:    serial_console_setup,
870
        flags:    CON_PRINTBUFFER,
871
        index:    -1
872
};
873
 
874
void __init tx3912_console_init(void)
875
{
876
        register_console(&sercons);
877
}
878
#endif

powered by: WebSVN 2.1.0

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