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