2 * linux/drivers/char/riscom.c -- RISCom/8 multiport serial driver.
4 * Copyright (C) 1994-1996 Dmitry Gorodchanin (pgmdsg@ibi.com)
6 * This code is loosely based on the Linux serial driver, written by
7 * Linus Torvalds, Theodore T'so and others. The RISCom/8 card
8 * programming info was obtained from various drivers for other OSes
9 * (FreeBSD, ISC, etc), but no source code from those drivers were
10 * directly included in this driver.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 27-Jun-2001
31 * - get rid of check_region and several cleanups
34 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/sched.h>
39 #include <linux/ioport.h>
40 #include <linux/interrupt.h>
41 #include <linux/errno.h>
42 #include <linux/tty.h>
44 #include <linux/serial.h>
45 #include <linux/fcntl.h>
46 #include <linux/major.h>
47 #include <linux/init.h>
48 #include <linux/delay.h>
50 #include <asm/uaccess.h>
53 #include "riscom8_reg.h"
55 /* Am I paranoid or not ? ;-) */
56 #define RISCOM_PARANOIA_CHECK
59 * Crazy InteliCom/8 boards sometimes has swapped CTS & DSR signals.
60 * You can slightly speed up things by #undefing the following option,
61 * if you are REALLY sure that your board is correct one.
64 #define RISCOM_BRAIN_DAMAGED_CTS
67 * The following defines are mostly for testing purposes. But if you need
68 * some nice reporting in your syslog, you can define them also.
71 #undef RC_REPORT_OVERRUN
74 #define RISCOM_LEGAL_FLAGS \
75 (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \
76 ASYNC_SPD_HI | ASYNC_SPEED_VHI | ASYNC_SESSION_LOCKOUT | \
77 ASYNC_PGRP_LOCKOUT | ASYNC_CALLOUT_NOHUP)
79 #define RS_EVENT_WRITE_WAKEUP 0
81 static struct riscom_board
* IRQ_to_board
[16];
82 static struct tty_driver
*riscom_driver
;
83 static unsigned char * tmp_buf
;
84 static DECLARE_MUTEX(tmp_buf_sem
);
86 static unsigned long baud_table
[] = {
87 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
88 9600, 19200, 38400, 57600, 76800, 0,
91 static struct riscom_board rc_board
[RC_NBOARD
] = {
106 static struct riscom_port rc_port
[RC_NBOARD
* RC_NPORT
];
108 /* RISCom/8 I/O ports addresses (without address translation) */
109 static unsigned short rc_ioport
[] = {
111 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c,
113 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10,
114 0x11, 0x12, 0x18, 0x28, 0x31, 0x32, 0x39, 0x3a, 0x40, 0x41, 0x61, 0x62,
115 0x63, 0x64, 0x6b, 0x70, 0x71, 0x78, 0x7a, 0x7b, 0x7f, 0x100, 0x101
118 #define RC_NIOPORT (sizeof(rc_ioport) / sizeof(rc_ioport[0]))
121 static inline int rc_paranoia_check(struct riscom_port
const * port
,
122 char *name
, const char *routine
)
124 #ifdef RISCOM_PARANOIA_CHECK
125 static const char badmagic
[] = KERN_INFO
126 "rc: Warning: bad riscom port magic number for device %s in %s\n";
127 static const char badinfo
[] = KERN_INFO
128 "rc: Warning: null riscom port for device %s in %s\n";
131 printk(badinfo
, name
, routine
);
134 if (port
->magic
!= RISCOM8_MAGIC
) {
135 printk(badmagic
, name
, routine
);
144 * Service functions for RISCom/8 driver.
148 /* Get board number from pointer */
149 static inline int board_No (struct riscom_board
const * bp
)
151 return bp
- rc_board
;
154 /* Get port number from pointer */
155 static inline int port_No (struct riscom_port
const * port
)
157 return RC_PORT(port
- rc_port
);
160 /* Get pointer to board from pointer to port */
161 static inline struct riscom_board
* port_Board(struct riscom_port
const * port
)
163 return &rc_board
[RC_BOARD(port
- rc_port
)];
166 /* Input Byte from CL CD180 register */
167 static inline unsigned char rc_in(struct riscom_board
const * bp
, unsigned short reg
)
169 return inb(bp
->base
+ RC_TO_ISA(reg
));
172 /* Output Byte to CL CD180 register */
173 static inline void rc_out(struct riscom_board
const * bp
, unsigned short reg
,
176 outb(val
, bp
->base
+ RC_TO_ISA(reg
));
179 /* Wait for Channel Command Register ready */
180 static inline void rc_wait_CCR(struct riscom_board
const * bp
)
184 /* FIXME: need something more descriptive then 100000 :) */
185 for (delay
= 100000; delay
; delay
--)
186 if (!rc_in(bp
, CD180_CCR
))
189 printk(KERN_INFO
"rc%d: Timeout waiting for CCR.\n", board_No(bp
));
193 * RISCom/8 probe functions.
196 static inline int rc_request_io_range(struct riscom_board
* const bp
)
200 for (i
= 0; i
< RC_NIOPORT
; i
++)
201 if (!request_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1,
207 printk(KERN_INFO
"rc%d: Skipping probe at 0x%03x. IO address in use.\n",
208 board_No(bp
), bp
->base
);
210 release_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1);
214 static inline void rc_release_io_range(struct riscom_board
* const bp
)
218 for (i
= 0; i
< RC_NIOPORT
; i
++)
219 release_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1);
222 /* Must be called with enabled interrupts */
223 static inline void rc_long_delay(unsigned long delay
)
227 for (i
= jiffies
+ delay
; time_after(i
,jiffies
); ) ;
230 /* Reset and setup CD180 chip */
231 static void __init
rc_init_CD180(struct riscom_board
const * bp
)
235 save_flags(flags
); cli();
236 rc_out(bp
, RC_CTOUT
, 0); /* Clear timeout */
237 rc_wait_CCR(bp
); /* Wait for CCR ready */
238 rc_out(bp
, CD180_CCR
, CCR_HARDRESET
); /* Reset CD180 chip */
240 rc_long_delay(HZ
/20); /* Delay 0.05 sec */
242 rc_out(bp
, CD180_GIVR
, RC_ID
); /* Set ID for this chip */
243 rc_out(bp
, CD180_GICR
, 0); /* Clear all bits */
244 rc_out(bp
, CD180_PILR1
, RC_ACK_MINT
); /* Prio for modem intr */
245 rc_out(bp
, CD180_PILR2
, RC_ACK_TINT
); /* Prio for transmitter intr */
246 rc_out(bp
, CD180_PILR3
, RC_ACK_RINT
); /* Prio for receiver intr */
248 /* Setting up prescaler. We need 4 ticks per 1 ms */
249 rc_out(bp
, CD180_PPRH
, (RC_OSCFREQ
/(1000000/RISCOM_TPS
)) >> 8);
250 rc_out(bp
, CD180_PPRL
, (RC_OSCFREQ
/(1000000/RISCOM_TPS
)) & 0xff);
252 restore_flags(flags
);
255 /* Main probing routine, also sets irq. */
256 static int __init
rc_probe(struct riscom_board
*bp
)
258 unsigned char val1
, val2
;
264 if (rc_request_io_range(bp
))
267 /* Are the I/O ports here ? */
268 rc_out(bp
, CD180_PPRL
, 0x5a);
270 val1
= rc_in(bp
, CD180_PPRL
);
271 rc_out(bp
, CD180_PPRL
, 0xa5);
273 val2
= rc_in(bp
, CD180_PPRL
);
275 if ((val1
!= 0x5a) || (val2
!= 0xa5)) {
276 printk(KERN_ERR
"rc%d: RISCom/8 Board at 0x%03x not found.\n",
277 board_No(bp
), bp
->base
);
281 /* It's time to find IRQ for this board */
282 for (retries
= 0; retries
< 5 && irqs
<= 0; retries
++) {
283 irqs
= probe_irq_on();
284 rc_init_CD180(bp
); /* Reset CD180 chip */
285 rc_out(bp
, CD180_CAR
, 2); /* Select port 2 */
287 rc_out(bp
, CD180_CCR
, CCR_TXEN
); /* Enable transmitter */
288 rc_out(bp
, CD180_IER
, IER_TXRDY
); /* Enable tx empty intr */
289 rc_long_delay(HZ
/20);
290 irqs
= probe_irq_off(irqs
);
291 val1
= rc_in(bp
, RC_BSR
); /* Get Board Status reg */
292 val2
= rc_in(bp
, RC_ACK_TINT
); /* ACK interrupt */
293 rc_init_CD180(bp
); /* Reset CD180 again */
295 if ((val1
& RC_BSR_TINT
) || (val2
!= (RC_ID
| GIVR_IT_TX
))) {
296 printk(KERN_ERR
"rc%d: RISCom/8 Board at 0x%03x not "
297 "found.\n", board_No(bp
), bp
->base
);
303 printk(KERN_ERR
"rc%d: Can't find IRQ for RISCom/8 board "
304 "at 0x%03x.\n", board_No(bp
), bp
->base
);
308 bp
->flags
|= RC_BOARD_PRESENT
;
310 printk(KERN_INFO
"rc%d: RISCom/8 Rev. %c board detected at "
313 (rc_in(bp
, CD180_GFRCR
) & 0x0f) + 'A', /* Board revision */
318 rc_release_io_range(bp
);
324 * Interrupt processing routines.
328 static inline void rc_mark_event(struct riscom_port
* port
, int event
)
330 set_bit(event
, &port
->event
);
331 schedule_work(&port
->tqueue
);
334 static inline struct riscom_port
* rc_get_port(struct riscom_board
const * bp
,
335 unsigned char const * what
)
337 unsigned char channel
;
338 struct riscom_port
* port
;
340 channel
= rc_in(bp
, CD180_GICR
) >> GICR_CHAN_OFF
;
341 if (channel
< CD180_NCH
) {
342 port
= &rc_port
[board_No(bp
) * RC_NPORT
+ channel
];
343 if (port
->flags
& ASYNC_INITIALIZED
) {
347 printk(KERN_ERR
"rc%d: %s interrupt from invalid port %d\n",
348 board_No(bp
), what
, channel
);
352 static inline void rc_receive_exc(struct riscom_board
const * bp
)
354 struct riscom_port
*port
;
355 struct tty_struct
*tty
;
356 unsigned char status
;
359 if (!(port
= rc_get_port(bp
, "Receive")))
363 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
364 printk(KERN_WARNING
"rc%d: port %d: Working around flip "
365 "buffer overflow.\n",
366 board_No(bp
), port_No(port
));
370 #ifdef RC_REPORT_OVERRUN
371 status
= rc_in(bp
, CD180_RCSR
);
372 if (status
& RCSR_OE
) {
375 printk(KERN_ERR
"rc%d: port %d: Overrun. Total %ld overruns\n",
376 board_No(bp
), port_No(port
), port
->overrun
);
379 status
&= port
->mark_mask
;
381 status
= rc_in(bp
, CD180_RCSR
) & port
->mark_mask
;
383 ch
= rc_in(bp
, CD180_RDR
);
387 if (status
& RCSR_TOUT
) {
388 printk(KERN_WARNING
"rc%d: port %d: Receiver timeout. "
389 "Hardware problems ?\n",
390 board_No(bp
), port_No(port
));
393 } else if (status
& RCSR_BREAK
) {
394 printk(KERN_INFO
"rc%d: port %d: Handling break...\n",
395 board_No(bp
), port_No(port
));
396 *tty
->flip
.flag_buf_ptr
++ = TTY_BREAK
;
397 if (port
->flags
& ASYNC_SAK
)
400 } else if (status
& RCSR_PE
)
401 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
403 else if (status
& RCSR_FE
)
404 *tty
->flip
.flag_buf_ptr
++ = TTY_FRAME
;
406 else if (status
& RCSR_OE
)
407 *tty
->flip
.flag_buf_ptr
++ = TTY_OVERRUN
;
410 *tty
->flip
.flag_buf_ptr
++ = 0;
412 *tty
->flip
.char_buf_ptr
++ = ch
;
414 schedule_delayed_work(&tty
->flip
.work
, 1);
417 static inline void rc_receive(struct riscom_board
const * bp
)
419 struct riscom_port
*port
;
420 struct tty_struct
*tty
;
423 if (!(port
= rc_get_port(bp
, "Receive")))
428 count
= rc_in(bp
, CD180_RDCR
);
430 #ifdef RC_REPORT_FIFO
431 port
->hits
[count
> 8 ? 9 : count
]++;
435 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
436 printk(KERN_WARNING
"rc%d: port %d: Working around "
437 "flip buffer overflow.\n",
438 board_No(bp
), port_No(port
));
441 *tty
->flip
.char_buf_ptr
++ = rc_in(bp
, CD180_RDR
);
442 *tty
->flip
.flag_buf_ptr
++ = 0;
445 schedule_delayed_work(&tty
->flip
.work
, 1);
448 static inline void rc_transmit(struct riscom_board
const * bp
)
450 struct riscom_port
*port
;
451 struct tty_struct
*tty
;
455 if (!(port
= rc_get_port(bp
, "Transmit")))
460 if (port
->IER
& IER_TXEMPTY
) {
462 rc_out(bp
, CD180_CAR
, port_No(port
));
463 port
->IER
&= ~IER_TXEMPTY
;
464 rc_out(bp
, CD180_IER
, port
->IER
);
468 if ((port
->xmit_cnt
<= 0 && !port
->break_length
)
469 || tty
->stopped
|| tty
->hw_stopped
) {
470 rc_out(bp
, CD180_CAR
, port_No(port
));
471 port
->IER
&= ~IER_TXRDY
;
472 rc_out(bp
, CD180_IER
, port
->IER
);
476 if (port
->break_length
) {
477 if (port
->break_length
> 0) {
478 if (port
->COR2
& COR2_ETC
) {
479 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
480 rc_out(bp
, CD180_TDR
, CD180_C_SBRK
);
481 port
->COR2
&= ~COR2_ETC
;
483 count
= min_t(int, port
->break_length
, 0xff);
484 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
485 rc_out(bp
, CD180_TDR
, CD180_C_DELAY
);
486 rc_out(bp
, CD180_TDR
, count
);
487 if (!(port
->break_length
-= count
))
488 port
->break_length
--;
490 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
491 rc_out(bp
, CD180_TDR
, CD180_C_EBRK
);
492 rc_out(bp
, CD180_COR2
, port
->COR2
);
494 rc_out(bp
, CD180_CCR
, CCR_CORCHG2
);
495 port
->break_length
= 0;
502 rc_out(bp
, CD180_TDR
, port
->xmit_buf
[port
->xmit_tail
++]);
503 port
->xmit_tail
= port
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
504 if (--port
->xmit_cnt
<= 0)
506 } while (--count
> 0);
508 if (port
->xmit_cnt
<= 0) {
509 rc_out(bp
, CD180_CAR
, port_No(port
));
510 port
->IER
&= ~IER_TXRDY
;
511 rc_out(bp
, CD180_IER
, port
->IER
);
513 if (port
->xmit_cnt
<= port
->wakeup_chars
)
514 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
517 static inline void rc_check_modem(struct riscom_board
const * bp
)
519 struct riscom_port
*port
;
520 struct tty_struct
*tty
;
523 if (!(port
= rc_get_port(bp
, "Modem")))
528 mcr
= rc_in(bp
, CD180_MCR
);
529 if (mcr
& MCR_CDCHG
) {
530 if (rc_in(bp
, CD180_MSVR
) & MSVR_CD
)
531 wake_up_interruptible(&port
->open_wait
);
533 schedule_work(&port
->tqueue_hangup
);
536 #ifdef RISCOM_BRAIN_DAMAGED_CTS
537 if (mcr
& MCR_CTSCHG
) {
538 if (rc_in(bp
, CD180_MSVR
) & MSVR_CTS
) {
540 port
->IER
|= IER_TXRDY
;
541 if (port
->xmit_cnt
<= port
->wakeup_chars
)
542 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
545 port
->IER
&= ~IER_TXRDY
;
547 rc_out(bp
, CD180_IER
, port
->IER
);
549 if (mcr
& MCR_DSRCHG
) {
550 if (rc_in(bp
, CD180_MSVR
) & MSVR_DSR
) {
552 port
->IER
|= IER_TXRDY
;
553 if (port
->xmit_cnt
<= port
->wakeup_chars
)
554 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
557 port
->IER
&= ~IER_TXRDY
;
559 rc_out(bp
, CD180_IER
, port
->IER
);
561 #endif /* RISCOM_BRAIN_DAMAGED_CTS */
563 /* Clear change bits */
564 rc_out(bp
, CD180_MCR
, 0);
567 /* The main interrupt processing routine */
568 static irqreturn_t
rc_interrupt(int irq
, void * dev_id
, struct pt_regs
* regs
)
570 unsigned char status
;
572 struct riscom_board
*bp
;
573 unsigned long loop
= 0;
576 bp
= IRQ_to_board
[irq
];
578 if (!bp
|| !(bp
->flags
& RC_BOARD_ACTIVE
)) {
582 while ((++loop
< 16) && ((status
= ~(rc_in(bp
, RC_BSR
))) &
583 (RC_BSR_TOUT
| RC_BSR_TINT
|
584 RC_BSR_MINT
| RC_BSR_RINT
))) {
586 if (status
& RC_BSR_TOUT
)
587 printk(KERN_WARNING
"rc%d: Got timeout. Hardware "
588 "error?\n", board_No(bp
));
590 else if (status
& RC_BSR_RINT
) {
591 ack
= rc_in(bp
, RC_ACK_RINT
);
593 if (ack
== (RC_ID
| GIVR_IT_RCV
))
595 else if (ack
== (RC_ID
| GIVR_IT_REXC
))
598 printk(KERN_WARNING
"rc%d: Bad receive ack "
602 } else if (status
& RC_BSR_TINT
) {
603 ack
= rc_in(bp
, RC_ACK_TINT
);
605 if (ack
== (RC_ID
| GIVR_IT_TX
))
608 printk(KERN_WARNING
"rc%d: Bad transmit ack "
612 } else /* if (status & RC_BSR_MINT) */ {
613 ack
= rc_in(bp
, RC_ACK_MINT
);
615 if (ack
== (RC_ID
| GIVR_IT_MODEM
))
618 printk(KERN_WARNING
"rc%d: Bad modem ack "
624 rc_out(bp
, CD180_EOIR
, 0); /* Mark end of interrupt */
625 rc_out(bp
, RC_CTOUT
, 0); /* Clear timeout flag */
627 return IRQ_RETVAL(handled
);
631 * Routines for open & close processing.
634 /* Called with disabled interrupts */
635 static inline int rc_setup_board(struct riscom_board
* bp
)
639 if (bp
->flags
& RC_BOARD_ACTIVE
)
642 error
= request_irq(bp
->irq
, rc_interrupt
, SA_INTERRUPT
,
647 rc_out(bp
, RC_CTOUT
, 0); /* Just in case */
649 rc_out(bp
, RC_DTR
, bp
->DTR
); /* Drop DTR on all ports */
651 IRQ_to_board
[bp
->irq
] = bp
;
652 bp
->flags
|= RC_BOARD_ACTIVE
;
657 /* Called with disabled interrupts */
658 static inline void rc_shutdown_board(struct riscom_board
*bp
)
660 if (!(bp
->flags
& RC_BOARD_ACTIVE
))
663 bp
->flags
&= ~RC_BOARD_ACTIVE
;
665 free_irq(bp
->irq
, NULL
);
666 IRQ_to_board
[bp
->irq
] = NULL
;
669 rc_out(bp
, RC_DTR
, bp
->DTR
); /* Drop DTR on all ports */
674 * Setting up port characteristics.
675 * Must be called with disabled interrupts
677 static void rc_change_speed(struct riscom_board
*bp
, struct riscom_port
*port
)
679 struct tty_struct
*tty
;
682 unsigned char cor1
= 0, cor3
= 0;
683 unsigned char mcor1
= 0, mcor2
= 0;
685 if (!(tty
= port
->tty
) || !tty
->termios
)
690 port
->MSVR
= MSVR_RTS
;
694 if (baud
& CBAUDEX
) {
696 if (baud
< 1 || baud
> 2)
697 port
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
702 if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
704 if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
708 /* Select port on the board */
709 rc_out(bp
, CD180_CAR
, port_No(port
));
711 if (!baud_table
[baud
]) {
712 /* Drop DTR & exit */
713 bp
->DTR
|= (1u << port_No(port
));
714 rc_out(bp
, RC_DTR
, bp
->DTR
);
718 bp
->DTR
&= ~(1u << port_No(port
));
719 rc_out(bp
, RC_DTR
, bp
->DTR
);
723 * Now we must calculate some speed depended things
726 /* Set baud rate for port */
727 tmp
= (((RC_OSCFREQ
+ baud_table
[baud
]/2) / baud_table
[baud
] +
728 CD180_TPC
/2) / CD180_TPC
);
730 rc_out(bp
, CD180_RBPRH
, (tmp
>> 8) & 0xff);
731 rc_out(bp
, CD180_TBPRH
, (tmp
>> 8) & 0xff);
732 rc_out(bp
, CD180_RBPRL
, tmp
& 0xff);
733 rc_out(bp
, CD180_TBPRL
, tmp
& 0xff);
735 baud
= (baud_table
[baud
] + 5) / 10; /* Estimated CPS */
737 /* Two timer ticks seems enough to wakeup something like SLIP driver */
738 tmp
= ((baud
+ HZ
/2) / HZ
) * 2 - CD180_NFIFO
;
739 port
->wakeup_chars
= (tmp
< 0) ? 0 : ((tmp
>= SERIAL_XMIT_SIZE
) ?
740 SERIAL_XMIT_SIZE
- 1 : tmp
);
742 /* Receiver timeout will be transmission time for 1.5 chars */
743 tmp
= (RISCOM_TPS
+ RISCOM_TPS
/2 + baud
/2) / baud
;
744 tmp
= (tmp
> 0xff) ? 0xff : tmp
;
745 rc_out(bp
, CD180_RTPR
, tmp
);
747 switch (C_CSIZE(tty
)) {
767 cor1
|= COR1_NORMPAR
;
771 cor1
&= ~COR1_IGNORE
;
773 /* Set marking of some errors */
774 port
->mark_mask
= RCSR_OE
| RCSR_TOUT
;
776 port
->mark_mask
|= RCSR_FE
| RCSR_PE
;
777 if (I_BRKINT(tty
) || I_PARMRK(tty
))
778 port
->mark_mask
|= RCSR_BREAK
;
780 port
->mark_mask
&= ~(RCSR_FE
| RCSR_PE
);
782 port
->mark_mask
&= ~RCSR_BREAK
;
784 /* Real raw mode. Ignore all */
785 port
->mark_mask
&= ~RCSR_OE
;
787 /* Enable Hardware Flow Control */
788 if (C_CRTSCTS(tty
)) {
789 #ifdef RISCOM_BRAIN_DAMAGED_CTS
790 port
->IER
|= IER_DSR
| IER_CTS
;
791 mcor1
|= MCOR1_DSRZD
| MCOR1_CTSZD
;
792 mcor2
|= MCOR2_DSROD
| MCOR2_CTSOD
;
793 tty
->hw_stopped
= !(rc_in(bp
, CD180_MSVR
) & (MSVR_CTS
|MSVR_DSR
));
795 port
->COR2
|= COR2_CTSAE
;
798 /* Enable Software Flow Control. FIXME: I'm not sure about this */
799 /* Some people reported that it works, but I still doubt */
801 port
->COR2
|= COR2_TXIBE
;
802 cor3
|= (COR3_FCT
| COR3_SCDE
);
804 port
->COR2
|= COR2_IXM
;
805 rc_out(bp
, CD180_SCHR1
, START_CHAR(tty
));
806 rc_out(bp
, CD180_SCHR2
, STOP_CHAR(tty
));
807 rc_out(bp
, CD180_SCHR3
, START_CHAR(tty
));
808 rc_out(bp
, CD180_SCHR4
, STOP_CHAR(tty
));
810 if (!C_CLOCAL(tty
)) {
811 /* Enable CD check */
818 /* Enable receiver */
819 port
->IER
|= IER_RXD
;
821 /* Set input FIFO size (1-8 bytes) */
822 cor3
|= RISCOM_RXFIFO
;
823 /* Setting up CD180 channel registers */
824 rc_out(bp
, CD180_COR1
, cor1
);
825 rc_out(bp
, CD180_COR2
, port
->COR2
);
826 rc_out(bp
, CD180_COR3
, cor3
);
827 /* Make CD180 know about registers change */
829 rc_out(bp
, CD180_CCR
, CCR_CORCHG1
| CCR_CORCHG2
| CCR_CORCHG3
);
830 /* Setting up modem option registers */
831 rc_out(bp
, CD180_MCOR1
, mcor1
);
832 rc_out(bp
, CD180_MCOR2
, mcor2
);
833 /* Enable CD180 transmitter & receiver */
835 rc_out(bp
, CD180_CCR
, CCR_TXEN
| CCR_RXEN
);
836 /* Enable interrupts */
837 rc_out(bp
, CD180_IER
, port
->IER
);
838 /* And finally set RTS on */
839 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
842 /* Must be called with interrupts enabled */
843 static int rc_setup_port(struct riscom_board
*bp
, struct riscom_port
*port
)
847 if (port
->flags
& ASYNC_INITIALIZED
)
850 if (!port
->xmit_buf
) {
851 /* We may sleep in get_zeroed_page() */
854 if (!(tmp
= get_zeroed_page(GFP_KERNEL
)))
857 if (port
->xmit_buf
) {
861 port
->xmit_buf
= (unsigned char *) tmp
;
864 save_flags(flags
); cli();
867 clear_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
869 if (port
->count
== 1)
872 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
873 rc_change_speed(bp
, port
);
874 port
->flags
|= ASYNC_INITIALIZED
;
876 restore_flags(flags
);
880 /* Must be called with interrupts disabled */
881 static void rc_shutdown_port(struct riscom_board
*bp
, struct riscom_port
*port
)
883 struct tty_struct
*tty
;
885 if (!(port
->flags
& ASYNC_INITIALIZED
))
888 #ifdef RC_REPORT_OVERRUN
889 printk(KERN_INFO
"rc%d: port %d: Total %ld overruns were detected.\n",
890 board_No(bp
), port_No(port
), port
->overrun
);
892 #ifdef RC_REPORT_FIFO
896 printk(KERN_INFO
"rc%d: port %d: FIFO hits [ ",
897 board_No(bp
), port_No(port
));
898 for (i
= 0; i
< 10; i
++) {
899 printk("%ld ", port
->hits
[i
]);
904 if (port
->xmit_buf
) {
905 free_page((unsigned long) port
->xmit_buf
);
906 port
->xmit_buf
= NULL
;
909 if (!(tty
= port
->tty
) || C_HUPCL(tty
)) {
911 bp
->DTR
|= (1u << port_No(port
));
912 rc_out(bp
, RC_DTR
, bp
->DTR
);
916 rc_out(bp
, CD180_CAR
, port_No(port
));
919 rc_out(bp
, CD180_CCR
, CCR_SOFTRESET
);
920 /* Disable all interrupts from this port */
922 rc_out(bp
, CD180_IER
, port
->IER
);
925 set_bit(TTY_IO_ERROR
, &tty
->flags
);
926 port
->flags
&= ~ASYNC_INITIALIZED
;
928 if (--bp
->count
< 0) {
929 printk(KERN_INFO
"rc%d: rc_shutdown_port: "
930 "bad board count: %d\n",
931 board_No(bp
), bp
->count
);
936 * If this is the last opened port on the board
937 * shutdown whole board
940 rc_shutdown_board(bp
);
944 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
945 struct riscom_port
*port
)
947 DECLARE_WAITQUEUE(wait
, current
);
948 struct riscom_board
*bp
= port_Board(port
);
954 * If the device is in the middle of being closed, then block
955 * until it's done, and then try again.
957 if (tty_hung_up_p(filp
) || port
->flags
& ASYNC_CLOSING
) {
958 interruptible_sleep_on(&port
->close_wait
);
959 if (port
->flags
& ASYNC_HUP_NOTIFY
)
966 * If non-blocking mode is set, or the port is not enabled,
967 * then make the check up front and then exit.
969 if ((filp
->f_flags
& O_NONBLOCK
) ||
970 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
971 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
979 * Block waiting for the carrier detect and the line to become
980 * free (i.e., not in use by the callout). While we are in
981 * this loop, info->count is dropped by one, so that
982 * rs_close() knows when to free things. We restore it upon
983 * exit, either normal or abnormal.
986 add_wait_queue(&port
->open_wait
, &wait
);
988 if (!tty_hung_up_p(filp
))
991 port
->blocked_open
++;
994 rc_out(bp
, CD180_CAR
, port_No(port
));
995 CD
= rc_in(bp
, CD180_MSVR
) & MSVR_CD
;
996 rc_out(bp
, CD180_MSVR
, MSVR_RTS
);
997 bp
->DTR
&= ~(1u << port_No(port
));
998 rc_out(bp
, RC_DTR
, bp
->DTR
);
1000 set_current_state(TASK_INTERRUPTIBLE
);
1001 if (tty_hung_up_p(filp
) ||
1002 !(port
->flags
& ASYNC_INITIALIZED
)) {
1003 if (port
->flags
& ASYNC_HUP_NOTIFY
)
1006 retval
= -ERESTARTSYS
;
1009 if (!(port
->flags
& ASYNC_CLOSING
) &&
1012 if (signal_pending(current
)) {
1013 retval
= -ERESTARTSYS
;
1018 current
->state
= TASK_RUNNING
;
1019 remove_wait_queue(&port
->open_wait
, &wait
);
1020 if (!tty_hung_up_p(filp
))
1022 port
->blocked_open
--;
1026 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
1030 static int rc_open(struct tty_struct
* tty
, struct file
* filp
)
1034 struct riscom_port
* port
;
1035 struct riscom_board
* bp
;
1037 board
= RC_BOARD(tty
->index
);
1038 if (board
>= RC_NBOARD
|| !(rc_board
[board
].flags
& RC_BOARD_PRESENT
))
1041 bp
= &rc_board
[board
];
1042 port
= rc_port
+ board
* RC_NPORT
+ RC_PORT(tty
->index
);
1043 if (rc_paranoia_check(port
, tty
->name
, "rc_open"))
1046 if ((error
= rc_setup_board(bp
)))
1050 tty
->driver_data
= port
;
1053 if ((error
= rc_setup_port(bp
, port
)))
1056 if ((error
= block_til_ready(tty
, filp
, port
)))
1062 static void rc_close(struct tty_struct
* tty
, struct file
* filp
)
1064 struct riscom_port
*port
= (struct riscom_port
*) tty
->driver_data
;
1065 struct riscom_board
*bp
;
1066 unsigned long flags
;
1067 unsigned long timeout
;
1069 if (!port
|| rc_paranoia_check(port
, tty
->name
, "close"))
1072 save_flags(flags
); cli();
1073 if (tty_hung_up_p(filp
))
1076 bp
= port_Board(port
);
1077 if ((tty
->count
== 1) && (port
->count
!= 1)) {
1078 printk(KERN_INFO
"rc%d: rc_close: bad port count;"
1079 " tty->count is 1, port count is %d\n",
1080 board_No(bp
), port
->count
);
1083 if (--port
->count
< 0) {
1084 printk(KERN_INFO
"rc%d: rc_close: bad port count "
1086 board_No(bp
), port_No(port
), port
->count
);
1091 port
->flags
|= ASYNC_CLOSING
;
1093 * Now we wait for the transmit buffer to clear; and we notify
1094 * the line discipline to only process XON/XOFF characters.
1097 if (port
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1098 tty_wait_until_sent(tty
, port
->closing_wait
);
1100 * At this point we stop accepting input. To do this, we
1101 * disable the receive line status interrupts, and tell the
1102 * interrupt driver to stop checking the data ready bit in the
1103 * line status register.
1105 port
->IER
&= ~IER_RXD
;
1106 if (port
->flags
& ASYNC_INITIALIZED
) {
1107 port
->IER
&= ~IER_TXRDY
;
1108 port
->IER
|= IER_TXEMPTY
;
1109 rc_out(bp
, CD180_CAR
, port_No(port
));
1110 rc_out(bp
, CD180_IER
, port
->IER
);
1112 * Before we drop DTR, make sure the UART transmitter
1113 * has completely drained; this is especially
1114 * important if there is a transmit FIFO!
1116 timeout
= jiffies
+HZ
;
1117 while(port
->IER
& IER_TXEMPTY
) {
1118 msleep_interruptible(jiffies_to_msecs(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 msleep_interruptible(jiffies_to_msecs(port
->close_delay
));
1135 wake_up_interruptible(&port
->open_wait
);
1137 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1138 wake_up_interruptible(&port
->close_wait
);
1139 out
: restore_flags(flags
);
1142 static int rc_write(struct tty_struct
* tty
,
1143 const unsigned char *buf
, int count
)
1145 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1146 struct riscom_board
*bp
;
1148 unsigned long flags
;
1150 if (rc_paranoia_check(port
, tty
->name
, "rc_write"))
1153 bp
= port_Board(port
);
1155 if (!tty
|| !port
->xmit_buf
|| !tmp_buf
)
1161 c
= min_t(int, count
, min(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1162 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1164 restore_flags(flags
);
1168 memcpy(port
->xmit_buf
+ port
->xmit_head
, buf
, c
);
1169 port
->xmit_head
= (port
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
1170 port
->xmit_cnt
+= c
;
1171 restore_flags(flags
);
1179 if (port
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
&&
1180 !(port
->IER
& IER_TXRDY
)) {
1181 port
->IER
|= IER_TXRDY
;
1182 rc_out(bp
, CD180_CAR
, port_No(port
));
1183 rc_out(bp
, CD180_IER
, port
->IER
);
1185 restore_flags(flags
);
1190 static void rc_put_char(struct tty_struct
* tty
, unsigned char ch
)
1192 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1193 unsigned long flags
;
1195 if (rc_paranoia_check(port
, tty
->name
, "rc_put_char"))
1198 if (!tty
|| !port
->xmit_buf
)
1201 save_flags(flags
); cli();
1203 if (port
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1)
1206 port
->xmit_buf
[port
->xmit_head
++] = ch
;
1207 port
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
1209 out
: restore_flags(flags
);
1212 static void rc_flush_chars(struct tty_struct
* tty
)
1214 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1215 unsigned long flags
;
1217 if (rc_paranoia_check(port
, tty
->name
, "rc_flush_chars"))
1220 if (port
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
1224 save_flags(flags
); cli();
1225 port
->IER
|= IER_TXRDY
;
1226 rc_out(port_Board(port
), CD180_CAR
, port_No(port
));
1227 rc_out(port_Board(port
), CD180_IER
, port
->IER
);
1228 restore_flags(flags
);
1231 static int rc_write_room(struct tty_struct
* tty
)
1233 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1236 if (rc_paranoia_check(port
, tty
->name
, "rc_write_room"))
1239 ret
= SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1;
1245 static int rc_chars_in_buffer(struct tty_struct
*tty
)
1247 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1249 if (rc_paranoia_check(port
, tty
->name
, "rc_chars_in_buffer"))
1252 return port
->xmit_cnt
;
1255 static void rc_flush_buffer(struct tty_struct
*tty
)
1257 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1258 unsigned long flags
;
1260 if (rc_paranoia_check(port
, tty
->name
, "rc_flush_buffer"))
1263 save_flags(flags
); cli();
1264 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
1265 restore_flags(flags
);
1267 wake_up_interruptible(&tty
->write_wait
);
1271 static int rc_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1273 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1274 struct riscom_board
* bp
;
1275 unsigned char status
;
1276 unsigned int result
;
1277 unsigned long flags
;
1279 if (rc_paranoia_check(port
, tty
->name
, __FUNCTION__
))
1282 bp
= port_Board(port
);
1283 save_flags(flags
); cli();
1284 rc_out(bp
, CD180_CAR
, port_No(port
));
1285 status
= rc_in(bp
, CD180_MSVR
);
1286 result
= rc_in(bp
, RC_RI
) & (1u << port_No(port
)) ? 0 : TIOCM_RNG
;
1287 restore_flags(flags
);
1288 result
|= ((status
& MSVR_RTS
) ? TIOCM_RTS
: 0)
1289 | ((status
& MSVR_DTR
) ? TIOCM_DTR
: 0)
1290 | ((status
& MSVR_CD
) ? TIOCM_CAR
: 0)
1291 | ((status
& MSVR_DSR
) ? TIOCM_DSR
: 0)
1292 | ((status
& MSVR_CTS
) ? TIOCM_CTS
: 0);
1296 static int rc_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1297 unsigned int set
, unsigned int clear
)
1299 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1300 unsigned long flags
;
1301 struct riscom_board
*bp
;
1303 if (rc_paranoia_check(port
, tty
->name
, __FUNCTION__
))
1306 bp
= port_Board(port
);
1308 save_flags(flags
); cli();
1309 if (set
& TIOCM_RTS
)
1310 port
->MSVR
|= MSVR_RTS
;
1311 if (set
& TIOCM_DTR
)
1312 bp
->DTR
&= ~(1u << port_No(port
));
1314 if (clear
& TIOCM_RTS
)
1315 port
->MSVR
&= ~MSVR_RTS
;
1316 if (clear
& TIOCM_DTR
)
1317 bp
->DTR
|= (1u << port_No(port
));
1319 rc_out(bp
, CD180_CAR
, port_No(port
));
1320 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1321 rc_out(bp
, RC_DTR
, bp
->DTR
);
1322 restore_flags(flags
);
1326 static inline void rc_send_break(struct riscom_port
* port
, unsigned long length
)
1328 struct riscom_board
*bp
= port_Board(port
);
1329 unsigned long flags
;
1331 save_flags(flags
); cli();
1332 port
->break_length
= RISCOM_TPS
/ HZ
* length
;
1333 port
->COR2
|= COR2_ETC
;
1334 port
->IER
|= IER_TXRDY
;
1335 rc_out(bp
, CD180_CAR
, port_No(port
));
1336 rc_out(bp
, CD180_COR2
, port
->COR2
);
1337 rc_out(bp
, CD180_IER
, port
->IER
);
1339 rc_out(bp
, CD180_CCR
, CCR_CORCHG2
);
1341 restore_flags(flags
);
1344 static inline int rc_set_serial_info(struct riscom_port
* port
,
1345 struct serial_struct __user
* newinfo
)
1347 struct serial_struct tmp
;
1348 struct riscom_board
*bp
= port_Board(port
);
1350 unsigned long flags
;
1352 if (copy_from_user(&tmp
, newinfo
, sizeof(tmp
)))
1356 if ((tmp
.irq
!= bp
->irq
) ||
1357 (tmp
.port
!= bp
->base
) ||
1358 (tmp
.type
!= PORT_CIRRUS
) ||
1359 (tmp
.baud_base
!= (RC_OSCFREQ
+ CD180_TPC
/2) / CD180_TPC
) ||
1360 (tmp
.custom_divisor
!= 0) ||
1361 (tmp
.xmit_fifo_size
!= CD180_NFIFO
) ||
1362 (tmp
.flags
& ~RISCOM_LEGAL_FLAGS
))
1366 change_speed
= ((port
->flags
& ASYNC_SPD_MASK
) !=
1367 (tmp
.flags
& ASYNC_SPD_MASK
));
1369 if (!capable(CAP_SYS_ADMIN
)) {
1370 if ((tmp
.close_delay
!= port
->close_delay
) ||
1371 (tmp
.closing_wait
!= port
->closing_wait
) ||
1372 ((tmp
.flags
& ~ASYNC_USR_MASK
) !=
1373 (port
->flags
& ~ASYNC_USR_MASK
)))
1375 port
->flags
= ((port
->flags
& ~ASYNC_USR_MASK
) |
1376 (tmp
.flags
& ASYNC_USR_MASK
));
1378 port
->flags
= ((port
->flags
& ~ASYNC_FLAGS
) |
1379 (tmp
.flags
& ASYNC_FLAGS
));
1380 port
->close_delay
= tmp
.close_delay
;
1381 port
->closing_wait
= tmp
.closing_wait
;
1384 save_flags(flags
); cli();
1385 rc_change_speed(bp
, port
);
1386 restore_flags(flags
);
1391 static inline int rc_get_serial_info(struct riscom_port
* port
,
1392 struct serial_struct __user
*retinfo
)
1394 struct serial_struct tmp
;
1395 struct riscom_board
*bp
= port_Board(port
);
1397 memset(&tmp
, 0, sizeof(tmp
));
1398 tmp
.type
= PORT_CIRRUS
;
1399 tmp
.line
= port
- rc_port
;
1400 tmp
.port
= bp
->base
;
1402 tmp
.flags
= port
->flags
;
1403 tmp
.baud_base
= (RC_OSCFREQ
+ CD180_TPC
/2) / CD180_TPC
;
1404 tmp
.close_delay
= port
->close_delay
* HZ
/100;
1405 tmp
.closing_wait
= port
->closing_wait
* HZ
/100;
1406 tmp
.xmit_fifo_size
= CD180_NFIFO
;
1407 return copy_to_user(retinfo
, &tmp
, sizeof(tmp
)) ? -EFAULT
: 0;
1410 static int rc_ioctl(struct tty_struct
* tty
, struct file
* filp
,
1411 unsigned int cmd
, unsigned long arg
)
1414 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1415 void __user
*argp
= (void __user
*)arg
;
1418 if (rc_paranoia_check(port
, tty
->name
, "rc_ioctl"))
1422 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1423 retval
= tty_check_change(tty
);
1426 tty_wait_until_sent(tty
, 0);
1428 rc_send_break(port
, HZ
/4); /* 1/4 second */
1430 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1431 retval
= tty_check_change(tty
);
1434 tty_wait_until_sent(tty
, 0);
1435 rc_send_break(port
, arg
? arg
*(HZ
/10) : HZ
/4);
1438 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned __user
*)argp
);
1440 if (get_user(arg
,(unsigned __user
*) argp
))
1442 tty
->termios
->c_cflag
=
1443 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1444 (arg
? CLOCAL
: 0));
1447 return rc_get_serial_info(port
, argp
);
1449 return rc_set_serial_info(port
, argp
);
1451 return -ENOIOCTLCMD
;
1456 static void rc_throttle(struct tty_struct
* tty
)
1458 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1459 struct riscom_board
*bp
;
1460 unsigned long flags
;
1462 if (rc_paranoia_check(port
, tty
->name
, "rc_throttle"))
1465 bp
= port_Board(port
);
1467 save_flags(flags
); cli();
1468 port
->MSVR
&= ~MSVR_RTS
;
1469 rc_out(bp
, CD180_CAR
, port_No(port
));
1472 rc_out(bp
, CD180_CCR
, CCR_SSCH2
);
1475 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1476 restore_flags(flags
);
1479 static void rc_unthrottle(struct tty_struct
* tty
)
1481 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1482 struct riscom_board
*bp
;
1483 unsigned long flags
;
1485 if (rc_paranoia_check(port
, tty
->name
, "rc_unthrottle"))
1488 bp
= port_Board(port
);
1490 save_flags(flags
); cli();
1491 port
->MSVR
|= MSVR_RTS
;
1492 rc_out(bp
, CD180_CAR
, port_No(port
));
1495 rc_out(bp
, CD180_CCR
, CCR_SSCH1
);
1498 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1499 restore_flags(flags
);
1502 static void rc_stop(struct tty_struct
* tty
)
1504 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1505 struct riscom_board
*bp
;
1506 unsigned long flags
;
1508 if (rc_paranoia_check(port
, tty
->name
, "rc_stop"))
1511 bp
= port_Board(port
);
1513 save_flags(flags
); cli();
1514 port
->IER
&= ~IER_TXRDY
;
1515 rc_out(bp
, CD180_CAR
, port_No(port
));
1516 rc_out(bp
, CD180_IER
, port
->IER
);
1517 restore_flags(flags
);
1520 static void rc_start(struct tty_struct
* tty
)
1522 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1523 struct riscom_board
*bp
;
1524 unsigned long flags
;
1526 if (rc_paranoia_check(port
, tty
->name
, "rc_start"))
1529 bp
= port_Board(port
);
1531 save_flags(flags
); cli();
1532 if (port
->xmit_cnt
&& port
->xmit_buf
&& !(port
->IER
& IER_TXRDY
)) {
1533 port
->IER
|= IER_TXRDY
;
1534 rc_out(bp
, CD180_CAR
, port_No(port
));
1535 rc_out(bp
, CD180_IER
, port
->IER
);
1537 restore_flags(flags
);
1541 * This routine is called from the work queue when the interrupt
1542 * routine has signalled that a hangup has occurred. The path of
1543 * hangup processing is:
1545 * serial interrupt routine -> (workqueue) ->
1546 * do_rc_hangup() -> tty->hangup() -> rc_hangup()
1549 static void do_rc_hangup(void *private_
)
1551 struct riscom_port
*port
= (struct riscom_port
*) private_
;
1552 struct tty_struct
*tty
;
1556 tty_hangup(tty
); /* FIXME: module removal race still here */
1559 static void rc_hangup(struct tty_struct
* tty
)
1561 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1562 struct riscom_board
*bp
;
1564 if (rc_paranoia_check(port
, tty
->name
, "rc_hangup"))
1567 bp
= port_Board(port
);
1569 rc_shutdown_port(bp
, port
);
1572 port
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1574 wake_up_interruptible(&port
->open_wait
);
1577 static void rc_set_termios(struct tty_struct
* tty
, struct termios
* old_termios
)
1579 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1580 unsigned long flags
;
1582 if (rc_paranoia_check(port
, tty
->name
, "rc_set_termios"))
1585 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
&&
1586 tty
->termios
->c_iflag
== old_termios
->c_iflag
)
1589 save_flags(flags
); cli();
1590 rc_change_speed(port_Board(port
), port
);
1591 restore_flags(flags
);
1593 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1594 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1595 tty
->hw_stopped
= 0;
1600 static void do_softint(void *private_
)
1602 struct riscom_port
*port
= (struct riscom_port
*) private_
;
1603 struct tty_struct
*tty
;
1605 if(!(tty
= port
->tty
))
1608 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &port
->event
)) {
1610 wake_up_interruptible(&tty
->write_wait
);
1614 static struct tty_operations riscom_ops
= {
1618 .put_char
= rc_put_char
,
1619 .flush_chars
= rc_flush_chars
,
1620 .write_room
= rc_write_room
,
1621 .chars_in_buffer
= rc_chars_in_buffer
,
1622 .flush_buffer
= rc_flush_buffer
,
1624 .throttle
= rc_throttle
,
1625 .unthrottle
= rc_unthrottle
,
1626 .set_termios
= rc_set_termios
,
1629 .hangup
= rc_hangup
,
1630 .tiocmget
= rc_tiocmget
,
1631 .tiocmset
= rc_tiocmset
,
1634 static inline int rc_init_drivers(void)
1639 riscom_driver
= alloc_tty_driver(RC_NBOARD
* RC_NPORT
);
1643 if (!(tmp_buf
= (unsigned char *) get_zeroed_page(GFP_KERNEL
))) {
1644 printk(KERN_ERR
"rc: Couldn't get free page.\n");
1645 put_tty_driver(riscom_driver
);
1648 memset(IRQ_to_board
, 0, sizeof(IRQ_to_board
));
1649 riscom_driver
->owner
= THIS_MODULE
;
1650 riscom_driver
->name
= "ttyL";
1651 riscom_driver
->devfs_name
= "tts/L";
1652 riscom_driver
->major
= RISCOM8_NORMAL_MAJOR
;
1653 riscom_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1654 riscom_driver
->subtype
= SERIAL_TYPE_NORMAL
;
1655 riscom_driver
->init_termios
= tty_std_termios
;
1656 riscom_driver
->init_termios
.c_cflag
=
1657 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1658 riscom_driver
->flags
= TTY_DRIVER_REAL_RAW
;
1659 tty_set_operations(riscom_driver
, &riscom_ops
);
1660 if ((error
= tty_register_driver(riscom_driver
))) {
1661 free_page((unsigned long)tmp_buf
);
1662 put_tty_driver(riscom_driver
);
1663 printk(KERN_ERR
"rc: Couldn't register RISCom/8 driver, "
1669 memset(rc_port
, 0, sizeof(rc_port
));
1670 for (i
= 0; i
< RC_NPORT
* RC_NBOARD
; i
++) {
1671 rc_port
[i
].magic
= RISCOM8_MAGIC
;
1672 INIT_WORK(&rc_port
[i
].tqueue
, do_softint
, &rc_port
[i
]);
1673 INIT_WORK(&rc_port
[i
].tqueue_hangup
, do_rc_hangup
, &rc_port
[i
]);
1674 rc_port
[i
].close_delay
= 50 * HZ
/100;
1675 rc_port
[i
].closing_wait
= 3000 * HZ
/100;
1676 init_waitqueue_head(&rc_port
[i
].open_wait
);
1677 init_waitqueue_head(&rc_port
[i
].close_wait
);
1683 static void rc_release_drivers(void)
1685 unsigned long flags
;
1689 free_page((unsigned long)tmp_buf
);
1690 tty_unregister_driver(riscom_driver
);
1691 put_tty_driver(riscom_driver
);
1692 restore_flags(flags
);
1697 * Called at boot time.
1699 * You can specify IO base for up to RC_NBOARD cards,
1700 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
1701 * Note that there will be no probing at default
1702 * addresses in this case.
1705 static int __init
riscom8_setup(char *str
)
1707 int ints
[RC_NBOARD
];
1710 str
= get_options(str
, ARRAY_SIZE(ints
), ints
);
1712 for (i
= 0; i
< RC_NBOARD
; i
++) {
1714 rc_board
[i
].base
= ints
[i
+1];
1716 rc_board
[i
].base
= 0;
1721 __setup("riscom8=", riscom8_setup
);
1724 static char banner
[] __initdata
=
1725 KERN_INFO
"rc: SDL RISCom/8 card driver v1.1, (c) D.Gorodchanin "
1727 static char no_boards_msg
[] __initdata
=
1728 KERN_INFO
"rc: No RISCom/8 boards detected.\n";
1731 * This routine must be called by kernel at boot time
1733 static int __init
riscom8_init(void)
1740 if (rc_init_drivers())
1743 for (i
= 0; i
< RC_NBOARD
; i
++)
1744 if (rc_board
[i
].base
&& !rc_probe(&rc_board
[i
]))
1748 rc_release_drivers();
1749 printk(no_boards_msg
);
1760 MODULE_PARM(iobase
, "i");
1761 MODULE_PARM(iobase1
, "i");
1762 MODULE_PARM(iobase2
, "i");
1763 MODULE_PARM(iobase3
, "i");
1765 MODULE_LICENSE("GPL");
1769 * You can setup up to 4 boards (current value of RC_NBOARD)
1770 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter.
1773 static int __init
riscom8_init_module (void)
1778 if (iobase
|| iobase1
|| iobase2
|| iobase3
) {
1779 for(i
= 0; i
< RC_NBOARD
; i
++)
1780 rc_board
[0].base
= 0;
1784 rc_board
[0].base
= iobase
;
1786 rc_board
[1].base
= iobase1
;
1788 rc_board
[2].base
= iobase2
;
1790 rc_board
[3].base
= iobase3
;
1793 return riscom8_init();
1796 static void __exit
riscom8_exit_module (void)
1800 rc_release_drivers();
1801 for (i
= 0; i
< RC_NBOARD
; i
++)
1802 if (rc_board
[i
].flags
& RC_BOARD_PRESENT
)
1803 rc_release_io_range(&rc_board
[i
]);
1807 module_init(riscom8_init_module
);
1808 module_exit(riscom8_exit_module
);