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
[] = {
120 #define NR_PORTS ARRAY_SIZE(cy_port)
123 * This is used to look up the divisor speeds and the timeouts
124 * We're normally limited to 15 distinct baud rates. The extra
125 * are accessed via settings in info->flags.
126 * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
127 * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
130 static int baud_table
[] = {
131 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
132 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000,
136 static char baud_co
[] = { /* 25 MHz clock option table */
137 /* value => 00 01 02 03 04 */
138 /* divide by 8 32 128 512 2048 */
139 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
140 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
142 static char baud_bpr
[] = { /* 25 MHz baud rate period table */
143 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
144 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15};
147 /* I think 166 brd clocks 2401 at 20MHz.... */
149 /* These values are written directly to tcor, and >> 5 for writing to rcor */
150 static u_char baud_co
[] = { /* 20 MHz clock option table */
151 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x60, 0x60, 0x40,
152 0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
154 /* These values written directly to tbpr/rbpr */
155 static u_char baud_bpr
[] = { /* 20 MHz baud rate period table */
156 0x00, 0xc0, 0x80, 0x58, 0x6c, 0x40, 0xc0, 0x81, 0x40, 0x81,
157 0x57, 0x40, 0x81, 0x40, 0x81, 0x40, 0x2b, 0x20, 0x15, 0x10};
159 static u_char baud_cor4
[] = { /* receive threshold */
160 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
161 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07};
165 static void shutdown(struct cyclades_port
*);
166 static int startup (struct cyclades_port
*);
167 static void cy_throttle(struct tty_struct
*);
168 static void cy_unthrottle(struct tty_struct
*);
169 static void config_setup(struct cyclades_port
*);
170 extern void console_print(const char *);
171 #ifdef CYCLOM_SHOW_STATUS
172 static void show_status(int);
175 #ifdef CONFIG_REMOTE_DEBUG
176 static void debug_setup(void);
177 void queueDebugChar (int c
);
178 int getDebugChar(void);
181 #define DEBUG_LEN 256
186 unsigned char buf
[DEBUG_LEN
];
193 * I have my own version of udelay(), as it is needed when initialising
194 * the chip, before the delay loop has been calibrated. Should probably
195 * reference one of the vmechip2 or pccchip2 counter for an accurate
196 * delay, but this wild guess will do for now.
199 void my_udelay (long us
)
202 volatile u_char
*p
= &x
;
206 for (i
= 100; i
; i
--)
211 serial_paranoia_check(struct cyclades_port
*info
, char *name
,
214 #ifdef SERIAL_PARANOIA_CHECK
215 static const char *badmagic
=
216 "Warning: bad magic number for serial struct (%s) in %s\n";
217 static const char *badinfo
=
218 "Warning: null cyclades_port for (%s) in %s\n";
219 static const char *badrange
=
220 "Warning: cyclades_port out of range for (%s) in %s\n";
223 printk(badinfo
, name
, routine
);
227 if( (long)info
< (long)(&cy_port
[0])
228 || (long)(&cy_port
[NR_PORTS
]) < (long)info
){
229 printk(badrange
, name
, routine
);
233 if (info
->magic
!= CYCLADES_MAGIC
) {
234 printk(badmagic
, 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
);
256 local_irq_save(flags
);
259 local_irq_restore(flags
);
262 void CP1(int data
) { (data
<10)? CP(data
+'0'): CP(data
+'A'-10); }/* CP1 */
263 void CP2(int data
) { CP1((data
>>4) & 0x0f); CP1( data
& 0x0f); }/* CP2 */
264 void CP4(int data
) { CP2((data
>>8) & 0xff); CP2(data
& 0xff); }/* CP4 */
265 void CP8(long data
) { CP4((data
>>16) & 0xffff); CP4(data
& 0xffff); }/* CP8 */
268 /* This routine waits up to 1000 micro-seconds for the previous
269 command to the Cirrus chip to complete and then issues the
270 new command. An error is returned if the previous command
271 didn't finish within the time limit.
274 write_cy_cmd(volatile u_char
*base_addr
, u_char cmd
)
279 local_irq_save(flags
);
280 /* Check to see that the previous command has completed */
281 for(i
= 0 ; i
< 100 ; i
++){
282 if (base_addr
[CyCCR
] == 0){
287 /* if the CCR never cleared, the previous command
288 didn't finish within the "reasonable time" */
290 local_irq_restore(flags
);
294 /* Issue the new command */
295 base_addr
[CyCCR
] = cmd
;
296 local_irq_restore(flags
);
301 /* cy_start and cy_stop provide software output flow control as a
302 function of XON/XOFF, software CTS, and other such stuff. */
305 cy_stop(struct tty_struct
*tty
)
307 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
308 volatile unsigned char *base_addr
= (unsigned char *)BASE_ADDR
;
312 #ifdef SERIAL_DEBUG_OTHER
313 printk("cy_stop %s\n", tty
->name
); /* */
316 if (serial_paranoia_check(info
, tty
->name
, "cy_stop"))
319 channel
= info
->line
;
321 local_irq_save(flags
);
322 base_addr
[CyCAR
] = (u_char
)(channel
); /* index channel */
323 base_addr
[CyIER
] &= ~(CyTxMpty
|CyTxRdy
);
324 local_irq_restore(flags
);
330 cy_start(struct tty_struct
*tty
)
332 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
333 volatile unsigned char *base_addr
= (unsigned char *)BASE_ADDR
;
337 #ifdef SERIAL_DEBUG_OTHER
338 printk("cy_start %s\n", tty
->name
); /* */
341 if (serial_paranoia_check(info
, tty
->name
, "cy_start"))
344 channel
= info
->line
;
346 local_irq_save(flags
);
347 base_addr
[CyCAR
] = (u_char
)(channel
);
348 base_addr
[CyIER
] |= CyTxMpty
;
349 local_irq_restore(flags
);
356 * This routine is used by the interrupt handler to schedule
357 * processing in the software interrupt portion of the driver
358 * (also known as the "bottom half"). This can be called any
359 * number of times for any channel without harm.
362 cy_sched_event(struct cyclades_port
*info
, int event
)
364 info
->event
|= 1 << event
; /* remember what kind of event and who */
365 schedule_work(&info
->tqueue
);
366 } /* cy_sched_event */
369 /* The real interrupt service routines are called
370 whenever the card wants its hand held--chars
371 received, out buffer empty, modem change, etc.
374 cd2401_rxerr_interrupt(int irq
, void *dev_id
)
376 struct tty_struct
*tty
;
377 struct cyclades_port
*info
;
378 volatile unsigned char *base_addr
= (unsigned char *)BASE_ADDR
;
379 unsigned char err
, rfoc
;
383 /* determine the channel and change to that context */
384 channel
= (u_short
) (base_addr
[CyLICR
] >> 2);
385 info
= &cy_port
[channel
];
386 info
->last_active
= jiffies
;
388 if ((err
= base_addr
[CyRISR
]) & CyTIMEOUT
) {
389 /* This is a receive timeout interrupt, ignore it */
390 base_addr
[CyREOIR
] = CyNOTRANS
;
394 /* Read a byte of data if there is any - assume the error
395 * is associated with this character */
397 if ((rfoc
= base_addr
[CyRFOC
]) != 0)
398 data
= base_addr
[CyRDR
];
402 /* if there is nowhere to put the data, discard it */
404 base_addr
[CyREOIR
] = rfoc
? 0 : CyNOTRANS
;
407 else { /* there is an open port for this data */
409 if(err
& info
->ignore_status_mask
){
410 base_addr
[CyREOIR
] = rfoc
? 0 : CyNOTRANS
;
413 if (tty_buffer_request_room(tty
, 1) != 0){
414 if (err
& info
->read_status_mask
){
416 tty_insert_flip_char(tty
, data
, TTY_BREAK
);
417 if (info
->flags
& ASYNC_SAK
){
420 }else if(err
& CyFRAME
){
421 tty_insert_flip_char(tty
, data
, TTY_FRAME
);
422 }else if(err
& CyPARITY
){
423 tty_insert_flip_char(tty
, data
, TTY_PARITY
);
424 }else if(err
& CyOVERRUN
){
425 tty_insert_flip_char(tty
, 0, TTY_OVERRUN
);
427 If the flip buffer itself is
428 overflowing, we still loose
429 the next incoming character.
431 if (tty_buffer_request_room(tty
, 1) != 0){
432 tty_insert_flip_char(tty
, data
, TTY_FRAME
);
434 /* These two conditions may imply */
435 /* a normal read should be done. */
436 /* else if(data & CyTIMEOUT) */
437 /* else if(data & CySPECHAR) */
439 tty_insert_flip_char(tty
, 0, TTY_NORMAL
);
442 tty_insert_flip_char(tty
, data
, TTY_NORMAL
);
445 /* there was a software buffer overrun
446 and nothing could be done about it!!! */
449 tty_schedule_flip(tty
);
451 base_addr
[CyREOIR
] = rfoc
? 0 : CyNOTRANS
;
453 } /* cy_rxerr_interrupt */
456 cd2401_modem_interrupt(int irq
, void *dev_id
)
458 struct cyclades_port
*info
;
459 volatile unsigned char *base_addr
= (unsigned char *)BASE_ADDR
;
465 /* determine the channel and change to that context */
466 channel
= (u_short
) (base_addr
[CyLICR
] >> 2);
467 info
= &cy_port
[channel
];
468 info
->last_active
= jiffies
;
470 mdm_change
= base_addr
[CyMISR
];
471 mdm_status
= base_addr
[CyMSVR1
];
473 if(info
->tty
== 0){ /* nowhere to put the data, ignore it */
476 if((mdm_change
& CyDCD
)
477 && (info
->flags
& ASYNC_CHECK_CD
)){
478 if(mdm_status
& CyDCD
){
480 cy_sched_event(info
, Cy_EVENT_OPEN_WAKEUP
);
483 cy_sched_event(info
, Cy_EVENT_HANGUP
);
486 if((mdm_change
& CyCTS
)
487 && (info
->flags
& ASYNC_CTS_FLOW
)){
488 if(info
->tty
->stopped
){
489 if(mdm_status
& CyCTS
){
490 /* !!! cy_start isn't used because... */
491 info
->tty
->stopped
= 0;
492 base_addr
[CyIER
] |= CyTxMpty
;
493 cy_sched_event(info
, Cy_EVENT_WRITE_WAKEUP
);
496 if(!(mdm_status
& CyCTS
)){
497 /* !!! cy_stop isn't used because... */
498 info
->tty
->stopped
= 1;
499 base_addr
[CyIER
] &= ~(CyTxMpty
|CyTxRdy
);
503 if(mdm_status
& CyDSR
){
506 base_addr
[CyMEOIR
] = 0;
508 } /* cy_modem_interrupt */
511 cd2401_tx_interrupt(int irq
, void *dev_id
)
513 struct cyclades_port
*info
;
514 volatile unsigned char *base_addr
= (unsigned char *)BASE_ADDR
;
516 int char_count
, saved_cnt
;
519 /* determine the channel and change to that context */
520 channel
= (u_short
) (base_addr
[CyLICR
] >> 2);
522 #ifdef CONFIG_REMOTE_DEBUG
523 if (channel
== DEBUG_PORT
) {
524 panic ("TxInt on debug port!!!");
528 info
= &cy_port
[channel
];
530 /* validate the port number (as configured and open) */
531 if( (channel
< 0) || (NR_PORTS
<= channel
) ){
532 base_addr
[CyIER
] &= ~(CyTxMpty
|CyTxRdy
);
533 base_addr
[CyTEOIR
] = CyNOTRANS
;
536 info
->last_active
= jiffies
;
538 base_addr
[CyIER
] &= ~(CyTxMpty
|CyTxRdy
);
539 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
540 cy_sched_event(info
, Cy_EVENT_WRITE_WAKEUP
);
542 base_addr
[CyTEOIR
] = CyNOTRANS
;
546 /* load the on-chip space available for outbound data */
547 saved_cnt
= char_count
= base_addr
[CyTFTC
];
549 if(info
->x_char
) { /* send special char */
550 outch
= info
->x_char
;
551 base_addr
[CyTDR
] = outch
;
557 /* The Cirrus chip requires the "Embedded Transmit
558 Commands" of start break, delay, and end break
559 sequences to be sent. The duration of the
560 break is given in TICs, which runs at HZ
561 (typically 100) and the PPR runs at 200 Hz,
562 so the delay is duration * 200/HZ, and thus a
563 break can run from 1/100 sec to about 5/4 sec.
564 Need to check these values - RGH 141095.
566 base_addr
[CyTDR
] = 0; /* start break */
567 base_addr
[CyTDR
] = 0x81;
568 base_addr
[CyTDR
] = 0; /* delay a bit */
569 base_addr
[CyTDR
] = 0x82;
570 base_addr
[CyTDR
] = info
->x_break
*200/HZ
;
571 base_addr
[CyTDR
] = 0; /* terminate break */
572 base_addr
[CyTDR
] = 0x83;
577 while (char_count
> 0){
578 if (!info
->xmit_cnt
){
579 base_addr
[CyIER
] &= ~(CyTxMpty
|CyTxRdy
);
582 if (info
->xmit_buf
== 0){
583 base_addr
[CyIER
] &= ~(CyTxMpty
|CyTxRdy
);
586 if (info
->tty
->stopped
|| info
->tty
->hw_stopped
){
587 base_addr
[CyIER
] &= ~(CyTxMpty
|CyTxRdy
);
590 /* Because the Embedded Transmit Commands have been
591 enabled, we must check to see if the escape
592 character, NULL, is being sent. If it is, we
593 must ensure that there is room for it to be
594 doubled in the output stream. Therefore we
595 no longer advance the pointer when the character
596 is fetched, but rather wait until after the check
597 for a NULL output character. (This is necessary
598 because there may not be room for the two chars
599 needed to send a NULL.
601 outch
= info
->xmit_buf
[info
->xmit_tail
];
604 info
->xmit_tail
= (info
->xmit_tail
+ 1)
606 base_addr
[CyTDR
] = outch
;
611 info
->xmit_tail
= (info
->xmit_tail
+ 1)
613 base_addr
[CyTDR
] = outch
;
614 base_addr
[CyTDR
] = 0;
623 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
624 cy_sched_event(info
, Cy_EVENT_WRITE_WAKEUP
);
626 base_addr
[CyTEOIR
] = (char_count
!= saved_cnt
) ? 0 : CyNOTRANS
;
628 } /* cy_tx_interrupt */
631 cd2401_rx_interrupt(int irq
, void *dev_id
)
633 struct tty_struct
*tty
;
634 struct cyclades_port
*info
;
635 volatile unsigned char *base_addr
= (unsigned char *)BASE_ADDR
;
642 /* determine the channel and change to that context */
643 channel
= (u_short
) (base_addr
[CyLICR
] >> 2);
644 info
= &cy_port
[channel
];
645 info
->last_active
= jiffies
;
646 save_cnt
= char_count
= base_addr
[CyRFOC
];
648 #ifdef CONFIG_REMOTE_DEBUG
649 if (channel
== DEBUG_PORT
) {
650 while (char_count
--) {
651 data
= base_addr
[CyRDR
];
652 queueDebugChar(data
);
657 /* if there is nowhere to put the data, discard it */
660 data
= base_addr
[CyRDR
];
662 }else{ /* there is an open port for this data */
664 /* load # characters available from the chip */
666 #ifdef CYCLOM_ENABLE_MONITORING
667 ++info
->mon
.int_count
;
668 info
->mon
.char_count
+= char_count
;
669 if (char_count
> info
->mon
.char_max
)
670 info
->mon
.char_max
= char_count
;
671 info
->mon
.char_last
= char_count
;
673 len
= tty_buffer_request_room(tty
, char_count
);
675 data
= base_addr
[CyRDR
];
676 tty_insert_flip_char(tty
, data
, TTY_NORMAL
);
677 #ifdef CYCLOM_16Y_HACK
681 tty_schedule_flip(tty
);
684 base_addr
[CyREOIR
] = save_cnt
? 0 : CyNOTRANS
;
686 } /* cy_rx_interrupt */
689 * This routine is used to handle the "bottom half" processing for the
690 * serial driver, known also the "software interrupt" processing.
691 * This processing is done at the kernel interrupt level, after the
692 * cy#/_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
693 * is where time-consuming activities which can not be done in the
694 * interrupt driver proper are done; the interrupt driver schedules
695 * them using cy_sched_event(), and they get done here.
697 * This is done through one level of indirection--the task queue.
698 * When a hardware interrupt service routine wants service by the
699 * driver's bottom half, it enqueues the appropriate tq_struct (one
700 * per port) to the keventd work queue and sets a request flag
701 * that the work queue be processed.
703 * Although this may seem unwieldy, it gives the system a way to
704 * pass an argument (in this case the pointer to the cyclades_port
705 * structure) to the bottom half of the driver. Previous kernels
706 * had to poll every port to see if that port needed servicing.
709 do_softint(struct work_struct
*ugly_api
)
711 struct cyclades_port
*info
= container_of(ugly_api
, struct cyclades_port
, tqueue
);
712 struct tty_struct
*tty
;
718 if (test_and_clear_bit(Cy_EVENT_HANGUP
, &info
->event
)) {
719 tty_hangup(info
->tty
);
720 wake_up_interruptible(&info
->open_wait
);
721 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
723 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP
, &info
->event
)) {
724 wake_up_interruptible(&info
->open_wait
);
726 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP
, &info
->event
)) {
732 /* This is called whenever a port becomes active;
733 interrupts are enabled and DTR & RTS are turned on.
736 startup(struct cyclades_port
* info
)
739 volatile unsigned char *base_addr
= (unsigned char *)BASE_ADDR
;
742 if (info
->flags
& ASYNC_INITIALIZED
){
748 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
752 if (!info
->xmit_buf
){
753 info
->xmit_buf
= (unsigned char *) get_zeroed_page (GFP_KERNEL
);
754 if (!info
->xmit_buf
){
761 channel
= info
->line
;
763 #ifdef SERIAL_DEBUG_OPEN
764 printk("startup channel %d\n", channel
);
767 local_irq_save(flags
);
768 base_addr
[CyCAR
] = (u_char
)channel
;
769 write_cy_cmd(base_addr
,CyENB_RCVR
|CyENB_XMTR
);
771 base_addr
[CyCAR
] = (u_char
)channel
; /* !!! Is this needed? */
772 base_addr
[CyMSVR1
] = CyRTS
;
773 /* CP('S');CP('1'); */
774 base_addr
[CyMSVR2
] = CyDTR
;
776 #ifdef SERIAL_DEBUG_DTR
777 printk("cyc: %d: raising DTR\n", __LINE__
);
778 printk(" status: 0x%x, 0x%x\n", base_addr
[CyMSVR1
], base_addr
[CyMSVR2
]);
781 base_addr
[CyIER
] |= CyRxData
;
782 info
->flags
|= ASYNC_INITIALIZED
;
785 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
787 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
789 local_irq_restore(flags
);
791 #ifdef SERIAL_DEBUG_OPEN
798 start_xmit( struct cyclades_port
*info
)
801 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
804 channel
= info
->line
;
805 local_irq_save(flags
);
806 base_addr
[CyCAR
] = channel
;
807 base_addr
[CyIER
] |= CyTxMpty
;
808 local_irq_restore(flags
);
812 * This routine shuts down a serial port; interrupts are disabled,
813 * and DTR is dropped if the hangup on close termio flag is on.
816 shutdown(struct cyclades_port
* info
)
819 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
822 if (!(info
->flags
& ASYNC_INITIALIZED
)){
827 channel
= info
->line
;
829 #ifdef SERIAL_DEBUG_OPEN
830 printk("shutdown channel %d\n", channel
);
833 /* !!! REALLY MUST WAIT FOR LAST CHARACTER TO BE
834 SENT BEFORE DROPPING THE LINE !!! (Perhaps
835 set some flag that is read when XMTY happens.)
836 Other choices are to delay some fixed interval
837 or schedule some later processing.
839 local_irq_save(flags
);
841 free_page((unsigned long) info
->xmit_buf
);
842 info
->xmit_buf
= NULL
;
845 base_addr
[CyCAR
] = (u_char
)channel
;
846 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
847 base_addr
[CyMSVR1
] = 0;
848 /* CP('C');CP('1'); */
849 base_addr
[CyMSVR2
] = 0;
850 #ifdef SERIAL_DEBUG_DTR
851 printk("cyc: %d: dropping DTR\n", __LINE__
);
852 printk(" status: 0x%x, 0x%x\n", base_addr
[CyMSVR1
], base_addr
[CyMSVR2
]);
855 write_cy_cmd(base_addr
,CyDIS_RCVR
);
856 /* it may be appropriate to clear _XMIT at
857 some later date (after testing)!!! */
860 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
862 info
->flags
&= ~ASYNC_INITIALIZED
;
863 local_irq_restore(flags
);
865 #ifdef SERIAL_DEBUG_OPEN
872 * This routine finds or computes the various line characteristics.
875 config_setup(struct cyclades_port
* info
)
878 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
882 unsigned char ti
, need_init_chan
= 0;
884 if (!info
->tty
|| !info
->tty
->termios
){
887 if (info
->line
== -1){
890 cflag
= info
->tty
->termios
->c_cflag
;
895 /* Starting with kernel 1.1.65, there is direct support for
896 higher baud rates. The following code supports those
897 changes. The conditional aspect allows this driver to be
898 used for earlier as well as later kernel versions. (The
899 mapping is slightly different from serial.c because there
900 is still the possibility of supporting 75 kbit/sec with
906 else if(i
== B115200
)
913 info
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
917 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
919 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
922 /* Don't ever change the speed of the console port. It will
923 * run at the speed specified in bootinfo, or at 19.2K */
924 /* Actually, it should run at whatever speed 166Bug was using */
925 /* Note info->timeout isn't used at present */
926 if (info
!= serial_console_info
) {
927 info
->tbpr
= baud_bpr
[i
]; /* Tx BPR */
928 info
->tco
= baud_co
[i
]; /* Tx CO */
929 info
->rbpr
= baud_bpr
[i
]; /* Rx BPR */
930 info
->rco
= baud_co
[i
] >> 5; /* Rx CO */
931 if (baud_table
[i
] == 134) {
932 info
->timeout
= (info
->xmit_fifo_size
*HZ
*30/269) + 2;
933 /* get it right for 134.5 baud */
934 } else if (baud_table
[i
]) {
935 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud_table
[i
]) + 2;
936 /* this needs to be propagated into the card info */
941 /* By tradition (is it a standard?) a baud rate of zero
942 implies the line should be/has been closed. A bit
943 later in this routine such a test is performed. */
945 /* byte size and parity */
949 info
->cor4
= (info
->default_threshold
950 ? info
->default_threshold
951 : baud_cor4
[i
]); /* receive threshold */
952 /* Following two lines added 101295, RGH. */
953 /* It is obviously wrong to access CyCORx, and not info->corx here,
954 * try and remember to fix it later! */
955 channel
= info
->line
;
956 base_addr
[CyCAR
] = (u_char
)channel
;
957 if (C_CLOCAL(info
->tty
)) {
958 if (base_addr
[CyIER
] & CyMdmCh
)
959 base_addr
[CyIER
] &= ~CyMdmCh
; /* without modem intr */
960 /* ignore 1->0 modem transitions */
961 if (base_addr
[CyCOR4
] & (CyDSR
|CyCTS
|CyDCD
))
962 base_addr
[CyCOR4
] &= ~(CyDSR
|CyCTS
|CyDCD
);
963 /* ignore 0->1 modem transitions */
964 if (base_addr
[CyCOR5
] & (CyDSR
|CyCTS
|CyDCD
))
965 base_addr
[CyCOR5
] &= ~(CyDSR
|CyCTS
|CyDCD
);
967 if ((base_addr
[CyIER
] & CyMdmCh
) != CyMdmCh
)
968 base_addr
[CyIER
] |= CyMdmCh
; /* with modem intr */
969 /* act on 1->0 modem transitions */
970 if ((base_addr
[CyCOR4
] & (CyDSR
|CyCTS
|CyDCD
)) != (CyDSR
|CyCTS
|CyDCD
))
971 base_addr
[CyCOR4
] |= CyDSR
|CyCTS
|CyDCD
;
972 /* act on 0->1 modem transitions */
973 if ((base_addr
[CyCOR5
] & (CyDSR
|CyCTS
|CyDCD
)) != (CyDSR
|CyCTS
|CyDCD
))
974 base_addr
[CyCOR5
] |= CyDSR
|CyCTS
|CyDCD
;
976 info
->cor3
= (cflag
& CSTOPB
) ? Cy_2_STOP
: Cy_1_STOP
;
978 switch(cflag
& CSIZE
){
980 info
->cor1
= Cy_5_BITS
;
983 info
->cor1
= Cy_6_BITS
;
986 info
->cor1
= Cy_7_BITS
;
989 info
->cor1
= Cy_8_BITS
;
994 info
->cor1
|= CyPARITY_O
;
996 info
->cor1
|= CyPARITY_E
;
999 info
->cor1
|= CyPARITY_NONE
;
1002 /* CTS flow control flag */
1004 /* Don't complcate matters for now! RGH 141095 */
1005 if (cflag
& CRTSCTS
){
1006 info
->flags
|= ASYNC_CTS_FLOW
;
1007 info
->cor2
|= CyCtsAE
;
1009 info
->flags
&= ~ASYNC_CTS_FLOW
;
1010 info
->cor2
&= ~CyCtsAE
;
1014 info
->flags
&= ~ASYNC_CHECK_CD
;
1016 info
->flags
|= ASYNC_CHECK_CD
;
1018 /***********************************************
1019 The hardware option, CyRtsAO, presents RTS when
1020 the chip has characters to send. Since most modems
1021 use RTS as reverse (inbound) flow control, this
1022 option is not used. If inbound flow control is
1023 necessary, DTR can be programmed to provide the
1024 appropriate signals for use with a non-standard
1025 cable. Contact Marcio Saito for details.
1026 ***********************************************/
1028 channel
= info
->line
;
1030 local_irq_save(flags
);
1031 base_addr
[CyCAR
] = (u_char
)channel
;
1033 /* CyCMR set once only in mvme167_init_serial() */
1034 if (base_addr
[CyLICR
] != channel
<< 2)
1035 base_addr
[CyLICR
] = channel
<< 2;
1036 if (base_addr
[CyLIVR
] != 0x5c)
1037 base_addr
[CyLIVR
] = 0x5c;
1039 /* tx and rx baud rate */
1041 if (base_addr
[CyCOR1
] != info
->cor1
)
1043 if (base_addr
[CyTCOR
] != info
->tco
)
1044 base_addr
[CyTCOR
] = info
->tco
;
1045 if (base_addr
[CyTBPR
] != info
->tbpr
)
1046 base_addr
[CyTBPR
] = info
->tbpr
;
1047 if (base_addr
[CyRCOR
] != info
->rco
)
1048 base_addr
[CyRCOR
] = info
->rco
;
1049 if (base_addr
[CyRBPR
] != info
->rbpr
)
1050 base_addr
[CyRBPR
] = info
->rbpr
;
1052 /* set line characteristics according configuration */
1054 if (base_addr
[CySCHR1
] != START_CHAR(info
->tty
))
1055 base_addr
[CySCHR1
] = START_CHAR(info
->tty
);
1056 if (base_addr
[CySCHR2
] != STOP_CHAR(info
->tty
))
1057 base_addr
[CySCHR2
] = STOP_CHAR(info
->tty
);
1058 if (base_addr
[CySCRL
] != START_CHAR(info
->tty
))
1059 base_addr
[CySCRL
] = START_CHAR(info
->tty
);
1060 if (base_addr
[CySCRH
] != START_CHAR(info
->tty
))
1061 base_addr
[CySCRH
] = START_CHAR(info
->tty
);
1062 if (base_addr
[CyCOR1
] != info
->cor1
)
1063 base_addr
[CyCOR1
] = info
->cor1
;
1064 if (base_addr
[CyCOR2
] != info
->cor2
)
1065 base_addr
[CyCOR2
] = info
->cor2
;
1066 if (base_addr
[CyCOR3
] != info
->cor3
)
1067 base_addr
[CyCOR3
] = info
->cor3
;
1068 if (base_addr
[CyCOR4
] != info
->cor4
)
1069 base_addr
[CyCOR4
] = info
->cor4
;
1070 if (base_addr
[CyCOR5
] != info
->cor5
)
1071 base_addr
[CyCOR5
] = info
->cor5
;
1072 if (base_addr
[CyCOR6
] != info
->cor6
)
1073 base_addr
[CyCOR6
] = info
->cor6
;
1074 if (base_addr
[CyCOR7
] != info
->cor7
)
1075 base_addr
[CyCOR7
] = info
->cor7
;
1078 write_cy_cmd(base_addr
,CyINIT_CHAN
);
1080 base_addr
[CyCAR
] = (u_char
)channel
; /* !!! Is this needed? */
1082 /* 2ms default rx timeout */
1083 ti
= info
->default_timeout
? info
->default_timeout
: 0x02;
1084 if (base_addr
[CyRTPRL
] != ti
)
1085 base_addr
[CyRTPRL
] = ti
;
1086 if (base_addr
[CyRTPRH
] != 0)
1087 base_addr
[CyRTPRH
] = 0;
1089 /* Set up RTS here also ????? RGH 141095 */
1090 if(i
== 0){ /* baud rate is zero, turn off line */
1091 if ((base_addr
[CyMSVR2
] & CyDTR
) == CyDTR
)
1092 base_addr
[CyMSVR2
] = 0;
1093 #ifdef SERIAL_DEBUG_DTR
1094 printk("cyc: %d: dropping DTR\n", __LINE__
);
1095 printk(" status: 0x%x, 0x%x\n", base_addr
[CyMSVR1
], base_addr
[CyMSVR2
]);
1098 if ((base_addr
[CyMSVR2
] & CyDTR
) != CyDTR
)
1099 base_addr
[CyMSVR2
] = CyDTR
;
1100 #ifdef SERIAL_DEBUG_DTR
1101 printk("cyc: %d: raising DTR\n", __LINE__
);
1102 printk(" status: 0x%x, 0x%x\n", base_addr
[CyMSVR1
], base_addr
[CyMSVR2
]);
1107 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1110 local_irq_restore(flags
);
1112 } /* config_setup */
1116 cy_put_char(struct tty_struct
*tty
, unsigned char ch
)
1118 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1119 unsigned long flags
;
1121 #ifdef SERIAL_DEBUG_IO
1122 printk("cy_put_char %s(0x%02x)\n", tty
->name
, ch
);
1125 if (serial_paranoia_check(info
, tty
->name
, "cy_put_char"))
1128 if (!info
->xmit_buf
)
1131 local_irq_save(flags
);
1132 if (info
->xmit_cnt
>= PAGE_SIZE
- 1) {
1133 local_irq_restore(flags
);
1137 info
->xmit_buf
[info
->xmit_head
++] = ch
;
1138 info
->xmit_head
&= PAGE_SIZE
- 1;
1140 local_irq_restore(flags
);
1145 cy_flush_chars(struct tty_struct
*tty
)
1147 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1148 unsigned long flags
;
1149 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1152 #ifdef SERIAL_DEBUG_IO
1153 printk("cy_flush_chars %s\n", tty
->name
); /* */
1156 if (serial_paranoia_check(info
, tty
->name
, "cy_flush_chars"))
1159 if (info
->xmit_cnt
<= 0 || tty
->stopped
1160 || tty
->hw_stopped
|| !info
->xmit_buf
)
1163 channel
= info
->line
;
1165 local_irq_save(flags
);
1166 base_addr
[CyCAR
] = channel
;
1167 base_addr
[CyIER
] |= CyTxMpty
;
1168 local_irq_restore(flags
);
1169 } /* cy_flush_chars */
1172 /* This routine gets called when tty_write has put something into
1173 the write_queue. If the port is not already transmitting stuff,
1174 start it off by enabling interrupts. The interrupt service
1175 routine will then ensure that the characters are sent. If the
1176 port is already active, there is no need to kick it.
1179 cy_write(struct tty_struct
* tty
,
1180 const unsigned char *buf
, int count
)
1182 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1183 unsigned long flags
;
1186 #ifdef SERIAL_DEBUG_IO
1187 printk("cy_write %s\n", tty
->name
); /* */
1190 if (serial_paranoia_check(info
, tty
->name
, "cy_write")){
1194 if (!info
->xmit_buf
){
1199 local_irq_save(flags
);
1200 c
= min_t(int, count
, min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1201 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1203 local_irq_restore(flags
);
1207 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
1208 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
1209 info
->xmit_cnt
+= c
;
1210 local_irq_restore(flags
);
1219 && !tty
->hw_stopped
) {
1227 cy_write_room(struct tty_struct
*tty
)
1229 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1232 #ifdef SERIAL_DEBUG_IO
1233 printk("cy_write_room %s\n", tty
->name
); /* */
1236 if (serial_paranoia_check(info
, tty
->name
, "cy_write_room"))
1238 ret
= PAGE_SIZE
- info
->xmit_cnt
- 1;
1242 } /* cy_write_room */
1246 cy_chars_in_buffer(struct tty_struct
*tty
)
1248 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1250 #ifdef SERIAL_DEBUG_IO
1251 printk("cy_chars_in_buffer %s %d\n", tty
->name
, info
->xmit_cnt
); /* */
1254 if (serial_paranoia_check(info
, tty
->name
, "cy_chars_in_buffer"))
1257 return info
->xmit_cnt
;
1258 } /* cy_chars_in_buffer */
1262 cy_flush_buffer(struct tty_struct
*tty
)
1264 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1265 unsigned long flags
;
1267 #ifdef SERIAL_DEBUG_IO
1268 printk("cy_flush_buffer %s\n", tty
->name
); /* */
1271 if (serial_paranoia_check(info
, tty
->name
, "cy_flush_buffer"))
1273 local_irq_save(flags
);
1274 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1275 local_irq_restore(flags
);
1277 } /* cy_flush_buffer */
1280 /* This routine is called by the upper-layer tty layer to signal
1281 that incoming characters should be throttled or that the
1282 throttle should be released.
1285 cy_throttle(struct tty_struct
* tty
)
1287 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1288 unsigned long flags
;
1289 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1292 #ifdef SERIAL_DEBUG_THROTTLE
1295 printk("throttle %s: %d....\n", tty_name(tty
, buf
),
1296 tty
->ldisc
.chars_in_buffer(tty
));
1297 printk("cy_throttle %s\n", tty
->name
);
1300 if (serial_paranoia_check(info
, tty
->name
, "cy_nthrottle")){
1305 info
->x_char
= STOP_CHAR(tty
);
1306 /* Should use the "Send Special Character" feature!!! */
1309 channel
= info
->line
;
1311 local_irq_save(flags
);
1312 base_addr
[CyCAR
] = (u_char
)channel
;
1313 base_addr
[CyMSVR1
] = 0;
1314 local_irq_restore(flags
);
1321 cy_unthrottle(struct tty_struct
* tty
)
1323 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1324 unsigned long flags
;
1325 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1328 #ifdef SERIAL_DEBUG_THROTTLE
1331 printk("throttle %s: %d....\n", tty_name(tty
, buf
),
1332 tty
->ldisc
.chars_in_buffer(tty
));
1333 printk("cy_unthrottle %s\n", tty
->name
);
1336 if (serial_paranoia_check(info
, tty
->name
, "cy_nthrottle")){
1341 info
->x_char
= START_CHAR(tty
);
1342 /* Should use the "Send Special Character" feature!!! */
1345 channel
= info
->line
;
1347 local_irq_save(flags
);
1348 base_addr
[CyCAR
] = (u_char
)channel
;
1349 base_addr
[CyMSVR1
] = CyRTS
;
1350 local_irq_restore(flags
);
1353 } /* cy_unthrottle */
1356 get_serial_info(struct cyclades_port
* info
,
1357 struct serial_struct __user
* retinfo
)
1359 struct serial_struct tmp
;
1364 memset(&tmp
, 0, sizeof(tmp
));
1365 tmp
.type
= info
->type
;
1366 tmp
.line
= info
->line
;
1367 tmp
.port
= info
->line
;
1369 tmp
.flags
= info
->flags
;
1370 tmp
.baud_base
= 0; /*!!!*/
1371 tmp
.close_delay
= info
->close_delay
;
1372 tmp
.custom_divisor
= 0; /*!!!*/
1373 tmp
.hub6
= 0; /*!!!*/
1374 return copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
)) ? -EFAULT
: 0;
1375 } /* get_serial_info */
1378 set_serial_info(struct cyclades_port
* info
,
1379 struct serial_struct __user
* new_info
)
1381 struct serial_struct new_serial
;
1382 struct cyclades_port old_info
;
1387 if (copy_from_user(&new_serial
,new_info
,sizeof(new_serial
)))
1391 if (!capable(CAP_SYS_ADMIN
)) {
1392 if ((new_serial
.close_delay
!= info
->close_delay
) ||
1393 ((new_serial
.flags
& ASYNC_FLAGS
& ~ASYNC_USR_MASK
) !=
1394 (info
->flags
& ASYNC_FLAGS
& ~ASYNC_USR_MASK
)))
1396 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) |
1397 (new_serial
.flags
& ASYNC_USR_MASK
));
1398 goto check_and_exit
;
1403 * OK, past this point, all the error checking has been done.
1404 * At this point, we start making changes.....
1407 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) |
1408 (new_serial
.flags
& ASYNC_FLAGS
));
1409 info
->close_delay
= new_serial
.close_delay
;
1413 if (info
->flags
& ASYNC_INITIALIZED
){
1417 return startup(info
);
1419 } /* set_serial_info */
1422 cy_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1424 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
1426 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1427 unsigned long flags
;
1428 unsigned char status
;
1430 channel
= info
->line
;
1432 local_irq_save(flags
);
1433 base_addr
[CyCAR
] = (u_char
)channel
;
1434 status
= base_addr
[CyMSVR1
] | base_addr
[CyMSVR2
];
1435 local_irq_restore(flags
);
1437 return ((status
& CyRTS
) ? TIOCM_RTS
: 0)
1438 | ((status
& CyDTR
) ? TIOCM_DTR
: 0)
1439 | ((status
& CyDCD
) ? TIOCM_CAR
: 0)
1440 | ((status
& CyDSR
) ? TIOCM_DSR
: 0)
1441 | ((status
& CyCTS
) ? TIOCM_CTS
: 0);
1445 cy_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1446 unsigned int set
, unsigned int clear
)
1448 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
1450 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1451 unsigned long flags
;
1453 channel
= info
->line
;
1455 if (set
& TIOCM_RTS
){
1456 local_irq_save(flags
);
1457 base_addr
[CyCAR
] = (u_char
)channel
;
1458 base_addr
[CyMSVR1
] = CyRTS
;
1459 local_irq_restore(flags
);
1461 if (set
& TIOCM_DTR
){
1462 local_irq_save(flags
);
1463 base_addr
[CyCAR
] = (u_char
)channel
;
1464 /* CP('S');CP('2'); */
1465 base_addr
[CyMSVR2
] = CyDTR
;
1466 #ifdef SERIAL_DEBUG_DTR
1467 printk("cyc: %d: raising DTR\n", __LINE__
);
1468 printk(" status: 0x%x, 0x%x\n", base_addr
[CyMSVR1
], base_addr
[CyMSVR2
]);
1470 local_irq_restore(flags
);
1473 if (clear
& TIOCM_RTS
){
1474 local_irq_save(flags
);
1475 base_addr
[CyCAR
] = (u_char
)channel
;
1476 base_addr
[CyMSVR1
] = 0;
1477 local_irq_restore(flags
);
1479 if (clear
& TIOCM_DTR
){
1480 local_irq_save(flags
);
1481 base_addr
[CyCAR
] = (u_char
)channel
;
1482 /* CP('C');CP('2'); */
1483 base_addr
[CyMSVR2
] = 0;
1484 #ifdef SERIAL_DEBUG_DTR
1485 printk("cyc: %d: dropping DTR\n", __LINE__
);
1486 printk(" status: 0x%x, 0x%x\n", base_addr
[CyMSVR1
], base_addr
[CyMSVR2
]);
1488 local_irq_restore(flags
);
1492 } /* set_modem_info */
1495 send_break( struct cyclades_port
* info
, int duration
)
1496 { /* Let the transmit ISR take care of this (since it
1497 requires stuffing characters into the output stream).
1499 info
->x_break
= duration
;
1500 if (!info
->xmit_cnt
) {
1506 get_mon_info(struct cyclades_port
* info
, struct cyclades_monitor __user
* mon
)
1509 if (copy_to_user(mon
, &info
->mon
, sizeof(struct cyclades_monitor
)))
1511 info
->mon
.int_count
= 0;
1512 info
->mon
.char_count
= 0;
1513 info
->mon
.char_max
= 0;
1514 info
->mon
.char_last
= 0;
1519 set_threshold(struct cyclades_port
* info
, unsigned long __user
*arg
)
1521 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1522 unsigned long value
;
1525 if (get_user(value
, arg
))
1528 channel
= info
->line
;
1529 info
->cor4
&= ~CyREC_FIFO
;
1530 info
->cor4
|= value
& CyREC_FIFO
;
1531 base_addr
[CyCOR4
] = info
->cor4
;
1536 get_threshold(struct cyclades_port
* info
, unsigned long __user
*value
)
1538 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1542 channel
= info
->line
;
1544 tmp
= base_addr
[CyCOR4
] & CyREC_FIFO
;
1545 return put_user(tmp
,value
);
1549 set_default_threshold(struct cyclades_port
* info
, unsigned long __user
*arg
)
1551 unsigned long value
;
1553 if (get_user(value
, arg
))
1556 info
->default_threshold
= value
& 0x0f;
1561 get_default_threshold(struct cyclades_port
* info
, unsigned long __user
*value
)
1563 return put_user(info
->default_threshold
,value
);
1567 set_timeout(struct cyclades_port
* info
, unsigned long __user
*arg
)
1569 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1571 unsigned long value
;
1573 if (get_user(value
, arg
))
1576 channel
= info
->line
;
1578 base_addr
[CyRTPRL
] = value
& 0xff;
1579 base_addr
[CyRTPRH
] = (value
>> 8) & 0xff;
1584 get_timeout(struct cyclades_port
* info
, unsigned long __user
*value
)
1586 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
1590 channel
= info
->line
;
1592 tmp
= base_addr
[CyRTPRL
];
1593 return put_user(tmp
,value
);
1597 set_default_timeout(struct cyclades_port
* info
, unsigned long value
)
1599 info
->default_timeout
= value
& 0xff;
1604 get_default_timeout(struct cyclades_port
* info
, unsigned long __user
*value
)
1606 return put_user(info
->default_timeout
,value
);
1610 cy_ioctl(struct tty_struct
*tty
, struct file
* file
,
1611 unsigned int cmd
, unsigned long arg
)
1614 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
1616 void __user
*argp
= (void __user
*)arg
;
1618 #ifdef SERIAL_DEBUG_OTHER
1619 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty
->name
, cmd
, arg
); /* */
1624 ret_val
= get_mon_info(info
, argp
);
1627 ret_val
= get_threshold(info
, argp
);
1630 ret_val
= set_threshold(info
, argp
);
1632 case CYGETDEFTHRESH
:
1633 ret_val
= get_default_threshold(info
, argp
);
1635 case CYSETDEFTHRESH
:
1636 ret_val
= set_default_threshold(info
, argp
);
1639 ret_val
= get_timeout(info
, argp
);
1642 ret_val
= set_timeout(info
, argp
);
1644 case CYGETDEFTIMEOUT
:
1645 ret_val
= get_default_timeout(info
, argp
);
1647 case CYSETDEFTIMEOUT
:
1648 ret_val
= set_default_timeout(info
, (unsigned long)arg
);
1650 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1651 ret_val
= tty_check_change(tty
);
1654 tty_wait_until_sent(tty
,0);
1656 send_break(info
, HZ
/4); /* 1/4 second */
1658 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1659 ret_val
= tty_check_change(tty
);
1662 tty_wait_until_sent(tty
,0);
1663 send_break(info
, arg
? arg
*(HZ
/10) : HZ
/4);
1666 /* The following commands are incompletely implemented!!! */
1668 ret_val
= put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long __user
*) argp
);
1671 ret_val
= get_user(val
, (unsigned long __user
*) argp
);
1674 tty
->termios
->c_cflag
=
1675 ((tty
->termios
->c_cflag
& ~CLOCAL
) | (val
? CLOCAL
: 0));
1678 ret_val
= get_serial_info(info
, argp
);
1681 ret_val
= set_serial_info(info
, argp
);
1684 ret_val
= -ENOIOCTLCMD
;
1687 #ifdef SERIAL_DEBUG_OTHER
1688 printk("cy_ioctl done\n");
1698 cy_set_termios(struct tty_struct
*tty
, struct ktermios
* old_termios
)
1700 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
1702 #ifdef SERIAL_DEBUG_OTHER
1703 printk("cy_set_termios %s\n", tty
->name
);
1706 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1710 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1711 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1715 #ifdef tytso_patch_94Nov25_1726
1716 if (!(old_termios
->c_cflag
& CLOCAL
) &&
1717 (tty
->termios
->c_cflag
& CLOCAL
))
1718 wake_up_interruptible(&info
->open_wait
);
1722 } /* cy_set_termios */
1726 cy_close(struct tty_struct
* tty
, struct file
* filp
)
1728 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
1731 #ifdef SERIAL_DEBUG_OTHER
1732 printk("cy_close %s\n", tty
->name
);
1736 || serial_paranoia_check(info
, tty
->name
, "cy_close")){
1739 #ifdef SERIAL_DEBUG_OPEN
1740 printk("cy_close %s, count = %d\n", tty
->name
, info
->count
);
1743 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1745 * Uh, oh. tty->count is 1, which means that the tty
1746 * structure will be freed. Info->count should always
1747 * be one in these conditions. If it's greater than
1748 * one, we've got real problems, since it means the
1749 * serial port won't be shutdown.
1751 printk("cy_close: bad serial port count; tty->count is 1, "
1752 "info->count is %d\n", info
->count
);
1755 #ifdef SERIAL_DEBUG_COUNT
1756 printk("cyc: %d: decrementing count to %d\n", __LINE__
, info
->count
- 1);
1758 if (--info
->count
< 0) {
1759 printk("cy_close: bad serial port count for ttys%d: %d\n",
1760 info
->line
, info
->count
);
1761 #ifdef SERIAL_DEBUG_COUNT
1762 printk("cyc: %d: setting count to 0\n", __LINE__
);
1768 info
->flags
|= ASYNC_CLOSING
;
1769 if (info
->flags
& ASYNC_INITIALIZED
)
1770 tty_wait_until_sent(tty
, 3000); /* 30 seconds timeout */
1772 if (tty
->driver
->flush_buffer
)
1773 tty
->driver
->flush_buffer(tty
);
1774 tty_ldisc_flush(tty
);
1777 if (info
->blocked_open
) {
1778 if (info
->close_delay
) {
1779 msleep_interruptible(jiffies_to_msecs(info
->close_delay
));
1781 wake_up_interruptible(&info
->open_wait
);
1783 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1784 wake_up_interruptible(&info
->close_wait
);
1786 #ifdef SERIAL_DEBUG_OTHER
1787 printk("cy_close done\n");
1794 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
1797 cy_hangup(struct tty_struct
*tty
)
1799 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
1801 #ifdef SERIAL_DEBUG_OTHER
1802 printk("cy_hangup %s\n", tty
->name
); /* */
1805 if (serial_paranoia_check(info
, tty
->name
, "cy_hangup"))
1812 #ifdef SERIAL_DEBUG_COUNT
1813 printk("cyc: %d: setting count to 0\n", __LINE__
);
1817 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1818 wake_up_interruptible(&info
->open_wait
);
1824 * ------------------------------------------------------------
1825 * cy_open() and friends
1826 * ------------------------------------------------------------
1830 block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1831 struct cyclades_port
*info
)
1833 DECLARE_WAITQUEUE(wait
, current
);
1834 unsigned long flags
;
1837 volatile u_char
*base_addr
= (u_char
*)BASE_ADDR
;
1840 * If the device is in the middle of being closed, then block
1841 * until it's done, and then try again.
1843 if (info
->flags
& ASYNC_CLOSING
) {
1844 interruptible_sleep_on(&info
->close_wait
);
1845 if (info
->flags
& ASYNC_HUP_NOTIFY
){
1848 return -ERESTARTSYS
;
1853 * If non-blocking mode is set, then make the check up front
1856 if (filp
->f_flags
& O_NONBLOCK
) {
1857 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1862 * Block waiting for the carrier detect and the line to become
1863 * free (i.e., not in use by the callout). While we are in
1864 * this loop, info->count is dropped by one, so that
1865 * cy_close() knows when to free things. We restore it upon
1866 * exit, either normal or abnormal.
1869 add_wait_queue(&info
->open_wait
, &wait
);
1870 #ifdef SERIAL_DEBUG_OPEN
1871 printk("block_til_ready before block: %s, count = %d\n",
1872 tty
->name
, info
->count
);/**/
1875 #ifdef SERIAL_DEBUG_COUNT
1876 printk("cyc: %d: decrementing count to %d\n", __LINE__
, info
->count
);
1878 info
->blocked_open
++;
1880 channel
= info
->line
;
1883 local_irq_save(flags
);
1884 base_addr
[CyCAR
] = (u_char
)channel
;
1885 base_addr
[CyMSVR1
] = CyRTS
;
1886 /* CP('S');CP('4'); */
1887 base_addr
[CyMSVR2
] = CyDTR
;
1888 #ifdef SERIAL_DEBUG_DTR
1889 printk("cyc: %d: raising DTR\n", __LINE__
);
1890 printk(" status: 0x%x, 0x%x\n", base_addr
[CyMSVR1
], base_addr
[CyMSVR2
]);
1892 local_irq_restore(flags
);
1893 set_current_state(TASK_INTERRUPTIBLE
);
1894 if (tty_hung_up_p(filp
)
1895 || !(info
->flags
& ASYNC_INITIALIZED
) ){
1896 if (info
->flags
& ASYNC_HUP_NOTIFY
) {
1899 retval
= -ERESTARTSYS
;
1903 local_irq_save(flags
);
1904 base_addr
[CyCAR
] = (u_char
)channel
;
1905 /* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */
1906 if (!(info
->flags
& ASYNC_CLOSING
)
1908 || (base_addr
[CyMSVR1
] & CyDCD
))) {
1909 local_irq_restore(flags
);
1912 local_irq_restore(flags
);
1913 if (signal_pending(current
)) {
1914 retval
= -ERESTARTSYS
;
1917 #ifdef SERIAL_DEBUG_OPEN
1918 printk("block_til_ready blocking: %s, count = %d\n",
1919 tty
->name
, info
->count
);/**/
1923 current
->state
= TASK_RUNNING
;
1924 remove_wait_queue(&info
->open_wait
, &wait
);
1925 if (!tty_hung_up_p(filp
)){
1927 #ifdef SERIAL_DEBUG_COUNT
1928 printk("cyc: %d: incrementing count to %d\n", __LINE__
, info
->count
);
1931 info
->blocked_open
--;
1932 #ifdef SERIAL_DEBUG_OPEN
1933 printk("block_til_ready after blocking: %s, count = %d\n",
1934 tty
->name
, info
->count
);/**/
1938 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1940 } /* block_til_ready */
1943 * This routine is called whenever a serial port is opened. It
1944 * performs the serial-specific initialization for the tty structure.
1947 cy_open(struct tty_struct
*tty
, struct file
* filp
)
1949 struct cyclades_port
*info
;
1954 if ((line
< 0) || (NR_PORTS
<= line
)){
1957 info
= &cy_port
[line
];
1958 if (info
->line
< 0){
1961 #ifdef SERIAL_DEBUG_OTHER
1962 printk("cy_open %s\n", tty
->name
); /* */
1964 if (serial_paranoia_check(info
, tty
->name
, "cy_open")){
1967 #ifdef SERIAL_DEBUG_OPEN
1968 printk("cy_open %s, count = %d\n", tty
->name
, info
->count
);/**/
1971 #ifdef SERIAL_DEBUG_COUNT
1972 printk("cyc: %d: incrementing count to %d\n", __LINE__
, info
->count
);
1974 tty
->driver_data
= info
;
1978 * Start up serial port
1980 retval
= startup(info
);
1985 retval
= block_til_ready(tty
, filp
, info
);
1987 #ifdef SERIAL_DEBUG_OPEN
1988 printk("cy_open returning after block_til_ready with %d\n",
1994 #ifdef SERIAL_DEBUG_OPEN
1995 printk("cy_open done\n");/**/
2003 * ---------------------------------------------------------------------
2004 * serial167_init() and friends
2006 * serial167_init() is called at boot-time to initialize the serial driver.
2007 * ---------------------------------------------------------------------
2011 * This routine prints out the appropriate serial driver version
2012 * number, and identifies which options were configured into this
2018 printk("MVME166/167 cd2401 driver\n");
2019 } /* show_version */
2021 /* initialize chips on card -- return number of valid
2022 chips (which is number of ports/4) */
2025 * This initialises the hardware to a reasonable state. It should
2026 * probe the chip first so as to copy 166-Bug setup as a default for
2027 * port 0. It initialises CMR to CyASYNC; that is never done again, so
2028 * as to limit the number of CyINIT_CHAN commands in normal running.
2030 * ... I wonder what I should do if this fails ...
2034 mvme167_serial_console_setup(int cflag
)
2036 volatile unsigned char* base_addr
= (u_char
*)BASE_ADDR
;
2039 u_char rcor
, rbpr
, badspeed
= 0;
2040 unsigned long flags
;
2042 local_irq_save(flags
);
2045 * First probe channel zero of the chip, to see what speed has
2049 base_addr
[CyCAR
] = 0;
2051 rcor
= base_addr
[CyRCOR
] << 5;
2052 rbpr
= base_addr
[CyRBPR
];
2054 for (spd
= 0; spd
< sizeof(baud_bpr
); spd
++)
2055 if (rbpr
== baud_bpr
[spd
] && rcor
== baud_co
[spd
])
2057 if (spd
>= sizeof(baud_bpr
)) {
2058 spd
= 14; /* 19200 */
2059 badspeed
= 1; /* Failed to identify speed */
2061 initial_console_speed
= spd
;
2063 /* OK, we have chosen a speed, now reset and reinitialise */
2065 my_udelay(20000L); /* Allow time for any active o/p to complete */
2066 if(base_addr
[CyCCR
] != 0x00){
2067 local_irq_restore(flags
);
2068 /* printk(" chip is never idle (CCR != 0)\n"); */
2072 base_addr
[CyCCR
] = CyCHIP_RESET
; /* Reset the chip */
2075 if(base_addr
[CyGFRCR
] == 0x00){
2076 local_irq_restore(flags
);
2077 /* printk(" chip is not responding (GFRCR stayed 0)\n"); */
2082 * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms
2086 base_addr
[CyTPR
] = 10;
2088 base_addr
[CyPILR1
] = 0x01; /* Interrupt level for modem change */
2089 base_addr
[CyPILR2
] = 0x02; /* Interrupt level for tx ints */
2090 base_addr
[CyPILR3
] = 0x03; /* Interrupt level for rx ints */
2093 * Attempt to set up all channels to something reasonable, and
2094 * bang out a INIT_CHAN command. We should then be able to limit
2095 * the ammount of fiddling we have to do in normal running.
2098 for (ch
= 3; ch
>= 0 ; ch
--) {
2099 base_addr
[CyCAR
] = (u_char
)ch
;
2100 base_addr
[CyIER
] = 0;
2101 base_addr
[CyCMR
] = CyASYNC
;
2102 base_addr
[CyLICR
] = (u_char
)ch
<< 2;
2103 base_addr
[CyLIVR
] = 0x5c;
2104 base_addr
[CyTCOR
] = baud_co
[spd
];
2105 base_addr
[CyTBPR
] = baud_bpr
[spd
];
2106 base_addr
[CyRCOR
] = baud_co
[spd
] >> 5;
2107 base_addr
[CyRBPR
] = baud_bpr
[spd
];
2108 base_addr
[CySCHR1
] = 'Q' & 0x1f;
2109 base_addr
[CySCHR2
] = 'X' & 0x1f;
2110 base_addr
[CySCRL
] = 0;
2111 base_addr
[CySCRH
] = 0;
2112 base_addr
[CyCOR1
] = Cy_8_BITS
| CyPARITY_NONE
;
2113 base_addr
[CyCOR2
] = 0;
2114 base_addr
[CyCOR3
] = Cy_1_STOP
;
2115 base_addr
[CyCOR4
] = baud_cor4
[spd
];
2116 base_addr
[CyCOR5
] = 0;
2117 base_addr
[CyCOR6
] = 0;
2118 base_addr
[CyCOR7
] = 0;
2119 base_addr
[CyRTPRL
] = 2;
2120 base_addr
[CyRTPRH
] = 0;
2121 base_addr
[CyMSVR1
] = 0;
2122 base_addr
[CyMSVR2
] = 0;
2123 write_cy_cmd(base_addr
,CyINIT_CHAN
|CyDIS_RCVR
|CyDIS_XMTR
);
2127 * Now do specials for channel zero....
2130 base_addr
[CyMSVR1
] = CyRTS
;
2131 base_addr
[CyMSVR2
] = CyDTR
;
2132 base_addr
[CyIER
] = CyRxData
;
2133 write_cy_cmd(base_addr
,CyENB_RCVR
|CyENB_XMTR
);
2135 local_irq_restore(flags
);
2137 my_udelay(20000L); /* Let it all settle down */
2139 printk("CD2401 initialised, chip is rev 0x%02x\n", base_addr
[CyGFRCR
]);
2141 printk(" WARNING: Failed to identify line speed, rcor=%02x,rbpr=%02x\n",
2143 } /* serial_console_init */
2145 static const struct tty_operations cy_ops
= {
2149 .put_char
= cy_put_char
,
2150 .flush_chars
= cy_flush_chars
,
2151 .write_room
= cy_write_room
,
2152 .chars_in_buffer
= cy_chars_in_buffer
,
2153 .flush_buffer
= cy_flush_buffer
,
2155 .throttle
= cy_throttle
,
2156 .unthrottle
= cy_unthrottle
,
2157 .set_termios
= cy_set_termios
,
2160 .hangup
= cy_hangup
,
2161 .tiocmget
= cy_tiocmget
,
2162 .tiocmset
= cy_tiocmset
,
2164 /* The serial driver boot-time initialization code!
2165 Hardware I/O ports are mapped to character special devices on a
2166 first found, first allocated manner. That is, this code searches
2167 for Cyclom cards in the system. As each is found, it is probed
2168 to discover how many chips (and thus how many ports) are present.
2169 These ports are mapped to the tty ports 64 and upward in monotonic
2170 fashion. If an 8-port card is replaced with a 16-port card, the
2171 port mapping on a following card will shift.
2173 This approach is different from what is used in the other serial
2174 device driver because the Cyclom is more properly a multiplexer,
2175 not just an aggregation of serial ports on one card.
2177 If there are more cards with more ports than have been statically
2178 allocated above, a warning is printed and the extra ports are ignored.
2181 serial167_init(void)
2183 struct cyclades_port
*info
;
2190 struct sigaction sa
;
2193 if (!(mvme16x_config
&MVME16x_CONFIG_GOT_CD2401
))
2196 cy_serial_driver
= alloc_tty_driver(NR_PORTS
);
2197 if (!cy_serial_driver
)
2206 /* Has "console=0,9600n8" been used in bootinfo to change speed? */
2207 if (serial_console_cflag
)
2208 DefSpeed
= serial_console_cflag
& 0017;
2210 DefSpeed
= initial_console_speed
;
2211 serial_console_info
= &cy_port
[0];
2212 serial_console_cflag
= DefSpeed
| CS8
;
2214 serial_console
= 64; /*callout_driver.minor_start*/
2218 /* Initialize the tty_driver structure */
2220 cy_serial_driver
->owner
= THIS_MODULE
;
2221 cy_serial_driver
->name
= "ttyS";
2222 cy_serial_driver
->major
= TTY_MAJOR
;
2223 cy_serial_driver
->minor_start
= 64;
2224 cy_serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
2225 cy_serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
2226 cy_serial_driver
->init_termios
= tty_std_termios
;
2227 cy_serial_driver
->init_termios
.c_cflag
=
2228 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2229 cy_serial_driver
->flags
= TTY_DRIVER_REAL_RAW
;
2230 tty_set_operations(cy_serial_driver
, &cy_ops
);
2232 ret
= tty_register_driver(cy_serial_driver
);
2234 printk(KERN_ERR
"Couldn't register MVME166/7 serial driver\n");
2235 put_tty_driver(cy_serial_driver
);
2241 for (index
= 0; index
< 1; index
++) {
2245 if(port_num
< NR_PORTS
){
2246 while( good_ports
-- && port_num
< NR_PORTS
){
2247 /*** initialize port ***/
2248 info
->magic
= CYCLADES_MAGIC
;
2249 info
->type
= PORT_CIRRUS
;
2251 info
->line
= port_num
;
2252 info
->flags
= STD_COM_FLAGS
;
2254 info
->xmit_fifo_size
= 12;
2255 info
->cor1
= CyPARITY_NONE
|Cy_8_BITS
;
2257 info
->cor3
= Cy_1_STOP
;
2258 info
->cor4
= 0x08; /* _very_ small receive threshold */
2262 info
->tbpr
= baud_bpr
[DefSpeed
]; /* Tx BPR */
2263 info
->tco
= baud_co
[DefSpeed
]; /* Tx CO */
2264 info
->rbpr
= baud_bpr
[DefSpeed
]; /* Rx BPR */
2265 info
->rco
= baud_co
[DefSpeed
] >> 5; /* Rx CO */
2266 info
->close_delay
= 0;
2270 #ifdef SERIAL_DEBUG_COUNT
2271 printk("cyc: %d: setting count to 0\n", __LINE__
);
2273 info
->blocked_open
= 0;
2274 info
->default_threshold
= 0;
2275 info
->default_timeout
= 0;
2276 INIT_WORK(&info
->tqueue
, do_softint
);
2277 init_waitqueue_head(&info
->open_wait
);
2278 init_waitqueue_head(&info
->close_wait
);
2281 /*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/
2282 info
->read_status_mask
= CyTIMEOUT
| CySPECHAR
| CyBREAK
2283 | CyPARITY
| CyFRAME
| CyOVERRUN
;
2286 printk("ttyS%d ", info
->line
);
2288 if(!(port_num
& 7)){
2295 while( port_num
< NR_PORTS
){
2299 #ifdef CONFIG_REMOTE_DEBUG
2302 ret
= request_irq(MVME167_IRQ_SER_ERR
, cd2401_rxerr_interrupt
, 0,
2303 "cd2401_errors", cd2401_rxerr_interrupt
);
2305 printk(KERN_ERR
"Could't get cd2401_errors IRQ");
2306 goto cleanup_serial_driver
;
2309 ret
= request_irq(MVME167_IRQ_SER_MODEM
, cd2401_modem_interrupt
, 0,
2310 "cd2401_modem", cd2401_modem_interrupt
);
2312 printk(KERN_ERR
"Could't get cd2401_modem IRQ");
2313 goto cleanup_irq_cd2401_errors
;
2316 ret
= request_irq(MVME167_IRQ_SER_TX
, cd2401_tx_interrupt
, 0,
2317 "cd2401_txints", cd2401_tx_interrupt
);
2319 printk(KERN_ERR
"Could't get cd2401_txints IRQ");
2320 goto cleanup_irq_cd2401_modem
;
2323 ret
= request_irq(MVME167_IRQ_SER_RX
, cd2401_rx_interrupt
, 0,
2324 "cd2401_rxints", cd2401_rx_interrupt
);
2326 printk(KERN_ERR
"Could't get cd2401_rxints IRQ");
2327 goto cleanup_irq_cd2401_txints
;
2330 /* Now we have registered the interrupt handlers, allow the interrupts */
2332 pcc2chip
[PccSCCMICR
] = 0x15; /* Serial ints are level 5 */
2333 pcc2chip
[PccSCCTICR
] = 0x15;
2334 pcc2chip
[PccSCCRICR
] = 0x15;
2336 pcc2chip
[PccIMLR
] = 3; /* Allow PCC2 ints above 3!? */
2339 cleanup_irq_cd2401_txints
:
2340 free_irq(MVME167_IRQ_SER_TX
, cd2401_tx_interrupt
);
2341 cleanup_irq_cd2401_modem
:
2342 free_irq(MVME167_IRQ_SER_MODEM
, cd2401_modem_interrupt
);
2343 cleanup_irq_cd2401_errors
:
2344 free_irq(MVME167_IRQ_SER_ERR
, cd2401_rxerr_interrupt
);
2345 cleanup_serial_driver
:
2346 if (tty_unregister_driver(cy_serial_driver
))
2347 printk(KERN_ERR
"Couldn't unregister MVME166/7 serial driver\n");
2348 put_tty_driver(cy_serial_driver
);
2350 } /* serial167_init */
2352 module_init(serial167_init
);
2355 #ifdef CYCLOM_SHOW_STATUS
2357 show_status(int line_num
)
2359 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
2361 struct cyclades_port
* info
;
2362 unsigned long flags
;
2364 info
= &cy_port
[line_num
];
2365 channel
= info
->line
;
2366 printk(" channel %d\n", channel
);/**/
2368 printk(" cy_port\n");
2369 printk(" card line flags = %d %d %x\n",
2370 info
->card
, info
->line
, info
->flags
);
2371 printk(" *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n",
2372 (long)info
->tty
, info
->read_status_mask
,
2373 info
->timeout
, info
->xmit_fifo_size
);
2374 printk(" cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n",
2375 info
->cor1
, info
->cor2
, info
->cor3
, info
->cor4
, info
->cor5
,
2376 info
->cor6
, info
->cor7
);
2377 printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n",
2378 info
->tbpr
, info
->tco
, info
->rbpr
, info
->rco
);
2379 printk(" close_delay event count = %d %d %d\n",
2380 info
->close_delay
, info
->event
, info
->count
);
2381 printk(" x_char blocked_open = %x %x\n",
2382 info
->x_char
, info
->blocked_open
);
2383 printk(" open_wait = %lx %lx %lx\n",
2384 (long)info
->open_wait
);
2387 local_irq_save(flags
);
2389 /* Global Registers */
2391 printk(" CyGFRCR %x\n", base_addr
[CyGFRCR
]);
2392 printk(" CyCAR %x\n", base_addr
[CyCAR
]);
2393 printk(" CyRISR %x\n", base_addr
[CyRISR
]);
2394 printk(" CyTISR %x\n", base_addr
[CyTISR
]);
2395 printk(" CyMISR %x\n", base_addr
[CyMISR
]);
2396 printk(" CyRIR %x\n", base_addr
[CyRIR
]);
2397 printk(" CyTIR %x\n", base_addr
[CyTIR
]);
2398 printk(" CyMIR %x\n", base_addr
[CyMIR
]);
2399 printk(" CyTPR %x\n", base_addr
[CyTPR
]);
2401 base_addr
[CyCAR
] = (u_char
)channel
;
2403 /* Virtual Registers */
2406 printk(" CyRIVR %x\n", base_addr
[CyRIVR
]);
2407 printk(" CyTIVR %x\n", base_addr
[CyTIVR
]);
2408 printk(" CyMIVR %x\n", base_addr
[CyMIVR
]);
2409 printk(" CyMISR %x\n", base_addr
[CyMISR
]);
2412 /* Channel Registers */
2414 printk(" CyCCR %x\n", base_addr
[CyCCR
]);
2415 printk(" CyIER %x\n", base_addr
[CyIER
]);
2416 printk(" CyCOR1 %x\n", base_addr
[CyCOR1
]);
2417 printk(" CyCOR2 %x\n", base_addr
[CyCOR2
]);
2418 printk(" CyCOR3 %x\n", base_addr
[CyCOR3
]);
2419 printk(" CyCOR4 %x\n", base_addr
[CyCOR4
]);
2420 printk(" CyCOR5 %x\n", base_addr
[CyCOR5
]);
2422 printk(" CyCCSR %x\n", base_addr
[CyCCSR
]);
2423 printk(" CyRDCR %x\n", base_addr
[CyRDCR
]);
2425 printk(" CySCHR1 %x\n", base_addr
[CySCHR1
]);
2426 printk(" CySCHR2 %x\n", base_addr
[CySCHR2
]);
2428 printk(" CySCHR3 %x\n", base_addr
[CySCHR3
]);
2429 printk(" CySCHR4 %x\n", base_addr
[CySCHR4
]);
2430 printk(" CySCRL %x\n", base_addr
[CySCRL
]);
2431 printk(" CySCRH %x\n", base_addr
[CySCRH
]);
2432 printk(" CyLNC %x\n", base_addr
[CyLNC
]);
2433 printk(" CyMCOR1 %x\n", base_addr
[CyMCOR1
]);
2434 printk(" CyMCOR2 %x\n", base_addr
[CyMCOR2
]);
2436 printk(" CyRTPRL %x\n", base_addr
[CyRTPRL
]);
2437 printk(" CyRTPRH %x\n", base_addr
[CyRTPRH
]);
2438 printk(" CyMSVR1 %x\n", base_addr
[CyMSVR1
]);
2439 printk(" CyMSVR2 %x\n", base_addr
[CyMSVR2
]);
2440 printk(" CyRBPR %x\n", base_addr
[CyRBPR
]);
2441 printk(" CyRCOR %x\n", base_addr
[CyRCOR
]);
2442 printk(" CyTBPR %x\n", base_addr
[CyTBPR
]);
2443 printk(" CyTCOR %x\n", base_addr
[CyTCOR
]);
2445 local_irq_restore(flags
);
2451 /* Dummy routine in mvme16x/config.c for now */
2453 /* Serial console setup. Called from linux/init/main.c */
2455 void console_setup(char *str
, int *ints
)
2458 int baud
, bits
, parity
;
2462 if (ints
[0] > 3 || ints
[1] > 3) return;
2464 /* Get baud, bits and parity */
2468 if (ints
[2]) baud
= ints
[2];
2469 if ((s
= strchr(str
, ','))) {
2472 } while(*s
>= '0' && *s
<= '9');
2473 if (*s
) parity
= *s
++;
2474 if (*s
) bits
= *s
- '0';
2477 /* Now construct a cflag setting. */
2514 serial_console_info
= &cy_port
[ints
[1]];
2515 serial_console_cflag
= cflag
;
2516 serial_console
= ints
[1] + 64; /*callout_driver.minor_start*/
2521 * The following is probably out of date for 2.1.x serial console stuff.
2523 * The console is registered early on from arch/m68k/kernel/setup.c, and
2524 * it therefore relies on the chip being setup correctly by 166-Bug. This
2525 * seems reasonable, as the serial port has been used to invoke the system
2526 * boot. It also means that this function must not rely on any data
2527 * initialisation performed by serial167_init() etc.
2529 * Of course, once the console has been registered, we had better ensure
2530 * that serial167_init() doesn't leave the chip non-functional.
2532 * The console must be locked when we get here.
2535 void serial167_console_write(struct console
*co
, const char *str
, unsigned count
)
2537 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
2538 unsigned long flags
;
2539 volatile u_char sink
;
2545 local_irq_save(flags
);
2547 /* Ensure transmitter is enabled! */
2550 base_addr
[CyCAR
] = (u_char
)port
;
2551 while (base_addr
[CyCCR
])
2553 base_addr
[CyCCR
] = CyENB_XMTR
;
2555 ier
= base_addr
[CyIER
];
2556 base_addr
[CyIER
] = CyTxMpty
;
2559 if (pcc2chip
[PccSCCTICR
] & 0x20)
2561 /* We have a Tx int. Acknowledge it */
2562 sink
= pcc2chip
[PccTPIACKR
];
2563 if ((base_addr
[CyLICR
] >> 2) == port
) {
2565 /* Last char of string is now output */
2566 base_addr
[CyTEOIR
] = CyNOTRANS
;
2570 base_addr
[CyTDR
] = '\n';
2575 else if (*str
== '\n') {
2576 base_addr
[CyTDR
] = '\r';
2580 base_addr
[CyTDR
] = *str
++;
2583 base_addr
[CyTEOIR
] = 0;
2586 base_addr
[CyTEOIR
] = CyNOTRANS
;
2590 base_addr
[CyIER
] = ier
;
2592 local_irq_restore(flags
);
2595 static struct tty_driver
*serial167_console_device(struct console
*c
, int *index
)
2598 return cy_serial_driver
;
2602 static int __init
serial167_console_setup(struct console
*co
, char *options
)
2608 static struct console sercons
= {
2610 .write
= serial167_console_write
,
2611 .device
= serial167_console_device
,
2612 .setup
= serial167_console_setup
,
2613 .flags
= CON_PRINTBUFFER
,
2618 static int __init
serial167_console_init(void)
2620 if (vme_brdtype
== VME_TYPE_MVME166
||
2621 vme_brdtype
== VME_TYPE_MVME167
||
2622 vme_brdtype
== VME_TYPE_MVME177
) {
2623 mvme167_serial_console_setup(0);
2624 register_console(&sercons
);
2628 console_initcall(serial167_console_init
);
2630 #ifdef CONFIG_REMOTE_DEBUG
2631 void putDebugChar (int c
)
2633 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
2634 unsigned long flags
;
2635 volatile u_char sink
;
2639 local_irq_save(flags
);
2641 /* Ensure transmitter is enabled! */
2644 base_addr
[CyCAR
] = (u_char
)port
;
2645 while (base_addr
[CyCCR
])
2647 base_addr
[CyCCR
] = CyENB_XMTR
;
2649 ier
= base_addr
[CyIER
];
2650 base_addr
[CyIER
] = CyTxMpty
;
2653 if (pcc2chip
[PccSCCTICR
] & 0x20)
2655 /* We have a Tx int. Acknowledge it */
2656 sink
= pcc2chip
[PccTPIACKR
];
2657 if ((base_addr
[CyLICR
] >> 2) == port
) {
2658 base_addr
[CyTDR
] = c
;
2659 base_addr
[CyTEOIR
] = 0;
2663 base_addr
[CyTEOIR
] = CyNOTRANS
;
2667 base_addr
[CyIER
] = ier
;
2669 local_irq_restore(flags
);
2674 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
2675 unsigned long flags
;
2676 volatile u_char sink
;
2682 if (i
!= debugiq
.in
) {
2684 if (++i
== DEBUG_LEN
)
2689 /* OK, nothing in queue, wait in poll loop */
2691 local_irq_save(flags
);
2693 /* Ensure receiver is enabled! */
2696 base_addr
[CyCAR
] = (u_char
)port
;
2698 while (base_addr
[CyCCR
])
2700 base_addr
[CyCCR
] = CyENB_RCVR
;
2702 ier
= base_addr
[CyIER
];
2703 base_addr
[CyIER
] = CyRxData
;
2706 if (pcc2chip
[PccSCCRICR
] & 0x20)
2708 /* We have a Rx int. Acknowledge it */
2709 sink
= pcc2chip
[PccRPIACKR
];
2710 if ((base_addr
[CyLICR
] >> 2) == port
) {
2711 int cnt
= base_addr
[CyRFOC
];
2714 c
= base_addr
[CyRDR
];
2716 printk ("!! debug char is null (cnt=%d) !!", cnt
);
2720 base_addr
[CyREOIR
] = 0;
2722 if (i
== debugiq
.in
)
2723 panic ("Debug input queue empty!");
2725 if (++i
== DEBUG_LEN
)
2731 base_addr
[CyREOIR
] = CyNOTRANS
;
2735 base_addr
[CyIER
] = ier
;
2737 local_irq_restore(flags
);
2742 void queueDebugChar (int c
)
2748 if (++i
== DEBUG_LEN
)
2750 if (i
!= debugiq
.out
)
2757 unsigned long flags
;
2758 volatile unsigned char *base_addr
= (u_char
*)BASE_ADDR
;
2763 local_irq_save(flags
);
2765 for (i
= 0; i
< 4; i
++)
2767 base_addr
[CyCAR
] = i
;
2768 base_addr
[CyLICR
] = i
<< 2;
2771 debugiq
.in
= debugiq
.out
= 0;
2773 base_addr
[CyCAR
] = DEBUG_PORT
;
2778 base_addr
[CyIER
] = 0;
2780 base_addr
[CyCMR
] = CyASYNC
;
2781 base_addr
[CyLICR
] = DEBUG_PORT
<< 2;
2782 base_addr
[CyLIVR
] = 0x5c;
2784 /* tx and rx baud rate */
2786 base_addr
[CyTCOR
] = baud_co
[i
];
2787 base_addr
[CyTBPR
] = baud_bpr
[i
];
2788 base_addr
[CyRCOR
] = baud_co
[i
] >> 5;
2789 base_addr
[CyRBPR
] = baud_bpr
[i
];
2791 /* set line characteristics according configuration */
2793 base_addr
[CySCHR1
] = 0;
2794 base_addr
[CySCHR2
] = 0;
2795 base_addr
[CySCRL
] = 0;
2796 base_addr
[CySCRH
] = 0;
2797 base_addr
[CyCOR1
] = Cy_8_BITS
| CyPARITY_NONE
;
2798 base_addr
[CyCOR2
] = 0;
2799 base_addr
[CyCOR3
] = Cy_1_STOP
;
2800 base_addr
[CyCOR4
] = baud_cor4
[i
];
2801 base_addr
[CyCOR5
] = 0;
2802 base_addr
[CyCOR6
] = 0;
2803 base_addr
[CyCOR7
] = 0;
2805 write_cy_cmd(base_addr
,CyINIT_CHAN
);
2806 write_cy_cmd(base_addr
,CyENB_RCVR
);
2808 base_addr
[CyCAR
] = DEBUG_PORT
; /* !!! Is this needed? */
2810 base_addr
[CyRTPRL
] = 2;
2811 base_addr
[CyRTPRH
] = 0;
2813 base_addr
[CyMSVR1
] = CyRTS
;
2814 base_addr
[CyMSVR2
] = CyDTR
;
2816 base_addr
[CyIER
] = CyRxData
;
2818 local_irq_restore(flags
);
2824 MODULE_LICENSE("GPL");