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)
78 #define RS_EVENT_WRITE_WAKEUP 0
80 static struct riscom_board
* IRQ_to_board
[16];
81 static struct tty_driver
*riscom_driver
;
82 static unsigned char * tmp_buf
;
83 static DECLARE_MUTEX(tmp_buf_sem
);
85 static unsigned long baud_table
[] = {
86 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
87 9600, 19200, 38400, 57600, 76800, 0,
90 static struct riscom_board rc_board
[RC_NBOARD
] = {
105 static struct riscom_port rc_port
[RC_NBOARD
* RC_NPORT
];
107 /* RISCom/8 I/O ports addresses (without address translation) */
108 static unsigned short rc_ioport
[] = {
110 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c,
112 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10,
113 0x11, 0x12, 0x18, 0x28, 0x31, 0x32, 0x39, 0x3a, 0x40, 0x41, 0x61, 0x62,
114 0x63, 0x64, 0x6b, 0x70, 0x71, 0x78, 0x7a, 0x7b, 0x7f, 0x100, 0x101
117 #define RC_NIOPORT (sizeof(rc_ioport) / sizeof(rc_ioport[0]))
120 static inline int rc_paranoia_check(struct riscom_port
const * port
,
121 char *name
, const char *routine
)
123 #ifdef RISCOM_PARANOIA_CHECK
124 static const char badmagic
[] = KERN_INFO
125 "rc: Warning: bad riscom port magic number for device %s in %s\n";
126 static const char badinfo
[] = KERN_INFO
127 "rc: Warning: null riscom port for device %s in %s\n";
130 printk(badinfo
, name
, routine
);
133 if (port
->magic
!= RISCOM8_MAGIC
) {
134 printk(badmagic
, name
, routine
);
143 * Service functions for RISCom/8 driver.
147 /* Get board number from pointer */
148 static inline int board_No (struct riscom_board
const * bp
)
150 return bp
- rc_board
;
153 /* Get port number from pointer */
154 static inline int port_No (struct riscom_port
const * port
)
156 return RC_PORT(port
- rc_port
);
159 /* Get pointer to board from pointer to port */
160 static inline struct riscom_board
* port_Board(struct riscom_port
const * port
)
162 return &rc_board
[RC_BOARD(port
- rc_port
)];
165 /* Input Byte from CL CD180 register */
166 static inline unsigned char rc_in(struct riscom_board
const * bp
, unsigned short reg
)
168 return inb(bp
->base
+ RC_TO_ISA(reg
));
171 /* Output Byte to CL CD180 register */
172 static inline void rc_out(struct riscom_board
const * bp
, unsigned short reg
,
175 outb(val
, bp
->base
+ RC_TO_ISA(reg
));
178 /* Wait for Channel Command Register ready */
179 static inline void rc_wait_CCR(struct riscom_board
const * bp
)
183 /* FIXME: need something more descriptive then 100000 :) */
184 for (delay
= 100000; delay
; delay
--)
185 if (!rc_in(bp
, CD180_CCR
))
188 printk(KERN_INFO
"rc%d: Timeout waiting for CCR.\n", board_No(bp
));
192 * RISCom/8 probe functions.
195 static inline int rc_request_io_range(struct riscom_board
* const bp
)
199 for (i
= 0; i
< RC_NIOPORT
; i
++)
200 if (!request_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1,
206 printk(KERN_INFO
"rc%d: Skipping probe at 0x%03x. IO address in use.\n",
207 board_No(bp
), bp
->base
);
209 release_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1);
213 static inline void rc_release_io_range(struct riscom_board
* const bp
)
217 for (i
= 0; i
< RC_NIOPORT
; i
++)
218 release_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1);
221 /* Must be called with enabled interrupts */
222 static inline void rc_long_delay(unsigned long delay
)
226 for (i
= jiffies
+ delay
; time_after(i
,jiffies
); ) ;
229 /* Reset and setup CD180 chip */
230 static void __init
rc_init_CD180(struct riscom_board
const * bp
)
234 save_flags(flags
); cli();
235 rc_out(bp
, RC_CTOUT
, 0); /* Clear timeout */
236 rc_wait_CCR(bp
); /* Wait for CCR ready */
237 rc_out(bp
, CD180_CCR
, CCR_HARDRESET
); /* Reset CD180 chip */
239 rc_long_delay(HZ
/20); /* Delay 0.05 sec */
241 rc_out(bp
, CD180_GIVR
, RC_ID
); /* Set ID for this chip */
242 rc_out(bp
, CD180_GICR
, 0); /* Clear all bits */
243 rc_out(bp
, CD180_PILR1
, RC_ACK_MINT
); /* Prio for modem intr */
244 rc_out(bp
, CD180_PILR2
, RC_ACK_TINT
); /* Prio for transmitter intr */
245 rc_out(bp
, CD180_PILR3
, RC_ACK_RINT
); /* Prio for receiver intr */
247 /* Setting up prescaler. We need 4 ticks per 1 ms */
248 rc_out(bp
, CD180_PPRH
, (RC_OSCFREQ
/(1000000/RISCOM_TPS
)) >> 8);
249 rc_out(bp
, CD180_PPRL
, (RC_OSCFREQ
/(1000000/RISCOM_TPS
)) & 0xff);
251 restore_flags(flags
);
254 /* Main probing routine, also sets irq. */
255 static int __init
rc_probe(struct riscom_board
*bp
)
257 unsigned char val1
, val2
;
263 if (rc_request_io_range(bp
))
266 /* Are the I/O ports here ? */
267 rc_out(bp
, CD180_PPRL
, 0x5a);
269 val1
= rc_in(bp
, CD180_PPRL
);
270 rc_out(bp
, CD180_PPRL
, 0xa5);
272 val2
= rc_in(bp
, CD180_PPRL
);
274 if ((val1
!= 0x5a) || (val2
!= 0xa5)) {
275 printk(KERN_ERR
"rc%d: RISCom/8 Board at 0x%03x not found.\n",
276 board_No(bp
), bp
->base
);
280 /* It's time to find IRQ for this board */
281 for (retries
= 0; retries
< 5 && irqs
<= 0; retries
++) {
282 irqs
= probe_irq_on();
283 rc_init_CD180(bp
); /* Reset CD180 chip */
284 rc_out(bp
, CD180_CAR
, 2); /* Select port 2 */
286 rc_out(bp
, CD180_CCR
, CCR_TXEN
); /* Enable transmitter */
287 rc_out(bp
, CD180_IER
, IER_TXRDY
); /* Enable tx empty intr */
288 rc_long_delay(HZ
/20);
289 irqs
= probe_irq_off(irqs
);
290 val1
= rc_in(bp
, RC_BSR
); /* Get Board Status reg */
291 val2
= rc_in(bp
, RC_ACK_TINT
); /* ACK interrupt */
292 rc_init_CD180(bp
); /* Reset CD180 again */
294 if ((val1
& RC_BSR_TINT
) || (val2
!= (RC_ID
| GIVR_IT_TX
))) {
295 printk(KERN_ERR
"rc%d: RISCom/8 Board at 0x%03x not "
296 "found.\n", board_No(bp
), bp
->base
);
302 printk(KERN_ERR
"rc%d: Can't find IRQ for RISCom/8 board "
303 "at 0x%03x.\n", board_No(bp
), bp
->base
);
307 bp
->flags
|= RC_BOARD_PRESENT
;
309 printk(KERN_INFO
"rc%d: RISCom/8 Rev. %c board detected at "
312 (rc_in(bp
, CD180_GFRCR
) & 0x0f) + 'A', /* Board revision */
317 rc_release_io_range(bp
);
323 * Interrupt processing routines.
327 static inline void rc_mark_event(struct riscom_port
* port
, int event
)
329 set_bit(event
, &port
->event
);
330 schedule_work(&port
->tqueue
);
333 static inline struct riscom_port
* rc_get_port(struct riscom_board
const * bp
,
334 unsigned char const * what
)
336 unsigned char channel
;
337 struct riscom_port
* port
;
339 channel
= rc_in(bp
, CD180_GICR
) >> GICR_CHAN_OFF
;
340 if (channel
< CD180_NCH
) {
341 port
= &rc_port
[board_No(bp
) * RC_NPORT
+ channel
];
342 if (port
->flags
& ASYNC_INITIALIZED
) {
346 printk(KERN_ERR
"rc%d: %s interrupt from invalid port %d\n",
347 board_No(bp
), what
, channel
);
351 static inline void rc_receive_exc(struct riscom_board
const * bp
)
353 struct riscom_port
*port
;
354 struct tty_struct
*tty
;
355 unsigned char status
;
358 if (!(port
= rc_get_port(bp
, "Receive")))
362 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
363 printk(KERN_WARNING
"rc%d: port %d: Working around flip "
364 "buffer overflow.\n",
365 board_No(bp
), port_No(port
));
369 #ifdef RC_REPORT_OVERRUN
370 status
= rc_in(bp
, CD180_RCSR
);
371 if (status
& RCSR_OE
) {
374 printk(KERN_ERR
"rc%d: port %d: Overrun. Total %ld overruns\n",
375 board_No(bp
), port_No(port
), port
->overrun
);
378 status
&= port
->mark_mask
;
380 status
= rc_in(bp
, CD180_RCSR
) & port
->mark_mask
;
382 ch
= rc_in(bp
, CD180_RDR
);
386 if (status
& RCSR_TOUT
) {
387 printk(KERN_WARNING
"rc%d: port %d: Receiver timeout. "
388 "Hardware problems ?\n",
389 board_No(bp
), port_No(port
));
392 } else if (status
& RCSR_BREAK
) {
393 printk(KERN_INFO
"rc%d: port %d: Handling break...\n",
394 board_No(bp
), port_No(port
));
395 *tty
->flip
.flag_buf_ptr
++ = TTY_BREAK
;
396 if (port
->flags
& ASYNC_SAK
)
399 } else if (status
& RCSR_PE
)
400 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
402 else if (status
& RCSR_FE
)
403 *tty
->flip
.flag_buf_ptr
++ = TTY_FRAME
;
405 else if (status
& RCSR_OE
)
406 *tty
->flip
.flag_buf_ptr
++ = TTY_OVERRUN
;
409 *tty
->flip
.flag_buf_ptr
++ = 0;
411 *tty
->flip
.char_buf_ptr
++ = ch
;
413 schedule_delayed_work(&tty
->flip
.work
, 1);
416 static inline void rc_receive(struct riscom_board
const * bp
)
418 struct riscom_port
*port
;
419 struct tty_struct
*tty
;
422 if (!(port
= rc_get_port(bp
, "Receive")))
427 count
= rc_in(bp
, CD180_RDCR
);
429 #ifdef RC_REPORT_FIFO
430 port
->hits
[count
> 8 ? 9 : count
]++;
434 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
435 printk(KERN_WARNING
"rc%d: port %d: Working around "
436 "flip buffer overflow.\n",
437 board_No(bp
), port_No(port
));
440 *tty
->flip
.char_buf_ptr
++ = rc_in(bp
, CD180_RDR
);
441 *tty
->flip
.flag_buf_ptr
++ = 0;
444 schedule_delayed_work(&tty
->flip
.work
, 1);
447 static inline void rc_transmit(struct riscom_board
const * bp
)
449 struct riscom_port
*port
;
450 struct tty_struct
*tty
;
454 if (!(port
= rc_get_port(bp
, "Transmit")))
459 if (port
->IER
& IER_TXEMPTY
) {
461 rc_out(bp
, CD180_CAR
, port_No(port
));
462 port
->IER
&= ~IER_TXEMPTY
;
463 rc_out(bp
, CD180_IER
, port
->IER
);
467 if ((port
->xmit_cnt
<= 0 && !port
->break_length
)
468 || tty
->stopped
|| tty
->hw_stopped
) {
469 rc_out(bp
, CD180_CAR
, port_No(port
));
470 port
->IER
&= ~IER_TXRDY
;
471 rc_out(bp
, CD180_IER
, port
->IER
);
475 if (port
->break_length
) {
476 if (port
->break_length
> 0) {
477 if (port
->COR2
& COR2_ETC
) {
478 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
479 rc_out(bp
, CD180_TDR
, CD180_C_SBRK
);
480 port
->COR2
&= ~COR2_ETC
;
482 count
= min_t(int, port
->break_length
, 0xff);
483 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
484 rc_out(bp
, CD180_TDR
, CD180_C_DELAY
);
485 rc_out(bp
, CD180_TDR
, count
);
486 if (!(port
->break_length
-= count
))
487 port
->break_length
--;
489 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
490 rc_out(bp
, CD180_TDR
, CD180_C_EBRK
);
491 rc_out(bp
, CD180_COR2
, port
->COR2
);
493 rc_out(bp
, CD180_CCR
, CCR_CORCHG2
);
494 port
->break_length
= 0;
501 rc_out(bp
, CD180_TDR
, port
->xmit_buf
[port
->xmit_tail
++]);
502 port
->xmit_tail
= port
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
503 if (--port
->xmit_cnt
<= 0)
505 } while (--count
> 0);
507 if (port
->xmit_cnt
<= 0) {
508 rc_out(bp
, CD180_CAR
, port_No(port
));
509 port
->IER
&= ~IER_TXRDY
;
510 rc_out(bp
, CD180_IER
, port
->IER
);
512 if (port
->xmit_cnt
<= port
->wakeup_chars
)
513 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
516 static inline void rc_check_modem(struct riscom_board
const * bp
)
518 struct riscom_port
*port
;
519 struct tty_struct
*tty
;
522 if (!(port
= rc_get_port(bp
, "Modem")))
527 mcr
= rc_in(bp
, CD180_MCR
);
528 if (mcr
& MCR_CDCHG
) {
529 if (rc_in(bp
, CD180_MSVR
) & MSVR_CD
)
530 wake_up_interruptible(&port
->open_wait
);
532 schedule_work(&port
->tqueue_hangup
);
535 #ifdef RISCOM_BRAIN_DAMAGED_CTS
536 if (mcr
& MCR_CTSCHG
) {
537 if (rc_in(bp
, CD180_MSVR
) & MSVR_CTS
) {
539 port
->IER
|= IER_TXRDY
;
540 if (port
->xmit_cnt
<= port
->wakeup_chars
)
541 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
544 port
->IER
&= ~IER_TXRDY
;
546 rc_out(bp
, CD180_IER
, port
->IER
);
548 if (mcr
& MCR_DSRCHG
) {
549 if (rc_in(bp
, CD180_MSVR
) & MSVR_DSR
) {
551 port
->IER
|= IER_TXRDY
;
552 if (port
->xmit_cnt
<= port
->wakeup_chars
)
553 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
556 port
->IER
&= ~IER_TXRDY
;
558 rc_out(bp
, CD180_IER
, port
->IER
);
560 #endif /* RISCOM_BRAIN_DAMAGED_CTS */
562 /* Clear change bits */
563 rc_out(bp
, CD180_MCR
, 0);
566 /* The main interrupt processing routine */
567 static irqreturn_t
rc_interrupt(int irq
, void * dev_id
, struct pt_regs
* regs
)
569 unsigned char status
;
571 struct riscom_board
*bp
;
572 unsigned long loop
= 0;
575 bp
= IRQ_to_board
[irq
];
577 if (!bp
|| !(bp
->flags
& RC_BOARD_ACTIVE
)) {
581 while ((++loop
< 16) && ((status
= ~(rc_in(bp
, RC_BSR
))) &
582 (RC_BSR_TOUT
| RC_BSR_TINT
|
583 RC_BSR_MINT
| RC_BSR_RINT
))) {
585 if (status
& RC_BSR_TOUT
)
586 printk(KERN_WARNING
"rc%d: Got timeout. Hardware "
587 "error?\n", board_No(bp
));
589 else if (status
& RC_BSR_RINT
) {
590 ack
= rc_in(bp
, RC_ACK_RINT
);
592 if (ack
== (RC_ID
| GIVR_IT_RCV
))
594 else if (ack
== (RC_ID
| GIVR_IT_REXC
))
597 printk(KERN_WARNING
"rc%d: Bad receive ack "
601 } else if (status
& RC_BSR_TINT
) {
602 ack
= rc_in(bp
, RC_ACK_TINT
);
604 if (ack
== (RC_ID
| GIVR_IT_TX
))
607 printk(KERN_WARNING
"rc%d: Bad transmit ack "
611 } else /* if (status & RC_BSR_MINT) */ {
612 ack
= rc_in(bp
, RC_ACK_MINT
);
614 if (ack
== (RC_ID
| GIVR_IT_MODEM
))
617 printk(KERN_WARNING
"rc%d: Bad modem ack "
623 rc_out(bp
, CD180_EOIR
, 0); /* Mark end of interrupt */
624 rc_out(bp
, RC_CTOUT
, 0); /* Clear timeout flag */
626 return IRQ_RETVAL(handled
);
630 * Routines for open & close processing.
633 /* Called with disabled interrupts */
634 static inline int rc_setup_board(struct riscom_board
* bp
)
638 if (bp
->flags
& RC_BOARD_ACTIVE
)
641 error
= request_irq(bp
->irq
, rc_interrupt
, SA_INTERRUPT
,
646 rc_out(bp
, RC_CTOUT
, 0); /* Just in case */
648 rc_out(bp
, RC_DTR
, bp
->DTR
); /* Drop DTR on all ports */
650 IRQ_to_board
[bp
->irq
] = bp
;
651 bp
->flags
|= RC_BOARD_ACTIVE
;
656 /* Called with disabled interrupts */
657 static inline void rc_shutdown_board(struct riscom_board
*bp
)
659 if (!(bp
->flags
& RC_BOARD_ACTIVE
))
662 bp
->flags
&= ~RC_BOARD_ACTIVE
;
664 free_irq(bp
->irq
, NULL
);
665 IRQ_to_board
[bp
->irq
] = NULL
;
668 rc_out(bp
, RC_DTR
, bp
->DTR
); /* Drop DTR on all ports */
673 * Setting up port characteristics.
674 * Must be called with disabled interrupts
676 static void rc_change_speed(struct riscom_board
*bp
, struct riscom_port
*port
)
678 struct tty_struct
*tty
;
681 unsigned char cor1
= 0, cor3
= 0;
682 unsigned char mcor1
= 0, mcor2
= 0;
684 if (!(tty
= port
->tty
) || !tty
->termios
)
689 port
->MSVR
= MSVR_RTS
;
693 if (baud
& CBAUDEX
) {
695 if (baud
< 1 || baud
> 2)
696 port
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
701 if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
703 if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
707 /* Select port on the board */
708 rc_out(bp
, CD180_CAR
, port_No(port
));
710 if (!baud_table
[baud
]) {
711 /* Drop DTR & exit */
712 bp
->DTR
|= (1u << port_No(port
));
713 rc_out(bp
, RC_DTR
, bp
->DTR
);
717 bp
->DTR
&= ~(1u << port_No(port
));
718 rc_out(bp
, RC_DTR
, bp
->DTR
);
722 * Now we must calculate some speed depended things
725 /* Set baud rate for port */
726 tmp
= (((RC_OSCFREQ
+ baud_table
[baud
]/2) / baud_table
[baud
] +
727 CD180_TPC
/2) / CD180_TPC
);
729 rc_out(bp
, CD180_RBPRH
, (tmp
>> 8) & 0xff);
730 rc_out(bp
, CD180_TBPRH
, (tmp
>> 8) & 0xff);
731 rc_out(bp
, CD180_RBPRL
, tmp
& 0xff);
732 rc_out(bp
, CD180_TBPRL
, tmp
& 0xff);
734 baud
= (baud_table
[baud
] + 5) / 10; /* Estimated CPS */
736 /* Two timer ticks seems enough to wakeup something like SLIP driver */
737 tmp
= ((baud
+ HZ
/2) / HZ
) * 2 - CD180_NFIFO
;
738 port
->wakeup_chars
= (tmp
< 0) ? 0 : ((tmp
>= SERIAL_XMIT_SIZE
) ?
739 SERIAL_XMIT_SIZE
- 1 : tmp
);
741 /* Receiver timeout will be transmission time for 1.5 chars */
742 tmp
= (RISCOM_TPS
+ RISCOM_TPS
/2 + baud
/2) / baud
;
743 tmp
= (tmp
> 0xff) ? 0xff : tmp
;
744 rc_out(bp
, CD180_RTPR
, tmp
);
746 switch (C_CSIZE(tty
)) {
766 cor1
|= COR1_NORMPAR
;
770 cor1
&= ~COR1_IGNORE
;
772 /* Set marking of some errors */
773 port
->mark_mask
= RCSR_OE
| RCSR_TOUT
;
775 port
->mark_mask
|= RCSR_FE
| RCSR_PE
;
776 if (I_BRKINT(tty
) || I_PARMRK(tty
))
777 port
->mark_mask
|= RCSR_BREAK
;
779 port
->mark_mask
&= ~(RCSR_FE
| RCSR_PE
);
781 port
->mark_mask
&= ~RCSR_BREAK
;
783 /* Real raw mode. Ignore all */
784 port
->mark_mask
&= ~RCSR_OE
;
786 /* Enable Hardware Flow Control */
787 if (C_CRTSCTS(tty
)) {
788 #ifdef RISCOM_BRAIN_DAMAGED_CTS
789 port
->IER
|= IER_DSR
| IER_CTS
;
790 mcor1
|= MCOR1_DSRZD
| MCOR1_CTSZD
;
791 mcor2
|= MCOR2_DSROD
| MCOR2_CTSOD
;
792 tty
->hw_stopped
= !(rc_in(bp
, CD180_MSVR
) & (MSVR_CTS
|MSVR_DSR
));
794 port
->COR2
|= COR2_CTSAE
;
797 /* Enable Software Flow Control. FIXME: I'm not sure about this */
798 /* Some people reported that it works, but I still doubt */
800 port
->COR2
|= COR2_TXIBE
;
801 cor3
|= (COR3_FCT
| COR3_SCDE
);
803 port
->COR2
|= COR2_IXM
;
804 rc_out(bp
, CD180_SCHR1
, START_CHAR(tty
));
805 rc_out(bp
, CD180_SCHR2
, STOP_CHAR(tty
));
806 rc_out(bp
, CD180_SCHR3
, START_CHAR(tty
));
807 rc_out(bp
, CD180_SCHR4
, STOP_CHAR(tty
));
809 if (!C_CLOCAL(tty
)) {
810 /* Enable CD check */
817 /* Enable receiver */
818 port
->IER
|= IER_RXD
;
820 /* Set input FIFO size (1-8 bytes) */
821 cor3
|= RISCOM_RXFIFO
;
822 /* Setting up CD180 channel registers */
823 rc_out(bp
, CD180_COR1
, cor1
);
824 rc_out(bp
, CD180_COR2
, port
->COR2
);
825 rc_out(bp
, CD180_COR3
, cor3
);
826 /* Make CD180 know about registers change */
828 rc_out(bp
, CD180_CCR
, CCR_CORCHG1
| CCR_CORCHG2
| CCR_CORCHG3
);
829 /* Setting up modem option registers */
830 rc_out(bp
, CD180_MCOR1
, mcor1
);
831 rc_out(bp
, CD180_MCOR2
, mcor2
);
832 /* Enable CD180 transmitter & receiver */
834 rc_out(bp
, CD180_CCR
, CCR_TXEN
| CCR_RXEN
);
835 /* Enable interrupts */
836 rc_out(bp
, CD180_IER
, port
->IER
);
837 /* And finally set RTS on */
838 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
841 /* Must be called with interrupts enabled */
842 static int rc_setup_port(struct riscom_board
*bp
, struct riscom_port
*port
)
846 if (port
->flags
& ASYNC_INITIALIZED
)
849 if (!port
->xmit_buf
) {
850 /* We may sleep in get_zeroed_page() */
853 if (!(tmp
= get_zeroed_page(GFP_KERNEL
)))
856 if (port
->xmit_buf
) {
860 port
->xmit_buf
= (unsigned char *) tmp
;
863 save_flags(flags
); cli();
866 clear_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
868 if (port
->count
== 1)
871 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
872 rc_change_speed(bp
, port
);
873 port
->flags
|= ASYNC_INITIALIZED
;
875 restore_flags(flags
);
879 /* Must be called with interrupts disabled */
880 static void rc_shutdown_port(struct riscom_board
*bp
, struct riscom_port
*port
)
882 struct tty_struct
*tty
;
884 if (!(port
->flags
& ASYNC_INITIALIZED
))
887 #ifdef RC_REPORT_OVERRUN
888 printk(KERN_INFO
"rc%d: port %d: Total %ld overruns were detected.\n",
889 board_No(bp
), port_No(port
), port
->overrun
);
891 #ifdef RC_REPORT_FIFO
895 printk(KERN_INFO
"rc%d: port %d: FIFO hits [ ",
896 board_No(bp
), port_No(port
));
897 for (i
= 0; i
< 10; i
++) {
898 printk("%ld ", port
->hits
[i
]);
903 if (port
->xmit_buf
) {
904 free_page((unsigned long) port
->xmit_buf
);
905 port
->xmit_buf
= NULL
;
908 if (!(tty
= port
->tty
) || C_HUPCL(tty
)) {
910 bp
->DTR
|= (1u << port_No(port
));
911 rc_out(bp
, RC_DTR
, bp
->DTR
);
915 rc_out(bp
, CD180_CAR
, port_No(port
));
918 rc_out(bp
, CD180_CCR
, CCR_SOFTRESET
);
919 /* Disable all interrupts from this port */
921 rc_out(bp
, CD180_IER
, port
->IER
);
924 set_bit(TTY_IO_ERROR
, &tty
->flags
);
925 port
->flags
&= ~ASYNC_INITIALIZED
;
927 if (--bp
->count
< 0) {
928 printk(KERN_INFO
"rc%d: rc_shutdown_port: "
929 "bad board count: %d\n",
930 board_No(bp
), bp
->count
);
935 * If this is the last opened port on the board
936 * shutdown whole board
939 rc_shutdown_board(bp
);
943 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
944 struct riscom_port
*port
)
946 DECLARE_WAITQUEUE(wait
, current
);
947 struct riscom_board
*bp
= port_Board(port
);
953 * If the device is in the middle of being closed, then block
954 * until it's done, and then try again.
956 if (tty_hung_up_p(filp
) || port
->flags
& ASYNC_CLOSING
) {
957 interruptible_sleep_on(&port
->close_wait
);
958 if (port
->flags
& ASYNC_HUP_NOTIFY
)
965 * If non-blocking mode is set, or the port is not enabled,
966 * then make the check up front and then exit.
968 if ((filp
->f_flags
& O_NONBLOCK
) ||
969 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
970 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
978 * Block waiting for the carrier detect and the line to become
979 * free (i.e., not in use by the callout). While we are in
980 * this loop, info->count is dropped by one, so that
981 * rs_close() knows when to free things. We restore it upon
982 * exit, either normal or abnormal.
985 add_wait_queue(&port
->open_wait
, &wait
);
987 if (!tty_hung_up_p(filp
))
990 port
->blocked_open
++;
993 rc_out(bp
, CD180_CAR
, port_No(port
));
994 CD
= rc_in(bp
, CD180_MSVR
) & MSVR_CD
;
995 rc_out(bp
, CD180_MSVR
, MSVR_RTS
);
996 bp
->DTR
&= ~(1u << port_No(port
));
997 rc_out(bp
, RC_DTR
, bp
->DTR
);
999 set_current_state(TASK_INTERRUPTIBLE
);
1000 if (tty_hung_up_p(filp
) ||
1001 !(port
->flags
& ASYNC_INITIALIZED
)) {
1002 if (port
->flags
& ASYNC_HUP_NOTIFY
)
1005 retval
= -ERESTARTSYS
;
1008 if (!(port
->flags
& ASYNC_CLOSING
) &&
1011 if (signal_pending(current
)) {
1012 retval
= -ERESTARTSYS
;
1017 current
->state
= TASK_RUNNING
;
1018 remove_wait_queue(&port
->open_wait
, &wait
);
1019 if (!tty_hung_up_p(filp
))
1021 port
->blocked_open
--;
1025 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
1029 static int rc_open(struct tty_struct
* tty
, struct file
* filp
)
1033 struct riscom_port
* port
;
1034 struct riscom_board
* bp
;
1036 board
= RC_BOARD(tty
->index
);
1037 if (board
>= RC_NBOARD
|| !(rc_board
[board
].flags
& RC_BOARD_PRESENT
))
1040 bp
= &rc_board
[board
];
1041 port
= rc_port
+ board
* RC_NPORT
+ RC_PORT(tty
->index
);
1042 if (rc_paranoia_check(port
, tty
->name
, "rc_open"))
1045 if ((error
= rc_setup_board(bp
)))
1049 tty
->driver_data
= port
;
1052 if ((error
= rc_setup_port(bp
, port
)))
1055 if ((error
= block_til_ready(tty
, filp
, port
)))
1061 static void rc_close(struct tty_struct
* tty
, struct file
* filp
)
1063 struct riscom_port
*port
= (struct riscom_port
*) tty
->driver_data
;
1064 struct riscom_board
*bp
;
1065 unsigned long flags
;
1066 unsigned long timeout
;
1068 if (!port
|| rc_paranoia_check(port
, tty
->name
, "close"))
1071 save_flags(flags
); cli();
1072 if (tty_hung_up_p(filp
))
1075 bp
= port_Board(port
);
1076 if ((tty
->count
== 1) && (port
->count
!= 1)) {
1077 printk(KERN_INFO
"rc%d: rc_close: bad port count;"
1078 " tty->count is 1, port count is %d\n",
1079 board_No(bp
), port
->count
);
1082 if (--port
->count
< 0) {
1083 printk(KERN_INFO
"rc%d: rc_close: bad port count "
1085 board_No(bp
), port_No(port
), port
->count
);
1090 port
->flags
|= ASYNC_CLOSING
;
1092 * Now we wait for the transmit buffer to clear; and we notify
1093 * the line discipline to only process XON/XOFF characters.
1096 if (port
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1097 tty_wait_until_sent(tty
, port
->closing_wait
);
1099 * At this point we stop accepting input. To do this, we
1100 * disable the receive line status interrupts, and tell the
1101 * interrupt driver to stop checking the data ready bit in the
1102 * line status register.
1104 port
->IER
&= ~IER_RXD
;
1105 if (port
->flags
& ASYNC_INITIALIZED
) {
1106 port
->IER
&= ~IER_TXRDY
;
1107 port
->IER
|= IER_TXEMPTY
;
1108 rc_out(bp
, CD180_CAR
, port_No(port
));
1109 rc_out(bp
, CD180_IER
, port
->IER
);
1111 * Before we drop DTR, make sure the UART transmitter
1112 * has completely drained; this is especially
1113 * important if there is a transmit FIFO!
1115 timeout
= jiffies
+HZ
;
1116 while(port
->IER
& IER_TXEMPTY
) {
1117 current
->state
= TASK_INTERRUPTIBLE
;
1118 schedule_timeout(port
->timeout
);
1119 if (time_after(jiffies
, timeout
))
1123 rc_shutdown_port(bp
, port
);
1124 if (tty
->driver
->flush_buffer
)
1125 tty
->driver
->flush_buffer(tty
);
1126 tty_ldisc_flush(tty
);
1131 if (port
->blocked_open
) {
1132 if (port
->close_delay
) {
1133 current
->state
= TASK_INTERRUPTIBLE
;
1134 schedule_timeout(port
->close_delay
);
1136 wake_up_interruptible(&port
->open_wait
);
1138 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1139 wake_up_interruptible(&port
->close_wait
);
1140 out
: restore_flags(flags
);
1143 static int rc_write(struct tty_struct
* tty
, int from_user
,
1144 const unsigned char *buf
, int count
)
1146 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1147 struct riscom_board
*bp
;
1149 unsigned long flags
;
1151 if (rc_paranoia_check(port
, tty
->name
, "rc_write"))
1154 bp
= port_Board(port
);
1156 if (!tty
|| !port
->xmit_buf
|| !tmp_buf
)
1164 c
= min_t(int, count
, min(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1165 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1169 c
-= copy_from_user(tmp_buf
, buf
, c
);
1177 c
= min_t(int, c
, min(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1178 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1179 memcpy(port
->xmit_buf
+ port
->xmit_head
, tmp_buf
, c
);
1180 port
->xmit_head
= (port
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
1181 port
->xmit_cnt
+= c
;
1182 restore_flags(flags
);
1192 c
= min_t(int, count
, min(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1193 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1195 restore_flags(flags
);
1199 memcpy(port
->xmit_buf
+ port
->xmit_head
, buf
, c
);
1200 port
->xmit_head
= (port
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
1201 port
->xmit_cnt
+= c
;
1202 restore_flags(flags
);
1211 if (port
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
&&
1212 !(port
->IER
& IER_TXRDY
)) {
1213 port
->IER
|= IER_TXRDY
;
1214 rc_out(bp
, CD180_CAR
, port_No(port
));
1215 rc_out(bp
, CD180_IER
, port
->IER
);
1217 restore_flags(flags
);
1222 static void rc_put_char(struct tty_struct
* tty
, unsigned char ch
)
1224 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1225 unsigned long flags
;
1227 if (rc_paranoia_check(port
, tty
->name
, "rc_put_char"))
1230 if (!tty
|| !port
->xmit_buf
)
1233 save_flags(flags
); cli();
1235 if (port
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1)
1238 port
->xmit_buf
[port
->xmit_head
++] = ch
;
1239 port
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
1241 out
: restore_flags(flags
);
1244 static void rc_flush_chars(struct tty_struct
* tty
)
1246 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1247 unsigned long flags
;
1249 if (rc_paranoia_check(port
, tty
->name
, "rc_flush_chars"))
1252 if (port
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
1256 save_flags(flags
); cli();
1257 port
->IER
|= IER_TXRDY
;
1258 rc_out(port_Board(port
), CD180_CAR
, port_No(port
));
1259 rc_out(port_Board(port
), CD180_IER
, port
->IER
);
1260 restore_flags(flags
);
1263 static int rc_write_room(struct tty_struct
* tty
)
1265 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1268 if (rc_paranoia_check(port
, tty
->name
, "rc_write_room"))
1271 ret
= SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1;
1277 static int rc_chars_in_buffer(struct tty_struct
*tty
)
1279 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1281 if (rc_paranoia_check(port
, tty
->name
, "rc_chars_in_buffer"))
1284 return port
->xmit_cnt
;
1287 static void rc_flush_buffer(struct tty_struct
*tty
)
1289 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1290 unsigned long flags
;
1292 if (rc_paranoia_check(port
, tty
->name
, "rc_flush_buffer"))
1295 save_flags(flags
); cli();
1296 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
1297 restore_flags(flags
);
1299 wake_up_interruptible(&tty
->write_wait
);
1303 static int rc_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1305 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1306 struct riscom_board
* bp
;
1307 unsigned char status
;
1308 unsigned int result
;
1309 unsigned long flags
;
1311 if (rc_paranoia_check(port
, tty
->name
, __FUNCTION__
))
1314 bp
= port_Board(port
);
1315 save_flags(flags
); cli();
1316 rc_out(bp
, CD180_CAR
, port_No(port
));
1317 status
= rc_in(bp
, CD180_MSVR
);
1318 result
= rc_in(bp
, RC_RI
) & (1u << port_No(port
)) ? 0 : TIOCM_RNG
;
1319 restore_flags(flags
);
1320 result
|= ((status
& MSVR_RTS
) ? TIOCM_RTS
: 0)
1321 | ((status
& MSVR_DTR
) ? TIOCM_DTR
: 0)
1322 | ((status
& MSVR_CD
) ? TIOCM_CAR
: 0)
1323 | ((status
& MSVR_DSR
) ? TIOCM_DSR
: 0)
1324 | ((status
& MSVR_CTS
) ? TIOCM_CTS
: 0);
1328 static int rc_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1329 unsigned int set
, unsigned int clear
)
1331 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1332 unsigned long flags
;
1333 struct riscom_board
*bp
;
1335 if (rc_paranoia_check(port
, tty
->name
, __FUNCTION__
))
1338 bp
= port_Board(port
);
1340 save_flags(flags
); cli();
1341 if (set
& TIOCM_RTS
)
1342 port
->MSVR
|= MSVR_RTS
;
1343 if (set
& TIOCM_DTR
)
1344 bp
->DTR
&= ~(1u << port_No(port
));
1346 if (clear
& TIOCM_RTS
)
1347 port
->MSVR
&= ~MSVR_RTS
;
1348 if (clear
& TIOCM_DTR
)
1349 bp
->DTR
|= (1u << port_No(port
));
1351 rc_out(bp
, CD180_CAR
, port_No(port
));
1352 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1353 rc_out(bp
, RC_DTR
, bp
->DTR
);
1354 restore_flags(flags
);
1358 static inline void rc_send_break(struct riscom_port
* port
, unsigned long length
)
1360 struct riscom_board
*bp
= port_Board(port
);
1361 unsigned long flags
;
1363 save_flags(flags
); cli();
1364 port
->break_length
= RISCOM_TPS
/ HZ
* length
;
1365 port
->COR2
|= COR2_ETC
;
1366 port
->IER
|= IER_TXRDY
;
1367 rc_out(bp
, CD180_CAR
, port_No(port
));
1368 rc_out(bp
, CD180_COR2
, port
->COR2
);
1369 rc_out(bp
, CD180_IER
, port
->IER
);
1371 rc_out(bp
, CD180_CCR
, CCR_CORCHG2
);
1373 restore_flags(flags
);
1376 static inline int rc_set_serial_info(struct riscom_port
* port
,
1377 struct serial_struct __user
* newinfo
)
1379 struct serial_struct tmp
;
1380 struct riscom_board
*bp
= port_Board(port
);
1382 unsigned long flags
;
1384 if (copy_from_user(&tmp
, newinfo
, sizeof(tmp
)))
1388 if ((tmp
.irq
!= bp
->irq
) ||
1389 (tmp
.port
!= bp
->base
) ||
1390 (tmp
.type
!= PORT_CIRRUS
) ||
1391 (tmp
.baud_base
!= (RC_OSCFREQ
+ CD180_TPC
/2) / CD180_TPC
) ||
1392 (tmp
.custom_divisor
!= 0) ||
1393 (tmp
.xmit_fifo_size
!= CD180_NFIFO
) ||
1394 (tmp
.flags
& ~RISCOM_LEGAL_FLAGS
))
1398 change_speed
= ((port
->flags
& ASYNC_SPD_MASK
) !=
1399 (tmp
.flags
& ASYNC_SPD_MASK
));
1401 if (!capable(CAP_SYS_ADMIN
)) {
1402 if ((tmp
.close_delay
!= port
->close_delay
) ||
1403 (tmp
.closing_wait
!= port
->closing_wait
) ||
1404 ((tmp
.flags
& ~ASYNC_USR_MASK
) !=
1405 (port
->flags
& ~ASYNC_USR_MASK
)))
1407 port
->flags
= ((port
->flags
& ~ASYNC_USR_MASK
) |
1408 (tmp
.flags
& ASYNC_USR_MASK
));
1410 port
->flags
= ((port
->flags
& ~ASYNC_FLAGS
) |
1411 (tmp
.flags
& ASYNC_FLAGS
));
1412 port
->close_delay
= tmp
.close_delay
;
1413 port
->closing_wait
= tmp
.closing_wait
;
1416 save_flags(flags
); cli();
1417 rc_change_speed(bp
, port
);
1418 restore_flags(flags
);
1423 static inline int rc_get_serial_info(struct riscom_port
* port
,
1424 struct serial_struct __user
*retinfo
)
1426 struct serial_struct tmp
;
1427 struct riscom_board
*bp
= port_Board(port
);
1429 memset(&tmp
, 0, sizeof(tmp
));
1430 tmp
.type
= PORT_CIRRUS
;
1431 tmp
.line
= port
- rc_port
;
1432 tmp
.port
= bp
->base
;
1434 tmp
.flags
= port
->flags
;
1435 tmp
.baud_base
= (RC_OSCFREQ
+ CD180_TPC
/2) / CD180_TPC
;
1436 tmp
.close_delay
= port
->close_delay
* HZ
/100;
1437 tmp
.closing_wait
= port
->closing_wait
* HZ
/100;
1438 tmp
.xmit_fifo_size
= CD180_NFIFO
;
1439 return copy_to_user(retinfo
, &tmp
, sizeof(tmp
)) ? -EFAULT
: 0;
1442 static int rc_ioctl(struct tty_struct
* tty
, struct file
* filp
,
1443 unsigned int cmd
, unsigned long arg
)
1446 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1447 void __user
*argp
= (void __user
*)arg
;
1450 if (rc_paranoia_check(port
, tty
->name
, "rc_ioctl"))
1454 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1455 retval
= tty_check_change(tty
);
1458 tty_wait_until_sent(tty
, 0);
1460 rc_send_break(port
, HZ
/4); /* 1/4 second */
1462 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1463 retval
= tty_check_change(tty
);
1466 tty_wait_until_sent(tty
, 0);
1467 rc_send_break(port
, arg
? arg
*(HZ
/10) : HZ
/4);
1470 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned __user
*)argp
);
1472 if (get_user(arg
,(unsigned __user
*) argp
))
1474 tty
->termios
->c_cflag
=
1475 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1476 (arg
? CLOCAL
: 0));
1479 return rc_get_serial_info(port
, argp
);
1481 return rc_set_serial_info(port
, argp
);
1483 return -ENOIOCTLCMD
;
1488 static void rc_throttle(struct tty_struct
* tty
)
1490 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1491 struct riscom_board
*bp
;
1492 unsigned long flags
;
1494 if (rc_paranoia_check(port
, tty
->name
, "rc_throttle"))
1497 bp
= port_Board(port
);
1499 save_flags(flags
); cli();
1500 port
->MSVR
&= ~MSVR_RTS
;
1501 rc_out(bp
, CD180_CAR
, port_No(port
));
1504 rc_out(bp
, CD180_CCR
, CCR_SSCH2
);
1507 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1508 restore_flags(flags
);
1511 static void rc_unthrottle(struct tty_struct
* tty
)
1513 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1514 struct riscom_board
*bp
;
1515 unsigned long flags
;
1517 if (rc_paranoia_check(port
, tty
->name
, "rc_unthrottle"))
1520 bp
= port_Board(port
);
1522 save_flags(flags
); cli();
1523 port
->MSVR
|= MSVR_RTS
;
1524 rc_out(bp
, CD180_CAR
, port_No(port
));
1527 rc_out(bp
, CD180_CCR
, CCR_SSCH1
);
1530 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1531 restore_flags(flags
);
1534 static void rc_stop(struct tty_struct
* tty
)
1536 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1537 struct riscom_board
*bp
;
1538 unsigned long flags
;
1540 if (rc_paranoia_check(port
, tty
->name
, "rc_stop"))
1543 bp
= port_Board(port
);
1545 save_flags(flags
); cli();
1546 port
->IER
&= ~IER_TXRDY
;
1547 rc_out(bp
, CD180_CAR
, port_No(port
));
1548 rc_out(bp
, CD180_IER
, port
->IER
);
1549 restore_flags(flags
);
1552 static void rc_start(struct tty_struct
* tty
)
1554 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1555 struct riscom_board
*bp
;
1556 unsigned long flags
;
1558 if (rc_paranoia_check(port
, tty
->name
, "rc_start"))
1561 bp
= port_Board(port
);
1563 save_flags(flags
); cli();
1564 if (port
->xmit_cnt
&& port
->xmit_buf
&& !(port
->IER
& IER_TXRDY
)) {
1565 port
->IER
|= IER_TXRDY
;
1566 rc_out(bp
, CD180_CAR
, port_No(port
));
1567 rc_out(bp
, CD180_IER
, port
->IER
);
1569 restore_flags(flags
);
1573 * This routine is called from the work queue when the interrupt
1574 * routine has signalled that a hangup has occurred. The path of
1575 * hangup processing is:
1577 * serial interrupt routine -> (workqueue) ->
1578 * do_rc_hangup() -> tty->hangup() -> rc_hangup()
1581 static void do_rc_hangup(void *private_
)
1583 struct riscom_port
*port
= (struct riscom_port
*) private_
;
1584 struct tty_struct
*tty
;
1588 tty_hangup(tty
); /* FIXME: module removal race still here */
1591 static void rc_hangup(struct tty_struct
* tty
)
1593 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1594 struct riscom_board
*bp
;
1596 if (rc_paranoia_check(port
, tty
->name
, "rc_hangup"))
1599 bp
= port_Board(port
);
1601 rc_shutdown_port(bp
, port
);
1604 port
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1606 wake_up_interruptible(&port
->open_wait
);
1609 static void rc_set_termios(struct tty_struct
* tty
, struct termios
* old_termios
)
1611 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1612 unsigned long flags
;
1614 if (rc_paranoia_check(port
, tty
->name
, "rc_set_termios"))
1617 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
&&
1618 tty
->termios
->c_iflag
== old_termios
->c_iflag
)
1621 save_flags(flags
); cli();
1622 rc_change_speed(port_Board(port
), port
);
1623 restore_flags(flags
);
1625 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1626 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1627 tty
->hw_stopped
= 0;
1632 static void do_softint(void *private_
)
1634 struct riscom_port
*port
= (struct riscom_port
*) private_
;
1635 struct tty_struct
*tty
;
1637 if(!(tty
= port
->tty
))
1640 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &port
->event
)) {
1642 wake_up_interruptible(&tty
->write_wait
);
1646 static struct tty_operations riscom_ops
= {
1650 .put_char
= rc_put_char
,
1651 .flush_chars
= rc_flush_chars
,
1652 .write_room
= rc_write_room
,
1653 .chars_in_buffer
= rc_chars_in_buffer
,
1654 .flush_buffer
= rc_flush_buffer
,
1656 .throttle
= rc_throttle
,
1657 .unthrottle
= rc_unthrottle
,
1658 .set_termios
= rc_set_termios
,
1661 .hangup
= rc_hangup
,
1662 .tiocmget
= rc_tiocmget
,
1663 .tiocmset
= rc_tiocmset
,
1666 static inline int rc_init_drivers(void)
1671 riscom_driver
= alloc_tty_driver(RC_NBOARD
* RC_NPORT
);
1675 if (!(tmp_buf
= (unsigned char *) get_zeroed_page(GFP_KERNEL
))) {
1676 printk(KERN_ERR
"rc: Couldn't get free page.\n");
1677 put_tty_driver(riscom_driver
);
1680 memset(IRQ_to_board
, 0, sizeof(IRQ_to_board
));
1681 riscom_driver
->owner
= THIS_MODULE
;
1682 riscom_driver
->name
= "ttyL";
1683 riscom_driver
->devfs_name
= "tts/L";
1684 riscom_driver
->major
= RISCOM8_NORMAL_MAJOR
;
1685 riscom_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1686 riscom_driver
->subtype
= SERIAL_TYPE_NORMAL
;
1687 riscom_driver
->init_termios
= tty_std_termios
;
1688 riscom_driver
->init_termios
.c_cflag
=
1689 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1690 riscom_driver
->flags
= TTY_DRIVER_REAL_RAW
;
1691 tty_set_operations(riscom_driver
, &riscom_ops
);
1692 if ((error
= tty_register_driver(riscom_driver
))) {
1693 free_page((unsigned long)tmp_buf
);
1694 put_tty_driver(riscom_driver
);
1695 printk(KERN_ERR
"rc: Couldn't register RISCom/8 driver, "
1701 memset(rc_port
, 0, sizeof(rc_port
));
1702 for (i
= 0; i
< RC_NPORT
* RC_NBOARD
; i
++) {
1703 rc_port
[i
].magic
= RISCOM8_MAGIC
;
1704 INIT_WORK(&rc_port
[i
].tqueue
, do_softint
, &rc_port
[i
]);
1705 INIT_WORK(&rc_port
[i
].tqueue_hangup
, do_rc_hangup
, &rc_port
[i
]);
1706 rc_port
[i
].close_delay
= 50 * HZ
/100;
1707 rc_port
[i
].closing_wait
= 3000 * HZ
/100;
1708 init_waitqueue_head(&rc_port
[i
].open_wait
);
1709 init_waitqueue_head(&rc_port
[i
].close_wait
);
1715 static void rc_release_drivers(void)
1717 unsigned long flags
;
1721 free_page((unsigned long)tmp_buf
);
1722 tty_unregister_driver(riscom_driver
);
1723 put_tty_driver(riscom_driver
);
1724 restore_flags(flags
);
1729 * Called at boot time.
1731 * You can specify IO base for up to RC_NBOARD cards,
1732 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
1733 * Note that there will be no probing at default
1734 * addresses in this case.
1737 static int __init
riscom8_setup(char *str
)
1739 int ints
[RC_NBOARD
];
1742 str
= get_options(str
, ARRAY_SIZE(ints
), ints
);
1744 for (i
= 0; i
< RC_NBOARD
; i
++) {
1746 rc_board
[i
].base
= ints
[i
+1];
1748 rc_board
[i
].base
= 0;
1753 __setup("riscom8=", riscom8_setup
);
1756 static char banner
[] __initdata
=
1757 KERN_INFO
"rc: SDL RISCom/8 card driver v1.1, (c) D.Gorodchanin "
1759 static char no_boards_msg
[] __initdata
=
1760 KERN_INFO
"rc: No RISCom/8 boards detected.\n";
1763 * This routine must be called by kernel at boot time
1765 static int __init
riscom8_init(void)
1772 if (rc_init_drivers())
1775 for (i
= 0; i
< RC_NBOARD
; i
++)
1776 if (rc_board
[i
].base
&& !rc_probe(&rc_board
[i
]))
1780 rc_release_drivers();
1781 printk(no_boards_msg
);
1792 MODULE_PARM(iobase
, "i");
1793 MODULE_PARM(iobase1
, "i");
1794 MODULE_PARM(iobase2
, "i");
1795 MODULE_PARM(iobase3
, "i");
1797 MODULE_LICENSE("GPL");
1801 * You can setup up to 4 boards (current value of RC_NBOARD)
1802 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter.
1805 static int __init
riscom8_init_module (void)
1810 if (iobase
|| iobase1
|| iobase2
|| iobase3
) {
1811 for(i
= 0; i
< RC_NBOARD
; i
++)
1812 rc_board
[0].base
= 0;
1816 rc_board
[0].base
= iobase
;
1818 rc_board
[1].base
= iobase1
;
1820 rc_board
[2].base
= iobase2
;
1822 rc_board
[3].base
= iobase3
;
1825 return riscom8_init();
1828 static void __exit
riscom8_exit_module (void)
1832 rc_release_drivers();
1833 for (i
= 0; i
< RC_NBOARD
; i
++)
1834 if (rc_board
[i
].flags
& RC_BOARD_PRESENT
)
1835 rc_release_io_range(&rc_board
[i
]);
1839 module_init(riscom8_init_module
);
1840 module_exit(riscom8_exit_module
);