1 /*****************************************************************************/
3 * mxser.c -- MOXA Smartio family multiport serial driver.
5 * Copyright (C) 1999-2000 Moxa Technologies (support@moxa.com.tw).
7 * This code is loosely based on the Linux serial driver, written by
8 * Linus Torvalds, Theodore T'so and others.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * MOXA Smartio Family Serial Driver
28 * Copyright (C) 1999,2000 Moxa Technologies Co., LTD.
30 * for : LINUX 2.0.X, 2.2.X
36 #include <linux/config.h>
37 #include <linux/module.h>
38 #include <linux/version.h>
39 #include <linux/errno.h>
40 #include <linux/signal.h>
41 #include <linux/sched.h>
42 #include <linux/timer.h>
43 #include <linux/interrupt.h>
44 #include <linux/tty.h>
45 #include <linux/tty_flip.h>
46 #include <linux/serial.h>
47 #include <linux/serial_reg.h>
48 #include <linux/major.h>
49 #include <linux/string.h>
50 #include <linux/fcntl.h>
51 #include <linux/ptrace.h>
52 #include <linux/ioport.h>
54 #include <linux/smp_lock.h>
55 #include <linux/pci.h>
57 #include <asm/system.h>
60 #include <asm/segment.h>
61 #include <asm/bitops.h>
62 #include <asm/uaccess.h>
64 #define MXSER_VERSION "1.1kern"
66 #define MXSERMAJOR 174
67 #define MXSERCUMAJOR 175
70 #define MXSER_EVENT_TXLOW 1
71 #define MXSER_EVENT_HANGUP 2
74 #define SERIAL_DO_RESTART
76 #define MXSER_BOARDS 4 /* Max. boards */
77 #define MXSER_PORTS 32 /* Max. ports */
78 #define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
79 #define MXSER_ISR_PASS_LIMIT 256
81 #define MXSER_ERR_IOADDR -1
82 #define MXSER_ERR_IRQ -2
83 #define MXSER_ERR_IRQ_CONFLIT -3
84 #define MXSER_ERR_VECTOR -4
86 #define SERIAL_TYPE_NORMAL 1
87 #define SERIAL_TYPE_CALLOUT 2
89 #define WAKEUP_CHARS 256
91 #define UART_MCR_AFE 0x20
92 #define UART_LSR_SPECIAL 0x1E
94 #define PORTNO(x) (MINOR((x)->device) - (x)->driver.minor_start)
96 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
98 #define IRQ_T(info) ((info->flags & ASYNC_SHARE_IRQ) ? SA_SHIRQ : SA_INTERRUPT)
101 #define MIN(a,b) ((a) < (b) ? (a) : (b))
105 * Define the Moxa PCI vendor and device IDs.
108 #ifndef PCI_VENDOR_ID_MOXA
109 #define PCI_VENDOR_ID_MOXA 0x1393
111 #ifndef PCI_DEVICE_ID_C168
112 #define PCI_DEVICE_ID_C168 0x1680
114 #ifndef PCI_DEVICE_ID_C104
115 #define PCI_DEVICE_ID_C104 0x1040
118 #define C168_ASIC_ID 1
119 #define C104_ASIC_ID 2
120 #define CI104J_ASIC_ID 5
123 MXSER_BOARD_C168_ISA
= 1,
124 MXSER_BOARD_C104_ISA
,
126 MXSER_BOARD_C168_PCI
,
127 MXSER_BOARD_C104_PCI
,
130 static char *mxser_brdname
[] =
139 static int mxser_numports
[] =
152 #define MOXA_GETDATACOUNT (MOXA + 23)
153 #define MOXA_GET_CONF (MOXA + 35)
154 #define MOXA_DIAGNOSE (MOXA + 50)
155 #define MOXA_CHKPORTENABLE (MOXA + 60)
156 #define MOXA_HighSpeedOn (MOXA + 61)
157 #define MOXA_GET_MAJOR (MOXA + 63)
158 #define MOXA_GET_CUMAJOR (MOXA + 64)
159 #define MOXA_GETMSTATUS (MOXA + 65)
162 unsigned short vendor_id
;
163 unsigned short device_id
;
164 unsigned short board_type
;
167 static mxser_pciinfo mxser_pcibrds
[] =
169 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_C168
, MXSER_BOARD_C168_PCI
},
170 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_C104
, MXSER_BOARD_C104_PCI
},
173 static int ioaddr
[MXSER_BOARDS
] = {0, 0, 0, 0};
174 static int ttymajor
= MXSERMAJOR
;
175 static int calloutmajor
= MXSERCUMAJOR
;
176 static int verbose
= 0;
178 /* Variables for insmod */
180 MODULE_AUTHOR("William Chen");
181 MODULE_DESCRIPTION("MOXA Smartio Family Multiport Board Device Driver");
182 MODULE_PARM(ioaddr
, "1-4i");
183 MODULE_PARM(ttymajor
, "i");
184 MODULE_PARM(calloutmajor
, "i");
185 MODULE_PARM(verbose
, "i");
187 struct mxser_hwconf
{
194 int ioaddr
[MXSER_PORTS_PER_BOARD
];
195 int baud_base
[MXSER_PORTS_PER_BOARD
];
196 struct pci_dev
*pdev
;
199 struct mxser_struct
{
201 int base
; /* port base address */
202 int irq
; /* port using irq no. */
203 int vector
; /* port irq vector */
204 int vectormask
; /* port vector mask */
205 int rx_trigger
; /* Rx fifo trigger level */
206 int baud_base
; /* max. speed */
207 int flags
; /* defined in tty.h */
208 int type
; /* UART type */
209 struct tty_struct
*tty
;
210 int read_status_mask
;
211 int ignore_status_mask
;
214 int x_char
; /* xon/xoff character */
216 unsigned short closing_wait
;
217 int IER
; /* Interrupt Enable Register */
218 int MCR
; /* Modem control register */
220 int count
; /* # of fd on device */
221 int blocked_open
; /* # of blocked opens */
222 long session
; /* Session of opening process */
223 long pgrp
; /* pgrp of opening process */
224 unsigned char *xmit_buf
;
228 struct tq_struct tqueue
;
229 struct termios normal_termios
;
230 struct termios callout_termios
;
231 wait_queue_head_t open_wait
;
232 wait_queue_head_t close_wait
;
233 wait_queue_head_t delta_msr_wait
;
234 struct async_icount icount
; /* kernel counters for the 4 input interrupts */
239 int rxcnt
[MXSER_PORTS
];
240 int txcnt
[MXSER_PORTS
];
243 struct mxser_mstatus
{
251 static struct mxser_mstatus GMStatus
[MXSER_PORTS
];
253 static int mxserBoardCAP
[MXSER_BOARDS
] =
256 /* 0x180, 0x280, 0x200, 0x320 */
260 static struct tty_driver mxvar_sdriver
, mxvar_cdriver
;
261 static int mxvar_refcount
;
262 static struct mxser_struct mxvar_table
[MXSER_PORTS
];
263 static struct tty_struct
*mxvar_tty
[MXSER_PORTS
+ 1];
264 static struct termios
*mxvar_termios
[MXSER_PORTS
+ 1];
265 static struct termios
*mxvar_termios_locked
[MXSER_PORTS
+ 1];
266 static struct mxser_log mxvar_log
;
267 static int mxvar_diagflag
;
269 * mxvar_tmp_buf is used as a temporary buffer by serial_write. We need
270 * to lock it in case the memcpy_fromfs blocks while swapping in a page,
271 * and some other program tries to do a serial write at the same time.
272 * Since the lock will only come under contention when the system is
273 * swapping and available memory is low, it makes sense to share one
274 * buffer across all the serial ports, since it significantly saves
275 * memory if large numbers of serial ports are open.
277 static unsigned char *mxvar_tmp_buf
= 0;
278 static struct semaphore mxvar_tmp_buf_sem
;
281 * This is used to figure out the divisor speeds and the timeouts
283 static int mxvar_baud_table
[] =
285 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
286 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600, 0};
288 struct mxser_hwconf mxsercfg
[MXSER_BOARDS
];
295 int init_module(void);
296 void cleanup_module(void);
299 static void mxser_getcfg(int board
, struct mxser_hwconf
*hwconf
);
300 int mxser_init(void);
301 static int mxser_get_ISA_conf(int, struct mxser_hwconf
*);
302 static int mxser_get_PCI_conf(struct pci_dev
*, int, struct mxser_hwconf
*);
303 static void mxser_do_softint(void *);
304 static int mxser_open(struct tty_struct
*, struct file
*);
305 static void mxser_close(struct tty_struct
*, struct file
*);
306 static int mxser_write(struct tty_struct
*, int, const unsigned char *, int);
307 static int mxser_write_room(struct tty_struct
*);
308 static void mxser_flush_buffer(struct tty_struct
*);
309 static int mxser_chars_in_buffer(struct tty_struct
*);
310 static void mxser_flush_chars(struct tty_struct
*);
311 static void mxser_put_char(struct tty_struct
*, unsigned char);
312 static int mxser_ioctl(struct tty_struct
*, struct file
*, uint
, ulong
);
313 static int mxser_ioctl_special(unsigned int, unsigned long);
314 static void mxser_throttle(struct tty_struct
*);
315 static void mxser_unthrottle(struct tty_struct
*);
316 static void mxser_set_termios(struct tty_struct
*, struct termios
*);
317 static void mxser_stop(struct tty_struct
*);
318 static void mxser_start(struct tty_struct
*);
319 static void mxser_hangup(struct tty_struct
*);
320 static void mxser_interrupt(int, void *, struct pt_regs
*);
321 static inline void mxser_receive_chars(struct mxser_struct
*, int *);
322 static inline void mxser_transmit_chars(struct mxser_struct
*);
323 static inline void mxser_check_modem_status(struct mxser_struct
*, int);
324 static int mxser_block_til_ready(struct tty_struct
*, struct file
*, struct mxser_struct
*);
325 static int mxser_startup(struct mxser_struct
*);
326 static void mxser_shutdown(struct mxser_struct
*);
327 static int mxser_change_speed(struct mxser_struct
*, struct termios
*old_termios
);
328 static int mxser_get_serial_info(struct mxser_struct
*, struct serial_struct
*);
329 static int mxser_set_serial_info(struct mxser_struct
*, struct serial_struct
*);
330 static int mxser_get_lsr_info(struct mxser_struct
*, unsigned int *);
331 static void mxser_send_break(struct mxser_struct
*, int);
332 static int mxser_get_modem_info(struct mxser_struct
*, unsigned int *);
333 static int mxser_set_modem_info(struct mxser_struct
*, unsigned int, unsigned int *);
336 * The MOXA C168/C104 serial driver boot-time initialization code!
341 int init_module(void)
346 printk("Loading module mxser ...\n");
353 void cleanup_module(void)
359 printk("Unloading module mxser ...\n");
360 if ((err
|= tty_unregister_driver(&mxvar_cdriver
)))
361 printk("Couldn't unregister MOXA Smartio family callout driver\n");
362 if ((err
|= tty_unregister_driver(&mxvar_sdriver
)))
363 printk("Couldn't unregister MOXA Smartio family serial driver\n");
365 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
366 if (mxsercfg
[i
].board_type
== -1)
369 free_irq(mxsercfg
[i
].irq
, &mxvar_table
[i
* MXSER_PORTS_PER_BOARD
]);
380 int mxser_initbrd(int board
, struct mxser_hwconf
*hwconf
)
382 struct mxser_struct
*info
;
387 init_MUTEX(&mxvar_tmp_buf_sem
);
389 n
= board
* MXSER_PORTS_PER_BOARD
;
390 info
= &mxvar_table
[n
];
391 for (i
= 0; i
< hwconf
->ports
; i
++, n
++, info
++) {
393 printk(" ttyM%d/cum%d at 0x%04x ", n
, n
, hwconf
->ioaddr
[i
]);
394 if (hwconf
->baud_base
[i
] == 115200)
395 printk(" max. baud rate up to 115200 bps.\n");
397 printk(" max. baud rate up to 921600 bps.\n");
400 info
->base
= hwconf
->ioaddr
[i
];
401 info
->irq
= hwconf
->irq
;
402 info
->vector
= hwconf
->vector
;
403 info
->vectormask
= hwconf
->vector_mask
;
404 info
->rx_trigger
= 14;
405 info
->baud_base
= hwconf
->baud_base
[i
];
406 info
->flags
= ASYNC_SHARE_IRQ
;
407 info
->type
= hwconf
->uart_type
;
408 if ((info
->type
== PORT_16450
) || (info
->type
== PORT_8250
))
409 info
->xmit_fifo_size
= 1;
411 info
->xmit_fifo_size
= 16;
412 info
->custom_divisor
= hwconf
->baud_base
[i
] * 16;
413 info
->close_delay
= 5 * HZ
/ 10;
414 info
->closing_wait
= 30 * HZ
;
415 info
->tqueue
.routine
= mxser_do_softint
;
416 info
->tqueue
.data
= info
;
417 info
->callout_termios
= mxvar_cdriver
.init_termios
;
418 info
->normal_termios
= mxvar_sdriver
.init_termios
;
419 init_waitqueue_head(&info
->open_wait
);
420 init_waitqueue_head(&info
->close_wait
);
421 init_waitqueue_head(&info
->delta_msr_wait
);
425 * Allocate the IRQ if necessary
429 n
= board
* MXSER_PORTS_PER_BOARD
;
430 info
= &mxvar_table
[n
];
433 retval
= request_irq(hwconf
->irq
, mxser_interrupt
, IRQ_T(info
),
436 restore_flags(flags
);
437 printk("Board %d: %s", board
, mxser_brdname
[hwconf
->board_type
- 1]);
438 printk(" Request irq fail,IRQ (%d) may be conflit with another device.\n", info
->irq
);
441 restore_flags(flags
);
447 static void mxser_getcfg(int board
, struct mxser_hwconf
*hwconf
)
449 mxsercfg
[board
] = *hwconf
;
452 static int mxser_get_PCI_conf(struct pci_dev
*pdev
, int board_type
, struct mxser_hwconf
*hwconf
)
455 unsigned int ioaddress
;
457 hwconf
->board_type
= board_type
;
458 hwconf
->ports
= mxser_numports
[board_type
- 1];
459 ioaddress
= pci_resource_start (pdev
, 2);
460 for (i
= 0; i
< hwconf
->ports
; i
++)
461 hwconf
->ioaddr
[i
] = ioaddress
+ 8 * i
;
463 ioaddress
= pci_resource_start (pdev
, 3);
464 hwconf
->vector
= ioaddress
;
466 hwconf
->irq
= pdev
->irq
;
468 hwconf
->uart_type
= PORT_16550A
;
469 hwconf
->vector_mask
= 0;
470 for (i
= 0; i
< hwconf
->ports
; i
++) {
471 hwconf
->vector_mask
|= (1 << i
);
472 hwconf
->baud_base
[i
] = 921600;
482 struct mxser_hwconf hwconf
;
484 printk("MOXA Smartio family driver version %s\n", MXSER_VERSION
);
486 /* Initialize the tty_driver structure */
488 memset(&mxvar_sdriver
, 0, sizeof(struct tty_driver
));
489 mxvar_sdriver
.magic
= TTY_DRIVER_MAGIC
;
490 mxvar_sdriver
.name
= "ttyM";
491 mxvar_sdriver
.major
= ttymajor
;
492 mxvar_sdriver
.minor_start
= 0;
493 mxvar_sdriver
.num
= MXSER_PORTS
+ 1;
494 mxvar_sdriver
.type
= TTY_DRIVER_TYPE_SERIAL
;
495 mxvar_sdriver
.subtype
= SERIAL_TYPE_NORMAL
;
496 mxvar_sdriver
.init_termios
= tty_std_termios
;
497 mxvar_sdriver
.init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
498 mxvar_sdriver
.flags
= TTY_DRIVER_REAL_RAW
;
499 mxvar_sdriver
.refcount
= &mxvar_refcount
;
500 mxvar_sdriver
.table
= mxvar_tty
;
501 mxvar_sdriver
.termios
= mxvar_termios
;
502 mxvar_sdriver
.termios_locked
= mxvar_termios_locked
;
504 mxvar_sdriver
.open
= mxser_open
;
505 mxvar_sdriver
.close
= mxser_close
;
506 mxvar_sdriver
.write
= mxser_write
;
507 mxvar_sdriver
.put_char
= mxser_put_char
;
508 mxvar_sdriver
.flush_chars
= mxser_flush_chars
;
509 mxvar_sdriver
.write_room
= mxser_write_room
;
510 mxvar_sdriver
.chars_in_buffer
= mxser_chars_in_buffer
;
511 mxvar_sdriver
.flush_buffer
= mxser_flush_buffer
;
512 mxvar_sdriver
.ioctl
= mxser_ioctl
;
513 mxvar_sdriver
.throttle
= mxser_throttle
;
514 mxvar_sdriver
.unthrottle
= mxser_unthrottle
;
515 mxvar_sdriver
.set_termios
= mxser_set_termios
;
516 mxvar_sdriver
.stop
= mxser_stop
;
517 mxvar_sdriver
.start
= mxser_start
;
518 mxvar_sdriver
.hangup
= mxser_hangup
;
521 * The callout device is just like normal device except for
522 * major number and the subtype code.
524 mxvar_cdriver
= mxvar_sdriver
;
525 mxvar_cdriver
.name
= "cum";
526 mxvar_cdriver
.major
= calloutmajor
;
527 mxvar_cdriver
.subtype
= SERIAL_TYPE_CALLOUT
;
529 printk("Tty devices major number = %d, callout devices major number = %d\n", ttymajor
, calloutmajor
);
532 memset(mxvar_table
, 0, MXSER_PORTS
* sizeof(struct mxser_struct
));
533 memset(&mxvar_log
, 0, sizeof(struct mxser_log
));
537 /* Start finding ISA boards here */
538 for (b
= 0; b
< MXSER_BOARDS
&& m
< MXSER_BOARDS
; b
++) {
540 if (!(cap
= mxserBoardCAP
[b
]))
543 retval
= mxser_get_ISA_conf(cap
, &hwconf
);
546 printk("Found MOXA %s board (CAP=0x%x)\n",
547 mxser_brdname
[hwconf
.board_type
- 1],
551 if (retval
== MXSER_ERR_IRQ
)
552 printk("Invalid interrupt number,board not configured\n");
553 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
554 printk("Invalid interrupt number,board not configured\n");
555 else if (retval
== MXSER_ERR_VECTOR
)
556 printk("Invalid interrupt vector,board not configured\n");
557 else if (retval
== MXSER_ERR_IOADDR
)
558 printk("Invalid I/O address,board not configured\n");
564 if (mxser_initbrd(m
, &hwconf
) < 0)
567 mxser_getcfg(m
, &hwconf
);
572 /* Start finding ISA boards from module arg */
573 for (b
= 0; b
< MXSER_BOARDS
&& m
< MXSER_BOARDS
; b
++) {
575 if (!(cap
= ioaddr
[b
]))
578 retval
= mxser_get_ISA_conf(cap
, &hwconf
);
581 printk("Found MOXA %s board (CAP=0x%x)\n",
582 mxser_brdname
[hwconf
.board_type
- 1],
586 if (retval
== MXSER_ERR_IRQ
)
587 printk("Invalid interrupt number,board not configured\n");
588 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
589 printk("Invalid interrupt number,board not configured\n");
590 else if (retval
== MXSER_ERR_VECTOR
)
591 printk("Invalid interrupt vector,board not configured\n");
592 else if (retval
== MXSER_ERR_IOADDR
)
593 printk("Invalid I/O address,board not configured\n");
599 if (mxser_initbrd(m
, &hwconf
) < 0)
602 mxser_getcfg(m
, &hwconf
);
607 /* start finding PCI board here */
611 struct pci_dev
*pdev
= NULL
;
613 n
= sizeof(mxser_pcibrds
) / sizeof(mxser_pciinfo
);
617 pdev
= pci_find_device(mxser_pcibrds
[b
].vendor_id
,
618 mxser_pcibrds
[b
].device_id
, pdev
);
621 if (pci_enable_device(pdev
))
625 printk("Found MOXA %s board(BusNo=%d,DevNo=%d)\n",
626 mxser_brdname
[mxser_pcibrds
[b
].board_type
- 1],
627 pdev
->bus
->number
, PCI_SLOT(pdev
->devfn
>> 3));
628 if (m
>= MXSER_BOARDS
) {
629 printk("Too many Smartio family boards find (maximum %d),board not configured\n", MXSER_BOARDS
);
631 retval
= mxser_get_PCI_conf(pdev
,
632 mxser_pcibrds
[b
].board_type
, &hwconf
);
634 if (retval
== MXSER_ERR_IRQ
)
635 printk("Invalid interrupt number,board not configured\n");
636 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
637 printk("Invalid interrupt number,board not configured\n");
638 else if (retval
== MXSER_ERR_VECTOR
)
639 printk("Invalid interrupt vector,board not configured\n");
640 else if (retval
== MXSER_ERR_IOADDR
)
641 printk("Invalid I/O address,board not configured\n");
645 if (mxser_initbrd(m
, &hwconf
) < 0)
647 mxser_getcfg(m
, &hwconf
);
656 for (i
= m
; i
< MXSER_BOARDS
; i
++) {
657 mxsercfg
[i
].board_type
= -1;
663 if (!(ret1
= tty_register_driver(&mxvar_sdriver
))) {
664 if (!(ret2
= tty_register_driver(&mxvar_cdriver
))) {
667 tty_unregister_driver(&mxvar_sdriver
);
668 printk("Couldn't install MOXA Smartio family callout driver !\n");
671 printk("Couldn't install MOXA Smartio family driver !\n");
675 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
676 if (mxsercfg
[i
].board_type
== -1)
679 free_irq(mxsercfg
[i
].irq
, &mxvar_table
[i
* MXSER_PORTS_PER_BOARD
]);
687 static void mxser_do_softint(void *private_
)
689 struct mxser_struct
*info
= (struct mxser_struct
*) private_
;
690 struct tty_struct
*tty
;
695 if (test_and_clear_bit(MXSER_EVENT_TXLOW
, &info
->event
)) {
696 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
697 tty
->ldisc
.write_wakeup
)
698 (tty
->ldisc
.write_wakeup
) (tty
);
699 wake_up_interruptible(&tty
->write_wait
);
701 if (test_and_clear_bit(MXSER_EVENT_HANGUP
, &info
->event
)) {
707 * This routine is called whenever a serial port is opened. It
708 * enables interrupts for a serial port, linking in its async structure into
709 * the IRQ chain. It also performs the serial-specific
710 * initialization for the tty structure.
713 static int mxser_open(struct tty_struct
*tty
, struct file
*filp
)
715 struct mxser_struct
*info
;
720 if (line
== MXSER_PORTS
)
722 if ((line
< 0) || (line
> MXSER_PORTS
))
724 info
= mxvar_table
+ line
;
729 tty
->driver_data
= info
;
732 if (!mxvar_tmp_buf
) {
733 page
= get_free_page(GFP_KERNEL
);
739 mxvar_tmp_buf
= (unsigned char *) page
;
742 * Start up serial port
744 retval
= mxser_startup(info
);
748 retval
= mxser_block_til_ready(tty
, filp
, info
);
752 if ((info
->count
== 1) && (info
->flags
& ASYNC_SPLIT_TERMIOS
)) {
753 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
754 *tty
->termios
= info
->normal_termios
;
756 *tty
->termios
= info
->callout_termios
;
757 mxser_change_speed(info
, 0);
759 info
->session
= current
->session
;
760 info
->pgrp
= current
->pgrp
;
768 * This routine is called when the serial port gets closed. First, we
769 * wait for the last remaining data to be sent. Then, we unlink its
770 * async structure from the interrupt chain if necessary, and we free
771 * that IRQ if nothing is left in the chain.
774 static void mxser_close(struct tty_struct
*tty
, struct file
*filp
)
776 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
778 unsigned long timeout
;
780 if (PORTNO(tty
) == MXSER_PORTS
)
788 if (tty_hung_up_p(filp
)) {
789 restore_flags(flags
);
793 if ((tty
->count
== 1) && (info
->count
!= 1)) {
795 * Uh, oh. tty->count is 1, which means that the tty
796 * structure will be freed. Info->count should always
797 * be one in these conditions. If it's greater than
798 * one, we've got real problems, since it means the
799 * serial port won't be shutdown.
801 printk("mxser_close: bad serial port count; tty->count is 1, "
802 "info->count is %d\n", info
->count
);
805 if (--info
->count
< 0) {
806 printk("mxser_close: bad serial port count for ttys%d: %d\n",
807 info
->port
, info
->count
);
811 restore_flags(flags
);
815 info
->flags
|= ASYNC_CLOSING
;
817 * Save the termios structure, since this port may have
818 * separate termios for callout and dialin.
820 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
821 info
->normal_termios
= *tty
->termios
;
822 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
823 info
->callout_termios
= *tty
->termios
;
825 * Now we wait for the transmit buffer to clear; and we notify
826 * the line discipline to only process XON/XOFF characters.
829 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
830 tty_wait_until_sent(tty
, info
->closing_wait
);
832 * At this point we stop accepting input. To do this, we
833 * disable the receive line status interrupts, and tell the
834 * interrupt driver to stop checking the data ready bit in the
835 * line status register.
837 info
->IER
&= ~UART_IER_RLSI
;
839 info->read_status_mask &= ~UART_LSR_DR;
841 if (info
->flags
& ASYNC_INITIALIZED
) {
842 outb(info
->IER
, info
->base
+ UART_IER
);
844 * Before we drop DTR, make sure the UART transmitter
845 * has completely drained; this is especially
846 * important if there is a transmit FIFO!
848 timeout
= jiffies
+ HZ
;
849 while (!(inb(info
->base
+ UART_LSR
) & UART_LSR_TEMT
)) {
850 current
->state
= TASK_INTERRUPTIBLE
;
852 if (jiffies
> timeout
)
856 mxser_shutdown(info
);
857 if (tty
->driver
.flush_buffer
)
858 tty
->driver
.flush_buffer(tty
);
859 if (tty
->ldisc
.flush_buffer
)
860 tty
->ldisc
.flush_buffer(tty
);
864 if (info
->blocked_open
) {
865 if (info
->close_delay
) {
866 current
->state
= TASK_INTERRUPTIBLE
;
867 schedule_timeout(info
->close_delay
);
869 wake_up_interruptible(&info
->open_wait
);
871 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CALLOUT_ACTIVE
|
873 wake_up_interruptible(&info
->close_wait
);
874 restore_flags(flags
);
879 static int mxser_write(struct tty_struct
*tty
, int from_user
,
880 const unsigned char *buf
, int count
)
883 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
886 if (!tty
|| !info
->xmit_buf
|| !mxvar_tmp_buf
)
890 down(&mxvar_tmp_buf_sem
);
894 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
895 SERIAL_XMIT_SIZE
- info
->xmit_head
));
900 copy_from_user(mxvar_tmp_buf
, buf
, c
);
901 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
902 SERIAL_XMIT_SIZE
- info
->xmit_head
));
903 memcpy(info
->xmit_buf
+ info
->xmit_head
, mxvar_tmp_buf
, c
);
905 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
906 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
- 1);
908 restore_flags(flags
);
914 up(&mxvar_tmp_buf_sem
);
915 if (info
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
&&
916 !(info
->IER
& UART_IER_THRI
)) {
917 info
->IER
|= UART_IER_THRI
;
918 outb(info
->IER
, info
->base
+ UART_IER
);
920 restore_flags(flags
);
924 static void mxser_put_char(struct tty_struct
*tty
, unsigned char ch
)
926 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
929 if (!tty
|| !info
->xmit_buf
)
934 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
935 restore_flags(flags
);
938 info
->xmit_buf
[info
->xmit_head
++] = ch
;
939 info
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
941 /********************************************** why ??? ***********
942 if ( !tty->stopped && !tty->hw_stopped &&
943 !(info->IER & UART_IER_THRI) ) {
944 info->IER |= UART_IER_THRI;
945 outb(info->IER, info->base + UART_IER);
947 *****************************************************************/
948 restore_flags(flags
);
951 static void mxser_flush_chars(struct tty_struct
*tty
)
953 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
956 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
962 info
->IER
|= UART_IER_THRI
;
963 outb(info
->IER
, info
->base
+ UART_IER
);
964 restore_flags(flags
);
967 static int mxser_write_room(struct tty_struct
*tty
)
969 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
972 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
978 static int mxser_chars_in_buffer(struct tty_struct
*tty
)
980 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
982 return (info
->xmit_cnt
);
985 static void mxser_flush_buffer(struct tty_struct
*tty
)
987 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
992 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
993 restore_flags(flags
);
994 wake_up_interruptible(&tty
->write_wait
);
995 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
996 tty
->ldisc
.write_wakeup
)
997 (tty
->ldisc
.write_wakeup
) (tty
);
1000 static int mxser_ioctl(struct tty_struct
*tty
, struct file
*file
,
1001 unsigned int cmd
, unsigned long arg
)
1003 unsigned long flags
;
1004 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1006 struct async_icount cprev
, cnow
; /* kernel counter temps */
1007 struct serial_icounter_struct
*p_cuser
; /* user space */
1008 unsigned long templ
;
1010 if (PORTNO(tty
) == MXSER_PORTS
)
1011 return (mxser_ioctl_special(cmd
, arg
));
1012 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCMIWAIT
) &&
1013 (cmd
!= TIOCGICOUNT
)) {
1014 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1018 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1019 retval
= tty_check_change(tty
);
1022 tty_wait_until_sent(tty
, 0);
1024 mxser_send_break(info
, HZ
/ 4); /* 1/4 second */
1026 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1027 retval
= tty_check_change(tty
);
1030 tty_wait_until_sent(tty
, 0);
1031 mxser_send_break(info
, arg
? arg
* (HZ
/ 10) : HZ
/ 4);
1034 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long *) arg
);
1036 if(get_user(templ
, (unsigned long *) arg
))
1039 tty
->termios
->c_cflag
= ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1040 (arg
? CLOCAL
: 0));
1043 return (mxser_get_modem_info(info
, (unsigned int *) arg
));
1047 return (mxser_set_modem_info(info
, cmd
, (unsigned int *) arg
));
1049 return (mxser_get_serial_info(info
, (struct serial_struct
*) arg
));
1051 return (mxser_set_serial_info(info
, (struct serial_struct
*) arg
));
1052 case TIOCSERGETLSR
: /* Get line status register */
1053 return (mxser_get_lsr_info(info
, (unsigned int *) arg
));
1055 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1056 * - mask passed in arg for lines of interest
1057 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1058 * Caller should use TIOCGICOUNT to see which one it was
1063 cprev
= info
->icount
; /* note the counters on entry */
1064 restore_flags(flags
);
1066 interruptible_sleep_on(&info
->delta_msr_wait
);
1067 /* see if a signal did it */
1068 if (signal_pending(current
))
1069 return (-ERESTARTSYS
);
1072 cnow
= info
->icount
; /* atomic copy */
1073 restore_flags(flags
);
1074 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
1075 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
1076 return (-EIO
); /* no change => error */
1077 if (((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
1078 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
1079 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
1080 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
))) {
1087 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1088 * Return: write counters to the user passed counter struct
1089 * NB: both 1->0 and 0->1 transitions are counted except for
1090 * RI where only 0->1 is counted.
1095 cnow
= info
->icount
;
1096 restore_flags(flags
);
1097 p_cuser
= (struct serial_icounter_struct
*) arg
;
1098 if(put_user(cnow
.cts
, &p_cuser
->cts
))
1100 if(put_user(cnow
.dsr
, &p_cuser
->dsr
))
1102 if(put_user(cnow
.rng
, &p_cuser
->rng
))
1104 return put_user(cnow
.dcd
, &p_cuser
->dcd
);
1105 case MOXA_HighSpeedOn
:
1106 return put_user(info
->baud_base
!= 115200 ? 1 : 0, (int *) arg
);
1108 return (-ENOIOCTLCMD
);
1113 static int mxser_ioctl_special(unsigned int cmd
, unsigned long arg
)
1115 int i
, result
, status
;
1119 if(copy_to_user((struct mxser_hwconf
*) arg
, mxsercfg
,
1120 sizeof(struct mxser_hwconf
) * 4))
1123 case MOXA_GET_MAJOR
:
1124 if(copy_to_user((int *) arg
, &ttymajor
, sizeof(int)))
1128 case MOXA_GET_CUMAJOR
:
1129 if(copy_to_user((int *) arg
, &calloutmajor
, sizeof(int)))
1133 case MOXA_CHKPORTENABLE
:
1135 for (i
= 0; i
< MXSER_PORTS
; i
++) {
1136 if (mxvar_table
[i
].base
)
1139 return put_user(result
, (unsigned long *) arg
);
1140 case MOXA_GETDATACOUNT
:
1141 if(copy_to_user((struct mxser_log
*) arg
, &mxvar_log
, sizeof(mxvar_log
)))
1144 case MOXA_GETMSTATUS
:
1145 for (i
= 0; i
< MXSER_PORTS
; i
++) {
1147 if (!mxvar_table
[i
].base
) {
1148 GMStatus
[i
].dcd
= 0;
1149 GMStatus
[i
].dsr
= 0;
1150 GMStatus
[i
].cts
= 0;
1153 if (!mxvar_table
[i
].tty
|| !mxvar_table
[i
].tty
->termios
)
1154 GMStatus
[i
].cflag
= mxvar_table
[i
].normal_termios
.c_cflag
;
1156 GMStatus
[i
].cflag
= mxvar_table
[i
].tty
->termios
->c_cflag
;
1158 status
= inb(mxvar_table
[i
].base
+ UART_MSR
);
1159 if (status
& 0x80 /*UART_MSR_DCD */ )
1160 GMStatus
[i
].dcd
= 1;
1162 GMStatus
[i
].dcd
= 0;
1164 if (status
& 0x20 /*UART_MSR_DSR */ )
1165 GMStatus
[i
].dsr
= 1;
1167 GMStatus
[i
].dsr
= 0;
1170 if (status
& 0x10 /*UART_MSR_CTS */ )
1171 GMStatus
[i
].cts
= 1;
1173 GMStatus
[i
].cts
= 0;
1175 if(copy_to_user((struct mxser_mstatus
*) arg
, GMStatus
,
1176 sizeof(struct mxser_mstatus
) * MXSER_PORTS
))
1180 return (-ENOIOCTLCMD
);
1186 * This routine is called by the upper-layer tty layer to signal that
1187 * incoming characters should be throttled.
1189 static void mxser_throttle(struct tty_struct
*tty
)
1191 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1192 unsigned long flags
;
1195 info
->x_char
= STOP_CHAR(tty
);
1199 info
->IER
|= UART_IER_THRI
;
1200 outb(info
->IER
, info
->base
+ UART_IER
); /* force Tx interrupt */
1201 restore_flags(flags
);
1203 if (info
->tty
->termios
->c_cflag
& CRTSCTS
) {
1204 info
->MCR
&= ~UART_MCR_RTS
;
1207 outb(info
->MCR
, info
->base
+ UART_MCR
);
1208 restore_flags(flags
);
1212 static void mxser_unthrottle(struct tty_struct
*tty
)
1214 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1215 unsigned long flags
;
1221 info
->x_char
= START_CHAR(tty
);
1225 info
->IER
|= UART_IER_THRI
; /* force Tx interrupt */
1226 outb(info
->IER
, info
->base
+ UART_IER
);
1227 restore_flags(flags
);
1230 if (info
->tty
->termios
->c_cflag
& CRTSCTS
) {
1231 info
->MCR
|= UART_MCR_RTS
;
1234 outb(info
->MCR
, info
->base
+ UART_MCR
);
1235 restore_flags(flags
);
1239 static void mxser_set_termios(struct tty_struct
*tty
,
1240 struct termios
*old_termios
)
1242 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1244 /* 8-2-99 by William
1245 if ( (tty->termios->c_cflag == old_termios->c_cflag) &&
1246 (RELEVANT_IFLAG(tty->termios->c_iflag) ==
1247 RELEVANT_IFLAG(old_termios->c_iflag)) )
1250 mxser_change_speed(info, old_termios);
1252 if ( (old_termios->c_cflag & CRTSCTS) &&
1253 !(tty->termios->c_cflag & CRTSCTS) ) {
1254 tty->hw_stopped = 0;
1258 if ((tty
->termios
->c_cflag
!= old_termios
->c_cflag
) ||
1259 (RELEVANT_IFLAG(tty
->termios
->c_iflag
) !=
1260 RELEVANT_IFLAG(old_termios
->c_iflag
))) {
1262 mxser_change_speed(info
, old_termios
);
1264 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1265 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1266 tty
->hw_stopped
= 0;
1270 /* Handle sw stopped */
1271 if ((old_termios
->c_iflag
& IXON
) &&
1272 !(tty
->termios
->c_iflag
& IXON
)) {
1279 * mxser_stop() and mxser_start()
1281 * This routines are called before setting or resetting tty->stopped.
1282 * They enable or disable transmitter interrupts, as necessary.
1284 static void mxser_stop(struct tty_struct
*tty
)
1286 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1287 unsigned long flags
;
1291 if (info
->IER
& UART_IER_THRI
) {
1292 info
->IER
&= ~UART_IER_THRI
;
1293 outb(info
->IER
, info
->base
+ UART_IER
);
1295 restore_flags(flags
);
1298 static void mxser_start(struct tty_struct
*tty
)
1300 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1301 unsigned long flags
;
1305 if (info
->xmit_cnt
&& info
->xmit_buf
&&
1306 !(info
->IER
& UART_IER_THRI
)) {
1307 info
->IER
|= UART_IER_THRI
;
1308 outb(info
->IER
, info
->base
+ UART_IER
);
1310 restore_flags(flags
);
1314 * This routine is called by tty_hangup() when a hangup is signaled.
1316 void mxser_hangup(struct tty_struct
*tty
)
1318 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1320 mxser_flush_buffer(tty
);
1321 mxser_shutdown(info
);
1324 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CALLOUT_ACTIVE
);
1326 wake_up_interruptible(&info
->open_wait
);
1330 * This is the serial driver's generic interrupt routine
1332 static void mxser_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1335 struct mxser_struct
*info
;
1336 struct mxser_struct
*port
;
1337 int max
, irqbits
, bits
, msr
;
1338 int pass_counter
= 0;
1341 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
1342 if (dev_id
== &(mxvar_table
[i
* MXSER_PORTS_PER_BOARD
])) {
1348 if (i
== MXSER_BOARDS
)
1352 max
= mxser_numports
[mxsercfg
[i
].board_type
- 1];
1355 irqbits
= inb(port
->vector
) & port
->vectormask
;
1356 if (irqbits
== port
->vectormask
)
1358 for (i
= 0, bits
= 1; i
< max
; i
++, irqbits
|= bits
, bits
<<= 1) {
1359 if (irqbits
== port
->vectormask
)
1365 (inb(info
->base
+ UART_IIR
) & UART_IIR_NO_INT
))
1367 status
= inb(info
->base
+ UART_LSR
) & info
->read_status_mask
;
1368 if (status
& UART_LSR_DR
)
1369 mxser_receive_chars(info
, &status
);
1370 msr
= inb(info
->base
+ UART_MSR
);
1371 if (msr
& UART_MSR_ANY_DELTA
)
1372 mxser_check_modem_status(info
, msr
);
1373 if (status
& UART_LSR_THRE
) {
1374 /* 8-2-99 by William
1375 if ( info->x_char || (info->xmit_cnt > 0) )
1377 mxser_transmit_chars(info
);
1380 if (pass_counter
++ > MXSER_ISR_PASS_LIMIT
) {
1382 printk("MOXA Smartio/Indusrtio family driver interrupt loop break\n");
1384 break; /* Prevent infinite loops */
1389 static inline void mxser_receive_chars(struct mxser_struct
*info
,
1392 struct tty_struct
*tty
= info
->tty
;
1398 ch
= inb(info
->base
+ UART_RX
);
1399 if (*status
& info
->ignore_status_mask
) {
1400 if (++ignored
> 100)
1403 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
1406 if (*status
& UART_LSR_SPECIAL
) {
1407 if (*status
& UART_LSR_BI
) {
1408 *tty
->flip
.flag_buf_ptr
++ = TTY_BREAK
;
1409 if (info
->flags
& ASYNC_SAK
)
1411 } else if (*status
& UART_LSR_PE
) {
1412 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
1413 } else if (*status
& UART_LSR_FE
) {
1414 *tty
->flip
.flag_buf_ptr
++ = TTY_FRAME
;
1415 } else if (*status
& UART_LSR_OE
) {
1416 *tty
->flip
.flag_buf_ptr
++ = TTY_OVERRUN
;
1418 *tty
->flip
.flag_buf_ptr
++ = 0;
1420 *tty
->flip
.flag_buf_ptr
++ = 0;
1421 *tty
->flip
.char_buf_ptr
++ = ch
;
1424 *status
= inb(info
->base
+ UART_LSR
) & info
->read_status_mask
;
1425 } while (*status
& UART_LSR_DR
);
1426 mxvar_log
.rxcnt
[info
->port
] += cnt
;
1427 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
1431 static inline void mxser_transmit_chars(struct mxser_struct
*info
)
1436 outb(info
->x_char
, info
->base
+ UART_TX
);
1438 mxvar_log
.txcnt
[info
->port
]++;
1441 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
||
1442 info
->tty
->hw_stopped
) {
1443 info
->IER
&= ~UART_IER_THRI
;
1444 outb(info
->IER
, info
->base
+ UART_IER
);
1447 cnt
= info
->xmit_cnt
;
1448 count
= info
->xmit_fifo_size
;
1450 outb(info
->xmit_buf
[info
->xmit_tail
++], info
->base
+ UART_TX
);
1451 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
- 1);
1452 if (--info
->xmit_cnt
<= 0)
1454 } while (--count
> 0);
1455 mxvar_log
.txcnt
[info
->port
] += (cnt
- info
->xmit_cnt
);
1457 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
1458 set_bit(MXSER_EVENT_TXLOW
, &info
->event
);
1459 queue_task(&info
->tqueue
, &tq_scheduler
);
1461 if (info
->xmit_cnt
<= 0) {
1462 info
->IER
&= ~UART_IER_THRI
;
1463 outb(info
->IER
, info
->base
+ UART_IER
);
1467 static inline void mxser_check_modem_status(struct mxser_struct
*info
,
1471 /* update input line counters */
1472 if (status
& UART_MSR_TERI
)
1474 if (status
& UART_MSR_DDSR
)
1476 if (status
& UART_MSR_DDCD
)
1478 if (status
& UART_MSR_DCTS
)
1480 wake_up_interruptible(&info
->delta_msr_wait
);
1482 if ((info
->flags
& ASYNC_CHECK_CD
) && (status
& UART_MSR_DDCD
)) {
1483 if (status
& UART_MSR_DCD
)
1484 wake_up_interruptible(&info
->open_wait
);
1485 else if (!((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1486 (info
->flags
& ASYNC_CALLOUT_NOHUP
)))
1487 set_bit(MXSER_EVENT_HANGUP
, &info
->event
);
1488 queue_task(&info
->tqueue
, &tq_scheduler
);
1491 if (info
->flags
& ASYNC_CTS_FLOW
) {
1492 if (info
->tty
->hw_stopped
) {
1493 if (status
& UART_MSR_CTS
) {
1494 info
->tty
->hw_stopped
= 0;
1495 info
->IER
|= UART_IER_THRI
;
1496 outb(info
->IER
, info
->base
+ UART_IER
);
1498 set_bit(MXSER_EVENT_TXLOW
, &info
->event
);
1499 queue_task(&info
->tqueue
, &tq_scheduler
);
1502 if (!(status
& UART_MSR_CTS
)) {
1503 info
->tty
->hw_stopped
= 1;
1504 info
->IER
&= ~UART_IER_THRI
;
1505 outb(info
->IER
, info
->base
+ UART_IER
);
1511 static int mxser_block_til_ready(struct tty_struct
*tty
, struct file
*filp
,
1512 struct mxser_struct
*info
)
1514 DECLARE_WAITQUEUE(wait
, current
);
1515 unsigned long flags
;
1520 * If the device is in the middle of being closed, then block
1521 * until it's done, and then try again.
1523 if (tty_hung_up_p(filp
) || (info
->flags
& ASYNC_CLOSING
)) {
1524 if (info
->flags
& ASYNC_CLOSING
)
1525 interruptible_sleep_on(&info
->close_wait
);
1526 #ifdef SERIAL_DO_RESTART
1527 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1530 return (-ERESTARTSYS
);
1536 * If this is a callout device, then just make sure the normal
1537 * device isn't being used.
1539 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
1540 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1542 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1543 (info
->flags
& ASYNC_SESSION_LOCKOUT
) &&
1544 (info
->session
!= current
->session
))
1546 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1547 (info
->flags
& ASYNC_PGRP_LOCKOUT
) &&
1548 (info
->pgrp
!= current
->pgrp
))
1550 info
->flags
|= ASYNC_CALLOUT_ACTIVE
;
1554 * If non-blocking mode is set, or the port is not enabled,
1555 * then make the check up front and then exit.
1557 if ((filp
->f_flags
& O_NONBLOCK
) ||
1558 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1559 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
1561 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1564 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
) {
1565 if (info
->normal_termios
.c_cflag
& CLOCAL
)
1568 if (tty
->termios
->c_cflag
& CLOCAL
)
1573 * Block waiting for the carrier detect and the line to become
1574 * free (i.e., not in use by the callout). While we are in
1575 * this loop, info->count is dropped by one, so that
1576 * mxser_close() knows when to free things. We restore it upon
1577 * exit, either normal or abnormal.
1580 add_wait_queue(&info
->open_wait
, &wait
);
1583 if (!tty_hung_up_p(filp
))
1585 restore_flags(flags
);
1586 info
->blocked_open
++;
1590 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
))
1591 outb(inb(info
->base
+ UART_MCR
) | UART_MCR_DTR
| UART_MCR_RTS
,
1592 info
->base
+ UART_MCR
);
1593 restore_flags(flags
);
1594 current
->state
= TASK_INTERRUPTIBLE
;
1595 if (tty_hung_up_p(filp
) || !(info
->flags
& ASYNC_INITIALIZED
)) {
1596 #ifdef SERIAL_DO_RESTART
1597 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1600 retval
= -ERESTARTSYS
;
1606 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1607 !(info
->flags
& ASYNC_CLOSING
) &&
1608 (do_clocal
|| (inb(info
->base
+ UART_MSR
) & UART_MSR_DCD
)))
1610 if (signal_pending(current
)) {
1611 retval
= -ERESTARTSYS
;
1616 current
->state
= TASK_RUNNING
;
1617 remove_wait_queue(&info
->open_wait
, &wait
);
1618 if (!tty_hung_up_p(filp
))
1620 info
->blocked_open
--;
1623 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1627 static int mxser_startup(struct mxser_struct
*info
)
1629 unsigned long flags
;
1632 page
= get_free_page(GFP_KERNEL
);
1639 if (info
->flags
& ASYNC_INITIALIZED
) {
1641 restore_flags(flags
);
1644 if (!info
->base
|| !info
->type
) {
1646 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1648 restore_flags(flags
);
1654 info
->xmit_buf
= (unsigned char *) page
;
1657 * Clear the FIFO buffers and disable them
1658 * (they will be reenabled in mxser_change_speed())
1660 if (info
->xmit_fifo_size
== 16)
1661 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
),
1662 info
->base
+ UART_FCR
);
1665 * At this point there's no way the LSR could still be 0xFF;
1666 * if it is, then bail out, because there's likely no UART
1669 if (inb(info
->base
+ UART_LSR
) == 0xff) {
1670 restore_flags(flags
);
1673 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1679 * Clear the interrupt registers.
1681 (void) inb(info
->base
+ UART_LSR
);
1682 (void) inb(info
->base
+ UART_RX
);
1683 (void) inb(info
->base
+ UART_IIR
);
1684 (void) inb(info
->base
+ UART_MSR
);
1687 * Now, initialize the UART
1689 outb(UART_LCR_WLEN8
, info
->base
+ UART_LCR
); /* reset DLAB */
1690 info
->MCR
= UART_MCR_DTR
| UART_MCR_RTS
;
1691 outb(info
->MCR
, info
->base
+ UART_MCR
);
1694 * Finally, enable interrupts
1696 info
->IER
= UART_IER_MSI
| UART_IER_RLSI
| UART_IER_RDI
;
1697 outb(info
->IER
, info
->base
+ UART_IER
); /* enable interrupts */
1700 * And clear the interrupt registers again for luck.
1702 (void) inb(info
->base
+ UART_LSR
);
1703 (void) inb(info
->base
+ UART_RX
);
1704 (void) inb(info
->base
+ UART_IIR
);
1705 (void) inb(info
->base
+ UART_MSR
);
1708 test_and_clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1710 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1713 * and set the speed of the serial port
1715 mxser_change_speed(info
, 0);
1717 info
->flags
|= ASYNC_INITIALIZED
;
1718 restore_flags(flags
);
1723 * This routine will shutdown a serial port; interrupts maybe disabled, and
1724 * DTR is dropped if the hangup on close termio flag is on.
1726 static void mxser_shutdown(struct mxser_struct
*info
)
1728 unsigned long flags
;
1730 if (!(info
->flags
& ASYNC_INITIALIZED
))
1734 cli(); /* Disable interrupts */
1737 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
1738 * here so the queue might never be waken up
1740 wake_up_interruptible(&info
->delta_msr_wait
);
1743 * Free the IRQ, if necessary
1745 if (info
->xmit_buf
) {
1746 free_page((unsigned long) info
->xmit_buf
);
1750 outb(0x00, info
->base
+ UART_IER
); /* disable all intrs */
1752 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
))
1753 info
->MCR
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
1754 outb(info
->MCR
, info
->base
+ UART_MCR
);
1756 /* clear Rx/Tx FIFO's */
1757 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
), info
->base
+ UART_FCR
);
1758 /* read data port to reset things */
1759 (void) inb(info
->base
+ UART_RX
);
1762 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1764 info
->flags
&= ~ASYNC_INITIALIZED
;
1765 restore_flags(flags
);
1769 * This routine is called to set the UART divisor registers to match
1770 * the specified baud rate for a serial port.
1772 static int mxser_change_speed(struct mxser_struct
*info
,
1773 struct termios
*old_termios
)
1776 unsigned cflag
, cval
, fcr
;
1779 unsigned long flags
;
1781 if (!info
->tty
|| !info
->tty
->termios
)
1783 cflag
= info
->tty
->termios
->c_cflag
;
1788 #define B921600 (B460800 +1)
1790 switch (cflag
& (CBAUD
| CBAUDEX
)) {
1857 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
1858 i
= 16; /* 57600 bps */
1859 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
1860 i
= 17; /* 115200 bps */
1862 #ifdef ASYNC_SPD_SHI
1863 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
1867 #ifdef ASYNC_SPD_WARP
1868 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
1872 if (mxvar_baud_table
[i
] == 134) {
1873 quot
= (2 * info
->baud_base
/ 269);
1874 } else if (mxvar_baud_table
[i
]) {
1875 quot
= info
->baud_base
/ mxvar_baud_table
[i
];
1876 if (!quot
&& old_termios
) {
1878 info
->tty
->termios
->c_cflag
&= ~CBAUD
;
1879 info
->tty
->termios
->c_cflag
|= (old_termios
->c_cflag
& CBAUD
);
1880 switch (info
->tty
->termios
->c_cflag
& (CBAUD
| CBAUDEX
)) {
1946 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
1947 i
= 16; /* 57600 bps */
1948 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
1949 i
= 17; /* 115200 bps */
1950 #ifdef ASYNC_SPD_SHI
1951 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
1954 #ifdef ASYNC_SPD_WARP
1955 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
1959 if (mxvar_baud_table
[i
] == 134) {
1960 quot
= (2 * info
->baud_base
/ 269);
1961 } else if (mxvar_baud_table
[i
]) {
1962 quot
= info
->baud_base
/ mxvar_baud_table
[i
];
1968 } else if (quot
== 0)
1975 info
->MCR
|= UART_MCR_DTR
;
1978 outb(info
->MCR
, info
->base
+ UART_MCR
);
1979 restore_flags(flags
);
1981 info
->MCR
&= ~UART_MCR_DTR
;
1984 outb(info
->MCR
, info
->base
+ UART_MCR
);
1985 restore_flags(flags
);
1988 /* byte size and parity */
1989 switch (cflag
& CSIZE
) {
2004 break; /* too keep GCC shut... */
2009 cval
|= UART_LCR_PARITY
;
2010 if (!(cflag
& PARODD
))
2011 cval
|= UART_LCR_EPAR
;
2012 if ((info
->type
== PORT_8250
) || (info
->type
== PORT_16450
)) {
2015 fcr
= UART_FCR_ENABLE_FIFO
;
2016 switch (info
->rx_trigger
) {
2018 fcr
|= UART_FCR_TRIGGER_1
;
2021 fcr
|= UART_FCR_TRIGGER_4
;
2024 fcr
|= UART_FCR_TRIGGER_8
;
2027 fcr
|= UART_FCR_TRIGGER_14
;
2031 /* CTS flow control flag and modem status interrupts */
2032 info
->IER
&= ~UART_IER_MSI
;
2033 info
->MCR
&= ~UART_MCR_AFE
;
2034 if (cflag
& CRTSCTS
) {
2035 info
->flags
|= ASYNC_CTS_FLOW
;
2036 info
->IER
|= UART_IER_MSI
;
2037 if (info
->type
== PORT_16550A
)
2038 info
->MCR
|= UART_MCR_AFE
;
2040 info
->flags
&= ~ASYNC_CTS_FLOW
;
2042 outb(info
->MCR
, info
->base
+ UART_MCR
);
2044 info
->flags
&= ~ASYNC_CHECK_CD
;
2046 info
->flags
|= ASYNC_CHECK_CD
;
2047 info
->IER
|= UART_IER_MSI
;
2049 outb(info
->IER
, info
->base
+ UART_IER
);
2052 * Set up parity check flag
2054 info
->read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
| UART_LSR_DR
;
2055 if (I_INPCK(info
->tty
))
2056 info
->read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
2057 if (I_BRKINT(info
->tty
) || I_PARMRK(info
->tty
))
2058 info
->read_status_mask
|= UART_LSR_BI
;
2060 info
->ignore_status_mask
= 0;
2062 /* This should be safe, but for some broken bits of hardware... */
2063 if (I_IGNPAR(info
->tty
)) {
2064 info
->ignore_status_mask
|= UART_LSR_PE
| UART_LSR_FE
;
2065 info
->read_status_mask
|= UART_LSR_PE
| UART_LSR_FE
;
2068 if (I_IGNBRK(info
->tty
)) {
2069 info
->ignore_status_mask
|= UART_LSR_BI
;
2070 info
->read_status_mask
|= UART_LSR_BI
;
2072 * If we're ignore parity and break indicators, ignore
2073 * overruns too. (For real raw support).
2075 if (I_IGNPAR(info
->tty
)) {
2076 info
->ignore_status_mask
|= UART_LSR_OE
| UART_LSR_PE
| UART_LSR_FE
;
2077 info
->read_status_mask
|= UART_LSR_OE
| UART_LSR_PE
| UART_LSR_FE
;
2082 outb(cval
| UART_LCR_DLAB
, info
->base
+ UART_LCR
); /* set DLAB */
2083 outb(quot
& 0xff, info
->base
+ UART_DLL
); /* LS of divisor */
2084 outb(quot
>> 8, info
->base
+ UART_DLM
); /* MS of divisor */
2085 outb(cval
, info
->base
+ UART_LCR
); /* reset DLAB */
2086 outb(fcr
, info
->base
+ UART_FCR
); /* set fcr */
2087 restore_flags(flags
);
2093 * ------------------------------------------------------------
2094 * friends of mxser_ioctl()
2095 * ------------------------------------------------------------
2097 static int mxser_get_serial_info(struct mxser_struct
*info
,
2098 struct serial_struct
*retinfo
)
2100 struct serial_struct tmp
;
2104 memset(&tmp
, 0, sizeof(tmp
));
2105 tmp
.type
= info
->type
;
2106 tmp
.line
= info
->port
;
2107 tmp
.port
= info
->base
;
2108 tmp
.irq
= info
->irq
;
2109 tmp
.flags
= info
->flags
;
2110 tmp
.baud_base
= info
->baud_base
;
2111 tmp
.close_delay
= info
->close_delay
;
2112 tmp
.closing_wait
= info
->closing_wait
;
2113 tmp
.custom_divisor
= info
->custom_divisor
;
2115 copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
));
2119 static int mxser_set_serial_info(struct mxser_struct
*info
,
2120 struct serial_struct
*new_info
)
2122 struct serial_struct new_serial
;
2126 if (!new_info
|| !info
->base
)
2128 copy_from_user(&new_serial
, new_info
, sizeof(new_serial
));
2130 if ((new_serial
.irq
!= info
->irq
) ||
2131 (new_serial
.port
!= info
->base
) ||
2132 (new_serial
.type
!= info
->type
) ||
2133 (new_serial
.custom_divisor
!= info
->custom_divisor
) ||
2134 (new_serial
.baud_base
!= info
->baud_base
))
2137 flags
= info
->flags
& ASYNC_SPD_MASK
;
2140 if ((new_serial
.baud_base
!= info
->baud_base
) ||
2141 (new_serial
.close_delay
!= info
->close_delay
) ||
2142 ((new_serial
.flags
& ~ASYNC_USR_MASK
) !=
2143 (info
->flags
& ~ASYNC_USR_MASK
)))
2145 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) |
2146 (new_serial
.flags
& ASYNC_USR_MASK
));
2149 * OK, past this point, all the error checking has been done.
2150 * At this point, we start making changes.....
2152 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) |
2153 (new_serial
.flags
& ASYNC_FLAGS
));
2154 info
->close_delay
= new_serial
.close_delay
* HZ
/ 100;
2155 info
->closing_wait
= new_serial
.closing_wait
* HZ
/ 100;
2158 if (info
->flags
& ASYNC_INITIALIZED
) {
2159 if (flags
!= (info
->flags
& ASYNC_SPD_MASK
)) {
2160 mxser_change_speed(info
, 0);
2163 retval
= mxser_startup(info
);
2168 * mxser_get_lsr_info - get line status register info
2170 * Purpose: Let user call ioctl() to get info when the UART physically
2171 * is emptied. On bus types like RS485, the transmitter must
2172 * release the bus after transmitting. This must be done when
2173 * the transmit shift register is empty, not be done when the
2174 * transmit holding register is empty. This functionality
2175 * allows an RS485 driver to be written in user space.
2177 static int mxser_get_lsr_info(struct mxser_struct
*info
, unsigned int *value
)
2179 unsigned char status
;
2180 unsigned int result
;
2181 unsigned long flags
;
2185 status
= inb(info
->base
+ UART_LSR
);
2186 restore_flags(flags
);
2187 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
2188 put_user(result
, value
);
2193 * This routine sends a break character out the serial port.
2195 static void mxser_send_break(struct mxser_struct
*info
, int duration
)
2197 unsigned long flags
;
2200 current
->state
= TASK_INTERRUPTIBLE
;
2203 outb(inb(info
->base
+ UART_LCR
) | UART_LCR_SBC
, info
->base
+ UART_LCR
);
2204 schedule_timeout(duration
);
2205 outb(inb(info
->base
+ UART_LCR
) & ~UART_LCR_SBC
, info
->base
+ UART_LCR
);
2206 restore_flags(flags
);
2209 static int mxser_get_modem_info(struct mxser_struct
*info
,
2210 unsigned int *value
)
2212 unsigned char control
, status
;
2213 unsigned int result
;
2214 unsigned long flags
;
2216 control
= info
->MCR
;
2219 status
= inb(info
->base
+ UART_MSR
);
2220 if (status
& UART_MSR_ANY_DELTA
)
2221 mxser_check_modem_status(info
, status
);
2222 restore_flags(flags
);
2223 result
= ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0) |
2224 ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0) |
2225 ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0) |
2226 ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0) |
2227 ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0) |
2228 ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
2229 put_user(result
, value
);
2233 static int mxser_set_modem_info(struct mxser_struct
*info
, unsigned int cmd
,
2234 unsigned int *value
)
2237 unsigned long flags
;
2239 if(get_user(arg
, value
))
2243 if (arg
& TIOCM_RTS
)
2244 info
->MCR
|= UART_MCR_RTS
;
2245 if (arg
& TIOCM_DTR
)
2246 info
->MCR
|= UART_MCR_DTR
;
2249 if (arg
& TIOCM_RTS
)
2250 info
->MCR
&= ~UART_MCR_RTS
;
2251 if (arg
& TIOCM_DTR
)
2252 info
->MCR
&= ~UART_MCR_DTR
;
2255 info
->MCR
= ((info
->MCR
& ~(UART_MCR_RTS
| UART_MCR_DTR
)) |
2256 ((arg
& TIOCM_RTS
) ? UART_MCR_RTS
: 0) |
2257 ((arg
& TIOCM_DTR
) ? UART_MCR_DTR
: 0));
2264 outb(info
->MCR
, info
->base
+ UART_MCR
);
2265 restore_flags(flags
);
2269 static int mxser_read_register(int, unsigned short *);
2270 static int mxser_program_mode(int);
2271 static void mxser_normal_mode(int);
2273 static int mxser_get_ISA_conf(int cap
, struct mxser_hwconf
*hwconf
)
2276 unsigned short regs
[16], irq
;
2277 unsigned char scratch
, scratch2
;
2279 id
= mxser_read_register(cap
, regs
);
2280 if (id
== C168_ASIC_ID
)
2281 hwconf
->board_type
= MXSER_BOARD_C168_ISA
;
2282 else if (id
== C104_ASIC_ID
)
2283 hwconf
->board_type
= MXSER_BOARD_C104_ISA
;
2284 else if (id
== CI104J_ASIC_ID
)
2285 hwconf
->board_type
= MXSER_BOARD_CI104J
;
2288 irq
= regs
[9] & 0x0F;
2289 irq
= irq
| (irq
<< 4);
2290 irq
= irq
| (irq
<< 8);
2291 if ((irq
!= regs
[9]) || ((id
== 1) && (irq
!= regs
[10]))) {
2292 return (MXSER_ERR_IRQ_CONFLIT
);
2295 return (MXSER_ERR_IRQ
);
2297 for (i
= 0; i
< 8; i
++)
2298 hwconf
->ioaddr
[i
] = (int) regs
[i
+ 1] & 0xFFF8;
2299 hwconf
->irq
= (int) (irq
& 0x0F);
2300 if ((regs
[12] & 0x80) == 0) {
2301 return (MXSER_ERR_VECTOR
);
2303 hwconf
->vector
= (int) regs
[11]; /* interrupt vector */
2305 hwconf
->vector_mask
= 0x00FF;
2307 hwconf
->vector_mask
= 0x000F;
2308 for (i
= 7, bits
= 0x0100; i
>= 0; i
--, bits
<<= 1) {
2309 if (regs
[12] & bits
)
2310 hwconf
->baud_base
[i
] = 921600;
2312 hwconf
->baud_base
[i
] = 115200;
2314 scratch2
= inb(cap
+ UART_LCR
) & (~UART_LCR_DLAB
);
2315 outb(scratch2
| UART_LCR_DLAB
, cap
+ UART_LCR
);
2316 outb(0, cap
+ UART_EFR
); /* EFR is the same as FCR */
2317 outb(scratch2
, cap
+ UART_LCR
);
2318 outb(UART_FCR_ENABLE_FIFO
, cap
+ UART_FCR
);
2319 scratch
= inb(cap
+ UART_IIR
);
2321 hwconf
->uart_type
= PORT_16550A
;
2323 hwconf
->uart_type
= PORT_16450
;
2328 return (hwconf
->ports
);
2331 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
2332 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
2333 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
2334 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
2335 #define EN_CCMD 0x000 /* Chip's command register */
2336 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
2337 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
2338 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
2339 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
2340 #define EN0_DCFG 0x00E /* Data configuration reg WR */
2341 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
2342 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
2343 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
2344 static int mxser_read_register(int port
, unsigned short *regs
)
2346 int i
, k
, value
, id
;
2349 id
= mxser_program_mode(port
);
2352 for (i
= 0; i
< 14; i
++) {
2353 k
= (i
& 0x3F) | 0x180;
2354 for (j
= 0x100; j
> 0; j
>>= 1) {
2355 outb(CHIP_CS
, port
);
2357 outb(CHIP_CS
| CHIP_DO
, port
);
2358 outb(CHIP_CS
| CHIP_DO
| CHIP_SK
, port
); /* A? bit of read */
2360 outb(CHIP_CS
, port
);
2361 outb(CHIP_CS
| CHIP_SK
, port
); /* A? bit of read */
2366 for (k
= 0, j
= 0x8000; k
< 16; k
++, j
>>= 1) {
2367 outb(CHIP_CS
, port
);
2368 outb(CHIP_CS
| CHIP_SK
, port
);
2369 if (inb(port
) & CHIP_DI
)
2375 mxser_normal_mode(port
);
2379 static int mxser_program_mode(int port
)
2382 unsigned long flags
;
2393 restore_flags(flags
);
2394 id
= inb(port
+ 1) & 0x1F;
2395 if ((id
!= C168_ASIC_ID
) && (id
!= C104_ASIC_ID
) && (id
!= CI104J_ASIC_ID
))
2397 for (i
= 0, j
= 0; i
< 4; i
++) {
2401 } else if ((j
== 1) && (n
== 1)) {
2412 static void mxser_normal_mode(int port
)
2416 outb(0xA5, port
+ 1);
2417 outb(0x80, port
+ 3);
2418 outb(12, port
+ 0); /* 9600 bps */
2420 outb(0x03, port
+ 3); /* 8 data bits */
2421 outb(0x13, port
+ 4); /* loop back mode */
2422 for (i
= 0; i
< 16; i
++) {
2424 if ((n
& 0x61) == 0x60)
2429 outb(0x00, port
+ 4);