2 * linux/drivers/char/pcxx.c
4 * Written by Troy De Jongh, November, 1994
6 * Copyright (C) 1994,1995 Troy De Jongh
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License.
10 * This driver is for the DigiBoard PC/Xe and PC/Xi line of products.
12 * This driver does NOT support DigiBoard's fastcook FEP option and
13 * does not support the transparent print (i.e. digiprint) option.
15 * This Driver is currently maintained by Christoph Lameter (christoph@lameter.com)
17 * Please contact digi for support issues at digilnux@dgii.com.
18 * Some more information can be found at
19 * http://lameter.com/digi.
21 * 1.5.2 Fall 1995 Bug fixes by David Nugent
22 * 1.5.3 March 9, 1996 Christoph Lameter: Fixed 115.2K Support. Memory
23 * allocation harmonized with 1.3.X Series.
24 * 1.5.4 March 30, 1996 Christoph Lameter: Fixup for 1.3.81. Use init_bh
25 * instead of direct assignment to kernel arrays.
26 * 1.5.5 April 5, 1996 Major device numbers corrected.
27 * Mike McLagan<mike.mclagan@linux.org>: Add setup
28 * variable handling, instead of using the old pcxxconfig.h
29 * 1.5.6 April 16, 1996 Christoph Lameter: Pointer cleanup, macro cleanup.
30 * Call out devices changed to /dev/cudxx.
31 * 1.5.7 July 22, 1996 Martin Mares: CLOCAL fix, pcxe_table clearing.
32 * David Nugent: Bug in pcxe_open.
33 * Brian J. Murrell: Modem Control fixes, Majors correctly assigned
34 * 1.6.1 April 6, 1997 Bernhard Kaindl: fixed virtual memory access for 2.1
35 * i386-kernels and use on other archtitectures, Allowing use
36 * as module, added module parameters, added switch to enable
37 * verbose messages to assist user during card configuration.
38 * Currently only tested on a PC/Xi card, but should work on Xe
40 * 1.6.2 August, 7, 2000: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
41 * get rid of panics, release previously allocated resources
42 * 1.6.3 August, 23, 2000: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
43 * cleaned up wrt verify_area.
44 * Christoph Lameter: Update documentation, email addresses
45 * and URLs. Remove some obsolete code.
49 #include <linux/module.h>
51 #include <linux/ioport.h>
52 #include <linux/errno.h>
53 #include <linux/signal.h>
54 #include <linux/sched.h>
55 #include <linux/timer.h>
56 #include <linux/interrupt.h>
57 #include <linux/tty.h>
58 #include <linux/tty_flip.h>
59 #include <linux/major.h>
60 #include <linux/string.h>
61 #include <linux/fcntl.h>
62 #include <linux/ptrace.h>
63 #include <linux/delay.h>
64 #include <linux/serial.h>
65 #include <linux/tty_driver.h>
66 #include <linux/slab.h>
67 #include <linux/init.h>
70 #include <linux/ctype.h> /* We only need it for parsing the "digi="-line */
73 #include <asm/system.h>
75 #include <asm/uaccess.h>
76 #include <asm/bitops.h>
77 #include <asm/semaphore.h>
79 #define VERSION "1.6.3"
85 #include "digi_bios.h"
88 * Define one default setting if no digi= config line is used.
89 * Default is altpin = disabled, 16 ports, I/O 200h, Memory 0D0000h
91 static struct board_info boards[MAX_DIGI_BOARDS] = { {
92 /* Board is enabled */ ENABLED,
93 /* Type is auto-detected */ 0,
94 /* altping is disabled */ DISABLED,
95 /* number of ports = 16 */ 16,
96 /* io address is 0x200 */ 0x200,
97 /* card memory at 0xd0000 */ 0xd0000,
98 /* first minor device no. */ 0
101 static int verbose = 0;
102 static int debug = 0;
105 /* Variables for insmod */
106 static int io[] = {0, 0, 0, 0};
107 static int membase[] = {0, 0, 0, 0};
108 static int memsize[] = {0, 0, 0, 0};
109 static int altpin[] = {0, 0, 0, 0};
110 static int numports[] = {0, 0, 0, 0};
112 MODULE_AUTHOR("Bernhard Kaindl");
113 MODULE_DESCRIPTION("Digiboard PC/X{i,e,eve} driver");
114 MODULE_LICENSE("GPL");
115 MODULE_PARM(verbose, "i");
116 MODULE_PARM(debug, "i");
117 MODULE_PARM(io, "1-4i");
118 MODULE_PARM(membase, "1-4i");
119 MODULE_PARM(memsize, "1-4i");
120 MODULE_PARM(altpin, "1-4i");
121 MODULE_PARM(numports, "1-4i");
125 static int numcards = 1;
126 static int nbdevs = 0;
128 static struct channel *digi_channels;
130 int pcxx_ncook=sizeof(pcxx_cook);
131 int pcxx_nbios=sizeof(pcxx_bios);
133 #define pcxxassert(x, msg) if(!(x)) pcxx_error(__LINE__, msg)
135 #define FEPTIMEOUT 200000
136 #define SERIAL_TYPE_NORMAL 1
137 #define PCXE_EVENT_HANGUP 1
139 static struct tty_driver *pcxe_driver;
141 static struct timer_list pcxx_timer;
143 static void pcxxpoll(unsigned long dummy);
144 static void fepcmd(struct channel *, int, int, int, int, int);
145 static void pcxe_put_char(struct tty_struct *, unsigned char);
146 static void pcxe_flush_chars(struct tty_struct *);
147 static void pcxx_error(int, char *);
148 static void pcxe_close(struct tty_struct *, struct file *);
149 static int pcxe_ioctl(struct tty_struct *, struct file *, unsigned int, unsigned long);
150 static void pcxe_set_termios(struct tty_struct *, struct termios *);
151 static int pcxe_write(struct tty_struct *, int, const unsigned char *, int);
152 static int pcxe_write_room(struct tty_struct *);
153 static int pcxe_chars_in_buffer(struct tty_struct *);
154 static void pcxe_flush_buffer(struct tty_struct *);
155 static void doevent(int);
156 static void receive_data(struct channel *);
157 static void pcxxparam(struct tty_struct *, struct channel *ch);
158 static void do_softint(void *);
159 static inline void pcxe_sched_event(struct channel *, int);
160 static void pcxe_start(struct tty_struct *);
161 static void pcxe_stop(struct tty_struct *);
162 static void pcxe_throttle(struct tty_struct *);
163 static void pcxe_unthrottle(struct tty_struct *);
164 static void digi_send_break(struct channel *ch, int msec);
165 static void shutdown(struct channel *);
166 static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
167 static inline void memwinon(struct board_info *b, unsigned int win);
168 static inline void memwinoff(struct board_info *b, unsigned int win);
169 static inline void globalwinon(struct channel *ch);
170 static inline void rxwinon(struct channel *ch);
171 static inline void txwinon(struct channel *ch);
172 static inline void memoff(struct channel *ch);
173 static inline void assertgwinon(struct channel *ch);
174 static inline void assertmemoff(struct channel *ch);
175 static int pcxe_tiocmget(struct tty_struct *tty, struct file *file);
176 static int pcxe_tiocmset(struct tty_struct *tty, struct file *file,
177 unsigned int set, unsigned int clear);
179 #define TZ_BUFSZ 4096
181 /* function definitions */
183 /*****************************************************************************/
185 static void cleanup_board_resources(void)
188 struct board_info *bd;
191 for(crd = 0; crd < numcards; crd++) {
193 ch = digi_channels + bd->first_minor;
196 release_region(bd->port, 4);
198 for(i = 0; i < bd->numports; i++, ch++)
204 static void __exit pcxe_cleanup(void)
210 printk(KERN_NOTICE "Unloading PC/Xx version %s\n", VERSION);
214 del_timer_sync(&pcxx_timer);
216 if ((e1 = tty_unregister_driver(pcxe_driver)))
217 printk("SERIAL: failed to unregister serial driver (%d)\n", e1);
219 put_tty_driver(pcxe_driver);
220 cleanup_board_resources();
221 kfree(digi_channels);
222 restore_flags(flags);
225 static inline struct channel *chan(register struct tty_struct *tty)
228 register struct channel *ch=(struct channel *)tty->driver_data;
229 if (ch >= digi_channels && ch < digi_channels+nbdevs) {
230 if (ch->magic==PCXX_MAGIC)
237 /* These inline routines are to turn board memory on and off */
238 static inline void memwinon(struct board_info *b, unsigned int win)
240 if(b->type == PCXEVE)
241 outb_p(FEPWIN|win, b->port+1);
243 outb_p(inb(b->port)|FEPMEM, b->port);
246 static inline void memwinoff(struct board_info *b, unsigned int win)
248 outb_p(inb(b->port)&~FEPMEM, b->port);
249 if(b->type == PCXEVE)
250 outb_p(0, b->port + 1);
253 static inline void globalwinon(struct channel *ch)
255 if(ch->board->type == PCXEVE)
256 outb_p(FEPWIN, ch->board->port+1);
258 outb_p(FEPMEM, ch->board->port);
261 static inline void rxwinon(struct channel *ch)
264 outb_p(FEPMEM, ch->board->port);
266 outb_p(ch->rxwin, ch->board->port+1);
269 static inline void txwinon(struct channel *ch)
272 outb_p(FEPMEM, ch->board->port);
274 outb_p(ch->txwin, ch->board->port+1);
277 static inline void memoff(struct channel *ch)
279 outb_p(0, ch->board->port);
280 if(ch->board->type == PCXEVE)
281 outb_p(0, ch->board->port+1);
284 static inline void assertgwinon(struct channel *ch)
286 if(ch->board->type != PCXEVE)
287 pcxxassert(inb(ch->board->port) & FEPMEM, "Global memory off");
290 static inline void assertmemoff(struct channel *ch)
292 if(ch->board->type != PCXEVE)
293 pcxxassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
296 static inline void pcxe_sched_event(struct channel *info, int event)
298 info->event |= 1 << event;
299 schedule_work(&info->tqueue);
302 static void pcxx_error(int line, char *msg)
304 printk("pcxx_error (DigiBoard): line=%d %s\n", line, msg);
307 static int pcxx_waitcarrier(struct tty_struct *tty,struct file *filp,struct channel *info)
309 DECLARE_WAITQUEUE(wait, current);
313 if (tty->termios->c_cflag & CLOCAL)
317 * Block waiting for the carrier detect and the line to become free
321 add_wait_queue(&info->open_wait, &wait);
323 info->blocked_open++;
328 info->omodem |= DTR|RTS;
329 fepcmd(info, SETMODEM, DTR|RTS, 0, 10, 1);
332 set_current_state(TASK_INTERRUPTIBLE);
333 if(tty_hung_up_p(filp) || (info->asyncflags & ASYNC_INITIALIZED) == 0) {
334 if(info->asyncflags & ASYNC_HUP_NOTIFY)
337 retval = -ERESTARTSYS;
340 if ((info->asyncflags & ASYNC_CLOSING) == 0 &&
341 (do_clocal || (info->imodem & info->dcd)))
343 if(signal_pending(current)) {
344 retval = -ERESTARTSYS;
349 current->state = TASK_RUNNING;
350 remove_wait_queue(&info->open_wait, &wait);
352 if(!tty_hung_up_p(filp))
354 info->blocked_open--;
360 int pcxe_open(struct tty_struct *tty, struct file * filp)
362 volatile struct board_chan *bc;
371 if(line < 0 || line >= nbdevs) {
372 printk("line out of range in pcxe_open\n");
373 tty->driver_data = NULL;
377 for(boardnum=0;boardnum<numcards;boardnum++)
378 if ((line >= boards[boardnum].first_minor) &&
379 (line < boards[boardnum].first_minor + boards[boardnum].numports))
382 if(boardnum >= numcards || boards[boardnum].status == DISABLED ||
383 (line - boards[boardnum].first_minor) >= boards[boardnum].numports) {
384 tty->driver_data = NULL; /* Mark this device as 'down' */
388 ch = digi_channels+line;
390 if(ch->brdchan == 0) {
391 tty->driver_data = NULL;
396 * If the device is in the middle of being closed, then block
397 * until it's done, and then try again.
399 if(ch->asyncflags & ASYNC_CLOSING) {
400 interruptible_sleep_on(&ch->close_wait);
401 if(ch->asyncflags & ASYNC_HUP_NOTIFY)
410 tty->driver_data = ch;
413 if ((ch->asyncflags & ASYNC_INITIALIZED) == 0) {
419 ch->imodem = bc->mstat;
424 ch->imodem = bc->mstat;
426 ch->omodem = DTR|RTS;
427 fepcmd(ch, SETMODEM, DTR|RTS, 0, 10, 1);
429 ch->asyncflags |= ASYNC_INITIALIZED;
431 restore_flags(flags);
433 if(ch->asyncflags & ASYNC_CLOSING) {
434 interruptible_sleep_on(&ch->close_wait);
435 if(ch->asyncflags & ASYNC_HUP_NOTIFY)
441 if (!(filp->f_flags & O_NONBLOCK)) {
442 /* this has to be set in order for the "block until
443 * CD" code to work correctly. i'm not sure under
444 * what circumstances asyncflags should be set to
445 * ASYNC_NORMAL_ACTIVE though
448 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
449 if ((retval = pcxx_waitcarrier(tty, filp, ch)) != 0)
452 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
457 static void shutdown(struct channel *info)
460 volatile struct board_chan *bc;
461 struct tty_struct *tty;
463 if (!(info->asyncflags & ASYNC_INITIALIZED))
477 * If we're a modem control device and HUPCL is on, drop RTS & DTR.
479 if(tty->termios->c_cflag & HUPCL) {
480 info->omodem &= ~(RTS|DTR);
481 fepcmd(info, SETMODEM, 0, DTR|RTS, 10, 1);
485 info->asyncflags &= ~ASYNC_INITIALIZED;
486 restore_flags(flags);
490 static void pcxe_close(struct tty_struct * tty, struct file * filp)
492 struct channel *info;
494 if ((info=chan(tty))!=NULL) {
499 if(tty_hung_up_p(filp)) {
500 /* flag that somebody is done with this module */
501 restore_flags(flags);
504 /* this check is in serial.c, it won't hurt to do it here too */
505 if ((tty->count == 1) && (info->count != 1)) {
507 * Uh, oh. tty->count is 1, which means that the tty
508 * structure will be freed. Info->count should always
509 * be one in these conditions. If it's greater than
510 * one, we've got real problems, since it means the
511 * serial port won't be shutdown.
513 printk("pcxe_close: bad serial port count; tty->count is 1, info->count is %d\n", info->count);
516 if (info->count-- > 1) {
517 restore_flags(flags);
520 if (info->count < 0) {
524 info->asyncflags |= ASYNC_CLOSING;
527 if(info->asyncflags & ASYNC_INITIALIZED) {
528 setup_empty_event(tty,info);
529 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
532 if(tty->driver->flush_buffer)
533 tty->driver->flush_buffer(tty);
534 tty_ldisc_flush(tty);
539 if(info->blocked_open) {
540 if(info->close_delay) {
541 current->state = TASK_INTERRUPTIBLE;
542 schedule_timeout(info->close_delay);
544 wake_up_interruptible(&info->open_wait);
546 info->asyncflags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
547 wake_up_interruptible(&info->close_wait);
548 restore_flags(flags);
553 void pcxe_hangup(struct tty_struct *tty)
557 if ((ch=chan(tty))!=NULL) {
566 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
567 wake_up_interruptible(&ch->open_wait);
568 restore_flags(flags);
574 static int pcxe_write(struct tty_struct * tty, int from_user, const unsigned char *buf, int count)
577 volatile struct board_chan *bc;
578 int total, remain, size, stlen;
579 unsigned int head, tail;
581 /* printk("Entering pcxe_write()\n"); */
583 if ((ch=chan(tty))==NULL)
587 size = ch->txbufsize;
591 down(&ch->tmp_buf_sem);
595 head = bc->tin & (size - 1);
596 /* It seems to be necessary to make sure that the value is stable here somehow
597 This is a rather odd pice of code here. */
601 } while (tail != bc->tout);
604 stlen = (head >= tail) ? (size - (head - tail) - 1) : (tail - head - 1);
605 count = min(stlen, count);
607 restore_flags(flags);
610 if (copy_from_user(ch->tmp_buf, buf, count))
617 * All data is now local
624 head = bc->tin & (size - 1);
626 if (tail != bc->tout)
630 remain = size - (head - tail) - 1;
634 remain = tail - head - 1;
637 count = min(remain, count);
641 stlen = min(count, stlen);
642 memcpy(ch->txptr + head, buf, stlen);
652 ch->statusflags |= TXBUSY;
655 if ((ch->statusflags & LOWWAIT) == 0) {
656 ch->statusflags |= LOWWAIT;
660 restore_flags(flags);
663 up(&ch->tmp_buf_sem);
669 static void pcxe_put_char(struct tty_struct *tty, unsigned char c)
671 pcxe_write(tty, 0, &c, 1);
676 static int pcxe_write_room(struct tty_struct *tty)
682 if ((ch=chan(tty))!=NULL) {
683 volatile struct board_chan *bc;
684 unsigned int head, tail;
692 head = bc->tin & (ch->txbufsize - 1);
694 if (tail != bc->tout)
696 tail &= (ch->txbufsize - 1);
698 if((remain = tail - head - 1) < 0 )
699 remain += ch->txbufsize;
701 if (remain && (ch->statusflags & LOWWAIT) == 0) {
702 ch->statusflags |= LOWWAIT;
706 restore_flags(flags);
713 static int pcxe_chars_in_buffer(struct tty_struct *tty)
716 unsigned int ctail, head, tail;
720 volatile struct board_chan *bc;
722 if ((ch=chan(tty))==NULL)
732 ctail = ch->mailbox->cout;
733 if(tail == head && ch->mailbox->cin == ctail && bc->tbusy == 0)
736 head = bc->tin & (ch->txbufsize - 1);
737 tail &= (ch->txbufsize - 1);
738 if((remain = tail - head - 1) < 0 )
739 remain += ch->txbufsize;
741 chars = (int)(ch->txbufsize - remain);
744 * Make it possible to wakeup anything waiting for output
745 * in tty_ioctl.c, etc.
747 if(!(ch->statusflags & EMPTYWAIT))
748 setup_empty_event(tty,ch);
752 restore_flags(flags);
758 static void pcxe_flush_buffer(struct tty_struct *tty)
761 volatile struct board_chan *bc;
765 if ((ch=chan(tty))==NULL)
774 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
777 restore_flags(flags);
782 static void pcxe_flush_chars(struct tty_struct *tty)
786 if ((ch=chan(tty))!=NULL) {
791 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
792 setup_empty_event(tty,ch);
793 restore_flags(flags);
800 * Driver setup function when linked into the kernel to optionally parse multible
801 * "digi="-lines and initialize the driver at boot time. No probing.
803 void __init pcxx_setup(char *str, int *ints)
806 struct board_info board;
813 memset(&board, 0, sizeof(board));
815 for(last=0,i=1;i<=ints[0];i++)
819 board.status = ints[i];
824 board.type = ints[i];
829 board.altpin = ints[i];
834 board.numports = ints[i];
839 board.port = ints[i];
844 board.membase = ints[i];
849 printk("PC/Xx: Too many integer parms\n");
855 /* find the next comma or terminator */
857 while (*temp && (*temp != ','))
871 if (strncmp("Disable", str, len) == 0)
874 if (strncmp("Enable", str, len) == 0)
878 printk("PC/Xx: Invalid status %s\n", str);
885 for(j=0;j<PCXX_NUM_TYPES;j++)
886 if (strcmp(board_desc[j], str) == 0)
889 if (i<PCXX_NUM_TYPES)
893 printk("PC/Xx: Invalid board name: %s\n", str);
901 if (strncmp("Disable", str, len) == 0)
904 if (strncmp("Enable", str, len) == 0)
908 printk("PC/Xx: Invalid altpin %s\n", str);
921 printk("PC/Xx: Invalid port count %s\n", str);
925 board.numports = simple_strtoul(str, NULL, 0);
931 while (isxdigit(*t2))
936 printk("PC/Xx: Invalid io port address %s\n", str);
940 board.port = simple_strtoul(str, NULL, 16);
946 while (isxdigit(*t2))
951 printk("PC/Xx: Invalid memory base %s\n", str);
955 board.membase = simple_strtoul(str, NULL, 16);
960 printk("PC/Xx: Too many string parms\n");
968 printk("PC/Xx: Insufficient parms specified\n");
972 /* I should REALLY validate the stuff here */
974 memcpy(&boards[numcards],&board, sizeof(board));
975 printk("PC/Xx: Added board %i, %s %s %i ports at 0x%4.4X base 0x%6.6X\n",
976 numcards, board_desc[board.type], board_mem[board.type],
977 board.numports, board.port, (unsigned int) board.membase);
979 /* keep track of my initial minor number */
981 boards[numcards].first_minor = boards[numcards-1].first_minor + boards[numcards-1].numports;
983 boards[numcards].first_minor = 0;
985 /* yeha! string parameter was successful! */
990 static struct tty_operations pcxe_ops = {
994 .put_char = pcxe_put_char,
995 .flush_chars = pcxe_flush_chars,
996 .write_room = pcxe_write_room,
997 .chars_in_buffer = pcxe_chars_in_buffer,
998 .flush_buffer = pcxe_flush_buffer,
1000 .throttle = pcxe_throttle,
1001 .unthrottle = pcxe_unthrottle,
1002 .set_termios = pcxe_set_termios,
1004 .start = pcxe_start,
1005 .hangup = pcxe_hangup,
1006 .tiocmget = pcxe_tiocmget,
1007 .tiocmset = pcxe_tiocmset,
1011 * function to initialize the driver with the given parameters, which are either
1012 * the default values from this file or the parameters given at boot.
1014 static int __init pcxe_init(void)
1016 ulong memory_seg=0, memory_size=0;
1017 int lowwater, enabled_cards=0, i, crd, shrinkmem=0, topwin = 0xff00L, botwin=0x100L;
1019 unchar *fepos, *memaddr, *bios, v;
1020 volatile struct global_data *gd;
1021 volatile struct board_chan *bc;
1022 struct board_info *bd;
1025 printk(KERN_NOTICE "Digiboard PC/X{i,e,eve} driver v%s\n", VERSION);
1028 for (i = 0; i < MAX_DIGI_BOARDS; i++) {
1034 if (numcards == 0) {
1035 int first_minor = 0;
1037 for (i = 0; i < MAX_DIGI_BOARDS; i++) {
1040 boards[i].status = DISABLED;
1043 boards[i].port = (ushort)io[i];
1044 boards[i].status = ENABLED;
1045 boards[i].first_minor = first_minor;
1049 boards[i].membase = (ulong)membase[i];
1051 boards[i].membase = 0xD0000;
1054 boards[i].memsize = (ulong)(memsize[i] * 1024);
1056 boards[i].memsize = 0;
1059 boards[i].altpin = ON;
1061 boards[i].altpin = OFF;
1064 boards[i].numports = (ushort)numports[i];
1066 boards[i].numports = 16;
1068 boards[i].region = NULL;
1069 first_minor += boards[i].numports;
1076 printk("PC/Xx: No cards configured, driver not active.\n");
1081 for (i = 0; i < numcards; i++) {
1082 printk("Card %d:status=%d, port=0x%x, membase=0x%lx, memsize=0x%lx, altpin=%d, numports=%d, first_minor=%d\n",
1090 boards[i].first_minor);
1094 for (i=0;i<numcards;i++)
1095 nbdevs += boards[i].numports;
1099 printk("PC/Xx: No devices activated, driver not active.\n");
1103 pcxe_driver = alloc_tty_driver(nbdevs);
1108 * this turns out to be more memory efficient, as there are no
1111 digi_channels = kmalloc(sizeof(struct channel) * nbdevs, GFP_KERNEL);
1112 if (!digi_channels) {
1113 printk(KERN_ERR "Unable to allocate digi_channel struct\n");
1114 put_tty_driver(pcxe_driver);
1117 memset(digi_channels, 0, sizeof(struct channel) * nbdevs);
1119 init_timer(&pcxx_timer);
1120 pcxx_timer.function = pcxxpoll;
1122 pcxe_driver->owner = THIS_MODULE;
1123 pcxe_driver->name = "ttyD";
1124 pcxe_driver->devfs_name = "pcxe/";
1125 pcxe_driver->major = DIGI_MAJOR;
1126 pcxe_driver->minor_start = 0;
1127 pcxe_driver->type = TTY_DRIVER_TYPE_SERIAL;
1128 pcxe_driver->subtype = SERIAL_TYPE_NORMAL;
1129 pcxe_driver->init_termios = tty_std_termios;
1130 pcxe_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1131 pcxe_driver->flags = TTY_DRIVER_REAL_RAW;
1132 tty_set_operations(pcxe_driver, &pcxe_ops);
1134 for(crd=0; crd < numcards; crd++) {
1136 outb(FEPRST, bd->port);
1139 for(i=0; (inb(bd->port) & FEPMASK) != FEPRST; i++) {
1141 printk("PC/Xx: Board not found at port 0x%x! Check switch settings.\n",
1143 bd->status = DISABLED;
1151 if(bd->status == DISABLED)
1156 if((v & 0x1) == 0x1) {
1157 if((v & 0x30) == 0) { /* PC/Xi 64K card */
1158 memory_seg = 0xf000;
1159 memory_size = 0x10000;
1162 if((v & 0x30) == 0x10) { /* PC/Xi 128K card */
1163 memory_seg = 0xe000;
1164 memory_size = 0x20000;
1167 if((v & 0x30) == 0x20) { /* PC/Xi 256K card */
1168 memory_seg = 0xc000;
1169 memory_size = 0x40000;
1172 if((v & 0x30) == 0x30) { /* PC/Xi 512K card */
1173 memory_seg = 0x8000;
1174 memory_size = 0x80000;
1178 if((v & 0x1) == 0x1) {
1179 bd->status = DISABLED; /* PC/Xm unsupported card */
1180 printk("PC/Xx: PC/Xm at 0x%x not supported!!\n", bd->port);
1185 outb((((ulong)bd->membase>>8) & 0xe0) | 0x10, bd->port+2);
1186 outb(((ulong)bd->membase>>16) & 0xff, bd->port+3);
1187 bd->type = PCXEVE; /* PC/Xe 8K card */
1189 bd->type = PCXE; /* PC/Xe 64K card */
1192 memory_seg = 0xf000;
1193 memory_size = 0x10000;
1197 printk("Configuring card %d as a %s %ldK card. io=0x%x, mem=%lx-%lx\n",
1198 crd+1, board_desc[bd->type], memory_size/1024,
1199 bd->port,bd->membase,bd->membase+memory_size-1);
1201 if (boards[crd].memsize == 0)
1202 boards[crd].memsize = memory_size;
1204 if (boards[crd].memsize != memory_size) {
1205 printk("PC/Xx: memory size mismatch:supplied=%lx(%ldK) probed=%ld(%ldK)\n",
1206 boards[crd].memsize, boards[crd].memsize / 1024,
1207 memory_size, memory_size / 1024);
1211 memaddr = (unchar *)phys_to_virt(bd->membase);
1214 printk("Resetting board and testing memory access:");
1216 outb(FEPRST|FEPMEM, bd->port);
1218 for(i=0; (inb(bd->port) & FEPMASK) != (FEPRST|FEPMEM); i++) {
1220 printk("\nPC/Xx: %s not resetting at port 0x%x! Check switch settings.\n",
1221 board_desc[bd->type], bd->port);
1222 bd->status = DISABLED;
1230 if(bd->status == DISABLED)
1234 *(ulong *)(memaddr + botwin) = 0xa55a3cc3;
1235 *(ulong *)(memaddr + topwin) = 0x5aa5c33c;
1237 if(*(ulong *)(memaddr + botwin) != 0xa55a3cc3 ||
1238 *(ulong *)(memaddr + topwin) != 0x5aa5c33c) {
1239 printk("PC/Xx: Failed memory test at %lx for %s at port %x, check switch settings.\n",
1240 bd->membase, board_desc[bd->type], bd->port);
1241 bd->status = DISABLED;
1247 for(i=0; i < 16; i++) {
1248 memaddr[MISCGLOBAL+i] = 0;
1251 if(bd->type == PCXI || bd->type == PCXE) {
1252 bios = memaddr + BIOSCODE + ((0xf000 - memory_seg) << 4);
1255 printk("Downloading BIOS to 0x%lx:", virt_to_phys(bios));
1257 memcpy(bios, pcxx_bios, pcxx_nbios);
1262 outb(FEPMEM, bd->port);
1265 printk("Waiting for BIOS to become ready");
1267 for(i=1; i <= 30; i++) {
1268 if(*(ushort *)((ulong)memaddr + MISCGLOBAL) == *(ushort *)"GD" ) {
1282 printk("\nPC/Xx: BIOS download failed for board at 0x%x(addr=%lx-%lx)!\n",
1283 bd->port, bd->membase, bd->membase+bd->memsize);
1284 bd->status = DISABLED;
1288 if(bd->type == PCXEVE) {
1289 bios = memaddr + (BIOSCODE & 0x1fff);
1292 memcpy(bios, pcxx_bios, pcxx_nbios);
1294 outb(FEPCLR, bd->port);
1297 for(i=0; i <= 1000; i++) {
1298 if(*(ushort *)((ulong)memaddr + MISCGLOBAL) == *(ushort *)"GD" ) {
1312 printk("\nPC/Xx: BIOS download failed on the %s at 0x%x!\n",
1313 board_desc[bd->type], bd->port);
1314 bd->status = DISABLED;
1319 fepos = memaddr + FEPCODE;
1320 if(bd->type == PCXEVE)
1321 fepos = memaddr + (FEPCODE & 0x1fff);
1324 printk(" ok.\nDownloading FEP/OS to 0x%lx:", virt_to_phys(fepos));
1326 memwinon(bd, (FEPCODE >> 13));
1327 memcpy(fepos, pcxx_cook, pcxx_ncook);
1333 *(ushort *)((ulong)memaddr + MBOX + 0) = 2;
1334 *(ushort *)((ulong)memaddr + MBOX + 2) = memory_seg + FEPCODESEG;
1335 *(ushort *)((ulong)memaddr + MBOX + 4) = 0;
1336 *(ushort *)((ulong)memaddr + MBOX + 6) = FEPCODESEG;
1337 *(ushort *)((ulong)memaddr + MBOX + 8) = 0;
1338 *(ushort *)((ulong)memaddr + MBOX + 10) = pcxx_ncook;
1340 outb(FEPMEM|FEPINT, bd->port);
1341 outb(FEPMEM, bd->port);
1343 for(i=0; *(ushort *)((ulong)memaddr + MBOX); i++) {
1345 printk("PC/Xx: Command failed for the %s at 0x%x!\n",
1346 board_desc[bd->type], bd->port);
1347 bd->status = DISABLED;
1356 if(bd->status == DISABLED)
1360 printk("Waiting for FEP/OS to become ready");
1362 *(ushort *)(memaddr + FEPSTAT) = 0;
1363 *(ushort *)(memaddr + MBOX + 0) = 1;
1364 *(ushort *)(memaddr + MBOX + 2) = FEPCODESEG;
1365 *(ushort *)(memaddr + MBOX + 4) = 0x4L;
1367 outb(FEPINT, bd->port);
1368 outb(FEPCLR, bd->port);
1371 for(i=1; *(ushort *)((ulong)memaddr + FEPSTAT) != *(ushort *)"OS"; i++) {
1373 printk("\nPC/Xx: FEP/OS download failed on the %s at 0x%x!\n",
1374 board_desc[bd->type], bd->port);
1375 bd->status = DISABLED;
1381 printk("\n%5d",i/50);
1388 if(bd->status == DISABLED)
1394 ch = digi_channels+bd->first_minor;
1395 pcxxassert(ch < digi_channels+nbdevs, "ch out of range");
1397 bc = (volatile struct board_chan *)((ulong)memaddr + CHANSTRUCT);
1398 gd = (volatile struct global_data *)((ulong)memaddr + GLOBAL);
1400 if((bd->type == PCXEVE) && (*(ushort *)((ulong)memaddr+NPORT) < 3))
1403 bd->region = request_region(bd->port, 4, "PC/Xx");
1406 printk(KERN_ERR "I/O port 0x%x is already used\n", bd->port);
1408 goto cleanup_boards;
1411 for(i=0; i < bd->numports; i++, ch++, bc++) {
1412 if(((ushort *)((ulong)memaddr + PORTBASE))[i] == 0) {
1418 INIT_WORK(&ch->tqueue, do_softint, ch);
1419 ch->board = &boards[crd];
1420 #ifdef DEFAULT_HW_FLOW
1421 ch->digiext.digi_flags = RTSPACE|CTSPACE;
1423 if(boards[crd].altpin) {
1426 ch->digiext.digi_flags |= DIGI_ALTPIN;
1432 ch->magic = PCXX_MAGIC;
1436 ch->dev = bd->first_minor + i;
1440 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1444 if(bd->type != PCXEVE) {
1445 ch->txptr = memaddr+((bc->tseg-memory_seg) << 4);
1446 ch->rxptr = memaddr+((bc->rseg-memory_seg) << 4);
1447 ch->txwin = ch->rxwin = 0;
1449 ch->txptr = memaddr+(((bc->tseg-memory_seg) << 4) & 0x1fff);
1450 ch->txwin = FEPWIN | ((bc->tseg-memory_seg) >> 9);
1451 ch->rxptr = memaddr+(((bc->rseg-memory_seg) << 4) & 0x1fff);
1452 ch->rxwin = FEPWIN | ((bc->rseg-memory_seg) >>9 );
1455 ch->txbufsize = bc->tmax + 1;
1456 ch->rxbufsize = bc->rmax + 1;
1457 ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL);
1458 init_MUTEX(&ch->tmp_buf_sem);
1461 printk(KERN_ERR "Unable to allocate memory for temp buffers\n");
1462 goto cleanup_boards;
1465 lowwater = ch->txbufsize >= 2000 ? 1024 : ch->txbufsize/2;
1466 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1467 fepcmd(ch, SRXLWATER, ch->rxbufsize/4, 0, 10, 0);
1468 fepcmd(ch, SRXHWATER, 3 * ch->rxbufsize/4, 0, 10, 0);
1473 ch->startc = bc->startc;
1474 ch->stopc = bc->stopc;
1475 ch->startca = bc->startca;
1476 ch->stopca = bc->stopca;
1486 ch->close_delay = 50;
1488 ch->blocked_open = 0;
1489 init_waitqueue_head(&ch->open_wait);
1490 init_waitqueue_head(&ch->close_wait);
1495 printk("Card No. %d ready: %s (%s) I/O=0x%x Mem=0x%lx Ports=%d\n",
1496 crd+1, board_desc[bd->type], board_mem[bd->type], bd->port,
1497 bd->membase, bd->numports);
1499 printk("PC/Xx: %s (%s) I/O=0x%x Mem=0x%lx Ports=%d\n",
1500 board_desc[bd->type], board_mem[bd->type], bd->port,
1501 bd->membase, bd->numports);
1507 if (enabled_cards <= 0) {
1508 printk(KERN_NOTICE "PC/Xx: No cards enabled, no driver.\n");
1510 goto cleanup_boards;
1513 ret = tty_register_driver(pcxe_driver);
1515 printk(KERN_ERR "Couldn't register PC/Xe driver\n");
1516 goto cleanup_boards;
1520 * Start up the poller to check for events on all enabled boards
1522 mod_timer(&pcxx_timer, HZ/25);
1525 printk(KERN_NOTICE "PC/Xx: Driver with %d card(s) ready.\n", enabled_cards);
1529 cleanup_board_resources();
1530 kfree(digi_channels);
1531 put_tty_driver(pcxe_driver);
1535 module_init(pcxe_init)
1536 module_exit(pcxe_cleanup)
1538 static void pcxxpoll(unsigned long dummy)
1540 unsigned long flags;
1542 volatile unsigned int head, tail;
1544 struct board_info *bd;
1549 for(crd=0; crd < numcards; crd++) {
1552 ch = digi_channels+bd->first_minor;
1554 if(bd->status == DISABLED)
1560 head = ch->mailbox->ein;
1561 tail = ch->mailbox->eout;
1569 mod_timer(&pcxx_timer, jiffies + HZ/25);
1570 restore_flags(flags);
1573 static void doevent(int crd)
1575 volatile struct board_info *bd;
1576 static struct tty_struct *tty;
1577 volatile struct board_chan *bc;
1578 volatile unchar *eventbuf;
1579 volatile unsigned int head;
1580 volatile unsigned int tail;
1582 struct channel *chan0;
1583 int channel, event, mstat, lstat;
1587 chan0 = digi_channels+bd->first_minor;
1588 pcxxassert(chan0 < digi_channels+nbdevs, "ch out of range");
1591 assertgwinon(chan0);
1593 while ((tail = chan0->mailbox->eout) != (head = chan0->mailbox->ein)) {
1594 assertgwinon(chan0);
1595 eventbuf = (volatile unchar *)phys_to_virt(bd->membase + tail + ISTART);
1596 channel = eventbuf[0];
1597 event = eventbuf[1];
1598 mstat = eventbuf[2];
1599 lstat = eventbuf[3];
1603 if ((unsigned)channel >= bd->numports || !ch) {
1604 printk("physmem=%lx, tail=%x, head=%x\n", bd->membase, tail, head);
1605 printk("doevent(%x) channel %x, event %x, mstat %x, lstat %x\n",
1606 crd, (unsigned)channel, event, (unsigned)mstat, lstat);
1607 if(channel >= bd->numports)
1612 if ((bc = ch->brdchan) == NULL)
1615 if (event & DATA_IND) {
1620 if (event & MODEMCHG_IND) {
1622 if (ch->asyncflags & ASYNC_NORMAL_ACTIVE) {
1623 if (ch->asyncflags & ASYNC_CHECK_CD) {
1624 if (mstat & ch->dcd) {
1625 wake_up_interruptible(&ch->open_wait);
1627 pcxe_sched_event(ch, PCXE_EVENT_HANGUP);
1637 if (event & BREAK_IND) {
1639 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
1640 *tty->flip.char_buf_ptr++ = 0;
1642 if (ch->asyncflags & ASYNC_SAK)
1645 tty_schedule_flip(tty);
1648 if (event & LOWTX_IND) {
1649 if (ch->statusflags & LOWWAIT) {
1650 ch->statusflags &= ~LOWWAIT;
1655 if (event & EMPTYTX_IND) {
1656 ch->statusflags &= ~TXBUSY;
1657 if (ch->statusflags & EMPTYWAIT) {
1658 ch->statusflags &= ~EMPTYWAIT;
1666 if(!bc) printk("bc == NULL in doevent!\n");
1669 chan0->mailbox->eout = (tail+4) & (IMAX-ISTART-4);
1677 fepcmd(struct channel *ch, int cmd, int word_or_byte, int byte2, int ncmds,
1681 unsigned int head, tail;
1685 if(ch->board->status == DISABLED)
1690 memaddr = (unchar *)phys_to_virt(ch->board->membase);
1691 head = ch->mailbox->cin;
1693 if(head >= (CMAX-CSTART) || (head & 03)) {
1694 printk("line %d: Out of range, cmd=%x, head=%x\n", __LINE__, cmd, head);
1699 *(unchar *)(memaddr+head+CSTART+0) = cmd;
1701 *(unchar *)(memaddr+head+CSTART+1) = ch->dev - ch->board->first_minor;
1703 *(unchar *)(memaddr+head+CSTART+2) = word_or_byte;
1704 *(unchar *)(memaddr+head+CSTART+3) = byte2;
1706 *(unchar *)(memaddr+head+CSTART+0) = cmd;
1708 *(unchar *)(memaddr+head+CSTART+1) = ch->dev - ch->board->first_minor;
1709 *(ushort*)(memaddr+head+CSTART+2) = word_or_byte;
1712 head = (head+4) & (CMAX-CSTART-4);
1713 ch->mailbox->cin = head;
1720 printk("Fep not responding in fepcmd()\n");
1724 head = ch->mailbox->cin;
1725 tail = ch->mailbox->cout;
1727 n = (head-tail) & (CMAX-CSTART-4);
1729 if(n <= ncmds * (sizeof(short)*4))
1731 /* Seems not to be good here: schedule(); */
1736 static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
1739 if (cflag & CBAUDEX)
1741 ch->digiext.digi_flags |= DIGI_FAST;
1743 /* This gets strange but if we don't do this we will get 78600
1744 * instead of 115200. 57600 is mapped to 50 baud yielding 57600 in
1745 * FAST mode. 115200 is mapped to 75. We need to map it to 110 to
1748 if (cflag & B115200) res|=1;
1750 else ch->digiext.digi_flags &= ~DIGI_FAST;
1751 res |= cflag & (CBAUD | PARODD | PARENB | CSTOPB | CSIZE | CLOCAL);
1755 static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
1757 unsigned res = iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|ISTRIP|IXON|IXANY|IXOFF);
1759 if(ch->digiext.digi_flags & DIGI_AIXON)
1764 static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
1768 if(cflag & CRTSCTS) {
1769 ch->digiext.digi_flags |= (RTSPACE|CTSPACE);
1772 if(ch->digiext.digi_flags & RTSPACE)
1774 if(ch->digiext.digi_flags & DTRPACE)
1776 if(ch->digiext.digi_flags & CTSPACE)
1778 if(ch->digiext.digi_flags & DSRPACE)
1780 if(ch->digiext.digi_flags & DCDPACE)
1784 ch->digiext.digi_flags |= RTSPACE;
1786 ch->digiext.digi_flags |= CTSPACE;
1791 static void pcxxparam(struct tty_struct *tty, struct channel *ch)
1793 volatile struct board_chan *bc;
1795 unsigned mval, hflow, cflag, iflag;
1802 if((ts->c_cflag & CBAUD) == 0) {
1806 fepcmd(ch, STOUT, (unsigned) head, 0, 0, 0);
1810 cflag = termios2digi_c(ch, ts->c_cflag);
1812 if(cflag != ch->fepcflag) {
1813 ch->fepcflag = cflag;
1814 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
1818 ch->asyncflags &= ~ASYNC_CHECK_CD;
1820 ch->asyncflags |= ASYNC_CHECK_CD;
1826 iflag = termios2digi_i(ch, ts->c_iflag);
1828 if(iflag != ch->fepiflag) {
1829 ch->fepiflag = iflag;
1830 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
1834 if((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
1835 if(ch->digiext.digi_flags & DIGI_FORCEDCD)
1838 ch->imodem = bc->mstat;
1840 hflow = termios2digi_h(ch, ts->c_cflag);
1842 if(hflow != ch->hflow) {
1844 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
1847 /* mval ^= ch->modemfake & (mval ^ ch->modem); */
1849 if(ch->omodem != mval) {
1851 fepcmd(ch, SETMODEM, mval, RTS|DTR, 0, 1);
1854 if(ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
1855 ch->fepstartc = ch->startc;
1856 ch->fepstopc = ch->stopc;
1857 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
1860 if(ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
1861 ch->fepstartca = ch->startca;
1862 ch->fepstopca = ch->stopca;
1863 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
1868 static void receive_data(struct channel *ch)
1870 volatile struct board_chan *bc;
1871 struct tty_struct *tty;
1872 unsigned int tail, head, wrapmask;
1875 struct termios *ts=0;
1882 if (ch->statusflags & RXSTOPPED)
1892 printk("bc is NULL in receive_data!\n");
1896 wrapmask = ch->rxbufsize - 1;
1900 tail = bc->rout & wrapmask;
1902 n = (head-tail) & wrapmask;
1908 * If CREAD bit is off or device not open, set TX tail to head
1910 if(!tty || !ts || !(ts->c_cflag & CREAD)) {
1915 if(tty->flip.count == TTY_FLIPBUF_SIZE) {
1916 /* printk("tty->flip.count = TTY_FLIPBUF_SIZE\n"); */
1922 printk("overrun! DigiBoard device %s\n", tty->name);
1926 rptr = tty->flip.char_buf_ptr;
1927 rc = tty->flip.count;
1929 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
1930 piece = (wrapgap < n) ? wrapgap : n;
1933 * Make sure we don't overflow the buffer
1936 if ((rc + piece) > TTY_FLIPBUF_SIZE)
1937 piece = TTY_FLIPBUF_SIZE - rc;
1942 memcpy(rptr, ch->rxptr + tail, piece);
1945 tail = (tail + piece) & wrapmask;
1948 tty->flip.count = rc;
1949 tty->flip.char_buf_ptr = rptr;
1953 /* Must be called with global data */
1954 tty_schedule_flip(ch->tty);
1959 static int pcxe_tiocmget(struct tty_struct *tty, struct file *file)
1961 struct channel *ch = (struct channel *) tty->driver_data;
1962 volatile struct board_chan *bc;
1963 unsigned long flags;
1970 printk("ch is NULL in %s!\n", __FUNCTION__);
1979 restore_flags(flags);
1998 static int pcxe_tiocmset(struct tty_struct *tty, struct file *file,
1999 unsigned int set, unsigned int clear)
2001 struct channel *ch = (struct channel *) tty->driver_data;
2002 volatile struct board_chan *bc;
2003 unsigned long flags;
2008 printk("ch is NULL in %s!\n", __FUNCTION__);
2015 * I think this modemfake stuff is broken. It doesn't
2016 * correctly reflect the behaviour desired by the TIOCM*
2017 * ioctls. Therefore this is probably broken.
2019 if (set & TIOCM_DTR) {
2020 ch->modemfake |= DTR;
2023 if (set & TIOCM_RTS) {
2024 ch->modemfake |= RTS;
2028 if (clear & TIOCM_DTR) {
2029 ch->modemfake |= DTR;
2032 if (clear & TIOCM_RTS) {
2033 ch->modemfake |= RTS;
2039 restore_flags(flags);
2044 static int pcxe_ioctl(struct tty_struct *tty, struct file * file,
2045 unsigned int cmd, unsigned long arg)
2047 struct channel *ch = (struct channel *) tty->driver_data;
2048 volatile struct board_chan *bc;
2050 unsigned int mflag, mstat;
2051 unsigned char startc, stopc;
2052 unsigned long flags;
2058 printk("ch is NULL in pcxe_ioctl!\n");
2065 case TCSBRK: /* SVID version: non-zero arg --> no break */
2066 retval = tty_check_change(tty);
2069 setup_empty_event(tty,ch);
2070 tty_wait_until_sent(tty, 0);
2072 digi_send_break(ch, HZ/4); /* 1/4 second */
2075 case TCSBRKP: /* support for POSIX tcsendbreak() */
2076 retval = tty_check_change(tty);
2079 setup_empty_event(tty,ch);
2080 tty_wait_until_sent(tty, 0);
2081 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
2085 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned int *)arg);
2090 if (get_user(value, (unsigned int *) arg))
2092 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (value ? CLOCAL : 0));
2097 mflag = pcxe_tiocmget(tty, file);
2098 if (put_user(mflag, (unsigned int *) arg))
2103 if (get_user(mstat, (unsigned int *) arg))
2105 return pcxe_tiocmset(tty, file, mstat, ~mstat);
2111 fepcmd(ch, SETMODEM, DTR, 0, 10, 1);
2113 restore_flags(flags);
2120 fepcmd(ch, SETMODEM, 0, DTR, 10, 1);
2122 restore_flags(flags);
2126 if (copy_to_user((char*)arg, &ch->digiext, sizeof(digi_t)))
2132 if(cmd == DIGI_SETAW) {
2133 setup_empty_event(tty,ch);
2134 tty_wait_until_sent(tty, 0);
2137 tty_ldisc_flush(tty);
2143 if (copy_from_user(&ch->digiext, (char*)arg, sizeof(digi_t)))
2146 printk("ioctl(DIGI_SETA): flags = %x\n", ch->digiext.digi_flags);
2149 if(ch->digiext.digi_flags & DIGI_ALTPIN) {
2161 restore_flags(flags);
2168 if(cmd == DIGI_GETFLOW) {
2169 dflow.startc = bc->startc;
2170 dflow.stopc = bc->stopc;
2172 dflow.startc = bc->startca;
2173 dflow.stopc = bc->stopca;
2176 restore_flags(flags);
2178 if (copy_to_user((char*)arg, &dflow, sizeof(dflow)))
2184 if(cmd == DIGI_SETFLOW) {
2185 startc = ch->startc;
2188 startc = ch->startca;
2192 if (copy_from_user(&dflow, (char*)arg, sizeof(dflow)))
2195 if(dflow.startc != startc || dflow.stopc != stopc) {
2199 if(cmd == DIGI_SETFLOW) {
2200 ch->fepstartc = ch->startc = dflow.startc;
2201 ch->fepstopc = ch->stopc = dflow.stopc;
2202 fepcmd(ch,SONOFFC,ch->fepstartc,ch->fepstopc,0, 1);
2204 ch->fepstartca = ch->startca = dflow.startc;
2205 ch->fepstopca = ch->stopca = dflow.stopc;
2206 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2209 if(ch->statusflags & TXSTOPPED)
2213 restore_flags(flags);
2218 return -ENOIOCTLCMD;
2224 static void pcxe_set_termios(struct tty_struct *tty, struct termios *old_termios)
2226 struct channel *info;
2228 if ((info=chan(tty))!=NULL) {
2229 unsigned long flags;
2233 pcxxparam(tty,info);
2236 if ((old_termios->c_cflag & CRTSCTS) &&
2237 ((tty->termios->c_cflag & CRTSCTS) == 0))
2238 tty->hw_stopped = 0;
2239 if(!(old_termios->c_cflag & CLOCAL) &&
2240 (tty->termios->c_cflag & CLOCAL))
2241 wake_up_interruptible(&info->open_wait);
2242 restore_flags(flags);
2248 static void do_softint(void *private_)
2250 struct channel *info = (struct channel *) private_;
2252 if(info && info->magic == PCXX_MAGIC) {
2253 struct tty_struct *tty = info->tty;
2254 if (tty && tty->driver_data) {
2255 if(test_and_clear_bit(PCXE_EVENT_HANGUP, &info->event)) {
2257 wake_up_interruptible(&info->open_wait);
2258 info->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
2265 static void pcxe_stop(struct tty_struct *tty)
2267 struct channel *info;
2269 if ((info=chan(tty))!=NULL) {
2270 unsigned long flags;
2273 if ((info->statusflags & TXSTOPPED) == 0) {
2275 fepcmd(info, PAUSETX, 0, 0, 0, 0);
2276 info->statusflags |= TXSTOPPED;
2279 restore_flags(flags);
2283 static void pcxe_throttle(struct tty_struct * tty)
2285 struct channel *info;
2287 if ((info=chan(tty))!=NULL) {
2288 unsigned long flags;
2291 if ((info->statusflags & RXSTOPPED) == 0) {
2293 fepcmd(info, PAUSERX, 0, 0, 0, 0);
2294 info->statusflags |= RXSTOPPED;
2297 restore_flags(flags);
2301 static void pcxe_unthrottle(struct tty_struct *tty)
2303 struct channel *info;
2305 if ((info=chan(tty)) != NULL) {
2306 unsigned long flags;
2308 /* Just in case output was resumed because of a change in Digi-flow */
2311 if(info->statusflags & RXSTOPPED) {
2312 volatile struct board_chan *bc;
2315 fepcmd(info, RESUMERX, 0, 0, 0, 0);
2316 info->statusflags &= ~RXSTOPPED;
2319 restore_flags(flags);
2324 static void pcxe_start(struct tty_struct *tty)
2326 struct channel *info;
2328 if ((info=chan(tty))!=NULL) {
2329 unsigned long flags;
2333 /* Just in case output was resumed because of a change in Digi-flow */
2334 if(info->statusflags & TXSTOPPED) {
2335 volatile struct board_chan *bc;
2338 if(info->statusflags & LOWWAIT)
2340 fepcmd(info, RESUMETX, 0, 0, 0, 0);
2341 info->statusflags &= ~TXSTOPPED;
2344 restore_flags(flags);
2349 void digi_send_break(struct channel *ch, int msec)
2351 unsigned long flags;
2358 * Maybe I should send an infinite break here, schedule() for
2359 * msec amount of time, and then stop the break. This way,
2360 * the user can't screw up the FEP by causing digi_send_break()
2361 * to be called (i.e. via an ioctl()) more than once in msec amount
2362 * of time. Try this for now...
2365 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2368 restore_flags(flags);
2371 static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2373 volatile struct board_chan *bc;
2374 unsigned long flags;
2379 ch->statusflags |= EMPTYWAIT;
2383 restore_flags(flags);