GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / char / riscom8.c
blob801eae4c3d53ebcded7432a5ba149b48cd28476a
1 /*
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.
27 * Revision 1.1
29 * ChangeLog:
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>
36 #include <linux/io.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>
43 #include <linux/mm.h>
44 #include <linux/serial.h>
45 #include <linux/fcntl.h>
46 #include <linux/major.h>
47 #include <linux/init.h>
48 #include <linux/delay.h>
49 #include <linux/tty_flip.h>
50 #include <linux/spinlock.h>
51 #include <linux/device.h>
53 #include <linux/uaccess.h>
55 #include "riscom8.h"
56 #include "riscom8_reg.h"
58 /* Am I paranoid or not ? ;-) */
59 #define RISCOM_PARANOIA_CHECK
62 * Crazy InteliCom/8 boards sometimes have swapped CTS & DSR signals.
63 * You can slightly speed up things by #undefing the following option,
64 * if you are REALLY sure that your board is correct one.
67 #define RISCOM_BRAIN_DAMAGED_CTS
70 * The following defines are mostly for testing purposes. But if you need
71 * some nice reporting in your syslog, you can define them also.
73 #undef RC_REPORT_FIFO
74 #undef RC_REPORT_OVERRUN
77 #define RISCOM_LEGAL_FLAGS \
78 (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \
79 ASYNC_SPD_HI | ASYNC_SPEED_VHI | ASYNC_SESSION_LOCKOUT | \
80 ASYNC_PGRP_LOCKOUT | ASYNC_CALLOUT_NOHUP)
82 static struct tty_driver *riscom_driver;
84 static DEFINE_SPINLOCK(riscom_lock);
86 static struct riscom_board rc_board[RC_NBOARD] = {
88 .base = RC_IOBASE1,
91 .base = RC_IOBASE2,
94 .base = RC_IOBASE3,
97 .base = RC_IOBASE4,
101 static struct riscom_port rc_port[RC_NBOARD * RC_NPORT];
103 /* RISCom/8 I/O ports addresses (without address translation) */
104 static unsigned short rc_ioport[] = {
105 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c,
107 #define RC_NIOPORT ARRAY_SIZE(rc_ioport)
110 static int rc_paranoia_check(struct riscom_port const *port,
111 char *name, const char *routine)
113 #ifdef RISCOM_PARANOIA_CHECK
114 static const char badmagic[] = KERN_INFO
115 "rc: Warning: bad riscom port magic number for device %s in %s\n";
116 static const char badinfo[] = KERN_INFO
117 "rc: Warning: null riscom port for device %s in %s\n";
119 if (!port) {
120 printk(badinfo, name, routine);
121 return 1;
123 if (port->magic != RISCOM8_MAGIC) {
124 printk(badmagic, name, routine);
125 return 1;
127 #endif
128 return 0;
133 * Service functions for RISCom/8 driver.
137 /* Get board number from pointer */
138 static inline int board_No(struct riscom_board const *bp)
140 return bp - rc_board;
143 /* Get port number from pointer */
144 static inline int port_No(struct riscom_port const *port)
146 return RC_PORT(port - rc_port);
149 /* Get pointer to board from pointer to port */
150 static inline struct riscom_board *port_Board(struct riscom_port const *port)
152 return &rc_board[RC_BOARD(port - rc_port)];
155 /* Input Byte from CL CD180 register */
156 static inline unsigned char rc_in(struct riscom_board const *bp,
157 unsigned short reg)
159 return inb(bp->base + RC_TO_ISA(reg));
162 /* Output Byte to CL CD180 register */
163 static inline void rc_out(struct riscom_board const *bp, unsigned short reg,
164 unsigned char val)
166 outb(val, bp->base + RC_TO_ISA(reg));
169 /* Wait for Channel Command Register ready */
170 static void rc_wait_CCR(struct riscom_board const *bp)
172 unsigned long delay;
174 for (delay = 100000; delay; delay--)
175 if (!rc_in(bp, CD180_CCR))
176 return;
178 printk(KERN_INFO "rc%d: Timeout waiting for CCR.\n", board_No(bp));
182 * RISCom/8 probe functions.
185 static int rc_request_io_range(struct riscom_board * const bp)
187 int i;
189 for (i = 0; i < RC_NIOPORT; i++)
190 if (!request_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1,
191 "RISCom/8")) {
192 goto out_release;
194 return 0;
195 out_release:
196 printk(KERN_INFO "rc%d: Skipping probe at 0x%03x. IO address in use.\n",
197 board_No(bp), bp->base);
198 while (--i >= 0)
199 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
200 return 1;
203 static void rc_release_io_range(struct riscom_board * const bp)
205 int i;
207 for (i = 0; i < RC_NIOPORT; i++)
208 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
211 /* Reset and setup CD180 chip */
212 static void __init rc_init_CD180(struct riscom_board const *bp)
214 unsigned long flags;
216 spin_lock_irqsave(&riscom_lock, flags);
218 rc_out(bp, RC_CTOUT, 0); /* Clear timeout */
219 rc_wait_CCR(bp); /* Wait for CCR ready */
220 rc_out(bp, CD180_CCR, CCR_HARDRESET); /* Reset CD180 chip */
221 spin_unlock_irqrestore(&riscom_lock, flags);
222 msleep(50); /* Delay 0.05 sec */
223 spin_lock_irqsave(&riscom_lock, flags);
224 rc_out(bp, CD180_GIVR, RC_ID); /* Set ID for this chip */
225 rc_out(bp, CD180_GICR, 0); /* Clear all bits */
226 rc_out(bp, CD180_PILR1, RC_ACK_MINT); /* Prio for modem intr */
227 rc_out(bp, CD180_PILR2, RC_ACK_TINT); /* Prio for tx intr */
228 rc_out(bp, CD180_PILR3, RC_ACK_RINT); /* Prio for rx intr */
230 /* Setting up prescaler. We need 4 ticks per 1 ms */
231 rc_out(bp, CD180_PPRH, (RC_OSCFREQ/(1000000/RISCOM_TPS)) >> 8);
232 rc_out(bp, CD180_PPRL, (RC_OSCFREQ/(1000000/RISCOM_TPS)) & 0xff);
234 spin_unlock_irqrestore(&riscom_lock, flags);
237 /* Main probing routine, also sets irq. */
238 static int __init rc_probe(struct riscom_board *bp)
240 unsigned char val1, val2;
241 int irqs = 0;
242 int retries;
244 bp->irq = 0;
246 if (rc_request_io_range(bp))
247 return 1;
249 /* Are the I/O ports here ? */
250 rc_out(bp, CD180_PPRL, 0x5a);
251 outb(0xff, 0x80);
252 val1 = rc_in(bp, CD180_PPRL);
253 rc_out(bp, CD180_PPRL, 0xa5);
254 outb(0x00, 0x80);
255 val2 = rc_in(bp, CD180_PPRL);
257 if ((val1 != 0x5a) || (val2 != 0xa5)) {
258 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not found.\n",
259 board_No(bp), bp->base);
260 goto out_release;
263 /* It's time to find IRQ for this board */
264 for (retries = 0; retries < 5 && irqs <= 0; retries++) {
265 irqs = probe_irq_on();
266 rc_init_CD180(bp); /* Reset CD180 chip */
267 rc_out(bp, CD180_CAR, 2); /* Select port 2 */
268 rc_wait_CCR(bp);
269 rc_out(bp, CD180_CCR, CCR_TXEN); /* Enable transmitter */
270 rc_out(bp, CD180_IER, IER_TXRDY);/* Enable tx empty intr */
271 msleep(50);
272 irqs = probe_irq_off(irqs);
273 val1 = rc_in(bp, RC_BSR); /* Get Board Status reg */
274 val2 = rc_in(bp, RC_ACK_TINT); /* ACK interrupt */
275 rc_init_CD180(bp); /* Reset CD180 again */
277 if ((val1 & RC_BSR_TINT) || (val2 != (RC_ID | GIVR_IT_TX))) {
278 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not "
279 "found.\n", board_No(bp), bp->base);
280 goto out_release;
284 if (irqs <= 0) {
285 printk(KERN_ERR "rc%d: Can't find IRQ for RISCom/8 board "
286 "at 0x%03x.\n", board_No(bp), bp->base);
287 goto out_release;
289 bp->irq = irqs;
290 bp->flags |= RC_BOARD_PRESENT;
292 printk(KERN_INFO "rc%d: RISCom/8 Rev. %c board detected at "
293 "0x%03x, IRQ %d.\n",
294 board_No(bp),
295 (rc_in(bp, CD180_GFRCR) & 0x0f) + 'A', /* Board revision */
296 bp->base, bp->irq);
298 return 0;
299 out_release:
300 rc_release_io_range(bp);
301 return 1;
306 * Interrupt processing routines.
310 static struct riscom_port *rc_get_port(struct riscom_board const *bp,
311 unsigned char const *what)
313 unsigned char channel;
314 struct riscom_port *port;
316 channel = rc_in(bp, CD180_GICR) >> GICR_CHAN_OFF;
317 if (channel < CD180_NCH) {
318 port = &rc_port[board_No(bp) * RC_NPORT + channel];
319 if (port->port.flags & ASYNC_INITIALIZED)
320 return port;
322 printk(KERN_ERR "rc%d: %s interrupt from invalid port %d\n",
323 board_No(bp), what, channel);
324 return NULL;
327 static void rc_receive_exc(struct riscom_board const *bp)
329 struct riscom_port *port;
330 struct tty_struct *tty;
331 unsigned char status;
332 unsigned char ch, flag;
334 port = rc_get_port(bp, "Receive");
335 if (port == NULL)
336 return;
338 tty = tty_port_tty_get(&port->port);
340 #ifdef RC_REPORT_OVERRUN
341 status = rc_in(bp, CD180_RCSR);
342 if (status & RCSR_OE)
343 port->overrun++;
344 status &= port->mark_mask;
345 #else
346 status = rc_in(bp, CD180_RCSR) & port->mark_mask;
347 #endif
348 ch = rc_in(bp, CD180_RDR);
349 if (!status)
350 goto out;
351 if (status & RCSR_TOUT) {
352 printk(KERN_WARNING "rc%d: port %d: Receiver timeout. "
353 "Hardware problems ?\n",
354 board_No(bp), port_No(port));
355 goto out;
357 } else if (status & RCSR_BREAK) {
358 printk(KERN_INFO "rc%d: port %d: Handling break...\n",
359 board_No(bp), port_No(port));
360 flag = TTY_BREAK;
361 if (tty && (port->port.flags & ASYNC_SAK))
362 do_SAK(tty);
364 } else if (status & RCSR_PE)
365 flag = TTY_PARITY;
367 else if (status & RCSR_FE)
368 flag = TTY_FRAME;
370 else if (status & RCSR_OE)
371 flag = TTY_OVERRUN;
372 else
373 flag = TTY_NORMAL;
375 if (tty) {
376 tty_insert_flip_char(tty, ch, flag);
377 tty_flip_buffer_push(tty);
379 out:
380 tty_kref_put(tty);
383 static void rc_receive(struct riscom_board const *bp)
385 struct riscom_port *port;
386 struct tty_struct *tty;
387 unsigned char count;
389 port = rc_get_port(bp, "Receive");
390 if (port == NULL)
391 return;
393 tty = tty_port_tty_get(&port->port);
395 count = rc_in(bp, CD180_RDCR);
397 #ifdef RC_REPORT_FIFO
398 port->hits[count > 8 ? 9 : count]++;
399 #endif
401 while (count--) {
402 u8 ch = rc_in(bp, CD180_RDR);
403 if (tty)
404 tty_insert_flip_char(tty, ch, TTY_NORMAL);
406 if (tty) {
407 tty_flip_buffer_push(tty);
408 tty_kref_put(tty);
412 static void rc_transmit(struct riscom_board const *bp)
414 struct riscom_port *port;
415 struct tty_struct *tty;
416 unsigned char count;
418 port = rc_get_port(bp, "Transmit");
419 if (port == NULL)
420 return;
422 tty = tty_port_tty_get(&port->port);
424 if (port->IER & IER_TXEMPTY) {
425 /* FIFO drained */
426 rc_out(bp, CD180_CAR, port_No(port));
427 port->IER &= ~IER_TXEMPTY;
428 rc_out(bp, CD180_IER, port->IER);
429 goto out;
432 if ((port->xmit_cnt <= 0 && !port->break_length)
433 || (tty && (tty->stopped || tty->hw_stopped))) {
434 rc_out(bp, CD180_CAR, port_No(port));
435 port->IER &= ~IER_TXRDY;
436 rc_out(bp, CD180_IER, port->IER);
437 goto out;
440 if (port->break_length) {
441 if (port->break_length > 0) {
442 if (port->COR2 & COR2_ETC) {
443 rc_out(bp, CD180_TDR, CD180_C_ESC);
444 rc_out(bp, CD180_TDR, CD180_C_SBRK);
445 port->COR2 &= ~COR2_ETC;
447 count = min_t(int, port->break_length, 0xff);
448 rc_out(bp, CD180_TDR, CD180_C_ESC);
449 rc_out(bp, CD180_TDR, CD180_C_DELAY);
450 rc_out(bp, CD180_TDR, count);
451 port->break_length -= count;
452 if (port->break_length == 0)
453 port->break_length--;
454 } else {
455 rc_out(bp, CD180_TDR, CD180_C_ESC);
456 rc_out(bp, CD180_TDR, CD180_C_EBRK);
457 rc_out(bp, CD180_COR2, port->COR2);
458 rc_wait_CCR(bp);
459 rc_out(bp, CD180_CCR, CCR_CORCHG2);
460 port->break_length = 0;
462 goto out;
465 count = CD180_NFIFO;
466 do {
467 rc_out(bp, CD180_TDR, port->port.xmit_buf[port->xmit_tail++]);
468 port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1);
469 if (--port->xmit_cnt <= 0)
470 break;
471 } while (--count > 0);
473 if (port->xmit_cnt <= 0) {
474 rc_out(bp, CD180_CAR, port_No(port));
475 port->IER &= ~IER_TXRDY;
476 rc_out(bp, CD180_IER, port->IER);
478 if (tty && port->xmit_cnt <= port->wakeup_chars)
479 tty_wakeup(tty);
480 out:
481 tty_kref_put(tty);
484 static void rc_check_modem(struct riscom_board const *bp)
486 struct riscom_port *port;
487 struct tty_struct *tty;
488 unsigned char mcr;
490 port = rc_get_port(bp, "Modem");
491 if (port == NULL)
492 return;
494 tty = tty_port_tty_get(&port->port);
496 mcr = rc_in(bp, CD180_MCR);
497 if (mcr & MCR_CDCHG) {
498 if (rc_in(bp, CD180_MSVR) & MSVR_CD)
499 wake_up_interruptible(&port->port.open_wait);
500 else if (tty)
501 tty_hangup(tty);
504 #ifdef RISCOM_BRAIN_DAMAGED_CTS
505 if (mcr & MCR_CTSCHG) {
506 if (rc_in(bp, CD180_MSVR) & MSVR_CTS) {
507 port->IER |= IER_TXRDY;
508 if (tty) {
509 tty->hw_stopped = 0;
510 if (port->xmit_cnt <= port->wakeup_chars)
511 tty_wakeup(tty);
513 } else {
514 if (tty)
515 tty->hw_stopped = 1;
516 port->IER &= ~IER_TXRDY;
518 rc_out(bp, CD180_IER, port->IER);
520 if (mcr & MCR_DSRCHG) {
521 if (rc_in(bp, CD180_MSVR) & MSVR_DSR) {
522 port->IER |= IER_TXRDY;
523 if (tty) {
524 tty->hw_stopped = 0;
525 if (port->xmit_cnt <= port->wakeup_chars)
526 tty_wakeup(tty);
528 } else {
529 if (tty)
530 tty->hw_stopped = 1;
531 port->IER &= ~IER_TXRDY;
533 rc_out(bp, CD180_IER, port->IER);
535 #endif /* RISCOM_BRAIN_DAMAGED_CTS */
537 /* Clear change bits */
538 rc_out(bp, CD180_MCR, 0);
539 tty_kref_put(tty);
542 /* The main interrupt processing routine */
543 static irqreturn_t rc_interrupt(int dummy, void *dev_id)
545 unsigned char status;
546 unsigned char ack;
547 struct riscom_board *bp = dev_id;
548 unsigned long loop = 0;
549 int handled = 0;
551 if (!(bp->flags & RC_BOARD_ACTIVE))
552 return IRQ_NONE;
554 while ((++loop < 16) && ((status = ~(rc_in(bp, RC_BSR))) &
555 (RC_BSR_TOUT | RC_BSR_TINT |
556 RC_BSR_MINT | RC_BSR_RINT))) {
557 handled = 1;
558 if (status & RC_BSR_TOUT)
559 printk(KERN_WARNING "rc%d: Got timeout. Hardware "
560 "error?\n", board_No(bp));
561 else if (status & RC_BSR_RINT) {
562 ack = rc_in(bp, RC_ACK_RINT);
563 if (ack == (RC_ID | GIVR_IT_RCV))
564 rc_receive(bp);
565 else if (ack == (RC_ID | GIVR_IT_REXC))
566 rc_receive_exc(bp);
567 else
568 printk(KERN_WARNING "rc%d: Bad receive ack "
569 "0x%02x.\n",
570 board_No(bp), ack);
571 } else if (status & RC_BSR_TINT) {
572 ack = rc_in(bp, RC_ACK_TINT);
573 if (ack == (RC_ID | GIVR_IT_TX))
574 rc_transmit(bp);
575 else
576 printk(KERN_WARNING "rc%d: Bad transmit ack "
577 "0x%02x.\n",
578 board_No(bp), ack);
579 } else /* if (status & RC_BSR_MINT) */ {
580 ack = rc_in(bp, RC_ACK_MINT);
581 if (ack == (RC_ID | GIVR_IT_MODEM))
582 rc_check_modem(bp);
583 else
584 printk(KERN_WARNING "rc%d: Bad modem ack "
585 "0x%02x.\n",
586 board_No(bp), ack);
588 rc_out(bp, CD180_EOIR, 0); /* Mark end of interrupt */
589 rc_out(bp, RC_CTOUT, 0); /* Clear timeout flag */
591 return IRQ_RETVAL(handled);
595 * Routines for open & close processing.
598 /* Called with disabled interrupts */
599 static int rc_setup_board(struct riscom_board *bp)
601 int error;
603 if (bp->flags & RC_BOARD_ACTIVE)
604 return 0;
606 error = request_irq(bp->irq, rc_interrupt, IRQF_DISABLED,
607 "RISCom/8", bp);
608 if (error)
609 return error;
611 rc_out(bp, RC_CTOUT, 0); /* Just in case */
612 bp->DTR = ~0;
613 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */
615 bp->flags |= RC_BOARD_ACTIVE;
617 return 0;
620 /* Called with disabled interrupts */
621 static void rc_shutdown_board(struct riscom_board *bp)
623 if (!(bp->flags & RC_BOARD_ACTIVE))
624 return;
626 bp->flags &= ~RC_BOARD_ACTIVE;
628 free_irq(bp->irq, NULL);
630 bp->DTR = ~0;
631 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */
636 * Setting up port characteristics.
637 * Must be called with disabled interrupts
639 static void rc_change_speed(struct tty_struct *tty, struct riscom_board *bp,
640 struct riscom_port *port)
642 unsigned long baud;
643 long tmp;
644 unsigned char cor1 = 0, cor3 = 0;
645 unsigned char mcor1 = 0, mcor2 = 0;
647 port->IER = 0;
648 port->COR2 = 0;
649 port->MSVR = MSVR_RTS;
651 baud = tty_get_baud_rate(tty);
653 /* Select port on the board */
654 rc_out(bp, CD180_CAR, port_No(port));
656 if (!baud) {
657 /* Drop DTR & exit */
658 bp->DTR |= (1u << port_No(port));
659 rc_out(bp, RC_DTR, bp->DTR);
660 return;
661 } else {
662 /* Set DTR on */
663 bp->DTR &= ~(1u << port_No(port));
664 rc_out(bp, RC_DTR, bp->DTR);
668 * Now we must calculate some speed depended things
671 /* Set baud rate for port */
672 tmp = (((RC_OSCFREQ + baud/2) / baud +
673 CD180_TPC/2) / CD180_TPC);
675 rc_out(bp, CD180_RBPRH, (tmp >> 8) & 0xff);
676 rc_out(bp, CD180_TBPRH, (tmp >> 8) & 0xff);
677 rc_out(bp, CD180_RBPRL, tmp & 0xff);
678 rc_out(bp, CD180_TBPRL, tmp & 0xff);
680 baud = (baud + 5) / 10; /* Estimated CPS */
682 /* Two timer ticks seems enough to wakeup something like SLIP driver */
683 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;
684 port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
685 SERIAL_XMIT_SIZE - 1 : tmp);
687 /* Receiver timeout will be transmission time for 1.5 chars */
688 tmp = (RISCOM_TPS + RISCOM_TPS/2 + baud/2) / baud;
689 tmp = (tmp > 0xff) ? 0xff : tmp;
690 rc_out(bp, CD180_RTPR, tmp);
692 switch (C_CSIZE(tty)) {
693 case CS5:
694 cor1 |= COR1_5BITS;
695 break;
696 case CS6:
697 cor1 |= COR1_6BITS;
698 break;
699 case CS7:
700 cor1 |= COR1_7BITS;
701 break;
702 case CS8:
703 cor1 |= COR1_8BITS;
704 break;
706 if (C_CSTOPB(tty))
707 cor1 |= COR1_2SB;
709 cor1 |= COR1_IGNORE;
710 if (C_PARENB(tty)) {
711 cor1 |= COR1_NORMPAR;
712 if (C_PARODD(tty))
713 cor1 |= COR1_ODDP;
714 if (I_INPCK(tty))
715 cor1 &= ~COR1_IGNORE;
717 /* Set marking of some errors */
718 port->mark_mask = RCSR_OE | RCSR_TOUT;
719 if (I_INPCK(tty))
720 port->mark_mask |= RCSR_FE | RCSR_PE;
721 if (I_BRKINT(tty) || I_PARMRK(tty))
722 port->mark_mask |= RCSR_BREAK;
723 if (I_IGNPAR(tty))
724 port->mark_mask &= ~(RCSR_FE | RCSR_PE);
725 if (I_IGNBRK(tty)) {
726 port->mark_mask &= ~RCSR_BREAK;
727 if (I_IGNPAR(tty))
728 /* Real raw mode. Ignore all */
729 port->mark_mask &= ~RCSR_OE;
731 /* Enable Hardware Flow Control */
732 if (C_CRTSCTS(tty)) {
733 #ifdef RISCOM_BRAIN_DAMAGED_CTS
734 port->IER |= IER_DSR | IER_CTS;
735 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
736 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
737 tty->hw_stopped = !(rc_in(bp, CD180_MSVR) &
738 (MSVR_CTS|MSVR_DSR));
739 #else
740 port->COR2 |= COR2_CTSAE;
741 #endif
743 /* Some people reported that it works, but I still doubt */
744 if (I_IXON(tty)) {
745 port->COR2 |= COR2_TXIBE;
746 cor3 |= (COR3_FCT | COR3_SCDE);
747 if (I_IXANY(tty))
748 port->COR2 |= COR2_IXM;
749 rc_out(bp, CD180_SCHR1, START_CHAR(tty));
750 rc_out(bp, CD180_SCHR2, STOP_CHAR(tty));
751 rc_out(bp, CD180_SCHR3, START_CHAR(tty));
752 rc_out(bp, CD180_SCHR4, STOP_CHAR(tty));
754 if (!C_CLOCAL(tty)) {
755 /* Enable CD check */
756 port->IER |= IER_CD;
757 mcor1 |= MCOR1_CDZD;
758 mcor2 |= MCOR2_CDOD;
761 if (C_CREAD(tty))
762 /* Enable receiver */
763 port->IER |= IER_RXD;
765 /* Set input FIFO size (1-8 bytes) */
766 cor3 |= RISCOM_RXFIFO;
767 /* Setting up CD180 channel registers */
768 rc_out(bp, CD180_COR1, cor1);
769 rc_out(bp, CD180_COR2, port->COR2);
770 rc_out(bp, CD180_COR3, cor3);
771 /* Make CD180 know about registers change */
772 rc_wait_CCR(bp);
773 rc_out(bp, CD180_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3);
774 /* Setting up modem option registers */
775 rc_out(bp, CD180_MCOR1, mcor1);
776 rc_out(bp, CD180_MCOR2, mcor2);
777 /* Enable CD180 transmitter & receiver */
778 rc_wait_CCR(bp);
779 rc_out(bp, CD180_CCR, CCR_TXEN | CCR_RXEN);
780 /* Enable interrupts */
781 rc_out(bp, CD180_IER, port->IER);
782 /* And finally set RTS on */
783 rc_out(bp, CD180_MSVR, port->MSVR);
786 /* Must be called with interrupts enabled */
787 static int rc_activate_port(struct tty_port *port, struct tty_struct *tty)
789 struct riscom_port *rp = container_of(port, struct riscom_port, port);
790 struct riscom_board *bp = port_Board(rp);
791 unsigned long flags;
793 if (tty_port_alloc_xmit_buf(port) < 0)
794 return -ENOMEM;
796 spin_lock_irqsave(&riscom_lock, flags);
798 clear_bit(TTY_IO_ERROR, &tty->flags);
799 bp->count++;
800 rp->xmit_cnt = rp->xmit_head = rp->xmit_tail = 0;
801 rc_change_speed(tty, bp, rp);
802 spin_unlock_irqrestore(&riscom_lock, flags);
803 return 0;
806 /* Must be called with interrupts disabled */
807 static void rc_shutdown_port(struct tty_struct *tty,
808 struct riscom_board *bp, struct riscom_port *port)
810 #ifdef RC_REPORT_OVERRUN
811 printk(KERN_INFO "rc%d: port %d: Total %ld overruns were detected.\n",
812 board_No(bp), port_No(port), port->overrun);
813 #endif
814 #ifdef RC_REPORT_FIFO
816 int i;
818 printk(KERN_INFO "rc%d: port %d: FIFO hits [ ",
819 board_No(bp), port_No(port));
820 for (i = 0; i < 10; i++)
821 printk("%ld ", port->hits[i]);
822 printk("].\n");
824 #endif
825 tty_port_free_xmit_buf(&port->port);
827 /* Select port */
828 rc_out(bp, CD180_CAR, port_No(port));
829 /* Reset port */
830 rc_wait_CCR(bp);
831 rc_out(bp, CD180_CCR, CCR_SOFTRESET);
832 /* Disable all interrupts from this port */
833 port->IER = 0;
834 rc_out(bp, CD180_IER, port->IER);
836 set_bit(TTY_IO_ERROR, &tty->flags);
838 if (--bp->count < 0) {
839 printk(KERN_INFO "rc%d: rc_shutdown_port: "
840 "bad board count: %d\n",
841 board_No(bp), bp->count);
842 bp->count = 0;
845 * If this is the last opened port on the board
846 * shutdown whole board
848 if (!bp->count)
849 rc_shutdown_board(bp);
852 static int carrier_raised(struct tty_port *port)
854 struct riscom_port *p = container_of(port, struct riscom_port, port);
855 struct riscom_board *bp = port_Board(p);
856 unsigned long flags;
857 int CD;
859 spin_lock_irqsave(&riscom_lock, flags);
860 rc_out(bp, CD180_CAR, port_No(p));
861 CD = rc_in(bp, CD180_MSVR) & MSVR_CD;
862 rc_out(bp, CD180_MSVR, MSVR_RTS);
863 bp->DTR &= ~(1u << port_No(p));
864 rc_out(bp, RC_DTR, bp->DTR);
865 spin_unlock_irqrestore(&riscom_lock, flags);
866 return CD;
869 static void dtr_rts(struct tty_port *port, int onoff)
871 struct riscom_port *p = container_of(port, struct riscom_port, port);
872 struct riscom_board *bp = port_Board(p);
873 unsigned long flags;
875 spin_lock_irqsave(&riscom_lock, flags);
876 bp->DTR &= ~(1u << port_No(p));
877 if (onoff == 0)
878 bp->DTR |= (1u << port_No(p));
879 rc_out(bp, RC_DTR, bp->DTR);
880 spin_unlock_irqrestore(&riscom_lock, flags);
883 static int rc_open(struct tty_struct *tty, struct file *filp)
885 int board;
886 int error;
887 struct riscom_port *port;
888 struct riscom_board *bp;
890 board = RC_BOARD(tty->index);
891 if (board >= RC_NBOARD || !(rc_board[board].flags & RC_BOARD_PRESENT))
892 return -ENODEV;
894 bp = &rc_board[board];
895 port = rc_port + board * RC_NPORT + RC_PORT(tty->index);
896 if (rc_paranoia_check(port, tty->name, "rc_open"))
897 return -ENODEV;
899 error = rc_setup_board(bp);
900 if (error)
901 return error;
903 tty->driver_data = port;
904 return tty_port_open(&port->port, tty, filp);
907 static void rc_flush_buffer(struct tty_struct *tty)
909 struct riscom_port *port = tty->driver_data;
910 unsigned long flags;
912 if (rc_paranoia_check(port, tty->name, "rc_flush_buffer"))
913 return;
915 spin_lock_irqsave(&riscom_lock, flags);
916 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
917 spin_unlock_irqrestore(&riscom_lock, flags);
919 tty_wakeup(tty);
922 static void rc_close_port(struct tty_port *port)
924 unsigned long flags;
925 struct riscom_port *rp = container_of(port, struct riscom_port, port);
926 struct riscom_board *bp = port_Board(rp);
927 unsigned long timeout;
930 * At this point we stop accepting input. To do this, we
931 * disable the receive line status interrupts, and tell the
932 * interrupt driver to stop checking the data ready bit in the
933 * line status register.
936 spin_lock_irqsave(&riscom_lock, flags);
937 rp->IER &= ~IER_RXD;
939 rp->IER &= ~IER_TXRDY;
940 rp->IER |= IER_TXEMPTY;
941 rc_out(bp, CD180_CAR, port_No(rp));
942 rc_out(bp, CD180_IER, rp->IER);
944 * Before we drop DTR, make sure the UART transmitter
945 * has completely drained; this is especially
946 * important if there is a transmit FIFO!
948 timeout = jiffies + HZ;
949 while (rp->IER & IER_TXEMPTY) {
950 spin_unlock_irqrestore(&riscom_lock, flags);
951 msleep_interruptible(jiffies_to_msecs(rp->timeout));
952 spin_lock_irqsave(&riscom_lock, flags);
953 if (time_after(jiffies, timeout))
954 break;
956 rc_shutdown_port(port->tty, bp, rp);
957 spin_unlock_irqrestore(&riscom_lock, flags);
960 static void rc_close(struct tty_struct *tty, struct file *filp)
962 struct riscom_port *port = tty->driver_data;
964 if (!port || rc_paranoia_check(port, tty->name, "close"))
965 return;
966 tty_port_close(&port->port, tty, filp);
969 static int rc_write(struct tty_struct *tty,
970 const unsigned char *buf, int count)
972 struct riscom_port *port = tty->driver_data;
973 struct riscom_board *bp;
974 int c, total = 0;
975 unsigned long flags;
977 if (rc_paranoia_check(port, tty->name, "rc_write"))
978 return 0;
980 bp = port_Board(port);
982 while (1) {
983 spin_lock_irqsave(&riscom_lock, flags);
985 c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
986 SERIAL_XMIT_SIZE - port->xmit_head));
987 if (c <= 0)
988 break; /* lock continues to be held */
990 memcpy(port->port.xmit_buf + port->xmit_head, buf, c);
991 port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
992 port->xmit_cnt += c;
994 spin_unlock_irqrestore(&riscom_lock, flags);
996 buf += c;
997 count -= c;
998 total += c;
1001 if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1002 !(port->IER & IER_TXRDY)) {
1003 port->IER |= IER_TXRDY;
1004 rc_out(bp, CD180_CAR, port_No(port));
1005 rc_out(bp, CD180_IER, port->IER);
1008 spin_unlock_irqrestore(&riscom_lock, flags);
1010 return total;
1013 static int rc_put_char(struct tty_struct *tty, unsigned char ch)
1015 struct riscom_port *port = tty->driver_data;
1016 unsigned long flags;
1017 int ret = 0;
1019 if (rc_paranoia_check(port, tty->name, "rc_put_char"))
1020 return 0;
1022 spin_lock_irqsave(&riscom_lock, flags);
1024 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1025 goto out;
1027 port->port.xmit_buf[port->xmit_head++] = ch;
1028 port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1029 port->xmit_cnt++;
1030 ret = 1;
1032 out:
1033 spin_unlock_irqrestore(&riscom_lock, flags);
1034 return ret;
1037 static void rc_flush_chars(struct tty_struct *tty)
1039 struct riscom_port *port = tty->driver_data;
1040 unsigned long flags;
1042 if (rc_paranoia_check(port, tty->name, "rc_flush_chars"))
1043 return;
1045 if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped)
1046 return;
1048 spin_lock_irqsave(&riscom_lock, flags);
1050 port->IER |= IER_TXRDY;
1051 rc_out(port_Board(port), CD180_CAR, port_No(port));
1052 rc_out(port_Board(port), CD180_IER, port->IER);
1054 spin_unlock_irqrestore(&riscom_lock, flags);
1057 static int rc_write_room(struct tty_struct *tty)
1059 struct riscom_port *port = tty->driver_data;
1060 int ret;
1062 if (rc_paranoia_check(port, tty->name, "rc_write_room"))
1063 return 0;
1065 ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
1066 if (ret < 0)
1067 ret = 0;
1068 return ret;
1071 static int rc_chars_in_buffer(struct tty_struct *tty)
1073 struct riscom_port *port = tty->driver_data;
1075 if (rc_paranoia_check(port, tty->name, "rc_chars_in_buffer"))
1076 return 0;
1078 return port->xmit_cnt;
1081 static int rc_tiocmget(struct tty_struct *tty, struct file *file)
1083 struct riscom_port *port = tty->driver_data;
1084 struct riscom_board *bp;
1085 unsigned char status;
1086 unsigned int result;
1087 unsigned long flags;
1089 if (rc_paranoia_check(port, tty->name, __func__))
1090 return -ENODEV;
1092 bp = port_Board(port);
1094 spin_lock_irqsave(&riscom_lock, flags);
1096 rc_out(bp, CD180_CAR, port_No(port));
1097 status = rc_in(bp, CD180_MSVR);
1098 result = rc_in(bp, RC_RI) & (1u << port_No(port)) ? 0 : TIOCM_RNG;
1100 spin_unlock_irqrestore(&riscom_lock, flags);
1102 result |= ((status & MSVR_RTS) ? TIOCM_RTS : 0)
1103 | ((status & MSVR_DTR) ? TIOCM_DTR : 0)
1104 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1105 | ((status & MSVR_DSR) ? TIOCM_DSR : 0)
1106 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1107 return result;
1110 static int rc_tiocmset(struct tty_struct *tty, struct file *file,
1111 unsigned int set, unsigned int clear)
1113 struct riscom_port *port = tty->driver_data;
1114 unsigned long flags;
1115 struct riscom_board *bp;
1117 if (rc_paranoia_check(port, tty->name, __func__))
1118 return -ENODEV;
1120 bp = port_Board(port);
1122 spin_lock_irqsave(&riscom_lock, flags);
1124 if (set & TIOCM_RTS)
1125 port->MSVR |= MSVR_RTS;
1126 if (set & TIOCM_DTR)
1127 bp->DTR &= ~(1u << port_No(port));
1129 if (clear & TIOCM_RTS)
1130 port->MSVR &= ~MSVR_RTS;
1131 if (clear & TIOCM_DTR)
1132 bp->DTR |= (1u << port_No(port));
1134 rc_out(bp, CD180_CAR, port_No(port));
1135 rc_out(bp, CD180_MSVR, port->MSVR);
1136 rc_out(bp, RC_DTR, bp->DTR);
1138 spin_unlock_irqrestore(&riscom_lock, flags);
1140 return 0;
1143 static int rc_send_break(struct tty_struct *tty, int length)
1145 struct riscom_port *port = tty->driver_data;
1146 struct riscom_board *bp = port_Board(port);
1147 unsigned long flags;
1149 if (length == 0 || length == -1)
1150 return -EOPNOTSUPP;
1152 spin_lock_irqsave(&riscom_lock, flags);
1154 port->break_length = RISCOM_TPS / HZ * length;
1155 port->COR2 |= COR2_ETC;
1156 port->IER |= IER_TXRDY;
1157 rc_out(bp, CD180_CAR, port_No(port));
1158 rc_out(bp, CD180_COR2, port->COR2);
1159 rc_out(bp, CD180_IER, port->IER);
1160 rc_wait_CCR(bp);
1161 rc_out(bp, CD180_CCR, CCR_CORCHG2);
1162 rc_wait_CCR(bp);
1164 spin_unlock_irqrestore(&riscom_lock, flags);
1165 return 0;
1168 static int rc_set_serial_info(struct tty_struct *tty, struct riscom_port *port,
1169 struct serial_struct __user *newinfo)
1171 struct serial_struct tmp;
1172 struct riscom_board *bp = port_Board(port);
1173 int change_speed;
1175 if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
1176 return -EFAULT;
1178 mutex_lock(&port->port.mutex);
1179 change_speed = ((port->port.flags & ASYNC_SPD_MASK) !=
1180 (tmp.flags & ASYNC_SPD_MASK));
1182 if (!capable(CAP_SYS_ADMIN)) {
1183 if ((tmp.close_delay != port->port.close_delay) ||
1184 (tmp.closing_wait != port->port.closing_wait) ||
1185 ((tmp.flags & ~ASYNC_USR_MASK) !=
1186 (port->port.flags & ~ASYNC_USR_MASK))) {
1187 mutex_unlock(&port->port.mutex);
1188 return -EPERM;
1190 port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) |
1191 (tmp.flags & ASYNC_USR_MASK));
1192 } else {
1193 port->port.flags = ((port->port.flags & ~ASYNC_FLAGS) |
1194 (tmp.flags & ASYNC_FLAGS));
1195 port->port.close_delay = tmp.close_delay;
1196 port->port.closing_wait = tmp.closing_wait;
1198 if (change_speed) {
1199 unsigned long flags;
1201 spin_lock_irqsave(&riscom_lock, flags);
1202 rc_change_speed(tty, bp, port);
1203 spin_unlock_irqrestore(&riscom_lock, flags);
1205 mutex_unlock(&port->port.mutex);
1206 return 0;
1209 static int rc_get_serial_info(struct riscom_port *port,
1210 struct serial_struct __user *retinfo)
1212 struct serial_struct tmp;
1213 struct riscom_board *bp = port_Board(port);
1215 memset(&tmp, 0, sizeof(tmp));
1216 tmp.type = PORT_CIRRUS;
1217 tmp.line = port - rc_port;
1219 mutex_lock(&port->port.mutex);
1220 tmp.port = bp->base;
1221 tmp.irq = bp->irq;
1222 tmp.flags = port->port.flags;
1223 tmp.baud_base = (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC;
1224 tmp.close_delay = port->port.close_delay * HZ/100;
1225 tmp.closing_wait = port->port.closing_wait * HZ/100;
1226 mutex_unlock(&port->port.mutex);
1227 tmp.xmit_fifo_size = CD180_NFIFO;
1228 return copy_to_user(retinfo, &tmp, sizeof(tmp)) ? -EFAULT : 0;
1231 static int rc_ioctl(struct tty_struct *tty, struct file *filp,
1232 unsigned int cmd, unsigned long arg)
1234 struct riscom_port *port = tty->driver_data;
1235 void __user *argp = (void __user *)arg;
1236 int retval;
1238 if (rc_paranoia_check(port, tty->name, "rc_ioctl"))
1239 return -ENODEV;
1241 switch (cmd) {
1242 case TIOCGSERIAL:
1243 retval = rc_get_serial_info(port, argp);
1244 break;
1245 case TIOCSSERIAL:
1246 retval = rc_set_serial_info(tty, port, argp);
1247 break;
1248 default:
1249 retval = -ENOIOCTLCMD;
1251 return retval;
1254 static void rc_throttle(struct tty_struct *tty)
1256 struct riscom_port *port = tty->driver_data;
1257 struct riscom_board *bp;
1258 unsigned long flags;
1260 if (rc_paranoia_check(port, tty->name, "rc_throttle"))
1261 return;
1262 bp = port_Board(port);
1264 spin_lock_irqsave(&riscom_lock, flags);
1265 port->MSVR &= ~MSVR_RTS;
1266 rc_out(bp, CD180_CAR, port_No(port));
1267 if (I_IXOFF(tty)) {
1268 rc_wait_CCR(bp);
1269 rc_out(bp, CD180_CCR, CCR_SSCH2);
1270 rc_wait_CCR(bp);
1272 rc_out(bp, CD180_MSVR, port->MSVR);
1273 spin_unlock_irqrestore(&riscom_lock, flags);
1276 static void rc_unthrottle(struct tty_struct *tty)
1278 struct riscom_port *port = tty->driver_data;
1279 struct riscom_board *bp;
1280 unsigned long flags;
1282 if (rc_paranoia_check(port, tty->name, "rc_unthrottle"))
1283 return;
1284 bp = port_Board(port);
1286 spin_lock_irqsave(&riscom_lock, flags);
1287 port->MSVR |= MSVR_RTS;
1288 rc_out(bp, CD180_CAR, port_No(port));
1289 if (I_IXOFF(tty)) {
1290 rc_wait_CCR(bp);
1291 rc_out(bp, CD180_CCR, CCR_SSCH1);
1292 rc_wait_CCR(bp);
1294 rc_out(bp, CD180_MSVR, port->MSVR);
1295 spin_unlock_irqrestore(&riscom_lock, flags);
1298 static void rc_stop(struct tty_struct *tty)
1300 struct riscom_port *port = tty->driver_data;
1301 struct riscom_board *bp;
1302 unsigned long flags;
1304 if (rc_paranoia_check(port, tty->name, "rc_stop"))
1305 return;
1307 bp = port_Board(port);
1309 spin_lock_irqsave(&riscom_lock, flags);
1310 port->IER &= ~IER_TXRDY;
1311 rc_out(bp, CD180_CAR, port_No(port));
1312 rc_out(bp, CD180_IER, port->IER);
1313 spin_unlock_irqrestore(&riscom_lock, flags);
1316 static void rc_start(struct tty_struct *tty)
1318 struct riscom_port *port = tty->driver_data;
1319 struct riscom_board *bp;
1320 unsigned long flags;
1322 if (rc_paranoia_check(port, tty->name, "rc_start"))
1323 return;
1325 bp = port_Board(port);
1327 spin_lock_irqsave(&riscom_lock, flags);
1329 if (port->xmit_cnt && port->port.xmit_buf && !(port->IER & IER_TXRDY)) {
1330 port->IER |= IER_TXRDY;
1331 rc_out(bp, CD180_CAR, port_No(port));
1332 rc_out(bp, CD180_IER, port->IER);
1334 spin_unlock_irqrestore(&riscom_lock, flags);
1337 static void rc_hangup(struct tty_struct *tty)
1339 struct riscom_port *port = tty->driver_data;
1341 if (rc_paranoia_check(port, tty->name, "rc_hangup"))
1342 return;
1344 tty_port_hangup(&port->port);
1347 static void rc_set_termios(struct tty_struct *tty,
1348 struct ktermios *old_termios)
1350 struct riscom_port *port = tty->driver_data;
1351 unsigned long flags;
1353 if (rc_paranoia_check(port, tty->name, "rc_set_termios"))
1354 return;
1356 spin_lock_irqsave(&riscom_lock, flags);
1357 rc_change_speed(tty, port_Board(port), port);
1358 spin_unlock_irqrestore(&riscom_lock, flags);
1360 if ((old_termios->c_cflag & CRTSCTS) &&
1361 !(tty->termios->c_cflag & CRTSCTS)) {
1362 tty->hw_stopped = 0;
1363 rc_start(tty);
1367 static const struct tty_operations riscom_ops = {
1368 .open = rc_open,
1369 .close = rc_close,
1370 .write = rc_write,
1371 .put_char = rc_put_char,
1372 .flush_chars = rc_flush_chars,
1373 .write_room = rc_write_room,
1374 .chars_in_buffer = rc_chars_in_buffer,
1375 .flush_buffer = rc_flush_buffer,
1376 .ioctl = rc_ioctl,
1377 .throttle = rc_throttle,
1378 .unthrottle = rc_unthrottle,
1379 .set_termios = rc_set_termios,
1380 .stop = rc_stop,
1381 .start = rc_start,
1382 .hangup = rc_hangup,
1383 .tiocmget = rc_tiocmget,
1384 .tiocmset = rc_tiocmset,
1385 .break_ctl = rc_send_break,
1388 static const struct tty_port_operations riscom_port_ops = {
1389 .carrier_raised = carrier_raised,
1390 .dtr_rts = dtr_rts,
1391 .shutdown = rc_close_port,
1392 .activate = rc_activate_port,
1396 static int __init rc_init_drivers(void)
1398 int error;
1399 int i;
1401 riscom_driver = alloc_tty_driver(RC_NBOARD * RC_NPORT);
1402 if (!riscom_driver)
1403 return -ENOMEM;
1405 riscom_driver->owner = THIS_MODULE;
1406 riscom_driver->name = "ttyL";
1407 riscom_driver->major = RISCOM8_NORMAL_MAJOR;
1408 riscom_driver->type = TTY_DRIVER_TYPE_SERIAL;
1409 riscom_driver->subtype = SERIAL_TYPE_NORMAL;
1410 riscom_driver->init_termios = tty_std_termios;
1411 riscom_driver->init_termios.c_cflag =
1412 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1413 riscom_driver->init_termios.c_ispeed = 9600;
1414 riscom_driver->init_termios.c_ospeed = 9600;
1415 riscom_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK;
1416 tty_set_operations(riscom_driver, &riscom_ops);
1417 error = tty_register_driver(riscom_driver);
1418 if (error != 0) {
1419 put_tty_driver(riscom_driver);
1420 printk(KERN_ERR "rc: Couldn't register RISCom/8 driver, "
1421 "error = %d\n", error);
1422 return 1;
1424 memset(rc_port, 0, sizeof(rc_port));
1425 for (i = 0; i < RC_NPORT * RC_NBOARD; i++) {
1426 tty_port_init(&rc_port[i].port);
1427 rc_port[i].port.ops = &riscom_port_ops;
1428 rc_port[i].magic = RISCOM8_MAGIC;
1430 return 0;
1433 static void rc_release_drivers(void)
1435 tty_unregister_driver(riscom_driver);
1436 put_tty_driver(riscom_driver);
1439 #ifndef MODULE
1441 * Called at boot time.
1443 * You can specify IO base for up to RC_NBOARD cards,
1444 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
1445 * Note that there will be no probing at default
1446 * addresses in this case.
1449 static int __init riscom8_setup(char *str)
1451 int ints[RC_NBOARD];
1452 int i;
1454 str = get_options(str, ARRAY_SIZE(ints), ints);
1456 for (i = 0; i < RC_NBOARD; i++) {
1457 if (i < ints[0])
1458 rc_board[i].base = ints[i+1];
1459 else
1460 rc_board[i].base = 0;
1462 return 1;
1465 __setup("riscom8=", riscom8_setup);
1466 #endif
1468 static char banner[] __initdata =
1469 KERN_INFO "rc: SDL RISCom/8 card driver v1.1, (c) D.Gorodchanin "
1470 "1994-1996.\n";
1471 static char no_boards_msg[] __initdata =
1472 KERN_INFO "rc: No RISCom/8 boards detected.\n";
1475 * This routine must be called by kernel at boot time
1477 static int __init riscom8_init(void)
1479 int i;
1480 int found = 0;
1482 printk(banner);
1484 if (rc_init_drivers())
1485 return -EIO;
1487 for (i = 0; i < RC_NBOARD; i++)
1488 if (rc_board[i].base && !rc_probe(&rc_board[i]))
1489 found++;
1490 if (!found) {
1491 rc_release_drivers();
1492 printk(no_boards_msg);
1493 return -EIO;
1495 return 0;
1498 #ifdef MODULE
1499 static int iobase;
1500 static int iobase1;
1501 static int iobase2;
1502 static int iobase3;
1503 module_param(iobase, int, 0);
1504 module_param(iobase1, int, 0);
1505 module_param(iobase2, int, 0);
1506 module_param(iobase3, int, 0);
1508 MODULE_LICENSE("GPL");
1509 MODULE_ALIAS_CHARDEV_MAJOR(RISCOM8_NORMAL_MAJOR);
1510 #endif /* MODULE */
1513 * You can setup up to 4 boards (current value of RC_NBOARD)
1514 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter.
1517 static int __init riscom8_init_module(void)
1519 #ifdef MODULE
1520 int i;
1522 if (iobase || iobase1 || iobase2 || iobase3) {
1523 for (i = 0; i < RC_NBOARD; i++)
1524 rc_board[i].base = 0;
1527 if (iobase)
1528 rc_board[0].base = iobase;
1529 if (iobase1)
1530 rc_board[1].base = iobase1;
1531 if (iobase2)
1532 rc_board[2].base = iobase2;
1533 if (iobase3)
1534 rc_board[3].base = iobase3;
1535 #endif /* MODULE */
1537 return riscom8_init();
1540 static void __exit riscom8_exit_module(void)
1542 int i;
1544 rc_release_drivers();
1545 for (i = 0; i < RC_NBOARD; i++)
1546 if (rc_board[i].flags & RC_BOARD_PRESENT)
1547 rc_release_io_range(&rc_board[i]);
1551 module_init(riscom8_init_module);
1552 module_exit(riscom8_exit_module);