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>
49 #include <asm/uaccess.h>
52 #include "riscom8_reg.h"
54 /* Am I paranoid or not ? ;-) */
55 #define RISCOM_PARANOIA_CHECK
58 * Crazy InteliCom/8 boards sometimes has swapped CTS & DSR signals.
59 * You can slightly speed up things by #undefing the following option,
60 * if you are REALLY sure that your board is correct one.
63 #define RISCOM_BRAIN_DAMAGED_CTS
66 * The following defines are mostly for testing purposes. But if you need
67 * some nice reporting in your syslog, you can define them also.
70 #undef RC_REPORT_OVERRUN
73 #define RISCOM_LEGAL_FLAGS \
74 (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \
75 ASYNC_SPD_HI | ASYNC_SPEED_VHI | ASYNC_SESSION_LOCKOUT | \
76 ASYNC_PGRP_LOCKOUT | ASYNC_CALLOUT_NOHUP)
79 #define MIN(a,b) ((a) < (b) ? (a) : (b))
82 #define RS_EVENT_WRITE_WAKEUP 0
84 static struct riscom_board * IRQ_to_board[16];
85 static struct tty_driver *riscom_driver;
86 static unsigned char * tmp_buf;
87 static DECLARE_MUTEX(tmp_buf_sem);
89 static unsigned long baud_table[] = {
90 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
91 9600, 19200, 38400, 57600, 76800, 0,
94 static struct riscom_board rc_board[RC_NBOARD] = {
109 static struct riscom_port rc_port[RC_NBOARD * RC_NPORT];
111 /* RISCom/8 I/O ports addresses (without address translation) */
112 static unsigned short rc_ioport[] = {
114 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c,
116 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10,
117 0x11, 0x12, 0x18, 0x28, 0x31, 0x32, 0x39, 0x3a, 0x40, 0x41, 0x61, 0x62,
118 0x63, 0x64, 0x6b, 0x70, 0x71, 0x78, 0x7a, 0x7b, 0x7f, 0x100, 0x101
121 #define RC_NIOPORT (sizeof(rc_ioport) / sizeof(rc_ioport[0]))
124 static inline int rc_paranoia_check(struct riscom_port const * port,
125 char *name, const char *routine)
127 #ifdef RISCOM_PARANOIA_CHECK
128 static const char badmagic[] = KERN_INFO
129 "rc: Warning: bad riscom port magic number for device %s in %s\n";
130 static const char badinfo[] = KERN_INFO
131 "rc: Warning: null riscom port for device %s in %s\n";
134 printk(badinfo, name, routine);
137 if (port->magic != RISCOM8_MAGIC) {
138 printk(badmagic, name, routine);
147 * Service functions for RISCom/8 driver.
151 /* Get board number from pointer */
152 static inline int board_No (struct riscom_board const * bp)
154 return bp - rc_board;
157 /* Get port number from pointer */
158 static inline int port_No (struct riscom_port const * port)
160 return RC_PORT(port - rc_port);
163 /* Get pointer to board from pointer to port */
164 static inline struct riscom_board * port_Board(struct riscom_port const * port)
166 return &rc_board[RC_BOARD(port - rc_port)];
169 /* Input Byte from CL CD180 register */
170 static inline unsigned char rc_in(struct riscom_board const * bp, unsigned short reg)
172 return inb(bp->base + RC_TO_ISA(reg));
175 /* Output Byte to CL CD180 register */
176 static inline void rc_out(struct riscom_board const * bp, unsigned short reg,
179 outb(val, bp->base + RC_TO_ISA(reg));
182 /* Wait for Channel Command Register ready */
183 static inline void rc_wait_CCR(struct riscom_board const * bp)
187 /* FIXME: need something more descriptive then 100000 :) */
188 for (delay = 100000; delay; delay--)
189 if (!rc_in(bp, CD180_CCR))
192 printk(KERN_INFO "rc%d: Timeout waiting for CCR.\n", board_No(bp));
196 * RISCom/8 probe functions.
199 static inline int rc_request_io_range(struct riscom_board * const bp)
203 for (i = 0; i < RC_NIOPORT; i++)
204 if (!request_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1,
210 printk(KERN_INFO "rc%d: Skipping probe at 0x%03x. IO address in use.\n",
211 board_No(bp), bp->base);
213 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
217 static inline void rc_release_io_range(struct riscom_board * const bp)
221 for (i = 0; i < RC_NIOPORT; i++)
222 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
225 /* Must be called with enabled interrupts */
226 static inline void rc_long_delay(unsigned long delay)
230 for (i = jiffies + delay; time_after(i,jiffies); ) ;
233 /* Reset and setup CD180 chip */
234 static void __init rc_init_CD180(struct riscom_board const * bp)
238 save_flags(flags); cli();
239 rc_out(bp, RC_CTOUT, 0); /* Clear timeout */
240 rc_wait_CCR(bp); /* Wait for CCR ready */
241 rc_out(bp, CD180_CCR, CCR_HARDRESET); /* Reset CD180 chip */
243 rc_long_delay(HZ/20); /* Delay 0.05 sec */
245 rc_out(bp, CD180_GIVR, RC_ID); /* Set ID for this chip */
246 rc_out(bp, CD180_GICR, 0); /* Clear all bits */
247 rc_out(bp, CD180_PILR1, RC_ACK_MINT); /* Prio for modem intr */
248 rc_out(bp, CD180_PILR2, RC_ACK_TINT); /* Prio for transmitter intr */
249 rc_out(bp, CD180_PILR3, RC_ACK_RINT); /* Prio for receiver intr */
251 /* Setting up prescaler. We need 4 ticks per 1 ms */
252 rc_out(bp, CD180_PPRH, (RC_OSCFREQ/(1000000/RISCOM_TPS)) >> 8);
253 rc_out(bp, CD180_PPRL, (RC_OSCFREQ/(1000000/RISCOM_TPS)) & 0xff);
255 restore_flags(flags);
258 /* Main probing routine, also sets irq. */
259 static int __init rc_probe(struct riscom_board *bp)
261 unsigned char val1, val2;
267 if (rc_request_io_range(bp))
270 /* Are the I/O ports here ? */
271 rc_out(bp, CD180_PPRL, 0x5a);
273 val1 = rc_in(bp, CD180_PPRL);
274 rc_out(bp, CD180_PPRL, 0xa5);
276 val2 = rc_in(bp, CD180_PPRL);
278 if ((val1 != 0x5a) || (val2 != 0xa5)) {
279 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not found.\n",
280 board_No(bp), bp->base);
284 /* It's time to find IRQ for this board */
285 for (retries = 0; retries < 5 && irqs <= 0; retries++) {
286 irqs = probe_irq_on();
287 rc_init_CD180(bp); /* Reset CD180 chip */
288 rc_out(bp, CD180_CAR, 2); /* Select port 2 */
290 rc_out(bp, CD180_CCR, CCR_TXEN); /* Enable transmitter */
291 rc_out(bp, CD180_IER, IER_TXRDY); /* Enable tx empty intr */
292 rc_long_delay(HZ/20);
293 irqs = probe_irq_off(irqs);
294 val1 = rc_in(bp, RC_BSR); /* Get Board Status reg */
295 val2 = rc_in(bp, RC_ACK_TINT); /* ACK interrupt */
296 rc_init_CD180(bp); /* Reset CD180 again */
298 if ((val1 & RC_BSR_TINT) || (val2 != (RC_ID | GIVR_IT_TX))) {
299 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not "
300 "found.\n", board_No(bp), bp->base);
306 printk(KERN_ERR "rc%d: Can't find IRQ for RISCom/8 board "
307 "at 0x%03x.\n", board_No(bp), bp->base);
311 bp->flags |= RC_BOARD_PRESENT;
313 printk(KERN_INFO "rc%d: RISCom/8 Rev. %c board detected at "
316 (rc_in(bp, CD180_GFRCR) & 0x0f) + 'A', /* Board revision */
321 rc_release_io_range(bp);
327 * Interrupt processing routines.
331 static inline void rc_mark_event(struct riscom_port * port, int event)
333 set_bit(event, &port->event);
334 schedule_work(&port->tqueue);
337 static inline struct riscom_port * rc_get_port(struct riscom_board const * bp,
338 unsigned char const * what)
340 unsigned char channel;
341 struct riscom_port * port;
343 channel = rc_in(bp, CD180_GICR) >> GICR_CHAN_OFF;
344 if (channel < CD180_NCH) {
345 port = &rc_port[board_No(bp) * RC_NPORT + channel];
346 if (port->flags & ASYNC_INITIALIZED) {
350 printk(KERN_ERR "rc%d: %s interrupt from invalid port %d\n",
351 board_No(bp), what, channel);
355 static inline void rc_receive_exc(struct riscom_board const * bp)
357 struct riscom_port *port;
358 struct tty_struct *tty;
359 unsigned char status;
362 if (!(port = rc_get_port(bp, "Receive")))
366 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
367 printk(KERN_WARNING "rc%d: port %d: Working around flip "
368 "buffer overflow.\n",
369 board_No(bp), port_No(port));
373 #ifdef RC_REPORT_OVERRUN
374 status = rc_in(bp, CD180_RCSR);
375 if (status & RCSR_OE) {
378 printk(KERN_ERR "rc%d: port %d: Overrun. Total %ld overruns\n",
379 board_No(bp), port_No(port), port->overrun);
382 status &= port->mark_mask;
384 status = rc_in(bp, CD180_RCSR) & port->mark_mask;
386 ch = rc_in(bp, CD180_RDR);
390 if (status & RCSR_TOUT) {
391 printk(KERN_WARNING "rc%d: port %d: Receiver timeout. "
392 "Hardware problems ?\n",
393 board_No(bp), port_No(port));
396 } else if (status & RCSR_BREAK) {
397 printk(KERN_INFO "rc%d: port %d: Handling break...\n",
398 board_No(bp), port_No(port));
399 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
400 if (port->flags & ASYNC_SAK)
403 } else if (status & RCSR_PE)
404 *tty->flip.flag_buf_ptr++ = TTY_PARITY;
406 else if (status & RCSR_FE)
407 *tty->flip.flag_buf_ptr++ = TTY_FRAME;
409 else if (status & RCSR_OE)
410 *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
413 *tty->flip.flag_buf_ptr++ = 0;
415 *tty->flip.char_buf_ptr++ = ch;
417 schedule_delayed_work(&tty->flip.work, 1);
420 static inline void rc_receive(struct riscom_board const * bp)
422 struct riscom_port *port;
423 struct tty_struct *tty;
426 if (!(port = rc_get_port(bp, "Receive")))
431 count = rc_in(bp, CD180_RDCR);
433 #ifdef RC_REPORT_FIFO
434 port->hits[count > 8 ? 9 : count]++;
438 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
439 printk(KERN_WARNING "rc%d: port %d: Working around "
440 "flip buffer overflow.\n",
441 board_No(bp), port_No(port));
444 *tty->flip.char_buf_ptr++ = rc_in(bp, CD180_RDR);
445 *tty->flip.flag_buf_ptr++ = 0;
448 schedule_delayed_work(&tty->flip.work, 1);
451 static inline void rc_transmit(struct riscom_board const * bp)
453 struct riscom_port *port;
454 struct tty_struct *tty;
458 if (!(port = rc_get_port(bp, "Transmit")))
463 if (port->IER & IER_TXEMPTY) {
465 rc_out(bp, CD180_CAR, port_No(port));
466 port->IER &= ~IER_TXEMPTY;
467 rc_out(bp, CD180_IER, port->IER);
471 if ((port->xmit_cnt <= 0 && !port->break_length)
472 || tty->stopped || tty->hw_stopped) {
473 rc_out(bp, CD180_CAR, port_No(port));
474 port->IER &= ~IER_TXRDY;
475 rc_out(bp, CD180_IER, port->IER);
479 if (port->break_length) {
480 if (port->break_length > 0) {
481 if (port->COR2 & COR2_ETC) {
482 rc_out(bp, CD180_TDR, CD180_C_ESC);
483 rc_out(bp, CD180_TDR, CD180_C_SBRK);
484 port->COR2 &= ~COR2_ETC;
486 count = MIN(port->break_length, 0xff);
487 rc_out(bp, CD180_TDR, CD180_C_ESC);
488 rc_out(bp, CD180_TDR, CD180_C_DELAY);
489 rc_out(bp, CD180_TDR, count);
490 if (!(port->break_length -= count))
491 port->break_length--;
493 rc_out(bp, CD180_TDR, CD180_C_ESC);
494 rc_out(bp, CD180_TDR, CD180_C_EBRK);
495 rc_out(bp, CD180_COR2, port->COR2);
497 rc_out(bp, CD180_CCR, CCR_CORCHG2);
498 port->break_length = 0;
505 rc_out(bp, CD180_TDR, port->xmit_buf[port->xmit_tail++]);
506 port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1);
507 if (--port->xmit_cnt <= 0)
509 } while (--count > 0);
511 if (port->xmit_cnt <= 0) {
512 rc_out(bp, CD180_CAR, port_No(port));
513 port->IER &= ~IER_TXRDY;
514 rc_out(bp, CD180_IER, port->IER);
516 if (port->xmit_cnt <= port->wakeup_chars)
517 rc_mark_event(port, RS_EVENT_WRITE_WAKEUP);
520 static inline void rc_check_modem(struct riscom_board const * bp)
522 struct riscom_port *port;
523 struct tty_struct *tty;
526 if (!(port = rc_get_port(bp, "Modem")))
531 mcr = rc_in(bp, CD180_MCR);
532 if (mcr & MCR_CDCHG) {
533 if (rc_in(bp, CD180_MSVR) & MSVR_CD)
534 wake_up_interruptible(&port->open_wait);
536 schedule_work(&port->tqueue_hangup);
539 #ifdef RISCOM_BRAIN_DAMAGED_CTS
540 if (mcr & MCR_CTSCHG) {
541 if (rc_in(bp, CD180_MSVR) & MSVR_CTS) {
543 port->IER |= IER_TXRDY;
544 if (port->xmit_cnt <= port->wakeup_chars)
545 rc_mark_event(port, RS_EVENT_WRITE_WAKEUP);
548 port->IER &= ~IER_TXRDY;
550 rc_out(bp, CD180_IER, port->IER);
552 if (mcr & MCR_DSRCHG) {
553 if (rc_in(bp, CD180_MSVR) & MSVR_DSR) {
555 port->IER |= IER_TXRDY;
556 if (port->xmit_cnt <= port->wakeup_chars)
557 rc_mark_event(port, RS_EVENT_WRITE_WAKEUP);
560 port->IER &= ~IER_TXRDY;
562 rc_out(bp, CD180_IER, port->IER);
564 #endif /* RISCOM_BRAIN_DAMAGED_CTS */
566 /* Clear change bits */
567 rc_out(bp, CD180_MCR, 0);
570 /* The main interrupt processing routine */
571 static irqreturn_t rc_interrupt(int irq, void * dev_id, struct pt_regs * regs)
573 unsigned char status;
575 struct riscom_board *bp;
576 unsigned long loop = 0;
579 bp = IRQ_to_board[irq];
581 if (!bp || !(bp->flags & RC_BOARD_ACTIVE)) {
585 while ((++loop < 16) && ((status = ~(rc_in(bp, RC_BSR))) &
586 (RC_BSR_TOUT | RC_BSR_TINT |
587 RC_BSR_MINT | RC_BSR_RINT))) {
589 if (status & RC_BSR_TOUT)
590 printk(KERN_WARNING "rc%d: Got timeout. Hardware "
591 "error?\n", board_No(bp));
593 else if (status & RC_BSR_RINT) {
594 ack = rc_in(bp, RC_ACK_RINT);
596 if (ack == (RC_ID | GIVR_IT_RCV))
598 else if (ack == (RC_ID | GIVR_IT_REXC))
601 printk(KERN_WARNING "rc%d: Bad receive ack "
605 } else if (status & RC_BSR_TINT) {
606 ack = rc_in(bp, RC_ACK_TINT);
608 if (ack == (RC_ID | GIVR_IT_TX))
611 printk(KERN_WARNING "rc%d: Bad transmit ack "
615 } else /* if (status & RC_BSR_MINT) */ {
616 ack = rc_in(bp, RC_ACK_MINT);
618 if (ack == (RC_ID | GIVR_IT_MODEM))
621 printk(KERN_WARNING "rc%d: Bad modem ack "
627 rc_out(bp, CD180_EOIR, 0); /* Mark end of interrupt */
628 rc_out(bp, RC_CTOUT, 0); /* Clear timeout flag */
630 return IRQ_RETVAL(handled);
634 * Routines for open & close processing.
637 /* Called with disabled interrupts */
638 static inline int rc_setup_board(struct riscom_board * bp)
642 if (bp->flags & RC_BOARD_ACTIVE)
645 error = request_irq(bp->irq, rc_interrupt, SA_INTERRUPT,
650 rc_out(bp, RC_CTOUT, 0); /* Just in case */
652 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */
654 IRQ_to_board[bp->irq] = bp;
655 bp->flags |= RC_BOARD_ACTIVE;
660 /* Called with disabled interrupts */
661 static inline void rc_shutdown_board(struct riscom_board *bp)
663 if (!(bp->flags & RC_BOARD_ACTIVE))
666 bp->flags &= ~RC_BOARD_ACTIVE;
668 free_irq(bp->irq, NULL);
669 IRQ_to_board[bp->irq] = NULL;
672 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */
677 * Setting up port characteristics.
678 * Must be called with disabled interrupts
680 static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
682 struct tty_struct *tty;
685 unsigned char cor1 = 0, cor3 = 0;
686 unsigned char mcor1 = 0, mcor2 = 0;
688 if (!(tty = port->tty) || !tty->termios)
693 port->MSVR = MSVR_RTS;
697 if (baud & CBAUDEX) {
699 if (baud < 1 || baud > 2)
700 port->tty->termios->c_cflag &= ~CBAUDEX;
705 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
707 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
711 /* Select port on the board */
712 rc_out(bp, CD180_CAR, port_No(port));
714 if (!baud_table[baud]) {
715 /* Drop DTR & exit */
716 bp->DTR |= (1u << port_No(port));
717 rc_out(bp, RC_DTR, bp->DTR);
721 bp->DTR &= ~(1u << port_No(port));
722 rc_out(bp, RC_DTR, bp->DTR);
726 * Now we must calculate some speed depended things
729 /* Set baud rate for port */
730 tmp = (((RC_OSCFREQ + baud_table[baud]/2) / baud_table[baud] +
731 CD180_TPC/2) / CD180_TPC);
733 rc_out(bp, CD180_RBPRH, (tmp >> 8) & 0xff);
734 rc_out(bp, CD180_TBPRH, (tmp >> 8) & 0xff);
735 rc_out(bp, CD180_RBPRL, tmp & 0xff);
736 rc_out(bp, CD180_TBPRL, tmp & 0xff);
738 baud = (baud_table[baud] + 5) / 10; /* Estimated CPS */
740 /* Two timer ticks seems enough to wakeup something like SLIP driver */
741 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;
742 port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
743 SERIAL_XMIT_SIZE - 1 : tmp);
745 /* Receiver timeout will be transmission time for 1.5 chars */
746 tmp = (RISCOM_TPS + RISCOM_TPS/2 + baud/2) / baud;
747 tmp = (tmp > 0xff) ? 0xff : tmp;
748 rc_out(bp, CD180_RTPR, tmp);
750 switch (C_CSIZE(tty)) {
770 cor1 |= COR1_NORMPAR;
774 cor1 &= ~COR1_IGNORE;
776 /* Set marking of some errors */
777 port->mark_mask = RCSR_OE | RCSR_TOUT;
779 port->mark_mask |= RCSR_FE | RCSR_PE;
780 if (I_BRKINT(tty) || I_PARMRK(tty))
781 port->mark_mask |= RCSR_BREAK;
783 port->mark_mask &= ~(RCSR_FE | RCSR_PE);
785 port->mark_mask &= ~RCSR_BREAK;
787 /* Real raw mode. Ignore all */
788 port->mark_mask &= ~RCSR_OE;
790 /* Enable Hardware Flow Control */
791 if (C_CRTSCTS(tty)) {
792 #ifdef RISCOM_BRAIN_DAMAGED_CTS
793 port->IER |= IER_DSR | IER_CTS;
794 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
795 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
796 tty->hw_stopped = !(rc_in(bp, CD180_MSVR) & (MSVR_CTS|MSVR_DSR));
798 port->COR2 |= COR2_CTSAE;
801 /* Enable Software Flow Control. FIXME: I'm not sure about this */
802 /* Some people reported that it works, but I still doubt */
804 port->COR2 |= COR2_TXIBE;
805 cor3 |= (COR3_FCT | COR3_SCDE);
807 port->COR2 |= COR2_IXM;
808 rc_out(bp, CD180_SCHR1, START_CHAR(tty));
809 rc_out(bp, CD180_SCHR2, STOP_CHAR(tty));
810 rc_out(bp, CD180_SCHR3, START_CHAR(tty));
811 rc_out(bp, CD180_SCHR4, STOP_CHAR(tty));
813 if (!C_CLOCAL(tty)) {
814 /* Enable CD check */
821 /* Enable receiver */
822 port->IER |= IER_RXD;
824 /* Set input FIFO size (1-8 bytes) */
825 cor3 |= RISCOM_RXFIFO;
826 /* Setting up CD180 channel registers */
827 rc_out(bp, CD180_COR1, cor1);
828 rc_out(bp, CD180_COR2, port->COR2);
829 rc_out(bp, CD180_COR3, cor3);
830 /* Make CD180 know about registers change */
832 rc_out(bp, CD180_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3);
833 /* Setting up modem option registers */
834 rc_out(bp, CD180_MCOR1, mcor1);
835 rc_out(bp, CD180_MCOR2, mcor2);
836 /* Enable CD180 transmitter & receiver */
838 rc_out(bp, CD180_CCR, CCR_TXEN | CCR_RXEN);
839 /* Enable interrupts */
840 rc_out(bp, CD180_IER, port->IER);
841 /* And finally set RTS on */
842 rc_out(bp, CD180_MSVR, port->MSVR);
845 /* Must be called with interrupts enabled */
846 static int rc_setup_port(struct riscom_board *bp, struct riscom_port *port)
850 if (port->flags & ASYNC_INITIALIZED)
853 if (!port->xmit_buf) {
854 /* We may sleep in get_zeroed_page() */
857 if (!(tmp = get_zeroed_page(GFP_KERNEL)))
860 if (port->xmit_buf) {
864 port->xmit_buf = (unsigned char *) tmp;
867 save_flags(flags); cli();
870 clear_bit(TTY_IO_ERROR, &port->tty->flags);
872 if (port->count == 1)
875 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
876 rc_change_speed(bp, port);
877 port->flags |= ASYNC_INITIALIZED;
879 restore_flags(flags);
883 /* Must be called with interrupts disabled */
884 static void rc_shutdown_port(struct riscom_board *bp, struct riscom_port *port)
886 struct tty_struct *tty;
888 if (!(port->flags & ASYNC_INITIALIZED))
891 #ifdef RC_REPORT_OVERRUN
892 printk(KERN_INFO "rc%d: port %d: Total %ld overruns were detected.\n",
893 board_No(bp), port_No(port), port->overrun);
895 #ifdef RC_REPORT_FIFO
899 printk(KERN_INFO "rc%d: port %d: FIFO hits [ ",
900 board_No(bp), port_No(port));
901 for (i = 0; i < 10; i++) {
902 printk("%ld ", port->hits[i]);
907 if (port->xmit_buf) {
908 free_page((unsigned long) port->xmit_buf);
909 port->xmit_buf = NULL;
912 if (!(tty = port->tty) || C_HUPCL(tty)) {
914 bp->DTR |= (1u << port_No(port));
915 rc_out(bp, RC_DTR, bp->DTR);
919 rc_out(bp, CD180_CAR, port_No(port));
922 rc_out(bp, CD180_CCR, CCR_SOFTRESET);
923 /* Disable all interrupts from this port */
925 rc_out(bp, CD180_IER, port->IER);
928 set_bit(TTY_IO_ERROR, &tty->flags);
929 port->flags &= ~ASYNC_INITIALIZED;
931 if (--bp->count < 0) {
932 printk(KERN_INFO "rc%d: rc_shutdown_port: "
933 "bad board count: %d\n",
934 board_No(bp), bp->count);
939 * If this is the last opened port on the board
940 * shutdown whole board
943 rc_shutdown_board(bp);
947 static int block_til_ready(struct tty_struct *tty, struct file * filp,
948 struct riscom_port *port)
950 DECLARE_WAITQUEUE(wait, current);
951 struct riscom_board *bp = port_Board(port);
957 * If the device is in the middle of being closed, then block
958 * until it's done, and then try again.
960 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
961 interruptible_sleep_on(&port->close_wait);
962 if (port->flags & ASYNC_HUP_NOTIFY)
969 * If non-blocking mode is set, or the port is not enabled,
970 * then make the check up front and then exit.
972 if ((filp->f_flags & O_NONBLOCK) ||
973 (tty->flags & (1 << TTY_IO_ERROR))) {
974 port->flags |= ASYNC_NORMAL_ACTIVE;
982 * Block waiting for the carrier detect and the line to become
983 * free (i.e., not in use by the callout). While we are in
984 * this loop, info->count is dropped by one, so that
985 * rs_close() knows when to free things. We restore it upon
986 * exit, either normal or abnormal.
989 add_wait_queue(&port->open_wait, &wait);
991 if (!tty_hung_up_p(filp))
994 port->blocked_open++;
997 rc_out(bp, CD180_CAR, port_No(port));
998 CD = rc_in(bp, CD180_MSVR) & MSVR_CD;
999 rc_out(bp, CD180_MSVR, MSVR_RTS);
1000 bp->DTR &= ~(1u << port_No(port));
1001 rc_out(bp, RC_DTR, bp->DTR);
1003 set_current_state(TASK_INTERRUPTIBLE);
1004 if (tty_hung_up_p(filp) ||
1005 !(port->flags & ASYNC_INITIALIZED)) {
1006 if (port->flags & ASYNC_HUP_NOTIFY)
1009 retval = -ERESTARTSYS;
1012 if (!(port->flags & ASYNC_CLOSING) &&
1015 if (signal_pending(current)) {
1016 retval = -ERESTARTSYS;
1021 current->state = TASK_RUNNING;
1022 remove_wait_queue(&port->open_wait, &wait);
1023 if (!tty_hung_up_p(filp))
1025 port->blocked_open--;
1029 port->flags |= ASYNC_NORMAL_ACTIVE;
1033 static int rc_open(struct tty_struct * tty, struct file * filp)
1037 struct riscom_port * port;
1038 struct riscom_board * bp;
1040 board = RC_BOARD(tty->index);
1041 if (board >= RC_NBOARD || !(rc_board[board].flags & RC_BOARD_PRESENT))
1044 bp = &rc_board[board];
1045 port = rc_port + board * RC_NPORT + RC_PORT(tty->index);
1046 if (rc_paranoia_check(port, tty->name, "rc_open"))
1049 if ((error = rc_setup_board(bp)))
1053 tty->driver_data = port;
1056 if ((error = rc_setup_port(bp, port)))
1059 if ((error = block_til_ready(tty, filp, port)))
1065 static void rc_close(struct tty_struct * tty, struct file * filp)
1067 struct riscom_port *port = (struct riscom_port *) tty->driver_data;
1068 struct riscom_board *bp;
1069 unsigned long flags;
1070 unsigned long timeout;
1072 if (!port || rc_paranoia_check(port, tty->name, "close"))
1075 save_flags(flags); cli();
1076 if (tty_hung_up_p(filp))
1079 bp = port_Board(port);
1080 if ((tty->count == 1) && (port->count != 1)) {
1081 printk(KERN_INFO "rc%d: rc_close: bad port count;"
1082 " tty->count is 1, port count is %d\n",
1083 board_No(bp), port->count);
1086 if (--port->count < 0) {
1087 printk(KERN_INFO "rc%d: rc_close: bad port count "
1089 board_No(bp), port_No(port), port->count);
1094 port->flags |= ASYNC_CLOSING;
1096 * Now we wait for the transmit buffer to clear; and we notify
1097 * the line discipline to only process XON/XOFF characters.
1100 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1101 tty_wait_until_sent(tty, port->closing_wait);
1103 * At this point we stop accepting input. To do this, we
1104 * disable the receive line status interrupts, and tell the
1105 * interrupt driver to stop checking the data ready bit in the
1106 * line status register.
1108 port->IER &= ~IER_RXD;
1109 if (port->flags & ASYNC_INITIALIZED) {
1110 port->IER &= ~IER_TXRDY;
1111 port->IER |= IER_TXEMPTY;
1112 rc_out(bp, CD180_CAR, port_No(port));
1113 rc_out(bp, CD180_IER, port->IER);
1115 * Before we drop DTR, make sure the UART transmitter
1116 * has completely drained; this is especially
1117 * important if there is a transmit FIFO!
1119 timeout = jiffies+HZ;
1120 while(port->IER & IER_TXEMPTY) {
1121 current->state = TASK_INTERRUPTIBLE;
1122 schedule_timeout(port->timeout);
1123 if (time_after(jiffies, timeout))
1127 rc_shutdown_port(bp, port);
1128 if (tty->driver->flush_buffer)
1129 tty->driver->flush_buffer(tty);
1130 if (tty->ldisc.flush_buffer)
1131 tty->ldisc.flush_buffer(tty);
1135 if (port->blocked_open) {
1136 if (port->close_delay) {
1137 current->state = TASK_INTERRUPTIBLE;
1138 schedule_timeout(port->close_delay);
1140 wake_up_interruptible(&port->open_wait);
1142 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1143 wake_up_interruptible(&port->close_wait);
1144 out: restore_flags(flags);
1147 static int rc_write(struct tty_struct * tty, int from_user,
1148 const unsigned char *buf, int count)
1150 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1151 struct riscom_board *bp;
1153 unsigned long flags;
1155 if (rc_paranoia_check(port, tty->name, "rc_write"))
1158 bp = port_Board(port);
1160 if (!tty || !port->xmit_buf || !tmp_buf)
1168 c = MIN(count, MIN(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1169 SERIAL_XMIT_SIZE - port->xmit_head));
1173 c -= copy_from_user(tmp_buf, buf, c);
1181 c = MIN(c, MIN(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1182 SERIAL_XMIT_SIZE - port->xmit_head));
1183 memcpy(port->xmit_buf + port->xmit_head, tmp_buf, c);
1184 port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1185 port->xmit_cnt += c;
1186 restore_flags(flags);
1196 c = MIN(count, MIN(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1197 SERIAL_XMIT_SIZE - port->xmit_head));
1199 restore_flags(flags);
1203 memcpy(port->xmit_buf + port->xmit_head, buf, c);
1204 port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1205 port->xmit_cnt += c;
1206 restore_flags(flags);
1215 if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1216 !(port->IER & IER_TXRDY)) {
1217 port->IER |= IER_TXRDY;
1218 rc_out(bp, CD180_CAR, port_No(port));
1219 rc_out(bp, CD180_IER, port->IER);
1221 restore_flags(flags);
1226 static void rc_put_char(struct tty_struct * tty, unsigned char ch)
1228 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1229 unsigned long flags;
1231 if (rc_paranoia_check(port, tty->name, "rc_put_char"))
1234 if (!tty || !port->xmit_buf)
1237 save_flags(flags); cli();
1239 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1242 port->xmit_buf[port->xmit_head++] = ch;
1243 port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1245 out: restore_flags(flags);
1248 static void rc_flush_chars(struct tty_struct * tty)
1250 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1251 unsigned long flags;
1253 if (rc_paranoia_check(port, tty->name, "rc_flush_chars"))
1256 if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1260 save_flags(flags); cli();
1261 port->IER |= IER_TXRDY;
1262 rc_out(port_Board(port), CD180_CAR, port_No(port));
1263 rc_out(port_Board(port), CD180_IER, port->IER);
1264 restore_flags(flags);
1267 static int rc_write_room(struct tty_struct * tty)
1269 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1272 if (rc_paranoia_check(port, tty->name, "rc_write_room"))
1275 ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
1281 static int rc_chars_in_buffer(struct tty_struct *tty)
1283 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1285 if (rc_paranoia_check(port, tty->name, "rc_chars_in_buffer"))
1288 return port->xmit_cnt;
1291 static void rc_flush_buffer(struct tty_struct *tty)
1293 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1294 unsigned long flags;
1296 if (rc_paranoia_check(port, tty->name, "rc_flush_buffer"))
1299 save_flags(flags); cli();
1300 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1301 restore_flags(flags);
1303 wake_up_interruptible(&tty->write_wait);
1304 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1305 tty->ldisc.write_wakeup)
1306 (tty->ldisc.write_wakeup)(tty);
1309 static int rc_tiocmget(struct tty_struct *tty, struct file *file)
1311 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1312 struct riscom_board * bp;
1313 unsigned char status;
1314 unsigned int result;
1315 unsigned long flags;
1317 if (rc_paranoia_check(port, tty->name, __FUNCTION__))
1320 bp = port_Board(port);
1321 save_flags(flags); cli();
1322 rc_out(bp, CD180_CAR, port_No(port));
1323 status = rc_in(bp, CD180_MSVR);
1324 result = rc_in(bp, RC_RI) & (1u << port_No(port)) ? 0 : TIOCM_RNG;
1325 restore_flags(flags);
1326 result |= ((status & MSVR_RTS) ? TIOCM_RTS : 0)
1327 | ((status & MSVR_DTR) ? TIOCM_DTR : 0)
1328 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1329 | ((status & MSVR_DSR) ? TIOCM_DSR : 0)
1330 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1334 static int rc_tiocmset(struct tty_struct *tty, struct file *file,
1335 unsigned int set, unsigned int clear)
1337 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1338 unsigned long flags;
1339 struct riscom_board *bp;
1341 if (rc_paranoia_check(port, tty->name, __FUNCTION__))
1344 bp = port_Board(port);
1346 save_flags(flags); cli();
1347 if (set & TIOCM_RTS)
1348 port->MSVR |= MSVR_RTS;
1349 if (set & TIOCM_DTR)
1350 bp->DTR &= ~(1u << port_No(port));
1352 if (clear & TIOCM_RTS)
1353 port->MSVR &= ~MSVR_RTS;
1354 if (clear & TIOCM_DTR)
1355 bp->DTR |= (1u << port_No(port));
1357 rc_out(bp, CD180_CAR, port_No(port));
1358 rc_out(bp, CD180_MSVR, port->MSVR);
1359 rc_out(bp, RC_DTR, bp->DTR);
1360 restore_flags(flags);
1364 static inline void rc_send_break(struct riscom_port * port, unsigned long length)
1366 struct riscom_board *bp = port_Board(port);
1367 unsigned long flags;
1369 save_flags(flags); cli();
1370 port->break_length = RISCOM_TPS / HZ * length;
1371 port->COR2 |= COR2_ETC;
1372 port->IER |= IER_TXRDY;
1373 rc_out(bp, CD180_CAR, port_No(port));
1374 rc_out(bp, CD180_COR2, port->COR2);
1375 rc_out(bp, CD180_IER, port->IER);
1377 rc_out(bp, CD180_CCR, CCR_CORCHG2);
1379 restore_flags(flags);
1382 static inline int rc_set_serial_info(struct riscom_port * port,
1383 struct serial_struct * newinfo)
1385 struct serial_struct tmp;
1386 struct riscom_board *bp = port_Board(port);
1388 unsigned long flags;
1390 if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
1394 if ((tmp.irq != bp->irq) ||
1395 (tmp.port != bp->base) ||
1396 (tmp.type != PORT_CIRRUS) ||
1397 (tmp.baud_base != (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC) ||
1398 (tmp.custom_divisor != 0) ||
1399 (tmp.xmit_fifo_size != CD180_NFIFO) ||
1400 (tmp.flags & ~RISCOM_LEGAL_FLAGS))
1404 change_speed = ((port->flags & ASYNC_SPD_MASK) !=
1405 (tmp.flags & ASYNC_SPD_MASK));
1407 if (!capable(CAP_SYS_ADMIN)) {
1408 if ((tmp.close_delay != port->close_delay) ||
1409 (tmp.closing_wait != port->closing_wait) ||
1410 ((tmp.flags & ~ASYNC_USR_MASK) !=
1411 (port->flags & ~ASYNC_USR_MASK)))
1413 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
1414 (tmp.flags & ASYNC_USR_MASK));
1416 port->flags = ((port->flags & ~ASYNC_FLAGS) |
1417 (tmp.flags & ASYNC_FLAGS));
1418 port->close_delay = tmp.close_delay;
1419 port->closing_wait = tmp.closing_wait;
1422 save_flags(flags); cli();
1423 rc_change_speed(bp, port);
1424 restore_flags(flags);
1429 static inline int rc_get_serial_info(struct riscom_port * port,
1430 struct serial_struct * retinfo)
1432 struct serial_struct tmp;
1433 struct riscom_board *bp = port_Board(port);
1435 memset(&tmp, 0, sizeof(tmp));
1436 tmp.type = PORT_CIRRUS;
1437 tmp.line = port - rc_port;
1438 tmp.port = bp->base;
1440 tmp.flags = port->flags;
1441 tmp.baud_base = (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC;
1442 tmp.close_delay = port->close_delay * HZ/100;
1443 tmp.closing_wait = port->closing_wait * HZ/100;
1444 tmp.xmit_fifo_size = CD180_NFIFO;
1445 return copy_to_user(retinfo, &tmp, sizeof(tmp)) ? -EFAULT : 0;
1448 static int rc_ioctl(struct tty_struct * tty, struct file * filp,
1449 unsigned int cmd, unsigned long arg)
1452 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1455 if (rc_paranoia_check(port, tty->name, "rc_ioctl"))
1459 case TCSBRK: /* SVID version: non-zero arg --> no break */
1460 retval = tty_check_change(tty);
1463 tty_wait_until_sent(tty, 0);
1465 rc_send_break(port, HZ/4); /* 1/4 second */
1467 case TCSBRKP: /* support for POSIX tcsendbreak() */
1468 retval = tty_check_change(tty);
1471 tty_wait_until_sent(tty, 0);
1472 rc_send_break(port, arg ? arg*(HZ/10) : HZ/4);
1475 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned int *) arg);
1477 if (get_user(arg,(unsigned int *) arg))
1479 tty->termios->c_cflag =
1480 ((tty->termios->c_cflag & ~CLOCAL) |
1481 (arg ? CLOCAL : 0));
1484 return rc_get_serial_info(port, (struct serial_struct *) arg);
1486 return rc_set_serial_info(port, (struct serial_struct *) arg);
1488 return -ENOIOCTLCMD;
1493 static void rc_throttle(struct tty_struct * tty)
1495 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1496 struct riscom_board *bp;
1497 unsigned long flags;
1499 if (rc_paranoia_check(port, tty->name, "rc_throttle"))
1502 bp = port_Board(port);
1504 save_flags(flags); cli();
1505 port->MSVR &= ~MSVR_RTS;
1506 rc_out(bp, CD180_CAR, port_No(port));
1509 rc_out(bp, CD180_CCR, CCR_SSCH2);
1512 rc_out(bp, CD180_MSVR, port->MSVR);
1513 restore_flags(flags);
1516 static void rc_unthrottle(struct tty_struct * tty)
1518 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1519 struct riscom_board *bp;
1520 unsigned long flags;
1522 if (rc_paranoia_check(port, tty->name, "rc_unthrottle"))
1525 bp = port_Board(port);
1527 save_flags(flags); cli();
1528 port->MSVR |= MSVR_RTS;
1529 rc_out(bp, CD180_CAR, port_No(port));
1532 rc_out(bp, CD180_CCR, CCR_SSCH1);
1535 rc_out(bp, CD180_MSVR, port->MSVR);
1536 restore_flags(flags);
1539 static void rc_stop(struct tty_struct * tty)
1541 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1542 struct riscom_board *bp;
1543 unsigned long flags;
1545 if (rc_paranoia_check(port, tty->name, "rc_stop"))
1548 bp = port_Board(port);
1550 save_flags(flags); cli();
1551 port->IER &= ~IER_TXRDY;
1552 rc_out(bp, CD180_CAR, port_No(port));
1553 rc_out(bp, CD180_IER, port->IER);
1554 restore_flags(flags);
1557 static void rc_start(struct tty_struct * tty)
1559 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1560 struct riscom_board *bp;
1561 unsigned long flags;
1563 if (rc_paranoia_check(port, tty->name, "rc_start"))
1566 bp = port_Board(port);
1568 save_flags(flags); cli();
1569 if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) {
1570 port->IER |= IER_TXRDY;
1571 rc_out(bp, CD180_CAR, port_No(port));
1572 rc_out(bp, CD180_IER, port->IER);
1574 restore_flags(flags);
1578 * This routine is called from the work queue when the interrupt
1579 * routine has signalled that a hangup has occurred. The path of
1580 * hangup processing is:
1582 * serial interrupt routine -> (workqueue) ->
1583 * do_rc_hangup() -> tty->hangup() -> rc_hangup()
1586 static void do_rc_hangup(void *private_)
1588 struct riscom_port *port = (struct riscom_port *) private_;
1589 struct tty_struct *tty;
1593 tty_hangup(tty); /* FIXME: module removal race still here */
1596 static void rc_hangup(struct tty_struct * tty)
1598 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1599 struct riscom_board *bp;
1601 if (rc_paranoia_check(port, tty->name, "rc_hangup"))
1604 bp = port_Board(port);
1606 rc_shutdown_port(bp, port);
1609 port->flags &= ~ASYNC_NORMAL_ACTIVE;
1611 wake_up_interruptible(&port->open_wait);
1614 static void rc_set_termios(struct tty_struct * tty, struct termios * old_termios)
1616 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1617 unsigned long flags;
1619 if (rc_paranoia_check(port, tty->name, "rc_set_termios"))
1622 if (tty->termios->c_cflag == old_termios->c_cflag &&
1623 tty->termios->c_iflag == old_termios->c_iflag)
1626 save_flags(flags); cli();
1627 rc_change_speed(port_Board(port), port);
1628 restore_flags(flags);
1630 if ((old_termios->c_cflag & CRTSCTS) &&
1631 !(tty->termios->c_cflag & CRTSCTS)) {
1632 tty->hw_stopped = 0;
1637 static void do_softint(void *private_)
1639 struct riscom_port *port = (struct riscom_port *) private_;
1640 struct tty_struct *tty;
1642 if(!(tty = port->tty))
1645 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) {
1646 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1647 tty->ldisc.write_wakeup)
1648 (tty->ldisc.write_wakeup)(tty);
1649 wake_up_interruptible(&tty->write_wait);
1653 static struct tty_operations riscom_ops = {
1657 .put_char = rc_put_char,
1658 .flush_chars = rc_flush_chars,
1659 .write_room = rc_write_room,
1660 .chars_in_buffer = rc_chars_in_buffer,
1661 .flush_buffer = rc_flush_buffer,
1663 .throttle = rc_throttle,
1664 .unthrottle = rc_unthrottle,
1665 .set_termios = rc_set_termios,
1668 .hangup = rc_hangup,
1669 .tiocmget = rc_tiocmget,
1670 .tiocmset = rc_tiocmset,
1673 static inline int rc_init_drivers(void)
1678 riscom_driver = alloc_tty_driver(RC_NBOARD * RC_NPORT);
1682 if (!(tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL))) {
1683 printk(KERN_ERR "rc: Couldn't get free page.\n");
1684 put_tty_driver(riscom_driver);
1687 memset(IRQ_to_board, 0, sizeof(IRQ_to_board));
1688 riscom_driver->owner = THIS_MODULE;
1689 riscom_driver->name = "ttyL";
1690 riscom_driver->devfs_name = "tts/L";
1691 riscom_driver->major = RISCOM8_NORMAL_MAJOR;
1692 riscom_driver->type = TTY_DRIVER_TYPE_SERIAL;
1693 riscom_driver->subtype = SERIAL_TYPE_NORMAL;
1694 riscom_driver->init_termios = tty_std_termios;
1695 riscom_driver->init_termios.c_cflag =
1696 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1697 riscom_driver->flags = TTY_DRIVER_REAL_RAW;
1698 tty_set_operations(riscom_driver, &riscom_ops);
1699 if ((error = tty_register_driver(riscom_driver))) {
1700 free_page((unsigned long)tmp_buf);
1701 put_tty_driver(riscom_driver);
1702 printk(KERN_ERR "rc: Couldn't register RISCom/8 driver, "
1708 memset(rc_port, 0, sizeof(rc_port));
1709 for (i = 0; i < RC_NPORT * RC_NBOARD; i++) {
1710 rc_port[i].magic = RISCOM8_MAGIC;
1711 INIT_WORK(&rc_port[i].tqueue, do_softint, &rc_port[i]);
1712 INIT_WORK(&rc_port[i].tqueue_hangup, do_rc_hangup, &rc_port[i]);
1713 rc_port[i].close_delay = 50 * HZ/100;
1714 rc_port[i].closing_wait = 3000 * HZ/100;
1715 init_waitqueue_head(&rc_port[i].open_wait);
1716 init_waitqueue_head(&rc_port[i].close_wait);
1722 static void rc_release_drivers(void)
1724 unsigned long flags;
1728 free_page((unsigned long)tmp_buf);
1729 tty_unregister_driver(riscom_driver);
1730 put_tty_driver(riscom_driver);
1731 restore_flags(flags);
1736 * Called at boot time.
1738 * You can specify IO base for up to RC_NBOARD cards,
1739 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
1740 * Note that there will be no probing at default
1741 * addresses in this case.
1744 static int __init riscom8_setup(char *str)
1746 int ints[RC_NBOARD];
1749 str = get_options(str, ARRAY_SIZE(ints), ints);
1751 for (i = 0; i < RC_NBOARD; i++) {
1753 rc_board[i].base = ints[i+1];
1755 rc_board[i].base = 0;
1760 __setup("riscom8=", riscom8_setup);
1763 static char banner[] __initdata =
1764 KERN_INFO "rc: SDL RISCom/8 card driver v1.1, (c) D.Gorodchanin "
1766 static char no_boards_msg[] __initdata =
1767 KERN_INFO "rc: No RISCom/8 boards detected.\n";
1770 * This routine must be called by kernel at boot time
1772 static int __init riscom8_init(void)
1779 if (rc_init_drivers())
1782 for (i = 0; i < RC_NBOARD; i++)
1783 if (rc_board[i].base && !rc_probe(&rc_board[i]))
1787 rc_release_drivers();
1788 printk(no_boards_msg);
1799 MODULE_PARM(iobase, "i");
1800 MODULE_PARM(iobase1, "i");
1801 MODULE_PARM(iobase2, "i");
1802 MODULE_PARM(iobase3, "i");
1804 MODULE_LICENSE("GPL");
1808 * You can setup up to 4 boards (current value of RC_NBOARD)
1809 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter.
1812 static int __init riscom8_init_module (void)
1817 if (iobase || iobase1 || iobase2 || iobase3) {
1818 for(i = 0; i < RC_NBOARD; i++)
1819 rc_board[0].base = 0;
1823 rc_board[0].base = iobase;
1825 rc_board[1].base = iobase1;
1827 rc_board[2].base = iobase2;
1829 rc_board[3].base = iobase3;
1832 return riscom8_init();
1835 static void __exit riscom8_exit_module (void)
1839 rc_release_drivers();
1840 for (i = 0; i < RC_NBOARD; i++)
1841 if (rc_board[i].flags & RC_BOARD_PRESENT)
1842 rc_release_io_range(&rc_board[i]);
1846 module_init(riscom8_init_module);
1847 module_exit(riscom8_exit_module);