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;
86 static unsigned long baud_table[] = {
87 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
88 9600, 19200, 38400, 57600, 76800, 0,
91 static struct riscom_board rc_board[RC_NBOARD] = {
106 static struct riscom_port rc_port[RC_NBOARD * RC_NPORT];
108 /* RISCom/8 I/O ports addresses (without address translation) */
109 static unsigned short rc_ioport[] = {
111 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c,
113 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10,
114 0x11, 0x12, 0x18, 0x28, 0x31, 0x32, 0x39, 0x3a, 0x40, 0x41, 0x61, 0x62,
115 0x63, 0x64, 0x6b, 0x70, 0x71, 0x78, 0x7a, 0x7b, 0x7f, 0x100, 0x101
118 #define RC_NIOPORT ARRAY_SIZE(rc_ioport)
121 static inline int rc_paranoia_check(struct riscom_port const * port,
122 char *name, const char *routine)
124 #ifdef RISCOM_PARANOIA_CHECK
125 static const char badmagic[] = KERN_INFO
126 "rc: Warning: bad riscom port magic number for device %s in %s\n";
127 static const char badinfo[] = KERN_INFO
128 "rc: Warning: null riscom port for device %s in %s\n";
131 printk(badinfo, name, routine);
134 if (port->magic != RISCOM8_MAGIC) {
135 printk(badmagic, name, routine);
144 * Service functions for RISCom/8 driver.
148 /* Get board number from pointer */
149 static inline int board_No (struct riscom_board const * bp)
151 return bp - rc_board;
154 /* Get port number from pointer */
155 static inline int port_No (struct riscom_port const * port)
157 return RC_PORT(port - rc_port);
160 /* Get pointer to board from pointer to port */
161 static inline struct riscom_board * port_Board(struct riscom_port const * port)
163 return &rc_board[RC_BOARD(port - rc_port)];
166 /* Input Byte from CL CD180 register */
167 static inline unsigned char rc_in(struct riscom_board const * bp, unsigned short reg)
169 return inb(bp->base + RC_TO_ISA(reg));
172 /* Output Byte to CL CD180 register */
173 static inline void rc_out(struct riscom_board const * bp, unsigned short reg,
176 outb(val, bp->base + RC_TO_ISA(reg));
179 /* Wait for Channel Command Register ready */
180 static inline void rc_wait_CCR(struct riscom_board const * bp)
184 /* FIXME: need something more descriptive then 100000 :) */
185 for (delay = 100000; delay; delay--)
186 if (!rc_in(bp, CD180_CCR))
189 printk(KERN_INFO "rc%d: Timeout waiting for CCR.\n", board_No(bp));
193 * RISCom/8 probe functions.
196 static inline int rc_request_io_range(struct riscom_board * const bp)
200 for (i = 0; i < RC_NIOPORT; i++)
201 if (!request_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1,
207 printk(KERN_INFO "rc%d: Skipping probe at 0x%03x. IO address in use.\n",
208 board_No(bp), bp->base);
210 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
214 static inline void rc_release_io_range(struct riscom_board * const bp)
218 for (i = 0; i < RC_NIOPORT; i++)
219 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
222 /* Must be called with enabled interrupts */
223 static inline void rc_long_delay(unsigned long delay)
227 for (i = jiffies + delay; time_after(i,jiffies); ) ;
230 /* Reset and setup CD180 chip */
231 static void __init rc_init_CD180(struct riscom_board const * bp)
235 save_flags(flags); cli();
236 rc_out(bp, RC_CTOUT, 0); /* Clear timeout */
237 rc_wait_CCR(bp); /* Wait for CCR ready */
238 rc_out(bp, CD180_CCR, CCR_HARDRESET); /* Reset CD180 chip */
240 rc_long_delay(HZ/20); /* Delay 0.05 sec */
242 rc_out(bp, CD180_GIVR, RC_ID); /* Set ID for this chip */
243 rc_out(bp, CD180_GICR, 0); /* Clear all bits */
244 rc_out(bp, CD180_PILR1, RC_ACK_MINT); /* Prio for modem intr */
245 rc_out(bp, CD180_PILR2, RC_ACK_TINT); /* Prio for transmitter intr */
246 rc_out(bp, CD180_PILR3, RC_ACK_RINT); /* Prio for receiver intr */
248 /* Setting up prescaler. We need 4 ticks per 1 ms */
249 rc_out(bp, CD180_PPRH, (RC_OSCFREQ/(1000000/RISCOM_TPS)) >> 8);
250 rc_out(bp, CD180_PPRL, (RC_OSCFREQ/(1000000/RISCOM_TPS)) & 0xff);
252 restore_flags(flags);
255 /* Main probing routine, also sets irq. */
256 static int __init rc_probe(struct riscom_board *bp)
258 unsigned char val1, val2;
264 if (rc_request_io_range(bp))
267 /* Are the I/O ports here ? */
268 rc_out(bp, CD180_PPRL, 0x5a);
270 val1 = rc_in(bp, CD180_PPRL);
271 rc_out(bp, CD180_PPRL, 0xa5);
273 val2 = rc_in(bp, CD180_PPRL);
275 if ((val1 != 0x5a) || (val2 != 0xa5)) {
276 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not found.\n",
277 board_No(bp), bp->base);
281 /* It's time to find IRQ for this board */
282 for (retries = 0; retries < 5 && irqs <= 0; retries++) {
283 irqs = probe_irq_on();
284 rc_init_CD180(bp); /* Reset CD180 chip */
285 rc_out(bp, CD180_CAR, 2); /* Select port 2 */
287 rc_out(bp, CD180_CCR, CCR_TXEN); /* Enable transmitter */
288 rc_out(bp, CD180_IER, IER_TXRDY); /* Enable tx empty intr */
289 rc_long_delay(HZ/20);
290 irqs = probe_irq_off(irqs);
291 val1 = rc_in(bp, RC_BSR); /* Get Board Status reg */
292 val2 = rc_in(bp, RC_ACK_TINT); /* ACK interrupt */
293 rc_init_CD180(bp); /* Reset CD180 again */
295 if ((val1 & RC_BSR_TINT) || (val2 != (RC_ID | GIVR_IT_TX))) {
296 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not "
297 "found.\n", board_No(bp), bp->base);
303 printk(KERN_ERR "rc%d: Can't find IRQ for RISCom/8 board "
304 "at 0x%03x.\n", board_No(bp), bp->base);
308 bp->flags |= RC_BOARD_PRESENT;
310 printk(KERN_INFO "rc%d: RISCom/8 Rev. %c board detected at "
313 (rc_in(bp, CD180_GFRCR) & 0x0f) + 'A', /* Board revision */
318 rc_release_io_range(bp);
324 * Interrupt processing routines.
328 static inline void rc_mark_event(struct riscom_port * port, int event)
330 set_bit(event, &port->event);
331 schedule_work(&port->tqueue);
334 static inline struct riscom_port * rc_get_port(struct riscom_board const * bp,
335 unsigned char const * what)
337 unsigned char channel;
338 struct riscom_port * port;
340 channel = rc_in(bp, CD180_GICR) >> GICR_CHAN_OFF;
341 if (channel < CD180_NCH) {
342 port = &rc_port[board_No(bp) * RC_NPORT + channel];
343 if (port->flags & ASYNC_INITIALIZED) {
347 printk(KERN_ERR "rc%d: %s interrupt from invalid port %d\n",
348 board_No(bp), what, channel);
352 static inline void rc_receive_exc(struct riscom_board const * bp)
354 struct riscom_port *port;
355 struct tty_struct *tty;
356 unsigned char status;
357 unsigned char ch, flag;
359 if (!(port = rc_get_port(bp, "Receive")))
364 #ifdef RC_REPORT_OVERRUN
365 status = rc_in(bp, CD180_RCSR);
366 if (status & RCSR_OE)
368 status &= port->mark_mask;
370 status = rc_in(bp, CD180_RCSR) & port->mark_mask;
372 ch = rc_in(bp, CD180_RDR);
376 if (status & RCSR_TOUT) {
377 printk(KERN_WARNING "rc%d: port %d: Receiver timeout. "
378 "Hardware problems ?\n",
379 board_No(bp), port_No(port));
382 } else if (status & RCSR_BREAK) {
383 printk(KERN_INFO "rc%d: port %d: Handling break...\n",
384 board_No(bp), port_No(port));
386 if (port->flags & ASYNC_SAK)
389 } else if (status & RCSR_PE)
392 else if (status & RCSR_FE)
395 else if (status & RCSR_OE)
401 tty_insert_flip_char(tty, ch, flag);
402 tty_flip_buffer_push(tty);
405 static inline void rc_receive(struct riscom_board const * bp)
407 struct riscom_port *port;
408 struct tty_struct *tty;
411 if (!(port = rc_get_port(bp, "Receive")))
416 count = rc_in(bp, CD180_RDCR);
418 #ifdef RC_REPORT_FIFO
419 port->hits[count > 8 ? 9 : count]++;
423 if (tty_buffer_request_room(tty, 1) == 0) {
424 printk(KERN_WARNING "rc%d: port %d: Working around "
425 "flip buffer overflow.\n",
426 board_No(bp), port_No(port));
429 tty_insert_flip_char(tty, rc_in(bp, CD180_RDR), TTY_NORMAL);
431 tty_flip_buffer_push(tty);
434 static inline void rc_transmit(struct riscom_board const * bp)
436 struct riscom_port *port;
437 struct tty_struct *tty;
441 if (!(port = rc_get_port(bp, "Transmit")))
446 if (port->IER & IER_TXEMPTY) {
448 rc_out(bp, CD180_CAR, port_No(port));
449 port->IER &= ~IER_TXEMPTY;
450 rc_out(bp, CD180_IER, port->IER);
454 if ((port->xmit_cnt <= 0 && !port->break_length)
455 || tty->stopped || tty->hw_stopped) {
456 rc_out(bp, CD180_CAR, port_No(port));
457 port->IER &= ~IER_TXRDY;
458 rc_out(bp, CD180_IER, port->IER);
462 if (port->break_length) {
463 if (port->break_length > 0) {
464 if (port->COR2 & COR2_ETC) {
465 rc_out(bp, CD180_TDR, CD180_C_ESC);
466 rc_out(bp, CD180_TDR, CD180_C_SBRK);
467 port->COR2 &= ~COR2_ETC;
469 count = min_t(int, port->break_length, 0xff);
470 rc_out(bp, CD180_TDR, CD180_C_ESC);
471 rc_out(bp, CD180_TDR, CD180_C_DELAY);
472 rc_out(bp, CD180_TDR, count);
473 if (!(port->break_length -= count))
474 port->break_length--;
476 rc_out(bp, CD180_TDR, CD180_C_ESC);
477 rc_out(bp, CD180_TDR, CD180_C_EBRK);
478 rc_out(bp, CD180_COR2, port->COR2);
480 rc_out(bp, CD180_CCR, CCR_CORCHG2);
481 port->break_length = 0;
488 rc_out(bp, CD180_TDR, port->xmit_buf[port->xmit_tail++]);
489 port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1);
490 if (--port->xmit_cnt <= 0)
492 } while (--count > 0);
494 if (port->xmit_cnt <= 0) {
495 rc_out(bp, CD180_CAR, port_No(port));
496 port->IER &= ~IER_TXRDY;
497 rc_out(bp, CD180_IER, port->IER);
499 if (port->xmit_cnt <= port->wakeup_chars)
500 rc_mark_event(port, RS_EVENT_WRITE_WAKEUP);
503 static inline void rc_check_modem(struct riscom_board const * bp)
505 struct riscom_port *port;
506 struct tty_struct *tty;
509 if (!(port = rc_get_port(bp, "Modem")))
514 mcr = rc_in(bp, CD180_MCR);
515 if (mcr & MCR_CDCHG) {
516 if (rc_in(bp, CD180_MSVR) & MSVR_CD)
517 wake_up_interruptible(&port->open_wait);
519 schedule_work(&port->tqueue_hangup);
522 #ifdef RISCOM_BRAIN_DAMAGED_CTS
523 if (mcr & MCR_CTSCHG) {
524 if (rc_in(bp, CD180_MSVR) & MSVR_CTS) {
526 port->IER |= IER_TXRDY;
527 if (port->xmit_cnt <= port->wakeup_chars)
528 rc_mark_event(port, RS_EVENT_WRITE_WAKEUP);
531 port->IER &= ~IER_TXRDY;
533 rc_out(bp, CD180_IER, port->IER);
535 if (mcr & MCR_DSRCHG) {
536 if (rc_in(bp, CD180_MSVR) & MSVR_DSR) {
538 port->IER |= IER_TXRDY;
539 if (port->xmit_cnt <= port->wakeup_chars)
540 rc_mark_event(port, RS_EVENT_WRITE_WAKEUP);
543 port->IER &= ~IER_TXRDY;
545 rc_out(bp, CD180_IER, port->IER);
547 #endif /* RISCOM_BRAIN_DAMAGED_CTS */
549 /* Clear change bits */
550 rc_out(bp, CD180_MCR, 0);
553 /* The main interrupt processing routine */
554 static irqreturn_t rc_interrupt(int irq, void * dev_id, struct pt_regs * regs)
556 unsigned char status;
558 struct riscom_board *bp;
559 unsigned long loop = 0;
562 bp = IRQ_to_board[irq];
564 if (!bp || !(bp->flags & RC_BOARD_ACTIVE)) {
568 while ((++loop < 16) && ((status = ~(rc_in(bp, RC_BSR))) &
569 (RC_BSR_TOUT | RC_BSR_TINT |
570 RC_BSR_MINT | RC_BSR_RINT))) {
572 if (status & RC_BSR_TOUT)
573 printk(KERN_WARNING "rc%d: Got timeout. Hardware "
574 "error?\n", board_No(bp));
576 else if (status & RC_BSR_RINT) {
577 ack = rc_in(bp, RC_ACK_RINT);
579 if (ack == (RC_ID | GIVR_IT_RCV))
581 else if (ack == (RC_ID | GIVR_IT_REXC))
584 printk(KERN_WARNING "rc%d: Bad receive ack "
588 } else if (status & RC_BSR_TINT) {
589 ack = rc_in(bp, RC_ACK_TINT);
591 if (ack == (RC_ID | GIVR_IT_TX))
594 printk(KERN_WARNING "rc%d: Bad transmit ack "
598 } else /* if (status & RC_BSR_MINT) */ {
599 ack = rc_in(bp, RC_ACK_MINT);
601 if (ack == (RC_ID | GIVR_IT_MODEM))
604 printk(KERN_WARNING "rc%d: Bad modem ack "
610 rc_out(bp, CD180_EOIR, 0); /* Mark end of interrupt */
611 rc_out(bp, RC_CTOUT, 0); /* Clear timeout flag */
613 return IRQ_RETVAL(handled);
617 * Routines for open & close processing.
620 /* Called with disabled interrupts */
621 static inline int rc_setup_board(struct riscom_board * bp)
625 if (bp->flags & RC_BOARD_ACTIVE)
628 error = request_irq(bp->irq, rc_interrupt, SA_INTERRUPT,
633 rc_out(bp, RC_CTOUT, 0); /* Just in case */
635 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */
637 IRQ_to_board[bp->irq] = bp;
638 bp->flags |= RC_BOARD_ACTIVE;
643 /* Called with disabled interrupts */
644 static inline void rc_shutdown_board(struct riscom_board *bp)
646 if (!(bp->flags & RC_BOARD_ACTIVE))
649 bp->flags &= ~RC_BOARD_ACTIVE;
651 free_irq(bp->irq, NULL);
652 IRQ_to_board[bp->irq] = NULL;
655 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */
660 * Setting up port characteristics.
661 * Must be called with disabled interrupts
663 static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
665 struct tty_struct *tty;
668 unsigned char cor1 = 0, cor3 = 0;
669 unsigned char mcor1 = 0, mcor2 = 0;
671 if (!(tty = port->tty) || !tty->termios)
676 port->MSVR = MSVR_RTS;
680 if (baud & CBAUDEX) {
682 if (baud < 1 || baud > 2)
683 port->tty->termios->c_cflag &= ~CBAUDEX;
688 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
690 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
694 /* Select port on the board */
695 rc_out(bp, CD180_CAR, port_No(port));
697 if (!baud_table[baud]) {
698 /* Drop DTR & exit */
699 bp->DTR |= (1u << port_No(port));
700 rc_out(bp, RC_DTR, bp->DTR);
704 bp->DTR &= ~(1u << port_No(port));
705 rc_out(bp, RC_DTR, bp->DTR);
709 * Now we must calculate some speed depended things
712 /* Set baud rate for port */
713 tmp = (((RC_OSCFREQ + baud_table[baud]/2) / baud_table[baud] +
714 CD180_TPC/2) / CD180_TPC);
716 rc_out(bp, CD180_RBPRH, (tmp >> 8) & 0xff);
717 rc_out(bp, CD180_TBPRH, (tmp >> 8) & 0xff);
718 rc_out(bp, CD180_RBPRL, tmp & 0xff);
719 rc_out(bp, CD180_TBPRL, tmp & 0xff);
721 baud = (baud_table[baud] + 5) / 10; /* Estimated CPS */
723 /* Two timer ticks seems enough to wakeup something like SLIP driver */
724 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;
725 port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
726 SERIAL_XMIT_SIZE - 1 : tmp);
728 /* Receiver timeout will be transmission time for 1.5 chars */
729 tmp = (RISCOM_TPS + RISCOM_TPS/2 + baud/2) / baud;
730 tmp = (tmp > 0xff) ? 0xff : tmp;
731 rc_out(bp, CD180_RTPR, tmp);
733 switch (C_CSIZE(tty)) {
753 cor1 |= COR1_NORMPAR;
757 cor1 &= ~COR1_IGNORE;
759 /* Set marking of some errors */
760 port->mark_mask = RCSR_OE | RCSR_TOUT;
762 port->mark_mask |= RCSR_FE | RCSR_PE;
763 if (I_BRKINT(tty) || I_PARMRK(tty))
764 port->mark_mask |= RCSR_BREAK;
766 port->mark_mask &= ~(RCSR_FE | RCSR_PE);
768 port->mark_mask &= ~RCSR_BREAK;
770 /* Real raw mode. Ignore all */
771 port->mark_mask &= ~RCSR_OE;
773 /* Enable Hardware Flow Control */
774 if (C_CRTSCTS(tty)) {
775 #ifdef RISCOM_BRAIN_DAMAGED_CTS
776 port->IER |= IER_DSR | IER_CTS;
777 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
778 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
779 tty->hw_stopped = !(rc_in(bp, CD180_MSVR) & (MSVR_CTS|MSVR_DSR));
781 port->COR2 |= COR2_CTSAE;
784 /* Enable Software Flow Control. FIXME: I'm not sure about this */
785 /* Some people reported that it works, but I still doubt */
787 port->COR2 |= COR2_TXIBE;
788 cor3 |= (COR3_FCT | COR3_SCDE);
790 port->COR2 |= COR2_IXM;
791 rc_out(bp, CD180_SCHR1, START_CHAR(tty));
792 rc_out(bp, CD180_SCHR2, STOP_CHAR(tty));
793 rc_out(bp, CD180_SCHR3, START_CHAR(tty));
794 rc_out(bp, CD180_SCHR4, STOP_CHAR(tty));
796 if (!C_CLOCAL(tty)) {
797 /* Enable CD check */
804 /* Enable receiver */
805 port->IER |= IER_RXD;
807 /* Set input FIFO size (1-8 bytes) */
808 cor3 |= RISCOM_RXFIFO;
809 /* Setting up CD180 channel registers */
810 rc_out(bp, CD180_COR1, cor1);
811 rc_out(bp, CD180_COR2, port->COR2);
812 rc_out(bp, CD180_COR3, cor3);
813 /* Make CD180 know about registers change */
815 rc_out(bp, CD180_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3);
816 /* Setting up modem option registers */
817 rc_out(bp, CD180_MCOR1, mcor1);
818 rc_out(bp, CD180_MCOR2, mcor2);
819 /* Enable CD180 transmitter & receiver */
821 rc_out(bp, CD180_CCR, CCR_TXEN | CCR_RXEN);
822 /* Enable interrupts */
823 rc_out(bp, CD180_IER, port->IER);
824 /* And finally set RTS on */
825 rc_out(bp, CD180_MSVR, port->MSVR);
828 /* Must be called with interrupts enabled */
829 static int rc_setup_port(struct riscom_board *bp, struct riscom_port *port)
833 if (port->flags & ASYNC_INITIALIZED)
836 if (!port->xmit_buf) {
837 /* We may sleep in get_zeroed_page() */
840 if (!(tmp = get_zeroed_page(GFP_KERNEL)))
843 if (port->xmit_buf) {
847 port->xmit_buf = (unsigned char *) tmp;
850 save_flags(flags); cli();
853 clear_bit(TTY_IO_ERROR, &port->tty->flags);
855 if (port->count == 1)
858 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
859 rc_change_speed(bp, port);
860 port->flags |= ASYNC_INITIALIZED;
862 restore_flags(flags);
866 /* Must be called with interrupts disabled */
867 static void rc_shutdown_port(struct riscom_board *bp, struct riscom_port *port)
869 struct tty_struct *tty;
871 if (!(port->flags & ASYNC_INITIALIZED))
874 #ifdef RC_REPORT_OVERRUN
875 printk(KERN_INFO "rc%d: port %d: Total %ld overruns were detected.\n",
876 board_No(bp), port_No(port), port->overrun);
878 #ifdef RC_REPORT_FIFO
882 printk(KERN_INFO "rc%d: port %d: FIFO hits [ ",
883 board_No(bp), port_No(port));
884 for (i = 0; i < 10; i++) {
885 printk("%ld ", port->hits[i]);
890 if (port->xmit_buf) {
891 free_page((unsigned long) port->xmit_buf);
892 port->xmit_buf = NULL;
895 if (!(tty = port->tty) || C_HUPCL(tty)) {
897 bp->DTR |= (1u << port_No(port));
898 rc_out(bp, RC_DTR, bp->DTR);
902 rc_out(bp, CD180_CAR, port_No(port));
905 rc_out(bp, CD180_CCR, CCR_SOFTRESET);
906 /* Disable all interrupts from this port */
908 rc_out(bp, CD180_IER, port->IER);
911 set_bit(TTY_IO_ERROR, &tty->flags);
912 port->flags &= ~ASYNC_INITIALIZED;
914 if (--bp->count < 0) {
915 printk(KERN_INFO "rc%d: rc_shutdown_port: "
916 "bad board count: %d\n",
917 board_No(bp), bp->count);
922 * If this is the last opened port on the board
923 * shutdown whole board
926 rc_shutdown_board(bp);
930 static int block_til_ready(struct tty_struct *tty, struct file * filp,
931 struct riscom_port *port)
933 DECLARE_WAITQUEUE(wait, current);
934 struct riscom_board *bp = port_Board(port);
940 * If the device is in the middle of being closed, then block
941 * until it's done, and then try again.
943 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
944 interruptible_sleep_on(&port->close_wait);
945 if (port->flags & ASYNC_HUP_NOTIFY)
952 * If non-blocking mode is set, or the port is not enabled,
953 * then make the check up front and then exit.
955 if ((filp->f_flags & O_NONBLOCK) ||
956 (tty->flags & (1 << TTY_IO_ERROR))) {
957 port->flags |= ASYNC_NORMAL_ACTIVE;
965 * Block waiting for the carrier detect and the line to become
966 * free (i.e., not in use by the callout). While we are in
967 * this loop, info->count is dropped by one, so that
968 * rs_close() knows when to free things. We restore it upon
969 * exit, either normal or abnormal.
972 add_wait_queue(&port->open_wait, &wait);
974 if (!tty_hung_up_p(filp))
977 port->blocked_open++;
980 rc_out(bp, CD180_CAR, port_No(port));
981 CD = rc_in(bp, CD180_MSVR) & MSVR_CD;
982 rc_out(bp, CD180_MSVR, MSVR_RTS);
983 bp->DTR &= ~(1u << port_No(port));
984 rc_out(bp, RC_DTR, bp->DTR);
986 set_current_state(TASK_INTERRUPTIBLE);
987 if (tty_hung_up_p(filp) ||
988 !(port->flags & ASYNC_INITIALIZED)) {
989 if (port->flags & ASYNC_HUP_NOTIFY)
992 retval = -ERESTARTSYS;
995 if (!(port->flags & ASYNC_CLOSING) &&
998 if (signal_pending(current)) {
999 retval = -ERESTARTSYS;
1004 current->state = TASK_RUNNING;
1005 remove_wait_queue(&port->open_wait, &wait);
1006 if (!tty_hung_up_p(filp))
1008 port->blocked_open--;
1012 port->flags |= ASYNC_NORMAL_ACTIVE;
1016 static int rc_open(struct tty_struct * tty, struct file * filp)
1020 struct riscom_port * port;
1021 struct riscom_board * bp;
1023 board = RC_BOARD(tty->index);
1024 if (board >= RC_NBOARD || !(rc_board[board].flags & RC_BOARD_PRESENT))
1027 bp = &rc_board[board];
1028 port = rc_port + board * RC_NPORT + RC_PORT(tty->index);
1029 if (rc_paranoia_check(port, tty->name, "rc_open"))
1032 if ((error = rc_setup_board(bp)))
1036 tty->driver_data = port;
1039 if ((error = rc_setup_port(bp, port)))
1042 if ((error = block_til_ready(tty, filp, port)))
1048 static void rc_close(struct tty_struct * tty, struct file * filp)
1050 struct riscom_port *port = (struct riscom_port *) tty->driver_data;
1051 struct riscom_board *bp;
1052 unsigned long flags;
1053 unsigned long timeout;
1055 if (!port || rc_paranoia_check(port, tty->name, "close"))
1058 save_flags(flags); cli();
1059 if (tty_hung_up_p(filp))
1062 bp = port_Board(port);
1063 if ((tty->count == 1) && (port->count != 1)) {
1064 printk(KERN_INFO "rc%d: rc_close: bad port count;"
1065 " tty->count is 1, port count is %d\n",
1066 board_No(bp), port->count);
1069 if (--port->count < 0) {
1070 printk(KERN_INFO "rc%d: rc_close: bad port count "
1072 board_No(bp), port_No(port), port->count);
1077 port->flags |= ASYNC_CLOSING;
1079 * Now we wait for the transmit buffer to clear; and we notify
1080 * the line discipline to only process XON/XOFF characters.
1083 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1084 tty_wait_until_sent(tty, port->closing_wait);
1086 * At this point we stop accepting input. To do this, we
1087 * disable the receive line status interrupts, and tell the
1088 * interrupt driver to stop checking the data ready bit in the
1089 * line status register.
1091 port->IER &= ~IER_RXD;
1092 if (port->flags & ASYNC_INITIALIZED) {
1093 port->IER &= ~IER_TXRDY;
1094 port->IER |= IER_TXEMPTY;
1095 rc_out(bp, CD180_CAR, port_No(port));
1096 rc_out(bp, CD180_IER, port->IER);
1098 * Before we drop DTR, make sure the UART transmitter
1099 * has completely drained; this is especially
1100 * important if there is a transmit FIFO!
1102 timeout = jiffies+HZ;
1103 while(port->IER & IER_TXEMPTY) {
1104 msleep_interruptible(jiffies_to_msecs(port->timeout));
1105 if (time_after(jiffies, timeout))
1109 rc_shutdown_port(bp, port);
1110 if (tty->driver->flush_buffer)
1111 tty->driver->flush_buffer(tty);
1112 tty_ldisc_flush(tty);
1117 if (port->blocked_open) {
1118 if (port->close_delay) {
1119 msleep_interruptible(jiffies_to_msecs(port->close_delay));
1121 wake_up_interruptible(&port->open_wait);
1123 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1124 wake_up_interruptible(&port->close_wait);
1125 out: restore_flags(flags);
1128 static int rc_write(struct tty_struct * tty,
1129 const unsigned char *buf, int count)
1131 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1132 struct riscom_board *bp;
1134 unsigned long flags;
1136 if (rc_paranoia_check(port, tty->name, "rc_write"))
1139 bp = port_Board(port);
1141 if (!tty || !port->xmit_buf || !tmp_buf)
1147 c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1148 SERIAL_XMIT_SIZE - port->xmit_head));
1150 restore_flags(flags);
1154 memcpy(port->xmit_buf + port->xmit_head, buf, c);
1155 port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1156 port->xmit_cnt += c;
1157 restore_flags(flags);
1165 if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1166 !(port->IER & IER_TXRDY)) {
1167 port->IER |= IER_TXRDY;
1168 rc_out(bp, CD180_CAR, port_No(port));
1169 rc_out(bp, CD180_IER, port->IER);
1171 restore_flags(flags);
1176 static void rc_put_char(struct tty_struct * tty, unsigned char ch)
1178 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1179 unsigned long flags;
1181 if (rc_paranoia_check(port, tty->name, "rc_put_char"))
1184 if (!tty || !port->xmit_buf)
1187 save_flags(flags); cli();
1189 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1192 port->xmit_buf[port->xmit_head++] = ch;
1193 port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1195 out: restore_flags(flags);
1198 static void rc_flush_chars(struct tty_struct * tty)
1200 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1201 unsigned long flags;
1203 if (rc_paranoia_check(port, tty->name, "rc_flush_chars"))
1206 if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1210 save_flags(flags); cli();
1211 port->IER |= IER_TXRDY;
1212 rc_out(port_Board(port), CD180_CAR, port_No(port));
1213 rc_out(port_Board(port), CD180_IER, port->IER);
1214 restore_flags(flags);
1217 static int rc_write_room(struct tty_struct * tty)
1219 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1222 if (rc_paranoia_check(port, tty->name, "rc_write_room"))
1225 ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
1231 static int rc_chars_in_buffer(struct tty_struct *tty)
1233 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1235 if (rc_paranoia_check(port, tty->name, "rc_chars_in_buffer"))
1238 return port->xmit_cnt;
1241 static void rc_flush_buffer(struct tty_struct *tty)
1243 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1244 unsigned long flags;
1246 if (rc_paranoia_check(port, tty->name, "rc_flush_buffer"))
1249 save_flags(flags); cli();
1250 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1251 restore_flags(flags);
1253 wake_up_interruptible(&tty->write_wait);
1257 static int rc_tiocmget(struct tty_struct *tty, struct file *file)
1259 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1260 struct riscom_board * bp;
1261 unsigned char status;
1262 unsigned int result;
1263 unsigned long flags;
1265 if (rc_paranoia_check(port, tty->name, __FUNCTION__))
1268 bp = port_Board(port);
1269 save_flags(flags); cli();
1270 rc_out(bp, CD180_CAR, port_No(port));
1271 status = rc_in(bp, CD180_MSVR);
1272 result = rc_in(bp, RC_RI) & (1u << port_No(port)) ? 0 : TIOCM_RNG;
1273 restore_flags(flags);
1274 result |= ((status & MSVR_RTS) ? TIOCM_RTS : 0)
1275 | ((status & MSVR_DTR) ? TIOCM_DTR : 0)
1276 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1277 | ((status & MSVR_DSR) ? TIOCM_DSR : 0)
1278 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1282 static int rc_tiocmset(struct tty_struct *tty, struct file *file,
1283 unsigned int set, unsigned int clear)
1285 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1286 unsigned long flags;
1287 struct riscom_board *bp;
1289 if (rc_paranoia_check(port, tty->name, __FUNCTION__))
1292 bp = port_Board(port);
1294 save_flags(flags); cli();
1295 if (set & TIOCM_RTS)
1296 port->MSVR |= MSVR_RTS;
1297 if (set & TIOCM_DTR)
1298 bp->DTR &= ~(1u << port_No(port));
1300 if (clear & TIOCM_RTS)
1301 port->MSVR &= ~MSVR_RTS;
1302 if (clear & TIOCM_DTR)
1303 bp->DTR |= (1u << port_No(port));
1305 rc_out(bp, CD180_CAR, port_No(port));
1306 rc_out(bp, CD180_MSVR, port->MSVR);
1307 rc_out(bp, RC_DTR, bp->DTR);
1308 restore_flags(flags);
1312 static inline void rc_send_break(struct riscom_port * port, unsigned long length)
1314 struct riscom_board *bp = port_Board(port);
1315 unsigned long flags;
1317 save_flags(flags); cli();
1318 port->break_length = RISCOM_TPS / HZ * length;
1319 port->COR2 |= COR2_ETC;
1320 port->IER |= IER_TXRDY;
1321 rc_out(bp, CD180_CAR, port_No(port));
1322 rc_out(bp, CD180_COR2, port->COR2);
1323 rc_out(bp, CD180_IER, port->IER);
1325 rc_out(bp, CD180_CCR, CCR_CORCHG2);
1327 restore_flags(flags);
1330 static inline int rc_set_serial_info(struct riscom_port * port,
1331 struct serial_struct __user * newinfo)
1333 struct serial_struct tmp;
1334 struct riscom_board *bp = port_Board(port);
1336 unsigned long flags;
1338 if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
1342 if ((tmp.irq != bp->irq) ||
1343 (tmp.port != bp->base) ||
1344 (tmp.type != PORT_CIRRUS) ||
1345 (tmp.baud_base != (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC) ||
1346 (tmp.custom_divisor != 0) ||
1347 (tmp.xmit_fifo_size != CD180_NFIFO) ||
1348 (tmp.flags & ~RISCOM_LEGAL_FLAGS))
1352 change_speed = ((port->flags & ASYNC_SPD_MASK) !=
1353 (tmp.flags & ASYNC_SPD_MASK));
1355 if (!capable(CAP_SYS_ADMIN)) {
1356 if ((tmp.close_delay != port->close_delay) ||
1357 (tmp.closing_wait != port->closing_wait) ||
1358 ((tmp.flags & ~ASYNC_USR_MASK) !=
1359 (port->flags & ~ASYNC_USR_MASK)))
1361 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
1362 (tmp.flags & ASYNC_USR_MASK));
1364 port->flags = ((port->flags & ~ASYNC_FLAGS) |
1365 (tmp.flags & ASYNC_FLAGS));
1366 port->close_delay = tmp.close_delay;
1367 port->closing_wait = tmp.closing_wait;
1370 save_flags(flags); cli();
1371 rc_change_speed(bp, port);
1372 restore_flags(flags);
1377 static inline int rc_get_serial_info(struct riscom_port * port,
1378 struct serial_struct __user *retinfo)
1380 struct serial_struct tmp;
1381 struct riscom_board *bp = port_Board(port);
1383 memset(&tmp, 0, sizeof(tmp));
1384 tmp.type = PORT_CIRRUS;
1385 tmp.line = port - rc_port;
1386 tmp.port = bp->base;
1388 tmp.flags = port->flags;
1389 tmp.baud_base = (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC;
1390 tmp.close_delay = port->close_delay * HZ/100;
1391 tmp.closing_wait = port->closing_wait * HZ/100;
1392 tmp.xmit_fifo_size = CD180_NFIFO;
1393 return copy_to_user(retinfo, &tmp, sizeof(tmp)) ? -EFAULT : 0;
1396 static int rc_ioctl(struct tty_struct * tty, struct file * filp,
1397 unsigned int cmd, unsigned long arg)
1400 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1401 void __user *argp = (void __user *)arg;
1404 if (rc_paranoia_check(port, tty->name, "rc_ioctl"))
1408 case TCSBRK: /* SVID version: non-zero arg --> no break */
1409 retval = tty_check_change(tty);
1412 tty_wait_until_sent(tty, 0);
1414 rc_send_break(port, HZ/4); /* 1/4 second */
1416 case TCSBRKP: /* support for POSIX tcsendbreak() */
1417 retval = tty_check_change(tty);
1420 tty_wait_until_sent(tty, 0);
1421 rc_send_break(port, arg ? arg*(HZ/10) : HZ/4);
1424 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned __user *)argp);
1426 if (get_user(arg,(unsigned __user *) argp))
1428 tty->termios->c_cflag =
1429 ((tty->termios->c_cflag & ~CLOCAL) |
1430 (arg ? CLOCAL : 0));
1433 return rc_get_serial_info(port, argp);
1435 return rc_set_serial_info(port, argp);
1437 return -ENOIOCTLCMD;
1442 static void rc_throttle(struct tty_struct * tty)
1444 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1445 struct riscom_board *bp;
1446 unsigned long flags;
1448 if (rc_paranoia_check(port, tty->name, "rc_throttle"))
1451 bp = port_Board(port);
1453 save_flags(flags); cli();
1454 port->MSVR &= ~MSVR_RTS;
1455 rc_out(bp, CD180_CAR, port_No(port));
1458 rc_out(bp, CD180_CCR, CCR_SSCH2);
1461 rc_out(bp, CD180_MSVR, port->MSVR);
1462 restore_flags(flags);
1465 static void rc_unthrottle(struct tty_struct * tty)
1467 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1468 struct riscom_board *bp;
1469 unsigned long flags;
1471 if (rc_paranoia_check(port, tty->name, "rc_unthrottle"))
1474 bp = port_Board(port);
1476 save_flags(flags); cli();
1477 port->MSVR |= MSVR_RTS;
1478 rc_out(bp, CD180_CAR, port_No(port));
1481 rc_out(bp, CD180_CCR, CCR_SSCH1);
1484 rc_out(bp, CD180_MSVR, port->MSVR);
1485 restore_flags(flags);
1488 static void rc_stop(struct tty_struct * tty)
1490 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1491 struct riscom_board *bp;
1492 unsigned long flags;
1494 if (rc_paranoia_check(port, tty->name, "rc_stop"))
1497 bp = port_Board(port);
1499 save_flags(flags); cli();
1500 port->IER &= ~IER_TXRDY;
1501 rc_out(bp, CD180_CAR, port_No(port));
1502 rc_out(bp, CD180_IER, port->IER);
1503 restore_flags(flags);
1506 static void rc_start(struct tty_struct * tty)
1508 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1509 struct riscom_board *bp;
1510 unsigned long flags;
1512 if (rc_paranoia_check(port, tty->name, "rc_start"))
1515 bp = port_Board(port);
1517 save_flags(flags); cli();
1518 if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) {
1519 port->IER |= IER_TXRDY;
1520 rc_out(bp, CD180_CAR, port_No(port));
1521 rc_out(bp, CD180_IER, port->IER);
1523 restore_flags(flags);
1527 * This routine is called from the work queue when the interrupt
1528 * routine has signalled that a hangup has occurred. The path of
1529 * hangup processing is:
1531 * serial interrupt routine -> (workqueue) ->
1532 * do_rc_hangup() -> tty->hangup() -> rc_hangup()
1535 static void do_rc_hangup(void *private_)
1537 struct riscom_port *port = (struct riscom_port *) private_;
1538 struct tty_struct *tty;
1542 tty_hangup(tty); /* FIXME: module removal race still here */
1545 static void rc_hangup(struct tty_struct * tty)
1547 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1548 struct riscom_board *bp;
1550 if (rc_paranoia_check(port, tty->name, "rc_hangup"))
1553 bp = port_Board(port);
1555 rc_shutdown_port(bp, port);
1558 port->flags &= ~ASYNC_NORMAL_ACTIVE;
1560 wake_up_interruptible(&port->open_wait);
1563 static void rc_set_termios(struct tty_struct * tty, struct termios * old_termios)
1565 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1566 unsigned long flags;
1568 if (rc_paranoia_check(port, tty->name, "rc_set_termios"))
1571 if (tty->termios->c_cflag == old_termios->c_cflag &&
1572 tty->termios->c_iflag == old_termios->c_iflag)
1575 save_flags(flags); cli();
1576 rc_change_speed(port_Board(port), port);
1577 restore_flags(flags);
1579 if ((old_termios->c_cflag & CRTSCTS) &&
1580 !(tty->termios->c_cflag & CRTSCTS)) {
1581 tty->hw_stopped = 0;
1586 static void do_softint(void *private_)
1588 struct riscom_port *port = (struct riscom_port *) private_;
1589 struct tty_struct *tty;
1591 if(!(tty = port->tty))
1594 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) {
1596 wake_up_interruptible(&tty->write_wait);
1600 static struct tty_operations riscom_ops = {
1604 .put_char = rc_put_char,
1605 .flush_chars = rc_flush_chars,
1606 .write_room = rc_write_room,
1607 .chars_in_buffer = rc_chars_in_buffer,
1608 .flush_buffer = rc_flush_buffer,
1610 .throttle = rc_throttle,
1611 .unthrottle = rc_unthrottle,
1612 .set_termios = rc_set_termios,
1615 .hangup = rc_hangup,
1616 .tiocmget = rc_tiocmget,
1617 .tiocmset = rc_tiocmset,
1620 static inline int rc_init_drivers(void)
1625 riscom_driver = alloc_tty_driver(RC_NBOARD * RC_NPORT);
1629 if (!(tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL))) {
1630 printk(KERN_ERR "rc: Couldn't get free page.\n");
1631 put_tty_driver(riscom_driver);
1634 memset(IRQ_to_board, 0, sizeof(IRQ_to_board));
1635 riscom_driver->owner = THIS_MODULE;
1636 riscom_driver->name = "ttyL";
1637 riscom_driver->devfs_name = "tts/L";
1638 riscom_driver->major = RISCOM8_NORMAL_MAJOR;
1639 riscom_driver->type = TTY_DRIVER_TYPE_SERIAL;
1640 riscom_driver->subtype = SERIAL_TYPE_NORMAL;
1641 riscom_driver->init_termios = tty_std_termios;
1642 riscom_driver->init_termios.c_cflag =
1643 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1644 riscom_driver->flags = TTY_DRIVER_REAL_RAW;
1645 tty_set_operations(riscom_driver, &riscom_ops);
1646 if ((error = tty_register_driver(riscom_driver))) {
1647 free_page((unsigned long)tmp_buf);
1648 put_tty_driver(riscom_driver);
1649 printk(KERN_ERR "rc: Couldn't register RISCom/8 driver, "
1655 memset(rc_port, 0, sizeof(rc_port));
1656 for (i = 0; i < RC_NPORT * RC_NBOARD; i++) {
1657 rc_port[i].magic = RISCOM8_MAGIC;
1658 INIT_WORK(&rc_port[i].tqueue, do_softint, &rc_port[i]);
1659 INIT_WORK(&rc_port[i].tqueue_hangup, do_rc_hangup, &rc_port[i]);
1660 rc_port[i].close_delay = 50 * HZ/100;
1661 rc_port[i].closing_wait = 3000 * HZ/100;
1662 init_waitqueue_head(&rc_port[i].open_wait);
1663 init_waitqueue_head(&rc_port[i].close_wait);
1669 static void rc_release_drivers(void)
1671 unsigned long flags;
1675 free_page((unsigned long)tmp_buf);
1676 tty_unregister_driver(riscom_driver);
1677 put_tty_driver(riscom_driver);
1678 restore_flags(flags);
1683 * Called at boot time.
1685 * You can specify IO base for up to RC_NBOARD cards,
1686 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
1687 * Note that there will be no probing at default
1688 * addresses in this case.
1691 static int __init riscom8_setup(char *str)
1693 int ints[RC_NBOARD];
1696 str = get_options(str, ARRAY_SIZE(ints), ints);
1698 for (i = 0; i < RC_NBOARD; i++) {
1700 rc_board[i].base = ints[i+1];
1702 rc_board[i].base = 0;
1707 __setup("riscom8=", riscom8_setup);
1710 static char banner[] __initdata =
1711 KERN_INFO "rc: SDL RISCom/8 card driver v1.1, (c) D.Gorodchanin "
1713 static char no_boards_msg[] __initdata =
1714 KERN_INFO "rc: No RISCom/8 boards detected.\n";
1717 * This routine must be called by kernel at boot time
1719 static int __init riscom8_init(void)
1726 if (rc_init_drivers())
1729 for (i = 0; i < RC_NBOARD; i++)
1730 if (rc_board[i].base && !rc_probe(&rc_board[i]))
1734 rc_release_drivers();
1735 printk(no_boards_msg);
1746 MODULE_PARM(iobase, "i");
1747 MODULE_PARM(iobase1, "i");
1748 MODULE_PARM(iobase2, "i");
1749 MODULE_PARM(iobase3, "i");
1751 MODULE_LICENSE("GPL");
1755 * You can setup up to 4 boards (current value of RC_NBOARD)
1756 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter.
1759 static int __init riscom8_init_module (void)
1764 if (iobase || iobase1 || iobase2 || iobase3) {
1765 for(i = 0; i < RC_NBOARD; i++)
1766 rc_board[0].base = 0;
1770 rc_board[0].base = iobase;
1772 rc_board[1].base = iobase1;
1774 rc_board[2].base = iobase2;
1776 rc_board[3].base = iobase3;
1779 return riscom8_init();
1782 static void __exit riscom8_exit_module (void)
1786 rc_release_drivers();
1787 for (i = 0; i < RC_NBOARD; i++)
1788 if (rc_board[i].flags & RC_BOARD_PRESENT)
1789 rc_release_io_range(&rc_board[i]);
1793 module_init(riscom8_init_module);
1794 module_exit(riscom8_exit_module);