Char: moxa, remove useless tty functions
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / char / moxa.c
blob7f8773523fbf11876237fcd97fe0502603ba3b4a
1 /*****************************************************************************/
2 /*
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
18 * for : LINUX
19 * date : 1999/1/7
20 * version : 5.1
23 #include <linux/module.h>
24 #include <linux/types.h>
25 #include <linux/mm.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>
46 #include <asm/system.h>
47 #include <asm/io.h>
48 #include <asm/uaccess.h>
50 #include "moxa.h"
52 #define MOXA_VERSION "5.1k"
54 #define MOXA_FW_HDRLEN 32
56 #define MOXAMAJOR 172
58 #define MAX_BOARDS 4 /* Don't change this value */
59 #define MAX_PORTS_PER_BOARD 32 /* Don't change this value */
60 #define MAX_PORTS (MAX_BOARDS * MAX_PORTS_PER_BOARD)
63 * Define the Moxa PCI vendor and device IDs.
65 #define MOXA_BUS_TYPE_ISA 0
66 #define MOXA_BUS_TYPE_PCI 1
68 enum {
69 MOXA_BOARD_C218_PCI = 1,
70 MOXA_BOARD_C218_ISA,
71 MOXA_BOARD_C320_PCI,
72 MOXA_BOARD_C320_ISA,
73 MOXA_BOARD_CP204J,
76 static char *moxa_brdname[] =
78 "C218 Turbo PCI series",
79 "C218 Turbo ISA series",
80 "C320 Turbo PCI series",
81 "C320 Turbo ISA series",
82 "CP-204J series",
85 #ifdef CONFIG_PCI
86 static struct pci_device_id moxa_pcibrds[] = {
87 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C218),
88 .driver_data = MOXA_BOARD_C218_PCI },
89 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C320),
90 .driver_data = MOXA_BOARD_C320_PCI },
91 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP204J),
92 .driver_data = MOXA_BOARD_CP204J },
93 { 0 }
95 MODULE_DEVICE_TABLE(pci, moxa_pcibrds);
96 #endif /* CONFIG_PCI */
98 struct moxa_port;
100 static struct moxa_board_conf {
101 int boardType;
102 int numPorts;
103 int busType;
105 unsigned int ready;
107 struct moxa_port *ports;
109 void __iomem *basemem;
110 void __iomem *intNdx;
111 void __iomem *intPend;
112 void __iomem *intTable;
113 } moxa_boards[MAX_BOARDS];
115 struct mxser_mstatus {
116 tcflag_t cflag;
117 int cts;
118 int dsr;
119 int ri;
120 int dcd;
123 struct moxaq_str {
124 int inq;
125 int outq;
128 struct moxa_port {
129 struct moxa_board_conf *board;
130 struct tty_struct *tty;
131 void __iomem *tableAddr;
133 int type;
134 int close_delay;
135 unsigned int count;
136 int asyncflags;
137 int cflag;
138 unsigned long statusflags;
139 wait_queue_head_t open_wait;
141 u8 DCDState;
142 u8 lineCtrl;
143 u8 lowChkFlag;
146 struct mon_str {
147 int tick;
148 int rxcnt[MAX_PORTS];
149 int txcnt[MAX_PORTS];
152 /* statusflags */
153 #define TXSTOPPED 0x1
154 #define LOWWAIT 0x2
155 #define EMPTYWAIT 0x4
156 #define THROTTLE 0x8
158 #define SERIAL_DO_RESTART
160 #define WAKEUP_CHARS 256
162 static int ttymajor = MOXAMAJOR;
163 static struct mon_str moxaLog;
164 static unsigned int moxaFuncTout = HZ / 2;
165 static unsigned int moxaLowWaterChk;
166 static DEFINE_MUTEX(moxa_openlock);
167 /* Variables for insmod */
168 #ifdef MODULE
169 static unsigned long baseaddr[MAX_BOARDS];
170 static unsigned int type[MAX_BOARDS];
171 static unsigned int numports[MAX_BOARDS];
172 #endif
174 MODULE_AUTHOR("William Chen");
175 MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver");
176 MODULE_LICENSE("GPL");
177 #ifdef MODULE
178 module_param_array(type, uint, NULL, 0);
179 MODULE_PARM_DESC(type, "card type: C218=2, C320=4");
180 module_param_array(baseaddr, ulong, NULL, 0);
181 MODULE_PARM_DESC(baseaddr, "base address");
182 module_param_array(numports, uint, NULL, 0);
183 MODULE_PARM_DESC(numports, "numports (ignored for C218)");
184 #endif
185 module_param(ttymajor, int, 0);
188 * static functions:
190 static int moxa_open(struct tty_struct *, struct file *);
191 static void moxa_close(struct tty_struct *, struct file *);
192 static int moxa_write(struct tty_struct *, const unsigned char *, int);
193 static int moxa_write_room(struct tty_struct *);
194 static void moxa_flush_buffer(struct tty_struct *);
195 static int moxa_chars_in_buffer(struct tty_struct *);
196 static void moxa_throttle(struct tty_struct *);
197 static void moxa_unthrottle(struct tty_struct *);
198 static void moxa_set_termios(struct tty_struct *, struct ktermios *);
199 static void moxa_stop(struct tty_struct *);
200 static void moxa_start(struct tty_struct *);
201 static void moxa_hangup(struct tty_struct *);
202 static int moxa_tiocmget(struct tty_struct *tty, struct file *file);
203 static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
204 unsigned int set, unsigned int clear);
205 static void moxa_poll(unsigned long);
206 static void moxa_set_tty_param(struct tty_struct *, struct ktermios *);
207 static void moxa_setup_empty_event(struct tty_struct *);
208 static void moxa_shut_down(struct moxa_port *);
210 * moxa board interface functions:
212 static void MoxaPortEnable(struct moxa_port *);
213 static void MoxaPortDisable(struct moxa_port *);
214 static int MoxaPortSetTermio(struct moxa_port *, struct ktermios *, speed_t);
215 static int MoxaPortGetLineOut(struct moxa_port *, int *, int *);
216 static void MoxaPortLineCtrl(struct moxa_port *, int, int);
217 static void MoxaPortFlowCtrl(struct moxa_port *, int, int, int, int, int);
218 static int MoxaPortLineStatus(struct moxa_port *);
219 static void MoxaPortFlushData(struct moxa_port *, int);
220 static int MoxaPortWriteData(struct moxa_port *, const unsigned char *, int);
221 static int MoxaPortReadData(struct moxa_port *);
222 static int MoxaPortTxQueue(struct moxa_port *);
223 static int MoxaPortRxQueue(struct moxa_port *);
224 static int MoxaPortTxFree(struct moxa_port *);
225 static void MoxaPortTxDisable(struct moxa_port *);
226 static void MoxaPortTxEnable(struct moxa_port *);
227 static int moxa_get_serial_info(struct moxa_port *, struct serial_struct __user *);
228 static int moxa_set_serial_info(struct moxa_port *, struct serial_struct __user *);
229 static void MoxaSetFifo(struct moxa_port *port, int enable);
232 * I/O functions
235 static void moxa_wait_finish(void __iomem *ofsAddr)
237 unsigned long end = jiffies + moxaFuncTout;
239 while (readw(ofsAddr + FuncCode) != 0)
240 if (time_after(jiffies, end))
241 return;
242 if (readw(ofsAddr + FuncCode) != 0 && printk_ratelimit())
243 printk(KERN_WARNING "moxa function expired\n");
246 static void moxafunc(void __iomem *ofsAddr, u16 cmd, u16 arg)
248 writew(arg, ofsAddr + FuncArg);
249 writew(cmd, ofsAddr + FuncCode);
250 moxa_wait_finish(ofsAddr);
253 static void moxa_low_water_check(void __iomem *ofsAddr)
255 u16 rptr, wptr, mask, len;
257 if (readb(ofsAddr + FlagStat) & Xoff_state) {
258 rptr = readw(ofsAddr + RXrptr);
259 wptr = readw(ofsAddr + RXwptr);
260 mask = readw(ofsAddr + RX_mask);
261 len = (wptr - rptr) & mask;
262 if (len <= Low_water)
263 moxafunc(ofsAddr, FC_SendXon, 0);
268 * TTY operations
271 static int moxa_ioctl(struct tty_struct *tty, struct file *file,
272 unsigned int cmd, unsigned long arg)
274 struct moxa_port *ch = tty->driver_data;
275 void __user *argp = (void __user *)arg;
276 int status, ret = 0;
278 if (tty->index == MAX_PORTS) {
279 if (cmd != MOXA_GETDATACOUNT && cmd != MOXA_GET_IOQUEUE &&
280 cmd != MOXA_GETMSTATUS)
281 return -EINVAL;
282 } else if (!ch)
283 return -ENODEV;
285 switch (cmd) {
286 case MOXA_GETDATACOUNT:
287 moxaLog.tick = jiffies;
288 if (copy_to_user(argp, &moxaLog, sizeof(moxaLog)))
289 ret = -EFAULT;
290 break;
291 case MOXA_FLUSH_QUEUE:
292 MoxaPortFlushData(ch, arg);
293 break;
294 case MOXA_GET_IOQUEUE: {
295 struct moxaq_str __user *argm = argp;
296 struct moxaq_str tmp;
297 struct moxa_port *p;
298 unsigned int i, j;
300 mutex_lock(&moxa_openlock);
301 for (i = 0; i < MAX_BOARDS; i++) {
302 p = moxa_boards[i].ports;
303 for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) {
304 memset(&tmp, 0, sizeof(tmp));
305 if (moxa_boards[i].ready) {
306 tmp.inq = MoxaPortRxQueue(p);
307 tmp.outq = MoxaPortTxQueue(p);
309 if (copy_to_user(argm, &tmp, sizeof(tmp))) {
310 mutex_unlock(&moxa_openlock);
311 return -EFAULT;
315 mutex_unlock(&moxa_openlock);
316 break;
317 } case MOXA_GET_OQUEUE:
318 status = MoxaPortTxQueue(ch);
319 ret = put_user(status, (unsigned long __user *)argp);
320 break;
321 case MOXA_GET_IQUEUE:
322 status = MoxaPortRxQueue(ch);
323 ret = put_user(status, (unsigned long __user *)argp);
324 break;
325 case MOXA_GETMSTATUS: {
326 struct mxser_mstatus __user *argm = argp;
327 struct mxser_mstatus tmp;
328 struct moxa_port *p;
329 unsigned int i, j;
331 mutex_lock(&moxa_openlock);
332 for (i = 0; i < MAX_BOARDS; i++) {
333 p = moxa_boards[i].ports;
334 for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) {
335 memset(&tmp, 0, sizeof(tmp));
336 if (!moxa_boards[i].ready)
337 goto copy;
339 status = MoxaPortLineStatus(p);
340 if (status & 1)
341 tmp.cts = 1;
342 if (status & 2)
343 tmp.dsr = 1;
344 if (status & 4)
345 tmp.dcd = 1;
347 if (!p->tty || !p->tty->termios)
348 tmp.cflag = p->cflag;
349 else
350 tmp.cflag = p->tty->termios->c_cflag;
351 copy:
352 if (copy_to_user(argm, &tmp, sizeof(tmp))) {
353 mutex_unlock(&moxa_openlock);
354 return -EFAULT;
358 mutex_unlock(&moxa_openlock);
359 break;
361 case TIOCGSERIAL:
362 mutex_lock(&moxa_openlock);
363 ret = moxa_get_serial_info(ch, argp);
364 mutex_unlock(&moxa_openlock);
365 break;
366 case TIOCSSERIAL:
367 mutex_lock(&moxa_openlock);
368 ret = moxa_set_serial_info(ch, argp);
369 mutex_unlock(&moxa_openlock);
370 break;
371 default:
372 ret = -ENOIOCTLCMD;
374 return ret;
377 static void moxa_break_ctl(struct tty_struct *tty, int state)
379 struct moxa_port *port = tty->driver_data;
381 moxafunc(port->tableAddr, state ? FC_SendBreak : FC_StopBreak,
382 Magic_code);
385 static const struct tty_operations moxa_ops = {
386 .open = moxa_open,
387 .close = moxa_close,
388 .write = moxa_write,
389 .write_room = moxa_write_room,
390 .flush_buffer = moxa_flush_buffer,
391 .chars_in_buffer = moxa_chars_in_buffer,
392 .ioctl = moxa_ioctl,
393 .throttle = moxa_throttle,
394 .unthrottle = moxa_unthrottle,
395 .set_termios = moxa_set_termios,
396 .stop = moxa_stop,
397 .start = moxa_start,
398 .hangup = moxa_hangup,
399 .break_ctl = moxa_break_ctl,
400 .tiocmget = moxa_tiocmget,
401 .tiocmset = moxa_tiocmset,
404 static struct tty_driver *moxaDriver;
405 static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0);
406 static DEFINE_SPINLOCK(moxa_lock);
409 * HW init
412 static int moxa_check_fw_model(struct moxa_board_conf *brd, u8 model)
414 switch (brd->boardType) {
415 case MOXA_BOARD_C218_ISA:
416 case MOXA_BOARD_C218_PCI:
417 if (model != 1)
418 goto err;
419 break;
420 case MOXA_BOARD_CP204J:
421 if (model != 3)
422 goto err;
423 break;
424 default:
425 if (model != 2)
426 goto err;
427 break;
429 return 0;
430 err:
431 return -EINVAL;
434 static int moxa_check_fw(const void *ptr)
436 const __le16 *lptr = ptr;
438 if (*lptr != cpu_to_le16(0x7980))
439 return -EINVAL;
441 return 0;
444 static int moxa_load_bios(struct moxa_board_conf *brd, const u8 *buf,
445 size_t len)
447 void __iomem *baseAddr = brd->basemem;
448 u16 tmp;
450 writeb(HW_reset, baseAddr + Control_reg); /* reset */
451 msleep(10);
452 memset_io(baseAddr, 0, 4096);
453 memcpy_toio(baseAddr, buf, len); /* download BIOS */
454 writeb(0, baseAddr + Control_reg); /* restart */
456 msleep(2000);
458 switch (brd->boardType) {
459 case MOXA_BOARD_C218_ISA:
460 case MOXA_BOARD_C218_PCI:
461 tmp = readw(baseAddr + C218_key);
462 if (tmp != C218_KeyCode)
463 goto err;
464 break;
465 case MOXA_BOARD_CP204J:
466 tmp = readw(baseAddr + C218_key);
467 if (tmp != CP204J_KeyCode)
468 goto err;
469 break;
470 default:
471 tmp = readw(baseAddr + C320_key);
472 if (tmp != C320_KeyCode)
473 goto err;
474 tmp = readw(baseAddr + C320_status);
475 if (tmp != STS_init) {
476 printk(KERN_ERR "MOXA: bios upload failed -- CPU/Basic "
477 "module not found\n");
478 return -EIO;
480 break;
483 return 0;
484 err:
485 printk(KERN_ERR "MOXA: bios upload failed -- board not found\n");
486 return -EIO;
489 static int moxa_load_320b(struct moxa_board_conf *brd, const u8 *ptr,
490 size_t len)
492 void __iomem *baseAddr = brd->basemem;
494 if (len < 7168) {
495 printk(KERN_ERR "MOXA: invalid 320 bios -- too short\n");
496 return -EINVAL;
499 writew(len - 7168 - 2, baseAddr + C320bapi_len);
500 writeb(1, baseAddr + Control_reg); /* Select Page 1 */
501 memcpy_toio(baseAddr + DynPage_addr, ptr, 7168);
502 writeb(2, baseAddr + Control_reg); /* Select Page 2 */
503 memcpy_toio(baseAddr + DynPage_addr, ptr + 7168, len - 7168);
505 return 0;
508 static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr,
509 size_t len)
511 void __iomem *baseAddr = brd->basemem;
512 const u16 *uptr = ptr;
513 size_t wlen, len2, j;
514 unsigned long key, loadbuf, loadlen, checksum, checksum_ok;
515 unsigned int i, retry, c320;
516 u16 usum, keycode;
518 c320 = brd->boardType == MOXA_BOARD_C320_PCI ||
519 brd->boardType == MOXA_BOARD_C320_ISA;
520 keycode = (brd->boardType == MOXA_BOARD_CP204J) ? CP204J_KeyCode :
521 C218_KeyCode;
523 switch (brd->boardType) {
524 case MOXA_BOARD_CP204J:
525 case MOXA_BOARD_C218_ISA:
526 case MOXA_BOARD_C218_PCI:
527 key = C218_key;
528 loadbuf = C218_LoadBuf;
529 loadlen = C218DLoad_len;
530 checksum = C218check_sum;
531 checksum_ok = C218chksum_ok;
532 break;
533 default:
534 key = C320_key;
535 keycode = C320_KeyCode;
536 loadbuf = C320_LoadBuf;
537 loadlen = C320DLoad_len;
538 checksum = C320check_sum;
539 checksum_ok = C320chksum_ok;
540 break;
543 usum = 0;
544 wlen = len >> 1;
545 for (i = 0; i < wlen; i++)
546 usum += le16_to_cpu(uptr[i]);
547 retry = 0;
548 do {
549 wlen = len >> 1;
550 j = 0;
551 while (wlen) {
552 len2 = (wlen > 2048) ? 2048 : wlen;
553 wlen -= len2;
554 memcpy_toio(baseAddr + loadbuf, ptr + j, len2 << 1);
555 j += len2 << 1;
557 writew(len2, baseAddr + loadlen);
558 writew(0, baseAddr + key);
559 for (i = 0; i < 100; i++) {
560 if (readw(baseAddr + key) == keycode)
561 break;
562 msleep(10);
564 if (readw(baseAddr + key) != keycode)
565 return -EIO;
567 writew(0, baseAddr + loadlen);
568 writew(usum, baseAddr + checksum);
569 writew(0, baseAddr + key);
570 for (i = 0; i < 100; i++) {
571 if (readw(baseAddr + key) == keycode)
572 break;
573 msleep(10);
575 retry++;
576 } while ((readb(baseAddr + checksum_ok) != 1) && (retry < 3));
577 if (readb(baseAddr + checksum_ok) != 1)
578 return -EIO;
580 writew(0, baseAddr + key);
581 for (i = 0; i < 600; i++) {
582 if (readw(baseAddr + Magic_no) == Magic_code)
583 break;
584 msleep(10);
586 if (readw(baseAddr + Magic_no) != Magic_code)
587 return -EIO;
589 if (c320) {
590 if (brd->busType == MOXA_BUS_TYPE_PCI) { /* ASIC board */
591 writew(0x3800, baseAddr + TMS320_PORT1);
592 writew(0x3900, baseAddr + TMS320_PORT2);
593 writew(28499, baseAddr + TMS320_CLOCK);
594 } else {
595 writew(0x3200, baseAddr + TMS320_PORT1);
596 writew(0x3400, baseAddr + TMS320_PORT2);
597 writew(19999, baseAddr + TMS320_CLOCK);
600 writew(1, baseAddr + Disable_IRQ);
601 writew(0, baseAddr + Magic_no);
602 for (i = 0; i < 500; i++) {
603 if (readw(baseAddr + Magic_no) == Magic_code)
604 break;
605 msleep(10);
607 if (readw(baseAddr + Magic_no) != Magic_code)
608 return -EIO;
610 if (c320) {
611 j = readw(baseAddr + Module_cnt);
612 if (j <= 0)
613 return -EIO;
614 brd->numPorts = j * 8;
615 writew(j, baseAddr + Module_no);
616 writew(0, baseAddr + Magic_no);
617 for (i = 0; i < 600; i++) {
618 if (readw(baseAddr + Magic_no) == Magic_code)
619 break;
620 msleep(10);
622 if (readw(baseAddr + Magic_no) != Magic_code)
623 return -EIO;
625 brd->intNdx = baseAddr + IRQindex;
626 brd->intPend = baseAddr + IRQpending;
627 brd->intTable = baseAddr + IRQtable;
629 return 0;
632 static int moxa_load_code(struct moxa_board_conf *brd, const void *ptr,
633 size_t len)
635 void __iomem *ofsAddr, *baseAddr = brd->basemem;
636 struct moxa_port *port;
637 int retval, i;
639 if (len % 2) {
640 printk(KERN_ERR "MOXA: bios length is not even\n");
641 return -EINVAL;
644 retval = moxa_real_load_code(brd, ptr, len); /* may change numPorts */
645 if (retval)
646 return retval;
648 switch (brd->boardType) {
649 case MOXA_BOARD_C218_ISA:
650 case MOXA_BOARD_C218_PCI:
651 case MOXA_BOARD_CP204J:
652 port = brd->ports;
653 for (i = 0; i < brd->numPorts; i++, port++) {
654 port->board = brd;
655 port->DCDState = 0;
656 port->tableAddr = baseAddr + Extern_table +
657 Extern_size * i;
658 ofsAddr = port->tableAddr;
659 writew(C218rx_mask, ofsAddr + RX_mask);
660 writew(C218tx_mask, ofsAddr + TX_mask);
661 writew(C218rx_spage + i * C218buf_pageno, ofsAddr + Page_rxb);
662 writew(readw(ofsAddr + Page_rxb) + C218rx_pageno, ofsAddr + EndPage_rxb);
664 writew(C218tx_spage + i * C218buf_pageno, ofsAddr + Page_txb);
665 writew(readw(ofsAddr + Page_txb) + C218tx_pageno, ofsAddr + EndPage_txb);
668 break;
669 default:
670 port = brd->ports;
671 for (i = 0; i < brd->numPorts; i++, port++) {
672 port->board = brd;
673 port->DCDState = 0;
674 port->tableAddr = baseAddr + Extern_table +
675 Extern_size * i;
676 ofsAddr = port->tableAddr;
677 switch (brd->numPorts) {
678 case 8:
679 writew(C320p8rx_mask, ofsAddr + RX_mask);
680 writew(C320p8tx_mask, ofsAddr + TX_mask);
681 writew(C320p8rx_spage + i * C320p8buf_pgno, ofsAddr + Page_rxb);
682 writew(readw(ofsAddr + Page_rxb) + C320p8rx_pgno, ofsAddr + EndPage_rxb);
683 writew(C320p8tx_spage + i * C320p8buf_pgno, ofsAddr + Page_txb);
684 writew(readw(ofsAddr + Page_txb) + C320p8tx_pgno, ofsAddr + EndPage_txb);
686 break;
687 case 16:
688 writew(C320p16rx_mask, ofsAddr + RX_mask);
689 writew(C320p16tx_mask, ofsAddr + TX_mask);
690 writew(C320p16rx_spage + i * C320p16buf_pgno, ofsAddr + Page_rxb);
691 writew(readw(ofsAddr + Page_rxb) + C320p16rx_pgno, ofsAddr + EndPage_rxb);
692 writew(C320p16tx_spage + i * C320p16buf_pgno, ofsAddr + Page_txb);
693 writew(readw(ofsAddr + Page_txb) + C320p16tx_pgno, ofsAddr + EndPage_txb);
694 break;
696 case 24:
697 writew(C320p24rx_mask, ofsAddr + RX_mask);
698 writew(C320p24tx_mask, ofsAddr + TX_mask);
699 writew(C320p24rx_spage + i * C320p24buf_pgno, ofsAddr + Page_rxb);
700 writew(readw(ofsAddr + Page_rxb) + C320p24rx_pgno, ofsAddr + EndPage_rxb);
701 writew(C320p24tx_spage + i * C320p24buf_pgno, ofsAddr + Page_txb);
702 writew(readw(ofsAddr + Page_txb), ofsAddr + EndPage_txb);
703 break;
704 case 32:
705 writew(C320p32rx_mask, ofsAddr + RX_mask);
706 writew(C320p32tx_mask, ofsAddr + TX_mask);
707 writew(C320p32tx_ofs, ofsAddr + Ofs_txb);
708 writew(C320p32rx_spage + i * C320p32buf_pgno, ofsAddr + Page_rxb);
709 writew(readb(ofsAddr + Page_rxb), ofsAddr + EndPage_rxb);
710 writew(C320p32tx_spage + i * C320p32buf_pgno, ofsAddr + Page_txb);
711 writew(readw(ofsAddr + Page_txb), ofsAddr + EndPage_txb);
712 break;
715 break;
717 return 0;
720 static int moxa_load_fw(struct moxa_board_conf *brd, const struct firmware *fw)
722 void *ptr = fw->data;
723 char rsn[64];
724 u16 lens[5];
725 size_t len;
726 unsigned int a, lenp, lencnt;
727 int ret = -EINVAL;
728 struct {
729 __le32 magic; /* 0x34303430 */
730 u8 reserved1[2];
731 u8 type; /* UNIX = 3 */
732 u8 model; /* C218T=1, C320T=2, CP204=3 */
733 u8 reserved2[8];
734 __le16 len[5];
735 } *hdr = ptr;
737 BUILD_BUG_ON(ARRAY_SIZE(hdr->len) != ARRAY_SIZE(lens));
739 if (fw->size < MOXA_FW_HDRLEN) {
740 strcpy(rsn, "too short (even header won't fit)");
741 goto err;
743 if (hdr->magic != cpu_to_le32(0x30343034)) {
744 sprintf(rsn, "bad magic: %.8x", le32_to_cpu(hdr->magic));
745 goto err;
747 if (hdr->type != 3) {
748 sprintf(rsn, "not for linux, type is %u", hdr->type);
749 goto err;
751 if (moxa_check_fw_model(brd, hdr->model)) {
752 sprintf(rsn, "not for this card, model is %u", hdr->model);
753 goto err;
756 len = MOXA_FW_HDRLEN;
757 lencnt = hdr->model == 2 ? 5 : 3;
758 for (a = 0; a < ARRAY_SIZE(lens); a++) {
759 lens[a] = le16_to_cpu(hdr->len[a]);
760 if (lens[a] && len + lens[a] <= fw->size &&
761 moxa_check_fw(&fw->data[len]))
762 printk(KERN_WARNING "MOXA firmware: unexpected input "
763 "at offset %u, but going on\n", (u32)len);
764 if (!lens[a] && a < lencnt) {
765 sprintf(rsn, "too few entries in fw file");
766 goto err;
768 len += lens[a];
771 if (len != fw->size) {
772 sprintf(rsn, "bad length: %u (should be %u)", (u32)fw->size,
773 (u32)len);
774 goto err;
777 ptr += MOXA_FW_HDRLEN;
778 lenp = 0; /* bios */
780 strcpy(rsn, "read above");
782 ret = moxa_load_bios(brd, ptr, lens[lenp]);
783 if (ret)
784 goto err;
786 /* we skip the tty section (lens[1]), since we don't need it */
787 ptr += lens[lenp] + lens[lenp + 1];
788 lenp += 2; /* comm */
790 if (hdr->model == 2) {
791 ret = moxa_load_320b(brd, ptr, lens[lenp]);
792 if (ret)
793 goto err;
794 /* skip another tty */
795 ptr += lens[lenp] + lens[lenp + 1];
796 lenp += 2;
799 ret = moxa_load_code(brd, ptr, lens[lenp]);
800 if (ret)
801 goto err;
803 return 0;
804 err:
805 printk(KERN_ERR "firmware failed to load, reason: %s\n", rsn);
806 return ret;
809 static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev)
811 const struct firmware *fw;
812 const char *file;
813 struct moxa_port *p;
814 unsigned int i;
815 int ret;
817 brd->ports = kcalloc(MAX_PORTS_PER_BOARD, sizeof(*brd->ports),
818 GFP_KERNEL);
819 if (brd->ports == NULL) {
820 printk(KERN_ERR "cannot allocate memory for ports\n");
821 ret = -ENOMEM;
822 goto err;
825 for (i = 0, p = brd->ports; i < MAX_PORTS_PER_BOARD; i++, p++) {
826 p->type = PORT_16550A;
827 p->close_delay = 5 * HZ / 10;
828 p->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
829 init_waitqueue_head(&p->open_wait);
832 switch (brd->boardType) {
833 case MOXA_BOARD_C218_ISA:
834 case MOXA_BOARD_C218_PCI:
835 file = "c218tunx.cod";
836 break;
837 case MOXA_BOARD_CP204J:
838 file = "cp204unx.cod";
839 break;
840 default:
841 file = "c320tunx.cod";
842 break;
845 ret = request_firmware(&fw, file, dev);
846 if (ret) {
847 printk(KERN_ERR "request_firmware failed\n");
848 goto err_free;
851 ret = moxa_load_fw(brd, fw);
853 release_firmware(fw);
855 if (ret)
856 goto err_free;
858 spin_lock_bh(&moxa_lock);
859 brd->ready = 1;
860 if (!timer_pending(&moxaTimer))
861 mod_timer(&moxaTimer, jiffies + HZ / 50);
862 spin_unlock_bh(&moxa_lock);
864 return 0;
865 err_free:
866 kfree(brd->ports);
867 err:
868 return ret;
871 static void moxa_board_deinit(struct moxa_board_conf *brd)
873 unsigned int a, opened;
875 mutex_lock(&moxa_openlock);
876 spin_lock_bh(&moxa_lock);
877 brd->ready = 0;
878 spin_unlock_bh(&moxa_lock);
880 /* pci hot-un-plug support */
881 for (a = 0; a < brd->numPorts; a++)
882 if (brd->ports[a].asyncflags & ASYNC_INITIALIZED)
883 tty_hangup(brd->ports[a].tty);
884 while (1) {
885 opened = 0;
886 for (a = 0; a < brd->numPorts; a++)
887 if (brd->ports[a].asyncflags & ASYNC_INITIALIZED)
888 opened++;
889 mutex_unlock(&moxa_openlock);
890 if (!opened)
891 break;
892 msleep(50);
893 mutex_lock(&moxa_openlock);
896 iounmap(brd->basemem);
897 brd->basemem = NULL;
898 kfree(brd->ports);
901 #ifdef CONFIG_PCI
902 static int __devinit moxa_pci_probe(struct pci_dev *pdev,
903 const struct pci_device_id *ent)
905 struct moxa_board_conf *board;
906 unsigned int i;
907 int board_type = ent->driver_data;
908 int retval;
910 retval = pci_enable_device(pdev);
911 if (retval) {
912 dev_err(&pdev->dev, "can't enable pci device\n");
913 goto err;
916 for (i = 0; i < MAX_BOARDS; i++)
917 if (moxa_boards[i].basemem == NULL)
918 break;
920 retval = -ENODEV;
921 if (i >= MAX_BOARDS) {
922 dev_warn(&pdev->dev, "more than %u MOXA Intellio family boards "
923 "found. Board is ignored.\n", MAX_BOARDS);
924 goto err;
927 board = &moxa_boards[i];
929 retval = pci_request_region(pdev, 2, "moxa-base");
930 if (retval) {
931 dev_err(&pdev->dev, "can't request pci region 2\n");
932 goto err;
935 board->basemem = ioremap(pci_resource_start(pdev, 2), 0x4000);
936 if (board->basemem == NULL) {
937 dev_err(&pdev->dev, "can't remap io space 2\n");
938 goto err_reg;
941 board->boardType = board_type;
942 switch (board_type) {
943 case MOXA_BOARD_C218_ISA:
944 case MOXA_BOARD_C218_PCI:
945 board->numPorts = 8;
946 break;
948 case MOXA_BOARD_CP204J:
949 board->numPorts = 4;
950 break;
951 default:
952 board->numPorts = 0;
953 break;
955 board->busType = MOXA_BUS_TYPE_PCI;
957 retval = moxa_init_board(board, &pdev->dev);
958 if (retval)
959 goto err_base;
961 pci_set_drvdata(pdev, board);
963 return 0;
964 err_base:
965 iounmap(board->basemem);
966 board->basemem = NULL;
967 err_reg:
968 pci_release_region(pdev, 2);
969 err:
970 return retval;
973 static void __devexit moxa_pci_remove(struct pci_dev *pdev)
975 struct moxa_board_conf *brd = pci_get_drvdata(pdev);
977 moxa_board_deinit(brd);
979 pci_release_region(pdev, 2);
982 static struct pci_driver moxa_pci_driver = {
983 .name = "moxa",
984 .id_table = moxa_pcibrds,
985 .probe = moxa_pci_probe,
986 .remove = __devexit_p(moxa_pci_remove)
988 #endif /* CONFIG_PCI */
990 static int __init moxa_init(void)
992 unsigned int isabrds = 0;
993 int retval = 0;
995 printk(KERN_INFO "MOXA Intellio family driver version %s\n",
996 MOXA_VERSION);
997 moxaDriver = alloc_tty_driver(MAX_PORTS + 1);
998 if (!moxaDriver)
999 return -ENOMEM;
1001 moxaDriver->owner = THIS_MODULE;
1002 moxaDriver->name = "ttyMX";
1003 moxaDriver->major = ttymajor;
1004 moxaDriver->minor_start = 0;
1005 moxaDriver->type = TTY_DRIVER_TYPE_SERIAL;
1006 moxaDriver->subtype = SERIAL_TYPE_NORMAL;
1007 moxaDriver->init_termios = tty_std_termios;
1008 moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1009 moxaDriver->init_termios.c_ispeed = 9600;
1010 moxaDriver->init_termios.c_ospeed = 9600;
1011 moxaDriver->flags = TTY_DRIVER_REAL_RAW;
1012 tty_set_operations(moxaDriver, &moxa_ops);
1014 if (tty_register_driver(moxaDriver)) {
1015 printk(KERN_ERR "can't register MOXA Smartio tty driver!\n");
1016 put_tty_driver(moxaDriver);
1017 return -1;
1020 /* Find the boards defined from module args. */
1021 #ifdef MODULE
1023 struct moxa_board_conf *brd = moxa_boards;
1024 unsigned int i;
1025 for (i = 0; i < MAX_BOARDS; i++) {
1026 if (!baseaddr[i])
1027 break;
1028 if (type[i] == MOXA_BOARD_C218_ISA ||
1029 type[i] == MOXA_BOARD_C320_ISA) {
1030 pr_debug("Moxa board %2d: %s board(baseAddr=%lx)\n",
1031 isabrds + 1, moxa_brdname[type[i] - 1],
1032 baseaddr[i]);
1033 brd->boardType = type[i];
1034 brd->numPorts = type[i] == MOXA_BOARD_C218_ISA ? 8 :
1035 numports[i];
1036 brd->busType = MOXA_BUS_TYPE_ISA;
1037 brd->basemem = ioremap(baseaddr[i], 0x4000);
1038 if (!brd->basemem) {
1039 printk(KERN_ERR "MOXA: can't remap %lx\n",
1040 baseaddr[i]);
1041 continue;
1043 if (moxa_init_board(brd, NULL)) {
1044 iounmap(brd->basemem);
1045 brd->basemem = NULL;
1046 continue;
1049 brd++;
1050 isabrds++;
1054 #endif
1056 #ifdef CONFIG_PCI
1057 retval = pci_register_driver(&moxa_pci_driver);
1058 if (retval) {
1059 printk(KERN_ERR "Can't register MOXA pci driver!\n");
1060 if (isabrds)
1061 retval = 0;
1063 #endif
1065 return retval;
1068 static void __exit moxa_exit(void)
1070 unsigned int i;
1072 #ifdef CONFIG_PCI
1073 pci_unregister_driver(&moxa_pci_driver);
1074 #endif
1076 for (i = 0; i < MAX_BOARDS; i++) /* ISA boards */
1077 if (moxa_boards[i].ready)
1078 moxa_board_deinit(&moxa_boards[i]);
1080 del_timer_sync(&moxaTimer);
1082 if (tty_unregister_driver(moxaDriver))
1083 printk(KERN_ERR "Couldn't unregister MOXA Intellio family "
1084 "serial driver\n");
1085 put_tty_driver(moxaDriver);
1088 module_init(moxa_init);
1089 module_exit(moxa_exit);
1091 static void moxa_close_port(struct moxa_port *ch)
1093 moxa_shut_down(ch);
1094 MoxaPortFlushData(ch, 2);
1095 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
1096 ch->tty->driver_data = NULL;
1097 ch->tty = NULL;
1100 static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
1101 struct moxa_port *ch)
1103 DEFINE_WAIT(wait);
1104 int retval = 0;
1105 u8 dcd;
1107 while (1) {
1108 prepare_to_wait(&ch->open_wait, &wait, TASK_INTERRUPTIBLE);
1109 if (tty_hung_up_p(filp)) {
1110 #ifdef SERIAL_DO_RESTART
1111 retval = -ERESTARTSYS;
1112 #else
1113 retval = -EAGAIN;
1114 #endif
1115 break;
1117 spin_lock_bh(&moxa_lock);
1118 dcd = ch->DCDState;
1119 spin_unlock_bh(&moxa_lock);
1120 if (dcd)
1121 break;
1123 if (signal_pending(current)) {
1124 retval = -ERESTARTSYS;
1125 break;
1127 schedule();
1129 finish_wait(&ch->open_wait, &wait);
1131 return retval;
1134 static int moxa_open(struct tty_struct *tty, struct file *filp)
1136 struct moxa_board_conf *brd;
1137 struct moxa_port *ch;
1138 int port;
1139 int retval;
1141 port = tty->index;
1142 if (port == MAX_PORTS) {
1143 return capable(CAP_SYS_ADMIN) ? 0 : -EPERM;
1145 if (mutex_lock_interruptible(&moxa_openlock))
1146 return -ERESTARTSYS;
1147 brd = &moxa_boards[port / MAX_PORTS_PER_BOARD];
1148 if (!brd->ready) {
1149 mutex_unlock(&moxa_openlock);
1150 return -ENODEV;
1153 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
1154 ch->count++;
1155 tty->driver_data = ch;
1156 ch->tty = tty;
1157 if (!(ch->asyncflags & ASYNC_INITIALIZED)) {
1158 ch->statusflags = 0;
1159 moxa_set_tty_param(tty, tty->termios);
1160 MoxaPortLineCtrl(ch, 1, 1);
1161 MoxaPortEnable(ch);
1162 MoxaSetFifo(ch, ch->type == PORT_16550A);
1163 ch->asyncflags |= ASYNC_INITIALIZED;
1165 mutex_unlock(&moxa_openlock);
1167 retval = 0;
1168 if (!(filp->f_flags & O_NONBLOCK) && !C_CLOCAL(tty))
1169 retval = moxa_block_till_ready(tty, filp, ch);
1170 mutex_lock(&moxa_openlock);
1171 if (retval) {
1172 if (ch->count) /* 0 means already hung up... */
1173 if (--ch->count == 0)
1174 moxa_close_port(ch);
1175 } else
1176 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1177 mutex_unlock(&moxa_openlock);
1179 return retval;
1182 static void moxa_close(struct tty_struct *tty, struct file *filp)
1184 struct moxa_port *ch;
1185 int port;
1187 port = tty->index;
1188 if (port == MAX_PORTS || tty_hung_up_p(filp))
1189 return;
1191 mutex_lock(&moxa_openlock);
1192 ch = tty->driver_data;
1193 if (ch == NULL)
1194 goto unlock;
1195 if (tty->count == 1 && ch->count != 1) {
1196 printk(KERN_WARNING "moxa_close: bad serial port count; "
1197 "tty->count is 1, ch->count is %d\n", ch->count);
1198 ch->count = 1;
1200 if (--ch->count < 0) {
1201 printk(KERN_WARNING "moxa_close: bad serial port count, "
1202 "device=%s\n", tty->name);
1203 ch->count = 0;
1205 if (ch->count)
1206 goto unlock;
1208 ch->cflag = tty->termios->c_cflag;
1209 if (ch->asyncflags & ASYNC_INITIALIZED) {
1210 moxa_setup_empty_event(tty);
1211 tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */
1214 moxa_close_port(ch);
1215 unlock:
1216 mutex_unlock(&moxa_openlock);
1219 static int moxa_write(struct tty_struct *tty,
1220 const unsigned char *buf, int count)
1222 struct moxa_port *ch = tty->driver_data;
1223 int len;
1225 if (ch == NULL)
1226 return 0;
1228 spin_lock_bh(&moxa_lock);
1229 len = MoxaPortWriteData(ch, buf, count);
1230 spin_unlock_bh(&moxa_lock);
1232 ch->statusflags |= LOWWAIT;
1233 return len;
1236 static int moxa_write_room(struct tty_struct *tty)
1238 struct moxa_port *ch;
1240 if (tty->stopped)
1241 return 0;
1242 ch = tty->driver_data;
1243 if (ch == NULL)
1244 return 0;
1245 return MoxaPortTxFree(ch);
1248 static void moxa_flush_buffer(struct tty_struct *tty)
1250 struct moxa_port *ch = tty->driver_data;
1252 if (ch == NULL)
1253 return;
1254 MoxaPortFlushData(ch, 1);
1255 tty_wakeup(tty);
1258 static int moxa_chars_in_buffer(struct tty_struct *tty)
1260 struct moxa_port *ch = tty->driver_data;
1261 int chars;
1264 * Sigh...I have to check if driver_data is NULL here, because
1265 * if an open() fails, the TTY subsystem eventually calls
1266 * tty_wait_until_sent(), which calls the driver's chars_in_buffer()
1267 * routine. And since the open() failed, we return 0 here. TDJ
1269 if (ch == NULL)
1270 return 0;
1271 chars = MoxaPortTxQueue(ch);
1272 if (chars) {
1274 * Make it possible to wakeup anything waiting for output
1275 * in tty_ioctl.c, etc.
1277 if (!(ch->statusflags & EMPTYWAIT))
1278 moxa_setup_empty_event(tty);
1280 return chars;
1283 static int moxa_tiocmget(struct tty_struct *tty, struct file *file)
1285 struct moxa_port *ch;
1286 int flag = 0, dtr, rts;
1288 mutex_lock(&moxa_openlock);
1289 ch = tty->driver_data;
1290 if (!ch) {
1291 mutex_unlock(&moxa_openlock);
1292 return -EINVAL;
1295 MoxaPortGetLineOut(ch, &dtr, &rts);
1296 if (dtr)
1297 flag |= TIOCM_DTR;
1298 if (rts)
1299 flag |= TIOCM_RTS;
1300 dtr = MoxaPortLineStatus(ch);
1301 if (dtr & 1)
1302 flag |= TIOCM_CTS;
1303 if (dtr & 2)
1304 flag |= TIOCM_DSR;
1305 if (dtr & 4)
1306 flag |= TIOCM_CD;
1307 mutex_unlock(&moxa_openlock);
1308 return flag;
1311 static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
1312 unsigned int set, unsigned int clear)
1314 struct moxa_port *ch;
1315 int port;
1316 int dtr, rts;
1318 port = tty->index;
1319 mutex_lock(&moxa_openlock);
1320 ch = tty->driver_data;
1321 if (!ch) {
1322 mutex_unlock(&moxa_openlock);
1323 return -EINVAL;
1326 MoxaPortGetLineOut(ch, &dtr, &rts);
1327 if (set & TIOCM_RTS)
1328 rts = 1;
1329 if (set & TIOCM_DTR)
1330 dtr = 1;
1331 if (clear & TIOCM_RTS)
1332 rts = 0;
1333 if (clear & TIOCM_DTR)
1334 dtr = 0;
1335 MoxaPortLineCtrl(ch, dtr, rts);
1336 mutex_unlock(&moxa_openlock);
1337 return 0;
1340 static void moxa_throttle(struct tty_struct *tty)
1342 struct moxa_port *ch = tty->driver_data;
1344 ch->statusflags |= THROTTLE;
1347 static void moxa_unthrottle(struct tty_struct *tty)
1349 struct moxa_port *ch = tty->driver_data;
1351 ch->statusflags &= ~THROTTLE;
1354 static void moxa_set_termios(struct tty_struct *tty,
1355 struct ktermios *old_termios)
1357 struct moxa_port *ch = tty->driver_data;
1359 if (ch == NULL)
1360 return;
1361 moxa_set_tty_param(tty, old_termios);
1362 if (!(old_termios->c_cflag & CLOCAL) && C_CLOCAL(tty))
1363 wake_up_interruptible(&ch->open_wait);
1366 static void moxa_stop(struct tty_struct *tty)
1368 struct moxa_port *ch = tty->driver_data;
1370 if (ch == NULL)
1371 return;
1372 MoxaPortTxDisable(ch);
1373 ch->statusflags |= TXSTOPPED;
1377 static void moxa_start(struct tty_struct *tty)
1379 struct moxa_port *ch = tty->driver_data;
1381 if (ch == NULL)
1382 return;
1384 if (!(ch->statusflags & TXSTOPPED))
1385 return;
1387 MoxaPortTxEnable(ch);
1388 ch->statusflags &= ~TXSTOPPED;
1391 static void moxa_hangup(struct tty_struct *tty)
1393 struct moxa_port *ch;
1395 mutex_lock(&moxa_openlock);
1396 ch = tty->driver_data;
1397 if (ch == NULL) {
1398 mutex_unlock(&moxa_openlock);
1399 return;
1401 ch->count = 0;
1402 moxa_close_port(ch);
1403 mutex_unlock(&moxa_openlock);
1405 wake_up_interruptible(&ch->open_wait);
1408 static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
1410 dcd = !!dcd;
1412 if (dcd != p->DCDState && p->tty && C_CLOCAL(p->tty)) {
1413 if (!dcd)
1414 tty_hangup(p->tty);
1416 p->DCDState = dcd;
1419 static int moxa_poll_port(struct moxa_port *p, unsigned int handle,
1420 u16 __iomem *ip)
1422 struct tty_struct *tty = p->tty;
1423 void __iomem *ofsAddr;
1424 unsigned int inited = p->asyncflags & ASYNC_INITIALIZED;
1425 u16 intr;
1427 if (tty) {
1428 if ((p->statusflags & EMPTYWAIT) &&
1429 MoxaPortTxQueue(p) == 0) {
1430 p->statusflags &= ~EMPTYWAIT;
1431 tty_wakeup(tty);
1433 if ((p->statusflags & LOWWAIT) && !tty->stopped &&
1434 MoxaPortTxQueue(p) <= WAKEUP_CHARS) {
1435 p->statusflags &= ~LOWWAIT;
1436 tty_wakeup(tty);
1439 if (inited && !(p->statusflags & THROTTLE) &&
1440 MoxaPortRxQueue(p) > 0) { /* RX */
1441 MoxaPortReadData(p);
1442 tty_schedule_flip(tty);
1444 } else {
1445 p->statusflags &= ~EMPTYWAIT;
1446 MoxaPortFlushData(p, 0); /* flush RX */
1449 if (!handle) /* nothing else to do */
1450 return 0;
1452 intr = readw(ip); /* port irq status */
1453 if (intr == 0)
1454 return 0;
1456 writew(0, ip); /* ACK port */
1457 ofsAddr = p->tableAddr;
1458 if (intr & IntrTx) /* disable tx intr */
1459 writew(readw(ofsAddr + HostStat) & ~WakeupTx,
1460 ofsAddr + HostStat);
1462 if (!inited)
1463 return 0;
1465 if (tty && (intr & IntrBreak) && !I_IGNBRK(tty)) { /* BREAK */
1466 tty_insert_flip_char(tty, 0, TTY_BREAK);
1467 tty_schedule_flip(tty);
1470 if (intr & IntrLine)
1471 moxa_new_dcdstate(p, readb(ofsAddr + FlagStat) & DCD_state);
1473 return 0;
1476 static void moxa_poll(unsigned long ignored)
1478 struct moxa_board_conf *brd;
1479 u16 __iomem *ip;
1480 unsigned int card, port, served = 0;
1482 spin_lock(&moxa_lock);
1483 for (card = 0; card < MAX_BOARDS; card++) {
1484 brd = &moxa_boards[card];
1485 if (!brd->ready)
1486 continue;
1488 served++;
1490 ip = NULL;
1491 if (readb(brd->intPend) == 0xff)
1492 ip = brd->intTable + readb(brd->intNdx);
1494 for (port = 0; port < brd->numPorts; port++)
1495 moxa_poll_port(&brd->ports[port], !!ip, ip + port);
1497 if (ip)
1498 writeb(0, brd->intPend); /* ACK */
1500 if (moxaLowWaterChk) {
1501 struct moxa_port *p = brd->ports;
1502 for (port = 0; port < brd->numPorts; port++, p++)
1503 if (p->lowChkFlag) {
1504 p->lowChkFlag = 0;
1505 moxa_low_water_check(p->tableAddr);
1509 moxaLowWaterChk = 0;
1511 if (served)
1512 mod_timer(&moxaTimer, jiffies + HZ / 50);
1513 spin_unlock(&moxa_lock);
1516 /******************************************************************************/
1518 static void moxa_set_tty_param(struct tty_struct *tty, struct ktermios *old_termios)
1520 register struct ktermios *ts = tty->termios;
1521 struct moxa_port *ch = tty->driver_data;
1522 int rts, cts, txflow, rxflow, xany, baud;
1524 rts = cts = txflow = rxflow = xany = 0;
1525 if (ts->c_cflag & CRTSCTS)
1526 rts = cts = 1;
1527 if (ts->c_iflag & IXON)
1528 txflow = 1;
1529 if (ts->c_iflag & IXOFF)
1530 rxflow = 1;
1531 if (ts->c_iflag & IXANY)
1532 xany = 1;
1534 /* Clear the features we don't support */
1535 ts->c_cflag &= ~CMSPAR;
1536 MoxaPortFlowCtrl(ch, rts, cts, txflow, rxflow, xany);
1537 baud = MoxaPortSetTermio(ch, ts, tty_get_baud_rate(tty));
1538 if (baud == -1)
1539 baud = tty_termios_baud_rate(old_termios);
1540 /* Not put the baud rate into the termios data */
1541 tty_encode_baud_rate(tty, baud, baud);
1544 static void moxa_setup_empty_event(struct tty_struct *tty)
1546 struct moxa_port *ch = tty->driver_data;
1548 spin_lock_bh(&moxa_lock);
1549 ch->statusflags |= EMPTYWAIT;
1550 spin_unlock_bh(&moxa_lock);
1553 static void moxa_shut_down(struct moxa_port *ch)
1555 struct tty_struct *tp = ch->tty;
1557 if (!(ch->asyncflags & ASYNC_INITIALIZED))
1558 return;
1560 MoxaPortDisable(ch);
1563 * If we're a modem control device and HUPCL is on, drop RTS & DTR.
1565 if (C_HUPCL(tp))
1566 MoxaPortLineCtrl(ch, 0, 0);
1568 spin_lock_bh(&moxa_lock);
1569 ch->asyncflags &= ~ASYNC_INITIALIZED;
1570 spin_unlock_bh(&moxa_lock);
1573 /*****************************************************************************
1574 * Driver level functions: *
1575 *****************************************************************************/
1577 static void MoxaPortFlushData(struct moxa_port *port, int mode)
1579 void __iomem *ofsAddr;
1580 if (mode < 0 || mode > 2)
1581 return;
1582 ofsAddr = port->tableAddr;
1583 moxafunc(ofsAddr, FC_FlushQueue, mode);
1584 if (mode != 1) {
1585 port->lowChkFlag = 0;
1586 moxa_low_water_check(ofsAddr);
1591 * Moxa Port Number Description:
1593 * MOXA serial driver supports up to 4 MOXA-C218/C320 boards. And,
1594 * the port number using in MOXA driver functions will be 0 to 31 for
1595 * first MOXA board, 32 to 63 for second, 64 to 95 for third and 96
1596 * to 127 for fourth. For example, if you setup three MOXA boards,
1597 * first board is C218, second board is C320-16 and third board is
1598 * C320-32. The port number of first board (C218 - 8 ports) is from
1599 * 0 to 7. The port number of second board (C320 - 16 ports) is form
1600 * 32 to 47. The port number of third board (C320 - 32 ports) is from
1601 * 64 to 95. And those port numbers form 8 to 31, 48 to 63 and 96 to
1602 * 127 will be invalid.
1605 * Moxa Functions Description:
1607 * Function 1: Driver initialization routine, this routine must be
1608 * called when initialized driver.
1609 * Syntax:
1610 * void MoxaDriverInit();
1613 * Function 2: Moxa driver private IOCTL command processing.
1614 * Syntax:
1615 * int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port);
1617 * unsigned int cmd : IOCTL command
1618 * unsigned long arg : IOCTL argument
1619 * int port : port number (0 - 127)
1621 * return: 0 (OK)
1622 * -EINVAL
1623 * -ENOIOCTLCMD
1626 * Function 6: Enable this port to start Tx/Rx data.
1627 * Syntax:
1628 * void MoxaPortEnable(int port);
1629 * int port : port number (0 - 127)
1632 * Function 7: Disable this port
1633 * Syntax:
1634 * void MoxaPortDisable(int port);
1635 * int port : port number (0 - 127)
1638 * Function 8: Get the maximun available baud rate of this port.
1639 * Syntax:
1640 * long MoxaPortGetMaxBaud(int port);
1641 * int port : port number (0 - 127)
1643 * return: 0 : this port is invalid
1644 * 38400/57600/115200 bps
1647 * Function 10: Setting baud rate of this port.
1648 * Syntax:
1649 * long MoxaPortSetBaud(int port, long baud);
1650 * int port : port number (0 - 127)
1651 * long baud : baud rate (50 - 115200)
1653 * return: 0 : this port is invalid or baud < 50
1654 * 50 - 115200 : the real baud rate set to the port, if
1655 * the argument baud is large than maximun
1656 * available baud rate, the real setting
1657 * baud rate will be the maximun baud rate.
1660 * Function 12: Configure the port.
1661 * Syntax:
1662 * int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud);
1663 * int port : port number (0 - 127)
1664 * struct ktermios * termio : termio structure pointer
1665 * speed_t baud : baud rate
1667 * return: -1 : this port is invalid or termio == NULL
1668 * 0 : setting O.K.
1671 * Function 13: Get the DTR/RTS state of this port.
1672 * Syntax:
1673 * int MoxaPortGetLineOut(int port, int *dtrState, int *rtsState);
1674 * int port : port number (0 - 127)
1675 * int * dtrState : pointer to INT to receive the current DTR
1676 * state. (if NULL, this function will not
1677 * write to this address)
1678 * int * rtsState : pointer to INT to receive the current RTS
1679 * state. (if NULL, this function will not
1680 * write to this address)
1682 * return: -1 : this port is invalid
1683 * 0 : O.K.
1686 * Function 14: Setting the DTR/RTS output state of this port.
1687 * Syntax:
1688 * void MoxaPortLineCtrl(int port, int dtrState, int rtsState);
1689 * int port : port number (0 - 127)
1690 * int dtrState : DTR output state (0: off, 1: on)
1691 * int rtsState : RTS output state (0: off, 1: on)
1694 * Function 15: Setting the flow control of this port.
1695 * Syntax:
1696 * void MoxaPortFlowCtrl(int port, int rtsFlow, int ctsFlow, int rxFlow,
1697 * int txFlow,int xany);
1698 * int port : port number (0 - 127)
1699 * int rtsFlow : H/W RTS flow control (0: no, 1: yes)
1700 * int ctsFlow : H/W CTS flow control (0: no, 1: yes)
1701 * int rxFlow : S/W Rx XON/XOFF flow control (0: no, 1: yes)
1702 * int txFlow : S/W Tx XON/XOFF flow control (0: no, 1: yes)
1703 * int xany : S/W XANY flow control (0: no, 1: yes)
1706 * Function 16: Get ths line status of this port
1707 * Syntax:
1708 * int MoxaPortLineStatus(int port);
1709 * int port : port number (0 - 127)
1711 * return: Bit 0 - CTS state (0: off, 1: on)
1712 * Bit 1 - DSR state (0: off, 1: on)
1713 * Bit 2 - DCD state (0: off, 1: on)
1716 * Function 19: Flush the Rx/Tx buffer data of this port.
1717 * Syntax:
1718 * void MoxaPortFlushData(int port, int mode);
1719 * int port : port number (0 - 127)
1720 * int mode
1721 * 0 : flush the Rx buffer
1722 * 1 : flush the Tx buffer
1723 * 2 : flush the Rx and Tx buffer
1726 * Function 20: Write data.
1727 * Syntax:
1728 * int MoxaPortWriteData(int port, unsigned char * buffer, int length);
1729 * int port : port number (0 - 127)
1730 * unsigned char * buffer : pointer to write data buffer.
1731 * int length : write data length
1733 * return: 0 - length : real write data length
1736 * Function 21: Read data.
1737 * Syntax:
1738 * int MoxaPortReadData(int port, struct tty_struct *tty);
1739 * int port : port number (0 - 127)
1740 * struct tty_struct *tty : tty for data
1742 * return: 0 - length : real read data length
1745 * Function 24: Get the Tx buffer current queued data bytes
1746 * Syntax:
1747 * int MoxaPortTxQueue(int port);
1748 * int port : port number (0 - 127)
1750 * return: .. : Tx buffer current queued data bytes
1753 * Function 25: Get the Tx buffer current free space
1754 * Syntax:
1755 * int MoxaPortTxFree(int port);
1756 * int port : port number (0 - 127)
1758 * return: .. : Tx buffer current free space
1761 * Function 26: Get the Rx buffer current queued data bytes
1762 * Syntax:
1763 * int MoxaPortRxQueue(int port);
1764 * int port : port number (0 - 127)
1766 * return: .. : Rx buffer current queued data bytes
1769 * Function 28: Disable port data transmission.
1770 * Syntax:
1771 * void MoxaPortTxDisable(int port);
1772 * int port : port number (0 - 127)
1775 * Function 29: Enable port data transmission.
1776 * Syntax:
1777 * void MoxaPortTxEnable(int port);
1778 * int port : port number (0 - 127)
1781 * Function 31: Get the received BREAK signal count and reset it.
1782 * Syntax:
1783 * int MoxaPortResetBrkCnt(int port);
1784 * int port : port number (0 - 127)
1786 * return: 0 - .. : BREAK signal count
1791 static void MoxaPortEnable(struct moxa_port *port)
1793 void __iomem *ofsAddr;
1794 u16 lowwater = 512;
1796 ofsAddr = port->tableAddr;
1797 writew(lowwater, ofsAddr + Low_water);
1798 if (port->board->boardType == MOXA_BOARD_C320_ISA ||
1799 port->board->boardType == MOXA_BOARD_C320_PCI)
1800 moxafunc(ofsAddr, FC_SetBreakIrq, 0);
1801 else
1802 writew(readw(ofsAddr + HostStat) | WakeupBreak,
1803 ofsAddr + HostStat);
1805 moxafunc(ofsAddr, FC_SetLineIrq, Magic_code);
1806 moxafunc(ofsAddr, FC_FlushQueue, 2);
1808 moxafunc(ofsAddr, FC_EnableCH, Magic_code);
1809 MoxaPortLineStatus(port);
1812 static void MoxaPortDisable(struct moxa_port *port)
1814 void __iomem *ofsAddr = port->tableAddr;
1816 moxafunc(ofsAddr, FC_SetFlowCtl, 0); /* disable flow control */
1817 moxafunc(ofsAddr, FC_ClrLineIrq, Magic_code);
1818 writew(0, ofsAddr + HostStat);
1819 moxafunc(ofsAddr, FC_DisableCH, Magic_code);
1822 static long MoxaPortGetMaxBaud(struct moxa_port *port)
1824 if (port->board->boardType == MOXA_BOARD_C320_ISA ||
1825 port->board->boardType == MOXA_BOARD_C320_PCI)
1826 return 460800L;
1827 else
1828 return 921600L;
1832 static long MoxaPortSetBaud(struct moxa_port *port, long baud)
1834 void __iomem *ofsAddr;
1835 long max, clock;
1836 unsigned int val;
1838 if (baud < 50L || (max = MoxaPortGetMaxBaud(port)) == 0)
1839 return 0;
1840 ofsAddr = port->tableAddr;
1841 if (baud > max)
1842 baud = max;
1843 if (max == 38400L)
1844 clock = 614400L; /* for 9.8304 Mhz : max. 38400 bps */
1845 else if (max == 57600L)
1846 clock = 691200L; /* for 11.0592 Mhz : max. 57600 bps */
1847 else
1848 clock = 921600L; /* for 14.7456 Mhz : max. 115200 bps */
1849 val = clock / baud;
1850 moxafunc(ofsAddr, FC_SetBaud, val);
1851 baud = clock / val;
1852 return baud;
1855 static int MoxaPortSetTermio(struct moxa_port *port, struct ktermios *termio,
1856 speed_t baud)
1858 void __iomem *ofsAddr;
1859 tcflag_t cflag;
1860 tcflag_t mode = 0;
1862 ofsAddr = port->tableAddr;
1863 cflag = termio->c_cflag; /* termio->c_cflag */
1865 mode = termio->c_cflag & CSIZE;
1866 if (mode == CS5)
1867 mode = MX_CS5;
1868 else if (mode == CS6)
1869 mode = MX_CS6;
1870 else if (mode == CS7)
1871 mode = MX_CS7;
1872 else if (mode == CS8)
1873 mode = MX_CS8;
1875 if (termio->c_cflag & CSTOPB) {
1876 if (mode == MX_CS5)
1877 mode |= MX_STOP15;
1878 else
1879 mode |= MX_STOP2;
1880 } else
1881 mode |= MX_STOP1;
1883 if (termio->c_cflag & PARENB) {
1884 if (termio->c_cflag & PARODD)
1885 mode |= MX_PARODD;
1886 else
1887 mode |= MX_PAREVEN;
1888 } else
1889 mode |= MX_PARNONE;
1891 moxafunc(ofsAddr, FC_SetDataMode, (u16)mode);
1893 if (port->board->boardType == MOXA_BOARD_C320_ISA ||
1894 port->board->boardType == MOXA_BOARD_C320_PCI) {
1895 if (baud >= 921600L)
1896 return -1;
1898 baud = MoxaPortSetBaud(port, baud);
1900 if (termio->c_iflag & (IXON | IXOFF | IXANY)) {
1901 writeb(termio->c_cc[VSTART], ofsAddr + FuncArg);
1902 writeb(termio->c_cc[VSTOP], ofsAddr + FuncArg1);
1903 writeb(FC_SetXonXoff, ofsAddr + FuncCode);
1904 moxa_wait_finish(ofsAddr);
1907 return baud;
1910 static int MoxaPortGetLineOut(struct moxa_port *port, int *dtrState,
1911 int *rtsState)
1913 if (dtrState)
1914 *dtrState = !!(port->lineCtrl & DTR_ON);
1915 if (rtsState)
1916 *rtsState = !!(port->lineCtrl & RTS_ON);
1918 return 0;
1921 static void MoxaPortLineCtrl(struct moxa_port *port, int dtr, int rts)
1923 u8 mode = 0;
1925 if (dtr)
1926 mode |= DTR_ON;
1927 if (rts)
1928 mode |= RTS_ON;
1929 port->lineCtrl = mode;
1930 moxafunc(port->tableAddr, FC_LineControl, mode);
1933 static void MoxaPortFlowCtrl(struct moxa_port *port, int rts, int cts,
1934 int txflow, int rxflow, int txany)
1936 int mode = 0;
1938 if (rts)
1939 mode |= RTS_FlowCtl;
1940 if (cts)
1941 mode |= CTS_FlowCtl;
1942 if (txflow)
1943 mode |= Tx_FlowCtl;
1944 if (rxflow)
1945 mode |= Rx_FlowCtl;
1946 if (txany)
1947 mode |= IXM_IXANY;
1948 moxafunc(port->tableAddr, FC_SetFlowCtl, mode);
1951 static int MoxaPortLineStatus(struct moxa_port *port)
1953 void __iomem *ofsAddr;
1954 int val;
1956 ofsAddr = port->tableAddr;
1957 if (port->board->boardType == MOXA_BOARD_C320_ISA ||
1958 port->board->boardType == MOXA_BOARD_C320_PCI) {
1959 moxafunc(ofsAddr, FC_LineStatus, 0);
1960 val = readw(ofsAddr + FuncArg);
1961 } else {
1962 val = readw(ofsAddr + FlagStat) >> 4;
1964 val &= 0x0B;
1965 if (val & 8)
1966 val |= 4;
1967 spin_lock_bh(&moxa_lock);
1968 moxa_new_dcdstate(port, val & 8);
1969 spin_unlock_bh(&moxa_lock);
1970 val &= 7;
1971 return val;
1974 static int MoxaPortWriteData(struct moxa_port *port,
1975 const unsigned char *buffer, int len)
1977 void __iomem *baseAddr, *ofsAddr, *ofs;
1978 unsigned int c, total;
1979 u16 head, tail, tx_mask, spage, epage;
1980 u16 pageno, pageofs, bufhead;
1982 ofsAddr = port->tableAddr;
1983 baseAddr = port->board->basemem;
1984 tx_mask = readw(ofsAddr + TX_mask);
1985 spage = readw(ofsAddr + Page_txb);
1986 epage = readw(ofsAddr + EndPage_txb);
1987 tail = readw(ofsAddr + TXwptr);
1988 head = readw(ofsAddr + TXrptr);
1989 c = (head > tail) ? (head - tail - 1) : (head - tail + tx_mask);
1990 if (c > len)
1991 c = len;
1992 moxaLog.txcnt[port->tty->index] += c;
1993 total = c;
1994 if (spage == epage) {
1995 bufhead = readw(ofsAddr + Ofs_txb);
1996 writew(spage, baseAddr + Control_reg);
1997 while (c > 0) {
1998 if (head > tail)
1999 len = head - tail - 1;
2000 else
2001 len = tx_mask + 1 - tail;
2002 len = (c > len) ? len : c;
2003 ofs = baseAddr + DynPage_addr + bufhead + tail;
2004 memcpy_toio(ofs, buffer, len);
2005 buffer += len;
2006 tail = (tail + len) & tx_mask;
2007 c -= len;
2009 } else {
2010 pageno = spage + (tail >> 13);
2011 pageofs = tail & Page_mask;
2012 while (c > 0) {
2013 len = Page_size - pageofs;
2014 if (len > c)
2015 len = c;
2016 writeb(pageno, baseAddr + Control_reg);
2017 ofs = baseAddr + DynPage_addr + pageofs;
2018 memcpy_toio(ofs, buffer, len);
2019 buffer += len;
2020 if (++pageno == epage)
2021 pageno = spage;
2022 pageofs = 0;
2023 c -= len;
2025 tail = (tail + total) & tx_mask;
2027 writew(tail, ofsAddr + TXwptr);
2028 writeb(1, ofsAddr + CD180TXirq); /* start to send */
2029 return total;
2032 static int MoxaPortReadData(struct moxa_port *port)
2034 struct tty_struct *tty = port->tty;
2035 unsigned char *dst;
2036 void __iomem *baseAddr, *ofsAddr, *ofs;
2037 unsigned int count, len, total;
2038 u16 tail, rx_mask, spage, epage;
2039 u16 pageno, pageofs, bufhead, head;
2041 ofsAddr = port->tableAddr;
2042 baseAddr = port->board->basemem;
2043 head = readw(ofsAddr + RXrptr);
2044 tail = readw(ofsAddr + RXwptr);
2045 rx_mask = readw(ofsAddr + RX_mask);
2046 spage = readw(ofsAddr + Page_rxb);
2047 epage = readw(ofsAddr + EndPage_rxb);
2048 count = (tail >= head) ? (tail - head) : (tail - head + rx_mask + 1);
2049 if (count == 0)
2050 return 0;
2052 total = count;
2053 moxaLog.rxcnt[tty->index] += total;
2054 if (spage == epage) {
2055 bufhead = readw(ofsAddr + Ofs_rxb);
2056 writew(spage, baseAddr + Control_reg);
2057 while (count > 0) {
2058 ofs = baseAddr + DynPage_addr + bufhead + head;
2059 len = (tail >= head) ? (tail - head) :
2060 (rx_mask + 1 - head);
2061 len = tty_prepare_flip_string(tty, &dst,
2062 min(len, count));
2063 memcpy_fromio(dst, ofs, len);
2064 head = (head + len) & rx_mask;
2065 count -= len;
2067 } else {
2068 pageno = spage + (head >> 13);
2069 pageofs = head & Page_mask;
2070 while (count > 0) {
2071 writew(pageno, baseAddr + Control_reg);
2072 ofs = baseAddr + DynPage_addr + pageofs;
2073 len = tty_prepare_flip_string(tty, &dst,
2074 min(Page_size - pageofs, count));
2075 memcpy_fromio(dst, ofs, len);
2077 count -= len;
2078 pageofs = (pageofs + len) & Page_mask;
2079 if (pageofs == 0 && ++pageno == epage)
2080 pageno = spage;
2082 head = (head + total) & rx_mask;
2084 writew(head, ofsAddr + RXrptr);
2085 if (readb(ofsAddr + FlagStat) & Xoff_state) {
2086 moxaLowWaterChk = 1;
2087 port->lowChkFlag = 1;
2089 return total;
2093 static int MoxaPortTxQueue(struct moxa_port *port)
2095 void __iomem *ofsAddr = port->tableAddr;
2096 u16 rptr, wptr, mask;
2098 rptr = readw(ofsAddr + TXrptr);
2099 wptr = readw(ofsAddr + TXwptr);
2100 mask = readw(ofsAddr + TX_mask);
2101 return (wptr - rptr) & mask;
2104 static int MoxaPortTxFree(struct moxa_port *port)
2106 void __iomem *ofsAddr = port->tableAddr;
2107 u16 rptr, wptr, mask;
2109 rptr = readw(ofsAddr + TXrptr);
2110 wptr = readw(ofsAddr + TXwptr);
2111 mask = readw(ofsAddr + TX_mask);
2112 return mask - ((wptr - rptr) & mask);
2115 static int MoxaPortRxQueue(struct moxa_port *port)
2117 void __iomem *ofsAddr = port->tableAddr;
2118 u16 rptr, wptr, mask;
2120 rptr = readw(ofsAddr + RXrptr);
2121 wptr = readw(ofsAddr + RXwptr);
2122 mask = readw(ofsAddr + RX_mask);
2123 return (wptr - rptr) & mask;
2126 static void MoxaPortTxDisable(struct moxa_port *port)
2128 moxafunc(port->tableAddr, FC_SetXoffState, Magic_code);
2131 static void MoxaPortTxEnable(struct moxa_port *port)
2133 moxafunc(port->tableAddr, FC_SetXonState, Magic_code);
2136 static int moxa_get_serial_info(struct moxa_port *info,
2137 struct serial_struct __user *retinfo)
2139 struct serial_struct tmp = {
2140 .type = info->type,
2141 .line = info->tty->index,
2142 .flags = info->asyncflags,
2143 .baud_base = 921600,
2144 .close_delay = info->close_delay
2146 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
2150 static int moxa_set_serial_info(struct moxa_port *info,
2151 struct serial_struct __user *new_info)
2153 struct serial_struct new_serial;
2155 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
2156 return -EFAULT;
2158 if (new_serial.irq != 0 || new_serial.port != 0 ||
2159 new_serial.custom_divisor != 0 ||
2160 new_serial.baud_base != 921600)
2161 return -EPERM;
2163 if (!capable(CAP_SYS_ADMIN)) {
2164 if (((new_serial.flags & ~ASYNC_USR_MASK) !=
2165 (info->asyncflags & ~ASYNC_USR_MASK)))
2166 return -EPERM;
2167 } else
2168 info->close_delay = new_serial.close_delay * HZ / 100;
2170 new_serial.flags = (new_serial.flags & ~ASYNC_FLAGS);
2171 new_serial.flags |= (info->asyncflags & ASYNC_FLAGS);
2173 MoxaSetFifo(info, new_serial.type == PORT_16550A);
2175 info->type = new_serial.type;
2176 return 0;
2181 /*****************************************************************************
2182 * Static local functions: *
2183 *****************************************************************************/
2185 static void MoxaSetFifo(struct moxa_port *port, int enable)
2187 void __iomem *ofsAddr = port->tableAddr;
2189 if (!enable) {
2190 moxafunc(ofsAddr, FC_SetRxFIFOTrig, 0);
2191 moxafunc(ofsAddr, FC_SetTxFIFOCnt, 1);
2192 } else {
2193 moxafunc(ofsAddr, FC_SetRxFIFOTrig, 3);
2194 moxafunc(ofsAddr, FC_SetTxFIFOCnt, 16);