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>
50 #include <linux/spinlock.h>
52 #include <asm/uaccess.h>
55 #include "riscom8_reg.h"
57 /* Am I paranoid or not ? ;-) */
58 #define RISCOM_PARANOIA_CHECK
61 * Crazy InteliCom/8 boards sometimes has swapped CTS & DSR signals.
62 * You can slightly speed up things by #undefing the following option,
63 * if you are REALLY sure that your board is correct one.
66 #define RISCOM_BRAIN_DAMAGED_CTS
69 * The following defines are mostly for testing purposes. But if you need
70 * some nice reporting in your syslog, you can define them also.
73 #undef RC_REPORT_OVERRUN
76 #define RISCOM_LEGAL_FLAGS \
77 (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \
78 ASYNC_SPD_HI | ASYNC_SPEED_VHI | ASYNC_SESSION_LOCKOUT | \
79 ASYNC_PGRP_LOCKOUT | ASYNC_CALLOUT_NOHUP)
81 #define RS_EVENT_WRITE_WAKEUP 0
83 static struct tty_driver *riscom_driver;
85 static DEFINE_SPINLOCK(riscom_lock);
87 static struct riscom_board rc_board[RC_NBOARD] = {
102 static struct riscom_port rc_port[RC_NBOARD * RC_NPORT];
104 /* RISCom/8 I/O ports addresses (without address translation) */
105 static unsigned short rc_ioport[] = {
107 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c,
109 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10,
110 0x11, 0x12, 0x18, 0x28, 0x31, 0x32, 0x39, 0x3a, 0x40, 0x41, 0x61, 0x62,
111 0x63, 0x64, 0x6b, 0x70, 0x71, 0x78, 0x7a, 0x7b, 0x7f, 0x100, 0x101
114 #define RC_NIOPORT ARRAY_SIZE(rc_ioport)
117 static inline int rc_paranoia_check(struct riscom_port const * port,
118 char *name, const char *routine)
120 #ifdef RISCOM_PARANOIA_CHECK
121 static const char badmagic[] = KERN_INFO
122 "rc: Warning: bad riscom port magic number for device %s in %s\n";
123 static const char badinfo[] = KERN_INFO
124 "rc: Warning: null riscom port for device %s in %s\n";
127 printk(badinfo, name, routine);
130 if (port->magic != RISCOM8_MAGIC) {
131 printk(badmagic, name, routine);
140 * Service functions for RISCom/8 driver.
144 /* Get board number from pointer */
145 static inline int board_No (struct riscom_board const * bp)
147 return bp - rc_board;
150 /* Get port number from pointer */
151 static inline int port_No (struct riscom_port const * port)
153 return RC_PORT(port - rc_port);
156 /* Get pointer to board from pointer to port */
157 static inline struct riscom_board * port_Board(struct riscom_port const * port)
159 return &rc_board[RC_BOARD(port - rc_port)];
162 /* Input Byte from CL CD180 register */
163 static inline unsigned char rc_in(struct riscom_board const * bp, unsigned short reg)
165 return inb(bp->base + RC_TO_ISA(reg));
168 /* Output Byte to CL CD180 register */
169 static inline void rc_out(struct riscom_board const * bp, unsigned short reg,
172 outb(val, bp->base + RC_TO_ISA(reg));
175 /* Wait for Channel Command Register ready */
176 static inline void rc_wait_CCR(struct riscom_board const * bp)
180 /* FIXME: need something more descriptive then 100000 :) */
181 for (delay = 100000; delay; delay--)
182 if (!rc_in(bp, CD180_CCR))
185 printk(KERN_INFO "rc%d: Timeout waiting for CCR.\n", board_No(bp));
189 * RISCom/8 probe functions.
192 static inline int rc_request_io_range(struct riscom_board * const bp)
196 for (i = 0; i < RC_NIOPORT; i++)
197 if (!request_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1,
203 printk(KERN_INFO "rc%d: Skipping probe at 0x%03x. IO address in use.\n",
204 board_No(bp), bp->base);
206 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
210 static inline void rc_release_io_range(struct riscom_board * const bp)
214 for (i = 0; i < RC_NIOPORT; i++)
215 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
218 /* Reset and setup CD180 chip */
219 static void __init rc_init_CD180(struct riscom_board const * bp)
223 spin_lock_irqsave(&riscom_lock, flags);
225 rc_out(bp, RC_CTOUT, 0); /* Clear timeout */
226 rc_wait_CCR(bp); /* Wait for CCR ready */
227 rc_out(bp, CD180_CCR, CCR_HARDRESET); /* Reset CD180 chip */
228 spin_unlock_irqrestore(&riscom_lock, flags);
229 msleep(50); /* Delay 0.05 sec */
230 spin_lock_irqsave(&riscom_lock, flags);
231 rc_out(bp, CD180_GIVR, RC_ID); /* Set ID for this chip */
232 rc_out(bp, CD180_GICR, 0); /* Clear all bits */
233 rc_out(bp, CD180_PILR1, RC_ACK_MINT); /* Prio for modem intr */
234 rc_out(bp, CD180_PILR2, RC_ACK_TINT); /* Prio for transmitter intr */
235 rc_out(bp, CD180_PILR3, RC_ACK_RINT); /* Prio for receiver intr */
237 /* Setting up prescaler. We need 4 ticks per 1 ms */
238 rc_out(bp, CD180_PPRH, (RC_OSCFREQ/(1000000/RISCOM_TPS)) >> 8);
239 rc_out(bp, CD180_PPRL, (RC_OSCFREQ/(1000000/RISCOM_TPS)) & 0xff);
241 spin_unlock_irqrestore(&riscom_lock, flags);
244 /* Main probing routine, also sets irq. */
245 static int __init rc_probe(struct riscom_board *bp)
247 unsigned char val1, val2;
253 if (rc_request_io_range(bp))
256 /* Are the I/O ports here ? */
257 rc_out(bp, CD180_PPRL, 0x5a);
259 val1 = rc_in(bp, CD180_PPRL);
260 rc_out(bp, CD180_PPRL, 0xa5);
262 val2 = rc_in(bp, CD180_PPRL);
264 if ((val1 != 0x5a) || (val2 != 0xa5)) {
265 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not found.\n",
266 board_No(bp), bp->base);
270 /* It's time to find IRQ for this board */
271 for (retries = 0; retries < 5 && irqs <= 0; retries++) {
272 irqs = probe_irq_on();
273 rc_init_CD180(bp); /* Reset CD180 chip */
274 rc_out(bp, CD180_CAR, 2); /* Select port 2 */
276 rc_out(bp, CD180_CCR, CCR_TXEN); /* Enable transmitter */
277 rc_out(bp, CD180_IER, IER_TXRDY); /* Enable tx empty intr */
279 irqs = probe_irq_off(irqs);
280 val1 = rc_in(bp, RC_BSR); /* Get Board Status reg */
281 val2 = rc_in(bp, RC_ACK_TINT); /* ACK interrupt */
282 rc_init_CD180(bp); /* Reset CD180 again */
284 if ((val1 & RC_BSR_TINT) || (val2 != (RC_ID | GIVR_IT_TX))) {
285 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not "
286 "found.\n", board_No(bp), bp->base);
292 printk(KERN_ERR "rc%d: Can't find IRQ for RISCom/8 board "
293 "at 0x%03x.\n", board_No(bp), bp->base);
297 bp->flags |= RC_BOARD_PRESENT;
299 printk(KERN_INFO "rc%d: RISCom/8 Rev. %c board detected at "
302 (rc_in(bp, CD180_GFRCR) & 0x0f) + 'A', /* Board revision */
307 rc_release_io_range(bp);
313 * Interrupt processing routines.
317 static inline void rc_mark_event(struct riscom_port * port, int event)
319 set_bit(event, &port->event);
320 schedule_work(&port->tqueue);
323 static inline struct riscom_port * rc_get_port(struct riscom_board const * bp,
324 unsigned char const * what)
326 unsigned char channel;
327 struct riscom_port * port;
329 channel = rc_in(bp, CD180_GICR) >> GICR_CHAN_OFF;
330 if (channel < CD180_NCH) {
331 port = &rc_port[board_No(bp) * RC_NPORT + channel];
332 if (port->flags & ASYNC_INITIALIZED) {
336 printk(KERN_ERR "rc%d: %s interrupt from invalid port %d\n",
337 board_No(bp), what, channel);
341 static inline void rc_receive_exc(struct riscom_board const * bp)
343 struct riscom_port *port;
344 struct tty_struct *tty;
345 unsigned char status;
346 unsigned char ch, flag;
348 if (!(port = rc_get_port(bp, "Receive")))
353 #ifdef RC_REPORT_OVERRUN
354 status = rc_in(bp, CD180_RCSR);
355 if (status & RCSR_OE)
357 status &= port->mark_mask;
359 status = rc_in(bp, CD180_RCSR) & port->mark_mask;
361 ch = rc_in(bp, CD180_RDR);
365 if (status & RCSR_TOUT) {
366 printk(KERN_WARNING "rc%d: port %d: Receiver timeout. "
367 "Hardware problems ?\n",
368 board_No(bp), port_No(port));
371 } else if (status & RCSR_BREAK) {
372 printk(KERN_INFO "rc%d: port %d: Handling break...\n",
373 board_No(bp), port_No(port));
375 if (port->flags & ASYNC_SAK)
378 } else if (status & RCSR_PE)
381 else if (status & RCSR_FE)
384 else if (status & RCSR_OE)
390 tty_insert_flip_char(tty, ch, flag);
391 tty_flip_buffer_push(tty);
394 static inline void rc_receive(struct riscom_board const * bp)
396 struct riscom_port *port;
397 struct tty_struct *tty;
400 if (!(port = rc_get_port(bp, "Receive")))
405 count = rc_in(bp, CD180_RDCR);
407 #ifdef RC_REPORT_FIFO
408 port->hits[count > 8 ? 9 : count]++;
412 if (tty_buffer_request_room(tty, 1) == 0) {
413 printk(KERN_WARNING "rc%d: port %d: Working around "
414 "flip buffer overflow.\n",
415 board_No(bp), port_No(port));
418 tty_insert_flip_char(tty, rc_in(bp, CD180_RDR), TTY_NORMAL);
420 tty_flip_buffer_push(tty);
423 static inline void rc_transmit(struct riscom_board const * bp)
425 struct riscom_port *port;
426 struct tty_struct *tty;
430 if (!(port = rc_get_port(bp, "Transmit")))
435 if (port->IER & IER_TXEMPTY) {
437 rc_out(bp, CD180_CAR, port_No(port));
438 port->IER &= ~IER_TXEMPTY;
439 rc_out(bp, CD180_IER, port->IER);
443 if ((port->xmit_cnt <= 0 && !port->break_length)
444 || tty->stopped || tty->hw_stopped) {
445 rc_out(bp, CD180_CAR, port_No(port));
446 port->IER &= ~IER_TXRDY;
447 rc_out(bp, CD180_IER, port->IER);
451 if (port->break_length) {
452 if (port->break_length > 0) {
453 if (port->COR2 & COR2_ETC) {
454 rc_out(bp, CD180_TDR, CD180_C_ESC);
455 rc_out(bp, CD180_TDR, CD180_C_SBRK);
456 port->COR2 &= ~COR2_ETC;
458 count = min_t(int, port->break_length, 0xff);
459 rc_out(bp, CD180_TDR, CD180_C_ESC);
460 rc_out(bp, CD180_TDR, CD180_C_DELAY);
461 rc_out(bp, CD180_TDR, count);
462 if (!(port->break_length -= count))
463 port->break_length--;
465 rc_out(bp, CD180_TDR, CD180_C_ESC);
466 rc_out(bp, CD180_TDR, CD180_C_EBRK);
467 rc_out(bp, CD180_COR2, port->COR2);
469 rc_out(bp, CD180_CCR, CCR_CORCHG2);
470 port->break_length = 0;
477 rc_out(bp, CD180_TDR, port->xmit_buf[port->xmit_tail++]);
478 port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1);
479 if (--port->xmit_cnt <= 0)
481 } while (--count > 0);
483 if (port->xmit_cnt <= 0) {
484 rc_out(bp, CD180_CAR, port_No(port));
485 port->IER &= ~IER_TXRDY;
486 rc_out(bp, CD180_IER, port->IER);
488 if (port->xmit_cnt <= port->wakeup_chars)
489 rc_mark_event(port, RS_EVENT_WRITE_WAKEUP);
492 static inline void rc_check_modem(struct riscom_board const * bp)
494 struct riscom_port *port;
495 struct tty_struct *tty;
498 if (!(port = rc_get_port(bp, "Modem")))
503 mcr = rc_in(bp, CD180_MCR);
504 if (mcr & MCR_CDCHG) {
505 if (rc_in(bp, CD180_MSVR) & MSVR_CD)
506 wake_up_interruptible(&port->open_wait);
508 schedule_work(&port->tqueue_hangup);
511 #ifdef RISCOM_BRAIN_DAMAGED_CTS
512 if (mcr & MCR_CTSCHG) {
513 if (rc_in(bp, CD180_MSVR) & MSVR_CTS) {
515 port->IER |= IER_TXRDY;
516 if (port->xmit_cnt <= port->wakeup_chars)
517 rc_mark_event(port, RS_EVENT_WRITE_WAKEUP);
520 port->IER &= ~IER_TXRDY;
522 rc_out(bp, CD180_IER, port->IER);
524 if (mcr & MCR_DSRCHG) {
525 if (rc_in(bp, CD180_MSVR) & MSVR_DSR) {
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 #endif /* RISCOM_BRAIN_DAMAGED_CTS */
538 /* Clear change bits */
539 rc_out(bp, CD180_MCR, 0);
542 /* The main interrupt processing routine */
543 static irqreturn_t rc_interrupt(int dummy, void * dev_id)
545 unsigned char status;
547 struct riscom_board *bp = dev_id;
548 unsigned long loop = 0;
551 if (!(bp->flags & RC_BOARD_ACTIVE))
554 while ((++loop < 16) && ((status = ~(rc_in(bp, RC_BSR))) &
555 (RC_BSR_TOUT | RC_BSR_TINT |
556 RC_BSR_MINT | RC_BSR_RINT))) {
558 if (status & RC_BSR_TOUT)
559 printk(KERN_WARNING "rc%d: Got timeout. Hardware "
560 "error?\n", board_No(bp));
562 else if (status & RC_BSR_RINT) {
563 ack = rc_in(bp, RC_ACK_RINT);
565 if (ack == (RC_ID | GIVR_IT_RCV))
567 else if (ack == (RC_ID | GIVR_IT_REXC))
570 printk(KERN_WARNING "rc%d: Bad receive ack "
574 } else if (status & RC_BSR_TINT) {
575 ack = rc_in(bp, RC_ACK_TINT);
577 if (ack == (RC_ID | GIVR_IT_TX))
580 printk(KERN_WARNING "rc%d: Bad transmit ack "
584 } else /* if (status & RC_BSR_MINT) */ {
585 ack = rc_in(bp, RC_ACK_MINT);
587 if (ack == (RC_ID | GIVR_IT_MODEM))
590 printk(KERN_WARNING "rc%d: Bad modem ack "
596 rc_out(bp, CD180_EOIR, 0); /* Mark end of interrupt */
597 rc_out(bp, RC_CTOUT, 0); /* Clear timeout flag */
599 return IRQ_RETVAL(handled);
603 * Routines for open & close processing.
606 /* Called with disabled interrupts */
607 static int rc_setup_board(struct riscom_board * bp)
611 if (bp->flags & RC_BOARD_ACTIVE)
614 error = request_irq(bp->irq, rc_interrupt, IRQF_DISABLED,
619 rc_out(bp, RC_CTOUT, 0); /* Just in case */
621 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */
623 bp->flags |= RC_BOARD_ACTIVE;
628 /* Called with disabled interrupts */
629 static void rc_shutdown_board(struct riscom_board *bp)
631 if (!(bp->flags & RC_BOARD_ACTIVE))
634 bp->flags &= ~RC_BOARD_ACTIVE;
636 free_irq(bp->irq, NULL);
639 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */
644 * Setting up port characteristics.
645 * Must be called with disabled interrupts
647 static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
649 struct tty_struct *tty;
652 unsigned char cor1 = 0, cor3 = 0;
653 unsigned char mcor1 = 0, mcor2 = 0;
655 if (!(tty = port->tty) || !tty->termios)
660 port->MSVR = MSVR_RTS;
662 baud = tty_get_baud_rate(tty);
664 /* Select port on the board */
665 rc_out(bp, CD180_CAR, port_No(port));
668 /* Drop DTR & exit */
669 bp->DTR |= (1u << port_No(port));
670 rc_out(bp, RC_DTR, bp->DTR);
674 bp->DTR &= ~(1u << port_No(port));
675 rc_out(bp, RC_DTR, bp->DTR);
679 * Now we must calculate some speed depended things
682 /* Set baud rate for port */
683 tmp = (((RC_OSCFREQ + baud/2) / baud +
684 CD180_TPC/2) / CD180_TPC);
686 rc_out(bp, CD180_RBPRH, (tmp >> 8) & 0xff);
687 rc_out(bp, CD180_TBPRH, (tmp >> 8) & 0xff);
688 rc_out(bp, CD180_RBPRL, tmp & 0xff);
689 rc_out(bp, CD180_TBPRL, tmp & 0xff);
691 baud = (baud + 5) / 10; /* Estimated CPS */
693 /* Two timer ticks seems enough to wakeup something like SLIP driver */
694 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;
695 port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
696 SERIAL_XMIT_SIZE - 1 : tmp);
698 /* Receiver timeout will be transmission time for 1.5 chars */
699 tmp = (RISCOM_TPS + RISCOM_TPS/2 + baud/2) / baud;
700 tmp = (tmp > 0xff) ? 0xff : tmp;
701 rc_out(bp, CD180_RTPR, tmp);
703 switch (C_CSIZE(tty)) {
723 cor1 |= COR1_NORMPAR;
727 cor1 &= ~COR1_IGNORE;
729 /* Set marking of some errors */
730 port->mark_mask = RCSR_OE | RCSR_TOUT;
732 port->mark_mask |= RCSR_FE | RCSR_PE;
733 if (I_BRKINT(tty) || I_PARMRK(tty))
734 port->mark_mask |= RCSR_BREAK;
736 port->mark_mask &= ~(RCSR_FE | RCSR_PE);
738 port->mark_mask &= ~RCSR_BREAK;
740 /* Real raw mode. Ignore all */
741 port->mark_mask &= ~RCSR_OE;
743 /* Enable Hardware Flow Control */
744 if (C_CRTSCTS(tty)) {
745 #ifdef RISCOM_BRAIN_DAMAGED_CTS
746 port->IER |= IER_DSR | IER_CTS;
747 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
748 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
749 tty->hw_stopped = !(rc_in(bp, CD180_MSVR) & (MSVR_CTS|MSVR_DSR));
751 port->COR2 |= COR2_CTSAE;
754 /* Enable Software Flow Control. FIXME: I'm not sure about this */
755 /* Some people reported that it works, but I still doubt */
757 port->COR2 |= COR2_TXIBE;
758 cor3 |= (COR3_FCT | COR3_SCDE);
760 port->COR2 |= COR2_IXM;
761 rc_out(bp, CD180_SCHR1, START_CHAR(tty));
762 rc_out(bp, CD180_SCHR2, STOP_CHAR(tty));
763 rc_out(bp, CD180_SCHR3, START_CHAR(tty));
764 rc_out(bp, CD180_SCHR4, STOP_CHAR(tty));
766 if (!C_CLOCAL(tty)) {
767 /* Enable CD check */
774 /* Enable receiver */
775 port->IER |= IER_RXD;
777 /* Set input FIFO size (1-8 bytes) */
778 cor3 |= RISCOM_RXFIFO;
779 /* Setting up CD180 channel registers */
780 rc_out(bp, CD180_COR1, cor1);
781 rc_out(bp, CD180_COR2, port->COR2);
782 rc_out(bp, CD180_COR3, cor3);
783 /* Make CD180 know about registers change */
785 rc_out(bp, CD180_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3);
786 /* Setting up modem option registers */
787 rc_out(bp, CD180_MCOR1, mcor1);
788 rc_out(bp, CD180_MCOR2, mcor2);
789 /* Enable CD180 transmitter & receiver */
791 rc_out(bp, CD180_CCR, CCR_TXEN | CCR_RXEN);
792 /* Enable interrupts */
793 rc_out(bp, CD180_IER, port->IER);
794 /* And finally set RTS on */
795 rc_out(bp, CD180_MSVR, port->MSVR);
798 /* Must be called with interrupts enabled */
799 static int rc_setup_port(struct riscom_board *bp, struct riscom_port *port)
803 if (port->flags & ASYNC_INITIALIZED)
806 if (!port->xmit_buf) {
807 /* We may sleep in get_zeroed_page() */
810 if (!(tmp = get_zeroed_page(GFP_KERNEL)))
813 if (port->xmit_buf) {
817 port->xmit_buf = (unsigned char *) tmp;
820 spin_lock_irqsave(&riscom_lock, flags);
823 clear_bit(TTY_IO_ERROR, &port->tty->flags);
825 if (port->count == 1)
828 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
829 rc_change_speed(bp, port);
830 port->flags |= ASYNC_INITIALIZED;
832 spin_unlock_irqrestore(&riscom_lock, flags);
836 /* Must be called with interrupts disabled */
837 static void rc_shutdown_port(struct riscom_board *bp, struct riscom_port *port)
839 struct tty_struct *tty;
841 if (!(port->flags & ASYNC_INITIALIZED))
844 #ifdef RC_REPORT_OVERRUN
845 printk(KERN_INFO "rc%d: port %d: Total %ld overruns were detected.\n",
846 board_No(bp), port_No(port), port->overrun);
848 #ifdef RC_REPORT_FIFO
852 printk(KERN_INFO "rc%d: port %d: FIFO hits [ ",
853 board_No(bp), port_No(port));
854 for (i = 0; i < 10; i++) {
855 printk("%ld ", port->hits[i]);
860 if (port->xmit_buf) {
861 free_page((unsigned long) port->xmit_buf);
862 port->xmit_buf = NULL;
865 if (!(tty = port->tty) || C_HUPCL(tty)) {
867 bp->DTR |= (1u << port_No(port));
868 rc_out(bp, RC_DTR, bp->DTR);
872 rc_out(bp, CD180_CAR, port_No(port));
875 rc_out(bp, CD180_CCR, CCR_SOFTRESET);
876 /* Disable all interrupts from this port */
878 rc_out(bp, CD180_IER, port->IER);
881 set_bit(TTY_IO_ERROR, &tty->flags);
882 port->flags &= ~ASYNC_INITIALIZED;
884 if (--bp->count < 0) {
885 printk(KERN_INFO "rc%d: rc_shutdown_port: "
886 "bad board count: %d\n",
887 board_No(bp), bp->count);
892 * If this is the last opened port on the board
893 * shutdown whole board
896 rc_shutdown_board(bp);
900 static int block_til_ready(struct tty_struct *tty, struct file * filp,
901 struct riscom_port *port)
903 DECLARE_WAITQUEUE(wait, current);
904 struct riscom_board *bp = port_Board(port);
911 * If the device is in the middle of being closed, then block
912 * until it's done, and then try again.
914 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
915 interruptible_sleep_on(&port->close_wait);
916 if (port->flags & ASYNC_HUP_NOTIFY)
923 * If non-blocking mode is set, or the port is not enabled,
924 * then make the check up front and then exit.
926 if ((filp->f_flags & O_NONBLOCK) ||
927 (tty->flags & (1 << TTY_IO_ERROR))) {
928 port->flags |= ASYNC_NORMAL_ACTIVE;
936 * Block waiting for the carrier detect and the line to become
937 * free (i.e., not in use by the callout). While we are in
938 * this loop, info->count is dropped by one, so that
939 * rs_close() knows when to free things. We restore it upon
940 * exit, either normal or abnormal.
943 add_wait_queue(&port->open_wait, &wait);
945 spin_lock_irqsave(&riscom_lock, flags);
947 if (!tty_hung_up_p(filp))
950 spin_unlock_irqrestore(&riscom_lock, flags);
952 port->blocked_open++;
954 spin_lock_irqsave(&riscom_lock, flags);
956 rc_out(bp, CD180_CAR, port_No(port));
957 CD = rc_in(bp, CD180_MSVR) & MSVR_CD;
958 rc_out(bp, CD180_MSVR, MSVR_RTS);
959 bp->DTR &= ~(1u << port_No(port));
960 rc_out(bp, RC_DTR, bp->DTR);
962 spin_unlock_irqrestore(&riscom_lock, flags);
964 set_current_state(TASK_INTERRUPTIBLE);
965 if (tty_hung_up_p(filp) ||
966 !(port->flags & ASYNC_INITIALIZED)) {
967 if (port->flags & ASYNC_HUP_NOTIFY)
970 retval = -ERESTARTSYS;
973 if (!(port->flags & ASYNC_CLOSING) &&
976 if (signal_pending(current)) {
977 retval = -ERESTARTSYS;
982 __set_current_state(TASK_RUNNING);
983 remove_wait_queue(&port->open_wait, &wait);
984 if (!tty_hung_up_p(filp))
986 port->blocked_open--;
990 port->flags |= ASYNC_NORMAL_ACTIVE;
994 static int rc_open(struct tty_struct * tty, struct file * filp)
998 struct riscom_port * port;
999 struct riscom_board * bp;
1001 board = RC_BOARD(tty->index);
1002 if (board >= RC_NBOARD || !(rc_board[board].flags & RC_BOARD_PRESENT))
1005 bp = &rc_board[board];
1006 port = rc_port + board * RC_NPORT + RC_PORT(tty->index);
1007 if (rc_paranoia_check(port, tty->name, "rc_open"))
1010 if ((error = rc_setup_board(bp)))
1014 tty->driver_data = port;
1017 if ((error = rc_setup_port(bp, port)))
1020 if ((error = block_til_ready(tty, filp, port)))
1026 static void rc_close(struct tty_struct * tty, struct file * filp)
1028 struct riscom_port *port = (struct riscom_port *) tty->driver_data;
1029 struct riscom_board *bp;
1030 unsigned long flags;
1031 unsigned long timeout;
1033 if (!port || rc_paranoia_check(port, tty->name, "close"))
1036 spin_lock_irqsave(&riscom_lock, flags);
1038 if (tty_hung_up_p(filp))
1041 bp = port_Board(port);
1042 if ((tty->count == 1) && (port->count != 1)) {
1043 printk(KERN_INFO "rc%d: rc_close: bad port count;"
1044 " tty->count is 1, port count is %d\n",
1045 board_No(bp), port->count);
1048 if (--port->count < 0) {
1049 printk(KERN_INFO "rc%d: rc_close: bad port count "
1051 board_No(bp), port_No(port), port->count);
1056 port->flags |= ASYNC_CLOSING;
1058 * Now we wait for the transmit buffer to clear; and we notify
1059 * the line discipline to only process XON/XOFF characters.
1062 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1063 tty_wait_until_sent(tty, port->closing_wait);
1065 * At this point we stop accepting input. To do this, we
1066 * disable the receive line status interrupts, and tell the
1067 * interrupt driver to stop checking the data ready bit in the
1068 * line status register.
1070 port->IER &= ~IER_RXD;
1071 if (port->flags & ASYNC_INITIALIZED) {
1072 port->IER &= ~IER_TXRDY;
1073 port->IER |= IER_TXEMPTY;
1074 rc_out(bp, CD180_CAR, port_No(port));
1075 rc_out(bp, CD180_IER, port->IER);
1077 * Before we drop DTR, make sure the UART transmitter
1078 * has completely drained; this is especially
1079 * important if there is a transmit FIFO!
1081 timeout = jiffies+HZ;
1082 while(port->IER & IER_TXEMPTY) {
1083 msleep_interruptible(jiffies_to_msecs(port->timeout));
1084 if (time_after(jiffies, timeout))
1088 rc_shutdown_port(bp, port);
1089 if (tty->driver->flush_buffer)
1090 tty->driver->flush_buffer(tty);
1091 tty_ldisc_flush(tty);
1096 if (port->blocked_open) {
1097 if (port->close_delay) {
1098 msleep_interruptible(jiffies_to_msecs(port->close_delay));
1100 wake_up_interruptible(&port->open_wait);
1102 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1103 wake_up_interruptible(&port->close_wait);
1106 spin_unlock_irqrestore(&riscom_lock, flags);
1109 static int rc_write(struct tty_struct * tty,
1110 const unsigned char *buf, int count)
1112 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1113 struct riscom_board *bp;
1115 unsigned long flags;
1117 if (rc_paranoia_check(port, tty->name, "rc_write"))
1120 bp = port_Board(port);
1122 if (!tty || !port->xmit_buf)
1126 spin_lock_irqsave(&riscom_lock, flags);
1128 c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1129 SERIAL_XMIT_SIZE - port->xmit_head));
1131 break; /* lock continues to be held */
1133 memcpy(port->xmit_buf + port->xmit_head, buf, c);
1134 port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1135 port->xmit_cnt += c;
1137 spin_unlock_irqrestore(&riscom_lock, flags);
1144 if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1145 !(port->IER & IER_TXRDY)) {
1146 port->IER |= IER_TXRDY;
1147 rc_out(bp, CD180_CAR, port_No(port));
1148 rc_out(bp, CD180_IER, port->IER);
1151 spin_unlock_irqrestore(&riscom_lock, flags);
1156 static void rc_put_char(struct tty_struct * tty, unsigned char ch)
1158 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1159 unsigned long flags;
1161 if (rc_paranoia_check(port, tty->name, "rc_put_char"))
1164 if (!tty || !port->xmit_buf)
1167 spin_lock_irqsave(&riscom_lock, flags);
1169 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1172 port->xmit_buf[port->xmit_head++] = ch;
1173 port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1177 spin_unlock_irqrestore(&riscom_lock, flags);
1180 static void rc_flush_chars(struct tty_struct * tty)
1182 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1183 unsigned long flags;
1185 if (rc_paranoia_check(port, tty->name, "rc_flush_chars"))
1188 if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1192 spin_lock_irqsave(&riscom_lock, flags);
1194 port->IER |= IER_TXRDY;
1195 rc_out(port_Board(port), CD180_CAR, port_No(port));
1196 rc_out(port_Board(port), CD180_IER, port->IER);
1198 spin_unlock_irqrestore(&riscom_lock, flags);
1201 static int rc_write_room(struct tty_struct * tty)
1203 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1206 if (rc_paranoia_check(port, tty->name, "rc_write_room"))
1209 ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
1215 static int rc_chars_in_buffer(struct tty_struct *tty)
1217 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1219 if (rc_paranoia_check(port, tty->name, "rc_chars_in_buffer"))
1222 return port->xmit_cnt;
1225 static void rc_flush_buffer(struct tty_struct *tty)
1227 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1228 unsigned long flags;
1230 if (rc_paranoia_check(port, tty->name, "rc_flush_buffer"))
1233 spin_lock_irqsave(&riscom_lock, flags);
1235 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1237 spin_unlock_irqrestore(&riscom_lock, flags);
1242 static int rc_tiocmget(struct tty_struct *tty, struct file *file)
1244 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1245 struct riscom_board * bp;
1246 unsigned char status;
1247 unsigned int result;
1248 unsigned long flags;
1250 if (rc_paranoia_check(port, tty->name, __FUNCTION__))
1253 bp = port_Board(port);
1255 spin_lock_irqsave(&riscom_lock, flags);
1257 rc_out(bp, CD180_CAR, port_No(port));
1258 status = rc_in(bp, CD180_MSVR);
1259 result = rc_in(bp, RC_RI) & (1u << port_No(port)) ? 0 : TIOCM_RNG;
1261 spin_unlock_irqrestore(&riscom_lock, flags);
1263 result |= ((status & MSVR_RTS) ? TIOCM_RTS : 0)
1264 | ((status & MSVR_DTR) ? TIOCM_DTR : 0)
1265 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1266 | ((status & MSVR_DSR) ? TIOCM_DSR : 0)
1267 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1271 static int rc_tiocmset(struct tty_struct *tty, struct file *file,
1272 unsigned int set, unsigned int clear)
1274 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1275 unsigned long flags;
1276 struct riscom_board *bp;
1278 if (rc_paranoia_check(port, tty->name, __FUNCTION__))
1281 bp = port_Board(port);
1283 spin_lock_irqsave(&riscom_lock, flags);
1285 if (set & TIOCM_RTS)
1286 port->MSVR |= MSVR_RTS;
1287 if (set & TIOCM_DTR)
1288 bp->DTR &= ~(1u << port_No(port));
1290 if (clear & TIOCM_RTS)
1291 port->MSVR &= ~MSVR_RTS;
1292 if (clear & TIOCM_DTR)
1293 bp->DTR |= (1u << port_No(port));
1295 rc_out(bp, CD180_CAR, port_No(port));
1296 rc_out(bp, CD180_MSVR, port->MSVR);
1297 rc_out(bp, RC_DTR, bp->DTR);
1299 spin_unlock_irqrestore(&riscom_lock, flags);
1304 static inline void rc_send_break(struct riscom_port * port, unsigned long length)
1306 struct riscom_board *bp = port_Board(port);
1307 unsigned long flags;
1309 spin_lock_irqsave(&riscom_lock, flags);
1311 port->break_length = RISCOM_TPS / HZ * length;
1312 port->COR2 |= COR2_ETC;
1313 port->IER |= IER_TXRDY;
1314 rc_out(bp, CD180_CAR, port_No(port));
1315 rc_out(bp, CD180_COR2, port->COR2);
1316 rc_out(bp, CD180_IER, port->IER);
1318 rc_out(bp, CD180_CCR, CCR_CORCHG2);
1321 spin_unlock_irqrestore(&riscom_lock, flags);
1324 static inline int rc_set_serial_info(struct riscom_port * port,
1325 struct serial_struct __user * newinfo)
1327 struct serial_struct tmp;
1328 struct riscom_board *bp = port_Board(port);
1331 if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
1335 if ((tmp.irq != bp->irq) ||
1336 (tmp.port != bp->base) ||
1337 (tmp.type != PORT_CIRRUS) ||
1338 (tmp.baud_base != (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC) ||
1339 (tmp.custom_divisor != 0) ||
1340 (tmp.xmit_fifo_size != CD180_NFIFO) ||
1341 (tmp.flags & ~RISCOM_LEGAL_FLAGS))
1345 change_speed = ((port->flags & ASYNC_SPD_MASK) !=
1346 (tmp.flags & ASYNC_SPD_MASK));
1348 if (!capable(CAP_SYS_ADMIN)) {
1349 if ((tmp.close_delay != port->close_delay) ||
1350 (tmp.closing_wait != port->closing_wait) ||
1351 ((tmp.flags & ~ASYNC_USR_MASK) !=
1352 (port->flags & ~ASYNC_USR_MASK)))
1354 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
1355 (tmp.flags & ASYNC_USR_MASK));
1357 port->flags = ((port->flags & ~ASYNC_FLAGS) |
1358 (tmp.flags & ASYNC_FLAGS));
1359 port->close_delay = tmp.close_delay;
1360 port->closing_wait = tmp.closing_wait;
1363 unsigned long flags;
1365 spin_lock_irqsave(&riscom_lock, flags);
1366 rc_change_speed(bp, port);
1367 spin_unlock_irqrestore(&riscom_lock, flags);
1372 static inline int rc_get_serial_info(struct riscom_port * port,
1373 struct serial_struct __user *retinfo)
1375 struct serial_struct tmp;
1376 struct riscom_board *bp = port_Board(port);
1378 memset(&tmp, 0, sizeof(tmp));
1379 tmp.type = PORT_CIRRUS;
1380 tmp.line = port - rc_port;
1381 tmp.port = bp->base;
1383 tmp.flags = port->flags;
1384 tmp.baud_base = (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC;
1385 tmp.close_delay = port->close_delay * HZ/100;
1386 tmp.closing_wait = port->closing_wait * HZ/100;
1387 tmp.xmit_fifo_size = CD180_NFIFO;
1388 return copy_to_user(retinfo, &tmp, sizeof(tmp)) ? -EFAULT : 0;
1391 static int rc_ioctl(struct tty_struct * tty, struct file * filp,
1392 unsigned int cmd, unsigned long arg)
1395 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1396 void __user *argp = (void __user *)arg;
1399 if (rc_paranoia_check(port, tty->name, "rc_ioctl"))
1403 case TCSBRK: /* SVID version: non-zero arg --> no break */
1404 retval = tty_check_change(tty);
1407 tty_wait_until_sent(tty, 0);
1409 rc_send_break(port, HZ/4); /* 1/4 second */
1411 case TCSBRKP: /* support for POSIX tcsendbreak() */
1412 retval = tty_check_change(tty);
1415 tty_wait_until_sent(tty, 0);
1416 rc_send_break(port, arg ? arg*(HZ/10) : HZ/4);
1419 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned __user *)argp);
1421 if (get_user(arg,(unsigned __user *) argp))
1423 tty->termios->c_cflag =
1424 ((tty->termios->c_cflag & ~CLOCAL) |
1425 (arg ? CLOCAL : 0));
1428 return rc_get_serial_info(port, argp);
1430 return rc_set_serial_info(port, argp);
1432 return -ENOIOCTLCMD;
1437 static void rc_throttle(struct tty_struct * tty)
1439 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1440 struct riscom_board *bp;
1441 unsigned long flags;
1443 if (rc_paranoia_check(port, tty->name, "rc_throttle"))
1446 bp = port_Board(port);
1448 spin_lock_irqsave(&riscom_lock, flags);
1450 port->MSVR &= ~MSVR_RTS;
1451 rc_out(bp, CD180_CAR, port_No(port));
1454 rc_out(bp, CD180_CCR, CCR_SSCH2);
1457 rc_out(bp, CD180_MSVR, port->MSVR);
1459 spin_unlock_irqrestore(&riscom_lock, flags);
1462 static void rc_unthrottle(struct tty_struct * tty)
1464 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1465 struct riscom_board *bp;
1466 unsigned long flags;
1468 if (rc_paranoia_check(port, tty->name, "rc_unthrottle"))
1471 bp = port_Board(port);
1473 spin_lock_irqsave(&riscom_lock, flags);
1475 port->MSVR |= MSVR_RTS;
1476 rc_out(bp, CD180_CAR, port_No(port));
1479 rc_out(bp, CD180_CCR, CCR_SSCH1);
1482 rc_out(bp, CD180_MSVR, port->MSVR);
1484 spin_unlock_irqrestore(&riscom_lock, flags);
1487 static void rc_stop(struct tty_struct * tty)
1489 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1490 struct riscom_board *bp;
1491 unsigned long flags;
1493 if (rc_paranoia_check(port, tty->name, "rc_stop"))
1496 bp = port_Board(port);
1498 spin_lock_irqsave(&riscom_lock, flags);
1500 port->IER &= ~IER_TXRDY;
1501 rc_out(bp, CD180_CAR, port_No(port));
1502 rc_out(bp, CD180_IER, port->IER);
1504 spin_unlock_irqrestore(&riscom_lock, 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 spin_lock_irqsave(&riscom_lock, flags);
1520 if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) {
1521 port->IER |= IER_TXRDY;
1522 rc_out(bp, CD180_CAR, port_No(port));
1523 rc_out(bp, CD180_IER, port->IER);
1526 spin_unlock_irqrestore(&riscom_lock, flags);
1530 * This routine is called from the work queue when the interrupt
1531 * routine has signalled that a hangup has occurred. The path of
1532 * hangup processing is:
1534 * serial interrupt routine -> (workqueue) ->
1535 * do_rc_hangup() -> tty->hangup() -> rc_hangup()
1538 static void do_rc_hangup(struct work_struct *ugly_api)
1540 struct riscom_port *port = container_of(ugly_api, struct riscom_port, tqueue_hangup);
1541 struct tty_struct *tty;
1545 tty_hangup(tty); /* FIXME: module removal race still here */
1548 static void rc_hangup(struct tty_struct * tty)
1550 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1551 struct riscom_board *bp;
1553 if (rc_paranoia_check(port, tty->name, "rc_hangup"))
1556 bp = port_Board(port);
1558 rc_shutdown_port(bp, port);
1561 port->flags &= ~ASYNC_NORMAL_ACTIVE;
1563 wake_up_interruptible(&port->open_wait);
1566 static void rc_set_termios(struct tty_struct * tty, struct ktermios * old_termios)
1568 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1569 unsigned long flags;
1571 if (rc_paranoia_check(port, tty->name, "rc_set_termios"))
1574 if (tty->termios->c_cflag == old_termios->c_cflag &&
1575 tty->termios->c_iflag == old_termios->c_iflag)
1578 spin_lock_irqsave(&riscom_lock, flags);
1579 rc_change_speed(port_Board(port), port);
1580 spin_unlock_irqrestore(&riscom_lock, flags);
1582 if ((old_termios->c_cflag & CRTSCTS) &&
1583 !(tty->termios->c_cflag & CRTSCTS)) {
1584 tty->hw_stopped = 0;
1589 static void do_softint(struct work_struct *ugly_api)
1591 struct riscom_port *port = container_of(ugly_api, struct riscom_port, tqueue);
1592 struct tty_struct *tty;
1594 if(!(tty = port->tty))
1597 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event))
1601 static const 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 riscom_driver->owner = THIS_MODULE;
1631 riscom_driver->name = "ttyL";
1632 riscom_driver->major = RISCOM8_NORMAL_MAJOR;
1633 riscom_driver->type = TTY_DRIVER_TYPE_SERIAL;
1634 riscom_driver->subtype = SERIAL_TYPE_NORMAL;
1635 riscom_driver->init_termios = tty_std_termios;
1636 riscom_driver->init_termios.c_cflag =
1637 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1638 riscom_driver->init_termios.c_ispeed = 9600;
1639 riscom_driver->init_termios.c_ospeed = 9600;
1640 riscom_driver->flags = TTY_DRIVER_REAL_RAW;
1641 tty_set_operations(riscom_driver, &riscom_ops);
1642 if ((error = tty_register_driver(riscom_driver))) {
1643 put_tty_driver(riscom_driver);
1644 printk(KERN_ERR "rc: Couldn't register RISCom/8 driver, "
1650 memset(rc_port, 0, sizeof(rc_port));
1651 for (i = 0; i < RC_NPORT * RC_NBOARD; i++) {
1652 rc_port[i].magic = RISCOM8_MAGIC;
1653 INIT_WORK(&rc_port[i].tqueue, do_softint);
1654 INIT_WORK(&rc_port[i].tqueue_hangup, do_rc_hangup);
1655 rc_port[i].close_delay = 50 * HZ/100;
1656 rc_port[i].closing_wait = 3000 * HZ/100;
1657 init_waitqueue_head(&rc_port[i].open_wait);
1658 init_waitqueue_head(&rc_port[i].close_wait);
1664 static void rc_release_drivers(void)
1666 unsigned long flags;
1668 spin_lock_irqsave(&riscom_lock, flags);
1670 tty_unregister_driver(riscom_driver);
1671 put_tty_driver(riscom_driver);
1673 spin_unlock_irqrestore(&riscom_lock, flags);
1678 * Called at boot time.
1680 * You can specify IO base for up to RC_NBOARD cards,
1681 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
1682 * Note that there will be no probing at default
1683 * addresses in this case.
1686 static int __init riscom8_setup(char *str)
1688 int ints[RC_NBOARD];
1691 str = get_options(str, ARRAY_SIZE(ints), ints);
1693 for (i = 0; i < RC_NBOARD; i++) {
1695 rc_board[i].base = ints[i+1];
1697 rc_board[i].base = 0;
1702 __setup("riscom8=", riscom8_setup);
1705 static char banner[] __initdata =
1706 KERN_INFO "rc: SDL RISCom/8 card driver v1.1, (c) D.Gorodchanin "
1708 static char no_boards_msg[] __initdata =
1709 KERN_INFO "rc: No RISCom/8 boards detected.\n";
1712 * This routine must be called by kernel at boot time
1714 static int __init riscom8_init(void)
1721 if (rc_init_drivers())
1724 for (i = 0; i < RC_NBOARD; i++)
1725 if (rc_board[i].base && !rc_probe(&rc_board[i]))
1729 rc_release_drivers();
1730 printk(no_boards_msg);
1741 module_param(iobase, int, 0);
1742 module_param(iobase1, int, 0);
1743 module_param(iobase2, int, 0);
1744 module_param(iobase3, int, 0);
1746 MODULE_LICENSE("GPL");
1750 * You can setup up to 4 boards (current value of RC_NBOARD)
1751 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter.
1754 static int __init riscom8_init_module (void)
1759 if (iobase || iobase1 || iobase2 || iobase3) {
1760 for(i = 0; i < RC_NBOARD; i++)
1761 rc_board[0].base = 0;
1765 rc_board[0].base = iobase;
1767 rc_board[1].base = iobase1;
1769 rc_board[2].base = iobase2;
1771 rc_board[3].base = iobase3;
1774 return riscom8_init();
1777 static void __exit riscom8_exit_module (void)
1781 rc_release_drivers();
1782 for (i = 0; i < RC_NBOARD; i++)
1783 if (rc_board[i].flags & RC_BOARD_PRESENT)
1784 rc_release_io_range(&rc_board[i]);
1788 module_init(riscom8_init_module);
1789 module_exit(riscom8_exit_module);