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