blob: ffcecde9e2a5b317319e605480c5520264c77ee3 [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
Alan Coxf2cf8e22005-09-06 15:16:44 -0700926 if ((bc = ch->brdchan) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 tty->driver_data = NULL;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700928 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 }
930
Alan Coxf2cf8e22005-09-06 15:16:44 -0700931 spin_lock_irqsave(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700932 /*
933 * Every time a channel is opened, increment a counter. This is
934 * necessary because we do not wish to flush and shutdown the channel
935 * until the last app holding the channel open, closes it.
936 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 ch->count++;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700938 /*
939 * Set a kernel structures pointer to our local channel structure. This
940 * way we can get to it when passed only a tty struct.
941 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 tty->driver_data = ch;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700943 /*
944 * If this is the first time the channel has been opened, initialize
945 * the tty->termios struct otherwise let pc_close handle it.
946 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 globalwinon(ch);
948 ch->statusflags = 0;
949
950 /* Save boards current modem status */
Al Virobc9a5152005-09-15 22:53:28 +0100951 ch->imodem = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700953 /*
954 * Set receive head and tail ptrs to each other. This indicates no data
955 * available to read.
956 */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700957 head = readw(&bc->rin);
958 writew(head, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
960 /* Set the channels associated tty structure */
961 ch->tty = tty;
962
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700963 /*
964 * The below routine generally sets up parity, baud, flow control
965 * issues, etc.... It effect both control flags and input flags.
966 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 epcaparam(tty,ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 ch->asyncflags |= ASYNC_INITIALIZED;
969 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700970 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
972 retval = block_til_ready(tty, filp, ch);
973 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 return retval;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700975 /*
976 * Set this again in case a hangup set it to zero while this open() was
977 * waiting for the line...
978 */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700979 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 ch->tty = tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 /* Enable Digi Data events */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700983 writeb(1, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700985 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987}
988
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -0700989static int __init epca_module_init(void)
990{
991 return pc_init();
992}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993module_init(epca_module_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995static struct pci_driver epca_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
997static void __exit epca_module_exit(void)
998{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 int count, crd;
1000 struct board_info *bd;
1001 struct channel *ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
1003 del_timer_sync(&epca_timer);
1004
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001005 if (tty_unregister_driver(pc_driver) || tty_unregister_driver(pc_info))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 {
Alan Coxf2cf8e22005-09-06 15:16:44 -07001007 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 return;
1009 }
1010 put_tty_driver(pc_driver);
1011 put_tty_driver(pc_info);
1012
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001013 for (crd = 0; crd < num_cards; crd++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 bd = &boards[crd];
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001015 if (!bd) { /* sanity check */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1017 return;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001018 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001019 ch = card_ptr[crd];
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001020 for (count = 0; count < bd->numports; count++, ch++) {
Jiri Slabyb3218a72006-10-04 02:15:27 -07001021 if (ch && ch->tty)
1022 tty_hangup(ch->tty);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001023 }
1024 }
1025 pci_unregister_driver(&epca_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026}
1027module_exit(epca_module_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
Jeff Dikeb68e31d2006-10-02 02:17:18 -07001029static const struct tty_operations pc_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 .open = pc_open,
1031 .close = pc_close,
1032 .write = pc_write,
1033 .write_room = pc_write_room,
1034 .flush_buffer = pc_flush_buffer,
1035 .chars_in_buffer = pc_chars_in_buffer,
1036 .flush_chars = pc_flush_chars,
1037 .put_char = pc_put_char,
1038 .ioctl = pc_ioctl,
1039 .set_termios = pc_set_termios,
1040 .stop = pc_stop,
1041 .start = pc_start,
1042 .throttle = pc_throttle,
1043 .unthrottle = pc_unthrottle,
1044 .hangup = pc_hangup,
1045};
1046
1047static int info_open(struct tty_struct *tty, struct file * filp)
1048{
1049 return 0;
1050}
1051
1052static struct tty_operations info_ops = {
1053 .open = info_open,
1054 .ioctl = info_ioctl,
1055};
1056
Alan Coxf2cf8e22005-09-06 15:16:44 -07001057static int __init pc_init(void)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001058{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 int crd;
1060 struct board_info *bd;
1061 unsigned char board_id = 0;
Akinobu Mitadabad052006-10-17 00:10:28 -07001062 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 int pci_boards_found, pci_count;
1065
1066 pci_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
1068 pc_driver = alloc_tty_driver(MAX_ALLOC);
1069 if (!pc_driver)
Akinobu Mitadabad052006-10-17 00:10:28 -07001070 goto out1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
1072 pc_info = alloc_tty_driver(MAX_ALLOC);
Akinobu Mitadabad052006-10-17 00:10:28 -07001073 if (!pc_info)
1074 goto out2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001076 /*
1077 * If epca_setup has not been ran by LILO set num_cards to defaults;
1078 * copy board structure defined by digiConfig into drivers board
1079 * structure. Note : If LILO has ran epca_setup then epca_setup will
1080 * handle defining num_cards as well as copying the data into the board
1081 * structure.
1082 */
1083 if (!liloconfig) {
1084 /* driver has been configured via. epcaconfig */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 nbdevs = NBDEVS;
1086 num_cards = NUMCARDS;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001087 memcpy(&boards, &static_boards,
1088 sizeof(struct board_info) * NUMCARDS);
1089 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001091 /*
1092 * Note : If lilo was used to configure the driver and the ignore
1093 * epcaconfig option was choosen (digiepca=2) then nbdevs and num_cards
1094 * will equal 0 at this point. This is okay; PCI cards will still be
1095 * picked up if detected.
1096 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001098 /*
1099 * Set up interrupt, we will worry about memory allocation in
1100 * post_fep_init.
1101 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1103
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001104 /*
1105 * NOTE : This code assumes that the number of ports found in the
1106 * boards array is correct. This could be wrong if the card in question
1107 * is PCI (And therefore has no ports entry in the boards structure.)
1108 * The rest of the information will be valid for PCI because the
1109 * beginning of pc_init scans for PCI and determines i/o and base
1110 * memory addresses. I am not sure if it is possible to read the number
1111 * of ports supported by the card prior to it being booted (Since that
1112 * is the state it is in when pc_init is run). Because it is not
1113 * possible to query the number of supported ports until after the card
1114 * has booted; we are required to calculate the card_ptrs as the card
1115 * is initialized (Inside post_fep_init). The negative thing about this
1116 * approach is that digiDload's call to GET_INFO will have a bad port
1117 * value. (Since this is called prior to post_fep_init.)
1118 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 pci_boards_found = 0;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001120 if (num_cards < MAXBOARDS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 pci_boards_found += init_PCI();
1122 num_cards += pci_boards_found;
1123
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 pc_driver->owner = THIS_MODULE;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001125 pc_driver->name = "ttyD";
1126 pc_driver->major = DIGI_MAJOR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 pc_driver->minor_start = 0;
1128 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1129 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1130 pc_driver->init_termios = tty_std_termios;
1131 pc_driver->init_termios.c_iflag = 0;
1132 pc_driver->init_termios.c_oflag = 0;
1133 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1134 pc_driver->init_termios.c_lflag = 0;
Alan Cox606d0992006-12-08 02:38:45 -08001135 pc_driver->init_termios.c_ispeed = 9600;
1136 pc_driver->init_termios.c_ospeed = 9600;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 pc_driver->flags = TTY_DRIVER_REAL_RAW;
1138 tty_set_operations(pc_driver, &pc_ops);
1139
1140 pc_info->owner = THIS_MODULE;
1141 pc_info->name = "digi_ctl";
1142 pc_info->major = DIGIINFOMAJOR;
1143 pc_info->minor_start = 0;
1144 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1145 pc_info->subtype = SERIAL_TYPE_INFO;
1146 pc_info->init_termios = tty_std_termios;
1147 pc_info->init_termios.c_iflag = 0;
1148 pc_info->init_termios.c_oflag = 0;
1149 pc_info->init_termios.c_lflag = 0;
1150 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
Alan Cox606d0992006-12-08 02:38:45 -08001151 pc_info->init_termios.c_ispeed = 9600;
1152 pc_info->init_termios.c_ospeed = 9600;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 pc_info->flags = TTY_DRIVER_REAL_RAW;
1154 tty_set_operations(pc_info, &info_ops);
1155
1156
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001157 for (crd = 0; crd < num_cards; crd++) {
1158 /*
1159 * This is where the appropriate memory handlers for the
1160 * hardware is set. Everything at runtime blindly jumps through
1161 * these vectors.
1162 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
1164 /* defined in epcaconfig.h */
1165 bd = &boards[crd];
1166
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001167 switch (bd->type) {
1168 case PCXEM:
1169 case EISAXEM:
1170 bd->memwinon = pcxem_memwinon;
1171 bd->memwinoff = pcxem_memwinoff;
1172 bd->globalwinon = pcxem_globalwinon;
1173 bd->txwinon = pcxem_txwinon;
1174 bd->rxwinon = pcxem_rxwinon;
1175 bd->memoff = pcxem_memoff;
1176 bd->assertgwinon = dummy_assertgwinon;
1177 bd->assertmemoff = dummy_assertmemoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 break;
1179
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001180 case PCIXEM:
1181 case PCIXRJ:
1182 case PCIXR:
1183 bd->memwinon = dummy_memwinon;
1184 bd->memwinoff = dummy_memwinoff;
1185 bd->globalwinon = dummy_globalwinon;
1186 bd->txwinon = dummy_txwinon;
1187 bd->rxwinon = dummy_rxwinon;
1188 bd->memoff = dummy_memoff;
1189 bd->assertgwinon = dummy_assertgwinon;
1190 bd->assertmemoff = dummy_assertmemoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 break;
1192
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001193 case PCXE:
1194 case PCXEVE:
1195 bd->memwinon = pcxe_memwinon;
1196 bd->memwinoff = pcxe_memwinoff;
1197 bd->globalwinon = pcxe_globalwinon;
1198 bd->txwinon = pcxe_txwinon;
1199 bd->rxwinon = pcxe_rxwinon;
1200 bd->memoff = pcxe_memoff;
1201 bd->assertgwinon = dummy_assertgwinon;
1202 bd->assertmemoff = dummy_assertmemoff;
1203 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001205 case PCXI:
1206 case PC64XE:
1207 bd->memwinon = pcxi_memwinon;
1208 bd->memwinoff = pcxi_memwinoff;
1209 bd->globalwinon = pcxi_globalwinon;
1210 bd->txwinon = pcxi_txwinon;
1211 bd->rxwinon = pcxi_rxwinon;
1212 bd->memoff = pcxi_memoff;
1213 bd->assertgwinon = pcxi_assertgwinon;
1214 bd->assertmemoff = pcxi_assertmemoff;
1215 break;
1216
1217 default:
1218 break;
1219 }
1220
1221 /*
1222 * Some cards need a memory segment to be defined for use in
1223 * transmit and receive windowing operations. These boards are
1224 * listed in the below switch. In the case of the XI the amount
1225 * of memory on the board is variable so the memory_seg is also
1226 * variable. This code determines what they segment should be.
1227 */
1228 switch (bd->type) {
1229 case PCXE:
1230 case PCXEVE:
1231 case PC64XE:
1232 bd->memory_seg = 0xf000;
1233 break;
1234
1235 case PCXI:
1236 board_id = inb((int)bd->port);
1237 if ((board_id & 0x1) == 0x1) {
1238 /* it's an XI card */
1239 /* Is it a 64K board */
1240 if ((board_id & 0x30) == 0)
1241 bd->memory_seg = 0xf000;
1242
1243 /* Is it a 128K board */
1244 if ((board_id & 0x30) == 0x10)
1245 bd->memory_seg = 0xe000;
1246
1247 /* Is is a 256K board */
1248 if ((board_id & 0x30) == 0x20)
1249 bd->memory_seg = 0xc000;
1250
1251 /* Is it a 512K board */
1252 if ((board_id & 0x30) == 0x30)
1253 bd->memory_seg = 0x8000;
1254 } else
1255 printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
1256 break;
1257 }
1258 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Akinobu Mitadabad052006-10-17 00:10:28 -07001260 err = tty_register_driver(pc_driver);
1261 if (err) {
1262 printk(KERN_ERR "Couldn't register Digi PC/ driver");
1263 goto out3;
1264 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
Akinobu Mitadabad052006-10-17 00:10:28 -07001266 err = tty_register_driver(pc_info);
1267 if (err) {
1268 printk(KERN_ERR "Couldn't register Digi PC/ info ");
1269 goto out4;
1270 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001272 /* Start up the poller to check for events on all enabled boards */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 init_timer(&epca_timer);
1274 epca_timer.function = epcapoll;
1275 mod_timer(&epca_timer, jiffies + HZ/25);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 return 0;
1277
Akinobu Mitadabad052006-10-17 00:10:28 -07001278out4:
1279 tty_unregister_driver(pc_driver);
1280out3:
1281 put_tty_driver(pc_info);
1282out2:
1283 put_tty_driver(pc_driver);
1284out1:
1285 return err;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001286}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
1288static void post_fep_init(unsigned int crd)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001289{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 int i;
Al Virobc9a5152005-09-15 22:53:28 +01001291 void __iomem *memaddr;
1292 struct global_data __iomem *gd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 struct board_info *bd;
Al Virobc9a5152005-09-15 22:53:28 +01001294 struct board_chan __iomem *bc;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001295 struct channel *ch;
1296 int shrinkmem = 0, lowwater;
1297
1298 /*
1299 * This call is made by the user via. the ioctl call DIGI_INIT. It is
1300 * responsible for setting up all the card specific stuff.
1301 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 bd = &boards[crd];
1303
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001304 /*
1305 * If this is a PCI board, get the port info. Remember PCI cards do not
1306 * have entries into the epcaconfig.h file, so we can't get the number
1307 * of ports from it. Unfortunetly, this means that anyone doing a
1308 * DIGI_GETINFO before the board has booted will get an invalid number
1309 * of ports returned (It should return 0). Calls to DIGI_GETINFO after
1310 * DIGI_INIT has been called will return the proper values.
1311 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001312 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001313 /*
1314 * Below we use XEMPORTS as a memory offset regardless of which
1315 * PCI card it is. This is because all of the supported PCI
1316 * cards have the same memory offset for the channel data. This
1317 * will have to be changed if we ever develop a PCI/XE card.
1318 * NOTE : The FEP manual states that the port offset is 0xC22
1319 * as opposed to 0xC02. This is only true for PC/XE, and PC/XI
1320 * cards; not for the XEM, or CX series. On the PCI cards the
1321 * number of ports is determined by reading a ID PROM located
1322 * in the box attached to the card. The card can then determine
1323 * the index the id to determine the number of ports available.
1324 * (FYI - The id should be located at 0x1ac (And may use up to
1325 * 4 bytes if the box in question is a XEM or CX)).
1326 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001327 /* PCI cards are already remapped at this point ISA are not */
1328 bd->numports = readw(bd->re_map_membase + XEMPORTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1330 nbdevs += (bd->numports);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001331 } else {
1332 /* Fix up the mappings for ISA/EISA etc */
1333 /* FIXME: 64K - can we be smarter ? */
1334 bd->re_map_membase = ioremap(bd->membase, 0x10000);
1335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
1337 if (crd != 0)
1338 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1339 else
1340 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1341
1342 ch = card_ptr[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1344
Alan Coxf2cf8e22005-09-06 15:16:44 -07001345 memaddr = bd->re_map_membase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001347 /*
1348 * The below assignment will set bc to point at the BEGINING of the
1349 * cards channel structures. For 1 card there will be between 8 and 64
1350 * of these structures.
1351 */
Al Virobc9a5152005-09-15 22:53:28 +01001352 bc = memaddr + CHANSTRUCT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001354 /*
1355 * The below assignment will set gd to point at the BEGINING of global
1356 * memory address 0xc00. The first data in that global memory actually
1357 * starts at address 0xc1a. The command in pointer begins at 0xd10.
1358 */
Al Virobc9a5152005-09-15 22:53:28 +01001359 gd = memaddr + GLOBAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001361 /*
1362 * XEPORTS (address 0xc22) points at the number of channels the card
1363 * supports. (For 64XE, XI, XEM, and XR use 0xc02)
1364 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001365 if ((bd->type == PCXEVE || bd->type == PCXE) && (readw(memaddr + XEPORTS) < 3))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 shrinkmem = 1;
1367 if (bd->type < PCIXEM)
1368 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001369 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 memwinon(bd, 0);
1371
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001372 /*
1373 * Remember ch is the main drivers channels structure, while bc is the
1374 * cards channel structure.
1375 */
1376 for (i = 0; i < bd->numports; i++, ch++, bc++) {
Alan Coxf2cf8e22005-09-06 15:16:44 -07001377 unsigned long flags;
Al Virobc9a5152005-09-15 22:53:28 +01001378 u16 tseg, rseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001380 ch->brdchan = bc;
1381 ch->mailbox = gd;
David Howellsc4028952006-11-22 14:57:56 +00001382 INIT_WORK(&ch->tqueue, do_softint);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001383 ch->board = &boards[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
Alan Coxf2cf8e22005-09-06 15:16:44 -07001385 spin_lock_irqsave(&epca_lock, flags);
1386 switch (bd->type) {
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001387 /*
1388 * Since some of the boards use different bitmaps for
1389 * their control signals we cannot hard code these
1390 * values and retain portability. We virtualize this
1391 * data here.
1392 */
1393 case EISAXEM:
1394 case PCXEM:
1395 case PCIXEM:
1396 case PCIXRJ:
1397 case PCIXR:
1398 ch->m_rts = 0x02;
1399 ch->m_dcd = 0x80;
1400 ch->m_dsr = 0x20;
1401 ch->m_cts = 0x10;
1402 ch->m_ri = 0x40;
1403 ch->m_dtr = 0x01;
1404 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001406 case PCXE:
1407 case PCXEVE:
1408 case PCXI:
1409 case PC64XE:
1410 ch->m_rts = 0x02;
1411 ch->m_dcd = 0x08;
1412 ch->m_dsr = 0x10;
1413 ch->m_cts = 0x20;
1414 ch->m_ri = 0x40;
1415 ch->m_dtr = 0x80;
1416 break;
1417 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Alan Coxf2cf8e22005-09-06 15:16:44 -07001419 if (boards[crd].altpin) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 ch->dsr = ch->m_dcd;
1421 ch->dcd = ch->m_dsr;
1422 ch->digiext.digi_flags |= DIGI_ALTPIN;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001423 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 ch->dcd = ch->m_dcd;
1425 ch->dsr = ch->m_dsr;
1426 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001427
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 ch->boardnum = crd;
1429 ch->channelnum = i;
1430 ch->magic = EPCA_MAGIC;
1431 ch->tty = NULL;
1432
Alan Coxf2cf8e22005-09-06 15:16:44 -07001433 if (shrinkmem) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1435 shrinkmem = 0;
1436 }
1437
Al Virobc9a5152005-09-15 22:53:28 +01001438 tseg = readw(&bc->tseg);
1439 rseg = readw(&bc->rseg);
1440
Alan Coxf2cf8e22005-09-06 15:16:44 -07001441 switch (bd->type) {
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001442 case PCIXEM:
1443 case PCIXRJ:
1444 case PCIXR:
1445 /* Cover all the 2MEG cards */
1446 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1447 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1448 ch->txwin = FEPWIN | (tseg >> 11);
1449 ch->rxwin = FEPWIN | (rseg >> 11);
1450 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001452 case PCXEM:
1453 case EISAXEM:
1454 /* Cover all the 32K windowed cards */
1455 /* Mask equal to window size - 1 */
1456 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1457 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1458 ch->txwin = FEPWIN | (tseg >> 11);
1459 ch->rxwin = FEPWIN | (rseg >> 11);
1460 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001462 case PCXEVE:
1463 case PCXE:
1464 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4) & 0x1fff);
1465 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1466 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4) & 0x1fff);
1467 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >>9 );
1468 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001470 case PCXI:
1471 case PC64XE:
1472 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1473 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
1474 ch->txwin = ch->rxwin = 0;
1475 break;
1476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
1478 ch->txbufhead = 0;
Al Virobc9a5152005-09-15 22:53:28 +01001479 ch->txbufsize = readw(&bc->tmax) + 1;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001480
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 ch->rxbufhead = 0;
Al Virobc9a5152005-09-15 22:53:28 +01001482 ch->rxbufsize = readw(&bc->rmax) + 1;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001483
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1485
1486 /* Set transmitter low water mark */
1487 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1488
1489 /* Set receiver low water mark */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
1491
1492 /* Set receiver high water mark */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1494
Alan Coxf2cf8e22005-09-06 15:16:44 -07001495 writew(100, &bc->edelay);
1496 writeb(1, &bc->idata);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001497
Alan Coxf2cf8e22005-09-06 15:16:44 -07001498 ch->startc = readb(&bc->startc);
1499 ch->stopc = readb(&bc->stopc);
1500 ch->startca = readb(&bc->startca);
1501 ch->stopca = readb(&bc->stopca);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001502
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 ch->fepcflag = 0;
1504 ch->fepiflag = 0;
1505 ch->fepoflag = 0;
1506 ch->fepstartc = 0;
1507 ch->fepstopc = 0;
1508 ch->fepstartca = 0;
1509 ch->fepstopca = 0;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001510
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 ch->close_delay = 50;
1512 ch->count = 0;
1513 ch->blocked_open = 0;
1514 init_waitqueue_head(&ch->open_wait);
1515 init_waitqueue_head(&ch->close_wait);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001516
1517 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001518 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001520 printk(KERN_INFO
1521 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 memwinoff(bd, 0);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001524}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
1526static void epcapoll(unsigned long ignored)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001527{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 unsigned long flags;
1529 int crd;
1530 volatile unsigned int head, tail;
1531 struct channel *ch;
1532 struct board_info *bd;
1533
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001534 /*
1535 * This routine is called upon every timer interrupt. Even though the
1536 * Digi series cards are capable of generating interrupts this method
1537 * of non-looping polling is more efficient. This routine checks for
1538 * card generated events (Such as receive data, are transmit buffer
1539 * empty) and acts on those events.
1540 */
1541 for (crd = 0; crd < num_cards; crd++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 bd = &boards[crd];
1543 ch = card_ptr[crd];
1544
1545 if ((bd->status == DISABLED) || digi_poller_inhibited)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001546 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001548 /*
1549 * assertmemoff is not needed here; indeed it is an empty
1550 * subroutine. It is being kept because future boards may need
1551 * this as well as some legacy boards.
1552 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001553 spin_lock_irqsave(&epca_lock, flags);
1554
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 assertmemoff(ch);
1556
1557 globalwinon(ch);
1558
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001559 /*
1560 * In this case head and tail actually refer to the event queue
1561 * not the transmit or receive queue.
1562 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001563 head = readw(&ch->mailbox->ein);
1564 tail = readw(&ch->mailbox->eout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001566 /* If head isn't equal to tail we have an event */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 if (head != tail)
1568 doevent(crd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 memoff(ch);
1570
Alan Coxf2cf8e22005-09-06 15:16:44 -07001571 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 } /* End for each card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 mod_timer(&epca_timer, jiffies + (HZ / 25));
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001574}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575
1576static void doevent(int crd)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001577{
Al Virobc9a5152005-09-15 22:53:28 +01001578 void __iomem *eventbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 struct channel *ch, *chan0;
1580 static struct tty_struct *tty;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001581 struct board_info *bd;
Al Virobc9a5152005-09-15 22:53:28 +01001582 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001583 unsigned int tail, head;
1584 int event, channel;
1585 int mstat, lstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001587 /*
1588 * This subroutine is called by epcapoll when an event is detected
1589 * in the event queue. This routine responds to those events.
1590 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 bd = &boards[crd];
1592
1593 chan0 = card_ptr[crd];
1594 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 assertgwinon(chan0);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001596 while ((tail = readw(&chan0->mailbox->eout)) != (head = readw(&chan0->mailbox->ein))) { /* Begin while something in event queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 assertgwinon(chan0);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001598 eventbuf = bd->re_map_membase + tail + ISTART;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 /* Get the channel the event occurred on */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001600 channel = readb(eventbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 /* Get the actual event code that occurred */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001602 event = readb(eventbuf + 1);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001603 /*
1604 * The two assignments below get the current modem status
1605 * (mstat) and the previous modem status (lstat). These are
1606 * useful becuase an event could signal a change in modem
1607 * signals itself.
1608 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001609 mstat = readb(eventbuf + 2);
1610 lstat = readb(eventbuf + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 ch = chan0 + channel;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001613 if ((unsigned)channel >= bd->numports || !ch) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 if (channel >= bd->numports)
1615 ch = chan0;
1616 bc = ch->brdchan;
1617 goto next;
1618 }
1619
1620 if ((bc = ch->brdchan) == NULL)
1621 goto next;
1622
Alan Coxf2cf8e22005-09-06 15:16:44 -07001623 if (event & DATA_IND) { /* Begin DATA_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 receive_data(ch);
1625 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 } /* End DATA_IND */
1627 /* else *//* Fix for DCD transition missed bug */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001628 if (event & MODEMCHG_IND) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 /* A modem signal change has been indicated */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 ch->imodem = mstat;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001631 if (ch->asyncflags & ASYNC_CHECK_CD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 if (mstat & ch->dcd) /* We are now receiving dcd */
1633 wake_up_interruptible(&ch->open_wait);
1634 else
1635 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
1636 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 tty = ch->tty;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001639 if (tty) {
1640 if (event & BREAK_IND) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 /* A break has been indicated */
Alan Cox33f0f882006-01-09 20:54:13 -08001642 tty_insert_flip_char(tty, 0, TTY_BREAK);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001643 tty_schedule_flip(tty);
1644 } else if (event & LOWTX_IND) {
1645 if (ch->statusflags & LOWWAIT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 ch->statusflags &= ~LOWWAIT;
1647 tty_wakeup(tty);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001648 }
1649 } else if (event & EMPTYTX_IND) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 /* This event is generated by setup_empty_event */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 ch->statusflags &= ~TXBUSY;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001652 if (ch->statusflags & EMPTYWAIT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 ch->statusflags &= ~EMPTYWAIT;
1654 tty_wakeup(tty);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001655 }
1656 }
1657 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 next:
1659 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001660 BUG_ON(!bc);
1661 writew(1, &bc->idata);
1662 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 globalwinon(chan0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 } /* End while something in event queue */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001665}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
1667static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1668 int byte2, int ncmds, int bytecmd)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001669{
Al Virobc9a5152005-09-15 22:53:28 +01001670 unchar __iomem *memaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 unsigned int head, cmdTail, cmdStart, cmdMax;
1672 long count;
1673 int n;
1674
1675 /* This is the routine in which commands may be passed to the card. */
1676
1677 if (ch->board->status == DISABLED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 /* Remember head (As well as max) is just an offset not a base addr */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001681 head = readw(&ch->mailbox->cin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 /* cmdStart is a base address */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001683 cmdStart = readw(&ch->mailbox->cstart);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001684 /*
1685 * We do the addition below because we do not want a max pointer
1686 * relative to cmdStart. We want a max pointer that points at the
1687 * physical end of the command queue.
1688 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001689 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 memaddr = ch->board->re_map_membase;
1691
Alan Coxf2cf8e22005-09-06 15:16:44 -07001692 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1693 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__, cmd, head);
1694 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__, cmdMax, cmdStart);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 return;
1696 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001697 if (bytecmd) {
1698 writeb(cmd, memaddr + head + cmdStart + 0);
1699 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 /* Below word_or_byte is bits to set */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001701 writeb(word_or_byte, memaddr + head + cmdStart + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 /* Below byte2 is bits to reset */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001703 writeb(byte2, memaddr + head + cmdStart + 3);
1704 } else {
1705 writeb(cmd, memaddr + head + cmdStart + 0);
1706 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1707 writeb(word_or_byte, memaddr + head + cmdStart + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 head = (head + 4) & (cmdMax - cmdStart - 4);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001710 writew(head, &ch->mailbox->cin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 count = FEPTIMEOUT;
1712
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001713 for (;;) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 count--;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001715 if (count == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1717 return;
1718 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001719 head = readw(&ch->mailbox->cin);
1720 cmdTail = readw(&ch->mailbox->cout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001722 /*
1723 * Basically this will break when the FEP acknowledges the
1724 * command by incrementing cmdTail (Making it equal to head).
1725 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 if (n <= ncmds * (sizeof(short) * 4))
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001727 break;
1728 }
1729}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001731/*
1732 * Digi products use fields in their channels structures that are very similar
1733 * to the c_cflag and c_iflag fields typically found in UNIX termios
1734 * structures. The below three routines allow mappings between these hardware
1735 * "flags" and their respective Linux flags.
1736 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001738{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 unsigned res = 0;
1740
Alan Coxf2cf8e22005-09-06 15:16:44 -07001741 if (cflag & CRTSCTS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1743 res |= ((ch->m_cts) | (ch->m_rts));
1744 }
1745
1746 if (ch->digiext.digi_flags & RTSPACE)
1747 res |= ch->m_rts;
1748
1749 if (ch->digiext.digi_flags & DTRPACE)
1750 res |= ch->m_dtr;
1751
1752 if (ch->digiext.digi_flags & CTSPACE)
1753 res |= ch->m_cts;
1754
1755 if (ch->digiext.digi_flags & DSRPACE)
1756 res |= ch->dsr;
1757
1758 if (ch->digiext.digi_flags & DCDPACE)
1759 res |= ch->dcd;
1760
1761 if (res & (ch->m_rts))
1762 ch->digiext.digi_flags |= RTSPACE;
1763
1764 if (res & (ch->m_cts))
1765 ch->digiext.digi_flags |= CTSPACE;
1766
1767 return res;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001768}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001771{
1772 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 INPCK | ISTRIP|IXON|IXANY|IXOFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 if (ch->digiext.digi_flags & DIGI_AIXON)
1775 res |= IAIXON;
1776 return res;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001777}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778
1779static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001780{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 unsigned res = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001782 if (cflag & CBAUDEX) {
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001783 ch->digiext.digi_flags |= DIGI_FAST;
1784 /*
1785 * HUPCL bit is used by FEP to indicate fast baud table is to
1786 * be used.
1787 */
1788 res |= FEP_HUPCL;
1789 } else
1790 ch->digiext.digi_flags &= ~DIGI_FAST;
1791 /*
1792 * CBAUD has bit position 0x1000 set these days to indicate Linux
1793 * baud rate remap. Digi hardware can't handle the bit assignment.
1794 * (We use a different bit assignment for high speed.). Clear this
1795 * bit out.
1796 */
1797 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
1798 /*
1799 * This gets a little confusing. The Digi cards have their own
1800 * representation of c_cflags controling baud rate. For the most part
1801 * this is identical to the Linux implementation. However; Digi
1802 * supports one rate (76800) that Linux doesn't. This means that the
1803 * c_cflag entry that would normally mean 76800 for Digi actually means
1804 * 115200 under Linux. Without the below mapping, a stty 115200 would
1805 * only drive the board at 76800. Since the rate 230400 is also found
1806 * after 76800, the same problem afflicts us when we choose a rate of
1807 * 230400. Without the below modificiation stty 230400 would actually
1808 * give us 115200.
1809 *
1810 * There are two additional differences. The Linux value for CLOCAL
1811 * (0x800; 0004000) has no meaning to the Digi hardware. Also in later
1812 * releases of Linux; the CBAUD define has CBAUDEX (0x1000; 0010000)
1813 * ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX should be
1814 * checked for a screened out prior to termios2digi_c returning. Since
1815 * CLOCAL isn't used by the board this can be ignored as long as the
1816 * returned value is used only by Digi hardware.
1817 */
1818 if (cflag & CBAUDEX) {
1819 /*
1820 * The below code is trying to guarantee that only baud rates
1821 * 115200 and 230400 are remapped. We use exclusive or because
1822 * the various baud rates share common bit positions and
1823 * therefore can't be tested for easily.
1824 */
1825 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 res += 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 return res;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001830}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
Alan Coxf2cf8e22005-09-06 15:16:44 -07001832/* Caller must hold the locks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833static void epcaparam(struct tty_struct *tty, struct channel *ch)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001834{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 unsigned int cmdHead;
Alan Cox606d0992006-12-08 02:38:45 -08001836 struct ktermios *ts;
Al Virobc9a5152005-09-15 22:53:28 +01001837 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 unsigned mval, hflow, cflag, iflag;
1839
1840 bc = ch->brdchan;
1841 epcaassert(bc !=0, "bc out of range");
1842
1843 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 ts = tty->termios;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001845 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
1846 cmdHead = readw(&bc->rin);
Al Virobc9a5152005-09-15 22:53:28 +01001847 writew(cmdHead, &bc->rout);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001848 cmdHead = readw(&bc->tin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 /* Changing baud in mid-stream transmission can be wonderful */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001850 /*
1851 * Flush current transmit buffer by setting cmdTail pointer
1852 * (tout) to cmdHead pointer (tin). Hopefully the transmit
1853 * buffer is empty.
1854 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
1856 mval = 0;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001857 } else { /* Begin CBAUD not detected */
1858 /*
1859 * c_cflags have changed but that change had nothing to do with
1860 * BAUD. Propagate the change to the card.
1861 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 cflag = termios2digi_c(ch, ts->c_cflag);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001863 if (cflag != ch->fepcflag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 ch->fepcflag = cflag;
1865 /* Set baud rate, char size, stop bits, parity */
1866 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
1867 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001868 /*
1869 * If the user has not forced CLOCAL and if the device is not a
1870 * CALLOUT device (Which is always CLOCAL) we set flags such
1871 * that the driver will wait on carrier detect.
1872 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 if (ts->c_cflag & CLOCAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 ch->asyncflags &= ~ASYNC_CHECK_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 ch->asyncflags |= ASYNC_CHECK_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 mval = ch->m_dtr | ch->m_rts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 } /* End CBAUD not detected */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 iflag = termios2digi_i(ch, ts->c_iflag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 /* Check input mode flags */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001881 if (iflag != ch->fepiflag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 ch->fepiflag = iflag;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001883 /*
1884 * Command sets channels iflag structure on the board. Such
1885 * things as input soft flow control, handling of parity
1886 * errors, and break handling are all set here.
1887 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 /* break handling, parity handling, input stripping, flow control chars */
1889 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
1890 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001891 /*
1892 * Set the board mint value for this channel. This will cause hardware
1893 * events to be generated each time the DCD signal (Described in mint)
1894 * changes.
1895 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001896 writeb(ch->dcd, &bc->mint);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
1898 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001899 writeb(0, &bc->mint);
1900 ch->imodem = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 hflow = termios2digi_h(ch, ts->c_cflag);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001902 if (hflow != ch->hflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 ch->hflow = hflow;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001904 /*
1905 * Hard flow control has been selected but the board is not
1906 * using it. Activate hard flow control now.
1907 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
1909 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 mval ^= ch->modemfake & (mval ^ ch->modem);
1911
Alan Coxf2cf8e22005-09-06 15:16:44 -07001912 if (ch->omodem ^ mval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 ch->omodem = mval;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001914 /*
1915 * The below command sets the DTR and RTS mstat structure. If
1916 * hard flow control is NOT active these changes will drive the
1917 * output of the actual DTR and RTS lines. If hard flow control
1918 * is active, the changes will be saved in the mstat structure
1919 * and only asserted when hard flow control is turned off.
1920 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
1922 /* First reset DTR & RTS; then set them */
1923 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
1924 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001926 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 ch->fepstartc = ch->startc;
1928 ch->fepstopc = ch->stopc;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001929 /*
1930 * The XON / XOFF characters have changed; propagate these
1931 * changes to the card.
1932 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
1934 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001935 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 ch->fepstartca = ch->startca;
1937 ch->fepstopca = ch->stopca;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001938 /*
1939 * Similar to the above, this time the auxilarly XON / XOFF
1940 * characters have changed; propagate these changes to the card.
1941 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
1943 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001944}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945
Alan Coxf2cf8e22005-09-06 15:16:44 -07001946/* Caller holds lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947static void receive_data(struct channel *ch)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001948{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 unchar *rptr;
Alan Cox606d0992006-12-08 02:38:45 -08001950 struct ktermios *ts = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 struct tty_struct *tty;
Al Virobc9a5152005-09-15 22:53:28 +01001952 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001953 int dataToRead, wrapgap, bytesAvailable;
1954 unsigned int tail, head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 unsigned int wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001957 /*
1958 * This routine is called by doint when a receive data event has taken
1959 * place.
1960 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 if (ch->statusflags & RXSTOPPED)
1963 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 tty = ch->tty;
1965 if (tty)
1966 ts = tty->termios;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001968 BUG_ON(!bc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 wrapmask = ch->rxbufsize - 1;
1970
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001971 /*
1972 * Get the head and tail pointers to the receiver queue. Wrap the head
1973 * pointer if it has reached the end of the buffer.
1974 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001975 head = readw(&bc->rin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 head &= wrapmask;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001977 tail = readw(&bc->rout) & wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
1979 bytesAvailable = (head - tail) & wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 if (bytesAvailable == 0)
1981 return;
1982
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07001983 /* If CREAD bit is off or device not open, set TX tail to head */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001984 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
Al Virobc9a5152005-09-15 22:53:28 +01001985 writew(head, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 return;
1987 }
1988
Alan Cox33f0f882006-01-09 20:54:13 -08001989 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 return;
1991
Alan Coxf2cf8e22005-09-06 15:16:44 -07001992 if (readb(&bc->orun)) {
1993 writeb(0, &bc->orun);
1994 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",tty->name);
Alan Cox33f0f882006-01-09 20:54:13 -08001995 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 rxwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001998 while (bytesAvailable > 0) { /* Begin while there is data on the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002000 /*
2001 * Even if head has wrapped around only report the amount of
2002 * data to be equal to the size - tail. Remember memcpy can't
2003 * automaticly wrap around the receive buffer.
2004 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002006 /* Make sure we don't overflow the buffer */
Alan Cox33f0f882006-01-09 20:54:13 -08002007 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 if (dataToRead == 0)
2009 break;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002010 /*
2011 * Move data read from our card into the line disciplines
2012 * buffer for translation if necessary.
2013 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002014 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 tail = (tail + dataToRead) & wrapmask;
2016 bytesAvailable -= dataToRead;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 } /* End while there is data on the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002019 writew(tail, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 /* Must be called with global data */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002021 tty_schedule_flip(ch->tty);
2022}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002024static int info_ioctl(struct tty_struct *tty, struct file *file,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 unsigned int cmd, unsigned long arg)
2026{
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002027 switch (cmd) {
2028 case DIGI_GETINFO:
2029 {
2030 struct digi_info di;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 int brd;
2032
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002033 if (get_user(brd, (unsigned int __user *)arg))
Alan Coxf2cf8e22005-09-06 15:16:44 -07002034 return -EFAULT;
2035 if (brd < 0 || brd >= num_cards || num_cards == 0)
2036 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037
2038 memset(&di, 0, sizeof(di));
2039
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002040 di.board = brd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 di.status = boards[brd].status;
2042 di.type = boards[brd].type ;
2043 di.numports = boards[brd].numports ;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002044 /* Legacy fixups - just move along nothing to see */
2045 di.port = (unsigned char *)boards[brd].port ;
2046 di.membase = (unsigned char *)boards[brd].membase ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002048 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 return -EFAULT;
2050 break;
2051
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002052 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002054 case DIGI_POLLER:
2055 {
2056 int brd = arg & 0xff000000 >> 16;
2057 unsigned char state = arg & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058
Alan Coxf2cf8e22005-09-06 15:16:44 -07002059 if (brd < 0 || brd >= num_cards) {
2060 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002061 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002063 digi_poller_inhibited = state;
2064 break;
2065 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002067 case DIGI_INIT:
2068 {
2069 /*
2070 * This call is made by the apps to complete the
2071 * initilization of the board(s). This routine is
2072 * responsible for setting the card to its initial
2073 * state and setting the drivers control fields to the
2074 * sutianle settings for the card in question.
2075 */
2076 int crd;
2077 for (crd = 0; crd < num_cards; crd++)
2078 post_fep_init(crd);
2079 break;
2080 }
2081 default:
2082 return -ENOTTY;
2083 }
2084 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086
2087static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2088{
2089 struct channel *ch = (struct channel *) tty->driver_data;
Al Virobc9a5152005-09-15 22:53:28 +01002090 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 unsigned int mstat, mflag = 0;
2092 unsigned long flags;
2093
2094 if (ch)
2095 bc = ch->brdchan;
2096 else
Alan Coxf2cf8e22005-09-06 15:16:44 -07002097 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
Alan Coxf2cf8e22005-09-06 15:16:44 -07002099 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002101 mstat = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002103 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
2105 if (mstat & ch->m_dtr)
2106 mflag |= TIOCM_DTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 if (mstat & ch->m_rts)
2108 mflag |= TIOCM_RTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 if (mstat & ch->m_cts)
2110 mflag |= TIOCM_CTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 if (mstat & ch->dsr)
2112 mflag |= TIOCM_DSR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 if (mstat & ch->m_ri)
2114 mflag |= TIOCM_RI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 if (mstat & ch->dcd)
2116 mflag |= TIOCM_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 return mflag;
2118}
2119
2120static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2121 unsigned int set, unsigned int clear)
2122{
2123 struct channel *ch = (struct channel *) tty->driver_data;
2124 unsigned long flags;
2125
Alan Coxf2cf8e22005-09-06 15:16:44 -07002126 if (!ch)
2127 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128
Alan Coxf2cf8e22005-09-06 15:16:44 -07002129 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 /*
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002131 * I think this modemfake stuff is broken. It doesn't correctly reflect
2132 * the behaviour desired by the TIOCM* ioctls. Therefore this is
2133 * probably broken.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 */
2135 if (set & TIOCM_RTS) {
2136 ch->modemfake |= ch->m_rts;
2137 ch->modem |= ch->m_rts;
2138 }
2139 if (set & TIOCM_DTR) {
2140 ch->modemfake |= ch->m_dtr;
2141 ch->modem |= ch->m_dtr;
2142 }
2143 if (clear & TIOCM_RTS) {
2144 ch->modemfake |= ch->m_rts;
2145 ch->modem &= ~ch->m_rts;
2146 }
2147 if (clear & TIOCM_DTR) {
2148 ch->modemfake |= ch->m_dtr;
2149 ch->modem &= ~ch->m_dtr;
2150 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 globalwinon(ch);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002152 /*
2153 * The below routine generally sets up parity, baud, flow control
2154 * issues, etc.... It effect both control flags and input flags.
2155 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 epcaparam(tty,ch);
2157 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002158 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 return 0;
2160}
2161
2162static int pc_ioctl(struct tty_struct *tty, struct file * file,
2163 unsigned int cmd, unsigned long arg)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002164{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 digiflow_t dflow;
2166 int retval;
2167 unsigned long flags;
2168 unsigned int mflag, mstat;
2169 unsigned char startc, stopc;
Al Virobc9a5152005-09-15 22:53:28 +01002170 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 struct channel *ch = (struct channel *) tty->driver_data;
2172 void __user *argp = (void __user *)arg;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002173
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 if (ch)
2175 bc = ch->brdchan;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002176 else
Alan Coxf2cf8e22005-09-06 15:16:44 -07002177 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002179 /*
2180 * For POSIX compliance we need to add more ioctls. See tty_ioctl.c in
2181 * /usr/src/linux/drivers/char for a good example. In particular think
2182 * about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
2183 */
2184 switch (cmd) {
2185 case TCSBRK: /* SVID version: non-zero arg --> no break */
2186 retval = tty_check_change(tty);
2187 if (retval)
2188 return retval;
2189 /* Setup an event to indicate when the transmit buffer empties */
2190 spin_lock_irqsave(&epca_lock, flags);
2191 setup_empty_event(tty,ch);
2192 spin_unlock_irqrestore(&epca_lock, flags);
2193 tty_wait_until_sent(tty, 0);
2194 if (!arg)
2195 digi_send_break(ch, HZ / 4); /* 1/4 second */
2196 return 0;
2197 case TCSBRKP: /* support for POSIX tcsendbreak() */
2198 retval = tty_check_change(tty);
2199 if (retval)
2200 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002202 /* Setup an event to indicate when the transmit buffer empties */
2203 spin_lock_irqsave(&epca_lock, flags);
2204 setup_empty_event(tty,ch);
2205 spin_unlock_irqrestore(&epca_lock, flags);
2206 tty_wait_until_sent(tty, 0);
2207 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
2208 return 0;
2209 case TIOCGSOFTCAR:
2210 if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg))
2211 return -EFAULT;
2212 return 0;
2213 case TIOCSSOFTCAR:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 {
2215 unsigned int value;
2216
2217 if (get_user(value, (unsigned __user *)argp))
2218 return -EFAULT;
2219 tty->termios->c_cflag =
2220 ((tty->termios->c_cflag & ~CLOCAL) |
2221 (value ? CLOCAL : 0));
2222 return 0;
2223 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002224 case TIOCMODG:
2225 mflag = pc_tiocmget(tty, file);
2226 if (put_user(mflag, (unsigned long __user *)argp))
2227 return -EFAULT;
2228 break;
2229 case TIOCMODS:
2230 if (get_user(mstat, (unsigned __user *)argp))
2231 return -EFAULT;
2232 return pc_tiocmset(tty, file, mstat, ~mstat);
2233 case TIOCSDTR:
2234 spin_lock_irqsave(&epca_lock, flags);
2235 ch->omodem |= ch->m_dtr;
2236 globalwinon(ch);
2237 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2238 memoff(ch);
2239 spin_unlock_irqrestore(&epca_lock, flags);
2240 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002242 case TIOCCDTR:
2243 spin_lock_irqsave(&epca_lock, flags);
2244 ch->omodem &= ~ch->m_dtr;
2245 globalwinon(ch);
2246 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2247 memoff(ch);
2248 spin_unlock_irqrestore(&epca_lock, flags);
2249 break;
2250 case DIGI_GETA:
2251 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2252 return -EFAULT;
2253 break;
2254 case DIGI_SETAW:
2255 case DIGI_SETAF:
2256 if (cmd == DIGI_SETAW) {
2257 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002258 spin_lock_irqsave(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002259 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002260 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002261 tty_wait_until_sent(tty, 0);
2262 } else {
2263 /* ldisc lock already held in ioctl */
2264 if (tty->ldisc.flush_buffer)
2265 tty->ldisc.flush_buffer(tty);
2266 }
2267 /* Fall Thru */
2268 case DIGI_SETA:
2269 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2270 return -EFAULT;
2271
2272 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
2273 ch->dcd = ch->m_dsr;
2274 ch->dsr = ch->m_dcd;
2275 } else {
2276 ch->dcd = ch->m_dcd;
2277 ch->dsr = ch->m_dsr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002279
2280 spin_lock_irqsave(&epca_lock, flags);
2281 globalwinon(ch);
2282
2283 /*
2284 * The below routine generally sets up parity, baud, flow
2285 * control issues, etc.... It effect both control flags and
2286 * input flags.
2287 */
2288 epcaparam(tty,ch);
2289 memoff(ch);
2290 spin_unlock_irqrestore(&epca_lock, flags);
2291 break;
2292
2293 case DIGI_GETFLOW:
2294 case DIGI_GETAFLOW:
2295 spin_lock_irqsave(&epca_lock, flags);
2296 globalwinon(ch);
2297 if (cmd == DIGI_GETFLOW) {
2298 dflow.startc = readb(&bc->startc);
2299 dflow.stopc = readb(&bc->stopc);
2300 } else {
2301 dflow.startc = readb(&bc->startca);
2302 dflow.stopc = readb(&bc->stopca);
2303 }
2304 memoff(ch);
2305 spin_unlock_irqrestore(&epca_lock, flags);
2306
2307 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2308 return -EFAULT;
2309 break;
2310
2311 case DIGI_SETAFLOW:
2312 case DIGI_SETFLOW:
2313 if (cmd == DIGI_SETFLOW) {
2314 startc = ch->startc;
2315 stopc = ch->stopc;
2316 } else {
2317 startc = ch->startca;
2318 stopc = ch->stopca;
2319 }
2320
2321 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2322 return -EFAULT;
2323
2324 if (dflow.startc != startc || dflow.stopc != stopc) { /* Begin if setflow toggled */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002325 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 globalwinon(ch);
2327
Alan Coxf2cf8e22005-09-06 15:16:44 -07002328 if (cmd == DIGI_SETFLOW) {
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002329 ch->fepstartc = ch->startc = dflow.startc;
2330 ch->fepstopc = ch->stopc = dflow.stopc;
2331 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002332 } else {
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002333 ch->fepstartca = ch->startca = dflow.startc;
2334 ch->fepstopca = ch->stopca = dflow.stopc;
2335 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 }
2337
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002338 if (ch->statusflags & TXSTOPPED)
2339 pc_start(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002341 memoff(ch);
2342 spin_unlock_irqrestore(&epca_lock, flags);
2343 } /* End if setflow toggled */
2344 break;
2345 default:
2346 return -ENOIOCTLCMD;
2347 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 return 0;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002349}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350
Alan Cox606d0992006-12-08 02:38:45 -08002351static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002352{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 struct channel *ch;
2354 unsigned long flags;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002355 /*
2356 * verifyChannel returns the channel from the tty struct if it is
2357 * valid. This serves as a sanity check.
2358 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002359 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
2360 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 globalwinon(ch);
2362 epcaparam(tty, ch);
2363 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002364 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365
2366 if ((old_termios->c_cflag & CRTSCTS) &&
2367 ((tty->termios->c_cflag & CRTSCTS) == 0))
2368 tty->hw_stopped = 0;
2369
2370 if (!(old_termios->c_cflag & CLOCAL) &&
2371 (tty->termios->c_cflag & CLOCAL))
2372 wake_up_interruptible(&ch->open_wait);
2373
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 } /* End if channel valid */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002375}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376
David Howellsc4028952006-11-22 14:57:56 +00002377static void do_softint(struct work_struct *work)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002378{
David Howellsc4028952006-11-22 14:57:56 +00002379 struct channel *ch = container_of(work, struct channel, tqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 /* Called in response to a modem change event */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002381 if (ch && ch->magic == EPCA_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 struct tty_struct *tty = ch->tty;
2383
Alan Coxf2cf8e22005-09-06 15:16:44 -07002384 if (tty && tty->driver_data) {
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002385 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2387 wake_up_interruptible(&ch->open_wait);
2388 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002389 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002391 }
2392}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002394/*
2395 * pc_stop and pc_start provide software flow control to the routine and the
2396 * pc_ioctl routine.
2397 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398static void pc_stop(struct tty_struct *tty)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002399{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 struct channel *ch;
2401 unsigned long flags;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002402 /*
2403 * verifyChannel returns the channel from the tty struct if it is
2404 * valid. This serves as a sanity check.
2405 */
2406 if ((ch = verifyChannel(tty)) != NULL) {
Alan Coxf2cf8e22005-09-06 15:16:44 -07002407 spin_lock_irqsave(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002408 if ((ch->statusflags & TXSTOPPED) == 0) { /* Begin if transmit stop requested */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 /* STOP transmitting now !! */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 ch->statusflags |= TXSTOPPED;
2413 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 } /* End if transmit stop requested */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002415 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002416 }
2417}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418
2419static void pc_start(struct tty_struct *tty)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002420{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 struct channel *ch;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002422 /*
2423 * verifyChannel returns the channel from the tty struct if it is
2424 * valid. This serves as a sanity check.
2425 */
2426 if ((ch = verifyChannel(tty)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 unsigned long flags;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002428 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 /* Just in case output was resumed because of a change in Digi-flow */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002430 if (ch->statusflags & TXSTOPPED) { /* Begin transmit resume requested */
Al Virobc9a5152005-09-15 22:53:28 +01002431 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 globalwinon(ch);
2433 bc = ch->brdchan;
2434 if (ch->statusflags & LOWWAIT)
Alan Coxf2cf8e22005-09-06 15:16:44 -07002435 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 /* Okay, you can start transmitting again... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 ch->statusflags &= ~TXSTOPPED;
2439 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 } /* End transmit resume requested */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002441 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002442 }
2443}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002445/*
2446 * The below routines pc_throttle and pc_unthrottle are used to slow (And
2447 * resume) the receipt of data into the kernels receive buffers. The exact
2448 * occurrence of this depends on the size of the kernels receive buffer and
2449 * what the 'watermarks' are set to for that buffer. See the n_ttys.c file for
2450 * more details.
2451 */
2452static void pc_throttle(struct tty_struct *tty)
2453{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 struct channel *ch;
2455 unsigned long flags;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002456 /*
2457 * verifyChannel returns the channel from the tty struct if it is
2458 * valid. This serves as a sanity check.
2459 */
2460 if ((ch = verifyChannel(tty)) != NULL) {
Alan Coxf2cf8e22005-09-06 15:16:44 -07002461 spin_lock_irqsave(&epca_lock, flags);
2462 if ((ch->statusflags & RXSTOPPED) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 globalwinon(ch);
2464 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 ch->statusflags |= RXSTOPPED;
2466 memoff(ch);
2467 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002468 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002469 }
2470}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471
2472static void pc_unthrottle(struct tty_struct *tty)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002473{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 struct channel *ch;
2475 unsigned long flags;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002476 /*
2477 * verifyChannel returns the channel from the tty struct if it is
2478 * valid. This serves as a sanity check.
2479 */
2480 if ((ch = verifyChannel(tty)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 /* Just in case output was resumed because of a change in Digi-flow */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002482 spin_lock_irqsave(&epca_lock, flags);
2483 if (ch->statusflags & RXSTOPPED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 ch->statusflags &= ~RXSTOPPED;
2487 memoff(ch);
2488 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002489 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002490 }
2491}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492
2493void digi_send_break(struct channel *ch, int msec)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002494{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 unsigned long flags;
2496
Alan Coxf2cf8e22005-09-06 15:16:44 -07002497 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 globalwinon(ch);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002499 /*
2500 * Maybe I should send an infinite break here, schedule() for msec
2501 * amount of time, and then stop the break. This way, the user can't
2502 * screw up the FEP by causing digi_send_break() to be called (i.e. via
2503 * an ioctl()) more than once in msec amount of time.
2504 * Try this for now...
2505 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2507 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002508 spin_unlock_irqrestore(&epca_lock, flags);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002509}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510
Alan Coxf2cf8e22005-09-06 15:16:44 -07002511/* Caller MUST hold the lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002513{
Al Virobc9a5152005-09-15 22:53:28 +01002514 struct board_chan __iomem *bc = ch->brdchan;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 globalwinon(ch);
2517 ch->statusflags |= EMPTYWAIT;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002518 /*
2519 * When set the iempty flag request a event to be generated when the
2520 * transmit buffer is empty (If there is no BREAK in progress).
2521 */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002522 writeb(1, &bc->iempty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 memoff(ch);
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002524}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526void epca_setup(char *str, int *ints)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002527{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 struct board_info board;
2529 int index, loop, last;
2530 char *temp, *t2;
2531 unsigned len;
2532
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002533 /*
2534 * If this routine looks a little strange it is because it is only
2535 * called if a LILO append command is given to boot the kernel with
2536 * parameters. In this way, we can provide the user a method of
2537 * changing his board configuration without rebuilding the kernel.
2538 */
2539 if (!liloconfig)
2540 liloconfig = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541
2542 memset(&board, 0, sizeof(board));
2543
2544 /* Assume the data is int first, later we can change it */
2545 /* I think that array position 0 of ints holds the number of args */
2546 for (last = 0, index = 1; index <= ints[0]; index++)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002547 switch (index) { /* Begin parse switch */
2548 case 1:
2549 board.status = ints[index];
2550 /*
2551 * We check for 2 (As opposed to 1; because 2 is a flag
2552 * instructing the driver to ignore epcaconfig.) For
2553 * this reason we check for 2.
2554 */
2555 if (board.status == 2) { /* Begin ignore epcaconfig as well as lilo cmd line */
2556 nbdevs = 0;
2557 num_cards = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 return;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002559 } /* End ignore epcaconfig as well as lilo cmd line */
2560
2561 if (board.status > 2) {
2562 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n", board.status);
2563 invalid_lilo_config = 1;
2564 setup_error_code |= INVALID_BOARD_STATUS;
2565 return;
2566 }
2567 last = index;
2568 break;
2569 case 2:
2570 board.type = ints[index];
2571 if (board.type >= PCIXEM) {
2572 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
2573 invalid_lilo_config = 1;
2574 setup_error_code |= INVALID_BOARD_TYPE;
2575 return;
2576 }
2577 last = index;
2578 break;
2579 case 3:
2580 board.altpin = ints[index];
2581 if (board.altpin > 1) {
2582 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
2583 invalid_lilo_config = 1;
2584 setup_error_code |= INVALID_ALTPIN;
2585 return;
2586 }
2587 last = index;
2588 break;
2589
2590 case 4:
2591 board.numports = ints[index];
2592 if (board.numports < 2 || board.numports > 256) {
2593 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
2594 invalid_lilo_config = 1;
2595 setup_error_code |= INVALID_NUM_PORTS;
2596 return;
2597 }
2598 nbdevs += board.numports;
2599 last = index;
2600 break;
2601
2602 case 5:
2603 board.port = ints[index];
2604 if (ints[index] <= 0) {
2605 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
2606 invalid_lilo_config = 1;
2607 setup_error_code |= INVALID_PORT_BASE;
2608 return;
2609 }
2610 last = index;
2611 break;
2612
2613 case 6:
2614 board.membase = ints[index];
2615 if (ints[index] <= 0) {
2616 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
2617 invalid_lilo_config = 1;
2618 setup_error_code |= INVALID_MEM_BASE;
2619 return;
2620 }
2621 last = index;
2622 break;
2623
2624 default:
2625 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
2626 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627
2628 } /* End parse switch */
2629
Alan Coxf2cf8e22005-09-06 15:16:44 -07002630 while (str && *str) { /* Begin while there is a string arg */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 /* find the next comma or terminator */
2632 temp = str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 /* While string is not null, and a comma hasn't been found */
2634 while (*temp && (*temp != ','))
2635 temp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 if (!*temp)
2637 temp = NULL;
2638 else
2639 *temp++ = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 /* Set index to the number of args + 1 */
2641 index = last + 1;
2642
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002643 switch (index) {
2644 case 1:
2645 len = strlen(str);
2646 if (strncmp("Disable", str, len) == 0)
2647 board.status = 0;
2648 else if (strncmp("Enable", str, len) == 0)
2649 board.status = 1;
2650 else {
2651 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
2652 invalid_lilo_config = 1;
2653 setup_error_code |= INVALID_BOARD_STATUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 return;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002655 }
2656 last = index;
2657 break;
2658
2659 case 2:
2660 for (loop = 0; loop < EPCA_NUM_TYPES; loop++)
2661 if (strcmp(board_desc[loop], str) == 0)
2662 break;
2663 /*
2664 * If the index incremented above refers to a
2665 * legitamate board type set it here.
2666 */
2667 if (index < EPCA_NUM_TYPES)
2668 board.type = loop;
2669 else {
2670 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
2671 invalid_lilo_config = 1;
2672 setup_error_code |= INVALID_BOARD_TYPE;
2673 return;
2674 }
2675 last = index;
2676 break;
2677
2678 case 3:
2679 len = strlen(str);
2680 if (strncmp("Disable", str, len) == 0)
2681 board.altpin = 0;
2682 else if (strncmp("Enable", str, len) == 0)
2683 board.altpin = 1;
2684 else {
2685 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
2686 invalid_lilo_config = 1;
2687 setup_error_code |= INVALID_ALTPIN;
2688 return;
2689 }
2690 last = index;
2691 break;
2692
2693 case 4:
2694 t2 = str;
2695 while (isdigit(*t2))
2696 t2++;
2697
2698 if (*t2) {
2699 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
2700 invalid_lilo_config = 1;
2701 setup_error_code |= INVALID_NUM_PORTS;
2702 return;
2703 }
2704
2705 /*
2706 * There is not a man page for simple_strtoul but the
2707 * code can be found in vsprintf.c. The first argument
2708 * is the string to translate (To an unsigned long
2709 * obviously), the second argument can be the address
2710 * of any character variable or a NULL. If a variable
2711 * is given, the end pointer of the string will be
2712 * stored in that variable; if a NULL is given the end
2713 * pointer will not be returned. The last argument is
2714 * the base to use. If a 0 is indicated, the routine
2715 * will attempt to determine the proper base by looking
2716 * at the values prefix (A '0' for octal, a 'x' for
2717 * hex, etc ... If a value is given it will use that
2718 * value as the base.
2719 */
2720 board.numports = simple_strtoul(str, NULL, 0);
2721 nbdevs += board.numports;
2722 last = index;
2723 break;
2724
2725 case 5:
2726 t2 = str;
2727 while (isxdigit(*t2))
2728 t2++;
2729
2730 if (*t2) {
2731 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
2732 invalid_lilo_config = 1;
2733 setup_error_code |= INVALID_PORT_BASE;
2734 return;
2735 }
2736
2737 board.port = simple_strtoul(str, NULL, 16);
2738 last = index;
2739 break;
2740
2741 case 6:
2742 t2 = str;
2743 while (isxdigit(*t2))
2744 t2++;
2745
2746 if (*t2) {
2747 printk(KERN_ERR "epca_setup: Invalid memory base %s\n",str);
2748 invalid_lilo_config = 1;
2749 setup_error_code |= INVALID_MEM_BASE;
2750 return;
2751 }
2752 board.membase = simple_strtoul(str, NULL, 16);
2753 last = index;
2754 break;
2755 default:
2756 printk(KERN_ERR "epca: Too many string parms\n");
2757 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 }
2759 str = temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 } /* End while there is a string arg */
2761
Alan Coxf2cf8e22005-09-06 15:16:44 -07002762 if (last < 6) {
2763 printk(KERN_ERR "epca: Insufficient parms specified\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 return;
2765 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002766
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 /* I should REALLY validate the stuff here */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 /* Copies our local copy of board into boards */
2769 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 /* Does this get called once per lilo arg are what ? */
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002771 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2772 num_cards, board_desc[board.type],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 board.numports, (int)board.port, (unsigned int) board.membase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 num_cards++;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002775}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776
2777enum epic_board_types {
2778 brd_xr = 0,
2779 brd_xem,
2780 brd_cx,
2781 brd_xrj,
2782};
2783
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784/* indexed directly by epic_board_types enum */
2785static struct {
2786 unsigned char board_type;
2787 unsigned bar_idx; /* PCI base address region */
2788} epca_info_tbl[] = {
2789 { PCIXR, 0, },
2790 { PCIXEM, 0, },
2791 { PCICX, 0, },
2792 { PCIXRJ, 2, },
2793};
2794
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002795static int __devinit epca_init_one(struct pci_dev *pdev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 const struct pci_device_id *ent)
2797{
2798 static int board_num = -1;
2799 int board_idx, info_idx = ent->driver_data;
2800 unsigned long addr;
2801
2802 if (pci_enable_device(pdev))
2803 return -EIO;
2804
2805 board_num++;
2806 board_idx = board_num + num_cards;
2807 if (board_idx >= MAXBOARDS)
2808 goto err_out;
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002809
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
2811 if (!addr) {
2812 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
2813 epca_info_tbl[info_idx].bar_idx);
2814 goto err_out;
2815 }
2816
2817 boards[board_idx].status = ENABLED;
2818 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
2819 boards[board_idx].numports = 0x0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002820 boards[board_idx].port = addr + PCI_IO_OFFSET;
2821 boards[board_idx].membase = addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822
2823 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
2824 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2825 0x200000, addr + PCI_IO_OFFSET);
2826 goto err_out;
2827 }
2828
2829 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
2830 if (!boards[board_idx].re_map_port) {
2831 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2832 0x200000, addr + PCI_IO_OFFSET);
2833 goto err_out_free_pciio;
2834 }
2835
2836 if (!request_mem_region (addr, 0x200000, "epca")) {
2837 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2838 0x200000, addr);
2839 goto err_out_free_iounmap;
2840 }
2841
2842 boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
2843 if (!boards[board_idx].re_map_membase) {
2844 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2845 0x200000, addr + PCI_IO_OFFSET);
2846 goto err_out_free_memregion;
2847 }
2848
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002849 /*
2850 * I don't know what the below does, but the hardware guys say its
2851 * required on everything except PLX (In this case XRJ).
2852 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 if (info_idx != brd_xrj) {
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002854 pci_write_config_byte(pdev, 0x40, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 pci_write_config_byte(pdev, 0x46, 0);
2856 }
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002857
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 return 0;
2859
2860err_out_free_memregion:
2861 release_mem_region (addr, 0x200000);
2862err_out_free_iounmap:
2863 iounmap (boards[board_idx].re_map_port);
2864err_out_free_pciio:
2865 release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
2866err_out:
2867 return -ENODEV;
2868}
2869
2870
2871static struct pci_device_id epca_pci_tbl[] = {
2872 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
2873 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
2874 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
2875 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
2876 { 0, }
2877};
2878
2879MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
2880
2881int __init init_PCI (void)
Alexey Dobriyanae0b78d2007-10-16 23:26:37 -07002882{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 memset (&epca_driver, 0, sizeof (epca_driver));
2884 epca_driver.name = "epca";
2885 epca_driver.id_table = epca_pci_tbl;
2886 epca_driver.probe = epca_init_one;
2887
2888 return pci_register_driver(&epca_driver);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002889}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890
2891MODULE_LICENSE("GPL");