1 /*****************************************************************************/
3 * moxa.c -- MOXA Intellio 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.
17 * MOXA Intellio Series Driver
23 #include <linux/module.h>
24 #include <linux/types.h>
26 #include <linux/ioport.h>
27 #include <linux/errno.h>
28 #include <linux/firmware.h>
29 #include <linux/signal.h>
30 #include <linux/sched.h>
31 #include <linux/timer.h>
32 #include <linux/interrupt.h>
33 #include <linux/tty.h>
34 #include <linux/tty_flip.h>
35 #include <linux/major.h>
36 #include <linux/string.h>
37 #include <linux/fcntl.h>
38 #include <linux/ptrace.h>
39 #include <linux/serial.h>
40 #include <linux/tty_driver.h>
41 #include <linux/delay.h>
42 #include <linux/pci.h>
43 #include <linux/init.h>
44 #include <linux/bitops.h>
45 #include <linux/completion.h>
47 #include <asm/system.h>
49 #include <asm/uaccess.h>
53 #define MOXA_VERSION "5.1k"
55 #define MOXA_FW_HDRLEN 32
58 #define MOXACUMAJOR 173
60 #define MAX_BOARDS 4 /* Don't change this value */
61 #define MAX_PORTS_PER_BOARD 32 /* Don't change this value */
62 #define MAX_PORTS (MAX_BOARDS * MAX_PORTS_PER_BOARD)
65 * Define the Moxa PCI vendor and device IDs.
67 #define MOXA_BUS_TYPE_ISA 0
68 #define MOXA_BUS_TYPE_PCI 1
71 MOXA_BOARD_C218_PCI = 1,
78 static char *moxa_brdname[] =
80 "C218 Turbo PCI series",
81 "C218 Turbo ISA series",
82 "C320 Turbo PCI series",
83 "C320 Turbo ISA series",
88 static struct pci_device_id moxa_pcibrds[] = {
89 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C218),
90 .driver_data = MOXA_BOARD_C218_PCI },
91 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C320),
92 .driver_data = MOXA_BOARD_C320_PCI },
93 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP204J),
94 .driver_data = MOXA_BOARD_CP204J },
97 MODULE_DEVICE_TABLE(pci, moxa_pcibrds);
98 #endif /* CONFIG_PCI */
102 static struct moxa_board_conf {
109 struct moxa_port *ports;
111 void __iomem *basemem;
112 void __iomem *intNdx;
113 void __iomem *intPend;
114 void __iomem *intTable;
115 } moxa_boards[MAX_BOARDS];
117 struct mxser_mstatus {
134 unsigned short closing_wait;
137 long event; /* long req'd for set_bit --RR */
139 unsigned long statusflags;
140 struct tty_struct *tty;
142 wait_queue_head_t open_wait;
143 struct completion close_wait;
145 struct timer_list emptyTimer;
149 void __iomem *tableAddr;
158 #define TXSTOPPED 0x1
160 #define EMPTYWAIT 0x4
163 #define SERIAL_DO_RESTART
165 #define WAKEUP_CHARS 256
167 static int ttymajor = MOXAMAJOR;
169 /* Variables for insmod */
171 static unsigned long baseaddr[MAX_BOARDS];
172 static unsigned int type[MAX_BOARDS];
173 static unsigned int numports[MAX_BOARDS];
176 MODULE_AUTHOR("William Chen");
177 MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver");
178 MODULE_LICENSE("GPL");
180 module_param_array(type, uint, NULL, 0);
181 MODULE_PARM_DESC(type, "card type: C218=2, C320=4");
182 module_param_array(baseaddr, ulong, NULL, 0);
183 MODULE_PARM_DESC(baseaddr, "base address");
184 module_param_array(numports, uint, NULL, 0);
185 MODULE_PARM_DESC(numports, "numports (ignored for C218)");
187 module_param(ttymajor, int, 0);
192 static int moxa_open(struct tty_struct *, struct file *);
193 static void moxa_close(struct tty_struct *, struct file *);
194 static int moxa_write(struct tty_struct *, const unsigned char *, int);
195 static int moxa_write_room(struct tty_struct *);
196 static void moxa_flush_buffer(struct tty_struct *);
197 static int moxa_chars_in_buffer(struct tty_struct *);
198 static void moxa_flush_chars(struct tty_struct *);
199 static void moxa_put_char(struct tty_struct *, unsigned char);
200 static int moxa_ioctl(struct tty_struct *, struct file *, unsigned int, unsigned long);
201 static void moxa_throttle(struct tty_struct *);
202 static void moxa_unthrottle(struct tty_struct *);
203 static void moxa_set_termios(struct tty_struct *, struct ktermios *);
204 static void moxa_stop(struct tty_struct *);
205 static void moxa_start(struct tty_struct *);
206 static void moxa_hangup(struct tty_struct *);
207 static int moxa_tiocmget(struct tty_struct *tty, struct file *file);
208 static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
209 unsigned int set, unsigned int clear);
210 static void moxa_poll(unsigned long);
211 static void moxa_set_tty_param(struct tty_struct *, struct ktermios *);
212 static int moxa_block_till_ready(struct tty_struct *, struct file *,
214 static void moxa_setup_empty_event(struct tty_struct *);
215 static void moxa_check_xmit_empty(unsigned long);
216 static void moxa_shut_down(struct moxa_port *);
217 static void moxa_receive_data(struct moxa_port *);
219 * moxa board interface functions:
221 static int MoxaDriverIoctl(unsigned int, unsigned long, int);
222 static int MoxaDriverPoll(void);
223 static int MoxaPortsOfCard(int);
224 static int MoxaPortIsValid(int);
225 static void MoxaPortEnable(int);
226 static void MoxaPortDisable(int);
227 static long MoxaPortGetMaxBaud(int);
228 static long MoxaPortSetBaud(int, long);
229 static int MoxaPortSetTermio(int, struct ktermios *, speed_t);
230 static int MoxaPortGetLineOut(int, int *, int *);
231 static void MoxaPortLineCtrl(int, int, int);
232 static void MoxaPortFlowCtrl(int, int, int, int, int, int);
233 static int MoxaPortLineStatus(int);
234 static int MoxaPortDCDChange(int);
235 static int MoxaPortDCDON(int);
236 static void MoxaPortFlushData(int, int);
237 static int MoxaPortWriteData(int, unsigned char *, int);
238 static int MoxaPortReadData(int, struct tty_struct *tty);
239 static int MoxaPortTxQueue(int);
240 static int MoxaPortRxQueue(int);
241 static int MoxaPortTxFree(int);
242 static void MoxaPortTxDisable(int);
243 static void MoxaPortTxEnable(int);
244 static int MoxaPortResetBrkCnt(int);
245 static void MoxaPortSendBreak(int, int);
246 static int moxa_get_serial_info(struct moxa_port *, struct serial_struct __user *);
247 static int moxa_set_serial_info(struct moxa_port *, struct serial_struct __user *);
248 static void MoxaSetFifo(int port, int enable);
250 static const struct tty_operations moxa_ops = {
254 .write_room = moxa_write_room,
255 .flush_buffer = moxa_flush_buffer,
256 .chars_in_buffer = moxa_chars_in_buffer,
257 .flush_chars = moxa_flush_chars,
258 .put_char = moxa_put_char,
260 .throttle = moxa_throttle,
261 .unthrottle = moxa_unthrottle,
262 .set_termios = moxa_set_termios,
265 .hangup = moxa_hangup,
266 .tiocmget = moxa_tiocmget,
267 .tiocmset = moxa_tiocmset,
270 static struct tty_driver *moxaDriver;
271 static struct moxa_port moxa_ports[MAX_PORTS];
272 static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0);
273 static DEFINE_SPINLOCK(moxa_lock);
275 static int moxa_check_fw_model(struct moxa_board_conf *brd, u8 model)
277 switch (brd->boardType) {
278 case MOXA_BOARD_C218_ISA:
279 case MOXA_BOARD_C218_PCI:
283 case MOXA_BOARD_CP204J:
297 static int moxa_check_fw(const void *ptr)
299 const __le16 *lptr = ptr;
301 if (*lptr != cpu_to_le16(0x7980))
307 static int moxa_load_bios(struct moxa_board_conf *brd, const u8 *buf,
310 void __iomem *baseAddr = brd->basemem;
313 writeb(HW_reset, baseAddr + Control_reg); /* reset */
315 memset_io(baseAddr, 0, 4096);
316 memcpy_toio(baseAddr, buf, len); /* download BIOS */
317 writeb(0, baseAddr + Control_reg); /* restart */
321 switch (brd->boardType) {
322 case MOXA_BOARD_C218_ISA:
323 case MOXA_BOARD_C218_PCI:
324 tmp = readw(baseAddr + C218_key);
325 if (tmp != C218_KeyCode)
328 case MOXA_BOARD_CP204J:
329 tmp = readw(baseAddr + C218_key);
330 if (tmp != CP204J_KeyCode)
334 tmp = readw(baseAddr + C320_key);
335 if (tmp != C320_KeyCode)
337 tmp = readw(baseAddr + C320_status);
338 if (tmp != STS_init) {
339 printk(KERN_ERR "moxa: bios upload failed -- CPU/Basic "
340 "module not found\n");
348 printk(KERN_ERR "moxa: bios upload failed -- board not found\n");
352 static int moxa_load_320b(struct moxa_board_conf *brd, const u8 *ptr,
355 void __iomem *baseAddr = brd->basemem;
358 printk(KERN_ERR "moxa: invalid 320 bios -- too short\n");
362 writew(len - 7168 - 2, baseAddr + C320bapi_len);
363 writeb(1, baseAddr + Control_reg); /* Select Page 1 */
364 memcpy_toio(baseAddr + DynPage_addr, ptr, 7168);
365 writeb(2, baseAddr + Control_reg); /* Select Page 2 */
366 memcpy_toio(baseAddr + DynPage_addr, ptr + 7168, len - 7168);
371 static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr,
374 void __iomem *baseAddr = brd->basemem;
375 const u16 *uptr = ptr;
376 size_t wlen, len2, j;
377 unsigned long key, loadbuf, loadlen, checksum, checksum_ok;
378 unsigned int i, retry, c320;
381 c320 = brd->boardType == MOXA_BOARD_C320_PCI ||
382 brd->boardType == MOXA_BOARD_C320_ISA;
383 keycode = (brd->boardType == MOXA_BOARD_CP204J) ? CP204J_KeyCode :
386 switch (brd->boardType) {
387 case MOXA_BOARD_CP204J:
388 case MOXA_BOARD_C218_ISA:
389 case MOXA_BOARD_C218_PCI:
391 loadbuf = C218_LoadBuf;
392 loadlen = C218DLoad_len;
393 checksum = C218check_sum;
394 checksum_ok = C218chksum_ok;
398 keycode = C320_KeyCode;
399 loadbuf = C320_LoadBuf;
400 loadlen = C320DLoad_len;
401 checksum = C320check_sum;
402 checksum_ok = C320chksum_ok;
408 for (i = 0; i < wlen; i++)
409 usum += le16_to_cpu(uptr[i]);
415 len2 = (wlen > 2048) ? 2048 : wlen;
417 memcpy_toio(baseAddr + loadbuf, ptr + j, len2 << 1);
420 writew(len2, baseAddr + loadlen);
421 writew(0, baseAddr + key);
422 for (i = 0; i < 100; i++) {
423 if (readw(baseAddr + key) == keycode)
427 if (readw(baseAddr + key) != keycode)
430 writew(0, baseAddr + loadlen);
431 writew(usum, baseAddr + checksum);
432 writew(0, baseAddr + key);
433 for (i = 0; i < 100; i++) {
434 if (readw(baseAddr + key) == keycode)
439 } while ((readb(baseAddr + checksum_ok) != 1) && (retry < 3));
440 if (readb(baseAddr + checksum_ok) != 1)
443 writew(0, baseAddr + key);
444 for (i = 0; i < 600; i++) {
445 if (readw(baseAddr + Magic_no) == Magic_code)
449 if (readw(baseAddr + Magic_no) != Magic_code)
453 if (brd->busType == MOXA_BUS_TYPE_PCI) { /* ASIC board */
454 writew(0x3800, baseAddr + TMS320_PORT1);
455 writew(0x3900, baseAddr + TMS320_PORT2);
456 writew(28499, baseAddr + TMS320_CLOCK);
458 writew(0x3200, baseAddr + TMS320_PORT1);
459 writew(0x3400, baseAddr + TMS320_PORT2);
460 writew(19999, baseAddr + TMS320_CLOCK);
463 writew(1, baseAddr + Disable_IRQ);
464 writew(0, baseAddr + Magic_no);
465 for (i = 0; i < 500; i++) {
466 if (readw(baseAddr + Magic_no) == Magic_code)
470 if (readw(baseAddr + Magic_no) != Magic_code)
474 j = readw(baseAddr + Module_cnt);
477 brd->numPorts = j * 8;
478 writew(j, baseAddr + Module_no);
479 writew(0, baseAddr + Magic_no);
480 for (i = 0; i < 600; i++) {
481 if (readw(baseAddr + Magic_no) == Magic_code)
485 if (readw(baseAddr + Magic_no) != Magic_code)
489 brd->intNdx = baseAddr + IRQindex;
490 brd->intPend = baseAddr + IRQpending;
491 brd->intTable = baseAddr + IRQtable;
496 static int moxa_load_code(struct moxa_board_conf *brd, const void *ptr,
499 void __iomem *ofsAddr, *baseAddr = brd->basemem;
500 struct moxa_port *port;
504 printk(KERN_ERR "moxa: bios length is not even\n");
508 retval = moxa_real_load_code(brd, ptr, len); /* may change numPorts */
512 switch (brd->boardType) {
513 case MOXA_BOARD_C218_ISA:
514 case MOXA_BOARD_C218_PCI:
515 case MOXA_BOARD_CP204J:
517 for (i = 0; i < brd->numPorts; i++, port++) {
519 port->curBaud = 9600L;
521 port->tableAddr = baseAddr + Extern_table +
523 ofsAddr = port->tableAddr;
524 writew(C218rx_mask, ofsAddr + RX_mask);
525 writew(C218tx_mask, ofsAddr + TX_mask);
526 writew(C218rx_spage + i * C218buf_pageno, ofsAddr + Page_rxb);
527 writew(readw(ofsAddr + Page_rxb) + C218rx_pageno, ofsAddr + EndPage_rxb);
529 writew(C218tx_spage + i * C218buf_pageno, ofsAddr + Page_txb);
530 writew(readw(ofsAddr + Page_txb) + C218tx_pageno, ofsAddr + EndPage_txb);
536 for (i = 0; i < brd->numPorts; i++, port++) {
538 port->curBaud = 9600L;
540 port->tableAddr = baseAddr + Extern_table +
542 ofsAddr = port->tableAddr;
543 switch (brd->numPorts) {
545 writew(C320p8rx_mask, ofsAddr + RX_mask);
546 writew(C320p8tx_mask, ofsAddr + TX_mask);
547 writew(C320p8rx_spage + i * C320p8buf_pgno, ofsAddr + Page_rxb);
548 writew(readw(ofsAddr + Page_rxb) + C320p8rx_pgno, ofsAddr + EndPage_rxb);
549 writew(C320p8tx_spage + i * C320p8buf_pgno, ofsAddr + Page_txb);
550 writew(readw(ofsAddr + Page_txb) + C320p8tx_pgno, ofsAddr + EndPage_txb);
554 writew(C320p16rx_mask, ofsAddr + RX_mask);
555 writew(C320p16tx_mask, ofsAddr + TX_mask);
556 writew(C320p16rx_spage + i * C320p16buf_pgno, ofsAddr + Page_rxb);
557 writew(readw(ofsAddr + Page_rxb) + C320p16rx_pgno, ofsAddr + EndPage_rxb);
558 writew(C320p16tx_spage + i * C320p16buf_pgno, ofsAddr + Page_txb);
559 writew(readw(ofsAddr + Page_txb) + C320p16tx_pgno, ofsAddr + EndPage_txb);
563 writew(C320p24rx_mask, ofsAddr + RX_mask);
564 writew(C320p24tx_mask, ofsAddr + TX_mask);
565 writew(C320p24rx_spage + i * C320p24buf_pgno, ofsAddr + Page_rxb);
566 writew(readw(ofsAddr + Page_rxb) + C320p24rx_pgno, ofsAddr + EndPage_rxb);
567 writew(C320p24tx_spage + i * C320p24buf_pgno, ofsAddr + Page_txb);
568 writew(readw(ofsAddr + Page_txb), ofsAddr + EndPage_txb);
571 writew(C320p32rx_mask, ofsAddr + RX_mask);
572 writew(C320p32tx_mask, ofsAddr + TX_mask);
573 writew(C320p32tx_ofs, ofsAddr + Ofs_txb);
574 writew(C320p32rx_spage + i * C320p32buf_pgno, ofsAddr + Page_rxb);
575 writew(readb(ofsAddr + Page_rxb), ofsAddr + EndPage_rxb);
576 writew(C320p32tx_spage + i * C320p32buf_pgno, ofsAddr + Page_txb);
577 writew(readw(ofsAddr + Page_txb), ofsAddr + EndPage_txb);
587 static int moxa_load_fw(struct moxa_board_conf *brd, const struct firmware *fw)
589 void *ptr = fw->data;
593 unsigned int a, lenp, lencnt;
596 __le32 magic; /* 0x34303430 */
598 u8 type; /* UNIX = 3 */
599 u8 model; /* C218T=1, C320T=2, CP204=3 */
604 BUILD_BUG_ON(ARRAY_SIZE(hdr->len) != ARRAY_SIZE(lens));
606 if (fw->size < MOXA_FW_HDRLEN) {
607 strcpy(rsn, "too short (even header won't fit)");
610 if (hdr->magic != cpu_to_le32(0x30343034)) {
611 sprintf(rsn, "bad magic: %.8x", le32_to_cpu(hdr->magic));
614 if (hdr->type != 3) {
615 sprintf(rsn, "not for linux, type is %u", hdr->type);
618 if (moxa_check_fw_model(brd, hdr->model)) {
619 sprintf(rsn, "not for this card, model is %u", hdr->model);
623 len = MOXA_FW_HDRLEN;
624 lencnt = hdr->model == 2 ? 5 : 3;
625 for (a = 0; a < ARRAY_SIZE(lens); a++) {
626 lens[a] = le16_to_cpu(hdr->len[a]);
627 if (lens[a] && len + lens[a] <= fw->size &&
628 moxa_check_fw(&fw->data[len]))
629 printk(KERN_WARNING "moxa firmware: unexpected input "
630 "at offset %u, but going on\n", (u32)len);
631 if (!lens[a] && a < lencnt) {
632 sprintf(rsn, "too few entries in fw file");
638 if (len != fw->size) {
639 sprintf(rsn, "bad length: %u (should be %u)", (u32)fw->size,
644 ptr += MOXA_FW_HDRLEN;
647 strcpy(rsn, "read above");
649 ret = moxa_load_bios(brd, ptr, lens[lenp]);
653 /* we skip the tty section (lens[1]), since we don't need it */
654 ptr += lens[lenp] + lens[lenp + 1];
655 lenp += 2; /* comm */
657 if (hdr->model == 2) {
658 ret = moxa_load_320b(brd, ptr, lens[lenp]);
661 /* skip another tty */
662 ptr += lens[lenp] + lens[lenp + 1];
666 ret = moxa_load_code(brd, ptr, lens[lenp]);
672 printk(KERN_ERR "firmware failed to load, reason: %s\n", rsn);
676 static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev)
678 const struct firmware *fw;
682 switch (brd->boardType) {
683 case MOXA_BOARD_C218_ISA:
684 case MOXA_BOARD_C218_PCI:
685 file = "c218tunx.cod";
687 case MOXA_BOARD_CP204J:
688 file = "cp204unx.cod";
691 file = "c320tunx.cod";
695 ret = request_firmware(&fw, file, dev);
697 printk(KERN_ERR "request_firmware failed\n");
701 ret = moxa_load_fw(brd, fw);
703 release_firmware(fw);
709 static int __devinit moxa_pci_probe(struct pci_dev *pdev,
710 const struct pci_device_id *ent)
712 struct moxa_board_conf *board;
714 int board_type = ent->driver_data;
717 retval = pci_enable_device(pdev);
719 dev_err(&pdev->dev, "can't enable pci device\n");
723 for (i = 0; i < MAX_BOARDS; i++)
724 if (moxa_boards[i].basemem == NULL)
728 if (i >= MAX_BOARDS) {
729 dev_warn(&pdev->dev, "more than %u MOXA Intellio family boards "
730 "found. Board is ignored.\n", MAX_BOARDS);
734 board = &moxa_boards[i];
735 board->ports = &moxa_ports[i * MAX_PORTS_PER_BOARD];
737 retval = pci_request_region(pdev, 2, "moxa-base");
739 dev_err(&pdev->dev, "can't request pci region 2\n");
743 board->basemem = ioremap(pci_resource_start(pdev, 2), 0x4000);
744 if (board->basemem == NULL) {
745 dev_err(&pdev->dev, "can't remap io space 2\n");
749 board->boardType = board_type;
750 switch (board_type) {
751 case MOXA_BOARD_C218_ISA:
752 case MOXA_BOARD_C218_PCI:
756 case MOXA_BOARD_CP204J:
763 board->busType = MOXA_BUS_TYPE_PCI;
765 retval = moxa_init_board(board, &pdev->dev);
769 pci_set_drvdata(pdev, board);
773 iounmap(board->basemem);
774 board->basemem = NULL;
776 pci_release_region(pdev, 2);
781 static void __devexit moxa_pci_remove(struct pci_dev *pdev)
783 struct moxa_board_conf *brd = pci_get_drvdata(pdev);
785 iounmap(brd->basemem);
787 pci_release_region(pdev, 2);
790 static struct pci_driver moxa_pci_driver = {
792 .id_table = moxa_pcibrds,
793 .probe = moxa_pci_probe,
794 .remove = __devexit_p(moxa_pci_remove)
796 #endif /* CONFIG_PCI */
798 static int __init moxa_init(void)
800 struct moxa_port *ch;
801 unsigned int i, isabrds = 0;
804 printk(KERN_INFO "MOXA Intellio family driver version %s\n",
806 moxaDriver = alloc_tty_driver(MAX_PORTS + 1);
810 moxaDriver->owner = THIS_MODULE;
811 moxaDriver->name = "ttyMX";
812 moxaDriver->major = ttymajor;
813 moxaDriver->minor_start = 0;
814 moxaDriver->type = TTY_DRIVER_TYPE_SERIAL;
815 moxaDriver->subtype = SERIAL_TYPE_NORMAL;
816 moxaDriver->init_termios = tty_std_termios;
817 moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
818 moxaDriver->init_termios.c_ispeed = 9600;
819 moxaDriver->init_termios.c_ospeed = 9600;
820 moxaDriver->flags = TTY_DRIVER_REAL_RAW;
821 tty_set_operations(moxaDriver, &moxa_ops);
823 for (i = 0, ch = moxa_ports; i < MAX_PORTS; i++, ch++) {
824 ch->type = PORT_16550A;
826 ch->close_delay = 5 * HZ / 10;
827 ch->closing_wait = 30 * HZ;
828 ch->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
829 init_waitqueue_head(&ch->open_wait);
830 init_completion(&ch->close_wait);
832 setup_timer(&ch->emptyTimer, moxa_check_xmit_empty,
836 pr_debug("Moxa tty devices major number = %d\n", ttymajor);
838 if (tty_register_driver(moxaDriver)) {
839 printk(KERN_ERR "Couldn't install MOXA Smartio family driver !\n");
840 put_tty_driver(moxaDriver);
844 mod_timer(&moxaTimer, jiffies + HZ / 50);
846 /* Find the boards defined from module args. */
849 struct moxa_board_conf *brd = moxa_boards;
850 for (i = 0; i < MAX_BOARDS; i++) {
853 if (type[i] == MOXA_BOARD_C218_ISA ||
854 type[i] == MOXA_BOARD_C320_ISA) {
855 pr_debug("Moxa board %2d: %s board(baseAddr=%lx)\n",
856 isabrds + 1, moxa_brdname[type[i] - 1],
858 brd->boardType = type[i];
859 brd->ports = &moxa_ports[isabrds * MAX_PORTS_PER_BOARD];
860 brd->numPorts = type[i] == MOXA_BOARD_C218_ISA ? 8 :
862 brd->busType = MOXA_BUS_TYPE_ISA;
863 brd->basemem = ioremap(baseaddr[i], 0x4000);
865 printk(KERN_ERR "moxa: can't remap %lx\n",
869 if (moxa_init_board(brd, NULL)) {
870 iounmap(brd->basemem);
883 retval = pci_register_driver(&moxa_pci_driver);
885 printk(KERN_ERR "Can't register moxa pci driver!\n");
894 static void __exit moxa_exit(void)
898 del_timer_sync(&moxaTimer);
900 for (i = 0; i < MAX_PORTS; i++)
901 del_timer_sync(&moxa_ports[i].emptyTimer);
903 if (tty_unregister_driver(moxaDriver))
904 printk(KERN_ERR "Couldn't unregister MOXA Intellio family "
906 put_tty_driver(moxaDriver);
909 pci_unregister_driver(&moxa_pci_driver);
912 for (i = 0; i < MAX_BOARDS; i++)
913 if (moxa_boards[i].basemem)
914 iounmap(moxa_boards[i].basemem);
917 module_init(moxa_init);
918 module_exit(moxa_exit);
920 static int moxa_open(struct tty_struct *tty, struct file *filp)
922 struct moxa_port *ch;
927 if (port == MAX_PORTS) {
930 if (!MoxaPortIsValid(port)) {
931 tty->driver_data = NULL;
935 ch = &moxa_ports[port];
937 tty->driver_data = ch;
939 if (!(ch->asyncflags & ASYNC_INITIALIZED)) {
941 moxa_set_tty_param(tty, tty->termios);
942 MoxaPortLineCtrl(ch->port, 1, 1);
943 MoxaPortEnable(ch->port);
944 ch->asyncflags |= ASYNC_INITIALIZED;
946 retval = moxa_block_till_ready(tty, filp, ch);
948 moxa_unthrottle(tty);
950 if (ch->type == PORT_16550A) {
951 MoxaSetFifo(ch->port, 1);
953 MoxaSetFifo(ch->port, 0);
959 static void moxa_close(struct tty_struct *tty, struct file *filp)
961 struct moxa_port *ch;
965 if (port == MAX_PORTS) {
968 if (!MoxaPortIsValid(port)) {
969 pr_debug("Invalid portno in moxa_close\n");
970 tty->driver_data = NULL;
973 if (tty->driver_data == NULL) {
976 if (tty_hung_up_p(filp)) {
979 ch = (struct moxa_port *) tty->driver_data;
981 if ((tty->count == 1) && (ch->count != 1)) {
982 printk(KERN_WARNING "moxa_close: bad serial port count; "
983 "tty->count is 1, ch->count is %d\n", ch->count);
986 if (--ch->count < 0) {
987 printk(KERN_WARNING "moxa_close: bad serial port count, "
988 "device=%s\n", tty->name);
994 ch->asyncflags |= ASYNC_CLOSING;
996 ch->cflag = tty->termios->c_cflag;
997 if (ch->asyncflags & ASYNC_INITIALIZED) {
998 moxa_setup_empty_event(tty);
999 tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */
1000 del_timer_sync(&moxa_ports[ch->port].emptyTimer);
1003 MoxaPortFlushData(port, 2);
1005 if (tty->driver->flush_buffer)
1006 tty->driver->flush_buffer(tty);
1007 tty_ldisc_flush(tty);
1012 if (ch->blocked_open) {
1013 if (ch->close_delay) {
1014 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
1016 wake_up_interruptible(&ch->open_wait);
1018 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1019 complete_all(&ch->close_wait);
1022 static int moxa_write(struct tty_struct *tty,
1023 const unsigned char *buf, int count)
1025 struct moxa_port *ch;
1027 unsigned long flags;
1029 ch = (struct moxa_port *) tty->driver_data;
1034 spin_lock_irqsave(&moxa_lock, flags);
1035 len = MoxaPortWriteData(port, (unsigned char *) buf, count);
1036 spin_unlock_irqrestore(&moxa_lock, flags);
1038 /*********************************************
1039 if ( !(ch->statusflags & LOWWAIT) &&
1040 ((len != count) || (MoxaPortTxFree(port) <= 100)) )
1041 ************************************************/
1042 ch->statusflags |= LOWWAIT;
1046 static int moxa_write_room(struct tty_struct *tty)
1048 struct moxa_port *ch;
1052 ch = (struct moxa_port *) tty->driver_data;
1055 return (MoxaPortTxFree(ch->port));
1058 static void moxa_flush_buffer(struct tty_struct *tty)
1060 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
1064 MoxaPortFlushData(ch->port, 1);
1068 static int moxa_chars_in_buffer(struct tty_struct *tty)
1071 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
1074 * Sigh...I have to check if driver_data is NULL here, because
1075 * if an open() fails, the TTY subsystem eventually calls
1076 * tty_wait_until_sent(), which calls the driver's chars_in_buffer()
1077 * routine. And since the open() failed, we return 0 here. TDJ
1081 chars = MoxaPortTxQueue(ch->port);
1084 * Make it possible to wakeup anything waiting for output
1085 * in tty_ioctl.c, etc.
1087 if (!(ch->statusflags & EMPTYWAIT))
1088 moxa_setup_empty_event(tty);
1093 static void moxa_flush_chars(struct tty_struct *tty)
1096 * Don't think I need this, because this is called to empty the TX
1097 * buffer for the 16450, 16550, etc.
1101 static void moxa_put_char(struct tty_struct *tty, unsigned char c)
1103 struct moxa_port *ch;
1105 unsigned long flags;
1107 ch = (struct moxa_port *) tty->driver_data;
1111 spin_lock_irqsave(&moxa_lock, flags);
1112 MoxaPortWriteData(port, &c, 1);
1113 spin_unlock_irqrestore(&moxa_lock, flags);
1114 /************************************************
1115 if ( !(ch->statusflags & LOWWAIT) && (MoxaPortTxFree(port) <= 100) )
1116 *************************************************/
1117 ch->statusflags |= LOWWAIT;
1120 static int moxa_tiocmget(struct tty_struct *tty, struct file *file)
1122 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
1124 int flag = 0, dtr, rts;
1127 if ((port != MAX_PORTS) && (!ch))
1130 MoxaPortGetLineOut(ch->port, &dtr, &rts);
1135 dtr = MoxaPortLineStatus(ch->port);
1145 static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
1146 unsigned int set, unsigned int clear)
1148 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
1153 if ((port != MAX_PORTS) && (!ch))
1156 MoxaPortGetLineOut(ch->port, &dtr, &rts);
1157 if (set & TIOCM_RTS)
1159 if (set & TIOCM_DTR)
1161 if (clear & TIOCM_RTS)
1163 if (clear & TIOCM_DTR)
1165 MoxaPortLineCtrl(ch->port, dtr, rts);
1169 static int moxa_ioctl(struct tty_struct *tty, struct file *file,
1170 unsigned int cmd, unsigned long arg)
1172 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
1174 void __user *argp = (void __user *)arg;
1178 if ((port != MAX_PORTS) && (!ch))
1182 case TCSBRK: /* SVID version: non-zero arg --> no break */
1183 retval = tty_check_change(tty);
1186 moxa_setup_empty_event(tty);
1187 tty_wait_until_sent(tty, 0);
1189 MoxaPortSendBreak(ch->port, 0);
1191 case TCSBRKP: /* support for POSIX tcsendbreak() */
1192 retval = tty_check_change(tty);
1195 moxa_setup_empty_event(tty);
1196 tty_wait_until_sent(tty, 0);
1197 MoxaPortSendBreak(ch->port, arg);
1200 return put_user(C_CLOCAL(tty) ? 1 : 0, (int __user *)argp);
1202 if (get_user(retval, (int __user *)argp))
1205 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) |
1206 (arg ? CLOCAL : 0));
1208 ch->asyncflags &= ~ASYNC_CHECK_CD;
1210 ch->asyncflags |= ASYNC_CHECK_CD;
1213 return moxa_get_serial_info(ch, argp);
1216 return moxa_set_serial_info(ch, argp);
1218 retval = MoxaDriverIoctl(cmd, arg, port);
1223 static void moxa_throttle(struct tty_struct *tty)
1225 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
1227 ch->statusflags |= THROTTLE;
1230 static void moxa_unthrottle(struct tty_struct *tty)
1232 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
1234 ch->statusflags &= ~THROTTLE;
1237 static void moxa_set_termios(struct tty_struct *tty,
1238 struct ktermios *old_termios)
1240 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
1244 moxa_set_tty_param(tty, old_termios);
1245 if (!(old_termios->c_cflag & CLOCAL) &&
1246 (tty->termios->c_cflag & CLOCAL))
1247 wake_up_interruptible(&ch->open_wait);
1250 static void moxa_stop(struct tty_struct *tty)
1252 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
1256 MoxaPortTxDisable(ch->port);
1257 ch->statusflags |= TXSTOPPED;
1261 static void moxa_start(struct tty_struct *tty)
1263 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
1268 if (!(ch->statusflags & TXSTOPPED))
1271 MoxaPortTxEnable(ch->port);
1272 ch->statusflags &= ~TXSTOPPED;
1275 static void moxa_hangup(struct tty_struct *tty)
1277 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
1279 moxa_flush_buffer(tty);
1283 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
1285 wake_up_interruptible(&ch->open_wait);
1288 static void moxa_poll(unsigned long ignored)
1291 struct moxa_port *ch;
1292 struct tty_struct *tp;
1295 del_timer(&moxaTimer);
1297 if (MoxaDriverPoll() < 0) {
1298 mod_timer(&moxaTimer, jiffies + HZ / 50);
1301 for (card = 0; card < MAX_BOARDS; card++) {
1302 if ((ports = MoxaPortsOfCard(card)) <= 0)
1304 ch = &moxa_ports[card * MAX_PORTS_PER_BOARD];
1305 for (i = 0; i < ports; i++, ch++) {
1306 if ((ch->asyncflags & ASYNC_INITIALIZED) == 0)
1308 if (!(ch->statusflags & THROTTLE) &&
1309 (MoxaPortRxQueue(ch->port) > 0))
1310 moxa_receive_data(ch);
1311 if ((tp = ch->tty) == 0)
1313 if (ch->statusflags & LOWWAIT) {
1314 if (MoxaPortTxQueue(ch->port) <= WAKEUP_CHARS) {
1316 ch->statusflags &= ~LOWWAIT;
1321 if (!I_IGNBRK(tp) && (MoxaPortResetBrkCnt(ch->port) > 0)) {
1322 tty_insert_flip_char(tp, 0, TTY_BREAK);
1323 tty_schedule_flip(tp);
1325 if (MoxaPortDCDChange(ch->port)) {
1326 if (ch->asyncflags & ASYNC_CHECK_CD) {
1327 if (MoxaPortDCDON(ch->port))
1328 wake_up_interruptible(&ch->open_wait);
1331 wake_up_interruptible(&ch->open_wait);
1332 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
1339 mod_timer(&moxaTimer, jiffies + HZ / 50);
1342 /******************************************************************************/
1344 static void moxa_set_tty_param(struct tty_struct *tty, struct ktermios *old_termios)
1346 register struct ktermios *ts;
1347 struct moxa_port *ch;
1348 int rts, cts, txflow, rxflow, xany, baud;
1350 ch = (struct moxa_port *) tty->driver_data;
1352 if (ts->c_cflag & CLOCAL)
1353 ch->asyncflags &= ~ASYNC_CHECK_CD;
1355 ch->asyncflags |= ASYNC_CHECK_CD;
1356 rts = cts = txflow = rxflow = xany = 0;
1357 if (ts->c_cflag & CRTSCTS)
1359 if (ts->c_iflag & IXON)
1361 if (ts->c_iflag & IXOFF)
1363 if (ts->c_iflag & IXANY)
1366 /* Clear the features we don't support */
1367 ts->c_cflag &= ~CMSPAR;
1368 MoxaPortFlowCtrl(ch->port, rts, cts, txflow, rxflow, xany);
1369 baud = MoxaPortSetTermio(ch->port, ts, tty_get_baud_rate(tty));
1371 baud = tty_termios_baud_rate(old_termios);
1372 /* Not put the baud rate into the termios data */
1373 tty_encode_baud_rate(tty, baud, baud);
1376 static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
1377 struct moxa_port *ch)
1379 DECLARE_WAITQUEUE(wait,current);
1380 unsigned long flags;
1382 int do_clocal = C_CLOCAL(tty);
1385 * If the device is in the middle of being closed, then block
1386 * until it's done, and then try again.
1388 if (tty_hung_up_p(filp) || (ch->asyncflags & ASYNC_CLOSING)) {
1389 if (ch->asyncflags & ASYNC_CLOSING)
1390 wait_for_completion_interruptible(&ch->close_wait);
1391 #ifdef SERIAL_DO_RESTART
1392 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1395 return (-ERESTARTSYS);
1401 * If non-blocking mode is set, then make the check up front
1404 if (filp->f_flags & O_NONBLOCK) {
1405 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1409 * Block waiting for the carrier detect and the line to become free
1412 add_wait_queue(&ch->open_wait, &wait);
1413 pr_debug("block_til_ready before block: ttys%d, count = %d\n",
1414 ch->port, ch->count);
1415 spin_lock_irqsave(&moxa_lock, flags);
1416 if (!tty_hung_up_p(filp))
1419 spin_unlock_irqrestore(&moxa_lock, flags);
1422 set_current_state(TASK_INTERRUPTIBLE);
1423 if (tty_hung_up_p(filp) ||
1424 !(ch->asyncflags & ASYNC_INITIALIZED)) {
1425 #ifdef SERIAL_DO_RESTART
1426 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1429 retval = -ERESTARTSYS;
1435 if (!(ch->asyncflags & ASYNC_CLOSING) && (do_clocal ||
1436 MoxaPortDCDON(ch->port)))
1439 if (signal_pending(current)) {
1440 retval = -ERESTARTSYS;
1445 set_current_state(TASK_RUNNING);
1446 remove_wait_queue(&ch->open_wait, &wait);
1448 spin_lock_irqsave(&moxa_lock, flags);
1449 if (!tty_hung_up_p(filp))
1452 spin_unlock_irqrestore(&moxa_lock, flags);
1453 pr_debug("block_til_ready after blocking: ttys%d, count = %d\n",
1454 ch->port, ch->count);
1457 /* FIXME: review to see if we need to use set_bit on these */
1458 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1462 static void moxa_setup_empty_event(struct tty_struct *tty)
1464 struct moxa_port *ch = tty->driver_data;
1465 unsigned long flags;
1467 spin_lock_irqsave(&moxa_lock, flags);
1468 ch->statusflags |= EMPTYWAIT;
1469 mod_timer(&moxa_ports[ch->port].emptyTimer, jiffies + HZ);
1470 spin_unlock_irqrestore(&moxa_lock, flags);
1473 static void moxa_check_xmit_empty(unsigned long data)
1475 struct moxa_port *ch;
1477 ch = (struct moxa_port *) data;
1478 if (ch->tty && (ch->statusflags & EMPTYWAIT)) {
1479 if (MoxaPortTxQueue(ch->port) == 0) {
1480 ch->statusflags &= ~EMPTYWAIT;
1481 tty_wakeup(ch->tty);
1484 mod_timer(&moxa_ports[ch->port].emptyTimer,
1485 round_jiffies(jiffies + HZ));
1487 ch->statusflags &= ~EMPTYWAIT;
1490 static void moxa_shut_down(struct moxa_port *ch)
1492 struct tty_struct *tp;
1494 if (!(ch->asyncflags & ASYNC_INITIALIZED))
1499 MoxaPortDisable(ch->port);
1502 * If we're a modem control device and HUPCL is on, drop RTS & DTR.
1504 if (tp->termios->c_cflag & HUPCL)
1505 MoxaPortLineCtrl(ch->port, 0, 0);
1507 ch->asyncflags &= ~ASYNC_INITIALIZED;
1510 static void moxa_receive_data(struct moxa_port *ch)
1512 struct tty_struct *tp;
1513 struct ktermios *ts;
1514 unsigned long flags;
1520 /**************************************************
1521 if ( !tp || !ts || !(ts->c_cflag & CREAD) ) {
1522 *****************************************************/
1524 MoxaPortFlushData(ch->port, 0);
1527 spin_lock_irqsave(&moxa_lock, flags);
1528 MoxaPortReadData(ch->port, tp);
1529 spin_unlock_irqrestore(&moxa_lock, flags);
1530 tty_schedule_flip(tp);
1539 int rxcnt[MAX_PORTS];
1540 int txcnt[MAX_PORTS];
1543 #define DCD_changed 0x01
1544 #define DCD_oldstate 0x80
1546 static int moxaLowWaterChk;
1547 static struct mon_str moxaLog;
1548 static int moxaFuncTout = HZ / 2;
1550 static void moxafunc(void __iomem *, int, ushort);
1551 static void moxa_wait_finish(void __iomem *);
1552 static void moxa_low_water_check(void __iomem *);
1554 /*****************************************************************************
1555 * Driver level functions: *
1556 * 2. MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port); *
1557 * 3. MoxaDriverPoll(void); *
1558 *****************************************************************************/
1560 #define MOXA_GET_IQUEUE (MOXA + 1) /* get input buffered count */
1561 #define MOXA_GET_OQUEUE (MOXA + 2) /* get output buffered count */
1562 #define MOXA_GETDATACOUNT (MOXA + 23)
1563 #define MOXA_GET_IOQUEUE (MOXA + 27)
1564 #define MOXA_FLUSH_QUEUE (MOXA + 28)
1565 #define MOXA_GET_CONF (MOXA + 35) /* configuration */
1566 #define MOXA_GET_MAJOR (MOXA + 63)
1567 #define MOXA_GET_CUMAJOR (MOXA + 64)
1568 #define MOXA_GETMSTATUS (MOXA + 65)
1570 void MoxaPortFlushData(int port, int mode)
1572 void __iomem *ofsAddr;
1573 if ((mode < 0) || (mode > 2))
1575 ofsAddr = moxa_ports[port].tableAddr;
1576 moxafunc(ofsAddr, FC_FlushQueue, mode);
1578 moxa_ports[port].lowChkFlag = 0;
1579 moxa_low_water_check(ofsAddr);
1583 int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port)
1587 int MoxaPortTxQueue(int), MoxaPortRxQueue(int);
1588 void __user *argp = (void __user *)arg;
1590 if (port == MAX_PORTS) {
1591 if ((cmd != MOXA_GET_CONF) && (cmd != MOXA_GETDATACOUNT) &&
1592 (cmd != MOXA_GET_IOQUEUE) && (cmd != MOXA_GET_MAJOR) &&
1593 (cmd != MOXA_GET_CUMAJOR) && (cmd != MOXA_GETMSTATUS))
1597 case MOXA_GETDATACOUNT:
1598 moxaLog.tick = jiffies;
1599 if(copy_to_user(argp, &moxaLog, sizeof(struct mon_str)))
1602 case MOXA_FLUSH_QUEUE:
1603 MoxaPortFlushData(port, arg);
1605 case MOXA_GET_IOQUEUE: {
1606 struct moxaq_str __user *argm = argp;
1607 struct moxaq_str tmp;
1609 for (i = 0; i < MAX_PORTS; i++, argm++) {
1610 memset(&tmp, 0, sizeof(tmp));
1611 if (moxa_ports[i].chkPort) {
1612 tmp.inq = MoxaPortRxQueue(i);
1613 tmp.outq = MoxaPortTxQueue(i);
1615 if (copy_to_user(argm, &tmp, sizeof(tmp)))
1619 } case MOXA_GET_OQUEUE:
1620 i = MoxaPortTxQueue(port);
1621 return put_user(i, (unsigned long __user *)argp);
1622 case MOXA_GET_IQUEUE:
1623 i = MoxaPortRxQueue(port);
1624 return put_user(i, (unsigned long __user *)argp);
1625 case MOXA_GET_MAJOR:
1626 if(copy_to_user(argp, &ttymajor, sizeof(int)))
1629 case MOXA_GET_CUMAJOR:
1631 if(copy_to_user(argp, &i, sizeof(int)))
1634 case MOXA_GETMSTATUS: {
1635 struct mxser_mstatus __user *argm = argp;
1636 struct mxser_mstatus tmp;
1637 struct moxa_port *p;
1639 for (i = 0; i < MAX_PORTS; i++, argm++) {
1641 memset(&tmp, 0, sizeof(tmp));
1645 status = MoxaPortLineStatus(p->port);
1654 if (!p->tty || !p->tty->termios)
1655 tmp.cflag = p->cflag;
1657 tmp.cflag = p->tty->termios->c_cflag;
1659 if (copy_to_user(argm, &tmp, sizeof(tmp)))
1666 return -ENOIOCTLCMD;
1669 int MoxaDriverPoll(void)
1671 struct moxa_board_conf *brd;
1672 register ushort temp;
1674 void __iomem *ofsAddr;
1680 for (card = 0; card < MAX_BOARDS; card++) {
1681 brd = &moxa_boards[card];
1682 if (brd->loadstat == 0)
1684 if ((ports = brd->numPorts) == 0)
1686 if (readb(brd->intPend) == 0xff) {
1687 ip = brd->intTable + readb(brd->intNdx);
1688 p = card * MAX_PORTS_PER_BOARD;
1690 for (port = 0; port < ports; port += 2, p++) {
1691 if ((temp = readw(ip + port)) != 0) {
1692 writew(0, ip + port);
1693 ofsAddr = moxa_ports[p].tableAddr;
1695 writew(readw(ofsAddr + HostStat) & ~WakeupTx, ofsAddr + HostStat);
1696 if (temp & IntrBreak) {
1697 moxa_ports[p].breakCnt++;
1699 if (temp & IntrLine) {
1700 if (readb(ofsAddr + FlagStat) & DCD_state) {
1701 if ((moxa_ports[p].DCDState & DCD_oldstate) == 0)
1702 moxa_ports[p].DCDState = (DCD_oldstate |
1705 if (moxa_ports[p].DCDState & DCD_oldstate)
1706 moxa_ports[p].DCDState = DCD_changed;
1711 writeb(0, brd->intPend);
1713 if (moxaLowWaterChk) {
1714 p = card * MAX_PORTS_PER_BOARD;
1715 for (port = 0; port < ports; port++, p++) {
1716 if (moxa_ports[p].lowChkFlag) {
1717 moxa_ports[p].lowChkFlag = 0;
1718 ofsAddr = moxa_ports[p].tableAddr;
1719 moxa_low_water_check(ofsAddr);
1724 moxaLowWaterChk = 0;
1728 /*****************************************************************************
1729 * Card level function: *
1730 * 1. MoxaPortsOfCard(int cardno); *
1731 *****************************************************************************/
1732 int MoxaPortsOfCard(int cardno)
1735 if (moxa_boards[cardno].boardType == 0)
1737 return (moxa_boards[cardno].numPorts);
1740 /*****************************************************************************
1741 * Port level functions: *
1742 * 1. MoxaPortIsValid(int port); *
1743 * 2. MoxaPortEnable(int port); *
1744 * 3. MoxaPortDisable(int port); *
1745 * 4. MoxaPortGetMaxBaud(int port); *
1746 * 6. MoxaPortSetBaud(int port, long baud); *
1747 * 8. MoxaPortSetTermio(int port, unsigned char *termio); *
1748 * 9. MoxaPortGetLineOut(int port, int *dtrState, int *rtsState); *
1749 * 10. MoxaPortLineCtrl(int port, int dtrState, int rtsState); *
1750 * 11. MoxaPortFlowCtrl(int port, int rts, int cts, int rx, int tx,int xany); *
1751 * 12. MoxaPortLineStatus(int port); *
1752 * 13. MoxaPortDCDChange(int port); *
1753 * 14. MoxaPortDCDON(int port); *
1754 * 15. MoxaPortFlushData(int port, int mode); *
1755 * 16. MoxaPortWriteData(int port, unsigned char * buffer, int length); *
1756 * 17. MoxaPortReadData(int port, struct tty_struct *tty); *
1757 * 20. MoxaPortTxQueue(int port); *
1758 * 21. MoxaPortTxFree(int port); *
1759 * 22. MoxaPortRxQueue(int port); *
1760 * 24. MoxaPortTxDisable(int port); *
1761 * 25. MoxaPortTxEnable(int port); *
1762 * 27. MoxaPortResetBrkCnt(int port); *
1763 * 30. MoxaPortSendBreak(int port, int ticks); *
1764 *****************************************************************************/
1766 * Moxa Port Number Description:
1768 * MOXA serial driver supports up to 4 MOXA-C218/C320 boards. And,
1769 * the port number using in MOXA driver functions will be 0 to 31 for
1770 * first MOXA board, 32 to 63 for second, 64 to 95 for third and 96
1771 * to 127 for fourth. For example, if you setup three MOXA boards,
1772 * first board is C218, second board is C320-16 and third board is
1773 * C320-32. The port number of first board (C218 - 8 ports) is from
1774 * 0 to 7. The port number of second board (C320 - 16 ports) is form
1775 * 32 to 47. The port number of third board (C320 - 32 ports) is from
1776 * 64 to 95. And those port numbers form 8 to 31, 48 to 63 and 96 to
1777 * 127 will be invalid.
1780 * Moxa Functions Description:
1782 * Function 1: Driver initialization routine, this routine must be
1783 * called when initialized driver.
1785 * void MoxaDriverInit();
1788 * Function 2: Moxa driver private IOCTL command processing.
1790 * int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port);
1792 * unsigned int cmd : IOCTL command
1793 * unsigned long arg : IOCTL argument
1794 * int port : port number (0 - 127)
1801 * Function 3: Moxa driver polling process routine.
1803 * int MoxaDriverPoll(void);
1805 * return: 0 ; polling O.K.
1806 * -1 : no any Moxa card.
1809 * Function 4: Get the ports of this card.
1811 * int MoxaPortsOfCard(int cardno);
1813 * int cardno : card number (0 - 3)
1815 * return: 0 : this card is invalid
1819 * Function 5: Check this port is valid or invalid
1821 * int MoxaPortIsValid(int port);
1822 * int port : port number (0 - 127, ref port description)
1824 * return: 0 : this port is invalid
1825 * 1 : this port is valid
1828 * Function 6: Enable this port to start Tx/Rx data.
1830 * void MoxaPortEnable(int port);
1831 * int port : port number (0 - 127)
1834 * Function 7: Disable this port
1836 * void MoxaPortDisable(int port);
1837 * int port : port number (0 - 127)
1840 * Function 8: Get the maximun available baud rate of this port.
1842 * long MoxaPortGetMaxBaud(int port);
1843 * int port : port number (0 - 127)
1845 * return: 0 : this port is invalid
1846 * 38400/57600/115200 bps
1849 * Function 10: Setting baud rate of this port.
1851 * long MoxaPortSetBaud(int port, long baud);
1852 * int port : port number (0 - 127)
1853 * long baud : baud rate (50 - 115200)
1855 * return: 0 : this port is invalid or baud < 50
1856 * 50 - 115200 : the real baud rate set to the port, if
1857 * the argument baud is large than maximun
1858 * available baud rate, the real setting
1859 * baud rate will be the maximun baud rate.
1862 * Function 12: Configure the port.
1864 * int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud);
1865 * int port : port number (0 - 127)
1866 * struct ktermios * termio : termio structure pointer
1867 * speed_t baud : baud rate
1869 * return: -1 : this port is invalid or termio == NULL
1873 * Function 13: Get the DTR/RTS state of this port.
1875 * int MoxaPortGetLineOut(int port, int *dtrState, int *rtsState);
1876 * int port : port number (0 - 127)
1877 * int * dtrState : pointer to INT to receive the current DTR
1878 * state. (if NULL, this function will not
1879 * write to this address)
1880 * int * rtsState : pointer to INT to receive the current RTS
1881 * state. (if NULL, this function will not
1882 * write to this address)
1884 * return: -1 : this port is invalid
1888 * Function 14: Setting the DTR/RTS output state of this port.
1890 * void MoxaPortLineCtrl(int port, int dtrState, int rtsState);
1891 * int port : port number (0 - 127)
1892 * int dtrState : DTR output state (0: off, 1: on)
1893 * int rtsState : RTS output state (0: off, 1: on)
1896 * Function 15: Setting the flow control of this port.
1898 * void MoxaPortFlowCtrl(int port, int rtsFlow, int ctsFlow, int rxFlow,
1899 * int txFlow,int xany);
1900 * int port : port number (0 - 127)
1901 * int rtsFlow : H/W RTS flow control (0: no, 1: yes)
1902 * int ctsFlow : H/W CTS flow control (0: no, 1: yes)
1903 * int rxFlow : S/W Rx XON/XOFF flow control (0: no, 1: yes)
1904 * int txFlow : S/W Tx XON/XOFF flow control (0: no, 1: yes)
1905 * int xany : S/W XANY flow control (0: no, 1: yes)
1908 * Function 16: Get ths line status of this port
1910 * int MoxaPortLineStatus(int port);
1911 * int port : port number (0 - 127)
1913 * return: Bit 0 - CTS state (0: off, 1: on)
1914 * Bit 1 - DSR state (0: off, 1: on)
1915 * Bit 2 - DCD state (0: off, 1: on)
1918 * Function 17: Check the DCD state has changed since the last read
1921 * int MoxaPortDCDChange(int port);
1922 * int port : port number (0 - 127)
1924 * return: 0 : no changed
1925 * 1 : DCD has changed
1928 * Function 18: Check ths current DCD state is ON or not.
1930 * int MoxaPortDCDON(int port);
1931 * int port : port number (0 - 127)
1933 * return: 0 : DCD off
1937 * Function 19: Flush the Rx/Tx buffer data of this port.
1939 * void MoxaPortFlushData(int port, int mode);
1940 * int port : port number (0 - 127)
1942 * 0 : flush the Rx buffer
1943 * 1 : flush the Tx buffer
1944 * 2 : flush the Rx and Tx buffer
1947 * Function 20: Write data.
1949 * int MoxaPortWriteData(int port, unsigned char * buffer, int length);
1950 * int port : port number (0 - 127)
1951 * unsigned char * buffer : pointer to write data buffer.
1952 * int length : write data length
1954 * return: 0 - length : real write data length
1957 * Function 21: Read data.
1959 * int MoxaPortReadData(int port, struct tty_struct *tty);
1960 * int port : port number (0 - 127)
1961 * struct tty_struct *tty : tty for data
1963 * return: 0 - length : real read data length
1966 * Function 24: Get the Tx buffer current queued data bytes
1968 * int MoxaPortTxQueue(int port);
1969 * int port : port number (0 - 127)
1971 * return: .. : Tx buffer current queued data bytes
1974 * Function 25: Get the Tx buffer current free space
1976 * int MoxaPortTxFree(int port);
1977 * int port : port number (0 - 127)
1979 * return: .. : Tx buffer current free space
1982 * Function 26: Get the Rx buffer current queued data bytes
1984 * int MoxaPortRxQueue(int port);
1985 * int port : port number (0 - 127)
1987 * return: .. : Rx buffer current queued data bytes
1990 * Function 28: Disable port data transmission.
1992 * void MoxaPortTxDisable(int port);
1993 * int port : port number (0 - 127)
1996 * Function 29: Enable port data transmission.
1998 * void MoxaPortTxEnable(int port);
1999 * int port : port number (0 - 127)
2002 * Function 31: Get the received BREAK signal count and reset it.
2004 * int MoxaPortResetBrkCnt(int port);
2005 * int port : port number (0 - 127)
2007 * return: 0 - .. : BREAK signal count
2010 * Function 34: Send out a BREAK signal.
2012 * void MoxaPortSendBreak(int port, int ms100);
2013 * int port : port number (0 - 127)
2014 * int ms100 : break signal time interval.
2015 * unit: 100 mini-second. if ms100 == 0, it will
2016 * send out a about 250 ms BREAK signal.
2019 int MoxaPortIsValid(int port)
2023 if (moxa_ports[port].chkPort == 0)
2028 void MoxaPortEnable(int port)
2030 void __iomem *ofsAddr;
2031 int MoxaPortLineStatus(int);
2032 short lowwater = 512;
2034 ofsAddr = moxa_ports[port].tableAddr;
2035 writew(lowwater, ofsAddr + Low_water);
2036 moxa_ports[port].breakCnt = 0;
2037 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) ||
2038 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) {
2039 moxafunc(ofsAddr, FC_SetBreakIrq, 0);
2041 writew(readw(ofsAddr + HostStat) | WakeupBreak, ofsAddr + HostStat);
2044 moxafunc(ofsAddr, FC_SetLineIrq, Magic_code);
2045 moxafunc(ofsAddr, FC_FlushQueue, 2);
2047 moxafunc(ofsAddr, FC_EnableCH, Magic_code);
2048 MoxaPortLineStatus(port);
2051 void MoxaPortDisable(int port)
2053 void __iomem *ofsAddr = moxa_ports[port].tableAddr;
2055 moxafunc(ofsAddr, FC_SetFlowCtl, 0); /* disable flow control */
2056 moxafunc(ofsAddr, FC_ClrLineIrq, Magic_code);
2057 writew(0, ofsAddr + HostStat);
2058 moxafunc(ofsAddr, FC_DisableCH, Magic_code);
2061 long MoxaPortGetMaxBaud(int port)
2063 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) ||
2064 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI))
2071 long MoxaPortSetBaud(int port, long baud)
2073 void __iomem *ofsAddr;
2077 if ((baud < 50L) || ((max = MoxaPortGetMaxBaud(port)) == 0))
2079 ofsAddr = moxa_ports[port].tableAddr;
2083 clock = 614400L; /* for 9.8304 Mhz : max. 38400 bps */
2084 else if (max == 57600L)
2085 clock = 691200L; /* for 11.0592 Mhz : max. 57600 bps */
2087 clock = 921600L; /* for 14.7456 Mhz : max. 115200 bps */
2089 moxafunc(ofsAddr, FC_SetBaud, val);
2091 moxa_ports[port].curBaud = baud;
2095 int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud)
2097 void __iomem *ofsAddr;
2101 if (moxa_ports[port].chkPort == 0 || termio == 0)
2103 ofsAddr = moxa_ports[port].tableAddr;
2104 cflag = termio->c_cflag; /* termio->c_cflag */
2106 mode = termio->c_cflag & CSIZE;
2109 else if (mode == CS6)
2111 else if (mode == CS7)
2113 else if (mode == CS8)
2116 if (termio->c_cflag & CSTOPB) {
2124 if (termio->c_cflag & PARENB) {
2125 if (termio->c_cflag & PARODD)
2132 moxafunc(ofsAddr, FC_SetDataMode, (ushort) mode);
2134 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) ||
2135 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) {
2136 if (baud >= 921600L)
2139 baud = MoxaPortSetBaud(port, baud);
2141 if (termio->c_iflag & (IXON | IXOFF | IXANY)) {
2142 writeb(termio->c_cc[VSTART], ofsAddr + FuncArg);
2143 writeb(termio->c_cc[VSTOP], ofsAddr + FuncArg1);
2144 writeb(FC_SetXonXoff, ofsAddr + FuncCode);
2145 moxa_wait_finish(ofsAddr);
2151 int MoxaPortGetLineOut(int port, int *dtrState, int *rtsState)
2154 if (!MoxaPortIsValid(port))
2157 if (moxa_ports[port].lineCtrl & DTR_ON)
2163 if (moxa_ports[port].lineCtrl & RTS_ON)
2171 void MoxaPortLineCtrl(int port, int dtr, int rts)
2173 void __iomem *ofsAddr;
2176 ofsAddr = moxa_ports[port].tableAddr;
2182 moxa_ports[port].lineCtrl = mode;
2183 moxafunc(ofsAddr, FC_LineControl, mode);
2186 void MoxaPortFlowCtrl(int port, int rts, int cts, int txflow, int rxflow, int txany)
2188 void __iomem *ofsAddr;
2191 ofsAddr = moxa_ports[port].tableAddr;
2194 mode |= RTS_FlowCtl;
2196 mode |= CTS_FlowCtl;
2203 moxafunc(ofsAddr, FC_SetFlowCtl, mode);
2206 int MoxaPortLineStatus(int port)
2208 void __iomem *ofsAddr;
2211 ofsAddr = moxa_ports[port].tableAddr;
2212 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) ||
2213 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) {
2214 moxafunc(ofsAddr, FC_LineStatus, 0);
2215 val = readw(ofsAddr + FuncArg);
2217 val = readw(ofsAddr + FlagStat) >> 4;
2222 if ((moxa_ports[port].DCDState & DCD_oldstate) == 0)
2223 moxa_ports[port].DCDState = (DCD_oldstate | DCD_changed);
2225 if (moxa_ports[port].DCDState & DCD_oldstate)
2226 moxa_ports[port].DCDState = DCD_changed;
2232 int MoxaPortDCDChange(int port)
2236 if (moxa_ports[port].chkPort == 0)
2238 n = moxa_ports[port].DCDState;
2239 moxa_ports[port].DCDState &= ~DCD_changed;
2244 int MoxaPortDCDON(int port)
2248 if (moxa_ports[port].chkPort == 0)
2250 if (moxa_ports[port].DCDState & DCD_oldstate)
2257 int MoxaPortWriteData(int port, unsigned char * buffer, int len)
2262 ushort head, tx_mask, spage, epage;
2263 ushort pageno, pageofs, bufhead;
2264 void __iomem *baseAddr, *ofsAddr, *ofs;
2266 ofsAddr = moxa_ports[port].tableAddr;
2267 baseAddr = moxa_boards[port / MAX_PORTS_PER_BOARD].basemem;
2268 tx_mask = readw(ofsAddr + TX_mask);
2269 spage = readw(ofsAddr + Page_txb);
2270 epage = readw(ofsAddr + EndPage_txb);
2271 tail = readw(ofsAddr + TXwptr);
2272 head = readw(ofsAddr + TXrptr);
2273 c = (head > tail) ? (head - tail - 1)
2274 : (head - tail + tx_mask);
2277 moxaLog.txcnt[port] += c;
2279 if (spage == epage) {
2280 bufhead = readw(ofsAddr + Ofs_txb);
2281 writew(spage, baseAddr + Control_reg);
2284 len = head - tail - 1;
2286 len = tx_mask + 1 - tail;
2287 len = (c > len) ? len : c;
2288 ofs = baseAddr + DynPage_addr + bufhead + tail;
2289 for (i = 0; i < len; i++)
2290 writeb(*buffer++, ofs + i);
2291 tail = (tail + len) & tx_mask;
2294 writew(tail, ofsAddr + TXwptr);
2297 pageno = spage + (tail >> 13);
2298 pageofs = tail & Page_mask;
2300 cnt = Page_size - pageofs;
2304 writeb(pageno, baseAddr + Control_reg);
2305 ofs = baseAddr + DynPage_addr + pageofs;
2306 for (i = 0; i < cnt; i++)
2307 writeb(*buffer++, ofs + i);
2309 writew((tail + len) & tx_mask, ofsAddr + TXwptr);
2312 if (++pageno == epage)
2317 writeb(1, ofsAddr + CD180TXirq); /* start to send */
2321 int MoxaPortReadData(int port, struct tty_struct *tty)
2323 register ushort head, pageofs;
2324 int i, count, cnt, len, total, remain;
2325 ushort tail, rx_mask, spage, epage;
2326 ushort pageno, bufhead;
2327 void __iomem *baseAddr, *ofsAddr, *ofs;
2329 ofsAddr = moxa_ports[port].tableAddr;
2330 baseAddr = moxa_boards[port / MAX_PORTS_PER_BOARD].basemem;
2331 head = readw(ofsAddr + RXrptr);
2332 tail = readw(ofsAddr + RXwptr);
2333 rx_mask = readw(ofsAddr + RX_mask);
2334 spage = readw(ofsAddr + Page_rxb);
2335 epage = readw(ofsAddr + EndPage_rxb);
2336 count = (tail >= head) ? (tail - head)
2337 : (tail - head + rx_mask + 1);
2342 remain = count - total;
2343 moxaLog.rxcnt[port] += total;
2345 if (spage == epage) {
2346 bufhead = readw(ofsAddr + Ofs_rxb);
2347 writew(spage, baseAddr + Control_reg);
2352 len = rx_mask + 1 - head;
2353 len = (count > len) ? len : count;
2354 ofs = baseAddr + DynPage_addr + bufhead + head;
2355 for (i = 0; i < len; i++)
2356 tty_insert_flip_char(tty, readb(ofs + i), TTY_NORMAL);
2357 head = (head + len) & rx_mask;
2360 writew(head, ofsAddr + RXrptr);
2363 pageno = spage + (head >> 13);
2364 pageofs = head & Page_mask;
2366 cnt = Page_size - pageofs;
2370 writew(pageno, baseAddr + Control_reg);
2371 ofs = baseAddr + DynPage_addr + pageofs;
2372 for (i = 0; i < cnt; i++)
2373 tty_insert_flip_char(tty, readb(ofs + i), TTY_NORMAL);
2375 writew((head + len) & rx_mask, ofsAddr + RXrptr);
2378 if (++pageno == epage)
2383 if ((readb(ofsAddr + FlagStat) & Xoff_state) && (remain < LowWater)) {
2384 moxaLowWaterChk = 1;
2385 moxa_ports[port].lowChkFlag = 1;
2391 int MoxaPortTxQueue(int port)
2393 void __iomem *ofsAddr;
2394 ushort rptr, wptr, mask;
2397 ofsAddr = moxa_ports[port].tableAddr;
2398 rptr = readw(ofsAddr + TXrptr);
2399 wptr = readw(ofsAddr + TXwptr);
2400 mask = readw(ofsAddr + TX_mask);
2401 len = (wptr - rptr) & mask;
2405 int MoxaPortTxFree(int port)
2407 void __iomem *ofsAddr;
2408 ushort rptr, wptr, mask;
2411 ofsAddr = moxa_ports[port].tableAddr;
2412 rptr = readw(ofsAddr + TXrptr);
2413 wptr = readw(ofsAddr + TXwptr);
2414 mask = readw(ofsAddr + TX_mask);
2415 len = mask - ((wptr - rptr) & mask);
2419 int MoxaPortRxQueue(int port)
2421 void __iomem *ofsAddr;
2422 ushort rptr, wptr, mask;
2425 ofsAddr = moxa_ports[port].tableAddr;
2426 rptr = readw(ofsAddr + RXrptr);
2427 wptr = readw(ofsAddr + RXwptr);
2428 mask = readw(ofsAddr + RX_mask);
2429 len = (wptr - rptr) & mask;
2434 void MoxaPortTxDisable(int port)
2436 void __iomem *ofsAddr;
2438 ofsAddr = moxa_ports[port].tableAddr;
2439 moxafunc(ofsAddr, FC_SetXoffState, Magic_code);
2442 void MoxaPortTxEnable(int port)
2444 void __iomem *ofsAddr;
2446 ofsAddr = moxa_ports[port].tableAddr;
2447 moxafunc(ofsAddr, FC_SetXonState, Magic_code);
2451 int MoxaPortResetBrkCnt(int port)
2454 cnt = moxa_ports[port].breakCnt;
2455 moxa_ports[port].breakCnt = 0;
2460 void MoxaPortSendBreak(int port, int ms100)
2462 void __iomem *ofsAddr;
2464 ofsAddr = moxa_ports[port].tableAddr;
2466 moxafunc(ofsAddr, FC_SendBreak, Magic_code);
2469 moxafunc(ofsAddr, FC_SendBreak, Magic_code);
2472 moxafunc(ofsAddr, FC_StopBreak, Magic_code);
2475 static int moxa_get_serial_info(struct moxa_port *info,
2476 struct serial_struct __user *retinfo)
2478 struct serial_struct tmp;
2480 memset(&tmp, 0, sizeof(tmp));
2481 tmp.type = info->type;
2482 tmp.line = info->port;
2485 tmp.flags = info->asyncflags;
2486 tmp.baud_base = 921600;
2487 tmp.close_delay = info->close_delay;
2488 tmp.closing_wait = info->closing_wait;
2489 tmp.custom_divisor = 0;
2491 if(copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2497 static int moxa_set_serial_info(struct moxa_port *info,
2498 struct serial_struct __user *new_info)
2500 struct serial_struct new_serial;
2502 if(copy_from_user(&new_serial, new_info, sizeof(new_serial)))
2505 if ((new_serial.irq != 0) ||
2506 (new_serial.port != 0) ||
2507 // (new_serial.type != info->type) ||
2508 (new_serial.custom_divisor != 0) ||
2509 (new_serial.baud_base != 921600))
2512 if (!capable(CAP_SYS_ADMIN)) {
2513 if (((new_serial.flags & ~ASYNC_USR_MASK) !=
2514 (info->asyncflags & ~ASYNC_USR_MASK)))
2517 info->close_delay = new_serial.close_delay * HZ / 100;
2518 info->closing_wait = new_serial.closing_wait * HZ / 100;
2521 new_serial.flags = (new_serial.flags & ~ASYNC_FLAGS);
2522 new_serial.flags |= (info->asyncflags & ASYNC_FLAGS);
2524 if (new_serial.type == PORT_16550A) {
2525 MoxaSetFifo(info->port, 1);
2527 MoxaSetFifo(info->port, 0);
2530 info->type = new_serial.type;
2536 /*****************************************************************************
2537 * Static local functions: *
2538 *****************************************************************************/
2539 static void moxafunc(void __iomem *ofsAddr, int cmd, ushort arg)
2542 writew(arg, ofsAddr + FuncArg);
2543 writew(cmd, ofsAddr + FuncCode);
2544 moxa_wait_finish(ofsAddr);
2547 static void moxa_wait_finish(void __iomem *ofsAddr)
2552 while (readw(ofsAddr + FuncCode) != 0) {
2554 if ((j - i) > moxaFuncTout) {
2560 static void moxa_low_water_check(void __iomem *ofsAddr)
2563 ushort rptr, wptr, mask;
2565 if (readb(ofsAddr + FlagStat) & Xoff_state) {
2566 rptr = readw(ofsAddr + RXrptr);
2567 wptr = readw(ofsAddr + RXwptr);
2568 mask = readw(ofsAddr + RX_mask);
2569 len = (wptr - rptr) & mask;
2570 if (len <= Low_water)
2571 moxafunc(ofsAddr, FC_SendXon, 0);
2575 static void MoxaSetFifo(int port, int enable)
2577 void __iomem *ofsAddr = moxa_ports[port].tableAddr;
2580 moxafunc(ofsAddr, FC_SetRxFIFOTrig, 0);
2581 moxafunc(ofsAddr, FC_SetTxFIFOCnt, 1);
2583 moxafunc(ofsAddr, FC_SetRxFIFOTrig, 3);
2584 moxafunc(ofsAddr, FC_SetTxFIFOCnt, 16);