2 * linux/drivers/char/serial167.c
4 * Driver for MVME166/7 board serial ports, which are via a CD2401.
5 * Based very much on cyclades.c.
7 * MVME166/7 work by Richard Hirst [richard@sleepie.demon.co.uk]
9 * ==============================================================
11 * static char rcsid[] =
12 * "$Revision: 1.36.1.4 $$Date: 1995/03/29 06:14:14 $";
14 * linux/kernel/cyclades.c
16 * Maintained by Marcio Saito (cyclades@netcom.com) and
17 * Randolph Bentson (bentson@grieg.seaslug.org)
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.
24 * This version does not support shared irq's.
26 * $Log: cyclades.c,v $
27 * Revision 1.36.1.4 1995/03/29 06:14:14 bentson
28 * disambiguate between Cyclom-16Y and Cyclom-32Ye;
32 * 200 lines of changes record removed - RGH 11-10-95, starting work on
33 * converting this to drive serial ports on mvme166 (cd2401).
35 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 2000/08/25
36 * - get rid of verify_area
37 * - use get_user to access memory from userspace in set_threshold,
38 * set_default_threshold and set_timeout
39 * - don't use the panic function in serial167_init
40 * - do resource release on failure on serial167_init
41 * - include missing restore_flags in mvme167_serial_console_setup
44 #include <linux/config.h>
45 #include <linux/errno.h>
46 #include <linux/signal.h>
47 #include <linux/sched.h>
48 #include <linux/timer.h>
49 #include <linux/tty.h>
50 #include <linux/interrupt.h>
51 #include <linux/serial.h>
52 #include <linux/serialP.h>
53 #include <linux/string.h>
54 #include <linux/fcntl.h>
55 #include <linux/ptrace.h>
56 #include <linux/serial167.h>
57 #include <linux/delay.h>
58 #include <linux/major.h>
60 #include <linux/console.h>
61 #include <linux/module.h>
63 #include <asm/system.h>
65 #include <asm/bitops.h>
66 #include <asm/mvme16xhw.h>
67 #include <asm/bootinfo.h>
68 #include <asm/setup.h>
70 #include <linux/types.h>
71 #include <linux/kernel.h>
73 #include <asm/uaccess.h>
74 #include <linux/init.h>
76 #define SERIAL_PARANOIA_CHECK
77 #undef SERIAL_DEBUG_OPEN
78 #undef SERIAL_DEBUG_THROTTLE
79 #undef SERIAL_DEBUG_OTHER
80 #undef SERIAL_DEBUG_IO
81 #undef SERIAL_DEBUG_COUNT
82 #undef SERIAL_DEBUG_DTR
83 #undef CYCLOM_16Y_HACK
84 #define CYCLOM_ENABLE_MONITORING
87 #define MIN(a,b) ((a) < (b) ? (a) : (b))
90 #define WAKEUP_CHARS 256
92 #define STD_COM_FLAGS (0)
94 #define SERIAL_TYPE_NORMAL 1
96 DECLARE_TASK_QUEUE(tq_cyclades);
98 static struct tty_driver *cy_serial_driver;
99 extern int serial_console;
100 static struct cyclades_port *serial_console_info = NULL;
101 static unsigned int serial_console_cflag = 0;
102 u_char initial_console_speed;
104 /* Base address of cd2401 chip on mvme166/7 */
106 #define BASE_ADDR (0xfff45000)
107 #define pcc2chip ((volatile u_char *)0xfff42000)
108 #define PccSCCMICR 0x1d
109 #define PccSCCTICR 0x1e
110 #define PccSCCRICR 0x1f
111 #define PccTPIACKR 0x25
112 #define PccRPIACKR 0x27
115 /* This is the per-port data structure */
116 struct cyclades_port cy_port[] = {
123 #define NR_PORTS (sizeof(cy_port)/sizeof(struct cyclades_port))
126 * tmp_buf is used as a temporary buffer by serial_write. We need to
127 * lock it in case the copy_from_user blocks while swapping in a page,
128 * and some other program tries to do a serial write at the same time.
129 * Since the lock will only come under contention when the system is
130 * swapping and available memory is low, it makes sense to share one
131 * buffer across all the serial ports, since it significantly saves
132 * memory if large numbers of serial ports are open.
134 static unsigned char *tmp_buf = 0;
135 DECLARE_MUTEX(tmp_buf_sem);
138 * This is used to look up the divisor speeds and the timeouts
139 * We're normally limited to 15 distinct baud rates. The extra
140 * are accessed via settings in info->flags.
141 * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
142 * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
145 static int baud_table[] = {
146 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
147 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000,
151 static char baud_co[] = { /* 25 MHz clock option table */
152 /* value => 00 01 02 03 04 */
153 /* divide by 8 32 128 512 2048 */
154 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
155 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
157 static char baud_bpr[] = { /* 25 MHz baud rate period table */
158 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
159 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15};
162 /* I think 166 brd clocks 2401 at 20MHz.... */
164 /* These values are written directly to tcor, and >> 5 for writing to rcor */
165 static u_char baud_co[] = { /* 20 MHz clock option table */
166 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x60, 0x60, 0x40,
167 0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
169 /* These values written directly to tbpr/rbpr */
170 static u_char baud_bpr[] = { /* 20 MHz baud rate period table */
171 0x00, 0xc0, 0x80, 0x58, 0x6c, 0x40, 0xc0, 0x81, 0x40, 0x81,
172 0x57, 0x40, 0x81, 0x40, 0x81, 0x40, 0x2b, 0x20, 0x15, 0x10};
174 static u_char baud_cor4[] = { /* receive threshold */
175 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
176 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07};
180 static void shutdown(struct cyclades_port *);
181 static int startup (struct cyclades_port *);
182 static void cy_throttle(struct tty_struct *);
183 static void cy_unthrottle(struct tty_struct *);
184 static void config_setup(struct cyclades_port *);
185 extern void console_print(const char *);
186 #ifdef CYCLOM_SHOW_STATUS
187 static void show_status(int);
190 #ifdef CONFIG_REMOTE_DEBUG
191 static void debug_setup(void);
192 void queueDebugChar (int c);
193 int getDebugChar(void);
196 #define DEBUG_LEN 256
201 unsigned char buf[DEBUG_LEN];
208 * I have my own version of udelay(), as it is needed when initialising
209 * the chip, before the delay loop has been calibrated. Should probably
210 * reference one of the vmechip2 or pccchip2 counter for an accurate
211 * delay, but this wild guess will do for now.
214 void my_udelay (long us)
217 volatile u_char *p = &x;
221 for (i = 100; i; i--)
226 serial_paranoia_check(struct cyclades_port *info, char *name,
229 #ifdef SERIAL_PARANOIA_CHECK
230 static const char *badmagic =
231 "Warning: bad magic number for serial struct (%s) in %s\n";
232 static const char *badinfo =
233 "Warning: null cyclades_port for (%s) in %s\n";
234 static const char *badrange =
235 "Warning: cyclades_port out of range for (%s) in %s\n";
238 printk(badinfo, name, routine);
242 if( (long)info < (long)(&cy_port[0])
243 || (long)(&cy_port[NR_PORTS]) < (long)info ){
244 printk(badrange, name, routine);
248 if (info->magic != CYCLADES_MAGIC) {
249 printk(badmagic, name, routine);
254 } /* serial_paranoia_check */
257 /* The following diagnostic routines allow the driver to spew
258 information on the screen, even (especially!) during interrupts.
263 local_irq_save(flags);
265 local_irq_restore(flags);
271 local_irq_save(flags);
274 local_irq_restore(flags);
277 void CP1(int data) { (data<10)? CP(data+'0'): CP(data+'A'-10); }/* CP1 */
278 void CP2(int data) { CP1((data>>4) & 0x0f); CP1( data & 0x0f); }/* CP2 */
279 void CP4(int data) { CP2((data>>8) & 0xff); CP2(data & 0xff); }/* CP4 */
280 void CP8(long data) { CP4((data>>16) & 0xffff); CP4(data & 0xffff); }/* CP8 */
283 /* This routine waits up to 1000 micro-seconds for the previous
284 command to the Cirrus chip to complete and then issues the
285 new command. An error is returned if the previous command
286 didn't finish within the time limit.
289 write_cy_cmd(volatile u_char *base_addr, u_char cmd)
294 local_irq_save(flags);
295 /* Check to see that the previous command has completed */
296 for(i = 0 ; i < 100 ; i++){
297 if (base_addr[CyCCR] == 0){
302 /* if the CCR never cleared, the previous command
303 didn't finish within the "reasonable time" */
305 local_irq_restore(flags);
309 /* Issue the new command */
310 base_addr[CyCCR] = cmd;
311 local_irq_restore(flags);
316 /* cy_start and cy_stop provide software output flow control as a
317 function of XON/XOFF, software CTS, and other such stuff. */
320 cy_stop(struct tty_struct *tty)
322 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
323 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
327 #ifdef SERIAL_DEBUG_OTHER
328 printk("cy_stop %s\n", tty->name); /* */
331 if (serial_paranoia_check(info, tty->name, "cy_stop"))
334 channel = info->line;
336 local_irq_save(flags);
337 base_addr[CyCAR] = (u_char)(channel); /* index channel */
338 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
339 local_irq_restore(flags);
345 cy_start(struct tty_struct *tty)
347 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
348 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
352 #ifdef SERIAL_DEBUG_OTHER
353 printk("cy_start %s\n", tty->name); /* */
356 if (serial_paranoia_check(info, tty->name, "cy_start"))
359 channel = info->line;
361 local_irq_save(flags);
362 base_addr[CyCAR] = (u_char)(channel);
363 base_addr[CyIER] |= CyTxMpty;
364 local_irq_restore(flags);
371 * This routine is used by the interrupt handler to schedule
372 * processing in the software interrupt portion of the driver
373 * (also known as the "bottom half"). This can be called any
374 * number of times for any channel without harm.
377 cy_sched_event(struct cyclades_port *info, int event)
379 info->event |= 1 << event; /* remember what kind of event and who */
380 queue_task(&info->tqueue, &tq_cyclades); /* it belongs to */
381 mark_bh(CYCLADES_BH); /* then trigger event */
382 } /* cy_sched_event */
385 /* The real interrupt service routines are called
386 whenever the card wants its hand held--chars
387 received, out buffer empty, modem change, etc.
390 cd2401_rxerr_interrupt(int irq, void *dev_id, struct pt_regs *fp)
392 struct tty_struct *tty;
393 struct cyclades_port *info;
394 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
395 unsigned char err, rfoc;
399 /* determine the channel and change to that context */
400 channel = (u_short ) (base_addr[CyLICR] >> 2);
401 info = &cy_port[channel];
402 info->last_active = jiffies;
404 if ((err = base_addr[CyRISR]) & CyTIMEOUT) {
405 /* This is a receive timeout interrupt, ignore it */
406 base_addr[CyREOIR] = CyNOTRANS;
410 /* Read a byte of data if there is any - assume the error
411 * is associated with this character */
413 if ((rfoc = base_addr[CyRFOC]) != 0)
414 data = base_addr[CyRDR];
418 /* if there is nowhere to put the data, discard it */
420 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
423 else { /* there is an open port for this data */
425 if(err & info->ignore_status_mask){
426 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
429 if (tty->flip.count < TTY_FLIPBUF_SIZE){
431 if (err & info->read_status_mask){
433 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
434 *tty->flip.char_buf_ptr++ = data;
435 if (info->flags & ASYNC_SAK){
438 }else if(err & CyFRAME){
439 *tty->flip.flag_buf_ptr++ = TTY_FRAME;
440 *tty->flip.char_buf_ptr++ = data;
441 }else if(err & CyPARITY){
442 *tty->flip.flag_buf_ptr++ = TTY_PARITY;
443 *tty->flip.char_buf_ptr++ = data;
444 }else if(err & CyOVERRUN){
445 *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
446 *tty->flip.char_buf_ptr++ = 0;
448 If the flip buffer itself is
449 overflowing, we still loose
450 the next incoming character.
452 if(tty->flip.count < TTY_FLIPBUF_SIZE){
454 *tty->flip.flag_buf_ptr++ = TTY_NORMAL;
455 *tty->flip.char_buf_ptr++ = data;
457 /* These two conditions may imply */
458 /* a normal read should be done. */
459 /* else if(data & CyTIMEOUT) */
460 /* else if(data & CySPECHAR) */
462 *tty->flip.flag_buf_ptr++ = 0;
463 *tty->flip.char_buf_ptr++ = 0;
466 *tty->flip.flag_buf_ptr++ = 0;
467 *tty->flip.char_buf_ptr++ = 0;
470 /* there was a software buffer overrun
471 and nothing could be done about it!!! */
474 queue_task(&tty->flip.tqueue, &tq_timer);
476 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
478 } /* cy_rxerr_interrupt */
481 cd2401_modem_interrupt(int irq, void *dev_id, struct pt_regs *fp)
483 struct cyclades_port *info;
484 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
490 /* determine the channel and change to that context */
491 channel = (u_short ) (base_addr[CyLICR] >> 2);
492 info = &cy_port[channel];
493 info->last_active = jiffies;
495 mdm_change = base_addr[CyMISR];
496 mdm_status = base_addr[CyMSVR1];
498 if(info->tty == 0){ /* nowhere to put the data, ignore it */
501 if((mdm_change & CyDCD)
502 && (info->flags & ASYNC_CHECK_CD)){
503 if(mdm_status & CyDCD){
505 cy_sched_event(info, Cy_EVENT_OPEN_WAKEUP);
508 cy_sched_event(info, Cy_EVENT_HANGUP);
511 if((mdm_change & CyCTS)
512 && (info->flags & ASYNC_CTS_FLOW)){
513 if(info->tty->stopped){
514 if(mdm_status & CyCTS){
515 /* !!! cy_start isn't used because... */
516 info->tty->stopped = 0;
517 base_addr[CyIER] |= CyTxMpty;
518 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
521 if(!(mdm_status & CyCTS)){
522 /* !!! cy_stop isn't used because... */
523 info->tty->stopped = 1;
524 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
528 if(mdm_status & CyDSR){
531 base_addr[CyMEOIR] = 0;
533 } /* cy_modem_interrupt */
536 cd2401_tx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
538 struct cyclades_port *info;
539 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
541 int char_count, saved_cnt;
544 /* determine the channel and change to that context */
545 channel = (u_short ) (base_addr[CyLICR] >> 2);
547 #ifdef CONFIG_REMOTE_DEBUG
548 if (channel == DEBUG_PORT) {
549 panic ("TxInt on debug port!!!");
553 info = &cy_port[channel];
555 /* validate the port number (as configured and open) */
556 if( (channel < 0) || (NR_PORTS <= channel) ){
557 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
558 base_addr[CyTEOIR] = CyNOTRANS;
561 info->last_active = jiffies;
563 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
564 if (info->xmit_cnt < WAKEUP_CHARS) {
565 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
567 base_addr[CyTEOIR] = CyNOTRANS;
571 /* load the on-chip space available for outbound data */
572 saved_cnt = char_count = base_addr[CyTFTC];
574 if(info->x_char) { /* send special char */
575 outch = info->x_char;
576 base_addr[CyTDR] = outch;
582 /* The Cirrus chip requires the "Embedded Transmit
583 Commands" of start break, delay, and end break
584 sequences to be sent. The duration of the
585 break is given in TICs, which runs at HZ
586 (typically 100) and the PPR runs at 200 Hz,
587 so the delay is duration * 200/HZ, and thus a
588 break can run from 1/100 sec to about 5/4 sec.
589 Need to check these values - RGH 141095.
591 base_addr[CyTDR] = 0; /* start break */
592 base_addr[CyTDR] = 0x81;
593 base_addr[CyTDR] = 0; /* delay a bit */
594 base_addr[CyTDR] = 0x82;
595 base_addr[CyTDR] = info->x_break*200/HZ;
596 base_addr[CyTDR] = 0; /* terminate break */
597 base_addr[CyTDR] = 0x83;
602 while (char_count > 0){
603 if (!info->xmit_cnt){
604 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
607 if (info->xmit_buf == 0){
608 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
611 if (info->tty->stopped || info->tty->hw_stopped){
612 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
615 /* Because the Embedded Transmit Commands have been
616 enabled, we must check to see if the escape
617 character, NULL, is being sent. If it is, we
618 must ensure that there is room for it to be
619 doubled in the output stream. Therefore we
620 no longer advance the pointer when the character
621 is fetched, but rather wait until after the check
622 for a NULL output character. (This is necessary
623 because there may not be room for the two chars
624 needed to send a NULL.
626 outch = info->xmit_buf[info->xmit_tail];
629 info->xmit_tail = (info->xmit_tail + 1)
631 base_addr[CyTDR] = outch;
636 info->xmit_tail = (info->xmit_tail + 1)
638 base_addr[CyTDR] = outch;
639 base_addr[CyTDR] = 0;
648 if (info->xmit_cnt < WAKEUP_CHARS) {
649 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
651 base_addr[CyTEOIR] = (char_count != saved_cnt) ? 0 : CyNOTRANS;
653 } /* cy_tx_interrupt */
656 cd2401_rx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
658 struct tty_struct *tty;
659 struct cyclades_port *info;
660 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
666 /* determine the channel and change to that context */
667 channel = (u_short ) (base_addr[CyLICR] >> 2);
668 info = &cy_port[channel];
669 info->last_active = jiffies;
670 save_cnt = char_count = base_addr[CyRFOC];
672 #ifdef CONFIG_REMOTE_DEBUG
673 if (channel == DEBUG_PORT) {
674 while (char_count--) {
675 data = base_addr[CyRDR];
676 queueDebugChar(data);
681 /* if there is nowhere to put the data, discard it */
684 data = base_addr[CyRDR];
686 }else{ /* there is an open port for this data */
688 /* load # characters available from the chip */
690 #ifdef CYCLOM_ENABLE_MONITORING
691 ++info->mon.int_count;
692 info->mon.char_count += char_count;
693 if (char_count > info->mon.char_max)
694 info->mon.char_max = char_count;
695 info->mon.char_last = char_count;
698 data = base_addr[CyRDR];
699 if (tty->flip.count >= TTY_FLIPBUF_SIZE){
703 *tty->flip.flag_buf_ptr++ = TTY_NORMAL;
704 *tty->flip.char_buf_ptr++ = data;
705 #ifdef CYCLOM_16Y_HACK
709 queue_task(&tty->flip.tqueue, &tq_timer);
712 base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS;
714 } /* cy_rx_interrupt */
717 * This routine is used to handle the "bottom half" processing for the
718 * serial driver, known also the "software interrupt" processing.
719 * This processing is done at the kernel interrupt level, after the
720 * cy_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
721 * is where time-consuming activities which can not be done in the
722 * interrupt driver proper are done; the interrupt driver schedules
723 * them using cy_sched_event(), and they get done here.
725 * This is done through one level of indirection--the task queue.
726 * When a hardware interrupt service routine wants service by the
727 * driver's bottom half, it enqueues the appropriate tq_struct (one
728 * per port) to the tq_cyclades work queue and sets a request flag
729 * via mark_bh for processing that queue. When the time is right,
730 * do_cyclades_bh is called (because of the mark_bh) and it requests
731 * that the work queue be processed.
733 * Although this may seem unwieldy, it gives the system a way to
734 * pass an argument (in this case the pointer to the cyclades_port
735 * structure) to the bottom half of the driver. Previous kernels
736 * had to poll every port to see if that port needed servicing.
741 run_task_queue(&tq_cyclades);
742 } /* do_cyclades_bh */
745 do_softint(void *private_)
747 struct cyclades_port *info = (struct cyclades_port *) private_;
748 struct tty_struct *tty;
754 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
755 tty_hangup(info->tty);
756 wake_up_interruptible(&info->open_wait);
757 info->flags &= ~ASYNC_NORMAL_ACTIVE;
759 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) {
760 wake_up_interruptible(&info->open_wait);
762 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
763 if((tty->flags & (1<< TTY_DO_WRITE_WAKEUP))
764 && tty->ldisc.write_wakeup){
765 (tty->ldisc.write_wakeup)(tty);
767 wake_up_interruptible(&tty->write_wait);
772 /* This is called whenever a port becomes active;
773 interrupts are enabled and DTR & RTS are turned on.
776 startup(struct cyclades_port * info)
779 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
782 if (info->flags & ASYNC_INITIALIZED){
788 set_bit(TTY_IO_ERROR, &info->tty->flags);
792 if (!info->xmit_buf){
793 info->xmit_buf = (unsigned char *) get_zeroed_page (GFP_KERNEL);
794 if (!info->xmit_buf){
801 channel = info->line;
803 #ifdef SERIAL_DEBUG_OPEN
804 printk("startup channel %d\n", channel);
807 local_irq_save(flags);
808 base_addr[CyCAR] = (u_char)channel;
809 write_cy_cmd(base_addr,CyENB_RCVR|CyENB_XMTR);
811 base_addr[CyCAR] = (u_char)channel; /* !!! Is this needed? */
812 base_addr[CyMSVR1] = CyRTS;
813 /* CP('S');CP('1'); */
814 base_addr[CyMSVR2] = CyDTR;
816 #ifdef SERIAL_DEBUG_DTR
817 printk("cyc: %d: raising DTR\n", __LINE__);
818 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
821 base_addr[CyIER] |= CyRxData;
822 info->flags |= ASYNC_INITIALIZED;
825 clear_bit(TTY_IO_ERROR, &info->tty->flags);
827 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
829 local_irq_restore(flags);
831 #ifdef SERIAL_DEBUG_OPEN
838 start_xmit( struct cyclades_port *info )
841 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
844 channel = info->line;
845 local_irq_save(flags);
846 base_addr[CyCAR] = channel;
847 base_addr[CyIER] |= CyTxMpty;
848 local_irq_restore(flags);
852 * This routine shuts down a serial port; interrupts are disabled,
853 * and DTR is dropped if the hangup on close termio flag is on.
856 shutdown(struct cyclades_port * info)
859 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
862 if (!(info->flags & ASYNC_INITIALIZED)){
867 channel = info->line;
869 #ifdef SERIAL_DEBUG_OPEN
870 printk("shutdown channel %d\n", channel);
873 /* !!! REALLY MUST WAIT FOR LAST CHARACTER TO BE
874 SENT BEFORE DROPPING THE LINE !!! (Perhaps
875 set some flag that is read when XMTY happens.)
876 Other choices are to delay some fixed interval
877 or schedule some later processing.
879 local_irq_save(flags);
881 free_page((unsigned long) info->xmit_buf);
885 base_addr[CyCAR] = (u_char)channel;
886 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
887 base_addr[CyMSVR1] = 0;
888 /* CP('C');CP('1'); */
889 base_addr[CyMSVR2] = 0;
890 #ifdef SERIAL_DEBUG_DTR
891 printk("cyc: %d: dropping DTR\n", __LINE__);
892 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
895 write_cy_cmd(base_addr,CyDIS_RCVR);
896 /* it may be appropriate to clear _XMIT at
897 some later date (after testing)!!! */
900 set_bit(TTY_IO_ERROR, &info->tty->flags);
902 info->flags &= ~ASYNC_INITIALIZED;
903 local_irq_restore(flags);
905 #ifdef SERIAL_DEBUG_OPEN
912 * This routine finds or computes the various line characteristics.
915 config_setup(struct cyclades_port * info)
918 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
922 unsigned char ti, need_init_chan = 0;
924 if (!info->tty || !info->tty->termios){
927 if (info->line == -1){
930 cflag = info->tty->termios->c_cflag;
935 /* Starting with kernel 1.1.65, there is direct support for
936 higher baud rates. The following code supports those
937 changes. The conditional aspect allows this driver to be
938 used for earlier as well as later kernel versions. (The
939 mapping is slightly different from serial.c because there
940 is still the possibility of supporting 75 kbit/sec with
946 else if(i == B115200)
953 info->tty->termios->c_cflag &= ~CBAUDEX;
957 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
959 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
962 /* Don't ever change the speed of the console port. It will
963 * run at the speed specified in bootinfo, or at 19.2K */
964 /* Actually, it should run at whatever speed 166Bug was using */
965 /* Note info->timeout isn't used at present */
966 if (info != serial_console_info) {
967 info->tbpr = baud_bpr[i]; /* Tx BPR */
968 info->tco = baud_co[i]; /* Tx CO */
969 info->rbpr = baud_bpr[i]; /* Rx BPR */
970 info->rco = baud_co[i] >> 5; /* Rx CO */
971 if (baud_table[i] == 134) {
972 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
973 /* get it right for 134.5 baud */
974 } else if (baud_table[i]) {
975 info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2;
976 /* this needs to be propagated into the card info */
981 /* By tradition (is it a standard?) a baud rate of zero
982 implies the line should be/has been closed. A bit
983 later in this routine such a test is performed. */
985 /* byte size and parity */
989 info->cor4 = (info->default_threshold
990 ? info->default_threshold
991 : baud_cor4[i]); /* receive threshold */
992 /* Following two lines added 101295, RGH. */
993 /* It is obviously wrong to access CyCORx, and not info->corx here,
994 * try and remember to fix it later! */
995 channel = info->line;
996 base_addr[CyCAR] = (u_char)channel;
997 if (C_CLOCAL(info->tty)) {
998 if (base_addr[CyIER] & CyMdmCh)
999 base_addr[CyIER] &= ~CyMdmCh; /* without modem intr */
1000 /* ignore 1->0 modem transitions */
1001 if (base_addr[CyCOR4] & (CyDSR|CyCTS|CyDCD))
1002 base_addr[CyCOR4] &= ~(CyDSR|CyCTS|CyDCD);
1003 /* ignore 0->1 modem transitions */
1004 if (base_addr[CyCOR5] & (CyDSR|CyCTS|CyDCD))
1005 base_addr[CyCOR5] &= ~(CyDSR|CyCTS|CyDCD);
1007 if ((base_addr[CyIER] & CyMdmCh) != CyMdmCh)
1008 base_addr[CyIER] |= CyMdmCh; /* with modem intr */
1009 /* act on 1->0 modem transitions */
1010 if ((base_addr[CyCOR4] & (CyDSR|CyCTS|CyDCD)) != (CyDSR|CyCTS|CyDCD))
1011 base_addr[CyCOR4] |= CyDSR|CyCTS|CyDCD;
1012 /* act on 0->1 modem transitions */
1013 if ((base_addr[CyCOR5] & (CyDSR|CyCTS|CyDCD)) != (CyDSR|CyCTS|CyDCD))
1014 base_addr[CyCOR5] |= CyDSR|CyCTS|CyDCD;
1016 info->cor3 = (cflag & CSTOPB) ? Cy_2_STOP : Cy_1_STOP;
1018 switch(cflag & CSIZE){
1020 info->cor1 = Cy_5_BITS;
1023 info->cor1 = Cy_6_BITS;
1026 info->cor1 = Cy_7_BITS;
1029 info->cor1 = Cy_8_BITS;
1032 if (cflag & PARENB){
1033 if (cflag & PARODD){
1034 info->cor1 |= CyPARITY_O;
1036 info->cor1 |= CyPARITY_E;
1039 info->cor1 |= CyPARITY_NONE;
1042 /* CTS flow control flag */
1044 /* Don't complcate matters for now! RGH 141095 */
1045 if (cflag & CRTSCTS){
1046 info->flags |= ASYNC_CTS_FLOW;
1047 info->cor2 |= CyCtsAE;
1049 info->flags &= ~ASYNC_CTS_FLOW;
1050 info->cor2 &= ~CyCtsAE;
1054 info->flags &= ~ASYNC_CHECK_CD;
1056 info->flags |= ASYNC_CHECK_CD;
1058 /***********************************************
1059 The hardware option, CyRtsAO, presents RTS when
1060 the chip has characters to send. Since most modems
1061 use RTS as reverse (inbound) flow control, this
1062 option is not used. If inbound flow control is
1063 necessary, DTR can be programmed to provide the
1064 appropriate signals for use with a non-standard
1065 cable. Contact Marcio Saito for details.
1066 ***********************************************/
1068 channel = info->line;
1070 local_irq_save(flags);
1071 base_addr[CyCAR] = (u_char)channel;
1073 /* CyCMR set once only in mvme167_init_serial() */
1074 if (base_addr[CyLICR] != channel << 2)
1075 base_addr[CyLICR] = channel << 2;
1076 if (base_addr[CyLIVR] != 0x5c)
1077 base_addr[CyLIVR] = 0x5c;
1079 /* tx and rx baud rate */
1081 if (base_addr[CyCOR1] != info->cor1)
1083 if (base_addr[CyTCOR] != info->tco)
1084 base_addr[CyTCOR] = info->tco;
1085 if (base_addr[CyTBPR] != info->tbpr)
1086 base_addr[CyTBPR] = info->tbpr;
1087 if (base_addr[CyRCOR] != info->rco)
1088 base_addr[CyRCOR] = info->rco;
1089 if (base_addr[CyRBPR] != info->rbpr)
1090 base_addr[CyRBPR] = info->rbpr;
1092 /* set line characteristics according configuration */
1094 if (base_addr[CySCHR1] != START_CHAR(info->tty))
1095 base_addr[CySCHR1] = START_CHAR(info->tty);
1096 if (base_addr[CySCHR2] != STOP_CHAR(info->tty))
1097 base_addr[CySCHR2] = STOP_CHAR(info->tty);
1098 if (base_addr[CySCRL] != START_CHAR(info->tty))
1099 base_addr[CySCRL] = START_CHAR(info->tty);
1100 if (base_addr[CySCRH] != START_CHAR(info->tty))
1101 base_addr[CySCRH] = START_CHAR(info->tty);
1102 if (base_addr[CyCOR1] != info->cor1)
1103 base_addr[CyCOR1] = info->cor1;
1104 if (base_addr[CyCOR2] != info->cor2)
1105 base_addr[CyCOR2] = info->cor2;
1106 if (base_addr[CyCOR3] != info->cor3)
1107 base_addr[CyCOR3] = info->cor3;
1108 if (base_addr[CyCOR4] != info->cor4)
1109 base_addr[CyCOR4] = info->cor4;
1110 if (base_addr[CyCOR5] != info->cor5)
1111 base_addr[CyCOR5] = info->cor5;
1112 if (base_addr[CyCOR6] != info->cor6)
1113 base_addr[CyCOR6] = info->cor6;
1114 if (base_addr[CyCOR7] != info->cor7)
1115 base_addr[CyCOR7] = info->cor7;
1118 write_cy_cmd(base_addr,CyINIT_CHAN);
1120 base_addr[CyCAR] = (u_char)channel; /* !!! Is this needed? */
1122 /* 2ms default rx timeout */
1123 ti = info->default_timeout ? info->default_timeout : 0x02;
1124 if (base_addr[CyRTPRL] != ti)
1125 base_addr[CyRTPRL] = ti;
1126 if (base_addr[CyRTPRH] != 0)
1127 base_addr[CyRTPRH] = 0;
1129 /* Set up RTS here also ????? RGH 141095 */
1130 if(i == 0){ /* baud rate is zero, turn off line */
1131 if ((base_addr[CyMSVR2] & CyDTR) == CyDTR)
1132 base_addr[CyMSVR2] = 0;
1133 #ifdef SERIAL_DEBUG_DTR
1134 printk("cyc: %d: dropping DTR\n", __LINE__);
1135 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1138 if ((base_addr[CyMSVR2] & CyDTR) != CyDTR)
1139 base_addr[CyMSVR2] = CyDTR;
1140 #ifdef SERIAL_DEBUG_DTR
1141 printk("cyc: %d: raising DTR\n", __LINE__);
1142 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1147 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1150 local_irq_restore(flags);
1152 } /* config_setup */
1156 cy_put_char(struct tty_struct *tty, unsigned char ch)
1158 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1159 unsigned long flags;
1161 #ifdef SERIAL_DEBUG_IO
1162 printk("cy_put_char %s(0x%02x)\n", tty->name, ch);
1165 if (serial_paranoia_check(info, tty->name, "cy_put_char"))
1168 if (!tty || !info->xmit_buf)
1171 local_irq_save(flags);
1172 if (info->xmit_cnt >= PAGE_SIZE - 1) {
1173 local_irq_restore(flags);
1177 info->xmit_buf[info->xmit_head++] = ch;
1178 info->xmit_head &= PAGE_SIZE - 1;
1180 local_irq_restore(flags);
1185 cy_flush_chars(struct tty_struct *tty)
1187 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1188 unsigned long flags;
1189 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1192 #ifdef SERIAL_DEBUG_IO
1193 printk("cy_flush_chars %s\n", tty->name); /* */
1196 if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
1199 if (info->xmit_cnt <= 0 || tty->stopped
1200 || tty->hw_stopped || !info->xmit_buf)
1203 channel = info->line;
1205 local_irq_save(flags);
1206 base_addr[CyCAR] = channel;
1207 base_addr[CyIER] |= CyTxMpty;
1208 local_irq_restore(flags);
1209 } /* cy_flush_chars */
1212 /* This routine gets called when tty_write has put something into
1213 the write_queue. If the port is not already transmitting stuff,
1214 start it off by enabling interrupts. The interrupt service
1215 routine will then ensure that the characters are sent. If the
1216 port is already active, there is no need to kick it.
1219 cy_write(struct tty_struct * tty, int from_user,
1220 const unsigned char *buf, int count)
1222 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1223 unsigned long flags;
1226 #ifdef SERIAL_DEBUG_IO
1227 printk("cy_write %s\n", tty->name); /* */
1230 if (serial_paranoia_check(info, tty->name, "cy_write")){
1234 if (!tty || !info->xmit_buf || !tmp_buf){
1241 c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1242 SERIAL_XMIT_SIZE - info->xmit_head));
1246 c -= copy_from_user(tmp_buf, buf, c);
1253 local_irq_save(flags);
1254 c = MIN(c, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1255 SERIAL_XMIT_SIZE - info->xmit_head));
1256 memcpy(info->xmit_buf + info->xmit_head, tmp_buf, c);
1257 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1258 info->xmit_cnt += c;
1259 local_irq_restore(flags);
1268 local_irq_save(flags);
1269 c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1270 SERIAL_XMIT_SIZE - info->xmit_head));
1272 local_irq_restore(flags);
1276 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1277 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1278 info->xmit_cnt += c;
1279 local_irq_restore(flags);
1289 && !tty->hw_stopped ) {
1297 cy_write_room(struct tty_struct *tty)
1299 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1302 #ifdef SERIAL_DEBUG_IO
1303 printk("cy_write_room %s\n", tty->name); /* */
1306 if (serial_paranoia_check(info, tty->name, "cy_write_room"))
1308 ret = PAGE_SIZE - info->xmit_cnt - 1;
1312 } /* cy_write_room */
1316 cy_chars_in_buffer(struct tty_struct *tty)
1318 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1320 #ifdef SERIAL_DEBUG_IO
1321 printk("cy_chars_in_buffer %s %d\n", tty->name, info->xmit_cnt); /* */
1324 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
1327 return info->xmit_cnt;
1328 } /* cy_chars_in_buffer */
1332 cy_flush_buffer(struct tty_struct *tty)
1334 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1335 unsigned long flags;
1337 #ifdef SERIAL_DEBUG_IO
1338 printk("cy_flush_buffer %s\n", tty->name); /* */
1341 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
1343 local_irq_save(flags);
1344 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1345 local_irq_restore(flags);
1346 wake_up_interruptible(&tty->write_wait);
1347 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP))
1348 && tty->ldisc.write_wakeup)
1349 (tty->ldisc.write_wakeup)(tty);
1350 } /* cy_flush_buffer */
1353 /* This routine is called by the upper-layer tty layer to signal
1354 that incoming characters should be throttled or that the
1355 throttle should be released.
1358 cy_throttle(struct tty_struct * tty)
1360 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1361 unsigned long flags;
1362 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1365 #ifdef SERIAL_DEBUG_THROTTLE
1368 printk("throttle %s: %d....\n", tty_name(tty, buf),
1369 tty->ldisc.chars_in_buffer(tty));
1370 printk("cy_throttle %s\n", tty->name);
1373 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")){
1378 info->x_char = STOP_CHAR(tty);
1379 /* Should use the "Send Special Character" feature!!! */
1382 channel = info->line;
1384 local_irq_save(flags);
1385 base_addr[CyCAR] = (u_char)channel;
1386 base_addr[CyMSVR1] = 0;
1387 local_irq_restore(flags);
1394 cy_unthrottle(struct tty_struct * tty)
1396 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1397 unsigned long flags;
1398 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1401 #ifdef SERIAL_DEBUG_THROTTLE
1404 printk("throttle %s: %d....\n", tty_name(tty, buf),
1405 tty->ldisc.chars_in_buffer(tty));
1406 printk("cy_unthrottle %s\n", tty->name);
1409 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")){
1414 info->x_char = START_CHAR(tty);
1415 /* Should use the "Send Special Character" feature!!! */
1418 channel = info->line;
1420 local_irq_save(flags);
1421 base_addr[CyCAR] = (u_char)channel;
1422 base_addr[CyMSVR1] = CyRTS;
1423 local_irq_restore(flags);
1426 } /* cy_unthrottle */
1429 get_serial_info(struct cyclades_port * info,
1430 struct serial_struct * retinfo)
1432 struct serial_struct tmp;
1437 memset(&tmp, 0, sizeof(tmp));
1438 tmp.type = info->type;
1439 tmp.line = info->line;
1440 tmp.port = info->line;
1442 tmp.flags = info->flags;
1443 tmp.baud_base = 0; /*!!!*/
1444 tmp.close_delay = info->close_delay;
1445 tmp.custom_divisor = 0; /*!!!*/
1446 tmp.hub6 = 0; /*!!!*/
1447 return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0;
1448 } /* get_serial_info */
1451 set_serial_info(struct cyclades_port * info,
1452 struct serial_struct * new_info)
1454 struct serial_struct new_serial;
1455 struct cyclades_port old_info;
1460 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
1464 if (!capable(CAP_SYS_ADMIN)) {
1465 if ((new_serial.close_delay != info->close_delay) ||
1466 ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) !=
1467 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK)))
1469 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1470 (new_serial.flags & ASYNC_USR_MASK));
1471 goto check_and_exit;
1476 * OK, past this point, all the error checking has been done.
1477 * At this point, we start making changes.....
1480 info->flags = ((info->flags & ~ASYNC_FLAGS) |
1481 (new_serial.flags & ASYNC_FLAGS));
1482 info->close_delay = new_serial.close_delay;
1486 if (info->flags & ASYNC_INITIALIZED){
1490 return startup(info);
1492 } /* set_serial_info */
1495 cy_tiocmget(struct tty_struct *tty, struct file *file)
1497 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1499 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1500 unsigned long flags;
1501 unsigned char status;
1502 unsigned int result;
1504 channel = info->line;
1506 local_irq_save(flags);
1507 base_addr[CyCAR] = (u_char)channel;
1508 status = base_addr[CyMSVR1] | base_addr[CyMSVR2];
1509 local_irq_restore(flags);
1511 return ((status & CyRTS) ? TIOCM_RTS : 0)
1512 | ((status & CyDTR) ? TIOCM_DTR : 0)
1513 | ((status & CyDCD) ? TIOCM_CAR : 0)
1514 | ((status & CyDSR) ? TIOCM_DSR : 0)
1515 | ((status & CyCTS) ? TIOCM_CTS : 0);
1519 cy_tiocmset(struct tty_struct *tty, struct file *file,
1520 unsigned int set, unsigned int clear)
1522 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1524 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1525 unsigned long flags;
1528 channel = info->line;
1530 if (set & TIOCM_RTS){
1531 local_irq_save(flags);
1532 base_addr[CyCAR] = (u_char)channel;
1533 base_addr[CyMSVR1] = CyRTS;
1534 local_irq_restore(flags);
1536 if (set & TIOCM_DTR){
1537 local_irq_save(flags);
1538 base_addr[CyCAR] = (u_char)channel;
1539 /* CP('S');CP('2'); */
1540 base_addr[CyMSVR2] = CyDTR;
1541 #ifdef SERIAL_DEBUG_DTR
1542 printk("cyc: %d: raising DTR\n", __LINE__);
1543 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1545 local_irq_restore(flags);
1548 if (clear & TIOCM_RTS){
1549 local_irq_save(flags);
1550 base_addr[CyCAR] = (u_char)channel;
1551 base_addr[CyMSVR1] = 0;
1552 local_irq_restore(flags);
1554 if (clear & TIOCM_DTR){
1555 local_irq_save(flags);
1556 base_addr[CyCAR] = (u_char)channel;
1557 /* CP('C');CP('2'); */
1558 base_addr[CyMSVR2] = 0;
1559 #ifdef SERIAL_DEBUG_DTR
1560 printk("cyc: %d: dropping DTR\n", __LINE__);
1561 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1563 local_irq_restore(flags);
1567 } /* set_modem_info */
1570 send_break( struct cyclades_port * info, int duration)
1571 { /* Let the transmit ISR take care of this (since it
1572 requires stuffing characters into the output stream).
1574 info->x_break = duration;
1575 if (!info->xmit_cnt ) {
1581 get_mon_info(struct cyclades_port * info, struct cyclades_monitor * mon)
1584 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
1586 info->mon.int_count = 0;
1587 info->mon.char_count = 0;
1588 info->mon.char_max = 0;
1589 info->mon.char_last = 0;
1594 set_threshold(struct cyclades_port * info, unsigned long *arg)
1596 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1597 unsigned long value;
1600 if (get_user(value, arg))
1603 channel = info->line;
1604 info->cor4 &= ~CyREC_FIFO;
1605 info->cor4 |= value & CyREC_FIFO;
1606 base_addr[CyCOR4] = info->cor4;
1611 get_threshold(struct cyclades_port * info, unsigned long *value)
1613 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1617 channel = info->line;
1619 tmp = base_addr[CyCOR4] & CyREC_FIFO;
1620 return put_user(tmp,value);
1624 set_default_threshold(struct cyclades_port * info, unsigned long *arg)
1626 unsigned long value;
1628 if (get_user(value, arg))
1631 info->default_threshold = value & 0x0f;
1636 get_default_threshold(struct cyclades_port * info, unsigned long *value)
1638 return put_user(info->default_threshold,value);
1642 set_timeout(struct cyclades_port * info, unsigned long *arg)
1644 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1646 unsigned long value;
1648 if (get_user(value, arg))
1651 channel = info->line;
1653 base_addr[CyRTPRL] = value & 0xff;
1654 base_addr[CyRTPRH] = (value >> 8) & 0xff;
1659 get_timeout(struct cyclades_port * info, unsigned long *value)
1661 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1665 channel = info->line;
1667 tmp = base_addr[CyRTPRL];
1668 return put_user(tmp,value);
1672 set_default_timeout(struct cyclades_port * info, unsigned long value)
1674 info->default_timeout = value & 0xff;
1679 get_default_timeout(struct cyclades_port * info, unsigned long *value)
1681 return put_user(info->default_timeout,value);
1685 cy_ioctl(struct tty_struct *tty, struct file * file,
1686 unsigned int cmd, unsigned long arg)
1689 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1692 #ifdef SERIAL_DEBUG_OTHER
1693 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */
1698 ret_val = get_mon_info(info, (struct cyclades_monitor *)arg);
1701 ret_val = get_threshold(info, (unsigned long *)arg);
1704 ret_val = set_threshold(info, (unsigned long *)arg);
1706 case CYGETDEFTHRESH:
1707 ret_val = get_default_threshold(info, (unsigned long *)arg);
1709 case CYSETDEFTHRESH:
1710 ret_val = set_default_threshold(info, (unsigned long *)arg);
1713 ret_val = get_timeout(info, (unsigned long *)arg);
1716 ret_val = set_timeout(info, (unsigned long *)arg);
1718 case CYGETDEFTIMEOUT:
1719 ret_val = get_default_timeout(info, (unsigned long *)arg);
1721 case CYSETDEFTIMEOUT:
1722 ret_val = set_default_timeout(info, (unsigned long)arg);
1724 case TCSBRK: /* SVID version: non-zero arg --> no break */
1725 ret_val = tty_check_change(tty);
1728 tty_wait_until_sent(tty,0);
1730 send_break(info, HZ/4); /* 1/4 second */
1732 case TCSBRKP: /* support for POSIX tcsendbreak() */
1733 ret_val = tty_check_change(tty);
1736 tty_wait_until_sent(tty,0);
1737 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1740 /* The following commands are incompletely implemented!!! */
1742 ret_val = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *) arg);
1745 ret_val = get_user(val, (unsigned long *) arg);
1748 tty->termios->c_cflag =
1749 ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0));
1752 ret_val = get_serial_info(info, (struct serial_struct *) arg);
1755 ret_val = set_serial_info(info,
1756 (struct serial_struct *) arg);
1759 ret_val = -ENOIOCTLCMD;
1762 #ifdef SERIAL_DEBUG_OTHER
1763 printk("cy_ioctl done\n");
1773 cy_set_termios(struct tty_struct *tty, struct termios * old_termios)
1775 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1777 #ifdef SERIAL_DEBUG_OTHER
1778 printk("cy_set_termios %s\n", tty->name);
1781 if (tty->termios->c_cflag == old_termios->c_cflag)
1785 if ((old_termios->c_cflag & CRTSCTS) &&
1786 !(tty->termios->c_cflag & CRTSCTS)) {
1790 #ifdef tytso_patch_94Nov25_1726
1791 if (!(old_termios->c_cflag & CLOCAL) &&
1792 (tty->termios->c_cflag & CLOCAL))
1793 wake_up_interruptible(&info->open_wait);
1797 } /* cy_set_termios */
1801 cy_close(struct tty_struct * tty, struct file * filp)
1803 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1806 #ifdef SERIAL_DEBUG_OTHER
1807 printk("cy_close %s\n", tty->name);
1811 || serial_paranoia_check(info, tty->name, "cy_close")){
1814 #ifdef SERIAL_DEBUG_OPEN
1815 printk("cy_close %s, count = %d\n", tty->name, info->count);
1818 if ((tty->count == 1) && (info->count != 1)) {
1820 * Uh, oh. tty->count is 1, which means that the tty
1821 * structure will be freed. Info->count should always
1822 * be one in these conditions. If it's greater than
1823 * one, we've got real problems, since it means the
1824 * serial port won't be shutdown.
1826 printk("cy_close: bad serial port count; tty->count is 1, "
1827 "info->count is %d\n", info->count);
1830 #ifdef SERIAL_DEBUG_COUNT
1831 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count - 1);
1833 if (--info->count < 0) {
1834 printk("cy_close: bad serial port count for ttys%d: %d\n",
1835 info->line, info->count);
1836 #ifdef SERIAL_DEBUG_COUNT
1837 printk("cyc: %d: setting count to 0\n", __LINE__);
1843 info->flags |= ASYNC_CLOSING;
1844 if (info->flags & ASYNC_INITIALIZED)
1845 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
1847 if (tty->driver->flush_buffer)
1848 tty->driver->flush_buffer(tty);
1849 if (tty->ldisc.flush_buffer)
1850 tty->ldisc.flush_buffer(tty);
1853 if (tty->ldisc.num != ldiscs[N_TTY].num) {
1854 if (tty->ldisc.close)
1855 (tty->ldisc.close)(tty);
1856 tty->ldisc = ldiscs[N_TTY];
1857 tty->termios->c_line = N_TTY;
1858 if (tty->ldisc.open)
1859 (tty->ldisc.open)(tty);
1861 if (info->blocked_open) {
1862 if (info->close_delay) {
1863 current->state = TASK_INTERRUPTIBLE;
1864 schedule_timeout(info->close_delay);
1866 wake_up_interruptible(&info->open_wait);
1868 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1869 wake_up_interruptible(&info->close_wait);
1871 #ifdef SERIAL_DEBUG_OTHER
1872 printk("cy_close done\n");
1879 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
1882 cy_hangup(struct tty_struct *tty)
1884 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1886 #ifdef SERIAL_DEBUG_OTHER
1887 printk("cy_hangup %s\n", tty->name); /* */
1890 if (serial_paranoia_check(info, tty->name, "cy_hangup"))
1897 #ifdef SERIAL_DEBUG_COUNT
1898 printk("cyc: %d: setting count to 0\n", __LINE__);
1902 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1903 wake_up_interruptible(&info->open_wait);
1909 * ------------------------------------------------------------
1910 * cy_open() and friends
1911 * ------------------------------------------------------------
1915 block_til_ready(struct tty_struct *tty, struct file * filp,
1916 struct cyclades_port *info)
1918 DECLARE_WAITQUEUE(wait, current);
1919 unsigned long flags;
1922 volatile u_char *base_addr = (u_char *)BASE_ADDR;
1925 * If the device is in the middle of being closed, then block
1926 * until it's done, and then try again.
1928 if (info->flags & ASYNC_CLOSING) {
1929 interruptible_sleep_on(&info->close_wait);
1930 if (info->flags & ASYNC_HUP_NOTIFY){
1933 return -ERESTARTSYS;
1938 * If non-blocking mode is set, then make the check up front
1941 if (filp->f_flags & O_NONBLOCK) {
1942 info->flags |= ASYNC_NORMAL_ACTIVE;
1947 * Block waiting for the carrier detect and the line to become
1948 * free (i.e., not in use by the callout). While we are in
1949 * this loop, info->count is dropped by one, so that
1950 * cy_close() knows when to free things. We restore it upon
1951 * exit, either normal or abnormal.
1954 add_wait_queue(&info->open_wait, &wait);
1955 #ifdef SERIAL_DEBUG_OPEN
1956 printk("block_til_ready before block: %s, count = %d\n",
1957 tty->name, info->count);/**/
1960 #ifdef SERIAL_DEBUG_COUNT
1961 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count);
1963 info->blocked_open++;
1965 channel = info->line;
1968 local_irq_save(flags);
1969 base_addr[CyCAR] = (u_char)channel;
1970 base_addr[CyMSVR1] = CyRTS;
1971 /* CP('S');CP('4'); */
1972 base_addr[CyMSVR2] = CyDTR;
1973 #ifdef SERIAL_DEBUG_DTR
1974 printk("cyc: %d: raising DTR\n", __LINE__);
1975 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1977 local_irq_restore(flags);
1978 set_current_state(TASK_INTERRUPTIBLE);
1979 if (tty_hung_up_p(filp)
1980 || !(info->flags & ASYNC_INITIALIZED) ){
1981 if (info->flags & ASYNC_HUP_NOTIFY) {
1984 retval = -ERESTARTSYS;
1988 local_irq_save(flags);
1989 base_addr[CyCAR] = (u_char)channel;
1990 /* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */
1991 if (!(info->flags & ASYNC_CLOSING)
1993 || (base_addr[CyMSVR1] & CyDCD))) {
1994 local_irq_restore(flags);
1997 local_irq_restore(flags);
1998 if (signal_pending(current)) {
1999 retval = -ERESTARTSYS;
2002 #ifdef SERIAL_DEBUG_OPEN
2003 printk("block_til_ready blocking: %s, count = %d\n",
2004 tty->name, info->count);/**/
2008 current->state = TASK_RUNNING;
2009 remove_wait_queue(&info->open_wait, &wait);
2010 if (!tty_hung_up_p(filp)){
2012 #ifdef SERIAL_DEBUG_COUNT
2013 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
2016 info->blocked_open--;
2017 #ifdef SERIAL_DEBUG_OPEN
2018 printk("block_til_ready after blocking: %s, count = %d\n",
2019 tty->name, info->count);/**/
2023 info->flags |= ASYNC_NORMAL_ACTIVE;
2025 } /* block_til_ready */
2028 * This routine is called whenever a serial port is opened. It
2029 * performs the serial-specific initialization for the tty structure.
2032 cy_open(struct tty_struct *tty, struct file * filp)
2034 struct cyclades_port *info;
2039 if ((line < 0) || (NR_PORTS <= line)){
2042 info = &cy_port[line];
2043 if (info->line < 0){
2046 #ifdef SERIAL_DEBUG_OTHER
2047 printk("cy_open %s\n", tty->name); /* */
2049 if (serial_paranoia_check(info, tty->name, "cy_open")){
2052 #ifdef SERIAL_DEBUG_OPEN
2053 printk("cy_open %s, count = %d\n", tty->name, info->count);/**/
2056 #ifdef SERIAL_DEBUG_COUNT
2057 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
2059 tty->driver_data = info;
2063 tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL);
2070 * Start up serial port
2072 retval = startup(info);
2077 retval = block_til_ready(tty, filp, info);
2079 #ifdef SERIAL_DEBUG_OPEN
2080 printk("cy_open returning after block_til_ready with %d\n",
2086 #ifdef SERIAL_DEBUG_OPEN
2087 printk("cy_open done\n");/**/
2095 * ---------------------------------------------------------------------
2096 * serial167_init() and friends
2098 * serial167_init() is called at boot-time to initialize the serial driver.
2099 * ---------------------------------------------------------------------
2103 * This routine prints out the appropriate serial driver version
2104 * number, and identifies which options were configured into this
2110 printk("MVME166/167 cd2401 driver\n");
2111 } /* show_version */
2113 /* initialize chips on card -- return number of valid
2114 chips (which is number of ports/4) */
2117 * This initialises the hardware to a reasonable state. It should
2118 * probe the chip first so as to copy 166-Bug setup as a default for
2119 * port 0. It initialises CMR to CyASYNC; that is never done again, so
2120 * as to limit the number of CyINIT_CHAN commands in normal running.
2122 * ... I wonder what I should do if this fails ...
2126 mvme167_serial_console_setup(int cflag)
2128 volatile unsigned char* base_addr = (u_char *)BASE_ADDR;
2131 u_char rcor, rbpr, badspeed = 0;
2132 unsigned long flags;
2134 local_irq_save(flags);
2137 * First probe channel zero of the chip, to see what speed has
2141 base_addr[CyCAR] = 0;
2143 rcor = base_addr[CyRCOR] << 5;
2144 rbpr = base_addr[CyRBPR];
2146 for (spd = 0; spd < sizeof(baud_bpr); spd++)
2147 if (rbpr == baud_bpr[spd] && rcor == baud_co[spd])
2149 if (spd >= sizeof(baud_bpr)) {
2150 spd = 14; /* 19200 */
2151 badspeed = 1; /* Failed to identify speed */
2153 initial_console_speed = spd;
2155 /* OK, we have chosen a speed, now reset and reinitialise */
2157 my_udelay(20000L); /* Allow time for any active o/p to complete */
2158 if(base_addr[CyCCR] != 0x00){
2159 local_irq_restore(flags);
2160 /* printk(" chip is never idle (CCR != 0)\n"); */
2164 base_addr[CyCCR] = CyCHIP_RESET; /* Reset the chip */
2167 if(base_addr[CyGFRCR] == 0x00){
2168 local_irq_restore(flags);
2169 /* printk(" chip is not responding (GFRCR stayed 0)\n"); */
2174 * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms
2178 base_addr[CyTPR] = 10;
2180 base_addr[CyPILR1] = 0x01; /* Interrupt level for modem change */
2181 base_addr[CyPILR2] = 0x02; /* Interrupt level for tx ints */
2182 base_addr[CyPILR3] = 0x03; /* Interrupt level for rx ints */
2185 * Attempt to set up all channels to something reasonable, and
2186 * bang out a INIT_CHAN command. We should then be able to limit
2187 * the ammount of fiddling we have to do in normal running.
2190 for (ch = 3; ch >= 0 ; ch--) {
2191 base_addr[CyCAR] = (u_char)ch;
2192 base_addr[CyIER] = 0;
2193 base_addr[CyCMR] = CyASYNC;
2194 base_addr[CyLICR] = (u_char)ch << 2;
2195 base_addr[CyLIVR] = 0x5c;
2196 base_addr[CyTCOR] = baud_co[spd];
2197 base_addr[CyTBPR] = baud_bpr[spd];
2198 base_addr[CyRCOR] = baud_co[spd] >> 5;
2199 base_addr[CyRBPR] = baud_bpr[spd];
2200 base_addr[CySCHR1] = 'Q' & 0x1f;
2201 base_addr[CySCHR2] = 'X' & 0x1f;
2202 base_addr[CySCRL] = 0;
2203 base_addr[CySCRH] = 0;
2204 base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
2205 base_addr[CyCOR2] = 0;
2206 base_addr[CyCOR3] = Cy_1_STOP;
2207 base_addr[CyCOR4] = baud_cor4[spd];
2208 base_addr[CyCOR5] = 0;
2209 base_addr[CyCOR6] = 0;
2210 base_addr[CyCOR7] = 0;
2211 base_addr[CyRTPRL] = 2;
2212 base_addr[CyRTPRH] = 0;
2213 base_addr[CyMSVR1] = 0;
2214 base_addr[CyMSVR2] = 0;
2215 write_cy_cmd(base_addr,CyINIT_CHAN|CyDIS_RCVR|CyDIS_XMTR);
2219 * Now do specials for channel zero....
2222 base_addr[CyMSVR1] = CyRTS;
2223 base_addr[CyMSVR2] = CyDTR;
2224 base_addr[CyIER] = CyRxData;
2225 write_cy_cmd(base_addr,CyENB_RCVR|CyENB_XMTR);
2227 local_irq_restore(flags);
2229 my_udelay(20000L); /* Let it all settle down */
2231 printk("CD2401 initialised, chip is rev 0x%02x\n", base_addr[CyGFRCR]);
2233 printk(" WARNING: Failed to identify line speed, rcor=%02x,rbpr=%02x\n",
2235 } /* serial_console_init */
2237 static struct tty_operations cy_ops = {
2241 .put_char = cy_put_char,
2242 .flush_chars = cy_flush_chars,
2243 .write_room = cy_write_room,
2244 .chars_in_buffer = cy_chars_in_buffer,
2245 .flush_buffer = cy_flush_buffer,
2247 .throttle = cy_throttle,
2248 .unthrottle = cy_unthrottle,
2249 .set_termios = cy_set_termios,
2252 .hangup = cy_hangup,
2253 .tiocmget = cy_tiocmget,
2254 .tiocmset = cy_tiocmset,
2256 /* The serial driver boot-time initialization code!
2257 Hardware I/O ports are mapped to character special devices on a
2258 first found, first allocated manner. That is, this code searches
2259 for Cyclom cards in the system. As each is found, it is probed
2260 to discover how many chips (and thus how many ports) are present.
2261 These ports are mapped to the tty ports 64 and upward in monotonic
2262 fashion. If an 8-port card is replaced with a 16-port card, the
2263 port mapping on a following card will shift.
2265 This approach is different from what is used in the other serial
2266 device driver because the Cyclom is more properly a multiplexer,
2267 not just an aggregation of serial ports on one card.
2269 If there are more cards with more ports than have been statically
2270 allocated above, a warning is printed and the extra ports are ignored.
2273 serial167_init(void)
2275 struct cyclades_port *info;
2282 struct sigaction sa;
2285 if (!(mvme16x_config &MVME16x_CONFIG_GOT_CD2401))
2288 cy_serial_driver = alloc_tty_driver(NR_PORTS);
2289 if (!cy_serial_driver)
2298 /* Has "console=0,9600n8" been used in bootinfo to change speed? */
2299 if (serial_console_cflag)
2300 DefSpeed = serial_console_cflag & 0017;
2302 DefSpeed = initial_console_speed;
2303 serial_console_info = &cy_port[0];
2304 serial_console_cflag = DefSpeed | CS8;
2306 serial_console = 64; /*callout_driver.minor_start*/
2310 /* Initialize the tty_driver structure */
2312 cy_serial_driver->owner = THIS_MODULE;
2313 cy_serial_driver->devfs_name = "tts/";
2314 cy_serial_driver->name = "ttyS";
2315 cy_serial_driver->major = TTY_MAJOR;
2316 cy_serial_driver->minor_start = 64;
2317 cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
2318 cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
2319 cy_serial_driver->init_termios = tty_std_termios;
2320 cy_serial_driver->init_termios.c_cflag =
2321 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2322 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
2323 tty_set_operations(cy_serial_driver, &cy_ops);
2325 ret = tty_register_driver(cy_serial_driver);
2327 printk(KERN_ERR "Couldn't register MVME166/7 serial driver\n");
2328 put_tty_driver(cy_serial_driver);
2332 init_bh(CYCLADES_BH, do_cyclades_bh);
2336 for (index = 0; index < 1; index++) {
2340 if(port_num < NR_PORTS){
2341 while( good_ports-- && port_num < NR_PORTS){
2342 /*** initialize port ***/
2343 info->magic = CYCLADES_MAGIC;
2344 info->type = PORT_CIRRUS;
2346 info->line = port_num;
2347 info->flags = STD_COM_FLAGS;
2349 info->xmit_fifo_size = 12;
2350 info->cor1 = CyPARITY_NONE|Cy_8_BITS;
2352 info->cor3 = Cy_1_STOP;
2353 info->cor4 = 0x08; /* _very_ small receive threshold */
2357 info->tbpr = baud_bpr[DefSpeed]; /* Tx BPR */
2358 info->tco = baud_co[DefSpeed]; /* Tx CO */
2359 info->rbpr = baud_bpr[DefSpeed]; /* Rx BPR */
2360 info->rco = baud_co[DefSpeed] >> 5; /* Rx CO */
2361 info->close_delay = 0;
2365 #ifdef SERIAL_DEBUG_COUNT
2366 printk("cyc: %d: setting count to 0\n", __LINE__);
2368 info->blocked_open = 0;
2369 info->default_threshold = 0;
2370 info->default_timeout = 0;
2371 info->tqueue.routine = do_softint;
2372 info->tqueue.data = info;
2373 init_waitqueue_head(&info->open_wait);
2374 init_waitqueue_head(&info->close_wait);
2377 /*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/
2378 info->read_status_mask = CyTIMEOUT| CySPECHAR| CyBREAK
2379 | CyPARITY| CyFRAME| CyOVERRUN;
2382 printk("ttyS%1d ", info->line);
2384 if(!(port_num & 7)){
2391 while( port_num < NR_PORTS){
2395 #ifdef CONFIG_REMOTE_DEBUG
2398 ret = request_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt, 0,
2399 "cd2401_errors", cd2401_rxerr_interrupt);
2401 printk(KERN_ERR "Could't get cd2401_errors IRQ");
2402 goto cleanup_serial_driver;
2405 ret = request_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt, 0,
2406 "cd2401_modem", cd2401_modem_interrupt);
2408 printk(KERN_ERR "Could't get cd2401_modem IRQ");
2409 goto cleanup_irq_cd2401_errors;
2412 ret = request_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt, 0,
2413 "cd2401_txints", cd2401_tx_interrupt);
2415 printk(KERN_ERR "Could't get cd2401_txints IRQ");
2416 goto cleanup_irq_cd2401_modem;
2419 ret = request_irq(MVME167_IRQ_SER_RX, cd2401_rx_interrupt, 0,
2420 "cd2401_rxints", cd2401_rx_interrupt);
2422 printk(KERN_ERR "Could't get cd2401_rxints IRQ");
2423 goto cleanup_irq_cd2401_txints;
2426 /* Now we have registered the interrupt handlers, allow the interrupts */
2428 pcc2chip[PccSCCMICR] = 0x15; /* Serial ints are level 5 */
2429 pcc2chip[PccSCCTICR] = 0x15;
2430 pcc2chip[PccSCCRICR] = 0x15;
2432 pcc2chip[PccIMLR] = 3; /* Allow PCC2 ints above 3!? */
2435 cleanup_irq_cd2401_txints:
2436 free_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt);
2437 cleanup_irq_cd2401_modem:
2438 free_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt);
2439 cleanup_irq_cd2401_errors:
2440 free_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt);
2441 cleanup_serial_driver:
2442 if (tty_unregister_driver(cy_serial_driver))
2443 printk(KERN_ERR "Couldn't unregister MVME166/7 serial driver\n");
2444 put_tty_driver(cy_serial_driver);
2446 } /* serial167_init */
2448 module_init(serial167_init);
2451 #ifdef CYCLOM_SHOW_STATUS
2453 show_status(int line_num)
2455 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2457 struct cyclades_port * info;
2458 unsigned long flags;
2460 info = &cy_port[line_num];
2461 channel = info->line;
2462 printk(" channel %d\n", channel);/**/
2464 printk(" cy_port\n");
2465 printk(" card line flags = %d %d %x\n",
2466 info->card, info->line, info->flags);
2467 printk(" *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n",
2468 (long)info->tty, info->read_status_mask,
2469 info->timeout, info->xmit_fifo_size);
2470 printk(" cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n",
2471 info->cor1, info->cor2, info->cor3, info->cor4, info->cor5,
2472 info->cor6, info->cor7);
2473 printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n",
2474 info->tbpr, info->tco, info->rbpr, info->rco);
2475 printk(" close_delay event count = %d %d %d\n",
2476 info->close_delay, info->event, info->count);
2477 printk(" x_char blocked_open = %x %x\n",
2478 info->x_char, info->blocked_open);
2479 printk(" open_wait = %lx %lx %lx\n",
2480 (long)info->open_wait);
2483 local_irq_save(flags);
2485 /* Global Registers */
2487 printk(" CyGFRCR %x\n", base_addr[CyGFRCR]);
2488 printk(" CyCAR %x\n", base_addr[CyCAR]);
2489 printk(" CyRISR %x\n", base_addr[CyRISR]);
2490 printk(" CyTISR %x\n", base_addr[CyTISR]);
2491 printk(" CyMISR %x\n", base_addr[CyMISR]);
2492 printk(" CyRIR %x\n", base_addr[CyRIR]);
2493 printk(" CyTIR %x\n", base_addr[CyTIR]);
2494 printk(" CyMIR %x\n", base_addr[CyMIR]);
2495 printk(" CyTPR %x\n", base_addr[CyTPR]);
2497 base_addr[CyCAR] = (u_char)channel;
2499 /* Virtual Registers */
2502 printk(" CyRIVR %x\n", base_addr[CyRIVR]);
2503 printk(" CyTIVR %x\n", base_addr[CyTIVR]);
2504 printk(" CyMIVR %x\n", base_addr[CyMIVR]);
2505 printk(" CyMISR %x\n", base_addr[CyMISR]);
2508 /* Channel Registers */
2510 printk(" CyCCR %x\n", base_addr[CyCCR]);
2511 printk(" CyIER %x\n", base_addr[CyIER]);
2512 printk(" CyCOR1 %x\n", base_addr[CyCOR1]);
2513 printk(" CyCOR2 %x\n", base_addr[CyCOR2]);
2514 printk(" CyCOR3 %x\n", base_addr[CyCOR3]);
2515 printk(" CyCOR4 %x\n", base_addr[CyCOR4]);
2516 printk(" CyCOR5 %x\n", base_addr[CyCOR5]);
2518 printk(" CyCCSR %x\n", base_addr[CyCCSR]);
2519 printk(" CyRDCR %x\n", base_addr[CyRDCR]);
2521 printk(" CySCHR1 %x\n", base_addr[CySCHR1]);
2522 printk(" CySCHR2 %x\n", base_addr[CySCHR2]);
2524 printk(" CySCHR3 %x\n", base_addr[CySCHR3]);
2525 printk(" CySCHR4 %x\n", base_addr[CySCHR4]);
2526 printk(" CySCRL %x\n", base_addr[CySCRL]);
2527 printk(" CySCRH %x\n", base_addr[CySCRH]);
2528 printk(" CyLNC %x\n", base_addr[CyLNC]);
2529 printk(" CyMCOR1 %x\n", base_addr[CyMCOR1]);
2530 printk(" CyMCOR2 %x\n", base_addr[CyMCOR2]);
2532 printk(" CyRTPRL %x\n", base_addr[CyRTPRL]);
2533 printk(" CyRTPRH %x\n", base_addr[CyRTPRH]);
2534 printk(" CyMSVR1 %x\n", base_addr[CyMSVR1]);
2535 printk(" CyMSVR2 %x\n", base_addr[CyMSVR2]);
2536 printk(" CyRBPR %x\n", base_addr[CyRBPR]);
2537 printk(" CyRCOR %x\n", base_addr[CyRCOR]);
2538 printk(" CyTBPR %x\n", base_addr[CyTBPR]);
2539 printk(" CyTCOR %x\n", base_addr[CyTCOR]);
2541 local_irq_restore(flags);
2547 /* Dummy routine in mvme16x/config.c for now */
2549 /* Serial console setup. Called from linux/init/main.c */
2551 void console_setup(char *str, int *ints)
2554 int baud, bits, parity;
2558 if (ints[0] > 3 || ints[1] > 3) return;
2560 /* Get baud, bits and parity */
2564 if (ints[2]) baud = ints[2];
2565 if ((s = strchr(str, ','))) {
2568 } while(*s >= '0' && *s <= '9');
2569 if (*s) parity = *s++;
2570 if (*s) bits = *s - '0';
2573 /* Now construct a cflag setting. */
2610 serial_console_info = &cy_port[ints[1]];
2611 serial_console_cflag = cflag;
2612 serial_console = ints[1] + 64; /*callout_driver.minor_start*/
2617 * The following is probably out of date for 2.1.x serial console stuff.
2619 * The console is registered early on from arch/m68k/kernel/setup.c, and
2620 * it therefore relies on the chip being setup correctly by 166-Bug. This
2621 * seems reasonable, as the serial port has been used to invoke the system
2622 * boot. It also means that this function must not rely on any data
2623 * initialisation performed by serial167_init() etc.
2625 * Of course, once the console has been registered, we had better ensure
2626 * that serial167_init() doesn't leave the chip non-functional.
2628 * The console must be locked when we get here.
2631 void serial167_console_write(struct console *co, const char *str, unsigned count)
2633 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2634 unsigned long flags;
2635 volatile u_char sink;
2641 local_irq_save(flags);
2643 /* Ensure transmitter is enabled! */
2646 base_addr[CyCAR] = (u_char)port;
2647 while (base_addr[CyCCR])
2649 base_addr[CyCCR] = CyENB_XMTR;
2651 ier = base_addr[CyIER];
2652 base_addr[CyIER] = CyTxMpty;
2655 if (pcc2chip[PccSCCTICR] & 0x20)
2657 /* We have a Tx int. Acknowledge it */
2658 sink = pcc2chip[PccTPIACKR];
2659 if ((base_addr[CyLICR] >> 2) == port) {
2661 /* Last char of string is now output */
2662 base_addr[CyTEOIR] = CyNOTRANS;
2666 base_addr[CyTDR] = '\n';
2671 else if (*str == '\n') {
2672 base_addr[CyTDR] = '\r';
2676 base_addr[CyTDR] = *str++;
2679 base_addr[CyTEOIR] = 0;
2682 base_addr[CyTEOIR] = CyNOTRANS;
2686 base_addr[CyIER] = ier;
2688 local_irq_restore(flags);
2691 static struct tty_driver *serial167_console_device(struct console *c, int *index)
2694 return cy_serial_driver;
2698 static int __init serial167_console_setup(struct console *co, char *options)
2704 static struct console sercons = {
2706 .write = serial167_console_write,
2707 .device = serial167_console_device,
2708 .setup = serial167_console_setup,
2709 .flags = CON_PRINTBUFFER,
2714 static int __init serial167_console_init(void)
2716 if (vme_brdtype == VME_TYPE_MVME166 ||
2717 vme_brdtype == VME_TYPE_MVME167 ||
2718 vme_brdtype == VME_TYPE_MVME177) {
2719 mvme167_serial_console_setup(0);
2720 register_console(&sercons);
2724 console_initcall(serial167_console_init);
2726 #ifdef CONFIG_REMOTE_DEBUG
2727 void putDebugChar (int c)
2729 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2730 unsigned long flags;
2731 volatile u_char sink;
2735 local_irq_save(flags);
2737 /* Ensure transmitter is enabled! */
2740 base_addr[CyCAR] = (u_char)port;
2741 while (base_addr[CyCCR])
2743 base_addr[CyCCR] = CyENB_XMTR;
2745 ier = base_addr[CyIER];
2746 base_addr[CyIER] = CyTxMpty;
2749 if (pcc2chip[PccSCCTICR] & 0x20)
2751 /* We have a Tx int. Acknowledge it */
2752 sink = pcc2chip[PccTPIACKR];
2753 if ((base_addr[CyLICR] >> 2) == port) {
2754 base_addr[CyTDR] = c;
2755 base_addr[CyTEOIR] = 0;
2759 base_addr[CyTEOIR] = CyNOTRANS;
2763 base_addr[CyIER] = ier;
2765 local_irq_restore(flags);
2770 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2771 unsigned long flags;
2772 volatile u_char sink;
2778 if (i != debugiq.in) {
2780 if (++i == DEBUG_LEN)
2785 /* OK, nothing in queue, wait in poll loop */
2787 local_irq_save(flags);
2789 /* Ensure receiver is enabled! */
2792 base_addr[CyCAR] = (u_char)port;
2794 while (base_addr[CyCCR])
2796 base_addr[CyCCR] = CyENB_RCVR;
2798 ier = base_addr[CyIER];
2799 base_addr[CyIER] = CyRxData;
2802 if (pcc2chip[PccSCCRICR] & 0x20)
2804 /* We have a Rx int. Acknowledge it */
2805 sink = pcc2chip[PccRPIACKR];
2806 if ((base_addr[CyLICR] >> 2) == port) {
2807 int cnt = base_addr[CyRFOC];
2810 c = base_addr[CyRDR];
2812 printk ("!! debug char is null (cnt=%d) !!", cnt);
2816 base_addr[CyREOIR] = 0;
2818 if (i == debugiq.in)
2819 panic ("Debug input queue empty!");
2821 if (++i == DEBUG_LEN)
2827 base_addr[CyREOIR] = CyNOTRANS;
2831 base_addr[CyIER] = ier;
2833 local_irq_restore(flags);
2838 void queueDebugChar (int c)
2844 if (++i == DEBUG_LEN)
2846 if (i != debugiq.out)
2853 unsigned long flags;
2854 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2859 local_irq_save(flags);
2861 for (i = 0; i < 4; i++)
2863 base_addr[CyCAR] = i;
2864 base_addr[CyLICR] = i << 2;
2867 debugiq.in = debugiq.out = 0;
2869 base_addr[CyCAR] = DEBUG_PORT;
2874 base_addr[CyIER] = 0;
2876 base_addr[CyCMR] = CyASYNC;
2877 base_addr[CyLICR] = DEBUG_PORT << 2;
2878 base_addr[CyLIVR] = 0x5c;
2880 /* tx and rx baud rate */
2882 base_addr[CyTCOR] = baud_co[i];
2883 base_addr[CyTBPR] = baud_bpr[i];
2884 base_addr[CyRCOR] = baud_co[i] >> 5;
2885 base_addr[CyRBPR] = baud_bpr[i];
2887 /* set line characteristics according configuration */
2889 base_addr[CySCHR1] = 0;
2890 base_addr[CySCHR2] = 0;
2891 base_addr[CySCRL] = 0;
2892 base_addr[CySCRH] = 0;
2893 base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
2894 base_addr[CyCOR2] = 0;
2895 base_addr[CyCOR3] = Cy_1_STOP;
2896 base_addr[CyCOR4] = baud_cor4[i];
2897 base_addr[CyCOR5] = 0;
2898 base_addr[CyCOR6] = 0;
2899 base_addr[CyCOR7] = 0;
2901 write_cy_cmd(base_addr,CyINIT_CHAN);
2902 write_cy_cmd(base_addr,CyENB_RCVR);
2904 base_addr[CyCAR] = DEBUG_PORT; /* !!! Is this needed? */
2906 base_addr[CyRTPRL] = 2;
2907 base_addr[CyRTPRH] = 0;
2909 base_addr[CyMSVR1] = CyRTS;
2910 base_addr[CyMSVR2] = CyDTR;
2912 base_addr[CyIER] = CyRxData;
2914 local_irq_restore(flags);
2920 MODULE_LICENSE("GPL");