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 riscom_board * IRQ_to_board[16];
83 static struct tty_driver *riscom_driver;
84 static unsigned char * tmp_buf;
85 static DECLARE_MUTEX(tmp_buf_sem);
87 static unsigned long baud_table[] = {
88 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
89 9600, 19200, 38400, 57600, 76800, 0,
92 static struct riscom_board rc_board[RC_NBOARD] = {
107 static struct riscom_port rc_port[RC_NBOARD * RC_NPORT];
109 /* RISCom/8 I/O ports addresses (without address translation) */
110 static unsigned short rc_ioport[] = {
112 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c,
114 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10,
115 0x11, 0x12, 0x18, 0x28, 0x31, 0x32, 0x39, 0x3a, 0x40, 0x41, 0x61, 0x62,
116 0x63, 0x64, 0x6b, 0x70, 0x71, 0x78, 0x7a, 0x7b, 0x7f, 0x100, 0x101
119 #define RC_NIOPORT ARRAY_SIZE(rc_ioport)
122 static inline int rc_paranoia_check(struct riscom_port const * port,
123 char *name, const char *routine)
125 #ifdef RISCOM_PARANOIA_CHECK
126 static const char badmagic[] = KERN_INFO
127 "rc: Warning: bad riscom port magic number for device %s in %s\n";
128 static const char badinfo[] = KERN_INFO
129 "rc: Warning: null riscom port for device %s in %s\n";
132 printk(badinfo, name, routine);
135 if (port->magic != RISCOM8_MAGIC) {
136 printk(badmagic, name, routine);
145 * Service functions for RISCom/8 driver.
149 /* Get board number from pointer */
150 static inline int board_No (struct riscom_board const * bp)
152 return bp - rc_board;
155 /* Get port number from pointer */
156 static inline int port_No (struct riscom_port const * port)
158 return RC_PORT(port - rc_port);
161 /* Get pointer to board from pointer to port */
162 static inline struct riscom_board * port_Board(struct riscom_port const * port)
164 return &rc_board[RC_BOARD(port - rc_port)];
167 /* Input Byte from CL CD180 register */
168 static inline unsigned char rc_in(struct riscom_board const * bp, unsigned short reg)
170 return inb(bp->base + RC_TO_ISA(reg));
173 /* Output Byte to CL CD180 register */
174 static inline void rc_out(struct riscom_board const * bp, unsigned short reg,
177 outb(val, bp->base + RC_TO_ISA(reg));
180 /* Wait for Channel Command Register ready */
181 static inline void rc_wait_CCR(struct riscom_board const * bp)
185 /* FIXME: need something more descriptive then 100000 :) */
186 for (delay = 100000; delay; delay--)
187 if (!rc_in(bp, CD180_CCR))
190 printk(KERN_INFO "rc%d: Timeout waiting for CCR.\n", board_No(bp));
194 * RISCom/8 probe functions.
197 static inline int rc_request_io_range(struct riscom_board * const bp)
201 for (i = 0; i < RC_NIOPORT; i++)
202 if (!request_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1,
208 printk(KERN_INFO "rc%d: Skipping probe at 0x%03x. IO address in use.\n",
209 board_No(bp), bp->base);
211 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
215 static inline void rc_release_io_range(struct riscom_board * const bp)
219 for (i = 0; i < RC_NIOPORT; i++)
220 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
223 /* Must be called with enabled interrupts */
224 static inline void rc_long_delay(unsigned long delay)
228 for (i = jiffies + delay; time_after(i,jiffies); ) ;
231 /* Reset and setup CD180 chip */
232 static void __init rc_init_CD180(struct riscom_board const * bp)
236 save_flags(flags); cli();
237 rc_out(bp, RC_CTOUT, 0); /* Clear timeout */
238 rc_wait_CCR(bp); /* Wait for CCR ready */
239 rc_out(bp, CD180_CCR, CCR_HARDRESET); /* Reset CD180 chip */
241 rc_long_delay(HZ/20); /* Delay 0.05 sec */
243 rc_out(bp, CD180_GIVR, RC_ID); /* Set ID for this chip */
244 rc_out(bp, CD180_GICR, 0); /* Clear all bits */
245 rc_out(bp, CD180_PILR1, RC_ACK_MINT); /* Prio for modem intr */
246 rc_out(bp, CD180_PILR2, RC_ACK_TINT); /* Prio for transmitter intr */
247 rc_out(bp, CD180_PILR3, RC_ACK_RINT); /* Prio for receiver intr */
249 /* Setting up prescaler. We need 4 ticks per 1 ms */
250 rc_out(bp, CD180_PPRH, (RC_OSCFREQ/(1000000/RISCOM_TPS)) >> 8);
251 rc_out(bp, CD180_PPRL, (RC_OSCFREQ/(1000000/RISCOM_TPS)) & 0xff);
253 restore_flags(flags);
256 /* Main probing routine, also sets irq. */
257 static int __init rc_probe(struct riscom_board *bp)
259 unsigned char val1, val2;
265 if (rc_request_io_range(bp))
268 /* Are the I/O ports here ? */
269 rc_out(bp, CD180_PPRL, 0x5a);
271 val1 = rc_in(bp, CD180_PPRL);
272 rc_out(bp, CD180_PPRL, 0xa5);
274 val2 = rc_in(bp, CD180_PPRL);
276 if ((val1 != 0x5a) || (val2 != 0xa5)) {
277 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not found.\n",
278 board_No(bp), bp->base);
282 /* It's time to find IRQ for this board */
283 for (retries = 0; retries < 5 && irqs <= 0; retries++) {
284 irqs = probe_irq_on();
285 rc_init_CD180(bp); /* Reset CD180 chip */
286 rc_out(bp, CD180_CAR, 2); /* Select port 2 */
288 rc_out(bp, CD180_CCR, CCR_TXEN); /* Enable transmitter */
289 rc_out(bp, CD180_IER, IER_TXRDY); /* Enable tx empty intr */
290 rc_long_delay(HZ/20);
291 irqs = probe_irq_off(irqs);
292 val1 = rc_in(bp, RC_BSR); /* Get Board Status reg */
293 val2 = rc_in(bp, RC_ACK_TINT); /* ACK interrupt */
294 rc_init_CD180(bp); /* Reset CD180 again */
296 if ((val1 & RC_BSR_TINT) || (val2 != (RC_ID | GIVR_IT_TX))) {
297 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not "
298 "found.\n", board_No(bp), bp->base);
304 printk(KERN_ERR "rc%d: Can't find IRQ for RISCom/8 board "
305 "at 0x%03x.\n", board_No(bp), bp->base);
309 bp->flags |= RC_BOARD_PRESENT;
311 printk(KERN_INFO "rc%d: RISCom/8 Rev. %c board detected at "
314 (rc_in(bp, CD180_GFRCR) & 0x0f) + 'A', /* Board revision */
319 rc_release_io_range(bp);
325 * Interrupt processing routines.
329 static inline void rc_mark_event(struct riscom_port * port, int event)
331 set_bit(event, &port->event);
332 schedule_work(&port->tqueue);
335 static inline struct riscom_port * rc_get_port(struct riscom_board const * bp,
336 unsigned char const * what)
338 unsigned char channel;
339 struct riscom_port * port;
341 channel = rc_in(bp, CD180_GICR) >> GICR_CHAN_OFF;
342 if (channel < CD180_NCH) {
343 port = &rc_port[board_No(bp) * RC_NPORT + channel];
344 if (port->flags & ASYNC_INITIALIZED) {
348 printk(KERN_ERR "rc%d: %s interrupt from invalid port %d\n",
349 board_No(bp), what, channel);
353 static inline void rc_receive_exc(struct riscom_board const * bp)
355 struct riscom_port *port;
356 struct tty_struct *tty;
357 unsigned char status;
358 unsigned char ch, flag;
360 if (!(port = rc_get_port(bp, "Receive")))
365 #ifdef RC_REPORT_OVERRUN
366 status = rc_in(bp, CD180_RCSR);
367 if (status & RCSR_OE)
369 status &= port->mark_mask;
371 status = rc_in(bp, CD180_RCSR) & port->mark_mask;
373 ch = rc_in(bp, CD180_RDR);
377 if (status & RCSR_TOUT) {
378 printk(KERN_WARNING "rc%d: port %d: Receiver timeout. "
379 "Hardware problems ?\n",
380 board_No(bp), port_No(port));
383 } else if (status & RCSR_BREAK) {
384 printk(KERN_INFO "rc%d: port %d: Handling break...\n",
385 board_No(bp), port_No(port));
387 if (port->flags & ASYNC_SAK)
390 } else if (status & RCSR_PE)
393 else if (status & RCSR_FE)
396 else if (status & RCSR_OE)
402 tty_insert_flip_char(tty, ch, flag);
403 tty_flip_buffer_push(tty);
406 static inline void rc_receive(struct riscom_board const * bp)
408 struct riscom_port *port;
409 struct tty_struct *tty;
412 if (!(port = rc_get_port(bp, "Receive")))
417 count = rc_in(bp, CD180_RDCR);
419 #ifdef RC_REPORT_FIFO
420 port->hits[count > 8 ? 9 : count]++;
424 if (tty_buffer_request_room(tty, 1) == 0) {
425 printk(KERN_WARNING "rc%d: port %d: Working around "
426 "flip buffer overflow.\n",
427 board_No(bp), port_No(port));
430 tty_insert_flip_char(tty, rc_in(bp, CD180_RDR), TTY_NORMAL);
432 tty_flip_buffer_push(tty);
435 static inline void rc_transmit(struct riscom_board const * bp)
437 struct riscom_port *port;
438 struct tty_struct *tty;
442 if (!(port = rc_get_port(bp, "Transmit")))
447 if (port->IER & IER_TXEMPTY) {
449 rc_out(bp, CD180_CAR, port_No(port));
450 port->IER &= ~IER_TXEMPTY;
451 rc_out(bp, CD180_IER, port->IER);
455 if ((port->xmit_cnt <= 0 && !port->break_length)
456 || tty->stopped || tty->hw_stopped) {
457 rc_out(bp, CD180_CAR, port_No(port));
458 port->IER &= ~IER_TXRDY;
459 rc_out(bp, CD180_IER, port->IER);
463 if (port->break_length) {
464 if (port->break_length > 0) {
465 if (port->COR2 & COR2_ETC) {
466 rc_out(bp, CD180_TDR, CD180_C_ESC);
467 rc_out(bp, CD180_TDR, CD180_C_SBRK);
468 port->COR2 &= ~COR2_ETC;
470 count = min_t(int, port->break_length, 0xff);
471 rc_out(bp, CD180_TDR, CD180_C_ESC);
472 rc_out(bp, CD180_TDR, CD180_C_DELAY);
473 rc_out(bp, CD180_TDR, count);
474 if (!(port->break_length -= count))
475 port->break_length--;
477 rc_out(bp, CD180_TDR, CD180_C_ESC);
478 rc_out(bp, CD180_TDR, CD180_C_EBRK);
479 rc_out(bp, CD180_COR2, port->COR2);
481 rc_out(bp, CD180_CCR, CCR_CORCHG2);
482 port->break_length = 0;
489 rc_out(bp, CD180_TDR, port->xmit_buf[port->xmit_tail++]);
490 port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1);
491 if (--port->xmit_cnt <= 0)
493 } while (--count > 0);
495 if (port->xmit_cnt <= 0) {
496 rc_out(bp, CD180_CAR, port_No(port));
497 port->IER &= ~IER_TXRDY;
498 rc_out(bp, CD180_IER, port->IER);
500 if (port->xmit_cnt <= port->wakeup_chars)
501 rc_mark_event(port, RS_EVENT_WRITE_WAKEUP);
504 static inline void rc_check_modem(struct riscom_board const * bp)
506 struct riscom_port *port;
507 struct tty_struct *tty;
510 if (!(port = rc_get_port(bp, "Modem")))
515 mcr = rc_in(bp, CD180_MCR);
516 if (mcr & MCR_CDCHG) {
517 if (rc_in(bp, CD180_MSVR) & MSVR_CD)
518 wake_up_interruptible(&port->open_wait);
520 schedule_work(&port->tqueue_hangup);
523 #ifdef RISCOM_BRAIN_DAMAGED_CTS
524 if (mcr & MCR_CTSCHG) {
525 if (rc_in(bp, CD180_MSVR) & MSVR_CTS) {
527 port->IER |= IER_TXRDY;
528 if (port->xmit_cnt <= port->wakeup_chars)
529 rc_mark_event(port, RS_EVENT_WRITE_WAKEUP);
532 port->IER &= ~IER_TXRDY;
534 rc_out(bp, CD180_IER, port->IER);
536 if (mcr & MCR_DSRCHG) {
537 if (rc_in(bp, CD180_MSVR) & MSVR_DSR) {
539 port->IER |= IER_TXRDY;
540 if (port->xmit_cnt <= port->wakeup_chars)
541 rc_mark_event(port, RS_EVENT_WRITE_WAKEUP);
544 port->IER &= ~IER_TXRDY;
546 rc_out(bp, CD180_IER, port->IER);
548 #endif /* RISCOM_BRAIN_DAMAGED_CTS */
550 /* Clear change bits */
551 rc_out(bp, CD180_MCR, 0);
554 /* The main interrupt processing routine */
555 static irqreturn_t rc_interrupt(int irq, void * dev_id, struct pt_regs * regs)
557 unsigned char status;
559 struct riscom_board *bp;
560 unsigned long loop = 0;
563 bp = IRQ_to_board[irq];
565 if (!bp || !(bp->flags & RC_BOARD_ACTIVE)) {
569 while ((++loop < 16) && ((status = ~(rc_in(bp, RC_BSR))) &
570 (RC_BSR_TOUT | RC_BSR_TINT |
571 RC_BSR_MINT | RC_BSR_RINT))) {
573 if (status & RC_BSR_TOUT)
574 printk(KERN_WARNING "rc%d: Got timeout. Hardware "
575 "error?\n", board_No(bp));
577 else if (status & RC_BSR_RINT) {
578 ack = rc_in(bp, RC_ACK_RINT);
580 if (ack == (RC_ID | GIVR_IT_RCV))
582 else if (ack == (RC_ID | GIVR_IT_REXC))
585 printk(KERN_WARNING "rc%d: Bad receive ack "
589 } else if (status & RC_BSR_TINT) {
590 ack = rc_in(bp, RC_ACK_TINT);
592 if (ack == (RC_ID | GIVR_IT_TX))
595 printk(KERN_WARNING "rc%d: Bad transmit ack "
599 } else /* if (status & RC_BSR_MINT) */ {
600 ack = rc_in(bp, RC_ACK_MINT);
602 if (ack == (RC_ID | GIVR_IT_MODEM))
605 printk(KERN_WARNING "rc%d: Bad modem ack "
611 rc_out(bp, CD180_EOIR, 0); /* Mark end of interrupt */
612 rc_out(bp, RC_CTOUT, 0); /* Clear timeout flag */
614 return IRQ_RETVAL(handled);
618 * Routines for open & close processing.
621 /* Called with disabled interrupts */
622 static inline int rc_setup_board(struct riscom_board * bp)
626 if (bp->flags & RC_BOARD_ACTIVE)
629 error = request_irq(bp->irq, rc_interrupt, SA_INTERRUPT,
634 rc_out(bp, RC_CTOUT, 0); /* Just in case */
636 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */
638 IRQ_to_board[bp->irq] = bp;
639 bp->flags |= RC_BOARD_ACTIVE;
644 /* Called with disabled interrupts */
645 static inline void rc_shutdown_board(struct riscom_board *bp)
647 if (!(bp->flags & RC_BOARD_ACTIVE))
650 bp->flags &= ~RC_BOARD_ACTIVE;
652 free_irq(bp->irq, NULL);
653 IRQ_to_board[bp->irq] = NULL;
656 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */
661 * Setting up port characteristics.
662 * Must be called with disabled interrupts
664 static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
666 struct tty_struct *tty;
669 unsigned char cor1 = 0, cor3 = 0;
670 unsigned char mcor1 = 0, mcor2 = 0;
672 if (!(tty = port->tty) || !tty->termios)
677 port->MSVR = MSVR_RTS;
681 if (baud & CBAUDEX) {
683 if (baud < 1 || baud > 2)
684 port->tty->termios->c_cflag &= ~CBAUDEX;
689 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
691 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
695 /* Select port on the board */
696 rc_out(bp, CD180_CAR, port_No(port));
698 if (!baud_table[baud]) {
699 /* Drop DTR & exit */
700 bp->DTR |= (1u << port_No(port));
701 rc_out(bp, RC_DTR, bp->DTR);
705 bp->DTR &= ~(1u << port_No(port));
706 rc_out(bp, RC_DTR, bp->DTR);
710 * Now we must calculate some speed depended things
713 /* Set baud rate for port */
714 tmp = (((RC_OSCFREQ + baud_table[baud]/2) / baud_table[baud] +
715 CD180_TPC/2) / CD180_TPC);
717 rc_out(bp, CD180_RBPRH, (tmp >> 8) & 0xff);
718 rc_out(bp, CD180_TBPRH, (tmp >> 8) & 0xff);
719 rc_out(bp, CD180_RBPRL, tmp & 0xff);
720 rc_out(bp, CD180_TBPRL, tmp & 0xff);
722 baud = (baud_table[baud] + 5) / 10; /* Estimated CPS */
724 /* Two timer ticks seems enough to wakeup something like SLIP driver */
725 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;
726 port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
727 SERIAL_XMIT_SIZE - 1 : tmp);
729 /* Receiver timeout will be transmission time for 1.5 chars */
730 tmp = (RISCOM_TPS + RISCOM_TPS/2 + baud/2) / baud;
731 tmp = (tmp > 0xff) ? 0xff : tmp;
732 rc_out(bp, CD180_RTPR, tmp);
734 switch (C_CSIZE(tty)) {
754 cor1 |= COR1_NORMPAR;
758 cor1 &= ~COR1_IGNORE;
760 /* Set marking of some errors */
761 port->mark_mask = RCSR_OE | RCSR_TOUT;
763 port->mark_mask |= RCSR_FE | RCSR_PE;
764 if (I_BRKINT(tty) || I_PARMRK(tty))
765 port->mark_mask |= RCSR_BREAK;
767 port->mark_mask &= ~(RCSR_FE | RCSR_PE);
769 port->mark_mask &= ~RCSR_BREAK;
771 /* Real raw mode. Ignore all */
772 port->mark_mask &= ~RCSR_OE;
774 /* Enable Hardware Flow Control */
775 if (C_CRTSCTS(tty)) {
776 #ifdef RISCOM_BRAIN_DAMAGED_CTS
777 port->IER |= IER_DSR | IER_CTS;
778 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
779 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
780 tty->hw_stopped = !(rc_in(bp, CD180_MSVR) & (MSVR_CTS|MSVR_DSR));
782 port->COR2 |= COR2_CTSAE;
785 /* Enable Software Flow Control. FIXME: I'm not sure about this */
786 /* Some people reported that it works, but I still doubt */
788 port->COR2 |= COR2_TXIBE;
789 cor3 |= (COR3_FCT | COR3_SCDE);
791 port->COR2 |= COR2_IXM;
792 rc_out(bp, CD180_SCHR1, START_CHAR(tty));
793 rc_out(bp, CD180_SCHR2, STOP_CHAR(tty));
794 rc_out(bp, CD180_SCHR3, START_CHAR(tty));
795 rc_out(bp, CD180_SCHR4, STOP_CHAR(tty));
797 if (!C_CLOCAL(tty)) {
798 /* Enable CD check */
805 /* Enable receiver */
806 port->IER |= IER_RXD;
808 /* Set input FIFO size (1-8 bytes) */
809 cor3 |= RISCOM_RXFIFO;
810 /* Setting up CD180 channel registers */
811 rc_out(bp, CD180_COR1, cor1);
812 rc_out(bp, CD180_COR2, port->COR2);
813 rc_out(bp, CD180_COR3, cor3);
814 /* Make CD180 know about registers change */
816 rc_out(bp, CD180_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3);
817 /* Setting up modem option registers */
818 rc_out(bp, CD180_MCOR1, mcor1);
819 rc_out(bp, CD180_MCOR2, mcor2);
820 /* Enable CD180 transmitter & receiver */
822 rc_out(bp, CD180_CCR, CCR_TXEN | CCR_RXEN);
823 /* Enable interrupts */
824 rc_out(bp, CD180_IER, port->IER);
825 /* And finally set RTS on */
826 rc_out(bp, CD180_MSVR, port->MSVR);
829 /* Must be called with interrupts enabled */
830 static int rc_setup_port(struct riscom_board *bp, struct riscom_port *port)
834 if (port->flags & ASYNC_INITIALIZED)
837 if (!port->xmit_buf) {
838 /* We may sleep in get_zeroed_page() */
841 if (!(tmp = get_zeroed_page(GFP_KERNEL)))
844 if (port->xmit_buf) {
848 port->xmit_buf = (unsigned char *) tmp;
851 save_flags(flags); cli();
854 clear_bit(TTY_IO_ERROR, &port->tty->flags);
856 if (port->count == 1)
859 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
860 rc_change_speed(bp, port);
861 port->flags |= ASYNC_INITIALIZED;
863 restore_flags(flags);
867 /* Must be called with interrupts disabled */
868 static void rc_shutdown_port(struct riscom_board *bp, struct riscom_port *port)
870 struct tty_struct *tty;
872 if (!(port->flags & ASYNC_INITIALIZED))
875 #ifdef RC_REPORT_OVERRUN
876 printk(KERN_INFO "rc%d: port %d: Total %ld overruns were detected.\n",
877 board_No(bp), port_No(port), port->overrun);
879 #ifdef RC_REPORT_FIFO
883 printk(KERN_INFO "rc%d: port %d: FIFO hits [ ",
884 board_No(bp), port_No(port));
885 for (i = 0; i < 10; i++) {
886 printk("%ld ", port->hits[i]);
891 if (port->xmit_buf) {
892 free_page((unsigned long) port->xmit_buf);
893 port->xmit_buf = NULL;
896 if (!(tty = port->tty) || C_HUPCL(tty)) {
898 bp->DTR |= (1u << port_No(port));
899 rc_out(bp, RC_DTR, bp->DTR);
903 rc_out(bp, CD180_CAR, port_No(port));
906 rc_out(bp, CD180_CCR, CCR_SOFTRESET);
907 /* Disable all interrupts from this port */
909 rc_out(bp, CD180_IER, port->IER);
912 set_bit(TTY_IO_ERROR, &tty->flags);
913 port->flags &= ~ASYNC_INITIALIZED;
915 if (--bp->count < 0) {
916 printk(KERN_INFO "rc%d: rc_shutdown_port: "
917 "bad board count: %d\n",
918 board_No(bp), bp->count);
923 * If this is the last opened port on the board
924 * shutdown whole board
927 rc_shutdown_board(bp);
931 static int block_til_ready(struct tty_struct *tty, struct file * filp,
932 struct riscom_port *port)
934 DECLARE_WAITQUEUE(wait, current);
935 struct riscom_board *bp = port_Board(port);
941 * If the device is in the middle of being closed, then block
942 * until it's done, and then try again.
944 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
945 interruptible_sleep_on(&port->close_wait);
946 if (port->flags & ASYNC_HUP_NOTIFY)
953 * If non-blocking mode is set, or the port is not enabled,
954 * then make the check up front and then exit.
956 if ((filp->f_flags & O_NONBLOCK) ||
957 (tty->flags & (1 << TTY_IO_ERROR))) {
958 port->flags |= ASYNC_NORMAL_ACTIVE;
966 * Block waiting for the carrier detect and the line to become
967 * free (i.e., not in use by the callout). While we are in
968 * this loop, info->count is dropped by one, so that
969 * rs_close() knows when to free things. We restore it upon
970 * exit, either normal or abnormal.
973 add_wait_queue(&port->open_wait, &wait);
975 if (!tty_hung_up_p(filp))
978 port->blocked_open++;
981 rc_out(bp, CD180_CAR, port_No(port));
982 CD = rc_in(bp, CD180_MSVR) & MSVR_CD;
983 rc_out(bp, CD180_MSVR, MSVR_RTS);
984 bp->DTR &= ~(1u << port_No(port));
985 rc_out(bp, RC_DTR, bp->DTR);
987 set_current_state(TASK_INTERRUPTIBLE);
988 if (tty_hung_up_p(filp) ||
989 !(port->flags & ASYNC_INITIALIZED)) {
990 if (port->flags & ASYNC_HUP_NOTIFY)
993 retval = -ERESTARTSYS;
996 if (!(port->flags & ASYNC_CLOSING) &&
999 if (signal_pending(current)) {
1000 retval = -ERESTARTSYS;
1005 current->state = TASK_RUNNING;
1006 remove_wait_queue(&port->open_wait, &wait);
1007 if (!tty_hung_up_p(filp))
1009 port->blocked_open--;
1013 port->flags |= ASYNC_NORMAL_ACTIVE;
1017 static int rc_open(struct tty_struct * tty, struct file * filp)
1021 struct riscom_port * port;
1022 struct riscom_board * bp;
1024 board = RC_BOARD(tty->index);
1025 if (board >= RC_NBOARD || !(rc_board[board].flags & RC_BOARD_PRESENT))
1028 bp = &rc_board[board];
1029 port = rc_port + board * RC_NPORT + RC_PORT(tty->index);
1030 if (rc_paranoia_check(port, tty->name, "rc_open"))
1033 if ((error = rc_setup_board(bp)))
1037 tty->driver_data = port;
1040 if ((error = rc_setup_port(bp, port)))
1043 if ((error = block_til_ready(tty, filp, port)))
1049 static void rc_close(struct tty_struct * tty, struct file * filp)
1051 struct riscom_port *port = (struct riscom_port *) tty->driver_data;
1052 struct riscom_board *bp;
1053 unsigned long flags;
1054 unsigned long timeout;
1056 if (!port || rc_paranoia_check(port, tty->name, "close"))
1059 save_flags(flags); cli();
1060 if (tty_hung_up_p(filp))
1063 bp = port_Board(port);
1064 if ((tty->count == 1) && (port->count != 1)) {
1065 printk(KERN_INFO "rc%d: rc_close: bad port count;"
1066 " tty->count is 1, port count is %d\n",
1067 board_No(bp), port->count);
1070 if (--port->count < 0) {
1071 printk(KERN_INFO "rc%d: rc_close: bad port count "
1073 board_No(bp), port_No(port), port->count);
1078 port->flags |= ASYNC_CLOSING;
1080 * Now we wait for the transmit buffer to clear; and we notify
1081 * the line discipline to only process XON/XOFF characters.
1084 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1085 tty_wait_until_sent(tty, port->closing_wait);
1087 * At this point we stop accepting input. To do this, we
1088 * disable the receive line status interrupts, and tell the
1089 * interrupt driver to stop checking the data ready bit in the
1090 * line status register.
1092 port->IER &= ~IER_RXD;
1093 if (port->flags & ASYNC_INITIALIZED) {
1094 port->IER &= ~IER_TXRDY;
1095 port->IER |= IER_TXEMPTY;
1096 rc_out(bp, CD180_CAR, port_No(port));
1097 rc_out(bp, CD180_IER, port->IER);
1099 * Before we drop DTR, make sure the UART transmitter
1100 * has completely drained; this is especially
1101 * important if there is a transmit FIFO!
1103 timeout = jiffies+HZ;
1104 while(port->IER & IER_TXEMPTY) {
1105 msleep_interruptible(jiffies_to_msecs(port->timeout));
1106 if (time_after(jiffies, timeout))
1110 rc_shutdown_port(bp, port);
1111 if (tty->driver->flush_buffer)
1112 tty->driver->flush_buffer(tty);
1113 tty_ldisc_flush(tty);
1118 if (port->blocked_open) {
1119 if (port->close_delay) {
1120 msleep_interruptible(jiffies_to_msecs(port->close_delay));
1122 wake_up_interruptible(&port->open_wait);
1124 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1125 wake_up_interruptible(&port->close_wait);
1126 out: restore_flags(flags);
1129 static int rc_write(struct tty_struct * tty,
1130 const unsigned char *buf, int count)
1132 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1133 struct riscom_board *bp;
1135 unsigned long flags;
1137 if (rc_paranoia_check(port, tty->name, "rc_write"))
1140 bp = port_Board(port);
1142 if (!tty || !port->xmit_buf || !tmp_buf)
1148 c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1149 SERIAL_XMIT_SIZE - port->xmit_head));
1151 restore_flags(flags);
1155 memcpy(port->xmit_buf + port->xmit_head, buf, c);
1156 port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1157 port->xmit_cnt += c;
1158 restore_flags(flags);
1166 if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1167 !(port->IER & IER_TXRDY)) {
1168 port->IER |= IER_TXRDY;
1169 rc_out(bp, CD180_CAR, port_No(port));
1170 rc_out(bp, CD180_IER, port->IER);
1172 restore_flags(flags);
1177 static void rc_put_char(struct tty_struct * tty, unsigned char ch)
1179 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1180 unsigned long flags;
1182 if (rc_paranoia_check(port, tty->name, "rc_put_char"))
1185 if (!tty || !port->xmit_buf)
1188 save_flags(flags); cli();
1190 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1193 port->xmit_buf[port->xmit_head++] = ch;
1194 port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1196 out: restore_flags(flags);
1199 static void rc_flush_chars(struct tty_struct * tty)
1201 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1202 unsigned long flags;
1204 if (rc_paranoia_check(port, tty->name, "rc_flush_chars"))
1207 if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1211 save_flags(flags); cli();
1212 port->IER |= IER_TXRDY;
1213 rc_out(port_Board(port), CD180_CAR, port_No(port));
1214 rc_out(port_Board(port), CD180_IER, port->IER);
1215 restore_flags(flags);
1218 static int rc_write_room(struct tty_struct * tty)
1220 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1223 if (rc_paranoia_check(port, tty->name, "rc_write_room"))
1226 ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
1232 static int rc_chars_in_buffer(struct tty_struct *tty)
1234 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1236 if (rc_paranoia_check(port, tty->name, "rc_chars_in_buffer"))
1239 return port->xmit_cnt;
1242 static void rc_flush_buffer(struct tty_struct *tty)
1244 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1245 unsigned long flags;
1247 if (rc_paranoia_check(port, tty->name, "rc_flush_buffer"))
1250 save_flags(flags); cli();
1251 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1252 restore_flags(flags);
1254 wake_up_interruptible(&tty->write_wait);
1258 static int rc_tiocmget(struct tty_struct *tty, struct file *file)
1260 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1261 struct riscom_board * bp;
1262 unsigned char status;
1263 unsigned int result;
1264 unsigned long flags;
1266 if (rc_paranoia_check(port, tty->name, __FUNCTION__))
1269 bp = port_Board(port);
1270 save_flags(flags); cli();
1271 rc_out(bp, CD180_CAR, port_No(port));
1272 status = rc_in(bp, CD180_MSVR);
1273 result = rc_in(bp, RC_RI) & (1u << port_No(port)) ? 0 : TIOCM_RNG;
1274 restore_flags(flags);
1275 result |= ((status & MSVR_RTS) ? TIOCM_RTS : 0)
1276 | ((status & MSVR_DTR) ? TIOCM_DTR : 0)
1277 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1278 | ((status & MSVR_DSR) ? TIOCM_DSR : 0)
1279 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1283 static int rc_tiocmset(struct tty_struct *tty, struct file *file,
1284 unsigned int set, unsigned int clear)
1286 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1287 unsigned long flags;
1288 struct riscom_board *bp;
1290 if (rc_paranoia_check(port, tty->name, __FUNCTION__))
1293 bp = port_Board(port);
1295 save_flags(flags); cli();
1296 if (set & TIOCM_RTS)
1297 port->MSVR |= MSVR_RTS;
1298 if (set & TIOCM_DTR)
1299 bp->DTR &= ~(1u << port_No(port));
1301 if (clear & TIOCM_RTS)
1302 port->MSVR &= ~MSVR_RTS;
1303 if (clear & TIOCM_DTR)
1304 bp->DTR |= (1u << port_No(port));
1306 rc_out(bp, CD180_CAR, port_No(port));
1307 rc_out(bp, CD180_MSVR, port->MSVR);
1308 rc_out(bp, RC_DTR, bp->DTR);
1309 restore_flags(flags);
1313 static inline void rc_send_break(struct riscom_port * port, unsigned long length)
1315 struct riscom_board *bp = port_Board(port);
1316 unsigned long flags;
1318 save_flags(flags); cli();
1319 port->break_length = RISCOM_TPS / HZ * length;
1320 port->COR2 |= COR2_ETC;
1321 port->IER |= IER_TXRDY;
1322 rc_out(bp, CD180_CAR, port_No(port));
1323 rc_out(bp, CD180_COR2, port->COR2);
1324 rc_out(bp, CD180_IER, port->IER);
1326 rc_out(bp, CD180_CCR, CCR_CORCHG2);
1328 restore_flags(flags);
1331 static inline int rc_set_serial_info(struct riscom_port * port,
1332 struct serial_struct __user * newinfo)
1334 struct serial_struct tmp;
1335 struct riscom_board *bp = port_Board(port);
1337 unsigned long flags;
1339 if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
1343 if ((tmp.irq != bp->irq) ||
1344 (tmp.port != bp->base) ||
1345 (tmp.type != PORT_CIRRUS) ||
1346 (tmp.baud_base != (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC) ||
1347 (tmp.custom_divisor != 0) ||
1348 (tmp.xmit_fifo_size != CD180_NFIFO) ||
1349 (tmp.flags & ~RISCOM_LEGAL_FLAGS))
1353 change_speed = ((port->flags & ASYNC_SPD_MASK) !=
1354 (tmp.flags & ASYNC_SPD_MASK));
1356 if (!capable(CAP_SYS_ADMIN)) {
1357 if ((tmp.close_delay != port->close_delay) ||
1358 (tmp.closing_wait != port->closing_wait) ||
1359 ((tmp.flags & ~ASYNC_USR_MASK) !=
1360 (port->flags & ~ASYNC_USR_MASK)))
1362 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
1363 (tmp.flags & ASYNC_USR_MASK));
1365 port->flags = ((port->flags & ~ASYNC_FLAGS) |
1366 (tmp.flags & ASYNC_FLAGS));
1367 port->close_delay = tmp.close_delay;
1368 port->closing_wait = tmp.closing_wait;
1371 save_flags(flags); cli();
1372 rc_change_speed(bp, port);
1373 restore_flags(flags);
1378 static inline int rc_get_serial_info(struct riscom_port * port,
1379 struct serial_struct __user *retinfo)
1381 struct serial_struct tmp;
1382 struct riscom_board *bp = port_Board(port);
1384 memset(&tmp, 0, sizeof(tmp));
1385 tmp.type = PORT_CIRRUS;
1386 tmp.line = port - rc_port;
1387 tmp.port = bp->base;
1389 tmp.flags = port->flags;
1390 tmp.baud_base = (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC;
1391 tmp.close_delay = port->close_delay * HZ/100;
1392 tmp.closing_wait = port->closing_wait * HZ/100;
1393 tmp.xmit_fifo_size = CD180_NFIFO;
1394 return copy_to_user(retinfo, &tmp, sizeof(tmp)) ? -EFAULT : 0;
1397 static int rc_ioctl(struct tty_struct * tty, struct file * filp,
1398 unsigned int cmd, unsigned long arg)
1401 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1402 void __user *argp = (void __user *)arg;
1405 if (rc_paranoia_check(port, tty->name, "rc_ioctl"))
1409 case TCSBRK: /* SVID version: non-zero arg --> no break */
1410 retval = tty_check_change(tty);
1413 tty_wait_until_sent(tty, 0);
1415 rc_send_break(port, HZ/4); /* 1/4 second */
1417 case TCSBRKP: /* support for POSIX tcsendbreak() */
1418 retval = tty_check_change(tty);
1421 tty_wait_until_sent(tty, 0);
1422 rc_send_break(port, arg ? arg*(HZ/10) : HZ/4);
1425 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned __user *)argp);
1427 if (get_user(arg,(unsigned __user *) argp))
1429 tty->termios->c_cflag =
1430 ((tty->termios->c_cflag & ~CLOCAL) |
1431 (arg ? CLOCAL : 0));
1434 return rc_get_serial_info(port, argp);
1436 return rc_set_serial_info(port, argp);
1438 return -ENOIOCTLCMD;
1443 static void rc_throttle(struct tty_struct * tty)
1445 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1446 struct riscom_board *bp;
1447 unsigned long flags;
1449 if (rc_paranoia_check(port, tty->name, "rc_throttle"))
1452 bp = port_Board(port);
1454 save_flags(flags); cli();
1455 port->MSVR &= ~MSVR_RTS;
1456 rc_out(bp, CD180_CAR, port_No(port));
1459 rc_out(bp, CD180_CCR, CCR_SSCH2);
1462 rc_out(bp, CD180_MSVR, port->MSVR);
1463 restore_flags(flags);
1466 static void rc_unthrottle(struct tty_struct * tty)
1468 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1469 struct riscom_board *bp;
1470 unsigned long flags;
1472 if (rc_paranoia_check(port, tty->name, "rc_unthrottle"))
1475 bp = port_Board(port);
1477 save_flags(flags); cli();
1478 port->MSVR |= MSVR_RTS;
1479 rc_out(bp, CD180_CAR, port_No(port));
1482 rc_out(bp, CD180_CCR, CCR_SSCH1);
1485 rc_out(bp, CD180_MSVR, port->MSVR);
1486 restore_flags(flags);
1489 static void rc_stop(struct tty_struct * tty)
1491 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1492 struct riscom_board *bp;
1493 unsigned long flags;
1495 if (rc_paranoia_check(port, tty->name, "rc_stop"))
1498 bp = port_Board(port);
1500 save_flags(flags); cli();
1501 port->IER &= ~IER_TXRDY;
1502 rc_out(bp, CD180_CAR, port_No(port));
1503 rc_out(bp, CD180_IER, port->IER);
1504 restore_flags(flags);
1507 static void rc_start(struct tty_struct * tty)
1509 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1510 struct riscom_board *bp;
1511 unsigned long flags;
1513 if (rc_paranoia_check(port, tty->name, "rc_start"))
1516 bp = port_Board(port);
1518 save_flags(flags); cli();
1519 if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) {
1520 port->IER |= IER_TXRDY;
1521 rc_out(bp, CD180_CAR, port_No(port));
1522 rc_out(bp, CD180_IER, port->IER);
1524 restore_flags(flags);
1528 * This routine is called from the work queue when the interrupt
1529 * routine has signalled that a hangup has occurred. The path of
1530 * hangup processing is:
1532 * serial interrupt routine -> (workqueue) ->
1533 * do_rc_hangup() -> tty->hangup() -> rc_hangup()
1536 static void do_rc_hangup(void *private_)
1538 struct riscom_port *port = (struct riscom_port *) private_;
1539 struct tty_struct *tty;
1543 tty_hangup(tty); /* FIXME: module removal race still here */
1546 static void rc_hangup(struct tty_struct * tty)
1548 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1549 struct riscom_board *bp;
1551 if (rc_paranoia_check(port, tty->name, "rc_hangup"))
1554 bp = port_Board(port);
1556 rc_shutdown_port(bp, port);
1559 port->flags &= ~ASYNC_NORMAL_ACTIVE;
1561 wake_up_interruptible(&port->open_wait);
1564 static void rc_set_termios(struct tty_struct * tty, struct termios * old_termios)
1566 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1567 unsigned long flags;
1569 if (rc_paranoia_check(port, tty->name, "rc_set_termios"))
1572 if (tty->termios->c_cflag == old_termios->c_cflag &&
1573 tty->termios->c_iflag == old_termios->c_iflag)
1576 save_flags(flags); cli();
1577 rc_change_speed(port_Board(port), port);
1578 restore_flags(flags);
1580 if ((old_termios->c_cflag & CRTSCTS) &&
1581 !(tty->termios->c_cflag & CRTSCTS)) {
1582 tty->hw_stopped = 0;
1587 static void do_softint(void *private_)
1589 struct riscom_port *port = (struct riscom_port *) private_;
1590 struct tty_struct *tty;
1592 if(!(tty = port->tty))
1595 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) {
1597 wake_up_interruptible(&tty->write_wait);
1601 static struct tty_operations riscom_ops = {
1605 .put_char = rc_put_char,
1606 .flush_chars = rc_flush_chars,
1607 .write_room = rc_write_room,
1608 .chars_in_buffer = rc_chars_in_buffer,
1609 .flush_buffer = rc_flush_buffer,
1611 .throttle = rc_throttle,
1612 .unthrottle = rc_unthrottle,
1613 .set_termios = rc_set_termios,
1616 .hangup = rc_hangup,
1617 .tiocmget = rc_tiocmget,
1618 .tiocmset = rc_tiocmset,
1621 static inline int rc_init_drivers(void)
1626 riscom_driver = alloc_tty_driver(RC_NBOARD * RC_NPORT);
1630 if (!(tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL))) {
1631 printk(KERN_ERR "rc: Couldn't get free page.\n");
1632 put_tty_driver(riscom_driver);
1635 memset(IRQ_to_board, 0, sizeof(IRQ_to_board));
1636 riscom_driver->owner = THIS_MODULE;
1637 riscom_driver->name = "ttyL";
1638 riscom_driver->devfs_name = "tts/L";
1639 riscom_driver->major = RISCOM8_NORMAL_MAJOR;
1640 riscom_driver->type = TTY_DRIVER_TYPE_SERIAL;
1641 riscom_driver->subtype = SERIAL_TYPE_NORMAL;
1642 riscom_driver->init_termios = tty_std_termios;
1643 riscom_driver->init_termios.c_cflag =
1644 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1645 riscom_driver->flags = TTY_DRIVER_REAL_RAW;
1646 tty_set_operations(riscom_driver, &riscom_ops);
1647 if ((error = tty_register_driver(riscom_driver))) {
1648 free_page((unsigned long)tmp_buf);
1649 put_tty_driver(riscom_driver);
1650 printk(KERN_ERR "rc: Couldn't register RISCom/8 driver, "
1656 memset(rc_port, 0, sizeof(rc_port));
1657 for (i = 0; i < RC_NPORT * RC_NBOARD; i++) {
1658 rc_port[i].magic = RISCOM8_MAGIC;
1659 INIT_WORK(&rc_port[i].tqueue, do_softint, &rc_port[i]);
1660 INIT_WORK(&rc_port[i].tqueue_hangup, do_rc_hangup, &rc_port[i]);
1661 rc_port[i].close_delay = 50 * HZ/100;
1662 rc_port[i].closing_wait = 3000 * HZ/100;
1663 init_waitqueue_head(&rc_port[i].open_wait);
1664 init_waitqueue_head(&rc_port[i].close_wait);
1670 static void rc_release_drivers(void)
1672 unsigned long flags;
1676 free_page((unsigned long)tmp_buf);
1677 tty_unregister_driver(riscom_driver);
1678 put_tty_driver(riscom_driver);
1679 restore_flags(flags);
1684 * Called at boot time.
1686 * You can specify IO base for up to RC_NBOARD cards,
1687 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
1688 * Note that there will be no probing at default
1689 * addresses in this case.
1692 static int __init riscom8_setup(char *str)
1694 int ints[RC_NBOARD];
1697 str = get_options(str, ARRAY_SIZE(ints), ints);
1699 for (i = 0; i < RC_NBOARD; i++) {
1701 rc_board[i].base = ints[i+1];
1703 rc_board[i].base = 0;
1708 __setup("riscom8=", riscom8_setup);
1711 static char banner[] __initdata =
1712 KERN_INFO "rc: SDL RISCom/8 card driver v1.1, (c) D.Gorodchanin "
1714 static char no_boards_msg[] __initdata =
1715 KERN_INFO "rc: No RISCom/8 boards detected.\n";
1718 * This routine must be called by kernel at boot time
1720 static int __init riscom8_init(void)
1727 if (rc_init_drivers())
1730 for (i = 0; i < RC_NBOARD; i++)
1731 if (rc_board[i].base && !rc_probe(&rc_board[i]))
1735 rc_release_drivers();
1736 printk(no_boards_msg);
1747 MODULE_PARM(iobase, "i");
1748 MODULE_PARM(iobase1, "i");
1749 MODULE_PARM(iobase2, "i");
1750 MODULE_PARM(iobase3, "i");
1752 MODULE_LICENSE("GPL");
1756 * You can setup up to 4 boards (current value of RC_NBOARD)
1757 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter.
1760 static int __init riscom8_init_module (void)
1765 if (iobase || iobase1 || iobase2 || iobase3) {
1766 for(i = 0; i < RC_NBOARD; i++)
1767 rc_board[0].base = 0;
1771 rc_board[0].base = iobase;
1773 rc_board[1].base = iobase1;
1775 rc_board[2].base = iobase2;
1777 rc_board[3].base = iobase3;
1780 return riscom8_init();
1783 static void __exit riscom8_exit_module (void)
1787 rc_release_drivers();
1788 for (i = 0; i < RC_NBOARD; i++)
1789 if (rc_board[i].flags & RC_BOARD_PRESENT)
1790 rc_release_io_range(&rc_board[i]);
1794 module_init(riscom8_init_module);
1795 module_exit(riscom8_exit_module);