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 <linux/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
78 static struct board_info boards[MAXBOARDS];
80 static struct tty_driver *pc_driver;
81 static struct tty_driver *pc_info;
83 /* ------------------ Begin Digi specific structures -------------------- */
86 * digi_channels represents an array of structures that keep track of each
87 * channel of the Digi product. Information such as transmit and receive
88 * pointers, termio data, and signal definitions (DTR, CTS, etc ...) are stored
89 * here. This structure is NOT used to overlay the cards physical channel
92 static struct channel digi_channels[MAX_ALLOC];
95 * card_ptr is an array used to hold the address of the first channel structure
96 * of each card. This array will hold the addresses of various channels located
99 static struct channel *card_ptr[MAXCARDS];
101 static struct timer_list epca_timer;
104 * Begin generic memory functions. These functions will be alias (point at)
105 * more specific functions dependent on the board being configured.
107 static void memwinon(struct board_info *b, unsigned int win);
108 static void memwinoff(struct board_info *b, unsigned int win);
109 static void globalwinon(struct channel *ch);
110 static void rxwinon(struct channel *ch);
111 static void txwinon(struct channel *ch);
112 static void memoff(struct channel *ch);
113 static void assertgwinon(struct channel *ch);
114 static void assertmemoff(struct channel *ch);
116 /* ---- Begin more 'specific' memory functions for cx_like products --- */
118 static void pcxem_memwinon(struct board_info *b, unsigned int win);
119 static void pcxem_memwinoff(struct board_info *b, unsigned int win);
120 static void pcxem_globalwinon(struct channel *ch);
121 static void pcxem_rxwinon(struct channel *ch);
122 static void pcxem_txwinon(struct channel *ch);
123 static void pcxem_memoff(struct channel *ch);
125 /* ------ Begin more 'specific' memory functions for the pcxe ------- */
127 static void pcxe_memwinon(struct board_info *b, unsigned int win);
128 static void pcxe_memwinoff(struct board_info *b, unsigned int win);
129 static void pcxe_globalwinon(struct channel *ch);
130 static void pcxe_rxwinon(struct channel *ch);
131 static void pcxe_txwinon(struct channel *ch);
132 static void pcxe_memoff(struct channel *ch);
134 /* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
135 /* Note : pc64xe and pcxi share the same windowing routines */
137 static void pcxi_memwinon(struct board_info *b, unsigned int win);
138 static void pcxi_memwinoff(struct board_info *b, unsigned int win);
139 static void pcxi_globalwinon(struct channel *ch);
140 static void pcxi_rxwinon(struct channel *ch);
141 static void pcxi_txwinon(struct channel *ch);
142 static void pcxi_memoff(struct channel *ch);
144 /* - Begin 'specific' do nothing memory functions needed for some cards - */
146 static void dummy_memwinon(struct board_info *b, unsigned int win);
147 static void dummy_memwinoff(struct board_info *b, unsigned int win);
148 static void dummy_globalwinon(struct channel *ch);
149 static void dummy_rxwinon(struct channel *ch);
150 static void dummy_txwinon(struct channel *ch);
151 static void dummy_memoff(struct channel *ch);
152 static void dummy_assertgwinon(struct channel *ch);
153 static void dummy_assertmemoff(struct channel *ch);
155 static struct channel *verifyChannel(struct tty_struct *);
156 static void pc_sched_event(struct channel *, int);
157 static void epca_error(int, char *);
158 static void pc_close(struct tty_struct *, struct file *);
159 static void shutdown(struct channel *);
160 static void pc_hangup(struct tty_struct *);
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 int pc_send_break(struct tty_struct *tty, int msec);
188 static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
189 static 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 ch = verifyChannel(tty);
430 spin_lock_irqsave(&epca_lock, flags);
431 if (tty_hung_up_p(filp)) {
432 spin_unlock_irqrestore(&epca_lock, flags);
435 if (ch->port.count-- > 1) {
436 /* Begin channel is open more than once */
438 * Return without doing anything. Someone might still
439 * be using the channel.
441 spin_unlock_irqrestore(&epca_lock, flags);
444 /* Port open only once go ahead with shutdown & reset */
445 BUG_ON(ch->port.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->port.flags |= ASYNC_CLOSING;
455 spin_unlock_irqrestore(&epca_lock, flags);
457 if (ch->port.flags & ASYNC_INITIALIZED) {
458 /* Setup an event to indicate when the
459 transmit buffer empties */
460 setup_empty_event(tty, ch);
461 /* 30 seconds timeout */
462 tty_wait_until_sent(tty, 3000);
464 pc_flush_buffer(tty);
466 tty_ldisc_flush(tty);
469 spin_lock_irqsave(&epca_lock, flags);
473 spin_unlock_irqrestore(&epca_lock, flags);
475 if (ch->port.blocked_open) {
477 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
478 wake_up_interruptible(&ch->port.open_wait);
480 ch->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
482 wake_up_interruptible(&ch->port.close_wait);
486 static void shutdown(struct channel *ch)
489 struct tty_struct *tty;
490 struct board_chan __iomem *bc;
492 if (!(ch->port.flags & ASYNC_INITIALIZED))
495 spin_lock_irqsave(&epca_lock, flags);
501 * In order for an event to be generated on the receipt of data the
502 * idata flag must be set. Since we are shutting down, this is not
503 * necessary clear this flag.
506 writeb(0, &bc->idata);
509 /* If we're a modem control device and HUPCL is on, drop RTS & DTR. */
510 if (tty->termios->c_cflag & HUPCL) {
511 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
512 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
517 * The channel has officialy been closed. The next time it is opened it
518 * will have to reinitialized. Set a flag to indicate this.
520 /* Prevent future Digi programmed interrupts from coming active */
521 ch->port.flags &= ~ASYNC_INITIALIZED;
522 spin_unlock_irqrestore(&epca_lock, flags);
525 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 ch = verifyChannel(tty);
536 pc_flush_buffer(tty);
537 tty_ldisc_flush(tty);
540 spin_lock_irqsave(&epca_lock, flags);
544 ch->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
545 spin_unlock_irqrestore(&epca_lock, flags);
546 wake_up_interruptible(&ch->port.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 ch = verifyChannel(tty);
579 /* Make a pointer to the channel data structure found on the board. */
581 size = ch->txbufsize;
584 spin_lock_irqsave(&epca_lock, flags);
587 head = readw(&bc->tin) & (size - 1);
588 tail = readw(&bc->tout);
590 if (tail != readw(&bc->tout))
591 tail = readw(&bc->tout);
595 /* head has not wrapped */
597 * remain (much like dataLen above) represents the total amount
598 * of space available on the card for data. Here dataLen
599 * represents the space existing between the head pointer and
600 * the end of buffer. This is important because a memcpy cannot
601 * be told to automatically wrap around when it hits the buffer
604 dataLen = size - head;
605 remain = size - (head - tail) - 1;
607 /* head has wrapped around */
608 remain = tail - head - 1;
612 * Check the space on the card. If we have more data than space; reduce
613 * the amount of data to fit the space.
615 bytesAvailable = min(remain, bytesAvailable);
617 while (bytesAvailable > 0) {
618 /* there is data to copy onto card */
621 * If head is not wrapped, the below will make sure the first
622 * data copy fills to the end of card buffer.
624 dataLen = min(bytesAvailable, dataLen);
625 memcpy_toio(ch->txptr + head, buf, dataLen);
628 amountCopied += dataLen;
629 bytesAvailable -= dataLen;
636 ch->statusflags |= TXBUSY;
638 writew(head, &bc->tin);
640 if ((ch->statusflags & LOWWAIT) == 0) {
641 ch->statusflags |= LOWWAIT;
642 writeb(1, &bc->ilow);
645 spin_unlock_irqrestore(&epca_lock, flags);
649 static int pc_write_room(struct tty_struct *tty)
654 unsigned int head, tail;
655 struct board_chan __iomem *bc;
657 * verifyChannel returns the channel from the tty struct if it is
658 * valid. This serves as a sanity check.
660 ch = verifyChannel(tty);
662 spin_lock_irqsave(&epca_lock, flags);
666 head = readw(&bc->tin) & (ch->txbufsize - 1);
667 tail = readw(&bc->tout);
669 if (tail != readw(&bc->tout))
670 tail = readw(&bc->tout);
671 /* Wrap tail if necessary */
672 tail &= (ch->txbufsize - 1);
673 remain = tail - head - 1;
675 remain += ch->txbufsize;
677 if (remain && (ch->statusflags & LOWWAIT) == 0) {
678 ch->statusflags |= LOWWAIT;
679 writeb(1, &bc->ilow);
682 spin_unlock_irqrestore(&epca_lock, flags);
684 /* Return how much room is left on card */
688 static int pc_chars_in_buffer(struct tty_struct *tty)
691 unsigned int ctail, head, tail;
695 struct board_chan __iomem *bc;
697 * verifyChannel returns the channel from the tty struct if it is
698 * valid. This serves as a sanity check.
700 ch = verifyChannel(tty);
704 spin_lock_irqsave(&epca_lock, flags);
708 tail = readw(&bc->tout);
709 head = readw(&bc->tin);
710 ctail = readw(&ch->mailbox->cout);
712 if (tail == head && readw(&ch->mailbox->cin) == ctail &&
713 readb(&bc->tbusy) == 0)
715 else { /* Begin if some space on the card has been used */
716 head = readw(&bc->tin) & (ch->txbufsize - 1);
717 tail &= (ch->txbufsize - 1);
719 * The logic here is basically opposite of the above
720 * pc_write_room here we are finding the amount of bytes in the
721 * buffer filled. Not the amount of bytes empty.
723 remain = tail - head - 1;
725 remain += ch->txbufsize;
726 chars = (int)(ch->txbufsize - remain);
728 * Make it possible to wakeup anything waiting for output in
731 * If not already set. Setup an event to indicate when the
732 * transmit buffer empties.
734 if (!(ch->statusflags & EMPTYWAIT))
735 setup_empty_event(tty, ch);
736 } /* End if some space on the card has been used */
738 spin_unlock_irqrestore(&epca_lock, flags);
739 /* Return number of characters residing on card. */
743 static void pc_flush_buffer(struct tty_struct *tty)
748 struct board_chan __iomem *bc;
750 * verifyChannel returns the channel from the tty struct if it is
751 * valid. This serves as a sanity check.
753 ch = verifyChannel(tty);
757 spin_lock_irqsave(&epca_lock, flags);
760 tail = readw(&bc->tout);
761 /* Have FEP move tout pointer; effectively flushing transmit buffer */
762 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
764 spin_unlock_irqrestore(&epca_lock, flags);
768 static void pc_flush_chars(struct tty_struct *tty)
772 * verifyChannel returns the channel from the tty struct if it is
773 * valid. This serves as a sanity check.
775 ch = verifyChannel(tty);
778 spin_lock_irqsave(&epca_lock, flags);
780 * If not already set and the transmitter is busy setup an
781 * event to indicate when the transmit empties.
783 if ((ch->statusflags & TXBUSY) &&
784 !(ch->statusflags & EMPTYWAIT))
785 setup_empty_event(tty, ch);
786 spin_unlock_irqrestore(&epca_lock, flags);
790 static int block_til_ready(struct tty_struct *tty,
791 struct file *filp, struct channel *ch)
793 DECLARE_WAITQUEUE(wait, current);
794 int retval, do_clocal = 0;
797 if (tty_hung_up_p(filp)) {
798 if (ch->port.flags & ASYNC_HUP_NOTIFY)
801 retval = -ERESTARTSYS;
806 * If the device is in the middle of being closed, then block until
807 * it's done, and then try again.
809 if (ch->port.flags & ASYNC_CLOSING) {
810 interruptible_sleep_on(&ch->port.close_wait);
812 if (ch->port.flags & ASYNC_HUP_NOTIFY)
818 if (filp->f_flags & O_NONBLOCK) {
820 * If non-blocking mode is set, then make the check up front
823 ch->port.flags |= ASYNC_NORMAL_ACTIVE;
826 if (tty->termios->c_cflag & CLOCAL)
828 /* Block waiting for the carrier detect and the line to become free */
831 add_wait_queue(&ch->port.open_wait, &wait);
833 spin_lock_irqsave(&epca_lock, flags);
834 /* We dec count so that pc_close will know when to free things */
835 if (!tty_hung_up_p(filp))
837 ch->port.blocked_open++;
839 set_current_state(TASK_INTERRUPTIBLE);
840 if (tty_hung_up_p(filp) ||
841 !(ch->port.flags & ASYNC_INITIALIZED)) {
842 if (ch->port.flags & ASYNC_HUP_NOTIFY)
845 retval = -ERESTARTSYS;
848 if (!(ch->port.flags & ASYNC_CLOSING) &&
849 (do_clocal || (ch->imodem & ch->dcd)))
851 if (signal_pending(current)) {
852 retval = -ERESTARTSYS;
855 spin_unlock_irqrestore(&epca_lock, flags);
857 * Allow someone else to be scheduled. We will occasionally go
858 * through this loop until one of the above conditions change.
859 * The below schedule call will allow other processes to enter
860 * and prevent this loop from hogging the cpu.
863 spin_lock_irqsave(&epca_lock, flags);
866 __set_current_state(TASK_RUNNING);
867 remove_wait_queue(&ch->port.open_wait, &wait);
868 if (!tty_hung_up_p(filp))
870 ch->port.blocked_open--;
872 spin_unlock_irqrestore(&epca_lock, flags);
877 ch->port.flags |= ASYNC_NORMAL_ACTIVE;
881 static int pc_open(struct tty_struct *tty, struct file *filp)
885 int line, retval, boardnum;
886 struct board_chan __iomem *bc;
890 if (line < 0 || line >= nbdevs)
893 ch = &digi_channels[line];
894 boardnum = ch->boardnum;
896 /* Check status of board configured in system. */
899 * I check to see if the epca_setup routine detected an user error. It
900 * might be better to put this in pc_init, but for the moment it goes
903 if (invalid_lilo_config) {
904 if (setup_error_code & INVALID_BOARD_TYPE)
905 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
906 if (setup_error_code & INVALID_NUM_PORTS)
907 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
908 if (setup_error_code & INVALID_MEM_BASE)
909 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
910 if (setup_error_code & INVALID_PORT_BASE)
911 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
912 if (setup_error_code & INVALID_BOARD_STATUS)
913 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
914 if (setup_error_code & INVALID_ALTPIN)
915 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
916 tty->driver_data = NULL; /* Mark this device as 'down' */
919 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
920 tty->driver_data = NULL; /* Mark this device as 'down' */
926 tty->driver_data = NULL;
930 spin_lock_irqsave(&epca_lock, flags);
932 * Every time a channel is opened, increment a counter. This is
933 * necessary because we do not wish to flush and shutdown the channel
934 * until the last app holding the channel open, closes it.
938 * Set a kernel structures pointer to our local channel structure. This
939 * way we can get to it when passed only a tty struct.
941 tty->driver_data = ch;
943 * If this is the first time the channel has been opened, initialize
944 * the tty->termios struct otherwise let pc_close handle it.
949 /* Save boards current modem status */
950 ch->imodem = readb(&bc->mstat);
953 * Set receive head and tail ptrs to each other. This indicates no data
956 head = readw(&bc->rin);
957 writew(head, &bc->rout);
959 /* Set the channels associated tty structure */
963 * The below routine generally sets up parity, baud, flow control
964 * issues, etc.... It effect both control flags and input flags.
967 ch->port.flags |= ASYNC_INITIALIZED;
969 spin_unlock_irqrestore(&epca_lock, flags);
971 retval = block_til_ready(tty, filp, ch);
975 * Set this again in case a hangup set it to zero while this open() was
976 * waiting for the line...
978 spin_lock_irqsave(&epca_lock, flags);
981 /* Enable Digi Data events */
982 writeb(1, &bc->idata);
984 spin_unlock_irqrestore(&epca_lock, flags);
988 static int __init epca_module_init(void)
992 module_init(epca_module_init);
994 static struct pci_driver epca_driver;
996 static void __exit epca_module_exit(void)
999 struct board_info *bd;
1002 del_timer_sync(&epca_timer);
1004 if (tty_unregister_driver(pc_driver) ||
1005 tty_unregister_driver(pc_info)) {
1006 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
1009 put_tty_driver(pc_driver);
1010 put_tty_driver(pc_info);
1012 for (crd = 0; crd < num_cards; crd++) {
1014 if (!bd) { /* sanity check */
1015 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1019 for (count = 0; count < bd->numports; count++, ch++) {
1020 if (ch && ch->port.tty)
1021 tty_hangup(ch->port.tty);
1024 pci_unregister_driver(&epca_driver);
1026 module_exit(epca_module_exit);
1028 static const struct tty_operations pc_ops = {
1032 .write_room = pc_write_room,
1033 .flush_buffer = pc_flush_buffer,
1034 .chars_in_buffer = pc_chars_in_buffer,
1035 .flush_chars = pc_flush_chars,
1037 .set_termios = pc_set_termios,
1040 .throttle = pc_throttle,
1041 .unthrottle = pc_unthrottle,
1042 .hangup = pc_hangup,
1043 .break_ctl = pc_send_break
1046 static int info_open(struct tty_struct *tty, struct file *filp)
1051 static struct tty_operations info_ops = {
1053 .ioctl = info_ioctl,
1056 static int __init pc_init(void)
1059 struct board_info *bd;
1060 unsigned char board_id = 0;
1063 int pci_boards_found, pci_count;
1067 pc_driver = alloc_tty_driver(MAX_ALLOC);
1071 pc_info = alloc_tty_driver(MAX_ALLOC);
1076 * If epca_setup has not been ran by LILO set num_cards to defaults;
1077 * copy board structure defined by digiConfig into drivers board
1078 * structure. Note : If LILO has ran epca_setup then epca_setup will
1079 * handle defining num_cards as well as copying the data into the board
1083 /* driver has been configured via. epcaconfig */
1085 num_cards = NUMCARDS;
1086 memcpy(&boards, &static_boards,
1087 sizeof(struct board_info) * NUMCARDS);
1091 * Note : If lilo was used to configure the driver and the ignore
1092 * epcaconfig option was choosen (digiepca=2) then nbdevs and num_cards
1093 * will equal 0 at this point. This is okay; PCI cards will still be
1094 * picked up if detected.
1098 * Set up interrupt, we will worry about memory allocation in
1101 printk(KERN_INFO "DIGI epca driver version %s loaded.\n", VERSION);
1104 * NOTE : This code assumes that the number of ports found in the
1105 * boards array is correct. This could be wrong if the card in question
1106 * is PCI (And therefore has no ports entry in the boards structure.)
1107 * The rest of the information will be valid for PCI because the
1108 * beginning of pc_init scans for PCI and determines i/o and base
1109 * memory addresses. I am not sure if it is possible to read the number
1110 * of ports supported by the card prior to it being booted (Since that
1111 * is the state it is in when pc_init is run). Because it is not
1112 * possible to query the number of supported ports until after the card
1113 * has booted; we are required to calculate the card_ptrs as the card
1114 * is initialized (Inside post_fep_init). The negative thing about this
1115 * approach is that digiDload's call to GET_INFO will have a bad port
1116 * value. (Since this is called prior to post_fep_init.)
1118 pci_boards_found = 0;
1119 if (num_cards < MAXBOARDS)
1120 pci_boards_found += init_PCI();
1121 num_cards += pci_boards_found;
1123 pc_driver->owner = THIS_MODULE;
1124 pc_driver->name = "ttyD";
1125 pc_driver->major = DIGI_MAJOR;
1126 pc_driver->minor_start = 0;
1127 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1128 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1129 pc_driver->init_termios = tty_std_termios;
1130 pc_driver->init_termios.c_iflag = 0;
1131 pc_driver->init_termios.c_oflag = 0;
1132 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1133 pc_driver->init_termios.c_lflag = 0;
1134 pc_driver->init_termios.c_ispeed = 9600;
1135 pc_driver->init_termios.c_ospeed = 9600;
1136 pc_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK;
1137 tty_set_operations(pc_driver, &pc_ops);
1139 pc_info->owner = THIS_MODULE;
1140 pc_info->name = "digi_ctl";
1141 pc_info->major = DIGIINFOMAJOR;
1142 pc_info->minor_start = 0;
1143 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1144 pc_info->subtype = SERIAL_TYPE_INFO;
1145 pc_info->init_termios = tty_std_termios;
1146 pc_info->init_termios.c_iflag = 0;
1147 pc_info->init_termios.c_oflag = 0;
1148 pc_info->init_termios.c_lflag = 0;
1149 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1150 pc_info->init_termios.c_ispeed = 9600;
1151 pc_info->init_termios.c_ospeed = 9600;
1152 pc_info->flags = TTY_DRIVER_REAL_RAW;
1153 tty_set_operations(pc_info, &info_ops);
1156 for (crd = 0; crd < num_cards; crd++) {
1158 * This is where the appropriate memory handlers for the
1159 * hardware is set. Everything at runtime blindly jumps through
1163 /* defined in epcaconfig.h */
1169 bd->memwinon = pcxem_memwinon;
1170 bd->memwinoff = pcxem_memwinoff;
1171 bd->globalwinon = pcxem_globalwinon;
1172 bd->txwinon = pcxem_txwinon;
1173 bd->rxwinon = pcxem_rxwinon;
1174 bd->memoff = pcxem_memoff;
1175 bd->assertgwinon = dummy_assertgwinon;
1176 bd->assertmemoff = dummy_assertmemoff;
1182 bd->memwinon = dummy_memwinon;
1183 bd->memwinoff = dummy_memwinoff;
1184 bd->globalwinon = dummy_globalwinon;
1185 bd->txwinon = dummy_txwinon;
1186 bd->rxwinon = dummy_rxwinon;
1187 bd->memoff = dummy_memoff;
1188 bd->assertgwinon = dummy_assertgwinon;
1189 bd->assertmemoff = dummy_assertmemoff;
1194 bd->memwinon = pcxe_memwinon;
1195 bd->memwinoff = pcxe_memwinoff;
1196 bd->globalwinon = pcxe_globalwinon;
1197 bd->txwinon = pcxe_txwinon;
1198 bd->rxwinon = pcxe_rxwinon;
1199 bd->memoff = pcxe_memoff;
1200 bd->assertgwinon = dummy_assertgwinon;
1201 bd->assertmemoff = dummy_assertmemoff;
1206 bd->memwinon = pcxi_memwinon;
1207 bd->memwinoff = pcxi_memwinoff;
1208 bd->globalwinon = pcxi_globalwinon;
1209 bd->txwinon = pcxi_txwinon;
1210 bd->rxwinon = pcxi_rxwinon;
1211 bd->memoff = pcxi_memoff;
1212 bd->assertgwinon = pcxi_assertgwinon;
1213 bd->assertmemoff = pcxi_assertmemoff;
1221 * Some cards need a memory segment to be defined for use in
1222 * transmit and receive windowing operations. These boards are
1223 * listed in the below switch. In the case of the XI the amount
1224 * of memory on the board is variable so the memory_seg is also
1225 * variable. This code determines what they segment should be.
1231 bd->memory_seg = 0xf000;
1235 board_id = inb((int)bd->port);
1236 if ((board_id & 0x1) == 0x1) {
1237 /* it's an XI card */
1238 /* Is it a 64K board */
1239 if ((board_id & 0x30) == 0)
1240 bd->memory_seg = 0xf000;
1242 /* Is it a 128K board */
1243 if ((board_id & 0x30) == 0x10)
1244 bd->memory_seg = 0xe000;
1246 /* Is is a 256K board */
1247 if ((board_id & 0x30) == 0x20)
1248 bd->memory_seg = 0xc000;
1250 /* Is it a 512K board */
1251 if ((board_id & 0x30) == 0x30)
1252 bd->memory_seg = 0x8000;
1254 printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n", (int)bd->port);
1259 err = tty_register_driver(pc_driver);
1261 printk(KERN_ERR "Couldn't register Digi PC/ driver");
1265 err = tty_register_driver(pc_info);
1267 printk(KERN_ERR "Couldn't register Digi PC/ info ");
1271 /* Start up the poller to check for events on all enabled boards */
1272 init_timer(&epca_timer);
1273 epca_timer.function = epcapoll;
1274 mod_timer(&epca_timer, jiffies + HZ/25);
1278 tty_unregister_driver(pc_driver);
1280 put_tty_driver(pc_info);
1282 put_tty_driver(pc_driver);
1287 static void post_fep_init(unsigned int crd)
1290 void __iomem *memaddr;
1291 struct global_data __iomem *gd;
1292 struct board_info *bd;
1293 struct board_chan __iomem *bc;
1295 int shrinkmem = 0, lowwater;
1298 * This call is made by the user via. the ioctl call DIGI_INIT. It is
1299 * responsible for setting up all the card specific stuff.
1304 * If this is a PCI board, get the port info. Remember PCI cards do not
1305 * have entries into the epcaconfig.h file, so we can't get the number
1306 * of ports from it. Unfortunetly, this means that anyone doing a
1307 * DIGI_GETINFO before the board has booted will get an invalid number
1308 * of ports returned (It should return 0). Calls to DIGI_GETINFO after
1309 * DIGI_INIT has been called will return the proper values.
1311 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
1313 * Below we use XEMPORTS as a memory offset regardless of which
1314 * PCI card it is. This is because all of the supported PCI
1315 * cards have the same memory offset for the channel data. This
1316 * will have to be changed if we ever develop a PCI/XE card.
1317 * NOTE : The FEP manual states that the port offset is 0xC22
1318 * as opposed to 0xC02. This is only true for PC/XE, and PC/XI
1319 * cards; not for the XEM, or CX series. On the PCI cards the
1320 * number of ports is determined by reading a ID PROM located
1321 * in the box attached to the card. The card can then determine
1322 * the index the id to determine the number of ports available.
1323 * (FYI - The id should be located at 0x1ac (And may use up to
1324 * 4 bytes if the box in question is a XEM or CX)).
1326 /* PCI cards are already remapped at this point ISA are not */
1327 bd->numports = readw(bd->re_map_membase + XEMPORTS);
1328 epcaassert(bd->numports <= 64, "PCI returned a invalid number of ports");
1329 nbdevs += (bd->numports);
1331 /* Fix up the mappings for ISA/EISA etc */
1332 /* FIXME: 64K - can we be smarter ? */
1333 bd->re_map_membase = ioremap_nocache(bd->membase, 0x10000);
1337 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1339 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1342 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1344 memaddr = bd->re_map_membase;
1347 * The below assignment will set bc to point at the BEGINING of the
1348 * cards channel structures. For 1 card there will be between 8 and 64
1349 * of these structures.
1351 bc = memaddr + CHANSTRUCT;
1354 * The below assignment will set gd to point at the BEGINING of global
1355 * memory address 0xc00. The first data in that global memory actually
1356 * starts at address 0xc1a. The command in pointer begins at 0xd10.
1358 gd = memaddr + GLOBAL;
1361 * XEPORTS (address 0xc22) points at the number of channels the card
1362 * supports. (For 64XE, XI, XEM, and XR use 0xc02)
1364 if ((bd->type == PCXEVE || bd->type == PCXE) &&
1365 (readw(memaddr + XEPORTS) < 3))
1367 if (bd->type < PCIXEM)
1368 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1373 * Remember ch is the main drivers channels structure, while bc is the
1374 * cards channel structure.
1376 for (i = 0; i < bd->numports; i++, ch++, bc++) {
1377 unsigned long flags;
1382 INIT_WORK(&ch->tqueue, do_softint);
1383 ch->board = &boards[crd];
1385 spin_lock_irqsave(&epca_lock, flags);
1388 * Since some of the boards use different bitmaps for
1389 * their control signals we cannot hard code these
1390 * values and retain portability. We virtualize this
1419 if (boards[crd].altpin) {
1420 ch->dsr = ch->m_dcd;
1421 ch->dcd = ch->m_dsr;
1422 ch->digiext.digi_flags |= DIGI_ALTPIN;
1424 ch->dcd = ch->m_dcd;
1425 ch->dsr = ch->m_dsr;
1430 ch->magic = EPCA_MAGIC;
1431 ch->port.tty = NULL;
1434 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1438 tseg = readw(&bc->tseg);
1439 rseg = readw(&bc->rseg);
1445 /* Cover all the 2MEG cards */
1446 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1447 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1448 ch->txwin = FEPWIN | (tseg >> 11);
1449 ch->rxwin = FEPWIN | (rseg >> 11);
1454 /* Cover all the 32K windowed cards */
1455 /* Mask equal to window size - 1 */
1456 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1457 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1458 ch->txwin = FEPWIN | (tseg >> 11);
1459 ch->rxwin = FEPWIN | (rseg >> 11);
1464 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4)
1466 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1467 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4)
1469 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >> 9);
1474 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1475 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
1476 ch->txwin = ch->rxwin = 0;
1481 ch->txbufsize = readw(&bc->tmax) + 1;
1484 ch->rxbufsize = readw(&bc->rmax) + 1;
1486 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1488 /* Set transmitter low water mark */
1489 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1491 /* Set receiver low water mark */
1492 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
1494 /* Set receiver high water mark */
1495 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1497 writew(100, &bc->edelay);
1498 writeb(1, &bc->idata);
1500 ch->startc = readb(&bc->startc);
1501 ch->stopc = readb(&bc->stopc);
1502 ch->startca = readb(&bc->startca);
1503 ch->stopca = readb(&bc->stopca);
1513 ch->close_delay = 50;
1515 ch->port.blocked_open = 0;
1516 init_waitqueue_head(&ch->port.open_wait);
1517 init_waitqueue_head(&ch->port.close_wait);
1519 spin_unlock_irqrestore(&epca_lock, flags);
1523 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1524 VERSION, board_desc[bd->type], (long)bd->port,
1525 (long)bd->membase, bd->numports);
1529 static void epcapoll(unsigned long ignored)
1531 unsigned long flags;
1533 unsigned int head, tail;
1535 struct board_info *bd;
1538 * This routine is called upon every timer interrupt. Even though the
1539 * Digi series cards are capable of generating interrupts this method
1540 * of non-looping polling is more efficient. This routine checks for
1541 * card generated events (Such as receive data, are transmit buffer
1542 * empty) and acts on those events.
1544 for (crd = 0; crd < num_cards; crd++) {
1548 if ((bd->status == DISABLED) || digi_poller_inhibited)
1552 * assertmemoff is not needed here; indeed it is an empty
1553 * subroutine. It is being kept because future boards may need
1554 * this as well as some legacy boards.
1556 spin_lock_irqsave(&epca_lock, flags);
1563 * In this case head and tail actually refer to the event queue
1564 * not the transmit or receive queue.
1566 head = readw(&ch->mailbox->ein);
1567 tail = readw(&ch->mailbox->eout);
1569 /* If head isn't equal to tail we have an event */
1574 spin_unlock_irqrestore(&epca_lock, flags);
1575 } /* End for each card */
1576 mod_timer(&epca_timer, jiffies + (HZ / 25));
1579 static void doevent(int crd)
1581 void __iomem *eventbuf;
1582 struct channel *ch, *chan0;
1583 static struct tty_struct *tty;
1584 struct board_info *bd;
1585 struct board_chan __iomem *bc;
1586 unsigned int tail, head;
1591 * This subroutine is called by epcapoll when an event is detected
1592 * in the event queue. This routine responds to those events.
1596 chan0 = card_ptr[crd];
1597 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
1598 assertgwinon(chan0);
1599 while ((tail = readw(&chan0->mailbox->eout)) !=
1600 (head = readw(&chan0->mailbox->ein))) {
1601 /* Begin while something in event queue */
1602 assertgwinon(chan0);
1603 eventbuf = bd->re_map_membase + tail + ISTART;
1604 /* Get the channel the event occurred on */
1605 channel = readb(eventbuf);
1606 /* Get the actual event code that occurred */
1607 event = readb(eventbuf + 1);
1609 * The two assignments below get the current modem status
1610 * (mstat) and the previous modem status (lstat). These are
1611 * useful becuase an event could signal a change in modem
1614 mstat = readb(eventbuf + 2);
1615 lstat = readb(eventbuf + 3);
1617 ch = chan0 + channel;
1618 if ((unsigned)channel >= bd->numports || !ch) {
1619 if (channel >= bd->numports)
1629 if (event & DATA_IND) { /* Begin DATA_IND */
1632 } /* End DATA_IND */
1633 /* else *//* Fix for DCD transition missed bug */
1634 if (event & MODEMCHG_IND) {
1635 /* A modem signal change has been indicated */
1637 if (ch->port.flags & ASYNC_CHECK_CD) {
1638 /* We are now receiving dcd */
1639 if (mstat & ch->dcd)
1640 wake_up_interruptible(&ch->port.open_wait);
1641 else /* No dcd; hangup */
1642 pc_sched_event(ch, EPCA_EVENT_HANGUP);
1647 if (event & BREAK_IND) {
1648 /* A break has been indicated */
1649 tty_insert_flip_char(tty, 0, TTY_BREAK);
1650 tty_schedule_flip(tty);
1651 } else if (event & LOWTX_IND) {
1652 if (ch->statusflags & LOWWAIT) {
1653 ch->statusflags &= ~LOWWAIT;
1656 } else if (event & EMPTYTX_IND) {
1657 /* This event is generated by
1658 setup_empty_event */
1659 ch->statusflags &= ~TXBUSY;
1660 if (ch->statusflags & EMPTYWAIT) {
1661 ch->statusflags &= ~EMPTYWAIT;
1669 writew(1, &bc->idata);
1670 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
1672 } /* End while something in event queue */
1675 static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1676 int byte2, int ncmds, int bytecmd)
1678 unchar __iomem *memaddr;
1679 unsigned int head, cmdTail, cmdStart, cmdMax;
1683 /* This is the routine in which commands may be passed to the card. */
1685 if (ch->board->status == DISABLED)
1688 /* Remember head (As well as max) is just an offset not a base addr */
1689 head = readw(&ch->mailbox->cin);
1690 /* cmdStart is a base address */
1691 cmdStart = readw(&ch->mailbox->cstart);
1693 * We do the addition below because we do not want a max pointer
1694 * relative to cmdStart. We want a max pointer that points at the
1695 * physical end of the command queue.
1697 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
1698 memaddr = ch->board->re_map_membase;
1700 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1701 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n",
1702 __LINE__, cmd, head);
1703 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n",
1704 __LINE__, cmdMax, cmdStart);
1708 writeb(cmd, memaddr + head + cmdStart + 0);
1709 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1710 /* Below word_or_byte is bits to set */
1711 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1712 /* Below byte2 is bits to reset */
1713 writeb(byte2, memaddr + head + cmdStart + 3);
1715 writeb(cmd, memaddr + head + cmdStart + 0);
1716 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1717 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1719 head = (head + 4) & (cmdMax - cmdStart - 4);
1720 writew(head, &ch->mailbox->cin);
1726 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1729 head = readw(&ch->mailbox->cin);
1730 cmdTail = readw(&ch->mailbox->cout);
1731 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
1733 * Basically this will break when the FEP acknowledges the
1734 * command by incrementing cmdTail (Making it equal to head).
1736 if (n <= ncmds * (sizeof(short) * 4))
1742 * Digi products use fields in their channels structures that are very similar
1743 * to the c_cflag and c_iflag fields typically found in UNIX termios
1744 * structures. The below three routines allow mappings between these hardware
1745 * "flags" and their respective Linux flags.
1747 static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
1751 if (cflag & CRTSCTS) {
1752 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1753 res |= ((ch->m_cts) | (ch->m_rts));
1756 if (ch->digiext.digi_flags & RTSPACE)
1759 if (ch->digiext.digi_flags & DTRPACE)
1762 if (ch->digiext.digi_flags & CTSPACE)
1765 if (ch->digiext.digi_flags & DSRPACE)
1768 if (ch->digiext.digi_flags & DCDPACE)
1771 if (res & (ch->m_rts))
1772 ch->digiext.digi_flags |= RTSPACE;
1774 if (res & (ch->m_cts))
1775 ch->digiext.digi_flags |= CTSPACE;
1780 static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
1782 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
1783 INPCK | ISTRIP | IXON | IXANY | IXOFF);
1784 if (ch->digiext.digi_flags & DIGI_AIXON)
1789 static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
1792 if (cflag & CBAUDEX) {
1793 ch->digiext.digi_flags |= DIGI_FAST;
1795 * HUPCL bit is used by FEP to indicate fast baud table is to
1800 ch->digiext.digi_flags &= ~DIGI_FAST;
1802 * CBAUD has bit position 0x1000 set these days to indicate Linux
1803 * baud rate remap. Digi hardware can't handle the bit assignment.
1804 * (We use a different bit assignment for high speed.). Clear this
1807 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
1809 * This gets a little confusing. The Digi cards have their own
1810 * representation of c_cflags controlling baud rate. For the most part
1811 * this is identical to the Linux implementation. However; Digi
1812 * supports one rate (76800) that Linux doesn't. This means that the
1813 * c_cflag entry that would normally mean 76800 for Digi actually means
1814 * 115200 under Linux. Without the below mapping, a stty 115200 would
1815 * only drive the board at 76800. Since the rate 230400 is also found
1816 * after 76800, the same problem afflicts us when we choose a rate of
1817 * 230400. Without the below modificiation stty 230400 would actually
1820 * There are two additional differences. The Linux value for CLOCAL
1821 * (0x800; 0004000) has no meaning to the Digi hardware. Also in later
1822 * releases of Linux; the CBAUD define has CBAUDEX (0x1000; 0010000)
1823 * ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX should be
1824 * checked for a screened out prior to termios2digi_c returning. Since
1825 * CLOCAL isn't used by the board this can be ignored as long as the
1826 * returned value is used only by Digi hardware.
1828 if (cflag & CBAUDEX) {
1830 * The below code is trying to guarantee that only baud rates
1831 * 115200 and 230400 are remapped. We use exclusive or because
1832 * the various baud rates share common bit positions and
1833 * therefore can't be tested for easily.
1835 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
1836 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
1842 /* Caller must hold the locks */
1843 static void epcaparam(struct tty_struct *tty, struct channel *ch)
1845 unsigned int cmdHead;
1846 struct ktermios *ts;
1847 struct board_chan __iomem *bc;
1848 unsigned mval, hflow, cflag, iflag;
1851 epcaassert(bc != NULL, "bc out of range");
1855 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
1856 cmdHead = readw(&bc->rin);
1857 writew(cmdHead, &bc->rout);
1858 cmdHead = readw(&bc->tin);
1859 /* Changing baud in mid-stream transmission can be wonderful */
1861 * Flush current transmit buffer by setting cmdTail pointer
1862 * (tout) to cmdHead pointer (tin). Hopefully the transmit
1865 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
1867 } else { /* Begin CBAUD not detected */
1869 * c_cflags have changed but that change had nothing to do with
1870 * BAUD. Propagate the change to the card.
1872 cflag = termios2digi_c(ch, ts->c_cflag);
1873 if (cflag != ch->fepcflag) {
1874 ch->fepcflag = cflag;
1875 /* Set baud rate, char size, stop bits, parity */
1876 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
1879 * If the user has not forced CLOCAL and if the device is not a
1880 * CALLOUT device (Which is always CLOCAL) we set flags such
1881 * that the driver will wait on carrier detect.
1883 if (ts->c_cflag & CLOCAL)
1884 ch->port.flags &= ~ASYNC_CHECK_CD;
1886 ch->port.flags |= ASYNC_CHECK_CD;
1887 mval = ch->m_dtr | ch->m_rts;
1888 } /* End CBAUD not detected */
1889 iflag = termios2digi_i(ch, ts->c_iflag);
1890 /* Check input mode flags */
1891 if (iflag != ch->fepiflag) {
1892 ch->fepiflag = iflag;
1894 * Command sets channels iflag structure on the board. Such
1895 * things as input soft flow control, handling of parity
1896 * errors, and break handling are all set here.
1898 * break handling, parity handling, input stripping,
1899 * flow control chars
1901 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
1904 * Set the board mint value for this channel. This will cause hardware
1905 * events to be generated each time the DCD signal (Described in mint)
1908 writeb(ch->dcd, &bc->mint);
1909 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
1910 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
1911 writeb(0, &bc->mint);
1912 ch->imodem = readb(&bc->mstat);
1913 hflow = termios2digi_h(ch, ts->c_cflag);
1914 if (hflow != ch->hflow) {
1917 * Hard flow control has been selected but the board is not
1918 * using it. Activate hard flow control now.
1920 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
1922 mval ^= ch->modemfake & (mval ^ ch->modem);
1924 if (ch->omodem ^ mval) {
1927 * The below command sets the DTR and RTS mstat structure. If
1928 * hard flow control is NOT active these changes will drive the
1929 * output of the actual DTR and RTS lines. If hard flow control
1930 * is active, the changes will be saved in the mstat structure
1931 * and only asserted when hard flow control is turned off.
1934 /* First reset DTR & RTS; then set them */
1935 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
1936 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
1938 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
1939 ch->fepstartc = ch->startc;
1940 ch->fepstopc = ch->stopc;
1942 * The XON / XOFF characters have changed; propagate these
1943 * changes to the card.
1945 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
1947 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
1948 ch->fepstartca = ch->startca;
1949 ch->fepstopca = ch->stopca;
1951 * Similar to the above, this time the auxilarly XON / XOFF
1952 * characters have changed; propagate these changes to the card.
1954 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
1958 /* Caller holds lock */
1959 static void receive_data(struct channel *ch)
1962 struct ktermios *ts = NULL;
1963 struct tty_struct *tty;
1964 struct board_chan __iomem *bc;
1965 int dataToRead, wrapgap, bytesAvailable;
1966 unsigned int tail, head;
1967 unsigned int wrapmask;
1970 * This routine is called by doint when a receive data event has taken
1974 if (ch->statusflags & RXSTOPPED)
1981 wrapmask = ch->rxbufsize - 1;
1984 * Get the head and tail pointers to the receiver queue. Wrap the head
1985 * pointer if it has reached the end of the buffer.
1987 head = readw(&bc->rin);
1989 tail = readw(&bc->rout) & wrapmask;
1991 bytesAvailable = (head - tail) & wrapmask;
1992 if (bytesAvailable == 0)
1995 /* If CREAD bit is off or device not open, set TX tail to head */
1996 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
1997 writew(head, &bc->rout);
2001 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
2004 if (readb(&bc->orun)) {
2005 writeb(0, &bc->orun);
2006 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",
2008 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
2011 while (bytesAvailable > 0) {
2012 /* Begin while there is data on the card */
2013 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
2015 * Even if head has wrapped around only report the amount of
2016 * data to be equal to the size - tail. Remember memcpy can't
2017 * automaticly wrap around the receive buffer.
2019 dataToRead = (wrapgap < bytesAvailable) ? wrapgap
2021 /* Make sure we don't overflow the buffer */
2022 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
2023 if (dataToRead == 0)
2026 * Move data read from our card into the line disciplines
2027 * buffer for translation if necessary.
2029 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
2030 tail = (tail + dataToRead) & wrapmask;
2031 bytesAvailable -= dataToRead;
2032 } /* End while there is data on the card */
2034 writew(tail, &bc->rout);
2035 /* Must be called with global data */
2036 tty_schedule_flip(ch->port.tty);
2039 static int info_ioctl(struct tty_struct *tty, struct file *file,
2040 unsigned int cmd, unsigned long arg)
2045 struct digi_info di;
2048 if (get_user(brd, (unsigned int __user *)arg))
2050 if (brd < 0 || brd >= num_cards || num_cards == 0)
2053 memset(&di, 0, sizeof(di));
2056 di.status = boards[brd].status;
2057 di.type = boards[brd].type ;
2058 di.numports = boards[brd].numports ;
2059 /* Legacy fixups - just move along nothing to see */
2060 di.port = (unsigned char *)boards[brd].port ;
2061 di.membase = (unsigned char *)boards[brd].membase ;
2063 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
2071 int brd = arg & 0xff000000 >> 16;
2072 unsigned char state = arg & 0xff;
2074 if (brd < 0 || brd >= num_cards) {
2075 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
2078 digi_poller_inhibited = state;
2085 * This call is made by the apps to complete the
2086 * initialization of the board(s). This routine is
2087 * responsible for setting the card to its initial
2088 * state and setting the drivers control fields to the
2089 * sutianle settings for the card in question.
2092 for (crd = 0; crd < num_cards; crd++)
2102 static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2104 struct channel *ch = (struct channel *) tty->driver_data;
2105 struct board_chan __iomem *bc;
2106 unsigned int mstat, mflag = 0;
2107 unsigned long flags;
2114 spin_lock_irqsave(&epca_lock, flags);
2116 mstat = readb(&bc->mstat);
2118 spin_unlock_irqrestore(&epca_lock, flags);
2120 if (mstat & ch->m_dtr)
2122 if (mstat & ch->m_rts)
2124 if (mstat & ch->m_cts)
2126 if (mstat & ch->dsr)
2128 if (mstat & ch->m_ri)
2130 if (mstat & ch->dcd)
2135 static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2136 unsigned int set, unsigned int clear)
2138 struct channel *ch = (struct channel *) tty->driver_data;
2139 unsigned long flags;
2144 spin_lock_irqsave(&epca_lock, flags);
2146 * I think this modemfake stuff is broken. It doesn't correctly reflect
2147 * the behaviour desired by the TIOCM* ioctls. Therefore this is
2150 if (set & TIOCM_RTS) {
2151 ch->modemfake |= ch->m_rts;
2152 ch->modem |= ch->m_rts;
2154 if (set & TIOCM_DTR) {
2155 ch->modemfake |= ch->m_dtr;
2156 ch->modem |= ch->m_dtr;
2158 if (clear & TIOCM_RTS) {
2159 ch->modemfake |= ch->m_rts;
2160 ch->modem &= ~ch->m_rts;
2162 if (clear & TIOCM_DTR) {
2163 ch->modemfake |= ch->m_dtr;
2164 ch->modem &= ~ch->m_dtr;
2168 * The below routine generally sets up parity, baud, flow control
2169 * issues, etc.... It effect both control flags and input flags.
2173 spin_unlock_irqrestore(&epca_lock, flags);
2177 static int pc_ioctl(struct tty_struct *tty, struct file *file,
2178 unsigned int cmd, unsigned long arg)
2181 unsigned long flags;
2182 unsigned int mflag, mstat;
2183 unsigned char startc, stopc;
2184 struct board_chan __iomem *bc;
2185 struct channel *ch = (struct channel *) tty->driver_data;
2186 void __user *argp = (void __user *)arg;
2194 mflag = pc_tiocmget(tty, file);
2195 if (put_user(mflag, (unsigned long __user *)argp))
2199 if (get_user(mstat, (unsigned __user *)argp))
2201 return pc_tiocmset(tty, file, mstat, ~mstat);
2203 spin_lock_irqsave(&epca_lock, flags);
2204 ch->omodem |= ch->m_dtr;
2206 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2208 spin_unlock_irqrestore(&epca_lock, flags);
2212 spin_lock_irqsave(&epca_lock, flags);
2213 ch->omodem &= ~ch->m_dtr;
2215 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2217 spin_unlock_irqrestore(&epca_lock, flags);
2220 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2226 if (cmd == DIGI_SETAW) {
2227 /* Setup an event to indicate when the transmit
2229 spin_lock_irqsave(&epca_lock, flags);
2230 setup_empty_event(tty, ch);
2231 spin_unlock_irqrestore(&epca_lock, flags);
2232 tty_wait_until_sent(tty, 0);
2234 /* ldisc lock already held in ioctl */
2235 if (tty->ldisc.ops->flush_buffer)
2236 tty->ldisc.ops->flush_buffer(tty);
2241 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2244 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
2245 ch->dcd = ch->m_dsr;
2246 ch->dsr = ch->m_dcd;
2248 ch->dcd = ch->m_dcd;
2249 ch->dsr = ch->m_dsr;
2252 spin_lock_irqsave(&epca_lock, flags);
2256 * The below routine generally sets up parity, baud, flow
2257 * control issues, etc.... It effect both control flags and
2262 spin_unlock_irqrestore(&epca_lock, flags);
2267 spin_lock_irqsave(&epca_lock, flags);
2269 if (cmd == DIGI_GETFLOW) {
2270 dflow.startc = readb(&bc->startc);
2271 dflow.stopc = readb(&bc->stopc);
2273 dflow.startc = readb(&bc->startca);
2274 dflow.stopc = readb(&bc->stopca);
2277 spin_unlock_irqrestore(&epca_lock, flags);
2279 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2285 if (cmd == DIGI_SETFLOW) {
2286 startc = ch->startc;
2289 startc = ch->startca;
2293 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2296 if (dflow.startc != startc || dflow.stopc != stopc) {
2297 /* Begin if setflow toggled */
2298 spin_lock_irqsave(&epca_lock, flags);
2301 if (cmd == DIGI_SETFLOW) {
2302 ch->fepstartc = ch->startc = dflow.startc;
2303 ch->fepstopc = ch->stopc = dflow.stopc;
2304 fepcmd(ch, SONOFFC, ch->fepstartc,
2305 ch->fepstopc, 0, 1);
2307 ch->fepstartca = ch->startca = dflow.startc;
2308 ch->fepstopca = ch->stopca = dflow.stopc;
2309 fepcmd(ch, SAUXONOFFC, ch->fepstartca,
2310 ch->fepstopca, 0, 1);
2313 if (ch->statusflags & TXSTOPPED)
2317 spin_unlock_irqrestore(&epca_lock, flags);
2318 } /* End if setflow toggled */
2321 return -ENOIOCTLCMD;
2326 static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2329 unsigned long flags;
2331 * verifyChannel returns the channel from the tty struct if it is
2332 * valid. This serves as a sanity check.
2334 ch = verifyChannel(tty);
2336 if (ch != NULL) { /* Begin if channel valid */
2337 spin_lock_irqsave(&epca_lock, flags);
2341 spin_unlock_irqrestore(&epca_lock, flags);
2343 if ((old_termios->c_cflag & CRTSCTS) &&
2344 ((tty->termios->c_cflag & CRTSCTS) == 0))
2345 tty->hw_stopped = 0;
2347 if (!(old_termios->c_cflag & CLOCAL) &&
2348 (tty->termios->c_cflag & CLOCAL))
2349 wake_up_interruptible(&ch->port.open_wait);
2351 } /* End if channel valid */
2354 static void do_softint(struct work_struct *work)
2356 struct channel *ch = container_of(work, struct channel, tqueue);
2357 /* Called in response to a modem change event */
2358 if (ch && ch->magic == EPCA_MAGIC) {
2359 struct tty_struct *tty = ch->port.tty;
2361 if (tty && tty->driver_data) {
2362 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) {
2364 wake_up_interruptible(&ch->port.open_wait);
2365 ch->port.flags &= ~ASYNC_NORMAL_ACTIVE;
2372 * pc_stop and pc_start provide software flow control to the routine and the
2375 static void pc_stop(struct tty_struct *tty)
2378 unsigned long flags;
2380 * verifyChannel returns the channel from the tty struct if it is
2381 * valid. This serves as a sanity check.
2383 ch = verifyChannel(tty);
2385 spin_lock_irqsave(&epca_lock, flags);
2386 if ((ch->statusflags & TXSTOPPED) == 0) {
2387 /* Begin if transmit stop requested */
2389 /* STOP transmitting now !! */
2390 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
2391 ch->statusflags |= TXSTOPPED;
2393 } /* End if transmit stop requested */
2394 spin_unlock_irqrestore(&epca_lock, flags);
2398 static void pc_start(struct tty_struct *tty)
2402 * verifyChannel returns the channel from the tty struct if it is
2403 * valid. This serves as a sanity check.
2405 ch = verifyChannel(tty);
2407 unsigned long flags;
2408 spin_lock_irqsave(&epca_lock, flags);
2409 /* Just in case output was resumed because of a change
2411 if (ch->statusflags & TXSTOPPED) {
2412 /* Begin transmit resume requested */
2413 struct board_chan __iomem *bc;
2416 if (ch->statusflags & LOWWAIT)
2417 writeb(1, &bc->ilow);
2418 /* Okay, you can start transmitting again... */
2419 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
2420 ch->statusflags &= ~TXSTOPPED;
2422 } /* End transmit resume requested */
2423 spin_unlock_irqrestore(&epca_lock, flags);
2428 * The below routines pc_throttle and pc_unthrottle are used to slow (And
2429 * resume) the receipt of data into the kernels receive buffers. The exact
2430 * occurrence of this depends on the size of the kernels receive buffer and
2431 * what the 'watermarks' are set to for that buffer. See the n_ttys.c file for
2434 static void pc_throttle(struct tty_struct *tty)
2437 unsigned long flags;
2439 * verifyChannel returns the channel from the tty struct if it is
2440 * valid. This serves as a sanity check.
2442 ch = verifyChannel(tty);
2444 spin_lock_irqsave(&epca_lock, flags);
2445 if ((ch->statusflags & RXSTOPPED) == 0) {
2447 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
2448 ch->statusflags |= RXSTOPPED;
2451 spin_unlock_irqrestore(&epca_lock, flags);
2455 static void pc_unthrottle(struct tty_struct *tty)
2458 unsigned long flags;
2460 * verifyChannel returns the channel from the tty struct if it is
2461 * valid. This serves as a sanity check.
2463 ch = verifyChannel(tty);
2465 /* Just in case output was resumed because of a change
2467 spin_lock_irqsave(&epca_lock, flags);
2468 if (ch->statusflags & RXSTOPPED) {
2470 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
2471 ch->statusflags &= ~RXSTOPPED;
2474 spin_unlock_irqrestore(&epca_lock, flags);
2478 static int pc_send_break(struct tty_struct *tty, int msec)
2480 struct channel *ch = (struct channel *) tty->driver_data;
2481 unsigned long flags;
2486 spin_lock_irqsave(&epca_lock, flags);
2489 * Maybe I should send an infinite break here, schedule() for msec
2490 * amount of time, and then stop the break. This way, the user can't
2491 * screw up the FEP by causing digi_send_break() to be called (i.e. via
2492 * an ioctl()) more than once in msec amount of time.
2493 * Try this for now...
2495 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2497 spin_unlock_irqrestore(&epca_lock, flags);
2501 /* Caller MUST hold the lock */
2502 static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2504 struct board_chan __iomem *bc = ch->brdchan;
2507 ch->statusflags |= EMPTYWAIT;
2509 * When set the iempty flag request a event to be generated when the
2510 * transmit buffer is empty (If there is no BREAK in progress).
2512 writeb(1, &bc->iempty);
2516 static void epca_setup(char *str, int *ints)
2518 struct board_info board;
2519 int index, loop, last;
2524 * If this routine looks a little strange it is because it is only
2525 * called if a LILO append command is given to boot the kernel with
2526 * parameters. In this way, we can provide the user a method of
2527 * changing his board configuration without rebuilding the kernel.
2532 memset(&board, 0, sizeof(board));
2534 /* Assume the data is int first, later we can change it */
2535 /* I think that array position 0 of ints holds the number of args */
2536 for (last = 0, index = 1; index <= ints[0]; index++)
2537 switch (index) { /* Begin parse switch */
2539 board.status = ints[index];
2541 * We check for 2 (As opposed to 1; because 2 is a flag
2542 * instructing the driver to ignore epcaconfig.) For
2543 * this reason we check for 2.
2545 if (board.status == 2) {
2546 /* Begin ignore epcaconfig as well as lilo cmd line */
2550 } /* End ignore epcaconfig as well as lilo cmd line */
2552 if (board.status > 2) {
2553 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n",
2555 invalid_lilo_config = 1;
2556 setup_error_code |= INVALID_BOARD_STATUS;
2562 board.type = ints[index];
2563 if (board.type >= PCIXEM) {
2564 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
2565 invalid_lilo_config = 1;
2566 setup_error_code |= INVALID_BOARD_TYPE;
2572 board.altpin = ints[index];
2573 if (board.altpin > 1) {
2574 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
2575 invalid_lilo_config = 1;
2576 setup_error_code |= INVALID_ALTPIN;
2583 board.numports = ints[index];
2584 if (board.numports < 2 || board.numports > 256) {
2585 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
2586 invalid_lilo_config = 1;
2587 setup_error_code |= INVALID_NUM_PORTS;
2590 nbdevs += board.numports;
2595 board.port = ints[index];
2596 if (ints[index] <= 0) {
2597 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
2598 invalid_lilo_config = 1;
2599 setup_error_code |= INVALID_PORT_BASE;
2606 board.membase = ints[index];
2607 if (ints[index] <= 0) {
2608 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",
2609 (unsigned int)board.membase);
2610 invalid_lilo_config = 1;
2611 setup_error_code |= INVALID_MEM_BASE;
2618 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
2621 } /* End parse switch */
2623 while (str && *str) { /* Begin while there is a string arg */
2624 /* find the next comma or terminator */
2626 /* While string is not null, and a comma hasn't been found */
2627 while (*temp && (*temp != ','))
2633 /* Set index to the number of args + 1 */
2639 if (strncmp("Disable", str, len) == 0)
2641 else if (strncmp("Enable", str, len) == 0)
2644 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
2645 invalid_lilo_config = 1;
2646 setup_error_code |= INVALID_BOARD_STATUS;
2653 for (loop = 0; loop < EPCA_NUM_TYPES; loop++)
2654 if (strcmp(board_desc[loop], str) == 0)
2657 * If the index incremented above refers to a
2658 * legitamate board type set it here.
2660 if (index < EPCA_NUM_TYPES)
2663 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
2664 invalid_lilo_config = 1;
2665 setup_error_code |= INVALID_BOARD_TYPE;
2673 if (strncmp("Disable", str, len) == 0)
2675 else if (strncmp("Enable", str, len) == 0)
2678 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
2679 invalid_lilo_config = 1;
2680 setup_error_code |= INVALID_ALTPIN;
2688 while (isdigit(*t2))
2692 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
2693 invalid_lilo_config = 1;
2694 setup_error_code |= INVALID_NUM_PORTS;
2699 * There is not a man page for simple_strtoul but the
2700 * code can be found in vsprintf.c. The first argument
2701 * is the string to translate (To an unsigned long
2702 * obviously), the second argument can be the address
2703 * of any character variable or a NULL. If a variable
2704 * is given, the end pointer of the string will be
2705 * stored in that variable; if a NULL is given the end
2706 * pointer will not be returned. The last argument is
2707 * the base to use. If a 0 is indicated, the routine
2708 * will attempt to determine the proper base by looking
2709 * at the values prefix (A '0' for octal, a 'x' for
2710 * hex, etc ... If a value is given it will use that
2711 * value as the base.
2713 board.numports = simple_strtoul(str, NULL, 0);
2714 nbdevs += board.numports;
2720 while (isxdigit(*t2))
2724 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
2725 invalid_lilo_config = 1;
2726 setup_error_code |= INVALID_PORT_BASE;
2730 board.port = simple_strtoul(str, NULL, 16);
2736 while (isxdigit(*t2))
2740 printk(KERN_ERR "epca_setup: Invalid memory base %s\n", str);
2741 invalid_lilo_config = 1;
2742 setup_error_code |= INVALID_MEM_BASE;
2745 board.membase = simple_strtoul(str, NULL, 16);
2749 printk(KERN_ERR "epca: Too many string parms\n");
2753 } /* End while there is a string arg */
2756 printk(KERN_ERR "epca: Insufficient parms specified\n");
2760 /* I should REALLY validate the stuff here */
2761 /* Copies our local copy of board into boards */
2762 memcpy((void *)&boards[num_cards], (void *)&board, sizeof(board));
2763 /* Does this get called once per lilo arg are what ? */
2764 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2765 num_cards, board_desc[board.type],
2766 board.numports, (int)board.port, (unsigned int) board.membase);
2770 enum epic_board_types {
2777 /* indexed directly by epic_board_types enum */
2779 unsigned char board_type;
2780 unsigned bar_idx; /* PCI base address region */
2781 } epca_info_tbl[] = {
2788 static int __devinit epca_init_one(struct pci_dev *pdev,
2789 const struct pci_device_id *ent)
2791 static int board_num = -1;
2792 int board_idx, info_idx = ent->driver_data;
2795 if (pci_enable_device(pdev))
2799 board_idx = board_num + num_cards;
2800 if (board_idx >= MAXBOARDS)
2803 addr = pci_resource_start(pdev, epca_info_tbl[info_idx].bar_idx);
2805 printk(KERN_ERR PFX "PCI region #%d not available (size 0)\n",
2806 epca_info_tbl[info_idx].bar_idx);
2810 boards[board_idx].status = ENABLED;
2811 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
2812 boards[board_idx].numports = 0x0;
2813 boards[board_idx].port = addr + PCI_IO_OFFSET;
2814 boards[board_idx].membase = addr;
2816 if (!request_mem_region(addr + PCI_IO_OFFSET, 0x200000, "epca")) {
2817 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2818 0x200000, addr + PCI_IO_OFFSET);
2822 boards[board_idx].re_map_port = ioremap_nocache(addr + PCI_IO_OFFSET,
2824 if (!boards[board_idx].re_map_port) {
2825 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2826 0x200000, addr + PCI_IO_OFFSET);
2827 goto err_out_free_pciio;
2830 if (!request_mem_region(addr, 0x200000, "epca")) {
2831 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2833 goto err_out_free_iounmap;
2836 boards[board_idx].re_map_membase = ioremap_nocache(addr, 0x200000);
2837 if (!boards[board_idx].re_map_membase) {
2838 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2839 0x200000, addr + PCI_IO_OFFSET);
2840 goto err_out_free_memregion;
2844 * I don't know what the below does, but the hardware guys say its
2845 * required on everything except PLX (In this case XRJ).
2847 if (info_idx != brd_xrj) {
2848 pci_write_config_byte(pdev, 0x40, 0);
2849 pci_write_config_byte(pdev, 0x46, 0);
2854 err_out_free_memregion:
2855 release_mem_region(addr, 0x200000);
2856 err_out_free_iounmap:
2857 iounmap(boards[board_idx].re_map_port);
2859 release_mem_region(addr + PCI_IO_OFFSET, 0x200000);
2865 static struct pci_device_id epca_pci_tbl[] = {
2866 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
2867 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
2868 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
2869 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
2873 MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
2875 static int __init init_PCI(void)
2877 memset(&epca_driver, 0, sizeof(epca_driver));
2878 epca_driver.name = "epca";
2879 epca_driver.id_table = epca_pci_tbl;
2880 epca_driver.probe = epca_init_one;
2882 return pci_register_driver(&epca_driver);
2885 MODULE_LICENSE("GPL");