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