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 DECLARE_TASK_QUEUE(tq_riscom
);
86 static struct riscom_board
* IRQ_to_board
[16];
87 static struct tty_driver
*riscom_driver
;
88 static unsigned char * tmp_buf
;
89 static DECLARE_MUTEX(tmp_buf_sem
);
91 static unsigned long baud_table
[] = {
92 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
93 9600, 19200, 38400, 57600, 76800, 0,
96 static struct riscom_board rc_board
[RC_NBOARD
] = {
111 static struct riscom_port rc_port
[RC_NBOARD
* RC_NPORT
];
113 /* RISCom/8 I/O ports addresses (without address translation) */
114 static unsigned short rc_ioport
[] = {
116 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c,
118 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10,
119 0x11, 0x12, 0x18, 0x28, 0x31, 0x32, 0x39, 0x3a, 0x40, 0x41, 0x61, 0x62,
120 0x63, 0x64, 0x6b, 0x70, 0x71, 0x78, 0x7a, 0x7b, 0x7f, 0x100, 0x101
123 #define RC_NIOPORT (sizeof(rc_ioport) / sizeof(rc_ioport[0]))
126 static inline int rc_paranoia_check(struct riscom_port
const * port
,
127 char *name
, const char *routine
)
129 #ifdef RISCOM_PARANOIA_CHECK
130 static const char badmagic
[] = KERN_INFO
131 "rc: Warning: bad riscom port magic number for device %s in %s\n";
132 static const char badinfo
[] = KERN_INFO
133 "rc: Warning: null riscom port for device %s in %s\n";
136 printk(badinfo
, name
, routine
);
139 if (port
->magic
!= RISCOM8_MAGIC
) {
140 printk(badmagic
, name
, routine
);
149 * Service functions for RISCom/8 driver.
153 /* Get board number from pointer */
154 static inline int board_No (struct riscom_board
const * bp
)
156 return bp
- rc_board
;
159 /* Get port number from pointer */
160 static inline int port_No (struct riscom_port
const * port
)
162 return RC_PORT(port
- rc_port
);
165 /* Get pointer to board from pointer to port */
166 static inline struct riscom_board
* port_Board(struct riscom_port
const * port
)
168 return &rc_board
[RC_BOARD(port
- rc_port
)];
171 /* Input Byte from CL CD180 register */
172 static inline unsigned char rc_in(struct riscom_board
const * bp
, unsigned short reg
)
174 return inb(bp
->base
+ RC_TO_ISA(reg
));
177 /* Output Byte to CL CD180 register */
178 static inline void rc_out(struct riscom_board
const * bp
, unsigned short reg
,
181 outb(val
, bp
->base
+ RC_TO_ISA(reg
));
184 /* Wait for Channel Command Register ready */
185 static inline void rc_wait_CCR(struct riscom_board
const * bp
)
189 /* FIXME: need something more descriptive then 100000 :) */
190 for (delay
= 100000; delay
; delay
--)
191 if (!rc_in(bp
, CD180_CCR
))
194 printk(KERN_INFO
"rc%d: Timeout waiting for CCR.\n", board_No(bp
));
198 * RISCom/8 probe functions.
201 static inline int rc_request_io_range(struct riscom_board
* const bp
)
205 for (i
= 0; i
< RC_NIOPORT
; i
++)
206 if (!request_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1,
212 printk(KERN_INFO
"rc%d: Skipping probe at 0x%03x. IO address in use.\n",
213 board_No(bp
), bp
->base
);
215 release_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1);
219 static inline void rc_release_io_range(struct riscom_board
* const bp
)
223 for (i
= 0; i
< RC_NIOPORT
; i
++)
224 release_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1);
227 /* Must be called with enabled interrupts */
228 static inline void rc_long_delay(unsigned long delay
)
232 for (i
= jiffies
+ delay
; time_after(i
,jiffies
); ) ;
235 /* Reset and setup CD180 chip */
236 static void __init
rc_init_CD180(struct riscom_board
const * bp
)
240 save_flags(flags
); cli();
241 rc_out(bp
, RC_CTOUT
, 0); /* Clear timeout */
242 rc_wait_CCR(bp
); /* Wait for CCR ready */
243 rc_out(bp
, CD180_CCR
, CCR_HARDRESET
); /* Reset CD180 chip */
245 rc_long_delay(HZ
/20); /* Delay 0.05 sec */
247 rc_out(bp
, CD180_GIVR
, RC_ID
); /* Set ID for this chip */
248 rc_out(bp
, CD180_GICR
, 0); /* Clear all bits */
249 rc_out(bp
, CD180_PILR1
, RC_ACK_MINT
); /* Prio for modem intr */
250 rc_out(bp
, CD180_PILR2
, RC_ACK_TINT
); /* Prio for transmitter intr */
251 rc_out(bp
, CD180_PILR3
, RC_ACK_RINT
); /* Prio for receiver intr */
253 /* Setting up prescaler. We need 4 ticks per 1 ms */
254 rc_out(bp
, CD180_PPRH
, (RC_OSCFREQ
/(1000000/RISCOM_TPS
)) >> 8);
255 rc_out(bp
, CD180_PPRL
, (RC_OSCFREQ
/(1000000/RISCOM_TPS
)) & 0xff);
257 restore_flags(flags
);
260 /* Main probing routine, also sets irq. */
261 static int __init
rc_probe(struct riscom_board
*bp
)
263 unsigned char val1
, val2
;
269 if (rc_request_io_range(bp
))
272 /* Are the I/O ports here ? */
273 rc_out(bp
, CD180_PPRL
, 0x5a);
275 val1
= rc_in(bp
, CD180_PPRL
);
276 rc_out(bp
, CD180_PPRL
, 0xa5);
278 val2
= rc_in(bp
, CD180_PPRL
);
280 if ((val1
!= 0x5a) || (val2
!= 0xa5)) {
281 printk(KERN_ERR
"rc%d: RISCom/8 Board at 0x%03x not found.\n",
282 board_No(bp
), bp
->base
);
286 /* It's time to find IRQ for this board */
287 for (retries
= 0; retries
< 5 && irqs
<= 0; retries
++) {
288 irqs
= probe_irq_on();
289 rc_init_CD180(bp
); /* Reset CD180 chip */
290 rc_out(bp
, CD180_CAR
, 2); /* Select port 2 */
292 rc_out(bp
, CD180_CCR
, CCR_TXEN
); /* Enable transmitter */
293 rc_out(bp
, CD180_IER
, IER_TXRDY
); /* Enable tx empty intr */
294 rc_long_delay(HZ
/20);
295 irqs
= probe_irq_off(irqs
);
296 val1
= rc_in(bp
, RC_BSR
); /* Get Board Status reg */
297 val2
= rc_in(bp
, RC_ACK_TINT
); /* ACK interrupt */
298 rc_init_CD180(bp
); /* Reset CD180 again */
300 if ((val1
& RC_BSR_TINT
) || (val2
!= (RC_ID
| GIVR_IT_TX
))) {
301 printk(KERN_ERR
"rc%d: RISCom/8 Board at 0x%03x not "
302 "found.\n", board_No(bp
), bp
->base
);
308 printk(KERN_ERR
"rc%d: Can't find IRQ for RISCom/8 board "
309 "at 0x%03x.\n", board_No(bp
), bp
->base
);
313 bp
->flags
|= RC_BOARD_PRESENT
;
315 printk(KERN_INFO
"rc%d: RISCom/8 Rev. %c board detected at "
318 (rc_in(bp
, CD180_GFRCR
) & 0x0f) + 'A', /* Board revision */
323 rc_release_io_range(bp
);
329 * Interrupt processing routines.
333 static inline void rc_mark_event(struct riscom_port
* port
, int event
)
336 * I'm not quite happy with current scheme all serial
337 * drivers use their own BH routine.
338 * It seems this easily can be done with one BH routine
339 * serving for all serial drivers.
340 * For now I must introduce another one - RISCOM8_BH.
341 * Still hope this will be changed in near future.
343 set_bit(event
, &port
->event
);
344 queue_task(&port
->tqueue
, &tq_riscom
);
348 static inline struct riscom_port
* rc_get_port(struct riscom_board
const * bp
,
349 unsigned char const * what
)
351 unsigned char channel
;
352 struct riscom_port
* port
;
354 channel
= rc_in(bp
, CD180_GICR
) >> GICR_CHAN_OFF
;
355 if (channel
< CD180_NCH
) {
356 port
= &rc_port
[board_No(bp
) * RC_NPORT
+ channel
];
357 if (port
->flags
& ASYNC_INITIALIZED
) {
361 printk(KERN_ERR
"rc%d: %s interrupt from invalid port %d\n",
362 board_No(bp
), what
, channel
);
366 static inline void rc_receive_exc(struct riscom_board
const * bp
)
368 struct riscom_port
*port
;
369 struct tty_struct
*tty
;
370 unsigned char status
;
373 if (!(port
= rc_get_port(bp
, "Receive")))
377 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
378 printk(KERN_WARNING
"rc%d: port %d: Working around flip "
379 "buffer overflow.\n",
380 board_No(bp
), port_No(port
));
384 #ifdef RC_REPORT_OVERRUN
385 status
= rc_in(bp
, CD180_RCSR
);
386 if (status
& RCSR_OE
) {
389 printk(KERN_ERR
"rc%d: port %d: Overrun. Total %ld overruns\n",
390 board_No(bp
), port_No(port
), port
->overrun
);
393 status
&= port
->mark_mask
;
395 status
= rc_in(bp
, CD180_RCSR
) & port
->mark_mask
;
397 ch
= rc_in(bp
, CD180_RDR
);
401 if (status
& RCSR_TOUT
) {
402 printk(KERN_WARNING
"rc%d: port %d: Receiver timeout. "
403 "Hardware problems ?\n",
404 board_No(bp
), port_No(port
));
407 } else if (status
& RCSR_BREAK
) {
408 printk(KERN_INFO
"rc%d: port %d: Handling break...\n",
409 board_No(bp
), port_No(port
));
410 *tty
->flip
.flag_buf_ptr
++ = TTY_BREAK
;
411 if (port
->flags
& ASYNC_SAK
)
414 } else if (status
& RCSR_PE
)
415 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
417 else if (status
& RCSR_FE
)
418 *tty
->flip
.flag_buf_ptr
++ = TTY_FRAME
;
420 else if (status
& RCSR_OE
)
421 *tty
->flip
.flag_buf_ptr
++ = TTY_OVERRUN
;
424 *tty
->flip
.flag_buf_ptr
++ = 0;
426 *tty
->flip
.char_buf_ptr
++ = ch
;
428 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
431 static inline void rc_receive(struct riscom_board
const * bp
)
433 struct riscom_port
*port
;
434 struct tty_struct
*tty
;
437 if (!(port
= rc_get_port(bp
, "Receive")))
442 count
= rc_in(bp
, CD180_RDCR
);
444 #ifdef RC_REPORT_FIFO
445 port
->hits
[count
> 8 ? 9 : count
]++;
449 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
450 printk(KERN_WARNING
"rc%d: port %d: Working around "
451 "flip buffer overflow.\n",
452 board_No(bp
), port_No(port
));
455 *tty
->flip
.char_buf_ptr
++ = rc_in(bp
, CD180_RDR
);
456 *tty
->flip
.flag_buf_ptr
++ = 0;
459 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
462 static inline void rc_transmit(struct riscom_board
const * bp
)
464 struct riscom_port
*port
;
465 struct tty_struct
*tty
;
469 if (!(port
= rc_get_port(bp
, "Transmit")))
474 if (port
->IER
& IER_TXEMPTY
) {
476 rc_out(bp
, CD180_CAR
, port_No(port
));
477 port
->IER
&= ~IER_TXEMPTY
;
478 rc_out(bp
, CD180_IER
, port
->IER
);
482 if ((port
->xmit_cnt
<= 0 && !port
->break_length
)
483 || tty
->stopped
|| tty
->hw_stopped
) {
484 rc_out(bp
, CD180_CAR
, port_No(port
));
485 port
->IER
&= ~IER_TXRDY
;
486 rc_out(bp
, CD180_IER
, port
->IER
);
490 if (port
->break_length
) {
491 if (port
->break_length
> 0) {
492 if (port
->COR2
& COR2_ETC
) {
493 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
494 rc_out(bp
, CD180_TDR
, CD180_C_SBRK
);
495 port
->COR2
&= ~COR2_ETC
;
497 count
= MIN(port
->break_length
, 0xff);
498 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
499 rc_out(bp
, CD180_TDR
, CD180_C_DELAY
);
500 rc_out(bp
, CD180_TDR
, count
);
501 if (!(port
->break_length
-= count
))
502 port
->break_length
--;
504 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
505 rc_out(bp
, CD180_TDR
, CD180_C_EBRK
);
506 rc_out(bp
, CD180_COR2
, port
->COR2
);
508 rc_out(bp
, CD180_CCR
, CCR_CORCHG2
);
509 port
->break_length
= 0;
516 rc_out(bp
, CD180_TDR
, port
->xmit_buf
[port
->xmit_tail
++]);
517 port
->xmit_tail
= port
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
518 if (--port
->xmit_cnt
<= 0)
520 } while (--count
> 0);
522 if (port
->xmit_cnt
<= 0) {
523 rc_out(bp
, CD180_CAR
, port_No(port
));
524 port
->IER
&= ~IER_TXRDY
;
525 rc_out(bp
, CD180_IER
, port
->IER
);
527 if (port
->xmit_cnt
<= port
->wakeup_chars
)
528 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
531 static inline void rc_check_modem(struct riscom_board
const * bp
)
533 struct riscom_port
*port
;
534 struct tty_struct
*tty
;
537 if (!(port
= rc_get_port(bp
, "Modem")))
542 mcr
= rc_in(bp
, CD180_MCR
);
543 if (mcr
& MCR_CDCHG
) {
544 if (rc_in(bp
, CD180_MSVR
) & MSVR_CD
)
545 wake_up_interruptible(&port
->open_wait
);
547 schedule_task(&port
->tqueue_hangup
);
550 #ifdef RISCOM_BRAIN_DAMAGED_CTS
551 if (mcr
& MCR_CTSCHG
) {
552 if (rc_in(bp
, CD180_MSVR
) & MSVR_CTS
) {
554 port
->IER
|= IER_TXRDY
;
555 if (port
->xmit_cnt
<= port
->wakeup_chars
)
556 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
559 port
->IER
&= ~IER_TXRDY
;
561 rc_out(bp
, CD180_IER
, port
->IER
);
563 if (mcr
& MCR_DSRCHG
) {
564 if (rc_in(bp
, CD180_MSVR
) & MSVR_DSR
) {
566 port
->IER
|= IER_TXRDY
;
567 if (port
->xmit_cnt
<= port
->wakeup_chars
)
568 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
571 port
->IER
&= ~IER_TXRDY
;
573 rc_out(bp
, CD180_IER
, port
->IER
);
575 #endif /* RISCOM_BRAIN_DAMAGED_CTS */
577 /* Clear change bits */
578 rc_out(bp
, CD180_MCR
, 0);
581 /* The main interrupt processing routine */
582 static irqreturn_t
rc_interrupt(int irq
, void * dev_id
, struct pt_regs
* regs
)
584 unsigned char status
;
586 struct riscom_board
*bp
;
587 unsigned long loop
= 0;
590 bp
= IRQ_to_board
[irq
];
592 if (!bp
|| !(bp
->flags
& RC_BOARD_ACTIVE
)) {
596 while ((++loop
< 16) && ((status
= ~(rc_in(bp
, RC_BSR
))) &
597 (RC_BSR_TOUT
| RC_BSR_TINT
|
598 RC_BSR_MINT
| RC_BSR_RINT
))) {
600 if (status
& RC_BSR_TOUT
)
601 printk(KERN_WARNING
"rc%d: Got timeout. Hardware "
602 "error?\n", board_No(bp
));
604 else if (status
& RC_BSR_RINT
) {
605 ack
= rc_in(bp
, RC_ACK_RINT
);
607 if (ack
== (RC_ID
| GIVR_IT_RCV
))
609 else if (ack
== (RC_ID
| GIVR_IT_REXC
))
612 printk(KERN_WARNING
"rc%d: Bad receive ack "
616 } else if (status
& RC_BSR_TINT
) {
617 ack
= rc_in(bp
, RC_ACK_TINT
);
619 if (ack
== (RC_ID
| GIVR_IT_TX
))
622 printk(KERN_WARNING
"rc%d: Bad transmit ack "
626 } else /* if (status & RC_BSR_MINT) */ {
627 ack
= rc_in(bp
, RC_ACK_MINT
);
629 if (ack
== (RC_ID
| GIVR_IT_MODEM
))
632 printk(KERN_WARNING
"rc%d: Bad modem ack "
638 rc_out(bp
, CD180_EOIR
, 0); /* Mark end of interrupt */
639 rc_out(bp
, RC_CTOUT
, 0); /* Clear timeout flag */
641 return IRQ_RETVAL(handled
);
645 * Routines for open & close processing.
648 /* Called with disabled interrupts */
649 static inline int rc_setup_board(struct riscom_board
* bp
)
653 if (bp
->flags
& RC_BOARD_ACTIVE
)
656 error
= request_irq(bp
->irq
, rc_interrupt
, SA_INTERRUPT
,
661 rc_out(bp
, RC_CTOUT
, 0); /* Just in case */
663 rc_out(bp
, RC_DTR
, bp
->DTR
); /* Drop DTR on all ports */
665 IRQ_to_board
[bp
->irq
] = bp
;
666 bp
->flags
|= RC_BOARD_ACTIVE
;
671 /* Called with disabled interrupts */
672 static inline void rc_shutdown_board(struct riscom_board
*bp
)
674 if (!(bp
->flags
& RC_BOARD_ACTIVE
))
677 bp
->flags
&= ~RC_BOARD_ACTIVE
;
679 free_irq(bp
->irq
, NULL
);
680 IRQ_to_board
[bp
->irq
] = NULL
;
683 rc_out(bp
, RC_DTR
, bp
->DTR
); /* Drop DTR on all ports */
688 * Setting up port characteristics.
689 * Must be called with disabled interrupts
691 static void rc_change_speed(struct riscom_board
*bp
, struct riscom_port
*port
)
693 struct tty_struct
*tty
;
696 unsigned char cor1
= 0, cor3
= 0;
697 unsigned char mcor1
= 0, mcor2
= 0;
699 if (!(tty
= port
->tty
) || !tty
->termios
)
704 port
->MSVR
= MSVR_RTS
;
708 if (baud
& CBAUDEX
) {
710 if (baud
< 1 || baud
> 2)
711 port
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
716 if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
718 if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
722 /* Select port on the board */
723 rc_out(bp
, CD180_CAR
, port_No(port
));
725 if (!baud_table
[baud
]) {
726 /* Drop DTR & exit */
727 bp
->DTR
|= (1u << port_No(port
));
728 rc_out(bp
, RC_DTR
, bp
->DTR
);
732 bp
->DTR
&= ~(1u << port_No(port
));
733 rc_out(bp
, RC_DTR
, bp
->DTR
);
737 * Now we must calculate some speed depended things
740 /* Set baud rate for port */
741 tmp
= (((RC_OSCFREQ
+ baud_table
[baud
]/2) / baud_table
[baud
] +
742 CD180_TPC
/2) / CD180_TPC
);
744 rc_out(bp
, CD180_RBPRH
, (tmp
>> 8) & 0xff);
745 rc_out(bp
, CD180_TBPRH
, (tmp
>> 8) & 0xff);
746 rc_out(bp
, CD180_RBPRL
, tmp
& 0xff);
747 rc_out(bp
, CD180_TBPRL
, tmp
& 0xff);
749 baud
= (baud_table
[baud
] + 5) / 10; /* Estimated CPS */
751 /* Two timer ticks seems enough to wakeup something like SLIP driver */
752 tmp
= ((baud
+ HZ
/2) / HZ
) * 2 - CD180_NFIFO
;
753 port
->wakeup_chars
= (tmp
< 0) ? 0 : ((tmp
>= SERIAL_XMIT_SIZE
) ?
754 SERIAL_XMIT_SIZE
- 1 : tmp
);
756 /* Receiver timeout will be transmission time for 1.5 chars */
757 tmp
= (RISCOM_TPS
+ RISCOM_TPS
/2 + baud
/2) / baud
;
758 tmp
= (tmp
> 0xff) ? 0xff : tmp
;
759 rc_out(bp
, CD180_RTPR
, tmp
);
761 switch (C_CSIZE(tty
)) {
781 cor1
|= COR1_NORMPAR
;
785 cor1
&= ~COR1_IGNORE
;
787 /* Set marking of some errors */
788 port
->mark_mask
= RCSR_OE
| RCSR_TOUT
;
790 port
->mark_mask
|= RCSR_FE
| RCSR_PE
;
791 if (I_BRKINT(tty
) || I_PARMRK(tty
))
792 port
->mark_mask
|= RCSR_BREAK
;
794 port
->mark_mask
&= ~(RCSR_FE
| RCSR_PE
);
796 port
->mark_mask
&= ~RCSR_BREAK
;
798 /* Real raw mode. Ignore all */
799 port
->mark_mask
&= ~RCSR_OE
;
801 /* Enable Hardware Flow Control */
802 if (C_CRTSCTS(tty
)) {
803 #ifdef RISCOM_BRAIN_DAMAGED_CTS
804 port
->IER
|= IER_DSR
| IER_CTS
;
805 mcor1
|= MCOR1_DSRZD
| MCOR1_CTSZD
;
806 mcor2
|= MCOR2_DSROD
| MCOR2_CTSOD
;
807 tty
->hw_stopped
= !(rc_in(bp
, CD180_MSVR
) & (MSVR_CTS
|MSVR_DSR
));
809 port
->COR2
|= COR2_CTSAE
;
812 /* Enable Software Flow Control. FIXME: I'm not sure about this */
813 /* Some people reported that it works, but I still doubt */
815 port
->COR2
|= COR2_TXIBE
;
816 cor3
|= (COR3_FCT
| COR3_SCDE
);
818 port
->COR2
|= COR2_IXM
;
819 rc_out(bp
, CD180_SCHR1
, START_CHAR(tty
));
820 rc_out(bp
, CD180_SCHR2
, STOP_CHAR(tty
));
821 rc_out(bp
, CD180_SCHR3
, START_CHAR(tty
));
822 rc_out(bp
, CD180_SCHR4
, STOP_CHAR(tty
));
824 if (!C_CLOCAL(tty
)) {
825 /* Enable CD check */
832 /* Enable receiver */
833 port
->IER
|= IER_RXD
;
835 /* Set input FIFO size (1-8 bytes) */
836 cor3
|= RISCOM_RXFIFO
;
837 /* Setting up CD180 channel registers */
838 rc_out(bp
, CD180_COR1
, cor1
);
839 rc_out(bp
, CD180_COR2
, port
->COR2
);
840 rc_out(bp
, CD180_COR3
, cor3
);
841 /* Make CD180 know about registers change */
843 rc_out(bp
, CD180_CCR
, CCR_CORCHG1
| CCR_CORCHG2
| CCR_CORCHG3
);
844 /* Setting up modem option registers */
845 rc_out(bp
, CD180_MCOR1
, mcor1
);
846 rc_out(bp
, CD180_MCOR2
, mcor2
);
847 /* Enable CD180 transmitter & receiver */
849 rc_out(bp
, CD180_CCR
, CCR_TXEN
| CCR_RXEN
);
850 /* Enable interrupts */
851 rc_out(bp
, CD180_IER
, port
->IER
);
852 /* And finally set RTS on */
853 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
856 /* Must be called with interrupts enabled */
857 static int rc_setup_port(struct riscom_board
*bp
, struct riscom_port
*port
)
861 if (port
->flags
& ASYNC_INITIALIZED
)
864 if (!port
->xmit_buf
) {
865 /* We may sleep in get_zeroed_page() */
868 if (!(tmp
= get_zeroed_page(GFP_KERNEL
)))
871 if (port
->xmit_buf
) {
875 port
->xmit_buf
= (unsigned char *) tmp
;
878 save_flags(flags
); cli();
881 clear_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
883 if (port
->count
== 1)
886 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
887 rc_change_speed(bp
, port
);
888 port
->flags
|= ASYNC_INITIALIZED
;
890 restore_flags(flags
);
894 /* Must be called with interrupts disabled */
895 static void rc_shutdown_port(struct riscom_board
*bp
, struct riscom_port
*port
)
897 struct tty_struct
*tty
;
899 if (!(port
->flags
& ASYNC_INITIALIZED
))
902 #ifdef RC_REPORT_OVERRUN
903 printk(KERN_INFO
"rc%d: port %d: Total %ld overruns were detected.\n",
904 board_No(bp
), port_No(port
), port
->overrun
);
906 #ifdef RC_REPORT_FIFO
910 printk(KERN_INFO
"rc%d: port %d: FIFO hits [ ",
911 board_No(bp
), port_No(port
));
912 for (i
= 0; i
< 10; i
++) {
913 printk("%ld ", port
->hits
[i
]);
918 if (port
->xmit_buf
) {
919 free_page((unsigned long) port
->xmit_buf
);
920 port
->xmit_buf
= NULL
;
923 if (!(tty
= port
->tty
) || C_HUPCL(tty
)) {
925 bp
->DTR
|= (1u << port_No(port
));
926 rc_out(bp
, RC_DTR
, bp
->DTR
);
930 rc_out(bp
, CD180_CAR
, port_No(port
));
933 rc_out(bp
, CD180_CCR
, CCR_SOFTRESET
);
934 /* Disable all interrupts from this port */
936 rc_out(bp
, CD180_IER
, port
->IER
);
939 set_bit(TTY_IO_ERROR
, &tty
->flags
);
940 port
->flags
&= ~ASYNC_INITIALIZED
;
942 if (--bp
->count
< 0) {
943 printk(KERN_INFO
"rc%d: rc_shutdown_port: "
944 "bad board count: %d\n",
945 board_No(bp
), bp
->count
);
950 * If this is the last opened port on the board
951 * shutdown whole board
954 rc_shutdown_board(bp
);
958 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
959 struct riscom_port
*port
)
961 DECLARE_WAITQUEUE(wait
, current
);
962 struct riscom_board
*bp
= port_Board(port
);
968 * If the device is in the middle of being closed, then block
969 * until it's done, and then try again.
971 if (tty_hung_up_p(filp
) || port
->flags
& ASYNC_CLOSING
) {
972 interruptible_sleep_on(&port
->close_wait
);
973 if (port
->flags
& ASYNC_HUP_NOTIFY
)
980 * If non-blocking mode is set, or the port is not enabled,
981 * then make the check up front and then exit.
983 if ((filp
->f_flags
& O_NONBLOCK
) ||
984 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
985 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
993 * Block waiting for the carrier detect and the line to become
994 * free (i.e., not in use by the callout). While we are in
995 * this loop, info->count is dropped by one, so that
996 * rs_close() knows when to free things. We restore it upon
997 * exit, either normal or abnormal.
1000 add_wait_queue(&port
->open_wait
, &wait
);
1002 if (!tty_hung_up_p(filp
))
1005 port
->blocked_open
++;
1008 rc_out(bp
, CD180_CAR
, port_No(port
));
1009 CD
= rc_in(bp
, CD180_MSVR
) & MSVR_CD
;
1010 rc_out(bp
, CD180_MSVR
, MSVR_RTS
);
1011 bp
->DTR
&= ~(1u << port_No(port
));
1012 rc_out(bp
, RC_DTR
, bp
->DTR
);
1014 set_current_state(TASK_INTERRUPTIBLE
);
1015 if (tty_hung_up_p(filp
) ||
1016 !(port
->flags
& ASYNC_INITIALIZED
)) {
1017 if (port
->flags
& ASYNC_HUP_NOTIFY
)
1020 retval
= -ERESTARTSYS
;
1023 if (!(port
->flags
& ASYNC_CLOSING
) &&
1026 if (signal_pending(current
)) {
1027 retval
= -ERESTARTSYS
;
1032 current
->state
= TASK_RUNNING
;
1033 remove_wait_queue(&port
->open_wait
, &wait
);
1034 if (!tty_hung_up_p(filp
))
1036 port
->blocked_open
--;
1040 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
1044 static int rc_open(struct tty_struct
* tty
, struct file
* filp
)
1048 struct riscom_port
* port
;
1049 struct riscom_board
* bp
;
1050 unsigned long flags
;
1052 board
= RC_BOARD(tty
->index
);
1053 if (board
>= RC_NBOARD
|| !(rc_board
[board
].flags
& RC_BOARD_PRESENT
))
1056 bp
= &rc_board
[board
];
1057 port
= rc_port
+ board
* RC_NPORT
+ RC_PORT(tty
->index
);
1058 if (rc_paranoia_check(port
, tty
->name
, "rc_open"))
1061 if ((error
= rc_setup_board(bp
)))
1065 tty
->driver_data
= port
;
1068 if ((error
= rc_setup_port(bp
, port
)))
1071 if ((error
= block_til_ready(tty
, filp
, port
)))
1077 static void rc_close(struct tty_struct
* tty
, struct file
* filp
)
1079 struct riscom_port
*port
= (struct riscom_port
*) tty
->driver_data
;
1080 struct riscom_board
*bp
;
1081 unsigned long flags
;
1082 unsigned long timeout
;
1084 if (!port
|| rc_paranoia_check(port
, tty
->name
, "close"))
1087 save_flags(flags
); cli();
1088 if (tty_hung_up_p(filp
))
1091 bp
= port_Board(port
);
1092 if ((tty
->count
== 1) && (port
->count
!= 1)) {
1093 printk(KERN_INFO
"rc%d: rc_close: bad port count;"
1094 " tty->count is 1, port count is %d\n",
1095 board_No(bp
), port
->count
);
1098 if (--port
->count
< 0) {
1099 printk(KERN_INFO
"rc%d: rc_close: bad port count "
1101 board_No(bp
), port_No(port
), port
->count
);
1106 port
->flags
|= ASYNC_CLOSING
;
1108 * Now we wait for the transmit buffer to clear; and we notify
1109 * the line discipline to only process XON/XOFF characters.
1112 if (port
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1113 tty_wait_until_sent(tty
, port
->closing_wait
);
1115 * At this point we stop accepting input. To do this, we
1116 * disable the receive line status interrupts, and tell the
1117 * interrupt driver to stop checking the data ready bit in the
1118 * line status register.
1120 port
->IER
&= ~IER_RXD
;
1121 if (port
->flags
& ASYNC_INITIALIZED
) {
1122 port
->IER
&= ~IER_TXRDY
;
1123 port
->IER
|= IER_TXEMPTY
;
1124 rc_out(bp
, CD180_CAR
, port_No(port
));
1125 rc_out(bp
, CD180_IER
, port
->IER
);
1127 * Before we drop DTR, make sure the UART transmitter
1128 * has completely drained; this is especially
1129 * important if there is a transmit FIFO!
1131 timeout
= jiffies
+HZ
;
1132 while(port
->IER
& IER_TXEMPTY
) {
1133 current
->state
= TASK_INTERRUPTIBLE
;
1134 schedule_timeout(port
->timeout
);
1135 if (time_after(jiffies
, timeout
))
1139 rc_shutdown_port(bp
, port
);
1140 if (tty
->driver
->flush_buffer
)
1141 tty
->driver
->flush_buffer(tty
);
1142 if (tty
->ldisc
.flush_buffer
)
1143 tty
->ldisc
.flush_buffer(tty
);
1147 if (port
->blocked_open
) {
1148 if (port
->close_delay
) {
1149 current
->state
= TASK_INTERRUPTIBLE
;
1150 schedule_timeout(port
->close_delay
);
1152 wake_up_interruptible(&port
->open_wait
);
1154 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1155 wake_up_interruptible(&port
->close_wait
);
1156 out
: restore_flags(flags
);
1159 static int rc_write(struct tty_struct
* tty
, int from_user
,
1160 const unsigned char *buf
, int count
)
1162 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1163 struct riscom_board
*bp
;
1165 unsigned long flags
;
1167 if (rc_paranoia_check(port
, tty
->name
, "rc_write"))
1170 bp
= port_Board(port
);
1172 if (!tty
|| !port
->xmit_buf
|| !tmp_buf
)
1180 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1181 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1185 c
-= copy_from_user(tmp_buf
, buf
, c
);
1193 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1194 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1195 memcpy(port
->xmit_buf
+ port
->xmit_head
, tmp_buf
, c
);
1196 port
->xmit_head
= (port
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
1197 port
->xmit_cnt
+= c
;
1198 restore_flags(flags
);
1208 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1209 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1211 restore_flags(flags
);
1215 memcpy(port
->xmit_buf
+ port
->xmit_head
, buf
, c
);
1216 port
->xmit_head
= (port
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
1217 port
->xmit_cnt
+= c
;
1218 restore_flags(flags
);
1227 if (port
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
&&
1228 !(port
->IER
& IER_TXRDY
)) {
1229 port
->IER
|= IER_TXRDY
;
1230 rc_out(bp
, CD180_CAR
, port_No(port
));
1231 rc_out(bp
, CD180_IER
, port
->IER
);
1233 restore_flags(flags
);
1238 static void rc_put_char(struct tty_struct
* tty
, unsigned char ch
)
1240 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1241 unsigned long flags
;
1243 if (rc_paranoia_check(port
, tty
->name
, "rc_put_char"))
1246 if (!tty
|| !port
->xmit_buf
)
1249 save_flags(flags
); cli();
1251 if (port
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1)
1254 port
->xmit_buf
[port
->xmit_head
++] = ch
;
1255 port
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
1257 out
: restore_flags(flags
);
1260 static void rc_flush_chars(struct tty_struct
* tty
)
1262 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1263 unsigned long flags
;
1265 if (rc_paranoia_check(port
, tty
->name
, "rc_flush_chars"))
1268 if (port
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
1272 save_flags(flags
); cli();
1273 port
->IER
|= IER_TXRDY
;
1274 rc_out(port_Board(port
), CD180_CAR
, port_No(port
));
1275 rc_out(port_Board(port
), CD180_IER
, port
->IER
);
1276 restore_flags(flags
);
1279 static int rc_write_room(struct tty_struct
* tty
)
1281 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1284 if (rc_paranoia_check(port
, tty
->name
, "rc_write_room"))
1287 ret
= SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1;
1293 static int rc_chars_in_buffer(struct tty_struct
*tty
)
1295 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1297 if (rc_paranoia_check(port
, tty
->name
, "rc_chars_in_buffer"))
1300 return port
->xmit_cnt
;
1303 static void rc_flush_buffer(struct tty_struct
*tty
)
1305 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1306 unsigned long flags
;
1308 if (rc_paranoia_check(port
, tty
->name
, "rc_flush_buffer"))
1311 save_flags(flags
); cli();
1312 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
1313 restore_flags(flags
);
1315 wake_up_interruptible(&tty
->write_wait
);
1316 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1317 tty
->ldisc
.write_wakeup
)
1318 (tty
->ldisc
.write_wakeup
)(tty
);
1321 static int rc_get_modem_info(struct riscom_port
* port
, unsigned int *value
)
1323 struct riscom_board
* bp
;
1324 unsigned char status
;
1325 unsigned int result
;
1326 unsigned long flags
;
1328 bp
= port_Board(port
);
1329 save_flags(flags
); cli();
1330 rc_out(bp
, CD180_CAR
, port_No(port
));
1331 status
= rc_in(bp
, CD180_MSVR
);
1332 result
= rc_in(bp
, RC_RI
) & (1u << port_No(port
)) ? 0 : TIOCM_RNG
;
1333 restore_flags(flags
);
1334 result
|= ((status
& MSVR_RTS
) ? TIOCM_RTS
: 0)
1335 | ((status
& MSVR_DTR
) ? TIOCM_DTR
: 0)
1336 | ((status
& MSVR_CD
) ? TIOCM_CAR
: 0)
1337 | ((status
& MSVR_DSR
) ? TIOCM_DSR
: 0)
1338 | ((status
& MSVR_CTS
) ? TIOCM_CTS
: 0);
1339 return put_user(result
, value
);
1342 static int rc_set_modem_info(struct riscom_port
* port
, unsigned int cmd
,
1343 unsigned int *value
)
1346 unsigned long flags
;
1347 struct riscom_board
*bp
= port_Board(port
);
1349 if (get_user(arg
, value
))
1353 if (arg
& TIOCM_RTS
)
1354 port
->MSVR
|= MSVR_RTS
;
1355 if (arg
& TIOCM_DTR
)
1356 bp
->DTR
&= ~(1u << port_No(port
));
1359 if (arg
& TIOCM_RTS
)
1360 port
->MSVR
&= ~MSVR_RTS
;
1361 if (arg
& TIOCM_DTR
)
1362 bp
->DTR
|= (1u << port_No(port
));
1365 port
->MSVR
= (arg
& TIOCM_RTS
) ? (port
->MSVR
| MSVR_RTS
) :
1366 (port
->MSVR
& ~MSVR_RTS
);
1367 bp
->DTR
= arg
& TIOCM_DTR
? (bp
->DTR
&= ~(1u << port_No(port
))) :
1368 (bp
->DTR
|= (1u << port_No(port
)));
1373 save_flags(flags
); cli();
1374 rc_out(bp
, CD180_CAR
, port_No(port
));
1375 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1376 rc_out(bp
, RC_DTR
, bp
->DTR
);
1377 restore_flags(flags
);
1381 static inline void rc_send_break(struct riscom_port
* port
, unsigned long length
)
1383 struct riscom_board
*bp
= port_Board(port
);
1384 unsigned long flags
;
1386 save_flags(flags
); cli();
1387 port
->break_length
= RISCOM_TPS
/ HZ
* length
;
1388 port
->COR2
|= COR2_ETC
;
1389 port
->IER
|= IER_TXRDY
;
1390 rc_out(bp
, CD180_CAR
, port_No(port
));
1391 rc_out(bp
, CD180_COR2
, port
->COR2
);
1392 rc_out(bp
, CD180_IER
, port
->IER
);
1394 rc_out(bp
, CD180_CCR
, CCR_CORCHG2
);
1396 restore_flags(flags
);
1399 static inline int rc_set_serial_info(struct riscom_port
* port
,
1400 struct serial_struct
* newinfo
)
1402 struct serial_struct tmp
;
1403 struct riscom_board
*bp
= port_Board(port
);
1405 unsigned long flags
;
1407 if (copy_from_user(&tmp
, newinfo
, sizeof(tmp
)))
1411 if ((tmp
.irq
!= bp
->irq
) ||
1412 (tmp
.port
!= bp
->base
) ||
1413 (tmp
.type
!= PORT_CIRRUS
) ||
1414 (tmp
.baud_base
!= (RC_OSCFREQ
+ CD180_TPC
/2) / CD180_TPC
) ||
1415 (tmp
.custom_divisor
!= 0) ||
1416 (tmp
.xmit_fifo_size
!= CD180_NFIFO
) ||
1417 (tmp
.flags
& ~RISCOM_LEGAL_FLAGS
))
1421 change_speed
= ((port
->flags
& ASYNC_SPD_MASK
) !=
1422 (tmp
.flags
& ASYNC_SPD_MASK
));
1424 if (!capable(CAP_SYS_ADMIN
)) {
1425 if ((tmp
.close_delay
!= port
->close_delay
) ||
1426 (tmp
.closing_wait
!= port
->closing_wait
) ||
1427 ((tmp
.flags
& ~ASYNC_USR_MASK
) !=
1428 (port
->flags
& ~ASYNC_USR_MASK
)))
1430 port
->flags
= ((port
->flags
& ~ASYNC_USR_MASK
) |
1431 (tmp
.flags
& ASYNC_USR_MASK
));
1433 port
->flags
= ((port
->flags
& ~ASYNC_FLAGS
) |
1434 (tmp
.flags
& ASYNC_FLAGS
));
1435 port
->close_delay
= tmp
.close_delay
;
1436 port
->closing_wait
= tmp
.closing_wait
;
1439 save_flags(flags
); cli();
1440 rc_change_speed(bp
, port
);
1441 restore_flags(flags
);
1446 static inline int rc_get_serial_info(struct riscom_port
* port
,
1447 struct serial_struct
* retinfo
)
1449 struct serial_struct tmp
;
1450 struct riscom_board
*bp
= port_Board(port
);
1452 memset(&tmp
, 0, sizeof(tmp
));
1453 tmp
.type
= PORT_CIRRUS
;
1454 tmp
.line
= port
- rc_port
;
1455 tmp
.port
= bp
->base
;
1457 tmp
.flags
= port
->flags
;
1458 tmp
.baud_base
= (RC_OSCFREQ
+ CD180_TPC
/2) / CD180_TPC
;
1459 tmp
.close_delay
= port
->close_delay
* HZ
/100;
1460 tmp
.closing_wait
= port
->closing_wait
* HZ
/100;
1461 tmp
.xmit_fifo_size
= CD180_NFIFO
;
1462 return copy_to_user(retinfo
, &tmp
, sizeof(tmp
)) ? -EFAULT
: 0;
1465 static int rc_ioctl(struct tty_struct
* tty
, struct file
* filp
,
1466 unsigned int cmd
, unsigned long arg
)
1469 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1472 if (rc_paranoia_check(port
, tty
->name
, "rc_ioctl"))
1476 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1477 retval
= tty_check_change(tty
);
1480 tty_wait_until_sent(tty
, 0);
1482 rc_send_break(port
, HZ
/4); /* 1/4 second */
1484 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1485 retval
= tty_check_change(tty
);
1488 tty_wait_until_sent(tty
, 0);
1489 rc_send_break(port
, arg
? arg
*(HZ
/10) : HZ
/4);
1492 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned int *) arg
);
1494 if (get_user(arg
,(unsigned int *) arg
))
1496 tty
->termios
->c_cflag
=
1497 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1498 (arg
? CLOCAL
: 0));
1501 return rc_get_modem_info(port
, (unsigned int *) arg
);
1505 return rc_set_modem_info(port
, cmd
, (unsigned int *) arg
);
1507 return rc_get_serial_info(port
, (struct serial_struct
*) arg
);
1509 return rc_set_serial_info(port
, (struct serial_struct
*) arg
);
1511 return -ENOIOCTLCMD
;
1516 static void rc_throttle(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_throttle"))
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_SSCH2
);
1535 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1536 restore_flags(flags
);
1539 static void rc_unthrottle(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_unthrottle"))
1548 bp
= port_Board(port
);
1550 save_flags(flags
); cli();
1551 port
->MSVR
|= MSVR_RTS
;
1552 rc_out(bp
, CD180_CAR
, port_No(port
));
1555 rc_out(bp
, CD180_CCR
, CCR_SSCH1
);
1558 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1559 restore_flags(flags
);
1562 static void rc_stop(struct tty_struct
* tty
)
1564 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1565 struct riscom_board
*bp
;
1566 unsigned long flags
;
1568 if (rc_paranoia_check(port
, tty
->name
, "rc_stop"))
1571 bp
= port_Board(port
);
1573 save_flags(flags
); cli();
1574 port
->IER
&= ~IER_TXRDY
;
1575 rc_out(bp
, CD180_CAR
, port_No(port
));
1576 rc_out(bp
, CD180_IER
, port
->IER
);
1577 restore_flags(flags
);
1580 static void rc_start(struct tty_struct
* tty
)
1582 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1583 struct riscom_board
*bp
;
1584 unsigned long flags
;
1586 if (rc_paranoia_check(port
, tty
->name
, "rc_start"))
1589 bp
= port_Board(port
);
1591 save_flags(flags
); cli();
1592 if (port
->xmit_cnt
&& port
->xmit_buf
&& !(port
->IER
& IER_TXRDY
)) {
1593 port
->IER
|= IER_TXRDY
;
1594 rc_out(bp
, CD180_CAR
, port_No(port
));
1595 rc_out(bp
, CD180_IER
, port
->IER
);
1597 restore_flags(flags
);
1601 * This routine is called from the scheduler tqueue when the interrupt
1602 * routine has signalled that a hangup has occurred. The path of
1603 * hangup processing is:
1605 * serial interrupt routine -> (scheduler tqueue) ->
1606 * do_rc_hangup() -> tty->hangup() -> rc_hangup()
1609 static void do_rc_hangup(void *private_
)
1611 struct riscom_port
*port
= (struct riscom_port
*) private_
;
1612 struct tty_struct
*tty
;
1616 tty_hangup(tty
); /* FIXME: module removal race still here */
1619 static void rc_hangup(struct tty_struct
* tty
)
1621 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1622 struct riscom_board
*bp
;
1624 if (rc_paranoia_check(port
, tty
->name
, "rc_hangup"))
1627 bp
= port_Board(port
);
1629 rc_shutdown_port(bp
, port
);
1632 port
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1634 wake_up_interruptible(&port
->open_wait
);
1637 static void rc_set_termios(struct tty_struct
* tty
, struct termios
* old_termios
)
1639 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1640 unsigned long flags
;
1642 if (rc_paranoia_check(port
, tty
->name
, "rc_set_termios"))
1645 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
&&
1646 tty
->termios
->c_iflag
== old_termios
->c_iflag
)
1649 save_flags(flags
); cli();
1650 rc_change_speed(port_Board(port
), port
);
1651 restore_flags(flags
);
1653 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1654 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1655 tty
->hw_stopped
= 0;
1660 static void do_riscom_bh(void)
1662 run_task_queue(&tq_riscom
);
1665 static void do_softint(void *private_
)
1667 struct riscom_port
*port
= (struct riscom_port
*) private_
;
1668 struct tty_struct
*tty
;
1670 if(!(tty
= port
->tty
))
1673 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &port
->event
)) {
1674 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1675 tty
->ldisc
.write_wakeup
)
1676 (tty
->ldisc
.write_wakeup
)(tty
);
1677 wake_up_interruptible(&tty
->write_wait
);
1681 static struct tty_operations riscom_ops
= {
1685 .put_char
= rc_put_char
,
1686 .flush_chars
= rc_flush_chars
,
1687 .write_room
= rc_write_room
,
1688 .chars_in_buffer
= rc_chars_in_buffer
,
1689 .flush_buffer
= rc_flush_buffer
,
1691 .throttle
= rc_throttle
,
1692 .unthrottle
= rc_unthrottle
,
1693 .set_termios
= rc_set_termios
,
1696 .hangup
= rc_hangup
,
1699 static inline int rc_init_drivers(void)
1704 riscom_driver
= alloc_tty_driver(RC_NBOARD
* RC_NPORT
);
1708 if (!(tmp_buf
= (unsigned char *) get_zeroed_page(GFP_KERNEL
))) {
1709 printk(KERN_ERR
"rc: Couldn't get free page.\n");
1710 put_tty_driver(riscom_driver
);
1713 init_bh(RISCOM8_BH
, do_riscom_bh
);
1714 memset(IRQ_to_board
, 0, sizeof(IRQ_to_board
));
1715 riscom_driver
->owner
= THIS_MODULE
;
1716 riscom_driver
->name
= "ttyL";
1717 riscom_driver
->major
= RISCOM8_NORMAL_MAJOR
;
1718 riscom_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1719 riscom_driver
->subtype
= SERIAL_TYPE_NORMAL
;
1720 riscom_driver
->init_termios
= tty_std_termios
;
1721 riscom_driver
->init_termios
.c_cflag
=
1722 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1723 riscom_driver
->flags
= TTY_DRIVER_REAL_RAW
;
1724 tty_set_operations(riscom_driver
, &riscom_ops
);
1725 if ((error
= tty_register_driver(riscom_driver
))) {
1726 free_page((unsigned long)tmp_buf
);
1727 put_tty_driver(riscom_driver
);
1728 printk(KERN_ERR
"rc: Couldn't register RISCom/8 driver, "
1734 memset(rc_port
, 0, sizeof(rc_port
));
1735 for (i
= 0; i
< RC_NPORT
* RC_NBOARD
; i
++) {
1736 rc_port
[i
].magic
= RISCOM8_MAGIC
;
1737 rc_port
[i
].tqueue
.routine
= do_softint
;
1738 rc_port
[i
].tqueue
.data
= &rc_port
[i
];
1739 rc_port
[i
].tqueue_hangup
.routine
= do_rc_hangup
;
1740 rc_port
[i
].tqueue_hangup
.data
= &rc_port
[i
];
1741 rc_port
[i
].close_delay
= 50 * HZ
/100;
1742 rc_port
[i
].closing_wait
= 3000 * HZ
/100;
1743 init_waitqueue_head(&rc_port
[i
].open_wait
);
1744 init_waitqueue_head(&rc_port
[i
].close_wait
);
1750 static void rc_release_drivers(void)
1752 unsigned long flags
;
1756 remove_bh(RISCOM8_BH
);
1757 free_page((unsigned long)tmp_buf
);
1758 tty_unregister_driver(riscom_driver
);
1759 put_tty_driver(riscom_driver
);
1760 restore_flags(flags
);
1765 * Called at boot time.
1767 * You can specify IO base for up to RC_NBOARD cards,
1768 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
1769 * Note that there will be no probing at default
1770 * addresses in this case.
1773 static int __init
riscom8_setup(char *str
)
1775 int ints
[RC_NBOARD
];
1778 str
= get_options(str
, ARRAY_SIZE(ints
), ints
);
1780 for (i
= 0; i
< RC_NBOARD
; i
++) {
1782 rc_board
[i
].base
= ints
[i
+1];
1784 rc_board
[i
].base
= 0;
1789 __setup("riscom8=", riscom8_setup
);
1792 static char banner
[] __initdata
=
1793 KERN_INFO
"rc: SDL RISCom/8 card driver v1.1, (c) D.Gorodchanin "
1795 static char no_boards_msg
[] __initdata
=
1796 KERN_INFO
"rc: No RISCom/8 boards detected.\n";
1799 * This routine must be called by kernel at boot time
1801 static int __init
riscom8_init(void)
1808 if (rc_init_drivers())
1811 for (i
= 0; i
< RC_NBOARD
; i
++)
1812 if (rc_board
[i
].base
&& !rc_probe(&rc_board
[i
]))
1816 rc_release_drivers();
1817 printk(no_boards_msg
);
1828 MODULE_PARM(iobase
, "i");
1829 MODULE_PARM(iobase1
, "i");
1830 MODULE_PARM(iobase2
, "i");
1831 MODULE_PARM(iobase3
, "i");
1833 MODULE_LICENSE("GPL");
1837 * You can setup up to 4 boards (current value of RC_NBOARD)
1838 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter.
1841 static int __init
riscom8_init_module (void)
1846 if (iobase
|| iobase1
|| iobase2
|| iobase3
) {
1847 for(i
= 0; i
< RC_NBOARD
; i
++)
1848 rc_board
[0].base
= 0;
1852 rc_board
[0].base
= iobase
;
1854 rc_board
[1].base
= iobase1
;
1856 rc_board
[2].base
= iobase2
;
1858 rc_board
[3].base
= iobase3
;
1861 return riscom8_init();
1864 static void __exit
riscom8_exit_module (void)
1868 rc_release_drivers();
1869 for (i
= 0; i
< RC_NBOARD
; i
++)
1870 if (rc_board
[i
].flags
& RC_BOARD_PRESENT
)
1871 rc_release_io_range(&rc_board
[i
]);
1875 module_init(riscom8_init_module
);
1876 module_exit(riscom8_exit_module
);