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>
49 #include <linux/tty_flip.h>
51 #include <asm/uaccess.h>
54 #include "riscom8_reg.h"
56 /* Am I paranoid or not ? ;-) */
57 #define RISCOM_PARANOIA_CHECK
60 * Crazy InteliCom/8 boards sometimes has swapped CTS & DSR signals.
61 * You can slightly speed up things by #undefing the following option,
62 * if you are REALLY sure that your board is correct one.
65 #define RISCOM_BRAIN_DAMAGED_CTS
68 * The following defines are mostly for testing purposes. But if you need
69 * some nice reporting in your syslog, you can define them also.
72 #undef RC_REPORT_OVERRUN
75 #define RISCOM_LEGAL_FLAGS \
76 (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \
77 ASYNC_SPD_HI | ASYNC_SPEED_VHI | ASYNC_SESSION_LOCKOUT | \
78 ASYNC_PGRP_LOCKOUT | ASYNC_CALLOUT_NOHUP)
80 #define RS_EVENT_WRITE_WAKEUP 0
82 static struct riscom_board
* IRQ_to_board
[16];
83 static struct tty_driver
*riscom_driver
;
85 static struct riscom_board rc_board
[RC_NBOARD
] = {
100 static struct riscom_port rc_port
[RC_NBOARD
* RC_NPORT
];
102 /* RISCom/8 I/O ports addresses (without address translation) */
103 static unsigned short rc_ioport
[] = {
105 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c,
107 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10,
108 0x11, 0x12, 0x18, 0x28, 0x31, 0x32, 0x39, 0x3a, 0x40, 0x41, 0x61, 0x62,
109 0x63, 0x64, 0x6b, 0x70, 0x71, 0x78, 0x7a, 0x7b, 0x7f, 0x100, 0x101
112 #define RC_NIOPORT ARRAY_SIZE(rc_ioport)
115 static inline int rc_paranoia_check(struct riscom_port
const * port
,
116 char *name
, const char *routine
)
118 #ifdef RISCOM_PARANOIA_CHECK
119 static const char badmagic
[] = KERN_INFO
120 "rc: Warning: bad riscom port magic number for device %s in %s\n";
121 static const char badinfo
[] = KERN_INFO
122 "rc: Warning: null riscom port for device %s in %s\n";
125 printk(badinfo
, name
, routine
);
128 if (port
->magic
!= RISCOM8_MAGIC
) {
129 printk(badmagic
, name
, routine
);
138 * Service functions for RISCom/8 driver.
142 /* Get board number from pointer */
143 static inline int board_No (struct riscom_board
const * bp
)
145 return bp
- rc_board
;
148 /* Get port number from pointer */
149 static inline int port_No (struct riscom_port
const * port
)
151 return RC_PORT(port
- rc_port
);
154 /* Get pointer to board from pointer to port */
155 static inline struct riscom_board
* port_Board(struct riscom_port
const * port
)
157 return &rc_board
[RC_BOARD(port
- rc_port
)];
160 /* Input Byte from CL CD180 register */
161 static inline unsigned char rc_in(struct riscom_board
const * bp
, unsigned short reg
)
163 return inb(bp
->base
+ RC_TO_ISA(reg
));
166 /* Output Byte to CL CD180 register */
167 static inline void rc_out(struct riscom_board
const * bp
, unsigned short reg
,
170 outb(val
, bp
->base
+ RC_TO_ISA(reg
));
173 /* Wait for Channel Command Register ready */
174 static inline void rc_wait_CCR(struct riscom_board
const * bp
)
178 /* FIXME: need something more descriptive then 100000 :) */
179 for (delay
= 100000; delay
; delay
--)
180 if (!rc_in(bp
, CD180_CCR
))
183 printk(KERN_INFO
"rc%d: Timeout waiting for CCR.\n", board_No(bp
));
187 * RISCom/8 probe functions.
190 static inline int rc_request_io_range(struct riscom_board
* const bp
)
194 for (i
= 0; i
< RC_NIOPORT
; i
++)
195 if (!request_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1,
201 printk(KERN_INFO
"rc%d: Skipping probe at 0x%03x. IO address in use.\n",
202 board_No(bp
), bp
->base
);
204 release_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1);
208 static inline void rc_release_io_range(struct riscom_board
* const bp
)
212 for (i
= 0; i
< RC_NIOPORT
; i
++)
213 release_region(RC_TO_ISA(rc_ioport
[i
]) + bp
->base
, 1);
216 /* Must be called with enabled interrupts */
217 static inline void rc_long_delay(unsigned long delay
)
221 for (i
= jiffies
+ delay
; time_after(i
,jiffies
); ) ;
224 /* Reset and setup CD180 chip */
225 static void __init
rc_init_CD180(struct riscom_board
const * bp
)
229 save_flags(flags
); cli();
230 rc_out(bp
, RC_CTOUT
, 0); /* Clear timeout */
231 rc_wait_CCR(bp
); /* Wait for CCR ready */
232 rc_out(bp
, CD180_CCR
, CCR_HARDRESET
); /* Reset CD180 chip */
234 rc_long_delay(HZ
/20); /* Delay 0.05 sec */
236 rc_out(bp
, CD180_GIVR
, RC_ID
); /* Set ID for this chip */
237 rc_out(bp
, CD180_GICR
, 0); /* Clear all bits */
238 rc_out(bp
, CD180_PILR1
, RC_ACK_MINT
); /* Prio for modem intr */
239 rc_out(bp
, CD180_PILR2
, RC_ACK_TINT
); /* Prio for transmitter intr */
240 rc_out(bp
, CD180_PILR3
, RC_ACK_RINT
); /* Prio for receiver intr */
242 /* Setting up prescaler. We need 4 ticks per 1 ms */
243 rc_out(bp
, CD180_PPRH
, (RC_OSCFREQ
/(1000000/RISCOM_TPS
)) >> 8);
244 rc_out(bp
, CD180_PPRL
, (RC_OSCFREQ
/(1000000/RISCOM_TPS
)) & 0xff);
246 restore_flags(flags
);
249 /* Main probing routine, also sets irq. */
250 static int __init
rc_probe(struct riscom_board
*bp
)
252 unsigned char val1
, val2
;
258 if (rc_request_io_range(bp
))
261 /* Are the I/O ports here ? */
262 rc_out(bp
, CD180_PPRL
, 0x5a);
264 val1
= rc_in(bp
, CD180_PPRL
);
265 rc_out(bp
, CD180_PPRL
, 0xa5);
267 val2
= rc_in(bp
, CD180_PPRL
);
269 if ((val1
!= 0x5a) || (val2
!= 0xa5)) {
270 printk(KERN_ERR
"rc%d: RISCom/8 Board at 0x%03x not found.\n",
271 board_No(bp
), bp
->base
);
275 /* It's time to find IRQ for this board */
276 for (retries
= 0; retries
< 5 && irqs
<= 0; retries
++) {
277 irqs
= probe_irq_on();
278 rc_init_CD180(bp
); /* Reset CD180 chip */
279 rc_out(bp
, CD180_CAR
, 2); /* Select port 2 */
281 rc_out(bp
, CD180_CCR
, CCR_TXEN
); /* Enable transmitter */
282 rc_out(bp
, CD180_IER
, IER_TXRDY
); /* Enable tx empty intr */
283 rc_long_delay(HZ
/20);
284 irqs
= probe_irq_off(irqs
);
285 val1
= rc_in(bp
, RC_BSR
); /* Get Board Status reg */
286 val2
= rc_in(bp
, RC_ACK_TINT
); /* ACK interrupt */
287 rc_init_CD180(bp
); /* Reset CD180 again */
289 if ((val1
& RC_BSR_TINT
) || (val2
!= (RC_ID
| GIVR_IT_TX
))) {
290 printk(KERN_ERR
"rc%d: RISCom/8 Board at 0x%03x not "
291 "found.\n", board_No(bp
), bp
->base
);
297 printk(KERN_ERR
"rc%d: Can't find IRQ for RISCom/8 board "
298 "at 0x%03x.\n", board_No(bp
), bp
->base
);
302 bp
->flags
|= RC_BOARD_PRESENT
;
304 printk(KERN_INFO
"rc%d: RISCom/8 Rev. %c board detected at "
307 (rc_in(bp
, CD180_GFRCR
) & 0x0f) + 'A', /* Board revision */
312 rc_release_io_range(bp
);
318 * Interrupt processing routines.
322 static inline void rc_mark_event(struct riscom_port
* port
, int event
)
324 set_bit(event
, &port
->event
);
325 schedule_work(&port
->tqueue
);
328 static inline struct riscom_port
* rc_get_port(struct riscom_board
const * bp
,
329 unsigned char const * what
)
331 unsigned char channel
;
332 struct riscom_port
* port
;
334 channel
= rc_in(bp
, CD180_GICR
) >> GICR_CHAN_OFF
;
335 if (channel
< CD180_NCH
) {
336 port
= &rc_port
[board_No(bp
) * RC_NPORT
+ channel
];
337 if (port
->flags
& ASYNC_INITIALIZED
) {
341 printk(KERN_ERR
"rc%d: %s interrupt from invalid port %d\n",
342 board_No(bp
), what
, channel
);
346 static inline void rc_receive_exc(struct riscom_board
const * bp
)
348 struct riscom_port
*port
;
349 struct tty_struct
*tty
;
350 unsigned char status
;
351 unsigned char ch
, flag
;
353 if (!(port
= rc_get_port(bp
, "Receive")))
358 #ifdef RC_REPORT_OVERRUN
359 status
= rc_in(bp
, CD180_RCSR
);
360 if (status
& RCSR_OE
)
362 status
&= port
->mark_mask
;
364 status
= rc_in(bp
, CD180_RCSR
) & port
->mark_mask
;
366 ch
= rc_in(bp
, CD180_RDR
);
370 if (status
& RCSR_TOUT
) {
371 printk(KERN_WARNING
"rc%d: port %d: Receiver timeout. "
372 "Hardware problems ?\n",
373 board_No(bp
), port_No(port
));
376 } else if (status
& RCSR_BREAK
) {
377 printk(KERN_INFO
"rc%d: port %d: Handling break...\n",
378 board_No(bp
), port_No(port
));
380 if (port
->flags
& ASYNC_SAK
)
383 } else if (status
& RCSR_PE
)
386 else if (status
& RCSR_FE
)
389 else if (status
& RCSR_OE
)
395 tty_insert_flip_char(tty
, ch
, flag
);
396 tty_flip_buffer_push(tty
);
399 static inline void rc_receive(struct riscom_board
const * bp
)
401 struct riscom_port
*port
;
402 struct tty_struct
*tty
;
405 if (!(port
= rc_get_port(bp
, "Receive")))
410 count
= rc_in(bp
, CD180_RDCR
);
412 #ifdef RC_REPORT_FIFO
413 port
->hits
[count
> 8 ? 9 : count
]++;
417 if (tty_buffer_request_room(tty
, 1) == 0) {
418 printk(KERN_WARNING
"rc%d: port %d: Working around "
419 "flip buffer overflow.\n",
420 board_No(bp
), port_No(port
));
423 tty_insert_flip_char(tty
, rc_in(bp
, CD180_RDR
), TTY_NORMAL
);
425 tty_flip_buffer_push(tty
);
428 static inline void rc_transmit(struct riscom_board
const * bp
)
430 struct riscom_port
*port
;
431 struct tty_struct
*tty
;
435 if (!(port
= rc_get_port(bp
, "Transmit")))
440 if (port
->IER
& IER_TXEMPTY
) {
442 rc_out(bp
, CD180_CAR
, port_No(port
));
443 port
->IER
&= ~IER_TXEMPTY
;
444 rc_out(bp
, CD180_IER
, port
->IER
);
448 if ((port
->xmit_cnt
<= 0 && !port
->break_length
)
449 || tty
->stopped
|| tty
->hw_stopped
) {
450 rc_out(bp
, CD180_CAR
, port_No(port
));
451 port
->IER
&= ~IER_TXRDY
;
452 rc_out(bp
, CD180_IER
, port
->IER
);
456 if (port
->break_length
) {
457 if (port
->break_length
> 0) {
458 if (port
->COR2
& COR2_ETC
) {
459 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
460 rc_out(bp
, CD180_TDR
, CD180_C_SBRK
);
461 port
->COR2
&= ~COR2_ETC
;
463 count
= min_t(int, port
->break_length
, 0xff);
464 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
465 rc_out(bp
, CD180_TDR
, CD180_C_DELAY
);
466 rc_out(bp
, CD180_TDR
, count
);
467 if (!(port
->break_length
-= count
))
468 port
->break_length
--;
470 rc_out(bp
, CD180_TDR
, CD180_C_ESC
);
471 rc_out(bp
, CD180_TDR
, CD180_C_EBRK
);
472 rc_out(bp
, CD180_COR2
, port
->COR2
);
474 rc_out(bp
, CD180_CCR
, CCR_CORCHG2
);
475 port
->break_length
= 0;
482 rc_out(bp
, CD180_TDR
, port
->xmit_buf
[port
->xmit_tail
++]);
483 port
->xmit_tail
= port
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
484 if (--port
->xmit_cnt
<= 0)
486 } while (--count
> 0);
488 if (port
->xmit_cnt
<= 0) {
489 rc_out(bp
, CD180_CAR
, port_No(port
));
490 port
->IER
&= ~IER_TXRDY
;
491 rc_out(bp
, CD180_IER
, port
->IER
);
493 if (port
->xmit_cnt
<= port
->wakeup_chars
)
494 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
497 static inline void rc_check_modem(struct riscom_board
const * bp
)
499 struct riscom_port
*port
;
500 struct tty_struct
*tty
;
503 if (!(port
= rc_get_port(bp
, "Modem")))
508 mcr
= rc_in(bp
, CD180_MCR
);
509 if (mcr
& MCR_CDCHG
) {
510 if (rc_in(bp
, CD180_MSVR
) & MSVR_CD
)
511 wake_up_interruptible(&port
->open_wait
);
513 schedule_work(&port
->tqueue_hangup
);
516 #ifdef RISCOM_BRAIN_DAMAGED_CTS
517 if (mcr
& MCR_CTSCHG
) {
518 if (rc_in(bp
, CD180_MSVR
) & MSVR_CTS
) {
520 port
->IER
|= IER_TXRDY
;
521 if (port
->xmit_cnt
<= port
->wakeup_chars
)
522 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
525 port
->IER
&= ~IER_TXRDY
;
527 rc_out(bp
, CD180_IER
, port
->IER
);
529 if (mcr
& MCR_DSRCHG
) {
530 if (rc_in(bp
, CD180_MSVR
) & MSVR_DSR
) {
532 port
->IER
|= IER_TXRDY
;
533 if (port
->xmit_cnt
<= port
->wakeup_chars
)
534 rc_mark_event(port
, RS_EVENT_WRITE_WAKEUP
);
537 port
->IER
&= ~IER_TXRDY
;
539 rc_out(bp
, CD180_IER
, port
->IER
);
541 #endif /* RISCOM_BRAIN_DAMAGED_CTS */
543 /* Clear change bits */
544 rc_out(bp
, CD180_MCR
, 0);
547 /* The main interrupt processing routine */
548 static irqreturn_t
rc_interrupt(int irq
, void * dev_id
)
550 unsigned char status
;
552 struct riscom_board
*bp
;
553 unsigned long loop
= 0;
556 bp
= IRQ_to_board
[irq
];
558 if (!(bp
->flags
& RC_BOARD_ACTIVE
))
561 while ((++loop
< 16) && ((status
= ~(rc_in(bp
, RC_BSR
))) &
562 (RC_BSR_TOUT
| RC_BSR_TINT
|
563 RC_BSR_MINT
| RC_BSR_RINT
))) {
565 if (status
& RC_BSR_TOUT
)
566 printk(KERN_WARNING
"rc%d: Got timeout. Hardware "
567 "error?\n", board_No(bp
));
569 else if (status
& RC_BSR_RINT
) {
570 ack
= rc_in(bp
, RC_ACK_RINT
);
572 if (ack
== (RC_ID
| GIVR_IT_RCV
))
574 else if (ack
== (RC_ID
| GIVR_IT_REXC
))
577 printk(KERN_WARNING
"rc%d: Bad receive ack "
581 } else if (status
& RC_BSR_TINT
) {
582 ack
= rc_in(bp
, RC_ACK_TINT
);
584 if (ack
== (RC_ID
| GIVR_IT_TX
))
587 printk(KERN_WARNING
"rc%d: Bad transmit ack "
591 } else /* if (status & RC_BSR_MINT) */ {
592 ack
= rc_in(bp
, RC_ACK_MINT
);
594 if (ack
== (RC_ID
| GIVR_IT_MODEM
))
597 printk(KERN_WARNING
"rc%d: Bad modem ack "
603 rc_out(bp
, CD180_EOIR
, 0); /* Mark end of interrupt */
604 rc_out(bp
, RC_CTOUT
, 0); /* Clear timeout flag */
606 return IRQ_RETVAL(handled
);
610 * Routines for open & close processing.
613 /* Called with disabled interrupts */
614 static inline int rc_setup_board(struct riscom_board
* bp
)
618 if (bp
->flags
& RC_BOARD_ACTIVE
)
621 error
= request_irq(bp
->irq
, rc_interrupt
, IRQF_DISABLED
,
626 rc_out(bp
, RC_CTOUT
, 0); /* Just in case */
628 rc_out(bp
, RC_DTR
, bp
->DTR
); /* Drop DTR on all ports */
630 IRQ_to_board
[bp
->irq
] = bp
;
631 bp
->flags
|= RC_BOARD_ACTIVE
;
636 /* Called with disabled interrupts */
637 static inline void rc_shutdown_board(struct riscom_board
*bp
)
639 if (!(bp
->flags
& RC_BOARD_ACTIVE
))
642 bp
->flags
&= ~RC_BOARD_ACTIVE
;
644 free_irq(bp
->irq
, NULL
);
645 IRQ_to_board
[bp
->irq
] = NULL
;
648 rc_out(bp
, RC_DTR
, bp
->DTR
); /* Drop DTR on all ports */
653 * Setting up port characteristics.
654 * Must be called with disabled interrupts
656 static void rc_change_speed(struct riscom_board
*bp
, struct riscom_port
*port
)
658 struct tty_struct
*tty
;
661 unsigned char cor1
= 0, cor3
= 0;
662 unsigned char mcor1
= 0, mcor2
= 0;
664 if (!(tty
= port
->tty
) || !tty
->termios
)
669 port
->MSVR
= MSVR_RTS
;
671 baud
= tty_get_baud_rate(tty
);
673 /* Select port on the board */
674 rc_out(bp
, CD180_CAR
, port_No(port
));
677 /* Drop DTR & exit */
678 bp
->DTR
|= (1u << port_No(port
));
679 rc_out(bp
, RC_DTR
, bp
->DTR
);
683 bp
->DTR
&= ~(1u << port_No(port
));
684 rc_out(bp
, RC_DTR
, bp
->DTR
);
688 * Now we must calculate some speed depended things
691 /* Set baud rate for port */
692 tmp
= (((RC_OSCFREQ
+ baud
/2) / baud
+
693 CD180_TPC
/2) / CD180_TPC
);
695 rc_out(bp
, CD180_RBPRH
, (tmp
>> 8) & 0xff);
696 rc_out(bp
, CD180_TBPRH
, (tmp
>> 8) & 0xff);
697 rc_out(bp
, CD180_RBPRL
, tmp
& 0xff);
698 rc_out(bp
, CD180_TBPRL
, tmp
& 0xff);
700 baud
= (baud
+ 5) / 10; /* Estimated CPS */
702 /* Two timer ticks seems enough to wakeup something like SLIP driver */
703 tmp
= ((baud
+ HZ
/2) / HZ
) * 2 - CD180_NFIFO
;
704 port
->wakeup_chars
= (tmp
< 0) ? 0 : ((tmp
>= SERIAL_XMIT_SIZE
) ?
705 SERIAL_XMIT_SIZE
- 1 : tmp
);
707 /* Receiver timeout will be transmission time for 1.5 chars */
708 tmp
= (RISCOM_TPS
+ RISCOM_TPS
/2 + baud
/2) / baud
;
709 tmp
= (tmp
> 0xff) ? 0xff : tmp
;
710 rc_out(bp
, CD180_RTPR
, tmp
);
712 switch (C_CSIZE(tty
)) {
732 cor1
|= COR1_NORMPAR
;
736 cor1
&= ~COR1_IGNORE
;
738 /* Set marking of some errors */
739 port
->mark_mask
= RCSR_OE
| RCSR_TOUT
;
741 port
->mark_mask
|= RCSR_FE
| RCSR_PE
;
742 if (I_BRKINT(tty
) || I_PARMRK(tty
))
743 port
->mark_mask
|= RCSR_BREAK
;
745 port
->mark_mask
&= ~(RCSR_FE
| RCSR_PE
);
747 port
->mark_mask
&= ~RCSR_BREAK
;
749 /* Real raw mode. Ignore all */
750 port
->mark_mask
&= ~RCSR_OE
;
752 /* Enable Hardware Flow Control */
753 if (C_CRTSCTS(tty
)) {
754 #ifdef RISCOM_BRAIN_DAMAGED_CTS
755 port
->IER
|= IER_DSR
| IER_CTS
;
756 mcor1
|= MCOR1_DSRZD
| MCOR1_CTSZD
;
757 mcor2
|= MCOR2_DSROD
| MCOR2_CTSOD
;
758 tty
->hw_stopped
= !(rc_in(bp
, CD180_MSVR
) & (MSVR_CTS
|MSVR_DSR
));
760 port
->COR2
|= COR2_CTSAE
;
763 /* Enable Software Flow Control. FIXME: I'm not sure about this */
764 /* Some people reported that it works, but I still doubt */
766 port
->COR2
|= COR2_TXIBE
;
767 cor3
|= (COR3_FCT
| COR3_SCDE
);
769 port
->COR2
|= COR2_IXM
;
770 rc_out(bp
, CD180_SCHR1
, START_CHAR(tty
));
771 rc_out(bp
, CD180_SCHR2
, STOP_CHAR(tty
));
772 rc_out(bp
, CD180_SCHR3
, START_CHAR(tty
));
773 rc_out(bp
, CD180_SCHR4
, STOP_CHAR(tty
));
775 if (!C_CLOCAL(tty
)) {
776 /* Enable CD check */
783 /* Enable receiver */
784 port
->IER
|= IER_RXD
;
786 /* Set input FIFO size (1-8 bytes) */
787 cor3
|= RISCOM_RXFIFO
;
788 /* Setting up CD180 channel registers */
789 rc_out(bp
, CD180_COR1
, cor1
);
790 rc_out(bp
, CD180_COR2
, port
->COR2
);
791 rc_out(bp
, CD180_COR3
, cor3
);
792 /* Make CD180 know about registers change */
794 rc_out(bp
, CD180_CCR
, CCR_CORCHG1
| CCR_CORCHG2
| CCR_CORCHG3
);
795 /* Setting up modem option registers */
796 rc_out(bp
, CD180_MCOR1
, mcor1
);
797 rc_out(bp
, CD180_MCOR2
, mcor2
);
798 /* Enable CD180 transmitter & receiver */
800 rc_out(bp
, CD180_CCR
, CCR_TXEN
| CCR_RXEN
);
801 /* Enable interrupts */
802 rc_out(bp
, CD180_IER
, port
->IER
);
803 /* And finally set RTS on */
804 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
807 /* Must be called with interrupts enabled */
808 static int rc_setup_port(struct riscom_board
*bp
, struct riscom_port
*port
)
812 if (port
->flags
& ASYNC_INITIALIZED
)
815 if (!port
->xmit_buf
) {
816 /* We may sleep in get_zeroed_page() */
819 if (!(tmp
= get_zeroed_page(GFP_KERNEL
)))
822 if (port
->xmit_buf
) {
826 port
->xmit_buf
= (unsigned char *) tmp
;
829 save_flags(flags
); cli();
832 clear_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
834 if (port
->count
== 1)
837 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
838 rc_change_speed(bp
, port
);
839 port
->flags
|= ASYNC_INITIALIZED
;
841 restore_flags(flags
);
845 /* Must be called with interrupts disabled */
846 static void rc_shutdown_port(struct riscom_board
*bp
, struct riscom_port
*port
)
848 struct tty_struct
*tty
;
850 if (!(port
->flags
& ASYNC_INITIALIZED
))
853 #ifdef RC_REPORT_OVERRUN
854 printk(KERN_INFO
"rc%d: port %d: Total %ld overruns were detected.\n",
855 board_No(bp
), port_No(port
), port
->overrun
);
857 #ifdef RC_REPORT_FIFO
861 printk(KERN_INFO
"rc%d: port %d: FIFO hits [ ",
862 board_No(bp
), port_No(port
));
863 for (i
= 0; i
< 10; i
++) {
864 printk("%ld ", port
->hits
[i
]);
869 if (port
->xmit_buf
) {
870 free_page((unsigned long) port
->xmit_buf
);
871 port
->xmit_buf
= NULL
;
874 if (!(tty
= port
->tty
) || C_HUPCL(tty
)) {
876 bp
->DTR
|= (1u << port_No(port
));
877 rc_out(bp
, RC_DTR
, bp
->DTR
);
881 rc_out(bp
, CD180_CAR
, port_No(port
));
884 rc_out(bp
, CD180_CCR
, CCR_SOFTRESET
);
885 /* Disable all interrupts from this port */
887 rc_out(bp
, CD180_IER
, port
->IER
);
890 set_bit(TTY_IO_ERROR
, &tty
->flags
);
891 port
->flags
&= ~ASYNC_INITIALIZED
;
893 if (--bp
->count
< 0) {
894 printk(KERN_INFO
"rc%d: rc_shutdown_port: "
895 "bad board count: %d\n",
896 board_No(bp
), bp
->count
);
901 * If this is the last opened port on the board
902 * shutdown whole board
905 rc_shutdown_board(bp
);
909 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
910 struct riscom_port
*port
)
912 DECLARE_WAITQUEUE(wait
, current
);
913 struct riscom_board
*bp
= port_Board(port
);
919 * If the device is in the middle of being closed, then block
920 * until it's done, and then try again.
922 if (tty_hung_up_p(filp
) || port
->flags
& ASYNC_CLOSING
) {
923 interruptible_sleep_on(&port
->close_wait
);
924 if (port
->flags
& ASYNC_HUP_NOTIFY
)
931 * If non-blocking mode is set, or the port is not enabled,
932 * then make the check up front and then exit.
934 if ((filp
->f_flags
& O_NONBLOCK
) ||
935 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
936 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
944 * Block waiting for the carrier detect and the line to become
945 * free (i.e., not in use by the callout). While we are in
946 * this loop, info->count is dropped by one, so that
947 * rs_close() knows when to free things. We restore it upon
948 * exit, either normal or abnormal.
951 add_wait_queue(&port
->open_wait
, &wait
);
953 if (!tty_hung_up_p(filp
))
956 port
->blocked_open
++;
959 rc_out(bp
, CD180_CAR
, port_No(port
));
960 CD
= rc_in(bp
, CD180_MSVR
) & MSVR_CD
;
961 rc_out(bp
, CD180_MSVR
, MSVR_RTS
);
962 bp
->DTR
&= ~(1u << port_No(port
));
963 rc_out(bp
, RC_DTR
, bp
->DTR
);
965 set_current_state(TASK_INTERRUPTIBLE
);
966 if (tty_hung_up_p(filp
) ||
967 !(port
->flags
& ASYNC_INITIALIZED
)) {
968 if (port
->flags
& ASYNC_HUP_NOTIFY
)
971 retval
= -ERESTARTSYS
;
974 if (!(port
->flags
& ASYNC_CLOSING
) &&
977 if (signal_pending(current
)) {
978 retval
= -ERESTARTSYS
;
983 __set_current_state(TASK_RUNNING
);
984 remove_wait_queue(&port
->open_wait
, &wait
);
985 if (!tty_hung_up_p(filp
))
987 port
->blocked_open
--;
991 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
995 static int rc_open(struct tty_struct
* tty
, struct file
* filp
)
999 struct riscom_port
* port
;
1000 struct riscom_board
* bp
;
1002 board
= RC_BOARD(tty
->index
);
1003 if (board
>= RC_NBOARD
|| !(rc_board
[board
].flags
& RC_BOARD_PRESENT
))
1006 bp
= &rc_board
[board
];
1007 port
= rc_port
+ board
* RC_NPORT
+ RC_PORT(tty
->index
);
1008 if (rc_paranoia_check(port
, tty
->name
, "rc_open"))
1011 if ((error
= rc_setup_board(bp
)))
1015 tty
->driver_data
= port
;
1018 if ((error
= rc_setup_port(bp
, port
)))
1021 if ((error
= block_til_ready(tty
, filp
, port
)))
1027 static void rc_close(struct tty_struct
* tty
, struct file
* filp
)
1029 struct riscom_port
*port
= (struct riscom_port
*) tty
->driver_data
;
1030 struct riscom_board
*bp
;
1031 unsigned long flags
;
1032 unsigned long timeout
;
1034 if (!port
|| rc_paranoia_check(port
, tty
->name
, "close"))
1037 save_flags(flags
); cli();
1038 if (tty_hung_up_p(filp
))
1041 bp
= port_Board(port
);
1042 if ((tty
->count
== 1) && (port
->count
!= 1)) {
1043 printk(KERN_INFO
"rc%d: rc_close: bad port count;"
1044 " tty->count is 1, port count is %d\n",
1045 board_No(bp
), port
->count
);
1048 if (--port
->count
< 0) {
1049 printk(KERN_INFO
"rc%d: rc_close: bad port count "
1051 board_No(bp
), port_No(port
), port
->count
);
1056 port
->flags
|= ASYNC_CLOSING
;
1058 * Now we wait for the transmit buffer to clear; and we notify
1059 * the line discipline to only process XON/XOFF characters.
1062 if (port
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1063 tty_wait_until_sent(tty
, port
->closing_wait
);
1065 * At this point we stop accepting input. To do this, we
1066 * disable the receive line status interrupts, and tell the
1067 * interrupt driver to stop checking the data ready bit in the
1068 * line status register.
1070 port
->IER
&= ~IER_RXD
;
1071 if (port
->flags
& ASYNC_INITIALIZED
) {
1072 port
->IER
&= ~IER_TXRDY
;
1073 port
->IER
|= IER_TXEMPTY
;
1074 rc_out(bp
, CD180_CAR
, port_No(port
));
1075 rc_out(bp
, CD180_IER
, port
->IER
);
1077 * Before we drop DTR, make sure the UART transmitter
1078 * has completely drained; this is especially
1079 * important if there is a transmit FIFO!
1081 timeout
= jiffies
+HZ
;
1082 while(port
->IER
& IER_TXEMPTY
) {
1083 msleep_interruptible(jiffies_to_msecs(port
->timeout
));
1084 if (time_after(jiffies
, timeout
))
1088 rc_shutdown_port(bp
, port
);
1089 if (tty
->driver
->flush_buffer
)
1090 tty
->driver
->flush_buffer(tty
);
1091 tty_ldisc_flush(tty
);
1096 if (port
->blocked_open
) {
1097 if (port
->close_delay
) {
1098 msleep_interruptible(jiffies_to_msecs(port
->close_delay
));
1100 wake_up_interruptible(&port
->open_wait
);
1102 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1103 wake_up_interruptible(&port
->close_wait
);
1104 out
: restore_flags(flags
);
1107 static int rc_write(struct tty_struct
* tty
,
1108 const unsigned char *buf
, int count
)
1110 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1111 struct riscom_board
*bp
;
1113 unsigned long flags
;
1115 if (rc_paranoia_check(port
, tty
->name
, "rc_write"))
1118 bp
= port_Board(port
);
1120 if (!tty
|| !port
->xmit_buf
)
1126 c
= min_t(int, count
, min(SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1,
1127 SERIAL_XMIT_SIZE
- port
->xmit_head
));
1129 restore_flags(flags
);
1133 memcpy(port
->xmit_buf
+ port
->xmit_head
, buf
, c
);
1134 port
->xmit_head
= (port
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
1135 port
->xmit_cnt
+= c
;
1136 restore_flags(flags
);
1144 if (port
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
&&
1145 !(port
->IER
& IER_TXRDY
)) {
1146 port
->IER
|= IER_TXRDY
;
1147 rc_out(bp
, CD180_CAR
, port_No(port
));
1148 rc_out(bp
, CD180_IER
, port
->IER
);
1150 restore_flags(flags
);
1155 static void rc_put_char(struct tty_struct
* tty
, unsigned char ch
)
1157 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1158 unsigned long flags
;
1160 if (rc_paranoia_check(port
, tty
->name
, "rc_put_char"))
1163 if (!tty
|| !port
->xmit_buf
)
1166 save_flags(flags
); cli();
1168 if (port
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1)
1171 port
->xmit_buf
[port
->xmit_head
++] = ch
;
1172 port
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
1174 out
: restore_flags(flags
);
1177 static void rc_flush_chars(struct tty_struct
* tty
)
1179 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1180 unsigned long flags
;
1182 if (rc_paranoia_check(port
, tty
->name
, "rc_flush_chars"))
1185 if (port
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
1189 save_flags(flags
); cli();
1190 port
->IER
|= IER_TXRDY
;
1191 rc_out(port_Board(port
), CD180_CAR
, port_No(port
));
1192 rc_out(port_Board(port
), CD180_IER
, port
->IER
);
1193 restore_flags(flags
);
1196 static int rc_write_room(struct tty_struct
* tty
)
1198 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1201 if (rc_paranoia_check(port
, tty
->name
, "rc_write_room"))
1204 ret
= SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1;
1210 static int rc_chars_in_buffer(struct tty_struct
*tty
)
1212 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1214 if (rc_paranoia_check(port
, tty
->name
, "rc_chars_in_buffer"))
1217 return port
->xmit_cnt
;
1220 static void rc_flush_buffer(struct tty_struct
*tty
)
1222 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1223 unsigned long flags
;
1225 if (rc_paranoia_check(port
, tty
->name
, "rc_flush_buffer"))
1228 save_flags(flags
); cli();
1229 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
1230 restore_flags(flags
);
1235 static int rc_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1237 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1238 struct riscom_board
* bp
;
1239 unsigned char status
;
1240 unsigned int result
;
1241 unsigned long flags
;
1243 if (rc_paranoia_check(port
, tty
->name
, __FUNCTION__
))
1246 bp
= port_Board(port
);
1247 save_flags(flags
); cli();
1248 rc_out(bp
, CD180_CAR
, port_No(port
));
1249 status
= rc_in(bp
, CD180_MSVR
);
1250 result
= rc_in(bp
, RC_RI
) & (1u << port_No(port
)) ? 0 : TIOCM_RNG
;
1251 restore_flags(flags
);
1252 result
|= ((status
& MSVR_RTS
) ? TIOCM_RTS
: 0)
1253 | ((status
& MSVR_DTR
) ? TIOCM_DTR
: 0)
1254 | ((status
& MSVR_CD
) ? TIOCM_CAR
: 0)
1255 | ((status
& MSVR_DSR
) ? TIOCM_DSR
: 0)
1256 | ((status
& MSVR_CTS
) ? TIOCM_CTS
: 0);
1260 static int rc_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1261 unsigned int set
, unsigned int clear
)
1263 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1264 unsigned long flags
;
1265 struct riscom_board
*bp
;
1267 if (rc_paranoia_check(port
, tty
->name
, __FUNCTION__
))
1270 bp
= port_Board(port
);
1272 save_flags(flags
); cli();
1273 if (set
& TIOCM_RTS
)
1274 port
->MSVR
|= MSVR_RTS
;
1275 if (set
& TIOCM_DTR
)
1276 bp
->DTR
&= ~(1u << port_No(port
));
1278 if (clear
& TIOCM_RTS
)
1279 port
->MSVR
&= ~MSVR_RTS
;
1280 if (clear
& TIOCM_DTR
)
1281 bp
->DTR
|= (1u << port_No(port
));
1283 rc_out(bp
, CD180_CAR
, port_No(port
));
1284 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1285 rc_out(bp
, RC_DTR
, bp
->DTR
);
1286 restore_flags(flags
);
1290 static inline void rc_send_break(struct riscom_port
* port
, unsigned long length
)
1292 struct riscom_board
*bp
= port_Board(port
);
1293 unsigned long flags
;
1295 save_flags(flags
); cli();
1296 port
->break_length
= RISCOM_TPS
/ HZ
* length
;
1297 port
->COR2
|= COR2_ETC
;
1298 port
->IER
|= IER_TXRDY
;
1299 rc_out(bp
, CD180_CAR
, port_No(port
));
1300 rc_out(bp
, CD180_COR2
, port
->COR2
);
1301 rc_out(bp
, CD180_IER
, port
->IER
);
1303 rc_out(bp
, CD180_CCR
, CCR_CORCHG2
);
1305 restore_flags(flags
);
1308 static inline int rc_set_serial_info(struct riscom_port
* port
,
1309 struct serial_struct __user
* newinfo
)
1311 struct serial_struct tmp
;
1312 struct riscom_board
*bp
= port_Board(port
);
1314 unsigned long flags
;
1316 if (copy_from_user(&tmp
, newinfo
, sizeof(tmp
)))
1320 if ((tmp
.irq
!= bp
->irq
) ||
1321 (tmp
.port
!= bp
->base
) ||
1322 (tmp
.type
!= PORT_CIRRUS
) ||
1323 (tmp
.baud_base
!= (RC_OSCFREQ
+ CD180_TPC
/2) / CD180_TPC
) ||
1324 (tmp
.custom_divisor
!= 0) ||
1325 (tmp
.xmit_fifo_size
!= CD180_NFIFO
) ||
1326 (tmp
.flags
& ~RISCOM_LEGAL_FLAGS
))
1330 change_speed
= ((port
->flags
& ASYNC_SPD_MASK
) !=
1331 (tmp
.flags
& ASYNC_SPD_MASK
));
1333 if (!capable(CAP_SYS_ADMIN
)) {
1334 if ((tmp
.close_delay
!= port
->close_delay
) ||
1335 (tmp
.closing_wait
!= port
->closing_wait
) ||
1336 ((tmp
.flags
& ~ASYNC_USR_MASK
) !=
1337 (port
->flags
& ~ASYNC_USR_MASK
)))
1339 port
->flags
= ((port
->flags
& ~ASYNC_USR_MASK
) |
1340 (tmp
.flags
& ASYNC_USR_MASK
));
1342 port
->flags
= ((port
->flags
& ~ASYNC_FLAGS
) |
1343 (tmp
.flags
& ASYNC_FLAGS
));
1344 port
->close_delay
= tmp
.close_delay
;
1345 port
->closing_wait
= tmp
.closing_wait
;
1348 save_flags(flags
); cli();
1349 rc_change_speed(bp
, port
);
1350 restore_flags(flags
);
1355 static inline int rc_get_serial_info(struct riscom_port
* port
,
1356 struct serial_struct __user
*retinfo
)
1358 struct serial_struct tmp
;
1359 struct riscom_board
*bp
= port_Board(port
);
1361 memset(&tmp
, 0, sizeof(tmp
));
1362 tmp
.type
= PORT_CIRRUS
;
1363 tmp
.line
= port
- rc_port
;
1364 tmp
.port
= bp
->base
;
1366 tmp
.flags
= port
->flags
;
1367 tmp
.baud_base
= (RC_OSCFREQ
+ CD180_TPC
/2) / CD180_TPC
;
1368 tmp
.close_delay
= port
->close_delay
* HZ
/100;
1369 tmp
.closing_wait
= port
->closing_wait
* HZ
/100;
1370 tmp
.xmit_fifo_size
= CD180_NFIFO
;
1371 return copy_to_user(retinfo
, &tmp
, sizeof(tmp
)) ? -EFAULT
: 0;
1374 static int rc_ioctl(struct tty_struct
* tty
, struct file
* filp
,
1375 unsigned int cmd
, unsigned long arg
)
1378 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1379 void __user
*argp
= (void __user
*)arg
;
1382 if (rc_paranoia_check(port
, tty
->name
, "rc_ioctl"))
1386 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1387 retval
= tty_check_change(tty
);
1390 tty_wait_until_sent(tty
, 0);
1392 rc_send_break(port
, HZ
/4); /* 1/4 second */
1394 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1395 retval
= tty_check_change(tty
);
1398 tty_wait_until_sent(tty
, 0);
1399 rc_send_break(port
, arg
? arg
*(HZ
/10) : HZ
/4);
1402 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned __user
*)argp
);
1404 if (get_user(arg
,(unsigned __user
*) argp
))
1406 tty
->termios
->c_cflag
=
1407 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1408 (arg
? CLOCAL
: 0));
1411 return rc_get_serial_info(port
, argp
);
1413 return rc_set_serial_info(port
, argp
);
1415 return -ENOIOCTLCMD
;
1420 static void rc_throttle(struct tty_struct
* tty
)
1422 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1423 struct riscom_board
*bp
;
1424 unsigned long flags
;
1426 if (rc_paranoia_check(port
, tty
->name
, "rc_throttle"))
1429 bp
= port_Board(port
);
1431 save_flags(flags
); cli();
1432 port
->MSVR
&= ~MSVR_RTS
;
1433 rc_out(bp
, CD180_CAR
, port_No(port
));
1436 rc_out(bp
, CD180_CCR
, CCR_SSCH2
);
1439 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1440 restore_flags(flags
);
1443 static void rc_unthrottle(struct tty_struct
* tty
)
1445 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1446 struct riscom_board
*bp
;
1447 unsigned long flags
;
1449 if (rc_paranoia_check(port
, tty
->name
, "rc_unthrottle"))
1452 bp
= port_Board(port
);
1454 save_flags(flags
); cli();
1455 port
->MSVR
|= MSVR_RTS
;
1456 rc_out(bp
, CD180_CAR
, port_No(port
));
1459 rc_out(bp
, CD180_CCR
, CCR_SSCH1
);
1462 rc_out(bp
, CD180_MSVR
, port
->MSVR
);
1463 restore_flags(flags
);
1466 static void rc_stop(struct tty_struct
* tty
)
1468 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1469 struct riscom_board
*bp
;
1470 unsigned long flags
;
1472 if (rc_paranoia_check(port
, tty
->name
, "rc_stop"))
1475 bp
= port_Board(port
);
1477 save_flags(flags
); cli();
1478 port
->IER
&= ~IER_TXRDY
;
1479 rc_out(bp
, CD180_CAR
, port_No(port
));
1480 rc_out(bp
, CD180_IER
, port
->IER
);
1481 restore_flags(flags
);
1484 static void rc_start(struct tty_struct
* tty
)
1486 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1487 struct riscom_board
*bp
;
1488 unsigned long flags
;
1490 if (rc_paranoia_check(port
, tty
->name
, "rc_start"))
1493 bp
= port_Board(port
);
1495 save_flags(flags
); cli();
1496 if (port
->xmit_cnt
&& port
->xmit_buf
&& !(port
->IER
& IER_TXRDY
)) {
1497 port
->IER
|= IER_TXRDY
;
1498 rc_out(bp
, CD180_CAR
, port_No(port
));
1499 rc_out(bp
, CD180_IER
, port
->IER
);
1501 restore_flags(flags
);
1505 * This routine is called from the work queue when the interrupt
1506 * routine has signalled that a hangup has occurred. The path of
1507 * hangup processing is:
1509 * serial interrupt routine -> (workqueue) ->
1510 * do_rc_hangup() -> tty->hangup() -> rc_hangup()
1513 static void do_rc_hangup(struct work_struct
*ugly_api
)
1515 struct riscom_port
*port
= container_of(ugly_api
, struct riscom_port
, tqueue_hangup
);
1516 struct tty_struct
*tty
;
1520 tty_hangup(tty
); /* FIXME: module removal race still here */
1523 static void rc_hangup(struct tty_struct
* tty
)
1525 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1526 struct riscom_board
*bp
;
1528 if (rc_paranoia_check(port
, tty
->name
, "rc_hangup"))
1531 bp
= port_Board(port
);
1533 rc_shutdown_port(bp
, port
);
1536 port
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1538 wake_up_interruptible(&port
->open_wait
);
1541 static void rc_set_termios(struct tty_struct
* tty
, struct ktermios
* old_termios
)
1543 struct riscom_port
*port
= (struct riscom_port
*)tty
->driver_data
;
1544 unsigned long flags
;
1546 if (rc_paranoia_check(port
, tty
->name
, "rc_set_termios"))
1549 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
&&
1550 tty
->termios
->c_iflag
== old_termios
->c_iflag
)
1553 save_flags(flags
); cli();
1554 rc_change_speed(port_Board(port
), port
);
1555 restore_flags(flags
);
1557 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1558 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1559 tty
->hw_stopped
= 0;
1564 static void do_softint(struct work_struct
*ugly_api
)
1566 struct riscom_port
*port
= container_of(ugly_api
, struct riscom_port
, tqueue
);
1567 struct tty_struct
*tty
;
1569 if(!(tty
= port
->tty
))
1572 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &port
->event
))
1576 static const struct tty_operations riscom_ops
= {
1580 .put_char
= rc_put_char
,
1581 .flush_chars
= rc_flush_chars
,
1582 .write_room
= rc_write_room
,
1583 .chars_in_buffer
= rc_chars_in_buffer
,
1584 .flush_buffer
= rc_flush_buffer
,
1586 .throttle
= rc_throttle
,
1587 .unthrottle
= rc_unthrottle
,
1588 .set_termios
= rc_set_termios
,
1591 .hangup
= rc_hangup
,
1592 .tiocmget
= rc_tiocmget
,
1593 .tiocmset
= rc_tiocmset
,
1596 static inline int rc_init_drivers(void)
1601 riscom_driver
= alloc_tty_driver(RC_NBOARD
* RC_NPORT
);
1605 memset(IRQ_to_board
, 0, sizeof(IRQ_to_board
));
1606 riscom_driver
->owner
= THIS_MODULE
;
1607 riscom_driver
->name
= "ttyL";
1608 riscom_driver
->major
= RISCOM8_NORMAL_MAJOR
;
1609 riscom_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1610 riscom_driver
->subtype
= SERIAL_TYPE_NORMAL
;
1611 riscom_driver
->init_termios
= tty_std_termios
;
1612 riscom_driver
->init_termios
.c_cflag
=
1613 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1614 riscom_driver
->init_termios
.c_ispeed
= 9600;
1615 riscom_driver
->init_termios
.c_ospeed
= 9600;
1616 riscom_driver
->flags
= TTY_DRIVER_REAL_RAW
;
1617 tty_set_operations(riscom_driver
, &riscom_ops
);
1618 if ((error
= tty_register_driver(riscom_driver
))) {
1619 put_tty_driver(riscom_driver
);
1620 printk(KERN_ERR
"rc: Couldn't register RISCom/8 driver, "
1626 memset(rc_port
, 0, sizeof(rc_port
));
1627 for (i
= 0; i
< RC_NPORT
* RC_NBOARD
; i
++) {
1628 rc_port
[i
].magic
= RISCOM8_MAGIC
;
1629 INIT_WORK(&rc_port
[i
].tqueue
, do_softint
);
1630 INIT_WORK(&rc_port
[i
].tqueue_hangup
, do_rc_hangup
);
1631 rc_port
[i
].close_delay
= 50 * HZ
/100;
1632 rc_port
[i
].closing_wait
= 3000 * HZ
/100;
1633 init_waitqueue_head(&rc_port
[i
].open_wait
);
1634 init_waitqueue_head(&rc_port
[i
].close_wait
);
1640 static void rc_release_drivers(void)
1642 unsigned long flags
;
1646 tty_unregister_driver(riscom_driver
);
1647 put_tty_driver(riscom_driver
);
1648 restore_flags(flags
);
1653 * Called at boot time.
1655 * You can specify IO base for up to RC_NBOARD cards,
1656 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
1657 * Note that there will be no probing at default
1658 * addresses in this case.
1661 static int __init
riscom8_setup(char *str
)
1663 int ints
[RC_NBOARD
];
1666 str
= get_options(str
, ARRAY_SIZE(ints
), ints
);
1668 for (i
= 0; i
< RC_NBOARD
; i
++) {
1670 rc_board
[i
].base
= ints
[i
+1];
1672 rc_board
[i
].base
= 0;
1677 __setup("riscom8=", riscom8_setup
);
1680 static char banner
[] __initdata
=
1681 KERN_INFO
"rc: SDL RISCom/8 card driver v1.1, (c) D.Gorodchanin "
1683 static char no_boards_msg
[] __initdata
=
1684 KERN_INFO
"rc: No RISCom/8 boards detected.\n";
1687 * This routine must be called by kernel at boot time
1689 static int __init
riscom8_init(void)
1696 if (rc_init_drivers())
1699 for (i
= 0; i
< RC_NBOARD
; i
++)
1700 if (rc_board
[i
].base
&& !rc_probe(&rc_board
[i
]))
1704 rc_release_drivers();
1705 printk(no_boards_msg
);
1716 module_param(iobase
, int, 0);
1717 module_param(iobase1
, int, 0);
1718 module_param(iobase2
, int, 0);
1719 module_param(iobase3
, int, 0);
1721 MODULE_LICENSE("GPL");
1725 * You can setup up to 4 boards (current value of RC_NBOARD)
1726 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter.
1729 static int __init
riscom8_init_module (void)
1734 if (iobase
|| iobase1
|| iobase2
|| iobase3
) {
1735 for(i
= 0; i
< RC_NBOARD
; i
++)
1736 rc_board
[0].base
= 0;
1740 rc_board
[0].base
= iobase
;
1742 rc_board
[1].base
= iobase1
;
1744 rc_board
[2].base
= iobase2
;
1746 rc_board
[3].base
= iobase3
;
1749 return riscom8_init();
1752 static void __exit
riscom8_exit_module (void)
1756 rc_release_drivers();
1757 for (i
= 0; i
< RC_NBOARD
; i
++)
1758 if (rc_board
[i
].flags
& RC_BOARD_PRESENT
)
1759 rc_release_io_range(&rc_board
[i
]);
1763 module_init(riscom8_init_module
);
1764 module_exit(riscom8_exit_module
);