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