2 * linux/drivers/char/serial167.c
4 * Driver for MVME166/7 board serial ports, which are via a CD2401.
5 * Based very much on cyclades.c.
7 * MVME166/7 work by Richard Hirst [richard@sleepie.demon.co.uk]
9 * ==============================================================
11 * static char rcsid[] =
12 * "$Revision: 1.36.1.4 $$Date: 1995/03/29 06:14:14 $";
14 * linux/kernel/cyclades.c
16 * Maintained by Marcio Saito (cyclades@netcom.com) and
17 * Randolph Bentson (bentson@grieg.seaslug.org)
19 * Much of the design and some of the code came from serial.c
20 * which was copyright (C) 1991, 1992 Linus Torvalds. It was
21 * extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92,
22 * and then fixed as suggested by Michael K. Johnson 12/12/92.
24 * This version does not support shared irq's.
26 * $Log: cyclades.c,v $
27 * Revision 1.36.1.4 1995/03/29 06:14:14 bentson
28 * disambiguate between Cyclom-16Y and Cyclom-32Ye;
32 * 200 lines of changes record removed - RGH 11-10-95, starting work on
33 * converting this to drive serial ports on mvme166 (cd2401).
35 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 2000/08/25
36 * - get rid of verify_area
37 * - use get_user to access memory from userspace in set_threshold,
38 * set_default_threshold and set_timeout
39 * - don't use the panic function in serial167_init
40 * - do resource release on failure on serial167_init
41 * - include missing restore_flags in mvme167_serial_console_setup
44 #include <linux/config.h>
45 #include <linux/errno.h>
46 #include <linux/signal.h>
47 #include <linux/sched.h>
48 #include <linux/timer.h>
49 #include <linux/tty.h>
50 #include <linux/interrupt.h>
51 #include <linux/serial.h>
52 #include <linux/serialP.h>
53 #include <linux/string.h>
54 #include <linux/fcntl.h>
55 #include <linux/ptrace.h>
56 #include <linux/serial167.h>
57 #include <linux/delay.h>
58 #include <linux/major.h>
60 #include <linux/console.h>
61 #include <linux/module.h>
63 #include <asm/system.h>
65 #include <asm/bitops.h>
66 #include <asm/mvme16xhw.h>
67 #include <asm/bootinfo.h>
68 #include <asm/setup.h>
70 #include <linux/types.h>
71 #include <linux/kernel.h>
73 #include <asm/uaccess.h>
74 #include <linux/init.h>
76 #define SERIAL_PARANOIA_CHECK
77 #undef SERIAL_DEBUG_OPEN
78 #undef SERIAL_DEBUG_THROTTLE
79 #undef SERIAL_DEBUG_OTHER
80 #undef SERIAL_DEBUG_IO
81 #undef SERIAL_DEBUG_COUNT
82 #undef SERIAL_DEBUG_DTR
83 #undef CYCLOM_16Y_HACK
84 #define CYCLOM_ENABLE_MONITORING
86 #define WAKEUP_CHARS 256
88 #define STD_COM_FLAGS (0)
90 #define SERIAL_TYPE_NORMAL 1
92 DECLARE_TASK_QUEUE(tq_cyclades
);
94 static struct tty_driver
*cy_serial_driver
;
95 extern int serial_console
;
96 static struct cyclades_port
*serial_console_info
= NULL
;
97 static unsigned int serial_console_cflag
= 0;
98 u_char initial_console_speed
;
100 /* Base address of cd2401 chip on mvme166/7 */
102 #define BASE_ADDR (0xfff45000)
103 #define pcc2chip ((volatile u_char *)0xfff42000)
104 #define PccSCCMICR 0x1d
105 #define PccSCCTICR 0x1e
106 #define PccSCCRICR 0x1f
107 #define PccTPIACKR 0x25
108 #define PccRPIACKR 0x27
111 /* This is the per-port data structure */
112 struct cyclades_port cy_port
[] = {
119 #define NR_PORTS (sizeof(cy_port)/sizeof(struct cyclades_port))
122 * tmp_buf is used as a temporary buffer by serial_write. We need to
123 * lock it in case the copy_from_user blocks while swapping in a page,
124 * and some other program tries to do a serial write at the same time.
125 * Since the lock will only come under contention when the system is
126 * swapping and available memory is low, it makes sense to share one
127 * buffer across all the serial ports, since it significantly saves
128 * memory if large numbers of serial ports are open.
130 static unsigned char *tmp_buf
= 0;
131 DECLARE_MUTEX(tmp_buf_sem
);
134 * This is used to look up the divisor speeds and the timeouts
135 * We're normally limited to 15 distinct baud rates. The extra
136 * are accessed via settings in info->flags.
137 * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
138 * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
141 static int baud_table
[] = {
142 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
143 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000,
147 static char baud_co
[] = { /* 25 MHz clock option table */
148 /* value => 00 01 02 03 04 */
149 /* divide by 8 32 128 512 2048 */
150 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
151 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
153 static char baud_bpr
[] = { /* 25 MHz baud rate period table */
154 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
155 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15};
158 /* I think 166 brd clocks 2401 at 20MHz.... */
160 /* These values are written directly to tcor, and >> 5 for writing to rcor */
161 static u_char baud_co
[] = { /* 20 MHz clock option table */
162 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x60, 0x60, 0x40,
163 0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
165 /* These values written directly to tbpr/rbpr */
166 static u_char baud_bpr
[] = { /* 20 MHz baud rate period table */
167 0x00, 0xc0, 0x80, 0x58, 0x6c, 0x40, 0xc0, 0x81, 0x40, 0x81,
168 0x57, 0x40, 0x81, 0x40, 0x81, 0x40, 0x2b, 0x20, 0x15, 0x10};
170 static u_char baud_cor4
[] = { /* receive threshold */
171 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
172 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07};
176 static void shutdown(struct cyclades_port
*);
177 static int startup (struct cyclades_port
*);
178 static void cy_throttle(struct tty_struct
*);
179 static void cy_unthrottle(struct tty_struct
*);
180 static void config_setup(struct cyclades_port
*);
181 extern void console_print(const char *);
182 #ifdef CYCLOM_SHOW_STATUS
183 static void show_status(int);
186 #ifdef CONFIG_REMOTE_DEBUG
187 static void debug_setup(void);
188 void queueDebugChar (int c
);
189 int getDebugChar(void);
192 #define DEBUG_LEN 256
197 unsigned char buf
[DEBUG_LEN
];
204 * I have my own version of udelay(), as it is needed when initialising
205 * the chip, before the delay loop has been calibrated. Should probably
206 * reference one of the vmechip2 or pccchip2 counter for an accurate
207 * delay, but this wild guess will do for now.
210 void my_udelay (long us
)
213 volatile u_char
*p
= &x
;
217 for (i
= 100; i
; i
--)
222 serial_paranoia_check(struct cyclades_port
*info
, char *name
,
225 #ifdef SERIAL_PARANOIA_CHECK
226 static const char *badmagic
=
227 "Warning: bad magic number for serial struct (%s) in %s\n";
228 static const char *badinfo
=
229 "Warning: null cyclades_port for (%s) in %s\n";
230 static const char *badrange
=
231 "Warning: cyclades_port out of range for (%s) in %s\n";
234 printk(badinfo
, name
, routine
);
238 if( (long)info
< (long)(&cy_port
[0])
239 || (long)(&cy_port
[NR_PORTS
]) < (long)info
){
240 printk(badrange
, name
, routine
);
244 if (info
->magic
!= CYCLADES_MAGIC
) {
245 printk(badmagic
, name
, routine
);
250 } /* serial_paranoia_check */
253 /* The following diagnostic routines allow the driver to spew
254 information on the screen, even (especially!) during interrupts.
259 local_irq_save(flags
);
261 local_irq_restore(flags
);
267 local_irq_save(flags
);
270 local_irq_restore(flags
);
273 void CP1(int data
) { (data
<10)? CP(data
+'0'): CP(data
+'A'-10); }/* CP1 */
274 void CP2(int data
) { CP1((data
>>4) & 0x0f); CP1( data
& 0x0f); }/* CP2 */
275 void CP4(int data
) { CP2((data
>>8) & 0xff); CP2(data
& 0xff); }/* CP4 */
276 void CP8(long data
) { CP4((data
>>16) & 0xffff); CP4(data
& 0xffff); }/* CP8 */
279 /* This routine waits up to 1000 micro-seconds for the previous
280 command to the Cirrus chip to complete and then issues the
281 new command. An error is returned if the previous command
282 didn't finish within the time limit.
285 write_cy_cmd(volatile u_char
*base_addr
, u_char cmd
)
290 local_irq_save(flags
);
291 /* Check to see that the previous command has completed */
292 for(i
= 0 ; i
< 100 ; i
++){
293 if (base_addr
[CyCCR
] == 0){
298 /* if the CCR never cleared, the previous command
299 didn't finish within the "reasonable time" */
301 local_irq_restore(flags
);
305 /* Issue the new command */
306 base_addr
[CyCCR
] = cmd
;
307 local_irq_restore(flags
);
312 /* cy_start and cy_stop provide software output flow control as a
313 function of XON/XOFF, software CTS, and other such stuff. */
316 cy_stop(struct tty_struct
*tty
)
318 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
319 volatile unsigned char *base_addr
= (unsigned char *)BASE_ADDR
;
323 #ifdef SERIAL_DEBUG_OTHER
324 printk("cy_stop %s\n", tty
->name
); /* */
327 if (serial_paranoia_check(info
, tty
->name
, "cy_stop"))
330 channel
= info
->line
;
332 local_irq_save(flags
);
333 base_addr
[CyCAR
] = (u_char
)(channel
); /* index channel */
334 base_addr
[CyIER
] &= ~(CyTxMpty
|CyTxRdy
);
335 local_irq_restore(flags
);
341 cy_start(struct tty_struct
*tty
)
343 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
344 volatile unsigned char *base_addr
= (unsigned char *)BASE_ADDR
;
348 #ifdef SERIAL_DEBUG_OTHER
349 printk("cy_start %s\n", tty
->name
); /* */
352 if (serial_paranoia_check(info
, tty
->name
, "cy_start"))
355 channel
= info
->line
;
357 local_irq_save(flags
);
358 base_addr
[CyCAR
] = (u_char
)(channel
);
359 base_addr
[CyIER
] |= CyTxMpty
;
360 local_irq_restore(flags
);
367 * This routine is used by the interrupt handler to schedule
368 * processing in the software interrupt portion of the driver
369 * (also known as the "bottom half"). This can be called any
370 * number of times for any channel without harm.
373 cy_sched_event(struct cyclades_port
*info
, int event
)
375 info
->event
|= 1 << event
; /* remember what kind of event and who */
376 queue_task(&info
->tqueue
, &tq_cyclades
); /* it belongs to */
377 mark_bh(CYCLADES_BH
); /* then trigger event */
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 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
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 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
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 tq_cyclades work queue and sets a request flag
725 * via mark_bh for processing that queue. When the time is right,
726 * do_cyclades_bh is called (because of the mark_bh) and it requests
727 * that the work queue be processed.
729 * Although this may seem unwieldy, it gives the system a way to
730 * pass an argument (in this case the pointer to the cyclades_port
731 * structure) to the bottom half of the driver. Previous kernels
732 * had to poll every port to see if that port needed servicing.
737 run_task_queue(&tq_cyclades
);
738 } /* do_cyclades_bh */
741 do_softint(void *private_
)
743 struct cyclades_port
*info
= (struct cyclades_port
*) private_
;
744 struct tty_struct
*tty
;
750 if (test_and_clear_bit(Cy_EVENT_HANGUP
, &info
->event
)) {
751 tty_hangup(info
->tty
);
752 wake_up_interruptible(&info
->open_wait
);
753 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
755 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP
, &info
->event
)) {
756 wake_up_interruptible(&info
->open_wait
);
758 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP
, &info
->event
)) {
764 /* This is called whenever a port becomes active;
765 interrupts are enabled and DTR & RTS are turned on.
768 startup(struct cyclades_port
* info
)
771 volatile unsigned char *base_addr
= (unsigned char *)BASE_ADDR
;
774 if (info
->flags
& ASYNC_INITIALIZED
){
780 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
784 if (!info
->xmit_buf
){
785 info
->xmit_buf
= (unsigned char *) get_zeroed_page (GFP_KERNEL
);
786 if (!info
->xmit_buf
){
793 channel
= info
->line
;
795 #ifdef SERIAL_DEBUG_OPEN
796 printk("startup channel %d\n", channel
);
799 local_irq_save(flags
);
800 base_addr
[CyCAR
] = (u_char
)channel
;
801 write_cy_cmd(base_addr
,CyENB_RCVR
|CyENB_XMTR
);
803 base_addr
[CyCAR
] = (u_char
)channel
; /* !!! Is this needed? */
804 base_addr
[CyMSVR1
] = CyRTS
;
805 /* CP('S');CP('1'); */
806 base_addr
[CyMSVR2
] = CyDTR
;
808 #ifdef SERIAL_DEBUG_DTR
809 printk("cyc: %d: raising DTR\n", __LINE__
);
810 printk(" status: 0x%x, 0x%x\n", base_addr
[CyMSVR1
], base_addr
[CyMSVR2
]);
813 base_addr
[CyIER
] |= CyRxData
;
814 info
->flags
|= ASYNC_INITIALIZED
;
817 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
819 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
821 local_irq_restore(flags
);
823 #ifdef SERIAL_DEBUG_OPEN
830 start_xmit( struct cyclades_port
*info
)
833 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
836 channel
= info
->line
;
837 local_irq_save(flags
);
838 base_addr
[CyCAR
] = channel
;
839 base_addr
[CyIER
] |= CyTxMpty
;
840 local_irq_restore(flags
);
844 * This routine shuts down a serial port; interrupts are disabled,
845 * and DTR is dropped if the hangup on close termio flag is on.
848 shutdown(struct cyclades_port
* info
)
851 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
854 if (!(info
->flags
& ASYNC_INITIALIZED
)){
859 channel
= info
->line
;
861 #ifdef SERIAL_DEBUG_OPEN
862 printk("shutdown channel %d\n", channel
);
865 /* !!! REALLY MUST WAIT FOR LAST CHARACTER TO BE
866 SENT BEFORE DROPPING THE LINE !!! (Perhaps
867 set some flag that is read when XMTY happens.)
868 Other choices are to delay some fixed interval
869 or schedule some later processing.
871 local_irq_save(flags
);
873 free_page((unsigned long) info
->xmit_buf
);
877 base_addr
[CyCAR
] = (u_char
)channel
;
878 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
879 base_addr
[CyMSVR1
] = 0;
880 /* CP('C');CP('1'); */
881 base_addr
[CyMSVR2
] = 0;
882 #ifdef SERIAL_DEBUG_DTR
883 printk("cyc: %d: dropping DTR\n", __LINE__
);
884 printk(" status: 0x%x, 0x%x\n", base_addr
[CyMSVR1
], base_addr
[CyMSVR2
]);
887 write_cy_cmd(base_addr
,CyDIS_RCVR
);
888 /* it may be appropriate to clear _XMIT at
889 some later date (after testing)!!! */
892 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
894 info
->flags
&= ~ASYNC_INITIALIZED
;
895 local_irq_restore(flags
);
897 #ifdef SERIAL_DEBUG_OPEN
904 * This routine finds or computes the various line characteristics.
907 config_setup(struct cyclades_port
* info
)
910 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
914 unsigned char ti
, need_init_chan
= 0;
916 if (!info
->tty
|| !info
->tty
->termios
){
919 if (info
->line
== -1){
922 cflag
= info
->tty
->termios
->c_cflag
;
927 /* Starting with kernel 1.1.65, there is direct support for
928 higher baud rates. The following code supports those
929 changes. The conditional aspect allows this driver to be
930 used for earlier as well as later kernel versions. (The
931 mapping is slightly different from serial.c because there
932 is still the possibility of supporting 75 kbit/sec with
938 else if(i
== B115200
)
945 info
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
949 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
951 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
954 /* Don't ever change the speed of the console port. It will
955 * run at the speed specified in bootinfo, or at 19.2K */
956 /* Actually, it should run at whatever speed 166Bug was using */
957 /* Note info->timeout isn't used at present */
958 if (info
!= serial_console_info
) {
959 info
->tbpr
= baud_bpr
[i
]; /* Tx BPR */
960 info
->tco
= baud_co
[i
]; /* Tx CO */
961 info
->rbpr
= baud_bpr
[i
]; /* Rx BPR */
962 info
->rco
= baud_co
[i
] >> 5; /* Rx CO */
963 if (baud_table
[i
] == 134) {
964 info
->timeout
= (info
->xmit_fifo_size
*HZ
*30/269) + 2;
965 /* get it right for 134.5 baud */
966 } else if (baud_table
[i
]) {
967 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud_table
[i
]) + 2;
968 /* this needs to be propagated into the card info */
973 /* By tradition (is it a standard?) a baud rate of zero
974 implies the line should be/has been closed. A bit
975 later in this routine such a test is performed. */
977 /* byte size and parity */
981 info
->cor4
= (info
->default_threshold
982 ? info
->default_threshold
983 : baud_cor4
[i
]); /* receive threshold */
984 /* Following two lines added 101295, RGH. */
985 /* It is obviously wrong to access CyCORx, and not info->corx here,
986 * try and remember to fix it later! */
987 channel
= info
->line
;
988 base_addr
[CyCAR
] = (u_char
)channel
;
989 if (C_CLOCAL(info
->tty
)) {
990 if (base_addr
[CyIER
] & CyMdmCh
)
991 base_addr
[CyIER
] &= ~CyMdmCh
; /* without modem intr */
992 /* ignore 1->0 modem transitions */
993 if (base_addr
[CyCOR4
] & (CyDSR
|CyCTS
|CyDCD
))
994 base_addr
[CyCOR4
] &= ~(CyDSR
|CyCTS
|CyDCD
);
995 /* ignore 0->1 modem transitions */
996 if (base_addr
[CyCOR5
] & (CyDSR
|CyCTS
|CyDCD
))
997 base_addr
[CyCOR5
] &= ~(CyDSR
|CyCTS
|CyDCD
);
999 if ((base_addr
[CyIER
] & CyMdmCh
) != CyMdmCh
)
1000 base_addr
[CyIER
] |= CyMdmCh
; /* with modem intr */
1001 /* act on 1->0 modem transitions */
1002 if ((base_addr
[CyCOR4
] & (CyDSR
|CyCTS
|CyDCD
)) != (CyDSR
|CyCTS
|CyDCD
))
1003 base_addr
[CyCOR4
] |= CyDSR
|CyCTS
|CyDCD
;
1004 /* act on 0->1 modem transitions */
1005 if ((base_addr
[CyCOR5
] & (CyDSR
|CyCTS
|CyDCD
)) != (CyDSR
|CyCTS
|CyDCD
))
1006 base_addr
[CyCOR5
] |= CyDSR
|CyCTS
|CyDCD
;
1008 info
->cor3
= (cflag
& CSTOPB
) ? Cy_2_STOP
: Cy_1_STOP
;
1010 switch(cflag
& CSIZE
){
1012 info
->cor1
= Cy_5_BITS
;
1015 info
->cor1
= Cy_6_BITS
;
1018 info
->cor1
= Cy_7_BITS
;
1021 info
->cor1
= Cy_8_BITS
;
1024 if (cflag
& PARENB
){
1025 if (cflag
& PARODD
){
1026 info
->cor1
|= CyPARITY_O
;
1028 info
->cor1
|= CyPARITY_E
;
1031 info
->cor1
|= CyPARITY_NONE
;
1034 /* CTS flow control flag */
1036 /* Don't complcate matters for now! RGH 141095 */
1037 if (cflag
& CRTSCTS
){
1038 info
->flags
|= ASYNC_CTS_FLOW
;
1039 info
->cor2
|= CyCtsAE
;
1041 info
->flags
&= ~ASYNC_CTS_FLOW
;
1042 info
->cor2
&= ~CyCtsAE
;
1046 info
->flags
&= ~ASYNC_CHECK_CD
;
1048 info
->flags
|= ASYNC_CHECK_CD
;
1050 /***********************************************
1051 The hardware option, CyRtsAO, presents RTS when
1052 the chip has characters to send. Since most modems
1053 use RTS as reverse (inbound) flow control, this
1054 option is not used. If inbound flow control is
1055 necessary, DTR can be programmed to provide the
1056 appropriate signals for use with a non-standard
1057 cable. Contact Marcio Saito for details.
1058 ***********************************************/
1060 channel
= info
->line
;
1062 local_irq_save(flags
);
1063 base_addr
[CyCAR
] = (u_char
)channel
;
1065 /* CyCMR set once only in mvme167_init_serial() */
1066 if (base_addr
[CyLICR
] != channel
<< 2)
1067 base_addr
[CyLICR
] = channel
<< 2;
1068 if (base_addr
[CyLIVR
] != 0x5c)
1069 base_addr
[CyLIVR
] = 0x5c;
1071 /* tx and rx baud rate */
1073 if (base_addr
[CyCOR1
] != info
->cor1
)
1075 if (base_addr
[CyTCOR
] != info
->tco
)
1076 base_addr
[CyTCOR
] = info
->tco
;
1077 if (base_addr
[CyTBPR
] != info
->tbpr
)
1078 base_addr
[CyTBPR
] = info
->tbpr
;
1079 if (base_addr
[CyRCOR
] != info
->rco
)
1080 base_addr
[CyRCOR
] = info
->rco
;
1081 if (base_addr
[CyRBPR
] != info
->rbpr
)
1082 base_addr
[CyRBPR
] = info
->rbpr
;
1084 /* set line characteristics according configuration */
1086 if (base_addr
[CySCHR1
] != START_CHAR(info
->tty
))
1087 base_addr
[CySCHR1
] = START_CHAR(info
->tty
);
1088 if (base_addr
[CySCHR2
] != STOP_CHAR(info
->tty
))
1089 base_addr
[CySCHR2
] = STOP_CHAR(info
->tty
);
1090 if (base_addr
[CySCRL
] != START_CHAR(info
->tty
))
1091 base_addr
[CySCRL
] = START_CHAR(info
->tty
);
1092 if (base_addr
[CySCRH
] != START_CHAR(info
->tty
))
1093 base_addr
[CySCRH
] = START_CHAR(info
->tty
);
1094 if (base_addr
[CyCOR1
] != info
->cor1
)
1095 base_addr
[CyCOR1
] = info
->cor1
;
1096 if (base_addr
[CyCOR2
] != info
->cor2
)
1097 base_addr
[CyCOR2
] = info
->cor2
;
1098 if (base_addr
[CyCOR3
] != info
->cor3
)
1099 base_addr
[CyCOR3
] = info
->cor3
;
1100 if (base_addr
[CyCOR4
] != info
->cor4
)
1101 base_addr
[CyCOR4
] = info
->cor4
;
1102 if (base_addr
[CyCOR5
] != info
->cor5
)
1103 base_addr
[CyCOR5
] = info
->cor5
;
1104 if (base_addr
[CyCOR6
] != info
->cor6
)
1105 base_addr
[CyCOR6
] = info
->cor6
;
1106 if (base_addr
[CyCOR7
] != info
->cor7
)
1107 base_addr
[CyCOR7
] = info
->cor7
;
1110 write_cy_cmd(base_addr
,CyINIT_CHAN
);
1112 base_addr
[CyCAR
] = (u_char
)channel
; /* !!! Is this needed? */
1114 /* 2ms default rx timeout */
1115 ti
= info
->default_timeout
? info
->default_timeout
: 0x02;
1116 if (base_addr
[CyRTPRL
] != ti
)
1117 base_addr
[CyRTPRL
] = ti
;
1118 if (base_addr
[CyRTPRH
] != 0)
1119 base_addr
[CyRTPRH
] = 0;
1121 /* Set up RTS here also ????? RGH 141095 */
1122 if(i
== 0){ /* baud rate is zero, turn off line */
1123 if ((base_addr
[CyMSVR2
] & CyDTR
) == CyDTR
)
1124 base_addr
[CyMSVR2
] = 0;
1125 #ifdef SERIAL_DEBUG_DTR
1126 printk("cyc: %d: dropping DTR\n", __LINE__
);
1127 printk(" status: 0x%x, 0x%x\n", base_addr
[CyMSVR1
], base_addr
[CyMSVR2
]);
1130 if ((base_addr
[CyMSVR2
] & CyDTR
) != CyDTR
)
1131 base_addr
[CyMSVR2
] = CyDTR
;
1132 #ifdef SERIAL_DEBUG_DTR
1133 printk("cyc: %d: raising DTR\n", __LINE__
);
1134 printk(" status: 0x%x, 0x%x\n", base_addr
[CyMSVR1
], base_addr
[CyMSVR2
]);
1139 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1142 local_irq_restore(flags
);
1144 } /* config_setup */
1148 cy_put_char(struct tty_struct
*tty
, unsigned char ch
)
1150 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1151 unsigned long flags
;
1153 #ifdef SERIAL_DEBUG_IO
1154 printk("cy_put_char %s(0x%02x)\n", tty
->name
, ch
);
1157 if (serial_paranoia_check(info
, tty
->name
, "cy_put_char"))
1160 if (!tty
|| !info
->xmit_buf
)
1163 local_irq_save(flags
);
1164 if (info
->xmit_cnt
>= PAGE_SIZE
- 1) {
1165 local_irq_restore(flags
);
1169 info
->xmit_buf
[info
->xmit_head
++] = ch
;
1170 info
->xmit_head
&= PAGE_SIZE
- 1;
1172 local_irq_restore(flags
);
1177 cy_flush_chars(struct tty_struct
*tty
)
1179 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1180 unsigned long flags
;
1181 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1184 #ifdef SERIAL_DEBUG_IO
1185 printk("cy_flush_chars %s\n", tty
->name
); /* */
1188 if (serial_paranoia_check(info
, tty
->name
, "cy_flush_chars"))
1191 if (info
->xmit_cnt
<= 0 || tty
->stopped
1192 || tty
->hw_stopped
|| !info
->xmit_buf
)
1195 channel
= info
->line
;
1197 local_irq_save(flags
);
1198 base_addr
[CyCAR
] = channel
;
1199 base_addr
[CyIER
] |= CyTxMpty
;
1200 local_irq_restore(flags
);
1201 } /* cy_flush_chars */
1204 /* This routine gets called when tty_write has put something into
1205 the write_queue. If the port is not already transmitting stuff,
1206 start it off by enabling interrupts. The interrupt service
1207 routine will then ensure that the characters are sent. If the
1208 port is already active, there is no need to kick it.
1211 cy_write(struct tty_struct
* tty
, int from_user
,
1212 const unsigned char *buf
, int count
)
1214 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1215 unsigned long flags
;
1218 #ifdef SERIAL_DEBUG_IO
1219 printk("cy_write %s\n", tty
->name
); /* */
1222 if (serial_paranoia_check(info
, tty
->name
, "cy_write")){
1226 if (!tty
|| !info
->xmit_buf
|| !tmp_buf
){
1233 c
= min_t(int, count
, min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1234 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1238 c
-= copy_from_user(tmp_buf
, buf
, c
);
1245 local_irq_save(flags
);
1246 c
= min_t(int, c
, min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1247 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1248 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
1249 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
1250 info
->xmit_cnt
+= c
;
1251 local_irq_restore(flags
);
1260 local_irq_save(flags
);
1261 c
= min_t(int, count
, min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1262 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1264 local_irq_restore(flags
);
1268 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
1269 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
1270 info
->xmit_cnt
+= c
;
1271 local_irq_restore(flags
);
1281 && !tty
->hw_stopped
) {
1289 cy_write_room(struct tty_struct
*tty
)
1291 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1294 #ifdef SERIAL_DEBUG_IO
1295 printk("cy_write_room %s\n", tty
->name
); /* */
1298 if (serial_paranoia_check(info
, tty
->name
, "cy_write_room"))
1300 ret
= PAGE_SIZE
- info
->xmit_cnt
- 1;
1304 } /* cy_write_room */
1308 cy_chars_in_buffer(struct tty_struct
*tty
)
1310 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1312 #ifdef SERIAL_DEBUG_IO
1313 printk("cy_chars_in_buffer %s %d\n", tty
->name
, info
->xmit_cnt
); /* */
1316 if (serial_paranoia_check(info
, tty
->name
, "cy_chars_in_buffer"))
1319 return info
->xmit_cnt
;
1320 } /* cy_chars_in_buffer */
1324 cy_flush_buffer(struct tty_struct
*tty
)
1326 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1327 unsigned long flags
;
1329 #ifdef SERIAL_DEBUG_IO
1330 printk("cy_flush_buffer %s\n", tty
->name
); /* */
1333 if (serial_paranoia_check(info
, tty
->name
, "cy_flush_buffer"))
1335 local_irq_save(flags
);
1336 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1337 local_irq_restore(flags
);
1339 } /* cy_flush_buffer */
1342 /* This routine is called by the upper-layer tty layer to signal
1343 that incoming characters should be throttled or that the
1344 throttle should be released.
1347 cy_throttle(struct tty_struct
* tty
)
1349 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1350 unsigned long flags
;
1351 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1354 #ifdef SERIAL_DEBUG_THROTTLE
1357 printk("throttle %s: %d....\n", tty_name(tty
, buf
),
1358 tty
->ldisc
.chars_in_buffer(tty
));
1359 printk("cy_throttle %s\n", tty
->name
);
1362 if (serial_paranoia_check(info
, tty
->name
, "cy_nthrottle")){
1367 info
->x_char
= STOP_CHAR(tty
);
1368 /* Should use the "Send Special Character" feature!!! */
1371 channel
= info
->line
;
1373 local_irq_save(flags
);
1374 base_addr
[CyCAR
] = (u_char
)channel
;
1375 base_addr
[CyMSVR1
] = 0;
1376 local_irq_restore(flags
);
1383 cy_unthrottle(struct tty_struct
* tty
)
1385 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1386 unsigned long flags
;
1387 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1390 #ifdef SERIAL_DEBUG_THROTTLE
1393 printk("throttle %s: %d....\n", tty_name(tty
, buf
),
1394 tty
->ldisc
.chars_in_buffer(tty
));
1395 printk("cy_unthrottle %s\n", tty
->name
);
1398 if (serial_paranoia_check(info
, tty
->name
, "cy_nthrottle")){
1403 info
->x_char
= START_CHAR(tty
);
1404 /* Should use the "Send Special Character" feature!!! */
1407 channel
= info
->line
;
1409 local_irq_save(flags
);
1410 base_addr
[CyCAR
] = (u_char
)channel
;
1411 base_addr
[CyMSVR1
] = CyRTS
;
1412 local_irq_restore(flags
);
1415 } /* cy_unthrottle */
1418 get_serial_info(struct cyclades_port
* info
,
1419 struct serial_struct
* retinfo
)
1421 struct serial_struct tmp
;
1426 memset(&tmp
, 0, sizeof(tmp
));
1427 tmp
.type
= info
->type
;
1428 tmp
.line
= info
->line
;
1429 tmp
.port
= info
->line
;
1431 tmp
.flags
= info
->flags
;
1432 tmp
.baud_base
= 0; /*!!!*/
1433 tmp
.close_delay
= info
->close_delay
;
1434 tmp
.custom_divisor
= 0; /*!!!*/
1435 tmp
.hub6
= 0; /*!!!*/
1436 return copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
)) ? -EFAULT
: 0;
1437 } /* get_serial_info */
1440 set_serial_info(struct cyclades_port
* info
,
1441 struct serial_struct
* new_info
)
1443 struct serial_struct new_serial
;
1444 struct cyclades_port old_info
;
1449 if (copy_from_user(&new_serial
,new_info
,sizeof(new_serial
)))
1453 if (!capable(CAP_SYS_ADMIN
)) {
1454 if ((new_serial
.close_delay
!= info
->close_delay
) ||
1455 ((new_serial
.flags
& ASYNC_FLAGS
& ~ASYNC_USR_MASK
) !=
1456 (info
->flags
& ASYNC_FLAGS
& ~ASYNC_USR_MASK
)))
1458 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) |
1459 (new_serial
.flags
& ASYNC_USR_MASK
));
1460 goto check_and_exit
;
1465 * OK, past this point, all the error checking has been done.
1466 * At this point, we start making changes.....
1469 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) |
1470 (new_serial
.flags
& ASYNC_FLAGS
));
1471 info
->close_delay
= new_serial
.close_delay
;
1475 if (info
->flags
& ASYNC_INITIALIZED
){
1479 return startup(info
);
1481 } /* set_serial_info */
1484 cy_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1486 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
1488 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1489 unsigned long flags
;
1490 unsigned char status
;
1491 unsigned int result
;
1493 channel
= info
->line
;
1495 local_irq_save(flags
);
1496 base_addr
[CyCAR
] = (u_char
)channel
;
1497 status
= base_addr
[CyMSVR1
] | base_addr
[CyMSVR2
];
1498 local_irq_restore(flags
);
1500 return ((status
& CyRTS
) ? TIOCM_RTS
: 0)
1501 | ((status
& CyDTR
) ? TIOCM_DTR
: 0)
1502 | ((status
& CyDCD
) ? TIOCM_CAR
: 0)
1503 | ((status
& CyDSR
) ? TIOCM_DSR
: 0)
1504 | ((status
& CyCTS
) ? TIOCM_CTS
: 0);
1508 cy_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1509 unsigned int set
, unsigned int clear
)
1511 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
1513 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1514 unsigned long flags
;
1517 channel
= info
->line
;
1519 if (set
& TIOCM_RTS
){
1520 local_irq_save(flags
);
1521 base_addr
[CyCAR
] = (u_char
)channel
;
1522 base_addr
[CyMSVR1
] = CyRTS
;
1523 local_irq_restore(flags
);
1525 if (set
& TIOCM_DTR
){
1526 local_irq_save(flags
);
1527 base_addr
[CyCAR
] = (u_char
)channel
;
1528 /* CP('S');CP('2'); */
1529 base_addr
[CyMSVR2
] = CyDTR
;
1530 #ifdef SERIAL_DEBUG_DTR
1531 printk("cyc: %d: raising DTR\n", __LINE__
);
1532 printk(" status: 0x%x, 0x%x\n", base_addr
[CyMSVR1
], base_addr
[CyMSVR2
]);
1534 local_irq_restore(flags
);
1537 if (clear
& TIOCM_RTS
){
1538 local_irq_save(flags
);
1539 base_addr
[CyCAR
] = (u_char
)channel
;
1540 base_addr
[CyMSVR1
] = 0;
1541 local_irq_restore(flags
);
1543 if (clear
& TIOCM_DTR
){
1544 local_irq_save(flags
);
1545 base_addr
[CyCAR
] = (u_char
)channel
;
1546 /* CP('C');CP('2'); */
1547 base_addr
[CyMSVR2
] = 0;
1548 #ifdef SERIAL_DEBUG_DTR
1549 printk("cyc: %d: dropping DTR\n", __LINE__
);
1550 printk(" status: 0x%x, 0x%x\n", base_addr
[CyMSVR1
], base_addr
[CyMSVR2
]);
1552 local_irq_restore(flags
);
1556 } /* set_modem_info */
1559 send_break( struct cyclades_port
* info
, int duration
)
1560 { /* Let the transmit ISR take care of this (since it
1561 requires stuffing characters into the output stream).
1563 info
->x_break
= duration
;
1564 if (!info
->xmit_cnt
) {
1570 get_mon_info(struct cyclades_port
* info
, struct cyclades_monitor
* mon
)
1573 if (copy_to_user(mon
, &info
->mon
, sizeof(struct cyclades_monitor
)))
1575 info
->mon
.int_count
= 0;
1576 info
->mon
.char_count
= 0;
1577 info
->mon
.char_max
= 0;
1578 info
->mon
.char_last
= 0;
1583 set_threshold(struct cyclades_port
* info
, unsigned long *arg
)
1585 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1586 unsigned long value
;
1589 if (get_user(value
, arg
))
1592 channel
= info
->line
;
1593 info
->cor4
&= ~CyREC_FIFO
;
1594 info
->cor4
|= value
& CyREC_FIFO
;
1595 base_addr
[CyCOR4
] = info
->cor4
;
1600 get_threshold(struct cyclades_port
* info
, unsigned long *value
)
1602 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1606 channel
= info
->line
;
1608 tmp
= base_addr
[CyCOR4
] & CyREC_FIFO
;
1609 return put_user(tmp
,value
);
1613 set_default_threshold(struct cyclades_port
* info
, unsigned long *arg
)
1615 unsigned long value
;
1617 if (get_user(value
, arg
))
1620 info
->default_threshold
= value
& 0x0f;
1625 get_default_threshold(struct cyclades_port
* info
, unsigned long *value
)
1627 return put_user(info
->default_threshold
,value
);
1631 set_timeout(struct cyclades_port
* info
, unsigned long *arg
)
1633 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1635 unsigned long value
;
1637 if (get_user(value
, arg
))
1640 channel
= info
->line
;
1642 base_addr
[CyRTPRL
] = value
& 0xff;
1643 base_addr
[CyRTPRH
] = (value
>> 8) & 0xff;
1648 get_timeout(struct cyclades_port
* info
, unsigned long *value
)
1650 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1654 channel
= info
->line
;
1656 tmp
= base_addr
[CyRTPRL
];
1657 return put_user(tmp
,value
);
1661 set_default_timeout(struct cyclades_port
* info
, unsigned long value
)
1663 info
->default_timeout
= value
& 0xff;
1668 get_default_timeout(struct cyclades_port
* info
, unsigned long *value
)
1670 return put_user(info
->default_timeout
,value
);
1674 cy_ioctl(struct tty_struct
*tty
, struct file
* file
,
1675 unsigned int cmd
, unsigned long arg
)
1678 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
1681 #ifdef SERIAL_DEBUG_OTHER
1682 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty
->name
, cmd
, arg
); /* */
1687 ret_val
= get_mon_info(info
, (struct cyclades_monitor
*)arg
);
1690 ret_val
= get_threshold(info
, (unsigned long *)arg
);
1693 ret_val
= set_threshold(info
, (unsigned long *)arg
);
1695 case CYGETDEFTHRESH
:
1696 ret_val
= get_default_threshold(info
, (unsigned long *)arg
);
1698 case CYSETDEFTHRESH
:
1699 ret_val
= set_default_threshold(info
, (unsigned long *)arg
);
1702 ret_val
= get_timeout(info
, (unsigned long *)arg
);
1705 ret_val
= set_timeout(info
, (unsigned long *)arg
);
1707 case CYGETDEFTIMEOUT
:
1708 ret_val
= get_default_timeout(info
, (unsigned long *)arg
);
1710 case CYSETDEFTIMEOUT
:
1711 ret_val
= set_default_timeout(info
, (unsigned long)arg
);
1713 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1714 ret_val
= tty_check_change(tty
);
1717 tty_wait_until_sent(tty
,0);
1719 send_break(info
, HZ
/4); /* 1/4 second */
1721 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1722 ret_val
= tty_check_change(tty
);
1725 tty_wait_until_sent(tty
,0);
1726 send_break(info
, arg
? arg
*(HZ
/10) : HZ
/4);
1729 /* The following commands are incompletely implemented!!! */
1731 ret_val
= put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long *) arg
);
1734 ret_val
= get_user(val
, (unsigned long *) arg
);
1737 tty
->termios
->c_cflag
=
1738 ((tty
->termios
->c_cflag
& ~CLOCAL
) | (val
? CLOCAL
: 0));
1741 ret_val
= get_serial_info(info
, (struct serial_struct
*) arg
);
1744 ret_val
= set_serial_info(info
,
1745 (struct serial_struct
*) arg
);
1748 ret_val
= -ENOIOCTLCMD
;
1751 #ifdef SERIAL_DEBUG_OTHER
1752 printk("cy_ioctl done\n");
1762 cy_set_termios(struct tty_struct
*tty
, struct termios
* old_termios
)
1764 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1766 #ifdef SERIAL_DEBUG_OTHER
1767 printk("cy_set_termios %s\n", tty
->name
);
1770 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1774 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1775 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1779 #ifdef tytso_patch_94Nov25_1726
1780 if (!(old_termios
->c_cflag
& CLOCAL
) &&
1781 (tty
->termios
->c_cflag
& CLOCAL
))
1782 wake_up_interruptible(&info
->open_wait
);
1786 } /* cy_set_termios */
1790 cy_close(struct tty_struct
* tty
, struct file
* filp
)
1792 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
1795 #ifdef SERIAL_DEBUG_OTHER
1796 printk("cy_close %s\n", tty
->name
);
1800 || serial_paranoia_check(info
, tty
->name
, "cy_close")){
1803 #ifdef SERIAL_DEBUG_OPEN
1804 printk("cy_close %s, count = %d\n", tty
->name
, info
->count
);
1807 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1809 * Uh, oh. tty->count is 1, which means that the tty
1810 * structure will be freed. Info->count should always
1811 * be one in these conditions. If it's greater than
1812 * one, we've got real problems, since it means the
1813 * serial port won't be shutdown.
1815 printk("cy_close: bad serial port count; tty->count is 1, "
1816 "info->count is %d\n", info
->count
);
1819 #ifdef SERIAL_DEBUG_COUNT
1820 printk("cyc: %d: decrementing count to %d\n", __LINE__
, info
->count
- 1);
1822 if (--info
->count
< 0) {
1823 printk("cy_close: bad serial port count for ttys%d: %d\n",
1824 info
->line
, info
->count
);
1825 #ifdef SERIAL_DEBUG_COUNT
1826 printk("cyc: %d: setting count to 0\n", __LINE__
);
1832 info
->flags
|= ASYNC_CLOSING
;
1833 if (info
->flags
& ASYNC_INITIALIZED
)
1834 tty_wait_until_sent(tty
, 3000); /* 30 seconds timeout */
1836 if (tty
->driver
->flush_buffer
)
1837 tty
->driver
->flush_buffer(tty
);
1838 tty_ldisc_flush(tty
);
1841 if (info
->blocked_open
) {
1842 if (info
->close_delay
) {
1843 current
->state
= TASK_INTERRUPTIBLE
;
1844 schedule_timeout(info
->close_delay
);
1846 wake_up_interruptible(&info
->open_wait
);
1848 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1849 wake_up_interruptible(&info
->close_wait
);
1851 #ifdef SERIAL_DEBUG_OTHER
1852 printk("cy_close done\n");
1859 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
1862 cy_hangup(struct tty_struct
*tty
)
1864 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
1866 #ifdef SERIAL_DEBUG_OTHER
1867 printk("cy_hangup %s\n", tty
->name
); /* */
1870 if (serial_paranoia_check(info
, tty
->name
, "cy_hangup"))
1877 #ifdef SERIAL_DEBUG_COUNT
1878 printk("cyc: %d: setting count to 0\n", __LINE__
);
1882 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1883 wake_up_interruptible(&info
->open_wait
);
1889 * ------------------------------------------------------------
1890 * cy_open() and friends
1891 * ------------------------------------------------------------
1895 block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1896 struct cyclades_port
*info
)
1898 DECLARE_WAITQUEUE(wait
, current
);
1899 unsigned long flags
;
1902 volatile u_char
*base_addr
= (u_char
*)BASE_ADDR
;
1905 * If the device is in the middle of being closed, then block
1906 * until it's done, and then try again.
1908 if (info
->flags
& ASYNC_CLOSING
) {
1909 interruptible_sleep_on(&info
->close_wait
);
1910 if (info
->flags
& ASYNC_HUP_NOTIFY
){
1913 return -ERESTARTSYS
;
1918 * If non-blocking mode is set, then make the check up front
1921 if (filp
->f_flags
& O_NONBLOCK
) {
1922 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1927 * Block waiting for the carrier detect and the line to become
1928 * free (i.e., not in use by the callout). While we are in
1929 * this loop, info->count is dropped by one, so that
1930 * cy_close() knows when to free things. We restore it upon
1931 * exit, either normal or abnormal.
1934 add_wait_queue(&info
->open_wait
, &wait
);
1935 #ifdef SERIAL_DEBUG_OPEN
1936 printk("block_til_ready before block: %s, count = %d\n",
1937 tty
->name
, info
->count
);/**/
1940 #ifdef SERIAL_DEBUG_COUNT
1941 printk("cyc: %d: decrementing count to %d\n", __LINE__
, info
->count
);
1943 info
->blocked_open
++;
1945 channel
= info
->line
;
1948 local_irq_save(flags
);
1949 base_addr
[CyCAR
] = (u_char
)channel
;
1950 base_addr
[CyMSVR1
] = CyRTS
;
1951 /* CP('S');CP('4'); */
1952 base_addr
[CyMSVR2
] = CyDTR
;
1953 #ifdef SERIAL_DEBUG_DTR
1954 printk("cyc: %d: raising DTR\n", __LINE__
);
1955 printk(" status: 0x%x, 0x%x\n", base_addr
[CyMSVR1
], base_addr
[CyMSVR2
]);
1957 local_irq_restore(flags
);
1958 set_current_state(TASK_INTERRUPTIBLE
);
1959 if (tty_hung_up_p(filp
)
1960 || !(info
->flags
& ASYNC_INITIALIZED
) ){
1961 if (info
->flags
& ASYNC_HUP_NOTIFY
) {
1964 retval
= -ERESTARTSYS
;
1968 local_irq_save(flags
);
1969 base_addr
[CyCAR
] = (u_char
)channel
;
1970 /* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */
1971 if (!(info
->flags
& ASYNC_CLOSING
)
1973 || (base_addr
[CyMSVR1
] & CyDCD
))) {
1974 local_irq_restore(flags
);
1977 local_irq_restore(flags
);
1978 if (signal_pending(current
)) {
1979 retval
= -ERESTARTSYS
;
1982 #ifdef SERIAL_DEBUG_OPEN
1983 printk("block_til_ready blocking: %s, count = %d\n",
1984 tty
->name
, info
->count
);/**/
1988 current
->state
= TASK_RUNNING
;
1989 remove_wait_queue(&info
->open_wait
, &wait
);
1990 if (!tty_hung_up_p(filp
)){
1992 #ifdef SERIAL_DEBUG_COUNT
1993 printk("cyc: %d: incrementing count to %d\n", __LINE__
, info
->count
);
1996 info
->blocked_open
--;
1997 #ifdef SERIAL_DEBUG_OPEN
1998 printk("block_til_ready after blocking: %s, count = %d\n",
1999 tty
->name
, info
->count
);/**/
2003 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2005 } /* block_til_ready */
2008 * This routine is called whenever a serial port is opened. It
2009 * performs the serial-specific initialization for the tty structure.
2012 cy_open(struct tty_struct
*tty
, struct file
* filp
)
2014 struct cyclades_port
*info
;
2019 if ((line
< 0) || (NR_PORTS
<= line
)){
2022 info
= &cy_port
[line
];
2023 if (info
->line
< 0){
2026 #ifdef SERIAL_DEBUG_OTHER
2027 printk("cy_open %s\n", tty
->name
); /* */
2029 if (serial_paranoia_check(info
, tty
->name
, "cy_open")){
2032 #ifdef SERIAL_DEBUG_OPEN
2033 printk("cy_open %s, count = %d\n", tty
->name
, info
->count
);/**/
2036 #ifdef SERIAL_DEBUG_COUNT
2037 printk("cyc: %d: incrementing count to %d\n", __LINE__
, info
->count
);
2039 tty
->driver_data
= info
;
2043 tmp_buf
= (unsigned char *) get_zeroed_page(GFP_KERNEL
);
2050 * Start up serial port
2052 retval
= startup(info
);
2057 retval
= block_til_ready(tty
, filp
, info
);
2059 #ifdef SERIAL_DEBUG_OPEN
2060 printk("cy_open returning after block_til_ready with %d\n",
2066 #ifdef SERIAL_DEBUG_OPEN
2067 printk("cy_open done\n");/**/
2075 * ---------------------------------------------------------------------
2076 * serial167_init() and friends
2078 * serial167_init() is called at boot-time to initialize the serial driver.
2079 * ---------------------------------------------------------------------
2083 * This routine prints out the appropriate serial driver version
2084 * number, and identifies which options were configured into this
2090 printk("MVME166/167 cd2401 driver\n");
2091 } /* show_version */
2093 /* initialize chips on card -- return number of valid
2094 chips (which is number of ports/4) */
2097 * This initialises the hardware to a reasonable state. It should
2098 * probe the chip first so as to copy 166-Bug setup as a default for
2099 * port 0. It initialises CMR to CyASYNC; that is never done again, so
2100 * as to limit the number of CyINIT_CHAN commands in normal running.
2102 * ... I wonder what I should do if this fails ...
2106 mvme167_serial_console_setup(int cflag
)
2108 volatile unsigned char* base_addr
= (u_char
*)BASE_ADDR
;
2111 u_char rcor
, rbpr
, badspeed
= 0;
2112 unsigned long flags
;
2114 local_irq_save(flags
);
2117 * First probe channel zero of the chip, to see what speed has
2121 base_addr
[CyCAR
] = 0;
2123 rcor
= base_addr
[CyRCOR
] << 5;
2124 rbpr
= base_addr
[CyRBPR
];
2126 for (spd
= 0; spd
< sizeof(baud_bpr
); spd
++)
2127 if (rbpr
== baud_bpr
[spd
] && rcor
== baud_co
[spd
])
2129 if (spd
>= sizeof(baud_bpr
)) {
2130 spd
= 14; /* 19200 */
2131 badspeed
= 1; /* Failed to identify speed */
2133 initial_console_speed
= spd
;
2135 /* OK, we have chosen a speed, now reset and reinitialise */
2137 my_udelay(20000L); /* Allow time for any active o/p to complete */
2138 if(base_addr
[CyCCR
] != 0x00){
2139 local_irq_restore(flags
);
2140 /* printk(" chip is never idle (CCR != 0)\n"); */
2144 base_addr
[CyCCR
] = CyCHIP_RESET
; /* Reset the chip */
2147 if(base_addr
[CyGFRCR
] == 0x00){
2148 local_irq_restore(flags
);
2149 /* printk(" chip is not responding (GFRCR stayed 0)\n"); */
2154 * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms
2158 base_addr
[CyTPR
] = 10;
2160 base_addr
[CyPILR1
] = 0x01; /* Interrupt level for modem change */
2161 base_addr
[CyPILR2
] = 0x02; /* Interrupt level for tx ints */
2162 base_addr
[CyPILR3
] = 0x03; /* Interrupt level for rx ints */
2165 * Attempt to set up all channels to something reasonable, and
2166 * bang out a INIT_CHAN command. We should then be able to limit
2167 * the ammount of fiddling we have to do in normal running.
2170 for (ch
= 3; ch
>= 0 ; ch
--) {
2171 base_addr
[CyCAR
] = (u_char
)ch
;
2172 base_addr
[CyIER
] = 0;
2173 base_addr
[CyCMR
] = CyASYNC
;
2174 base_addr
[CyLICR
] = (u_char
)ch
<< 2;
2175 base_addr
[CyLIVR
] = 0x5c;
2176 base_addr
[CyTCOR
] = baud_co
[spd
];
2177 base_addr
[CyTBPR
] = baud_bpr
[spd
];
2178 base_addr
[CyRCOR
] = baud_co
[spd
] >> 5;
2179 base_addr
[CyRBPR
] = baud_bpr
[spd
];
2180 base_addr
[CySCHR1
] = 'Q' & 0x1f;
2181 base_addr
[CySCHR2
] = 'X' & 0x1f;
2182 base_addr
[CySCRL
] = 0;
2183 base_addr
[CySCRH
] = 0;
2184 base_addr
[CyCOR1
] = Cy_8_BITS
| CyPARITY_NONE
;
2185 base_addr
[CyCOR2
] = 0;
2186 base_addr
[CyCOR3
] = Cy_1_STOP
;
2187 base_addr
[CyCOR4
] = baud_cor4
[spd
];
2188 base_addr
[CyCOR5
] = 0;
2189 base_addr
[CyCOR6
] = 0;
2190 base_addr
[CyCOR7
] = 0;
2191 base_addr
[CyRTPRL
] = 2;
2192 base_addr
[CyRTPRH
] = 0;
2193 base_addr
[CyMSVR1
] = 0;
2194 base_addr
[CyMSVR2
] = 0;
2195 write_cy_cmd(base_addr
,CyINIT_CHAN
|CyDIS_RCVR
|CyDIS_XMTR
);
2199 * Now do specials for channel zero....
2202 base_addr
[CyMSVR1
] = CyRTS
;
2203 base_addr
[CyMSVR2
] = CyDTR
;
2204 base_addr
[CyIER
] = CyRxData
;
2205 write_cy_cmd(base_addr
,CyENB_RCVR
|CyENB_XMTR
);
2207 local_irq_restore(flags
);
2209 my_udelay(20000L); /* Let it all settle down */
2211 printk("CD2401 initialised, chip is rev 0x%02x\n", base_addr
[CyGFRCR
]);
2213 printk(" WARNING: Failed to identify line speed, rcor=%02x,rbpr=%02x\n",
2215 } /* serial_console_init */
2217 static struct tty_operations cy_ops
= {
2221 .put_char
= cy_put_char
,
2222 .flush_chars
= cy_flush_chars
,
2223 .write_room
= cy_write_room
,
2224 .chars_in_buffer
= cy_chars_in_buffer
,
2225 .flush_buffer
= cy_flush_buffer
,
2227 .throttle
= cy_throttle
,
2228 .unthrottle
= cy_unthrottle
,
2229 .set_termios
= cy_set_termios
,
2232 .hangup
= cy_hangup
,
2233 .tiocmget
= cy_tiocmget
,
2234 .tiocmset
= cy_tiocmset
,
2236 /* The serial driver boot-time initialization code!
2237 Hardware I/O ports are mapped to character special devices on a
2238 first found, first allocated manner. That is, this code searches
2239 for Cyclom cards in the system. As each is found, it is probed
2240 to discover how many chips (and thus how many ports) are present.
2241 These ports are mapped to the tty ports 64 and upward in monotonic
2242 fashion. If an 8-port card is replaced with a 16-port card, the
2243 port mapping on a following card will shift.
2245 This approach is different from what is used in the other serial
2246 device driver because the Cyclom is more properly a multiplexer,
2247 not just an aggregation of serial ports on one card.
2249 If there are more cards with more ports than have been statically
2250 allocated above, a warning is printed and the extra ports are ignored.
2253 serial167_init(void)
2255 struct cyclades_port
*info
;
2262 struct sigaction sa
;
2265 if (!(mvme16x_config
&MVME16x_CONFIG_GOT_CD2401
))
2268 cy_serial_driver
= alloc_tty_driver(NR_PORTS
);
2269 if (!cy_serial_driver
)
2278 /* Has "console=0,9600n8" been used in bootinfo to change speed? */
2279 if (serial_console_cflag
)
2280 DefSpeed
= serial_console_cflag
& 0017;
2282 DefSpeed
= initial_console_speed
;
2283 serial_console_info
= &cy_port
[0];
2284 serial_console_cflag
= DefSpeed
| CS8
;
2286 serial_console
= 64; /*callout_driver.minor_start*/
2290 /* Initialize the tty_driver structure */
2292 cy_serial_driver
->owner
= THIS_MODULE
;
2293 cy_serial_driver
->devfs_name
= "tts/";
2294 cy_serial_driver
->name
= "ttyS";
2295 cy_serial_driver
->major
= TTY_MAJOR
;
2296 cy_serial_driver
->minor_start
= 64;
2297 cy_serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
2298 cy_serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
2299 cy_serial_driver
->init_termios
= tty_std_termios
;
2300 cy_serial_driver
->init_termios
.c_cflag
=
2301 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2302 cy_serial_driver
->flags
= TTY_DRIVER_REAL_RAW
;
2303 tty_set_operations(cy_serial_driver
, &cy_ops
);
2305 ret
= tty_register_driver(cy_serial_driver
);
2307 printk(KERN_ERR
"Couldn't register MVME166/7 serial driver\n");
2308 put_tty_driver(cy_serial_driver
);
2312 init_bh(CYCLADES_BH
, do_cyclades_bh
);
2316 for (index
= 0; index
< 1; index
++) {
2320 if(port_num
< NR_PORTS
){
2321 while( good_ports
-- && port_num
< NR_PORTS
){
2322 /*** initialize port ***/
2323 info
->magic
= CYCLADES_MAGIC
;
2324 info
->type
= PORT_CIRRUS
;
2326 info
->line
= port_num
;
2327 info
->flags
= STD_COM_FLAGS
;
2329 info
->xmit_fifo_size
= 12;
2330 info
->cor1
= CyPARITY_NONE
|Cy_8_BITS
;
2332 info
->cor3
= Cy_1_STOP
;
2333 info
->cor4
= 0x08; /* _very_ small receive threshold */
2337 info
->tbpr
= baud_bpr
[DefSpeed
]; /* Tx BPR */
2338 info
->tco
= baud_co
[DefSpeed
]; /* Tx CO */
2339 info
->rbpr
= baud_bpr
[DefSpeed
]; /* Rx BPR */
2340 info
->rco
= baud_co
[DefSpeed
] >> 5; /* Rx CO */
2341 info
->close_delay
= 0;
2345 #ifdef SERIAL_DEBUG_COUNT
2346 printk("cyc: %d: setting count to 0\n", __LINE__
);
2348 info
->blocked_open
= 0;
2349 info
->default_threshold
= 0;
2350 info
->default_timeout
= 0;
2351 info
->tqueue
.routine
= do_softint
;
2352 info
->tqueue
.data
= info
;
2353 init_waitqueue_head(&info
->open_wait
);
2354 init_waitqueue_head(&info
->close_wait
);
2357 /*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/
2358 info
->read_status_mask
= CyTIMEOUT
| CySPECHAR
| CyBREAK
2359 | CyPARITY
| CyFRAME
| CyOVERRUN
;
2362 printk("ttyS%d ", info
->line
);
2364 if(!(port_num
& 7)){
2371 while( port_num
< NR_PORTS
){
2375 #ifdef CONFIG_REMOTE_DEBUG
2378 ret
= request_irq(MVME167_IRQ_SER_ERR
, cd2401_rxerr_interrupt
, 0,
2379 "cd2401_errors", cd2401_rxerr_interrupt
);
2381 printk(KERN_ERR
"Could't get cd2401_errors IRQ");
2382 goto cleanup_serial_driver
;
2385 ret
= request_irq(MVME167_IRQ_SER_MODEM
, cd2401_modem_interrupt
, 0,
2386 "cd2401_modem", cd2401_modem_interrupt
);
2388 printk(KERN_ERR
"Could't get cd2401_modem IRQ");
2389 goto cleanup_irq_cd2401_errors
;
2392 ret
= request_irq(MVME167_IRQ_SER_TX
, cd2401_tx_interrupt
, 0,
2393 "cd2401_txints", cd2401_tx_interrupt
);
2395 printk(KERN_ERR
"Could't get cd2401_txints IRQ");
2396 goto cleanup_irq_cd2401_modem
;
2399 ret
= request_irq(MVME167_IRQ_SER_RX
, cd2401_rx_interrupt
, 0,
2400 "cd2401_rxints", cd2401_rx_interrupt
);
2402 printk(KERN_ERR
"Could't get cd2401_rxints IRQ");
2403 goto cleanup_irq_cd2401_txints
;
2406 /* Now we have registered the interrupt handlers, allow the interrupts */
2408 pcc2chip
[PccSCCMICR
] = 0x15; /* Serial ints are level 5 */
2409 pcc2chip
[PccSCCTICR
] = 0x15;
2410 pcc2chip
[PccSCCRICR
] = 0x15;
2412 pcc2chip
[PccIMLR
] = 3; /* Allow PCC2 ints above 3!? */
2415 cleanup_irq_cd2401_txints
:
2416 free_irq(MVME167_IRQ_SER_TX
, cd2401_tx_interrupt
);
2417 cleanup_irq_cd2401_modem
:
2418 free_irq(MVME167_IRQ_SER_MODEM
, cd2401_modem_interrupt
);
2419 cleanup_irq_cd2401_errors
:
2420 free_irq(MVME167_IRQ_SER_ERR
, cd2401_rxerr_interrupt
);
2421 cleanup_serial_driver
:
2422 if (tty_unregister_driver(cy_serial_driver
))
2423 printk(KERN_ERR
"Couldn't unregister MVME166/7 serial driver\n");
2424 put_tty_driver(cy_serial_driver
);
2426 } /* serial167_init */
2428 module_init(serial167_init
);
2431 #ifdef CYCLOM_SHOW_STATUS
2433 show_status(int line_num
)
2435 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
2437 struct cyclades_port
* info
;
2438 unsigned long flags
;
2440 info
= &cy_port
[line_num
];
2441 channel
= info
->line
;
2442 printk(" channel %d\n", channel
);/**/
2444 printk(" cy_port\n");
2445 printk(" card line flags = %d %d %x\n",
2446 info
->card
, info
->line
, info
->flags
);
2447 printk(" *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n",
2448 (long)info
->tty
, info
->read_status_mask
,
2449 info
->timeout
, info
->xmit_fifo_size
);
2450 printk(" cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n",
2451 info
->cor1
, info
->cor2
, info
->cor3
, info
->cor4
, info
->cor5
,
2452 info
->cor6
, info
->cor7
);
2453 printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n",
2454 info
->tbpr
, info
->tco
, info
->rbpr
, info
->rco
);
2455 printk(" close_delay event count = %d %d %d\n",
2456 info
->close_delay
, info
->event
, info
->count
);
2457 printk(" x_char blocked_open = %x %x\n",
2458 info
->x_char
, info
->blocked_open
);
2459 printk(" open_wait = %lx %lx %lx\n",
2460 (long)info
->open_wait
);
2463 local_irq_save(flags
);
2465 /* Global Registers */
2467 printk(" CyGFRCR %x\n", base_addr
[CyGFRCR
]);
2468 printk(" CyCAR %x\n", base_addr
[CyCAR
]);
2469 printk(" CyRISR %x\n", base_addr
[CyRISR
]);
2470 printk(" CyTISR %x\n", base_addr
[CyTISR
]);
2471 printk(" CyMISR %x\n", base_addr
[CyMISR
]);
2472 printk(" CyRIR %x\n", base_addr
[CyRIR
]);
2473 printk(" CyTIR %x\n", base_addr
[CyTIR
]);
2474 printk(" CyMIR %x\n", base_addr
[CyMIR
]);
2475 printk(" CyTPR %x\n", base_addr
[CyTPR
]);
2477 base_addr
[CyCAR
] = (u_char
)channel
;
2479 /* Virtual Registers */
2482 printk(" CyRIVR %x\n", base_addr
[CyRIVR
]);
2483 printk(" CyTIVR %x\n", base_addr
[CyTIVR
]);
2484 printk(" CyMIVR %x\n", base_addr
[CyMIVR
]);
2485 printk(" CyMISR %x\n", base_addr
[CyMISR
]);
2488 /* Channel Registers */
2490 printk(" CyCCR %x\n", base_addr
[CyCCR
]);
2491 printk(" CyIER %x\n", base_addr
[CyIER
]);
2492 printk(" CyCOR1 %x\n", base_addr
[CyCOR1
]);
2493 printk(" CyCOR2 %x\n", base_addr
[CyCOR2
]);
2494 printk(" CyCOR3 %x\n", base_addr
[CyCOR3
]);
2495 printk(" CyCOR4 %x\n", base_addr
[CyCOR4
]);
2496 printk(" CyCOR5 %x\n", base_addr
[CyCOR5
]);
2498 printk(" CyCCSR %x\n", base_addr
[CyCCSR
]);
2499 printk(" CyRDCR %x\n", base_addr
[CyRDCR
]);
2501 printk(" CySCHR1 %x\n", base_addr
[CySCHR1
]);
2502 printk(" CySCHR2 %x\n", base_addr
[CySCHR2
]);
2504 printk(" CySCHR3 %x\n", base_addr
[CySCHR3
]);
2505 printk(" CySCHR4 %x\n", base_addr
[CySCHR4
]);
2506 printk(" CySCRL %x\n", base_addr
[CySCRL
]);
2507 printk(" CySCRH %x\n", base_addr
[CySCRH
]);
2508 printk(" CyLNC %x\n", base_addr
[CyLNC
]);
2509 printk(" CyMCOR1 %x\n", base_addr
[CyMCOR1
]);
2510 printk(" CyMCOR2 %x\n", base_addr
[CyMCOR2
]);
2512 printk(" CyRTPRL %x\n", base_addr
[CyRTPRL
]);
2513 printk(" CyRTPRH %x\n", base_addr
[CyRTPRH
]);
2514 printk(" CyMSVR1 %x\n", base_addr
[CyMSVR1
]);
2515 printk(" CyMSVR2 %x\n", base_addr
[CyMSVR2
]);
2516 printk(" CyRBPR %x\n", base_addr
[CyRBPR
]);
2517 printk(" CyRCOR %x\n", base_addr
[CyRCOR
]);
2518 printk(" CyTBPR %x\n", base_addr
[CyTBPR
]);
2519 printk(" CyTCOR %x\n", base_addr
[CyTCOR
]);
2521 local_irq_restore(flags
);
2527 /* Dummy routine in mvme16x/config.c for now */
2529 /* Serial console setup. Called from linux/init/main.c */
2531 void console_setup(char *str
, int *ints
)
2534 int baud
, bits
, parity
;
2538 if (ints
[0] > 3 || ints
[1] > 3) return;
2540 /* Get baud, bits and parity */
2544 if (ints
[2]) baud
= ints
[2];
2545 if ((s
= strchr(str
, ','))) {
2548 } while(*s
>= '0' && *s
<= '9');
2549 if (*s
) parity
= *s
++;
2550 if (*s
) bits
= *s
- '0';
2553 /* Now construct a cflag setting. */
2590 serial_console_info
= &cy_port
[ints
[1]];
2591 serial_console_cflag
= cflag
;
2592 serial_console
= ints
[1] + 64; /*callout_driver.minor_start*/
2597 * The following is probably out of date for 2.1.x serial console stuff.
2599 * The console is registered early on from arch/m68k/kernel/setup.c, and
2600 * it therefore relies on the chip being setup correctly by 166-Bug. This
2601 * seems reasonable, as the serial port has been used to invoke the system
2602 * boot. It also means that this function must not rely on any data
2603 * initialisation performed by serial167_init() etc.
2605 * Of course, once the console has been registered, we had better ensure
2606 * that serial167_init() doesn't leave the chip non-functional.
2608 * The console must be locked when we get here.
2611 void serial167_console_write(struct console
*co
, const char *str
, unsigned count
)
2613 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
2614 unsigned long flags
;
2615 volatile u_char sink
;
2621 local_irq_save(flags
);
2623 /* Ensure transmitter is enabled! */
2626 base_addr
[CyCAR
] = (u_char
)port
;
2627 while (base_addr
[CyCCR
])
2629 base_addr
[CyCCR
] = CyENB_XMTR
;
2631 ier
= base_addr
[CyIER
];
2632 base_addr
[CyIER
] = CyTxMpty
;
2635 if (pcc2chip
[PccSCCTICR
] & 0x20)
2637 /* We have a Tx int. Acknowledge it */
2638 sink
= pcc2chip
[PccTPIACKR
];
2639 if ((base_addr
[CyLICR
] >> 2) == port
) {
2641 /* Last char of string is now output */
2642 base_addr
[CyTEOIR
] = CyNOTRANS
;
2646 base_addr
[CyTDR
] = '\n';
2651 else if (*str
== '\n') {
2652 base_addr
[CyTDR
] = '\r';
2656 base_addr
[CyTDR
] = *str
++;
2659 base_addr
[CyTEOIR
] = 0;
2662 base_addr
[CyTEOIR
] = CyNOTRANS
;
2666 base_addr
[CyIER
] = ier
;
2668 local_irq_restore(flags
);
2671 static struct tty_driver
*serial167_console_device(struct console
*c
, int *index
)
2674 return cy_serial_driver
;
2678 static int __init
serial167_console_setup(struct console
*co
, char *options
)
2684 static struct console sercons
= {
2686 .write
= serial167_console_write
,
2687 .device
= serial167_console_device
,
2688 .setup
= serial167_console_setup
,
2689 .flags
= CON_PRINTBUFFER
,
2694 static int __init
serial167_console_init(void)
2696 if (vme_brdtype
== VME_TYPE_MVME166
||
2697 vme_brdtype
== VME_TYPE_MVME167
||
2698 vme_brdtype
== VME_TYPE_MVME177
) {
2699 mvme167_serial_console_setup(0);
2700 register_console(&sercons
);
2704 console_initcall(serial167_console_init
);
2706 #ifdef CONFIG_REMOTE_DEBUG
2707 void putDebugChar (int c
)
2709 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
2710 unsigned long flags
;
2711 volatile u_char sink
;
2715 local_irq_save(flags
);
2717 /* Ensure transmitter is enabled! */
2720 base_addr
[CyCAR
] = (u_char
)port
;
2721 while (base_addr
[CyCCR
])
2723 base_addr
[CyCCR
] = CyENB_XMTR
;
2725 ier
= base_addr
[CyIER
];
2726 base_addr
[CyIER
] = CyTxMpty
;
2729 if (pcc2chip
[PccSCCTICR
] & 0x20)
2731 /* We have a Tx int. Acknowledge it */
2732 sink
= pcc2chip
[PccTPIACKR
];
2733 if ((base_addr
[CyLICR
] >> 2) == port
) {
2734 base_addr
[CyTDR
] = c
;
2735 base_addr
[CyTEOIR
] = 0;
2739 base_addr
[CyTEOIR
] = CyNOTRANS
;
2743 base_addr
[CyIER
] = ier
;
2745 local_irq_restore(flags
);
2750 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
2751 unsigned long flags
;
2752 volatile u_char sink
;
2758 if (i
!= debugiq
.in
) {
2760 if (++i
== DEBUG_LEN
)
2765 /* OK, nothing in queue, wait in poll loop */
2767 local_irq_save(flags
);
2769 /* Ensure receiver is enabled! */
2772 base_addr
[CyCAR
] = (u_char
)port
;
2774 while (base_addr
[CyCCR
])
2776 base_addr
[CyCCR
] = CyENB_RCVR
;
2778 ier
= base_addr
[CyIER
];
2779 base_addr
[CyIER
] = CyRxData
;
2782 if (pcc2chip
[PccSCCRICR
] & 0x20)
2784 /* We have a Rx int. Acknowledge it */
2785 sink
= pcc2chip
[PccRPIACKR
];
2786 if ((base_addr
[CyLICR
] >> 2) == port
) {
2787 int cnt
= base_addr
[CyRFOC
];
2790 c
= base_addr
[CyRDR
];
2792 printk ("!! debug char is null (cnt=%d) !!", cnt
);
2796 base_addr
[CyREOIR
] = 0;
2798 if (i
== debugiq
.in
)
2799 panic ("Debug input queue empty!");
2801 if (++i
== DEBUG_LEN
)
2807 base_addr
[CyREOIR
] = CyNOTRANS
;
2811 base_addr
[CyIER
] = ier
;
2813 local_irq_restore(flags
);
2818 void queueDebugChar (int c
)
2824 if (++i
== DEBUG_LEN
)
2826 if (i
!= debugiq
.out
)
2833 unsigned long flags
;
2834 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
2839 local_irq_save(flags
);
2841 for (i
= 0; i
< 4; i
++)
2843 base_addr
[CyCAR
] = i
;
2844 base_addr
[CyLICR
] = i
<< 2;
2847 debugiq
.in
= debugiq
.out
= 0;
2849 base_addr
[CyCAR
] = DEBUG_PORT
;
2854 base_addr
[CyIER
] = 0;
2856 base_addr
[CyCMR
] = CyASYNC
;
2857 base_addr
[CyLICR
] = DEBUG_PORT
<< 2;
2858 base_addr
[CyLIVR
] = 0x5c;
2860 /* tx and rx baud rate */
2862 base_addr
[CyTCOR
] = baud_co
[i
];
2863 base_addr
[CyTBPR
] = baud_bpr
[i
];
2864 base_addr
[CyRCOR
] = baud_co
[i
] >> 5;
2865 base_addr
[CyRBPR
] = baud_bpr
[i
];
2867 /* set line characteristics according configuration */
2869 base_addr
[CySCHR1
] = 0;
2870 base_addr
[CySCHR2
] = 0;
2871 base_addr
[CySCRL
] = 0;
2872 base_addr
[CySCRH
] = 0;
2873 base_addr
[CyCOR1
] = Cy_8_BITS
| CyPARITY_NONE
;
2874 base_addr
[CyCOR2
] = 0;
2875 base_addr
[CyCOR3
] = Cy_1_STOP
;
2876 base_addr
[CyCOR4
] = baud_cor4
[i
];
2877 base_addr
[CyCOR5
] = 0;
2878 base_addr
[CyCOR6
] = 0;
2879 base_addr
[CyCOR7
] = 0;
2881 write_cy_cmd(base_addr
,CyINIT_CHAN
);
2882 write_cy_cmd(base_addr
,CyENB_RCVR
);
2884 base_addr
[CyCAR
] = DEBUG_PORT
; /* !!! Is this needed? */
2886 base_addr
[CyRTPRL
] = 2;
2887 base_addr
[CyRTPRH
] = 0;
2889 base_addr
[CyMSVR1
] = CyRTS
;
2890 base_addr
[CyMSVR2
] = CyDTR
;
2892 base_addr
[CyIER
] = CyRxData
;
2894 local_irq_restore(flags
);
2900 MODULE_LICENSE("GPL");