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
43 * Kars de Jong <jongk@linux-m68k.org> - 2004/09/06
44 * - replace bottom half handler with task queue handler
47 #include <linux/config.h>
48 #include <linux/errno.h>
49 #include <linux/signal.h>
50 #include <linux/sched.h>
51 #include <linux/timer.h>
52 #include <linux/tty.h>
53 #include <linux/interrupt.h>
54 #include <linux/serial.h>
55 #include <linux/serialP.h>
56 #include <linux/string.h>
57 #include <linux/fcntl.h>
58 #include <linux/ptrace.h>
59 #include <linux/serial167.h>
60 #include <linux/delay.h>
61 #include <linux/major.h>
63 #include <linux/console.h>
64 #include <linux/module.h>
65 #include <linux/bitops.h>
67 #include <asm/system.h>
69 #include <asm/mvme16xhw.h>
70 #include <asm/bootinfo.h>
71 #include <asm/setup.h>
73 #include <linux/types.h>
74 #include <linux/kernel.h>
76 #include <asm/uaccess.h>
77 #include <linux/init.h>
79 #define SERIAL_PARANOIA_CHECK
80 #undef SERIAL_DEBUG_OPEN
81 #undef SERIAL_DEBUG_THROTTLE
82 #undef SERIAL_DEBUG_OTHER
83 #undef SERIAL_DEBUG_IO
84 #undef SERIAL_DEBUG_COUNT
85 #undef SERIAL_DEBUG_DTR
86 #undef CYCLOM_16Y_HACK
87 #define CYCLOM_ENABLE_MONITORING
89 #define WAKEUP_CHARS 256
91 #define STD_COM_FLAGS (0)
93 #define SERIAL_TYPE_NORMAL 1
95 static struct tty_driver *cy_serial_driver;
96 extern int serial_console;
97 static struct cyclades_port *serial_console_info = NULL;
98 static unsigned int serial_console_cflag = 0;
99 u_char initial_console_speed;
101 /* Base address of cd2401 chip on mvme166/7 */
103 #define BASE_ADDR (0xfff45000)
104 #define pcc2chip ((volatile u_char *)0xfff42000)
105 #define PccSCCMICR 0x1d
106 #define PccSCCTICR 0x1e
107 #define PccSCCRICR 0x1f
108 #define PccTPIACKR 0x25
109 #define PccRPIACKR 0x27
112 /* This is the per-port data structure */
113 struct cyclades_port cy_port[] = {
120 #define NR_PORTS ARRAY_SIZE(cy_port)
123 * tmp_buf is used as a temporary buffer by serial_write. We need to
124 * lock it in case the copy_from_user blocks while swapping in a page,
125 * and some other program tries to do a serial write at the same time.
126 * Since the lock will only come under contention when the system is
127 * swapping and available memory is low, it makes sense to share one
128 * buffer across all the serial ports, since it significantly saves
129 * memory if large numbers of serial ports are open.
131 static unsigned char *tmp_buf = 0;
134 * This is used to look up the divisor speeds and the timeouts
135 * We're normally limited to 15 distinct baud rates. The extra
136 * are accessed via settings in info->flags.
137 * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
138 * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
141 static int baud_table[] = {
142 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
143 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000,
147 static char baud_co[] = { /* 25 MHz clock option table */
148 /* value => 00 01 02 03 04 */
149 /* divide by 8 32 128 512 2048 */
150 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
151 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
153 static char baud_bpr[] = { /* 25 MHz baud rate period table */
154 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
155 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15};
158 /* I think 166 brd clocks 2401 at 20MHz.... */
160 /* These values are written directly to tcor, and >> 5 for writing to rcor */
161 static u_char baud_co[] = { /* 20 MHz clock option table */
162 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x60, 0x60, 0x40,
163 0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
165 /* These values written directly to tbpr/rbpr */
166 static u_char baud_bpr[] = { /* 20 MHz baud rate period table */
167 0x00, 0xc0, 0x80, 0x58, 0x6c, 0x40, 0xc0, 0x81, 0x40, 0x81,
168 0x57, 0x40, 0x81, 0x40, 0x81, 0x40, 0x2b, 0x20, 0x15, 0x10};
170 static u_char baud_cor4[] = { /* receive threshold */
171 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
172 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07};
176 static void shutdown(struct cyclades_port *);
177 static int startup (struct cyclades_port *);
178 static void cy_throttle(struct tty_struct *);
179 static void cy_unthrottle(struct tty_struct *);
180 static void config_setup(struct cyclades_port *);
181 extern void console_print(const char *);
182 #ifdef CYCLOM_SHOW_STATUS
183 static void show_status(int);
186 #ifdef CONFIG_REMOTE_DEBUG
187 static void debug_setup(void);
188 void queueDebugChar (int c);
189 int getDebugChar(void);
192 #define DEBUG_LEN 256
197 unsigned char buf[DEBUG_LEN];
204 * I have my own version of udelay(), as it is needed when initialising
205 * the chip, before the delay loop has been calibrated. Should probably
206 * reference one of the vmechip2 or pccchip2 counter for an accurate
207 * delay, but this wild guess will do for now.
210 void my_udelay (long us)
213 volatile u_char *p = &x;
217 for (i = 100; i; i--)
222 serial_paranoia_check(struct cyclades_port *info, char *name,
225 #ifdef SERIAL_PARANOIA_CHECK
226 static const char *badmagic =
227 "Warning: bad magic number for serial struct (%s) in %s\n";
228 static const char *badinfo =
229 "Warning: null cyclades_port for (%s) in %s\n";
230 static const char *badrange =
231 "Warning: cyclades_port out of range for (%s) in %s\n";
234 printk(badinfo, name, routine);
238 if( (long)info < (long)(&cy_port[0])
239 || (long)(&cy_port[NR_PORTS]) < (long)info ){
240 printk(badrange, name, routine);
244 if (info->magic != CYCLADES_MAGIC) {
245 printk(badmagic, name, routine);
250 } /* serial_paranoia_check */
253 /* The following diagnostic routines allow the driver to spew
254 information on the screen, even (especially!) during interrupts.
259 local_irq_save(flags);
261 local_irq_restore(flags);
267 local_irq_save(flags);
270 local_irq_restore(flags);
273 void CP1(int data) { (data<10)? CP(data+'0'): CP(data+'A'-10); }/* CP1 */
274 void CP2(int data) { CP1((data>>4) & 0x0f); CP1( data & 0x0f); }/* CP2 */
275 void CP4(int data) { CP2((data>>8) & 0xff); CP2(data & 0xff); }/* CP4 */
276 void CP8(long data) { CP4((data>>16) & 0xffff); CP4(data & 0xffff); }/* CP8 */
279 /* This routine waits up to 1000 micro-seconds for the previous
280 command to the Cirrus chip to complete and then issues the
281 new command. An error is returned if the previous command
282 didn't finish within the time limit.
285 write_cy_cmd(volatile u_char *base_addr, u_char cmd)
290 local_irq_save(flags);
291 /* Check to see that the previous command has completed */
292 for(i = 0 ; i < 100 ; i++){
293 if (base_addr[CyCCR] == 0){
298 /* if the CCR never cleared, the previous command
299 didn't finish within the "reasonable time" */
301 local_irq_restore(flags);
305 /* Issue the new command */
306 base_addr[CyCCR] = cmd;
307 local_irq_restore(flags);
312 /* cy_start and cy_stop provide software output flow control as a
313 function of XON/XOFF, software CTS, and other such stuff. */
316 cy_stop(struct tty_struct *tty)
318 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
319 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
323 #ifdef SERIAL_DEBUG_OTHER
324 printk("cy_stop %s\n", tty->name); /* */
327 if (serial_paranoia_check(info, tty->name, "cy_stop"))
330 channel = info->line;
332 local_irq_save(flags);
333 base_addr[CyCAR] = (u_char)(channel); /* index channel */
334 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
335 local_irq_restore(flags);
341 cy_start(struct tty_struct *tty)
343 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
344 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
348 #ifdef SERIAL_DEBUG_OTHER
349 printk("cy_start %s\n", tty->name); /* */
352 if (serial_paranoia_check(info, tty->name, "cy_start"))
355 channel = info->line;
357 local_irq_save(flags);
358 base_addr[CyCAR] = (u_char)(channel);
359 base_addr[CyIER] |= CyTxMpty;
360 local_irq_restore(flags);
367 * This routine is used by the interrupt handler to schedule
368 * processing in the software interrupt portion of the driver
369 * (also known as the "bottom half"). This can be called any
370 * number of times for any channel without harm.
373 cy_sched_event(struct cyclades_port *info, int event)
375 info->event |= 1 << event; /* remember what kind of event and who */
376 schedule_work(&info->tqueue);
377 } /* cy_sched_event */
380 /* The real interrupt service routines are called
381 whenever the card wants its hand held--chars
382 received, out buffer empty, modem change, etc.
385 cd2401_rxerr_interrupt(int irq, void *dev_id, struct pt_regs *fp)
387 struct tty_struct *tty;
388 struct cyclades_port *info;
389 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
390 unsigned char err, rfoc;
394 /* determine the channel and change to that context */
395 channel = (u_short ) (base_addr[CyLICR] >> 2);
396 info = &cy_port[channel];
397 info->last_active = jiffies;
399 if ((err = base_addr[CyRISR]) & CyTIMEOUT) {
400 /* This is a receive timeout interrupt, ignore it */
401 base_addr[CyREOIR] = CyNOTRANS;
405 /* Read a byte of data if there is any - assume the error
406 * is associated with this character */
408 if ((rfoc = base_addr[CyRFOC]) != 0)
409 data = base_addr[CyRDR];
413 /* if there is nowhere to put the data, discard it */
415 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
418 else { /* there is an open port for this data */
420 if(err & info->ignore_status_mask){
421 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
424 if (tty_buffer_request_room(tty, 1) != 0){
425 if (err & info->read_status_mask){
427 tty_insert_flip_char(tty, data, TTY_BREAK);
428 if (info->flags & ASYNC_SAK){
431 }else if(err & CyFRAME){
432 tty_insert_flip_char(tty, data, TTY_FRAME);
433 }else if(err & CyPARITY){
434 tty_insert_flip_char(tty, data, TTY_PARITY);
435 }else if(err & CyOVERRUN){
436 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
438 If the flip buffer itself is
439 overflowing, we still loose
440 the next incoming character.
442 tty_insert_flip_char(tty, data, TTY_NORMAL);
444 /* These two conditions may imply */
445 /* a normal read should be done. */
446 /* else if(data & CyTIMEOUT) */
447 /* else if(data & CySPECHAR) */
449 tty_insert_flip_char(tty, 0, TTY_NORMAL);
452 tty_insert_flip_char(tty, data, TTY_NORMAL);
455 /* there was a software buffer overrun
456 and nothing could be done about it!!! */
459 schedule_delayed_work(&tty->flip.work, 1);
461 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
463 } /* cy_rxerr_interrupt */
466 cd2401_modem_interrupt(int irq, void *dev_id, struct pt_regs *fp)
468 struct cyclades_port *info;
469 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
475 /* determine the channel and change to that context */
476 channel = (u_short ) (base_addr[CyLICR] >> 2);
477 info = &cy_port[channel];
478 info->last_active = jiffies;
480 mdm_change = base_addr[CyMISR];
481 mdm_status = base_addr[CyMSVR1];
483 if(info->tty == 0){ /* nowhere to put the data, ignore it */
486 if((mdm_change & CyDCD)
487 && (info->flags & ASYNC_CHECK_CD)){
488 if(mdm_status & CyDCD){
490 cy_sched_event(info, Cy_EVENT_OPEN_WAKEUP);
493 cy_sched_event(info, Cy_EVENT_HANGUP);
496 if((mdm_change & CyCTS)
497 && (info->flags & ASYNC_CTS_FLOW)){
498 if(info->tty->stopped){
499 if(mdm_status & CyCTS){
500 /* !!! cy_start isn't used because... */
501 info->tty->stopped = 0;
502 base_addr[CyIER] |= CyTxMpty;
503 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
506 if(!(mdm_status & CyCTS)){
507 /* !!! cy_stop isn't used because... */
508 info->tty->stopped = 1;
509 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
513 if(mdm_status & CyDSR){
516 base_addr[CyMEOIR] = 0;
518 } /* cy_modem_interrupt */
521 cd2401_tx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
523 struct cyclades_port *info;
524 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
526 int char_count, saved_cnt;
529 /* determine the channel and change to that context */
530 channel = (u_short ) (base_addr[CyLICR] >> 2);
532 #ifdef CONFIG_REMOTE_DEBUG
533 if (channel == DEBUG_PORT) {
534 panic ("TxInt on debug port!!!");
538 info = &cy_port[channel];
540 /* validate the port number (as configured and open) */
541 if( (channel < 0) || (NR_PORTS <= channel) ){
542 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
543 base_addr[CyTEOIR] = CyNOTRANS;
546 info->last_active = jiffies;
548 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
549 if (info->xmit_cnt < WAKEUP_CHARS) {
550 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
552 base_addr[CyTEOIR] = CyNOTRANS;
556 /* load the on-chip space available for outbound data */
557 saved_cnt = char_count = base_addr[CyTFTC];
559 if(info->x_char) { /* send special char */
560 outch = info->x_char;
561 base_addr[CyTDR] = outch;
567 /* The Cirrus chip requires the "Embedded Transmit
568 Commands" of start break, delay, and end break
569 sequences to be sent. The duration of the
570 break is given in TICs, which runs at HZ
571 (typically 100) and the PPR runs at 200 Hz,
572 so the delay is duration * 200/HZ, and thus a
573 break can run from 1/100 sec to about 5/4 sec.
574 Need to check these values - RGH 141095.
576 base_addr[CyTDR] = 0; /* start break */
577 base_addr[CyTDR] = 0x81;
578 base_addr[CyTDR] = 0; /* delay a bit */
579 base_addr[CyTDR] = 0x82;
580 base_addr[CyTDR] = info->x_break*200/HZ;
581 base_addr[CyTDR] = 0; /* terminate break */
582 base_addr[CyTDR] = 0x83;
587 while (char_count > 0){
588 if (!info->xmit_cnt){
589 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
592 if (info->xmit_buf == 0){
593 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
596 if (info->tty->stopped || info->tty->hw_stopped){
597 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
600 /* Because the Embedded Transmit Commands have been
601 enabled, we must check to see if the escape
602 character, NULL, is being sent. If it is, we
603 must ensure that there is room for it to be
604 doubled in the output stream. Therefore we
605 no longer advance the pointer when the character
606 is fetched, but rather wait until after the check
607 for a NULL output character. (This is necessary
608 because there may not be room for the two chars
609 needed to send a NULL.
611 outch = info->xmit_buf[info->xmit_tail];
614 info->xmit_tail = (info->xmit_tail + 1)
616 base_addr[CyTDR] = outch;
621 info->xmit_tail = (info->xmit_tail + 1)
623 base_addr[CyTDR] = outch;
624 base_addr[CyTDR] = 0;
633 if (info->xmit_cnt < WAKEUP_CHARS) {
634 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
636 base_addr[CyTEOIR] = (char_count != saved_cnt) ? 0 : CyNOTRANS;
638 } /* cy_tx_interrupt */
641 cd2401_rx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
643 struct tty_struct *tty;
644 struct cyclades_port *info;
645 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
651 /* determine the channel and change to that context */
652 channel = (u_short ) (base_addr[CyLICR] >> 2);
653 info = &cy_port[channel];
654 info->last_active = jiffies;
655 save_cnt = char_count = base_addr[CyRFOC];
657 #ifdef CONFIG_REMOTE_DEBUG
658 if (channel == DEBUG_PORT) {
659 while (char_count--) {
660 data = base_addr[CyRDR];
661 queueDebugChar(data);
666 /* if there is nowhere to put the data, discard it */
669 data = base_addr[CyRDR];
671 }else{ /* there is an open port for this data */
673 /* load # characters available from the chip */
675 #ifdef CYCLOM_ENABLE_MONITORING
676 ++info->mon.int_count;
677 info->mon.char_count += char_count;
678 if (char_count > info->mon.char_max)
679 info->mon.char_max = char_count;
680 info->mon.char_last = char_count;
683 data = base_addr[CyRDR];
684 tty_insert_flip_char(tty, data, TTY_NORMAL);
685 #ifdef CYCLOM_16Y_HACK
689 schedule_delayed_work(&tty->flip.work, 1);
692 base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS;
694 } /* cy_rx_interrupt */
697 * This routine is used to handle the "bottom half" processing for the
698 * serial driver, known also the "software interrupt" processing.
699 * This processing is done at the kernel interrupt level, after the
700 * cy#/_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
701 * is where time-consuming activities which can not be done in the
702 * interrupt driver proper are done; the interrupt driver schedules
703 * them using cy_sched_event(), and they get done here.
705 * This is done through one level of indirection--the task queue.
706 * When a hardware interrupt service routine wants service by the
707 * driver's bottom half, it enqueues the appropriate tq_struct (one
708 * per port) to the keventd work queue and sets a request flag
709 * that the work queue be processed.
711 * Although this may seem unwieldy, it gives the system a way to
712 * pass an argument (in this case the pointer to the cyclades_port
713 * structure) to the bottom half of the driver. Previous kernels
714 * had to poll every port to see if that port needed servicing.
717 do_softint(void *private_)
719 struct cyclades_port *info = (struct cyclades_port *) private_;
720 struct tty_struct *tty;
726 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
727 tty_hangup(info->tty);
728 wake_up_interruptible(&info->open_wait);
729 info->flags &= ~ASYNC_NORMAL_ACTIVE;
731 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) {
732 wake_up_interruptible(&info->open_wait);
734 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
740 /* This is called whenever a port becomes active;
741 interrupts are enabled and DTR & RTS are turned on.
744 startup(struct cyclades_port * info)
747 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
750 if (info->flags & ASYNC_INITIALIZED){
756 set_bit(TTY_IO_ERROR, &info->tty->flags);
760 if (!info->xmit_buf){
761 info->xmit_buf = (unsigned char *) get_zeroed_page (GFP_KERNEL);
762 if (!info->xmit_buf){
769 channel = info->line;
771 #ifdef SERIAL_DEBUG_OPEN
772 printk("startup channel %d\n", channel);
775 local_irq_save(flags);
776 base_addr[CyCAR] = (u_char)channel;
777 write_cy_cmd(base_addr,CyENB_RCVR|CyENB_XMTR);
779 base_addr[CyCAR] = (u_char)channel; /* !!! Is this needed? */
780 base_addr[CyMSVR1] = CyRTS;
781 /* CP('S');CP('1'); */
782 base_addr[CyMSVR2] = CyDTR;
784 #ifdef SERIAL_DEBUG_DTR
785 printk("cyc: %d: raising DTR\n", __LINE__);
786 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
789 base_addr[CyIER] |= CyRxData;
790 info->flags |= ASYNC_INITIALIZED;
793 clear_bit(TTY_IO_ERROR, &info->tty->flags);
795 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
797 local_irq_restore(flags);
799 #ifdef SERIAL_DEBUG_OPEN
806 start_xmit( struct cyclades_port *info )
809 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
812 channel = info->line;
813 local_irq_save(flags);
814 base_addr[CyCAR] = channel;
815 base_addr[CyIER] |= CyTxMpty;
816 local_irq_restore(flags);
820 * This routine shuts down a serial port; interrupts are disabled,
821 * and DTR is dropped if the hangup on close termio flag is on.
824 shutdown(struct cyclades_port * info)
827 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
830 if (!(info->flags & ASYNC_INITIALIZED)){
835 channel = info->line;
837 #ifdef SERIAL_DEBUG_OPEN
838 printk("shutdown channel %d\n", channel);
841 /* !!! REALLY MUST WAIT FOR LAST CHARACTER TO BE
842 SENT BEFORE DROPPING THE LINE !!! (Perhaps
843 set some flag that is read when XMTY happens.)
844 Other choices are to delay some fixed interval
845 or schedule some later processing.
847 local_irq_save(flags);
849 free_page((unsigned long) info->xmit_buf);
853 base_addr[CyCAR] = (u_char)channel;
854 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
855 base_addr[CyMSVR1] = 0;
856 /* CP('C');CP('1'); */
857 base_addr[CyMSVR2] = 0;
858 #ifdef SERIAL_DEBUG_DTR
859 printk("cyc: %d: dropping DTR\n", __LINE__);
860 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
863 write_cy_cmd(base_addr,CyDIS_RCVR);
864 /* it may be appropriate to clear _XMIT at
865 some later date (after testing)!!! */
868 set_bit(TTY_IO_ERROR, &info->tty->flags);
870 info->flags &= ~ASYNC_INITIALIZED;
871 local_irq_restore(flags);
873 #ifdef SERIAL_DEBUG_OPEN
880 * This routine finds or computes the various line characteristics.
883 config_setup(struct cyclades_port * info)
886 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
890 unsigned char ti, need_init_chan = 0;
892 if (!info->tty || !info->tty->termios){
895 if (info->line == -1){
898 cflag = info->tty->termios->c_cflag;
903 /* Starting with kernel 1.1.65, there is direct support for
904 higher baud rates. The following code supports those
905 changes. The conditional aspect allows this driver to be
906 used for earlier as well as later kernel versions. (The
907 mapping is slightly different from serial.c because there
908 is still the possibility of supporting 75 kbit/sec with
914 else if(i == B115200)
921 info->tty->termios->c_cflag &= ~CBAUDEX;
925 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
927 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
930 /* Don't ever change the speed of the console port. It will
931 * run at the speed specified in bootinfo, or at 19.2K */
932 /* Actually, it should run at whatever speed 166Bug was using */
933 /* Note info->timeout isn't used at present */
934 if (info != serial_console_info) {
935 info->tbpr = baud_bpr[i]; /* Tx BPR */
936 info->tco = baud_co[i]; /* Tx CO */
937 info->rbpr = baud_bpr[i]; /* Rx BPR */
938 info->rco = baud_co[i] >> 5; /* Rx CO */
939 if (baud_table[i] == 134) {
940 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
941 /* get it right for 134.5 baud */
942 } else if (baud_table[i]) {
943 info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2;
944 /* this needs to be propagated into the card info */
949 /* By tradition (is it a standard?) a baud rate of zero
950 implies the line should be/has been closed. A bit
951 later in this routine such a test is performed. */
953 /* byte size and parity */
957 info->cor4 = (info->default_threshold
958 ? info->default_threshold
959 : baud_cor4[i]); /* receive threshold */
960 /* Following two lines added 101295, RGH. */
961 /* It is obviously wrong to access CyCORx, and not info->corx here,
962 * try and remember to fix it later! */
963 channel = info->line;
964 base_addr[CyCAR] = (u_char)channel;
965 if (C_CLOCAL(info->tty)) {
966 if (base_addr[CyIER] & CyMdmCh)
967 base_addr[CyIER] &= ~CyMdmCh; /* without modem intr */
968 /* ignore 1->0 modem transitions */
969 if (base_addr[CyCOR4] & (CyDSR|CyCTS|CyDCD))
970 base_addr[CyCOR4] &= ~(CyDSR|CyCTS|CyDCD);
971 /* ignore 0->1 modem transitions */
972 if (base_addr[CyCOR5] & (CyDSR|CyCTS|CyDCD))
973 base_addr[CyCOR5] &= ~(CyDSR|CyCTS|CyDCD);
975 if ((base_addr[CyIER] & CyMdmCh) != CyMdmCh)
976 base_addr[CyIER] |= CyMdmCh; /* with modem intr */
977 /* act on 1->0 modem transitions */
978 if ((base_addr[CyCOR4] & (CyDSR|CyCTS|CyDCD)) != (CyDSR|CyCTS|CyDCD))
979 base_addr[CyCOR4] |= CyDSR|CyCTS|CyDCD;
980 /* act on 0->1 modem transitions */
981 if ((base_addr[CyCOR5] & (CyDSR|CyCTS|CyDCD)) != (CyDSR|CyCTS|CyDCD))
982 base_addr[CyCOR5] |= CyDSR|CyCTS|CyDCD;
984 info->cor3 = (cflag & CSTOPB) ? Cy_2_STOP : Cy_1_STOP;
986 switch(cflag & CSIZE){
988 info->cor1 = Cy_5_BITS;
991 info->cor1 = Cy_6_BITS;
994 info->cor1 = Cy_7_BITS;
997 info->cor1 = Cy_8_BITS;
1000 if (cflag & PARENB){
1001 if (cflag & PARODD){
1002 info->cor1 |= CyPARITY_O;
1004 info->cor1 |= CyPARITY_E;
1007 info->cor1 |= CyPARITY_NONE;
1010 /* CTS flow control flag */
1012 /* Don't complcate matters for now! RGH 141095 */
1013 if (cflag & CRTSCTS){
1014 info->flags |= ASYNC_CTS_FLOW;
1015 info->cor2 |= CyCtsAE;
1017 info->flags &= ~ASYNC_CTS_FLOW;
1018 info->cor2 &= ~CyCtsAE;
1022 info->flags &= ~ASYNC_CHECK_CD;
1024 info->flags |= ASYNC_CHECK_CD;
1026 /***********************************************
1027 The hardware option, CyRtsAO, presents RTS when
1028 the chip has characters to send. Since most modems
1029 use RTS as reverse (inbound) flow control, this
1030 option is not used. If inbound flow control is
1031 necessary, DTR can be programmed to provide the
1032 appropriate signals for use with a non-standard
1033 cable. Contact Marcio Saito for details.
1034 ***********************************************/
1036 channel = info->line;
1038 local_irq_save(flags);
1039 base_addr[CyCAR] = (u_char)channel;
1041 /* CyCMR set once only in mvme167_init_serial() */
1042 if (base_addr[CyLICR] != channel << 2)
1043 base_addr[CyLICR] = channel << 2;
1044 if (base_addr[CyLIVR] != 0x5c)
1045 base_addr[CyLIVR] = 0x5c;
1047 /* tx and rx baud rate */
1049 if (base_addr[CyCOR1] != info->cor1)
1051 if (base_addr[CyTCOR] != info->tco)
1052 base_addr[CyTCOR] = info->tco;
1053 if (base_addr[CyTBPR] != info->tbpr)
1054 base_addr[CyTBPR] = info->tbpr;
1055 if (base_addr[CyRCOR] != info->rco)
1056 base_addr[CyRCOR] = info->rco;
1057 if (base_addr[CyRBPR] != info->rbpr)
1058 base_addr[CyRBPR] = info->rbpr;
1060 /* set line characteristics according configuration */
1062 if (base_addr[CySCHR1] != START_CHAR(info->tty))
1063 base_addr[CySCHR1] = START_CHAR(info->tty);
1064 if (base_addr[CySCHR2] != STOP_CHAR(info->tty))
1065 base_addr[CySCHR2] = STOP_CHAR(info->tty);
1066 if (base_addr[CySCRL] != START_CHAR(info->tty))
1067 base_addr[CySCRL] = START_CHAR(info->tty);
1068 if (base_addr[CySCRH] != START_CHAR(info->tty))
1069 base_addr[CySCRH] = START_CHAR(info->tty);
1070 if (base_addr[CyCOR1] != info->cor1)
1071 base_addr[CyCOR1] = info->cor1;
1072 if (base_addr[CyCOR2] != info->cor2)
1073 base_addr[CyCOR2] = info->cor2;
1074 if (base_addr[CyCOR3] != info->cor3)
1075 base_addr[CyCOR3] = info->cor3;
1076 if (base_addr[CyCOR4] != info->cor4)
1077 base_addr[CyCOR4] = info->cor4;
1078 if (base_addr[CyCOR5] != info->cor5)
1079 base_addr[CyCOR5] = info->cor5;
1080 if (base_addr[CyCOR6] != info->cor6)
1081 base_addr[CyCOR6] = info->cor6;
1082 if (base_addr[CyCOR7] != info->cor7)
1083 base_addr[CyCOR7] = info->cor7;
1086 write_cy_cmd(base_addr,CyINIT_CHAN);
1088 base_addr[CyCAR] = (u_char)channel; /* !!! Is this needed? */
1090 /* 2ms default rx timeout */
1091 ti = info->default_timeout ? info->default_timeout : 0x02;
1092 if (base_addr[CyRTPRL] != ti)
1093 base_addr[CyRTPRL] = ti;
1094 if (base_addr[CyRTPRH] != 0)
1095 base_addr[CyRTPRH] = 0;
1097 /* Set up RTS here also ????? RGH 141095 */
1098 if(i == 0){ /* baud rate is zero, turn off line */
1099 if ((base_addr[CyMSVR2] & CyDTR) == CyDTR)
1100 base_addr[CyMSVR2] = 0;
1101 #ifdef SERIAL_DEBUG_DTR
1102 printk("cyc: %d: dropping DTR\n", __LINE__);
1103 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1106 if ((base_addr[CyMSVR2] & CyDTR) != CyDTR)
1107 base_addr[CyMSVR2] = CyDTR;
1108 #ifdef SERIAL_DEBUG_DTR
1109 printk("cyc: %d: raising DTR\n", __LINE__);
1110 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1115 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1118 local_irq_restore(flags);
1120 } /* config_setup */
1124 cy_put_char(struct tty_struct *tty, unsigned char ch)
1126 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1127 unsigned long flags;
1129 #ifdef SERIAL_DEBUG_IO
1130 printk("cy_put_char %s(0x%02x)\n", tty->name, ch);
1133 if (serial_paranoia_check(info, tty->name, "cy_put_char"))
1136 if (!tty || !info->xmit_buf)
1139 local_irq_save(flags);
1140 if (info->xmit_cnt >= PAGE_SIZE - 1) {
1141 local_irq_restore(flags);
1145 info->xmit_buf[info->xmit_head++] = ch;
1146 info->xmit_head &= PAGE_SIZE - 1;
1148 local_irq_restore(flags);
1153 cy_flush_chars(struct tty_struct *tty)
1155 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1156 unsigned long flags;
1157 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1160 #ifdef SERIAL_DEBUG_IO
1161 printk("cy_flush_chars %s\n", tty->name); /* */
1164 if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
1167 if (info->xmit_cnt <= 0 || tty->stopped
1168 || tty->hw_stopped || !info->xmit_buf)
1171 channel = info->line;
1173 local_irq_save(flags);
1174 base_addr[CyCAR] = channel;
1175 base_addr[CyIER] |= CyTxMpty;
1176 local_irq_restore(flags);
1177 } /* cy_flush_chars */
1180 /* This routine gets called when tty_write has put something into
1181 the write_queue. If the port is not already transmitting stuff,
1182 start it off by enabling interrupts. The interrupt service
1183 routine will then ensure that the characters are sent. If the
1184 port is already active, there is no need to kick it.
1187 cy_write(struct tty_struct * tty,
1188 const unsigned char *buf, int count)
1190 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1191 unsigned long flags;
1194 #ifdef SERIAL_DEBUG_IO
1195 printk("cy_write %s\n", tty->name); /* */
1198 if (serial_paranoia_check(info, tty->name, "cy_write")){
1202 if (!tty || !info->xmit_buf || !tmp_buf){
1207 local_irq_save(flags);
1208 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1209 SERIAL_XMIT_SIZE - info->xmit_head));
1211 local_irq_restore(flags);
1215 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1216 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1217 info->xmit_cnt += c;
1218 local_irq_restore(flags);
1227 && !tty->hw_stopped ) {
1235 cy_write_room(struct tty_struct *tty)
1237 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1240 #ifdef SERIAL_DEBUG_IO
1241 printk("cy_write_room %s\n", tty->name); /* */
1244 if (serial_paranoia_check(info, tty->name, "cy_write_room"))
1246 ret = PAGE_SIZE - info->xmit_cnt - 1;
1250 } /* cy_write_room */
1254 cy_chars_in_buffer(struct tty_struct *tty)
1256 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1258 #ifdef SERIAL_DEBUG_IO
1259 printk("cy_chars_in_buffer %s %d\n", tty->name, info->xmit_cnt); /* */
1262 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
1265 return info->xmit_cnt;
1266 } /* cy_chars_in_buffer */
1270 cy_flush_buffer(struct tty_struct *tty)
1272 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1273 unsigned long flags;
1275 #ifdef SERIAL_DEBUG_IO
1276 printk("cy_flush_buffer %s\n", tty->name); /* */
1279 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
1281 local_irq_save(flags);
1282 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1283 local_irq_restore(flags);
1285 } /* cy_flush_buffer */
1288 /* This routine is called by the upper-layer tty layer to signal
1289 that incoming characters should be throttled or that the
1290 throttle should be released.
1293 cy_throttle(struct tty_struct * tty)
1295 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1296 unsigned long flags;
1297 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1300 #ifdef SERIAL_DEBUG_THROTTLE
1303 printk("throttle %s: %d....\n", tty_name(tty, buf),
1304 tty->ldisc.chars_in_buffer(tty));
1305 printk("cy_throttle %s\n", tty->name);
1308 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")){
1313 info->x_char = STOP_CHAR(tty);
1314 /* Should use the "Send Special Character" feature!!! */
1317 channel = info->line;
1319 local_irq_save(flags);
1320 base_addr[CyCAR] = (u_char)channel;
1321 base_addr[CyMSVR1] = 0;
1322 local_irq_restore(flags);
1329 cy_unthrottle(struct tty_struct * tty)
1331 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1332 unsigned long flags;
1333 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1336 #ifdef SERIAL_DEBUG_THROTTLE
1339 printk("throttle %s: %d....\n", tty_name(tty, buf),
1340 tty->ldisc.chars_in_buffer(tty));
1341 printk("cy_unthrottle %s\n", tty->name);
1344 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")){
1349 info->x_char = START_CHAR(tty);
1350 /* Should use the "Send Special Character" feature!!! */
1353 channel = info->line;
1355 local_irq_save(flags);
1356 base_addr[CyCAR] = (u_char)channel;
1357 base_addr[CyMSVR1] = CyRTS;
1358 local_irq_restore(flags);
1361 } /* cy_unthrottle */
1364 get_serial_info(struct cyclades_port * info,
1365 struct serial_struct * retinfo)
1367 struct serial_struct tmp;
1372 memset(&tmp, 0, sizeof(tmp));
1373 tmp.type = info->type;
1374 tmp.line = info->line;
1375 tmp.port = info->line;
1377 tmp.flags = info->flags;
1378 tmp.baud_base = 0; /*!!!*/
1379 tmp.close_delay = info->close_delay;
1380 tmp.custom_divisor = 0; /*!!!*/
1381 tmp.hub6 = 0; /*!!!*/
1382 return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0;
1383 } /* get_serial_info */
1386 set_serial_info(struct cyclades_port * info,
1387 struct serial_struct * new_info)
1389 struct serial_struct new_serial;
1390 struct cyclades_port old_info;
1395 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
1399 if (!capable(CAP_SYS_ADMIN)) {
1400 if ((new_serial.close_delay != info->close_delay) ||
1401 ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) !=
1402 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK)))
1404 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1405 (new_serial.flags & ASYNC_USR_MASK));
1406 goto check_and_exit;
1411 * OK, past this point, all the error checking has been done.
1412 * At this point, we start making changes.....
1415 info->flags = ((info->flags & ~ASYNC_FLAGS) |
1416 (new_serial.flags & ASYNC_FLAGS));
1417 info->close_delay = new_serial.close_delay;
1421 if (info->flags & ASYNC_INITIALIZED){
1425 return startup(info);
1427 } /* set_serial_info */
1430 cy_tiocmget(struct tty_struct *tty, struct file *file)
1432 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1434 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1435 unsigned long flags;
1436 unsigned char status;
1437 unsigned int result;
1439 channel = info->line;
1441 local_irq_save(flags);
1442 base_addr[CyCAR] = (u_char)channel;
1443 status = base_addr[CyMSVR1] | base_addr[CyMSVR2];
1444 local_irq_restore(flags);
1446 return ((status & CyRTS) ? TIOCM_RTS : 0)
1447 | ((status & CyDTR) ? TIOCM_DTR : 0)
1448 | ((status & CyDCD) ? TIOCM_CAR : 0)
1449 | ((status & CyDSR) ? TIOCM_DSR : 0)
1450 | ((status & CyCTS) ? TIOCM_CTS : 0);
1454 cy_tiocmset(struct tty_struct *tty, struct file *file,
1455 unsigned int set, unsigned int clear)
1457 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1459 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1460 unsigned long flags;
1463 channel = info->line;
1465 if (set & TIOCM_RTS){
1466 local_irq_save(flags);
1467 base_addr[CyCAR] = (u_char)channel;
1468 base_addr[CyMSVR1] = CyRTS;
1469 local_irq_restore(flags);
1471 if (set & TIOCM_DTR){
1472 local_irq_save(flags);
1473 base_addr[CyCAR] = (u_char)channel;
1474 /* CP('S');CP('2'); */
1475 base_addr[CyMSVR2] = CyDTR;
1476 #ifdef SERIAL_DEBUG_DTR
1477 printk("cyc: %d: raising DTR\n", __LINE__);
1478 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1480 local_irq_restore(flags);
1483 if (clear & TIOCM_RTS){
1484 local_irq_save(flags);
1485 base_addr[CyCAR] = (u_char)channel;
1486 base_addr[CyMSVR1] = 0;
1487 local_irq_restore(flags);
1489 if (clear & TIOCM_DTR){
1490 local_irq_save(flags);
1491 base_addr[CyCAR] = (u_char)channel;
1492 /* CP('C');CP('2'); */
1493 base_addr[CyMSVR2] = 0;
1494 #ifdef SERIAL_DEBUG_DTR
1495 printk("cyc: %d: dropping DTR\n", __LINE__);
1496 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1498 local_irq_restore(flags);
1502 } /* set_modem_info */
1505 send_break( struct cyclades_port * info, int duration)
1506 { /* Let the transmit ISR take care of this (since it
1507 requires stuffing characters into the output stream).
1509 info->x_break = duration;
1510 if (!info->xmit_cnt ) {
1516 get_mon_info(struct cyclades_port * info, struct cyclades_monitor * mon)
1519 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
1521 info->mon.int_count = 0;
1522 info->mon.char_count = 0;
1523 info->mon.char_max = 0;
1524 info->mon.char_last = 0;
1529 set_threshold(struct cyclades_port * info, unsigned long *arg)
1531 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1532 unsigned long value;
1535 if (get_user(value, arg))
1538 channel = info->line;
1539 info->cor4 &= ~CyREC_FIFO;
1540 info->cor4 |= value & CyREC_FIFO;
1541 base_addr[CyCOR4] = info->cor4;
1546 get_threshold(struct cyclades_port * info, unsigned long *value)
1548 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1552 channel = info->line;
1554 tmp = base_addr[CyCOR4] & CyREC_FIFO;
1555 return put_user(tmp,value);
1559 set_default_threshold(struct cyclades_port * info, unsigned long *arg)
1561 unsigned long value;
1563 if (get_user(value, arg))
1566 info->default_threshold = value & 0x0f;
1571 get_default_threshold(struct cyclades_port * info, unsigned long *value)
1573 return put_user(info->default_threshold,value);
1577 set_timeout(struct cyclades_port * info, unsigned long *arg)
1579 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1581 unsigned long value;
1583 if (get_user(value, arg))
1586 channel = info->line;
1588 base_addr[CyRTPRL] = value & 0xff;
1589 base_addr[CyRTPRH] = (value >> 8) & 0xff;
1594 get_timeout(struct cyclades_port * info, unsigned long *value)
1596 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1600 channel = info->line;
1602 tmp = base_addr[CyRTPRL];
1603 return put_user(tmp,value);
1607 set_default_timeout(struct cyclades_port * info, unsigned long value)
1609 info->default_timeout = value & 0xff;
1614 get_default_timeout(struct cyclades_port * info, unsigned long *value)
1616 return put_user(info->default_timeout,value);
1620 cy_ioctl(struct tty_struct *tty, struct file * file,
1621 unsigned int cmd, unsigned long arg)
1624 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1627 #ifdef SERIAL_DEBUG_OTHER
1628 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */
1633 ret_val = get_mon_info(info, (struct cyclades_monitor *)arg);
1636 ret_val = get_threshold(info, (unsigned long *)arg);
1639 ret_val = set_threshold(info, (unsigned long *)arg);
1641 case CYGETDEFTHRESH:
1642 ret_val = get_default_threshold(info, (unsigned long *)arg);
1644 case CYSETDEFTHRESH:
1645 ret_val = set_default_threshold(info, (unsigned long *)arg);
1648 ret_val = get_timeout(info, (unsigned long *)arg);
1651 ret_val = set_timeout(info, (unsigned long *)arg);
1653 case CYGETDEFTIMEOUT:
1654 ret_val = get_default_timeout(info, (unsigned long *)arg);
1656 case CYSETDEFTIMEOUT:
1657 ret_val = set_default_timeout(info, (unsigned long)arg);
1659 case TCSBRK: /* SVID version: non-zero arg --> no break */
1660 ret_val = tty_check_change(tty);
1663 tty_wait_until_sent(tty,0);
1665 send_break(info, HZ/4); /* 1/4 second */
1667 case TCSBRKP: /* support for POSIX tcsendbreak() */
1668 ret_val = tty_check_change(tty);
1671 tty_wait_until_sent(tty,0);
1672 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1675 /* The following commands are incompletely implemented!!! */
1677 ret_val = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *) arg);
1680 ret_val = get_user(val, (unsigned long *) arg);
1683 tty->termios->c_cflag =
1684 ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0));
1687 ret_val = get_serial_info(info, (struct serial_struct *) arg);
1690 ret_val = set_serial_info(info,
1691 (struct serial_struct *) arg);
1694 ret_val = -ENOIOCTLCMD;
1697 #ifdef SERIAL_DEBUG_OTHER
1698 printk("cy_ioctl done\n");
1708 cy_set_termios(struct tty_struct *tty, struct termios * old_termios)
1710 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1712 #ifdef SERIAL_DEBUG_OTHER
1713 printk("cy_set_termios %s\n", tty->name);
1716 if (tty->termios->c_cflag == old_termios->c_cflag)
1720 if ((old_termios->c_cflag & CRTSCTS) &&
1721 !(tty->termios->c_cflag & CRTSCTS)) {
1725 #ifdef tytso_patch_94Nov25_1726
1726 if (!(old_termios->c_cflag & CLOCAL) &&
1727 (tty->termios->c_cflag & CLOCAL))
1728 wake_up_interruptible(&info->open_wait);
1732 } /* cy_set_termios */
1736 cy_close(struct tty_struct * tty, struct file * filp)
1738 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1741 #ifdef SERIAL_DEBUG_OTHER
1742 printk("cy_close %s\n", tty->name);
1746 || serial_paranoia_check(info, tty->name, "cy_close")){
1749 #ifdef SERIAL_DEBUG_OPEN
1750 printk("cy_close %s, count = %d\n", tty->name, info->count);
1753 if ((tty->count == 1) && (info->count != 1)) {
1755 * Uh, oh. tty->count is 1, which means that the tty
1756 * structure will be freed. Info->count should always
1757 * be one in these conditions. If it's greater than
1758 * one, we've got real problems, since it means the
1759 * serial port won't be shutdown.
1761 printk("cy_close: bad serial port count; tty->count is 1, "
1762 "info->count is %d\n", info->count);
1765 #ifdef SERIAL_DEBUG_COUNT
1766 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count - 1);
1768 if (--info->count < 0) {
1769 printk("cy_close: bad serial port count for ttys%d: %d\n",
1770 info->line, info->count);
1771 #ifdef SERIAL_DEBUG_COUNT
1772 printk("cyc: %d: setting count to 0\n", __LINE__);
1778 info->flags |= ASYNC_CLOSING;
1779 if (info->flags & ASYNC_INITIALIZED)
1780 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
1782 if (tty->driver->flush_buffer)
1783 tty->driver->flush_buffer(tty);
1784 tty_ldisc_flush(tty);
1787 if (info->blocked_open) {
1788 if (info->close_delay) {
1789 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1791 wake_up_interruptible(&info->open_wait);
1793 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1794 wake_up_interruptible(&info->close_wait);
1796 #ifdef SERIAL_DEBUG_OTHER
1797 printk("cy_close done\n");
1804 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
1807 cy_hangup(struct tty_struct *tty)
1809 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1811 #ifdef SERIAL_DEBUG_OTHER
1812 printk("cy_hangup %s\n", tty->name); /* */
1815 if (serial_paranoia_check(info, tty->name, "cy_hangup"))
1822 #ifdef SERIAL_DEBUG_COUNT
1823 printk("cyc: %d: setting count to 0\n", __LINE__);
1827 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1828 wake_up_interruptible(&info->open_wait);
1834 * ------------------------------------------------------------
1835 * cy_open() and friends
1836 * ------------------------------------------------------------
1840 block_til_ready(struct tty_struct *tty, struct file * filp,
1841 struct cyclades_port *info)
1843 DECLARE_WAITQUEUE(wait, current);
1844 unsigned long flags;
1847 volatile u_char *base_addr = (u_char *)BASE_ADDR;
1850 * If the device is in the middle of being closed, then block
1851 * until it's done, and then try again.
1853 if (info->flags & ASYNC_CLOSING) {
1854 interruptible_sleep_on(&info->close_wait);
1855 if (info->flags & ASYNC_HUP_NOTIFY){
1858 return -ERESTARTSYS;
1863 * If non-blocking mode is set, then make the check up front
1866 if (filp->f_flags & O_NONBLOCK) {
1867 info->flags |= ASYNC_NORMAL_ACTIVE;
1872 * Block waiting for the carrier detect and the line to become
1873 * free (i.e., not in use by the callout). While we are in
1874 * this loop, info->count is dropped by one, so that
1875 * cy_close() knows when to free things. We restore it upon
1876 * exit, either normal or abnormal.
1879 add_wait_queue(&info->open_wait, &wait);
1880 #ifdef SERIAL_DEBUG_OPEN
1881 printk("block_til_ready before block: %s, count = %d\n",
1882 tty->name, info->count);/**/
1885 #ifdef SERIAL_DEBUG_COUNT
1886 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count);
1888 info->blocked_open++;
1890 channel = info->line;
1893 local_irq_save(flags);
1894 base_addr[CyCAR] = (u_char)channel;
1895 base_addr[CyMSVR1] = CyRTS;
1896 /* CP('S');CP('4'); */
1897 base_addr[CyMSVR2] = CyDTR;
1898 #ifdef SERIAL_DEBUG_DTR
1899 printk("cyc: %d: raising DTR\n", __LINE__);
1900 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1902 local_irq_restore(flags);
1903 set_current_state(TASK_INTERRUPTIBLE);
1904 if (tty_hung_up_p(filp)
1905 || !(info->flags & ASYNC_INITIALIZED) ){
1906 if (info->flags & ASYNC_HUP_NOTIFY) {
1909 retval = -ERESTARTSYS;
1913 local_irq_save(flags);
1914 base_addr[CyCAR] = (u_char)channel;
1915 /* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */
1916 if (!(info->flags & ASYNC_CLOSING)
1918 || (base_addr[CyMSVR1] & CyDCD))) {
1919 local_irq_restore(flags);
1922 local_irq_restore(flags);
1923 if (signal_pending(current)) {
1924 retval = -ERESTARTSYS;
1927 #ifdef SERIAL_DEBUG_OPEN
1928 printk("block_til_ready blocking: %s, count = %d\n",
1929 tty->name, info->count);/**/
1933 current->state = TASK_RUNNING;
1934 remove_wait_queue(&info->open_wait, &wait);
1935 if (!tty_hung_up_p(filp)){
1937 #ifdef SERIAL_DEBUG_COUNT
1938 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
1941 info->blocked_open--;
1942 #ifdef SERIAL_DEBUG_OPEN
1943 printk("block_til_ready after blocking: %s, count = %d\n",
1944 tty->name, info->count);/**/
1948 info->flags |= ASYNC_NORMAL_ACTIVE;
1950 } /* block_til_ready */
1953 * This routine is called whenever a serial port is opened. It
1954 * performs the serial-specific initialization for the tty structure.
1957 cy_open(struct tty_struct *tty, struct file * filp)
1959 struct cyclades_port *info;
1964 if ((line < 0) || (NR_PORTS <= line)){
1967 info = &cy_port[line];
1968 if (info->line < 0){
1971 #ifdef SERIAL_DEBUG_OTHER
1972 printk("cy_open %s\n", tty->name); /* */
1974 if (serial_paranoia_check(info, tty->name, "cy_open")){
1977 #ifdef SERIAL_DEBUG_OPEN
1978 printk("cy_open %s, count = %d\n", tty->name, info->count);/**/
1981 #ifdef SERIAL_DEBUG_COUNT
1982 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
1984 tty->driver_data = info;
1988 tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL);
1995 * Start up serial port
1997 retval = startup(info);
2002 retval = block_til_ready(tty, filp, info);
2004 #ifdef SERIAL_DEBUG_OPEN
2005 printk("cy_open returning after block_til_ready with %d\n",
2011 #ifdef SERIAL_DEBUG_OPEN
2012 printk("cy_open done\n");/**/
2020 * ---------------------------------------------------------------------
2021 * serial167_init() and friends
2023 * serial167_init() is called at boot-time to initialize the serial driver.
2024 * ---------------------------------------------------------------------
2028 * This routine prints out the appropriate serial driver version
2029 * number, and identifies which options were configured into this
2035 printk("MVME166/167 cd2401 driver\n");
2036 } /* show_version */
2038 /* initialize chips on card -- return number of valid
2039 chips (which is number of ports/4) */
2042 * This initialises the hardware to a reasonable state. It should
2043 * probe the chip first so as to copy 166-Bug setup as a default for
2044 * port 0. It initialises CMR to CyASYNC; that is never done again, so
2045 * as to limit the number of CyINIT_CHAN commands in normal running.
2047 * ... I wonder what I should do if this fails ...
2051 mvme167_serial_console_setup(int cflag)
2053 volatile unsigned char* base_addr = (u_char *)BASE_ADDR;
2056 u_char rcor, rbpr, badspeed = 0;
2057 unsigned long flags;
2059 local_irq_save(flags);
2062 * First probe channel zero of the chip, to see what speed has
2066 base_addr[CyCAR] = 0;
2068 rcor = base_addr[CyRCOR] << 5;
2069 rbpr = base_addr[CyRBPR];
2071 for (spd = 0; spd < sizeof(baud_bpr); spd++)
2072 if (rbpr == baud_bpr[spd] && rcor == baud_co[spd])
2074 if (spd >= sizeof(baud_bpr)) {
2075 spd = 14; /* 19200 */
2076 badspeed = 1; /* Failed to identify speed */
2078 initial_console_speed = spd;
2080 /* OK, we have chosen a speed, now reset and reinitialise */
2082 my_udelay(20000L); /* Allow time for any active o/p to complete */
2083 if(base_addr[CyCCR] != 0x00){
2084 local_irq_restore(flags);
2085 /* printk(" chip is never idle (CCR != 0)\n"); */
2089 base_addr[CyCCR] = CyCHIP_RESET; /* Reset the chip */
2092 if(base_addr[CyGFRCR] == 0x00){
2093 local_irq_restore(flags);
2094 /* printk(" chip is not responding (GFRCR stayed 0)\n"); */
2099 * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms
2103 base_addr[CyTPR] = 10;
2105 base_addr[CyPILR1] = 0x01; /* Interrupt level for modem change */
2106 base_addr[CyPILR2] = 0x02; /* Interrupt level for tx ints */
2107 base_addr[CyPILR3] = 0x03; /* Interrupt level for rx ints */
2110 * Attempt to set up all channels to something reasonable, and
2111 * bang out a INIT_CHAN command. We should then be able to limit
2112 * the ammount of fiddling we have to do in normal running.
2115 for (ch = 3; ch >= 0 ; ch--) {
2116 base_addr[CyCAR] = (u_char)ch;
2117 base_addr[CyIER] = 0;
2118 base_addr[CyCMR] = CyASYNC;
2119 base_addr[CyLICR] = (u_char)ch << 2;
2120 base_addr[CyLIVR] = 0x5c;
2121 base_addr[CyTCOR] = baud_co[spd];
2122 base_addr[CyTBPR] = baud_bpr[spd];
2123 base_addr[CyRCOR] = baud_co[spd] >> 5;
2124 base_addr[CyRBPR] = baud_bpr[spd];
2125 base_addr[CySCHR1] = 'Q' & 0x1f;
2126 base_addr[CySCHR2] = 'X' & 0x1f;
2127 base_addr[CySCRL] = 0;
2128 base_addr[CySCRH] = 0;
2129 base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
2130 base_addr[CyCOR2] = 0;
2131 base_addr[CyCOR3] = Cy_1_STOP;
2132 base_addr[CyCOR4] = baud_cor4[spd];
2133 base_addr[CyCOR5] = 0;
2134 base_addr[CyCOR6] = 0;
2135 base_addr[CyCOR7] = 0;
2136 base_addr[CyRTPRL] = 2;
2137 base_addr[CyRTPRH] = 0;
2138 base_addr[CyMSVR1] = 0;
2139 base_addr[CyMSVR2] = 0;
2140 write_cy_cmd(base_addr,CyINIT_CHAN|CyDIS_RCVR|CyDIS_XMTR);
2144 * Now do specials for channel zero....
2147 base_addr[CyMSVR1] = CyRTS;
2148 base_addr[CyMSVR2] = CyDTR;
2149 base_addr[CyIER] = CyRxData;
2150 write_cy_cmd(base_addr,CyENB_RCVR|CyENB_XMTR);
2152 local_irq_restore(flags);
2154 my_udelay(20000L); /* Let it all settle down */
2156 printk("CD2401 initialised, chip is rev 0x%02x\n", base_addr[CyGFRCR]);
2158 printk(" WARNING: Failed to identify line speed, rcor=%02x,rbpr=%02x\n",
2160 } /* serial_console_init */
2162 static struct tty_operations cy_ops = {
2166 .put_char = cy_put_char,
2167 .flush_chars = cy_flush_chars,
2168 .write_room = cy_write_room,
2169 .chars_in_buffer = cy_chars_in_buffer,
2170 .flush_buffer = cy_flush_buffer,
2172 .throttle = cy_throttle,
2173 .unthrottle = cy_unthrottle,
2174 .set_termios = cy_set_termios,
2177 .hangup = cy_hangup,
2178 .tiocmget = cy_tiocmget,
2179 .tiocmset = cy_tiocmset,
2181 /* The serial driver boot-time initialization code!
2182 Hardware I/O ports are mapped to character special devices on a
2183 first found, first allocated manner. That is, this code searches
2184 for Cyclom cards in the system. As each is found, it is probed
2185 to discover how many chips (and thus how many ports) are present.
2186 These ports are mapped to the tty ports 64 and upward in monotonic
2187 fashion. If an 8-port card is replaced with a 16-port card, the
2188 port mapping on a following card will shift.
2190 This approach is different from what is used in the other serial
2191 device driver because the Cyclom is more properly a multiplexer,
2192 not just an aggregation of serial ports on one card.
2194 If there are more cards with more ports than have been statically
2195 allocated above, a warning is printed and the extra ports are ignored.
2198 serial167_init(void)
2200 struct cyclades_port *info;
2207 struct sigaction sa;
2210 if (!(mvme16x_config &MVME16x_CONFIG_GOT_CD2401))
2213 cy_serial_driver = alloc_tty_driver(NR_PORTS);
2214 if (!cy_serial_driver)
2223 /* Has "console=0,9600n8" been used in bootinfo to change speed? */
2224 if (serial_console_cflag)
2225 DefSpeed = serial_console_cflag & 0017;
2227 DefSpeed = initial_console_speed;
2228 serial_console_info = &cy_port[0];
2229 serial_console_cflag = DefSpeed | CS8;
2231 serial_console = 64; /*callout_driver.minor_start*/
2235 /* Initialize the tty_driver structure */
2237 cy_serial_driver->owner = THIS_MODULE;
2238 cy_serial_driver->devfs_name = "tts/";
2239 cy_serial_driver->name = "ttyS";
2240 cy_serial_driver->major = TTY_MAJOR;
2241 cy_serial_driver->minor_start = 64;
2242 cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
2243 cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
2244 cy_serial_driver->init_termios = tty_std_termios;
2245 cy_serial_driver->init_termios.c_cflag =
2246 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2247 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
2248 tty_set_operations(cy_serial_driver, &cy_ops);
2250 ret = tty_register_driver(cy_serial_driver);
2252 printk(KERN_ERR "Couldn't register MVME166/7 serial driver\n");
2253 put_tty_driver(cy_serial_driver);
2259 for (index = 0; index < 1; index++) {
2263 if(port_num < NR_PORTS){
2264 while( good_ports-- && port_num < NR_PORTS){
2265 /*** initialize port ***/
2266 info->magic = CYCLADES_MAGIC;
2267 info->type = PORT_CIRRUS;
2269 info->line = port_num;
2270 info->flags = STD_COM_FLAGS;
2272 info->xmit_fifo_size = 12;
2273 info->cor1 = CyPARITY_NONE|Cy_8_BITS;
2275 info->cor3 = Cy_1_STOP;
2276 info->cor4 = 0x08; /* _very_ small receive threshold */
2280 info->tbpr = baud_bpr[DefSpeed]; /* Tx BPR */
2281 info->tco = baud_co[DefSpeed]; /* Tx CO */
2282 info->rbpr = baud_bpr[DefSpeed]; /* Rx BPR */
2283 info->rco = baud_co[DefSpeed] >> 5; /* Rx CO */
2284 info->close_delay = 0;
2288 #ifdef SERIAL_DEBUG_COUNT
2289 printk("cyc: %d: setting count to 0\n", __LINE__);
2291 info->blocked_open = 0;
2292 info->default_threshold = 0;
2293 info->default_timeout = 0;
2294 INIT_WORK(&info->tqueue, do_softint, info);
2295 init_waitqueue_head(&info->open_wait);
2296 init_waitqueue_head(&info->close_wait);
2299 /*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/
2300 info->read_status_mask = CyTIMEOUT| CySPECHAR| CyBREAK
2301 | CyPARITY| CyFRAME| CyOVERRUN;
2304 printk("ttyS%d ", info->line);
2306 if(!(port_num & 7)){
2313 while( port_num < NR_PORTS){
2317 #ifdef CONFIG_REMOTE_DEBUG
2320 ret = request_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt, 0,
2321 "cd2401_errors", cd2401_rxerr_interrupt);
2323 printk(KERN_ERR "Could't get cd2401_errors IRQ");
2324 goto cleanup_serial_driver;
2327 ret = request_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt, 0,
2328 "cd2401_modem", cd2401_modem_interrupt);
2330 printk(KERN_ERR "Could't get cd2401_modem IRQ");
2331 goto cleanup_irq_cd2401_errors;
2334 ret = request_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt, 0,
2335 "cd2401_txints", cd2401_tx_interrupt);
2337 printk(KERN_ERR "Could't get cd2401_txints IRQ");
2338 goto cleanup_irq_cd2401_modem;
2341 ret = request_irq(MVME167_IRQ_SER_RX, cd2401_rx_interrupt, 0,
2342 "cd2401_rxints", cd2401_rx_interrupt);
2344 printk(KERN_ERR "Could't get cd2401_rxints IRQ");
2345 goto cleanup_irq_cd2401_txints;
2348 /* Now we have registered the interrupt handlers, allow the interrupts */
2350 pcc2chip[PccSCCMICR] = 0x15; /* Serial ints are level 5 */
2351 pcc2chip[PccSCCTICR] = 0x15;
2352 pcc2chip[PccSCCRICR] = 0x15;
2354 pcc2chip[PccIMLR] = 3; /* Allow PCC2 ints above 3!? */
2357 cleanup_irq_cd2401_txints:
2358 free_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt);
2359 cleanup_irq_cd2401_modem:
2360 free_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt);
2361 cleanup_irq_cd2401_errors:
2362 free_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt);
2363 cleanup_serial_driver:
2364 if (tty_unregister_driver(cy_serial_driver))
2365 printk(KERN_ERR "Couldn't unregister MVME166/7 serial driver\n");
2366 put_tty_driver(cy_serial_driver);
2368 } /* serial167_init */
2370 module_init(serial167_init);
2373 #ifdef CYCLOM_SHOW_STATUS
2375 show_status(int line_num)
2377 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2379 struct cyclades_port * info;
2380 unsigned long flags;
2382 info = &cy_port[line_num];
2383 channel = info->line;
2384 printk(" channel %d\n", channel);/**/
2386 printk(" cy_port\n");
2387 printk(" card line flags = %d %d %x\n",
2388 info->card, info->line, info->flags);
2389 printk(" *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n",
2390 (long)info->tty, info->read_status_mask,
2391 info->timeout, info->xmit_fifo_size);
2392 printk(" cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n",
2393 info->cor1, info->cor2, info->cor3, info->cor4, info->cor5,
2394 info->cor6, info->cor7);
2395 printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n",
2396 info->tbpr, info->tco, info->rbpr, info->rco);
2397 printk(" close_delay event count = %d %d %d\n",
2398 info->close_delay, info->event, info->count);
2399 printk(" x_char blocked_open = %x %x\n",
2400 info->x_char, info->blocked_open);
2401 printk(" open_wait = %lx %lx %lx\n",
2402 (long)info->open_wait);
2405 local_irq_save(flags);
2407 /* Global Registers */
2409 printk(" CyGFRCR %x\n", base_addr[CyGFRCR]);
2410 printk(" CyCAR %x\n", base_addr[CyCAR]);
2411 printk(" CyRISR %x\n", base_addr[CyRISR]);
2412 printk(" CyTISR %x\n", base_addr[CyTISR]);
2413 printk(" CyMISR %x\n", base_addr[CyMISR]);
2414 printk(" CyRIR %x\n", base_addr[CyRIR]);
2415 printk(" CyTIR %x\n", base_addr[CyTIR]);
2416 printk(" CyMIR %x\n", base_addr[CyMIR]);
2417 printk(" CyTPR %x\n", base_addr[CyTPR]);
2419 base_addr[CyCAR] = (u_char)channel;
2421 /* Virtual Registers */
2424 printk(" CyRIVR %x\n", base_addr[CyRIVR]);
2425 printk(" CyTIVR %x\n", base_addr[CyTIVR]);
2426 printk(" CyMIVR %x\n", base_addr[CyMIVR]);
2427 printk(" CyMISR %x\n", base_addr[CyMISR]);
2430 /* Channel Registers */
2432 printk(" CyCCR %x\n", base_addr[CyCCR]);
2433 printk(" CyIER %x\n", base_addr[CyIER]);
2434 printk(" CyCOR1 %x\n", base_addr[CyCOR1]);
2435 printk(" CyCOR2 %x\n", base_addr[CyCOR2]);
2436 printk(" CyCOR3 %x\n", base_addr[CyCOR3]);
2437 printk(" CyCOR4 %x\n", base_addr[CyCOR4]);
2438 printk(" CyCOR5 %x\n", base_addr[CyCOR5]);
2440 printk(" CyCCSR %x\n", base_addr[CyCCSR]);
2441 printk(" CyRDCR %x\n", base_addr[CyRDCR]);
2443 printk(" CySCHR1 %x\n", base_addr[CySCHR1]);
2444 printk(" CySCHR2 %x\n", base_addr[CySCHR2]);
2446 printk(" CySCHR3 %x\n", base_addr[CySCHR3]);
2447 printk(" CySCHR4 %x\n", base_addr[CySCHR4]);
2448 printk(" CySCRL %x\n", base_addr[CySCRL]);
2449 printk(" CySCRH %x\n", base_addr[CySCRH]);
2450 printk(" CyLNC %x\n", base_addr[CyLNC]);
2451 printk(" CyMCOR1 %x\n", base_addr[CyMCOR1]);
2452 printk(" CyMCOR2 %x\n", base_addr[CyMCOR2]);
2454 printk(" CyRTPRL %x\n", base_addr[CyRTPRL]);
2455 printk(" CyRTPRH %x\n", base_addr[CyRTPRH]);
2456 printk(" CyMSVR1 %x\n", base_addr[CyMSVR1]);
2457 printk(" CyMSVR2 %x\n", base_addr[CyMSVR2]);
2458 printk(" CyRBPR %x\n", base_addr[CyRBPR]);
2459 printk(" CyRCOR %x\n", base_addr[CyRCOR]);
2460 printk(" CyTBPR %x\n", base_addr[CyTBPR]);
2461 printk(" CyTCOR %x\n", base_addr[CyTCOR]);
2463 local_irq_restore(flags);
2469 /* Dummy routine in mvme16x/config.c for now */
2471 /* Serial console setup. Called from linux/init/main.c */
2473 void console_setup(char *str, int *ints)
2476 int baud, bits, parity;
2480 if (ints[0] > 3 || ints[1] > 3) return;
2482 /* Get baud, bits and parity */
2486 if (ints[2]) baud = ints[2];
2487 if ((s = strchr(str, ','))) {
2490 } while(*s >= '0' && *s <= '9');
2491 if (*s) parity = *s++;
2492 if (*s) bits = *s - '0';
2495 /* Now construct a cflag setting. */
2532 serial_console_info = &cy_port[ints[1]];
2533 serial_console_cflag = cflag;
2534 serial_console = ints[1] + 64; /*callout_driver.minor_start*/
2539 * The following is probably out of date for 2.1.x serial console stuff.
2541 * The console is registered early on from arch/m68k/kernel/setup.c, and
2542 * it therefore relies on the chip being setup correctly by 166-Bug. This
2543 * seems reasonable, as the serial port has been used to invoke the system
2544 * boot. It also means that this function must not rely on any data
2545 * initialisation performed by serial167_init() etc.
2547 * Of course, once the console has been registered, we had better ensure
2548 * that serial167_init() doesn't leave the chip non-functional.
2550 * The console must be locked when we get here.
2553 void serial167_console_write(struct console *co, const char *str, unsigned count)
2555 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2556 unsigned long flags;
2557 volatile u_char sink;
2563 local_irq_save(flags);
2565 /* Ensure transmitter is enabled! */
2568 base_addr[CyCAR] = (u_char)port;
2569 while (base_addr[CyCCR])
2571 base_addr[CyCCR] = CyENB_XMTR;
2573 ier = base_addr[CyIER];
2574 base_addr[CyIER] = CyTxMpty;
2577 if (pcc2chip[PccSCCTICR] & 0x20)
2579 /* We have a Tx int. Acknowledge it */
2580 sink = pcc2chip[PccTPIACKR];
2581 if ((base_addr[CyLICR] >> 2) == port) {
2583 /* Last char of string is now output */
2584 base_addr[CyTEOIR] = CyNOTRANS;
2588 base_addr[CyTDR] = '\n';
2593 else if (*str == '\n') {
2594 base_addr[CyTDR] = '\r';
2598 base_addr[CyTDR] = *str++;
2601 base_addr[CyTEOIR] = 0;
2604 base_addr[CyTEOIR] = CyNOTRANS;
2608 base_addr[CyIER] = ier;
2610 local_irq_restore(flags);
2613 static struct tty_driver *serial167_console_device(struct console *c, int *index)
2616 return cy_serial_driver;
2620 static int __init serial167_console_setup(struct console *co, char *options)
2626 static struct console sercons = {
2628 .write = serial167_console_write,
2629 .device = serial167_console_device,
2630 .setup = serial167_console_setup,
2631 .flags = CON_PRINTBUFFER,
2636 static int __init serial167_console_init(void)
2638 if (vme_brdtype == VME_TYPE_MVME166 ||
2639 vme_brdtype == VME_TYPE_MVME167 ||
2640 vme_brdtype == VME_TYPE_MVME177) {
2641 mvme167_serial_console_setup(0);
2642 register_console(&sercons);
2646 console_initcall(serial167_console_init);
2648 #ifdef CONFIG_REMOTE_DEBUG
2649 void putDebugChar (int c)
2651 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2652 unsigned long flags;
2653 volatile u_char sink;
2657 local_irq_save(flags);
2659 /* Ensure transmitter is enabled! */
2662 base_addr[CyCAR] = (u_char)port;
2663 while (base_addr[CyCCR])
2665 base_addr[CyCCR] = CyENB_XMTR;
2667 ier = base_addr[CyIER];
2668 base_addr[CyIER] = CyTxMpty;
2671 if (pcc2chip[PccSCCTICR] & 0x20)
2673 /* We have a Tx int. Acknowledge it */
2674 sink = pcc2chip[PccTPIACKR];
2675 if ((base_addr[CyLICR] >> 2) == port) {
2676 base_addr[CyTDR] = c;
2677 base_addr[CyTEOIR] = 0;
2681 base_addr[CyTEOIR] = CyNOTRANS;
2685 base_addr[CyIER] = ier;
2687 local_irq_restore(flags);
2692 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2693 unsigned long flags;
2694 volatile u_char sink;
2700 if (i != debugiq.in) {
2702 if (++i == DEBUG_LEN)
2707 /* OK, nothing in queue, wait in poll loop */
2709 local_irq_save(flags);
2711 /* Ensure receiver is enabled! */
2714 base_addr[CyCAR] = (u_char)port;
2716 while (base_addr[CyCCR])
2718 base_addr[CyCCR] = CyENB_RCVR;
2720 ier = base_addr[CyIER];
2721 base_addr[CyIER] = CyRxData;
2724 if (pcc2chip[PccSCCRICR] & 0x20)
2726 /* We have a Rx int. Acknowledge it */
2727 sink = pcc2chip[PccRPIACKR];
2728 if ((base_addr[CyLICR] >> 2) == port) {
2729 int cnt = base_addr[CyRFOC];
2732 c = base_addr[CyRDR];
2734 printk ("!! debug char is null (cnt=%d) !!", cnt);
2738 base_addr[CyREOIR] = 0;
2740 if (i == debugiq.in)
2741 panic ("Debug input queue empty!");
2743 if (++i == DEBUG_LEN)
2749 base_addr[CyREOIR] = CyNOTRANS;
2753 base_addr[CyIER] = ier;
2755 local_irq_restore(flags);
2760 void queueDebugChar (int c)
2766 if (++i == DEBUG_LEN)
2768 if (i != debugiq.out)
2775 unsigned long flags;
2776 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2781 local_irq_save(flags);
2783 for (i = 0; i < 4; i++)
2785 base_addr[CyCAR] = i;
2786 base_addr[CyLICR] = i << 2;
2789 debugiq.in = debugiq.out = 0;
2791 base_addr[CyCAR] = DEBUG_PORT;
2796 base_addr[CyIER] = 0;
2798 base_addr[CyCMR] = CyASYNC;
2799 base_addr[CyLICR] = DEBUG_PORT << 2;
2800 base_addr[CyLIVR] = 0x5c;
2802 /* tx and rx baud rate */
2804 base_addr[CyTCOR] = baud_co[i];
2805 base_addr[CyTBPR] = baud_bpr[i];
2806 base_addr[CyRCOR] = baud_co[i] >> 5;
2807 base_addr[CyRBPR] = baud_bpr[i];
2809 /* set line characteristics according configuration */
2811 base_addr[CySCHR1] = 0;
2812 base_addr[CySCHR2] = 0;
2813 base_addr[CySCRL] = 0;
2814 base_addr[CySCRH] = 0;
2815 base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
2816 base_addr[CyCOR2] = 0;
2817 base_addr[CyCOR3] = Cy_1_STOP;
2818 base_addr[CyCOR4] = baud_cor4[i];
2819 base_addr[CyCOR5] = 0;
2820 base_addr[CyCOR6] = 0;
2821 base_addr[CyCOR7] = 0;
2823 write_cy_cmd(base_addr,CyINIT_CHAN);
2824 write_cy_cmd(base_addr,CyENB_RCVR);
2826 base_addr[CyCAR] = DEBUG_PORT; /* !!! Is this needed? */
2828 base_addr[CyRTPRL] = 2;
2829 base_addr[CyRTPRH] = 0;
2831 base_addr[CyMSVR1] = CyRTS;
2832 base_addr[CyMSVR2] = CyDTR;
2834 base_addr[CyIER] = CyRxData;
2836 local_irq_restore(flags);
2842 MODULE_LICENSE("GPL");