MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / char / epca.c
blob0f13bef975f51634fac1f367134a670d95437109
1 /*
4 Copyright (C) 1996 Digi International.
6 For technical support please email digiLinux@dgii.com or
7 call Digi tech support at (612) 912-3456
9 Much of this design and code came from epca.c which was
10 copyright (C) 1994, 1995 Troy De Jongh, and subsquently
11 modified by David Nugent, Christoph Lameter, Mike McLagan.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 --------------------------------------------------------------------------- */
28 /* See README.epca for change history --DAT*/
31 #include <linux/config.h>
32 #include <linux/module.h>
33 #include <linux/kernel.h>
34 #include <linux/types.h>
35 #include <linux/init.h>
36 #include <linux/serial.h>
37 #include <linux/delay.h>
38 #include <linux/ctype.h>
39 #include <linux/tty.h>
40 #include <linux/tty_flip.h>
41 #include <linux/slab.h>
42 #include <linux/ioport.h>
43 #include <linux/interrupt.h>
44 #include <asm/uaccess.h>
45 #include <asm/io.h>
47 #ifdef CONFIG_PCI
48 #define ENABLE_PCI
49 #endif /* CONFIG_PCI */
51 #define putUser(arg1, arg2) put_user(arg1, (unsigned long __user *)arg2)
52 #define getUser(arg1, arg2) get_user(arg1, (unsigned __user *)arg2)
54 #ifdef ENABLE_PCI
55 #include <linux/pci.h>
56 #include "digiPCI.h"
57 #endif /* ENABLE_PCI */
59 #include "digi1.h"
60 #include "digiFep1.h"
61 #include "epca.h"
62 #include "epcaconfig.h"
64 #if BITS_PER_LONG != 32
65 # error FIXME: this driver only works on 32-bit platforms
66 #endif
68 /* ---------------------- Begin defines ------------------------ */
70 #define VERSION "1.3.0.1-LK"
72 /* This major needs to be submitted to Linux to join the majors list */
74 #define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
77 #define MAXCARDS 7
78 #define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
80 #define PFX "epca: "
82 /* ----------------- Begin global definitions ------------------- */
84 static char mesg[100];
85 static int nbdevs, num_cards, liloconfig;
86 static int digi_poller_inhibited = 1 ;
88 static int setup_error_code;
89 static int invalid_lilo_config;
91 /* -----------------------------------------------------------------------
92 MAXBOARDS is typically 12, but ISA and EISA cards are restricted to
93 7 below.
94 --------------------------------------------------------------------------*/
95 static struct board_info boards[MAXBOARDS];
98 /* ------------- Begin structures used for driver registeration ---------- */
100 static struct tty_driver *pc_driver;
101 static struct tty_driver *pc_info;
103 /* ------------------ Begin Digi specific structures -------------------- */
105 /* ------------------------------------------------------------------------
106 digi_channels represents an array of structures that keep track of
107 each channel of the Digi product. Information such as transmit and
108 receive pointers, termio data, and signal definitions (DTR, CTS, etc ...)
109 are stored here. This structure is NOT used to overlay the cards
110 physical channel structure.
111 -------------------------------------------------------------------------- */
113 static struct channel digi_channels[MAX_ALLOC];
115 /* ------------------------------------------------------------------------
116 card_ptr is an array used to hold the address of the
117 first channel structure of each card. This array will hold
118 the addresses of various channels located in digi_channels.
119 -------------------------------------------------------------------------- */
120 static struct channel *card_ptr[MAXCARDS];
122 static struct timer_list epca_timer;
124 /* ---------------------- Begin function prototypes --------------------- */
126 /* ----------------------------------------------------------------------
127 Begin generic memory functions. These functions will be alias
128 (point at) more specific functions dependent on the board being
129 configured.
130 ----------------------------------------------------------------------- */
132 static inline void memwinon(struct board_info *b, unsigned int win);
133 static inline void memwinoff(struct board_info *b, unsigned int win);
134 static inline void globalwinon(struct channel *ch);
135 static inline void rxwinon(struct channel *ch);
136 static inline void txwinon(struct channel *ch);
137 static inline void memoff(struct channel *ch);
138 static inline void assertgwinon(struct channel *ch);
139 static inline void assertmemoff(struct channel *ch);
141 /* ---- Begin more 'specific' memory functions for cx_like products --- */
143 static inline void pcxem_memwinon(struct board_info *b, unsigned int win);
144 static inline void pcxem_memwinoff(struct board_info *b, unsigned int win);
145 static inline void pcxem_globalwinon(struct channel *ch);
146 static inline void pcxem_rxwinon(struct channel *ch);
147 static inline void pcxem_txwinon(struct channel *ch);
148 static inline void pcxem_memoff(struct channel *ch);
150 /* ------ Begin more 'specific' memory functions for the pcxe ------- */
152 static inline void pcxe_memwinon(struct board_info *b, unsigned int win);
153 static inline void pcxe_memwinoff(struct board_info *b, unsigned int win);
154 static inline void pcxe_globalwinon(struct channel *ch);
155 static inline void pcxe_rxwinon(struct channel *ch);
156 static inline void pcxe_txwinon(struct channel *ch);
157 static inline void pcxe_memoff(struct channel *ch);
159 /* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
160 /* Note : pc64xe and pcxi share the same windowing routines */
162 static inline void pcxi_memwinon(struct board_info *b, unsigned int win);
163 static inline void pcxi_memwinoff(struct board_info *b, unsigned int win);
164 static inline void pcxi_globalwinon(struct channel *ch);
165 static inline void pcxi_rxwinon(struct channel *ch);
166 static inline void pcxi_txwinon(struct channel *ch);
167 static inline void pcxi_memoff(struct channel *ch);
169 /* - Begin 'specific' do nothing memory functions needed for some cards - */
171 static inline void dummy_memwinon(struct board_info *b, unsigned int win);
172 static inline void dummy_memwinoff(struct board_info *b, unsigned int win);
173 static inline void dummy_globalwinon(struct channel *ch);
174 static inline void dummy_rxwinon(struct channel *ch);
175 static inline void dummy_txwinon(struct channel *ch);
176 static inline void dummy_memoff(struct channel *ch);
177 static inline void dummy_assertgwinon(struct channel *ch);
178 static inline void dummy_assertmemoff(struct channel *ch);
180 /* ------------------- Begin declare functions ----------------------- */
182 static inline struct channel *verifyChannel(register struct tty_struct *);
183 static inline void pc_sched_event(struct channel *, int);
184 static void epca_error(int, char *);
185 static void pc_close(struct tty_struct *, struct file *);
186 static void shutdown(struct channel *);
187 static void pc_hangup(struct tty_struct *);
188 static void pc_put_char(struct tty_struct *, unsigned char);
189 static int pc_write_room(struct tty_struct *);
190 static int pc_chars_in_buffer(struct tty_struct *);
191 static void pc_flush_buffer(struct tty_struct *);
192 static void pc_flush_chars(struct tty_struct *);
193 static int block_til_ready(struct tty_struct *, struct file *,
194 struct channel *);
195 static int pc_open(struct tty_struct *, struct file *);
196 static void post_fep_init(unsigned int crd);
197 static void epcapoll(unsigned long);
198 static void doevent(int);
199 static void fepcmd(struct channel *, int, int, int, int, int);
200 static unsigned termios2digi_h(struct channel *ch, unsigned);
201 static unsigned termios2digi_i(struct channel *ch, unsigned);
202 static unsigned termios2digi_c(struct channel *ch, unsigned);
203 static void epcaparam(struct tty_struct *, struct channel *);
204 static void receive_data(struct channel *);
205 static int pc_ioctl(struct tty_struct *, struct file *,
206 unsigned int, unsigned long);
207 static int info_ioctl(struct tty_struct *, struct file *,
208 unsigned int, unsigned long);
209 static void pc_set_termios(struct tty_struct *, struct termios *);
210 static void do_softint(void *);
211 static void pc_stop(struct tty_struct *);
212 static void pc_start(struct tty_struct *);
213 static void pc_throttle(struct tty_struct * tty);
214 static void pc_unthrottle(struct tty_struct *tty);
215 static void digi_send_break(struct channel *ch, int msec);
216 static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
217 void epca_setup(char *, int *);
218 void console_print(const char *);
220 static int get_termio(struct tty_struct *, struct termio __user *);
221 static int pc_write(struct tty_struct *, int, const unsigned char *, int);
222 int pc_init(void);
224 #ifdef ENABLE_PCI
225 static int init_PCI(void);
226 #endif /* ENABLE_PCI */
229 /* ------------------------------------------------------------------
230 Table of functions for each board to handle memory. Mantaining
231 parallelism is a *very* good idea here. The idea is for the
232 runtime code to blindly call these functions, not knowing/caring
233 about the underlying hardware. This stuff should contain no
234 conditionals; if more functionality is needed a different entry
235 should be established. These calls are the interface calls and
236 are the only functions that should be accessed. Anyone caught
237 making direct calls deserves what they get.
238 -------------------------------------------------------------------- */
240 static inline void memwinon(struct board_info *b, unsigned int win)
242 (b->memwinon)(b, win);
245 static inline void memwinoff(struct board_info *b, unsigned int win)
247 (b->memwinoff)(b, win);
250 static inline void globalwinon(struct channel *ch)
252 (ch->board->globalwinon)(ch);
255 static inline void rxwinon(struct channel *ch)
257 (ch->board->rxwinon)(ch);
260 static inline void txwinon(struct channel *ch)
262 (ch->board->txwinon)(ch);
265 static inline void memoff(struct channel *ch)
267 (ch->board->memoff)(ch);
269 static inline void assertgwinon(struct channel *ch)
271 (ch->board->assertgwinon)(ch);
274 static inline void assertmemoff(struct channel *ch)
276 (ch->board->assertmemoff)(ch);
279 /* ---------------------------------------------------------
280 PCXEM windowing is the same as that used in the PCXR
281 and CX series cards.
282 ------------------------------------------------------------ */
284 static inline void pcxem_memwinon(struct board_info *b, unsigned int win)
286 outb_p(FEPWIN|win, (int)b->port + 1);
289 static inline void pcxem_memwinoff(struct board_info *b, unsigned int win)
291 outb_p(0, (int)b->port + 1);
294 static inline void pcxem_globalwinon(struct channel *ch)
296 outb_p( FEPWIN, (int)ch->board->port + 1);
299 static inline void pcxem_rxwinon(struct channel *ch)
301 outb_p(ch->rxwin, (int)ch->board->port + 1);
304 static inline void pcxem_txwinon(struct channel *ch)
306 outb_p(ch->txwin, (int)ch->board->port + 1);
309 static inline void pcxem_memoff(struct channel *ch)
311 outb_p(0, (int)ch->board->port + 1);
314 /* ----------------- Begin pcxe memory window stuff ------------------ */
316 static inline void pcxe_memwinon(struct board_info *b, unsigned int win)
318 outb_p(FEPWIN | win, (int)b->port + 1);
321 static inline void pcxe_memwinoff(struct board_info *b, unsigned int win)
323 outb_p(inb((int)b->port) & ~FEPMEM,
324 (int)b->port + 1);
325 outb_p(0, (int)b->port + 1);
328 static inline void pcxe_globalwinon(struct channel *ch)
330 outb_p( FEPWIN, (int)ch->board->port + 1);
333 static inline void pcxe_rxwinon(struct channel *ch)
335 outb_p(ch->rxwin, (int)ch->board->port + 1);
338 static inline void pcxe_txwinon(struct channel *ch)
340 outb_p(ch->txwin, (int)ch->board->port + 1);
343 static inline void pcxe_memoff(struct channel *ch)
345 outb_p(0, (int)ch->board->port);
346 outb_p(0, (int)ch->board->port + 1);
349 /* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
351 static inline void pcxi_memwinon(struct board_info *b, unsigned int win)
353 outb_p(inb((int)b->port) | FEPMEM, (int)b->port);
356 static inline void pcxi_memwinoff(struct board_info *b, unsigned int win)
358 outb_p(inb((int)b->port) & ~FEPMEM, (int)b->port);
361 static inline void pcxi_globalwinon(struct channel *ch)
363 outb_p(FEPMEM, (int)ch->board->port);
366 static inline void pcxi_rxwinon(struct channel *ch)
368 outb_p(FEPMEM, (int)ch->board->port);
371 static inline void pcxi_txwinon(struct channel *ch)
373 outb_p(FEPMEM, (int)ch->board->port);
376 static inline void pcxi_memoff(struct channel *ch)
378 outb_p(0, (int)ch->board->port);
381 static inline void pcxi_assertgwinon(struct channel *ch)
383 epcaassert(inb((int)ch->board->port) & FEPMEM, "Global memory off");
386 static inline void pcxi_assertmemoff(struct channel *ch)
388 epcaassert(!(inb((int)ch->board->port) & FEPMEM), "Memory on");
392 /* ----------------------------------------------------------------------
393 Not all of the cards need specific memory windowing routines. Some
394 cards (Such as PCI) needs no windowing routines at all. We provide
395 these do nothing routines so that the same code base can be used.
396 The driver will ALWAYS call a windowing routine if it thinks it needs
397 to; regardless of the card. However, dependent on the card the routine
398 may or may not do anything.
399 ---------------------------------------------------------------------------*/
401 static inline void dummy_memwinon(struct board_info *b, unsigned int win)
405 static inline void dummy_memwinoff(struct board_info *b, unsigned int win)
409 static inline void dummy_globalwinon(struct channel *ch)
413 static inline void dummy_rxwinon(struct channel *ch)
417 static inline void dummy_txwinon(struct channel *ch)
421 static inline void dummy_memoff(struct channel *ch)
425 static inline void dummy_assertgwinon(struct channel *ch)
429 static inline void dummy_assertmemoff(struct channel *ch)
433 /* ----------------- Begin verifyChannel function ----------------------- */
434 static inline struct channel *verifyChannel(register struct tty_struct *tty)
435 { /* Begin verifyChannel */
437 /* --------------------------------------------------------------------
438 This routine basically provides a sanity check. It insures that
439 the channel returned is within the proper range of addresses as
440 well as properly initialized. If some bogus info gets passed in
441 through tty->driver_data this should catch it.
442 --------------------------------------------------------------------- */
444 if (tty)
445 { /* Begin if tty */
447 register struct channel *ch = (struct channel *)tty->driver_data;
449 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs]))
451 if (ch->magic == EPCA_MAGIC)
452 return ch;
455 } /* End if tty */
457 /* Else return a NULL for invalid */
458 return NULL;
460 } /* End verifyChannel */
462 /* ------------------ Begin pc_sched_event ------------------------- */
464 static inline void pc_sched_event(struct channel *ch, int event)
465 { /* Begin pc_sched_event */
468 /* ----------------------------------------------------------------------
469 We call this to schedule interrupt processing on some event. The
470 kernel sees our request and calls the related routine in OUR driver.
471 -------------------------------------------------------------------------*/
473 ch->event |= 1 << event;
474 schedule_work(&ch->tqueue);
477 } /* End pc_sched_event */
479 /* ------------------ Begin epca_error ------------------------- */
481 static void epca_error(int line, char *msg)
482 { /* Begin epca_error */
484 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
485 return;
487 } /* End epca_error */
489 /* ------------------ Begin pc_close ------------------------- */
490 static void pc_close(struct tty_struct * tty, struct file * filp)
491 { /* Begin pc_close */
493 struct channel *ch;
494 unsigned long flags;
496 /* ---------------------------------------------------------
497 verifyChannel returns the channel from the tty struct
498 if it is valid. This serves as a sanity check.
499 ------------------------------------------------------------- */
501 if ((ch = verifyChannel(tty)) != NULL)
502 { /* Begin if ch != NULL */
504 save_flags(flags);
505 cli();
507 if (tty_hung_up_p(filp))
509 restore_flags(flags);
510 return;
513 /* Check to see if the channel is open more than once */
514 if (ch->count-- > 1)
515 { /* Begin channel is open more than once */
517 /* -------------------------------------------------------------
518 Return without doing anything. Someone might still be using
519 the channel.
520 ---------------------------------------------------------------- */
522 restore_flags(flags);
523 return;
524 } /* End channel is open more than once */
526 /* Port open only once go ahead with shutdown & reset */
528 if (ch->count < 0)
530 ch->count = 0;
533 /* ---------------------------------------------------------------
534 Let the rest of the driver know the channel is being closed.
535 This becomes important if an open is attempted before close
536 is finished.
537 ------------------------------------------------------------------ */
539 ch->asyncflags |= ASYNC_CLOSING;
541 tty->closing = 1;
543 if (ch->asyncflags & ASYNC_INITIALIZED)
545 /* Setup an event to indicate when the transmit buffer empties */
546 setup_empty_event(tty, ch);
547 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
550 if (tty->driver->flush_buffer)
551 tty->driver->flush_buffer(tty);
553 tty_ldisc_flush(tty);
554 shutdown(ch);
555 tty->closing = 0;
556 ch->event = 0;
557 ch->tty = NULL;
559 if (ch->blocked_open)
560 { /* Begin if blocked_open */
562 if (ch->close_delay)
564 current->state = TASK_INTERRUPTIBLE;
565 schedule_timeout(ch->close_delay);
568 wake_up_interruptible(&ch->open_wait);
570 } /* End if blocked_open */
572 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
573 ASYNC_CLOSING);
574 wake_up_interruptible(&ch->close_wait);
577 restore_flags(flags);
579 } /* End if ch != NULL */
581 } /* End pc_close */
583 /* ------------------ Begin shutdown ------------------------- */
585 static void shutdown(struct channel *ch)
586 { /* Begin shutdown */
588 unsigned long flags;
589 struct tty_struct *tty;
590 volatile struct board_chan *bc;
592 if (!(ch->asyncflags & ASYNC_INITIALIZED))
593 return;
595 save_flags(flags);
596 cli();
597 globalwinon(ch);
599 bc = ch->brdchan;
601 /* ------------------------------------------------------------------
602 In order for an event to be generated on the receipt of data the
603 idata flag must be set. Since we are shutting down, this is not
604 necessary clear this flag.
605 --------------------------------------------------------------------- */
607 if (bc)
608 bc->idata = 0;
610 tty = ch->tty;
612 /* ----------------------------------------------------------------
613 If we're a modem control device and HUPCL is on, drop RTS & DTR.
614 ------------------------------------------------------------------ */
616 if (tty->termios->c_cflag & HUPCL)
618 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
619 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
622 memoff(ch);
624 /* ------------------------------------------------------------------
625 The channel has officialy been closed. The next time it is opened
626 it will have to reinitialized. Set a flag to indicate this.
627 ---------------------------------------------------------------------- */
629 /* Prevent future Digi programmed interrupts from coming active */
631 ch->asyncflags &= ~ASYNC_INITIALIZED;
632 restore_flags(flags);
634 } /* End shutdown */
636 /* ------------------ Begin pc_hangup ------------------------- */
638 static void pc_hangup(struct tty_struct *tty)
639 { /* Begin pc_hangup */
641 struct channel *ch;
643 /* ---------------------------------------------------------
644 verifyChannel returns the channel from the tty struct
645 if it is valid. This serves as a sanity check.
646 ------------------------------------------------------------- */
648 if ((ch = verifyChannel(tty)) != NULL)
649 { /* Begin if ch != NULL */
651 unsigned long flags;
653 save_flags(flags);
654 cli();
655 if (tty->driver->flush_buffer)
656 tty->driver->flush_buffer(tty);
657 tty_ldisc_flush(tty);
658 shutdown(ch);
660 ch->tty = NULL;
661 ch->event = 0;
662 ch->count = 0;
663 restore_flags(flags);
664 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
665 wake_up_interruptible(&ch->open_wait);
667 } /* End if ch != NULL */
669 } /* End pc_hangup */
671 /* ------------------ Begin pc_write ------------------------- */
673 static int pc_write(struct tty_struct * tty, int from_user,
674 const unsigned char *buf, int bytesAvailable)
675 { /* Begin pc_write */
677 register unsigned int head, tail;
678 register int dataLen;
679 register int size;
680 register int amountCopied;
683 struct channel *ch;
684 unsigned long flags;
685 int remain;
686 volatile struct board_chan *bc;
689 /* ----------------------------------------------------------------
690 pc_write is primarily called directly by the kernel routine
691 tty_write (Though it can also be called by put_char) found in
692 tty_io.c. pc_write is passed a line discipline buffer where
693 the data to be written out is stored. The line discipline
694 implementation itself is done at the kernel level and is not
695 brought into the driver.
696 ------------------------------------------------------------------- */
698 /* ---------------------------------------------------------
699 verifyChannel returns the channel from the tty struct
700 if it is valid. This serves as a sanity check.
701 ------------------------------------------------------------- */
703 if ((ch = verifyChannel(tty)) == NULL)
704 return 0;
706 /* Make a pointer to the channel data structure found on the board. */
708 bc = ch->brdchan;
709 size = ch->txbufsize;
711 if (from_user)
712 { /* Begin from_user */
714 save_flags(flags);
715 cli();
717 globalwinon(ch);
719 /* -----------------------------------------------------------------
720 Anding against size will wrap the pointer back to its beginning
721 position if it is necessary. This will only work if size is
722 a power of 2 which should always be the case. Size is determined
723 by the cards on board FEP/OS.
724 -------------------------------------------------------------------- */
726 /* head refers to the next empty location in which data may be stored */
728 head = bc->tin & (size - 1);
730 /* tail refers to the next data byte to be transmitted */
732 tail = bc->tout;
734 /* Consider changing this to a do statement to make sure */
736 if (tail != bc->tout)
737 tail = bc->tout;
739 /* ------------------------------------------------------------------
740 Anding against size will wrap the pointer back to its beginning
741 position if it is necessary. This will only work if size is
742 a power of 2 which should always be the case. Size is determined
743 by the cards on board FEP/OS.
744 --------------------------------------------------------------------- */
746 tail &= (size - 1);
748 /* -----------------------------------------------------------------
749 Two situations can affect how space in the transmit buffer
750 is calculated. You can have a situation where the transmit
751 in pointer (tin) head has wrapped around and actually has a
752 lower address than the transmit out pointer (tout) tail; or
753 the transmit in pointer (tin) head will not be wrapped around
754 yet, and have a higher address than the transmit out pointer
755 (tout) tail. Obviously space available in the transmit buffer
756 is calculated differently for each case.
758 Example 1:
760 Consider a 10 byte buffer where head is a pointer to the next
761 empty location in the buffer and tail is a pointer to the next
762 byte to transmit. In this example head will not have wrapped
763 around and therefore head > tail.
765 0 1 2 3 4 5 6 7 8 9
766 tail head
768 The above diagram shows that buffer locations 2,3,4,5 and 6 have
769 data to be transmitted, while head points at the next empty
770 location. To calculate how much space is available first we have
771 to determine if the head pointer (tin) has wrapped. To do this
772 compare the head pointer to the tail pointer, If head is equal
773 or greater than tail; then it has not wrapped; and the space may
774 be calculated by subtracting tail from head and then subtracting
775 that value from the buffers size. A one is subtracted from the
776 new value to indicate how much space is available between the
777 head pointer and end of buffer; as well as the space between the
778 beginning of the buffer and the tail. If the head is not greater
779 or equal to the tail this indicates that the head has wrapped
780 around to the beginning of the buffer. To calculate the space
781 available in this case simply subtract head from tail. This new
782 value minus one represents the space available betwwen the head
783 and tail pointers. In this example head (7) is greater than tail (2)
784 and therefore has not wrapped around. We find the space by first
785 subtracting tail from head (7-2=5). We then subtract this value
786 from the buffer size of ten and subtract one (10-5-1=4). The space
787 remaining is 4 bytes.
789 Example 2:
791 Consider a 10 byte buffer where head is a pointer to the next
792 empty location in the buffer and tail is a pointer to the next
793 byte to transmit. In this example head will wrapped around and
794 therefore head < tail.
796 0 1 2 3 4 5 6 7 8 9
797 head tail
799 The above diagram shows that buffer locations 7,8,9,0 and 1 have
800 data to be transmitted, while head points at the next empty
801 location. To find the space available we compare head to tail. If
802 head is not equal to, or greater than tail this indicates that head
803 has wrapped around. In this case head (2) is not equal to, or
804 greater than tail (7) and therefore has already wrapped around. To
805 calculate the available space between the two pointers we subtract
806 head from tail (7-2=5). We then subtract one from this new value
807 (5-1=4). We have 5 bytes empty remaining in the buffer. Unlike the
808 previous example these five bytes are located between the head and
809 tail pointers.
811 ----------------------------------------------------------------------- */
813 dataLen = (head >= tail) ? (size - (head - tail) - 1) : (tail - head - 1);
815 /* ----------------------------------------------------------------------
816 In this case bytesAvailable has been passed into pc_write and
817 represents the amount of data that needs to be written. dataLen
818 represents the amount of space available on the card. Whichever
819 value is smaller will be the amount actually written.
820 bytesAvailable will then take on this newly calculated value.
821 ---------------------------------------------------------------------- */
823 bytesAvailable = min(dataLen, bytesAvailable);
825 /* First we read the data in from the file system into a temp buffer */
827 memoff(ch);
828 restore_flags(flags);
830 if (bytesAvailable)
831 { /* Begin bytesAvailable */
832 /* ---------------------------------------------------------------
833 The below function reads data from user memory. This routine
834 can not be used in an interrupt routine. (Because it may
835 generate a page fault) It can only be called while we can the
836 user context is accessible.
838 The prototype is :
839 inline void copy_from_user(void * to, const void * from,
840 unsigned long count);
842 I also think (Check hackers guide) that optimization must
843 be turned ON. (Which sounds strange to me...)
845 Remember copy_from_user WILL generate a page fault if the
846 user memory being accessed has been swapped out. This can
847 cause this routine to temporarily sleep while this page
848 fault is occurring.
850 ----------------------------------------------------------------- */
852 if (copy_from_user(ch->tmp_buf, buf,
853 bytesAvailable))
854 return -EFAULT;
855 } /* End bytesAvailable */
857 /* ------------------------------------------------------------------
858 Set buf to this address for the moment. tmp_buf was allocated in
859 post_fep_init.
860 --------------------------------------------------------------------- */
861 buf = ch->tmp_buf;
863 } /* End from_user */
865 /* All data is now local */
867 amountCopied = 0;
868 save_flags(flags);
869 cli();
871 globalwinon(ch);
873 head = bc->tin & (size - 1);
874 tail = bc->tout;
876 if (tail != bc->tout)
877 tail = bc->tout;
878 tail &= (size - 1);
880 /* If head >= tail, head has not wrapped around. */
881 if (head >= tail)
882 { /* Begin head has not wrapped */
884 /* ---------------------------------------------------------------
885 remain (much like dataLen above) represents the total amount of
886 space available on the card for data. Here dataLen represents
887 the space existing between the head pointer and the end of
888 buffer. This is important because a memcpy cannot be told to
889 automatically wrap around when it hits the buffer end.
890 ------------------------------------------------------------------ */
892 dataLen = size - head;
893 remain = size - (head - tail) - 1;
895 } /* End head has not wrapped */
896 else
897 { /* Begin head has wrapped around */
899 remain = tail - head - 1;
900 dataLen = remain;
902 } /* End head has wrapped around */
904 /* -------------------------------------------------------------------
905 Check the space on the card. If we have more data than
906 space; reduce the amount of data to fit the space.
907 ---------------------------------------------------------------------- */
909 bytesAvailable = min(remain, bytesAvailable);
911 txwinon(ch);
912 while (bytesAvailable > 0)
913 { /* Begin while there is data to copy onto card */
915 /* -----------------------------------------------------------------
916 If head is not wrapped, the below will make sure the first
917 data copy fills to the end of card buffer.
918 ------------------------------------------------------------------- */
920 dataLen = min(bytesAvailable, dataLen);
921 memcpy(ch->txptr + head, buf, dataLen);
922 buf += dataLen;
923 head += dataLen;
924 amountCopied += dataLen;
925 bytesAvailable -= dataLen;
927 if (head >= size)
929 head = 0;
930 dataLen = tail;
933 } /* End while there is data to copy onto card */
935 ch->statusflags |= TXBUSY;
936 globalwinon(ch);
937 bc->tin = head;
939 if ((ch->statusflags & LOWWAIT) == 0)
941 ch->statusflags |= LOWWAIT;
942 bc->ilow = 1;
944 memoff(ch);
945 restore_flags(flags);
947 return(amountCopied);
949 } /* End pc_write */
951 /* ------------------ Begin pc_put_char ------------------------- */
953 static void pc_put_char(struct tty_struct *tty, unsigned char c)
954 { /* Begin pc_put_char */
957 pc_write(tty, 0, &c, 1);
958 return;
960 } /* End pc_put_char */
962 /* ------------------ Begin pc_write_room ------------------------- */
964 static int pc_write_room(struct tty_struct *tty)
965 { /* Begin pc_write_room */
967 int remain;
968 struct channel *ch;
969 unsigned long flags;
970 unsigned int head, tail;
971 volatile struct board_chan *bc;
973 remain = 0;
975 /* ---------------------------------------------------------
976 verifyChannel returns the channel from the tty struct
977 if it is valid. This serves as a sanity check.
978 ------------------------------------------------------------- */
980 if ((ch = verifyChannel(tty)) != NULL)
982 save_flags(flags);
983 cli();
984 globalwinon(ch);
986 bc = ch->brdchan;
987 head = bc->tin & (ch->txbufsize - 1);
988 tail = bc->tout;
990 if (tail != bc->tout)
991 tail = bc->tout;
992 /* Wrap tail if necessary */
993 tail &= (ch->txbufsize - 1);
995 if ((remain = tail - head - 1) < 0 )
996 remain += ch->txbufsize;
998 if (remain && (ch->statusflags & LOWWAIT) == 0)
1000 ch->statusflags |= LOWWAIT;
1001 bc->ilow = 1;
1003 memoff(ch);
1004 restore_flags(flags);
1007 /* Return how much room is left on card */
1008 return remain;
1010 } /* End pc_write_room */
1012 /* ------------------ Begin pc_chars_in_buffer ---------------------- */
1014 static int pc_chars_in_buffer(struct tty_struct *tty)
1015 { /* Begin pc_chars_in_buffer */
1017 int chars;
1018 unsigned int ctail, head, tail;
1019 int remain;
1020 unsigned long flags;
1021 struct channel *ch;
1022 volatile struct board_chan *bc;
1025 /* ---------------------------------------------------------
1026 verifyChannel returns the channel from the tty struct
1027 if it is valid. This serves as a sanity check.
1028 ------------------------------------------------------------- */
1030 if ((ch = verifyChannel(tty)) == NULL)
1031 return(0);
1033 save_flags(flags);
1034 cli();
1035 globalwinon(ch);
1037 bc = ch->brdchan;
1038 tail = bc->tout;
1039 head = bc->tin;
1040 ctail = ch->mailbox->cout;
1042 if (tail == head && ch->mailbox->cin == ctail && bc->tbusy == 0)
1043 chars = 0;
1044 else
1045 { /* Begin if some space on the card has been used */
1047 head = bc->tin & (ch->txbufsize - 1);
1048 tail &= (ch->txbufsize - 1);
1050 /* --------------------------------------------------------------
1051 The logic here is basically opposite of the above pc_write_room
1052 here we are finding the amount of bytes in the buffer filled.
1053 Not the amount of bytes empty.
1054 ------------------------------------------------------------------- */
1056 if ((remain = tail - head - 1) < 0 )
1057 remain += ch->txbufsize;
1059 chars = (int)(ch->txbufsize - remain);
1061 /* -------------------------------------------------------------
1062 Make it possible to wakeup anything waiting for output
1063 in tty_ioctl.c, etc.
1065 If not already set. Setup an event to indicate when the
1066 transmit buffer empties
1067 ----------------------------------------------------------------- */
1069 if (!(ch->statusflags & EMPTYWAIT))
1070 setup_empty_event(tty,ch);
1072 } /* End if some space on the card has been used */
1074 memoff(ch);
1075 restore_flags(flags);
1077 /* Return number of characters residing on card. */
1078 return(chars);
1080 } /* End pc_chars_in_buffer */
1082 /* ------------------ Begin pc_flush_buffer ---------------------- */
1084 static void pc_flush_buffer(struct tty_struct *tty)
1085 { /* Begin pc_flush_buffer */
1087 unsigned int tail;
1088 unsigned long flags;
1089 struct channel *ch;
1090 volatile struct board_chan *bc;
1093 /* ---------------------------------------------------------
1094 verifyChannel returns the channel from the tty struct
1095 if it is valid. This serves as a sanity check.
1096 ------------------------------------------------------------- */
1098 if ((ch = verifyChannel(tty)) == NULL)
1099 return;
1101 save_flags(flags);
1102 cli();
1104 globalwinon(ch);
1106 bc = ch->brdchan;
1107 tail = bc->tout;
1109 /* Have FEP move tout pointer; effectively flushing transmit buffer */
1111 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
1113 memoff(ch);
1114 restore_flags(flags);
1116 wake_up_interruptible(&tty->write_wait);
1117 tty_wakeup(tty);
1119 } /* End pc_flush_buffer */
1121 /* ------------------ Begin pc_flush_chars ---------------------- */
1123 static void pc_flush_chars(struct tty_struct *tty)
1124 { /* Begin pc_flush_chars */
1126 struct channel * ch;
1128 /* ---------------------------------------------------------
1129 verifyChannel returns the channel from the tty struct
1130 if it is valid. This serves as a sanity check.
1131 ------------------------------------------------------------- */
1133 if ((ch = verifyChannel(tty)) != NULL)
1135 unsigned long flags;
1137 save_flags(flags);
1138 cli();
1140 /* ----------------------------------------------------------------
1141 If not already set and the transmitter is busy setup an event
1142 to indicate when the transmit empties.
1143 ------------------------------------------------------------------- */
1145 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
1146 setup_empty_event(tty,ch);
1148 restore_flags(flags);
1151 } /* End pc_flush_chars */
1153 /* ------------------ Begin block_til_ready ---------------------- */
1155 static int block_til_ready(struct tty_struct *tty,
1156 struct file *filp, struct channel *ch)
1157 { /* Begin block_til_ready */
1159 DECLARE_WAITQUEUE(wait,current);
1160 int retval, do_clocal = 0;
1161 unsigned long flags;
1164 if (tty_hung_up_p(filp))
1166 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1167 retval = -EAGAIN;
1168 else
1169 retval = -ERESTARTSYS;
1170 return(retval);
1173 /* -----------------------------------------------------------------
1174 If the device is in the middle of being closed, then block
1175 until it's done, and then try again.
1176 -------------------------------------------------------------------- */
1177 if (ch->asyncflags & ASYNC_CLOSING)
1179 interruptible_sleep_on(&ch->close_wait);
1181 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1182 return -EAGAIN;
1183 else
1184 return -ERESTARTSYS;
1187 if (filp->f_flags & O_NONBLOCK)
1189 /* -----------------------------------------------------------------
1190 If non-blocking mode is set, then make the check up front
1191 and then exit.
1192 -------------------------------------------------------------------- */
1194 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1196 return 0;
1200 if (tty->termios->c_cflag & CLOCAL)
1201 do_clocal = 1;
1203 /* Block waiting for the carrier detect and the line to become free */
1205 retval = 0;
1206 add_wait_queue(&ch->open_wait, &wait);
1207 save_flags(flags);
1208 cli();
1211 /* We dec count so that pc_close will know when to free things */
1212 if (!tty_hung_up_p(filp))
1213 ch->count--;
1215 restore_flags(flags);
1217 ch->blocked_open++;
1219 while(1)
1220 { /* Begin forever while */
1222 set_current_state(TASK_INTERRUPTIBLE);
1224 if (tty_hung_up_p(filp) ||
1225 !(ch->asyncflags & ASYNC_INITIALIZED))
1227 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1228 retval = -EAGAIN;
1229 else
1230 retval = -ERESTARTSYS;
1231 break;
1234 if (!(ch->asyncflags & ASYNC_CLOSING) &&
1235 (do_clocal || (ch->imodem & ch->dcd)))
1236 break;
1238 if (signal_pending(current))
1240 retval = -ERESTARTSYS;
1241 break;
1244 /* ---------------------------------------------------------------
1245 Allow someone else to be scheduled. We will occasionally go
1246 through this loop until one of the above conditions change.
1247 The below schedule call will allow other processes to enter and
1248 prevent this loop from hogging the cpu.
1249 ------------------------------------------------------------------ */
1250 schedule();
1252 } /* End forever while */
1254 current->state = TASK_RUNNING;
1255 remove_wait_queue(&ch->open_wait, &wait);
1256 cli();
1257 if (!tty_hung_up_p(filp))
1258 ch->count++;
1259 restore_flags(flags);
1261 ch->blocked_open--;
1263 if (retval)
1264 return retval;
1266 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1268 return 0;
1270 } /* End block_til_ready */
1272 /* ------------------ Begin pc_open ---------------------- */
1274 static int pc_open(struct tty_struct *tty, struct file * filp)
1275 { /* Begin pc_open */
1277 struct channel *ch;
1278 unsigned long flags;
1279 int line, retval, boardnum;
1280 volatile struct board_chan *bc;
1281 volatile unsigned int head;
1283 line = tty->index;
1284 if (line < 0 || line >= nbdevs)
1286 printk(KERN_ERR "<Error> - pc_open : line out of range in pc_open\n");
1287 tty->driver_data = NULL;
1288 return(-ENODEV);
1292 ch = &digi_channels[line];
1293 boardnum = ch->boardnum;
1295 /* Check status of board configured in system. */
1297 /* -----------------------------------------------------------------
1298 I check to see if the epca_setup routine detected an user error.
1299 It might be better to put this in pc_init, but for the moment it
1300 goes here.
1301 ---------------------------------------------------------------------- */
1303 if (invalid_lilo_config)
1305 if (setup_error_code & INVALID_BOARD_TYPE)
1306 printk(KERN_ERR "<Error> - pc_open: Invalid board type specified in LILO command\n");
1308 if (setup_error_code & INVALID_NUM_PORTS)
1309 printk(KERN_ERR "<Error> - pc_open: Invalid number of ports specified in LILO command\n");
1311 if (setup_error_code & INVALID_MEM_BASE)
1312 printk(KERN_ERR "<Error> - pc_open: Invalid board memory address specified in LILO command\n");
1314 if (setup_error_code & INVALID_PORT_BASE)
1315 printk(KERN_ERR "<Error> - pc_open: Invalid board port address specified in LILO command\n");
1317 if (setup_error_code & INVALID_BOARD_STATUS)
1318 printk(KERN_ERR "<Error> - pc_open: Invalid board status specified in LILO command\n");
1320 if (setup_error_code & INVALID_ALTPIN)
1321 printk(KERN_ERR "<Error> - pc_open: Invalid board altpin specified in LILO command\n");
1323 tty->driver_data = NULL; /* Mark this device as 'down' */
1324 return(-ENODEV);
1327 if ((boardnum >= num_cards) || (boards[boardnum].status == DISABLED))
1329 tty->driver_data = NULL; /* Mark this device as 'down' */
1330 return(-ENODEV);
1333 if (( bc = ch->brdchan) == 0)
1335 tty->driver_data = NULL;
1336 return(-ENODEV);
1339 /* ------------------------------------------------------------------
1340 Every time a channel is opened, increment a counter. This is
1341 necessary because we do not wish to flush and shutdown the channel
1342 until the last app holding the channel open, closes it.
1343 --------------------------------------------------------------------- */
1345 ch->count++;
1347 /* ----------------------------------------------------------------
1348 Set a kernel structures pointer to our local channel
1349 structure. This way we can get to it when passed only
1350 a tty struct.
1351 ------------------------------------------------------------------ */
1353 tty->driver_data = ch;
1355 /* ----------------------------------------------------------------
1356 If this is the first time the channel has been opened, initialize
1357 the tty->termios struct otherwise let pc_close handle it.
1358 -------------------------------------------------------------------- */
1360 save_flags(flags);
1361 cli();
1363 globalwinon(ch);
1364 ch->statusflags = 0;
1366 /* Save boards current modem status */
1367 ch->imodem = bc->mstat;
1369 /* ----------------------------------------------------------------
1370 Set receive head and tail ptrs to each other. This indicates
1371 no data available to read.
1372 ----------------------------------------------------------------- */
1373 head = bc->rin;
1374 bc->rout = head;
1376 /* Set the channels associated tty structure */
1377 ch->tty = tty;
1379 /* -----------------------------------------------------------------
1380 The below routine generally sets up parity, baud, flow control
1381 issues, etc.... It effect both control flags and input flags.
1382 -------------------------------------------------------------------- */
1383 epcaparam(tty,ch);
1385 ch->asyncflags |= ASYNC_INITIALIZED;
1386 memoff(ch);
1388 restore_flags(flags);
1390 retval = block_til_ready(tty, filp, ch);
1391 if (retval)
1393 return retval;
1396 /* -------------------------------------------------------------
1397 Set this again in case a hangup set it to zero while this
1398 open() was waiting for the line...
1399 --------------------------------------------------------------- */
1400 ch->tty = tty;
1402 save_flags(flags);
1403 cli();
1404 globalwinon(ch);
1406 /* Enable Digi Data events */
1407 bc->idata = 1;
1409 memoff(ch);
1410 restore_flags(flags);
1412 return 0;
1414 } /* End pc_open */
1416 #ifdef MODULE
1417 static int __init epca_module_init(void)
1418 { /* Begin init_module */
1420 unsigned long flags;
1422 save_flags(flags);
1423 cli();
1425 pc_init();
1427 restore_flags(flags);
1429 return(0);
1432 module_init(epca_module_init);
1433 #endif
1435 #ifdef ENABLE_PCI
1436 static struct pci_driver epca_driver;
1437 #endif
1439 #ifdef MODULE
1440 /* -------------------- Begin cleanup_module ---------------------- */
1442 static void __exit epca_module_exit(void)
1445 int count, crd;
1446 struct board_info *bd;
1447 struct channel *ch;
1448 unsigned long flags;
1450 del_timer_sync(&epca_timer);
1452 save_flags(flags);
1453 cli();
1455 if ((tty_unregister_driver(pc_driver)) ||
1456 (tty_unregister_driver(pc_info)))
1458 printk(KERN_WARNING "<Error> - DIGI : cleanup_module failed to un-register tty driver\n");
1459 restore_flags(flags);
1460 return;
1462 put_tty_driver(pc_driver);
1463 put_tty_driver(pc_info);
1465 for (crd = 0; crd < num_cards; crd++)
1466 { /* Begin for each card */
1468 bd = &boards[crd];
1470 if (!bd)
1471 { /* Begin sanity check */
1472 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1473 return;
1474 } /* End sanity check */
1476 ch = card_ptr[crd];
1478 for (count = 0; count < bd->numports; count++, ch++)
1479 { /* Begin for each port */
1481 if (ch)
1483 if (ch->tty)
1484 tty_hangup(ch->tty);
1485 kfree(ch->tmp_buf);
1488 } /* End for each port */
1489 } /* End for each card */
1491 #ifdef ENABLE_PCI
1492 pci_unregister_driver (&epca_driver);
1493 #endif
1495 restore_flags(flags);
1498 module_exit(epca_module_exit);
1499 #endif /* MODULE */
1501 static struct tty_operations pc_ops = {
1502 .open = pc_open,
1503 .close = pc_close,
1504 .write = pc_write,
1505 .write_room = pc_write_room,
1506 .flush_buffer = pc_flush_buffer,
1507 .chars_in_buffer = pc_chars_in_buffer,
1508 .flush_chars = pc_flush_chars,
1509 .put_char = pc_put_char,
1510 .ioctl = pc_ioctl,
1511 .set_termios = pc_set_termios,
1512 .stop = pc_stop,
1513 .start = pc_start,
1514 .throttle = pc_throttle,
1515 .unthrottle = pc_unthrottle,
1516 .hangup = pc_hangup,
1519 static int info_open(struct tty_struct *tty, struct file * filp)
1521 return 0;
1524 static struct tty_operations info_ops = {
1525 .open = info_open,
1526 .ioctl = info_ioctl,
1529 /* ------------------ Begin pc_init ---------------------- */
1531 int __init pc_init(void)
1532 { /* Begin pc_init */
1534 /* ----------------------------------------------------------------
1535 pc_init is called by the operating system during boot up prior to
1536 any open calls being made. In the older versions of Linux (Prior
1537 to 2.0.0) an entry is made into tty_io.c. A pointer to the last
1538 memory location (from kernel space) used (kmem_start) is passed
1539 to pc_init. It is pc_inits responsibility to modify this value
1540 for any memory that the Digi driver might need and then return
1541 this value to the operating system. For example if the driver
1542 wishes to allocate 1K of kernel memory, pc_init would return
1543 (kmem_start + 1024). This memory (Between kmem_start and kmem_start
1544 + 1024) would then be available for use exclusively by the driver.
1545 In this case our driver does not allocate any of this kernel
1546 memory.
1547 ------------------------------------------------------------------*/
1549 ulong flags;
1550 int crd;
1551 struct board_info *bd;
1552 unsigned char board_id = 0;
1554 #ifdef ENABLE_PCI
1555 int pci_boards_found, pci_count;
1557 pci_count = 0;
1558 #endif /* ENABLE_PCI */
1560 pc_driver = alloc_tty_driver(MAX_ALLOC);
1561 if (!pc_driver)
1562 return -ENOMEM;
1564 pc_info = alloc_tty_driver(MAX_ALLOC);
1565 if (!pc_info) {
1566 put_tty_driver(pc_driver);
1567 return -ENOMEM;
1570 /* -----------------------------------------------------------------------
1571 If epca_setup has not been ran by LILO set num_cards to defaults; copy
1572 board structure defined by digiConfig into drivers board structure.
1573 Note : If LILO has ran epca_setup then epca_setup will handle defining
1574 num_cards as well as copying the data into the board structure.
1575 -------------------------------------------------------------------------- */
1576 if (!liloconfig)
1577 { /* Begin driver has been configured via. epcaconfig */
1579 nbdevs = NBDEVS;
1580 num_cards = NUMCARDS;
1581 memcpy((void *)&boards, (void *)&static_boards,
1582 (sizeof(struct board_info) * NUMCARDS));
1583 } /* End driver has been configured via. epcaconfig */
1585 /* -----------------------------------------------------------------
1586 Note : If lilo was used to configure the driver and the
1587 ignore epcaconfig option was choosen (digiepca=2) then
1588 nbdevs and num_cards will equal 0 at this point. This is
1589 okay; PCI cards will still be picked up if detected.
1590 --------------------------------------------------------------------- */
1592 /* -----------------------------------------------------------
1593 Set up interrupt, we will worry about memory allocation in
1594 post_fep_init.
1595 --------------------------------------------------------------- */
1598 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1600 #ifdef ENABLE_PCI
1602 /* ------------------------------------------------------------------
1603 NOTE : This code assumes that the number of ports found in
1604 the boards array is correct. This could be wrong if
1605 the card in question is PCI (And therefore has no ports
1606 entry in the boards structure.) The rest of the
1607 information will be valid for PCI because the beginning
1608 of pc_init scans for PCI and determines i/o and base
1609 memory addresses. I am not sure if it is possible to
1610 read the number of ports supported by the card prior to
1611 it being booted (Since that is the state it is in when
1612 pc_init is run). Because it is not possible to query the
1613 number of supported ports until after the card has booted;
1614 we are required to calculate the card_ptrs as the card is
1615 is initialized (Inside post_fep_init). The negative thing
1616 about this approach is that digiDload's call to GET_INFO
1617 will have a bad port value. (Since this is called prior
1618 to post_fep_init.)
1620 --------------------------------------------------------------------- */
1622 pci_boards_found = 0;
1623 if(num_cards < MAXBOARDS)
1624 pci_boards_found += init_PCI();
1625 num_cards += pci_boards_found;
1627 #endif /* ENABLE_PCI */
1629 pc_driver->owner = THIS_MODULE;
1630 pc_driver->name = "ttyD";
1631 pc_driver->devfs_name = "tts/D";
1632 pc_driver->major = DIGI_MAJOR;
1633 pc_driver->minor_start = 0;
1634 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1635 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1636 pc_driver->init_termios = tty_std_termios;
1637 pc_driver->init_termios.c_iflag = 0;
1638 pc_driver->init_termios.c_oflag = 0;
1639 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1640 pc_driver->init_termios.c_lflag = 0;
1641 pc_driver->flags = TTY_DRIVER_REAL_RAW;
1642 tty_set_operations(pc_driver, &pc_ops);
1644 pc_info->owner = THIS_MODULE;
1645 pc_info->name = "digi_ctl";
1646 pc_info->major = DIGIINFOMAJOR;
1647 pc_info->minor_start = 0;
1648 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1649 pc_info->subtype = SERIAL_TYPE_INFO;
1650 pc_info->init_termios = tty_std_termios;
1651 pc_info->init_termios.c_iflag = 0;
1652 pc_info->init_termios.c_oflag = 0;
1653 pc_info->init_termios.c_lflag = 0;
1654 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1655 pc_info->flags = TTY_DRIVER_REAL_RAW;
1656 tty_set_operations(pc_info, &info_ops);
1659 save_flags(flags);
1660 cli();
1662 for (crd = 0; crd < num_cards; crd++)
1663 { /* Begin for each card */
1665 /* ------------------------------------------------------------------
1666 This is where the appropriate memory handlers for the hardware is
1667 set. Everything at runtime blindly jumps through these vectors.
1668 ---------------------------------------------------------------------- */
1670 /* defined in epcaconfig.h */
1671 bd = &boards[crd];
1673 switch (bd->type)
1674 { /* Begin switch on bd->type {board type} */
1675 case PCXEM:
1676 case EISAXEM:
1677 bd->memwinon = pcxem_memwinon ;
1678 bd->memwinoff = pcxem_memwinoff ;
1679 bd->globalwinon = pcxem_globalwinon ;
1680 bd->txwinon = pcxem_txwinon ;
1681 bd->rxwinon = pcxem_rxwinon ;
1682 bd->memoff = pcxem_memoff ;
1683 bd->assertgwinon = dummy_assertgwinon;
1684 bd->assertmemoff = dummy_assertmemoff;
1685 break;
1687 case PCIXEM:
1688 case PCIXRJ:
1689 case PCIXR:
1690 bd->memwinon = dummy_memwinon;
1691 bd->memwinoff = dummy_memwinoff;
1692 bd->globalwinon = dummy_globalwinon;
1693 bd->txwinon = dummy_txwinon;
1694 bd->rxwinon = dummy_rxwinon;
1695 bd->memoff = dummy_memoff;
1696 bd->assertgwinon = dummy_assertgwinon;
1697 bd->assertmemoff = dummy_assertmemoff;
1698 break;
1700 case PCXE:
1701 case PCXEVE:
1703 bd->memwinon = pcxe_memwinon;
1704 bd->memwinoff = pcxe_memwinoff;
1705 bd->globalwinon = pcxe_globalwinon;
1706 bd->txwinon = pcxe_txwinon;
1707 bd->rxwinon = pcxe_rxwinon;
1708 bd->memoff = pcxe_memoff;
1709 bd->assertgwinon = dummy_assertgwinon;
1710 bd->assertmemoff = dummy_assertmemoff;
1711 break;
1713 case PCXI:
1714 case PC64XE:
1716 bd->memwinon = pcxi_memwinon;
1717 bd->memwinoff = pcxi_memwinoff;
1718 bd->globalwinon = pcxi_globalwinon;
1719 bd->txwinon = pcxi_txwinon;
1720 bd->rxwinon = pcxi_rxwinon;
1721 bd->memoff = pcxi_memoff;
1722 bd->assertgwinon = pcxi_assertgwinon;
1723 bd->assertmemoff = pcxi_assertmemoff;
1724 break;
1726 default:
1727 break;
1729 } /* End switch on bd->type */
1731 /* ---------------------------------------------------------------
1732 Some cards need a memory segment to be defined for use in
1733 transmit and receive windowing operations. These boards
1734 are listed in the below switch. In the case of the XI the
1735 amount of memory on the board is variable so the memory_seg
1736 is also variable. This code determines what they segment
1737 should be.
1738 ----------------------------------------------------------------- */
1740 switch (bd->type)
1741 { /* Begin switch on bd->type {board type} */
1743 case PCXE:
1744 case PCXEVE:
1745 case PC64XE:
1746 bd->memory_seg = 0xf000;
1747 break;
1749 case PCXI:
1750 board_id = inb((int)bd->port);
1751 if ((board_id & 0x1) == 0x1)
1752 { /* Begin it's an XI card */
1754 /* Is it a 64K board */
1755 if ((board_id & 0x30) == 0)
1756 bd->memory_seg = 0xf000;
1758 /* Is it a 128K board */
1759 if ((board_id & 0x30) == 0x10)
1760 bd->memory_seg = 0xe000;
1762 /* Is is a 256K board */
1763 if ((board_id & 0x30) == 0x20)
1764 bd->memory_seg = 0xc000;
1766 /* Is it a 512K board */
1767 if ((board_id & 0x30) == 0x30)
1768 bd->memory_seg = 0x8000;
1770 } /* End it is an XI card */
1771 else
1773 printk(KERN_ERR "<Error> - Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
1775 break;
1777 } /* End switch on bd->type */
1779 } /* End for each card */
1781 if (tty_register_driver(pc_driver))
1782 panic("Couldn't register Digi PC/ driver");
1784 if (tty_register_driver(pc_info))
1785 panic("Couldn't register Digi PC/ info ");
1787 /* -------------------------------------------------------------------
1788 Start up the poller to check for events on all enabled boards
1789 ---------------------------------------------------------------------- */
1791 init_timer(&epca_timer);
1792 epca_timer.function = epcapoll;
1793 mod_timer(&epca_timer, jiffies + HZ/25);
1795 restore_flags(flags);
1797 return 0;
1799 } /* End pc_init */
1801 /* ------------------ Begin post_fep_init ---------------------- */
1803 static void post_fep_init(unsigned int crd)
1804 { /* Begin post_fep_init */
1806 int i;
1807 unchar *memaddr;
1808 volatile struct global_data *gd;
1809 struct board_info *bd;
1810 volatile struct board_chan *bc;
1811 struct channel *ch;
1812 int shrinkmem = 0, lowwater ;
1814 /* -------------------------------------------------------------
1815 This call is made by the user via. the ioctl call DIGI_INIT.
1816 It is responsible for setting up all the card specific stuff.
1817 ---------------------------------------------------------------- */
1818 bd = &boards[crd];
1820 /* -----------------------------------------------------------------
1821 If this is a PCI board, get the port info. Remember PCI cards
1822 do not have entries into the epcaconfig.h file, so we can't get
1823 the number of ports from it. Unfortunetly, this means that anyone
1824 doing a DIGI_GETINFO before the board has booted will get an invalid
1825 number of ports returned (It should return 0). Calls to DIGI_GETINFO
1826 after DIGI_INIT has been called will return the proper values.
1827 ------------------------------------------------------------------- */
1829 if (bd->type >= PCIXEM) /* If the board in question is PCI */
1830 { /* Begin get PCI number of ports */
1832 /* --------------------------------------------------------------------
1833 Below we use XEMPORTS as a memory offset regardless of which PCI
1834 card it is. This is because all of the supported PCI cards have
1835 the same memory offset for the channel data. This will have to be
1836 changed if we ever develop a PCI/XE card. NOTE : The FEP manual
1837 states that the port offset is 0xC22 as opposed to 0xC02. This is
1838 only true for PC/XE, and PC/XI cards; not for the XEM, or CX series.
1839 On the PCI cards the number of ports is determined by reading a
1840 ID PROM located in the box attached to the card. The card can then
1841 determine the index the id to determine the number of ports available.
1842 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
1843 if the box in question is a XEM or CX)).
1844 ------------------------------------------------------------------------ */
1846 bd->numports = (unsigned short)*(unsigned char *)bus_to_virt((unsigned long)
1847 (bd->re_map_membase + XEMPORTS));
1850 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1851 nbdevs += (bd->numports);
1853 } /* End get PCI number of ports */
1855 if (crd != 0)
1856 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1857 else
1858 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1860 ch = card_ptr[crd];
1863 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1865 memaddr = (unchar *)bd->re_map_membase;
1868 The below command is necessary because newer kernels (2.1.x and
1869 up) do not have a 1:1 virtual to physical mapping. The below
1870 call adjust for that.
1873 memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
1875 /* -----------------------------------------------------------------
1876 The below assignment will set bc to point at the BEGINING of
1877 the cards channel structures. For 1 card there will be between
1878 8 and 64 of these structures.
1879 -------------------------------------------------------------------- */
1881 bc = (volatile struct board_chan *)((ulong)memaddr + CHANSTRUCT);
1883 /* -------------------------------------------------------------------
1884 The below assignment will set gd to point at the BEGINING of
1885 global memory address 0xc00. The first data in that global
1886 memory actually starts at address 0xc1a. The command in
1887 pointer begins at 0xd10.
1888 ---------------------------------------------------------------------- */
1890 gd = (volatile struct global_data *)((ulong)memaddr + GLOBAL);
1892 /* --------------------------------------------------------------------
1893 XEPORTS (address 0xc22) points at the number of channels the
1894 card supports. (For 64XE, XI, XEM, and XR use 0xc02)
1895 ----------------------------------------------------------------------- */
1897 if (((bd->type == PCXEVE) | (bd->type == PCXE)) &&
1898 (*(ushort *)((ulong)memaddr + XEPORTS) < 3))
1899 shrinkmem = 1;
1900 if (bd->type < PCIXEM)
1901 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1902 return;
1904 memwinon(bd, 0);
1906 /* --------------------------------------------------------------------
1907 Remember ch is the main drivers channels structure, while bc is
1908 the cards channel structure.
1909 ------------------------------------------------------------------------ */
1911 /* For every port on the card do ..... */
1913 for (i = 0; i < bd->numports; i++, ch++, bc++)
1914 { /* Begin for each port */
1916 ch->brdchan = bc;
1917 ch->mailbox = gd;
1918 INIT_WORK(&ch->tqueue, do_softint, ch);
1919 ch->board = &boards[crd];
1921 switch (bd->type)
1922 { /* Begin switch bd->type */
1924 /* ----------------------------------------------------------------
1925 Since some of the boards use different bitmaps for their
1926 control signals we cannot hard code these values and retain
1927 portability. We virtualize this data here.
1928 ------------------------------------------------------------------- */
1929 case EISAXEM:
1930 case PCXEM:
1931 case PCIXEM:
1932 case PCIXRJ:
1933 case PCIXR:
1934 ch->m_rts = 0x02 ;
1935 ch->m_dcd = 0x80 ;
1936 ch->m_dsr = 0x20 ;
1937 ch->m_cts = 0x10 ;
1938 ch->m_ri = 0x40 ;
1939 ch->m_dtr = 0x01 ;
1940 break;
1942 case PCXE:
1943 case PCXEVE:
1944 case PCXI:
1945 case PC64XE:
1946 ch->m_rts = 0x02 ;
1947 ch->m_dcd = 0x08 ;
1948 ch->m_dsr = 0x10 ;
1949 ch->m_cts = 0x20 ;
1950 ch->m_ri = 0x40 ;
1951 ch->m_dtr = 0x80 ;
1952 break;
1954 } /* End switch bd->type */
1956 if (boards[crd].altpin)
1958 ch->dsr = ch->m_dcd;
1959 ch->dcd = ch->m_dsr;
1960 ch->digiext.digi_flags |= DIGI_ALTPIN;
1962 else
1964 ch->dcd = ch->m_dcd;
1965 ch->dsr = ch->m_dsr;
1968 ch->boardnum = crd;
1969 ch->channelnum = i;
1970 ch->magic = EPCA_MAGIC;
1971 ch->tty = NULL;
1973 if (shrinkmem)
1975 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1976 shrinkmem = 0;
1979 switch (bd->type)
1980 { /* Begin switch bd->type */
1982 case PCIXEM:
1983 case PCIXRJ:
1984 case PCIXR:
1985 /* Cover all the 2MEG cards */
1986 ch->txptr = memaddr + (((bc->tseg) << 4) & 0x1fffff);
1987 ch->rxptr = memaddr + (((bc->rseg) << 4) & 0x1fffff);
1988 ch->txwin = FEPWIN | ((bc->tseg) >> 11);
1989 ch->rxwin = FEPWIN | ((bc->rseg) >> 11);
1990 break;
1992 case PCXEM:
1993 case EISAXEM:
1994 /* Cover all the 32K windowed cards */
1995 /* Mask equal to window size - 1 */
1996 ch->txptr = memaddr + (((bc->tseg) << 4) & 0x7fff);
1997 ch->rxptr = memaddr + (((bc->rseg) << 4) & 0x7fff);
1998 ch->txwin = FEPWIN | ((bc->tseg) >> 11);
1999 ch->rxwin = FEPWIN | ((bc->rseg) >> 11);
2000 break;
2002 case PCXEVE:
2003 case PCXE:
2004 ch->txptr = memaddr + (((bc->tseg - bd->memory_seg) << 4) & 0x1fff);
2005 ch->txwin = FEPWIN | ((bc->tseg - bd->memory_seg) >> 9);
2006 ch->rxptr = memaddr + (((bc->rseg - bd->memory_seg) << 4) & 0x1fff);
2007 ch->rxwin = FEPWIN | ((bc->rseg - bd->memory_seg) >>9 );
2008 break;
2010 case PCXI:
2011 case PC64XE:
2012 ch->txptr = memaddr + ((bc->tseg - bd->memory_seg) << 4);
2013 ch->rxptr = memaddr + ((bc->rseg - bd->memory_seg) << 4);
2014 ch->txwin = ch->rxwin = 0;
2015 break;
2017 } /* End switch bd->type */
2019 ch->txbufhead = 0;
2020 ch->txbufsize = bc->tmax + 1;
2022 ch->rxbufhead = 0;
2023 ch->rxbufsize = bc->rmax + 1;
2025 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
2027 /* Set transmitter low water mark */
2028 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
2030 /* Set receiver low water mark */
2032 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
2034 /* Set receiver high water mark */
2036 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
2038 bc->edelay = 100;
2039 bc->idata = 1;
2041 ch->startc = bc->startc;
2042 ch->stopc = bc->stopc;
2043 ch->startca = bc->startca;
2044 ch->stopca = bc->stopca;
2046 ch->fepcflag = 0;
2047 ch->fepiflag = 0;
2048 ch->fepoflag = 0;
2049 ch->fepstartc = 0;
2050 ch->fepstopc = 0;
2051 ch->fepstartca = 0;
2052 ch->fepstopca = 0;
2054 ch->close_delay = 50;
2055 ch->count = 0;
2056 ch->blocked_open = 0;
2057 init_waitqueue_head(&ch->open_wait);
2058 init_waitqueue_head(&ch->close_wait);
2059 ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL);
2060 if (!(ch->tmp_buf))
2062 printk(KERN_ERR "POST FEP INIT : kmalloc failed for port 0x%x\n",i);
2063 release_region((int)bd->port, 4);
2064 while(i-- > 0)
2065 kfree((ch--)->tmp_buf);
2066 return;
2068 else
2069 memset((void *)ch->tmp_buf,0,ch->txbufsize);
2070 } /* End for each port */
2072 printk(KERN_INFO
2073 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
2074 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
2075 sprintf(mesg,
2076 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
2077 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
2078 console_print(mesg);
2080 memwinoff(bd, 0);
2082 } /* End post_fep_init */
2084 /* --------------------- Begin epcapoll ------------------------ */
2086 static void epcapoll(unsigned long ignored)
2087 { /* Begin epcapoll */
2089 unsigned long flags;
2090 int crd;
2091 volatile unsigned int head, tail;
2092 struct channel *ch;
2093 struct board_info *bd;
2095 /* -------------------------------------------------------------------
2096 This routine is called upon every timer interrupt. Even though
2097 the Digi series cards are capable of generating interrupts this
2098 method of non-looping polling is more efficient. This routine
2099 checks for card generated events (Such as receive data, are transmit
2100 buffer empty) and acts on those events.
2101 ----------------------------------------------------------------------- */
2103 save_flags(flags);
2104 cli();
2106 for (crd = 0; crd < num_cards; crd++)
2107 { /* Begin for each card */
2109 bd = &boards[crd];
2110 ch = card_ptr[crd];
2112 if ((bd->status == DISABLED) || digi_poller_inhibited)
2113 continue; /* Begin loop next interation */
2115 /* -----------------------------------------------------------
2116 assertmemoff is not needed here; indeed it is an empty subroutine.
2117 It is being kept because future boards may need this as well as
2118 some legacy boards.
2119 ---------------------------------------------------------------- */
2121 assertmemoff(ch);
2123 globalwinon(ch);
2125 /* ---------------------------------------------------------------
2126 In this case head and tail actually refer to the event queue not
2127 the transmit or receive queue.
2128 ------------------------------------------------------------------- */
2130 head = ch->mailbox->ein;
2131 tail = ch->mailbox->eout;
2133 /* If head isn't equal to tail we have an event */
2135 if (head != tail)
2136 doevent(crd);
2138 memoff(ch);
2140 } /* End for each card */
2142 mod_timer(&epca_timer, jiffies + (HZ / 25));
2144 restore_flags(flags);
2145 } /* End epcapoll */
2147 /* --------------------- Begin doevent ------------------------ */
2149 static void doevent(int crd)
2150 { /* Begin doevent */
2152 volatile unchar *eventbuf;
2153 struct channel *ch, *chan0;
2154 static struct tty_struct *tty;
2155 volatile struct board_info *bd;
2156 volatile struct board_chan *bc;
2157 register volatile unsigned int tail, head;
2158 register int event, channel;
2159 register int mstat, lstat;
2161 /* -------------------------------------------------------------------
2162 This subroutine is called by epcapoll when an event is detected
2163 in the event queue. This routine responds to those events.
2164 --------------------------------------------------------------------- */
2166 bd = &boards[crd];
2168 chan0 = card_ptr[crd];
2169 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
2171 assertgwinon(chan0);
2173 while ((tail = chan0->mailbox->eout) != (head = chan0->mailbox->ein))
2174 { /* Begin while something in event queue */
2176 assertgwinon(chan0);
2178 eventbuf = (volatile unchar *)bus_to_virt((ulong)(bd->re_map_membase + tail + ISTART));
2180 /* Get the channel the event occurred on */
2181 channel = eventbuf[0];
2183 /* Get the actual event code that occurred */
2184 event = eventbuf[1];
2186 /* ----------------------------------------------------------------
2187 The two assignments below get the current modem status (mstat)
2188 and the previous modem status (lstat). These are useful becuase
2189 an event could signal a change in modem signals itself.
2190 ------------------------------------------------------------------- */
2192 mstat = eventbuf[2];
2193 lstat = eventbuf[3];
2195 ch = chan0 + channel;
2197 if ((unsigned)channel >= bd->numports || !ch)
2199 if (channel >= bd->numports)
2200 ch = chan0;
2201 bc = ch->brdchan;
2202 goto next;
2205 if ((bc = ch->brdchan) == NULL)
2206 goto next;
2208 if (event & DATA_IND)
2209 { /* Begin DATA_IND */
2211 receive_data(ch);
2212 assertgwinon(ch);
2214 } /* End DATA_IND */
2215 /* else *//* Fix for DCD transition missed bug */
2216 if (event & MODEMCHG_IND)
2217 { /* Begin MODEMCHG_IND */
2219 /* A modem signal change has been indicated */
2221 ch->imodem = mstat;
2223 if (ch->asyncflags & ASYNC_CHECK_CD)
2225 if (mstat & ch->dcd) /* We are now receiving dcd */
2226 wake_up_interruptible(&ch->open_wait);
2227 else
2228 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
2231 } /* End MODEMCHG_IND */
2233 tty = ch->tty;
2234 if (tty)
2235 { /* Begin if valid tty */
2237 if (event & BREAK_IND)
2238 { /* Begin if BREAK_IND */
2240 /* A break has been indicated */
2242 tty->flip.count++;
2243 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
2245 *tty->flip.char_buf_ptr++ = 0;
2247 tty_schedule_flip(tty);
2249 } /* End if BREAK_IND */
2250 else
2251 if (event & LOWTX_IND)
2252 { /* Begin LOWTX_IND */
2254 if (ch->statusflags & LOWWAIT)
2255 { /* Begin if LOWWAIT */
2257 ch->statusflags &= ~LOWWAIT;
2258 tty_wakeup(tty);
2259 wake_up_interruptible(&tty->write_wait);
2261 } /* End if LOWWAIT */
2263 } /* End LOWTX_IND */
2264 else
2265 if (event & EMPTYTX_IND)
2266 { /* Begin EMPTYTX_IND */
2268 /* This event is generated by setup_empty_event */
2270 ch->statusflags &= ~TXBUSY;
2271 if (ch->statusflags & EMPTYWAIT)
2272 { /* Begin if EMPTYWAIT */
2274 ch->statusflags &= ~EMPTYWAIT;
2275 tty_wakeup(tty);
2277 wake_up_interruptible(&tty->write_wait);
2279 } /* End if EMPTYWAIT */
2281 } /* End EMPTYTX_IND */
2283 } /* End if valid tty */
2286 next:
2287 globalwinon(ch);
2289 if (!bc)
2290 printk(KERN_ERR "<Error> - bc == NULL in doevent!\n");
2291 else
2292 bc->idata = 1;
2294 chan0->mailbox->eout = (tail + 4) & (IMAX - ISTART - 4);
2295 globalwinon(chan0);
2297 } /* End while something in event queue */
2299 } /* End doevent */
2301 /* --------------------- Begin fepcmd ------------------------ */
2303 static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
2304 int byte2, int ncmds, int bytecmd)
2305 { /* Begin fepcmd */
2307 unchar *memaddr;
2308 unsigned int head, cmdTail, cmdStart, cmdMax;
2309 long count;
2310 int n;
2312 /* This is the routine in which commands may be passed to the card. */
2314 if (ch->board->status == DISABLED)
2316 return;
2319 assertgwinon(ch);
2321 /* Remember head (As well as max) is just an offset not a base addr */
2322 head = ch->mailbox->cin;
2324 /* cmdStart is a base address */
2325 cmdStart = ch->mailbox->cstart;
2327 /* ------------------------------------------------------------------
2328 We do the addition below because we do not want a max pointer
2329 relative to cmdStart. We want a max pointer that points at the
2330 physical end of the command queue.
2331 -------------------------------------------------------------------- */
2333 cmdMax = (cmdStart + 4 + (ch->mailbox->cmax));
2335 memaddr = ch->board->re_map_membase;
2338 The below command is necessary because newer kernels (2.1.x and
2339 up) do not have a 1:1 virtual to physical mapping. The below
2340 call adjust for that.
2343 memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
2345 if (head >= (cmdMax - cmdStart) || (head & 03))
2347 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__,
2348 cmd, head);
2349 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__,
2350 cmdMax, cmdStart);
2351 return;
2354 if (bytecmd)
2356 *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
2358 *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
2359 /* Below word_or_byte is bits to set */
2360 *(volatile unchar *)(memaddr + head + cmdStart + 2) = (unchar)word_or_byte;
2361 /* Below byte2 is bits to reset */
2362 *(volatile unchar *)(memaddr + head + cmdStart + 3) = (unchar)byte2;
2365 else
2367 *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
2368 *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
2369 *(volatile ushort*)(memaddr + head + cmdStart + 2) = (ushort)word_or_byte;
2372 head = (head + 4) & (cmdMax - cmdStart - 4);
2373 ch->mailbox->cin = head;
2375 count = FEPTIMEOUT;
2377 for (;;)
2378 { /* Begin forever loop */
2380 count--;
2381 if (count == 0)
2383 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
2384 return;
2387 head = ch->mailbox->cin;
2388 cmdTail = ch->mailbox->cout;
2390 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
2392 /* ----------------------------------------------------------
2393 Basically this will break when the FEP acknowledges the
2394 command by incrementing cmdTail (Making it equal to head).
2395 ------------------------------------------------------------- */
2397 if (n <= ncmds * (sizeof(short) * 4))
2398 break; /* Well nearly forever :-) */
2400 } /* End forever loop */
2402 } /* End fepcmd */
2404 /* ---------------------------------------------------------------------
2405 Digi products use fields in their channels structures that are very
2406 similar to the c_cflag and c_iflag fields typically found in UNIX
2407 termios structures. The below three routines allow mappings
2408 between these hardware "flags" and their respective Linux flags.
2409 ------------------------------------------------------------------------- */
2411 /* --------------------- Begin termios2digi_h -------------------- */
2413 static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
2414 { /* Begin termios2digi_h */
2416 unsigned res = 0;
2418 if (cflag & CRTSCTS)
2420 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
2421 res |= ((ch->m_cts) | (ch->m_rts));
2424 if (ch->digiext.digi_flags & RTSPACE)
2425 res |= ch->m_rts;
2427 if (ch->digiext.digi_flags & DTRPACE)
2428 res |= ch->m_dtr;
2430 if (ch->digiext.digi_flags & CTSPACE)
2431 res |= ch->m_cts;
2433 if (ch->digiext.digi_flags & DSRPACE)
2434 res |= ch->dsr;
2436 if (ch->digiext.digi_flags & DCDPACE)
2437 res |= ch->dcd;
2439 if (res & (ch->m_rts))
2440 ch->digiext.digi_flags |= RTSPACE;
2442 if (res & (ch->m_cts))
2443 ch->digiext.digi_flags |= CTSPACE;
2445 return res;
2447 } /* End termios2digi_h */
2449 /* --------------------- Begin termios2digi_i -------------------- */
2450 static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
2451 { /* Begin termios2digi_i */
2453 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
2454 INPCK | ISTRIP|IXON|IXANY|IXOFF);
2456 if (ch->digiext.digi_flags & DIGI_AIXON)
2457 res |= IAIXON;
2458 return res;
2460 } /* End termios2digi_i */
2462 /* --------------------- Begin termios2digi_c -------------------- */
2464 static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
2465 { /* Begin termios2digi_c */
2467 unsigned res = 0;
2469 #ifdef SPEED_HACK
2470 /* CL: HACK to force 115200 at 38400 and 57600 at 19200 Baud */
2471 if ((cflag & CBAUD)== B38400) cflag=cflag - B38400 + B115200;
2472 if ((cflag & CBAUD)== B19200) cflag=cflag - B19200 + B57600;
2473 #endif /* SPEED_HACK */
2475 if (cflag & CBAUDEX)
2476 { /* Begin detected CBAUDEX */
2478 ch->digiext.digi_flags |= DIGI_FAST;
2480 /* -------------------------------------------------------------
2481 HUPCL bit is used by FEP to indicate fast baud
2482 table is to be used.
2483 ----------------------------------------------------------------- */
2485 res |= FEP_HUPCL;
2487 } /* End detected CBAUDEX */
2488 else ch->digiext.digi_flags &= ~DIGI_FAST;
2490 /* -------------------------------------------------------------------
2491 CBAUD has bit position 0x1000 set these days to indicate Linux
2492 baud rate remap. Digi hardware can't handle the bit assignment.
2493 (We use a different bit assignment for high speed.). Clear this
2494 bit out.
2495 ---------------------------------------------------------------------- */
2496 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
2498 /* -------------------------------------------------------------
2499 This gets a little confusing. The Digi cards have their own
2500 representation of c_cflags controling baud rate. For the most
2501 part this is identical to the Linux implementation. However;
2502 Digi supports one rate (76800) that Linux doesn't. This means
2503 that the c_cflag entry that would normally mean 76800 for Digi
2504 actually means 115200 under Linux. Without the below mapping,
2505 a stty 115200 would only drive the board at 76800. Since
2506 the rate 230400 is also found after 76800, the same problem afflicts
2507 us when we choose a rate of 230400. Without the below modificiation
2508 stty 230400 would actually give us 115200.
2510 There are two additional differences. The Linux value for CLOCAL
2511 (0x800; 0004000) has no meaning to the Digi hardware. Also in
2512 later releases of Linux; the CBAUD define has CBAUDEX (0x1000;
2513 0010000) ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX
2514 should be checked for a screened out prior to termios2digi_c
2515 returning. Since CLOCAL isn't used by the board this can be
2516 ignored as long as the returned value is used only by Digi hardware.
2517 ----------------------------------------------------------------- */
2519 if (cflag & CBAUDEX)
2521 /* -------------------------------------------------------------
2522 The below code is trying to guarantee that only baud rates
2523 115200 and 230400 are remapped. We use exclusive or because
2524 the various baud rates share common bit positions and therefore
2525 can't be tested for easily.
2526 ----------------------------------------------------------------- */
2529 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
2530 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
2532 res += 1;
2536 return res;
2538 } /* End termios2digi_c */
2540 /* --------------------- Begin epcaparam ----------------------- */
2542 static void epcaparam(struct tty_struct *tty, struct channel *ch)
2543 { /* Begin epcaparam */
2545 unsigned int cmdHead;
2546 struct termios *ts;
2547 volatile struct board_chan *bc;
2548 unsigned mval, hflow, cflag, iflag;
2550 bc = ch->brdchan;
2551 epcaassert(bc !=0, "bc out of range");
2553 assertgwinon(ch);
2555 ts = tty->termios;
2557 if ((ts->c_cflag & CBAUD) == 0)
2558 { /* Begin CBAUD detected */
2560 cmdHead = bc->rin;
2561 bc->rout = cmdHead;
2562 cmdHead = bc->tin;
2564 /* Changing baud in mid-stream transmission can be wonderful */
2565 /* ---------------------------------------------------------------
2566 Flush current transmit buffer by setting cmdTail pointer (tout)
2567 to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
2568 ----------------------------------------------------------------- */
2570 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
2571 mval = 0;
2573 } /* End CBAUD detected */
2574 else
2575 { /* Begin CBAUD not detected */
2577 /* -------------------------------------------------------------------
2578 c_cflags have changed but that change had nothing to do with BAUD.
2579 Propagate the change to the card.
2580 ---------------------------------------------------------------------- */
2582 cflag = termios2digi_c(ch, ts->c_cflag);
2584 if (cflag != ch->fepcflag)
2586 ch->fepcflag = cflag;
2587 /* Set baud rate, char size, stop bits, parity */
2588 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
2592 /* ----------------------------------------------------------------
2593 If the user has not forced CLOCAL and if the device is not a
2594 CALLOUT device (Which is always CLOCAL) we set flags such that
2595 the driver will wait on carrier detect.
2596 ------------------------------------------------------------------- */
2598 if (ts->c_cflag & CLOCAL)
2599 { /* Begin it is a cud device or a ttyD device with CLOCAL on */
2600 ch->asyncflags &= ~ASYNC_CHECK_CD;
2601 } /* End it is a cud device or a ttyD device with CLOCAL on */
2602 else
2603 { /* Begin it is a ttyD device */
2604 ch->asyncflags |= ASYNC_CHECK_CD;
2605 } /* End it is a ttyD device */
2607 mval = ch->m_dtr | ch->m_rts;
2609 } /* End CBAUD not detected */
2611 iflag = termios2digi_i(ch, ts->c_iflag);
2613 /* Check input mode flags */
2615 if (iflag != ch->fepiflag)
2617 ch->fepiflag = iflag;
2619 /* ---------------------------------------------------------------
2620 Command sets channels iflag structure on the board. Such things
2621 as input soft flow control, handling of parity errors, and
2622 break handling are all set here.
2623 ------------------------------------------------------------------- */
2625 /* break handling, parity handling, input stripping, flow control chars */
2626 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
2629 /* ---------------------------------------------------------------
2630 Set the board mint value for this channel. This will cause hardware
2631 events to be generated each time the DCD signal (Described in mint)
2632 changes.
2633 ------------------------------------------------------------------- */
2634 bc->mint = ch->dcd;
2636 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
2637 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
2638 bc->mint = 0;
2640 ch->imodem = bc->mstat;
2642 hflow = termios2digi_h(ch, ts->c_cflag);
2644 if (hflow != ch->hflow)
2646 ch->hflow = hflow;
2648 /* --------------------------------------------------------------
2649 Hard flow control has been selected but the board is not
2650 using it. Activate hard flow control now.
2651 ----------------------------------------------------------------- */
2653 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
2657 mval ^= ch->modemfake & (mval ^ ch->modem);
2659 if (ch->omodem ^ mval)
2661 ch->omodem = mval;
2663 /* --------------------------------------------------------------
2664 The below command sets the DTR and RTS mstat structure. If
2665 hard flow control is NOT active these changes will drive the
2666 output of the actual DTR and RTS lines. If hard flow control
2667 is active, the changes will be saved in the mstat structure and
2668 only asserted when hard flow control is turned off.
2669 ----------------------------------------------------------------- */
2671 /* First reset DTR & RTS; then set them */
2672 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
2673 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
2677 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc)
2679 ch->fepstartc = ch->startc;
2680 ch->fepstopc = ch->stopc;
2682 /* ------------------------------------------------------------
2683 The XON / XOFF characters have changed; propagate these
2684 changes to the card.
2685 --------------------------------------------------------------- */
2687 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
2690 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca)
2692 ch->fepstartca = ch->startca;
2693 ch->fepstopca = ch->stopca;
2695 /* ---------------------------------------------------------------
2696 Similar to the above, this time the auxilarly XON / XOFF
2697 characters have changed; propagate these changes to the card.
2698 ------------------------------------------------------------------ */
2700 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2703 } /* End epcaparam */
2705 /* --------------------- Begin receive_data ----------------------- */
2707 static void receive_data(struct channel *ch)
2708 { /* Begin receive_data */
2710 unchar *rptr;
2711 struct termios *ts = NULL;
2712 struct tty_struct *tty;
2713 volatile struct board_chan *bc;
2714 register int dataToRead, wrapgap, bytesAvailable;
2715 register unsigned int tail, head;
2716 unsigned int wrapmask;
2717 int rc;
2720 /* ---------------------------------------------------------------
2721 This routine is called by doint when a receive data event
2722 has taken place.
2723 ------------------------------------------------------------------- */
2725 globalwinon(ch);
2727 if (ch->statusflags & RXSTOPPED)
2728 return;
2730 tty = ch->tty;
2731 if (tty)
2732 ts = tty->termios;
2734 bc = ch->brdchan;
2736 if (!bc)
2738 printk(KERN_ERR "<Error> - bc is NULL in receive_data!\n");
2739 return;
2742 wrapmask = ch->rxbufsize - 1;
2744 /* ---------------------------------------------------------------------
2745 Get the head and tail pointers to the receiver queue. Wrap the
2746 head pointer if it has reached the end of the buffer.
2747 ------------------------------------------------------------------------ */
2749 head = bc->rin;
2750 head &= wrapmask;
2751 tail = bc->rout & wrapmask;
2753 bytesAvailable = (head - tail) & wrapmask;
2755 if (bytesAvailable == 0)
2756 return;
2758 /* ------------------------------------------------------------------
2759 If CREAD bit is off or device not open, set TX tail to head
2760 --------------------------------------------------------------------- */
2762 if (!tty || !ts || !(ts->c_cflag & CREAD))
2764 bc->rout = head;
2765 return;
2768 if (tty->flip.count == TTY_FLIPBUF_SIZE)
2769 return;
2771 if (bc->orun)
2773 bc->orun = 0;
2774 printk(KERN_WARNING "overrun! DigiBoard device %s\n",tty->name);
2777 rxwinon(ch);
2778 rptr = tty->flip.char_buf_ptr;
2779 rc = tty->flip.count;
2781 while (bytesAvailable > 0)
2782 { /* Begin while there is data on the card */
2784 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
2786 /* ---------------------------------------------------------------
2787 Even if head has wrapped around only report the amount of
2788 data to be equal to the size - tail. Remember memcpy can't
2789 automaticly wrap around the receive buffer.
2790 ----------------------------------------------------------------- */
2792 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
2794 /* --------------------------------------------------------------
2795 Make sure we don't overflow the buffer
2796 ----------------------------------------------------------------- */
2798 if ((rc + dataToRead) > TTY_FLIPBUF_SIZE)
2799 dataToRead = TTY_FLIPBUF_SIZE - rc;
2801 if (dataToRead == 0)
2802 break;
2804 /* ---------------------------------------------------------------
2805 Move data read from our card into the line disciplines buffer
2806 for translation if necessary.
2807 ------------------------------------------------------------------ */
2809 if ((memcpy(rptr, ch->rxptr + tail, dataToRead)) != rptr)
2810 printk(KERN_ERR "<Error> - receive_data : memcpy failed\n");
2812 rc += dataToRead;
2813 rptr += dataToRead;
2814 tail = (tail + dataToRead) & wrapmask;
2815 bytesAvailable -= dataToRead;
2817 } /* End while there is data on the card */
2820 tty->flip.count = rc;
2821 tty->flip.char_buf_ptr = rptr;
2822 globalwinon(ch);
2823 bc->rout = tail;
2825 /* Must be called with global data */
2826 tty_schedule_flip(ch->tty);
2827 return;
2829 } /* End receive_data */
2831 static int info_ioctl(struct tty_struct *tty, struct file * file,
2832 unsigned int cmd, unsigned long arg)
2834 switch (cmd)
2835 { /* Begin switch cmd */
2837 case DIGI_GETINFO:
2838 { /* Begin case DIGI_GETINFO */
2840 struct digi_info di ;
2841 int brd;
2843 getUser(brd, (unsigned int __user *)arg);
2845 if ((brd < 0) || (brd >= num_cards) || (num_cards == 0))
2846 return (-ENODEV);
2848 memset(&di, 0, sizeof(di));
2850 di.board = brd ;
2851 di.status = boards[brd].status;
2852 di.type = boards[brd].type ;
2853 di.numports = boards[brd].numports ;
2854 di.port = boards[brd].port ;
2855 di.membase = boards[brd].membase ;
2857 if (copy_to_user((void __user *)arg, &di, sizeof (di)))
2858 return -EFAULT;
2859 break;
2861 } /* End case DIGI_GETINFO */
2863 case DIGI_POLLER:
2864 { /* Begin case DIGI_POLLER */
2866 int brd = arg & 0xff000000 >> 16 ;
2867 unsigned char state = arg & 0xff ;
2869 if ((brd < 0) || (brd >= num_cards))
2871 printk(KERN_ERR "<Error> - DIGI POLLER : brd not valid!\n");
2872 return (-ENODEV);
2875 digi_poller_inhibited = state ;
2876 break ;
2878 } /* End case DIGI_POLLER */
2880 case DIGI_INIT:
2881 { /* Begin case DIGI_INIT */
2883 /* ------------------------------------------------------------
2884 This call is made by the apps to complete the initilization
2885 of the board(s). This routine is responsible for setting
2886 the card to its initial state and setting the drivers control
2887 fields to the sutianle settings for the card in question.
2888 ---------------------------------------------------------------- */
2890 int crd ;
2891 for (crd = 0; crd < num_cards; crd++)
2892 post_fep_init (crd);
2894 break ;
2896 } /* End case DIGI_INIT */
2899 default:
2900 return -ENOIOCTLCMD;
2902 } /* End switch cmd */
2903 return (0) ;
2905 /* --------------------- Begin pc_ioctl ----------------------- */
2907 static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2909 struct channel *ch = (struct channel *) tty->driver_data;
2910 volatile struct board_chan *bc;
2911 unsigned int mstat, mflag = 0;
2912 unsigned long flags;
2914 if (ch)
2915 bc = ch->brdchan;
2916 else
2918 printk(KERN_ERR "<Error> - ch is NULL in pc_tiocmget!\n");
2919 return(-EINVAL);
2922 save_flags(flags);
2923 cli();
2924 globalwinon(ch);
2925 mstat = bc->mstat;
2926 memoff(ch);
2927 restore_flags(flags);
2929 if (mstat & ch->m_dtr)
2930 mflag |= TIOCM_DTR;
2932 if (mstat & ch->m_rts)
2933 mflag |= TIOCM_RTS;
2935 if (mstat & ch->m_cts)
2936 mflag |= TIOCM_CTS;
2938 if (mstat & ch->dsr)
2939 mflag |= TIOCM_DSR;
2941 if (mstat & ch->m_ri)
2942 mflag |= TIOCM_RI;
2944 if (mstat & ch->dcd)
2945 mflag |= TIOCM_CD;
2947 return mflag;
2950 static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2951 unsigned int set, unsigned int clear)
2953 struct channel *ch = (struct channel *) tty->driver_data;
2954 unsigned long flags;
2956 if (!ch) {
2957 printk(KERN_ERR "<Error> - ch is NULL in pc_tiocmset!\n");
2958 return(-EINVAL);
2961 save_flags(flags);
2962 cli();
2964 * I think this modemfake stuff is broken. It doesn't
2965 * correctly reflect the behaviour desired by the TIOCM*
2966 * ioctls. Therefore this is probably broken.
2968 if (set & TIOCM_RTS) {
2969 ch->modemfake |= ch->m_rts;
2970 ch->modem |= ch->m_rts;
2972 if (set & TIOCM_DTR) {
2973 ch->modemfake |= ch->m_dtr;
2974 ch->modem |= ch->m_dtr;
2976 if (clear & TIOCM_RTS) {
2977 ch->modemfake |= ch->m_rts;
2978 ch->modem &= ~ch->m_rts;
2980 if (clear & TIOCM_DTR) {
2981 ch->modemfake |= ch->m_dtr;
2982 ch->modem &= ~ch->m_dtr;
2985 globalwinon(ch);
2987 /* --------------------------------------------------------------
2988 The below routine generally sets up parity, baud, flow control
2989 issues, etc.... It effect both control flags and input flags.
2990 ------------------------------------------------------------------ */
2992 epcaparam(tty,ch);
2993 memoff(ch);
2994 restore_flags(flags);
2995 return 0;
2998 static int pc_ioctl(struct tty_struct *tty, struct file * file,
2999 unsigned int cmd, unsigned long arg)
3000 { /* Begin pc_ioctl */
3002 digiflow_t dflow;
3003 int retval;
3004 unsigned long flags;
3005 unsigned int mflag, mstat;
3006 unsigned char startc, stopc;
3007 volatile struct board_chan *bc;
3008 struct channel *ch = (struct channel *) tty->driver_data;
3009 void __user *argp = (void __user *)arg;
3011 if (ch)
3012 bc = ch->brdchan;
3013 else
3015 printk(KERN_ERR "<Error> - ch is NULL in pc_ioctl!\n");
3016 return(-EINVAL);
3019 save_flags(flags);
3021 /* -------------------------------------------------------------------
3022 For POSIX compliance we need to add more ioctls. See tty_ioctl.c
3023 in /usr/src/linux/drivers/char for a good example. In particular
3024 think about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
3025 ---------------------------------------------------------------------- */
3027 switch (cmd)
3028 { /* Begin switch cmd */
3030 case TCGETS:
3031 if (copy_to_user(argp,
3032 tty->termios, sizeof(struct termios)))
3033 return -EFAULT;
3034 return(0);
3036 case TCGETA:
3037 return get_termio(tty, argp);
3039 case TCSBRK: /* SVID version: non-zero arg --> no break */
3041 retval = tty_check_change(tty);
3042 if (retval)
3043 return retval;
3045 /* Setup an event to indicate when the transmit buffer empties */
3047 setup_empty_event(tty,ch);
3048 tty_wait_until_sent(tty, 0);
3049 if (!arg)
3050 digi_send_break(ch, HZ/4); /* 1/4 second */
3051 return 0;
3053 case TCSBRKP: /* support for POSIX tcsendbreak() */
3055 retval = tty_check_change(tty);
3056 if (retval)
3057 return retval;
3059 /* Setup an event to indicate when the transmit buffer empties */
3061 setup_empty_event(tty,ch);
3062 tty_wait_until_sent(tty, 0);
3063 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
3064 return 0;
3066 case TIOCGSOFTCAR:
3067 if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg))
3068 return -EFAULT;
3069 return 0;
3071 case TIOCSSOFTCAR:
3073 unsigned int value;
3075 if (get_user(value, (unsigned __user *)argp))
3076 return -EFAULT;
3077 tty->termios->c_cflag =
3078 ((tty->termios->c_cflag & ~CLOCAL) |
3079 (value ? CLOCAL : 0));
3080 return 0;
3083 case TIOCMODG:
3084 mflag = pc_tiocmget(tty, file);
3085 if (put_user(mflag, (unsigned long __user *)argp))
3086 return -EFAULT;
3087 break;
3089 case TIOCMODS:
3090 if (get_user(mstat, (unsigned __user *)argp))
3091 return -EFAULT;
3092 return pc_tiocmset(tty, file, mstat, ~mstat);
3094 case TIOCSDTR:
3095 ch->omodem |= ch->m_dtr;
3096 cli();
3097 globalwinon(ch);
3098 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
3099 memoff(ch);
3100 restore_flags(flags);
3101 break;
3103 case TIOCCDTR:
3104 ch->omodem &= ~ch->m_dtr;
3105 cli();
3106 globalwinon(ch);
3107 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
3108 memoff(ch);
3109 restore_flags(flags);
3110 break;
3112 case DIGI_GETA:
3113 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
3114 return -EFAULT;
3115 break;
3117 case DIGI_SETAW:
3118 case DIGI_SETAF:
3119 if ((cmd) == (DIGI_SETAW))
3121 /* Setup an event to indicate when the transmit buffer empties */
3123 setup_empty_event(tty,ch);
3124 tty_wait_until_sent(tty, 0);
3126 else
3128 /* ldisc lock already held in ioctl */
3129 if (tty->ldisc.flush_buffer)
3130 tty->ldisc.flush_buffer(tty);
3133 /* Fall Thru */
3135 case DIGI_SETA:
3136 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
3137 return -EFAULT;
3139 if (ch->digiext.digi_flags & DIGI_ALTPIN)
3141 ch->dcd = ch->m_dsr;
3142 ch->dsr = ch->m_dcd;
3144 else
3146 ch->dcd = ch->m_dcd;
3147 ch->dsr = ch->m_dsr;
3150 cli();
3151 globalwinon(ch);
3153 /* -----------------------------------------------------------------
3154 The below routine generally sets up parity, baud, flow control
3155 issues, etc.... It effect both control flags and input flags.
3156 ------------------------------------------------------------------- */
3158 epcaparam(tty,ch);
3159 memoff(ch);
3160 restore_flags(flags);
3161 break;
3163 case DIGI_GETFLOW:
3164 case DIGI_GETAFLOW:
3165 cli();
3166 globalwinon(ch);
3167 if ((cmd) == (DIGI_GETFLOW))
3169 dflow.startc = bc->startc;
3170 dflow.stopc = bc->stopc;
3172 else
3174 dflow.startc = bc->startca;
3175 dflow.stopc = bc->stopca;
3177 memoff(ch);
3178 restore_flags(flags);
3180 if (copy_to_user(argp, &dflow, sizeof(dflow)))
3181 return -EFAULT;
3182 break;
3184 case DIGI_SETAFLOW:
3185 case DIGI_SETFLOW:
3186 if ((cmd) == (DIGI_SETFLOW))
3188 startc = ch->startc;
3189 stopc = ch->stopc;
3191 else
3193 startc = ch->startca;
3194 stopc = ch->stopca;
3197 if (copy_from_user(&dflow, argp, sizeof(dflow)))
3198 return -EFAULT;
3200 if (dflow.startc != startc || dflow.stopc != stopc)
3201 { /* Begin if setflow toggled */
3202 cli();
3203 globalwinon(ch);
3205 if ((cmd) == (DIGI_SETFLOW))
3207 ch->fepstartc = ch->startc = dflow.startc;
3208 ch->fepstopc = ch->stopc = dflow.stopc;
3209 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
3211 else
3213 ch->fepstartca = ch->startca = dflow.startc;
3214 ch->fepstopca = ch->stopca = dflow.stopc;
3215 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
3218 if (ch->statusflags & TXSTOPPED)
3219 pc_start(tty);
3221 memoff(ch);
3222 restore_flags(flags);
3224 } /* End if setflow toggled */
3225 break;
3227 default:
3228 return -ENOIOCTLCMD;
3230 } /* End switch cmd */
3232 return 0;
3234 } /* End pc_ioctl */
3236 /* --------------------- Begin pc_set_termios ----------------------- */
3238 static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
3239 { /* Begin pc_set_termios */
3241 struct channel *ch;
3242 unsigned long flags;
3244 /* ---------------------------------------------------------
3245 verifyChannel returns the channel from the tty struct
3246 if it is valid. This serves as a sanity check.
3247 ------------------------------------------------------------- */
3249 if ((ch = verifyChannel(tty)) != NULL)
3250 { /* Begin if channel valid */
3252 save_flags(flags);
3253 cli();
3254 globalwinon(ch);
3255 epcaparam(tty, ch);
3256 memoff(ch);
3258 if ((old_termios->c_cflag & CRTSCTS) &&
3259 ((tty->termios->c_cflag & CRTSCTS) == 0))
3260 tty->hw_stopped = 0;
3262 if (!(old_termios->c_cflag & CLOCAL) &&
3263 (tty->termios->c_cflag & CLOCAL))
3264 wake_up_interruptible(&ch->open_wait);
3266 restore_flags(flags);
3268 } /* End if channel valid */
3270 } /* End pc_set_termios */
3272 /* --------------------- Begin do_softint ----------------------- */
3274 static void do_softint(void *private_)
3275 { /* Begin do_softint */
3277 struct channel *ch = (struct channel *) private_;
3280 /* Called in response to a modem change event */
3282 if (ch && ch->magic == EPCA_MAGIC)
3283 { /* Begin EPCA_MAGIC */
3285 struct tty_struct *tty = ch->tty;
3287 if (tty && tty->driver_data)
3289 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event))
3290 { /* Begin if clear_bit */
3292 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
3293 wake_up_interruptible(&ch->open_wait);
3294 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
3296 } /* End if clear_bit */
3299 } /* End EPCA_MAGIC */
3300 } /* End do_softint */
3302 /* ------------------------------------------------------------
3303 pc_stop and pc_start provide software flow control to the
3304 routine and the pc_ioctl routine.
3305 ---------------------------------------------------------------- */
3307 /* --------------------- Begin pc_stop ----------------------- */
3309 static void pc_stop(struct tty_struct *tty)
3310 { /* Begin pc_stop */
3312 struct channel *ch;
3313 unsigned long flags;
3315 /* ---------------------------------------------------------
3316 verifyChannel returns the channel from the tty struct
3317 if it is valid. This serves as a sanity check.
3318 ------------------------------------------------------------- */
3320 if ((ch = verifyChannel(tty)) != NULL)
3321 { /* Begin if valid channel */
3323 save_flags(flags);
3324 cli();
3326 if ((ch->statusflags & TXSTOPPED) == 0)
3327 { /* Begin if transmit stop requested */
3329 globalwinon(ch);
3331 /* STOP transmitting now !! */
3333 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
3335 ch->statusflags |= TXSTOPPED;
3336 memoff(ch);
3338 } /* End if transmit stop requested */
3340 restore_flags(flags);
3342 } /* End if valid channel */
3344 } /* End pc_stop */
3346 /* --------------------- Begin pc_start ----------------------- */
3348 static void pc_start(struct tty_struct *tty)
3349 { /* Begin pc_start */
3351 struct channel *ch;
3353 /* ---------------------------------------------------------
3354 verifyChannel returns the channel from the tty struct
3355 if it is valid. This serves as a sanity check.
3356 ------------------------------------------------------------- */
3358 if ((ch = verifyChannel(tty)) != NULL)
3359 { /* Begin if channel valid */
3361 unsigned long flags;
3363 save_flags(flags);
3364 cli();
3366 /* Just in case output was resumed because of a change in Digi-flow */
3367 if (ch->statusflags & TXSTOPPED)
3368 { /* Begin transmit resume requested */
3370 volatile struct board_chan *bc;
3372 globalwinon(ch);
3373 bc = ch->brdchan;
3374 if (ch->statusflags & LOWWAIT)
3375 bc->ilow = 1;
3377 /* Okay, you can start transmitting again... */
3379 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
3381 ch->statusflags &= ~TXSTOPPED;
3382 memoff(ch);
3384 } /* End transmit resume requested */
3386 restore_flags(flags);
3388 } /* End if channel valid */
3390 } /* End pc_start */
3392 /* ------------------------------------------------------------------
3393 The below routines pc_throttle and pc_unthrottle are used
3394 to slow (And resume) the receipt of data into the kernels
3395 receive buffers. The exact occurrence of this depends on the
3396 size of the kernels receive buffer and what the 'watermarks'
3397 are set to for that buffer. See the n_ttys.c file for more
3398 details.
3399 ______________________________________________________________________ */
3400 /* --------------------- Begin throttle ----------------------- */
3402 static void pc_throttle(struct tty_struct * tty)
3403 { /* Begin pc_throttle */
3405 struct channel *ch;
3406 unsigned long flags;
3408 /* ---------------------------------------------------------
3409 verifyChannel returns the channel from the tty struct
3410 if it is valid. This serves as a sanity check.
3411 ------------------------------------------------------------- */
3413 if ((ch = verifyChannel(tty)) != NULL)
3414 { /* Begin if channel valid */
3417 save_flags(flags);
3418 cli();
3420 if ((ch->statusflags & RXSTOPPED) == 0)
3422 globalwinon(ch);
3423 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
3425 ch->statusflags |= RXSTOPPED;
3426 memoff(ch);
3428 restore_flags(flags);
3430 } /* End if channel valid */
3432 } /* End pc_throttle */
3434 /* --------------------- Begin unthrottle ----------------------- */
3436 static void pc_unthrottle(struct tty_struct *tty)
3437 { /* Begin pc_unthrottle */
3439 struct channel *ch;
3440 unsigned long flags;
3441 volatile struct board_chan *bc;
3444 /* ---------------------------------------------------------
3445 verifyChannel returns the channel from the tty struct
3446 if it is valid. This serves as a sanity check.
3447 ------------------------------------------------------------- */
3449 if ((ch = verifyChannel(tty)) != NULL)
3450 { /* Begin if channel valid */
3453 /* Just in case output was resumed because of a change in Digi-flow */
3454 save_flags(flags);
3455 cli();
3457 if (ch->statusflags & RXSTOPPED)
3460 globalwinon(ch);
3461 bc = ch->brdchan;
3462 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
3464 ch->statusflags &= ~RXSTOPPED;
3465 memoff(ch);
3467 restore_flags(flags);
3469 } /* End if channel valid */
3471 } /* End pc_unthrottle */
3473 /* --------------------- Begin digi_send_break ----------------------- */
3475 void digi_send_break(struct channel *ch, int msec)
3476 { /* Begin digi_send_break */
3478 unsigned long flags;
3480 save_flags(flags);
3481 cli();
3482 globalwinon(ch);
3484 /* --------------------------------------------------------------------
3485 Maybe I should send an infinite break here, schedule() for
3486 msec amount of time, and then stop the break. This way,
3487 the user can't screw up the FEP by causing digi_send_break()
3488 to be called (i.e. via an ioctl()) more than once in msec amount
3489 of time. Try this for now...
3490 ------------------------------------------------------------------------ */
3492 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
3493 memoff(ch);
3495 restore_flags(flags);
3497 } /* End digi_send_break */
3499 /* --------------------- Begin setup_empty_event ----------------------- */
3501 static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
3502 { /* Begin setup_empty_event */
3504 volatile struct board_chan *bc = ch->brdchan;
3505 unsigned long int flags;
3507 save_flags(flags);
3508 cli();
3509 globalwinon(ch);
3510 ch->statusflags |= EMPTYWAIT;
3512 /* ------------------------------------------------------------------
3513 When set the iempty flag request a event to be generated when the
3514 transmit buffer is empty (If there is no BREAK in progress).
3515 --------------------------------------------------------------------- */
3517 bc->iempty = 1;
3518 memoff(ch);
3519 restore_flags(flags);
3521 } /* End setup_empty_event */
3523 /* --------------------- Begin get_termio ----------------------- */
3525 static int get_termio(struct tty_struct * tty, struct termio __user * termio)
3526 { /* Begin get_termio */
3527 return kernel_termios_to_user_termio(termio, tty->termios);
3528 } /* End get_termio */
3529 /* ---------------------- Begin epca_setup -------------------------- */
3530 void epca_setup(char *str, int *ints)
3531 { /* Begin epca_setup */
3533 struct board_info board;
3534 int index, loop, last;
3535 char *temp, *t2;
3536 unsigned len;
3538 /* ----------------------------------------------------------------------
3539 If this routine looks a little strange it is because it is only called
3540 if a LILO append command is given to boot the kernel with parameters.
3541 In this way, we can provide the user a method of changing his board
3542 configuration without rebuilding the kernel.
3543 ----------------------------------------------------------------------- */
3544 if (!liloconfig)
3545 liloconfig = 1;
3547 memset(&board, 0, sizeof(board));
3549 /* Assume the data is int first, later we can change it */
3550 /* I think that array position 0 of ints holds the number of args */
3551 for (last = 0, index = 1; index <= ints[0]; index++)
3552 switch(index)
3553 { /* Begin parse switch */
3555 case 1:
3556 board.status = ints[index];
3558 /* ---------------------------------------------------------
3559 We check for 2 (As opposed to 1; because 2 is a flag
3560 instructing the driver to ignore epcaconfig.) For this
3561 reason we check for 2.
3562 ------------------------------------------------------------ */
3563 if (board.status == 2)
3564 { /* Begin ignore epcaconfig as well as lilo cmd line */
3565 nbdevs = 0;
3566 num_cards = 0;
3567 return;
3568 } /* End ignore epcaconfig as well as lilo cmd line */
3570 if (board.status > 2)
3572 printk(KERN_ERR "<Error> - epca_setup: Invalid board status 0x%x\n", board.status);
3573 invalid_lilo_config = 1;
3574 setup_error_code |= INVALID_BOARD_STATUS;
3575 return;
3577 last = index;
3578 break;
3580 case 2:
3581 board.type = ints[index];
3582 if (board.type >= PCIXEM)
3584 printk(KERN_ERR "<Error> - epca_setup: Invalid board type 0x%x\n", board.type);
3585 invalid_lilo_config = 1;
3586 setup_error_code |= INVALID_BOARD_TYPE;
3587 return;
3589 last = index;
3590 break;
3592 case 3:
3593 board.altpin = ints[index];
3594 if (board.altpin > 1)
3596 printk(KERN_ERR "<Error> - epca_setup: Invalid board altpin 0x%x\n", board.altpin);
3597 invalid_lilo_config = 1;
3598 setup_error_code |= INVALID_ALTPIN;
3599 return;
3601 last = index;
3602 break;
3604 case 4:
3605 board.numports = ints[index];
3606 if ((board.numports < 2) || (board.numports > 256))
3608 printk(KERN_ERR "<Error> - epca_setup: Invalid board numports 0x%x\n", board.numports);
3609 invalid_lilo_config = 1;
3610 setup_error_code |= INVALID_NUM_PORTS;
3611 return;
3613 nbdevs += board.numports;
3614 last = index;
3615 break;
3617 case 5:
3618 board.port = (unsigned char *)ints[index];
3619 if (ints[index] <= 0)
3621 printk(KERN_ERR "<Error> - epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
3622 invalid_lilo_config = 1;
3623 setup_error_code |= INVALID_PORT_BASE;
3624 return;
3626 last = index;
3627 break;
3629 case 6:
3630 board.membase = (unsigned char *)ints[index];
3631 if (ints[index] <= 0)
3633 printk(KERN_ERR "<Error> - epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
3634 invalid_lilo_config = 1;
3635 setup_error_code |= INVALID_MEM_BASE;
3636 return;
3638 last = index;
3639 break;
3641 default:
3642 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
3643 return;
3645 } /* End parse switch */
3647 while (str && *str)
3648 { /* Begin while there is a string arg */
3650 /* find the next comma or terminator */
3651 temp = str;
3653 /* While string is not null, and a comma hasn't been found */
3654 while (*temp && (*temp != ','))
3655 temp++;
3657 if (!*temp)
3658 temp = NULL;
3659 else
3660 *temp++ = 0;
3662 /* Set index to the number of args + 1 */
3663 index = last + 1;
3665 switch(index)
3667 case 1:
3668 len = strlen(str);
3669 if (strncmp("Disable", str, len) == 0)
3670 board.status = 0;
3671 else
3672 if (strncmp("Enable", str, len) == 0)
3673 board.status = 1;
3674 else
3676 printk(KERN_ERR "<Error> - epca_setup: Invalid status %s\n", str);
3677 invalid_lilo_config = 1;
3678 setup_error_code |= INVALID_BOARD_STATUS;
3679 return;
3681 last = index;
3682 break;
3684 case 2:
3686 for(loop = 0; loop < EPCA_NUM_TYPES; loop++)
3687 if (strcmp(board_desc[loop], str) == 0)
3688 break;
3691 /* ---------------------------------------------------------------
3692 If the index incremented above refers to a legitamate board
3693 type set it here.
3694 ------------------------------------------------------------------*/
3696 if (index < EPCA_NUM_TYPES)
3697 board.type = loop;
3698 else
3700 printk(KERN_ERR "<Error> - epca_setup: Invalid board type: %s\n", str);
3701 invalid_lilo_config = 1;
3702 setup_error_code |= INVALID_BOARD_TYPE;
3703 return;
3705 last = index;
3706 break;
3708 case 3:
3709 len = strlen(str);
3710 if (strncmp("Disable", str, len) == 0)
3711 board.altpin = 0;
3712 else
3713 if (strncmp("Enable", str, len) == 0)
3714 board.altpin = 1;
3715 else
3717 printk(KERN_ERR "<Error> - epca_setup: Invalid altpin %s\n", str);
3718 invalid_lilo_config = 1;
3719 setup_error_code |= INVALID_ALTPIN;
3720 return;
3722 last = index;
3723 break;
3725 case 4:
3726 t2 = str;
3727 while (isdigit(*t2))
3728 t2++;
3730 if (*t2)
3732 printk(KERN_ERR "<Error> - epca_setup: Invalid port count %s\n", str);
3733 invalid_lilo_config = 1;
3734 setup_error_code |= INVALID_NUM_PORTS;
3735 return;
3738 /* ------------------------------------------------------------
3739 There is not a man page for simple_strtoul but the code can be
3740 found in vsprintf.c. The first argument is the string to
3741 translate (To an unsigned long obviously), the second argument
3742 can be the address of any character variable or a NULL. If a
3743 variable is given, the end pointer of the string will be stored
3744 in that variable; if a NULL is given the end pointer will
3745 not be returned. The last argument is the base to use. If
3746 a 0 is indicated, the routine will attempt to determine the
3747 proper base by looking at the values prefix (A '0' for octal,
3748 a 'x' for hex, etc ... If a value is given it will use that
3749 value as the base.
3750 ---------------------------------------------------------------- */
3751 board.numports = simple_strtoul(str, NULL, 0);
3752 nbdevs += board.numports;
3753 last = index;
3754 break;
3756 case 5:
3757 t2 = str;
3758 while (isxdigit(*t2))
3759 t2++;
3761 if (*t2)
3763 printk(KERN_ERR "<Error> - epca_setup: Invalid i/o address %s\n", str);
3764 invalid_lilo_config = 1;
3765 setup_error_code |= INVALID_PORT_BASE;
3766 return;
3769 board.port = (unsigned char *)simple_strtoul(str, NULL, 16);
3770 last = index;
3771 break;
3773 case 6:
3774 t2 = str;
3775 while (isxdigit(*t2))
3776 t2++;
3778 if (*t2)
3780 printk(KERN_ERR "<Error> - epca_setup: Invalid memory base %s\n",str);
3781 invalid_lilo_config = 1;
3782 setup_error_code |= INVALID_MEM_BASE;
3783 return;
3786 board.membase = (unsigned char *)simple_strtoul(str, NULL, 16);
3787 last = index;
3788 break;
3790 default:
3791 printk(KERN_ERR "PC/Xx: Too many string parms\n");
3792 return;
3794 str = temp;
3796 } /* End while there is a string arg */
3799 if (last < 6)
3801 printk(KERN_ERR "PC/Xx: Insufficient parms specified\n");
3802 return;
3805 /* I should REALLY validate the stuff here */
3807 /* Copies our local copy of board into boards */
3808 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
3811 /* Does this get called once per lilo arg are what ? */
3813 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
3814 num_cards, board_desc[board.type],
3815 board.numports, (int)board.port, (unsigned int) board.membase);
3817 num_cards++;
3819 } /* End epca_setup */
3823 #ifdef ENABLE_PCI
3824 /* ------------------------ Begin init_PCI --------------------------- */
3826 enum epic_board_types {
3827 brd_xr = 0,
3828 brd_xem,
3829 brd_cx,
3830 brd_xrj,
3834 /* indexed directly by epic_board_types enum */
3835 static struct {
3836 unsigned char board_type;
3837 unsigned bar_idx; /* PCI base address region */
3838 } epca_info_tbl[] = {
3839 { PCIXR, 0, },
3840 { PCIXEM, 0, },
3841 { PCICX, 0, },
3842 { PCIXRJ, 2, },
3846 static int __devinit epca_init_one (struct pci_dev *pdev,
3847 const struct pci_device_id *ent)
3849 static int board_num = -1;
3850 int board_idx, info_idx = ent->driver_data;
3851 unsigned long addr;
3853 if (pci_enable_device(pdev))
3854 return -EIO;
3856 board_num++;
3857 board_idx = board_num + num_cards;
3858 if (board_idx >= MAXBOARDS)
3859 goto err_out;
3861 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
3862 if (!addr) {
3863 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
3864 epca_info_tbl[info_idx].bar_idx);
3865 goto err_out;
3868 boards[board_idx].status = ENABLED;
3869 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
3870 boards[board_idx].numports = 0x0;
3871 boards[board_idx].port =
3872 (unsigned char *)((char *) addr + PCI_IO_OFFSET);
3873 boards[board_idx].membase =
3874 (unsigned char *)((char *) addr);
3876 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
3877 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3878 0x200000, addr + PCI_IO_OFFSET);
3879 goto err_out;
3882 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
3883 if (!boards[board_idx].re_map_port) {
3884 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3885 0x200000, addr + PCI_IO_OFFSET);
3886 goto err_out_free_pciio;
3889 if (!request_mem_region (addr, 0x200000, "epca")) {
3890 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3891 0x200000, addr);
3892 goto err_out_free_iounmap;
3895 boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
3896 if (!boards[board_idx].re_map_membase) {
3897 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3898 0x200000, addr + PCI_IO_OFFSET);
3899 goto err_out_free_memregion;
3902 /* --------------------------------------------------------------
3903 I don't know what the below does, but the hardware guys say
3904 its required on everything except PLX (In this case XRJ).
3905 ---------------------------------------------------------------- */
3906 if (info_idx != brd_xrj) {
3907 pci_write_config_byte(pdev, 0x40, 0);
3908 pci_write_config_byte(pdev, 0x46, 0);
3911 return 0;
3913 err_out_free_memregion:
3914 release_mem_region (addr, 0x200000);
3915 err_out_free_iounmap:
3916 iounmap (boards[board_idx].re_map_port);
3917 err_out_free_pciio:
3918 release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
3919 err_out:
3920 return -ENODEV;
3924 static struct pci_device_id epca_pci_tbl[] = {
3925 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
3926 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
3927 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
3928 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
3929 { 0, }
3932 MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
3934 int __init init_PCI (void)
3935 { /* Begin init_PCI */
3937 int pci_count;
3939 memset (&epca_driver, 0, sizeof (epca_driver));
3940 epca_driver.name = "epca";
3941 epca_driver.id_table = epca_pci_tbl;
3942 epca_driver.probe = epca_init_one;
3944 pci_count = pci_register_driver (&epca_driver);
3946 if (pci_count <= 0) {
3947 pci_unregister_driver (&epca_driver);
3948 pci_count = 0;
3951 return(pci_count);
3953 } /* End init_PCI */
3955 #endif /* ENABLE_PCI */
3957 MODULE_LICENSE("GPL");