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