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. This lock guards the hardware
73 * and the tty_port lock guards the kernel side stuff like use counts. Take
74 * this lock inside the port lock if you must take both.
76 static DEFINE_SPINLOCK(epca_lock);
78 /* MAXBOARDS is typically 12, but ISA and EISA cards are restricted
80 static struct board_info boards[MAXBOARDS];
82 static struct tty_driver *pc_driver;
83 static struct tty_driver *pc_info;
85 /* ------------------ Begin Digi specific structures -------------------- */
88 * digi_channels represents an array of structures that keep track of each
89 * channel of the Digi product. Information such as transmit and receive
90 * pointers, termio data, and signal definitions (DTR, CTS, etc ...) are stored
91 * here. This structure is NOT used to overlay the cards physical channel
94 static struct channel digi_channels[MAX_ALLOC];
97 * card_ptr is an array used to hold the address of the first channel structure
98 * of each card. This array will hold the addresses of various channels located
101 static struct channel *card_ptr[MAXCARDS];
103 static struct timer_list epca_timer;
106 * Begin generic memory functions. These functions will be alias (point at)
107 * more specific functions dependent on the board being configured.
109 static void memwinon(struct board_info *b, unsigned int win);
110 static void memwinoff(struct board_info *b, unsigned int win);
111 static void globalwinon(struct channel *ch);
112 static void rxwinon(struct channel *ch);
113 static void txwinon(struct channel *ch);
114 static void memoff(struct channel *ch);
115 static void assertgwinon(struct channel *ch);
116 static void assertmemoff(struct channel *ch);
118 /* ---- Begin more 'specific' memory functions for cx_like products --- */
120 static void pcxem_memwinon(struct board_info *b, unsigned int win);
121 static void pcxem_memwinoff(struct board_info *b, unsigned int win);
122 static void pcxem_globalwinon(struct channel *ch);
123 static void pcxem_rxwinon(struct channel *ch);
124 static void pcxem_txwinon(struct channel *ch);
125 static void pcxem_memoff(struct channel *ch);
127 /* ------ Begin more 'specific' memory functions for the pcxe ------- */
129 static void pcxe_memwinon(struct board_info *b, unsigned int win);
130 static void pcxe_memwinoff(struct board_info *b, unsigned int win);
131 static void pcxe_globalwinon(struct channel *ch);
132 static void pcxe_rxwinon(struct channel *ch);
133 static void pcxe_txwinon(struct channel *ch);
134 static void pcxe_memoff(struct channel *ch);
136 /* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
137 /* Note : pc64xe and pcxi share the same windowing routines */
139 static void pcxi_memwinon(struct board_info *b, unsigned int win);
140 static void pcxi_memwinoff(struct board_info *b, unsigned int win);
141 static void pcxi_globalwinon(struct channel *ch);
142 static void pcxi_rxwinon(struct channel *ch);
143 static void pcxi_txwinon(struct channel *ch);
144 static void pcxi_memoff(struct channel *ch);
146 /* - Begin 'specific' do nothing memory functions needed for some cards - */
148 static void dummy_memwinon(struct board_info *b, unsigned int win);
149 static void dummy_memwinoff(struct board_info *b, unsigned int win);
150 static void dummy_globalwinon(struct channel *ch);
151 static void dummy_rxwinon(struct channel *ch);
152 static void dummy_txwinon(struct channel *ch);
153 static void dummy_memoff(struct channel *ch);
154 static void dummy_assertgwinon(struct channel *ch);
155 static void dummy_assertmemoff(struct channel *ch);
157 static struct channel *verifyChannel(struct tty_struct *);
158 static void pc_sched_event(struct channel *, int);
159 static void epca_error(int, char *);
160 static void pc_close(struct tty_struct *, struct file *);
161 static void shutdown(struct channel *, struct tty_struct *tty);
162 static void pc_hangup(struct tty_struct *);
163 static int pc_write_room(struct tty_struct *);
164 static int pc_chars_in_buffer(struct tty_struct *);
165 static void pc_flush_buffer(struct tty_struct *);
166 static void pc_flush_chars(struct tty_struct *);
167 static int block_til_ready(struct tty_struct *, struct file *,
169 static int pc_open(struct tty_struct *, struct file *);
170 static void post_fep_init(unsigned int crd);
171 static void epcapoll(unsigned long);
172 static void doevent(int);
173 static void fepcmd(struct channel *, int, int, int, int, int);
174 static unsigned termios2digi_h(struct channel *ch, unsigned);
175 static unsigned termios2digi_i(struct channel *ch, unsigned);
176 static unsigned termios2digi_c(struct channel *ch, unsigned);
177 static void epcaparam(struct tty_struct *, struct channel *);
178 static void receive_data(struct channel *, struct tty_struct *tty);
179 static int pc_ioctl(struct tty_struct *, struct file *,
180 unsigned int, unsigned long);
181 static int info_ioctl(struct tty_struct *, struct file *,
182 unsigned int, unsigned long);
183 static void pc_set_termios(struct tty_struct *, struct ktermios *);
184 static void do_softint(struct work_struct *work);
185 static void pc_stop(struct tty_struct *);
186 static void pc_start(struct tty_struct *);
187 static void pc_throttle(struct tty_struct *tty);
188 static void pc_unthrottle(struct tty_struct *tty);
189 static int pc_send_break(struct tty_struct *tty, int msec);
190 static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
192 static int pc_write(struct tty_struct *, const unsigned char *, int);
193 static int pc_init(void);
194 static int init_PCI(void);
197 * Table of functions for each board to handle memory. Mantaining parallelism
198 * is a *very* good idea here. The idea is for the runtime code to blindly call
199 * these functions, not knowing/caring about the underlying hardware. This
200 * stuff should contain no conditionals; if more functionality is needed a
201 * different entry should be established. These calls are the interface calls
202 * and are the only functions that should be accessed. Anyone caught making
203 * direct calls deserves what they get.
205 static void memwinon(struct board_info *b, unsigned int win)
210 static void memwinoff(struct board_info *b, unsigned int win)
212 b->memwinoff(b, win);
215 static void globalwinon(struct channel *ch)
217 ch->board->globalwinon(ch);
220 static void rxwinon(struct channel *ch)
222 ch->board->rxwinon(ch);
225 static void txwinon(struct channel *ch)
227 ch->board->txwinon(ch);
230 static void memoff(struct channel *ch)
232 ch->board->memoff(ch);
234 static void assertgwinon(struct channel *ch)
236 ch->board->assertgwinon(ch);
239 static void assertmemoff(struct channel *ch)
241 ch->board->assertmemoff(ch);
244 /* PCXEM windowing is the same as that used in the PCXR and CX series cards. */
245 static void pcxem_memwinon(struct board_info *b, unsigned int win)
247 outb_p(FEPWIN | win, b->port + 1);
250 static void pcxem_memwinoff(struct board_info *b, unsigned int win)
252 outb_p(0, b->port + 1);
255 static void pcxem_globalwinon(struct channel *ch)
257 outb_p(FEPWIN, (int)ch->board->port + 1);
260 static void pcxem_rxwinon(struct channel *ch)
262 outb_p(ch->rxwin, (int)ch->board->port + 1);
265 static void pcxem_txwinon(struct channel *ch)
267 outb_p(ch->txwin, (int)ch->board->port + 1);
270 static void pcxem_memoff(struct channel *ch)
272 outb_p(0, (int)ch->board->port + 1);
275 /* ----------------- Begin pcxe memory window stuff ------------------ */
276 static void pcxe_memwinon(struct board_info *b, unsigned int win)
278 outb_p(FEPWIN | win, b->port + 1);
281 static void pcxe_memwinoff(struct board_info *b, unsigned int win)
283 outb_p(inb(b->port) & ~FEPMEM, b->port + 1);
284 outb_p(0, b->port + 1);
287 static void pcxe_globalwinon(struct channel *ch)
289 outb_p(FEPWIN, (int)ch->board->port + 1);
292 static void pcxe_rxwinon(struct channel *ch)
294 outb_p(ch->rxwin, (int)ch->board->port + 1);
297 static void pcxe_txwinon(struct channel *ch)
299 outb_p(ch->txwin, (int)ch->board->port + 1);
302 static void pcxe_memoff(struct channel *ch)
304 outb_p(0, (int)ch->board->port);
305 outb_p(0, (int)ch->board->port + 1);
308 /* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
309 static void pcxi_memwinon(struct board_info *b, unsigned int win)
311 outb_p(inb(b->port) | FEPMEM, b->port);
314 static void pcxi_memwinoff(struct board_info *b, unsigned int win)
316 outb_p(inb(b->port) & ~FEPMEM, b->port);
319 static void pcxi_globalwinon(struct channel *ch)
321 outb_p(FEPMEM, ch->board->port);
324 static void pcxi_rxwinon(struct channel *ch)
326 outb_p(FEPMEM, ch->board->port);
329 static void pcxi_txwinon(struct channel *ch)
331 outb_p(FEPMEM, ch->board->port);
334 static void pcxi_memoff(struct channel *ch)
336 outb_p(0, ch->board->port);
339 static void pcxi_assertgwinon(struct channel *ch)
341 epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
344 static void pcxi_assertmemoff(struct channel *ch)
346 epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
350 * Not all of the cards need specific memory windowing routines. Some cards
351 * (Such as PCI) needs no windowing routines at all. We provide these do
352 * nothing routines so that the same code base can be used. The driver will
353 * ALWAYS call a windowing routine if it thinks it needs to; regardless of the
354 * card. However, dependent on the card the routine may or may not do anything.
356 static void dummy_memwinon(struct board_info *b, unsigned int win)
360 static void dummy_memwinoff(struct board_info *b, unsigned int win)
364 static void dummy_globalwinon(struct channel *ch)
368 static void dummy_rxwinon(struct channel *ch)
372 static void dummy_txwinon(struct channel *ch)
376 static void dummy_memoff(struct channel *ch)
380 static void dummy_assertgwinon(struct channel *ch)
384 static void dummy_assertmemoff(struct channel *ch)
388 static struct channel *verifyChannel(struct tty_struct *tty)
391 * This routine basically provides a sanity check. It insures that the
392 * channel returned is within the proper range of addresses as well as
393 * properly initialized. If some bogus info gets passed in
394 * through tty->driver_data this should catch it.
397 struct channel *ch = tty->driver_data;
398 if (ch >= &digi_channels[0] && ch < &digi_channels[nbdevs]) {
399 if (ch->magic == EPCA_MAGIC)
406 static void pc_sched_event(struct channel *ch, int event)
409 * We call this to schedule interrupt processing on some event. The
410 * kernel sees our request and calls the related routine in OUR driver.
412 ch->event |= 1 << event;
413 schedule_work(&ch->tqueue);
416 static void epca_error(int line, char *msg)
418 printk(KERN_ERR "epca_error (Digi): line = %d %s\n", line, msg);
421 static void pc_close(struct tty_struct *tty, struct file *filp)
424 struct tty_port *port;
427 * verifyChannel returns the channel from the tty struct if it is
428 * valid. This serves as a sanity check.
430 ch = verifyChannel(tty);
435 spin_lock_irqsave(&port->lock, flags);
436 if (tty_hung_up_p(filp)) {
437 spin_unlock_irqrestore(&port->lock, flags);
440 if (port->count-- > 1) {
441 /* Begin channel is open more than once */
443 * Return without doing anything. Someone might still
444 * be using the channel.
446 spin_unlock_irqrestore(&port->lock, flags);
449 /* Port open only once go ahead with shutdown & reset */
450 WARN_ON(port->count < 0);
453 * Let the rest of the driver know the channel is being closed.
454 * This becomes important if an open is attempted before close
457 port->flags |= ASYNC_CLOSING;
460 spin_unlock_irqrestore(&port->lock, flags);
462 if (port->flags & ASYNC_INITIALIZED) {
463 /* Setup an event to indicate when the
464 transmit buffer empties */
465 setup_empty_event(tty, ch);
466 /* 30 seconds timeout */
467 tty_wait_until_sent(tty, 3000);
469 pc_flush_buffer(tty);
470 tty_ldisc_flush(tty);
473 spin_lock_irqsave(&port->lock, flags);
476 tty_port_tty_set(port, NULL);
477 spin_unlock_irqrestore(&port->lock, flags);
479 if (port->blocked_open) {
481 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
482 wake_up_interruptible(&port->open_wait);
484 port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
486 wake_up_interruptible(&port->close_wait);
489 static void shutdown(struct channel *ch, struct tty_struct *tty)
492 struct board_chan __iomem *bc;
493 struct tty_port *port = &ch->port;
495 if (!(port->flags & ASYNC_INITIALIZED))
498 spin_lock_irqsave(&epca_lock, flags);
504 * In order for an event to be generated on the receipt of data the
505 * idata flag must be set. Since we are shutting down, this is not
506 * necessary clear this flag.
509 writeb(0, &bc->idata);
511 /* If we're a modem control device and HUPCL is on, drop RTS & DTR. */
512 if (tty->termios->c_cflag & HUPCL) {
513 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
514 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
519 * The channel has officialy been closed. The next time it is opened it
520 * will have to reinitialized. Set a flag to indicate this.
522 /* Prevent future Digi programmed interrupts from coming active */
523 port->flags &= ~ASYNC_INITIALIZED;
524 spin_unlock_irqrestore(&epca_lock, flags);
527 static void pc_hangup(struct tty_struct *tty)
530 struct tty_port *port;
533 * verifyChannel returns the channel from the tty struct if it is
534 * valid. This serves as a sanity check.
536 ch = verifyChannel(tty);
541 pc_flush_buffer(tty);
542 tty_ldisc_flush(tty);
545 spin_lock_irqsave(&port->lock, flags);
547 ch->event = 0; /* FIXME: review locking of ch->event */
549 port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
550 spin_unlock_irqrestore(&port->lock, flags);
551 wake_up_interruptible(&port->open_wait);
555 static int pc_write(struct tty_struct *tty,
556 const unsigned char *buf, int bytesAvailable)
558 unsigned int head, tail;
565 struct board_chan __iomem *bc;
568 * pc_write is primarily called directly by the kernel routine
569 * tty_write (Though it can also be called by put_char) found in
570 * tty_io.c. pc_write is passed a line discipline buffer where the data
571 * to be written out is stored. The line discipline implementation
572 * itself is done at the kernel level and is not brought into the
577 * verifyChannel returns the channel from the tty struct if it is
578 * valid. This serves as a sanity check.
580 ch = verifyChannel(tty);
584 /* Make a pointer to the channel data structure found on the board. */
586 size = ch->txbufsize;
589 spin_lock_irqsave(&epca_lock, flags);
592 head = readw(&bc->tin) & (size - 1);
593 tail = readw(&bc->tout);
595 if (tail != readw(&bc->tout))
596 tail = readw(&bc->tout);
600 /* head has not wrapped */
602 * remain (much like dataLen above) represents the total amount
603 * of space available on the card for data. Here dataLen
604 * represents the space existing between the head pointer and
605 * the end of buffer. This is important because a memcpy cannot
606 * be told to automatically wrap around when it hits the buffer
609 dataLen = size - head;
610 remain = size - (head - tail) - 1;
612 /* head has wrapped around */
613 remain = tail - head - 1;
617 * Check the space on the card. If we have more data than space; reduce
618 * the amount of data to fit the space.
620 bytesAvailable = min(remain, bytesAvailable);
622 while (bytesAvailable > 0) {
623 /* there is data to copy onto card */
626 * If head is not wrapped, the below will make sure the first
627 * data copy fills to the end of card buffer.
629 dataLen = min(bytesAvailable, dataLen);
630 memcpy_toio(ch->txptr + head, buf, dataLen);
633 amountCopied += dataLen;
634 bytesAvailable -= dataLen;
641 ch->statusflags |= TXBUSY;
643 writew(head, &bc->tin);
645 if ((ch->statusflags & LOWWAIT) == 0) {
646 ch->statusflags |= LOWWAIT;
647 writeb(1, &bc->ilow);
650 spin_unlock_irqrestore(&epca_lock, flags);
654 static int pc_write_room(struct tty_struct *tty)
659 unsigned int head, tail;
660 struct board_chan __iomem *bc;
662 * verifyChannel returns the channel from the tty struct if it is
663 * valid. This serves as a sanity check.
665 ch = verifyChannel(tty);
667 spin_lock_irqsave(&epca_lock, flags);
671 head = readw(&bc->tin) & (ch->txbufsize - 1);
672 tail = readw(&bc->tout);
674 if (tail != readw(&bc->tout))
675 tail = readw(&bc->tout);
676 /* Wrap tail if necessary */
677 tail &= (ch->txbufsize - 1);
678 remain = tail - head - 1;
680 remain += ch->txbufsize;
682 if (remain && (ch->statusflags & LOWWAIT) == 0) {
683 ch->statusflags |= LOWWAIT;
684 writeb(1, &bc->ilow);
687 spin_unlock_irqrestore(&epca_lock, flags);
689 /* Return how much room is left on card */
693 static int pc_chars_in_buffer(struct tty_struct *tty)
696 unsigned int ctail, head, tail;
700 struct board_chan __iomem *bc;
702 * verifyChannel returns the channel from the tty struct if it is
703 * valid. This serves as a sanity check.
705 ch = verifyChannel(tty);
709 spin_lock_irqsave(&epca_lock, flags);
713 tail = readw(&bc->tout);
714 head = readw(&bc->tin);
715 ctail = readw(&ch->mailbox->cout);
717 if (tail == head && readw(&ch->mailbox->cin) == ctail &&
718 readb(&bc->tbusy) == 0)
720 else { /* Begin if some space on the card has been used */
721 head = readw(&bc->tin) & (ch->txbufsize - 1);
722 tail &= (ch->txbufsize - 1);
724 * The logic here is basically opposite of the above
725 * pc_write_room here we are finding the amount of bytes in the
726 * buffer filled. Not the amount of bytes empty.
728 remain = tail - head - 1;
730 remain += ch->txbufsize;
731 chars = (int)(ch->txbufsize - remain);
733 * Make it possible to wakeup anything waiting for output in
736 * If not already set. Setup an event to indicate when the
737 * transmit buffer empties.
739 if (!(ch->statusflags & EMPTYWAIT))
740 setup_empty_event(tty, ch);
741 } /* End if some space on the card has been used */
743 spin_unlock_irqrestore(&epca_lock, flags);
744 /* Return number of characters residing on card. */
748 static void pc_flush_buffer(struct tty_struct *tty)
753 struct board_chan __iomem *bc;
755 * verifyChannel returns the channel from the tty struct if it is
756 * valid. This serves as a sanity check.
758 ch = verifyChannel(tty);
762 spin_lock_irqsave(&epca_lock, flags);
765 tail = readw(&bc->tout);
766 /* Have FEP move tout pointer; effectively flushing transmit buffer */
767 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
769 spin_unlock_irqrestore(&epca_lock, flags);
773 static void pc_flush_chars(struct tty_struct *tty)
777 * verifyChannel returns the channel from the tty struct if it is
778 * valid. This serves as a sanity check.
780 ch = verifyChannel(tty);
783 spin_lock_irqsave(&epca_lock, flags);
785 * If not already set and the transmitter is busy setup an
786 * event to indicate when the transmit empties.
788 if ((ch->statusflags & TXBUSY) &&
789 !(ch->statusflags & EMPTYWAIT))
790 setup_empty_event(tty, ch);
791 spin_unlock_irqrestore(&epca_lock, flags);
795 static int block_til_ready(struct tty_struct *tty,
796 struct file *filp, struct channel *ch)
798 DECLARE_WAITQUEUE(wait, current);
799 int retval, do_clocal = 0;
801 struct tty_port *port = &ch->port;
803 if (tty_hung_up_p(filp)) {
804 if (port->flags & ASYNC_HUP_NOTIFY)
807 retval = -ERESTARTSYS;
812 * If the device is in the middle of being closed, then block until
813 * it's done, and then try again.
815 if (port->flags & ASYNC_CLOSING) {
816 interruptible_sleep_on(&port->close_wait);
818 if (port->flags & ASYNC_HUP_NOTIFY)
824 if (filp->f_flags & O_NONBLOCK) {
826 * If non-blocking mode is set, then make the check up front
829 port->flags |= ASYNC_NORMAL_ACTIVE;
832 if (tty->termios->c_cflag & CLOCAL)
834 /* Block waiting for the carrier detect and the line to become free */
837 add_wait_queue(&port->open_wait, &wait);
839 spin_lock_irqsave(&port->lock, flags);
840 /* We dec count so that pc_close will know when to free things */
841 if (!tty_hung_up_p(filp))
843 port->blocked_open++;
845 set_current_state(TASK_INTERRUPTIBLE);
846 if (tty_hung_up_p(filp) ||
847 !(port->flags & ASYNC_INITIALIZED)) {
848 if (port->flags & ASYNC_HUP_NOTIFY)
851 retval = -ERESTARTSYS;
854 if (!(port->flags & ASYNC_CLOSING) &&
855 (do_clocal || (ch->imodem & ch->dcd)))
857 if (signal_pending(current)) {
858 retval = -ERESTARTSYS;
861 spin_unlock_irqrestore(&port->lock, flags);
863 * Allow someone else to be scheduled. We will occasionally go
864 * through this loop until one of the above conditions change.
865 * The below schedule call will allow other processes to enter
866 * and prevent this loop from hogging the cpu.
869 spin_lock_irqsave(&port->lock, flags);
872 __set_current_state(TASK_RUNNING);
873 remove_wait_queue(&port->open_wait, &wait);
874 if (!tty_hung_up_p(filp))
876 port->blocked_open--;
878 spin_unlock_irqrestore(&port->lock, flags);
883 port->flags |= ASYNC_NORMAL_ACTIVE;
887 static int pc_open(struct tty_struct *tty, struct file *filp)
890 struct tty_port *port;
892 int line, retval, boardnum;
893 struct board_chan __iomem *bc;
897 if (line < 0 || line >= nbdevs)
900 ch = &digi_channels[line];
902 boardnum = ch->boardnum;
904 /* Check status of board configured in system. */
907 * I check to see if the epca_setup routine detected an user error. It
908 * might be better to put this in pc_init, but for the moment it goes
911 if (invalid_lilo_config) {
912 if (setup_error_code & INVALID_BOARD_TYPE)
913 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
914 if (setup_error_code & INVALID_NUM_PORTS)
915 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
916 if (setup_error_code & INVALID_MEM_BASE)
917 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
918 if (setup_error_code & INVALID_PORT_BASE)
919 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
920 if (setup_error_code & INVALID_BOARD_STATUS)
921 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
922 if (setup_error_code & INVALID_ALTPIN)
923 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
924 tty->driver_data = NULL; /* Mark this device as 'down' */
927 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
928 tty->driver_data = NULL; /* Mark this device as 'down' */
934 tty->driver_data = NULL;
938 spin_lock_irqsave(&port->lock, flags);
940 * Every time a channel is opened, increment a counter. This is
941 * necessary because we do not wish to flush and shutdown the channel
942 * until the last app holding the channel open, closes it.
946 * Set a kernel structures pointer to our local channel structure. This
947 * way we can get to it when passed only a tty struct.
949 tty->driver_data = ch;
952 * If this is the first time the channel has been opened, initialize
953 * the tty->termios struct otherwise let pc_close handle it.
955 spin_lock(&epca_lock);
959 /* Save boards current modem status */
960 ch->imodem = readb(&bc->mstat);
963 * Set receive head and tail ptrs to each other. This indicates no data
966 head = readw(&bc->rin);
967 writew(head, &bc->rout);
969 /* Set the channels associated tty structure */
972 * The below routine generally sets up parity, baud, flow control
973 * issues, etc.... It effect both control flags and input flags.
977 spin_unlock(&epca_lock);
978 port->flags |= ASYNC_INITIALIZED;
979 spin_unlock_irqrestore(&port->lock, flags);
981 retval = block_til_ready(tty, filp, ch);
985 * Set this again in case a hangup set it to zero while this open() was
986 * waiting for the line...
988 spin_lock_irqsave(&port->lock, flags);
990 spin_lock(&epca_lock);
992 /* Enable Digi Data events */
993 writeb(1, &bc->idata);
995 spin_unlock(&epca_lock);
996 spin_unlock_irqrestore(&port->lock, flags);
1000 static int __init epca_module_init(void)
1004 module_init(epca_module_init);
1006 static struct pci_driver epca_driver;
1008 static void __exit epca_module_exit(void)
1011 struct board_info *bd;
1014 del_timer_sync(&epca_timer);
1016 if (tty_unregister_driver(pc_driver) ||
1017 tty_unregister_driver(pc_info)) {
1018 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
1021 put_tty_driver(pc_driver);
1022 put_tty_driver(pc_info);
1024 for (crd = 0; crd < num_cards; crd++) {
1026 if (!bd) { /* sanity check */
1027 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1031 for (count = 0; count < bd->numports; count++, ch++) {
1032 struct tty_struct *tty = tty_port_tty_get(&ch->port);
1039 pci_unregister_driver(&epca_driver);
1041 module_exit(epca_module_exit);
1043 static const struct tty_operations pc_ops = {
1047 .write_room = pc_write_room,
1048 .flush_buffer = pc_flush_buffer,
1049 .chars_in_buffer = pc_chars_in_buffer,
1050 .flush_chars = pc_flush_chars,
1052 .set_termios = pc_set_termios,
1055 .throttle = pc_throttle,
1056 .unthrottle = pc_unthrottle,
1057 .hangup = pc_hangup,
1058 .break_ctl = pc_send_break
1061 static int info_open(struct tty_struct *tty, struct file *filp)
1066 static struct tty_operations info_ops = {
1068 .ioctl = info_ioctl,
1071 static int __init pc_init(void)
1074 struct board_info *bd;
1075 unsigned char board_id = 0;
1078 int pci_boards_found, pci_count;
1082 pc_driver = alloc_tty_driver(MAX_ALLOC);
1086 pc_info = alloc_tty_driver(MAX_ALLOC);
1091 * If epca_setup has not been ran by LILO set num_cards to defaults;
1092 * copy board structure defined by digiConfig into drivers board
1093 * structure. Note : If LILO has ran epca_setup then epca_setup will
1094 * handle defining num_cards as well as copying the data into the board
1098 /* driver has been configured via. epcaconfig */
1100 num_cards = NUMCARDS;
1101 memcpy(&boards, &static_boards,
1102 sizeof(struct board_info) * NUMCARDS);
1106 * Note : If lilo was used to configure the driver and the ignore
1107 * epcaconfig option was choosen (digiepca=2) then nbdevs and num_cards
1108 * will equal 0 at this point. This is okay; PCI cards will still be
1109 * picked up if detected.
1113 * Set up interrupt, we will worry about memory allocation in
1116 printk(KERN_INFO "DIGI epca driver version %s loaded.\n", VERSION);
1119 * NOTE : This code assumes that the number of ports found in the
1120 * boards array is correct. This could be wrong if the card in question
1121 * is PCI (And therefore has no ports entry in the boards structure.)
1122 * The rest of the information will be valid for PCI because the
1123 * beginning of pc_init scans for PCI and determines i/o and base
1124 * memory addresses. I am not sure if it is possible to read the number
1125 * of ports supported by the card prior to it being booted (Since that
1126 * is the state it is in when pc_init is run). Because it is not
1127 * possible to query the number of supported ports until after the card
1128 * has booted; we are required to calculate the card_ptrs as the card
1129 * is initialized (Inside post_fep_init). The negative thing about this
1130 * approach is that digiDload's call to GET_INFO will have a bad port
1131 * value. (Since this is called prior to post_fep_init.)
1133 pci_boards_found = 0;
1134 if (num_cards < MAXBOARDS)
1135 pci_boards_found += init_PCI();
1136 num_cards += pci_boards_found;
1138 pc_driver->owner = THIS_MODULE;
1139 pc_driver->name = "ttyD";
1140 pc_driver->major = DIGI_MAJOR;
1141 pc_driver->minor_start = 0;
1142 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1143 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1144 pc_driver->init_termios = tty_std_termios;
1145 pc_driver->init_termios.c_iflag = 0;
1146 pc_driver->init_termios.c_oflag = 0;
1147 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1148 pc_driver->init_termios.c_lflag = 0;
1149 pc_driver->init_termios.c_ispeed = 9600;
1150 pc_driver->init_termios.c_ospeed = 9600;
1151 pc_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK;
1152 tty_set_operations(pc_driver, &pc_ops);
1154 pc_info->owner = THIS_MODULE;
1155 pc_info->name = "digi_ctl";
1156 pc_info->major = DIGIINFOMAJOR;
1157 pc_info->minor_start = 0;
1158 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1159 pc_info->subtype = SERIAL_TYPE_INFO;
1160 pc_info->init_termios = tty_std_termios;
1161 pc_info->init_termios.c_iflag = 0;
1162 pc_info->init_termios.c_oflag = 0;
1163 pc_info->init_termios.c_lflag = 0;
1164 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1165 pc_info->init_termios.c_ispeed = 9600;
1166 pc_info->init_termios.c_ospeed = 9600;
1167 pc_info->flags = TTY_DRIVER_REAL_RAW;
1168 tty_set_operations(pc_info, &info_ops);
1171 for (crd = 0; crd < num_cards; crd++) {
1173 * This is where the appropriate memory handlers for the
1174 * hardware is set. Everything at runtime blindly jumps through
1178 /* defined in epcaconfig.h */
1184 bd->memwinon = pcxem_memwinon;
1185 bd->memwinoff = pcxem_memwinoff;
1186 bd->globalwinon = pcxem_globalwinon;
1187 bd->txwinon = pcxem_txwinon;
1188 bd->rxwinon = pcxem_rxwinon;
1189 bd->memoff = pcxem_memoff;
1190 bd->assertgwinon = dummy_assertgwinon;
1191 bd->assertmemoff = dummy_assertmemoff;
1197 bd->memwinon = dummy_memwinon;
1198 bd->memwinoff = dummy_memwinoff;
1199 bd->globalwinon = dummy_globalwinon;
1200 bd->txwinon = dummy_txwinon;
1201 bd->rxwinon = dummy_rxwinon;
1202 bd->memoff = dummy_memoff;
1203 bd->assertgwinon = dummy_assertgwinon;
1204 bd->assertmemoff = dummy_assertmemoff;
1209 bd->memwinon = pcxe_memwinon;
1210 bd->memwinoff = pcxe_memwinoff;
1211 bd->globalwinon = pcxe_globalwinon;
1212 bd->txwinon = pcxe_txwinon;
1213 bd->rxwinon = pcxe_rxwinon;
1214 bd->memoff = pcxe_memoff;
1215 bd->assertgwinon = dummy_assertgwinon;
1216 bd->assertmemoff = dummy_assertmemoff;
1221 bd->memwinon = pcxi_memwinon;
1222 bd->memwinoff = pcxi_memwinoff;
1223 bd->globalwinon = pcxi_globalwinon;
1224 bd->txwinon = pcxi_txwinon;
1225 bd->rxwinon = pcxi_rxwinon;
1226 bd->memoff = pcxi_memoff;
1227 bd->assertgwinon = pcxi_assertgwinon;
1228 bd->assertmemoff = pcxi_assertmemoff;
1236 * Some cards need a memory segment to be defined for use in
1237 * transmit and receive windowing operations. These boards are
1238 * listed in the below switch. In the case of the XI the amount
1239 * of memory on the board is variable so the memory_seg is also
1240 * variable. This code determines what they segment should be.
1246 bd->memory_seg = 0xf000;
1250 board_id = inb((int)bd->port);
1251 if ((board_id & 0x1) == 0x1) {
1252 /* it's an XI card */
1253 /* Is it a 64K board */
1254 if ((board_id & 0x30) == 0)
1255 bd->memory_seg = 0xf000;
1257 /* Is it a 128K board */
1258 if ((board_id & 0x30) == 0x10)
1259 bd->memory_seg = 0xe000;
1261 /* Is is a 256K board */
1262 if ((board_id & 0x30) == 0x20)
1263 bd->memory_seg = 0xc000;
1265 /* Is it a 512K board */
1266 if ((board_id & 0x30) == 0x30)
1267 bd->memory_seg = 0x8000;
1269 printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n", (int)bd->port);
1274 err = tty_register_driver(pc_driver);
1276 printk(KERN_ERR "Couldn't register Digi PC/ driver");
1280 err = tty_register_driver(pc_info);
1282 printk(KERN_ERR "Couldn't register Digi PC/ info ");
1286 /* Start up the poller to check for events on all enabled boards */
1287 init_timer(&epca_timer);
1288 epca_timer.function = epcapoll;
1289 mod_timer(&epca_timer, jiffies + HZ/25);
1293 tty_unregister_driver(pc_driver);
1295 put_tty_driver(pc_info);
1297 put_tty_driver(pc_driver);
1302 static void post_fep_init(unsigned int crd)
1305 void __iomem *memaddr;
1306 struct global_data __iomem *gd;
1307 struct board_info *bd;
1308 struct board_chan __iomem *bc;
1310 int shrinkmem = 0, lowwater;
1313 * This call is made by the user via. the ioctl call DIGI_INIT. It is
1314 * responsible for setting up all the card specific stuff.
1319 * If this is a PCI board, get the port info. Remember PCI cards do not
1320 * have entries into the epcaconfig.h file, so we can't get the number
1321 * of ports from it. Unfortunetly, this means that anyone doing a
1322 * DIGI_GETINFO before the board has booted will get an invalid number
1323 * of ports returned (It should return 0). Calls to DIGI_GETINFO after
1324 * DIGI_INIT has been called will return the proper values.
1326 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
1328 * Below we use XEMPORTS as a memory offset regardless of which
1329 * PCI card it is. This is because all of the supported PCI
1330 * cards have the same memory offset for the channel data. This
1331 * will have to be changed if we ever develop a PCI/XE card.
1332 * NOTE : The FEP manual states that the port offset is 0xC22
1333 * as opposed to 0xC02. This is only true for PC/XE, and PC/XI
1334 * cards; not for the XEM, or CX series. On the PCI cards the
1335 * number of ports is determined by reading a ID PROM located
1336 * in the box attached to the card. The card can then determine
1337 * the index the id to determine the number of ports available.
1338 * (FYI - The id should be located at 0x1ac (And may use up to
1339 * 4 bytes if the box in question is a XEM or CX)).
1341 /* PCI cards are already remapped at this point ISA are not */
1342 bd->numports = readw(bd->re_map_membase + XEMPORTS);
1343 epcaassert(bd->numports <= 64, "PCI returned a invalid number of ports");
1344 nbdevs += (bd->numports);
1346 /* Fix up the mappings for ISA/EISA etc */
1347 /* FIXME: 64K - can we be smarter ? */
1348 bd->re_map_membase = ioremap_nocache(bd->membase, 0x10000);
1352 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1354 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1357 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1359 memaddr = bd->re_map_membase;
1362 * The below assignment will set bc to point at the BEGINING of the
1363 * cards channel structures. For 1 card there will be between 8 and 64
1364 * of these structures.
1366 bc = memaddr + CHANSTRUCT;
1369 * The below assignment will set gd to point at the BEGINING of global
1370 * memory address 0xc00. The first data in that global memory actually
1371 * starts at address 0xc1a. The command in pointer begins at 0xd10.
1373 gd = memaddr + GLOBAL;
1376 * XEPORTS (address 0xc22) points at the number of channels the card
1377 * supports. (For 64XE, XI, XEM, and XR use 0xc02)
1379 if ((bd->type == PCXEVE || bd->type == PCXE) &&
1380 (readw(memaddr + XEPORTS) < 3))
1382 if (bd->type < PCIXEM)
1383 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1388 * Remember ch is the main drivers channels structure, while bc is the
1389 * cards channel structure.
1391 for (i = 0; i < bd->numports; i++, ch++, bc++) {
1392 unsigned long flags;
1395 tty_port_init(&ch->port);
1398 INIT_WORK(&ch->tqueue, do_softint);
1399 ch->board = &boards[crd];
1401 spin_lock_irqsave(&epca_lock, flags);
1404 * Since some of the boards use different bitmaps for
1405 * their control signals we cannot hard code these
1406 * values and retain portability. We virtualize this
1435 if (boards[crd].altpin) {
1436 ch->dsr = ch->m_dcd;
1437 ch->dcd = ch->m_dsr;
1438 ch->digiext.digi_flags |= DIGI_ALTPIN;
1440 ch->dcd = ch->m_dcd;
1441 ch->dsr = ch->m_dsr;
1446 ch->magic = EPCA_MAGIC;
1447 tty_port_tty_set(&ch->port, NULL);
1450 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1454 tseg = readw(&bc->tseg);
1455 rseg = readw(&bc->rseg);
1461 /* Cover all the 2MEG cards */
1462 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1463 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1464 ch->txwin = FEPWIN | (tseg >> 11);
1465 ch->rxwin = FEPWIN | (rseg >> 11);
1470 /* Cover all the 32K windowed cards */
1471 /* Mask equal to window size - 1 */
1472 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1473 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1474 ch->txwin = FEPWIN | (tseg >> 11);
1475 ch->rxwin = FEPWIN | (rseg >> 11);
1480 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4)
1482 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1483 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4)
1485 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >> 9);
1490 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1491 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
1492 ch->txwin = ch->rxwin = 0;
1497 ch->txbufsize = readw(&bc->tmax) + 1;
1500 ch->rxbufsize = readw(&bc->rmax) + 1;
1502 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1504 /* Set transmitter low water mark */
1505 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1507 /* Set receiver low water mark */
1508 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
1510 /* Set receiver high water mark */
1511 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1513 writew(100, &bc->edelay);
1514 writeb(1, &bc->idata);
1516 ch->startc = readb(&bc->startc);
1517 ch->stopc = readb(&bc->stopc);
1518 ch->startca = readb(&bc->startca);
1519 ch->stopca = readb(&bc->stopca);
1529 ch->close_delay = 50;
1531 spin_unlock_irqrestore(&epca_lock, flags);
1535 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1536 VERSION, board_desc[bd->type], (long)bd->port,
1537 (long)bd->membase, bd->numports);
1541 static void epcapoll(unsigned long ignored)
1543 unsigned long flags;
1545 unsigned int head, tail;
1547 struct board_info *bd;
1550 * This routine is called upon every timer interrupt. Even though the
1551 * Digi series cards are capable of generating interrupts this method
1552 * of non-looping polling is more efficient. This routine checks for
1553 * card generated events (Such as receive data, are transmit buffer
1554 * empty) and acts on those events.
1556 for (crd = 0; crd < num_cards; crd++) {
1560 if ((bd->status == DISABLED) || digi_poller_inhibited)
1564 * assertmemoff is not needed here; indeed it is an empty
1565 * subroutine. It is being kept because future boards may need
1566 * this as well as some legacy boards.
1568 spin_lock_irqsave(&epca_lock, flags);
1575 * In this case head and tail actually refer to the event queue
1576 * not the transmit or receive queue.
1578 head = readw(&ch->mailbox->ein);
1579 tail = readw(&ch->mailbox->eout);
1581 /* If head isn't equal to tail we have an event */
1586 spin_unlock_irqrestore(&epca_lock, flags);
1587 } /* End for each card */
1588 mod_timer(&epca_timer, jiffies + (HZ / 25));
1591 static void doevent(int crd)
1593 void __iomem *eventbuf;
1594 struct channel *ch, *chan0;
1595 static struct tty_struct *tty;
1596 struct board_info *bd;
1597 struct board_chan __iomem *bc;
1598 unsigned int tail, head;
1603 * This subroutine is called by epcapoll when an event is detected
1604 * in the event queue. This routine responds to those events.
1608 chan0 = card_ptr[crd];
1609 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
1610 assertgwinon(chan0);
1611 while ((tail = readw(&chan0->mailbox->eout)) !=
1612 (head = readw(&chan0->mailbox->ein))) {
1613 /* Begin while something in event queue */
1614 assertgwinon(chan0);
1615 eventbuf = bd->re_map_membase + tail + ISTART;
1616 /* Get the channel the event occurred on */
1617 channel = readb(eventbuf);
1618 /* Get the actual event code that occurred */
1619 event = readb(eventbuf + 1);
1621 * The two assignments below get the current modem status
1622 * (mstat) and the previous modem status (lstat). These are
1623 * useful becuase an event could signal a change in modem
1626 mstat = readb(eventbuf + 2);
1627 lstat = readb(eventbuf + 3);
1629 ch = chan0 + channel;
1630 if ((unsigned)channel >= bd->numports || !ch) {
1631 if (channel >= bd->numports)
1641 tty = tty_port_tty_get(&ch->port);
1642 if (event & DATA_IND) { /* Begin DATA_IND */
1643 receive_data(ch, tty);
1645 } /* End DATA_IND */
1646 /* else *//* Fix for DCD transition missed bug */
1647 if (event & MODEMCHG_IND) {
1648 /* A modem signal change has been indicated */
1650 if (ch->port.flags & ASYNC_CHECK_CD) {
1651 /* We are now receiving dcd */
1652 if (mstat & ch->dcd)
1653 wake_up_interruptible(&ch->port.open_wait);
1654 else /* No dcd; hangup */
1655 pc_sched_event(ch, EPCA_EVENT_HANGUP);
1659 if (event & BREAK_IND) {
1660 /* A break has been indicated */
1661 tty_insert_flip_char(tty, 0, TTY_BREAK);
1662 tty_schedule_flip(tty);
1663 } else if (event & LOWTX_IND) {
1664 if (ch->statusflags & LOWWAIT) {
1665 ch->statusflags &= ~LOWWAIT;
1668 } else if (event & EMPTYTX_IND) {
1669 /* This event is generated by
1670 setup_empty_event */
1671 ch->statusflags &= ~TXBUSY;
1672 if (ch->statusflags & EMPTYWAIT) {
1673 ch->statusflags &= ~EMPTYWAIT;
1682 writew(1, &bc->idata);
1683 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
1685 } /* End while something in event queue */
1688 static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1689 int byte2, int ncmds, int bytecmd)
1691 unchar __iomem *memaddr;
1692 unsigned int head, cmdTail, cmdStart, cmdMax;
1696 /* This is the routine in which commands may be passed to the card. */
1698 if (ch->board->status == DISABLED)
1701 /* Remember head (As well as max) is just an offset not a base addr */
1702 head = readw(&ch->mailbox->cin);
1703 /* cmdStart is a base address */
1704 cmdStart = readw(&ch->mailbox->cstart);
1706 * We do the addition below because we do not want a max pointer
1707 * relative to cmdStart. We want a max pointer that points at the
1708 * physical end of the command queue.
1710 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
1711 memaddr = ch->board->re_map_membase;
1713 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1714 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n",
1715 __LINE__, cmd, head);
1716 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n",
1717 __LINE__, cmdMax, cmdStart);
1721 writeb(cmd, memaddr + head + cmdStart + 0);
1722 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1723 /* Below word_or_byte is bits to set */
1724 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1725 /* Below byte2 is bits to reset */
1726 writeb(byte2, memaddr + head + cmdStart + 3);
1728 writeb(cmd, memaddr + head + cmdStart + 0);
1729 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1730 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1732 head = (head + 4) & (cmdMax - cmdStart - 4);
1733 writew(head, &ch->mailbox->cin);
1739 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1742 head = readw(&ch->mailbox->cin);
1743 cmdTail = readw(&ch->mailbox->cout);
1744 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
1746 * Basically this will break when the FEP acknowledges the
1747 * command by incrementing cmdTail (Making it equal to head).
1749 if (n <= ncmds * (sizeof(short) * 4))
1755 * Digi products use fields in their channels structures that are very similar
1756 * to the c_cflag and c_iflag fields typically found in UNIX termios
1757 * structures. The below three routines allow mappings between these hardware
1758 * "flags" and their respective Linux flags.
1760 static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
1764 if (cflag & CRTSCTS) {
1765 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1766 res |= ((ch->m_cts) | (ch->m_rts));
1769 if (ch->digiext.digi_flags & RTSPACE)
1772 if (ch->digiext.digi_flags & DTRPACE)
1775 if (ch->digiext.digi_flags & CTSPACE)
1778 if (ch->digiext.digi_flags & DSRPACE)
1781 if (ch->digiext.digi_flags & DCDPACE)
1784 if (res & (ch->m_rts))
1785 ch->digiext.digi_flags |= RTSPACE;
1787 if (res & (ch->m_cts))
1788 ch->digiext.digi_flags |= CTSPACE;
1793 static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
1795 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
1796 INPCK | ISTRIP | IXON | IXANY | IXOFF);
1797 if (ch->digiext.digi_flags & DIGI_AIXON)
1802 static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
1805 if (cflag & CBAUDEX) {
1806 ch->digiext.digi_flags |= DIGI_FAST;
1808 * HUPCL bit is used by FEP to indicate fast baud table is to
1813 ch->digiext.digi_flags &= ~DIGI_FAST;
1815 * CBAUD has bit position 0x1000 set these days to indicate Linux
1816 * baud rate remap. Digi hardware can't handle the bit assignment.
1817 * (We use a different bit assignment for high speed.). Clear this
1820 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
1822 * This gets a little confusing. The Digi cards have their own
1823 * representation of c_cflags controlling baud rate. For the most part
1824 * this is identical to the Linux implementation. However; Digi
1825 * supports one rate (76800) that Linux doesn't. This means that the
1826 * c_cflag entry that would normally mean 76800 for Digi actually means
1827 * 115200 under Linux. Without the below mapping, a stty 115200 would
1828 * only drive the board at 76800. Since the rate 230400 is also found
1829 * after 76800, the same problem afflicts us when we choose a rate of
1830 * 230400. Without the below modificiation stty 230400 would actually
1833 * There are two additional differences. The Linux value for CLOCAL
1834 * (0x800; 0004000) has no meaning to the Digi hardware. Also in later
1835 * releases of Linux; the CBAUD define has CBAUDEX (0x1000; 0010000)
1836 * ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX should be
1837 * checked for a screened out prior to termios2digi_c returning. Since
1838 * CLOCAL isn't used by the board this can be ignored as long as the
1839 * returned value is used only by Digi hardware.
1841 if (cflag & CBAUDEX) {
1843 * The below code is trying to guarantee that only baud rates
1844 * 115200 and 230400 are remapped. We use exclusive or because
1845 * the various baud rates share common bit positions and
1846 * therefore can't be tested for easily.
1848 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
1849 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
1855 /* Caller must hold the locks */
1856 static void epcaparam(struct tty_struct *tty, struct channel *ch)
1858 unsigned int cmdHead;
1859 struct ktermios *ts;
1860 struct board_chan __iomem *bc;
1861 unsigned mval, hflow, cflag, iflag;
1864 epcaassert(bc != NULL, "bc out of range");
1868 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
1869 cmdHead = readw(&bc->rin);
1870 writew(cmdHead, &bc->rout);
1871 cmdHead = readw(&bc->tin);
1872 /* Changing baud in mid-stream transmission can be wonderful */
1874 * Flush current transmit buffer by setting cmdTail pointer
1875 * (tout) to cmdHead pointer (tin). Hopefully the transmit
1878 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
1880 } else { /* Begin CBAUD not detected */
1882 * c_cflags have changed but that change had nothing to do with
1883 * BAUD. Propagate the change to the card.
1885 cflag = termios2digi_c(ch, ts->c_cflag);
1886 if (cflag != ch->fepcflag) {
1887 ch->fepcflag = cflag;
1888 /* Set baud rate, char size, stop bits, parity */
1889 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
1892 * If the user has not forced CLOCAL and if the device is not a
1893 * CALLOUT device (Which is always CLOCAL) we set flags such
1894 * that the driver will wait on carrier detect.
1896 if (ts->c_cflag & CLOCAL)
1897 ch->port.flags &= ~ASYNC_CHECK_CD;
1899 ch->port.flags |= ASYNC_CHECK_CD;
1900 mval = ch->m_dtr | ch->m_rts;
1901 } /* End CBAUD not detected */
1902 iflag = termios2digi_i(ch, ts->c_iflag);
1903 /* Check input mode flags */
1904 if (iflag != ch->fepiflag) {
1905 ch->fepiflag = iflag;
1907 * Command sets channels iflag structure on the board. Such
1908 * things as input soft flow control, handling of parity
1909 * errors, and break handling are all set here.
1911 * break handling, parity handling, input stripping,
1912 * flow control chars
1914 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
1917 * Set the board mint value for this channel. This will cause hardware
1918 * events to be generated each time the DCD signal (Described in mint)
1921 writeb(ch->dcd, &bc->mint);
1922 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
1923 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
1924 writeb(0, &bc->mint);
1925 ch->imodem = readb(&bc->mstat);
1926 hflow = termios2digi_h(ch, ts->c_cflag);
1927 if (hflow != ch->hflow) {
1930 * Hard flow control has been selected but the board is not
1931 * using it. Activate hard flow control now.
1933 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
1935 mval ^= ch->modemfake & (mval ^ ch->modem);
1937 if (ch->omodem ^ mval) {
1940 * The below command sets the DTR and RTS mstat structure. If
1941 * hard flow control is NOT active these changes will drive the
1942 * output of the actual DTR and RTS lines. If hard flow control
1943 * is active, the changes will be saved in the mstat structure
1944 * and only asserted when hard flow control is turned off.
1947 /* First reset DTR & RTS; then set them */
1948 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
1949 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
1951 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
1952 ch->fepstartc = ch->startc;
1953 ch->fepstopc = ch->stopc;
1955 * The XON / XOFF characters have changed; propagate these
1956 * changes to the card.
1958 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
1960 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
1961 ch->fepstartca = ch->startca;
1962 ch->fepstopca = ch->stopca;
1964 * Similar to the above, this time the auxilarly XON / XOFF
1965 * characters have changed; propagate these changes to the card.
1967 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
1971 /* Caller holds lock */
1972 static void receive_data(struct channel *ch, struct tty_struct *tty)
1975 struct ktermios *ts = NULL;
1976 struct board_chan __iomem *bc;
1977 int dataToRead, wrapgap, bytesAvailable;
1978 unsigned int tail, head;
1979 unsigned int wrapmask;
1982 * This routine is called by doint when a receive data event has taken
1986 if (ch->statusflags & RXSTOPPED)
1992 wrapmask = ch->rxbufsize - 1;
1995 * Get the head and tail pointers to the receiver queue. Wrap the head
1996 * pointer if it has reached the end of the buffer.
1998 head = readw(&bc->rin);
2000 tail = readw(&bc->rout) & wrapmask;
2002 bytesAvailable = (head - tail) & wrapmask;
2003 if (bytesAvailable == 0)
2006 /* If CREAD bit is off or device not open, set TX tail to head */
2007 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
2008 writew(head, &bc->rout);
2012 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
2015 if (readb(&bc->orun)) {
2016 writeb(0, &bc->orun);
2017 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",
2019 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
2022 while (bytesAvailable > 0) {
2023 /* Begin while there is data on the card */
2024 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
2026 * Even if head has wrapped around only report the amount of
2027 * data to be equal to the size - tail. Remember memcpy can't
2028 * automaticly wrap around the receive buffer.
2030 dataToRead = (wrapgap < bytesAvailable) ? wrapgap
2032 /* Make sure we don't overflow the buffer */
2033 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
2034 if (dataToRead == 0)
2037 * Move data read from our card into the line disciplines
2038 * buffer for translation if necessary.
2040 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
2041 tail = (tail + dataToRead) & wrapmask;
2042 bytesAvailable -= dataToRead;
2043 } /* End while there is data on the card */
2045 writew(tail, &bc->rout);
2046 /* Must be called with global data */
2047 tty_schedule_flip(tty);
2050 static int info_ioctl(struct tty_struct *tty, struct file *file,
2051 unsigned int cmd, unsigned long arg)
2056 struct digi_info di;
2059 if (get_user(brd, (unsigned int __user *)arg))
2061 if (brd < 0 || brd >= num_cards || num_cards == 0)
2064 memset(&di, 0, sizeof(di));
2067 di.status = boards[brd].status;
2068 di.type = boards[brd].type ;
2069 di.numports = boards[brd].numports ;
2070 /* Legacy fixups - just move along nothing to see */
2071 di.port = (unsigned char *)boards[brd].port ;
2072 di.membase = (unsigned char *)boards[brd].membase ;
2074 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
2082 int brd = arg & 0xff000000 >> 16;
2083 unsigned char state = arg & 0xff;
2085 if (brd < 0 || brd >= num_cards) {
2086 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
2089 digi_poller_inhibited = state;
2096 * This call is made by the apps to complete the
2097 * initialization of the board(s). This routine is
2098 * responsible for setting the card to its initial
2099 * state and setting the drivers control fields to the
2100 * sutianle settings for the card in question.
2103 for (crd = 0; crd < num_cards; crd++)
2113 static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2115 struct channel *ch = tty->driver_data;
2116 struct board_chan __iomem *bc;
2117 unsigned int mstat, mflag = 0;
2118 unsigned long flags;
2125 spin_lock_irqsave(&epca_lock, flags);
2127 mstat = readb(&bc->mstat);
2129 spin_unlock_irqrestore(&epca_lock, flags);
2131 if (mstat & ch->m_dtr)
2133 if (mstat & ch->m_rts)
2135 if (mstat & ch->m_cts)
2137 if (mstat & ch->dsr)
2139 if (mstat & ch->m_ri)
2141 if (mstat & ch->dcd)
2146 static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2147 unsigned int set, unsigned int clear)
2149 struct channel *ch = tty->driver_data;
2150 unsigned long flags;
2155 spin_lock_irqsave(&epca_lock, flags);
2157 * I think this modemfake stuff is broken. It doesn't correctly reflect
2158 * the behaviour desired by the TIOCM* ioctls. Therefore this is
2161 if (set & TIOCM_RTS) {
2162 ch->modemfake |= ch->m_rts;
2163 ch->modem |= ch->m_rts;
2165 if (set & TIOCM_DTR) {
2166 ch->modemfake |= ch->m_dtr;
2167 ch->modem |= ch->m_dtr;
2169 if (clear & TIOCM_RTS) {
2170 ch->modemfake |= ch->m_rts;
2171 ch->modem &= ~ch->m_rts;
2173 if (clear & TIOCM_DTR) {
2174 ch->modemfake |= ch->m_dtr;
2175 ch->modem &= ~ch->m_dtr;
2179 * The below routine generally sets up parity, baud, flow control
2180 * issues, etc.... It effect both control flags and input flags.
2184 spin_unlock_irqrestore(&epca_lock, flags);
2188 static int pc_ioctl(struct tty_struct *tty, struct file *file,
2189 unsigned int cmd, unsigned long arg)
2192 unsigned long flags;
2193 unsigned int mflag, mstat;
2194 unsigned char startc, stopc;
2195 struct board_chan __iomem *bc;
2196 struct channel *ch = tty->driver_data;
2197 void __user *argp = (void __user *)arg;
2205 mflag = pc_tiocmget(tty, file);
2206 if (put_user(mflag, (unsigned long __user *)argp))
2210 if (get_user(mstat, (unsigned __user *)argp))
2212 return pc_tiocmset(tty, file, mstat, ~mstat);
2214 spin_lock_irqsave(&epca_lock, flags);
2215 ch->omodem |= ch->m_dtr;
2217 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2219 spin_unlock_irqrestore(&epca_lock, flags);
2223 spin_lock_irqsave(&epca_lock, flags);
2224 ch->omodem &= ~ch->m_dtr;
2226 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2228 spin_unlock_irqrestore(&epca_lock, flags);
2231 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2237 if (cmd == DIGI_SETAW) {
2238 /* Setup an event to indicate when the transmit
2240 spin_lock_irqsave(&epca_lock, flags);
2241 setup_empty_event(tty, ch);
2242 spin_unlock_irqrestore(&epca_lock, flags);
2243 tty_wait_until_sent(tty, 0);
2245 /* ldisc lock already held in ioctl */
2246 if (tty->ldisc.ops->flush_buffer)
2247 tty->ldisc.ops->flush_buffer(tty);
2252 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2255 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
2256 ch->dcd = ch->m_dsr;
2257 ch->dsr = ch->m_dcd;
2259 ch->dcd = ch->m_dcd;
2260 ch->dsr = ch->m_dsr;
2263 spin_lock_irqsave(&epca_lock, flags);
2267 * The below routine generally sets up parity, baud, flow
2268 * control issues, etc.... It effect both control flags and
2273 spin_unlock_irqrestore(&epca_lock, flags);
2278 spin_lock_irqsave(&epca_lock, flags);
2280 if (cmd == DIGI_GETFLOW) {
2281 dflow.startc = readb(&bc->startc);
2282 dflow.stopc = readb(&bc->stopc);
2284 dflow.startc = readb(&bc->startca);
2285 dflow.stopc = readb(&bc->stopca);
2288 spin_unlock_irqrestore(&epca_lock, flags);
2290 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2296 if (cmd == DIGI_SETFLOW) {
2297 startc = ch->startc;
2300 startc = ch->startca;
2304 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2307 if (dflow.startc != startc || dflow.stopc != stopc) {
2308 /* Begin if setflow toggled */
2309 spin_lock_irqsave(&epca_lock, flags);
2312 if (cmd == DIGI_SETFLOW) {
2313 ch->fepstartc = ch->startc = dflow.startc;
2314 ch->fepstopc = ch->stopc = dflow.stopc;
2315 fepcmd(ch, SONOFFC, ch->fepstartc,
2316 ch->fepstopc, 0, 1);
2318 ch->fepstartca = ch->startca = dflow.startc;
2319 ch->fepstopca = ch->stopca = dflow.stopc;
2320 fepcmd(ch, SAUXONOFFC, ch->fepstartca,
2321 ch->fepstopca, 0, 1);
2324 if (ch->statusflags & TXSTOPPED)
2328 spin_unlock_irqrestore(&epca_lock, flags);
2329 } /* End if setflow toggled */
2332 return -ENOIOCTLCMD;
2337 static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2340 unsigned long flags;
2342 * verifyChannel returns the channel from the tty struct if it is
2343 * valid. This serves as a sanity check.
2345 ch = verifyChannel(tty);
2347 if (ch != NULL) { /* Begin if channel valid */
2348 spin_lock_irqsave(&epca_lock, flags);
2352 spin_unlock_irqrestore(&epca_lock, flags);
2354 if ((old_termios->c_cflag & CRTSCTS) &&
2355 ((tty->termios->c_cflag & CRTSCTS) == 0))
2356 tty->hw_stopped = 0;
2358 if (!(old_termios->c_cflag & CLOCAL) &&
2359 (tty->termios->c_cflag & CLOCAL))
2360 wake_up_interruptible(&ch->port.open_wait);
2362 } /* End if channel valid */
2365 static void do_softint(struct work_struct *work)
2367 struct channel *ch = container_of(work, struct channel, tqueue);
2368 /* Called in response to a modem change event */
2369 if (ch && ch->magic == EPCA_MAGIC) {
2370 struct tty_struct *tty = tty_port_tty_get(&ch->port);;
2372 if (tty && tty->driver_data) {
2373 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) {
2375 wake_up_interruptible(&ch->port.open_wait);
2376 ch->port.flags &= ~ASYNC_NORMAL_ACTIVE;
2384 * pc_stop and pc_start provide software flow control to the routine and the
2387 static void pc_stop(struct tty_struct *tty)
2390 unsigned long flags;
2392 * verifyChannel returns the channel from the tty struct if it is
2393 * valid. This serves as a sanity check.
2395 ch = verifyChannel(tty);
2397 spin_lock_irqsave(&epca_lock, flags);
2398 if ((ch->statusflags & TXSTOPPED) == 0) {
2399 /* Begin if transmit stop requested */
2401 /* STOP transmitting now !! */
2402 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
2403 ch->statusflags |= TXSTOPPED;
2405 } /* End if transmit stop requested */
2406 spin_unlock_irqrestore(&epca_lock, flags);
2410 static void pc_start(struct tty_struct *tty)
2414 * verifyChannel returns the channel from the tty struct if it is
2415 * valid. This serves as a sanity check.
2417 ch = verifyChannel(tty);
2419 unsigned long flags;
2420 spin_lock_irqsave(&epca_lock, flags);
2421 /* Just in case output was resumed because of a change
2423 if (ch->statusflags & TXSTOPPED) {
2424 /* Begin transmit resume requested */
2425 struct board_chan __iomem *bc;
2428 if (ch->statusflags & LOWWAIT)
2429 writeb(1, &bc->ilow);
2430 /* Okay, you can start transmitting again... */
2431 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
2432 ch->statusflags &= ~TXSTOPPED;
2434 } /* End transmit resume requested */
2435 spin_unlock_irqrestore(&epca_lock, flags);
2440 * The below routines pc_throttle and pc_unthrottle are used to slow (And
2441 * resume) the receipt of data into the kernels receive buffers. The exact
2442 * occurrence of this depends on the size of the kernels receive buffer and
2443 * what the 'watermarks' are set to for that buffer. See the n_ttys.c file for
2446 static void pc_throttle(struct tty_struct *tty)
2449 unsigned long flags;
2451 * verifyChannel returns the channel from the tty struct if it is
2452 * valid. This serves as a sanity check.
2454 ch = verifyChannel(tty);
2456 spin_lock_irqsave(&epca_lock, flags);
2457 if ((ch->statusflags & RXSTOPPED) == 0) {
2459 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
2460 ch->statusflags |= RXSTOPPED;
2463 spin_unlock_irqrestore(&epca_lock, flags);
2467 static void pc_unthrottle(struct tty_struct *tty)
2470 unsigned long flags;
2472 * verifyChannel returns the channel from the tty struct if it is
2473 * valid. This serves as a sanity check.
2475 ch = verifyChannel(tty);
2477 /* Just in case output was resumed because of a change
2479 spin_lock_irqsave(&epca_lock, flags);
2480 if (ch->statusflags & RXSTOPPED) {
2482 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
2483 ch->statusflags &= ~RXSTOPPED;
2486 spin_unlock_irqrestore(&epca_lock, flags);
2490 static int pc_send_break(struct tty_struct *tty, int msec)
2492 struct channel *ch = tty->driver_data;
2493 unsigned long flags;
2497 else if (msec > 0xFFFE)
2502 spin_lock_irqsave(&epca_lock, flags);
2505 * Maybe I should send an infinite break here, schedule() for msec
2506 * amount of time, and then stop the break. This way, the user can't
2507 * screw up the FEP by causing digi_send_break() to be called (i.e. via
2508 * an ioctl()) more than once in msec amount of time.
2509 * Try this for now...
2511 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2513 spin_unlock_irqrestore(&epca_lock, flags);
2517 /* Caller MUST hold the lock */
2518 static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2520 struct board_chan __iomem *bc = ch->brdchan;
2523 ch->statusflags |= EMPTYWAIT;
2525 * When set the iempty flag request a event to be generated when the
2526 * transmit buffer is empty (If there is no BREAK in progress).
2528 writeb(1, &bc->iempty);
2533 static void __init epca_setup(char *str, int *ints)
2535 struct board_info board;
2536 int index, loop, last;
2541 * If this routine looks a little strange it is because it is only
2542 * called if a LILO append command is given to boot the kernel with
2543 * parameters. In this way, we can provide the user a method of
2544 * changing his board configuration without rebuilding the kernel.
2549 memset(&board, 0, sizeof(board));
2551 /* Assume the data is int first, later we can change it */
2552 /* I think that array position 0 of ints holds the number of args */
2553 for (last = 0, index = 1; index <= ints[0]; index++)
2554 switch (index) { /* Begin parse switch */
2556 board.status = ints[index];
2558 * We check for 2 (As opposed to 1; because 2 is a flag
2559 * instructing the driver to ignore epcaconfig.) For
2560 * this reason we check for 2.
2562 if (board.status == 2) {
2563 /* Begin ignore epcaconfig as well as lilo cmd line */
2567 } /* End ignore epcaconfig as well as lilo cmd line */
2569 if (board.status > 2) {
2570 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n",
2572 invalid_lilo_config = 1;
2573 setup_error_code |= INVALID_BOARD_STATUS;
2579 board.type = ints[index];
2580 if (board.type >= PCIXEM) {
2581 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
2582 invalid_lilo_config = 1;
2583 setup_error_code |= INVALID_BOARD_TYPE;
2589 board.altpin = ints[index];
2590 if (board.altpin > 1) {
2591 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
2592 invalid_lilo_config = 1;
2593 setup_error_code |= INVALID_ALTPIN;
2600 board.numports = ints[index];
2601 if (board.numports < 2 || board.numports > 256) {
2602 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
2603 invalid_lilo_config = 1;
2604 setup_error_code |= INVALID_NUM_PORTS;
2607 nbdevs += board.numports;
2612 board.port = ints[index];
2613 if (ints[index] <= 0) {
2614 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
2615 invalid_lilo_config = 1;
2616 setup_error_code |= INVALID_PORT_BASE;
2623 board.membase = ints[index];
2624 if (ints[index] <= 0) {
2625 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",
2626 (unsigned int)board.membase);
2627 invalid_lilo_config = 1;
2628 setup_error_code |= INVALID_MEM_BASE;
2635 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
2638 } /* End parse switch */
2640 while (str && *str) { /* Begin while there is a string arg */
2641 /* find the next comma or terminator */
2643 /* While string is not null, and a comma hasn't been found */
2644 while (*temp && (*temp != ','))
2650 /* Set index to the number of args + 1 */
2656 if (strncmp("Disable", str, len) == 0)
2658 else if (strncmp("Enable", str, len) == 0)
2661 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
2662 invalid_lilo_config = 1;
2663 setup_error_code |= INVALID_BOARD_STATUS;
2670 for (loop = 0; loop < EPCA_NUM_TYPES; loop++)
2671 if (strcmp(board_desc[loop], str) == 0)
2674 * If the index incremented above refers to a
2675 * legitamate board type set it here.
2677 if (index < EPCA_NUM_TYPES)
2680 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
2681 invalid_lilo_config = 1;
2682 setup_error_code |= INVALID_BOARD_TYPE;
2690 if (strncmp("Disable", str, len) == 0)
2692 else if (strncmp("Enable", str, len) == 0)
2695 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
2696 invalid_lilo_config = 1;
2697 setup_error_code |= INVALID_ALTPIN;
2705 while (isdigit(*t2))
2709 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
2710 invalid_lilo_config = 1;
2711 setup_error_code |= INVALID_NUM_PORTS;
2716 * There is not a man page for simple_strtoul but the
2717 * code can be found in vsprintf.c. The first argument
2718 * is the string to translate (To an unsigned long
2719 * obviously), the second argument can be the address
2720 * of any character variable or a NULL. If a variable
2721 * is given, the end pointer of the string will be
2722 * stored in that variable; if a NULL is given the end
2723 * pointer will not be returned. The last argument is
2724 * the base to use. If a 0 is indicated, the routine
2725 * will attempt to determine the proper base by looking
2726 * at the values prefix (A '0' for octal, a 'x' for
2727 * hex, etc ... If a value is given it will use that
2728 * value as the base.
2730 board.numports = simple_strtoul(str, NULL, 0);
2731 nbdevs += board.numports;
2737 while (isxdigit(*t2))
2741 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
2742 invalid_lilo_config = 1;
2743 setup_error_code |= INVALID_PORT_BASE;
2747 board.port = simple_strtoul(str, NULL, 16);
2753 while (isxdigit(*t2))
2757 printk(KERN_ERR "epca_setup: Invalid memory base %s\n", str);
2758 invalid_lilo_config = 1;
2759 setup_error_code |= INVALID_MEM_BASE;
2762 board.membase = simple_strtoul(str, NULL, 16);
2766 printk(KERN_ERR "epca: Too many string parms\n");
2770 } /* End while there is a string arg */
2773 printk(KERN_ERR "epca: Insufficient parms specified\n");
2777 /* I should REALLY validate the stuff here */
2778 /* Copies our local copy of board into boards */
2779 memcpy((void *)&boards[num_cards], (void *)&board, sizeof(board));
2780 /* Does this get called once per lilo arg are what ? */
2781 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2782 num_cards, board_desc[board.type],
2783 board.numports, (int)board.port, (unsigned int) board.membase);
2787 static int __init epca_real_setup(char *str)
2791 epca_setup(get_options(str, 11, ints), ints);
2795 __setup("digiepca", epca_real_setup);
2798 enum epic_board_types {
2805 /* indexed directly by epic_board_types enum */
2807 unsigned char board_type;
2808 unsigned bar_idx; /* PCI base address region */
2809 } epca_info_tbl[] = {
2816 static int __devinit epca_init_one(struct pci_dev *pdev,
2817 const struct pci_device_id *ent)
2819 static int board_num = -1;
2820 int board_idx, info_idx = ent->driver_data;
2823 if (pci_enable_device(pdev))
2827 board_idx = board_num + num_cards;
2828 if (board_idx >= MAXBOARDS)
2831 addr = pci_resource_start(pdev, epca_info_tbl[info_idx].bar_idx);
2833 printk(KERN_ERR PFX "PCI region #%d not available (size 0)\n",
2834 epca_info_tbl[info_idx].bar_idx);
2838 boards[board_idx].status = ENABLED;
2839 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
2840 boards[board_idx].numports = 0x0;
2841 boards[board_idx].port = addr + PCI_IO_OFFSET;
2842 boards[board_idx].membase = addr;
2844 if (!request_mem_region(addr + PCI_IO_OFFSET, 0x200000, "epca")) {
2845 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2846 0x200000, addr + PCI_IO_OFFSET);
2850 boards[board_idx].re_map_port = ioremap_nocache(addr + PCI_IO_OFFSET,
2852 if (!boards[board_idx].re_map_port) {
2853 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2854 0x200000, addr + PCI_IO_OFFSET);
2855 goto err_out_free_pciio;
2858 if (!request_mem_region(addr, 0x200000, "epca")) {
2859 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2861 goto err_out_free_iounmap;
2864 boards[board_idx].re_map_membase = ioremap_nocache(addr, 0x200000);
2865 if (!boards[board_idx].re_map_membase) {
2866 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2867 0x200000, addr + PCI_IO_OFFSET);
2868 goto err_out_free_memregion;
2872 * I don't know what the below does, but the hardware guys say its
2873 * required on everything except PLX (In this case XRJ).
2875 if (info_idx != brd_xrj) {
2876 pci_write_config_byte(pdev, 0x40, 0);
2877 pci_write_config_byte(pdev, 0x46, 0);
2882 err_out_free_memregion:
2883 release_mem_region(addr, 0x200000);
2884 err_out_free_iounmap:
2885 iounmap(boards[board_idx].re_map_port);
2887 release_mem_region(addr + PCI_IO_OFFSET, 0x200000);
2893 static struct pci_device_id epca_pci_tbl[] = {
2894 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
2895 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
2896 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
2897 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
2901 MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
2903 static int __init init_PCI(void)
2905 memset(&epca_driver, 0, sizeof(epca_driver));
2906 epca_driver.name = "epca";
2907 epca_driver.id_table = epca_pci_tbl;
2908 epca_driver.probe = epca_init_one;
2910 return pci_register_driver(&epca_driver);
2913 MODULE_LICENSE("GPL");