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/sched.h>
34 #include <linux/serial.h>
35 #include <linux/delay.h>
36 #include <linux/ctype.h>
37 #include <linux/tty.h>
38 #include <linux/tty_flip.h>
39 #include <linux/slab.h>
40 #include <linux/ioport.h>
41 #include <linux/interrupt.h>
42 #include <linux/uaccess.h>
44 #include <linux/spinlock.h>
45 #include <linux/pci.h>
52 #include "epcaconfig.h"
54 #define VERSION "1.3.0.1-LK2.6"
56 /* This major needs to be submitted to Linux to join the majors list */
57 #define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
61 #define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
65 static int nbdevs, num_cards, liloconfig;
66 static int digi_poller_inhibited = 1 ;
68 static int setup_error_code;
69 static int invalid_lilo_config;
72 * The ISA boards do window flipping into the same spaces so its only sane with
73 * a single lock. It's still pretty efficient. This lock guards the hardware
74 * and the tty_port lock guards the kernel side stuff like use counts. Take
75 * this lock inside the port lock if you must take both.
77 static DEFINE_SPINLOCK(epca_lock);
79 /* MAXBOARDS is typically 12, but ISA and EISA cards are restricted
81 static struct board_info boards[MAXBOARDS];
83 static struct tty_driver *pc_driver;
84 static struct tty_driver *pc_info;
86 /* ------------------ Begin Digi specific structures -------------------- */
89 * digi_channels represents an array of structures that keep track of each
90 * channel of the Digi product. Information such as transmit and receive
91 * pointers, termio data, and signal definitions (DTR, CTS, etc ...) are stored
92 * here. This structure is NOT used to overlay the cards physical channel
95 static struct channel digi_channels[MAX_ALLOC];
98 * card_ptr is an array used to hold the address of the first channel structure
99 * of each card. This array will hold the addresses of various channels located
102 static struct channel *card_ptr[MAXCARDS];
104 static struct timer_list epca_timer;
107 * Begin generic memory functions. These functions will be alias (point at)
108 * more specific functions dependent on the board being configured.
110 static void memwinon(struct board_info *b, unsigned int win);
111 static void memwinoff(struct board_info *b, unsigned int win);
112 static void globalwinon(struct channel *ch);
113 static void rxwinon(struct channel *ch);
114 static void txwinon(struct channel *ch);
115 static void memoff(struct channel *ch);
116 static void assertgwinon(struct channel *ch);
117 static void assertmemoff(struct channel *ch);
119 /* ---- Begin more 'specific' memory functions for cx_like products --- */
121 static void pcxem_memwinon(struct board_info *b, unsigned int win);
122 static void pcxem_memwinoff(struct board_info *b, unsigned int win);
123 static void pcxem_globalwinon(struct channel *ch);
124 static void pcxem_rxwinon(struct channel *ch);
125 static void pcxem_txwinon(struct channel *ch);
126 static void pcxem_memoff(struct channel *ch);
128 /* ------ Begin more 'specific' memory functions for the pcxe ------- */
130 static void pcxe_memwinon(struct board_info *b, unsigned int win);
131 static void pcxe_memwinoff(struct board_info *b, unsigned int win);
132 static void pcxe_globalwinon(struct channel *ch);
133 static void pcxe_rxwinon(struct channel *ch);
134 static void pcxe_txwinon(struct channel *ch);
135 static void pcxe_memoff(struct channel *ch);
137 /* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
138 /* Note : pc64xe and pcxi share the same windowing routines */
140 static void pcxi_memwinon(struct board_info *b, unsigned int win);
141 static void pcxi_memwinoff(struct board_info *b, unsigned int win);
142 static void pcxi_globalwinon(struct channel *ch);
143 static void pcxi_rxwinon(struct channel *ch);
144 static void pcxi_txwinon(struct channel *ch);
145 static void pcxi_memoff(struct channel *ch);
147 /* - Begin 'specific' do nothing memory functions needed for some cards - */
149 static void dummy_memwinon(struct board_info *b, unsigned int win);
150 static void dummy_memwinoff(struct board_info *b, unsigned int win);
151 static void dummy_globalwinon(struct channel *ch);
152 static void dummy_rxwinon(struct channel *ch);
153 static void dummy_txwinon(struct channel *ch);
154 static void dummy_memoff(struct channel *ch);
155 static void dummy_assertgwinon(struct channel *ch);
156 static void dummy_assertmemoff(struct channel *ch);
158 static struct channel *verifyChannel(struct tty_struct *);
159 static void pc_sched_event(struct channel *, int);
160 static void epca_error(int, char *);
161 static void pc_close(struct tty_struct *, struct file *);
162 static void shutdown(struct channel *, struct tty_struct *tty);
163 static void pc_hangup(struct tty_struct *);
164 static int pc_write_room(struct tty_struct *);
165 static int pc_chars_in_buffer(struct tty_struct *);
166 static void pc_flush_buffer(struct tty_struct *);
167 static void pc_flush_chars(struct tty_struct *);
168 static int pc_open(struct tty_struct *, struct file *);
169 static void post_fep_init(unsigned int crd);
170 static void epcapoll(unsigned long);
171 static void doevent(int);
172 static void fepcmd(struct channel *, int, int, int, int, int);
173 static unsigned termios2digi_h(struct channel *ch, unsigned);
174 static unsigned termios2digi_i(struct channel *ch, unsigned);
175 static unsigned termios2digi_c(struct channel *ch, unsigned);
176 static void epcaparam(struct tty_struct *, struct channel *);
177 static void receive_data(struct channel *, struct tty_struct *tty);
178 static int pc_ioctl(struct tty_struct *, struct file *,
179 unsigned int, unsigned long);
180 static int info_ioctl(struct tty_struct *, struct file *,
181 unsigned int, unsigned long);
182 static void pc_set_termios(struct tty_struct *, struct ktermios *);
183 static void do_softint(struct work_struct *work);
184 static void pc_stop(struct tty_struct *);
185 static void pc_start(struct tty_struct *);
186 static void pc_throttle(struct tty_struct *tty);
187 static void pc_unthrottle(struct tty_struct *tty);
188 static int pc_send_break(struct tty_struct *tty, int msec);
189 static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
191 static int pc_write(struct tty_struct *, const unsigned char *, int);
192 static int pc_init(void);
193 static int init_PCI(void);
196 * Table of functions for each board to handle memory. Mantaining parallelism
197 * is a *very* good idea here. The idea is for the runtime code to blindly call
198 * these functions, not knowing/caring about the underlying hardware. This
199 * stuff should contain no conditionals; if more functionality is needed a
200 * different entry should be established. These calls are the interface calls
201 * and are the only functions that should be accessed. Anyone caught making
202 * direct calls deserves what they get.
204 static void memwinon(struct board_info *b, unsigned int win)
209 static void memwinoff(struct board_info *b, unsigned int win)
211 b->memwinoff(b, win);
214 static void globalwinon(struct channel *ch)
216 ch->board->globalwinon(ch);
219 static void rxwinon(struct channel *ch)
221 ch->board->rxwinon(ch);
224 static void txwinon(struct channel *ch)
226 ch->board->txwinon(ch);
229 static void memoff(struct channel *ch)
231 ch->board->memoff(ch);
233 static void assertgwinon(struct channel *ch)
235 ch->board->assertgwinon(ch);
238 static void assertmemoff(struct channel *ch)
240 ch->board->assertmemoff(ch);
243 /* PCXEM windowing is the same as that used in the PCXR and CX series cards. */
244 static void pcxem_memwinon(struct board_info *b, unsigned int win)
246 outb_p(FEPWIN | win, b->port + 1);
249 static void pcxem_memwinoff(struct board_info *b, unsigned int win)
251 outb_p(0, b->port + 1);
254 static void pcxem_globalwinon(struct channel *ch)
256 outb_p(FEPWIN, (int)ch->board->port + 1);
259 static void pcxem_rxwinon(struct channel *ch)
261 outb_p(ch->rxwin, (int)ch->board->port + 1);
264 static void pcxem_txwinon(struct channel *ch)
266 outb_p(ch->txwin, (int)ch->board->port + 1);
269 static void pcxem_memoff(struct channel *ch)
271 outb_p(0, (int)ch->board->port + 1);
274 /* ----------------- Begin pcxe memory window stuff ------------------ */
275 static void pcxe_memwinon(struct board_info *b, unsigned int win)
277 outb_p(FEPWIN | win, b->port + 1);
280 static void pcxe_memwinoff(struct board_info *b, unsigned int win)
282 outb_p(inb(b->port) & ~FEPMEM, b->port + 1);
283 outb_p(0, b->port + 1);
286 static void pcxe_globalwinon(struct channel *ch)
288 outb_p(FEPWIN, (int)ch->board->port + 1);
291 static void pcxe_rxwinon(struct channel *ch)
293 outb_p(ch->rxwin, (int)ch->board->port + 1);
296 static void pcxe_txwinon(struct channel *ch)
298 outb_p(ch->txwin, (int)ch->board->port + 1);
301 static void pcxe_memoff(struct channel *ch)
303 outb_p(0, (int)ch->board->port);
304 outb_p(0, (int)ch->board->port + 1);
307 /* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
308 static void pcxi_memwinon(struct board_info *b, unsigned int win)
310 outb_p(inb(b->port) | FEPMEM, b->port);
313 static void pcxi_memwinoff(struct board_info *b, unsigned int win)
315 outb_p(inb(b->port) & ~FEPMEM, b->port);
318 static void pcxi_globalwinon(struct channel *ch)
320 outb_p(FEPMEM, ch->board->port);
323 static void pcxi_rxwinon(struct channel *ch)
325 outb_p(FEPMEM, ch->board->port);
328 static void pcxi_txwinon(struct channel *ch)
330 outb_p(FEPMEM, ch->board->port);
333 static void pcxi_memoff(struct channel *ch)
335 outb_p(0, ch->board->port);
338 static void pcxi_assertgwinon(struct channel *ch)
340 epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
343 static void pcxi_assertmemoff(struct channel *ch)
345 epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
349 * Not all of the cards need specific memory windowing routines. Some cards
350 * (Such as PCI) needs no windowing routines at all. We provide these do
351 * nothing routines so that the same code base can be used. The driver will
352 * ALWAYS call a windowing routine if it thinks it needs to; regardless of the
353 * card. However, dependent on the card the routine may or may not do anything.
355 static void dummy_memwinon(struct board_info *b, unsigned int win)
359 static void dummy_memwinoff(struct board_info *b, unsigned int win)
363 static void dummy_globalwinon(struct channel *ch)
367 static void dummy_rxwinon(struct channel *ch)
371 static void dummy_txwinon(struct channel *ch)
375 static void dummy_memoff(struct channel *ch)
379 static void dummy_assertgwinon(struct channel *ch)
383 static void dummy_assertmemoff(struct channel *ch)
387 static struct channel *verifyChannel(struct tty_struct *tty)
390 * This routine basically provides a sanity check. It insures that the
391 * channel returned is within the proper range of addresses as well as
392 * properly initialized. If some bogus info gets passed in
393 * through tty->driver_data this should catch it.
396 struct channel *ch = tty->driver_data;
397 if (ch >= &digi_channels[0] && ch < &digi_channels[nbdevs]) {
398 if (ch->magic == EPCA_MAGIC)
405 static void pc_sched_event(struct channel *ch, int event)
408 * We call this to schedule interrupt processing on some event. The
409 * kernel sees our request and calls the related routine in OUR driver.
411 ch->event |= 1 << event;
412 schedule_work(&ch->tqueue);
415 static void epca_error(int line, char *msg)
417 printk(KERN_ERR "epca_error (Digi): line = %d %s\n", line, msg);
420 static void pc_close(struct tty_struct *tty, struct file *filp)
423 struct tty_port *port;
425 * verifyChannel returns the channel from the tty struct if it is
426 * valid. This serves as a sanity check.
428 ch = verifyChannel(tty);
433 if (tty_port_close_start(port, tty, filp) == 0)
436 pc_flush_buffer(tty);
439 tty_port_close_end(port, tty);
440 ch->event = 0; /* FIXME: review ch->event locking */
441 tty_port_tty_set(port, NULL);
444 static void shutdown(struct channel *ch, struct tty_struct *tty)
447 struct board_chan __iomem *bc;
448 struct tty_port *port = &ch->port;
450 if (!(port->flags & ASYNC_INITIALIZED))
453 spin_lock_irqsave(&epca_lock, flags);
459 * In order for an event to be generated on the receipt of data the
460 * idata flag must be set. Since we are shutting down, this is not
461 * necessary clear this flag.
464 writeb(0, &bc->idata);
466 /* If we're a modem control device and HUPCL is on, drop RTS & DTR. */
467 if (tty->termios->c_cflag & HUPCL) {
468 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
469 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
474 * The channel has officialy been closed. The next time it is opened it
475 * will have to reinitialized. Set a flag to indicate this.
477 /* Prevent future Digi programmed interrupts from coming active */
478 port->flags &= ~ASYNC_INITIALIZED;
479 spin_unlock_irqrestore(&epca_lock, flags);
482 static void pc_hangup(struct tty_struct *tty)
487 * verifyChannel returns the channel from the tty struct if it is
488 * valid. This serves as a sanity check.
490 ch = verifyChannel(tty);
492 pc_flush_buffer(tty);
493 tty_ldisc_flush(tty);
496 ch->event = 0; /* FIXME: review locking of ch->event */
497 tty_port_hangup(&ch->port);
501 static int pc_write(struct tty_struct *tty,
502 const unsigned char *buf, int bytesAvailable)
504 unsigned int head, tail;
511 struct board_chan __iomem *bc;
514 * pc_write is primarily called directly by the kernel routine
515 * tty_write (Though it can also be called by put_char) found in
516 * tty_io.c. pc_write is passed a line discipline buffer where the data
517 * to be written out is stored. The line discipline implementation
518 * itself is done at the kernel level and is not brought into the
523 * verifyChannel returns the channel from the tty struct if it is
524 * valid. This serves as a sanity check.
526 ch = verifyChannel(tty);
530 /* Make a pointer to the channel data structure found on the board. */
532 size = ch->txbufsize;
535 spin_lock_irqsave(&epca_lock, flags);
538 head = readw(&bc->tin) & (size - 1);
539 tail = readw(&bc->tout);
541 if (tail != readw(&bc->tout))
542 tail = readw(&bc->tout);
546 /* head has not wrapped */
548 * remain (much like dataLen above) represents the total amount
549 * of space available on the card for data. Here dataLen
550 * represents the space existing between the head pointer and
551 * the end of buffer. This is important because a memcpy cannot
552 * be told to automatically wrap around when it hits the buffer
555 dataLen = size - head;
556 remain = size - (head - tail) - 1;
558 /* head has wrapped around */
559 remain = tail - head - 1;
563 * Check the space on the card. If we have more data than space; reduce
564 * the amount of data to fit the space.
566 bytesAvailable = min(remain, bytesAvailable);
568 while (bytesAvailable > 0) {
569 /* there is data to copy onto card */
572 * If head is not wrapped, the below will make sure the first
573 * data copy fills to the end of card buffer.
575 dataLen = min(bytesAvailable, dataLen);
576 memcpy_toio(ch->txptr + head, buf, dataLen);
579 amountCopied += dataLen;
580 bytesAvailable -= dataLen;
587 ch->statusflags |= TXBUSY;
589 writew(head, &bc->tin);
591 if ((ch->statusflags & LOWWAIT) == 0) {
592 ch->statusflags |= LOWWAIT;
593 writeb(1, &bc->ilow);
596 spin_unlock_irqrestore(&epca_lock, flags);
600 static int pc_write_room(struct tty_struct *tty)
605 unsigned int head, tail;
606 struct board_chan __iomem *bc;
608 * verifyChannel returns the channel from the tty struct if it is
609 * valid. This serves as a sanity check.
611 ch = verifyChannel(tty);
613 spin_lock_irqsave(&epca_lock, flags);
617 head = readw(&bc->tin) & (ch->txbufsize - 1);
618 tail = readw(&bc->tout);
620 if (tail != readw(&bc->tout))
621 tail = readw(&bc->tout);
622 /* Wrap tail if necessary */
623 tail &= (ch->txbufsize - 1);
624 remain = tail - head - 1;
626 remain += ch->txbufsize;
628 if (remain && (ch->statusflags & LOWWAIT) == 0) {
629 ch->statusflags |= LOWWAIT;
630 writeb(1, &bc->ilow);
633 spin_unlock_irqrestore(&epca_lock, flags);
635 /* Return how much room is left on card */
639 static int pc_chars_in_buffer(struct tty_struct *tty)
642 unsigned int ctail, head, tail;
646 struct board_chan __iomem *bc;
648 * verifyChannel returns the channel from the tty struct if it is
649 * valid. This serves as a sanity check.
651 ch = verifyChannel(tty);
655 spin_lock_irqsave(&epca_lock, flags);
659 tail = readw(&bc->tout);
660 head = readw(&bc->tin);
661 ctail = readw(&ch->mailbox->cout);
663 if (tail == head && readw(&ch->mailbox->cin) == ctail &&
664 readb(&bc->tbusy) == 0)
666 else { /* Begin if some space on the card has been used */
667 head = readw(&bc->tin) & (ch->txbufsize - 1);
668 tail &= (ch->txbufsize - 1);
670 * The logic here is basically opposite of the above
671 * pc_write_room here we are finding the amount of bytes in the
672 * buffer filled. Not the amount of bytes empty.
674 remain = tail - head - 1;
676 remain += ch->txbufsize;
677 chars = (int)(ch->txbufsize - remain);
679 * Make it possible to wakeup anything waiting for output in
682 * If not already set. Setup an event to indicate when the
683 * transmit buffer empties.
685 if (!(ch->statusflags & EMPTYWAIT))
686 setup_empty_event(tty, ch);
687 } /* End if some space on the card has been used */
689 spin_unlock_irqrestore(&epca_lock, flags);
690 /* Return number of characters residing on card. */
694 static void pc_flush_buffer(struct tty_struct *tty)
699 struct board_chan __iomem *bc;
701 * verifyChannel returns the channel from the tty struct if it is
702 * valid. This serves as a sanity check.
704 ch = verifyChannel(tty);
708 spin_lock_irqsave(&epca_lock, flags);
711 tail = readw(&bc->tout);
712 /* Have FEP move tout pointer; effectively flushing transmit buffer */
713 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
715 spin_unlock_irqrestore(&epca_lock, flags);
719 static void pc_flush_chars(struct tty_struct *tty)
723 * verifyChannel returns the channel from the tty struct if it is
724 * valid. This serves as a sanity check.
726 ch = verifyChannel(tty);
729 spin_lock_irqsave(&epca_lock, flags);
731 * If not already set and the transmitter is busy setup an
732 * event to indicate when the transmit empties.
734 if ((ch->statusflags & TXBUSY) &&
735 !(ch->statusflags & EMPTYWAIT))
736 setup_empty_event(tty, ch);
737 spin_unlock_irqrestore(&epca_lock, flags);
741 static int epca_carrier_raised(struct tty_port *port)
743 struct channel *ch = container_of(port, struct channel, port);
744 if (ch->imodem & ch->dcd)
749 static void epca_dtr_rts(struct tty_port *port, int onoff)
753 static int pc_open(struct tty_struct *tty, struct file *filp)
756 struct tty_port *port;
758 int line, retval, boardnum;
759 struct board_chan __iomem *bc;
763 if (line < 0 || line >= nbdevs)
766 ch = &digi_channels[line];
768 boardnum = ch->boardnum;
770 /* Check status of board configured in system. */
773 * I check to see if the epca_setup routine detected a user error. It
774 * might be better to put this in pc_init, but for the moment it goes
777 if (invalid_lilo_config) {
778 if (setup_error_code & INVALID_BOARD_TYPE)
779 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
780 if (setup_error_code & INVALID_NUM_PORTS)
781 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
782 if (setup_error_code & INVALID_MEM_BASE)
783 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
784 if (setup_error_code & INVALID_PORT_BASE)
785 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
786 if (setup_error_code & INVALID_BOARD_STATUS)
787 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
788 if (setup_error_code & INVALID_ALTPIN)
789 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
790 tty->driver_data = NULL; /* Mark this device as 'down' */
793 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
794 tty->driver_data = NULL; /* Mark this device as 'down' */
800 tty->driver_data = NULL;
804 spin_lock_irqsave(&port->lock, flags);
806 * Every time a channel is opened, increment a counter. This is
807 * necessary because we do not wish to flush and shutdown the channel
808 * until the last app holding the channel open, closes it.
812 * Set a kernel structures pointer to our local channel structure. This
813 * way we can get to it when passed only a tty struct.
815 tty->driver_data = ch;
818 * If this is the first time the channel has been opened, initialize
819 * the tty->termios struct otherwise let pc_close handle it.
821 spin_lock(&epca_lock);
825 /* Save boards current modem status */
826 ch->imodem = readb(&bc->mstat);
829 * Set receive head and tail ptrs to each other. This indicates no data
832 head = readw(&bc->rin);
833 writew(head, &bc->rout);
835 /* Set the channels associated tty structure */
838 * The below routine generally sets up parity, baud, flow control
839 * issues, etc.... It effect both control flags and input flags.
843 spin_unlock(&epca_lock);
844 port->flags |= ASYNC_INITIALIZED;
845 spin_unlock_irqrestore(&port->lock, flags);
847 retval = tty_port_block_til_ready(port, tty, filp);
851 * Set this again in case a hangup set it to zero while this open() was
852 * waiting for the line...
854 spin_lock_irqsave(&port->lock, flags);
856 spin_lock(&epca_lock);
858 /* Enable Digi Data events */
859 writeb(1, &bc->idata);
861 spin_unlock(&epca_lock);
862 spin_unlock_irqrestore(&port->lock, flags);
866 static int __init epca_module_init(void)
870 module_init(epca_module_init);
872 static struct pci_driver epca_driver;
874 static void __exit epca_module_exit(void)
877 struct board_info *bd;
880 del_timer_sync(&epca_timer);
882 if (tty_unregister_driver(pc_driver) ||
883 tty_unregister_driver(pc_info)) {
884 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
887 put_tty_driver(pc_driver);
888 put_tty_driver(pc_info);
890 for (crd = 0; crd < num_cards; crd++) {
892 if (!bd) { /* sanity check */
893 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
897 for (count = 0; count < bd->numports; count++, ch++) {
898 struct tty_struct *tty = tty_port_tty_get(&ch->port);
905 pci_unregister_driver(&epca_driver);
907 module_exit(epca_module_exit);
909 static const struct tty_operations pc_ops = {
913 .write_room = pc_write_room,
914 .flush_buffer = pc_flush_buffer,
915 .chars_in_buffer = pc_chars_in_buffer,
916 .flush_chars = pc_flush_chars,
918 .set_termios = pc_set_termios,
921 .throttle = pc_throttle,
922 .unthrottle = pc_unthrottle,
924 .break_ctl = pc_send_break
927 static const struct tty_port_operations epca_port_ops = {
928 .carrier_raised = epca_carrier_raised,
929 .dtr_rts = epca_dtr_rts,
932 static int info_open(struct tty_struct *tty, struct file *filp)
937 static const struct tty_operations info_ops = {
942 static int __init pc_init(void)
945 struct board_info *bd;
946 unsigned char board_id = 0;
949 int pci_boards_found, pci_count;
953 pc_driver = alloc_tty_driver(MAX_ALLOC);
957 pc_info = alloc_tty_driver(MAX_ALLOC);
962 * If epca_setup has not been ran by LILO set num_cards to defaults;
963 * copy board structure defined by digiConfig into drivers board
964 * structure. Note : If LILO has ran epca_setup then epca_setup will
965 * handle defining num_cards as well as copying the data into the board
969 /* driver has been configured via. epcaconfig */
971 num_cards = NUMCARDS;
972 memcpy(&boards, &static_boards,
973 sizeof(struct board_info) * NUMCARDS);
977 * Note : If lilo was used to configure the driver and the ignore
978 * epcaconfig option was choosen (digiepca=2) then nbdevs and num_cards
979 * will equal 0 at this point. This is okay; PCI cards will still be
980 * picked up if detected.
984 * Set up interrupt, we will worry about memory allocation in
987 printk(KERN_INFO "DIGI epca driver version %s loaded.\n", VERSION);
990 * NOTE : This code assumes that the number of ports found in the
991 * boards array is correct. This could be wrong if the card in question
992 * is PCI (And therefore has no ports entry in the boards structure.)
993 * The rest of the information will be valid for PCI because the
994 * beginning of pc_init scans for PCI and determines i/o and base
995 * memory addresses. I am not sure if it is possible to read the number
996 * of ports supported by the card prior to it being booted (Since that
997 * is the state it is in when pc_init is run). Because it is not
998 * possible to query the number of supported ports until after the card
999 * has booted; we are required to calculate the card_ptrs as the card
1000 * is initialized (Inside post_fep_init). The negative thing about this
1001 * approach is that digiDload's call to GET_INFO will have a bad port
1002 * value. (Since this is called prior to post_fep_init.)
1004 pci_boards_found = 0;
1005 if (num_cards < MAXBOARDS)
1006 pci_boards_found += init_PCI();
1007 num_cards += pci_boards_found;
1009 pc_driver->owner = THIS_MODULE;
1010 pc_driver->name = "ttyD";
1011 pc_driver->major = DIGI_MAJOR;
1012 pc_driver->minor_start = 0;
1013 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1014 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1015 pc_driver->init_termios = tty_std_termios;
1016 pc_driver->init_termios.c_iflag = 0;
1017 pc_driver->init_termios.c_oflag = 0;
1018 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1019 pc_driver->init_termios.c_lflag = 0;
1020 pc_driver->init_termios.c_ispeed = 9600;
1021 pc_driver->init_termios.c_ospeed = 9600;
1022 pc_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK;
1023 tty_set_operations(pc_driver, &pc_ops);
1025 pc_info->owner = THIS_MODULE;
1026 pc_info->name = "digi_ctl";
1027 pc_info->major = DIGIINFOMAJOR;
1028 pc_info->minor_start = 0;
1029 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1030 pc_info->subtype = SERIAL_TYPE_INFO;
1031 pc_info->init_termios = tty_std_termios;
1032 pc_info->init_termios.c_iflag = 0;
1033 pc_info->init_termios.c_oflag = 0;
1034 pc_info->init_termios.c_lflag = 0;
1035 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1036 pc_info->init_termios.c_ispeed = 9600;
1037 pc_info->init_termios.c_ospeed = 9600;
1038 pc_info->flags = TTY_DRIVER_REAL_RAW;
1039 tty_set_operations(pc_info, &info_ops);
1042 for (crd = 0; crd < num_cards; crd++) {
1044 * This is where the appropriate memory handlers for the
1045 * hardware is set. Everything at runtime blindly jumps through
1049 /* defined in epcaconfig.h */
1055 bd->memwinon = pcxem_memwinon;
1056 bd->memwinoff = pcxem_memwinoff;
1057 bd->globalwinon = pcxem_globalwinon;
1058 bd->txwinon = pcxem_txwinon;
1059 bd->rxwinon = pcxem_rxwinon;
1060 bd->memoff = pcxem_memoff;
1061 bd->assertgwinon = dummy_assertgwinon;
1062 bd->assertmemoff = dummy_assertmemoff;
1068 bd->memwinon = dummy_memwinon;
1069 bd->memwinoff = dummy_memwinoff;
1070 bd->globalwinon = dummy_globalwinon;
1071 bd->txwinon = dummy_txwinon;
1072 bd->rxwinon = dummy_rxwinon;
1073 bd->memoff = dummy_memoff;
1074 bd->assertgwinon = dummy_assertgwinon;
1075 bd->assertmemoff = dummy_assertmemoff;
1080 bd->memwinon = pcxe_memwinon;
1081 bd->memwinoff = pcxe_memwinoff;
1082 bd->globalwinon = pcxe_globalwinon;
1083 bd->txwinon = pcxe_txwinon;
1084 bd->rxwinon = pcxe_rxwinon;
1085 bd->memoff = pcxe_memoff;
1086 bd->assertgwinon = dummy_assertgwinon;
1087 bd->assertmemoff = dummy_assertmemoff;
1092 bd->memwinon = pcxi_memwinon;
1093 bd->memwinoff = pcxi_memwinoff;
1094 bd->globalwinon = pcxi_globalwinon;
1095 bd->txwinon = pcxi_txwinon;
1096 bd->rxwinon = pcxi_rxwinon;
1097 bd->memoff = pcxi_memoff;
1098 bd->assertgwinon = pcxi_assertgwinon;
1099 bd->assertmemoff = pcxi_assertmemoff;
1107 * Some cards need a memory segment to be defined for use in
1108 * transmit and receive windowing operations. These boards are
1109 * listed in the below switch. In the case of the XI the amount
1110 * of memory on the board is variable so the memory_seg is also
1111 * variable. This code determines what they segment should be.
1117 bd->memory_seg = 0xf000;
1121 board_id = inb((int)bd->port);
1122 if ((board_id & 0x1) == 0x1) {
1123 /* it's an XI card */
1124 /* Is it a 64K board */
1125 if ((board_id & 0x30) == 0)
1126 bd->memory_seg = 0xf000;
1128 /* Is it a 128K board */
1129 if ((board_id & 0x30) == 0x10)
1130 bd->memory_seg = 0xe000;
1132 /* Is is a 256K board */
1133 if ((board_id & 0x30) == 0x20)
1134 bd->memory_seg = 0xc000;
1136 /* Is it a 512K board */
1137 if ((board_id & 0x30) == 0x30)
1138 bd->memory_seg = 0x8000;
1140 printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n", (int)bd->port);
1145 err = tty_register_driver(pc_driver);
1147 printk(KERN_ERR "Couldn't register Digi PC/ driver");
1151 err = tty_register_driver(pc_info);
1153 printk(KERN_ERR "Couldn't register Digi PC/ info ");
1157 /* Start up the poller to check for events on all enabled boards */
1158 init_timer(&epca_timer);
1159 epca_timer.function = epcapoll;
1160 mod_timer(&epca_timer, jiffies + HZ/25);
1164 tty_unregister_driver(pc_driver);
1166 put_tty_driver(pc_info);
1168 put_tty_driver(pc_driver);
1173 static void post_fep_init(unsigned int crd)
1176 void __iomem *memaddr;
1177 struct global_data __iomem *gd;
1178 struct board_info *bd;
1179 struct board_chan __iomem *bc;
1181 int shrinkmem = 0, lowwater;
1184 * This call is made by the user via. the ioctl call DIGI_INIT. It is
1185 * responsible for setting up all the card specific stuff.
1190 * If this is a PCI board, get the port info. Remember PCI cards do not
1191 * have entries into the epcaconfig.h file, so we can't get the number
1192 * of ports from it. Unfortunetly, this means that anyone doing a
1193 * DIGI_GETINFO before the board has booted will get an invalid number
1194 * of ports returned (It should return 0). Calls to DIGI_GETINFO after
1195 * DIGI_INIT has been called will return the proper values.
1197 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
1199 * Below we use XEMPORTS as a memory offset regardless of which
1200 * PCI card it is. This is because all of the supported PCI
1201 * cards have the same memory offset for the channel data. This
1202 * will have to be changed if we ever develop a PCI/XE card.
1203 * NOTE : The FEP manual states that the port offset is 0xC22
1204 * as opposed to 0xC02. This is only true for PC/XE, and PC/XI
1205 * cards; not for the XEM, or CX series. On the PCI cards the
1206 * number of ports is determined by reading a ID PROM located
1207 * in the box attached to the card. The card can then determine
1208 * the index the id to determine the number of ports available.
1209 * (FYI - The id should be located at 0x1ac (And may use up to
1210 * 4 bytes if the box in question is a XEM or CX)).
1212 /* PCI cards are already remapped at this point ISA are not */
1213 bd->numports = readw(bd->re_map_membase + XEMPORTS);
1214 epcaassert(bd->numports <= 64, "PCI returned a invalid number of ports");
1215 nbdevs += (bd->numports);
1217 /* Fix up the mappings for ISA/EISA etc */
1218 /* FIXME: 64K - can we be smarter ? */
1219 bd->re_map_membase = ioremap_nocache(bd->membase, 0x10000);
1223 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1225 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1228 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1230 memaddr = bd->re_map_membase;
1233 * The below assignment will set bc to point at the BEGINING of the
1234 * cards channel structures. For 1 card there will be between 8 and 64
1235 * of these structures.
1237 bc = memaddr + CHANSTRUCT;
1240 * The below assignment will set gd to point at the BEGINING of global
1241 * memory address 0xc00. The first data in that global memory actually
1242 * starts at address 0xc1a. The command in pointer begins at 0xd10.
1244 gd = memaddr + GLOBAL;
1247 * XEPORTS (address 0xc22) points at the number of channels the card
1248 * supports. (For 64XE, XI, XEM, and XR use 0xc02)
1250 if ((bd->type == PCXEVE || bd->type == PCXE) &&
1251 (readw(memaddr + XEPORTS) < 3))
1253 if (bd->type < PCIXEM)
1254 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1259 * Remember ch is the main drivers channels structure, while bc is the
1260 * cards channel structure.
1262 for (i = 0; i < bd->numports; i++, ch++, bc++) {
1263 unsigned long flags;
1266 tty_port_init(&ch->port);
1267 ch->port.ops = &epca_port_ops;
1270 INIT_WORK(&ch->tqueue, do_softint);
1271 ch->board = &boards[crd];
1273 spin_lock_irqsave(&epca_lock, flags);
1276 * Since some of the boards use different bitmaps for
1277 * their control signals we cannot hard code these
1278 * values and retain portability. We virtualize this
1307 if (boards[crd].altpin) {
1308 ch->dsr = ch->m_dcd;
1309 ch->dcd = ch->m_dsr;
1310 ch->digiext.digi_flags |= DIGI_ALTPIN;
1312 ch->dcd = ch->m_dcd;
1313 ch->dsr = ch->m_dsr;
1318 ch->magic = EPCA_MAGIC;
1319 tty_port_tty_set(&ch->port, NULL);
1322 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1326 tseg = readw(&bc->tseg);
1327 rseg = readw(&bc->rseg);
1333 /* Cover all the 2MEG cards */
1334 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1335 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1336 ch->txwin = FEPWIN | (tseg >> 11);
1337 ch->rxwin = FEPWIN | (rseg >> 11);
1342 /* Cover all the 32K windowed cards */
1343 /* Mask equal to window size - 1 */
1344 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1345 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1346 ch->txwin = FEPWIN | (tseg >> 11);
1347 ch->rxwin = FEPWIN | (rseg >> 11);
1352 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4)
1354 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1355 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4)
1357 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >> 9);
1362 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1363 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
1364 ch->txwin = ch->rxwin = 0;
1369 ch->txbufsize = readw(&bc->tmax) + 1;
1372 ch->rxbufsize = readw(&bc->rmax) + 1;
1374 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1376 /* Set transmitter low water mark */
1377 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1379 /* Set receiver low water mark */
1380 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
1382 /* Set receiver high water mark */
1383 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1385 writew(100, &bc->edelay);
1386 writeb(1, &bc->idata);
1388 ch->startc = readb(&bc->startc);
1389 ch->stopc = readb(&bc->stopc);
1390 ch->startca = readb(&bc->startca);
1391 ch->stopca = readb(&bc->stopca);
1401 ch->port.close_delay = 50;
1403 spin_unlock_irqrestore(&epca_lock, flags);
1407 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1408 VERSION, board_desc[bd->type], (long)bd->port,
1409 (long)bd->membase, bd->numports);
1413 static void epcapoll(unsigned long ignored)
1415 unsigned long flags;
1417 unsigned int head, tail;
1419 struct board_info *bd;
1422 * This routine is called upon every timer interrupt. Even though the
1423 * Digi series cards are capable of generating interrupts this method
1424 * of non-looping polling is more efficient. This routine checks for
1425 * card generated events (Such as receive data, are transmit buffer
1426 * empty) and acts on those events.
1428 for (crd = 0; crd < num_cards; crd++) {
1432 if ((bd->status == DISABLED) || digi_poller_inhibited)
1436 * assertmemoff is not needed here; indeed it is an empty
1437 * subroutine. It is being kept because future boards may need
1438 * this as well as some legacy boards.
1440 spin_lock_irqsave(&epca_lock, flags);
1447 * In this case head and tail actually refer to the event queue
1448 * not the transmit or receive queue.
1450 head = readw(&ch->mailbox->ein);
1451 tail = readw(&ch->mailbox->eout);
1453 /* If head isn't equal to tail we have an event */
1458 spin_unlock_irqrestore(&epca_lock, flags);
1459 } /* End for each card */
1460 mod_timer(&epca_timer, jiffies + (HZ / 25));
1463 static void doevent(int crd)
1465 void __iomem *eventbuf;
1466 struct channel *ch, *chan0;
1467 static struct tty_struct *tty;
1468 struct board_info *bd;
1469 struct board_chan __iomem *bc;
1470 unsigned int tail, head;
1475 * This subroutine is called by epcapoll when an event is detected
1476 * in the event queue. This routine responds to those events.
1480 chan0 = card_ptr[crd];
1481 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
1482 assertgwinon(chan0);
1483 while ((tail = readw(&chan0->mailbox->eout)) !=
1484 (head = readw(&chan0->mailbox->ein))) {
1485 /* Begin while something in event queue */
1486 assertgwinon(chan0);
1487 eventbuf = bd->re_map_membase + tail + ISTART;
1488 /* Get the channel the event occurred on */
1489 channel = readb(eventbuf);
1490 /* Get the actual event code that occurred */
1491 event = readb(eventbuf + 1);
1493 * The two assignments below get the current modem status
1494 * (mstat) and the previous modem status (lstat). These are
1495 * useful becuase an event could signal a change in modem
1498 mstat = readb(eventbuf + 2);
1499 lstat = readb(eventbuf + 3);
1501 ch = chan0 + channel;
1502 if ((unsigned)channel >= bd->numports || !ch) {
1503 if (channel >= bd->numports)
1513 tty = tty_port_tty_get(&ch->port);
1514 if (event & DATA_IND) { /* Begin DATA_IND */
1515 receive_data(ch, tty);
1517 } /* End DATA_IND */
1518 /* else *//* Fix for DCD transition missed bug */
1519 if (event & MODEMCHG_IND) {
1520 /* A modem signal change has been indicated */
1522 if (test_bit(ASYNCB_CHECK_CD, &ch->port.flags)) {
1523 /* We are now receiving dcd */
1524 if (mstat & ch->dcd)
1525 wake_up_interruptible(&ch->port.open_wait);
1526 else /* No dcd; hangup */
1527 pc_sched_event(ch, EPCA_EVENT_HANGUP);
1531 if (event & BREAK_IND) {
1532 /* A break has been indicated */
1533 tty_insert_flip_char(tty, 0, TTY_BREAK);
1534 tty_schedule_flip(tty);
1535 } else if (event & LOWTX_IND) {
1536 if (ch->statusflags & LOWWAIT) {
1537 ch->statusflags &= ~LOWWAIT;
1540 } else if (event & EMPTYTX_IND) {
1541 /* This event is generated by
1542 setup_empty_event */
1543 ch->statusflags &= ~TXBUSY;
1544 if (ch->statusflags & EMPTYWAIT) {
1545 ch->statusflags &= ~EMPTYWAIT;
1554 writew(1, &bc->idata);
1555 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
1557 } /* End while something in event queue */
1560 static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1561 int byte2, int ncmds, int bytecmd)
1563 unchar __iomem *memaddr;
1564 unsigned int head, cmdTail, cmdStart, cmdMax;
1568 /* This is the routine in which commands may be passed to the card. */
1570 if (ch->board->status == DISABLED)
1573 /* Remember head (As well as max) is just an offset not a base addr */
1574 head = readw(&ch->mailbox->cin);
1575 /* cmdStart is a base address */
1576 cmdStart = readw(&ch->mailbox->cstart);
1578 * We do the addition below because we do not want a max pointer
1579 * relative to cmdStart. We want a max pointer that points at the
1580 * physical end of the command queue.
1582 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
1583 memaddr = ch->board->re_map_membase;
1585 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1586 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n",
1587 __LINE__, cmd, head);
1588 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n",
1589 __LINE__, cmdMax, cmdStart);
1593 writeb(cmd, memaddr + head + cmdStart + 0);
1594 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1595 /* Below word_or_byte is bits to set */
1596 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1597 /* Below byte2 is bits to reset */
1598 writeb(byte2, memaddr + head + cmdStart + 3);
1600 writeb(cmd, memaddr + head + cmdStart + 0);
1601 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1602 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1604 head = (head + 4) & (cmdMax - cmdStart - 4);
1605 writew(head, &ch->mailbox->cin);
1611 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1614 head = readw(&ch->mailbox->cin);
1615 cmdTail = readw(&ch->mailbox->cout);
1616 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
1618 * Basically this will break when the FEP acknowledges the
1619 * command by incrementing cmdTail (Making it equal to head).
1621 if (n <= ncmds * (sizeof(short) * 4))
1627 * Digi products use fields in their channels structures that are very similar
1628 * to the c_cflag and c_iflag fields typically found in UNIX termios
1629 * structures. The below three routines allow mappings between these hardware
1630 * "flags" and their respective Linux flags.
1632 static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
1636 if (cflag & CRTSCTS) {
1637 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1638 res |= ((ch->m_cts) | (ch->m_rts));
1641 if (ch->digiext.digi_flags & RTSPACE)
1644 if (ch->digiext.digi_flags & DTRPACE)
1647 if (ch->digiext.digi_flags & CTSPACE)
1650 if (ch->digiext.digi_flags & DSRPACE)
1653 if (ch->digiext.digi_flags & DCDPACE)
1656 if (res & (ch->m_rts))
1657 ch->digiext.digi_flags |= RTSPACE;
1659 if (res & (ch->m_cts))
1660 ch->digiext.digi_flags |= CTSPACE;
1665 static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
1667 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
1668 INPCK | ISTRIP | IXON | IXANY | IXOFF);
1669 if (ch->digiext.digi_flags & DIGI_AIXON)
1674 static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
1677 if (cflag & CBAUDEX) {
1678 ch->digiext.digi_flags |= DIGI_FAST;
1680 * HUPCL bit is used by FEP to indicate fast baud table is to
1685 ch->digiext.digi_flags &= ~DIGI_FAST;
1687 * CBAUD has bit position 0x1000 set these days to indicate Linux
1688 * baud rate remap. Digi hardware can't handle the bit assignment.
1689 * (We use a different bit assignment for high speed.). Clear this
1692 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
1694 * This gets a little confusing. The Digi cards have their own
1695 * representation of c_cflags controlling baud rate. For the most part
1696 * this is identical to the Linux implementation. However; Digi
1697 * supports one rate (76800) that Linux doesn't. This means that the
1698 * c_cflag entry that would normally mean 76800 for Digi actually means
1699 * 115200 under Linux. Without the below mapping, a stty 115200 would
1700 * only drive the board at 76800. Since the rate 230400 is also found
1701 * after 76800, the same problem afflicts us when we choose a rate of
1702 * 230400. Without the below modificiation stty 230400 would actually
1705 * There are two additional differences. The Linux value for CLOCAL
1706 * (0x800; 0004000) has no meaning to the Digi hardware. Also in later
1707 * releases of Linux; the CBAUD define has CBAUDEX (0x1000; 0010000)
1708 * ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX should be
1709 * checked for a screened out prior to termios2digi_c returning. Since
1710 * CLOCAL isn't used by the board this can be ignored as long as the
1711 * returned value is used only by Digi hardware.
1713 if (cflag & CBAUDEX) {
1715 * The below code is trying to guarantee that only baud rates
1716 * 115200 and 230400 are remapped. We use exclusive or because
1717 * the various baud rates share common bit positions and
1718 * therefore can't be tested for easily.
1720 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
1721 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
1727 /* Caller must hold the locks */
1728 static void epcaparam(struct tty_struct *tty, struct channel *ch)
1730 unsigned int cmdHead;
1731 struct ktermios *ts;
1732 struct board_chan __iomem *bc;
1733 unsigned mval, hflow, cflag, iflag;
1736 epcaassert(bc != NULL, "bc out of range");
1740 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
1741 cmdHead = readw(&bc->rin);
1742 writew(cmdHead, &bc->rout);
1743 cmdHead = readw(&bc->tin);
1744 /* Changing baud in mid-stream transmission can be wonderful */
1746 * Flush current transmit buffer by setting cmdTail pointer
1747 * (tout) to cmdHead pointer (tin). Hopefully the transmit
1750 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
1752 } else { /* Begin CBAUD not detected */
1754 * c_cflags have changed but that change had nothing to do with
1755 * BAUD. Propagate the change to the card.
1757 cflag = termios2digi_c(ch, ts->c_cflag);
1758 if (cflag != ch->fepcflag) {
1759 ch->fepcflag = cflag;
1760 /* Set baud rate, char size, stop bits, parity */
1761 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
1764 * If the user has not forced CLOCAL and if the device is not a
1765 * CALLOUT device (Which is always CLOCAL) we set flags such
1766 * that the driver will wait on carrier detect.
1768 if (ts->c_cflag & CLOCAL)
1769 clear_bit(ASYNCB_CHECK_CD, &ch->port.flags);
1771 set_bit(ASYNCB_CHECK_CD, &ch->port.flags);
1772 mval = ch->m_dtr | ch->m_rts;
1773 } /* End CBAUD not detected */
1774 iflag = termios2digi_i(ch, ts->c_iflag);
1775 /* Check input mode flags */
1776 if (iflag != ch->fepiflag) {
1777 ch->fepiflag = iflag;
1779 * Command sets channels iflag structure on the board. Such
1780 * things as input soft flow control, handling of parity
1781 * errors, and break handling are all set here.
1783 * break handling, parity handling, input stripping,
1784 * flow control chars
1786 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
1789 * Set the board mint value for this channel. This will cause hardware
1790 * events to be generated each time the DCD signal (Described in mint)
1793 writeb(ch->dcd, &bc->mint);
1794 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
1795 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
1796 writeb(0, &bc->mint);
1797 ch->imodem = readb(&bc->mstat);
1798 hflow = termios2digi_h(ch, ts->c_cflag);
1799 if (hflow != ch->hflow) {
1802 * Hard flow control has been selected but the board is not
1803 * using it. Activate hard flow control now.
1805 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
1807 mval ^= ch->modemfake & (mval ^ ch->modem);
1809 if (ch->omodem ^ mval) {
1812 * The below command sets the DTR and RTS mstat structure. If
1813 * hard flow control is NOT active these changes will drive the
1814 * output of the actual DTR and RTS lines. If hard flow control
1815 * is active, the changes will be saved in the mstat structure
1816 * and only asserted when hard flow control is turned off.
1819 /* First reset DTR & RTS; then set them */
1820 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
1821 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
1823 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
1824 ch->fepstartc = ch->startc;
1825 ch->fepstopc = ch->stopc;
1827 * The XON / XOFF characters have changed; propagate these
1828 * changes to the card.
1830 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
1832 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
1833 ch->fepstartca = ch->startca;
1834 ch->fepstopca = ch->stopca;
1836 * Similar to the above, this time the auxilarly XON / XOFF
1837 * characters have changed; propagate these changes to the card.
1839 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
1843 /* Caller holds lock */
1844 static void receive_data(struct channel *ch, struct tty_struct *tty)
1847 struct ktermios *ts = NULL;
1848 struct board_chan __iomem *bc;
1849 int dataToRead, wrapgap, bytesAvailable;
1850 unsigned int tail, head;
1851 unsigned int wrapmask;
1854 * This routine is called by doint when a receive data event has taken
1858 if (ch->statusflags & RXSTOPPED)
1864 wrapmask = ch->rxbufsize - 1;
1867 * Get the head and tail pointers to the receiver queue. Wrap the head
1868 * pointer if it has reached the end of the buffer.
1870 head = readw(&bc->rin);
1872 tail = readw(&bc->rout) & wrapmask;
1874 bytesAvailable = (head - tail) & wrapmask;
1875 if (bytesAvailable == 0)
1878 /* If CREAD bit is off or device not open, set TX tail to head */
1879 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
1880 writew(head, &bc->rout);
1884 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
1887 if (readb(&bc->orun)) {
1888 writeb(0, &bc->orun);
1889 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",
1891 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
1894 while (bytesAvailable > 0) {
1895 /* Begin while there is data on the card */
1896 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
1898 * Even if head has wrapped around only report the amount of
1899 * data to be equal to the size - tail. Remember memcpy can't
1900 * automaticly wrap around the receive buffer.
1902 dataToRead = (wrapgap < bytesAvailable) ? wrapgap
1904 /* Make sure we don't overflow the buffer */
1905 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
1906 if (dataToRead == 0)
1909 * Move data read from our card into the line disciplines
1910 * buffer for translation if necessary.
1912 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
1913 tail = (tail + dataToRead) & wrapmask;
1914 bytesAvailable -= dataToRead;
1915 } /* End while there is data on the card */
1917 writew(tail, &bc->rout);
1918 /* Must be called with global data */
1919 tty_schedule_flip(tty);
1922 static int info_ioctl(struct tty_struct *tty, struct file *file,
1923 unsigned int cmd, unsigned long arg)
1928 struct digi_info di;
1931 if (get_user(brd, (unsigned int __user *)arg))
1933 if (brd < 0 || brd >= num_cards || num_cards == 0)
1936 memset(&di, 0, sizeof(di));
1939 di.status = boards[brd].status;
1940 di.type = boards[brd].type ;
1941 di.numports = boards[brd].numports ;
1942 /* Legacy fixups - just move along nothing to see */
1943 di.port = (unsigned char *)boards[brd].port ;
1944 di.membase = (unsigned char *)boards[brd].membase ;
1946 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
1954 int brd = arg & 0xff000000 >> 16;
1955 unsigned char state = arg & 0xff;
1957 if (brd < 0 || brd >= num_cards) {
1958 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
1961 digi_poller_inhibited = state;
1968 * This call is made by the apps to complete the
1969 * initialization of the board(s). This routine is
1970 * responsible for setting the card to its initial
1971 * state and setting the drivers control fields to the
1972 * sutianle settings for the card in question.
1975 for (crd = 0; crd < num_cards; crd++)
1985 static int pc_tiocmget(struct tty_struct *tty, struct file *file)
1987 struct channel *ch = tty->driver_data;
1988 struct board_chan __iomem *bc;
1989 unsigned int mstat, mflag = 0;
1990 unsigned long flags;
1997 spin_lock_irqsave(&epca_lock, flags);
1999 mstat = readb(&bc->mstat);
2001 spin_unlock_irqrestore(&epca_lock, flags);
2003 if (mstat & ch->m_dtr)
2005 if (mstat & ch->m_rts)
2007 if (mstat & ch->m_cts)
2009 if (mstat & ch->dsr)
2011 if (mstat & ch->m_ri)
2013 if (mstat & ch->dcd)
2018 static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2019 unsigned int set, unsigned int clear)
2021 struct channel *ch = tty->driver_data;
2022 unsigned long flags;
2027 spin_lock_irqsave(&epca_lock, flags);
2029 * I think this modemfake stuff is broken. It doesn't correctly reflect
2030 * the behaviour desired by the TIOCM* ioctls. Therefore this is
2033 if (set & TIOCM_RTS) {
2034 ch->modemfake |= ch->m_rts;
2035 ch->modem |= ch->m_rts;
2037 if (set & TIOCM_DTR) {
2038 ch->modemfake |= ch->m_dtr;
2039 ch->modem |= ch->m_dtr;
2041 if (clear & TIOCM_RTS) {
2042 ch->modemfake |= ch->m_rts;
2043 ch->modem &= ~ch->m_rts;
2045 if (clear & TIOCM_DTR) {
2046 ch->modemfake |= ch->m_dtr;
2047 ch->modem &= ~ch->m_dtr;
2051 * The below routine generally sets up parity, baud, flow control
2052 * issues, etc.... It effect both control flags and input flags.
2056 spin_unlock_irqrestore(&epca_lock, flags);
2060 static int pc_ioctl(struct tty_struct *tty, struct file *file,
2061 unsigned int cmd, unsigned long arg)
2064 unsigned long flags;
2065 unsigned int mflag, mstat;
2066 unsigned char startc, stopc;
2067 struct board_chan __iomem *bc;
2068 struct channel *ch = tty->driver_data;
2069 void __user *argp = (void __user *)arg;
2077 mflag = pc_tiocmget(tty, file);
2078 if (put_user(mflag, (unsigned long __user *)argp))
2082 if (get_user(mstat, (unsigned __user *)argp))
2084 return pc_tiocmset(tty, file, mstat, ~mstat);
2086 spin_lock_irqsave(&epca_lock, flags);
2087 ch->omodem |= ch->m_dtr;
2089 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2091 spin_unlock_irqrestore(&epca_lock, flags);
2095 spin_lock_irqsave(&epca_lock, flags);
2096 ch->omodem &= ~ch->m_dtr;
2098 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2100 spin_unlock_irqrestore(&epca_lock, flags);
2103 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2108 if (cmd == DIGI_SETAW) {
2109 /* Setup an event to indicate when the transmit
2111 spin_lock_irqsave(&epca_lock, flags);
2112 setup_empty_event(tty, ch);
2113 spin_unlock_irqrestore(&epca_lock, flags);
2114 tty_wait_until_sent(tty, 0);
2116 /* ldisc lock already held in ioctl */
2117 if (tty->ldisc->ops->flush_buffer)
2118 tty->ldisc->ops->flush_buffer(tty);
2122 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2125 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
2126 ch->dcd = ch->m_dsr;
2127 ch->dsr = ch->m_dcd;
2129 ch->dcd = ch->m_dcd;
2130 ch->dsr = ch->m_dsr;
2133 spin_lock_irqsave(&epca_lock, flags);
2137 * The below routine generally sets up parity, baud, flow
2138 * control issues, etc.... It effect both control flags and
2143 spin_unlock_irqrestore(&epca_lock, flags);
2148 spin_lock_irqsave(&epca_lock, flags);
2150 if (cmd == DIGI_GETFLOW) {
2151 dflow.startc = readb(&bc->startc);
2152 dflow.stopc = readb(&bc->stopc);
2154 dflow.startc = readb(&bc->startca);
2155 dflow.stopc = readb(&bc->stopca);
2158 spin_unlock_irqrestore(&epca_lock, flags);
2160 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2166 if (cmd == DIGI_SETFLOW) {
2167 startc = ch->startc;
2170 startc = ch->startca;
2174 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2177 if (dflow.startc != startc || dflow.stopc != stopc) {
2178 /* Begin if setflow toggled */
2179 spin_lock_irqsave(&epca_lock, flags);
2182 if (cmd == DIGI_SETFLOW) {
2183 ch->fepstartc = ch->startc = dflow.startc;
2184 ch->fepstopc = ch->stopc = dflow.stopc;
2185 fepcmd(ch, SONOFFC, ch->fepstartc,
2186 ch->fepstopc, 0, 1);
2188 ch->fepstartca = ch->startca = dflow.startc;
2189 ch->fepstopca = ch->stopca = dflow.stopc;
2190 fepcmd(ch, SAUXONOFFC, ch->fepstartca,
2191 ch->fepstopca, 0, 1);
2194 if (ch->statusflags & TXSTOPPED)
2198 spin_unlock_irqrestore(&epca_lock, flags);
2199 } /* End if setflow toggled */
2202 return -ENOIOCTLCMD;
2207 static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2210 unsigned long flags;
2212 * verifyChannel returns the channel from the tty struct if it is
2213 * valid. This serves as a sanity check.
2215 ch = verifyChannel(tty);
2217 if (ch != NULL) { /* Begin if channel valid */
2218 spin_lock_irqsave(&epca_lock, flags);
2222 spin_unlock_irqrestore(&epca_lock, flags);
2224 if ((old_termios->c_cflag & CRTSCTS) &&
2225 ((tty->termios->c_cflag & CRTSCTS) == 0))
2226 tty->hw_stopped = 0;
2228 if (!(old_termios->c_cflag & CLOCAL) &&
2229 (tty->termios->c_cflag & CLOCAL))
2230 wake_up_interruptible(&ch->port.open_wait);
2232 } /* End if channel valid */
2235 static void do_softint(struct work_struct *work)
2237 struct channel *ch = container_of(work, struct channel, tqueue);
2238 /* Called in response to a modem change event */
2239 if (ch && ch->magic == EPCA_MAGIC) {
2240 struct tty_struct *tty = tty_port_tty_get(&ch->port);
2242 if (tty && tty->driver_data) {
2243 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) {
2245 wake_up_interruptible(&ch->port.open_wait);
2246 clear_bit(ASYNCB_NORMAL_ACTIVE,
2255 * pc_stop and pc_start provide software flow control to the routine and the
2258 static void pc_stop(struct tty_struct *tty)
2261 unsigned long flags;
2263 * verifyChannel returns the channel from the tty struct if it is
2264 * valid. This serves as a sanity check.
2266 ch = verifyChannel(tty);
2268 spin_lock_irqsave(&epca_lock, flags);
2269 if ((ch->statusflags & TXSTOPPED) == 0) {
2270 /* Begin if transmit stop requested */
2272 /* STOP transmitting now !! */
2273 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
2274 ch->statusflags |= TXSTOPPED;
2276 } /* End if transmit stop requested */
2277 spin_unlock_irqrestore(&epca_lock, flags);
2281 static void pc_start(struct tty_struct *tty)
2285 * verifyChannel returns the channel from the tty struct if it is
2286 * valid. This serves as a sanity check.
2288 ch = verifyChannel(tty);
2290 unsigned long flags;
2291 spin_lock_irqsave(&epca_lock, flags);
2292 /* Just in case output was resumed because of a change
2294 if (ch->statusflags & TXSTOPPED) {
2295 /* Begin transmit resume requested */
2296 struct board_chan __iomem *bc;
2299 if (ch->statusflags & LOWWAIT)
2300 writeb(1, &bc->ilow);
2301 /* Okay, you can start transmitting again... */
2302 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
2303 ch->statusflags &= ~TXSTOPPED;
2305 } /* End transmit resume requested */
2306 spin_unlock_irqrestore(&epca_lock, flags);
2311 * The below routines pc_throttle and pc_unthrottle are used to slow (And
2312 * resume) the receipt of data into the kernels receive buffers. The exact
2313 * occurrence of this depends on the size of the kernels receive buffer and
2314 * what the 'watermarks' are set to for that buffer. See the n_ttys.c file for
2317 static void pc_throttle(struct tty_struct *tty)
2320 unsigned long flags;
2322 * verifyChannel returns the channel from the tty struct if it is
2323 * valid. This serves as a sanity check.
2325 ch = verifyChannel(tty);
2327 spin_lock_irqsave(&epca_lock, flags);
2328 if ((ch->statusflags & RXSTOPPED) == 0) {
2330 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
2331 ch->statusflags |= RXSTOPPED;
2334 spin_unlock_irqrestore(&epca_lock, flags);
2338 static void pc_unthrottle(struct tty_struct *tty)
2341 unsigned long flags;
2343 * verifyChannel returns the channel from the tty struct if it is
2344 * valid. This serves as a sanity check.
2346 ch = verifyChannel(tty);
2348 /* Just in case output was resumed because of a change
2350 spin_lock_irqsave(&epca_lock, flags);
2351 if (ch->statusflags & RXSTOPPED) {
2353 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
2354 ch->statusflags &= ~RXSTOPPED;
2357 spin_unlock_irqrestore(&epca_lock, flags);
2361 static int pc_send_break(struct tty_struct *tty, int msec)
2363 struct channel *ch = tty->driver_data;
2364 unsigned long flags;
2368 else if (msec > 0xFFFE)
2373 spin_lock_irqsave(&epca_lock, flags);
2376 * Maybe I should send an infinite break here, schedule() for msec
2377 * amount of time, and then stop the break. This way, the user can't
2378 * screw up the FEP by causing digi_send_break() to be called (i.e. via
2379 * an ioctl()) more than once in msec amount of time.
2380 * Try this for now...
2382 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2384 spin_unlock_irqrestore(&epca_lock, flags);
2388 /* Caller MUST hold the lock */
2389 static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2391 struct board_chan __iomem *bc = ch->brdchan;
2394 ch->statusflags |= EMPTYWAIT;
2396 * When set the iempty flag request a event to be generated when the
2397 * transmit buffer is empty (If there is no BREAK in progress).
2399 writeb(1, &bc->iempty);
2404 static void __init epca_setup(char *str, int *ints)
2406 struct board_info board;
2407 int index, loop, last;
2412 * If this routine looks a little strange it is because it is only
2413 * called if a LILO append command is given to boot the kernel with
2414 * parameters. In this way, we can provide the user a method of
2415 * changing his board configuration without rebuilding the kernel.
2420 memset(&board, 0, sizeof(board));
2422 /* Assume the data is int first, later we can change it */
2423 /* I think that array position 0 of ints holds the number of args */
2424 for (last = 0, index = 1; index <= ints[0]; index++)
2425 switch (index) { /* Begin parse switch */
2427 board.status = ints[index];
2429 * We check for 2 (As opposed to 1; because 2 is a flag
2430 * instructing the driver to ignore epcaconfig.) For
2431 * this reason we check for 2.
2433 if (board.status == 2) {
2434 /* Begin ignore epcaconfig as well as lilo cmd line */
2438 } /* End ignore epcaconfig as well as lilo cmd line */
2440 if (board.status > 2) {
2441 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n",
2443 invalid_lilo_config = 1;
2444 setup_error_code |= INVALID_BOARD_STATUS;
2450 board.type = ints[index];
2451 if (board.type >= PCIXEM) {
2452 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
2453 invalid_lilo_config = 1;
2454 setup_error_code |= INVALID_BOARD_TYPE;
2460 board.altpin = ints[index];
2461 if (board.altpin > 1) {
2462 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
2463 invalid_lilo_config = 1;
2464 setup_error_code |= INVALID_ALTPIN;
2471 board.numports = ints[index];
2472 if (board.numports < 2 || board.numports > 256) {
2473 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
2474 invalid_lilo_config = 1;
2475 setup_error_code |= INVALID_NUM_PORTS;
2478 nbdevs += board.numports;
2483 board.port = ints[index];
2484 if (ints[index] <= 0) {
2485 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
2486 invalid_lilo_config = 1;
2487 setup_error_code |= INVALID_PORT_BASE;
2494 board.membase = ints[index];
2495 if (ints[index] <= 0) {
2496 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",
2497 (unsigned int)board.membase);
2498 invalid_lilo_config = 1;
2499 setup_error_code |= INVALID_MEM_BASE;
2506 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
2509 } /* End parse switch */
2511 while (str && *str) { /* Begin while there is a string arg */
2512 /* find the next comma or terminator */
2514 /* While string is not null, and a comma hasn't been found */
2515 while (*temp && (*temp != ','))
2521 /* Set index to the number of args + 1 */
2527 if (strncmp("Disable", str, len) == 0)
2529 else if (strncmp("Enable", str, len) == 0)
2532 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
2533 invalid_lilo_config = 1;
2534 setup_error_code |= INVALID_BOARD_STATUS;
2541 for (loop = 0; loop < EPCA_NUM_TYPES; loop++)
2542 if (strcmp(board_desc[loop], str) == 0)
2545 * If the index incremented above refers to a
2546 * legitamate board type set it here.
2548 if (index < EPCA_NUM_TYPES)
2551 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
2552 invalid_lilo_config = 1;
2553 setup_error_code |= INVALID_BOARD_TYPE;
2561 if (strncmp("Disable", str, len) == 0)
2563 else if (strncmp("Enable", str, len) == 0)
2566 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
2567 invalid_lilo_config = 1;
2568 setup_error_code |= INVALID_ALTPIN;
2576 while (isdigit(*t2))
2580 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
2581 invalid_lilo_config = 1;
2582 setup_error_code |= INVALID_NUM_PORTS;
2587 * There is not a man page for simple_strtoul but the
2588 * code can be found in vsprintf.c. The first argument
2589 * is the string to translate (To an unsigned long
2590 * obviously), the second argument can be the address
2591 * of any character variable or a NULL. If a variable
2592 * is given, the end pointer of the string will be
2593 * stored in that variable; if a NULL is given the end
2594 * pointer will not be returned. The last argument is
2595 * the base to use. If a 0 is indicated, the routine
2596 * will attempt to determine the proper base by looking
2597 * at the values prefix (A '0' for octal, a 'x' for
2598 * hex, etc ... If a value is given it will use that
2599 * value as the base.
2601 board.numports = simple_strtoul(str, NULL, 0);
2602 nbdevs += board.numports;
2608 while (isxdigit(*t2))
2612 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
2613 invalid_lilo_config = 1;
2614 setup_error_code |= INVALID_PORT_BASE;
2618 board.port = simple_strtoul(str, NULL, 16);
2624 while (isxdigit(*t2))
2628 printk(KERN_ERR "epca_setup: Invalid memory base %s\n", str);
2629 invalid_lilo_config = 1;
2630 setup_error_code |= INVALID_MEM_BASE;
2633 board.membase = simple_strtoul(str, NULL, 16);
2637 printk(KERN_ERR "epca: Too many string parms\n");
2641 } /* End while there is a string arg */
2644 printk(KERN_ERR "epca: Insufficient parms specified\n");
2648 /* I should REALLY validate the stuff here */
2649 /* Copies our local copy of board into boards */
2650 memcpy((void *)&boards[num_cards], (void *)&board, sizeof(board));
2651 /* Does this get called once per lilo arg are what ? */
2652 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2653 num_cards, board_desc[board.type],
2654 board.numports, (int)board.port, (unsigned int) board.membase);
2658 static int __init epca_real_setup(char *str)
2662 epca_setup(get_options(str, 11, ints), ints);
2666 __setup("digiepca", epca_real_setup);
2669 enum epic_board_types {
2676 /* indexed directly by epic_board_types enum */
2678 unsigned char board_type;
2679 unsigned bar_idx; /* PCI base address region */
2680 } epca_info_tbl[] = {
2687 static int __devinit epca_init_one(struct pci_dev *pdev,
2688 const struct pci_device_id *ent)
2690 static int board_num = -1;
2691 int board_idx, info_idx = ent->driver_data;
2694 if (pci_enable_device(pdev))
2698 board_idx = board_num + num_cards;
2699 if (board_idx >= MAXBOARDS)
2702 addr = pci_resource_start(pdev, epca_info_tbl[info_idx].bar_idx);
2704 printk(KERN_ERR PFX "PCI region #%d not available (size 0)\n",
2705 epca_info_tbl[info_idx].bar_idx);
2709 boards[board_idx].status = ENABLED;
2710 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
2711 boards[board_idx].numports = 0x0;
2712 boards[board_idx].port = addr + PCI_IO_OFFSET;
2713 boards[board_idx].membase = addr;
2715 if (!request_mem_region(addr + PCI_IO_OFFSET, 0x200000, "epca")) {
2716 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2717 0x200000, addr + PCI_IO_OFFSET);
2721 boards[board_idx].re_map_port = ioremap_nocache(addr + PCI_IO_OFFSET,
2723 if (!boards[board_idx].re_map_port) {
2724 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2725 0x200000, addr + PCI_IO_OFFSET);
2726 goto err_out_free_pciio;
2729 if (!request_mem_region(addr, 0x200000, "epca")) {
2730 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2732 goto err_out_free_iounmap;
2735 boards[board_idx].re_map_membase = ioremap_nocache(addr, 0x200000);
2736 if (!boards[board_idx].re_map_membase) {
2737 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2738 0x200000, addr + PCI_IO_OFFSET);
2739 goto err_out_free_memregion;
2743 * I don't know what the below does, but the hardware guys say its
2744 * required on everything except PLX (In this case XRJ).
2746 if (info_idx != brd_xrj) {
2747 pci_write_config_byte(pdev, 0x40, 0);
2748 pci_write_config_byte(pdev, 0x46, 0);
2753 err_out_free_memregion:
2754 release_mem_region(addr, 0x200000);
2755 err_out_free_iounmap:
2756 iounmap(boards[board_idx].re_map_port);
2758 release_mem_region(addr + PCI_IO_OFFSET, 0x200000);
2764 static struct pci_device_id epca_pci_tbl[] = {
2765 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
2766 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
2767 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
2768 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
2772 MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
2774 static int __init init_PCI(void)
2776 memset(&epca_driver, 0, sizeof(epca_driver));
2777 epca_driver.name = "epca";
2778 epca_driver.id_table = epca_pci_tbl;
2779 epca_driver.probe = epca_init_one;
2781 return pci_register_driver(&epca_driver);
2784 MODULE_LICENSE("GPL");