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/errno.h>
48 #include <linux/signal.h>
49 #include <linux/sched.h>
50 #include <linux/timer.h>
51 #include <linux/tty.h>
52 #include <linux/interrupt.h>
53 #include <linux/serial.h>
54 #include <linux/serialP.h>
55 #include <linux/string.h>
56 #include <linux/fcntl.h>
57 #include <linux/ptrace.h>
58 #include <linux/serial167.h>
59 #include <linux/delay.h>
60 #include <linux/major.h>
62 #include <linux/console.h>
63 #include <linux/module.h>
64 #include <linux/bitops.h>
66 #include <asm/system.h>
68 #include <asm/mvme16xhw.h>
69 #include <asm/bootinfo.h>
70 #include <asm/setup.h>
72 #include <linux/types.h>
73 #include <linux/kernel.h>
75 #include <asm/uaccess.h>
76 #include <linux/init.h>
78 #define SERIAL_PARANOIA_CHECK
79 #undef SERIAL_DEBUG_OPEN
80 #undef SERIAL_DEBUG_THROTTLE
81 #undef SERIAL_DEBUG_OTHER
82 #undef SERIAL_DEBUG_IO
83 #undef SERIAL_DEBUG_COUNT
84 #undef SERIAL_DEBUG_DTR
85 #undef CYCLOM_16Y_HACK
86 #define CYCLOM_ENABLE_MONITORING
88 #define WAKEUP_CHARS 256
90 #define STD_COM_FLAGS (0)
92 #define SERIAL_TYPE_NORMAL 1
94 static struct tty_driver *cy_serial_driver;
95 extern int serial_console;
96 static struct cyclades_port *serial_console_info = NULL;
97 static unsigned int serial_console_cflag = 0;
98 u_char initial_console_speed;
100 /* Base address of cd2401 chip on mvme166/7 */
102 #define BASE_ADDR (0xfff45000)
103 #define pcc2chip ((volatile u_char *)0xfff42000)
104 #define PccSCCMICR 0x1d
105 #define PccSCCTICR 0x1e
106 #define PccSCCRICR 0x1f
107 #define PccTPIACKR 0x25
108 #define PccRPIACKR 0x27
111 /* This is the per-port data structure */
112 struct cyclades_port cy_port[] = {
119 #define NR_PORTS ARRAY_SIZE(cy_port)
122 * This is used to look up the divisor speeds and the timeouts
123 * We're normally limited to 15 distinct baud rates. The extra
124 * are accessed via settings in info->flags.
125 * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
126 * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
129 static int baud_table[] = {
130 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
131 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000,
135 static char baud_co[] = { /* 25 MHz clock option table */
136 /* value => 00 01 02 03 04 */
137 /* divide by 8 32 128 512 2048 */
138 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
139 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
141 static char baud_bpr[] = { /* 25 MHz baud rate period table */
142 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
143 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15};
146 /* I think 166 brd clocks 2401 at 20MHz.... */
148 /* These values are written directly to tcor, and >> 5 for writing to rcor */
149 static u_char baud_co[] = { /* 20 MHz clock option table */
150 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x60, 0x60, 0x40,
151 0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
153 /* These values written directly to tbpr/rbpr */
154 static u_char baud_bpr[] = { /* 20 MHz baud rate period table */
155 0x00, 0xc0, 0x80, 0x58, 0x6c, 0x40, 0xc0, 0x81, 0x40, 0x81,
156 0x57, 0x40, 0x81, 0x40, 0x81, 0x40, 0x2b, 0x20, 0x15, 0x10};
158 static u_char baud_cor4[] = { /* receive threshold */
159 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
160 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07};
164 static void shutdown(struct cyclades_port *);
165 static int startup (struct cyclades_port *);
166 static void cy_throttle(struct tty_struct *);
167 static void cy_unthrottle(struct tty_struct *);
168 static void config_setup(struct cyclades_port *);
169 extern void console_print(const char *);
170 #ifdef CYCLOM_SHOW_STATUS
171 static void show_status(int);
174 #ifdef CONFIG_REMOTE_DEBUG
175 static void debug_setup(void);
176 void queueDebugChar (int c);
177 int getDebugChar(void);
180 #define DEBUG_LEN 256
185 unsigned char buf[DEBUG_LEN];
192 * I have my own version of udelay(), as it is needed when initialising
193 * the chip, before the delay loop has been calibrated. Should probably
194 * reference one of the vmechip2 or pccchip2 counter for an accurate
195 * delay, but this wild guess will do for now.
198 void my_udelay (long us)
201 volatile u_char *p = &x;
205 for (i = 100; i; i--)
210 serial_paranoia_check(struct cyclades_port *info, char *name,
213 #ifdef SERIAL_PARANOIA_CHECK
214 static const char *badmagic =
215 "Warning: bad magic number for serial struct (%s) in %s\n";
216 static const char *badinfo =
217 "Warning: null cyclades_port for (%s) in %s\n";
218 static const char *badrange =
219 "Warning: cyclades_port out of range for (%s) in %s\n";
222 printk(badinfo, name, routine);
226 if( (long)info < (long)(&cy_port[0])
227 || (long)(&cy_port[NR_PORTS]) < (long)info ){
228 printk(badrange, name, routine);
232 if (info->magic != CYCLADES_MAGIC) {
233 printk(badmagic, name, routine);
238 } /* serial_paranoia_check */
241 /* The following diagnostic routines allow the driver to spew
242 information on the screen, even (especially!) during interrupts.
247 local_irq_save(flags);
249 local_irq_restore(flags);
255 local_irq_save(flags);
258 local_irq_restore(flags);
261 void CP1(int data) { (data<10)? CP(data+'0'): CP(data+'A'-10); }/* CP1 */
262 void CP2(int data) { CP1((data>>4) & 0x0f); CP1( data & 0x0f); }/* CP2 */
263 void CP4(int data) { CP2((data>>8) & 0xff); CP2(data & 0xff); }/* CP4 */
264 void CP8(long data) { CP4((data>>16) & 0xffff); CP4(data & 0xffff); }/* CP8 */
267 /* This routine waits up to 1000 micro-seconds for the previous
268 command to the Cirrus chip to complete and then issues the
269 new command. An error is returned if the previous command
270 didn't finish within the time limit.
273 write_cy_cmd(volatile u_char *base_addr, u_char cmd)
278 local_irq_save(flags);
279 /* Check to see that the previous command has completed */
280 for(i = 0 ; i < 100 ; i++){
281 if (base_addr[CyCCR] == 0){
286 /* if the CCR never cleared, the previous command
287 didn't finish within the "reasonable time" */
289 local_irq_restore(flags);
293 /* Issue the new command */
294 base_addr[CyCCR] = cmd;
295 local_irq_restore(flags);
300 /* cy_start and cy_stop provide software output flow control as a
301 function of XON/XOFF, software CTS, and other such stuff. */
304 cy_stop(struct tty_struct *tty)
306 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
307 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
311 #ifdef SERIAL_DEBUG_OTHER
312 printk("cy_stop %s\n", tty->name); /* */
315 if (serial_paranoia_check(info, tty->name, "cy_stop"))
318 channel = info->line;
320 local_irq_save(flags);
321 base_addr[CyCAR] = (u_char)(channel); /* index channel */
322 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
323 local_irq_restore(flags);
329 cy_start(struct tty_struct *tty)
331 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
332 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
336 #ifdef SERIAL_DEBUG_OTHER
337 printk("cy_start %s\n", tty->name); /* */
340 if (serial_paranoia_check(info, tty->name, "cy_start"))
343 channel = info->line;
345 local_irq_save(flags);
346 base_addr[CyCAR] = (u_char)(channel);
347 base_addr[CyIER] |= CyTxMpty;
348 local_irq_restore(flags);
355 * This routine is used by the interrupt handler to schedule
356 * processing in the software interrupt portion of the driver
357 * (also known as the "bottom half"). This can be called any
358 * number of times for any channel without harm.
361 cy_sched_event(struct cyclades_port *info, int event)
363 info->event |= 1 << event; /* remember what kind of event and who */
364 schedule_work(&info->tqueue);
365 } /* cy_sched_event */
368 /* The real interrupt service routines are called
369 whenever the card wants its hand held--chars
370 received, out buffer empty, modem change, etc.
373 cd2401_rxerr_interrupt(int irq, void *dev_id)
375 struct tty_struct *tty;
376 struct cyclades_port *info;
377 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
378 unsigned char err, rfoc;
382 /* determine the channel and change to that context */
383 channel = (u_short ) (base_addr[CyLICR] >> 2);
384 info = &cy_port[channel];
385 info->last_active = jiffies;
387 if ((err = base_addr[CyRISR]) & CyTIMEOUT) {
388 /* This is a receive timeout interrupt, ignore it */
389 base_addr[CyREOIR] = CyNOTRANS;
393 /* Read a byte of data if there is any - assume the error
394 * is associated with this character */
396 if ((rfoc = base_addr[CyRFOC]) != 0)
397 data = base_addr[CyRDR];
401 /* if there is nowhere to put the data, discard it */
403 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
406 else { /* there is an open port for this data */
408 if(err & info->ignore_status_mask){
409 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
412 if (tty_buffer_request_room(tty, 1) != 0){
413 if (err & info->read_status_mask){
415 tty_insert_flip_char(tty, data, TTY_BREAK);
416 if (info->flags & ASYNC_SAK){
419 }else if(err & CyFRAME){
420 tty_insert_flip_char(tty, data, TTY_FRAME);
421 }else if(err & CyPARITY){
422 tty_insert_flip_char(tty, data, TTY_PARITY);
423 }else if(err & CyOVERRUN){
424 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
426 If the flip buffer itself is
427 overflowing, we still loose
428 the next incoming character.
430 tty_insert_flip_char(tty, data, TTY_NORMAL);
432 /* These two conditions may imply */
433 /* a normal read should be done. */
434 /* else if(data & CyTIMEOUT) */
435 /* else if(data & CySPECHAR) */
437 tty_insert_flip_char(tty, 0, TTY_NORMAL);
440 tty_insert_flip_char(tty, data, TTY_NORMAL);
443 /* there was a software buffer overrun
444 and nothing could be done about it!!! */
447 schedule_delayed_work(&tty->flip.work, 1);
449 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
451 } /* cy_rxerr_interrupt */
454 cd2401_modem_interrupt(int irq, void *dev_id)
456 struct cyclades_port *info;
457 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
463 /* determine the channel and change to that context */
464 channel = (u_short ) (base_addr[CyLICR] >> 2);
465 info = &cy_port[channel];
466 info->last_active = jiffies;
468 mdm_change = base_addr[CyMISR];
469 mdm_status = base_addr[CyMSVR1];
471 if(info->tty == 0){ /* nowhere to put the data, ignore it */
474 if((mdm_change & CyDCD)
475 && (info->flags & ASYNC_CHECK_CD)){
476 if(mdm_status & CyDCD){
478 cy_sched_event(info, Cy_EVENT_OPEN_WAKEUP);
481 cy_sched_event(info, Cy_EVENT_HANGUP);
484 if((mdm_change & CyCTS)
485 && (info->flags & ASYNC_CTS_FLOW)){
486 if(info->tty->stopped){
487 if(mdm_status & CyCTS){
488 /* !!! cy_start isn't used because... */
489 info->tty->stopped = 0;
490 base_addr[CyIER] |= CyTxMpty;
491 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
494 if(!(mdm_status & CyCTS)){
495 /* !!! cy_stop isn't used because... */
496 info->tty->stopped = 1;
497 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
501 if(mdm_status & CyDSR){
504 base_addr[CyMEOIR] = 0;
506 } /* cy_modem_interrupt */
509 cd2401_tx_interrupt(int irq, void *dev_id)
511 struct cyclades_port *info;
512 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
514 int char_count, saved_cnt;
517 /* determine the channel and change to that context */
518 channel = (u_short ) (base_addr[CyLICR] >> 2);
520 #ifdef CONFIG_REMOTE_DEBUG
521 if (channel == DEBUG_PORT) {
522 panic ("TxInt on debug port!!!");
526 info = &cy_port[channel];
528 /* validate the port number (as configured and open) */
529 if( (channel < 0) || (NR_PORTS <= channel) ){
530 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
531 base_addr[CyTEOIR] = CyNOTRANS;
534 info->last_active = jiffies;
536 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
537 if (info->xmit_cnt < WAKEUP_CHARS) {
538 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
540 base_addr[CyTEOIR] = CyNOTRANS;
544 /* load the on-chip space available for outbound data */
545 saved_cnt = char_count = base_addr[CyTFTC];
547 if(info->x_char) { /* send special char */
548 outch = info->x_char;
549 base_addr[CyTDR] = outch;
555 /* The Cirrus chip requires the "Embedded Transmit
556 Commands" of start break, delay, and end break
557 sequences to be sent. The duration of the
558 break is given in TICs, which runs at HZ
559 (typically 100) and the PPR runs at 200 Hz,
560 so the delay is duration * 200/HZ, and thus a
561 break can run from 1/100 sec to about 5/4 sec.
562 Need to check these values - RGH 141095.
564 base_addr[CyTDR] = 0; /* start break */
565 base_addr[CyTDR] = 0x81;
566 base_addr[CyTDR] = 0; /* delay a bit */
567 base_addr[CyTDR] = 0x82;
568 base_addr[CyTDR] = info->x_break*200/HZ;
569 base_addr[CyTDR] = 0; /* terminate break */
570 base_addr[CyTDR] = 0x83;
575 while (char_count > 0){
576 if (!info->xmit_cnt){
577 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
580 if (info->xmit_buf == 0){
581 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
584 if (info->tty->stopped || info->tty->hw_stopped){
585 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
588 /* Because the Embedded Transmit Commands have been
589 enabled, we must check to see if the escape
590 character, NULL, is being sent. If it is, we
591 must ensure that there is room for it to be
592 doubled in the output stream. Therefore we
593 no longer advance the pointer when the character
594 is fetched, but rather wait until after the check
595 for a NULL output character. (This is necessary
596 because there may not be room for the two chars
597 needed to send a NULL.
599 outch = info->xmit_buf[info->xmit_tail];
602 info->xmit_tail = (info->xmit_tail + 1)
604 base_addr[CyTDR] = outch;
609 info->xmit_tail = (info->xmit_tail + 1)
611 base_addr[CyTDR] = outch;
612 base_addr[CyTDR] = 0;
621 if (info->xmit_cnt < WAKEUP_CHARS) {
622 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
624 base_addr[CyTEOIR] = (char_count != saved_cnt) ? 0 : CyNOTRANS;
626 } /* cy_tx_interrupt */
629 cd2401_rx_interrupt(int irq, void *dev_id)
631 struct tty_struct *tty;
632 struct cyclades_port *info;
633 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
639 /* determine the channel and change to that context */
640 channel = (u_short ) (base_addr[CyLICR] >> 2);
641 info = &cy_port[channel];
642 info->last_active = jiffies;
643 save_cnt = char_count = base_addr[CyRFOC];
645 #ifdef CONFIG_REMOTE_DEBUG
646 if (channel == DEBUG_PORT) {
647 while (char_count--) {
648 data = base_addr[CyRDR];
649 queueDebugChar(data);
654 /* if there is nowhere to put the data, discard it */
657 data = base_addr[CyRDR];
659 }else{ /* there is an open port for this data */
661 /* load # characters available from the chip */
663 #ifdef CYCLOM_ENABLE_MONITORING
664 ++info->mon.int_count;
665 info->mon.char_count += char_count;
666 if (char_count > info->mon.char_max)
667 info->mon.char_max = char_count;
668 info->mon.char_last = char_count;
671 data = base_addr[CyRDR];
672 tty_insert_flip_char(tty, data, TTY_NORMAL);
673 #ifdef CYCLOM_16Y_HACK
677 schedule_delayed_work(&tty->flip.work, 1);
680 base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS;
682 } /* cy_rx_interrupt */
685 * This routine is used to handle the "bottom half" processing for the
686 * serial driver, known also the "software interrupt" processing.
687 * This processing is done at the kernel interrupt level, after the
688 * cy#/_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
689 * is where time-consuming activities which can not be done in the
690 * interrupt driver proper are done; the interrupt driver schedules
691 * them using cy_sched_event(), and they get done here.
693 * This is done through one level of indirection--the task queue.
694 * When a hardware interrupt service routine wants service by the
695 * driver's bottom half, it enqueues the appropriate tq_struct (one
696 * per port) to the keventd work queue and sets a request flag
697 * that the work queue be processed.
699 * Although this may seem unwieldy, it gives the system a way to
700 * pass an argument (in this case the pointer to the cyclades_port
701 * structure) to the bottom half of the driver. Previous kernels
702 * had to poll every port to see if that port needed servicing.
705 do_softint(void *private_)
707 struct cyclades_port *info = (struct cyclades_port *) private_;
708 struct tty_struct *tty;
714 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
715 tty_hangup(info->tty);
716 wake_up_interruptible(&info->open_wait);
717 info->flags &= ~ASYNC_NORMAL_ACTIVE;
719 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) {
720 wake_up_interruptible(&info->open_wait);
722 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
728 /* This is called whenever a port becomes active;
729 interrupts are enabled and DTR & RTS are turned on.
732 startup(struct cyclades_port * info)
735 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
738 if (info->flags & ASYNC_INITIALIZED){
744 set_bit(TTY_IO_ERROR, &info->tty->flags);
748 if (!info->xmit_buf){
749 info->xmit_buf = (unsigned char *) get_zeroed_page (GFP_KERNEL);
750 if (!info->xmit_buf){
757 channel = info->line;
759 #ifdef SERIAL_DEBUG_OPEN
760 printk("startup channel %d\n", channel);
763 local_irq_save(flags);
764 base_addr[CyCAR] = (u_char)channel;
765 write_cy_cmd(base_addr,CyENB_RCVR|CyENB_XMTR);
767 base_addr[CyCAR] = (u_char)channel; /* !!! Is this needed? */
768 base_addr[CyMSVR1] = CyRTS;
769 /* CP('S');CP('1'); */
770 base_addr[CyMSVR2] = CyDTR;
772 #ifdef SERIAL_DEBUG_DTR
773 printk("cyc: %d: raising DTR\n", __LINE__);
774 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
777 base_addr[CyIER] |= CyRxData;
778 info->flags |= ASYNC_INITIALIZED;
781 clear_bit(TTY_IO_ERROR, &info->tty->flags);
783 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
785 local_irq_restore(flags);
787 #ifdef SERIAL_DEBUG_OPEN
794 start_xmit( struct cyclades_port *info )
797 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
800 channel = info->line;
801 local_irq_save(flags);
802 base_addr[CyCAR] = channel;
803 base_addr[CyIER] |= CyTxMpty;
804 local_irq_restore(flags);
808 * This routine shuts down a serial port; interrupts are disabled,
809 * and DTR is dropped if the hangup on close termio flag is on.
812 shutdown(struct cyclades_port * info)
815 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
818 if (!(info->flags & ASYNC_INITIALIZED)){
823 channel = info->line;
825 #ifdef SERIAL_DEBUG_OPEN
826 printk("shutdown channel %d\n", channel);
829 /* !!! REALLY MUST WAIT FOR LAST CHARACTER TO BE
830 SENT BEFORE DROPPING THE LINE !!! (Perhaps
831 set some flag that is read when XMTY happens.)
832 Other choices are to delay some fixed interval
833 or schedule some later processing.
835 local_irq_save(flags);
837 free_page((unsigned long) info->xmit_buf);
841 base_addr[CyCAR] = (u_char)channel;
842 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
843 base_addr[CyMSVR1] = 0;
844 /* CP('C');CP('1'); */
845 base_addr[CyMSVR2] = 0;
846 #ifdef SERIAL_DEBUG_DTR
847 printk("cyc: %d: dropping DTR\n", __LINE__);
848 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
851 write_cy_cmd(base_addr,CyDIS_RCVR);
852 /* it may be appropriate to clear _XMIT at
853 some later date (after testing)!!! */
856 set_bit(TTY_IO_ERROR, &info->tty->flags);
858 info->flags &= ~ASYNC_INITIALIZED;
859 local_irq_restore(flags);
861 #ifdef SERIAL_DEBUG_OPEN
868 * This routine finds or computes the various line characteristics.
871 config_setup(struct cyclades_port * info)
874 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
878 unsigned char ti, need_init_chan = 0;
880 if (!info->tty || !info->tty->termios){
883 if (info->line == -1){
886 cflag = info->tty->termios->c_cflag;
891 /* Starting with kernel 1.1.65, there is direct support for
892 higher baud rates. The following code supports those
893 changes. The conditional aspect allows this driver to be
894 used for earlier as well as later kernel versions. (The
895 mapping is slightly different from serial.c because there
896 is still the possibility of supporting 75 kbit/sec with
902 else if(i == B115200)
909 info->tty->termios->c_cflag &= ~CBAUDEX;
913 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
915 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
918 /* Don't ever change the speed of the console port. It will
919 * run at the speed specified in bootinfo, or at 19.2K */
920 /* Actually, it should run at whatever speed 166Bug was using */
921 /* Note info->timeout isn't used at present */
922 if (info != serial_console_info) {
923 info->tbpr = baud_bpr[i]; /* Tx BPR */
924 info->tco = baud_co[i]; /* Tx CO */
925 info->rbpr = baud_bpr[i]; /* Rx BPR */
926 info->rco = baud_co[i] >> 5; /* Rx CO */
927 if (baud_table[i] == 134) {
928 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
929 /* get it right for 134.5 baud */
930 } else if (baud_table[i]) {
931 info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2;
932 /* this needs to be propagated into the card info */
937 /* By tradition (is it a standard?) a baud rate of zero
938 implies the line should be/has been closed. A bit
939 later in this routine such a test is performed. */
941 /* byte size and parity */
945 info->cor4 = (info->default_threshold
946 ? info->default_threshold
947 : baud_cor4[i]); /* receive threshold */
948 /* Following two lines added 101295, RGH. */
949 /* It is obviously wrong to access CyCORx, and not info->corx here,
950 * try and remember to fix it later! */
951 channel = info->line;
952 base_addr[CyCAR] = (u_char)channel;
953 if (C_CLOCAL(info->tty)) {
954 if (base_addr[CyIER] & CyMdmCh)
955 base_addr[CyIER] &= ~CyMdmCh; /* without modem intr */
956 /* ignore 1->0 modem transitions */
957 if (base_addr[CyCOR4] & (CyDSR|CyCTS|CyDCD))
958 base_addr[CyCOR4] &= ~(CyDSR|CyCTS|CyDCD);
959 /* ignore 0->1 modem transitions */
960 if (base_addr[CyCOR5] & (CyDSR|CyCTS|CyDCD))
961 base_addr[CyCOR5] &= ~(CyDSR|CyCTS|CyDCD);
963 if ((base_addr[CyIER] & CyMdmCh) != CyMdmCh)
964 base_addr[CyIER] |= CyMdmCh; /* with modem intr */
965 /* act on 1->0 modem transitions */
966 if ((base_addr[CyCOR4] & (CyDSR|CyCTS|CyDCD)) != (CyDSR|CyCTS|CyDCD))
967 base_addr[CyCOR4] |= CyDSR|CyCTS|CyDCD;
968 /* act on 0->1 modem transitions */
969 if ((base_addr[CyCOR5] & (CyDSR|CyCTS|CyDCD)) != (CyDSR|CyCTS|CyDCD))
970 base_addr[CyCOR5] |= CyDSR|CyCTS|CyDCD;
972 info->cor3 = (cflag & CSTOPB) ? Cy_2_STOP : Cy_1_STOP;
974 switch(cflag & CSIZE){
976 info->cor1 = Cy_5_BITS;
979 info->cor1 = Cy_6_BITS;
982 info->cor1 = Cy_7_BITS;
985 info->cor1 = Cy_8_BITS;
990 info->cor1 |= CyPARITY_O;
992 info->cor1 |= CyPARITY_E;
995 info->cor1 |= CyPARITY_NONE;
998 /* CTS flow control flag */
1000 /* Don't complcate matters for now! RGH 141095 */
1001 if (cflag & CRTSCTS){
1002 info->flags |= ASYNC_CTS_FLOW;
1003 info->cor2 |= CyCtsAE;
1005 info->flags &= ~ASYNC_CTS_FLOW;
1006 info->cor2 &= ~CyCtsAE;
1010 info->flags &= ~ASYNC_CHECK_CD;
1012 info->flags |= ASYNC_CHECK_CD;
1014 /***********************************************
1015 The hardware option, CyRtsAO, presents RTS when
1016 the chip has characters to send. Since most modems
1017 use RTS as reverse (inbound) flow control, this
1018 option is not used. If inbound flow control is
1019 necessary, DTR can be programmed to provide the
1020 appropriate signals for use with a non-standard
1021 cable. Contact Marcio Saito for details.
1022 ***********************************************/
1024 channel = info->line;
1026 local_irq_save(flags);
1027 base_addr[CyCAR] = (u_char)channel;
1029 /* CyCMR set once only in mvme167_init_serial() */
1030 if (base_addr[CyLICR] != channel << 2)
1031 base_addr[CyLICR] = channel << 2;
1032 if (base_addr[CyLIVR] != 0x5c)
1033 base_addr[CyLIVR] = 0x5c;
1035 /* tx and rx baud rate */
1037 if (base_addr[CyCOR1] != info->cor1)
1039 if (base_addr[CyTCOR] != info->tco)
1040 base_addr[CyTCOR] = info->tco;
1041 if (base_addr[CyTBPR] != info->tbpr)
1042 base_addr[CyTBPR] = info->tbpr;
1043 if (base_addr[CyRCOR] != info->rco)
1044 base_addr[CyRCOR] = info->rco;
1045 if (base_addr[CyRBPR] != info->rbpr)
1046 base_addr[CyRBPR] = info->rbpr;
1048 /* set line characteristics according configuration */
1050 if (base_addr[CySCHR1] != START_CHAR(info->tty))
1051 base_addr[CySCHR1] = START_CHAR(info->tty);
1052 if (base_addr[CySCHR2] != STOP_CHAR(info->tty))
1053 base_addr[CySCHR2] = STOP_CHAR(info->tty);
1054 if (base_addr[CySCRL] != START_CHAR(info->tty))
1055 base_addr[CySCRL] = START_CHAR(info->tty);
1056 if (base_addr[CySCRH] != START_CHAR(info->tty))
1057 base_addr[CySCRH] = START_CHAR(info->tty);
1058 if (base_addr[CyCOR1] != info->cor1)
1059 base_addr[CyCOR1] = info->cor1;
1060 if (base_addr[CyCOR2] != info->cor2)
1061 base_addr[CyCOR2] = info->cor2;
1062 if (base_addr[CyCOR3] != info->cor3)
1063 base_addr[CyCOR3] = info->cor3;
1064 if (base_addr[CyCOR4] != info->cor4)
1065 base_addr[CyCOR4] = info->cor4;
1066 if (base_addr[CyCOR5] != info->cor5)
1067 base_addr[CyCOR5] = info->cor5;
1068 if (base_addr[CyCOR6] != info->cor6)
1069 base_addr[CyCOR6] = info->cor6;
1070 if (base_addr[CyCOR7] != info->cor7)
1071 base_addr[CyCOR7] = info->cor7;
1074 write_cy_cmd(base_addr,CyINIT_CHAN);
1076 base_addr[CyCAR] = (u_char)channel; /* !!! Is this needed? */
1078 /* 2ms default rx timeout */
1079 ti = info->default_timeout ? info->default_timeout : 0x02;
1080 if (base_addr[CyRTPRL] != ti)
1081 base_addr[CyRTPRL] = ti;
1082 if (base_addr[CyRTPRH] != 0)
1083 base_addr[CyRTPRH] = 0;
1085 /* Set up RTS here also ????? RGH 141095 */
1086 if(i == 0){ /* baud rate is zero, turn off line */
1087 if ((base_addr[CyMSVR2] & CyDTR) == CyDTR)
1088 base_addr[CyMSVR2] = 0;
1089 #ifdef SERIAL_DEBUG_DTR
1090 printk("cyc: %d: dropping DTR\n", __LINE__);
1091 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1094 if ((base_addr[CyMSVR2] & CyDTR) != CyDTR)
1095 base_addr[CyMSVR2] = CyDTR;
1096 #ifdef SERIAL_DEBUG_DTR
1097 printk("cyc: %d: raising DTR\n", __LINE__);
1098 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1103 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1106 local_irq_restore(flags);
1108 } /* config_setup */
1112 cy_put_char(struct tty_struct *tty, unsigned char ch)
1114 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1115 unsigned long flags;
1117 #ifdef SERIAL_DEBUG_IO
1118 printk("cy_put_char %s(0x%02x)\n", tty->name, ch);
1121 if (serial_paranoia_check(info, tty->name, "cy_put_char"))
1124 if (!info->xmit_buf)
1127 local_irq_save(flags);
1128 if (info->xmit_cnt >= PAGE_SIZE - 1) {
1129 local_irq_restore(flags);
1133 info->xmit_buf[info->xmit_head++] = ch;
1134 info->xmit_head &= PAGE_SIZE - 1;
1136 local_irq_restore(flags);
1141 cy_flush_chars(struct tty_struct *tty)
1143 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1144 unsigned long flags;
1145 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1148 #ifdef SERIAL_DEBUG_IO
1149 printk("cy_flush_chars %s\n", tty->name); /* */
1152 if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
1155 if (info->xmit_cnt <= 0 || tty->stopped
1156 || tty->hw_stopped || !info->xmit_buf)
1159 channel = info->line;
1161 local_irq_save(flags);
1162 base_addr[CyCAR] = channel;
1163 base_addr[CyIER] |= CyTxMpty;
1164 local_irq_restore(flags);
1165 } /* cy_flush_chars */
1168 /* This routine gets called when tty_write has put something into
1169 the write_queue. If the port is not already transmitting stuff,
1170 start it off by enabling interrupts. The interrupt service
1171 routine will then ensure that the characters are sent. If the
1172 port is already active, there is no need to kick it.
1175 cy_write(struct tty_struct * tty,
1176 const unsigned char *buf, int count)
1178 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1179 unsigned long flags;
1182 #ifdef SERIAL_DEBUG_IO
1183 printk("cy_write %s\n", tty->name); /* */
1186 if (serial_paranoia_check(info, tty->name, "cy_write")){
1190 if (!info->xmit_buf){
1195 local_irq_save(flags);
1196 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1197 SERIAL_XMIT_SIZE - info->xmit_head));
1199 local_irq_restore(flags);
1203 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1204 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1205 info->xmit_cnt += c;
1206 local_irq_restore(flags);
1215 && !tty->hw_stopped ) {
1223 cy_write_room(struct tty_struct *tty)
1225 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1228 #ifdef SERIAL_DEBUG_IO
1229 printk("cy_write_room %s\n", tty->name); /* */
1232 if (serial_paranoia_check(info, tty->name, "cy_write_room"))
1234 ret = PAGE_SIZE - info->xmit_cnt - 1;
1238 } /* cy_write_room */
1242 cy_chars_in_buffer(struct tty_struct *tty)
1244 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1246 #ifdef SERIAL_DEBUG_IO
1247 printk("cy_chars_in_buffer %s %d\n", tty->name, info->xmit_cnt); /* */
1250 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
1253 return info->xmit_cnt;
1254 } /* cy_chars_in_buffer */
1258 cy_flush_buffer(struct tty_struct *tty)
1260 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1261 unsigned long flags;
1263 #ifdef SERIAL_DEBUG_IO
1264 printk("cy_flush_buffer %s\n", tty->name); /* */
1267 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
1269 local_irq_save(flags);
1270 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1271 local_irq_restore(flags);
1273 } /* cy_flush_buffer */
1276 /* This routine is called by the upper-layer tty layer to signal
1277 that incoming characters should be throttled or that the
1278 throttle should be released.
1281 cy_throttle(struct tty_struct * tty)
1283 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1284 unsigned long flags;
1285 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1288 #ifdef SERIAL_DEBUG_THROTTLE
1291 printk("throttle %s: %d....\n", tty_name(tty, buf),
1292 tty->ldisc.chars_in_buffer(tty));
1293 printk("cy_throttle %s\n", tty->name);
1296 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")){
1301 info->x_char = STOP_CHAR(tty);
1302 /* Should use the "Send Special Character" feature!!! */
1305 channel = info->line;
1307 local_irq_save(flags);
1308 base_addr[CyCAR] = (u_char)channel;
1309 base_addr[CyMSVR1] = 0;
1310 local_irq_restore(flags);
1317 cy_unthrottle(struct tty_struct * tty)
1319 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1320 unsigned long flags;
1321 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1324 #ifdef SERIAL_DEBUG_THROTTLE
1327 printk("throttle %s: %d....\n", tty_name(tty, buf),
1328 tty->ldisc.chars_in_buffer(tty));
1329 printk("cy_unthrottle %s\n", tty->name);
1332 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")){
1337 info->x_char = START_CHAR(tty);
1338 /* Should use the "Send Special Character" feature!!! */
1341 channel = info->line;
1343 local_irq_save(flags);
1344 base_addr[CyCAR] = (u_char)channel;
1345 base_addr[CyMSVR1] = CyRTS;
1346 local_irq_restore(flags);
1349 } /* cy_unthrottle */
1352 get_serial_info(struct cyclades_port * info,
1353 struct serial_struct * retinfo)
1355 struct serial_struct tmp;
1360 memset(&tmp, 0, sizeof(tmp));
1361 tmp.type = info->type;
1362 tmp.line = info->line;
1363 tmp.port = info->line;
1365 tmp.flags = info->flags;
1366 tmp.baud_base = 0; /*!!!*/
1367 tmp.close_delay = info->close_delay;
1368 tmp.custom_divisor = 0; /*!!!*/
1369 tmp.hub6 = 0; /*!!!*/
1370 return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0;
1371 } /* get_serial_info */
1374 set_serial_info(struct cyclades_port * info,
1375 struct serial_struct * new_info)
1377 struct serial_struct new_serial;
1378 struct cyclades_port old_info;
1383 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
1387 if (!capable(CAP_SYS_ADMIN)) {
1388 if ((new_serial.close_delay != info->close_delay) ||
1389 ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) !=
1390 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK)))
1392 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1393 (new_serial.flags & ASYNC_USR_MASK));
1394 goto check_and_exit;
1399 * OK, past this point, all the error checking has been done.
1400 * At this point, we start making changes.....
1403 info->flags = ((info->flags & ~ASYNC_FLAGS) |
1404 (new_serial.flags & ASYNC_FLAGS));
1405 info->close_delay = new_serial.close_delay;
1409 if (info->flags & ASYNC_INITIALIZED){
1413 return startup(info);
1415 } /* set_serial_info */
1418 cy_tiocmget(struct tty_struct *tty, struct file *file)
1420 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1422 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1423 unsigned long flags;
1424 unsigned char status;
1426 channel = info->line;
1428 local_irq_save(flags);
1429 base_addr[CyCAR] = (u_char)channel;
1430 status = base_addr[CyMSVR1] | base_addr[CyMSVR2];
1431 local_irq_restore(flags);
1433 return ((status & CyRTS) ? TIOCM_RTS : 0)
1434 | ((status & CyDTR) ? TIOCM_DTR : 0)
1435 | ((status & CyDCD) ? TIOCM_CAR : 0)
1436 | ((status & CyDSR) ? TIOCM_DSR : 0)
1437 | ((status & CyCTS) ? TIOCM_CTS : 0);
1441 cy_tiocmset(struct tty_struct *tty, struct file *file,
1442 unsigned int set, unsigned int clear)
1444 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1446 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1447 unsigned long flags;
1449 channel = info->line;
1451 if (set & TIOCM_RTS){
1452 local_irq_save(flags);
1453 base_addr[CyCAR] = (u_char)channel;
1454 base_addr[CyMSVR1] = CyRTS;
1455 local_irq_restore(flags);
1457 if (set & TIOCM_DTR){
1458 local_irq_save(flags);
1459 base_addr[CyCAR] = (u_char)channel;
1460 /* CP('S');CP('2'); */
1461 base_addr[CyMSVR2] = CyDTR;
1462 #ifdef SERIAL_DEBUG_DTR
1463 printk("cyc: %d: raising DTR\n", __LINE__);
1464 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1466 local_irq_restore(flags);
1469 if (clear & TIOCM_RTS){
1470 local_irq_save(flags);
1471 base_addr[CyCAR] = (u_char)channel;
1472 base_addr[CyMSVR1] = 0;
1473 local_irq_restore(flags);
1475 if (clear & TIOCM_DTR){
1476 local_irq_save(flags);
1477 base_addr[CyCAR] = (u_char)channel;
1478 /* CP('C');CP('2'); */
1479 base_addr[CyMSVR2] = 0;
1480 #ifdef SERIAL_DEBUG_DTR
1481 printk("cyc: %d: dropping DTR\n", __LINE__);
1482 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1484 local_irq_restore(flags);
1488 } /* set_modem_info */
1491 send_break( struct cyclades_port * info, int duration)
1492 { /* Let the transmit ISR take care of this (since it
1493 requires stuffing characters into the output stream).
1495 info->x_break = duration;
1496 if (!info->xmit_cnt ) {
1502 get_mon_info(struct cyclades_port * info, struct cyclades_monitor * mon)
1505 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
1507 info->mon.int_count = 0;
1508 info->mon.char_count = 0;
1509 info->mon.char_max = 0;
1510 info->mon.char_last = 0;
1515 set_threshold(struct cyclades_port * info, unsigned long *arg)
1517 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1518 unsigned long value;
1521 if (get_user(value, arg))
1524 channel = info->line;
1525 info->cor4 &= ~CyREC_FIFO;
1526 info->cor4 |= value & CyREC_FIFO;
1527 base_addr[CyCOR4] = info->cor4;
1532 get_threshold(struct cyclades_port * info, unsigned long *value)
1534 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1538 channel = info->line;
1540 tmp = base_addr[CyCOR4] & CyREC_FIFO;
1541 return put_user(tmp,value);
1545 set_default_threshold(struct cyclades_port * info, unsigned long *arg)
1547 unsigned long value;
1549 if (get_user(value, arg))
1552 info->default_threshold = value & 0x0f;
1557 get_default_threshold(struct cyclades_port * info, unsigned long *value)
1559 return put_user(info->default_threshold,value);
1563 set_timeout(struct cyclades_port * info, unsigned long *arg)
1565 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1567 unsigned long value;
1569 if (get_user(value, arg))
1572 channel = info->line;
1574 base_addr[CyRTPRL] = value & 0xff;
1575 base_addr[CyRTPRH] = (value >> 8) & 0xff;
1580 get_timeout(struct cyclades_port * info, unsigned long *value)
1582 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1586 channel = info->line;
1588 tmp = base_addr[CyRTPRL];
1589 return put_user(tmp,value);
1593 set_default_timeout(struct cyclades_port * info, unsigned long value)
1595 info->default_timeout = value & 0xff;
1600 get_default_timeout(struct cyclades_port * info, unsigned long *value)
1602 return put_user(info->default_timeout,value);
1606 cy_ioctl(struct tty_struct *tty, struct file * file,
1607 unsigned int cmd, unsigned long arg)
1610 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1613 #ifdef SERIAL_DEBUG_OTHER
1614 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */
1619 ret_val = get_mon_info(info, (struct cyclades_monitor *)arg);
1622 ret_val = get_threshold(info, (unsigned long *)arg);
1625 ret_val = set_threshold(info, (unsigned long *)arg);
1627 case CYGETDEFTHRESH:
1628 ret_val = get_default_threshold(info, (unsigned long *)arg);
1630 case CYSETDEFTHRESH:
1631 ret_val = set_default_threshold(info, (unsigned long *)arg);
1634 ret_val = get_timeout(info, (unsigned long *)arg);
1637 ret_val = set_timeout(info, (unsigned long *)arg);
1639 case CYGETDEFTIMEOUT:
1640 ret_val = get_default_timeout(info, (unsigned long *)arg);
1642 case CYSETDEFTIMEOUT:
1643 ret_val = set_default_timeout(info, (unsigned long)arg);
1645 case TCSBRK: /* SVID version: non-zero arg --> no break */
1646 ret_val = tty_check_change(tty);
1649 tty_wait_until_sent(tty,0);
1651 send_break(info, HZ/4); /* 1/4 second */
1653 case TCSBRKP: /* support for POSIX tcsendbreak() */
1654 ret_val = tty_check_change(tty);
1657 tty_wait_until_sent(tty,0);
1658 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1661 /* The following commands are incompletely implemented!!! */
1663 ret_val = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *) arg);
1666 ret_val = get_user(val, (unsigned long *) arg);
1669 tty->termios->c_cflag =
1670 ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0));
1673 ret_val = get_serial_info(info, (struct serial_struct *) arg);
1676 ret_val = set_serial_info(info,
1677 (struct serial_struct *) arg);
1680 ret_val = -ENOIOCTLCMD;
1683 #ifdef SERIAL_DEBUG_OTHER
1684 printk("cy_ioctl done\n");
1694 cy_set_termios(struct tty_struct *tty, struct termios * old_termios)
1696 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1698 #ifdef SERIAL_DEBUG_OTHER
1699 printk("cy_set_termios %s\n", tty->name);
1702 if (tty->termios->c_cflag == old_termios->c_cflag)
1706 if ((old_termios->c_cflag & CRTSCTS) &&
1707 !(tty->termios->c_cflag & CRTSCTS)) {
1711 #ifdef tytso_patch_94Nov25_1726
1712 if (!(old_termios->c_cflag & CLOCAL) &&
1713 (tty->termios->c_cflag & CLOCAL))
1714 wake_up_interruptible(&info->open_wait);
1718 } /* cy_set_termios */
1722 cy_close(struct tty_struct * tty, struct file * filp)
1724 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1727 #ifdef SERIAL_DEBUG_OTHER
1728 printk("cy_close %s\n", tty->name);
1732 || serial_paranoia_check(info, tty->name, "cy_close")){
1735 #ifdef SERIAL_DEBUG_OPEN
1736 printk("cy_close %s, count = %d\n", tty->name, info->count);
1739 if ((tty->count == 1) && (info->count != 1)) {
1741 * Uh, oh. tty->count is 1, which means that the tty
1742 * structure will be freed. Info->count should always
1743 * be one in these conditions. If it's greater than
1744 * one, we've got real problems, since it means the
1745 * serial port won't be shutdown.
1747 printk("cy_close: bad serial port count; tty->count is 1, "
1748 "info->count is %d\n", info->count);
1751 #ifdef SERIAL_DEBUG_COUNT
1752 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count - 1);
1754 if (--info->count < 0) {
1755 printk("cy_close: bad serial port count for ttys%d: %d\n",
1756 info->line, info->count);
1757 #ifdef SERIAL_DEBUG_COUNT
1758 printk("cyc: %d: setting count to 0\n", __LINE__);
1764 info->flags |= ASYNC_CLOSING;
1765 if (info->flags & ASYNC_INITIALIZED)
1766 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
1768 if (tty->driver->flush_buffer)
1769 tty->driver->flush_buffer(tty);
1770 tty_ldisc_flush(tty);
1773 if (info->blocked_open) {
1774 if (info->close_delay) {
1775 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1777 wake_up_interruptible(&info->open_wait);
1779 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1780 wake_up_interruptible(&info->close_wait);
1782 #ifdef SERIAL_DEBUG_OTHER
1783 printk("cy_close done\n");
1790 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
1793 cy_hangup(struct tty_struct *tty)
1795 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1797 #ifdef SERIAL_DEBUG_OTHER
1798 printk("cy_hangup %s\n", tty->name); /* */
1801 if (serial_paranoia_check(info, tty->name, "cy_hangup"))
1808 #ifdef SERIAL_DEBUG_COUNT
1809 printk("cyc: %d: setting count to 0\n", __LINE__);
1813 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1814 wake_up_interruptible(&info->open_wait);
1820 * ------------------------------------------------------------
1821 * cy_open() and friends
1822 * ------------------------------------------------------------
1826 block_til_ready(struct tty_struct *tty, struct file * filp,
1827 struct cyclades_port *info)
1829 DECLARE_WAITQUEUE(wait, current);
1830 unsigned long flags;
1833 volatile u_char *base_addr = (u_char *)BASE_ADDR;
1836 * If the device is in the middle of being closed, then block
1837 * until it's done, and then try again.
1839 if (info->flags & ASYNC_CLOSING) {
1840 interruptible_sleep_on(&info->close_wait);
1841 if (info->flags & ASYNC_HUP_NOTIFY){
1844 return -ERESTARTSYS;
1849 * If non-blocking mode is set, then make the check up front
1852 if (filp->f_flags & O_NONBLOCK) {
1853 info->flags |= ASYNC_NORMAL_ACTIVE;
1858 * Block waiting for the carrier detect and the line to become
1859 * free (i.e., not in use by the callout). While we are in
1860 * this loop, info->count is dropped by one, so that
1861 * cy_close() knows when to free things. We restore it upon
1862 * exit, either normal or abnormal.
1865 add_wait_queue(&info->open_wait, &wait);
1866 #ifdef SERIAL_DEBUG_OPEN
1867 printk("block_til_ready before block: %s, count = %d\n",
1868 tty->name, info->count);/**/
1871 #ifdef SERIAL_DEBUG_COUNT
1872 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count);
1874 info->blocked_open++;
1876 channel = info->line;
1879 local_irq_save(flags);
1880 base_addr[CyCAR] = (u_char)channel;
1881 base_addr[CyMSVR1] = CyRTS;
1882 /* CP('S');CP('4'); */
1883 base_addr[CyMSVR2] = CyDTR;
1884 #ifdef SERIAL_DEBUG_DTR
1885 printk("cyc: %d: raising DTR\n", __LINE__);
1886 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1888 local_irq_restore(flags);
1889 set_current_state(TASK_INTERRUPTIBLE);
1890 if (tty_hung_up_p(filp)
1891 || !(info->flags & ASYNC_INITIALIZED) ){
1892 if (info->flags & ASYNC_HUP_NOTIFY) {
1895 retval = -ERESTARTSYS;
1899 local_irq_save(flags);
1900 base_addr[CyCAR] = (u_char)channel;
1901 /* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */
1902 if (!(info->flags & ASYNC_CLOSING)
1904 || (base_addr[CyMSVR1] & CyDCD))) {
1905 local_irq_restore(flags);
1908 local_irq_restore(flags);
1909 if (signal_pending(current)) {
1910 retval = -ERESTARTSYS;
1913 #ifdef SERIAL_DEBUG_OPEN
1914 printk("block_til_ready blocking: %s, count = %d\n",
1915 tty->name, info->count);/**/
1919 current->state = TASK_RUNNING;
1920 remove_wait_queue(&info->open_wait, &wait);
1921 if (!tty_hung_up_p(filp)){
1923 #ifdef SERIAL_DEBUG_COUNT
1924 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
1927 info->blocked_open--;
1928 #ifdef SERIAL_DEBUG_OPEN
1929 printk("block_til_ready after blocking: %s, count = %d\n",
1930 tty->name, info->count);/**/
1934 info->flags |= ASYNC_NORMAL_ACTIVE;
1936 } /* block_til_ready */
1939 * This routine is called whenever a serial port is opened. It
1940 * performs the serial-specific initialization for the tty structure.
1943 cy_open(struct tty_struct *tty, struct file * filp)
1945 struct cyclades_port *info;
1950 if ((line < 0) || (NR_PORTS <= line)){
1953 info = &cy_port[line];
1954 if (info->line < 0){
1957 #ifdef SERIAL_DEBUG_OTHER
1958 printk("cy_open %s\n", tty->name); /* */
1960 if (serial_paranoia_check(info, tty->name, "cy_open")){
1963 #ifdef SERIAL_DEBUG_OPEN
1964 printk("cy_open %s, count = %d\n", tty->name, info->count);/**/
1967 #ifdef SERIAL_DEBUG_COUNT
1968 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
1970 tty->driver_data = info;
1974 * Start up serial port
1976 retval = startup(info);
1981 retval = block_til_ready(tty, filp, info);
1983 #ifdef SERIAL_DEBUG_OPEN
1984 printk("cy_open returning after block_til_ready with %d\n",
1990 #ifdef SERIAL_DEBUG_OPEN
1991 printk("cy_open done\n");/**/
1999 * ---------------------------------------------------------------------
2000 * serial167_init() and friends
2002 * serial167_init() is called at boot-time to initialize the serial driver.
2003 * ---------------------------------------------------------------------
2007 * This routine prints out the appropriate serial driver version
2008 * number, and identifies which options were configured into this
2014 printk("MVME166/167 cd2401 driver\n");
2015 } /* show_version */
2017 /* initialize chips on card -- return number of valid
2018 chips (which is number of ports/4) */
2021 * This initialises the hardware to a reasonable state. It should
2022 * probe the chip first so as to copy 166-Bug setup as a default for
2023 * port 0. It initialises CMR to CyASYNC; that is never done again, so
2024 * as to limit the number of CyINIT_CHAN commands in normal running.
2026 * ... I wonder what I should do if this fails ...
2030 mvme167_serial_console_setup(int cflag)
2032 volatile unsigned char* base_addr = (u_char *)BASE_ADDR;
2035 u_char rcor, rbpr, badspeed = 0;
2036 unsigned long flags;
2038 local_irq_save(flags);
2041 * First probe channel zero of the chip, to see what speed has
2045 base_addr[CyCAR] = 0;
2047 rcor = base_addr[CyRCOR] << 5;
2048 rbpr = base_addr[CyRBPR];
2050 for (spd = 0; spd < sizeof(baud_bpr); spd++)
2051 if (rbpr == baud_bpr[spd] && rcor == baud_co[spd])
2053 if (spd >= sizeof(baud_bpr)) {
2054 spd = 14; /* 19200 */
2055 badspeed = 1; /* Failed to identify speed */
2057 initial_console_speed = spd;
2059 /* OK, we have chosen a speed, now reset and reinitialise */
2061 my_udelay(20000L); /* Allow time for any active o/p to complete */
2062 if(base_addr[CyCCR] != 0x00){
2063 local_irq_restore(flags);
2064 /* printk(" chip is never idle (CCR != 0)\n"); */
2068 base_addr[CyCCR] = CyCHIP_RESET; /* Reset the chip */
2071 if(base_addr[CyGFRCR] == 0x00){
2072 local_irq_restore(flags);
2073 /* printk(" chip is not responding (GFRCR stayed 0)\n"); */
2078 * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms
2082 base_addr[CyTPR] = 10;
2084 base_addr[CyPILR1] = 0x01; /* Interrupt level for modem change */
2085 base_addr[CyPILR2] = 0x02; /* Interrupt level for tx ints */
2086 base_addr[CyPILR3] = 0x03; /* Interrupt level for rx ints */
2089 * Attempt to set up all channels to something reasonable, and
2090 * bang out a INIT_CHAN command. We should then be able to limit
2091 * the ammount of fiddling we have to do in normal running.
2094 for (ch = 3; ch >= 0 ; ch--) {
2095 base_addr[CyCAR] = (u_char)ch;
2096 base_addr[CyIER] = 0;
2097 base_addr[CyCMR] = CyASYNC;
2098 base_addr[CyLICR] = (u_char)ch << 2;
2099 base_addr[CyLIVR] = 0x5c;
2100 base_addr[CyTCOR] = baud_co[spd];
2101 base_addr[CyTBPR] = baud_bpr[spd];
2102 base_addr[CyRCOR] = baud_co[spd] >> 5;
2103 base_addr[CyRBPR] = baud_bpr[spd];
2104 base_addr[CySCHR1] = 'Q' & 0x1f;
2105 base_addr[CySCHR2] = 'X' & 0x1f;
2106 base_addr[CySCRL] = 0;
2107 base_addr[CySCRH] = 0;
2108 base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
2109 base_addr[CyCOR2] = 0;
2110 base_addr[CyCOR3] = Cy_1_STOP;
2111 base_addr[CyCOR4] = baud_cor4[spd];
2112 base_addr[CyCOR5] = 0;
2113 base_addr[CyCOR6] = 0;
2114 base_addr[CyCOR7] = 0;
2115 base_addr[CyRTPRL] = 2;
2116 base_addr[CyRTPRH] = 0;
2117 base_addr[CyMSVR1] = 0;
2118 base_addr[CyMSVR2] = 0;
2119 write_cy_cmd(base_addr,CyINIT_CHAN|CyDIS_RCVR|CyDIS_XMTR);
2123 * Now do specials for channel zero....
2126 base_addr[CyMSVR1] = CyRTS;
2127 base_addr[CyMSVR2] = CyDTR;
2128 base_addr[CyIER] = CyRxData;
2129 write_cy_cmd(base_addr,CyENB_RCVR|CyENB_XMTR);
2131 local_irq_restore(flags);
2133 my_udelay(20000L); /* Let it all settle down */
2135 printk("CD2401 initialised, chip is rev 0x%02x\n", base_addr[CyGFRCR]);
2137 printk(" WARNING: Failed to identify line speed, rcor=%02x,rbpr=%02x\n",
2139 } /* serial_console_init */
2141 static const struct tty_operations cy_ops = {
2145 .put_char = cy_put_char,
2146 .flush_chars = cy_flush_chars,
2147 .write_room = cy_write_room,
2148 .chars_in_buffer = cy_chars_in_buffer,
2149 .flush_buffer = cy_flush_buffer,
2151 .throttle = cy_throttle,
2152 .unthrottle = cy_unthrottle,
2153 .set_termios = cy_set_termios,
2156 .hangup = cy_hangup,
2157 .tiocmget = cy_tiocmget,
2158 .tiocmset = cy_tiocmset,
2160 /* The serial driver boot-time initialization code!
2161 Hardware I/O ports are mapped to character special devices on a
2162 first found, first allocated manner. That is, this code searches
2163 for Cyclom cards in the system. As each is found, it is probed
2164 to discover how many chips (and thus how many ports) are present.
2165 These ports are mapped to the tty ports 64 and upward in monotonic
2166 fashion. If an 8-port card is replaced with a 16-port card, the
2167 port mapping on a following card will shift.
2169 This approach is different from what is used in the other serial
2170 device driver because the Cyclom is more properly a multiplexer,
2171 not just an aggregation of serial ports on one card.
2173 If there are more cards with more ports than have been statically
2174 allocated above, a warning is printed and the extra ports are ignored.
2177 serial167_init(void)
2179 struct cyclades_port *info;
2186 struct sigaction sa;
2189 if (!(mvme16x_config &MVME16x_CONFIG_GOT_CD2401))
2192 cy_serial_driver = alloc_tty_driver(NR_PORTS);
2193 if (!cy_serial_driver)
2202 /* Has "console=0,9600n8" been used in bootinfo to change speed? */
2203 if (serial_console_cflag)
2204 DefSpeed = serial_console_cflag & 0017;
2206 DefSpeed = initial_console_speed;
2207 serial_console_info = &cy_port[0];
2208 serial_console_cflag = DefSpeed | CS8;
2210 serial_console = 64; /*callout_driver.minor_start*/
2214 /* Initialize the tty_driver structure */
2216 cy_serial_driver->owner = THIS_MODULE;
2217 cy_serial_driver->name = "ttyS";
2218 cy_serial_driver->major = TTY_MAJOR;
2219 cy_serial_driver->minor_start = 64;
2220 cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
2221 cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
2222 cy_serial_driver->init_termios = tty_std_termios;
2223 cy_serial_driver->init_termios.c_cflag =
2224 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2225 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
2226 tty_set_operations(cy_serial_driver, &cy_ops);
2228 ret = tty_register_driver(cy_serial_driver);
2230 printk(KERN_ERR "Couldn't register MVME166/7 serial driver\n");
2231 put_tty_driver(cy_serial_driver);
2237 for (index = 0; index < 1; index++) {
2241 if(port_num < NR_PORTS){
2242 while( good_ports-- && port_num < NR_PORTS){
2243 /*** initialize port ***/
2244 info->magic = CYCLADES_MAGIC;
2245 info->type = PORT_CIRRUS;
2247 info->line = port_num;
2248 info->flags = STD_COM_FLAGS;
2250 info->xmit_fifo_size = 12;
2251 info->cor1 = CyPARITY_NONE|Cy_8_BITS;
2253 info->cor3 = Cy_1_STOP;
2254 info->cor4 = 0x08; /* _very_ small receive threshold */
2258 info->tbpr = baud_bpr[DefSpeed]; /* Tx BPR */
2259 info->tco = baud_co[DefSpeed]; /* Tx CO */
2260 info->rbpr = baud_bpr[DefSpeed]; /* Rx BPR */
2261 info->rco = baud_co[DefSpeed] >> 5; /* Rx CO */
2262 info->close_delay = 0;
2266 #ifdef SERIAL_DEBUG_COUNT
2267 printk("cyc: %d: setting count to 0\n", __LINE__);
2269 info->blocked_open = 0;
2270 info->default_threshold = 0;
2271 info->default_timeout = 0;
2272 INIT_WORK(&info->tqueue, do_softint, info);
2273 init_waitqueue_head(&info->open_wait);
2274 init_waitqueue_head(&info->close_wait);
2277 /*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/
2278 info->read_status_mask = CyTIMEOUT| CySPECHAR| CyBREAK
2279 | CyPARITY| CyFRAME| CyOVERRUN;
2282 printk("ttyS%d ", info->line);
2284 if(!(port_num & 7)){
2291 while( port_num < NR_PORTS){
2295 #ifdef CONFIG_REMOTE_DEBUG
2298 ret = request_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt, 0,
2299 "cd2401_errors", cd2401_rxerr_interrupt);
2301 printk(KERN_ERR "Could't get cd2401_errors IRQ");
2302 goto cleanup_serial_driver;
2305 ret = request_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt, 0,
2306 "cd2401_modem", cd2401_modem_interrupt);
2308 printk(KERN_ERR "Could't get cd2401_modem IRQ");
2309 goto cleanup_irq_cd2401_errors;
2312 ret = request_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt, 0,
2313 "cd2401_txints", cd2401_tx_interrupt);
2315 printk(KERN_ERR "Could't get cd2401_txints IRQ");
2316 goto cleanup_irq_cd2401_modem;
2319 ret = request_irq(MVME167_IRQ_SER_RX, cd2401_rx_interrupt, 0,
2320 "cd2401_rxints", cd2401_rx_interrupt);
2322 printk(KERN_ERR "Could't get cd2401_rxints IRQ");
2323 goto cleanup_irq_cd2401_txints;
2326 /* Now we have registered the interrupt handlers, allow the interrupts */
2328 pcc2chip[PccSCCMICR] = 0x15; /* Serial ints are level 5 */
2329 pcc2chip[PccSCCTICR] = 0x15;
2330 pcc2chip[PccSCCRICR] = 0x15;
2332 pcc2chip[PccIMLR] = 3; /* Allow PCC2 ints above 3!? */
2335 cleanup_irq_cd2401_txints:
2336 free_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt);
2337 cleanup_irq_cd2401_modem:
2338 free_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt);
2339 cleanup_irq_cd2401_errors:
2340 free_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt);
2341 cleanup_serial_driver:
2342 if (tty_unregister_driver(cy_serial_driver))
2343 printk(KERN_ERR "Couldn't unregister MVME166/7 serial driver\n");
2344 put_tty_driver(cy_serial_driver);
2346 } /* serial167_init */
2348 module_init(serial167_init);
2351 #ifdef CYCLOM_SHOW_STATUS
2353 show_status(int line_num)
2355 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2357 struct cyclades_port * info;
2358 unsigned long flags;
2360 info = &cy_port[line_num];
2361 channel = info->line;
2362 printk(" channel %d\n", channel);/**/
2364 printk(" cy_port\n");
2365 printk(" card line flags = %d %d %x\n",
2366 info->card, info->line, info->flags);
2367 printk(" *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n",
2368 (long)info->tty, info->read_status_mask,
2369 info->timeout, info->xmit_fifo_size);
2370 printk(" cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n",
2371 info->cor1, info->cor2, info->cor3, info->cor4, info->cor5,
2372 info->cor6, info->cor7);
2373 printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n",
2374 info->tbpr, info->tco, info->rbpr, info->rco);
2375 printk(" close_delay event count = %d %d %d\n",
2376 info->close_delay, info->event, info->count);
2377 printk(" x_char blocked_open = %x %x\n",
2378 info->x_char, info->blocked_open);
2379 printk(" open_wait = %lx %lx %lx\n",
2380 (long)info->open_wait);
2383 local_irq_save(flags);
2385 /* Global Registers */
2387 printk(" CyGFRCR %x\n", base_addr[CyGFRCR]);
2388 printk(" CyCAR %x\n", base_addr[CyCAR]);
2389 printk(" CyRISR %x\n", base_addr[CyRISR]);
2390 printk(" CyTISR %x\n", base_addr[CyTISR]);
2391 printk(" CyMISR %x\n", base_addr[CyMISR]);
2392 printk(" CyRIR %x\n", base_addr[CyRIR]);
2393 printk(" CyTIR %x\n", base_addr[CyTIR]);
2394 printk(" CyMIR %x\n", base_addr[CyMIR]);
2395 printk(" CyTPR %x\n", base_addr[CyTPR]);
2397 base_addr[CyCAR] = (u_char)channel;
2399 /* Virtual Registers */
2402 printk(" CyRIVR %x\n", base_addr[CyRIVR]);
2403 printk(" CyTIVR %x\n", base_addr[CyTIVR]);
2404 printk(" CyMIVR %x\n", base_addr[CyMIVR]);
2405 printk(" CyMISR %x\n", base_addr[CyMISR]);
2408 /* Channel Registers */
2410 printk(" CyCCR %x\n", base_addr[CyCCR]);
2411 printk(" CyIER %x\n", base_addr[CyIER]);
2412 printk(" CyCOR1 %x\n", base_addr[CyCOR1]);
2413 printk(" CyCOR2 %x\n", base_addr[CyCOR2]);
2414 printk(" CyCOR3 %x\n", base_addr[CyCOR3]);
2415 printk(" CyCOR4 %x\n", base_addr[CyCOR4]);
2416 printk(" CyCOR5 %x\n", base_addr[CyCOR5]);
2418 printk(" CyCCSR %x\n", base_addr[CyCCSR]);
2419 printk(" CyRDCR %x\n", base_addr[CyRDCR]);
2421 printk(" CySCHR1 %x\n", base_addr[CySCHR1]);
2422 printk(" CySCHR2 %x\n", base_addr[CySCHR2]);
2424 printk(" CySCHR3 %x\n", base_addr[CySCHR3]);
2425 printk(" CySCHR4 %x\n", base_addr[CySCHR4]);
2426 printk(" CySCRL %x\n", base_addr[CySCRL]);
2427 printk(" CySCRH %x\n", base_addr[CySCRH]);
2428 printk(" CyLNC %x\n", base_addr[CyLNC]);
2429 printk(" CyMCOR1 %x\n", base_addr[CyMCOR1]);
2430 printk(" CyMCOR2 %x\n", base_addr[CyMCOR2]);
2432 printk(" CyRTPRL %x\n", base_addr[CyRTPRL]);
2433 printk(" CyRTPRH %x\n", base_addr[CyRTPRH]);
2434 printk(" CyMSVR1 %x\n", base_addr[CyMSVR1]);
2435 printk(" CyMSVR2 %x\n", base_addr[CyMSVR2]);
2436 printk(" CyRBPR %x\n", base_addr[CyRBPR]);
2437 printk(" CyRCOR %x\n", base_addr[CyRCOR]);
2438 printk(" CyTBPR %x\n", base_addr[CyTBPR]);
2439 printk(" CyTCOR %x\n", base_addr[CyTCOR]);
2441 local_irq_restore(flags);
2447 /* Dummy routine in mvme16x/config.c for now */
2449 /* Serial console setup. Called from linux/init/main.c */
2451 void console_setup(char *str, int *ints)
2454 int baud, bits, parity;
2458 if (ints[0] > 3 || ints[1] > 3) return;
2460 /* Get baud, bits and parity */
2464 if (ints[2]) baud = ints[2];
2465 if ((s = strchr(str, ','))) {
2468 } while(*s >= '0' && *s <= '9');
2469 if (*s) parity = *s++;
2470 if (*s) bits = *s - '0';
2473 /* Now construct a cflag setting. */
2510 serial_console_info = &cy_port[ints[1]];
2511 serial_console_cflag = cflag;
2512 serial_console = ints[1] + 64; /*callout_driver.minor_start*/
2517 * The following is probably out of date for 2.1.x serial console stuff.
2519 * The console is registered early on from arch/m68k/kernel/setup.c, and
2520 * it therefore relies on the chip being setup correctly by 166-Bug. This
2521 * seems reasonable, as the serial port has been used to invoke the system
2522 * boot. It also means that this function must not rely on any data
2523 * initialisation performed by serial167_init() etc.
2525 * Of course, once the console has been registered, we had better ensure
2526 * that serial167_init() doesn't leave the chip non-functional.
2528 * The console must be locked when we get here.
2531 void serial167_console_write(struct console *co, const char *str, unsigned count)
2533 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2534 unsigned long flags;
2535 volatile u_char sink;
2541 local_irq_save(flags);
2543 /* Ensure transmitter is enabled! */
2546 base_addr[CyCAR] = (u_char)port;
2547 while (base_addr[CyCCR])
2549 base_addr[CyCCR] = CyENB_XMTR;
2551 ier = base_addr[CyIER];
2552 base_addr[CyIER] = CyTxMpty;
2555 if (pcc2chip[PccSCCTICR] & 0x20)
2557 /* We have a Tx int. Acknowledge it */
2558 sink = pcc2chip[PccTPIACKR];
2559 if ((base_addr[CyLICR] >> 2) == port) {
2561 /* Last char of string is now output */
2562 base_addr[CyTEOIR] = CyNOTRANS;
2566 base_addr[CyTDR] = '\n';
2571 else if (*str == '\n') {
2572 base_addr[CyTDR] = '\r';
2576 base_addr[CyTDR] = *str++;
2579 base_addr[CyTEOIR] = 0;
2582 base_addr[CyTEOIR] = CyNOTRANS;
2586 base_addr[CyIER] = ier;
2588 local_irq_restore(flags);
2591 static struct tty_driver *serial167_console_device(struct console *c, int *index)
2594 return cy_serial_driver;
2598 static int __init serial167_console_setup(struct console *co, char *options)
2604 static struct console sercons = {
2606 .write = serial167_console_write,
2607 .device = serial167_console_device,
2608 .setup = serial167_console_setup,
2609 .flags = CON_PRINTBUFFER,
2614 static int __init serial167_console_init(void)
2616 if (vme_brdtype == VME_TYPE_MVME166 ||
2617 vme_brdtype == VME_TYPE_MVME167 ||
2618 vme_brdtype == VME_TYPE_MVME177) {
2619 mvme167_serial_console_setup(0);
2620 register_console(&sercons);
2624 console_initcall(serial167_console_init);
2626 #ifdef CONFIG_REMOTE_DEBUG
2627 void putDebugChar (int c)
2629 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2630 unsigned long flags;
2631 volatile u_char sink;
2635 local_irq_save(flags);
2637 /* Ensure transmitter is enabled! */
2640 base_addr[CyCAR] = (u_char)port;
2641 while (base_addr[CyCCR])
2643 base_addr[CyCCR] = CyENB_XMTR;
2645 ier = base_addr[CyIER];
2646 base_addr[CyIER] = CyTxMpty;
2649 if (pcc2chip[PccSCCTICR] & 0x20)
2651 /* We have a Tx int. Acknowledge it */
2652 sink = pcc2chip[PccTPIACKR];
2653 if ((base_addr[CyLICR] >> 2) == port) {
2654 base_addr[CyTDR] = c;
2655 base_addr[CyTEOIR] = 0;
2659 base_addr[CyTEOIR] = CyNOTRANS;
2663 base_addr[CyIER] = ier;
2665 local_irq_restore(flags);
2670 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2671 unsigned long flags;
2672 volatile u_char sink;
2678 if (i != debugiq.in) {
2680 if (++i == DEBUG_LEN)
2685 /* OK, nothing in queue, wait in poll loop */
2687 local_irq_save(flags);
2689 /* Ensure receiver is enabled! */
2692 base_addr[CyCAR] = (u_char)port;
2694 while (base_addr[CyCCR])
2696 base_addr[CyCCR] = CyENB_RCVR;
2698 ier = base_addr[CyIER];
2699 base_addr[CyIER] = CyRxData;
2702 if (pcc2chip[PccSCCRICR] & 0x20)
2704 /* We have a Rx int. Acknowledge it */
2705 sink = pcc2chip[PccRPIACKR];
2706 if ((base_addr[CyLICR] >> 2) == port) {
2707 int cnt = base_addr[CyRFOC];
2710 c = base_addr[CyRDR];
2712 printk ("!! debug char is null (cnt=%d) !!", cnt);
2716 base_addr[CyREOIR] = 0;
2718 if (i == debugiq.in)
2719 panic ("Debug input queue empty!");
2721 if (++i == DEBUG_LEN)
2727 base_addr[CyREOIR] = CyNOTRANS;
2731 base_addr[CyIER] = ier;
2733 local_irq_restore(flags);
2738 void queueDebugChar (int c)
2744 if (++i == DEBUG_LEN)
2746 if (i != debugiq.out)
2753 unsigned long flags;
2754 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2759 local_irq_save(flags);
2761 for (i = 0; i < 4; i++)
2763 base_addr[CyCAR] = i;
2764 base_addr[CyLICR] = i << 2;
2767 debugiq.in = debugiq.out = 0;
2769 base_addr[CyCAR] = DEBUG_PORT;
2774 base_addr[CyIER] = 0;
2776 base_addr[CyCMR] = CyASYNC;
2777 base_addr[CyLICR] = DEBUG_PORT << 2;
2778 base_addr[CyLIVR] = 0x5c;
2780 /* tx and rx baud rate */
2782 base_addr[CyTCOR] = baud_co[i];
2783 base_addr[CyTBPR] = baud_bpr[i];
2784 base_addr[CyRCOR] = baud_co[i] >> 5;
2785 base_addr[CyRBPR] = baud_bpr[i];
2787 /* set line characteristics according configuration */
2789 base_addr[CySCHR1] = 0;
2790 base_addr[CySCHR2] = 0;
2791 base_addr[CySCRL] = 0;
2792 base_addr[CySCRH] = 0;
2793 base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
2794 base_addr[CyCOR2] = 0;
2795 base_addr[CyCOR3] = Cy_1_STOP;
2796 base_addr[CyCOR4] = baud_cor4[i];
2797 base_addr[CyCOR5] = 0;
2798 base_addr[CyCOR6] = 0;
2799 base_addr[CyCOR7] = 0;
2801 write_cy_cmd(base_addr,CyINIT_CHAN);
2802 write_cy_cmd(base_addr,CyENB_RCVR);
2804 base_addr[CyCAR] = DEBUG_PORT; /* !!! Is this needed? */
2806 base_addr[CyRTPRL] = 2;
2807 base_addr[CyRTPRH] = 0;
2809 base_addr[CyMSVR1] = CyRTS;
2810 base_addr[CyMSVR2] = CyDTR;
2812 base_addr[CyIER] = CyRxData;
2814 local_irq_restore(flags);
2820 MODULE_LICENSE("GPL");