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/config.h>
46 #include <linux/major.h>
47 #include <linux/string.h>
48 #include <linux/fcntl.h>
49 #include <linux/ptrace.h>
50 #include <linux/serial.h>
51 #include <linux/tty_driver.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
55 #include <asm/system.h>
57 #include <asm/segment.h>
58 #include <asm/bitops.h>
59 #include <asm/uaccess.h>
61 #define MOXA_VERSION "5.1k"
64 #define MOXACUMAJOR 173
66 #define put_to_user(arg1, arg2) put_user(arg1, (unsigned long *)arg2)
67 #define get_from_user(arg1, arg2) get_user(arg1, (unsigned int *)arg2)
69 #define MAX_BOARDS 4 /* Don't change this value */
70 #define MAX_PORTS_PER_BOARD 32 /* Don't change this value */
71 #define MAX_PORTS 128 /* Don't change this value */
74 * Define the Moxa PCI vendor and device IDs.
76 #define MOXA_BUS_TYPE_ISA 0
77 #define MOXA_BUS_TYPE_PCI 1
79 #ifndef PCI_VENDOR_ID_MOXA
80 #define PCI_VENDOR_ID_MOXA 0x1393
82 #ifndef PCI_DEVICE_ID_CP204J
83 #define PCI_DEVICE_ID_CP204J 0x2040
85 #ifndef PCI_DEVICE_ID_C218
86 #define PCI_DEVICE_ID_C218 0x2180
88 #ifndef PCI_DEVICE_ID_C320
89 #define PCI_DEVICE_ID_C320 0x3200
93 MOXA_BOARD_C218_PCI
= 1,
100 static char *moxa_brdname
[] =
102 "C218 Turbo PCI series",
103 "C218 Turbo ISA series",
104 "C320 Turbo PCI series",
105 "C320 Turbo ISA series",
110 unsigned short vendor_id
;
111 unsigned short device_id
;
112 unsigned short board_type
;
115 static moxa_pciinfo moxa_pcibrds
[] =
117 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_C218
, MOXA_BOARD_C218_PCI
},
118 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_C320
, MOXA_BOARD_C320_PCI
},
119 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_CP204J
, MOXA_BOARD_CP204J
},
122 typedef struct _moxa_isa_board_conf
{
125 unsigned long baseAddr
;
126 } moxa_isa_board_conf
;
128 static moxa_isa_board_conf moxa_isa_boards
[] =
130 /* {MOXA_BOARD_C218_ISA,8,0xDC000}, */
133 typedef struct _moxa_pci_devinfo
{
138 typedef struct _moxa_board_conf
{
141 unsigned long baseAddr
;
143 moxa_pci_devinfo pciInfo
;
146 static moxa_board_conf moxa_boards
[MAX_BOARDS
];
147 static unsigned long moxaBaseAddr
[MAX_BOARDS
];
153 unsigned short closing_wait
;
160 unsigned long statusflags
;
161 struct tty_struct
*tty
;
162 struct termios normal_termios
;
163 struct termios callout_termios
;
164 wait_queue_head_t open_wait
;
165 wait_queue_head_t close_wait
;
166 struct tq_struct tqueue
;
169 struct mxser_mstatus
{
177 static struct mxser_mstatus GMStatus
[MAX_PORTS
];
180 #define TXSTOPPED 0x1
182 #define EMPTYWAIT 0x4
186 #define MOXA_EVENT_HANGUP 1
188 #define SERIAL_DO_RESTART
191 #define SERIAL_TYPE_NORMAL 1
192 #define SERIAL_TYPE_CALLOUT 2
194 #define WAKEUP_CHARS 256
196 #define PORTNO(x) (MINOR((x)->device) - (x)->driver.minor_start)
198 static int verbose
= 0;
199 static int ttymajor
= MOXAMAJOR
;
200 static int calloutmajor
= MOXACUMAJOR
;
202 /* Variables for insmod */
203 static int baseaddr
[] = {0, 0, 0, 0};
204 static int type
[] = {0, 0, 0, 0};
205 static int numports
[] = {0, 0, 0, 0};
207 MODULE_AUTHOR("William Chen");
208 MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver");
209 MODULE_PARM(type
, "1-4i");
210 MODULE_PARM(baseaddr
, "1-4i");
211 MODULE_PARM(numports
, "1-4i");
212 MODULE_PARM(ttymajor
, "i");
213 MODULE_PARM(calloutmajor
, "i");
214 MODULE_PARM(verbose
, "i");
218 static struct tty_driver moxaDriver
;
219 static struct tty_driver moxaCallout
;
220 static struct tty_struct
*moxaTable
[MAX_PORTS
+ 1];
221 static struct termios
*moxaTermios
[MAX_PORTS
+ 1];
222 static struct termios
*moxaTermiosLocked
[MAX_PORTS
+ 1];
223 static struct moxa_str moxaChannels
[MAX_PORTS
];
224 static int moxaRefcount
;
225 static unsigned char *moxaXmitBuff
;
226 static int moxaTimer_on
;
227 static struct timer_list moxaTimer
;
228 static int moxaEmptyTimer_on
[MAX_PORTS
];
229 static struct timer_list moxaEmptyTimer
[MAX_PORTS
];
230 static struct semaphore moxaBuffSem
;
234 int init_module(void);
235 void cleanup_module(void);
240 static int moxa_get_PCI_conf(struct pci_dev
*, int, moxa_board_conf
*);
241 static void do_moxa_softint(void *);
242 static int moxa_open(struct tty_struct
*, struct file
*);
243 static void moxa_close(struct tty_struct
*, struct file
*);
244 static int moxa_write(struct tty_struct
*, int, const unsigned char *, int);
245 static int moxa_write_room(struct tty_struct
*);
246 static void moxa_flush_buffer(struct tty_struct
*);
247 static int moxa_chars_in_buffer(struct tty_struct
*);
248 static void moxa_flush_chars(struct tty_struct
*);
249 static void moxa_put_char(struct tty_struct
*, unsigned char);
250 static int moxa_ioctl(struct tty_struct
*, struct file
*, unsigned int, unsigned long);
251 static void moxa_throttle(struct tty_struct
*);
252 static void moxa_unthrottle(struct tty_struct
*);
253 static void moxa_set_termios(struct tty_struct
*, struct termios
*);
254 static void moxa_stop(struct tty_struct
*);
255 static void moxa_start(struct tty_struct
*);
256 static void moxa_hangup(struct tty_struct
*);
257 static void moxa_poll(unsigned long);
258 static void set_tty_param(struct tty_struct
*);
259 static int block_till_ready(struct tty_struct
*, struct file
*,
261 static void setup_empty_event(struct tty_struct
*);
262 static void check_xmit_empty(unsigned long);
263 static void shut_down(struct moxa_str
*);
264 static void receive_data(struct moxa_str
*);
266 * moxa board interface functions:
268 static void MoxaDriverInit(void);
269 static int MoxaDriverIoctl(unsigned int, unsigned long, int);
270 static int MoxaDriverPoll(void);
271 static int MoxaPortsOfCard(int);
272 static int MoxaPortIsValid(int);
273 static void MoxaPortEnable(int);
274 static void MoxaPortDisable(int);
275 static long MoxaPortGetMaxBaud(int);
276 static long MoxaPortSetBaud(int, long);
277 static int MoxaPortSetTermio(int, struct termios
*);
278 static int MoxaPortGetLineOut(int, int *, int *);
279 static void MoxaPortLineCtrl(int, int, int);
280 static void MoxaPortFlowCtrl(int, int, int, int, int, int);
281 static int MoxaPortLineStatus(int);
282 static int MoxaPortDCDChange(int);
283 static int MoxaPortDCDON(int);
284 static void MoxaPortFlushData(int, int);
285 static int MoxaPortWriteData(int, unsigned char *, int);
286 static int MoxaPortReadData(int, unsigned char *, int);
287 static int MoxaPortTxQueue(int);
288 static int MoxaPortRxQueue(int);
289 static int MoxaPortTxFree(int);
290 static void MoxaPortTxDisable(int);
291 static void MoxaPortTxEnable(int);
292 static int MoxaPortResetBrkCnt(int);
293 static void MoxaPortSendBreak(int, int);
294 static int moxa_get_serial_info(struct moxa_str
*, struct serial_struct
*);
295 static int moxa_set_serial_info(struct moxa_str
*, struct serial_struct
*);
296 static void MoxaSetFifo(int port
, int enable
);
299 int init_module(void)
304 printk("Loading module moxa ...\n");
311 void cleanup_module(void)
316 printk("Unloading module moxa ...\n");
319 del_timer(&moxaTimer
);
321 for (i
= 0; i
< MAX_PORTS
; i
++)
322 if (moxaEmptyTimer_on
[i
])
323 del_timer(&moxaEmptyTimer
[i
]);
325 if (tty_unregister_driver(&moxaCallout
))
326 printk("Couldn't unregister MOXA Intellio family callout driver\n");
327 if (tty_unregister_driver(&moxaDriver
))
328 printk("Couldn't unregister MOXA Intellio family serial driver\n");
341 printk(KERN_INFO
"MOXA Intellio family driver version %s\n", MOXA_VERSION
);
343 init_MUTEX(&moxaBuffSem
);
344 memset(&moxaDriver
, 0, sizeof(struct tty_driver
));
345 memset(&moxaCallout
, 0, sizeof(struct tty_driver
));
346 moxaDriver
.magic
= TTY_DRIVER_MAGIC
;
347 moxaDriver
.name
= "ttya";
348 moxaDriver
.major
= ttymajor
;
349 moxaDriver
.minor_start
= 0;
350 moxaDriver
.num
= MAX_PORTS
+ 1;
351 moxaDriver
.type
= TTY_DRIVER_TYPE_SERIAL
;
352 moxaDriver
.subtype
= SERIAL_TYPE_NORMAL
;
353 moxaDriver
.init_termios
= tty_std_termios
;
354 moxaDriver
.init_termios
.c_iflag
= 0;
355 moxaDriver
.init_termios
.c_oflag
= 0;
356 moxaDriver
.init_termios
.c_cflag
= B9600
| CS8
| CREAD
| CLOCAL
| HUPCL
;
357 moxaDriver
.init_termios
.c_lflag
= 0;
358 moxaDriver
.flags
= TTY_DRIVER_REAL_RAW
;
359 moxaDriver
.refcount
= &moxaRefcount
;
360 moxaDriver
.table
= moxaTable
;
361 moxaDriver
.termios
= moxaTermios
;
362 moxaDriver
.termios_locked
= moxaTermiosLocked
;
364 moxaDriver
.open
= moxa_open
;
365 moxaDriver
.close
= moxa_close
;
366 moxaDriver
.write
= moxa_write
;
367 moxaDriver
.write_room
= moxa_write_room
;
368 moxaDriver
.flush_buffer
= moxa_flush_buffer
;
369 moxaDriver
.chars_in_buffer
= moxa_chars_in_buffer
;
370 moxaDriver
.flush_chars
= moxa_flush_chars
;
371 moxaDriver
.put_char
= moxa_put_char
;
372 moxaDriver
.ioctl
= moxa_ioctl
;
373 moxaDriver
.throttle
= moxa_throttle
;
374 moxaDriver
.unthrottle
= moxa_unthrottle
;
375 moxaDriver
.set_termios
= moxa_set_termios
;
376 moxaDriver
.stop
= moxa_stop
;
377 moxaDriver
.start
= moxa_start
;
378 moxaDriver
.hangup
= moxa_hangup
;
380 moxaCallout
= moxaDriver
;
381 moxaCallout
.name
= "ttyA";
382 moxaCallout
.major
= calloutmajor
;
383 moxaCallout
.subtype
= SERIAL_TYPE_CALLOUT
;
387 for (i
= 0, ch
= moxaChannels
; i
< MAX_PORTS
; i
++, ch
++) {
388 ch
->type
= PORT_16550A
;
390 ch
->tqueue
.routine
= do_moxa_softint
;
391 ch
->tqueue
.data
= ch
;
393 ch
->close_delay
= 5 * HZ
/ 10;
394 ch
->closing_wait
= 30 * HZ
;
396 ch
->blocked_open
= 0;
397 ch
->callout_termios
= moxaCallout
.init_termios
;
398 ch
->normal_termios
= moxaDriver
.init_termios
;
399 init_waitqueue_head(&ch
->open_wait
);
400 init_waitqueue_head(&ch
->close_wait
);
403 for (i
= 0; i
< MAX_BOARDS
; i
++) {
404 moxa_boards
[i
].boardType
= 0;
405 moxa_boards
[i
].numPorts
= 0;
406 moxa_boards
[i
].baseAddr
= 0;
407 moxa_boards
[i
].busType
= 0;
408 moxa_boards
[i
].pciInfo
.busNum
= 0;
409 moxa_boards
[i
].pciInfo
.devNum
= 0;
412 printk("Tty devices major number = %d, callout devices major number = %d\n", ttymajor
, calloutmajor
);
416 if ((ret1
= tty_register_driver(&moxaDriver
))) {
417 printk(KERN_ERR
"Couldn't install MOXA Smartio family driver !\n");
418 } else if ((ret2
= tty_register_driver(&moxaCallout
))) {
419 tty_unregister_driver(&moxaDriver
);
420 printk(KERN_ERR
"Couldn't install MOXA Smartio family callout driver !\n");
425 for (i
= 0; i
< MAX_PORTS
; i
++) {
426 init_timer(&moxaEmptyTimer
[i
]);
427 moxaEmptyTimer
[i
].function
= check_xmit_empty
;
428 moxaEmptyTimer
[i
].data
= (unsigned long) & moxaChannels
[i
];
429 moxaEmptyTimer_on
[i
] = 0;
432 init_timer(&moxaTimer
);
433 moxaTimer
.function
= moxa_poll
;
434 moxaTimer
.expires
= jiffies
+ (HZ
/ 50);
436 add_timer(&moxaTimer
);
438 /* Find the boards defined in source code */
440 for (i
= 0; i
< MAX_BOARDS
; i
++) {
441 if ((moxa_isa_boards
[i
].boardType
== MOXA_BOARD_C218_ISA
) ||
442 (moxa_isa_boards
[i
].boardType
== MOXA_BOARD_C320_ISA
)) {
443 moxa_boards
[numBoards
].boardType
= moxa_isa_boards
[i
].boardType
;
444 if (moxa_isa_boards
[i
].boardType
== MOXA_BOARD_C218_ISA
)
445 moxa_boards
[numBoards
].numPorts
= 8;
447 moxa_boards
[numBoards
].numPorts
= moxa_isa_boards
[i
].numPorts
;
448 moxa_boards
[numBoards
].busType
= MOXA_BUS_TYPE_ISA
;
449 moxa_boards
[numBoards
].baseAddr
= moxa_isa_boards
[i
].baseAddr
;
451 printk("Board %2d: %s board(baseAddr=%lx)\n",
453 moxa_brdname
[moxa_boards
[numBoards
].boardType
- 1],
454 moxa_boards
[numBoards
].baseAddr
);
458 /* Find the boards defined form module args. */
460 for (i
= 0; i
< MAX_BOARDS
; i
++) {
461 if ((type
[i
] == MOXA_BOARD_C218_ISA
) ||
462 (type
[i
] == MOXA_BOARD_C320_ISA
)) {
464 printk("Board %2d: %s board(baseAddr=%lx)\n",
466 moxa_brdname
[type
[i
] - 1],
467 (unsigned long) baseaddr
[i
]);
468 if (numBoards
>= MAX_BOARDS
) {
470 printk("More than %d MOXA Intellio family boards found. Board is ignored.", MAX_BOARDS
);
473 moxa_boards
[numBoards
].boardType
= type
[i
];
474 if (moxa_isa_boards
[i
].boardType
== MOXA_BOARD_C218_ISA
)
475 moxa_boards
[numBoards
].numPorts
= 8;
477 moxa_boards
[numBoards
].numPorts
= numports
[i
];
478 moxa_boards
[numBoards
].busType
= MOXA_BUS_TYPE_ISA
;
479 moxa_boards
[numBoards
].baseAddr
= baseaddr
[i
];
484 /* Find PCI boards here */
487 struct pci_dev
*p
= NULL
;
488 n
= sizeof(moxa_pcibrds
) / sizeof(moxa_pciinfo
);
491 while((p
= pci_find_device(moxa_pcibrds
[i
].vendor_id
, moxa_pcibrds
[i
].device_id
, p
))!=NULL
)
493 if (numBoards
>= MAX_BOARDS
) {
495 printk("More than %d MOXA Intellio family boards found. Board is ignored.", MAX_BOARDS
);
497 moxa_get_PCI_conf(p
, moxa_pcibrds
[i
].board_type
,
498 &moxa_boards
[numBoards
]);
506 for (i
= 0; i
< numBoards
; i
++) {
507 moxaBaseAddr
[i
] = (unsigned long) ioremap((unsigned long) moxa_boards
[i
].baseAddr
, 0x4000);
513 static int moxa_get_PCI_conf(struct pci_dev
*p
, int board_type
, moxa_board_conf
* board
)
517 board
->baseAddr
= p
->resource
[2].start
;
518 board
->boardType
= board_type
;
519 switch (board_type
) {
520 case MOXA_BOARD_C218_ISA
:
521 case MOXA_BOARD_C218_PCI
:
525 case MOXA_BOARD_CP204J
:
532 board
->busType
= MOXA_BUS_TYPE_PCI
;
533 board
->pciInfo
.busNum
= p
->bus
->number
;
534 board
->pciInfo
.devNum
= p
->devfn
>> 3;
539 static void do_moxa_softint(void *private_
)
541 struct moxa_str
*ch
= (struct moxa_str
*) private_
;
542 struct tty_struct
*tty
;
544 if (!ch
|| !(tty
= ch
->tty
))
546 if (test_and_clear_bit(MOXA_EVENT_HANGUP
, &ch
->event
)) {
548 wake_up_interruptible(&ch
->open_wait
);
549 ch
->asyncflags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CALLOUT_ACTIVE
);
553 static int moxa_open(struct tty_struct
*tty
, struct file
*filp
)
561 if (port
== MAX_PORTS
) {
565 if (!MoxaPortIsValid(port
)) {
566 tty
->driver_data
= NULL
;
571 page
= get_free_page(GFP_KERNEL
);
579 moxaXmitBuff
= (unsigned char *) page
;
584 ch
= &moxaChannels
[port
];
586 tty
->driver_data
= ch
;
588 if (ch
->count
== 1 && (ch
->asyncflags
& ASYNC_SPLIT_TERMIOS
)) {
589 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
590 *tty
->termios
= ch
->normal_termios
;
592 *tty
->termios
= ch
->callout_termios
;
594 ch
->session
= current
->session
;
595 ch
->pgrp
= current
->pgrp
;
596 if (!(ch
->asyncflags
& ASYNC_INITIALIZED
)) {
599 MoxaPortLineCtrl(ch
->port
, 1, 1);
600 MoxaPortEnable(ch
->port
);
601 ch
->asyncflags
|= ASYNC_INITIALIZED
;
603 retval
= block_till_ready(tty
, filp
, ch
);
605 moxa_unthrottle(tty
);
607 if (ch
->type
== PORT_16550A
) {
608 MoxaSetFifo(ch
->port
, 1);
610 MoxaSetFifo(ch
->port
, 0);
616 static void moxa_close(struct tty_struct
*tty
, struct file
*filp
)
622 if (port
== MAX_PORTS
) {
626 if (!MoxaPortIsValid(port
)) {
627 #ifdef SERIAL_DEBUG_CLOSE
628 printk("Invalid portno in moxa_close\n");
630 tty
->driver_data
= NULL
;
633 if (tty
->driver_data
== NULL
) {
636 if (tty_hung_up_p(filp
)) {
640 ch
= (struct moxa_str
*) tty
->driver_data
;
642 if ((tty
->count
== 1) && (ch
->count
!= 1)) {
643 printk("moxa_close: bad serial port count; tty->count is 1, "
644 "ch->count is %d\n", ch
->count
);
647 if (--ch
->count
< 0) {
648 printk("moxa_close: bad serial port count, minor=%d\n",
656 ch
->asyncflags
|= ASYNC_CLOSING
;
659 * Save the termios structure, since this port may have
660 * separate termios for callout and dialin.
662 if (ch
->asyncflags
& ASYNC_NORMAL_ACTIVE
)
663 ch
->normal_termios
= *tty
->termios
;
664 if (ch
->asyncflags
& ASYNC_CALLOUT_ACTIVE
)
665 ch
->callout_termios
= *tty
->termios
;
666 if (ch
->asyncflags
& ASYNC_INITIALIZED
) {
667 setup_empty_event(tty
);
668 tty_wait_until_sent(tty
, 30 * HZ
); /* 30 seconds timeout */
669 moxaEmptyTimer_on
[ch
->port
] = 0;
670 del_timer(&moxaEmptyTimer
[ch
->port
]);
673 MoxaPortFlushData(port
, 2);
675 if (tty
->driver
.flush_buffer
)
676 tty
->driver
.flush_buffer(tty
);
677 if (tty
->ldisc
.flush_buffer
)
678 tty
->ldisc
.flush_buffer(tty
);
682 if (ch
->blocked_open
) {
683 if (ch
->close_delay
) {
684 current
->state
= TASK_INTERRUPTIBLE
;
685 schedule_timeout(ch
->close_delay
);
687 wake_up_interruptible(&ch
->open_wait
);
689 ch
->asyncflags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CALLOUT_ACTIVE
|
691 wake_up_interruptible(&ch
->close_wait
);
695 static int moxa_write(struct tty_struct
*tty
, int from_user
,
696 const unsigned char *buf
, int count
)
703 ch
= (struct moxa_str
*) tty
->driver_data
;
710 copy_from_user(moxaXmitBuff
, buf
, count
);
713 temp
= (unsigned char *) buf
;
714 len
= MoxaPortWriteData(port
, temp
, count
);
715 restore_flags(flags
);
716 /*********************************************
717 if ( !(ch->statusflags & LOWWAIT) &&
718 ((len != count) || (MoxaPortTxFree(port) <= 100)) )
719 ************************************************/
720 ch
->statusflags
|= LOWWAIT
;
724 static int moxa_write_room(struct tty_struct
*tty
)
730 ch
= (struct moxa_str
*) tty
->driver_data
;
733 return (MoxaPortTxFree(ch
->port
));
736 static void moxa_flush_buffer(struct tty_struct
*tty
)
738 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
742 MoxaPortFlushData(ch
->port
, 1);
743 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
744 tty
->ldisc
.write_wakeup
)
745 (tty
->ldisc
.write_wakeup
) (tty
);
746 wake_up_interruptible(&tty
->write_wait
);
749 static int moxa_chars_in_buffer(struct tty_struct
*tty
)
752 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
755 * Sigh...I have to check if driver_data is NULL here, because
756 * if an open() fails, the TTY subsystem eventually calls
757 * tty_wait_until_sent(), which calls the driver's chars_in_buffer()
758 * routine. And since the open() failed, we return 0 here. TDJ
762 chars
= MoxaPortTxQueue(ch
->port
);
765 * Make it possible to wakeup anything waiting for output
766 * in tty_ioctl.c, etc.
768 if (!(ch
->statusflags
& EMPTYWAIT
))
769 setup_empty_event(tty
);
774 static void moxa_flush_chars(struct tty_struct
*tty
)
777 * Don't think I need this, because this is called to empty the TX
778 * buffer for the 16450, 16550, etc.
782 static void moxa_put_char(struct tty_struct
*tty
, unsigned char c
)
788 ch
= (struct moxa_str
*) tty
->driver_data
;
795 MoxaPortWriteData(port
, moxaXmitBuff
, 1);
796 restore_flags(flags
);
797 /************************************************
798 if ( !(ch->statusflags & LOWWAIT) && (MoxaPortTxFree(port) <= 100) )
799 *************************************************/
800 ch
->statusflags
|= LOWWAIT
;
803 static int moxa_ioctl(struct tty_struct
*tty
, struct file
*file
,
804 unsigned int cmd
, unsigned long arg
)
806 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
808 int retval
, dtr
, rts
;
812 if ((port
!= MAX_PORTS
) && (!ch
))
816 case TCSBRK
: /* SVID version: non-zero arg --> no break */
817 retval
= tty_check_change(tty
);
820 setup_empty_event(tty
);
821 tty_wait_until_sent(tty
, 0);
823 MoxaPortSendBreak(ch
->port
, 0);
825 case TCSBRKP
: /* support for POSIX tcsendbreak() */
826 retval
= tty_check_change(tty
);
829 setup_empty_event(tty
);
830 tty_wait_until_sent(tty
, 0);
831 MoxaPortSendBreak(ch
->port
, arg
);
834 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long *) arg
);
836 if(get_user(retval
, (unsigned long *) arg
))
839 tty
->termios
->c_cflag
= ((tty
->termios
->c_cflag
& ~CLOCAL
) |
842 ch
->asyncflags
&= ~ASYNC_CHECK_CD
;
844 ch
->asyncflags
|= ASYNC_CHECK_CD
;
848 MoxaPortGetLineOut(ch
->port
, &dtr
, &rts
);
853 dtr
= MoxaPortLineStatus(ch
->port
);
860 return put_user(flag
, (unsigned int *) arg
);
862 if(get_user(retval
, (unsigned int *) arg
))
864 MoxaPortGetLineOut(ch
->port
, &dtr
, &rts
);
865 if (retval
& TIOCM_RTS
)
867 if (retval
& TIOCM_DTR
)
869 MoxaPortLineCtrl(ch
->port
, dtr
, rts
);
872 if(get_user(retval
, (unsigned int *) arg
))
874 MoxaPortGetLineOut(ch
->port
, &dtr
, &rts
);
875 if (retval
& TIOCM_RTS
)
877 if (retval
& TIOCM_DTR
)
879 MoxaPortLineCtrl(ch
->port
, dtr
, rts
);
882 if(get_user(retval
, (unsigned long *) arg
))
885 if (retval
& TIOCM_RTS
)
887 if (retval
& TIOCM_DTR
)
889 MoxaPortLineCtrl(ch
->port
, dtr
, rts
);
892 return (moxa_get_serial_info(ch
, (struct serial_struct
*) arg
));
895 return (moxa_set_serial_info(ch
, (struct serial_struct
*) arg
));
897 retval
= MoxaDriverIoctl(cmd
, arg
, port
);
902 static void moxa_throttle(struct tty_struct
*tty
)
904 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
906 ch
->statusflags
|= THROTTLE
;
909 static void moxa_unthrottle(struct tty_struct
*tty
)
911 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
913 ch
->statusflags
&= ~THROTTLE
;
916 static void moxa_set_termios(struct tty_struct
*tty
,
917 struct termios
*old_termios
)
919 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
924 if (!(old_termios
->c_cflag
& CLOCAL
) &&
925 (tty
->termios
->c_cflag
& CLOCAL
))
926 wake_up_interruptible(&ch
->open_wait
);
929 static void moxa_stop(struct tty_struct
*tty
)
931 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
935 MoxaPortTxDisable(ch
->port
);
936 ch
->statusflags
|= TXSTOPPED
;
940 static void moxa_start(struct tty_struct
*tty
)
942 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
947 if (!(ch
->statusflags
& TXSTOPPED
))
950 MoxaPortTxEnable(ch
->port
);
951 ch
->statusflags
&= ~TXSTOPPED
;
954 static void moxa_hangup(struct tty_struct
*tty
)
956 struct moxa_str
*ch
= (struct moxa_str
*) tty
->driver_data
;
958 moxa_flush_buffer(tty
);
962 ch
->asyncflags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CALLOUT_ACTIVE
);
964 wake_up_interruptible(&ch
->open_wait
);
967 static void moxa_poll(unsigned long ignored
)
971 struct tty_struct
*tp
;
975 del_timer(&moxaTimer
);
977 if (MoxaDriverPoll() < 0) {
978 moxaTimer
.function
= moxa_poll
;
979 moxaTimer
.expires
= jiffies
+ (HZ
/ 50);
981 add_timer(&moxaTimer
);
984 for (card
= 0; card
< MAX_BOARDS
; card
++) {
985 if ((ports
= MoxaPortsOfCard(card
)) <= 0)
987 ch
= &moxaChannels
[card
* MAX_PORTS_PER_BOARD
];
988 for (i
= 0; i
< ports
; i
++, ch
++) {
989 if ((ch
->asyncflags
& ASYNC_INITIALIZED
) == 0)
991 if (!(ch
->statusflags
& THROTTLE
) &&
992 (MoxaPortRxQueue(ch
->port
) > 0))
994 if ((tp
= ch
->tty
) == 0)
996 if (ch
->statusflags
& LOWWAIT
) {
997 if (MoxaPortTxQueue(ch
->port
) <= WAKEUP_CHARS
) {
999 ch
->statusflags
&= ~LOWWAIT
;
1000 if ((tp
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1001 tp
->ldisc
.write_wakeup
)
1002 (tp
->ldisc
.write_wakeup
) (tp
);
1003 wake_up_interruptible(&tp
->write_wait
);
1007 if (!I_IGNBRK(tp
) && (MoxaPortResetBrkCnt(ch
->port
) > 0)) {
1008 tty_insert_flip_char(tp
, 0, TTY_BREAK
);
1009 tty_schedule_flip(tp
);
1011 if (MoxaPortDCDChange(ch
->port
)) {
1012 if (ch
->asyncflags
& ASYNC_CHECK_CD
) {
1013 if (MoxaPortDCDON(ch
->port
))
1014 wake_up_interruptible(&ch
->open_wait
);
1016 set_bit(MOXA_EVENT_HANGUP
, &ch
->event
);
1017 queue_task(&ch
->tqueue
, &tq_scheduler
);
1024 moxaTimer
.function
= moxa_poll
;
1025 moxaTimer
.expires
= jiffies
+ (HZ
/ 50);
1027 add_timer(&moxaTimer
);
1030 /******************************************************************************/
1032 static void set_tty_param(struct tty_struct
*tty
)
1034 register struct termios
*ts
;
1035 struct moxa_str
*ch
;
1036 int rts
, cts
, txflow
, rxflow
, xany
;
1038 ch
= (struct moxa_str
*) tty
->driver_data
;
1040 if (ts
->c_cflag
& CLOCAL
)
1041 ch
->asyncflags
&= ~ASYNC_CHECK_CD
;
1043 ch
->asyncflags
|= ASYNC_CHECK_CD
;
1044 rts
= cts
= txflow
= rxflow
= xany
= 0;
1045 if (ts
->c_cflag
& CRTSCTS
)
1047 if (ts
->c_iflag
& IXON
)
1049 if (ts
->c_iflag
& IXOFF
)
1051 if (ts
->c_iflag
& IXANY
)
1053 MoxaPortFlowCtrl(ch
->port
, rts
, cts
, txflow
, rxflow
, xany
);
1054 MoxaPortSetTermio(ch
->port
, ts
);
1057 static int block_till_ready(struct tty_struct
*tty
, struct file
*filp
,
1058 struct moxa_str
*ch
)
1060 DECLARE_WAITQUEUE(wait
,current
);
1061 unsigned long flags
;
1063 int do_clocal
= C_CLOCAL(tty
);
1066 * If the device is in the middle of being closed, then block
1067 * until it's done, and then try again.
1069 if (tty_hung_up_p(filp
) || (ch
->asyncflags
& ASYNC_CLOSING
)) {
1070 if (ch
->asyncflags
& ASYNC_CLOSING
)
1071 interruptible_sleep_on(&ch
->close_wait
);
1072 #ifdef SERIAL_DO_RESTART
1073 if (ch
->asyncflags
& ASYNC_HUP_NOTIFY
)
1076 return (-ERESTARTSYS
);
1082 * If this is a callout device, then just make sure the normal
1083 * device isn't being used.
1085 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
1086 if (ch
->asyncflags
& ASYNC_NORMAL_ACTIVE
)
1088 if ((ch
->asyncflags
& ASYNC_CALLOUT_ACTIVE
) &&
1089 (ch
->asyncflags
& ASYNC_SESSION_LOCKOUT
) &&
1090 (ch
->session
!= current
->session
))
1092 if ((ch
->asyncflags
& ASYNC_CALLOUT_ACTIVE
) &&
1093 (ch
->asyncflags
& ASYNC_PGRP_LOCKOUT
) &&
1094 (ch
->pgrp
!= current
->pgrp
))
1096 ch
->asyncflags
|= ASYNC_CALLOUT_ACTIVE
;
1100 * If non-blocking mode is set, then make the check up front
1103 if (filp
->f_flags
& O_NONBLOCK
) {
1104 if (ch
->asyncflags
& ASYNC_CALLOUT_ACTIVE
)
1106 ch
->asyncflags
|= ASYNC_NORMAL_ACTIVE
;
1110 * Block waiting for the carrier detect and the line to become free
1113 add_wait_queue(&ch
->open_wait
, &wait
);
1114 #ifdef SERIAL_DEBUG_OPEN
1115 printk("block_til_ready before block: ttys%d, count = %d\n",
1116 ch
->line
, ch
->count
);
1120 if (!tty_hung_up_p(filp
))
1122 restore_flags(flags
);
1125 current
->state
= TASK_INTERRUPTIBLE
;
1126 if (tty_hung_up_p(filp
) ||
1127 !(ch
->asyncflags
& ASYNC_INITIALIZED
)) {
1128 #ifdef SERIAL_DO_RESTART
1129 if (ch
->asyncflags
& ASYNC_HUP_NOTIFY
)
1132 retval
= -ERESTARTSYS
;
1138 if (!(ch
->asyncflags
& ASYNC_CALLOUT_ACTIVE
) &&
1139 !(ch
->asyncflags
& ASYNC_CLOSING
) && (do_clocal
||
1140 MoxaPortDCDON(ch
->port
)))
1143 if (signal_pending(current
)) {
1144 retval
= -ERESTARTSYS
;
1149 current
->state
= TASK_RUNNING
;
1150 remove_wait_queue(&ch
->open_wait
, &wait
);
1151 if (!tty_hung_up_p(filp
))
1154 #ifdef SERIAL_DEBUG_OPEN
1155 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1156 ch
->line
, ch
->count
);
1160 ch
->asyncflags
|= ASYNC_NORMAL_ACTIVE
;
1164 static void setup_empty_event(struct tty_struct
*tty
)
1166 struct moxa_str
*ch
= tty
->driver_data
;
1167 unsigned long flags
;
1171 ch
->statusflags
|= EMPTYWAIT
;
1172 moxaEmptyTimer_on
[ch
->port
] = 0;
1173 del_timer(&moxaEmptyTimer
[ch
->port
]);
1174 moxaEmptyTimer
[ch
->port
].expires
= jiffies
+ HZ
;
1175 moxaEmptyTimer_on
[ch
->port
] = 1;
1176 add_timer(&moxaEmptyTimer
[ch
->port
]);
1177 restore_flags(flags
);
1180 static void check_xmit_empty(unsigned long data
)
1182 struct moxa_str
*ch
;
1184 ch
= (struct moxa_str
*) data
;
1185 moxaEmptyTimer_on
[ch
->port
] = 0;
1186 del_timer(&moxaEmptyTimer
[ch
->port
]);
1187 if (ch
->tty
&& (ch
->statusflags
& EMPTYWAIT
)) {
1188 if (MoxaPortTxQueue(ch
->port
) == 0) {
1189 ch
->statusflags
&= ~EMPTYWAIT
;
1190 if ((ch
->tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1191 ch
->tty
->ldisc
.write_wakeup
)
1192 (ch
->tty
->ldisc
.write_wakeup
) (ch
->tty
);
1193 wake_up_interruptible(&ch
->tty
->write_wait
);
1196 moxaEmptyTimer
[ch
->port
].expires
= jiffies
+ HZ
;
1197 moxaEmptyTimer_on
[ch
->port
] = 1;
1198 add_timer(&moxaEmptyTimer
[ch
->port
]);
1200 ch
->statusflags
&= ~EMPTYWAIT
;
1203 static void shut_down(struct moxa_str
*ch
)
1205 struct tty_struct
*tp
;
1207 if (!(ch
->asyncflags
& ASYNC_INITIALIZED
))
1212 MoxaPortDisable(ch
->port
);
1215 * If we're a modem control device and HUPCL is on, drop RTS & DTR.
1217 if (tp
->termios
->c_cflag
& HUPCL
)
1218 MoxaPortLineCtrl(ch
->port
, 0, 0);
1220 ch
->asyncflags
&= ~ASYNC_INITIALIZED
;
1223 static void receive_data(struct moxa_str
*ch
)
1225 struct tty_struct
*tp
;
1227 int i
, count
, rc
, space
;
1228 unsigned char *charptr
, *flagptr
;
1229 unsigned long flags
;
1235 /**************************************************
1236 if ( !tp || !ts || !(ts->c_cflag & CREAD) ) {
1237 *****************************************************/
1239 MoxaPortFlushData(ch
->port
, 0);
1242 space
= TTY_FLIPBUF_SIZE
- tp
->flip
.count
;
1245 charptr
= tp
->flip
.char_buf_ptr
;
1246 flagptr
= tp
->flip
.flag_buf_ptr
;
1247 rc
= tp
->flip
.count
;
1250 count
= MoxaPortReadData(ch
->port
, charptr
, space
);
1251 restore_flags(flags
);
1252 for (i
= 0; i
< count
; i
++)
1256 tp
->flip
.count
= rc
;
1257 tp
->flip
.char_buf_ptr
= charptr
;
1258 tp
->flip
.flag_buf_ptr
= flagptr
;
1259 tty_schedule_flip(ch
->tty
);
1262 #define Magic_code 0x404
1265 * System Configuration
1268 * for C218 BIOS initialization
1270 #define C218_ConfBase 0x800
1271 #define C218_status (C218_ConfBase + 0) /* BIOS running status */
1272 #define C218_diag (C218_ConfBase + 2) /* diagnostic status */
1273 #define C218_key (C218_ConfBase + 4) /* WORD (0x218 for C218) */
1274 #define C218DLoad_len (C218_ConfBase + 6) /* WORD */
1275 #define C218check_sum (C218_ConfBase + 8) /* BYTE */
1276 #define C218chksum_ok (C218_ConfBase + 0x0a) /* BYTE (1:ok) */
1277 #define C218_TestRx (C218_ConfBase + 0x10) /* 8 bytes for 8 ports */
1278 #define C218_TestTx (C218_ConfBase + 0x18) /* 8 bytes for 8 ports */
1279 #define C218_RXerr (C218_ConfBase + 0x20) /* 8 bytes for 8 ports */
1280 #define C218_ErrFlag (C218_ConfBase + 0x28) /* 8 bytes for 8 ports */
1282 #define C218_LoadBuf 0x0F00
1283 #define C218_KeyCode 0x218
1284 #define CP204J_KeyCode 0x204
1287 * for C320 BIOS initialization
1289 #define C320_ConfBase 0x800
1290 #define C320_LoadBuf 0x0f00
1291 #define STS_init 0x05 /* for C320_status */
1293 #define C320_status C320_ConfBase + 0 /* BIOS running status */
1294 #define C320_diag C320_ConfBase + 2 /* diagnostic status */
1295 #define C320_key C320_ConfBase + 4 /* WORD (0320H for C320) */
1296 #define C320DLoad_len C320_ConfBase + 6 /* WORD */
1297 #define C320check_sum C320_ConfBase + 8 /* WORD */
1298 #define C320chksum_ok C320_ConfBase + 0x0a /* WORD (1:ok) */
1299 #define C320bapi_len C320_ConfBase + 0x0c /* WORD */
1300 #define C320UART_no C320_ConfBase + 0x0e /* WORD */
1302 #define C320_KeyCode 0x320
1304 #define FixPage_addr 0x0000 /* starting addr of static page */
1305 #define DynPage_addr 0x2000 /* starting addr of dynamic page */
1306 #define C218_start 0x3000 /* starting addr of C218 BIOS prg */
1307 #define Control_reg 0x1ff0 /* select page and reset control */
1308 #define HW_reset 0x80
1313 #define FC_CardReset 0x80
1314 #define FC_ChannelReset 1 /* C320 firmware not supported */
1315 #define FC_EnableCH 2
1316 #define FC_DisableCH 3
1317 #define FC_SetParam 4
1318 #define FC_SetMode 5
1319 #define FC_SetRate 6
1320 #define FC_LineControl 7
1321 #define FC_LineStatus 8
1322 #define FC_XmitControl 9
1323 #define FC_FlushQueue 10
1324 #define FC_SendBreak 11
1325 #define FC_StopBreak 12
1326 #define FC_LoopbackON 13
1327 #define FC_LoopbackOFF 14
1328 #define FC_ClrIrqTable 15
1329 #define FC_SendXon 16
1330 #define FC_SetTermIrq 17 /* C320 firmware not supported */
1331 #define FC_SetCntIrq 18 /* C320 firmware not supported */
1332 #define FC_SetBreakIrq 19
1333 #define FC_SetLineIrq 20
1334 #define FC_SetFlowCtl 21
1335 #define FC_GenIrq 22
1336 #define FC_InCD180 23
1337 #define FC_OutCD180 24
1338 #define FC_InUARTreg 23
1339 #define FC_OutUARTreg 24
1340 #define FC_SetXonXoff 25
1341 #define FC_OutCD180CCR 26
1342 #define FC_ExtIQueue 27
1343 #define FC_ExtOQueue 28
1344 #define FC_ClrLineIrq 29
1345 #define FC_HWFlowCtl 30
1346 #define FC_GetClockRate 35
1347 #define FC_SetBaud 36
1348 #define FC_SetDataMode 41
1349 #define FC_GetCCSR 43
1350 #define FC_GetDataError 45
1351 #define FC_RxControl 50
1352 #define FC_ImmSend 51
1353 #define FC_SetXonState 52
1354 #define FC_SetXoffState 53
1355 #define FC_SetRxFIFOTrig 54
1356 #define FC_SetTxFIFOCnt 55
1357 #define FC_UnixRate 56
1358 #define FC_UnixResetTimer 57
1360 #define RxFIFOTrig1 0
1361 #define RxFIFOTrig4 1
1362 #define RxFIFOTrig8 2
1363 #define RxFIFOTrig14 3
1368 #define DRAM_global 0
1369 #define INT_data (DRAM_global + 0)
1370 #define Config_base (DRAM_global + 0x108)
1372 #define IRQindex (INT_data + 0)
1373 #define IRQpending (INT_data + 4)
1374 #define IRQtable (INT_data + 8)
1379 #define IntrRx 0x01 /* receiver data O.K. */
1380 #define IntrTx 0x02 /* transmit buffer empty */
1381 #define IntrFunc 0x04 /* function complete */
1382 #define IntrBreak 0x08 /* received break */
1383 #define IntrLine 0x10 /* line status change
1385 #define IntrIntr 0x20 /* received INTR code */
1386 #define IntrQuit 0x40 /* received QUIT code */
1387 #define IntrEOF 0x80 /* received EOF code */
1389 #define IntrRxTrigger 0x100 /* rx data count reach tigger value */
1390 #define IntrTxTrigger 0x200 /* tx data count below trigger value */
1392 #define Magic_no (Config_base + 0)
1393 #define Card_model_no (Config_base + 2)
1394 #define Total_ports (Config_base + 4)
1395 #define Module_cnt (Config_base + 8)
1396 #define Module_no (Config_base + 10)
1397 #define Timer_10ms (Config_base + 14)
1398 #define Disable_IRQ (Config_base + 20)
1399 #define TMS320_PORT1 (Config_base + 22)
1400 #define TMS320_PORT2 (Config_base + 24)
1401 #define TMS320_CLOCK (Config_base + 26)
1404 * DATA BUFFER in DRAM
1406 #define Extern_table 0x400 /* Base address of the external table
1407 (24 words * 64) total 3K bytes
1408 (24 words * 128) total 6K bytes */
1409 #define Extern_size 0x60 /* 96 bytes */
1410 #define RXrptr 0x00 /* read pointer for RX buffer */
1411 #define RXwptr 0x02 /* write pointer for RX buffer */
1412 #define TXrptr 0x04 /* read pointer for TX buffer */
1413 #define TXwptr 0x06 /* write pointer for TX buffer */
1414 #define HostStat 0x08 /* IRQ flag and general flag */
1415 #define FlagStat 0x0A
1416 #define FlowControl 0x0C /* B7 B6 B5 B4 B3 B2 B1 B0 */
1417 /* x x x x | | | | */
1418 /* | | | + CTS flow */
1419 /* | | +--- RTS flow */
1420 /* | +------ TX Xon/Xoff */
1421 /* +--------- RX Xon/Xoff */
1422 #define Break_cnt 0x0E /* received break count */
1423 #define CD180TXirq 0x10 /* if non-0: enable TX irq */
1424 #define RX_mask 0x12
1425 #define TX_mask 0x14
1426 #define Ofs_rxb 0x16
1427 #define Ofs_txb 0x18
1428 #define Page_rxb 0x1A
1429 #define Page_txb 0x1C
1430 #define EndPage_rxb 0x1E
1431 #define EndPage_txb 0x20
1432 #define Data_error 0x22
1433 #define RxTrigger 0x28
1434 #define TxTrigger 0x2a
1436 #define rRXwptr 0x34
1437 #define Low_water 0x36
1439 #define FuncCode 0x40
1440 #define FuncArg 0x42
1441 #define FuncArg1 0x44
1443 #define C218rx_size 0x2000 /* 8K bytes */
1444 #define C218tx_size 0x8000 /* 32K bytes */
1446 #define C218rx_mask (C218rx_size - 1)
1447 #define C218tx_mask (C218tx_size - 1)
1449 #define C320p8rx_size 0x2000
1450 #define C320p8tx_size 0x8000
1451 #define C320p8rx_mask (C320p8rx_size - 1)
1452 #define C320p8tx_mask (C320p8tx_size - 1)
1454 #define C320p16rx_size 0x2000
1455 #define C320p16tx_size 0x4000
1456 #define C320p16rx_mask (C320p16rx_size - 1)
1457 #define C320p16tx_mask (C320p16tx_size - 1)
1459 #define C320p24rx_size 0x2000
1460 #define C320p24tx_size 0x2000
1461 #define C320p24rx_mask (C320p24rx_size - 1)
1462 #define C320p24tx_mask (C320p24tx_size - 1)
1464 #define C320p32rx_size 0x1000
1465 #define C320p32tx_size 0x1000
1466 #define C320p32rx_mask (C320p32rx_size - 1)
1467 #define C320p32tx_mask (C320p32tx_size - 1)
1469 #define Page_size 0x2000
1470 #define Page_mask (Page_size - 1)
1471 #define C218rx_spage 3
1472 #define C218tx_spage 4
1473 #define C218rx_pageno 1
1474 #define C218tx_pageno 4
1475 #define C218buf_pageno 5
1477 #define C320p8rx_spage 3
1478 #define C320p8tx_spage 4
1479 #define C320p8rx_pgno 1
1480 #define C320p8tx_pgno 4
1481 #define C320p8buf_pgno 5
1483 #define C320p16rx_spage 3
1484 #define C320p16tx_spage 4
1485 #define C320p16rx_pgno 1
1486 #define C320p16tx_pgno 2
1487 #define C320p16buf_pgno 3
1489 #define C320p24rx_spage 3
1490 #define C320p24tx_spage 4
1491 #define C320p24rx_pgno 1
1492 #define C320p24tx_pgno 1
1493 #define C320p24buf_pgno 2
1495 #define C320p32rx_spage 3
1496 #define C320p32tx_ofs C320p32rx_size
1497 #define C320p32tx_spage 3
1498 #define C320p32buf_pgno 1
1503 #define WakeupRx 0x01
1504 #define WakeupTx 0x02
1505 #define WakeupBreak 0x08
1506 #define WakeupLine 0x10
1507 #define WakeupIntr 0x20
1508 #define WakeupQuit 0x40
1509 #define WakeupEOF 0x80 /* used in VTIME control */
1510 #define WakeupRxTrigger 0x100
1511 #define WakeupTxTrigger 0x200
1515 #define Rx_over 0x01
1516 #define Xoff_state 0x02
1517 #define Tx_flowOff 0x04
1518 #define Tx_enable 0x08
1519 #define CTS_state 0x10
1520 #define DSR_state 0x20
1521 #define DCD_state 0x80
1525 #define CTS_FlowCtl 1
1526 #define RTS_FlowCtl 2
1527 #define Tx_FlowCtl 4
1528 #define Rx_FlowCtl 8
1529 #define IXM_IXANY 0x10
1531 #define LowWater 128
1539 /* mode definition */
1545 #define MX_STOP1 0x00
1546 #define MX_STOP15 0x04
1547 #define MX_STOP2 0x08
1549 #define MX_PARNONE 0x00
1550 #define MX_PAREVEN 0x40
1551 #define MX_PARODD 0xC0
1556 #define QueryPort MAX_PORTS
1562 int rxcnt
[MAX_PORTS
];
1563 int txcnt
[MAX_PORTS
];
1565 typedef struct mon_str mon_st
;
1567 #define DCD_changed 0x01
1568 #define DCD_oldstate 0x80
1570 static unsigned char moxaBuff
[10240];
1571 static unsigned long moxaIntNdx
[MAX_BOARDS
];
1572 static unsigned long moxaIntPend
[MAX_BOARDS
];
1573 static unsigned long moxaIntTable
[MAX_BOARDS
];
1574 static char moxaChkPort
[MAX_PORTS
];
1575 static char moxaLineCtrl
[MAX_PORTS
];
1576 static unsigned long moxaTableAddr
[MAX_PORTS
];
1577 static long moxaCurBaud
[MAX_PORTS
];
1578 static char moxaDCDState
[MAX_PORTS
];
1579 static char moxaLowChkFlag
[MAX_PORTS
];
1580 static int moxaLowWaterChk
;
1581 static int moxaCard
;
1582 static mon_st moxaLog
;
1583 static int moxaFuncTout
;
1584 static ushort moxaBreakCnt
[MAX_PORTS
];
1586 static void moxadelay(int);
1587 static void moxafunc(unsigned long, int, ushort
);
1588 static void wait_finish(unsigned long);
1589 static void low_water_check(unsigned long);
1590 static int moxaloadbios(int, unsigned char *, int);
1591 static int moxafindcard(int);
1592 static int moxaload320b(int, unsigned char *, int);
1593 static int moxaloadcode(int, unsigned char *, int);
1594 static int moxaloadc218(int, unsigned long, int);
1595 static int moxaloadc320(int, unsigned long, int, int *);
1597 /*****************************************************************************
1598 * Driver level functions: *
1599 * 1. MoxaDriverInit(void); *
1600 * 2. MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port); *
1601 * 3. MoxaDriverPoll(void); *
1602 *****************************************************************************/
1603 void MoxaDriverInit(void)
1607 moxaFuncTout
= HZ
/ 2; /* 500 mini-seconds */
1610 moxaLowWaterChk
= 0;
1611 for (i
= 0; i
< MAX_PORTS
; i
++) {
1613 moxaLowChkFlag
[i
] = 0;
1614 moxaLineCtrl
[i
] = 0;
1615 moxaLog
.rxcnt
[i
] = 0;
1616 moxaLog
.txcnt
[i
] = 0;
1621 #define MOXA_GET_IQUEUE (MOXA + 1) /* get input buffered count */
1622 #define MOXA_GET_OQUEUE (MOXA + 2) /* get output buffered count */
1623 #define MOXA_INIT_DRIVER (MOXA + 6) /* moxaCard=0 */
1624 #define MOXA_LOAD_BIOS (MOXA + 9) /* download BIOS */
1625 #define MOXA_FIND_BOARD (MOXA + 10) /* Check if MOXA card exist? */
1626 #define MOXA_LOAD_C320B (MOXA + 11) /* download 320B firmware */
1627 #define MOXA_LOAD_CODE (MOXA + 12) /* download firmware */
1628 #define MOXA_GETDATACOUNT (MOXA + 23)
1629 #define MOXA_GET_IOQUEUE (MOXA + 27)
1630 #define MOXA_FLUSH_QUEUE (MOXA + 28)
1631 #define MOXA_GET_CONF (MOXA + 35) /* configuration */
1632 #define MOXA_GET_MAJOR (MOXA + 63)
1633 #define MOXA_GET_CUMAJOR (MOXA + 64)
1634 #define MOXA_GETMSTATUS (MOXA + 65)
1648 static struct moxaq_str temp_queue
[MAX_PORTS
];
1649 static struct dl_str dltmp
;
1651 void MoxaPortFlushData(int port
, int mode
)
1653 unsigned long ofsAddr
;
1654 if ((mode
< 0) || (mode
> 2))
1656 ofsAddr
= moxaTableAddr
[port
];
1657 moxafunc(ofsAddr
, FC_FlushQueue
, mode
);
1659 moxaLowChkFlag
[port
] = 0;
1660 low_water_check(ofsAddr
);
1664 int MoxaDriverIoctl(unsigned int cmd
, unsigned long arg
, int port
)
1668 int MoxaPortTxQueue(int), MoxaPortRxQueue(int);
1670 if (port
== QueryPort
) {
1671 if ((cmd
!= MOXA_GET_CONF
) && (cmd
!= MOXA_INIT_DRIVER
) &&
1672 (cmd
!= MOXA_LOAD_BIOS
) && (cmd
!= MOXA_FIND_BOARD
) && (cmd
!= MOXA_LOAD_C320B
) &&
1673 (cmd
!= MOXA_LOAD_CODE
) && (cmd
!= MOXA_GETDATACOUNT
) &&
1674 (cmd
!= MOXA_GET_IOQUEUE
) && (cmd
!= MOXA_GET_MAJOR
) &&
1675 (cmd
!= MOXA_GET_CUMAJOR
) && (cmd
!= MOXA_GETMSTATUS
))
1680 if(copy_to_user((void *)arg
, &moxa_boards
, MAX_BOARDS
* sizeof(moxa_board_conf
)))
1683 case MOXA_INIT_DRIVER
:
1684 if ((int) arg
== 0x404)
1687 case MOXA_GETDATACOUNT
:
1688 moxaLog
.tick
= jiffies
;
1689 if(copy_to_user((void *)arg
, &moxaLog
, sizeof(mon_st
)))
1692 case MOXA_FLUSH_QUEUE
:
1693 MoxaPortFlushData(port
, arg
);
1695 case MOXA_GET_IOQUEUE
:
1696 for (i
= 0; i
< MAX_PORTS
; i
++) {
1697 if (moxaChkPort
[i
]) {
1698 temp_queue
[i
].inq
= MoxaPortRxQueue(i
);
1699 temp_queue
[i
].outq
= MoxaPortTxQueue(i
);
1702 if(copy_to_user((void *)arg
, temp_queue
, sizeof(struct moxaq_str
) * MAX_PORTS
))
1705 case MOXA_LOAD_BIOS
:
1706 if(copy_from_user(&dltmp
, (void *)arg
, sizeof(struct dl_str
)))
1708 i
= moxaloadbios(dltmp
.cardno
, dltmp
.buf
, dltmp
.len
);
1710 case MOXA_FIND_BOARD
:
1711 if(copy_from_user(&dltmp
, (void *)arg
, sizeof(struct dl_str
)))
1713 return moxafindcard(dltmp
.cardno
);
1714 case MOXA_LOAD_C320B
:
1715 if(copy_from_user(&dltmp
, (void *)arg
, sizeof(struct dl_str
)))
1717 moxaload320b(dltmp
.cardno
, dltmp
.buf
, dltmp
.len
);
1719 case MOXA_LOAD_CODE
:
1720 if(copy_from_user(&dltmp
, (void *)arg
, sizeof(struct dl_str
)))
1722 i
= moxaloadcode(dltmp
.cardno
, dltmp
.buf
, dltmp
.len
);
1726 case MOXA_GET_OQUEUE
:
1727 i
= MoxaPortTxQueue(port
);
1728 return put_user(i
, (unsigned long *) arg
);
1729 case MOXA_GET_IQUEUE
:
1730 i
= MoxaPortRxQueue(port
);
1731 return put_user(i
, (unsigned long *) arg
);
1732 case MOXA_GET_MAJOR
:
1733 if(copy_to_user((void *)arg
, &ttymajor
, sizeof(int)))
1736 case MOXA_GET_CUMAJOR
:
1737 if(copy_to_user((void *)arg
, &calloutmajor
, sizeof(int)))
1740 case MOXA_GETMSTATUS
:
1741 for (i
= 0; i
< MAX_PORTS
; i
++) {
1743 GMStatus
[i
].dcd
= 0;
1744 GMStatus
[i
].dsr
= 0;
1745 GMStatus
[i
].cts
= 0;
1746 if (!moxaChkPort
[i
]) {
1749 status
= MoxaPortLineStatus(moxaChannels
[i
].port
);
1751 GMStatus
[i
].cts
= 1;
1753 GMStatus
[i
].dsr
= 1;
1755 GMStatus
[i
].dcd
= 1;
1758 if (!moxaChannels
[i
].tty
|| !moxaChannels
[i
].tty
->termios
)
1759 GMStatus
[i
].cflag
= moxaChannels
[i
].normal_termios
.c_cflag
;
1761 GMStatus
[i
].cflag
= moxaChannels
[i
].tty
->termios
->c_cflag
;
1763 if(copy_to_user((void *)arg
, GMStatus
, sizeof(struct mxser_mstatus
) * MAX_PORTS
))
1768 return (-ENOIOCTLCMD
);
1771 int MoxaDriverPoll(void)
1773 register ushort temp
;
1775 unsigned long ip
, ofsAddr
;
1780 for (card
= 0; card
< MAX_BOARDS
; card
++) {
1781 if ((ports
= moxa_boards
[card
].numPorts
) == 0)
1783 if (readb(moxaIntPend
[card
]) == 0xff) {
1784 ip
= moxaIntTable
[card
] + readb(moxaIntNdx
[card
]);
1785 p
= card
* MAX_PORTS_PER_BOARD
;
1787 for (port
= 0; port
< ports
; port
+= 2, p
++) {
1788 if ((temp
= readw(ip
+ port
)) != 0) {
1789 writew(0, ip
+ port
);
1790 ofsAddr
= moxaTableAddr
[p
];
1792 writew(readw(ofsAddr
+ HostStat
) & ~WakeupTx
, ofsAddr
+ HostStat
);
1793 if (temp
& IntrBreak
) {
1796 if (temp
& IntrLine
) {
1797 if (readb(ofsAddr
+ FlagStat
) & DCD_state
) {
1798 if ((moxaDCDState
[p
] & DCD_oldstate
) == 0)
1799 moxaDCDState
[p
] = (DCD_oldstate
|
1802 if (moxaDCDState
[p
] & DCD_oldstate
)
1803 moxaDCDState
[p
] = DCD_changed
;
1808 writeb(0, moxaIntPend
[card
]);
1810 if (moxaLowWaterChk
) {
1811 p
= card
* MAX_PORTS_PER_BOARD
;
1812 for (port
= 0; port
< ports
; port
++, p
++) {
1813 if (moxaLowChkFlag
[p
]) {
1814 moxaLowChkFlag
[p
] = 0;
1815 ofsAddr
= moxaTableAddr
[p
];
1816 low_water_check(ofsAddr
);
1821 moxaLowWaterChk
= 0;
1825 /*****************************************************************************
1826 * Card level function: *
1827 * 1. MoxaPortsOfCard(int cardno); *
1828 *****************************************************************************/
1829 int MoxaPortsOfCard(int cardno
)
1832 if (moxa_boards
[cardno
].boardType
== 0)
1834 return (moxa_boards
[cardno
].numPorts
);
1837 /*****************************************************************************
1838 * Port level functions: *
1839 * 1. MoxaPortIsValid(int port); *
1840 * 2. MoxaPortEnable(int port); *
1841 * 3. MoxaPortDisable(int port); *
1842 * 4. MoxaPortGetMaxBaud(int port); *
1843 * 5. MoxaPortGetCurBaud(int port); *
1844 * 6. MoxaPortSetBaud(int port, long baud); *
1845 * 7. MoxaPortSetMode(int port, int databit, int stopbit, int parity); *
1846 * 8. MoxaPortSetTermio(int port, unsigned char *termio); *
1847 * 9. MoxaPortGetLineOut(int port, int *dtrState, int *rtsState); *
1848 * 10. MoxaPortLineCtrl(int port, int dtrState, int rtsState); *
1849 * 11. MoxaPortFlowCtrl(int port, int rts, int cts, int rx, int tx,int xany); *
1850 * 12. MoxaPortLineStatus(int port); *
1851 * 13. MoxaPortDCDChange(int port); *
1852 * 14. MoxaPortDCDON(int port); *
1853 * 15. MoxaPortFlushData(int port, int mode); *
1854 * 16. MoxaPortWriteData(int port, unsigned char * buffer, int length); *
1855 * 17. MoxaPortReadData(int port, unsigned char * buffer, int length); *
1856 * 18. MoxaPortTxBufSize(int port); *
1857 * 19. MoxaPortRxBufSize(int port); *
1858 * 20. MoxaPortTxQueue(int port); *
1859 * 21. MoxaPortTxFree(int port); *
1860 * 22. MoxaPortRxQueue(int port); *
1861 * 23. MoxaPortRxFree(int port); *
1862 * 24. MoxaPortTxDisable(int port); *
1863 * 25. MoxaPortTxEnable(int port); *
1864 * 26. MoxaPortGetBrkCnt(int port); *
1865 * 27. MoxaPortResetBrkCnt(int port); *
1866 * 28. MoxaPortSetXonXoff(int port, int xonValue, int xoffValue); *
1867 * 29. MoxaPortIsTxHold(int port); *
1868 * 30. MoxaPortSendBreak(int port, int ticks); *
1869 *****************************************************************************/
1871 * Moxa Port Number Description:
1873 * MOXA serial driver supports up to 4 MOXA-C218/C320 boards. And,
1874 * the port number using in MOXA driver functions will be 0 to 31 for
1875 * first MOXA board, 32 to 63 for second, 64 to 95 for third and 96
1876 * to 127 for fourth. For example, if you setup three MOXA boards,
1877 * first board is C218, second board is C320-16 and third board is
1878 * C320-32. The port number of first board (C218 - 8 ports) is from
1879 * 0 to 7. The port number of second board (C320 - 16 ports) is form
1880 * 32 to 47. The port number of third board (C320 - 32 ports) is from
1881 * 64 to 95. And those port numbers form 8 to 31, 48 to 63 and 96 to
1882 * 127 will be invalid.
1885 * Moxa Functions Description:
1887 * Function 1: Driver initialization routine, this routine must be
1888 * called when initialized driver.
1890 * void MoxaDriverInit();
1893 * Function 2: Moxa driver private IOCTL command processing.
1895 * int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port);
1897 * unsigned int cmd : IOCTL command
1898 * unsigned long arg : IOCTL argument
1899 * int port : port number (0 - 127)
1906 * Function 3: Moxa driver polling process routine.
1908 * int MoxaDriverPoll(void);
1910 * return: 0 ; polling O.K.
1911 * -1 : no any Moxa card.
1914 * Function 4: Get the ports of this card.
1916 * int MoxaPortsOfCard(int cardno);
1918 * int cardno : card number (0 - 3)
1920 * return: 0 : this card is invalid
1924 * Function 5: Check this port is valid or invalid
1926 * int MoxaPortIsValid(int port);
1927 * int port : port number (0 - 127, ref port description)
1929 * return: 0 : this port is invalid
1930 * 1 : this port is valid
1933 * Function 6: Enable this port to start Tx/Rx data.
1935 * void MoxaPortEnable(int port);
1936 * int port : port number (0 - 127)
1939 * Function 7: Disable this port
1941 * void MoxaPortDisable(int port);
1942 * int port : port number (0 - 127)
1945 * Function 8: Get the maximun available baud rate of this port.
1947 * long MoxaPortGetMaxBaud(int port);
1948 * int port : port number (0 - 127)
1950 * return: 0 : this port is invalid
1951 * 38400/57600/115200 bps
1954 * Function 9: Get the current baud rate of this port.
1956 * long MoxaPortGetCurBaud(int port);
1957 * int port : port number (0 - 127)
1959 * return: 0 : this port is invalid
1963 * Function 10: Setting baud rate of this port.
1965 * long MoxaPortSetBaud(int port, long baud);
1966 * int port : port number (0 - 127)
1967 * long baud : baud rate (50 - 115200)
1969 * return: 0 : this port is invalid or baud < 50
1970 * 50 - 115200 : the real baud rate set to the port, if
1971 * the argument baud is large than maximun
1972 * available baud rate, the real setting
1973 * baud rate will be the maximun baud rate.
1976 * Function 11: Setting the data-bits/stop-bits/parity of this port
1978 * int MoxaPortSetMode(int port, int databits, int stopbits, int parity);
1979 * int port : port number (0 - 127)
1980 * int databits : data bits (8/7/6/5)
1981 * int stopbits : stop bits (2/1/0, 0 show 1.5 stop bits)
1982 int parity : parity (0:None,1:Odd,2:Even,3:Mark,4:Space)
1984 * return: -1 : invalid parameter
1988 * Function 12: Configure the port.
1990 * int MoxaPortSetTermio(int port, struct termios *termio);
1991 * int port : port number (0 - 127)
1992 * struct termios * termio : termio structure pointer
1994 * return: -1 : this port is invalid or termio == NULL
1998 * Function 13: Get the DTR/RTS state of this port.
2000 * int MoxaPortGetLineOut(int port, int *dtrState, int *rtsState);
2001 * int port : port number (0 - 127)
2002 * int * dtrState : pointer to INT to receive the current DTR
2003 * state. (if NULL, this function will not
2004 * write to this address)
2005 * int * rtsState : pointer to INT to receive the current RTS
2006 * state. (if NULL, this function will not
2007 * write to this address)
2009 * return: -1 : this port is invalid
2013 * Function 14: Setting the DTR/RTS output state of this port.
2015 * void MoxaPortLineCtrl(int port, int dtrState, int rtsState);
2016 * int port : port number (0 - 127)
2017 * int dtrState : DTR output state (0: off, 1: on)
2018 * int rtsState : RTS output state (0: off, 1: on)
2021 * Function 15: Setting the flow control of this port.
2023 * void MoxaPortFlowCtrl(int port, int rtsFlow, int ctsFlow, int rxFlow,
2024 * int txFlow,int xany);
2025 * int port : port number (0 - 127)
2026 * int rtsFlow : H/W RTS flow control (0: no, 1: yes)
2027 * int ctsFlow : H/W CTS flow control (0: no, 1: yes)
2028 * int rxFlow : S/W Rx XON/XOFF flow control (0: no, 1: yes)
2029 * int txFlow : S/W Tx XON/XOFF flow control (0: no, 1: yes)
2030 * int xany : S/W XANY flow control (0: no, 1: yes)
2033 * Function 16: Get ths line status of this port
2035 * int MoxaPortLineStatus(int port);
2036 * int port : port number (0 - 127)
2038 * return: Bit 0 - CTS state (0: off, 1: on)
2039 * Bit 1 - DSR state (0: off, 1: on)
2040 * Bit 2 - DCD state (0: off, 1: on)
2043 * Function 17: Check the DCD state has changed since the last read
2046 * int MoxaPortDCDChange(int port);
2047 * int port : port number (0 - 127)
2049 * return: 0 : no changed
2050 * 1 : DCD has changed
2053 * Function 18: Check ths current DCD state is ON or not.
2055 * int MoxaPortDCDON(int port);
2056 * int port : port number (0 - 127)
2058 * return: 0 : DCD off
2062 * Function 19: Flush the Rx/Tx buffer data of this port.
2064 * void MoxaPortFlushData(int port, int mode);
2065 * int port : port number (0 - 127)
2067 * 0 : flush the Rx buffer
2068 * 1 : flush the Tx buffer
2069 * 2 : flush the Rx and Tx buffer
2072 * Function 20: Write data.
2074 * int MoxaPortWriteData(int port, unsigned char * buffer, int length);
2075 * int port : port number (0 - 127)
2076 * unsigned char * buffer : pointer to write data buffer.
2077 * int length : write data length
2079 * return: 0 - length : real write data length
2082 * Function 21: Read data.
2084 * int MoxaPortReadData(int port, unsigned char * buffer, int length);
2085 * int port : port number (0 - 127)
2086 * unsigned char * buffer : pointer to read data buffer.
2087 * int length : read data buffer length
2089 * return: 0 - length : real read data length
2092 * Function 22: Get the Tx buffer size of this port
2094 * int MoxaPortTxBufSize(int port);
2095 * int port : port number (0 - 127)
2097 * return: .. : Tx buffer size
2100 * Function 23: Get the Rx buffer size of this port
2102 * int MoxaPortRxBufSize(int port);
2103 * int port : port number (0 - 127)
2105 * return: .. : Rx buffer size
2108 * Function 24: Get the Tx buffer current queued data bytes
2110 * int MoxaPortTxQueue(int port);
2111 * int port : port number (0 - 127)
2113 * return: .. : Tx buffer current queued data bytes
2116 * Function 25: Get the Tx buffer current free space
2118 * int MoxaPortTxFree(int port);
2119 * int port : port number (0 - 127)
2121 * return: .. : Tx buffer current free space
2124 * Function 26: Get the Rx buffer current queued data bytes
2126 * int MoxaPortRxQueue(int port);
2127 * int port : port number (0 - 127)
2129 * return: .. : Rx buffer current queued data bytes
2132 * Function 27: Get the Rx buffer current free space
2134 * int MoxaPortRxFree(int port);
2135 * int port : port number (0 - 127)
2137 * return: .. : Rx buffer current free space
2140 * Function 28: Disable port data transmission.
2142 * void MoxaPortTxDisable(int port);
2143 * int port : port number (0 - 127)
2146 * Function 29: Enable port data transmission.
2148 * void MoxaPortTxEnable(int port);
2149 * int port : port number (0 - 127)
2152 * Function 30: Get the received BREAK signal count.
2154 * int MoxaPortGetBrkCnt(int port);
2155 * int port : port number (0 - 127)
2157 * return: 0 - .. : BREAK signal count
2160 * Function 31: Get the received BREAK signal count and reset it.
2162 * int MoxaPortResetBrkCnt(int port);
2163 * int port : port number (0 - 127)
2165 * return: 0 - .. : BREAK signal count
2168 * Function 32: Set the S/W flow control new XON/XOFF value, default
2169 * XON is 0x11 & XOFF is 0x13.
2171 * void MoxaPortSetXonXoff(int port, int xonValue, int xoffValue);
2172 * int port : port number (0 - 127)
2173 * int xonValue : new XON value (0 - 255)
2174 * int xoffValue : new XOFF value (0 - 255)
2177 * Function 33: Check this port's transmission is hold by remote site
2178 * because the flow control.
2180 * int MoxaPortIsTxHold(int port);
2181 * int port : port number (0 - 127)
2183 * return: 0 : normal
2184 * 1 : hold by remote site
2187 * Function 34: Send out a BREAK signal.
2189 * void MoxaPortSendBreak(int port, int ms100);
2190 * int port : port number (0 - 127)
2191 * int ms100 : break signal time interval.
2192 * unit: 100 mini-second. if ms100 == 0, it will
2193 * send out a about 250 ms BREAK signal.
2196 int MoxaPortIsValid(int port
)
2201 if (moxaChkPort
[port
] == 0)
2206 void MoxaPortEnable(int port
)
2208 unsigned long ofsAddr
;
2209 int MoxaPortLineStatus(int);
2210 short lowwater
= 512;
2212 ofsAddr
= moxaTableAddr
[port
];
2213 writew(lowwater
, ofsAddr
+ Low_water
);
2214 moxaBreakCnt
[port
] = 0;
2215 if ((moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_ISA
) ||
2216 (moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_PCI
)) {
2217 moxafunc(ofsAddr
, FC_SetBreakIrq
, 0);
2219 writew(readw(ofsAddr
+ HostStat
) | WakeupBreak
, ofsAddr
+ HostStat
);
2222 moxafunc(ofsAddr
, FC_SetLineIrq
, Magic_code
);
2223 moxafunc(ofsAddr
, FC_FlushQueue
, 2);
2225 moxafunc(ofsAddr
, FC_EnableCH
, Magic_code
);
2226 MoxaPortLineStatus(port
);
2229 void MoxaPortDisable(int port
)
2231 unsigned long ofsAddr
;
2233 ofsAddr
= moxaTableAddr
[port
];
2234 moxafunc(ofsAddr
, FC_SetFlowCtl
, 0); /* disable flow control */
2235 moxafunc(ofsAddr
, FC_ClrLineIrq
, Magic_code
);
2236 writew(0, ofsAddr
+ HostStat
);
2237 moxafunc(ofsAddr
, FC_DisableCH
, Magic_code
);
2240 long MoxaPortGetMaxBaud(int port
)
2242 if ((moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_ISA
) ||
2243 (moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_PCI
))
2250 long MoxaPortSetBaud(int port
, long baud
)
2252 unsigned long ofsAddr
;
2256 if ((baud
< 50L) || ((max
= MoxaPortGetMaxBaud(port
)) == 0))
2258 ofsAddr
= moxaTableAddr
[port
];
2262 clock
= 614400L; /* for 9.8304 Mhz : max. 38400 bps */
2263 else if (max
== 57600L)
2264 clock
= 691200L; /* for 11.0592 Mhz : max. 57600 bps */
2266 clock
= 921600L; /* for 14.7456 Mhz : max. 115200 bps */
2268 moxafunc(ofsAddr
, FC_SetBaud
, val
);
2270 moxaCurBaud
[port
] = baud
;
2274 int MoxaPortSetTermio(int port
, struct termios
*termio
)
2276 unsigned long ofsAddr
;
2281 if (moxaChkPort
[port
] == 0 || termio
== 0)
2283 ofsAddr
= moxaTableAddr
[port
];
2284 cflag
= termio
->c_cflag
; /* termio->c_cflag */
2286 mode
= termio
->c_cflag
& CSIZE
;
2289 else if (mode
== CS6
)
2291 else if (mode
== CS7
)
2293 else if (mode
== CS8
)
2296 if (termio
->c_cflag
& CSTOPB
) {
2304 if (termio
->c_cflag
& PARENB
) {
2305 if (termio
->c_cflag
& PARODD
)
2312 moxafunc(ofsAddr
, FC_SetDataMode
, (ushort
) mode
);
2314 cflag
&= (CBAUD
| CBAUDEX
);
2316 #define B921600 (B460800+1)
2382 if ((moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_ISA
) ||
2383 (moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_PCI
)) {
2384 if (baud
== 921600L)
2387 MoxaPortSetBaud(port
, baud
);
2389 if (termio
->c_iflag
& (IXON
| IXOFF
| IXANY
)) {
2390 writeb(termio
->c_cc
[VSTART
], ofsAddr
+ FuncArg
);
2391 writeb(termio
->c_cc
[VSTOP
], ofsAddr
+ FuncArg1
);
2392 writeb(FC_SetXonXoff
, ofsAddr
+ FuncCode
);
2393 wait_finish(ofsAddr
);
2399 int MoxaPortGetLineOut(int port
, int *dtrState
, int *rtsState
)
2402 if (!MoxaPortIsValid(port
))
2405 if (moxaLineCtrl
[port
] & DTR_ON
)
2411 if (moxaLineCtrl
[port
] & RTS_ON
)
2419 void MoxaPortLineCtrl(int port
, int dtr
, int rts
)
2421 unsigned long ofsAddr
;
2424 ofsAddr
= moxaTableAddr
[port
];
2430 moxaLineCtrl
[port
] = mode
;
2431 moxafunc(ofsAddr
, FC_LineControl
, mode
);
2434 void MoxaPortFlowCtrl(int port
, int rts
, int cts
, int txflow
, int rxflow
, int txany
)
2436 unsigned long ofsAddr
;
2439 ofsAddr
= moxaTableAddr
[port
];
2442 mode
|= RTS_FlowCtl
;
2444 mode
|= CTS_FlowCtl
;
2451 moxafunc(ofsAddr
, FC_SetFlowCtl
, mode
);
2454 int MoxaPortLineStatus(int port
)
2456 unsigned long ofsAddr
;
2459 ofsAddr
= moxaTableAddr
[port
];
2460 if ((moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_ISA
) ||
2461 (moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_PCI
)) {
2462 moxafunc(ofsAddr
, FC_LineStatus
, 0);
2463 val
= readw(ofsAddr
+ FuncArg
);
2465 val
= readw(ofsAddr
+ FlagStat
) >> 4;
2470 if ((moxaDCDState
[port
] & DCD_oldstate
) == 0)
2471 moxaDCDState
[port
] = (DCD_oldstate
| DCD_changed
);
2473 if (moxaDCDState
[port
] & DCD_oldstate
)
2474 moxaDCDState
[port
] = DCD_changed
;
2480 int MoxaPortDCDChange(int port
)
2484 if (moxaChkPort
[port
] == 0)
2486 n
= moxaDCDState
[port
];
2487 moxaDCDState
[port
] &= ~DCD_changed
;
2492 int MoxaPortDCDON(int port
)
2496 if (moxaChkPort
[port
] == 0)
2498 if (moxaDCDState
[port
] & DCD_oldstate
)
2507 int MoxaDumpMem(int port, unsigned char * buffer, int len)
2510 unsigned long baseAddr,ofsAddr,ofs;
2512 baseAddr = moxaBaseAddr[port / MAX_PORTS_PER_BOARD];
2513 ofs = baseAddr + DynPage_addr + pageofs;
2516 for (i = 0; i < len; i++)
2517 buffer[i] = readb(ofs+i);
2522 int MoxaPortWriteData(int port
, unsigned char * buffer
, int len
)
2527 ushort head
, tx_mask
, spage
, epage
;
2528 ushort pageno
, pageofs
, bufhead
;
2529 unsigned long baseAddr
, ofsAddr
, ofs
;
2531 ofsAddr
= moxaTableAddr
[port
];
2532 baseAddr
= moxaBaseAddr
[port
/ MAX_PORTS_PER_BOARD
];
2533 tx_mask
= readw(ofsAddr
+ TX_mask
);
2534 spage
= readw(ofsAddr
+ Page_txb
);
2535 epage
= readw(ofsAddr
+ EndPage_txb
);
2536 tail
= readw(ofsAddr
+ TXwptr
);
2537 head
= readw(ofsAddr
+ TXrptr
);
2538 c
= (head
> tail
) ? (head
- tail
- 1)
2539 : (head
- tail
+ tx_mask
);
2542 moxaLog
.txcnt
[port
] += c
;
2544 if (spage
== epage
) {
2545 bufhead
= readw(ofsAddr
+ Ofs_txb
);
2546 writew(spage
, baseAddr
+ Control_reg
);
2549 len
= head
- tail
- 1;
2551 len
= tx_mask
+ 1 - tail
;
2552 len
= (c
> len
) ? len
: c
;
2553 ofs
= baseAddr
+ DynPage_addr
+ bufhead
+ tail
;
2554 for (i
= 0; i
< len
; i
++)
2555 writeb(*buffer
++, ofs
+ i
);
2556 tail
= (tail
+ len
) & tx_mask
;
2559 writew(tail
, ofsAddr
+ TXwptr
);
2562 pageno
= spage
+ (tail
>> 13);
2563 pageofs
= tail
& Page_mask
;
2565 cnt
= Page_size
- pageofs
;
2569 writeb(pageno
, baseAddr
+ Control_reg
);
2570 ofs
= baseAddr
+ DynPage_addr
+ pageofs
;
2571 for (i
= 0; i
< cnt
; i
++)
2572 writeb(*buffer
++, ofs
+ i
);
2574 writew((tail
+ len
) & tx_mask
, ofsAddr
+ TXwptr
);
2577 if (++pageno
== epage
)
2582 writeb(1, ofsAddr
+ CD180TXirq
); /* start to send */
2586 int MoxaPortReadData(int port
, unsigned char * buffer
, int space
)
2588 register ushort head
, pageofs
;
2589 int i
, count
, cnt
, len
, total
, remain
;
2590 ushort tail
, rx_mask
, spage
, epage
;
2591 ushort pageno
, bufhead
;
2592 unsigned long baseAddr
, ofsAddr
, ofs
;
2594 ofsAddr
= moxaTableAddr
[port
];
2595 baseAddr
= moxaBaseAddr
[port
/ MAX_PORTS_PER_BOARD
];
2596 head
= readw(ofsAddr
+ RXrptr
);
2597 tail
= readw(ofsAddr
+ RXwptr
);
2598 rx_mask
= readw(ofsAddr
+ RX_mask
);
2599 spage
= readw(ofsAddr
+ Page_rxb
);
2600 epage
= readw(ofsAddr
+ EndPage_rxb
);
2601 count
= (tail
>= head
) ? (tail
- head
)
2602 : (tail
- head
+ rx_mask
+ 1);
2606 total
= (space
> count
) ? count
: space
;
2607 remain
= count
- total
;
2608 moxaLog
.rxcnt
[port
] += total
;
2610 if (spage
== epage
) {
2611 bufhead
= readw(ofsAddr
+ Ofs_rxb
);
2612 writew(spage
, baseAddr
+ Control_reg
);
2617 len
= rx_mask
+ 1 - head
;
2618 len
= (count
> len
) ? len
: count
;
2619 ofs
= baseAddr
+ DynPage_addr
+ bufhead
+ head
;
2620 for (i
= 0; i
< len
; i
++)
2621 *buffer
++ = readb(ofs
+ i
);
2622 head
= (head
+ len
) & rx_mask
;
2625 writew(head
, ofsAddr
+ RXrptr
);
2628 pageno
= spage
+ (head
>> 13);
2629 pageofs
= head
& Page_mask
;
2631 cnt
= Page_size
- pageofs
;
2635 writew(pageno
, baseAddr
+ Control_reg
);
2636 ofs
= baseAddr
+ DynPage_addr
+ pageofs
;
2637 for (i
= 0; i
< cnt
; i
++)
2638 *buffer
++ = readb(ofs
+ i
);
2640 writew((head
+ len
) & rx_mask
, ofsAddr
+ RXrptr
);
2643 if (++pageno
== epage
)
2648 if ((readb(ofsAddr
+ FlagStat
) & Xoff_state
) && (remain
< LowWater
)) {
2649 moxaLowWaterChk
= 1;
2650 moxaLowChkFlag
[port
] = 1;
2656 int MoxaPortTxQueue(int port
)
2658 unsigned long ofsAddr
;
2659 ushort rptr
, wptr
, mask
;
2662 ofsAddr
= moxaTableAddr
[port
];
2663 rptr
= readw(ofsAddr
+ TXrptr
);
2664 wptr
= readw(ofsAddr
+ TXwptr
);
2665 mask
= readw(ofsAddr
+ TX_mask
);
2666 len
= (wptr
- rptr
) & mask
;
2670 int MoxaPortTxFree(int port
)
2672 unsigned long ofsAddr
;
2673 ushort rptr
, wptr
, mask
;
2676 ofsAddr
= moxaTableAddr
[port
];
2677 rptr
= readw(ofsAddr
+ TXrptr
);
2678 wptr
= readw(ofsAddr
+ TXwptr
);
2679 mask
= readw(ofsAddr
+ TX_mask
);
2680 len
= mask
- ((wptr
- rptr
) & mask
);
2684 int MoxaPortRxQueue(int port
)
2686 unsigned long ofsAddr
;
2687 ushort rptr
, wptr
, mask
;
2690 ofsAddr
= moxaTableAddr
[port
];
2691 rptr
= readw(ofsAddr
+ RXrptr
);
2692 wptr
= readw(ofsAddr
+ RXwptr
);
2693 mask
= readw(ofsAddr
+ RX_mask
);
2694 len
= (wptr
- rptr
) & mask
;
2699 void MoxaPortTxDisable(int port
)
2701 unsigned long ofsAddr
;
2703 ofsAddr
= moxaTableAddr
[port
];
2704 moxafunc(ofsAddr
, FC_SetXoffState
, Magic_code
);
2707 void MoxaPortTxEnable(int port
)
2709 unsigned long ofsAddr
;
2711 ofsAddr
= moxaTableAddr
[port
];
2712 moxafunc(ofsAddr
, FC_SetXonState
, Magic_code
);
2716 int MoxaPortResetBrkCnt(int port
)
2719 cnt
= moxaBreakCnt
[port
];
2720 moxaBreakCnt
[port
] = 0;
2725 void MoxaPortSendBreak(int port
, int ms100
)
2727 unsigned long ofsAddr
;
2729 ofsAddr
= moxaTableAddr
[port
];
2731 moxafunc(ofsAddr
, FC_SendBreak
, Magic_code
);
2732 moxadelay(ms100
* (HZ
/ 10));
2734 moxafunc(ofsAddr
, FC_SendBreak
, Magic_code
);
2735 moxadelay(HZ
/ 4); /* 250 ms */
2737 moxafunc(ofsAddr
, FC_StopBreak
, Magic_code
);
2740 static int moxa_get_serial_info(struct moxa_str
*info
,
2741 struct serial_struct
*retinfo
)
2743 struct serial_struct tmp
;
2747 memset(&tmp
, 0, sizeof(tmp
));
2748 tmp
.type
= info
->type
;
2749 tmp
.line
= info
->port
;
2752 tmp
.flags
= info
->asyncflags
;
2753 tmp
.baud_base
= 921600;
2754 tmp
.close_delay
= info
->close_delay
;
2755 tmp
.closing_wait
= info
->closing_wait
;
2756 tmp
.custom_divisor
= 0;
2758 if(copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
2764 static int moxa_set_serial_info(struct moxa_str
*info
,
2765 struct serial_struct
*new_info
)
2767 struct serial_struct new_serial
;
2769 if(copy_from_user(&new_serial
, new_info
, sizeof(new_serial
)))
2772 if ((new_serial
.irq
!= 0) ||
2773 (new_serial
.port
!= 0) ||
2774 // (new_serial.type != info->type) ||
2775 (new_serial
.custom_divisor
!= 0) ||
2776 (new_serial
.baud_base
!= 921600))
2780 if (((new_serial
.flags
& ~ASYNC_USR_MASK
) !=
2781 (info
->asyncflags
& ~ASYNC_USR_MASK
)))
2784 info
->close_delay
= new_serial
.close_delay
* HZ
/ 100;
2785 info
->closing_wait
= new_serial
.closing_wait
* HZ
/ 100;
2788 new_serial
.flags
= (new_serial
.flags
& ~ASYNC_FLAGS
);
2789 new_serial
.flags
|= (info
->asyncflags
& ASYNC_FLAGS
);
2791 if (new_serial
.type
== PORT_16550A
) {
2792 MoxaSetFifo(info
->port
, 1);
2794 MoxaSetFifo(info
->port
, 0);
2797 info
->type
= new_serial
.type
;
2803 /*****************************************************************************
2804 * Static local functions: *
2805 *****************************************************************************/
2807 * moxadelay - delays a specified number ticks
2809 static void moxadelay(int tick
)
2811 unsigned long st
, et
;
2815 while (jiffies
< et
);
2818 static void moxafunc(unsigned long ofsAddr
, int cmd
, ushort arg
)
2821 writew(arg
, ofsAddr
+ FuncArg
);
2822 writew(cmd
, ofsAddr
+ FuncCode
);
2823 wait_finish(ofsAddr
);
2826 static void wait_finish(unsigned long ofsAddr
)
2831 while (readw(ofsAddr
+ FuncCode
) != 0) {
2833 if ((j
- i
) > moxaFuncTout
) {
2839 static void low_water_check(unsigned long ofsAddr
)
2842 ushort rptr
, wptr
, mask
;
2844 if (readb(ofsAddr
+ FlagStat
) & Xoff_state
) {
2845 rptr
= readw(ofsAddr
+ RXrptr
);
2846 wptr
= readw(ofsAddr
+ RXwptr
);
2847 mask
= readw(ofsAddr
+ RX_mask
);
2848 len
= (wptr
- rptr
) & mask
;
2849 if (len
<= Low_water
)
2850 moxafunc(ofsAddr
, FC_SendXon
, 0);
2854 static int moxaloadbios(int cardno
, unsigned char *tmp
, int len
)
2856 unsigned long baseAddr
;
2859 if(copy_from_user(moxaBuff
, tmp
, len
))
2861 baseAddr
= moxaBaseAddr
[cardno
];
2862 writeb(HW_reset
, baseAddr
+ Control_reg
); /* reset */
2863 moxadelay(1); /* delay 10 ms */
2864 for (i
= 0; i
< 4096; i
++)
2865 writeb(0, baseAddr
+ i
); /* clear fix page */
2866 for (i
= 0; i
< len
; i
++)
2867 writeb(moxaBuff
[i
], baseAddr
+ i
); /* download BIOS */
2868 writeb(0, baseAddr
+ Control_reg
); /* restart */
2872 static int moxafindcard(int cardno
)
2874 unsigned long baseAddr
;
2877 baseAddr
= moxaBaseAddr
[cardno
];
2878 switch (moxa_boards
[cardno
].boardType
) {
2879 case MOXA_BOARD_C218_ISA
:
2880 case MOXA_BOARD_C218_PCI
:
2881 if ((tmp
= readw(baseAddr
+ C218_key
)) != C218_KeyCode
) {
2885 case MOXA_BOARD_CP204J
:
2886 if ((tmp
= readw(baseAddr
+ C218_key
)) != CP204J_KeyCode
) {
2891 if ((tmp
= readw(baseAddr
+ C320_key
)) != C320_KeyCode
) {
2894 if ((tmp
= readw(baseAddr
+ C320_status
)) != STS_init
) {
2901 static int moxaload320b(int cardno
, unsigned char * tmp
, int len
)
2903 unsigned long baseAddr
;
2906 if(copy_from_user(moxaBuff
, tmp
, len
))
2908 baseAddr
= moxaBaseAddr
[cardno
];
2909 writew(len
- 7168 - 2, baseAddr
+ C320bapi_len
);
2910 writeb(1, baseAddr
+ Control_reg
); /* Select Page 1 */
2911 for (i
= 0; i
< 7168; i
++)
2912 writeb(moxaBuff
[i
], baseAddr
+ DynPage_addr
+ i
);
2913 writeb(2, baseAddr
+ Control_reg
); /* Select Page 2 */
2914 for (i
= 0; i
< (len
- 7168); i
++)
2915 writeb(moxaBuff
[i
+ 7168], baseAddr
+ DynPage_addr
+ i
);
2919 static int moxaloadcode(int cardno
, unsigned char * tmp
, int len
)
2921 unsigned long baseAddr
, ofsAddr
;
2922 int retval
, port
, i
;
2924 if(copy_from_user(moxaBuff
, tmp
, len
))
2926 baseAddr
= moxaBaseAddr
[cardno
];
2927 switch (moxa_boards
[cardno
].boardType
) {
2928 case MOXA_BOARD_C218_ISA
:
2929 case MOXA_BOARD_C218_PCI
:
2930 case MOXA_BOARD_CP204J
:
2931 retval
= moxaloadc218(cardno
, baseAddr
, len
);
2934 port
= cardno
* MAX_PORTS_PER_BOARD
;
2935 for (i
= 0; i
< moxa_boards
[cardno
].numPorts
; i
++, port
++) {
2936 moxaChkPort
[port
] = 1;
2937 moxaCurBaud
[port
] = 9600L;
2938 moxaDCDState
[port
] = 0;
2939 moxaTableAddr
[port
] = baseAddr
+ Extern_table
+ Extern_size
* i
;
2940 ofsAddr
= moxaTableAddr
[port
];
2941 writew(C218rx_mask
, ofsAddr
+ RX_mask
);
2942 writew(C218tx_mask
, ofsAddr
+ TX_mask
);
2943 writew(C218rx_spage
+ i
* C218buf_pageno
, ofsAddr
+ Page_rxb
);
2944 writew(readw(ofsAddr
+ Page_rxb
) + C218rx_pageno
, ofsAddr
+ EndPage_rxb
);
2946 writew(C218tx_spage
+ i
* C218buf_pageno
, ofsAddr
+ Page_txb
);
2947 writew(readw(ofsAddr
+ Page_txb
) + C218tx_pageno
, ofsAddr
+ EndPage_txb
);
2952 retval
= moxaloadc320(cardno
, baseAddr
, len
,
2953 &moxa_boards
[cardno
].numPorts
);
2956 port
= cardno
* MAX_PORTS_PER_BOARD
;
2957 for (i
= 0; i
< moxa_boards
[cardno
].numPorts
; i
++, port
++) {
2958 moxaChkPort
[port
] = 1;
2959 moxaCurBaud
[port
] = 9600L;
2960 moxaDCDState
[port
] = 0;
2961 moxaTableAddr
[port
] = baseAddr
+ Extern_table
+ Extern_size
* i
;
2962 ofsAddr
= moxaTableAddr
[port
];
2963 if (moxa_boards
[cardno
].numPorts
== 8) {
2964 writew(C320p8rx_mask
, ofsAddr
+ RX_mask
);
2965 writew(C320p8tx_mask
, ofsAddr
+ TX_mask
);
2966 writew(C320p8rx_spage
+ i
* C320p8buf_pgno
, ofsAddr
+ Page_rxb
);
2967 writew(readw(ofsAddr
+ Page_rxb
) + C320p8rx_pgno
, ofsAddr
+ EndPage_rxb
);
2968 writew(C320p8tx_spage
+ i
* C320p8buf_pgno
, ofsAddr
+ Page_txb
);
2969 writew(readw(ofsAddr
+ Page_txb
) + C320p8tx_pgno
, ofsAddr
+ EndPage_txb
);
2971 } else if (moxa_boards
[cardno
].numPorts
== 16) {
2972 writew(C320p16rx_mask
, ofsAddr
+ RX_mask
);
2973 writew(C320p16tx_mask
, ofsAddr
+ TX_mask
);
2974 writew(C320p16rx_spage
+ i
* C320p16buf_pgno
, ofsAddr
+ Page_rxb
);
2975 writew(readw(ofsAddr
+ Page_rxb
) + C320p16rx_pgno
, ofsAddr
+ EndPage_rxb
);
2976 writew(C320p16tx_spage
+ i
* C320p16buf_pgno
, ofsAddr
+ Page_txb
);
2977 writew(readw(ofsAddr
+ Page_txb
) + C320p16tx_pgno
, ofsAddr
+ EndPage_txb
);
2979 } else if (moxa_boards
[cardno
].numPorts
== 24) {
2980 writew(C320p24rx_mask
, ofsAddr
+ RX_mask
);
2981 writew(C320p24tx_mask
, ofsAddr
+ TX_mask
);
2982 writew(C320p24rx_spage
+ i
* C320p24buf_pgno
, ofsAddr
+ Page_rxb
);
2983 writew(readw(ofsAddr
+ Page_rxb
) + C320p24rx_pgno
, ofsAddr
+ EndPage_rxb
);
2984 writew(C320p24tx_spage
+ i
* C320p24buf_pgno
, ofsAddr
+ Page_txb
);
2985 writew(readw(ofsAddr
+ Page_txb
), ofsAddr
+ EndPage_txb
);
2986 } else if (moxa_boards
[cardno
].numPorts
== 32) {
2987 writew(C320p32rx_mask
, ofsAddr
+ RX_mask
);
2988 writew(C320p32tx_mask
, ofsAddr
+ TX_mask
);
2989 writew(C320p32tx_ofs
, ofsAddr
+ Ofs_txb
);
2990 writew(C320p32rx_spage
+ i
* C320p32buf_pgno
, ofsAddr
+ Page_rxb
);
2991 writew(readb(ofsAddr
+ Page_rxb
), ofsAddr
+ EndPage_rxb
);
2992 writew(C320p32tx_spage
+ i
* C320p32buf_pgno
, ofsAddr
+ Page_txb
);
2993 writew(readw(ofsAddr
+ Page_txb
), ofsAddr
+ EndPage_txb
);
3001 static int moxaloadc218(int cardno
, unsigned long baseAddr
, int len
)
3004 int i
, j
, len1
, len2
;
3005 ushort usum
, *ptr
, keycode
;
3007 if (moxa_boards
[cardno
].boardType
== MOXA_BOARD_CP204J
)
3008 keycode
= CP204J_KeyCode
;
3010 keycode
= C218_KeyCode
;
3013 ptr
= (ushort
*) moxaBuff
;
3014 for (i
= 0; i
< len1
; i
++)
3021 len2
= (len1
> 2048) ? 2048 : len1
;
3023 for (i
= 0; i
< len2
<< 1; i
++)
3024 writeb(moxaBuff
[i
+ j
], baseAddr
+ C218_LoadBuf
+ i
);
3027 writew(len2
, baseAddr
+ C218DLoad_len
);
3028 writew(0, baseAddr
+ C218_key
);
3029 for (i
= 0; i
< 100; i
++) {
3030 if (readw(baseAddr
+ C218_key
) == keycode
)
3032 moxadelay(1); /* delay 10 ms */
3034 if (readw(baseAddr
+ C218_key
) != keycode
) {
3038 writew(0, baseAddr
+ C218DLoad_len
);
3039 writew(usum
, baseAddr
+ C218check_sum
);
3040 writew(0, baseAddr
+ C218_key
);
3041 for (i
= 0; i
< 100; i
++) {
3042 if (readw(baseAddr
+ C218_key
) == keycode
)
3044 moxadelay(1); /* delay 10 ms */
3047 } while ((readb(baseAddr
+ C218chksum_ok
) != 1) && (retry
< 3));
3048 if (readb(baseAddr
+ C218chksum_ok
) != 1) {
3051 writew(0, baseAddr
+ C218_key
);
3052 for (i
= 0; i
< 100; i
++) {
3053 if (readw(baseAddr
+ Magic_no
) == Magic_code
)
3055 moxadelay(1); /* delay 10 ms */
3057 if (readw(baseAddr
+ Magic_no
) != Magic_code
) {
3060 writew(1, baseAddr
+ Disable_IRQ
);
3061 writew(0, baseAddr
+ Magic_no
);
3062 for (i
= 0; i
< 100; i
++) {
3063 if (readw(baseAddr
+ Magic_no
) == Magic_code
)
3065 moxadelay(1); /* delay 10 ms */
3067 if (readw(baseAddr
+ Magic_no
) != Magic_code
) {
3071 moxaIntNdx
[cardno
] = baseAddr
+ IRQindex
;
3072 moxaIntPend
[cardno
] = baseAddr
+ IRQpending
;
3073 moxaIntTable
[cardno
] = baseAddr
+ IRQtable
;
3077 static int moxaloadc320(int cardno
, unsigned long baseAddr
, int len
, int *numPorts
)
3080 int i
, j
, wlen
, len2
, retry
;
3085 uptr
= (ushort
*) moxaBuff
;
3086 for (i
= 0; i
< wlen
; i
++)
3098 for (i
= 0; i
< len2
; i
++)
3099 writeb(moxaBuff
[j
+ i
], baseAddr
+ C320_LoadBuf
+ i
);
3102 writew(len2
, baseAddr
+ C320DLoad_len
);
3103 writew(0, baseAddr
+ C320_key
);
3104 for (i
= 0; i
< 10; i
++) {
3105 if (readw(baseAddr
+ C320_key
) == C320_KeyCode
)
3109 if (readw(baseAddr
+ C320_key
) != C320_KeyCode
)
3112 writew(0, baseAddr
+ C320DLoad_len
);
3113 writew(usum
, baseAddr
+ C320check_sum
);
3114 writew(0, baseAddr
+ C320_key
);
3115 for (i
= 0; i
< 10; i
++) {
3116 if (readw(baseAddr
+ C320_key
) == C320_KeyCode
)
3121 } while ((readb(baseAddr
+ C320chksum_ok
) != 1) && (retry
< 3));
3122 if (readb(baseAddr
+ C320chksum_ok
) != 1)
3124 writew(0, baseAddr
+ C320_key
);
3125 for (i
= 0; i
< 600; i
++) {
3126 if (readw(baseAddr
+ Magic_no
) == Magic_code
)
3130 if (readw(baseAddr
+ Magic_no
) != Magic_code
)
3133 if (moxa_boards
[cardno
].busType
== MOXA_BUS_TYPE_PCI
) { /* ASIC board */
3134 writew(0x3800, baseAddr
+ TMS320_PORT1
);
3135 writew(0x3900, baseAddr
+ TMS320_PORT2
);
3136 writew(28499, baseAddr
+ TMS320_CLOCK
);
3138 writew(0x3200, baseAddr
+ TMS320_PORT1
);
3139 writew(0x3400, baseAddr
+ TMS320_PORT2
);
3140 writew(19999, baseAddr
+ TMS320_CLOCK
);
3142 writew(1, baseAddr
+ Disable_IRQ
);
3143 writew(0, baseAddr
+ Magic_no
);
3144 for (i
= 0; i
< 500; i
++) {
3145 if (readw(baseAddr
+ Magic_no
) == Magic_code
)
3149 if (readw(baseAddr
+ Magic_no
) != Magic_code
)
3152 j
= readw(baseAddr
+ Module_cnt
);
3156 writew(j
, baseAddr
+ Module_no
);
3157 writew(0, baseAddr
+ Magic_no
);
3158 for (i
= 0; i
< 600; i
++) {
3159 if (readw(baseAddr
+ Magic_no
) == Magic_code
)
3163 if (readw(baseAddr
+ Magic_no
) != Magic_code
)
3166 moxaIntNdx
[cardno
] = baseAddr
+ IRQindex
;
3167 moxaIntPend
[cardno
] = baseAddr
+ IRQpending
;
3168 moxaIntTable
[cardno
] = baseAddr
+ IRQtable
;
3172 long MoxaPortGetCurBaud(int port
)
3175 if (moxaChkPort
[port
] == 0)
3177 return (moxaCurBaud
[port
]);
3180 static void MoxaSetFifo(int port
, int enable
)
3182 unsigned long ofsAddr
= moxaTableAddr
[port
];
3185 moxafunc(ofsAddr
, FC_SetRxFIFOTrig
, 0);
3186 moxafunc(ofsAddr
, FC_SetTxFIFOCnt
, 1);
3188 moxafunc(ofsAddr
, FC_SetRxFIFOTrig
, 3);
3189 moxafunc(ofsAddr
, FC_SetTxFIFOCnt
, 16);
3194 int MoxaPortSetMode(int port
, int databits
, int stopbits
, int parity
)
3196 unsigned long ofsAddr
;
3219 break; /* stop bits 1.5 */
3248 ofsAddr
= moxaTableAddr
[port
];
3249 moxafunc(ofsAddr
, FC_SetMode
, val
);
3253 int MoxaPortTxBufSize(int port
)
3255 unsigned long ofsAddr
;
3258 ofsAddr
= moxaTableAddr
[port
];
3259 size
= readw(ofsAddr
+ TX_mask
);
3263 int MoxaPortRxBufSize(int port
)
3265 unsigned long ofsAddr
;
3268 ofsAddr
= moxaTableAddr
[port
];
3269 size
= readw(ofsAddr
+ RX_mask
);
3273 int MoxaPortRxFree(int port
)
3275 unsigned long ofsAddr
;
3276 ushort rptr
, wptr
, mask
;
3279 ofsAddr
= moxaTableAddr
[port
];
3280 rptr
= readw(ofsAddr
+ RXrptr
);
3281 wptr
= readw(ofsAddr
+ RXwptr
);
3282 mask
= readw(ofsAddr
+ RX_mask
);
3283 len
= mask
- ((wptr
- rptr
) & mask
);
3286 int MoxaPortGetBrkCnt(int port
)
3288 return (moxaBreakCnt
[port
]);
3291 void MoxaPortSetXonXoff(int port
, int xonValue
, int xoffValue
)
3293 unsigned long ofsAddr
;
3295 ofsAddr
= moxaTableAddr
[port
];
3296 writew(xonValue
, ofsAddr
+ FuncArg
);
3297 writew(xoffValue
, ofsAddr
+ FuncArg1
);
3298 writew(FC_SetXonXoff
, ofsAddr
+ FuncCode
);
3299 wait_finish(ofsAddr
);
3302 int MoxaPortIsTxHold(int port
)
3304 unsigned long ofsAddr
;
3307 ofsAddr
= moxaTableAddr
[port
];
3308 if ((moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_ISA
) ||
3309 (moxa_boards
[port
/ MAX_PORTS_PER_BOARD
].boardType
== MOXA_BOARD_C320_PCI
)) {
3310 moxafunc(ofsAddr
, FC_GetCCSR
, 0);
3311 val
= readw(ofsAddr
+ FuncArg
);
3315 if (readw(ofsAddr
+ FlagStat
) & Tx_flowOff
)