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);
190 static int pc_write(struct tty_struct *, const unsigned char *, int);
191 static int pc_init(void);
192 static int init_PCI(void);
195 * Table of functions for each board to handle memory. Mantaining parallelism
196 * is a *very* good idea here. The idea is for the runtime code to blindly call
197 * these functions, not knowing/caring about the underlying hardware. This
198 * stuff should contain no conditionals; if more functionality is needed a
199 * different entry should be established. These calls are the interface calls
200 * and are the only functions that should be accessed. Anyone caught making
201 * direct calls deserves what they get.
203 static void memwinon(struct board_info *b, unsigned int win)
208 static void memwinoff(struct board_info *b, unsigned int win)
210 b->memwinoff(b, win);
213 static void globalwinon(struct channel *ch)
215 ch->board->globalwinon(ch);
218 static void rxwinon(struct channel *ch)
220 ch->board->rxwinon(ch);
223 static void txwinon(struct channel *ch)
225 ch->board->txwinon(ch);
228 static void memoff(struct channel *ch)
230 ch->board->memoff(ch);
232 static void assertgwinon(struct channel *ch)
234 ch->board->assertgwinon(ch);
237 static void assertmemoff(struct channel *ch)
239 ch->board->assertmemoff(ch);
242 /* PCXEM windowing is the same as that used in the PCXR and CX series cards. */
243 static void pcxem_memwinon(struct board_info *b, unsigned int win)
245 outb_p(FEPWIN | win, b->port + 1);
248 static void pcxem_memwinoff(struct board_info *b, unsigned int win)
250 outb_p(0, b->port + 1);
253 static void pcxem_globalwinon(struct channel *ch)
255 outb_p(FEPWIN, (int)ch->board->port + 1);
258 static void pcxem_rxwinon(struct channel *ch)
260 outb_p(ch->rxwin, (int)ch->board->port + 1);
263 static void pcxem_txwinon(struct channel *ch)
265 outb_p(ch->txwin, (int)ch->board->port + 1);
268 static void pcxem_memoff(struct channel *ch)
270 outb_p(0, (int)ch->board->port + 1);
273 /* ----------------- Begin pcxe memory window stuff ------------------ */
274 static void pcxe_memwinon(struct board_info *b, unsigned int win)
276 outb_p(FEPWIN | win, b->port + 1);
279 static void pcxe_memwinoff(struct board_info *b, unsigned int win)
281 outb_p(inb(b->port) & ~FEPMEM, b->port + 1);
282 outb_p(0, b->port + 1);
285 static void pcxe_globalwinon(struct channel *ch)
287 outb_p(FEPWIN, (int)ch->board->port + 1);
290 static void pcxe_rxwinon(struct channel *ch)
292 outb_p(ch->rxwin, (int)ch->board->port + 1);
295 static void pcxe_txwinon(struct channel *ch)
297 outb_p(ch->txwin, (int)ch->board->port + 1);
300 static void pcxe_memoff(struct channel *ch)
302 outb_p(0, (int)ch->board->port);
303 outb_p(0, (int)ch->board->port + 1);
306 /* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
307 static void pcxi_memwinon(struct board_info *b, unsigned int win)
309 outb_p(inb(b->port) | FEPMEM, b->port);
312 static void pcxi_memwinoff(struct board_info *b, unsigned int win)
314 outb_p(inb(b->port) & ~FEPMEM, b->port);
317 static void pcxi_globalwinon(struct channel *ch)
319 outb_p(FEPMEM, ch->board->port);
322 static void pcxi_rxwinon(struct channel *ch)
324 outb_p(FEPMEM, ch->board->port);
327 static void pcxi_txwinon(struct channel *ch)
329 outb_p(FEPMEM, ch->board->port);
332 static void pcxi_memoff(struct channel *ch)
334 outb_p(0, ch->board->port);
337 static void pcxi_assertgwinon(struct channel *ch)
339 epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
342 static void pcxi_assertmemoff(struct channel *ch)
344 epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
348 * Not all of the cards need specific memory windowing routines. Some cards
349 * (Such as PCI) needs no windowing routines at all. We provide these do
350 * nothing routines so that the same code base can be used. The driver will
351 * ALWAYS call a windowing routine if it thinks it needs to; regardless of the
352 * card. However, dependent on the card the routine may or may not do anything.
354 static void dummy_memwinon(struct board_info *b, unsigned int win)
358 static void dummy_memwinoff(struct board_info *b, unsigned int win)
362 static void dummy_globalwinon(struct channel *ch)
366 static void dummy_rxwinon(struct channel *ch)
370 static void dummy_txwinon(struct channel *ch)
374 static void dummy_memoff(struct channel *ch)
378 static void dummy_assertgwinon(struct channel *ch)
382 static void dummy_assertmemoff(struct channel *ch)
386 static struct channel *verifyChannel(struct tty_struct *tty)
389 * This routine basically provides a sanity check. It insures that the
390 * channel returned is within the proper range of addresses as well as
391 * properly initialized. If some bogus info gets passed in
392 * through tty->driver_data this should catch it.
395 struct channel *ch = (struct channel *)tty->driver_data;
396 if (ch >= &digi_channels[0] && ch < &digi_channels[nbdevs]) {
397 if (ch->magic == EPCA_MAGIC)
404 static void pc_sched_event(struct channel *ch, int event)
407 * We call this to schedule interrupt processing on some event. The
408 * kernel sees our request and calls the related routine in OUR driver.
410 ch->event |= 1 << event;
411 schedule_work(&ch->tqueue);
414 static void epca_error(int line, char *msg)
416 printk(KERN_ERR "epca_error (Digi): line = %d %s\n", line, msg);
419 static void pc_close(struct tty_struct *tty, struct file *filp)
424 * verifyChannel returns the channel from the tty struct if it is
425 * valid. This serves as a sanity check.
427 ch = verifyChannel(tty);
429 spin_lock_irqsave(&epca_lock, flags);
430 if (tty_hung_up_p(filp)) {
431 spin_unlock_irqrestore(&epca_lock, flags);
434 if (ch->port.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);
443 /* Port open only once go ahead with shutdown & reset */
444 BUG_ON(ch->port.count < 0);
447 * Let the rest of the driver know the channel is being closed.
448 * This becomes important if an open is attempted before close
451 ch->port.flags |= ASYNC_CLOSING;
454 spin_unlock_irqrestore(&epca_lock, flags);
456 if (ch->port.flags & ASYNC_INITIALIZED) {
457 /* Setup an event to indicate when the
458 transmit buffer empties */
459 setup_empty_event(tty, ch);
460 /* 30 seconds timeout */
461 tty_wait_until_sent(tty, 3000);
463 pc_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->port.blocked_open) {
476 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
477 wake_up_interruptible(&ch->port.open_wait);
479 ch->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
481 wake_up_interruptible(&ch->port.close_wait);
485 static void shutdown(struct channel *ch)
488 struct tty_struct *tty;
489 struct board_chan __iomem *bc;
491 if (!(ch->port.flags & 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->port.flags &= ~ASYNC_INITIALIZED;
521 spin_unlock_irqrestore(&epca_lock, flags);
524 static void pc_hangup(struct tty_struct *tty)
528 * verifyChannel returns the channel from the tty struct if it is
529 * valid. This serves as a sanity check.
531 ch = verifyChannel(tty);
535 pc_flush_buffer(tty);
536 tty_ldisc_flush(tty);
539 spin_lock_irqsave(&epca_lock, flags);
543 ch->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
544 spin_unlock_irqrestore(&epca_lock, flags);
545 wake_up_interruptible(&ch->port.open_wait);
549 static int pc_write(struct tty_struct *tty,
550 const unsigned char *buf, int bytesAvailable)
552 unsigned int head, tail;
559 struct board_chan __iomem *bc;
562 * pc_write is primarily called directly by the kernel routine
563 * tty_write (Though it can also be called by put_char) found in
564 * tty_io.c. pc_write is passed a line discipline buffer where the data
565 * to be written out is stored. The line discipline implementation
566 * itself is done at the kernel level and is not brought into the
571 * verifyChannel returns the channel from the tty struct if it is
572 * valid. This serves as a sanity check.
574 ch = verifyChannel(tty);
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 int pc_write_room(struct tty_struct *tty)
653 unsigned int head, tail;
654 struct board_chan __iomem *bc;
656 * verifyChannel returns the channel from the tty struct if it is
657 * valid. This serves as a sanity check.
659 ch = verifyChannel(tty);
661 spin_lock_irqsave(&epca_lock, flags);
665 head = readw(&bc->tin) & (ch->txbufsize - 1);
666 tail = readw(&bc->tout);
668 if (tail != readw(&bc->tout))
669 tail = readw(&bc->tout);
670 /* Wrap tail if necessary */
671 tail &= (ch->txbufsize - 1);
672 remain = tail - head - 1;
674 remain += ch->txbufsize;
676 if (remain && (ch->statusflags & LOWWAIT) == 0) {
677 ch->statusflags |= LOWWAIT;
678 writeb(1, &bc->ilow);
681 spin_unlock_irqrestore(&epca_lock, flags);
683 /* Return how much room is left on card */
687 static int pc_chars_in_buffer(struct tty_struct *tty)
690 unsigned int ctail, head, tail;
694 struct board_chan __iomem *bc;
696 * verifyChannel returns the channel from the tty struct if it is
697 * valid. This serves as a sanity check.
699 ch = verifyChannel(tty);
703 spin_lock_irqsave(&epca_lock, flags);
707 tail = readw(&bc->tout);
708 head = readw(&bc->tin);
709 ctail = readw(&ch->mailbox->cout);
711 if (tail == head && readw(&ch->mailbox->cin) == ctail &&
712 readb(&bc->tbusy) == 0)
714 else { /* Begin if some space on the card has been used */
715 head = readw(&bc->tin) & (ch->txbufsize - 1);
716 tail &= (ch->txbufsize - 1);
718 * The logic here is basically opposite of the above
719 * pc_write_room here we are finding the amount of bytes in the
720 * buffer filled. Not the amount of bytes empty.
722 remain = tail - head - 1;
724 remain += ch->txbufsize;
725 chars = (int)(ch->txbufsize - remain);
727 * Make it possible to wakeup anything waiting for output in
730 * If not already set. Setup an event to indicate when the
731 * transmit buffer empties.
733 if (!(ch->statusflags & EMPTYWAIT))
734 setup_empty_event(tty, ch);
735 } /* End if some space on the card has been used */
737 spin_unlock_irqrestore(&epca_lock, flags);
738 /* Return number of characters residing on card. */
742 static void pc_flush_buffer(struct tty_struct *tty)
747 struct board_chan __iomem *bc;
749 * verifyChannel returns the channel from the tty struct if it is
750 * valid. This serves as a sanity check.
752 ch = verifyChannel(tty);
756 spin_lock_irqsave(&epca_lock, flags);
759 tail = readw(&bc->tout);
760 /* Have FEP move tout pointer; effectively flushing transmit buffer */
761 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
763 spin_unlock_irqrestore(&epca_lock, flags);
767 static void pc_flush_chars(struct tty_struct *tty)
771 * verifyChannel returns the channel from the tty struct if it is
772 * valid. This serves as a sanity check.
774 ch = verifyChannel(tty);
777 spin_lock_irqsave(&epca_lock, flags);
779 * If not already set and the transmitter is busy setup an
780 * event to indicate when the transmit empties.
782 if ((ch->statusflags & TXBUSY) &&
783 !(ch->statusflags & EMPTYWAIT))
784 setup_empty_event(tty, ch);
785 spin_unlock_irqrestore(&epca_lock, flags);
789 static int block_til_ready(struct tty_struct *tty,
790 struct file *filp, struct channel *ch)
792 DECLARE_WAITQUEUE(wait, current);
793 int retval, do_clocal = 0;
796 if (tty_hung_up_p(filp)) {
797 if (ch->port.flags & ASYNC_HUP_NOTIFY)
800 retval = -ERESTARTSYS;
805 * If the device is in the middle of being closed, then block until
806 * it's done, and then try again.
808 if (ch->port.flags & ASYNC_CLOSING) {
809 interruptible_sleep_on(&ch->port.close_wait);
811 if (ch->port.flags & ASYNC_HUP_NOTIFY)
817 if (filp->f_flags & O_NONBLOCK) {
819 * If non-blocking mode is set, then make the check up front
822 ch->port.flags |= ASYNC_NORMAL_ACTIVE;
825 if (tty->termios->c_cflag & CLOCAL)
827 /* Block waiting for the carrier detect and the line to become free */
830 add_wait_queue(&ch->port.open_wait, &wait);
832 spin_lock_irqsave(&epca_lock, flags);
833 /* We dec count so that pc_close will know when to free things */
834 if (!tty_hung_up_p(filp))
836 ch->port.blocked_open++;
838 set_current_state(TASK_INTERRUPTIBLE);
839 if (tty_hung_up_p(filp) ||
840 !(ch->port.flags & ASYNC_INITIALIZED)) {
841 if (ch->port.flags & ASYNC_HUP_NOTIFY)
844 retval = -ERESTARTSYS;
847 if (!(ch->port.flags & ASYNC_CLOSING) &&
848 (do_clocal || (ch->imodem & ch->dcd)))
850 if (signal_pending(current)) {
851 retval = -ERESTARTSYS;
854 spin_unlock_irqrestore(&epca_lock, flags);
856 * Allow someone else to be scheduled. We will occasionally go
857 * through this loop until one of the above conditions change.
858 * The below schedule call will allow other processes to enter
859 * and prevent this loop from hogging the cpu.
862 spin_lock_irqsave(&epca_lock, flags);
865 __set_current_state(TASK_RUNNING);
866 remove_wait_queue(&ch->port.open_wait, &wait);
867 if (!tty_hung_up_p(filp))
869 ch->port.blocked_open--;
871 spin_unlock_irqrestore(&epca_lock, flags);
876 ch->port.flags |= ASYNC_NORMAL_ACTIVE;
880 static int pc_open(struct tty_struct *tty, struct file *filp)
884 int line, retval, boardnum;
885 struct board_chan __iomem *bc;
889 if (line < 0 || line >= nbdevs)
892 ch = &digi_channels[line];
893 boardnum = ch->boardnum;
895 /* Check status of board configured in system. */
898 * I check to see if the epca_setup routine detected an user error. It
899 * might be better to put this in pc_init, but for the moment it goes
902 if (invalid_lilo_config) {
903 if (setup_error_code & INVALID_BOARD_TYPE)
904 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
905 if (setup_error_code & INVALID_NUM_PORTS)
906 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
907 if (setup_error_code & INVALID_MEM_BASE)
908 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
909 if (setup_error_code & INVALID_PORT_BASE)
910 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
911 if (setup_error_code & INVALID_BOARD_STATUS)
912 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
913 if (setup_error_code & INVALID_ALTPIN)
914 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
915 tty->driver_data = NULL; /* Mark this device as 'down' */
918 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
919 tty->driver_data = NULL; /* Mark this device as 'down' */
925 tty->driver_data = NULL;
929 spin_lock_irqsave(&epca_lock, flags);
931 * Every time a channel is opened, increment a counter. This is
932 * necessary because we do not wish to flush and shutdown the channel
933 * until the last app holding the channel open, closes it.
937 * Set a kernel structures pointer to our local channel structure. This
938 * way we can get to it when passed only a tty struct.
940 tty->driver_data = ch;
942 * If this is the first time the channel has been opened, initialize
943 * the tty->termios struct otherwise let pc_close handle it.
948 /* Save boards current modem status */
949 ch->imodem = readb(&bc->mstat);
952 * Set receive head and tail ptrs to each other. This indicates no data
955 head = readw(&bc->rin);
956 writew(head, &bc->rout);
958 /* Set the channels associated tty structure */
962 * The below routine generally sets up parity, baud, flow control
963 * issues, etc.... It effect both control flags and input flags.
966 ch->port.flags |= ASYNC_INITIALIZED;
968 spin_unlock_irqrestore(&epca_lock, flags);
970 retval = block_til_ready(tty, filp, ch);
974 * Set this again in case a hangup set it to zero while this open() was
975 * waiting for the line...
977 spin_lock_irqsave(&epca_lock, flags);
980 /* Enable Digi Data events */
981 writeb(1, &bc->idata);
983 spin_unlock_irqrestore(&epca_lock, flags);
987 static int __init epca_module_init(void)
991 module_init(epca_module_init);
993 static struct pci_driver epca_driver;
995 static void __exit epca_module_exit(void)
998 struct board_info *bd;
1001 del_timer_sync(&epca_timer);
1003 if (tty_unregister_driver(pc_driver) ||
1004 tty_unregister_driver(pc_info)) {
1005 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
1008 put_tty_driver(pc_driver);
1009 put_tty_driver(pc_info);
1011 for (crd = 0; crd < num_cards; crd++) {
1013 if (!bd) { /* sanity check */
1014 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1018 for (count = 0; count < bd->numports; count++, ch++) {
1019 if (ch && ch->port.tty)
1020 tty_hangup(ch->port.tty);
1023 pci_unregister_driver(&epca_driver);
1025 module_exit(epca_module_exit);
1027 static const struct tty_operations pc_ops = {
1031 .write_room = pc_write_room,
1032 .flush_buffer = pc_flush_buffer,
1033 .chars_in_buffer = pc_chars_in_buffer,
1034 .flush_chars = pc_flush_chars,
1036 .set_termios = pc_set_termios,
1039 .throttle = pc_throttle,
1040 .unthrottle = pc_unthrottle,
1041 .hangup = pc_hangup,
1042 .break_ctl = pc_send_break
1045 static int info_open(struct tty_struct *tty, struct file *filp)
1050 static struct tty_operations info_ops = {
1052 .ioctl = info_ioctl,
1055 static int __init pc_init(void)
1058 struct board_info *bd;
1059 unsigned char board_id = 0;
1062 int pci_boards_found, pci_count;
1066 pc_driver = alloc_tty_driver(MAX_ALLOC);
1070 pc_info = alloc_tty_driver(MAX_ALLOC);
1075 * If epca_setup has not been ran by LILO set num_cards to defaults;
1076 * copy board structure defined by digiConfig into drivers board
1077 * structure. Note : If LILO has ran epca_setup then epca_setup will
1078 * handle defining num_cards as well as copying the data into the board
1082 /* driver has been configured via. epcaconfig */
1084 num_cards = NUMCARDS;
1085 memcpy(&boards, &static_boards,
1086 sizeof(struct board_info) * NUMCARDS);
1090 * Note : If lilo was used to configure the driver and the ignore
1091 * epcaconfig option was choosen (digiepca=2) then nbdevs and num_cards
1092 * will equal 0 at this point. This is okay; PCI cards will still be
1093 * picked up if detected.
1097 * Set up interrupt, we will worry about memory allocation in
1100 printk(KERN_INFO "DIGI epca driver version %s loaded.\n", VERSION);
1103 * NOTE : This code assumes that the number of ports found in the
1104 * boards array is correct. This could be wrong if the card in question
1105 * is PCI (And therefore has no ports entry in the boards structure.)
1106 * The rest of the information will be valid for PCI because the
1107 * beginning of pc_init scans for PCI and determines i/o and base
1108 * memory addresses. I am not sure if it is possible to read the number
1109 * of ports supported by the card prior to it being booted (Since that
1110 * is the state it is in when pc_init is run). Because it is not
1111 * possible to query the number of supported ports until after the card
1112 * has booted; we are required to calculate the card_ptrs as the card
1113 * is initialized (Inside post_fep_init). The negative thing about this
1114 * approach is that digiDload's call to GET_INFO will have a bad port
1115 * value. (Since this is called prior to post_fep_init.)
1117 pci_boards_found = 0;
1118 if (num_cards < MAXBOARDS)
1119 pci_boards_found += init_PCI();
1120 num_cards += pci_boards_found;
1122 pc_driver->owner = THIS_MODULE;
1123 pc_driver->name = "ttyD";
1124 pc_driver->major = DIGI_MAJOR;
1125 pc_driver->minor_start = 0;
1126 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1127 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1128 pc_driver->init_termios = tty_std_termios;
1129 pc_driver->init_termios.c_iflag = 0;
1130 pc_driver->init_termios.c_oflag = 0;
1131 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1132 pc_driver->init_termios.c_lflag = 0;
1133 pc_driver->init_termios.c_ispeed = 9600;
1134 pc_driver->init_termios.c_ospeed = 9600;
1135 pc_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK;
1136 tty_set_operations(pc_driver, &pc_ops);
1138 pc_info->owner = THIS_MODULE;
1139 pc_info->name = "digi_ctl";
1140 pc_info->major = DIGIINFOMAJOR;
1141 pc_info->minor_start = 0;
1142 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1143 pc_info->subtype = SERIAL_TYPE_INFO;
1144 pc_info->init_termios = tty_std_termios;
1145 pc_info->init_termios.c_iflag = 0;
1146 pc_info->init_termios.c_oflag = 0;
1147 pc_info->init_termios.c_lflag = 0;
1148 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1149 pc_info->init_termios.c_ispeed = 9600;
1150 pc_info->init_termios.c_ospeed = 9600;
1151 pc_info->flags = TTY_DRIVER_REAL_RAW;
1152 tty_set_operations(pc_info, &info_ops);
1155 for (crd = 0; crd < num_cards; crd++) {
1157 * This is where the appropriate memory handlers for the
1158 * hardware is set. Everything at runtime blindly jumps through
1162 /* defined in epcaconfig.h */
1168 bd->memwinon = pcxem_memwinon;
1169 bd->memwinoff = pcxem_memwinoff;
1170 bd->globalwinon = pcxem_globalwinon;
1171 bd->txwinon = pcxem_txwinon;
1172 bd->rxwinon = pcxem_rxwinon;
1173 bd->memoff = pcxem_memoff;
1174 bd->assertgwinon = dummy_assertgwinon;
1175 bd->assertmemoff = dummy_assertmemoff;
1181 bd->memwinon = dummy_memwinon;
1182 bd->memwinoff = dummy_memwinoff;
1183 bd->globalwinon = dummy_globalwinon;
1184 bd->txwinon = dummy_txwinon;
1185 bd->rxwinon = dummy_rxwinon;
1186 bd->memoff = dummy_memoff;
1187 bd->assertgwinon = dummy_assertgwinon;
1188 bd->assertmemoff = dummy_assertmemoff;
1193 bd->memwinon = pcxe_memwinon;
1194 bd->memwinoff = pcxe_memwinoff;
1195 bd->globalwinon = pcxe_globalwinon;
1196 bd->txwinon = pcxe_txwinon;
1197 bd->rxwinon = pcxe_rxwinon;
1198 bd->memoff = pcxe_memoff;
1199 bd->assertgwinon = dummy_assertgwinon;
1200 bd->assertmemoff = dummy_assertmemoff;
1205 bd->memwinon = pcxi_memwinon;
1206 bd->memwinoff = pcxi_memwinoff;
1207 bd->globalwinon = pcxi_globalwinon;
1208 bd->txwinon = pcxi_txwinon;
1209 bd->rxwinon = pcxi_rxwinon;
1210 bd->memoff = pcxi_memoff;
1211 bd->assertgwinon = pcxi_assertgwinon;
1212 bd->assertmemoff = pcxi_assertmemoff;
1220 * Some cards need a memory segment to be defined for use in
1221 * transmit and receive windowing operations. These boards are
1222 * listed in the below switch. In the case of the XI the amount
1223 * of memory on the board is variable so the memory_seg is also
1224 * variable. This code determines what they segment should be.
1230 bd->memory_seg = 0xf000;
1234 board_id = inb((int)bd->port);
1235 if ((board_id & 0x1) == 0x1) {
1236 /* it's an XI card */
1237 /* Is it a 64K board */
1238 if ((board_id & 0x30) == 0)
1239 bd->memory_seg = 0xf000;
1241 /* Is it a 128K board */
1242 if ((board_id & 0x30) == 0x10)
1243 bd->memory_seg = 0xe000;
1245 /* Is is a 256K board */
1246 if ((board_id & 0x30) == 0x20)
1247 bd->memory_seg = 0xc000;
1249 /* Is it a 512K board */
1250 if ((board_id & 0x30) == 0x30)
1251 bd->memory_seg = 0x8000;
1253 printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n", (int)bd->port);
1258 err = tty_register_driver(pc_driver);
1260 printk(KERN_ERR "Couldn't register Digi PC/ driver");
1264 err = tty_register_driver(pc_info);
1266 printk(KERN_ERR "Couldn't register Digi PC/ info ");
1270 /* Start up the poller to check for events on all enabled boards */
1271 init_timer(&epca_timer);
1272 epca_timer.function = epcapoll;
1273 mod_timer(&epca_timer, jiffies + HZ/25);
1277 tty_unregister_driver(pc_driver);
1279 put_tty_driver(pc_info);
1281 put_tty_driver(pc_driver);
1286 static void post_fep_init(unsigned int crd)
1289 void __iomem *memaddr;
1290 struct global_data __iomem *gd;
1291 struct board_info *bd;
1292 struct board_chan __iomem *bc;
1294 int shrinkmem = 0, lowwater;
1297 * This call is made by the user via. the ioctl call DIGI_INIT. It is
1298 * responsible for setting up all the card specific stuff.
1303 * If this is a PCI board, get the port info. Remember PCI cards do not
1304 * have entries into the epcaconfig.h file, so we can't get the number
1305 * of ports from it. Unfortunetly, this means that anyone doing a
1306 * DIGI_GETINFO before the board has booted will get an invalid number
1307 * of ports returned (It should return 0). Calls to DIGI_GETINFO after
1308 * DIGI_INIT has been called will return the proper values.
1310 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
1312 * Below we use XEMPORTS as a memory offset regardless of which
1313 * PCI card it is. This is because all of the supported PCI
1314 * cards have the same memory offset for the channel data. This
1315 * will have to be changed if we ever develop a PCI/XE card.
1316 * NOTE : The FEP manual states that the port offset is 0xC22
1317 * as opposed to 0xC02. This is only true for PC/XE, and PC/XI
1318 * cards; not for the XEM, or CX series. On the PCI cards the
1319 * number of ports is determined by reading a ID PROM located
1320 * in the box attached to the card. The card can then determine
1321 * the index the id to determine the number of ports available.
1322 * (FYI - The id should be located at 0x1ac (And may use up to
1323 * 4 bytes if the box in question is a XEM or CX)).
1325 /* PCI cards are already remapped at this point ISA are not */
1326 bd->numports = readw(bd->re_map_membase + XEMPORTS);
1327 epcaassert(bd->numports <= 64, "PCI returned a invalid number of ports");
1328 nbdevs += (bd->numports);
1330 /* Fix up the mappings for ISA/EISA etc */
1331 /* FIXME: 64K - can we be smarter ? */
1332 bd->re_map_membase = ioremap_nocache(bd->membase, 0x10000);
1336 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1338 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1341 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1343 memaddr = bd->re_map_membase;
1346 * The below assignment will set bc to point at the BEGINING of the
1347 * cards channel structures. For 1 card there will be between 8 and 64
1348 * of these structures.
1350 bc = memaddr + CHANSTRUCT;
1353 * The below assignment will set gd to point at the BEGINING of global
1354 * memory address 0xc00. The first data in that global memory actually
1355 * starts at address 0xc1a. The command in pointer begins at 0xd10.
1357 gd = memaddr + GLOBAL;
1360 * XEPORTS (address 0xc22) points at the number of channels the card
1361 * supports. (For 64XE, XI, XEM, and XR use 0xc02)
1363 if ((bd->type == PCXEVE || bd->type == PCXE) &&
1364 (readw(memaddr + XEPORTS) < 3))
1366 if (bd->type < PCIXEM)
1367 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1372 * Remember ch is the main drivers channels structure, while bc is the
1373 * cards channel structure.
1375 for (i = 0; i < bd->numports; i++, ch++, bc++) {
1376 unsigned long flags;
1381 INIT_WORK(&ch->tqueue, do_softint);
1382 ch->board = &boards[crd];
1384 spin_lock_irqsave(&epca_lock, flags);
1387 * Since some of the boards use different bitmaps for
1388 * their control signals we cannot hard code these
1389 * values and retain portability. We virtualize this
1418 if (boards[crd].altpin) {
1419 ch->dsr = ch->m_dcd;
1420 ch->dcd = ch->m_dsr;
1421 ch->digiext.digi_flags |= DIGI_ALTPIN;
1423 ch->dcd = ch->m_dcd;
1424 ch->dsr = ch->m_dsr;
1429 ch->magic = EPCA_MAGIC;
1430 ch->port.tty = NULL;
1433 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1437 tseg = readw(&bc->tseg);
1438 rseg = readw(&bc->rseg);
1444 /* Cover all the 2MEG cards */
1445 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1446 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1447 ch->txwin = FEPWIN | (tseg >> 11);
1448 ch->rxwin = FEPWIN | (rseg >> 11);
1453 /* Cover all the 32K windowed cards */
1454 /* Mask equal to window size - 1 */
1455 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1456 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1457 ch->txwin = FEPWIN | (tseg >> 11);
1458 ch->rxwin = FEPWIN | (rseg >> 11);
1463 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4)
1465 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1466 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4)
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->port.blocked_open = 0;
1515 init_waitqueue_head(&ch->port.open_wait);
1516 init_waitqueue_head(&ch->port.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,
1524 (long)bd->membase, bd->numports);
1528 static void epcapoll(unsigned long ignored)
1530 unsigned long flags;
1532 unsigned int head, tail;
1534 struct board_info *bd;
1537 * This routine is called upon every timer interrupt. Even though the
1538 * Digi series cards are capable of generating interrupts this method
1539 * of non-looping polling is more efficient. This routine checks for
1540 * card generated events (Such as receive data, are transmit buffer
1541 * empty) and acts on those events.
1543 for (crd = 0; crd < num_cards; crd++) {
1547 if ((bd->status == DISABLED) || digi_poller_inhibited)
1551 * assertmemoff is not needed here; indeed it is an empty
1552 * subroutine. It is being kept because future boards may need
1553 * this as well as some legacy boards.
1555 spin_lock_irqsave(&epca_lock, flags);
1562 * In this case head and tail actually refer to the event queue
1563 * not the transmit or receive queue.
1565 head = readw(&ch->mailbox->ein);
1566 tail = readw(&ch->mailbox->eout);
1568 /* If head isn't equal to tail we have an event */
1573 spin_unlock_irqrestore(&epca_lock, flags);
1574 } /* End for each card */
1575 mod_timer(&epca_timer, jiffies + (HZ / 25));
1578 static void doevent(int crd)
1580 void __iomem *eventbuf;
1581 struct channel *ch, *chan0;
1582 static struct tty_struct *tty;
1583 struct board_info *bd;
1584 struct board_chan __iomem *bc;
1585 unsigned int tail, head;
1590 * This subroutine is called by epcapoll when an event is detected
1591 * in the event queue. This routine responds to those events.
1595 chan0 = card_ptr[crd];
1596 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
1597 assertgwinon(chan0);
1598 while ((tail = readw(&chan0->mailbox->eout)) !=
1599 (head = readw(&chan0->mailbox->ein))) {
1600 /* Begin while something in event queue */
1601 assertgwinon(chan0);
1602 eventbuf = bd->re_map_membase + tail + ISTART;
1603 /* Get the channel the event occurred on */
1604 channel = readb(eventbuf);
1605 /* Get the actual event code that occurred */
1606 event = readb(eventbuf + 1);
1608 * The two assignments below get the current modem status
1609 * (mstat) and the previous modem status (lstat). These are
1610 * useful becuase an event could signal a change in modem
1613 mstat = readb(eventbuf + 2);
1614 lstat = readb(eventbuf + 3);
1616 ch = chan0 + channel;
1617 if ((unsigned)channel >= bd->numports || !ch) {
1618 if (channel >= bd->numports)
1628 if (event & DATA_IND) { /* Begin DATA_IND */
1631 } /* End DATA_IND */
1632 /* else *//* Fix for DCD transition missed bug */
1633 if (event & MODEMCHG_IND) {
1634 /* A modem signal change has been indicated */
1636 if (ch->port.flags & ASYNC_CHECK_CD) {
1637 /* We are now receiving dcd */
1638 if (mstat & ch->dcd)
1639 wake_up_interruptible(&ch->port.open_wait);
1640 else /* No dcd; hangup */
1641 pc_sched_event(ch, EPCA_EVENT_HANGUP);
1646 if (event & BREAK_IND) {
1647 /* A break has been indicated */
1648 tty_insert_flip_char(tty, 0, TTY_BREAK);
1649 tty_schedule_flip(tty);
1650 } else if (event & LOWTX_IND) {
1651 if (ch->statusflags & LOWWAIT) {
1652 ch->statusflags &= ~LOWWAIT;
1655 } else if (event & EMPTYTX_IND) {
1656 /* This event is generated by
1657 setup_empty_event */
1658 ch->statusflags &= ~TXBUSY;
1659 if (ch->statusflags & EMPTYWAIT) {
1660 ch->statusflags &= ~EMPTYWAIT;
1668 writew(1, &bc->idata);
1669 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
1671 } /* End while something in event queue */
1674 static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1675 int byte2, int ncmds, int bytecmd)
1677 unchar __iomem *memaddr;
1678 unsigned int head, cmdTail, cmdStart, cmdMax;
1682 /* This is the routine in which commands may be passed to the card. */
1684 if (ch->board->status == DISABLED)
1687 /* Remember head (As well as max) is just an offset not a base addr */
1688 head = readw(&ch->mailbox->cin);
1689 /* cmdStart is a base address */
1690 cmdStart = readw(&ch->mailbox->cstart);
1692 * We do the addition below because we do not want a max pointer
1693 * relative to cmdStart. We want a max pointer that points at the
1694 * physical end of the command queue.
1696 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
1697 memaddr = ch->board->re_map_membase;
1699 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1700 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n",
1701 __LINE__, cmd, head);
1702 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n",
1703 __LINE__, cmdMax, cmdStart);
1707 writeb(cmd, memaddr + head + cmdStart + 0);
1708 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1709 /* Below word_or_byte is bits to set */
1710 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1711 /* Below byte2 is bits to reset */
1712 writeb(byte2, memaddr + head + cmdStart + 3);
1714 writeb(cmd, memaddr + head + cmdStart + 0);
1715 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1716 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1718 head = (head + 4) & (cmdMax - cmdStart - 4);
1719 writew(head, &ch->mailbox->cin);
1725 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1728 head = readw(&ch->mailbox->cin);
1729 cmdTail = readw(&ch->mailbox->cout);
1730 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
1732 * Basically this will break when the FEP acknowledges the
1733 * command by incrementing cmdTail (Making it equal to head).
1735 if (n <= ncmds * (sizeof(short) * 4))
1741 * Digi products use fields in their channels structures that are very similar
1742 * to the c_cflag and c_iflag fields typically found in UNIX termios
1743 * structures. The below three routines allow mappings between these hardware
1744 * "flags" and their respective Linux flags.
1746 static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
1750 if (cflag & CRTSCTS) {
1751 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1752 res |= ((ch->m_cts) | (ch->m_rts));
1755 if (ch->digiext.digi_flags & RTSPACE)
1758 if (ch->digiext.digi_flags & DTRPACE)
1761 if (ch->digiext.digi_flags & CTSPACE)
1764 if (ch->digiext.digi_flags & DSRPACE)
1767 if (ch->digiext.digi_flags & DCDPACE)
1770 if (res & (ch->m_rts))
1771 ch->digiext.digi_flags |= RTSPACE;
1773 if (res & (ch->m_cts))
1774 ch->digiext.digi_flags |= CTSPACE;
1779 static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
1781 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
1782 INPCK | ISTRIP | IXON | IXANY | IXOFF);
1783 if (ch->digiext.digi_flags & DIGI_AIXON)
1788 static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
1791 if (cflag & CBAUDEX) {
1792 ch->digiext.digi_flags |= DIGI_FAST;
1794 * HUPCL bit is used by FEP to indicate fast baud table is to
1799 ch->digiext.digi_flags &= ~DIGI_FAST;
1801 * CBAUD has bit position 0x1000 set these days to indicate Linux
1802 * baud rate remap. Digi hardware can't handle the bit assignment.
1803 * (We use a different bit assignment for high speed.). Clear this
1806 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
1808 * This gets a little confusing. The Digi cards have their own
1809 * representation of c_cflags controlling baud rate. For the most part
1810 * this is identical to the Linux implementation. However; Digi
1811 * supports one rate (76800) that Linux doesn't. This means that the
1812 * c_cflag entry that would normally mean 76800 for Digi actually means
1813 * 115200 under Linux. Without the below mapping, a stty 115200 would
1814 * only drive the board at 76800. Since the rate 230400 is also found
1815 * after 76800, the same problem afflicts us when we choose a rate of
1816 * 230400. Without the below modificiation stty 230400 would actually
1819 * There are two additional differences. The Linux value for CLOCAL
1820 * (0x800; 0004000) has no meaning to the Digi hardware. Also in later
1821 * releases of Linux; the CBAUD define has CBAUDEX (0x1000; 0010000)
1822 * ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX should be
1823 * checked for a screened out prior to termios2digi_c returning. Since
1824 * CLOCAL isn't used by the board this can be ignored as long as the
1825 * returned value is used only by Digi hardware.
1827 if (cflag & CBAUDEX) {
1829 * The below code is trying to guarantee that only baud rates
1830 * 115200 and 230400 are remapped. We use exclusive or because
1831 * the various baud rates share common bit positions and
1832 * therefore can't be tested for easily.
1834 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
1835 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
1841 /* Caller must hold the locks */
1842 static void epcaparam(struct tty_struct *tty, struct channel *ch)
1844 unsigned int cmdHead;
1845 struct ktermios *ts;
1846 struct board_chan __iomem *bc;
1847 unsigned mval, hflow, cflag, iflag;
1850 epcaassert(bc != NULL, "bc out of range");
1854 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
1855 cmdHead = readw(&bc->rin);
1856 writew(cmdHead, &bc->rout);
1857 cmdHead = readw(&bc->tin);
1858 /* Changing baud in mid-stream transmission can be wonderful */
1860 * Flush current transmit buffer by setting cmdTail pointer
1861 * (tout) to cmdHead pointer (tin). Hopefully the transmit
1864 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
1866 } else { /* Begin CBAUD not detected */
1868 * c_cflags have changed but that change had nothing to do with
1869 * BAUD. Propagate the change to the card.
1871 cflag = termios2digi_c(ch, ts->c_cflag);
1872 if (cflag != ch->fepcflag) {
1873 ch->fepcflag = cflag;
1874 /* Set baud rate, char size, stop bits, parity */
1875 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
1878 * If the user has not forced CLOCAL and if the device is not a
1879 * CALLOUT device (Which is always CLOCAL) we set flags such
1880 * that the driver will wait on carrier detect.
1882 if (ts->c_cflag & CLOCAL)
1883 ch->port.flags &= ~ASYNC_CHECK_CD;
1885 ch->port.flags |= ASYNC_CHECK_CD;
1886 mval = ch->m_dtr | ch->m_rts;
1887 } /* End CBAUD not detected */
1888 iflag = termios2digi_i(ch, ts->c_iflag);
1889 /* Check input mode flags */
1890 if (iflag != ch->fepiflag) {
1891 ch->fepiflag = iflag;
1893 * Command sets channels iflag structure on the board. Such
1894 * things as input soft flow control, handling of parity
1895 * errors, and break handling are all set here.
1897 * break handling, parity handling, input stripping,
1898 * flow control chars
1900 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
1903 * Set the board mint value for this channel. This will cause hardware
1904 * events to be generated each time the DCD signal (Described in mint)
1907 writeb(ch->dcd, &bc->mint);
1908 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
1909 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
1910 writeb(0, &bc->mint);
1911 ch->imodem = readb(&bc->mstat);
1912 hflow = termios2digi_h(ch, ts->c_cflag);
1913 if (hflow != ch->hflow) {
1916 * Hard flow control has been selected but the board is not
1917 * using it. Activate hard flow control now.
1919 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
1921 mval ^= ch->modemfake & (mval ^ ch->modem);
1923 if (ch->omodem ^ mval) {
1926 * The below command sets the DTR and RTS mstat structure. If
1927 * hard flow control is NOT active these changes will drive the
1928 * output of the actual DTR and RTS lines. If hard flow control
1929 * is active, the changes will be saved in the mstat structure
1930 * and only asserted when hard flow control is turned off.
1933 /* First reset DTR & RTS; then set them */
1934 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
1935 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
1937 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
1938 ch->fepstartc = ch->startc;
1939 ch->fepstopc = ch->stopc;
1941 * The XON / XOFF characters have changed; propagate these
1942 * changes to the card.
1944 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
1946 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
1947 ch->fepstartca = ch->startca;
1948 ch->fepstopca = ch->stopca;
1950 * Similar to the above, this time the auxilarly XON / XOFF
1951 * characters have changed; propagate these changes to the card.
1953 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
1957 /* Caller holds lock */
1958 static void receive_data(struct channel *ch)
1961 struct ktermios *ts = NULL;
1962 struct tty_struct *tty;
1963 struct board_chan __iomem *bc;
1964 int dataToRead, wrapgap, bytesAvailable;
1965 unsigned int tail, head;
1966 unsigned int wrapmask;
1969 * This routine is called by doint when a receive data event has taken
1973 if (ch->statusflags & RXSTOPPED)
1980 wrapmask = ch->rxbufsize - 1;
1983 * Get the head and tail pointers to the receiver queue. Wrap the head
1984 * pointer if it has reached the end of the buffer.
1986 head = readw(&bc->rin);
1988 tail = readw(&bc->rout) & wrapmask;
1990 bytesAvailable = (head - tail) & wrapmask;
1991 if (bytesAvailable == 0)
1994 /* If CREAD bit is off or device not open, set TX tail to head */
1995 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
1996 writew(head, &bc->rout);
2000 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
2003 if (readb(&bc->orun)) {
2004 writeb(0, &bc->orun);
2005 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",
2007 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
2010 while (bytesAvailable > 0) {
2011 /* Begin while there is data on the card */
2012 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
2014 * Even if head has wrapped around only report the amount of
2015 * data to be equal to the size - tail. Remember memcpy can't
2016 * automaticly wrap around the receive buffer.
2018 dataToRead = (wrapgap < bytesAvailable) ? wrapgap
2020 /* Make sure we don't overflow the buffer */
2021 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
2022 if (dataToRead == 0)
2025 * Move data read from our card into the line disciplines
2026 * buffer for translation if necessary.
2028 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
2029 tail = (tail + dataToRead) & wrapmask;
2030 bytesAvailable -= dataToRead;
2031 } /* End while there is data on the card */
2033 writew(tail, &bc->rout);
2034 /* Must be called with global data */
2035 tty_schedule_flip(ch->port.tty);
2038 static int info_ioctl(struct tty_struct *tty, struct file *file,
2039 unsigned int cmd, unsigned long arg)
2044 struct digi_info di;
2047 if (get_user(brd, (unsigned int __user *)arg))
2049 if (brd < 0 || brd >= num_cards || num_cards == 0)
2052 memset(&di, 0, sizeof(di));
2055 di.status = boards[brd].status;
2056 di.type = boards[brd].type ;
2057 di.numports = boards[brd].numports ;
2058 /* Legacy fixups - just move along nothing to see */
2059 di.port = (unsigned char *)boards[brd].port ;
2060 di.membase = (unsigned char *)boards[brd].membase ;
2062 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
2070 int brd = arg & 0xff000000 >> 16;
2071 unsigned char state = arg & 0xff;
2073 if (brd < 0 || brd >= num_cards) {
2074 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
2077 digi_poller_inhibited = state;
2084 * This call is made by the apps to complete the
2085 * initialization of the board(s). This routine is
2086 * responsible for setting the card to its initial
2087 * state and setting the drivers control fields to the
2088 * sutianle settings for the card in question.
2091 for (crd = 0; crd < num_cards; crd++)
2101 static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2103 struct channel *ch = (struct channel *) tty->driver_data;
2104 struct board_chan __iomem *bc;
2105 unsigned int mstat, mflag = 0;
2106 unsigned long flags;
2113 spin_lock_irqsave(&epca_lock, flags);
2115 mstat = readb(&bc->mstat);
2117 spin_unlock_irqrestore(&epca_lock, flags);
2119 if (mstat & ch->m_dtr)
2121 if (mstat & ch->m_rts)
2123 if (mstat & ch->m_cts)
2125 if (mstat & ch->dsr)
2127 if (mstat & ch->m_ri)
2129 if (mstat & ch->dcd)
2134 static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2135 unsigned int set, unsigned int clear)
2137 struct channel *ch = (struct channel *) tty->driver_data;
2138 unsigned long flags;
2143 spin_lock_irqsave(&epca_lock, flags);
2145 * I think this modemfake stuff is broken. It doesn't correctly reflect
2146 * the behaviour desired by the TIOCM* ioctls. Therefore this is
2149 if (set & TIOCM_RTS) {
2150 ch->modemfake |= ch->m_rts;
2151 ch->modem |= ch->m_rts;
2153 if (set & TIOCM_DTR) {
2154 ch->modemfake |= ch->m_dtr;
2155 ch->modem |= ch->m_dtr;
2157 if (clear & TIOCM_RTS) {
2158 ch->modemfake |= ch->m_rts;
2159 ch->modem &= ~ch->m_rts;
2161 if (clear & TIOCM_DTR) {
2162 ch->modemfake |= ch->m_dtr;
2163 ch->modem &= ~ch->m_dtr;
2167 * The below routine generally sets up parity, baud, flow control
2168 * issues, etc.... It effect both control flags and input flags.
2172 spin_unlock_irqrestore(&epca_lock, flags);
2176 static int pc_ioctl(struct tty_struct *tty, struct file *file,
2177 unsigned int cmd, unsigned long arg)
2180 unsigned long flags;
2181 unsigned int mflag, mstat;
2182 unsigned char startc, stopc;
2183 struct board_chan __iomem *bc;
2184 struct channel *ch = (struct channel *) tty->driver_data;
2185 void __user *argp = (void __user *)arg;
2193 mflag = pc_tiocmget(tty, file);
2194 if (put_user(mflag, (unsigned long __user *)argp))
2198 if (get_user(mstat, (unsigned __user *)argp))
2200 return pc_tiocmset(tty, file, mstat, ~mstat);
2202 spin_lock_irqsave(&epca_lock, flags);
2203 ch->omodem |= ch->m_dtr;
2205 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2207 spin_unlock_irqrestore(&epca_lock, flags);
2211 spin_lock_irqsave(&epca_lock, flags);
2212 ch->omodem &= ~ch->m_dtr;
2214 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2216 spin_unlock_irqrestore(&epca_lock, flags);
2219 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2225 if (cmd == DIGI_SETAW) {
2226 /* Setup an event to indicate when the transmit
2228 spin_lock_irqsave(&epca_lock, flags);
2229 setup_empty_event(tty, ch);
2230 spin_unlock_irqrestore(&epca_lock, flags);
2231 tty_wait_until_sent(tty, 0);
2233 /* ldisc lock already held in ioctl */
2234 if (tty->ldisc.ops->flush_buffer)
2235 tty->ldisc.ops->flush_buffer(tty);
2240 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2243 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
2244 ch->dcd = ch->m_dsr;
2245 ch->dsr = ch->m_dcd;
2247 ch->dcd = ch->m_dcd;
2248 ch->dsr = ch->m_dsr;
2251 spin_lock_irqsave(&epca_lock, flags);
2255 * The below routine generally sets up parity, baud, flow
2256 * control issues, etc.... It effect both control flags and
2261 spin_unlock_irqrestore(&epca_lock, flags);
2266 spin_lock_irqsave(&epca_lock, flags);
2268 if (cmd == DIGI_GETFLOW) {
2269 dflow.startc = readb(&bc->startc);
2270 dflow.stopc = readb(&bc->stopc);
2272 dflow.startc = readb(&bc->startca);
2273 dflow.stopc = readb(&bc->stopca);
2276 spin_unlock_irqrestore(&epca_lock, flags);
2278 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2284 if (cmd == DIGI_SETFLOW) {
2285 startc = ch->startc;
2288 startc = ch->startca;
2292 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2295 if (dflow.startc != startc || dflow.stopc != stopc) {
2296 /* Begin if setflow toggled */
2297 spin_lock_irqsave(&epca_lock, flags);
2300 if (cmd == DIGI_SETFLOW) {
2301 ch->fepstartc = ch->startc = dflow.startc;
2302 ch->fepstopc = ch->stopc = dflow.stopc;
2303 fepcmd(ch, SONOFFC, ch->fepstartc,
2304 ch->fepstopc, 0, 1);
2306 ch->fepstartca = ch->startca = dflow.startc;
2307 ch->fepstopca = ch->stopca = dflow.stopc;
2308 fepcmd(ch, SAUXONOFFC, ch->fepstartca,
2309 ch->fepstopca, 0, 1);
2312 if (ch->statusflags & TXSTOPPED)
2316 spin_unlock_irqrestore(&epca_lock, flags);
2317 } /* End if setflow toggled */
2320 return -ENOIOCTLCMD;
2325 static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2328 unsigned long flags;
2330 * verifyChannel returns the channel from the tty struct if it is
2331 * valid. This serves as a sanity check.
2333 ch = verifyChannel(tty);
2335 if (ch != NULL) { /* Begin if channel valid */
2336 spin_lock_irqsave(&epca_lock, flags);
2340 spin_unlock_irqrestore(&epca_lock, flags);
2342 if ((old_termios->c_cflag & CRTSCTS) &&
2343 ((tty->termios->c_cflag & CRTSCTS) == 0))
2344 tty->hw_stopped = 0;
2346 if (!(old_termios->c_cflag & CLOCAL) &&
2347 (tty->termios->c_cflag & CLOCAL))
2348 wake_up_interruptible(&ch->port.open_wait);
2350 } /* End if channel valid */
2353 static void do_softint(struct work_struct *work)
2355 struct channel *ch = container_of(work, struct channel, tqueue);
2356 /* Called in response to a modem change event */
2357 if (ch && ch->magic == EPCA_MAGIC) {
2358 struct tty_struct *tty = ch->port.tty;
2360 if (tty && tty->driver_data) {
2361 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) {
2363 wake_up_interruptible(&ch->port.open_wait);
2364 ch->port.flags &= ~ASYNC_NORMAL_ACTIVE;
2371 * pc_stop and pc_start provide software flow control to the routine and the
2374 static void pc_stop(struct tty_struct *tty)
2377 unsigned long flags;
2379 * verifyChannel returns the channel from the tty struct if it is
2380 * valid. This serves as a sanity check.
2382 ch = verifyChannel(tty);
2384 spin_lock_irqsave(&epca_lock, flags);
2385 if ((ch->statusflags & TXSTOPPED) == 0) {
2386 /* Begin if transmit stop requested */
2388 /* STOP transmitting now !! */
2389 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
2390 ch->statusflags |= TXSTOPPED;
2392 } /* End if transmit stop requested */
2393 spin_unlock_irqrestore(&epca_lock, flags);
2397 static void pc_start(struct tty_struct *tty)
2401 * verifyChannel returns the channel from the tty struct if it is
2402 * valid. This serves as a sanity check.
2404 ch = verifyChannel(tty);
2406 unsigned long flags;
2407 spin_lock_irqsave(&epca_lock, flags);
2408 /* Just in case output was resumed because of a change
2410 if (ch->statusflags & TXSTOPPED) {
2411 /* Begin transmit resume requested */
2412 struct board_chan __iomem *bc;
2415 if (ch->statusflags & LOWWAIT)
2416 writeb(1, &bc->ilow);
2417 /* Okay, you can start transmitting again... */
2418 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
2419 ch->statusflags &= ~TXSTOPPED;
2421 } /* End transmit resume requested */
2422 spin_unlock_irqrestore(&epca_lock, flags);
2427 * The below routines pc_throttle and pc_unthrottle are used to slow (And
2428 * resume) the receipt of data into the kernels receive buffers. The exact
2429 * occurrence of this depends on the size of the kernels receive buffer and
2430 * what the 'watermarks' are set to for that buffer. See the n_ttys.c file for
2433 static void pc_throttle(struct tty_struct *tty)
2436 unsigned long flags;
2438 * verifyChannel returns the channel from the tty struct if it is
2439 * valid. This serves as a sanity check.
2441 ch = verifyChannel(tty);
2443 spin_lock_irqsave(&epca_lock, flags);
2444 if ((ch->statusflags & RXSTOPPED) == 0) {
2446 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
2447 ch->statusflags |= RXSTOPPED;
2450 spin_unlock_irqrestore(&epca_lock, flags);
2454 static void pc_unthrottle(struct tty_struct *tty)
2457 unsigned long flags;
2459 * verifyChannel returns the channel from the tty struct if it is
2460 * valid. This serves as a sanity check.
2462 ch = verifyChannel(tty);
2464 /* Just in case output was resumed because of a change
2466 spin_lock_irqsave(&epca_lock, flags);
2467 if (ch->statusflags & RXSTOPPED) {
2469 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
2470 ch->statusflags &= ~RXSTOPPED;
2473 spin_unlock_irqrestore(&epca_lock, flags);
2477 static int pc_send_break(struct tty_struct *tty, int msec)
2479 struct channel *ch = (struct channel *) tty->driver_data;
2480 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);
2500 /* Caller MUST hold the lock */
2501 static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2503 struct board_chan __iomem *bc = ch->brdchan;
2506 ch->statusflags |= EMPTYWAIT;
2508 * When set the iempty flag request a event to be generated when the
2509 * transmit buffer is empty (If there is no BREAK in progress).
2511 writeb(1, &bc->iempty);
2516 static void __init 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 static int __init epca_real_setup(char *str)
2774 epca_setup(get_options(str, 11, ints), ints);
2778 __setup("digiepca", epca_real_setup);
2781 enum epic_board_types {
2788 /* indexed directly by epic_board_types enum */
2790 unsigned char board_type;
2791 unsigned bar_idx; /* PCI base address region */
2792 } epca_info_tbl[] = {
2799 static int __devinit epca_init_one(struct pci_dev *pdev,
2800 const struct pci_device_id *ent)
2802 static int board_num = -1;
2803 int board_idx, info_idx = ent->driver_data;
2806 if (pci_enable_device(pdev))
2810 board_idx = board_num + num_cards;
2811 if (board_idx >= MAXBOARDS)
2814 addr = pci_resource_start(pdev, epca_info_tbl[info_idx].bar_idx);
2816 printk(KERN_ERR PFX "PCI region #%d not available (size 0)\n",
2817 epca_info_tbl[info_idx].bar_idx);
2821 boards[board_idx].status = ENABLED;
2822 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
2823 boards[board_idx].numports = 0x0;
2824 boards[board_idx].port = addr + PCI_IO_OFFSET;
2825 boards[board_idx].membase = addr;
2827 if (!request_mem_region(addr + PCI_IO_OFFSET, 0x200000, "epca")) {
2828 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2829 0x200000, addr + PCI_IO_OFFSET);
2833 boards[board_idx].re_map_port = ioremap_nocache(addr + PCI_IO_OFFSET,
2835 if (!boards[board_idx].re_map_port) {
2836 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2837 0x200000, addr + PCI_IO_OFFSET);
2838 goto err_out_free_pciio;
2841 if (!request_mem_region(addr, 0x200000, "epca")) {
2842 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2844 goto err_out_free_iounmap;
2847 boards[board_idx].re_map_membase = ioremap_nocache(addr, 0x200000);
2848 if (!boards[board_idx].re_map_membase) {
2849 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2850 0x200000, addr + PCI_IO_OFFSET);
2851 goto err_out_free_memregion;
2855 * I don't know what the below does, but the hardware guys say its
2856 * required on everything except PLX (In this case XRJ).
2858 if (info_idx != brd_xrj) {
2859 pci_write_config_byte(pdev, 0x40, 0);
2860 pci_write_config_byte(pdev, 0x46, 0);
2865 err_out_free_memregion:
2866 release_mem_region(addr, 0x200000);
2867 err_out_free_iounmap:
2868 iounmap(boards[board_idx].re_map_port);
2870 release_mem_region(addr + PCI_IO_OFFSET, 0x200000);
2876 static struct pci_device_id epca_pci_tbl[] = {
2877 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
2878 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
2879 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
2880 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
2884 MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
2886 static int __init init_PCI(void)
2888 memset(&epca_driver, 0, sizeof(epca_driver));
2889 epca_driver.name = "epca";
2890 epca_driver.id_table = epca_pci_tbl;
2891 epca_driver.probe = epca_init_one;
2893 return pci_register_driver(&epca_driver);
2896 MODULE_LICENSE("GPL");