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>
65 #include <linux/tty_flip.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[] = {
121 #define NR_PORTS ARRAY_SIZE(cy_port)
124 * This is used to look up the divisor speeds and the timeouts
125 * We're normally limited to 15 distinct baud rates. The extra
126 * are accessed via settings in info->flags.
127 * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
128 * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
131 static int baud_table[] = {
132 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
133 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200, 150000,
138 static char baud_co[] = { /* 25 MHz clock option table */
139 /* value => 00 01 02 03 04 */
140 /* divide by 8 32 128 512 2048 */
141 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
142 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
145 static char baud_bpr[] = { /* 25 MHz baud rate period table */
146 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
147 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15
151 /* I think 166 brd clocks 2401 at 20MHz.... */
153 /* These values are written directly to tcor, and >> 5 for writing to rcor */
154 static u_char baud_co[] = { /* 20 MHz clock option table */
155 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x60, 0x60, 0x40,
156 0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
159 /* These values written directly to tbpr/rbpr */
160 static u_char baud_bpr[] = { /* 20 MHz baud rate period table */
161 0x00, 0xc0, 0x80, 0x58, 0x6c, 0x40, 0xc0, 0x81, 0x40, 0x81,
162 0x57, 0x40, 0x81, 0x40, 0x81, 0x40, 0x2b, 0x20, 0x15, 0x10
165 static u_char baud_cor4[] = { /* receive threshold */
166 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
167 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07
170 static void shutdown(struct cyclades_port *);
171 static int startup(struct cyclades_port *);
172 static void cy_throttle(struct tty_struct *);
173 static void cy_unthrottle(struct tty_struct *);
174 static void config_setup(struct cyclades_port *);
175 extern void console_print(const char *);
176 #ifdef CYCLOM_SHOW_STATUS
177 static void show_status(int);
180 #ifdef CONFIG_REMOTE_DEBUG
181 static void debug_setup(void);
182 void queueDebugChar(int c);
183 int getDebugChar(void);
186 #define DEBUG_LEN 256
191 unsigned char buf[DEBUG_LEN];
198 * I have my own version of udelay(), as it is needed when initialising
199 * the chip, before the delay loop has been calibrated. Should probably
200 * reference one of the vmechip2 or pccchip2 counter for an accurate
201 * delay, but this wild guess will do for now.
204 void my_udelay(long us)
207 volatile u_char *p = &x;
211 for (i = 100; i; i--)
215 static inline int serial_paranoia_check(struct cyclades_port *info, char *name,
218 #ifdef SERIAL_PARANOIA_CHECK
220 printk("Warning: null cyclades_port for (%s) in %s\n", name,
225 if ((long)info < (long)(&cy_port[0])
226 || (long)(&cy_port[NR_PORTS]) < (long)info) {
227 printk("Warning: cyclades_port out of range for (%s) in %s\n",
232 if (info->magic != CYCLADES_MAGIC) {
233 printk("Warning: bad magic number for serial struct (%s) in "
234 "%s\n", name, routine);
239 } /* serial_paranoia_check */
242 /* The following diagnostic routines allow the driver to spew
243 information on the screen, even (especially!) during interrupts.
248 local_irq_save(flags);
250 local_irq_restore(flags);
257 local_irq_save(flags);
260 local_irq_restore(flags);
265 (data < 10) ? CP(data + '0') : CP(data + 'A' - 10);
269 CP1((data >> 4) & 0x0f);
274 CP2((data >> 8) & 0xff);
279 CP4((data >> 16) & 0xffff);
284 /* This routine waits up to 1000 micro-seconds for the previous
285 command to the Cirrus chip to complete and then issues the
286 new command. An error is returned if the previous command
287 didn't finish within the time limit.
289 u_short write_cy_cmd(volatile u_char * base_addr, u_char cmd)
294 local_irq_save(flags);
295 /* Check to see that the previous command has completed */
296 for (i = 0; i < 100; i++) {
297 if (base_addr[CyCCR] == 0) {
302 /* if the CCR never cleared, the previous command
303 didn't finish within the "reasonable time" */
305 local_irq_restore(flags);
309 /* Issue the new command */
310 base_addr[CyCCR] = cmd;
311 local_irq_restore(flags);
315 /* cy_start and cy_stop provide software output flow control as a
316 function of XON/XOFF, software CTS, and other such stuff. */
318 static void cy_stop(struct tty_struct *tty)
320 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
321 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
325 #ifdef SERIAL_DEBUG_OTHER
326 printk("cy_stop %s\n", tty->name); /* */
329 if (serial_paranoia_check(info, tty->name, "cy_stop"))
332 channel = info->line;
334 local_irq_save(flags);
335 base_addr[CyCAR] = (u_char) (channel); /* index channel */
336 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
337 local_irq_restore(flags);
340 static void cy_start(struct tty_struct *tty)
342 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
343 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
347 #ifdef SERIAL_DEBUG_OTHER
348 printk("cy_start %s\n", tty->name); /* */
351 if (serial_paranoia_check(info, tty->name, "cy_start"))
354 channel = info->line;
356 local_irq_save(flags);
357 base_addr[CyCAR] = (u_char) (channel);
358 base_addr[CyIER] |= CyTxMpty;
359 local_irq_restore(flags);
363 * This routine is used by the interrupt handler to schedule
364 * processing in the software interrupt portion of the driver
365 * (also known as the "bottom half"). This can be called any
366 * number of times for any channel without harm.
368 static inline void cy_sched_event(struct cyclades_port *info, int event)
370 info->event |= 1 << event; /* remember what kind of event and who */
371 schedule_work(&info->tqueue);
372 } /* cy_sched_event */
374 /* The real interrupt service routines are called
375 whenever the card wants its hand held--chars
376 received, out buffer empty, modem change, etc.
378 static irqreturn_t cd2401_rxerr_interrupt(int irq, void *dev_id)
380 struct tty_struct *tty;
381 struct cyclades_port *info;
382 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
383 unsigned char err, rfoc;
387 /* determine the channel and change to that context */
388 channel = (u_short) (base_addr[CyLICR] >> 2);
389 info = &cy_port[channel];
390 info->last_active = jiffies;
392 if ((err = base_addr[CyRISR]) & CyTIMEOUT) {
393 /* This is a receive timeout interrupt, ignore it */
394 base_addr[CyREOIR] = CyNOTRANS;
398 /* Read a byte of data if there is any - assume the error
399 * is associated with this character */
401 if ((rfoc = base_addr[CyRFOC]) != 0)
402 data = base_addr[CyRDR];
406 /* if there is nowhere to put the data, discard it */
407 if (info->tty == 0) {
408 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
410 } else { /* there is an open port for this data */
412 if (err & info->ignore_status_mask) {
413 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
416 if (tty_buffer_request_room(tty, 1) != 0) {
417 if (err & info->read_status_mask) {
419 tty_insert_flip_char(tty, data,
421 if (info->flags & ASYNC_SAK) {
424 } else if (err & CyFRAME) {
425 tty_insert_flip_char(tty, data,
427 } else if (err & CyPARITY) {
428 tty_insert_flip_char(tty, data,
430 } else if (err & CyOVERRUN) {
431 tty_insert_flip_char(tty, 0,
434 If the flip buffer itself is
435 overflowing, we still loose
436 the next incoming character.
438 if (tty_buffer_request_room(tty, 1) !=
440 tty_insert_flip_char(tty, data,
443 /* These two conditions may imply */
444 /* a normal read should be done. */
445 /* else if(data & CyTIMEOUT) */
446 /* else if(data & CySPECHAR) */
448 tty_insert_flip_char(tty, 0,
452 tty_insert_flip_char(tty, data, TTY_NORMAL);
455 /* there was a software buffer overrun
456 and nothing could be done about it!!! */
459 tty_schedule_flip(tty);
461 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
463 } /* cy_rxerr_interrupt */
465 static irqreturn_t cd2401_modem_interrupt(int irq, void *dev_id)
467 struct cyclades_port *info;
468 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
473 /* determine the channel and change to that context */
474 channel = (u_short) (base_addr[CyLICR] >> 2);
475 info = &cy_port[channel];
476 info->last_active = jiffies;
478 mdm_change = base_addr[CyMISR];
479 mdm_status = base_addr[CyMSVR1];
481 if (info->tty == 0) { /* nowhere to put the data, ignore it */
484 if ((mdm_change & CyDCD)
485 && (info->flags & ASYNC_CHECK_CD)) {
486 if (mdm_status & CyDCD) {
488 cy_sched_event(info, Cy_EVENT_OPEN_WAKEUP);
491 cy_sched_event(info, Cy_EVENT_HANGUP);
494 if ((mdm_change & CyCTS)
495 && (info->flags & ASYNC_CTS_FLOW)) {
496 if (info->tty->stopped) {
497 if (mdm_status & CyCTS) {
498 /* !!! cy_start isn't used because... */
499 info->tty->stopped = 0;
500 base_addr[CyIER] |= CyTxMpty;
502 Cy_EVENT_WRITE_WAKEUP);
505 if (!(mdm_status & CyCTS)) {
506 /* !!! cy_stop isn't used because... */
507 info->tty->stopped = 1;
509 ~(CyTxMpty | CyTxRdy);
513 if (mdm_status & CyDSR) {
516 base_addr[CyMEOIR] = 0;
518 } /* cy_modem_interrupt */
520 static irqreturn_t cd2401_tx_interrupt(int irq, void *dev_id)
522 struct cyclades_port *info;
523 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
525 int char_count, saved_cnt;
528 /* determine the channel and change to that context */
529 channel = (u_short) (base_addr[CyLICR] >> 2);
531 #ifdef CONFIG_REMOTE_DEBUG
532 if (channel == DEBUG_PORT) {
533 panic("TxInt on debug port!!!");
537 info = &cy_port[channel];
539 /* validate the port number (as configured and open) */
540 if ((channel < 0) || (NR_PORTS <= channel)) {
541 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
542 base_addr[CyTEOIR] = CyNOTRANS;
545 info->last_active = jiffies;
546 if (info->tty == 0) {
547 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
548 if (info->xmit_cnt < WAKEUP_CHARS) {
549 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
551 base_addr[CyTEOIR] = CyNOTRANS;
555 /* load the on-chip space available for outbound data */
556 saved_cnt = char_count = base_addr[CyTFTC];
558 if (info->x_char) { /* send special char */
559 outch = info->x_char;
560 base_addr[CyTDR] = outch;
566 /* The Cirrus chip requires the "Embedded Transmit
567 Commands" of start break, delay, and end break
568 sequences to be sent. The duration of the
569 break is given in TICs, which runs at HZ
570 (typically 100) and the PPR runs at 200 Hz,
571 so the delay is duration * 200/HZ, and thus a
572 break can run from 1/100 sec to about 5/4 sec.
573 Need to check these values - RGH 141095.
575 base_addr[CyTDR] = 0; /* start break */
576 base_addr[CyTDR] = 0x81;
577 base_addr[CyTDR] = 0; /* delay a bit */
578 base_addr[CyTDR] = 0x82;
579 base_addr[CyTDR] = info->x_break * 200 / HZ;
580 base_addr[CyTDR] = 0; /* terminate break */
581 base_addr[CyTDR] = 0x83;
586 while (char_count > 0) {
587 if (!info->xmit_cnt) {
588 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
591 if (info->xmit_buf == 0) {
592 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
595 if (info->tty->stopped || info->tty->hw_stopped) {
596 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
599 /* Because the Embedded Transmit Commands have been
600 enabled, we must check to see if the escape
601 character, NULL, is being sent. If it is, we
602 must ensure that there is room for it to be
603 doubled in the output stream. Therefore we
604 no longer advance the pointer when the character
605 is fetched, but rather wait until after the check
606 for a NULL output character. (This is necessary
607 because there may not be room for the two chars
608 needed to send a NULL.
610 outch = info->xmit_buf[info->xmit_tail];
613 info->xmit_tail = (info->xmit_tail + 1)
615 base_addr[CyTDR] = outch;
618 if (char_count > 1) {
620 info->xmit_tail = (info->xmit_tail + 1)
622 base_addr[CyTDR] = outch;
623 base_addr[CyTDR] = 0;
632 if (info->xmit_cnt < WAKEUP_CHARS) {
633 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
635 base_addr[CyTEOIR] = (char_count != saved_cnt) ? 0 : CyNOTRANS;
637 } /* cy_tx_interrupt */
639 static irqreturn_t cd2401_rx_interrupt(int irq, void *dev_id)
641 struct tty_struct *tty;
642 struct cyclades_port *info;
643 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
650 /* determine the channel and change to that context */
651 channel = (u_short) (base_addr[CyLICR] >> 2);
652 info = &cy_port[channel];
653 info->last_active = jiffies;
654 save_cnt = char_count = base_addr[CyRFOC];
656 #ifdef CONFIG_REMOTE_DEBUG
657 if (channel == DEBUG_PORT) {
658 while (char_count--) {
659 data = base_addr[CyRDR];
660 queueDebugChar(data);
664 /* if there is nowhere to put the data, discard it */
665 if (info->tty == 0) {
666 while (char_count--) {
667 data = base_addr[CyRDR];
669 } else { /* there is an open port for this data */
671 /* load # characters available from the chip */
673 #ifdef CYCLOM_ENABLE_MONITORING
674 ++info->mon.int_count;
675 info->mon.char_count += char_count;
676 if (char_count > info->mon.char_max)
677 info->mon.char_max = char_count;
678 info->mon.char_last = char_count;
680 len = tty_buffer_request_room(tty, char_count);
682 data = base_addr[CyRDR];
683 tty_insert_flip_char(tty, data, TTY_NORMAL);
684 #ifdef CYCLOM_16Y_HACK
688 tty_schedule_flip(tty);
691 base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS;
693 } /* cy_rx_interrupt */
696 * This routine is used to handle the "bottom half" processing for the
697 * serial driver, known also the "software interrupt" processing.
698 * This processing is done at the kernel interrupt level, after the
699 * cy#/_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
700 * is where time-consuming activities which can not be done in the
701 * interrupt driver proper are done; the interrupt driver schedules
702 * them using cy_sched_event(), and they get done here.
704 * This is done through one level of indirection--the task queue.
705 * When a hardware interrupt service routine wants service by the
706 * driver's bottom half, it enqueues the appropriate tq_struct (one
707 * per port) to the keventd work queue and sets a request flag
708 * that the work queue be processed.
710 * Although this may seem unwieldy, it gives the system a way to
711 * pass an argument (in this case the pointer to the cyclades_port
712 * structure) to the bottom half of the driver. Previous kernels
713 * had to poll every port to see if that port needed servicing.
715 static void do_softint(struct work_struct *ugly_api)
717 struct cyclades_port *info =
718 container_of(ugly_api, struct cyclades_port, tqueue);
719 struct tty_struct *tty;
725 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
726 tty_hangup(info->tty);
727 wake_up_interruptible(&info->open_wait);
728 info->flags &= ~ASYNC_NORMAL_ACTIVE;
730 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) {
731 wake_up_interruptible(&info->open_wait);
733 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
738 /* This is called whenever a port becomes active;
739 interrupts are enabled and DTR & RTS are turned on.
741 static int startup(struct cyclades_port *info)
744 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
747 if (info->flags & ASYNC_INITIALIZED) {
753 set_bit(TTY_IO_ERROR, &info->tty->flags);
757 if (!info->xmit_buf) {
758 info->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL);
759 if (!info->xmit_buf) {
766 channel = info->line;
768 #ifdef SERIAL_DEBUG_OPEN
769 printk("startup channel %d\n", channel);
772 local_irq_save(flags);
773 base_addr[CyCAR] = (u_char) channel;
774 write_cy_cmd(base_addr, CyENB_RCVR | CyENB_XMTR);
776 base_addr[CyCAR] = (u_char) channel; /* !!! Is this needed? */
777 base_addr[CyMSVR1] = CyRTS;
778 /* CP('S');CP('1'); */
779 base_addr[CyMSVR2] = CyDTR;
781 #ifdef SERIAL_DEBUG_DTR
782 printk("cyc: %d: raising DTR\n", __LINE__);
783 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
787 base_addr[CyIER] |= CyRxData;
788 info->flags |= ASYNC_INITIALIZED;
791 clear_bit(TTY_IO_ERROR, &info->tty->flags);
793 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
795 local_irq_restore(flags);
797 #ifdef SERIAL_DEBUG_OPEN
803 void start_xmit(struct cyclades_port *info)
806 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
809 channel = info->line;
810 local_irq_save(flags);
811 base_addr[CyCAR] = channel;
812 base_addr[CyIER] |= CyTxMpty;
813 local_irq_restore(flags);
817 * This routine shuts down a serial port; interrupts are disabled,
818 * and DTR is dropped if the hangup on close termio flag is on.
820 static void shutdown(struct cyclades_port *info)
823 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
826 if (!(info->flags & ASYNC_INITIALIZED)) {
831 channel = info->line;
833 #ifdef SERIAL_DEBUG_OPEN
834 printk("shutdown channel %d\n", channel);
837 /* !!! REALLY MUST WAIT FOR LAST CHARACTER TO BE
838 SENT BEFORE DROPPING THE LINE !!! (Perhaps
839 set some flag that is read when XMTY happens.)
840 Other choices are to delay some fixed interval
841 or schedule some later processing.
843 local_irq_save(flags);
844 if (info->xmit_buf) {
845 free_page((unsigned long)info->xmit_buf);
846 info->xmit_buf = NULL;
849 base_addr[CyCAR] = (u_char) channel;
850 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
851 base_addr[CyMSVR1] = 0;
852 /* CP('C');CP('1'); */
853 base_addr[CyMSVR2] = 0;
854 #ifdef SERIAL_DEBUG_DTR
855 printk("cyc: %d: dropping DTR\n", __LINE__);
856 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
860 write_cy_cmd(base_addr, CyDIS_RCVR);
861 /* it may be appropriate to clear _XMIT at
862 some later date (after testing)!!! */
865 set_bit(TTY_IO_ERROR, &info->tty->flags);
867 info->flags &= ~ASYNC_INITIALIZED;
868 local_irq_restore(flags);
870 #ifdef SERIAL_DEBUG_OPEN
876 * This routine finds or computes the various line characteristics.
878 static void config_setup(struct cyclades_port *info)
881 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
885 unsigned char ti, need_init_chan = 0;
887 if (!info->tty || !info->tty->termios) {
890 if (info->line == -1) {
893 cflag = info->tty->termios->c_cflag;
898 /* Starting with kernel 1.1.65, there is direct support for
899 higher baud rates. The following code supports those
900 changes. The conditional aspect allows this driver to be
901 used for earlier as well as later kernel versions. (The
902 mapping is slightly different from serial.c because there
903 is still the possibility of supporting 75 kbit/sec with
909 else if (i == B115200)
912 else if (i == B78600)
916 info->tty->termios->c_cflag &= ~CBAUDEX;
920 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
922 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
925 /* Don't ever change the speed of the console port. It will
926 * run at the speed specified in bootinfo, or at 19.2K */
927 /* Actually, it should run at whatever speed 166Bug was using */
928 /* Note info->timeout isn't used at present */
929 if (info != serial_console_info) {
930 info->tbpr = baud_bpr[i]; /* Tx BPR */
931 info->tco = baud_co[i]; /* Tx CO */
932 info->rbpr = baud_bpr[i]; /* Rx BPR */
933 info->rco = baud_co[i] >> 5; /* Rx CO */
934 if (baud_table[i] == 134) {
936 (info->xmit_fifo_size * HZ * 30 / 269) + 2;
937 /* get it right for 134.5 baud */
938 } else if (baud_table[i]) {
940 (info->xmit_fifo_size * HZ * 15 / baud_table[i]) +
942 /* this needs to be propagated into the card info */
947 /* By tradition (is it a standard?) a baud rate of zero
948 implies the line should be/has been closed. A bit
949 later in this routine such a test is performed. */
951 /* byte size and parity */
955 info->cor4 = (info->default_threshold ? info->default_threshold : baud_cor4[i]); /* receive threshold */
956 /* Following two lines added 101295, RGH. */
957 /* It is obviously wrong to access CyCORx, and not info->corx here,
958 * try and remember to fix it later! */
959 channel = info->line;
960 base_addr[CyCAR] = (u_char) channel;
961 if (C_CLOCAL(info->tty)) {
962 if (base_addr[CyIER] & CyMdmCh)
963 base_addr[CyIER] &= ~CyMdmCh; /* without modem intr */
964 /* ignore 1->0 modem transitions */
965 if (base_addr[CyCOR4] & (CyDSR | CyCTS | CyDCD))
966 base_addr[CyCOR4] &= ~(CyDSR | CyCTS | CyDCD);
967 /* ignore 0->1 modem transitions */
968 if (base_addr[CyCOR5] & (CyDSR | CyCTS | CyDCD))
969 base_addr[CyCOR5] &= ~(CyDSR | CyCTS | CyDCD);
971 if ((base_addr[CyIER] & CyMdmCh) != CyMdmCh)
972 base_addr[CyIER] |= CyMdmCh; /* with modem intr */
973 /* act on 1->0 modem transitions */
974 if ((base_addr[CyCOR4] & (CyDSR | CyCTS | CyDCD)) !=
975 (CyDSR | CyCTS | CyDCD))
976 base_addr[CyCOR4] |= CyDSR | CyCTS | CyDCD;
977 /* act on 0->1 modem transitions */
978 if ((base_addr[CyCOR5] & (CyDSR | CyCTS | CyDCD)) !=
979 (CyDSR | CyCTS | CyDCD))
980 base_addr[CyCOR5] |= CyDSR | CyCTS | CyDCD;
982 info->cor3 = (cflag & CSTOPB) ? Cy_2_STOP : Cy_1_STOP;
984 switch (cflag & CSIZE) {
986 info->cor1 = Cy_5_BITS;
989 info->cor1 = Cy_6_BITS;
992 info->cor1 = Cy_7_BITS;
995 info->cor1 = Cy_8_BITS;
998 if (cflag & PARENB) {
999 if (cflag & PARODD) {
1000 info->cor1 |= CyPARITY_O;
1002 info->cor1 |= CyPARITY_E;
1005 info->cor1 |= CyPARITY_NONE;
1008 /* CTS flow control flag */
1010 /* Don't complcate matters for now! RGH 141095 */
1011 if (cflag & CRTSCTS) {
1012 info->flags |= ASYNC_CTS_FLOW;
1013 info->cor2 |= CyCtsAE;
1015 info->flags &= ~ASYNC_CTS_FLOW;
1016 info->cor2 &= ~CyCtsAE;
1020 info->flags &= ~ASYNC_CHECK_CD;
1022 info->flags |= ASYNC_CHECK_CD;
1024 /***********************************************
1025 The hardware option, CyRtsAO, presents RTS when
1026 the chip has characters to send. Since most modems
1027 use RTS as reverse (inbound) flow control, this
1028 option is not used. If inbound flow control is
1029 necessary, DTR can be programmed to provide the
1030 appropriate signals for use with a non-standard
1031 cable. Contact Marcio Saito for details.
1032 ***********************************************/
1034 channel = info->line;
1036 local_irq_save(flags);
1037 base_addr[CyCAR] = (u_char) channel;
1039 /* CyCMR set once only in mvme167_init_serial() */
1040 if (base_addr[CyLICR] != channel << 2)
1041 base_addr[CyLICR] = channel << 2;
1042 if (base_addr[CyLIVR] != 0x5c)
1043 base_addr[CyLIVR] = 0x5c;
1045 /* tx and rx baud rate */
1047 if (base_addr[CyCOR1] != info->cor1)
1049 if (base_addr[CyTCOR] != info->tco)
1050 base_addr[CyTCOR] = info->tco;
1051 if (base_addr[CyTBPR] != info->tbpr)
1052 base_addr[CyTBPR] = info->tbpr;
1053 if (base_addr[CyRCOR] != info->rco)
1054 base_addr[CyRCOR] = info->rco;
1055 if (base_addr[CyRBPR] != info->rbpr)
1056 base_addr[CyRBPR] = info->rbpr;
1058 /* set line characteristics according configuration */
1060 if (base_addr[CySCHR1] != START_CHAR(info->tty))
1061 base_addr[CySCHR1] = START_CHAR(info->tty);
1062 if (base_addr[CySCHR2] != STOP_CHAR(info->tty))
1063 base_addr[CySCHR2] = STOP_CHAR(info->tty);
1064 if (base_addr[CySCRL] != START_CHAR(info->tty))
1065 base_addr[CySCRL] = START_CHAR(info->tty);
1066 if (base_addr[CySCRH] != START_CHAR(info->tty))
1067 base_addr[CySCRH] = START_CHAR(info->tty);
1068 if (base_addr[CyCOR1] != info->cor1)
1069 base_addr[CyCOR1] = info->cor1;
1070 if (base_addr[CyCOR2] != info->cor2)
1071 base_addr[CyCOR2] = info->cor2;
1072 if (base_addr[CyCOR3] != info->cor3)
1073 base_addr[CyCOR3] = info->cor3;
1074 if (base_addr[CyCOR4] != info->cor4)
1075 base_addr[CyCOR4] = info->cor4;
1076 if (base_addr[CyCOR5] != info->cor5)
1077 base_addr[CyCOR5] = info->cor5;
1078 if (base_addr[CyCOR6] != info->cor6)
1079 base_addr[CyCOR6] = info->cor6;
1080 if (base_addr[CyCOR7] != info->cor7)
1081 base_addr[CyCOR7] = info->cor7;
1084 write_cy_cmd(base_addr, CyINIT_CHAN);
1086 base_addr[CyCAR] = (u_char) channel; /* !!! Is this needed? */
1088 /* 2ms default rx timeout */
1089 ti = info->default_timeout ? info->default_timeout : 0x02;
1090 if (base_addr[CyRTPRL] != ti)
1091 base_addr[CyRTPRL] = ti;
1092 if (base_addr[CyRTPRH] != 0)
1093 base_addr[CyRTPRH] = 0;
1095 /* Set up RTS here also ????? RGH 141095 */
1096 if (i == 0) { /* baud rate is zero, turn off line */
1097 if ((base_addr[CyMSVR2] & CyDTR) == CyDTR)
1098 base_addr[CyMSVR2] = 0;
1099 #ifdef SERIAL_DEBUG_DTR
1100 printk("cyc: %d: dropping DTR\n", __LINE__);
1101 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
1102 base_addr[CyMSVR2]);
1105 if ((base_addr[CyMSVR2] & CyDTR) != CyDTR)
1106 base_addr[CyMSVR2] = CyDTR;
1107 #ifdef SERIAL_DEBUG_DTR
1108 printk("cyc: %d: raising DTR\n", __LINE__);
1109 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
1110 base_addr[CyMSVR2]);
1115 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1118 local_irq_restore(flags);
1120 } /* config_setup */
1122 static void cy_put_char(struct tty_struct *tty, unsigned char ch)
1124 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1125 unsigned long flags;
1127 #ifdef SERIAL_DEBUG_IO
1128 printk("cy_put_char %s(0x%02x)\n", tty->name, ch);
1131 if (serial_paranoia_check(info, tty->name, "cy_put_char"))
1134 if (!info->xmit_buf)
1137 local_irq_save(flags);
1138 if (info->xmit_cnt >= PAGE_SIZE - 1) {
1139 local_irq_restore(flags);
1143 info->xmit_buf[info->xmit_head++] = ch;
1144 info->xmit_head &= PAGE_SIZE - 1;
1146 local_irq_restore(flags);
1149 static void cy_flush_chars(struct tty_struct *tty)
1151 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1152 unsigned long flags;
1153 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1156 #ifdef SERIAL_DEBUG_IO
1157 printk("cy_flush_chars %s\n", tty->name); /* */
1160 if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
1163 if (info->xmit_cnt <= 0 || tty->stopped
1164 || tty->hw_stopped || !info->xmit_buf)
1167 channel = info->line;
1169 local_irq_save(flags);
1170 base_addr[CyCAR] = channel;
1171 base_addr[CyIER] |= CyTxMpty;
1172 local_irq_restore(flags);
1173 } /* cy_flush_chars */
1175 /* This routine gets called when tty_write has put something into
1176 the write_queue. If the port is not already transmitting stuff,
1177 start it off by enabling interrupts. The interrupt service
1178 routine will then ensure that the characters are sent. If the
1179 port is already active, there is no need to kick it.
1181 static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
1183 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1184 unsigned long flags;
1187 #ifdef SERIAL_DEBUG_IO
1188 printk("cy_write %s\n", tty->name); /* */
1191 if (serial_paranoia_check(info, tty->name, "cy_write")) {
1195 if (!info->xmit_buf) {
1200 local_irq_save(flags);
1201 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1202 SERIAL_XMIT_SIZE - info->xmit_head));
1204 local_irq_restore(flags);
1208 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1210 (info->xmit_head + c) & (SERIAL_XMIT_SIZE - 1);
1211 info->xmit_cnt += c;
1212 local_irq_restore(flags);
1219 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
1225 static int cy_write_room(struct tty_struct *tty)
1227 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1230 #ifdef SERIAL_DEBUG_IO
1231 printk("cy_write_room %s\n", tty->name); /* */
1234 if (serial_paranoia_check(info, tty->name, "cy_write_room"))
1236 ret = PAGE_SIZE - info->xmit_cnt - 1;
1240 } /* cy_write_room */
1242 static int 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 */
1256 static void cy_flush_buffer(struct tty_struct *tty)
1258 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1259 unsigned long flags;
1261 #ifdef SERIAL_DEBUG_IO
1262 printk("cy_flush_buffer %s\n", tty->name); /* */
1265 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
1267 local_irq_save(flags);
1268 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1269 local_irq_restore(flags);
1271 } /* cy_flush_buffer */
1273 /* This routine is called by the upper-layer tty layer to signal
1274 that incoming characters should be throttled or that the
1275 throttle should be released.
1277 static void cy_throttle(struct tty_struct *tty)
1279 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1280 unsigned long flags;
1281 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1284 #ifdef SERIAL_DEBUG_THROTTLE
1287 printk("throttle %s: %d....\n", tty_name(tty, buf),
1288 tty->ldisc.chars_in_buffer(tty));
1289 printk("cy_throttle %s\n", tty->name);
1292 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")) {
1297 info->x_char = STOP_CHAR(tty);
1298 /* Should use the "Send Special Character" feature!!! */
1301 channel = info->line;
1303 local_irq_save(flags);
1304 base_addr[CyCAR] = (u_char) channel;
1305 base_addr[CyMSVR1] = 0;
1306 local_irq_restore(flags);
1309 static void cy_unthrottle(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_unthrottle %s\n", tty->name);
1324 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")) {
1329 info->x_char = START_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] = CyRTS;
1338 local_irq_restore(flags);
1339 } /* cy_unthrottle */
1342 get_serial_info(struct cyclades_port *info,
1343 struct serial_struct __user * retinfo)
1345 struct serial_struct tmp;
1350 memset(&tmp, 0, sizeof(tmp));
1351 tmp.type = info->type;
1352 tmp.line = info->line;
1353 tmp.port = info->line;
1355 tmp.flags = info->flags;
1356 tmp.baud_base = 0; /*!!! */
1357 tmp.close_delay = info->close_delay;
1358 tmp.custom_divisor = 0; /*!!! */
1359 tmp.hub6 = 0; /*!!! */
1360 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
1361 } /* get_serial_info */
1364 set_serial_info(struct cyclades_port *info,
1365 struct serial_struct __user * new_info)
1367 struct serial_struct new_serial;
1368 struct cyclades_port old_info;
1373 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
1377 if (!capable(CAP_SYS_ADMIN)) {
1378 if ((new_serial.close_delay != info->close_delay) ||
1379 ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) !=
1380 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK)))
1382 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1383 (new_serial.flags & ASYNC_USR_MASK));
1384 goto check_and_exit;
1388 * OK, past this point, all the error checking has been done.
1389 * At this point, we start making changes.....
1392 info->flags = ((info->flags & ~ASYNC_FLAGS) |
1393 (new_serial.flags & ASYNC_FLAGS));
1394 info->close_delay = new_serial.close_delay;
1397 if (info->flags & ASYNC_INITIALIZED) {
1401 return startup(info);
1402 } /* set_serial_info */
1404 static int cy_tiocmget(struct tty_struct *tty, struct file *file)
1406 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1408 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1409 unsigned long flags;
1410 unsigned char status;
1412 channel = info->line;
1414 local_irq_save(flags);
1415 base_addr[CyCAR] = (u_char) channel;
1416 status = base_addr[CyMSVR1] | base_addr[CyMSVR2];
1417 local_irq_restore(flags);
1419 return ((status & CyRTS) ? TIOCM_RTS : 0)
1420 | ((status & CyDTR) ? TIOCM_DTR : 0)
1421 | ((status & CyDCD) ? TIOCM_CAR : 0)
1422 | ((status & CyDSR) ? TIOCM_DSR : 0)
1423 | ((status & CyCTS) ? TIOCM_CTS : 0);
1427 cy_tiocmset(struct tty_struct *tty, struct file *file,
1428 unsigned int set, unsigned int clear)
1430 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1432 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1433 unsigned long flags;
1435 channel = info->line;
1437 if (set & TIOCM_RTS) {
1438 local_irq_save(flags);
1439 base_addr[CyCAR] = (u_char) channel;
1440 base_addr[CyMSVR1] = CyRTS;
1441 local_irq_restore(flags);
1443 if (set & TIOCM_DTR) {
1444 local_irq_save(flags);
1445 base_addr[CyCAR] = (u_char) channel;
1446 /* CP('S');CP('2'); */
1447 base_addr[CyMSVR2] = CyDTR;
1448 #ifdef SERIAL_DEBUG_DTR
1449 printk("cyc: %d: raising DTR\n", __LINE__);
1450 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
1451 base_addr[CyMSVR2]);
1453 local_irq_restore(flags);
1456 if (clear & TIOCM_RTS) {
1457 local_irq_save(flags);
1458 base_addr[CyCAR] = (u_char) channel;
1459 base_addr[CyMSVR1] = 0;
1460 local_irq_restore(flags);
1462 if (clear & TIOCM_DTR) {
1463 local_irq_save(flags);
1464 base_addr[CyCAR] = (u_char) channel;
1465 /* CP('C');CP('2'); */
1466 base_addr[CyMSVR2] = 0;
1467 #ifdef SERIAL_DEBUG_DTR
1468 printk("cyc: %d: dropping DTR\n", __LINE__);
1469 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
1470 base_addr[CyMSVR2]);
1472 local_irq_restore(flags);
1476 } /* set_modem_info */
1478 static void send_break(struct cyclades_port *info, int duration)
1479 { /* Let the transmit ISR take care of this (since it
1480 requires stuffing characters into the output stream).
1482 info->x_break = duration;
1483 if (!info->xmit_cnt) {
1489 get_mon_info(struct cyclades_port *info, struct cyclades_monitor __user * mon)
1492 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
1494 info->mon.int_count = 0;
1495 info->mon.char_count = 0;
1496 info->mon.char_max = 0;
1497 info->mon.char_last = 0;
1501 static int set_threshold(struct cyclades_port *info, unsigned long __user * arg)
1503 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1504 unsigned long value;
1507 if (get_user(value, arg))
1510 channel = info->line;
1511 info->cor4 &= ~CyREC_FIFO;
1512 info->cor4 |= value & CyREC_FIFO;
1513 base_addr[CyCOR4] = info->cor4;
1518 get_threshold(struct cyclades_port *info, unsigned long __user * value)
1520 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1524 channel = info->line;
1526 tmp = base_addr[CyCOR4] & CyREC_FIFO;
1527 return put_user(tmp, value);
1531 set_default_threshold(struct cyclades_port *info, unsigned long __user * arg)
1533 unsigned long value;
1535 if (get_user(value, arg))
1538 info->default_threshold = value & 0x0f;
1543 get_default_threshold(struct cyclades_port *info, unsigned long __user * value)
1545 return put_user(info->default_threshold, value);
1548 static int set_timeout(struct cyclades_port *info, unsigned long __user * arg)
1550 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1552 unsigned long value;
1554 if (get_user(value, arg))
1557 channel = info->line;
1559 base_addr[CyRTPRL] = value & 0xff;
1560 base_addr[CyRTPRH] = (value >> 8) & 0xff;
1564 static int get_timeout(struct cyclades_port *info, unsigned long __user * value)
1566 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1570 channel = info->line;
1572 tmp = base_addr[CyRTPRL];
1573 return put_user(tmp, value);
1576 static int set_default_timeout(struct cyclades_port *info, unsigned long value)
1578 info->default_timeout = value & 0xff;
1583 get_default_timeout(struct cyclades_port *info, unsigned long __user * value)
1585 return put_user(info->default_timeout, value);
1589 cy_ioctl(struct tty_struct *tty, struct file *file,
1590 unsigned int cmd, unsigned long arg)
1593 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1595 void __user *argp = (void __user *)arg;
1597 #ifdef SERIAL_DEBUG_OTHER
1598 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */
1603 ret_val = get_mon_info(info, argp);
1606 ret_val = get_threshold(info, argp);
1609 ret_val = set_threshold(info, argp);
1611 case CYGETDEFTHRESH:
1612 ret_val = get_default_threshold(info, argp);
1614 case CYSETDEFTHRESH:
1615 ret_val = set_default_threshold(info, argp);
1618 ret_val = get_timeout(info, argp);
1621 ret_val = set_timeout(info, argp);
1623 case CYGETDEFTIMEOUT:
1624 ret_val = get_default_timeout(info, argp);
1626 case CYSETDEFTIMEOUT:
1627 ret_val = set_default_timeout(info, (unsigned long)arg);
1629 case TCSBRK: /* SVID version: non-zero arg --> no break */
1630 ret_val = tty_check_change(tty);
1633 tty_wait_until_sent(tty, 0);
1635 send_break(info, HZ / 4); /* 1/4 second */
1637 case TCSBRKP: /* support for POSIX tcsendbreak() */
1638 ret_val = tty_check_change(tty);
1641 tty_wait_until_sent(tty, 0);
1642 send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1645 /* The following commands are incompletely implemented!!! */
1648 put_user(C_CLOCAL(tty) ? 1 : 0,
1649 (unsigned long __user *)argp);
1652 ret_val = get_user(val, (unsigned long __user *)argp);
1655 tty->termios->c_cflag =
1656 ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0));
1659 ret_val = get_serial_info(info, argp);
1662 ret_val = set_serial_info(info, argp);
1665 ret_val = -ENOIOCTLCMD;
1668 #ifdef SERIAL_DEBUG_OTHER
1669 printk("cy_ioctl done\n");
1675 static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1677 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1679 #ifdef SERIAL_DEBUG_OTHER
1680 printk("cy_set_termios %s\n", tty->name);
1683 if (tty->termios->c_cflag == old_termios->c_cflag)
1687 if ((old_termios->c_cflag & CRTSCTS) &&
1688 !(tty->termios->c_cflag & CRTSCTS)) {
1692 #ifdef tytso_patch_94Nov25_1726
1693 if (!(old_termios->c_cflag & CLOCAL) &&
1694 (tty->termios->c_cflag & CLOCAL))
1695 wake_up_interruptible(&info->open_wait);
1697 } /* cy_set_termios */
1699 static void cy_close(struct tty_struct *tty, struct file *filp)
1701 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1704 #ifdef SERIAL_DEBUG_OTHER
1705 printk("cy_close %s\n", tty->name);
1708 if (!info || serial_paranoia_check(info, tty->name, "cy_close")) {
1711 #ifdef SERIAL_DEBUG_OPEN
1712 printk("cy_close %s, count = %d\n", tty->name, info->count);
1715 if ((tty->count == 1) && (info->count != 1)) {
1717 * Uh, oh. tty->count is 1, which means that the tty
1718 * structure will be freed. Info->count should always
1719 * be one in these conditions. If it's greater than
1720 * one, we've got real problems, since it means the
1721 * serial port won't be shutdown.
1723 printk("cy_close: bad serial port count; tty->count is 1, "
1724 "info->count is %d\n", info->count);
1727 #ifdef SERIAL_DEBUG_COUNT
1728 printk("cyc: %d: decrementing count to %d\n", __LINE__,
1731 if (--info->count < 0) {
1732 printk("cy_close: bad serial port count for ttys%d: %d\n",
1733 info->line, info->count);
1734 #ifdef SERIAL_DEBUG_COUNT
1735 printk("cyc: %d: setting count to 0\n", __LINE__);
1741 info->flags |= ASYNC_CLOSING;
1742 if (info->flags & ASYNC_INITIALIZED)
1743 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
1745 if (tty->driver->flush_buffer)
1746 tty->driver->flush_buffer(tty);
1747 tty_ldisc_flush(tty);
1750 if (info->blocked_open) {
1751 if (info->close_delay) {
1752 msleep_interruptible(jiffies_to_msecs
1753 (info->close_delay));
1755 wake_up_interruptible(&info->open_wait);
1757 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1758 wake_up_interruptible(&info->close_wait);
1760 #ifdef SERIAL_DEBUG_OTHER
1761 printk("cy_close done\n");
1766 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
1768 void cy_hangup(struct tty_struct *tty)
1770 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1772 #ifdef SERIAL_DEBUG_OTHER
1773 printk("cy_hangup %s\n", tty->name); /* */
1776 if (serial_paranoia_check(info, tty->name, "cy_hangup"))
1783 #ifdef SERIAL_DEBUG_COUNT
1784 printk("cyc: %d: setting count to 0\n", __LINE__);
1788 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1789 wake_up_interruptible(&info->open_wait);
1793 * ------------------------------------------------------------
1794 * cy_open() and friends
1795 * ------------------------------------------------------------
1799 block_til_ready(struct tty_struct *tty, struct file *filp,
1800 struct cyclades_port *info)
1802 DECLARE_WAITQUEUE(wait, current);
1803 unsigned long flags;
1806 volatile u_char *base_addr = (u_char *) BASE_ADDR;
1809 * If the device is in the middle of being closed, then block
1810 * until it's done, and then try again.
1812 if (info->flags & ASYNC_CLOSING) {
1813 interruptible_sleep_on(&info->close_wait);
1814 if (info->flags & ASYNC_HUP_NOTIFY) {
1817 return -ERESTARTSYS;
1822 * If non-blocking mode is set, then make the check up front
1825 if (filp->f_flags & O_NONBLOCK) {
1826 info->flags |= ASYNC_NORMAL_ACTIVE;
1831 * Block waiting for the carrier detect and the line to become
1832 * free (i.e., not in use by the callout). While we are in
1833 * this loop, info->count is dropped by one, so that
1834 * cy_close() knows when to free things. We restore it upon
1835 * exit, either normal or abnormal.
1838 add_wait_queue(&info->open_wait, &wait);
1839 #ifdef SERIAL_DEBUG_OPEN
1840 printk("block_til_ready before block: %s, count = %d\n",
1841 tty->name, info->count);
1845 #ifdef SERIAL_DEBUG_COUNT
1846 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count);
1848 info->blocked_open++;
1850 channel = info->line;
1853 local_irq_save(flags);
1854 base_addr[CyCAR] = (u_char) channel;
1855 base_addr[CyMSVR1] = CyRTS;
1856 /* CP('S');CP('4'); */
1857 base_addr[CyMSVR2] = CyDTR;
1858 #ifdef SERIAL_DEBUG_DTR
1859 printk("cyc: %d: raising DTR\n", __LINE__);
1860 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
1861 base_addr[CyMSVR2]);
1863 local_irq_restore(flags);
1864 set_current_state(TASK_INTERRUPTIBLE);
1865 if (tty_hung_up_p(filp)
1866 || !(info->flags & ASYNC_INITIALIZED)) {
1867 if (info->flags & ASYNC_HUP_NOTIFY) {
1870 retval = -ERESTARTSYS;
1874 local_irq_save(flags);
1875 base_addr[CyCAR] = (u_char) channel;
1876 /* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */
1877 if (!(info->flags & ASYNC_CLOSING)
1879 || (base_addr[CyMSVR1] & CyDCD))) {
1880 local_irq_restore(flags);
1883 local_irq_restore(flags);
1884 if (signal_pending(current)) {
1885 retval = -ERESTARTSYS;
1888 #ifdef SERIAL_DEBUG_OPEN
1889 printk("block_til_ready blocking: %s, count = %d\n",
1890 tty->name, info->count);
1895 __set_current_state(TASK_RUNNING);
1896 remove_wait_queue(&info->open_wait, &wait);
1897 if (!tty_hung_up_p(filp)) {
1899 #ifdef SERIAL_DEBUG_COUNT
1900 printk("cyc: %d: incrementing count to %d\n", __LINE__,
1904 info->blocked_open--;
1905 #ifdef SERIAL_DEBUG_OPEN
1906 printk("block_til_ready after blocking: %s, count = %d\n",
1907 tty->name, info->count);
1912 info->flags |= ASYNC_NORMAL_ACTIVE;
1914 } /* block_til_ready */
1917 * This routine is called whenever a serial port is opened. It
1918 * performs the serial-specific initialization for the tty structure.
1920 int cy_open(struct tty_struct *tty, struct file *filp)
1922 struct cyclades_port *info;
1927 if ((line < 0) || (NR_PORTS <= line)) {
1930 info = &cy_port[line];
1931 if (info->line < 0) {
1934 #ifdef SERIAL_DEBUG_OTHER
1935 printk("cy_open %s\n", tty->name); /* */
1937 if (serial_paranoia_check(info, tty->name, "cy_open")) {
1940 #ifdef SERIAL_DEBUG_OPEN
1941 printk("cy_open %s, count = %d\n", tty->name, info->count);
1945 #ifdef SERIAL_DEBUG_COUNT
1946 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
1948 tty->driver_data = info;
1952 * Start up serial port
1954 retval = startup(info);
1959 retval = block_til_ready(tty, filp, info);
1961 #ifdef SERIAL_DEBUG_OPEN
1962 printk("cy_open returning after block_til_ready with %d\n",
1967 #ifdef SERIAL_DEBUG_OPEN
1968 printk("cy_open done\n");
1975 * ---------------------------------------------------------------------
1976 * serial167_init() and friends
1978 * serial167_init() is called at boot-time to initialize the serial driver.
1979 * ---------------------------------------------------------------------
1983 * This routine prints out the appropriate serial driver version
1984 * number, and identifies which options were configured into this
1987 static void show_version(void)
1989 printk("MVME166/167 cd2401 driver\n");
1990 } /* show_version */
1992 /* initialize chips on card -- return number of valid
1993 chips (which is number of ports/4) */
1996 * This initialises the hardware to a reasonable state. It should
1997 * probe the chip first so as to copy 166-Bug setup as a default for
1998 * port 0. It initialises CMR to CyASYNC; that is never done again, so
1999 * as to limit the number of CyINIT_CHAN commands in normal running.
2001 * ... I wonder what I should do if this fails ...
2004 void mvme167_serial_console_setup(int cflag)
2006 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2009 u_char rcor, rbpr, badspeed = 0;
2010 unsigned long flags;
2012 local_irq_save(flags);
2015 * First probe channel zero of the chip, to see what speed has
2019 base_addr[CyCAR] = 0;
2021 rcor = base_addr[CyRCOR] << 5;
2022 rbpr = base_addr[CyRBPR];
2024 for (spd = 0; spd < sizeof(baud_bpr); spd++)
2025 if (rbpr == baud_bpr[spd] && rcor == baud_co[spd])
2027 if (spd >= sizeof(baud_bpr)) {
2028 spd = 14; /* 19200 */
2029 badspeed = 1; /* Failed to identify speed */
2031 initial_console_speed = spd;
2033 /* OK, we have chosen a speed, now reset and reinitialise */
2035 my_udelay(20000L); /* Allow time for any active o/p to complete */
2036 if (base_addr[CyCCR] != 0x00) {
2037 local_irq_restore(flags);
2038 /* printk(" chip is never idle (CCR != 0)\n"); */
2042 base_addr[CyCCR] = CyCHIP_RESET; /* Reset the chip */
2045 if (base_addr[CyGFRCR] == 0x00) {
2046 local_irq_restore(flags);
2047 /* printk(" chip is not responding (GFRCR stayed 0)\n"); */
2052 * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms
2056 base_addr[CyTPR] = 10;
2058 base_addr[CyPILR1] = 0x01; /* Interrupt level for modem change */
2059 base_addr[CyPILR2] = 0x02; /* Interrupt level for tx ints */
2060 base_addr[CyPILR3] = 0x03; /* Interrupt level for rx ints */
2063 * Attempt to set up all channels to something reasonable, and
2064 * bang out a INIT_CHAN command. We should then be able to limit
2065 * the ammount of fiddling we have to do in normal running.
2068 for (ch = 3; ch >= 0; ch--) {
2069 base_addr[CyCAR] = (u_char) ch;
2070 base_addr[CyIER] = 0;
2071 base_addr[CyCMR] = CyASYNC;
2072 base_addr[CyLICR] = (u_char) ch << 2;
2073 base_addr[CyLIVR] = 0x5c;
2074 base_addr[CyTCOR] = baud_co[spd];
2075 base_addr[CyTBPR] = baud_bpr[spd];
2076 base_addr[CyRCOR] = baud_co[spd] >> 5;
2077 base_addr[CyRBPR] = baud_bpr[spd];
2078 base_addr[CySCHR1] = 'Q' & 0x1f;
2079 base_addr[CySCHR2] = 'X' & 0x1f;
2080 base_addr[CySCRL] = 0;
2081 base_addr[CySCRH] = 0;
2082 base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
2083 base_addr[CyCOR2] = 0;
2084 base_addr[CyCOR3] = Cy_1_STOP;
2085 base_addr[CyCOR4] = baud_cor4[spd];
2086 base_addr[CyCOR5] = 0;
2087 base_addr[CyCOR6] = 0;
2088 base_addr[CyCOR7] = 0;
2089 base_addr[CyRTPRL] = 2;
2090 base_addr[CyRTPRH] = 0;
2091 base_addr[CyMSVR1] = 0;
2092 base_addr[CyMSVR2] = 0;
2093 write_cy_cmd(base_addr, CyINIT_CHAN | CyDIS_RCVR | CyDIS_XMTR);
2097 * Now do specials for channel zero....
2100 base_addr[CyMSVR1] = CyRTS;
2101 base_addr[CyMSVR2] = CyDTR;
2102 base_addr[CyIER] = CyRxData;
2103 write_cy_cmd(base_addr, CyENB_RCVR | CyENB_XMTR);
2105 local_irq_restore(flags);
2107 my_udelay(20000L); /* Let it all settle down */
2109 printk("CD2401 initialised, chip is rev 0x%02x\n", base_addr[CyGFRCR]);
2112 (" WARNING: Failed to identify line speed, rcor=%02x,rbpr=%02x\n",
2114 } /* serial_console_init */
2116 static const struct tty_operations cy_ops = {
2120 .put_char = cy_put_char,
2121 .flush_chars = cy_flush_chars,
2122 .write_room = cy_write_room,
2123 .chars_in_buffer = cy_chars_in_buffer,
2124 .flush_buffer = cy_flush_buffer,
2126 .throttle = cy_throttle,
2127 .unthrottle = cy_unthrottle,
2128 .set_termios = cy_set_termios,
2131 .hangup = cy_hangup,
2132 .tiocmget = cy_tiocmget,
2133 .tiocmset = cy_tiocmset,
2136 /* The serial driver boot-time initialization code!
2137 Hardware I/O ports are mapped to character special devices on a
2138 first found, first allocated manner. That is, this code searches
2139 for Cyclom cards in the system. As each is found, it is probed
2140 to discover how many chips (and thus how many ports) are present.
2141 These ports are mapped to the tty ports 64 and upward in monotonic
2142 fashion. If an 8-port card is replaced with a 16-port card, the
2143 port mapping on a following card will shift.
2145 This approach is different from what is used in the other serial
2146 device driver because the Cyclom is more properly a multiplexer,
2147 not just an aggregation of serial ports on one card.
2149 If there are more cards with more ports than have been statically
2150 allocated above, a warning is printed and the extra ports are ignored.
2152 static int __init serial167_init(void)
2154 struct cyclades_port *info;
2161 struct sigaction sa;
2164 if (!(mvme16x_config & MVME16x_CONFIG_GOT_CD2401))
2167 cy_serial_driver = alloc_tty_driver(NR_PORTS);
2168 if (!cy_serial_driver)
2177 /* Has "console=0,9600n8" been used in bootinfo to change speed? */
2178 if (serial_console_cflag)
2179 DefSpeed = serial_console_cflag & 0017;
2181 DefSpeed = initial_console_speed;
2182 serial_console_info = &cy_port[0];
2183 serial_console_cflag = DefSpeed | CS8;
2185 serial_console = 64; /*callout_driver.minor_start */
2189 /* Initialize the tty_driver structure */
2191 cy_serial_driver->owner = THIS_MODULE;
2192 cy_serial_driver->name = "ttyS";
2193 cy_serial_driver->major = TTY_MAJOR;
2194 cy_serial_driver->minor_start = 64;
2195 cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
2196 cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
2197 cy_serial_driver->init_termios = tty_std_termios;
2198 cy_serial_driver->init_termios.c_cflag =
2199 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2200 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
2201 tty_set_operations(cy_serial_driver, &cy_ops);
2203 ret = tty_register_driver(cy_serial_driver);
2205 printk(KERN_ERR "Couldn't register MVME166/7 serial driver\n");
2206 put_tty_driver(cy_serial_driver);
2212 for (index = 0; index < 1; index++) {
2216 if (port_num < NR_PORTS) {
2217 while (good_ports-- && port_num < NR_PORTS) {
2218 /*** initialize port ***/
2219 info->magic = CYCLADES_MAGIC;
2220 info->type = PORT_CIRRUS;
2222 info->line = port_num;
2223 info->flags = STD_COM_FLAGS;
2225 info->xmit_fifo_size = 12;
2226 info->cor1 = CyPARITY_NONE | Cy_8_BITS;
2228 info->cor3 = Cy_1_STOP;
2229 info->cor4 = 0x08; /* _very_ small receive threshold */
2233 info->tbpr = baud_bpr[DefSpeed]; /* Tx BPR */
2234 info->tco = baud_co[DefSpeed]; /* Tx CO */
2235 info->rbpr = baud_bpr[DefSpeed]; /* Rx BPR */
2236 info->rco = baud_co[DefSpeed] >> 5; /* Rx CO */
2237 info->close_delay = 0;
2241 #ifdef SERIAL_DEBUG_COUNT
2242 printk("cyc: %d: setting count to 0\n",
2245 info->blocked_open = 0;
2246 info->default_threshold = 0;
2247 info->default_timeout = 0;
2248 INIT_WORK(&info->tqueue, do_softint);
2249 init_waitqueue_head(&info->open_wait);
2250 init_waitqueue_head(&info->close_wait);
2253 /*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/
2254 info->read_status_mask =
2255 CyTIMEOUT | CySPECHAR | CyBREAK | CyPARITY |
2256 CyFRAME | CyOVERRUN;
2259 printk("ttyS%d ", info->line);
2262 if (!(port_num & 7)) {
2269 while (port_num < NR_PORTS) {
2274 #ifdef CONFIG_REMOTE_DEBUG
2277 ret = request_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt, 0,
2278 "cd2401_errors", cd2401_rxerr_interrupt);
2280 printk(KERN_ERR "Could't get cd2401_errors IRQ");
2281 goto cleanup_serial_driver;
2284 ret = request_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt, 0,
2285 "cd2401_modem", cd2401_modem_interrupt);
2287 printk(KERN_ERR "Could't get cd2401_modem IRQ");
2288 goto cleanup_irq_cd2401_errors;
2291 ret = request_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt, 0,
2292 "cd2401_txints", cd2401_tx_interrupt);
2294 printk(KERN_ERR "Could't get cd2401_txints IRQ");
2295 goto cleanup_irq_cd2401_modem;
2298 ret = request_irq(MVME167_IRQ_SER_RX, cd2401_rx_interrupt, 0,
2299 "cd2401_rxints", cd2401_rx_interrupt);
2301 printk(KERN_ERR "Could't get cd2401_rxints IRQ");
2302 goto cleanup_irq_cd2401_txints;
2305 /* Now we have registered the interrupt handlers, allow the interrupts */
2307 pcc2chip[PccSCCMICR] = 0x15; /* Serial ints are level 5 */
2308 pcc2chip[PccSCCTICR] = 0x15;
2309 pcc2chip[PccSCCRICR] = 0x15;
2311 pcc2chip[PccIMLR] = 3; /* Allow PCC2 ints above 3!? */
2314 cleanup_irq_cd2401_txints:
2315 free_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt);
2316 cleanup_irq_cd2401_modem:
2317 free_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt);
2318 cleanup_irq_cd2401_errors:
2319 free_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt);
2320 cleanup_serial_driver:
2321 if (tty_unregister_driver(cy_serial_driver))
2323 "Couldn't unregister MVME166/7 serial driver\n");
2324 put_tty_driver(cy_serial_driver);
2326 } /* serial167_init */
2328 module_init(serial167_init);
2330 #ifdef CYCLOM_SHOW_STATUS
2331 static void show_status(int line_num)
2333 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2335 struct cyclades_port *info;
2336 unsigned long flags;
2338 info = &cy_port[line_num];
2339 channel = info->line;
2340 printk(" channel %d\n", channel);
2341 /**/ printk(" cy_port\n");
2342 printk(" card line flags = %d %d %x\n",
2343 info->card, info->line, info->flags);
2345 (" *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n",
2346 (long)info->tty, info->read_status_mask, info->timeout,
2347 info->xmit_fifo_size);
2348 printk(" cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n",
2349 info->cor1, info->cor2, info->cor3, info->cor4, info->cor5,
2350 info->cor6, info->cor7);
2351 printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n", info->tbpr, info->tco,
2352 info->rbpr, info->rco);
2353 printk(" close_delay event count = %d %d %d\n", info->close_delay,
2354 info->event, info->count);
2355 printk(" x_char blocked_open = %x %x\n", info->x_char,
2356 info->blocked_open);
2357 printk(" open_wait = %lx %lx %lx\n", (long)info->open_wait);
2359 local_irq_save(flags);
2361 /* Global Registers */
2363 printk(" CyGFRCR %x\n", base_addr[CyGFRCR]);
2364 printk(" CyCAR %x\n", base_addr[CyCAR]);
2365 printk(" CyRISR %x\n", base_addr[CyRISR]);
2366 printk(" CyTISR %x\n", base_addr[CyTISR]);
2367 printk(" CyMISR %x\n", base_addr[CyMISR]);
2368 printk(" CyRIR %x\n", base_addr[CyRIR]);
2369 printk(" CyTIR %x\n", base_addr[CyTIR]);
2370 printk(" CyMIR %x\n", base_addr[CyMIR]);
2371 printk(" CyTPR %x\n", base_addr[CyTPR]);
2373 base_addr[CyCAR] = (u_char) channel;
2375 /* Virtual Registers */
2378 printk(" CyRIVR %x\n", base_addr[CyRIVR]);
2379 printk(" CyTIVR %x\n", base_addr[CyTIVR]);
2380 printk(" CyMIVR %x\n", base_addr[CyMIVR]);
2381 printk(" CyMISR %x\n", base_addr[CyMISR]);
2384 /* Channel Registers */
2386 printk(" CyCCR %x\n", base_addr[CyCCR]);
2387 printk(" CyIER %x\n", base_addr[CyIER]);
2388 printk(" CyCOR1 %x\n", base_addr[CyCOR1]);
2389 printk(" CyCOR2 %x\n", base_addr[CyCOR2]);
2390 printk(" CyCOR3 %x\n", base_addr[CyCOR3]);
2391 printk(" CyCOR4 %x\n", base_addr[CyCOR4]);
2392 printk(" CyCOR5 %x\n", base_addr[CyCOR5]);
2394 printk(" CyCCSR %x\n", base_addr[CyCCSR]);
2395 printk(" CyRDCR %x\n", base_addr[CyRDCR]);
2397 printk(" CySCHR1 %x\n", base_addr[CySCHR1]);
2398 printk(" CySCHR2 %x\n", base_addr[CySCHR2]);
2400 printk(" CySCHR3 %x\n", base_addr[CySCHR3]);
2401 printk(" CySCHR4 %x\n", base_addr[CySCHR4]);
2402 printk(" CySCRL %x\n", base_addr[CySCRL]);
2403 printk(" CySCRH %x\n", base_addr[CySCRH]);
2404 printk(" CyLNC %x\n", base_addr[CyLNC]);
2405 printk(" CyMCOR1 %x\n", base_addr[CyMCOR1]);
2406 printk(" CyMCOR2 %x\n", base_addr[CyMCOR2]);
2408 printk(" CyRTPRL %x\n", base_addr[CyRTPRL]);
2409 printk(" CyRTPRH %x\n", base_addr[CyRTPRH]);
2410 printk(" CyMSVR1 %x\n", base_addr[CyMSVR1]);
2411 printk(" CyMSVR2 %x\n", base_addr[CyMSVR2]);
2412 printk(" CyRBPR %x\n", base_addr[CyRBPR]);
2413 printk(" CyRCOR %x\n", base_addr[CyRCOR]);
2414 printk(" CyTBPR %x\n", base_addr[CyTBPR]);
2415 printk(" CyTCOR %x\n", base_addr[CyTCOR]);
2417 local_irq_restore(flags);
2422 /* Dummy routine in mvme16x/config.c for now */
2424 /* Serial console setup. Called from linux/init/main.c */
2426 void console_setup(char *str, int *ints)
2429 int baud, bits, parity;
2433 if (ints[0] > 3 || ints[1] > 3)
2436 /* Get baud, bits and parity */
2442 if ((s = strchr(str, ','))) {
2445 } while (*s >= '0' && *s <= '9');
2452 /* Now construct a cflag setting. */
2491 serial_console_info = &cy_port[ints[1]];
2492 serial_console_cflag = cflag;
2493 serial_console = ints[1] + 64; /*callout_driver.minor_start */
2498 * The following is probably out of date for 2.1.x serial console stuff.
2500 * The console is registered early on from arch/m68k/kernel/setup.c, and
2501 * it therefore relies on the chip being setup correctly by 166-Bug. This
2502 * seems reasonable, as the serial port has been used to invoke the system
2503 * boot. It also means that this function must not rely on any data
2504 * initialisation performed by serial167_init() etc.
2506 * Of course, once the console has been registered, we had better ensure
2507 * that serial167_init() doesn't leave the chip non-functional.
2509 * The console must be locked when we get here.
2512 void serial167_console_write(struct console *co, const char *str,
2515 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2516 unsigned long flags;
2517 volatile u_char sink;
2523 local_irq_save(flags);
2525 /* Ensure transmitter is enabled! */
2528 base_addr[CyCAR] = (u_char) port;
2529 while (base_addr[CyCCR])
2531 base_addr[CyCCR] = CyENB_XMTR;
2533 ier = base_addr[CyIER];
2534 base_addr[CyIER] = CyTxMpty;
2537 if (pcc2chip[PccSCCTICR] & 0x20) {
2538 /* We have a Tx int. Acknowledge it */
2539 sink = pcc2chip[PccTPIACKR];
2540 if ((base_addr[CyLICR] >> 2) == port) {
2542 /* Last char of string is now output */
2543 base_addr[CyTEOIR] = CyNOTRANS;
2547 base_addr[CyTDR] = '\n';
2551 } else if (*str == '\n') {
2552 base_addr[CyTDR] = '\r';
2555 base_addr[CyTDR] = *str++;
2558 base_addr[CyTEOIR] = 0;
2560 base_addr[CyTEOIR] = CyNOTRANS;
2564 base_addr[CyIER] = ier;
2566 local_irq_restore(flags);
2569 static struct tty_driver *serial167_console_device(struct console *c,
2573 return cy_serial_driver;
2576 static struct console sercons = {
2578 .write = serial167_console_write,
2579 .device = serial167_console_device,
2580 .flags = CON_PRINTBUFFER,
2584 static int __init serial167_console_init(void)
2586 if (vme_brdtype == VME_TYPE_MVME166 ||
2587 vme_brdtype == VME_TYPE_MVME167 ||
2588 vme_brdtype == VME_TYPE_MVME177) {
2589 mvme167_serial_console_setup(0);
2590 register_console(&sercons);
2595 console_initcall(serial167_console_init);
2597 #ifdef CONFIG_REMOTE_DEBUG
2598 void putDebugChar(int c)
2600 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2601 unsigned long flags;
2602 volatile u_char sink;
2606 local_irq_save(flags);
2608 /* Ensure transmitter is enabled! */
2611 base_addr[CyCAR] = (u_char) port;
2612 while (base_addr[CyCCR])
2614 base_addr[CyCCR] = CyENB_XMTR;
2616 ier = base_addr[CyIER];
2617 base_addr[CyIER] = CyTxMpty;
2620 if (pcc2chip[PccSCCTICR] & 0x20) {
2621 /* We have a Tx int. Acknowledge it */
2622 sink = pcc2chip[PccTPIACKR];
2623 if ((base_addr[CyLICR] >> 2) == port) {
2624 base_addr[CyTDR] = c;
2625 base_addr[CyTEOIR] = 0;
2628 base_addr[CyTEOIR] = CyNOTRANS;
2632 base_addr[CyIER] = ier;
2634 local_irq_restore(flags);
2639 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2640 unsigned long flags;
2641 volatile u_char sink;
2647 if (i != debugiq.in) {
2649 if (++i == DEBUG_LEN)
2654 /* OK, nothing in queue, wait in poll loop */
2656 local_irq_save(flags);
2658 /* Ensure receiver is enabled! */
2661 base_addr[CyCAR] = (u_char) port;
2663 while (base_addr[CyCCR])
2665 base_addr[CyCCR] = CyENB_RCVR;
2667 ier = base_addr[CyIER];
2668 base_addr[CyIER] = CyRxData;
2671 if (pcc2chip[PccSCCRICR] & 0x20) {
2672 /* We have a Rx int. Acknowledge it */
2673 sink = pcc2chip[PccRPIACKR];
2674 if ((base_addr[CyLICR] >> 2) == port) {
2675 int cnt = base_addr[CyRFOC];
2677 c = base_addr[CyRDR];
2680 ("!! debug char is null (cnt=%d) !!",
2685 base_addr[CyREOIR] = 0;
2687 if (i == debugiq.in)
2688 panic("Debug input queue empty!");
2690 if (++i == DEBUG_LEN)
2695 base_addr[CyREOIR] = CyNOTRANS;
2699 base_addr[CyIER] = ier;
2701 local_irq_restore(flags);
2706 void queueDebugChar(int c)
2712 if (++i == DEBUG_LEN)
2714 if (i != debugiq.out)
2718 static void debug_setup()
2720 unsigned long flags;
2721 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2726 local_irq_save(flags);
2728 for (i = 0; i < 4; i++) {
2729 base_addr[CyCAR] = i;
2730 base_addr[CyLICR] = i << 2;
2733 debugiq.in = debugiq.out = 0;
2735 base_addr[CyCAR] = DEBUG_PORT;
2740 base_addr[CyIER] = 0;
2742 base_addr[CyCMR] = CyASYNC;
2743 base_addr[CyLICR] = DEBUG_PORT << 2;
2744 base_addr[CyLIVR] = 0x5c;
2746 /* tx and rx baud rate */
2748 base_addr[CyTCOR] = baud_co[i];
2749 base_addr[CyTBPR] = baud_bpr[i];
2750 base_addr[CyRCOR] = baud_co[i] >> 5;
2751 base_addr[CyRBPR] = baud_bpr[i];
2753 /* set line characteristics according configuration */
2755 base_addr[CySCHR1] = 0;
2756 base_addr[CySCHR2] = 0;
2757 base_addr[CySCRL] = 0;
2758 base_addr[CySCRH] = 0;
2759 base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
2760 base_addr[CyCOR2] = 0;
2761 base_addr[CyCOR3] = Cy_1_STOP;
2762 base_addr[CyCOR4] = baud_cor4[i];
2763 base_addr[CyCOR5] = 0;
2764 base_addr[CyCOR6] = 0;
2765 base_addr[CyCOR7] = 0;
2767 write_cy_cmd(base_addr, CyINIT_CHAN);
2768 write_cy_cmd(base_addr, CyENB_RCVR);
2770 base_addr[CyCAR] = DEBUG_PORT; /* !!! Is this needed? */
2772 base_addr[CyRTPRL] = 2;
2773 base_addr[CyRTPRH] = 0;
2775 base_addr[CyMSVR1] = CyRTS;
2776 base_addr[CyMSVR2] = CyDTR;
2778 base_addr[CyIER] = CyRxData;
2780 local_irq_restore(flags);
2786 MODULE_LICENSE("GPL");