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