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;
85 static unsigned long baud_table[] = {
86 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
87 9600, 19200, 38400, 57600, 76800, 0,
90 static struct riscom_board rc_board[RC_NBOARD] = {
105 static struct riscom_port rc_port[RC_NBOARD * RC_NPORT];
107 /* RISCom/8 I/O ports addresses (without address translation) */
108 static unsigned short rc_ioport[] = {
110 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c,
112 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10,
113 0x11, 0x12, 0x18, 0x28, 0x31, 0x32, 0x39, 0x3a, 0x40, 0x41, 0x61, 0x62,
114 0x63, 0x64, 0x6b, 0x70, 0x71, 0x78, 0x7a, 0x7b, 0x7f, 0x100, 0x101
117 #define RC_NIOPORT ARRAY_SIZE(rc_ioport)
120 static inline int rc_paranoia_check(struct riscom_port const * port,
121 char *name, const char *routine)
123 #ifdef RISCOM_PARANOIA_CHECK
124 static const char badmagic[] = KERN_INFO
125 "rc: Warning: bad riscom port magic number for device %s in %s\n";
126 static const char badinfo[] = KERN_INFO
127 "rc: Warning: null riscom port for device %s in %s\n";
130 printk(badinfo, name, routine);
133 if (port->magic != RISCOM8_MAGIC) {
134 printk(badmagic, name, routine);
143 * Service functions for RISCom/8 driver.
147 /* Get board number from pointer */
148 static inline int board_No (struct riscom_board const * bp)
150 return bp - rc_board;
153 /* Get port number from pointer */
154 static inline int port_No (struct riscom_port const * port)
156 return RC_PORT(port - rc_port);
159 /* Get pointer to board from pointer to port */
160 static inline struct riscom_board * port_Board(struct riscom_port const * port)
162 return &rc_board[RC_BOARD(port - rc_port)];
165 /* Input Byte from CL CD180 register */
166 static inline unsigned char rc_in(struct riscom_board const * bp, unsigned short reg)
168 return inb(bp->base + RC_TO_ISA(reg));
171 /* Output Byte to CL CD180 register */
172 static inline void rc_out(struct riscom_board const * bp, unsigned short reg,
175 outb(val, bp->base + RC_TO_ISA(reg));
178 /* Wait for Channel Command Register ready */
179 static inline void rc_wait_CCR(struct riscom_board const * bp)
183 /* FIXME: need something more descriptive then 100000 :) */
184 for (delay = 100000; delay; delay--)
185 if (!rc_in(bp, CD180_CCR))
188 printk(KERN_INFO "rc%d: Timeout waiting for CCR.\n", board_No(bp));
192 * RISCom/8 probe functions.
195 static inline int rc_request_io_range(struct riscom_board * const bp)
199 for (i = 0; i < RC_NIOPORT; i++)
200 if (!request_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1,
206 printk(KERN_INFO "rc%d: Skipping probe at 0x%03x. IO address in use.\n",
207 board_No(bp), bp->base);
209 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
213 static inline void rc_release_io_range(struct riscom_board * const bp)
217 for (i = 0; i < RC_NIOPORT; i++)
218 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
221 /* Must be called with enabled interrupts */
222 static inline void rc_long_delay(unsigned long delay)
226 for (i = jiffies + delay; time_after(i,jiffies); ) ;
229 /* Reset and setup CD180 chip */
230 static void __init rc_init_CD180(struct riscom_board const * bp)
234 save_flags(flags); cli();
235 rc_out(bp, RC_CTOUT, 0); /* Clear timeout */
236 rc_wait_CCR(bp); /* Wait for CCR ready */
237 rc_out(bp, CD180_CCR, CCR_HARDRESET); /* Reset CD180 chip */
239 rc_long_delay(HZ/20); /* Delay 0.05 sec */
241 rc_out(bp, CD180_GIVR, RC_ID); /* Set ID for this chip */
242 rc_out(bp, CD180_GICR, 0); /* Clear all bits */
243 rc_out(bp, CD180_PILR1, RC_ACK_MINT); /* Prio for modem intr */
244 rc_out(bp, CD180_PILR2, RC_ACK_TINT); /* Prio for transmitter intr */
245 rc_out(bp, CD180_PILR3, RC_ACK_RINT); /* Prio for receiver intr */
247 /* Setting up prescaler. We need 4 ticks per 1 ms */
248 rc_out(bp, CD180_PPRH, (RC_OSCFREQ/(1000000/RISCOM_TPS)) >> 8);
249 rc_out(bp, CD180_PPRL, (RC_OSCFREQ/(1000000/RISCOM_TPS)) & 0xff);
251 restore_flags(flags);
254 /* Main probing routine, also sets irq. */
255 static int __init rc_probe(struct riscom_board *bp)
257 unsigned char val1, val2;
263 if (rc_request_io_range(bp))
266 /* Are the I/O ports here ? */
267 rc_out(bp, CD180_PPRL, 0x5a);
269 val1 = rc_in(bp, CD180_PPRL);
270 rc_out(bp, CD180_PPRL, 0xa5);
272 val2 = rc_in(bp, CD180_PPRL);
274 if ((val1 != 0x5a) || (val2 != 0xa5)) {
275 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not found.\n",
276 board_No(bp), bp->base);
280 /* It's time to find IRQ for this board */
281 for (retries = 0; retries < 5 && irqs <= 0; retries++) {
282 irqs = probe_irq_on();
283 rc_init_CD180(bp); /* Reset CD180 chip */
284 rc_out(bp, CD180_CAR, 2); /* Select port 2 */
286 rc_out(bp, CD180_CCR, CCR_TXEN); /* Enable transmitter */
287 rc_out(bp, CD180_IER, IER_TXRDY); /* Enable tx empty intr */
288 rc_long_delay(HZ/20);
289 irqs = probe_irq_off(irqs);
290 val1 = rc_in(bp, RC_BSR); /* Get Board Status reg */
291 val2 = rc_in(bp, RC_ACK_TINT); /* ACK interrupt */
292 rc_init_CD180(bp); /* Reset CD180 again */
294 if ((val1 & RC_BSR_TINT) || (val2 != (RC_ID | GIVR_IT_TX))) {
295 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not "
296 "found.\n", board_No(bp), bp->base);
302 printk(KERN_ERR "rc%d: Can't find IRQ for RISCom/8 board "
303 "at 0x%03x.\n", board_No(bp), bp->base);
307 bp->flags |= RC_BOARD_PRESENT;
309 printk(KERN_INFO "rc%d: RISCom/8 Rev. %c board detected at "
312 (rc_in(bp, CD180_GFRCR) & 0x0f) + 'A', /* Board revision */
317 rc_release_io_range(bp);
323 * Interrupt processing routines.
327 static inline void rc_mark_event(struct riscom_port * port, int event)
329 set_bit(event, &port->event);
330 schedule_work(&port->tqueue);
333 static inline struct riscom_port * rc_get_port(struct riscom_board const * bp,
334 unsigned char const * what)
336 unsigned char channel;
337 struct riscom_port * port;
339 channel = rc_in(bp, CD180_GICR) >> GICR_CHAN_OFF;
340 if (channel < CD180_NCH) {
341 port = &rc_port[board_No(bp) * RC_NPORT + channel];
342 if (port->flags & ASYNC_INITIALIZED) {
346 printk(KERN_ERR "rc%d: %s interrupt from invalid port %d\n",
347 board_No(bp), what, channel);
351 static inline void rc_receive_exc(struct riscom_board const * bp)
353 struct riscom_port *port;
354 struct tty_struct *tty;
355 unsigned char status;
356 unsigned char ch, flag;
358 if (!(port = rc_get_port(bp, "Receive")))
363 #ifdef RC_REPORT_OVERRUN
364 status = rc_in(bp, CD180_RCSR);
365 if (status & RCSR_OE)
367 status &= port->mark_mask;
369 status = rc_in(bp, CD180_RCSR) & port->mark_mask;
371 ch = rc_in(bp, CD180_RDR);
375 if (status & RCSR_TOUT) {
376 printk(KERN_WARNING "rc%d: port %d: Receiver timeout. "
377 "Hardware problems ?\n",
378 board_No(bp), port_No(port));
381 } else if (status & RCSR_BREAK) {
382 printk(KERN_INFO "rc%d: port %d: Handling break...\n",
383 board_No(bp), port_No(port));
385 if (port->flags & ASYNC_SAK)
388 } else if (status & RCSR_PE)
391 else if (status & RCSR_FE)
394 else if (status & RCSR_OE)
400 tty_insert_flip_char(tty, ch, flag);
401 tty_flip_buffer_push(tty);
404 static inline void rc_receive(struct riscom_board const * bp)
406 struct riscom_port *port;
407 struct tty_struct *tty;
410 if (!(port = rc_get_port(bp, "Receive")))
415 count = rc_in(bp, CD180_RDCR);
417 #ifdef RC_REPORT_FIFO
418 port->hits[count > 8 ? 9 : count]++;
422 if (tty_buffer_request_room(tty, 1) == 0) {
423 printk(KERN_WARNING "rc%d: port %d: Working around "
424 "flip buffer overflow.\n",
425 board_No(bp), port_No(port));
428 tty_insert_flip_char(tty, rc_in(bp, CD180_RDR), TTY_NORMAL);
430 tty_flip_buffer_push(tty);
433 static inline void rc_transmit(struct riscom_board const * bp)
435 struct riscom_port *port;
436 struct tty_struct *tty;
440 if (!(port = rc_get_port(bp, "Transmit")))
445 if (port->IER & IER_TXEMPTY) {
447 rc_out(bp, CD180_CAR, port_No(port));
448 port->IER &= ~IER_TXEMPTY;
449 rc_out(bp, CD180_IER, port->IER);
453 if ((port->xmit_cnt <= 0 && !port->break_length)
454 || tty->stopped || tty->hw_stopped) {
455 rc_out(bp, CD180_CAR, port_No(port));
456 port->IER &= ~IER_TXRDY;
457 rc_out(bp, CD180_IER, port->IER);
461 if (port->break_length) {
462 if (port->break_length > 0) {
463 if (port->COR2 & COR2_ETC) {
464 rc_out(bp, CD180_TDR, CD180_C_ESC);
465 rc_out(bp, CD180_TDR, CD180_C_SBRK);
466 port->COR2 &= ~COR2_ETC;
468 count = min_t(int, port->break_length, 0xff);
469 rc_out(bp, CD180_TDR, CD180_C_ESC);
470 rc_out(bp, CD180_TDR, CD180_C_DELAY);
471 rc_out(bp, CD180_TDR, count);
472 if (!(port->break_length -= count))
473 port->break_length--;
475 rc_out(bp, CD180_TDR, CD180_C_ESC);
476 rc_out(bp, CD180_TDR, CD180_C_EBRK);
477 rc_out(bp, CD180_COR2, port->COR2);
479 rc_out(bp, CD180_CCR, CCR_CORCHG2);
480 port->break_length = 0;
487 rc_out(bp, CD180_TDR, port->xmit_buf[port->xmit_tail++]);
488 port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1);
489 if (--port->xmit_cnt <= 0)
491 } while (--count > 0);
493 if (port->xmit_cnt <= 0) {
494 rc_out(bp, CD180_CAR, port_No(port));
495 port->IER &= ~IER_TXRDY;
496 rc_out(bp, CD180_IER, port->IER);
498 if (port->xmit_cnt <= port->wakeup_chars)
499 rc_mark_event(port, RS_EVENT_WRITE_WAKEUP);
502 static inline void rc_check_modem(struct riscom_board const * bp)
504 struct riscom_port *port;
505 struct tty_struct *tty;
508 if (!(port = rc_get_port(bp, "Modem")))
513 mcr = rc_in(bp, CD180_MCR);
514 if (mcr & MCR_CDCHG) {
515 if (rc_in(bp, CD180_MSVR) & MSVR_CD)
516 wake_up_interruptible(&port->open_wait);
518 schedule_work(&port->tqueue_hangup);
521 #ifdef RISCOM_BRAIN_DAMAGED_CTS
522 if (mcr & MCR_CTSCHG) {
523 if (rc_in(bp, CD180_MSVR) & MSVR_CTS) {
525 port->IER |= IER_TXRDY;
526 if (port->xmit_cnt <= port->wakeup_chars)
527 rc_mark_event(port, RS_EVENT_WRITE_WAKEUP);
530 port->IER &= ~IER_TXRDY;
532 rc_out(bp, CD180_IER, port->IER);
534 if (mcr & MCR_DSRCHG) {
535 if (rc_in(bp, CD180_MSVR) & MSVR_DSR) {
537 port->IER |= IER_TXRDY;
538 if (port->xmit_cnt <= port->wakeup_chars)
539 rc_mark_event(port, RS_EVENT_WRITE_WAKEUP);
542 port->IER &= ~IER_TXRDY;
544 rc_out(bp, CD180_IER, port->IER);
546 #endif /* RISCOM_BRAIN_DAMAGED_CTS */
548 /* Clear change bits */
549 rc_out(bp, CD180_MCR, 0);
552 /* The main interrupt processing routine */
553 static irqreturn_t rc_interrupt(int irq, void * dev_id)
555 unsigned char status;
557 struct riscom_board *bp;
558 unsigned long loop = 0;
561 bp = IRQ_to_board[irq];
563 if (!(bp->flags & RC_BOARD_ACTIVE))
566 while ((++loop < 16) && ((status = ~(rc_in(bp, RC_BSR))) &
567 (RC_BSR_TOUT | RC_BSR_TINT |
568 RC_BSR_MINT | RC_BSR_RINT))) {
570 if (status & RC_BSR_TOUT)
571 printk(KERN_WARNING "rc%d: Got timeout. Hardware "
572 "error?\n", board_No(bp));
574 else if (status & RC_BSR_RINT) {
575 ack = rc_in(bp, RC_ACK_RINT);
577 if (ack == (RC_ID | GIVR_IT_RCV))
579 else if (ack == (RC_ID | GIVR_IT_REXC))
582 printk(KERN_WARNING "rc%d: Bad receive ack "
586 } else if (status & RC_BSR_TINT) {
587 ack = rc_in(bp, RC_ACK_TINT);
589 if (ack == (RC_ID | GIVR_IT_TX))
592 printk(KERN_WARNING "rc%d: Bad transmit ack "
596 } else /* if (status & RC_BSR_MINT) */ {
597 ack = rc_in(bp, RC_ACK_MINT);
599 if (ack == (RC_ID | GIVR_IT_MODEM))
602 printk(KERN_WARNING "rc%d: Bad modem ack "
608 rc_out(bp, CD180_EOIR, 0); /* Mark end of interrupt */
609 rc_out(bp, RC_CTOUT, 0); /* Clear timeout flag */
611 return IRQ_RETVAL(handled);
615 * Routines for open & close processing.
618 /* Called with disabled interrupts */
619 static inline int rc_setup_board(struct riscom_board * bp)
623 if (bp->flags & RC_BOARD_ACTIVE)
626 error = request_irq(bp->irq, rc_interrupt, IRQF_DISABLED,
631 rc_out(bp, RC_CTOUT, 0); /* Just in case */
633 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */
635 IRQ_to_board[bp->irq] = bp;
636 bp->flags |= RC_BOARD_ACTIVE;
641 /* Called with disabled interrupts */
642 static inline void rc_shutdown_board(struct riscom_board *bp)
644 if (!(bp->flags & RC_BOARD_ACTIVE))
647 bp->flags &= ~RC_BOARD_ACTIVE;
649 free_irq(bp->irq, NULL);
650 IRQ_to_board[bp->irq] = NULL;
653 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */
658 * Setting up port characteristics.
659 * Must be called with disabled interrupts
661 static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
663 struct tty_struct *tty;
666 unsigned char cor1 = 0, cor3 = 0;
667 unsigned char mcor1 = 0, mcor2 = 0;
669 if (!(tty = port->tty) || !tty->termios)
674 port->MSVR = MSVR_RTS;
676 baud = tty_get_baud_rate(tty);
678 /* Select port on the board */
679 rc_out(bp, CD180_CAR, port_No(port));
682 /* Drop DTR & exit */
683 bp->DTR |= (1u << port_No(port));
684 rc_out(bp, RC_DTR, bp->DTR);
688 bp->DTR &= ~(1u << port_No(port));
689 rc_out(bp, RC_DTR, bp->DTR);
693 * Now we must calculate some speed depended things
696 /* Set baud rate for port */
697 tmp = (((RC_OSCFREQ + baud/2) / baud +
698 CD180_TPC/2) / CD180_TPC);
700 rc_out(bp, CD180_RBPRH, (tmp >> 8) & 0xff);
701 rc_out(bp, CD180_TBPRH, (tmp >> 8) & 0xff);
702 rc_out(bp, CD180_RBPRL, tmp & 0xff);
703 rc_out(bp, CD180_TBPRL, tmp & 0xff);
705 baud = (baud + 5) / 10; /* Estimated CPS */
707 /* Two timer ticks seems enough to wakeup something like SLIP driver */
708 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;
709 port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
710 SERIAL_XMIT_SIZE - 1 : tmp);
712 /* Receiver timeout will be transmission time for 1.5 chars */
713 tmp = (RISCOM_TPS + RISCOM_TPS/2 + baud/2) / baud;
714 tmp = (tmp > 0xff) ? 0xff : tmp;
715 rc_out(bp, CD180_RTPR, tmp);
717 switch (C_CSIZE(tty)) {
737 cor1 |= COR1_NORMPAR;
741 cor1 &= ~COR1_IGNORE;
743 /* Set marking of some errors */
744 port->mark_mask = RCSR_OE | RCSR_TOUT;
746 port->mark_mask |= RCSR_FE | RCSR_PE;
747 if (I_BRKINT(tty) || I_PARMRK(tty))
748 port->mark_mask |= RCSR_BREAK;
750 port->mark_mask &= ~(RCSR_FE | RCSR_PE);
752 port->mark_mask &= ~RCSR_BREAK;
754 /* Real raw mode. Ignore all */
755 port->mark_mask &= ~RCSR_OE;
757 /* Enable Hardware Flow Control */
758 if (C_CRTSCTS(tty)) {
759 #ifdef RISCOM_BRAIN_DAMAGED_CTS
760 port->IER |= IER_DSR | IER_CTS;
761 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
762 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
763 tty->hw_stopped = !(rc_in(bp, CD180_MSVR) & (MSVR_CTS|MSVR_DSR));
765 port->COR2 |= COR2_CTSAE;
768 /* Enable Software Flow Control. FIXME: I'm not sure about this */
769 /* Some people reported that it works, but I still doubt */
771 port->COR2 |= COR2_TXIBE;
772 cor3 |= (COR3_FCT | COR3_SCDE);
774 port->COR2 |= COR2_IXM;
775 rc_out(bp, CD180_SCHR1, START_CHAR(tty));
776 rc_out(bp, CD180_SCHR2, STOP_CHAR(tty));
777 rc_out(bp, CD180_SCHR3, START_CHAR(tty));
778 rc_out(bp, CD180_SCHR4, STOP_CHAR(tty));
780 if (!C_CLOCAL(tty)) {
781 /* Enable CD check */
788 /* Enable receiver */
789 port->IER |= IER_RXD;
791 /* Set input FIFO size (1-8 bytes) */
792 cor3 |= RISCOM_RXFIFO;
793 /* Setting up CD180 channel registers */
794 rc_out(bp, CD180_COR1, cor1);
795 rc_out(bp, CD180_COR2, port->COR2);
796 rc_out(bp, CD180_COR3, cor3);
797 /* Make CD180 know about registers change */
799 rc_out(bp, CD180_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3);
800 /* Setting up modem option registers */
801 rc_out(bp, CD180_MCOR1, mcor1);
802 rc_out(bp, CD180_MCOR2, mcor2);
803 /* Enable CD180 transmitter & receiver */
805 rc_out(bp, CD180_CCR, CCR_TXEN | CCR_RXEN);
806 /* Enable interrupts */
807 rc_out(bp, CD180_IER, port->IER);
808 /* And finally set RTS on */
809 rc_out(bp, CD180_MSVR, port->MSVR);
812 /* Must be called with interrupts enabled */
813 static int rc_setup_port(struct riscom_board *bp, struct riscom_port *port)
817 if (port->flags & ASYNC_INITIALIZED)
820 if (!port->xmit_buf) {
821 /* We may sleep in get_zeroed_page() */
824 if (!(tmp = get_zeroed_page(GFP_KERNEL)))
827 if (port->xmit_buf) {
831 port->xmit_buf = (unsigned char *) tmp;
834 save_flags(flags); cli();
837 clear_bit(TTY_IO_ERROR, &port->tty->flags);
839 if (port->count == 1)
842 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
843 rc_change_speed(bp, port);
844 port->flags |= ASYNC_INITIALIZED;
846 restore_flags(flags);
850 /* Must be called with interrupts disabled */
851 static void rc_shutdown_port(struct riscom_board *bp, struct riscom_port *port)
853 struct tty_struct *tty;
855 if (!(port->flags & ASYNC_INITIALIZED))
858 #ifdef RC_REPORT_OVERRUN
859 printk(KERN_INFO "rc%d: port %d: Total %ld overruns were detected.\n",
860 board_No(bp), port_No(port), port->overrun);
862 #ifdef RC_REPORT_FIFO
866 printk(KERN_INFO "rc%d: port %d: FIFO hits [ ",
867 board_No(bp), port_No(port));
868 for (i = 0; i < 10; i++) {
869 printk("%ld ", port->hits[i]);
874 if (port->xmit_buf) {
875 free_page((unsigned long) port->xmit_buf);
876 port->xmit_buf = NULL;
879 if (!(tty = port->tty) || C_HUPCL(tty)) {
881 bp->DTR |= (1u << port_No(port));
882 rc_out(bp, RC_DTR, bp->DTR);
886 rc_out(bp, CD180_CAR, port_No(port));
889 rc_out(bp, CD180_CCR, CCR_SOFTRESET);
890 /* Disable all interrupts from this port */
892 rc_out(bp, CD180_IER, port->IER);
895 set_bit(TTY_IO_ERROR, &tty->flags);
896 port->flags &= ~ASYNC_INITIALIZED;
898 if (--bp->count < 0) {
899 printk(KERN_INFO "rc%d: rc_shutdown_port: "
900 "bad board count: %d\n",
901 board_No(bp), bp->count);
906 * If this is the last opened port on the board
907 * shutdown whole board
910 rc_shutdown_board(bp);
914 static int block_til_ready(struct tty_struct *tty, struct file * filp,
915 struct riscom_port *port)
917 DECLARE_WAITQUEUE(wait, current);
918 struct riscom_board *bp = port_Board(port);
924 * If the device is in the middle of being closed, then block
925 * until it's done, and then try again.
927 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
928 interruptible_sleep_on(&port->close_wait);
929 if (port->flags & ASYNC_HUP_NOTIFY)
936 * If non-blocking mode is set, or the port is not enabled,
937 * then make the check up front and then exit.
939 if ((filp->f_flags & O_NONBLOCK) ||
940 (tty->flags & (1 << TTY_IO_ERROR))) {
941 port->flags |= ASYNC_NORMAL_ACTIVE;
949 * Block waiting for the carrier detect and the line to become
950 * free (i.e., not in use by the callout). While we are in
951 * this loop, info->count is dropped by one, so that
952 * rs_close() knows when to free things. We restore it upon
953 * exit, either normal or abnormal.
956 add_wait_queue(&port->open_wait, &wait);
958 if (!tty_hung_up_p(filp))
961 port->blocked_open++;
964 rc_out(bp, CD180_CAR, port_No(port));
965 CD = rc_in(bp, CD180_MSVR) & MSVR_CD;
966 rc_out(bp, CD180_MSVR, MSVR_RTS);
967 bp->DTR &= ~(1u << port_No(port));
968 rc_out(bp, RC_DTR, bp->DTR);
970 set_current_state(TASK_INTERRUPTIBLE);
971 if (tty_hung_up_p(filp) ||
972 !(port->flags & ASYNC_INITIALIZED)) {
973 if (port->flags & ASYNC_HUP_NOTIFY)
976 retval = -ERESTARTSYS;
979 if (!(port->flags & ASYNC_CLOSING) &&
982 if (signal_pending(current)) {
983 retval = -ERESTARTSYS;
988 current->state = TASK_RUNNING;
989 remove_wait_queue(&port->open_wait, &wait);
990 if (!tty_hung_up_p(filp))
992 port->blocked_open--;
996 port->flags |= ASYNC_NORMAL_ACTIVE;
1000 static int rc_open(struct tty_struct * tty, struct file * filp)
1004 struct riscom_port * port;
1005 struct riscom_board * bp;
1007 board = RC_BOARD(tty->index);
1008 if (board >= RC_NBOARD || !(rc_board[board].flags & RC_BOARD_PRESENT))
1011 bp = &rc_board[board];
1012 port = rc_port + board * RC_NPORT + RC_PORT(tty->index);
1013 if (rc_paranoia_check(port, tty->name, "rc_open"))
1016 if ((error = rc_setup_board(bp)))
1020 tty->driver_data = port;
1023 if ((error = rc_setup_port(bp, port)))
1026 if ((error = block_til_ready(tty, filp, port)))
1032 static void rc_close(struct tty_struct * tty, struct file * filp)
1034 struct riscom_port *port = (struct riscom_port *) tty->driver_data;
1035 struct riscom_board *bp;
1036 unsigned long flags;
1037 unsigned long timeout;
1039 if (!port || rc_paranoia_check(port, tty->name, "close"))
1042 save_flags(flags); cli();
1043 if (tty_hung_up_p(filp))
1046 bp = port_Board(port);
1047 if ((tty->count == 1) && (port->count != 1)) {
1048 printk(KERN_INFO "rc%d: rc_close: bad port count;"
1049 " tty->count is 1, port count is %d\n",
1050 board_No(bp), port->count);
1053 if (--port->count < 0) {
1054 printk(KERN_INFO "rc%d: rc_close: bad port count "
1056 board_No(bp), port_No(port), port->count);
1061 port->flags |= ASYNC_CLOSING;
1063 * Now we wait for the transmit buffer to clear; and we notify
1064 * the line discipline to only process XON/XOFF characters.
1067 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1068 tty_wait_until_sent(tty, port->closing_wait);
1070 * At this point we stop accepting input. To do this, we
1071 * disable the receive line status interrupts, and tell the
1072 * interrupt driver to stop checking the data ready bit in the
1073 * line status register.
1075 port->IER &= ~IER_RXD;
1076 if (port->flags & ASYNC_INITIALIZED) {
1077 port->IER &= ~IER_TXRDY;
1078 port->IER |= IER_TXEMPTY;
1079 rc_out(bp, CD180_CAR, port_No(port));
1080 rc_out(bp, CD180_IER, port->IER);
1082 * Before we drop DTR, make sure the UART transmitter
1083 * has completely drained; this is especially
1084 * important if there is a transmit FIFO!
1086 timeout = jiffies+HZ;
1087 while(port->IER & IER_TXEMPTY) {
1088 msleep_interruptible(jiffies_to_msecs(port->timeout));
1089 if (time_after(jiffies, timeout))
1093 rc_shutdown_port(bp, port);
1094 if (tty->driver->flush_buffer)
1095 tty->driver->flush_buffer(tty);
1096 tty_ldisc_flush(tty);
1101 if (port->blocked_open) {
1102 if (port->close_delay) {
1103 msleep_interruptible(jiffies_to_msecs(port->close_delay));
1105 wake_up_interruptible(&port->open_wait);
1107 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1108 wake_up_interruptible(&port->close_wait);
1109 out: restore_flags(flags);
1112 static int rc_write(struct tty_struct * tty,
1113 const unsigned char *buf, int count)
1115 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1116 struct riscom_board *bp;
1118 unsigned long flags;
1120 if (rc_paranoia_check(port, tty->name, "rc_write"))
1123 bp = port_Board(port);
1125 if (!tty || !port->xmit_buf)
1131 c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1132 SERIAL_XMIT_SIZE - port->xmit_head));
1134 restore_flags(flags);
1138 memcpy(port->xmit_buf + port->xmit_head, buf, c);
1139 port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1140 port->xmit_cnt += c;
1141 restore_flags(flags);
1149 if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1150 !(port->IER & IER_TXRDY)) {
1151 port->IER |= IER_TXRDY;
1152 rc_out(bp, CD180_CAR, port_No(port));
1153 rc_out(bp, CD180_IER, port->IER);
1155 restore_flags(flags);
1160 static void rc_put_char(struct tty_struct * tty, unsigned char ch)
1162 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1163 unsigned long flags;
1165 if (rc_paranoia_check(port, tty->name, "rc_put_char"))
1168 if (!tty || !port->xmit_buf)
1171 save_flags(flags); cli();
1173 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1176 port->xmit_buf[port->xmit_head++] = ch;
1177 port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1179 out: restore_flags(flags);
1182 static void rc_flush_chars(struct tty_struct * tty)
1184 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1185 unsigned long flags;
1187 if (rc_paranoia_check(port, tty->name, "rc_flush_chars"))
1190 if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1194 save_flags(flags); cli();
1195 port->IER |= IER_TXRDY;
1196 rc_out(port_Board(port), CD180_CAR, port_No(port));
1197 rc_out(port_Board(port), CD180_IER, port->IER);
1198 restore_flags(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 save_flags(flags); cli();
1234 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1235 restore_flags(flags);
1237 wake_up_interruptible(&tty->write_wait);
1241 static int rc_tiocmget(struct tty_struct *tty, struct file *file)
1243 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1244 struct riscom_board * bp;
1245 unsigned char status;
1246 unsigned int result;
1247 unsigned long flags;
1249 if (rc_paranoia_check(port, tty->name, __FUNCTION__))
1252 bp = port_Board(port);
1253 save_flags(flags); cli();
1254 rc_out(bp, CD180_CAR, port_No(port));
1255 status = rc_in(bp, CD180_MSVR);
1256 result = rc_in(bp, RC_RI) & (1u << port_No(port)) ? 0 : TIOCM_RNG;
1257 restore_flags(flags);
1258 result |= ((status & MSVR_RTS) ? TIOCM_RTS : 0)
1259 | ((status & MSVR_DTR) ? TIOCM_DTR : 0)
1260 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1261 | ((status & MSVR_DSR) ? TIOCM_DSR : 0)
1262 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1266 static int rc_tiocmset(struct tty_struct *tty, struct file *file,
1267 unsigned int set, unsigned int clear)
1269 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1270 unsigned long flags;
1271 struct riscom_board *bp;
1273 if (rc_paranoia_check(port, tty->name, __FUNCTION__))
1276 bp = port_Board(port);
1278 save_flags(flags); cli();
1279 if (set & TIOCM_RTS)
1280 port->MSVR |= MSVR_RTS;
1281 if (set & TIOCM_DTR)
1282 bp->DTR &= ~(1u << port_No(port));
1284 if (clear & TIOCM_RTS)
1285 port->MSVR &= ~MSVR_RTS;
1286 if (clear & TIOCM_DTR)
1287 bp->DTR |= (1u << port_No(port));
1289 rc_out(bp, CD180_CAR, port_No(port));
1290 rc_out(bp, CD180_MSVR, port->MSVR);
1291 rc_out(bp, RC_DTR, bp->DTR);
1292 restore_flags(flags);
1296 static inline void rc_send_break(struct riscom_port * port, unsigned long length)
1298 struct riscom_board *bp = port_Board(port);
1299 unsigned long flags;
1301 save_flags(flags); cli();
1302 port->break_length = RISCOM_TPS / HZ * length;
1303 port->COR2 |= COR2_ETC;
1304 port->IER |= IER_TXRDY;
1305 rc_out(bp, CD180_CAR, port_No(port));
1306 rc_out(bp, CD180_COR2, port->COR2);
1307 rc_out(bp, CD180_IER, port->IER);
1309 rc_out(bp, CD180_CCR, CCR_CORCHG2);
1311 restore_flags(flags);
1314 static inline int rc_set_serial_info(struct riscom_port * port,
1315 struct serial_struct __user * newinfo)
1317 struct serial_struct tmp;
1318 struct riscom_board *bp = port_Board(port);
1320 unsigned long flags;
1322 if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
1326 if ((tmp.irq != bp->irq) ||
1327 (tmp.port != bp->base) ||
1328 (tmp.type != PORT_CIRRUS) ||
1329 (tmp.baud_base != (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC) ||
1330 (tmp.custom_divisor != 0) ||
1331 (tmp.xmit_fifo_size != CD180_NFIFO) ||
1332 (tmp.flags & ~RISCOM_LEGAL_FLAGS))
1336 change_speed = ((port->flags & ASYNC_SPD_MASK) !=
1337 (tmp.flags & ASYNC_SPD_MASK));
1339 if (!capable(CAP_SYS_ADMIN)) {
1340 if ((tmp.close_delay != port->close_delay) ||
1341 (tmp.closing_wait != port->closing_wait) ||
1342 ((tmp.flags & ~ASYNC_USR_MASK) !=
1343 (port->flags & ~ASYNC_USR_MASK)))
1345 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
1346 (tmp.flags & ASYNC_USR_MASK));
1348 port->flags = ((port->flags & ~ASYNC_FLAGS) |
1349 (tmp.flags & ASYNC_FLAGS));
1350 port->close_delay = tmp.close_delay;
1351 port->closing_wait = tmp.closing_wait;
1354 save_flags(flags); cli();
1355 rc_change_speed(bp, port);
1356 restore_flags(flags);
1361 static inline int rc_get_serial_info(struct riscom_port * port,
1362 struct serial_struct __user *retinfo)
1364 struct serial_struct tmp;
1365 struct riscom_board *bp = port_Board(port);
1367 memset(&tmp, 0, sizeof(tmp));
1368 tmp.type = PORT_CIRRUS;
1369 tmp.line = port - rc_port;
1370 tmp.port = bp->base;
1372 tmp.flags = port->flags;
1373 tmp.baud_base = (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC;
1374 tmp.close_delay = port->close_delay * HZ/100;
1375 tmp.closing_wait = port->closing_wait * HZ/100;
1376 tmp.xmit_fifo_size = CD180_NFIFO;
1377 return copy_to_user(retinfo, &tmp, sizeof(tmp)) ? -EFAULT : 0;
1380 static int rc_ioctl(struct tty_struct * tty, struct file * filp,
1381 unsigned int cmd, unsigned long arg)
1384 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1385 void __user *argp = (void __user *)arg;
1388 if (rc_paranoia_check(port, tty->name, "rc_ioctl"))
1392 case TCSBRK: /* SVID version: non-zero arg --> no break */
1393 retval = tty_check_change(tty);
1396 tty_wait_until_sent(tty, 0);
1398 rc_send_break(port, HZ/4); /* 1/4 second */
1400 case TCSBRKP: /* support for POSIX tcsendbreak() */
1401 retval = tty_check_change(tty);
1404 tty_wait_until_sent(tty, 0);
1405 rc_send_break(port, arg ? arg*(HZ/10) : HZ/4);
1408 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned __user *)argp);
1410 if (get_user(arg,(unsigned __user *) argp))
1412 tty->termios->c_cflag =
1413 ((tty->termios->c_cflag & ~CLOCAL) |
1414 (arg ? CLOCAL : 0));
1417 return rc_get_serial_info(port, argp);
1419 return rc_set_serial_info(port, argp);
1421 return -ENOIOCTLCMD;
1426 static void rc_throttle(struct tty_struct * tty)
1428 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1429 struct riscom_board *bp;
1430 unsigned long flags;
1432 if (rc_paranoia_check(port, tty->name, "rc_throttle"))
1435 bp = port_Board(port);
1437 save_flags(flags); cli();
1438 port->MSVR &= ~MSVR_RTS;
1439 rc_out(bp, CD180_CAR, port_No(port));
1442 rc_out(bp, CD180_CCR, CCR_SSCH2);
1445 rc_out(bp, CD180_MSVR, port->MSVR);
1446 restore_flags(flags);
1449 static void rc_unthrottle(struct tty_struct * tty)
1451 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1452 struct riscom_board *bp;
1453 unsigned long flags;
1455 if (rc_paranoia_check(port, tty->name, "rc_unthrottle"))
1458 bp = port_Board(port);
1460 save_flags(flags); cli();
1461 port->MSVR |= MSVR_RTS;
1462 rc_out(bp, CD180_CAR, port_No(port));
1465 rc_out(bp, CD180_CCR, CCR_SSCH1);
1468 rc_out(bp, CD180_MSVR, port->MSVR);
1469 restore_flags(flags);
1472 static void rc_stop(struct tty_struct * tty)
1474 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1475 struct riscom_board *bp;
1476 unsigned long flags;
1478 if (rc_paranoia_check(port, tty->name, "rc_stop"))
1481 bp = port_Board(port);
1483 save_flags(flags); cli();
1484 port->IER &= ~IER_TXRDY;
1485 rc_out(bp, CD180_CAR, port_No(port));
1486 rc_out(bp, CD180_IER, port->IER);
1487 restore_flags(flags);
1490 static void rc_start(struct tty_struct * tty)
1492 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1493 struct riscom_board *bp;
1494 unsigned long flags;
1496 if (rc_paranoia_check(port, tty->name, "rc_start"))
1499 bp = port_Board(port);
1501 save_flags(flags); cli();
1502 if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) {
1503 port->IER |= IER_TXRDY;
1504 rc_out(bp, CD180_CAR, port_No(port));
1505 rc_out(bp, CD180_IER, port->IER);
1507 restore_flags(flags);
1511 * This routine is called from the work queue when the interrupt
1512 * routine has signalled that a hangup has occurred. The path of
1513 * hangup processing is:
1515 * serial interrupt routine -> (workqueue) ->
1516 * do_rc_hangup() -> tty->hangup() -> rc_hangup()
1519 static void do_rc_hangup(struct work_struct *ugly_api)
1521 struct riscom_port *port = container_of(ugly_api, struct riscom_port, tqueue_hangup);
1522 struct tty_struct *tty;
1526 tty_hangup(tty); /* FIXME: module removal race still here */
1529 static void rc_hangup(struct tty_struct * tty)
1531 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1532 struct riscom_board *bp;
1534 if (rc_paranoia_check(port, tty->name, "rc_hangup"))
1537 bp = port_Board(port);
1539 rc_shutdown_port(bp, port);
1542 port->flags &= ~ASYNC_NORMAL_ACTIVE;
1544 wake_up_interruptible(&port->open_wait);
1547 static void rc_set_termios(struct tty_struct * tty, struct termios * old_termios)
1549 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1550 unsigned long flags;
1552 if (rc_paranoia_check(port, tty->name, "rc_set_termios"))
1555 if (tty->termios->c_cflag == old_termios->c_cflag &&
1556 tty->termios->c_iflag == old_termios->c_iflag)
1559 save_flags(flags); cli();
1560 rc_change_speed(port_Board(port), port);
1561 restore_flags(flags);
1563 if ((old_termios->c_cflag & CRTSCTS) &&
1564 !(tty->termios->c_cflag & CRTSCTS)) {
1565 tty->hw_stopped = 0;
1570 static void do_softint(struct work_struct *ugly_api)
1572 struct riscom_port *port = container_of(ugly_api, struct riscom_port, tqueue);
1573 struct tty_struct *tty;
1575 if(!(tty = port->tty))
1578 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) {
1580 wake_up_interruptible(&tty->write_wait);
1584 static const struct tty_operations riscom_ops = {
1588 .put_char = rc_put_char,
1589 .flush_chars = rc_flush_chars,
1590 .write_room = rc_write_room,
1591 .chars_in_buffer = rc_chars_in_buffer,
1592 .flush_buffer = rc_flush_buffer,
1594 .throttle = rc_throttle,
1595 .unthrottle = rc_unthrottle,
1596 .set_termios = rc_set_termios,
1599 .hangup = rc_hangup,
1600 .tiocmget = rc_tiocmget,
1601 .tiocmset = rc_tiocmset,
1604 static inline int rc_init_drivers(void)
1609 riscom_driver = alloc_tty_driver(RC_NBOARD * RC_NPORT);
1613 memset(IRQ_to_board, 0, sizeof(IRQ_to_board));
1614 riscom_driver->owner = THIS_MODULE;
1615 riscom_driver->name = "ttyL";
1616 riscom_driver->major = RISCOM8_NORMAL_MAJOR;
1617 riscom_driver->type = TTY_DRIVER_TYPE_SERIAL;
1618 riscom_driver->subtype = SERIAL_TYPE_NORMAL;
1619 riscom_driver->init_termios = tty_std_termios;
1620 riscom_driver->init_termios.c_cflag =
1621 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1622 riscom_driver->flags = TTY_DRIVER_REAL_RAW;
1623 tty_set_operations(riscom_driver, &riscom_ops);
1624 if ((error = tty_register_driver(riscom_driver))) {
1625 put_tty_driver(riscom_driver);
1626 printk(KERN_ERR "rc: Couldn't register RISCom/8 driver, "
1632 memset(rc_port, 0, sizeof(rc_port));
1633 for (i = 0; i < RC_NPORT * RC_NBOARD; i++) {
1634 rc_port[i].magic = RISCOM8_MAGIC;
1635 INIT_WORK(&rc_port[i].tqueue, do_softint);
1636 INIT_WORK(&rc_port[i].tqueue_hangup, do_rc_hangup);
1637 rc_port[i].close_delay = 50 * HZ/100;
1638 rc_port[i].closing_wait = 3000 * HZ/100;
1639 init_waitqueue_head(&rc_port[i].open_wait);
1640 init_waitqueue_head(&rc_port[i].close_wait);
1646 static void rc_release_drivers(void)
1648 unsigned long flags;
1652 tty_unregister_driver(riscom_driver);
1653 put_tty_driver(riscom_driver);
1654 restore_flags(flags);
1659 * Called at boot time.
1661 * You can specify IO base for up to RC_NBOARD cards,
1662 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
1663 * Note that there will be no probing at default
1664 * addresses in this case.
1667 static int __init riscom8_setup(char *str)
1669 int ints[RC_NBOARD];
1672 str = get_options(str, ARRAY_SIZE(ints), ints);
1674 for (i = 0; i < RC_NBOARD; i++) {
1676 rc_board[i].base = ints[i+1];
1678 rc_board[i].base = 0;
1683 __setup("riscom8=", riscom8_setup);
1686 static char banner[] __initdata =
1687 KERN_INFO "rc: SDL RISCom/8 card driver v1.1, (c) D.Gorodchanin "
1689 static char no_boards_msg[] __initdata =
1690 KERN_INFO "rc: No RISCom/8 boards detected.\n";
1693 * This routine must be called by kernel at boot time
1695 static int __init riscom8_init(void)
1702 if (rc_init_drivers())
1705 for (i = 0; i < RC_NBOARD; i++)
1706 if (rc_board[i].base && !rc_probe(&rc_board[i]))
1710 rc_release_drivers();
1711 printk(no_boards_msg);
1722 module_param(iobase, int, 0);
1723 module_param(iobase1, int, 0);
1724 module_param(iobase2, int, 0);
1725 module_param(iobase3, int, 0);
1727 MODULE_LICENSE("GPL");
1731 * You can setup up to 4 boards (current value of RC_NBOARD)
1732 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter.
1735 static int __init riscom8_init_module (void)
1740 if (iobase || iobase1 || iobase2 || iobase3) {
1741 for(i = 0; i < RC_NBOARD; i++)
1742 rc_board[0].base = 0;
1746 rc_board[0].base = iobase;
1748 rc_board[1].base = iobase1;
1750 rc_board[2].base = iobase2;
1752 rc_board[3].base = iobase3;
1755 return riscom8_init();
1758 static void __exit riscom8_exit_module (void)
1762 rc_release_drivers();
1763 for (i = 0; i < RC_NBOARD; i++)
1764 if (rc_board[i].flags & RC_BOARD_PRESENT)
1765 rc_release_io_range(&rc_board[i]);
1769 module_init(riscom8_init_module);
1770 module_exit(riscom8_exit_module);