Commit 4982d6b37a5ccebe6c2af79970c7a15c1939243a

Authored by Alan Cox
Committed by Linus Torvalds
1 parent 52d417388d

esp: use tty_port

Switch esp to use the new tty_port structures

Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 2 changed files with 138 additions and 143 deletions Inline Diff

1 /* 1 /*
2 * esp.c - driver for Hayes ESP serial cards 2 * esp.c - driver for Hayes ESP serial cards
3 * 3 *
4 * --- Notices from serial.c, upon which this driver is based --- 4 * --- Notices from serial.c, upon which this driver is based ---
5 * 5 *
6 * Copyright (C) 1991, 1992 Linus Torvalds 6 * Copyright (C) 1991, 1992 Linus Torvalds
7 * 7 *
8 * Extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92. Now 8 * Extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92. Now
9 * much more extensible to support other serial cards based on the 9 * much more extensible to support other serial cards based on the
10 * 16450/16550A UART's. Added support for the AST FourPort and the 10 * 16450/16550A UART's. Added support for the AST FourPort and the
11 * Accent Async board. 11 * Accent Async board.
12 * 12 *
13 * set_serial_info fixed to set the flags, custom divisor, and uart 13 * set_serial_info fixed to set the flags, custom divisor, and uart
14 * type fields. Fix suggested by Michael K. Johnson 12/12/92. 14 * type fields. Fix suggested by Michael K. Johnson 12/12/92.
15 * 15 *
16 * 11/95: TIOCMIWAIT, TIOCGICOUNT by Angelo Haritsis <ah@doc.ic.ac.uk> 16 * 11/95: TIOCMIWAIT, TIOCGICOUNT by Angelo Haritsis <ah@doc.ic.ac.uk>
17 * 17 *
18 * 03/96: Modularised by Angelo Haritsis <ah@doc.ic.ac.uk> 18 * 03/96: Modularised by Angelo Haritsis <ah@doc.ic.ac.uk>
19 * 19 *
20 * rs_set_termios fixed to look also for changes of the input 20 * rs_set_termios fixed to look also for changes of the input
21 * flags INPCK, BRKINT, PARMRK, IGNPAR and IGNBRK. 21 * flags INPCK, BRKINT, PARMRK, IGNPAR and IGNBRK.
22 * Bernd Anhäupl 05/17/96. 22 * Bernd Anhäupl 05/17/96.
23 * 23 *
24 * --- End of notices from serial.c --- 24 * --- End of notices from serial.c ---
25 * 25 *
26 * Support for the ESP serial card by Andrew J. Robinson 26 * Support for the ESP serial card by Andrew J. Robinson
27 * <arobinso@nyx.net> (Card detection routine taken from a patch 27 * <arobinso@nyx.net> (Card detection routine taken from a patch
28 * by Dennis J. Boylan). Patches to allow use with 2.1.x contributed 28 * by Dennis J. Boylan). Patches to allow use with 2.1.x contributed
29 * by Chris Faylor. 29 * by Chris Faylor.
30 * 30 *
31 * Most recent changes: (Andrew J. Robinson) 31 * Most recent changes: (Andrew J. Robinson)
32 * Support for PIO mode. This allows the driver to work properly with 32 * Support for PIO mode. This allows the driver to work properly with
33 * multiport cards. 33 * multiport cards.
34 * 34 *
35 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 35 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> -
36 * several cleanups, use module_init/module_exit, etc 36 * several cleanups, use module_init/module_exit, etc
37 * 37 *
38 * This module exports the following rs232 io functions: 38 * This module exports the following rs232 io functions:
39 * 39 *
40 * int espserial_init(void); 40 * int espserial_init(void);
41 */ 41 */
42 42
43 #include <linux/module.h> 43 #include <linux/module.h>
44 #include <linux/errno.h> 44 #include <linux/errno.h>
45 #include <linux/signal.h> 45 #include <linux/signal.h>
46 #include <linux/sched.h> 46 #include <linux/sched.h>
47 #include <linux/interrupt.h> 47 #include <linux/interrupt.h>
48 #include <linux/tty.h> 48 #include <linux/tty.h>
49 #include <linux/tty_flip.h> 49 #include <linux/tty_flip.h>
50 #include <linux/serial.h> 50 #include <linux/serial.h>
51 #include <linux/serialP.h> 51 #include <linux/serialP.h>
52 #include <linux/serial_reg.h> 52 #include <linux/serial_reg.h>
53 #include <linux/major.h> 53 #include <linux/major.h>
54 #include <linux/string.h> 54 #include <linux/string.h>
55 #include <linux/fcntl.h> 55 #include <linux/fcntl.h>
56 #include <linux/ptrace.h> 56 #include <linux/ptrace.h>
57 #include <linux/ioport.h> 57 #include <linux/ioport.h>
58 #include <linux/mm.h> 58 #include <linux/mm.h>
59 #include <linux/init.h> 59 #include <linux/init.h>
60 #include <linux/delay.h> 60 #include <linux/delay.h>
61 #include <linux/bitops.h> 61 #include <linux/bitops.h>
62 62
63 #include <asm/system.h> 63 #include <asm/system.h>
64 #include <linux/io.h> 64 #include <linux/io.h>
65 65
66 #include <asm/dma.h> 66 #include <asm/dma.h>
67 #include <linux/slab.h> 67 #include <linux/slab.h>
68 #include <linux/uaccess.h> 68 #include <linux/uaccess.h>
69 69
70 #include <linux/hayesesp.h> 70 #include <linux/hayesesp.h>
71 71
72 #define NR_PORTS 64 /* maximum number of ports */ 72 #define NR_PORTS 64 /* maximum number of ports */
73 #define NR_PRIMARY 8 /* maximum number of primary ports */ 73 #define NR_PRIMARY 8 /* maximum number of primary ports */
74 #define REGION_SIZE 8 /* size of io region to request */ 74 #define REGION_SIZE 8 /* size of io region to request */
75 75
76 /* The following variables can be set by giving module options */ 76 /* The following variables can be set by giving module options */
77 static int irq[NR_PRIMARY]; /* IRQ for each base port */ 77 static int irq[NR_PRIMARY]; /* IRQ for each base port */
78 static unsigned int divisor[NR_PRIMARY]; /* custom divisor for each port */ 78 static unsigned int divisor[NR_PRIMARY]; /* custom divisor for each port */
79 static unsigned int dma = ESP_DMA_CHANNEL; /* DMA channel */ 79 static unsigned int dma = ESP_DMA_CHANNEL; /* DMA channel */
80 static unsigned int rx_trigger = ESP_RX_TRIGGER; 80 static unsigned int rx_trigger = ESP_RX_TRIGGER;
81 static unsigned int tx_trigger = ESP_TX_TRIGGER; 81 static unsigned int tx_trigger = ESP_TX_TRIGGER;
82 static unsigned int flow_off = ESP_FLOW_OFF; 82 static unsigned int flow_off = ESP_FLOW_OFF;
83 static unsigned int flow_on = ESP_FLOW_ON; 83 static unsigned int flow_on = ESP_FLOW_ON;
84 static unsigned int rx_timeout = ESP_RX_TMOUT; 84 static unsigned int rx_timeout = ESP_RX_TMOUT;
85 static unsigned int pio_threshold = ESP_PIO_THRESHOLD; 85 static unsigned int pio_threshold = ESP_PIO_THRESHOLD;
86 86
87 MODULE_LICENSE("GPL"); 87 MODULE_LICENSE("GPL");
88 88
89 module_param_array(irq, int, NULL, 0); 89 module_param_array(irq, int, NULL, 0);
90 module_param_array(divisor, uint, NULL, 0); 90 module_param_array(divisor, uint, NULL, 0);
91 module_param(dma, uint, 0); 91 module_param(dma, uint, 0);
92 module_param(rx_trigger, uint, 0); 92 module_param(rx_trigger, uint, 0);
93 module_param(tx_trigger, uint, 0); 93 module_param(tx_trigger, uint, 0);
94 module_param(flow_off, uint, 0); 94 module_param(flow_off, uint, 0);
95 module_param(flow_on, uint, 0); 95 module_param(flow_on, uint, 0);
96 module_param(rx_timeout, uint, 0); 96 module_param(rx_timeout, uint, 0);
97 module_param(pio_threshold, uint, 0); 97 module_param(pio_threshold, uint, 0);
98 98
99 /* END */ 99 /* END */
100 100
101 static char *dma_buffer; 101 static char *dma_buffer;
102 static int dma_bytes; 102 static int dma_bytes;
103 static struct esp_pio_buffer *free_pio_buf; 103 static struct esp_pio_buffer *free_pio_buf;
104 104
105 #define DMA_BUFFER_SZ 1024 105 #define DMA_BUFFER_SZ 1024
106 106
107 #define WAKEUP_CHARS 1024 107 #define WAKEUP_CHARS 1024
108 108
109 static char serial_name[] __initdata = "ESP serial driver"; 109 static char serial_name[] __initdata = "ESP serial driver";
110 static char serial_version[] __initdata = "2.2"; 110 static char serial_version[] __initdata = "2.2";
111 111
112 static struct tty_driver *esp_driver; 112 static struct tty_driver *esp_driver;
113 113
114 /* 114 /*
115 * Serial driver configuration section. Here are the various options: 115 * Serial driver configuration section. Here are the various options:
116 * 116 *
117 * SERIAL_PARANOIA_CHECK 117 * SERIAL_PARANOIA_CHECK
118 * Check the magic number for the esp_structure where 118 * Check the magic number for the esp_structure where
119 * ever possible. 119 * ever possible.
120 */ 120 */
121 121
122 #undef SERIAL_PARANOIA_CHECK 122 #undef SERIAL_PARANOIA_CHECK
123 #define SERIAL_DO_RESTART 123 #define SERIAL_DO_RESTART
124 124
125 #undef SERIAL_DEBUG_INTR 125 #undef SERIAL_DEBUG_INTR
126 #undef SERIAL_DEBUG_OPEN 126 #undef SERIAL_DEBUG_OPEN
127 #undef SERIAL_DEBUG_FLOW 127 #undef SERIAL_DEBUG_FLOW
128 128
129 #if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT) 129 #if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT)
130 #define DBG_CNT(s) printk(KERN_DEBUG "(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \ 130 #define DBG_CNT(s) printk(KERN_DEBUG "(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \
131 tty->name, info->flags, \ 131 tty->name, info->port.flags, \
132 serial_driver.refcount, \ 132 serial_driver.refcount, \
133 info->count, tty->count, s) 133 info->port.count, tty->count, s)
134 #else 134 #else
135 #define DBG_CNT(s) 135 #define DBG_CNT(s)
136 #endif 136 #endif
137 137
138 static struct esp_struct *ports; 138 static struct esp_struct *ports;
139 139
140 static void change_speed(struct esp_struct *info); 140 static void change_speed(struct esp_struct *info);
141 static void rs_wait_until_sent(struct tty_struct *, int); 141 static void rs_wait_until_sent(struct tty_struct *, int);
142 142
143 /* 143 /*
144 * The ESP card has a clock rate of 14.7456 MHz (that is, 2**ESPC_SCALE 144 * The ESP card has a clock rate of 14.7456 MHz (that is, 2**ESPC_SCALE
145 * times the normal 1.8432 Mhz clock of most serial boards). 145 * times the normal 1.8432 Mhz clock of most serial boards).
146 */ 146 */
147 #define BASE_BAUD ((1843200 / 16) * (1 << ESPC_SCALE)) 147 #define BASE_BAUD ((1843200 / 16) * (1 << ESPC_SCALE))
148 148
149 /* Standard COM flags (except for COM4, because of the 8514 problem) */ 149 /* Standard COM flags (except for COM4, because of the 8514 problem) */
150 #define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST) 150 #define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST)
151 151
152 static inline int serial_paranoia_check(struct esp_struct *info, 152 static inline int serial_paranoia_check(struct esp_struct *info,
153 char *name, const char *routine) 153 char *name, const char *routine)
154 { 154 {
155 #ifdef SERIAL_PARANOIA_CHECK 155 #ifdef SERIAL_PARANOIA_CHECK
156 static const char badmagic[] = KERN_WARNING 156 static const char badmagic[] = KERN_WARNING
157 "Warning: bad magic number for serial struct (%s) in %s\n"; 157 "Warning: bad magic number for serial struct (%s) in %s\n";
158 static const char badinfo[] = KERN_WARNING 158 static const char badinfo[] = KERN_WARNING
159 "Warning: null esp_struct for (%s) in %s\n"; 159 "Warning: null esp_struct for (%s) in %s\n";
160 160
161 if (!info) { 161 if (!info) {
162 printk(badinfo, name, routine); 162 printk(badinfo, name, routine);
163 return 1; 163 return 1;
164 } 164 }
165 if (info->magic != ESP_MAGIC) { 165 if (info->magic != ESP_MAGIC) {
166 printk(badmagic, name, routine); 166 printk(badmagic, name, routine);
167 return 1; 167 return 1;
168 } 168 }
169 #endif 169 #endif
170 return 0; 170 return 0;
171 } 171 }
172 172
173 static inline unsigned int serial_in(struct esp_struct *info, int offset) 173 static inline unsigned int serial_in(struct esp_struct *info, int offset)
174 { 174 {
175 return inb(info->port + offset); 175 return inb(info->io_port + offset);
176 } 176 }
177 177
178 static inline void serial_out(struct esp_struct *info, int offset, 178 static inline void serial_out(struct esp_struct *info, int offset,
179 unsigned char value) 179 unsigned char value)
180 { 180 {
181 outb(value, info->port+offset); 181 outb(value, info->io_port+offset);
182 } 182 }
183 183
184 /* 184 /*
185 * ------------------------------------------------------------ 185 * ------------------------------------------------------------
186 * rs_stop() and rs_start() 186 * rs_stop() and rs_start()
187 * 187 *
188 * This routines are called before setting or resetting tty->stopped. 188 * This routines are called before setting or resetting tty->stopped.
189 * They enable or disable transmitter interrupts, as necessary. 189 * They enable or disable transmitter interrupts, as necessary.
190 * ------------------------------------------------------------ 190 * ------------------------------------------------------------
191 */ 191 */
192 static void rs_stop(struct tty_struct *tty) 192 static void rs_stop(struct tty_struct *tty)
193 { 193 {
194 struct esp_struct *info = tty->driver_data; 194 struct esp_struct *info = tty->driver_data;
195 unsigned long flags; 195 unsigned long flags;
196 196
197 if (serial_paranoia_check(info, tty->name, "rs_stop")) 197 if (serial_paranoia_check(info, tty->name, "rs_stop"))
198 return; 198 return;
199 199
200 spin_lock_irqsave(&info->lock, flags); 200 spin_lock_irqsave(&info->lock, flags);
201 if (info->IER & UART_IER_THRI) { 201 if (info->IER & UART_IER_THRI) {
202 info->IER &= ~UART_IER_THRI; 202 info->IER &= ~UART_IER_THRI;
203 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK); 203 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
204 serial_out(info, UART_ESI_CMD2, info->IER); 204 serial_out(info, UART_ESI_CMD2, info->IER);
205 } 205 }
206 spin_unlock_irqrestore(&info->lock, flags); 206 spin_unlock_irqrestore(&info->lock, flags);
207 } 207 }
208 208
209 static void rs_start(struct tty_struct *tty) 209 static void rs_start(struct tty_struct *tty)
210 { 210 {
211 struct esp_struct *info = tty->driver_data; 211 struct esp_struct *info = tty->driver_data;
212 unsigned long flags; 212 unsigned long flags;
213 213
214 if (serial_paranoia_check(info, tty->name, "rs_start")) 214 if (serial_paranoia_check(info, tty->name, "rs_start"))
215 return; 215 return;
216 216
217 spin_lock_irqsave(&info->lock, flags); 217 spin_lock_irqsave(&info->lock, flags);
218 if (info->xmit_cnt && info->xmit_buf && !(info->IER & UART_IER_THRI)) { 218 if (info->xmit_cnt && info->xmit_buf && !(info->IER & UART_IER_THRI)) {
219 info->IER |= UART_IER_THRI; 219 info->IER |= UART_IER_THRI;
220 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK); 220 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
221 serial_out(info, UART_ESI_CMD2, info->IER); 221 serial_out(info, UART_ESI_CMD2, info->IER);
222 } 222 }
223 spin_unlock_irqrestore(&info->lock, flags); 223 spin_unlock_irqrestore(&info->lock, flags);
224 } 224 }
225 225
226 /* 226 /*
227 * ---------------------------------------------------------------------- 227 * ----------------------------------------------------------------------
228 * 228 *
229 * Here starts the interrupt handling routines. All of the following 229 * Here starts the interrupt handling routines. All of the following
230 * subroutines are declared as inline and are folded into 230 * subroutines are declared as inline and are folded into
231 * rs_interrupt(). They were separated out for readability's sake. 231 * rs_interrupt(). They were separated out for readability's sake.
232 * 232 *
233 * Note: rs_interrupt() is a "fast" interrupt, which means that it 233 * Note: rs_interrupt() is a "fast" interrupt, which means that it
234 * runs with interrupts turned off. People who may want to modify 234 * runs with interrupts turned off. People who may want to modify
235 * rs_interrupt() should try to keep the interrupt handler as fast as 235 * rs_interrupt() should try to keep the interrupt handler as fast as
236 * possible. After you are done making modifications, it is not a bad 236 * possible. After you are done making modifications, it is not a bad
237 * idea to do: 237 * idea to do:
238 * 238 *
239 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c 239 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
240 * 240 *
241 * and look at the resulting assemble code in serial.s. 241 * and look at the resulting assemble code in serial.s.
242 * 242 *
243 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93 243 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
244 * ----------------------------------------------------------------------- 244 * -----------------------------------------------------------------------
245 */ 245 */
246 246
247 static DEFINE_SPINLOCK(pio_lock); 247 static DEFINE_SPINLOCK(pio_lock);
248 248
249 static inline struct esp_pio_buffer *get_pio_buffer(void) 249 static inline struct esp_pio_buffer *get_pio_buffer(void)
250 { 250 {
251 struct esp_pio_buffer *buf; 251 struct esp_pio_buffer *buf;
252 unsigned long flags; 252 unsigned long flags;
253 253
254 spin_lock_irqsave(&pio_lock, flags); 254 spin_lock_irqsave(&pio_lock, flags);
255 if (free_pio_buf) { 255 if (free_pio_buf) {
256 buf = free_pio_buf; 256 buf = free_pio_buf;
257 free_pio_buf = buf->next; 257 free_pio_buf = buf->next;
258 } else { 258 } else {
259 buf = kmalloc(sizeof(struct esp_pio_buffer), GFP_ATOMIC); 259 buf = kmalloc(sizeof(struct esp_pio_buffer), GFP_ATOMIC);
260 } 260 }
261 spin_unlock_irqrestore(&pio_lock, flags); 261 spin_unlock_irqrestore(&pio_lock, flags);
262 return buf; 262 return buf;
263 } 263 }
264 264
265 static inline void release_pio_buffer(struct esp_pio_buffer *buf) 265 static inline void release_pio_buffer(struct esp_pio_buffer *buf)
266 { 266 {
267 unsigned long flags; 267 unsigned long flags;
268 spin_lock_irqsave(&pio_lock, flags); 268 spin_lock_irqsave(&pio_lock, flags);
269 buf->next = free_pio_buf; 269 buf->next = free_pio_buf;
270 free_pio_buf = buf; 270 free_pio_buf = buf;
271 spin_unlock_irqrestore(&pio_lock, flags); 271 spin_unlock_irqrestore(&pio_lock, flags);
272 } 272 }
273 273
274 static inline void receive_chars_pio(struct esp_struct *info, int num_bytes) 274 static inline void receive_chars_pio(struct esp_struct *info, int num_bytes)
275 { 275 {
276 struct tty_struct *tty = info->tty; 276 struct tty_struct *tty = info->port.tty;
277 int i; 277 int i;
278 struct esp_pio_buffer *pio_buf; 278 struct esp_pio_buffer *pio_buf;
279 struct esp_pio_buffer *err_buf; 279 struct esp_pio_buffer *err_buf;
280 unsigned char status_mask; 280 unsigned char status_mask;
281 281
282 pio_buf = get_pio_buffer(); 282 pio_buf = get_pio_buffer();
283 283
284 if (!pio_buf) 284 if (!pio_buf)
285 return; 285 return;
286 286
287 err_buf = get_pio_buffer(); 287 err_buf = get_pio_buffer();
288 288
289 if (!err_buf) { 289 if (!err_buf) {
290 release_pio_buffer(pio_buf); 290 release_pio_buffer(pio_buf);
291 return; 291 return;
292 } 292 }
293 293
294 status_mask = (info->read_status_mask >> 2) & 0x07; 294 status_mask = (info->read_status_mask >> 2) & 0x07;
295 295
296 for (i = 0; i < num_bytes - 1; i += 2) { 296 for (i = 0; i < num_bytes - 1; i += 2) {
297 *((unsigned short *)(pio_buf->data + i)) = 297 *((unsigned short *)(pio_buf->data + i)) =
298 inw(info->port + UART_ESI_RX); 298 inw(info->io_port + UART_ESI_RX);
299 err_buf->data[i] = serial_in(info, UART_ESI_RWS); 299 err_buf->data[i] = serial_in(info, UART_ESI_RWS);
300 err_buf->data[i + 1] = (err_buf->data[i] >> 3) & status_mask; 300 err_buf->data[i + 1] = (err_buf->data[i] >> 3) & status_mask;
301 err_buf->data[i] &= status_mask; 301 err_buf->data[i] &= status_mask;
302 } 302 }
303 303
304 if (num_bytes & 0x0001) { 304 if (num_bytes & 0x0001) {
305 pio_buf->data[num_bytes - 1] = serial_in(info, UART_ESI_RX); 305 pio_buf->data[num_bytes - 1] = serial_in(info, UART_ESI_RX);
306 err_buf->data[num_bytes - 1] = 306 err_buf->data[num_bytes - 1] =
307 (serial_in(info, UART_ESI_RWS) >> 3) & status_mask; 307 (serial_in(info, UART_ESI_RWS) >> 3) & status_mask;
308 } 308 }
309 309
310 /* make sure everything is still ok since interrupts were enabled */ 310 /* make sure everything is still ok since interrupts were enabled */
311 tty = info->tty; 311 tty = info->port.tty;
312 312
313 if (!tty) { 313 if (!tty) {
314 release_pio_buffer(pio_buf); 314 release_pio_buffer(pio_buf);
315 release_pio_buffer(err_buf); 315 release_pio_buffer(err_buf);
316 info->stat_flags &= ~ESP_STAT_RX_TIMEOUT; 316 info->stat_flags &= ~ESP_STAT_RX_TIMEOUT;
317 return; 317 return;
318 } 318 }
319 319
320 status_mask = (info->ignore_status_mask >> 2) & 0x07; 320 status_mask = (info->ignore_status_mask >> 2) & 0x07;
321 321
322 for (i = 0; i < num_bytes; i++) { 322 for (i = 0; i < num_bytes; i++) {
323 if (!(err_buf->data[i] & status_mask)) { 323 if (!(err_buf->data[i] & status_mask)) {
324 int flag = 0; 324 int flag = 0;
325 325
326 if (err_buf->data[i] & 0x04) { 326 if (err_buf->data[i] & 0x04) {
327 flag = TTY_BREAK; 327 flag = TTY_BREAK;
328 if (info->flags & ASYNC_SAK) 328 if (info->port.flags & ASYNC_SAK)
329 do_SAK(tty); 329 do_SAK(tty);
330 } else if (err_buf->data[i] & 0x02) 330 } else if (err_buf->data[i] & 0x02)
331 flag = TTY_FRAME; 331 flag = TTY_FRAME;
332 else if (err_buf->data[i] & 0x01) 332 else if (err_buf->data[i] & 0x01)
333 flag = TTY_PARITY; 333 flag = TTY_PARITY;
334 tty_insert_flip_char(tty, pio_buf->data[i], flag); 334 tty_insert_flip_char(tty, pio_buf->data[i], flag);
335 } 335 }
336 } 336 }
337 337
338 tty_schedule_flip(tty); 338 tty_schedule_flip(tty);
339 339
340 info->stat_flags &= ~ESP_STAT_RX_TIMEOUT; 340 info->stat_flags &= ~ESP_STAT_RX_TIMEOUT;
341 release_pio_buffer(pio_buf); 341 release_pio_buffer(pio_buf);
342 release_pio_buffer(err_buf); 342 release_pio_buffer(err_buf);
343 } 343 }
344 344
345 static void program_isa_dma(int dma, int dir, unsigned long addr, int len) 345 static void program_isa_dma(int dma, int dir, unsigned long addr, int len)
346 { 346 {
347 unsigned long flags; 347 unsigned long flags;
348 348
349 flags = claim_dma_lock(); 349 flags = claim_dma_lock();
350 disable_dma(dma); 350 disable_dma(dma);
351 clear_dma_ff(dma); 351 clear_dma_ff(dma);
352 set_dma_mode(dma, dir); 352 set_dma_mode(dma, dir);
353 set_dma_addr(dma, addr); 353 set_dma_addr(dma, addr);
354 set_dma_count(dma, len); 354 set_dma_count(dma, len);
355 enable_dma(dma); 355 enable_dma(dma);
356 release_dma_lock(flags); 356 release_dma_lock(flags);
357 } 357 }
358 358
359 static void receive_chars_dma(struct esp_struct *info, int num_bytes) 359 static void receive_chars_dma(struct esp_struct *info, int num_bytes)
360 { 360 {
361 info->stat_flags &= ~ESP_STAT_RX_TIMEOUT; 361 info->stat_flags &= ~ESP_STAT_RX_TIMEOUT;
362 dma_bytes = num_bytes; 362 dma_bytes = num_bytes;
363 info->stat_flags |= ESP_STAT_DMA_RX; 363 info->stat_flags |= ESP_STAT_DMA_RX;
364 364
365 program_isa_dma(dma, DMA_MODE_READ, isa_virt_to_bus(dma_buffer), 365 program_isa_dma(dma, DMA_MODE_READ, isa_virt_to_bus(dma_buffer),
366 dma_bytes); 366 dma_bytes);
367 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_RX); 367 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_RX);
368 } 368 }
369 369
370 static inline void receive_chars_dma_done(struct esp_struct *info, 370 static inline void receive_chars_dma_done(struct esp_struct *info,
371 int status) 371 int status)
372 { 372 {
373 struct tty_struct *tty = info->tty; 373 struct tty_struct *tty = info->port.tty;
374 int num_bytes; 374 int num_bytes;
375 unsigned long flags; 375 unsigned long flags;
376 376
377 flags = claim_dma_lock(); 377 flags = claim_dma_lock();
378 disable_dma(dma); 378 disable_dma(dma);
379 clear_dma_ff(dma); 379 clear_dma_ff(dma);
380 380
381 info->stat_flags &= ~ESP_STAT_DMA_RX; 381 info->stat_flags &= ~ESP_STAT_DMA_RX;
382 num_bytes = dma_bytes - get_dma_residue(dma); 382 num_bytes = dma_bytes - get_dma_residue(dma);
383 release_dma_lock(flags); 383 release_dma_lock(flags);
384 384
385 info->icount.rx += num_bytes; 385 info->icount.rx += num_bytes;
386 386
387 if (num_bytes > 0) { 387 if (num_bytes > 0) {
388 tty_insert_flip_string(tty, dma_buffer, num_bytes - 1); 388 tty_insert_flip_string(tty, dma_buffer, num_bytes - 1);
389 389
390 status &= (0x1c & info->read_status_mask); 390 status &= (0x1c & info->read_status_mask);
391 391
392 /* Is the status significant or do we throw the last byte ? */ 392 /* Is the status significant or do we throw the last byte ? */
393 if (!(status & info->ignore_status_mask)) { 393 if (!(status & info->ignore_status_mask)) {
394 int statflag = 0; 394 int statflag = 0;
395 395
396 if (status & 0x10) { 396 if (status & 0x10) {
397 statflag = TTY_BREAK; 397 statflag = TTY_BREAK;
398 (info->icount.brk)++; 398 (info->icount.brk)++;
399 if (info->flags & ASYNC_SAK) 399 if (info->port.flags & ASYNC_SAK)
400 do_SAK(tty); 400 do_SAK(tty);
401 } else if (status & 0x08) { 401 } else if (status & 0x08) {
402 statflag = TTY_FRAME; 402 statflag = TTY_FRAME;
403 info->icount.frame++; 403 info->icount.frame++;
404 } else if (status & 0x04) { 404 } else if (status & 0x04) {
405 statflag = TTY_PARITY; 405 statflag = TTY_PARITY;
406 info->icount.parity++; 406 info->icount.parity++;
407 } 407 }
408 tty_insert_flip_char(tty, dma_buffer[num_bytes - 1], 408 tty_insert_flip_char(tty, dma_buffer[num_bytes - 1],
409 statflag); 409 statflag);
410 } 410 }
411 tty_schedule_flip(tty); 411 tty_schedule_flip(tty);
412 } 412 }
413 413
414 if (dma_bytes != num_bytes) { 414 if (dma_bytes != num_bytes) {
415 num_bytes = dma_bytes - num_bytes; 415 num_bytes = dma_bytes - num_bytes;
416 dma_bytes = 0; 416 dma_bytes = 0;
417 receive_chars_dma(info, num_bytes); 417 receive_chars_dma(info, num_bytes);
418 } else 418 } else
419 dma_bytes = 0; 419 dma_bytes = 0;
420 } 420 }
421 421
422 /* Caller must hold info->lock */ 422 /* Caller must hold info->lock */
423 423
424 static inline void transmit_chars_pio(struct esp_struct *info, 424 static inline void transmit_chars_pio(struct esp_struct *info,
425 int space_avail) 425 int space_avail)
426 { 426 {
427 int i; 427 int i;
428 struct esp_pio_buffer *pio_buf; 428 struct esp_pio_buffer *pio_buf;
429 429
430 pio_buf = get_pio_buffer(); 430 pio_buf = get_pio_buffer();
431 431
432 if (!pio_buf) 432 if (!pio_buf)
433 return; 433 return;
434 434
435 while (space_avail && info->xmit_cnt) { 435 while (space_avail && info->xmit_cnt) {
436 if (info->xmit_tail + space_avail <= ESP_XMIT_SIZE) { 436 if (info->xmit_tail + space_avail <= ESP_XMIT_SIZE) {
437 memcpy(pio_buf->data, 437 memcpy(pio_buf->data,
438 &(info->xmit_buf[info->xmit_tail]), 438 &(info->xmit_buf[info->xmit_tail]),
439 space_avail); 439 space_avail);
440 } else { 440 } else {
441 i = ESP_XMIT_SIZE - info->xmit_tail; 441 i = ESP_XMIT_SIZE - info->xmit_tail;
442 memcpy(pio_buf->data, 442 memcpy(pio_buf->data,
443 &(info->xmit_buf[info->xmit_tail]), i); 443 &(info->xmit_buf[info->xmit_tail]), i);
444 memcpy(&(pio_buf->data[i]), info->xmit_buf, 444 memcpy(&(pio_buf->data[i]), info->xmit_buf,
445 space_avail - i); 445 space_avail - i);
446 } 446 }
447 447
448 info->xmit_cnt -= space_avail; 448 info->xmit_cnt -= space_avail;
449 info->xmit_tail = (info->xmit_tail + space_avail) & 449 info->xmit_tail = (info->xmit_tail + space_avail) &
450 (ESP_XMIT_SIZE - 1); 450 (ESP_XMIT_SIZE - 1);
451 451
452 for (i = 0; i < space_avail - 1; i += 2) { 452 for (i = 0; i < space_avail - 1; i += 2) {
453 outw(*((unsigned short *)(pio_buf->data + i)), 453 outw(*((unsigned short *)(pio_buf->data + i)),
454 info->port + UART_ESI_TX); 454 info->io_port + UART_ESI_TX);
455 } 455 }
456 456
457 if (space_avail & 0x0001) 457 if (space_avail & 0x0001)
458 serial_out(info, UART_ESI_TX, 458 serial_out(info, UART_ESI_TX,
459 pio_buf->data[space_avail - 1]); 459 pio_buf->data[space_avail - 1]);
460 460
461 if (info->xmit_cnt) { 461 if (info->xmit_cnt) {
462 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND); 462 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
463 serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL); 463 serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL);
464 space_avail = serial_in(info, UART_ESI_STAT1) << 8; 464 space_avail = serial_in(info, UART_ESI_STAT1) << 8;
465 space_avail |= serial_in(info, UART_ESI_STAT2); 465 space_avail |= serial_in(info, UART_ESI_STAT2);
466 466
467 if (space_avail > info->xmit_cnt) 467 if (space_avail > info->xmit_cnt)
468 space_avail = info->xmit_cnt; 468 space_avail = info->xmit_cnt;
469 } 469 }
470 } 470 }
471 471
472 if (info->xmit_cnt < WAKEUP_CHARS) { 472 if (info->xmit_cnt < WAKEUP_CHARS) {
473 if (info->tty) 473 if (info->port.tty)
474 tty_wakeup(info->tty); 474 tty_wakeup(info->port.tty);
475 475
476 #ifdef SERIAL_DEBUG_INTR 476 #ifdef SERIAL_DEBUG_INTR
477 printk("THRE..."); 477 printk("THRE...");
478 #endif 478 #endif
479 479
480 if (info->xmit_cnt <= 0) { 480 if (info->xmit_cnt <= 0) {
481 info->IER &= ~UART_IER_THRI; 481 info->IER &= ~UART_IER_THRI;
482 serial_out(info, UART_ESI_CMD1, 482 serial_out(info, UART_ESI_CMD1,
483 ESI_SET_SRV_MASK); 483 ESI_SET_SRV_MASK);
484 serial_out(info, UART_ESI_CMD2, info->IER); 484 serial_out(info, UART_ESI_CMD2, info->IER);
485 } 485 }
486 } 486 }
487 487
488 release_pio_buffer(pio_buf); 488 release_pio_buffer(pio_buf);
489 } 489 }
490 490
491 /* Caller must hold info->lock */ 491 /* Caller must hold info->lock */
492 static inline void transmit_chars_dma(struct esp_struct *info, int num_bytes) 492 static inline void transmit_chars_dma(struct esp_struct *info, int num_bytes)
493 { 493 {
494 dma_bytes = num_bytes; 494 dma_bytes = num_bytes;
495 495
496 if (info->xmit_tail + dma_bytes <= ESP_XMIT_SIZE) { 496 if (info->xmit_tail + dma_bytes <= ESP_XMIT_SIZE) {
497 memcpy(dma_buffer, &(info->xmit_buf[info->xmit_tail]), 497 memcpy(dma_buffer, &(info->xmit_buf[info->xmit_tail]),
498 dma_bytes); 498 dma_bytes);
499 } else { 499 } else {
500 int i = ESP_XMIT_SIZE - info->xmit_tail; 500 int i = ESP_XMIT_SIZE - info->xmit_tail;
501 memcpy(dma_buffer, &(info->xmit_buf[info->xmit_tail]), 501 memcpy(dma_buffer, &(info->xmit_buf[info->xmit_tail]),
502 i); 502 i);
503 memcpy(&(dma_buffer[i]), info->xmit_buf, dma_bytes - i); 503 memcpy(&(dma_buffer[i]), info->xmit_buf, dma_bytes - i);
504 } 504 }
505 505
506 info->xmit_cnt -= dma_bytes; 506 info->xmit_cnt -= dma_bytes;
507 info->xmit_tail = (info->xmit_tail + dma_bytes) & (ESP_XMIT_SIZE - 1); 507 info->xmit_tail = (info->xmit_tail + dma_bytes) & (ESP_XMIT_SIZE - 1);
508 508
509 if (info->xmit_cnt < WAKEUP_CHARS) { 509 if (info->xmit_cnt < WAKEUP_CHARS) {
510 if (info->tty) 510 if (info->port.tty)
511 tty_wakeup(info->tty); 511 tty_wakeup(info->port.tty);
512 512
513 #ifdef SERIAL_DEBUG_INTR 513 #ifdef SERIAL_DEBUG_INTR
514 printk("THRE..."); 514 printk("THRE...");
515 #endif 515 #endif
516 516
517 if (info->xmit_cnt <= 0) { 517 if (info->xmit_cnt <= 0) {
518 info->IER &= ~UART_IER_THRI; 518 info->IER &= ~UART_IER_THRI;
519 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK); 519 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
520 serial_out(info, UART_ESI_CMD2, info->IER); 520 serial_out(info, UART_ESI_CMD2, info->IER);
521 } 521 }
522 } 522 }
523 523
524 info->stat_flags |= ESP_STAT_DMA_TX; 524 info->stat_flags |= ESP_STAT_DMA_TX;
525 525
526 program_isa_dma(dma, DMA_MODE_WRITE, isa_virt_to_bus(dma_buffer), 526 program_isa_dma(dma, DMA_MODE_WRITE, isa_virt_to_bus(dma_buffer),
527 dma_bytes); 527 dma_bytes);
528 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_TX); 528 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_TX);
529 } 529 }
530 530
531 static inline void transmit_chars_dma_done(struct esp_struct *info) 531 static inline void transmit_chars_dma_done(struct esp_struct *info)
532 { 532 {
533 int num_bytes; 533 int num_bytes;
534 unsigned long flags; 534 unsigned long flags;
535 535
536 flags = claim_dma_lock(); 536 flags = claim_dma_lock();
537 disable_dma(dma); 537 disable_dma(dma);
538 clear_dma_ff(dma); 538 clear_dma_ff(dma);
539 539
540 num_bytes = dma_bytes - get_dma_residue(dma); 540 num_bytes = dma_bytes - get_dma_residue(dma);
541 info->icount.tx += dma_bytes; 541 info->icount.tx += dma_bytes;
542 release_dma_lock(flags); 542 release_dma_lock(flags);
543 543
544 if (dma_bytes != num_bytes) { 544 if (dma_bytes != num_bytes) {
545 dma_bytes -= num_bytes; 545 dma_bytes -= num_bytes;
546 memmove(dma_buffer, dma_buffer + num_bytes, dma_bytes); 546 memmove(dma_buffer, dma_buffer + num_bytes, dma_bytes);
547 547
548 program_isa_dma(dma, DMA_MODE_WRITE, 548 program_isa_dma(dma, DMA_MODE_WRITE,
549 isa_virt_to_bus(dma_buffer), dma_bytes); 549 isa_virt_to_bus(dma_buffer), dma_bytes);
550 550
551 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_TX); 551 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_TX);
552 } else { 552 } else {
553 dma_bytes = 0; 553 dma_bytes = 0;
554 info->stat_flags &= ~ESP_STAT_DMA_TX; 554 info->stat_flags &= ~ESP_STAT_DMA_TX;
555 } 555 }
556 } 556 }
557 557
558 static void check_modem_status(struct esp_struct *info) 558 static void check_modem_status(struct esp_struct *info)
559 { 559 {
560 int status; 560 int status;
561 561
562 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT); 562 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT);
563 status = serial_in(info, UART_ESI_STAT2); 563 status = serial_in(info, UART_ESI_STAT2);
564 564
565 if (status & UART_MSR_ANY_DELTA) { 565 if (status & UART_MSR_ANY_DELTA) {
566 /* update input line counters */ 566 /* update input line counters */
567 if (status & UART_MSR_TERI) 567 if (status & UART_MSR_TERI)
568 info->icount.rng++; 568 info->icount.rng++;
569 if (status & UART_MSR_DDSR) 569 if (status & UART_MSR_DDSR)
570 info->icount.dsr++; 570 info->icount.dsr++;
571 if (status & UART_MSR_DDCD) 571 if (status & UART_MSR_DDCD)
572 info->icount.dcd++; 572 info->icount.dcd++;
573 if (status & UART_MSR_DCTS) 573 if (status & UART_MSR_DCTS)
574 info->icount.cts++; 574 info->icount.cts++;
575 wake_up_interruptible(&info->delta_msr_wait); 575 wake_up_interruptible(&info->delta_msr_wait);
576 } 576 }
577 577
578 if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) { 578 if ((info->port.flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
579 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR)) 579 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
580 printk("ttys%d CD now %s...", info->line, 580 printk("ttys%d CD now %s...", info->line,
581 (status & UART_MSR_DCD) ? "on" : "off"); 581 (status & UART_MSR_DCD) ? "on" : "off");
582 #endif 582 #endif
583 if (status & UART_MSR_DCD) 583 if (status & UART_MSR_DCD)
584 wake_up_interruptible(&info->open_wait); 584 wake_up_interruptible(&info->port.open_wait);
585 else { 585 else {
586 #ifdef SERIAL_DEBUG_OPEN 586 #ifdef SERIAL_DEBUG_OPEN
587 printk("scheduling hangup..."); 587 printk("scheduling hangup...");
588 #endif 588 #endif
589 tty_hangup(info->tty); 589 tty_hangup(info->port.tty);
590 } 590 }
591 } 591 }
592 } 592 }
593 593
594 /* 594 /*
595 * This is the serial driver's interrupt routine 595 * This is the serial driver's interrupt routine
596 */ 596 */
597 static irqreturn_t rs_interrupt_single(int irq, void *dev_id) 597 static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
598 { 598 {
599 struct esp_struct *info; 599 struct esp_struct *info;
600 unsigned err_status; 600 unsigned err_status;
601 unsigned int scratch; 601 unsigned int scratch;
602 602
603 #ifdef SERIAL_DEBUG_INTR 603 #ifdef SERIAL_DEBUG_INTR
604 printk("rs_interrupt_single(%d)...", irq); 604 printk("rs_interrupt_single(%d)...", irq);
605 #endif 605 #endif
606 info = (struct esp_struct *)dev_id; 606 info = (struct esp_struct *)dev_id;
607 err_status = 0; 607 err_status = 0;
608 scratch = serial_in(info, UART_ESI_SID); 608 scratch = serial_in(info, UART_ESI_SID);
609 609
610 spin_lock(&info->lock); 610 spin_lock(&info->lock);
611 611
612 if (!info->tty) { 612 if (!info->port.tty) {
613 spin_unlock(&info->lock); 613 spin_unlock(&info->lock);
614 return IRQ_NONE; 614 return IRQ_NONE;
615 } 615 }
616 616
617 if (scratch & 0x04) { /* error */ 617 if (scratch & 0x04) { /* error */
618 serial_out(info, UART_ESI_CMD1, ESI_GET_ERR_STAT); 618 serial_out(info, UART_ESI_CMD1, ESI_GET_ERR_STAT);
619 err_status = serial_in(info, UART_ESI_STAT1); 619 err_status = serial_in(info, UART_ESI_STAT1);
620 serial_in(info, UART_ESI_STAT2); 620 serial_in(info, UART_ESI_STAT2);
621 621
622 if (err_status & 0x01) 622 if (err_status & 0x01)
623 info->stat_flags |= ESP_STAT_RX_TIMEOUT; 623 info->stat_flags |= ESP_STAT_RX_TIMEOUT;
624 624
625 if (err_status & 0x20) /* UART status */ 625 if (err_status & 0x20) /* UART status */
626 check_modem_status(info); 626 check_modem_status(info);
627 627
628 if (err_status & 0x80) /* Start break */ 628 if (err_status & 0x80) /* Start break */
629 wake_up_interruptible(&info->break_wait); 629 wake_up_interruptible(&info->break_wait);
630 } 630 }
631 631
632 if ((scratch & 0x88) || /* DMA completed or timed out */ 632 if ((scratch & 0x88) || /* DMA completed or timed out */
633 (err_status & 0x1c) /* receive error */) { 633 (err_status & 0x1c) /* receive error */) {
634 if (info->stat_flags & ESP_STAT_DMA_RX) 634 if (info->stat_flags & ESP_STAT_DMA_RX)
635 receive_chars_dma_done(info, err_status); 635 receive_chars_dma_done(info, err_status);
636 else if (info->stat_flags & ESP_STAT_DMA_TX) 636 else if (info->stat_flags & ESP_STAT_DMA_TX)
637 transmit_chars_dma_done(info); 637 transmit_chars_dma_done(info);
638 } 638 }
639 639
640 if (!(info->stat_flags & (ESP_STAT_DMA_RX | ESP_STAT_DMA_TX)) && 640 if (!(info->stat_flags & (ESP_STAT_DMA_RX | ESP_STAT_DMA_TX)) &&
641 ((scratch & 0x01) || (info->stat_flags & ESP_STAT_RX_TIMEOUT)) && 641 ((scratch & 0x01) || (info->stat_flags & ESP_STAT_RX_TIMEOUT)) &&
642 (info->IER & UART_IER_RDI)) { 642 (info->IER & UART_IER_RDI)) {
643 int num_bytes; 643 int num_bytes;
644 644
645 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND); 645 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
646 serial_out(info, UART_ESI_CMD1, ESI_GET_RX_AVAIL); 646 serial_out(info, UART_ESI_CMD1, ESI_GET_RX_AVAIL);
647 num_bytes = serial_in(info, UART_ESI_STAT1) << 8; 647 num_bytes = serial_in(info, UART_ESI_STAT1) << 8;
648 num_bytes |= serial_in(info, UART_ESI_STAT2); 648 num_bytes |= serial_in(info, UART_ESI_STAT2);
649 649
650 num_bytes = tty_buffer_request_room(info->tty, num_bytes); 650 num_bytes = tty_buffer_request_room(info->port.tty, num_bytes);
651 651
652 if (num_bytes) { 652 if (num_bytes) {
653 if (dma_bytes || 653 if (dma_bytes ||
654 (info->stat_flags & ESP_STAT_USE_PIO) || 654 (info->stat_flags & ESP_STAT_USE_PIO) ||
655 (num_bytes <= info->config.pio_threshold)) 655 (num_bytes <= info->config.pio_threshold))
656 receive_chars_pio(info, num_bytes); 656 receive_chars_pio(info, num_bytes);
657 else 657 else
658 receive_chars_dma(info, num_bytes); 658 receive_chars_dma(info, num_bytes);
659 } 659 }
660 } 660 }
661 661
662 if (!(info->stat_flags & (ESP_STAT_DMA_RX | ESP_STAT_DMA_TX)) && 662 if (!(info->stat_flags & (ESP_STAT_DMA_RX | ESP_STAT_DMA_TX)) &&
663 (scratch & 0x02) && (info->IER & UART_IER_THRI)) { 663 (scratch & 0x02) && (info->IER & UART_IER_THRI)) {
664 if ((info->xmit_cnt <= 0) || info->tty->stopped) { 664 if ((info->xmit_cnt <= 0) || info->port.tty->stopped) {
665 info->IER &= ~UART_IER_THRI; 665 info->IER &= ~UART_IER_THRI;
666 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK); 666 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
667 serial_out(info, UART_ESI_CMD2, info->IER); 667 serial_out(info, UART_ESI_CMD2, info->IER);
668 } else { 668 } else {
669 int num_bytes; 669 int num_bytes;
670 670
671 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND); 671 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
672 serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL); 672 serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL);
673 num_bytes = serial_in(info, UART_ESI_STAT1) << 8; 673 num_bytes = serial_in(info, UART_ESI_STAT1) << 8;
674 num_bytes |= serial_in(info, UART_ESI_STAT2); 674 num_bytes |= serial_in(info, UART_ESI_STAT2);
675 675
676 if (num_bytes > info->xmit_cnt) 676 if (num_bytes > info->xmit_cnt)
677 num_bytes = info->xmit_cnt; 677 num_bytes = info->xmit_cnt;
678 678
679 if (num_bytes) { 679 if (num_bytes) {
680 if (dma_bytes || 680 if (dma_bytes ||
681 (info->stat_flags & ESP_STAT_USE_PIO) || 681 (info->stat_flags & ESP_STAT_USE_PIO) ||
682 (num_bytes <= info->config.pio_threshold)) 682 (num_bytes <= info->config.pio_threshold))
683 transmit_chars_pio(info, num_bytes); 683 transmit_chars_pio(info, num_bytes);
684 else 684 else
685 transmit_chars_dma(info, num_bytes); 685 transmit_chars_dma(info, num_bytes);
686 } 686 }
687 } 687 }
688 } 688 }
689 689
690 info->last_active = jiffies; 690 info->last_active = jiffies;
691 691
692 #ifdef SERIAL_DEBUG_INTR 692 #ifdef SERIAL_DEBUG_INTR
693 printk("end.\n"); 693 printk("end.\n");
694 #endif 694 #endif
695 spin_unlock(&info->lock); 695 spin_unlock(&info->lock);
696 return IRQ_HANDLED; 696 return IRQ_HANDLED;
697 } 697 }
698 698
699 /* 699 /*
700 * ------------------------------------------------------------------- 700 * -------------------------------------------------------------------
701 * Here ends the serial interrupt routines. 701 * Here ends the serial interrupt routines.
702 * ------------------------------------------------------------------- 702 * -------------------------------------------------------------------
703 */ 703 */
704 704
705 /* 705 /*
706 * --------------------------------------------------------------- 706 * ---------------------------------------------------------------
707 * Low level utility subroutines for the serial driver: routines to 707 * Low level utility subroutines for the serial driver: routines to
708 * figure out the appropriate timeout for an interrupt chain, routines 708 * figure out the appropriate timeout for an interrupt chain, routines
709 * to initialize and startup a serial port, and routines to shutdown a 709 * to initialize and startup a serial port, and routines to shutdown a
710 * serial port. Useful stuff like that. 710 * serial port. Useful stuff like that.
711 * 711 *
712 * Caller should hold lock 712 * Caller should hold lock
713 * --------------------------------------------------------------- 713 * ---------------------------------------------------------------
714 */ 714 */
715 715
716 static void esp_basic_init(struct esp_struct *info) 716 static void esp_basic_init(struct esp_struct *info)
717 { 717 {
718 /* put ESPC in enhanced mode */ 718 /* put ESPC in enhanced mode */
719 serial_out(info, UART_ESI_CMD1, ESI_SET_MODE); 719 serial_out(info, UART_ESI_CMD1, ESI_SET_MODE);
720 720
721 if (info->stat_flags & ESP_STAT_NEVER_DMA) 721 if (info->stat_flags & ESP_STAT_NEVER_DMA)
722 serial_out(info, UART_ESI_CMD2, 0x01); 722 serial_out(info, UART_ESI_CMD2, 0x01);
723 else 723 else
724 serial_out(info, UART_ESI_CMD2, 0x31); 724 serial_out(info, UART_ESI_CMD2, 0x31);
725 725
726 /* disable interrupts for now */ 726 /* disable interrupts for now */
727 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK); 727 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
728 serial_out(info, UART_ESI_CMD2, 0x00); 728 serial_out(info, UART_ESI_CMD2, 0x00);
729 729
730 /* set interrupt and DMA channel */ 730 /* set interrupt and DMA channel */
731 serial_out(info, UART_ESI_CMD1, ESI_SET_IRQ); 731 serial_out(info, UART_ESI_CMD1, ESI_SET_IRQ);
732 732
733 if (info->stat_flags & ESP_STAT_NEVER_DMA) 733 if (info->stat_flags & ESP_STAT_NEVER_DMA)
734 serial_out(info, UART_ESI_CMD2, 0x01); 734 serial_out(info, UART_ESI_CMD2, 0x01);
735 else 735 else
736 serial_out(info, UART_ESI_CMD2, (dma << 4) | 0x01); 736 serial_out(info, UART_ESI_CMD2, (dma << 4) | 0x01);
737 737
738 serial_out(info, UART_ESI_CMD1, ESI_SET_ENH_IRQ); 738 serial_out(info, UART_ESI_CMD1, ESI_SET_ENH_IRQ);
739 739
740 if (info->line % 8) /* secondary port */ 740 if (info->line % 8) /* secondary port */
741 serial_out(info, UART_ESI_CMD2, 0x0d); /* shared */ 741 serial_out(info, UART_ESI_CMD2, 0x0d); /* shared */
742 else if (info->irq == 9) 742 else if (info->irq == 9)
743 serial_out(info, UART_ESI_CMD2, 0x02); 743 serial_out(info, UART_ESI_CMD2, 0x02);
744 else 744 else
745 serial_out(info, UART_ESI_CMD2, info->irq); 745 serial_out(info, UART_ESI_CMD2, info->irq);
746 746
747 /* set error status mask (check this) */ 747 /* set error status mask (check this) */
748 serial_out(info, UART_ESI_CMD1, ESI_SET_ERR_MASK); 748 serial_out(info, UART_ESI_CMD1, ESI_SET_ERR_MASK);
749 749
750 if (info->stat_flags & ESP_STAT_NEVER_DMA) 750 if (info->stat_flags & ESP_STAT_NEVER_DMA)
751 serial_out(info, UART_ESI_CMD2, 0xa1); 751 serial_out(info, UART_ESI_CMD2, 0xa1);
752 else 752 else
753 serial_out(info, UART_ESI_CMD2, 0xbd); 753 serial_out(info, UART_ESI_CMD2, 0xbd);
754 754
755 serial_out(info, UART_ESI_CMD2, 0x00); 755 serial_out(info, UART_ESI_CMD2, 0x00);
756 756
757 /* set DMA timeout */ 757 /* set DMA timeout */
758 serial_out(info, UART_ESI_CMD1, ESI_SET_DMA_TMOUT); 758 serial_out(info, UART_ESI_CMD1, ESI_SET_DMA_TMOUT);
759 serial_out(info, UART_ESI_CMD2, 0xff); 759 serial_out(info, UART_ESI_CMD2, 0xff);
760 760
761 /* set FIFO trigger levels */ 761 /* set FIFO trigger levels */
762 serial_out(info, UART_ESI_CMD1, ESI_SET_TRIGGER); 762 serial_out(info, UART_ESI_CMD1, ESI_SET_TRIGGER);
763 serial_out(info, UART_ESI_CMD2, info->config.rx_trigger >> 8); 763 serial_out(info, UART_ESI_CMD2, info->config.rx_trigger >> 8);
764 serial_out(info, UART_ESI_CMD2, info->config.rx_trigger); 764 serial_out(info, UART_ESI_CMD2, info->config.rx_trigger);
765 serial_out(info, UART_ESI_CMD2, info->config.tx_trigger >> 8); 765 serial_out(info, UART_ESI_CMD2, info->config.tx_trigger >> 8);
766 serial_out(info, UART_ESI_CMD2, info->config.tx_trigger); 766 serial_out(info, UART_ESI_CMD2, info->config.tx_trigger);
767 767
768 /* Set clock scaling and wait states */ 768 /* Set clock scaling and wait states */
769 serial_out(info, UART_ESI_CMD1, ESI_SET_PRESCALAR); 769 serial_out(info, UART_ESI_CMD1, ESI_SET_PRESCALAR);
770 serial_out(info, UART_ESI_CMD2, 0x04 | ESPC_SCALE); 770 serial_out(info, UART_ESI_CMD2, 0x04 | ESPC_SCALE);
771 771
772 /* set reinterrupt pacing */ 772 /* set reinterrupt pacing */
773 serial_out(info, UART_ESI_CMD1, ESI_SET_REINTR); 773 serial_out(info, UART_ESI_CMD1, ESI_SET_REINTR);
774 serial_out(info, UART_ESI_CMD2, 0xff); 774 serial_out(info, UART_ESI_CMD2, 0xff);
775 } 775 }
776 776
777 static int startup(struct esp_struct *info) 777 static int startup(struct esp_struct *info)
778 { 778 {
779 unsigned long flags; 779 unsigned long flags;
780 int retval = 0; 780 int retval = 0;
781 unsigned int num_chars; 781 unsigned int num_chars;
782 782
783 spin_lock_irqsave(&info->lock, flags); 783 spin_lock_irqsave(&info->lock, flags);
784 784
785 if (info->flags & ASYNC_INITIALIZED) 785 if (info->port.flags & ASYNC_INITIALIZED)
786 goto out; 786 goto out;
787 787
788 if (!info->xmit_buf) { 788 if (!info->xmit_buf) {
789 info->xmit_buf = (unsigned char *)get_zeroed_page(GFP_ATOMIC); 789 info->xmit_buf = (unsigned char *)get_zeroed_page(GFP_ATOMIC);
790 retval = -ENOMEM; 790 retval = -ENOMEM;
791 if (!info->xmit_buf) 791 if (!info->xmit_buf)
792 goto out; 792 goto out;
793 } 793 }
794 794
795 #ifdef SERIAL_DEBUG_OPEN 795 #ifdef SERIAL_DEBUG_OPEN
796 printk(KERN_DEBUG "starting up ttys%d (irq %d)...", 796 printk(KERN_DEBUG "starting up ttys%d (irq %d)...",
797 info->line, info->irq); 797 info->line, info->irq);
798 #endif 798 #endif
799 799
800 /* Flush the RX buffer. Using the ESI flush command may cause */ 800 /* Flush the RX buffer. Using the ESI flush command may cause */
801 /* wild interrupts, so read all the data instead. */ 801 /* wild interrupts, so read all the data instead. */
802 802
803 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND); 803 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
804 serial_out(info, UART_ESI_CMD1, ESI_GET_RX_AVAIL); 804 serial_out(info, UART_ESI_CMD1, ESI_GET_RX_AVAIL);
805 num_chars = serial_in(info, UART_ESI_STAT1) << 8; 805 num_chars = serial_in(info, UART_ESI_STAT1) << 8;
806 num_chars |= serial_in(info, UART_ESI_STAT2); 806 num_chars |= serial_in(info, UART_ESI_STAT2);
807 807
808 while (num_chars > 1) { 808 while (num_chars > 1) {
809 inw(info->port + UART_ESI_RX); 809 inw(info->io_port + UART_ESI_RX);
810 num_chars -= 2; 810 num_chars -= 2;
811 } 811 }
812 812
813 if (num_chars) 813 if (num_chars)
814 serial_in(info, UART_ESI_RX); 814 serial_in(info, UART_ESI_RX);
815 815
816 /* set receive character timeout */ 816 /* set receive character timeout */
817 serial_out(info, UART_ESI_CMD1, ESI_SET_RX_TIMEOUT); 817 serial_out(info, UART_ESI_CMD1, ESI_SET_RX_TIMEOUT);
818 serial_out(info, UART_ESI_CMD2, info->config.rx_timeout); 818 serial_out(info, UART_ESI_CMD2, info->config.rx_timeout);
819 819
820 /* clear all flags except the "never DMA" flag */ 820 /* clear all flags except the "never DMA" flag */
821 info->stat_flags &= ESP_STAT_NEVER_DMA; 821 info->stat_flags &= ESP_STAT_NEVER_DMA;
822 822
823 if (info->stat_flags & ESP_STAT_NEVER_DMA) 823 if (info->stat_flags & ESP_STAT_NEVER_DMA)
824 info->stat_flags |= ESP_STAT_USE_PIO; 824 info->stat_flags |= ESP_STAT_USE_PIO;
825 825
826 spin_unlock_irqrestore(&info->lock, flags); 826 spin_unlock_irqrestore(&info->lock, flags);
827 827
828 /* 828 /*
829 * Allocate the IRQ 829 * Allocate the IRQ
830 */ 830 */
831 831
832 retval = request_irq(info->irq, rs_interrupt_single, IRQF_SHARED, 832 retval = request_irq(info->irq, rs_interrupt_single, IRQF_SHARED,
833 "esp serial", info); 833 "esp serial", info);
834 834
835 if (retval) { 835 if (retval) {
836 if (capable(CAP_SYS_ADMIN)) { 836 if (capable(CAP_SYS_ADMIN)) {
837 if (info->tty) 837 if (info->port.tty)
838 set_bit(TTY_IO_ERROR, 838 set_bit(TTY_IO_ERROR,
839 &info->tty->flags); 839 &info->port.tty->flags);
840 retval = 0; 840 retval = 0;
841 } 841 }
842 goto out_unlocked; 842 goto out_unlocked;
843 } 843 }
844 844
845 if (!(info->stat_flags & ESP_STAT_USE_PIO) && !dma_buffer) { 845 if (!(info->stat_flags & ESP_STAT_USE_PIO) && !dma_buffer) {
846 dma_buffer = (char *)__get_dma_pages( 846 dma_buffer = (char *)__get_dma_pages(
847 GFP_KERNEL, get_order(DMA_BUFFER_SZ)); 847 GFP_KERNEL, get_order(DMA_BUFFER_SZ));
848 848
849 /* use PIO mode if DMA buf/chan cannot be allocated */ 849 /* use PIO mode if DMA buf/chan cannot be allocated */
850 if (!dma_buffer) 850 if (!dma_buffer)
851 info->stat_flags |= ESP_STAT_USE_PIO; 851 info->stat_flags |= ESP_STAT_USE_PIO;
852 else if (request_dma(dma, "esp serial")) { 852 else if (request_dma(dma, "esp serial")) {
853 free_pages((unsigned long)dma_buffer, 853 free_pages((unsigned long)dma_buffer,
854 get_order(DMA_BUFFER_SZ)); 854 get_order(DMA_BUFFER_SZ));
855 dma_buffer = NULL; 855 dma_buffer = NULL;
856 info->stat_flags |= ESP_STAT_USE_PIO; 856 info->stat_flags |= ESP_STAT_USE_PIO;
857 } 857 }
858 858
859 } 859 }
860 860
861 info->MCR = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2; 861 info->MCR = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2;
862 862
863 spin_lock_irqsave(&info->lock, flags); 863 spin_lock_irqsave(&info->lock, flags);
864 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART); 864 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
865 serial_out(info, UART_ESI_CMD2, UART_MCR); 865 serial_out(info, UART_ESI_CMD2, UART_MCR);
866 serial_out(info, UART_ESI_CMD2, info->MCR); 866 serial_out(info, UART_ESI_CMD2, info->MCR);
867 867
868 /* 868 /*
869 * Finally, enable interrupts 869 * Finally, enable interrupts
870 */ 870 */
871 /* info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI; */ 871 /* info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI; */
872 info->IER = UART_IER_RLSI | UART_IER_RDI | UART_IER_DMA_TMOUT | 872 info->IER = UART_IER_RLSI | UART_IER_RDI | UART_IER_DMA_TMOUT |
873 UART_IER_DMA_TC; 873 UART_IER_DMA_TC;
874 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK); 874 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
875 serial_out(info, UART_ESI_CMD2, info->IER); 875 serial_out(info, UART_ESI_CMD2, info->IER);
876 876
877 if (info->tty) 877 if (info->port.tty)
878 clear_bit(TTY_IO_ERROR, &info->tty->flags); 878 clear_bit(TTY_IO_ERROR, &info->port.tty->flags);
879 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 879 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
880 spin_unlock_irqrestore(&info->lock, flags); 880 spin_unlock_irqrestore(&info->lock, flags);
881 881
882 /* 882 /*
883 * Set up the tty->alt_speed kludge 883 * Set up the tty->alt_speed kludge
884 */ 884 */
885 if (info->tty) { 885 if (info->port.tty) {
886 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 886 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
887 info->tty->alt_speed = 57600; 887 info->port.tty->alt_speed = 57600;
888 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 888 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
889 info->tty->alt_speed = 115200; 889 info->port.tty->alt_speed = 115200;
890 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) 890 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
891 info->tty->alt_speed = 230400; 891 info->port.tty->alt_speed = 230400;
892 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) 892 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
893 info->tty->alt_speed = 460800; 893 info->port.tty->alt_speed = 460800;
894 } 894 }
895 895
896 /* 896 /*
897 * set the speed of the serial port 897 * set the speed of the serial port
898 */ 898 */
899 change_speed(info); 899 change_speed(info);
900 info->flags |= ASYNC_INITIALIZED; 900 info->port.flags |= ASYNC_INITIALIZED;
901 return 0; 901 return 0;
902 902
903 out: 903 out:
904 spin_unlock_irqrestore(&info->lock, flags); 904 spin_unlock_irqrestore(&info->lock, flags);
905 out_unlocked: 905 out_unlocked:
906 return retval; 906 return retval;
907 } 907 }
908 908
909 /* 909 /*
910 * This routine will shutdown a serial port; interrupts are disabled, and 910 * This routine will shutdown a serial port; interrupts are disabled, and
911 * DTR is dropped if the hangup on close termio flag is on. 911 * DTR is dropped if the hangup on close termio flag is on.
912 */ 912 */
913 static void shutdown(struct esp_struct *info) 913 static void shutdown(struct esp_struct *info)
914 { 914 {
915 unsigned long flags, f; 915 unsigned long flags, f;
916 916
917 if (!(info->flags & ASYNC_INITIALIZED)) 917 if (!(info->port.flags & ASYNC_INITIALIZED))
918 return; 918 return;
919 919
920 #ifdef SERIAL_DEBUG_OPEN 920 #ifdef SERIAL_DEBUG_OPEN
921 printk("Shutting down serial port %d (irq %d)....", info->line, 921 printk("Shutting down serial port %d (irq %d)....", info->line,
922 info->irq); 922 info->irq);
923 #endif 923 #endif
924 924
925 spin_lock_irqsave(&info->lock, flags); 925 spin_lock_irqsave(&info->lock, flags);
926 /* 926 /*
927 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq 927 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
928 * here so the queue might never be waken up 928 * here so the queue might never be waken up
929 */ 929 */
930 wake_up_interruptible(&info->delta_msr_wait); 930 wake_up_interruptible(&info->delta_msr_wait);
931 wake_up_interruptible(&info->break_wait); 931 wake_up_interruptible(&info->break_wait);
932 932
933 /* stop a DMA transfer on the port being closed */ 933 /* stop a DMA transfer on the port being closed */
934 /* DMA lock is higher priority always */ 934 /* DMA lock is higher priority always */
935 if (info->stat_flags & (ESP_STAT_DMA_RX | ESP_STAT_DMA_TX)) { 935 if (info->stat_flags & (ESP_STAT_DMA_RX | ESP_STAT_DMA_TX)) {
936 f = claim_dma_lock(); 936 f = claim_dma_lock();
937 disable_dma(dma); 937 disable_dma(dma);
938 clear_dma_ff(dma); 938 clear_dma_ff(dma);
939 release_dma_lock(f); 939 release_dma_lock(f);
940 940
941 dma_bytes = 0; 941 dma_bytes = 0;
942 } 942 }
943 943
944 /* 944 /*
945 * Free the IRQ 945 * Free the IRQ
946 */ 946 */
947 free_irq(info->irq, info); 947 free_irq(info->irq, info);
948 948
949 if (dma_buffer) { 949 if (dma_buffer) {
950 struct esp_struct *current_port = ports; 950 struct esp_struct *current_port = ports;
951 951
952 while (current_port) { 952 while (current_port) {
953 if ((current_port != info) && 953 if ((current_port != info) &&
954 (current_port->flags & ASYNC_INITIALIZED)) 954 (current_port->port.flags & ASYNC_INITIALIZED))
955 break; 955 break;
956 956
957 current_port = current_port->next_port; 957 current_port = current_port->next_port;
958 } 958 }
959 959
960 if (!current_port) { 960 if (!current_port) {
961 free_dma(dma); 961 free_dma(dma);
962 free_pages((unsigned long)dma_buffer, 962 free_pages((unsigned long)dma_buffer,
963 get_order(DMA_BUFFER_SZ)); 963 get_order(DMA_BUFFER_SZ));
964 dma_buffer = NULL; 964 dma_buffer = NULL;
965 } 965 }
966 } 966 }
967 967
968 if (info->xmit_buf) { 968 if (info->xmit_buf) {
969 free_page((unsigned long) info->xmit_buf); 969 free_page((unsigned long) info->xmit_buf);
970 info->xmit_buf = NULL; 970 info->xmit_buf = NULL;
971 } 971 }
972 972
973 info->IER = 0; 973 info->IER = 0;
974 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK); 974 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
975 serial_out(info, UART_ESI_CMD2, 0x00); 975 serial_out(info, UART_ESI_CMD2, 0x00);
976 976
977 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) 977 if (!info->port.tty || (info->port.tty->termios->c_cflag & HUPCL))
978 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS); 978 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
979 979
980 info->MCR &= ~UART_MCR_OUT2; 980 info->MCR &= ~UART_MCR_OUT2;
981 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART); 981 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
982 serial_out(info, UART_ESI_CMD2, UART_MCR); 982 serial_out(info, UART_ESI_CMD2, UART_MCR);
983 serial_out(info, UART_ESI_CMD2, info->MCR); 983 serial_out(info, UART_ESI_CMD2, info->MCR);
984 984
985 if (info->tty) 985 if (info->port.tty)
986 set_bit(TTY_IO_ERROR, &info->tty->flags); 986 set_bit(TTY_IO_ERROR, &info->port.tty->flags);
987 987
988 info->flags &= ~ASYNC_INITIALIZED; 988 info->port.flags &= ~ASYNC_INITIALIZED;
989 spin_unlock_irqrestore(&info->lock, flags); 989 spin_unlock_irqrestore(&info->lock, flags);
990 } 990 }
991 991
992 /* 992 /*
993 * This routine is called to set the UART divisor registers to match 993 * This routine is called to set the UART divisor registers to match
994 * the specified baud rate for a serial port. 994 * the specified baud rate for a serial port.
995 */ 995 */
996 static void change_speed(struct esp_struct *info) 996 static void change_speed(struct esp_struct *info)
997 { 997 {
998 unsigned short port; 998 unsigned short port;
999 int quot = 0; 999 int quot = 0;
1000 unsigned cflag, cval; 1000 unsigned cflag, cval;
1001 int baud, bits; 1001 int baud, bits;
1002 unsigned char flow1 = 0, flow2 = 0; 1002 unsigned char flow1 = 0, flow2 = 0;
1003 unsigned long flags; 1003 unsigned long flags;
1004 1004
1005 if (!info->tty || !info->tty->termios) 1005 if (!info->port.tty || !info->port.tty->termios)
1006 return; 1006 return;
1007 cflag = info->tty->termios->c_cflag; 1007 cflag = info->port.tty->termios->c_cflag;
1008 port = info->port; 1008 port = info->io_port;
1009 1009
1010 /* byte size and parity */ 1010 /* byte size and parity */
1011 switch (cflag & CSIZE) { 1011 switch (cflag & CSIZE) {
1012 case CS5: cval = 0x00; bits = 7; break; 1012 case CS5: cval = 0x00; bits = 7; break;
1013 case CS6: cval = 0x01; bits = 8; break; 1013 case CS6: cval = 0x01; bits = 8; break;
1014 case CS7: cval = 0x02; bits = 9; break; 1014 case CS7: cval = 0x02; bits = 9; break;
1015 case CS8: cval = 0x03; bits = 10; break; 1015 case CS8: cval = 0x03; bits = 10; break;
1016 default: cval = 0x00; bits = 7; break; 1016 default: cval = 0x00; bits = 7; break;
1017 } 1017 }
1018 if (cflag & CSTOPB) { 1018 if (cflag & CSTOPB) {
1019 cval |= 0x04; 1019 cval |= 0x04;
1020 bits++; 1020 bits++;
1021 } 1021 }
1022 if (cflag & PARENB) { 1022 if (cflag & PARENB) {
1023 cval |= UART_LCR_PARITY; 1023 cval |= UART_LCR_PARITY;
1024 bits++; 1024 bits++;
1025 } 1025 }
1026 if (!(cflag & PARODD)) 1026 if (!(cflag & PARODD))
1027 cval |= UART_LCR_EPAR; 1027 cval |= UART_LCR_EPAR;
1028 #ifdef CMSPAR 1028 #ifdef CMSPAR
1029 if (cflag & CMSPAR) 1029 if (cflag & CMSPAR)
1030 cval |= UART_LCR_SPAR; 1030 cval |= UART_LCR_SPAR;
1031 #endif 1031 #endif
1032 baud = tty_get_baud_rate(info->tty); 1032 baud = tty_get_baud_rate(info->port.tty);
1033 if (baud == 38400 && 1033 if (baud == 38400 &&
1034 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) 1034 ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST))
1035 quot = info->custom_divisor; 1035 quot = info->custom_divisor;
1036 else { 1036 else {
1037 if (baud == 134) /* Special case since 134 is really 134.5 */ 1037 if (baud == 134) /* Special case since 134 is really 134.5 */
1038 quot = (2*BASE_BAUD / 269); 1038 quot = (2*BASE_BAUD / 269);
1039 else if (baud) 1039 else if (baud)
1040 quot = BASE_BAUD / baud; 1040 quot = BASE_BAUD / baud;
1041 } 1041 }
1042 /* If the quotient is ever zero, default to 9600 bps */ 1042 /* If the quotient is ever zero, default to 9600 bps */
1043 if (!quot) 1043 if (!quot)
1044 quot = BASE_BAUD / 9600; 1044 quot = BASE_BAUD / 9600;
1045 1045
1046 if (baud) { 1046 if (baud) {
1047 /* Actual rate */ 1047 /* Actual rate */
1048 baud = BASE_BAUD/quot; 1048 baud = BASE_BAUD/quot;
1049 tty_encode_baud_rate(info->tty, baud, baud); 1049 tty_encode_baud_rate(info->port.tty, baud, baud);
1050 } 1050 }
1051 info->timeout = ((1024 * HZ * bits * quot) / BASE_BAUD) + (HZ / 50); 1051 info->timeout = ((1024 * HZ * bits * quot) / BASE_BAUD) + (HZ / 50);
1052 1052
1053 /* CTS flow control flag and modem status interrupts */ 1053 /* CTS flow control flag and modem status interrupts */
1054 /* info->IER &= ~UART_IER_MSI; */ 1054 /* info->IER &= ~UART_IER_MSI; */
1055 if (cflag & CRTSCTS) { 1055 if (cflag & CRTSCTS) {
1056 info->flags |= ASYNC_CTS_FLOW; 1056 info->port.flags |= ASYNC_CTS_FLOW;
1057 /* info->IER |= UART_IER_MSI; */ 1057 /* info->IER |= UART_IER_MSI; */
1058 flow1 = 0x04; 1058 flow1 = 0x04;
1059 flow2 = 0x10; 1059 flow2 = 0x10;
1060 } else 1060 } else
1061 info->flags &= ~ASYNC_CTS_FLOW; 1061 info->port.flags &= ~ASYNC_CTS_FLOW;
1062 if (cflag & CLOCAL) 1062 if (cflag & CLOCAL)
1063 info->flags &= ~ASYNC_CHECK_CD; 1063 info->port.flags &= ~ASYNC_CHECK_CD;
1064 else 1064 else
1065 info->flags |= ASYNC_CHECK_CD; 1065 info->port.flags |= ASYNC_CHECK_CD;
1066 1066
1067 /* 1067 /*
1068 * Set up parity check flag 1068 * Set up parity check flag
1069 */ 1069 */
1070 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; 1070 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
1071 if (I_INPCK(info->tty)) 1071 if (I_INPCK(info->port.tty))
1072 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE; 1072 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
1073 if (I_BRKINT(info->tty) || I_PARMRK(info->tty)) 1073 if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty))
1074 info->read_status_mask |= UART_LSR_BI; 1074 info->read_status_mask |= UART_LSR_BI;
1075 1075
1076 info->ignore_status_mask = 0; 1076 info->ignore_status_mask = 0;
1077 #if 0 1077 #if 0
1078 /* This should be safe, but for some broken bits of hardware... */ 1078 /* This should be safe, but for some broken bits of hardware... */
1079 if (I_IGNPAR(info->tty)) { 1079 if (I_IGNPAR(info->port.tty)) {
1080 info->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; 1080 info->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
1081 info->read_status_mask |= UART_LSR_PE | UART_LSR_FE; 1081 info->read_status_mask |= UART_LSR_PE | UART_LSR_FE;
1082 } 1082 }
1083 #endif 1083 #endif
1084 if (I_IGNBRK(info->tty)) { 1084 if (I_IGNBRK(info->port.tty)) {
1085 info->ignore_status_mask |= UART_LSR_BI; 1085 info->ignore_status_mask |= UART_LSR_BI;
1086 info->read_status_mask |= UART_LSR_BI; 1086 info->read_status_mask |= UART_LSR_BI;
1087 /* 1087 /*
1088 * If we're ignore parity and break indicators, ignore 1088 * If we're ignore parity and break indicators, ignore
1089 * overruns too. (For real raw support). 1089 * overruns too. (For real raw support).
1090 */ 1090 */
1091 if (I_IGNPAR(info->tty)) { 1091 if (I_IGNPAR(info->port.tty)) {
1092 info->ignore_status_mask |= UART_LSR_OE | \ 1092 info->ignore_status_mask |= UART_LSR_OE | \
1093 UART_LSR_PE | UART_LSR_FE; 1093 UART_LSR_PE | UART_LSR_FE;
1094 info->read_status_mask |= UART_LSR_OE | \ 1094 info->read_status_mask |= UART_LSR_OE | \
1095 UART_LSR_PE | UART_LSR_FE; 1095 UART_LSR_PE | UART_LSR_FE;
1096 } 1096 }
1097 } 1097 }
1098 1098
1099 if (I_IXOFF(info->tty)) 1099 if (I_IXOFF(info->port.tty))
1100 flow1 |= 0x81; 1100 flow1 |= 0x81;
1101 1101
1102 spin_lock_irqsave(&info->lock, flags); 1102 spin_lock_irqsave(&info->lock, flags);
1103 /* set baud */ 1103 /* set baud */
1104 serial_out(info, UART_ESI_CMD1, ESI_SET_BAUD); 1104 serial_out(info, UART_ESI_CMD1, ESI_SET_BAUD);
1105 serial_out(info, UART_ESI_CMD2, quot >> 8); 1105 serial_out(info, UART_ESI_CMD2, quot >> 8);
1106 serial_out(info, UART_ESI_CMD2, quot & 0xff); 1106 serial_out(info, UART_ESI_CMD2, quot & 0xff);
1107 1107
1108 /* set data bits, parity, etc. */ 1108 /* set data bits, parity, etc. */
1109 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART); 1109 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
1110 serial_out(info, UART_ESI_CMD2, UART_LCR); 1110 serial_out(info, UART_ESI_CMD2, UART_LCR);
1111 serial_out(info, UART_ESI_CMD2, cval); 1111 serial_out(info, UART_ESI_CMD2, cval);
1112 1112
1113 /* Enable flow control */ 1113 /* Enable flow control */
1114 serial_out(info, UART_ESI_CMD1, ESI_SET_FLOW_CNTL); 1114 serial_out(info, UART_ESI_CMD1, ESI_SET_FLOW_CNTL);
1115 serial_out(info, UART_ESI_CMD2, flow1); 1115 serial_out(info, UART_ESI_CMD2, flow1);
1116 serial_out(info, UART_ESI_CMD2, flow2); 1116 serial_out(info, UART_ESI_CMD2, flow2);
1117 1117
1118 /* set flow control characters (XON/XOFF only) */ 1118 /* set flow control characters (XON/XOFF only) */
1119 if (I_IXOFF(info->tty)) { 1119 if (I_IXOFF(info->port.tty)) {
1120 serial_out(info, UART_ESI_CMD1, ESI_SET_FLOW_CHARS); 1120 serial_out(info, UART_ESI_CMD1, ESI_SET_FLOW_CHARS);
1121 serial_out(info, UART_ESI_CMD2, START_CHAR(info->tty)); 1121 serial_out(info, UART_ESI_CMD2, START_CHAR(info->port.tty));
1122 serial_out(info, UART_ESI_CMD2, STOP_CHAR(info->tty)); 1122 serial_out(info, UART_ESI_CMD2, STOP_CHAR(info->port.tty));
1123 serial_out(info, UART_ESI_CMD2, 0x10); 1123 serial_out(info, UART_ESI_CMD2, 0x10);
1124 serial_out(info, UART_ESI_CMD2, 0x21); 1124 serial_out(info, UART_ESI_CMD2, 0x21);
1125 switch (cflag & CSIZE) { 1125 switch (cflag & CSIZE) {
1126 case CS5: 1126 case CS5:
1127 serial_out(info, UART_ESI_CMD2, 0x1f); 1127 serial_out(info, UART_ESI_CMD2, 0x1f);
1128 break; 1128 break;
1129 case CS6: 1129 case CS6:
1130 serial_out(info, UART_ESI_CMD2, 0x3f); 1130 serial_out(info, UART_ESI_CMD2, 0x3f);
1131 break; 1131 break;
1132 case CS7: 1132 case CS7:
1133 case CS8: 1133 case CS8:
1134 serial_out(info, UART_ESI_CMD2, 0x7f); 1134 serial_out(info, UART_ESI_CMD2, 0x7f);
1135 break; 1135 break;
1136 default: 1136 default:
1137 serial_out(info, UART_ESI_CMD2, 0xff); 1137 serial_out(info, UART_ESI_CMD2, 0xff);
1138 break; 1138 break;
1139 } 1139 }
1140 } 1140 }
1141 1141
1142 /* Set high/low water */ 1142 /* Set high/low water */
1143 serial_out(info, UART_ESI_CMD1, ESI_SET_FLOW_LVL); 1143 serial_out(info, UART_ESI_CMD1, ESI_SET_FLOW_LVL);
1144 serial_out(info, UART_ESI_CMD2, info->config.flow_off >> 8); 1144 serial_out(info, UART_ESI_CMD2, info->config.flow_off >> 8);
1145 serial_out(info, UART_ESI_CMD2, info->config.flow_off); 1145 serial_out(info, UART_ESI_CMD2, info->config.flow_off);
1146 serial_out(info, UART_ESI_CMD2, info->config.flow_on >> 8); 1146 serial_out(info, UART_ESI_CMD2, info->config.flow_on >> 8);
1147 serial_out(info, UART_ESI_CMD2, info->config.flow_on); 1147 serial_out(info, UART_ESI_CMD2, info->config.flow_on);
1148 1148
1149 spin_unlock_irqrestore(&info->lock, flags); 1149 spin_unlock_irqrestore(&info->lock, flags);
1150 } 1150 }
1151 1151
1152 static int rs_put_char(struct tty_struct *tty, unsigned char ch) 1152 static int rs_put_char(struct tty_struct *tty, unsigned char ch)
1153 { 1153 {
1154 struct esp_struct *info = tty->driver_data; 1154 struct esp_struct *info = tty->driver_data;
1155 unsigned long flags; 1155 unsigned long flags;
1156 int ret = 0; 1156 int ret = 0;
1157 1157
1158 if (serial_paranoia_check(info, tty->name, "rs_put_char")) 1158 if (serial_paranoia_check(info, tty->name, "rs_put_char"))
1159 return 0; 1159 return 0;
1160 1160
1161 if (!info->xmit_buf) 1161 if (!info->xmit_buf)
1162 return 0; 1162 return 0;
1163 1163
1164 spin_lock_irqsave(&info->lock, flags); 1164 spin_lock_irqsave(&info->lock, flags);
1165 if (info->xmit_cnt < ESP_XMIT_SIZE - 1) { 1165 if (info->xmit_cnt < ESP_XMIT_SIZE - 1) {
1166 info->xmit_buf[info->xmit_head++] = ch; 1166 info->xmit_buf[info->xmit_head++] = ch;
1167 info->xmit_head &= ESP_XMIT_SIZE-1; 1167 info->xmit_head &= ESP_XMIT_SIZE-1;
1168 info->xmit_cnt++; 1168 info->xmit_cnt++;
1169 ret = 1; 1169 ret = 1;
1170 } 1170 }
1171 spin_unlock_irqrestore(&info->lock, flags); 1171 spin_unlock_irqrestore(&info->lock, flags);
1172 return ret; 1172 return ret;
1173 } 1173 }
1174 1174
1175 static void rs_flush_chars(struct tty_struct *tty) 1175 static void rs_flush_chars(struct tty_struct *tty)
1176 { 1176 {
1177 struct esp_struct *info = tty->driver_data; 1177 struct esp_struct *info = tty->driver_data;
1178 unsigned long flags; 1178 unsigned long flags;
1179 1179
1180 if (serial_paranoia_check(info, tty->name, "rs_flush_chars")) 1180 if (serial_paranoia_check(info, tty->name, "rs_flush_chars"))
1181 return; 1181 return;
1182 1182
1183 spin_lock_irqsave(&info->lock, flags); 1183 spin_lock_irqsave(&info->lock, flags);
1184 1184
1185 if (info->xmit_cnt <= 0 || tty->stopped || !info->xmit_buf) 1185 if (info->xmit_cnt <= 0 || tty->stopped || !info->xmit_buf)
1186 goto out; 1186 goto out;
1187 1187
1188 if (!(info->IER & UART_IER_THRI)) { 1188 if (!(info->IER & UART_IER_THRI)) {
1189 info->IER |= UART_IER_THRI; 1189 info->IER |= UART_IER_THRI;
1190 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK); 1190 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
1191 serial_out(info, UART_ESI_CMD2, info->IER); 1191 serial_out(info, UART_ESI_CMD2, info->IER);
1192 } 1192 }
1193 out: 1193 out:
1194 spin_unlock_irqrestore(&info->lock, flags); 1194 spin_unlock_irqrestore(&info->lock, flags);
1195 } 1195 }
1196 1196
1197 static int rs_write(struct tty_struct *tty, 1197 static int rs_write(struct tty_struct *tty,
1198 const unsigned char *buf, int count) 1198 const unsigned char *buf, int count)
1199 { 1199 {
1200 int c, t, ret = 0; 1200 int c, t, ret = 0;
1201 struct esp_struct *info = tty->driver_data; 1201 struct esp_struct *info = tty->driver_data;
1202 unsigned long flags; 1202 unsigned long flags;
1203 1203
1204 if (serial_paranoia_check(info, tty->name, "rs_write")) 1204 if (serial_paranoia_check(info, tty->name, "rs_write"))
1205 return 0; 1205 return 0;
1206 1206
1207 if (!info->xmit_buf) 1207 if (!info->xmit_buf)
1208 return 0; 1208 return 0;
1209 1209
1210 while (1) { 1210 while (1) {
1211 /* Thanks to R. Wolff for suggesting how to do this with */ 1211 /* Thanks to R. Wolff for suggesting how to do this with */
1212 /* interrupts enabled */ 1212 /* interrupts enabled */
1213 1213
1214 c = count; 1214 c = count;
1215 t = ESP_XMIT_SIZE - info->xmit_cnt - 1; 1215 t = ESP_XMIT_SIZE - info->xmit_cnt - 1;
1216 1216
1217 if (t < c) 1217 if (t < c)
1218 c = t; 1218 c = t;
1219 1219
1220 t = ESP_XMIT_SIZE - info->xmit_head; 1220 t = ESP_XMIT_SIZE - info->xmit_head;
1221 1221
1222 if (t < c) 1222 if (t < c)
1223 c = t; 1223 c = t;
1224 1224
1225 if (c <= 0) 1225 if (c <= 0)
1226 break; 1226 break;
1227 1227
1228 memcpy(info->xmit_buf + info->xmit_head, buf, c); 1228 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1229 1229
1230 info->xmit_head = (info->xmit_head + c) & (ESP_XMIT_SIZE-1); 1230 info->xmit_head = (info->xmit_head + c) & (ESP_XMIT_SIZE-1);
1231 info->xmit_cnt += c; 1231 info->xmit_cnt += c;
1232 buf += c; 1232 buf += c;
1233 count -= c; 1233 count -= c;
1234 ret += c; 1234 ret += c;
1235 } 1235 }
1236 1236
1237 spin_lock_irqsave(&info->lock, flags); 1237 spin_lock_irqsave(&info->lock, flags);
1238 1238
1239 if (info->xmit_cnt && !tty->stopped && !(info->IER & UART_IER_THRI)) { 1239 if (info->xmit_cnt && !tty->stopped && !(info->IER & UART_IER_THRI)) {
1240 info->IER |= UART_IER_THRI; 1240 info->IER |= UART_IER_THRI;
1241 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK); 1241 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
1242 serial_out(info, UART_ESI_CMD2, info->IER); 1242 serial_out(info, UART_ESI_CMD2, info->IER);
1243 } 1243 }
1244 1244
1245 spin_unlock_irqrestore(&info->lock, flags); 1245 spin_unlock_irqrestore(&info->lock, flags);
1246 return ret; 1246 return ret;
1247 } 1247 }
1248 1248
1249 static int rs_write_room(struct tty_struct *tty) 1249 static int rs_write_room(struct tty_struct *tty)
1250 { 1250 {
1251 struct esp_struct *info = tty->driver_data; 1251 struct esp_struct *info = tty->driver_data;
1252 int ret; 1252 int ret;
1253 unsigned long flags; 1253 unsigned long flags;
1254 1254
1255 if (serial_paranoia_check(info, tty->name, "rs_write_room")) 1255 if (serial_paranoia_check(info, tty->name, "rs_write_room"))
1256 return 0; 1256 return 0;
1257 1257
1258 spin_lock_irqsave(&info->lock, flags); 1258 spin_lock_irqsave(&info->lock, flags);
1259 1259
1260 ret = ESP_XMIT_SIZE - info->xmit_cnt - 1; 1260 ret = ESP_XMIT_SIZE - info->xmit_cnt - 1;
1261 if (ret < 0) 1261 if (ret < 0)
1262 ret = 0; 1262 ret = 0;
1263 spin_unlock_irqrestore(&info->lock, flags); 1263 spin_unlock_irqrestore(&info->lock, flags);
1264 return ret; 1264 return ret;
1265 } 1265 }
1266 1266
1267 static int rs_chars_in_buffer(struct tty_struct *tty) 1267 static int rs_chars_in_buffer(struct tty_struct *tty)
1268 { 1268 {
1269 struct esp_struct *info = tty->driver_data; 1269 struct esp_struct *info = tty->driver_data;
1270 1270
1271 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer")) 1271 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
1272 return 0; 1272 return 0;
1273 return info->xmit_cnt; 1273 return info->xmit_cnt;
1274 } 1274 }
1275 1275
1276 static void rs_flush_buffer(struct tty_struct *tty) 1276 static void rs_flush_buffer(struct tty_struct *tty)
1277 { 1277 {
1278 struct esp_struct *info = tty->driver_data; 1278 struct esp_struct *info = tty->driver_data;
1279 unsigned long flags; 1279 unsigned long flags;
1280 1280
1281 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer")) 1281 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
1282 return; 1282 return;
1283 spin_lock_irqsave(&info->lock, flags); 1283 spin_lock_irqsave(&info->lock, flags);
1284 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 1284 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1285 spin_unlock_irqrestore(&info->lock, flags); 1285 spin_unlock_irqrestore(&info->lock, flags);
1286 tty_wakeup(tty); 1286 tty_wakeup(tty);
1287 } 1287 }
1288 1288
1289 /* 1289 /*
1290 * ------------------------------------------------------------ 1290 * ------------------------------------------------------------
1291 * rs_throttle() 1291 * rs_throttle()
1292 * 1292 *
1293 * This routine is called by the upper-layer tty layer to signal that 1293 * This routine is called by the upper-layer tty layer to signal that
1294 * incoming characters should be throttled. 1294 * incoming characters should be throttled.
1295 * ------------------------------------------------------------ 1295 * ------------------------------------------------------------
1296 */ 1296 */
1297 static void rs_throttle(struct tty_struct *tty) 1297 static void rs_throttle(struct tty_struct *tty)
1298 { 1298 {
1299 struct esp_struct *info = tty->driver_data; 1299 struct esp_struct *info = tty->driver_data;
1300 unsigned long flags; 1300 unsigned long flags;
1301 #ifdef SERIAL_DEBUG_THROTTLE 1301 #ifdef SERIAL_DEBUG_THROTTLE
1302 char buf[64]; 1302 char buf[64];
1303 1303
1304 printk("throttle %s: %d....\n", tty_name(tty, buf), 1304 printk("throttle %s: %d....\n", tty_name(tty, buf),
1305 tty_chars_in_buffer(tty)); 1305 tty_chars_in_buffer(tty));
1306 #endif 1306 #endif
1307 1307
1308 if (serial_paranoia_check(info, tty->name, "rs_throttle")) 1308 if (serial_paranoia_check(info, tty->name, "rs_throttle"))
1309 return; 1309 return;
1310 1310
1311 spin_lock_irqsave(&info->lock, flags); 1311 spin_lock_irqsave(&info->lock, flags);
1312 info->IER &= ~UART_IER_RDI; 1312 info->IER &= ~UART_IER_RDI;
1313 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK); 1313 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
1314 serial_out(info, UART_ESI_CMD2, info->IER); 1314 serial_out(info, UART_ESI_CMD2, info->IER);
1315 serial_out(info, UART_ESI_CMD1, ESI_SET_RX_TIMEOUT); 1315 serial_out(info, UART_ESI_CMD1, ESI_SET_RX_TIMEOUT);
1316 serial_out(info, UART_ESI_CMD2, 0x00); 1316 serial_out(info, UART_ESI_CMD2, 0x00);
1317 spin_unlock_irqrestore(&info->lock, flags); 1317 spin_unlock_irqrestore(&info->lock, flags);
1318 } 1318 }
1319 1319
1320 static void rs_unthrottle(struct tty_struct *tty) 1320 static void rs_unthrottle(struct tty_struct *tty)
1321 { 1321 {
1322 struct esp_struct *info = tty->driver_data; 1322 struct esp_struct *info = tty->driver_data;
1323 unsigned long flags; 1323 unsigned long flags;
1324 #ifdef SERIAL_DEBUG_THROTTLE 1324 #ifdef SERIAL_DEBUG_THROTTLE
1325 char buf[64]; 1325 char buf[64];
1326 1326
1327 printk(KERN_DEBUG "unthrottle %s: %d....\n", tty_name(tty, buf), 1327 printk(KERN_DEBUG "unthrottle %s: %d....\n", tty_name(tty, buf),
1328 tty_chars_in_buffer(tty)); 1328 tty_chars_in_buffer(tty));
1329 #endif 1329 #endif
1330 1330
1331 if (serial_paranoia_check(info, tty->name, "rs_unthrottle")) 1331 if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
1332 return; 1332 return;
1333 1333
1334 spin_lock_irqsave(&info->lock, flags); 1334 spin_lock_irqsave(&info->lock, flags);
1335 info->IER |= UART_IER_RDI; 1335 info->IER |= UART_IER_RDI;
1336 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK); 1336 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
1337 serial_out(info, UART_ESI_CMD2, info->IER); 1337 serial_out(info, UART_ESI_CMD2, info->IER);
1338 serial_out(info, UART_ESI_CMD1, ESI_SET_RX_TIMEOUT); 1338 serial_out(info, UART_ESI_CMD1, ESI_SET_RX_TIMEOUT);
1339 serial_out(info, UART_ESI_CMD2, info->config.rx_timeout); 1339 serial_out(info, UART_ESI_CMD2, info->config.rx_timeout);
1340 spin_unlock_irqrestore(&info->lock, flags); 1340 spin_unlock_irqrestore(&info->lock, flags);
1341 } 1341 }
1342 1342
1343 /* 1343 /*
1344 * ------------------------------------------------------------ 1344 * ------------------------------------------------------------
1345 * rs_ioctl() and friends 1345 * rs_ioctl() and friends
1346 * ------------------------------------------------------------ 1346 * ------------------------------------------------------------
1347 */ 1347 */
1348 1348
1349 static int get_serial_info(struct esp_struct *info, 1349 static int get_serial_info(struct esp_struct *info,
1350 struct serial_struct __user *retinfo) 1350 struct serial_struct __user *retinfo)
1351 { 1351 {
1352 struct serial_struct tmp; 1352 struct serial_struct tmp;
1353 1353
1354 lock_kernel(); 1354 lock_kernel();
1355 memset(&tmp, 0, sizeof(tmp)); 1355 memset(&tmp, 0, sizeof(tmp));
1356 tmp.type = PORT_16550A; 1356 tmp.type = PORT_16550A;
1357 tmp.line = info->line; 1357 tmp.line = info->line;
1358 tmp.port = info->port; 1358 tmp.port = info->io_port;
1359 tmp.irq = info->irq; 1359 tmp.irq = info->irq;
1360 tmp.flags = info->flags; 1360 tmp.flags = info->port.flags;
1361 tmp.xmit_fifo_size = 1024; 1361 tmp.xmit_fifo_size = 1024;
1362 tmp.baud_base = BASE_BAUD; 1362 tmp.baud_base = BASE_BAUD;
1363 tmp.close_delay = info->close_delay; 1363 tmp.close_delay = info->close_delay;
1364 tmp.closing_wait = info->closing_wait; 1364 tmp.closing_wait = info->closing_wait;
1365 tmp.custom_divisor = info->custom_divisor; 1365 tmp.custom_divisor = info->custom_divisor;
1366 tmp.hub6 = 0; 1366 tmp.hub6 = 0;
1367 unlock_kernel(); 1367 unlock_kernel();
1368 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 1368 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1369 return -EFAULT; 1369 return -EFAULT;
1370 return 0; 1370 return 0;
1371 } 1371 }
1372 1372
1373 static int get_esp_config(struct esp_struct *info, 1373 static int get_esp_config(struct esp_struct *info,
1374 struct hayes_esp_config __user *retinfo) 1374 struct hayes_esp_config __user *retinfo)
1375 { 1375 {
1376 struct hayes_esp_config tmp; 1376 struct hayes_esp_config tmp;
1377 1377
1378 if (!retinfo) 1378 if (!retinfo)
1379 return -EFAULT; 1379 return -EFAULT;
1380 1380
1381 memset(&tmp, 0, sizeof(tmp)); 1381 memset(&tmp, 0, sizeof(tmp));
1382 lock_kernel(); 1382 lock_kernel();
1383 tmp.rx_timeout = info->config.rx_timeout; 1383 tmp.rx_timeout = info->config.rx_timeout;
1384 tmp.rx_trigger = info->config.rx_trigger; 1384 tmp.rx_trigger = info->config.rx_trigger;
1385 tmp.tx_trigger = info->config.tx_trigger; 1385 tmp.tx_trigger = info->config.tx_trigger;
1386 tmp.flow_off = info->config.flow_off; 1386 tmp.flow_off = info->config.flow_off;
1387 tmp.flow_on = info->config.flow_on; 1387 tmp.flow_on = info->config.flow_on;
1388 tmp.pio_threshold = info->config.pio_threshold; 1388 tmp.pio_threshold = info->config.pio_threshold;
1389 tmp.dma_channel = (info->stat_flags & ESP_STAT_NEVER_DMA ? 0 : dma); 1389 tmp.dma_channel = (info->stat_flags & ESP_STAT_NEVER_DMA ? 0 : dma);
1390 unlock_kernel(); 1390 unlock_kernel();
1391 1391
1392 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0; 1392 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
1393 } 1393 }
1394 1394
1395 static int set_serial_info(struct esp_struct *info, 1395 static int set_serial_info(struct esp_struct *info,
1396 struct serial_struct __user *new_info) 1396 struct serial_struct __user *new_info)
1397 { 1397 {
1398 struct serial_struct new_serial; 1398 struct serial_struct new_serial;
1399 struct esp_struct old_info; 1399 struct esp_struct old_info;
1400 unsigned int change_irq; 1400 unsigned int change_irq;
1401 int retval = 0; 1401 int retval = 0;
1402 struct esp_struct *current_async; 1402 struct esp_struct *current_async;
1403 1403
1404 if (copy_from_user(&new_serial, new_info, sizeof(new_serial))) 1404 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
1405 return -EFAULT; 1405 return -EFAULT;
1406 old_info = *info; 1406 old_info = *info;
1407 1407
1408 if ((new_serial.type != PORT_16550A) || 1408 if ((new_serial.type != PORT_16550A) ||
1409 (new_serial.hub6) || 1409 (new_serial.hub6) ||
1410 (info->port != new_serial.port) || 1410 (info->io_port != new_serial.port) ||
1411 (new_serial.baud_base != BASE_BAUD) || 1411 (new_serial.baud_base != BASE_BAUD) ||
1412 (new_serial.irq > 15) || 1412 (new_serial.irq > 15) ||
1413 (new_serial.irq < 2) || 1413 (new_serial.irq < 2) ||
1414 (new_serial.irq == 6) || 1414 (new_serial.irq == 6) ||
1415 (new_serial.irq == 8) || 1415 (new_serial.irq == 8) ||
1416 (new_serial.irq == 13)) 1416 (new_serial.irq == 13))
1417 return -EINVAL; 1417 return -EINVAL;
1418 1418
1419 change_irq = new_serial.irq != info->irq; 1419 change_irq = new_serial.irq != info->irq;
1420 1420
1421 if (change_irq && (info->line % 8)) 1421 if (change_irq && (info->line % 8))
1422 return -EINVAL; 1422 return -EINVAL;
1423 1423
1424 if (!capable(CAP_SYS_ADMIN)) { 1424 if (!capable(CAP_SYS_ADMIN)) {
1425 if (change_irq || 1425 if (change_irq ||
1426 (new_serial.close_delay != info->close_delay) || 1426 (new_serial.close_delay != info->close_delay) ||
1427 ((new_serial.flags & ~ASYNC_USR_MASK) != 1427 ((new_serial.flags & ~ASYNC_USR_MASK) !=
1428 (info->flags & ~ASYNC_USR_MASK))) 1428 (info->port.flags & ~ASYNC_USR_MASK)))
1429 return -EPERM; 1429 return -EPERM;
1430 info->flags = ((info->flags & ~ASYNC_USR_MASK) | 1430 info->port.flags = ((info->port.flags & ~ASYNC_USR_MASK) |
1431 (new_serial.flags & ASYNC_USR_MASK)); 1431 (new_serial.flags & ASYNC_USR_MASK));
1432 info->custom_divisor = new_serial.custom_divisor; 1432 info->custom_divisor = new_serial.custom_divisor;
1433 } else { 1433 } else {
1434 if (new_serial.irq == 2) 1434 if (new_serial.irq == 2)
1435 new_serial.irq = 9; 1435 new_serial.irq = 9;
1436 1436
1437 if (change_irq) { 1437 if (change_irq) {
1438 current_async = ports; 1438 current_async = ports;
1439 1439
1440 while (current_async) { 1440 while (current_async) {
1441 if ((current_async->line >= info->line) && 1441 if ((current_async->line >= info->line) &&
1442 (current_async->line < (info->line + 8))) { 1442 (current_async->line < (info->line + 8))) {
1443 if (current_async == info) { 1443 if (current_async == info) {
1444 if (current_async->count > 1) 1444 if (current_async->port.count > 1)
1445 return -EBUSY; 1445 return -EBUSY;
1446 } else if (current_async->count) 1446 } else if (current_async->port.count)
1447 return -EBUSY; 1447 return -EBUSY;
1448 } 1448 }
1449 1449
1450 current_async = current_async->next_port; 1450 current_async = current_async->next_port;
1451 } 1451 }
1452 } 1452 }
1453 1453
1454 /* 1454 /*
1455 * OK, past this point, all the error checking has been done. 1455 * OK, past this point, all the error checking has been done.
1456 * At this point, we start making changes..... 1456 * At this point, we start making changes.....
1457 */ 1457 */
1458 1458
1459 info->flags = ((info->flags & ~ASYNC_FLAGS) | 1459 info->port.flags = ((info->port.flags & ~ASYNC_FLAGS) |
1460 (new_serial.flags & ASYNC_FLAGS)); 1460 (new_serial.flags & ASYNC_FLAGS));
1461 info->custom_divisor = new_serial.custom_divisor; 1461 info->custom_divisor = new_serial.custom_divisor;
1462 info->close_delay = new_serial.close_delay * HZ/100; 1462 info->close_delay = new_serial.close_delay * HZ/100;
1463 info->closing_wait = new_serial.closing_wait * HZ/100; 1463 info->closing_wait = new_serial.closing_wait * HZ/100;
1464 1464
1465 if (change_irq) { 1465 if (change_irq) {
1466 /* 1466 /*
1467 * We need to shutdown the serial port at the old 1467 * We need to shutdown the serial port at the old
1468 * port/irq combination. 1468 * port/irq combination.
1469 */ 1469 */
1470 shutdown(info); 1470 shutdown(info);
1471 1471
1472 current_async = ports; 1472 current_async = ports;
1473 1473
1474 while (current_async) { 1474 while (current_async) {
1475 if ((current_async->line >= info->line) && 1475 if ((current_async->line >= info->line) &&
1476 (current_async->line < (info->line + 8))) 1476 (current_async->line < (info->line + 8)))
1477 current_async->irq = new_serial.irq; 1477 current_async->irq = new_serial.irq;
1478 1478
1479 current_async = current_async->next_port; 1479 current_async = current_async->next_port;
1480 } 1480 }
1481 1481
1482 serial_out(info, UART_ESI_CMD1, ESI_SET_ENH_IRQ); 1482 serial_out(info, UART_ESI_CMD1, ESI_SET_ENH_IRQ);
1483 if (info->irq == 9) 1483 if (info->irq == 9)
1484 serial_out(info, UART_ESI_CMD2, 0x02); 1484 serial_out(info, UART_ESI_CMD2, 0x02);
1485 else 1485 else
1486 serial_out(info, UART_ESI_CMD2, info->irq); 1486 serial_out(info, UART_ESI_CMD2, info->irq);
1487 } 1487 }
1488 } 1488 }
1489 1489
1490 if (info->flags & ASYNC_INITIALIZED) { 1490 if (info->port.flags & ASYNC_INITIALIZED) {
1491 if (((old_info.flags & ASYNC_SPD_MASK) != 1491 if (((old_info.port.flags & ASYNC_SPD_MASK) !=
1492 (info->flags & ASYNC_SPD_MASK)) || 1492 (info->port.flags & ASYNC_SPD_MASK)) ||
1493 (old_info.custom_divisor != info->custom_divisor)) { 1493 (old_info.custom_divisor != info->custom_divisor)) {
1494 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 1494 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
1495 info->tty->alt_speed = 57600; 1495 info->port.tty->alt_speed = 57600;
1496 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 1496 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1497 info->tty->alt_speed = 115200; 1497 info->port.tty->alt_speed = 115200;
1498 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) 1498 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
1499 info->tty->alt_speed = 230400; 1499 info->port.tty->alt_speed = 230400;
1500 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) 1500 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
1501 info->tty->alt_speed = 460800; 1501 info->port.tty->alt_speed = 460800;
1502 change_speed(info); 1502 change_speed(info);
1503 } 1503 }
1504 } else 1504 } else
1505 retval = startup(info); 1505 retval = startup(info);
1506 1506
1507 return retval; 1507 return retval;
1508 } 1508 }
1509 1509
1510 static int set_esp_config(struct esp_struct *info, 1510 static int set_esp_config(struct esp_struct *info,
1511 struct hayes_esp_config __user *new_info) 1511 struct hayes_esp_config __user *new_info)
1512 { 1512 {
1513 struct hayes_esp_config new_config; 1513 struct hayes_esp_config new_config;
1514 unsigned int change_dma; 1514 unsigned int change_dma;
1515 int retval = 0; 1515 int retval = 0;
1516 struct esp_struct *current_async; 1516 struct esp_struct *current_async;
1517 unsigned long flags; 1517 unsigned long flags;
1518 1518
1519 /* Perhaps a non-sysadmin user should be able to do some of these */ 1519 /* Perhaps a non-sysadmin user should be able to do some of these */
1520 /* operations. I haven't decided yet. */ 1520 /* operations. I haven't decided yet. */
1521 1521
1522 if (!capable(CAP_SYS_ADMIN)) 1522 if (!capable(CAP_SYS_ADMIN))
1523 return -EPERM; 1523 return -EPERM;
1524 1524
1525 if (copy_from_user(&new_config, new_info, sizeof(new_config))) 1525 if (copy_from_user(&new_config, new_info, sizeof(new_config)))
1526 return -EFAULT; 1526 return -EFAULT;
1527 1527
1528 if ((new_config.flow_on >= new_config.flow_off) || 1528 if ((new_config.flow_on >= new_config.flow_off) ||
1529 (new_config.rx_trigger < 1) || 1529 (new_config.rx_trigger < 1) ||
1530 (new_config.tx_trigger < 1) || 1530 (new_config.tx_trigger < 1) ||
1531 (new_config.flow_off < 1) || 1531 (new_config.flow_off < 1) ||
1532 (new_config.flow_on < 1) || 1532 (new_config.flow_on < 1) ||
1533 (new_config.rx_trigger > 1023) || 1533 (new_config.rx_trigger > 1023) ||
1534 (new_config.tx_trigger > 1023) || 1534 (new_config.tx_trigger > 1023) ||
1535 (new_config.flow_off > 1023) || 1535 (new_config.flow_off > 1023) ||
1536 (new_config.flow_on > 1023) || 1536 (new_config.flow_on > 1023) ||
1537 (new_config.pio_threshold < 0) || 1537 (new_config.pio_threshold < 0) ||
1538 (new_config.pio_threshold > 1024)) 1538 (new_config.pio_threshold > 1024))
1539 return -EINVAL; 1539 return -EINVAL;
1540 1540
1541 if ((new_config.dma_channel != 1) && (new_config.dma_channel != 3)) 1541 if ((new_config.dma_channel != 1) && (new_config.dma_channel != 3))
1542 new_config.dma_channel = 0; 1542 new_config.dma_channel = 0;
1543 1543
1544 if (info->stat_flags & ESP_STAT_NEVER_DMA) 1544 if (info->stat_flags & ESP_STAT_NEVER_DMA)
1545 change_dma = new_config.dma_channel; 1545 change_dma = new_config.dma_channel;
1546 else 1546 else
1547 change_dma = (new_config.dma_channel != dma); 1547 change_dma = (new_config.dma_channel != dma);
1548 1548
1549 if (change_dma) { 1549 if (change_dma) {
1550 if (new_config.dma_channel) { 1550 if (new_config.dma_channel) {
1551 /* PIO mode to DMA mode transition OR */ 1551 /* PIO mode to DMA mode transition OR */
1552 /* change current DMA channel */ 1552 /* change current DMA channel */
1553 current_async = ports; 1553 current_async = ports;
1554 1554
1555 while (current_async) { 1555 while (current_async) {
1556 if (current_async == info) { 1556 if (current_async == info) {
1557 if (current_async->count > 1) 1557 if (current_async->port.count > 1)
1558 return -EBUSY; 1558 return -EBUSY;
1559 } else if (current_async->count) 1559 } else if (current_async->port.count)
1560 return -EBUSY; 1560 return -EBUSY;
1561 1561
1562 current_async = current_async->next_port; 1562 current_async = current_async->next_port;
1563 } 1563 }
1564 1564
1565 shutdown(info); 1565 shutdown(info);
1566 dma = new_config.dma_channel; 1566 dma = new_config.dma_channel;
1567 info->stat_flags &= ~ESP_STAT_NEVER_DMA; 1567 info->stat_flags &= ~ESP_STAT_NEVER_DMA;
1568 1568
1569 /* all ports must use the same DMA channel */ 1569 /* all ports must use the same DMA channel */
1570 1570
1571 spin_lock_irqsave(&info->lock, flags); 1571 spin_lock_irqsave(&info->lock, flags);
1572 current_async = ports; 1572 current_async = ports;
1573 1573
1574 while (current_async) { 1574 while (current_async) {
1575 esp_basic_init(current_async); 1575 esp_basic_init(current_async);
1576 current_async = current_async->next_port; 1576 current_async = current_async->next_port;
1577 } 1577 }
1578 spin_unlock_irqrestore(&info->lock, flags); 1578 spin_unlock_irqrestore(&info->lock, flags);
1579 } else { 1579 } else {
1580 /* DMA mode to PIO mode only */ 1580 /* DMA mode to PIO mode only */
1581 if (info->count > 1) 1581 if (info->port.count > 1)
1582 return -EBUSY; 1582 return -EBUSY;
1583 1583
1584 shutdown(info); 1584 shutdown(info);
1585 spin_lock_irqsave(&info->lock, flags); 1585 spin_lock_irqsave(&info->lock, flags);
1586 info->stat_flags |= ESP_STAT_NEVER_DMA; 1586 info->stat_flags |= ESP_STAT_NEVER_DMA;
1587 esp_basic_init(info); 1587 esp_basic_init(info);
1588 spin_unlock_irqrestore(&info->lock, flags); 1588 spin_unlock_irqrestore(&info->lock, flags);
1589 } 1589 }
1590 } 1590 }
1591 1591
1592 info->config.pio_threshold = new_config.pio_threshold; 1592 info->config.pio_threshold = new_config.pio_threshold;
1593 1593
1594 if ((new_config.flow_off != info->config.flow_off) || 1594 if ((new_config.flow_off != info->config.flow_off) ||
1595 (new_config.flow_on != info->config.flow_on)) { 1595 (new_config.flow_on != info->config.flow_on)) {
1596 info->config.flow_off = new_config.flow_off; 1596 info->config.flow_off = new_config.flow_off;
1597 info->config.flow_on = new_config.flow_on; 1597 info->config.flow_on = new_config.flow_on;
1598 1598
1599 spin_lock_irqsave(&info->lock, flags); 1599 spin_lock_irqsave(&info->lock, flags);
1600 serial_out(info, UART_ESI_CMD1, ESI_SET_FLOW_LVL); 1600 serial_out(info, UART_ESI_CMD1, ESI_SET_FLOW_LVL);
1601 serial_out(info, UART_ESI_CMD2, new_config.flow_off >> 8); 1601 serial_out(info, UART_ESI_CMD2, new_config.flow_off >> 8);
1602 serial_out(info, UART_ESI_CMD2, new_config.flow_off); 1602 serial_out(info, UART_ESI_CMD2, new_config.flow_off);
1603 serial_out(info, UART_ESI_CMD2, new_config.flow_on >> 8); 1603 serial_out(info, UART_ESI_CMD2, new_config.flow_on >> 8);
1604 serial_out(info, UART_ESI_CMD2, new_config.flow_on); 1604 serial_out(info, UART_ESI_CMD2, new_config.flow_on);
1605 spin_unlock_irqrestore(&info->lock, flags); 1605 spin_unlock_irqrestore(&info->lock, flags);
1606 } 1606 }
1607 1607
1608 if ((new_config.rx_trigger != info->config.rx_trigger) || 1608 if ((new_config.rx_trigger != info->config.rx_trigger) ||
1609 (new_config.tx_trigger != info->config.tx_trigger)) { 1609 (new_config.tx_trigger != info->config.tx_trigger)) {
1610 info->config.rx_trigger = new_config.rx_trigger; 1610 info->config.rx_trigger = new_config.rx_trigger;
1611 info->config.tx_trigger = new_config.tx_trigger; 1611 info->config.tx_trigger = new_config.tx_trigger;
1612 spin_lock_irqsave(&info->lock, flags); 1612 spin_lock_irqsave(&info->lock, flags);
1613 serial_out(info, UART_ESI_CMD1, ESI_SET_TRIGGER); 1613 serial_out(info, UART_ESI_CMD1, ESI_SET_TRIGGER);
1614 serial_out(info, UART_ESI_CMD2, 1614 serial_out(info, UART_ESI_CMD2,
1615 new_config.rx_trigger >> 8); 1615 new_config.rx_trigger >> 8);
1616 serial_out(info, UART_ESI_CMD2, new_config.rx_trigger); 1616 serial_out(info, UART_ESI_CMD2, new_config.rx_trigger);
1617 serial_out(info, UART_ESI_CMD2, 1617 serial_out(info, UART_ESI_CMD2,
1618 new_config.tx_trigger >> 8); 1618 new_config.tx_trigger >> 8);
1619 serial_out(info, UART_ESI_CMD2, new_config.tx_trigger); 1619 serial_out(info, UART_ESI_CMD2, new_config.tx_trigger);
1620 spin_unlock_irqrestore(&info->lock, flags); 1620 spin_unlock_irqrestore(&info->lock, flags);
1621 } 1621 }
1622 1622
1623 if (new_config.rx_timeout != info->config.rx_timeout) { 1623 if (new_config.rx_timeout != info->config.rx_timeout) {
1624 info->config.rx_timeout = new_config.rx_timeout; 1624 info->config.rx_timeout = new_config.rx_timeout;
1625 spin_lock_irqsave(&info->lock, flags); 1625 spin_lock_irqsave(&info->lock, flags);
1626 1626
1627 if (info->IER & UART_IER_RDI) { 1627 if (info->IER & UART_IER_RDI) {
1628 serial_out(info, UART_ESI_CMD1, 1628 serial_out(info, UART_ESI_CMD1,
1629 ESI_SET_RX_TIMEOUT); 1629 ESI_SET_RX_TIMEOUT);
1630 serial_out(info, UART_ESI_CMD2, 1630 serial_out(info, UART_ESI_CMD2,
1631 new_config.rx_timeout); 1631 new_config.rx_timeout);
1632 } 1632 }
1633 1633
1634 spin_unlock_irqrestore(&info->lock, flags); 1634 spin_unlock_irqrestore(&info->lock, flags);
1635 } 1635 }
1636 1636
1637 if (!(info->flags & ASYNC_INITIALIZED)) 1637 if (!(info->port.flags & ASYNC_INITIALIZED))
1638 retval = startup(info); 1638 retval = startup(info);
1639 1639
1640 return retval; 1640 return retval;
1641 } 1641 }
1642 1642
1643 /* 1643 /*
1644 * get_lsr_info - get line status register info 1644 * get_lsr_info - get line status register info
1645 * 1645 *
1646 * Purpose: Let user call ioctl() to get info when the UART physically 1646 * Purpose: Let user call ioctl() to get info when the UART physically
1647 * is emptied. On bus types like RS485, the transmitter must 1647 * is emptied. On bus types like RS485, the transmitter must
1648 * release the bus after transmitting. This must be done when 1648 * release the bus after transmitting. This must be done when
1649 * the transmit shift register is empty, not be done when the 1649 * the transmit shift register is empty, not be done when the
1650 * transmit holding register is empty. This functionality 1650 * transmit holding register is empty. This functionality
1651 * allows an RS485 driver to be written in user space. 1651 * allows an RS485 driver to be written in user space.
1652 */ 1652 */
1653 static int get_lsr_info(struct esp_struct *info, unsigned int __user *value) 1653 static int get_lsr_info(struct esp_struct *info, unsigned int __user *value)
1654 { 1654 {
1655 unsigned char status; 1655 unsigned char status;
1656 unsigned int result; 1656 unsigned int result;
1657 unsigned long flags; 1657 unsigned long flags;
1658 1658
1659 spin_lock_irqsave(&info->lock, flags); 1659 spin_lock_irqsave(&info->lock, flags);
1660 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT); 1660 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT);
1661 status = serial_in(info, UART_ESI_STAT1); 1661 status = serial_in(info, UART_ESI_STAT1);
1662 spin_unlock_irqrestore(&info->lock, flags); 1662 spin_unlock_irqrestore(&info->lock, flags);
1663 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0); 1663 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1664 return put_user(result, value); 1664 return put_user(result, value);
1665 } 1665 }
1666 1666
1667 1667
1668 static int esp_tiocmget(struct tty_struct *tty, struct file *file) 1668 static int esp_tiocmget(struct tty_struct *tty, struct file *file)
1669 { 1669 {
1670 struct esp_struct *info = tty->driver_data; 1670 struct esp_struct *info = tty->driver_data;
1671 unsigned char control, status; 1671 unsigned char control, status;
1672 unsigned long flags; 1672 unsigned long flags;
1673 1673
1674 if (serial_paranoia_check(info, tty->name, __func__)) 1674 if (serial_paranoia_check(info, tty->name, __func__))
1675 return -ENODEV; 1675 return -ENODEV;
1676 if (tty->flags & (1 << TTY_IO_ERROR)) 1676 if (tty->flags & (1 << TTY_IO_ERROR))
1677 return -EIO; 1677 return -EIO;
1678 1678
1679 control = info->MCR; 1679 control = info->MCR;
1680 1680
1681 spin_lock_irqsave(&info->lock, flags); 1681 spin_lock_irqsave(&info->lock, flags);
1682 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT); 1682 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT);
1683 status = serial_in(info, UART_ESI_STAT2); 1683 status = serial_in(info, UART_ESI_STAT2);
1684 spin_unlock_irqrestore(&info->lock, flags); 1684 spin_unlock_irqrestore(&info->lock, flags);
1685 1685
1686 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) 1686 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
1687 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) 1687 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
1688 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0) 1688 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
1689 | ((status & UART_MSR_RI) ? TIOCM_RNG : 0) 1689 | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
1690 | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0) 1690 | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
1691 | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0); 1691 | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
1692 } 1692 }
1693 1693
1694 static int esp_tiocmset(struct tty_struct *tty, struct file *file, 1694 static int esp_tiocmset(struct tty_struct *tty, struct file *file,
1695 unsigned int set, unsigned int clear) 1695 unsigned int set, unsigned int clear)
1696 { 1696 {
1697 struct esp_struct *info = tty->driver_data; 1697 struct esp_struct *info = tty->driver_data;
1698 unsigned long flags; 1698 unsigned long flags;
1699 1699
1700 if (serial_paranoia_check(info, tty->name, __func__)) 1700 if (serial_paranoia_check(info, tty->name, __func__))
1701 return -ENODEV; 1701 return -ENODEV;
1702 if (tty->flags & (1 << TTY_IO_ERROR)) 1702 if (tty->flags & (1 << TTY_IO_ERROR))
1703 return -EIO; 1703 return -EIO;
1704 1704
1705 spin_lock_irqsave(&info->lock, flags); 1705 spin_lock_irqsave(&info->lock, flags);
1706 1706
1707 if (set & TIOCM_RTS) 1707 if (set & TIOCM_RTS)
1708 info->MCR |= UART_MCR_RTS; 1708 info->MCR |= UART_MCR_RTS;
1709 if (set & TIOCM_DTR) 1709 if (set & TIOCM_DTR)
1710 info->MCR |= UART_MCR_DTR; 1710 info->MCR |= UART_MCR_DTR;
1711 1711
1712 if (clear & TIOCM_RTS) 1712 if (clear & TIOCM_RTS)
1713 info->MCR &= ~UART_MCR_RTS; 1713 info->MCR &= ~UART_MCR_RTS;
1714 if (clear & TIOCM_DTR) 1714 if (clear & TIOCM_DTR)
1715 info->MCR &= ~UART_MCR_DTR; 1715 info->MCR &= ~UART_MCR_DTR;
1716 1716
1717 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART); 1717 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
1718 serial_out(info, UART_ESI_CMD2, UART_MCR); 1718 serial_out(info, UART_ESI_CMD2, UART_MCR);
1719 serial_out(info, UART_ESI_CMD2, info->MCR); 1719 serial_out(info, UART_ESI_CMD2, info->MCR);
1720 1720
1721 spin_unlock_irqrestore(&info->lock, flags); 1721 spin_unlock_irqrestore(&info->lock, flags);
1722 return 0; 1722 return 0;
1723 } 1723 }
1724 1724
1725 /* 1725 /*
1726 * rs_break() --- routine which turns the break handling on or off 1726 * rs_break() --- routine which turns the break handling on or off
1727 */ 1727 */
1728 static void esp_break(struct tty_struct *tty, int break_state) 1728 static void esp_break(struct tty_struct *tty, int break_state)
1729 { 1729 {
1730 struct esp_struct *info = tty->driver_data; 1730 struct esp_struct *info = tty->driver_data;
1731 unsigned long flags; 1731 unsigned long flags;
1732 1732
1733 if (serial_paranoia_check(info, tty->name, "esp_break")) 1733 if (serial_paranoia_check(info, tty->name, "esp_break"))
1734 return; 1734 return;
1735 1735
1736 if (break_state == -1) { 1736 if (break_state == -1) {
1737 spin_lock_irqsave(&info->lock, flags); 1737 spin_lock_irqsave(&info->lock, flags);
1738 serial_out(info, UART_ESI_CMD1, ESI_ISSUE_BREAK); 1738 serial_out(info, UART_ESI_CMD1, ESI_ISSUE_BREAK);
1739 serial_out(info, UART_ESI_CMD2, 0x01); 1739 serial_out(info, UART_ESI_CMD2, 0x01);
1740 spin_unlock_irqrestore(&info->lock, flags); 1740 spin_unlock_irqrestore(&info->lock, flags);
1741 1741
1742 /* FIXME - new style wait needed here */ 1742 /* FIXME - new style wait needed here */
1743 interruptible_sleep_on(&info->break_wait); 1743 interruptible_sleep_on(&info->break_wait);
1744 } else { 1744 } else {
1745 spin_lock_irqsave(&info->lock, flags); 1745 spin_lock_irqsave(&info->lock, flags);
1746 serial_out(info, UART_ESI_CMD1, ESI_ISSUE_BREAK); 1746 serial_out(info, UART_ESI_CMD1, ESI_ISSUE_BREAK);
1747 serial_out(info, UART_ESI_CMD2, 0x00); 1747 serial_out(info, UART_ESI_CMD2, 0x00);
1748 spin_unlock_irqrestore(&info->lock, flags); 1748 spin_unlock_irqrestore(&info->lock, flags);
1749 } 1749 }
1750 } 1750 }
1751 1751
1752 static int rs_ioctl(struct tty_struct *tty, struct file *file, 1752 static int rs_ioctl(struct tty_struct *tty, struct file *file,
1753 unsigned int cmd, unsigned long arg) 1753 unsigned int cmd, unsigned long arg)
1754 { 1754 {
1755 struct esp_struct *info = tty->driver_data; 1755 struct esp_struct *info = tty->driver_data;
1756 struct async_icount cprev, cnow; /* kernel counter temps */ 1756 struct async_icount cprev, cnow; /* kernel counter temps */
1757 struct serial_icounter_struct __user *p_cuser; /* user space */ 1757 struct serial_icounter_struct __user *p_cuser; /* user space */
1758 void __user *argp = (void __user *)arg; 1758 void __user *argp = (void __user *)arg;
1759 unsigned long flags; 1759 unsigned long flags;
1760 int ret; 1760 int ret;
1761 1761
1762 if (serial_paranoia_check(info, tty->name, "rs_ioctl")) 1762 if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
1763 return -ENODEV; 1763 return -ENODEV;
1764 1764
1765 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && 1765 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1766 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) && 1766 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) &&
1767 (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT) && 1767 (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT) &&
1768 (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT) && 1768 (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT) &&
1769 (cmd != TIOCGHAYESESP) && (cmd != TIOCSHAYESESP)) { 1769 (cmd != TIOCGHAYESESP) && (cmd != TIOCSHAYESESP)) {
1770 if (tty->flags & (1 << TTY_IO_ERROR)) 1770 if (tty->flags & (1 << TTY_IO_ERROR))
1771 return -EIO; 1771 return -EIO;
1772 } 1772 }
1773 1773
1774 switch (cmd) { 1774 switch (cmd) {
1775 case TIOCGSERIAL: 1775 case TIOCGSERIAL:
1776 return get_serial_info(info, argp); 1776 return get_serial_info(info, argp);
1777 case TIOCSSERIAL: 1777 case TIOCSSERIAL:
1778 lock_kernel(); 1778 lock_kernel();
1779 ret = set_serial_info(info, argp); 1779 ret = set_serial_info(info, argp);
1780 unlock_kernel(); 1780 unlock_kernel();
1781 return ret; 1781 return ret;
1782 case TIOCSERGWILD: 1782 case TIOCSERGWILD:
1783 return put_user(0L, (unsigned long __user *)argp); 1783 return put_user(0L, (unsigned long __user *)argp);
1784 case TIOCSERGETLSR: /* Get line status register */ 1784 case TIOCSERGETLSR: /* Get line status register */
1785 return get_lsr_info(info, argp); 1785 return get_lsr_info(info, argp);
1786 case TIOCSERSWILD: 1786 case TIOCSERSWILD:
1787 if (!capable(CAP_SYS_ADMIN)) 1787 if (!capable(CAP_SYS_ADMIN))
1788 return -EPERM; 1788 return -EPERM;
1789 return 0; 1789 return 0;
1790 /* 1790 /*
1791 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change 1791 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1792 * - mask passed in arg for lines of interest 1792 * - mask passed in arg for lines of interest
1793 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking) 1793 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1794 * Caller should use TIOCGICOUNT to see which one it was 1794 * Caller should use TIOCGICOUNT to see which one it was
1795 */ 1795 */
1796 case TIOCMIWAIT: 1796 case TIOCMIWAIT:
1797 spin_lock_irqsave(&info->lock, flags); 1797 spin_lock_irqsave(&info->lock, flags);
1798 cprev = info->icount; /* note the counters on entry */ 1798 cprev = info->icount; /* note the counters on entry */
1799 spin_unlock_irqrestore(&info->lock, flags); 1799 spin_unlock_irqrestore(&info->lock, flags);
1800 while (1) { 1800 while (1) {
1801 /* FIXME: convert to new style wakeup */ 1801 /* FIXME: convert to new style wakeup */
1802 interruptible_sleep_on(&info->delta_msr_wait); 1802 interruptible_sleep_on(&info->delta_msr_wait);
1803 /* see if a signal did it */ 1803 /* see if a signal did it */
1804 if (signal_pending(current)) 1804 if (signal_pending(current))
1805 return -ERESTARTSYS; 1805 return -ERESTARTSYS;
1806 spin_lock_irqsave(&info->lock, flags); 1806 spin_lock_irqsave(&info->lock, flags);
1807 cnow = info->icount; /* atomic copy */ 1807 cnow = info->icount; /* atomic copy */
1808 spin_unlock_irqrestore(&info->lock, flags); 1808 spin_unlock_irqrestore(&info->lock, flags);
1809 if (cnow.rng == cprev.rng && 1809 if (cnow.rng == cprev.rng &&
1810 cnow.dsr == cprev.dsr && 1810 cnow.dsr == cprev.dsr &&
1811 cnow.dcd == cprev.dcd && 1811 cnow.dcd == cprev.dcd &&
1812 cnow.cts == cprev.cts) 1812 cnow.cts == cprev.cts)
1813 return -EIO; /* no change => error */ 1813 return -EIO; /* no change => error */
1814 if (((arg & TIOCM_RNG) && 1814 if (((arg & TIOCM_RNG) &&
1815 (cnow.rng != cprev.rng)) || 1815 (cnow.rng != cprev.rng)) ||
1816 ((arg & TIOCM_DSR) && 1816 ((arg & TIOCM_DSR) &&
1817 (cnow.dsr != cprev.dsr)) || 1817 (cnow.dsr != cprev.dsr)) ||
1818 ((arg & TIOCM_CD) && 1818 ((arg & TIOCM_CD) &&
1819 (cnow.dcd != cprev.dcd)) || 1819 (cnow.dcd != cprev.dcd)) ||
1820 ((arg & TIOCM_CTS) && 1820 ((arg & TIOCM_CTS) &&
1821 (cnow.cts != cprev.cts))) { 1821 (cnow.cts != cprev.cts))) {
1822 return 0; 1822 return 0;
1823 } 1823 }
1824 cprev = cnow; 1824 cprev = cnow;
1825 } 1825 }
1826 /* NOTREACHED */ 1826 /* NOTREACHED */
1827 /* 1827 /*
1828 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) 1828 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1829 * Return: write counters to the user passed counter struct 1829 * Return: write counters to the user passed counter struct
1830 * NB: both 1->0 and 0->1 transitions are counted except for 1830 * NB: both 1->0 and 0->1 transitions are counted except for
1831 * RI where only 0->1 is counted. 1831 * RI where only 0->1 is counted.
1832 */ 1832 */
1833 case TIOCGICOUNT: 1833 case TIOCGICOUNT:
1834 spin_lock_irqsave(&info->lock, flags); 1834 spin_lock_irqsave(&info->lock, flags);
1835 cnow = info->icount; 1835 cnow = info->icount;
1836 spin_unlock_irqrestore(&info->lock, flags); 1836 spin_unlock_irqrestore(&info->lock, flags);
1837 p_cuser = argp; 1837 p_cuser = argp;
1838 if (put_user(cnow.cts, &p_cuser->cts) || 1838 if (put_user(cnow.cts, &p_cuser->cts) ||
1839 put_user(cnow.dsr, &p_cuser->dsr) || 1839 put_user(cnow.dsr, &p_cuser->dsr) ||
1840 put_user(cnow.rng, &p_cuser->rng) || 1840 put_user(cnow.rng, &p_cuser->rng) ||
1841 put_user(cnow.dcd, &p_cuser->dcd)) 1841 put_user(cnow.dcd, &p_cuser->dcd))
1842 return -EFAULT; 1842 return -EFAULT;
1843 return 0; 1843 return 0;
1844 case TIOCGHAYESESP: 1844 case TIOCGHAYESESP:
1845 return get_esp_config(info, argp); 1845 return get_esp_config(info, argp);
1846 case TIOCSHAYESESP: 1846 case TIOCSHAYESESP:
1847 lock_kernel(); 1847 lock_kernel();
1848 ret = set_esp_config(info, argp); 1848 ret = set_esp_config(info, argp);
1849 unlock_kernel(); 1849 unlock_kernel();
1850 return ret; 1850 return ret;
1851 default: 1851 default:
1852 return -ENOIOCTLCMD; 1852 return -ENOIOCTLCMD;
1853 } 1853 }
1854 return 0; 1854 return 0;
1855 } 1855 }
1856 1856
1857 static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios) 1857 static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1858 { 1858 {
1859 struct esp_struct *info = tty->driver_data; 1859 struct esp_struct *info = tty->driver_data;
1860 unsigned long flags; 1860 unsigned long flags;
1861 1861
1862 change_speed(info); 1862 change_speed(info);
1863 1863
1864 spin_lock_irqsave(&info->lock, flags); 1864 spin_lock_irqsave(&info->lock, flags);
1865 1865
1866 /* Handle transition to B0 status */ 1866 /* Handle transition to B0 status */
1867 if ((old_termios->c_cflag & CBAUD) && 1867 if ((old_termios->c_cflag & CBAUD) &&
1868 !(tty->termios->c_cflag & CBAUD)) { 1868 !(tty->termios->c_cflag & CBAUD)) {
1869 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS); 1869 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
1870 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART); 1870 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
1871 serial_out(info, UART_ESI_CMD2, UART_MCR); 1871 serial_out(info, UART_ESI_CMD2, UART_MCR);
1872 serial_out(info, UART_ESI_CMD2, info->MCR); 1872 serial_out(info, UART_ESI_CMD2, info->MCR);
1873 } 1873 }
1874 1874
1875 /* Handle transition away from B0 status */ 1875 /* Handle transition away from B0 status */
1876 if (!(old_termios->c_cflag & CBAUD) && 1876 if (!(old_termios->c_cflag & CBAUD) &&
1877 (tty->termios->c_cflag & CBAUD)) { 1877 (tty->termios->c_cflag & CBAUD)) {
1878 info->MCR |= (UART_MCR_DTR | UART_MCR_RTS); 1878 info->MCR |= (UART_MCR_DTR | UART_MCR_RTS);
1879 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART); 1879 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
1880 serial_out(info, UART_ESI_CMD2, UART_MCR); 1880 serial_out(info, UART_ESI_CMD2, UART_MCR);
1881 serial_out(info, UART_ESI_CMD2, info->MCR); 1881 serial_out(info, UART_ESI_CMD2, info->MCR);
1882 } 1882 }
1883 1883
1884 spin_unlock_irqrestore(&info->lock, flags); 1884 spin_unlock_irqrestore(&info->lock, flags);
1885 1885
1886 /* Handle turning of CRTSCTS */ 1886 /* Handle turning of CRTSCTS */
1887 if ((old_termios->c_cflag & CRTSCTS) && 1887 if ((old_termios->c_cflag & CRTSCTS) &&
1888 !(tty->termios->c_cflag & CRTSCTS)) { 1888 !(tty->termios->c_cflag & CRTSCTS)) {
1889 rs_start(tty); 1889 rs_start(tty);
1890 } 1890 }
1891 } 1891 }
1892 1892
1893 /* 1893 /*
1894 * ------------------------------------------------------------ 1894 * ------------------------------------------------------------
1895 * rs_close() 1895 * rs_close()
1896 * 1896 *
1897 * This routine is called when the serial port gets closed. First, we 1897 * This routine is called when the serial port gets closed. First, we
1898 * wait for the last remaining data to be sent. Then, we unlink its 1898 * wait for the last remaining data to be sent. Then, we unlink its
1899 * async structure from the interrupt chain if necessary, and we free 1899 * async structure from the interrupt chain if necessary, and we free
1900 * that IRQ if nothing is left in the chain. 1900 * that IRQ if nothing is left in the chain.
1901 * ------------------------------------------------------------ 1901 * ------------------------------------------------------------
1902 */ 1902 */
1903 static void rs_close(struct tty_struct *tty, struct file *filp) 1903 static void rs_close(struct tty_struct *tty, struct file *filp)
1904 { 1904 {
1905 struct esp_struct *info = tty->driver_data; 1905 struct esp_struct *info = tty->driver_data;
1906 unsigned long flags; 1906 unsigned long flags;
1907 1907
1908 if (!info || serial_paranoia_check(info, tty->name, "rs_close")) 1908 if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
1909 return; 1909 return;
1910 1910
1911 spin_lock_irqsave(&info->lock, flags); 1911 spin_lock_irqsave(&info->lock, flags);
1912 1912
1913 if (tty_hung_up_p(filp)) { 1913 if (tty_hung_up_p(filp)) {
1914 DBG_CNT("before DEC-hung"); 1914 DBG_CNT("before DEC-hung");
1915 goto out; 1915 goto out;
1916 } 1916 }
1917 1917
1918 #ifdef SERIAL_DEBUG_OPEN 1918 #ifdef SERIAL_DEBUG_OPEN
1919 printk(KERN_DEBUG "rs_close ttys%d, count = %d\n", 1919 printk(KERN_DEBUG "rs_close ttys%d, count = %d\n",
1920 info->line, info->count); 1920 info->line, info->port.count);
1921 #endif 1921 #endif
1922 if (tty->count == 1 && info->count != 1) { 1922 if (tty->count == 1 && info->port.count != 1) {
1923 /* 1923 /*
1924 * Uh, oh. tty->count is 1, which means that the tty 1924 * Uh, oh. tty->count is 1, which means that the tty
1925 * structure will be freed. Info->count should always 1925 * structure will be freed. Info->count should always
1926 * be one in these conditions. If it's greater than 1926 * be one in these conditions. If it's greater than
1927 * one, we've got real problems, since it means the 1927 * one, we've got real problems, since it means the
1928 * serial port won't be shutdown. 1928 * serial port won't be shutdown.
1929 */ 1929 */
1930 printk(KERN_DEBUG "rs_close: bad serial port count; tty->count is 1, info->count is %d\n", info->count); 1930 printk(KERN_DEBUG "rs_close: bad serial port count; tty->count is 1, info->port.count is %d\n", info->port.count);
1931 info->count = 1; 1931 info->port.count = 1;
1932 } 1932 }
1933 if (--info->count < 0) { 1933 if (--info->port.count < 0) {
1934 printk(KERN_ERR "rs_close: bad serial port count for ttys%d: %d\n", 1934 printk(KERN_ERR "rs_close: bad serial port count for ttys%d: %d\n",
1935 info->line, info->count); 1935 info->line, info->port.count);
1936 info->count = 0; 1936 info->port.count = 0;
1937 } 1937 }
1938 if (info->count) { 1938 if (info->port.count) {
1939 DBG_CNT("before DEC-2"); 1939 DBG_CNT("before DEC-2");
1940 goto out; 1940 goto out;
1941 } 1941 }
1942 info->flags |= ASYNC_CLOSING; 1942 info->port.flags |= ASYNC_CLOSING;
1943 1943
1944 spin_unlock_irqrestore(&info->lock, flags); 1944 spin_unlock_irqrestore(&info->lock, flags);
1945 /* 1945 /*
1946 * Now we wait for the transmit buffer to clear; and we notify 1946 * Now we wait for the transmit buffer to clear; and we notify
1947 * the line discipline to only process XON/XOFF characters. 1947 * the line discipline to only process XON/XOFF characters.
1948 */ 1948 */
1949 tty->closing = 1; 1949 tty->closing = 1;
1950 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE) 1950 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1951 tty_wait_until_sent(tty, info->closing_wait); 1951 tty_wait_until_sent(tty, info->closing_wait);
1952 /* 1952 /*
1953 * At this point we stop accepting input. To do this, we 1953 * At this point we stop accepting input. To do this, we
1954 * disable the receive line status interrupts, and tell the 1954 * disable the receive line status interrupts, and tell the
1955 * interrupt driver to stop checking the data ready bit in the 1955 * interrupt driver to stop checking the data ready bit in the
1956 * line status register. 1956 * line status register.
1957 */ 1957 */
1958 /* info->IER &= ~UART_IER_RLSI; */ 1958 /* info->IER &= ~UART_IER_RLSI; */
1959 info->IER &= ~UART_IER_RDI; 1959 info->IER &= ~UART_IER_RDI;
1960 info->read_status_mask &= ~UART_LSR_DR; 1960 info->read_status_mask &= ~UART_LSR_DR;
1961 if (info->flags & ASYNC_INITIALIZED) { 1961 if (info->port.flags & ASYNC_INITIALIZED) {
1962 1962
1963 spin_lock_irqsave(&info->lock, flags); 1963 spin_lock_irqsave(&info->lock, flags);
1964 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK); 1964 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
1965 serial_out(info, UART_ESI_CMD2, info->IER); 1965 serial_out(info, UART_ESI_CMD2, info->IER);
1966 1966
1967 /* disable receive timeout */ 1967 /* disable receive timeout */
1968 serial_out(info, UART_ESI_CMD1, ESI_SET_RX_TIMEOUT); 1968 serial_out(info, UART_ESI_CMD1, ESI_SET_RX_TIMEOUT);
1969 serial_out(info, UART_ESI_CMD2, 0x00); 1969 serial_out(info, UART_ESI_CMD2, 0x00);
1970 1970
1971 spin_unlock_irqrestore(&info->lock, flags); 1971 spin_unlock_irqrestore(&info->lock, flags);
1972 1972
1973 /* 1973 /*
1974 * Before we drop DTR, make sure the UART transmitter 1974 * Before we drop DTR, make sure the UART transmitter
1975 * has completely drained; this is especially 1975 * has completely drained; this is especially
1976 * important if there is a transmit FIFO! 1976 * important if there is a transmit FIFO!
1977 */ 1977 */
1978 rs_wait_until_sent(tty, info->timeout); 1978 rs_wait_until_sent(tty, info->timeout);
1979 } 1979 }
1980 shutdown(info); 1980 shutdown(info);
1981 rs_flush_buffer(tty); 1981 rs_flush_buffer(tty);
1982 tty_ldisc_flush(tty); 1982 tty_ldisc_flush(tty);
1983 tty->closing = 0; 1983 tty->closing = 0;
1984 info->tty = NULL; 1984 info->port.tty = NULL;
1985 1985
1986 if (info->blocked_open) { 1986 if (info->port.blocked_open) {
1987 if (info->close_delay) 1987 if (info->close_delay)
1988 msleep_interruptible(jiffies_to_msecs(info->close_delay)); 1988 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1989 wake_up_interruptible(&info->open_wait); 1989 wake_up_interruptible(&info->port.open_wait);
1990 } 1990 }
1991 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 1991 info->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1992 wake_up_interruptible(&info->close_wait); 1992 wake_up_interruptible(&info->port.close_wait);
1993 return; 1993 return;
1994 1994
1995 out: 1995 out:
1996 spin_unlock_irqrestore(&info->lock, flags); 1996 spin_unlock_irqrestore(&info->lock, flags);
1997 } 1997 }
1998 1998
1999 static void rs_wait_until_sent(struct tty_struct *tty, int timeout) 1999 static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
2000 { 2000 {
2001 struct esp_struct *info = tty->driver_data; 2001 struct esp_struct *info = tty->driver_data;
2002 unsigned long orig_jiffies, char_time; 2002 unsigned long orig_jiffies, char_time;
2003 unsigned long flags; 2003 unsigned long flags;
2004 2004
2005 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent")) 2005 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
2006 return; 2006 return;
2007 2007
2008 orig_jiffies = jiffies; 2008 orig_jiffies = jiffies;
2009 char_time = ((info->timeout - HZ / 50) / 1024) / 5; 2009 char_time = ((info->timeout - HZ / 50) / 1024) / 5;
2010 2010
2011 if (!char_time) 2011 if (!char_time)
2012 char_time = 1; 2012 char_time = 1;
2013 2013
2014 spin_lock_irqsave(&info->lock, flags); 2014 spin_lock_irqsave(&info->lock, flags);
2015 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND); 2015 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
2016 serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL); 2016 serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL);
2017 2017
2018 while ((serial_in(info, UART_ESI_STAT1) != 0x03) || 2018 while ((serial_in(info, UART_ESI_STAT1) != 0x03) ||
2019 (serial_in(info, UART_ESI_STAT2) != 0xff)) { 2019 (serial_in(info, UART_ESI_STAT2) != 0xff)) {
2020 2020
2021 spin_unlock_irqrestore(&info->lock, flags); 2021 spin_unlock_irqrestore(&info->lock, flags);
2022 msleep_interruptible(jiffies_to_msecs(char_time)); 2022 msleep_interruptible(jiffies_to_msecs(char_time));
2023 2023
2024 if (signal_pending(current)) 2024 if (signal_pending(current))
2025 return; 2025 return;
2026 2026
2027 if (timeout && time_after(jiffies, orig_jiffies + timeout)) 2027 if (timeout && time_after(jiffies, orig_jiffies + timeout))
2028 return; 2028 return;
2029 2029
2030 spin_lock_irqsave(&info->lock, flags); 2030 spin_lock_irqsave(&info->lock, flags);
2031 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND); 2031 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
2032 serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL); 2032 serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL);
2033 } 2033 }
2034 spin_unlock_irqrestore(&info->lock, flags); 2034 spin_unlock_irqrestore(&info->lock, flags);
2035 set_current_state(TASK_RUNNING); 2035 set_current_state(TASK_RUNNING);
2036 } 2036 }
2037 2037
2038 /* 2038 /*
2039 * esp_hangup() --- called by tty_hangup() when a hangup is signaled. 2039 * esp_hangup() --- called by tty_hangup() when a hangup is signaled.
2040 */ 2040 */
2041 static void esp_hangup(struct tty_struct *tty) 2041 static void esp_hangup(struct tty_struct *tty)
2042 { 2042 {
2043 struct esp_struct *info = tty->driver_data; 2043 struct esp_struct *info = tty->driver_data;
2044 2044
2045 if (serial_paranoia_check(info, tty->name, "esp_hangup")) 2045 if (serial_paranoia_check(info, tty->name, "esp_hangup"))
2046 return; 2046 return;
2047 2047
2048 rs_flush_buffer(tty); 2048 rs_flush_buffer(tty);
2049 shutdown(info); 2049 shutdown(info);
2050 info->count = 0; 2050 info->port.count = 0;
2051 info->flags &= ~ASYNC_NORMAL_ACTIVE; 2051 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
2052 info->tty = NULL; 2052 info->port.tty = NULL;
2053 wake_up_interruptible(&info->open_wait); 2053 wake_up_interruptible(&info->port.open_wait);
2054 } 2054 }
2055 2055
2056 /* 2056 /*
2057 * ------------------------------------------------------------ 2057 * ------------------------------------------------------------
2058 * esp_open() and friends 2058 * esp_open() and friends
2059 * ------------------------------------------------------------ 2059 * ------------------------------------------------------------
2060 */ 2060 */
2061 static int block_til_ready(struct tty_struct *tty, struct file *filp, 2061 static int block_til_ready(struct tty_struct *tty, struct file *filp,
2062 struct esp_struct *info) 2062 struct esp_struct *info)
2063 { 2063 {
2064 DECLARE_WAITQUEUE(wait, current); 2064 DECLARE_WAITQUEUE(wait, current);
2065 int retval; 2065 int retval;
2066 int do_clocal = 0; 2066 int do_clocal = 0;
2067 unsigned long flags; 2067 unsigned long flags;
2068 2068
2069 /* 2069 /*
2070 * If the device is in the middle of being closed, then block 2070 * If the device is in the middle of being closed, then block
2071 * until it's done, and then try again. 2071 * until it's done, and then try again.
2072 */ 2072 */
2073 if (tty_hung_up_p(filp) || 2073 if (tty_hung_up_p(filp) ||
2074 (info->flags & ASYNC_CLOSING)) { 2074 (info->port.flags & ASYNC_CLOSING)) {
2075 if (info->flags & ASYNC_CLOSING) 2075 if (info->port.flags & ASYNC_CLOSING)
2076 interruptible_sleep_on(&info->close_wait); 2076 interruptible_sleep_on(&info->port.close_wait);
2077 #ifdef SERIAL_DO_RESTART 2077 #ifdef SERIAL_DO_RESTART
2078 if (info->flags & ASYNC_HUP_NOTIFY) 2078 if (info->port.flags & ASYNC_HUP_NOTIFY)
2079 return -EAGAIN; 2079 return -EAGAIN;
2080 else 2080 else
2081 return -ERESTARTSYS; 2081 return -ERESTARTSYS;
2082 #else 2082 #else
2083 return -EAGAIN; 2083 return -EAGAIN;
2084 #endif 2084 #endif
2085 } 2085 }
2086 2086
2087 /* 2087 /*
2088 * If non-blocking mode is set, or the port is not enabled, 2088 * If non-blocking mode is set, or the port is not enabled,
2089 * then make the check up front and then exit. 2089 * then make the check up front and then exit.
2090 */ 2090 */
2091 if ((filp->f_flags & O_NONBLOCK) || 2091 if ((filp->f_flags & O_NONBLOCK) ||
2092 (tty->flags & (1 << TTY_IO_ERROR))) { 2092 (tty->flags & (1 << TTY_IO_ERROR))) {
2093 info->flags |= ASYNC_NORMAL_ACTIVE; 2093 info->port.flags |= ASYNC_NORMAL_ACTIVE;
2094 return 0; 2094 return 0;
2095 } 2095 }
2096 2096
2097 if (tty->termios->c_cflag & CLOCAL) 2097 if (tty->termios->c_cflag & CLOCAL)
2098 do_clocal = 1; 2098 do_clocal = 1;
2099 2099
2100 /* 2100 /*
2101 * Block waiting for the carrier detect and the line to become 2101 * Block waiting for the carrier detect and the line to become
2102 * free (i.e., not in use by the callout). While we are in 2102 * free (i.e., not in use by the callout). While we are in
2103 * this loop, info->count is dropped by one, so that 2103 * this loop, info->port.count is dropped by one, so that
2104 * rs_close() knows when to free things. We restore it upon 2104 * rs_close() knows when to free things. We restore it upon
2105 * exit, either normal or abnormal. 2105 * exit, either normal or abnormal.
2106 */ 2106 */
2107 retval = 0; 2107 retval = 0;
2108 add_wait_queue(&info->open_wait, &wait); 2108 add_wait_queue(&info->port.open_wait, &wait);
2109 #ifdef SERIAL_DEBUG_OPEN 2109 #ifdef SERIAL_DEBUG_OPEN
2110 printk(KERN_DEBUG "block_til_ready before block: ttys%d, count = %d\n", 2110 printk(KERN_DEBUG "block_til_ready before block: ttys%d, count = %d\n",
2111 info->line, info->count); 2111 info->line, info->port.count);
2112 #endif 2112 #endif
2113 spin_lock_irqsave(&info->lock, flags); 2113 spin_lock_irqsave(&info->lock, flags);
2114 if (!tty_hung_up_p(filp)) 2114 if (!tty_hung_up_p(filp))
2115 info->count--; 2115 info->port.count--;
2116 info->blocked_open++; 2116 info->port.blocked_open++;
2117 while (1) { 2117 while (1) {
2118 if ((tty->termios->c_cflag & CBAUD)) { 2118 if ((tty->termios->c_cflag & CBAUD)) {
2119 unsigned int scratch; 2119 unsigned int scratch;
2120 2120
2121 serial_out(info, UART_ESI_CMD1, ESI_READ_UART); 2121 serial_out(info, UART_ESI_CMD1, ESI_READ_UART);
2122 serial_out(info, UART_ESI_CMD2, UART_MCR); 2122 serial_out(info, UART_ESI_CMD2, UART_MCR);
2123 scratch = serial_in(info, UART_ESI_STAT1); 2123 scratch = serial_in(info, UART_ESI_STAT1);
2124 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART); 2124 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
2125 serial_out(info, UART_ESI_CMD2, UART_MCR); 2125 serial_out(info, UART_ESI_CMD2, UART_MCR);
2126 serial_out(info, UART_ESI_CMD2, 2126 serial_out(info, UART_ESI_CMD2,
2127 scratch | UART_MCR_DTR | UART_MCR_RTS); 2127 scratch | UART_MCR_DTR | UART_MCR_RTS);
2128 } 2128 }
2129 set_current_state(TASK_INTERRUPTIBLE); 2129 set_current_state(TASK_INTERRUPTIBLE);
2130 if (tty_hung_up_p(filp) || 2130 if (tty_hung_up_p(filp) ||
2131 !(info->flags & ASYNC_INITIALIZED)) { 2131 !(info->port.flags & ASYNC_INITIALIZED)) {
2132 #ifdef SERIAL_DO_RESTART 2132 #ifdef SERIAL_DO_RESTART
2133 if (info->flags & ASYNC_HUP_NOTIFY) 2133 if (info->port.flags & ASYNC_HUP_NOTIFY)
2134 retval = -EAGAIN; 2134 retval = -EAGAIN;
2135 else 2135 else
2136 retval = -ERESTARTSYS; 2136 retval = -ERESTARTSYS;
2137 #else 2137 #else
2138 retval = -EAGAIN; 2138 retval = -EAGAIN;
2139 #endif 2139 #endif
2140 break; 2140 break;
2141 } 2141 }
2142 2142
2143 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT); 2143 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT);
2144 if (serial_in(info, UART_ESI_STAT2) & UART_MSR_DCD) 2144 if (serial_in(info, UART_ESI_STAT2) & UART_MSR_DCD)
2145 do_clocal = 1; 2145 do_clocal = 1;
2146 2146
2147 if (!(info->flags & ASYNC_CLOSING) && 2147 if (!(info->port.flags & ASYNC_CLOSING) &&
2148 (do_clocal)) 2148 (do_clocal))
2149 break; 2149 break;
2150 if (signal_pending(current)) { 2150 if (signal_pending(current)) {
2151 retval = -ERESTARTSYS; 2151 retval = -ERESTARTSYS;
2152 break; 2152 break;
2153 } 2153 }
2154 #ifdef SERIAL_DEBUG_OPEN 2154 #ifdef SERIAL_DEBUG_OPEN
2155 printk(KERN_DEBUG "block_til_ready blocking: ttys%d, count = %d\n", 2155 printk(KERN_DEBUG "block_til_ready blocking: ttys%d, count = %d\n",
2156 info->line, info->count); 2156 info->line, info->port.count);
2157 #endif 2157 #endif
2158 spin_unlock_irqrestore(&info->lock, flags); 2158 spin_unlock_irqrestore(&info->lock, flags);
2159 schedule(); 2159 schedule();
2160 spin_lock_irqsave(&info->lock, flags); 2160 spin_lock_irqsave(&info->lock, flags);
2161 } 2161 }
2162 set_current_state(TASK_RUNNING); 2162 set_current_state(TASK_RUNNING);
2163 remove_wait_queue(&info->open_wait, &wait); 2163 remove_wait_queue(&info->port.open_wait, &wait);
2164 if (!tty_hung_up_p(filp)) 2164 if (!tty_hung_up_p(filp))
2165 info->count++; 2165 info->port.count++;
2166 info->blocked_open--; 2166 info->port.blocked_open--;
2167 spin_unlock_irqrestore(&info->lock, flags); 2167 spin_unlock_irqrestore(&info->lock, flags);
2168 #ifdef SERIAL_DEBUG_OPEN 2168 #ifdef SERIAL_DEBUG_OPEN
2169 printk(KERN_DEBUG "block_til_ready after blocking: ttys%d, count = %d\n", 2169 printk(KERN_DEBUG "block_til_ready after blocking: ttys%d, count = %d\n",
2170 info->line, info->count); 2170 info->line, info->port.count);
2171 #endif 2171 #endif
2172 if (retval) 2172 if (retval)
2173 return retval; 2173 return retval;
2174 info->flags |= ASYNC_NORMAL_ACTIVE; 2174 info->port.flags |= ASYNC_NORMAL_ACTIVE;
2175 return 0; 2175 return 0;
2176 } 2176 }
2177 2177
2178 /* 2178 /*
2179 * This routine is called whenever a serial port is opened. It 2179 * This routine is called whenever a serial port is opened. It
2180 * enables interrupts for a serial port, linking in its async structure into 2180 * enables interrupts for a serial port, linking in its async structure into
2181 * the IRQ chain. It also performs the serial-specific 2181 * the IRQ chain. It also performs the serial-specific
2182 * initialization for the tty structure. 2182 * initialization for the tty structure.
2183 */ 2183 */
2184 static int esp_open(struct tty_struct *tty, struct file *filp) 2184 static int esp_open(struct tty_struct *tty, struct file *filp)
2185 { 2185 {
2186 struct esp_struct *info; 2186 struct esp_struct *info;
2187 int retval, line; 2187 int retval, line;
2188 unsigned long flags; 2188 unsigned long flags;
2189 2189
2190 line = tty->index; 2190 line = tty->index;
2191 if ((line < 0) || (line >= NR_PORTS)) 2191 if ((line < 0) || (line >= NR_PORTS))
2192 return -ENODEV; 2192 return -ENODEV;
2193 2193
2194 /* find the port in the chain */ 2194 /* find the port in the chain */
2195 2195
2196 info = ports; 2196 info = ports;
2197 2197
2198 while (info && (info->line != line)) 2198 while (info && (info->line != line))
2199 info = info->next_port; 2199 info = info->next_port;
2200 2200
2201 if (!info) { 2201 if (!info) {
2202 serial_paranoia_check(info, tty->name, "esp_open"); 2202 serial_paranoia_check(info, tty->name, "esp_open");
2203 return -ENODEV; 2203 return -ENODEV;
2204 } 2204 }
2205 2205
2206 #ifdef SERIAL_DEBUG_OPEN 2206 #ifdef SERIAL_DEBUG_OPEN
2207 printk(KERN_DEBUG "esp_open %s, count = %d\n", tty->name, info->count); 2207 printk(KERN_DEBUG "esp_open %s, count = %d\n", tty->name, info->port.count);
2208 #endif 2208 #endif
2209 spin_lock_irqsave(&info->lock, flags); 2209 spin_lock_irqsave(&info->lock, flags);
2210 info->count++; 2210 info->port.count++;
2211 tty->driver_data = info; 2211 tty->driver_data = info;
2212 info->tty = tty; 2212 info->port.tty = tty;
2213 2213
2214 spin_unlock_irqrestore(&info->lock, flags); 2214 spin_unlock_irqrestore(&info->lock, flags);
2215 2215
2216 /* 2216 /*
2217 * Start up serial port 2217 * Start up serial port
2218 */ 2218 */
2219 retval = startup(info); 2219 retval = startup(info);
2220 if (retval) 2220 if (retval)
2221 return retval; 2221 return retval;
2222 2222
2223 retval = block_til_ready(tty, filp, info); 2223 retval = block_til_ready(tty, filp, info);
2224 if (retval) { 2224 if (retval) {
2225 #ifdef SERIAL_DEBUG_OPEN 2225 #ifdef SERIAL_DEBUG_OPEN
2226 printk(KERN_DEBUG "esp_open returning after block_til_ready with %d\n", 2226 printk(KERN_DEBUG "esp_open returning after block_til_ready with %d\n",
2227 retval); 2227 retval);
2228 #endif 2228 #endif
2229 return retval; 2229 return retval;
2230 } 2230 }
2231 #ifdef SERIAL_DEBUG_OPEN 2231 #ifdef SERIAL_DEBUG_OPEN
2232 printk(KERN_DEBUG "esp_open %s successful...", tty->name); 2232 printk(KERN_DEBUG "esp_open %s successful...", tty->name);
2233 #endif 2233 #endif
2234 return 0; 2234 return 0;
2235 } 2235 }
2236 2236
2237 /* 2237 /*
2238 * --------------------------------------------------------------------- 2238 * ---------------------------------------------------------------------
2239 * espserial_init() and friends 2239 * espserial_init() and friends
2240 * 2240 *
2241 * espserial_init() is called at boot-time to initialize the serial driver. 2241 * espserial_init() is called at boot-time to initialize the serial driver.
2242 * --------------------------------------------------------------------- 2242 * ---------------------------------------------------------------------
2243 */ 2243 */
2244 2244
2245 /* 2245 /*
2246 * This routine prints out the appropriate serial driver version 2246 * This routine prints out the appropriate serial driver version
2247 * number, and identifies which options were configured into this 2247 * number, and identifies which options were configured into this
2248 * driver. 2248 * driver.
2249 */ 2249 */
2250 2250
2251 static void show_serial_version(void) 2251 static void show_serial_version(void)
2252 { 2252 {
2253 printk(KERN_INFO "%s version %s (DMA %u)\n", 2253 printk(KERN_INFO "%s version %s (DMA %u)\n",
2254 serial_name, serial_version, dma); 2254 serial_name, serial_version, dma);
2255 } 2255 }
2256 2256
2257 /* 2257 /*
2258 * This routine is called by espserial_init() to initialize a specific serial 2258 * This routine is called by espserial_init() to initialize a specific serial
2259 * port. 2259 * port.
2260 */ 2260 */
2261 static int autoconfig(struct esp_struct *info) 2261 static int autoconfig(struct esp_struct *info)
2262 { 2262 {
2263 int port_detected = 0; 2263 int port_detected = 0;
2264 unsigned long flags; 2264 unsigned long flags;
2265 2265
2266 if (!request_region(info->port, REGION_SIZE, "esp serial")) 2266 if (!request_region(info->io_port, REGION_SIZE, "esp serial"))
2267 return -EIO; 2267 return -EIO;
2268 2268
2269 spin_lock_irqsave(&info->lock, flags); 2269 spin_lock_irqsave(&info->lock, flags);
2270 /* 2270 /*
2271 * Check for ESP card 2271 * Check for ESP card
2272 */ 2272 */
2273 2273
2274 if (serial_in(info, UART_ESI_BASE) == 0xf3) { 2274 if (serial_in(info, UART_ESI_BASE) == 0xf3) {
2275 serial_out(info, UART_ESI_CMD1, 0x00); 2275 serial_out(info, UART_ESI_CMD1, 0x00);
2276 serial_out(info, UART_ESI_CMD1, 0x01); 2276 serial_out(info, UART_ESI_CMD1, 0x01);
2277 2277
2278 if ((serial_in(info, UART_ESI_STAT2) & 0x70) == 0x20) { 2278 if ((serial_in(info, UART_ESI_STAT2) & 0x70) == 0x20) {
2279 port_detected = 1; 2279 port_detected = 1;
2280 2280
2281 if (!(info->irq)) { 2281 if (!(info->irq)) {
2282 serial_out(info, UART_ESI_CMD1, 0x02); 2282 serial_out(info, UART_ESI_CMD1, 0x02);
2283 2283
2284 if (serial_in(info, UART_ESI_STAT1) & 0x01) 2284 if (serial_in(info, UART_ESI_STAT1) & 0x01)
2285 info->irq = 3; 2285 info->irq = 3;
2286 else 2286 else
2287 info->irq = 4; 2287 info->irq = 4;
2288 } 2288 }
2289 2289
2290 2290
2291 /* put card in enhanced mode */ 2291 /* put card in enhanced mode */
2292 /* this prevents access through */ 2292 /* this prevents access through */
2293 /* the "old" IO ports */ 2293 /* the "old" IO ports */
2294 esp_basic_init(info); 2294 esp_basic_init(info);
2295 2295
2296 /* clear out MCR */ 2296 /* clear out MCR */
2297 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART); 2297 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
2298 serial_out(info, UART_ESI_CMD2, UART_MCR); 2298 serial_out(info, UART_ESI_CMD2, UART_MCR);
2299 serial_out(info, UART_ESI_CMD2, 0x00); 2299 serial_out(info, UART_ESI_CMD2, 0x00);
2300 } 2300 }
2301 } 2301 }
2302 if (!port_detected) 2302 if (!port_detected)
2303 release_region(info->port, REGION_SIZE); 2303 release_region(info->io_port, REGION_SIZE);
2304 2304
2305 spin_unlock_irqrestore(&info->lock, flags); 2305 spin_unlock_irqrestore(&info->lock, flags);
2306 return (port_detected); 2306 return (port_detected);
2307 } 2307 }
2308 2308
2309 static const struct tty_operations esp_ops = { 2309 static const struct tty_operations esp_ops = {
2310 .open = esp_open, 2310 .open = esp_open,
2311 .close = rs_close, 2311 .close = rs_close,
2312 .write = rs_write, 2312 .write = rs_write,
2313 .put_char = rs_put_char, 2313 .put_char = rs_put_char,
2314 .flush_chars = rs_flush_chars, 2314 .flush_chars = rs_flush_chars,
2315 .write_room = rs_write_room, 2315 .write_room = rs_write_room,
2316 .chars_in_buffer = rs_chars_in_buffer, 2316 .chars_in_buffer = rs_chars_in_buffer,
2317 .flush_buffer = rs_flush_buffer, 2317 .flush_buffer = rs_flush_buffer,
2318 .ioctl = rs_ioctl, 2318 .ioctl = rs_ioctl,
2319 .throttle = rs_throttle, 2319 .throttle = rs_throttle,
2320 .unthrottle = rs_unthrottle, 2320 .unthrottle = rs_unthrottle,
2321 .set_termios = rs_set_termios, 2321 .set_termios = rs_set_termios,
2322 .stop = rs_stop, 2322 .stop = rs_stop,
2323 .start = rs_start, 2323 .start = rs_start,
2324 .hangup = esp_hangup, 2324 .hangup = esp_hangup,
2325 .break_ctl = esp_break, 2325 .break_ctl = esp_break,
2326 .wait_until_sent = rs_wait_until_sent, 2326 .wait_until_sent = rs_wait_until_sent,
2327 .tiocmget = esp_tiocmget, 2327 .tiocmget = esp_tiocmget,
2328 .tiocmset = esp_tiocmset, 2328 .tiocmset = esp_tiocmset,
2329 }; 2329 };
2330 2330
2331 /* 2331 /*
2332 * The serial driver boot-time initialization code! 2332 * The serial driver boot-time initialization code!
2333 */ 2333 */
2334 static int __init espserial_init(void) 2334 static int __init espserial_init(void)
2335 { 2335 {
2336 int i, offset; 2336 int i, offset;
2337 struct esp_struct *info; 2337 struct esp_struct *info;
2338 struct esp_struct *last_primary = NULL; 2338 struct esp_struct *last_primary = NULL;
2339 int esp[] = { 0x100, 0x140, 0x180, 0x200, 0x240, 0x280, 0x300, 0x380 }; 2339 int esp[] = { 0x100, 0x140, 0x180, 0x200, 0x240, 0x280, 0x300, 0x380 };
2340 2340
2341 esp_driver = alloc_tty_driver(NR_PORTS); 2341 esp_driver = alloc_tty_driver(NR_PORTS);
2342 if (!esp_driver) 2342 if (!esp_driver)
2343 return -ENOMEM; 2343 return -ENOMEM;
2344 2344
2345 for (i = 0; i < NR_PRIMARY; i++) { 2345 for (i = 0; i < NR_PRIMARY; i++) {
2346 if (irq[i] != 0) { 2346 if (irq[i] != 0) {
2347 if ((irq[i] < 2) || (irq[i] > 15) || (irq[i] == 6) || 2347 if ((irq[i] < 2) || (irq[i] > 15) || (irq[i] == 6) ||
2348 (irq[i] == 8) || (irq[i] == 13)) 2348 (irq[i] == 8) || (irq[i] == 13))
2349 irq[i] = 0; 2349 irq[i] = 0;
2350 else if (irq[i] == 2) 2350 else if (irq[i] == 2)
2351 irq[i] = 9; 2351 irq[i] = 9;
2352 } 2352 }
2353 } 2353 }
2354 2354
2355 if ((dma != 1) && (dma != 3)) 2355 if ((dma != 1) && (dma != 3))
2356 dma = 0; 2356 dma = 0;
2357 2357
2358 if ((rx_trigger < 1) || (rx_trigger > 1023)) 2358 if ((rx_trigger < 1) || (rx_trigger > 1023))
2359 rx_trigger = 768; 2359 rx_trigger = 768;
2360 2360
2361 if ((tx_trigger < 1) || (tx_trigger > 1023)) 2361 if ((tx_trigger < 1) || (tx_trigger > 1023))
2362 tx_trigger = 768; 2362 tx_trigger = 768;
2363 2363
2364 if ((flow_off < 1) || (flow_off > 1023)) 2364 if ((flow_off < 1) || (flow_off > 1023))
2365 flow_off = 1016; 2365 flow_off = 1016;
2366 2366
2367 if ((flow_on < 1) || (flow_on > 1023)) 2367 if ((flow_on < 1) || (flow_on > 1023))
2368 flow_on = 944; 2368 flow_on = 944;
2369 2369
2370 if ((rx_timeout < 0) || (rx_timeout > 255)) 2370 if ((rx_timeout < 0) || (rx_timeout > 255))
2371 rx_timeout = 128; 2371 rx_timeout = 128;
2372 2372
2373 if (flow_on >= flow_off) 2373 if (flow_on >= flow_off)
2374 flow_on = flow_off - 1; 2374 flow_on = flow_off - 1;
2375 2375
2376 show_serial_version(); 2376 show_serial_version();
2377 2377
2378 /* Initialize the tty_driver structure */ 2378 /* Initialize the tty_driver structure */
2379 2379
2380 esp_driver->owner = THIS_MODULE; 2380 esp_driver->owner = THIS_MODULE;
2381 esp_driver->name = "ttyP"; 2381 esp_driver->name = "ttyP";
2382 esp_driver->major = ESP_IN_MAJOR; 2382 esp_driver->major = ESP_IN_MAJOR;
2383 esp_driver->minor_start = 0; 2383 esp_driver->minor_start = 0;
2384 esp_driver->type = TTY_DRIVER_TYPE_SERIAL; 2384 esp_driver->type = TTY_DRIVER_TYPE_SERIAL;
2385 esp_driver->subtype = SERIAL_TYPE_NORMAL; 2385 esp_driver->subtype = SERIAL_TYPE_NORMAL;
2386 esp_driver->init_termios = tty_std_termios; 2386 esp_driver->init_termios = tty_std_termios;
2387 esp_driver->init_termios.c_cflag = 2387 esp_driver->init_termios.c_cflag =
2388 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 2388 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2389 esp_driver->init_termios.c_ispeed = 9600; 2389 esp_driver->init_termios.c_ispeed = 9600;
2390 esp_driver->init_termios.c_ospeed = 9600; 2390 esp_driver->init_termios.c_ospeed = 9600;
2391 esp_driver->flags = TTY_DRIVER_REAL_RAW; 2391 esp_driver->flags = TTY_DRIVER_REAL_RAW;
2392 tty_set_operations(esp_driver, &esp_ops); 2392 tty_set_operations(esp_driver, &esp_ops);
2393 if (tty_register_driver(esp_driver)) { 2393 if (tty_register_driver(esp_driver)) {
2394 printk(KERN_ERR "Couldn't register esp serial driver"); 2394 printk(KERN_ERR "Couldn't register esp serial driver");
2395 put_tty_driver(esp_driver); 2395 put_tty_driver(esp_driver);
2396 return 1; 2396 return 1;
2397 } 2397 }
2398 2398
2399 info = kzalloc(sizeof(struct esp_struct), GFP_KERNEL); 2399 info = kzalloc(sizeof(struct esp_struct), GFP_KERNEL);
2400 2400
2401 if (!info) { 2401 if (!info) {
2402 printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n"); 2402 printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n");
2403 tty_unregister_driver(esp_driver); 2403 tty_unregister_driver(esp_driver);
2404 put_tty_driver(esp_driver); 2404 put_tty_driver(esp_driver);
2405 return 1; 2405 return 1;
2406 } 2406 }
2407 2407
2408 spin_lock_init(&info->lock); 2408 spin_lock_init(&info->lock);
2409 /* rx_trigger, tx_trigger are needed by autoconfig */ 2409 /* rx_trigger, tx_trigger are needed by autoconfig */
2410 info->config.rx_trigger = rx_trigger; 2410 info->config.rx_trigger = rx_trigger;
2411 info->config.tx_trigger = tx_trigger; 2411 info->config.tx_trigger = tx_trigger;
2412 2412
2413 i = 0; 2413 i = 0;
2414 offset = 0; 2414 offset = 0;
2415 2415
2416 do { 2416 do {
2417 info->port = esp[i] + offset; 2417 info->io_port = esp[i] + offset;
2418 info->irq = irq[i]; 2418 info->irq = irq[i];
2419 info->line = (i * 8) + (offset / 8); 2419 info->line = (i * 8) + (offset / 8);
2420 2420
2421 if (!autoconfig(info)) { 2421 if (!autoconfig(info)) {
2422 i++; 2422 i++;
2423 offset = 0; 2423 offset = 0;
2424 continue; 2424 continue;
2425 } 2425 }
2426 2426
2427 info->custom_divisor = (divisor[i] >> (offset / 2)) & 0xf; 2427 info->custom_divisor = (divisor[i] >> (offset / 2)) & 0xf;
2428 info->flags = STD_COM_FLAGS; 2428 info->port.flags = STD_COM_FLAGS;
2429 if (info->custom_divisor) 2429 if (info->custom_divisor)
2430 info->flags |= ASYNC_SPD_CUST; 2430 info->port.flags |= ASYNC_SPD_CUST;
2431 info->magic = ESP_MAGIC; 2431 info->magic = ESP_MAGIC;
2432 info->close_delay = 5*HZ/10; 2432 info->close_delay = 5*HZ/10;
2433 info->closing_wait = 30*HZ; 2433 info->closing_wait = 30*HZ;
2434 info->config.rx_timeout = rx_timeout; 2434 info->config.rx_timeout = rx_timeout;
2435 info->config.flow_on = flow_on; 2435 info->config.flow_on = flow_on;
2436 info->config.flow_off = flow_off; 2436 info->config.flow_off = flow_off;
2437 info->config.pio_threshold = pio_threshold; 2437 info->config.pio_threshold = pio_threshold;
2438 info->next_port = ports; 2438 info->next_port = ports;
2439 init_waitqueue_head(&info->open_wait); 2439 init_waitqueue_head(&info->port.open_wait);
2440 init_waitqueue_head(&info->close_wait); 2440 init_waitqueue_head(&info->port.close_wait);
2441 init_waitqueue_head(&info->delta_msr_wait); 2441 init_waitqueue_head(&info->delta_msr_wait);
2442 init_waitqueue_head(&info->break_wait); 2442 init_waitqueue_head(&info->break_wait);
2443 ports = info; 2443 ports = info;
2444 printk(KERN_INFO "ttyP%d at 0x%04x (irq = %d) is an ESP ", 2444 printk(KERN_INFO "ttyP%d at 0x%04x (irq = %d) is an ESP ",
2445 info->line, info->port, info->irq); 2445 info->line, info->io_port, info->irq);
2446 2446
2447 if (info->line % 8) { 2447 if (info->line % 8) {
2448 printk("secondary port\n"); 2448 printk("secondary port\n");
2449 /* 8 port cards can't do DMA */ 2449 /* 8 port cards can't do DMA */
2450 info->stat_flags |= ESP_STAT_NEVER_DMA; 2450 info->stat_flags |= ESP_STAT_NEVER_DMA;
2451 2451
2452 if (last_primary) 2452 if (last_primary)
2453 last_primary->stat_flags |= ESP_STAT_NEVER_DMA; 2453 last_primary->stat_flags |= ESP_STAT_NEVER_DMA;
2454 } else { 2454 } else {
2455 printk("primary port\n"); 2455 printk("primary port\n");
2456 last_primary = info; 2456 last_primary = info;
2457 irq[i] = info->irq; 2457 irq[i] = info->irq;
2458 } 2458 }
2459 2459
2460 if (!dma) 2460 if (!dma)
2461 info->stat_flags |= ESP_STAT_NEVER_DMA; 2461 info->stat_flags |= ESP_STAT_NEVER_DMA;
2462 2462
2463 info = kzalloc(sizeof(struct esp_struct), GFP_KERNEL); 2463 info = kzalloc(sizeof(struct esp_struct), GFP_KERNEL);
2464 if (!info) { 2464 if (!info) {
2465 printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n"); 2465 printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n");
2466 /* allow use of the already detected ports */ 2466 /* allow use of the already detected ports */
2467 return 0; 2467 return 0;
2468 } 2468 }
2469 2469
2470 spin_lock_init(&info->lock); 2470 spin_lock_init(&info->lock);
2471 /* rx_trigger, tx_trigger are needed by autoconfig */ 2471 /* rx_trigger, tx_trigger are needed by autoconfig */
2472 info->config.rx_trigger = rx_trigger; 2472 info->config.rx_trigger = rx_trigger;
2473 info->config.tx_trigger = tx_trigger; 2473 info->config.tx_trigger = tx_trigger;
2474 2474
2475 if (offset == 56) { 2475 if (offset == 56) {
2476 i++; 2476 i++;
2477 offset = 0; 2477 offset = 0;
2478 } else { 2478 } else {
2479 offset += 8; 2479 offset += 8;
2480 } 2480 }
2481 } while (i < NR_PRIMARY); 2481 } while (i < NR_PRIMARY);
2482 2482
2483 /* free the last port memory allocation */ 2483 /* free the last port memory allocation */
2484 kfree(info); 2484 kfree(info);
2485 2485
2486 return 0; 2486 return 0;
2487 } 2487 }
2488 2488
2489 static void __exit espserial_exit(void) 2489 static void __exit espserial_exit(void)
2490 { 2490 {
2491 int e1; 2491 int e1;
2492 struct esp_struct *temp_async; 2492 struct esp_struct *temp_async;
2493 struct esp_pio_buffer *pio_buf; 2493 struct esp_pio_buffer *pio_buf;
2494 2494
2495 e1 = tty_unregister_driver(esp_driver); 2495 e1 = tty_unregister_driver(esp_driver);
2496 if (e1) 2496 if (e1)
2497 printk(KERN_ERR "esp: failed to unregister driver (%d)\n", e1); 2497 printk(KERN_ERR "esp: failed to unregister driver (%d)\n", e1);
2498 put_tty_driver(esp_driver); 2498 put_tty_driver(esp_driver);
2499 2499
2500 while (ports) { 2500 while (ports) {
2501 if (ports->port) 2501 if (ports->io_port)
2502 release_region(ports->port, REGION_SIZE); 2502 release_region(ports->io_port, REGION_SIZE);
2503 temp_async = ports->next_port; 2503 temp_async = ports->next_port;
2504 kfree(ports); 2504 kfree(ports);
2505 ports = temp_async; 2505 ports = temp_async;
2506 } 2506 }
2507 2507
2508 if (dma_buffer) 2508 if (dma_buffer)
2509 free_pages((unsigned long)dma_buffer, 2509 free_pages((unsigned long)dma_buffer,
2510 get_order(DMA_BUFFER_SZ)); 2510 get_order(DMA_BUFFER_SZ));
2511 2511
2512 while (free_pio_buf) { 2512 while (free_pio_buf) {
2513 pio_buf = free_pio_buf->next; 2513 pio_buf = free_pio_buf->next;
2514 kfree(free_pio_buf); 2514 kfree(free_pio_buf);
2515 free_pio_buf = pio_buf; 2515 free_pio_buf = pio_buf;
2516 } 2516 }
2517 } 2517 }
2518 2518
2519 module_init(espserial_init); 2519 module_init(espserial_init);
2520 module_exit(espserial_exit); 2520 module_exit(espserial_exit);
2521 2521
include/linux/hayesesp.h
1 #ifndef HAYESESP_H 1 #ifndef HAYESESP_H
2 #define HAYESESP_H 2 #define HAYESESP_H
3 3
4 struct hayes_esp_config { 4 struct hayes_esp_config {
5 short flow_on; 5 short flow_on;
6 short flow_off; 6 short flow_off;
7 short rx_trigger; 7 short rx_trigger;
8 short tx_trigger; 8 short tx_trigger;
9 short pio_threshold; 9 short pio_threshold;
10 unsigned char rx_timeout; 10 unsigned char rx_timeout;
11 char dma_channel; 11 char dma_channel;
12 }; 12 };
13 13
14 #ifdef __KERNEL__ 14 #ifdef __KERNEL__
15 15
16 #define ESP_DMA_CHANNEL 0 16 #define ESP_DMA_CHANNEL 0
17 #define ESP_RX_TRIGGER 768 17 #define ESP_RX_TRIGGER 768
18 #define ESP_TX_TRIGGER 768 18 #define ESP_TX_TRIGGER 768
19 #define ESP_FLOW_OFF 1016 19 #define ESP_FLOW_OFF 1016
20 #define ESP_FLOW_ON 944 20 #define ESP_FLOW_ON 944
21 #define ESP_RX_TMOUT 128 21 #define ESP_RX_TMOUT 128
22 #define ESP_PIO_THRESHOLD 32 22 #define ESP_PIO_THRESHOLD 32
23 23
24 #define ESP_IN_MAJOR 57 /* major dev # for dial in */ 24 #define ESP_IN_MAJOR 57 /* major dev # for dial in */
25 #define ESP_OUT_MAJOR 58 /* major dev # for dial out */ 25 #define ESP_OUT_MAJOR 58 /* major dev # for dial out */
26 #define ESPC_SCALE 3 26 #define ESPC_SCALE 3
27 #define UART_ESI_BASE 0x00 27 #define UART_ESI_BASE 0x00
28 #define UART_ESI_SID 0x01 28 #define UART_ESI_SID 0x01
29 #define UART_ESI_RX 0x02 29 #define UART_ESI_RX 0x02
30 #define UART_ESI_TX 0x02 30 #define UART_ESI_TX 0x02
31 #define UART_ESI_CMD1 0x04 31 #define UART_ESI_CMD1 0x04
32 #define UART_ESI_CMD2 0x05 32 #define UART_ESI_CMD2 0x05
33 #define UART_ESI_STAT1 0x04 33 #define UART_ESI_STAT1 0x04
34 #define UART_ESI_STAT2 0x05 34 #define UART_ESI_STAT2 0x05
35 #define UART_ESI_RWS 0x07 35 #define UART_ESI_RWS 0x07
36 36
37 #define UART_IER_DMA_TMOUT 0x80 37 #define UART_IER_DMA_TMOUT 0x80
38 #define UART_IER_DMA_TC 0x08 38 #define UART_IER_DMA_TC 0x08
39 39
40 #define ESI_SET_IRQ 0x04 40 #define ESI_SET_IRQ 0x04
41 #define ESI_SET_DMA_TMOUT 0x05 41 #define ESI_SET_DMA_TMOUT 0x05
42 #define ESI_SET_SRV_MASK 0x06 42 #define ESI_SET_SRV_MASK 0x06
43 #define ESI_SET_ERR_MASK 0x07 43 #define ESI_SET_ERR_MASK 0x07
44 #define ESI_SET_FLOW_CNTL 0x08 44 #define ESI_SET_FLOW_CNTL 0x08
45 #define ESI_SET_FLOW_CHARS 0x09 45 #define ESI_SET_FLOW_CHARS 0x09
46 #define ESI_SET_FLOW_LVL 0x0a 46 #define ESI_SET_FLOW_LVL 0x0a
47 #define ESI_SET_TRIGGER 0x0b 47 #define ESI_SET_TRIGGER 0x0b
48 #define ESI_SET_RX_TIMEOUT 0x0c 48 #define ESI_SET_RX_TIMEOUT 0x0c
49 #define ESI_SET_FLOW_TMOUT 0x0d 49 #define ESI_SET_FLOW_TMOUT 0x0d
50 #define ESI_WRITE_UART 0x0e 50 #define ESI_WRITE_UART 0x0e
51 #define ESI_READ_UART 0x0f 51 #define ESI_READ_UART 0x0f
52 #define ESI_SET_MODE 0x10 52 #define ESI_SET_MODE 0x10
53 #define ESI_GET_ERR_STAT 0x12 53 #define ESI_GET_ERR_STAT 0x12
54 #define ESI_GET_UART_STAT 0x13 54 #define ESI_GET_UART_STAT 0x13
55 #define ESI_GET_RX_AVAIL 0x14 55 #define ESI_GET_RX_AVAIL 0x14
56 #define ESI_GET_TX_AVAIL 0x15 56 #define ESI_GET_TX_AVAIL 0x15
57 #define ESI_START_DMA_RX 0x16 57 #define ESI_START_DMA_RX 0x16
58 #define ESI_START_DMA_TX 0x17 58 #define ESI_START_DMA_TX 0x17
59 #define ESI_ISSUE_BREAK 0x1a 59 #define ESI_ISSUE_BREAK 0x1a
60 #define ESI_FLUSH_RX 0x1b 60 #define ESI_FLUSH_RX 0x1b
61 #define ESI_FLUSH_TX 0x1c 61 #define ESI_FLUSH_TX 0x1c
62 #define ESI_SET_BAUD 0x1d 62 #define ESI_SET_BAUD 0x1d
63 #define ESI_SET_ENH_IRQ 0x1f 63 #define ESI_SET_ENH_IRQ 0x1f
64 #define ESI_SET_REINTR 0x20 64 #define ESI_SET_REINTR 0x20
65 #define ESI_SET_PRESCALAR 0x23 65 #define ESI_SET_PRESCALAR 0x23
66 #define ESI_NO_COMMAND 0xff 66 #define ESI_NO_COMMAND 0xff
67 67
68 #define ESP_STAT_RX_TIMEOUT 0x01 68 #define ESP_STAT_RX_TIMEOUT 0x01
69 #define ESP_STAT_DMA_RX 0x02 69 #define ESP_STAT_DMA_RX 0x02
70 #define ESP_STAT_DMA_TX 0x04 70 #define ESP_STAT_DMA_TX 0x04
71 #define ESP_STAT_NEVER_DMA 0x08 71 #define ESP_STAT_NEVER_DMA 0x08
72 #define ESP_STAT_USE_PIO 0x10 72 #define ESP_STAT_USE_PIO 0x10
73 73
74 #define ESP_MAGIC 0x53ee 74 #define ESP_MAGIC 0x53ee
75 #define ESP_XMIT_SIZE 4096 75 #define ESP_XMIT_SIZE 4096
76 76
77 struct esp_struct { 77 struct esp_struct {
78 int magic; 78 int magic;
79 struct tty_port port;
79 spinlock_t lock; 80 spinlock_t lock;
80 int port; 81 int io_port;
81 int irq; 82 int irq;
82 int flags; /* defined in tty.h */
83 struct tty_struct *tty;
84 int read_status_mask; 83 int read_status_mask;
85 int ignore_status_mask; 84 int ignore_status_mask;
86 int timeout; 85 int timeout;
87 int stat_flags; 86 int stat_flags;
88 int custom_divisor; 87 int custom_divisor;
89 int close_delay; 88 int close_delay;
90 unsigned short closing_wait; 89 unsigned short closing_wait;
91 unsigned short closing_wait2; 90 unsigned short closing_wait2;
92 int IER; /* Interrupt Enable Register */ 91 int IER; /* Interrupt Enable Register */
93 int MCR; /* Modem control register */ 92 int MCR; /* Modem control register */
94 unsigned long last_active; 93 unsigned long last_active;
95 int line; 94 int line;
96 int count; /* # of fd on device */
97 int blocked_open; /* # of blocked opens */
98 unsigned char *xmit_buf; 95 unsigned char *xmit_buf;
99 int xmit_head; 96 int xmit_head;
100 int xmit_tail; 97 int xmit_tail;
101 int xmit_cnt; 98 int xmit_cnt;
102 wait_queue_head_t open_wait;
103 wait_queue_head_t close_wait;
104 wait_queue_head_t delta_msr_wait; 99 wait_queue_head_t delta_msr_wait;
105 wait_queue_head_t break_wait; 100 wait_queue_head_t break_wait;
106 struct async_icount icount; /* kernel counters for the 4 input interrupts */ 101 struct async_icount icount; /* kernel counters for the 4 input interrupts */
107 struct hayes_esp_config config; /* port configuration */ 102 struct hayes_esp_config config; /* port configuration */
108 struct esp_struct *next_port; /* For the linked list */ 103 struct esp_struct *next_port; /* For the linked list */
109 }; 104 };
110 105
111 struct esp_pio_buffer { 106 struct esp_pio_buffer {
112 unsigned char data[1024]; 107 unsigned char data[1024];
113 struct esp_pio_buffer *next; 108 struct esp_pio_buffer *next;
114 }; 109 };
115 110
116 #endif /* __KERNEL__ */ 111 #endif /* __KERNEL__ */
117 112
118 113
119 #endif /* ESP_H */ 114 #endif /* ESP_H */
120 115