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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [char/] [68328serial.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/* 68328serial.c: Serial port driver for 68328 microcontroller
2
 *
3
 * Copyright (C) 1995       David S. Miller    <davem@caip.rutgers.edu>
4
 * Copyright (C) 1998       Kenneth Albanowski <kjahds@kjahds.com>
5
 * Copyright (C) 1998, 1999 D. Jeff Dionne     <jeff@rt-control.com>
6
 * Copyright (C) 1999       Vladimir Gurevich  <vgurevic@cisco.com>
7
 *
8
 */
9
 
10
#include <linux/errno.h>
11
#include <linux/signal.h>
12
#include <linux/sched.h>
13
#include <linux/timer.h>
14
#include <linux/interrupt.h>
15
#include <linux/tty.h>
16
#include <linux/tty_flip.h>
17
#include <linux/config.h>
18
#include <linux/major.h>
19
#include <linux/string.h>
20
#include <linux/fcntl.h>
21
#include <linux/mm.h>
22
#include <linux/kernel.h>
23
 
24
#include <asm/io.h>
25
#include <asm/irq.h>
26
#include <asm/system.h>
27
#include <asm/segment.h>
28
#include <asm/bitops.h>
29
#include <asm/delay.h>
30
 
31
#include "68328serial.h"
32
 
33
 
34
/* Turn off usage of real serial interrupt code, to "support" Copilot */
35
#ifdef CONFIG_XCOPILOT_BUGS
36
#undef USE_INTS
37
#else
38
#define USE_INTS
39
#endif
40
 
41
static struct m68k_serial m68k_soft;
42
 
43
struct tty_struct m68k_ttys;
44
struct m68k_serial *m68k_consinfo = 0;
45
 
46
#define M68K_CLOCK (16667000) /* FIXME: 16MHz is likely wrong */
47
 
48
DECLARE_TASK_QUEUE(tq_serial);
49
 
50
struct tty_driver serial_driver, callout_driver;
51
static int serial_refcount;
52
 
53
/* serial subtype definitions */
54
#define SERIAL_TYPE_NORMAL      1
55
#define SERIAL_TYPE_CALLOUT     2
56
 
57
/* number of characters left in xmit buffer before we ask for more */
58
#define WAKEUP_CHARS 256
59
 
60
/* Debugging... DEBUG_INTR is bad to use when one of the zs
61
 * lines is your console ;(
62
 */
63
#undef SERIAL_DEBUG_INTR
64
#undef SERIAL_DEBUG_OPEN
65
#undef SERIAL_DEBUG_FLOW
66
 
67
#define RS_ISR_PASS_LIMIT 256
68
 
69
#define _INLINE_ inline
70
 
71
static void change_speed(struct m68k_serial *info);
72
 
73
static struct tty_struct *serial_table[2];
74
static struct termios *serial_termios[2];
75
static struct termios *serial_termios_locked[2];
76
 
77
#ifndef MIN
78
#define MIN(a,b)        ((a) < (b) ? (a) : (b))
79
#endif
80
 
81
/*
82
 * tmp_buf is used as a temporary buffer by serial_write.  We need to
83
 * lock it in case the memcpy_fromfs blocks while swapping in a page,
84
 * and some other program tries to do a serial write at the same time.
85
 * Since the lock will only come under contention when the system is
86
 * swapping and available memory is low, it makes sense to share one
87
 * buffer across all the serial ports, since it significantly saves
88
 * memory if large numbers of serial ports are open.
89
 */
90
static unsigned char tmp_buf[SERIAL_XMIT_SIZE]; /* This is cheating */
91
static struct semaphore tmp_buf_sem = MUTEX;
92
 
93
static inline int serial_paranoia_check(struct m68k_serial *info,
94
                                        dev_t device, const char *routine)
95
{
96
#ifdef SERIAL_PARANOIA_CHECK
97
        static const char *badmagic =
98
                "Warning: bad magic number for serial struct (%d, %d) in %s\n";
99
        static const char *badinfo =
100
                "Warning: null m68k_serial for (%d, %d) in %s\n";
101
 
102
        if (!info) {
103
                printk(badinfo, MAJOR(device), MINOR(device), routine);
104
                return 1;
105
        }
106
        if (info->magic != SERIAL_MAGIC) {
107
                printk(badmagic, MAJOR(device), MINOR(device), routine);
108
                return 1;
109
        }
110
#endif
111
        return 0;
112
}
113
 
114
/*
115
 * This is used to figure out the divisor speeds and the timeouts
116
 */
117
static int baud_table[] = {
118
        0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
119
        9600, 19200, 38400, 57600, 115200, 0 };
120
 
121
/* Sets or clears DTR/RTS on the requested line */
122
static inline void m68k_rtsdtr(struct m68k_serial *ss, int set)
123
{
124
        if (set) {
125
                /* set the RTS/CTS line */
126
        } else {
127
                /* clear it */
128
        }
129
        return;
130
}
131
 
132
/* Utility routines */
133
static inline int get_baud(struct m68k_serial *ss)
134
{
135
        unsigned long result = 115200;
136
        unsigned short int baud = UBAUD;
137
        if (GET_FIELD(baud, UBAUD_PRESCALER) == 0x38) result = 38400;
138
        result >>= GET_FIELD(baud, UBAUD_DIVIDE);
139
 
140
        return result;
141
}
142
 
143
/*
144
 * ------------------------------------------------------------
145
 * rs_stop() and rs_start()
146
 *
147
 * This routines are called before setting or resetting tty->stopped.
148
 * They enable or disable transmitter interrupts, as necessary.
149
 * ------------------------------------------------------------
150
 */
151
static void rs_stop(struct tty_struct *tty)
152
{
153
        struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
154
        unsigned long flags;
155
 
156
        if (serial_paranoia_check(info, tty->device, "rs_stop"))
157
                return;
158
 
159
        save_flags(flags); cli();
160
        USTCNT &= ~USTCNT_TXEN;
161
        restore_flags(flags);
162
}
163
 
164
static void rs_put_char(char ch)
165
{
166
        int flags, loops = 0;
167
 
168
        save_flags(flags); cli();
169
 
170
        while (!(UTX & UTX_TX_AVAIL) && (loops < 1000)) {
171
                loops++;
172
                udelay(5);
173
        }
174
 
175
        UTX_TXDATA = ch;
176
        udelay(5);
177
        restore_flags(flags);
178
}
179
 
180
static void rs_start(struct tty_struct *tty)
181
{
182
        struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
183
        unsigned long flags;
184
 
185
        if (serial_paranoia_check(info, tty->device, "rs_start"))
186
                return;
187
 
188
        save_flags(flags); cli();
189
        if (info->xmit_cnt && info->xmit_buf && !(USTCNT & USTCNT_TXEN)) {
190
#ifdef USE_INTS
191
                USTCNT |= USTCNT_TXEN | USTCNT_TX_INTR_MASK;
192
#else
193
                USTCNT |= USTCNT_TXEN;
194
#endif
195
        }
196
        restore_flags(flags);
197
}
198
 
199
/* Drop into either the boot monitor or kadb upon receiving a break
200
 * from keyboard/console input.
201
 */
202
static void batten_down_hatches(void)
203
{
204
        /* Drop into the debugger */
205
}
206
 
207
static _INLINE_ void status_handle(struct m68k_serial *info, unsigned short status)
208
{
209
#if 0
210
        if(status & DCD) {
211
                if((info->tty->termios->c_cflag & CRTSCTS) &&
212
                   ((info->curregs[3] & AUTO_ENAB)==0)) {
213
                        info->curregs[3] |= AUTO_ENAB;
214
                        info->pendregs[3] |= AUTO_ENAB;
215
                        write_zsreg(info->m68k_channel, 3, info->curregs[3]);
216
                }
217
        } else {
218
                if((info->curregs[3] & AUTO_ENAB)) {
219
                        info->curregs[3] &= ~AUTO_ENAB;
220
                        info->pendregs[3] &= ~AUTO_ENAB;
221
                        write_zsreg(info->m68k_channel, 3, info->curregs[3]);
222
                }
223
        }
224
#endif
225
        /* If this is console input and this is a
226
         * 'break asserted' status change interrupt
227
         * see if we can drop into the debugger
228
         */
229
        if((status & URX_BREAK) && info->break_abort)
230
                batten_down_hatches();
231
        return;
232
}
233
 
234
/*
235
 * This routine is used by the interrupt handler to schedule
236
 * processing in the software interrupt portion of the driver.
237
 */
238
static _INLINE_ void rs_sched_event(struct m68k_serial *info,
239
                                    int event)
240
{
241
        info->event |= 1 << event;
242
        queue_task_irq_off(&info->tqueue, &tq_serial);
243
        mark_bh(SERIAL_BH);
244
}
245
 
246
static _INLINE_ void receive_chars(struct m68k_serial *info, struct pt_regs *regs, unsigned short rx)
247
{
248
        struct tty_struct *tty = info->tty;
249
        unsigned char ch;
250
 
251
        /*
252
         * This do { } while() loop will get ALL chars out of Rx FIFO
253
         */
254
#ifndef CONFIG_XCOPILOT_BUGS
255
        do {
256
#endif  
257
                ch = GET_FIELD(rx, URX_RXDATA);
258
 
259
                if(info->is_cons) {
260
                        if(URX_BREAK & rx) { /* whee, break received */
261
                                status_handle(info, rx);
262
                                return;
263
                        } else if (ch == 0x10) { /* ^P */
264
                                show_state();
265
                                show_free_areas();
266
                                show_buffers();
267
                                show_net_buffers();
268
                                return;
269
                        } else if (ch == 0x12) { /* ^R */
270
                                hard_reset_now();
271
                                return;
272
                        }
273
                        /* It is a 'keyboard interrupt' ;-) */
274
                        wake_up(&keypress_wait);
275
                }
276
 
277
                if(!tty)
278
                        goto clear_and_exit;
279
 
280
                /*
281
                 * Make sure that we do not overflow the buffer
282
                 */
283
                if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
284
                        queue_task_irq_off(&tty->flip.tqueue, &tq_timer);
285
                        return;
286
                }
287
 
288
                if(rx & URX_PARITY_ERROR) {
289
                        *tty->flip.flag_buf_ptr++ = TTY_PARITY;
290
                        status_handle(info, rx);
291
                } else if(rx & URX_OVRUN) {
292
                        *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
293
                        status_handle(info, rx);
294
                } else if(rx & URX_FRAME_ERROR) {
295
                        *tty->flip.flag_buf_ptr++ = TTY_FRAME;
296
                        status_handle(info, rx);
297
                } else {
298
                        *tty->flip.flag_buf_ptr++ = 0; /* XXX */
299
                }
300
                *tty->flip.char_buf_ptr++ = ch;
301
                tty->flip.count++;
302
 
303
#ifndef CONFIG_XCOPILOT_BUGS
304
        } while((rx = URX) & URX_DATA_READY);
305
#endif
306
 
307
        queue_task_irq_off(&tty->flip.tqueue, &tq_timer);
308
 
309
clear_and_exit:
310
        return;
311
}
312
 
313
static _INLINE_ void transmit_chars(struct m68k_serial *info)
314
{
315
        if (info->x_char) {
316
                /* Send next char */
317
                UTX_TXDATA = info->x_char;
318
                info->x_char = 0;
319
                goto clear_and_return;
320
        }
321
 
322
        if((info->xmit_cnt <= 0) || info->tty->stopped) {
323
                /* That's peculiar... TX ints off */
324
                USTCNT &= ~USTCNT_TX_INTR_MASK;
325
                goto clear_and_return;
326
        }
327
 
328
        /* Send char */
329
        UTX_TXDATA = info->xmit_buf[info->xmit_tail++];
330
        info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
331
        info->xmit_cnt--;
332
 
333
        if (info->xmit_cnt < WAKEUP_CHARS)
334
                rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
335
 
336
        if(info->xmit_cnt <= 0) {
337
                /* All done for now... TX ints off */
338
                USTCNT &= ~USTCNT_TX_INTR_MASK;
339
                goto clear_and_return;
340
        }
341
 
342
clear_and_return:
343
        /* Clear interrupt (should be auto)*/
344
        return;
345
}
346
 
347
/*
348
 * This is the serial driver's generic interrupt routine
349
 */
350
void rs_interrupt(int irq, void *dev_id, struct pt_regs * regs)
351
{
352
        struct m68k_serial * info = &m68k_soft;
353
        unsigned short rx = URX;
354
#ifdef USE_INTS
355
        unsigned short tx = UTX;
356
 
357
        if (rx & URX_DATA_READY) receive_chars(info, regs, rx);
358
        if (tx & UTX_TX_AVAIL)   transmit_chars(info);
359
#else
360
        receive_chars(info, regs, rx);
361
#endif
362
        return;
363
}
364
 
365
/*
366
 * This routine is used to handle the "bottom half" processing for the
367
 * serial driver, known also the "software interrupt" processing.
368
 * This processing is done at the kernel interrupt level, after the
369
 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON.  This
370
 * is where time-consuming activities which can not be done in the
371
 * interrupt driver proper are done; the interrupt driver schedules
372
 * them using rs_sched_event(), and they get done here.
373
 */
374
static void do_serial_bh(void)
375
{
376
        run_task_queue(&tq_serial);
377
}
378
 
379
static void do_softint(void *private_)
380
{
381
        struct m68k_serial      *info = (struct m68k_serial *) private_;
382
        struct tty_struct       *tty;
383
 
384
        tty = info->tty;
385
        if (!tty)
386
                return;
387
 
388
        if (clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) {
389
                if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
390
                    tty->ldisc.write_wakeup)
391
                        (tty->ldisc.write_wakeup)(tty);
392
                wake_up_interruptible(&tty->write_wait);
393
        }
394
}
395
 
396
/*
397
 * This routine is called from the scheduler tqueue when the interrupt
398
 * routine has signalled that a hangup has occurred.  The path of
399
 * hangup processing is:
400
 *
401
 *      serial interrupt routine -> (scheduler tqueue) ->
402
 *      do_serial_hangup() -> tty->hangup() -> rs_hangup()
403
 *
404
 */
405
static void do_serial_hangup(void *private_)
406
{
407
        struct m68k_serial      *info = (struct m68k_serial *) private_;
408
        struct tty_struct       *tty;
409
 
410
        tty = info->tty;
411
        if (!tty)
412
                return;
413
 
414
        tty_hangup(tty);
415
}
416
 
417
 
418
/*
419
 * This subroutine is called when the RS_TIMER goes off.  It is used
420
 * by the serial driver to handle ports that do not have an interrupt
421
 * 68328 does, we had better never get here.
422
 */
423
 
424
static void rs_timer(void)
425
{
426
        panic("rs_timer called\n");
427
        return;
428
}
429
 
430
static int startup(struct m68k_serial * info)
431
{
432
        unsigned long flags;
433
 
434
        if (info->flags & S_INITIALIZED)
435
                return 0;
436
 
437
        if (!info->xmit_buf) {
438
                info->xmit_buf = (unsigned char *) get_free_page(GFP_KERNEL);
439
                if (!info->xmit_buf)
440
                        return -ENOMEM;
441
        }
442
 
443
        save_flags(flags); cli();
444
 
445
        /*
446
         * Clear the FIFO buffers and disable them
447
         * (they will be reenabled in change_speed())
448
         */
449
 
450
        USTCNT = USTCNT_UEN;
451
        info->xmit_fifo_size = 1;
452
        USTCNT = USTCNT_UEN | USTCNT_RXEN | USTCNT_TXEN;
453
        (void)URX;
454
 
455
        /*
456
         * Finally, enable sequencing and interrupts
457
         */
458
#ifdef USE_INTS
459
        USTCNT = USTCNT_UEN | USTCNT_RXEN |
460
                 USTCNT_RX_INTR_MASK | USTCNT_TX_INTR_MASK;
461
#else
462
        USTCNT = USTCNT_UEN | USTCNT_RXEN | USTCNT_RX_INTR_MASK;
463
#endif
464
 
465
        if (info->tty)
466
                clear_bit(TTY_IO_ERROR, &info->tty->flags);
467
        info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
468
 
469
        /*
470
         * and set the speed of the serial port
471
         */
472
 
473
        change_speed(info);
474
 
475
        info->flags |= S_INITIALIZED;
476
        restore_flags(flags);
477
        return 0;
478
}
479
 
480
/*
481
 * This routine will shutdown a serial port; interrupts are disabled, and
482
 * DTR is dropped if the hangup on close termio flag is on.
483
 */
484
static void shutdown(struct m68k_serial * info)
485
{
486
        unsigned long   flags;
487
 
488
        USTCNT = 0; /* All off! */
489
        if (!(info->flags & S_INITIALIZED))
490
                return;
491
 
492
        save_flags(flags); cli(); /* Disable interrupts */
493
 
494
        if (info->xmit_buf) {
495
                free_page((unsigned long) info->xmit_buf);
496
                info->xmit_buf = 0;
497
        }
498
 
499
        if (info->tty)
500
                set_bit(TTY_IO_ERROR, &info->tty->flags);
501
 
502
        info->flags &= ~S_INITIALIZED;
503
        restore_flags(flags);
504
}
505
 
506
struct {
507
        int divisor, prescale;
508
} hw_baud_table[18] = {
509
        {0,0}, /* 0 */
510
        {0,0}, /* 50 */
511
        {0,0}, /* 75 */
512
        {0,0}, /* 110 */
513
        {0,0}, /* 134 */
514
        {0,0}, /* 150 */
515
        {0,0}, /* 200 */
516
        {7,0x26}, /* 300 */
517
        {6,0x26}, /* 600 */
518
        {5,0x26}, /* 1200 */
519
        {0,0}, /* 1800 */
520
        {4,0x26}, /* 2400 */
521
        {3,0x26}, /* 4800 */
522
        {2,0x26}, /* 9600 */
523
        {1,0x26}, /* 19200 */
524
        {0,0x26}, /* 38400 */
525
        {1,0x38}, /* 57600 */
526
        {0,0x38}, /* 115200 */
527
};
528
/* rate = 1036800 / ((65 - prescale) * (1<<divider)) */
529
 
530
/*
531
 * This routine is called to set the UART divisor registers to match
532
 * the specified baud rate for a serial port.
533
 */
534
static void change_speed(struct m68k_serial *info)
535
{
536
        unsigned short port;
537
        unsigned short ustcnt;
538
        unsigned cflag;
539
        int     i;
540
 
541
        if (!info->tty || !info->tty->termios)
542
                return;
543
        cflag = info->tty->termios->c_cflag;
544
        if (!(port = info->port))
545
                return;
546
 
547
        ustcnt = USTCNT;
548
        USTCNT = ustcnt & ~USTCNT_TXEN;
549
 
550
        i = cflag & CBAUD;
551
        if (i & CBAUDEX) {
552
                i = (i & ~CBAUDEX) + B38400;
553
        }
554
 
555
        info->baud = baud_table[i];
556
        UBAUD = PUT_FIELD(UBAUD_DIVIDE,    hw_baud_table[i].divisor) |
557
                PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale);
558
 
559
        ustcnt &= ~(USTCNT_PARITYEN | USTCNT_ODD_EVEN | USTCNT_STOP | USTCNT_8_7);
560
 
561
        if ((cflag & CSIZE) == CS8)
562
                ustcnt |= USTCNT_8_7;
563
 
564
        if (cflag & CSTOPB)
565
                ustcnt |= USTCNT_STOP;
566
 
567
        if (cflag & PARENB)
568
                ustcnt |= USTCNT_PARITYEN;
569
        if (cflag & PARODD)
570
                ustcnt |= USTCNT_ODD_EVEN;
571
 
572
#ifdef CONFIG_68328_SERIAL_RTS_CTS
573
        if (cflag & CRTSCTS) {
574
                UTX &= ~ UTX_NOCTS;
575
        } else {
576
                UTX |= UTX_NOCTS;
577
        }
578
#endif
579
 
580
        ustcnt |= USTCNT_TXEN;
581
 
582
        USTCNT = ustcnt;
583
        return;
584
}
585
 
586
/*
587
 * Fair output driver allows a process to speak.
588
 */
589
static void rs_fair_output(void)
590
{
591
        int left;               /* Output no more than that */
592
        unsigned long flags;
593
        struct m68k_serial *info = &m68k_soft;
594
        char c;
595
 
596
        if (info == 0) return;
597
        if (info->xmit_buf == 0) return;
598
 
599
        save_flags(flags);  cli();
600
        left = info->xmit_cnt;
601
        while (left != 0) {
602
                c = info->xmit_buf[info->xmit_tail];
603
                info->xmit_tail = (info->xmit_tail+1) & (SERIAL_XMIT_SIZE-1);
604
                info->xmit_cnt--;
605
                restore_flags(flags);
606
 
607
                rs_put_char(c);
608
 
609
                save_flags(flags);  cli();
610
                left = MIN(info->xmit_cnt, left-1);
611
        }
612
 
613
        /* Last character is being transmitted now (hopefully). */
614
        udelay(5);
615
 
616
        restore_flags(flags);
617
        return;
618
}
619
 
620
/*
621
 * m68k_console_print is registered for printk.
622
 */
623
void console_print_68328(const char *p)
624
{
625
        char c;
626
 
627
        while((c=*(p++)) != 0) {
628
                if(c == '\n')
629
                        rs_put_char('\r');
630
                rs_put_char(c);
631
        }
632
 
633
        /* Comment this if you want to have a strict interrupt-driven output */
634
        rs_fair_output();
635
 
636
        return;
637
}
638
 
639
static void rs_set_ldisc(struct tty_struct *tty)
640
{
641
        struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
642
 
643
        if (serial_paranoia_check(info, tty->device, "rs_set_ldisc"))
644
                return;
645
 
646
        info->is_cons = (tty->termios->c_line == N_TTY);
647
 
648
        printk("ttyS%d console mode %s\n", info->line, info->is_cons ? "on" : "off");
649
}
650
 
651
static void rs_flush_chars(struct tty_struct *tty)
652
{
653
        struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
654
        unsigned long flags;
655
 
656
        if (serial_paranoia_check(info, tty->device, "rs_flush_chars"))
657
                return;
658
#ifndef USE_INTS
659
        for(;;) {
660
#endif
661
        if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
662
            !info->xmit_buf)
663
                return;
664
 
665
        /* Enable transmitter */
666
        save_flags(flags); cli();
667
 
668
#ifdef USE_INTS
669
        USTCNT |= USTCNT_TXEN | USTCNT_TX_INTR_MASK;
670
#else
671
        USTCNT |= USTCNT_TXEN;
672
#endif
673
 
674
#ifdef USE_INTS
675
        if (UTX & UTX_TX_AVAIL) {
676
#else
677
        if (1) {
678
#endif
679
                /* Send char */
680
                UTX_TXDATA = info->xmit_buf[info->xmit_tail++];
681
                info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
682
                info->xmit_cnt--;
683
        }
684
 
685
#ifndef USE_INTS
686
        while (!(UTX & UTX_TX_AVAIL)) udelay(5);
687
        }
688
#endif
689
        restore_flags(flags);
690
}
691
 
692
extern void console_printn(const char * b, int count);
693
 
694
static int rs_write(struct tty_struct * tty, int from_user,
695
                    const unsigned char *buf, int count)
696
{
697
        int     c, total = 0;
698
        struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
699
        unsigned long flags;
700
 
701
        if (serial_paranoia_check(info, tty->device, "rs_write"))
702
                return 0;
703
 
704
        if (!tty || !info->xmit_buf)
705
                return 0;
706
 
707
        save_flags(flags);
708
        while (1) {
709
                cli();
710
                c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
711
                                   SERIAL_XMIT_SIZE - info->xmit_head));
712
                if (c <= 0)
713
                        break;
714
 
715
                if (from_user) {
716
                        down(&tmp_buf_sem);
717
                        memcpy_fromfs(tmp_buf, buf, c);
718
                        c = MIN(c, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
719
                                       SERIAL_XMIT_SIZE - info->xmit_head));
720
                        memcpy(info->xmit_buf + info->xmit_head, tmp_buf, c);
721
                        up(&tmp_buf_sem);
722
                } else
723
                        memcpy(info->xmit_buf + info->xmit_head, buf, c);
724
                info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
725
                info->xmit_cnt += c;
726
                restore_flags(flags);
727
                buf += c;
728
                count -= c;
729
                total += c;
730
        }
731
 
732
        if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
733
                /* Enable transmitter */
734
                cli();
735
#ifndef USE_INTS
736
                while(info->xmit_cnt) {
737
#endif
738
 
739
                USTCNT |= USTCNT_TXEN;
740
#ifdef USE_INTS
741
                USTCNT |= USTCNT_TX_INTR_MASK;
742
#else
743
                while (!(UTX & UTX_TX_AVAIL)) udelay(5);
744
#endif
745
                if (UTX & UTX_TX_AVAIL) {
746
                        UTX_TXDATA = info->xmit_buf[info->xmit_tail++];
747
                        info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
748
                        info->xmit_cnt--;
749
                }
750
 
751
#ifndef USE_INTS
752
                }
753
#endif
754
                restore_flags(flags);
755
        }
756
        restore_flags(flags);
757
        return total;
758
}
759
 
760
static int rs_write_room(struct tty_struct *tty)
761
{
762
        struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
763
        int     ret;
764
 
765
        if (serial_paranoia_check(info, tty->device, "rs_write_room"))
766
                return 0;
767
        ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
768
        if (ret < 0)
769
                ret = 0;
770
        return ret;
771
}
772
 
773
static int rs_chars_in_buffer(struct tty_struct *tty)
774
{
775
        struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
776
 
777
        if (serial_paranoia_check(info, tty->device, "rs_chars_in_buffer"))
778
                return 0;
779
        return info->xmit_cnt;
780
}
781
 
782
static void rs_flush_buffer(struct tty_struct *tty)
783
{
784
        struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
785
 
786
        if (serial_paranoia_check(info, tty->device, "rs_flush_buffer"))
787
                return;
788
        cli();
789
        info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
790
        sti();
791
        wake_up_interruptible(&tty->write_wait);
792
        if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
793
            tty->ldisc.write_wakeup)
794
                (tty->ldisc.write_wakeup)(tty);
795
}
796
 
797
/*
798
 * ------------------------------------------------------------
799
 * rs_throttle()
800
 *
801
 * This routine is called by the upper-layer tty layer to signal that
802
 * incoming characters should be throttled.
803
 * ------------------------------------------------------------
804
 */
805
static void rs_throttle(struct tty_struct * tty)
806
{
807
        struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
808
 
809
        if (serial_paranoia_check(info, tty->device, "rs_throttle"))
810
                return;
811
 
812
        if (I_IXOFF(tty))
813
                info->x_char = STOP_CHAR(tty);
814
 
815
        /* Turn off RTS line (do this atomic) */
816
}
817
 
818
static void rs_unthrottle(struct tty_struct * tty)
819
{
820
        struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
821
 
822
        if (serial_paranoia_check(info, tty->device, "rs_unthrottle"))
823
                return;
824
 
825
        if (I_IXOFF(tty)) {
826
                if (info->x_char)
827
                        info->x_char = 0;
828
                else
829
                        info->x_char = START_CHAR(tty);
830
        }
831
 
832
        /* Assert RTS line (do this atomic) */
833
}
834
 
835
/*
836
 * ------------------------------------------------------------
837
 * rs_ioctl() and friends
838
 * ------------------------------------------------------------
839
 */
840
 
841
static int get_serial_info(struct m68k_serial * info,
842
                           struct serial_struct * retinfo)
843
{
844
        struct serial_struct tmp;
845
 
846
        if (!retinfo)
847
                return -EFAULT;
848
        memset(&tmp, 0, sizeof(tmp));
849
        tmp.type = info->type;
850
        tmp.line = info->line;
851
        tmp.port = info->port;
852
        tmp.irq = info->irq;
853
        tmp.flags = info->flags;
854
        tmp.baud_base = info->baud_base;
855
        tmp.close_delay = info->close_delay;
856
        tmp.closing_wait = info->closing_wait;
857
        tmp.custom_divisor = info->custom_divisor;
858
        memcpy_tofs(retinfo,&tmp,sizeof(*retinfo));
859
        return 0;
860
}
861
 
862
static int set_serial_info(struct m68k_serial * info,
863
                           struct serial_struct * new_info)
864
{
865
        struct serial_struct new_serial;
866
        struct m68k_serial old_info;
867
        int                     retval = 0;
868
 
869
        if (!new_info)
870
                return -EFAULT;
871
        memcpy_fromfs(&new_serial,new_info,sizeof(new_serial));
872
        old_info = *info;
873
 
874
        if (!suser()) {
875
                if ((new_serial.baud_base != info->baud_base) ||
876
                    (new_serial.type != info->type) ||
877
                    (new_serial.close_delay != info->close_delay) ||
878
                    ((new_serial.flags & ~S_USR_MASK) !=
879
                     (info->flags & ~S_USR_MASK)))
880
                        return -EPERM;
881
                info->flags = ((info->flags & ~S_USR_MASK) |
882
                               (new_serial.flags & S_USR_MASK));
883
                info->custom_divisor = new_serial.custom_divisor;
884
                goto check_and_exit;
885
        }
886
 
887
        if (info->count > 1)
888
                return -EBUSY;
889
 
890
        /*
891
         * OK, past this point, all the error checking has been done.
892
         * At this point, we start making changes.....
893
         */
894
 
895
        info->baud_base = new_serial.baud_base;
896
        info->flags = ((info->flags & ~S_FLAGS) |
897
                        (new_serial.flags & S_FLAGS));
898
        info->type = new_serial.type;
899
        info->close_delay = new_serial.close_delay;
900
        info->closing_wait = new_serial.closing_wait;
901
 
902
check_and_exit:
903
        retval = startup(info);
904
        return retval;
905
}
906
 
907
/*
908
 * get_lsr_info - get line status register info
909
 *
910
 * Purpose: Let user call ioctl() to get info when the UART physically
911
 *          is emptied.  On bus types like RS485, the transmitter must
912
 *          release the bus after transmitting. This must be done when
913
 *          the transmit shift register is empty, not be done when the
914
 *          transmit holding register is empty.  This functionality
915
 *          allows an RS485 driver to be written in user space.
916
 */
917
static int get_lsr_info(struct m68k_serial * info, unsigned int *value)
918
{
919
        unsigned char status;
920
 
921
        cli();
922
#ifdef CONFIG_68328_SERIAL_RTS_CTS
923
        status = (UTX & UTX_CTS_STAT) ? 1 : 0;
924
#else
925
        status = 0;
926
#endif
927
        sti();
928
        put_user(status,value);
929
        return 0;
930
}
931
 
932
/*
933
 * This routine sends a break character out the serial port.
934
 */
935
static void send_break( struct m68k_serial * info, int duration)
936
{
937
        if (!info->port)
938
                return;
939
        current->state = TASK_INTERRUPTIBLE;
940
        current->timeout = jiffies + duration;
941
        cli();
942
#ifdef USE_INTS
943
        UTX |= UTX_SEND_BREAK;
944
        schedule();
945
        UTX &= ~UTX_SEND_BREAK;
946
#endif
947
        sti();
948
}
949
 
950
static int rs_ioctl(struct tty_struct *tty, struct file * file,
951
                    unsigned int cmd, unsigned long arg)
952
{
953
        int error;
954
        struct m68k_serial * info = (struct m68k_serial *)tty->driver_data;
955
        int retval;
956
 
957
        if (serial_paranoia_check(info, tty->device, "rs_ioctl"))
958
                return -ENODEV;
959
 
960
        if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
961
            (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD)  &&
962
            (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) {
963
                if (tty->flags & (1 << TTY_IO_ERROR))
964
                    return -EIO;
965
        }
966
 
967
        switch (cmd) {
968
                case TCSBRK:    /* SVID version: non-zero arg --> no break */
969
                        retval = tty_check_change(tty);
970
                        if (retval)
971
                                return retval;
972
                        tty_wait_until_sent(tty, 0);
973
                        if (!arg)
974
                                send_break(info, HZ/4); /* 1/4 second */
975
                        return 0;
976
                case TCSBRKP:   /* support for POSIX tcsendbreak() */
977
                        retval = tty_check_change(tty);
978
                        if (retval)
979
                                return retval;
980
                        tty_wait_until_sent(tty, 0);
981
                        send_break(info, arg ? arg*(HZ/10) : HZ/4);
982
                        return 0;
983
                case TIOCGSOFTCAR:
984
                        error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(long));
985
                        if (error)
986
                                return error;
987
                        put_fs_long(C_CLOCAL(tty) ? 1 : 0,
988
                                    (unsigned long *) arg);
989
                        return 0;
990
                case TIOCSSOFTCAR:
991
                        arg = get_fs_long((unsigned long *) arg);
992
                        tty->termios->c_cflag =
993
                                ((tty->termios->c_cflag & ~CLOCAL) |
994
                                 (arg ? CLOCAL : 0));
995
                        return 0;
996
                case TIOCGSERIAL:
997
                        error = verify_area(VERIFY_WRITE, (void *) arg,
998
                                                sizeof(struct serial_struct));
999
                        if (error)
1000
                                return error;
1001
                        return get_serial_info(info,
1002
                                               (struct serial_struct *) arg);
1003
                case TIOCSSERIAL:
1004
                        return set_serial_info(info,
1005
                                               (struct serial_struct *) arg);
1006
                case TIOCSERGETLSR: /* Get line status register */
1007
                        error = verify_area(VERIFY_WRITE, (void *) arg,
1008
                                sizeof(unsigned int));
1009
                        if (error)
1010
                                return error;
1011
                        else
1012
                            return get_lsr_info(info, (unsigned int *) arg);
1013
 
1014
                case TIOCSERGSTRUCT:
1015
                        error = verify_area(VERIFY_WRITE, (void *) arg,
1016
                                                sizeof(struct m68k_serial));
1017
                        if (error)
1018
                                return error;
1019
                        memcpy_tofs((struct m68k_serial *) arg,
1020
                                    info, sizeof(struct m68k_serial));
1021
                        return 0;
1022
 
1023
                default:
1024
                        return -ENOIOCTLCMD;
1025
                }
1026
        return 0;
1027
}
1028
 
1029
static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios)
1030
{
1031
        struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
1032
 
1033
        if (tty->termios->c_cflag == old_termios->c_cflag)
1034
                return;
1035
 
1036
        change_speed(info);
1037
 
1038
        if ((old_termios->c_cflag & CRTSCTS) &&
1039
            !(tty->termios->c_cflag & CRTSCTS)) {
1040
                tty->hw_stopped = 0;
1041
                rs_start(tty);
1042
        }
1043
 
1044
}
1045
 
1046
/*
1047
 * ------------------------------------------------------------
1048
 * rs_close()
1049
 *
1050
 * This routine is called when the serial port gets closed.  First, we
1051
 * wait for the last remaining data to be sent.  Then, we unlink its
1052
 * S structure from the interrupt chain if necessary, and we free
1053
 * that IRQ if nothing is left in the chain.
1054
 * ------------------------------------------------------------
1055
 */
1056
static void rs_close(struct tty_struct *tty, struct file * filp)
1057
{
1058
        struct m68k_serial * info = (struct m68k_serial *)tty->driver_data;
1059
        unsigned long flags;
1060
 
1061
        if (!info || serial_paranoia_check(info, tty->device, "rs_close"))
1062
                return;
1063
 
1064
        save_flags(flags); cli();
1065
 
1066
        if (tty_hung_up_p(filp)) {
1067
                restore_flags(flags);
1068
                return;
1069
        }
1070
 
1071
        if ((tty->count == 1) && (info->count != 1)) {
1072
                /*
1073
                 * Uh, oh.  tty->count is 1, which means that the tty
1074
                 * structure will be freed.  Info->count should always
1075
                 * be one in these conditions.  If it's greater than
1076
                 * one, we've got real problems, since it means the
1077
                 * serial port won't be shutdown.
1078
                 */
1079
                printk("rs_close: bad serial port count; tty->count is 1, "
1080
                       "info->count is %d\n", info->count);
1081
                info->count = 1;
1082
        }
1083
        if (--info->count < 0) {
1084
                printk("rs_close: bad serial port count for ttyS%d: %d\n",
1085
                       info->line, info->count);
1086
                info->count = 0;
1087
        }
1088
        if (info->count) {
1089
                restore_flags(flags);
1090
                return;
1091
        }
1092
        info->flags |= S_CLOSING;
1093
        /*
1094
         * Save the termios structure, since this port may have
1095
         * separate termios for callout and dialin.
1096
         */
1097
        if (info->flags & S_NORMAL_ACTIVE)
1098
                info->normal_termios = *tty->termios;
1099
        if (info->flags & S_CALLOUT_ACTIVE)
1100
                info->callout_termios = *tty->termios;
1101
        /*
1102
         * Now we wait for the transmit buffer to clear; and we notify
1103
         * the line discipline to only process XON/XOFF characters.
1104
         */
1105
        tty->closing = 1;
1106
        if (info->closing_wait != S_CLOSING_WAIT_NONE)
1107
                tty_wait_until_sent(tty, info->closing_wait);
1108
        /*
1109
         * At this point we stop accepting input.  To do this, we
1110
         * disable the receive line status interrupts, and tell the
1111
         * interrupt driver to stop checking the data ready bit in the
1112
         * line status register.
1113
         */
1114
 
1115
        USTCNT &= ~USTCNT_RXEN;
1116
        USTCNT &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK);
1117
 
1118
        shutdown(info);
1119
        if (tty->driver.flush_buffer)
1120
                tty->driver.flush_buffer(tty);
1121
        if (tty->ldisc.flush_buffer)
1122
                tty->ldisc.flush_buffer(tty);
1123
        tty->closing = 0;
1124
        info->event = 0;
1125
        info->tty = 0;
1126
        if (tty->ldisc.num != ldiscs[N_TTY].num) {
1127
                if (tty->ldisc.close)
1128
                        (tty->ldisc.close)(tty);
1129
                tty->ldisc = ldiscs[N_TTY];
1130
                tty->termios->c_line = N_TTY;
1131
                if (tty->ldisc.open)
1132
                        (tty->ldisc.open)(tty);
1133
        }
1134
        if (info->blocked_open) {
1135
                if (info->close_delay) {
1136
                        current->state = TASK_INTERRUPTIBLE;
1137
                        current->timeout = jiffies + info->close_delay;
1138
                        schedule();
1139
                }
1140
                wake_up_interruptible(&info->open_wait);
1141
        }
1142
        info->flags &= ~(S_NORMAL_ACTIVE|S_CALLOUT_ACTIVE|
1143
                         S_CLOSING);
1144
        wake_up_interruptible(&info->close_wait);
1145
        restore_flags(flags);
1146
}
1147
 
1148
/*
1149
 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1150
 */
1151
void rs_hangup(struct tty_struct *tty)
1152
{
1153
        struct m68k_serial * info = (struct m68k_serial *)tty->driver_data;
1154
 
1155
        if (serial_paranoia_check(info, tty->device, "rs_hangup"))
1156
                return;
1157
 
1158
        rs_flush_buffer(tty);
1159
        shutdown(info);
1160
        info->event = 0;
1161
        info->count = 0;
1162
        info->flags &= ~(S_NORMAL_ACTIVE|S_CALLOUT_ACTIVE);
1163
        info->tty = 0;
1164
        wake_up_interruptible(&info->open_wait);
1165
}
1166
 
1167
/*
1168
 * ------------------------------------------------------------
1169
 * rs_open() and friends
1170
 * ------------------------------------------------------------
1171
 */
1172
static int block_til_ready(struct tty_struct *tty, struct file * filp,
1173
                           struct m68k_serial *info)
1174
{
1175
        struct wait_queue wait = { current, NULL };
1176
        int             retval;
1177
        int             do_clocal = 0;
1178
 
1179
        /*
1180
         * If the device is in the middle of being closed, then block
1181
         * until it's done, and then try again.
1182
         */
1183
        if (info->flags & S_CLOSING) {
1184
                interruptible_sleep_on(&info->close_wait);
1185
#ifdef SERIAL_DO_RESTART
1186
                if (info->flags & S_HUP_NOTIFY)
1187
                        return -EAGAIN;
1188
                else
1189
                        return -ERESTARTSYS;
1190
#else
1191
                return -EAGAIN;
1192
#endif
1193
        }
1194
 
1195
        /*
1196
         * If this is a callout device, then just make sure the normal
1197
         * device isn't being used.
1198
         */
1199
        if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
1200
                if (info->flags & S_NORMAL_ACTIVE)
1201
                        return -EBUSY;
1202
                if ((info->flags & S_CALLOUT_ACTIVE) &&
1203
                    (info->flags & S_SESSION_LOCKOUT) &&
1204
                    (info->session != current->session))
1205
                    return -EBUSY;
1206
                if ((info->flags & S_CALLOUT_ACTIVE) &&
1207
                    (info->flags & S_PGRP_LOCKOUT) &&
1208
                    (info->pgrp != current->pgrp))
1209
                    return -EBUSY;
1210
                info->flags |= S_CALLOUT_ACTIVE;
1211
                return 0;
1212
        }
1213
 
1214
        /*
1215
         * If non-blocking mode is set, or the port is not enabled,
1216
         * then make the check up front and then exit.
1217
         */
1218
        if ((filp->f_flags & O_NONBLOCK) ||
1219
            (tty->flags & (1 << TTY_IO_ERROR))) {
1220
                if (info->flags & S_CALLOUT_ACTIVE)
1221
                        return -EBUSY;
1222
                info->flags |= S_NORMAL_ACTIVE;
1223
                return 0;
1224
        }
1225
 
1226
        if (info->flags & S_CALLOUT_ACTIVE) {
1227
                if (info->normal_termios.c_cflag & CLOCAL)
1228
                        do_clocal = 1;
1229
        } else {
1230
                if (tty->termios->c_cflag & CLOCAL)
1231
                        do_clocal = 1;
1232
        }
1233
 
1234
        /*
1235
         * Block waiting for the carrier detect and the line to become
1236
         * free (i.e., not in use by the callout).  While we are in
1237
         * this loop, info->count is dropped by one, so that
1238
         * rs_close() knows when to free things.  We restore it upon
1239
         * exit, either normal or abnormal.
1240
         */
1241
        retval = 0;
1242
        add_wait_queue(&info->open_wait, &wait);
1243
 
1244
        info->count--;
1245
        info->blocked_open++;
1246
        while (1) {
1247
                cli();
1248
                if (!(info->flags & S_CALLOUT_ACTIVE))
1249
                        m68k_rtsdtr(info, 1);
1250
                sti();
1251
                current->state = TASK_INTERRUPTIBLE;
1252
                if (tty_hung_up_p(filp) ||
1253
                    !(info->flags & S_INITIALIZED)) {
1254
#ifdef SERIAL_DO_RESTART
1255
                        if (info->flags & S_HUP_NOTIFY)
1256
                                retval = -EAGAIN;
1257
                        else
1258
                                retval = -ERESTARTSYS;
1259
#else
1260
                        retval = -EAGAIN;
1261
#endif
1262
                        break;
1263
                }
1264
                if (!(info->flags & S_CALLOUT_ACTIVE) &&
1265
                    !(info->flags & S_CLOSING) && do_clocal)
1266
                        break;
1267
                if (current->signal & ~current->blocked) {
1268
                        retval = -ERESTARTSYS;
1269
                        break;
1270
                }
1271
                schedule();
1272
        }
1273
        current->state = TASK_RUNNING;
1274
        remove_wait_queue(&info->open_wait, &wait);
1275
        if (!tty_hung_up_p(filp))
1276
                info->count++;
1277
        info->blocked_open--;
1278
 
1279
        if (retval)
1280
                return retval;
1281
        info->flags |= S_NORMAL_ACTIVE;
1282
        return 0;
1283
}
1284
 
1285
/*
1286
 * This routine is called whenever a serial port is opened.  It
1287
 * enables interrupts for a serial port, linking in its S structure into
1288
 * the IRQ chain.   It also performs the serial-specific
1289
 * initialization for the tty structure.
1290
 */
1291
int rs_open(struct tty_struct *tty, struct file * filp)
1292
{
1293
        struct m68k_serial      *info;
1294
        int                     retval, line;
1295
 
1296
        line = MINOR(tty->device) - tty->driver.minor_start;
1297
 
1298
        if (line != 0) /* we have exactly one */
1299
                return -ENODEV;
1300
 
1301
        info = &m68k_soft;
1302
 
1303
        if (serial_paranoia_check(info, tty->device, "rs_open"))
1304
                return -ENODEV;
1305
 
1306
        info->count++;
1307
        tty->driver_data = info;
1308
        info->tty = tty;
1309
 
1310
        /*
1311
         * Start up serial port
1312
         */
1313
        retval = startup(info);
1314
        if (retval)
1315
                return retval;
1316
 
1317
        retval = block_til_ready(tty, filp, info);
1318
        if (retval) {
1319
                return retval;
1320
        }
1321
 
1322
        if ((info->count == 1) && (info->flags & S_SPLIT_TERMIOS)) {
1323
                if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
1324
                        *tty->termios = info->normal_termios;
1325
                else
1326
                        *tty->termios = info->callout_termios;
1327
                change_speed(info);
1328
        }
1329
 
1330
        info->session = current->session;
1331
        info->pgrp = current->pgrp;
1332
 
1333
        return 0;
1334
}
1335
 
1336
/* Finally, routines used to initialize the serial driver. */
1337
 
1338
static void show_serial_version(void)
1339
{
1340
        printk("MC68328 serial driver version 1.00\n");
1341
}
1342
 
1343
extern void register_console(void (*proc)(const char *));
1344
 
1345
volatile int test_done;
1346
 
1347
/* rs_init inits the driver */
1348
int rs68328_init(void)
1349
{
1350
        int flags;
1351
        struct m68k_serial *info;
1352
 
1353
        /* Setup base handler, and timer table. */
1354
        init_bh(SERIAL_BH, do_serial_bh);
1355
        timer_table[RS_TIMER].fn = rs_timer;
1356
        timer_table[RS_TIMER].expires = 0;
1357
 
1358
        show_serial_version();
1359
 
1360
        /* Initialize the tty_driver structure */
1361
        /* SPARC: Not all of this is exactly right for us. */
1362
 
1363
        memset(&serial_driver, 0, sizeof(struct tty_driver));
1364
        serial_driver.magic = TTY_DRIVER_MAGIC;
1365
        serial_driver.name = "ttyS";
1366
        serial_driver.major = TTY_MAJOR;
1367
        serial_driver.minor_start = 64;
1368
        serial_driver.num = 1;
1369
        serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
1370
        serial_driver.subtype = SERIAL_TYPE_NORMAL;
1371
        serial_driver.init_termios = tty_std_termios;
1372
 
1373
 
1374
        serial_driver.init_termios.c_cflag =
1375
#if   defined(CONFIG_PILOT)
1376
                B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1377
#elif defined(CONFIG_UCSIMM)
1378
                B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1379
#elif defined(CONFIG_M68EZ328ADS)
1380
                B115200 | CS8 | CREAD | HUPCL | CLOCAL;
1381
#elif defined(CONFIG_ALMA_ANS)
1382
                B115200 | CS8 | CREAD | HUPCL | CLOCAL;
1383
#else 
1384
#error  Please, define the default console settings for your board
1385
#endif
1386
 
1387
        serial_driver.flags = TTY_DRIVER_REAL_RAW;
1388
        serial_driver.refcount = &serial_refcount;
1389
        serial_driver.table = serial_table;
1390
        serial_driver.termios = serial_termios;
1391
        serial_driver.termios_locked = serial_termios_locked;
1392
 
1393
        serial_driver.open = rs_open;
1394
        serial_driver.close = rs_close;
1395
        serial_driver.write = rs_write;
1396
        serial_driver.flush_chars = rs_flush_chars;
1397
        serial_driver.write_room = rs_write_room;
1398
        serial_driver.chars_in_buffer = rs_chars_in_buffer;
1399
        serial_driver.flush_buffer = rs_flush_buffer;
1400
        serial_driver.ioctl = rs_ioctl;
1401
        serial_driver.throttle = rs_throttle;
1402
        serial_driver.unthrottle = rs_unthrottle;
1403
        serial_driver.set_termios = rs_set_termios;
1404
        serial_driver.stop = rs_stop;
1405
        serial_driver.start = rs_start;
1406
        serial_driver.hangup = rs_hangup;
1407
        serial_driver.set_ldisc = rs_set_ldisc;
1408
 
1409
        /*
1410
         * The callout device is just like normal device except for
1411
         * major number and the subtype code.
1412
         */
1413
        callout_driver = serial_driver;
1414
        callout_driver.name = "cua";
1415
        callout_driver.major = TTYAUX_MAJOR;
1416
        callout_driver.subtype = SERIAL_TYPE_CALLOUT;
1417
 
1418
        if (tty_register_driver(&serial_driver))
1419
                panic("Couldn't register serial driver\n");
1420
        if (tty_register_driver(&callout_driver))
1421
                panic("Couldn't register callout driver\n");
1422
 
1423
        save_flags(flags); cli();
1424
 
1425
        info = &m68k_soft;
1426
        info->magic = SERIAL_MAGIC;
1427
        info->port = 0xfffff900;
1428
        info->tty = 0;
1429
        info->irq = 0x40;
1430
        info->custom_divisor = 16;
1431
        info->close_delay = 50;
1432
        info->closing_wait = 3000;
1433
        info->x_char = 0;
1434
        info->event = 0;
1435
        info->count = 0;
1436
        info->blocked_open = 0;
1437
        info->tqueue.routine = do_softint;
1438
        info->tqueue.data = info;
1439
        info->tqueue_hangup.routine = do_serial_hangup;
1440
        info->tqueue_hangup.data = info;
1441
        info->callout_termios =callout_driver.init_termios;
1442
        info->normal_termios = serial_driver.init_termios;
1443
        info->open_wait = 0;
1444
        info->close_wait = 0;
1445
        info->line = 0;
1446
        info->is_cons = 1; /* Means shortcuts work */
1447
 
1448
        printk("%s%d at 0x%08x (irq = %d)", serial_driver.name, info->line,
1449
               info->port, info->irq);
1450
                printk(" is a builtin MC68328 UART\n");
1451
 
1452
        if (request_irq(IRQ_MACHSPEC | UART_IRQ_NUM,
1453
                        rs_interrupt,
1454
                        IRQ_FLG_STD,
1455
                        "M68328_UART", NULL))
1456
                panic("Unable to attach 68328 serial interrupt\n");
1457
        restore_flags(flags);
1458
        return 0;
1459
}
1460
 
1461
/*
1462
 * register_serial and unregister_serial allows for serial ports to be
1463
 * configured at run-time, to support PCMCIA modems.
1464
 */
1465
/* SPARC: Unused at this time, just here to make things link. */
1466
int register_serial(struct serial_struct *req)
1467
{
1468
        return -1;
1469
}
1470
 
1471
void unregister_serial(int line)
1472
{
1473
        return;
1474
}

powered by: WebSVN 2.1.0

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