2 Copyright (C) 1996 Digi International.
4 For technical support please email digiLinux@dgii.com or
5 call Digi tech support at (612) 912-3456
7 ** This driver is no longer supported by Digi **
9 Much of this design and code came from epca.c which was
10 copyright (C) 1994, 1995 Troy De Jongh, and subsquently
11 modified by David Nugent, Christoph Lameter, Mike McLagan.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /* See README.epca for change history --DAT*/
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/types.h>
32 #include <linux/init.h>
33 #include <linux/sched.h>
34 #include <linux/serial.h>
35 #include <linux/delay.h>
36 #include <linux/ctype.h>
37 #include <linux/tty.h>
38 #include <linux/tty_flip.h>
39 #include <linux/slab.h>
40 #include <linux/smp_lock.h>
41 #include <linux/ioport.h>
42 #include <linux/interrupt.h>
43 #include <linux/uaccess.h>
45 #include <linux/spinlock.h>
46 #include <linux/pci.h>
53 #include "epcaconfig.h"
55 #define VERSION "1.3.0.1-LK2.6"
57 /* This major needs to be submitted to Linux to join the majors list */
58 #define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
62 #define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
66 static int nbdevs
, num_cards
, liloconfig
;
67 static int digi_poller_inhibited
= 1 ;
69 static int setup_error_code
;
70 static int invalid_lilo_config
;
73 * The ISA boards do window flipping into the same spaces so its only sane with
74 * a single lock. It's still pretty efficient. This lock guards the hardware
75 * and the tty_port lock guards the kernel side stuff like use counts. Take
76 * this lock inside the port lock if you must take both.
78 static DEFINE_SPINLOCK(epca_lock
);
80 /* MAXBOARDS is typically 12, but ISA and EISA cards are restricted
82 static struct board_info boards
[MAXBOARDS
];
84 static struct tty_driver
*pc_driver
;
85 static struct tty_driver
*pc_info
;
87 /* ------------------ Begin Digi specific structures -------------------- */
90 * digi_channels represents an array of structures that keep track of each
91 * channel of the Digi product. Information such as transmit and receive
92 * pointers, termio data, and signal definitions (DTR, CTS, etc ...) are stored
93 * here. This structure is NOT used to overlay the cards physical channel
96 static struct channel digi_channels
[MAX_ALLOC
];
99 * card_ptr is an array used to hold the address of the first channel structure
100 * of each card. This array will hold the addresses of various channels located
103 static struct channel
*card_ptr
[MAXCARDS
];
105 static struct timer_list epca_timer
;
108 * Begin generic memory functions. These functions will be alias (point at)
109 * more specific functions dependent on the board being configured.
111 static void memwinon(struct board_info
*b
, unsigned int win
);
112 static void memwinoff(struct board_info
*b
, unsigned int win
);
113 static void globalwinon(struct channel
*ch
);
114 static void rxwinon(struct channel
*ch
);
115 static void txwinon(struct channel
*ch
);
116 static void memoff(struct channel
*ch
);
117 static void assertgwinon(struct channel
*ch
);
118 static void assertmemoff(struct channel
*ch
);
120 /* ---- Begin more 'specific' memory functions for cx_like products --- */
122 static void pcxem_memwinon(struct board_info
*b
, unsigned int win
);
123 static void pcxem_memwinoff(struct board_info
*b
, unsigned int win
);
124 static void pcxem_globalwinon(struct channel
*ch
);
125 static void pcxem_rxwinon(struct channel
*ch
);
126 static void pcxem_txwinon(struct channel
*ch
);
127 static void pcxem_memoff(struct channel
*ch
);
129 /* ------ Begin more 'specific' memory functions for the pcxe ------- */
131 static void pcxe_memwinon(struct board_info
*b
, unsigned int win
);
132 static void pcxe_memwinoff(struct board_info
*b
, unsigned int win
);
133 static void pcxe_globalwinon(struct channel
*ch
);
134 static void pcxe_rxwinon(struct channel
*ch
);
135 static void pcxe_txwinon(struct channel
*ch
);
136 static void pcxe_memoff(struct channel
*ch
);
138 /* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
139 /* Note : pc64xe and pcxi share the same windowing routines */
141 static void pcxi_memwinon(struct board_info
*b
, unsigned int win
);
142 static void pcxi_memwinoff(struct board_info
*b
, unsigned int win
);
143 static void pcxi_globalwinon(struct channel
*ch
);
144 static void pcxi_rxwinon(struct channel
*ch
);
145 static void pcxi_txwinon(struct channel
*ch
);
146 static void pcxi_memoff(struct channel
*ch
);
148 /* - Begin 'specific' do nothing memory functions needed for some cards - */
150 static void dummy_memwinon(struct board_info
*b
, unsigned int win
);
151 static void dummy_memwinoff(struct board_info
*b
, unsigned int win
);
152 static void dummy_globalwinon(struct channel
*ch
);
153 static void dummy_rxwinon(struct channel
*ch
);
154 static void dummy_txwinon(struct channel
*ch
);
155 static void dummy_memoff(struct channel
*ch
);
156 static void dummy_assertgwinon(struct channel
*ch
);
157 static void dummy_assertmemoff(struct channel
*ch
);
159 static struct channel
*verifyChannel(struct tty_struct
*);
160 static void pc_sched_event(struct channel
*, int);
161 static void epca_error(int, char *);
162 static void pc_close(struct tty_struct
*, struct file
*);
163 static void shutdown(struct channel
*, struct tty_struct
*tty
);
164 static void pc_hangup(struct tty_struct
*);
165 static int pc_write_room(struct tty_struct
*);
166 static int pc_chars_in_buffer(struct tty_struct
*);
167 static void pc_flush_buffer(struct tty_struct
*);
168 static void pc_flush_chars(struct tty_struct
*);
169 static int pc_open(struct tty_struct
*, struct file
*);
170 static void post_fep_init(unsigned int crd
);
171 static void epcapoll(unsigned long);
172 static void doevent(int);
173 static void fepcmd(struct channel
*, int, int, int, int, int);
174 static unsigned termios2digi_h(struct channel
*ch
, unsigned);
175 static unsigned termios2digi_i(struct channel
*ch
, unsigned);
176 static unsigned termios2digi_c(struct channel
*ch
, unsigned);
177 static void epcaparam(struct tty_struct
*, struct channel
*);
178 static void receive_data(struct channel
*, struct tty_struct
*tty
);
179 static int pc_ioctl(struct tty_struct
*, struct file
*,
180 unsigned int, unsigned long);
181 static int info_ioctl(struct tty_struct
*, struct file
*,
182 unsigned int, unsigned long);
183 static void pc_set_termios(struct tty_struct
*, struct ktermios
*);
184 static void do_softint(struct work_struct
*work
);
185 static void pc_stop(struct tty_struct
*);
186 static void pc_start(struct tty_struct
*);
187 static void pc_throttle(struct tty_struct
*tty
);
188 static void pc_unthrottle(struct tty_struct
*tty
);
189 static int pc_send_break(struct tty_struct
*tty
, int msec
);
190 static void setup_empty_event(struct tty_struct
*tty
, struct channel
*ch
);
192 static int pc_write(struct tty_struct
*, const unsigned char *, int);
193 static int pc_init(void);
194 static int init_PCI(void);
197 * Table of functions for each board to handle memory. Mantaining parallelism
198 * is a *very* good idea here. The idea is for the runtime code to blindly call
199 * these functions, not knowing/caring about the underlying hardware. This
200 * stuff should contain no conditionals; if more functionality is needed a
201 * different entry should be established. These calls are the interface calls
202 * and are the only functions that should be accessed. Anyone caught making
203 * direct calls deserves what they get.
205 static void memwinon(struct board_info
*b
, unsigned int win
)
210 static void memwinoff(struct board_info
*b
, unsigned int win
)
212 b
->memwinoff(b
, win
);
215 static void globalwinon(struct channel
*ch
)
217 ch
->board
->globalwinon(ch
);
220 static void rxwinon(struct channel
*ch
)
222 ch
->board
->rxwinon(ch
);
225 static void txwinon(struct channel
*ch
)
227 ch
->board
->txwinon(ch
);
230 static void memoff(struct channel
*ch
)
232 ch
->board
->memoff(ch
);
234 static void assertgwinon(struct channel
*ch
)
236 ch
->board
->assertgwinon(ch
);
239 static void assertmemoff(struct channel
*ch
)
241 ch
->board
->assertmemoff(ch
);
244 /* PCXEM windowing is the same as that used in the PCXR and CX series cards. */
245 static void pcxem_memwinon(struct board_info
*b
, unsigned int win
)
247 outb_p(FEPWIN
| win
, b
->port
+ 1);
250 static void pcxem_memwinoff(struct board_info
*b
, unsigned int win
)
252 outb_p(0, b
->port
+ 1);
255 static void pcxem_globalwinon(struct channel
*ch
)
257 outb_p(FEPWIN
, (int)ch
->board
->port
+ 1);
260 static void pcxem_rxwinon(struct channel
*ch
)
262 outb_p(ch
->rxwin
, (int)ch
->board
->port
+ 1);
265 static void pcxem_txwinon(struct channel
*ch
)
267 outb_p(ch
->txwin
, (int)ch
->board
->port
+ 1);
270 static void pcxem_memoff(struct channel
*ch
)
272 outb_p(0, (int)ch
->board
->port
+ 1);
275 /* ----------------- Begin pcxe memory window stuff ------------------ */
276 static void pcxe_memwinon(struct board_info
*b
, unsigned int win
)
278 outb_p(FEPWIN
| win
, b
->port
+ 1);
281 static void pcxe_memwinoff(struct board_info
*b
, unsigned int win
)
283 outb_p(inb(b
->port
) & ~FEPMEM
, b
->port
+ 1);
284 outb_p(0, b
->port
+ 1);
287 static void pcxe_globalwinon(struct channel
*ch
)
289 outb_p(FEPWIN
, (int)ch
->board
->port
+ 1);
292 static void pcxe_rxwinon(struct channel
*ch
)
294 outb_p(ch
->rxwin
, (int)ch
->board
->port
+ 1);
297 static void pcxe_txwinon(struct channel
*ch
)
299 outb_p(ch
->txwin
, (int)ch
->board
->port
+ 1);
302 static void pcxe_memoff(struct channel
*ch
)
304 outb_p(0, (int)ch
->board
->port
);
305 outb_p(0, (int)ch
->board
->port
+ 1);
308 /* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
309 static void pcxi_memwinon(struct board_info
*b
, unsigned int win
)
311 outb_p(inb(b
->port
) | FEPMEM
, b
->port
);
314 static void pcxi_memwinoff(struct board_info
*b
, unsigned int win
)
316 outb_p(inb(b
->port
) & ~FEPMEM
, b
->port
);
319 static void pcxi_globalwinon(struct channel
*ch
)
321 outb_p(FEPMEM
, ch
->board
->port
);
324 static void pcxi_rxwinon(struct channel
*ch
)
326 outb_p(FEPMEM
, ch
->board
->port
);
329 static void pcxi_txwinon(struct channel
*ch
)
331 outb_p(FEPMEM
, ch
->board
->port
);
334 static void pcxi_memoff(struct channel
*ch
)
336 outb_p(0, ch
->board
->port
);
339 static void pcxi_assertgwinon(struct channel
*ch
)
341 epcaassert(inb(ch
->board
->port
) & FEPMEM
, "Global memory off");
344 static void pcxi_assertmemoff(struct channel
*ch
)
346 epcaassert(!(inb(ch
->board
->port
) & FEPMEM
), "Memory on");
350 * Not all of the cards need specific memory windowing routines. Some cards
351 * (Such as PCI) needs no windowing routines at all. We provide these do
352 * nothing routines so that the same code base can be used. The driver will
353 * ALWAYS call a windowing routine if it thinks it needs to; regardless of the
354 * card. However, dependent on the card the routine may or may not do anything.
356 static void dummy_memwinon(struct board_info
*b
, unsigned int win
)
360 static void dummy_memwinoff(struct board_info
*b
, unsigned int win
)
364 static void dummy_globalwinon(struct channel
*ch
)
368 static void dummy_rxwinon(struct channel
*ch
)
372 static void dummy_txwinon(struct channel
*ch
)
376 static void dummy_memoff(struct channel
*ch
)
380 static void dummy_assertgwinon(struct channel
*ch
)
384 static void dummy_assertmemoff(struct channel
*ch
)
388 static struct channel
*verifyChannel(struct tty_struct
*tty
)
391 * This routine basically provides a sanity check. It insures that the
392 * channel returned is within the proper range of addresses as well as
393 * properly initialized. If some bogus info gets passed in
394 * through tty->driver_data this should catch it.
397 struct channel
*ch
= tty
->driver_data
;
398 if (ch
>= &digi_channels
[0] && ch
< &digi_channels
[nbdevs
]) {
399 if (ch
->magic
== EPCA_MAGIC
)
406 static void pc_sched_event(struct channel
*ch
, int event
)
409 * We call this to schedule interrupt processing on some event. The
410 * kernel sees our request and calls the related routine in OUR driver.
412 ch
->event
|= 1 << event
;
413 schedule_work(&ch
->tqueue
);
416 static void epca_error(int line
, char *msg
)
418 printk(KERN_ERR
"epca_error (Digi): line = %d %s\n", line
, msg
);
421 static void pc_close(struct tty_struct
*tty
, struct file
*filp
)
424 struct tty_port
*port
;
426 * verifyChannel returns the channel from the tty struct if it is
427 * valid. This serves as a sanity check.
429 ch
= verifyChannel(tty
);
434 if (tty_port_close_start(port
, tty
, filp
) == 0)
437 pc_flush_buffer(tty
);
440 tty_port_close_end(port
, tty
);
441 ch
->event
= 0; /* FIXME: review ch->event locking */
442 tty_port_tty_set(port
, NULL
);
445 static void shutdown(struct channel
*ch
, struct tty_struct
*tty
)
448 struct board_chan __iomem
*bc
;
449 struct tty_port
*port
= &ch
->port
;
451 if (!(port
->flags
& ASYNC_INITIALIZED
))
454 spin_lock_irqsave(&epca_lock
, flags
);
460 * In order for an event to be generated on the receipt of data the
461 * idata flag must be set. Since we are shutting down, this is not
462 * necessary clear this flag.
465 writeb(0, &bc
->idata
);
467 /* If we're a modem control device and HUPCL is on, drop RTS & DTR. */
468 if (tty
->termios
->c_cflag
& HUPCL
) {
469 ch
->omodem
&= ~(ch
->m_rts
| ch
->m_dtr
);
470 fepcmd(ch
, SETMODEM
, 0, ch
->m_dtr
| ch
->m_rts
, 10, 1);
475 * The channel has officialy been closed. The next time it is opened it
476 * will have to reinitialized. Set a flag to indicate this.
478 /* Prevent future Digi programmed interrupts from coming active */
479 port
->flags
&= ~ASYNC_INITIALIZED
;
480 spin_unlock_irqrestore(&epca_lock
, flags
);
483 static void pc_hangup(struct tty_struct
*tty
)
488 * verifyChannel returns the channel from the tty struct if it is
489 * valid. This serves as a sanity check.
491 ch
= verifyChannel(tty
);
493 pc_flush_buffer(tty
);
494 tty_ldisc_flush(tty
);
497 ch
->event
= 0; /* FIXME: review locking of ch->event */
498 tty_port_hangup(&ch
->port
);
502 static int pc_write(struct tty_struct
*tty
,
503 const unsigned char *buf
, int bytesAvailable
)
505 unsigned int head
, tail
;
512 struct board_chan __iomem
*bc
;
515 * pc_write is primarily called directly by the kernel routine
516 * tty_write (Though it can also be called by put_char) found in
517 * tty_io.c. pc_write is passed a line discipline buffer where the data
518 * to be written out is stored. The line discipline implementation
519 * itself is done at the kernel level and is not brought into the
524 * verifyChannel returns the channel from the tty struct if it is
525 * valid. This serves as a sanity check.
527 ch
= verifyChannel(tty
);
531 /* Make a pointer to the channel data structure found on the board. */
533 size
= ch
->txbufsize
;
536 spin_lock_irqsave(&epca_lock
, flags
);
539 head
= readw(&bc
->tin
) & (size
- 1);
540 tail
= readw(&bc
->tout
);
542 if (tail
!= readw(&bc
->tout
))
543 tail
= readw(&bc
->tout
);
547 /* head has not wrapped */
549 * remain (much like dataLen above) represents the total amount
550 * of space available on the card for data. Here dataLen
551 * represents the space existing between the head pointer and
552 * the end of buffer. This is important because a memcpy cannot
553 * be told to automatically wrap around when it hits the buffer
556 dataLen
= size
- head
;
557 remain
= size
- (head
- tail
) - 1;
559 /* head has wrapped around */
560 remain
= tail
- head
- 1;
564 * Check the space on the card. If we have more data than space; reduce
565 * the amount of data to fit the space.
567 bytesAvailable
= min(remain
, bytesAvailable
);
569 while (bytesAvailable
> 0) {
570 /* there is data to copy onto card */
573 * If head is not wrapped, the below will make sure the first
574 * data copy fills to the end of card buffer.
576 dataLen
= min(bytesAvailable
, dataLen
);
577 memcpy_toio(ch
->txptr
+ head
, buf
, dataLen
);
580 amountCopied
+= dataLen
;
581 bytesAvailable
-= dataLen
;
588 ch
->statusflags
|= TXBUSY
;
590 writew(head
, &bc
->tin
);
592 if ((ch
->statusflags
& LOWWAIT
) == 0) {
593 ch
->statusflags
|= LOWWAIT
;
594 writeb(1, &bc
->ilow
);
597 spin_unlock_irqrestore(&epca_lock
, flags
);
601 static int pc_write_room(struct tty_struct
*tty
)
606 unsigned int head
, tail
;
607 struct board_chan __iomem
*bc
;
609 * verifyChannel returns the channel from the tty struct if it is
610 * valid. This serves as a sanity check.
612 ch
= verifyChannel(tty
);
614 spin_lock_irqsave(&epca_lock
, flags
);
618 head
= readw(&bc
->tin
) & (ch
->txbufsize
- 1);
619 tail
= readw(&bc
->tout
);
621 if (tail
!= readw(&bc
->tout
))
622 tail
= readw(&bc
->tout
);
623 /* Wrap tail if necessary */
624 tail
&= (ch
->txbufsize
- 1);
625 remain
= tail
- head
- 1;
627 remain
+= ch
->txbufsize
;
629 if (remain
&& (ch
->statusflags
& LOWWAIT
) == 0) {
630 ch
->statusflags
|= LOWWAIT
;
631 writeb(1, &bc
->ilow
);
634 spin_unlock_irqrestore(&epca_lock
, flags
);
636 /* Return how much room is left on card */
640 static int pc_chars_in_buffer(struct tty_struct
*tty
)
643 unsigned int ctail
, head
, tail
;
647 struct board_chan __iomem
*bc
;
649 * verifyChannel returns the channel from the tty struct if it is
650 * valid. This serves as a sanity check.
652 ch
= verifyChannel(tty
);
656 spin_lock_irqsave(&epca_lock
, flags
);
660 tail
= readw(&bc
->tout
);
661 head
= readw(&bc
->tin
);
662 ctail
= readw(&ch
->mailbox
->cout
);
664 if (tail
== head
&& readw(&ch
->mailbox
->cin
) == ctail
&&
665 readb(&bc
->tbusy
) == 0)
667 else { /* Begin if some space on the card has been used */
668 head
= readw(&bc
->tin
) & (ch
->txbufsize
- 1);
669 tail
&= (ch
->txbufsize
- 1);
671 * The logic here is basically opposite of the above
672 * pc_write_room here we are finding the amount of bytes in the
673 * buffer filled. Not the amount of bytes empty.
675 remain
= tail
- head
- 1;
677 remain
+= ch
->txbufsize
;
678 chars
= (int)(ch
->txbufsize
- remain
);
680 * Make it possible to wakeup anything waiting for output in
683 * If not already set. Setup an event to indicate when the
684 * transmit buffer empties.
686 if (!(ch
->statusflags
& EMPTYWAIT
))
687 setup_empty_event(tty
, ch
);
688 } /* End if some space on the card has been used */
690 spin_unlock_irqrestore(&epca_lock
, flags
);
691 /* Return number of characters residing on card. */
695 static void pc_flush_buffer(struct tty_struct
*tty
)
700 struct board_chan __iomem
*bc
;
702 * verifyChannel returns the channel from the tty struct if it is
703 * valid. This serves as a sanity check.
705 ch
= verifyChannel(tty
);
709 spin_lock_irqsave(&epca_lock
, flags
);
712 tail
= readw(&bc
->tout
);
713 /* Have FEP move tout pointer; effectively flushing transmit buffer */
714 fepcmd(ch
, STOUT
, (unsigned) tail
, 0, 0, 0);
716 spin_unlock_irqrestore(&epca_lock
, flags
);
720 static void pc_flush_chars(struct tty_struct
*tty
)
724 * verifyChannel returns the channel from the tty struct if it is
725 * valid. This serves as a sanity check.
727 ch
= verifyChannel(tty
);
730 spin_lock_irqsave(&epca_lock
, flags
);
732 * If not already set and the transmitter is busy setup an
733 * event to indicate when the transmit empties.
735 if ((ch
->statusflags
& TXBUSY
) &&
736 !(ch
->statusflags
& EMPTYWAIT
))
737 setup_empty_event(tty
, ch
);
738 spin_unlock_irqrestore(&epca_lock
, flags
);
742 static int epca_carrier_raised(struct tty_port
*port
)
744 struct channel
*ch
= container_of(port
, struct channel
, port
);
745 if (ch
->imodem
& ch
->dcd
)
750 static void epca_dtr_rts(struct tty_port
*port
, int onoff
)
754 static int pc_open(struct tty_struct
*tty
, struct file
*filp
)
757 struct tty_port
*port
;
759 int line
, retval
, boardnum
;
760 struct board_chan __iomem
*bc
;
764 if (line
< 0 || line
>= nbdevs
)
767 ch
= &digi_channels
[line
];
769 boardnum
= ch
->boardnum
;
771 /* Check status of board configured in system. */
774 * I check to see if the epca_setup routine detected a user error. It
775 * might be better to put this in pc_init, but for the moment it goes
778 if (invalid_lilo_config
) {
779 if (setup_error_code
& INVALID_BOARD_TYPE
)
780 printk(KERN_ERR
"epca: pc_open: Invalid board type specified in kernel options.\n");
781 if (setup_error_code
& INVALID_NUM_PORTS
)
782 printk(KERN_ERR
"epca: pc_open: Invalid number of ports specified in kernel options.\n");
783 if (setup_error_code
& INVALID_MEM_BASE
)
784 printk(KERN_ERR
"epca: pc_open: Invalid board memory address specified in kernel options.\n");
785 if (setup_error_code
& INVALID_PORT_BASE
)
786 printk(KERN_ERR
"epca; pc_open: Invalid board port address specified in kernel options.\n");
787 if (setup_error_code
& INVALID_BOARD_STATUS
)
788 printk(KERN_ERR
"epca: pc_open: Invalid board status specified in kernel options.\n");
789 if (setup_error_code
& INVALID_ALTPIN
)
790 printk(KERN_ERR
"epca: pc_open: Invalid board altpin specified in kernel options;\n");
791 tty
->driver_data
= NULL
; /* Mark this device as 'down' */
794 if (boardnum
>= num_cards
|| boards
[boardnum
].status
== DISABLED
) {
795 tty
->driver_data
= NULL
; /* Mark this device as 'down' */
801 tty
->driver_data
= NULL
;
805 spin_lock_irqsave(&port
->lock
, flags
);
807 * Every time a channel is opened, increment a counter. This is
808 * necessary because we do not wish to flush and shutdown the channel
809 * until the last app holding the channel open, closes it.
813 * Set a kernel structures pointer to our local channel structure. This
814 * way we can get to it when passed only a tty struct.
816 tty
->driver_data
= ch
;
819 * If this is the first time the channel has been opened, initialize
820 * the tty->termios struct otherwise let pc_close handle it.
822 spin_lock(&epca_lock
);
826 /* Save boards current modem status */
827 ch
->imodem
= readb(&bc
->mstat
);
830 * Set receive head and tail ptrs to each other. This indicates no data
833 head
= readw(&bc
->rin
);
834 writew(head
, &bc
->rout
);
836 /* Set the channels associated tty structure */
839 * The below routine generally sets up parity, baud, flow control
840 * issues, etc.... It effect both control flags and input flags.
844 spin_unlock(&epca_lock
);
845 port
->flags
|= ASYNC_INITIALIZED
;
846 spin_unlock_irqrestore(&port
->lock
, flags
);
848 retval
= tty_port_block_til_ready(port
, tty
, filp
);
852 * Set this again in case a hangup set it to zero while this open() was
853 * waiting for the line...
855 spin_lock_irqsave(&port
->lock
, flags
);
857 spin_lock(&epca_lock
);
859 /* Enable Digi Data events */
860 writeb(1, &bc
->idata
);
862 spin_unlock(&epca_lock
);
863 spin_unlock_irqrestore(&port
->lock
, flags
);
867 static int __init
epca_module_init(void)
871 module_init(epca_module_init
);
873 static struct pci_driver epca_driver
;
875 static void __exit
epca_module_exit(void)
878 struct board_info
*bd
;
881 del_timer_sync(&epca_timer
);
883 if (tty_unregister_driver(pc_driver
) ||
884 tty_unregister_driver(pc_info
)) {
885 printk(KERN_WARNING
"epca: cleanup_module failed to un-register tty driver\n");
888 put_tty_driver(pc_driver
);
889 put_tty_driver(pc_info
);
891 for (crd
= 0; crd
< num_cards
; crd
++) {
893 if (!bd
) { /* sanity check */
894 printk(KERN_ERR
"<Error> - Digi : cleanup_module failed\n");
898 for (count
= 0; count
< bd
->numports
; count
++, ch
++) {
899 struct tty_struct
*tty
= tty_port_tty_get(&ch
->port
);
906 pci_unregister_driver(&epca_driver
);
908 module_exit(epca_module_exit
);
910 static const struct tty_operations pc_ops
= {
914 .write_room
= pc_write_room
,
915 .flush_buffer
= pc_flush_buffer
,
916 .chars_in_buffer
= pc_chars_in_buffer
,
917 .flush_chars
= pc_flush_chars
,
919 .set_termios
= pc_set_termios
,
922 .throttle
= pc_throttle
,
923 .unthrottle
= pc_unthrottle
,
925 .break_ctl
= pc_send_break
928 static const struct tty_port_operations epca_port_ops
= {
929 .carrier_raised
= epca_carrier_raised
,
930 .dtr_rts
= epca_dtr_rts
,
933 static int info_open(struct tty_struct
*tty
, struct file
*filp
)
938 static const struct tty_operations info_ops
= {
943 static int __init
pc_init(void)
946 struct board_info
*bd
;
947 unsigned char board_id
= 0;
950 int pci_boards_found
, pci_count
;
954 pc_driver
= alloc_tty_driver(MAX_ALLOC
);
958 pc_info
= alloc_tty_driver(MAX_ALLOC
);
963 * If epca_setup has not been ran by LILO set num_cards to defaults;
964 * copy board structure defined by digiConfig into drivers board
965 * structure. Note : If LILO has ran epca_setup then epca_setup will
966 * handle defining num_cards as well as copying the data into the board
970 /* driver has been configured via. epcaconfig */
972 num_cards
= NUMCARDS
;
973 memcpy(&boards
, &static_boards
,
974 sizeof(struct board_info
) * NUMCARDS
);
978 * Note : If lilo was used to configure the driver and the ignore
979 * epcaconfig option was choosen (digiepca=2) then nbdevs and num_cards
980 * will equal 0 at this point. This is okay; PCI cards will still be
981 * picked up if detected.
985 * Set up interrupt, we will worry about memory allocation in
988 printk(KERN_INFO
"DIGI epca driver version %s loaded.\n", VERSION
);
991 * NOTE : This code assumes that the number of ports found in the
992 * boards array is correct. This could be wrong if the card in question
993 * is PCI (And therefore has no ports entry in the boards structure.)
994 * The rest of the information will be valid for PCI because the
995 * beginning of pc_init scans for PCI and determines i/o and base
996 * memory addresses. I am not sure if it is possible to read the number
997 * of ports supported by the card prior to it being booted (Since that
998 * is the state it is in when pc_init is run). Because it is not
999 * possible to query the number of supported ports until after the card
1000 * has booted; we are required to calculate the card_ptrs as the card
1001 * is initialized (Inside post_fep_init). The negative thing about this
1002 * approach is that digiDload's call to GET_INFO will have a bad port
1003 * value. (Since this is called prior to post_fep_init.)
1005 pci_boards_found
= 0;
1006 if (num_cards
< MAXBOARDS
)
1007 pci_boards_found
+= init_PCI();
1008 num_cards
+= pci_boards_found
;
1010 pc_driver
->owner
= THIS_MODULE
;
1011 pc_driver
->name
= "ttyD";
1012 pc_driver
->major
= DIGI_MAJOR
;
1013 pc_driver
->minor_start
= 0;
1014 pc_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1015 pc_driver
->subtype
= SERIAL_TYPE_NORMAL
;
1016 pc_driver
->init_termios
= tty_std_termios
;
1017 pc_driver
->init_termios
.c_iflag
= 0;
1018 pc_driver
->init_termios
.c_oflag
= 0;
1019 pc_driver
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| CLOCAL
| HUPCL
;
1020 pc_driver
->init_termios
.c_lflag
= 0;
1021 pc_driver
->init_termios
.c_ispeed
= 9600;
1022 pc_driver
->init_termios
.c_ospeed
= 9600;
1023 pc_driver
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_HARDWARE_BREAK
;
1024 tty_set_operations(pc_driver
, &pc_ops
);
1026 pc_info
->owner
= THIS_MODULE
;
1027 pc_info
->name
= "digi_ctl";
1028 pc_info
->major
= DIGIINFOMAJOR
;
1029 pc_info
->minor_start
= 0;
1030 pc_info
->type
= TTY_DRIVER_TYPE_SERIAL
;
1031 pc_info
->subtype
= SERIAL_TYPE_INFO
;
1032 pc_info
->init_termios
= tty_std_termios
;
1033 pc_info
->init_termios
.c_iflag
= 0;
1034 pc_info
->init_termios
.c_oflag
= 0;
1035 pc_info
->init_termios
.c_lflag
= 0;
1036 pc_info
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
;
1037 pc_info
->init_termios
.c_ispeed
= 9600;
1038 pc_info
->init_termios
.c_ospeed
= 9600;
1039 pc_info
->flags
= TTY_DRIVER_REAL_RAW
;
1040 tty_set_operations(pc_info
, &info_ops
);
1043 for (crd
= 0; crd
< num_cards
; crd
++) {
1045 * This is where the appropriate memory handlers for the
1046 * hardware is set. Everything at runtime blindly jumps through
1050 /* defined in epcaconfig.h */
1056 bd
->memwinon
= pcxem_memwinon
;
1057 bd
->memwinoff
= pcxem_memwinoff
;
1058 bd
->globalwinon
= pcxem_globalwinon
;
1059 bd
->txwinon
= pcxem_txwinon
;
1060 bd
->rxwinon
= pcxem_rxwinon
;
1061 bd
->memoff
= pcxem_memoff
;
1062 bd
->assertgwinon
= dummy_assertgwinon
;
1063 bd
->assertmemoff
= dummy_assertmemoff
;
1069 bd
->memwinon
= dummy_memwinon
;
1070 bd
->memwinoff
= dummy_memwinoff
;
1071 bd
->globalwinon
= dummy_globalwinon
;
1072 bd
->txwinon
= dummy_txwinon
;
1073 bd
->rxwinon
= dummy_rxwinon
;
1074 bd
->memoff
= dummy_memoff
;
1075 bd
->assertgwinon
= dummy_assertgwinon
;
1076 bd
->assertmemoff
= dummy_assertmemoff
;
1081 bd
->memwinon
= pcxe_memwinon
;
1082 bd
->memwinoff
= pcxe_memwinoff
;
1083 bd
->globalwinon
= pcxe_globalwinon
;
1084 bd
->txwinon
= pcxe_txwinon
;
1085 bd
->rxwinon
= pcxe_rxwinon
;
1086 bd
->memoff
= pcxe_memoff
;
1087 bd
->assertgwinon
= dummy_assertgwinon
;
1088 bd
->assertmemoff
= dummy_assertmemoff
;
1093 bd
->memwinon
= pcxi_memwinon
;
1094 bd
->memwinoff
= pcxi_memwinoff
;
1095 bd
->globalwinon
= pcxi_globalwinon
;
1096 bd
->txwinon
= pcxi_txwinon
;
1097 bd
->rxwinon
= pcxi_rxwinon
;
1098 bd
->memoff
= pcxi_memoff
;
1099 bd
->assertgwinon
= pcxi_assertgwinon
;
1100 bd
->assertmemoff
= pcxi_assertmemoff
;
1108 * Some cards need a memory segment to be defined for use in
1109 * transmit and receive windowing operations. These boards are
1110 * listed in the below switch. In the case of the XI the amount
1111 * of memory on the board is variable so the memory_seg is also
1112 * variable. This code determines what they segment should be.
1118 bd
->memory_seg
= 0xf000;
1122 board_id
= inb((int)bd
->port
);
1123 if ((board_id
& 0x1) == 0x1) {
1124 /* it's an XI card */
1125 /* Is it a 64K board */
1126 if ((board_id
& 0x30) == 0)
1127 bd
->memory_seg
= 0xf000;
1129 /* Is it a 128K board */
1130 if ((board_id
& 0x30) == 0x10)
1131 bd
->memory_seg
= 0xe000;
1133 /* Is is a 256K board */
1134 if ((board_id
& 0x30) == 0x20)
1135 bd
->memory_seg
= 0xc000;
1137 /* Is it a 512K board */
1138 if ((board_id
& 0x30) == 0x30)
1139 bd
->memory_seg
= 0x8000;
1141 printk(KERN_ERR
"epca: Board at 0x%x doesn't appear to be an XI\n", (int)bd
->port
);
1146 err
= tty_register_driver(pc_driver
);
1148 printk(KERN_ERR
"Couldn't register Digi PC/ driver");
1152 err
= tty_register_driver(pc_info
);
1154 printk(KERN_ERR
"Couldn't register Digi PC/ info ");
1158 /* Start up the poller to check for events on all enabled boards */
1159 init_timer(&epca_timer
);
1160 epca_timer
.function
= epcapoll
;
1161 mod_timer(&epca_timer
, jiffies
+ HZ
/25);
1165 tty_unregister_driver(pc_driver
);
1167 put_tty_driver(pc_info
);
1169 put_tty_driver(pc_driver
);
1174 static void post_fep_init(unsigned int crd
)
1177 void __iomem
*memaddr
;
1178 struct global_data __iomem
*gd
;
1179 struct board_info
*bd
;
1180 struct board_chan __iomem
*bc
;
1182 int shrinkmem
= 0, lowwater
;
1185 * This call is made by the user via. the ioctl call DIGI_INIT. It is
1186 * responsible for setting up all the card specific stuff.
1191 * If this is a PCI board, get the port info. Remember PCI cards do not
1192 * have entries into the epcaconfig.h file, so we can't get the number
1193 * of ports from it. Unfortunetly, this means that anyone doing a
1194 * DIGI_GETINFO before the board has booted will get an invalid number
1195 * of ports returned (It should return 0). Calls to DIGI_GETINFO after
1196 * DIGI_INIT has been called will return the proper values.
1198 if (bd
->type
>= PCIXEM
) { /* Begin get PCI number of ports */
1200 * Below we use XEMPORTS as a memory offset regardless of which
1201 * PCI card it is. This is because all of the supported PCI
1202 * cards have the same memory offset for the channel data. This
1203 * will have to be changed if we ever develop a PCI/XE card.
1204 * NOTE : The FEP manual states that the port offset is 0xC22
1205 * as opposed to 0xC02. This is only true for PC/XE, and PC/XI
1206 * cards; not for the XEM, or CX series. On the PCI cards the
1207 * number of ports is determined by reading a ID PROM located
1208 * in the box attached to the card. The card can then determine
1209 * the index the id to determine the number of ports available.
1210 * (FYI - The id should be located at 0x1ac (And may use up to
1211 * 4 bytes if the box in question is a XEM or CX)).
1213 /* PCI cards are already remapped at this point ISA are not */
1214 bd
->numports
= readw(bd
->re_map_membase
+ XEMPORTS
);
1215 epcaassert(bd
->numports
<= 64, "PCI returned a invalid number of ports");
1216 nbdevs
+= (bd
->numports
);
1218 /* Fix up the mappings for ISA/EISA etc */
1219 /* FIXME: 64K - can we be smarter ? */
1220 bd
->re_map_membase
= ioremap_nocache(bd
->membase
, 0x10000);
1224 card_ptr
[crd
] = card_ptr
[crd
-1] + boards
[crd
-1].numports
;
1226 card_ptr
[crd
] = &digi_channels
[crd
]; /* <- For card 0 only */
1229 epcaassert(ch
<= &digi_channels
[nbdevs
- 1], "ch out of range");
1231 memaddr
= bd
->re_map_membase
;
1234 * The below assignment will set bc to point at the BEGINING of the
1235 * cards channel structures. For 1 card there will be between 8 and 64
1236 * of these structures.
1238 bc
= memaddr
+ CHANSTRUCT
;
1241 * The below assignment will set gd to point at the BEGINING of global
1242 * memory address 0xc00. The first data in that global memory actually
1243 * starts at address 0xc1a. The command in pointer begins at 0xd10.
1245 gd
= memaddr
+ GLOBAL
;
1248 * XEPORTS (address 0xc22) points at the number of channels the card
1249 * supports. (For 64XE, XI, XEM, and XR use 0xc02)
1251 if ((bd
->type
== PCXEVE
|| bd
->type
== PCXE
) &&
1252 (readw(memaddr
+ XEPORTS
) < 3))
1254 if (bd
->type
< PCIXEM
)
1255 if (!request_region((int)bd
->port
, 4, board_desc
[bd
->type
]))
1260 * Remember ch is the main drivers channels structure, while bc is the
1261 * cards channel structure.
1263 for (i
= 0; i
< bd
->numports
; i
++, ch
++, bc
++) {
1264 unsigned long flags
;
1267 tty_port_init(&ch
->port
);
1268 ch
->port
.ops
= &epca_port_ops
;
1271 INIT_WORK(&ch
->tqueue
, do_softint
);
1272 ch
->board
= &boards
[crd
];
1274 spin_lock_irqsave(&epca_lock
, flags
);
1277 * Since some of the boards use different bitmaps for
1278 * their control signals we cannot hard code these
1279 * values and retain portability. We virtualize this
1308 if (boards
[crd
].altpin
) {
1309 ch
->dsr
= ch
->m_dcd
;
1310 ch
->dcd
= ch
->m_dsr
;
1311 ch
->digiext
.digi_flags
|= DIGI_ALTPIN
;
1313 ch
->dcd
= ch
->m_dcd
;
1314 ch
->dsr
= ch
->m_dsr
;
1319 ch
->magic
= EPCA_MAGIC
;
1320 tty_port_tty_set(&ch
->port
, NULL
);
1323 fepcmd(ch
, SETBUFFER
, 32, 0, 0, 0);
1327 tseg
= readw(&bc
->tseg
);
1328 rseg
= readw(&bc
->rseg
);
1334 /* Cover all the 2MEG cards */
1335 ch
->txptr
= memaddr
+ ((tseg
<< 4) & 0x1fffff);
1336 ch
->rxptr
= memaddr
+ ((rseg
<< 4) & 0x1fffff);
1337 ch
->txwin
= FEPWIN
| (tseg
>> 11);
1338 ch
->rxwin
= FEPWIN
| (rseg
>> 11);
1343 /* Cover all the 32K windowed cards */
1344 /* Mask equal to window size - 1 */
1345 ch
->txptr
= memaddr
+ ((tseg
<< 4) & 0x7fff);
1346 ch
->rxptr
= memaddr
+ ((rseg
<< 4) & 0x7fff);
1347 ch
->txwin
= FEPWIN
| (tseg
>> 11);
1348 ch
->rxwin
= FEPWIN
| (rseg
>> 11);
1353 ch
->txptr
= memaddr
+ (((tseg
- bd
->memory_seg
) << 4)
1355 ch
->txwin
= FEPWIN
| ((tseg
- bd
->memory_seg
) >> 9);
1356 ch
->rxptr
= memaddr
+ (((rseg
- bd
->memory_seg
) << 4)
1358 ch
->rxwin
= FEPWIN
| ((rseg
- bd
->memory_seg
) >> 9);
1363 ch
->txptr
= memaddr
+ ((tseg
- bd
->memory_seg
) << 4);
1364 ch
->rxptr
= memaddr
+ ((rseg
- bd
->memory_seg
) << 4);
1365 ch
->txwin
= ch
->rxwin
= 0;
1370 ch
->txbufsize
= readw(&bc
->tmax
) + 1;
1373 ch
->rxbufsize
= readw(&bc
->rmax
) + 1;
1375 lowwater
= ch
->txbufsize
>= 2000 ? 1024 : (ch
->txbufsize
/ 2);
1377 /* Set transmitter low water mark */
1378 fepcmd(ch
, STXLWATER
, lowwater
, 0, 10, 0);
1380 /* Set receiver low water mark */
1381 fepcmd(ch
, SRXLWATER
, (ch
->rxbufsize
/ 4), 0, 10, 0);
1383 /* Set receiver high water mark */
1384 fepcmd(ch
, SRXHWATER
, (3 * ch
->rxbufsize
/ 4), 0, 10, 0);
1386 writew(100, &bc
->edelay
);
1387 writeb(1, &bc
->idata
);
1389 ch
->startc
= readb(&bc
->startc
);
1390 ch
->stopc
= readb(&bc
->stopc
);
1391 ch
->startca
= readb(&bc
->startca
);
1392 ch
->stopca
= readb(&bc
->stopca
);
1402 ch
->port
.close_delay
= 50;
1404 spin_unlock_irqrestore(&epca_lock
, flags
);
1408 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1409 VERSION
, board_desc
[bd
->type
], (long)bd
->port
,
1410 (long)bd
->membase
, bd
->numports
);
1414 static void epcapoll(unsigned long ignored
)
1416 unsigned long flags
;
1418 unsigned int head
, tail
;
1420 struct board_info
*bd
;
1423 * This routine is called upon every timer interrupt. Even though the
1424 * Digi series cards are capable of generating interrupts this method
1425 * of non-looping polling is more efficient. This routine checks for
1426 * card generated events (Such as receive data, are transmit buffer
1427 * empty) and acts on those events.
1429 for (crd
= 0; crd
< num_cards
; crd
++) {
1433 if ((bd
->status
== DISABLED
) || digi_poller_inhibited
)
1437 * assertmemoff is not needed here; indeed it is an empty
1438 * subroutine. It is being kept because future boards may need
1439 * this as well as some legacy boards.
1441 spin_lock_irqsave(&epca_lock
, flags
);
1448 * In this case head and tail actually refer to the event queue
1449 * not the transmit or receive queue.
1451 head
= readw(&ch
->mailbox
->ein
);
1452 tail
= readw(&ch
->mailbox
->eout
);
1454 /* If head isn't equal to tail we have an event */
1459 spin_unlock_irqrestore(&epca_lock
, flags
);
1460 } /* End for each card */
1461 mod_timer(&epca_timer
, jiffies
+ (HZ
/ 25));
1464 static void doevent(int crd
)
1466 void __iomem
*eventbuf
;
1467 struct channel
*ch
, *chan0
;
1468 static struct tty_struct
*tty
;
1469 struct board_info
*bd
;
1470 struct board_chan __iomem
*bc
;
1471 unsigned int tail
, head
;
1476 * This subroutine is called by epcapoll when an event is detected
1477 * in the event queue. This routine responds to those events.
1481 chan0
= card_ptr
[crd
];
1482 epcaassert(chan0
<= &digi_channels
[nbdevs
- 1], "ch out of range");
1483 assertgwinon(chan0
);
1484 while ((tail
= readw(&chan0
->mailbox
->eout
)) !=
1485 (head
= readw(&chan0
->mailbox
->ein
))) {
1486 /* Begin while something in event queue */
1487 assertgwinon(chan0
);
1488 eventbuf
= bd
->re_map_membase
+ tail
+ ISTART
;
1489 /* Get the channel the event occurred on */
1490 channel
= readb(eventbuf
);
1491 /* Get the actual event code that occurred */
1492 event
= readb(eventbuf
+ 1);
1494 * The two assignments below get the current modem status
1495 * (mstat) and the previous modem status (lstat). These are
1496 * useful becuase an event could signal a change in modem
1499 mstat
= readb(eventbuf
+ 2);
1500 lstat
= readb(eventbuf
+ 3);
1502 ch
= chan0
+ channel
;
1503 if ((unsigned)channel
>= bd
->numports
|| !ch
) {
1504 if (channel
>= bd
->numports
)
1514 tty
= tty_port_tty_get(&ch
->port
);
1515 if (event
& DATA_IND
) { /* Begin DATA_IND */
1516 receive_data(ch
, tty
);
1518 } /* End DATA_IND */
1519 /* else *//* Fix for DCD transition missed bug */
1520 if (event
& MODEMCHG_IND
) {
1521 /* A modem signal change has been indicated */
1523 if (test_bit(ASYNCB_CHECK_CD
, &ch
->port
.flags
)) {
1524 /* We are now receiving dcd */
1525 if (mstat
& ch
->dcd
)
1526 wake_up_interruptible(&ch
->port
.open_wait
);
1527 else /* No dcd; hangup */
1528 pc_sched_event(ch
, EPCA_EVENT_HANGUP
);
1532 if (event
& BREAK_IND
) {
1533 /* A break has been indicated */
1534 tty_insert_flip_char(tty
, 0, TTY_BREAK
);
1535 tty_schedule_flip(tty
);
1536 } else if (event
& LOWTX_IND
) {
1537 if (ch
->statusflags
& LOWWAIT
) {
1538 ch
->statusflags
&= ~LOWWAIT
;
1541 } else if (event
& EMPTYTX_IND
) {
1542 /* This event is generated by
1543 setup_empty_event */
1544 ch
->statusflags
&= ~TXBUSY
;
1545 if (ch
->statusflags
& EMPTYWAIT
) {
1546 ch
->statusflags
&= ~EMPTYWAIT
;
1555 writew(1, &bc
->idata
);
1556 writew((tail
+ 4) & (IMAX
- ISTART
- 4), &chan0
->mailbox
->eout
);
1558 } /* End while something in event queue */
1561 static void fepcmd(struct channel
*ch
, int cmd
, int word_or_byte
,
1562 int byte2
, int ncmds
, int bytecmd
)
1564 unchar __iomem
*memaddr
;
1565 unsigned int head
, cmdTail
, cmdStart
, cmdMax
;
1569 /* This is the routine in which commands may be passed to the card. */
1571 if (ch
->board
->status
== DISABLED
)
1574 /* Remember head (As well as max) is just an offset not a base addr */
1575 head
= readw(&ch
->mailbox
->cin
);
1576 /* cmdStart is a base address */
1577 cmdStart
= readw(&ch
->mailbox
->cstart
);
1579 * We do the addition below because we do not want a max pointer
1580 * relative to cmdStart. We want a max pointer that points at the
1581 * physical end of the command queue.
1583 cmdMax
= (cmdStart
+ 4 + readw(&ch
->mailbox
->cmax
));
1584 memaddr
= ch
->board
->re_map_membase
;
1586 if (head
>= (cmdMax
- cmdStart
) || (head
& 03)) {
1587 printk(KERN_ERR
"line %d: Out of range, cmd = %x, head = %x\n",
1588 __LINE__
, cmd
, head
);
1589 printk(KERN_ERR
"line %d: Out of range, cmdMax = %x, cmdStart = %x\n",
1590 __LINE__
, cmdMax
, cmdStart
);
1594 writeb(cmd
, memaddr
+ head
+ cmdStart
+ 0);
1595 writeb(ch
->channelnum
, memaddr
+ head
+ cmdStart
+ 1);
1596 /* Below word_or_byte is bits to set */
1597 writeb(word_or_byte
, memaddr
+ head
+ cmdStart
+ 2);
1598 /* Below byte2 is bits to reset */
1599 writeb(byte2
, memaddr
+ head
+ cmdStart
+ 3);
1601 writeb(cmd
, memaddr
+ head
+ cmdStart
+ 0);
1602 writeb(ch
->channelnum
, memaddr
+ head
+ cmdStart
+ 1);
1603 writeb(word_or_byte
, memaddr
+ head
+ cmdStart
+ 2);
1605 head
= (head
+ 4) & (cmdMax
- cmdStart
- 4);
1606 writew(head
, &ch
->mailbox
->cin
);
1612 printk(KERN_ERR
"<Error> - Fep not responding in fepcmd()\n");
1615 head
= readw(&ch
->mailbox
->cin
);
1616 cmdTail
= readw(&ch
->mailbox
->cout
);
1617 n
= (head
- cmdTail
) & (cmdMax
- cmdStart
- 4);
1619 * Basically this will break when the FEP acknowledges the
1620 * command by incrementing cmdTail (Making it equal to head).
1622 if (n
<= ncmds
* (sizeof(short) * 4))
1628 * Digi products use fields in their channels structures that are very similar
1629 * to the c_cflag and c_iflag fields typically found in UNIX termios
1630 * structures. The below three routines allow mappings between these hardware
1631 * "flags" and their respective Linux flags.
1633 static unsigned termios2digi_h(struct channel
*ch
, unsigned cflag
)
1637 if (cflag
& CRTSCTS
) {
1638 ch
->digiext
.digi_flags
|= (RTSPACE
| CTSPACE
);
1639 res
|= ((ch
->m_cts
) | (ch
->m_rts
));
1642 if (ch
->digiext
.digi_flags
& RTSPACE
)
1645 if (ch
->digiext
.digi_flags
& DTRPACE
)
1648 if (ch
->digiext
.digi_flags
& CTSPACE
)
1651 if (ch
->digiext
.digi_flags
& DSRPACE
)
1654 if (ch
->digiext
.digi_flags
& DCDPACE
)
1657 if (res
& (ch
->m_rts
))
1658 ch
->digiext
.digi_flags
|= RTSPACE
;
1660 if (res
& (ch
->m_cts
))
1661 ch
->digiext
.digi_flags
|= CTSPACE
;
1666 static unsigned termios2digi_i(struct channel
*ch
, unsigned iflag
)
1668 unsigned res
= iflag
& (IGNBRK
| BRKINT
| IGNPAR
| PARMRK
|
1669 INPCK
| ISTRIP
| IXON
| IXANY
| IXOFF
);
1670 if (ch
->digiext
.digi_flags
& DIGI_AIXON
)
1675 static unsigned termios2digi_c(struct channel
*ch
, unsigned cflag
)
1678 if (cflag
& CBAUDEX
) {
1679 ch
->digiext
.digi_flags
|= DIGI_FAST
;
1681 * HUPCL bit is used by FEP to indicate fast baud table is to
1686 ch
->digiext
.digi_flags
&= ~DIGI_FAST
;
1688 * CBAUD has bit position 0x1000 set these days to indicate Linux
1689 * baud rate remap. Digi hardware can't handle the bit assignment.
1690 * (We use a different bit assignment for high speed.). Clear this
1693 res
|= cflag
& ((CBAUD
^ CBAUDEX
) | PARODD
| PARENB
| CSTOPB
| CSIZE
);
1695 * This gets a little confusing. The Digi cards have their own
1696 * representation of c_cflags controlling baud rate. For the most part
1697 * this is identical to the Linux implementation. However; Digi
1698 * supports one rate (76800) that Linux doesn't. This means that the
1699 * c_cflag entry that would normally mean 76800 for Digi actually means
1700 * 115200 under Linux. Without the below mapping, a stty 115200 would
1701 * only drive the board at 76800. Since the rate 230400 is also found
1702 * after 76800, the same problem afflicts us when we choose a rate of
1703 * 230400. Without the below modificiation stty 230400 would actually
1706 * There are two additional differences. The Linux value for CLOCAL
1707 * (0x800; 0004000) has no meaning to the Digi hardware. Also in later
1708 * releases of Linux; the CBAUD define has CBAUDEX (0x1000; 0010000)
1709 * ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX should be
1710 * checked for a screened out prior to termios2digi_c returning. Since
1711 * CLOCAL isn't used by the board this can be ignored as long as the
1712 * returned value is used only by Digi hardware.
1714 if (cflag
& CBAUDEX
) {
1716 * The below code is trying to guarantee that only baud rates
1717 * 115200 and 230400 are remapped. We use exclusive or because
1718 * the various baud rates share common bit positions and
1719 * therefore can't be tested for easily.
1721 if ((!((cflag
& 0x7) ^ (B115200
& ~CBAUDEX
))) ||
1722 (!((cflag
& 0x7) ^ (B230400
& ~CBAUDEX
))))
1728 /* Caller must hold the locks */
1729 static void epcaparam(struct tty_struct
*tty
, struct channel
*ch
)
1731 unsigned int cmdHead
;
1732 struct ktermios
*ts
;
1733 struct board_chan __iomem
*bc
;
1734 unsigned mval
, hflow
, cflag
, iflag
;
1737 epcaassert(bc
!= NULL
, "bc out of range");
1741 if ((ts
->c_cflag
& CBAUD
) == 0) { /* Begin CBAUD detected */
1742 cmdHead
= readw(&bc
->rin
);
1743 writew(cmdHead
, &bc
->rout
);
1744 cmdHead
= readw(&bc
->tin
);
1745 /* Changing baud in mid-stream transmission can be wonderful */
1747 * Flush current transmit buffer by setting cmdTail pointer
1748 * (tout) to cmdHead pointer (tin). Hopefully the transmit
1751 fepcmd(ch
, STOUT
, (unsigned) cmdHead
, 0, 0, 0);
1753 } else { /* Begin CBAUD not detected */
1755 * c_cflags have changed but that change had nothing to do with
1756 * BAUD. Propagate the change to the card.
1758 cflag
= termios2digi_c(ch
, ts
->c_cflag
);
1759 if (cflag
!= ch
->fepcflag
) {
1760 ch
->fepcflag
= cflag
;
1761 /* Set baud rate, char size, stop bits, parity */
1762 fepcmd(ch
, SETCTRLFLAGS
, (unsigned) cflag
, 0, 0, 0);
1765 * If the user has not forced CLOCAL and if the device is not a
1766 * CALLOUT device (Which is always CLOCAL) we set flags such
1767 * that the driver will wait on carrier detect.
1769 if (ts
->c_cflag
& CLOCAL
)
1770 clear_bit(ASYNCB_CHECK_CD
, &ch
->port
.flags
);
1772 set_bit(ASYNCB_CHECK_CD
, &ch
->port
.flags
);
1773 mval
= ch
->m_dtr
| ch
->m_rts
;
1774 } /* End CBAUD not detected */
1775 iflag
= termios2digi_i(ch
, ts
->c_iflag
);
1776 /* Check input mode flags */
1777 if (iflag
!= ch
->fepiflag
) {
1778 ch
->fepiflag
= iflag
;
1780 * Command sets channels iflag structure on the board. Such
1781 * things as input soft flow control, handling of parity
1782 * errors, and break handling are all set here.
1784 * break handling, parity handling, input stripping,
1785 * flow control chars
1787 fepcmd(ch
, SETIFLAGS
, (unsigned int) ch
->fepiflag
, 0, 0, 0);
1790 * Set the board mint value for this channel. This will cause hardware
1791 * events to be generated each time the DCD signal (Described in mint)
1794 writeb(ch
->dcd
, &bc
->mint
);
1795 if ((ts
->c_cflag
& CLOCAL
) || (ch
->digiext
.digi_flags
& DIGI_FORCEDCD
))
1796 if (ch
->digiext
.digi_flags
& DIGI_FORCEDCD
)
1797 writeb(0, &bc
->mint
);
1798 ch
->imodem
= readb(&bc
->mstat
);
1799 hflow
= termios2digi_h(ch
, ts
->c_cflag
);
1800 if (hflow
!= ch
->hflow
) {
1803 * Hard flow control has been selected but the board is not
1804 * using it. Activate hard flow control now.
1806 fepcmd(ch
, SETHFLOW
, hflow
, 0xff, 0, 1);
1808 mval
^= ch
->modemfake
& (mval
^ ch
->modem
);
1810 if (ch
->omodem
^ mval
) {
1813 * The below command sets the DTR and RTS mstat structure. If
1814 * hard flow control is NOT active these changes will drive the
1815 * output of the actual DTR and RTS lines. If hard flow control
1816 * is active, the changes will be saved in the mstat structure
1817 * and only asserted when hard flow control is turned off.
1820 /* First reset DTR & RTS; then set them */
1821 fepcmd(ch
, SETMODEM
, 0, ((ch
->m_dtr
)|(ch
->m_rts
)), 0, 1);
1822 fepcmd(ch
, SETMODEM
, mval
, 0, 0, 1);
1824 if (ch
->startc
!= ch
->fepstartc
|| ch
->stopc
!= ch
->fepstopc
) {
1825 ch
->fepstartc
= ch
->startc
;
1826 ch
->fepstopc
= ch
->stopc
;
1828 * The XON / XOFF characters have changed; propagate these
1829 * changes to the card.
1831 fepcmd(ch
, SONOFFC
, ch
->fepstartc
, ch
->fepstopc
, 0, 1);
1833 if (ch
->startca
!= ch
->fepstartca
|| ch
->stopca
!= ch
->fepstopca
) {
1834 ch
->fepstartca
= ch
->startca
;
1835 ch
->fepstopca
= ch
->stopca
;
1837 * Similar to the above, this time the auxilarly XON / XOFF
1838 * characters have changed; propagate these changes to the card.
1840 fepcmd(ch
, SAUXONOFFC
, ch
->fepstartca
, ch
->fepstopca
, 0, 1);
1844 /* Caller holds lock */
1845 static void receive_data(struct channel
*ch
, struct tty_struct
*tty
)
1848 struct ktermios
*ts
= NULL
;
1849 struct board_chan __iomem
*bc
;
1850 int dataToRead
, wrapgap
, bytesAvailable
;
1851 unsigned int tail
, head
;
1852 unsigned int wrapmask
;
1855 * This routine is called by doint when a receive data event has taken
1859 if (ch
->statusflags
& RXSTOPPED
)
1865 wrapmask
= ch
->rxbufsize
- 1;
1868 * Get the head and tail pointers to the receiver queue. Wrap the head
1869 * pointer if it has reached the end of the buffer.
1871 head
= readw(&bc
->rin
);
1873 tail
= readw(&bc
->rout
) & wrapmask
;
1875 bytesAvailable
= (head
- tail
) & wrapmask
;
1876 if (bytesAvailable
== 0)
1879 /* If CREAD bit is off or device not open, set TX tail to head */
1880 if (!tty
|| !ts
|| !(ts
->c_cflag
& CREAD
)) {
1881 writew(head
, &bc
->rout
);
1885 if (tty_buffer_request_room(tty
, bytesAvailable
+ 1) == 0)
1888 if (readb(&bc
->orun
)) {
1889 writeb(0, &bc
->orun
);
1890 printk(KERN_WARNING
"epca; overrun! DigiBoard device %s\n",
1892 tty_insert_flip_char(tty
, 0, TTY_OVERRUN
);
1895 while (bytesAvailable
> 0) {
1896 /* Begin while there is data on the card */
1897 wrapgap
= (head
>= tail
) ? head
- tail
: ch
->rxbufsize
- tail
;
1899 * Even if head has wrapped around only report the amount of
1900 * data to be equal to the size - tail. Remember memcpy can't
1901 * automaticly wrap around the receive buffer.
1903 dataToRead
= (wrapgap
< bytesAvailable
) ? wrapgap
1905 /* Make sure we don't overflow the buffer */
1906 dataToRead
= tty_prepare_flip_string(tty
, &rptr
, dataToRead
);
1907 if (dataToRead
== 0)
1910 * Move data read from our card into the line disciplines
1911 * buffer for translation if necessary.
1913 memcpy_fromio(rptr
, ch
->rxptr
+ tail
, dataToRead
);
1914 tail
= (tail
+ dataToRead
) & wrapmask
;
1915 bytesAvailable
-= dataToRead
;
1916 } /* End while there is data on the card */
1918 writew(tail
, &bc
->rout
);
1919 /* Must be called with global data */
1920 tty_schedule_flip(tty
);
1923 static int info_ioctl(struct tty_struct
*tty
, struct file
*file
,
1924 unsigned int cmd
, unsigned long arg
)
1929 struct digi_info di
;
1932 if (get_user(brd
, (unsigned int __user
*)arg
))
1934 if (brd
< 0 || brd
>= num_cards
|| num_cards
== 0)
1937 memset(&di
, 0, sizeof(di
));
1940 di
.status
= boards
[brd
].status
;
1941 di
.type
= boards
[brd
].type
;
1942 di
.numports
= boards
[brd
].numports
;
1943 /* Legacy fixups - just move along nothing to see */
1944 di
.port
= (unsigned char *)boards
[brd
].port
;
1945 di
.membase
= (unsigned char *)boards
[brd
].membase
;
1947 if (copy_to_user((void __user
*)arg
, &di
, sizeof(di
)))
1955 int brd
= arg
& 0xff000000 >> 16;
1956 unsigned char state
= arg
& 0xff;
1958 if (brd
< 0 || brd
>= num_cards
) {
1959 printk(KERN_ERR
"epca: DIGI POLLER : brd not valid!\n");
1962 digi_poller_inhibited
= state
;
1969 * This call is made by the apps to complete the
1970 * initialization of the board(s). This routine is
1971 * responsible for setting the card to its initial
1972 * state and setting the drivers control fields to the
1973 * sutianle settings for the card in question.
1976 for (crd
= 0; crd
< num_cards
; crd
++)
1986 static int pc_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1988 struct channel
*ch
= tty
->driver_data
;
1989 struct board_chan __iomem
*bc
;
1990 unsigned int mstat
, mflag
= 0;
1991 unsigned long flags
;
1998 spin_lock_irqsave(&epca_lock
, flags
);
2000 mstat
= readb(&bc
->mstat
);
2002 spin_unlock_irqrestore(&epca_lock
, flags
);
2004 if (mstat
& ch
->m_dtr
)
2006 if (mstat
& ch
->m_rts
)
2008 if (mstat
& ch
->m_cts
)
2010 if (mstat
& ch
->dsr
)
2012 if (mstat
& ch
->m_ri
)
2014 if (mstat
& ch
->dcd
)
2019 static int pc_tiocmset(struct tty_struct
*tty
, struct file
*file
,
2020 unsigned int set
, unsigned int clear
)
2022 struct channel
*ch
= tty
->driver_data
;
2023 unsigned long flags
;
2028 spin_lock_irqsave(&epca_lock
, flags
);
2030 * I think this modemfake stuff is broken. It doesn't correctly reflect
2031 * the behaviour desired by the TIOCM* ioctls. Therefore this is
2034 if (set
& TIOCM_RTS
) {
2035 ch
->modemfake
|= ch
->m_rts
;
2036 ch
->modem
|= ch
->m_rts
;
2038 if (set
& TIOCM_DTR
) {
2039 ch
->modemfake
|= ch
->m_dtr
;
2040 ch
->modem
|= ch
->m_dtr
;
2042 if (clear
& TIOCM_RTS
) {
2043 ch
->modemfake
|= ch
->m_rts
;
2044 ch
->modem
&= ~ch
->m_rts
;
2046 if (clear
& TIOCM_DTR
) {
2047 ch
->modemfake
|= ch
->m_dtr
;
2048 ch
->modem
&= ~ch
->m_dtr
;
2052 * The below routine generally sets up parity, baud, flow control
2053 * issues, etc.... It effect both control flags and input flags.
2057 spin_unlock_irqrestore(&epca_lock
, flags
);
2061 static int pc_ioctl(struct tty_struct
*tty
, struct file
*file
,
2062 unsigned int cmd
, unsigned long arg
)
2065 unsigned long flags
;
2066 unsigned int mflag
, mstat
;
2067 unsigned char startc
, stopc
;
2068 struct board_chan __iomem
*bc
;
2069 struct channel
*ch
= tty
->driver_data
;
2070 void __user
*argp
= (void __user
*)arg
;
2078 mflag
= pc_tiocmget(tty
, file
);
2079 if (put_user(mflag
, (unsigned long __user
*)argp
))
2083 if (get_user(mstat
, (unsigned __user
*)argp
))
2085 return pc_tiocmset(tty
, file
, mstat
, ~mstat
);
2087 spin_lock_irqsave(&epca_lock
, flags
);
2088 ch
->omodem
|= ch
->m_dtr
;
2090 fepcmd(ch
, SETMODEM
, ch
->m_dtr
, 0, 10, 1);
2092 spin_unlock_irqrestore(&epca_lock
, flags
);
2096 spin_lock_irqsave(&epca_lock
, flags
);
2097 ch
->omodem
&= ~ch
->m_dtr
;
2099 fepcmd(ch
, SETMODEM
, 0, ch
->m_dtr
, 10, 1);
2101 spin_unlock_irqrestore(&epca_lock
, flags
);
2104 if (copy_to_user(argp
, &ch
->digiext
, sizeof(digi_t
)))
2110 if (cmd
== DIGI_SETAW
) {
2111 /* Setup an event to indicate when the transmit
2113 spin_lock_irqsave(&epca_lock
, flags
);
2114 setup_empty_event(tty
, ch
);
2115 spin_unlock_irqrestore(&epca_lock
, flags
);
2116 tty_wait_until_sent(tty
, 0);
2118 /* ldisc lock already held in ioctl */
2119 if (tty
->ldisc
->ops
->flush_buffer
)
2120 tty
->ldisc
->ops
->flush_buffer(tty
);
2125 if (copy_from_user(&ch
->digiext
, argp
, sizeof(digi_t
)))
2128 if (ch
->digiext
.digi_flags
& DIGI_ALTPIN
) {
2129 ch
->dcd
= ch
->m_dsr
;
2130 ch
->dsr
= ch
->m_dcd
;
2132 ch
->dcd
= ch
->m_dcd
;
2133 ch
->dsr
= ch
->m_dsr
;
2136 spin_lock_irqsave(&epca_lock
, flags
);
2140 * The below routine generally sets up parity, baud, flow
2141 * control issues, etc.... It effect both control flags and
2146 spin_unlock_irqrestore(&epca_lock
, flags
);
2151 spin_lock_irqsave(&epca_lock
, flags
);
2153 if (cmd
== DIGI_GETFLOW
) {
2154 dflow
.startc
= readb(&bc
->startc
);
2155 dflow
.stopc
= readb(&bc
->stopc
);
2157 dflow
.startc
= readb(&bc
->startca
);
2158 dflow
.stopc
= readb(&bc
->stopca
);
2161 spin_unlock_irqrestore(&epca_lock
, flags
);
2163 if (copy_to_user(argp
, &dflow
, sizeof(dflow
)))
2169 if (cmd
== DIGI_SETFLOW
) {
2170 startc
= ch
->startc
;
2173 startc
= ch
->startca
;
2177 if (copy_from_user(&dflow
, argp
, sizeof(dflow
)))
2180 if (dflow
.startc
!= startc
|| dflow
.stopc
!= stopc
) {
2181 /* Begin if setflow toggled */
2182 spin_lock_irqsave(&epca_lock
, flags
);
2185 if (cmd
== DIGI_SETFLOW
) {
2186 ch
->fepstartc
= ch
->startc
= dflow
.startc
;
2187 ch
->fepstopc
= ch
->stopc
= dflow
.stopc
;
2188 fepcmd(ch
, SONOFFC
, ch
->fepstartc
,
2189 ch
->fepstopc
, 0, 1);
2191 ch
->fepstartca
= ch
->startca
= dflow
.startc
;
2192 ch
->fepstopca
= ch
->stopca
= dflow
.stopc
;
2193 fepcmd(ch
, SAUXONOFFC
, ch
->fepstartca
,
2194 ch
->fepstopca
, 0, 1);
2197 if (ch
->statusflags
& TXSTOPPED
)
2201 spin_unlock_irqrestore(&epca_lock
, flags
);
2202 } /* End if setflow toggled */
2205 return -ENOIOCTLCMD
;
2210 static void pc_set_termios(struct tty_struct
*tty
, struct ktermios
*old_termios
)
2213 unsigned long flags
;
2215 * verifyChannel returns the channel from the tty struct if it is
2216 * valid. This serves as a sanity check.
2218 ch
= verifyChannel(tty
);
2220 if (ch
!= NULL
) { /* Begin if channel valid */
2221 spin_lock_irqsave(&epca_lock
, flags
);
2225 spin_unlock_irqrestore(&epca_lock
, flags
);
2227 if ((old_termios
->c_cflag
& CRTSCTS
) &&
2228 ((tty
->termios
->c_cflag
& CRTSCTS
) == 0))
2229 tty
->hw_stopped
= 0;
2231 if (!(old_termios
->c_cflag
& CLOCAL
) &&
2232 (tty
->termios
->c_cflag
& CLOCAL
))
2233 wake_up_interruptible(&ch
->port
.open_wait
);
2235 } /* End if channel valid */
2238 static void do_softint(struct work_struct
*work
)
2240 struct channel
*ch
= container_of(work
, struct channel
, tqueue
);
2241 /* Called in response to a modem change event */
2242 if (ch
&& ch
->magic
== EPCA_MAGIC
) {
2243 struct tty_struct
*tty
= tty_port_tty_get(&ch
->port
);
2245 if (tty
&& tty
->driver_data
) {
2246 if (test_and_clear_bit(EPCA_EVENT_HANGUP
, &ch
->event
)) {
2248 wake_up_interruptible(&ch
->port
.open_wait
);
2249 clear_bit(ASYNCB_NORMAL_ACTIVE
,
2258 * pc_stop and pc_start provide software flow control to the routine and the
2261 static void pc_stop(struct tty_struct
*tty
)
2264 unsigned long flags
;
2266 * verifyChannel returns the channel from the tty struct if it is
2267 * valid. This serves as a sanity check.
2269 ch
= verifyChannel(tty
);
2271 spin_lock_irqsave(&epca_lock
, flags
);
2272 if ((ch
->statusflags
& TXSTOPPED
) == 0) {
2273 /* Begin if transmit stop requested */
2275 /* STOP transmitting now !! */
2276 fepcmd(ch
, PAUSETX
, 0, 0, 0, 0);
2277 ch
->statusflags
|= TXSTOPPED
;
2279 } /* End if transmit stop requested */
2280 spin_unlock_irqrestore(&epca_lock
, flags
);
2284 static void pc_start(struct tty_struct
*tty
)
2288 * verifyChannel returns the channel from the tty struct if it is
2289 * valid. This serves as a sanity check.
2291 ch
= verifyChannel(tty
);
2293 unsigned long flags
;
2294 spin_lock_irqsave(&epca_lock
, flags
);
2295 /* Just in case output was resumed because of a change
2297 if (ch
->statusflags
& TXSTOPPED
) {
2298 /* Begin transmit resume requested */
2299 struct board_chan __iomem
*bc
;
2302 if (ch
->statusflags
& LOWWAIT
)
2303 writeb(1, &bc
->ilow
);
2304 /* Okay, you can start transmitting again... */
2305 fepcmd(ch
, RESUMETX
, 0, 0, 0, 0);
2306 ch
->statusflags
&= ~TXSTOPPED
;
2308 } /* End transmit resume requested */
2309 spin_unlock_irqrestore(&epca_lock
, flags
);
2314 * The below routines pc_throttle and pc_unthrottle are used to slow (And
2315 * resume) the receipt of data into the kernels receive buffers. The exact
2316 * occurrence of this depends on the size of the kernels receive buffer and
2317 * what the 'watermarks' are set to for that buffer. See the n_ttys.c file for
2320 static void pc_throttle(struct tty_struct
*tty
)
2323 unsigned long flags
;
2325 * verifyChannel returns the channel from the tty struct if it is
2326 * valid. This serves as a sanity check.
2328 ch
= verifyChannel(tty
);
2330 spin_lock_irqsave(&epca_lock
, flags
);
2331 if ((ch
->statusflags
& RXSTOPPED
) == 0) {
2333 fepcmd(ch
, PAUSERX
, 0, 0, 0, 0);
2334 ch
->statusflags
|= RXSTOPPED
;
2337 spin_unlock_irqrestore(&epca_lock
, flags
);
2341 static void pc_unthrottle(struct tty_struct
*tty
)
2344 unsigned long flags
;
2346 * verifyChannel returns the channel from the tty struct if it is
2347 * valid. This serves as a sanity check.
2349 ch
= verifyChannel(tty
);
2351 /* Just in case output was resumed because of a change
2353 spin_lock_irqsave(&epca_lock
, flags
);
2354 if (ch
->statusflags
& RXSTOPPED
) {
2356 fepcmd(ch
, RESUMERX
, 0, 0, 0, 0);
2357 ch
->statusflags
&= ~RXSTOPPED
;
2360 spin_unlock_irqrestore(&epca_lock
, flags
);
2364 static int pc_send_break(struct tty_struct
*tty
, int msec
)
2366 struct channel
*ch
= tty
->driver_data
;
2367 unsigned long flags
;
2371 else if (msec
> 0xFFFE)
2376 spin_lock_irqsave(&epca_lock
, flags
);
2379 * Maybe I should send an infinite break here, schedule() for msec
2380 * amount of time, and then stop the break. This way, the user can't
2381 * screw up the FEP by causing digi_send_break() to be called (i.e. via
2382 * an ioctl()) more than once in msec amount of time.
2383 * Try this for now...
2385 fepcmd(ch
, SENDBREAK
, msec
, 0, 10, 0);
2387 spin_unlock_irqrestore(&epca_lock
, flags
);
2391 /* Caller MUST hold the lock */
2392 static void setup_empty_event(struct tty_struct
*tty
, struct channel
*ch
)
2394 struct board_chan __iomem
*bc
= ch
->brdchan
;
2397 ch
->statusflags
|= EMPTYWAIT
;
2399 * When set the iempty flag request a event to be generated when the
2400 * transmit buffer is empty (If there is no BREAK in progress).
2402 writeb(1, &bc
->iempty
);
2407 static void __init
epca_setup(char *str
, int *ints
)
2409 struct board_info board
;
2410 int index
, loop
, last
;
2415 * If this routine looks a little strange it is because it is only
2416 * called if a LILO append command is given to boot the kernel with
2417 * parameters. In this way, we can provide the user a method of
2418 * changing his board configuration without rebuilding the kernel.
2423 memset(&board
, 0, sizeof(board
));
2425 /* Assume the data is int first, later we can change it */
2426 /* I think that array position 0 of ints holds the number of args */
2427 for (last
= 0, index
= 1; index
<= ints
[0]; index
++)
2428 switch (index
) { /* Begin parse switch */
2430 board
.status
= ints
[index
];
2432 * We check for 2 (As opposed to 1; because 2 is a flag
2433 * instructing the driver to ignore epcaconfig.) For
2434 * this reason we check for 2.
2436 if (board
.status
== 2) {
2437 /* Begin ignore epcaconfig as well as lilo cmd line */
2441 } /* End ignore epcaconfig as well as lilo cmd line */
2443 if (board
.status
> 2) {
2444 printk(KERN_ERR
"epca_setup: Invalid board status 0x%x\n",
2446 invalid_lilo_config
= 1;
2447 setup_error_code
|= INVALID_BOARD_STATUS
;
2453 board
.type
= ints
[index
];
2454 if (board
.type
>= PCIXEM
) {
2455 printk(KERN_ERR
"epca_setup: Invalid board type 0x%x\n", board
.type
);
2456 invalid_lilo_config
= 1;
2457 setup_error_code
|= INVALID_BOARD_TYPE
;
2463 board
.altpin
= ints
[index
];
2464 if (board
.altpin
> 1) {
2465 printk(KERN_ERR
"epca_setup: Invalid board altpin 0x%x\n", board
.altpin
);
2466 invalid_lilo_config
= 1;
2467 setup_error_code
|= INVALID_ALTPIN
;
2474 board
.numports
= ints
[index
];
2475 if (board
.numports
< 2 || board
.numports
> 256) {
2476 printk(KERN_ERR
"epca_setup: Invalid board numports 0x%x\n", board
.numports
);
2477 invalid_lilo_config
= 1;
2478 setup_error_code
|= INVALID_NUM_PORTS
;
2481 nbdevs
+= board
.numports
;
2486 board
.port
= ints
[index
];
2487 if (ints
[index
] <= 0) {
2488 printk(KERN_ERR
"epca_setup: Invalid io port 0x%x\n", (unsigned int)board
.port
);
2489 invalid_lilo_config
= 1;
2490 setup_error_code
|= INVALID_PORT_BASE
;
2497 board
.membase
= ints
[index
];
2498 if (ints
[index
] <= 0) {
2499 printk(KERN_ERR
"epca_setup: Invalid memory base 0x%x\n",
2500 (unsigned int)board
.membase
);
2501 invalid_lilo_config
= 1;
2502 setup_error_code
|= INVALID_MEM_BASE
;
2509 printk(KERN_ERR
"<Error> - epca_setup: Too many integer parms\n");
2512 } /* End parse switch */
2514 while (str
&& *str
) { /* Begin while there is a string arg */
2515 /* find the next comma or terminator */
2517 /* While string is not null, and a comma hasn't been found */
2518 while (*temp
&& (*temp
!= ','))
2524 /* Set index to the number of args + 1 */
2530 if (strncmp("Disable", str
, len
) == 0)
2532 else if (strncmp("Enable", str
, len
) == 0)
2535 printk(KERN_ERR
"epca_setup: Invalid status %s\n", str
);
2536 invalid_lilo_config
= 1;
2537 setup_error_code
|= INVALID_BOARD_STATUS
;
2544 for (loop
= 0; loop
< EPCA_NUM_TYPES
; loop
++)
2545 if (strcmp(board_desc
[loop
], str
) == 0)
2548 * If the index incremented above refers to a
2549 * legitamate board type set it here.
2551 if (index
< EPCA_NUM_TYPES
)
2554 printk(KERN_ERR
"epca_setup: Invalid board type: %s\n", str
);
2555 invalid_lilo_config
= 1;
2556 setup_error_code
|= INVALID_BOARD_TYPE
;
2564 if (strncmp("Disable", str
, len
) == 0)
2566 else if (strncmp("Enable", str
, len
) == 0)
2569 printk(KERN_ERR
"epca_setup: Invalid altpin %s\n", str
);
2570 invalid_lilo_config
= 1;
2571 setup_error_code
|= INVALID_ALTPIN
;
2579 while (isdigit(*t2
))
2583 printk(KERN_ERR
"epca_setup: Invalid port count %s\n", str
);
2584 invalid_lilo_config
= 1;
2585 setup_error_code
|= INVALID_NUM_PORTS
;
2590 * There is not a man page for simple_strtoul but the
2591 * code can be found in vsprintf.c. The first argument
2592 * is the string to translate (To an unsigned long
2593 * obviously), the second argument can be the address
2594 * of any character variable or a NULL. If a variable
2595 * is given, the end pointer of the string will be
2596 * stored in that variable; if a NULL is given the end
2597 * pointer will not be returned. The last argument is
2598 * the base to use. If a 0 is indicated, the routine
2599 * will attempt to determine the proper base by looking
2600 * at the values prefix (A '0' for octal, a 'x' for
2601 * hex, etc ... If a value is given it will use that
2602 * value as the base.
2604 board
.numports
= simple_strtoul(str
, NULL
, 0);
2605 nbdevs
+= board
.numports
;
2611 while (isxdigit(*t2
))
2615 printk(KERN_ERR
"epca_setup: Invalid i/o address %s\n", str
);
2616 invalid_lilo_config
= 1;
2617 setup_error_code
|= INVALID_PORT_BASE
;
2621 board
.port
= simple_strtoul(str
, NULL
, 16);
2627 while (isxdigit(*t2
))
2631 printk(KERN_ERR
"epca_setup: Invalid memory base %s\n", str
);
2632 invalid_lilo_config
= 1;
2633 setup_error_code
|= INVALID_MEM_BASE
;
2636 board
.membase
= simple_strtoul(str
, NULL
, 16);
2640 printk(KERN_ERR
"epca: Too many string parms\n");
2644 } /* End while there is a string arg */
2647 printk(KERN_ERR
"epca: Insufficient parms specified\n");
2651 /* I should REALLY validate the stuff here */
2652 /* Copies our local copy of board into boards */
2653 memcpy((void *)&boards
[num_cards
], (void *)&board
, sizeof(board
));
2654 /* Does this get called once per lilo arg are what ? */
2655 printk(KERN_INFO
"PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2656 num_cards
, board_desc
[board
.type
],
2657 board
.numports
, (int)board
.port
, (unsigned int) board
.membase
);
2661 static int __init
epca_real_setup(char *str
)
2665 epca_setup(get_options(str
, 11, ints
), ints
);
2669 __setup("digiepca", epca_real_setup
);
2672 enum epic_board_types
{
2679 /* indexed directly by epic_board_types enum */
2681 unsigned char board_type
;
2682 unsigned bar_idx
; /* PCI base address region */
2683 } epca_info_tbl
[] = {
2690 static int __devinit
epca_init_one(struct pci_dev
*pdev
,
2691 const struct pci_device_id
*ent
)
2693 static int board_num
= -1;
2694 int board_idx
, info_idx
= ent
->driver_data
;
2697 if (pci_enable_device(pdev
))
2701 board_idx
= board_num
+ num_cards
;
2702 if (board_idx
>= MAXBOARDS
)
2705 addr
= pci_resource_start(pdev
, epca_info_tbl
[info_idx
].bar_idx
);
2707 printk(KERN_ERR PFX
"PCI region #%d not available (size 0)\n",
2708 epca_info_tbl
[info_idx
].bar_idx
);
2712 boards
[board_idx
].status
= ENABLED
;
2713 boards
[board_idx
].type
= epca_info_tbl
[info_idx
].board_type
;
2714 boards
[board_idx
].numports
= 0x0;
2715 boards
[board_idx
].port
= addr
+ PCI_IO_OFFSET
;
2716 boards
[board_idx
].membase
= addr
;
2718 if (!request_mem_region(addr
+ PCI_IO_OFFSET
, 0x200000, "epca")) {
2719 printk(KERN_ERR PFX
"resource 0x%x @ 0x%lx unavailable\n",
2720 0x200000, addr
+ PCI_IO_OFFSET
);
2724 boards
[board_idx
].re_map_port
= ioremap_nocache(addr
+ PCI_IO_OFFSET
,
2726 if (!boards
[board_idx
].re_map_port
) {
2727 printk(KERN_ERR PFX
"cannot map 0x%x @ 0x%lx\n",
2728 0x200000, addr
+ PCI_IO_OFFSET
);
2729 goto err_out_free_pciio
;
2732 if (!request_mem_region(addr
, 0x200000, "epca")) {
2733 printk(KERN_ERR PFX
"resource 0x%x @ 0x%lx unavailable\n",
2735 goto err_out_free_iounmap
;
2738 boards
[board_idx
].re_map_membase
= ioremap_nocache(addr
, 0x200000);
2739 if (!boards
[board_idx
].re_map_membase
) {
2740 printk(KERN_ERR PFX
"cannot map 0x%x @ 0x%lx\n",
2741 0x200000, addr
+ PCI_IO_OFFSET
);
2742 goto err_out_free_memregion
;
2746 * I don't know what the below does, but the hardware guys say its
2747 * required on everything except PLX (In this case XRJ).
2749 if (info_idx
!= brd_xrj
) {
2750 pci_write_config_byte(pdev
, 0x40, 0);
2751 pci_write_config_byte(pdev
, 0x46, 0);
2756 err_out_free_memregion
:
2757 release_mem_region(addr
, 0x200000);
2758 err_out_free_iounmap
:
2759 iounmap(boards
[board_idx
].re_map_port
);
2761 release_mem_region(addr
+ PCI_IO_OFFSET
, 0x200000);
2767 static struct pci_device_id epca_pci_tbl
[] = {
2768 { PCI_VENDOR_DIGI
, PCI_DEVICE_XR
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, brd_xr
},
2769 { PCI_VENDOR_DIGI
, PCI_DEVICE_XEM
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, brd_xem
},
2770 { PCI_VENDOR_DIGI
, PCI_DEVICE_CX
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, brd_cx
},
2771 { PCI_VENDOR_DIGI
, PCI_DEVICE_XRJ
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, brd_xrj
},
2775 MODULE_DEVICE_TABLE(pci
, epca_pci_tbl
);
2777 static int __init
init_PCI(void)
2779 memset(&epca_driver
, 0, sizeof(epca_driver
));
2780 epca_driver
.name
= "epca";
2781 epca_driver
.id_table
= epca_pci_tbl
;
2782 epca_driver
.probe
= epca_init_one
;
2784 return pci_register_driver(&epca_driver
);
2787 MODULE_LICENSE("GPL");