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

Subversion Repositories or1k

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * linux/drivers/char/serial167.c
3
 *
4
 * Driver for MVME166/7 board serial ports, which are via a CD2401.
5
 * Based very much on cyclades.c.
6
 *
7
 * MVME166/7 work by Richard Hirst [richard@sleepie.demon.co.uk]
8
 *
9
 * ==============================================================
10
 *
11
 * static char rcsid[] =
12
 * "$Revision: 1.1.1.1 $$Date: 2004-04-15 02:00:19 $";
13
 *
14
 *  linux/kernel/cyclades.c
15
 *
16
 * Maintained by Marcio Saito (cyclades@netcom.com) and
17
 * Randolph Bentson (bentson@grieg.seaslug.org)
18
 *
19
 * Much of the design and some of the code came from serial.c
20
 * which was copyright (C) 1991, 1992  Linus Torvalds.  It was
21
 * extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92,
22
 * and then fixed as suggested by Michael K. Johnson 12/12/92.
23
 *
24
 * This version does not support shared irq's.
25
 *
26
 * This module exports the following rs232 io functions:
27
 *   int cy_init(void);
28
 *   int  cy_open(struct tty_struct *tty, struct file *filp);
29
 *
30
 * $Log: not supported by cvs2svn $
31
 * Revision 1.36.1.4  1995/03/29  06:14:14  bentson
32
 * disambiguate between Cyclom-16Y and Cyclom-32Ye;
33
 *
34
 * Changes:
35
 *
36
 * 200 lines of changes record removed - RGH 11-10-95, starting work on
37
 * converting this to drive serial ports on mvme166 (cd2401).
38
 *
39
 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 2000/08/25
40
 * - get rid of verify_area
41
 * - use get_user to access memory from userspace in set_threshold,
42
 *   set_default_threshold and set_timeout
43
 * - don't use the panic function in serial167_init
44
 * - do resource release on failure on serial167_init
45
 * - include missing restore_flags in mvme167_serial_console_setup
46
 */
47
 
48
#include <linux/config.h>
49
#include <linux/errno.h>
50
#include <linux/signal.h>
51
#include <linux/sched.h>
52
#include <linux/timer.h>
53
#include <linux/tty.h>
54
#include <linux/interrupt.h>
55
#include <linux/serial.h>
56
#include <linux/serialP.h>
57
#include <linux/string.h>
58
#include <linux/fcntl.h>
59
#include <linux/ptrace.h>
60
#include <linux/serial167.h>
61
#include <linux/delay.h>
62
#include <linux/major.h>
63
#include <linux/mm.h>
64
#include <linux/console.h>
65
#include <linux/module.h>
66
 
67
#include <asm/system.h>
68
#include <asm/io.h>
69
#include <asm/segment.h>
70
#include <asm/bitops.h>
71
#include <asm/mvme16xhw.h>
72
#include <asm/bootinfo.h>
73
#include <asm/setup.h>
74
 
75
#include <linux/types.h>
76
#include <linux/kernel.h>
77
 
78
#include <linux/version.h>
79
#include <asm/uaccess.h>
80
#include <linux/init.h>
81
 
82
#define SERIAL_PARANOIA_CHECK
83
#undef  SERIAL_DEBUG_OPEN
84
#undef  SERIAL_DEBUG_THROTTLE
85
#undef  SERIAL_DEBUG_OTHER
86
#undef  SERIAL_DEBUG_IO
87
#undef  SERIAL_DEBUG_COUNT
88
#undef  SERIAL_DEBUG_DTR
89
#undef  CYCLOM_16Y_HACK
90
#define  CYCLOM_ENABLE_MONITORING
91
 
92
#ifndef MIN
93
#define MIN(a,b)        ((a) < (b) ? (a) : (b))
94
#endif
95
 
96
#define WAKEUP_CHARS 256
97
 
98
#define STD_COM_FLAGS (0)
99
 
100
#define SERIAL_TYPE_NORMAL  1
101
#define SERIAL_TYPE_CALLOUT 2
102
 
103
 
104
DECLARE_TASK_QUEUE(tq_cyclades);
105
 
106
struct tty_driver cy_serial_driver, cy_callout_driver;
107
extern int serial_console;
108
static struct cyclades_port *serial_console_info = NULL;
109
static unsigned int serial_console_cflag = 0;
110
u_char initial_console_speed;
111
 
112
/* Base address of cd2401 chip on mvme166/7 */
113
 
114
#define BASE_ADDR (0xfff45000)
115
#define pcc2chip        ((volatile u_char *)0xfff42000)
116
#define PccSCCMICR      0x1d
117
#define PccSCCTICR      0x1e
118
#define PccSCCRICR      0x1f
119
#define PccTPIACKR      0x25
120
#define PccRPIACKR      0x27
121
#define PccIMLR         0x3f
122
 
123
/* This is the per-port data structure */
124
struct cyclades_port cy_port[] = {
125
      /* CARD#  */
126
        {-1 },      /* ttyS0 */
127
        {-1 },      /* ttyS1 */
128
        {-1 },      /* ttyS2 */
129
        {-1 },      /* ttyS3 */
130
};
131
#define NR_PORTS        (sizeof(cy_port)/sizeof(struct cyclades_port))
132
 
133
static int serial_refcount;
134
 
135
static struct tty_struct *serial_table[NR_PORTS];
136
static struct termios *serial_termios[NR_PORTS];
137
static struct termios *serial_termios_locked[NR_PORTS];
138
 
139
 
140
/*
141
 * tmp_buf is used as a temporary buffer by serial_write.  We need to
142
 * lock it in case the copy_from_user blocks while swapping in a page,
143
 * and some other program tries to do a serial write at the same time.
144
 * Since the lock will only come under contention when the system is
145
 * swapping and available memory is low, it makes sense to share one
146
 * buffer across all the serial ports, since it significantly saves
147
 * memory if large numbers of serial ports are open.
148
 */
149
static unsigned char *tmp_buf = 0;
150
DECLARE_MUTEX(tmp_buf_sem);
151
 
152
/*
153
 * This is used to look up the divisor speeds and the timeouts
154
 * We're normally limited to 15 distinct baud rates.  The extra
155
 * are accessed via settings in info->flags.
156
 *         0,     1,     2,     3,     4,     5,     6,     7,     8,     9,
157
 *        10,    11,    12,    13,    14,    15,    16,    17,    18,    19,
158
 *                                                  HI            VHI
159
 */
160
static int baud_table[] = {
161
           0,    50,    75,   110,   134,   150,   200,   300,   600,  1200,
162
        1800,  2400,  4800,  9600, 19200, 38400, 57600, 76800,115200,150000,
163
        0};
164
 
165
#if 0
166
static char baud_co[] = {  /* 25 MHz clock option table */
167
        /* value =>    00    01   02    03    04 */
168
        /* divide by    8    32   128   512  2048 */
169
        0x00,  0x04,  0x04,  0x04,  0x04,  0x04,  0x03,  0x03,  0x03,  0x02,
170
        0x02,  0x02,  0x01,  0x01,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00};
171
 
172
static char baud_bpr[] = {  /* 25 MHz baud rate period table */
173
        0x00,  0xf5,  0xa3,  0x6f,  0x5c,  0x51,  0xf5,  0xa3,  0x51,  0xa3,
174
        0x6d,  0x51,  0xa3,  0x51,  0xa3,  0x51,  0x36,  0x29,  0x1b,  0x15};
175
#endif
176
 
177
/* I think 166 brd clocks 2401 at 20MHz.... */
178
 
179
/* These values are written directly to tcor, and >> 5 for writing to rcor */
180
static u_char baud_co[] = {  /* 20 MHz clock option table */
181
        0x00,  0x80,  0x80,  0x80,  0x80,  0x80,  0x80,  0x60,  0x60,  0x40,
182
        0x40,  0x40,  0x20,  0x20,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00};
183
 
184
/* These values written directly to tbpr/rbpr */
185
static u_char baud_bpr[] = {  /* 20 MHz baud rate period table */
186
        0x00,  0xc0,  0x80,  0x58,  0x6c,  0x40,  0xc0,  0x81,  0x40,  0x81,
187
        0x57,  0x40,  0x81,  0x40,  0x81,  0x40,  0x2b,  0x20,  0x15,  0x10};
188
 
189
static u_char baud_cor4[] = {  /* receive threshold */
190
        0x0a,  0x0a,  0x0a,  0x0a,  0x0a,  0x0a,  0x0a,  0x0a,  0x0a,  0x0a,
191
        0x0a,  0x0a,  0x0a,  0x09,  0x09,  0x08,  0x08,  0x08,  0x08,  0x07};
192
 
193
 
194
 
195
static void shutdown(struct cyclades_port *);
196
static int startup (struct cyclades_port *);
197
static void cy_throttle(struct tty_struct *);
198
static void cy_unthrottle(struct tty_struct *);
199
static void config_setup(struct cyclades_port *);
200
extern void console_print(const char *);
201
#ifdef CYCLOM_SHOW_STATUS
202
static void show_status(int);
203
#endif
204
 
205
#ifdef CONFIG_REMOTE_DEBUG
206
static void debug_setup(void);
207
void queueDebugChar (int c);
208
int getDebugChar(void);
209
 
210
#define DEBUG_PORT      1
211
#define DEBUG_LEN       256
212
 
213
typedef struct {
214
        int     in;
215
        int     out;
216
        unsigned char   buf[DEBUG_LEN];
217
} debugq;
218
 
219
debugq debugiq;
220
#endif
221
 
222
/*
223
 * I have my own version of udelay(), as it is needed when initialising
224
 * the chip, before the delay loop has been calibrated.  Should probably
225
 * reference one of the vmechip2 or pccchip2 counter for an accurate
226
 * delay, but this wild guess will do for now.
227
 */
228
 
229
void my_udelay (long us)
230
{
231
        u_char x;
232
        volatile u_char *p = &x;
233
        int i;
234
 
235
        while (us--)
236
                for (i = 100; i; i--)
237
                        x |= *p;
238
}
239
 
240
static inline int
241
serial_paranoia_check(struct cyclades_port *info,
242
                        dev_t device, const char *routine)
243
{
244
#ifdef SERIAL_PARANOIA_CHECK
245
    static const char *badmagic =
246
        "Warning: bad magic number for serial struct (%d, %d) in %s\n";
247
    static const char *badinfo =
248
        "Warning: null cyclades_port for (%d, %d) in %s\n";
249
    static const char *badrange =
250
        "Warning: cyclades_port out of range for (%d, %d) in %s\n";
251
 
252
    if (!info) {
253
        printk(badinfo, MAJOR(device), MINOR(device), routine);
254
        return 1;
255
    }
256
 
257
    if( (long)info < (long)(&cy_port[0])
258
    || (long)(&cy_port[NR_PORTS]) < (long)info ){
259
        printk(badrange, MAJOR(device), MINOR(device), routine);
260
        return 1;
261
    }
262
 
263
    if (info->magic != CYCLADES_MAGIC) {
264
        printk(badmagic, MAJOR(device), MINOR(device), routine);
265
        return 1;
266
    }
267
#endif
268
        return 0;
269
} /* serial_paranoia_check */
270
 
271
#if 0
272
/* The following diagnostic routines allow the driver to spew
273
   information on the screen, even (especially!) during interrupts.
274
 */
275
void
276
SP(char *data){
277
  unsigned long flags;
278
    save_flags(flags); cli();
279
        console_print(data);
280
    restore_flags(flags);
281
}
282
char scrn[2];
283
void
284
CP(char data){
285
  unsigned long flags;
286
    save_flags(flags); cli();
287
        scrn[0] = data;
288
        console_print(scrn);
289
    restore_flags(flags);
290
}/* CP */
291
 
292
void CP1(int data) { (data<10)?  CP(data+'0'): CP(data+'A'-10); }/* CP1 */
293
void CP2(int data) { CP1((data>>4) & 0x0f); CP1( data & 0x0f); }/* CP2 */
294
void CP4(int data) { CP2((data>>8) & 0xff); CP2(data & 0xff); }/* CP4 */
295
void CP8(long data) { CP4((data>>16) & 0xffff); CP4(data & 0xffff); }/* CP8 */
296
#endif
297
 
298
/* This routine waits up to 1000 micro-seconds for the previous
299
   command to the Cirrus chip to complete and then issues the
300
   new command.  An error is returned if the previous command
301
   didn't finish within the time limit.
302
 */
303
u_short
304
write_cy_cmd(volatile u_char *base_addr, u_char cmd)
305
{
306
  unsigned long flags;
307
  volatile int  i;
308
 
309
    save_flags(flags); cli();
310
        /* Check to see that the previous command has completed */
311
        for(i = 0 ; i < 100 ; i++){
312
            if (base_addr[CyCCR] == 0){
313
                break;
314
            }
315
            my_udelay(10L);
316
        }
317
        /* if the CCR never cleared, the previous command
318
            didn't finish within the "reasonable time" */
319
        if ( i == 10 ) {
320
            restore_flags(flags);
321
            return (-1);
322
        }
323
 
324
        /* Issue the new command */
325
        base_addr[CyCCR] = cmd;
326
    restore_flags(flags);
327
    return(0);
328
} /* write_cy_cmd */
329
 
330
 
331
/* cy_start and cy_stop provide software output flow control as a
332
   function of XON/XOFF, software CTS, and other such stuff. */
333
 
334
static void
335
cy_stop(struct tty_struct *tty)
336
{
337
  struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
338
  volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
339
  int channel;
340
  unsigned long flags;
341
 
342
#ifdef SERIAL_DEBUG_OTHER
343
    printk("cy_stop ttyS%d\n", info->line); /* */
344
#endif
345
 
346
    if (serial_paranoia_check(info, tty->device, "cy_stop"))
347
        return;
348
 
349
    channel = info->line;
350
 
351
    save_flags(flags); cli();
352
        base_addr[CyCAR] = (u_char)(channel); /* index channel */
353
        base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
354
    restore_flags(flags);
355
 
356
    return;
357
} /* cy_stop */
358
 
359
static void
360
cy_start(struct tty_struct *tty)
361
{
362
  struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
363
  volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
364
  int channel;
365
  unsigned long flags;
366
 
367
#ifdef SERIAL_DEBUG_OTHER
368
    printk("cy_start ttyS%d\n", info->line); /* */
369
#endif
370
 
371
    if (serial_paranoia_check(info, tty->device, "cy_start"))
372
        return;
373
 
374
    channel = info->line;
375
 
376
    save_flags(flags); cli();
377
        base_addr[CyCAR] = (u_char)(channel);
378
        base_addr[CyIER] |= CyTxMpty;
379
    restore_flags(flags);
380
 
381
    return;
382
} /* cy_start */
383
 
384
 
385
/*
386
 * This routine is used by the interrupt handler to schedule
387
 * processing in the software interrupt portion of the driver
388
 * (also known as the "bottom half").  This can be called any
389
 * number of times for any channel without harm.
390
 */
391
static inline void
392
cy_sched_event(struct cyclades_port *info, int event)
393
{
394
    info->event |= 1 << event; /* remember what kind of event and who */
395
    queue_task(&info->tqueue, &tq_cyclades); /* it belongs to */
396
    mark_bh(CYCLADES_BH);                       /* then trigger event */
397
} /* cy_sched_event */
398
 
399
 
400
/* The real interrupt service routines are called
401
   whenever the card wants its hand held--chars
402
   received, out buffer empty, modem change, etc.
403
 */
404
static void
405
cd2401_rxerr_interrupt(int irq, void *dev_id, struct pt_regs *fp)
406
{
407
    struct tty_struct *tty;
408
    struct cyclades_port *info;
409
    volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
410
    unsigned char err, rfoc;
411
    int channel;
412
    char data;
413
 
414
    /* determine the channel and change to that context */
415
    channel = (u_short ) (base_addr[CyLICR] >> 2);
416
    info = &cy_port[channel];
417
    info->last_active = jiffies;
418
 
419
    if ((err = base_addr[CyRISR]) & CyTIMEOUT) {
420
        /* This is a receive timeout interrupt, ignore it */
421
        base_addr[CyREOIR] = CyNOTRANS;
422
        return;
423
    }
424
 
425
    /* Read a byte of data if there is any - assume the error
426
     * is associated with this character */
427
 
428
    if ((rfoc = base_addr[CyRFOC]) != 0)
429
        data = base_addr[CyRDR];
430
    else
431
        data = 0;
432
 
433
    /* if there is nowhere to put the data, discard it */
434
    if(info->tty == 0) {
435
        base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
436
        return;
437
    }
438
    else { /* there is an open port for this data */
439
        tty = info->tty;
440
        if(err & info->ignore_status_mask){
441
            base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
442
            return;
443
        }
444
        if (tty->flip.count < TTY_FLIPBUF_SIZE){
445
            tty->flip.count++;
446
            if (err & info->read_status_mask){
447
                if(err & CyBREAK){
448
                    *tty->flip.flag_buf_ptr++ = TTY_BREAK;
449
                    *tty->flip.char_buf_ptr++ = data;
450
                    if (info->flags & ASYNC_SAK){
451
                        do_SAK(tty);
452
                    }
453
                }else if(err & CyFRAME){
454
                    *tty->flip.flag_buf_ptr++ = TTY_FRAME;
455
                    *tty->flip.char_buf_ptr++ = data;
456
                }else if(err & CyPARITY){
457
                    *tty->flip.flag_buf_ptr++ = TTY_PARITY;
458
                    *tty->flip.char_buf_ptr++ = data;
459
                }else if(err & CyOVERRUN){
460
                    *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
461
                    *tty->flip.char_buf_ptr++ = 0;
462
                    /*
463
                       If the flip buffer itself is
464
                       overflowing, we still loose
465
                       the next incoming character.
466
                     */
467
                    if(tty->flip.count < TTY_FLIPBUF_SIZE){
468
                        tty->flip.count++;
469
                        *tty->flip.flag_buf_ptr++ = TTY_NORMAL;
470
                        *tty->flip.char_buf_ptr++ = data;
471
                    }
472
                /* These two conditions may imply */
473
                /* a normal read should be done. */
474
                /* else if(data & CyTIMEOUT) */
475
                /* else if(data & CySPECHAR) */
476
                }else{
477
                    *tty->flip.flag_buf_ptr++ = 0;
478
                    *tty->flip.char_buf_ptr++ = 0;
479
                }
480
            }else{
481
                *tty->flip.flag_buf_ptr++ = 0;
482
                *tty->flip.char_buf_ptr++ = 0;
483
            }
484
        }else{
485
            /* there was a software buffer overrun
486
               and nothing could be done about it!!! */
487
        }
488
    }
489
    queue_task(&tty->flip.tqueue, &tq_timer);
490
    /* end of service */
491
    base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
492
} /* cy_rxerr_interrupt */
493
 
494
static void
495
cd2401_modem_interrupt(int irq, void *dev_id, struct pt_regs *fp)
496
{
497
    struct cyclades_port *info;
498
    volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
499
    int channel;
500
    int mdm_change;
501
    int mdm_status;
502
 
503
 
504
    /* determine the channel and change to that context */
505
    channel = (u_short ) (base_addr[CyLICR] >> 2);
506
    info = &cy_port[channel];
507
    info->last_active = jiffies;
508
 
509
    mdm_change = base_addr[CyMISR];
510
    mdm_status = base_addr[CyMSVR1];
511
 
512
    if(info->tty == 0){ /* nowhere to put the data, ignore it */
513
        ;
514
    }else{
515
        if((mdm_change & CyDCD)
516
        && (info->flags & ASYNC_CHECK_CD)){
517
            if(mdm_status & CyDCD){
518
/* CP('!'); */
519
                cy_sched_event(info, Cy_EVENT_OPEN_WAKEUP);
520
            }else if(!((info->flags & ASYNC_CALLOUT_ACTIVE)
521
                     &&(info->flags & ASYNC_CALLOUT_NOHUP))){
522
/* CP('@'); */
523
                cy_sched_event(info, Cy_EVENT_HANGUP);
524
            }
525
        }
526
        if((mdm_change & CyCTS)
527
        && (info->flags & ASYNC_CTS_FLOW)){
528
            if(info->tty->stopped){
529
                if(mdm_status & CyCTS){
530
                    /* !!! cy_start isn't used because... */
531
                    info->tty->stopped = 0;
532
                    base_addr[CyIER] |= CyTxMpty;
533
                    cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
534
                }
535
            }else{
536
                if(!(mdm_status & CyCTS)){
537
                    /* !!! cy_stop isn't used because... */
538
                    info->tty->stopped = 1;
539
                    base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
540
                }
541
            }
542
        }
543
        if(mdm_status & CyDSR){
544
        }
545
    }
546
    base_addr[CyMEOIR] = 0;
547
} /* cy_modem_interrupt */
548
 
549
static void
550
cd2401_tx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
551
{
552
    struct cyclades_port *info;
553
    volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
554
    int channel;
555
    int char_count, saved_cnt;
556
    int outch;
557
 
558
    /* determine the channel and change to that context */
559
    channel = (u_short ) (base_addr[CyLICR] >> 2);
560
 
561
#ifdef CONFIG_REMOTE_DEBUG
562
    if (channel == DEBUG_PORT) {
563
        panic ("TxInt on debug port!!!");
564
    }
565
#endif
566
 
567
    info = &cy_port[channel];
568
 
569
    /* validate the port number (as configured and open) */
570
    if( (channel < 0) || (NR_PORTS <= channel) ){
571
        base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
572
        base_addr[CyTEOIR] = CyNOTRANS;
573
        return;
574
    }
575
    info->last_active = jiffies;
576
    if(info->tty == 0){
577
        base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
578
        if (info->xmit_cnt < WAKEUP_CHARS) {
579
            cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
580
        }
581
        base_addr[CyTEOIR] = CyNOTRANS;
582
        return;
583
    }
584
 
585
    /* load the on-chip space available for outbound data */
586
    saved_cnt = char_count = base_addr[CyTFTC];
587
 
588
    if(info->x_char) { /* send special char */
589
        outch = info->x_char;
590
        base_addr[CyTDR] = outch;
591
        char_count--;
592
        info->x_char = 0;
593
    }
594
 
595
    if (info->x_break){
596
        /*  The Cirrus chip requires the "Embedded Transmit
597
            Commands" of start break, delay, and end break
598
            sequences to be sent.  The duration of the
599
            break is given in TICs, which runs at HZ
600
            (typically 100) and the PPR runs at 200 Hz,
601
            so the delay is duration * 200/HZ, and thus a
602
            break can run from 1/100 sec to about 5/4 sec.
603
            Need to check these values - RGH 141095.
604
         */
605
        base_addr[CyTDR] = 0; /* start break */
606
        base_addr[CyTDR] = 0x81;
607
        base_addr[CyTDR] = 0; /* delay a bit */
608
        base_addr[CyTDR] = 0x82;
609
        base_addr[CyTDR] = info->x_break*200/HZ;
610
        base_addr[CyTDR] = 0; /* terminate break */
611
        base_addr[CyTDR] = 0x83;
612
        char_count -= 7;
613
        info->x_break = 0;
614
    }
615
 
616
    while (char_count > 0){
617
        if (!info->xmit_cnt){
618
            base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
619
            break;
620
        }
621
        if (info->xmit_buf == 0){
622
            base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
623
            break;
624
        }
625
        if (info->tty->stopped || info->tty->hw_stopped){
626
            base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
627
            break;
628
        }
629
        /* Because the Embedded Transmit Commands have been
630
           enabled, we must check to see if the escape
631
           character, NULL, is being sent.  If it is, we
632
           must ensure that there is room for it to be
633
           doubled in the output stream.  Therefore we
634
           no longer advance the pointer when the character
635
           is fetched, but rather wait until after the check
636
           for a NULL output character. (This is necessary
637
           because there may not be room for the two chars
638
           needed to send a NULL.
639
         */
640
        outch = info->xmit_buf[info->xmit_tail];
641
        if( outch ){
642
            info->xmit_cnt--;
643
            info->xmit_tail = (info->xmit_tail + 1)
644
                                      & (PAGE_SIZE - 1);
645
            base_addr[CyTDR] = outch;
646
            char_count--;
647
        }else{
648
            if(char_count > 1){
649
                info->xmit_cnt--;
650
                info->xmit_tail = (info->xmit_tail + 1)
651
                                          & (PAGE_SIZE - 1);
652
                base_addr[CyTDR] = outch;
653
                base_addr[CyTDR] = 0;
654
                char_count--;
655
                char_count--;
656
            }else{
657
                break;
658
            }
659
        }
660
    }
661
 
662
    if (info->xmit_cnt < WAKEUP_CHARS) {
663
        cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
664
    }
665
    base_addr[CyTEOIR] = (char_count != saved_cnt) ? 0 : CyNOTRANS;
666
} /* cy_tx_interrupt */
667
 
668
static void
669
cd2401_rx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
670
{
671
    struct tty_struct *tty;
672
    struct cyclades_port *info;
673
    volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
674
    int channel;
675
    char data;
676
    int char_count;
677
    int save_cnt;
678
 
679
    /* determine the channel and change to that context */
680
    channel = (u_short ) (base_addr[CyLICR] >> 2);
681
    info = &cy_port[channel];
682
    info->last_active = jiffies;
683
    save_cnt = char_count = base_addr[CyRFOC];
684
 
685
#ifdef CONFIG_REMOTE_DEBUG
686
    if (channel == DEBUG_PORT) {
687
        while (char_count--) {
688
            data = base_addr[CyRDR];
689
            queueDebugChar(data);
690
        }
691
    }
692
    else
693
#endif
694
    /* if there is nowhere to put the data, discard it */
695
    if(info->tty == 0){
696
        while(char_count--){
697
            data = base_addr[CyRDR];
698
        }
699
    }else{ /* there is an open port for this data */
700
        tty = info->tty;
701
        /* load # characters available from the chip */
702
 
703
#ifdef CYCLOM_ENABLE_MONITORING
704
        ++info->mon.int_count;
705
        info->mon.char_count += char_count;
706
        if (char_count > info->mon.char_max)
707
            info->mon.char_max = char_count;
708
        info->mon.char_last = char_count;
709
#endif
710
        while(char_count--){
711
            data = base_addr[CyRDR];
712
            if (tty->flip.count >= TTY_FLIPBUF_SIZE){
713
                continue;
714
            }
715
            tty->flip.count++;
716
            *tty->flip.flag_buf_ptr++ = TTY_NORMAL;
717
            *tty->flip.char_buf_ptr++ = data;
718
#ifdef CYCLOM_16Y_HACK
719
            udelay(10L);
720
#endif
721
        }
722
        queue_task(&tty->flip.tqueue, &tq_timer);
723
    }
724
    /* end of service */
725
    base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS;
726
} /* cy_rx_interrupt */
727
 
728
/*
729
 * This routine is used to handle the "bottom half" processing for the
730
 * serial driver, known also the "software interrupt" processing.
731
 * This processing is done at the kernel interrupt level, after the
732
 * cy_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON.  This
733
 * is where time-consuming activities which can not be done in the
734
 * interrupt driver proper are done; the interrupt driver schedules
735
 * them using cy_sched_event(), and they get done here.
736
 *
737
 * This is done through one level of indirection--the task queue.
738
 * When a hardware interrupt service routine wants service by the
739
 * driver's bottom half, it enqueues the appropriate tq_struct (one
740
 * per port) to the tq_cyclades work queue and sets a request flag
741
 * via mark_bh for processing that queue.  When the time is right,
742
 * do_cyclades_bh is called (because of the mark_bh) and it requests
743
 * that the work queue be processed.
744
 *
745
 * Although this may seem unwieldy, it gives the system a way to
746
 * pass an argument (in this case the pointer to the cyclades_port
747
 * structure) to the bottom half of the driver.  Previous kernels
748
 * had to poll every port to see if that port needed servicing.
749
 */
750
static void
751
do_cyclades_bh(void)
752
{
753
    run_task_queue(&tq_cyclades);
754
} /* do_cyclades_bh */
755
 
756
static void
757
do_softint(void *private_)
758
{
759
  struct cyclades_port *info = (struct cyclades_port *) private_;
760
  struct tty_struct    *tty;
761
 
762
    tty = info->tty;
763
    if (!tty)
764
        return;
765
 
766
    if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
767
        tty_hangup(info->tty);
768
        wake_up_interruptible(&info->open_wait);
769
        info->flags &= ~(ASYNC_NORMAL_ACTIVE|
770
                             ASYNC_CALLOUT_ACTIVE);
771
    }
772
    if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) {
773
        wake_up_interruptible(&info->open_wait);
774
    }
775
    if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
776
        if((tty->flags & (1<< TTY_DO_WRITE_WAKEUP))
777
        && tty->ldisc.write_wakeup){
778
            (tty->ldisc.write_wakeup)(tty);
779
        }
780
        wake_up_interruptible(&tty->write_wait);
781
    }
782
} /* do_softint */
783
 
784
 
785
/* This is called whenever a port becomes active;
786
   interrupts are enabled and DTR & RTS are turned on.
787
 */
788
static int
789
startup(struct cyclades_port * info)
790
{
791
  unsigned long flags;
792
  volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
793
  int channel;
794
 
795
    if (info->flags & ASYNC_INITIALIZED){
796
        return 0;
797
    }
798
 
799
    if (!info->type){
800
        if (info->tty){
801
            set_bit(TTY_IO_ERROR, &info->tty->flags);
802
        }
803
        return 0;
804
    }
805
    if (!info->xmit_buf){
806
        info->xmit_buf = (unsigned char *) get_free_page (GFP_KERNEL);
807
        if (!info->xmit_buf){
808
            return -ENOMEM;
809
        }
810
    }
811
 
812
    config_setup(info);
813
 
814
    channel = info->line;
815
 
816
#ifdef SERIAL_DEBUG_OPEN
817
    printk("startup channel %d\n", channel);
818
#endif
819
 
820
    save_flags(flags); cli();
821
        base_addr[CyCAR] = (u_char)channel;
822
        write_cy_cmd(base_addr,CyENB_RCVR|CyENB_XMTR);
823
 
824
        base_addr[CyCAR] = (u_char)channel; /* !!! Is this needed? */
825
        base_addr[CyMSVR1] = CyRTS;
826
/* CP('S');CP('1'); */
827
        base_addr[CyMSVR2] = CyDTR;
828
 
829
#ifdef SERIAL_DEBUG_DTR
830
        printk("cyc: %d: raising DTR\n", __LINE__);
831
        printk("     status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
832
#endif
833
 
834
        base_addr[CyIER] |= CyRxData;
835
        info->flags |= ASYNC_INITIALIZED;
836
 
837
        if (info->tty){
838
            clear_bit(TTY_IO_ERROR, &info->tty->flags);
839
        }
840
        info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
841
 
842
    restore_flags(flags);
843
 
844
#ifdef SERIAL_DEBUG_OPEN
845
    printk(" done\n");
846
#endif
847
    return 0;
848
} /* startup */
849
 
850
void
851
start_xmit( struct cyclades_port *info )
852
{
853
  unsigned long flags;
854
  volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
855
  int channel;
856
 
857
    channel = info->line;
858
    save_flags(flags); cli();
859
        base_addr[CyCAR] = channel;
860
        base_addr[CyIER] |= CyTxMpty;
861
    restore_flags(flags);
862
} /* start_xmit */
863
 
864
/*
865
 * This routine shuts down a serial port; interrupts are disabled,
866
 * and DTR is dropped if the hangup on close termio flag is on.
867
 */
868
static void
869
shutdown(struct cyclades_port * info)
870
{
871
  unsigned long flags;
872
  volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
873
  int channel;
874
 
875
    if (!(info->flags & ASYNC_INITIALIZED)){
876
/* CP('$'); */
877
        return;
878
    }
879
 
880
    channel = info->line;
881
 
882
#ifdef SERIAL_DEBUG_OPEN
883
    printk("shutdown channel %d\n", channel);
884
#endif
885
 
886
    /* !!! REALLY MUST WAIT FOR LAST CHARACTER TO BE
887
       SENT BEFORE DROPPING THE LINE !!!  (Perhaps
888
       set some flag that is read when XMTY happens.)
889
       Other choices are to delay some fixed interval
890
       or schedule some later processing.
891
     */
892
    save_flags(flags); cli();
893
        if (info->xmit_buf){
894
            free_page((unsigned long) info->xmit_buf);
895
            info->xmit_buf = 0;
896
        }
897
 
898
        base_addr[CyCAR] = (u_char)channel;
899
        if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
900
            base_addr[CyMSVR1] = 0;
901
/* CP('C');CP('1'); */
902
            base_addr[CyMSVR2] = 0;
903
#ifdef SERIAL_DEBUG_DTR
904
            printk("cyc: %d: dropping DTR\n", __LINE__);
905
            printk("     status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
906
#endif
907
        }
908
        write_cy_cmd(base_addr,CyDIS_RCVR);
909
         /* it may be appropriate to clear _XMIT at
910
           some later date (after testing)!!! */
911
 
912
        if (info->tty){
913
            set_bit(TTY_IO_ERROR, &info->tty->flags);
914
        }
915
        info->flags &= ~ASYNC_INITIALIZED;
916
    restore_flags(flags);
917
 
918
#ifdef SERIAL_DEBUG_OPEN
919
    printk(" done\n");
920
#endif
921
    return;
922
} /* shutdown */
923
 
924
/*
925
 * This routine finds or computes the various line characteristics.
926
 */
927
static void
928
config_setup(struct cyclades_port * info)
929
{
930
  unsigned long flags;
931
  volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
932
  int channel;
933
  unsigned cflag;
934
  int   i;
935
  unsigned char ti, need_init_chan = 0;
936
 
937
    if (!info->tty || !info->tty->termios){
938
        return;
939
    }
940
    if (info->line == -1){
941
        return;
942
    }
943
    cflag = info->tty->termios->c_cflag;
944
 
945
    /* baud rate */
946
    i = cflag & CBAUD;
947
#ifdef CBAUDEX
948
/* Starting with kernel 1.1.65, there is direct support for
949
   higher baud rates.  The following code supports those
950
   changes.  The conditional aspect allows this driver to be
951
   used for earlier as well as later kernel versions.  (The
952
   mapping is slightly different from serial.c because there
953
   is still the possibility of supporting 75 kbit/sec with
954
   the Cyclades board.)
955
 */
956
    if (i & CBAUDEX) {
957
        if (i == B57600)
958
            i = 16;
959
        else if(i == B115200)
960
            i = 18;
961
#ifdef B78600
962
        else if(i == B78600)
963
            i = 17;
964
#endif
965
        else
966
            info->tty->termios->c_cflag &= ~CBAUDEX;
967
    }
968
#endif
969
    if (i == 15) {
970
            if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
971
                    i += 1;
972
            if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
973
                    i += 3;
974
    }
975
    /* Don't ever change the speed of the console port.  It will
976
     * run at the speed specified in bootinfo, or at 19.2K */
977
    /* Actually, it should run at whatever speed 166Bug was using */
978
    /* Note info->timeout isn't used at present */
979
    if (info != serial_console_info) {
980
        info->tbpr = baud_bpr[i]; /* Tx BPR */
981
        info->tco = baud_co[i]; /* Tx CO */
982
        info->rbpr = baud_bpr[i]; /* Rx BPR */
983
        info->rco = baud_co[i] >> 5; /* Rx CO */
984
        if (baud_table[i] == 134) {
985
            info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
986
            /* get it right for 134.5 baud */
987
        } else if (baud_table[i]) {
988
            info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2;
989
        /* this needs to be propagated into the card info */
990
        } else {
991
            info->timeout = 0;
992
        }
993
    }
994
    /* By tradition (is it a standard?) a baud rate of zero
995
       implies the line should be/has been closed.  A bit
996
       later in this routine such a test is performed. */
997
 
998
    /* byte size and parity */
999
    info->cor7 = 0;
1000
    info->cor6 = 0;
1001
    info->cor5 = 0;
1002
    info->cor4 = (info->default_threshold
1003
                  ? info->default_threshold
1004
                  : baud_cor4[i]); /* receive threshold */
1005
    /* Following two lines added 101295, RGH. */
1006
    /* It is obviously wrong to access CyCORx, and not info->corx here,
1007
     * try and remember to fix it later! */
1008
    channel = info->line;
1009
    base_addr[CyCAR] = (u_char)channel;
1010
    if (C_CLOCAL(info->tty)) {
1011
        if (base_addr[CyIER] & CyMdmCh)
1012
            base_addr[CyIER] &= ~CyMdmCh; /* without modem intr */
1013
                               /* ignore 1->0 modem transitions */
1014
        if (base_addr[CyCOR4] & (CyDSR|CyCTS|CyDCD))
1015
            base_addr[CyCOR4] &= ~(CyDSR|CyCTS|CyDCD);
1016
                               /* ignore 0->1 modem transitions */
1017
        if (base_addr[CyCOR5] & (CyDSR|CyCTS|CyDCD))
1018
            base_addr[CyCOR5] &= ~(CyDSR|CyCTS|CyDCD);
1019
    } else {
1020
        if ((base_addr[CyIER] & CyMdmCh) != CyMdmCh)
1021
            base_addr[CyIER] |= CyMdmCh; /* with modem intr */
1022
                               /* act on 1->0 modem transitions */
1023
        if ((base_addr[CyCOR4] & (CyDSR|CyCTS|CyDCD)) != (CyDSR|CyCTS|CyDCD))
1024
            base_addr[CyCOR4] |= CyDSR|CyCTS|CyDCD;
1025
                               /* act on 0->1 modem transitions */
1026
        if ((base_addr[CyCOR5] & (CyDSR|CyCTS|CyDCD)) != (CyDSR|CyCTS|CyDCD))
1027
            base_addr[CyCOR5] |= CyDSR|CyCTS|CyDCD;
1028
    }
1029
    info->cor3 = (cflag & CSTOPB) ? Cy_2_STOP : Cy_1_STOP;
1030
    info->cor2 = CyETC;
1031
    switch(cflag & CSIZE){
1032
    case CS5:
1033
        info->cor1 = Cy_5_BITS;
1034
        break;
1035
    case CS6:
1036
        info->cor1 = Cy_6_BITS;
1037
        break;
1038
    case CS7:
1039
        info->cor1 = Cy_7_BITS;
1040
        break;
1041
    case CS8:
1042
        info->cor1 = Cy_8_BITS;
1043
        break;
1044
    }
1045
    if (cflag & PARENB){
1046
        if (cflag & PARODD){
1047
            info->cor1 |= CyPARITY_O;
1048
        }else{
1049
            info->cor1 |= CyPARITY_E;
1050
        }
1051
    }else{
1052
        info->cor1 |= CyPARITY_NONE;
1053
    }
1054
 
1055
    /* CTS flow control flag */
1056
#if 0
1057
    /* Don't complcate matters for now! RGH 141095 */
1058
    if (cflag & CRTSCTS){
1059
        info->flags |= ASYNC_CTS_FLOW;
1060
        info->cor2 |= CyCtsAE;
1061
    }else{
1062
        info->flags &= ~ASYNC_CTS_FLOW;
1063
        info->cor2 &= ~CyCtsAE;
1064
    }
1065
#endif
1066
    if (cflag & CLOCAL)
1067
        info->flags &= ~ASYNC_CHECK_CD;
1068
    else
1069
        info->flags |= ASYNC_CHECK_CD;
1070
 
1071
     /***********************************************
1072
        The hardware option, CyRtsAO, presents RTS when
1073
        the chip has characters to send.  Since most modems
1074
        use RTS as reverse (inbound) flow control, this
1075
        option is not used.  If inbound flow control is
1076
        necessary, DTR can be programmed to provide the
1077
        appropriate signals for use with a non-standard
1078
        cable.  Contact Marcio Saito for details.
1079
     ***********************************************/
1080
 
1081
    channel = info->line;
1082
 
1083
    save_flags(flags); cli();
1084
        base_addr[CyCAR] = (u_char)channel;
1085
 
1086
        /* CyCMR set once only in mvme167_init_serial() */
1087
        if (base_addr[CyLICR] != channel << 2)
1088
            base_addr[CyLICR] = channel << 2;
1089
        if (base_addr[CyLIVR] != 0x5c)
1090
            base_addr[CyLIVR] = 0x5c;
1091
 
1092
       /* tx and rx baud rate */
1093
 
1094
        if (base_addr[CyCOR1] != info->cor1)
1095
            need_init_chan = 1;
1096
        if (base_addr[CyTCOR] != info->tco)
1097
            base_addr[CyTCOR] = info->tco;
1098
        if (base_addr[CyTBPR] != info->tbpr)
1099
            base_addr[CyTBPR] = info->tbpr;
1100
        if (base_addr[CyRCOR] != info->rco)
1101
            base_addr[CyRCOR] = info->rco;
1102
        if (base_addr[CyRBPR] != info->rbpr)
1103
            base_addr[CyRBPR] = info->rbpr;
1104
 
1105
        /* set line characteristics  according configuration */
1106
 
1107
        if (base_addr[CySCHR1] != START_CHAR(info->tty))
1108
            base_addr[CySCHR1] = START_CHAR(info->tty);
1109
        if (base_addr[CySCHR2] != STOP_CHAR(info->tty))
1110
            base_addr[CySCHR2] = STOP_CHAR(info->tty);
1111
        if (base_addr[CySCRL] != START_CHAR(info->tty))
1112
            base_addr[CySCRL] = START_CHAR(info->tty);
1113
        if (base_addr[CySCRH] != START_CHAR(info->tty))
1114
            base_addr[CySCRH] = START_CHAR(info->tty);
1115
        if (base_addr[CyCOR1] != info->cor1)
1116
            base_addr[CyCOR1] = info->cor1;
1117
        if (base_addr[CyCOR2] != info->cor2)
1118
            base_addr[CyCOR2] = info->cor2;
1119
        if (base_addr[CyCOR3] != info->cor3)
1120
            base_addr[CyCOR3] = info->cor3;
1121
        if (base_addr[CyCOR4] != info->cor4)
1122
            base_addr[CyCOR4] = info->cor4;
1123
        if (base_addr[CyCOR5] != info->cor5)
1124
            base_addr[CyCOR5] = info->cor5;
1125
        if (base_addr[CyCOR6] != info->cor6)
1126
            base_addr[CyCOR6] = info->cor6;
1127
        if (base_addr[CyCOR7] != info->cor7)
1128
            base_addr[CyCOR7] = info->cor7;
1129
 
1130
        if (need_init_chan)
1131
            write_cy_cmd(base_addr,CyINIT_CHAN);
1132
 
1133
        base_addr[CyCAR] = (u_char)channel; /* !!! Is this needed? */
1134
 
1135
        /* 2ms default rx timeout */
1136
        ti = info->default_timeout ? info->default_timeout : 0x02;
1137
        if (base_addr[CyRTPRL] != ti)
1138
            base_addr[CyRTPRL] = ti;
1139
        if (base_addr[CyRTPRH] != 0)
1140
            base_addr[CyRTPRH] = 0;
1141
 
1142
        /* Set up RTS here also ????? RGH 141095 */
1143
        if(i == 0){ /* baud rate is zero, turn off line */
1144
            if ((base_addr[CyMSVR2] & CyDTR) == CyDTR)
1145
                base_addr[CyMSVR2] = 0;
1146
#ifdef SERIAL_DEBUG_DTR
1147
            printk("cyc: %d: dropping DTR\n", __LINE__);
1148
            printk("     status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1149
#endif
1150
        }else{
1151
            if ((base_addr[CyMSVR2] & CyDTR) != CyDTR)
1152
                base_addr[CyMSVR2] = CyDTR;
1153
#ifdef SERIAL_DEBUG_DTR
1154
            printk("cyc: %d: raising DTR\n", __LINE__);
1155
            printk("     status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1156
#endif
1157
        }
1158
 
1159
        if (info->tty){
1160
            clear_bit(TTY_IO_ERROR, &info->tty->flags);
1161
        }
1162
 
1163
    restore_flags(flags);
1164
 
1165
} /* config_setup */
1166
 
1167
 
1168
static void
1169
cy_put_char(struct tty_struct *tty, unsigned char ch)
1170
{
1171
  struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1172
  unsigned long flags;
1173
 
1174
#ifdef SERIAL_DEBUG_IO
1175
    printk("cy_put_char ttyS%d(0x%02x)\n", info->line, ch);
1176
#endif
1177
 
1178
    if (serial_paranoia_check(info, tty->device, "cy_put_char"))
1179
        return;
1180
 
1181
    if (!tty || !info->xmit_buf)
1182
        return;
1183
 
1184
    save_flags(flags); cli();
1185
        if (info->xmit_cnt >= PAGE_SIZE - 1) {
1186
            restore_flags(flags);
1187
            return;
1188
        }
1189
 
1190
        info->xmit_buf[info->xmit_head++] = ch;
1191
        info->xmit_head &= PAGE_SIZE - 1;
1192
        info->xmit_cnt++;
1193
    restore_flags(flags);
1194
} /* cy_put_char */
1195
 
1196
 
1197
static void
1198
cy_flush_chars(struct tty_struct *tty)
1199
{
1200
  struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1201
  unsigned long flags;
1202
  volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1203
  int channel;
1204
 
1205
#ifdef SERIAL_DEBUG_IO
1206
    printk("cy_flush_chars ttyS%d\n", info->line); /* */
1207
#endif
1208
 
1209
    if (serial_paranoia_check(info, tty->device, "cy_flush_chars"))
1210
        return;
1211
 
1212
    if (info->xmit_cnt <= 0 || tty->stopped
1213
    || tty->hw_stopped || !info->xmit_buf)
1214
        return;
1215
 
1216
    channel = info->line;
1217
 
1218
    save_flags(flags); cli();
1219
        base_addr[CyCAR] = channel;
1220
        base_addr[CyIER] |= CyTxMpty;
1221
    restore_flags(flags);
1222
} /* cy_flush_chars */
1223
 
1224
 
1225
/* This routine gets called when tty_write has put something into
1226
    the write_queue.  If the port is not already transmitting stuff,
1227
    start it off by enabling interrupts.  The interrupt service
1228
    routine will then ensure that the characters are sent.  If the
1229
    port is already active, there is no need to kick it.
1230
 */
1231
static int
1232
cy_write(struct tty_struct * tty, int from_user,
1233
           const unsigned char *buf, int count)
1234
{
1235
  struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1236
  unsigned long flags;
1237
  int c, total = 0;
1238
 
1239
#ifdef SERIAL_DEBUG_IO
1240
    printk("cy_write ttyS%d\n", info->line); /* */
1241
#endif
1242
 
1243
    if (serial_paranoia_check(info, tty->device, "cy_write")){
1244
        return 0;
1245
    }
1246
 
1247
    if (!tty || !info->xmit_buf || !tmp_buf){
1248
        return 0;
1249
    }
1250
 
1251
    if (from_user) {
1252
            down(&tmp_buf_sem);
1253
            while (1) {
1254
                    c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1255
                                       SERIAL_XMIT_SIZE - info->xmit_head));
1256
                    if (c <= 0)
1257
                            break;
1258
 
1259
                    c -= copy_from_user(tmp_buf, buf, c);
1260
                    if (!c) {
1261
                            if (!total)
1262
                                    total = -EFAULT;
1263
                            break;
1264
                    }
1265
 
1266
                    save_flags(flags); cli();
1267
                    c = MIN(c, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1268
                                   SERIAL_XMIT_SIZE - info->xmit_head));
1269
                    memcpy(info->xmit_buf + info->xmit_head, tmp_buf, c);
1270
                    info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1271
                    info->xmit_cnt += c;
1272
                    restore_flags(flags);
1273
 
1274
                    buf += c;
1275
                    count -= c;
1276
                    total += c;
1277
            }
1278
            up(&tmp_buf_sem);
1279
    } else {
1280
            while (1) {
1281
                    save_flags(flags); cli();
1282
                    c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1283
                                       SERIAL_XMIT_SIZE - info->xmit_head));
1284
                    if (c <= 0) {
1285
                            restore_flags(flags);
1286
                            break;
1287
                    }
1288
 
1289
                    memcpy(info->xmit_buf + info->xmit_head, buf, c);
1290
                    info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1291
                    info->xmit_cnt += c;
1292
                    restore_flags(flags);
1293
 
1294
                    buf += c;
1295
                    count -= c;
1296
                    total += c;
1297
            }
1298
    }
1299
 
1300
    if (info->xmit_cnt
1301
    && !tty->stopped
1302
    && !tty->hw_stopped ) {
1303
        start_xmit(info);
1304
    }
1305
    return total;
1306
} /* cy_write */
1307
 
1308
 
1309
static int
1310
cy_write_room(struct tty_struct *tty)
1311
{
1312
  struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1313
  int   ret;
1314
 
1315
#ifdef SERIAL_DEBUG_IO
1316
    printk("cy_write_room ttyS%d\n", info->line); /* */
1317
#endif
1318
 
1319
    if (serial_paranoia_check(info, tty->device, "cy_write_room"))
1320
        return 0;
1321
    ret = PAGE_SIZE - info->xmit_cnt - 1;
1322
    if (ret < 0)
1323
        ret = 0;
1324
    return ret;
1325
} /* cy_write_room */
1326
 
1327
 
1328
static int
1329
cy_chars_in_buffer(struct tty_struct *tty)
1330
{
1331
  struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1332
 
1333
#ifdef SERIAL_DEBUG_IO
1334
    printk("cy_chars_in_buffer ttyS%d %d\n", info->line, info->xmit_cnt); /* */
1335
#endif
1336
 
1337
    if (serial_paranoia_check(info, tty->device, "cy_chars_in_buffer"))
1338
        return 0;
1339
 
1340
    return info->xmit_cnt;
1341
} /* cy_chars_in_buffer */
1342
 
1343
 
1344
static void
1345
cy_flush_buffer(struct tty_struct *tty)
1346
{
1347
  struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1348
  unsigned long flags;
1349
 
1350
#ifdef SERIAL_DEBUG_IO
1351
    printk("cy_flush_buffer ttyS%d\n", info->line); /* */
1352
#endif
1353
 
1354
    if (serial_paranoia_check(info, tty->device, "cy_flush_buffer"))
1355
        return;
1356
    save_flags(flags); cli();
1357
        info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1358
    restore_flags(flags);
1359
    wake_up_interruptible(&tty->write_wait);
1360
    if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP))
1361
    && tty->ldisc.write_wakeup)
1362
        (tty->ldisc.write_wakeup)(tty);
1363
} /* cy_flush_buffer */
1364
 
1365
 
1366
/* This routine is called by the upper-layer tty layer to signal
1367
   that incoming characters should be throttled or that the
1368
   throttle should be released.
1369
 */
1370
static void
1371
cy_throttle(struct tty_struct * tty)
1372
{
1373
  struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1374
  unsigned long flags;
1375
  volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1376
  int channel;
1377
 
1378
#ifdef SERIAL_DEBUG_THROTTLE
1379
  char buf[64];
1380
 
1381
    printk("throttle %s: %d....\n", tty_name(tty, buf),
1382
           tty->ldisc.chars_in_buffer(tty));
1383
    printk("cy_throttle ttyS%d\n", info->line);
1384
#endif
1385
 
1386
    if (serial_paranoia_check(info, tty->device, "cy_nthrottle")){
1387
            return;
1388
    }
1389
 
1390
    if (I_IXOFF(tty)) {
1391
        info->x_char = STOP_CHAR(tty);
1392
            /* Should use the "Send Special Character" feature!!! */
1393
    }
1394
 
1395
    channel = info->line;
1396
 
1397
    save_flags(flags); cli();
1398
        base_addr[CyCAR] = (u_char)channel;
1399
        base_addr[CyMSVR1] = 0;
1400
    restore_flags(flags);
1401
 
1402
    return;
1403
} /* cy_throttle */
1404
 
1405
 
1406
static void
1407
cy_unthrottle(struct tty_struct * tty)
1408
{
1409
  struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1410
  unsigned long flags;
1411
  volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1412
  int channel;
1413
 
1414
#ifdef SERIAL_DEBUG_THROTTLE
1415
  char buf[64];
1416
 
1417
    printk("throttle %s: %d....\n", tty_name(tty, buf),
1418
           tty->ldisc.chars_in_buffer(tty));
1419
    printk("cy_unthrottle ttyS%d\n", info->line);
1420
#endif
1421
 
1422
    if (serial_paranoia_check(info, tty->device, "cy_nthrottle")){
1423
            return;
1424
    }
1425
 
1426
    if (I_IXOFF(tty)) {
1427
        info->x_char = START_CHAR(tty);
1428
        /* Should use the "Send Special Character" feature!!! */
1429
    }
1430
 
1431
    channel = info->line;
1432
 
1433
    save_flags(flags); cli();
1434
        base_addr[CyCAR] = (u_char)channel;
1435
        base_addr[CyMSVR1] = CyRTS;
1436
    restore_flags(flags);
1437
 
1438
    return;
1439
} /* cy_unthrottle */
1440
 
1441
static int
1442
get_serial_info(struct cyclades_port * info,
1443
                           struct serial_struct * retinfo)
1444
{
1445
  struct serial_struct tmp;
1446
 
1447
/* CP('g'); */
1448
    if (!retinfo)
1449
            return -EFAULT;
1450
    memset(&tmp, 0, sizeof(tmp));
1451
    tmp.type = info->type;
1452
    tmp.line = info->line;
1453
    tmp.port = info->line;
1454
    tmp.irq = 0;
1455
    tmp.flags = info->flags;
1456
    tmp.baud_base = 0;          /*!!!*/
1457
    tmp.close_delay = info->close_delay;
1458
    tmp.custom_divisor = 0;     /*!!!*/
1459
    tmp.hub6 = 0;               /*!!!*/
1460
    return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0;
1461
} /* get_serial_info */
1462
 
1463
static int
1464
set_serial_info(struct cyclades_port * info,
1465
                           struct serial_struct * new_info)
1466
{
1467
  struct serial_struct new_serial;
1468
  struct cyclades_port old_info;
1469
 
1470
/* CP('s'); */
1471
    if (!new_info)
1472
            return -EFAULT;
1473
    if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
1474
            return -EFAULT;
1475
    old_info = *info;
1476
 
1477
    if (!suser()) {
1478
            if ((new_serial.close_delay != info->close_delay) ||
1479
                ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) !=
1480
                 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK)))
1481
                    return -EPERM;
1482
            info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1483
                           (new_serial.flags & ASYNC_USR_MASK));
1484
            goto check_and_exit;
1485
    }
1486
 
1487
 
1488
    /*
1489
     * OK, past this point, all the error checking has been done.
1490
     * At this point, we start making changes.....
1491
     */
1492
 
1493
    info->flags = ((info->flags & ~ASYNC_FLAGS) |
1494
                    (new_serial.flags & ASYNC_FLAGS));
1495
    info->close_delay = new_serial.close_delay;
1496
 
1497
 
1498
check_and_exit:
1499
    if (info->flags & ASYNC_INITIALIZED){
1500
        config_setup(info);
1501
        return 0;
1502
    }else{
1503
        return startup(info);
1504
    }
1505
} /* set_serial_info */
1506
 
1507
static int
1508
get_modem_info(struct cyclades_port * info, unsigned int *value)
1509
{
1510
  int channel;
1511
  volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1512
  unsigned long flags;
1513
  unsigned char status;
1514
  unsigned int result;
1515
 
1516
    channel = info->line;
1517
 
1518
    save_flags(flags); cli();
1519
        base_addr[CyCAR] = (u_char)channel;
1520
        status = base_addr[CyMSVR1] | base_addr[CyMSVR2];
1521
    restore_flags(flags);
1522
 
1523
    result =  ((status  & CyRTS) ? TIOCM_RTS : 0)
1524
            | ((status  & CyDTR) ? TIOCM_DTR : 0)
1525
            | ((status  & CyDCD) ? TIOCM_CAR : 0)
1526
            | ((status  & CyDSR) ? TIOCM_DSR : 0)
1527
            | ((status  & CyCTS) ? TIOCM_CTS : 0);
1528
    return put_user(result,(unsigned int *) value);
1529
} /* get_modem_info */
1530
 
1531
static int
1532
set_modem_info(struct cyclades_port * info, unsigned int cmd,
1533
                          unsigned int *value)
1534
{
1535
  int channel;
1536
  volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1537
  unsigned long flags;
1538
  unsigned int arg;
1539
 
1540
    if (get_user(arg, (unsigned long *) value))
1541
        return -EFAULT;
1542
    channel = info->line;
1543
 
1544
    switch (cmd) {
1545
    case TIOCMBIS:
1546
        if (arg & TIOCM_RTS){
1547
            save_flags(flags); cli();
1548
                base_addr[CyCAR] = (u_char)channel;
1549
                base_addr[CyMSVR1] = CyRTS;
1550
            restore_flags(flags);
1551
        }
1552
        if (arg & TIOCM_DTR){
1553
            save_flags(flags); cli();
1554
            base_addr[CyCAR] = (u_char)channel;
1555
/* CP('S');CP('2'); */
1556
            base_addr[CyMSVR2] = CyDTR;
1557
#ifdef SERIAL_DEBUG_DTR
1558
            printk("cyc: %d: raising DTR\n", __LINE__);
1559
            printk("     status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1560
#endif
1561
            restore_flags(flags);
1562
        }
1563
        break;
1564
    case TIOCMBIC:
1565
        if (arg & TIOCM_RTS){
1566
            save_flags(flags); cli();
1567
                base_addr[CyCAR] = (u_char)channel;
1568
                base_addr[CyMSVR1] = 0;
1569
            restore_flags(flags);
1570
        }
1571
        if (arg & TIOCM_DTR){
1572
            save_flags(flags); cli();
1573
            base_addr[CyCAR] = (u_char)channel;
1574
/* CP('C');CP('2'); */
1575
            base_addr[CyMSVR2] = 0;
1576
#ifdef SERIAL_DEBUG_DTR
1577
            printk("cyc: %d: dropping DTR\n", __LINE__);
1578
            printk("     status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1579
#endif
1580
            restore_flags(flags);
1581
        }
1582
        break;
1583
    case TIOCMSET:
1584
        if (arg & TIOCM_RTS){
1585
            save_flags(flags); cli();
1586
                base_addr[CyCAR] = (u_char)channel;
1587
                base_addr[CyMSVR1] = CyRTS;
1588
            restore_flags(flags);
1589
        }else{
1590
            save_flags(flags); cli();
1591
                base_addr[CyCAR] = (u_char)channel;
1592
                base_addr[CyMSVR1] = 0;
1593
            restore_flags(flags);
1594
        }
1595
        if (arg & TIOCM_DTR){
1596
            save_flags(flags); cli();
1597
            base_addr[CyCAR] = (u_char)channel;
1598
/* CP('S');CP('3'); */
1599
            base_addr[CyMSVR2] = CyDTR;
1600
#ifdef SERIAL_DEBUG_DTR
1601
            printk("cyc: %d: raising DTR\n", __LINE__);
1602
            printk("     status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1603
#endif
1604
            restore_flags(flags);
1605
        }else{
1606
            save_flags(flags); cli();
1607
            base_addr[CyCAR] = (u_char)channel;
1608
/* CP('C');CP('3'); */
1609
            base_addr[CyMSVR2] = 0;
1610
#ifdef SERIAL_DEBUG_DTR
1611
            printk("cyc: %d: dropping DTR\n", __LINE__);
1612
            printk("     status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1613
#endif
1614
            restore_flags(flags);
1615
        }
1616
        break;
1617
    default:
1618
                return -EINVAL;
1619
        }
1620
    return 0;
1621
} /* set_modem_info */
1622
 
1623
static void
1624
send_break( struct cyclades_port * info, int duration)
1625
{ /* Let the transmit ISR take care of this (since it
1626
     requires stuffing characters into the output stream).
1627
   */
1628
    info->x_break = duration;
1629
    if (!info->xmit_cnt ) {
1630
        start_xmit(info);
1631
    }
1632
} /* send_break */
1633
 
1634
static int
1635
get_mon_info(struct cyclades_port * info, struct cyclades_monitor * mon)
1636
{
1637
 
1638
   if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
1639
           return -EFAULT;
1640
   info->mon.int_count  = 0;
1641
   info->mon.char_count = 0;
1642
   info->mon.char_max   = 0;
1643
   info->mon.char_last  = 0;
1644
   return 0;
1645
}
1646
 
1647
static int
1648
set_threshold(struct cyclades_port * info, unsigned long *arg)
1649
{
1650
   volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1651
   unsigned long value;
1652
   int channel;
1653
 
1654
   if (get_user(value, arg))
1655
           return -EFAULT;
1656
 
1657
   channel = info->line;
1658
   info->cor4 &= ~CyREC_FIFO;
1659
   info->cor4 |= value & CyREC_FIFO;
1660
   base_addr[CyCOR4] = info->cor4;
1661
   return 0;
1662
}
1663
 
1664
static int
1665
get_threshold(struct cyclades_port * info, unsigned long *value)
1666
{
1667
   volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1668
   int channel;
1669
   unsigned long tmp;
1670
 
1671
   channel = info->line;
1672
 
1673
   tmp = base_addr[CyCOR4] & CyREC_FIFO;
1674
   return put_user(tmp,value);
1675
}
1676
 
1677
static int
1678
set_default_threshold(struct cyclades_port * info, unsigned long *arg)
1679
{
1680
   unsigned long value;
1681
 
1682
   if (get_user(value, arg))
1683
        return -EFAULT;
1684
 
1685
   info->default_threshold = value & 0x0f;
1686
   return 0;
1687
}
1688
 
1689
static int
1690
get_default_threshold(struct cyclades_port * info, unsigned long *value)
1691
{
1692
   return put_user(info->default_threshold,value);
1693
}
1694
 
1695
static int
1696
set_timeout(struct cyclades_port * info, unsigned long *arg)
1697
{
1698
   volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1699
   int channel;
1700
   unsigned long value;
1701
 
1702
   if (get_user(value, arg))
1703
           return -EFAULT;
1704
 
1705
   channel = info->line;
1706
 
1707
   base_addr[CyRTPRL] = value & 0xff;
1708
   base_addr[CyRTPRH] = (value >> 8) & 0xff;
1709
   return 0;
1710
}
1711
 
1712
static int
1713
get_timeout(struct cyclades_port * info, unsigned long *value)
1714
{
1715
   volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1716
   int channel;
1717
   unsigned long tmp;
1718
 
1719
   channel = info->line;
1720
 
1721
   tmp = base_addr[CyRTPRL];
1722
   return put_user(tmp,value);
1723
}
1724
 
1725
static int
1726
set_default_timeout(struct cyclades_port * info, unsigned long value)
1727
{
1728
   info->default_timeout = value & 0xff;
1729
   return 0;
1730
}
1731
 
1732
static int
1733
get_default_timeout(struct cyclades_port * info, unsigned long *value)
1734
{
1735
   return put_user(info->default_timeout,value);
1736
}
1737
 
1738
static int
1739
cy_ioctl(struct tty_struct *tty, struct file * file,
1740
            unsigned int cmd, unsigned long arg)
1741
{
1742
  unsigned long val;
1743
  struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1744
  int ret_val = 0;
1745
 
1746
#ifdef SERIAL_DEBUG_OTHER
1747
    printk("cy_ioctl ttyS%d, cmd = %x arg = %lx\n", info->line, cmd, arg); /* */
1748
#endif
1749
 
1750
    switch (cmd) {
1751
        case CYGETMON:
1752
            ret_val = get_mon_info(info, (struct cyclades_monitor *)arg);
1753
            break;
1754
        case CYGETTHRESH:
1755
            ret_val = get_threshold(info, (unsigned long *)arg);
1756
            break;
1757
        case CYSETTHRESH:
1758
            ret_val = set_threshold(info, (unsigned long *)arg);
1759
            break;
1760
        case CYGETDEFTHRESH:
1761
            ret_val = get_default_threshold(info, (unsigned long *)arg);
1762
            break;
1763
        case CYSETDEFTHRESH:
1764
            ret_val = set_default_threshold(info, (unsigned long *)arg);
1765
            break;
1766
        case CYGETTIMEOUT:
1767
            ret_val = get_timeout(info, (unsigned long *)arg);
1768
            break;
1769
        case CYSETTIMEOUT:
1770
            ret_val = set_timeout(info, (unsigned long *)arg);
1771
            break;
1772
        case CYGETDEFTIMEOUT:
1773
            ret_val = get_default_timeout(info, (unsigned long *)arg);
1774
            break;
1775
        case CYSETDEFTIMEOUT:
1776
            ret_val = set_default_timeout(info, (unsigned long)arg);
1777
            break;
1778
        case TCSBRK:    /* SVID version: non-zero arg --> no break */
1779
            ret_val = tty_check_change(tty);
1780
            if (ret_val)
1781
                    break;
1782
            tty_wait_until_sent(tty,0);
1783
            if (!arg)
1784
                send_break(info, HZ/4); /* 1/4 second */
1785
            break;
1786
        case TCSBRKP:   /* support for POSIX tcsendbreak() */
1787
            ret_val = tty_check_change(tty);
1788
            if (ret_val)
1789
                break;
1790
            tty_wait_until_sent(tty,0);
1791
            send_break(info, arg ? arg*(HZ/10) : HZ/4);
1792
            break;
1793
        case TIOCMBIS:
1794
        case TIOCMBIC:
1795
        case TIOCMSET:
1796
            ret_val = set_modem_info(info, cmd, (unsigned int *) arg);
1797
            break;
1798
 
1799
/* The following commands are incompletely implemented!!! */
1800
        case TIOCGSOFTCAR:
1801
            ret_val = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *) arg);
1802
            break;
1803
        case TIOCSSOFTCAR:
1804
            ret_val = get_user(val, (unsigned long *) arg);
1805
            if (ret_val)
1806
                    break;
1807
            tty->termios->c_cflag =
1808
                    ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0));
1809
            break;
1810
        case TIOCMGET:
1811
            ret_val = get_modem_info(info, (unsigned int *) arg);
1812
            break;
1813
        case TIOCGSERIAL:
1814
            ret_val = get_serial_info(info, (struct serial_struct *) arg);
1815
            break;
1816
        case TIOCSSERIAL:
1817
            ret_val = set_serial_info(info,
1818
                                   (struct serial_struct *) arg);
1819
            break;
1820
        default:
1821
            ret_val = -ENOIOCTLCMD;
1822
    }
1823
 
1824
#ifdef SERIAL_DEBUG_OTHER
1825
    printk("cy_ioctl done\n");
1826
#endif
1827
 
1828
    return ret_val;
1829
} /* cy_ioctl */
1830
 
1831
 
1832
 
1833
 
1834
static void
1835
cy_set_termios(struct tty_struct *tty, struct termios * old_termios)
1836
{
1837
  struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1838
 
1839
#ifdef SERIAL_DEBUG_OTHER
1840
    printk("cy_set_termios ttyS%d\n", info->line);
1841
#endif
1842
 
1843
    if (tty->termios->c_cflag == old_termios->c_cflag)
1844
        return;
1845
    config_setup(info);
1846
 
1847
    if ((old_termios->c_cflag & CRTSCTS) &&
1848
        !(tty->termios->c_cflag & CRTSCTS)) {
1849
            tty->stopped = 0;
1850
            cy_start(tty);
1851
    }
1852
#ifdef tytso_patch_94Nov25_1726
1853
    if (!(old_termios->c_cflag & CLOCAL) &&
1854
        (tty->termios->c_cflag & CLOCAL))
1855
            wake_up_interruptible(&info->open_wait);
1856
#endif
1857
 
1858
    return;
1859
} /* cy_set_termios */
1860
 
1861
 
1862
static void
1863
cy_close(struct tty_struct * tty, struct file * filp)
1864
{
1865
  struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1866
 
1867
/* CP('C'); */
1868
#ifdef SERIAL_DEBUG_OTHER
1869
    printk("cy_close ttyS%d\n", info->line);
1870
#endif
1871
 
1872
    if (!info
1873
    || serial_paranoia_check(info, tty->device, "cy_close")){
1874
        return;
1875
    }
1876
#ifdef SERIAL_DEBUG_OPEN
1877
    printk("cy_close ttyS%d, count = %d\n", info->line, info->count);
1878
#endif
1879
 
1880
    if ((tty->count == 1) && (info->count != 1)) {
1881
        /*
1882
         * Uh, oh.  tty->count is 1, which means that the tty
1883
         * structure will be freed.  Info->count should always
1884
         * be one in these conditions.  If it's greater than
1885
         * one, we've got real problems, since it means the
1886
         * serial port won't be shutdown.
1887
         */
1888
        printk("cy_close: bad serial port count; tty->count is 1, "
1889
           "info->count is %d\n", info->count);
1890
        info->count = 1;
1891
    }
1892
#ifdef SERIAL_DEBUG_COUNT
1893
    printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count - 1);
1894
#endif
1895
    if (--info->count < 0) {
1896
        printk("cy_close: bad serial port count for ttys%d: %d\n",
1897
               info->line, info->count);
1898
#ifdef SERIAL_DEBUG_COUNT
1899
    printk("cyc: %d: setting count to 0\n", __LINE__);
1900
#endif
1901
        info->count = 0;
1902
    }
1903
    if (info->count)
1904
        return;
1905
    info->flags |= ASYNC_CLOSING;
1906
    /*
1907
     * Save the termios structure, since this port may have
1908
     * separate termios for callout and dialin.
1909
     */
1910
    if (info->flags & ASYNC_NORMAL_ACTIVE)
1911
        info->normal_termios = *tty->termios;
1912
    if (info->flags & ASYNC_CALLOUT_ACTIVE)
1913
        info->callout_termios = *tty->termios;
1914
    if (info->flags & ASYNC_INITIALIZED)
1915
        tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
1916
    shutdown(info);
1917
    if (tty->driver.flush_buffer)
1918
        tty->driver.flush_buffer(tty);
1919
    if (tty->ldisc.flush_buffer)
1920
        tty->ldisc.flush_buffer(tty);
1921
    info->event = 0;
1922
    info->tty = 0;
1923
    if (tty->ldisc.num != ldiscs[N_TTY].num) {
1924
        if (tty->ldisc.close)
1925
            (tty->ldisc.close)(tty);
1926
        tty->ldisc = ldiscs[N_TTY];
1927
        tty->termios->c_line = N_TTY;
1928
        if (tty->ldisc.open)
1929
            (tty->ldisc.open)(tty);
1930
    }
1931
    if (info->blocked_open) {
1932
        if (info->close_delay) {
1933
            current->state = TASK_INTERRUPTIBLE;
1934
            schedule_timeout(info->close_delay);
1935
        }
1936
        wake_up_interruptible(&info->open_wait);
1937
    }
1938
    info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
1939
                     ASYNC_CLOSING);
1940
    wake_up_interruptible(&info->close_wait);
1941
 
1942
#ifdef SERIAL_DEBUG_OTHER
1943
    printk("cy_close done\n");
1944
#endif
1945
 
1946
    return;
1947
} /* cy_close */
1948
 
1949
/*
1950
 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
1951
 */
1952
void
1953
cy_hangup(struct tty_struct *tty)
1954
{
1955
  struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1956
 
1957
#ifdef SERIAL_DEBUG_OTHER
1958
    printk("cy_hangup ttyS%d\n", info->line); /* */
1959
#endif
1960
 
1961
    if (serial_paranoia_check(info, tty->device, "cy_hangup"))
1962
        return;
1963
 
1964
    shutdown(info);
1965
#if 0
1966
    info->event = 0;
1967
    info->count = 0;
1968
#ifdef SERIAL_DEBUG_COUNT
1969
    printk("cyc: %d: setting count to 0\n", __LINE__);
1970
#endif
1971
    info->tty = 0;
1972
#endif
1973
    info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
1974
    wake_up_interruptible(&info->open_wait);
1975
} /* cy_hangup */
1976
 
1977
 
1978
 
1979
/*
1980
 * ------------------------------------------------------------
1981
 * cy_open() and friends
1982
 * ------------------------------------------------------------
1983
 */
1984
 
1985
static int
1986
block_til_ready(struct tty_struct *tty, struct file * filp,
1987
                           struct cyclades_port *info)
1988
{
1989
  DECLARE_WAITQUEUE(wait, current);
1990
  unsigned long flags;
1991
  int channel;
1992
  int retval;
1993
  volatile u_char *base_addr = (u_char *)BASE_ADDR;
1994
 
1995
    /*
1996
     * If the device is in the middle of being closed, then block
1997
     * until it's done, and then try again.
1998
     */
1999
    if (info->flags & ASYNC_CLOSING) {
2000
        interruptible_sleep_on(&info->close_wait);
2001
        if (info->flags & ASYNC_HUP_NOTIFY){
2002
            return -EAGAIN;
2003
        }else{
2004
            return -ERESTARTSYS;
2005
        }
2006
    }
2007
 
2008
    /*
2009
     * If this is a callout device, then just make sure the normal
2010
     * device isn't being used.
2011
     */
2012
    if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
2013
        if (info->flags & ASYNC_NORMAL_ACTIVE){
2014
            return -EBUSY;
2015
        }
2016
        if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
2017
            (info->flags & ASYNC_SESSION_LOCKOUT) &&
2018
            (info->session != current->session)){
2019
            return -EBUSY;
2020
        }
2021
        if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
2022
            (info->flags & ASYNC_PGRP_LOCKOUT) &&
2023
            (info->pgrp != current->pgrp)){
2024
            return -EBUSY;
2025
        }
2026
        info->flags |= ASYNC_CALLOUT_ACTIVE;
2027
        return 0;
2028
    }
2029
 
2030
    /*
2031
     * If non-blocking mode is set, then make the check up front
2032
     * and then exit.
2033
     */
2034
    if (filp->f_flags & O_NONBLOCK) {
2035
        if (info->flags & ASYNC_CALLOUT_ACTIVE){
2036
            return -EBUSY;
2037
        }
2038
        info->flags |= ASYNC_NORMAL_ACTIVE;
2039
        return 0;
2040
    }
2041
 
2042
    /*
2043
     * Block waiting for the carrier detect and the line to become
2044
     * free (i.e., not in use by the callout).  While we are in
2045
     * this loop, info->count is dropped by one, so that
2046
     * cy_close() knows when to free things.  We restore it upon
2047
     * exit, either normal or abnormal.
2048
     */
2049
    retval = 0;
2050
    add_wait_queue(&info->open_wait, &wait);
2051
#ifdef SERIAL_DEBUG_OPEN
2052
    printk("block_til_ready before block: ttyS%d, count = %d\n",
2053
           info->line, info->count);/**/
2054
#endif
2055
    info->count--;
2056
#ifdef SERIAL_DEBUG_COUNT
2057
    printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count);
2058
#endif
2059
    info->blocked_open++;
2060
 
2061
    channel = info->line;
2062
 
2063
    while (1) {
2064
        save_flags(flags); cli();
2065
            if (!(info->flags & ASYNC_CALLOUT_ACTIVE)){
2066
                base_addr[CyCAR] = (u_char)channel;
2067
                base_addr[CyMSVR1] = CyRTS;
2068
/* CP('S');CP('4'); */
2069
                base_addr[CyMSVR2] = CyDTR;
2070
#ifdef SERIAL_DEBUG_DTR
2071
                printk("cyc: %d: raising DTR\n", __LINE__);
2072
                printk("     status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
2073
#endif
2074
            }
2075
        restore_flags(flags);
2076
        set_current_state(TASK_INTERRUPTIBLE);
2077
        if (tty_hung_up_p(filp)
2078
        || !(info->flags & ASYNC_INITIALIZED) ){
2079
            if (info->flags & ASYNC_HUP_NOTIFY) {
2080
                retval = -EAGAIN;
2081
            }else{
2082
                retval = -ERESTARTSYS;
2083
            }
2084
            break;
2085
        }
2086
        save_flags(flags); cli();
2087
            base_addr[CyCAR] = (u_char)channel;
2088
/* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */
2089
            if (!(info->flags & ASYNC_CALLOUT_ACTIVE)
2090
            && !(info->flags & ASYNC_CLOSING)
2091
            && (C_CLOCAL(tty)
2092
                || (base_addr[CyMSVR1] & CyDCD))) {
2093
                    restore_flags(flags);
2094
                    break;
2095
            }
2096
        restore_flags(flags);
2097
        if (signal_pending(current)) {
2098
            retval = -ERESTARTSYS;
2099
            break;
2100
        }
2101
#ifdef SERIAL_DEBUG_OPEN
2102
        printk("block_til_ready blocking: ttyS%d, count = %d\n",
2103
               info->line, info->count);/**/
2104
#endif
2105
        schedule();
2106
    }
2107
    current->state = TASK_RUNNING;
2108
    remove_wait_queue(&info->open_wait, &wait);
2109
    if (!tty_hung_up_p(filp)){
2110
        info->count++;
2111
#ifdef SERIAL_DEBUG_COUNT
2112
    printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
2113
#endif
2114
    }
2115
    info->blocked_open--;
2116
#ifdef SERIAL_DEBUG_OPEN
2117
    printk("block_til_ready after blocking: ttyS%d, count = %d\n",
2118
           info->line, info->count);/**/
2119
#endif
2120
    if (retval)
2121
            return retval;
2122
    info->flags |= ASYNC_NORMAL_ACTIVE;
2123
    return 0;
2124
} /* block_til_ready */
2125
 
2126
/*
2127
 * This routine is called whenever a serial port is opened.  It
2128
 * performs the serial-specific initialization for the tty structure.
2129
 */
2130
int
2131
cy_open(struct tty_struct *tty, struct file * filp)
2132
{
2133
  struct cyclades_port  *info;
2134
  int retval, line;
2135
 
2136
/* CP('O'); */
2137
    line = MINOR(tty->device) - tty->driver.minor_start;
2138
    if ((line < 0) || (NR_PORTS <= line)){
2139
        return -ENODEV;
2140
    }
2141
    info = &cy_port[line];
2142
    if (info->line < 0){
2143
        return -ENODEV;
2144
    }
2145
#ifdef SERIAL_DEBUG_OTHER
2146
    printk("cy_open ttyS%d\n", info->line); /* */
2147
#endif
2148
    if (serial_paranoia_check(info, tty->device, "cy_open")){
2149
        return -ENODEV;
2150
    }
2151
#ifdef SERIAL_DEBUG_OPEN
2152
    printk("cy_open ttyS%d, count = %d\n", info->line, info->count);/**/
2153
#endif
2154
    info->count++;
2155
#ifdef SERIAL_DEBUG_COUNT
2156
    printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
2157
#endif
2158
    tty->driver_data = info;
2159
    info->tty = tty;
2160
 
2161
    if (!tmp_buf) {
2162
        tmp_buf = (unsigned char *) get_free_page(GFP_KERNEL);
2163
        if (!tmp_buf){
2164
            return -ENOMEM;
2165
        }
2166
    }
2167
 
2168
    if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
2169
        if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
2170
            *tty->termios = info->normal_termios;
2171
        else
2172
            *tty->termios = info->callout_termios;
2173
    }
2174
    /*
2175
     * Start up serial port
2176
     */
2177
    retval = startup(info);
2178
    if (retval){
2179
        return retval;
2180
    }
2181
 
2182
    retval = block_til_ready(tty, filp, info);
2183
    if (retval) {
2184
#ifdef SERIAL_DEBUG_OPEN
2185
        printk("cy_open returning after block_til_ready with %d\n",
2186
               retval);
2187
#endif
2188
        return retval;
2189
    }
2190
 
2191
    info->session = current->session;
2192
    info->pgrp = current->pgrp;
2193
 
2194
#ifdef SERIAL_DEBUG_OPEN
2195
    printk("cy_open done\n");/**/
2196
#endif
2197
    return 0;
2198
} /* cy_open */
2199
 
2200
 
2201
 
2202
/*
2203
 * ---------------------------------------------------------------------
2204
 * serial167_init() and friends
2205
 *
2206
 * serial167_init() is called at boot-time to initialize the serial driver.
2207
 * ---------------------------------------------------------------------
2208
 */
2209
 
2210
/*
2211
 * This routine prints out the appropriate serial driver version
2212
 * number, and identifies which options were configured into this
2213
 * driver.
2214
 */
2215
static void
2216
show_version(void)
2217
{
2218
    printk("MVME166/167 cd2401 driver\n");
2219
} /* show_version */
2220
 
2221
/* initialize chips on card -- return number of valid
2222
   chips (which is number of ports/4) */
2223
 
2224
/*
2225
 * This initialises the hardware to a reasonable state.  It should
2226
 * probe the chip first so as to copy 166-Bug setup as a default for
2227
 * port 0.  It initialises CMR to CyASYNC; that is never done again, so
2228
 * as to limit the number of CyINIT_CHAN commands in normal running.
2229
 *
2230
 * ... I wonder what I should do if this fails ...
2231
 */
2232
 
2233
void
2234
mvme167_serial_console_setup(int cflag)
2235
{
2236
        volatile unsigned char* base_addr = (u_char *)BASE_ADDR;
2237
        int ch;
2238
        u_char spd;
2239
        u_char rcor, rbpr, badspeed = 0;
2240
        unsigned long flags;
2241
 
2242
        save_flags(flags); cli();
2243
 
2244
        /*
2245
         * First probe channel zero of the chip, to see what speed has
2246
         * been selected.
2247
         */
2248
 
2249
        base_addr[CyCAR] = 0;
2250
 
2251
        rcor = base_addr[CyRCOR] << 5;
2252
        rbpr = base_addr[CyRBPR];
2253
 
2254
        for (spd = 0; spd < sizeof(baud_bpr); spd++)
2255
                if (rbpr == baud_bpr[spd] && rcor == baud_co[spd])
2256
                        break;
2257
        if (spd >= sizeof(baud_bpr)) {
2258
                spd = 14;       /* 19200 */
2259
                badspeed = 1;   /* Failed to identify speed */
2260
        }
2261
        initial_console_speed = spd;
2262
 
2263
        /* OK, we have chosen a speed, now reset and reinitialise */
2264
 
2265
        my_udelay(20000L);      /* Allow time for any active o/p to complete */
2266
        if(base_addr[CyCCR] != 0x00){
2267
            restore_flags(flags);
2268
            /* printk(" chip is never idle (CCR != 0)\n"); */
2269
            return;
2270
        }
2271
 
2272
        base_addr[CyCCR] = CyCHIP_RESET;        /* Reset the chip */
2273
        my_udelay(1000L);
2274
 
2275
        if(base_addr[CyGFRCR] == 0x00){
2276
            restore_flags(flags);
2277
            /* printk(" chip is not responding (GFRCR stayed 0)\n"); */
2278
            return;
2279
        }
2280
 
2281
        /*
2282
         * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms
2283
         * tick
2284
         */
2285
 
2286
        base_addr[CyTPR] = 10;
2287
 
2288
        base_addr[CyPILR1] = 0x01;    /* Interrupt level for modem change */
2289
        base_addr[CyPILR2] = 0x02;    /* Interrupt level for tx ints */
2290
        base_addr[CyPILR3] = 0x03;    /* Interrupt level for rx ints */
2291
 
2292
        /*
2293
         * Attempt to set up all channels to something reasonable, and
2294
         * bang out a INIT_CHAN command.  We should then be able to limit
2295
         * the ammount of fiddling we have to do in normal running.
2296
         */
2297
 
2298
        for (ch = 3; ch >= 0 ; ch--) {
2299
                base_addr[CyCAR] = (u_char)ch;
2300
                base_addr[CyIER] = 0;
2301
                base_addr[CyCMR] = CyASYNC;
2302
                base_addr[CyLICR] = (u_char)ch << 2;
2303
                base_addr[CyLIVR] = 0x5c;
2304
                base_addr[CyTCOR] = baud_co[spd];
2305
                base_addr[CyTBPR] = baud_bpr[spd];
2306
                base_addr[CyRCOR] = baud_co[spd] >> 5;
2307
                base_addr[CyRBPR] = baud_bpr[spd];
2308
                base_addr[CySCHR1] = 'Q' & 0x1f;
2309
                base_addr[CySCHR2] = 'X' & 0x1f;
2310
                base_addr[CySCRL] = 0;
2311
                base_addr[CySCRH] = 0;
2312
                base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
2313
                base_addr[CyCOR2] = 0;
2314
                base_addr[CyCOR3] = Cy_1_STOP;
2315
                base_addr[CyCOR4] = baud_cor4[spd];
2316
                base_addr[CyCOR5] = 0;
2317
                base_addr[CyCOR6] = 0;
2318
                base_addr[CyCOR7] = 0;
2319
                base_addr[CyRTPRL] = 2;
2320
                base_addr[CyRTPRH] = 0;
2321
                base_addr[CyMSVR1] = 0;
2322
                base_addr[CyMSVR2] = 0;
2323
                write_cy_cmd(base_addr,CyINIT_CHAN|CyDIS_RCVR|CyDIS_XMTR);
2324
        }
2325
 
2326
        /*
2327
         * Now do specials for channel zero....
2328
         */
2329
 
2330
        base_addr[CyMSVR1] = CyRTS;
2331
        base_addr[CyMSVR2] = CyDTR;
2332
        base_addr[CyIER] = CyRxData;
2333
        write_cy_cmd(base_addr,CyENB_RCVR|CyENB_XMTR);
2334
 
2335
        restore_flags(flags);
2336
 
2337
        my_udelay(20000L);      /* Let it all settle down */
2338
 
2339
        printk("CD2401 initialised,  chip is rev 0x%02x\n", base_addr[CyGFRCR]);
2340
        if (badspeed)
2341
                printk("  WARNING:  Failed to identify line speed, rcor=%02x,rbpr=%02x\n",
2342
                                        rcor >> 5, rbpr);
2343
} /* serial_console_init */
2344
 
2345
/* The serial driver boot-time initialization code!
2346
    Hardware I/O ports are mapped to character special devices on a
2347
    first found, first allocated manner.  That is, this code searches
2348
    for Cyclom cards in the system.  As each is found, it is probed
2349
    to discover how many chips (and thus how many ports) are present.
2350
    These ports are mapped to the tty ports 64 and upward in monotonic
2351
    fashion.  If an 8-port card is replaced with a 16-port card, the
2352
    port mapping on a following card will shift.
2353
 
2354
    This approach is different from what is used in the other serial
2355
    device driver because the Cyclom is more properly a multiplexer,
2356
    not just an aggregation of serial ports on one card.
2357
 
2358
    If there are more cards with more ports than have been statically
2359
    allocated above, a warning is printed and the extra ports are ignored.
2360
 */
2361
int
2362
serial167_init(void)
2363
{
2364
  struct cyclades_port *info;
2365
  int ret = 0;
2366
  int good_ports = 0;
2367
  int port_num = 0;
2368
  int index;
2369
  int DefSpeed;
2370
#ifdef notyet
2371
  struct sigaction sa;
2372
#endif
2373
 
2374
    if (!(mvme16x_config &MVME16x_CONFIG_GOT_CD2401))
2375
        return 0;
2376
 
2377
#if 0
2378
scrn[1] = '\0';
2379
#endif
2380
 
2381
    show_version();
2382
 
2383
    /* Has "console=0,9600n8" been used in bootinfo to change speed? */
2384
    if (serial_console_cflag)
2385
        DefSpeed = serial_console_cflag & 0017;
2386
    else {
2387
        DefSpeed = initial_console_speed;
2388
        serial_console_info = &cy_port[0];
2389
        serial_console_cflag = DefSpeed | CS8;
2390
#if 0
2391
        serial_console = 64; /*callout_driver.minor_start*/
2392
#endif
2393
    }
2394
 
2395
    /* Initialize the tty_driver structure */
2396
 
2397
    memset(&cy_serial_driver, 0, sizeof(struct tty_driver));
2398
    cy_serial_driver.magic = TTY_DRIVER_MAGIC;
2399
#ifdef CONFIG_DEVFS_FS
2400
    cy_serial_driver.name = "tts/%d";
2401
#else
2402
    cy_serial_driver.name = "ttyS";
2403
#endif
2404
    cy_serial_driver.major = TTY_MAJOR;
2405
    cy_serial_driver.minor_start = 64;
2406
    cy_serial_driver.num = NR_PORTS;
2407
    cy_serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
2408
    cy_serial_driver.subtype = SERIAL_TYPE_NORMAL;
2409
    cy_serial_driver.init_termios = tty_std_termios;
2410
    cy_serial_driver.init_termios.c_cflag =
2411
            B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2412
    cy_serial_driver.flags = TTY_DRIVER_REAL_RAW;
2413
    cy_serial_driver.refcount = &serial_refcount;
2414
    cy_serial_driver.table = serial_table;
2415
    cy_serial_driver.termios = serial_termios;
2416
    cy_serial_driver.termios_locked = serial_termios_locked;
2417
    cy_serial_driver.open = cy_open;
2418
    cy_serial_driver.close = cy_close;
2419
    cy_serial_driver.write = cy_write;
2420
    cy_serial_driver.put_char = cy_put_char;
2421
    cy_serial_driver.flush_chars = cy_flush_chars;
2422
    cy_serial_driver.write_room = cy_write_room;
2423
    cy_serial_driver.chars_in_buffer = cy_chars_in_buffer;
2424
    cy_serial_driver.flush_buffer = cy_flush_buffer;
2425
    cy_serial_driver.ioctl = cy_ioctl;
2426
    cy_serial_driver.throttle = cy_throttle;
2427
    cy_serial_driver.unthrottle = cy_unthrottle;
2428
    cy_serial_driver.set_termios = cy_set_termios;
2429
    cy_serial_driver.stop = cy_stop;
2430
    cy_serial_driver.start = cy_start;
2431
    cy_serial_driver.hangup = cy_hangup;
2432
 
2433
    /*
2434
     * The callout device is just like normal device except for
2435
     * major number and the subtype code.
2436
     */
2437
    cy_callout_driver = cy_serial_driver;
2438
#ifdef CONFIG_DEVFS_FS
2439
    cy_callout_driver.name = "cua/%d";
2440
#else
2441
    cy_callout_driver.name = "cua";
2442
#endif
2443
    cy_callout_driver.major = TTYAUX_MAJOR;
2444
    cy_callout_driver.subtype = SERIAL_TYPE_CALLOUT;
2445
 
2446
    ret = tty_register_driver(&cy_serial_driver);
2447
    if (ret) {
2448
            printk(KERN_ERR "Couldn't register MVME166/7 serial driver\n");
2449
            return ret;
2450
    }
2451
    ret = tty_register_driver(&cy_callout_driver);
2452
    if (ret) {
2453
            printk(KERN_ERR "Couldn't register MVME166/7 callout driver\n");
2454
            goto cleanup_serial_driver;
2455
    }
2456
 
2457
    init_bh(CYCLADES_BH, do_cyclades_bh);
2458
 
2459
    port_num = 0;
2460
    info = cy_port;
2461
    for (index = 0; index < 1; index++) {
2462
 
2463
        good_ports = 4;
2464
 
2465
        if(port_num < NR_PORTS){
2466
            while( good_ports-- && port_num < NR_PORTS){
2467
                /*** initialize port ***/
2468
                info->magic = CYCLADES_MAGIC;
2469
                info->type = PORT_CIRRUS;
2470
                info->card = index;
2471
                info->line = port_num;
2472
                info->flags = STD_COM_FLAGS;
2473
                info->tty = 0;
2474
                info->xmit_fifo_size = 12;
2475
                info->cor1 = CyPARITY_NONE|Cy_8_BITS;
2476
                info->cor2 = CyETC;
2477
                info->cor3 = Cy_1_STOP;
2478
                info->cor4 = 0x08; /* _very_ small receive threshold */
2479
                info->cor5 = 0;
2480
                info->cor6 = 0;
2481
                info->cor7 = 0;
2482
                info->tbpr = baud_bpr[DefSpeed]; /* Tx BPR */
2483
                info->tco = baud_co[DefSpeed]; /* Tx CO */
2484
                info->rbpr = baud_bpr[DefSpeed]; /* Rx BPR */
2485
                info->rco = baud_co[DefSpeed] >> 5; /* Rx CO */
2486
                info->close_delay = 0;
2487
                info->x_char = 0;
2488
                info->event = 0;
2489
                info->count = 0;
2490
#ifdef SERIAL_DEBUG_COUNT
2491
    printk("cyc: %d: setting count to 0\n", __LINE__);
2492
#endif
2493
                info->blocked_open = 0;
2494
                info->default_threshold = 0;
2495
                info->default_timeout = 0;
2496
                info->tqueue.routine = do_softint;
2497
                info->tqueue.data = info;
2498
                info->callout_termios =cy_callout_driver.init_termios;
2499
                info->normal_termios = cy_serial_driver.init_termios;
2500
                init_waitqueue_head(&info->open_wait);
2501
                init_waitqueue_head(&info->close_wait);
2502
                /* info->session */
2503
                /* info->pgrp */
2504
/*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/
2505
                info->read_status_mask = CyTIMEOUT| CySPECHAR| CyBREAK
2506
                                       | CyPARITY| CyFRAME| CyOVERRUN;
2507
                /* info->timeout */
2508
 
2509
                printk("ttyS%1d ", info->line);
2510
                port_num++;info++;
2511
                if(!(port_num & 7)){
2512
                    printk("\n               ");
2513
                }
2514
            }
2515
        }
2516
        printk("\n");
2517
    }
2518
    while( port_num < NR_PORTS){
2519
        info->line = -1;
2520
        port_num++;info++;
2521
    }
2522
#ifdef CONFIG_REMOTE_DEBUG
2523
    debug_setup();
2524
#endif
2525
    ret = request_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt, 0,
2526
                                "cd2401_errors", cd2401_rxerr_interrupt);
2527
    if (ret) {
2528
            printk(KERN_ERR "Could't get cd2401_errors IRQ");
2529
            goto cleanup_callout_driver;
2530
    }
2531
 
2532
    ret = request_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt, 0,
2533
                                "cd2401_modem", cd2401_modem_interrupt);
2534
    if (ret) {
2535
            printk(KERN_ERR "Could't get cd2401_modem IRQ");
2536
            goto cleanup_irq_cd2401_errors;
2537
    }
2538
 
2539
    ret = request_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt, 0,
2540
                                "cd2401_txints", cd2401_tx_interrupt);
2541
    if (ret) {
2542
            printk(KERN_ERR "Could't get cd2401_txints IRQ");
2543
            goto cleanup_irq_cd2401_modem;
2544
    }
2545
 
2546
    ret = request_irq(MVME167_IRQ_SER_RX, cd2401_rx_interrupt, 0,
2547
                                "cd2401_rxints", cd2401_rx_interrupt);
2548
    if (ret) {
2549
            printk(KERN_ERR "Could't get cd2401_rxints IRQ");
2550
            goto cleanup_irq_cd2401_txints;
2551
    }
2552
 
2553
    /* Now we have registered the interrupt handlers, allow the interrupts */
2554
 
2555
    pcc2chip[PccSCCMICR] = 0x15;                /* Serial ints are level 5 */
2556
    pcc2chip[PccSCCTICR] = 0x15;
2557
    pcc2chip[PccSCCRICR] = 0x15;
2558
 
2559
    pcc2chip[PccIMLR] = 3;                      /* Allow PCC2 ints above 3!? */
2560
 
2561
    return 0;
2562
cleanup_irq_cd2401_txints:
2563
    free_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt);
2564
cleanup_irq_cd2401_modem:
2565
    free_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt);
2566
cleanup_irq_cd2401_errors:
2567
    free_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt);
2568
cleanup_callout_driver:
2569
    if (tty_unregister_driver(&cy_callout_driver))
2570
            printk(KERN_ERR "Couldn't unregister MVME166/7 callout driver\n");
2571
cleanup_serial_driver:
2572
    if (tty_unregister_driver(&cy_serial_driver))
2573
            printk(KERN_ERR "Couldn't unregister MVME166/7 serial driver\n");
2574
    return ret;
2575
} /* serial167_init */
2576
 
2577
 
2578
#ifdef CYCLOM_SHOW_STATUS
2579
static void
2580
show_status(int line_num)
2581
{
2582
  volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2583
  int channel;
2584
  struct cyclades_port * info;
2585
  unsigned long flags;
2586
 
2587
    info = &cy_port[line_num];
2588
    channel = info->line;
2589
    printk("  channel %d\n", channel);/**/
2590
 
2591
    printk(" cy_port\n");
2592
    printk("  card line flags = %d %d %x\n",
2593
                 info->card, info->line, info->flags);
2594
    printk("  *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n",
2595
                 (long)info->tty, info->read_status_mask,
2596
                 info->timeout, info->xmit_fifo_size);
2597
    printk("  cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n",
2598
             info->cor1, info->cor2, info->cor3, info->cor4, info->cor5,
2599
                        info->cor6, info->cor7);
2600
    printk("  tbpr,tco,rbpr,rco = %d %d %d %d\n",
2601
             info->tbpr, info->tco, info->rbpr, info->rco);
2602
    printk("  close_delay event count = %d %d %d\n",
2603
             info->close_delay, info->event, info->count);
2604
    printk("  x_char blocked_open = %x %x\n",
2605
             info->x_char, info->blocked_open);
2606
    printk("  session pgrp open_wait = %lx %lx %lx\n",
2607
             info->session, info->pgrp, (long)info->open_wait);
2608
 
2609
 
2610
    save_flags(flags); cli();
2611
 
2612
/* Global Registers */
2613
 
2614
        printk(" CyGFRCR %x\n", base_addr[CyGFRCR]);
2615
        printk(" CyCAR %x\n", base_addr[CyCAR]);
2616
        printk(" CyRISR %x\n", base_addr[CyRISR]);
2617
        printk(" CyTISR %x\n", base_addr[CyTISR]);
2618
        printk(" CyMISR %x\n", base_addr[CyMISR]);
2619
        printk(" CyRIR %x\n", base_addr[CyRIR]);
2620
        printk(" CyTIR %x\n", base_addr[CyTIR]);
2621
        printk(" CyMIR %x\n", base_addr[CyMIR]);
2622
        printk(" CyTPR %x\n", base_addr[CyTPR]);
2623
 
2624
        base_addr[CyCAR] = (u_char)channel;
2625
 
2626
/* Virtual Registers */
2627
 
2628
#if 0
2629
        printk(" CyRIVR %x\n", base_addr[CyRIVR]);
2630
        printk(" CyTIVR %x\n", base_addr[CyTIVR]);
2631
        printk(" CyMIVR %x\n", base_addr[CyMIVR]);
2632
        printk(" CyMISR %x\n", base_addr[CyMISR]);
2633
#endif
2634
 
2635
/* Channel Registers */
2636
 
2637
        printk(" CyCCR %x\n", base_addr[CyCCR]);
2638
        printk(" CyIER %x\n", base_addr[CyIER]);
2639
        printk(" CyCOR1 %x\n", base_addr[CyCOR1]);
2640
        printk(" CyCOR2 %x\n", base_addr[CyCOR2]);
2641
        printk(" CyCOR3 %x\n", base_addr[CyCOR3]);
2642
        printk(" CyCOR4 %x\n", base_addr[CyCOR4]);
2643
        printk(" CyCOR5 %x\n", base_addr[CyCOR5]);
2644
#if 0
2645
        printk(" CyCCSR %x\n", base_addr[CyCCSR]);
2646
        printk(" CyRDCR %x\n", base_addr[CyRDCR]);
2647
#endif
2648
        printk(" CySCHR1 %x\n", base_addr[CySCHR1]);
2649
        printk(" CySCHR2 %x\n", base_addr[CySCHR2]);
2650
#if 0
2651
        printk(" CySCHR3 %x\n", base_addr[CySCHR3]);
2652
        printk(" CySCHR4 %x\n", base_addr[CySCHR4]);
2653
        printk(" CySCRL %x\n", base_addr[CySCRL]);
2654
        printk(" CySCRH %x\n", base_addr[CySCRH]);
2655
        printk(" CyLNC %x\n", base_addr[CyLNC]);
2656
        printk(" CyMCOR1 %x\n", base_addr[CyMCOR1]);
2657
        printk(" CyMCOR2 %x\n", base_addr[CyMCOR2]);
2658
#endif
2659
        printk(" CyRTPRL %x\n", base_addr[CyRTPRL]);
2660
        printk(" CyRTPRH %x\n", base_addr[CyRTPRH]);
2661
        printk(" CyMSVR1 %x\n", base_addr[CyMSVR1]);
2662
        printk(" CyMSVR2 %x\n", base_addr[CyMSVR2]);
2663
        printk(" CyRBPR %x\n", base_addr[CyRBPR]);
2664
        printk(" CyRCOR %x\n", base_addr[CyRCOR]);
2665
        printk(" CyTBPR %x\n", base_addr[CyTBPR]);
2666
        printk(" CyTCOR %x\n", base_addr[CyTCOR]);
2667
 
2668
    restore_flags(flags);
2669
} /* show_status */
2670
#endif
2671
 
2672
 
2673
#if 0
2674
/* Dummy routine in mvme16x/config.c for now */
2675
 
2676
/* Serial console setup. Called from linux/init/main.c */
2677
 
2678
void console_setup(char *str, int *ints)
2679
{
2680
        char *s;
2681
        int baud, bits, parity;
2682
        int cflag = 0;
2683
 
2684
        /* Sanity check. */
2685
        if (ints[0] > 3 || ints[1] > 3) return;
2686
 
2687
        /* Get baud, bits and parity */
2688
        baud = 2400;
2689
        bits = 8;
2690
        parity = 'n';
2691
        if (ints[2]) baud = ints[2];
2692
        if ((s = strchr(str, ','))) {
2693
                do {
2694
                        s++;
2695
                } while(*s >= '0' && *s <= '9');
2696
                if (*s) parity = *s++;
2697
                if (*s) bits   = *s - '0';
2698
        }
2699
 
2700
        /* Now construct a cflag setting. */
2701
        switch(baud) {
2702
                case 1200:
2703
                        cflag |= B1200;
2704
                        break;
2705
                case 9600:
2706
                        cflag |= B9600;
2707
                        break;
2708
                case 19200:
2709
                        cflag |= B19200;
2710
                        break;
2711
                case 38400:
2712
                        cflag |= B38400;
2713
                        break;
2714
                case 2400:
2715
                default:
2716
                        cflag |= B2400;
2717
                        break;
2718
        }
2719
        switch(bits) {
2720
                case 7:
2721
                        cflag |= CS7;
2722
                        break;
2723
                default:
2724
                case 8:
2725
                        cflag |= CS8;
2726
                        break;
2727
        }
2728
        switch(parity) {
2729
                case 'o': case 'O':
2730
                        cflag |= PARODD;
2731
                        break;
2732
                case 'e': case 'E':
2733
                        cflag |= PARENB;
2734
                        break;
2735
        }
2736
 
2737
        serial_console_info = &cy_port[ints[1]];
2738
        serial_console_cflag = cflag;
2739
        serial_console = ints[1] + 64; /*callout_driver.minor_start*/
2740
}
2741
#endif
2742
 
2743
/*
2744
 * The following is probably out of date for 2.1.x serial console stuff.
2745
 *
2746
 * The console is registered early on from arch/m68k/kernel/setup.c, and
2747
 * it therefore relies on the chip being setup correctly by 166-Bug.  This
2748
 * seems reasonable, as the serial port has been used to invoke the system
2749
 * boot.  It also means that this function must not rely on any data
2750
 * initialisation performed by serial167_init() etc.
2751
 *
2752
 * Of course, once the console has been registered, we had better ensure
2753
 * that serial167_init() doesn't leave the chip non-functional.
2754
 *
2755
 * The console must be locked when we get here.
2756
 */
2757
 
2758
void serial167_console_write(struct console *co, const char *str, unsigned count)
2759
{
2760
        volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2761
        unsigned long flags;
2762
        volatile u_char sink;
2763
        u_char ier;
2764
        int port;
2765
        u_char do_lf = 0;
2766
        int i = 0;
2767
 
2768
        save_flags(flags); cli();
2769
 
2770
        /* Ensure transmitter is enabled! */
2771
 
2772
        port = 0;
2773
        base_addr[CyCAR] = (u_char)port;
2774
        while (base_addr[CyCCR])
2775
                ;
2776
        base_addr[CyCCR] = CyENB_XMTR;
2777
 
2778
        ier = base_addr[CyIER];
2779
        base_addr[CyIER] = CyTxMpty;
2780
 
2781
        while (1) {
2782
                if (pcc2chip[PccSCCTICR] & 0x20)
2783
                {
2784
                        /* We have a Tx int. Acknowledge it */
2785
                        sink = pcc2chip[PccTPIACKR];
2786
                        if ((base_addr[CyLICR] >> 2) == port) {
2787
                                if (i == count) {
2788
                                        /* Last char of string is now output */
2789
                                        base_addr[CyTEOIR] = CyNOTRANS;
2790
                                        break;
2791
                                }
2792
                                if (do_lf) {
2793
                                        base_addr[CyTDR] = '\n';
2794
                                        str++;
2795
                                        i++;
2796
                                        do_lf = 0;
2797
                                }
2798
                                else if (*str == '\n') {
2799
                                        base_addr[CyTDR] = '\r';
2800
                                        do_lf = 1;
2801
                                }
2802
                                else {
2803
                                        base_addr[CyTDR] = *str++;
2804
                                        i++;
2805
                                }
2806
                                base_addr[CyTEOIR] = 0;
2807
                        }
2808
                        else
2809
                                base_addr[CyTEOIR] = CyNOTRANS;
2810
                }
2811
        }
2812
 
2813
        base_addr[CyIER] = ier;
2814
 
2815
        restore_flags(flags);
2816
}
2817
 
2818
static kdev_t serial167_console_device(struct console *c)
2819
{
2820
        return MKDEV(TTY_MAJOR, 64 + c->index);
2821
}
2822
 
2823
 
2824
static int __init serial167_console_setup(struct console *co, char *options)
2825
{
2826
        return 0;
2827
}
2828
 
2829
 
2830
static struct console sercons = {
2831
        name:           "ttyS",
2832
        write:          serial167_console_write,
2833
        device:         serial167_console_device,
2834
        setup:          serial167_console_setup,
2835
        flags:          CON_PRINTBUFFER,
2836
        index:          -1,
2837
};
2838
 
2839
 
2840
void __init serial167_console_init(void)
2841
{
2842
        if (vme_brdtype == VME_TYPE_MVME166 ||
2843
                        vme_brdtype == VME_TYPE_MVME167 ||
2844
                        vme_brdtype == VME_TYPE_MVME177) {
2845
                mvme167_serial_console_setup(0);
2846
                register_console(&sercons);
2847
        }
2848
}
2849
 
2850
#ifdef CONFIG_REMOTE_DEBUG
2851
void putDebugChar (int c)
2852
{
2853
        volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2854
        unsigned long flags;
2855
        volatile u_char sink;
2856
        u_char ier;
2857
        int port;
2858
 
2859
        save_flags(flags); cli();
2860
 
2861
        /* Ensure transmitter is enabled! */
2862
 
2863
        port = DEBUG_PORT;
2864
        base_addr[CyCAR] = (u_char)port;
2865
        while (base_addr[CyCCR])
2866
                ;
2867
        base_addr[CyCCR] = CyENB_XMTR;
2868
 
2869
        ier = base_addr[CyIER];
2870
        base_addr[CyIER] = CyTxMpty;
2871
 
2872
        while (1) {
2873
                if (pcc2chip[PccSCCTICR] & 0x20)
2874
                {
2875
                        /* We have a Tx int. Acknowledge it */
2876
                        sink = pcc2chip[PccTPIACKR];
2877
                        if ((base_addr[CyLICR] >> 2) == port) {
2878
                                base_addr[CyTDR] = c;
2879
                                base_addr[CyTEOIR] = 0;
2880
                                break;
2881
                        }
2882
                        else
2883
                                base_addr[CyTEOIR] = CyNOTRANS;
2884
                }
2885
        }
2886
 
2887
        base_addr[CyIER] = ier;
2888
 
2889
        restore_flags(flags);
2890
}
2891
 
2892
int getDebugChar()
2893
{
2894
        volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2895
        unsigned long flags;
2896
        volatile u_char sink;
2897
        u_char ier;
2898
        int port;
2899
        int i, c;
2900
 
2901
        i = debugiq.out;
2902
        if (i != debugiq.in) {
2903
                c = debugiq.buf[i];
2904
                if (++i == DEBUG_LEN)
2905
                        i = 0;
2906
                debugiq.out = i;
2907
                return c;
2908
        }
2909
        /* OK, nothing in queue, wait in poll loop */
2910
 
2911
        save_flags(flags); cli();
2912
 
2913
        /* Ensure receiver is enabled! */
2914
 
2915
        port = DEBUG_PORT;
2916
        base_addr[CyCAR] = (u_char)port;
2917
#if 0
2918
        while (base_addr[CyCCR])
2919
                ;
2920
        base_addr[CyCCR] = CyENB_RCVR;
2921
#endif
2922
        ier = base_addr[CyIER];
2923
        base_addr[CyIER] = CyRxData;
2924
 
2925
        while (1) {
2926
                if (pcc2chip[PccSCCRICR] & 0x20)
2927
                {
2928
                        /* We have a Rx int. Acknowledge it */
2929
                        sink = pcc2chip[PccRPIACKR];
2930
                        if ((base_addr[CyLICR] >> 2) == port) {
2931
                                int cnt = base_addr[CyRFOC];
2932
                                while (cnt-- > 0)
2933
                                {
2934
                                        c = base_addr[CyRDR];
2935
                                        if (c == 0)
2936
                                                printk ("!! debug char is null (cnt=%d) !!", cnt);
2937
                                        else
2938
                                                queueDebugChar (c);
2939
                                }
2940
                                base_addr[CyREOIR] = 0;
2941
                                i = debugiq.out;
2942
                                if (i == debugiq.in)
2943
                                        panic ("Debug input queue empty!");
2944
                                c = debugiq.buf[i];
2945
                                if (++i == DEBUG_LEN)
2946
                                        i = 0;
2947
                                debugiq.out = i;
2948
                                break;
2949
                        }
2950
                        else
2951
                                base_addr[CyREOIR] = CyNOTRANS;
2952
                }
2953
        }
2954
 
2955
        base_addr[CyIER] = ier;
2956
 
2957
        restore_flags(flags);
2958
 
2959
        return (c);
2960
}
2961
 
2962
void queueDebugChar (int c)
2963
{
2964
        int i;
2965
 
2966
        i = debugiq.in;
2967
        debugiq.buf[i] = c;
2968
        if (++i == DEBUG_LEN)
2969
                i = 0;
2970
        if (i != debugiq.out)
2971
                debugiq.in = i;
2972
}
2973
 
2974
static void
2975
debug_setup()
2976
{
2977
  unsigned long flags;
2978
  volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2979
  int   i, cflag;
2980
 
2981
    cflag = B19200;
2982
 
2983
    save_flags(flags); cli();
2984
 
2985
    for (i = 0; i < 4; i++)
2986
    {
2987
        base_addr[CyCAR] = i;
2988
        base_addr[CyLICR] = i << 2;
2989
    }
2990
 
2991
    debugiq.in = debugiq.out = 0;
2992
 
2993
    base_addr[CyCAR] = DEBUG_PORT;
2994
 
2995
    /* baud rate */
2996
    i = cflag & CBAUD;
2997
 
2998
    base_addr[CyIER] = 0;
2999
 
3000
    base_addr[CyCMR] = CyASYNC;
3001
    base_addr[CyLICR] = DEBUG_PORT << 2;
3002
    base_addr[CyLIVR] = 0x5c;
3003
 
3004
    /* tx and rx baud rate */
3005
 
3006
    base_addr[CyTCOR] = baud_co[i];
3007
    base_addr[CyTBPR] = baud_bpr[i];
3008
    base_addr[CyRCOR] = baud_co[i] >> 5;
3009
    base_addr[CyRBPR] = baud_bpr[i];
3010
 
3011
    /* set line characteristics  according configuration */
3012
 
3013
    base_addr[CySCHR1] = 0;
3014
    base_addr[CySCHR2] = 0;
3015
    base_addr[CySCRL] = 0;
3016
    base_addr[CySCRH] = 0;
3017
    base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
3018
    base_addr[CyCOR2] = 0;
3019
    base_addr[CyCOR3] = Cy_1_STOP;
3020
    base_addr[CyCOR4] = baud_cor4[i];
3021
    base_addr[CyCOR5] = 0;
3022
    base_addr[CyCOR6] = 0;
3023
    base_addr[CyCOR7] = 0;
3024
 
3025
    write_cy_cmd(base_addr,CyINIT_CHAN);
3026
    write_cy_cmd(base_addr,CyENB_RCVR);
3027
 
3028
    base_addr[CyCAR] = DEBUG_PORT; /* !!! Is this needed? */
3029
 
3030
    base_addr[CyRTPRL] = 2;
3031
    base_addr[CyRTPRH] = 0;
3032
 
3033
    base_addr[CyMSVR1] = CyRTS;
3034
    base_addr[CyMSVR2] = CyDTR;
3035
 
3036
    base_addr[CyIER] = CyRxData;
3037
 
3038
    restore_flags(flags);
3039
 
3040
} /* debug_setup */
3041
 
3042
#endif
3043
 
3044
MODULE_LICENSE("GPL");

powered by: WebSVN 2.1.0

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