2 * linux/drivers/char/riscom.c -- RISCom/8 multiport serial driver.
4 * Copyright (C) 1994-1996 Dmitry Gorodchanin (pgmdsg@ibi.com)
6 * This code is loosely based on the Linux serial driver, written by
7 * Linus Torvalds, Theodore T'so and others. The RISCom/8 card
8 * programming info was obtained from various drivers for other OSes
9 * (FreeBSD, ISC, etc), but no source code from those drivers were
10 * directly included in this driver.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include <linux/module.h>
33 #include <linux/kernel.h>
34 #include <linux/sched.h>
35 #include <linux/ioport.h>
36 #include <linux/interrupt.h>
37 #include <linux/errno.h>
38 #include <linux/tty.h>
40 #include <linux/serial.h>
41 #include <linux/fcntl.h>
42 #include <linux/major.h>
43 #include <linux/init.h>
45 #include <asm/uaccess.h>
48 #include "riscom8_reg.h"
50 /* Am I paranoid or not ? ;-) */
51 #define RISCOM_PARANOIA_CHECK
54 * Crazy InteliCom/8 boards sometimes has swapped CTS & DSR signals.
55 * You can slightly speed up things by #undefing the following option,
56 * if you are REALLY sure that your board is correct one.
59 #define RISCOM_BRAIN_DAMAGED_CTS
62 * The following defines are mostly for testing purposes. But if you need
63 * some nice reporting in your syslog, you can define them also.
66 #undef RC_REPORT_OVERRUN
69 #define RISCOM_LEGAL_FLAGS \
70 (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \
71 ASYNC_SPD_HI | ASYNC_SPEED_VHI | ASYNC_SESSION_LOCKOUT | \
72 ASYNC_PGRP_LOCKOUT | ASYNC_CALLOUT_NOHUP)
75 #define MIN(a,b) ((a) < (b) ? (a) : (b))
78 #define RS_EVENT_WRITE_WAKEUP 0
80 DECLARE_TASK_QUEUE(tq_riscom
);
82 #define RISCOM_TYPE_NORMAL 1
83 #define RISCOM_TYPE_CALLOUT 2
85 static struct riscom_board
* IRQ_to_board
[16] = { NULL
, } ;
86 static struct tty_driver riscom_driver
, riscom_callout_driver
;
87 static int riscom_refcount
= 0;
88 static struct tty_struct
* riscom_table
[RC_NBOARD
* RC_NPORT
] = { NULL
, };
89 static struct termios
* riscom_termios
[RC_NBOARD
* RC_NPORT
] = { NULL
, };
90 static struct termios
* riscom_termios_locked
[RC_NBOARD
* RC_NPORT
] = { NULL
, };
91 static unsigned char * tmp_buf
= NULL
;
92 static DECLARE_MUTEX(tmp_buf_sem
);
94 static unsigned long baud_table
[] = {
95 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
96 9600, 19200, 38400, 57600, 76800, 0,
99 static struct riscom_board rc_board
[RC_NBOARD
] = {
100 { 0, RC_IOBASE1
, 0, },
101 { 0, RC_IOBASE2
, 0, },
102 { 0, RC_IOBASE3
, 0, },
103 { 0, RC_IOBASE4
, 0, },
106 static struct riscom_port rc_port
[RC_NBOARD
* RC_NPORT
] = {
110 /* RISCom/8 I/O ports addresses (without address translation) */
111 static unsigned short rc_ioport
[] = {
113 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c,
115 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10,
116 0x11, 0x12, 0x18, 0x28, 0x31, 0x32, 0x39, 0x3a, 0x40, 0x41, 0x61, 0x62,
117 0x63, 0x64, 0x6b, 0x70, 0x71, 0x78, 0x7a, 0x7b, 0x7f, 0x100, 0x101
120 #define RC_NIOPORT (sizeof(rc_ioport) / sizeof(rc_ioport[0]))
123 static inline int rc_paranoia_check(struct riscom_port
const * port
,
124 kdev_t device
, const char *routine
)
126 #ifdef RISCOM_PARANOIA_CHECK
127 static const char *badmagic
=
128 "rc: Warning: bad riscom port magic number for device %s in %s\n";
129 static const char *badinfo
=
130 "rc: Warning: null riscom port for device %s in %s\n";
133 printk(badinfo
, kdevname(device
), routine
);
136 if (port
->magic
!= RISCOM8_MAGIC
) {
137 printk(badmagic
, kdevname(device
), routine
);
146 * Service functions for RISCom/8 driver.
150 /* Get board number from pointer */
151 extern inline int board_No (struct riscom_board
const * bp
)
153 return bp
- rc_board
;
156 /* Get port number from pointer */
157 extern inline int port_No (struct riscom_port
const * port
)
159 return RC_PORT(port
- rc_port
);
162 /* Get pointer to board from pointer to port */
163 extern inline struct riscom_board
* port_Board(struct riscom_port
const * port
)
165 return &rc_board
[RC_BOARD(port
- rc_port
)];
168 /* Input Byte from CL CD180 register */
169 extern inline unsigned char rc_in(struct riscom_board
const * bp
, unsigned short reg
)
171 return inb(bp
->base
+ RC_TO_ISA(reg
));
174 /* Output Byte to CL CD180 register */
175 extern inline void rc_out(struct riscom_board
const * bp
, unsigned short reg
,
178 outb(val
, bp
->base
+ RC_TO_ISA(reg
));
181 /* Wait for Channel Command Register ready */
182 extern inline void rc_wait_CCR(struct riscom_board
const * bp
)
186 /* FIXME: need something more descriptive then 100000 :) */
187 for (delay
= 100000; delay
; delay
--)
188 if (!rc_in(bp
, CD180_CCR
))
191 printk("rc%d: Timeout waiting for CCR.\n", board_No(bp
));
195 * RISCom/8 probe functions.
198 extern inline int rc_check_io_range(struct riscom_board
* const bp
)
202 for (i
= 0; i
< RC_NIOPORT
; i
++)
203 if (check_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1)) {
204 printk("rc%d: Skipping probe at 0x%03x. I/O address in use.\n",
205 board_No(bp
), bp
->base
);
211 extern inline void rc_request_io_range(struct riscom_board
* const bp
)
215 for (i
= 0; i
< RC_NIOPORT
; i
++)
216 request_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1, "RISCom/8" );
219 extern inline void rc_release_io_range(struct riscom_board
* const bp
)
223 for (i
= 0; i
< RC_NIOPORT
; i
++)
224 release_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1);
228 /* Must be called with enabled interrupts */
229 extern inline void rc_long_delay(unsigned long delay
)
233 for (i
= jiffies
+ delay
; time_after(i
,jiffies
); ) ;
236 /* Reset and setup CD180 chip */
237 static void __init
rc_init_CD180(struct riscom_board
const * bp
)
241 save_flags(flags
); cli();
242 rc_out(bp
, RC_CTOUT
, 0); /* Clear timeout */
243 rc_wait_CCR(bp
); /* Wait for CCR ready */
244 rc_out(bp
, CD180_CCR
, CCR_HARDRESET
); /* Reset CD180 chip */
246 rc_long_delay(HZ
/20); /* Delay 0.05 sec */
248 rc_out(bp
, CD180_GIVR
, RC_ID
); /* Set ID for this chip */
249 rc_out(bp
, CD180_GICR
, 0); /* Clear all bits */
250 rc_out(bp
, CD180_PILR1
, RC_ACK_MINT
); /* Prio for modem intr */
251 rc_out(bp
, CD180_PILR2
, RC_ACK_TINT
); /* Prio for transmitter intr */
252 rc_out(bp
, CD180_PILR3
, RC_ACK_RINT
); /* Prio for receiver intr */
254 /* Setting up prescaler. We need 4 ticks per 1 ms */
255 rc_out(bp
, CD180_PPRH
, (RC_OSCFREQ
/(1000000/RISCOM_TPS
)) >> 8);
256 rc_out(bp
, CD180_PPRL
, (RC_OSCFREQ
/(1000000/RISCOM_TPS
)) & 0xff);
258 restore_flags(flags
);
261 /* Main probing routine, also sets irq. */
262 static int __init
rc_probe(struct riscom_board
*bp
)
264 unsigned char val1
, val2
;
270 if (rc_check_io_range(bp
))
273 /* Are the I/O ports here ? */
274 rc_out(bp
, CD180_PPRL
, 0x5a);
276 val1
= rc_in(bp
, CD180_PPRL
);
277 rc_out(bp
, CD180_PPRL
, 0xa5);
279 val2
= rc_in(bp
, CD180_PPRL
);
281 if ((val1
!= 0x5a) || (val2
!= 0xa5)) {
282 printk("rc%d: RISCom/8 Board at 0x%03x not found.\n",
283 board_No(bp
), bp
->base
);
287 /* It's time to find IRQ for this board */
288 for (retries
= 0; retries
< 5 && irqs
<= 0; retries
++) {
289 irqs
= probe_irq_on();
290 rc_init_CD180(bp
); /* Reset CD180 chip */
291 rc_out(bp
, CD180_CAR
, 2); /* Select port 2 */
293 rc_out(bp
, CD180_CCR
, CCR_TXEN
); /* Enable transmitter */
294 rc_out(bp
, CD180_IER
, IER_TXRDY
); /* Enable tx empty intr */
295 rc_long_delay(HZ
/20);
296 irqs
= probe_irq_off(irqs
);
297 val1
= rc_in(bp
, RC_BSR
); /* Get Board Status reg */
298 val2
= rc_in(bp
, RC_ACK_TINT
); /* ACK interrupt */
299 rc_init_CD180(bp
); /* Reset CD180 again */
301 if ((val1
& RC_BSR_TINT
) || (val2
!= (RC_ID
| GIVR_IT_TX
))) {
302 printk("rc%d: RISCom/8 Board at 0x%03x not found.\n",
303 board_No(bp
), bp
->base
);
309 printk("rc%d: Can't find IRQ for RISCom/8 board at 0x%03x.\n",
310 board_No(bp
), bp
->base
);
313 rc_request_io_range(bp
);
315 bp
->flags
|= RC_BOARD_PRESENT
;
317 printk("rc%d: RISCom/8 Rev. %c board detected at 0x%03x, IRQ %d.\n",
319 (rc_in(bp
, CD180_GFRCR
) & 0x0f) + 'A', /* Board revision */
327 * Interrupt processing routines.
331 extern inline void rc_mark_event(struct riscom_port
* port
, int event
)
334 * I'm not quite happy with current scheme all serial
335 * drivers use their own BH routine.
336 * It seems this easily can be done with one BH routine
337 * serving for all serial drivers.
338 * For now I must introduce another one - RISCOM8_BH.
339 * Still hope this will be changed in near future.
341 set_bit(event
, &port
->event
);
342 queue_task(&port
->tqueue
, &tq_riscom
);
346 extern inline struct riscom_port
* rc_get_port(struct riscom_board
const * bp
,
347 unsigned char const * what
)
349 unsigned char channel
;
350 struct riscom_port
* port
;
352 channel
= rc_in(bp
, CD180_GICR
) >> GICR_CHAN_OFF
;
353 if (channel
< CD180_NCH
) {
354 port
= &rc_port
[board_No(bp
) * RC_NPORT
+ channel
];
355 if (port
->flags
& ASYNC_INITIALIZED
) {
359 printk("rc%d: %s interrupt from invalid port %d\n",
360 board_No(bp
), what
, channel
);
364 extern inline void rc_receive_exc(struct riscom_board
const * bp
)
366 struct riscom_port
*port
;
367 struct tty_struct
*tty
;
368 unsigned char status
;
371 if (!(port
= rc_get_port(bp
, "Receive")))
375 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
376 printk("rc%d: port %d: Working around flip buffer overflow.\n",
377 board_No(bp
), port_No(port
));
381 #ifdef RC_REPORT_OVERRUN
382 status
= rc_in(bp
, CD180_RCSR
);
383 if (status
& RCSR_OE
) {
386 printk("rc%d: port %d: Overrun. Total %ld overruns.\n",
387 board_No(bp
), port_No(port
), port
->overrun
);
390 status
&= port
->mark_mask
;
392 status
= rc_in(bp
, CD180_RCSR
) & port
->mark_mask
;
394 ch
= rc_in(bp
, CD180_RDR
);
398 if (status
& RCSR_TOUT
) {
399 printk("rc%d: port %d: Receiver timeout. Hardware problems ?\n",
400 board_No(bp
), port_No(port
));
403 } else if (status
& RCSR_BREAK
) {
404 printk("rc%d: port %d: Handling break...\n",
405 board_No(bp
), port_No(port
));
406 *tty
->flip
.flag_buf_ptr
++ = TTY_BREAK
;
407 if (port
->flags
& ASYNC_SAK
)
410 } else if (status
& RCSR_PE
)
411 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
413 else if (status
& RCSR_FE
)
414 *tty
->flip
.flag_buf_ptr
++ = TTY_FRAME
;
416 else if (status
& RCSR_OE
)
417 *tty
->flip
.flag_buf_ptr
++ = TTY_OVERRUN
;
420 *tty
->flip
.flag_buf_ptr
++ = 0;
422 *tty
->flip
.char_buf_ptr
++ = ch
;
424 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
427 extern inline void rc_receive(struct riscom_board
const * bp
)
429 struct riscom_port
*port
;
430 struct tty_struct
*tty
;
433 if (!(port
= rc_get_port(bp
, "Receive")))
438 count
= rc_in(bp
, CD180_RDCR
);
440 #ifdef RC_REPORT_FIFO
441 port
->hits
[count
> 8 ? 9 : count
]++;
445 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
446 printk("rc%d: port %d: Working around flip buffer overflow.\n",
447 board_No(bp
), port_No(port
));
450 *tty
->flip
.char_buf_ptr
++ = rc_in(bp
, CD180_RDR
);
451 *tty
->flip
.flag_buf_ptr
++ = 0;
454 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
457 extern inline void rc_transmit(struct riscom_board
const * bp
)
459 struct riscom_port
*port
;
460 struct tty_struct
*tty
;
464 if (!(port
= rc_get_port(bp
, "Transmit")))
469 if (port
->IER
& IER_TXEMPTY
) {
471 rc_out(bp
, CD180_CAR
, port_No(port
));
472 port
->IER
&= ~IER_TXEMPTY
;
473 rc_out(bp
, CD180_IER
, port
->IER
);
477 if ((port
->xmit_cnt
<= 0 && !port
->break_length
)
478 || tty
->stopped
|| tty
->hw_stopped
) {
479 rc_out(bp
, CD180_CAR
, port_No(port
));
480 port
->IER
&= ~IER_TXRDY
;
481 rc_out(bp
, CD180_IER
, port
->IER
);
485 if (port
->break_length
) {
486 if (port
->break_length
> 0) {
487 if (port
->COR2
& COR2_ETC
) {
488 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
489 rc_out(bp
, CD180_TDR
, CD180_C_SBRK
);
490 port
->COR2
&= ~COR2_ETC
;
492 count
= MIN(port
->break_length
, 0xff);
493 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
494 rc_out(bp
, CD180_TDR
, CD180_C_DELAY
);
495 rc_out(bp
, CD180_TDR
, count
);
496 if (!(port
->break_length
-= count
))
497 port
->break_length
--;
499 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
500 rc_out(bp
, CD180_TDR
, CD180_C_EBRK
);
501 rc_out(bp
, CD180_COR2
, port
->COR2
);
503 rc_out(bp
, CD180_CCR
, CCR_CORCHG2
);
504 port
->break_length
= 0;
511 rc_out(bp
, CD180_TDR
, port
->xmit_buf
[port
->xmit_tail
++]);
512 port
->xmit_tail
= port
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
513 if (--port
->xmit_cnt
<= 0)
515 } while (--count
> 0);
517 if (port
->xmit_cnt
<= 0) {
518 rc_out(bp
, CD180_CAR
, port_No(port
));
519 port
->IER
&= ~IER_TXRDY
;
520 rc_out(bp
, CD180_IER
, port
->IER
);
522 if (port
->xmit_cnt
<= port
->wakeup_chars
)
523 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
526 extern inline void rc_check_modem(struct riscom_board
const * bp
)
528 struct riscom_port
*port
;
529 struct tty_struct
*tty
;
532 if (!(port
= rc_get_port(bp
, "Modem")))
537 mcr
= rc_in(bp
, CD180_MCR
);
538 if (mcr
& MCR_CDCHG
) {
539 if (rc_in(bp
, CD180_MSVR
) & MSVR_CD
)
540 wake_up_interruptible(&port
->open_wait
);
541 else if (!((port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
542 (port
->flags
& ASYNC_CALLOUT_NOHUP
)))
543 queue_task(&port
->tqueue_hangup
, &tq_scheduler
);
546 #ifdef RISCOM_BRAIN_DAMAGED_CTS
547 if (mcr
& MCR_CTSCHG
) {
548 if (rc_in(bp
, CD180_MSVR
) & MSVR_CTS
) {
550 port
->IER
|= IER_TXRDY
;
551 if (port
->xmit_cnt
<= port
->wakeup_chars
)
552 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
555 port
->IER
&= ~IER_TXRDY
;
557 rc_out(bp
, CD180_IER
, port
->IER
);
559 if (mcr
& MCR_DSRCHG
) {
560 if (rc_in(bp
, CD180_MSVR
) & MSVR_DSR
) {
562 port
->IER
|= IER_TXRDY
;
563 if (port
->xmit_cnt
<= port
->wakeup_chars
)
564 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
567 port
->IER
&= ~IER_TXRDY
;
569 rc_out(bp
, CD180_IER
, port
->IER
);
571 #endif /* RISCOM_BRAIN_DAMAGED_CTS */
573 /* Clear change bits */
574 rc_out(bp
, CD180_MCR
, 0);
577 /* The main interrupt processing routine */
578 static void rc_interrupt(int irq
, void * dev_id
, struct pt_regs
* regs
)
580 unsigned char status
;
582 struct riscom_board
*bp
;
583 unsigned long loop
= 0;
585 bp
= IRQ_to_board
[irq
];
587 if (!bp
|| !(bp
->flags
& RC_BOARD_ACTIVE
)) {
591 while ((++loop
< 16) && ((status
= ~(rc_in(bp
, RC_BSR
))) &
592 (RC_BSR_TOUT
| RC_BSR_TINT
|
593 RC_BSR_MINT
| RC_BSR_RINT
))) {
595 if (status
& RC_BSR_TOUT
)
596 printk("rc%d: Got timeout. Hardware error ?\n", board_No(bp
));
598 else if (status
& RC_BSR_RINT
) {
599 ack
= rc_in(bp
, RC_ACK_RINT
);
601 if (ack
== (RC_ID
| GIVR_IT_RCV
))
603 else if (ack
== (RC_ID
| GIVR_IT_REXC
))
606 printk("rc%d: Bad receive ack 0x%02x.\n",
609 } else if (status
& RC_BSR_TINT
) {
610 ack
= rc_in(bp
, RC_ACK_TINT
);
612 if (ack
== (RC_ID
| GIVR_IT_TX
))
615 printk("rc%d: Bad transmit ack 0x%02x.\n",
618 } else /* if (status & RC_BSR_MINT) */ {
619 ack
= rc_in(bp
, RC_ACK_MINT
);
621 if (ack
== (RC_ID
| GIVR_IT_MODEM
))
624 printk("rc%d: Bad modem ack 0x%02x.\n",
629 rc_out(bp
, CD180_EOIR
, 0); /* Mark end of interrupt */
630 rc_out(bp
, RC_CTOUT
, 0); /* Clear timeout flag */
635 * Routines for open & close processing.
638 /* Called with disabled interrupts */
639 extern inline int rc_setup_board(struct riscom_board
* bp
)
643 if (bp
->flags
& RC_BOARD_ACTIVE
)
646 error
= request_irq(bp
->irq
, rc_interrupt
, SA_INTERRUPT
, "RISCom/8", NULL
);
650 rc_out(bp
, RC_CTOUT
, 0); /* Just in case */
652 rc_out(bp
, RC_DTR
, bp
->DTR
); /* Drop DTR on all ports */
654 IRQ_to_board
[bp
->irq
] = bp
;
655 bp
->flags
|= RC_BOARD_ACTIVE
;
661 /* Called with disabled interrupts */
662 extern inline void rc_shutdown_board(struct riscom_board
*bp
)
664 if (!(bp
->flags
& RC_BOARD_ACTIVE
))
667 bp
->flags
&= ~RC_BOARD_ACTIVE
;
669 free_irq(bp
->irq
, NULL
);
670 IRQ_to_board
[bp
->irq
] = NULL
;
673 rc_out(bp
, RC_DTR
, bp
->DTR
); /* Drop DTR on all ports */
679 * Setting up port characteristics.
680 * Must be called with disabled interrupts
682 static void rc_change_speed(struct riscom_board
*bp
, struct riscom_port
*port
)
684 struct tty_struct
*tty
;
687 unsigned char cor1
= 0, cor3
= 0;
688 unsigned char mcor1
= 0, mcor2
= 0;
690 if (!(tty
= port
->tty
) || !tty
->termios
)
695 port
->MSVR
= MSVR_RTS
;
699 if (baud
& CBAUDEX
) {
701 if (baud
< 1 || baud
> 2)
702 port
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
707 if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
709 if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
713 /* Select port on the board */
714 rc_out(bp
, CD180_CAR
, port_No(port
));
716 if (!baud_table
[baud
]) {
717 /* Drop DTR & exit */
718 bp
->DTR
|= (1u << port_No(port
));
719 rc_out(bp
, RC_DTR
, bp
->DTR
);
723 bp
->DTR
&= ~(1u << port_No(port
));
724 rc_out(bp
, RC_DTR
, bp
->DTR
);
728 * Now we must calculate some speed depended things
731 /* Set baud rate for port */
732 tmp
= (((RC_OSCFREQ
+ baud_table
[baud
]/2) / baud_table
[baud
] +
733 CD180_TPC
/2) / CD180_TPC
);
735 rc_out(bp
, CD180_RBPRH
, (tmp
>> 8) & 0xff);
736 rc_out(bp
, CD180_TBPRH
, (tmp
>> 8) & 0xff);
737 rc_out(bp
, CD180_RBPRL
, tmp
& 0xff);
738 rc_out(bp
, CD180_TBPRL
, tmp
& 0xff);
740 baud
= (baud_table
[baud
] + 5) / 10; /* Estimated CPS */
742 /* Two timer ticks seems enough to wakeup something like SLIP driver */
743 tmp
= ((baud
+ HZ
/2) / HZ
) * 2 - CD180_NFIFO
;
744 port
->wakeup_chars
= (tmp
< 0) ? 0 : ((tmp
>= SERIAL_XMIT_SIZE
) ?
745 SERIAL_XMIT_SIZE
- 1 : tmp
);
747 /* Receiver timeout will be transmission time for 1.5 chars */
748 tmp
= (RISCOM_TPS
+ RISCOM_TPS
/2 + baud
/2) / baud
;
749 tmp
= (tmp
> 0xff) ? 0xff : tmp
;
750 rc_out(bp
, CD180_RTPR
, tmp
);
752 switch (C_CSIZE(tty
)) {
772 cor1
|= COR1_NORMPAR
;
776 cor1
&= ~COR1_IGNORE
;
778 /* Set marking of some errors */
779 port
->mark_mask
= RCSR_OE
| RCSR_TOUT
;
781 port
->mark_mask
|= RCSR_FE
| RCSR_PE
;
782 if (I_BRKINT(tty
) || I_PARMRK(tty
))
783 port
->mark_mask
|= RCSR_BREAK
;
785 port
->mark_mask
&= ~(RCSR_FE
| RCSR_PE
);
787 port
->mark_mask
&= ~RCSR_BREAK
;
789 /* Real raw mode. Ignore all */
790 port
->mark_mask
&= ~RCSR_OE
;
792 /* Enable Hardware Flow Control */
793 if (C_CRTSCTS(tty
)) {
794 #ifdef RISCOM_BRAIN_DAMAGED_CTS
795 port
->IER
|= IER_DSR
| IER_CTS
;
796 mcor1
|= MCOR1_DSRZD
| MCOR1_CTSZD
;
797 mcor2
|= MCOR2_DSROD
| MCOR2_CTSOD
;
798 tty
->hw_stopped
= !(rc_in(bp
, CD180_MSVR
) & (MSVR_CTS
|MSVR_DSR
));
800 port
->COR2
|= COR2_CTSAE
;
803 /* Enable Software Flow Control. FIXME: I'm not sure about this */
804 /* Some people reported that it works, but I still doubt */
806 port
->COR2
|= COR2_TXIBE
;
807 cor3
|= (COR3_FCT
| COR3_SCDE
);
809 port
->COR2
|= COR2_IXM
;
810 rc_out(bp
, CD180_SCHR1
, START_CHAR(tty
));
811 rc_out(bp
, CD180_SCHR2
, STOP_CHAR(tty
));
812 rc_out(bp
, CD180_SCHR3
, START_CHAR(tty
));
813 rc_out(bp
, CD180_SCHR4
, STOP_CHAR(tty
));
815 if (!C_CLOCAL(tty
)) {
816 /* Enable CD check */
823 /* Enable receiver */
824 port
->IER
|= IER_RXD
;
826 /* Set input FIFO size (1-8 bytes) */
827 cor3
|= RISCOM_RXFIFO
;
828 /* Setting up CD180 channel registers */
829 rc_out(bp
, CD180_COR1
, cor1
);
830 rc_out(bp
, CD180_COR2
, port
->COR2
);
831 rc_out(bp
, CD180_COR3
, cor3
);
832 /* Make CD180 know about registers change */
834 rc_out(bp
, CD180_CCR
, CCR_CORCHG1
| CCR_CORCHG2
| CCR_CORCHG3
);
835 /* Setting up modem option registers */
836 rc_out(bp
, CD180_MCOR1
, mcor1
);
837 rc_out(bp
, CD180_MCOR2
, mcor2
);
838 /* Enable CD180 transmitter & receiver */
840 rc_out(bp
, CD180_CCR
, CCR_TXEN
| CCR_RXEN
);
841 /* Enable interrupts */
842 rc_out(bp
, CD180_IER
, port
->IER
);
843 /* And finally set RTS on */
844 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
847 /* Must be called with interrupts enabled */
848 static int rc_setup_port(struct riscom_board
*bp
, struct riscom_port
*port
)
852 if (port
->flags
& ASYNC_INITIALIZED
)
855 if (!port
->xmit_buf
) {
856 /* We may sleep in get_free_page() */
859 if (!(tmp
= get_free_page(GFP_KERNEL
)))
862 if (port
->xmit_buf
) {
866 port
->xmit_buf
= (unsigned char *) tmp
;
869 save_flags(flags
); cli();
872 clear_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
874 if (port
->count
== 1)
877 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
878 rc_change_speed(bp
, port
);
879 port
->flags
|= ASYNC_INITIALIZED
;
881 restore_flags(flags
);
885 /* Must be called with interrupts disabled */
886 static void rc_shutdown_port(struct riscom_board
*bp
, struct riscom_port
*port
)
888 struct tty_struct
*tty
;
890 if (!(port
->flags
& ASYNC_INITIALIZED
))
893 #ifdef RC_REPORT_OVERRUN
894 printk("rc%d: port %d: Total %ld overruns were detected.\n",
895 board_No(bp
), port_No(port
), port
->overrun
);
897 #ifdef RC_REPORT_FIFO
901 printk("rc%d: port %d: FIFO hits [ ",
902 board_No(bp
), port_No(port
));
903 for (i
= 0; i
< 10; i
++) {
904 printk("%ld ", port
->hits
[i
]);
909 if (port
->xmit_buf
) {
910 free_page((unsigned long) port
->xmit_buf
);
911 port
->xmit_buf
= NULL
;
914 if (!(tty
= port
->tty
) || C_HUPCL(tty
)) {
916 bp
->DTR
|= (1u << port_No(port
));
917 rc_out(bp
, RC_DTR
, bp
->DTR
);
921 rc_out(bp
, CD180_CAR
, port_No(port
));
924 rc_out(bp
, CD180_CCR
, CCR_SOFTRESET
);
925 /* Disable all interrupts from this port */
927 rc_out(bp
, CD180_IER
, port
->IER
);
930 set_bit(TTY_IO_ERROR
, &tty
->flags
);
931 port
->flags
&= ~ASYNC_INITIALIZED
;
933 if (--bp
->count
< 0) {
934 printk("rc%d: rc_shutdown_port: bad board count: %d\n",
935 board_No(bp
), bp
->count
);
940 * If this is the last opened port on the board
941 * shutdown whole board
944 rc_shutdown_board(bp
);
948 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
949 struct riscom_port
*port
)
951 DECLARE_WAITQUEUE(wait
, current
);
952 struct riscom_board
*bp
= port_Board(port
);
958 * If the device is in the middle of being closed, then block
959 * until it's done, and then try again.
961 if (tty_hung_up_p(filp
) || port
->flags
& ASYNC_CLOSING
) {
962 interruptible_sleep_on(&port
->close_wait
);
963 if (port
->flags
& ASYNC_HUP_NOTIFY
)
970 * If this is a callout device, then just make sure the normal
971 * device isn't being used.
973 if (tty
->driver
.subtype
== RISCOM_TYPE_CALLOUT
) {
974 if (port
->flags
& ASYNC_NORMAL_ACTIVE
)
976 if ((port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
977 (port
->flags
& ASYNC_SESSION_LOCKOUT
) &&
978 (port
->session
!= current
->session
))
980 if ((port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
981 (port
->flags
& ASYNC_PGRP_LOCKOUT
) &&
982 (port
->pgrp
!= current
->pgrp
))
984 port
->flags
|= ASYNC_CALLOUT_ACTIVE
;
989 * If non-blocking mode is set, or the port is not enabled,
990 * then make the check up front and then exit.
992 if ((filp
->f_flags
& O_NONBLOCK
) ||
993 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
994 if (port
->flags
& ASYNC_CALLOUT_ACTIVE
)
996 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
1000 if (port
->flags
& ASYNC_CALLOUT_ACTIVE
) {
1001 if (port
->normal_termios
.c_cflag
& CLOCAL
)
1009 * Block waiting for the carrier detect and the line to become
1010 * free (i.e., not in use by the callout). While we are in
1011 * this loop, info->count is dropped by one, so that
1012 * rs_close() knows when to free things. We restore it upon
1013 * exit, either normal or abnormal.
1016 add_wait_queue(&port
->open_wait
, &wait
);
1018 if (!tty_hung_up_p(filp
))
1021 port
->blocked_open
++;
1024 rc_out(bp
, CD180_CAR
, port_No(port
));
1025 CD
= rc_in(bp
, CD180_MSVR
) & MSVR_CD
;
1026 if (!(port
->flags
& ASYNC_CALLOUT_ACTIVE
)) {
1027 rc_out(bp
, CD180_MSVR
, MSVR_RTS
);
1028 bp
->DTR
&= ~(1u << port_No(port
));
1029 rc_out(bp
, RC_DTR
, bp
->DTR
);
1032 set_current_state(TASK_INTERRUPTIBLE
);
1033 if (tty_hung_up_p(filp
) ||
1034 !(port
->flags
& ASYNC_INITIALIZED
)) {
1035 if (port
->flags
& ASYNC_HUP_NOTIFY
)
1038 retval
= -ERESTARTSYS
;
1041 if (!(port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1042 !(port
->flags
& ASYNC_CLOSING
) &&
1045 if (signal_pending(current
)) {
1046 retval
= -ERESTARTSYS
;
1051 current
->state
= TASK_RUNNING
;
1052 remove_wait_queue(&port
->open_wait
, &wait
);
1053 if (!tty_hung_up_p(filp
))
1055 port
->blocked_open
--;
1059 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
1063 static int rc_open(struct tty_struct
* tty
, struct file
* filp
)
1067 struct riscom_port
* port
;
1068 struct riscom_board
* bp
;
1069 unsigned long flags
;
1071 board
= RC_BOARD(MINOR(tty
->device
));
1072 if (board
> RC_NBOARD
|| !(rc_board
[board
].flags
& RC_BOARD_PRESENT
))
1075 bp
= &rc_board
[board
];
1076 port
= rc_port
+ board
* RC_NPORT
+ RC_PORT(MINOR(tty
->device
));
1077 if (rc_paranoia_check(port
, tty
->device
, "rc_open"))
1080 if ((error
= rc_setup_board(bp
)))
1084 tty
->driver_data
= port
;
1087 if ((error
= rc_setup_port(bp
, port
)))
1090 if ((error
= block_til_ready(tty
, filp
, port
)))
1093 if ((port
->count
== 1) && (port
->flags
& ASYNC_SPLIT_TERMIOS
)) {
1094 if (tty
->driver
.subtype
== RISCOM_TYPE_NORMAL
)
1095 *tty
->termios
= port
->normal_termios
;
1097 *tty
->termios
= port
->callout_termios
;
1098 save_flags(flags
); cli();
1099 rc_change_speed(bp
, port
);
1100 restore_flags(flags
);
1103 port
->session
= current
->session
;
1104 port
->pgrp
= current
->pgrp
;
1109 static void rc_close(struct tty_struct
* tty
, struct file
* filp
)
1111 struct riscom_port
*port
= (struct riscom_port
*) tty
->driver_data
;
1112 struct riscom_board
*bp
;
1113 unsigned long flags
;
1114 unsigned long timeout
;
1116 if (!port
|| rc_paranoia_check(port
, tty
->device
, "close"))
1119 save_flags(flags
); cli();
1120 if (tty_hung_up_p(filp
)) {
1121 restore_flags(flags
);
1125 bp
= port_Board(port
);
1126 if ((tty
->count
== 1) && (port
->count
!= 1)) {
1127 printk("rc%d: rc_close: bad port count;"
1128 " tty->count is 1, port count is %d\n",
1129 board_No(bp
), port
->count
);
1132 if (--port
->count
< 0) {
1133 printk("rc%d: rc_close: bad port count for tty%d: %d\n",
1134 board_No(bp
), port_No(port
), port
->count
);
1138 restore_flags(flags
);
1141 port
->flags
|= ASYNC_CLOSING
;
1143 * Save the termios structure, since this port may have
1144 * separate termios for callout and dialin.
1146 if (port
->flags
& ASYNC_NORMAL_ACTIVE
)
1147 port
->normal_termios
= *tty
->termios
;
1148 if (port
->flags
& ASYNC_CALLOUT_ACTIVE
)
1149 port
->callout_termios
= *tty
->termios
;
1151 * Now we wait for the transmit buffer to clear; and we notify
1152 * the line discipline to only process XON/XOFF characters.
1155 if (port
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1156 tty_wait_until_sent(tty
, port
->closing_wait
);
1158 * At this point we stop accepting input. To do this, we
1159 * disable the receive line status interrupts, and tell the
1160 * interrupt driver to stop checking the data ready bit in the
1161 * line status register.
1163 port
->IER
&= ~IER_RXD
;
1164 if (port
->flags
& ASYNC_INITIALIZED
) {
1165 port
->IER
&= ~IER_TXRDY
;
1166 port
->IER
|= IER_TXEMPTY
;
1167 rc_out(bp
, CD180_CAR
, port_No(port
));
1168 rc_out(bp
, CD180_IER
, port
->IER
);
1170 * Before we drop DTR, make sure the UART transmitter
1171 * has completely drained; this is especially
1172 * important if there is a transmit FIFO!
1174 timeout
= jiffies
+HZ
;
1175 while(port
->IER
& IER_TXEMPTY
) {
1176 current
->state
= TASK_INTERRUPTIBLE
;
1177 schedule_timeout(port
->timeout
);
1178 if (time_after(jiffies
, timeout
))
1182 rc_shutdown_port(bp
, port
);
1183 if (tty
->driver
.flush_buffer
)
1184 tty
->driver
.flush_buffer(tty
);
1185 if (tty
->ldisc
.flush_buffer
)
1186 tty
->ldisc
.flush_buffer(tty
);
1190 if (port
->blocked_open
) {
1191 if (port
->close_delay
) {
1192 current
->state
= TASK_INTERRUPTIBLE
;
1193 schedule_timeout(port
->close_delay
);
1195 wake_up_interruptible(&port
->open_wait
);
1197 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
|
1199 wake_up_interruptible(&port
->close_wait
);
1200 restore_flags(flags
);
1203 static int rc_write(struct tty_struct
* tty
, int from_user
,
1204 const unsigned char *buf
, int count
)
1206 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1207 struct riscom_board
*bp
;
1209 unsigned long flags
;
1211 if (rc_paranoia_check(port
, tty
->device
, "rc_write"))
1214 bp
= port_Board(port
);
1216 if (!tty
|| !port
->xmit_buf
|| !tmp_buf
)
1225 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1226 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1231 copy_from_user(tmp_buf
, buf
, c
);
1232 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1233 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1234 memcpy(port
->xmit_buf
+ port
->xmit_head
, tmp_buf
, c
);
1236 memcpy(port
->xmit_buf
+ port
->xmit_head
, buf
, c
);
1237 port
->xmit_head
= (port
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
1238 port
->xmit_cnt
+= c
;
1239 restore_flags(flags
);
1246 if (port
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
&&
1247 !(port
->IER
& IER_TXRDY
)) {
1248 port
->IER
|= IER_TXRDY
;
1249 rc_out(bp
, CD180_CAR
, port_No(port
));
1250 rc_out(bp
, CD180_IER
, port
->IER
);
1252 restore_flags(flags
);
1256 static void rc_put_char(struct tty_struct
* tty
, unsigned char ch
)
1258 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1259 unsigned long flags
;
1261 if (rc_paranoia_check(port
, tty
->device
, "rc_put_char"))
1264 if (!tty
|| !port
->xmit_buf
)
1267 save_flags(flags
); cli();
1269 if (port
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
1270 restore_flags(flags
);
1274 port
->xmit_buf
[port
->xmit_head
++] = ch
;
1275 port
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
1277 restore_flags(flags
);
1280 static void rc_flush_chars(struct tty_struct
* tty
)
1282 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1283 unsigned long flags
;
1285 if (rc_paranoia_check(port
, tty
->device
, "rc_flush_chars"))
1288 if (port
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
1292 save_flags(flags
); cli();
1293 port
->IER
|= IER_TXRDY
;
1294 rc_out(port_Board(port
), CD180_CAR
, port_No(port
));
1295 rc_out(port_Board(port
), CD180_IER
, port
->IER
);
1296 restore_flags(flags
);
1299 static int rc_write_room(struct tty_struct
* tty
)
1301 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1304 if (rc_paranoia_check(port
, tty
->device
, "rc_write_room"))
1307 ret
= SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1;
1313 static int rc_chars_in_buffer(struct tty_struct
*tty
)
1315 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1317 if (rc_paranoia_check(port
, tty
->device
, "rc_chars_in_buffer"))
1320 return port
->xmit_cnt
;
1323 static void rc_flush_buffer(struct tty_struct
*tty
)
1325 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1326 unsigned long flags
;
1328 if (rc_paranoia_check(port
, tty
->device
, "rc_flush_buffer"))
1331 save_flags(flags
); cli();
1332 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
1333 restore_flags(flags
);
1335 wake_up_interruptible(&tty
->write_wait
);
1336 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1337 tty
->ldisc
.write_wakeup
)
1338 (tty
->ldisc
.write_wakeup
)(tty
);
1341 static int rc_get_modem_info(struct riscom_port
* port
, unsigned int *value
)
1343 struct riscom_board
* bp
;
1344 unsigned char status
;
1345 unsigned int result
;
1346 unsigned long flags
;
1348 bp
= port_Board(port
);
1349 save_flags(flags
); cli();
1350 rc_out(bp
, CD180_CAR
, port_No(port
));
1351 status
= rc_in(bp
, CD180_MSVR
);
1352 result
= rc_in(bp
, RC_RI
) & (1u << port_No(port
)) ? 0 : TIOCM_RNG
;
1353 restore_flags(flags
);
1354 result
|= ((status
& MSVR_RTS
) ? TIOCM_RTS
: 0)
1355 | ((status
& MSVR_DTR
) ? TIOCM_DTR
: 0)
1356 | ((status
& MSVR_CD
) ? TIOCM_CAR
: 0)
1357 | ((status
& MSVR_DSR
) ? TIOCM_DSR
: 0)
1358 | ((status
& MSVR_CTS
) ? TIOCM_CTS
: 0);
1359 put_user(result
, value
);
1363 static int rc_set_modem_info(struct riscom_port
* port
, unsigned int cmd
,
1364 unsigned int *value
)
1368 unsigned long flags
;
1369 struct riscom_board
*bp
= port_Board(port
);
1371 error
= get_user(arg
, value
);
1376 if (arg
& TIOCM_RTS
)
1377 port
->MSVR
|= MSVR_RTS
;
1378 if (arg
& TIOCM_DTR
)
1379 bp
->DTR
&= ~(1u << port_No(port
));
1382 if (arg
& TIOCM_RTS
)
1383 port
->MSVR
&= ~MSVR_RTS
;
1384 if (arg
& TIOCM_DTR
)
1385 bp
->DTR
|= (1u << port_No(port
));
1388 port
->MSVR
= (arg
& TIOCM_RTS
) ? (port
->MSVR
| MSVR_RTS
) :
1389 (port
->MSVR
& ~MSVR_RTS
);
1390 bp
->DTR
= arg
& TIOCM_DTR
? (bp
->DTR
&= ~(1u << port_No(port
))) :
1391 (bp
->DTR
|= (1u << port_No(port
)));
1396 save_flags(flags
); cli();
1397 rc_out(bp
, CD180_CAR
, port_No(port
));
1398 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1399 rc_out(bp
, RC_DTR
, bp
->DTR
);
1400 restore_flags(flags
);
1404 extern inline void rc_send_break(struct riscom_port
* port
, unsigned long length
)
1406 struct riscom_board
*bp
= port_Board(port
);
1407 unsigned long flags
;
1409 save_flags(flags
); cli();
1410 port
->break_length
= RISCOM_TPS
/ HZ
* length
;
1411 port
->COR2
|= COR2_ETC
;
1412 port
->IER
|= IER_TXRDY
;
1413 rc_out(bp
, CD180_CAR
, port_No(port
));
1414 rc_out(bp
, CD180_COR2
, port
->COR2
);
1415 rc_out(bp
, CD180_IER
, port
->IER
);
1417 rc_out(bp
, CD180_CCR
, CCR_CORCHG2
);
1419 restore_flags(flags
);
1422 extern inline int rc_set_serial_info(struct riscom_port
* port
,
1423 struct serial_struct
* newinfo
)
1425 struct serial_struct tmp
;
1426 struct riscom_board
*bp
= port_Board(port
);
1428 unsigned long flags
;
1431 error
= verify_area(VERIFY_READ
, (void *) newinfo
, sizeof(tmp
));
1434 copy_from_user(&tmp
, newinfo
, sizeof(tmp
));
1437 if ((tmp
.irq
!= bp
->irq
) ||
1438 (tmp
.port
!= bp
->base
) ||
1439 (tmp
.type
!= PORT_CIRRUS
) ||
1440 (tmp
.baud_base
!= (RC_OSCFREQ
+ CD180_TPC
/2) / CD180_TPC
) ||
1441 (tmp
.custom_divisor
!= 0) ||
1442 (tmp
.xmit_fifo_size
!= CD180_NFIFO
) ||
1443 (tmp
.flags
& ~RISCOM_LEGAL_FLAGS
))
1447 change_speed
= ((port
->flags
& ASYNC_SPD_MASK
) !=
1448 (tmp
.flags
& ASYNC_SPD_MASK
));
1450 if (!capable(CAP_SYS_ADMIN
)) {
1451 if ((tmp
.close_delay
!= port
->close_delay
) ||
1452 (tmp
.closing_wait
!= port
->closing_wait
) ||
1453 ((tmp
.flags
& ~ASYNC_USR_MASK
) !=
1454 (port
->flags
& ~ASYNC_USR_MASK
)))
1456 port
->flags
= ((port
->flags
& ~ASYNC_USR_MASK
) |
1457 (tmp
.flags
& ASYNC_USR_MASK
));
1459 port
->flags
= ((port
->flags
& ~ASYNC_FLAGS
) |
1460 (tmp
.flags
& ASYNC_FLAGS
));
1461 port
->close_delay
= tmp
.close_delay
;
1462 port
->closing_wait
= tmp
.closing_wait
;
1465 save_flags(flags
); cli();
1466 rc_change_speed(bp
, port
);
1467 restore_flags(flags
);
1472 extern inline int rc_get_serial_info(struct riscom_port
* port
,
1473 struct serial_struct
* retinfo
)
1475 struct serial_struct tmp
;
1476 struct riscom_board
*bp
= port_Board(port
);
1479 error
= verify_area(VERIFY_WRITE
, (void *) retinfo
, sizeof(tmp
));
1483 memset(&tmp
, 0, sizeof(tmp
));
1484 tmp
.type
= PORT_CIRRUS
;
1485 tmp
.line
= port
- rc_port
;
1486 tmp
.port
= bp
->base
;
1488 tmp
.flags
= port
->flags
;
1489 tmp
.baud_base
= (RC_OSCFREQ
+ CD180_TPC
/2) / CD180_TPC
;
1490 tmp
.close_delay
= port
->close_delay
* HZ
/100;
1491 tmp
.closing_wait
= port
->closing_wait
* HZ
/100;
1492 tmp
.xmit_fifo_size
= CD180_NFIFO
;
1493 copy_to_user(retinfo
, &tmp
, sizeof(tmp
));
1497 static int rc_ioctl(struct tty_struct
* tty
, struct file
* filp
,
1498 unsigned int cmd
, unsigned long arg
)
1501 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1505 if (rc_paranoia_check(port
, tty
->device
, "rc_ioctl"))
1509 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1510 retval
= tty_check_change(tty
);
1513 tty_wait_until_sent(tty
, 0);
1515 rc_send_break(port
, HZ
/4); /* 1/4 second */
1517 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1518 retval
= tty_check_change(tty
);
1521 tty_wait_until_sent(tty
, 0);
1522 rc_send_break(port
, arg
? arg
*(HZ
/10) : HZ
/4);
1525 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned int *) arg
);
1527 retval
= get_user(arg
,(unsigned int *) arg
);
1530 tty
->termios
->c_cflag
=
1531 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1532 (arg
? CLOCAL
: 0));
1535 error
= verify_area(VERIFY_WRITE
, (void *) arg
,
1536 sizeof(unsigned int));
1539 return rc_get_modem_info(port
, (unsigned int *) arg
);
1543 return rc_set_modem_info(port
, cmd
, (unsigned int *) arg
);
1545 return rc_get_serial_info(port
, (struct serial_struct
*) arg
);
1547 return rc_set_serial_info(port
, (struct serial_struct
*) arg
);
1549 return -ENOIOCTLCMD
;
1554 static void rc_throttle(struct tty_struct
* tty
)
1556 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1557 struct riscom_board
*bp
;
1558 unsigned long flags
;
1560 if (rc_paranoia_check(port
, tty
->device
, "rc_throttle"))
1563 bp
= port_Board(port
);
1565 save_flags(flags
); cli();
1566 port
->MSVR
&= ~MSVR_RTS
;
1567 rc_out(bp
, CD180_CAR
, port_No(port
));
1570 rc_out(bp
, CD180_CCR
, CCR_SSCH2
);
1573 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1574 restore_flags(flags
);
1577 static void rc_unthrottle(struct tty_struct
* tty
)
1579 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1580 struct riscom_board
*bp
;
1581 unsigned long flags
;
1583 if (rc_paranoia_check(port
, tty
->device
, "rc_unthrottle"))
1586 bp
= port_Board(port
);
1588 save_flags(flags
); cli();
1589 port
->MSVR
|= MSVR_RTS
;
1590 rc_out(bp
, CD180_CAR
, port_No(port
));
1593 rc_out(bp
, CD180_CCR
, CCR_SSCH1
);
1596 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1597 restore_flags(flags
);
1600 static void rc_stop(struct tty_struct
* tty
)
1602 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1603 struct riscom_board
*bp
;
1604 unsigned long flags
;
1606 if (rc_paranoia_check(port
, tty
->device
, "rc_stop"))
1609 bp
= port_Board(port
);
1611 save_flags(flags
); cli();
1612 port
->IER
&= ~IER_TXRDY
;
1613 rc_out(bp
, CD180_CAR
, port_No(port
));
1614 rc_out(bp
, CD180_IER
, port
->IER
);
1615 restore_flags(flags
);
1618 static void rc_start(struct tty_struct
* tty
)
1620 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1621 struct riscom_board
*bp
;
1622 unsigned long flags
;
1624 if (rc_paranoia_check(port
, tty
->device
, "rc_start"))
1627 bp
= port_Board(port
);
1629 save_flags(flags
); cli();
1630 if (port
->xmit_cnt
&& port
->xmit_buf
&& !(port
->IER
& IER_TXRDY
)) {
1631 port
->IER
|= IER_TXRDY
;
1632 rc_out(bp
, CD180_CAR
, port_No(port
));
1633 rc_out(bp
, CD180_IER
, port
->IER
);
1635 restore_flags(flags
);
1639 * This routine is called from the scheduler tqueue when the interrupt
1640 * routine has signalled that a hangup has occurred. The path of
1641 * hangup processing is:
1643 * serial interrupt routine -> (scheduler tqueue) ->
1644 * do_rc_hangup() -> tty->hangup() -> rc_hangup()
1647 static void do_rc_hangup(void *private_
)
1649 struct riscom_port
*port
= (struct riscom_port
*) private_
;
1650 struct tty_struct
*tty
;
1659 static void rc_hangup(struct tty_struct
* tty
)
1661 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1662 struct riscom_board
*bp
;
1664 if (rc_paranoia_check(port
, tty
->device
, "rc_hangup"))
1667 bp
= port_Board(port
);
1669 rc_shutdown_port(bp
, port
);
1672 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
);
1674 wake_up_interruptible(&port
->open_wait
);
1677 static void rc_set_termios(struct tty_struct
* tty
, struct termios
* old_termios
)
1679 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1680 unsigned long flags
;
1682 if (rc_paranoia_check(port
, tty
->device
, "rc_set_termios"))
1685 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
&&
1686 tty
->termios
->c_iflag
== old_termios
->c_iflag
)
1689 save_flags(flags
); cli();
1690 rc_change_speed(port_Board(port
), port
);
1691 restore_flags(flags
);
1693 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1694 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1695 tty
->hw_stopped
= 0;
1700 static void do_riscom_bh(void)
1702 run_task_queue(&tq_riscom
);
1705 static void do_softint(void *private_
)
1707 struct riscom_port
*port
= (struct riscom_port
*) private_
;
1708 struct tty_struct
*tty
;
1710 if(!(tty
= port
->tty
))
1713 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &port
->event
)) {
1714 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1715 tty
->ldisc
.write_wakeup
)
1716 (tty
->ldisc
.write_wakeup
)(tty
);
1717 wake_up_interruptible(&tty
->write_wait
);
1721 static inline int rc_init_drivers(void)
1727 if (!(tmp_buf
= (unsigned char *) get_free_page(GFP_KERNEL
))) {
1728 printk("rc: Couldn't get free page.\n");
1731 init_bh(RISCOM8_BH
, do_riscom_bh
);
1732 memset(IRQ_to_board
, 0, sizeof(IRQ_to_board
));
1733 memset(&riscom_driver
, 0, sizeof(riscom_driver
));
1734 riscom_driver
.magic
= TTY_DRIVER_MAGIC
;
1735 riscom_driver
.name
= "ttyL";
1736 riscom_driver
.major
= RISCOM8_NORMAL_MAJOR
;
1737 riscom_driver
.num
= RC_NBOARD
* RC_NPORT
;
1738 riscom_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
1739 riscom_driver
.subtype
= RISCOM_TYPE_NORMAL
;
1740 riscom_driver
.init_termios
= tty_std_termios
;
1741 riscom_driver
.init_termios
.c_cflag
=
1742 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1743 riscom_driver
.flags
= TTY_DRIVER_REAL_RAW
;
1744 riscom_driver
.refcount
= &riscom_refcount
;
1745 riscom_driver
.table
= riscom_table
;
1746 riscom_driver
.termios
= riscom_termios
;
1747 riscom_driver
.termios_locked
= riscom_termios_locked
;
1749 riscom_driver
.open
= rc_open
;
1750 riscom_driver
.close
= rc_close
;
1751 riscom_driver
.write
= rc_write
;
1752 riscom_driver
.put_char
= rc_put_char
;
1753 riscom_driver
.flush_chars
= rc_flush_chars
;
1754 riscom_driver
.write_room
= rc_write_room
;
1755 riscom_driver
.chars_in_buffer
= rc_chars_in_buffer
;
1756 riscom_driver
.flush_buffer
= rc_flush_buffer
;
1757 riscom_driver
.ioctl
= rc_ioctl
;
1758 riscom_driver
.throttle
= rc_throttle
;
1759 riscom_driver
.unthrottle
= rc_unthrottle
;
1760 riscom_driver
.set_termios
= rc_set_termios
;
1761 riscom_driver
.stop
= rc_stop
;
1762 riscom_driver
.start
= rc_start
;
1763 riscom_driver
.hangup
= rc_hangup
;
1765 riscom_callout_driver
= riscom_driver
;
1766 riscom_callout_driver
.name
= "cul";
1767 riscom_callout_driver
.major
= RISCOM8_CALLOUT_MAJOR
;
1768 riscom_callout_driver
.subtype
= RISCOM_TYPE_CALLOUT
;
1770 if ((error
= tty_register_driver(&riscom_driver
))) {
1771 free_page((unsigned long)tmp_buf
);
1772 printk("rc: Couldn't register RISCom/8 driver, error = %d\n",
1776 if ((error
= tty_register_driver(&riscom_callout_driver
))) {
1777 free_page((unsigned long)tmp_buf
);
1778 tty_unregister_driver(&riscom_driver
);
1779 printk("rc: Couldn't register RISCom/8 callout driver, error = %d\n",
1784 memset(rc_port
, 0, sizeof(rc_port
));
1785 for (i
= 0; i
< RC_NPORT
* RC_NBOARD
; i
++) {
1786 rc_port
[i
].callout_termios
= riscom_callout_driver
.init_termios
;
1787 rc_port
[i
].normal_termios
= riscom_driver
.init_termios
;
1788 rc_port
[i
].magic
= RISCOM8_MAGIC
;
1789 rc_port
[i
].tqueue
.routine
= do_softint
;
1790 rc_port
[i
].tqueue
.data
= &rc_port
[i
];
1791 rc_port
[i
].tqueue_hangup
.routine
= do_rc_hangup
;
1792 rc_port
[i
].tqueue_hangup
.data
= &rc_port
[i
];
1793 rc_port
[i
].close_delay
= 50 * HZ
/100;
1794 rc_port
[i
].closing_wait
= 3000 * HZ
/100;
1795 init_waitqueue_head(&rc_port
[i
].open_wait
);
1796 init_waitqueue_head(&rc_port
[i
].close_wait
);
1802 static void rc_release_drivers(void)
1804 unsigned long flags
;
1808 remove_bh(RISCOM8_BH
);
1809 free_page((unsigned long)tmp_buf
);
1810 tty_unregister_driver(&riscom_driver
);
1811 tty_unregister_driver(&riscom_callout_driver
);
1812 restore_flags(flags
);
1817 * Called at boot time.
1819 * You can specify IO base for up to RC_NBOARD cards,
1820 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
1821 * Note that there will be no probing at default
1822 * addresses in this case.
1825 void __init
riscom8_setup(char *str
, int * ints
)
1829 for (i
= 0; i
< RC_NBOARD
; i
++) {
1831 rc_board
[i
].base
= ints
[i
+1];
1833 rc_board
[i
].base
= 0;
1839 * This routine must be called by kernel at boot time
1841 int __init
riscom8_init(void)
1846 printk("rc: SDL RISCom/8 card driver v1.0, (c) D.Gorodchanin 1994-1996.\n");
1848 if (rc_init_drivers())
1851 for (i
= 0; i
< RC_NBOARD
; i
++)
1852 if (rc_board
[i
].base
&& !rc_probe(&rc_board
[i
]))
1856 rc_release_drivers();
1857 printk("rc: No RISCom/8 boards detected.\n");
1868 MODULE_PARM(iobase
, "i");
1869 MODULE_PARM(iobase1
, "i");
1870 MODULE_PARM(iobase2
, "i");
1871 MODULE_PARM(iobase3
, "i");
1874 * You can setup up to 4 boards (current value of RC_NBOARD)
1875 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter.
1878 int init_module(void)
1882 if (iobase
|| iobase1
|| iobase2
|| iobase3
) {
1883 for(i
= 0; i
< RC_NBOARD
; i
++)
1884 rc_board
[0].base
= 0;
1888 rc_board
[0].base
= iobase
;
1890 rc_board
[1].base
= iobase1
;
1892 rc_board
[2].base
= iobase2
;
1894 rc_board
[3].base
= iobase3
;
1896 return riscom8_init();
1899 void cleanup_module(void)
1903 rc_release_drivers();
1904 for (i
= 0; i
< RC_NBOARD
; i
++)
1905 if (rc_board
[i
].flags
& RC_BOARD_PRESENT
)
1906 rc_release_io_range(&rc_board
[i
]);