4 Copyright (C) 1996 Digi International.
6 For technical support please email digiLinux@dgii.com or
7 call Digi tech support at (612) 912-3456
9 ** This driver is no longer supported by Digi **
11 Much of this design and code came from epca.c which was
12 copyright (C) 1994, 1995 Troy De Jongh, and subsquently
13 modified by David Nugent, Christoph Lameter, Mike McLagan.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 --------------------------------------------------------------------------- */
30 /* See README.epca for change history --DAT*/
33 #include <linux/config.h>
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/types.h>
37 #include <linux/init.h>
38 #include <linux/serial.h>
39 #include <linux/delay.h>
40 #include <linux/ctype.h>
41 #include <linux/tty.h>
42 #include <linux/tty_flip.h>
43 #include <linux/slab.h>
44 #include <linux/ioport.h>
45 #include <linux/interrupt.h>
46 #include <asm/uaccess.h>
48 #include <linux/spinlock.h>
49 #include <linux/pci.h>
56 #include "epcaconfig.h"
58 /* ---------------------- Begin defines ------------------------ */
60 #define VERSION "1.3.0.1-LK2.6"
62 /* This major needs to be submitted to Linux to join the majors list */
64 #define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
68 #define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
72 /* ----------------- Begin global definitions ------------------- */
74 static int nbdevs
, num_cards
, liloconfig
;
75 static int digi_poller_inhibited
= 1 ;
77 static int setup_error_code
;
78 static int invalid_lilo_config
;
80 /* The ISA boards do window flipping into the same spaces so its only sane
81 with a single lock. It's still pretty efficient */
83 static spinlock_t epca_lock
= SPIN_LOCK_UNLOCKED
;
85 /* -----------------------------------------------------------------------
86 MAXBOARDS is typically 12, but ISA and EISA cards are restricted to
88 --------------------------------------------------------------------------*/
89 static struct board_info boards
[MAXBOARDS
];
92 /* ------------- Begin structures used for driver registeration ---------- */
94 static struct tty_driver
*pc_driver
;
95 static struct tty_driver
*pc_info
;
97 /* ------------------ Begin Digi specific structures -------------------- */
99 /* ------------------------------------------------------------------------
100 digi_channels represents an array of structures that keep track of
101 each channel of the Digi product. Information such as transmit and
102 receive pointers, termio data, and signal definitions (DTR, CTS, etc ...)
103 are stored here. This structure is NOT used to overlay the cards
104 physical channel structure.
105 -------------------------------------------------------------------------- */
107 static struct channel digi_channels
[MAX_ALLOC
];
109 /* ------------------------------------------------------------------------
110 card_ptr is an array used to hold the address of the
111 first channel structure of each card. This array will hold
112 the addresses of various channels located in digi_channels.
113 -------------------------------------------------------------------------- */
114 static struct channel
*card_ptr
[MAXCARDS
];
116 static struct timer_list epca_timer
;
118 /* ---------------------- Begin function prototypes --------------------- */
120 /* ----------------------------------------------------------------------
121 Begin generic memory functions. These functions will be alias
122 (point at) more specific functions dependent on the board being
124 ----------------------------------------------------------------------- */
126 static void memwinon(struct board_info
*b
, unsigned int win
);
127 static void memwinoff(struct board_info
*b
, unsigned int win
);
128 static void globalwinon(struct channel
*ch
);
129 static void rxwinon(struct channel
*ch
);
130 static void txwinon(struct channel
*ch
);
131 static void memoff(struct channel
*ch
);
132 static void assertgwinon(struct channel
*ch
);
133 static void assertmemoff(struct channel
*ch
);
135 /* ---- Begin more 'specific' memory functions for cx_like products --- */
137 static void pcxem_memwinon(struct board_info
*b
, unsigned int win
);
138 static void pcxem_memwinoff(struct board_info
*b
, unsigned int win
);
139 static void pcxem_globalwinon(struct channel
*ch
);
140 static void pcxem_rxwinon(struct channel
*ch
);
141 static void pcxem_txwinon(struct channel
*ch
);
142 static void pcxem_memoff(struct channel
*ch
);
144 /* ------ Begin more 'specific' memory functions for the pcxe ------- */
146 static void pcxe_memwinon(struct board_info
*b
, unsigned int win
);
147 static void pcxe_memwinoff(struct board_info
*b
, unsigned int win
);
148 static void pcxe_globalwinon(struct channel
*ch
);
149 static void pcxe_rxwinon(struct channel
*ch
);
150 static void pcxe_txwinon(struct channel
*ch
);
151 static void pcxe_memoff(struct channel
*ch
);
153 /* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
154 /* Note : pc64xe and pcxi share the same windowing routines */
156 static void pcxi_memwinon(struct board_info
*b
, unsigned int win
);
157 static void pcxi_memwinoff(struct board_info
*b
, unsigned int win
);
158 static void pcxi_globalwinon(struct channel
*ch
);
159 static void pcxi_rxwinon(struct channel
*ch
);
160 static void pcxi_txwinon(struct channel
*ch
);
161 static void pcxi_memoff(struct channel
*ch
);
163 /* - Begin 'specific' do nothing memory functions needed for some cards - */
165 static void dummy_memwinon(struct board_info
*b
, unsigned int win
);
166 static void dummy_memwinoff(struct board_info
*b
, unsigned int win
);
167 static void dummy_globalwinon(struct channel
*ch
);
168 static void dummy_rxwinon(struct channel
*ch
);
169 static void dummy_txwinon(struct channel
*ch
);
170 static void dummy_memoff(struct channel
*ch
);
171 static void dummy_assertgwinon(struct channel
*ch
);
172 static void dummy_assertmemoff(struct channel
*ch
);
174 /* ------------------- Begin declare functions ----------------------- */
176 static struct channel
*verifyChannel(struct tty_struct
*);
177 static void pc_sched_event(struct channel
*, int);
178 static void epca_error(int, char *);
179 static void pc_close(struct tty_struct
*, struct file
*);
180 static void shutdown(struct channel
*);
181 static void pc_hangup(struct tty_struct
*);
182 static void pc_put_char(struct tty_struct
*, unsigned char);
183 static int pc_write_room(struct tty_struct
*);
184 static int pc_chars_in_buffer(struct tty_struct
*);
185 static void pc_flush_buffer(struct tty_struct
*);
186 static void pc_flush_chars(struct tty_struct
*);
187 static int block_til_ready(struct tty_struct
*, struct file
*,
189 static int pc_open(struct tty_struct
*, struct file
*);
190 static void post_fep_init(unsigned int crd
);
191 static void epcapoll(unsigned long);
192 static void doevent(int);
193 static void fepcmd(struct channel
*, int, int, int, int, int);
194 static unsigned termios2digi_h(struct channel
*ch
, unsigned);
195 static unsigned termios2digi_i(struct channel
*ch
, unsigned);
196 static unsigned termios2digi_c(struct channel
*ch
, unsigned);
197 static void epcaparam(struct tty_struct
*, struct channel
*);
198 static void receive_data(struct channel
*);
199 static int pc_ioctl(struct tty_struct
*, struct file
*,
200 unsigned int, unsigned long);
201 static int info_ioctl(struct tty_struct
*, struct file
*,
202 unsigned int, unsigned long);
203 static void pc_set_termios(struct tty_struct
*, struct termios
*);
204 static void do_softint(void *);
205 static void pc_stop(struct tty_struct
*);
206 static void pc_start(struct tty_struct
*);
207 static void pc_throttle(struct tty_struct
* tty
);
208 static void pc_unthrottle(struct tty_struct
*tty
);
209 static void digi_send_break(struct channel
*ch
, int msec
);
210 static void setup_empty_event(struct tty_struct
*tty
, struct channel
*ch
);
211 void epca_setup(char *, int *);
213 static int get_termio(struct tty_struct
*, struct termio __user
*);
214 static int pc_write(struct tty_struct
*, const unsigned char *, int);
215 static int pc_init(void);
216 static int init_PCI(void);
219 /* ------------------------------------------------------------------
220 Table of functions for each board to handle memory. Mantaining
221 parallelism is a *very* good idea here. The idea is for the
222 runtime code to blindly call these functions, not knowing/caring
223 about the underlying hardware. This stuff should contain no
224 conditionals; if more functionality is needed a different entry
225 should be established. These calls are the interface calls and
226 are the only functions that should be accessed. Anyone caught
227 making direct calls deserves what they get.
228 -------------------------------------------------------------------- */
230 static void memwinon(struct board_info
*b
, unsigned int win
)
232 (b
->memwinon
)(b
, win
);
235 static void memwinoff(struct board_info
*b
, unsigned int win
)
237 (b
->memwinoff
)(b
, win
);
240 static void globalwinon(struct channel
*ch
)
242 (ch
->board
->globalwinon
)(ch
);
245 static void rxwinon(struct channel
*ch
)
247 (ch
->board
->rxwinon
)(ch
);
250 static void txwinon(struct channel
*ch
)
252 (ch
->board
->txwinon
)(ch
);
255 static void memoff(struct channel
*ch
)
257 (ch
->board
->memoff
)(ch
);
259 static void assertgwinon(struct channel
*ch
)
261 (ch
->board
->assertgwinon
)(ch
);
264 static void assertmemoff(struct channel
*ch
)
266 (ch
->board
->assertmemoff
)(ch
);
269 /* ---------------------------------------------------------
270 PCXEM windowing is the same as that used in the PCXR
272 ------------------------------------------------------------ */
274 static void pcxem_memwinon(struct board_info
*b
, unsigned int win
)
276 outb_p(FEPWIN
|win
, b
->port
+ 1);
279 static void pcxem_memwinoff(struct board_info
*b
, unsigned int win
)
281 outb_p(0, b
->port
+ 1);
284 static void pcxem_globalwinon(struct channel
*ch
)
286 outb_p( FEPWIN
, (int)ch
->board
->port
+ 1);
289 static void pcxem_rxwinon(struct channel
*ch
)
291 outb_p(ch
->rxwin
, (int)ch
->board
->port
+ 1);
294 static void pcxem_txwinon(struct channel
*ch
)
296 outb_p(ch
->txwin
, (int)ch
->board
->port
+ 1);
299 static void pcxem_memoff(struct channel
*ch
)
301 outb_p(0, (int)ch
->board
->port
+ 1);
304 /* ----------------- Begin pcxe memory window stuff ------------------ */
306 static void pcxe_memwinon(struct board_info
*b
, unsigned int win
)
308 outb_p(FEPWIN
| win
, b
->port
+ 1);
311 static void pcxe_memwinoff(struct board_info
*b
, unsigned int win
)
313 outb_p(inb(b
->port
) & ~FEPMEM
,
315 outb_p(0, b
->port
+ 1);
318 static void pcxe_globalwinon(struct channel
*ch
)
320 outb_p( FEPWIN
, (int)ch
->board
->port
+ 1);
323 static void pcxe_rxwinon(struct channel
*ch
)
325 outb_p(ch
->rxwin
, (int)ch
->board
->port
+ 1);
328 static void pcxe_txwinon(struct channel
*ch
)
330 outb_p(ch
->txwin
, (int)ch
->board
->port
+ 1);
333 static void pcxe_memoff(struct channel
*ch
)
335 outb_p(0, (int)ch
->board
->port
);
336 outb_p(0, (int)ch
->board
->port
+ 1);
339 /* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
341 static void pcxi_memwinon(struct board_info
*b
, unsigned int win
)
343 outb_p(inb(b
->port
) | FEPMEM
, b
->port
);
346 static void pcxi_memwinoff(struct board_info
*b
, unsigned int win
)
348 outb_p(inb(b
->port
) & ~FEPMEM
, b
->port
);
351 static void pcxi_globalwinon(struct channel
*ch
)
353 outb_p(FEPMEM
, ch
->board
->port
);
356 static void pcxi_rxwinon(struct channel
*ch
)
358 outb_p(FEPMEM
, ch
->board
->port
);
361 static void pcxi_txwinon(struct channel
*ch
)
363 outb_p(FEPMEM
, ch
->board
->port
);
366 static void pcxi_memoff(struct channel
*ch
)
368 outb_p(0, ch
->board
->port
);
371 static void pcxi_assertgwinon(struct channel
*ch
)
373 epcaassert(inb(ch
->board
->port
) & FEPMEM
, "Global memory off");
376 static void pcxi_assertmemoff(struct channel
*ch
)
378 epcaassert(!(inb(ch
->board
->port
) & FEPMEM
), "Memory on");
382 /* ----------------------------------------------------------------------
383 Not all of the cards need specific memory windowing routines. Some
384 cards (Such as PCI) needs no windowing routines at all. We provide
385 these do nothing routines so that the same code base can be used.
386 The driver will ALWAYS call a windowing routine if it thinks it needs
387 to; regardless of the card. However, dependent on the card the routine
388 may or may not do anything.
389 ---------------------------------------------------------------------------*/
391 static void dummy_memwinon(struct board_info
*b
, unsigned int win
)
395 static void dummy_memwinoff(struct board_info
*b
, unsigned int win
)
399 static void dummy_globalwinon(struct channel
*ch
)
403 static void dummy_rxwinon(struct channel
*ch
)
407 static void dummy_txwinon(struct channel
*ch
)
411 static void dummy_memoff(struct channel
*ch
)
415 static void dummy_assertgwinon(struct channel
*ch
)
419 static void dummy_assertmemoff(struct channel
*ch
)
423 /* ----------------- Begin verifyChannel function ----------------------- */
424 static struct channel
*verifyChannel(struct tty_struct
*tty
)
425 { /* Begin verifyChannel */
426 /* --------------------------------------------------------------------
427 This routine basically provides a sanity check. It insures that
428 the channel returned is within the proper range of addresses as
429 well as properly initialized. If some bogus info gets passed in
430 through tty->driver_data this should catch it.
431 --------------------------------------------------------------------- */
433 struct channel
*ch
= (struct channel
*)tty
->driver_data
;
434 if ((ch
>= &digi_channels
[0]) && (ch
< &digi_channels
[nbdevs
])) {
435 if (ch
->magic
== EPCA_MAGIC
)
441 } /* End verifyChannel */
443 /* ------------------ Begin pc_sched_event ------------------------- */
445 static void pc_sched_event(struct channel
*ch
, int event
)
447 /* ----------------------------------------------------------------------
448 We call this to schedule interrupt processing on some event. The
449 kernel sees our request and calls the related routine in OUR driver.
450 -------------------------------------------------------------------------*/
451 ch
->event
|= 1 << event
;
452 schedule_work(&ch
->tqueue
);
453 } /* End pc_sched_event */
455 /* ------------------ Begin epca_error ------------------------- */
457 static void epca_error(int line
, char *msg
)
459 printk(KERN_ERR
"epca_error (Digi): line = %d %s\n",line
,msg
);
462 /* ------------------ Begin pc_close ------------------------- */
463 static void pc_close(struct tty_struct
* tty
, struct file
* filp
)
467 /* ---------------------------------------------------------
468 verifyChannel returns the channel from the tty struct
469 if it is valid. This serves as a sanity check.
470 ------------------------------------------------------------- */
471 if ((ch
= verifyChannel(tty
)) != NULL
) { /* Begin if ch != NULL */
472 spin_lock_irqsave(&epca_lock
, flags
);
473 if (tty_hung_up_p(filp
)) {
474 spin_unlock_irqrestore(&epca_lock
, flags
);
477 /* Check to see if the channel is open more than once */
478 if (ch
->count
-- > 1) {
479 /* Begin channel is open more than once */
480 /* -------------------------------------------------------------
481 Return without doing anything. Someone might still be using
483 ---------------------------------------------------------------- */
484 spin_unlock_irqrestore(&epca_lock
, flags
);
486 } /* End channel is open more than once */
488 /* Port open only once go ahead with shutdown & reset */
492 /* ---------------------------------------------------------------
493 Let the rest of the driver know the channel is being closed.
494 This becomes important if an open is attempted before close
496 ------------------------------------------------------------------ */
497 ch
->asyncflags
|= ASYNC_CLOSING
;
500 spin_unlock_irqrestore(&epca_lock
, flags
);
502 if (ch
->asyncflags
& ASYNC_INITIALIZED
) {
503 /* Setup an event to indicate when the transmit buffer empties */
504 setup_empty_event(tty
, ch
);
505 tty_wait_until_sent(tty
, 3000); /* 30 seconds timeout */
507 if (tty
->driver
->flush_buffer
)
508 tty
->driver
->flush_buffer(tty
);
510 tty_ldisc_flush(tty
);
513 spin_lock_irqsave(&epca_lock
, flags
);
517 spin_unlock_irqrestore(&epca_lock
, flags
);
519 if (ch
->blocked_open
) { /* Begin if blocked_open */
521 msleep_interruptible(jiffies_to_msecs(ch
->close_delay
));
522 wake_up_interruptible(&ch
->open_wait
);
523 } /* End if blocked_open */
524 ch
->asyncflags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_INITIALIZED
|
526 wake_up_interruptible(&ch
->close_wait
);
527 } /* End if ch != NULL */
530 /* ------------------ Begin shutdown ------------------------- */
532 static void shutdown(struct channel
*ch
)
533 { /* Begin shutdown */
536 struct tty_struct
*tty
;
537 struct board_chan __iomem
*bc
;
539 if (!(ch
->asyncflags
& ASYNC_INITIALIZED
))
542 spin_lock_irqsave(&epca_lock
, flags
);
547 /* ------------------------------------------------------------------
548 In order for an event to be generated on the receipt of data the
549 idata flag must be set. Since we are shutting down, this is not
550 necessary clear this flag.
551 --------------------------------------------------------------------- */
554 writeb(0, &bc
->idata
);
557 /* ----------------------------------------------------------------
558 If we're a modem control device and HUPCL is on, drop RTS & DTR.
559 ------------------------------------------------------------------ */
561 if (tty
->termios
->c_cflag
& HUPCL
) {
562 ch
->omodem
&= ~(ch
->m_rts
| ch
->m_dtr
);
563 fepcmd(ch
, SETMODEM
, 0, ch
->m_dtr
| ch
->m_rts
, 10, 1);
567 /* ------------------------------------------------------------------
568 The channel has officialy been closed. The next time it is opened
569 it will have to reinitialized. Set a flag to indicate this.
570 ---------------------------------------------------------------------- */
572 /* Prevent future Digi programmed interrupts from coming active */
574 ch
->asyncflags
&= ~ASYNC_INITIALIZED
;
575 spin_unlock_irqrestore(&epca_lock
, flags
);
579 /* ------------------ Begin pc_hangup ------------------------- */
581 static void pc_hangup(struct tty_struct
*tty
)
582 { /* Begin pc_hangup */
585 /* ---------------------------------------------------------
586 verifyChannel returns the channel from the tty struct
587 if it is valid. This serves as a sanity check.
588 ------------------------------------------------------------- */
590 if ((ch
= verifyChannel(tty
)) != NULL
) { /* Begin if ch != NULL */
593 if (tty
->driver
->flush_buffer
)
594 tty
->driver
->flush_buffer(tty
);
595 tty_ldisc_flush(tty
);
598 spin_lock_irqsave(&epca_lock
, flags
);
602 ch
->asyncflags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_INITIALIZED
);
603 spin_unlock_irqrestore(&epca_lock
, flags
);
604 wake_up_interruptible(&ch
->open_wait
);
605 } /* End if ch != NULL */
607 } /* End pc_hangup */
609 /* ------------------ Begin pc_write ------------------------- */
611 static int pc_write(struct tty_struct
* tty
,
612 const unsigned char *buf
, int bytesAvailable
)
613 { /* Begin pc_write */
614 unsigned int head
, tail
;
621 struct board_chan __iomem
*bc
;
623 /* ----------------------------------------------------------------
624 pc_write is primarily called directly by the kernel routine
625 tty_write (Though it can also be called by put_char) found in
626 tty_io.c. pc_write is passed a line discipline buffer where
627 the data to be written out is stored. The line discipline
628 implementation itself is done at the kernel level and is not
629 brought into the driver.
630 ------------------------------------------------------------------- */
632 /* ---------------------------------------------------------
633 verifyChannel returns the channel from the tty struct
634 if it is valid. This serves as a sanity check.
635 ------------------------------------------------------------- */
637 if ((ch
= verifyChannel(tty
)) == NULL
)
640 /* Make a pointer to the channel data structure found on the board. */
643 size
= ch
->txbufsize
;
646 spin_lock_irqsave(&epca_lock
, flags
);
649 head
= readw(&bc
->tin
) & (size
- 1);
650 tail
= readw(&bc
->tout
);
652 if (tail
!= readw(&bc
->tout
))
653 tail
= readw(&bc
->tout
);
656 /* If head >= tail, head has not wrapped around. */
657 if (head
>= tail
) { /* Begin head has not wrapped */
658 /* ---------------------------------------------------------------
659 remain (much like dataLen above) represents the total amount of
660 space available on the card for data. Here dataLen represents
661 the space existing between the head pointer and the end of
662 buffer. This is important because a memcpy cannot be told to
663 automatically wrap around when it hits the buffer end.
664 ------------------------------------------------------------------ */
665 dataLen
= size
- head
;
666 remain
= size
- (head
- tail
) - 1;
667 } else { /* Begin head has wrapped around */
669 remain
= tail
- head
- 1;
672 } /* End head has wrapped around */
673 /* -------------------------------------------------------------------
674 Check the space on the card. If we have more data than
675 space; reduce the amount of data to fit the space.
676 ---------------------------------------------------------------------- */
677 bytesAvailable
= min(remain
, bytesAvailable
);
679 while (bytesAvailable
> 0)
680 { /* Begin while there is data to copy onto card */
682 /* -----------------------------------------------------------------
683 If head is not wrapped, the below will make sure the first
684 data copy fills to the end of card buffer.
685 ------------------------------------------------------------------- */
687 dataLen
= min(bytesAvailable
, dataLen
);
688 memcpy_toio(ch
->txptr
+ head
, buf
, dataLen
);
691 amountCopied
+= dataLen
;
692 bytesAvailable
-= dataLen
;
698 } /* End while there is data to copy onto card */
699 ch
->statusflags
|= TXBUSY
;
701 writew(head
, &bc
->tin
);
703 if ((ch
->statusflags
& LOWWAIT
) == 0) {
704 ch
->statusflags
|= LOWWAIT
;
705 writeb(1, &bc
->ilow
);
708 spin_unlock_irqrestore(&epca_lock
, flags
);
709 return(amountCopied
);
713 /* ------------------ Begin pc_put_char ------------------------- */
715 static void pc_put_char(struct tty_struct
*tty
, unsigned char c
)
716 { /* Begin pc_put_char */
717 pc_write(tty
, &c
, 1);
718 } /* End pc_put_char */
720 /* ------------------ Begin pc_write_room ------------------------- */
722 static int pc_write_room(struct tty_struct
*tty
)
723 { /* Begin pc_write_room */
728 unsigned int head
, tail
;
729 struct board_chan __iomem
*bc
;
733 /* ---------------------------------------------------------
734 verifyChannel returns the channel from the tty struct
735 if it is valid. This serves as a sanity check.
736 ------------------------------------------------------------- */
738 if ((ch
= verifyChannel(tty
)) != NULL
) {
739 spin_lock_irqsave(&epca_lock
, flags
);
743 head
= readw(&bc
->tin
) & (ch
->txbufsize
- 1);
744 tail
= readw(&bc
->tout
);
746 if (tail
!= readw(&bc
->tout
))
747 tail
= readw(&bc
->tout
);
748 /* Wrap tail if necessary */
749 tail
&= (ch
->txbufsize
- 1);
751 if ((remain
= tail
- head
- 1) < 0 )
752 remain
+= ch
->txbufsize
;
754 if (remain
&& (ch
->statusflags
& LOWWAIT
) == 0) {
755 ch
->statusflags
|= LOWWAIT
;
756 writeb(1, &bc
->ilow
);
759 spin_unlock_irqrestore(&epca_lock
, flags
);
761 /* Return how much room is left on card */
764 } /* End pc_write_room */
766 /* ------------------ Begin pc_chars_in_buffer ---------------------- */
768 static int pc_chars_in_buffer(struct tty_struct
*tty
)
769 { /* Begin pc_chars_in_buffer */
772 unsigned int ctail
, head
, tail
;
776 struct board_chan __iomem
*bc
;
778 /* ---------------------------------------------------------
779 verifyChannel returns the channel from the tty struct
780 if it is valid. This serves as a sanity check.
781 ------------------------------------------------------------- */
783 if ((ch
= verifyChannel(tty
)) == NULL
)
786 spin_lock_irqsave(&epca_lock
, flags
);
790 tail
= readw(&bc
->tout
);
791 head
= readw(&bc
->tin
);
792 ctail
= readw(&ch
->mailbox
->cout
);
794 if (tail
== head
&& readw(&ch
->mailbox
->cin
) == ctail
&& readb(&bc
->tbusy
) == 0)
796 else { /* Begin if some space on the card has been used */
797 head
= readw(&bc
->tin
) & (ch
->txbufsize
- 1);
798 tail
&= (ch
->txbufsize
- 1);
799 /* --------------------------------------------------------------
800 The logic here is basically opposite of the above pc_write_room
801 here we are finding the amount of bytes in the buffer filled.
802 Not the amount of bytes empty.
803 ------------------------------------------------------------------- */
804 if ((remain
= tail
- head
- 1) < 0 )
805 remain
+= ch
->txbufsize
;
806 chars
= (int)(ch
->txbufsize
- remain
);
807 /* -------------------------------------------------------------
808 Make it possible to wakeup anything waiting for output
811 If not already set. Setup an event to indicate when the
812 transmit buffer empties
813 ----------------------------------------------------------------- */
814 if (!(ch
->statusflags
& EMPTYWAIT
))
815 setup_empty_event(tty
,ch
);
817 } /* End if some space on the card has been used */
819 spin_unlock_irqrestore(&epca_lock
, flags
);
820 /* Return number of characters residing on card. */
823 } /* End pc_chars_in_buffer */
825 /* ------------------ Begin pc_flush_buffer ---------------------- */
827 static void pc_flush_buffer(struct tty_struct
*tty
)
828 { /* Begin pc_flush_buffer */
833 struct board_chan __iomem
*bc
;
834 /* ---------------------------------------------------------
835 verifyChannel returns the channel from the tty struct
836 if it is valid. This serves as a sanity check.
837 ------------------------------------------------------------- */
838 if ((ch
= verifyChannel(tty
)) == NULL
)
841 spin_lock_irqsave(&epca_lock
, flags
);
844 tail
= readw(&bc
->tout
);
845 /* Have FEP move tout pointer; effectively flushing transmit buffer */
846 fepcmd(ch
, STOUT
, (unsigned) tail
, 0, 0, 0);
848 spin_unlock_irqrestore(&epca_lock
, flags
);
849 wake_up_interruptible(&tty
->write_wait
);
851 } /* End pc_flush_buffer */
853 /* ------------------ Begin pc_flush_chars ---------------------- */
855 static void pc_flush_chars(struct tty_struct
*tty
)
856 { /* Begin pc_flush_chars */
858 /* ---------------------------------------------------------
859 verifyChannel returns the channel from the tty struct
860 if it is valid. This serves as a sanity check.
861 ------------------------------------------------------------- */
862 if ((ch
= verifyChannel(tty
)) != NULL
) {
864 spin_lock_irqsave(&epca_lock
, flags
);
865 /* ----------------------------------------------------------------
866 If not already set and the transmitter is busy setup an event
867 to indicate when the transmit empties.
868 ------------------------------------------------------------------- */
869 if ((ch
->statusflags
& TXBUSY
) && !(ch
->statusflags
& EMPTYWAIT
))
870 setup_empty_event(tty
,ch
);
871 spin_unlock_irqrestore(&epca_lock
, flags
);
873 } /* End pc_flush_chars */
875 /* ------------------ Begin block_til_ready ---------------------- */
877 static int block_til_ready(struct tty_struct
*tty
,
878 struct file
*filp
, struct channel
*ch
)
879 { /* Begin block_til_ready */
880 DECLARE_WAITQUEUE(wait
,current
);
881 int retval
, do_clocal
= 0;
884 if (tty_hung_up_p(filp
)) {
885 if (ch
->asyncflags
& ASYNC_HUP_NOTIFY
)
888 retval
= -ERESTARTSYS
;
892 /* -----------------------------------------------------------------
893 If the device is in the middle of being closed, then block
894 until it's done, and then try again.
895 -------------------------------------------------------------------- */
896 if (ch
->asyncflags
& ASYNC_CLOSING
) {
897 interruptible_sleep_on(&ch
->close_wait
);
899 if (ch
->asyncflags
& ASYNC_HUP_NOTIFY
)
905 if (filp
->f_flags
& O_NONBLOCK
) {
906 /* -----------------------------------------------------------------
907 If non-blocking mode is set, then make the check up front
909 -------------------------------------------------------------------- */
910 ch
->asyncflags
|= ASYNC_NORMAL_ACTIVE
;
913 if (tty
->termios
->c_cflag
& CLOCAL
)
915 /* Block waiting for the carrier detect and the line to become free */
918 add_wait_queue(&ch
->open_wait
, &wait
);
920 spin_lock_irqsave(&epca_lock
, flags
);
921 /* We dec count so that pc_close will know when to free things */
922 if (!tty_hung_up_p(filp
))
926 { /* Begin forever while */
927 set_current_state(TASK_INTERRUPTIBLE
);
928 if (tty_hung_up_p(filp
) ||
929 !(ch
->asyncflags
& ASYNC_INITIALIZED
))
931 if (ch
->asyncflags
& ASYNC_HUP_NOTIFY
)
934 retval
= -ERESTARTSYS
;
937 if (!(ch
->asyncflags
& ASYNC_CLOSING
) &&
938 (do_clocal
|| (ch
->imodem
& ch
->dcd
)))
940 if (signal_pending(current
)) {
941 retval
= -ERESTARTSYS
;
944 spin_unlock_irqrestore(&epca_lock
, flags
);
945 /* ---------------------------------------------------------------
946 Allow someone else to be scheduled. We will occasionally go
947 through this loop until one of the above conditions change.
948 The below schedule call will allow other processes to enter and
949 prevent this loop from hogging the cpu.
950 ------------------------------------------------------------------ */
952 spin_lock_irqsave(&epca_lock
, flags
);
954 } /* End forever while */
956 current
->state
= TASK_RUNNING
;
957 remove_wait_queue(&ch
->open_wait
, &wait
);
958 if (!tty_hung_up_p(filp
))
962 spin_unlock_irqrestore(&epca_lock
, flags
);
967 ch
->asyncflags
|= ASYNC_NORMAL_ACTIVE
;
969 } /* End block_til_ready */
971 /* ------------------ Begin pc_open ---------------------- */
973 static int pc_open(struct tty_struct
*tty
, struct file
* filp
)
974 { /* Begin pc_open */
978 int line
, retval
, boardnum
;
979 struct board_chan __iomem
*bc
;
983 if (line
< 0 || line
>= nbdevs
)
986 ch
= &digi_channels
[line
];
987 boardnum
= ch
->boardnum
;
989 /* Check status of board configured in system. */
991 /* -----------------------------------------------------------------
992 I check to see if the epca_setup routine detected an user error.
993 It might be better to put this in pc_init, but for the moment it
995 ---------------------------------------------------------------------- */
997 if (invalid_lilo_config
) {
998 if (setup_error_code
& INVALID_BOARD_TYPE
)
999 printk(KERN_ERR
"epca: pc_open: Invalid board type specified in kernel options.\n");
1000 if (setup_error_code
& INVALID_NUM_PORTS
)
1001 printk(KERN_ERR
"epca: pc_open: Invalid number of ports specified in kernel options.\n");
1002 if (setup_error_code
& INVALID_MEM_BASE
)
1003 printk(KERN_ERR
"epca: pc_open: Invalid board memory address specified in kernel options.\n");
1004 if (setup_error_code
& INVALID_PORT_BASE
)
1005 printk(KERN_ERR
"epca; pc_open: Invalid board port address specified in kernel options.\n");
1006 if (setup_error_code
& INVALID_BOARD_STATUS
)
1007 printk(KERN_ERR
"epca: pc_open: Invalid board status specified in kernel options.\n");
1008 if (setup_error_code
& INVALID_ALTPIN
)
1009 printk(KERN_ERR
"epca: pc_open: Invalid board altpin specified in kernel options;\n");
1010 tty
->driver_data
= NULL
; /* Mark this device as 'down' */
1013 if (boardnum
>= num_cards
|| boards
[boardnum
].status
== DISABLED
) {
1014 tty
->driver_data
= NULL
; /* Mark this device as 'down' */
1018 if ((bc
= ch
->brdchan
) == 0) {
1019 tty
->driver_data
= NULL
;
1023 spin_lock_irqsave(&epca_lock
, flags
);
1024 /* ------------------------------------------------------------------
1025 Every time a channel is opened, increment a counter. This is
1026 necessary because we do not wish to flush and shutdown the channel
1027 until the last app holding the channel open, closes it.
1028 --------------------------------------------------------------------- */
1030 /* ----------------------------------------------------------------
1031 Set a kernel structures pointer to our local channel
1032 structure. This way we can get to it when passed only
1034 ------------------------------------------------------------------ */
1035 tty
->driver_data
= ch
;
1036 /* ----------------------------------------------------------------
1037 If this is the first time the channel has been opened, initialize
1038 the tty->termios struct otherwise let pc_close handle it.
1039 -------------------------------------------------------------------- */
1041 ch
->statusflags
= 0;
1043 /* Save boards current modem status */
1044 ch
->imodem
= readb(&bc
->mstat
);
1046 /* ----------------------------------------------------------------
1047 Set receive head and tail ptrs to each other. This indicates
1048 no data available to read.
1049 ----------------------------------------------------------------- */
1050 head
= readw(&bc
->rin
);
1051 writew(head
, &bc
->rout
);
1053 /* Set the channels associated tty structure */
1056 /* -----------------------------------------------------------------
1057 The below routine generally sets up parity, baud, flow control
1058 issues, etc.... It effect both control flags and input flags.
1059 -------------------------------------------------------------------- */
1061 ch
->asyncflags
|= ASYNC_INITIALIZED
;
1063 spin_unlock_irqrestore(&epca_lock
, flags
);
1065 retval
= block_til_ready(tty
, filp
, ch
);
1068 /* -------------------------------------------------------------
1069 Set this again in case a hangup set it to zero while this
1070 open() was waiting for the line...
1071 --------------------------------------------------------------- */
1072 spin_lock_irqsave(&epca_lock
, flags
);
1075 /* Enable Digi Data events */
1076 writeb(1, &bc
->idata
);
1078 spin_unlock_irqrestore(&epca_lock
, flags
);
1082 static int __init
epca_module_init(void)
1083 { /* Begin init_module */
1087 module_init(epca_module_init
);
1089 static struct pci_driver epca_driver
;
1091 static void __exit
epca_module_exit(void)
1094 struct board_info
*bd
;
1097 del_timer_sync(&epca_timer
);
1099 if ((tty_unregister_driver(pc_driver
)) ||
1100 (tty_unregister_driver(pc_info
)))
1102 printk(KERN_WARNING
"epca: cleanup_module failed to un-register tty driver\n");
1105 put_tty_driver(pc_driver
);
1106 put_tty_driver(pc_info
);
1108 for (crd
= 0; crd
< num_cards
; crd
++) { /* Begin for each card */
1111 { /* Begin sanity check */
1112 printk(KERN_ERR
"<Error> - Digi : cleanup_module failed\n");
1114 } /* End sanity check */
1116 for (count
= 0; count
< bd
->numports
; count
++, ch
++)
1117 { /* Begin for each port */
1120 tty_hangup(ch
->tty
);
1123 } /* End for each port */
1124 } /* End for each card */
1125 pci_unregister_driver (&epca_driver
);
1128 module_exit(epca_module_exit
);
1130 static struct tty_operations pc_ops
= {
1134 .write_room
= pc_write_room
,
1135 .flush_buffer
= pc_flush_buffer
,
1136 .chars_in_buffer
= pc_chars_in_buffer
,
1137 .flush_chars
= pc_flush_chars
,
1138 .put_char
= pc_put_char
,
1140 .set_termios
= pc_set_termios
,
1143 .throttle
= pc_throttle
,
1144 .unthrottle
= pc_unthrottle
,
1145 .hangup
= pc_hangup
,
1148 static int info_open(struct tty_struct
*tty
, struct file
* filp
)
1153 static struct tty_operations info_ops
= {
1155 .ioctl
= info_ioctl
,
1158 /* ------------------ Begin pc_init ---------------------- */
1160 static int __init
pc_init(void)
1161 { /* Begin pc_init */
1163 struct board_info
*bd
;
1164 unsigned char board_id
= 0;
1166 int pci_boards_found
, pci_count
;
1170 pc_driver
= alloc_tty_driver(MAX_ALLOC
);
1174 pc_info
= alloc_tty_driver(MAX_ALLOC
);
1176 put_tty_driver(pc_driver
);
1180 /* -----------------------------------------------------------------------
1181 If epca_setup has not been ran by LILO set num_cards to defaults; copy
1182 board structure defined by digiConfig into drivers board structure.
1183 Note : If LILO has ran epca_setup then epca_setup will handle defining
1184 num_cards as well as copying the data into the board structure.
1185 -------------------------------------------------------------------------- */
1186 if (!liloconfig
) { /* Begin driver has been configured via. epcaconfig */
1189 num_cards
= NUMCARDS
;
1190 memcpy((void *)&boards
, (void *)&static_boards
,
1191 (sizeof(struct board_info
) * NUMCARDS
));
1192 } /* End driver has been configured via. epcaconfig */
1194 /* -----------------------------------------------------------------
1195 Note : If lilo was used to configure the driver and the
1196 ignore epcaconfig option was choosen (digiepca=2) then
1197 nbdevs and num_cards will equal 0 at this point. This is
1198 okay; PCI cards will still be picked up if detected.
1199 --------------------------------------------------------------------- */
1201 /* -----------------------------------------------------------
1202 Set up interrupt, we will worry about memory allocation in
1204 --------------------------------------------------------------- */
1207 printk(KERN_INFO
"DIGI epca driver version %s loaded.\n",VERSION
);
1209 /* ------------------------------------------------------------------
1210 NOTE : This code assumes that the number of ports found in
1211 the boards array is correct. This could be wrong if
1212 the card in question is PCI (And therefore has no ports
1213 entry in the boards structure.) The rest of the
1214 information will be valid for PCI because the beginning
1215 of pc_init scans for PCI and determines i/o and base
1216 memory addresses. I am not sure if it is possible to
1217 read the number of ports supported by the card prior to
1218 it being booted (Since that is the state it is in when
1219 pc_init is run). Because it is not possible to query the
1220 number of supported ports until after the card has booted;
1221 we are required to calculate the card_ptrs as the card is
1222 is initialized (Inside post_fep_init). The negative thing
1223 about this approach is that digiDload's call to GET_INFO
1224 will have a bad port value. (Since this is called prior
1227 --------------------------------------------------------------------- */
1229 pci_boards_found
= 0;
1230 if(num_cards
< MAXBOARDS
)
1231 pci_boards_found
+= init_PCI();
1232 num_cards
+= pci_boards_found
;
1234 pc_driver
->owner
= THIS_MODULE
;
1235 pc_driver
->name
= "ttyD";
1236 pc_driver
->devfs_name
= "tts/D";
1237 pc_driver
->major
= DIGI_MAJOR
;
1238 pc_driver
->minor_start
= 0;
1239 pc_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1240 pc_driver
->subtype
= SERIAL_TYPE_NORMAL
;
1241 pc_driver
->init_termios
= tty_std_termios
;
1242 pc_driver
->init_termios
.c_iflag
= 0;
1243 pc_driver
->init_termios
.c_oflag
= 0;
1244 pc_driver
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| CLOCAL
| HUPCL
;
1245 pc_driver
->init_termios
.c_lflag
= 0;
1246 pc_driver
->flags
= TTY_DRIVER_REAL_RAW
;
1247 tty_set_operations(pc_driver
, &pc_ops
);
1249 pc_info
->owner
= THIS_MODULE
;
1250 pc_info
->name
= "digi_ctl";
1251 pc_info
->major
= DIGIINFOMAJOR
;
1252 pc_info
->minor_start
= 0;
1253 pc_info
->type
= TTY_DRIVER_TYPE_SERIAL
;
1254 pc_info
->subtype
= SERIAL_TYPE_INFO
;
1255 pc_info
->init_termios
= tty_std_termios
;
1256 pc_info
->init_termios
.c_iflag
= 0;
1257 pc_info
->init_termios
.c_oflag
= 0;
1258 pc_info
->init_termios
.c_lflag
= 0;
1259 pc_info
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
;
1260 pc_info
->flags
= TTY_DRIVER_REAL_RAW
;
1261 tty_set_operations(pc_info
, &info_ops
);
1264 for (crd
= 0; crd
< num_cards
; crd
++)
1265 { /* Begin for each card */
1267 /* ------------------------------------------------------------------
1268 This is where the appropriate memory handlers for the hardware is
1269 set. Everything at runtime blindly jumps through these vectors.
1270 ---------------------------------------------------------------------- */
1272 /* defined in epcaconfig.h */
1276 { /* Begin switch on bd->type {board type} */
1279 bd
->memwinon
= pcxem_memwinon
;
1280 bd
->memwinoff
= pcxem_memwinoff
;
1281 bd
->globalwinon
= pcxem_globalwinon
;
1282 bd
->txwinon
= pcxem_txwinon
;
1283 bd
->rxwinon
= pcxem_rxwinon
;
1284 bd
->memoff
= pcxem_memoff
;
1285 bd
->assertgwinon
= dummy_assertgwinon
;
1286 bd
->assertmemoff
= dummy_assertmemoff
;
1292 bd
->memwinon
= dummy_memwinon
;
1293 bd
->memwinoff
= dummy_memwinoff
;
1294 bd
->globalwinon
= dummy_globalwinon
;
1295 bd
->txwinon
= dummy_txwinon
;
1296 bd
->rxwinon
= dummy_rxwinon
;
1297 bd
->memoff
= dummy_memoff
;
1298 bd
->assertgwinon
= dummy_assertgwinon
;
1299 bd
->assertmemoff
= dummy_assertmemoff
;
1305 bd
->memwinon
= pcxe_memwinon
;
1306 bd
->memwinoff
= pcxe_memwinoff
;
1307 bd
->globalwinon
= pcxe_globalwinon
;
1308 bd
->txwinon
= pcxe_txwinon
;
1309 bd
->rxwinon
= pcxe_rxwinon
;
1310 bd
->memoff
= pcxe_memoff
;
1311 bd
->assertgwinon
= dummy_assertgwinon
;
1312 bd
->assertmemoff
= dummy_assertmemoff
;
1318 bd
->memwinon
= pcxi_memwinon
;
1319 bd
->memwinoff
= pcxi_memwinoff
;
1320 bd
->globalwinon
= pcxi_globalwinon
;
1321 bd
->txwinon
= pcxi_txwinon
;
1322 bd
->rxwinon
= pcxi_rxwinon
;
1323 bd
->memoff
= pcxi_memoff
;
1324 bd
->assertgwinon
= pcxi_assertgwinon
;
1325 bd
->assertmemoff
= pcxi_assertmemoff
;
1331 } /* End switch on bd->type */
1333 /* ---------------------------------------------------------------
1334 Some cards need a memory segment to be defined for use in
1335 transmit and receive windowing operations. These boards
1336 are listed in the below switch. In the case of the XI the
1337 amount of memory on the board is variable so the memory_seg
1338 is also variable. This code determines what they segment
1340 ----------------------------------------------------------------- */
1343 { /* Begin switch on bd->type {board type} */
1348 bd
->memory_seg
= 0xf000;
1352 board_id
= inb((int)bd
->port
);
1353 if ((board_id
& 0x1) == 0x1)
1354 { /* Begin it's an XI card */
1356 /* Is it a 64K board */
1357 if ((board_id
& 0x30) == 0)
1358 bd
->memory_seg
= 0xf000;
1360 /* Is it a 128K board */
1361 if ((board_id
& 0x30) == 0x10)
1362 bd
->memory_seg
= 0xe000;
1364 /* Is is a 256K board */
1365 if ((board_id
& 0x30) == 0x20)
1366 bd
->memory_seg
= 0xc000;
1368 /* Is it a 512K board */
1369 if ((board_id
& 0x30) == 0x30)
1370 bd
->memory_seg
= 0x8000;
1372 } else printk(KERN_ERR
"epca: Board at 0x%x doesn't appear to be an XI\n",(int)bd
->port
);
1375 } /* End switch on bd->type */
1377 } /* End for each card */
1379 if (tty_register_driver(pc_driver
))
1380 panic("Couldn't register Digi PC/ driver");
1382 if (tty_register_driver(pc_info
))
1383 panic("Couldn't register Digi PC/ info ");
1385 /* -------------------------------------------------------------------
1386 Start up the poller to check for events on all enabled boards
1387 ---------------------------------------------------------------------- */
1389 init_timer(&epca_timer
);
1390 epca_timer
.function
= epcapoll
;
1391 mod_timer(&epca_timer
, jiffies
+ HZ
/25);
1396 /* ------------------ Begin post_fep_init ---------------------- */
1398 static void post_fep_init(unsigned int crd
)
1399 { /* Begin post_fep_init */
1402 void __iomem
*memaddr
;
1403 struct global_data __iomem
*gd
;
1404 struct board_info
*bd
;
1405 struct board_chan __iomem
*bc
;
1407 int shrinkmem
= 0, lowwater
;
1409 /* -------------------------------------------------------------
1410 This call is made by the user via. the ioctl call DIGI_INIT.
1411 It is responsible for setting up all the card specific stuff.
1412 ---------------------------------------------------------------- */
1415 /* -----------------------------------------------------------------
1416 If this is a PCI board, get the port info. Remember PCI cards
1417 do not have entries into the epcaconfig.h file, so we can't get
1418 the number of ports from it. Unfortunetly, this means that anyone
1419 doing a DIGI_GETINFO before the board has booted will get an invalid
1420 number of ports returned (It should return 0). Calls to DIGI_GETINFO
1421 after DIGI_INIT has been called will return the proper values.
1422 ------------------------------------------------------------------- */
1424 if (bd
->type
>= PCIXEM
) { /* Begin get PCI number of ports */
1425 /* --------------------------------------------------------------------
1426 Below we use XEMPORTS as a memory offset regardless of which PCI
1427 card it is. This is because all of the supported PCI cards have
1428 the same memory offset for the channel data. This will have to be
1429 changed if we ever develop a PCI/XE card. NOTE : The FEP manual
1430 states that the port offset is 0xC22 as opposed to 0xC02. This is
1431 only true for PC/XE, and PC/XI cards; not for the XEM, or CX series.
1432 On the PCI cards the number of ports is determined by reading a
1433 ID PROM located in the box attached to the card. The card can then
1434 determine the index the id to determine the number of ports available.
1435 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
1436 if the box in question is a XEM or CX)).
1437 ------------------------------------------------------------------------ */
1438 /* PCI cards are already remapped at this point ISA are not */
1439 bd
->numports
= readw(bd
->re_map_membase
+ XEMPORTS
);
1440 epcaassert(bd
->numports
<= 64,"PCI returned a invalid number of ports");
1441 nbdevs
+= (bd
->numports
);
1443 /* Fix up the mappings for ISA/EISA etc */
1444 /* FIXME: 64K - can we be smarter ? */
1445 bd
->re_map_membase
= ioremap(bd
->membase
, 0x10000);
1449 card_ptr
[crd
] = card_ptr
[crd
-1] + boards
[crd
-1].numports
;
1451 card_ptr
[crd
] = &digi_channels
[crd
]; /* <- For card 0 only */
1454 epcaassert(ch
<= &digi_channels
[nbdevs
- 1], "ch out of range");
1456 memaddr
= bd
->re_map_membase
;
1458 /* -----------------------------------------------------------------
1459 The below assignment will set bc to point at the BEGINING of
1460 the cards channel structures. For 1 card there will be between
1461 8 and 64 of these structures.
1462 -------------------------------------------------------------------- */
1464 bc
= memaddr
+ CHANSTRUCT
;
1466 /* -------------------------------------------------------------------
1467 The below assignment will set gd to point at the BEGINING of
1468 global memory address 0xc00. The first data in that global
1469 memory actually starts at address 0xc1a. The command in
1470 pointer begins at 0xd10.
1471 ---------------------------------------------------------------------- */
1473 gd
= memaddr
+ GLOBAL
;
1475 /* --------------------------------------------------------------------
1476 XEPORTS (address 0xc22) points at the number of channels the
1477 card supports. (For 64XE, XI, XEM, and XR use 0xc02)
1478 ----------------------------------------------------------------------- */
1480 if ((bd
->type
== PCXEVE
|| bd
->type
== PCXE
) && (readw(memaddr
+ XEPORTS
) < 3))
1482 if (bd
->type
< PCIXEM
)
1483 if (!request_region((int)bd
->port
, 4, board_desc
[bd
->type
]))
1487 /* --------------------------------------------------------------------
1488 Remember ch is the main drivers channels structure, while bc is
1489 the cards channel structure.
1490 ------------------------------------------------------------------------ */
1492 /* For every port on the card do ..... */
1494 for (i
= 0; i
< bd
->numports
; i
++, ch
++, bc
++) { /* Begin for each port */
1495 unsigned long flags
;
1500 INIT_WORK(&ch
->tqueue
, do_softint
, ch
);
1501 ch
->board
= &boards
[crd
];
1503 spin_lock_irqsave(&epca_lock
, flags
);
1505 /* ----------------------------------------------------------------
1506 Since some of the boards use different bitmaps for their
1507 control signals we cannot hard code these values and retain
1508 portability. We virtualize this data here.
1509 ------------------------------------------------------------------- */
1535 } /* End switch bd->type */
1537 if (boards
[crd
].altpin
) {
1538 ch
->dsr
= ch
->m_dcd
;
1539 ch
->dcd
= ch
->m_dsr
;
1540 ch
->digiext
.digi_flags
|= DIGI_ALTPIN
;
1543 ch
->dcd
= ch
->m_dcd
;
1544 ch
->dsr
= ch
->m_dsr
;
1549 ch
->magic
= EPCA_MAGIC
;
1553 fepcmd(ch
, SETBUFFER
, 32, 0, 0, 0);
1557 tseg
= readw(&bc
->tseg
);
1558 rseg
= readw(&bc
->rseg
);
1565 /* Cover all the 2MEG cards */
1566 ch
->txptr
= memaddr
+ ((tseg
<< 4) & 0x1fffff);
1567 ch
->rxptr
= memaddr
+ ((rseg
<< 4) & 0x1fffff);
1568 ch
->txwin
= FEPWIN
| (tseg
>> 11);
1569 ch
->rxwin
= FEPWIN
| (rseg
>> 11);
1574 /* Cover all the 32K windowed cards */
1575 /* Mask equal to window size - 1 */
1576 ch
->txptr
= memaddr
+ ((tseg
<< 4) & 0x7fff);
1577 ch
->rxptr
= memaddr
+ ((rseg
<< 4) & 0x7fff);
1578 ch
->txwin
= FEPWIN
| (tseg
>> 11);
1579 ch
->rxwin
= FEPWIN
| (rseg
>> 11);
1584 ch
->txptr
= memaddr
+ (((tseg
- bd
->memory_seg
) << 4) & 0x1fff);
1585 ch
->txwin
= FEPWIN
| ((tseg
- bd
->memory_seg
) >> 9);
1586 ch
->rxptr
= memaddr
+ (((rseg
- bd
->memory_seg
) << 4) & 0x1fff);
1587 ch
->rxwin
= FEPWIN
| ((rseg
- bd
->memory_seg
) >>9 );
1592 ch
->txptr
= memaddr
+ ((tseg
- bd
->memory_seg
) << 4);
1593 ch
->rxptr
= memaddr
+ ((rseg
- bd
->memory_seg
) << 4);
1594 ch
->txwin
= ch
->rxwin
= 0;
1597 } /* End switch bd->type */
1600 ch
->txbufsize
= readw(&bc
->tmax
) + 1;
1603 ch
->rxbufsize
= readw(&bc
->rmax
) + 1;
1605 lowwater
= ch
->txbufsize
>= 2000 ? 1024 : (ch
->txbufsize
/ 2);
1607 /* Set transmitter low water mark */
1608 fepcmd(ch
, STXLWATER
, lowwater
, 0, 10, 0);
1610 /* Set receiver low water mark */
1612 fepcmd(ch
, SRXLWATER
, (ch
->rxbufsize
/ 4), 0, 10, 0);
1614 /* Set receiver high water mark */
1616 fepcmd(ch
, SRXHWATER
, (3 * ch
->rxbufsize
/ 4), 0, 10, 0);
1618 writew(100, &bc
->edelay
);
1619 writeb(1, &bc
->idata
);
1621 ch
->startc
= readb(&bc
->startc
);
1622 ch
->stopc
= readb(&bc
->stopc
);
1623 ch
->startca
= readb(&bc
->startca
);
1624 ch
->stopca
= readb(&bc
->stopca
);
1634 ch
->close_delay
= 50;
1636 ch
->blocked_open
= 0;
1637 init_waitqueue_head(&ch
->open_wait
);
1638 init_waitqueue_head(&ch
->close_wait
);
1640 spin_unlock_irqrestore(&epca_lock
, flags
);
1642 ch
->tmp_buf
= kmalloc(ch
->txbufsize
,GFP_KERNEL
);
1644 printk(KERN_ERR
"POST FEP INIT : kmalloc failed for port 0x%x\n",i
);
1645 release_region((int)bd
->port
, 4);
1647 kfree((ch
--)->tmp_buf
);
1650 memset((void *)ch
->tmp_buf
,0,ch
->txbufsize
);
1651 } /* End for each port */
1654 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1655 VERSION
, board_desc
[bd
->type
], (long)bd
->port
, (long)bd
->membase
, bd
->numports
);
1658 } /* End post_fep_init */
1660 /* --------------------- Begin epcapoll ------------------------ */
1662 static void epcapoll(unsigned long ignored
)
1663 { /* Begin epcapoll */
1665 unsigned long flags
;
1667 volatile unsigned int head
, tail
;
1669 struct board_info
*bd
;
1671 /* -------------------------------------------------------------------
1672 This routine is called upon every timer interrupt. Even though
1673 the Digi series cards are capable of generating interrupts this
1674 method of non-looping polling is more efficient. This routine
1675 checks for card generated events (Such as receive data, are transmit
1676 buffer empty) and acts on those events.
1677 ----------------------------------------------------------------------- */
1679 for (crd
= 0; crd
< num_cards
; crd
++)
1680 { /* Begin for each card */
1685 if ((bd
->status
== DISABLED
) || digi_poller_inhibited
)
1686 continue; /* Begin loop next interation */
1688 /* -----------------------------------------------------------
1689 assertmemoff is not needed here; indeed it is an empty subroutine.
1690 It is being kept because future boards may need this as well as
1692 ---------------------------------------------------------------- */
1694 spin_lock_irqsave(&epca_lock
, flags
);
1700 /* ---------------------------------------------------------------
1701 In this case head and tail actually refer to the event queue not
1702 the transmit or receive queue.
1703 ------------------------------------------------------------------- */
1705 head
= readw(&ch
->mailbox
->ein
);
1706 tail
= readw(&ch
->mailbox
->eout
);
1708 /* If head isn't equal to tail we have an event */
1714 spin_unlock_irqrestore(&epca_lock
, flags
);
1716 } /* End for each card */
1717 mod_timer(&epca_timer
, jiffies
+ (HZ
/ 25));
1718 } /* End epcapoll */
1720 /* --------------------- Begin doevent ------------------------ */
1722 static void doevent(int crd
)
1723 { /* Begin doevent */
1725 void __iomem
*eventbuf
;
1726 struct channel
*ch
, *chan0
;
1727 static struct tty_struct
*tty
;
1728 struct board_info
*bd
;
1729 struct board_chan __iomem
*bc
;
1730 unsigned int tail
, head
;
1734 /* -------------------------------------------------------------------
1735 This subroutine is called by epcapoll when an event is detected
1736 in the event queue. This routine responds to those events.
1737 --------------------------------------------------------------------- */
1740 chan0
= card_ptr
[crd
];
1741 epcaassert(chan0
<= &digi_channels
[nbdevs
- 1], "ch out of range");
1742 assertgwinon(chan0
);
1743 while ((tail
= readw(&chan0
->mailbox
->eout
)) != (head
= readw(&chan0
->mailbox
->ein
)))
1744 { /* Begin while something in event queue */
1745 assertgwinon(chan0
);
1746 eventbuf
= bd
->re_map_membase
+ tail
+ ISTART
;
1747 /* Get the channel the event occurred on */
1748 channel
= readb(eventbuf
);
1749 /* Get the actual event code that occurred */
1750 event
= readb(eventbuf
+ 1);
1751 /* ----------------------------------------------------------------
1752 The two assignments below get the current modem status (mstat)
1753 and the previous modem status (lstat). These are useful becuase
1754 an event could signal a change in modem signals itself.
1755 ------------------------------------------------------------------- */
1756 mstat
= readb(eventbuf
+ 2);
1757 lstat
= readb(eventbuf
+ 3);
1759 ch
= chan0
+ channel
;
1760 if ((unsigned)channel
>= bd
->numports
|| !ch
) {
1761 if (channel
>= bd
->numports
)
1767 if ((bc
= ch
->brdchan
) == NULL
)
1770 if (event
& DATA_IND
) { /* Begin DATA_IND */
1773 } /* End DATA_IND */
1774 /* else *//* Fix for DCD transition missed bug */
1775 if (event
& MODEMCHG_IND
) { /* Begin MODEMCHG_IND */
1776 /* A modem signal change has been indicated */
1778 if (ch
->asyncflags
& ASYNC_CHECK_CD
) {
1779 if (mstat
& ch
->dcd
) /* We are now receiving dcd */
1780 wake_up_interruptible(&ch
->open_wait
);
1782 pc_sched_event(ch
, EPCA_EVENT_HANGUP
); /* No dcd; hangup */
1784 } /* End MODEMCHG_IND */
1786 if (tty
) { /* Begin if valid tty */
1787 if (event
& BREAK_IND
) { /* Begin if BREAK_IND */
1788 /* A break has been indicated */
1789 tty_insert_flip_char(tty
, 0, TTY_BREAK
);
1790 tty_schedule_flip(tty
);
1791 } else if (event
& LOWTX_IND
) { /* Begin LOWTX_IND */
1792 if (ch
->statusflags
& LOWWAIT
)
1793 { /* Begin if LOWWAIT */
1794 ch
->statusflags
&= ~LOWWAIT
;
1796 wake_up_interruptible(&tty
->write_wait
);
1797 } /* End if LOWWAIT */
1798 } else if (event
& EMPTYTX_IND
) { /* Begin EMPTYTX_IND */
1799 /* This event is generated by setup_empty_event */
1800 ch
->statusflags
&= ~TXBUSY
;
1801 if (ch
->statusflags
& EMPTYWAIT
) { /* Begin if EMPTYWAIT */
1802 ch
->statusflags
&= ~EMPTYWAIT
;
1804 wake_up_interruptible(&tty
->write_wait
);
1805 } /* End if EMPTYWAIT */
1806 } /* End EMPTYTX_IND */
1807 } /* End if valid tty */
1811 writew(1, &bc
->idata
);
1812 writew((tail
+ 4) & (IMAX
- ISTART
- 4), &chan0
->mailbox
->eout
);
1814 } /* End while something in event queue */
1817 /* --------------------- Begin fepcmd ------------------------ */
1819 static void fepcmd(struct channel
*ch
, int cmd
, int word_or_byte
,
1820 int byte2
, int ncmds
, int bytecmd
)
1821 { /* Begin fepcmd */
1822 unchar __iomem
*memaddr
;
1823 unsigned int head
, cmdTail
, cmdStart
, cmdMax
;
1827 /* This is the routine in which commands may be passed to the card. */
1829 if (ch
->board
->status
== DISABLED
)
1832 /* Remember head (As well as max) is just an offset not a base addr */
1833 head
= readw(&ch
->mailbox
->cin
);
1834 /* cmdStart is a base address */
1835 cmdStart
= readw(&ch
->mailbox
->cstart
);
1836 /* ------------------------------------------------------------------
1837 We do the addition below because we do not want a max pointer
1838 relative to cmdStart. We want a max pointer that points at the
1839 physical end of the command queue.
1840 -------------------------------------------------------------------- */
1841 cmdMax
= (cmdStart
+ 4 + readw(&ch
->mailbox
->cmax
));
1842 memaddr
= ch
->board
->re_map_membase
;
1844 if (head
>= (cmdMax
- cmdStart
) || (head
& 03)) {
1845 printk(KERN_ERR
"line %d: Out of range, cmd = %x, head = %x\n", __LINE__
, cmd
, head
);
1846 printk(KERN_ERR
"line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__
, cmdMax
, cmdStart
);
1850 writeb(cmd
, memaddr
+ head
+ cmdStart
+ 0);
1851 writeb(ch
->channelnum
, memaddr
+ head
+ cmdStart
+ 1);
1852 /* Below word_or_byte is bits to set */
1853 writeb(word_or_byte
, memaddr
+ head
+ cmdStart
+ 2);
1854 /* Below byte2 is bits to reset */
1855 writeb(byte2
, memaddr
+ head
+ cmdStart
+ 3);
1857 writeb(cmd
, memaddr
+ head
+ cmdStart
+ 0);
1858 writeb(ch
->channelnum
, memaddr
+ head
+ cmdStart
+ 1);
1859 writeb(word_or_byte
, memaddr
+ head
+ cmdStart
+ 2);
1861 head
= (head
+ 4) & (cmdMax
- cmdStart
- 4);
1862 writew(head
, &ch
->mailbox
->cin
);
1865 for (;;) { /* Begin forever loop */
1868 printk(KERN_ERR
"<Error> - Fep not responding in fepcmd()\n");
1871 head
= readw(&ch
->mailbox
->cin
);
1872 cmdTail
= readw(&ch
->mailbox
->cout
);
1873 n
= (head
- cmdTail
) & (cmdMax
- cmdStart
- 4);
1874 /* ----------------------------------------------------------
1875 Basically this will break when the FEP acknowledges the
1876 command by incrementing cmdTail (Making it equal to head).
1877 ------------------------------------------------------------- */
1878 if (n
<= ncmds
* (sizeof(short) * 4))
1879 break; /* Well nearly forever :-) */
1880 } /* End forever loop */
1883 /* ---------------------------------------------------------------------
1884 Digi products use fields in their channels structures that are very
1885 similar to the c_cflag and c_iflag fields typically found in UNIX
1886 termios structures. The below three routines allow mappings
1887 between these hardware "flags" and their respective Linux flags.
1888 ------------------------------------------------------------------------- */
1890 /* --------------------- Begin termios2digi_h -------------------- */
1892 static unsigned termios2digi_h(struct channel
*ch
, unsigned cflag
)
1893 { /* Begin termios2digi_h */
1896 if (cflag
& CRTSCTS
) {
1897 ch
->digiext
.digi_flags
|= (RTSPACE
| CTSPACE
);
1898 res
|= ((ch
->m_cts
) | (ch
->m_rts
));
1901 if (ch
->digiext
.digi_flags
& RTSPACE
)
1904 if (ch
->digiext
.digi_flags
& DTRPACE
)
1907 if (ch
->digiext
.digi_flags
& CTSPACE
)
1910 if (ch
->digiext
.digi_flags
& DSRPACE
)
1913 if (ch
->digiext
.digi_flags
& DCDPACE
)
1916 if (res
& (ch
->m_rts
))
1917 ch
->digiext
.digi_flags
|= RTSPACE
;
1919 if (res
& (ch
->m_cts
))
1920 ch
->digiext
.digi_flags
|= CTSPACE
;
1924 } /* End termios2digi_h */
1926 /* --------------------- Begin termios2digi_i -------------------- */
1927 static unsigned termios2digi_i(struct channel
*ch
, unsigned iflag
)
1928 { /* Begin termios2digi_i */
1930 unsigned res
= iflag
& (IGNBRK
| BRKINT
| IGNPAR
| PARMRK
|
1931 INPCK
| ISTRIP
|IXON
|IXANY
|IXOFF
);
1932 if (ch
->digiext
.digi_flags
& DIGI_AIXON
)
1936 } /* End termios2digi_i */
1938 /* --------------------- Begin termios2digi_c -------------------- */
1940 static unsigned termios2digi_c(struct channel
*ch
, unsigned cflag
)
1941 { /* Begin termios2digi_c */
1944 if (cflag
& CBAUDEX
) { /* Begin detected CBAUDEX */
1945 ch
->digiext
.digi_flags
|= DIGI_FAST
;
1946 /* -------------------------------------------------------------
1947 HUPCL bit is used by FEP to indicate fast baud
1948 table is to be used.
1949 ----------------------------------------------------------------- */
1951 } /* End detected CBAUDEX */
1952 else ch
->digiext
.digi_flags
&= ~DIGI_FAST
;
1953 /* -------------------------------------------------------------------
1954 CBAUD has bit position 0x1000 set these days to indicate Linux
1955 baud rate remap. Digi hardware can't handle the bit assignment.
1956 (We use a different bit assignment for high speed.). Clear this
1958 ---------------------------------------------------------------------- */
1959 res
|= cflag
& ((CBAUD
^ CBAUDEX
) | PARODD
| PARENB
| CSTOPB
| CSIZE
);
1960 /* -------------------------------------------------------------
1961 This gets a little confusing. The Digi cards have their own
1962 representation of c_cflags controling baud rate. For the most
1963 part this is identical to the Linux implementation. However;
1964 Digi supports one rate (76800) that Linux doesn't. This means
1965 that the c_cflag entry that would normally mean 76800 for Digi
1966 actually means 115200 under Linux. Without the below mapping,
1967 a stty 115200 would only drive the board at 76800. Since
1968 the rate 230400 is also found after 76800, the same problem afflicts
1969 us when we choose a rate of 230400. Without the below modificiation
1970 stty 230400 would actually give us 115200.
1972 There are two additional differences. The Linux value for CLOCAL
1973 (0x800; 0004000) has no meaning to the Digi hardware. Also in
1974 later releases of Linux; the CBAUD define has CBAUDEX (0x1000;
1975 0010000) ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX
1976 should be checked for a screened out prior to termios2digi_c
1977 returning. Since CLOCAL isn't used by the board this can be
1978 ignored as long as the returned value is used only by Digi hardware.
1979 ----------------------------------------------------------------- */
1980 if (cflag
& CBAUDEX
) {
1981 /* -------------------------------------------------------------
1982 The below code is trying to guarantee that only baud rates
1983 115200 and 230400 are remapped. We use exclusive or because
1984 the various baud rates share common bit positions and therefore
1985 can't be tested for easily.
1986 ----------------------------------------------------------------- */
1989 if ((!((cflag
& 0x7) ^ (B115200
& ~CBAUDEX
))) ||
1990 (!((cflag
& 0x7) ^ (B230400
& ~CBAUDEX
))))
1995 } /* End termios2digi_c */
1997 /* --------------------- Begin epcaparam ----------------------- */
1999 /* Caller must hold the locks */
2000 static void epcaparam(struct tty_struct
*tty
, struct channel
*ch
)
2001 { /* Begin epcaparam */
2003 unsigned int cmdHead
;
2005 struct board_chan __iomem
*bc
;
2006 unsigned mval
, hflow
, cflag
, iflag
;
2009 epcaassert(bc
!=0, "bc out of range");
2013 if ((ts
->c_cflag
& CBAUD
) == 0) { /* Begin CBAUD detected */
2014 cmdHead
= readw(&bc
->rin
);
2015 writew(cmdHead
, &bc
->rout
);
2016 cmdHead
= readw(&bc
->tin
);
2017 /* Changing baud in mid-stream transmission can be wonderful */
2018 /* ---------------------------------------------------------------
2019 Flush current transmit buffer by setting cmdTail pointer (tout)
2020 to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
2021 ----------------------------------------------------------------- */
2022 fepcmd(ch
, STOUT
, (unsigned) cmdHead
, 0, 0, 0);
2024 } else { /* Begin CBAUD not detected */
2025 /* -------------------------------------------------------------------
2026 c_cflags have changed but that change had nothing to do with BAUD.
2027 Propagate the change to the card.
2028 ---------------------------------------------------------------------- */
2029 cflag
= termios2digi_c(ch
, ts
->c_cflag
);
2030 if (cflag
!= ch
->fepcflag
) {
2031 ch
->fepcflag
= cflag
;
2032 /* Set baud rate, char size, stop bits, parity */
2033 fepcmd(ch
, SETCTRLFLAGS
, (unsigned) cflag
, 0, 0, 0);
2035 /* ----------------------------------------------------------------
2036 If the user has not forced CLOCAL and if the device is not a
2037 CALLOUT device (Which is always CLOCAL) we set flags such that
2038 the driver will wait on carrier detect.
2039 ------------------------------------------------------------------- */
2040 if (ts
->c_cflag
& CLOCAL
)
2041 ch
->asyncflags
&= ~ASYNC_CHECK_CD
;
2043 ch
->asyncflags
|= ASYNC_CHECK_CD
;
2044 mval
= ch
->m_dtr
| ch
->m_rts
;
2045 } /* End CBAUD not detected */
2046 iflag
= termios2digi_i(ch
, ts
->c_iflag
);
2047 /* Check input mode flags */
2048 if (iflag
!= ch
->fepiflag
) {
2049 ch
->fepiflag
= iflag
;
2050 /* ---------------------------------------------------------------
2051 Command sets channels iflag structure on the board. Such things
2052 as input soft flow control, handling of parity errors, and
2053 break handling are all set here.
2054 ------------------------------------------------------------------- */
2055 /* break handling, parity handling, input stripping, flow control chars */
2056 fepcmd(ch
, SETIFLAGS
, (unsigned int) ch
->fepiflag
, 0, 0, 0);
2058 /* ---------------------------------------------------------------
2059 Set the board mint value for this channel. This will cause hardware
2060 events to be generated each time the DCD signal (Described in mint)
2062 ------------------------------------------------------------------- */
2063 writeb(ch
->dcd
, &bc
->mint
);
2064 if ((ts
->c_cflag
& CLOCAL
) || (ch
->digiext
.digi_flags
& DIGI_FORCEDCD
))
2065 if (ch
->digiext
.digi_flags
& DIGI_FORCEDCD
)
2066 writeb(0, &bc
->mint
);
2067 ch
->imodem
= readb(&bc
->mstat
);
2068 hflow
= termios2digi_h(ch
, ts
->c_cflag
);
2069 if (hflow
!= ch
->hflow
) {
2071 /* --------------------------------------------------------------
2072 Hard flow control has been selected but the board is not
2073 using it. Activate hard flow control now.
2074 ----------------------------------------------------------------- */
2075 fepcmd(ch
, SETHFLOW
, hflow
, 0xff, 0, 1);
2077 mval
^= ch
->modemfake
& (mval
^ ch
->modem
);
2079 if (ch
->omodem
^ mval
) {
2081 /* --------------------------------------------------------------
2082 The below command sets the DTR and RTS mstat structure. If
2083 hard flow control is NOT active these changes will drive the
2084 output of the actual DTR and RTS lines. If hard flow control
2085 is active, the changes will be saved in the mstat structure and
2086 only asserted when hard flow control is turned off.
2087 ----------------------------------------------------------------- */
2089 /* First reset DTR & RTS; then set them */
2090 fepcmd(ch
, SETMODEM
, 0, ((ch
->m_dtr
)|(ch
->m_rts
)), 0, 1);
2091 fepcmd(ch
, SETMODEM
, mval
, 0, 0, 1);
2093 if (ch
->startc
!= ch
->fepstartc
|| ch
->stopc
!= ch
->fepstopc
) {
2094 ch
->fepstartc
= ch
->startc
;
2095 ch
->fepstopc
= ch
->stopc
;
2096 /* ------------------------------------------------------------
2097 The XON / XOFF characters have changed; propagate these
2098 changes to the card.
2099 --------------------------------------------------------------- */
2100 fepcmd(ch
, SONOFFC
, ch
->fepstartc
, ch
->fepstopc
, 0, 1);
2102 if (ch
->startca
!= ch
->fepstartca
|| ch
->stopca
!= ch
->fepstopca
) {
2103 ch
->fepstartca
= ch
->startca
;
2104 ch
->fepstopca
= ch
->stopca
;
2105 /* ---------------------------------------------------------------
2106 Similar to the above, this time the auxilarly XON / XOFF
2107 characters have changed; propagate these changes to the card.
2108 ------------------------------------------------------------------ */
2109 fepcmd(ch
, SAUXONOFFC
, ch
->fepstartca
, ch
->fepstopca
, 0, 1);
2111 } /* End epcaparam */
2113 /* --------------------- Begin receive_data ----------------------- */
2114 /* Caller holds lock */
2115 static void receive_data(struct channel
*ch
)
2116 { /* Begin receive_data */
2119 struct termios
*ts
= NULL
;
2120 struct tty_struct
*tty
;
2121 struct board_chan __iomem
*bc
;
2122 int dataToRead
, wrapgap
, bytesAvailable
;
2123 unsigned int tail
, head
;
2124 unsigned int wrapmask
;
2126 /* ---------------------------------------------------------------
2127 This routine is called by doint when a receive data event
2129 ------------------------------------------------------------------- */
2132 if (ch
->statusflags
& RXSTOPPED
)
2139 wrapmask
= ch
->rxbufsize
- 1;
2141 /* ---------------------------------------------------------------------
2142 Get the head and tail pointers to the receiver queue. Wrap the
2143 head pointer if it has reached the end of the buffer.
2144 ------------------------------------------------------------------------ */
2145 head
= readw(&bc
->rin
);
2147 tail
= readw(&bc
->rout
) & wrapmask
;
2149 bytesAvailable
= (head
- tail
) & wrapmask
;
2150 if (bytesAvailable
== 0)
2153 /* ------------------------------------------------------------------
2154 If CREAD bit is off or device not open, set TX tail to head
2155 --------------------------------------------------------------------- */
2157 if (!tty
|| !ts
|| !(ts
->c_cflag
& CREAD
)) {
2158 writew(head
, &bc
->rout
);
2162 if (tty_buffer_request_room(tty
, bytesAvailable
+ 1) == 0)
2165 if (readb(&bc
->orun
)) {
2166 writeb(0, &bc
->orun
);
2167 printk(KERN_WARNING
"epca; overrun! DigiBoard device %s\n",tty
->name
);
2168 tty_insert_flip_char(tty
, 0, TTY_OVERRUN
);
2171 while (bytesAvailable
> 0) { /* Begin while there is data on the card */
2172 wrapgap
= (head
>= tail
) ? head
- tail
: ch
->rxbufsize
- tail
;
2173 /* ---------------------------------------------------------------
2174 Even if head has wrapped around only report the amount of
2175 data to be equal to the size - tail. Remember memcpy can't
2176 automaticly wrap around the receive buffer.
2177 ----------------------------------------------------------------- */
2178 dataToRead
= (wrapgap
< bytesAvailable
) ? wrapgap
: bytesAvailable
;
2179 /* --------------------------------------------------------------
2180 Make sure we don't overflow the buffer
2181 ----------------------------------------------------------------- */
2182 dataToRead
= tty_prepare_flip_string(tty
, &rptr
, dataToRead
);
2183 if (dataToRead
== 0)
2185 /* ---------------------------------------------------------------
2186 Move data read from our card into the line disciplines buffer
2187 for translation if necessary.
2188 ------------------------------------------------------------------ */
2189 memcpy_fromio(rptr
, ch
->rxptr
+ tail
, dataToRead
);
2190 tail
= (tail
+ dataToRead
) & wrapmask
;
2191 bytesAvailable
-= dataToRead
;
2192 } /* End while there is data on the card */
2194 writew(tail
, &bc
->rout
);
2195 /* Must be called with global data */
2196 tty_schedule_flip(ch
->tty
);
2198 } /* End receive_data */
2200 static int info_ioctl(struct tty_struct
*tty
, struct file
* file
,
2201 unsigned int cmd
, unsigned long arg
)
2204 { /* Begin switch cmd */
2206 { /* Begin case DIGI_GETINFO */
2207 struct digi_info di
;
2210 if(get_user(brd
, (unsigned int __user
*)arg
))
2212 if (brd
< 0 || brd
>= num_cards
|| num_cards
== 0)
2215 memset(&di
, 0, sizeof(di
));
2218 di
.status
= boards
[brd
].status
;
2219 di
.type
= boards
[brd
].type
;
2220 di
.numports
= boards
[brd
].numports
;
2221 /* Legacy fixups - just move along nothing to see */
2222 di
.port
= (unsigned char *)boards
[brd
].port
;
2223 di
.membase
= (unsigned char *)boards
[brd
].membase
;
2225 if (copy_to_user((void __user
*)arg
, &di
, sizeof (di
)))
2229 } /* End case DIGI_GETINFO */
2232 { /* Begin case DIGI_POLLER */
2234 int brd
= arg
& 0xff000000 >> 16 ;
2235 unsigned char state
= arg
& 0xff ;
2237 if (brd
< 0 || brd
>= num_cards
) {
2238 printk(KERN_ERR
"epca: DIGI POLLER : brd not valid!\n");
2241 digi_poller_inhibited
= state
;
2243 } /* End case DIGI_POLLER */
2246 { /* Begin case DIGI_INIT */
2247 /* ------------------------------------------------------------
2248 This call is made by the apps to complete the initilization
2249 of the board(s). This routine is responsible for setting
2250 the card to its initial state and setting the drivers control
2251 fields to the sutianle settings for the card in question.
2252 ---------------------------------------------------------------- */
2254 for (crd
= 0; crd
< num_cards
; crd
++)
2255 post_fep_init (crd
);
2257 } /* End case DIGI_INIT */
2260 } /* End switch cmd */
2263 /* --------------------- Begin pc_ioctl ----------------------- */
2265 static int pc_tiocmget(struct tty_struct
*tty
, struct file
*file
)
2267 struct channel
*ch
= (struct channel
*) tty
->driver_data
;
2268 struct board_chan __iomem
*bc
;
2269 unsigned int mstat
, mflag
= 0;
2270 unsigned long flags
;
2277 spin_lock_irqsave(&epca_lock
, flags
);
2279 mstat
= readb(&bc
->mstat
);
2281 spin_unlock_irqrestore(&epca_lock
, flags
);
2283 if (mstat
& ch
->m_dtr
)
2285 if (mstat
& ch
->m_rts
)
2287 if (mstat
& ch
->m_cts
)
2289 if (mstat
& ch
->dsr
)
2291 if (mstat
& ch
->m_ri
)
2293 if (mstat
& ch
->dcd
)
2298 static int pc_tiocmset(struct tty_struct
*tty
, struct file
*file
,
2299 unsigned int set
, unsigned int clear
)
2301 struct channel
*ch
= (struct channel
*) tty
->driver_data
;
2302 unsigned long flags
;
2307 spin_lock_irqsave(&epca_lock
, flags
);
2309 * I think this modemfake stuff is broken. It doesn't
2310 * correctly reflect the behaviour desired by the TIOCM*
2311 * ioctls. Therefore this is probably broken.
2313 if (set
& TIOCM_RTS
) {
2314 ch
->modemfake
|= ch
->m_rts
;
2315 ch
->modem
|= ch
->m_rts
;
2317 if (set
& TIOCM_DTR
) {
2318 ch
->modemfake
|= ch
->m_dtr
;
2319 ch
->modem
|= ch
->m_dtr
;
2321 if (clear
& TIOCM_RTS
) {
2322 ch
->modemfake
|= ch
->m_rts
;
2323 ch
->modem
&= ~ch
->m_rts
;
2325 if (clear
& TIOCM_DTR
) {
2326 ch
->modemfake
|= ch
->m_dtr
;
2327 ch
->modem
&= ~ch
->m_dtr
;
2330 /* --------------------------------------------------------------
2331 The below routine generally sets up parity, baud, flow control
2332 issues, etc.... It effect both control flags and input flags.
2333 ------------------------------------------------------------------ */
2336 spin_unlock_irqrestore(&epca_lock
, flags
);
2340 static int pc_ioctl(struct tty_struct
*tty
, struct file
* file
,
2341 unsigned int cmd
, unsigned long arg
)
2342 { /* Begin pc_ioctl */
2346 unsigned long flags
;
2347 unsigned int mflag
, mstat
;
2348 unsigned char startc
, stopc
;
2349 struct board_chan __iomem
*bc
;
2350 struct channel
*ch
= (struct channel
*) tty
->driver_data
;
2351 void __user
*argp
= (void __user
*)arg
;
2358 /* -------------------------------------------------------------------
2359 For POSIX compliance we need to add more ioctls. See tty_ioctl.c
2360 in /usr/src/linux/drivers/char for a good example. In particular
2361 think about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
2362 ---------------------------------------------------------------------- */
2365 { /* Begin switch cmd */
2368 if (copy_to_user(argp
, tty
->termios
, sizeof(struct termios
)))
2372 return get_termio(tty
, argp
);
2373 case TCSBRK
: /* SVID version: non-zero arg --> no break */
2374 retval
= tty_check_change(tty
);
2377 /* Setup an event to indicate when the transmit buffer empties */
2378 spin_lock_irqsave(&epca_lock
, flags
);
2379 setup_empty_event(tty
,ch
);
2380 spin_unlock_irqrestore(&epca_lock
, flags
);
2381 tty_wait_until_sent(tty
, 0);
2383 digi_send_break(ch
, HZ
/4); /* 1/4 second */
2385 case TCSBRKP
: /* support for POSIX tcsendbreak() */
2386 retval
= tty_check_change(tty
);
2390 /* Setup an event to indicate when the transmit buffer empties */
2391 spin_lock_irqsave(&epca_lock
, flags
);
2392 setup_empty_event(tty
,ch
);
2393 spin_unlock_irqrestore(&epca_lock
, flags
);
2394 tty_wait_until_sent(tty
, 0);
2395 digi_send_break(ch
, arg
? arg
*(HZ
/10) : HZ
/4);
2398 if (put_user(C_CLOCAL(tty
)?1:0, (unsigned long __user
*)arg
))
2405 if (get_user(value
, (unsigned __user
*)argp
))
2407 tty
->termios
->c_cflag
=
2408 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
2409 (value
? CLOCAL
: 0));
2413 mflag
= pc_tiocmget(tty
, file
);
2414 if (put_user(mflag
, (unsigned long __user
*)argp
))
2418 if (get_user(mstat
, (unsigned __user
*)argp
))
2420 return pc_tiocmset(tty
, file
, mstat
, ~mstat
);
2422 spin_lock_irqsave(&epca_lock
, flags
);
2423 ch
->omodem
|= ch
->m_dtr
;
2425 fepcmd(ch
, SETMODEM
, ch
->m_dtr
, 0, 10, 1);
2427 spin_unlock_irqrestore(&epca_lock
, flags
);
2431 spin_lock_irqsave(&epca_lock
, flags
);
2432 ch
->omodem
&= ~ch
->m_dtr
;
2434 fepcmd(ch
, SETMODEM
, 0, ch
->m_dtr
, 10, 1);
2436 spin_unlock_irqrestore(&epca_lock
, flags
);
2439 if (copy_to_user(argp
, &ch
->digiext
, sizeof(digi_t
)))
2444 if (cmd
== DIGI_SETAW
) {
2445 /* Setup an event to indicate when the transmit buffer empties */
2446 spin_lock_irqsave(&epca_lock
, flags
);
2447 setup_empty_event(tty
,ch
);
2448 spin_unlock_irqrestore(&epca_lock
, flags
);
2449 tty_wait_until_sent(tty
, 0);
2451 /* ldisc lock already held in ioctl */
2452 if (tty
->ldisc
.flush_buffer
)
2453 tty
->ldisc
.flush_buffer(tty
);
2457 if (copy_from_user(&ch
->digiext
, argp
, sizeof(digi_t
)))
2460 if (ch
->digiext
.digi_flags
& DIGI_ALTPIN
) {
2461 ch
->dcd
= ch
->m_dsr
;
2462 ch
->dsr
= ch
->m_dcd
;
2464 ch
->dcd
= ch
->m_dcd
;
2465 ch
->dsr
= ch
->m_dsr
;
2468 spin_lock_irqsave(&epca_lock
, flags
);
2471 /* -----------------------------------------------------------------
2472 The below routine generally sets up parity, baud, flow control
2473 issues, etc.... It effect both control flags and input flags.
2474 ------------------------------------------------------------------- */
2478 spin_unlock_irqrestore(&epca_lock
, flags
);
2483 spin_lock_irqsave(&epca_lock
, flags
);
2485 if (cmd
== DIGI_GETFLOW
) {
2486 dflow
.startc
= readb(&bc
->startc
);
2487 dflow
.stopc
= readb(&bc
->stopc
);
2489 dflow
.startc
= readb(&bc
->startca
);
2490 dflow
.stopc
= readb(&bc
->stopca
);
2493 spin_unlock_irqrestore(&epca_lock
, flags
);
2495 if (copy_to_user(argp
, &dflow
, sizeof(dflow
)))
2501 if (cmd
== DIGI_SETFLOW
) {
2502 startc
= ch
->startc
;
2505 startc
= ch
->startca
;
2509 if (copy_from_user(&dflow
, argp
, sizeof(dflow
)))
2512 if (dflow
.startc
!= startc
|| dflow
.stopc
!= stopc
) { /* Begin if setflow toggled */
2513 spin_lock_irqsave(&epca_lock
, flags
);
2516 if (cmd
== DIGI_SETFLOW
) {
2517 ch
->fepstartc
= ch
->startc
= dflow
.startc
;
2518 ch
->fepstopc
= ch
->stopc
= dflow
.stopc
;
2519 fepcmd(ch
, SONOFFC
, ch
->fepstartc
, ch
->fepstopc
, 0, 1);
2521 ch
->fepstartca
= ch
->startca
= dflow
.startc
;
2522 ch
->fepstopca
= ch
->stopca
= dflow
.stopc
;
2523 fepcmd(ch
, SAUXONOFFC
, ch
->fepstartca
, ch
->fepstopca
, 0, 1);
2526 if (ch
->statusflags
& TXSTOPPED
)
2530 spin_unlock_irqrestore(&epca_lock
, flags
);
2531 } /* End if setflow toggled */
2534 return -ENOIOCTLCMD
;
2535 } /* End switch cmd */
2537 } /* End pc_ioctl */
2539 /* --------------------- Begin pc_set_termios ----------------------- */
2541 static void pc_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
2542 { /* Begin pc_set_termios */
2545 unsigned long flags
;
2546 /* ---------------------------------------------------------
2547 verifyChannel returns the channel from the tty struct
2548 if it is valid. This serves as a sanity check.
2549 ------------------------------------------------------------- */
2550 if ((ch
= verifyChannel(tty
)) != NULL
) { /* Begin if channel valid */
2551 spin_lock_irqsave(&epca_lock
, flags
);
2555 spin_unlock_irqrestore(&epca_lock
, flags
);
2557 if ((old_termios
->c_cflag
& CRTSCTS
) &&
2558 ((tty
->termios
->c_cflag
& CRTSCTS
) == 0))
2559 tty
->hw_stopped
= 0;
2561 if (!(old_termios
->c_cflag
& CLOCAL
) &&
2562 (tty
->termios
->c_cflag
& CLOCAL
))
2563 wake_up_interruptible(&ch
->open_wait
);
2565 } /* End if channel valid */
2567 } /* End pc_set_termios */
2569 /* --------------------- Begin do_softint ----------------------- */
2571 static void do_softint(void *private_
)
2572 { /* Begin do_softint */
2573 struct channel
*ch
= (struct channel
*) private_
;
2574 /* Called in response to a modem change event */
2575 if (ch
&& ch
->magic
== EPCA_MAGIC
) { /* Begin EPCA_MAGIC */
2576 struct tty_struct
*tty
= ch
->tty
;
2578 if (tty
&& tty
->driver_data
) {
2579 if (test_and_clear_bit(EPCA_EVENT_HANGUP
, &ch
->event
)) { /* Begin if clear_bit */
2580 tty_hangup(tty
); /* FIXME: module removal race here - AKPM */
2581 wake_up_interruptible(&ch
->open_wait
);
2582 ch
->asyncflags
&= ~ASYNC_NORMAL_ACTIVE
;
2583 } /* End if clear_bit */
2585 } /* End EPCA_MAGIC */
2586 } /* End do_softint */
2588 /* ------------------------------------------------------------
2589 pc_stop and pc_start provide software flow control to the
2590 routine and the pc_ioctl routine.
2591 ---------------------------------------------------------------- */
2593 /* --------------------- Begin pc_stop ----------------------- */
2595 static void pc_stop(struct tty_struct
*tty
)
2596 { /* Begin pc_stop */
2599 unsigned long flags
;
2600 /* ---------------------------------------------------------
2601 verifyChannel returns the channel from the tty struct
2602 if it is valid. This serves as a sanity check.
2603 ------------------------------------------------------------- */
2604 if ((ch
= verifyChannel(tty
)) != NULL
) { /* Begin if valid channel */
2605 spin_lock_irqsave(&epca_lock
, flags
);
2606 if ((ch
->statusflags
& TXSTOPPED
) == 0) { /* Begin if transmit stop requested */
2608 /* STOP transmitting now !! */
2609 fepcmd(ch
, PAUSETX
, 0, 0, 0, 0);
2610 ch
->statusflags
|= TXSTOPPED
;
2612 } /* End if transmit stop requested */
2613 spin_unlock_irqrestore(&epca_lock
, flags
);
2614 } /* End if valid channel */
2617 /* --------------------- Begin pc_start ----------------------- */
2619 static void pc_start(struct tty_struct
*tty
)
2620 { /* Begin pc_start */
2622 /* ---------------------------------------------------------
2623 verifyChannel returns the channel from the tty struct
2624 if it is valid. This serves as a sanity check.
2625 ------------------------------------------------------------- */
2626 if ((ch
= verifyChannel(tty
)) != NULL
) { /* Begin if channel valid */
2627 unsigned long flags
;
2628 spin_lock_irqsave(&epca_lock
, flags
);
2629 /* Just in case output was resumed because of a change in Digi-flow */
2630 if (ch
->statusflags
& TXSTOPPED
) { /* Begin transmit resume requested */
2631 struct board_chan __iomem
*bc
;
2634 if (ch
->statusflags
& LOWWAIT
)
2635 writeb(1, &bc
->ilow
);
2636 /* Okay, you can start transmitting again... */
2637 fepcmd(ch
, RESUMETX
, 0, 0, 0, 0);
2638 ch
->statusflags
&= ~TXSTOPPED
;
2640 } /* End transmit resume requested */
2641 spin_unlock_irqrestore(&epca_lock
, flags
);
2642 } /* End if channel valid */
2643 } /* End pc_start */
2645 /* ------------------------------------------------------------------
2646 The below routines pc_throttle and pc_unthrottle are used
2647 to slow (And resume) the receipt of data into the kernels
2648 receive buffers. The exact occurrence of this depends on the
2649 size of the kernels receive buffer and what the 'watermarks'
2650 are set to for that buffer. See the n_ttys.c file for more
2652 ______________________________________________________________________ */
2653 /* --------------------- Begin throttle ----------------------- */
2655 static void pc_throttle(struct tty_struct
* tty
)
2656 { /* Begin pc_throttle */
2658 unsigned long flags
;
2659 /* ---------------------------------------------------------
2660 verifyChannel returns the channel from the tty struct
2661 if it is valid. This serves as a sanity check.
2662 ------------------------------------------------------------- */
2663 if ((ch
= verifyChannel(tty
)) != NULL
) { /* Begin if channel valid */
2664 spin_lock_irqsave(&epca_lock
, flags
);
2665 if ((ch
->statusflags
& RXSTOPPED
) == 0) {
2667 fepcmd(ch
, PAUSERX
, 0, 0, 0, 0);
2668 ch
->statusflags
|= RXSTOPPED
;
2671 spin_unlock_irqrestore(&epca_lock
, flags
);
2672 } /* End if channel valid */
2673 } /* End pc_throttle */
2675 /* --------------------- Begin unthrottle ----------------------- */
2677 static void pc_unthrottle(struct tty_struct
*tty
)
2678 { /* Begin pc_unthrottle */
2680 unsigned long flags
;
2681 /* ---------------------------------------------------------
2682 verifyChannel returns the channel from the tty struct
2683 if it is valid. This serves as a sanity check.
2684 ------------------------------------------------------------- */
2685 if ((ch
= verifyChannel(tty
)) != NULL
) { /* Begin if channel valid */
2686 /* Just in case output was resumed because of a change in Digi-flow */
2687 spin_lock_irqsave(&epca_lock
, flags
);
2688 if (ch
->statusflags
& RXSTOPPED
) {
2690 fepcmd(ch
, RESUMERX
, 0, 0, 0, 0);
2691 ch
->statusflags
&= ~RXSTOPPED
;
2694 spin_unlock_irqrestore(&epca_lock
, flags
);
2695 } /* End if channel valid */
2696 } /* End pc_unthrottle */
2698 /* --------------------- Begin digi_send_break ----------------------- */
2700 void digi_send_break(struct channel
*ch
, int msec
)
2701 { /* Begin digi_send_break */
2702 unsigned long flags
;
2704 spin_lock_irqsave(&epca_lock
, flags
);
2706 /* --------------------------------------------------------------------
2707 Maybe I should send an infinite break here, schedule() for
2708 msec amount of time, and then stop the break. This way,
2709 the user can't screw up the FEP by causing digi_send_break()
2710 to be called (i.e. via an ioctl()) more than once in msec amount
2711 of time. Try this for now...
2712 ------------------------------------------------------------------------ */
2713 fepcmd(ch
, SENDBREAK
, msec
, 0, 10, 0);
2715 spin_unlock_irqrestore(&epca_lock
, flags
);
2716 } /* End digi_send_break */
2718 /* --------------------- Begin setup_empty_event ----------------------- */
2720 /* Caller MUST hold the lock */
2722 static void setup_empty_event(struct tty_struct
*tty
, struct channel
*ch
)
2723 { /* Begin setup_empty_event */
2725 struct board_chan __iomem
*bc
= ch
->brdchan
;
2728 ch
->statusflags
|= EMPTYWAIT
;
2729 /* ------------------------------------------------------------------
2730 When set the iempty flag request a event to be generated when the
2731 transmit buffer is empty (If there is no BREAK in progress).
2732 --------------------------------------------------------------------- */
2733 writeb(1, &bc
->iempty
);
2735 } /* End setup_empty_event */
2737 /* --------------------- Begin get_termio ----------------------- */
2739 static int get_termio(struct tty_struct
* tty
, struct termio __user
* termio
)
2740 { /* Begin get_termio */
2741 return kernel_termios_to_user_termio(termio
, tty
->termios
);
2742 } /* End get_termio */
2744 /* ---------------------- Begin epca_setup -------------------------- */
2745 void epca_setup(char *str
, int *ints
)
2746 { /* Begin epca_setup */
2747 struct board_info board
;
2748 int index
, loop
, last
;
2752 /* ----------------------------------------------------------------------
2753 If this routine looks a little strange it is because it is only called
2754 if a LILO append command is given to boot the kernel with parameters.
2755 In this way, we can provide the user a method of changing his board
2756 configuration without rebuilding the kernel.
2757 ----------------------------------------------------------------------- */
2761 memset(&board
, 0, sizeof(board
));
2763 /* Assume the data is int first, later we can change it */
2764 /* I think that array position 0 of ints holds the number of args */
2765 for (last
= 0, index
= 1; index
<= ints
[0]; index
++)
2767 { /* Begin parse switch */
2769 board
.status
= ints
[index
];
2770 /* ---------------------------------------------------------
2771 We check for 2 (As opposed to 1; because 2 is a flag
2772 instructing the driver to ignore epcaconfig.) For this
2773 reason we check for 2.
2774 ------------------------------------------------------------ */
2775 if (board
.status
== 2) { /* Begin ignore epcaconfig as well as lilo cmd line */
2779 } /* End ignore epcaconfig as well as lilo cmd line */
2781 if (board
.status
> 2) {
2782 printk(KERN_ERR
"epca_setup: Invalid board status 0x%x\n", board
.status
);
2783 invalid_lilo_config
= 1;
2784 setup_error_code
|= INVALID_BOARD_STATUS
;
2790 board
.type
= ints
[index
];
2791 if (board
.type
>= PCIXEM
) {
2792 printk(KERN_ERR
"epca_setup: Invalid board type 0x%x\n", board
.type
);
2793 invalid_lilo_config
= 1;
2794 setup_error_code
|= INVALID_BOARD_TYPE
;
2800 board
.altpin
= ints
[index
];
2801 if (board
.altpin
> 1) {
2802 printk(KERN_ERR
"epca_setup: Invalid board altpin 0x%x\n", board
.altpin
);
2803 invalid_lilo_config
= 1;
2804 setup_error_code
|= INVALID_ALTPIN
;
2811 board
.numports
= ints
[index
];
2812 if (board
.numports
< 2 || board
.numports
> 256) {
2813 printk(KERN_ERR
"epca_setup: Invalid board numports 0x%x\n", board
.numports
);
2814 invalid_lilo_config
= 1;
2815 setup_error_code
|= INVALID_NUM_PORTS
;
2818 nbdevs
+= board
.numports
;
2823 board
.port
= ints
[index
];
2824 if (ints
[index
] <= 0) {
2825 printk(KERN_ERR
"epca_setup: Invalid io port 0x%x\n", (unsigned int)board
.port
);
2826 invalid_lilo_config
= 1;
2827 setup_error_code
|= INVALID_PORT_BASE
;
2834 board
.membase
= ints
[index
];
2835 if (ints
[index
] <= 0) {
2836 printk(KERN_ERR
"epca_setup: Invalid memory base 0x%x\n",(unsigned int)board
.membase
);
2837 invalid_lilo_config
= 1;
2838 setup_error_code
|= INVALID_MEM_BASE
;
2845 printk(KERN_ERR
"<Error> - epca_setup: Too many integer parms\n");
2848 } /* End parse switch */
2850 while (str
&& *str
) { /* Begin while there is a string arg */
2851 /* find the next comma or terminator */
2853 /* While string is not null, and a comma hasn't been found */
2854 while (*temp
&& (*temp
!= ','))
2860 /* Set index to the number of args + 1 */
2867 if (strncmp("Disable", str
, len
) == 0)
2869 else if (strncmp("Enable", str
, len
) == 0)
2872 printk(KERN_ERR
"epca_setup: Invalid status %s\n", str
);
2873 invalid_lilo_config
= 1;
2874 setup_error_code
|= INVALID_BOARD_STATUS
;
2881 for(loop
= 0; loop
< EPCA_NUM_TYPES
; loop
++)
2882 if (strcmp(board_desc
[loop
], str
) == 0)
2884 /* ---------------------------------------------------------------
2885 If the index incremented above refers to a legitamate board
2887 ------------------------------------------------------------------*/
2888 if (index
< EPCA_NUM_TYPES
)
2891 printk(KERN_ERR
"epca_setup: Invalid board type: %s\n", str
);
2892 invalid_lilo_config
= 1;
2893 setup_error_code
|= INVALID_BOARD_TYPE
;
2901 if (strncmp("Disable", str
, len
) == 0)
2903 else if (strncmp("Enable", str
, len
) == 0)
2906 printk(KERN_ERR
"epca_setup: Invalid altpin %s\n", str
);
2907 invalid_lilo_config
= 1;
2908 setup_error_code
|= INVALID_ALTPIN
;
2916 while (isdigit(*t2
))
2920 printk(KERN_ERR
"epca_setup: Invalid port count %s\n", str
);
2921 invalid_lilo_config
= 1;
2922 setup_error_code
|= INVALID_NUM_PORTS
;
2926 /* ------------------------------------------------------------
2927 There is not a man page for simple_strtoul but the code can be
2928 found in vsprintf.c. The first argument is the string to
2929 translate (To an unsigned long obviously), the second argument
2930 can be the address of any character variable or a NULL. If a
2931 variable is given, the end pointer of the string will be stored
2932 in that variable; if a NULL is given the end pointer will
2933 not be returned. The last argument is the base to use. If
2934 a 0 is indicated, the routine will attempt to determine the
2935 proper base by looking at the values prefix (A '0' for octal,
2936 a 'x' for hex, etc ... If a value is given it will use that
2938 ---------------------------------------------------------------- */
2939 board
.numports
= simple_strtoul(str
, NULL
, 0);
2940 nbdevs
+= board
.numports
;
2946 while (isxdigit(*t2
))
2950 printk(KERN_ERR
"epca_setup: Invalid i/o address %s\n", str
);
2951 invalid_lilo_config
= 1;
2952 setup_error_code
|= INVALID_PORT_BASE
;
2956 board
.port
= simple_strtoul(str
, NULL
, 16);
2962 while (isxdigit(*t2
))
2966 printk(KERN_ERR
"epca_setup: Invalid memory base %s\n",str
);
2967 invalid_lilo_config
= 1;
2968 setup_error_code
|= INVALID_MEM_BASE
;
2971 board
.membase
= simple_strtoul(str
, NULL
, 16);
2975 printk(KERN_ERR
"epca: Too many string parms\n");
2979 } /* End while there is a string arg */
2982 printk(KERN_ERR
"epca: Insufficient parms specified\n");
2986 /* I should REALLY validate the stuff here */
2987 /* Copies our local copy of board into boards */
2988 memcpy((void *)&boards
[num_cards
],(void *)&board
, sizeof(board
));
2989 /* Does this get called once per lilo arg are what ? */
2990 printk(KERN_INFO
"PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2991 num_cards
, board_desc
[board
.type
],
2992 board
.numports
, (int)board
.port
, (unsigned int) board
.membase
);
2994 } /* End epca_setup */
2997 /* ------------------------ Begin init_PCI --------------------------- */
2999 enum epic_board_types
{
3007 /* indexed directly by epic_board_types enum */
3009 unsigned char board_type
;
3010 unsigned bar_idx
; /* PCI base address region */
3011 } epca_info_tbl
[] = {
3018 static int __devinit
epca_init_one (struct pci_dev
*pdev
,
3019 const struct pci_device_id
*ent
)
3021 static int board_num
= -1;
3022 int board_idx
, info_idx
= ent
->driver_data
;
3025 if (pci_enable_device(pdev
))
3029 board_idx
= board_num
+ num_cards
;
3030 if (board_idx
>= MAXBOARDS
)
3033 addr
= pci_resource_start (pdev
, epca_info_tbl
[info_idx
].bar_idx
);
3035 printk (KERN_ERR PFX
"PCI region #%d not available (size 0)\n",
3036 epca_info_tbl
[info_idx
].bar_idx
);
3040 boards
[board_idx
].status
= ENABLED
;
3041 boards
[board_idx
].type
= epca_info_tbl
[info_idx
].board_type
;
3042 boards
[board_idx
].numports
= 0x0;
3043 boards
[board_idx
].port
= addr
+ PCI_IO_OFFSET
;
3044 boards
[board_idx
].membase
= addr
;
3046 if (!request_mem_region (addr
+ PCI_IO_OFFSET
, 0x200000, "epca")) {
3047 printk (KERN_ERR PFX
"resource 0x%x @ 0x%lx unavailable\n",
3048 0x200000, addr
+ PCI_IO_OFFSET
);
3052 boards
[board_idx
].re_map_port
= ioremap(addr
+ PCI_IO_OFFSET
, 0x200000);
3053 if (!boards
[board_idx
].re_map_port
) {
3054 printk (KERN_ERR PFX
"cannot map 0x%x @ 0x%lx\n",
3055 0x200000, addr
+ PCI_IO_OFFSET
);
3056 goto err_out_free_pciio
;
3059 if (!request_mem_region (addr
, 0x200000, "epca")) {
3060 printk (KERN_ERR PFX
"resource 0x%x @ 0x%lx unavailable\n",
3062 goto err_out_free_iounmap
;
3065 boards
[board_idx
].re_map_membase
= ioremap(addr
, 0x200000);
3066 if (!boards
[board_idx
].re_map_membase
) {
3067 printk (KERN_ERR PFX
"cannot map 0x%x @ 0x%lx\n",
3068 0x200000, addr
+ PCI_IO_OFFSET
);
3069 goto err_out_free_memregion
;
3072 /* --------------------------------------------------------------
3073 I don't know what the below does, but the hardware guys say
3074 its required on everything except PLX (In this case XRJ).
3075 ---------------------------------------------------------------- */
3076 if (info_idx
!= brd_xrj
) {
3077 pci_write_config_byte(pdev
, 0x40, 0);
3078 pci_write_config_byte(pdev
, 0x46, 0);
3083 err_out_free_memregion
:
3084 release_mem_region (addr
, 0x200000);
3085 err_out_free_iounmap
:
3086 iounmap (boards
[board_idx
].re_map_port
);
3088 release_mem_region (addr
+ PCI_IO_OFFSET
, 0x200000);
3094 static struct pci_device_id epca_pci_tbl
[] = {
3095 { PCI_VENDOR_DIGI
, PCI_DEVICE_XR
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, brd_xr
},
3096 { PCI_VENDOR_DIGI
, PCI_DEVICE_XEM
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, brd_xem
},
3097 { PCI_VENDOR_DIGI
, PCI_DEVICE_CX
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, brd_cx
},
3098 { PCI_VENDOR_DIGI
, PCI_DEVICE_XRJ
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, brd_xrj
},
3102 MODULE_DEVICE_TABLE(pci
, epca_pci_tbl
);
3104 int __init
init_PCI (void)
3105 { /* Begin init_PCI */
3106 memset (&epca_driver
, 0, sizeof (epca_driver
));
3107 epca_driver
.name
= "epca";
3108 epca_driver
.id_table
= epca_pci_tbl
;
3109 epca_driver
.probe
= epca_init_one
;
3111 return pci_register_driver(&epca_driver
);
3114 MODULE_LICENSE("GPL");