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.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * MOXA Intellio Series Driver
32 #include <linux/config.h>
33 #include <linux/module.h>
34 #include <linux/types.h>
35 #include <linux/version.h>
37 #include <linux/ioport.h>
38 #include <linux/errno.h>
39 #include <linux/signal.h>
40 #include <linux/sched.h>
41 #include <linux/timer.h>
42 #include <linux/interrupt.h>
43 #include <linux/tty.h>
44 #include <linux/tty_flip.h>
45 #include <linux/major.h>
46 #include <linux/string.h>
47 #include <linux/fcntl.h>
48 #include <linux/ptrace.h>
49 #include <linux/serial.h>
50 #include <linux/tty_driver.h>
51 #include <linux/delay.h>
52 #include <linux/pci.h>
54 #include <asm/system.h>
56 #include <asm/segment.h>
57 #include <asm/bitops.h>
58 #include <asm/uaccess.h>
60 #define MOXA_VERSION "5.1k"
63 #define MOXACUMAJOR 173
65 #define put_to_user(arg1, arg2) put_user(arg1, (unsigned long *)arg2)
66 #define get_from_user(arg1, arg2) get_user(arg1, (unsigned int *)arg2)
68 #define MAX_BOARDS 4 /* Don't change this value */
69 #define MAX_PORTS_PER_BOARD 32 /* Don't change this value */
70 #define MAX_PORTS 128 /* Don't change this value */
73 * Define the Moxa PCI vendor and device IDs.
75 #define MOXA_BUS_TYPE_ISA 0
76 #define MOXA_BUS_TYPE_PCI 1
78 #ifndef PCI_VENDOR_ID_MOXA
79 #define PCI_VENDOR_ID_MOXA 0x1393
81 #ifndef PCI_DEVICE_ID_CP204J
82 #define PCI_DEVICE_ID_CP204J 0x2040
84 #ifndef PCI_DEVICE_ID_C218
85 #define PCI_DEVICE_ID_C218 0x2180
87 #ifndef PCI_DEVICE_ID_C320
88 #define PCI_DEVICE_ID_C320 0x3200
92 MOXA_BOARD_C218_PCI
= 1,
99 static char *moxa_brdname
[] =
101 "C218 Turbo PCI series",
102 "C218 Turbo ISA series",
103 "C320 Turbo PCI series",
104 "C320 Turbo ISA series",
109 unsigned short vendor_id
;
110 unsigned short device_id
;
111 unsigned short board_type
;
114 static moxa_pciinfo moxa_pcibrds
[] =
116 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_C218
, MOXA_BOARD_C218_PCI
},
117 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_C320
, MOXA_BOARD_C320_PCI
},
118 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_CP204J
, MOXA_BOARD_CP204J
},
121 typedef struct _moxa_isa_board_conf
{
124 unsigned long baseAddr
;
125 } moxa_isa_board_conf
;
127 static moxa_isa_board_conf moxa_isa_boards
[] =
129 /* {MOXA_BOARD_C218_ISA,8,0xDC000}, */
132 typedef struct _moxa_pci_devinfo
{
137 typedef struct _moxa_board_conf
{
140 unsigned long baseAddr
;
142 moxa_pci_devinfo pciInfo
;
145 static moxa_board_conf moxa_boards
[MAX_BOARDS
];
146 static unsigned long moxaBaseAddr
[MAX_BOARDS
];
152 unsigned short closing_wait
;
155 long event
; /* long req'd for set_bit --RR */
159 unsigned long statusflags
;
160 struct tty_struct
*tty
;
161 struct termios normal_termios
;
162 struct termios callout_termios
;
163 wait_queue_head_t open_wait
;
164 wait_queue_head_t close_wait
;
165 struct tq_struct tqueue
;
168 struct mxser_mstatus
{
176 static struct mxser_mstatus GMStatus
[MAX_PORTS
];
179 #define TXSTOPPED 0x1
181 #define EMPTYWAIT 0x4
185 #define MOXA_EVENT_HANGUP 1
187 #define SERIAL_DO_RESTART
190 #define SERIAL_TYPE_NORMAL 1
191 #define SERIAL_TYPE_CALLOUT 2
193 #define WAKEUP_CHARS 256
195 #define PORTNO(x) (MINOR((x)->device) - (x)->driver.minor_start)
197 static int verbose
= 0;
198 static int ttymajor
= MOXAMAJOR
;
199 static int calloutmajor
= MOXACUMAJOR
;
201 /* Variables for insmod */
202 static int baseaddr
[] = {0, 0, 0, 0};
203 static int type
[] = {0, 0, 0, 0};
204 static int numports
[] = {0, 0, 0, 0};
206 MODULE_AUTHOR("William Chen");
207 MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver");
208 MODULE_PARM(type
, "1-4i");
209 MODULE_PARM(baseaddr
, "1-4i");
210 MODULE_PARM(numports
, "1-4i");
211 MODULE_PARM(ttymajor
, "i");
212 MODULE_PARM(calloutmajor
, "i");
213 MODULE_PARM(verbose
, "i");
217 static struct tty_driver moxaDriver
;
218 static struct tty_driver moxaCallout
;
219 static struct tty_struct
*moxaTable
[MAX_PORTS
+ 1];
220 static struct termios
*moxaTermios
[MAX_PORTS
+ 1];
221 static struct termios
*moxaTermiosLocked
[MAX_PORTS
+ 1];
222 static struct moxa_str moxaChannels
[MAX_PORTS
];
223 static int moxaRefcount
;
224 static unsigned char *moxaXmitBuff
;
225 static int moxaTimer_on
;
226 static struct timer_list moxaTimer
;
227 static int moxaEmptyTimer_on
[MAX_PORTS
];
228 static struct timer_list moxaEmptyTimer
[MAX_PORTS
];
229 static struct semaphore moxaBuffSem
;
233 int init_module(void);
234 void cleanup_module(void);
239 static int moxa_get_PCI_conf(struct pci_dev
*, int, moxa_board_conf
*);
240 static void do_moxa_softint(void *);
241 static int moxa_open(struct tty_struct
*, struct file
*);
242 static void moxa_close(struct tty_struct
*, struct file
*);
243 static int moxa_write(struct tty_struct
*, int, const unsigned char *, int);
244 static int moxa_write_room(struct tty_struct
*);
245 static void moxa_flush_buffer(struct tty_struct
*);
246 static int moxa_chars_in_buffer(struct tty_struct
*);
247 static void moxa_flush_chars(struct tty_struct
*);
248 static void moxa_put_char(struct tty_struct
*, unsigned char);
249 static int moxa_ioctl(struct tty_struct
*, struct file
*, unsigned int, unsigned long);
250 static void moxa_throttle(struct tty_struct
*);
251 static void moxa_unthrottle(struct tty_struct
*);
252 static void moxa_set_termios(struct tty_struct
*, struct termios
*);
253 static void moxa_stop(struct tty_struct
*);
254 static void moxa_start(struct tty_struct
*);
255 static void moxa_hangup(struct tty_struct
*);
256 static void moxa_poll(unsigned long);
257 static void set_tty_param(struct tty_struct
*);
258 static int block_till_ready(struct tty_struct
*, struct file
*,
260 static void setup_empty_event(struct tty_struct
*);
261 static void check_xmit_empty(unsigned long);
262 static void shut_down(struct moxa_str
*);
263 static void receive_data(struct moxa_str
*);
265 * moxa board interface functions:
267 static void MoxaDriverInit(void);
268 static int MoxaDriverIoctl(unsigned int, unsigned long, int);
269 static int MoxaDriverPoll(void);
270 static int MoxaPortsOfCard(int);
271 static int MoxaPortIsValid(int);
272 static void MoxaPortEnable(int);
273 static void MoxaPortDisable(int);
274 static long MoxaPortGetMaxBaud(int);
275 static long MoxaPortSetBaud(int, long);
276 static int MoxaPortSetTermio(int, struct termios
*);
277 static int MoxaPortGetLineOut(int, int *, int *);
278 static void MoxaPortLineCtrl(int, int, int);
279 static void MoxaPortFlowCtrl(int, int, int, int, int, int);
280 static int MoxaPortLineStatus(int);
281 static int MoxaPortDCDChange(int);
282 static int MoxaPortDCDON(int);
283 static void MoxaPortFlushData(int, int);
284 static int MoxaPortWriteData(int, unsigned char *, int);
285 static int MoxaPortReadData(int, unsigned char *, int);
286 static int MoxaPortTxQueue(int);
287 static int MoxaPortRxQueue(int);
288 static int MoxaPortTxFree(int);
289 static void MoxaPortTxDisable(int);
290 static void MoxaPortTxEnable(int);
291 static int MoxaPortResetBrkCnt(int);
292 static void MoxaPortSendBreak(int, int);
293 static int moxa_get_serial_info(struct moxa_str
*, struct serial_struct
*);
294 static int moxa_set_serial_info(struct moxa_str
*, struct serial_struct
*);
295 static void MoxaSetFifo(int port
, int enable
);
298 int init_module(void)
303 printk("Loading module moxa ...\n");
310 void cleanup_module(void)
315 printk("Unloading module moxa ...\n");
318 del_timer(&moxaTimer
);
320 for (i
= 0; i
< MAX_PORTS
; i
++)
321 if (moxaEmptyTimer_on
[i
])
322 del_timer(&moxaEmptyTimer
[i
]);
324 if (tty_unregister_driver(&moxaCallout
))
325 printk("Couldn't unregister MOXA Intellio family callout driver\n");
326 if (tty_unregister_driver(&moxaDriver
))
327 printk("Couldn't unregister MOXA Intellio family serial driver\n");
340 printk(KERN_INFO
"MOXA Intellio family driver version %s\n", MOXA_VERSION
);
342 init_MUTEX(&moxaBuffSem
);
343 memset(&moxaDriver
, 0, sizeof(struct tty_driver
));
344 memset(&moxaCallout
, 0, sizeof(struct tty_driver
));
345 moxaDriver
.magic
= TTY_DRIVER_MAGIC
;
346 moxaDriver
.name
= "ttya";
347 moxaDriver
.major
= ttymajor
;
348 moxaDriver
.minor_start
= 0;
349 moxaDriver
.num
= MAX_PORTS
+ 1;
350 moxaDriver
.type
= TTY_DRIVER_TYPE_SERIAL
;
351 moxaDriver
.subtype
= SERIAL_TYPE_NORMAL
;
352 moxaDriver
.init_termios
= tty_std_termios
;
353 moxaDriver
.init_termios
.c_iflag
= 0;
354 moxaDriver
.init_termios
.c_oflag
= 0;
355 moxaDriver
.init_termios
.c_cflag
= B9600
| CS8
| CREAD
| CLOCAL
| HUPCL
;
356 moxaDriver
.init_termios
.c_lflag
= 0;
357 moxaDriver
.flags
= TTY_DRIVER_REAL_RAW
;
358 moxaDriver
.refcount
= &moxaRefcount
;
359 moxaDriver
.table
= moxaTable
;
360 moxaDriver
.termios
= moxaTermios
;
361 moxaDriver
.termios_locked
= moxaTermiosLocked
;
363 moxaDriver
.open
= moxa_open
;
364 moxaDriver
.close
= moxa_close
;
365 moxaDriver
.write
= moxa_write
;
366 moxaDriver
.write_room
= moxa_write_room
;
367 moxaDriver
.flush_buffer
= moxa_flush_buffer
;
368 moxaDriver
.chars_in_buffer
= moxa_chars_in_buffer
;
369 moxaDriver
.flush_chars
= moxa_flush_chars
;
370 moxaDriver
.put_char
= moxa_put_char
;
371 moxaDriver
.ioctl
= moxa_ioctl
;
372 moxaDriver
.throttle
= moxa_throttle
;
373 moxaDriver
.unthrottle
= moxa_unthrottle
;
374 moxaDriver
.set_termios
= moxa_set_termios
;
375 moxaDriver
.stop
= moxa_stop
;
376 moxaDriver
.start
= moxa_start
;
377 moxaDriver
.hangup
= moxa_hangup
;
379 moxaCallout
= moxaDriver
;
380 moxaCallout
.name
= "ttyA";
381 moxaCallout
.major
= calloutmajor
;
382 moxaCallout
.subtype
= SERIAL_TYPE_CALLOUT
;
386 for (i
= 0, ch
= moxaChannels
; i
< MAX_PORTS
; i
++, ch
++) {
387 ch
->type
= PORT_16550A
;
389 ch
->tqueue
.routine
= do_moxa_softint
;
390 ch
->tqueue
.data
= ch
;
392 ch
->close_delay
= 5 * HZ
/ 10;
393 ch
->closing_wait
= 30 * HZ
;
395 ch
->blocked_open
= 0;
396 ch
->callout_termios
= moxaCallout
.init_termios
;
397 ch
->normal_termios
= moxaDriver
.init_termios
;
398 init_waitqueue_head(&ch
->open_wait
);
399 init_waitqueue_head(&ch
->close_wait
);
402 for (i
= 0; i
< MAX_BOARDS
; i
++) {
403 moxa_boards
[i
].boardType
= 0;
404 moxa_boards
[i
].numPorts
= 0;
405 moxa_boards
[i
].baseAddr
= 0;
406 moxa_boards
[i
].busType
= 0;
407 moxa_boards
[i
].pciInfo
.busNum
= 0;
408 moxa_boards
[i
].pciInfo
.devNum
= 0;
411 printk("Tty devices major number = %d, callout devices major number = %d\n", ttymajor
, calloutmajor
);
415 if ((ret1
= tty_register_driver(&moxaDriver
))) {
416 printk(KERN_ERR
"Couldn't install MOXA Smartio family driver !\n");
417 } else if ((ret2
= tty_register_driver(&moxaCallout
))) {
418 tty_unregister_driver(&moxaDriver
);
419 printk(KERN_ERR
"Couldn't install MOXA Smartio family callout driver !\n");
424 for (i
= 0; i
< MAX_PORTS
; i
++) {
425 init_timer(&moxaEmptyTimer
[i
]);
426 moxaEmptyTimer
[i
].function
= check_xmit_empty
;
427 moxaEmptyTimer
[i
].data
= (unsigned long) & moxaChannels
[i
];
428 moxaEmptyTimer_on
[i
] = 0;
431 init_timer(&moxaTimer
);
432 moxaTimer
.function
= moxa_poll
;
433 moxaTimer
.expires
= jiffies
+ (HZ
/ 50);
435 add_timer(&moxaTimer
);
437 /* Find the boards defined in source code */
439 for (i
= 0; i
< MAX_BOARDS
; i
++) {
440 if ((moxa_isa_boards
[i
].boardType
== MOXA_BOARD_C218_ISA
) ||
441 (moxa_isa_boards
[i
].boardType
== MOXA_BOARD_C320_ISA
)) {
442 moxa_boards
[numBoards
].boardType
= moxa_isa_boards
[i
].boardType
;
443 if (moxa_isa_boards
[i
].boardType
== MOXA_BOARD_C218_ISA
)
444 moxa_boards
[numBoards
].numPorts
= 8;
446 moxa_boards
[numBoards
].numPorts
= moxa_isa_boards
[i
].numPorts
;
447 moxa_boards
[numBoards
].busType
= MOXA_BUS_TYPE_ISA
;
448 moxa_boards
[numBoards
].baseAddr
= moxa_isa_boards
[i
].baseAddr
;
450 printk("Board %2d: %s board(baseAddr=%lx)\n",
452 moxa_brdname
[moxa_boards
[numBoards
].boardType
- 1],
453 moxa_boards
[numBoards
].baseAddr
);
457 /* Find the boards defined form module args. */
459 for (i
= 0; i
< MAX_BOARDS
; i
++) {
460 if ((type
[i
] == MOXA_BOARD_C218_ISA
) ||
461 (type
[i
] == MOXA_BOARD_C320_ISA
)) {
463 printk("Board %2d: %s board(baseAddr=%lx)\n",
465 moxa_brdname
[type
[i
] - 1],
466 (unsigned long) baseaddr
[i
]);
467 if (numBoards
>= MAX_BOARDS
) {
469 printk("More than %d MOXA Intellio family boards found. Board is ignored.", MAX_BOARDS
);
472 moxa_boards
[numBoards
].boardType
= type
[i
];
473 if (moxa_isa_boards
[i
].boardType
== MOXA_BOARD_C218_ISA
)
474 moxa_boards
[numBoards
].numPorts
= 8;
476 moxa_boards
[numBoards
].numPorts
= numports
[i
];
477 moxa_boards
[numBoards
].busType
= MOXA_BUS_TYPE_ISA
;
478 moxa_boards
[numBoards
].baseAddr
= baseaddr
[i
];
483 /* Find PCI boards here */
486 struct pci_dev
*p
= NULL
;
487 n
= sizeof(moxa_pcibrds
) / sizeof(moxa_pciinfo
);
490 while((p
= pci_find_device(moxa_pcibrds
[i
].vendor_id
, moxa_pcibrds
[i
].device_id
, p
))!=NULL
)
492 if (pci_enable_device(p
))
494 if (numBoards
>= MAX_BOARDS
) {
496 printk("More than %d MOXA Intellio family boards found. Board is ignored.", MAX_BOARDS
);
498 moxa_get_PCI_conf(p
, moxa_pcibrds
[i
].board_type
,
499 &moxa_boards
[numBoards
]);
507 for (i
= 0; i
< numBoards
; i
++) {
508 moxaBaseAddr
[i
] = (unsigned long) ioremap((unsigned long) moxa_boards
[i
].baseAddr
, 0x4000);
514 static int moxa_get_PCI_conf(struct pci_dev
*p
, int board_type
, moxa_board_conf
* board
)
516 board
->baseAddr
= pci_resource_start (p
, 2);
517 board
->boardType
= board_type
;
518 switch (board_type
) {
519 case MOXA_BOARD_C218_ISA
:
520 case MOXA_BOARD_C218_PCI
:
524 case MOXA_BOARD_CP204J
:
531 board
->busType
= MOXA_BUS_TYPE_PCI
;
532 board
->pciInfo
.busNum
= p
->bus
->number
;
533 board
->pciInfo
.devNum
= p
->devfn
>> 3;
538 static void do_moxa_softint(void *private_
)
540 struct moxa_str
*ch
= (struct moxa_str
*) private_
;
541 struct tty_struct
*tty
;
543 if (!ch
|| !(tty
= ch
->tty
))
545 if (test_and_clear_bit(MOXA_EVENT_HANGUP
, &ch
->event
)) {
547 wake_up_interruptible(&ch
->open_wait
);
548 ch
->asyncflags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CALLOUT_ACTIVE
);
552 static int moxa_open(struct tty_struct
*tty
, struct file
*filp
)
560 if (port
== MAX_PORTS
) {
564 if (!MoxaPortIsValid(port
)) {
565 tty
->driver_data
= NULL
;
570 page
= get_free_page(GFP_KERNEL
);
578 moxaXmitBuff
= (unsigned char *) page
;
583 ch
= &moxaChannels
[port
];
585 tty
->driver_data
= ch
;
587 if (ch
->count
== 1 && (ch
->asyncflags
& ASYNC_SPLIT_TERMIOS
)) {
588 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
589 *tty
->termios
= ch
->normal_termios
;
591 *tty
->termios
= ch
->callout_termios
;
593 ch
->session
= current
->session
;
594 ch
->pgrp
= current
->pgrp
;
595 if (!(ch
->asyncflags
& ASYNC_INITIALIZED
)) {
598 MoxaPortLineCtrl(ch
->port
, 1, 1);
599 MoxaPortEnable(ch
->port
);
600 ch
->asyncflags
|= ASYNC_INITIALIZED
;
602 retval
= block_till_ready(tty
, filp
, ch
);
604 moxa_unthrottle(tty
);
606 if (ch
->type
== PORT_16550A
) {
607 MoxaSetFifo(ch
->port
, 1);
609 MoxaSetFifo(ch
->port
, 0);
615 static void moxa_close(struct tty_struct
*tty
, struct file
*filp
)
621 if (port
== MAX_PORTS
) {
625 if (!MoxaPortIsValid(port
)) {
626 #ifdef SERIAL_DEBUG_CLOSE
627 printk("Invalid portno in moxa_close\n");
629 tty
->driver_data
= NULL
;
632 if (tty
->driver_data
== NULL
) {
635 if (tty_hung_up_p(filp
)) {
639 ch
= (struct moxa_str
*) tty
->driver_data
;
641 if ((tty
->count
== 1) && (ch
->count
!= 1)) {
642 printk("moxa_close: bad serial port count; tty->count is 1, "
643 "ch->count is %d\n", ch
->count
);
646 if (--ch
->count
< 0) {
647 printk("moxa_close: bad serial port count, minor=%d\n",
655 ch
->asyncflags
|= ASYNC_CLOSING
;
658 * Save the termios structure, since this port may have
659 * separate termios for callout and dialin.
661 if (ch
->asyncflags
& ASYNC_NORMAL_ACTIVE
)
662 ch
->normal_termios
= *tty
->termios
;
663 if (ch
->asyncflags
& ASYNC_CALLOUT_ACTIVE
)
664 ch
->callout_termios
= *tty
->termios
;
665 if (ch
->asyncflags
& ASYNC_INITIALIZED
) {
666 setup_empty_event(tty
);
667 tty_wait_until_sent(tty
, 30 * HZ
); /* 30 seconds timeout */
668 moxaEmptyTimer_on
[ch
->port
] = 0;
669 del_timer(&moxaEmptyTimer
[ch
->port
]);
672 MoxaPortFlushData(port
, 2);
674 if (tty
->driver
.flush_buffer
)
675 tty
->driver
.flush_buffer(tty
);
676 if (tty
->ldisc
.flush_buffer
)
677 tty
->ldisc
.flush_buffer(tty
);
681 if (ch
->blocked_open
) {
682 if (ch
->close_delay
) {
683 current
->state
= TASK_INTERRUPTIBLE
;
684 schedule_timeout(ch
->close_delay
);
686 wake_up_interruptible(&ch
->open_wait
);
688 ch
->asyncflags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CALLOUT_ACTIVE
|
690 wake_up_interruptible(&ch
->close_wait
);
694 static int moxa_write(struct tty_struct
*tty
, int from_user
,
695 const unsigned char *buf
, int count
)
702 ch
= (struct moxa_str
*) tty
->driver_data
;
709 copy_from_user(moxaXmitBuff
, buf
, count
);
712 temp
= (unsigned char *) buf
;
713 len
= MoxaPortWriteData(port
, temp
, count
);
714 restore_flags(flags
);
715 /*********************************************
716 if ( !(ch->statusflags & LOWWAIT) &&
717 ((len != count) || (MoxaPortTxFree(port) <= 100)) )
718 ************************************************/
719 ch
->statusflags
|= LOWWAIT
;
723 static int moxa_write_room(struct tty_struct
*tty
)
729 ch
= (struct moxa_str
*) tty
->driver_data
;
732 return (MoxaPortTxFree(ch
->port
));
735 static void moxa_flush_buffer(struct tty_struct
*tty
)
737 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
741 MoxaPortFlushData(ch
->port
, 1);
742 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
743 tty
->ldisc
.write_wakeup
)
744 (tty
->ldisc
.write_wakeup
) (tty
);
745 wake_up_interruptible(&tty
->write_wait
);
748 static int moxa_chars_in_buffer(struct tty_struct
*tty
)
751 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
754 * Sigh...I have to check if driver_data is NULL here, because
755 * if an open() fails, the TTY subsystem eventually calls
756 * tty_wait_until_sent(), which calls the driver's chars_in_buffer()
757 * routine. And since the open() failed, we return 0 here. TDJ
761 chars
= MoxaPortTxQueue(ch
->port
);
764 * Make it possible to wakeup anything waiting for output
765 * in tty_ioctl.c, etc.
767 if (!(ch
->statusflags
& EMPTYWAIT
))
768 setup_empty_event(tty
);
773 static void moxa_flush_chars(struct tty_struct
*tty
)
776 * Don't think I need this, because this is called to empty the TX
777 * buffer for the 16450, 16550, etc.
781 static void moxa_put_char(struct tty_struct
*tty
, unsigned char c
)
787 ch
= (struct moxa_str
*) tty
->driver_data
;
794 MoxaPortWriteData(port
, moxaXmitBuff
, 1);
795 restore_flags(flags
);
796 /************************************************
797 if ( !(ch->statusflags & LOWWAIT) && (MoxaPortTxFree(port) <= 100) )
798 *************************************************/
799 ch
->statusflags
|= LOWWAIT
;
802 static int moxa_ioctl(struct tty_struct
*tty
, struct file
*file
,
803 unsigned int cmd
, unsigned long arg
)
805 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
807 int retval
, dtr
, rts
;
811 if ((port
!= MAX_PORTS
) && (!ch
))
815 case TCSBRK
: /* SVID version: non-zero arg --> no break */
816 retval
= tty_check_change(tty
);
819 setup_empty_event(tty
);
820 tty_wait_until_sent(tty
, 0);
822 MoxaPortSendBreak(ch
->port
, 0);
824 case TCSBRKP
: /* support for POSIX tcsendbreak() */
825 retval
= tty_check_change(tty
);
828 setup_empty_event(tty
);
829 tty_wait_until_sent(tty
, 0);
830 MoxaPortSendBreak(ch
->port
, arg
);
833 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long *) arg
);
835 if(get_user(retval
, (unsigned long *) arg
))
838 tty
->termios
->c_cflag
= ((tty
->termios
->c_cflag
& ~CLOCAL
) |
841 ch
->asyncflags
&= ~ASYNC_CHECK_CD
;
843 ch
->asyncflags
|= ASYNC_CHECK_CD
;
847 MoxaPortGetLineOut(ch
->port
, &dtr
, &rts
);
852 dtr
= MoxaPortLineStatus(ch
->port
);
859 return put_user(flag
, (unsigned int *) arg
);
861 if(get_user(retval
, (unsigned int *) arg
))
863 MoxaPortGetLineOut(ch
->port
, &dtr
, &rts
);
864 if (retval
& TIOCM_RTS
)
866 if (retval
& TIOCM_DTR
)
868 MoxaPortLineCtrl(ch
->port
, dtr
, rts
);
871 if(get_user(retval
, (unsigned int *) arg
))
873 MoxaPortGetLineOut(ch
->port
, &dtr
, &rts
);
874 if (retval
& TIOCM_RTS
)
876 if (retval
& TIOCM_DTR
)
878 MoxaPortLineCtrl(ch
->port
, dtr
, rts
);
881 if(get_user(retval
, (unsigned long *) arg
))
884 if (retval
& TIOCM_RTS
)
886 if (retval
& TIOCM_DTR
)
888 MoxaPortLineCtrl(ch
->port
, dtr
, rts
);
891 return (moxa_get_serial_info(ch
, (struct serial_struct
*) arg
));
894 return (moxa_set_serial_info(ch
, (struct serial_struct
*) arg
));
896 retval
= MoxaDriverIoctl(cmd
, arg
, port
);
901 static void moxa_throttle(struct tty_struct
*tty
)
903 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
905 ch
->statusflags
|= THROTTLE
;
908 static void moxa_unthrottle(struct tty_struct
*tty
)
910 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
912 ch
->statusflags
&= ~THROTTLE
;
915 static void moxa_set_termios(struct tty_struct
*tty
,
916 struct termios
*old_termios
)
918 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
923 if (!(old_termios
->c_cflag
& CLOCAL
) &&
924 (tty
->termios
->c_cflag
& CLOCAL
))
925 wake_up_interruptible(&ch
->open_wait
);
928 static void moxa_stop(struct tty_struct
*tty
)
930 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
934 MoxaPortTxDisable(ch
->port
);
935 ch
->statusflags
|= TXSTOPPED
;
939 static void moxa_start(struct tty_struct
*tty
)
941 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
946 if (!(ch
->statusflags
& TXSTOPPED
))
949 MoxaPortTxEnable(ch
->port
);
950 ch
->statusflags
&= ~TXSTOPPED
;
953 static void moxa_hangup(struct tty_struct
*tty
)
955 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
957 moxa_flush_buffer(tty
);
961 ch
->asyncflags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CALLOUT_ACTIVE
);
963 wake_up_interruptible(&ch
->open_wait
);
966 static void moxa_poll(unsigned long ignored
)
970 struct tty_struct
*tp
;
974 del_timer(&moxaTimer
);
976 if (MoxaDriverPoll() < 0) {
977 moxaTimer
.function
= moxa_poll
;
978 moxaTimer
.expires
= jiffies
+ (HZ
/ 50);
980 add_timer(&moxaTimer
);
983 for (card
= 0; card
< MAX_BOARDS
; card
++) {
984 if ((ports
= MoxaPortsOfCard(card
)) <= 0)
986 ch
= &moxaChannels
[card
* MAX_PORTS_PER_BOARD
];
987 for (i
= 0; i
< ports
; i
++, ch
++) {
988 if ((ch
->asyncflags
& ASYNC_INITIALIZED
) == 0)
990 if (!(ch
->statusflags
& THROTTLE
) &&
991 (MoxaPortRxQueue(ch
->port
) > 0))
993 if ((tp
= ch
->tty
) == 0)
995 if (ch
->statusflags
& LOWWAIT
) {
996 if (MoxaPortTxQueue(ch
->port
) <= WAKEUP_CHARS
) {
998 ch
->statusflags
&= ~LOWWAIT
;
999 if ((tp
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1000 tp
->ldisc
.write_wakeup
)
1001 (tp
->ldisc
.write_wakeup
) (tp
);
1002 wake_up_interruptible(&tp
->write_wait
);
1006 if (!I_IGNBRK(tp
) && (MoxaPortResetBrkCnt(ch
->port
) > 0)) {
1007 tty_insert_flip_char(tp
, 0, TTY_BREAK
);
1008 tty_schedule_flip(tp
);
1010 if (MoxaPortDCDChange(ch
->port
)) {
1011 if (ch
->asyncflags
& ASYNC_CHECK_CD
) {
1012 if (MoxaPortDCDON(ch
->port
))
1013 wake_up_interruptible(&ch
->open_wait
);
1015 set_bit(MOXA_EVENT_HANGUP
, &ch
->event
);
1016 queue_task(&ch
->tqueue
, &tq_scheduler
);
1023 moxaTimer
.function
= moxa_poll
;
1024 moxaTimer
.expires
= jiffies
+ (HZ
/ 50);
1026 add_timer(&moxaTimer
);
1029 /******************************************************************************/
1031 static void set_tty_param(struct tty_struct
*tty
)
1033 register struct termios
*ts
;
1034 struct moxa_str
*ch
;
1035 int rts
, cts
, txflow
, rxflow
, xany
;
1037 ch
= (struct moxa_str
*) tty
->driver_data
;
1039 if (ts
->c_cflag
& CLOCAL
)
1040 ch
->asyncflags
&= ~ASYNC_CHECK_CD
;
1042 ch
->asyncflags
|= ASYNC_CHECK_CD
;
1043 rts
= cts
= txflow
= rxflow
= xany
= 0;
1044 if (ts
->c_cflag
& CRTSCTS
)
1046 if (ts
->c_iflag
& IXON
)
1048 if (ts
->c_iflag
& IXOFF
)
1050 if (ts
->c_iflag
& IXANY
)
1052 MoxaPortFlowCtrl(ch
->port
, rts
, cts
, txflow
, rxflow
, xany
);
1053 MoxaPortSetTermio(ch
->port
, ts
);
1056 static int block_till_ready(struct tty_struct
*tty
, struct file
*filp
,
1057 struct moxa_str
*ch
)
1059 DECLARE_WAITQUEUE(wait
,current
);
1060 unsigned long flags
;
1062 int do_clocal
= C_CLOCAL(tty
);
1065 * If the device is in the middle of being closed, then block
1066 * until it's done, and then try again.
1068 if (tty_hung_up_p(filp
) || (ch
->asyncflags
& ASYNC_CLOSING
)) {
1069 if (ch
->asyncflags
& ASYNC_CLOSING
)
1070 interruptible_sleep_on(&ch
->close_wait
);
1071 #ifdef SERIAL_DO_RESTART
1072 if (ch
->asyncflags
& ASYNC_HUP_NOTIFY
)
1075 return (-ERESTARTSYS
);
1081 * If this is a callout device, then just make sure the normal
1082 * device isn't being used.
1084 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
1085 if (ch
->asyncflags
& ASYNC_NORMAL_ACTIVE
)
1087 if ((ch
->asyncflags
& ASYNC_CALLOUT_ACTIVE
) &&
1088 (ch
->asyncflags
& ASYNC_SESSION_LOCKOUT
) &&
1089 (ch
->session
!= current
->session
))
1091 if ((ch
->asyncflags
& ASYNC_CALLOUT_ACTIVE
) &&
1092 (ch
->asyncflags
& ASYNC_PGRP_LOCKOUT
) &&
1093 (ch
->pgrp
!= current
->pgrp
))
1095 ch
->asyncflags
|= ASYNC_CALLOUT_ACTIVE
;
1099 * If non-blocking mode is set, then make the check up front
1102 if (filp
->f_flags
& O_NONBLOCK
) {
1103 if (ch
->asyncflags
& ASYNC_CALLOUT_ACTIVE
)
1105 ch
->asyncflags
|= ASYNC_NORMAL_ACTIVE
;
1109 * Block waiting for the carrier detect and the line to become free
1112 add_wait_queue(&ch
->open_wait
, &wait
);
1113 #ifdef SERIAL_DEBUG_OPEN
1114 printk("block_til_ready before block: ttys%d, count = %d\n",
1115 ch
->line
, ch
->count
);
1119 if (!tty_hung_up_p(filp
))
1121 restore_flags(flags
);
1124 current
->state
= TASK_INTERRUPTIBLE
;
1125 if (tty_hung_up_p(filp
) ||
1126 !(ch
->asyncflags
& ASYNC_INITIALIZED
)) {
1127 #ifdef SERIAL_DO_RESTART
1128 if (ch
->asyncflags
& ASYNC_HUP_NOTIFY
)
1131 retval
= -ERESTARTSYS
;
1137 if (!(ch
->asyncflags
& ASYNC_CALLOUT_ACTIVE
) &&
1138 !(ch
->asyncflags
& ASYNC_CLOSING
) && (do_clocal
||
1139 MoxaPortDCDON(ch
->port
)))
1142 if (signal_pending(current
)) {
1143 retval
= -ERESTARTSYS
;
1148 current
->state
= TASK_RUNNING
;
1149 remove_wait_queue(&ch
->open_wait
, &wait
);
1150 if (!tty_hung_up_p(filp
))
1153 #ifdef SERIAL_DEBUG_OPEN
1154 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1155 ch
->line
, ch
->count
);
1159 ch
->asyncflags
|= ASYNC_NORMAL_ACTIVE
;
1163 static void setup_empty_event(struct tty_struct
*tty
)
1165 struct moxa_str
*ch
= tty
->driver_data
;
1166 unsigned long flags
;
1170 ch
->statusflags
|= EMPTYWAIT
;
1171 moxaEmptyTimer_on
[ch
->port
] = 0;
1172 del_timer(&moxaEmptyTimer
[ch
->port
]);
1173 moxaEmptyTimer
[ch
->port
].expires
= jiffies
+ HZ
;
1174 moxaEmptyTimer_on
[ch
->port
] = 1;
1175 add_timer(&moxaEmptyTimer
[ch
->port
]);
1176 restore_flags(flags
);
1179 static void check_xmit_empty(unsigned long data
)
1181 struct moxa_str
*ch
;
1183 ch
= (struct moxa_str
*) data
;
1184 moxaEmptyTimer_on
[ch
->port
] = 0;
1185 del_timer(&moxaEmptyTimer
[ch
->port
]);
1186 if (ch
->tty
&& (ch
->statusflags
& EMPTYWAIT
)) {
1187 if (MoxaPortTxQueue(ch
->port
) == 0) {
1188 ch
->statusflags
&= ~EMPTYWAIT
;
1189 if ((ch
->tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1190 ch
->tty
->ldisc
.write_wakeup
)
1191 (ch
->tty
->ldisc
.write_wakeup
) (ch
->tty
);
1192 wake_up_interruptible(&ch
->tty
->write_wait
);
1195 moxaEmptyTimer
[ch
->port
].expires
= jiffies
+ HZ
;
1196 moxaEmptyTimer_on
[ch
->port
] = 1;
1197 add_timer(&moxaEmptyTimer
[ch
->port
]);
1199 ch
->statusflags
&= ~EMPTYWAIT
;
1202 static void shut_down(struct moxa_str
*ch
)
1204 struct tty_struct
*tp
;
1206 if (!(ch
->asyncflags
& ASYNC_INITIALIZED
))
1211 MoxaPortDisable(ch
->port
);
1214 * If we're a modem control device and HUPCL is on, drop RTS & DTR.
1216 if (tp
->termios
->c_cflag
& HUPCL
)
1217 MoxaPortLineCtrl(ch
->port
, 0, 0);
1219 ch
->asyncflags
&= ~ASYNC_INITIALIZED
;
1222 static void receive_data(struct moxa_str
*ch
)
1224 struct tty_struct
*tp
;
1226 int i
, count
, rc
, space
;
1227 unsigned char *charptr
, *flagptr
;
1228 unsigned long flags
;
1234 /**************************************************
1235 if ( !tp || !ts || !(ts->c_cflag & CREAD) ) {
1236 *****************************************************/
1238 MoxaPortFlushData(ch
->port
, 0);
1241 space
= TTY_FLIPBUF_SIZE
- tp
->flip
.count
;
1244 charptr
= tp
->flip
.char_buf_ptr
;
1245 flagptr
= tp
->flip
.flag_buf_ptr
;
1246 rc
= tp
->flip
.count
;
1249 count
= MoxaPortReadData(ch
->port
, charptr
, space
);
1250 restore_flags(flags
);
1251 for (i
= 0; i
< count
; i
++)
1255 tp
->flip
.count
= rc
;
1256 tp
->flip
.char_buf_ptr
= charptr
;
1257 tp
->flip
.flag_buf_ptr
= flagptr
;
1258 tty_schedule_flip(ch
->tty
);
1261 #define Magic_code 0x404
1264 * System Configuration
1267 * for C218 BIOS initialization
1269 #define C218_ConfBase 0x800
1270 #define C218_status (C218_ConfBase + 0) /* BIOS running status */
1271 #define C218_diag (C218_ConfBase + 2) /* diagnostic status */
1272 #define C218_key (C218_ConfBase + 4) /* WORD (0x218 for C218) */
1273 #define C218DLoad_len (C218_ConfBase + 6) /* WORD */
1274 #define C218check_sum (C218_ConfBase + 8) /* BYTE */
1275 #define C218chksum_ok (C218_ConfBase + 0x0a) /* BYTE (1:ok) */
1276 #define C218_TestRx (C218_ConfBase + 0x10) /* 8 bytes for 8 ports */
1277 #define C218_TestTx (C218_ConfBase + 0x18) /* 8 bytes for 8 ports */
1278 #define C218_RXerr (C218_ConfBase + 0x20) /* 8 bytes for 8 ports */
1279 #define C218_ErrFlag (C218_ConfBase + 0x28) /* 8 bytes for 8 ports */
1281 #define C218_LoadBuf 0x0F00
1282 #define C218_KeyCode 0x218
1283 #define CP204J_KeyCode 0x204
1286 * for C320 BIOS initialization
1288 #define C320_ConfBase 0x800
1289 #define C320_LoadBuf 0x0f00
1290 #define STS_init 0x05 /* for C320_status */
1292 #define C320_status C320_ConfBase + 0 /* BIOS running status */
1293 #define C320_diag C320_ConfBase + 2 /* diagnostic status */
1294 #define C320_key C320_ConfBase + 4 /* WORD (0320H for C320) */
1295 #define C320DLoad_len C320_ConfBase + 6 /* WORD */
1296 #define C320check_sum C320_ConfBase + 8 /* WORD */
1297 #define C320chksum_ok C320_ConfBase + 0x0a /* WORD (1:ok) */
1298 #define C320bapi_len C320_ConfBase + 0x0c /* WORD */
1299 #define C320UART_no C320_ConfBase + 0x0e /* WORD */
1301 #define C320_KeyCode 0x320
1303 #define FixPage_addr 0x0000 /* starting addr of static page */
1304 #define DynPage_addr 0x2000 /* starting addr of dynamic page */
1305 #define C218_start 0x3000 /* starting addr of C218 BIOS prg */
1306 #define Control_reg 0x1ff0 /* select page and reset control */
1307 #define HW_reset 0x80
1312 #define FC_CardReset 0x80
1313 #define FC_ChannelReset 1 /* C320 firmware not supported */
1314 #define FC_EnableCH 2
1315 #define FC_DisableCH 3
1316 #define FC_SetParam 4
1317 #define FC_SetMode 5
1318 #define FC_SetRate 6
1319 #define FC_LineControl 7
1320 #define FC_LineStatus 8
1321 #define FC_XmitControl 9
1322 #define FC_FlushQueue 10
1323 #define FC_SendBreak 11
1324 #define FC_StopBreak 12
1325 #define FC_LoopbackON 13
1326 #define FC_LoopbackOFF 14
1327 #define FC_ClrIrqTable 15
1328 #define FC_SendXon 16
1329 #define FC_SetTermIrq 17 /* C320 firmware not supported */
1330 #define FC_SetCntIrq 18 /* C320 firmware not supported */
1331 #define FC_SetBreakIrq 19
1332 #define FC_SetLineIrq 20
1333 #define FC_SetFlowCtl 21
1334 #define FC_GenIrq 22
1335 #define FC_InCD180 23
1336 #define FC_OutCD180 24
1337 #define FC_InUARTreg 23
1338 #define FC_OutUARTreg 24
1339 #define FC_SetXonXoff 25
1340 #define FC_OutCD180CCR 26
1341 #define FC_ExtIQueue 27
1342 #define FC_ExtOQueue 28
1343 #define FC_ClrLineIrq 29
1344 #define FC_HWFlowCtl 30
1345 #define FC_GetClockRate 35
1346 #define FC_SetBaud 36
1347 #define FC_SetDataMode 41
1348 #define FC_GetCCSR 43
1349 #define FC_GetDataError 45
1350 #define FC_RxControl 50
1351 #define FC_ImmSend 51
1352 #define FC_SetXonState 52
1353 #define FC_SetXoffState 53
1354 #define FC_SetRxFIFOTrig 54
1355 #define FC_SetTxFIFOCnt 55
1356 #define FC_UnixRate 56
1357 #define FC_UnixResetTimer 57
1359 #define RxFIFOTrig1 0
1360 #define RxFIFOTrig4 1
1361 #define RxFIFOTrig8 2
1362 #define RxFIFOTrig14 3
1367 #define DRAM_global 0
1368 #define INT_data (DRAM_global + 0)
1369 #define Config_base (DRAM_global + 0x108)
1371 #define IRQindex (INT_data + 0)
1372 #define IRQpending (INT_data + 4)
1373 #define IRQtable (INT_data + 8)
1378 #define IntrRx 0x01 /* receiver data O.K. */
1379 #define IntrTx 0x02 /* transmit buffer empty */
1380 #define IntrFunc 0x04 /* function complete */
1381 #define IntrBreak 0x08 /* received break */
1382 #define IntrLine 0x10 /* line status change
1384 #define IntrIntr 0x20 /* received INTR code */
1385 #define IntrQuit 0x40 /* received QUIT code */
1386 #define IntrEOF 0x80 /* received EOF code */
1388 #define IntrRxTrigger 0x100 /* rx data count reach tigger value */
1389 #define IntrTxTrigger 0x200 /* tx data count below trigger value */
1391 #define Magic_no (Config_base + 0)
1392 #define Card_model_no (Config_base + 2)
1393 #define Total_ports (Config_base + 4)
1394 #define Module_cnt (Config_base + 8)
1395 #define Module_no (Config_base + 10)
1396 #define Timer_10ms (Config_base + 14)
1397 #define Disable_IRQ (Config_base + 20)
1398 #define TMS320_PORT1 (Config_base + 22)
1399 #define TMS320_PORT2 (Config_base + 24)
1400 #define TMS320_CLOCK (Config_base + 26)
1403 * DATA BUFFER in DRAM
1405 #define Extern_table 0x400 /* Base address of the external table
1406 (24 words * 64) total 3K bytes
1407 (24 words * 128) total 6K bytes */
1408 #define Extern_size 0x60 /* 96 bytes */
1409 #define RXrptr 0x00 /* read pointer for RX buffer */
1410 #define RXwptr 0x02 /* write pointer for RX buffer */
1411 #define TXrptr 0x04 /* read pointer for TX buffer */
1412 #define TXwptr 0x06 /* write pointer for TX buffer */
1413 #define HostStat 0x08 /* IRQ flag and general flag */
1414 #define FlagStat 0x0A
1415 #define FlowControl 0x0C /* B7 B6 B5 B4 B3 B2 B1 B0 */
1416 /* x x x x | | | | */
1417 /* | | | + CTS flow */
1418 /* | | +--- RTS flow */
1419 /* | +------ TX Xon/Xoff */
1420 /* +--------- RX Xon/Xoff */
1421 #define Break_cnt 0x0E /* received break count */
1422 #define CD180TXirq 0x10 /* if non-0: enable TX irq */
1423 #define RX_mask 0x12
1424 #define TX_mask 0x14
1425 #define Ofs_rxb 0x16
1426 #define Ofs_txb 0x18
1427 #define Page_rxb 0x1A
1428 #define Page_txb 0x1C
1429 #define EndPage_rxb 0x1E
1430 #define EndPage_txb 0x20
1431 #define Data_error 0x22
1432 #define RxTrigger 0x28
1433 #define TxTrigger 0x2a
1435 #define rRXwptr 0x34
1436 #define Low_water 0x36
1438 #define FuncCode 0x40
1439 #define FuncArg 0x42
1440 #define FuncArg1 0x44
1442 #define C218rx_size 0x2000 /* 8K bytes */
1443 #define C218tx_size 0x8000 /* 32K bytes */
1445 #define C218rx_mask (C218rx_size - 1)
1446 #define C218tx_mask (C218tx_size - 1)
1448 #define C320p8rx_size 0x2000
1449 #define C320p8tx_size 0x8000
1450 #define C320p8rx_mask (C320p8rx_size - 1)
1451 #define C320p8tx_mask (C320p8tx_size - 1)
1453 #define C320p16rx_size 0x2000
1454 #define C320p16tx_size 0x4000
1455 #define C320p16rx_mask (C320p16rx_size - 1)
1456 #define C320p16tx_mask (C320p16tx_size - 1)
1458 #define C320p24rx_size 0x2000
1459 #define C320p24tx_size 0x2000
1460 #define C320p24rx_mask (C320p24rx_size - 1)
1461 #define C320p24tx_mask (C320p24tx_size - 1)
1463 #define C320p32rx_size 0x1000
1464 #define C320p32tx_size 0x1000
1465 #define C320p32rx_mask (C320p32rx_size - 1)
1466 #define C320p32tx_mask (C320p32tx_size - 1)
1468 #define Page_size 0x2000
1469 #define Page_mask (Page_size - 1)
1470 #define C218rx_spage 3
1471 #define C218tx_spage 4
1472 #define C218rx_pageno 1
1473 #define C218tx_pageno 4
1474 #define C218buf_pageno 5
1476 #define C320p8rx_spage 3
1477 #define C320p8tx_spage 4
1478 #define C320p8rx_pgno 1
1479 #define C320p8tx_pgno 4
1480 #define C320p8buf_pgno 5
1482 #define C320p16rx_spage 3
1483 #define C320p16tx_spage 4
1484 #define C320p16rx_pgno 1
1485 #define C320p16tx_pgno 2
1486 #define C320p16buf_pgno 3
1488 #define C320p24rx_spage 3
1489 #define C320p24tx_spage 4
1490 #define C320p24rx_pgno 1
1491 #define C320p24tx_pgno 1
1492 #define C320p24buf_pgno 2
1494 #define C320p32rx_spage 3
1495 #define C320p32tx_ofs C320p32rx_size
1496 #define C320p32tx_spage 3
1497 #define C320p32buf_pgno 1
1502 #define WakeupRx 0x01
1503 #define WakeupTx 0x02
1504 #define WakeupBreak 0x08
1505 #define WakeupLine 0x10
1506 #define WakeupIntr 0x20
1507 #define WakeupQuit 0x40
1508 #define WakeupEOF 0x80 /* used in VTIME control */
1509 #define WakeupRxTrigger 0x100
1510 #define WakeupTxTrigger 0x200
1514 #define Rx_over 0x01
1515 #define Xoff_state 0x02
1516 #define Tx_flowOff 0x04
1517 #define Tx_enable 0x08
1518 #define CTS_state 0x10
1519 #define DSR_state 0x20
1520 #define DCD_state 0x80
1524 #define CTS_FlowCtl 1
1525 #define RTS_FlowCtl 2
1526 #define Tx_FlowCtl 4
1527 #define Rx_FlowCtl 8
1528 #define IXM_IXANY 0x10
1530 #define LowWater 128
1538 /* mode definition */
1544 #define MX_STOP1 0x00
1545 #define MX_STOP15 0x04
1546 #define MX_STOP2 0x08
1548 #define MX_PARNONE 0x00
1549 #define MX_PAREVEN 0x40
1550 #define MX_PARODD 0xC0
1555 #define QueryPort MAX_PORTS
1561 int rxcnt
[MAX_PORTS
];
1562 int txcnt
[MAX_PORTS
];
1564 typedef struct mon_str mon_st
;
1566 #define DCD_changed 0x01
1567 #define DCD_oldstate 0x80
1569 static unsigned char moxaBuff
[10240];
1570 static unsigned long moxaIntNdx
[MAX_BOARDS
];
1571 static unsigned long moxaIntPend
[MAX_BOARDS
];
1572 static unsigned long moxaIntTable
[MAX_BOARDS
];
1573 static char moxaChkPort
[MAX_PORTS
];
1574 static char moxaLineCtrl
[MAX_PORTS
];
1575 static unsigned long moxaTableAddr
[MAX_PORTS
];
1576 static long moxaCurBaud
[MAX_PORTS
];
1577 static char moxaDCDState
[MAX_PORTS
];
1578 static char moxaLowChkFlag
[MAX_PORTS
];
1579 static int moxaLowWaterChk
;
1580 static int moxaCard
;
1581 static mon_st moxaLog
;
1582 static int moxaFuncTout
;
1583 static ushort moxaBreakCnt
[MAX_PORTS
];
1585 static void moxadelay(int);
1586 static void moxafunc(unsigned long, int, ushort
);
1587 static void wait_finish(unsigned long);
1588 static void low_water_check(unsigned long);
1589 static int moxaloadbios(int, unsigned char *, int);
1590 static int moxafindcard(int);
1591 static int moxaload320b(int, unsigned char *, int);
1592 static int moxaloadcode(int, unsigned char *, int);
1593 static int moxaloadc218(int, unsigned long, int);
1594 static int moxaloadc320(int, unsigned long, int, int *);
1596 /*****************************************************************************
1597 * Driver level functions: *
1598 * 1. MoxaDriverInit(void); *
1599 * 2. MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port); *
1600 * 3. MoxaDriverPoll(void); *
1601 *****************************************************************************/
1602 void MoxaDriverInit(void)
1606 moxaFuncTout
= HZ
/ 2; /* 500 mini-seconds */
1609 moxaLowWaterChk
= 0;
1610 for (i
= 0; i
< MAX_PORTS
; i
++) {
1612 moxaLowChkFlag
[i
] = 0;
1613 moxaLineCtrl
[i
] = 0;
1614 moxaLog
.rxcnt
[i
] = 0;
1615 moxaLog
.txcnt
[i
] = 0;
1620 #define MOXA_GET_IQUEUE (MOXA + 1) /* get input buffered count */
1621 #define MOXA_GET_OQUEUE (MOXA + 2) /* get output buffered count */
1622 #define MOXA_INIT_DRIVER (MOXA + 6) /* moxaCard=0 */
1623 #define MOXA_LOAD_BIOS (MOXA + 9) /* download BIOS */
1624 #define MOXA_FIND_BOARD (MOXA + 10) /* Check if MOXA card exist? */
1625 #define MOXA_LOAD_C320B (MOXA + 11) /* download 320B firmware */
1626 #define MOXA_LOAD_CODE (MOXA + 12) /* download firmware */
1627 #define MOXA_GETDATACOUNT (MOXA + 23)
1628 #define MOXA_GET_IOQUEUE (MOXA + 27)
1629 #define MOXA_FLUSH_QUEUE (MOXA + 28)
1630 #define MOXA_GET_CONF (MOXA + 35) /* configuration */
1631 #define MOXA_GET_MAJOR (MOXA + 63)
1632 #define MOXA_GET_CUMAJOR (MOXA + 64)
1633 #define MOXA_GETMSTATUS (MOXA + 65)
1647 static struct moxaq_str temp_queue
[MAX_PORTS
];
1648 static struct dl_str dltmp
;
1650 void MoxaPortFlushData(int port
, int mode
)
1652 unsigned long ofsAddr
;
1653 if ((mode
< 0) || (mode
> 2))
1655 ofsAddr
= moxaTableAddr
[port
];
1656 moxafunc(ofsAddr
, FC_FlushQueue
, mode
);
1658 moxaLowChkFlag
[port
] = 0;
1659 low_water_check(ofsAddr
);
1663 int MoxaDriverIoctl(unsigned int cmd
, unsigned long arg
, int port
)
1667 int MoxaPortTxQueue(int), MoxaPortRxQueue(int);
1669 if (port
== QueryPort
) {
1670 if ((cmd
!= MOXA_GET_CONF
) && (cmd
!= MOXA_INIT_DRIVER
) &&
1671 (cmd
!= MOXA_LOAD_BIOS
) && (cmd
!= MOXA_FIND_BOARD
) && (cmd
!= MOXA_LOAD_C320B
) &&
1672 (cmd
!= MOXA_LOAD_CODE
) && (cmd
!= MOXA_GETDATACOUNT
) &&
1673 (cmd
!= MOXA_GET_IOQUEUE
) && (cmd
!= MOXA_GET_MAJOR
) &&
1674 (cmd
!= MOXA_GET_CUMAJOR
) && (cmd
!= MOXA_GETMSTATUS
))
1679 if(copy_to_user((void *)arg
, &moxa_boards
, MAX_BOARDS
* sizeof(moxa_board_conf
)))
1682 case MOXA_INIT_DRIVER
:
1683 if ((int) arg
== 0x404)
1686 case MOXA_GETDATACOUNT
:
1687 moxaLog
.tick
= jiffies
;
1688 if(copy_to_user((void *)arg
, &moxaLog
, sizeof(mon_st
)))
1691 case MOXA_FLUSH_QUEUE
:
1692 MoxaPortFlushData(port
, arg
);
1694 case MOXA_GET_IOQUEUE
:
1695 for (i
= 0; i
< MAX_PORTS
; i
++) {
1696 if (moxaChkPort
[i
]) {
1697 temp_queue
[i
].inq
= MoxaPortRxQueue(i
);
1698 temp_queue
[i
].outq
= MoxaPortTxQueue(i
);
1701 if(copy_to_user((void *)arg
, temp_queue
, sizeof(struct moxaq_str
) * MAX_PORTS
))
1704 case MOXA_LOAD_BIOS
:
1705 if(copy_from_user(&dltmp
, (void *)arg
, sizeof(struct dl_str
)))
1707 i
= moxaloadbios(dltmp
.cardno
, dltmp
.buf
, dltmp
.len
);
1709 case MOXA_FIND_BOARD
:
1710 if(copy_from_user(&dltmp
, (void *)arg
, sizeof(struct dl_str
)))
1712 return moxafindcard(dltmp
.cardno
);
1713 case MOXA_LOAD_C320B
:
1714 if(copy_from_user(&dltmp
, (void *)arg
, sizeof(struct dl_str
)))
1716 moxaload320b(dltmp
.cardno
, dltmp
.buf
, dltmp
.len
);
1718 case MOXA_LOAD_CODE
:
1719 if(copy_from_user(&dltmp
, (void *)arg
, sizeof(struct dl_str
)))
1721 i
= moxaloadcode(dltmp
.cardno
, dltmp
.buf
, dltmp
.len
);
1725 case MOXA_GET_OQUEUE
:
1726 i
= MoxaPortTxQueue(port
);
1727 return put_user(i
, (unsigned long *) arg
);
1728 case MOXA_GET_IQUEUE
:
1729 i
= MoxaPortRxQueue(port
);
1730 return put_user(i
, (unsigned long *) arg
);
1731 case MOXA_GET_MAJOR
:
1732 if(copy_to_user((void *)arg
, &ttymajor
, sizeof(int)))
1735 case MOXA_GET_CUMAJOR
:
1736 if(copy_to_user((void *)arg
, &calloutmajor
, sizeof(int)))
1739 case MOXA_GETMSTATUS
:
1740 for (i
= 0; i
< MAX_PORTS
; i
++) {
1742 GMStatus
[i
].dcd
= 0;
1743 GMStatus
[i
].dsr
= 0;
1744 GMStatus
[i
].cts
= 0;
1745 if (!moxaChkPort
[i
]) {
1748 status
= MoxaPortLineStatus(moxaChannels
[i
].port
);
1750 GMStatus
[i
].cts
= 1;
1752 GMStatus
[i
].dsr
= 1;
1754 GMStatus
[i
].dcd
= 1;
1757 if (!moxaChannels
[i
].tty
|| !moxaChannels
[i
].tty
->termios
)
1758 GMStatus
[i
].cflag
= moxaChannels
[i
].normal_termios
.c_cflag
;
1760 GMStatus
[i
].cflag
= moxaChannels
[i
].tty
->termios
->c_cflag
;
1762 if(copy_to_user((void *)arg
, GMStatus
, sizeof(struct mxser_mstatus
) * MAX_PORTS
))
1767 return (-ENOIOCTLCMD
);
1770 int MoxaDriverPoll(void)
1772 register ushort temp
;
1774 unsigned long ip
, ofsAddr
;
1779 for (card
= 0; card
< MAX_BOARDS
; card
++) {
1780 if ((ports
= moxa_boards
[card
].numPorts
) == 0)
1782 if (readb(moxaIntPend
[card
]) == 0xff) {
1783 ip
= moxaIntTable
[card
] + readb(moxaIntNdx
[card
]);
1784 p
= card
* MAX_PORTS_PER_BOARD
;
1786 for (port
= 0; port
< ports
; port
+= 2, p
++) {
1787 if ((temp
= readw(ip
+ port
)) != 0) {
1788 writew(0, ip
+ port
);
1789 ofsAddr
= moxaTableAddr
[p
];
1791 writew(readw(ofsAddr
+ HostStat
) & ~WakeupTx
, ofsAddr
+ HostStat
);
1792 if (temp
& IntrBreak
) {
1795 if (temp
& IntrLine
) {
1796 if (readb(ofsAddr
+ FlagStat
) & DCD_state
) {
1797 if ((moxaDCDState
[p
] & DCD_oldstate
) == 0)
1798 moxaDCDState
[p
] = (DCD_oldstate
|
1801 if (moxaDCDState
[p
] & DCD_oldstate
)
1802 moxaDCDState
[p
] = DCD_changed
;
1807 writeb(0, moxaIntPend
[card
]);
1809 if (moxaLowWaterChk
) {
1810 p
= card
* MAX_PORTS_PER_BOARD
;
1811 for (port
= 0; port
< ports
; port
++, p
++) {
1812 if (moxaLowChkFlag
[p
]) {
1813 moxaLowChkFlag
[p
] = 0;
1814 ofsAddr
= moxaTableAddr
[p
];
1815 low_water_check(ofsAddr
);
1820 moxaLowWaterChk
= 0;
1824 /*****************************************************************************
1825 * Card level function: *
1826 * 1. MoxaPortsOfCard(int cardno); *
1827 *****************************************************************************/
1828 int MoxaPortsOfCard(int cardno
)
1831 if (moxa_boards
[cardno
].boardType
== 0)
1833 return (moxa_boards
[cardno
].numPorts
);
1836 /*****************************************************************************
1837 * Port level functions: *
1838 * 1. MoxaPortIsValid(int port); *
1839 * 2. MoxaPortEnable(int port); *
1840 * 3. MoxaPortDisable(int port); *
1841 * 4. MoxaPortGetMaxBaud(int port); *
1842 * 5. MoxaPortGetCurBaud(int port); *
1843 * 6. MoxaPortSetBaud(int port, long baud); *
1844 * 7. MoxaPortSetMode(int port, int databit, int stopbit, int parity); *
1845 * 8. MoxaPortSetTermio(int port, unsigned char *termio); *
1846 * 9. MoxaPortGetLineOut(int port, int *dtrState, int *rtsState); *
1847 * 10. MoxaPortLineCtrl(int port, int dtrState, int rtsState); *
1848 * 11. MoxaPortFlowCtrl(int port, int rts, int cts, int rx, int tx,int xany); *
1849 * 12. MoxaPortLineStatus(int port); *
1850 * 13. MoxaPortDCDChange(int port); *
1851 * 14. MoxaPortDCDON(int port); *
1852 * 15. MoxaPortFlushData(int port, int mode); *
1853 * 16. MoxaPortWriteData(int port, unsigned char * buffer, int length); *
1854 * 17. MoxaPortReadData(int port, unsigned char * buffer, int length); *
1855 * 18. MoxaPortTxBufSize(int port); *
1856 * 19. MoxaPortRxBufSize(int port); *
1857 * 20. MoxaPortTxQueue(int port); *
1858 * 21. MoxaPortTxFree(int port); *
1859 * 22. MoxaPortRxQueue(int port); *
1860 * 23. MoxaPortRxFree(int port); *
1861 * 24. MoxaPortTxDisable(int port); *
1862 * 25. MoxaPortTxEnable(int port); *
1863 * 26. MoxaPortGetBrkCnt(int port); *
1864 * 27. MoxaPortResetBrkCnt(int port); *
1865 * 28. MoxaPortSetXonXoff(int port, int xonValue, int xoffValue); *
1866 * 29. MoxaPortIsTxHold(int port); *
1867 * 30. MoxaPortSendBreak(int port, int ticks); *
1868 *****************************************************************************/
1870 * Moxa Port Number Description:
1872 * MOXA serial driver supports up to 4 MOXA-C218/C320 boards. And,
1873 * the port number using in MOXA driver functions will be 0 to 31 for
1874 * first MOXA board, 32 to 63 for second, 64 to 95 for third and 96
1875 * to 127 for fourth. For example, if you setup three MOXA boards,
1876 * first board is C218, second board is C320-16 and third board is
1877 * C320-32. The port number of first board (C218 - 8 ports) is from
1878 * 0 to 7. The port number of second board (C320 - 16 ports) is form
1879 * 32 to 47. The port number of third board (C320 - 32 ports) is from
1880 * 64 to 95. And those port numbers form 8 to 31, 48 to 63 and 96 to
1881 * 127 will be invalid.
1884 * Moxa Functions Description:
1886 * Function 1: Driver initialization routine, this routine must be
1887 * called when initialized driver.
1889 * void MoxaDriverInit();
1892 * Function 2: Moxa driver private IOCTL command processing.
1894 * int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port);
1896 * unsigned int cmd : IOCTL command
1897 * unsigned long arg : IOCTL argument
1898 * int port : port number (0 - 127)
1905 * Function 3: Moxa driver polling process routine.
1907 * int MoxaDriverPoll(void);
1909 * return: 0 ; polling O.K.
1910 * -1 : no any Moxa card.
1913 * Function 4: Get the ports of this card.
1915 * int MoxaPortsOfCard(int cardno);
1917 * int cardno : card number (0 - 3)
1919 * return: 0 : this card is invalid
1923 * Function 5: Check this port is valid or invalid
1925 * int MoxaPortIsValid(int port);
1926 * int port : port number (0 - 127, ref port description)
1928 * return: 0 : this port is invalid
1929 * 1 : this port is valid
1932 * Function 6: Enable this port to start Tx/Rx data.
1934 * void MoxaPortEnable(int port);
1935 * int port : port number (0 - 127)
1938 * Function 7: Disable this port
1940 * void MoxaPortDisable(int port);
1941 * int port : port number (0 - 127)
1944 * Function 8: Get the maximun available baud rate of this port.
1946 * long MoxaPortGetMaxBaud(int port);
1947 * int port : port number (0 - 127)
1949 * return: 0 : this port is invalid
1950 * 38400/57600/115200 bps
1953 * Function 9: Get the current baud rate of this port.
1955 * long MoxaPortGetCurBaud(int port);
1956 * int port : port number (0 - 127)
1958 * return: 0 : this port is invalid
1962 * Function 10: Setting baud rate of this port.
1964 * long MoxaPortSetBaud(int port, long baud);
1965 * int port : port number (0 - 127)
1966 * long baud : baud rate (50 - 115200)
1968 * return: 0 : this port is invalid or baud < 50
1969 * 50 - 115200 : the real baud rate set to the port, if
1970 * the argument baud is large than maximun
1971 * available baud rate, the real setting
1972 * baud rate will be the maximun baud rate.
1975 * Function 11: Setting the data-bits/stop-bits/parity of this port
1977 * int MoxaPortSetMode(int port, int databits, int stopbits, int parity);
1978 * int port : port number (0 - 127)
1979 * int databits : data bits (8/7/6/5)
1980 * int stopbits : stop bits (2/1/0, 0 show 1.5 stop bits)
1981 int parity : parity (0:None,1:Odd,2:Even,3:Mark,4:Space)
1983 * return: -1 : invalid parameter
1987 * Function 12: Configure the port.
1989 * int MoxaPortSetTermio(int port, struct termios *termio);
1990 * int port : port number (0 - 127)
1991 * struct termios * termio : termio structure pointer
1993 * return: -1 : this port is invalid or termio == NULL
1997 * Function 13: Get the DTR/RTS state of this port.
1999 * int MoxaPortGetLineOut(int port, int *dtrState, int *rtsState);
2000 * int port : port number (0 - 127)
2001 * int * dtrState : pointer to INT to receive the current DTR
2002 * state. (if NULL, this function will not
2003 * write to this address)
2004 * int * rtsState : pointer to INT to receive the current RTS
2005 * state. (if NULL, this function will not
2006 * write to this address)
2008 * return: -1 : this port is invalid
2012 * Function 14: Setting the DTR/RTS output state of this port.
2014 * void MoxaPortLineCtrl(int port, int dtrState, int rtsState);
2015 * int port : port number (0 - 127)
2016 * int dtrState : DTR output state (0: off, 1: on)
2017 * int rtsState : RTS output state (0: off, 1: on)
2020 * Function 15: Setting the flow control of this port.
2022 * void MoxaPortFlowCtrl(int port, int rtsFlow, int ctsFlow, int rxFlow,
2023 * int txFlow,int xany);
2024 * int port : port number (0 - 127)
2025 * int rtsFlow : H/W RTS flow control (0: no, 1: yes)
2026 * int ctsFlow : H/W CTS flow control (0: no, 1: yes)
2027 * int rxFlow : S/W Rx XON/XOFF flow control (0: no, 1: yes)
2028 * int txFlow : S/W Tx XON/XOFF flow control (0: no, 1: yes)
2029 * int xany : S/W XANY flow control (0: no, 1: yes)
2032 * Function 16: Get ths line status of this port
2034 * int MoxaPortLineStatus(int port);
2035 * int port : port number (0 - 127)
2037 * return: Bit 0 - CTS state (0: off, 1: on)
2038 * Bit 1 - DSR state (0: off, 1: on)
2039 * Bit 2 - DCD state (0: off, 1: on)
2042 * Function 17: Check the DCD state has changed since the last read
2045 * int MoxaPortDCDChange(int port);
2046 * int port : port number (0 - 127)
2048 * return: 0 : no changed
2049 * 1 : DCD has changed
2052 * Function 18: Check ths current DCD state is ON or not.
2054 * int MoxaPortDCDON(int port);
2055 * int port : port number (0 - 127)
2057 * return: 0 : DCD off
2061 * Function 19: Flush the Rx/Tx buffer data of this port.
2063 * void MoxaPortFlushData(int port, int mode);
2064 * int port : port number (0 - 127)
2066 * 0 : flush the Rx buffer
2067 * 1 : flush the Tx buffer
2068 * 2 : flush the Rx and Tx buffer
2071 * Function 20: Write data.
2073 * int MoxaPortWriteData(int port, unsigned char * buffer, int length);
2074 * int port : port number (0 - 127)
2075 * unsigned char * buffer : pointer to write data buffer.
2076 * int length : write data length
2078 * return: 0 - length : real write data length
2081 * Function 21: Read data.
2083 * int MoxaPortReadData(int port, unsigned char * buffer, int length);
2084 * int port : port number (0 - 127)
2085 * unsigned char * buffer : pointer to read data buffer.
2086 * int length : read data buffer length
2088 * return: 0 - length : real read data length
2091 * Function 22: Get the Tx buffer size of this port
2093 * int MoxaPortTxBufSize(int port);
2094 * int port : port number (0 - 127)
2096 * return: .. : Tx buffer size
2099 * Function 23: Get the Rx buffer size of this port
2101 * int MoxaPortRxBufSize(int port);
2102 * int port : port number (0 - 127)
2104 * return: .. : Rx buffer size
2107 * Function 24: Get the Tx buffer current queued data bytes
2109 * int MoxaPortTxQueue(int port);
2110 * int port : port number (0 - 127)
2112 * return: .. : Tx buffer current queued data bytes
2115 * Function 25: Get the Tx buffer current free space
2117 * int MoxaPortTxFree(int port);
2118 * int port : port number (0 - 127)
2120 * return: .. : Tx buffer current free space
2123 * Function 26: Get the Rx buffer current queued data bytes
2125 * int MoxaPortRxQueue(int port);
2126 * int port : port number (0 - 127)
2128 * return: .. : Rx buffer current queued data bytes
2131 * Function 27: Get the Rx buffer current free space
2133 * int MoxaPortRxFree(int port);
2134 * int port : port number (0 - 127)
2136 * return: .. : Rx buffer current free space
2139 * Function 28: Disable port data transmission.
2141 * void MoxaPortTxDisable(int port);
2142 * int port : port number (0 - 127)
2145 * Function 29: Enable port data transmission.
2147 * void MoxaPortTxEnable(int port);
2148 * int port : port number (0 - 127)
2151 * Function 30: Get the received BREAK signal count.
2153 * int MoxaPortGetBrkCnt(int port);
2154 * int port : port number (0 - 127)
2156 * return: 0 - .. : BREAK signal count
2159 * Function 31: Get the received BREAK signal count and reset it.
2161 * int MoxaPortResetBrkCnt(int port);
2162 * int port : port number (0 - 127)
2164 * return: 0 - .. : BREAK signal count
2167 * Function 32: Set the S/W flow control new XON/XOFF value, default
2168 * XON is 0x11 & XOFF is 0x13.
2170 * void MoxaPortSetXonXoff(int port, int xonValue, int xoffValue);
2171 * int port : port number (0 - 127)
2172 * int xonValue : new XON value (0 - 255)
2173 * int xoffValue : new XOFF value (0 - 255)
2176 * Function 33: Check this port's transmission is hold by remote site
2177 * because the flow control.
2179 * int MoxaPortIsTxHold(int port);
2180 * int port : port number (0 - 127)
2182 * return: 0 : normal
2183 * 1 : hold by remote site
2186 * Function 34: Send out a BREAK signal.
2188 * void MoxaPortSendBreak(int port, int ms100);
2189 * int port : port number (0 - 127)
2190 * int ms100 : break signal time interval.
2191 * unit: 100 mini-second. if ms100 == 0, it will
2192 * send out a about 250 ms BREAK signal.
2195 int MoxaPortIsValid(int port
)
2200 if (moxaChkPort
[port
] == 0)
2205 void MoxaPortEnable(int port
)
2207 unsigned long ofsAddr
;
2208 int MoxaPortLineStatus(int);
2209 short lowwater
= 512;
2211 ofsAddr
= moxaTableAddr
[port
];
2212 writew(lowwater
, ofsAddr
+ Low_water
);
2213 moxaBreakCnt
[port
] = 0;
2214 if ((moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_ISA
) ||
2215 (moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_PCI
)) {
2216 moxafunc(ofsAddr
, FC_SetBreakIrq
, 0);
2218 writew(readw(ofsAddr
+ HostStat
) | WakeupBreak
, ofsAddr
+ HostStat
);
2221 moxafunc(ofsAddr
, FC_SetLineIrq
, Magic_code
);
2222 moxafunc(ofsAddr
, FC_FlushQueue
, 2);
2224 moxafunc(ofsAddr
, FC_EnableCH
, Magic_code
);
2225 MoxaPortLineStatus(port
);
2228 void MoxaPortDisable(int port
)
2230 unsigned long ofsAddr
;
2232 ofsAddr
= moxaTableAddr
[port
];
2233 moxafunc(ofsAddr
, FC_SetFlowCtl
, 0); /* disable flow control */
2234 moxafunc(ofsAddr
, FC_ClrLineIrq
, Magic_code
);
2235 writew(0, ofsAddr
+ HostStat
);
2236 moxafunc(ofsAddr
, FC_DisableCH
, Magic_code
);
2239 long MoxaPortGetMaxBaud(int port
)
2241 if ((moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_ISA
) ||
2242 (moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_PCI
))
2249 long MoxaPortSetBaud(int port
, long baud
)
2251 unsigned long ofsAddr
;
2255 if ((baud
< 50L) || ((max
= MoxaPortGetMaxBaud(port
)) == 0))
2257 ofsAddr
= moxaTableAddr
[port
];
2261 clock
= 614400L; /* for 9.8304 Mhz : max. 38400 bps */
2262 else if (max
== 57600L)
2263 clock
= 691200L; /* for 11.0592 Mhz : max. 57600 bps */
2265 clock
= 921600L; /* for 14.7456 Mhz : max. 115200 bps */
2267 moxafunc(ofsAddr
, FC_SetBaud
, val
);
2269 moxaCurBaud
[port
] = baud
;
2273 int MoxaPortSetTermio(int port
, struct termios
*termio
)
2275 unsigned long ofsAddr
;
2280 if (moxaChkPort
[port
] == 0 || termio
== 0)
2282 ofsAddr
= moxaTableAddr
[port
];
2283 cflag
= termio
->c_cflag
; /* termio->c_cflag */
2285 mode
= termio
->c_cflag
& CSIZE
;
2288 else if (mode
== CS6
)
2290 else if (mode
== CS7
)
2292 else if (mode
== CS8
)
2295 if (termio
->c_cflag
& CSTOPB
) {
2303 if (termio
->c_cflag
& PARENB
) {
2304 if (termio
->c_cflag
& PARODD
)
2311 moxafunc(ofsAddr
, FC_SetDataMode
, (ushort
) mode
);
2313 cflag
&= (CBAUD
| CBAUDEX
);
2315 #define B921600 (B460800+1)
2381 if ((moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_ISA
) ||
2382 (moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_PCI
)) {
2383 if (baud
== 921600L)
2386 MoxaPortSetBaud(port
, baud
);
2388 if (termio
->c_iflag
& (IXON
| IXOFF
| IXANY
)) {
2389 writeb(termio
->c_cc
[VSTART
], ofsAddr
+ FuncArg
);
2390 writeb(termio
->c_cc
[VSTOP
], ofsAddr
+ FuncArg1
);
2391 writeb(FC_SetXonXoff
, ofsAddr
+ FuncCode
);
2392 wait_finish(ofsAddr
);
2398 int MoxaPortGetLineOut(int port
, int *dtrState
, int *rtsState
)
2401 if (!MoxaPortIsValid(port
))
2404 if (moxaLineCtrl
[port
] & DTR_ON
)
2410 if (moxaLineCtrl
[port
] & RTS_ON
)
2418 void MoxaPortLineCtrl(int port
, int dtr
, int rts
)
2420 unsigned long ofsAddr
;
2423 ofsAddr
= moxaTableAddr
[port
];
2429 moxaLineCtrl
[port
] = mode
;
2430 moxafunc(ofsAddr
, FC_LineControl
, mode
);
2433 void MoxaPortFlowCtrl(int port
, int rts
, int cts
, int txflow
, int rxflow
, int txany
)
2435 unsigned long ofsAddr
;
2438 ofsAddr
= moxaTableAddr
[port
];
2441 mode
|= RTS_FlowCtl
;
2443 mode
|= CTS_FlowCtl
;
2450 moxafunc(ofsAddr
, FC_SetFlowCtl
, mode
);
2453 int MoxaPortLineStatus(int port
)
2455 unsigned long ofsAddr
;
2458 ofsAddr
= moxaTableAddr
[port
];
2459 if ((moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_ISA
) ||
2460 (moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_PCI
)) {
2461 moxafunc(ofsAddr
, FC_LineStatus
, 0);
2462 val
= readw(ofsAddr
+ FuncArg
);
2464 val
= readw(ofsAddr
+ FlagStat
) >> 4;
2469 if ((moxaDCDState
[port
] & DCD_oldstate
) == 0)
2470 moxaDCDState
[port
] = (DCD_oldstate
| DCD_changed
);
2472 if (moxaDCDState
[port
] & DCD_oldstate
)
2473 moxaDCDState
[port
] = DCD_changed
;
2479 int MoxaPortDCDChange(int port
)
2483 if (moxaChkPort
[port
] == 0)
2485 n
= moxaDCDState
[port
];
2486 moxaDCDState
[port
] &= ~DCD_changed
;
2491 int MoxaPortDCDON(int port
)
2495 if (moxaChkPort
[port
] == 0)
2497 if (moxaDCDState
[port
] & DCD_oldstate
)
2506 int MoxaDumpMem(int port, unsigned char * buffer, int len)
2509 unsigned long baseAddr,ofsAddr,ofs;
2511 baseAddr = moxaBaseAddr[port / MAX_PORTS_PER_BOARD];
2512 ofs = baseAddr + DynPage_addr + pageofs;
2515 for (i = 0; i < len; i++)
2516 buffer[i] = readb(ofs+i);
2521 int MoxaPortWriteData(int port
, unsigned char * buffer
, int len
)
2526 ushort head
, tx_mask
, spage
, epage
;
2527 ushort pageno
, pageofs
, bufhead
;
2528 unsigned long baseAddr
, ofsAddr
, ofs
;
2530 ofsAddr
= moxaTableAddr
[port
];
2531 baseAddr
= moxaBaseAddr
[port
/ MAX_PORTS_PER_BOARD
];
2532 tx_mask
= readw(ofsAddr
+ TX_mask
);
2533 spage
= readw(ofsAddr
+ Page_txb
);
2534 epage
= readw(ofsAddr
+ EndPage_txb
);
2535 tail
= readw(ofsAddr
+ TXwptr
);
2536 head
= readw(ofsAddr
+ TXrptr
);
2537 c
= (head
> tail
) ? (head
- tail
- 1)
2538 : (head
- tail
+ tx_mask
);
2541 moxaLog
.txcnt
[port
] += c
;
2543 if (spage
== epage
) {
2544 bufhead
= readw(ofsAddr
+ Ofs_txb
);
2545 writew(spage
, baseAddr
+ Control_reg
);
2548 len
= head
- tail
- 1;
2550 len
= tx_mask
+ 1 - tail
;
2551 len
= (c
> len
) ? len
: c
;
2552 ofs
= baseAddr
+ DynPage_addr
+ bufhead
+ tail
;
2553 for (i
= 0; i
< len
; i
++)
2554 writeb(*buffer
++, ofs
+ i
);
2555 tail
= (tail
+ len
) & tx_mask
;
2558 writew(tail
, ofsAddr
+ TXwptr
);
2561 pageno
= spage
+ (tail
>> 13);
2562 pageofs
= tail
& Page_mask
;
2564 cnt
= Page_size
- pageofs
;
2568 writeb(pageno
, baseAddr
+ Control_reg
);
2569 ofs
= baseAddr
+ DynPage_addr
+ pageofs
;
2570 for (i
= 0; i
< cnt
; i
++)
2571 writeb(*buffer
++, ofs
+ i
);
2573 writew((tail
+ len
) & tx_mask
, ofsAddr
+ TXwptr
);
2576 if (++pageno
== epage
)
2581 writeb(1, ofsAddr
+ CD180TXirq
); /* start to send */
2585 int MoxaPortReadData(int port
, unsigned char * buffer
, int space
)
2587 register ushort head
, pageofs
;
2588 int i
, count
, cnt
, len
, total
, remain
;
2589 ushort tail
, rx_mask
, spage
, epage
;
2590 ushort pageno
, bufhead
;
2591 unsigned long baseAddr
, ofsAddr
, ofs
;
2593 ofsAddr
= moxaTableAddr
[port
];
2594 baseAddr
= moxaBaseAddr
[port
/ MAX_PORTS_PER_BOARD
];
2595 head
= readw(ofsAddr
+ RXrptr
);
2596 tail
= readw(ofsAddr
+ RXwptr
);
2597 rx_mask
= readw(ofsAddr
+ RX_mask
);
2598 spage
= readw(ofsAddr
+ Page_rxb
);
2599 epage
= readw(ofsAddr
+ EndPage_rxb
);
2600 count
= (tail
>= head
) ? (tail
- head
)
2601 : (tail
- head
+ rx_mask
+ 1);
2605 total
= (space
> count
) ? count
: space
;
2606 remain
= count
- total
;
2607 moxaLog
.rxcnt
[port
] += total
;
2609 if (spage
== epage
) {
2610 bufhead
= readw(ofsAddr
+ Ofs_rxb
);
2611 writew(spage
, baseAddr
+ Control_reg
);
2616 len
= rx_mask
+ 1 - head
;
2617 len
= (count
> len
) ? len
: count
;
2618 ofs
= baseAddr
+ DynPage_addr
+ bufhead
+ head
;
2619 for (i
= 0; i
< len
; i
++)
2620 *buffer
++ = readb(ofs
+ i
);
2621 head
= (head
+ len
) & rx_mask
;
2624 writew(head
, ofsAddr
+ RXrptr
);
2627 pageno
= spage
+ (head
>> 13);
2628 pageofs
= head
& Page_mask
;
2630 cnt
= Page_size
- pageofs
;
2634 writew(pageno
, baseAddr
+ Control_reg
);
2635 ofs
= baseAddr
+ DynPage_addr
+ pageofs
;
2636 for (i
= 0; i
< cnt
; i
++)
2637 *buffer
++ = readb(ofs
+ i
);
2639 writew((head
+ len
) & rx_mask
, ofsAddr
+ RXrptr
);
2642 if (++pageno
== epage
)
2647 if ((readb(ofsAddr
+ FlagStat
) & Xoff_state
) && (remain
< LowWater
)) {
2648 moxaLowWaterChk
= 1;
2649 moxaLowChkFlag
[port
] = 1;
2655 int MoxaPortTxQueue(int port
)
2657 unsigned long ofsAddr
;
2658 ushort rptr
, wptr
, mask
;
2661 ofsAddr
= moxaTableAddr
[port
];
2662 rptr
= readw(ofsAddr
+ TXrptr
);
2663 wptr
= readw(ofsAddr
+ TXwptr
);
2664 mask
= readw(ofsAddr
+ TX_mask
);
2665 len
= (wptr
- rptr
) & mask
;
2669 int MoxaPortTxFree(int port
)
2671 unsigned long ofsAddr
;
2672 ushort rptr
, wptr
, mask
;
2675 ofsAddr
= moxaTableAddr
[port
];
2676 rptr
= readw(ofsAddr
+ TXrptr
);
2677 wptr
= readw(ofsAddr
+ TXwptr
);
2678 mask
= readw(ofsAddr
+ TX_mask
);
2679 len
= mask
- ((wptr
- rptr
) & mask
);
2683 int MoxaPortRxQueue(int port
)
2685 unsigned long ofsAddr
;
2686 ushort rptr
, wptr
, mask
;
2689 ofsAddr
= moxaTableAddr
[port
];
2690 rptr
= readw(ofsAddr
+ RXrptr
);
2691 wptr
= readw(ofsAddr
+ RXwptr
);
2692 mask
= readw(ofsAddr
+ RX_mask
);
2693 len
= (wptr
- rptr
) & mask
;
2698 void MoxaPortTxDisable(int port
)
2700 unsigned long ofsAddr
;
2702 ofsAddr
= moxaTableAddr
[port
];
2703 moxafunc(ofsAddr
, FC_SetXoffState
, Magic_code
);
2706 void MoxaPortTxEnable(int port
)
2708 unsigned long ofsAddr
;
2710 ofsAddr
= moxaTableAddr
[port
];
2711 moxafunc(ofsAddr
, FC_SetXonState
, Magic_code
);
2715 int MoxaPortResetBrkCnt(int port
)
2718 cnt
= moxaBreakCnt
[port
];
2719 moxaBreakCnt
[port
] = 0;
2724 void MoxaPortSendBreak(int port
, int ms100
)
2726 unsigned long ofsAddr
;
2728 ofsAddr
= moxaTableAddr
[port
];
2730 moxafunc(ofsAddr
, FC_SendBreak
, Magic_code
);
2731 moxadelay(ms100
* (HZ
/ 10));
2733 moxafunc(ofsAddr
, FC_SendBreak
, Magic_code
);
2734 moxadelay(HZ
/ 4); /* 250 ms */
2736 moxafunc(ofsAddr
, FC_StopBreak
, Magic_code
);
2739 static int moxa_get_serial_info(struct moxa_str
*info
,
2740 struct serial_struct
*retinfo
)
2742 struct serial_struct tmp
;
2746 memset(&tmp
, 0, sizeof(tmp
));
2747 tmp
.type
= info
->type
;
2748 tmp
.line
= info
->port
;
2751 tmp
.flags
= info
->asyncflags
;
2752 tmp
.baud_base
= 921600;
2753 tmp
.close_delay
= info
->close_delay
;
2754 tmp
.closing_wait
= info
->closing_wait
;
2755 tmp
.custom_divisor
= 0;
2757 if(copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
2763 static int moxa_set_serial_info(struct moxa_str
*info
,
2764 struct serial_struct
*new_info
)
2766 struct serial_struct new_serial
;
2768 if(copy_from_user(&new_serial
, new_info
, sizeof(new_serial
)))
2771 if ((new_serial
.irq
!= 0) ||
2772 (new_serial
.port
!= 0) ||
2773 // (new_serial.type != info->type) ||
2774 (new_serial
.custom_divisor
!= 0) ||
2775 (new_serial
.baud_base
!= 921600))
2779 if (((new_serial
.flags
& ~ASYNC_USR_MASK
) !=
2780 (info
->asyncflags
& ~ASYNC_USR_MASK
)))
2783 info
->close_delay
= new_serial
.close_delay
* HZ
/ 100;
2784 info
->closing_wait
= new_serial
.closing_wait
* HZ
/ 100;
2787 new_serial
.flags
= (new_serial
.flags
& ~ASYNC_FLAGS
);
2788 new_serial
.flags
|= (info
->asyncflags
& ASYNC_FLAGS
);
2790 if (new_serial
.type
== PORT_16550A
) {
2791 MoxaSetFifo(info
->port
, 1);
2793 MoxaSetFifo(info
->port
, 0);
2796 info
->type
= new_serial
.type
;
2802 /*****************************************************************************
2803 * Static local functions: *
2804 *****************************************************************************/
2806 * moxadelay - delays a specified number ticks
2808 static void moxadelay(int tick
)
2810 unsigned long st
, et
;
2814 while (jiffies
< et
);
2817 static void moxafunc(unsigned long ofsAddr
, int cmd
, ushort arg
)
2820 writew(arg
, ofsAddr
+ FuncArg
);
2821 writew(cmd
, ofsAddr
+ FuncCode
);
2822 wait_finish(ofsAddr
);
2825 static void wait_finish(unsigned long ofsAddr
)
2830 while (readw(ofsAddr
+ FuncCode
) != 0) {
2832 if ((j
- i
) > moxaFuncTout
) {
2838 static void low_water_check(unsigned long ofsAddr
)
2841 ushort rptr
, wptr
, mask
;
2843 if (readb(ofsAddr
+ FlagStat
) & Xoff_state
) {
2844 rptr
= readw(ofsAddr
+ RXrptr
);
2845 wptr
= readw(ofsAddr
+ RXwptr
);
2846 mask
= readw(ofsAddr
+ RX_mask
);
2847 len
= (wptr
- rptr
) & mask
;
2848 if (len
<= Low_water
)
2849 moxafunc(ofsAddr
, FC_SendXon
, 0);
2853 static int moxaloadbios(int cardno
, unsigned char *tmp
, int len
)
2855 unsigned long baseAddr
;
2858 if(copy_from_user(moxaBuff
, tmp
, len
))
2860 baseAddr
= moxaBaseAddr
[cardno
];
2861 writeb(HW_reset
, baseAddr
+ Control_reg
); /* reset */
2862 moxadelay(1); /* delay 10 ms */
2863 for (i
= 0; i
< 4096; i
++)
2864 writeb(0, baseAddr
+ i
); /* clear fix page */
2865 for (i
= 0; i
< len
; i
++)
2866 writeb(moxaBuff
[i
], baseAddr
+ i
); /* download BIOS */
2867 writeb(0, baseAddr
+ Control_reg
); /* restart */
2871 static int moxafindcard(int cardno
)
2873 unsigned long baseAddr
;
2876 baseAddr
= moxaBaseAddr
[cardno
];
2877 switch (moxa_boards
[cardno
].boardType
) {
2878 case MOXA_BOARD_C218_ISA
:
2879 case MOXA_BOARD_C218_PCI
:
2880 if ((tmp
= readw(baseAddr
+ C218_key
)) != C218_KeyCode
) {
2884 case MOXA_BOARD_CP204J
:
2885 if ((tmp
= readw(baseAddr
+ C218_key
)) != CP204J_KeyCode
) {
2890 if ((tmp
= readw(baseAddr
+ C320_key
)) != C320_KeyCode
) {
2893 if ((tmp
= readw(baseAddr
+ C320_status
)) != STS_init
) {
2900 static int moxaload320b(int cardno
, unsigned char * tmp
, int len
)
2902 unsigned long baseAddr
;
2905 if(copy_from_user(moxaBuff
, tmp
, len
))
2907 baseAddr
= moxaBaseAddr
[cardno
];
2908 writew(len
- 7168 - 2, baseAddr
+ C320bapi_len
);
2909 writeb(1, baseAddr
+ Control_reg
); /* Select Page 1 */
2910 for (i
= 0; i
< 7168; i
++)
2911 writeb(moxaBuff
[i
], baseAddr
+ DynPage_addr
+ i
);
2912 writeb(2, baseAddr
+ Control_reg
); /* Select Page 2 */
2913 for (i
= 0; i
< (len
- 7168); i
++)
2914 writeb(moxaBuff
[i
+ 7168], baseAddr
+ DynPage_addr
+ i
);
2918 static int moxaloadcode(int cardno
, unsigned char * tmp
, int len
)
2920 unsigned long baseAddr
, ofsAddr
;
2921 int retval
, port
, i
;
2923 if(copy_from_user(moxaBuff
, tmp
, len
))
2925 baseAddr
= moxaBaseAddr
[cardno
];
2926 switch (moxa_boards
[cardno
].boardType
) {
2927 case MOXA_BOARD_C218_ISA
:
2928 case MOXA_BOARD_C218_PCI
:
2929 case MOXA_BOARD_CP204J
:
2930 retval
= moxaloadc218(cardno
, baseAddr
, len
);
2933 port
= cardno
* MAX_PORTS_PER_BOARD
;
2934 for (i
= 0; i
< moxa_boards
[cardno
].numPorts
; i
++, port
++) {
2935 moxaChkPort
[port
] = 1;
2936 moxaCurBaud
[port
] = 9600L;
2937 moxaDCDState
[port
] = 0;
2938 moxaTableAddr
[port
] = baseAddr
+ Extern_table
+ Extern_size
* i
;
2939 ofsAddr
= moxaTableAddr
[port
];
2940 writew(C218rx_mask
, ofsAddr
+ RX_mask
);
2941 writew(C218tx_mask
, ofsAddr
+ TX_mask
);
2942 writew(C218rx_spage
+ i
* C218buf_pageno
, ofsAddr
+ Page_rxb
);
2943 writew(readw(ofsAddr
+ Page_rxb
) + C218rx_pageno
, ofsAddr
+ EndPage_rxb
);
2945 writew(C218tx_spage
+ i
* C218buf_pageno
, ofsAddr
+ Page_txb
);
2946 writew(readw(ofsAddr
+ Page_txb
) + C218tx_pageno
, ofsAddr
+ EndPage_txb
);
2951 retval
= moxaloadc320(cardno
, baseAddr
, len
,
2952 &moxa_boards
[cardno
].numPorts
);
2955 port
= cardno
* MAX_PORTS_PER_BOARD
;
2956 for (i
= 0; i
< moxa_boards
[cardno
].numPorts
; i
++, port
++) {
2957 moxaChkPort
[port
] = 1;
2958 moxaCurBaud
[port
] = 9600L;
2959 moxaDCDState
[port
] = 0;
2960 moxaTableAddr
[port
] = baseAddr
+ Extern_table
+ Extern_size
* i
;
2961 ofsAddr
= moxaTableAddr
[port
];
2962 if (moxa_boards
[cardno
].numPorts
== 8) {
2963 writew(C320p8rx_mask
, ofsAddr
+ RX_mask
);
2964 writew(C320p8tx_mask
, ofsAddr
+ TX_mask
);
2965 writew(C320p8rx_spage
+ i
* C320p8buf_pgno
, ofsAddr
+ Page_rxb
);
2966 writew(readw(ofsAddr
+ Page_rxb
) + C320p8rx_pgno
, ofsAddr
+ EndPage_rxb
);
2967 writew(C320p8tx_spage
+ i
* C320p8buf_pgno
, ofsAddr
+ Page_txb
);
2968 writew(readw(ofsAddr
+ Page_txb
) + C320p8tx_pgno
, ofsAddr
+ EndPage_txb
);
2970 } else if (moxa_boards
[cardno
].numPorts
== 16) {
2971 writew(C320p16rx_mask
, ofsAddr
+ RX_mask
);
2972 writew(C320p16tx_mask
, ofsAddr
+ TX_mask
);
2973 writew(C320p16rx_spage
+ i
* C320p16buf_pgno
, ofsAddr
+ Page_rxb
);
2974 writew(readw(ofsAddr
+ Page_rxb
) + C320p16rx_pgno
, ofsAddr
+ EndPage_rxb
);
2975 writew(C320p16tx_spage
+ i
* C320p16buf_pgno
, ofsAddr
+ Page_txb
);
2976 writew(readw(ofsAddr
+ Page_txb
) + C320p16tx_pgno
, ofsAddr
+ EndPage_txb
);
2978 } else if (moxa_boards
[cardno
].numPorts
== 24) {
2979 writew(C320p24rx_mask
, ofsAddr
+ RX_mask
);
2980 writew(C320p24tx_mask
, ofsAddr
+ TX_mask
);
2981 writew(C320p24rx_spage
+ i
* C320p24buf_pgno
, ofsAddr
+ Page_rxb
);
2982 writew(readw(ofsAddr
+ Page_rxb
) + C320p24rx_pgno
, ofsAddr
+ EndPage_rxb
);
2983 writew(C320p24tx_spage
+ i
* C320p24buf_pgno
, ofsAddr
+ Page_txb
);
2984 writew(readw(ofsAddr
+ Page_txb
), ofsAddr
+ EndPage_txb
);
2985 } else if (moxa_boards
[cardno
].numPorts
== 32) {
2986 writew(C320p32rx_mask
, ofsAddr
+ RX_mask
);
2987 writew(C320p32tx_mask
, ofsAddr
+ TX_mask
);
2988 writew(C320p32tx_ofs
, ofsAddr
+ Ofs_txb
);
2989 writew(C320p32rx_spage
+ i
* C320p32buf_pgno
, ofsAddr
+ Page_rxb
);
2990 writew(readb(ofsAddr
+ Page_rxb
), ofsAddr
+ EndPage_rxb
);
2991 writew(C320p32tx_spage
+ i
* C320p32buf_pgno
, ofsAddr
+ Page_txb
);
2992 writew(readw(ofsAddr
+ Page_txb
), ofsAddr
+ EndPage_txb
);
3000 static int moxaloadc218(int cardno
, unsigned long baseAddr
, int len
)
3003 int i
, j
, len1
, len2
;
3004 ushort usum
, *ptr
, keycode
;
3006 if (moxa_boards
[cardno
].boardType
== MOXA_BOARD_CP204J
)
3007 keycode
= CP204J_KeyCode
;
3009 keycode
= C218_KeyCode
;
3012 ptr
= (ushort
*) moxaBuff
;
3013 for (i
= 0; i
< len1
; i
++)
3020 len2
= (len1
> 2048) ? 2048 : len1
;
3022 for (i
= 0; i
< len2
<< 1; i
++)
3023 writeb(moxaBuff
[i
+ j
], baseAddr
+ C218_LoadBuf
+ i
);
3026 writew(len2
, baseAddr
+ C218DLoad_len
);
3027 writew(0, baseAddr
+ C218_key
);
3028 for (i
= 0; i
< 100; i
++) {
3029 if (readw(baseAddr
+ C218_key
) == keycode
)
3031 moxadelay(1); /* delay 10 ms */
3033 if (readw(baseAddr
+ C218_key
) != keycode
) {
3037 writew(0, baseAddr
+ C218DLoad_len
);
3038 writew(usum
, baseAddr
+ C218check_sum
);
3039 writew(0, baseAddr
+ C218_key
);
3040 for (i
= 0; i
< 100; i
++) {
3041 if (readw(baseAddr
+ C218_key
) == keycode
)
3043 moxadelay(1); /* delay 10 ms */
3046 } while ((readb(baseAddr
+ C218chksum_ok
) != 1) && (retry
< 3));
3047 if (readb(baseAddr
+ C218chksum_ok
) != 1) {
3050 writew(0, baseAddr
+ C218_key
);
3051 for (i
= 0; i
< 100; i
++) {
3052 if (readw(baseAddr
+ Magic_no
) == Magic_code
)
3054 moxadelay(1); /* delay 10 ms */
3056 if (readw(baseAddr
+ Magic_no
) != Magic_code
) {
3059 writew(1, baseAddr
+ Disable_IRQ
);
3060 writew(0, baseAddr
+ Magic_no
);
3061 for (i
= 0; i
< 100; i
++) {
3062 if (readw(baseAddr
+ Magic_no
) == Magic_code
)
3064 moxadelay(1); /* delay 10 ms */
3066 if (readw(baseAddr
+ Magic_no
) != Magic_code
) {
3070 moxaIntNdx
[cardno
] = baseAddr
+ IRQindex
;
3071 moxaIntPend
[cardno
] = baseAddr
+ IRQpending
;
3072 moxaIntTable
[cardno
] = baseAddr
+ IRQtable
;
3076 static int moxaloadc320(int cardno
, unsigned long baseAddr
, int len
, int *numPorts
)
3079 int i
, j
, wlen
, len2
, retry
;
3084 uptr
= (ushort
*) moxaBuff
;
3085 for (i
= 0; i
< wlen
; i
++)
3097 for (i
= 0; i
< len2
; i
++)
3098 writeb(moxaBuff
[j
+ i
], baseAddr
+ C320_LoadBuf
+ i
);
3101 writew(len2
, baseAddr
+ C320DLoad_len
);
3102 writew(0, baseAddr
+ C320_key
);
3103 for (i
= 0; i
< 10; i
++) {
3104 if (readw(baseAddr
+ C320_key
) == C320_KeyCode
)
3108 if (readw(baseAddr
+ C320_key
) != C320_KeyCode
)
3111 writew(0, baseAddr
+ C320DLoad_len
);
3112 writew(usum
, baseAddr
+ C320check_sum
);
3113 writew(0, baseAddr
+ C320_key
);
3114 for (i
= 0; i
< 10; i
++) {
3115 if (readw(baseAddr
+ C320_key
) == C320_KeyCode
)
3120 } while ((readb(baseAddr
+ C320chksum_ok
) != 1) && (retry
< 3));
3121 if (readb(baseAddr
+ C320chksum_ok
) != 1)
3123 writew(0, baseAddr
+ C320_key
);
3124 for (i
= 0; i
< 600; i
++) {
3125 if (readw(baseAddr
+ Magic_no
) == Magic_code
)
3129 if (readw(baseAddr
+ Magic_no
) != Magic_code
)
3132 if (moxa_boards
[cardno
].busType
== MOXA_BUS_TYPE_PCI
) { /* ASIC board */
3133 writew(0x3800, baseAddr
+ TMS320_PORT1
);
3134 writew(0x3900, baseAddr
+ TMS320_PORT2
);
3135 writew(28499, baseAddr
+ TMS320_CLOCK
);
3137 writew(0x3200, baseAddr
+ TMS320_PORT1
);
3138 writew(0x3400, baseAddr
+ TMS320_PORT2
);
3139 writew(19999, baseAddr
+ TMS320_CLOCK
);
3141 writew(1, baseAddr
+ Disable_IRQ
);
3142 writew(0, baseAddr
+ Magic_no
);
3143 for (i
= 0; i
< 500; i
++) {
3144 if (readw(baseAddr
+ Magic_no
) == Magic_code
)
3148 if (readw(baseAddr
+ Magic_no
) != Magic_code
)
3151 j
= readw(baseAddr
+ Module_cnt
);
3155 writew(j
, baseAddr
+ Module_no
);
3156 writew(0, baseAddr
+ Magic_no
);
3157 for (i
= 0; i
< 600; i
++) {
3158 if (readw(baseAddr
+ Magic_no
) == Magic_code
)
3162 if (readw(baseAddr
+ Magic_no
) != Magic_code
)
3165 moxaIntNdx
[cardno
] = baseAddr
+ IRQindex
;
3166 moxaIntPend
[cardno
] = baseAddr
+ IRQpending
;
3167 moxaIntTable
[cardno
] = baseAddr
+ IRQtable
;
3171 long MoxaPortGetCurBaud(int port
)
3174 if (moxaChkPort
[port
] == 0)
3176 return (moxaCurBaud
[port
]);
3179 static void MoxaSetFifo(int port
, int enable
)
3181 unsigned long ofsAddr
= moxaTableAddr
[port
];
3184 moxafunc(ofsAddr
, FC_SetRxFIFOTrig
, 0);
3185 moxafunc(ofsAddr
, FC_SetTxFIFOCnt
, 1);
3187 moxafunc(ofsAddr
, FC_SetRxFIFOTrig
, 3);
3188 moxafunc(ofsAddr
, FC_SetTxFIFOCnt
, 16);
3193 int MoxaPortSetMode(int port
, int databits
, int stopbits
, int parity
)
3195 unsigned long ofsAddr
;
3218 break; /* stop bits 1.5 */
3247 ofsAddr
= moxaTableAddr
[port
];
3248 moxafunc(ofsAddr
, FC_SetMode
, val
);
3252 int MoxaPortTxBufSize(int port
)
3254 unsigned long ofsAddr
;
3257 ofsAddr
= moxaTableAddr
[port
];
3258 size
= readw(ofsAddr
+ TX_mask
);
3262 int MoxaPortRxBufSize(int port
)
3264 unsigned long ofsAddr
;
3267 ofsAddr
= moxaTableAddr
[port
];
3268 size
= readw(ofsAddr
+ RX_mask
);
3272 int MoxaPortRxFree(int port
)
3274 unsigned long ofsAddr
;
3275 ushort rptr
, wptr
, mask
;
3278 ofsAddr
= moxaTableAddr
[port
];
3279 rptr
= readw(ofsAddr
+ RXrptr
);
3280 wptr
= readw(ofsAddr
+ RXwptr
);
3281 mask
= readw(ofsAddr
+ RX_mask
);
3282 len
= mask
- ((wptr
- rptr
) & mask
);
3285 int MoxaPortGetBrkCnt(int port
)
3287 return (moxaBreakCnt
[port
]);
3290 void MoxaPortSetXonXoff(int port
, int xonValue
, int xoffValue
)
3292 unsigned long ofsAddr
;
3294 ofsAddr
= moxaTableAddr
[port
];
3295 writew(xonValue
, ofsAddr
+ FuncArg
);
3296 writew(xoffValue
, ofsAddr
+ FuncArg1
);
3297 writew(FC_SetXonXoff
, ofsAddr
+ FuncCode
);
3298 wait_finish(ofsAddr
);
3301 int MoxaPortIsTxHold(int port
)
3303 unsigned long ofsAddr
;
3306 ofsAddr
= moxaTableAddr
[port
];
3307 if ((moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_ISA
) ||
3308 (moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_PCI
)) {
3309 moxafunc(ofsAddr
, FC_GetCCSR
, 0);
3310 val
= readw(ofsAddr
+ FuncArg
);
3314 if (readw(ofsAddr
+ FlagStat
) & Tx_flowOff
)