2 * specialix.c -- specialix IO8+ multiport serial driver.
4 * Copyright (C) 1997 Roger Wolff (R.E.Wolff@BitWizard.nl)
5 * Copyright (C) 1994-1996 Dmitry Gorodchanin (pgmdsg@ibi.com)
7 * Specialix pays for the development and support of this driver.
8 * Please DO contact io8-linux@specialix.co.uk if you require
9 * support. But please read the documentation (specialix.txt)
12 * This driver was developped in the BitWizard linux device
13 * driver service. If you require a linux device driver for your
14 * product, please contact devices@BitWizard.nl for a quote.
16 * This code is firmly based on the riscom/8 serial driver,
17 * written by Dmitry Gorodchanin. The specialix IO8+ card
18 * programming information was obtained from the CL-CD1865 Data
19 * Book, and Specialix document number 6200059: IO8+ Hardware
20 * Functional Specification.
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License as
24 * published by the Free Software Foundation; either version 2 of
25 * the License, or (at your option) any later version.
27 * This program is distributed in the hope that it will be
28 * useful, but WITHOUT ANY WARRANTY; without even the implied
29 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
30 * PURPOSE. See the GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public
33 * License along with this program; if not, write to the Free
34 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
39 * Revision 1.0: April 1st 1997.
40 * Initial release for alpha testing.
41 * Revision 1.1: April 14th 1997.
42 * Incorporated Richard Hudsons suggestions,
43 * removed some debugging printk's.
44 * Revision 1.2: April 15th 1997.
45 * Ported to 2.1.x kernels.
46 * Revision 1.3: April 17th 1997
47 * Backported to 2.0. (Compatibility macros).
48 * Revision 1.4: April 18th 1997
49 * Fixed DTR/RTS bug that caused the card to indicate
50 * "don't send data" to a modem after the password prompt.
51 * Fixed bug for premature (fake) interrupts.
52 * Revision 1.5: April 19th 1997
53 * fixed a minor typo in the header file, cleanup a little.
54 * performance warnings are now MAXed at once per minute.
55 * Revision 1.6: May 23 1997
56 * Changed the specialix=... format to include interrupt.
57 * Revision 1.7: May 27 1997
58 * Made many more debug printk's a compile time option.
59 * Revision 1.8: Jul 1 1997
60 * port to linux-2.1.43 kernel.
61 * Revision 1.9: Oct 9 1998
62 * Added stuff for the IO8+/PCI version.
63 * Revision 1.10: Oct 22 1999 / Jan 21 2000.
64 * Added stuff for setserial.
65 * Nicolas Mailhot (Nicolas.Mailhot@email.enst.fr)
69 #define VERSION "1.10"
73 * There is a bunch of documentation about the card, jumpers, config
74 * settings, restrictions, cables, device names and numbers in
75 * Documentation/specialix.txt
78 #include <linux/config.h>
79 #include <linux/module.h>
82 #include <linux/kernel.h>
83 #include <linux/sched.h>
84 #include <linux/ioport.h>
85 #include <linux/interrupt.h>
86 #include <linux/errno.h>
87 #include <linux/tty.h>
89 #include <linux/serial.h>
90 #include <linux/fcntl.h>
91 #include <linux/major.h>
92 #include <linux/delay.h>
93 #include <linux/version.h>
94 #include <linux/pci.h>
95 #include <linux/init.h>
96 #include <asm/uaccess.h>
98 #include "specialix_io8.h"
103 /* Configurable options: */
105 /* Am I paranoid or not ? ;-) */
106 #define SPECIALIX_PARANOIA_CHECK
108 /* Do I trust the IRQ from the card? (enabeling it doesn't seem to help)
109 When the IRQ routine leaves the chip in a state that is keeps on
110 requiring attention, the timer doesn't help either. */
111 #undef SPECIALIX_TIMER
114 * The following defines are mostly for testing purposes. But if you need
115 * some nice reporting in your syslog, you can define them also.
117 #undef SX_REPORT_FIFO
118 #undef SX_REPORT_OVERRUN
122 #ifdef CONFIG_SPECIALIX_RTSCTS
123 #define SX_CRTSCTS(bla) 1
125 #define SX_CRTSCTS(tty) C_CRTSCTS(tty)
129 /* Used to be outb (0xff, 0x80); */
130 #define short_pause() udelay (1)
133 #define SPECIALIX_LEGAL_FLAGS \
134 (ASYNC_HUP_NOTIFY | ASYNC_SAK | ASYNC_SPLIT_TERMIOS | \
135 ASYNC_SPD_HI | ASYNC_SPEED_VHI | ASYNC_SESSION_LOCKOUT | \
136 ASYNC_PGRP_LOCKOUT | ASYNC_CALLOUT_NOHUP)
138 #undef RS_EVENT_WRITE_WAKEUP
139 #define RS_EVENT_WRITE_WAKEUP 0
141 static struct tty_driver *specialix_driver;
142 static unsigned char * tmp_buf;
143 static DECLARE_MUTEX(tmp_buf_sem);
145 static unsigned long baud_table[] = {
146 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
147 9600, 19200, 38400, 57600, 115200, 0,
150 static struct specialix_board sx_board[SX_NBOARD] = {
151 { 0, SX_IOBASE1, 9, },
152 { 0, SX_IOBASE2, 11, },
153 { 0, SX_IOBASE3, 12, },
154 { 0, SX_IOBASE4, 15, },
157 static struct specialix_port sx_port[SX_NBOARD * SX_NPORT];
160 #ifdef SPECIALIX_TIMER
161 static struct timer_list missed_irq_timer;
162 static irqreturn_t sx_interrupt(int irq, void * dev_id, struct pt_regs * regs);
167 static inline int sx_paranoia_check(struct specialix_port const * port,
168 char *name, const char *routine)
170 #ifdef SPECIALIX_PARANOIA_CHECK
171 static const char *badmagic =
172 KERN_ERR "sx: Warning: bad specialix port magic number for device %s in %s\n";
173 static const char *badinfo =
174 KERN_ERR "sx: Warning: null specialix port for device %s in %s\n";
177 printk(badinfo, name, routine);
180 if (port->magic != SPECIALIX_MAGIC) {
181 printk(badmagic, name, routine);
191 * Service functions for specialix IO8+ driver.
195 /* Get board number from pointer */
196 static inline int board_No (struct specialix_board * bp)
198 return bp - sx_board;
202 /* Get port number from pointer */
203 static inline int port_No (struct specialix_port const * port)
205 return SX_PORT(port - sx_port);
209 /* Get pointer to board from pointer to port */
210 static inline struct specialix_board * port_Board(struct specialix_port const * port)
212 return &sx_board[SX_BOARD(port - sx_port)];
216 /* Input Byte from CL CD186x register */
217 static inline unsigned char sx_in(struct specialix_board * bp, unsigned short reg)
219 bp->reg = reg | 0x80;
220 outb (reg | 0x80, bp->base + SX_ADDR_REG);
221 return inb (bp->base + SX_DATA_REG);
225 /* Output Byte to CL CD186x register */
226 static inline void sx_out(struct specialix_board * bp, unsigned short reg,
229 bp->reg = reg | 0x80;
230 outb (reg | 0x80, bp->base + SX_ADDR_REG);
231 outb (val, bp->base + SX_DATA_REG);
235 /* Input Byte from CL CD186x register */
236 static inline unsigned char sx_in_off(struct specialix_board * bp, unsigned short reg)
239 outb (reg, bp->base + SX_ADDR_REG);
240 return inb (bp->base + SX_DATA_REG);
244 /* Output Byte to CL CD186x register */
245 static inline void sx_out_off(struct specialix_board * bp, unsigned short reg,
249 outb (reg, bp->base + SX_ADDR_REG);
250 outb (val, bp->base + SX_DATA_REG);
254 /* Wait for Channel Command Register ready */
255 static inline void sx_wait_CCR(struct specialix_board * bp)
259 for (delay = SX_CCR_TIMEOUT; delay; delay--)
260 if (!sx_in(bp, CD186x_CCR))
263 printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp));
267 /* Wait for Channel Command Register ready */
268 static inline void sx_wait_CCR_off(struct specialix_board * bp)
272 for (delay = SX_CCR_TIMEOUT; delay; delay--)
273 if (!sx_in_off(bp, CD186x_CCR))
276 printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp));
281 * specialix IO8+ IO range functions.
284 static inline int sx_check_io_range(struct specialix_board * bp)
286 return check_region (bp->base, SX_IO_SPACE);
290 static inline void sx_request_io_range(struct specialix_board * bp)
292 request_region(bp->base,
293 bp->flags&SX_BOARD_IS_PCI?SX_PCI_IO_SPACE:SX_IO_SPACE,
298 static inline void sx_release_io_range(struct specialix_board * bp)
300 release_region(bp->base,
301 bp->flags&SX_BOARD_IS_PCI?SX_PCI_IO_SPACE:SX_IO_SPACE);
305 /* Must be called with enabled interrupts */
306 /* Ugly. Very ugly. Don't use this for anything else than initialization
308 static inline void sx_long_delay(unsigned long delay)
312 for (i = jiffies + delay; time_after(i, jiffies); ) ;
317 /* Set the IRQ using the RTS lines that run to the PAL on the board.... */
318 int sx_set_irq ( struct specialix_board *bp)
323 if (bp->flags & SX_BOARD_IS_PCI)
326 /* In the same order as in the docs... */
327 case 15: virq = 0;break;
328 case 12: virq = 1;break;
329 case 11: virq = 2;break;
330 case 9: virq = 3;break;
331 default: printk (KERN_ERR "Speclialix: cannot set irq to %d.\n", bp->irq);
336 sx_out(bp, CD186x_CAR, i);
337 sx_out(bp, CD186x_MSVRTS, ((virq >> i) & 0x1)? MSVR_RTS:0);
343 /* Reset and setup CD186x chip */
344 static int sx_init_CD186x(struct specialix_board * bp)
350 save_flags(flags); cli();
352 sx_wait_CCR_off(bp); /* Wait for CCR ready */
353 sx_out_off(bp, CD186x_CCR, CCR_HARDRESET); /* Reset CD186x chip */
355 sx_long_delay(HZ/20); /* Delay 0.05 sec */
357 sx_out_off(bp, CD186x_GIVR, SX_ID); /* Set ID for this chip */
358 sx_out_off(bp, CD186x_GICR, 0); /* Clear all bits */
359 sx_out_off(bp, CD186x_PILR1, SX_ACK_MINT); /* Prio for modem intr */
360 sx_out_off(bp, CD186x_PILR2, SX_ACK_TINT); /* Prio for transmitter intr */
361 sx_out_off(bp, CD186x_PILR3, SX_ACK_RINT); /* Prio for receiver intr */
363 sx_out_off(bp, CD186x_SRCR, sx_in (bp, CD186x_SRCR) | SRCR_REGACKEN);
365 /* Setting up prescaler. We need 4 ticks per 1 ms */
366 scaler = SX_OSCFREQ/SPECIALIX_TPS;
368 sx_out_off(bp, CD186x_PPRH, scaler >> 8);
369 sx_out_off(bp, CD186x_PPRL, scaler & 0xff);
371 if (!sx_set_irq (bp)) {
372 /* Figure out how to pass this along... */
373 printk (KERN_ERR "Cannot set irq to %d.\n", bp->irq);
377 restore_flags(flags);
382 int read_cross_byte (struct specialix_board *bp, int reg, int bit)
387 for (i=0, t=0;i<8;i++) {
388 sx_out_off (bp, CD186x_CAR, i);
389 if (sx_in_off (bp, reg) & bit)
396 #ifdef SPECIALIX_TIMER
397 void missed_irq (unsigned long data)
399 if (sx_in ((struct specialix_board *)data, CD186x_SRSR) &
403 printk (KERN_INFO "Missed interrupt... Calling int from timer. \n");
404 sx_interrupt (((struct specialix_board *)data)->irq,
407 missed_irq_timer.expires = jiffies + HZ;
408 add_timer (&missed_irq_timer);
414 /* Main probing routine, also sets irq. */
415 static int sx_probe(struct specialix_board *bp)
417 unsigned char val1, val2;
425 if (sx_check_io_range(bp))
428 /* Are the I/O ports here ? */
429 sx_out_off(bp, CD186x_PPRL, 0x5a);
431 val1 = sx_in_off(bp, CD186x_PPRL);
433 sx_out_off(bp, CD186x_PPRL, 0xa5);
435 val2 = sx_in_off(bp, CD186x_PPRL);
438 if ((val1 != 0x5a) || (val2 != 0xa5)) {
439 printk(KERN_INFO "sx%d: specialix IO8+ Board at 0x%03x not found.\n",
440 board_No(bp), bp->base);
444 /* Check the DSR lines that Specialix uses as board
446 val1 = read_cross_byte (bp, CD186x_MSVR, MSVR_DSR);
447 val2 = read_cross_byte (bp, CD186x_MSVR, MSVR_RTS);
448 #ifdef SPECIALIX_DEBUG
449 printk (KERN_DEBUG "sx%d: DSR lines are: %02x, rts lines are: %02x\n",
450 board_No(bp), val1, val2);
452 /* They managed to switch the bit order between the docs and
453 the IO8+ card. The new PCI card now conforms to old docs.
454 They changed the PCI docs to reflect the situation on the
456 val2 = (bp->flags & SX_BOARD_IS_PCI)?0x4d : 0xb2;
458 printk(KERN_INFO "sx%d: specialix IO8+ ID %02x at 0x%03x not found (%02x).\n",
459 board_No(bp), val2, bp->base, val1);
465 /* It's time to find IRQ for this board */
466 for (retries = 0; retries < 5 && irqs <= 0; retries++) {
467 irqs = probe_irq_on();
468 sx_init_CD186x(bp); /* Reset CD186x chip */
469 sx_out(bp, CD186x_CAR, 2); /* Select port 2 */
471 sx_out(bp, CD186x_CCR, CCR_TXEN); /* Enable transmitter */
472 sx_out(bp, CD186x_IER, IER_TXRDY); /* Enable tx empty intr */
473 sx_long_delay(HZ/20);
474 irqs = probe_irq_off(irqs);
476 #if SPECIALIX_DEBUG > 2
477 printk (KERN_DEBUG "SRSR = %02x, ", sx_in(bp, CD186x_SRSR));
478 printk ( "TRAR = %02x, ", sx_in(bp, CD186x_TRAR));
479 printk ( "GIVR = %02x, ", sx_in(bp, CD186x_GIVR));
480 printk ( "GICR = %02x, ", sx_in(bp, CD186x_GICR));
483 /* Reset CD186x again */
484 if (!sx_init_CD186x(bp)) {
485 /* Hmmm. This is dead code anyway. */
487 #if SPECIALIX_DEBUG > 2
488 printk (KERN_DEBUG "val1 = %02x, val2 = %02x, val3 = %02x.\n",
496 printk(KERN_ERR "sx%d: Can't find IRQ for specialix IO8+ board at 0x%03x.\n",
497 board_No(bp), bp->base);
501 printk (KERN_INFO "Started with irq=%d, but now have irq=%d.\n", bp->irq, irqs);
505 /* Reset CD186x again */
506 if (!sx_init_CD186x(bp)) {
510 sx_request_io_range(bp);
511 bp->flags |= SX_BOARD_PRESENT;
513 /* Chip revcode pkgtype
518 CD1865 rev A 0x83 1 -- Do not use!!! Does not work.
520 -- Thanks to Gwen Wang, Cirrus Logic.
523 switch (sx_in_off(bp, CD186x_GFRCR)) {
524 case 0x82:chip = 1864;rev='A';break;
525 case 0x83:chip = 1865;rev='A';break;
526 case 0x84:chip = 1865;rev='B';break;
527 case 0x85:chip = 1865;rev='C';break; /* Does not exist at this time */
528 default:chip=-1;rev='x';
531 #if SPECIALIX_DEBUG > 2
532 printk (KERN_DEBUG " GFCR = 0x%02x\n", sx_in_off(bp, CD186x_GFRCR) );
535 #ifdef SPECIALIX_TIMER
536 init_timer (&missed_irq_timer);
537 missed_irq_timer.function = missed_irq;
538 missed_irq_timer.data = (unsigned long) bp;
539 missed_irq_timer.expires = jiffies + HZ;
540 add_timer (&missed_irq_timer);
543 printk(KERN_INFO"sx%d: specialix IO8+ board detected at 0x%03x, IRQ %d, CD%d Rev. %c.\n",
553 * Interrupt processing routines.
556 static inline void sx_mark_event(struct specialix_port * port, int event)
558 set_bit(event, &port->event);
559 schedule_work(&port->tqueue);
563 static inline struct specialix_port * sx_get_port(struct specialix_board * bp,
564 unsigned char const * what)
566 unsigned char channel;
567 struct specialix_port * port;
569 channel = sx_in(bp, CD186x_GICR) >> GICR_CHAN_OFF;
570 if (channel < CD186x_NCH) {
571 port = &sx_port[board_No(bp) * SX_NPORT + channel];
572 if (port->flags & ASYNC_INITIALIZED) {
576 printk(KERN_INFO "sx%d: %s interrupt from invalid port %d\n",
577 board_No(bp), what, channel);
582 static inline void sx_receive_exc(struct specialix_board * bp)
584 struct specialix_port *port;
585 struct tty_struct *tty;
586 unsigned char status;
589 if (!(port = sx_get_port(bp, "Receive")))
593 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
594 printk(KERN_INFO "sx%d: port %d: Working around flip buffer overflow.\n",
595 board_No(bp), port_No(port));
599 #ifdef SX_REPORT_OVERRUN
600 status = sx_in(bp, CD186x_RCSR);
601 if (status & RCSR_OE) {
604 printk(KERN_DEBUG "sx%d: port %d: Overrun. Total %ld overruns.\n",
605 board_No(bp), port_No(port), port->overrun);
608 status &= port->mark_mask;
610 status = sx_in(bp, CD186x_RCSR) & port->mark_mask;
612 ch = sx_in(bp, CD186x_RDR);
616 if (status & RCSR_TOUT) {
617 printk(KERN_INFO "sx%d: port %d: Receiver timeout. Hardware problems ?\n",
618 board_No(bp), port_No(port));
621 } else if (status & RCSR_BREAK) {
622 #ifdef SPECIALIX_DEBUG
623 printk(KERN_DEBUG "sx%d: port %d: Handling break...\n",
624 board_No(bp), port_No(port));
626 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
627 if (port->flags & ASYNC_SAK)
630 } else if (status & RCSR_PE)
631 *tty->flip.flag_buf_ptr++ = TTY_PARITY;
633 else if (status & RCSR_FE)
634 *tty->flip.flag_buf_ptr++ = TTY_FRAME;
636 else if (status & RCSR_OE)
637 *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
640 *tty->flip.flag_buf_ptr++ = 0;
642 *tty->flip.char_buf_ptr++ = ch;
644 schedule_delayed_work(&tty->flip.work, 1);
648 static inline void sx_receive(struct specialix_board * bp)
650 struct specialix_port *port;
651 struct tty_struct *tty;
654 if (!(port = sx_get_port(bp, "Receive")))
659 count = sx_in(bp, CD186x_RDCR);
661 #ifdef SX_REPORT_FIFO
662 port->hits[count > 8 ? 9 : count]++;
666 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
667 printk(KERN_INFO "sx%d: port %d: Working around flip buffer overflow.\n",
668 board_No(bp), port_No(port));
671 *tty->flip.char_buf_ptr++ = sx_in(bp, CD186x_RDR);
672 *tty->flip.flag_buf_ptr++ = 0;
675 schedule_delayed_work(&tty->flip.work, 1);
679 static inline void sx_transmit(struct specialix_board * bp)
681 struct specialix_port *port;
682 struct tty_struct *tty;
686 if (!(port = sx_get_port(bp, "Transmit")))
691 if (port->IER & IER_TXEMPTY) {
693 sx_out(bp, CD186x_CAR, port_No(port));
694 port->IER &= ~IER_TXEMPTY;
695 sx_out(bp, CD186x_IER, port->IER);
699 if ((port->xmit_cnt <= 0 && !port->break_length)
700 || tty->stopped || tty->hw_stopped) {
701 sx_out(bp, CD186x_CAR, port_No(port));
702 port->IER &= ~IER_TXRDY;
703 sx_out(bp, CD186x_IER, port->IER);
707 if (port->break_length) {
708 if (port->break_length > 0) {
709 if (port->COR2 & COR2_ETC) {
710 sx_out(bp, CD186x_TDR, CD186x_C_ESC);
711 sx_out(bp, CD186x_TDR, CD186x_C_SBRK);
712 port->COR2 &= ~COR2_ETC;
714 count = min_t(int, port->break_length, 0xff);
715 sx_out(bp, CD186x_TDR, CD186x_C_ESC);
716 sx_out(bp, CD186x_TDR, CD186x_C_DELAY);
717 sx_out(bp, CD186x_TDR, count);
718 if (!(port->break_length -= count))
719 port->break_length--;
721 sx_out(bp, CD186x_TDR, CD186x_C_ESC);
722 sx_out(bp, CD186x_TDR, CD186x_C_EBRK);
723 sx_out(bp, CD186x_COR2, port->COR2);
725 sx_out(bp, CD186x_CCR, CCR_CORCHG2);
726 port->break_length = 0;
731 count = CD186x_NFIFO;
733 sx_out(bp, CD186x_TDR, port->xmit_buf[port->xmit_tail++]);
734 port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1);
735 if (--port->xmit_cnt <= 0)
737 } while (--count > 0);
739 if (port->xmit_cnt <= 0) {
740 sx_out(bp, CD186x_CAR, port_No(port));
741 port->IER &= ~IER_TXRDY;
742 sx_out(bp, CD186x_IER, port->IER);
744 if (port->xmit_cnt <= port->wakeup_chars)
745 sx_mark_event(port, RS_EVENT_WRITE_WAKEUP);
749 static inline void sx_check_modem(struct specialix_board * bp)
751 struct specialix_port *port;
752 struct tty_struct *tty;
755 #ifdef SPECIALIX_DEBUG
756 printk (KERN_DEBUG "Modem intr. ");
758 if (!(port = sx_get_port(bp, "Modem")))
763 mcr = sx_in(bp, CD186x_MCR);
764 printk ("mcr = %02x.\n", mcr);
766 if ((mcr & MCR_CDCHG)) {
767 #ifdef SPECIALIX_DEBUG
768 printk (KERN_DEBUG "CD just changed... ");
770 if (sx_in(bp, CD186x_MSVR) & MSVR_CD) {
771 #ifdef SPECIALIX_DEBUG
772 printk ( "Waking up guys in open.\n");
774 wake_up_interruptible(&port->open_wait);
776 #ifdef SPECIALIX_DEBUG
777 printk ( "Sending HUP.\n");
779 schedule_work(&port->tqueue_hangup);
783 #ifdef SPECIALIX_BRAIN_DAMAGED_CTS
784 if (mcr & MCR_CTSCHG) {
785 if (sx_in(bp, CD186x_MSVR) & MSVR_CTS) {
787 port->IER |= IER_TXRDY;
788 if (port->xmit_cnt <= port->wakeup_chars)
789 sx_mark_event(port, RS_EVENT_WRITE_WAKEUP);
792 port->IER &= ~IER_TXRDY;
794 sx_out(bp, CD186x_IER, port->IER);
796 if (mcr & MCR_DSSXHG) {
797 if (sx_in(bp, CD186x_MSVR) & MSVR_DSR) {
799 port->IER |= IER_TXRDY;
800 if (port->xmit_cnt <= port->wakeup_chars)
801 sx_mark_event(port, RS_EVENT_WRITE_WAKEUP);
804 port->IER &= ~IER_TXRDY;
806 sx_out(bp, CD186x_IER, port->IER);
808 #endif /* SPECIALIX_BRAIN_DAMAGED_CTS */
810 /* Clear change bits */
811 sx_out(bp, CD186x_MCR, 0);
815 /* The main interrupt processing routine */
816 static irqreturn_t sx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
818 unsigned char status;
820 struct specialix_board *bp;
821 unsigned long loop = 0;
826 if (!bp || !(bp->flags & SX_BOARD_ACTIVE)) {
827 #ifdef SPECIALIX_DEBUG
828 printk (KERN_DEBUG "sx: False interrupt. irq %d.\n", irq);
835 while ((++loop < 16) && (status = (sx_in(bp, CD186x_SRSR) &
839 if (status & SRSR_RREQint) {
840 ack = sx_in(bp, CD186x_RRAR);
842 if (ack == (SX_ID | GIVR_IT_RCV))
844 else if (ack == (SX_ID | GIVR_IT_REXC))
847 printk(KERN_ERR "sx%d: Bad receive ack 0x%02x.\n",
850 } else if (status & SRSR_TREQint) {
851 ack = sx_in(bp, CD186x_TRAR);
853 if (ack == (SX_ID | GIVR_IT_TX))
856 printk(KERN_ERR "sx%d: Bad transmit ack 0x%02x.\n",
858 } else if (status & SRSR_MREQint) {
859 ack = sx_in(bp, CD186x_MRAR);
861 if (ack == (SX_ID | GIVR_IT_MODEM))
864 printk(KERN_ERR "sx%d: Bad modem ack 0x%02x.\n",
869 sx_out(bp, CD186x_EOIR, 0); /* Mark end of interrupt */
872 outb (bp->reg, bp->base + SX_ADDR_REG);
878 * Routines for open & close processing.
881 void turn_ints_off (struct specialix_board *bp)
883 if (bp->flags & SX_BOARD_IS_PCI) {
884 /* This was intended for enabeling the interrupt on the
885 * PCI card. However it seems that it's already enabled
886 * and as PCI interrupts can be shared, there is no real
887 * reason to have to turn it off. */
889 (void) sx_in_off (bp, 0); /* Turn off interrupts. */
892 void turn_ints_on (struct specialix_board *bp)
894 if (bp->flags & SX_BOARD_IS_PCI) {
895 /* play with the PCI chip. See comment above. */
897 (void) sx_in (bp, 0); /* Turn ON interrupts. */
901 /* Called with disabled interrupts */
902 static inline int sx_setup_board(struct specialix_board * bp)
906 if (bp->flags & SX_BOARD_ACTIVE)
909 if (bp->flags & SX_BOARD_IS_PCI)
910 error = request_irq(bp->irq, sx_interrupt, SA_INTERRUPT | SA_SHIRQ, "specialix IO8+", bp);
912 error = request_irq(bp->irq, sx_interrupt, SA_INTERRUPT, "specialix IO8+", bp);
918 bp->flags |= SX_BOARD_ACTIVE;
924 /* Called with disabled interrupts */
925 static inline void sx_shutdown_board(struct specialix_board *bp)
927 if (!(bp->flags & SX_BOARD_ACTIVE))
930 bp->flags &= ~SX_BOARD_ACTIVE;
932 #if SPECIALIX_DEBUG > 2
933 printk ("Freeing IRQ%d for board %d.\n", bp->irq, board_No (bp));
935 free_irq(bp->irq, bp);
943 * Setting up port characteristics.
944 * Must be called with disabled interrupts
946 static void sx_change_speed(struct specialix_board *bp, struct specialix_port *port)
948 struct tty_struct *tty;
951 unsigned char cor1 = 0, cor3 = 0;
952 unsigned char mcor1 = 0, mcor2 = 0;
953 static unsigned long again;
955 if (!(tty = port->tty) || !tty->termios)
960 /* Select port on the board */
961 sx_out(bp, CD186x_CAR, port_No(port));
963 /* The Specialix board doens't implement the RTS lines.
964 They are used to set the IRQ level. Don't touch them. */
966 port->MSVR = MSVR_DTR | (sx_in(bp, CD186x_MSVR) & MSVR_RTS);
968 port->MSVR = (sx_in(bp, CD186x_MSVR) & MSVR_RTS);
969 #ifdef DEBUG_SPECIALIX
970 printk (KERN_DEBUG "sx: got MSVR=%02x.\n", port->MSVR);
974 if (baud & CBAUDEX) {
976 if (baud < 1 || baud > 2)
977 port->tty->termios->c_cflag &= ~CBAUDEX;
982 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
984 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
989 if (!baud_table[baud]) {
990 /* Drop DTR & exit */
991 #ifdef SPECIALIX_DEBUG
992 printk (KERN_DEBUG "Dropping DTR... Hmm....\n");
994 if (!SX_CRTSCTS (tty)) {
995 port -> MSVR &= ~ MSVR_DTR;
996 sx_out(bp, CD186x_MSVR, port->MSVR );
998 #ifdef DEBUG_SPECIALIX
1000 printk (KERN_DEBUG "Can't drop DTR: no DTR.\n");
1005 if (!SX_CRTSCTS (tty)) {
1006 port ->MSVR |= MSVR_DTR;
1011 * Now we must calculate some speed depended things
1014 /* Set baud rate for port */
1015 tmp = port->custom_divisor ;
1017 printk (KERN_INFO "sx%d: Using custom baud rate divisor %ld. \n"
1018 "This is an untested option, please be carefull.\n",
1019 port_No (port), tmp);
1021 tmp = (((SX_OSCFREQ + baud_table[baud]/2) / baud_table[baud] +
1022 CD186x_TPC/2) / CD186x_TPC);
1024 if ((tmp < 0x10) && time_before(again, jiffies)) {
1025 again = jiffies + HZ * 60;
1026 /* Page 48 of version 2.0 of the CL-CD1865 databook */
1028 printk (KERN_INFO "sx%d: Baud rate divisor is %ld. \n"
1029 "Performance degradation is possible.\n"
1030 "Read specialix.txt for more info.\n",
1031 port_No (port), tmp);
1033 printk (KERN_INFO "sx%d: Baud rate divisor is %ld. \n"
1034 "Warning: overstressing Cirrus chip. "
1035 "This might not work.\n"
1036 "Read specialix.txt for more info.\n",
1037 port_No (port), tmp);
1041 sx_out(bp, CD186x_RBPRH, (tmp >> 8) & 0xff);
1042 sx_out(bp, CD186x_TBPRH, (tmp >> 8) & 0xff);
1043 sx_out(bp, CD186x_RBPRL, tmp & 0xff);
1044 sx_out(bp, CD186x_TBPRL, tmp & 0xff);
1046 if (port->custom_divisor) {
1047 baud = (SX_OSCFREQ + port->custom_divisor/2) / port->custom_divisor;
1048 baud = ( baud + 5 ) / 10;
1050 baud = (baud_table[baud] + 5) / 10; /* Estimated CPS */
1052 /* Two timer ticks seems enough to wakeup something like SLIP driver */
1053 tmp = ((baud + HZ/2) / HZ) * 2 - CD186x_NFIFO;
1054 port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
1055 SERIAL_XMIT_SIZE - 1 : tmp);
1057 /* Receiver timeout will be transmission time for 1.5 chars */
1058 tmp = (SPECIALIX_TPS + SPECIALIX_TPS/2 + baud/2) / baud;
1059 tmp = (tmp > 0xff) ? 0xff : tmp;
1060 sx_out(bp, CD186x_RTPR, tmp);
1062 switch (C_CSIZE(tty)) {
1080 cor1 |= COR1_IGNORE;
1081 if (C_PARENB(tty)) {
1082 cor1 |= COR1_NORMPAR;
1086 cor1 &= ~COR1_IGNORE;
1088 /* Set marking of some errors */
1089 port->mark_mask = RCSR_OE | RCSR_TOUT;
1091 port->mark_mask |= RCSR_FE | RCSR_PE;
1092 if (I_BRKINT(tty) || I_PARMRK(tty))
1093 port->mark_mask |= RCSR_BREAK;
1095 port->mark_mask &= ~(RCSR_FE | RCSR_PE);
1096 if (I_IGNBRK(tty)) {
1097 port->mark_mask &= ~RCSR_BREAK;
1099 /* Real raw mode. Ignore all */
1100 port->mark_mask &= ~RCSR_OE;
1102 /* Enable Hardware Flow Control */
1103 if (C_CRTSCTS(tty)) {
1104 #ifdef SPECIALIX_BRAIN_DAMAGED_CTS
1105 port->IER |= IER_DSR | IER_CTS;
1106 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
1107 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
1108 tty->hw_stopped = !(sx_in(bp, CD186x_MSVR) & (MSVR_CTS|MSVR_DSR));
1110 port->COR2 |= COR2_CTSAE;
1113 /* Enable Software Flow Control. FIXME: I'm not sure about this */
1114 /* Some people reported that it works, but I still doubt it */
1116 port->COR2 |= COR2_TXIBE;
1117 cor3 |= (COR3_FCT | COR3_SCDE);
1119 port->COR2 |= COR2_IXM;
1120 sx_out(bp, CD186x_SCHR1, START_CHAR(tty));
1121 sx_out(bp, CD186x_SCHR2, STOP_CHAR(tty));
1122 sx_out(bp, CD186x_SCHR3, START_CHAR(tty));
1123 sx_out(bp, CD186x_SCHR4, STOP_CHAR(tty));
1125 if (!C_CLOCAL(tty)) {
1126 /* Enable CD check */
1127 port->IER |= IER_CD;
1128 mcor1 |= MCOR1_CDZD;
1129 mcor2 |= MCOR2_CDOD;
1133 /* Enable receiver */
1134 port->IER |= IER_RXD;
1136 /* Set input FIFO size (1-8 bytes) */
1137 cor3 |= SPECIALIX_RXFIFO;
1138 /* Setting up CD186x channel registers */
1139 sx_out(bp, CD186x_COR1, cor1);
1140 sx_out(bp, CD186x_COR2, port->COR2);
1141 sx_out(bp, CD186x_COR3, cor3);
1142 /* Make CD186x know about registers change */
1144 sx_out(bp, CD186x_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3);
1145 /* Setting up modem option registers */
1146 #ifdef DEBUG_SPECIALIX
1147 printk ("Mcor1 = %02x, mcor2 = %02x.\n", mcor1, mcor2);
1149 sx_out(bp, CD186x_MCOR1, mcor1);
1150 sx_out(bp, CD186x_MCOR2, mcor2);
1151 /* Enable CD186x transmitter & receiver */
1153 sx_out(bp, CD186x_CCR, CCR_TXEN | CCR_RXEN);
1154 /* Enable interrupts */
1155 sx_out(bp, CD186x_IER, port->IER);
1156 /* And finally set the modem lines... */
1157 sx_out(bp, CD186x_MSVR, port->MSVR);
1161 /* Must be called with interrupts enabled */
1162 static int sx_setup_port(struct specialix_board *bp, struct specialix_port *port)
1164 unsigned long flags;
1166 if (port->flags & ASYNC_INITIALIZED)
1169 if (!port->xmit_buf) {
1170 /* We may sleep in get_zeroed_page() */
1173 if (!(tmp = get_zeroed_page(GFP_KERNEL)))
1176 if (port->xmit_buf) {
1178 return -ERESTARTSYS;
1180 port->xmit_buf = (unsigned char *) tmp;
1183 save_flags(flags); cli();
1186 clear_bit(TTY_IO_ERROR, &port->tty->flags);
1188 if (port->count == 1)
1191 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1192 sx_change_speed(bp, port);
1193 port->flags |= ASYNC_INITIALIZED;
1195 restore_flags(flags);
1200 /* Must be called with interrupts disabled */
1201 static void sx_shutdown_port(struct specialix_board *bp, struct specialix_port *port)
1203 struct tty_struct *tty;
1205 if (!(port->flags & ASYNC_INITIALIZED))
1208 #ifdef SX_REPORT_OVERRUN
1209 printk(KERN_INFO "sx%d: port %d: Total %ld overruns were detected.\n",
1210 board_No(bp), port_No(port), port->overrun);
1212 #ifdef SX_REPORT_FIFO
1216 printk(KERN_INFO "sx%d: port %d: FIFO hits [ ",
1217 board_No(bp), port_No(port));
1218 for (i = 0; i < 10; i++) {
1219 printk("%ld ", port->hits[i]);
1224 if (port->xmit_buf) {
1225 free_page((unsigned long) port->xmit_buf);
1226 port->xmit_buf = NULL;
1230 sx_out(bp, CD186x_CAR, port_No(port));
1232 if (!(tty = port->tty) || C_HUPCL(tty)) {
1234 sx_out(bp, CD186x_MSVDTR, 0);
1239 sx_out(bp, CD186x_CCR, CCR_SOFTRESET);
1240 /* Disable all interrupts from this port */
1242 sx_out(bp, CD186x_IER, port->IER);
1245 set_bit(TTY_IO_ERROR, &tty->flags);
1246 port->flags &= ~ASYNC_INITIALIZED;
1248 if (--bp->count < 0) {
1249 printk(KERN_ERR "sx%d: sx_shutdown_port: bad board count: %d\n",
1250 board_No(bp), bp->count);
1255 * If this is the last opened port on the board
1256 * shutdown whole board
1259 sx_shutdown_board(bp);
1263 static int block_til_ready(struct tty_struct *tty, struct file * filp,
1264 struct specialix_port *port)
1266 DECLARE_WAITQUEUE(wait, current);
1267 struct specialix_board *bp = port_Board(port);
1273 * If the device is in the middle of being closed, then block
1274 * until it's done, and then try again.
1276 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
1277 interruptible_sleep_on(&port->close_wait);
1278 if (port->flags & ASYNC_HUP_NOTIFY)
1281 return -ERESTARTSYS;
1285 * If non-blocking mode is set, or the port is not enabled,
1286 * then make the check up front and then exit.
1288 if ((filp->f_flags & O_NONBLOCK) ||
1289 (tty->flags & (1 << TTY_IO_ERROR))) {
1290 port->flags |= ASYNC_NORMAL_ACTIVE;
1298 * Block waiting for the carrier detect and the line to become
1299 * free (i.e., not in use by the callout). While we are in
1300 * this loop, info->count is dropped by one, so that
1301 * rs_close() knows when to free things. We restore it upon
1302 * exit, either normal or abnormal.
1305 add_wait_queue(&port->open_wait, &wait);
1307 if (!tty_hung_up_p(filp))
1310 port->blocked_open++;
1313 sx_out(bp, CD186x_CAR, port_No(port));
1314 CD = sx_in(bp, CD186x_MSVR) & MSVR_CD;
1315 if (SX_CRTSCTS (tty)) {
1317 port->MSVR |= MSVR_DTR; /* WTF? */
1318 sx_out (bp, CD186x_MSVR, port->MSVR);
1321 port->MSVR |= MSVR_DTR;
1322 sx_out (bp, CD186x_MSVR, port->MSVR);
1325 set_current_state(TASK_INTERRUPTIBLE);
1326 if (tty_hung_up_p(filp) ||
1327 !(port->flags & ASYNC_INITIALIZED)) {
1328 if (port->flags & ASYNC_HUP_NOTIFY)
1331 retval = -ERESTARTSYS;
1334 if (!(port->flags & ASYNC_CLOSING) &&
1337 if (signal_pending(current)) {
1338 retval = -ERESTARTSYS;
1343 current->state = TASK_RUNNING;
1344 remove_wait_queue(&port->open_wait, &wait);
1345 if (!tty_hung_up_p(filp))
1347 port->blocked_open--;
1351 port->flags |= ASYNC_NORMAL_ACTIVE;
1356 static int sx_open(struct tty_struct * tty, struct file * filp)
1360 struct specialix_port * port;
1361 struct specialix_board * bp;
1363 board = SX_BOARD(tty->index);
1365 if (board >= SX_NBOARD || !(sx_board[board].flags & SX_BOARD_PRESENT))
1368 bp = &sx_board[board];
1369 port = sx_port + board * SX_NPORT + SX_PORT(tty->index);
1371 #ifdef DEBUG_SPECIALIX
1372 printk (KERN_DEBUG "Board = %d, bp = %p, port = %p, portno = %d.\n",
1373 board, bp, port, SX_PORT(tty->index));
1376 if (sx_paranoia_check(port, tty->name, "sx_open"))
1379 if ((error = sx_setup_board(bp)))
1383 tty->driver_data = port;
1386 if ((error = sx_setup_port(bp, port)))
1389 if ((error = block_til_ready(tty, filp, port)))
1396 static void sx_close(struct tty_struct * tty, struct file * filp)
1398 struct specialix_port *port = (struct specialix_port *) tty->driver_data;
1399 struct specialix_board *bp;
1400 unsigned long flags;
1401 unsigned long timeout;
1403 if (!port || sx_paranoia_check(port, tty->name, "close"))
1406 save_flags(flags); cli();
1407 if (tty_hung_up_p(filp)) {
1408 restore_flags(flags);
1412 bp = port_Board(port);
1413 if ((tty->count == 1) && (port->count != 1)) {
1414 printk(KERN_ERR "sx%d: sx_close: bad port count;"
1415 " tty->count is 1, port count is %d\n",
1416 board_No(bp), port->count);
1419 if (--port->count < 0) {
1420 printk(KERN_ERR "sx%d: sx_close: bad port count for tty%d: %d\n",
1421 board_No(bp), port_No(port), port->count);
1425 restore_flags(flags);
1428 port->flags |= ASYNC_CLOSING;
1430 * Now we wait for the transmit buffer to clear; and we notify
1431 * the line discipline to only process XON/XOFF characters.
1434 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1435 tty_wait_until_sent(tty, port->closing_wait);
1437 * At this point we stop accepting input. To do this, we
1438 * disable the receive line status interrupts, and tell the
1439 * interrupt driver to stop checking the data ready bit in the
1440 * line status register.
1442 port->IER &= ~IER_RXD;
1443 if (port->flags & ASYNC_INITIALIZED) {
1444 port->IER &= ~IER_TXRDY;
1445 port->IER |= IER_TXEMPTY;
1446 sx_out(bp, CD186x_CAR, port_No(port));
1447 sx_out(bp, CD186x_IER, port->IER);
1449 * Before we drop DTR, make sure the UART transmitter
1450 * has completely drained; this is especially
1451 * important if there is a transmit FIFO!
1453 timeout = jiffies+HZ;
1454 while(port->IER & IER_TXEMPTY) {
1455 current->state = TASK_INTERRUPTIBLE;
1456 schedule_timeout(port->timeout);
1457 if (time_after(jiffies, timeout)) {
1458 printk (KERN_INFO "Timeout waiting for close\n");
1464 sx_shutdown_port(bp, port);
1465 if (tty->driver->flush_buffer)
1466 tty->driver->flush_buffer(tty);
1467 tty_ldisc_flush(tty);
1471 if (port->blocked_open) {
1472 if (port->close_delay) {
1473 current->state = TASK_INTERRUPTIBLE;
1474 schedule_timeout(port->close_delay);
1476 wake_up_interruptible(&port->open_wait);
1478 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1479 wake_up_interruptible(&port->close_wait);
1480 restore_flags(flags);
1484 static int sx_write(struct tty_struct * tty, int from_user,
1485 const unsigned char *buf, int count)
1487 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1488 struct specialix_board *bp;
1490 unsigned long flags;
1492 if (sx_paranoia_check(port, tty->name, "sx_write"))
1495 bp = port_Board(port);
1497 if (!tty || !port->xmit_buf || !tmp_buf)
1504 c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1505 SERIAL_XMIT_SIZE - port->xmit_head));
1509 c -= copy_from_user(tmp_buf, buf, c);
1517 c = min_t(int, c, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1518 SERIAL_XMIT_SIZE - port->xmit_head));
1519 memcpy(port->xmit_buf + port->xmit_head, tmp_buf, c);
1520 port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1521 port->xmit_cnt += c;
1522 restore_flags(flags);
1532 c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1533 SERIAL_XMIT_SIZE - port->xmit_head));
1535 restore_flags(flags);
1538 memcpy(port->xmit_buf + port->xmit_head, buf, c);
1539 port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1540 port->xmit_cnt += c;
1541 restore_flags(flags);
1550 if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1551 !(port->IER & IER_TXRDY)) {
1552 port->IER |= IER_TXRDY;
1553 sx_out(bp, CD186x_CAR, port_No(port));
1554 sx_out(bp, CD186x_IER, port->IER);
1556 restore_flags(flags);
1561 static void sx_put_char(struct tty_struct * tty, unsigned char ch)
1563 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1564 unsigned long flags;
1566 if (sx_paranoia_check(port, tty->name, "sx_put_char"))
1569 if (!tty || !port->xmit_buf)
1572 save_flags(flags); cli();
1574 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
1575 restore_flags(flags);
1579 port->xmit_buf[port->xmit_head++] = ch;
1580 port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1582 restore_flags(flags);
1586 static void sx_flush_chars(struct tty_struct * tty)
1588 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1589 unsigned long flags;
1591 if (sx_paranoia_check(port, tty->name, "sx_flush_chars"))
1594 if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1598 save_flags(flags); cli();
1599 port->IER |= IER_TXRDY;
1600 sx_out(port_Board(port), CD186x_CAR, port_No(port));
1601 sx_out(port_Board(port), CD186x_IER, port->IER);
1602 restore_flags(flags);
1606 static int sx_write_room(struct tty_struct * tty)
1608 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1611 if (sx_paranoia_check(port, tty->name, "sx_write_room"))
1614 ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
1621 static int sx_chars_in_buffer(struct tty_struct *tty)
1623 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1625 if (sx_paranoia_check(port, tty->name, "sx_chars_in_buffer"))
1628 return port->xmit_cnt;
1632 static void sx_flush_buffer(struct tty_struct *tty)
1634 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1635 unsigned long flags;
1637 if (sx_paranoia_check(port, tty->name, "sx_flush_buffer"))
1640 save_flags(flags); cli();
1641 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1642 restore_flags(flags);
1645 wake_up_interruptible(&tty->write_wait);
1649 static int sx_tiocmget(struct tty_struct *tty, struct file *file)
1651 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1652 struct specialix_board * bp;
1653 unsigned char status;
1654 unsigned int result;
1655 unsigned long flags;
1657 if (sx_paranoia_check(port, tty->name, __FUNCTION__))
1660 bp = port_Board(port);
1661 save_flags(flags); cli();
1662 sx_out(bp, CD186x_CAR, port_No(port));
1663 status = sx_in(bp, CD186x_MSVR);
1664 restore_flags(flags);
1665 #ifdef DEBUG_SPECIALIX
1666 printk (KERN_DEBUG "Got msvr[%d] = %02x, car = %d.\n",
1667 port_No(port), status, sx_in (bp, CD186x_CAR));
1668 printk (KERN_DEBUG "sx_port = %p, port = %p\n", sx_port, port);
1670 if (SX_CRTSCTS(port->tty)) {
1671 result = /* (status & MSVR_RTS) ? */ TIOCM_DTR /* : 0) */
1672 | ((status & MSVR_DTR) ? TIOCM_RTS : 0)
1673 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1674 |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */
1675 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1677 result = /* (status & MSVR_RTS) ? */ TIOCM_RTS /* : 0) */
1678 | ((status & MSVR_DTR) ? TIOCM_DTR : 0)
1679 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1680 |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */
1681 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1688 static int sx_tiocmset(struct tty_struct *tty, struct file *file,
1689 unsigned int set, unsigned int clear)
1691 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1692 unsigned long flags;
1693 struct specialix_board *bp;
1695 if (sx_paranoia_check(port, tty->name, __FUNCTION__))
1698 bp = port_Board(port);
1700 save_flags(flags); cli();
1701 /* if (set & TIOCM_RTS)
1702 port->MSVR |= MSVR_RTS; */
1703 /* if (set & TIOCM_DTR)
1704 port->MSVR |= MSVR_DTR; */
1706 if (SX_CRTSCTS(port->tty)) {
1707 if (set & TIOCM_RTS)
1708 port->MSVR |= MSVR_DTR;
1710 if (set & TIOCM_DTR)
1711 port->MSVR |= MSVR_DTR;
1714 /* if (clear & TIOCM_RTS)
1715 port->MSVR &= ~MSVR_RTS; */
1716 /* if (clear & TIOCM_DTR)
1717 port->MSVR &= ~MSVR_DTR; */
1718 if (SX_CRTSCTS(port->tty)) {
1719 if (clear & TIOCM_RTS)
1720 port->MSVR &= ~MSVR_DTR;
1722 if (clear & TIOCM_DTR)
1723 port->MSVR &= ~MSVR_DTR;
1726 sx_out(bp, CD186x_CAR, port_No(port));
1727 sx_out(bp, CD186x_MSVR, port->MSVR);
1728 restore_flags(flags);
1733 static inline void sx_send_break(struct specialix_port * port, unsigned long length)
1735 struct specialix_board *bp = port_Board(port);
1736 unsigned long flags;
1738 save_flags(flags); cli();
1739 port->break_length = SPECIALIX_TPS / HZ * length;
1740 port->COR2 |= COR2_ETC;
1741 port->IER |= IER_TXRDY;
1742 sx_out(bp, CD186x_CAR, port_No(port));
1743 sx_out(bp, CD186x_COR2, port->COR2);
1744 sx_out(bp, CD186x_IER, port->IER);
1746 sx_out(bp, CD186x_CCR, CCR_CORCHG2);
1748 restore_flags(flags);
1752 static inline int sx_set_serial_info(struct specialix_port * port,
1753 struct serial_struct __user * newinfo)
1755 struct serial_struct tmp;
1756 struct specialix_board *bp = port_Board(port);
1758 unsigned long flags;
1760 if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
1764 if ((tmp.irq != bp->irq) ||
1765 (tmp.port != bp->base) ||
1766 (tmp.type != PORT_CIRRUS) ||
1767 (tmp.baud_base != (SX_OSCFREQ + CD186x_TPC/2) / CD186x_TPC) ||
1768 (tmp.custom_divisor != 0) ||
1769 (tmp.xmit_fifo_size != CD186x_NFIFO) ||
1770 (tmp.flags & ~SPECIALIX_LEGAL_FLAGS))
1774 change_speed = ((port->flags & ASYNC_SPD_MASK) !=
1775 (tmp.flags & ASYNC_SPD_MASK));
1776 change_speed |= (tmp.custom_divisor != port->custom_divisor);
1778 if (!capable(CAP_SYS_ADMIN)) {
1779 if ((tmp.close_delay != port->close_delay) ||
1780 (tmp.closing_wait != port->closing_wait) ||
1781 ((tmp.flags & ~ASYNC_USR_MASK) !=
1782 (port->flags & ~ASYNC_USR_MASK)))
1784 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
1785 (tmp.flags & ASYNC_USR_MASK));
1786 port->custom_divisor = tmp.custom_divisor;
1788 port->flags = ((port->flags & ~ASYNC_FLAGS) |
1789 (tmp.flags & ASYNC_FLAGS));
1790 port->close_delay = tmp.close_delay;
1791 port->closing_wait = tmp.closing_wait;
1792 port->custom_divisor = tmp.custom_divisor;
1795 save_flags(flags); cli();
1796 sx_change_speed(bp, port);
1797 restore_flags(flags);
1803 static inline int sx_get_serial_info(struct specialix_port * port,
1804 struct serial_struct __user *retinfo)
1806 struct serial_struct tmp;
1807 struct specialix_board *bp = port_Board(port);
1809 memset(&tmp, 0, sizeof(tmp));
1810 tmp.type = PORT_CIRRUS;
1811 tmp.line = port - sx_port;
1812 tmp.port = bp->base;
1814 tmp.flags = port->flags;
1815 tmp.baud_base = (SX_OSCFREQ + CD186x_TPC/2) / CD186x_TPC;
1816 tmp.close_delay = port->close_delay * HZ/100;
1817 tmp.closing_wait = port->closing_wait * HZ/100;
1818 tmp.custom_divisor = port->custom_divisor;
1819 tmp.xmit_fifo_size = CD186x_NFIFO;
1820 if (copy_to_user(retinfo, &tmp, sizeof(tmp)))
1826 static int sx_ioctl(struct tty_struct * tty, struct file * filp,
1827 unsigned int cmd, unsigned long arg)
1829 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1831 void __user *argp = (void __user *)arg;
1833 if (sx_paranoia_check(port, tty->name, "sx_ioctl"))
1837 case TCSBRK: /* SVID version: non-zero arg --> no break */
1838 retval = tty_check_change(tty);
1841 tty_wait_until_sent(tty, 0);
1843 sx_send_break(port, HZ/4); /* 1/4 second */
1845 case TCSBRKP: /* support for POSIX tcsendbreak() */
1846 retval = tty_check_change(tty);
1849 tty_wait_until_sent(tty, 0);
1850 sx_send_break(port, arg ? arg*(HZ/10) : HZ/4);
1853 if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)argp))
1857 if (get_user(arg, (unsigned long __user *) argp))
1859 tty->termios->c_cflag =
1860 ((tty->termios->c_cflag & ~CLOCAL) |
1861 (arg ? CLOCAL : 0));
1864 return sx_get_serial_info(port, argp);
1866 return sx_set_serial_info(port, argp);
1868 return -ENOIOCTLCMD;
1874 static void sx_throttle(struct tty_struct * tty)
1876 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1877 struct specialix_board *bp;
1878 unsigned long flags;
1880 if (sx_paranoia_check(port, tty->name, "sx_throttle"))
1883 bp = port_Board(port);
1885 save_flags(flags); cli();
1887 /* Use DTR instead of RTS ! */
1888 if (SX_CRTSCTS (tty))
1889 port->MSVR &= ~MSVR_DTR;
1891 /* Auch!!! I think the system shouldn't call this then. */
1892 /* Or maybe we're supposed (allowed?) to do our side of hw
1893 handshake anyway, even when hardware handshake is off.
1894 When you see this in your logs, please report.... */
1895 printk (KERN_ERR "sx%d: Need to throttle, but can't (hardware hs is off)\n",
1898 sx_out(bp, CD186x_CAR, port_No(port));
1901 sx_out(bp, CD186x_CCR, CCR_SSCH2);
1904 sx_out(bp, CD186x_MSVR, port->MSVR);
1905 restore_flags(flags);
1909 static void sx_unthrottle(struct tty_struct * tty)
1911 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1912 struct specialix_board *bp;
1913 unsigned long flags;
1915 if (sx_paranoia_check(port, tty->name, "sx_unthrottle"))
1918 bp = port_Board(port);
1920 save_flags(flags); cli();
1921 /* XXXX Use DTR INSTEAD???? */
1922 if (SX_CRTSCTS(tty)) {
1923 port->MSVR |= MSVR_DTR;
1924 } /* Else clause: see remark in "sx_throttle"... */
1926 sx_out(bp, CD186x_CAR, port_No(port));
1929 sx_out(bp, CD186x_CCR, CCR_SSCH1);
1932 sx_out(bp, CD186x_MSVR, port->MSVR);
1933 restore_flags(flags);
1937 static void sx_stop(struct tty_struct * tty)
1939 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1940 struct specialix_board *bp;
1941 unsigned long flags;
1943 if (sx_paranoia_check(port, tty->name, "sx_stop"))
1946 bp = port_Board(port);
1948 save_flags(flags); cli();
1949 port->IER &= ~IER_TXRDY;
1950 sx_out(bp, CD186x_CAR, port_No(port));
1951 sx_out(bp, CD186x_IER, port->IER);
1952 restore_flags(flags);
1956 static void sx_start(struct tty_struct * tty)
1958 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1959 struct specialix_board *bp;
1960 unsigned long flags;
1962 if (sx_paranoia_check(port, tty->name, "sx_start"))
1965 bp = port_Board(port);
1967 save_flags(flags); cli();
1968 if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) {
1969 port->IER |= IER_TXRDY;
1970 sx_out(bp, CD186x_CAR, port_No(port));
1971 sx_out(bp, CD186x_IER, port->IER);
1973 restore_flags(flags);
1978 * This routine is called from the work-queue when the interrupt
1979 * routine has signalled that a hangup has occurred. The path of
1980 * hangup processing is:
1982 * serial interrupt routine -> (workqueue) ->
1983 * do_sx_hangup() -> tty->hangup() -> sx_hangup()
1986 static void do_sx_hangup(void *private_)
1988 struct specialix_port *port = (struct specialix_port *) private_;
1989 struct tty_struct *tty;
1993 tty_hangup(tty); /* FIXME: module removal race here */
1997 static void sx_hangup(struct tty_struct * tty)
1999 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2000 struct specialix_board *bp;
2002 if (sx_paranoia_check(port, tty->name, "sx_hangup"))
2005 bp = port_Board(port);
2007 sx_shutdown_port(bp, port);
2010 port->flags &= ~ASYNC_NORMAL_ACTIVE;
2012 wake_up_interruptible(&port->open_wait);
2016 static void sx_set_termios(struct tty_struct * tty, struct termios * old_termios)
2018 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2019 unsigned long flags;
2021 if (sx_paranoia_check(port, tty->name, "sx_set_termios"))
2024 if (tty->termios->c_cflag == old_termios->c_cflag &&
2025 tty->termios->c_iflag == old_termios->c_iflag)
2028 save_flags(flags); cli();
2029 sx_change_speed(port_Board(port), port);
2030 restore_flags(flags);
2032 if ((old_termios->c_cflag & CRTSCTS) &&
2033 !(tty->termios->c_cflag & CRTSCTS)) {
2034 tty->hw_stopped = 0;
2040 static void do_softint(void *private_)
2042 struct specialix_port *port = (struct specialix_port *) private_;
2043 struct tty_struct *tty;
2045 if(!(tty = port->tty))
2048 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event))
2052 static struct tty_operations sx_ops = {
2056 .put_char = sx_put_char,
2057 .flush_chars = sx_flush_chars,
2058 .write_room = sx_write_room,
2059 .chars_in_buffer = sx_chars_in_buffer,
2060 .flush_buffer = sx_flush_buffer,
2062 .throttle = sx_throttle,
2063 .unthrottle = sx_unthrottle,
2064 .set_termios = sx_set_termios,
2067 .hangup = sx_hangup,
2068 .tiocmget = sx_tiocmget,
2069 .tiocmset = sx_tiocmset,
2072 static int sx_init_drivers(void)
2077 specialix_driver = alloc_tty_driver(SX_NBOARD * SX_NPORT);
2078 if (!specialix_driver) {
2079 printk(KERN_ERR "sx: Couldn't allocate tty_driver.\n");
2083 if (!(tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL))) {
2084 printk(KERN_ERR "sx: Couldn't get free page.\n");
2085 put_tty_driver(specialix_driver);
2088 specialix_driver->owner = THIS_MODULE;
2089 specialix_driver->name = "ttyW";
2090 specialix_driver->major = SPECIALIX_NORMAL_MAJOR;
2091 specialix_driver->type = TTY_DRIVER_TYPE_SERIAL;
2092 specialix_driver->subtype = SERIAL_TYPE_NORMAL;
2093 specialix_driver->init_termios = tty_std_termios;
2094 specialix_driver->init_termios.c_cflag =
2095 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2096 specialix_driver->flags = TTY_DRIVER_REAL_RAW;
2097 tty_set_operations(specialix_driver, &sx_ops);
2099 if ((error = tty_register_driver(specialix_driver))) {
2100 put_tty_driver(specialix_driver);
2101 free_page((unsigned long)tmp_buf);
2102 printk(KERN_ERR "sx: Couldn't register specialix IO8+ driver, error = %d\n",
2106 memset(sx_port, 0, sizeof(sx_port));
2107 for (i = 0; i < SX_NPORT * SX_NBOARD; i++) {
2108 sx_port[i].magic = SPECIALIX_MAGIC;
2109 INIT_WORK(&sx_port[i].tqueue, do_softint, &sx_port[i]);
2110 INIT_WORK(&sx_port[i].tqueue_hangup, do_sx_hangup, &sx_port[i]);
2111 sx_port[i].close_delay = 50 * HZ/100;
2112 sx_port[i].closing_wait = 3000 * HZ/100;
2113 init_waitqueue_head(&sx_port[i].open_wait);
2114 init_waitqueue_head(&sx_port[i].close_wait);
2121 static void sx_release_drivers(void)
2123 free_page((unsigned long)tmp_buf);
2124 tty_unregister_driver(specialix_driver);
2125 put_tty_driver(specialix_driver);
2131 * Called at boot time.
2133 * You can specify IO base for up to SX_NBOARD cards,
2134 * using line "specialix=0xiobase1,0xiobase2,.." at LILO prompt.
2135 * Note that there will be no probing at default
2136 * addresses in this case.
2139 void specialix_setup(char *str, int * ints)
2143 for (i=0;i<SX_NBOARD;i++) {
2144 sx_board[i].base = 0;
2147 for (i = 1; i <= ints[0]; i++) {
2149 sx_board[i/2].base = ints[i];
2151 sx_board[i/2 -1].irq = ints[i];
2157 * This routine must be called by kernel at boot time
2159 static int __init specialix_init(void)
2164 printk(KERN_INFO "sx: Specialix IO8+ driver v" VERSION ", (c) R.E.Wolff 1997/1998.\n");
2165 printk(KERN_INFO "sx: derived from work (c) D.Gorodchanin 1994-1996.\n");
2166 #ifdef CONFIG_SPECIALIX_RTSCTS
2167 printk (KERN_INFO "sx: DTR/RTS pin is always RTS.\n");
2169 printk (KERN_INFO "sx: DTR/RTS pin is RTS when CRTSCTS is on.\n");
2172 if (sx_init_drivers())
2175 for (i = 0; i < SX_NBOARD; i++)
2176 if (sx_board[i].base && !sx_probe(&sx_board[i]))
2181 struct pci_dev *pdev = NULL;
2184 while (i < SX_NBOARD) {
2185 if (sx_board[i].flags & SX_BOARD_PRESENT) {
2189 pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX,
2190 PCI_DEVICE_ID_SPECIALIX_IO8,
2194 if (pci_enable_device(pdev))
2197 sx_board[i].irq = pdev->irq;
2199 sx_board[i].base = pci_resource_start (pdev, 2);
2201 sx_board[i].flags |= SX_BOARD_IS_PCI;
2202 if (!sx_probe(&sx_board[i]))
2209 sx_release_drivers();
2210 printk(KERN_INFO "sx: No specialix IO8+ boards detected.\n");
2217 int iobase[SX_NBOARD] = {0,};
2219 int irq [SX_NBOARD] = {0,};
2221 MODULE_PARM(iobase,"1-" __MODULE_STRING(SX_NBOARD) "i");
2222 MODULE_PARM(irq,"1-" __MODULE_STRING(SX_NBOARD) "i");
2225 * You can setup up to 4 boards.
2226 * by specifying "iobase=0xXXX,0xXXX ..." as insmod parameter.
2227 * You should specify the IRQs too in that case "irq=....,...".
2229 * More than 4 boards in one computer is not possible, as the card can
2230 * only use 4 different interrupts.
2233 static int __init specialix_init_module(void)
2237 if (iobase[0] || iobase[1] || iobase[2] || iobase[3]) {
2238 for(i = 0; i < SX_NBOARD; i++) {
2239 sx_board[i].base = iobase[i];
2240 sx_board[i].irq = irq[i];
2244 return specialix_init();
2247 static void __exit specialix_exit_module(void)
2251 sx_release_drivers();
2252 for (i = 0; i < SX_NBOARD; i++)
2253 if (sx_board[i].flags & SX_BOARD_PRESENT)
2254 sx_release_io_range(&sx_board[i]);
2255 #ifdef SPECIALIX_TIMER
2256 del_timer (&missed_irq_timer);
2261 module_init(specialix_init_module);
2262 module_exit(specialix_exit_module);
2264 MODULE_LICENSE("GPL");