]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/char/epca.c
ixgbe: add MAC and PHY support for x540
[net-next-2.6.git] / drivers / char / epca.c
CommitLineData
1da177e4 1/*
1da177e4 2 Copyright (C) 1996 Digi International.
ae0b78d0 3
1da177e4
LT
4 For technical support please email digiLinux@dgii.com or
5 call Digi tech support at (612) 912-3456
6
f2cf8e25
AC
7 ** This driver is no longer supported by Digi **
8
ae0b78d0
AD
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.
12
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.
1da177e4 17
ae0b78d0
AD
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.
22
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.
26*/
27/* See README.epca for change history --DAT*/
1da177e4 28
1da177e4
LT
29#include <linux/module.h>
30#include <linux/kernel.h>
31#include <linux/types.h>
32#include <linux/init.h>
d43c36dc 33#include <linux/sched.h>
1da177e4
LT
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>
7cc34fd0 39#include <linux/slab.h>
1da177e4
LT
40#include <linux/ioport.h>
41#include <linux/interrupt.h>
191260a0
AC
42#include <linux/uaccess.h>
43#include <linux/io.h>
f2cf8e25 44#include <linux/spinlock.h>
1da177e4
LT
45#include <linux/pci.h>
46#include "digiPCI.h"
f2cf8e25 47
1da177e4
LT
48
49#include "digi1.h"
50#include "digiFep1.h"
51#include "epca.h"
52#include "epcaconfig.h"
53
f2cf8e25 54#define VERSION "1.3.0.1-LK2.6"
1da177e4
LT
55
56/* This major needs to be submitted to Linux to join the majors list */
ae0b78d0 57#define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
1da177e4
LT
58
59
60#define MAXCARDS 7
61#define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
62
63#define PFX "epca: "
64
1da177e4
LT
65static int nbdevs, num_cards, liloconfig;
66static int digi_poller_inhibited = 1 ;
67
68static int setup_error_code;
69static int invalid_lilo_config;
70
ae0b78d0
AD
71/*
72 * The ISA boards do window flipping into the same spaces so its only sane with
d1c815e5
AC
73 * a single lock. It's still pretty efficient. This lock guards the hardware
74 * and the tty_port lock guards the kernel side stuff like use counts. Take
75 * this lock inside the port lock if you must take both.
ae0b78d0 76 */
34af946a 77static DEFINE_SPINLOCK(epca_lock);
f2cf8e25 78
191260a0
AC
79/* MAXBOARDS is typically 12, but ISA and EISA cards are restricted
80 to 7 below. */
1da177e4
LT
81static struct board_info boards[MAXBOARDS];
82
1da177e4
LT
83static struct tty_driver *pc_driver;
84static struct tty_driver *pc_info;
85
86/* ------------------ Begin Digi specific structures -------------------- */
87
ae0b78d0
AD
88/*
89 * digi_channels represents an array of structures that keep track of each
90 * channel of the Digi product. Information such as transmit and receive
91 * pointers, termio data, and signal definitions (DTR, CTS, etc ...) are stored
92 * here. This structure is NOT used to overlay the cards physical channel
93 * structure.
94 */
1da177e4
LT
95static struct channel digi_channels[MAX_ALLOC];
96
ae0b78d0
AD
97/*
98 * card_ptr is an array used to hold the address of the first channel structure
99 * of each card. This array will hold the addresses of various channels located
100 * in digi_channels.
101 */
1da177e4
LT
102static struct channel *card_ptr[MAXCARDS];
103
104static struct timer_list epca_timer;
105
ae0b78d0
AD
106/*
107 * Begin generic memory functions. These functions will be alias (point at)
108 * more specific functions dependent on the board being configured.
109 */
f2cf8e25
AC
110static void memwinon(struct board_info *b, unsigned int win);
111static void memwinoff(struct board_info *b, unsigned int win);
112static void globalwinon(struct channel *ch);
113static void rxwinon(struct channel *ch);
114static void txwinon(struct channel *ch);
115static void memoff(struct channel *ch);
116static void assertgwinon(struct channel *ch);
117static void assertmemoff(struct channel *ch);
1da177e4
LT
118
119/* ---- Begin more 'specific' memory functions for cx_like products --- */
120
f2cf8e25
AC
121static void pcxem_memwinon(struct board_info *b, unsigned int win);
122static void pcxem_memwinoff(struct board_info *b, unsigned int win);
123static void pcxem_globalwinon(struct channel *ch);
124static void pcxem_rxwinon(struct channel *ch);
125static void pcxem_txwinon(struct channel *ch);
126static void pcxem_memoff(struct channel *ch);
1da177e4
LT
127
128/* ------ Begin more 'specific' memory functions for the pcxe ------- */
129
f2cf8e25
AC
130static void pcxe_memwinon(struct board_info *b, unsigned int win);
131static void pcxe_memwinoff(struct board_info *b, unsigned int win);
132static void pcxe_globalwinon(struct channel *ch);
133static void pcxe_rxwinon(struct channel *ch);
134static void pcxe_txwinon(struct channel *ch);
135static void pcxe_memoff(struct channel *ch);
1da177e4
LT
136
137/* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
138/* Note : pc64xe and pcxi share the same windowing routines */
139
f2cf8e25
AC
140static void pcxi_memwinon(struct board_info *b, unsigned int win);
141static void pcxi_memwinoff(struct board_info *b, unsigned int win);
142static void pcxi_globalwinon(struct channel *ch);
143static void pcxi_rxwinon(struct channel *ch);
144static void pcxi_txwinon(struct channel *ch);
145static void pcxi_memoff(struct channel *ch);
1da177e4
LT
146
147/* - Begin 'specific' do nothing memory functions needed for some cards - */
148
f2cf8e25
AC
149static void dummy_memwinon(struct board_info *b, unsigned int win);
150static void dummy_memwinoff(struct board_info *b, unsigned int win);
151static void dummy_globalwinon(struct channel *ch);
152static void dummy_rxwinon(struct channel *ch);
153static void dummy_txwinon(struct channel *ch);
154static void dummy_memoff(struct channel *ch);
155static void dummy_assertgwinon(struct channel *ch);
156static void dummy_assertmemoff(struct channel *ch);
1da177e4 157
f2cf8e25
AC
158static struct channel *verifyChannel(struct tty_struct *);
159static void pc_sched_event(struct channel *, int);
1da177e4
LT
160static void epca_error(int, char *);
161static void pc_close(struct tty_struct *, struct file *);
d1c815e5 162static void shutdown(struct channel *, struct tty_struct *tty);
1da177e4 163static void pc_hangup(struct tty_struct *);
1da177e4
LT
164static int pc_write_room(struct tty_struct *);
165static int pc_chars_in_buffer(struct tty_struct *);
166static void pc_flush_buffer(struct tty_struct *);
167static void pc_flush_chars(struct tty_struct *);
1da177e4
LT
168static int pc_open(struct tty_struct *, struct file *);
169static void post_fep_init(unsigned int crd);
170static void epcapoll(unsigned long);
171static void doevent(int);
172static void fepcmd(struct channel *, int, int, int, int, int);
173static unsigned termios2digi_h(struct channel *ch, unsigned);
174static unsigned termios2digi_i(struct channel *ch, unsigned);
175static unsigned termios2digi_c(struct channel *ch, unsigned);
176static void epcaparam(struct tty_struct *, struct channel *);
3969ffba 177static void receive_data(struct channel *, struct tty_struct *tty);
1da177e4 178static int pc_ioctl(struct tty_struct *, struct file *,
191260a0 179 unsigned int, unsigned long);
1da177e4 180static int info_ioctl(struct tty_struct *, struct file *,
191260a0 181 unsigned int, unsigned long);
606d099c 182static void pc_set_termios(struct tty_struct *, struct ktermios *);
c4028958 183static void do_softint(struct work_struct *work);
1da177e4
LT
184static void pc_stop(struct tty_struct *);
185static void pc_start(struct tty_struct *);
191260a0 186static void pc_throttle(struct tty_struct *tty);
1da177e4 187static void pc_unthrottle(struct tty_struct *tty);
dcbf1280 188static int pc_send_break(struct tty_struct *tty, int msec);
1da177e4 189static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
1da177e4 190
1da177e4 191static int pc_write(struct tty_struct *, const unsigned char *, int);
f2cf8e25 192static int pc_init(void);
1da177e4 193static int init_PCI(void);
1da177e4 194
ae0b78d0
AD
195/*
196 * Table of functions for each board to handle memory. Mantaining parallelism
197 * is a *very* good idea here. The idea is for the runtime code to blindly call
198 * these functions, not knowing/caring about the underlying hardware. This
199 * stuff should contain no conditionals; if more functionality is needed a
200 * different entry should be established. These calls are the interface calls
201 * and are the only functions that should be accessed. Anyone caught making
202 * direct calls deserves what they get.
203 */
f2cf8e25 204static void memwinon(struct board_info *b, unsigned int win)
1da177e4 205{
ae0b78d0 206 b->memwinon(b, win);
1da177e4
LT
207}
208
f2cf8e25 209static void memwinoff(struct board_info *b, unsigned int win)
1da177e4 210{
ae0b78d0 211 b->memwinoff(b, win);
1da177e4
LT
212}
213
f2cf8e25 214static void globalwinon(struct channel *ch)
1da177e4 215{
ae0b78d0 216 ch->board->globalwinon(ch);
1da177e4
LT
217}
218
f2cf8e25 219static void rxwinon(struct channel *ch)
1da177e4 220{
ae0b78d0 221 ch->board->rxwinon(ch);
1da177e4
LT
222}
223
f2cf8e25 224static void txwinon(struct channel *ch)
1da177e4 225{
ae0b78d0 226 ch->board->txwinon(ch);
1da177e4
LT
227}
228
f2cf8e25 229static void memoff(struct channel *ch)
1da177e4 230{
ae0b78d0 231 ch->board->memoff(ch);
1da177e4 232}
f2cf8e25 233static void assertgwinon(struct channel *ch)
1da177e4 234{
ae0b78d0 235 ch->board->assertgwinon(ch);
1da177e4
LT
236}
237
f2cf8e25 238static void assertmemoff(struct channel *ch)
1da177e4 239{
ae0b78d0 240 ch->board->assertmemoff(ch);
1da177e4
LT
241}
242
ae0b78d0 243/* PCXEM windowing is the same as that used in the PCXR and CX series cards. */
f2cf8e25 244static void pcxem_memwinon(struct board_info *b, unsigned int win)
1da177e4 245{
191260a0 246 outb_p(FEPWIN | win, b->port + 1);
1da177e4
LT
247}
248
f2cf8e25 249static void pcxem_memwinoff(struct board_info *b, unsigned int win)
1da177e4 250{
f2cf8e25 251 outb_p(0, b->port + 1);
1da177e4
LT
252}
253
f2cf8e25 254static void pcxem_globalwinon(struct channel *ch)
1da177e4 255{
191260a0 256 outb_p(FEPWIN, (int)ch->board->port + 1);
1da177e4
LT
257}
258
f2cf8e25 259static void pcxem_rxwinon(struct channel *ch)
1da177e4
LT
260{
261 outb_p(ch->rxwin, (int)ch->board->port + 1);
262}
263
f2cf8e25 264static void pcxem_txwinon(struct channel *ch)
1da177e4
LT
265{
266 outb_p(ch->txwin, (int)ch->board->port + 1);
267}
268
f2cf8e25 269static void pcxem_memoff(struct channel *ch)
1da177e4
LT
270{
271 outb_p(0, (int)ch->board->port + 1);
272}
273
274/* ----------------- Begin pcxe memory window stuff ------------------ */
f2cf8e25 275static void pcxe_memwinon(struct board_info *b, unsigned int win)
1da177e4 276{
ae0b78d0 277 outb_p(FEPWIN | win, b->port + 1);
1da177e4
LT
278}
279
f2cf8e25 280static void pcxe_memwinoff(struct board_info *b, unsigned int win)
1da177e4 281{
ae0b78d0 282 outb_p(inb(b->port) & ~FEPMEM, b->port + 1);
f2cf8e25 283 outb_p(0, b->port + 1);
1da177e4
LT
284}
285
f2cf8e25 286static void pcxe_globalwinon(struct channel *ch)
1da177e4 287{
ae0b78d0 288 outb_p(FEPWIN, (int)ch->board->port + 1);
1da177e4
LT
289}
290
f2cf8e25 291static void pcxe_rxwinon(struct channel *ch)
1da177e4 292{
ae0b78d0 293 outb_p(ch->rxwin, (int)ch->board->port + 1);
1da177e4
LT
294}
295
f2cf8e25 296static void pcxe_txwinon(struct channel *ch)
1da177e4 297{
ae0b78d0 298 outb_p(ch->txwin, (int)ch->board->port + 1);
1da177e4
LT
299}
300
f2cf8e25 301static void pcxe_memoff(struct channel *ch)
1da177e4
LT
302{
303 outb_p(0, (int)ch->board->port);
304 outb_p(0, (int)ch->board->port + 1);
305}
306
307/* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
f2cf8e25 308static void pcxi_memwinon(struct board_info *b, unsigned int win)
1da177e4 309{
ae0b78d0 310 outb_p(inb(b->port) | FEPMEM, b->port);
1da177e4
LT
311}
312
f2cf8e25 313static void pcxi_memwinoff(struct board_info *b, unsigned int win)
1da177e4 314{
f2cf8e25 315 outb_p(inb(b->port) & ~FEPMEM, b->port);
1da177e4
LT
316}
317
f2cf8e25 318static void pcxi_globalwinon(struct channel *ch)
1da177e4 319{
f2cf8e25 320 outb_p(FEPMEM, ch->board->port);
1da177e4
LT
321}
322
f2cf8e25 323static void pcxi_rxwinon(struct channel *ch)
1da177e4 324{
ae0b78d0 325 outb_p(FEPMEM, ch->board->port);
1da177e4
LT
326}
327
f2cf8e25 328static void pcxi_txwinon(struct channel *ch)
1da177e4 329{
ae0b78d0 330 outb_p(FEPMEM, ch->board->port);
1da177e4
LT
331}
332
f2cf8e25 333static void pcxi_memoff(struct channel *ch)
1da177e4 334{
f2cf8e25 335 outb_p(0, ch->board->port);
1da177e4
LT
336}
337
f2cf8e25 338static void pcxi_assertgwinon(struct channel *ch)
1da177e4 339{
f2cf8e25 340 epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
1da177e4
LT
341}
342
f2cf8e25 343static void pcxi_assertmemoff(struct channel *ch)
1da177e4 344{
f2cf8e25 345 epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
1da177e4
LT
346}
347
ae0b78d0
AD
348/*
349 * Not all of the cards need specific memory windowing routines. Some cards
350 * (Such as PCI) needs no windowing routines at all. We provide these do
351 * nothing routines so that the same code base can be used. The driver will
352 * ALWAYS call a windowing routine if it thinks it needs to; regardless of the
353 * card. However, dependent on the card the routine may or may not do anything.
354 */
f2cf8e25 355static void dummy_memwinon(struct board_info *b, unsigned int win)
1da177e4
LT
356{
357}
358
f2cf8e25 359static void dummy_memwinoff(struct board_info *b, unsigned int win)
1da177e4
LT
360{
361}
362
f2cf8e25 363static void dummy_globalwinon(struct channel *ch)
1da177e4
LT
364{
365}
366
f2cf8e25 367static void dummy_rxwinon(struct channel *ch)
1da177e4
LT
368{
369}
370
f2cf8e25 371static void dummy_txwinon(struct channel *ch)
1da177e4
LT
372{
373}
374
f2cf8e25 375static void dummy_memoff(struct channel *ch)
1da177e4
LT
376{
377}
378
f2cf8e25 379static void dummy_assertgwinon(struct channel *ch)
1da177e4
LT
380{
381}
382
f2cf8e25 383static void dummy_assertmemoff(struct channel *ch)
1da177e4
LT
384{
385}
386
f2cf8e25 387static struct channel *verifyChannel(struct tty_struct *tty)
ae0b78d0
AD
388{
389 /*
390 * This routine basically provides a sanity check. It insures that the
391 * channel returned is within the proper range of addresses as well as
392 * properly initialized. If some bogus info gets passed in
393 * through tty->driver_data this should catch it.
394 */
f2cf8e25 395 if (tty) {
c9f19e96 396 struct channel *ch = tty->driver_data;
191260a0 397 if (ch >= &digi_channels[0] && ch < &digi_channels[nbdevs]) {
1da177e4
LT
398 if (ch->magic == EPCA_MAGIC)
399 return ch;
400 }
f2cf8e25 401 }
1da177e4 402 return NULL;
ae0b78d0 403}
1da177e4 404
f2cf8e25
AC
405static void pc_sched_event(struct channel *ch, int event)
406{
ae0b78d0
AD
407 /*
408 * We call this to schedule interrupt processing on some event. The
409 * kernel sees our request and calls the related routine in OUR driver.
410 */
1da177e4
LT
411 ch->event |= 1 << event;
412 schedule_work(&ch->tqueue);
ae0b78d0 413}
1da177e4
LT
414
415static void epca_error(int line, char *msg)
f2cf8e25 416{
191260a0 417 printk(KERN_ERR "epca_error (Digi): line = %d %s\n", line, msg);
f2cf8e25 418}
1da177e4 419
ae0b78d0 420static void pc_close(struct tty_struct *tty, struct file *filp)
f2cf8e25 421{
1da177e4 422 struct channel *ch;
d1c815e5 423 struct tty_port *port;
ae0b78d0
AD
424 /*
425 * verifyChannel returns the channel from the tty struct if it is
426 * valid. This serves as a sanity check.
427 */
191260a0 428 ch = verifyChannel(tty);
d1c815e5
AC
429 if (ch == NULL)
430 return;
431 port = &ch->port;
1da177e4 432
6ed1dbae 433 if (tty_port_close_start(port, tty, filp) == 0)
d1c815e5 434 return;
1da177e4 435
d1c815e5 436 pc_flush_buffer(tty);
d1c815e5
AC
437 shutdown(ch, tty);
438
6ed1dbae
AC
439 tty_port_close_end(port, tty);
440 ch->event = 0; /* FIXME: review ch->event locking */
3969ffba 441 tty_port_tty_set(port, NULL);
ae0b78d0 442}
1da177e4 443
d1c815e5 444static void shutdown(struct channel *ch, struct tty_struct *tty)
ae0b78d0 445{
1da177e4 446 unsigned long flags;
bc9a5154 447 struct board_chan __iomem *bc;
d1c815e5 448 struct tty_port *port = &ch->port;
1da177e4 449
d1c815e5 450 if (!(port->flags & ASYNC_INITIALIZED))
1da177e4
LT
451 return;
452
f2cf8e25 453 spin_lock_irqsave(&epca_lock, flags);
1da177e4 454
f2cf8e25 455 globalwinon(ch);
1da177e4
LT
456 bc = ch->brdchan;
457
ae0b78d0
AD
458 /*
459 * In order for an event to be generated on the receipt of data the
460 * idata flag must be set. Since we are shutting down, this is not
461 * necessary clear this flag.
462 */
1da177e4 463 if (bc)
f2cf8e25 464 writeb(0, &bc->idata);
1da177e4 465
ae0b78d0 466 /* If we're a modem control device and HUPCL is on, drop RTS & DTR. */
f2cf8e25 467 if (tty->termios->c_cflag & HUPCL) {
1da177e4
LT
468 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
469 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
470 }
1da177e4
LT
471 memoff(ch);
472
ae0b78d0
AD
473 /*
474 * The channel has officialy been closed. The next time it is opened it
475 * will have to reinitialized. Set a flag to indicate this.
476 */
1da177e4 477 /* Prevent future Digi programmed interrupts from coming active */
d1c815e5 478 port->flags &= ~ASYNC_INITIALIZED;
f2cf8e25 479 spin_unlock_irqrestore(&epca_lock, flags);
ae0b78d0 480}
1da177e4
LT
481
482static void pc_hangup(struct tty_struct *tty)
ae0b78d0 483{
1da177e4 484 struct channel *ch;
d1c815e5 485
ae0b78d0
AD
486 /*
487 * verifyChannel returns the channel from the tty struct if it is
488 * valid. This serves as a sanity check.
489 */
191260a0
AC
490 ch = verifyChannel(tty);
491 if (ch != NULL) {
978e595f 492 pc_flush_buffer(tty);
1da177e4 493 tty_ldisc_flush(tty);
d1c815e5
AC
494 shutdown(ch, tty);
495
d1c815e5 496 ch->event = 0; /* FIXME: review locking of ch->event */
6ed1dbae 497 tty_port_hangup(&ch->port);
ae0b78d0
AD
498 }
499}
1da177e4 500
ae0b78d0 501static int pc_write(struct tty_struct *tty,
191260a0 502 const unsigned char *buf, int bytesAvailable)
ae0b78d0 503{
f2cf8e25
AC
504 unsigned int head, tail;
505 int dataLen;
506 int size;
507 int amountCopied;
1da177e4
LT
508 struct channel *ch;
509 unsigned long flags;
510 int remain;
bc9a5154 511 struct board_chan __iomem *bc;
1da177e4 512
ae0b78d0
AD
513 /*
514 * pc_write is primarily called directly by the kernel routine
515 * tty_write (Though it can also be called by put_char) found in
516 * tty_io.c. pc_write is passed a line discipline buffer where the data
517 * to be written out is stored. The line discipline implementation
518 * itself is done at the kernel level and is not brought into the
519 * driver.
520 */
1da177e4 521
ae0b78d0
AD
522 /*
523 * verifyChannel returns the channel from the tty struct if it is
524 * valid. This serves as a sanity check.
525 */
191260a0
AC
526 ch = verifyChannel(tty);
527 if (ch == NULL)
1da177e4
LT
528 return 0;
529
530 /* Make a pointer to the channel data structure found on the board. */
1da177e4
LT
531 bc = ch->brdchan;
532 size = ch->txbufsize;
1da177e4 533 amountCopied = 0;
1da177e4 534
f2cf8e25 535 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
536 globalwinon(ch);
537
f2cf8e25
AC
538 head = readw(&bc->tin) & (size - 1);
539 tail = readw(&bc->tout);
1da177e4 540
f2cf8e25
AC
541 if (tail != readw(&bc->tout))
542 tail = readw(&bc->tout);
1da177e4
LT
543 tail &= (size - 1);
544
ae0b78d0
AD
545 if (head >= tail) {
546 /* head has not wrapped */
547 /*
548 * remain (much like dataLen above) represents the total amount
549 * of space available on the card for data. Here dataLen
550 * represents the space existing between the head pointer and
551 * the end of buffer. This is important because a memcpy cannot
552 * be told to automatically wrap around when it hits the buffer
553 * end.
554 */
1da177e4
LT
555 dataLen = size - head;
556 remain = size - (head - tail) - 1;
ae0b78d0
AD
557 } else {
558 /* head has wrapped around */
1da177e4
LT
559 remain = tail - head - 1;
560 dataLen = remain;
ae0b78d0
AD
561 }
562 /*
563 * Check the space on the card. If we have more data than space; reduce
564 * the amount of data to fit the space.
565 */
1da177e4 566 bytesAvailable = min(remain, bytesAvailable);
1da177e4 567 txwinon(ch);
ae0b78d0
AD
568 while (bytesAvailable > 0) {
569 /* there is data to copy onto card */
1da177e4 570
ae0b78d0
AD
571 /*
572 * If head is not wrapped, the below will make sure the first
573 * data copy fills to the end of card buffer.
574 */
1da177e4 575 dataLen = min(bytesAvailable, dataLen);
bc9a5154 576 memcpy_toio(ch->txptr + head, buf, dataLen);
1da177e4
LT
577 buf += dataLen;
578 head += dataLen;
579 amountCopied += dataLen;
580 bytesAvailable -= dataLen;
581
f2cf8e25 582 if (head >= size) {
1da177e4
LT
583 head = 0;
584 dataLen = tail;
585 }
ae0b78d0 586 }
1da177e4
LT
587 ch->statusflags |= TXBUSY;
588 globalwinon(ch);
f2cf8e25 589 writew(head, &bc->tin);
1da177e4 590
f2cf8e25 591 if ((ch->statusflags & LOWWAIT) == 0) {
1da177e4 592 ch->statusflags |= LOWWAIT;
f2cf8e25 593 writeb(1, &bc->ilow);
1da177e4
LT
594 }
595 memoff(ch);
f2cf8e25 596 spin_unlock_irqrestore(&epca_lock, flags);
ae0b78d0
AD
597 return amountCopied;
598}
1da177e4 599
1da177e4 600static int pc_write_room(struct tty_struct *tty)
ae0b78d0 601{
191260a0 602 int remain = 0;
1da177e4
LT
603 struct channel *ch;
604 unsigned long flags;
605 unsigned int head, tail;
bc9a5154 606 struct board_chan __iomem *bc;
ae0b78d0
AD
607 /*
608 * verifyChannel returns the channel from the tty struct if it is
609 * valid. This serves as a sanity check.
610 */
191260a0
AC
611 ch = verifyChannel(tty);
612 if (ch != NULL) {
f2cf8e25 613 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
614 globalwinon(ch);
615
616 bc = ch->brdchan;
f2cf8e25
AC
617 head = readw(&bc->tin) & (ch->txbufsize - 1);
618 tail = readw(&bc->tout);
1da177e4 619
f2cf8e25
AC
620 if (tail != readw(&bc->tout))
621 tail = readw(&bc->tout);
1da177e4
LT
622 /* Wrap tail if necessary */
623 tail &= (ch->txbufsize - 1);
191260a0
AC
624 remain = tail - head - 1;
625 if (remain < 0)
1da177e4
LT
626 remain += ch->txbufsize;
627
f2cf8e25 628 if (remain && (ch->statusflags & LOWWAIT) == 0) {
1da177e4 629 ch->statusflags |= LOWWAIT;
f2cf8e25 630 writeb(1, &bc->ilow);
1da177e4
LT
631 }
632 memoff(ch);
f2cf8e25 633 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4 634 }
1da177e4
LT
635 /* Return how much room is left on card */
636 return remain;
ae0b78d0 637}
1da177e4
LT
638
639static int pc_chars_in_buffer(struct tty_struct *tty)
ae0b78d0 640{
1da177e4
LT
641 int chars;
642 unsigned int ctail, head, tail;
643 int remain;
644 unsigned long flags;
645 struct channel *ch;
bc9a5154 646 struct board_chan __iomem *bc;
ae0b78d0
AD
647 /*
648 * verifyChannel returns the channel from the tty struct if it is
649 * valid. This serves as a sanity check.
650 */
191260a0
AC
651 ch = verifyChannel(tty);
652 if (ch == NULL)
ae0b78d0 653 return 0;
1da177e4 654
f2cf8e25 655 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
656 globalwinon(ch);
657
658 bc = ch->brdchan;
f2cf8e25
AC
659 tail = readw(&bc->tout);
660 head = readw(&bc->tin);
661 ctail = readw(&ch->mailbox->cout);
1da177e4 662
191260a0
AC
663 if (tail == head && readw(&ch->mailbox->cin) == ctail &&
664 readb(&bc->tbusy) == 0)
1da177e4 665 chars = 0;
f2cf8e25
AC
666 else { /* Begin if some space on the card has been used */
667 head = readw(&bc->tin) & (ch->txbufsize - 1);
1da177e4 668 tail &= (ch->txbufsize - 1);
ae0b78d0
AD
669 /*
670 * The logic here is basically opposite of the above
671 * pc_write_room here we are finding the amount of bytes in the
672 * buffer filled. Not the amount of bytes empty.
673 */
191260a0
AC
674 remain = tail - head - 1;
675 if (remain < 0)
1da177e4 676 remain += ch->txbufsize;
1da177e4 677 chars = (int)(ch->txbufsize - remain);
ae0b78d0
AD
678 /*
679 * Make it possible to wakeup anything waiting for output in
680 * tty_ioctl.c, etc.
681 *
682 * If not already set. Setup an event to indicate when the
683 * transmit buffer empties.
684 */
1da177e4 685 if (!(ch->statusflags & EMPTYWAIT))
191260a0 686 setup_empty_event(tty, ch);
1da177e4 687 } /* End if some space on the card has been used */
1da177e4 688 memoff(ch);
f2cf8e25 689 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4 690 /* Return number of characters residing on card. */
ae0b78d0
AD
691 return chars;
692}
1da177e4
LT
693
694static void pc_flush_buffer(struct tty_struct *tty)
ae0b78d0 695{
1da177e4
LT
696 unsigned int tail;
697 unsigned long flags;
698 struct channel *ch;
bc9a5154 699 struct board_chan __iomem *bc;
ae0b78d0
AD
700 /*
701 * verifyChannel returns the channel from the tty struct if it is
702 * valid. This serves as a sanity check.
703 */
191260a0
AC
704 ch = verifyChannel(tty);
705 if (ch == NULL)
1da177e4
LT
706 return;
707
f2cf8e25 708 spin_lock_irqsave(&epca_lock, flags);
1da177e4 709 globalwinon(ch);
1da177e4 710 bc = ch->brdchan;
f2cf8e25 711 tail = readw(&bc->tout);
1da177e4 712 /* Have FEP move tout pointer; effectively flushing transmit buffer */
1da177e4 713 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
1da177e4 714 memoff(ch);
f2cf8e25 715 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4 716 tty_wakeup(tty);
ae0b78d0 717}
1da177e4
LT
718
719static void pc_flush_chars(struct tty_struct *tty)
ae0b78d0
AD
720{
721 struct channel *ch;
722 /*
723 * verifyChannel returns the channel from the tty struct if it is
724 * valid. This serves as a sanity check.
725 */
191260a0
AC
726 ch = verifyChannel(tty);
727 if (ch != NULL) {
1da177e4 728 unsigned long flags;
f2cf8e25 729 spin_lock_irqsave(&epca_lock, flags);
ae0b78d0
AD
730 /*
731 * If not already set and the transmitter is busy setup an
732 * event to indicate when the transmit empties.
733 */
191260a0
AC
734 if ((ch->statusflags & TXBUSY) &&
735 !(ch->statusflags & EMPTYWAIT))
736 setup_empty_event(tty, ch);
f2cf8e25 737 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4 738 }
ae0b78d0 739}
1da177e4 740
6ed1dbae 741static int epca_carrier_raised(struct tty_port *port)
ae0b78d0 742{
6ed1dbae
AC
743 struct channel *ch = container_of(port, struct channel, port);
744 if (ch->imodem & ch->dcd)
745 return 1;
1da177e4 746 return 0;
ae0b78d0 747}
1da177e4 748
fcc8ac18 749static void epca_dtr_rts(struct tty_port *port, int onoff)
6ed1dbae
AC
750{
751}
752
191260a0 753static int pc_open(struct tty_struct *tty, struct file *filp)
ae0b78d0 754{
1da177e4 755 struct channel *ch;
d1c815e5 756 struct tty_port *port;
1da177e4
LT
757 unsigned long flags;
758 int line, retval, boardnum;
bc9a5154 759 struct board_chan __iomem *bc;
f2cf8e25 760 unsigned int head;
1da177e4
LT
761
762 line = tty->index;
f2cf8e25
AC
763 if (line < 0 || line >= nbdevs)
764 return -ENODEV;
1da177e4
LT
765
766 ch = &digi_channels[line];
d1c815e5 767 port = &ch->port;
1da177e4
LT
768 boardnum = ch->boardnum;
769
770 /* Check status of board configured in system. */
771
ae0b78d0 772 /*
0211a9c8 773 * I check to see if the epca_setup routine detected a user error. It
ae0b78d0
AD
774 * might be better to put this in pc_init, but for the moment it goes
775 * here.
776 */
f2cf8e25 777 if (invalid_lilo_config) {
1da177e4 778 if (setup_error_code & INVALID_BOARD_TYPE)
f2cf8e25 779 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
1da177e4 780 if (setup_error_code & INVALID_NUM_PORTS)
f2cf8e25 781 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
1da177e4 782 if (setup_error_code & INVALID_MEM_BASE)
f2cf8e25 783 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
1da177e4 784 if (setup_error_code & INVALID_PORT_BASE)
f2cf8e25 785 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
1da177e4 786 if (setup_error_code & INVALID_BOARD_STATUS)
f2cf8e25 787 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
1da177e4 788 if (setup_error_code & INVALID_ALTPIN)
f2cf8e25 789 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
1da177e4 790 tty->driver_data = NULL; /* Mark this device as 'down' */
f2cf8e25 791 return -ENODEV;
1da177e4 792 }
f2cf8e25 793 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
1da177e4
LT
794 tty->driver_data = NULL; /* Mark this device as 'down' */
795 return(-ENODEV);
796 }
ae0b78d0 797
11fb09bf
HH
798 bc = ch->brdchan;
799 if (bc == NULL) {
1da177e4 800 tty->driver_data = NULL;
f2cf8e25 801 return -ENODEV;
1da177e4
LT
802 }
803
d1c815e5 804 spin_lock_irqsave(&port->lock, flags);
ae0b78d0
AD
805 /*
806 * Every time a channel is opened, increment a counter. This is
807 * necessary because we do not wish to flush and shutdown the channel
808 * until the last app holding the channel open, closes it.
809 */
d1c815e5 810 port->count++;
ae0b78d0
AD
811 /*
812 * Set a kernel structures pointer to our local channel structure. This
813 * way we can get to it when passed only a tty struct.
814 */
1da177e4 815 tty->driver_data = ch;
d1c815e5 816 port->tty = tty;
ae0b78d0
AD
817 /*
818 * If this is the first time the channel has been opened, initialize
819 * the tty->termios struct otherwise let pc_close handle it.
820 */
d1c815e5 821 spin_lock(&epca_lock);
1da177e4
LT
822 globalwinon(ch);
823 ch->statusflags = 0;
824
825 /* Save boards current modem status */
bc9a5154 826 ch->imodem = readb(&bc->mstat);
1da177e4 827
ae0b78d0
AD
828 /*
829 * Set receive head and tail ptrs to each other. This indicates no data
830 * available to read.
831 */
f2cf8e25
AC
832 head = readw(&bc->rin);
833 writew(head, &bc->rout);
1da177e4
LT
834
835 /* Set the channels associated tty structure */
1da177e4 836
ae0b78d0
AD
837 /*
838 * The below routine generally sets up parity, baud, flow control
839 * issues, etc.... It effect both control flags and input flags.
840 */
191260a0 841 epcaparam(tty, ch);
1da177e4 842 memoff(ch);
d1c815e5
AC
843 spin_unlock(&epca_lock);
844 port->flags |= ASYNC_INITIALIZED;
845 spin_unlock_irqrestore(&port->lock, flags);
1da177e4 846
6ed1dbae 847 retval = tty_port_block_til_ready(port, tty, filp);
1da177e4 848 if (retval)
1da177e4 849 return retval;
ae0b78d0
AD
850 /*
851 * Set this again in case a hangup set it to zero while this open() was
852 * waiting for the line...
853 */
d1c815e5
AC
854 spin_lock_irqsave(&port->lock, flags);
855 port->tty = tty;
856 spin_lock(&epca_lock);
1da177e4 857 globalwinon(ch);
1da177e4 858 /* Enable Digi Data events */
f2cf8e25 859 writeb(1, &bc->idata);
1da177e4 860 memoff(ch);
d1c815e5
AC
861 spin_unlock(&epca_lock);
862 spin_unlock_irqrestore(&port->lock, flags);
1da177e4 863 return 0;
ae0b78d0 864}
1da177e4 865
1da177e4 866static int __init epca_module_init(void)
ae0b78d0 867{
f2cf8e25 868 return pc_init();
1da177e4 869}
1da177e4 870module_init(epca_module_init);
1da177e4 871
1da177e4 872static struct pci_driver epca_driver;
1da177e4
LT
873
874static void __exit epca_module_exit(void)
875{
1da177e4
LT
876 int count, crd;
877 struct board_info *bd;
878 struct channel *ch;
1da177e4
LT
879
880 del_timer_sync(&epca_timer);
881
191260a0
AC
882 if (tty_unregister_driver(pc_driver) ||
883 tty_unregister_driver(pc_info)) {
f2cf8e25 884 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
1da177e4
LT
885 return;
886 }
887 put_tty_driver(pc_driver);
888 put_tty_driver(pc_info);
889
ae0b78d0 890 for (crd = 0; crd < num_cards; crd++) {
1da177e4 891 bd = &boards[crd];
ae0b78d0 892 if (!bd) { /* sanity check */
1da177e4
LT
893 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
894 return;
ae0b78d0 895 }
f2cf8e25 896 ch = card_ptr[crd];
ae0b78d0 897 for (count = 0; count < bd->numports; count++, ch++) {
3969ffba
AC
898 struct tty_struct *tty = tty_port_tty_get(&ch->port);
899 if (tty) {
900 tty_hangup(tty);
901 tty_kref_put(tty);
902 }
ae0b78d0
AD
903 }
904 }
905 pci_unregister_driver(&epca_driver);
1da177e4
LT
906}
907module_exit(epca_module_exit);
1da177e4 908
b68e31d0 909static const struct tty_operations pc_ops = {
1da177e4
LT
910 .open = pc_open,
911 .close = pc_close,
912 .write = pc_write,
913 .write_room = pc_write_room,
914 .flush_buffer = pc_flush_buffer,
915 .chars_in_buffer = pc_chars_in_buffer,
916 .flush_chars = pc_flush_chars,
1da177e4
LT
917 .ioctl = pc_ioctl,
918 .set_termios = pc_set_termios,
919 .stop = pc_stop,
920 .start = pc_start,
921 .throttle = pc_throttle,
922 .unthrottle = pc_unthrottle,
923 .hangup = pc_hangup,
dcbf1280 924 .break_ctl = pc_send_break
1da177e4
LT
925};
926
6ed1dbae
AC
927static const struct tty_port_operations epca_port_ops = {
928 .carrier_raised = epca_carrier_raised,
fcc8ac18 929 .dtr_rts = epca_dtr_rts,
6ed1dbae
AC
930};
931
191260a0 932static int info_open(struct tty_struct *tty, struct file *filp)
1da177e4
LT
933{
934 return 0;
935}
936
1cceefd3 937static const struct tty_operations info_ops = {
1da177e4
LT
938 .open = info_open,
939 .ioctl = info_ioctl,
940};
941
f2cf8e25 942static int __init pc_init(void)
ae0b78d0 943{
1da177e4
LT
944 int crd;
945 struct board_info *bd;
946 unsigned char board_id = 0;
dabad056 947 int err = -ENOMEM;
1da177e4 948
1da177e4
LT
949 int pci_boards_found, pci_count;
950
951 pci_count = 0;
1da177e4
LT
952
953 pc_driver = alloc_tty_driver(MAX_ALLOC);
954 if (!pc_driver)
dabad056 955 goto out1;
1da177e4
LT
956
957 pc_info = alloc_tty_driver(MAX_ALLOC);
dabad056
AM
958 if (!pc_info)
959 goto out2;
1da177e4 960
ae0b78d0
AD
961 /*
962 * If epca_setup has not been ran by LILO set num_cards to defaults;
963 * copy board structure defined by digiConfig into drivers board
964 * structure. Note : If LILO has ran epca_setup then epca_setup will
965 * handle defining num_cards as well as copying the data into the board
966 * structure.
967 */
968 if (!liloconfig) {
969 /* driver has been configured via. epcaconfig */
1da177e4
LT
970 nbdevs = NBDEVS;
971 num_cards = NUMCARDS;
ae0b78d0
AD
972 memcpy(&boards, &static_boards,
973 sizeof(struct board_info) * NUMCARDS);
974 }
1da177e4 975
ae0b78d0
AD
976 /*
977 * Note : If lilo was used to configure the driver and the ignore
978 * epcaconfig option was choosen (digiepca=2) then nbdevs and num_cards
979 * will equal 0 at this point. This is okay; PCI cards will still be
980 * picked up if detected.
981 */
1da177e4 982
ae0b78d0
AD
983 /*
984 * Set up interrupt, we will worry about memory allocation in
985 * post_fep_init.
986 */
191260a0 987 printk(KERN_INFO "DIGI epca driver version %s loaded.\n", VERSION);
1da177e4 988
ae0b78d0
AD
989 /*
990 * NOTE : This code assumes that the number of ports found in the
991 * boards array is correct. This could be wrong if the card in question
992 * is PCI (And therefore has no ports entry in the boards structure.)
993 * The rest of the information will be valid for PCI because the
994 * beginning of pc_init scans for PCI and determines i/o and base
995 * memory addresses. I am not sure if it is possible to read the number
996 * of ports supported by the card prior to it being booted (Since that
997 * is the state it is in when pc_init is run). Because it is not
998 * possible to query the number of supported ports until after the card
999 * has booted; we are required to calculate the card_ptrs as the card
1000 * is initialized (Inside post_fep_init). The negative thing about this
1001 * approach is that digiDload's call to GET_INFO will have a bad port
1002 * value. (Since this is called prior to post_fep_init.)
1003 */
1da177e4 1004 pci_boards_found = 0;
ae0b78d0 1005 if (num_cards < MAXBOARDS)
1da177e4
LT
1006 pci_boards_found += init_PCI();
1007 num_cards += pci_boards_found;
1008
1da177e4 1009 pc_driver->owner = THIS_MODULE;
ae0b78d0
AD
1010 pc_driver->name = "ttyD";
1011 pc_driver->major = DIGI_MAJOR;
1da177e4
LT
1012 pc_driver->minor_start = 0;
1013 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1014 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1015 pc_driver->init_termios = tty_std_termios;
1016 pc_driver->init_termios.c_iflag = 0;
1017 pc_driver->init_termios.c_oflag = 0;
1018 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1019 pc_driver->init_termios.c_lflag = 0;
606d099c
AC
1020 pc_driver->init_termios.c_ispeed = 9600;
1021 pc_driver->init_termios.c_ospeed = 9600;
dcbf1280 1022 pc_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK;
1da177e4
LT
1023 tty_set_operations(pc_driver, &pc_ops);
1024
1025 pc_info->owner = THIS_MODULE;
1026 pc_info->name = "digi_ctl";
1027 pc_info->major = DIGIINFOMAJOR;
1028 pc_info->minor_start = 0;
1029 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1030 pc_info->subtype = SERIAL_TYPE_INFO;
1031 pc_info->init_termios = tty_std_termios;
1032 pc_info->init_termios.c_iflag = 0;
1033 pc_info->init_termios.c_oflag = 0;
1034 pc_info->init_termios.c_lflag = 0;
1035 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
606d099c
AC
1036 pc_info->init_termios.c_ispeed = 9600;
1037 pc_info->init_termios.c_ospeed = 9600;
1da177e4
LT
1038 pc_info->flags = TTY_DRIVER_REAL_RAW;
1039 tty_set_operations(pc_info, &info_ops);
1040
1041
ae0b78d0
AD
1042 for (crd = 0; crd < num_cards; crd++) {
1043 /*
1044 * This is where the appropriate memory handlers for the
1045 * hardware is set. Everything at runtime blindly jumps through
1046 * these vectors.
1047 */
1da177e4
LT
1048
1049 /* defined in epcaconfig.h */
1050 bd = &boards[crd];
1051
ae0b78d0
AD
1052 switch (bd->type) {
1053 case PCXEM:
1054 case EISAXEM:
1055 bd->memwinon = pcxem_memwinon;
1056 bd->memwinoff = pcxem_memwinoff;
1057 bd->globalwinon = pcxem_globalwinon;
1058 bd->txwinon = pcxem_txwinon;
1059 bd->rxwinon = pcxem_rxwinon;
1060 bd->memoff = pcxem_memoff;
1061 bd->assertgwinon = dummy_assertgwinon;
1062 bd->assertmemoff = dummy_assertmemoff;
1da177e4
LT
1063 break;
1064
ae0b78d0
AD
1065 case PCIXEM:
1066 case PCIXRJ:
1067 case PCIXR:
1068 bd->memwinon = dummy_memwinon;
1069 bd->memwinoff = dummy_memwinoff;
1070 bd->globalwinon = dummy_globalwinon;
1071 bd->txwinon = dummy_txwinon;
1072 bd->rxwinon = dummy_rxwinon;
1073 bd->memoff = dummy_memoff;
1074 bd->assertgwinon = dummy_assertgwinon;
1075 bd->assertmemoff = dummy_assertmemoff;
1076 break;
1da177e4 1077
ae0b78d0
AD
1078 case PCXE:
1079 case PCXEVE:
1080 bd->memwinon = pcxe_memwinon;
1081 bd->memwinoff = pcxe_memwinoff;
1082 bd->globalwinon = pcxe_globalwinon;
1083 bd->txwinon = pcxe_txwinon;
1084 bd->rxwinon = pcxe_rxwinon;
1085 bd->memoff = pcxe_memoff;
1086 bd->assertgwinon = dummy_assertgwinon;
1087 bd->assertmemoff = dummy_assertmemoff;
1088 break;
1da177e4 1089
ae0b78d0
AD
1090 case PCXI:
1091 case PC64XE:
1092 bd->memwinon = pcxi_memwinon;
1093 bd->memwinoff = pcxi_memwinoff;
1094 bd->globalwinon = pcxi_globalwinon;
1095 bd->txwinon = pcxi_txwinon;
1096 bd->rxwinon = pcxi_rxwinon;
1097 bd->memoff = pcxi_memoff;
1098 bd->assertgwinon = pcxi_assertgwinon;
1099 bd->assertmemoff = pcxi_assertmemoff;
1100 break;
1da177e4 1101
ae0b78d0 1102 default:
1da177e4 1103 break;
ae0b78d0 1104 }
1da177e4 1105
ae0b78d0
AD
1106 /*
1107 * Some cards need a memory segment to be defined for use in
1108 * transmit and receive windowing operations. These boards are
1109 * listed in the below switch. In the case of the XI the amount
1110 * of memory on the board is variable so the memory_seg is also
1111 * variable. This code determines what they segment should be.
1112 */
1113 switch (bd->type) {
1114 case PCXE:
1115 case PCXEVE:
1116 case PC64XE:
1117 bd->memory_seg = 0xf000;
1118 break;
1da177e4 1119
ae0b78d0
AD
1120 case PCXI:
1121 board_id = inb((int)bd->port);
1122 if ((board_id & 0x1) == 0x1) {
1123 /* it's an XI card */
1124 /* Is it a 64K board */
1125 if ((board_id & 0x30) == 0)
1126 bd->memory_seg = 0xf000;
1127
1128 /* Is it a 128K board */
1129 if ((board_id & 0x30) == 0x10)
1130 bd->memory_seg = 0xe000;
1131
1132 /* Is is a 256K board */
1133 if ((board_id & 0x30) == 0x20)
1134 bd->memory_seg = 0xc000;
1135
1136 /* Is it a 512K board */
1137 if ((board_id & 0x30) == 0x30)
1138 bd->memory_seg = 0x8000;
1139 } else
191260a0 1140 printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n", (int)bd->port);
ae0b78d0
AD
1141 break;
1142 }
1143 }
1da177e4 1144
dabad056
AM
1145 err = tty_register_driver(pc_driver);
1146 if (err) {
1147 printk(KERN_ERR "Couldn't register Digi PC/ driver");
1148 goto out3;
1149 }
1da177e4 1150
dabad056
AM
1151 err = tty_register_driver(pc_info);
1152 if (err) {
1153 printk(KERN_ERR "Couldn't register Digi PC/ info ");
1154 goto out4;
1155 }
1da177e4 1156
ae0b78d0 1157 /* Start up the poller to check for events on all enabled boards */
1da177e4
LT
1158 init_timer(&epca_timer);
1159 epca_timer.function = epcapoll;
1160 mod_timer(&epca_timer, jiffies + HZ/25);
1da177e4
LT
1161 return 0;
1162
dabad056
AM
1163out4:
1164 tty_unregister_driver(pc_driver);
1165out3:
1166 put_tty_driver(pc_info);
1167out2:
1168 put_tty_driver(pc_driver);
1169out1:
1170 return err;
ae0b78d0 1171}
1da177e4
LT
1172
1173static void post_fep_init(unsigned int crd)
ae0b78d0 1174{
1da177e4 1175 int i;
bc9a5154
AV
1176 void __iomem *memaddr;
1177 struct global_data __iomem *gd;
1da177e4 1178 struct board_info *bd;
bc9a5154 1179 struct board_chan __iomem *bc;
ae0b78d0
AD
1180 struct channel *ch;
1181 int shrinkmem = 0, lowwater;
1da177e4 1182
ae0b78d0
AD
1183 /*
1184 * This call is made by the user via. the ioctl call DIGI_INIT. It is
1185 * responsible for setting up all the card specific stuff.
1186 */
1187 bd = &boards[crd];
1da177e4 1188
ae0b78d0
AD
1189 /*
1190 * If this is a PCI board, get the port info. Remember PCI cards do not
1191 * have entries into the epcaconfig.h file, so we can't get the number
1192 * of ports from it. Unfortunetly, this means that anyone doing a
1193 * DIGI_GETINFO before the board has booted will get an invalid number
1194 * of ports returned (It should return 0). Calls to DIGI_GETINFO after
1195 * DIGI_INIT has been called will return the proper values.
1196 */
f2cf8e25 1197 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
ae0b78d0
AD
1198 /*
1199 * Below we use XEMPORTS as a memory offset regardless of which
1200 * PCI card it is. This is because all of the supported PCI
1201 * cards have the same memory offset for the channel data. This
1202 * will have to be changed if we ever develop a PCI/XE card.
1203 * NOTE : The FEP manual states that the port offset is 0xC22
1204 * as opposed to 0xC02. This is only true for PC/XE, and PC/XI
1205 * cards; not for the XEM, or CX series. On the PCI cards the
1206 * number of ports is determined by reading a ID PROM located
1207 * in the box attached to the card. The card can then determine
1208 * the index the id to determine the number of ports available.
1209 * (FYI - The id should be located at 0x1ac (And may use up to
1210 * 4 bytes if the box in question is a XEM or CX)).
1211 */
f2cf8e25
AC
1212 /* PCI cards are already remapped at this point ISA are not */
1213 bd->numports = readw(bd->re_map_membase + XEMPORTS);
191260a0 1214 epcaassert(bd->numports <= 64, "PCI returned a invalid number of ports");
1da177e4 1215 nbdevs += (bd->numports);
f2cf8e25
AC
1216 } else {
1217 /* Fix up the mappings for ISA/EISA etc */
1218 /* FIXME: 64K - can we be smarter ? */
191260a0 1219 bd->re_map_membase = ioremap_nocache(bd->membase, 0x10000);
f2cf8e25 1220 }
1da177e4
LT
1221
1222 if (crd != 0)
1223 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1224 else
1225 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1226
1227 ch = card_ptr[crd];
1da177e4
LT
1228 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1229
f2cf8e25 1230 memaddr = bd->re_map_membase;
1da177e4 1231
ae0b78d0
AD
1232 /*
1233 * The below assignment will set bc to point at the BEGINING of the
1234 * cards channel structures. For 1 card there will be between 8 and 64
1235 * of these structures.
1236 */
bc9a5154 1237 bc = memaddr + CHANSTRUCT;
1da177e4 1238
ae0b78d0
AD
1239 /*
1240 * The below assignment will set gd to point at the BEGINING of global
1241 * memory address 0xc00. The first data in that global memory actually
1242 * starts at address 0xc1a. The command in pointer begins at 0xd10.
1243 */
bc9a5154 1244 gd = memaddr + GLOBAL;
1da177e4 1245
ae0b78d0
AD
1246 /*
1247 * XEPORTS (address 0xc22) points at the number of channels the card
1248 * supports. (For 64XE, XI, XEM, and XR use 0xc02)
1249 */
191260a0
AC
1250 if ((bd->type == PCXEVE || bd->type == PCXE) &&
1251 (readw(memaddr + XEPORTS) < 3))
1da177e4
LT
1252 shrinkmem = 1;
1253 if (bd->type < PCIXEM)
1254 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
ae0b78d0 1255 return;
1da177e4
LT
1256 memwinon(bd, 0);
1257
ae0b78d0
AD
1258 /*
1259 * Remember ch is the main drivers channels structure, while bc is the
1260 * cards channel structure.
1261 */
1262 for (i = 0; i < bd->numports; i++, ch++, bc++) {
f2cf8e25 1263 unsigned long flags;
bc9a5154 1264 u16 tseg, rseg;
1da177e4 1265
9ae7b08a 1266 tty_port_init(&ch->port);
c1314a49 1267 ch->port.ops = &epca_port_ops;
ae0b78d0
AD
1268 ch->brdchan = bc;
1269 ch->mailbox = gd;
c4028958 1270 INIT_WORK(&ch->tqueue, do_softint);
ae0b78d0 1271 ch->board = &boards[crd];
1da177e4 1272
f2cf8e25
AC
1273 spin_lock_irqsave(&epca_lock, flags);
1274 switch (bd->type) {
ae0b78d0
AD
1275 /*
1276 * Since some of the boards use different bitmaps for
1277 * their control signals we cannot hard code these
1278 * values and retain portability. We virtualize this
1279 * data here.
1280 */
1281 case EISAXEM:
1282 case PCXEM:
1283 case PCIXEM:
1284 case PCIXRJ:
1285 case PCIXR:
1286 ch->m_rts = 0x02;
1287 ch->m_dcd = 0x80;
1288 ch->m_dsr = 0x20;
1289 ch->m_cts = 0x10;
1290 ch->m_ri = 0x40;
1291 ch->m_dtr = 0x01;
1292 break;
1293
1294 case PCXE:
1295 case PCXEVE:
1296 case PCXI:
1297 case PC64XE:
1298 ch->m_rts = 0x02;
1299 ch->m_dcd = 0x08;
1300 ch->m_dsr = 0x10;
1301 ch->m_cts = 0x20;
1302 ch->m_ri = 0x40;
1303 ch->m_dtr = 0x80;
1304 break;
1305 }
1da177e4 1306
f2cf8e25 1307 if (boards[crd].altpin) {
1da177e4
LT
1308 ch->dsr = ch->m_dcd;
1309 ch->dcd = ch->m_dsr;
1310 ch->digiext.digi_flags |= DIGI_ALTPIN;
ae0b78d0 1311 } else {
1da177e4
LT
1312 ch->dcd = ch->m_dcd;
1313 ch->dsr = ch->m_dsr;
1314 }
ae0b78d0 1315
1da177e4
LT
1316 ch->boardnum = crd;
1317 ch->channelnum = i;
1318 ch->magic = EPCA_MAGIC;
3969ffba 1319 tty_port_tty_set(&ch->port, NULL);
1da177e4 1320
f2cf8e25 1321 if (shrinkmem) {
1da177e4
LT
1322 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1323 shrinkmem = 0;
1324 }
1325
bc9a5154
AV
1326 tseg = readw(&bc->tseg);
1327 rseg = readw(&bc->rseg);
1328
f2cf8e25 1329 switch (bd->type) {
ae0b78d0
AD
1330 case PCIXEM:
1331 case PCIXRJ:
1332 case PCIXR:
1333 /* Cover all the 2MEG cards */
1334 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1335 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1336 ch->txwin = FEPWIN | (tseg >> 11);
1337 ch->rxwin = FEPWIN | (rseg >> 11);
1338 break;
1339
1340 case PCXEM:
1341 case EISAXEM:
1342 /* Cover all the 32K windowed cards */
1343 /* Mask equal to window size - 1 */
1344 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1345 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1346 ch->txwin = FEPWIN | (tseg >> 11);
1347 ch->rxwin = FEPWIN | (rseg >> 11);
1348 break;
1da177e4 1349
ae0b78d0
AD
1350 case PCXEVE:
1351 case PCXE:
191260a0
AC
1352 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4)
1353 & 0x1fff);
ae0b78d0 1354 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
191260a0
AC
1355 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4)
1356 & 0x1fff);
1357 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >> 9);
ae0b78d0
AD
1358 break;
1359
1360 case PCXI:
1361 case PC64XE:
1362 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1363 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
1364 ch->txwin = ch->rxwin = 0;
1365 break;
1366 }
1da177e4
LT
1367
1368 ch->txbufhead = 0;
bc9a5154 1369 ch->txbufsize = readw(&bc->tmax) + 1;
ae0b78d0 1370
1da177e4 1371 ch->rxbufhead = 0;
bc9a5154 1372 ch->rxbufsize = readw(&bc->rmax) + 1;
ae0b78d0 1373
1da177e4
LT
1374 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1375
1376 /* Set transmitter low water mark */
1377 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1378
1379 /* Set receiver low water mark */
1da177e4
LT
1380 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
1381
1382 /* Set receiver high water mark */
1da177e4
LT
1383 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1384
f2cf8e25
AC
1385 writew(100, &bc->edelay);
1386 writeb(1, &bc->idata);
ae0b78d0 1387
f2cf8e25
AC
1388 ch->startc = readb(&bc->startc);
1389 ch->stopc = readb(&bc->stopc);
1390 ch->startca = readb(&bc->startca);
1391 ch->stopca = readb(&bc->stopca);
ae0b78d0 1392
1da177e4
LT
1393 ch->fepcflag = 0;
1394 ch->fepiflag = 0;
1395 ch->fepoflag = 0;
1396 ch->fepstartc = 0;
1397 ch->fepstopc = 0;
1398 ch->fepstartca = 0;
1399 ch->fepstopca = 0;
ae0b78d0 1400
6ed1dbae 1401 ch->port.close_delay = 50;
f2cf8e25
AC
1402
1403 spin_unlock_irqrestore(&epca_lock, flags);
ae0b78d0 1404 }
1da177e4 1405
ae0b78d0 1406 printk(KERN_INFO
191260a0
AC
1407 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1408 VERSION, board_desc[bd->type], (long)bd->port,
1409 (long)bd->membase, bd->numports);
1da177e4 1410 memwinoff(bd, 0);
ae0b78d0 1411}
1da177e4
LT
1412
1413static void epcapoll(unsigned long ignored)
ae0b78d0 1414{
1da177e4
LT
1415 unsigned long flags;
1416 int crd;
191260a0 1417 unsigned int head, tail;
1da177e4
LT
1418 struct channel *ch;
1419 struct board_info *bd;
1420
ae0b78d0
AD
1421 /*
1422 * This routine is called upon every timer interrupt. Even though the
1423 * Digi series cards are capable of generating interrupts this method
1424 * of non-looping polling is more efficient. This routine checks for
1425 * card generated events (Such as receive data, are transmit buffer
1426 * empty) and acts on those events.
1427 */
1428 for (crd = 0; crd < num_cards; crd++) {
1da177e4
LT
1429 bd = &boards[crd];
1430 ch = card_ptr[crd];
1431
1432 if ((bd->status == DISABLED) || digi_poller_inhibited)
ae0b78d0 1433 continue;
1da177e4 1434
ae0b78d0
AD
1435 /*
1436 * assertmemoff is not needed here; indeed it is an empty
1437 * subroutine. It is being kept because future boards may need
1438 * this as well as some legacy boards.
1439 */
f2cf8e25
AC
1440 spin_lock_irqsave(&epca_lock, flags);
1441
1da177e4
LT
1442 assertmemoff(ch);
1443
1444 globalwinon(ch);
1445
ae0b78d0
AD
1446 /*
1447 * In this case head and tail actually refer to the event queue
1448 * not the transmit or receive queue.
1449 */
f2cf8e25
AC
1450 head = readw(&ch->mailbox->ein);
1451 tail = readw(&ch->mailbox->eout);
1da177e4 1452
ae0b78d0 1453 /* If head isn't equal to tail we have an event */
1da177e4
LT
1454 if (head != tail)
1455 doevent(crd);
1da177e4
LT
1456 memoff(ch);
1457
f2cf8e25 1458 spin_unlock_irqrestore(&epca_lock, flags);
f2cf8e25 1459 } /* End for each card */
1da177e4 1460 mod_timer(&epca_timer, jiffies + (HZ / 25));
ae0b78d0 1461}
1da177e4
LT
1462
1463static void doevent(int crd)
ae0b78d0 1464{
bc9a5154 1465 void __iomem *eventbuf;
1da177e4
LT
1466 struct channel *ch, *chan0;
1467 static struct tty_struct *tty;
f2cf8e25 1468 struct board_info *bd;
bc9a5154 1469 struct board_chan __iomem *bc;
f2cf8e25
AC
1470 unsigned int tail, head;
1471 int event, channel;
1472 int mstat, lstat;
1da177e4 1473
ae0b78d0
AD
1474 /*
1475 * This subroutine is called by epcapoll when an event is detected
1476 * in the event queue. This routine responds to those events.
1477 */
1da177e4
LT
1478 bd = &boards[crd];
1479
1480 chan0 = card_ptr[crd];
1481 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
1da177e4 1482 assertgwinon(chan0);
191260a0
AC
1483 while ((tail = readw(&chan0->mailbox->eout)) !=
1484 (head = readw(&chan0->mailbox->ein))) {
1485 /* Begin while something in event queue */
1da177e4 1486 assertgwinon(chan0);
f2cf8e25 1487 eventbuf = bd->re_map_membase + tail + ISTART;
1da177e4 1488 /* Get the channel the event occurred on */
f2cf8e25 1489 channel = readb(eventbuf);
1da177e4 1490 /* Get the actual event code that occurred */
f2cf8e25 1491 event = readb(eventbuf + 1);
ae0b78d0
AD
1492 /*
1493 * The two assignments below get the current modem status
1494 * (mstat) and the previous modem status (lstat). These are
1495 * useful becuase an event could signal a change in modem
1496 * signals itself.
1497 */
f2cf8e25
AC
1498 mstat = readb(eventbuf + 2);
1499 lstat = readb(eventbuf + 3);
1da177e4
LT
1500
1501 ch = chan0 + channel;
f2cf8e25 1502 if ((unsigned)channel >= bd->numports || !ch) {
1da177e4
LT
1503 if (channel >= bd->numports)
1504 ch = chan0;
1505 bc = ch->brdchan;
1506 goto next;
1507 }
1508
191260a0
AC
1509 bc = ch->brdchan;
1510 if (bc == NULL)
1da177e4
LT
1511 goto next;
1512
3969ffba 1513 tty = tty_port_tty_get(&ch->port);
f2cf8e25 1514 if (event & DATA_IND) { /* Begin DATA_IND */
3969ffba 1515 receive_data(ch, tty);
1da177e4 1516 assertgwinon(ch);
1da177e4
LT
1517 } /* End DATA_IND */
1518 /* else *//* Fix for DCD transition missed bug */
ae0b78d0 1519 if (event & MODEMCHG_IND) {
1da177e4 1520 /* A modem signal change has been indicated */
1da177e4 1521 ch->imodem = mstat;
c3301a5c 1522 if (test_bit(ASYNCB_CHECK_CD, &ch->port.flags)) {
191260a0
AC
1523 /* We are now receiving dcd */
1524 if (mstat & ch->dcd)
52d41738 1525 wake_up_interruptible(&ch->port.open_wait);
191260a0
AC
1526 else /* No dcd; hangup */
1527 pc_sched_event(ch, EPCA_EVENT_HANGUP);
1da177e4 1528 }
ae0b78d0 1529 }
ae0b78d0
AD
1530 if (tty) {
1531 if (event & BREAK_IND) {
1da177e4 1532 /* A break has been indicated */
33f0f88f 1533 tty_insert_flip_char(tty, 0, TTY_BREAK);
ae0b78d0
AD
1534 tty_schedule_flip(tty);
1535 } else if (event & LOWTX_IND) {
1536 if (ch->statusflags & LOWWAIT) {
1da177e4
LT
1537 ch->statusflags &= ~LOWWAIT;
1538 tty_wakeup(tty);
ae0b78d0
AD
1539 }
1540 } else if (event & EMPTYTX_IND) {
191260a0
AC
1541 /* This event is generated by
1542 setup_empty_event */
1da177e4 1543 ch->statusflags &= ~TXBUSY;
ae0b78d0 1544 if (ch->statusflags & EMPTYWAIT) {
1da177e4
LT
1545 ch->statusflags &= ~EMPTYWAIT;
1546 tty_wakeup(tty);
ae0b78d0
AD
1547 }
1548 }
3969ffba 1549 tty_kref_put(tty);
ae0b78d0 1550 }
191260a0 1551next:
1da177e4 1552 globalwinon(ch);
f2cf8e25
AC
1553 BUG_ON(!bc);
1554 writew(1, &bc->idata);
1555 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
1da177e4 1556 globalwinon(chan0);
1da177e4 1557 } /* End while something in event queue */
ae0b78d0 1558}
1da177e4
LT
1559
1560static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
191260a0 1561 int byte2, int ncmds, int bytecmd)
ae0b78d0 1562{
bc9a5154 1563 unchar __iomem *memaddr;
1da177e4
LT
1564 unsigned int head, cmdTail, cmdStart, cmdMax;
1565 long count;
1566 int n;
1567
1568 /* This is the routine in which commands may be passed to the card. */
1569
1570 if (ch->board->status == DISABLED)
1da177e4 1571 return;
1da177e4 1572 assertgwinon(ch);
1da177e4 1573 /* Remember head (As well as max) is just an offset not a base addr */
f2cf8e25 1574 head = readw(&ch->mailbox->cin);
1da177e4 1575 /* cmdStart is a base address */
f2cf8e25 1576 cmdStart = readw(&ch->mailbox->cstart);
ae0b78d0
AD
1577 /*
1578 * We do the addition below because we do not want a max pointer
1579 * relative to cmdStart. We want a max pointer that points at the
1580 * physical end of the command queue.
1581 */
f2cf8e25 1582 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
1da177e4
LT
1583 memaddr = ch->board->re_map_membase;
1584
f2cf8e25 1585 if (head >= (cmdMax - cmdStart) || (head & 03)) {
191260a0
AC
1586 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n",
1587 __LINE__, cmd, head);
1588 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n",
1589 __LINE__, cmdMax, cmdStart);
1da177e4
LT
1590 return;
1591 }
f2cf8e25
AC
1592 if (bytecmd) {
1593 writeb(cmd, memaddr + head + cmdStart + 0);
1594 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1da177e4 1595 /* Below word_or_byte is bits to set */
f2cf8e25 1596 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1da177e4 1597 /* Below byte2 is bits to reset */
f2cf8e25
AC
1598 writeb(byte2, memaddr + head + cmdStart + 3);
1599 } else {
1600 writeb(cmd, memaddr + head + cmdStart + 0);
1601 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1602 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1da177e4 1603 }
1da177e4 1604 head = (head + 4) & (cmdMax - cmdStart - 4);
f2cf8e25 1605 writew(head, &ch->mailbox->cin);
1da177e4
LT
1606 count = FEPTIMEOUT;
1607
ae0b78d0 1608 for (;;) {
1da177e4 1609 count--;
f2cf8e25 1610 if (count == 0) {
1da177e4
LT
1611 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1612 return;
1613 }
f2cf8e25
AC
1614 head = readw(&ch->mailbox->cin);
1615 cmdTail = readw(&ch->mailbox->cout);
1da177e4 1616 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
ae0b78d0
AD
1617 /*
1618 * Basically this will break when the FEP acknowledges the
1619 * command by incrementing cmdTail (Making it equal to head).
1620 */
1da177e4 1621 if (n <= ncmds * (sizeof(short) * 4))
ae0b78d0
AD
1622 break;
1623 }
1624}
1da177e4 1625
ae0b78d0
AD
1626/*
1627 * Digi products use fields in their channels structures that are very similar
1628 * to the c_cflag and c_iflag fields typically found in UNIX termios
1629 * structures. The below three routines allow mappings between these hardware
1630 * "flags" and their respective Linux flags.
1631 */
1da177e4 1632static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
ae0b78d0 1633{
1da177e4
LT
1634 unsigned res = 0;
1635
f2cf8e25 1636 if (cflag & CRTSCTS) {
1da177e4
LT
1637 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1638 res |= ((ch->m_cts) | (ch->m_rts));
1639 }
1640
1641 if (ch->digiext.digi_flags & RTSPACE)
1642 res |= ch->m_rts;
1643
1644 if (ch->digiext.digi_flags & DTRPACE)
1645 res |= ch->m_dtr;
1646
1647 if (ch->digiext.digi_flags & CTSPACE)
1648 res |= ch->m_cts;
1649
1650 if (ch->digiext.digi_flags & DSRPACE)
1651 res |= ch->dsr;
1652
1653 if (ch->digiext.digi_flags & DCDPACE)
1654 res |= ch->dcd;
1655
1656 if (res & (ch->m_rts))
1657 ch->digiext.digi_flags |= RTSPACE;
1658
1659 if (res & (ch->m_cts))
1660 ch->digiext.digi_flags |= CTSPACE;
1661
1662 return res;
ae0b78d0 1663}
1da177e4 1664
1da177e4 1665static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
ae0b78d0
AD
1666{
1667 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
191260a0 1668 INPCK | ISTRIP | IXON | IXANY | IXOFF);
1da177e4
LT
1669 if (ch->digiext.digi_flags & DIGI_AIXON)
1670 res |= IAIXON;
1671 return res;
ae0b78d0 1672}
1da177e4
LT
1673
1674static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
ae0b78d0 1675{
1da177e4 1676 unsigned res = 0;
ae0b78d0 1677 if (cflag & CBAUDEX) {
1da177e4 1678 ch->digiext.digi_flags |= DIGI_FAST;
ae0b78d0
AD
1679 /*
1680 * HUPCL bit is used by FEP to indicate fast baud table is to
1681 * be used.
1682 */
1da177e4 1683 res |= FEP_HUPCL;
ae0b78d0
AD
1684 } else
1685 ch->digiext.digi_flags &= ~DIGI_FAST;
1686 /*
1687 * CBAUD has bit position 0x1000 set these days to indicate Linux
1688 * baud rate remap. Digi hardware can't handle the bit assignment.
1689 * (We use a different bit assignment for high speed.). Clear this
1690 * bit out.
1691 */
1da177e4 1692 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
ae0b78d0
AD
1693 /*
1694 * This gets a little confusing. The Digi cards have their own
8dfba4d7 1695 * representation of c_cflags controlling baud rate. For the most part
ae0b78d0
AD
1696 * this is identical to the Linux implementation. However; Digi
1697 * supports one rate (76800) that Linux doesn't. This means that the
1698 * c_cflag entry that would normally mean 76800 for Digi actually means
1699 * 115200 under Linux. Without the below mapping, a stty 115200 would
1700 * only drive the board at 76800. Since the rate 230400 is also found
1701 * after 76800, the same problem afflicts us when we choose a rate of
1702 * 230400. Without the below modificiation stty 230400 would actually
1703 * give us 115200.
1704 *
1705 * There are two additional differences. The Linux value for CLOCAL
1706 * (0x800; 0004000) has no meaning to the Digi hardware. Also in later
1707 * releases of Linux; the CBAUD define has CBAUDEX (0x1000; 0010000)
1708 * ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX should be
1709 * checked for a screened out prior to termios2digi_c returning. Since
1710 * CLOCAL isn't used by the board this can be ignored as long as the
1711 * returned value is used only by Digi hardware.
1712 */
f2cf8e25 1713 if (cflag & CBAUDEX) {
ae0b78d0
AD
1714 /*
1715 * The below code is trying to guarantee that only baud rates
1716 * 115200 and 230400 are remapped. We use exclusive or because
1717 * the various baud rates share common bit positions and
1718 * therefore can't be tested for easily.
1719 */
1720 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
1da177e4 1721 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
1da177e4 1722 res += 1;
1da177e4 1723 }
1da177e4 1724 return res;
ae0b78d0 1725}
1da177e4 1726
f2cf8e25 1727/* Caller must hold the locks */
1da177e4 1728static void epcaparam(struct tty_struct *tty, struct channel *ch)
ae0b78d0 1729{
1da177e4 1730 unsigned int cmdHead;
606d099c 1731 struct ktermios *ts;
bc9a5154 1732 struct board_chan __iomem *bc;
1da177e4
LT
1733 unsigned mval, hflow, cflag, iflag;
1734
1735 bc = ch->brdchan;
11fb09bf 1736 epcaassert(bc != NULL, "bc out of range");
1da177e4
LT
1737
1738 assertgwinon(ch);
1da177e4 1739 ts = tty->termios;
f2cf8e25
AC
1740 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
1741 cmdHead = readw(&bc->rin);
bc9a5154 1742 writew(cmdHead, &bc->rout);
f2cf8e25 1743 cmdHead = readw(&bc->tin);
1da177e4 1744 /* Changing baud in mid-stream transmission can be wonderful */
ae0b78d0
AD
1745 /*
1746 * Flush current transmit buffer by setting cmdTail pointer
1747 * (tout) to cmdHead pointer (tin). Hopefully the transmit
1748 * buffer is empty.
1749 */
1da177e4
LT
1750 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
1751 mval = 0;
ae0b78d0
AD
1752 } else { /* Begin CBAUD not detected */
1753 /*
1754 * c_cflags have changed but that change had nothing to do with
1755 * BAUD. Propagate the change to the card.
1756 */
1da177e4 1757 cflag = termios2digi_c(ch, ts->c_cflag);
f2cf8e25 1758 if (cflag != ch->fepcflag) {
1da177e4
LT
1759 ch->fepcflag = cflag;
1760 /* Set baud rate, char size, stop bits, parity */
1761 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
1762 }
ae0b78d0
AD
1763 /*
1764 * If the user has not forced CLOCAL and if the device is not a
1765 * CALLOUT device (Which is always CLOCAL) we set flags such
1766 * that the driver will wait on carrier detect.
1767 */
1da177e4 1768 if (ts->c_cflag & CLOCAL)
c3301a5c 1769 clear_bit(ASYNCB_CHECK_CD, &ch->port.flags);
1da177e4 1770 else
c3301a5c 1771 set_bit(ASYNCB_CHECK_CD, &ch->port.flags);
1da177e4 1772 mval = ch->m_dtr | ch->m_rts;
1da177e4 1773 } /* End CBAUD not detected */
1da177e4 1774 iflag = termios2digi_i(ch, ts->c_iflag);
1da177e4 1775 /* Check input mode flags */
f2cf8e25 1776 if (iflag != ch->fepiflag) {
1da177e4 1777 ch->fepiflag = iflag;
ae0b78d0
AD
1778 /*
1779 * Command sets channels iflag structure on the board. Such
1780 * things as input soft flow control, handling of parity
1781 * errors, and break handling are all set here.
191260a0
AC
1782 *
1783 * break handling, parity handling, input stripping,
1784 * flow control chars
ae0b78d0 1785 */
1da177e4
LT
1786 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
1787 }
ae0b78d0
AD
1788 /*
1789 * Set the board mint value for this channel. This will cause hardware
1790 * events to be generated each time the DCD signal (Described in mint)
1791 * changes.
1792 */
f2cf8e25 1793 writeb(ch->dcd, &bc->mint);
1da177e4
LT
1794 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
1795 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
f2cf8e25
AC
1796 writeb(0, &bc->mint);
1797 ch->imodem = readb(&bc->mstat);
1da177e4 1798 hflow = termios2digi_h(ch, ts->c_cflag);
f2cf8e25 1799 if (hflow != ch->hflow) {
1da177e4 1800 ch->hflow = hflow;
ae0b78d0
AD
1801 /*
1802 * Hard flow control has been selected but the board is not
1803 * using it. Activate hard flow control now.
1804 */
1da177e4
LT
1805 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
1806 }
1da177e4
LT
1807 mval ^= ch->modemfake & (mval ^ ch->modem);
1808
f2cf8e25 1809 if (ch->omodem ^ mval) {
1da177e4 1810 ch->omodem = mval;
ae0b78d0
AD
1811 /*
1812 * The below command sets the DTR and RTS mstat structure. If
1813 * hard flow control is NOT active these changes will drive the
1814 * output of the actual DTR and RTS lines. If hard flow control
1815 * is active, the changes will be saved in the mstat structure
1816 * and only asserted when hard flow control is turned off.
1817 */
1da177e4
LT
1818
1819 /* First reset DTR & RTS; then set them */
1820 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
1821 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
1da177e4 1822 }
f2cf8e25 1823 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
1da177e4
LT
1824 ch->fepstartc = ch->startc;
1825 ch->fepstopc = ch->stopc;
ae0b78d0
AD
1826 /*
1827 * The XON / XOFF characters have changed; propagate these
1828 * changes to the card.
1829 */
1da177e4
LT
1830 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
1831 }
f2cf8e25 1832 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
1da177e4
LT
1833 ch->fepstartca = ch->startca;
1834 ch->fepstopca = ch->stopca;
ae0b78d0
AD
1835 /*
1836 * Similar to the above, this time the auxilarly XON / XOFF
1837 * characters have changed; propagate these changes to the card.
1838 */
1da177e4
LT
1839 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
1840 }
ae0b78d0 1841}
1da177e4 1842
f2cf8e25 1843/* Caller holds lock */
3969ffba 1844static void receive_data(struct channel *ch, struct tty_struct *tty)
ae0b78d0 1845{
1da177e4 1846 unchar *rptr;
606d099c 1847 struct ktermios *ts = NULL;
bc9a5154 1848 struct board_chan __iomem *bc;
f2cf8e25
AC
1849 int dataToRead, wrapgap, bytesAvailable;
1850 unsigned int tail, head;
1da177e4 1851 unsigned int wrapmask;
1da177e4 1852
ae0b78d0
AD
1853 /*
1854 * This routine is called by doint when a receive data event has taken
1855 * place.
1856 */
1da177e4 1857 globalwinon(ch);
1da177e4
LT
1858 if (ch->statusflags & RXSTOPPED)
1859 return;
1da177e4
LT
1860 if (tty)
1861 ts = tty->termios;
1da177e4 1862 bc = ch->brdchan;
f2cf8e25 1863 BUG_ON(!bc);
1da177e4
LT
1864 wrapmask = ch->rxbufsize - 1;
1865
ae0b78d0
AD
1866 /*
1867 * Get the head and tail pointers to the receiver queue. Wrap the head
1868 * pointer if it has reached the end of the buffer.
1869 */
f2cf8e25 1870 head = readw(&bc->rin);
1da177e4 1871 head &= wrapmask;
f2cf8e25 1872 tail = readw(&bc->rout) & wrapmask;
1da177e4
LT
1873
1874 bytesAvailable = (head - tail) & wrapmask;
1da177e4
LT
1875 if (bytesAvailable == 0)
1876 return;
1877
ae0b78d0 1878 /* If CREAD bit is off or device not open, set TX tail to head */
191260a0 1879 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
bc9a5154 1880 writew(head, &bc->rout);
1da177e4
LT
1881 return;
1882 }
1883
33f0f88f 1884 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
1da177e4
LT
1885 return;
1886
f2cf8e25
AC
1887 if (readb(&bc->orun)) {
1888 writeb(0, &bc->orun);
191260a0
AC
1889 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",
1890 tty->name);
33f0f88f 1891 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
1da177e4 1892 }
1da177e4 1893 rxwinon(ch);
191260a0
AC
1894 while (bytesAvailable > 0) {
1895 /* Begin while there is data on the card */
1da177e4 1896 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
ae0b78d0
AD
1897 /*
1898 * Even if head has wrapped around only report the amount of
1899 * data to be equal to the size - tail. Remember memcpy can't
1900 * automaticly wrap around the receive buffer.
1901 */
191260a0
AC
1902 dataToRead = (wrapgap < bytesAvailable) ? wrapgap
1903 : bytesAvailable;
ae0b78d0 1904 /* Make sure we don't overflow the buffer */
33f0f88f 1905 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
1da177e4
LT
1906 if (dataToRead == 0)
1907 break;
ae0b78d0
AD
1908 /*
1909 * Move data read from our card into the line disciplines
1910 * buffer for translation if necessary.
1911 */
f2cf8e25 1912 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
1da177e4
LT
1913 tail = (tail + dataToRead) & wrapmask;
1914 bytesAvailable -= dataToRead;
1da177e4 1915 } /* End while there is data on the card */
1da177e4 1916 globalwinon(ch);
f2cf8e25 1917 writew(tail, &bc->rout);
1da177e4 1918 /* Must be called with global data */
3969ffba 1919 tty_schedule_flip(tty);
ae0b78d0 1920}
1da177e4 1921
ae0b78d0 1922static int info_ioctl(struct tty_struct *tty, struct file *file,
1da177e4
LT
1923 unsigned int cmd, unsigned long arg)
1924{
ae0b78d0
AD
1925 switch (cmd) {
1926 case DIGI_GETINFO:
1927 {
1928 struct digi_info di;
1da177e4
LT
1929 int brd;
1930
ae0b78d0 1931 if (get_user(brd, (unsigned int __user *)arg))
f2cf8e25
AC
1932 return -EFAULT;
1933 if (brd < 0 || brd >= num_cards || num_cards == 0)
1934 return -ENODEV;
1da177e4
LT
1935
1936 memset(&di, 0, sizeof(di));
1937
ae0b78d0 1938 di.board = brd;
1da177e4
LT
1939 di.status = boards[brd].status;
1940 di.type = boards[brd].type ;
1941 di.numports = boards[brd].numports ;
f2cf8e25
AC
1942 /* Legacy fixups - just move along nothing to see */
1943 di.port = (unsigned char *)boards[brd].port ;
1944 di.membase = (unsigned char *)boards[brd].membase ;
1da177e4 1945
ae0b78d0 1946 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
1da177e4
LT
1947 return -EFAULT;
1948 break;
1949
ae0b78d0 1950 }
1da177e4 1951
ae0b78d0
AD
1952 case DIGI_POLLER:
1953 {
1954 int brd = arg & 0xff000000 >> 16;
1955 unsigned char state = arg & 0xff;
1da177e4 1956
f2cf8e25
AC
1957 if (brd < 0 || brd >= num_cards) {
1958 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
ae0b78d0 1959 return -ENODEV;
1da177e4 1960 }
ae0b78d0
AD
1961 digi_poller_inhibited = state;
1962 break;
1963 }
1964
1965 case DIGI_INIT:
1966 {
1967 /*
1968 * This call is made by the apps to complete the
8dfba4d7 1969 * initialization of the board(s). This routine is
ae0b78d0
AD
1970 * responsible for setting the card to its initial
1971 * state and setting the drivers control fields to the
1972 * sutianle settings for the card in question.
1973 */
1974 int crd;
1975 for (crd = 0; crd < num_cards; crd++)
1976 post_fep_init(crd);
1977 break;
1978 }
1979 default:
1980 return -ENOTTY;
1981 }
1982 return 0;
1da177e4 1983}
1da177e4
LT
1984
1985static int pc_tiocmget(struct tty_struct *tty, struct file *file)
1986{
c9f19e96 1987 struct channel *ch = tty->driver_data;
bc9a5154 1988 struct board_chan __iomem *bc;
1da177e4
LT
1989 unsigned int mstat, mflag = 0;
1990 unsigned long flags;
1991
1992 if (ch)
1993 bc = ch->brdchan;
1994 else
f2cf8e25 1995 return -EINVAL;
1da177e4 1996
f2cf8e25 1997 spin_lock_irqsave(&epca_lock, flags);
1da177e4 1998 globalwinon(ch);
f2cf8e25 1999 mstat = readb(&bc->mstat);
1da177e4 2000 memoff(ch);
f2cf8e25 2001 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
2002
2003 if (mstat & ch->m_dtr)
2004 mflag |= TIOCM_DTR;
1da177e4
LT
2005 if (mstat & ch->m_rts)
2006 mflag |= TIOCM_RTS;
1da177e4
LT
2007 if (mstat & ch->m_cts)
2008 mflag |= TIOCM_CTS;
1da177e4
LT
2009 if (mstat & ch->dsr)
2010 mflag |= TIOCM_DSR;
1da177e4
LT
2011 if (mstat & ch->m_ri)
2012 mflag |= TIOCM_RI;
1da177e4
LT
2013 if (mstat & ch->dcd)
2014 mflag |= TIOCM_CD;
1da177e4
LT
2015 return mflag;
2016}
2017
2018static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2019 unsigned int set, unsigned int clear)
2020{
c9f19e96 2021 struct channel *ch = tty->driver_data;
1da177e4
LT
2022 unsigned long flags;
2023
f2cf8e25
AC
2024 if (!ch)
2025 return -EINVAL;
1da177e4 2026
f2cf8e25 2027 spin_lock_irqsave(&epca_lock, flags);
1da177e4 2028 /*
ae0b78d0
AD
2029 * I think this modemfake stuff is broken. It doesn't correctly reflect
2030 * the behaviour desired by the TIOCM* ioctls. Therefore this is
2031 * probably broken.
1da177e4
LT
2032 */
2033 if (set & TIOCM_RTS) {
2034 ch->modemfake |= ch->m_rts;
2035 ch->modem |= ch->m_rts;
2036 }
2037 if (set & TIOCM_DTR) {
2038 ch->modemfake |= ch->m_dtr;
2039 ch->modem |= ch->m_dtr;
2040 }
2041 if (clear & TIOCM_RTS) {
2042 ch->modemfake |= ch->m_rts;
2043 ch->modem &= ~ch->m_rts;
2044 }
2045 if (clear & TIOCM_DTR) {
2046 ch->modemfake |= ch->m_dtr;
2047 ch->modem &= ~ch->m_dtr;
2048 }
1da177e4 2049 globalwinon(ch);
ae0b78d0
AD
2050 /*
2051 * The below routine generally sets up parity, baud, flow control
2052 * issues, etc.... It effect both control flags and input flags.
2053 */
191260a0 2054 epcaparam(tty, ch);
1da177e4 2055 memoff(ch);
f2cf8e25 2056 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
2057 return 0;
2058}
2059
191260a0
AC
2060static int pc_ioctl(struct tty_struct *tty, struct file *file,
2061 unsigned int cmd, unsigned long arg)
ae0b78d0 2062{
1da177e4 2063 digiflow_t dflow;
1da177e4
LT
2064 unsigned long flags;
2065 unsigned int mflag, mstat;
2066 unsigned char startc, stopc;
bc9a5154 2067 struct board_chan __iomem *bc;
c9f19e96 2068 struct channel *ch = tty->driver_data;
1da177e4 2069 void __user *argp = (void __user *)arg;
ae0b78d0 2070
1da177e4
LT
2071 if (ch)
2072 bc = ch->brdchan;
ae0b78d0 2073 else
f2cf8e25 2074 return -EINVAL;
ae0b78d0 2075 switch (cmd) {
ae0b78d0
AD
2076 case TIOCMODG:
2077 mflag = pc_tiocmget(tty, file);
2078 if (put_user(mflag, (unsigned long __user *)argp))
2079 return -EFAULT;
2080 break;
2081 case TIOCMODS:
2082 if (get_user(mstat, (unsigned __user *)argp))
2083 return -EFAULT;
2084 return pc_tiocmset(tty, file, mstat, ~mstat);
2085 case TIOCSDTR:
2086 spin_lock_irqsave(&epca_lock, flags);
2087 ch->omodem |= ch->m_dtr;
2088 globalwinon(ch);
2089 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2090 memoff(ch);
2091 spin_unlock_irqrestore(&epca_lock, flags);
2092 break;
1da177e4 2093
ae0b78d0
AD
2094 case TIOCCDTR:
2095 spin_lock_irqsave(&epca_lock, flags);
2096 ch->omodem &= ~ch->m_dtr;
2097 globalwinon(ch);
2098 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2099 memoff(ch);
2100 spin_unlock_irqrestore(&epca_lock, flags);
2101 break;
2102 case DIGI_GETA:
2103 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2104 return -EFAULT;
2105 break;
2106 case DIGI_SETAW:
2107 case DIGI_SETAF:
2108 if (cmd == DIGI_SETAW) {
191260a0
AC
2109 /* Setup an event to indicate when the transmit
2110 buffer empties */
f2cf8e25 2111 spin_lock_irqsave(&epca_lock, flags);
191260a0 2112 setup_empty_event(tty, ch);
f2cf8e25 2113 spin_unlock_irqrestore(&epca_lock, flags);
ae0b78d0
AD
2114 tty_wait_until_sent(tty, 0);
2115 } else {
2116 /* ldisc lock already held in ioctl */
c65c9bc3
AC
2117 if (tty->ldisc->ops->flush_buffer)
2118 tty->ldisc->ops->flush_buffer(tty);
ae0b78d0
AD
2119 }
2120 /* Fall Thru */
2121 case DIGI_SETA:
2122 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2123 return -EFAULT;
2124
2125 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
2126 ch->dcd = ch->m_dsr;
2127 ch->dsr = ch->m_dcd;
2128 } else {
2129 ch->dcd = ch->m_dcd;
2130 ch->dsr = ch->m_dsr;
1da177e4 2131 }
1da177e4 2132
ae0b78d0
AD
2133 spin_lock_irqsave(&epca_lock, flags);
2134 globalwinon(ch);
1da177e4 2135
ae0b78d0
AD
2136 /*
2137 * The below routine generally sets up parity, baud, flow
2138 * control issues, etc.... It effect both control flags and
2139 * input flags.
2140 */
191260a0 2141 epcaparam(tty, ch);
ae0b78d0
AD
2142 memoff(ch);
2143 spin_unlock_irqrestore(&epca_lock, flags);
2144 break;
2145
2146 case DIGI_GETFLOW:
2147 case DIGI_GETAFLOW:
2148 spin_lock_irqsave(&epca_lock, flags);
2149 globalwinon(ch);
2150 if (cmd == DIGI_GETFLOW) {
2151 dflow.startc = readb(&bc->startc);
2152 dflow.stopc = readb(&bc->stopc);
2153 } else {
2154 dflow.startc = readb(&bc->startca);
2155 dflow.stopc = readb(&bc->stopca);
2156 }
2157 memoff(ch);
2158 spin_unlock_irqrestore(&epca_lock, flags);
2159
2160 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2161 return -EFAULT;
2162 break;
2163
2164 case DIGI_SETAFLOW:
2165 case DIGI_SETFLOW:
2166 if (cmd == DIGI_SETFLOW) {
2167 startc = ch->startc;
2168 stopc = ch->stopc;
2169 } else {
2170 startc = ch->startca;
2171 stopc = ch->stopca;
2172 }
1da177e4 2173
ae0b78d0
AD
2174 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2175 return -EFAULT;
2176
191260a0
AC
2177 if (dflow.startc != startc || dflow.stopc != stopc) {
2178 /* Begin if setflow toggled */
f2cf8e25 2179 spin_lock_irqsave(&epca_lock, flags);
1da177e4 2180 globalwinon(ch);
1da177e4 2181
f2cf8e25 2182 if (cmd == DIGI_SETFLOW) {
ae0b78d0
AD
2183 ch->fepstartc = ch->startc = dflow.startc;
2184 ch->fepstopc = ch->stopc = dflow.stopc;
191260a0
AC
2185 fepcmd(ch, SONOFFC, ch->fepstartc,
2186 ch->fepstopc, 0, 1);
f2cf8e25 2187 } else {
ae0b78d0
AD
2188 ch->fepstartca = ch->startca = dflow.startc;
2189 ch->fepstopca = ch->stopca = dflow.stopc;
191260a0
AC
2190 fepcmd(ch, SAUXONOFFC, ch->fepstartca,
2191 ch->fepstopca, 0, 1);
1da177e4
LT
2192 }
2193
ae0b78d0
AD
2194 if (ch->statusflags & TXSTOPPED)
2195 pc_start(tty);
1da177e4 2196
ae0b78d0
AD
2197 memoff(ch);
2198 spin_unlock_irqrestore(&epca_lock, flags);
2199 } /* End if setflow toggled */
2200 break;
2201 default:
2202 return -ENOIOCTLCMD;
2203 }
1da177e4 2204 return 0;
ae0b78d0 2205}
1da177e4 2206
606d099c 2207static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
ae0b78d0 2208{
1da177e4
LT
2209 struct channel *ch;
2210 unsigned long flags;
ae0b78d0
AD
2211 /*
2212 * verifyChannel returns the channel from the tty struct if it is
2213 * valid. This serves as a sanity check.
2214 */
191260a0
AC
2215 ch = verifyChannel(tty);
2216
2217 if (ch != NULL) { /* Begin if channel valid */
f2cf8e25 2218 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
2219 globalwinon(ch);
2220 epcaparam(tty, ch);
2221 memoff(ch);
f2cf8e25 2222 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
2223
2224 if ((old_termios->c_cflag & CRTSCTS) &&
2225 ((tty->termios->c_cflag & CRTSCTS) == 0))
2226 tty->hw_stopped = 0;
2227
2228 if (!(old_termios->c_cflag & CLOCAL) &&
2229 (tty->termios->c_cflag & CLOCAL))
52d41738 2230 wake_up_interruptible(&ch->port.open_wait);
1da177e4 2231
1da177e4 2232 } /* End if channel valid */
ae0b78d0 2233}
1da177e4 2234
c4028958 2235static void do_softint(struct work_struct *work)
ae0b78d0 2236{
c4028958 2237 struct channel *ch = container_of(work, struct channel, tqueue);
1da177e4 2238 /* Called in response to a modem change event */
ae0b78d0 2239 if (ch && ch->magic == EPCA_MAGIC) {
a419aef8 2240 struct tty_struct *tty = tty_port_tty_get(&ch->port);
1da177e4 2241
f2cf8e25 2242 if (tty && tty->driver_data) {
ae0b78d0 2243 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) {
191260a0 2244 tty_hangup(tty);
52d41738 2245 wake_up_interruptible(&ch->port.open_wait);
c3301a5c
JS
2246 clear_bit(ASYNCB_NORMAL_ACTIVE,
2247 &ch->port.flags);
ae0b78d0 2248 }
1da177e4 2249 }
3969ffba 2250 tty_kref_put(tty);
ae0b78d0
AD
2251 }
2252}
1da177e4 2253
ae0b78d0
AD
2254/*
2255 * pc_stop and pc_start provide software flow control to the routine and the
2256 * pc_ioctl routine.
2257 */
1da177e4 2258static void pc_stop(struct tty_struct *tty)
ae0b78d0 2259{
1da177e4
LT
2260 struct channel *ch;
2261 unsigned long flags;
ae0b78d0
AD
2262 /*
2263 * verifyChannel returns the channel from the tty struct if it is
2264 * valid. This serves as a sanity check.
2265 */
191260a0
AC
2266 ch = verifyChannel(tty);
2267 if (ch != NULL) {
f2cf8e25 2268 spin_lock_irqsave(&epca_lock, flags);
191260a0
AC
2269 if ((ch->statusflags & TXSTOPPED) == 0) {
2270 /* Begin if transmit stop requested */
1da177e4 2271 globalwinon(ch);
1da177e4 2272 /* STOP transmitting now !! */
1da177e4 2273 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
1da177e4
LT
2274 ch->statusflags |= TXSTOPPED;
2275 memoff(ch);
1da177e4 2276 } /* End if transmit stop requested */
f2cf8e25 2277 spin_unlock_irqrestore(&epca_lock, flags);
ae0b78d0
AD
2278 }
2279}
1da177e4
LT
2280
2281static void pc_start(struct tty_struct *tty)
ae0b78d0 2282{
1da177e4 2283 struct channel *ch;
ae0b78d0
AD
2284 /*
2285 * verifyChannel returns the channel from the tty struct if it is
2286 * valid. This serves as a sanity check.
2287 */
191260a0
AC
2288 ch = verifyChannel(tty);
2289 if (ch != NULL) {
1da177e4 2290 unsigned long flags;
f2cf8e25 2291 spin_lock_irqsave(&epca_lock, flags);
191260a0
AC
2292 /* Just in case output was resumed because of a change
2293 in Digi-flow */
2294 if (ch->statusflags & TXSTOPPED) {
2295 /* Begin transmit resume requested */
bc9a5154 2296 struct board_chan __iomem *bc;
1da177e4
LT
2297 globalwinon(ch);
2298 bc = ch->brdchan;
2299 if (ch->statusflags & LOWWAIT)
f2cf8e25 2300 writeb(1, &bc->ilow);
1da177e4 2301 /* Okay, you can start transmitting again... */
1da177e4 2302 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
1da177e4
LT
2303 ch->statusflags &= ~TXSTOPPED;
2304 memoff(ch);
1da177e4 2305 } /* End transmit resume requested */
f2cf8e25 2306 spin_unlock_irqrestore(&epca_lock, flags);
ae0b78d0
AD
2307 }
2308}
2309
2310/*
2311 * The below routines pc_throttle and pc_unthrottle are used to slow (And
2312 * resume) the receipt of data into the kernels receive buffers. The exact
2313 * occurrence of this depends on the size of the kernels receive buffer and
2314 * what the 'watermarks' are set to for that buffer. See the n_ttys.c file for
2315 * more details.
2316 */
2317static void pc_throttle(struct tty_struct *tty)
2318{
1da177e4
LT
2319 struct channel *ch;
2320 unsigned long flags;
ae0b78d0
AD
2321 /*
2322 * verifyChannel returns the channel from the tty struct if it is
2323 * valid. This serves as a sanity check.
2324 */
191260a0
AC
2325 ch = verifyChannel(tty);
2326 if (ch != NULL) {
f2cf8e25
AC
2327 spin_lock_irqsave(&epca_lock, flags);
2328 if ((ch->statusflags & RXSTOPPED) == 0) {
1da177e4
LT
2329 globalwinon(ch);
2330 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
1da177e4
LT
2331 ch->statusflags |= RXSTOPPED;
2332 memoff(ch);
2333 }
f2cf8e25 2334 spin_unlock_irqrestore(&epca_lock, flags);
ae0b78d0
AD
2335 }
2336}
1da177e4
LT
2337
2338static void pc_unthrottle(struct tty_struct *tty)
ae0b78d0 2339{
1da177e4
LT
2340 struct channel *ch;
2341 unsigned long flags;
ae0b78d0
AD
2342 /*
2343 * verifyChannel returns the channel from the tty struct if it is
2344 * valid. This serves as a sanity check.
2345 */
191260a0
AC
2346 ch = verifyChannel(tty);
2347 if (ch != NULL) {
2348 /* Just in case output was resumed because of a change
2349 in Digi-flow */
f2cf8e25
AC
2350 spin_lock_irqsave(&epca_lock, flags);
2351 if (ch->statusflags & RXSTOPPED) {
1da177e4 2352 globalwinon(ch);
1da177e4 2353 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
1da177e4
LT
2354 ch->statusflags &= ~RXSTOPPED;
2355 memoff(ch);
2356 }
f2cf8e25 2357 spin_unlock_irqrestore(&epca_lock, flags);
ae0b78d0
AD
2358 }
2359}
1da177e4 2360
dcbf1280 2361static int pc_send_break(struct tty_struct *tty, int msec)
ae0b78d0 2362{
c9f19e96 2363 struct channel *ch = tty->driver_data;
1da177e4
LT
2364 unsigned long flags;
2365
dcbf1280 2366 if (msec == -1)
252883e5
AC
2367 msec = 0xFFFF;
2368 else if (msec > 0xFFFE)
2369 msec = 0xFFFE;
2370 else if (msec < 1)
2371 msec = 1;
dcbf1280 2372
f2cf8e25 2373 spin_lock_irqsave(&epca_lock, flags);
1da177e4 2374 globalwinon(ch);
ae0b78d0
AD
2375 /*
2376 * Maybe I should send an infinite break here, schedule() for msec
2377 * amount of time, and then stop the break. This way, the user can't
2378 * screw up the FEP by causing digi_send_break() to be called (i.e. via
2379 * an ioctl()) more than once in msec amount of time.
2380 * Try this for now...
2381 */
1da177e4
LT
2382 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2383 memoff(ch);
f2cf8e25 2384 spin_unlock_irqrestore(&epca_lock, flags);
dcbf1280 2385 return 0;
ae0b78d0 2386}
1da177e4 2387
f2cf8e25 2388/* Caller MUST hold the lock */
1da177e4 2389static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
ae0b78d0 2390{
bc9a5154 2391 struct board_chan __iomem *bc = ch->brdchan;
1da177e4 2392
1da177e4
LT
2393 globalwinon(ch);
2394 ch->statusflags |= EMPTYWAIT;
ae0b78d0
AD
2395 /*
2396 * When set the iempty flag request a event to be generated when the
2397 * transmit buffer is empty (If there is no BREAK in progress).
2398 */
f2cf8e25 2399 writeb(1, &bc->iempty);
1da177e4 2400 memoff(ch);
ae0b78d0 2401}
1da177e4 2402
88e88249
DH
2403#ifndef MODULE
2404static void __init epca_setup(char *str, int *ints)
ae0b78d0 2405{
1da177e4
LT
2406 struct board_info board;
2407 int index, loop, last;
2408 char *temp, *t2;
2409 unsigned len;
2410
ae0b78d0
AD
2411 /*
2412 * If this routine looks a little strange it is because it is only
2413 * called if a LILO append command is given to boot the kernel with
2414 * parameters. In this way, we can provide the user a method of
2415 * changing his board configuration without rebuilding the kernel.
2416 */
2417 if (!liloconfig)
2418 liloconfig = 1;
1da177e4
LT
2419
2420 memset(&board, 0, sizeof(board));
2421
2422 /* Assume the data is int first, later we can change it */
2423 /* I think that array position 0 of ints holds the number of args */
2424 for (last = 0, index = 1; index <= ints[0]; index++)
ae0b78d0
AD
2425 switch (index) { /* Begin parse switch */
2426 case 1:
2427 board.status = ints[index];
2428 /*
2429 * We check for 2 (As opposed to 1; because 2 is a flag
2430 * instructing the driver to ignore epcaconfig.) For
2431 * this reason we check for 2.
2432 */
191260a0
AC
2433 if (board.status == 2) {
2434 /* Begin ignore epcaconfig as well as lilo cmd line */
ae0b78d0
AD
2435 nbdevs = 0;
2436 num_cards = 0;
2437 return;
2438 } /* End ignore epcaconfig as well as lilo cmd line */
2439
2440 if (board.status > 2) {
191260a0
AC
2441 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n",
2442 board.status);
ae0b78d0
AD
2443 invalid_lilo_config = 1;
2444 setup_error_code |= INVALID_BOARD_STATUS;
2445 return;
2446 }
2447 last = index;
2448 break;
2449 case 2:
2450 board.type = ints[index];
2451 if (board.type >= PCIXEM) {
2452 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
2453 invalid_lilo_config = 1;
2454 setup_error_code |= INVALID_BOARD_TYPE;
2455 return;
2456 }
2457 last = index;
2458 break;
2459 case 3:
2460 board.altpin = ints[index];
2461 if (board.altpin > 1) {
2462 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
2463 invalid_lilo_config = 1;
2464 setup_error_code |= INVALID_ALTPIN;
2465 return;
2466 }
2467 last = index;
2468 break;
2469
2470 case 4:
2471 board.numports = ints[index];
2472 if (board.numports < 2 || board.numports > 256) {
2473 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
2474 invalid_lilo_config = 1;
2475 setup_error_code |= INVALID_NUM_PORTS;
2476 return;
2477 }
2478 nbdevs += board.numports;
2479 last = index;
2480 break;
1da177e4 2481
ae0b78d0
AD
2482 case 5:
2483 board.port = ints[index];
2484 if (ints[index] <= 0) {
2485 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
2486 invalid_lilo_config = 1;
2487 setup_error_code |= INVALID_PORT_BASE;
1da177e4 2488 return;
ae0b78d0
AD
2489 }
2490 last = index;
2491 break;
2492
2493 case 6:
2494 board.membase = ints[index];
2495 if (ints[index] <= 0) {
191260a0
AC
2496 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",
2497 (unsigned int)board.membase);
ae0b78d0
AD
2498 invalid_lilo_config = 1;
2499 setup_error_code |= INVALID_MEM_BASE;
2500 return;
2501 }
2502 last = index;
2503 break;
2504
2505 default:
2506 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
2507 return;
1da177e4
LT
2508
2509 } /* End parse switch */
2510
f2cf8e25 2511 while (str && *str) { /* Begin while there is a string arg */
1da177e4
LT
2512 /* find the next comma or terminator */
2513 temp = str;
1da177e4
LT
2514 /* While string is not null, and a comma hasn't been found */
2515 while (*temp && (*temp != ','))
2516 temp++;
1da177e4
LT
2517 if (!*temp)
2518 temp = NULL;
2519 else
2520 *temp++ = 0;
1da177e4
LT
2521 /* Set index to the number of args + 1 */
2522 index = last + 1;
2523
ae0b78d0
AD
2524 switch (index) {
2525 case 1:
2526 len = strlen(str);
2527 if (strncmp("Disable", str, len) == 0)
2528 board.status = 0;
2529 else if (strncmp("Enable", str, len) == 0)
2530 board.status = 1;
2531 else {
2532 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
2533 invalid_lilo_config = 1;
2534 setup_error_code |= INVALID_BOARD_STATUS;
2535 return;
2536 }
2537 last = index;
2538 break;
1da177e4 2539
ae0b78d0
AD
2540 case 2:
2541 for (loop = 0; loop < EPCA_NUM_TYPES; loop++)
2542 if (strcmp(board_desc[loop], str) == 0)
2543 break;
2544 /*
2545 * If the index incremented above refers to a
2546 * legitamate board type set it here.
2547 */
2548 if (index < EPCA_NUM_TYPES)
2549 board.type = loop;
2550 else {
2551 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
2552 invalid_lilo_config = 1;
2553 setup_error_code |= INVALID_BOARD_TYPE;
2554 return;
2555 }
2556 last = index;
2557 break;
2558
2559 case 3:
2560 len = strlen(str);
2561 if (strncmp("Disable", str, len) == 0)
2562 board.altpin = 0;
2563 else if (strncmp("Enable", str, len) == 0)
2564 board.altpin = 1;
2565 else {
2566 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
2567 invalid_lilo_config = 1;
2568 setup_error_code |= INVALID_ALTPIN;
2569 return;
2570 }
2571 last = index;
2572 break;
1da177e4 2573
ae0b78d0
AD
2574 case 4:
2575 t2 = str;
2576 while (isdigit(*t2))
2577 t2++;
1da177e4 2578
ae0b78d0
AD
2579 if (*t2) {
2580 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
2581 invalid_lilo_config = 1;
2582 setup_error_code |= INVALID_NUM_PORTS;
2583 return;
2584 }
1da177e4 2585
ae0b78d0
AD
2586 /*
2587 * There is not a man page for simple_strtoul but the
2588 * code can be found in vsprintf.c. The first argument
2589 * is the string to translate (To an unsigned long
2590 * obviously), the second argument can be the address
2591 * of any character variable or a NULL. If a variable
2592 * is given, the end pointer of the string will be
2593 * stored in that variable; if a NULL is given the end
2594 * pointer will not be returned. The last argument is
2595 * the base to use. If a 0 is indicated, the routine
2596 * will attempt to determine the proper base by looking
2597 * at the values prefix (A '0' for octal, a 'x' for
2598 * hex, etc ... If a value is given it will use that
2599 * value as the base.
2600 */
2601 board.numports = simple_strtoul(str, NULL, 0);
2602 nbdevs += board.numports;
2603 last = index;
2604 break;
2605
2606 case 5:
2607 t2 = str;
2608 while (isxdigit(*t2))
2609 t2++;
2610
2611 if (*t2) {
2612 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
2613 invalid_lilo_config = 1;
2614 setup_error_code |= INVALID_PORT_BASE;
2615 return;
2616 }
2617
2618 board.port = simple_strtoul(str, NULL, 16);
2619 last = index;
2620 break;
2621
2622 case 6:
2623 t2 = str;
2624 while (isxdigit(*t2))
2625 t2++;
2626
2627 if (*t2) {
191260a0 2628 printk(KERN_ERR "epca_setup: Invalid memory base %s\n", str);
ae0b78d0
AD
2629 invalid_lilo_config = 1;
2630 setup_error_code |= INVALID_MEM_BASE;
1da177e4 2631 return;
ae0b78d0
AD
2632 }
2633 board.membase = simple_strtoul(str, NULL, 16);
2634 last = index;
2635 break;
2636 default:
2637 printk(KERN_ERR "epca: Too many string parms\n");
2638 return;
1da177e4
LT
2639 }
2640 str = temp;
1da177e4
LT
2641 } /* End while there is a string arg */
2642
f2cf8e25
AC
2643 if (last < 6) {
2644 printk(KERN_ERR "epca: Insufficient parms specified\n");
1da177e4
LT
2645 return;
2646 }
ae0b78d0 2647
1da177e4 2648 /* I should REALLY validate the stuff here */
1da177e4 2649 /* Copies our local copy of board into boards */
191260a0 2650 memcpy((void *)&boards[num_cards], (void *)&board, sizeof(board));
1da177e4 2651 /* Does this get called once per lilo arg are what ? */
ae0b78d0
AD
2652 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2653 num_cards, board_desc[board.type],
1da177e4 2654 board.numports, (int)board.port, (unsigned int) board.membase);
1da177e4 2655 num_cards++;
ae0b78d0 2656}
1da177e4 2657
88e88249
DH
2658static int __init epca_real_setup(char *str)
2659{
2660 int ints[11];
2661
2662 epca_setup(get_options(str, 11, ints), ints);
2663 return 1;
2664}
2665
2666__setup("digiepca", epca_real_setup);
2667#endif
2668
1da177e4
LT
2669enum epic_board_types {
2670 brd_xr = 0,
2671 brd_xem,
2672 brd_cx,
2673 brd_xrj,
2674};
2675
1da177e4
LT
2676/* indexed directly by epic_board_types enum */
2677static struct {
2678 unsigned char board_type;
2679 unsigned bar_idx; /* PCI base address region */
2680} epca_info_tbl[] = {
2681 { PCIXR, 0, },
2682 { PCIXEM, 0, },
2683 { PCICX, 0, },
2684 { PCIXRJ, 2, },
2685};
2686
ae0b78d0 2687static int __devinit epca_init_one(struct pci_dev *pdev,
1da177e4
LT
2688 const struct pci_device_id *ent)
2689{
2690 static int board_num = -1;
2691 int board_idx, info_idx = ent->driver_data;
2692 unsigned long addr;
2693
2694 if (pci_enable_device(pdev))
2695 return -EIO;
2696
2697 board_num++;
2698 board_idx = board_num + num_cards;
2699 if (board_idx >= MAXBOARDS)
2700 goto err_out;
ae0b78d0 2701
191260a0 2702 addr = pci_resource_start(pdev, epca_info_tbl[info_idx].bar_idx);
1da177e4 2703 if (!addr) {
191260a0 2704 printk(KERN_ERR PFX "PCI region #%d not available (size 0)\n",
1da177e4
LT
2705 epca_info_tbl[info_idx].bar_idx);
2706 goto err_out;
2707 }
2708
2709 boards[board_idx].status = ENABLED;
2710 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
2711 boards[board_idx].numports = 0x0;
f2cf8e25
AC
2712 boards[board_idx].port = addr + PCI_IO_OFFSET;
2713 boards[board_idx].membase = addr;
1da177e4 2714
191260a0
AC
2715 if (!request_mem_region(addr + PCI_IO_OFFSET, 0x200000, "epca")) {
2716 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
1da177e4
LT
2717 0x200000, addr + PCI_IO_OFFSET);
2718 goto err_out;
2719 }
2720
191260a0
AC
2721 boards[board_idx].re_map_port = ioremap_nocache(addr + PCI_IO_OFFSET,
2722 0x200000);
1da177e4 2723 if (!boards[board_idx].re_map_port) {
191260a0 2724 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
1da177e4
LT
2725 0x200000, addr + PCI_IO_OFFSET);
2726 goto err_out_free_pciio;
2727 }
2728
191260a0
AC
2729 if (!request_mem_region(addr, 0x200000, "epca")) {
2730 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
1da177e4
LT
2731 0x200000, addr);
2732 goto err_out_free_iounmap;
2733 }
2734
191260a0 2735 boards[board_idx].re_map_membase = ioremap_nocache(addr, 0x200000);
1da177e4 2736 if (!boards[board_idx].re_map_membase) {
191260a0 2737 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
1da177e4
LT
2738 0x200000, addr + PCI_IO_OFFSET);
2739 goto err_out_free_memregion;
2740 }
2741
ae0b78d0
AD
2742 /*
2743 * I don't know what the below does, but the hardware guys say its
2744 * required on everything except PLX (In this case XRJ).
2745 */
1da177e4 2746 if (info_idx != brd_xrj) {
ae0b78d0 2747 pci_write_config_byte(pdev, 0x40, 0);
1da177e4
LT
2748 pci_write_config_byte(pdev, 0x46, 0);
2749 }
ae0b78d0 2750
1da177e4
LT
2751 return 0;
2752
2753err_out_free_memregion:
191260a0 2754 release_mem_region(addr, 0x200000);
1da177e4 2755err_out_free_iounmap:
191260a0 2756 iounmap(boards[board_idx].re_map_port);
1da177e4 2757err_out_free_pciio:
191260a0 2758 release_mem_region(addr + PCI_IO_OFFSET, 0x200000);
1da177e4
LT
2759err_out:
2760 return -ENODEV;
2761}
2762
2763
2764static struct pci_device_id epca_pci_tbl[] = {
2765 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
2766 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
2767 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
2768 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
2769 { 0, }
2770};
2771
2772MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
2773
11fb09bf 2774static int __init init_PCI(void)
ae0b78d0 2775{
191260a0 2776 memset(&epca_driver, 0, sizeof(epca_driver));
1da177e4
LT
2777 epca_driver.name = "epca";
2778 epca_driver.id_table = epca_pci_tbl;
2779 epca_driver.probe = epca_init_one;
2780
2781 return pci_register_driver(&epca_driver);
f2cf8e25 2782}
1da177e4
LT
2783
2784MODULE_LICENSE("GPL");