2 * linux/drivers/char/riscom.c -- RISCom/8 multiport serial driver.
4 * Copyright (C) 1994-1996 Dmitry Gorodchanin (begemot@bgm.rosprint.net)
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 DECLARE_TASK_QUEUE(tq_riscom
);
80 #define RISCOM_TYPE_NORMAL 1
81 #define RISCOM_TYPE_CALLOUT 2
83 static struct riscom_board
* IRQ_to_board
[16] = { NULL
, } ;
84 static struct tty_driver riscom_driver
, riscom_callout_driver
;
85 static int riscom_refcount
= 0;
86 static struct tty_struct
* riscom_table
[RC_NBOARD
* RC_NPORT
] = { NULL
, };
87 static struct termios
* riscom_termios
[RC_NBOARD
* RC_NPORT
] = { NULL
, };
88 static struct termios
* riscom_termios_locked
[RC_NBOARD
* RC_NPORT
] = { NULL
, };
89 static unsigned char * tmp_buf
= NULL
;
90 static struct semaphore tmp_buf_sem
= MUTEX
;
92 static unsigned long baud_table
[] = {
93 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
94 9600, 19200, 38400, 57600, 76800, 0,
97 static struct riscom_board rc_board
[RC_NBOARD
] = {
98 { 0, RC_IOBASE1
, 0, },
99 { 0, RC_IOBASE2
, 0, },
100 { 0, RC_IOBASE3
, 0, },
101 { 0, RC_IOBASE4
, 0, },
104 static struct riscom_port rc_port
[RC_NBOARD
* RC_NPORT
] = {
108 /* RISCom/8 I/O ports addresses (without address translation) */
109 static unsigned short rc_ioport
[] = {
111 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c,
113 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10,
114 0x11, 0x12, 0x18, 0x28, 0x31, 0x32, 0x39, 0x3a, 0x40, 0x41, 0x61, 0x62,
115 0x63, 0x64, 0x6b, 0x70, 0x71, 0x78, 0x7a, 0x7b, 0x7f, 0x100, 0x101
118 #define RC_NIOPORT (sizeof(rc_ioport) / sizeof(rc_ioport[0]))
121 static inline int rc_paranoia_check(struct riscom_port
const * port
,
122 kdev_t device
, const char *routine
)
124 #ifdef RISCOM_PARANOIA_CHECK
125 static const char *badmagic
=
126 "rc: Warning: bad riscom port magic number for device %s in %s\n";
127 static const char *badinfo
=
128 "rc: Warning: null riscom port for device %s in %s\n";
131 printk(badinfo
, kdevname(device
), routine
);
134 if (port
->magic
!= RISCOM8_MAGIC
) {
135 printk(badmagic
, kdevname(device
), routine
);
144 * Service functions for RISCom/8 driver.
148 /* Get board number from pointer */
149 extern inline int board_No (struct riscom_board
const * bp
)
151 return bp
- rc_board
;
154 /* Get port number from pointer */
155 extern inline int port_No (struct riscom_port
const * port
)
157 return RC_PORT(port
- rc_port
);
160 /* Get pointer to board from pointer to port */
161 extern inline struct riscom_board
* port_Board(struct riscom_port
const * port
)
163 return &rc_board
[RC_BOARD(port
- rc_port
)];
166 /* Input Byte from CL CD180 register */
167 extern inline unsigned char rc_in(struct riscom_board
const * bp
, unsigned short reg
)
169 return inb(bp
->base
+ RC_TO_ISA(reg
));
172 /* Output Byte to CL CD180 register */
173 extern inline void rc_out(struct riscom_board
const * bp
, unsigned short reg
,
176 outb(val
, bp
->base
+ RC_TO_ISA(reg
));
179 /* Wait for Channel Command Register ready */
180 extern inline void rc_wait_CCR(struct riscom_board
const * bp
)
184 /* FIXME: need something more descriptive then 100000 :) */
185 for (delay
= 100000; delay
; delay
--)
186 if (!rc_in(bp
, CD180_CCR
))
189 printk("rc%d: Timeout waiting for CCR.\n", board_No(bp
));
193 * RISCom/8 probe functions.
196 extern inline int rc_check_io_range(struct riscom_board
* const bp
)
200 for (i
= 0; i
< RC_NIOPORT
; i
++)
201 if (check_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1)) {
202 printk("rc%d: Skipping probe at 0x%03x. I/O address in use.\n",
203 board_No(bp
), bp
->base
);
209 extern inline void rc_request_io_range(struct riscom_board
* const bp
)
213 for (i
= 0; i
< RC_NIOPORT
; i
++)
214 request_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1, "RISCom/8" );
217 extern inline void rc_release_io_range(struct riscom_board
* const bp
)
221 for (i
= 0; i
< RC_NIOPORT
; i
++)
222 release_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1);
226 /* Must be called with enabled interrupts */
227 extern inline void rc_long_delay(unsigned long delay
)
231 for (i
= jiffies
+ delay
; i
> jiffies
; ) ;
234 /* Reset and setup CD180 chip */
235 __initfunc(static void rc_init_CD180(struct riscom_board
const * bp
))
239 save_flags(flags
); cli();
240 rc_out(bp
, RC_CTOUT
, 0); /* Clear timeout */
241 rc_wait_CCR(bp
); /* Wait for CCR ready */
242 rc_out(bp
, CD180_CCR
, CCR_HARDRESET
); /* Reset CD180 chip */
244 rc_long_delay(HZ
/20); /* Delay 0.05 sec */
246 rc_out(bp
, CD180_GIVR
, RC_ID
); /* Set ID for this chip */
247 rc_out(bp
, CD180_GICR
, 0); /* Clear all bits */
248 rc_out(bp
, CD180_PILR1
, RC_ACK_MINT
); /* Prio for modem intr */
249 rc_out(bp
, CD180_PILR2
, RC_ACK_TINT
); /* Prio for transmitter intr */
250 rc_out(bp
, CD180_PILR3
, RC_ACK_RINT
); /* Prio for receiver intr */
252 /* Setting up prescaler. We need 4 ticks per 1 ms */
253 rc_out(bp
, CD180_PPRH
, (RC_OSCFREQ
/(1000000/RISCOM_TPS
)) >> 8);
254 rc_out(bp
, CD180_PPRL
, (RC_OSCFREQ
/(1000000/RISCOM_TPS
)) & 0xff);
256 restore_flags(flags
);
259 /* Main probing routine, also sets irq. */
260 __initfunc(static int rc_probe(struct riscom_board
*bp
))
262 unsigned char val1
, val2
;
268 if (rc_check_io_range(bp
))
271 /* Are the I/O ports here ? */
272 rc_out(bp
, CD180_PPRL
, 0x5a);
274 val1
= rc_in(bp
, CD180_PPRL
);
275 rc_out(bp
, CD180_PPRL
, 0xa5);
277 val2
= rc_in(bp
, CD180_PPRL
);
279 if ((val1
!= 0x5a) || (val2
!= 0xa5)) {
280 printk("rc%d: RISCom/8 Board at 0x%03x not found.\n",
281 board_No(bp
), bp
->base
);
285 /* It's time to find IRQ for this board */
286 for (retries
= 0; retries
< 5 && irqs
<= 0; retries
++) {
287 irqs
= probe_irq_on();
288 rc_init_CD180(bp
); /* Reset CD180 chip */
289 rc_out(bp
, CD180_CAR
, 2); /* Select port 2 */
291 rc_out(bp
, CD180_CCR
, CCR_TXEN
); /* Enable transmitter */
292 rc_out(bp
, CD180_IER
, IER_TXRDY
); /* Enable tx empty intr */
293 rc_long_delay(HZ
/20);
294 irqs
= probe_irq_off(irqs
);
295 val1
= rc_in(bp
, RC_BSR
); /* Get Board Status reg */
296 val2
= rc_in(bp
, RC_ACK_TINT
); /* ACK interrupt */
297 rc_init_CD180(bp
); /* Reset CD180 again */
299 if ((val1
& RC_BSR_TINT
) || (val2
!= (RC_ID
| GIVR_IT_TX
))) {
300 printk("rc%d: RISCom/8 Board at 0x%03x not found.\n",
301 board_No(bp
), bp
->base
);
307 printk("rc%d: Can't find IRQ for RISCom/8 board at 0x%03x.\n",
308 board_No(bp
), bp
->base
);
311 rc_request_io_range(bp
);
313 bp
->flags
|= RC_BOARD_PRESENT
;
315 printk("rc%d: RISCom/8 Rev. %c board detected at 0x%03x, IRQ %d.\n",
317 (rc_in(bp
, CD180_GFRCR
) & 0x0f) + 'A', /* Board revision */
325 * Interrupt processing routines.
329 extern inline void rc_mark_event(struct riscom_port
* port
, int event
)
332 * I'm not quite happy with current scheme all serial
333 * drivers use their own BH routine.
334 * It seems this easily can be done with one BH routine
335 * serving for all serial drivers.
336 * For now I must introduce another one - RISCOM8_BH.
337 * Still hope this will be changed in near future.
339 set_bit(event
, &port
->event
);
340 queue_task_irq_off(&port
->tqueue
, &tq_riscom
);
344 extern inline struct riscom_port
* rc_get_port(struct riscom_board
const * bp
,
345 unsigned char const * what
)
347 unsigned char channel
;
348 struct riscom_port
* port
;
350 channel
= rc_in(bp
, CD180_GICR
) >> GICR_CHAN_OFF
;
351 if (channel
< CD180_NCH
) {
352 port
= &rc_port
[board_No(bp
) * RC_NPORT
+ channel
];
353 if (port
->flags
& ASYNC_INITIALIZED
) {
357 printk("rc%d: %s interrupt from invalid port %d\n",
358 board_No(bp
), what
, channel
);
362 extern inline void rc_receive_exc(struct riscom_board
const * bp
)
364 struct riscom_port
*port
;
365 struct tty_struct
*tty
;
366 unsigned char status
;
369 if (!(port
= rc_get_port(bp
, "Receive")))
373 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
374 printk("rc%d: port %d: Working around flip buffer overflow.\n",
375 board_No(bp
), port_No(port
));
379 #ifdef RC_REPORT_OVERRUN
380 status
= rc_in(bp
, CD180_RCSR
);
381 if (status
& RCSR_OE
) {
384 printk("rc%d: port %d: Overrun. Total %ld overruns.\n",
385 board_No(bp
), port_No(port
), port
->overrun
);
388 status
&= port
->mark_mask
;
390 status
= rc_in(bp
, CD180_RCSR
) & port
->mark_mask
;
392 ch
= rc_in(bp
, CD180_RDR
);
396 if (status
& RCSR_TOUT
) {
397 printk("rc%d: port %d: Receiver timeout. Hardware problems ?\n",
398 board_No(bp
), port_No(port
));
401 } else if (status
& RCSR_BREAK
) {
402 printk("rc%d: port %d: Handling break...\n",
403 board_No(bp
), port_No(port
));
404 *tty
->flip
.flag_buf_ptr
++ = TTY_BREAK
;
405 if (port
->flags
& ASYNC_SAK
)
408 } else if (status
& RCSR_PE
)
409 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
411 else if (status
& RCSR_FE
)
412 *tty
->flip
.flag_buf_ptr
++ = TTY_FRAME
;
414 else if (status
& RCSR_OE
)
415 *tty
->flip
.flag_buf_ptr
++ = TTY_OVERRUN
;
418 *tty
->flip
.flag_buf_ptr
++ = 0;
420 *tty
->flip
.char_buf_ptr
++ = ch
;
422 queue_task_irq_off(&tty
->flip
.tqueue
, &tq_timer
);
425 extern inline void rc_receive(struct riscom_board
const * bp
)
427 struct riscom_port
*port
;
428 struct tty_struct
*tty
;
431 if (!(port
= rc_get_port(bp
, "Receive")))
436 count
= rc_in(bp
, CD180_RDCR
);
438 #ifdef RC_REPORT_FIFO
439 port
->hits
[count
> 8 ? 9 : count
]++;
443 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
444 printk("rc%d: port %d: Working around flip buffer overflow.\n",
445 board_No(bp
), port_No(port
));
448 *tty
->flip
.char_buf_ptr
++ = rc_in(bp
, CD180_RDR
);
449 *tty
->flip
.flag_buf_ptr
++ = 0;
452 queue_task_irq_off(&tty
->flip
.tqueue
, &tq_timer
);
455 extern inline void rc_transmit(struct riscom_board
const * bp
)
457 struct riscom_port
*port
;
458 struct tty_struct
*tty
;
462 if (!(port
= rc_get_port(bp
, "Transmit")))
467 if (port
->IER
& IER_TXEMPTY
) {
469 rc_out(bp
, CD180_CAR
, port_No(port
));
470 port
->IER
&= ~IER_TXEMPTY
;
471 rc_out(bp
, CD180_IER
, port
->IER
);
475 if ((port
->xmit_cnt
<= 0 && !port
->break_length
)
476 || tty
->stopped
|| tty
->hw_stopped
) {
477 rc_out(bp
, CD180_CAR
, port_No(port
));
478 port
->IER
&= ~IER_TXRDY
;
479 rc_out(bp
, CD180_IER
, port
->IER
);
483 if (port
->break_length
) {
484 if (port
->break_length
> 0) {
485 if (port
->COR2
& COR2_ETC
) {
486 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
487 rc_out(bp
, CD180_TDR
, CD180_C_SBRK
);
488 port
->COR2
&= ~COR2_ETC
;
490 count
= MIN(port
->break_length
, 0xff);
491 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
492 rc_out(bp
, CD180_TDR
, CD180_C_DELAY
);
493 rc_out(bp
, CD180_TDR
, count
);
494 if (!(port
->break_length
-= count
))
495 port
->break_length
--;
497 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
498 rc_out(bp
, CD180_TDR
, CD180_C_EBRK
);
499 rc_out(bp
, CD180_COR2
, port
->COR2
);
501 rc_out(bp
, CD180_CCR
, CCR_CORCHG2
);
502 port
->break_length
= 0;
509 rc_out(bp
, CD180_TDR
, port
->xmit_buf
[port
->xmit_tail
++]);
510 port
->xmit_tail
= port
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
511 if (--port
->xmit_cnt
<= 0)
513 } while (--count
> 0);
515 if (port
->xmit_cnt
<= 0) {
516 rc_out(bp
, CD180_CAR
, port_No(port
));
517 port
->IER
&= ~IER_TXRDY
;
518 rc_out(bp
, CD180_IER
, port
->IER
);
520 if (port
->xmit_cnt
<= port
->wakeup_chars
)
521 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
524 extern inline void rc_check_modem(struct riscom_board
const * bp
)
526 struct riscom_port
*port
;
527 struct tty_struct
*tty
;
530 if (!(port
= rc_get_port(bp
, "Modem")))
535 mcr
= rc_in(bp
, CD180_MCR
);
536 if (mcr
& MCR_CDCHG
) {
537 if (rc_in(bp
, CD180_MSVR
) & MSVR_CD
)
538 wake_up_interruptible(&port
->open_wait
);
539 else if (!((port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
540 (port
->flags
& ASYNC_CALLOUT_NOHUP
)))
541 queue_task_irq_off(&port
->tqueue_hangup
,
545 #ifdef RISCOM_BRAIN_DAMAGED_CTS
546 if (mcr
& MCR_CTSCHG
) {
547 if (rc_in(bp
, CD180_MSVR
) & MSVR_CTS
) {
549 port
->IER
|= IER_TXRDY
;
550 if (port
->xmit_cnt
<= port
->wakeup_chars
)
551 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
554 port
->IER
&= ~IER_TXRDY
;
556 rc_out(bp
, CD180_IER
, port
->IER
);
558 if (mcr
& MCR_DSRCHG
) {
559 if (rc_in(bp
, CD180_MSVR
) & MSVR_DSR
) {
561 port
->IER
|= IER_TXRDY
;
562 if (port
->xmit_cnt
<= port
->wakeup_chars
)
563 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
566 port
->IER
&= ~IER_TXRDY
;
568 rc_out(bp
, CD180_IER
, port
->IER
);
570 #endif /* RISCOM_BRAIN_DAMAGED_CTS */
572 /* Clear change bits */
573 rc_out(bp
, CD180_MCR
, 0);
576 /* The main interrupt processing routine */
577 static void rc_interrupt(int irq
, void * dev_id
, struct pt_regs
* regs
)
579 unsigned char status
;
581 struct riscom_board
*bp
;
582 unsigned long loop
= 0;
584 bp
= IRQ_to_board
[irq
];
586 if (!bp
|| !(bp
->flags
& RC_BOARD_ACTIVE
)) {
590 while ((++loop
< 16) && ((status
= ~(rc_in(bp
, RC_BSR
))) &
591 (RC_BSR_TOUT
| RC_BSR_TINT
|
592 RC_BSR_MINT
| RC_BSR_RINT
))) {
594 if (status
& RC_BSR_TOUT
)
595 printk("rc%d: Got timeout. Hardware error ?\n", board_No(bp
));
597 else if (status
& RC_BSR_RINT
) {
598 ack
= rc_in(bp
, RC_ACK_RINT
);
600 if (ack
== (RC_ID
| GIVR_IT_RCV
))
602 else if (ack
== (RC_ID
| GIVR_IT_REXC
))
605 printk("rc%d: Bad receive ack 0x%02x.\n",
608 } else if (status
& RC_BSR_TINT
) {
609 ack
= rc_in(bp
, RC_ACK_TINT
);
611 if (ack
== (RC_ID
| GIVR_IT_TX
))
614 printk("rc%d: Bad transmit ack 0x%02x.\n",
617 } else /* if (status & RC_BSR_MINT) */ {
618 ack
= rc_in(bp
, RC_ACK_MINT
);
620 if (ack
== (RC_ID
| GIVR_IT_MODEM
))
623 printk("rc%d: Bad modem ack 0x%02x.\n",
628 rc_out(bp
, CD180_EOIR
, 0); /* Mark end of interrupt */
629 rc_out(bp
, RC_CTOUT
, 0); /* Clear timeout flag */
634 * Routines for open & close processing.
637 /* Called with disabled interrupts */
638 extern inline int rc_setup_board(struct riscom_board
* bp
)
642 if (bp
->flags
& RC_BOARD_ACTIVE
)
645 error
= request_irq(bp
->irq
, rc_interrupt
, SA_INTERRUPT
, "RISCom/8", NULL
);
649 rc_out(bp
, RC_CTOUT
, 0); /* Just in case */
651 rc_out(bp
, RC_DTR
, bp
->DTR
); /* Drop DTR on all ports */
653 IRQ_to_board
[bp
->irq
] = bp
;
654 bp
->flags
|= RC_BOARD_ACTIVE
;
660 /* Called with disabled interrupts */
661 extern inline void rc_shutdown_board(struct riscom_board
*bp
)
663 if (!(bp
->flags
& RC_BOARD_ACTIVE
))
666 bp
->flags
&= ~RC_BOARD_ACTIVE
;
668 free_irq(bp
->irq
, NULL
);
669 IRQ_to_board
[bp
->irq
] = NULL
;
672 rc_out(bp
, RC_DTR
, bp
->DTR
); /* Drop DTR on all ports */
678 * Setting up port characteristics.
679 * Must be called with disabled interrupts
681 static void rc_change_speed(struct riscom_board
*bp
, struct riscom_port
*port
)
683 struct tty_struct
*tty
;
686 unsigned char cor1
= 0, cor3
= 0;
687 unsigned char mcor1
= 0, mcor2
= 0;
689 if (!(tty
= port
->tty
) || !tty
->termios
)
694 port
->MSVR
= MSVR_RTS
;
698 if (baud
& CBAUDEX
) {
700 if (baud
< 1 || baud
> 2)
701 port
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
706 if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
708 if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
712 /* Select port on the board */
713 rc_out(bp
, CD180_CAR
, port_No(port
));
715 if (!baud_table
[baud
]) {
716 /* Drop DTR & exit */
717 bp
->DTR
|= (1u << port_No(port
));
718 rc_out(bp
, RC_DTR
, bp
->DTR
);
722 bp
->DTR
&= ~(1u << port_No(port
));
723 rc_out(bp
, RC_DTR
, bp
->DTR
);
727 * Now we must calculate some speed depended things
730 /* Set baud rate for port */
731 tmp
= (((RC_OSCFREQ
+ baud_table
[baud
]/2) / baud_table
[baud
] +
732 CD180_TPC
/2) / CD180_TPC
);
734 rc_out(bp
, CD180_RBPRH
, (tmp
>> 8) & 0xff);
735 rc_out(bp
, CD180_TBPRH
, (tmp
>> 8) & 0xff);
736 rc_out(bp
, CD180_RBPRL
, tmp
& 0xff);
737 rc_out(bp
, CD180_TBPRL
, tmp
& 0xff);
739 baud
= (baud_table
[baud
] + 5) / 10; /* Estimated CPS */
741 /* Two timer ticks seems enough to wakeup something like SLIP driver */
742 tmp
= ((baud
+ HZ
/2) / HZ
) * 2 - CD180_NFIFO
;
743 port
->wakeup_chars
= (tmp
< 0) ? 0 : ((tmp
>= SERIAL_XMIT_SIZE
) ?
744 SERIAL_XMIT_SIZE
- 1 : tmp
);
746 /* Receiver timeout will be transmission time for 1.5 chars */
747 tmp
= (RISCOM_TPS
+ RISCOM_TPS
/2 + baud
/2) / baud
;
748 tmp
= (tmp
> 0xff) ? 0xff : tmp
;
749 rc_out(bp
, CD180_RTPR
, tmp
);
751 switch (C_CSIZE(tty
)) {
771 cor1
|= COR1_NORMPAR
;
775 cor1
&= ~COR1_IGNORE
;
777 /* Set marking of some errors */
778 port
->mark_mask
= RCSR_OE
| RCSR_TOUT
;
780 port
->mark_mask
|= RCSR_FE
| RCSR_PE
;
781 if (I_BRKINT(tty
) || I_PARMRK(tty
))
782 port
->mark_mask
|= RCSR_BREAK
;
784 port
->mark_mask
&= ~(RCSR_FE
| RCSR_PE
);
786 port
->mark_mask
&= ~RCSR_BREAK
;
788 /* Real raw mode. Ignore all */
789 port
->mark_mask
&= ~RCSR_OE
;
791 /* Enable Hardware Flow Control */
792 if (C_CRTSCTS(tty
)) {
793 #ifdef RISCOM_BRAIN_DAMAGED_CTS
794 port
->IER
|= IER_DSR
| IER_CTS
;
795 mcor1
|= MCOR1_DSRZD
| MCOR1_CTSZD
;
796 mcor2
|= MCOR2_DSROD
| MCOR2_CTSOD
;
797 tty
->hw_stopped
= !(rc_in(bp
, CD180_MSVR
) & (MSVR_CTS
|MSVR_DSR
));
799 port
->COR2
|= COR2_CTSAE
;
802 /* Enable Software Flow Control. FIXME: I'm not sure about this */
803 /* Some people reported that it works, but I still doubt */
805 port
->COR2
|= COR2_TXIBE
;
806 cor3
|= (COR3_FCT
| COR3_SCDE
);
808 port
->COR2
|= COR2_IXM
;
809 rc_out(bp
, CD180_SCHR1
, START_CHAR(tty
));
810 rc_out(bp
, CD180_SCHR2
, STOP_CHAR(tty
));
811 rc_out(bp
, CD180_SCHR3
, START_CHAR(tty
));
812 rc_out(bp
, CD180_SCHR4
, STOP_CHAR(tty
));
814 if (!C_CLOCAL(tty
)) {
815 /* Enable CD check */
822 /* Enable receiver */
823 port
->IER
|= IER_RXD
;
825 /* Set input FIFO size (1-8 bytes) */
826 cor3
|= RISCOM_RXFIFO
;
827 /* Setting up CD180 channel registers */
828 rc_out(bp
, CD180_COR1
, cor1
);
829 rc_out(bp
, CD180_COR2
, port
->COR2
);
830 rc_out(bp
, CD180_COR3
, cor3
);
831 /* Make CD180 know about registers change */
833 rc_out(bp
, CD180_CCR
, CCR_CORCHG1
| CCR_CORCHG2
| CCR_CORCHG3
);
834 /* Setting up modem option registers */
835 rc_out(bp
, CD180_MCOR1
, mcor1
);
836 rc_out(bp
, CD180_MCOR2
, mcor2
);
837 /* Enable CD180 transmitter & receiver */
839 rc_out(bp
, CD180_CCR
, CCR_TXEN
| CCR_RXEN
);
840 /* Enable interrupts */
841 rc_out(bp
, CD180_IER
, port
->IER
);
842 /* And finally set RTS on */
843 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
846 /* Must be called with interrupts enabled */
847 static int rc_setup_port(struct riscom_board
*bp
, struct riscom_port
*port
)
851 if (port
->flags
& ASYNC_INITIALIZED
)
854 if (!port
->xmit_buf
) {
855 /* We may sleep in get_free_page() */
858 if (!(tmp
= get_free_page(GFP_KERNEL
)))
861 if (port
->xmit_buf
) {
865 port
->xmit_buf
= (unsigned char *) tmp
;
868 save_flags(flags
); cli();
871 clear_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
873 if (port
->count
== 1)
876 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
877 rc_change_speed(bp
, port
);
878 port
->flags
|= ASYNC_INITIALIZED
;
880 restore_flags(flags
);
884 /* Must be called with interrupts disabled */
885 static void rc_shutdown_port(struct riscom_board
*bp
, struct riscom_port
*port
)
887 struct tty_struct
*tty
;
889 if (!(port
->flags
& ASYNC_INITIALIZED
))
892 #ifdef RC_REPORT_OVERRUN
893 printk("rc%d: port %d: Total %ld overruns were detected.\n",
894 board_No(bp
), port_No(port
), port
->overrun
);
896 #ifdef RC_REPORT_FIFO
900 printk("rc%d: port %d: FIFO hits [ ",
901 board_No(bp
), port_No(port
));
902 for (i
= 0; i
< 10; i
++) {
903 printk("%ld ", port
->hits
[i
]);
908 if (port
->xmit_buf
) {
909 free_page((unsigned long) port
->xmit_buf
);
910 port
->xmit_buf
= NULL
;
913 if (!(tty
= port
->tty
) || C_HUPCL(tty
)) {
915 bp
->DTR
|= (1u << port_No(port
));
916 rc_out(bp
, RC_DTR
, bp
->DTR
);
920 rc_out(bp
, CD180_CAR
, port_No(port
));
923 rc_out(bp
, CD180_CCR
, CCR_SOFTRESET
);
924 /* Disable all interrupts from this port */
926 rc_out(bp
, CD180_IER
, port
->IER
);
929 set_bit(TTY_IO_ERROR
, &tty
->flags
);
930 port
->flags
&= ~ASYNC_INITIALIZED
;
932 if (--bp
->count
< 0) {
933 printk("rc%d: rc_shutdown_port: bad board count: %d\n",
934 board_No(bp
), bp
->count
);
939 * If this is the last opened port on the board
940 * shutdown whole board
943 rc_shutdown_board(bp
);
947 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
948 struct riscom_port
*port
)
950 struct wait_queue wait
= { current
, NULL
};
951 struct riscom_board
*bp
= port_Board(port
);
957 * If the device is in the middle of being closed, then block
958 * until it's done, and then try again.
960 if (tty_hung_up_p(filp
) || port
->flags
& ASYNC_CLOSING
) {
961 interruptible_sleep_on(&port
->close_wait
);
962 if (port
->flags
& ASYNC_HUP_NOTIFY
)
969 * If this is a callout device, then just make sure the normal
970 * device isn't being used.
972 if (tty
->driver
.subtype
== RISCOM_TYPE_CALLOUT
) {
973 if (port
->flags
& ASYNC_NORMAL_ACTIVE
)
975 if ((port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
976 (port
->flags
& ASYNC_SESSION_LOCKOUT
) &&
977 (port
->session
!= current
->session
))
979 if ((port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
980 (port
->flags
& ASYNC_PGRP_LOCKOUT
) &&
981 (port
->pgrp
!= current
->pgrp
))
983 port
->flags
|= ASYNC_CALLOUT_ACTIVE
;
988 * If non-blocking mode is set, or the port is not enabled,
989 * then make the check up front and then exit.
991 if ((filp
->f_flags
& O_NONBLOCK
) ||
992 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
993 if (port
->flags
& ASYNC_CALLOUT_ACTIVE
)
995 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
999 if (port
->flags
& ASYNC_CALLOUT_ACTIVE
) {
1000 if (port
->normal_termios
.c_cflag
& CLOCAL
)
1008 * Block waiting for the carrier detect and the line to become
1009 * free (i.e., not in use by the callout). While we are in
1010 * this loop, info->count is dropped by one, so that
1011 * rs_close() knows when to free things. We restore it upon
1012 * exit, either normal or abnormal.
1015 add_wait_queue(&port
->open_wait
, &wait
);
1017 if (!tty_hung_up_p(filp
))
1020 port
->blocked_open
++;
1023 rc_out(bp
, CD180_CAR
, port_No(port
));
1024 CD
= rc_in(bp
, CD180_MSVR
) & MSVR_CD
;
1025 if (!(port
->flags
& ASYNC_CALLOUT_ACTIVE
)) {
1026 rc_out(bp
, CD180_MSVR
, MSVR_RTS
);
1027 bp
->DTR
&= ~(1u << port_No(port
));
1028 rc_out(bp
, RC_DTR
, bp
->DTR
);
1031 current
->state
= TASK_INTERRUPTIBLE
;
1032 if (tty_hung_up_p(filp
) ||
1033 !(port
->flags
& ASYNC_INITIALIZED
)) {
1034 if (port
->flags
& ASYNC_HUP_NOTIFY
)
1037 retval
= -ERESTARTSYS
;
1040 if (!(port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1041 !(port
->flags
& ASYNC_CLOSING
) &&
1044 if (current
->signal
& ~current
->blocked
) {
1045 retval
= -ERESTARTSYS
;
1050 current
->state
= TASK_RUNNING
;
1051 remove_wait_queue(&port
->open_wait
, &wait
);
1052 if (!tty_hung_up_p(filp
))
1054 port
->blocked_open
--;
1058 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
1062 static int rc_open(struct tty_struct
* tty
, struct file
* filp
)
1066 struct riscom_port
* port
;
1067 struct riscom_board
* bp
;
1068 unsigned long flags
;
1070 board
= RC_BOARD(MINOR(tty
->device
));
1071 if (board
> RC_NBOARD
|| !(rc_board
[board
].flags
& RC_BOARD_PRESENT
))
1074 bp
= &rc_board
[board
];
1075 port
= rc_port
+ board
* RC_NPORT
+ RC_PORT(MINOR(tty
->device
));
1076 if (rc_paranoia_check(port
, tty
->device
, "rc_open"))
1079 if ((error
= rc_setup_board(bp
)))
1083 tty
->driver_data
= port
;
1086 if ((error
= rc_setup_port(bp
, port
)))
1089 if ((error
= block_til_ready(tty
, filp
, port
)))
1092 if ((port
->count
== 1) && (port
->flags
& ASYNC_SPLIT_TERMIOS
)) {
1093 if (tty
->driver
.subtype
== RISCOM_TYPE_NORMAL
)
1094 *tty
->termios
= port
->normal_termios
;
1096 *tty
->termios
= port
->callout_termios
;
1097 save_flags(flags
); cli();
1098 rc_change_speed(bp
, port
);
1099 restore_flags(flags
);
1102 port
->session
= current
->session
;
1103 port
->pgrp
= current
->pgrp
;
1108 static void rc_close(struct tty_struct
* tty
, struct file
* filp
)
1110 struct riscom_port
*port
= (struct riscom_port
*) tty
->driver_data
;
1111 struct riscom_board
*bp
;
1112 unsigned long flags
;
1113 unsigned long timeout
;
1115 if (!port
|| rc_paranoia_check(port
, tty
->device
, "close"))
1118 save_flags(flags
); cli();
1119 if (tty_hung_up_p(filp
)) {
1120 restore_flags(flags
);
1124 bp
= port_Board(port
);
1125 if ((tty
->count
== 1) && (port
->count
!= 1)) {
1126 printk("rc%d: rc_close: bad port count;"
1127 " tty->count is 1, port count is %d\n",
1128 board_No(bp
), port
->count
);
1131 if (--port
->count
< 0) {
1132 printk("rc%d: rc_close: bad port count for tty%d: %d\n",
1133 board_No(bp
), port_No(port
), port
->count
);
1137 restore_flags(flags
);
1140 port
->flags
|= ASYNC_CLOSING
;
1142 * Save the termios structure, since this port may have
1143 * separate termios for callout and dialin.
1145 if (port
->flags
& ASYNC_NORMAL_ACTIVE
)
1146 port
->normal_termios
= *tty
->termios
;
1147 if (port
->flags
& ASYNC_CALLOUT_ACTIVE
)
1148 port
->callout_termios
= *tty
->termios
;
1150 * Now we wait for the transmit buffer to clear; and we notify
1151 * the line discipline to only process XON/XOFF characters.
1154 if (port
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1155 tty_wait_until_sent(tty
, port
->closing_wait
);
1157 * At this point we stop accepting input. To do this, we
1158 * disable the receive line status interrupts, and tell the
1159 * interrupt driver to stop checking the data ready bit in the
1160 * line status register.
1162 port
->IER
&= ~IER_RXD
;
1163 if (port
->flags
& ASYNC_INITIALIZED
) {
1164 port
->IER
&= ~IER_TXRDY
;
1165 port
->IER
|= IER_TXEMPTY
;
1166 rc_out(bp
, CD180_CAR
, port_No(port
));
1167 rc_out(bp
, CD180_IER
, port
->IER
);
1169 * Before we drop DTR, make sure the UART transmitter
1170 * has completely drained; this is especially
1171 * important if there is a transmit FIFO!
1173 timeout
= jiffies
+HZ
;
1174 while(port
->IER
& IER_TXEMPTY
) {
1175 current
->state
= TASK_INTERRUPTIBLE
;
1176 current
->timeout
= jiffies
+ port
->timeout
;
1178 if (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 current
->timeout
= jiffies
+ port
->close_delay
;
1196 wake_up_interruptible(&port
->open_wait
);
1198 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
|
1200 wake_up_interruptible(&port
->close_wait
);
1201 restore_flags(flags
);
1204 static int rc_write(struct tty_struct
* tty
, int from_user
,
1205 const unsigned char *buf
, int count
)
1207 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1208 struct riscom_board
*bp
;
1210 unsigned long flags
;
1212 if (rc_paranoia_check(port
, tty
->device
, "rc_write"))
1215 bp
= port_Board(port
);
1217 if (!tty
|| !port
->xmit_buf
|| !tmp_buf
)
1226 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1227 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1232 copy_from_user(tmp_buf
, buf
, c
);
1233 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1234 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1235 memcpy(port
->xmit_buf
+ port
->xmit_head
, tmp_buf
, c
);
1237 memcpy(port
->xmit_buf
+ port
->xmit_head
, buf
, c
);
1238 port
->xmit_head
= (port
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
1239 port
->xmit_cnt
+= c
;
1240 restore_flags(flags
);
1247 if (port
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
&&
1248 !(port
->IER
& IER_TXRDY
)) {
1249 port
->IER
|= IER_TXRDY
;
1250 rc_out(bp
, CD180_CAR
, port_No(port
));
1251 rc_out(bp
, CD180_IER
, port
->IER
);
1253 restore_flags(flags
);
1257 static void rc_put_char(struct tty_struct
* tty
, unsigned char ch
)
1259 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1260 unsigned long flags
;
1262 if (rc_paranoia_check(port
, tty
->device
, "rc_put_char"))
1265 if (!tty
|| !port
->xmit_buf
)
1268 save_flags(flags
); cli();
1270 if (port
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
1271 restore_flags(flags
);
1275 port
->xmit_buf
[port
->xmit_head
++] = ch
;
1276 port
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
1278 restore_flags(flags
);
1281 static void rc_flush_chars(struct tty_struct
* tty
)
1283 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1284 unsigned long flags
;
1286 if (rc_paranoia_check(port
, tty
->device
, "rc_flush_chars"))
1289 if (port
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
1293 save_flags(flags
); cli();
1294 port
->IER
|= IER_TXRDY
;
1295 rc_out(port_Board(port
), CD180_CAR
, port_No(port
));
1296 rc_out(port_Board(port
), CD180_IER
, port
->IER
);
1297 restore_flags(flags
);
1300 static int rc_write_room(struct tty_struct
* tty
)
1302 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1305 if (rc_paranoia_check(port
, tty
->device
, "rc_write_room"))
1308 ret
= SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1;
1314 static int rc_chars_in_buffer(struct tty_struct
*tty
)
1316 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1318 if (rc_paranoia_check(port
, tty
->device
, "rc_chars_in_buffer"))
1321 return port
->xmit_cnt
;
1324 static void rc_flush_buffer(struct tty_struct
*tty
)
1326 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1327 unsigned long flags
;
1329 if (rc_paranoia_check(port
, tty
->device
, "rc_flush_buffer"))
1332 save_flags(flags
); cli();
1333 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
1334 restore_flags(flags
);
1336 wake_up_interruptible(&tty
->write_wait
);
1337 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1338 tty
->ldisc
.write_wakeup
)
1339 (tty
->ldisc
.write_wakeup
)(tty
);
1342 static int rc_get_modem_info(struct riscom_port
* port
, unsigned int *value
)
1344 struct riscom_board
* bp
;
1345 unsigned char status
;
1346 unsigned int result
;
1347 unsigned long flags
;
1349 bp
= port_Board(port
);
1350 save_flags(flags
); cli();
1351 rc_out(bp
, CD180_CAR
, port_No(port
));
1352 status
= rc_in(bp
, CD180_MSVR
);
1353 result
= rc_in(bp
, RC_RI
) & (1u << port_No(port
)) ? 0 : TIOCM_RNG
;
1354 restore_flags(flags
);
1355 result
|= ((status
& MSVR_RTS
) ? TIOCM_RTS
: 0)
1356 | ((status
& MSVR_DTR
) ? TIOCM_DTR
: 0)
1357 | ((status
& MSVR_CD
) ? TIOCM_CAR
: 0)
1358 | ((status
& MSVR_DSR
) ? TIOCM_DSR
: 0)
1359 | ((status
& MSVR_CTS
) ? TIOCM_CTS
: 0);
1360 put_user(result
, value
);
1364 static int rc_set_modem_info(struct riscom_port
* port
, unsigned int cmd
,
1365 unsigned int *value
)
1369 unsigned long flags
;
1370 struct riscom_board
*bp
= port_Board(port
);
1372 error
= get_user(arg
, value
);
1377 if (arg
& TIOCM_RTS
)
1378 port
->MSVR
|= MSVR_RTS
;
1379 if (arg
& TIOCM_DTR
)
1380 bp
->DTR
&= ~(1u << port_No(port
));
1383 if (arg
& TIOCM_RTS
)
1384 port
->MSVR
&= ~MSVR_RTS
;
1385 if (arg
& TIOCM_DTR
)
1386 bp
->DTR
|= (1u << port_No(port
));
1389 port
->MSVR
= (arg
& TIOCM_RTS
) ? (port
->MSVR
| MSVR_RTS
) :
1390 (port
->MSVR
& ~MSVR_RTS
);
1391 bp
->DTR
= arg
& TIOCM_DTR
? (bp
->DTR
&= ~(1u << port_No(port
))) :
1392 (bp
->DTR
|= (1u << port_No(port
)));
1397 save_flags(flags
); cli();
1398 rc_out(bp
, CD180_CAR
, port_No(port
));
1399 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1400 rc_out(bp
, RC_DTR
, bp
->DTR
);
1401 restore_flags(flags
);
1405 extern inline void rc_send_break(struct riscom_port
* port
, unsigned long length
)
1407 struct riscom_board
*bp
= port_Board(port
);
1408 unsigned long flags
;
1410 save_flags(flags
); cli();
1411 port
->break_length
= RISCOM_TPS
/ HZ
* length
;
1412 port
->COR2
|= COR2_ETC
;
1413 port
->IER
|= IER_TXRDY
;
1414 rc_out(bp
, CD180_CAR
, port_No(port
));
1415 rc_out(bp
, CD180_COR2
, port
->COR2
);
1416 rc_out(bp
, CD180_IER
, port
->IER
);
1418 rc_out(bp
, CD180_CCR
, CCR_CORCHG2
);
1420 restore_flags(flags
);
1423 extern inline int rc_set_serial_info(struct riscom_port
* port
,
1424 struct serial_struct
* newinfo
)
1426 struct serial_struct tmp
;
1427 struct riscom_board
*bp
= port_Board(port
);
1429 unsigned long flags
;
1432 error
= verify_area(VERIFY_READ
, (void *) newinfo
, sizeof(tmp
));
1435 copy_from_user(&tmp
, newinfo
, sizeof(tmp
));
1438 if ((tmp
.irq
!= bp
->irq
) ||
1439 (tmp
.port
!= bp
->base
) ||
1440 (tmp
.type
!= PORT_CIRRUS
) ||
1441 (tmp
.baud_base
!= (RC_OSCFREQ
+ CD180_TPC
/2) / CD180_TPC
) ||
1442 (tmp
.custom_divisor
!= 0) ||
1443 (tmp
.xmit_fifo_size
!= CD180_NFIFO
) ||
1444 (tmp
.flags
& ~RISCOM_LEGAL_FLAGS
))
1448 change_speed
= ((port
->flags
& ASYNC_SPD_MASK
) !=
1449 (tmp
.flags
& ASYNC_SPD_MASK
));
1452 if ((tmp
.close_delay
!= port
->close_delay
) ||
1453 (tmp
.closing_wait
!= port
->closing_wait
) ||
1454 ((tmp
.flags
& ~ASYNC_USR_MASK
) !=
1455 (port
->flags
& ~ASYNC_USR_MASK
)))
1457 port
->flags
= ((port
->flags
& ~ASYNC_USR_MASK
) |
1458 (tmp
.flags
& ASYNC_USR_MASK
));
1460 port
->flags
= ((port
->flags
& ~ASYNC_FLAGS
) |
1461 (tmp
.flags
& ASYNC_FLAGS
));
1462 port
->close_delay
= tmp
.close_delay
;
1463 port
->closing_wait
= tmp
.closing_wait
;
1466 save_flags(flags
); cli();
1467 rc_change_speed(bp
, port
);
1468 restore_flags(flags
);
1473 extern inline int rc_get_serial_info(struct riscom_port
* port
,
1474 struct serial_struct
* retinfo
)
1476 struct serial_struct tmp
;
1477 struct riscom_board
*bp
= port_Board(port
);
1480 error
= verify_area(VERIFY_WRITE
, (void *) retinfo
, sizeof(tmp
));
1484 memset(&tmp
, 0, sizeof(tmp
));
1485 tmp
.type
= PORT_CIRRUS
;
1486 tmp
.line
= port
- rc_port
;
1487 tmp
.port
= bp
->base
;
1489 tmp
.flags
= port
->flags
;
1490 tmp
.baud_base
= (RC_OSCFREQ
+ CD180_TPC
/2) / CD180_TPC
;
1491 tmp
.close_delay
= port
->close_delay
* HZ
/100;
1492 tmp
.closing_wait
= port
->closing_wait
* HZ
/100;
1493 tmp
.xmit_fifo_size
= CD180_NFIFO
;
1494 copy_to_user(retinfo
, &tmp
, sizeof(tmp
));
1498 static int rc_ioctl(struct tty_struct
* tty
, struct file
* filp
,
1499 unsigned int cmd
, unsigned long arg
)
1502 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1506 if (rc_paranoia_check(port
, tty
->device
, "rc_ioctl"))
1510 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1511 retval
= tty_check_change(tty
);
1514 tty_wait_until_sent(tty
, 0);
1516 rc_send_break(port
, HZ
/4); /* 1/4 second */
1518 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1519 retval
= tty_check_change(tty
);
1522 tty_wait_until_sent(tty
, 0);
1523 rc_send_break(port
, arg
? arg
*(HZ
/10) : HZ
/4);
1526 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned int *) arg
);
1528 retval
= get_user(arg
,(unsigned int *) arg
);
1531 tty
->termios
->c_cflag
=
1532 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1533 (arg
? CLOCAL
: 0));
1536 error
= verify_area(VERIFY_WRITE
, (void *) arg
,
1537 sizeof(unsigned int));
1540 return rc_get_modem_info(port
, (unsigned int *) arg
);
1544 return rc_set_modem_info(port
, cmd
, (unsigned int *) arg
);
1546 return rc_get_serial_info(port
, (struct serial_struct
*) arg
);
1548 return rc_set_serial_info(port
, (struct serial_struct
*) arg
);
1550 return -ENOIOCTLCMD
;
1555 static void rc_throttle(struct tty_struct
* tty
)
1557 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1558 struct riscom_board
*bp
;
1559 unsigned long flags
;
1561 if (rc_paranoia_check(port
, tty
->device
, "rc_throttle"))
1564 bp
= port_Board(port
);
1566 save_flags(flags
); cli();
1567 port
->MSVR
&= ~MSVR_RTS
;
1568 rc_out(bp
, CD180_CAR
, port_No(port
));
1571 rc_out(bp
, CD180_CCR
, CCR_SSCH2
);
1574 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1575 restore_flags(flags
);
1578 static void rc_unthrottle(struct tty_struct
* tty
)
1580 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1581 struct riscom_board
*bp
;
1582 unsigned long flags
;
1584 if (rc_paranoia_check(port
, tty
->device
, "rc_unthrottle"))
1587 bp
= port_Board(port
);
1589 save_flags(flags
); cli();
1590 port
->MSVR
|= MSVR_RTS
;
1591 rc_out(bp
, CD180_CAR
, port_No(port
));
1594 rc_out(bp
, CD180_CCR
, CCR_SSCH1
);
1597 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1598 restore_flags(flags
);
1601 static void rc_stop(struct tty_struct
* tty
)
1603 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1604 struct riscom_board
*bp
;
1605 unsigned long flags
;
1607 if (rc_paranoia_check(port
, tty
->device
, "rc_stop"))
1610 bp
= port_Board(port
);
1612 save_flags(flags
); cli();
1613 port
->IER
&= ~IER_TXRDY
;
1614 rc_out(bp
, CD180_CAR
, port_No(port
));
1615 rc_out(bp
, CD180_IER
, port
->IER
);
1616 restore_flags(flags
);
1619 static void rc_start(struct tty_struct
* tty
)
1621 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1622 struct riscom_board
*bp
;
1623 unsigned long flags
;
1625 if (rc_paranoia_check(port
, tty
->device
, "rc_start"))
1628 bp
= port_Board(port
);
1630 save_flags(flags
); cli();
1631 if (port
->xmit_cnt
&& port
->xmit_buf
&& !(port
->IER
& IER_TXRDY
)) {
1632 port
->IER
|= IER_TXRDY
;
1633 rc_out(bp
, CD180_CAR
, port_No(port
));
1634 rc_out(bp
, CD180_IER
, port
->IER
);
1636 restore_flags(flags
);
1640 * This routine is called from the scheduler tqueue when the interrupt
1641 * routine has signalled that a hangup has occurred. The path of
1642 * hangup processing is:
1644 * serial interrupt routine -> (scheduler tqueue) ->
1645 * do_rc_hangup() -> tty->hangup() -> rc_hangup()
1648 static void do_rc_hangup(void *private_
)
1650 struct riscom_port
*port
= (struct riscom_port
*) private_
;
1651 struct tty_struct
*tty
;
1660 static void rc_hangup(struct tty_struct
* tty
)
1662 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1663 struct riscom_board
*bp
;
1665 if (rc_paranoia_check(port
, tty
->device
, "rc_hangup"))
1668 bp
= port_Board(port
);
1670 rc_shutdown_port(bp
, port
);
1673 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
);
1675 wake_up_interruptible(&port
->open_wait
);
1678 static void rc_set_termios(struct tty_struct
* tty
, struct termios
* old_termios
)
1680 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1681 unsigned long flags
;
1683 if (rc_paranoia_check(port
, tty
->device
, "rc_set_termios"))
1686 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
&&
1687 tty
->termios
->c_iflag
== old_termios
->c_iflag
)
1690 save_flags(flags
); cli();
1691 rc_change_speed(port_Board(port
), port
);
1692 restore_flags(flags
);
1694 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1695 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1696 tty
->hw_stopped
= 0;
1701 static void do_riscom_bh(void)
1703 run_task_queue(&tq_riscom
);
1706 static void do_softint(void *private_
)
1708 struct riscom_port
*port
= (struct riscom_port
*) private_
;
1709 struct tty_struct
*tty
;
1711 if(!(tty
= port
->tty
))
1714 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &port
->event
)) {
1715 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1716 tty
->ldisc
.write_wakeup
)
1717 (tty
->ldisc
.write_wakeup
)(tty
);
1718 wake_up_interruptible(&tty
->write_wait
);
1722 static inline int rc_init_drivers(void)
1728 if (!(tmp_buf
= (unsigned char *) get_free_page(GFP_KERNEL
))) {
1729 printk("rc: Couldn't get free page.\n");
1732 init_bh(RISCOM8_BH
, do_riscom_bh
);
1733 memset(IRQ_to_board
, 0, sizeof(IRQ_to_board
));
1734 memset(&riscom_driver
, 0, sizeof(riscom_driver
));
1735 riscom_driver
.magic
= TTY_DRIVER_MAGIC
;
1736 riscom_driver
.name
= "ttyL";
1737 riscom_driver
.major
= RISCOM8_NORMAL_MAJOR
;
1738 riscom_driver
.num
= RC_NBOARD
* RC_NPORT
;
1739 riscom_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
1740 riscom_driver
.subtype
= RISCOM_TYPE_NORMAL
;
1741 riscom_driver
.init_termios
= tty_std_termios
;
1742 riscom_driver
.init_termios
.c_cflag
=
1743 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1744 riscom_driver
.flags
= TTY_DRIVER_REAL_RAW
;
1745 riscom_driver
.refcount
= &riscom_refcount
;
1746 riscom_driver
.table
= riscom_table
;
1747 riscom_driver
.termios
= riscom_termios
;
1748 riscom_driver
.termios_locked
= riscom_termios_locked
;
1750 riscom_driver
.open
= rc_open
;
1751 riscom_driver
.close
= rc_close
;
1752 riscom_driver
.write
= rc_write
;
1753 riscom_driver
.put_char
= rc_put_char
;
1754 riscom_driver
.flush_chars
= rc_flush_chars
;
1755 riscom_driver
.write_room
= rc_write_room
;
1756 riscom_driver
.chars_in_buffer
= rc_chars_in_buffer
;
1757 riscom_driver
.flush_buffer
= rc_flush_buffer
;
1758 riscom_driver
.ioctl
= rc_ioctl
;
1759 riscom_driver
.throttle
= rc_throttle
;
1760 riscom_driver
.unthrottle
= rc_unthrottle
;
1761 riscom_driver
.set_termios
= rc_set_termios
;
1762 riscom_driver
.stop
= rc_stop
;
1763 riscom_driver
.start
= rc_start
;
1764 riscom_driver
.hangup
= rc_hangup
;
1766 riscom_callout_driver
= riscom_driver
;
1767 riscom_callout_driver
.name
= "cul";
1768 riscom_callout_driver
.major
= RISCOM8_CALLOUT_MAJOR
;
1769 riscom_callout_driver
.subtype
= RISCOM_TYPE_CALLOUT
;
1771 if ((error
= tty_register_driver(&riscom_driver
))) {
1772 free_page((unsigned long)tmp_buf
);
1773 printk("rc: Couldn't register RISCom/8 driver, error = %d\n",
1777 if ((error
= tty_register_driver(&riscom_callout_driver
))) {
1778 free_page((unsigned long)tmp_buf
);
1779 tty_unregister_driver(&riscom_driver
);
1780 printk("rc: Couldn't register RISCom/8 callout driver, error = %d\n",
1785 memset(rc_port
, 0, sizeof(rc_port
));
1786 for (i
= 0; i
< RC_NPORT
* RC_NBOARD
; i
++) {
1787 rc_port
[i
].callout_termios
= riscom_callout_driver
.init_termios
;
1788 rc_port
[i
].normal_termios
= riscom_driver
.init_termios
;
1789 rc_port
[i
].magic
= RISCOM8_MAGIC
;
1790 rc_port
[i
].tqueue
.routine
= do_softint
;
1791 rc_port
[i
].tqueue
.data
= &rc_port
[i
];
1792 rc_port
[i
].tqueue_hangup
.routine
= do_rc_hangup
;
1793 rc_port
[i
].tqueue_hangup
.data
= &rc_port
[i
];
1794 rc_port
[i
].close_delay
= 50 * HZ
/100;
1795 rc_port
[i
].closing_wait
= 3000 * HZ
/100;
1801 static void rc_release_drivers(void)
1803 unsigned long flags
;
1807 remove_bh(RISCOM8_BH
);
1808 free_page((unsigned long)tmp_buf
);
1809 tty_unregister_driver(&riscom_driver
);
1810 tty_unregister_driver(&riscom_callout_driver
);
1811 restore_flags(flags
);
1816 * Called at boot time.
1818 * You can specify IO base for up to RC_NBOARD cards,
1819 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
1820 * Note that there will be no probing at default
1821 * addresses in this case.
1824 __initfunc(void riscom8_setup(char *str
, int * ints
))
1828 for (i
= 0; i
< RC_NBOARD
; i
++) {
1830 rc_board
[i
].base
= ints
[i
+1];
1832 rc_board
[i
].base
= 0;
1838 * This routine must be called by kernel at boot time
1840 __initfunc(int riscom8_init(void))
1845 printk("rc: SDL RISCom/8 card driver v1.0, (c) D.Gorodchanin 1994-1996.\n");
1847 if (rc_init_drivers())
1850 for (i
= 0; i
< RC_NBOARD
; i
++)
1851 if (rc_board
[i
].base
&& !rc_probe(&rc_board
[i
]))
1855 rc_release_drivers();
1856 printk("rc: No RISCom/8 boards detected.\n");
1867 MODULE_PARM(iobase
, "i");
1868 MODULE_PARM(iobase1
, "i");
1869 MODULE_PARM(iobase2
, "i");
1870 MODULE_PARM(iobase3
, "i");
1873 * You can setup up to 4 boards (current value of RC_NBOARD)
1874 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter.
1877 int init_module(void)
1881 if (iobase
|| iobase1
|| iobase2
|| iobase3
) {
1882 for(i
= 0; i
< RC_NBOARD
; i
++)
1883 rc_board
[0].base
= 0;
1887 rc_board
[0].base
= iobase
;
1889 rc_board
[1].base
= iobase1
;
1891 rc_board
[2].base
= iobase2
;
1893 rc_board
[3].base
= iobase3
;
1895 return riscom8_init();
1898 void cleanup_module(void)
1902 rc_release_drivers();
1903 for (i
= 0; i
< RC_NBOARD
; i
++)
1904 if (rc_board
[i
].flags
& RC_BOARD_PRESENT
)
1905 rc_release_io_range(&rc_board
[i
]);