2 Copyright (C) 1996 Digi International.
4 For technical support please email digiLinux@dgii.com or
5 call Digi tech support at (612) 912-3456
7 ** This driver is no longer supported by Digi **
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 /* See README.epca for change history --DAT*/
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/types.h>
32 #include <linux/init.h>
33 #include <linux/serial.h>
34 #include <linux/delay.h>
35 #include <linux/ctype.h>
36 #include <linux/tty.h>
37 #include <linux/tty_flip.h>
38 #include <linux/slab.h>
39 #include <linux/ioport.h>
40 #include <linux/interrupt.h>
41 #include <asm/uaccess.h>
43 #include <linux/spinlock.h>
44 #include <linux/pci.h>
51 #include "epcaconfig.h"
53 #define VERSION "1.3.0.1-LK2.6"
55 /* This major needs to be submitted to Linux to join the majors list */
56 #define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
60 #define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
64 static int nbdevs, num_cards, liloconfig;
65 static int digi_poller_inhibited = 1 ;
67 static int setup_error_code;
68 static int invalid_lilo_config;
71 * The ISA boards do window flipping into the same spaces so its only sane with
72 * a single lock. It's still pretty efficient.
74 static DEFINE_SPINLOCK(epca_lock);
76 /* MAXBOARDS is typically 12, but ISA and EISA cards are restricted to 7 below. */
77 static struct board_info boards[MAXBOARDS];
79 static struct tty_driver *pc_driver;
80 static struct tty_driver *pc_info;
82 /* ------------------ Begin Digi specific structures -------------------- */
85 * digi_channels represents an array of structures that keep track of each
86 * channel of the Digi product. Information such as transmit and receive
87 * pointers, termio data, and signal definitions (DTR, CTS, etc ...) are stored
88 * here. This structure is NOT used to overlay the cards physical channel
91 static struct channel digi_channels[MAX_ALLOC];
94 * card_ptr is an array used to hold the address of the first channel structure
95 * of each card. This array will hold the addresses of various channels located
98 static struct channel *card_ptr[MAXCARDS];
100 static struct timer_list epca_timer;
103 * Begin generic memory functions. These functions will be alias (point at)
104 * more specific functions dependent on the board being configured.
106 static void memwinon(struct board_info *b, unsigned int win);
107 static void memwinoff(struct board_info *b, unsigned int win);
108 static void globalwinon(struct channel *ch);
109 static void rxwinon(struct channel *ch);
110 static void txwinon(struct channel *ch);
111 static void memoff(struct channel *ch);
112 static void assertgwinon(struct channel *ch);
113 static void assertmemoff(struct channel *ch);
115 /* ---- Begin more 'specific' memory functions for cx_like products --- */
117 static void pcxem_memwinon(struct board_info *b, unsigned int win);
118 static void pcxem_memwinoff(struct board_info *b, unsigned int win);
119 static void pcxem_globalwinon(struct channel *ch);
120 static void pcxem_rxwinon(struct channel *ch);
121 static void pcxem_txwinon(struct channel *ch);
122 static void pcxem_memoff(struct channel *ch);
124 /* ------ Begin more 'specific' memory functions for the pcxe ------- */
126 static void pcxe_memwinon(struct board_info *b, unsigned int win);
127 static void pcxe_memwinoff(struct board_info *b, unsigned int win);
128 static void pcxe_globalwinon(struct channel *ch);
129 static void pcxe_rxwinon(struct channel *ch);
130 static void pcxe_txwinon(struct channel *ch);
131 static void pcxe_memoff(struct channel *ch);
133 /* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
134 /* Note : pc64xe and pcxi share the same windowing routines */
136 static void pcxi_memwinon(struct board_info *b, unsigned int win);
137 static void pcxi_memwinoff(struct board_info *b, unsigned int win);
138 static void pcxi_globalwinon(struct channel *ch);
139 static void pcxi_rxwinon(struct channel *ch);
140 static void pcxi_txwinon(struct channel *ch);
141 static void pcxi_memoff(struct channel *ch);
143 /* - Begin 'specific' do nothing memory functions needed for some cards - */
145 static void dummy_memwinon(struct board_info *b, unsigned int win);
146 static void dummy_memwinoff(struct board_info *b, unsigned int win);
147 static void dummy_globalwinon(struct channel *ch);
148 static void dummy_rxwinon(struct channel *ch);
149 static void dummy_txwinon(struct channel *ch);
150 static void dummy_memoff(struct channel *ch);
151 static void dummy_assertgwinon(struct channel *ch);
152 static void dummy_assertmemoff(struct channel *ch);
154 static struct channel *verifyChannel(struct tty_struct *);
155 static void pc_sched_event(struct channel *, int);
156 static void epca_error(int, char *);
157 static void pc_close(struct tty_struct *, struct file *);
158 static void shutdown(struct channel *);
159 static void pc_hangup(struct tty_struct *);
160 static void pc_put_char(struct tty_struct *, unsigned char);
161 static int pc_write_room(struct tty_struct *);
162 static int pc_chars_in_buffer(struct tty_struct *);
163 static void pc_flush_buffer(struct tty_struct *);
164 static void pc_flush_chars(struct tty_struct *);
165 static int block_til_ready(struct tty_struct *, struct file *,
167 static int pc_open(struct tty_struct *, struct file *);
168 static void post_fep_init(unsigned int crd);
169 static void epcapoll(unsigned long);
170 static void doevent(int);
171 static void fepcmd(struct channel *, int, int, int, int, int);
172 static unsigned termios2digi_h(struct channel *ch, unsigned);
173 static unsigned termios2digi_i(struct channel *ch, unsigned);
174 static unsigned termios2digi_c(struct channel *ch, unsigned);
175 static void epcaparam(struct tty_struct *, struct channel *);
176 static void receive_data(struct channel *);
177 static int pc_ioctl(struct tty_struct *, struct file *,
178 unsigned int, unsigned long);
179 static int info_ioctl(struct tty_struct *, struct file *,
180 unsigned int, unsigned long);
181 static void pc_set_termios(struct tty_struct *, struct ktermios *);
182 static void do_softint(struct work_struct *work);
183 static void pc_stop(struct tty_struct *);
184 static void pc_start(struct tty_struct *);
185 static void pc_throttle(struct tty_struct * tty);
186 static void pc_unthrottle(struct tty_struct *tty);
187 static void digi_send_break(struct channel *ch, int msec);
188 static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
189 void epca_setup(char *, int *);
191 static int pc_write(struct tty_struct *, const unsigned char *, int);
192 static int pc_init(void);
193 static int init_PCI(void);
196 * Table of functions for each board to handle memory. Mantaining parallelism
197 * is a *very* good idea here. The idea is for the runtime code to blindly call
198 * these functions, not knowing/caring about the underlying hardware. This
199 * stuff should contain no conditionals; if more functionality is needed a
200 * different entry should be established. These calls are the interface calls
201 * and are the only functions that should be accessed. Anyone caught making
202 * direct calls deserves what they get.
204 static void memwinon(struct board_info *b, unsigned int win)
209 static void memwinoff(struct board_info *b, unsigned int win)
211 b->memwinoff(b, win);
214 static void globalwinon(struct channel *ch)
216 ch->board->globalwinon(ch);
219 static void rxwinon(struct channel *ch)
221 ch->board->rxwinon(ch);
224 static void txwinon(struct channel *ch)
226 ch->board->txwinon(ch);
229 static void memoff(struct channel *ch)
231 ch->board->memoff(ch);
233 static void assertgwinon(struct channel *ch)
235 ch->board->assertgwinon(ch);
238 static void assertmemoff(struct channel *ch)
240 ch->board->assertmemoff(ch);
243 /* PCXEM windowing is the same as that used in the PCXR and CX series cards. */
244 static void pcxem_memwinon(struct board_info *b, unsigned int win)
246 outb_p(FEPWIN|win, b->port + 1);
249 static void pcxem_memwinoff(struct board_info *b, unsigned int win)
251 outb_p(0, b->port + 1);
254 static void pcxem_globalwinon(struct channel *ch)
256 outb_p( FEPWIN, (int)ch->board->port + 1);
259 static void pcxem_rxwinon(struct channel *ch)
261 outb_p(ch->rxwin, (int)ch->board->port + 1);
264 static void pcxem_txwinon(struct channel *ch)
266 outb_p(ch->txwin, (int)ch->board->port + 1);
269 static void pcxem_memoff(struct channel *ch)
271 outb_p(0, (int)ch->board->port + 1);
274 /* ----------------- Begin pcxe memory window stuff ------------------ */
275 static void pcxe_memwinon(struct board_info *b, unsigned int win)
277 outb_p(FEPWIN | win, b->port + 1);
280 static void pcxe_memwinoff(struct board_info *b, unsigned int win)
282 outb_p(inb(b->port) & ~FEPMEM, b->port + 1);
283 outb_p(0, b->port + 1);
286 static void pcxe_globalwinon(struct channel *ch)
288 outb_p(FEPWIN, (int)ch->board->port + 1);
291 static void pcxe_rxwinon(struct channel *ch)
293 outb_p(ch->rxwin, (int)ch->board->port + 1);
296 static void pcxe_txwinon(struct channel *ch)
298 outb_p(ch->txwin, (int)ch->board->port + 1);
301 static void pcxe_memoff(struct channel *ch)
303 outb_p(0, (int)ch->board->port);
304 outb_p(0, (int)ch->board->port + 1);
307 /* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
308 static void pcxi_memwinon(struct board_info *b, unsigned int win)
310 outb_p(inb(b->port) | FEPMEM, b->port);
313 static void pcxi_memwinoff(struct board_info *b, unsigned int win)
315 outb_p(inb(b->port) & ~FEPMEM, b->port);
318 static void pcxi_globalwinon(struct channel *ch)
320 outb_p(FEPMEM, ch->board->port);
323 static void pcxi_rxwinon(struct channel *ch)
325 outb_p(FEPMEM, ch->board->port);
328 static void pcxi_txwinon(struct channel *ch)
330 outb_p(FEPMEM, ch->board->port);
333 static void pcxi_memoff(struct channel *ch)
335 outb_p(0, ch->board->port);
338 static void pcxi_assertgwinon(struct channel *ch)
340 epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
343 static void pcxi_assertmemoff(struct channel *ch)
345 epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
349 * Not all of the cards need specific memory windowing routines. Some cards
350 * (Such as PCI) needs no windowing routines at all. We provide these do
351 * nothing routines so that the same code base can be used. The driver will
352 * ALWAYS call a windowing routine if it thinks it needs to; regardless of the
353 * card. However, dependent on the card the routine may or may not do anything.
355 static void dummy_memwinon(struct board_info *b, unsigned int win)
359 static void dummy_memwinoff(struct board_info *b, unsigned int win)
363 static void dummy_globalwinon(struct channel *ch)
367 static void dummy_rxwinon(struct channel *ch)
371 static void dummy_txwinon(struct channel *ch)
375 static void dummy_memoff(struct channel *ch)
379 static void dummy_assertgwinon(struct channel *ch)
383 static void dummy_assertmemoff(struct channel *ch)
387 static struct channel *verifyChannel(struct tty_struct *tty)
390 * This routine basically provides a sanity check. It insures that the
391 * channel returned is within the proper range of addresses as well as
392 * properly initialized. If some bogus info gets passed in
393 * through tty->driver_data this should catch it.
396 struct channel *ch = (struct channel *)tty->driver_data;
397 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs])) {
398 if (ch->magic == EPCA_MAGIC)
405 static void pc_sched_event(struct channel *ch, int event)
408 * We call this to schedule interrupt processing on some event. The
409 * kernel sees our request and calls the related routine in OUR driver.
411 ch->event |= 1 << event;
412 schedule_work(&ch->tqueue);
415 static void epca_error(int line, char *msg)
417 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
420 static void pc_close(struct tty_struct *tty, struct file *filp)
425 * verifyChannel returns the channel from the tty struct if it is
426 * valid. This serves as a sanity check.
428 if ((ch = verifyChannel(tty)) != NULL) {
429 spin_lock_irqsave(&epca_lock, flags);
430 if (tty_hung_up_p(filp)) {
431 spin_unlock_irqrestore(&epca_lock, flags);
434 if (ch->count-- > 1) {
435 /* Begin channel is open more than once */
437 * Return without doing anything. Someone might still
438 * be using the channel.
440 spin_unlock_irqrestore(&epca_lock, flags);
444 /* Port open only once go ahead with shutdown & reset */
445 BUG_ON(ch->count < 0);
448 * Let the rest of the driver know the channel is being closed.
449 * This becomes important if an open is attempted before close
452 ch->asyncflags |= ASYNC_CLOSING;
455 spin_unlock_irqrestore(&epca_lock, flags);
457 if (ch->asyncflags & ASYNC_INITIALIZED) {
458 /* Setup an event to indicate when the transmit buffer empties */
459 setup_empty_event(tty, ch);
460 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
462 if (tty->driver->flush_buffer)
463 tty->driver->flush_buffer(tty);
465 tty_ldisc_flush(tty);
468 spin_lock_irqsave(&epca_lock, flags);
472 spin_unlock_irqrestore(&epca_lock, flags);
474 if (ch->blocked_open) {
476 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
477 wake_up_interruptible(&ch->open_wait);
479 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
481 wake_up_interruptible(&ch->close_wait);
485 static void shutdown(struct channel *ch)
488 struct tty_struct *tty;
489 struct board_chan __iomem *bc;
491 if (!(ch->asyncflags & ASYNC_INITIALIZED))
494 spin_lock_irqsave(&epca_lock, flags);
500 * In order for an event to be generated on the receipt of data the
501 * idata flag must be set. Since we are shutting down, this is not
502 * necessary clear this flag.
505 writeb(0, &bc->idata);
508 /* If we're a modem control device and HUPCL is on, drop RTS & DTR. */
509 if (tty->termios->c_cflag & HUPCL) {
510 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
511 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
516 * The channel has officialy been closed. The next time it is opened it
517 * will have to reinitialized. Set a flag to indicate this.
519 /* Prevent future Digi programmed interrupts from coming active */
520 ch->asyncflags &= ~ASYNC_INITIALIZED;
521 spin_unlock_irqrestore(&epca_lock, flags);
524 static void pc_hangup(struct tty_struct *tty)
529 * verifyChannel returns the channel from the tty struct if it is
530 * valid. This serves as a sanity check.
532 if ((ch = verifyChannel(tty)) != NULL) {
535 if (tty->driver->flush_buffer)
536 tty->driver->flush_buffer(tty);
537 tty_ldisc_flush(tty);
540 spin_lock_irqsave(&epca_lock, flags);
544 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
545 spin_unlock_irqrestore(&epca_lock, flags);
546 wake_up_interruptible(&ch->open_wait);
550 static int pc_write(struct tty_struct *tty,
551 const unsigned char *buf, int bytesAvailable)
553 unsigned int head, tail;
560 struct board_chan __iomem *bc;
563 * pc_write is primarily called directly by the kernel routine
564 * tty_write (Though it can also be called by put_char) found in
565 * tty_io.c. pc_write is passed a line discipline buffer where the data
566 * to be written out is stored. The line discipline implementation
567 * itself is done at the kernel level and is not brought into the
572 * verifyChannel returns the channel from the tty struct if it is
573 * valid. This serves as a sanity check.
575 if ((ch = verifyChannel(tty)) == NULL)
578 /* Make a pointer to the channel data structure found on the board. */
580 size = ch->txbufsize;
583 spin_lock_irqsave(&epca_lock, flags);
586 head = readw(&bc->tin) & (size - 1);
587 tail = readw(&bc->tout);
589 if (tail != readw(&bc->tout))
590 tail = readw(&bc->tout);
594 /* head has not wrapped */
596 * remain (much like dataLen above) represents the total amount
597 * of space available on the card for data. Here dataLen
598 * represents the space existing between the head pointer and
599 * the end of buffer. This is important because a memcpy cannot
600 * be told to automatically wrap around when it hits the buffer
603 dataLen = size - head;
604 remain = size - (head - tail) - 1;
606 /* head has wrapped around */
607 remain = tail - head - 1;
611 * Check the space on the card. If we have more data than space; reduce
612 * the amount of data to fit the space.
614 bytesAvailable = min(remain, bytesAvailable);
616 while (bytesAvailable > 0) {
617 /* there is data to copy onto card */
620 * If head is not wrapped, the below will make sure the first
621 * data copy fills to the end of card buffer.
623 dataLen = min(bytesAvailable, dataLen);
624 memcpy_toio(ch->txptr + head, buf, dataLen);
627 amountCopied += dataLen;
628 bytesAvailable -= dataLen;
635 ch->statusflags |= TXBUSY;
637 writew(head, &bc->tin);
639 if ((ch->statusflags & LOWWAIT) == 0) {
640 ch->statusflags |= LOWWAIT;
641 writeb(1, &bc->ilow);
644 spin_unlock_irqrestore(&epca_lock, flags);
648 static void pc_put_char(struct tty_struct *tty, unsigned char c)
650 pc_write(tty, &c, 1);
653 static int pc_write_room(struct tty_struct *tty)
658 unsigned int head, tail;
659 struct board_chan __iomem *bc;
664 * verifyChannel returns the channel from the tty struct if it is
665 * valid. This serves as a sanity check.
667 if ((ch = verifyChannel(tty)) != NULL) {
668 spin_lock_irqsave(&epca_lock, flags);
672 head = readw(&bc->tin) & (ch->txbufsize - 1);
673 tail = readw(&bc->tout);
675 if (tail != readw(&bc->tout))
676 tail = readw(&bc->tout);
677 /* Wrap tail if necessary */
678 tail &= (ch->txbufsize - 1);
680 if ((remain = tail - head - 1) < 0 )
681 remain += ch->txbufsize;
683 if (remain && (ch->statusflags & LOWWAIT) == 0) {
684 ch->statusflags |= LOWWAIT;
685 writeb(1, &bc->ilow);
688 spin_unlock_irqrestore(&epca_lock, flags);
690 /* Return how much room is left on card */
694 static int pc_chars_in_buffer(struct tty_struct *tty)
697 unsigned int ctail, head, tail;
701 struct board_chan __iomem *bc;
704 * verifyChannel returns the channel from the tty struct if it is
705 * valid. This serves as a sanity check.
707 if ((ch = verifyChannel(tty)) == NULL)
710 spin_lock_irqsave(&epca_lock, flags);
714 tail = readw(&bc->tout);
715 head = readw(&bc->tin);
716 ctail = readw(&ch->mailbox->cout);
718 if (tail == head && readw(&ch->mailbox->cin) == ctail && readb(&bc->tbusy) == 0)
720 else { /* Begin if some space on the card has been used */
721 head = readw(&bc->tin) & (ch->txbufsize - 1);
722 tail &= (ch->txbufsize - 1);
724 * The logic here is basically opposite of the above
725 * pc_write_room here we are finding the amount of bytes in the
726 * buffer filled. Not the amount of bytes empty.
728 if ((remain = tail - head - 1) < 0 )
729 remain += ch->txbufsize;
730 chars = (int)(ch->txbufsize - remain);
732 * Make it possible to wakeup anything waiting for output in
735 * If not already set. Setup an event to indicate when the
736 * transmit buffer empties.
738 if (!(ch->statusflags & EMPTYWAIT))
739 setup_empty_event(tty,ch);
740 } /* End if some space on the card has been used */
742 spin_unlock_irqrestore(&epca_lock, flags);
743 /* Return number of characters residing on card. */
747 static void pc_flush_buffer(struct tty_struct *tty)
752 struct board_chan __iomem *bc;
754 * verifyChannel returns the channel from the tty struct if it is
755 * valid. This serves as a sanity check.
757 if ((ch = verifyChannel(tty)) == NULL)
760 spin_lock_irqsave(&epca_lock, flags);
763 tail = readw(&bc->tout);
764 /* Have FEP move tout pointer; effectively flushing transmit buffer */
765 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
767 spin_unlock_irqrestore(&epca_lock, flags);
771 static void pc_flush_chars(struct tty_struct *tty)
775 * verifyChannel returns the channel from the tty struct if it is
776 * valid. This serves as a sanity check.
778 if ((ch = verifyChannel(tty)) != NULL) {
780 spin_lock_irqsave(&epca_lock, flags);
782 * If not already set and the transmitter is busy setup an
783 * event to indicate when the transmit empties.
785 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
786 setup_empty_event(tty,ch);
787 spin_unlock_irqrestore(&epca_lock, flags);
791 static int block_til_ready(struct tty_struct *tty,
792 struct file *filp, struct channel *ch)
794 DECLARE_WAITQUEUE(wait,current);
795 int retval, do_clocal = 0;
798 if (tty_hung_up_p(filp)) {
799 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
802 retval = -ERESTARTSYS;
807 * If the device is in the middle of being closed, then block until
808 * it's done, and then try again.
810 if (ch->asyncflags & ASYNC_CLOSING) {
811 interruptible_sleep_on(&ch->close_wait);
813 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
819 if (filp->f_flags & O_NONBLOCK) {
821 * If non-blocking mode is set, then make the check up front
824 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
827 if (tty->termios->c_cflag & CLOCAL)
829 /* Block waiting for the carrier detect and the line to become free */
832 add_wait_queue(&ch->open_wait, &wait);
834 spin_lock_irqsave(&epca_lock, flags);
835 /* We dec count so that pc_close will know when to free things */
836 if (!tty_hung_up_p(filp))
840 set_current_state(TASK_INTERRUPTIBLE);
841 if (tty_hung_up_p(filp) ||
842 !(ch->asyncflags & ASYNC_INITIALIZED))
844 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
847 retval = -ERESTARTSYS;
850 if (!(ch->asyncflags & ASYNC_CLOSING) &&
851 (do_clocal || (ch->imodem & ch->dcd)))
853 if (signal_pending(current)) {
854 retval = -ERESTARTSYS;
857 spin_unlock_irqrestore(&epca_lock, flags);
859 * Allow someone else to be scheduled. We will occasionally go
860 * through this loop until one of the above conditions change.
861 * The below schedule call will allow other processes to enter
862 * and prevent this loop from hogging the cpu.
865 spin_lock_irqsave(&epca_lock, flags);
868 __set_current_state(TASK_RUNNING);
869 remove_wait_queue(&ch->open_wait, &wait);
870 if (!tty_hung_up_p(filp))
874 spin_unlock_irqrestore(&epca_lock, flags);
879 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
883 static int pc_open(struct tty_struct *tty, struct file * filp)
887 int line, retval, boardnum;
888 struct board_chan __iomem *bc;
892 if (line < 0 || line >= nbdevs)
895 ch = &digi_channels[line];
896 boardnum = ch->boardnum;
898 /* Check status of board configured in system. */
901 * I check to see if the epca_setup routine detected an user error. It
902 * might be better to put this in pc_init, but for the moment it goes
905 if (invalid_lilo_config) {
906 if (setup_error_code & INVALID_BOARD_TYPE)
907 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
908 if (setup_error_code & INVALID_NUM_PORTS)
909 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
910 if (setup_error_code & INVALID_MEM_BASE)
911 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
912 if (setup_error_code & INVALID_PORT_BASE)
913 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
914 if (setup_error_code & INVALID_BOARD_STATUS)
915 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
916 if (setup_error_code & INVALID_ALTPIN)
917 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
918 tty->driver_data = NULL; /* Mark this device as 'down' */
921 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
922 tty->driver_data = NULL; /* Mark this device as 'down' */
928 tty->driver_data = NULL;
932 spin_lock_irqsave(&epca_lock, flags);
934 * Every time a channel is opened, increment a counter. This is
935 * necessary because we do not wish to flush and shutdown the channel
936 * until the last app holding the channel open, closes it.
940 * Set a kernel structures pointer to our local channel structure. This
941 * way we can get to it when passed only a tty struct.
943 tty->driver_data = ch;
945 * If this is the first time the channel has been opened, initialize
946 * the tty->termios struct otherwise let pc_close handle it.
951 /* Save boards current modem status */
952 ch->imodem = readb(&bc->mstat);
955 * Set receive head and tail ptrs to each other. This indicates no data
958 head = readw(&bc->rin);
959 writew(head, &bc->rout);
961 /* Set the channels associated tty structure */
965 * The below routine generally sets up parity, baud, flow control
966 * issues, etc.... It effect both control flags and input flags.
969 ch->asyncflags |= ASYNC_INITIALIZED;
971 spin_unlock_irqrestore(&epca_lock, flags);
973 retval = block_til_ready(tty, filp, ch);
977 * Set this again in case a hangup set it to zero while this open() was
978 * waiting for the line...
980 spin_lock_irqsave(&epca_lock, flags);
983 /* Enable Digi Data events */
984 writeb(1, &bc->idata);
986 spin_unlock_irqrestore(&epca_lock, flags);
990 static int __init epca_module_init(void)
994 module_init(epca_module_init);
996 static struct pci_driver epca_driver;
998 static void __exit epca_module_exit(void)
1001 struct board_info *bd;
1004 del_timer_sync(&epca_timer);
1006 if (tty_unregister_driver(pc_driver) || tty_unregister_driver(pc_info))
1008 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
1011 put_tty_driver(pc_driver);
1012 put_tty_driver(pc_info);
1014 for (crd = 0; crd < num_cards; crd++) {
1016 if (!bd) { /* sanity check */
1017 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1021 for (count = 0; count < bd->numports; count++, ch++) {
1023 tty_hangup(ch->tty);
1026 pci_unregister_driver(&epca_driver);
1028 module_exit(epca_module_exit);
1030 static const struct tty_operations pc_ops = {
1034 .write_room = pc_write_room,
1035 .flush_buffer = pc_flush_buffer,
1036 .chars_in_buffer = pc_chars_in_buffer,
1037 .flush_chars = pc_flush_chars,
1038 .put_char = pc_put_char,
1040 .set_termios = pc_set_termios,
1043 .throttle = pc_throttle,
1044 .unthrottle = pc_unthrottle,
1045 .hangup = pc_hangup,
1048 static int info_open(struct tty_struct *tty, struct file * filp)
1053 static struct tty_operations info_ops = {
1055 .ioctl = info_ioctl,
1058 static int __init pc_init(void)
1061 struct board_info *bd;
1062 unsigned char board_id = 0;
1065 int pci_boards_found, pci_count;
1069 pc_driver = alloc_tty_driver(MAX_ALLOC);
1073 pc_info = alloc_tty_driver(MAX_ALLOC);
1078 * If epca_setup has not been ran by LILO set num_cards to defaults;
1079 * copy board structure defined by digiConfig into drivers board
1080 * structure. Note : If LILO has ran epca_setup then epca_setup will
1081 * handle defining num_cards as well as copying the data into the board
1085 /* driver has been configured via. epcaconfig */
1087 num_cards = NUMCARDS;
1088 memcpy(&boards, &static_boards,
1089 sizeof(struct board_info) * NUMCARDS);
1093 * Note : If lilo was used to configure the driver and the ignore
1094 * epcaconfig option was choosen (digiepca=2) then nbdevs and num_cards
1095 * will equal 0 at this point. This is okay; PCI cards will still be
1096 * picked up if detected.
1100 * Set up interrupt, we will worry about memory allocation in
1103 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1106 * NOTE : This code assumes that the number of ports found in the
1107 * boards array is correct. This could be wrong if the card in question
1108 * is PCI (And therefore has no ports entry in the boards structure.)
1109 * The rest of the information will be valid for PCI because the
1110 * beginning of pc_init scans for PCI and determines i/o and base
1111 * memory addresses. I am not sure if it is possible to read the number
1112 * of ports supported by the card prior to it being booted (Since that
1113 * is the state it is in when pc_init is run). Because it is not
1114 * possible to query the number of supported ports until after the card
1115 * has booted; we are required to calculate the card_ptrs as the card
1116 * is initialized (Inside post_fep_init). The negative thing about this
1117 * approach is that digiDload's call to GET_INFO will have a bad port
1118 * value. (Since this is called prior to post_fep_init.)
1120 pci_boards_found = 0;
1121 if (num_cards < MAXBOARDS)
1122 pci_boards_found += init_PCI();
1123 num_cards += pci_boards_found;
1125 pc_driver->owner = THIS_MODULE;
1126 pc_driver->name = "ttyD";
1127 pc_driver->major = DIGI_MAJOR;
1128 pc_driver->minor_start = 0;
1129 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1130 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1131 pc_driver->init_termios = tty_std_termios;
1132 pc_driver->init_termios.c_iflag = 0;
1133 pc_driver->init_termios.c_oflag = 0;
1134 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1135 pc_driver->init_termios.c_lflag = 0;
1136 pc_driver->init_termios.c_ispeed = 9600;
1137 pc_driver->init_termios.c_ospeed = 9600;
1138 pc_driver->flags = TTY_DRIVER_REAL_RAW;
1139 tty_set_operations(pc_driver, &pc_ops);
1141 pc_info->owner = THIS_MODULE;
1142 pc_info->name = "digi_ctl";
1143 pc_info->major = DIGIINFOMAJOR;
1144 pc_info->minor_start = 0;
1145 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1146 pc_info->subtype = SERIAL_TYPE_INFO;
1147 pc_info->init_termios = tty_std_termios;
1148 pc_info->init_termios.c_iflag = 0;
1149 pc_info->init_termios.c_oflag = 0;
1150 pc_info->init_termios.c_lflag = 0;
1151 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1152 pc_info->init_termios.c_ispeed = 9600;
1153 pc_info->init_termios.c_ospeed = 9600;
1154 pc_info->flags = TTY_DRIVER_REAL_RAW;
1155 tty_set_operations(pc_info, &info_ops);
1158 for (crd = 0; crd < num_cards; crd++) {
1160 * This is where the appropriate memory handlers for the
1161 * hardware is set. Everything at runtime blindly jumps through
1165 /* defined in epcaconfig.h */
1171 bd->memwinon = pcxem_memwinon;
1172 bd->memwinoff = pcxem_memwinoff;
1173 bd->globalwinon = pcxem_globalwinon;
1174 bd->txwinon = pcxem_txwinon;
1175 bd->rxwinon = pcxem_rxwinon;
1176 bd->memoff = pcxem_memoff;
1177 bd->assertgwinon = dummy_assertgwinon;
1178 bd->assertmemoff = dummy_assertmemoff;
1184 bd->memwinon = dummy_memwinon;
1185 bd->memwinoff = dummy_memwinoff;
1186 bd->globalwinon = dummy_globalwinon;
1187 bd->txwinon = dummy_txwinon;
1188 bd->rxwinon = dummy_rxwinon;
1189 bd->memoff = dummy_memoff;
1190 bd->assertgwinon = dummy_assertgwinon;
1191 bd->assertmemoff = dummy_assertmemoff;
1196 bd->memwinon = pcxe_memwinon;
1197 bd->memwinoff = pcxe_memwinoff;
1198 bd->globalwinon = pcxe_globalwinon;
1199 bd->txwinon = pcxe_txwinon;
1200 bd->rxwinon = pcxe_rxwinon;
1201 bd->memoff = pcxe_memoff;
1202 bd->assertgwinon = dummy_assertgwinon;
1203 bd->assertmemoff = dummy_assertmemoff;
1208 bd->memwinon = pcxi_memwinon;
1209 bd->memwinoff = pcxi_memwinoff;
1210 bd->globalwinon = pcxi_globalwinon;
1211 bd->txwinon = pcxi_txwinon;
1212 bd->rxwinon = pcxi_rxwinon;
1213 bd->memoff = pcxi_memoff;
1214 bd->assertgwinon = pcxi_assertgwinon;
1215 bd->assertmemoff = pcxi_assertmemoff;
1223 * Some cards need a memory segment to be defined for use in
1224 * transmit and receive windowing operations. These boards are
1225 * listed in the below switch. In the case of the XI the amount
1226 * of memory on the board is variable so the memory_seg is also
1227 * variable. This code determines what they segment should be.
1233 bd->memory_seg = 0xf000;
1237 board_id = inb((int)bd->port);
1238 if ((board_id & 0x1) == 0x1) {
1239 /* it's an XI card */
1240 /* Is it a 64K board */
1241 if ((board_id & 0x30) == 0)
1242 bd->memory_seg = 0xf000;
1244 /* Is it a 128K board */
1245 if ((board_id & 0x30) == 0x10)
1246 bd->memory_seg = 0xe000;
1248 /* Is is a 256K board */
1249 if ((board_id & 0x30) == 0x20)
1250 bd->memory_seg = 0xc000;
1252 /* Is it a 512K board */
1253 if ((board_id & 0x30) == 0x30)
1254 bd->memory_seg = 0x8000;
1256 printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
1261 err = tty_register_driver(pc_driver);
1263 printk(KERN_ERR "Couldn't register Digi PC/ driver");
1267 err = tty_register_driver(pc_info);
1269 printk(KERN_ERR "Couldn't register Digi PC/ info ");
1273 /* Start up the poller to check for events on all enabled boards */
1274 init_timer(&epca_timer);
1275 epca_timer.function = epcapoll;
1276 mod_timer(&epca_timer, jiffies + HZ/25);
1280 tty_unregister_driver(pc_driver);
1282 put_tty_driver(pc_info);
1284 put_tty_driver(pc_driver);
1289 static void post_fep_init(unsigned int crd)
1292 void __iomem *memaddr;
1293 struct global_data __iomem *gd;
1294 struct board_info *bd;
1295 struct board_chan __iomem *bc;
1297 int shrinkmem = 0, lowwater;
1300 * This call is made by the user via. the ioctl call DIGI_INIT. It is
1301 * responsible for setting up all the card specific stuff.
1306 * If this is a PCI board, get the port info. Remember PCI cards do not
1307 * have entries into the epcaconfig.h file, so we can't get the number
1308 * of ports from it. Unfortunetly, this means that anyone doing a
1309 * DIGI_GETINFO before the board has booted will get an invalid number
1310 * of ports returned (It should return 0). Calls to DIGI_GETINFO after
1311 * DIGI_INIT has been called will return the proper values.
1313 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
1315 * Below we use XEMPORTS as a memory offset regardless of which
1316 * PCI card it is. This is because all of the supported PCI
1317 * cards have the same memory offset for the channel data. This
1318 * will have to be changed if we ever develop a PCI/XE card.
1319 * NOTE : The FEP manual states that the port offset is 0xC22
1320 * as opposed to 0xC02. This is only true for PC/XE, and PC/XI
1321 * cards; not for the XEM, or CX series. On the PCI cards the
1322 * number of ports is determined by reading a ID PROM located
1323 * in the box attached to the card. The card can then determine
1324 * the index the id to determine the number of ports available.
1325 * (FYI - The id should be located at 0x1ac (And may use up to
1326 * 4 bytes if the box in question is a XEM or CX)).
1328 /* PCI cards are already remapped at this point ISA are not */
1329 bd->numports = readw(bd->re_map_membase + XEMPORTS);
1330 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1331 nbdevs += (bd->numports);
1333 /* Fix up the mappings for ISA/EISA etc */
1334 /* FIXME: 64K - can we be smarter ? */
1335 bd->re_map_membase = ioremap(bd->membase, 0x10000);
1339 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1341 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1344 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1346 memaddr = bd->re_map_membase;
1349 * The below assignment will set bc to point at the BEGINING of the
1350 * cards channel structures. For 1 card there will be between 8 and 64
1351 * of these structures.
1353 bc = memaddr + CHANSTRUCT;
1356 * The below assignment will set gd to point at the BEGINING of global
1357 * memory address 0xc00. The first data in that global memory actually
1358 * starts at address 0xc1a. The command in pointer begins at 0xd10.
1360 gd = memaddr + GLOBAL;
1363 * XEPORTS (address 0xc22) points at the number of channels the card
1364 * supports. (For 64XE, XI, XEM, and XR use 0xc02)
1366 if ((bd->type == PCXEVE || bd->type == PCXE) && (readw(memaddr + XEPORTS) < 3))
1368 if (bd->type < PCIXEM)
1369 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1374 * Remember ch is the main drivers channels structure, while bc is the
1375 * cards channel structure.
1377 for (i = 0; i < bd->numports; i++, ch++, bc++) {
1378 unsigned long flags;
1383 INIT_WORK(&ch->tqueue, do_softint);
1384 ch->board = &boards[crd];
1386 spin_lock_irqsave(&epca_lock, flags);
1389 * Since some of the boards use different bitmaps for
1390 * their control signals we cannot hard code these
1391 * values and retain portability. We virtualize this
1420 if (boards[crd].altpin) {
1421 ch->dsr = ch->m_dcd;
1422 ch->dcd = ch->m_dsr;
1423 ch->digiext.digi_flags |= DIGI_ALTPIN;
1425 ch->dcd = ch->m_dcd;
1426 ch->dsr = ch->m_dsr;
1431 ch->magic = EPCA_MAGIC;
1435 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1439 tseg = readw(&bc->tseg);
1440 rseg = readw(&bc->rseg);
1446 /* Cover all the 2MEG cards */
1447 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1448 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1449 ch->txwin = FEPWIN | (tseg >> 11);
1450 ch->rxwin = FEPWIN | (rseg >> 11);
1455 /* Cover all the 32K windowed cards */
1456 /* Mask equal to window size - 1 */
1457 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1458 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1459 ch->txwin = FEPWIN | (tseg >> 11);
1460 ch->rxwin = FEPWIN | (rseg >> 11);
1465 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4) & 0x1fff);
1466 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1467 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4) & 0x1fff);
1468 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >>9 );
1473 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1474 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
1475 ch->txwin = ch->rxwin = 0;
1480 ch->txbufsize = readw(&bc->tmax) + 1;
1483 ch->rxbufsize = readw(&bc->rmax) + 1;
1485 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1487 /* Set transmitter low water mark */
1488 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1490 /* Set receiver low water mark */
1491 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
1493 /* Set receiver high water mark */
1494 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1496 writew(100, &bc->edelay);
1497 writeb(1, &bc->idata);
1499 ch->startc = readb(&bc->startc);
1500 ch->stopc = readb(&bc->stopc);
1501 ch->startca = readb(&bc->startca);
1502 ch->stopca = readb(&bc->stopca);
1512 ch->close_delay = 50;
1514 ch->blocked_open = 0;
1515 init_waitqueue_head(&ch->open_wait);
1516 init_waitqueue_head(&ch->close_wait);
1518 spin_unlock_irqrestore(&epca_lock, flags);
1522 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1523 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
1527 static void epcapoll(unsigned long ignored)
1529 unsigned long flags;
1531 volatile unsigned int head, tail;
1533 struct board_info *bd;
1536 * This routine is called upon every timer interrupt. Even though the
1537 * Digi series cards are capable of generating interrupts this method
1538 * of non-looping polling is more efficient. This routine checks for
1539 * card generated events (Such as receive data, are transmit buffer
1540 * empty) and acts on those events.
1542 for (crd = 0; crd < num_cards; crd++) {
1546 if ((bd->status == DISABLED) || digi_poller_inhibited)
1550 * assertmemoff is not needed here; indeed it is an empty
1551 * subroutine. It is being kept because future boards may need
1552 * this as well as some legacy boards.
1554 spin_lock_irqsave(&epca_lock, flags);
1561 * In this case head and tail actually refer to the event queue
1562 * not the transmit or receive queue.
1564 head = readw(&ch->mailbox->ein);
1565 tail = readw(&ch->mailbox->eout);
1567 /* If head isn't equal to tail we have an event */
1572 spin_unlock_irqrestore(&epca_lock, flags);
1573 } /* End for each card */
1574 mod_timer(&epca_timer, jiffies + (HZ / 25));
1577 static void doevent(int crd)
1579 void __iomem *eventbuf;
1580 struct channel *ch, *chan0;
1581 static struct tty_struct *tty;
1582 struct board_info *bd;
1583 struct board_chan __iomem *bc;
1584 unsigned int tail, head;
1589 * This subroutine is called by epcapoll when an event is detected
1590 * in the event queue. This routine responds to those events.
1594 chan0 = card_ptr[crd];
1595 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
1596 assertgwinon(chan0);
1597 while ((tail = readw(&chan0->mailbox->eout)) != (head = readw(&chan0->mailbox->ein))) { /* Begin while something in event queue */
1598 assertgwinon(chan0);
1599 eventbuf = bd->re_map_membase + tail + ISTART;
1600 /* Get the channel the event occurred on */
1601 channel = readb(eventbuf);
1602 /* Get the actual event code that occurred */
1603 event = readb(eventbuf + 1);
1605 * The two assignments below get the current modem status
1606 * (mstat) and the previous modem status (lstat). These are
1607 * useful becuase an event could signal a change in modem
1610 mstat = readb(eventbuf + 2);
1611 lstat = readb(eventbuf + 3);
1613 ch = chan0 + channel;
1614 if ((unsigned)channel >= bd->numports || !ch) {
1615 if (channel >= bd->numports)
1621 if ((bc = ch->brdchan) == NULL)
1624 if (event & DATA_IND) { /* Begin DATA_IND */
1627 } /* End DATA_IND */
1628 /* else *//* Fix for DCD transition missed bug */
1629 if (event & MODEMCHG_IND) {
1630 /* A modem signal change has been indicated */
1632 if (ch->asyncflags & ASYNC_CHECK_CD) {
1633 if (mstat & ch->dcd) /* We are now receiving dcd */
1634 wake_up_interruptible(&ch->open_wait);
1636 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
1641 if (event & BREAK_IND) {
1642 /* A break has been indicated */
1643 tty_insert_flip_char(tty, 0, TTY_BREAK);
1644 tty_schedule_flip(tty);
1645 } else if (event & LOWTX_IND) {
1646 if (ch->statusflags & LOWWAIT) {
1647 ch->statusflags &= ~LOWWAIT;
1650 } else if (event & EMPTYTX_IND) {
1651 /* This event is generated by setup_empty_event */
1652 ch->statusflags &= ~TXBUSY;
1653 if (ch->statusflags & EMPTYWAIT) {
1654 ch->statusflags &= ~EMPTYWAIT;
1662 writew(1, &bc->idata);
1663 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
1665 } /* End while something in event queue */
1668 static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1669 int byte2, int ncmds, int bytecmd)
1671 unchar __iomem *memaddr;
1672 unsigned int head, cmdTail, cmdStart, cmdMax;
1676 /* This is the routine in which commands may be passed to the card. */
1678 if (ch->board->status == DISABLED)
1681 /* Remember head (As well as max) is just an offset not a base addr */
1682 head = readw(&ch->mailbox->cin);
1683 /* cmdStart is a base address */
1684 cmdStart = readw(&ch->mailbox->cstart);
1686 * We do the addition below because we do not want a max pointer
1687 * relative to cmdStart. We want a max pointer that points at the
1688 * physical end of the command queue.
1690 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
1691 memaddr = ch->board->re_map_membase;
1693 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1694 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__, cmd, head);
1695 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__, cmdMax, cmdStart);
1699 writeb(cmd, memaddr + head + cmdStart + 0);
1700 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1701 /* Below word_or_byte is bits to set */
1702 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1703 /* Below byte2 is bits to reset */
1704 writeb(byte2, memaddr + head + cmdStart + 3);
1706 writeb(cmd, memaddr + head + cmdStart + 0);
1707 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1708 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1710 head = (head + 4) & (cmdMax - cmdStart - 4);
1711 writew(head, &ch->mailbox->cin);
1717 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1720 head = readw(&ch->mailbox->cin);
1721 cmdTail = readw(&ch->mailbox->cout);
1722 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
1724 * Basically this will break when the FEP acknowledges the
1725 * command by incrementing cmdTail (Making it equal to head).
1727 if (n <= ncmds * (sizeof(short) * 4))
1733 * Digi products use fields in their channels structures that are very similar
1734 * to the c_cflag and c_iflag fields typically found in UNIX termios
1735 * structures. The below three routines allow mappings between these hardware
1736 * "flags" and their respective Linux flags.
1738 static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
1742 if (cflag & CRTSCTS) {
1743 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1744 res |= ((ch->m_cts) | (ch->m_rts));
1747 if (ch->digiext.digi_flags & RTSPACE)
1750 if (ch->digiext.digi_flags & DTRPACE)
1753 if (ch->digiext.digi_flags & CTSPACE)
1756 if (ch->digiext.digi_flags & DSRPACE)
1759 if (ch->digiext.digi_flags & DCDPACE)
1762 if (res & (ch->m_rts))
1763 ch->digiext.digi_flags |= RTSPACE;
1765 if (res & (ch->m_cts))
1766 ch->digiext.digi_flags |= CTSPACE;
1771 static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
1773 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
1774 INPCK | ISTRIP|IXON|IXANY|IXOFF);
1775 if (ch->digiext.digi_flags & DIGI_AIXON)
1780 static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
1783 if (cflag & CBAUDEX) {
1784 ch->digiext.digi_flags |= DIGI_FAST;
1786 * HUPCL bit is used by FEP to indicate fast baud table is to
1791 ch->digiext.digi_flags &= ~DIGI_FAST;
1793 * CBAUD has bit position 0x1000 set these days to indicate Linux
1794 * baud rate remap. Digi hardware can't handle the bit assignment.
1795 * (We use a different bit assignment for high speed.). Clear this
1798 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
1800 * This gets a little confusing. The Digi cards have their own
1801 * representation of c_cflags controlling baud rate. For the most part
1802 * this is identical to the Linux implementation. However; Digi
1803 * supports one rate (76800) that Linux doesn't. This means that the
1804 * c_cflag entry that would normally mean 76800 for Digi actually means
1805 * 115200 under Linux. Without the below mapping, a stty 115200 would
1806 * only drive the board at 76800. Since the rate 230400 is also found
1807 * after 76800, the same problem afflicts us when we choose a rate of
1808 * 230400. Without the below modificiation stty 230400 would actually
1811 * There are two additional differences. The Linux value for CLOCAL
1812 * (0x800; 0004000) has no meaning to the Digi hardware. Also in later
1813 * releases of Linux; the CBAUD define has CBAUDEX (0x1000; 0010000)
1814 * ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX should be
1815 * checked for a screened out prior to termios2digi_c returning. Since
1816 * CLOCAL isn't used by the board this can be ignored as long as the
1817 * returned value is used only by Digi hardware.
1819 if (cflag & CBAUDEX) {
1821 * The below code is trying to guarantee that only baud rates
1822 * 115200 and 230400 are remapped. We use exclusive or because
1823 * the various baud rates share common bit positions and
1824 * therefore can't be tested for easily.
1826 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
1827 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
1833 /* Caller must hold the locks */
1834 static void epcaparam(struct tty_struct *tty, struct channel *ch)
1836 unsigned int cmdHead;
1837 struct ktermios *ts;
1838 struct board_chan __iomem *bc;
1839 unsigned mval, hflow, cflag, iflag;
1842 epcaassert(bc != NULL, "bc out of range");
1846 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
1847 cmdHead = readw(&bc->rin);
1848 writew(cmdHead, &bc->rout);
1849 cmdHead = readw(&bc->tin);
1850 /* Changing baud in mid-stream transmission can be wonderful */
1852 * Flush current transmit buffer by setting cmdTail pointer
1853 * (tout) to cmdHead pointer (tin). Hopefully the transmit
1856 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
1858 } else { /* Begin CBAUD not detected */
1860 * c_cflags have changed but that change had nothing to do with
1861 * BAUD. Propagate the change to the card.
1863 cflag = termios2digi_c(ch, ts->c_cflag);
1864 if (cflag != ch->fepcflag) {
1865 ch->fepcflag = cflag;
1866 /* Set baud rate, char size, stop bits, parity */
1867 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
1870 * If the user has not forced CLOCAL and if the device is not a
1871 * CALLOUT device (Which is always CLOCAL) we set flags such
1872 * that the driver will wait on carrier detect.
1874 if (ts->c_cflag & CLOCAL)
1875 ch->asyncflags &= ~ASYNC_CHECK_CD;
1877 ch->asyncflags |= ASYNC_CHECK_CD;
1878 mval = ch->m_dtr | ch->m_rts;
1879 } /* End CBAUD not detected */
1880 iflag = termios2digi_i(ch, ts->c_iflag);
1881 /* Check input mode flags */
1882 if (iflag != ch->fepiflag) {
1883 ch->fepiflag = iflag;
1885 * Command sets channels iflag structure on the board. Such
1886 * things as input soft flow control, handling of parity
1887 * errors, and break handling are all set here.
1889 /* break handling, parity handling, input stripping, flow control chars */
1890 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
1893 * Set the board mint value for this channel. This will cause hardware
1894 * events to be generated each time the DCD signal (Described in mint)
1897 writeb(ch->dcd, &bc->mint);
1898 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
1899 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
1900 writeb(0, &bc->mint);
1901 ch->imodem = readb(&bc->mstat);
1902 hflow = termios2digi_h(ch, ts->c_cflag);
1903 if (hflow != ch->hflow) {
1906 * Hard flow control has been selected but the board is not
1907 * using it. Activate hard flow control now.
1909 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
1911 mval ^= ch->modemfake & (mval ^ ch->modem);
1913 if (ch->omodem ^ mval) {
1916 * The below command sets the DTR and RTS mstat structure. If
1917 * hard flow control is NOT active these changes will drive the
1918 * output of the actual DTR and RTS lines. If hard flow control
1919 * is active, the changes will be saved in the mstat structure
1920 * and only asserted when hard flow control is turned off.
1923 /* First reset DTR & RTS; then set them */
1924 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
1925 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
1927 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
1928 ch->fepstartc = ch->startc;
1929 ch->fepstopc = ch->stopc;
1931 * The XON / XOFF characters have changed; propagate these
1932 * changes to the card.
1934 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
1936 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
1937 ch->fepstartca = ch->startca;
1938 ch->fepstopca = ch->stopca;
1940 * Similar to the above, this time the auxilarly XON / XOFF
1941 * characters have changed; propagate these changes to the card.
1943 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
1947 /* Caller holds lock */
1948 static void receive_data(struct channel *ch)
1951 struct ktermios *ts = NULL;
1952 struct tty_struct *tty;
1953 struct board_chan __iomem *bc;
1954 int dataToRead, wrapgap, bytesAvailable;
1955 unsigned int tail, head;
1956 unsigned int wrapmask;
1959 * This routine is called by doint when a receive data event has taken
1963 if (ch->statusflags & RXSTOPPED)
1970 wrapmask = ch->rxbufsize - 1;
1973 * Get the head and tail pointers to the receiver queue. Wrap the head
1974 * pointer if it has reached the end of the buffer.
1976 head = readw(&bc->rin);
1978 tail = readw(&bc->rout) & wrapmask;
1980 bytesAvailable = (head - tail) & wrapmask;
1981 if (bytesAvailable == 0)
1984 /* If CREAD bit is off or device not open, set TX tail to head */
1985 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
1986 writew(head, &bc->rout);
1990 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
1993 if (readb(&bc->orun)) {
1994 writeb(0, &bc->orun);
1995 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",tty->name);
1996 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
1999 while (bytesAvailable > 0) { /* Begin while there is data on the card */
2000 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
2002 * Even if head has wrapped around only report the amount of
2003 * data to be equal to the size - tail. Remember memcpy can't
2004 * automaticly wrap around the receive buffer.
2006 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
2007 /* Make sure we don't overflow the buffer */
2008 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
2009 if (dataToRead == 0)
2012 * Move data read from our card into the line disciplines
2013 * buffer for translation if necessary.
2015 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
2016 tail = (tail + dataToRead) & wrapmask;
2017 bytesAvailable -= dataToRead;
2018 } /* End while there is data on the card */
2020 writew(tail, &bc->rout);
2021 /* Must be called with global data */
2022 tty_schedule_flip(ch->tty);
2025 static int info_ioctl(struct tty_struct *tty, struct file *file,
2026 unsigned int cmd, unsigned long arg)
2031 struct digi_info di;
2034 if (get_user(brd, (unsigned int __user *)arg))
2036 if (brd < 0 || brd >= num_cards || num_cards == 0)
2039 memset(&di, 0, sizeof(di));
2042 di.status = boards[brd].status;
2043 di.type = boards[brd].type ;
2044 di.numports = boards[brd].numports ;
2045 /* Legacy fixups - just move along nothing to see */
2046 di.port = (unsigned char *)boards[brd].port ;
2047 di.membase = (unsigned char *)boards[brd].membase ;
2049 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
2057 int brd = arg & 0xff000000 >> 16;
2058 unsigned char state = arg & 0xff;
2060 if (brd < 0 || brd >= num_cards) {
2061 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
2064 digi_poller_inhibited = state;
2071 * This call is made by the apps to complete the
2072 * initialization of the board(s). This routine is
2073 * responsible for setting the card to its initial
2074 * state and setting the drivers control fields to the
2075 * sutianle settings for the card in question.
2078 for (crd = 0; crd < num_cards; crd++)
2088 static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2090 struct channel *ch = (struct channel *) tty->driver_data;
2091 struct board_chan __iomem *bc;
2092 unsigned int mstat, mflag = 0;
2093 unsigned long flags;
2100 spin_lock_irqsave(&epca_lock, flags);
2102 mstat = readb(&bc->mstat);
2104 spin_unlock_irqrestore(&epca_lock, flags);
2106 if (mstat & ch->m_dtr)
2108 if (mstat & ch->m_rts)
2110 if (mstat & ch->m_cts)
2112 if (mstat & ch->dsr)
2114 if (mstat & ch->m_ri)
2116 if (mstat & ch->dcd)
2121 static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2122 unsigned int set, unsigned int clear)
2124 struct channel *ch = (struct channel *) tty->driver_data;
2125 unsigned long flags;
2130 spin_lock_irqsave(&epca_lock, flags);
2132 * I think this modemfake stuff is broken. It doesn't correctly reflect
2133 * the behaviour desired by the TIOCM* ioctls. Therefore this is
2136 if (set & TIOCM_RTS) {
2137 ch->modemfake |= ch->m_rts;
2138 ch->modem |= ch->m_rts;
2140 if (set & TIOCM_DTR) {
2141 ch->modemfake |= ch->m_dtr;
2142 ch->modem |= ch->m_dtr;
2144 if (clear & TIOCM_RTS) {
2145 ch->modemfake |= ch->m_rts;
2146 ch->modem &= ~ch->m_rts;
2148 if (clear & TIOCM_DTR) {
2149 ch->modemfake |= ch->m_dtr;
2150 ch->modem &= ~ch->m_dtr;
2154 * The below routine generally sets up parity, baud, flow control
2155 * issues, etc.... It effect both control flags and input flags.
2159 spin_unlock_irqrestore(&epca_lock, flags);
2163 static int pc_ioctl(struct tty_struct *tty, struct file * file,
2164 unsigned int cmd, unsigned long arg)
2168 unsigned long flags;
2169 unsigned int mflag, mstat;
2170 unsigned char startc, stopc;
2171 struct board_chan __iomem *bc;
2172 struct channel *ch = (struct channel *) tty->driver_data;
2173 void __user *argp = (void __user *)arg;
2181 * For POSIX compliance we need to add more ioctls. See tty_ioctl.c in
2182 * /usr/src/linux/drivers/char for a good example. In particular think
2183 * about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
2186 case TCSBRK: /* SVID version: non-zero arg --> no break */
2187 retval = tty_check_change(tty);
2190 /* Setup an event to indicate when the transmit buffer empties */
2191 spin_lock_irqsave(&epca_lock, flags);
2192 setup_empty_event(tty,ch);
2193 spin_unlock_irqrestore(&epca_lock, flags);
2194 tty_wait_until_sent(tty, 0);
2196 digi_send_break(ch, HZ / 4); /* 1/4 second */
2198 case TCSBRKP: /* support for POSIX tcsendbreak() */
2199 retval = tty_check_change(tty);
2203 /* Setup an event to indicate when the transmit buffer empties */
2204 spin_lock_irqsave(&epca_lock, flags);
2205 setup_empty_event(tty,ch);
2206 spin_unlock_irqrestore(&epca_lock, flags);
2207 tty_wait_until_sent(tty, 0);
2208 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
2211 mflag = pc_tiocmget(tty, file);
2212 if (put_user(mflag, (unsigned long __user *)argp))
2216 if (get_user(mstat, (unsigned __user *)argp))
2218 return pc_tiocmset(tty, file, mstat, ~mstat);
2220 spin_lock_irqsave(&epca_lock, flags);
2221 ch->omodem |= ch->m_dtr;
2223 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2225 spin_unlock_irqrestore(&epca_lock, flags);
2229 spin_lock_irqsave(&epca_lock, flags);
2230 ch->omodem &= ~ch->m_dtr;
2232 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2234 spin_unlock_irqrestore(&epca_lock, flags);
2237 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2243 if (cmd == DIGI_SETAW) {
2244 /* Setup an event to indicate when the transmit buffer empties */
2245 spin_lock_irqsave(&epca_lock, flags);
2246 setup_empty_event(tty,ch);
2247 spin_unlock_irqrestore(&epca_lock, flags);
2248 tty_wait_until_sent(tty, 0);
2250 /* ldisc lock already held in ioctl */
2251 if (tty->ldisc.flush_buffer)
2252 tty->ldisc.flush_buffer(tty);
2257 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2260 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
2261 ch->dcd = ch->m_dsr;
2262 ch->dsr = ch->m_dcd;
2264 ch->dcd = ch->m_dcd;
2265 ch->dsr = ch->m_dsr;
2268 spin_lock_irqsave(&epca_lock, flags);
2272 * The below routine generally sets up parity, baud, flow
2273 * control issues, etc.... It effect both control flags and
2278 spin_unlock_irqrestore(&epca_lock, flags);
2283 spin_lock_irqsave(&epca_lock, flags);
2285 if (cmd == DIGI_GETFLOW) {
2286 dflow.startc = readb(&bc->startc);
2287 dflow.stopc = readb(&bc->stopc);
2289 dflow.startc = readb(&bc->startca);
2290 dflow.stopc = readb(&bc->stopca);
2293 spin_unlock_irqrestore(&epca_lock, flags);
2295 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2301 if (cmd == DIGI_SETFLOW) {
2302 startc = ch->startc;
2305 startc = ch->startca;
2309 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2312 if (dflow.startc != startc || dflow.stopc != stopc) { /* Begin if setflow toggled */
2313 spin_lock_irqsave(&epca_lock, flags);
2316 if (cmd == DIGI_SETFLOW) {
2317 ch->fepstartc = ch->startc = dflow.startc;
2318 ch->fepstopc = ch->stopc = dflow.stopc;
2319 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
2321 ch->fepstartca = ch->startca = dflow.startc;
2322 ch->fepstopca = ch->stopca = dflow.stopc;
2323 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2326 if (ch->statusflags & TXSTOPPED)
2330 spin_unlock_irqrestore(&epca_lock, flags);
2331 } /* End if setflow toggled */
2334 return -ENOIOCTLCMD;
2339 static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2342 unsigned long flags;
2344 * verifyChannel returns the channel from the tty struct if it is
2345 * valid. This serves as a sanity check.
2347 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
2348 spin_lock_irqsave(&epca_lock, flags);
2352 spin_unlock_irqrestore(&epca_lock, flags);
2354 if ((old_termios->c_cflag & CRTSCTS) &&
2355 ((tty->termios->c_cflag & CRTSCTS) == 0))
2356 tty->hw_stopped = 0;
2358 if (!(old_termios->c_cflag & CLOCAL) &&
2359 (tty->termios->c_cflag & CLOCAL))
2360 wake_up_interruptible(&ch->open_wait);
2362 } /* End if channel valid */
2365 static void do_softint(struct work_struct *work)
2367 struct channel *ch = container_of(work, struct channel, tqueue);
2368 /* Called in response to a modem change event */
2369 if (ch && ch->magic == EPCA_MAGIC) {
2370 struct tty_struct *tty = ch->tty;
2372 if (tty && tty->driver_data) {
2373 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) {
2374 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2375 wake_up_interruptible(&ch->open_wait);
2376 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
2383 * pc_stop and pc_start provide software flow control to the routine and the
2386 static void pc_stop(struct tty_struct *tty)
2389 unsigned long flags;
2391 * verifyChannel returns the channel from the tty struct if it is
2392 * valid. This serves as a sanity check.
2394 if ((ch = verifyChannel(tty)) != NULL) {
2395 spin_lock_irqsave(&epca_lock, flags);
2396 if ((ch->statusflags & TXSTOPPED) == 0) { /* Begin if transmit stop requested */
2398 /* STOP transmitting now !! */
2399 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
2400 ch->statusflags |= TXSTOPPED;
2402 } /* End if transmit stop requested */
2403 spin_unlock_irqrestore(&epca_lock, flags);
2407 static void pc_start(struct tty_struct *tty)
2411 * verifyChannel returns the channel from the tty struct if it is
2412 * valid. This serves as a sanity check.
2414 if ((ch = verifyChannel(tty)) != NULL) {
2415 unsigned long flags;
2416 spin_lock_irqsave(&epca_lock, flags);
2417 /* Just in case output was resumed because of a change in Digi-flow */
2418 if (ch->statusflags & TXSTOPPED) { /* Begin transmit resume requested */
2419 struct board_chan __iomem *bc;
2422 if (ch->statusflags & LOWWAIT)
2423 writeb(1, &bc->ilow);
2424 /* Okay, you can start transmitting again... */
2425 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
2426 ch->statusflags &= ~TXSTOPPED;
2428 } /* End transmit resume requested */
2429 spin_unlock_irqrestore(&epca_lock, flags);
2434 * The below routines pc_throttle and pc_unthrottle are used to slow (And
2435 * resume) the receipt of data into the kernels receive buffers. The exact
2436 * occurrence of this depends on the size of the kernels receive buffer and
2437 * what the 'watermarks' are set to for that buffer. See the n_ttys.c file for
2440 static void pc_throttle(struct tty_struct *tty)
2443 unsigned long flags;
2445 * verifyChannel returns the channel from the tty struct if it is
2446 * valid. This serves as a sanity check.
2448 if ((ch = verifyChannel(tty)) != NULL) {
2449 spin_lock_irqsave(&epca_lock, flags);
2450 if ((ch->statusflags & RXSTOPPED) == 0) {
2452 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
2453 ch->statusflags |= RXSTOPPED;
2456 spin_unlock_irqrestore(&epca_lock, flags);
2460 static void pc_unthrottle(struct tty_struct *tty)
2463 unsigned long flags;
2465 * verifyChannel returns the channel from the tty struct if it is
2466 * valid. This serves as a sanity check.
2468 if ((ch = verifyChannel(tty)) != NULL) {
2469 /* Just in case output was resumed because of a change in Digi-flow */
2470 spin_lock_irqsave(&epca_lock, flags);
2471 if (ch->statusflags & RXSTOPPED) {
2473 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
2474 ch->statusflags &= ~RXSTOPPED;
2477 spin_unlock_irqrestore(&epca_lock, flags);
2481 static void digi_send_break(struct channel *ch, int msec)
2483 unsigned long flags;
2485 spin_lock_irqsave(&epca_lock, flags);
2488 * Maybe I should send an infinite break here, schedule() for msec
2489 * amount of time, and then stop the break. This way, the user can't
2490 * screw up the FEP by causing digi_send_break() to be called (i.e. via
2491 * an ioctl()) more than once in msec amount of time.
2492 * Try this for now...
2494 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2496 spin_unlock_irqrestore(&epca_lock, flags);
2499 /* Caller MUST hold the lock */
2500 static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2502 struct board_chan __iomem *bc = ch->brdchan;
2505 ch->statusflags |= EMPTYWAIT;
2507 * When set the iempty flag request a event to be generated when the
2508 * transmit buffer is empty (If there is no BREAK in progress).
2510 writeb(1, &bc->iempty);
2514 void epca_setup(char *str, int *ints)
2516 struct board_info board;
2517 int index, loop, last;
2522 * If this routine looks a little strange it is because it is only
2523 * called if a LILO append command is given to boot the kernel with
2524 * parameters. In this way, we can provide the user a method of
2525 * changing his board configuration without rebuilding the kernel.
2530 memset(&board, 0, sizeof(board));
2532 /* Assume the data is int first, later we can change it */
2533 /* I think that array position 0 of ints holds the number of args */
2534 for (last = 0, index = 1; index <= ints[0]; index++)
2535 switch (index) { /* Begin parse switch */
2537 board.status = ints[index];
2539 * We check for 2 (As opposed to 1; because 2 is a flag
2540 * instructing the driver to ignore epcaconfig.) For
2541 * this reason we check for 2.
2543 if (board.status == 2) { /* Begin ignore epcaconfig as well as lilo cmd line */
2547 } /* End ignore epcaconfig as well as lilo cmd line */
2549 if (board.status > 2) {
2550 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n", board.status);
2551 invalid_lilo_config = 1;
2552 setup_error_code |= INVALID_BOARD_STATUS;
2558 board.type = ints[index];
2559 if (board.type >= PCIXEM) {
2560 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
2561 invalid_lilo_config = 1;
2562 setup_error_code |= INVALID_BOARD_TYPE;
2568 board.altpin = ints[index];
2569 if (board.altpin > 1) {
2570 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
2571 invalid_lilo_config = 1;
2572 setup_error_code |= INVALID_ALTPIN;
2579 board.numports = ints[index];
2580 if (board.numports < 2 || board.numports > 256) {
2581 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
2582 invalid_lilo_config = 1;
2583 setup_error_code |= INVALID_NUM_PORTS;
2586 nbdevs += board.numports;
2591 board.port = ints[index];
2592 if (ints[index] <= 0) {
2593 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
2594 invalid_lilo_config = 1;
2595 setup_error_code |= INVALID_PORT_BASE;
2602 board.membase = ints[index];
2603 if (ints[index] <= 0) {
2604 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
2605 invalid_lilo_config = 1;
2606 setup_error_code |= INVALID_MEM_BASE;
2613 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
2616 } /* End parse switch */
2618 while (str && *str) { /* Begin while there is a string arg */
2619 /* find the next comma or terminator */
2621 /* While string is not null, and a comma hasn't been found */
2622 while (*temp && (*temp != ','))
2628 /* Set index to the number of args + 1 */
2634 if (strncmp("Disable", str, len) == 0)
2636 else if (strncmp("Enable", str, len) == 0)
2639 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
2640 invalid_lilo_config = 1;
2641 setup_error_code |= INVALID_BOARD_STATUS;
2648 for (loop = 0; loop < EPCA_NUM_TYPES; loop++)
2649 if (strcmp(board_desc[loop], str) == 0)
2652 * If the index incremented above refers to a
2653 * legitamate board type set it here.
2655 if (index < EPCA_NUM_TYPES)
2658 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
2659 invalid_lilo_config = 1;
2660 setup_error_code |= INVALID_BOARD_TYPE;
2668 if (strncmp("Disable", str, len) == 0)
2670 else if (strncmp("Enable", str, len) == 0)
2673 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
2674 invalid_lilo_config = 1;
2675 setup_error_code |= INVALID_ALTPIN;
2683 while (isdigit(*t2))
2687 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
2688 invalid_lilo_config = 1;
2689 setup_error_code |= INVALID_NUM_PORTS;
2694 * There is not a man page for simple_strtoul but the
2695 * code can be found in vsprintf.c. The first argument
2696 * is the string to translate (To an unsigned long
2697 * obviously), the second argument can be the address
2698 * of any character variable or a NULL. If a variable
2699 * is given, the end pointer of the string will be
2700 * stored in that variable; if a NULL is given the end
2701 * pointer will not be returned. The last argument is
2702 * the base to use. If a 0 is indicated, the routine
2703 * will attempt to determine the proper base by looking
2704 * at the values prefix (A '0' for octal, a 'x' for
2705 * hex, etc ... If a value is given it will use that
2706 * value as the base.
2708 board.numports = simple_strtoul(str, NULL, 0);
2709 nbdevs += board.numports;
2715 while (isxdigit(*t2))
2719 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
2720 invalid_lilo_config = 1;
2721 setup_error_code |= INVALID_PORT_BASE;
2725 board.port = simple_strtoul(str, NULL, 16);
2731 while (isxdigit(*t2))
2735 printk(KERN_ERR "epca_setup: Invalid memory base %s\n",str);
2736 invalid_lilo_config = 1;
2737 setup_error_code |= INVALID_MEM_BASE;
2740 board.membase = simple_strtoul(str, NULL, 16);
2744 printk(KERN_ERR "epca: Too many string parms\n");
2748 } /* End while there is a string arg */
2751 printk(KERN_ERR "epca: Insufficient parms specified\n");
2755 /* I should REALLY validate the stuff here */
2756 /* Copies our local copy of board into boards */
2757 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
2758 /* Does this get called once per lilo arg are what ? */
2759 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2760 num_cards, board_desc[board.type],
2761 board.numports, (int)board.port, (unsigned int) board.membase);
2765 enum epic_board_types {
2772 /* indexed directly by epic_board_types enum */
2774 unsigned char board_type;
2775 unsigned bar_idx; /* PCI base address region */
2776 } epca_info_tbl[] = {
2783 static int __devinit epca_init_one(struct pci_dev *pdev,
2784 const struct pci_device_id *ent)
2786 static int board_num = -1;
2787 int board_idx, info_idx = ent->driver_data;
2790 if (pci_enable_device(pdev))
2794 board_idx = board_num + num_cards;
2795 if (board_idx >= MAXBOARDS)
2798 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
2800 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
2801 epca_info_tbl[info_idx].bar_idx);
2805 boards[board_idx].status = ENABLED;
2806 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
2807 boards[board_idx].numports = 0x0;
2808 boards[board_idx].port = addr + PCI_IO_OFFSET;
2809 boards[board_idx].membase = addr;
2811 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
2812 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2813 0x200000, addr + PCI_IO_OFFSET);
2817 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
2818 if (!boards[board_idx].re_map_port) {
2819 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2820 0x200000, addr + PCI_IO_OFFSET);
2821 goto err_out_free_pciio;
2824 if (!request_mem_region (addr, 0x200000, "epca")) {
2825 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2827 goto err_out_free_iounmap;
2830 boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
2831 if (!boards[board_idx].re_map_membase) {
2832 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2833 0x200000, addr + PCI_IO_OFFSET);
2834 goto err_out_free_memregion;
2838 * I don't know what the below does, but the hardware guys say its
2839 * required on everything except PLX (In this case XRJ).
2841 if (info_idx != brd_xrj) {
2842 pci_write_config_byte(pdev, 0x40, 0);
2843 pci_write_config_byte(pdev, 0x46, 0);
2848 err_out_free_memregion:
2849 release_mem_region (addr, 0x200000);
2850 err_out_free_iounmap:
2851 iounmap (boards[board_idx].re_map_port);
2853 release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
2859 static struct pci_device_id epca_pci_tbl[] = {
2860 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
2861 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
2862 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
2863 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
2867 MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
2869 static int __init init_PCI(void)
2871 memset (&epca_driver, 0, sizeof (epca_driver));
2872 epca_driver.name = "epca";
2873 epca_driver.id_table = epca_pci_tbl;
2874 epca_driver.probe = epca_init_one;
2876 return pci_register_driver(&epca_driver);
2879 MODULE_LICENSE("GPL");