2 Copyright (C) 1996 Digi International.
4 For technical support please email digiLinux@dgii.com or
5 call Digi tech support at (612) 912-3456
7 ** This driver is no longer supported by Digi **
9 Much of this design and code came from epca.c which was
10 copyright (C) 1994, 1995 Troy De Jongh, and subsquently
11 modified by David Nugent, Christoph Lameter, Mike McLagan.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /* See README.epca for change history --DAT*/
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/types.h>
32 #include <linux/init.h>
33 #include <linux/serial.h>
34 #include <linux/delay.h>
35 #include <linux/ctype.h>
36 #include <linux/tty.h>
37 #include <linux/tty_flip.h>
38 #include <linux/slab.h>
39 #include <linux/ioport.h>
40 #include <linux/interrupt.h>
41 #include <asm/uaccess.h>
43 #include <linux/spinlock.h>
44 #include <linux/pci.h>
51 #include "epcaconfig.h"
53 #define VERSION "1.3.0.1-LK2.6"
55 /* This major needs to be submitted to Linux to join the majors list */
56 #define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
60 #define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
64 static int nbdevs, num_cards, liloconfig;
65 static int digi_poller_inhibited = 1 ;
67 static int setup_error_code;
68 static int invalid_lilo_config;
71 * The ISA boards do window flipping into the same spaces so its only sane with
72 * a single lock. It's still pretty efficient.
74 static DEFINE_SPINLOCK(epca_lock);
76 /* MAXBOARDS is typically 12, but ISA and EISA cards are restricted to 7 below. */
77 static struct board_info boards[MAXBOARDS];
79 static struct tty_driver *pc_driver;
80 static struct tty_driver *pc_info;
82 /* ------------------ Begin Digi specific structures -------------------- */
85 * digi_channels represents an array of structures that keep track of each
86 * channel of the Digi product. Information such as transmit and receive
87 * pointers, termio data, and signal definitions (DTR, CTS, etc ...) are stored
88 * here. This structure is NOT used to overlay the cards physical channel
91 static struct channel digi_channels[MAX_ALLOC];
94 * card_ptr is an array used to hold the address of the first channel structure
95 * of each card. This array will hold the addresses of various channels located
98 static struct channel *card_ptr[MAXCARDS];
100 static struct timer_list epca_timer;
103 * Begin generic memory functions. These functions will be alias (point at)
104 * more specific functions dependent on the board being configured.
106 static void memwinon(struct board_info *b, unsigned int win);
107 static void memwinoff(struct board_info *b, unsigned int win);
108 static void globalwinon(struct channel *ch);
109 static void rxwinon(struct channel *ch);
110 static void txwinon(struct channel *ch);
111 static void memoff(struct channel *ch);
112 static void assertgwinon(struct channel *ch);
113 static void assertmemoff(struct channel *ch);
115 /* ---- Begin more 'specific' memory functions for cx_like products --- */
117 static void pcxem_memwinon(struct board_info *b, unsigned int win);
118 static void pcxem_memwinoff(struct board_info *b, unsigned int win);
119 static void pcxem_globalwinon(struct channel *ch);
120 static void pcxem_rxwinon(struct channel *ch);
121 static void pcxem_txwinon(struct channel *ch);
122 static void pcxem_memoff(struct channel *ch);
124 /* ------ Begin more 'specific' memory functions for the pcxe ------- */
126 static void pcxe_memwinon(struct board_info *b, unsigned int win);
127 static void pcxe_memwinoff(struct board_info *b, unsigned int win);
128 static void pcxe_globalwinon(struct channel *ch);
129 static void pcxe_rxwinon(struct channel *ch);
130 static void pcxe_txwinon(struct channel *ch);
131 static void pcxe_memoff(struct channel *ch);
133 /* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
134 /* Note : pc64xe and pcxi share the same windowing routines */
136 static void pcxi_memwinon(struct board_info *b, unsigned int win);
137 static void pcxi_memwinoff(struct board_info *b, unsigned int win);
138 static void pcxi_globalwinon(struct channel *ch);
139 static void pcxi_rxwinon(struct channel *ch);
140 static void pcxi_txwinon(struct channel *ch);
141 static void pcxi_memoff(struct channel *ch);
143 /* - Begin 'specific' do nothing memory functions needed for some cards - */
145 static void dummy_memwinon(struct board_info *b, unsigned int win);
146 static void dummy_memwinoff(struct board_info *b, unsigned int win);
147 static void dummy_globalwinon(struct channel *ch);
148 static void dummy_rxwinon(struct channel *ch);
149 static void dummy_txwinon(struct channel *ch);
150 static void dummy_memoff(struct channel *ch);
151 static void dummy_assertgwinon(struct channel *ch);
152 static void dummy_assertmemoff(struct channel *ch);
154 static struct channel *verifyChannel(struct tty_struct *);
155 static void pc_sched_event(struct channel *, int);
156 static void epca_error(int, char *);
157 static void pc_close(struct tty_struct *, struct file *);
158 static void shutdown(struct channel *);
159 static void pc_hangup(struct tty_struct *);
160 static int pc_write_room(struct tty_struct *);
161 static int pc_chars_in_buffer(struct tty_struct *);
162 static void pc_flush_buffer(struct tty_struct *);
163 static void pc_flush_chars(struct tty_struct *);
164 static int block_til_ready(struct tty_struct *, struct file *,
166 static int pc_open(struct tty_struct *, struct file *);
167 static void post_fep_init(unsigned int crd);
168 static void epcapoll(unsigned long);
169 static void doevent(int);
170 static void fepcmd(struct channel *, int, int, int, int, int);
171 static unsigned termios2digi_h(struct channel *ch, unsigned);
172 static unsigned termios2digi_i(struct channel *ch, unsigned);
173 static unsigned termios2digi_c(struct channel *ch, unsigned);
174 static void epcaparam(struct tty_struct *, struct channel *);
175 static void receive_data(struct channel *);
176 static int pc_ioctl(struct tty_struct *, struct file *,
177 unsigned int, unsigned long);
178 static int info_ioctl(struct tty_struct *, struct file *,
179 unsigned int, unsigned long);
180 static void pc_set_termios(struct tty_struct *, struct ktermios *);
181 static void do_softint(struct work_struct *work);
182 static void pc_stop(struct tty_struct *);
183 static void pc_start(struct tty_struct *);
184 static void pc_throttle(struct tty_struct * tty);
185 static void pc_unthrottle(struct tty_struct *tty);
186 static void digi_send_break(struct channel *ch, int msec);
187 static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
188 void epca_setup(char *, int *);
190 static int pc_write(struct tty_struct *, const unsigned char *, int);
191 static int pc_init(void);
192 static int init_PCI(void);
195 * Table of functions for each board to handle memory. Mantaining parallelism
196 * is a *very* good idea here. The idea is for the runtime code to blindly call
197 * these functions, not knowing/caring about the underlying hardware. This
198 * stuff should contain no conditionals; if more functionality is needed a
199 * different entry should be established. These calls are the interface calls
200 * and are the only functions that should be accessed. Anyone caught making
201 * direct calls deserves what they get.
203 static void memwinon(struct board_info *b, unsigned int win)
208 static void memwinoff(struct board_info *b, unsigned int win)
210 b->memwinoff(b, win);
213 static void globalwinon(struct channel *ch)
215 ch->board->globalwinon(ch);
218 static void rxwinon(struct channel *ch)
220 ch->board->rxwinon(ch);
223 static void txwinon(struct channel *ch)
225 ch->board->txwinon(ch);
228 static void memoff(struct channel *ch)
230 ch->board->memoff(ch);
232 static void assertgwinon(struct channel *ch)
234 ch->board->assertgwinon(ch);
237 static void assertmemoff(struct channel *ch)
239 ch->board->assertmemoff(ch);
242 /* PCXEM windowing is the same as that used in the PCXR and CX series cards. */
243 static void pcxem_memwinon(struct board_info *b, unsigned int win)
245 outb_p(FEPWIN|win, b->port + 1);
248 static void pcxem_memwinoff(struct board_info *b, unsigned int win)
250 outb_p(0, b->port + 1);
253 static void pcxem_globalwinon(struct channel *ch)
255 outb_p( FEPWIN, (int)ch->board->port + 1);
258 static void pcxem_rxwinon(struct channel *ch)
260 outb_p(ch->rxwin, (int)ch->board->port + 1);
263 static void pcxem_txwinon(struct channel *ch)
265 outb_p(ch->txwin, (int)ch->board->port + 1);
268 static void pcxem_memoff(struct channel *ch)
270 outb_p(0, (int)ch->board->port + 1);
273 /* ----------------- Begin pcxe memory window stuff ------------------ */
274 static void pcxe_memwinon(struct board_info *b, unsigned int win)
276 outb_p(FEPWIN | win, b->port + 1);
279 static void pcxe_memwinoff(struct board_info *b, unsigned int win)
281 outb_p(inb(b->port) & ~FEPMEM, b->port + 1);
282 outb_p(0, b->port + 1);
285 static void pcxe_globalwinon(struct channel *ch)
287 outb_p(FEPWIN, (int)ch->board->port + 1);
290 static void pcxe_rxwinon(struct channel *ch)
292 outb_p(ch->rxwin, (int)ch->board->port + 1);
295 static void pcxe_txwinon(struct channel *ch)
297 outb_p(ch->txwin, (int)ch->board->port + 1);
300 static void pcxe_memoff(struct channel *ch)
302 outb_p(0, (int)ch->board->port);
303 outb_p(0, (int)ch->board->port + 1);
306 /* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
307 static void pcxi_memwinon(struct board_info *b, unsigned int win)
309 outb_p(inb(b->port) | FEPMEM, b->port);
312 static void pcxi_memwinoff(struct board_info *b, unsigned int win)
314 outb_p(inb(b->port) & ~FEPMEM, b->port);
317 static void pcxi_globalwinon(struct channel *ch)
319 outb_p(FEPMEM, ch->board->port);
322 static void pcxi_rxwinon(struct channel *ch)
324 outb_p(FEPMEM, ch->board->port);
327 static void pcxi_txwinon(struct channel *ch)
329 outb_p(FEPMEM, ch->board->port);
332 static void pcxi_memoff(struct channel *ch)
334 outb_p(0, ch->board->port);
337 static void pcxi_assertgwinon(struct channel *ch)
339 epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
342 static void pcxi_assertmemoff(struct channel *ch)
344 epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
348 * Not all of the cards need specific memory windowing routines. Some cards
349 * (Such as PCI) needs no windowing routines at all. We provide these do
350 * nothing routines so that the same code base can be used. The driver will
351 * ALWAYS call a windowing routine if it thinks it needs to; regardless of the
352 * card. However, dependent on the card the routine may or may not do anything.
354 static void dummy_memwinon(struct board_info *b, unsigned int win)
358 static void dummy_memwinoff(struct board_info *b, unsigned int win)
362 static void dummy_globalwinon(struct channel *ch)
366 static void dummy_rxwinon(struct channel *ch)
370 static void dummy_txwinon(struct channel *ch)
374 static void dummy_memoff(struct channel *ch)
378 static void dummy_assertgwinon(struct channel *ch)
382 static void dummy_assertmemoff(struct channel *ch)
386 static struct channel *verifyChannel(struct tty_struct *tty)
389 * This routine basically provides a sanity check. It insures that the
390 * channel returned is within the proper range of addresses as well as
391 * properly initialized. If some bogus info gets passed in
392 * through tty->driver_data this should catch it.
395 struct channel *ch = (struct channel *)tty->driver_data;
396 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs])) {
397 if (ch->magic == EPCA_MAGIC)
404 static void pc_sched_event(struct channel *ch, int event)
407 * We call this to schedule interrupt processing on some event. The
408 * kernel sees our request and calls the related routine in OUR driver.
410 ch->event |= 1 << event;
411 schedule_work(&ch->tqueue);
414 static void epca_error(int line, char *msg)
416 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
419 static void pc_close(struct tty_struct *tty, struct file *filp)
424 * verifyChannel returns the channel from the tty struct if it is
425 * valid. This serves as a sanity check.
427 if ((ch = verifyChannel(tty)) != NULL) {
428 spin_lock_irqsave(&epca_lock, flags);
429 if (tty_hung_up_p(filp)) {
430 spin_unlock_irqrestore(&epca_lock, flags);
433 if (ch->count-- > 1) {
434 /* Begin channel is open more than once */
436 * Return without doing anything. Someone might still
437 * be using the channel.
439 spin_unlock_irqrestore(&epca_lock, flags);
443 /* Port open only once go ahead with shutdown & reset */
444 BUG_ON(ch->count < 0);
447 * Let the rest of the driver know the channel is being closed.
448 * This becomes important if an open is attempted before close
451 ch->asyncflags |= ASYNC_CLOSING;
454 spin_unlock_irqrestore(&epca_lock, flags);
456 if (ch->asyncflags & ASYNC_INITIALIZED) {
457 /* Setup an event to indicate when the transmit buffer empties */
458 setup_empty_event(tty, ch);
459 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
461 pc_flush_buffer(tty);
463 tty_ldisc_flush(tty);
466 spin_lock_irqsave(&epca_lock, flags);
470 spin_unlock_irqrestore(&epca_lock, flags);
472 if (ch->blocked_open) {
474 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
475 wake_up_interruptible(&ch->open_wait);
477 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
479 wake_up_interruptible(&ch->close_wait);
483 static void shutdown(struct channel *ch)
486 struct tty_struct *tty;
487 struct board_chan __iomem *bc;
489 if (!(ch->asyncflags & ASYNC_INITIALIZED))
492 spin_lock_irqsave(&epca_lock, flags);
498 * In order for an event to be generated on the receipt of data the
499 * idata flag must be set. Since we are shutting down, this is not
500 * necessary clear this flag.
503 writeb(0, &bc->idata);
506 /* If we're a modem control device and HUPCL is on, drop RTS & DTR. */
507 if (tty->termios->c_cflag & HUPCL) {
508 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
509 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
514 * The channel has officialy been closed. The next time it is opened it
515 * will have to reinitialized. Set a flag to indicate this.
517 /* Prevent future Digi programmed interrupts from coming active */
518 ch->asyncflags &= ~ASYNC_INITIALIZED;
519 spin_unlock_irqrestore(&epca_lock, flags);
522 static void pc_hangup(struct tty_struct *tty)
527 * verifyChannel returns the channel from the tty struct if it is
528 * valid. This serves as a sanity check.
530 if ((ch = verifyChannel(tty)) != NULL) {
533 pc_flush_buffer(tty);
534 tty_ldisc_flush(tty);
537 spin_lock_irqsave(&epca_lock, flags);
541 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
542 spin_unlock_irqrestore(&epca_lock, flags);
543 wake_up_interruptible(&ch->open_wait);
547 static int pc_write(struct tty_struct *tty,
548 const unsigned char *buf, int bytesAvailable)
550 unsigned int head, tail;
557 struct board_chan __iomem *bc;
560 * pc_write is primarily called directly by the kernel routine
561 * tty_write (Though it can also be called by put_char) found in
562 * tty_io.c. pc_write is passed a line discipline buffer where the data
563 * to be written out is stored. The line discipline implementation
564 * itself is done at the kernel level and is not brought into the
569 * verifyChannel returns the channel from the tty struct if it is
570 * valid. This serves as a sanity check.
572 if ((ch = verifyChannel(tty)) == NULL)
575 /* Make a pointer to the channel data structure found on the board. */
577 size = ch->txbufsize;
580 spin_lock_irqsave(&epca_lock, flags);
583 head = readw(&bc->tin) & (size - 1);
584 tail = readw(&bc->tout);
586 if (tail != readw(&bc->tout))
587 tail = readw(&bc->tout);
591 /* head has not wrapped */
593 * remain (much like dataLen above) represents the total amount
594 * of space available on the card for data. Here dataLen
595 * represents the space existing between the head pointer and
596 * the end of buffer. This is important because a memcpy cannot
597 * be told to automatically wrap around when it hits the buffer
600 dataLen = size - head;
601 remain = size - (head - tail) - 1;
603 /* head has wrapped around */
604 remain = tail - head - 1;
608 * Check the space on the card. If we have more data than space; reduce
609 * the amount of data to fit the space.
611 bytesAvailable = min(remain, bytesAvailable);
613 while (bytesAvailable > 0) {
614 /* there is data to copy onto card */
617 * If head is not wrapped, the below will make sure the first
618 * data copy fills to the end of card buffer.
620 dataLen = min(bytesAvailable, dataLen);
621 memcpy_toio(ch->txptr + head, buf, dataLen);
624 amountCopied += dataLen;
625 bytesAvailable -= dataLen;
632 ch->statusflags |= TXBUSY;
634 writew(head, &bc->tin);
636 if ((ch->statusflags & LOWWAIT) == 0) {
637 ch->statusflags |= LOWWAIT;
638 writeb(1, &bc->ilow);
641 spin_unlock_irqrestore(&epca_lock, flags);
645 static int pc_write_room(struct tty_struct *tty)
650 unsigned int head, tail;
651 struct board_chan __iomem *bc;
656 * verifyChannel returns the channel from the tty struct if it is
657 * valid. This serves as a sanity check.
659 if ((ch = verifyChannel(tty)) != NULL) {
660 spin_lock_irqsave(&epca_lock, flags);
664 head = readw(&bc->tin) & (ch->txbufsize - 1);
665 tail = readw(&bc->tout);
667 if (tail != readw(&bc->tout))
668 tail = readw(&bc->tout);
669 /* Wrap tail if necessary */
670 tail &= (ch->txbufsize - 1);
672 if ((remain = tail - head - 1) < 0 )
673 remain += ch->txbufsize;
675 if (remain && (ch->statusflags & LOWWAIT) == 0) {
676 ch->statusflags |= LOWWAIT;
677 writeb(1, &bc->ilow);
680 spin_unlock_irqrestore(&epca_lock, flags);
682 /* Return how much room is left on card */
686 static int pc_chars_in_buffer(struct tty_struct *tty)
689 unsigned int ctail, head, tail;
693 struct board_chan __iomem *bc;
696 * verifyChannel returns the channel from the tty struct if it is
697 * valid. This serves as a sanity check.
699 if ((ch = verifyChannel(tty)) == NULL)
702 spin_lock_irqsave(&epca_lock, flags);
706 tail = readw(&bc->tout);
707 head = readw(&bc->tin);
708 ctail = readw(&ch->mailbox->cout);
710 if (tail == head && readw(&ch->mailbox->cin) == ctail && readb(&bc->tbusy) == 0)
712 else { /* Begin if some space on the card has been used */
713 head = readw(&bc->tin) & (ch->txbufsize - 1);
714 tail &= (ch->txbufsize - 1);
716 * The logic here is basically opposite of the above
717 * pc_write_room here we are finding the amount of bytes in the
718 * buffer filled. Not the amount of bytes empty.
720 if ((remain = tail - head - 1) < 0 )
721 remain += ch->txbufsize;
722 chars = (int)(ch->txbufsize - remain);
724 * Make it possible to wakeup anything waiting for output in
727 * If not already set. Setup an event to indicate when the
728 * transmit buffer empties.
730 if (!(ch->statusflags & EMPTYWAIT))
731 setup_empty_event(tty,ch);
732 } /* End if some space on the card has been used */
734 spin_unlock_irqrestore(&epca_lock, flags);
735 /* Return number of characters residing on card. */
739 static void pc_flush_buffer(struct tty_struct *tty)
744 struct board_chan __iomem *bc;
746 * verifyChannel returns the channel from the tty struct if it is
747 * valid. This serves as a sanity check.
749 if ((ch = verifyChannel(tty)) == NULL)
752 spin_lock_irqsave(&epca_lock, flags);
755 tail = readw(&bc->tout);
756 /* Have FEP move tout pointer; effectively flushing transmit buffer */
757 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
759 spin_unlock_irqrestore(&epca_lock, flags);
763 static void pc_flush_chars(struct tty_struct *tty)
767 * verifyChannel returns the channel from the tty struct if it is
768 * valid. This serves as a sanity check.
770 if ((ch = verifyChannel(tty)) != NULL) {
772 spin_lock_irqsave(&epca_lock, flags);
774 * If not already set and the transmitter is busy setup an
775 * event to indicate when the transmit empties.
777 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
778 setup_empty_event(tty,ch);
779 spin_unlock_irqrestore(&epca_lock, flags);
783 static int block_til_ready(struct tty_struct *tty,
784 struct file *filp, struct channel *ch)
786 DECLARE_WAITQUEUE(wait,current);
787 int retval, do_clocal = 0;
790 if (tty_hung_up_p(filp)) {
791 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
794 retval = -ERESTARTSYS;
799 * If the device is in the middle of being closed, then block until
800 * it's done, and then try again.
802 if (ch->asyncflags & ASYNC_CLOSING) {
803 interruptible_sleep_on(&ch->close_wait);
805 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
811 if (filp->f_flags & O_NONBLOCK) {
813 * If non-blocking mode is set, then make the check up front
816 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
819 if (tty->termios->c_cflag & CLOCAL)
821 /* Block waiting for the carrier detect and the line to become free */
824 add_wait_queue(&ch->open_wait, &wait);
826 spin_lock_irqsave(&epca_lock, flags);
827 /* We dec count so that pc_close will know when to free things */
828 if (!tty_hung_up_p(filp))
832 set_current_state(TASK_INTERRUPTIBLE);
833 if (tty_hung_up_p(filp) ||
834 !(ch->asyncflags & ASYNC_INITIALIZED))
836 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
839 retval = -ERESTARTSYS;
842 if (!(ch->asyncflags & ASYNC_CLOSING) &&
843 (do_clocal || (ch->imodem & ch->dcd)))
845 if (signal_pending(current)) {
846 retval = -ERESTARTSYS;
849 spin_unlock_irqrestore(&epca_lock, flags);
851 * Allow someone else to be scheduled. We will occasionally go
852 * through this loop until one of the above conditions change.
853 * The below schedule call will allow other processes to enter
854 * and prevent this loop from hogging the cpu.
857 spin_lock_irqsave(&epca_lock, flags);
860 __set_current_state(TASK_RUNNING);
861 remove_wait_queue(&ch->open_wait, &wait);
862 if (!tty_hung_up_p(filp))
866 spin_unlock_irqrestore(&epca_lock, flags);
871 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
875 static int pc_open(struct tty_struct *tty, struct file * filp)
879 int line, retval, boardnum;
880 struct board_chan __iomem *bc;
884 if (line < 0 || line >= nbdevs)
887 ch = &digi_channels[line];
888 boardnum = ch->boardnum;
890 /* Check status of board configured in system. */
893 * I check to see if the epca_setup routine detected an user error. It
894 * might be better to put this in pc_init, but for the moment it goes
897 if (invalid_lilo_config) {
898 if (setup_error_code & INVALID_BOARD_TYPE)
899 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
900 if (setup_error_code & INVALID_NUM_PORTS)
901 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
902 if (setup_error_code & INVALID_MEM_BASE)
903 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
904 if (setup_error_code & INVALID_PORT_BASE)
905 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
906 if (setup_error_code & INVALID_BOARD_STATUS)
907 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
908 if (setup_error_code & INVALID_ALTPIN)
909 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
910 tty->driver_data = NULL; /* Mark this device as 'down' */
913 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
914 tty->driver_data = NULL; /* Mark this device as 'down' */
920 tty->driver_data = NULL;
924 spin_lock_irqsave(&epca_lock, flags);
926 * Every time a channel is opened, increment a counter. This is
927 * necessary because we do not wish to flush and shutdown the channel
928 * until the last app holding the channel open, closes it.
932 * Set a kernel structures pointer to our local channel structure. This
933 * way we can get to it when passed only a tty struct.
935 tty->driver_data = ch;
937 * If this is the first time the channel has been opened, initialize
938 * the tty->termios struct otherwise let pc_close handle it.
943 /* Save boards current modem status */
944 ch->imodem = readb(&bc->mstat);
947 * Set receive head and tail ptrs to each other. This indicates no data
950 head = readw(&bc->rin);
951 writew(head, &bc->rout);
953 /* Set the channels associated tty structure */
957 * The below routine generally sets up parity, baud, flow control
958 * issues, etc.... It effect both control flags and input flags.
961 ch->asyncflags |= ASYNC_INITIALIZED;
963 spin_unlock_irqrestore(&epca_lock, flags);
965 retval = block_til_ready(tty, filp, ch);
969 * Set this again in case a hangup set it to zero while this open() was
970 * waiting for the line...
972 spin_lock_irqsave(&epca_lock, flags);
975 /* Enable Digi Data events */
976 writeb(1, &bc->idata);
978 spin_unlock_irqrestore(&epca_lock, flags);
982 static int __init epca_module_init(void)
986 module_init(epca_module_init);
988 static struct pci_driver epca_driver;
990 static void __exit epca_module_exit(void)
993 struct board_info *bd;
996 del_timer_sync(&epca_timer);
998 if (tty_unregister_driver(pc_driver) || tty_unregister_driver(pc_info))
1000 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
1003 put_tty_driver(pc_driver);
1004 put_tty_driver(pc_info);
1006 for (crd = 0; crd < num_cards; crd++) {
1008 if (!bd) { /* sanity check */
1009 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1013 for (count = 0; count < bd->numports; count++, ch++) {
1015 tty_hangup(ch->tty);
1018 pci_unregister_driver(&epca_driver);
1020 module_exit(epca_module_exit);
1022 static const struct tty_operations pc_ops = {
1026 .write_room = pc_write_room,
1027 .flush_buffer = pc_flush_buffer,
1028 .chars_in_buffer = pc_chars_in_buffer,
1029 .flush_chars = pc_flush_chars,
1031 .set_termios = pc_set_termios,
1034 .throttle = pc_throttle,
1035 .unthrottle = pc_unthrottle,
1036 .hangup = pc_hangup,
1039 static int info_open(struct tty_struct *tty, struct file * filp)
1044 static struct tty_operations info_ops = {
1046 .ioctl = info_ioctl,
1049 static int __init pc_init(void)
1052 struct board_info *bd;
1053 unsigned char board_id = 0;
1056 int pci_boards_found, pci_count;
1060 pc_driver = alloc_tty_driver(MAX_ALLOC);
1064 pc_info = alloc_tty_driver(MAX_ALLOC);
1069 * If epca_setup has not been ran by LILO set num_cards to defaults;
1070 * copy board structure defined by digiConfig into drivers board
1071 * structure. Note : If LILO has ran epca_setup then epca_setup will
1072 * handle defining num_cards as well as copying the data into the board
1076 /* driver has been configured via. epcaconfig */
1078 num_cards = NUMCARDS;
1079 memcpy(&boards, &static_boards,
1080 sizeof(struct board_info) * NUMCARDS);
1084 * Note : If lilo was used to configure the driver and the ignore
1085 * epcaconfig option was choosen (digiepca=2) then nbdevs and num_cards
1086 * will equal 0 at this point. This is okay; PCI cards will still be
1087 * picked up if detected.
1091 * Set up interrupt, we will worry about memory allocation in
1094 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1097 * NOTE : This code assumes that the number of ports found in the
1098 * boards array is correct. This could be wrong if the card in question
1099 * is PCI (And therefore has no ports entry in the boards structure.)
1100 * The rest of the information will be valid for PCI because the
1101 * beginning of pc_init scans for PCI and determines i/o and base
1102 * memory addresses. I am not sure if it is possible to read the number
1103 * of ports supported by the card prior to it being booted (Since that
1104 * is the state it is in when pc_init is run). Because it is not
1105 * possible to query the number of supported ports until after the card
1106 * has booted; we are required to calculate the card_ptrs as the card
1107 * is initialized (Inside post_fep_init). The negative thing about this
1108 * approach is that digiDload's call to GET_INFO will have a bad port
1109 * value. (Since this is called prior to post_fep_init.)
1111 pci_boards_found = 0;
1112 if (num_cards < MAXBOARDS)
1113 pci_boards_found += init_PCI();
1114 num_cards += pci_boards_found;
1116 pc_driver->owner = THIS_MODULE;
1117 pc_driver->name = "ttyD";
1118 pc_driver->major = DIGI_MAJOR;
1119 pc_driver->minor_start = 0;
1120 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1121 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1122 pc_driver->init_termios = tty_std_termios;
1123 pc_driver->init_termios.c_iflag = 0;
1124 pc_driver->init_termios.c_oflag = 0;
1125 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1126 pc_driver->init_termios.c_lflag = 0;
1127 pc_driver->init_termios.c_ispeed = 9600;
1128 pc_driver->init_termios.c_ospeed = 9600;
1129 pc_driver->flags = TTY_DRIVER_REAL_RAW;
1130 tty_set_operations(pc_driver, &pc_ops);
1132 pc_info->owner = THIS_MODULE;
1133 pc_info->name = "digi_ctl";
1134 pc_info->major = DIGIINFOMAJOR;
1135 pc_info->minor_start = 0;
1136 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1137 pc_info->subtype = SERIAL_TYPE_INFO;
1138 pc_info->init_termios = tty_std_termios;
1139 pc_info->init_termios.c_iflag = 0;
1140 pc_info->init_termios.c_oflag = 0;
1141 pc_info->init_termios.c_lflag = 0;
1142 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1143 pc_info->init_termios.c_ispeed = 9600;
1144 pc_info->init_termios.c_ospeed = 9600;
1145 pc_info->flags = TTY_DRIVER_REAL_RAW;
1146 tty_set_operations(pc_info, &info_ops);
1149 for (crd = 0; crd < num_cards; crd++) {
1151 * This is where the appropriate memory handlers for the
1152 * hardware is set. Everything at runtime blindly jumps through
1156 /* defined in epcaconfig.h */
1162 bd->memwinon = pcxem_memwinon;
1163 bd->memwinoff = pcxem_memwinoff;
1164 bd->globalwinon = pcxem_globalwinon;
1165 bd->txwinon = pcxem_txwinon;
1166 bd->rxwinon = pcxem_rxwinon;
1167 bd->memoff = pcxem_memoff;
1168 bd->assertgwinon = dummy_assertgwinon;
1169 bd->assertmemoff = dummy_assertmemoff;
1175 bd->memwinon = dummy_memwinon;
1176 bd->memwinoff = dummy_memwinoff;
1177 bd->globalwinon = dummy_globalwinon;
1178 bd->txwinon = dummy_txwinon;
1179 bd->rxwinon = dummy_rxwinon;
1180 bd->memoff = dummy_memoff;
1181 bd->assertgwinon = dummy_assertgwinon;
1182 bd->assertmemoff = dummy_assertmemoff;
1187 bd->memwinon = pcxe_memwinon;
1188 bd->memwinoff = pcxe_memwinoff;
1189 bd->globalwinon = pcxe_globalwinon;
1190 bd->txwinon = pcxe_txwinon;
1191 bd->rxwinon = pcxe_rxwinon;
1192 bd->memoff = pcxe_memoff;
1193 bd->assertgwinon = dummy_assertgwinon;
1194 bd->assertmemoff = dummy_assertmemoff;
1199 bd->memwinon = pcxi_memwinon;
1200 bd->memwinoff = pcxi_memwinoff;
1201 bd->globalwinon = pcxi_globalwinon;
1202 bd->txwinon = pcxi_txwinon;
1203 bd->rxwinon = pcxi_rxwinon;
1204 bd->memoff = pcxi_memoff;
1205 bd->assertgwinon = pcxi_assertgwinon;
1206 bd->assertmemoff = pcxi_assertmemoff;
1214 * Some cards need a memory segment to be defined for use in
1215 * transmit and receive windowing operations. These boards are
1216 * listed in the below switch. In the case of the XI the amount
1217 * of memory on the board is variable so the memory_seg is also
1218 * variable. This code determines what they segment should be.
1224 bd->memory_seg = 0xf000;
1228 board_id = inb((int)bd->port);
1229 if ((board_id & 0x1) == 0x1) {
1230 /* it's an XI card */
1231 /* Is it a 64K board */
1232 if ((board_id & 0x30) == 0)
1233 bd->memory_seg = 0xf000;
1235 /* Is it a 128K board */
1236 if ((board_id & 0x30) == 0x10)
1237 bd->memory_seg = 0xe000;
1239 /* Is is a 256K board */
1240 if ((board_id & 0x30) == 0x20)
1241 bd->memory_seg = 0xc000;
1243 /* Is it a 512K board */
1244 if ((board_id & 0x30) == 0x30)
1245 bd->memory_seg = 0x8000;
1247 printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
1252 err = tty_register_driver(pc_driver);
1254 printk(KERN_ERR "Couldn't register Digi PC/ driver");
1258 err = tty_register_driver(pc_info);
1260 printk(KERN_ERR "Couldn't register Digi PC/ info ");
1264 /* Start up the poller to check for events on all enabled boards */
1265 init_timer(&epca_timer);
1266 epca_timer.function = epcapoll;
1267 mod_timer(&epca_timer, jiffies + HZ/25);
1271 tty_unregister_driver(pc_driver);
1273 put_tty_driver(pc_info);
1275 put_tty_driver(pc_driver);
1280 static void post_fep_init(unsigned int crd)
1283 void __iomem *memaddr;
1284 struct global_data __iomem *gd;
1285 struct board_info *bd;
1286 struct board_chan __iomem *bc;
1288 int shrinkmem = 0, lowwater;
1291 * This call is made by the user via. the ioctl call DIGI_INIT. It is
1292 * responsible for setting up all the card specific stuff.
1297 * If this is a PCI board, get the port info. Remember PCI cards do not
1298 * have entries into the epcaconfig.h file, so we can't get the number
1299 * of ports from it. Unfortunetly, this means that anyone doing a
1300 * DIGI_GETINFO before the board has booted will get an invalid number
1301 * of ports returned (It should return 0). Calls to DIGI_GETINFO after
1302 * DIGI_INIT has been called will return the proper values.
1304 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
1306 * Below we use XEMPORTS as a memory offset regardless of which
1307 * PCI card it is. This is because all of the supported PCI
1308 * cards have the same memory offset for the channel data. This
1309 * will have to be changed if we ever develop a PCI/XE card.
1310 * NOTE : The FEP manual states that the port offset is 0xC22
1311 * as opposed to 0xC02. This is only true for PC/XE, and PC/XI
1312 * cards; not for the XEM, or CX series. On the PCI cards the
1313 * number of ports is determined by reading a ID PROM located
1314 * in the box attached to the card. The card can then determine
1315 * the index the id to determine the number of ports available.
1316 * (FYI - The id should be located at 0x1ac (And may use up to
1317 * 4 bytes if the box in question is a XEM or CX)).
1319 /* PCI cards are already remapped at this point ISA are not */
1320 bd->numports = readw(bd->re_map_membase + XEMPORTS);
1321 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1322 nbdevs += (bd->numports);
1324 /* Fix up the mappings for ISA/EISA etc */
1325 /* FIXME: 64K - can we be smarter ? */
1326 bd->re_map_membase = ioremap(bd->membase, 0x10000);
1330 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1332 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1335 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1337 memaddr = bd->re_map_membase;
1340 * The below assignment will set bc to point at the BEGINING of the
1341 * cards channel structures. For 1 card there will be between 8 and 64
1342 * of these structures.
1344 bc = memaddr + CHANSTRUCT;
1347 * The below assignment will set gd to point at the BEGINING of global
1348 * memory address 0xc00. The first data in that global memory actually
1349 * starts at address 0xc1a. The command in pointer begins at 0xd10.
1351 gd = memaddr + GLOBAL;
1354 * XEPORTS (address 0xc22) points at the number of channels the card
1355 * supports. (For 64XE, XI, XEM, and XR use 0xc02)
1357 if ((bd->type == PCXEVE || bd->type == PCXE) && (readw(memaddr + XEPORTS) < 3))
1359 if (bd->type < PCIXEM)
1360 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1365 * Remember ch is the main drivers channels structure, while bc is the
1366 * cards channel structure.
1368 for (i = 0; i < bd->numports; i++, ch++, bc++) {
1369 unsigned long flags;
1374 INIT_WORK(&ch->tqueue, do_softint);
1375 ch->board = &boards[crd];
1377 spin_lock_irqsave(&epca_lock, flags);
1380 * Since some of the boards use different bitmaps for
1381 * their control signals we cannot hard code these
1382 * values and retain portability. We virtualize this
1411 if (boards[crd].altpin) {
1412 ch->dsr = ch->m_dcd;
1413 ch->dcd = ch->m_dsr;
1414 ch->digiext.digi_flags |= DIGI_ALTPIN;
1416 ch->dcd = ch->m_dcd;
1417 ch->dsr = ch->m_dsr;
1422 ch->magic = EPCA_MAGIC;
1426 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1430 tseg = readw(&bc->tseg);
1431 rseg = readw(&bc->rseg);
1437 /* Cover all the 2MEG cards */
1438 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1439 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1440 ch->txwin = FEPWIN | (tseg >> 11);
1441 ch->rxwin = FEPWIN | (rseg >> 11);
1446 /* Cover all the 32K windowed cards */
1447 /* Mask equal to window size - 1 */
1448 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1449 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1450 ch->txwin = FEPWIN | (tseg >> 11);
1451 ch->rxwin = FEPWIN | (rseg >> 11);
1456 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4) & 0x1fff);
1457 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1458 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4) & 0x1fff);
1459 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >>9 );
1464 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1465 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
1466 ch->txwin = ch->rxwin = 0;
1471 ch->txbufsize = readw(&bc->tmax) + 1;
1474 ch->rxbufsize = readw(&bc->rmax) + 1;
1476 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1478 /* Set transmitter low water mark */
1479 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1481 /* Set receiver low water mark */
1482 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
1484 /* Set receiver high water mark */
1485 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1487 writew(100, &bc->edelay);
1488 writeb(1, &bc->idata);
1490 ch->startc = readb(&bc->startc);
1491 ch->stopc = readb(&bc->stopc);
1492 ch->startca = readb(&bc->startca);
1493 ch->stopca = readb(&bc->stopca);
1503 ch->close_delay = 50;
1505 ch->blocked_open = 0;
1506 init_waitqueue_head(&ch->open_wait);
1507 init_waitqueue_head(&ch->close_wait);
1509 spin_unlock_irqrestore(&epca_lock, flags);
1513 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1514 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
1518 static void epcapoll(unsigned long ignored)
1520 unsigned long flags;
1522 volatile unsigned int head, tail;
1524 struct board_info *bd;
1527 * This routine is called upon every timer interrupt. Even though the
1528 * Digi series cards are capable of generating interrupts this method
1529 * of non-looping polling is more efficient. This routine checks for
1530 * card generated events (Such as receive data, are transmit buffer
1531 * empty) and acts on those events.
1533 for (crd = 0; crd < num_cards; crd++) {
1537 if ((bd->status == DISABLED) || digi_poller_inhibited)
1541 * assertmemoff is not needed here; indeed it is an empty
1542 * subroutine. It is being kept because future boards may need
1543 * this as well as some legacy boards.
1545 spin_lock_irqsave(&epca_lock, flags);
1552 * In this case head and tail actually refer to the event queue
1553 * not the transmit or receive queue.
1555 head = readw(&ch->mailbox->ein);
1556 tail = readw(&ch->mailbox->eout);
1558 /* If head isn't equal to tail we have an event */
1563 spin_unlock_irqrestore(&epca_lock, flags);
1564 } /* End for each card */
1565 mod_timer(&epca_timer, jiffies + (HZ / 25));
1568 static void doevent(int crd)
1570 void __iomem *eventbuf;
1571 struct channel *ch, *chan0;
1572 static struct tty_struct *tty;
1573 struct board_info *bd;
1574 struct board_chan __iomem *bc;
1575 unsigned int tail, head;
1580 * This subroutine is called by epcapoll when an event is detected
1581 * in the event queue. This routine responds to those events.
1585 chan0 = card_ptr[crd];
1586 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
1587 assertgwinon(chan0);
1588 while ((tail = readw(&chan0->mailbox->eout)) != (head = readw(&chan0->mailbox->ein))) { /* Begin while something in event queue */
1589 assertgwinon(chan0);
1590 eventbuf = bd->re_map_membase + tail + ISTART;
1591 /* Get the channel the event occurred on */
1592 channel = readb(eventbuf);
1593 /* Get the actual event code that occurred */
1594 event = readb(eventbuf + 1);
1596 * The two assignments below get the current modem status
1597 * (mstat) and the previous modem status (lstat). These are
1598 * useful becuase an event could signal a change in modem
1601 mstat = readb(eventbuf + 2);
1602 lstat = readb(eventbuf + 3);
1604 ch = chan0 + channel;
1605 if ((unsigned)channel >= bd->numports || !ch) {
1606 if (channel >= bd->numports)
1612 if ((bc = ch->brdchan) == NULL)
1615 if (event & DATA_IND) { /* Begin DATA_IND */
1618 } /* End DATA_IND */
1619 /* else *//* Fix for DCD transition missed bug */
1620 if (event & MODEMCHG_IND) {
1621 /* A modem signal change has been indicated */
1623 if (ch->asyncflags & ASYNC_CHECK_CD) {
1624 if (mstat & ch->dcd) /* We are now receiving dcd */
1625 wake_up_interruptible(&ch->open_wait);
1627 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
1632 if (event & BREAK_IND) {
1633 /* A break has been indicated */
1634 tty_insert_flip_char(tty, 0, TTY_BREAK);
1635 tty_schedule_flip(tty);
1636 } else if (event & LOWTX_IND) {
1637 if (ch->statusflags & LOWWAIT) {
1638 ch->statusflags &= ~LOWWAIT;
1641 } else if (event & EMPTYTX_IND) {
1642 /* This event is generated by setup_empty_event */
1643 ch->statusflags &= ~TXBUSY;
1644 if (ch->statusflags & EMPTYWAIT) {
1645 ch->statusflags &= ~EMPTYWAIT;
1653 writew(1, &bc->idata);
1654 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
1656 } /* End while something in event queue */
1659 static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1660 int byte2, int ncmds, int bytecmd)
1662 unchar __iomem *memaddr;
1663 unsigned int head, cmdTail, cmdStart, cmdMax;
1667 /* This is the routine in which commands may be passed to the card. */
1669 if (ch->board->status == DISABLED)
1672 /* Remember head (As well as max) is just an offset not a base addr */
1673 head = readw(&ch->mailbox->cin);
1674 /* cmdStart is a base address */
1675 cmdStart = readw(&ch->mailbox->cstart);
1677 * We do the addition below because we do not want a max pointer
1678 * relative to cmdStart. We want a max pointer that points at the
1679 * physical end of the command queue.
1681 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
1682 memaddr = ch->board->re_map_membase;
1684 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1685 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__, cmd, head);
1686 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__, cmdMax, cmdStart);
1690 writeb(cmd, memaddr + head + cmdStart + 0);
1691 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1692 /* Below word_or_byte is bits to set */
1693 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1694 /* Below byte2 is bits to reset */
1695 writeb(byte2, memaddr + head + cmdStart + 3);
1697 writeb(cmd, memaddr + head + cmdStart + 0);
1698 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1699 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1701 head = (head + 4) & (cmdMax - cmdStart - 4);
1702 writew(head, &ch->mailbox->cin);
1708 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1711 head = readw(&ch->mailbox->cin);
1712 cmdTail = readw(&ch->mailbox->cout);
1713 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
1715 * Basically this will break when the FEP acknowledges the
1716 * command by incrementing cmdTail (Making it equal to head).
1718 if (n <= ncmds * (sizeof(short) * 4))
1724 * Digi products use fields in their channels structures that are very similar
1725 * to the c_cflag and c_iflag fields typically found in UNIX termios
1726 * structures. The below three routines allow mappings between these hardware
1727 * "flags" and their respective Linux flags.
1729 static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
1733 if (cflag & CRTSCTS) {
1734 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1735 res |= ((ch->m_cts) | (ch->m_rts));
1738 if (ch->digiext.digi_flags & RTSPACE)
1741 if (ch->digiext.digi_flags & DTRPACE)
1744 if (ch->digiext.digi_flags & CTSPACE)
1747 if (ch->digiext.digi_flags & DSRPACE)
1750 if (ch->digiext.digi_flags & DCDPACE)
1753 if (res & (ch->m_rts))
1754 ch->digiext.digi_flags |= RTSPACE;
1756 if (res & (ch->m_cts))
1757 ch->digiext.digi_flags |= CTSPACE;
1762 static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
1764 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
1765 INPCK | ISTRIP|IXON|IXANY|IXOFF);
1766 if (ch->digiext.digi_flags & DIGI_AIXON)
1771 static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
1774 if (cflag & CBAUDEX) {
1775 ch->digiext.digi_flags |= DIGI_FAST;
1777 * HUPCL bit is used by FEP to indicate fast baud table is to
1782 ch->digiext.digi_flags &= ~DIGI_FAST;
1784 * CBAUD has bit position 0x1000 set these days to indicate Linux
1785 * baud rate remap. Digi hardware can't handle the bit assignment.
1786 * (We use a different bit assignment for high speed.). Clear this
1789 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
1791 * This gets a little confusing. The Digi cards have their own
1792 * representation of c_cflags controlling baud rate. For the most part
1793 * this is identical to the Linux implementation. However; Digi
1794 * supports one rate (76800) that Linux doesn't. This means that the
1795 * c_cflag entry that would normally mean 76800 for Digi actually means
1796 * 115200 under Linux. Without the below mapping, a stty 115200 would
1797 * only drive the board at 76800. Since the rate 230400 is also found
1798 * after 76800, the same problem afflicts us when we choose a rate of
1799 * 230400. Without the below modificiation stty 230400 would actually
1802 * There are two additional differences. The Linux value for CLOCAL
1803 * (0x800; 0004000) has no meaning to the Digi hardware. Also in later
1804 * releases of Linux; the CBAUD define has CBAUDEX (0x1000; 0010000)
1805 * ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX should be
1806 * checked for a screened out prior to termios2digi_c returning. Since
1807 * CLOCAL isn't used by the board this can be ignored as long as the
1808 * returned value is used only by Digi hardware.
1810 if (cflag & CBAUDEX) {
1812 * The below code is trying to guarantee that only baud rates
1813 * 115200 and 230400 are remapped. We use exclusive or because
1814 * the various baud rates share common bit positions and
1815 * therefore can't be tested for easily.
1817 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
1818 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
1824 /* Caller must hold the locks */
1825 static void epcaparam(struct tty_struct *tty, struct channel *ch)
1827 unsigned int cmdHead;
1828 struct ktermios *ts;
1829 struct board_chan __iomem *bc;
1830 unsigned mval, hflow, cflag, iflag;
1833 epcaassert(bc != NULL, "bc out of range");
1837 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
1838 cmdHead = readw(&bc->rin);
1839 writew(cmdHead, &bc->rout);
1840 cmdHead = readw(&bc->tin);
1841 /* Changing baud in mid-stream transmission can be wonderful */
1843 * Flush current transmit buffer by setting cmdTail pointer
1844 * (tout) to cmdHead pointer (tin). Hopefully the transmit
1847 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
1849 } else { /* Begin CBAUD not detected */
1851 * c_cflags have changed but that change had nothing to do with
1852 * BAUD. Propagate the change to the card.
1854 cflag = termios2digi_c(ch, ts->c_cflag);
1855 if (cflag != ch->fepcflag) {
1856 ch->fepcflag = cflag;
1857 /* Set baud rate, char size, stop bits, parity */
1858 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
1861 * If the user has not forced CLOCAL and if the device is not a
1862 * CALLOUT device (Which is always CLOCAL) we set flags such
1863 * that the driver will wait on carrier detect.
1865 if (ts->c_cflag & CLOCAL)
1866 ch->asyncflags &= ~ASYNC_CHECK_CD;
1868 ch->asyncflags |= ASYNC_CHECK_CD;
1869 mval = ch->m_dtr | ch->m_rts;
1870 } /* End CBAUD not detected */
1871 iflag = termios2digi_i(ch, ts->c_iflag);
1872 /* Check input mode flags */
1873 if (iflag != ch->fepiflag) {
1874 ch->fepiflag = iflag;
1876 * Command sets channels iflag structure on the board. Such
1877 * things as input soft flow control, handling of parity
1878 * errors, and break handling are all set here.
1880 /* break handling, parity handling, input stripping, flow control chars */
1881 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
1884 * Set the board mint value for this channel. This will cause hardware
1885 * events to be generated each time the DCD signal (Described in mint)
1888 writeb(ch->dcd, &bc->mint);
1889 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
1890 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
1891 writeb(0, &bc->mint);
1892 ch->imodem = readb(&bc->mstat);
1893 hflow = termios2digi_h(ch, ts->c_cflag);
1894 if (hflow != ch->hflow) {
1897 * Hard flow control has been selected but the board is not
1898 * using it. Activate hard flow control now.
1900 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
1902 mval ^= ch->modemfake & (mval ^ ch->modem);
1904 if (ch->omodem ^ mval) {
1907 * The below command sets the DTR and RTS mstat structure. If
1908 * hard flow control is NOT active these changes will drive the
1909 * output of the actual DTR and RTS lines. If hard flow control
1910 * is active, the changes will be saved in the mstat structure
1911 * and only asserted when hard flow control is turned off.
1914 /* First reset DTR & RTS; then set them */
1915 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
1916 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
1918 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
1919 ch->fepstartc = ch->startc;
1920 ch->fepstopc = ch->stopc;
1922 * The XON / XOFF characters have changed; propagate these
1923 * changes to the card.
1925 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
1927 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
1928 ch->fepstartca = ch->startca;
1929 ch->fepstopca = ch->stopca;
1931 * Similar to the above, this time the auxilarly XON / XOFF
1932 * characters have changed; propagate these changes to the card.
1934 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
1938 /* Caller holds lock */
1939 static void receive_data(struct channel *ch)
1942 struct ktermios *ts = NULL;
1943 struct tty_struct *tty;
1944 struct board_chan __iomem *bc;
1945 int dataToRead, wrapgap, bytesAvailable;
1946 unsigned int tail, head;
1947 unsigned int wrapmask;
1950 * This routine is called by doint when a receive data event has taken
1954 if (ch->statusflags & RXSTOPPED)
1961 wrapmask = ch->rxbufsize - 1;
1964 * Get the head and tail pointers to the receiver queue. Wrap the head
1965 * pointer if it has reached the end of the buffer.
1967 head = readw(&bc->rin);
1969 tail = readw(&bc->rout) & wrapmask;
1971 bytesAvailable = (head - tail) & wrapmask;
1972 if (bytesAvailable == 0)
1975 /* If CREAD bit is off or device not open, set TX tail to head */
1976 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
1977 writew(head, &bc->rout);
1981 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
1984 if (readb(&bc->orun)) {
1985 writeb(0, &bc->orun);
1986 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",tty->name);
1987 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
1990 while (bytesAvailable > 0) { /* Begin while there is data on the card */
1991 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
1993 * Even if head has wrapped around only report the amount of
1994 * data to be equal to the size - tail. Remember memcpy can't
1995 * automaticly wrap around the receive buffer.
1997 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
1998 /* Make sure we don't overflow the buffer */
1999 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
2000 if (dataToRead == 0)
2003 * Move data read from our card into the line disciplines
2004 * buffer for translation if necessary.
2006 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
2007 tail = (tail + dataToRead) & wrapmask;
2008 bytesAvailable -= dataToRead;
2009 } /* End while there is data on the card */
2011 writew(tail, &bc->rout);
2012 /* Must be called with global data */
2013 tty_schedule_flip(ch->tty);
2016 static int info_ioctl(struct tty_struct *tty, struct file *file,
2017 unsigned int cmd, unsigned long arg)
2022 struct digi_info di;
2025 if (get_user(brd, (unsigned int __user *)arg))
2027 if (brd < 0 || brd >= num_cards || num_cards == 0)
2030 memset(&di, 0, sizeof(di));
2033 di.status = boards[brd].status;
2034 di.type = boards[brd].type ;
2035 di.numports = boards[brd].numports ;
2036 /* Legacy fixups - just move along nothing to see */
2037 di.port = (unsigned char *)boards[brd].port ;
2038 di.membase = (unsigned char *)boards[brd].membase ;
2040 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
2048 int brd = arg & 0xff000000 >> 16;
2049 unsigned char state = arg & 0xff;
2051 if (brd < 0 || brd >= num_cards) {
2052 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
2055 digi_poller_inhibited = state;
2062 * This call is made by the apps to complete the
2063 * initialization of the board(s). This routine is
2064 * responsible for setting the card to its initial
2065 * state and setting the drivers control fields to the
2066 * sutianle settings for the card in question.
2069 for (crd = 0; crd < num_cards; crd++)
2079 static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2081 struct channel *ch = (struct channel *) tty->driver_data;
2082 struct board_chan __iomem *bc;
2083 unsigned int mstat, mflag = 0;
2084 unsigned long flags;
2091 spin_lock_irqsave(&epca_lock, flags);
2093 mstat = readb(&bc->mstat);
2095 spin_unlock_irqrestore(&epca_lock, flags);
2097 if (mstat & ch->m_dtr)
2099 if (mstat & ch->m_rts)
2101 if (mstat & ch->m_cts)
2103 if (mstat & ch->dsr)
2105 if (mstat & ch->m_ri)
2107 if (mstat & ch->dcd)
2112 static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2113 unsigned int set, unsigned int clear)
2115 struct channel *ch = (struct channel *) tty->driver_data;
2116 unsigned long flags;
2121 spin_lock_irqsave(&epca_lock, flags);
2123 * I think this modemfake stuff is broken. It doesn't correctly reflect
2124 * the behaviour desired by the TIOCM* ioctls. Therefore this is
2127 if (set & TIOCM_RTS) {
2128 ch->modemfake |= ch->m_rts;
2129 ch->modem |= ch->m_rts;
2131 if (set & TIOCM_DTR) {
2132 ch->modemfake |= ch->m_dtr;
2133 ch->modem |= ch->m_dtr;
2135 if (clear & TIOCM_RTS) {
2136 ch->modemfake |= ch->m_rts;
2137 ch->modem &= ~ch->m_rts;
2139 if (clear & TIOCM_DTR) {
2140 ch->modemfake |= ch->m_dtr;
2141 ch->modem &= ~ch->m_dtr;
2145 * The below routine generally sets up parity, baud, flow control
2146 * issues, etc.... It effect both control flags and input flags.
2150 spin_unlock_irqrestore(&epca_lock, flags);
2154 static int pc_ioctl(struct tty_struct *tty, struct file * file,
2155 unsigned int cmd, unsigned long arg)
2159 unsigned long flags;
2160 unsigned int mflag, mstat;
2161 unsigned char startc, stopc;
2162 struct board_chan __iomem *bc;
2163 struct channel *ch = (struct channel *) tty->driver_data;
2164 void __user *argp = (void __user *)arg;
2172 * For POSIX compliance we need to add more ioctls. See tty_ioctl.c in
2173 * /usr/src/linux/drivers/char for a good example. In particular think
2174 * about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
2177 case TCSBRK: /* SVID version: non-zero arg --> no break */
2178 retval = tty_check_change(tty);
2181 /* Setup an event to indicate when the transmit buffer empties */
2182 spin_lock_irqsave(&epca_lock, flags);
2183 setup_empty_event(tty,ch);
2184 spin_unlock_irqrestore(&epca_lock, flags);
2185 tty_wait_until_sent(tty, 0);
2187 digi_send_break(ch, HZ / 4); /* 1/4 second */
2189 case TCSBRKP: /* support for POSIX tcsendbreak() */
2190 retval = tty_check_change(tty);
2194 /* Setup an event to indicate when the transmit buffer empties */
2195 spin_lock_irqsave(&epca_lock, flags);
2196 setup_empty_event(tty,ch);
2197 spin_unlock_irqrestore(&epca_lock, flags);
2198 tty_wait_until_sent(tty, 0);
2199 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
2202 mflag = pc_tiocmget(tty, file);
2203 if (put_user(mflag, (unsigned long __user *)argp))
2207 if (get_user(mstat, (unsigned __user *)argp))
2209 return pc_tiocmset(tty, file, mstat, ~mstat);
2211 spin_lock_irqsave(&epca_lock, flags);
2212 ch->omodem |= ch->m_dtr;
2214 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2216 spin_unlock_irqrestore(&epca_lock, flags);
2220 spin_lock_irqsave(&epca_lock, flags);
2221 ch->omodem &= ~ch->m_dtr;
2223 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2225 spin_unlock_irqrestore(&epca_lock, flags);
2228 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2234 if (cmd == DIGI_SETAW) {
2235 /* Setup an event to indicate when the transmit buffer empties */
2236 spin_lock_irqsave(&epca_lock, flags);
2237 setup_empty_event(tty,ch);
2238 spin_unlock_irqrestore(&epca_lock, flags);
2239 tty_wait_until_sent(tty, 0);
2241 /* ldisc lock already held in ioctl */
2242 if (tty->ldisc.flush_buffer)
2243 tty->ldisc.flush_buffer(tty);
2248 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2251 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
2252 ch->dcd = ch->m_dsr;
2253 ch->dsr = ch->m_dcd;
2255 ch->dcd = ch->m_dcd;
2256 ch->dsr = ch->m_dsr;
2259 spin_lock_irqsave(&epca_lock, flags);
2263 * The below routine generally sets up parity, baud, flow
2264 * control issues, etc.... It effect both control flags and
2269 spin_unlock_irqrestore(&epca_lock, flags);
2274 spin_lock_irqsave(&epca_lock, flags);
2276 if (cmd == DIGI_GETFLOW) {
2277 dflow.startc = readb(&bc->startc);
2278 dflow.stopc = readb(&bc->stopc);
2280 dflow.startc = readb(&bc->startca);
2281 dflow.stopc = readb(&bc->stopca);
2284 spin_unlock_irqrestore(&epca_lock, flags);
2286 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2292 if (cmd == DIGI_SETFLOW) {
2293 startc = ch->startc;
2296 startc = ch->startca;
2300 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2303 if (dflow.startc != startc || dflow.stopc != stopc) { /* Begin if setflow toggled */
2304 spin_lock_irqsave(&epca_lock, flags);
2307 if (cmd == DIGI_SETFLOW) {
2308 ch->fepstartc = ch->startc = dflow.startc;
2309 ch->fepstopc = ch->stopc = dflow.stopc;
2310 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
2312 ch->fepstartca = ch->startca = dflow.startc;
2313 ch->fepstopca = ch->stopca = dflow.stopc;
2314 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2317 if (ch->statusflags & TXSTOPPED)
2321 spin_unlock_irqrestore(&epca_lock, flags);
2322 } /* End if setflow toggled */
2325 return -ENOIOCTLCMD;
2330 static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2333 unsigned long flags;
2335 * verifyChannel returns the channel from the tty struct if it is
2336 * valid. This serves as a sanity check.
2338 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
2339 spin_lock_irqsave(&epca_lock, flags);
2343 spin_unlock_irqrestore(&epca_lock, flags);
2345 if ((old_termios->c_cflag & CRTSCTS) &&
2346 ((tty->termios->c_cflag & CRTSCTS) == 0))
2347 tty->hw_stopped = 0;
2349 if (!(old_termios->c_cflag & CLOCAL) &&
2350 (tty->termios->c_cflag & CLOCAL))
2351 wake_up_interruptible(&ch->open_wait);
2353 } /* End if channel valid */
2356 static void do_softint(struct work_struct *work)
2358 struct channel *ch = container_of(work, struct channel, tqueue);
2359 /* Called in response to a modem change event */
2360 if (ch && ch->magic == EPCA_MAGIC) {
2361 struct tty_struct *tty = ch->tty;
2363 if (tty && tty->driver_data) {
2364 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) {
2365 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2366 wake_up_interruptible(&ch->open_wait);
2367 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
2374 * pc_stop and pc_start provide software flow control to the routine and the
2377 static void pc_stop(struct tty_struct *tty)
2380 unsigned long flags;
2382 * verifyChannel returns the channel from the tty struct if it is
2383 * valid. This serves as a sanity check.
2385 if ((ch = verifyChannel(tty)) != NULL) {
2386 spin_lock_irqsave(&epca_lock, flags);
2387 if ((ch->statusflags & TXSTOPPED) == 0) { /* Begin if transmit stop requested */
2389 /* STOP transmitting now !! */
2390 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
2391 ch->statusflags |= TXSTOPPED;
2393 } /* End if transmit stop requested */
2394 spin_unlock_irqrestore(&epca_lock, flags);
2398 static void pc_start(struct tty_struct *tty)
2402 * verifyChannel returns the channel from the tty struct if it is
2403 * valid. This serves as a sanity check.
2405 if ((ch = verifyChannel(tty)) != NULL) {
2406 unsigned long flags;
2407 spin_lock_irqsave(&epca_lock, flags);
2408 /* Just in case output was resumed because of a change in Digi-flow */
2409 if (ch->statusflags & TXSTOPPED) { /* Begin transmit resume requested */
2410 struct board_chan __iomem *bc;
2413 if (ch->statusflags & LOWWAIT)
2414 writeb(1, &bc->ilow);
2415 /* Okay, you can start transmitting again... */
2416 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
2417 ch->statusflags &= ~TXSTOPPED;
2419 } /* End transmit resume requested */
2420 spin_unlock_irqrestore(&epca_lock, flags);
2425 * The below routines pc_throttle and pc_unthrottle are used to slow (And
2426 * resume) the receipt of data into the kernels receive buffers. The exact
2427 * occurrence of this depends on the size of the kernels receive buffer and
2428 * what the 'watermarks' are set to for that buffer. See the n_ttys.c file for
2431 static void pc_throttle(struct tty_struct *tty)
2434 unsigned long flags;
2436 * verifyChannel returns the channel from the tty struct if it is
2437 * valid. This serves as a sanity check.
2439 if ((ch = verifyChannel(tty)) != NULL) {
2440 spin_lock_irqsave(&epca_lock, flags);
2441 if ((ch->statusflags & RXSTOPPED) == 0) {
2443 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
2444 ch->statusflags |= RXSTOPPED;
2447 spin_unlock_irqrestore(&epca_lock, flags);
2451 static void pc_unthrottle(struct tty_struct *tty)
2454 unsigned long flags;
2456 * verifyChannel returns the channel from the tty struct if it is
2457 * valid. This serves as a sanity check.
2459 if ((ch = verifyChannel(tty)) != NULL) {
2460 /* Just in case output was resumed because of a change in Digi-flow */
2461 spin_lock_irqsave(&epca_lock, flags);
2462 if (ch->statusflags & RXSTOPPED) {
2464 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
2465 ch->statusflags &= ~RXSTOPPED;
2468 spin_unlock_irqrestore(&epca_lock, flags);
2472 static void digi_send_break(struct channel *ch, int msec)
2474 unsigned long flags;
2476 spin_lock_irqsave(&epca_lock, flags);
2479 * Maybe I should send an infinite break here, schedule() for msec
2480 * amount of time, and then stop the break. This way, the user can't
2481 * screw up the FEP by causing digi_send_break() to be called (i.e. via
2482 * an ioctl()) more than once in msec amount of time.
2483 * Try this for now...
2485 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2487 spin_unlock_irqrestore(&epca_lock, flags);
2490 /* Caller MUST hold the lock */
2491 static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2493 struct board_chan __iomem *bc = ch->brdchan;
2496 ch->statusflags |= EMPTYWAIT;
2498 * When set the iempty flag request a event to be generated when the
2499 * transmit buffer is empty (If there is no BREAK in progress).
2501 writeb(1, &bc->iempty);
2505 void epca_setup(char *str, int *ints)
2507 struct board_info board;
2508 int index, loop, last;
2513 * If this routine looks a little strange it is because it is only
2514 * called if a LILO append command is given to boot the kernel with
2515 * parameters. In this way, we can provide the user a method of
2516 * changing his board configuration without rebuilding the kernel.
2521 memset(&board, 0, sizeof(board));
2523 /* Assume the data is int first, later we can change it */
2524 /* I think that array position 0 of ints holds the number of args */
2525 for (last = 0, index = 1; index <= ints[0]; index++)
2526 switch (index) { /* Begin parse switch */
2528 board.status = ints[index];
2530 * We check for 2 (As opposed to 1; because 2 is a flag
2531 * instructing the driver to ignore epcaconfig.) For
2532 * this reason we check for 2.
2534 if (board.status == 2) { /* Begin ignore epcaconfig as well as lilo cmd line */
2538 } /* End ignore epcaconfig as well as lilo cmd line */
2540 if (board.status > 2) {
2541 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n", board.status);
2542 invalid_lilo_config = 1;
2543 setup_error_code |= INVALID_BOARD_STATUS;
2549 board.type = ints[index];
2550 if (board.type >= PCIXEM) {
2551 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
2552 invalid_lilo_config = 1;
2553 setup_error_code |= INVALID_BOARD_TYPE;
2559 board.altpin = ints[index];
2560 if (board.altpin > 1) {
2561 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
2562 invalid_lilo_config = 1;
2563 setup_error_code |= INVALID_ALTPIN;
2570 board.numports = ints[index];
2571 if (board.numports < 2 || board.numports > 256) {
2572 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
2573 invalid_lilo_config = 1;
2574 setup_error_code |= INVALID_NUM_PORTS;
2577 nbdevs += board.numports;
2582 board.port = ints[index];
2583 if (ints[index] <= 0) {
2584 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
2585 invalid_lilo_config = 1;
2586 setup_error_code |= INVALID_PORT_BASE;
2593 board.membase = ints[index];
2594 if (ints[index] <= 0) {
2595 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
2596 invalid_lilo_config = 1;
2597 setup_error_code |= INVALID_MEM_BASE;
2604 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
2607 } /* End parse switch */
2609 while (str && *str) { /* Begin while there is a string arg */
2610 /* find the next comma or terminator */
2612 /* While string is not null, and a comma hasn't been found */
2613 while (*temp && (*temp != ','))
2619 /* Set index to the number of args + 1 */
2625 if (strncmp("Disable", str, len) == 0)
2627 else if (strncmp("Enable", str, len) == 0)
2630 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
2631 invalid_lilo_config = 1;
2632 setup_error_code |= INVALID_BOARD_STATUS;
2639 for (loop = 0; loop < EPCA_NUM_TYPES; loop++)
2640 if (strcmp(board_desc[loop], str) == 0)
2643 * If the index incremented above refers to a
2644 * legitamate board type set it here.
2646 if (index < EPCA_NUM_TYPES)
2649 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
2650 invalid_lilo_config = 1;
2651 setup_error_code |= INVALID_BOARD_TYPE;
2659 if (strncmp("Disable", str, len) == 0)
2661 else if (strncmp("Enable", str, len) == 0)
2664 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
2665 invalid_lilo_config = 1;
2666 setup_error_code |= INVALID_ALTPIN;
2674 while (isdigit(*t2))
2678 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
2679 invalid_lilo_config = 1;
2680 setup_error_code |= INVALID_NUM_PORTS;
2685 * There is not a man page for simple_strtoul but the
2686 * code can be found in vsprintf.c. The first argument
2687 * is the string to translate (To an unsigned long
2688 * obviously), the second argument can be the address
2689 * of any character variable or a NULL. If a variable
2690 * is given, the end pointer of the string will be
2691 * stored in that variable; if a NULL is given the end
2692 * pointer will not be returned. The last argument is
2693 * the base to use. If a 0 is indicated, the routine
2694 * will attempt to determine the proper base by looking
2695 * at the values prefix (A '0' for octal, a 'x' for
2696 * hex, etc ... If a value is given it will use that
2697 * value as the base.
2699 board.numports = simple_strtoul(str, NULL, 0);
2700 nbdevs += board.numports;
2706 while (isxdigit(*t2))
2710 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
2711 invalid_lilo_config = 1;
2712 setup_error_code |= INVALID_PORT_BASE;
2716 board.port = simple_strtoul(str, NULL, 16);
2722 while (isxdigit(*t2))
2726 printk(KERN_ERR "epca_setup: Invalid memory base %s\n",str);
2727 invalid_lilo_config = 1;
2728 setup_error_code |= INVALID_MEM_BASE;
2731 board.membase = simple_strtoul(str, NULL, 16);
2735 printk(KERN_ERR "epca: Too many string parms\n");
2739 } /* End while there is a string arg */
2742 printk(KERN_ERR "epca: Insufficient parms specified\n");
2746 /* I should REALLY validate the stuff here */
2747 /* Copies our local copy of board into boards */
2748 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
2749 /* Does this get called once per lilo arg are what ? */
2750 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2751 num_cards, board_desc[board.type],
2752 board.numports, (int)board.port, (unsigned int) board.membase);
2756 enum epic_board_types {
2763 /* indexed directly by epic_board_types enum */
2765 unsigned char board_type;
2766 unsigned bar_idx; /* PCI base address region */
2767 } epca_info_tbl[] = {
2774 static int __devinit epca_init_one(struct pci_dev *pdev,
2775 const struct pci_device_id *ent)
2777 static int board_num = -1;
2778 int board_idx, info_idx = ent->driver_data;
2781 if (pci_enable_device(pdev))
2785 board_idx = board_num + num_cards;
2786 if (board_idx >= MAXBOARDS)
2789 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
2791 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
2792 epca_info_tbl[info_idx].bar_idx);
2796 boards[board_idx].status = ENABLED;
2797 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
2798 boards[board_idx].numports = 0x0;
2799 boards[board_idx].port = addr + PCI_IO_OFFSET;
2800 boards[board_idx].membase = addr;
2802 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
2803 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2804 0x200000, addr + PCI_IO_OFFSET);
2808 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
2809 if (!boards[board_idx].re_map_port) {
2810 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2811 0x200000, addr + PCI_IO_OFFSET);
2812 goto err_out_free_pciio;
2815 if (!request_mem_region (addr, 0x200000, "epca")) {
2816 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2818 goto err_out_free_iounmap;
2821 boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
2822 if (!boards[board_idx].re_map_membase) {
2823 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2824 0x200000, addr + PCI_IO_OFFSET);
2825 goto err_out_free_memregion;
2829 * I don't know what the below does, but the hardware guys say its
2830 * required on everything except PLX (In this case XRJ).
2832 if (info_idx != brd_xrj) {
2833 pci_write_config_byte(pdev, 0x40, 0);
2834 pci_write_config_byte(pdev, 0x46, 0);
2839 err_out_free_memregion:
2840 release_mem_region (addr, 0x200000);
2841 err_out_free_iounmap:
2842 iounmap (boards[board_idx].re_map_port);
2844 release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
2850 static struct pci_device_id epca_pci_tbl[] = {
2851 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
2852 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
2853 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
2854 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
2858 MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
2860 static int __init init_PCI(void)
2862 memset (&epca_driver, 0, sizeof (epca_driver));
2863 epca_driver.name = "epca";
2864 epca_driver.id_table = epca_pci_tbl;
2865 epca_driver.probe = epca_init_one;
2867 return pci_register_driver(&epca_driver);
2870 MODULE_LICENSE("GPL");