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 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 27-Jun-2001
31 * - get rid of check_region and several cleanups
34 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/sched.h>
39 #include <linux/ioport.h>
40 #include <linux/interrupt.h>
41 #include <linux/errno.h>
42 #include <linux/tty.h>
44 #include <linux/serial.h>
45 #include <linux/fcntl.h>
46 #include <linux/major.h>
47 #include <linux/init.h>
48 #include <linux/delay.h>
49 #include <linux/tty_flip.h>
51 #include <asm/uaccess.h>
54 #include "riscom8_reg.h"
56 /* Am I paranoid or not ? ;-) */
57 #define RISCOM_PARANOIA_CHECK
60 * Crazy InteliCom/8 boards sometimes has swapped CTS & DSR signals.
61 * You can slightly speed up things by #undefing the following option,
62 * if you are REALLY sure that your board is correct one.
65 #define RISCOM_BRAIN_DAMAGED_CTS
68 * The following defines are mostly for testing purposes. But if you need
69 * some nice reporting in your syslog, you can define them also.
72 #undef RC_REPORT_OVERRUN
75 #define RISCOM_LEGAL_FLAGS \
76 (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \
77 ASYNC_SPD_HI | ASYNC_SPEED_VHI | ASYNC_SESSION_LOCKOUT | \
78 ASYNC_PGRP_LOCKOUT | ASYNC_CALLOUT_NOHUP)
80 #define RS_EVENT_WRITE_WAKEUP 0
82 static struct tty_driver
*riscom_driver
;
84 static struct riscom_board rc_board
[RC_NBOARD
] = {
99 static struct riscom_port rc_port
[RC_NBOARD
* RC_NPORT
];
101 /* RISCom/8 I/O ports addresses (without address translation) */
102 static unsigned short rc_ioport
[] = {
104 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c,
106 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10,
107 0x11, 0x12, 0x18, 0x28, 0x31, 0x32, 0x39, 0x3a, 0x40, 0x41, 0x61, 0x62,
108 0x63, 0x64, 0x6b, 0x70, 0x71, 0x78, 0x7a, 0x7b, 0x7f, 0x100, 0x101
111 #define RC_NIOPORT ARRAY_SIZE(rc_ioport)
114 static inline int rc_paranoia_check(struct riscom_port
const * port
,
115 char *name
, const char *routine
)
117 #ifdef RISCOM_PARANOIA_CHECK
118 static const char badmagic
[] = KERN_INFO
119 "rc: Warning: bad riscom port magic number for device %s in %s\n";
120 static const char badinfo
[] = KERN_INFO
121 "rc: Warning: null riscom port for device %s in %s\n";
124 printk(badinfo
, name
, routine
);
127 if (port
->magic
!= RISCOM8_MAGIC
) {
128 printk(badmagic
, name
, routine
);
137 * Service functions for RISCom/8 driver.
141 /* Get board number from pointer */
142 static inline int board_No (struct riscom_board
const * bp
)
144 return bp
- rc_board
;
147 /* Get port number from pointer */
148 static inline int port_No (struct riscom_port
const * port
)
150 return RC_PORT(port
- rc_port
);
153 /* Get pointer to board from pointer to port */
154 static inline struct riscom_board
* port_Board(struct riscom_port
const * port
)
156 return &rc_board
[RC_BOARD(port
- rc_port
)];
159 /* Input Byte from CL CD180 register */
160 static inline unsigned char rc_in(struct riscom_board
const * bp
, unsigned short reg
)
162 return inb(bp
->base
+ RC_TO_ISA(reg
));
165 /* Output Byte to CL CD180 register */
166 static inline void rc_out(struct riscom_board
const * bp
, unsigned short reg
,
169 outb(val
, bp
->base
+ RC_TO_ISA(reg
));
172 /* Wait for Channel Command Register ready */
173 static inline void rc_wait_CCR(struct riscom_board
const * bp
)
177 /* FIXME: need something more descriptive then 100000 :) */
178 for (delay
= 100000; delay
; delay
--)
179 if (!rc_in(bp
, CD180_CCR
))
182 printk(KERN_INFO
"rc%d: Timeout waiting for CCR.\n", board_No(bp
));
186 * RISCom/8 probe functions.
189 static inline int rc_request_io_range(struct riscom_board
* const bp
)
193 for (i
= 0; i
< RC_NIOPORT
; i
++)
194 if (!request_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1,
200 printk(KERN_INFO
"rc%d: Skipping probe at 0x%03x. IO address in use.\n",
201 board_No(bp
), bp
->base
);
203 release_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1);
207 static inline void rc_release_io_range(struct riscom_board
* const bp
)
211 for (i
= 0; i
< RC_NIOPORT
; i
++)
212 release_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1);
215 /* Reset and setup CD180 chip */
216 static void __init
rc_init_CD180(struct riscom_board
const * bp
)
220 save_flags(flags
); cli();
221 rc_out(bp
, RC_CTOUT
, 0); /* Clear timeout */
222 rc_wait_CCR(bp
); /* Wait for CCR ready */
223 rc_out(bp
, CD180_CCR
, CCR_HARDRESET
); /* Reset CD180 chip */
225 msleep(50); /* Delay 0.05 sec */
227 rc_out(bp
, CD180_GIVR
, RC_ID
); /* Set ID for this chip */
228 rc_out(bp
, CD180_GICR
, 0); /* Clear all bits */
229 rc_out(bp
, CD180_PILR1
, RC_ACK_MINT
); /* Prio for modem intr */
230 rc_out(bp
, CD180_PILR2
, RC_ACK_TINT
); /* Prio for transmitter intr */
231 rc_out(bp
, CD180_PILR3
, RC_ACK_RINT
); /* Prio for receiver intr */
233 /* Setting up prescaler. We need 4 ticks per 1 ms */
234 rc_out(bp
, CD180_PPRH
, (RC_OSCFREQ
/(1000000/RISCOM_TPS
)) >> 8);
235 rc_out(bp
, CD180_PPRL
, (RC_OSCFREQ
/(1000000/RISCOM_TPS
)) & 0xff);
237 restore_flags(flags
);
240 /* Main probing routine, also sets irq. */
241 static int __init
rc_probe(struct riscom_board
*bp
)
243 unsigned char val1
, val2
;
249 if (rc_request_io_range(bp
))
252 /* Are the I/O ports here ? */
253 rc_out(bp
, CD180_PPRL
, 0x5a);
255 val1
= rc_in(bp
, CD180_PPRL
);
256 rc_out(bp
, CD180_PPRL
, 0xa5);
258 val2
= rc_in(bp
, CD180_PPRL
);
260 if ((val1
!= 0x5a) || (val2
!= 0xa5)) {
261 printk(KERN_ERR
"rc%d: RISCom/8 Board at 0x%03x not found.\n",
262 board_No(bp
), bp
->base
);
266 /* It's time to find IRQ for this board */
267 for (retries
= 0; retries
< 5 && irqs
<= 0; retries
++) {
268 irqs
= probe_irq_on();
269 rc_init_CD180(bp
); /* Reset CD180 chip */
270 rc_out(bp
, CD180_CAR
, 2); /* Select port 2 */
272 rc_out(bp
, CD180_CCR
, CCR_TXEN
); /* Enable transmitter */
273 rc_out(bp
, CD180_IER
, IER_TXRDY
); /* Enable tx empty intr */
275 irqs
= probe_irq_off(irqs
);
276 val1
= rc_in(bp
, RC_BSR
); /* Get Board Status reg */
277 val2
= rc_in(bp
, RC_ACK_TINT
); /* ACK interrupt */
278 rc_init_CD180(bp
); /* Reset CD180 again */
280 if ((val1
& RC_BSR_TINT
) || (val2
!= (RC_ID
| GIVR_IT_TX
))) {
281 printk(KERN_ERR
"rc%d: RISCom/8 Board at 0x%03x not "
282 "found.\n", board_No(bp
), bp
->base
);
288 printk(KERN_ERR
"rc%d: Can't find IRQ for RISCom/8 board "
289 "at 0x%03x.\n", board_No(bp
), bp
->base
);
293 bp
->flags
|= RC_BOARD_PRESENT
;
295 printk(KERN_INFO
"rc%d: RISCom/8 Rev. %c board detected at "
298 (rc_in(bp
, CD180_GFRCR
) & 0x0f) + 'A', /* Board revision */
303 rc_release_io_range(bp
);
309 * Interrupt processing routines.
313 static inline void rc_mark_event(struct riscom_port
* port
, int event
)
315 set_bit(event
, &port
->event
);
316 schedule_work(&port
->tqueue
);
319 static inline struct riscom_port
* rc_get_port(struct riscom_board
const * bp
,
320 unsigned char const * what
)
322 unsigned char channel
;
323 struct riscom_port
* port
;
325 channel
= rc_in(bp
, CD180_GICR
) >> GICR_CHAN_OFF
;
326 if (channel
< CD180_NCH
) {
327 port
= &rc_port
[board_No(bp
) * RC_NPORT
+ channel
];
328 if (port
->flags
& ASYNC_INITIALIZED
) {
332 printk(KERN_ERR
"rc%d: %s interrupt from invalid port %d\n",
333 board_No(bp
), what
, channel
);
337 static inline void rc_receive_exc(struct riscom_board
const * bp
)
339 struct riscom_port
*port
;
340 struct tty_struct
*tty
;
341 unsigned char status
;
342 unsigned char ch
, flag
;
344 if (!(port
= rc_get_port(bp
, "Receive")))
349 #ifdef RC_REPORT_OVERRUN
350 status
= rc_in(bp
, CD180_RCSR
);
351 if (status
& RCSR_OE
)
353 status
&= port
->mark_mask
;
355 status
= rc_in(bp
, CD180_RCSR
) & port
->mark_mask
;
357 ch
= rc_in(bp
, CD180_RDR
);
361 if (status
& RCSR_TOUT
) {
362 printk(KERN_WARNING
"rc%d: port %d: Receiver timeout. "
363 "Hardware problems ?\n",
364 board_No(bp
), port_No(port
));
367 } else if (status
& RCSR_BREAK
) {
368 printk(KERN_INFO
"rc%d: port %d: Handling break...\n",
369 board_No(bp
), port_No(port
));
371 if (port
->flags
& ASYNC_SAK
)
374 } else if (status
& RCSR_PE
)
377 else if (status
& RCSR_FE
)
380 else if (status
& RCSR_OE
)
386 tty_insert_flip_char(tty
, ch
, flag
);
387 tty_flip_buffer_push(tty
);
390 static inline void rc_receive(struct riscom_board
const * bp
)
392 struct riscom_port
*port
;
393 struct tty_struct
*tty
;
396 if (!(port
= rc_get_port(bp
, "Receive")))
401 count
= rc_in(bp
, CD180_RDCR
);
403 #ifdef RC_REPORT_FIFO
404 port
->hits
[count
> 8 ? 9 : count
]++;
408 if (tty_buffer_request_room(tty
, 1) == 0) {
409 printk(KERN_WARNING
"rc%d: port %d: Working around "
410 "flip buffer overflow.\n",
411 board_No(bp
), port_No(port
));
414 tty_insert_flip_char(tty
, rc_in(bp
, CD180_RDR
), TTY_NORMAL
);
416 tty_flip_buffer_push(tty
);
419 static inline void rc_transmit(struct riscom_board
const * bp
)
421 struct riscom_port
*port
;
422 struct tty_struct
*tty
;
426 if (!(port
= rc_get_port(bp
, "Transmit")))
431 if (port
->IER
& IER_TXEMPTY
) {
433 rc_out(bp
, CD180_CAR
, port_No(port
));
434 port
->IER
&= ~IER_TXEMPTY
;
435 rc_out(bp
, CD180_IER
, port
->IER
);
439 if ((port
->xmit_cnt
<= 0 && !port
->break_length
)
440 || tty
->stopped
|| tty
->hw_stopped
) {
441 rc_out(bp
, CD180_CAR
, port_No(port
));
442 port
->IER
&= ~IER_TXRDY
;
443 rc_out(bp
, CD180_IER
, port
->IER
);
447 if (port
->break_length
) {
448 if (port
->break_length
> 0) {
449 if (port
->COR2
& COR2_ETC
) {
450 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
451 rc_out(bp
, CD180_TDR
, CD180_C_SBRK
);
452 port
->COR2
&= ~COR2_ETC
;
454 count
= min_t(int, port
->break_length
, 0xff);
455 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
456 rc_out(bp
, CD180_TDR
, CD180_C_DELAY
);
457 rc_out(bp
, CD180_TDR
, count
);
458 if (!(port
->break_length
-= count
))
459 port
->break_length
--;
461 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
462 rc_out(bp
, CD180_TDR
, CD180_C_EBRK
);
463 rc_out(bp
, CD180_COR2
, port
->COR2
);
465 rc_out(bp
, CD180_CCR
, CCR_CORCHG2
);
466 port
->break_length
= 0;
473 rc_out(bp
, CD180_TDR
, port
->xmit_buf
[port
->xmit_tail
++]);
474 port
->xmit_tail
= port
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
475 if (--port
->xmit_cnt
<= 0)
477 } while (--count
> 0);
479 if (port
->xmit_cnt
<= 0) {
480 rc_out(bp
, CD180_CAR
, port_No(port
));
481 port
->IER
&= ~IER_TXRDY
;
482 rc_out(bp
, CD180_IER
, port
->IER
);
484 if (port
->xmit_cnt
<= port
->wakeup_chars
)
485 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
488 static inline void rc_check_modem(struct riscom_board
const * bp
)
490 struct riscom_port
*port
;
491 struct tty_struct
*tty
;
494 if (!(port
= rc_get_port(bp
, "Modem")))
499 mcr
= rc_in(bp
, CD180_MCR
);
500 if (mcr
& MCR_CDCHG
) {
501 if (rc_in(bp
, CD180_MSVR
) & MSVR_CD
)
502 wake_up_interruptible(&port
->open_wait
);
504 schedule_work(&port
->tqueue_hangup
);
507 #ifdef RISCOM_BRAIN_DAMAGED_CTS
508 if (mcr
& MCR_CTSCHG
) {
509 if (rc_in(bp
, CD180_MSVR
) & MSVR_CTS
) {
511 port
->IER
|= IER_TXRDY
;
512 if (port
->xmit_cnt
<= port
->wakeup_chars
)
513 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
516 port
->IER
&= ~IER_TXRDY
;
518 rc_out(bp
, CD180_IER
, port
->IER
);
520 if (mcr
& MCR_DSRCHG
) {
521 if (rc_in(bp
, CD180_MSVR
) & MSVR_DSR
) {
523 port
->IER
|= IER_TXRDY
;
524 if (port
->xmit_cnt
<= port
->wakeup_chars
)
525 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
528 port
->IER
&= ~IER_TXRDY
;
530 rc_out(bp
, CD180_IER
, port
->IER
);
532 #endif /* RISCOM_BRAIN_DAMAGED_CTS */
534 /* Clear change bits */
535 rc_out(bp
, CD180_MCR
, 0);
538 /* The main interrupt processing routine */
539 static irqreturn_t
rc_interrupt(int dummy
, void * dev_id
)
541 unsigned char status
;
543 struct riscom_board
*bp
= dev_id
;
544 unsigned long loop
= 0;
547 if (!(bp
->flags
& RC_BOARD_ACTIVE
))
550 while ((++loop
< 16) && ((status
= ~(rc_in(bp
, RC_BSR
))) &
551 (RC_BSR_TOUT
| RC_BSR_TINT
|
552 RC_BSR_MINT
| RC_BSR_RINT
))) {
554 if (status
& RC_BSR_TOUT
)
555 printk(KERN_WARNING
"rc%d: Got timeout. Hardware "
556 "error?\n", board_No(bp
));
558 else if (status
& RC_BSR_RINT
) {
559 ack
= rc_in(bp
, RC_ACK_RINT
);
561 if (ack
== (RC_ID
| GIVR_IT_RCV
))
563 else if (ack
== (RC_ID
| GIVR_IT_REXC
))
566 printk(KERN_WARNING
"rc%d: Bad receive ack "
570 } else if (status
& RC_BSR_TINT
) {
571 ack
= rc_in(bp
, RC_ACK_TINT
);
573 if (ack
== (RC_ID
| GIVR_IT_TX
))
576 printk(KERN_WARNING
"rc%d: Bad transmit ack "
580 } else /* if (status & RC_BSR_MINT) */ {
581 ack
= rc_in(bp
, RC_ACK_MINT
);
583 if (ack
== (RC_ID
| GIVR_IT_MODEM
))
586 printk(KERN_WARNING
"rc%d: Bad modem ack "
592 rc_out(bp
, CD180_EOIR
, 0); /* Mark end of interrupt */
593 rc_out(bp
, RC_CTOUT
, 0); /* Clear timeout flag */
595 return IRQ_RETVAL(handled
);
599 * Routines for open & close processing.
602 /* Called with disabled interrupts */
603 static int rc_setup_board(struct riscom_board
* bp
)
607 if (bp
->flags
& RC_BOARD_ACTIVE
)
610 error
= request_irq(bp
->irq
, rc_interrupt
, IRQF_DISABLED
,
615 rc_out(bp
, RC_CTOUT
, 0); /* Just in case */
617 rc_out(bp
, RC_DTR
, bp
->DTR
); /* Drop DTR on all ports */
619 bp
->flags
|= RC_BOARD_ACTIVE
;
624 /* Called with disabled interrupts */
625 static void rc_shutdown_board(struct riscom_board
*bp
)
627 if (!(bp
->flags
& RC_BOARD_ACTIVE
))
630 bp
->flags
&= ~RC_BOARD_ACTIVE
;
632 free_irq(bp
->irq
, NULL
);
635 rc_out(bp
, RC_DTR
, bp
->DTR
); /* Drop DTR on all ports */
640 * Setting up port characteristics.
641 * Must be called with disabled interrupts
643 static void rc_change_speed(struct riscom_board
*bp
, struct riscom_port
*port
)
645 struct tty_struct
*tty
;
648 unsigned char cor1
= 0, cor3
= 0;
649 unsigned char mcor1
= 0, mcor2
= 0;
651 if (!(tty
= port
->tty
) || !tty
->termios
)
656 port
->MSVR
= MSVR_RTS
;
658 baud
= tty_get_baud_rate(tty
);
660 /* Select port on the board */
661 rc_out(bp
, CD180_CAR
, port_No(port
));
664 /* Drop DTR & exit */
665 bp
->DTR
|= (1u << port_No(port
));
666 rc_out(bp
, RC_DTR
, bp
->DTR
);
670 bp
->DTR
&= ~(1u << port_No(port
));
671 rc_out(bp
, RC_DTR
, bp
->DTR
);
675 * Now we must calculate some speed depended things
678 /* Set baud rate for port */
679 tmp
= (((RC_OSCFREQ
+ baud
/2) / baud
+
680 CD180_TPC
/2) / CD180_TPC
);
682 rc_out(bp
, CD180_RBPRH
, (tmp
>> 8) & 0xff);
683 rc_out(bp
, CD180_TBPRH
, (tmp
>> 8) & 0xff);
684 rc_out(bp
, CD180_RBPRL
, tmp
& 0xff);
685 rc_out(bp
, CD180_TBPRL
, tmp
& 0xff);
687 baud
= (baud
+ 5) / 10; /* Estimated CPS */
689 /* Two timer ticks seems enough to wakeup something like SLIP driver */
690 tmp
= ((baud
+ HZ
/2) / HZ
) * 2 - CD180_NFIFO
;
691 port
->wakeup_chars
= (tmp
< 0) ? 0 : ((tmp
>= SERIAL_XMIT_SIZE
) ?
692 SERIAL_XMIT_SIZE
- 1 : tmp
);
694 /* Receiver timeout will be transmission time for 1.5 chars */
695 tmp
= (RISCOM_TPS
+ RISCOM_TPS
/2 + baud
/2) / baud
;
696 tmp
= (tmp
> 0xff) ? 0xff : tmp
;
697 rc_out(bp
, CD180_RTPR
, tmp
);
699 switch (C_CSIZE(tty
)) {
719 cor1
|= COR1_NORMPAR
;
723 cor1
&= ~COR1_IGNORE
;
725 /* Set marking of some errors */
726 port
->mark_mask
= RCSR_OE
| RCSR_TOUT
;
728 port
->mark_mask
|= RCSR_FE
| RCSR_PE
;
729 if (I_BRKINT(tty
) || I_PARMRK(tty
))
730 port
->mark_mask
|= RCSR_BREAK
;
732 port
->mark_mask
&= ~(RCSR_FE
| RCSR_PE
);
734 port
->mark_mask
&= ~RCSR_BREAK
;
736 /* Real raw mode. Ignore all */
737 port
->mark_mask
&= ~RCSR_OE
;
739 /* Enable Hardware Flow Control */
740 if (C_CRTSCTS(tty
)) {
741 #ifdef RISCOM_BRAIN_DAMAGED_CTS
742 port
->IER
|= IER_DSR
| IER_CTS
;
743 mcor1
|= MCOR1_DSRZD
| MCOR1_CTSZD
;
744 mcor2
|= MCOR2_DSROD
| MCOR2_CTSOD
;
745 tty
->hw_stopped
= !(rc_in(bp
, CD180_MSVR
) & (MSVR_CTS
|MSVR_DSR
));
747 port
->COR2
|= COR2_CTSAE
;
750 /* Enable Software Flow Control. FIXME: I'm not sure about this */
751 /* Some people reported that it works, but I still doubt */
753 port
->COR2
|= COR2_TXIBE
;
754 cor3
|= (COR3_FCT
| COR3_SCDE
);
756 port
->COR2
|= COR2_IXM
;
757 rc_out(bp
, CD180_SCHR1
, START_CHAR(tty
));
758 rc_out(bp
, CD180_SCHR2
, STOP_CHAR(tty
));
759 rc_out(bp
, CD180_SCHR3
, START_CHAR(tty
));
760 rc_out(bp
, CD180_SCHR4
, STOP_CHAR(tty
));
762 if (!C_CLOCAL(tty
)) {
763 /* Enable CD check */
770 /* Enable receiver */
771 port
->IER
|= IER_RXD
;
773 /* Set input FIFO size (1-8 bytes) */
774 cor3
|= RISCOM_RXFIFO
;
775 /* Setting up CD180 channel registers */
776 rc_out(bp
, CD180_COR1
, cor1
);
777 rc_out(bp
, CD180_COR2
, port
->COR2
);
778 rc_out(bp
, CD180_COR3
, cor3
);
779 /* Make CD180 know about registers change */
781 rc_out(bp
, CD180_CCR
, CCR_CORCHG1
| CCR_CORCHG2
| CCR_CORCHG3
);
782 /* Setting up modem option registers */
783 rc_out(bp
, CD180_MCOR1
, mcor1
);
784 rc_out(bp
, CD180_MCOR2
, mcor2
);
785 /* Enable CD180 transmitter & receiver */
787 rc_out(bp
, CD180_CCR
, CCR_TXEN
| CCR_RXEN
);
788 /* Enable interrupts */
789 rc_out(bp
, CD180_IER
, port
->IER
);
790 /* And finally set RTS on */
791 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
794 /* Must be called with interrupts enabled */
795 static int rc_setup_port(struct riscom_board
*bp
, struct riscom_port
*port
)
799 if (port
->flags
& ASYNC_INITIALIZED
)
802 if (!port
->xmit_buf
) {
803 /* We may sleep in get_zeroed_page() */
806 if (!(tmp
= get_zeroed_page(GFP_KERNEL
)))
809 if (port
->xmit_buf
) {
813 port
->xmit_buf
= (unsigned char *) tmp
;
816 save_flags(flags
); cli();
819 clear_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
821 if (port
->count
== 1)
824 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
825 rc_change_speed(bp
, port
);
826 port
->flags
|= ASYNC_INITIALIZED
;
828 restore_flags(flags
);
832 /* Must be called with interrupts disabled */
833 static void rc_shutdown_port(struct riscom_board
*bp
, struct riscom_port
*port
)
835 struct tty_struct
*tty
;
837 if (!(port
->flags
& ASYNC_INITIALIZED
))
840 #ifdef RC_REPORT_OVERRUN
841 printk(KERN_INFO
"rc%d: port %d: Total %ld overruns were detected.\n",
842 board_No(bp
), port_No(port
), port
->overrun
);
844 #ifdef RC_REPORT_FIFO
848 printk(KERN_INFO
"rc%d: port %d: FIFO hits [ ",
849 board_No(bp
), port_No(port
));
850 for (i
= 0; i
< 10; i
++) {
851 printk("%ld ", port
->hits
[i
]);
856 if (port
->xmit_buf
) {
857 free_page((unsigned long) port
->xmit_buf
);
858 port
->xmit_buf
= NULL
;
861 if (!(tty
= port
->tty
) || C_HUPCL(tty
)) {
863 bp
->DTR
|= (1u << port_No(port
));
864 rc_out(bp
, RC_DTR
, bp
->DTR
);
868 rc_out(bp
, CD180_CAR
, port_No(port
));
871 rc_out(bp
, CD180_CCR
, CCR_SOFTRESET
);
872 /* Disable all interrupts from this port */
874 rc_out(bp
, CD180_IER
, port
->IER
);
877 set_bit(TTY_IO_ERROR
, &tty
->flags
);
878 port
->flags
&= ~ASYNC_INITIALIZED
;
880 if (--bp
->count
< 0) {
881 printk(KERN_INFO
"rc%d: rc_shutdown_port: "
882 "bad board count: %d\n",
883 board_No(bp
), bp
->count
);
888 * If this is the last opened port on the board
889 * shutdown whole board
892 rc_shutdown_board(bp
);
896 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
897 struct riscom_port
*port
)
899 DECLARE_WAITQUEUE(wait
, current
);
900 struct riscom_board
*bp
= port_Board(port
);
906 * If the device is in the middle of being closed, then block
907 * until it's done, and then try again.
909 if (tty_hung_up_p(filp
) || port
->flags
& ASYNC_CLOSING
) {
910 interruptible_sleep_on(&port
->close_wait
);
911 if (port
->flags
& ASYNC_HUP_NOTIFY
)
918 * If non-blocking mode is set, or the port is not enabled,
919 * then make the check up front and then exit.
921 if ((filp
->f_flags
& O_NONBLOCK
) ||
922 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
923 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
931 * Block waiting for the carrier detect and the line to become
932 * free (i.e., not in use by the callout). While we are in
933 * this loop, info->count is dropped by one, so that
934 * rs_close() knows when to free things. We restore it upon
935 * exit, either normal or abnormal.
938 add_wait_queue(&port
->open_wait
, &wait
);
940 if (!tty_hung_up_p(filp
))
943 port
->blocked_open
++;
946 rc_out(bp
, CD180_CAR
, port_No(port
));
947 CD
= rc_in(bp
, CD180_MSVR
) & MSVR_CD
;
948 rc_out(bp
, CD180_MSVR
, MSVR_RTS
);
949 bp
->DTR
&= ~(1u << port_No(port
));
950 rc_out(bp
, RC_DTR
, bp
->DTR
);
952 set_current_state(TASK_INTERRUPTIBLE
);
953 if (tty_hung_up_p(filp
) ||
954 !(port
->flags
& ASYNC_INITIALIZED
)) {
955 if (port
->flags
& ASYNC_HUP_NOTIFY
)
958 retval
= -ERESTARTSYS
;
961 if (!(port
->flags
& ASYNC_CLOSING
) &&
964 if (signal_pending(current
)) {
965 retval
= -ERESTARTSYS
;
970 __set_current_state(TASK_RUNNING
);
971 remove_wait_queue(&port
->open_wait
, &wait
);
972 if (!tty_hung_up_p(filp
))
974 port
->blocked_open
--;
978 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
982 static int rc_open(struct tty_struct
* tty
, struct file
* filp
)
986 struct riscom_port
* port
;
987 struct riscom_board
* bp
;
989 board
= RC_BOARD(tty
->index
);
990 if (board
>= RC_NBOARD
|| !(rc_board
[board
].flags
& RC_BOARD_PRESENT
))
993 bp
= &rc_board
[board
];
994 port
= rc_port
+ board
* RC_NPORT
+ RC_PORT(tty
->index
);
995 if (rc_paranoia_check(port
, tty
->name
, "rc_open"))
998 if ((error
= rc_setup_board(bp
)))
1002 tty
->driver_data
= port
;
1005 if ((error
= rc_setup_port(bp
, port
)))
1008 if ((error
= block_til_ready(tty
, filp
, port
)))
1014 static void rc_close(struct tty_struct
* tty
, struct file
* filp
)
1016 struct riscom_port
*port
= (struct riscom_port
*) tty
->driver_data
;
1017 struct riscom_board
*bp
;
1018 unsigned long flags
;
1019 unsigned long timeout
;
1021 if (!port
|| rc_paranoia_check(port
, tty
->name
, "close"))
1024 save_flags(flags
); cli();
1025 if (tty_hung_up_p(filp
))
1028 bp
= port_Board(port
);
1029 if ((tty
->count
== 1) && (port
->count
!= 1)) {
1030 printk(KERN_INFO
"rc%d: rc_close: bad port count;"
1031 " tty->count is 1, port count is %d\n",
1032 board_No(bp
), port
->count
);
1035 if (--port
->count
< 0) {
1036 printk(KERN_INFO
"rc%d: rc_close: bad port count "
1038 board_No(bp
), port_No(port
), port
->count
);
1043 port
->flags
|= ASYNC_CLOSING
;
1045 * Now we wait for the transmit buffer to clear; and we notify
1046 * the line discipline to only process XON/XOFF characters.
1049 if (port
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1050 tty_wait_until_sent(tty
, port
->closing_wait
);
1052 * At this point we stop accepting input. To do this, we
1053 * disable the receive line status interrupts, and tell the
1054 * interrupt driver to stop checking the data ready bit in the
1055 * line status register.
1057 port
->IER
&= ~IER_RXD
;
1058 if (port
->flags
& ASYNC_INITIALIZED
) {
1059 port
->IER
&= ~IER_TXRDY
;
1060 port
->IER
|= IER_TXEMPTY
;
1061 rc_out(bp
, CD180_CAR
, port_No(port
));
1062 rc_out(bp
, CD180_IER
, port
->IER
);
1064 * Before we drop DTR, make sure the UART transmitter
1065 * has completely drained; this is especially
1066 * important if there is a transmit FIFO!
1068 timeout
= jiffies
+HZ
;
1069 while(port
->IER
& IER_TXEMPTY
) {
1070 msleep_interruptible(jiffies_to_msecs(port
->timeout
));
1071 if (time_after(jiffies
, timeout
))
1075 rc_shutdown_port(bp
, port
);
1076 if (tty
->driver
->flush_buffer
)
1077 tty
->driver
->flush_buffer(tty
);
1078 tty_ldisc_flush(tty
);
1083 if (port
->blocked_open
) {
1084 if (port
->close_delay
) {
1085 msleep_interruptible(jiffies_to_msecs(port
->close_delay
));
1087 wake_up_interruptible(&port
->open_wait
);
1089 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1090 wake_up_interruptible(&port
->close_wait
);
1091 out
: restore_flags(flags
);
1094 static int rc_write(struct tty_struct
* tty
,
1095 const unsigned char *buf
, int count
)
1097 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1098 struct riscom_board
*bp
;
1100 unsigned long flags
;
1102 if (rc_paranoia_check(port
, tty
->name
, "rc_write"))
1105 bp
= port_Board(port
);
1107 if (!tty
|| !port
->xmit_buf
)
1113 c
= min_t(int, count
, min(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1114 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1116 restore_flags(flags
);
1120 memcpy(port
->xmit_buf
+ port
->xmit_head
, buf
, c
);
1121 port
->xmit_head
= (port
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
1122 port
->xmit_cnt
+= c
;
1123 restore_flags(flags
);
1131 if (port
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
&&
1132 !(port
->IER
& IER_TXRDY
)) {
1133 port
->IER
|= IER_TXRDY
;
1134 rc_out(bp
, CD180_CAR
, port_No(port
));
1135 rc_out(bp
, CD180_IER
, port
->IER
);
1137 restore_flags(flags
);
1142 static void rc_put_char(struct tty_struct
* tty
, unsigned char ch
)
1144 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1145 unsigned long flags
;
1147 if (rc_paranoia_check(port
, tty
->name
, "rc_put_char"))
1150 if (!tty
|| !port
->xmit_buf
)
1153 save_flags(flags
); cli();
1155 if (port
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1)
1158 port
->xmit_buf
[port
->xmit_head
++] = ch
;
1159 port
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
1161 out
: restore_flags(flags
);
1164 static void rc_flush_chars(struct tty_struct
* tty
)
1166 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1167 unsigned long flags
;
1169 if (rc_paranoia_check(port
, tty
->name
, "rc_flush_chars"))
1172 if (port
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
1176 save_flags(flags
); cli();
1177 port
->IER
|= IER_TXRDY
;
1178 rc_out(port_Board(port
), CD180_CAR
, port_No(port
));
1179 rc_out(port_Board(port
), CD180_IER
, port
->IER
);
1180 restore_flags(flags
);
1183 static int rc_write_room(struct tty_struct
* tty
)
1185 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1188 if (rc_paranoia_check(port
, tty
->name
, "rc_write_room"))
1191 ret
= SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1;
1197 static int rc_chars_in_buffer(struct tty_struct
*tty
)
1199 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1201 if (rc_paranoia_check(port
, tty
->name
, "rc_chars_in_buffer"))
1204 return port
->xmit_cnt
;
1207 static void rc_flush_buffer(struct tty_struct
*tty
)
1209 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1210 unsigned long flags
;
1212 if (rc_paranoia_check(port
, tty
->name
, "rc_flush_buffer"))
1215 save_flags(flags
); cli();
1216 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
1217 restore_flags(flags
);
1222 static int rc_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1224 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1225 struct riscom_board
* bp
;
1226 unsigned char status
;
1227 unsigned int result
;
1228 unsigned long flags
;
1230 if (rc_paranoia_check(port
, tty
->name
, __FUNCTION__
))
1233 bp
= port_Board(port
);
1234 save_flags(flags
); cli();
1235 rc_out(bp
, CD180_CAR
, port_No(port
));
1236 status
= rc_in(bp
, CD180_MSVR
);
1237 result
= rc_in(bp
, RC_RI
) & (1u << port_No(port
)) ? 0 : TIOCM_RNG
;
1238 restore_flags(flags
);
1239 result
|= ((status
& MSVR_RTS
) ? TIOCM_RTS
: 0)
1240 | ((status
& MSVR_DTR
) ? TIOCM_DTR
: 0)
1241 | ((status
& MSVR_CD
) ? TIOCM_CAR
: 0)
1242 | ((status
& MSVR_DSR
) ? TIOCM_DSR
: 0)
1243 | ((status
& MSVR_CTS
) ? TIOCM_CTS
: 0);
1247 static int rc_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1248 unsigned int set
, unsigned int clear
)
1250 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1251 unsigned long flags
;
1252 struct riscom_board
*bp
;
1254 if (rc_paranoia_check(port
, tty
->name
, __FUNCTION__
))
1257 bp
= port_Board(port
);
1259 save_flags(flags
); cli();
1260 if (set
& TIOCM_RTS
)
1261 port
->MSVR
|= MSVR_RTS
;
1262 if (set
& TIOCM_DTR
)
1263 bp
->DTR
&= ~(1u << port_No(port
));
1265 if (clear
& TIOCM_RTS
)
1266 port
->MSVR
&= ~MSVR_RTS
;
1267 if (clear
& TIOCM_DTR
)
1268 bp
->DTR
|= (1u << port_No(port
));
1270 rc_out(bp
, CD180_CAR
, port_No(port
));
1271 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1272 rc_out(bp
, RC_DTR
, bp
->DTR
);
1273 restore_flags(flags
);
1277 static inline void rc_send_break(struct riscom_port
* port
, unsigned long length
)
1279 struct riscom_board
*bp
= port_Board(port
);
1280 unsigned long flags
;
1282 save_flags(flags
); cli();
1283 port
->break_length
= RISCOM_TPS
/ HZ
* length
;
1284 port
->COR2
|= COR2_ETC
;
1285 port
->IER
|= IER_TXRDY
;
1286 rc_out(bp
, CD180_CAR
, port_No(port
));
1287 rc_out(bp
, CD180_COR2
, port
->COR2
);
1288 rc_out(bp
, CD180_IER
, port
->IER
);
1290 rc_out(bp
, CD180_CCR
, CCR_CORCHG2
);
1292 restore_flags(flags
);
1295 static inline int rc_set_serial_info(struct riscom_port
* port
,
1296 struct serial_struct __user
* newinfo
)
1298 struct serial_struct tmp
;
1299 struct riscom_board
*bp
= port_Board(port
);
1301 unsigned long flags
;
1303 if (copy_from_user(&tmp
, newinfo
, sizeof(tmp
)))
1307 if ((tmp
.irq
!= bp
->irq
) ||
1308 (tmp
.port
!= bp
->base
) ||
1309 (tmp
.type
!= PORT_CIRRUS
) ||
1310 (tmp
.baud_base
!= (RC_OSCFREQ
+ CD180_TPC
/2) / CD180_TPC
) ||
1311 (tmp
.custom_divisor
!= 0) ||
1312 (tmp
.xmit_fifo_size
!= CD180_NFIFO
) ||
1313 (tmp
.flags
& ~RISCOM_LEGAL_FLAGS
))
1317 change_speed
= ((port
->flags
& ASYNC_SPD_MASK
) !=
1318 (tmp
.flags
& ASYNC_SPD_MASK
));
1320 if (!capable(CAP_SYS_ADMIN
)) {
1321 if ((tmp
.close_delay
!= port
->close_delay
) ||
1322 (tmp
.closing_wait
!= port
->closing_wait
) ||
1323 ((tmp
.flags
& ~ASYNC_USR_MASK
) !=
1324 (port
->flags
& ~ASYNC_USR_MASK
)))
1326 port
->flags
= ((port
->flags
& ~ASYNC_USR_MASK
) |
1327 (tmp
.flags
& ASYNC_USR_MASK
));
1329 port
->flags
= ((port
->flags
& ~ASYNC_FLAGS
) |
1330 (tmp
.flags
& ASYNC_FLAGS
));
1331 port
->close_delay
= tmp
.close_delay
;
1332 port
->closing_wait
= tmp
.closing_wait
;
1335 save_flags(flags
); cli();
1336 rc_change_speed(bp
, port
);
1337 restore_flags(flags
);
1342 static inline int rc_get_serial_info(struct riscom_port
* port
,
1343 struct serial_struct __user
*retinfo
)
1345 struct serial_struct tmp
;
1346 struct riscom_board
*bp
= port_Board(port
);
1348 memset(&tmp
, 0, sizeof(tmp
));
1349 tmp
.type
= PORT_CIRRUS
;
1350 tmp
.line
= port
- rc_port
;
1351 tmp
.port
= bp
->base
;
1353 tmp
.flags
= port
->flags
;
1354 tmp
.baud_base
= (RC_OSCFREQ
+ CD180_TPC
/2) / CD180_TPC
;
1355 tmp
.close_delay
= port
->close_delay
* HZ
/100;
1356 tmp
.closing_wait
= port
->closing_wait
* HZ
/100;
1357 tmp
.xmit_fifo_size
= CD180_NFIFO
;
1358 return copy_to_user(retinfo
, &tmp
, sizeof(tmp
)) ? -EFAULT
: 0;
1361 static int rc_ioctl(struct tty_struct
* tty
, struct file
* filp
,
1362 unsigned int cmd
, unsigned long arg
)
1365 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1366 void __user
*argp
= (void __user
*)arg
;
1369 if (rc_paranoia_check(port
, tty
->name
, "rc_ioctl"))
1373 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1374 retval
= tty_check_change(tty
);
1377 tty_wait_until_sent(tty
, 0);
1379 rc_send_break(port
, HZ
/4); /* 1/4 second */
1381 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1382 retval
= tty_check_change(tty
);
1385 tty_wait_until_sent(tty
, 0);
1386 rc_send_break(port
, arg
? arg
*(HZ
/10) : HZ
/4);
1389 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned __user
*)argp
);
1391 if (get_user(arg
,(unsigned __user
*) argp
))
1393 tty
->termios
->c_cflag
=
1394 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1395 (arg
? CLOCAL
: 0));
1398 return rc_get_serial_info(port
, argp
);
1400 return rc_set_serial_info(port
, argp
);
1402 return -ENOIOCTLCMD
;
1407 static void rc_throttle(struct tty_struct
* tty
)
1409 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1410 struct riscom_board
*bp
;
1411 unsigned long flags
;
1413 if (rc_paranoia_check(port
, tty
->name
, "rc_throttle"))
1416 bp
= port_Board(port
);
1418 save_flags(flags
); cli();
1419 port
->MSVR
&= ~MSVR_RTS
;
1420 rc_out(bp
, CD180_CAR
, port_No(port
));
1423 rc_out(bp
, CD180_CCR
, CCR_SSCH2
);
1426 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1427 restore_flags(flags
);
1430 static void rc_unthrottle(struct tty_struct
* tty
)
1432 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1433 struct riscom_board
*bp
;
1434 unsigned long flags
;
1436 if (rc_paranoia_check(port
, tty
->name
, "rc_unthrottle"))
1439 bp
= port_Board(port
);
1441 save_flags(flags
); cli();
1442 port
->MSVR
|= MSVR_RTS
;
1443 rc_out(bp
, CD180_CAR
, port_No(port
));
1446 rc_out(bp
, CD180_CCR
, CCR_SSCH1
);
1449 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1450 restore_flags(flags
);
1453 static void rc_stop(struct tty_struct
* tty
)
1455 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1456 struct riscom_board
*bp
;
1457 unsigned long flags
;
1459 if (rc_paranoia_check(port
, tty
->name
, "rc_stop"))
1462 bp
= port_Board(port
);
1464 save_flags(flags
); cli();
1465 port
->IER
&= ~IER_TXRDY
;
1466 rc_out(bp
, CD180_CAR
, port_No(port
));
1467 rc_out(bp
, CD180_IER
, port
->IER
);
1468 restore_flags(flags
);
1471 static void rc_start(struct tty_struct
* tty
)
1473 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1474 struct riscom_board
*bp
;
1475 unsigned long flags
;
1477 if (rc_paranoia_check(port
, tty
->name
, "rc_start"))
1480 bp
= port_Board(port
);
1482 save_flags(flags
); cli();
1483 if (port
->xmit_cnt
&& port
->xmit_buf
&& !(port
->IER
& IER_TXRDY
)) {
1484 port
->IER
|= IER_TXRDY
;
1485 rc_out(bp
, CD180_CAR
, port_No(port
));
1486 rc_out(bp
, CD180_IER
, port
->IER
);
1488 restore_flags(flags
);
1492 * This routine is called from the work queue when the interrupt
1493 * routine has signalled that a hangup has occurred. The path of
1494 * hangup processing is:
1496 * serial interrupt routine -> (workqueue) ->
1497 * do_rc_hangup() -> tty->hangup() -> rc_hangup()
1500 static void do_rc_hangup(struct work_struct
*ugly_api
)
1502 struct riscom_port
*port
= container_of(ugly_api
, struct riscom_port
, tqueue_hangup
);
1503 struct tty_struct
*tty
;
1507 tty_hangup(tty
); /* FIXME: module removal race still here */
1510 static void rc_hangup(struct tty_struct
* tty
)
1512 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1513 struct riscom_board
*bp
;
1515 if (rc_paranoia_check(port
, tty
->name
, "rc_hangup"))
1518 bp
= port_Board(port
);
1520 rc_shutdown_port(bp
, port
);
1523 port
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1525 wake_up_interruptible(&port
->open_wait
);
1528 static void rc_set_termios(struct tty_struct
* tty
, struct ktermios
* old_termios
)
1530 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1531 unsigned long flags
;
1533 if (rc_paranoia_check(port
, tty
->name
, "rc_set_termios"))
1536 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
&&
1537 tty
->termios
->c_iflag
== old_termios
->c_iflag
)
1540 save_flags(flags
); cli();
1541 rc_change_speed(port_Board(port
), port
);
1542 restore_flags(flags
);
1544 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1545 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1546 tty
->hw_stopped
= 0;
1551 static void do_softint(struct work_struct
*ugly_api
)
1553 struct riscom_port
*port
= container_of(ugly_api
, struct riscom_port
, tqueue
);
1554 struct tty_struct
*tty
;
1556 if(!(tty
= port
->tty
))
1559 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &port
->event
))
1563 static const struct tty_operations riscom_ops
= {
1567 .put_char
= rc_put_char
,
1568 .flush_chars
= rc_flush_chars
,
1569 .write_room
= rc_write_room
,
1570 .chars_in_buffer
= rc_chars_in_buffer
,
1571 .flush_buffer
= rc_flush_buffer
,
1573 .throttle
= rc_throttle
,
1574 .unthrottle
= rc_unthrottle
,
1575 .set_termios
= rc_set_termios
,
1578 .hangup
= rc_hangup
,
1579 .tiocmget
= rc_tiocmget
,
1580 .tiocmset
= rc_tiocmset
,
1583 static inline int rc_init_drivers(void)
1588 riscom_driver
= alloc_tty_driver(RC_NBOARD
* RC_NPORT
);
1592 riscom_driver
->owner
= THIS_MODULE
;
1593 riscom_driver
->name
= "ttyL";
1594 riscom_driver
->major
= RISCOM8_NORMAL_MAJOR
;
1595 riscom_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1596 riscom_driver
->subtype
= SERIAL_TYPE_NORMAL
;
1597 riscom_driver
->init_termios
= tty_std_termios
;
1598 riscom_driver
->init_termios
.c_cflag
=
1599 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1600 riscom_driver
->init_termios
.c_ispeed
= 9600;
1601 riscom_driver
->init_termios
.c_ospeed
= 9600;
1602 riscom_driver
->flags
= TTY_DRIVER_REAL_RAW
;
1603 tty_set_operations(riscom_driver
, &riscom_ops
);
1604 if ((error
= tty_register_driver(riscom_driver
))) {
1605 put_tty_driver(riscom_driver
);
1606 printk(KERN_ERR
"rc: Couldn't register RISCom/8 driver, "
1612 memset(rc_port
, 0, sizeof(rc_port
));
1613 for (i
= 0; i
< RC_NPORT
* RC_NBOARD
; i
++) {
1614 rc_port
[i
].magic
= RISCOM8_MAGIC
;
1615 INIT_WORK(&rc_port
[i
].tqueue
, do_softint
);
1616 INIT_WORK(&rc_port
[i
].tqueue_hangup
, do_rc_hangup
);
1617 rc_port
[i
].close_delay
= 50 * HZ
/100;
1618 rc_port
[i
].closing_wait
= 3000 * HZ
/100;
1619 init_waitqueue_head(&rc_port
[i
].open_wait
);
1620 init_waitqueue_head(&rc_port
[i
].close_wait
);
1626 static void rc_release_drivers(void)
1628 unsigned long flags
;
1632 tty_unregister_driver(riscom_driver
);
1633 put_tty_driver(riscom_driver
);
1634 restore_flags(flags
);
1639 * Called at boot time.
1641 * You can specify IO base for up to RC_NBOARD cards,
1642 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
1643 * Note that there will be no probing at default
1644 * addresses in this case.
1647 static int __init
riscom8_setup(char *str
)
1649 int ints
[RC_NBOARD
];
1652 str
= get_options(str
, ARRAY_SIZE(ints
), ints
);
1654 for (i
= 0; i
< RC_NBOARD
; i
++) {
1656 rc_board
[i
].base
= ints
[i
+1];
1658 rc_board
[i
].base
= 0;
1663 __setup("riscom8=", riscom8_setup
);
1666 static char banner
[] __initdata
=
1667 KERN_INFO
"rc: SDL RISCom/8 card driver v1.1, (c) D.Gorodchanin "
1669 static char no_boards_msg
[] __initdata
=
1670 KERN_INFO
"rc: No RISCom/8 boards detected.\n";
1673 * This routine must be called by kernel at boot time
1675 static int __init
riscom8_init(void)
1682 if (rc_init_drivers())
1685 for (i
= 0; i
< RC_NBOARD
; i
++)
1686 if (rc_board
[i
].base
&& !rc_probe(&rc_board
[i
]))
1690 rc_release_drivers();
1691 printk(no_boards_msg
);
1702 module_param(iobase
, int, 0);
1703 module_param(iobase1
, int, 0);
1704 module_param(iobase2
, int, 0);
1705 module_param(iobase3
, int, 0);
1707 MODULE_LICENSE("GPL");
1711 * You can setup up to 4 boards (current value of RC_NBOARD)
1712 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter.
1715 static int __init
riscom8_init_module (void)
1720 if (iobase
|| iobase1
|| iobase2
|| iobase3
) {
1721 for(i
= 0; i
< RC_NBOARD
; i
++)
1722 rc_board
[0].base
= 0;
1726 rc_board
[0].base
= iobase
;
1728 rc_board
[1].base
= iobase1
;
1730 rc_board
[2].base
= iobase2
;
1732 rc_board
[3].base
= iobase3
;
1735 return riscom8_init();
1738 static void __exit
riscom8_exit_module (void)
1742 rc_release_drivers();
1743 for (i
= 0; i
< RC_NBOARD
; i
++)
1744 if (rc_board
[i
].flags
& RC_BOARD_PRESENT
)
1745 rc_release_io_range(&rc_board
[i
]);
1749 module_init(riscom8_init_module
);
1750 module_exit(riscom8_exit_module
);