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 (sizeof(cy_port)/sizeof(struct cyclades_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;
132 DECLARE_MUTEX(tmp_buf_sem);
135 * This is used to look up the divisor speeds and the timeouts
136 * We're normally limited to 15 distinct baud rates. The extra
137 * are accessed via settings in info->flags.
138 * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
139 * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
142 static int baud_table[] = {
143 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
144 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000,
148 static char baud_co[] = { /* 25 MHz clock option table */
149 /* value => 00 01 02 03 04 */
150 /* divide by 8 32 128 512 2048 */
151 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
152 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
154 static char baud_bpr[] = { /* 25 MHz baud rate period table */
155 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
156 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15};
159 /* I think 166 brd clocks 2401 at 20MHz.... */
161 /* These values are written directly to tcor, and >> 5 for writing to rcor */
162 static u_char baud_co[] = { /* 20 MHz clock option table */
163 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x60, 0x60, 0x40,
164 0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
166 /* These values written directly to tbpr/rbpr */
167 static u_char baud_bpr[] = { /* 20 MHz baud rate period table */
168 0x00, 0xc0, 0x80, 0x58, 0x6c, 0x40, 0xc0, 0x81, 0x40, 0x81,
169 0x57, 0x40, 0x81, 0x40, 0x81, 0x40, 0x2b, 0x20, 0x15, 0x10};
171 static u_char baud_cor4[] = { /* receive threshold */
172 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
173 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07};
177 static void shutdown(struct cyclades_port *);
178 static int startup (struct cyclades_port *);
179 static void cy_throttle(struct tty_struct *);
180 static void cy_unthrottle(struct tty_struct *);
181 static void config_setup(struct cyclades_port *);
182 extern void console_print(const char *);
183 #ifdef CYCLOM_SHOW_STATUS
184 static void show_status(int);
187 #ifdef CONFIG_REMOTE_DEBUG
188 static void debug_setup(void);
189 void queueDebugChar (int c);
190 int getDebugChar(void);
193 #define DEBUG_LEN 256
198 unsigned char buf[DEBUG_LEN];
205 * I have my own version of udelay(), as it is needed when initialising
206 * the chip, before the delay loop has been calibrated. Should probably
207 * reference one of the vmechip2 or pccchip2 counter for an accurate
208 * delay, but this wild guess will do for now.
211 void my_udelay (long us)
214 volatile u_char *p = &x;
218 for (i = 100; i; i--)
223 serial_paranoia_check(struct cyclades_port *info, char *name,
226 #ifdef SERIAL_PARANOIA_CHECK
227 static const char *badmagic =
228 "Warning: bad magic number for serial struct (%s) in %s\n";
229 static const char *badinfo =
230 "Warning: null cyclades_port for (%s) in %s\n";
231 static const char *badrange =
232 "Warning: cyclades_port out of range for (%s) in %s\n";
235 printk(badinfo, name, routine);
239 if( (long)info < (long)(&cy_port[0])
240 || (long)(&cy_port[NR_PORTS]) < (long)info ){
241 printk(badrange, name, routine);
245 if (info->magic != CYCLADES_MAGIC) {
246 printk(badmagic, name, routine);
251 } /* serial_paranoia_check */
254 /* The following diagnostic routines allow the driver to spew
255 information on the screen, even (especially!) during interrupts.
260 local_irq_save(flags);
262 local_irq_restore(flags);
268 local_irq_save(flags);
271 local_irq_restore(flags);
274 void CP1(int data) { (data<10)? CP(data+'0'): CP(data+'A'-10); }/* CP1 */
275 void CP2(int data) { CP1((data>>4) & 0x0f); CP1( data & 0x0f); }/* CP2 */
276 void CP4(int data) { CP2((data>>8) & 0xff); CP2(data & 0xff); }/* CP4 */
277 void CP8(long data) { CP4((data>>16) & 0xffff); CP4(data & 0xffff); }/* CP8 */
280 /* This routine waits up to 1000 micro-seconds for the previous
281 command to the Cirrus chip to complete and then issues the
282 new command. An error is returned if the previous command
283 didn't finish within the time limit.
286 write_cy_cmd(volatile u_char *base_addr, u_char cmd)
291 local_irq_save(flags);
292 /* Check to see that the previous command has completed */
293 for(i = 0 ; i < 100 ; i++){
294 if (base_addr[CyCCR] == 0){
299 /* if the CCR never cleared, the previous command
300 didn't finish within the "reasonable time" */
302 local_irq_restore(flags);
306 /* Issue the new command */
307 base_addr[CyCCR] = cmd;
308 local_irq_restore(flags);
313 /* cy_start and cy_stop provide software output flow control as a
314 function of XON/XOFF, software CTS, and other such stuff. */
317 cy_stop(struct tty_struct *tty)
319 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
320 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
324 #ifdef SERIAL_DEBUG_OTHER
325 printk("cy_stop %s\n", tty->name); /* */
328 if (serial_paranoia_check(info, tty->name, "cy_stop"))
331 channel = info->line;
333 local_irq_save(flags);
334 base_addr[CyCAR] = (u_char)(channel); /* index channel */
335 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
336 local_irq_restore(flags);
342 cy_start(struct tty_struct *tty)
344 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
345 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
349 #ifdef SERIAL_DEBUG_OTHER
350 printk("cy_start %s\n", tty->name); /* */
353 if (serial_paranoia_check(info, tty->name, "cy_start"))
356 channel = info->line;
358 local_irq_save(flags);
359 base_addr[CyCAR] = (u_char)(channel);
360 base_addr[CyIER] |= CyTxMpty;
361 local_irq_restore(flags);
368 * This routine is used by the interrupt handler to schedule
369 * processing in the software interrupt portion of the driver
370 * (also known as the "bottom half"). This can be called any
371 * number of times for any channel without harm.
374 cy_sched_event(struct cyclades_port *info, int event)
376 info->event |= 1 << event; /* remember what kind of event and who */
377 schedule_work(&info->tqueue);
378 } /* cy_sched_event */
381 /* The real interrupt service routines are called
382 whenever the card wants its hand held--chars
383 received, out buffer empty, modem change, etc.
386 cd2401_rxerr_interrupt(int irq, void *dev_id, struct pt_regs *fp)
388 struct tty_struct *tty;
389 struct cyclades_port *info;
390 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
391 unsigned char err, rfoc;
395 /* determine the channel and change to that context */
396 channel = (u_short ) (base_addr[CyLICR] >> 2);
397 info = &cy_port[channel];
398 info->last_active = jiffies;
400 if ((err = base_addr[CyRISR]) & CyTIMEOUT) {
401 /* This is a receive timeout interrupt, ignore it */
402 base_addr[CyREOIR] = CyNOTRANS;
406 /* Read a byte of data if there is any - assume the error
407 * is associated with this character */
409 if ((rfoc = base_addr[CyRFOC]) != 0)
410 data = base_addr[CyRDR];
414 /* if there is nowhere to put the data, discard it */
416 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
419 else { /* there is an open port for this data */
421 if(err & info->ignore_status_mask){
422 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
425 if (tty->flip.count < TTY_FLIPBUF_SIZE){
427 if (err & info->read_status_mask){
429 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
430 *tty->flip.char_buf_ptr++ = data;
431 if (info->flags & ASYNC_SAK){
434 }else if(err & CyFRAME){
435 *tty->flip.flag_buf_ptr++ = TTY_FRAME;
436 *tty->flip.char_buf_ptr++ = data;
437 }else if(err & CyPARITY){
438 *tty->flip.flag_buf_ptr++ = TTY_PARITY;
439 *tty->flip.char_buf_ptr++ = data;
440 }else if(err & CyOVERRUN){
441 *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
442 *tty->flip.char_buf_ptr++ = 0;
444 If the flip buffer itself is
445 overflowing, we still loose
446 the next incoming character.
448 if(tty->flip.count < TTY_FLIPBUF_SIZE){
450 *tty->flip.flag_buf_ptr++ = TTY_NORMAL;
451 *tty->flip.char_buf_ptr++ = data;
453 /* These two conditions may imply */
454 /* a normal read should be done. */
455 /* else if(data & CyTIMEOUT) */
456 /* else if(data & CySPECHAR) */
458 *tty->flip.flag_buf_ptr++ = 0;
459 *tty->flip.char_buf_ptr++ = 0;
462 *tty->flip.flag_buf_ptr++ = 0;
463 *tty->flip.char_buf_ptr++ = 0;
466 /* there was a software buffer overrun
467 and nothing could be done about it!!! */
470 schedule_delayed_work(&tty->flip.work, 1);
472 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
474 } /* cy_rxerr_interrupt */
477 cd2401_modem_interrupt(int irq, void *dev_id, struct pt_regs *fp)
479 struct cyclades_port *info;
480 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
486 /* determine the channel and change to that context */
487 channel = (u_short ) (base_addr[CyLICR] >> 2);
488 info = &cy_port[channel];
489 info->last_active = jiffies;
491 mdm_change = base_addr[CyMISR];
492 mdm_status = base_addr[CyMSVR1];
494 if(info->tty == 0){ /* nowhere to put the data, ignore it */
497 if((mdm_change & CyDCD)
498 && (info->flags & ASYNC_CHECK_CD)){
499 if(mdm_status & CyDCD){
501 cy_sched_event(info, Cy_EVENT_OPEN_WAKEUP);
504 cy_sched_event(info, Cy_EVENT_HANGUP);
507 if((mdm_change & CyCTS)
508 && (info->flags & ASYNC_CTS_FLOW)){
509 if(info->tty->stopped){
510 if(mdm_status & CyCTS){
511 /* !!! cy_start isn't used because... */
512 info->tty->stopped = 0;
513 base_addr[CyIER] |= CyTxMpty;
514 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
517 if(!(mdm_status & CyCTS)){
518 /* !!! cy_stop isn't used because... */
519 info->tty->stopped = 1;
520 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
524 if(mdm_status & CyDSR){
527 base_addr[CyMEOIR] = 0;
529 } /* cy_modem_interrupt */
532 cd2401_tx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
534 struct cyclades_port *info;
535 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
537 int char_count, saved_cnt;
540 /* determine the channel and change to that context */
541 channel = (u_short ) (base_addr[CyLICR] >> 2);
543 #ifdef CONFIG_REMOTE_DEBUG
544 if (channel == DEBUG_PORT) {
545 panic ("TxInt on debug port!!!");
549 info = &cy_port[channel];
551 /* validate the port number (as configured and open) */
552 if( (channel < 0) || (NR_PORTS <= channel) ){
553 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
554 base_addr[CyTEOIR] = CyNOTRANS;
557 info->last_active = jiffies;
559 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
560 if (info->xmit_cnt < WAKEUP_CHARS) {
561 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
563 base_addr[CyTEOIR] = CyNOTRANS;
567 /* load the on-chip space available for outbound data */
568 saved_cnt = char_count = base_addr[CyTFTC];
570 if(info->x_char) { /* send special char */
571 outch = info->x_char;
572 base_addr[CyTDR] = outch;
578 /* The Cirrus chip requires the "Embedded Transmit
579 Commands" of start break, delay, and end break
580 sequences to be sent. The duration of the
581 break is given in TICs, which runs at HZ
582 (typically 100) and the PPR runs at 200 Hz,
583 so the delay is duration * 200/HZ, and thus a
584 break can run from 1/100 sec to about 5/4 sec.
585 Need to check these values - RGH 141095.
587 base_addr[CyTDR] = 0; /* start break */
588 base_addr[CyTDR] = 0x81;
589 base_addr[CyTDR] = 0; /* delay a bit */
590 base_addr[CyTDR] = 0x82;
591 base_addr[CyTDR] = info->x_break*200/HZ;
592 base_addr[CyTDR] = 0; /* terminate break */
593 base_addr[CyTDR] = 0x83;
598 while (char_count > 0){
599 if (!info->xmit_cnt){
600 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
603 if (info->xmit_buf == 0){
604 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
607 if (info->tty->stopped || info->tty->hw_stopped){
608 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
611 /* Because the Embedded Transmit Commands have been
612 enabled, we must check to see if the escape
613 character, NULL, is being sent. If it is, we
614 must ensure that there is room for it to be
615 doubled in the output stream. Therefore we
616 no longer advance the pointer when the character
617 is fetched, but rather wait until after the check
618 for a NULL output character. (This is necessary
619 because there may not be room for the two chars
620 needed to send a NULL.
622 outch = info->xmit_buf[info->xmit_tail];
625 info->xmit_tail = (info->xmit_tail + 1)
627 base_addr[CyTDR] = outch;
632 info->xmit_tail = (info->xmit_tail + 1)
634 base_addr[CyTDR] = outch;
635 base_addr[CyTDR] = 0;
644 if (info->xmit_cnt < WAKEUP_CHARS) {
645 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
647 base_addr[CyTEOIR] = (char_count != saved_cnt) ? 0 : CyNOTRANS;
649 } /* cy_tx_interrupt */
652 cd2401_rx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
654 struct tty_struct *tty;
655 struct cyclades_port *info;
656 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
662 /* determine the channel and change to that context */
663 channel = (u_short ) (base_addr[CyLICR] >> 2);
664 info = &cy_port[channel];
665 info->last_active = jiffies;
666 save_cnt = char_count = base_addr[CyRFOC];
668 #ifdef CONFIG_REMOTE_DEBUG
669 if (channel == DEBUG_PORT) {
670 while (char_count--) {
671 data = base_addr[CyRDR];
672 queueDebugChar(data);
677 /* if there is nowhere to put the data, discard it */
680 data = base_addr[CyRDR];
682 }else{ /* there is an open port for this data */
684 /* load # characters available from the chip */
686 #ifdef CYCLOM_ENABLE_MONITORING
687 ++info->mon.int_count;
688 info->mon.char_count += char_count;
689 if (char_count > info->mon.char_max)
690 info->mon.char_max = char_count;
691 info->mon.char_last = char_count;
694 data = base_addr[CyRDR];
695 if (tty->flip.count >= TTY_FLIPBUF_SIZE){
699 *tty->flip.flag_buf_ptr++ = TTY_NORMAL;
700 *tty->flip.char_buf_ptr++ = data;
701 #ifdef CYCLOM_16Y_HACK
705 schedule_delayed_work(&tty->flip.work, 1);
708 base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS;
710 } /* cy_rx_interrupt */
713 * This routine is used to handle the "bottom half" processing for the
714 * serial driver, known also the "software interrupt" processing.
715 * This processing is done at the kernel interrupt level, after the
716 * cy#/_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
717 * is where time-consuming activities which can not be done in the
718 * interrupt driver proper are done; the interrupt driver schedules
719 * them using cy_sched_event(), and they get done here.
721 * This is done through one level of indirection--the task queue.
722 * When a hardware interrupt service routine wants service by the
723 * driver's bottom half, it enqueues the appropriate tq_struct (one
724 * per port) to the keventd work queue and sets a request flag
725 * that the work queue be processed.
727 * Although this may seem unwieldy, it gives the system a way to
728 * pass an argument (in this case the pointer to the cyclades_port
729 * structure) to the bottom half of the driver. Previous kernels
730 * had to poll every port to see if that port needed servicing.
733 do_softint(void *private_)
735 struct cyclades_port *info = (struct cyclades_port *) private_;
736 struct tty_struct *tty;
742 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
743 tty_hangup(info->tty);
744 wake_up_interruptible(&info->open_wait);
745 info->flags &= ~ASYNC_NORMAL_ACTIVE;
747 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) {
748 wake_up_interruptible(&info->open_wait);
750 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
756 /* This is called whenever a port becomes active;
757 interrupts are enabled and DTR & RTS are turned on.
760 startup(struct cyclades_port * info)
763 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
766 if (info->flags & ASYNC_INITIALIZED){
772 set_bit(TTY_IO_ERROR, &info->tty->flags);
776 if (!info->xmit_buf){
777 info->xmit_buf = (unsigned char *) get_zeroed_page (GFP_KERNEL);
778 if (!info->xmit_buf){
785 channel = info->line;
787 #ifdef SERIAL_DEBUG_OPEN
788 printk("startup channel %d\n", channel);
791 local_irq_save(flags);
792 base_addr[CyCAR] = (u_char)channel;
793 write_cy_cmd(base_addr,CyENB_RCVR|CyENB_XMTR);
795 base_addr[CyCAR] = (u_char)channel; /* !!! Is this needed? */
796 base_addr[CyMSVR1] = CyRTS;
797 /* CP('S');CP('1'); */
798 base_addr[CyMSVR2] = CyDTR;
800 #ifdef SERIAL_DEBUG_DTR
801 printk("cyc: %d: raising DTR\n", __LINE__);
802 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
805 base_addr[CyIER] |= CyRxData;
806 info->flags |= ASYNC_INITIALIZED;
809 clear_bit(TTY_IO_ERROR, &info->tty->flags);
811 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
813 local_irq_restore(flags);
815 #ifdef SERIAL_DEBUG_OPEN
822 start_xmit( struct cyclades_port *info )
825 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
828 channel = info->line;
829 local_irq_save(flags);
830 base_addr[CyCAR] = channel;
831 base_addr[CyIER] |= CyTxMpty;
832 local_irq_restore(flags);
836 * This routine shuts down a serial port; interrupts are disabled,
837 * and DTR is dropped if the hangup on close termio flag is on.
840 shutdown(struct cyclades_port * info)
843 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
846 if (!(info->flags & ASYNC_INITIALIZED)){
851 channel = info->line;
853 #ifdef SERIAL_DEBUG_OPEN
854 printk("shutdown channel %d\n", channel);
857 /* !!! REALLY MUST WAIT FOR LAST CHARACTER TO BE
858 SENT BEFORE DROPPING THE LINE !!! (Perhaps
859 set some flag that is read when XMTY happens.)
860 Other choices are to delay some fixed interval
861 or schedule some later processing.
863 local_irq_save(flags);
865 free_page((unsigned long) info->xmit_buf);
869 base_addr[CyCAR] = (u_char)channel;
870 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
871 base_addr[CyMSVR1] = 0;
872 /* CP('C');CP('1'); */
873 base_addr[CyMSVR2] = 0;
874 #ifdef SERIAL_DEBUG_DTR
875 printk("cyc: %d: dropping DTR\n", __LINE__);
876 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
879 write_cy_cmd(base_addr,CyDIS_RCVR);
880 /* it may be appropriate to clear _XMIT at
881 some later date (after testing)!!! */
884 set_bit(TTY_IO_ERROR, &info->tty->flags);
886 info->flags &= ~ASYNC_INITIALIZED;
887 local_irq_restore(flags);
889 #ifdef SERIAL_DEBUG_OPEN
896 * This routine finds or computes the various line characteristics.
899 config_setup(struct cyclades_port * info)
902 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
906 unsigned char ti, need_init_chan = 0;
908 if (!info->tty || !info->tty->termios){
911 if (info->line == -1){
914 cflag = info->tty->termios->c_cflag;
919 /* Starting with kernel 1.1.65, there is direct support for
920 higher baud rates. The following code supports those
921 changes. The conditional aspect allows this driver to be
922 used for earlier as well as later kernel versions. (The
923 mapping is slightly different from serial.c because there
924 is still the possibility of supporting 75 kbit/sec with
930 else if(i == B115200)
937 info->tty->termios->c_cflag &= ~CBAUDEX;
941 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
943 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
946 /* Don't ever change the speed of the console port. It will
947 * run at the speed specified in bootinfo, or at 19.2K */
948 /* Actually, it should run at whatever speed 166Bug was using */
949 /* Note info->timeout isn't used at present */
950 if (info != serial_console_info) {
951 info->tbpr = baud_bpr[i]; /* Tx BPR */
952 info->tco = baud_co[i]; /* Tx CO */
953 info->rbpr = baud_bpr[i]; /* Rx BPR */
954 info->rco = baud_co[i] >> 5; /* Rx CO */
955 if (baud_table[i] == 134) {
956 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
957 /* get it right for 134.5 baud */
958 } else if (baud_table[i]) {
959 info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2;
960 /* this needs to be propagated into the card info */
965 /* By tradition (is it a standard?) a baud rate of zero
966 implies the line should be/has been closed. A bit
967 later in this routine such a test is performed. */
969 /* byte size and parity */
973 info->cor4 = (info->default_threshold
974 ? info->default_threshold
975 : baud_cor4[i]); /* receive threshold */
976 /* Following two lines added 101295, RGH. */
977 /* It is obviously wrong to access CyCORx, and not info->corx here,
978 * try and remember to fix it later! */
979 channel = info->line;
980 base_addr[CyCAR] = (u_char)channel;
981 if (C_CLOCAL(info->tty)) {
982 if (base_addr[CyIER] & CyMdmCh)
983 base_addr[CyIER] &= ~CyMdmCh; /* without modem intr */
984 /* ignore 1->0 modem transitions */
985 if (base_addr[CyCOR4] & (CyDSR|CyCTS|CyDCD))
986 base_addr[CyCOR4] &= ~(CyDSR|CyCTS|CyDCD);
987 /* ignore 0->1 modem transitions */
988 if (base_addr[CyCOR5] & (CyDSR|CyCTS|CyDCD))
989 base_addr[CyCOR5] &= ~(CyDSR|CyCTS|CyDCD);
991 if ((base_addr[CyIER] & CyMdmCh) != CyMdmCh)
992 base_addr[CyIER] |= CyMdmCh; /* with modem intr */
993 /* act on 1->0 modem transitions */
994 if ((base_addr[CyCOR4] & (CyDSR|CyCTS|CyDCD)) != (CyDSR|CyCTS|CyDCD))
995 base_addr[CyCOR4] |= CyDSR|CyCTS|CyDCD;
996 /* act on 0->1 modem transitions */
997 if ((base_addr[CyCOR5] & (CyDSR|CyCTS|CyDCD)) != (CyDSR|CyCTS|CyDCD))
998 base_addr[CyCOR5] |= CyDSR|CyCTS|CyDCD;
1000 info->cor3 = (cflag & CSTOPB) ? Cy_2_STOP : Cy_1_STOP;
1002 switch(cflag & CSIZE){
1004 info->cor1 = Cy_5_BITS;
1007 info->cor1 = Cy_6_BITS;
1010 info->cor1 = Cy_7_BITS;
1013 info->cor1 = Cy_8_BITS;
1016 if (cflag & PARENB){
1017 if (cflag & PARODD){
1018 info->cor1 |= CyPARITY_O;
1020 info->cor1 |= CyPARITY_E;
1023 info->cor1 |= CyPARITY_NONE;
1026 /* CTS flow control flag */
1028 /* Don't complcate matters for now! RGH 141095 */
1029 if (cflag & CRTSCTS){
1030 info->flags |= ASYNC_CTS_FLOW;
1031 info->cor2 |= CyCtsAE;
1033 info->flags &= ~ASYNC_CTS_FLOW;
1034 info->cor2 &= ~CyCtsAE;
1038 info->flags &= ~ASYNC_CHECK_CD;
1040 info->flags |= ASYNC_CHECK_CD;
1042 /***********************************************
1043 The hardware option, CyRtsAO, presents RTS when
1044 the chip has characters to send. Since most modems
1045 use RTS as reverse (inbound) flow control, this
1046 option is not used. If inbound flow control is
1047 necessary, DTR can be programmed to provide the
1048 appropriate signals for use with a non-standard
1049 cable. Contact Marcio Saito for details.
1050 ***********************************************/
1052 channel = info->line;
1054 local_irq_save(flags);
1055 base_addr[CyCAR] = (u_char)channel;
1057 /* CyCMR set once only in mvme167_init_serial() */
1058 if (base_addr[CyLICR] != channel << 2)
1059 base_addr[CyLICR] = channel << 2;
1060 if (base_addr[CyLIVR] != 0x5c)
1061 base_addr[CyLIVR] = 0x5c;
1063 /* tx and rx baud rate */
1065 if (base_addr[CyCOR1] != info->cor1)
1067 if (base_addr[CyTCOR] != info->tco)
1068 base_addr[CyTCOR] = info->tco;
1069 if (base_addr[CyTBPR] != info->tbpr)
1070 base_addr[CyTBPR] = info->tbpr;
1071 if (base_addr[CyRCOR] != info->rco)
1072 base_addr[CyRCOR] = info->rco;
1073 if (base_addr[CyRBPR] != info->rbpr)
1074 base_addr[CyRBPR] = info->rbpr;
1076 /* set line characteristics according configuration */
1078 if (base_addr[CySCHR1] != START_CHAR(info->tty))
1079 base_addr[CySCHR1] = START_CHAR(info->tty);
1080 if (base_addr[CySCHR2] != STOP_CHAR(info->tty))
1081 base_addr[CySCHR2] = STOP_CHAR(info->tty);
1082 if (base_addr[CySCRL] != START_CHAR(info->tty))
1083 base_addr[CySCRL] = START_CHAR(info->tty);
1084 if (base_addr[CySCRH] != START_CHAR(info->tty))
1085 base_addr[CySCRH] = START_CHAR(info->tty);
1086 if (base_addr[CyCOR1] != info->cor1)
1087 base_addr[CyCOR1] = info->cor1;
1088 if (base_addr[CyCOR2] != info->cor2)
1089 base_addr[CyCOR2] = info->cor2;
1090 if (base_addr[CyCOR3] != info->cor3)
1091 base_addr[CyCOR3] = info->cor3;
1092 if (base_addr[CyCOR4] != info->cor4)
1093 base_addr[CyCOR4] = info->cor4;
1094 if (base_addr[CyCOR5] != info->cor5)
1095 base_addr[CyCOR5] = info->cor5;
1096 if (base_addr[CyCOR6] != info->cor6)
1097 base_addr[CyCOR6] = info->cor6;
1098 if (base_addr[CyCOR7] != info->cor7)
1099 base_addr[CyCOR7] = info->cor7;
1102 write_cy_cmd(base_addr,CyINIT_CHAN);
1104 base_addr[CyCAR] = (u_char)channel; /* !!! Is this needed? */
1106 /* 2ms default rx timeout */
1107 ti = info->default_timeout ? info->default_timeout : 0x02;
1108 if (base_addr[CyRTPRL] != ti)
1109 base_addr[CyRTPRL] = ti;
1110 if (base_addr[CyRTPRH] != 0)
1111 base_addr[CyRTPRH] = 0;
1113 /* Set up RTS here also ????? RGH 141095 */
1114 if(i == 0){ /* baud rate is zero, turn off line */
1115 if ((base_addr[CyMSVR2] & CyDTR) == CyDTR)
1116 base_addr[CyMSVR2] = 0;
1117 #ifdef SERIAL_DEBUG_DTR
1118 printk("cyc: %d: dropping DTR\n", __LINE__);
1119 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1122 if ((base_addr[CyMSVR2] & CyDTR) != CyDTR)
1123 base_addr[CyMSVR2] = CyDTR;
1124 #ifdef SERIAL_DEBUG_DTR
1125 printk("cyc: %d: raising DTR\n", __LINE__);
1126 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1131 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1134 local_irq_restore(flags);
1136 } /* config_setup */
1140 cy_put_char(struct tty_struct *tty, unsigned char ch)
1142 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1143 unsigned long flags;
1145 #ifdef SERIAL_DEBUG_IO
1146 printk("cy_put_char %s(0x%02x)\n", tty->name, ch);
1149 if (serial_paranoia_check(info, tty->name, "cy_put_char"))
1152 if (!tty || !info->xmit_buf)
1155 local_irq_save(flags);
1156 if (info->xmit_cnt >= PAGE_SIZE - 1) {
1157 local_irq_restore(flags);
1161 info->xmit_buf[info->xmit_head++] = ch;
1162 info->xmit_head &= PAGE_SIZE - 1;
1164 local_irq_restore(flags);
1169 cy_flush_chars(struct tty_struct *tty)
1171 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1172 unsigned long flags;
1173 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1176 #ifdef SERIAL_DEBUG_IO
1177 printk("cy_flush_chars %s\n", tty->name); /* */
1180 if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
1183 if (info->xmit_cnt <= 0 || tty->stopped
1184 || tty->hw_stopped || !info->xmit_buf)
1187 channel = info->line;
1189 local_irq_save(flags);
1190 base_addr[CyCAR] = channel;
1191 base_addr[CyIER] |= CyTxMpty;
1192 local_irq_restore(flags);
1193 } /* cy_flush_chars */
1196 /* This routine gets called when tty_write has put something into
1197 the write_queue. If the port is not already transmitting stuff,
1198 start it off by enabling interrupts. The interrupt service
1199 routine will then ensure that the characters are sent. If the
1200 port is already active, there is no need to kick it.
1203 cy_write(struct tty_struct * tty,
1204 const unsigned char *buf, int count)
1206 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1207 unsigned long flags;
1210 #ifdef SERIAL_DEBUG_IO
1211 printk("cy_write %s\n", tty->name); /* */
1214 if (serial_paranoia_check(info, tty->name, "cy_write")){
1218 if (!tty || !info->xmit_buf || !tmp_buf){
1223 local_irq_save(flags);
1224 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1225 SERIAL_XMIT_SIZE - info->xmit_head));
1227 local_irq_restore(flags);
1231 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1232 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1233 info->xmit_cnt += c;
1234 local_irq_restore(flags);
1243 && !tty->hw_stopped ) {
1251 cy_write_room(struct tty_struct *tty)
1253 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1256 #ifdef SERIAL_DEBUG_IO
1257 printk("cy_write_room %s\n", tty->name); /* */
1260 if (serial_paranoia_check(info, tty->name, "cy_write_room"))
1262 ret = PAGE_SIZE - info->xmit_cnt - 1;
1266 } /* cy_write_room */
1270 cy_chars_in_buffer(struct tty_struct *tty)
1272 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1274 #ifdef SERIAL_DEBUG_IO
1275 printk("cy_chars_in_buffer %s %d\n", tty->name, info->xmit_cnt); /* */
1278 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
1281 return info->xmit_cnt;
1282 } /* cy_chars_in_buffer */
1286 cy_flush_buffer(struct tty_struct *tty)
1288 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1289 unsigned long flags;
1291 #ifdef SERIAL_DEBUG_IO
1292 printk("cy_flush_buffer %s\n", tty->name); /* */
1295 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
1297 local_irq_save(flags);
1298 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1299 local_irq_restore(flags);
1301 } /* cy_flush_buffer */
1304 /* This routine is called by the upper-layer tty layer to signal
1305 that incoming characters should be throttled or that the
1306 throttle should be released.
1309 cy_throttle(struct tty_struct * tty)
1311 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1312 unsigned long flags;
1313 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1316 #ifdef SERIAL_DEBUG_THROTTLE
1319 printk("throttle %s: %d....\n", tty_name(tty, buf),
1320 tty->ldisc.chars_in_buffer(tty));
1321 printk("cy_throttle %s\n", tty->name);
1324 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")){
1329 info->x_char = STOP_CHAR(tty);
1330 /* Should use the "Send Special Character" feature!!! */
1333 channel = info->line;
1335 local_irq_save(flags);
1336 base_addr[CyCAR] = (u_char)channel;
1337 base_addr[CyMSVR1] = 0;
1338 local_irq_restore(flags);
1345 cy_unthrottle(struct tty_struct * tty)
1347 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1348 unsigned long flags;
1349 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1352 #ifdef SERIAL_DEBUG_THROTTLE
1355 printk("throttle %s: %d....\n", tty_name(tty, buf),
1356 tty->ldisc.chars_in_buffer(tty));
1357 printk("cy_unthrottle %s\n", tty->name);
1360 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")){
1365 info->x_char = START_CHAR(tty);
1366 /* Should use the "Send Special Character" feature!!! */
1369 channel = info->line;
1371 local_irq_save(flags);
1372 base_addr[CyCAR] = (u_char)channel;
1373 base_addr[CyMSVR1] = CyRTS;
1374 local_irq_restore(flags);
1377 } /* cy_unthrottle */
1380 get_serial_info(struct cyclades_port * info,
1381 struct serial_struct * retinfo)
1383 struct serial_struct tmp;
1388 memset(&tmp, 0, sizeof(tmp));
1389 tmp.type = info->type;
1390 tmp.line = info->line;
1391 tmp.port = info->line;
1393 tmp.flags = info->flags;
1394 tmp.baud_base = 0; /*!!!*/
1395 tmp.close_delay = info->close_delay;
1396 tmp.custom_divisor = 0; /*!!!*/
1397 tmp.hub6 = 0; /*!!!*/
1398 return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0;
1399 } /* get_serial_info */
1402 set_serial_info(struct cyclades_port * info,
1403 struct serial_struct * new_info)
1405 struct serial_struct new_serial;
1406 struct cyclades_port old_info;
1411 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
1415 if (!capable(CAP_SYS_ADMIN)) {
1416 if ((new_serial.close_delay != info->close_delay) ||
1417 ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) !=
1418 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK)))
1420 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1421 (new_serial.flags & ASYNC_USR_MASK));
1422 goto check_and_exit;
1427 * OK, past this point, all the error checking has been done.
1428 * At this point, we start making changes.....
1431 info->flags = ((info->flags & ~ASYNC_FLAGS) |
1432 (new_serial.flags & ASYNC_FLAGS));
1433 info->close_delay = new_serial.close_delay;
1437 if (info->flags & ASYNC_INITIALIZED){
1441 return startup(info);
1443 } /* set_serial_info */
1446 cy_tiocmget(struct tty_struct *tty, struct file *file)
1448 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1450 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1451 unsigned long flags;
1452 unsigned char status;
1453 unsigned int result;
1455 channel = info->line;
1457 local_irq_save(flags);
1458 base_addr[CyCAR] = (u_char)channel;
1459 status = base_addr[CyMSVR1] | base_addr[CyMSVR2];
1460 local_irq_restore(flags);
1462 return ((status & CyRTS) ? TIOCM_RTS : 0)
1463 | ((status & CyDTR) ? TIOCM_DTR : 0)
1464 | ((status & CyDCD) ? TIOCM_CAR : 0)
1465 | ((status & CyDSR) ? TIOCM_DSR : 0)
1466 | ((status & CyCTS) ? TIOCM_CTS : 0);
1470 cy_tiocmset(struct tty_struct *tty, struct file *file,
1471 unsigned int set, unsigned int clear)
1473 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1475 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1476 unsigned long flags;
1479 channel = info->line;
1481 if (set & TIOCM_RTS){
1482 local_irq_save(flags);
1483 base_addr[CyCAR] = (u_char)channel;
1484 base_addr[CyMSVR1] = CyRTS;
1485 local_irq_restore(flags);
1487 if (set & TIOCM_DTR){
1488 local_irq_save(flags);
1489 base_addr[CyCAR] = (u_char)channel;
1490 /* CP('S');CP('2'); */
1491 base_addr[CyMSVR2] = CyDTR;
1492 #ifdef SERIAL_DEBUG_DTR
1493 printk("cyc: %d: raising DTR\n", __LINE__);
1494 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1496 local_irq_restore(flags);
1499 if (clear & TIOCM_RTS){
1500 local_irq_save(flags);
1501 base_addr[CyCAR] = (u_char)channel;
1502 base_addr[CyMSVR1] = 0;
1503 local_irq_restore(flags);
1505 if (clear & TIOCM_DTR){
1506 local_irq_save(flags);
1507 base_addr[CyCAR] = (u_char)channel;
1508 /* CP('C');CP('2'); */
1509 base_addr[CyMSVR2] = 0;
1510 #ifdef SERIAL_DEBUG_DTR
1511 printk("cyc: %d: dropping DTR\n", __LINE__);
1512 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1514 local_irq_restore(flags);
1518 } /* set_modem_info */
1521 send_break( struct cyclades_port * info, int duration)
1522 { /* Let the transmit ISR take care of this (since it
1523 requires stuffing characters into the output stream).
1525 info->x_break = duration;
1526 if (!info->xmit_cnt ) {
1532 get_mon_info(struct cyclades_port * info, struct cyclades_monitor * mon)
1535 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
1537 info->mon.int_count = 0;
1538 info->mon.char_count = 0;
1539 info->mon.char_max = 0;
1540 info->mon.char_last = 0;
1545 set_threshold(struct cyclades_port * info, unsigned long *arg)
1547 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1548 unsigned long value;
1551 if (get_user(value, arg))
1554 channel = info->line;
1555 info->cor4 &= ~CyREC_FIFO;
1556 info->cor4 |= value & CyREC_FIFO;
1557 base_addr[CyCOR4] = info->cor4;
1562 get_threshold(struct cyclades_port * info, unsigned long *value)
1564 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1568 channel = info->line;
1570 tmp = base_addr[CyCOR4] & CyREC_FIFO;
1571 return put_user(tmp,value);
1575 set_default_threshold(struct cyclades_port * info, unsigned long *arg)
1577 unsigned long value;
1579 if (get_user(value, arg))
1582 info->default_threshold = value & 0x0f;
1587 get_default_threshold(struct cyclades_port * info, unsigned long *value)
1589 return put_user(info->default_threshold,value);
1593 set_timeout(struct cyclades_port * info, unsigned long *arg)
1595 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1597 unsigned long value;
1599 if (get_user(value, arg))
1602 channel = info->line;
1604 base_addr[CyRTPRL] = value & 0xff;
1605 base_addr[CyRTPRH] = (value >> 8) & 0xff;
1610 get_timeout(struct cyclades_port * info, unsigned long *value)
1612 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1616 channel = info->line;
1618 tmp = base_addr[CyRTPRL];
1619 return put_user(tmp,value);
1623 set_default_timeout(struct cyclades_port * info, unsigned long value)
1625 info->default_timeout = value & 0xff;
1630 get_default_timeout(struct cyclades_port * info, unsigned long *value)
1632 return put_user(info->default_timeout,value);
1636 cy_ioctl(struct tty_struct *tty, struct file * file,
1637 unsigned int cmd, unsigned long arg)
1640 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1643 #ifdef SERIAL_DEBUG_OTHER
1644 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */
1649 ret_val = get_mon_info(info, (struct cyclades_monitor *)arg);
1652 ret_val = get_threshold(info, (unsigned long *)arg);
1655 ret_val = set_threshold(info, (unsigned long *)arg);
1657 case CYGETDEFTHRESH:
1658 ret_val = get_default_threshold(info, (unsigned long *)arg);
1660 case CYSETDEFTHRESH:
1661 ret_val = set_default_threshold(info, (unsigned long *)arg);
1664 ret_val = get_timeout(info, (unsigned long *)arg);
1667 ret_val = set_timeout(info, (unsigned long *)arg);
1669 case CYGETDEFTIMEOUT:
1670 ret_val = get_default_timeout(info, (unsigned long *)arg);
1672 case CYSETDEFTIMEOUT:
1673 ret_val = set_default_timeout(info, (unsigned long)arg);
1675 case TCSBRK: /* SVID version: non-zero arg --> no break */
1676 ret_val = tty_check_change(tty);
1679 tty_wait_until_sent(tty,0);
1681 send_break(info, HZ/4); /* 1/4 second */
1683 case TCSBRKP: /* support for POSIX tcsendbreak() */
1684 ret_val = tty_check_change(tty);
1687 tty_wait_until_sent(tty,0);
1688 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1691 /* The following commands are incompletely implemented!!! */
1693 ret_val = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *) arg);
1696 ret_val = get_user(val, (unsigned long *) arg);
1699 tty->termios->c_cflag =
1700 ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0));
1703 ret_val = get_serial_info(info, (struct serial_struct *) arg);
1706 ret_val = set_serial_info(info,
1707 (struct serial_struct *) arg);
1710 ret_val = -ENOIOCTLCMD;
1713 #ifdef SERIAL_DEBUG_OTHER
1714 printk("cy_ioctl done\n");
1724 cy_set_termios(struct tty_struct *tty, struct termios * old_termios)
1726 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1728 #ifdef SERIAL_DEBUG_OTHER
1729 printk("cy_set_termios %s\n", tty->name);
1732 if (tty->termios->c_cflag == old_termios->c_cflag)
1736 if ((old_termios->c_cflag & CRTSCTS) &&
1737 !(tty->termios->c_cflag & CRTSCTS)) {
1741 #ifdef tytso_patch_94Nov25_1726
1742 if (!(old_termios->c_cflag & CLOCAL) &&
1743 (tty->termios->c_cflag & CLOCAL))
1744 wake_up_interruptible(&info->open_wait);
1748 } /* cy_set_termios */
1752 cy_close(struct tty_struct * tty, struct file * filp)
1754 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1757 #ifdef SERIAL_DEBUG_OTHER
1758 printk("cy_close %s\n", tty->name);
1762 || serial_paranoia_check(info, tty->name, "cy_close")){
1765 #ifdef SERIAL_DEBUG_OPEN
1766 printk("cy_close %s, count = %d\n", tty->name, info->count);
1769 if ((tty->count == 1) && (info->count != 1)) {
1771 * Uh, oh. tty->count is 1, which means that the tty
1772 * structure will be freed. Info->count should always
1773 * be one in these conditions. If it's greater than
1774 * one, we've got real problems, since it means the
1775 * serial port won't be shutdown.
1777 printk("cy_close: bad serial port count; tty->count is 1, "
1778 "info->count is %d\n", info->count);
1781 #ifdef SERIAL_DEBUG_COUNT
1782 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count - 1);
1784 if (--info->count < 0) {
1785 printk("cy_close: bad serial port count for ttys%d: %d\n",
1786 info->line, info->count);
1787 #ifdef SERIAL_DEBUG_COUNT
1788 printk("cyc: %d: setting count to 0\n", __LINE__);
1794 info->flags |= ASYNC_CLOSING;
1795 if (info->flags & ASYNC_INITIALIZED)
1796 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
1798 if (tty->driver->flush_buffer)
1799 tty->driver->flush_buffer(tty);
1800 tty_ldisc_flush(tty);
1803 if (info->blocked_open) {
1804 if (info->close_delay) {
1805 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1807 wake_up_interruptible(&info->open_wait);
1809 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1810 wake_up_interruptible(&info->close_wait);
1812 #ifdef SERIAL_DEBUG_OTHER
1813 printk("cy_close done\n");
1820 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
1823 cy_hangup(struct tty_struct *tty)
1825 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1827 #ifdef SERIAL_DEBUG_OTHER
1828 printk("cy_hangup %s\n", tty->name); /* */
1831 if (serial_paranoia_check(info, tty->name, "cy_hangup"))
1838 #ifdef SERIAL_DEBUG_COUNT
1839 printk("cyc: %d: setting count to 0\n", __LINE__);
1843 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1844 wake_up_interruptible(&info->open_wait);
1850 * ------------------------------------------------------------
1851 * cy_open() and friends
1852 * ------------------------------------------------------------
1856 block_til_ready(struct tty_struct *tty, struct file * filp,
1857 struct cyclades_port *info)
1859 DECLARE_WAITQUEUE(wait, current);
1860 unsigned long flags;
1863 volatile u_char *base_addr = (u_char *)BASE_ADDR;
1866 * If the device is in the middle of being closed, then block
1867 * until it's done, and then try again.
1869 if (info->flags & ASYNC_CLOSING) {
1870 interruptible_sleep_on(&info->close_wait);
1871 if (info->flags & ASYNC_HUP_NOTIFY){
1874 return -ERESTARTSYS;
1879 * If non-blocking mode is set, then make the check up front
1882 if (filp->f_flags & O_NONBLOCK) {
1883 info->flags |= ASYNC_NORMAL_ACTIVE;
1888 * Block waiting for the carrier detect and the line to become
1889 * free (i.e., not in use by the callout). While we are in
1890 * this loop, info->count is dropped by one, so that
1891 * cy_close() knows when to free things. We restore it upon
1892 * exit, either normal or abnormal.
1895 add_wait_queue(&info->open_wait, &wait);
1896 #ifdef SERIAL_DEBUG_OPEN
1897 printk("block_til_ready before block: %s, count = %d\n",
1898 tty->name, info->count);/**/
1901 #ifdef SERIAL_DEBUG_COUNT
1902 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count);
1904 info->blocked_open++;
1906 channel = info->line;
1909 local_irq_save(flags);
1910 base_addr[CyCAR] = (u_char)channel;
1911 base_addr[CyMSVR1] = CyRTS;
1912 /* CP('S');CP('4'); */
1913 base_addr[CyMSVR2] = CyDTR;
1914 #ifdef SERIAL_DEBUG_DTR
1915 printk("cyc: %d: raising DTR\n", __LINE__);
1916 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1918 local_irq_restore(flags);
1919 set_current_state(TASK_INTERRUPTIBLE);
1920 if (tty_hung_up_p(filp)
1921 || !(info->flags & ASYNC_INITIALIZED) ){
1922 if (info->flags & ASYNC_HUP_NOTIFY) {
1925 retval = -ERESTARTSYS;
1929 local_irq_save(flags);
1930 base_addr[CyCAR] = (u_char)channel;
1931 /* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */
1932 if (!(info->flags & ASYNC_CLOSING)
1934 || (base_addr[CyMSVR1] & CyDCD))) {
1935 local_irq_restore(flags);
1938 local_irq_restore(flags);
1939 if (signal_pending(current)) {
1940 retval = -ERESTARTSYS;
1943 #ifdef SERIAL_DEBUG_OPEN
1944 printk("block_til_ready blocking: %s, count = %d\n",
1945 tty->name, info->count);/**/
1949 current->state = TASK_RUNNING;
1950 remove_wait_queue(&info->open_wait, &wait);
1951 if (!tty_hung_up_p(filp)){
1953 #ifdef SERIAL_DEBUG_COUNT
1954 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
1957 info->blocked_open--;
1958 #ifdef SERIAL_DEBUG_OPEN
1959 printk("block_til_ready after blocking: %s, count = %d\n",
1960 tty->name, info->count);/**/
1964 info->flags |= ASYNC_NORMAL_ACTIVE;
1966 } /* block_til_ready */
1969 * This routine is called whenever a serial port is opened. It
1970 * performs the serial-specific initialization for the tty structure.
1973 cy_open(struct tty_struct *tty, struct file * filp)
1975 struct cyclades_port *info;
1980 if ((line < 0) || (NR_PORTS <= line)){
1983 info = &cy_port[line];
1984 if (info->line < 0){
1987 #ifdef SERIAL_DEBUG_OTHER
1988 printk("cy_open %s\n", tty->name); /* */
1990 if (serial_paranoia_check(info, tty->name, "cy_open")){
1993 #ifdef SERIAL_DEBUG_OPEN
1994 printk("cy_open %s, count = %d\n", tty->name, info->count);/**/
1997 #ifdef SERIAL_DEBUG_COUNT
1998 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
2000 tty->driver_data = info;
2004 tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL);
2011 * Start up serial port
2013 retval = startup(info);
2018 retval = block_til_ready(tty, filp, info);
2020 #ifdef SERIAL_DEBUG_OPEN
2021 printk("cy_open returning after block_til_ready with %d\n",
2027 #ifdef SERIAL_DEBUG_OPEN
2028 printk("cy_open done\n");/**/
2036 * ---------------------------------------------------------------------
2037 * serial167_init() and friends
2039 * serial167_init() is called at boot-time to initialize the serial driver.
2040 * ---------------------------------------------------------------------
2044 * This routine prints out the appropriate serial driver version
2045 * number, and identifies which options were configured into this
2051 printk("MVME166/167 cd2401 driver\n");
2052 } /* show_version */
2054 /* initialize chips on card -- return number of valid
2055 chips (which is number of ports/4) */
2058 * This initialises the hardware to a reasonable state. It should
2059 * probe the chip first so as to copy 166-Bug setup as a default for
2060 * port 0. It initialises CMR to CyASYNC; that is never done again, so
2061 * as to limit the number of CyINIT_CHAN commands in normal running.
2063 * ... I wonder what I should do if this fails ...
2067 mvme167_serial_console_setup(int cflag)
2069 volatile unsigned char* base_addr = (u_char *)BASE_ADDR;
2072 u_char rcor, rbpr, badspeed = 0;
2073 unsigned long flags;
2075 local_irq_save(flags);
2078 * First probe channel zero of the chip, to see what speed has
2082 base_addr[CyCAR] = 0;
2084 rcor = base_addr[CyRCOR] << 5;
2085 rbpr = base_addr[CyRBPR];
2087 for (spd = 0; spd < sizeof(baud_bpr); spd++)
2088 if (rbpr == baud_bpr[spd] && rcor == baud_co[spd])
2090 if (spd >= sizeof(baud_bpr)) {
2091 spd = 14; /* 19200 */
2092 badspeed = 1; /* Failed to identify speed */
2094 initial_console_speed = spd;
2096 /* OK, we have chosen a speed, now reset and reinitialise */
2098 my_udelay(20000L); /* Allow time for any active o/p to complete */
2099 if(base_addr[CyCCR] != 0x00){
2100 local_irq_restore(flags);
2101 /* printk(" chip is never idle (CCR != 0)\n"); */
2105 base_addr[CyCCR] = CyCHIP_RESET; /* Reset the chip */
2108 if(base_addr[CyGFRCR] == 0x00){
2109 local_irq_restore(flags);
2110 /* printk(" chip is not responding (GFRCR stayed 0)\n"); */
2115 * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms
2119 base_addr[CyTPR] = 10;
2121 base_addr[CyPILR1] = 0x01; /* Interrupt level for modem change */
2122 base_addr[CyPILR2] = 0x02; /* Interrupt level for tx ints */
2123 base_addr[CyPILR3] = 0x03; /* Interrupt level for rx ints */
2126 * Attempt to set up all channels to something reasonable, and
2127 * bang out a INIT_CHAN command. We should then be able to limit
2128 * the ammount of fiddling we have to do in normal running.
2131 for (ch = 3; ch >= 0 ; ch--) {
2132 base_addr[CyCAR] = (u_char)ch;
2133 base_addr[CyIER] = 0;
2134 base_addr[CyCMR] = CyASYNC;
2135 base_addr[CyLICR] = (u_char)ch << 2;
2136 base_addr[CyLIVR] = 0x5c;
2137 base_addr[CyTCOR] = baud_co[spd];
2138 base_addr[CyTBPR] = baud_bpr[spd];
2139 base_addr[CyRCOR] = baud_co[spd] >> 5;
2140 base_addr[CyRBPR] = baud_bpr[spd];
2141 base_addr[CySCHR1] = 'Q' & 0x1f;
2142 base_addr[CySCHR2] = 'X' & 0x1f;
2143 base_addr[CySCRL] = 0;
2144 base_addr[CySCRH] = 0;
2145 base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
2146 base_addr[CyCOR2] = 0;
2147 base_addr[CyCOR3] = Cy_1_STOP;
2148 base_addr[CyCOR4] = baud_cor4[spd];
2149 base_addr[CyCOR5] = 0;
2150 base_addr[CyCOR6] = 0;
2151 base_addr[CyCOR7] = 0;
2152 base_addr[CyRTPRL] = 2;
2153 base_addr[CyRTPRH] = 0;
2154 base_addr[CyMSVR1] = 0;
2155 base_addr[CyMSVR2] = 0;
2156 write_cy_cmd(base_addr,CyINIT_CHAN|CyDIS_RCVR|CyDIS_XMTR);
2160 * Now do specials for channel zero....
2163 base_addr[CyMSVR1] = CyRTS;
2164 base_addr[CyMSVR2] = CyDTR;
2165 base_addr[CyIER] = CyRxData;
2166 write_cy_cmd(base_addr,CyENB_RCVR|CyENB_XMTR);
2168 local_irq_restore(flags);
2170 my_udelay(20000L); /* Let it all settle down */
2172 printk("CD2401 initialised, chip is rev 0x%02x\n", base_addr[CyGFRCR]);
2174 printk(" WARNING: Failed to identify line speed, rcor=%02x,rbpr=%02x\n",
2176 } /* serial_console_init */
2178 static struct tty_operations cy_ops = {
2182 .put_char = cy_put_char,
2183 .flush_chars = cy_flush_chars,
2184 .write_room = cy_write_room,
2185 .chars_in_buffer = cy_chars_in_buffer,
2186 .flush_buffer = cy_flush_buffer,
2188 .throttle = cy_throttle,
2189 .unthrottle = cy_unthrottle,
2190 .set_termios = cy_set_termios,
2193 .hangup = cy_hangup,
2194 .tiocmget = cy_tiocmget,
2195 .tiocmset = cy_tiocmset,
2197 /* The serial driver boot-time initialization code!
2198 Hardware I/O ports are mapped to character special devices on a
2199 first found, first allocated manner. That is, this code searches
2200 for Cyclom cards in the system. As each is found, it is probed
2201 to discover how many chips (and thus how many ports) are present.
2202 These ports are mapped to the tty ports 64 and upward in monotonic
2203 fashion. If an 8-port card is replaced with a 16-port card, the
2204 port mapping on a following card will shift.
2206 This approach is different from what is used in the other serial
2207 device driver because the Cyclom is more properly a multiplexer,
2208 not just an aggregation of serial ports on one card.
2210 If there are more cards with more ports than have been statically
2211 allocated above, a warning is printed and the extra ports are ignored.
2214 serial167_init(void)
2216 struct cyclades_port *info;
2223 struct sigaction sa;
2226 if (!(mvme16x_config &MVME16x_CONFIG_GOT_CD2401))
2229 cy_serial_driver = alloc_tty_driver(NR_PORTS);
2230 if (!cy_serial_driver)
2239 /* Has "console=0,9600n8" been used in bootinfo to change speed? */
2240 if (serial_console_cflag)
2241 DefSpeed = serial_console_cflag & 0017;
2243 DefSpeed = initial_console_speed;
2244 serial_console_info = &cy_port[0];
2245 serial_console_cflag = DefSpeed | CS8;
2247 serial_console = 64; /*callout_driver.minor_start*/
2251 /* Initialize the tty_driver structure */
2253 cy_serial_driver->owner = THIS_MODULE;
2254 cy_serial_driver->devfs_name = "tts/";
2255 cy_serial_driver->name = "ttyS";
2256 cy_serial_driver->major = TTY_MAJOR;
2257 cy_serial_driver->minor_start = 64;
2258 cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
2259 cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
2260 cy_serial_driver->init_termios = tty_std_termios;
2261 cy_serial_driver->init_termios.c_cflag =
2262 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2263 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
2264 tty_set_operations(cy_serial_driver, &cy_ops);
2266 ret = tty_register_driver(cy_serial_driver);
2268 printk(KERN_ERR "Couldn't register MVME166/7 serial driver\n");
2269 put_tty_driver(cy_serial_driver);
2275 for (index = 0; index < 1; index++) {
2279 if(port_num < NR_PORTS){
2280 while( good_ports-- && port_num < NR_PORTS){
2281 /*** initialize port ***/
2282 info->magic = CYCLADES_MAGIC;
2283 info->type = PORT_CIRRUS;
2285 info->line = port_num;
2286 info->flags = STD_COM_FLAGS;
2288 info->xmit_fifo_size = 12;
2289 info->cor1 = CyPARITY_NONE|Cy_8_BITS;
2291 info->cor3 = Cy_1_STOP;
2292 info->cor4 = 0x08; /* _very_ small receive threshold */
2296 info->tbpr = baud_bpr[DefSpeed]; /* Tx BPR */
2297 info->tco = baud_co[DefSpeed]; /* Tx CO */
2298 info->rbpr = baud_bpr[DefSpeed]; /* Rx BPR */
2299 info->rco = baud_co[DefSpeed] >> 5; /* Rx CO */
2300 info->close_delay = 0;
2304 #ifdef SERIAL_DEBUG_COUNT
2305 printk("cyc: %d: setting count to 0\n", __LINE__);
2307 info->blocked_open = 0;
2308 info->default_threshold = 0;
2309 info->default_timeout = 0;
2310 INIT_WORK(&info->tqueue, do_softint, info);
2311 init_waitqueue_head(&info->open_wait);
2312 init_waitqueue_head(&info->close_wait);
2315 /*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/
2316 info->read_status_mask = CyTIMEOUT| CySPECHAR| CyBREAK
2317 | CyPARITY| CyFRAME| CyOVERRUN;
2320 printk("ttyS%d ", info->line);
2322 if(!(port_num & 7)){
2329 while( port_num < NR_PORTS){
2333 #ifdef CONFIG_REMOTE_DEBUG
2336 ret = request_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt, 0,
2337 "cd2401_errors", cd2401_rxerr_interrupt);
2339 printk(KERN_ERR "Could't get cd2401_errors IRQ");
2340 goto cleanup_serial_driver;
2343 ret = request_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt, 0,
2344 "cd2401_modem", cd2401_modem_interrupt);
2346 printk(KERN_ERR "Could't get cd2401_modem IRQ");
2347 goto cleanup_irq_cd2401_errors;
2350 ret = request_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt, 0,
2351 "cd2401_txints", cd2401_tx_interrupt);
2353 printk(KERN_ERR "Could't get cd2401_txints IRQ");
2354 goto cleanup_irq_cd2401_modem;
2357 ret = request_irq(MVME167_IRQ_SER_RX, cd2401_rx_interrupt, 0,
2358 "cd2401_rxints", cd2401_rx_interrupt);
2360 printk(KERN_ERR "Could't get cd2401_rxints IRQ");
2361 goto cleanup_irq_cd2401_txints;
2364 /* Now we have registered the interrupt handlers, allow the interrupts */
2366 pcc2chip[PccSCCMICR] = 0x15; /* Serial ints are level 5 */
2367 pcc2chip[PccSCCTICR] = 0x15;
2368 pcc2chip[PccSCCRICR] = 0x15;
2370 pcc2chip[PccIMLR] = 3; /* Allow PCC2 ints above 3!? */
2373 cleanup_irq_cd2401_txints:
2374 free_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt);
2375 cleanup_irq_cd2401_modem:
2376 free_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt);
2377 cleanup_irq_cd2401_errors:
2378 free_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt);
2379 cleanup_serial_driver:
2380 if (tty_unregister_driver(cy_serial_driver))
2381 printk(KERN_ERR "Couldn't unregister MVME166/7 serial driver\n");
2382 put_tty_driver(cy_serial_driver);
2384 } /* serial167_init */
2386 module_init(serial167_init);
2389 #ifdef CYCLOM_SHOW_STATUS
2391 show_status(int line_num)
2393 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2395 struct cyclades_port * info;
2396 unsigned long flags;
2398 info = &cy_port[line_num];
2399 channel = info->line;
2400 printk(" channel %d\n", channel);/**/
2402 printk(" cy_port\n");
2403 printk(" card line flags = %d %d %x\n",
2404 info->card, info->line, info->flags);
2405 printk(" *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n",
2406 (long)info->tty, info->read_status_mask,
2407 info->timeout, info->xmit_fifo_size);
2408 printk(" cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n",
2409 info->cor1, info->cor2, info->cor3, info->cor4, info->cor5,
2410 info->cor6, info->cor7);
2411 printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n",
2412 info->tbpr, info->tco, info->rbpr, info->rco);
2413 printk(" close_delay event count = %d %d %d\n",
2414 info->close_delay, info->event, info->count);
2415 printk(" x_char blocked_open = %x %x\n",
2416 info->x_char, info->blocked_open);
2417 printk(" open_wait = %lx %lx %lx\n",
2418 (long)info->open_wait);
2421 local_irq_save(flags);
2423 /* Global Registers */
2425 printk(" CyGFRCR %x\n", base_addr[CyGFRCR]);
2426 printk(" CyCAR %x\n", base_addr[CyCAR]);
2427 printk(" CyRISR %x\n", base_addr[CyRISR]);
2428 printk(" CyTISR %x\n", base_addr[CyTISR]);
2429 printk(" CyMISR %x\n", base_addr[CyMISR]);
2430 printk(" CyRIR %x\n", base_addr[CyRIR]);
2431 printk(" CyTIR %x\n", base_addr[CyTIR]);
2432 printk(" CyMIR %x\n", base_addr[CyMIR]);
2433 printk(" CyTPR %x\n", base_addr[CyTPR]);
2435 base_addr[CyCAR] = (u_char)channel;
2437 /* Virtual Registers */
2440 printk(" CyRIVR %x\n", base_addr[CyRIVR]);
2441 printk(" CyTIVR %x\n", base_addr[CyTIVR]);
2442 printk(" CyMIVR %x\n", base_addr[CyMIVR]);
2443 printk(" CyMISR %x\n", base_addr[CyMISR]);
2446 /* Channel Registers */
2448 printk(" CyCCR %x\n", base_addr[CyCCR]);
2449 printk(" CyIER %x\n", base_addr[CyIER]);
2450 printk(" CyCOR1 %x\n", base_addr[CyCOR1]);
2451 printk(" CyCOR2 %x\n", base_addr[CyCOR2]);
2452 printk(" CyCOR3 %x\n", base_addr[CyCOR3]);
2453 printk(" CyCOR4 %x\n", base_addr[CyCOR4]);
2454 printk(" CyCOR5 %x\n", base_addr[CyCOR5]);
2456 printk(" CyCCSR %x\n", base_addr[CyCCSR]);
2457 printk(" CyRDCR %x\n", base_addr[CyRDCR]);
2459 printk(" CySCHR1 %x\n", base_addr[CySCHR1]);
2460 printk(" CySCHR2 %x\n", base_addr[CySCHR2]);
2462 printk(" CySCHR3 %x\n", base_addr[CySCHR3]);
2463 printk(" CySCHR4 %x\n", base_addr[CySCHR4]);
2464 printk(" CySCRL %x\n", base_addr[CySCRL]);
2465 printk(" CySCRH %x\n", base_addr[CySCRH]);
2466 printk(" CyLNC %x\n", base_addr[CyLNC]);
2467 printk(" CyMCOR1 %x\n", base_addr[CyMCOR1]);
2468 printk(" CyMCOR2 %x\n", base_addr[CyMCOR2]);
2470 printk(" CyRTPRL %x\n", base_addr[CyRTPRL]);
2471 printk(" CyRTPRH %x\n", base_addr[CyRTPRH]);
2472 printk(" CyMSVR1 %x\n", base_addr[CyMSVR1]);
2473 printk(" CyMSVR2 %x\n", base_addr[CyMSVR2]);
2474 printk(" CyRBPR %x\n", base_addr[CyRBPR]);
2475 printk(" CyRCOR %x\n", base_addr[CyRCOR]);
2476 printk(" CyTBPR %x\n", base_addr[CyTBPR]);
2477 printk(" CyTCOR %x\n", base_addr[CyTCOR]);
2479 local_irq_restore(flags);
2485 /* Dummy routine in mvme16x/config.c for now */
2487 /* Serial console setup. Called from linux/init/main.c */
2489 void console_setup(char *str, int *ints)
2492 int baud, bits, parity;
2496 if (ints[0] > 3 || ints[1] > 3) return;
2498 /* Get baud, bits and parity */
2502 if (ints[2]) baud = ints[2];
2503 if ((s = strchr(str, ','))) {
2506 } while(*s >= '0' && *s <= '9');
2507 if (*s) parity = *s++;
2508 if (*s) bits = *s - '0';
2511 /* Now construct a cflag setting. */
2548 serial_console_info = &cy_port[ints[1]];
2549 serial_console_cflag = cflag;
2550 serial_console = ints[1] + 64; /*callout_driver.minor_start*/
2555 * The following is probably out of date for 2.1.x serial console stuff.
2557 * The console is registered early on from arch/m68k/kernel/setup.c, and
2558 * it therefore relies on the chip being setup correctly by 166-Bug. This
2559 * seems reasonable, as the serial port has been used to invoke the system
2560 * boot. It also means that this function must not rely on any data
2561 * initialisation performed by serial167_init() etc.
2563 * Of course, once the console has been registered, we had better ensure
2564 * that serial167_init() doesn't leave the chip non-functional.
2566 * The console must be locked when we get here.
2569 void serial167_console_write(struct console *co, const char *str, unsigned count)
2571 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2572 unsigned long flags;
2573 volatile u_char sink;
2579 local_irq_save(flags);
2581 /* Ensure transmitter is enabled! */
2584 base_addr[CyCAR] = (u_char)port;
2585 while (base_addr[CyCCR])
2587 base_addr[CyCCR] = CyENB_XMTR;
2589 ier = base_addr[CyIER];
2590 base_addr[CyIER] = CyTxMpty;
2593 if (pcc2chip[PccSCCTICR] & 0x20)
2595 /* We have a Tx int. Acknowledge it */
2596 sink = pcc2chip[PccTPIACKR];
2597 if ((base_addr[CyLICR] >> 2) == port) {
2599 /* Last char of string is now output */
2600 base_addr[CyTEOIR] = CyNOTRANS;
2604 base_addr[CyTDR] = '\n';
2609 else if (*str == '\n') {
2610 base_addr[CyTDR] = '\r';
2614 base_addr[CyTDR] = *str++;
2617 base_addr[CyTEOIR] = 0;
2620 base_addr[CyTEOIR] = CyNOTRANS;
2624 base_addr[CyIER] = ier;
2626 local_irq_restore(flags);
2629 static struct tty_driver *serial167_console_device(struct console *c, int *index)
2632 return cy_serial_driver;
2636 static int __init serial167_console_setup(struct console *co, char *options)
2642 static struct console sercons = {
2644 .write = serial167_console_write,
2645 .device = serial167_console_device,
2646 .setup = serial167_console_setup,
2647 .flags = CON_PRINTBUFFER,
2652 static int __init serial167_console_init(void)
2654 if (vme_brdtype == VME_TYPE_MVME166 ||
2655 vme_brdtype == VME_TYPE_MVME167 ||
2656 vme_brdtype == VME_TYPE_MVME177) {
2657 mvme167_serial_console_setup(0);
2658 register_console(&sercons);
2662 console_initcall(serial167_console_init);
2664 #ifdef CONFIG_REMOTE_DEBUG
2665 void putDebugChar (int c)
2667 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2668 unsigned long flags;
2669 volatile u_char sink;
2673 local_irq_save(flags);
2675 /* Ensure transmitter is enabled! */
2678 base_addr[CyCAR] = (u_char)port;
2679 while (base_addr[CyCCR])
2681 base_addr[CyCCR] = CyENB_XMTR;
2683 ier = base_addr[CyIER];
2684 base_addr[CyIER] = CyTxMpty;
2687 if (pcc2chip[PccSCCTICR] & 0x20)
2689 /* We have a Tx int. Acknowledge it */
2690 sink = pcc2chip[PccTPIACKR];
2691 if ((base_addr[CyLICR] >> 2) == port) {
2692 base_addr[CyTDR] = c;
2693 base_addr[CyTEOIR] = 0;
2697 base_addr[CyTEOIR] = CyNOTRANS;
2701 base_addr[CyIER] = ier;
2703 local_irq_restore(flags);
2708 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2709 unsigned long flags;
2710 volatile u_char sink;
2716 if (i != debugiq.in) {
2718 if (++i == DEBUG_LEN)
2723 /* OK, nothing in queue, wait in poll loop */
2725 local_irq_save(flags);
2727 /* Ensure receiver is enabled! */
2730 base_addr[CyCAR] = (u_char)port;
2732 while (base_addr[CyCCR])
2734 base_addr[CyCCR] = CyENB_RCVR;
2736 ier = base_addr[CyIER];
2737 base_addr[CyIER] = CyRxData;
2740 if (pcc2chip[PccSCCRICR] & 0x20)
2742 /* We have a Rx int. Acknowledge it */
2743 sink = pcc2chip[PccRPIACKR];
2744 if ((base_addr[CyLICR] >> 2) == port) {
2745 int cnt = base_addr[CyRFOC];
2748 c = base_addr[CyRDR];
2750 printk ("!! debug char is null (cnt=%d) !!", cnt);
2754 base_addr[CyREOIR] = 0;
2756 if (i == debugiq.in)
2757 panic ("Debug input queue empty!");
2759 if (++i == DEBUG_LEN)
2765 base_addr[CyREOIR] = CyNOTRANS;
2769 base_addr[CyIER] = ier;
2771 local_irq_restore(flags);
2776 void queueDebugChar (int c)
2782 if (++i == DEBUG_LEN)
2784 if (i != debugiq.out)
2791 unsigned long flags;
2792 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
2797 local_irq_save(flags);
2799 for (i = 0; i < 4; i++)
2801 base_addr[CyCAR] = i;
2802 base_addr[CyLICR] = i << 2;
2805 debugiq.in = debugiq.out = 0;
2807 base_addr[CyCAR] = DEBUG_PORT;
2812 base_addr[CyIER] = 0;
2814 base_addr[CyCMR] = CyASYNC;
2815 base_addr[CyLICR] = DEBUG_PORT << 2;
2816 base_addr[CyLIVR] = 0x5c;
2818 /* tx and rx baud rate */
2820 base_addr[CyTCOR] = baud_co[i];
2821 base_addr[CyTBPR] = baud_bpr[i];
2822 base_addr[CyRCOR] = baud_co[i] >> 5;
2823 base_addr[CyRBPR] = baud_bpr[i];
2825 /* set line characteristics according configuration */
2827 base_addr[CySCHR1] = 0;
2828 base_addr[CySCHR2] = 0;
2829 base_addr[CySCRL] = 0;
2830 base_addr[CySCRH] = 0;
2831 base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
2832 base_addr[CyCOR2] = 0;
2833 base_addr[CyCOR3] = Cy_1_STOP;
2834 base_addr[CyCOR4] = baud_cor4[i];
2835 base_addr[CyCOR5] = 0;
2836 base_addr[CyCOR6] = 0;
2837 base_addr[CyCOR7] = 0;
2839 write_cy_cmd(base_addr,CyINIT_CHAN);
2840 write_cy_cmd(base_addr,CyENB_RCVR);
2842 base_addr[CyCAR] = DEBUG_PORT; /* !!! Is this needed? */
2844 base_addr[CyRTPRL] = 2;
2845 base_addr[CyRTPRH] = 0;
2847 base_addr[CyMSVR1] = CyRTS;
2848 base_addr[CyMSVR2] = CyDTR;
2850 base_addr[CyIER] = CyRxData;
2852 local_irq_restore(flags);
2858 MODULE_LICENSE("GPL");