blob: 37d4dca5a5d4d4572685d1a885c13159ab2941e6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 Copyright (C) 1996 Digi International.
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07003
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 For technical support please email digiLinux@dgii.com or
5 call Digi tech support at (612) 912-3456
6
Alan Coxf2cf8e22005-09-06 15:16:44 -07007 ** This driver is no longer supported by Digi **
8
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07009 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -070013 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -070018 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -070023 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*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070027/* See README.epca for change history --DAT*/
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/module.h>
30#include <linux/kernel.h>
31#include <linux/types.h>
32#include <linux/init.h>
33#include <linux/serial.h>
34#include <linux/delay.h>
35#include <linux/ctype.h>
36#include <linux/tty.h>
37#include <linux/tty_flip.h>
38#include <linux/slab.h>
39#include <linux/ioport.h>
40#include <linux/interrupt.h>
41#include <asm/uaccess.h>
42#include <asm/io.h>
Alan Coxf2cf8e22005-09-06 15:16:44 -070043#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/pci.h>
45#include "digiPCI.h"
Alan Coxf2cf8e22005-09-06 15:16:44 -070046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48#include "digi1.h"
49#include "digiFep1.h"
50#include "epca.h"
51#include "epcaconfig.h"
52
Alan Coxf2cf8e22005-09-06 15:16:44 -070053#define VERSION "1.3.0.1-LK2.6"
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/* This major needs to be submitted to Linux to join the majors list */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -070056#define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58
59#define MAXCARDS 7
60#define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
61
62#define PFX "epca: "
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static int nbdevs, num_cards, liloconfig;
65static int digi_poller_inhibited = 1 ;
66
67static int setup_error_code;
68static int invalid_lilo_config;
69
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -070070/*
71 * The ISA boards do window flipping into the same spaces so its only sane with
72 * a single lock. It's still pretty efficient.
73 */
Ingo Molnar34af9462006-06-27 02:53:55 -070074static DEFINE_SPINLOCK(epca_lock);
Alan Coxf2cf8e22005-09-06 15:16:44 -070075
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -070076/* MAXBOARDS is typically 12, but ISA and EISA cards are restricted to 7 below. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070077static struct board_info boards[MAXBOARDS];
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079static struct tty_driver *pc_driver;
80static struct tty_driver *pc_info;
81
82/* ------------------ Begin Digi specific structures -------------------- */
83
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -070084/*
85 * digi_channels represents an array of structures that keep track of each
86 * channel of the Digi product. Information such as transmit and receive
87 * pointers, termio data, and signal definitions (DTR, CTS, etc ...) are stored
88 * here. This structure is NOT used to overlay the cards physical channel
89 * structure.
90 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091static struct channel digi_channels[MAX_ALLOC];
92
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -070093/*
94 * card_ptr is an array used to hold the address of the first channel structure
95 * of each card. This array will hold the addresses of various channels located
96 * in digi_channels.
97 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070098static struct channel *card_ptr[MAXCARDS];
99
100static struct timer_list epca_timer;
101
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700102/*
103 * Begin generic memory functions. These functions will be alias (point at)
104 * more specific functions dependent on the board being configured.
105 */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700106static void memwinon(struct board_info *b, unsigned int win);
107static void memwinoff(struct board_info *b, unsigned int win);
108static void globalwinon(struct channel *ch);
109static void rxwinon(struct channel *ch);
110static void txwinon(struct channel *ch);
111static void memoff(struct channel *ch);
112static void assertgwinon(struct channel *ch);
113static void assertmemoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115/* ---- Begin more 'specific' memory functions for cx_like products --- */
116
Alan Coxf2cf8e22005-09-06 15:16:44 -0700117static void pcxem_memwinon(struct board_info *b, unsigned int win);
118static void pcxem_memwinoff(struct board_info *b, unsigned int win);
119static void pcxem_globalwinon(struct channel *ch);
120static void pcxem_rxwinon(struct channel *ch);
121static void pcxem_txwinon(struct channel *ch);
122static void pcxem_memoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124/* ------ Begin more 'specific' memory functions for the pcxe ------- */
125
Alan Coxf2cf8e22005-09-06 15:16:44 -0700126static void pcxe_memwinon(struct board_info *b, unsigned int win);
127static void pcxe_memwinoff(struct board_info *b, unsigned int win);
128static void pcxe_globalwinon(struct channel *ch);
129static void pcxe_rxwinon(struct channel *ch);
130static void pcxe_txwinon(struct channel *ch);
131static void pcxe_memoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133/* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
134/* Note : pc64xe and pcxi share the same windowing routines */
135
Alan Coxf2cf8e22005-09-06 15:16:44 -0700136static void pcxi_memwinon(struct board_info *b, unsigned int win);
137static void pcxi_memwinoff(struct board_info *b, unsigned int win);
138static void pcxi_globalwinon(struct channel *ch);
139static void pcxi_rxwinon(struct channel *ch);
140static void pcxi_txwinon(struct channel *ch);
141static void pcxi_memoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143/* - Begin 'specific' do nothing memory functions needed for some cards - */
144
Alan Coxf2cf8e22005-09-06 15:16:44 -0700145static void dummy_memwinon(struct board_info *b, unsigned int win);
146static void dummy_memwinoff(struct board_info *b, unsigned int win);
147static void dummy_globalwinon(struct channel *ch);
148static void dummy_rxwinon(struct channel *ch);
149static void dummy_txwinon(struct channel *ch);
150static void dummy_memoff(struct channel *ch);
151static void dummy_assertgwinon(struct channel *ch);
152static void dummy_assertmemoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Alan Coxf2cf8e22005-09-06 15:16:44 -0700154static struct channel *verifyChannel(struct tty_struct *);
155static void pc_sched_event(struct channel *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156static void epca_error(int, char *);
157static void pc_close(struct tty_struct *, struct file *);
158static void shutdown(struct channel *);
159static void pc_hangup(struct tty_struct *);
160static void pc_put_char(struct tty_struct *, unsigned char);
161static int pc_write_room(struct tty_struct *);
162static int pc_chars_in_buffer(struct tty_struct *);
163static void pc_flush_buffer(struct tty_struct *);
164static void pc_flush_chars(struct tty_struct *);
165static int block_til_ready(struct tty_struct *, struct file *,
166 struct channel *);
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 *);
176static void receive_data(struct channel *);
177static int pc_ioctl(struct tty_struct *, struct file *,
178 unsigned int, unsigned long);
179static int info_ioctl(struct tty_struct *, struct file *,
180 unsigned int, unsigned long);
Alan Cox606d0992006-12-08 02:38:45 -0800181static void pc_set_termios(struct tty_struct *, struct ktermios *);
David Howellsc4028952006-11-22 14:57:56 +0000182static void do_softint(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183static void pc_stop(struct tty_struct *);
184static void pc_start(struct tty_struct *);
185static void pc_throttle(struct tty_struct * tty);
186static void pc_unthrottle(struct tty_struct *tty);
187static void digi_send_break(struct channel *ch, int msec);
188static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
189void epca_setup(char *, int *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191static int pc_write(struct tty_struct *, const unsigned char *, int);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700192static int pc_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193static int init_PCI(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700195/*
196 * Table of functions for each board to handle memory. Mantaining parallelism
197 * is a *very* good idea here. The idea is for the runtime code to blindly call
198 * these functions, not knowing/caring about the underlying hardware. This
199 * stuff should contain no conditionals; if more functionality is needed a
200 * different entry should be established. These calls are the interface calls
201 * and are the only functions that should be accessed. Anyone caught making
202 * direct calls deserves what they get.
203 */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700204static void memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700206 b->memwinon(b, win);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
208
Alan Coxf2cf8e22005-09-06 15:16:44 -0700209static void memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700211 b->memwinoff(b, win);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212}
213
Alan Coxf2cf8e22005-09-06 15:16:44 -0700214static void globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700216 ch->board->globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217}
218
Alan Coxf2cf8e22005-09-06 15:16:44 -0700219static void rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700221 ch->board->rxwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222}
223
Alan Coxf2cf8e22005-09-06 15:16:44 -0700224static void txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700226 ch->board->txwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
Alan Coxf2cf8e22005-09-06 15:16:44 -0700229static void memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700231 ch->board->memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
Alan Coxf2cf8e22005-09-06 15:16:44 -0700233static void assertgwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700235 ch->board->assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
237
Alan Coxf2cf8e22005-09-06 15:16:44 -0700238static void assertmemoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700240 ch->board->assertmemoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241}
242
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700243/* PCXEM windowing is the same as that used in the PCXR and CX series cards. */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700244static void pcxem_memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700246 outb_p(FEPWIN|win, b->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247}
248
Alan Coxf2cf8e22005-09-06 15:16:44 -0700249static void pcxem_memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700251 outb_p(0, b->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252}
253
Alan Coxf2cf8e22005-09-06 15:16:44 -0700254static void pcxem_globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
256 outb_p( FEPWIN, (int)ch->board->port + 1);
257}
258
Alan Coxf2cf8e22005-09-06 15:16:44 -0700259static void pcxem_rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
261 outb_p(ch->rxwin, (int)ch->board->port + 1);
262}
263
Alan Coxf2cf8e22005-09-06 15:16:44 -0700264static void pcxem_txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
266 outb_p(ch->txwin, (int)ch->board->port + 1);
267}
268
Alan Coxf2cf8e22005-09-06 15:16:44 -0700269static void pcxem_memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
271 outb_p(0, (int)ch->board->port + 1);
272}
273
274/* ----------------- Begin pcxe memory window stuff ------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700275static void pcxe_memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700277 outb_p(FEPWIN | win, b->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278}
279
Alan Coxf2cf8e22005-09-06 15:16:44 -0700280static void pcxe_memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700282 outb_p(inb(b->port) & ~FEPMEM, b->port + 1);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700283 outb_p(0, b->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284}
285
Alan Coxf2cf8e22005-09-06 15:16:44 -0700286static void pcxe_globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700288 outb_p(FEPWIN, (int)ch->board->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289}
290
Alan Coxf2cf8e22005-09-06 15:16:44 -0700291static void pcxe_rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700293 outb_p(ch->rxwin, (int)ch->board->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294}
295
Alan Coxf2cf8e22005-09-06 15:16:44 -0700296static void pcxe_txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700298 outb_p(ch->txwin, (int)ch->board->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299}
300
Alan Coxf2cf8e22005-09-06 15:16:44 -0700301static void pcxe_memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
303 outb_p(0, (int)ch->board->port);
304 outb_p(0, (int)ch->board->port + 1);
305}
306
307/* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700308static void pcxi_memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700310 outb_p(inb(b->port) | FEPMEM, b->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
312
Alan Coxf2cf8e22005-09-06 15:16:44 -0700313static void pcxi_memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700315 outb_p(inb(b->port) & ~FEPMEM, b->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316}
317
Alan Coxf2cf8e22005-09-06 15:16:44 -0700318static void pcxi_globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700320 outb_p(FEPMEM, ch->board->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321}
322
Alan Coxf2cf8e22005-09-06 15:16:44 -0700323static void pcxi_rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700325 outb_p(FEPMEM, ch->board->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326}
327
Alan Coxf2cf8e22005-09-06 15:16:44 -0700328static void pcxi_txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700330 outb_p(FEPMEM, ch->board->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331}
332
Alan Coxf2cf8e22005-09-06 15:16:44 -0700333static void pcxi_memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700335 outb_p(0, ch->board->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}
337
Alan Coxf2cf8e22005-09-06 15:16:44 -0700338static void pcxi_assertgwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700340 epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341}
342
Alan Coxf2cf8e22005-09-06 15:16:44 -0700343static void pcxi_assertmemoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700345 epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346}
347
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700348/*
349 * Not all of the cards need specific memory windowing routines. Some cards
350 * (Such as PCI) needs no windowing routines at all. We provide these do
351 * nothing routines so that the same code base can be used. The driver will
352 * ALWAYS call a windowing routine if it thinks it needs to; regardless of the
353 * card. However, dependent on the card the routine may or may not do anything.
354 */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700355static void dummy_memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
357}
358
Alan Coxf2cf8e22005-09-06 15:16:44 -0700359static void dummy_memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
361}
362
Alan Coxf2cf8e22005-09-06 15:16:44 -0700363static void dummy_globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
365}
366
Alan Coxf2cf8e22005-09-06 15:16:44 -0700367static void dummy_rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
369}
370
Alan Coxf2cf8e22005-09-06 15:16:44 -0700371static void dummy_txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372{
373}
374
Alan Coxf2cf8e22005-09-06 15:16:44 -0700375static void dummy_memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376{
377}
378
Alan Coxf2cf8e22005-09-06 15:16:44 -0700379static void dummy_assertgwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
381}
382
Alan Coxf2cf8e22005-09-06 15:16:44 -0700383static void dummy_assertmemoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
385}
386
Alan Coxf2cf8e22005-09-06 15:16:44 -0700387static struct channel *verifyChannel(struct tty_struct *tty)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700388{
389 /*
390 * This routine basically provides a sanity check. It insures that the
391 * channel returned is within the proper range of addresses as well as
392 * properly initialized. If some bogus info gets passed in
393 * through tty->driver_data this should catch it.
394 */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700395 if (tty) {
396 struct channel *ch = (struct channel *)tty->driver_data;
397 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 if (ch->magic == EPCA_MAGIC)
399 return ch;
400 }
Alan Coxf2cf8e22005-09-06 15:16:44 -0700401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 return NULL;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700403}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Alan Coxf2cf8e22005-09-06 15:16:44 -0700405static void pc_sched_event(struct channel *ch, int event)
406{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700407 /*
408 * We call this to schedule interrupt processing on some event. The
409 * kernel sees our request and calls the related routine in OUR driver.
410 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 ch->event |= 1 << event;
412 schedule_work(&ch->tqueue);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700413}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415static void epca_error(int line, char *msg)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700416{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700418}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700420static void pc_close(struct tty_struct *tty, struct file *filp)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700421{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 struct channel *ch;
423 unsigned long flags;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700424 /*
425 * verifyChannel returns the channel from the tty struct if it is
426 * valid. This serves as a sanity check.
427 */
428 if ((ch = verifyChannel(tty)) != NULL) {
Alan Coxf2cf8e22005-09-06 15:16:44 -0700429 spin_lock_irqsave(&epca_lock, flags);
430 if (tty_hung_up_p(filp)) {
431 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 return;
433 }
Alan Coxf2cf8e22005-09-06 15:16:44 -0700434 if (ch->count-- > 1) {
435 /* Begin channel is open more than once */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700436 /*
437 * Return without doing anything. Someone might still
438 * be using the channel.
439 */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700440 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 return;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700442 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444 /* Port open only once go ahead with shutdown & reset */
Eric Sesterhenn56ee4822006-03-26 18:17:21 +0200445 BUG_ON(ch->count < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700447 /*
448 * Let the rest of the driver know the channel is being closed.
449 * This becomes important if an open is attempted before close
450 * is finished.
451 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 ch->asyncflags |= ASYNC_CLOSING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 tty->closing = 1;
454
Alan Coxf2cf8e22005-09-06 15:16:44 -0700455 spin_unlock_irqrestore(&epca_lock, flags);
456
457 if (ch->asyncflags & ASYNC_INITIALIZED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 /* Setup an event to indicate when the transmit buffer empties */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700459 setup_empty_event(tty, ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
461 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 if (tty->driver->flush_buffer)
463 tty->driver->flush_buffer(tty);
464
465 tty_ldisc_flush(tty);
466 shutdown(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700467
468 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 tty->closing = 0;
470 ch->event = 0;
471 ch->tty = NULL;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700472 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700474 if (ch->blocked_open) {
475 if (ch->close_delay)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 wake_up_interruptible(&ch->open_wait);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700478 }
479 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 ASYNC_CLOSING);
481 wake_up_interruptible(&ch->close_wait);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700482 }
483}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485static void shutdown(struct channel *ch)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700486{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 unsigned long flags;
488 struct tty_struct *tty;
Al Virobc9a5152005-09-15 22:53:28 +0100489 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700491 if (!(ch->asyncflags & ASYNC_INITIALIZED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 return;
493
Alan Coxf2cf8e22005-09-06 15:16:44 -0700494 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Alan Coxf2cf8e22005-09-06 15:16:44 -0700496 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 bc = ch->brdchan;
498
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700499 /*
500 * In order for an event to be generated on the receipt of data the
501 * idata flag must be set. Since we are shutting down, this is not
502 * necessary clear this flag.
503 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 if (bc)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700505 writeb(0, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 tty = ch->tty;
507
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700508 /* If we're a modem control device and HUPCL is on, drop RTS & DTR. */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700509 if (tty->termios->c_cflag & HUPCL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
511 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
512 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 memoff(ch);
514
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700515 /*
516 * The channel has officialy been closed. The next time it is opened it
517 * will have to reinitialized. Set a flag to indicate this.
518 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 /* Prevent future Digi programmed interrupts from coming active */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 ch->asyncflags &= ~ASYNC_INITIALIZED;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700521 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700522}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524static void pc_hangup(struct tty_struct *tty)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700525{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 struct channel *ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700528 /*
529 * verifyChannel returns the channel from the tty struct if it is
530 * valid. This serves as a sanity check.
531 */
532 if ((ch = verifyChannel(tty)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 unsigned long flags;
534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 if (tty->driver->flush_buffer)
536 tty->driver->flush_buffer(tty);
537 tty_ldisc_flush(tty);
538 shutdown(ch);
539
Alan Coxf2cf8e22005-09-06 15:16:44 -0700540 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 ch->tty = NULL;
542 ch->event = 0;
543 ch->count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700545 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 wake_up_interruptible(&ch->open_wait);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700547 }
548}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700550static int pc_write(struct tty_struct *tty,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 const unsigned char *buf, int bytesAvailable)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700552{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700553 unsigned int head, tail;
554 int dataLen;
555 int size;
556 int amountCopied;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 struct channel *ch;
558 unsigned long flags;
559 int remain;
Al Virobc9a5152005-09-15 22:53:28 +0100560 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700562 /*
563 * pc_write is primarily called directly by the kernel routine
564 * tty_write (Though it can also be called by put_char) found in
565 * tty_io.c. pc_write is passed a line discipline buffer where the data
566 * to be written out is stored. The line discipline implementation
567 * itself is done at the kernel level and is not brought into the
568 * driver.
569 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700571 /*
572 * verifyChannel returns the channel from the tty struct if it is
573 * valid. This serves as a sanity check.
574 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 if ((ch = verifyChannel(tty)) == NULL)
576 return 0;
577
578 /* Make a pointer to the channel data structure found on the board. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 bc = ch->brdchan;
580 size = ch->txbufsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 amountCopied = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Alan Coxf2cf8e22005-09-06 15:16:44 -0700583 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 globalwinon(ch);
585
Alan Coxf2cf8e22005-09-06 15:16:44 -0700586 head = readw(&bc->tin) & (size - 1);
587 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Alan Coxf2cf8e22005-09-06 15:16:44 -0700589 if (tail != readw(&bc->tout))
590 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 tail &= (size - 1);
592
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700593 if (head >= tail) {
594 /* head has not wrapped */
595 /*
596 * remain (much like dataLen above) represents the total amount
597 * of space available on the card for data. Here dataLen
598 * represents the space existing between the head pointer and
599 * the end of buffer. This is important because a memcpy cannot
600 * be told to automatically wrap around when it hits the buffer
601 * end.
602 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 dataLen = size - head;
604 remain = size - (head - tail) - 1;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700605 } else {
606 /* head has wrapped around */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 remain = tail - head - 1;
608 dataLen = remain;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700609 }
610 /*
611 * Check the space on the card. If we have more data than space; reduce
612 * the amount of data to fit the space.
613 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 bytesAvailable = min(remain, bytesAvailable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 txwinon(ch);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700616 while (bytesAvailable > 0) {
617 /* there is data to copy onto card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700619 /*
620 * If head is not wrapped, the below will make sure the first
621 * data copy fills to the end of card buffer.
622 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 dataLen = min(bytesAvailable, dataLen);
Al Virobc9a5152005-09-15 22:53:28 +0100624 memcpy_toio(ch->txptr + head, buf, dataLen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 buf += dataLen;
626 head += dataLen;
627 amountCopied += dataLen;
628 bytesAvailable -= dataLen;
629
Alan Coxf2cf8e22005-09-06 15:16:44 -0700630 if (head >= size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 head = 0;
632 dataLen = tail;
633 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700634 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 ch->statusflags |= TXBUSY;
636 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700637 writew(head, &bc->tin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Alan Coxf2cf8e22005-09-06 15:16:44 -0700639 if ((ch->statusflags & LOWWAIT) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 ch->statusflags |= LOWWAIT;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700641 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 }
643 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700644 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700645 return amountCopied;
646}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
648static void pc_put_char(struct tty_struct *tty, unsigned char c)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700649{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 pc_write(tty, &c, 1);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700651}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
653static int pc_write_room(struct tty_struct *tty)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700654{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 int remain;
656 struct channel *ch;
657 unsigned long flags;
658 unsigned int head, tail;
Al Virobc9a5152005-09-15 22:53:28 +0100659 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
661 remain = 0;
662
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700663 /*
664 * verifyChannel returns the channel from the tty struct if it is
665 * valid. This serves as a sanity check.
666 */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700667 if ((ch = verifyChannel(tty)) != NULL) {
668 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 globalwinon(ch);
670
671 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700672 head = readw(&bc->tin) & (ch->txbufsize - 1);
673 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Alan Coxf2cf8e22005-09-06 15:16:44 -0700675 if (tail != readw(&bc->tout))
676 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 /* Wrap tail if necessary */
678 tail &= (ch->txbufsize - 1);
679
680 if ((remain = tail - head - 1) < 0 )
681 remain += ch->txbufsize;
682
Alan Coxf2cf8e22005-09-06 15:16:44 -0700683 if (remain && (ch->statusflags & LOWWAIT) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 ch->statusflags |= LOWWAIT;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700685 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 }
687 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700688 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 /* Return how much room is left on card */
691 return remain;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700692}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
694static int pc_chars_in_buffer(struct tty_struct *tty)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700695{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 int chars;
697 unsigned int ctail, head, tail;
698 int remain;
699 unsigned long flags;
700 struct channel *ch;
Al Virobc9a5152005-09-15 22:53:28 +0100701 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700703 /*
704 * verifyChannel returns the channel from the tty struct if it is
705 * valid. This serves as a sanity check.
706 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 if ((ch = verifyChannel(tty)) == NULL)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700708 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Alan Coxf2cf8e22005-09-06 15:16:44 -0700710 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 globalwinon(ch);
712
713 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700714 tail = readw(&bc->tout);
715 head = readw(&bc->tin);
716 ctail = readw(&ch->mailbox->cout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
Alan Coxf2cf8e22005-09-06 15:16:44 -0700718 if (tail == head && readw(&ch->mailbox->cin) == ctail && readb(&bc->tbusy) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 chars = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700720 else { /* Begin if some space on the card has been used */
721 head = readw(&bc->tin) & (ch->txbufsize - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 tail &= (ch->txbufsize - 1);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700723 /*
724 * The logic here is basically opposite of the above
725 * pc_write_room here we are finding the amount of bytes in the
726 * buffer filled. Not the amount of bytes empty.
727 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 if ((remain = tail - head - 1) < 0 )
729 remain += ch->txbufsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 chars = (int)(ch->txbufsize - remain);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700731 /*
732 * Make it possible to wakeup anything waiting for output in
733 * tty_ioctl.c, etc.
734 *
735 * If not already set. Setup an event to indicate when the
736 * transmit buffer empties.
737 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 if (!(ch->statusflags & EMPTYWAIT))
739 setup_empty_event(tty,ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 } /* End if some space on the card has been used */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700742 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 /* Return number of characters residing on card. */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700744 return chars;
745}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747static void pc_flush_buffer(struct tty_struct *tty)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700748{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 unsigned int tail;
750 unsigned long flags;
751 struct channel *ch;
Al Virobc9a5152005-09-15 22:53:28 +0100752 struct board_chan __iomem *bc;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700753 /*
754 * verifyChannel returns the channel from the tty struct if it is
755 * valid. This serves as a sanity check.
756 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 if ((ch = verifyChannel(tty)) == NULL)
758 return;
759
Alan Coxf2cf8e22005-09-06 15:16:44 -0700760 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700763 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 /* Have FEP move tout pointer; effectively flushing transmit buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700767 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 tty_wakeup(tty);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700769}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
771static void pc_flush_chars(struct tty_struct *tty)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700772{
773 struct channel *ch;
774 /*
775 * verifyChannel returns the channel from the tty struct if it is
776 * valid. This serves as a sanity check.
777 */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700778 if ((ch = verifyChannel(tty)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 unsigned long flags;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700780 spin_lock_irqsave(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700781 /*
782 * If not already set and the transmitter is busy setup an
783 * event to indicate when the transmit empties.
784 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
786 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700787 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700789}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700791static int block_til_ready(struct tty_struct *tty,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 struct file *filp, struct channel *ch)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700793{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 DECLARE_WAITQUEUE(wait,current);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700795 int retval, do_clocal = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 unsigned long flags;
797
Alan Coxf2cf8e22005-09-06 15:16:44 -0700798 if (tty_hung_up_p(filp)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
800 retval = -EAGAIN;
801 else
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700802 retval = -ERESTARTSYS;
803 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 }
805
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700806 /*
807 * If the device is in the middle of being closed, then block until
808 * it's done, and then try again.
809 */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700810 if (ch->asyncflags & ASYNC_CLOSING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 interruptible_sleep_on(&ch->close_wait);
812
813 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
814 return -EAGAIN;
815 else
816 return -ERESTARTSYS;
817 }
818
Alan Coxf2cf8e22005-09-06 15:16:44 -0700819 if (filp->f_flags & O_NONBLOCK) {
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700820 /*
821 * If non-blocking mode is set, then make the check up front
822 * and then exit.
823 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 return 0;
826 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 if (tty->termios->c_cflag & CLOCAL)
828 do_clocal = 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700829 /* Block waiting for the carrier detect and the line to become free */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 retval = 0;
832 add_wait_queue(&ch->open_wait, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
Alan Coxf2cf8e22005-09-06 15:16:44 -0700834 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 /* We dec count so that pc_close will know when to free things */
836 if (!tty_hung_up_p(filp))
837 ch->count--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 ch->blocked_open++;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700839 while (1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 if (tty_hung_up_p(filp) ||
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700842 !(ch->asyncflags & ASYNC_INITIALIZED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 {
844 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
845 retval = -EAGAIN;
846 else
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700847 retval = -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 break;
849 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700850 if (!(ch->asyncflags & ASYNC_CLOSING) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 (do_clocal || (ch->imodem & ch->dcd)))
852 break;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700853 if (signal_pending(current)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 retval = -ERESTARTSYS;
855 break;
856 }
Alan Coxf2cf8e22005-09-06 15:16:44 -0700857 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700858 /*
859 * Allow someone else to be scheduled. We will occasionally go
860 * through this loop until one of the above conditions change.
861 * The below schedule call will allow other processes to enter
862 * and prevent this loop from hogging the cpu.
863 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 schedule();
Alan Coxf2cf8e22005-09-06 15:16:44 -0700865 spin_lock_irqsave(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700866 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
Milind Arun Choudharycc0a8fb2007-05-08 00:30:52 -0700868 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 remove_wait_queue(&ch->open_wait, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 if (!tty_hung_up_p(filp))
871 ch->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 ch->blocked_open--;
873
Alan Coxf2cf8e22005-09-06 15:16:44 -0700874 spin_unlock_irqrestore(&epca_lock, flags);
875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 if (retval)
877 return retval;
878
879 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 return 0;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700881}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
883static int pc_open(struct tty_struct *tty, struct file * filp)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700884{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 struct channel *ch;
886 unsigned long flags;
887 int line, retval, boardnum;
Al Virobc9a5152005-09-15 22:53:28 +0100888 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700889 unsigned int head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
891 line = tty->index;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700892 if (line < 0 || line >= nbdevs)
893 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
895 ch = &digi_channels[line];
896 boardnum = ch->boardnum;
897
898 /* Check status of board configured in system. */
899
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700900 /*
901 * I check to see if the epca_setup routine detected an user error. It
902 * might be better to put this in pc_init, but for the moment it goes
903 * here.
904 */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700905 if (invalid_lilo_config) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 if (setup_error_code & INVALID_BOARD_TYPE)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700907 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 if (setup_error_code & INVALID_NUM_PORTS)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700909 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 if (setup_error_code & INVALID_MEM_BASE)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700911 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 if (setup_error_code & INVALID_PORT_BASE)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700913 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 if (setup_error_code & INVALID_BOARD_STATUS)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700915 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 if (setup_error_code & INVALID_ALTPIN)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700917 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 tty->driver_data = NULL; /* Mark this device as 'down' */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700919 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 }
Alan Coxf2cf8e22005-09-06 15:16:44 -0700921 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 tty->driver_data = NULL; /* Mark this device as 'down' */
923 return(-ENODEV);
924 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700925
Harvey Harrison11fb09b2008-04-30 00:53:52 -0700926 bc = ch->brdchan;
927 if (bc == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 tty->driver_data = NULL;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700929 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 }
931
Alan Coxf2cf8e22005-09-06 15:16:44 -0700932 spin_lock_irqsave(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700933 /*
934 * Every time a channel is opened, increment a counter. This is
935 * necessary because we do not wish to flush and shutdown the channel
936 * until the last app holding the channel open, closes it.
937 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 ch->count++;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700939 /*
940 * Set a kernel structures pointer to our local channel structure. This
941 * way we can get to it when passed only a tty struct.
942 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 tty->driver_data = ch;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700944 /*
945 * If this is the first time the channel has been opened, initialize
946 * the tty->termios struct otherwise let pc_close handle it.
947 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 globalwinon(ch);
949 ch->statusflags = 0;
950
951 /* Save boards current modem status */
Al Virobc9a5152005-09-15 22:53:28 +0100952 ch->imodem = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700954 /*
955 * Set receive head and tail ptrs to each other. This indicates no data
956 * available to read.
957 */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700958 head = readw(&bc->rin);
959 writew(head, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
961 /* Set the channels associated tty structure */
962 ch->tty = tty;
963
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700964 /*
965 * The below routine generally sets up parity, baud, flow control
966 * issues, etc.... It effect both control flags and input flags.
967 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 epcaparam(tty,ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 ch->asyncflags |= ASYNC_INITIALIZED;
970 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700971 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
973 retval = block_til_ready(tty, filp, ch);
974 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 return retval;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700976 /*
977 * Set this again in case a hangup set it to zero while this open() was
978 * waiting for the line...
979 */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700980 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 ch->tty = tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 /* Enable Digi Data events */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700984 writeb(1, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700986 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988}
989
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700990static int __init epca_module_init(void)
991{
992 return pc_init();
993}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994module_init(epca_module_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996static struct pci_driver epca_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
998static void __exit epca_module_exit(void)
999{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 int count, crd;
1001 struct board_info *bd;
1002 struct channel *ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
1004 del_timer_sync(&epca_timer);
1005
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001006 if (tty_unregister_driver(pc_driver) || tty_unregister_driver(pc_info))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 {
Alan Coxf2cf8e22005-09-06 15:16:44 -07001008 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 return;
1010 }
1011 put_tty_driver(pc_driver);
1012 put_tty_driver(pc_info);
1013
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001014 for (crd = 0; crd < num_cards; crd++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 bd = &boards[crd];
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001016 if (!bd) { /* sanity check */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1018 return;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001019 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001020 ch = card_ptr[crd];
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001021 for (count = 0; count < bd->numports; count++, ch++) {
Jiri Slabyb3218a72006-10-04 02:15:27 -07001022 if (ch && ch->tty)
1023 tty_hangup(ch->tty);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001024 }
1025 }
1026 pci_unregister_driver(&epca_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027}
1028module_exit(epca_module_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
Jeff Dikeb68e31d2006-10-02 02:17:18 -07001030static const struct tty_operations pc_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 .open = pc_open,
1032 .close = pc_close,
1033 .write = pc_write,
1034 .write_room = pc_write_room,
1035 .flush_buffer = pc_flush_buffer,
1036 .chars_in_buffer = pc_chars_in_buffer,
1037 .flush_chars = pc_flush_chars,
1038 .put_char = pc_put_char,
1039 .ioctl = pc_ioctl,
1040 .set_termios = pc_set_termios,
1041 .stop = pc_stop,
1042 .start = pc_start,
1043 .throttle = pc_throttle,
1044 .unthrottle = pc_unthrottle,
1045 .hangup = pc_hangup,
1046};
1047
1048static int info_open(struct tty_struct *tty, struct file * filp)
1049{
1050 return 0;
1051}
1052
1053static struct tty_operations info_ops = {
1054 .open = info_open,
1055 .ioctl = info_ioctl,
1056};
1057
Alan Coxf2cf8e22005-09-06 15:16:44 -07001058static int __init pc_init(void)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001059{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 int crd;
1061 struct board_info *bd;
1062 unsigned char board_id = 0;
Akinobu Mitadabad052006-10-17 00:10:28 -07001063 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 int pci_boards_found, pci_count;
1066
1067 pci_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
1069 pc_driver = alloc_tty_driver(MAX_ALLOC);
1070 if (!pc_driver)
Akinobu Mitadabad052006-10-17 00:10:28 -07001071 goto out1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
1073 pc_info = alloc_tty_driver(MAX_ALLOC);
Akinobu Mitadabad052006-10-17 00:10:28 -07001074 if (!pc_info)
1075 goto out2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001077 /*
1078 * If epca_setup has not been ran by LILO set num_cards to defaults;
1079 * copy board structure defined by digiConfig into drivers board
1080 * structure. Note : If LILO has ran epca_setup then epca_setup will
1081 * handle defining num_cards as well as copying the data into the board
1082 * structure.
1083 */
1084 if (!liloconfig) {
1085 /* driver has been configured via. epcaconfig */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 nbdevs = NBDEVS;
1087 num_cards = NUMCARDS;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001088 memcpy(&boards, &static_boards,
1089 sizeof(struct board_info) * NUMCARDS);
1090 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001092 /*
1093 * Note : If lilo was used to configure the driver and the ignore
1094 * epcaconfig option was choosen (digiepca=2) then nbdevs and num_cards
1095 * will equal 0 at this point. This is okay; PCI cards will still be
1096 * picked up if detected.
1097 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001099 /*
1100 * Set up interrupt, we will worry about memory allocation in
1101 * post_fep_init.
1102 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1104
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001105 /*
1106 * NOTE : This code assumes that the number of ports found in the
1107 * boards array is correct. This could be wrong if the card in question
1108 * is PCI (And therefore has no ports entry in the boards structure.)
1109 * The rest of the information will be valid for PCI because the
1110 * beginning of pc_init scans for PCI and determines i/o and base
1111 * memory addresses. I am not sure if it is possible to read the number
1112 * of ports supported by the card prior to it being booted (Since that
1113 * is the state it is in when pc_init is run). Because it is not
1114 * possible to query the number of supported ports until after the card
1115 * has booted; we are required to calculate the card_ptrs as the card
1116 * is initialized (Inside post_fep_init). The negative thing about this
1117 * approach is that digiDload's call to GET_INFO will have a bad port
1118 * value. (Since this is called prior to post_fep_init.)
1119 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 pci_boards_found = 0;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001121 if (num_cards < MAXBOARDS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 pci_boards_found += init_PCI();
1123 num_cards += pci_boards_found;
1124
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 pc_driver->owner = THIS_MODULE;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001126 pc_driver->name = "ttyD";
1127 pc_driver->major = DIGI_MAJOR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 pc_driver->minor_start = 0;
1129 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1130 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1131 pc_driver->init_termios = tty_std_termios;
1132 pc_driver->init_termios.c_iflag = 0;
1133 pc_driver->init_termios.c_oflag = 0;
1134 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1135 pc_driver->init_termios.c_lflag = 0;
Alan Cox606d0992006-12-08 02:38:45 -08001136 pc_driver->init_termios.c_ispeed = 9600;
1137 pc_driver->init_termios.c_ospeed = 9600;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 pc_driver->flags = TTY_DRIVER_REAL_RAW;
1139 tty_set_operations(pc_driver, &pc_ops);
1140
1141 pc_info->owner = THIS_MODULE;
1142 pc_info->name = "digi_ctl";
1143 pc_info->major = DIGIINFOMAJOR;
1144 pc_info->minor_start = 0;
1145 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1146 pc_info->subtype = SERIAL_TYPE_INFO;
1147 pc_info->init_termios = tty_std_termios;
1148 pc_info->init_termios.c_iflag = 0;
1149 pc_info->init_termios.c_oflag = 0;
1150 pc_info->init_termios.c_lflag = 0;
1151 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
Alan Cox606d0992006-12-08 02:38:45 -08001152 pc_info->init_termios.c_ispeed = 9600;
1153 pc_info->init_termios.c_ospeed = 9600;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 pc_info->flags = TTY_DRIVER_REAL_RAW;
1155 tty_set_operations(pc_info, &info_ops);
1156
1157
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001158 for (crd = 0; crd < num_cards; crd++) {
1159 /*
1160 * This is where the appropriate memory handlers for the
1161 * hardware is set. Everything at runtime blindly jumps through
1162 * these vectors.
1163 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
1165 /* defined in epcaconfig.h */
1166 bd = &boards[crd];
1167
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001168 switch (bd->type) {
1169 case PCXEM:
1170 case EISAXEM:
1171 bd->memwinon = pcxem_memwinon;
1172 bd->memwinoff = pcxem_memwinoff;
1173 bd->globalwinon = pcxem_globalwinon;
1174 bd->txwinon = pcxem_txwinon;
1175 bd->rxwinon = pcxem_rxwinon;
1176 bd->memoff = pcxem_memoff;
1177 bd->assertgwinon = dummy_assertgwinon;
1178 bd->assertmemoff = dummy_assertmemoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 break;
1180
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001181 case PCIXEM:
1182 case PCIXRJ:
1183 case PCIXR:
1184 bd->memwinon = dummy_memwinon;
1185 bd->memwinoff = dummy_memwinoff;
1186 bd->globalwinon = dummy_globalwinon;
1187 bd->txwinon = dummy_txwinon;
1188 bd->rxwinon = dummy_rxwinon;
1189 bd->memoff = dummy_memoff;
1190 bd->assertgwinon = dummy_assertgwinon;
1191 bd->assertmemoff = dummy_assertmemoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 break;
1193
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001194 case PCXE:
1195 case PCXEVE:
1196 bd->memwinon = pcxe_memwinon;
1197 bd->memwinoff = pcxe_memwinoff;
1198 bd->globalwinon = pcxe_globalwinon;
1199 bd->txwinon = pcxe_txwinon;
1200 bd->rxwinon = pcxe_rxwinon;
1201 bd->memoff = pcxe_memoff;
1202 bd->assertgwinon = dummy_assertgwinon;
1203 bd->assertmemoff = dummy_assertmemoff;
1204 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001206 case PCXI:
1207 case PC64XE:
1208 bd->memwinon = pcxi_memwinon;
1209 bd->memwinoff = pcxi_memwinoff;
1210 bd->globalwinon = pcxi_globalwinon;
1211 bd->txwinon = pcxi_txwinon;
1212 bd->rxwinon = pcxi_rxwinon;
1213 bd->memoff = pcxi_memoff;
1214 bd->assertgwinon = pcxi_assertgwinon;
1215 bd->assertmemoff = pcxi_assertmemoff;
1216 break;
1217
1218 default:
1219 break;
1220 }
1221
1222 /*
1223 * Some cards need a memory segment to be defined for use in
1224 * transmit and receive windowing operations. These boards are
1225 * listed in the below switch. In the case of the XI the amount
1226 * of memory on the board is variable so the memory_seg is also
1227 * variable. This code determines what they segment should be.
1228 */
1229 switch (bd->type) {
1230 case PCXE:
1231 case PCXEVE:
1232 case PC64XE:
1233 bd->memory_seg = 0xf000;
1234 break;
1235
1236 case PCXI:
1237 board_id = inb((int)bd->port);
1238 if ((board_id & 0x1) == 0x1) {
1239 /* it's an XI card */
1240 /* Is it a 64K board */
1241 if ((board_id & 0x30) == 0)
1242 bd->memory_seg = 0xf000;
1243
1244 /* Is it a 128K board */
1245 if ((board_id & 0x30) == 0x10)
1246 bd->memory_seg = 0xe000;
1247
1248 /* Is is a 256K board */
1249 if ((board_id & 0x30) == 0x20)
1250 bd->memory_seg = 0xc000;
1251
1252 /* Is it a 512K board */
1253 if ((board_id & 0x30) == 0x30)
1254 bd->memory_seg = 0x8000;
1255 } else
1256 printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
1257 break;
1258 }
1259 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
Akinobu Mitadabad052006-10-17 00:10:28 -07001261 err = tty_register_driver(pc_driver);
1262 if (err) {
1263 printk(KERN_ERR "Couldn't register Digi PC/ driver");
1264 goto out3;
1265 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Akinobu Mitadabad052006-10-17 00:10:28 -07001267 err = tty_register_driver(pc_info);
1268 if (err) {
1269 printk(KERN_ERR "Couldn't register Digi PC/ info ");
1270 goto out4;
1271 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001273 /* Start up the poller to check for events on all enabled boards */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 init_timer(&epca_timer);
1275 epca_timer.function = epcapoll;
1276 mod_timer(&epca_timer, jiffies + HZ/25);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 return 0;
1278
Akinobu Mitadabad052006-10-17 00:10:28 -07001279out4:
1280 tty_unregister_driver(pc_driver);
1281out3:
1282 put_tty_driver(pc_info);
1283out2:
1284 put_tty_driver(pc_driver);
1285out1:
1286 return err;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001287}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
1289static void post_fep_init(unsigned int crd)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001290{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 int i;
Al Virobc9a5152005-09-15 22:53:28 +01001292 void __iomem *memaddr;
1293 struct global_data __iomem *gd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 struct board_info *bd;
Al Virobc9a5152005-09-15 22:53:28 +01001295 struct board_chan __iomem *bc;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001296 struct channel *ch;
1297 int shrinkmem = 0, lowwater;
1298
1299 /*
1300 * This call is made by the user via. the ioctl call DIGI_INIT. It is
1301 * responsible for setting up all the card specific stuff.
1302 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 bd = &boards[crd];
1304
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001305 /*
1306 * If this is a PCI board, get the port info. Remember PCI cards do not
1307 * have entries into the epcaconfig.h file, so we can't get the number
1308 * of ports from it. Unfortunetly, this means that anyone doing a
1309 * DIGI_GETINFO before the board has booted will get an invalid number
1310 * of ports returned (It should return 0). Calls to DIGI_GETINFO after
1311 * DIGI_INIT has been called will return the proper values.
1312 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001313 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001314 /*
1315 * Below we use XEMPORTS as a memory offset regardless of which
1316 * PCI card it is. This is because all of the supported PCI
1317 * cards have the same memory offset for the channel data. This
1318 * will have to be changed if we ever develop a PCI/XE card.
1319 * NOTE : The FEP manual states that the port offset is 0xC22
1320 * as opposed to 0xC02. This is only true for PC/XE, and PC/XI
1321 * cards; not for the XEM, or CX series. On the PCI cards the
1322 * number of ports is determined by reading a ID PROM located
1323 * in the box attached to the card. The card can then determine
1324 * the index the id to determine the number of ports available.
1325 * (FYI - The id should be located at 0x1ac (And may use up to
1326 * 4 bytes if the box in question is a XEM or CX)).
1327 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001328 /* PCI cards are already remapped at this point ISA are not */
1329 bd->numports = readw(bd->re_map_membase + XEMPORTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1331 nbdevs += (bd->numports);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001332 } else {
1333 /* Fix up the mappings for ISA/EISA etc */
1334 /* FIXME: 64K - can we be smarter ? */
1335 bd->re_map_membase = ioremap(bd->membase, 0x10000);
1336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
1338 if (crd != 0)
1339 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1340 else
1341 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1342
1343 ch = card_ptr[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1345
Alan Coxf2cf8e22005-09-06 15:16:44 -07001346 memaddr = bd->re_map_membase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001348 /*
1349 * The below assignment will set bc to point at the BEGINING of the
1350 * cards channel structures. For 1 card there will be between 8 and 64
1351 * of these structures.
1352 */
Al Virobc9a5152005-09-15 22:53:28 +01001353 bc = memaddr + CHANSTRUCT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001355 /*
1356 * The below assignment will set gd to point at the BEGINING of global
1357 * memory address 0xc00. The first data in that global memory actually
1358 * starts at address 0xc1a. The command in pointer begins at 0xd10.
1359 */
Al Virobc9a5152005-09-15 22:53:28 +01001360 gd = memaddr + GLOBAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001362 /*
1363 * XEPORTS (address 0xc22) points at the number of channels the card
1364 * supports. (For 64XE, XI, XEM, and XR use 0xc02)
1365 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001366 if ((bd->type == PCXEVE || bd->type == PCXE) && (readw(memaddr + XEPORTS) < 3))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 shrinkmem = 1;
1368 if (bd->type < PCIXEM)
1369 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001370 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 memwinon(bd, 0);
1372
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001373 /*
1374 * Remember ch is the main drivers channels structure, while bc is the
1375 * cards channel structure.
1376 */
1377 for (i = 0; i < bd->numports; i++, ch++, bc++) {
Alan Coxf2cf8e22005-09-06 15:16:44 -07001378 unsigned long flags;
Al Virobc9a5152005-09-15 22:53:28 +01001379 u16 tseg, rseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001381 ch->brdchan = bc;
1382 ch->mailbox = gd;
David Howellsc4028952006-11-22 14:57:56 +00001383 INIT_WORK(&ch->tqueue, do_softint);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001384 ch->board = &boards[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
Alan Coxf2cf8e22005-09-06 15:16:44 -07001386 spin_lock_irqsave(&epca_lock, flags);
1387 switch (bd->type) {
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001388 /*
1389 * Since some of the boards use different bitmaps for
1390 * their control signals we cannot hard code these
1391 * values and retain portability. We virtualize this
1392 * data here.
1393 */
1394 case EISAXEM:
1395 case PCXEM:
1396 case PCIXEM:
1397 case PCIXRJ:
1398 case PCIXR:
1399 ch->m_rts = 0x02;
1400 ch->m_dcd = 0x80;
1401 ch->m_dsr = 0x20;
1402 ch->m_cts = 0x10;
1403 ch->m_ri = 0x40;
1404 ch->m_dtr = 0x01;
1405 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001407 case PCXE:
1408 case PCXEVE:
1409 case PCXI:
1410 case PC64XE:
1411 ch->m_rts = 0x02;
1412 ch->m_dcd = 0x08;
1413 ch->m_dsr = 0x10;
1414 ch->m_cts = 0x20;
1415 ch->m_ri = 0x40;
1416 ch->m_dtr = 0x80;
1417 break;
1418 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
Alan Coxf2cf8e22005-09-06 15:16:44 -07001420 if (boards[crd].altpin) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 ch->dsr = ch->m_dcd;
1422 ch->dcd = ch->m_dsr;
1423 ch->digiext.digi_flags |= DIGI_ALTPIN;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001424 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 ch->dcd = ch->m_dcd;
1426 ch->dsr = ch->m_dsr;
1427 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001428
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 ch->boardnum = crd;
1430 ch->channelnum = i;
1431 ch->magic = EPCA_MAGIC;
1432 ch->tty = NULL;
1433
Alan Coxf2cf8e22005-09-06 15:16:44 -07001434 if (shrinkmem) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1436 shrinkmem = 0;
1437 }
1438
Al Virobc9a5152005-09-15 22:53:28 +01001439 tseg = readw(&bc->tseg);
1440 rseg = readw(&bc->rseg);
1441
Alan Coxf2cf8e22005-09-06 15:16:44 -07001442 switch (bd->type) {
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001443 case PCIXEM:
1444 case PCIXRJ:
1445 case PCIXR:
1446 /* Cover all the 2MEG cards */
1447 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1448 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1449 ch->txwin = FEPWIN | (tseg >> 11);
1450 ch->rxwin = FEPWIN | (rseg >> 11);
1451 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001453 case PCXEM:
1454 case EISAXEM:
1455 /* Cover all the 32K windowed cards */
1456 /* Mask equal to window size - 1 */
1457 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1458 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1459 ch->txwin = FEPWIN | (tseg >> 11);
1460 ch->rxwin = FEPWIN | (rseg >> 11);
1461 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001463 case PCXEVE:
1464 case PCXE:
1465 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4) & 0x1fff);
1466 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1467 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4) & 0x1fff);
1468 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >>9 );
1469 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001471 case PCXI:
1472 case PC64XE:
1473 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1474 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
1475 ch->txwin = ch->rxwin = 0;
1476 break;
1477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478
1479 ch->txbufhead = 0;
Al Virobc9a5152005-09-15 22:53:28 +01001480 ch->txbufsize = readw(&bc->tmax) + 1;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001481
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 ch->rxbufhead = 0;
Al Virobc9a5152005-09-15 22:53:28 +01001483 ch->rxbufsize = readw(&bc->rmax) + 1;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001484
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1486
1487 /* Set transmitter low water mark */
1488 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1489
1490 /* Set receiver low water mark */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
1492
1493 /* Set receiver high water mark */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1495
Alan Coxf2cf8e22005-09-06 15:16:44 -07001496 writew(100, &bc->edelay);
1497 writeb(1, &bc->idata);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001498
Alan Coxf2cf8e22005-09-06 15:16:44 -07001499 ch->startc = readb(&bc->startc);
1500 ch->stopc = readb(&bc->stopc);
1501 ch->startca = readb(&bc->startca);
1502 ch->stopca = readb(&bc->stopca);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001503
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 ch->fepcflag = 0;
1505 ch->fepiflag = 0;
1506 ch->fepoflag = 0;
1507 ch->fepstartc = 0;
1508 ch->fepstopc = 0;
1509 ch->fepstartca = 0;
1510 ch->fepstopca = 0;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001511
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 ch->close_delay = 50;
1513 ch->count = 0;
1514 ch->blocked_open = 0;
1515 init_waitqueue_head(&ch->open_wait);
1516 init_waitqueue_head(&ch->close_wait);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001517
1518 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001519 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001521 printk(KERN_INFO
1522 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 memwinoff(bd, 0);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001525}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
1527static void epcapoll(unsigned long ignored)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001528{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 unsigned long flags;
1530 int crd;
1531 volatile unsigned int head, tail;
1532 struct channel *ch;
1533 struct board_info *bd;
1534
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001535 /*
1536 * This routine is called upon every timer interrupt. Even though the
1537 * Digi series cards are capable of generating interrupts this method
1538 * of non-looping polling is more efficient. This routine checks for
1539 * card generated events (Such as receive data, are transmit buffer
1540 * empty) and acts on those events.
1541 */
1542 for (crd = 0; crd < num_cards; crd++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 bd = &boards[crd];
1544 ch = card_ptr[crd];
1545
1546 if ((bd->status == DISABLED) || digi_poller_inhibited)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001547 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001549 /*
1550 * assertmemoff is not needed here; indeed it is an empty
1551 * subroutine. It is being kept because future boards may need
1552 * this as well as some legacy boards.
1553 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001554 spin_lock_irqsave(&epca_lock, flags);
1555
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 assertmemoff(ch);
1557
1558 globalwinon(ch);
1559
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001560 /*
1561 * In this case head and tail actually refer to the event queue
1562 * not the transmit or receive queue.
1563 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001564 head = readw(&ch->mailbox->ein);
1565 tail = readw(&ch->mailbox->eout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001567 /* If head isn't equal to tail we have an event */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 if (head != tail)
1569 doevent(crd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 memoff(ch);
1571
Alan Coxf2cf8e22005-09-06 15:16:44 -07001572 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 } /* End for each card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 mod_timer(&epca_timer, jiffies + (HZ / 25));
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001575}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
1577static void doevent(int crd)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001578{
Al Virobc9a5152005-09-15 22:53:28 +01001579 void __iomem *eventbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 struct channel *ch, *chan0;
1581 static struct tty_struct *tty;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001582 struct board_info *bd;
Al Virobc9a5152005-09-15 22:53:28 +01001583 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001584 unsigned int tail, head;
1585 int event, channel;
1586 int mstat, lstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001588 /*
1589 * This subroutine is called by epcapoll when an event is detected
1590 * in the event queue. This routine responds to those events.
1591 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 bd = &boards[crd];
1593
1594 chan0 = card_ptr[crd];
1595 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 assertgwinon(chan0);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001597 while ((tail = readw(&chan0->mailbox->eout)) != (head = readw(&chan0->mailbox->ein))) { /* Begin while something in event queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 assertgwinon(chan0);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001599 eventbuf = bd->re_map_membase + tail + ISTART;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 /* Get the channel the event occurred on */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001601 channel = readb(eventbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 /* Get the actual event code that occurred */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001603 event = readb(eventbuf + 1);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001604 /*
1605 * The two assignments below get the current modem status
1606 * (mstat) and the previous modem status (lstat). These are
1607 * useful becuase an event could signal a change in modem
1608 * signals itself.
1609 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001610 mstat = readb(eventbuf + 2);
1611 lstat = readb(eventbuf + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612
1613 ch = chan0 + channel;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001614 if ((unsigned)channel >= bd->numports || !ch) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 if (channel >= bd->numports)
1616 ch = chan0;
1617 bc = ch->brdchan;
1618 goto next;
1619 }
1620
1621 if ((bc = ch->brdchan) == NULL)
1622 goto next;
1623
Alan Coxf2cf8e22005-09-06 15:16:44 -07001624 if (event & DATA_IND) { /* Begin DATA_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 receive_data(ch);
1626 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 } /* End DATA_IND */
1628 /* else *//* Fix for DCD transition missed bug */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001629 if (event & MODEMCHG_IND) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 /* A modem signal change has been indicated */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 ch->imodem = mstat;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001632 if (ch->asyncflags & ASYNC_CHECK_CD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 if (mstat & ch->dcd) /* We are now receiving dcd */
1634 wake_up_interruptible(&ch->open_wait);
1635 else
1636 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
1637 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 tty = ch->tty;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001640 if (tty) {
1641 if (event & BREAK_IND) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 /* A break has been indicated */
Alan Cox33f0f882006-01-09 20:54:13 -08001643 tty_insert_flip_char(tty, 0, TTY_BREAK);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001644 tty_schedule_flip(tty);
1645 } else if (event & LOWTX_IND) {
1646 if (ch->statusflags & LOWWAIT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 ch->statusflags &= ~LOWWAIT;
1648 tty_wakeup(tty);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001649 }
1650 } else if (event & EMPTYTX_IND) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 /* This event is generated by setup_empty_event */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 ch->statusflags &= ~TXBUSY;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001653 if (ch->statusflags & EMPTYWAIT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 ch->statusflags &= ~EMPTYWAIT;
1655 tty_wakeup(tty);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001656 }
1657 }
1658 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 next:
1660 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001661 BUG_ON(!bc);
1662 writew(1, &bc->idata);
1663 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 globalwinon(chan0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 } /* End while something in event queue */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001666}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
1668static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1669 int byte2, int ncmds, int bytecmd)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001670{
Al Virobc9a5152005-09-15 22:53:28 +01001671 unchar __iomem *memaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 unsigned int head, cmdTail, cmdStart, cmdMax;
1673 long count;
1674 int n;
1675
1676 /* This is the routine in which commands may be passed to the card. */
1677
1678 if (ch->board->status == DISABLED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 /* Remember head (As well as max) is just an offset not a base addr */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001682 head = readw(&ch->mailbox->cin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 /* cmdStart is a base address */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001684 cmdStart = readw(&ch->mailbox->cstart);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001685 /*
1686 * We do the addition below because we do not want a max pointer
1687 * relative to cmdStart. We want a max pointer that points at the
1688 * physical end of the command queue.
1689 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001690 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 memaddr = ch->board->re_map_membase;
1692
Alan Coxf2cf8e22005-09-06 15:16:44 -07001693 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1694 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__, cmd, head);
1695 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__, cmdMax, cmdStart);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 return;
1697 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001698 if (bytecmd) {
1699 writeb(cmd, memaddr + head + cmdStart + 0);
1700 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 /* Below word_or_byte is bits to set */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001702 writeb(word_or_byte, memaddr + head + cmdStart + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 /* Below byte2 is bits to reset */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001704 writeb(byte2, memaddr + head + cmdStart + 3);
1705 } else {
1706 writeb(cmd, memaddr + head + cmdStart + 0);
1707 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1708 writeb(word_or_byte, memaddr + head + cmdStart + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 head = (head + 4) & (cmdMax - cmdStart - 4);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001711 writew(head, &ch->mailbox->cin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 count = FEPTIMEOUT;
1713
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001714 for (;;) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 count--;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001716 if (count == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1718 return;
1719 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001720 head = readw(&ch->mailbox->cin);
1721 cmdTail = readw(&ch->mailbox->cout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001723 /*
1724 * Basically this will break when the FEP acknowledges the
1725 * command by incrementing cmdTail (Making it equal to head).
1726 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 if (n <= ncmds * (sizeof(short) * 4))
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001728 break;
1729 }
1730}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001732/*
1733 * Digi products use fields in their channels structures that are very similar
1734 * to the c_cflag and c_iflag fields typically found in UNIX termios
1735 * structures. The below three routines allow mappings between these hardware
1736 * "flags" and their respective Linux flags.
1737 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001739{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 unsigned res = 0;
1741
Alan Coxf2cf8e22005-09-06 15:16:44 -07001742 if (cflag & CRTSCTS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1744 res |= ((ch->m_cts) | (ch->m_rts));
1745 }
1746
1747 if (ch->digiext.digi_flags & RTSPACE)
1748 res |= ch->m_rts;
1749
1750 if (ch->digiext.digi_flags & DTRPACE)
1751 res |= ch->m_dtr;
1752
1753 if (ch->digiext.digi_flags & CTSPACE)
1754 res |= ch->m_cts;
1755
1756 if (ch->digiext.digi_flags & DSRPACE)
1757 res |= ch->dsr;
1758
1759 if (ch->digiext.digi_flags & DCDPACE)
1760 res |= ch->dcd;
1761
1762 if (res & (ch->m_rts))
1763 ch->digiext.digi_flags |= RTSPACE;
1764
1765 if (res & (ch->m_cts))
1766 ch->digiext.digi_flags |= CTSPACE;
1767
1768 return res;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001769}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001772{
1773 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 INPCK | ISTRIP|IXON|IXANY|IXOFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 if (ch->digiext.digi_flags & DIGI_AIXON)
1776 res |= IAIXON;
1777 return res;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001778}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
1780static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001781{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 unsigned res = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001783 if (cflag & CBAUDEX) {
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001784 ch->digiext.digi_flags |= DIGI_FAST;
1785 /*
1786 * HUPCL bit is used by FEP to indicate fast baud table is to
1787 * be used.
1788 */
1789 res |= FEP_HUPCL;
1790 } else
1791 ch->digiext.digi_flags &= ~DIGI_FAST;
1792 /*
1793 * CBAUD has bit position 0x1000 set these days to indicate Linux
1794 * baud rate remap. Digi hardware can't handle the bit assignment.
1795 * (We use a different bit assignment for high speed.). Clear this
1796 * bit out.
1797 */
1798 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
1799 /*
1800 * This gets a little confusing. The Digi cards have their own
Joe Perches8dfba4d2008-02-03 17:11:42 +02001801 * representation of c_cflags controlling baud rate. For the most part
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001802 * this is identical to the Linux implementation. However; Digi
1803 * supports one rate (76800) that Linux doesn't. This means that the
1804 * c_cflag entry that would normally mean 76800 for Digi actually means
1805 * 115200 under Linux. Without the below mapping, a stty 115200 would
1806 * only drive the board at 76800. Since the rate 230400 is also found
1807 * after 76800, the same problem afflicts us when we choose a rate of
1808 * 230400. Without the below modificiation stty 230400 would actually
1809 * give us 115200.
1810 *
1811 * There are two additional differences. The Linux value for CLOCAL
1812 * (0x800; 0004000) has no meaning to the Digi hardware. Also in later
1813 * releases of Linux; the CBAUD define has CBAUDEX (0x1000; 0010000)
1814 * ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX should be
1815 * checked for a screened out prior to termios2digi_c returning. Since
1816 * CLOCAL isn't used by the board this can be ignored as long as the
1817 * returned value is used only by Digi hardware.
1818 */
1819 if (cflag & CBAUDEX) {
1820 /*
1821 * The below code is trying to guarantee that only baud rates
1822 * 115200 and 230400 are remapped. We use exclusive or because
1823 * the various baud rates share common bit positions and
1824 * therefore can't be tested for easily.
1825 */
1826 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 res += 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 return res;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001831}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
Alan Coxf2cf8e22005-09-06 15:16:44 -07001833/* Caller must hold the locks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834static void epcaparam(struct tty_struct *tty, struct channel *ch)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001835{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 unsigned int cmdHead;
Alan Cox606d0992006-12-08 02:38:45 -08001837 struct ktermios *ts;
Al Virobc9a5152005-09-15 22:53:28 +01001838 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 unsigned mval, hflow, cflag, iflag;
1840
1841 bc = ch->brdchan;
Harvey Harrison11fb09b2008-04-30 00:53:52 -07001842 epcaassert(bc != NULL, "bc out of range");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
1844 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 ts = tty->termios;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001846 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
1847 cmdHead = readw(&bc->rin);
Al Virobc9a5152005-09-15 22:53:28 +01001848 writew(cmdHead, &bc->rout);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001849 cmdHead = readw(&bc->tin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 /* Changing baud in mid-stream transmission can be wonderful */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001851 /*
1852 * Flush current transmit buffer by setting cmdTail pointer
1853 * (tout) to cmdHead pointer (tin). Hopefully the transmit
1854 * buffer is empty.
1855 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
1857 mval = 0;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001858 } else { /* Begin CBAUD not detected */
1859 /*
1860 * c_cflags have changed but that change had nothing to do with
1861 * BAUD. Propagate the change to the card.
1862 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 cflag = termios2digi_c(ch, ts->c_cflag);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001864 if (cflag != ch->fepcflag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 ch->fepcflag = cflag;
1866 /* Set baud rate, char size, stop bits, parity */
1867 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
1868 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001869 /*
1870 * If the user has not forced CLOCAL and if the device is not a
1871 * CALLOUT device (Which is always CLOCAL) we set flags such
1872 * that the driver will wait on carrier detect.
1873 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 if (ts->c_cflag & CLOCAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 ch->asyncflags &= ~ASYNC_CHECK_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 ch->asyncflags |= ASYNC_CHECK_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 mval = ch->m_dtr | ch->m_rts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 } /* End CBAUD not detected */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 iflag = termios2digi_i(ch, ts->c_iflag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 /* Check input mode flags */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001882 if (iflag != ch->fepiflag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 ch->fepiflag = iflag;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001884 /*
1885 * Command sets channels iflag structure on the board. Such
1886 * things as input soft flow control, handling of parity
1887 * errors, and break handling are all set here.
1888 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 /* break handling, parity handling, input stripping, flow control chars */
1890 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
1891 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001892 /*
1893 * Set the board mint value for this channel. This will cause hardware
1894 * events to be generated each time the DCD signal (Described in mint)
1895 * changes.
1896 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001897 writeb(ch->dcd, &bc->mint);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
1899 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001900 writeb(0, &bc->mint);
1901 ch->imodem = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 hflow = termios2digi_h(ch, ts->c_cflag);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001903 if (hflow != ch->hflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 ch->hflow = hflow;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001905 /*
1906 * Hard flow control has been selected but the board is not
1907 * using it. Activate hard flow control now.
1908 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
1910 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 mval ^= ch->modemfake & (mval ^ ch->modem);
1912
Alan Coxf2cf8e22005-09-06 15:16:44 -07001913 if (ch->omodem ^ mval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 ch->omodem = mval;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001915 /*
1916 * The below command sets the DTR and RTS mstat structure. If
1917 * hard flow control is NOT active these changes will drive the
1918 * output of the actual DTR and RTS lines. If hard flow control
1919 * is active, the changes will be saved in the mstat structure
1920 * and only asserted when hard flow control is turned off.
1921 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922
1923 /* First reset DTR & RTS; then set them */
1924 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
1925 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001927 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 ch->fepstartc = ch->startc;
1929 ch->fepstopc = ch->stopc;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001930 /*
1931 * The XON / XOFF characters have changed; propagate these
1932 * changes to the card.
1933 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
1935 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001936 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 ch->fepstartca = ch->startca;
1938 ch->fepstopca = ch->stopca;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001939 /*
1940 * Similar to the above, this time the auxilarly XON / XOFF
1941 * characters have changed; propagate these changes to the card.
1942 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
1944 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001945}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946
Alan Coxf2cf8e22005-09-06 15:16:44 -07001947/* Caller holds lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948static void receive_data(struct channel *ch)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001949{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 unchar *rptr;
Alan Cox606d0992006-12-08 02:38:45 -08001951 struct ktermios *ts = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 struct tty_struct *tty;
Al Virobc9a5152005-09-15 22:53:28 +01001953 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001954 int dataToRead, wrapgap, bytesAvailable;
1955 unsigned int tail, head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 unsigned int wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001958 /*
1959 * This routine is called by doint when a receive data event has taken
1960 * place.
1961 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 if (ch->statusflags & RXSTOPPED)
1964 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 tty = ch->tty;
1966 if (tty)
1967 ts = tty->termios;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001969 BUG_ON(!bc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 wrapmask = ch->rxbufsize - 1;
1971
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001972 /*
1973 * Get the head and tail pointers to the receiver queue. Wrap the head
1974 * pointer if it has reached the end of the buffer.
1975 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001976 head = readw(&bc->rin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 head &= wrapmask;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001978 tail = readw(&bc->rout) & wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
1980 bytesAvailable = (head - tail) & wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 if (bytesAvailable == 0)
1982 return;
1983
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001984 /* If CREAD bit is off or device not open, set TX tail to head */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001985 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
Al Virobc9a5152005-09-15 22:53:28 +01001986 writew(head, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 return;
1988 }
1989
Alan Cox33f0f882006-01-09 20:54:13 -08001990 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 return;
1992
Alan Coxf2cf8e22005-09-06 15:16:44 -07001993 if (readb(&bc->orun)) {
1994 writeb(0, &bc->orun);
1995 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",tty->name);
Alan Cox33f0f882006-01-09 20:54:13 -08001996 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 rxwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001999 while (bytesAvailable > 0) { /* Begin while there is data on the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002001 /*
2002 * Even if head has wrapped around only report the amount of
2003 * data to be equal to the size - tail. Remember memcpy can't
2004 * automaticly wrap around the receive buffer.
2005 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002007 /* Make sure we don't overflow the buffer */
Alan Cox33f0f882006-01-09 20:54:13 -08002008 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 if (dataToRead == 0)
2010 break;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002011 /*
2012 * Move data read from our card into the line disciplines
2013 * buffer for translation if necessary.
2014 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002015 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 tail = (tail + dataToRead) & wrapmask;
2017 bytesAvailable -= dataToRead;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 } /* End while there is data on the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002020 writew(tail, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 /* Must be called with global data */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002022 tty_schedule_flip(ch->tty);
2023}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002025static int info_ioctl(struct tty_struct *tty, struct file *file,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 unsigned int cmd, unsigned long arg)
2027{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002028 switch (cmd) {
2029 case DIGI_GETINFO:
2030 {
2031 struct digi_info di;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 int brd;
2033
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002034 if (get_user(brd, (unsigned int __user *)arg))
Alan Coxf2cf8e22005-09-06 15:16:44 -07002035 return -EFAULT;
2036 if (brd < 0 || brd >= num_cards || num_cards == 0)
2037 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038
2039 memset(&di, 0, sizeof(di));
2040
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002041 di.board = brd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 di.status = boards[brd].status;
2043 di.type = boards[brd].type ;
2044 di.numports = boards[brd].numports ;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002045 /* Legacy fixups - just move along nothing to see */
2046 di.port = (unsigned char *)boards[brd].port ;
2047 di.membase = (unsigned char *)boards[brd].membase ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002049 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 return -EFAULT;
2051 break;
2052
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002053 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002055 case DIGI_POLLER:
2056 {
2057 int brd = arg & 0xff000000 >> 16;
2058 unsigned char state = arg & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
Alan Coxf2cf8e22005-09-06 15:16:44 -07002060 if (brd < 0 || brd >= num_cards) {
2061 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002062 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002064 digi_poller_inhibited = state;
2065 break;
2066 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002068 case DIGI_INIT:
2069 {
2070 /*
2071 * This call is made by the apps to complete the
Joe Perches8dfba4d2008-02-03 17:11:42 +02002072 * initialization of the board(s). This routine is
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002073 * responsible for setting the card to its initial
2074 * state and setting the drivers control fields to the
2075 * sutianle settings for the card in question.
2076 */
2077 int crd;
2078 for (crd = 0; crd < num_cards; crd++)
2079 post_fep_init(crd);
2080 break;
2081 }
2082 default:
2083 return -ENOTTY;
2084 }
2085 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087
2088static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2089{
2090 struct channel *ch = (struct channel *) tty->driver_data;
Al Virobc9a5152005-09-15 22:53:28 +01002091 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 unsigned int mstat, mflag = 0;
2093 unsigned long flags;
2094
2095 if (ch)
2096 bc = ch->brdchan;
2097 else
Alan Coxf2cf8e22005-09-06 15:16:44 -07002098 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
Alan Coxf2cf8e22005-09-06 15:16:44 -07002100 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002102 mstat = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002104 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105
2106 if (mstat & ch->m_dtr)
2107 mflag |= TIOCM_DTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 if (mstat & ch->m_rts)
2109 mflag |= TIOCM_RTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 if (mstat & ch->m_cts)
2111 mflag |= TIOCM_CTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 if (mstat & ch->dsr)
2113 mflag |= TIOCM_DSR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 if (mstat & ch->m_ri)
2115 mflag |= TIOCM_RI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 if (mstat & ch->dcd)
2117 mflag |= TIOCM_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 return mflag;
2119}
2120
2121static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2122 unsigned int set, unsigned int clear)
2123{
2124 struct channel *ch = (struct channel *) tty->driver_data;
2125 unsigned long flags;
2126
Alan Coxf2cf8e22005-09-06 15:16:44 -07002127 if (!ch)
2128 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
Alan Coxf2cf8e22005-09-06 15:16:44 -07002130 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 /*
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002132 * I think this modemfake stuff is broken. It doesn't correctly reflect
2133 * the behaviour desired by the TIOCM* ioctls. Therefore this is
2134 * probably broken.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 */
2136 if (set & TIOCM_RTS) {
2137 ch->modemfake |= ch->m_rts;
2138 ch->modem |= ch->m_rts;
2139 }
2140 if (set & TIOCM_DTR) {
2141 ch->modemfake |= ch->m_dtr;
2142 ch->modem |= ch->m_dtr;
2143 }
2144 if (clear & TIOCM_RTS) {
2145 ch->modemfake |= ch->m_rts;
2146 ch->modem &= ~ch->m_rts;
2147 }
2148 if (clear & TIOCM_DTR) {
2149 ch->modemfake |= ch->m_dtr;
2150 ch->modem &= ~ch->m_dtr;
2151 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 globalwinon(ch);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002153 /*
2154 * The below routine generally sets up parity, baud, flow control
2155 * issues, etc.... It effect both control flags and input flags.
2156 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 epcaparam(tty,ch);
2158 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002159 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 return 0;
2161}
2162
2163static int pc_ioctl(struct tty_struct *tty, struct file * file,
2164 unsigned int cmd, unsigned long arg)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002165{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 digiflow_t dflow;
2167 int retval;
2168 unsigned long flags;
2169 unsigned int mflag, mstat;
2170 unsigned char startc, stopc;
Al Virobc9a5152005-09-15 22:53:28 +01002171 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 struct channel *ch = (struct channel *) tty->driver_data;
2173 void __user *argp = (void __user *)arg;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002174
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 if (ch)
2176 bc = ch->brdchan;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002177 else
Alan Coxf2cf8e22005-09-06 15:16:44 -07002178 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002180 /*
2181 * For POSIX compliance we need to add more ioctls. See tty_ioctl.c in
2182 * /usr/src/linux/drivers/char for a good example. In particular think
2183 * about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
2184 */
2185 switch (cmd) {
2186 case TCSBRK: /* SVID version: non-zero arg --> no break */
2187 retval = tty_check_change(tty);
2188 if (retval)
2189 return retval;
2190 /* Setup an event to indicate when the transmit buffer empties */
2191 spin_lock_irqsave(&epca_lock, flags);
2192 setup_empty_event(tty,ch);
2193 spin_unlock_irqrestore(&epca_lock, flags);
2194 tty_wait_until_sent(tty, 0);
2195 if (!arg)
2196 digi_send_break(ch, HZ / 4); /* 1/4 second */
2197 return 0;
2198 case TCSBRKP: /* support for POSIX tcsendbreak() */
2199 retval = tty_check_change(tty);
2200 if (retval)
2201 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002203 /* Setup an event to indicate when the transmit buffer empties */
2204 spin_lock_irqsave(&epca_lock, flags);
2205 setup_empty_event(tty,ch);
2206 spin_unlock_irqrestore(&epca_lock, flags);
2207 tty_wait_until_sent(tty, 0);
2208 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
2209 return 0;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002210 case TIOCMODG:
2211 mflag = pc_tiocmget(tty, file);
2212 if (put_user(mflag, (unsigned long __user *)argp))
2213 return -EFAULT;
2214 break;
2215 case TIOCMODS:
2216 if (get_user(mstat, (unsigned __user *)argp))
2217 return -EFAULT;
2218 return pc_tiocmset(tty, file, mstat, ~mstat);
2219 case TIOCSDTR:
2220 spin_lock_irqsave(&epca_lock, flags);
2221 ch->omodem |= ch->m_dtr;
2222 globalwinon(ch);
2223 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2224 memoff(ch);
2225 spin_unlock_irqrestore(&epca_lock, flags);
2226 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002228 case TIOCCDTR:
2229 spin_lock_irqsave(&epca_lock, flags);
2230 ch->omodem &= ~ch->m_dtr;
2231 globalwinon(ch);
2232 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2233 memoff(ch);
2234 spin_unlock_irqrestore(&epca_lock, flags);
2235 break;
2236 case DIGI_GETA:
2237 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2238 return -EFAULT;
2239 break;
2240 case DIGI_SETAW:
2241 case DIGI_SETAF:
Alan Cox37925e02008-04-30 00:53:17 -07002242 lock_kernel();
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002243 if (cmd == DIGI_SETAW) {
2244 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002245 spin_lock_irqsave(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002246 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002247 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002248 tty_wait_until_sent(tty, 0);
2249 } else {
2250 /* ldisc lock already held in ioctl */
2251 if (tty->ldisc.flush_buffer)
2252 tty->ldisc.flush_buffer(tty);
2253 }
Alan Cox37925e02008-04-30 00:53:17 -07002254 unlock_kernel();
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002255 /* Fall Thru */
2256 case DIGI_SETA:
2257 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2258 return -EFAULT;
2259
2260 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
2261 ch->dcd = ch->m_dsr;
2262 ch->dsr = ch->m_dcd;
2263 } else {
2264 ch->dcd = ch->m_dcd;
2265 ch->dsr = ch->m_dsr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002267
2268 spin_lock_irqsave(&epca_lock, flags);
2269 globalwinon(ch);
2270
2271 /*
2272 * The below routine generally sets up parity, baud, flow
2273 * control issues, etc.... It effect both control flags and
2274 * input flags.
2275 */
2276 epcaparam(tty,ch);
2277 memoff(ch);
2278 spin_unlock_irqrestore(&epca_lock, flags);
2279 break;
2280
2281 case DIGI_GETFLOW:
2282 case DIGI_GETAFLOW:
2283 spin_lock_irqsave(&epca_lock, flags);
2284 globalwinon(ch);
2285 if (cmd == DIGI_GETFLOW) {
2286 dflow.startc = readb(&bc->startc);
2287 dflow.stopc = readb(&bc->stopc);
2288 } else {
2289 dflow.startc = readb(&bc->startca);
2290 dflow.stopc = readb(&bc->stopca);
2291 }
2292 memoff(ch);
2293 spin_unlock_irqrestore(&epca_lock, flags);
2294
2295 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2296 return -EFAULT;
2297 break;
2298
2299 case DIGI_SETAFLOW:
2300 case DIGI_SETFLOW:
2301 if (cmd == DIGI_SETFLOW) {
2302 startc = ch->startc;
2303 stopc = ch->stopc;
2304 } else {
2305 startc = ch->startca;
2306 stopc = ch->stopca;
2307 }
2308
2309 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2310 return -EFAULT;
2311
2312 if (dflow.startc != startc || dflow.stopc != stopc) { /* Begin if setflow toggled */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002313 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 globalwinon(ch);
2315
Alan Coxf2cf8e22005-09-06 15:16:44 -07002316 if (cmd == DIGI_SETFLOW) {
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002317 ch->fepstartc = ch->startc = dflow.startc;
2318 ch->fepstopc = ch->stopc = dflow.stopc;
2319 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002320 } else {
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002321 ch->fepstartca = ch->startca = dflow.startc;
2322 ch->fepstopca = ch->stopca = dflow.stopc;
2323 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 }
2325
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002326 if (ch->statusflags & TXSTOPPED)
2327 pc_start(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002329 memoff(ch);
2330 spin_unlock_irqrestore(&epca_lock, flags);
2331 } /* End if setflow toggled */
2332 break;
2333 default:
2334 return -ENOIOCTLCMD;
2335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 return 0;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002337}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
Alan Cox606d0992006-12-08 02:38:45 -08002339static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002340{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 struct channel *ch;
2342 unsigned long flags;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002343 /*
2344 * verifyChannel returns the channel from the tty struct if it is
2345 * valid. This serves as a sanity check.
2346 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002347 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
2348 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 globalwinon(ch);
2350 epcaparam(tty, ch);
2351 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002352 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353
2354 if ((old_termios->c_cflag & CRTSCTS) &&
2355 ((tty->termios->c_cflag & CRTSCTS) == 0))
2356 tty->hw_stopped = 0;
2357
2358 if (!(old_termios->c_cflag & CLOCAL) &&
2359 (tty->termios->c_cflag & CLOCAL))
2360 wake_up_interruptible(&ch->open_wait);
2361
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 } /* End if channel valid */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002363}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
David Howellsc4028952006-11-22 14:57:56 +00002365static void do_softint(struct work_struct *work)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002366{
David Howellsc4028952006-11-22 14:57:56 +00002367 struct channel *ch = container_of(work, struct channel, tqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 /* Called in response to a modem change event */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002369 if (ch && ch->magic == EPCA_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 struct tty_struct *tty = ch->tty;
2371
Alan Coxf2cf8e22005-09-06 15:16:44 -07002372 if (tty && tty->driver_data) {
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002373 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2375 wake_up_interruptible(&ch->open_wait);
2376 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002377 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002379 }
2380}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002382/*
2383 * pc_stop and pc_start provide software flow control to the routine and the
2384 * pc_ioctl routine.
2385 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386static void pc_stop(struct tty_struct *tty)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002387{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 struct channel *ch;
2389 unsigned long flags;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002390 /*
2391 * verifyChannel returns the channel from the tty struct if it is
2392 * valid. This serves as a sanity check.
2393 */
2394 if ((ch = verifyChannel(tty)) != NULL) {
Alan Coxf2cf8e22005-09-06 15:16:44 -07002395 spin_lock_irqsave(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002396 if ((ch->statusflags & TXSTOPPED) == 0) { /* Begin if transmit stop requested */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 /* STOP transmitting now !! */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 ch->statusflags |= TXSTOPPED;
2401 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 } /* End if transmit stop requested */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002403 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002404 }
2405}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
2407static void pc_start(struct tty_struct *tty)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002408{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 struct channel *ch;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002410 /*
2411 * verifyChannel returns the channel from the tty struct if it is
2412 * valid. This serves as a sanity check.
2413 */
2414 if ((ch = verifyChannel(tty)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 unsigned long flags;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002416 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 /* Just in case output was resumed because of a change in Digi-flow */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002418 if (ch->statusflags & TXSTOPPED) { /* Begin transmit resume requested */
Al Virobc9a5152005-09-15 22:53:28 +01002419 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 globalwinon(ch);
2421 bc = ch->brdchan;
2422 if (ch->statusflags & LOWWAIT)
Alan Coxf2cf8e22005-09-06 15:16:44 -07002423 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 /* Okay, you can start transmitting again... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 ch->statusflags &= ~TXSTOPPED;
2427 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 } /* End transmit resume requested */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002429 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002430 }
2431}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002433/*
2434 * The below routines pc_throttle and pc_unthrottle are used to slow (And
2435 * resume) the receipt of data into the kernels receive buffers. The exact
2436 * occurrence of this depends on the size of the kernels receive buffer and
2437 * what the 'watermarks' are set to for that buffer. See the n_ttys.c file for
2438 * more details.
2439 */
2440static void pc_throttle(struct tty_struct *tty)
2441{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 struct channel *ch;
2443 unsigned long flags;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002444 /*
2445 * verifyChannel returns the channel from the tty struct if it is
2446 * valid. This serves as a sanity check.
2447 */
2448 if ((ch = verifyChannel(tty)) != NULL) {
Alan Coxf2cf8e22005-09-06 15:16:44 -07002449 spin_lock_irqsave(&epca_lock, flags);
2450 if ((ch->statusflags & RXSTOPPED) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 globalwinon(ch);
2452 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 ch->statusflags |= RXSTOPPED;
2454 memoff(ch);
2455 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002456 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002457 }
2458}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459
2460static void pc_unthrottle(struct tty_struct *tty)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002461{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 struct channel *ch;
2463 unsigned long flags;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002464 /*
2465 * verifyChannel returns the channel from the tty struct if it is
2466 * valid. This serves as a sanity check.
2467 */
2468 if ((ch = verifyChannel(tty)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 /* Just in case output was resumed because of a change in Digi-flow */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002470 spin_lock_irqsave(&epca_lock, flags);
2471 if (ch->statusflags & RXSTOPPED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 ch->statusflags &= ~RXSTOPPED;
2475 memoff(ch);
2476 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002477 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002478 }
2479}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480
Harvey Harrison11fb09b2008-04-30 00:53:52 -07002481static void digi_send_break(struct channel *ch, int msec)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002482{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 unsigned long flags;
2484
Alan Coxf2cf8e22005-09-06 15:16:44 -07002485 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 globalwinon(ch);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002487 /*
2488 * Maybe I should send an infinite break here, schedule() for msec
2489 * amount of time, and then stop the break. This way, the user can't
2490 * screw up the FEP by causing digi_send_break() to be called (i.e. via
2491 * an ioctl()) more than once in msec amount of time.
2492 * Try this for now...
2493 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2495 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002496 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002497}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498
Alan Coxf2cf8e22005-09-06 15:16:44 -07002499/* Caller MUST hold the lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002501{
Al Virobc9a5152005-09-15 22:53:28 +01002502 struct board_chan __iomem *bc = ch->brdchan;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 globalwinon(ch);
2505 ch->statusflags |= EMPTYWAIT;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002506 /*
2507 * When set the iempty flag request a event to be generated when the
2508 * transmit buffer is empty (If there is no BREAK in progress).
2509 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002510 writeb(1, &bc->iempty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 memoff(ch);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002512}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514void epca_setup(char *str, int *ints)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002515{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 struct board_info board;
2517 int index, loop, last;
2518 char *temp, *t2;
2519 unsigned len;
2520
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002521 /*
2522 * If this routine looks a little strange it is because it is only
2523 * called if a LILO append command is given to boot the kernel with
2524 * parameters. In this way, we can provide the user a method of
2525 * changing his board configuration without rebuilding the kernel.
2526 */
2527 if (!liloconfig)
2528 liloconfig = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529
2530 memset(&board, 0, sizeof(board));
2531
2532 /* Assume the data is int first, later we can change it */
2533 /* I think that array position 0 of ints holds the number of args */
2534 for (last = 0, index = 1; index <= ints[0]; index++)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002535 switch (index) { /* Begin parse switch */
2536 case 1:
2537 board.status = ints[index];
2538 /*
2539 * We check for 2 (As opposed to 1; because 2 is a flag
2540 * instructing the driver to ignore epcaconfig.) For
2541 * this reason we check for 2.
2542 */
2543 if (board.status == 2) { /* Begin ignore epcaconfig as well as lilo cmd line */
2544 nbdevs = 0;
2545 num_cards = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 return;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002547 } /* End ignore epcaconfig as well as lilo cmd line */
2548
2549 if (board.status > 2) {
2550 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n", board.status);
2551 invalid_lilo_config = 1;
2552 setup_error_code |= INVALID_BOARD_STATUS;
2553 return;
2554 }
2555 last = index;
2556 break;
2557 case 2:
2558 board.type = ints[index];
2559 if (board.type >= PCIXEM) {
2560 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
2561 invalid_lilo_config = 1;
2562 setup_error_code |= INVALID_BOARD_TYPE;
2563 return;
2564 }
2565 last = index;
2566 break;
2567 case 3:
2568 board.altpin = ints[index];
2569 if (board.altpin > 1) {
2570 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
2571 invalid_lilo_config = 1;
2572 setup_error_code |= INVALID_ALTPIN;
2573 return;
2574 }
2575 last = index;
2576 break;
2577
2578 case 4:
2579 board.numports = ints[index];
2580 if (board.numports < 2 || board.numports > 256) {
2581 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
2582 invalid_lilo_config = 1;
2583 setup_error_code |= INVALID_NUM_PORTS;
2584 return;
2585 }
2586 nbdevs += board.numports;
2587 last = index;
2588 break;
2589
2590 case 5:
2591 board.port = ints[index];
2592 if (ints[index] <= 0) {
2593 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
2594 invalid_lilo_config = 1;
2595 setup_error_code |= INVALID_PORT_BASE;
2596 return;
2597 }
2598 last = index;
2599 break;
2600
2601 case 6:
2602 board.membase = ints[index];
2603 if (ints[index] <= 0) {
2604 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
2605 invalid_lilo_config = 1;
2606 setup_error_code |= INVALID_MEM_BASE;
2607 return;
2608 }
2609 last = index;
2610 break;
2611
2612 default:
2613 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
2614 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615
2616 } /* End parse switch */
2617
Alan Coxf2cf8e22005-09-06 15:16:44 -07002618 while (str && *str) { /* Begin while there is a string arg */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 /* find the next comma or terminator */
2620 temp = str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 /* While string is not null, and a comma hasn't been found */
2622 while (*temp && (*temp != ','))
2623 temp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 if (!*temp)
2625 temp = NULL;
2626 else
2627 *temp++ = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 /* Set index to the number of args + 1 */
2629 index = last + 1;
2630
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002631 switch (index) {
2632 case 1:
2633 len = strlen(str);
2634 if (strncmp("Disable", str, len) == 0)
2635 board.status = 0;
2636 else if (strncmp("Enable", str, len) == 0)
2637 board.status = 1;
2638 else {
2639 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
2640 invalid_lilo_config = 1;
2641 setup_error_code |= INVALID_BOARD_STATUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 return;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002643 }
2644 last = index;
2645 break;
2646
2647 case 2:
2648 for (loop = 0; loop < EPCA_NUM_TYPES; loop++)
2649 if (strcmp(board_desc[loop], str) == 0)
2650 break;
2651 /*
2652 * If the index incremented above refers to a
2653 * legitamate board type set it here.
2654 */
2655 if (index < EPCA_NUM_TYPES)
2656 board.type = loop;
2657 else {
2658 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
2659 invalid_lilo_config = 1;
2660 setup_error_code |= INVALID_BOARD_TYPE;
2661 return;
2662 }
2663 last = index;
2664 break;
2665
2666 case 3:
2667 len = strlen(str);
2668 if (strncmp("Disable", str, len) == 0)
2669 board.altpin = 0;
2670 else if (strncmp("Enable", str, len) == 0)
2671 board.altpin = 1;
2672 else {
2673 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
2674 invalid_lilo_config = 1;
2675 setup_error_code |= INVALID_ALTPIN;
2676 return;
2677 }
2678 last = index;
2679 break;
2680
2681 case 4:
2682 t2 = str;
2683 while (isdigit(*t2))
2684 t2++;
2685
2686 if (*t2) {
2687 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
2688 invalid_lilo_config = 1;
2689 setup_error_code |= INVALID_NUM_PORTS;
2690 return;
2691 }
2692
2693 /*
2694 * There is not a man page for simple_strtoul but the
2695 * code can be found in vsprintf.c. The first argument
2696 * is the string to translate (To an unsigned long
2697 * obviously), the second argument can be the address
2698 * of any character variable or a NULL. If a variable
2699 * is given, the end pointer of the string will be
2700 * stored in that variable; if a NULL is given the end
2701 * pointer will not be returned. The last argument is
2702 * the base to use. If a 0 is indicated, the routine
2703 * will attempt to determine the proper base by looking
2704 * at the values prefix (A '0' for octal, a 'x' for
2705 * hex, etc ... If a value is given it will use that
2706 * value as the base.
2707 */
2708 board.numports = simple_strtoul(str, NULL, 0);
2709 nbdevs += board.numports;
2710 last = index;
2711 break;
2712
2713 case 5:
2714 t2 = str;
2715 while (isxdigit(*t2))
2716 t2++;
2717
2718 if (*t2) {
2719 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
2720 invalid_lilo_config = 1;
2721 setup_error_code |= INVALID_PORT_BASE;
2722 return;
2723 }
2724
2725 board.port = simple_strtoul(str, NULL, 16);
2726 last = index;
2727 break;
2728
2729 case 6:
2730 t2 = str;
2731 while (isxdigit(*t2))
2732 t2++;
2733
2734 if (*t2) {
2735 printk(KERN_ERR "epca_setup: Invalid memory base %s\n",str);
2736 invalid_lilo_config = 1;
2737 setup_error_code |= INVALID_MEM_BASE;
2738 return;
2739 }
2740 board.membase = simple_strtoul(str, NULL, 16);
2741 last = index;
2742 break;
2743 default:
2744 printk(KERN_ERR "epca: Too many string parms\n");
2745 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 }
2747 str = temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 } /* End while there is a string arg */
2749
Alan Coxf2cf8e22005-09-06 15:16:44 -07002750 if (last < 6) {
2751 printk(KERN_ERR "epca: Insufficient parms specified\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 return;
2753 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002754
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 /* I should REALLY validate the stuff here */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 /* Copies our local copy of board into boards */
2757 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 /* Does this get called once per lilo arg are what ? */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002759 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2760 num_cards, board_desc[board.type],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 board.numports, (int)board.port, (unsigned int) board.membase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 num_cards++;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002763}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764
2765enum epic_board_types {
2766 brd_xr = 0,
2767 brd_xem,
2768 brd_cx,
2769 brd_xrj,
2770};
2771
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772/* indexed directly by epic_board_types enum */
2773static struct {
2774 unsigned char board_type;
2775 unsigned bar_idx; /* PCI base address region */
2776} epca_info_tbl[] = {
2777 { PCIXR, 0, },
2778 { PCIXEM, 0, },
2779 { PCICX, 0, },
2780 { PCIXRJ, 2, },
2781};
2782
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002783static int __devinit epca_init_one(struct pci_dev *pdev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 const struct pci_device_id *ent)
2785{
2786 static int board_num = -1;
2787 int board_idx, info_idx = ent->driver_data;
2788 unsigned long addr;
2789
2790 if (pci_enable_device(pdev))
2791 return -EIO;
2792
2793 board_num++;
2794 board_idx = board_num + num_cards;
2795 if (board_idx >= MAXBOARDS)
2796 goto err_out;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002797
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
2799 if (!addr) {
2800 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
2801 epca_info_tbl[info_idx].bar_idx);
2802 goto err_out;
2803 }
2804
2805 boards[board_idx].status = ENABLED;
2806 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
2807 boards[board_idx].numports = 0x0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002808 boards[board_idx].port = addr + PCI_IO_OFFSET;
2809 boards[board_idx].membase = addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810
2811 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
2812 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2813 0x200000, addr + PCI_IO_OFFSET);
2814 goto err_out;
2815 }
2816
2817 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
2818 if (!boards[board_idx].re_map_port) {
2819 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2820 0x200000, addr + PCI_IO_OFFSET);
2821 goto err_out_free_pciio;
2822 }
2823
2824 if (!request_mem_region (addr, 0x200000, "epca")) {
2825 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2826 0x200000, addr);
2827 goto err_out_free_iounmap;
2828 }
2829
2830 boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
2831 if (!boards[board_idx].re_map_membase) {
2832 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2833 0x200000, addr + PCI_IO_OFFSET);
2834 goto err_out_free_memregion;
2835 }
2836
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002837 /*
2838 * I don't know what the below does, but the hardware guys say its
2839 * required on everything except PLX (In this case XRJ).
2840 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 if (info_idx != brd_xrj) {
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002842 pci_write_config_byte(pdev, 0x40, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 pci_write_config_byte(pdev, 0x46, 0);
2844 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002845
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 return 0;
2847
2848err_out_free_memregion:
2849 release_mem_region (addr, 0x200000);
2850err_out_free_iounmap:
2851 iounmap (boards[board_idx].re_map_port);
2852err_out_free_pciio:
2853 release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
2854err_out:
2855 return -ENODEV;
2856}
2857
2858
2859static struct pci_device_id epca_pci_tbl[] = {
2860 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
2861 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
2862 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
2863 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
2864 { 0, }
2865};
2866
2867MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
2868
Harvey Harrison11fb09b2008-04-30 00:53:52 -07002869static int __init init_PCI(void)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002870{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 memset (&epca_driver, 0, sizeof (epca_driver));
2872 epca_driver.name = "epca";
2873 epca_driver.id_table = epca_pci_tbl;
2874 epca_driver.probe = epca_init_one;
2875
2876 return pci_register_driver(&epca_driver);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002877}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878
2879MODULE_LICENSE("GPL");