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, IRQF_DISABLED,
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;
678 baud = tty_get_baud_rate(tty);
680 /* Select port on the board */
681 rc_out(bp, CD180_CAR, port_No(port));
684 /* Drop DTR & exit */
685 bp->DTR |= (1u << port_No(port));
686 rc_out(bp, RC_DTR, bp->DTR);
690 bp->DTR &= ~(1u << port_No(port));
691 rc_out(bp, RC_DTR, bp->DTR);
695 * Now we must calculate some speed depended things
698 /* Set baud rate for port */
699 tmp = (((RC_OSCFREQ + baud/2) / baud +
700 CD180_TPC/2) / CD180_TPC);
702 rc_out(bp, CD180_RBPRH, (tmp >> 8) & 0xff);
703 rc_out(bp, CD180_TBPRH, (tmp >> 8) & 0xff);
704 rc_out(bp, CD180_RBPRL, tmp & 0xff);
705 rc_out(bp, CD180_TBPRL, tmp & 0xff);
707 baud = (baud + 5) / 10; /* Estimated CPS */
709 /* Two timer ticks seems enough to wakeup something like SLIP driver */
710 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;
711 port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
712 SERIAL_XMIT_SIZE - 1 : tmp);
714 /* Receiver timeout will be transmission time for 1.5 chars */
715 tmp = (RISCOM_TPS + RISCOM_TPS/2 + baud/2) / baud;
716 tmp = (tmp > 0xff) ? 0xff : tmp;
717 rc_out(bp, CD180_RTPR, tmp);
719 switch (C_CSIZE(tty)) {
739 cor1 |= COR1_NORMPAR;
743 cor1 &= ~COR1_IGNORE;
745 /* Set marking of some errors */
746 port->mark_mask = RCSR_OE | RCSR_TOUT;
748 port->mark_mask |= RCSR_FE | RCSR_PE;
749 if (I_BRKINT(tty) || I_PARMRK(tty))
750 port->mark_mask |= RCSR_BREAK;
752 port->mark_mask &= ~(RCSR_FE | RCSR_PE);
754 port->mark_mask &= ~RCSR_BREAK;
756 /* Real raw mode. Ignore all */
757 port->mark_mask &= ~RCSR_OE;
759 /* Enable Hardware Flow Control */
760 if (C_CRTSCTS(tty)) {
761 #ifdef RISCOM_BRAIN_DAMAGED_CTS
762 port->IER |= IER_DSR | IER_CTS;
763 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
764 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
765 tty->hw_stopped = !(rc_in(bp, CD180_MSVR) & (MSVR_CTS|MSVR_DSR));
767 port->COR2 |= COR2_CTSAE;
770 /* Enable Software Flow Control. FIXME: I'm not sure about this */
771 /* Some people reported that it works, but I still doubt */
773 port->COR2 |= COR2_TXIBE;
774 cor3 |= (COR3_FCT | COR3_SCDE);
776 port->COR2 |= COR2_IXM;
777 rc_out(bp, CD180_SCHR1, START_CHAR(tty));
778 rc_out(bp, CD180_SCHR2, STOP_CHAR(tty));
779 rc_out(bp, CD180_SCHR3, START_CHAR(tty));
780 rc_out(bp, CD180_SCHR4, STOP_CHAR(tty));
782 if (!C_CLOCAL(tty)) {
783 /* Enable CD check */
790 /* Enable receiver */
791 port->IER |= IER_RXD;
793 /* Set input FIFO size (1-8 bytes) */
794 cor3 |= RISCOM_RXFIFO;
795 /* Setting up CD180 channel registers */
796 rc_out(bp, CD180_COR1, cor1);
797 rc_out(bp, CD180_COR2, port->COR2);
798 rc_out(bp, CD180_COR3, cor3);
799 /* Make CD180 know about registers change */
801 rc_out(bp, CD180_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3);
802 /* Setting up modem option registers */
803 rc_out(bp, CD180_MCOR1, mcor1);
804 rc_out(bp, CD180_MCOR2, mcor2);
805 /* Enable CD180 transmitter & receiver */
807 rc_out(bp, CD180_CCR, CCR_TXEN | CCR_RXEN);
808 /* Enable interrupts */
809 rc_out(bp, CD180_IER, port->IER);
810 /* And finally set RTS on */
811 rc_out(bp, CD180_MSVR, port->MSVR);
814 /* Must be called with interrupts enabled */
815 static int rc_setup_port(struct riscom_board *bp, struct riscom_port *port)
819 if (port->flags & ASYNC_INITIALIZED)
822 if (!port->xmit_buf) {
823 /* We may sleep in get_zeroed_page() */
826 if (!(tmp = get_zeroed_page(GFP_KERNEL)))
829 if (port->xmit_buf) {
833 port->xmit_buf = (unsigned char *) tmp;
836 save_flags(flags); cli();
839 clear_bit(TTY_IO_ERROR, &port->tty->flags);
841 if (port->count == 1)
844 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
845 rc_change_speed(bp, port);
846 port->flags |= ASYNC_INITIALIZED;
848 restore_flags(flags);
852 /* Must be called with interrupts disabled */
853 static void rc_shutdown_port(struct riscom_board *bp, struct riscom_port *port)
855 struct tty_struct *tty;
857 if (!(port->flags & ASYNC_INITIALIZED))
860 #ifdef RC_REPORT_OVERRUN
861 printk(KERN_INFO "rc%d: port %d: Total %ld overruns were detected.\n",
862 board_No(bp), port_No(port), port->overrun);
864 #ifdef RC_REPORT_FIFO
868 printk(KERN_INFO "rc%d: port %d: FIFO hits [ ",
869 board_No(bp), port_No(port));
870 for (i = 0; i < 10; i++) {
871 printk("%ld ", port->hits[i]);
876 if (port->xmit_buf) {
877 free_page((unsigned long) port->xmit_buf);
878 port->xmit_buf = NULL;
881 if (!(tty = port->tty) || C_HUPCL(tty)) {
883 bp->DTR |= (1u << port_No(port));
884 rc_out(bp, RC_DTR, bp->DTR);
888 rc_out(bp, CD180_CAR, port_No(port));
891 rc_out(bp, CD180_CCR, CCR_SOFTRESET);
892 /* Disable all interrupts from this port */
894 rc_out(bp, CD180_IER, port->IER);
897 set_bit(TTY_IO_ERROR, &tty->flags);
898 port->flags &= ~ASYNC_INITIALIZED;
900 if (--bp->count < 0) {
901 printk(KERN_INFO "rc%d: rc_shutdown_port: "
902 "bad board count: %d\n",
903 board_No(bp), bp->count);
908 * If this is the last opened port on the board
909 * shutdown whole board
912 rc_shutdown_board(bp);
916 static int block_til_ready(struct tty_struct *tty, struct file * filp,
917 struct riscom_port *port)
919 DECLARE_WAITQUEUE(wait, current);
920 struct riscom_board *bp = port_Board(port);
926 * If the device is in the middle of being closed, then block
927 * until it's done, and then try again.
929 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
930 interruptible_sleep_on(&port->close_wait);
931 if (port->flags & ASYNC_HUP_NOTIFY)
938 * If non-blocking mode is set, or the port is not enabled,
939 * then make the check up front and then exit.
941 if ((filp->f_flags & O_NONBLOCK) ||
942 (tty->flags & (1 << TTY_IO_ERROR))) {
943 port->flags |= ASYNC_NORMAL_ACTIVE;
951 * Block waiting for the carrier detect and the line to become
952 * free (i.e., not in use by the callout). While we are in
953 * this loop, info->count is dropped by one, so that
954 * rs_close() knows when to free things. We restore it upon
955 * exit, either normal or abnormal.
958 add_wait_queue(&port->open_wait, &wait);
960 if (!tty_hung_up_p(filp))
963 port->blocked_open++;
966 rc_out(bp, CD180_CAR, port_No(port));
967 CD = rc_in(bp, CD180_MSVR) & MSVR_CD;
968 rc_out(bp, CD180_MSVR, MSVR_RTS);
969 bp->DTR &= ~(1u << port_No(port));
970 rc_out(bp, RC_DTR, bp->DTR);
972 set_current_state(TASK_INTERRUPTIBLE);
973 if (tty_hung_up_p(filp) ||
974 !(port->flags & ASYNC_INITIALIZED)) {
975 if (port->flags & ASYNC_HUP_NOTIFY)
978 retval = -ERESTARTSYS;
981 if (!(port->flags & ASYNC_CLOSING) &&
984 if (signal_pending(current)) {
985 retval = -ERESTARTSYS;
990 current->state = TASK_RUNNING;
991 remove_wait_queue(&port->open_wait, &wait);
992 if (!tty_hung_up_p(filp))
994 port->blocked_open--;
998 port->flags |= ASYNC_NORMAL_ACTIVE;
1002 static int rc_open(struct tty_struct * tty, struct file * filp)
1006 struct riscom_port * port;
1007 struct riscom_board * bp;
1009 board = RC_BOARD(tty->index);
1010 if (board >= RC_NBOARD || !(rc_board[board].flags & RC_BOARD_PRESENT))
1013 bp = &rc_board[board];
1014 port = rc_port + board * RC_NPORT + RC_PORT(tty->index);
1015 if (rc_paranoia_check(port, tty->name, "rc_open"))
1018 if ((error = rc_setup_board(bp)))
1022 tty->driver_data = port;
1025 if ((error = rc_setup_port(bp, port)))
1028 if ((error = block_til_ready(tty, filp, port)))
1034 static void rc_close(struct tty_struct * tty, struct file * filp)
1036 struct riscom_port *port = (struct riscom_port *) tty->driver_data;
1037 struct riscom_board *bp;
1038 unsigned long flags;
1039 unsigned long timeout;
1041 if (!port || rc_paranoia_check(port, tty->name, "close"))
1044 save_flags(flags); cli();
1045 if (tty_hung_up_p(filp))
1048 bp = port_Board(port);
1049 if ((tty->count == 1) && (port->count != 1)) {
1050 printk(KERN_INFO "rc%d: rc_close: bad port count;"
1051 " tty->count is 1, port count is %d\n",
1052 board_No(bp), port->count);
1055 if (--port->count < 0) {
1056 printk(KERN_INFO "rc%d: rc_close: bad port count "
1058 board_No(bp), port_No(port), port->count);
1063 port->flags |= ASYNC_CLOSING;
1065 * Now we wait for the transmit buffer to clear; and we notify
1066 * the line discipline to only process XON/XOFF characters.
1069 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1070 tty_wait_until_sent(tty, port->closing_wait);
1072 * At this point we stop accepting input. To do this, we
1073 * disable the receive line status interrupts, and tell the
1074 * interrupt driver to stop checking the data ready bit in the
1075 * line status register.
1077 port->IER &= ~IER_RXD;
1078 if (port->flags & ASYNC_INITIALIZED) {
1079 port->IER &= ~IER_TXRDY;
1080 port->IER |= IER_TXEMPTY;
1081 rc_out(bp, CD180_CAR, port_No(port));
1082 rc_out(bp, CD180_IER, port->IER);
1084 * Before we drop DTR, make sure the UART transmitter
1085 * has completely drained; this is especially
1086 * important if there is a transmit FIFO!
1088 timeout = jiffies+HZ;
1089 while(port->IER & IER_TXEMPTY) {
1090 msleep_interruptible(jiffies_to_msecs(port->timeout));
1091 if (time_after(jiffies, timeout))
1095 rc_shutdown_port(bp, port);
1096 if (tty->driver->flush_buffer)
1097 tty->driver->flush_buffer(tty);
1098 tty_ldisc_flush(tty);
1103 if (port->blocked_open) {
1104 if (port->close_delay) {
1105 msleep_interruptible(jiffies_to_msecs(port->close_delay));
1107 wake_up_interruptible(&port->open_wait);
1109 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1110 wake_up_interruptible(&port->close_wait);
1111 out: restore_flags(flags);
1114 static int rc_write(struct tty_struct * tty,
1115 const unsigned char *buf, int count)
1117 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1118 struct riscom_board *bp;
1120 unsigned long flags;
1122 if (rc_paranoia_check(port, tty->name, "rc_write"))
1125 bp = port_Board(port);
1127 if (!tty || !port->xmit_buf || !tmp_buf)
1133 c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1134 SERIAL_XMIT_SIZE - port->xmit_head));
1136 restore_flags(flags);
1140 memcpy(port->xmit_buf + port->xmit_head, buf, c);
1141 port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1142 port->xmit_cnt += c;
1143 restore_flags(flags);
1151 if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1152 !(port->IER & IER_TXRDY)) {
1153 port->IER |= IER_TXRDY;
1154 rc_out(bp, CD180_CAR, port_No(port));
1155 rc_out(bp, CD180_IER, port->IER);
1157 restore_flags(flags);
1162 static void rc_put_char(struct tty_struct * tty, unsigned char ch)
1164 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1165 unsigned long flags;
1167 if (rc_paranoia_check(port, tty->name, "rc_put_char"))
1170 if (!tty || !port->xmit_buf)
1173 save_flags(flags); cli();
1175 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1178 port->xmit_buf[port->xmit_head++] = ch;
1179 port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1181 out: restore_flags(flags);
1184 static void rc_flush_chars(struct tty_struct * tty)
1186 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1187 unsigned long flags;
1189 if (rc_paranoia_check(port, tty->name, "rc_flush_chars"))
1192 if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1196 save_flags(flags); cli();
1197 port->IER |= IER_TXRDY;
1198 rc_out(port_Board(port), CD180_CAR, port_No(port));
1199 rc_out(port_Board(port), CD180_IER, port->IER);
1200 restore_flags(flags);
1203 static int rc_write_room(struct tty_struct * tty)
1205 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1208 if (rc_paranoia_check(port, tty->name, "rc_write_room"))
1211 ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
1217 static int rc_chars_in_buffer(struct tty_struct *tty)
1219 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1221 if (rc_paranoia_check(port, tty->name, "rc_chars_in_buffer"))
1224 return port->xmit_cnt;
1227 static void rc_flush_buffer(struct tty_struct *tty)
1229 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1230 unsigned long flags;
1232 if (rc_paranoia_check(port, tty->name, "rc_flush_buffer"))
1235 save_flags(flags); cli();
1236 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1237 restore_flags(flags);
1239 wake_up_interruptible(&tty->write_wait);
1243 static int rc_tiocmget(struct tty_struct *tty, struct file *file)
1245 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1246 struct riscom_board * bp;
1247 unsigned char status;
1248 unsigned int result;
1249 unsigned long flags;
1251 if (rc_paranoia_check(port, tty->name, __FUNCTION__))
1254 bp = port_Board(port);
1255 save_flags(flags); cli();
1256 rc_out(bp, CD180_CAR, port_No(port));
1257 status = rc_in(bp, CD180_MSVR);
1258 result = rc_in(bp, RC_RI) & (1u << port_No(port)) ? 0 : TIOCM_RNG;
1259 restore_flags(flags);
1260 result |= ((status & MSVR_RTS) ? TIOCM_RTS : 0)
1261 | ((status & MSVR_DTR) ? TIOCM_DTR : 0)
1262 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1263 | ((status & MSVR_DSR) ? TIOCM_DSR : 0)
1264 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1268 static int rc_tiocmset(struct tty_struct *tty, struct file *file,
1269 unsigned int set, unsigned int clear)
1271 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1272 unsigned long flags;
1273 struct riscom_board *bp;
1275 if (rc_paranoia_check(port, tty->name, __FUNCTION__))
1278 bp = port_Board(port);
1280 save_flags(flags); cli();
1281 if (set & TIOCM_RTS)
1282 port->MSVR |= MSVR_RTS;
1283 if (set & TIOCM_DTR)
1284 bp->DTR &= ~(1u << port_No(port));
1286 if (clear & TIOCM_RTS)
1287 port->MSVR &= ~MSVR_RTS;
1288 if (clear & TIOCM_DTR)
1289 bp->DTR |= (1u << port_No(port));
1291 rc_out(bp, CD180_CAR, port_No(port));
1292 rc_out(bp, CD180_MSVR, port->MSVR);
1293 rc_out(bp, RC_DTR, bp->DTR);
1294 restore_flags(flags);
1298 static inline void rc_send_break(struct riscom_port * port, unsigned long length)
1300 struct riscom_board *bp = port_Board(port);
1301 unsigned long flags;
1303 save_flags(flags); cli();
1304 port->break_length = RISCOM_TPS / HZ * length;
1305 port->COR2 |= COR2_ETC;
1306 port->IER |= IER_TXRDY;
1307 rc_out(bp, CD180_CAR, port_No(port));
1308 rc_out(bp, CD180_COR2, port->COR2);
1309 rc_out(bp, CD180_IER, port->IER);
1311 rc_out(bp, CD180_CCR, CCR_CORCHG2);
1313 restore_flags(flags);
1316 static inline int rc_set_serial_info(struct riscom_port * port,
1317 struct serial_struct __user * newinfo)
1319 struct serial_struct tmp;
1320 struct riscom_board *bp = port_Board(port);
1322 unsigned long flags;
1324 if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
1328 if ((tmp.irq != bp->irq) ||
1329 (tmp.port != bp->base) ||
1330 (tmp.type != PORT_CIRRUS) ||
1331 (tmp.baud_base != (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC) ||
1332 (tmp.custom_divisor != 0) ||
1333 (tmp.xmit_fifo_size != CD180_NFIFO) ||
1334 (tmp.flags & ~RISCOM_LEGAL_FLAGS))
1338 change_speed = ((port->flags & ASYNC_SPD_MASK) !=
1339 (tmp.flags & ASYNC_SPD_MASK));
1341 if (!capable(CAP_SYS_ADMIN)) {
1342 if ((tmp.close_delay != port->close_delay) ||
1343 (tmp.closing_wait != port->closing_wait) ||
1344 ((tmp.flags & ~ASYNC_USR_MASK) !=
1345 (port->flags & ~ASYNC_USR_MASK)))
1347 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
1348 (tmp.flags & ASYNC_USR_MASK));
1350 port->flags = ((port->flags & ~ASYNC_FLAGS) |
1351 (tmp.flags & ASYNC_FLAGS));
1352 port->close_delay = tmp.close_delay;
1353 port->closing_wait = tmp.closing_wait;
1356 save_flags(flags); cli();
1357 rc_change_speed(bp, port);
1358 restore_flags(flags);
1363 static inline int rc_get_serial_info(struct riscom_port * port,
1364 struct serial_struct __user *retinfo)
1366 struct serial_struct tmp;
1367 struct riscom_board *bp = port_Board(port);
1369 memset(&tmp, 0, sizeof(tmp));
1370 tmp.type = PORT_CIRRUS;
1371 tmp.line = port - rc_port;
1372 tmp.port = bp->base;
1374 tmp.flags = port->flags;
1375 tmp.baud_base = (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC;
1376 tmp.close_delay = port->close_delay * HZ/100;
1377 tmp.closing_wait = port->closing_wait * HZ/100;
1378 tmp.xmit_fifo_size = CD180_NFIFO;
1379 return copy_to_user(retinfo, &tmp, sizeof(tmp)) ? -EFAULT : 0;
1382 static int rc_ioctl(struct tty_struct * tty, struct file * filp,
1383 unsigned int cmd, unsigned long arg)
1386 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1387 void __user *argp = (void __user *)arg;
1390 if (rc_paranoia_check(port, tty->name, "rc_ioctl"))
1394 case TCSBRK: /* SVID version: non-zero arg --> no break */
1395 retval = tty_check_change(tty);
1398 tty_wait_until_sent(tty, 0);
1400 rc_send_break(port, HZ/4); /* 1/4 second */
1402 case TCSBRKP: /* support for POSIX tcsendbreak() */
1403 retval = tty_check_change(tty);
1406 tty_wait_until_sent(tty, 0);
1407 rc_send_break(port, arg ? arg*(HZ/10) : HZ/4);
1410 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned __user *)argp);
1412 if (get_user(arg,(unsigned __user *) argp))
1414 tty->termios->c_cflag =
1415 ((tty->termios->c_cflag & ~CLOCAL) |
1416 (arg ? CLOCAL : 0));
1419 return rc_get_serial_info(port, argp);
1421 return rc_set_serial_info(port, argp);
1423 return -ENOIOCTLCMD;
1428 static void rc_throttle(struct tty_struct * tty)
1430 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1431 struct riscom_board *bp;
1432 unsigned long flags;
1434 if (rc_paranoia_check(port, tty->name, "rc_throttle"))
1437 bp = port_Board(port);
1439 save_flags(flags); cli();
1440 port->MSVR &= ~MSVR_RTS;
1441 rc_out(bp, CD180_CAR, port_No(port));
1444 rc_out(bp, CD180_CCR, CCR_SSCH2);
1447 rc_out(bp, CD180_MSVR, port->MSVR);
1448 restore_flags(flags);
1451 static void rc_unthrottle(struct tty_struct * tty)
1453 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1454 struct riscom_board *bp;
1455 unsigned long flags;
1457 if (rc_paranoia_check(port, tty->name, "rc_unthrottle"))
1460 bp = port_Board(port);
1462 save_flags(flags); cli();
1463 port->MSVR |= MSVR_RTS;
1464 rc_out(bp, CD180_CAR, port_No(port));
1467 rc_out(bp, CD180_CCR, CCR_SSCH1);
1470 rc_out(bp, CD180_MSVR, port->MSVR);
1471 restore_flags(flags);
1474 static void rc_stop(struct tty_struct * tty)
1476 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1477 struct riscom_board *bp;
1478 unsigned long flags;
1480 if (rc_paranoia_check(port, tty->name, "rc_stop"))
1483 bp = port_Board(port);
1485 save_flags(flags); cli();
1486 port->IER &= ~IER_TXRDY;
1487 rc_out(bp, CD180_CAR, port_No(port));
1488 rc_out(bp, CD180_IER, port->IER);
1489 restore_flags(flags);
1492 static void rc_start(struct tty_struct * tty)
1494 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1495 struct riscom_board *bp;
1496 unsigned long flags;
1498 if (rc_paranoia_check(port, tty->name, "rc_start"))
1501 bp = port_Board(port);
1503 save_flags(flags); cli();
1504 if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) {
1505 port->IER |= IER_TXRDY;
1506 rc_out(bp, CD180_CAR, port_No(port));
1507 rc_out(bp, CD180_IER, port->IER);
1509 restore_flags(flags);
1513 * This routine is called from the work queue when the interrupt
1514 * routine has signalled that a hangup has occurred. The path of
1515 * hangup processing is:
1517 * serial interrupt routine -> (workqueue) ->
1518 * do_rc_hangup() -> tty->hangup() -> rc_hangup()
1521 static void do_rc_hangup(void *private_)
1523 struct riscom_port *port = (struct riscom_port *) private_;
1524 struct tty_struct *tty;
1528 tty_hangup(tty); /* FIXME: module removal race still here */
1531 static void rc_hangup(struct tty_struct * tty)
1533 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1534 struct riscom_board *bp;
1536 if (rc_paranoia_check(port, tty->name, "rc_hangup"))
1539 bp = port_Board(port);
1541 rc_shutdown_port(bp, port);
1544 port->flags &= ~ASYNC_NORMAL_ACTIVE;
1546 wake_up_interruptible(&port->open_wait);
1549 static void rc_set_termios(struct tty_struct * tty, struct termios * old_termios)
1551 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1552 unsigned long flags;
1554 if (rc_paranoia_check(port, tty->name, "rc_set_termios"))
1557 if (tty->termios->c_cflag == old_termios->c_cflag &&
1558 tty->termios->c_iflag == old_termios->c_iflag)
1561 save_flags(flags); cli();
1562 rc_change_speed(port_Board(port), port);
1563 restore_flags(flags);
1565 if ((old_termios->c_cflag & CRTSCTS) &&
1566 !(tty->termios->c_cflag & CRTSCTS)) {
1567 tty->hw_stopped = 0;
1572 static void do_softint(void *private_)
1574 struct riscom_port *port = (struct riscom_port *) private_;
1575 struct tty_struct *tty;
1577 if(!(tty = port->tty))
1580 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) {
1582 wake_up_interruptible(&tty->write_wait);
1586 static const struct tty_operations riscom_ops = {
1590 .put_char = rc_put_char,
1591 .flush_chars = rc_flush_chars,
1592 .write_room = rc_write_room,
1593 .chars_in_buffer = rc_chars_in_buffer,
1594 .flush_buffer = rc_flush_buffer,
1596 .throttle = rc_throttle,
1597 .unthrottle = rc_unthrottle,
1598 .set_termios = rc_set_termios,
1601 .hangup = rc_hangup,
1602 .tiocmget = rc_tiocmget,
1603 .tiocmset = rc_tiocmset,
1606 static inline int rc_init_drivers(void)
1611 riscom_driver = alloc_tty_driver(RC_NBOARD * RC_NPORT);
1615 if (!(tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL))) {
1616 printk(KERN_ERR "rc: Couldn't get free page.\n");
1617 put_tty_driver(riscom_driver);
1620 memset(IRQ_to_board, 0, sizeof(IRQ_to_board));
1621 riscom_driver->owner = THIS_MODULE;
1622 riscom_driver->name = "ttyL";
1623 riscom_driver->major = RISCOM8_NORMAL_MAJOR;
1624 riscom_driver->type = TTY_DRIVER_TYPE_SERIAL;
1625 riscom_driver->subtype = SERIAL_TYPE_NORMAL;
1626 riscom_driver->init_termios = tty_std_termios;
1627 riscom_driver->init_termios.c_cflag =
1628 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1629 riscom_driver->flags = TTY_DRIVER_REAL_RAW;
1630 tty_set_operations(riscom_driver, &riscom_ops);
1631 if ((error = tty_register_driver(riscom_driver))) {
1632 free_page((unsigned long)tmp_buf);
1633 put_tty_driver(riscom_driver);
1634 printk(KERN_ERR "rc: Couldn't register RISCom/8 driver, "
1640 memset(rc_port, 0, sizeof(rc_port));
1641 for (i = 0; i < RC_NPORT * RC_NBOARD; i++) {
1642 rc_port[i].magic = RISCOM8_MAGIC;
1643 INIT_WORK(&rc_port[i].tqueue, do_softint, &rc_port[i]);
1644 INIT_WORK(&rc_port[i].tqueue_hangup, do_rc_hangup, &rc_port[i]);
1645 rc_port[i].close_delay = 50 * HZ/100;
1646 rc_port[i].closing_wait = 3000 * HZ/100;
1647 init_waitqueue_head(&rc_port[i].open_wait);
1648 init_waitqueue_head(&rc_port[i].close_wait);
1654 static void rc_release_drivers(void)
1656 unsigned long flags;
1660 free_page((unsigned long)tmp_buf);
1661 tty_unregister_driver(riscom_driver);
1662 put_tty_driver(riscom_driver);
1663 restore_flags(flags);
1668 * Called at boot time.
1670 * You can specify IO base for up to RC_NBOARD cards,
1671 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
1672 * Note that there will be no probing at default
1673 * addresses in this case.
1676 static int __init riscom8_setup(char *str)
1678 int ints[RC_NBOARD];
1681 str = get_options(str, ARRAY_SIZE(ints), ints);
1683 for (i = 0; i < RC_NBOARD; i++) {
1685 rc_board[i].base = ints[i+1];
1687 rc_board[i].base = 0;
1692 __setup("riscom8=", riscom8_setup);
1695 static char banner[] __initdata =
1696 KERN_INFO "rc: SDL RISCom/8 card driver v1.1, (c) D.Gorodchanin "
1698 static char no_boards_msg[] __initdata =
1699 KERN_INFO "rc: No RISCom/8 boards detected.\n";
1702 * This routine must be called by kernel at boot time
1704 static int __init riscom8_init(void)
1711 if (rc_init_drivers())
1714 for (i = 0; i < RC_NBOARD; i++)
1715 if (rc_board[i].base && !rc_probe(&rc_board[i]))
1719 rc_release_drivers();
1720 printk(no_boards_msg);
1731 module_param(iobase, int, 0);
1732 module_param(iobase1, int, 0);
1733 module_param(iobase2, int, 0);
1734 module_param(iobase3, int, 0);
1736 MODULE_LICENSE("GPL");
1740 * You can setup up to 4 boards (current value of RC_NBOARD)
1741 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter.
1744 static int __init riscom8_init_module (void)
1749 if (iobase || iobase1 || iobase2 || iobase3) {
1750 for(i = 0; i < RC_NBOARD; i++)
1751 rc_board[0].base = 0;
1755 rc_board[0].base = iobase;
1757 rc_board[1].base = iobase1;
1759 rc_board[2].base = iobase2;
1761 rc_board[3].base = iobase3;
1764 return riscom8_init();
1767 static void __exit riscom8_exit_module (void)
1771 rc_release_drivers();
1772 for (i = 0; i < RC_NBOARD; i++)
1773 if (rc_board[i].flags & RC_BOARD_PRESENT)
1774 rc_release_io_range(&rc_board[i]);
1778 module_init(riscom8_init_module);
1779 module_exit(riscom8_exit_module);